diff -Nru libwebsockets-3.2.1/appveyor.yml libwebsockets-4.1.6/appveyor.yml --- libwebsockets-3.2.1/appveyor.yml 2019-12-18 14:45:31.000000000 +0000 +++ libwebsockets-4.1.6/appveyor.yml 1970-01-01 00:00:00.000000000 +0000 @@ -1,77 +0,0 @@ -environment: - matrix: - - LWS_METHOD: jose - CMAKE_ARGS: -DLWS_WITH_JOSE=1 - - - LWS_METHOD: x64 - CMAKE_ARGS: -DCMAKE_GENERATOR_PLATFORM=x64 -DLWS_WITH_HTTP2=1 -DLWS_WITH_PLUGINS=1 -DLIBUV_INCLUDE_DIRS=C:\assets\libuv64\include -DLIBUV_LIBRARIES=C:\assets\libuv64\libuv.lib - - - LWS_METHOD: lwsws - CMAKE_ARGS: -DLWS_WITH_LWSWS=1 -DSQLITE3_INCLUDE_DIRS=C:\assets\sqlite3 -DSQLITE3_LIBRARIES=C:\assets\sqlite3\sqlite3.lib -DLIBUV_INCLUDE_DIRS=C:\assets\libuv\include -DLIBUV_LIBRARIES=C:\assets\libuv\libuv.lib - - - LWS_METHOD: default - - - LWS_METHOD: noserver - CMAKE_ARGS: -DLWS_WITHOUT_SERVER=ON - - - LWS_METHOD: noclient - CMAKE_ARGS: -DLWS_WITHOUT_CLIENT=ON - - - LWS_METHOD: noext - CMAKE_ARGS: -DLWS_WITHOUT_EXTENSIONS=ON - - - LWS_METHOD: nossl - CMAKE_ARGS: -DLWS_WITH_SSL=OFF - -install: - - appveyor DownloadFile https://libwebsockets.org:444/win-libuv.zip - - mkdir c:\assets - - mkdir c:\assets\libuv - - 7z x -oc:\assets\libuv win-libuv.zip - - appveyor DownloadFile https://libwebsockets.org:444/win-libuv64.zip - - mkdir c:\assets\libuv64 - - 7z x -oc:\assets\libuv64 win-libuv64.zip - - appveyor DownloadFile https://libwebsockets.org:444/nsis-3.0rc1-setup.exe - - cmd /c start /wait nsis-3.0rc1-setup.exe /S /D=C:\nsis - - appveyor DownloadFile https://libwebsockets.org:444/sqlite-dll-win32-x86-3130000.zip - - mkdir c:\assets\sqlite3 - - 7z x -oc:\assets\sqlite3 sqlite-dll-win32-x86-3130000.zip - - SET PATH=C:\Program Files\NSIS\;C:\Program Files (x86)\NSIS\;c:\nsis;%PATH% - -build_script: - - md build - - cd build - - cmake -DCMAKE_BUILD_TYPE=Release %CMAKE_ARGS% .. - - cmake --build . --config Release - -after_build: - - cd %APPVEYOR_BUILD_FOLDER% - - mkdir staging - - mkdir staging\include - - cp -r %APPVEYOR_BUILD_FOLDER%\build\bin %APPVEYOR_BUILD_FOLDER%\build\lib staging - - if EXIST staging\bin\share mv staging\bin\share staging - - if NOT EXIST staging\share\libwebsockets-test-server mkdir staging\share\libwebsockets-test-server - - IF EXIST %APPVEYOR_BUILD_FOLDER%\build\libwebsockets-test-server.pem cp %APPVEYOR_BUILD_FOLDER%\build\libwebsockets-test-server.pem staging\share\libwebsockets-test-server - - IF EXIST %APPVEYOR_BUILD_FOLDER%\build\libwebsockets-test-server.key.pem cp %APPVEYOR_BUILD_FOLDER%\build\libwebsockets-test-server.key.pem staging\share\libwebsockets-test-server - - IF EXIST %APPVEYOR_BUILD_FOLDER%\build\lws_config.h cp %APPVEYOR_BUILD_FOLDER%\build\lws_config.h staging\include - - cp %APPVEYOR_BUILD_FOLDER%\include\libwebsockets.h staging\include - - cp -r %APPVEYOR_BUILD_FOLDER%\include\libwebsockets staging\include - - 7z a build\lws-%LWS_METHOD%-%APPVEYOR_BUILD_ID%.zip %APPVEYOR_BUILD_FOLDER%\staging\* - -artifacts: - - path: build\lws-%LWS_METHOD%-%APPVEYOR_BUILD_ID%.zip - -#deploy: -#- provider: BinTray -# username: lws-team -# api_key: -# secure: nDpZ7P/wrk98DwJPMC6KpCC23QrVP8f3RxvKzBaqOmb9LiVrg1IyO1cc5vcgShZC -# subject: lws-team -# repo: libwebsockets -# package: windows -# publish: true -# override: true -# explode: false - -matrix: - fast_finish: true diff -Nru libwebsockets-3.2.1/bug_report.md libwebsockets-4.1.6/bug_report.md --- libwebsockets-3.2.1/bug_report.md 1970-01-01 00:00:00.000000000 +0000 +++ libwebsockets-4.1.6/bug_report.md 2020-12-01 17:40:26.000000000 +0000 @@ -0,0 +1,37 @@ +** What version of lws ** + +"vx.y.z" or "01234567 from master thismorning" etc + +If it's much older than last stable release, we will likely suggest you try that or master. + +** What platform and arch? ** + +"Fedora 32 x86_64" or "OSX Catalina" etc + +** What parts of lws does it involve? ** + +dunno / core / client / server +raw / http / ws / mqtt / other (give me a hint) + +** How can I reproduce the problem just using lws code? ** + +We can't guess your problem especially in your code. It's great if you can give us a way to +realize our own failure clearly with a reproducer that uses our own code. + +Try to remove your code from the equation by trying the same flow on an lws minimal example and provide a little diff against that. We can find out if it's only on your platform, or only on that version, or only in your code from that quickly, and if something to fix in lws, I can confirm it really is fixed using the same test. + +** Describe the bug ** + + "fails" --> this word is a red flag you didn't try to debug the issue much... exactly how does it "fail", what evidence is it leaving like logs or return codes or traces? + "hangs" --> this word is a red flag you didn't try to debug the issue much... exactly what does it mean, whole device frozen? Spinning 100% cpu? Just idle? Building on fire? Have you tried it via strace or similar if it seems frozen to see what it's doing? Attach a debugger like gdb -p pid and get a backtrace? perf top if Linux to see what it spends its time on. + "crashes" --> what happens if you run under valgrind? You know lws is not threadsafe except for lws_cancel_service(), right... + "sucks" --> let's discuss you writing a patch to improve whatever it is + +** Additional data ** + +Build problems? Describe the toolchain and paste the warnings / errors. + +Crash? Get a usable backtrace by building with `cmake .. -DCMAKE_BUILD_TYPE=DEBUG` and run under gdb, lldb, or valgrind. + +Mysterious happenings? Get verbose lws logs by building with `cmake .. -DCMAKE_BUILD_TYPE=DEBUG` and run with `lws_set_log_level(1151, NULL)`, on the example apps they all take a switch like -d1151. + diff -Nru libwebsockets-3.2.1/changelog libwebsockets-4.1.6/changelog --- libwebsockets-3.2.1/changelog 2019-12-18 14:45:31.000000000 +0000 +++ libwebsockets-4.1.6/changelog 2020-12-01 17:40:26.000000000 +0000 @@ -1,6 +1,187 @@ Changelog --------- +v4.1.0 +====== + + - NEW: travis / appveyor / bintray are replaced by Sai + https://libwebsockets.org/sai/ which for lws currently does 193 builds per + git push on 16 platforms, all self-hosted. The homebrew bash scripts used + to select Minimal examples are replaced by CTest. Platforms currently + include Fedora/AMD/GCC, Windows/AMD/mingw32, Windows/AMD/mingw64, Android/ + aarch64/LLVM, esp-idf (on WROVER-KIT and HELTEC physical boards), Fedora/ + RISCV (on QEMU)/GCC, CentOS8/AMD/GCC, Gentoo/AMD/GCC, Bionic/AMD/GCC, + Linkit 7697, Focal/AMD/GCC, Windows (on QEMU)/AMD/MSVC, + Focal/aarch64-RPI4/GCC, iOS/aarch64/LLVM and OSX/AMD/LLVM. + + - NEW: The single CMakeLists.txt has been refactored and modernized into smaller + CMakeLists.txt in the subdirectory along with the code that is being managed + for build by it. Build options are still listed in the top level as before + but the new way is much more maintainable. + + - NEW: event lib support on Unix is now built into dynamically loaded plugins + and brought in at runtime, allowing all of the support to be built in + isolation without conflicts, and separately packaged with individual + dependencies. See ./READMEs/event-libs.md for details and how to force + the old static build into lws method. + + - NEW: Captive Portal Detection. Lws can determine if the active default + route is able to connect to the internet, or is in a captive portal type + situation, by trying to connect to a remote server that will respond in an + unusual way, like provide a 204. + + - NEW: Secure streams: Support system trust store if it exists + Build on Windows + Support lws raw socket protocol in SS + Support Unix Domain Socket transport + + - NEW: Windows: Support Unix Domain Sockets same as other platforms + + - NEW: Windows: Build using native pthreads, async dns, ipv6 on MSVC + + - NEW: lws_struct: BLOB support + + - NEW: lws_sul: Now provides two sorted timer domains, a default one as + before, and another whose scheduled events are capable to wake the system from suspend + + - NEW: System Message Distribution: lws_smd provides a very lightweight way + to pass short messages between subsystems both in RTOS type case where the + subsystems are all on the lws event loop, and in the case participants are in + different processes, using Secure Streams proxying. Participants register a bitmap + of message classes they care about; if no particpant cares about a particular message, + it is rejected at allocation time for the sender, making it cheap to provide messages + speculatively. See lib/system/smd/README.md for full details. + + - NEW: lws_drivers: wrappers for SDK driver abstractions (or actual drivers) + See lib/drivers/README.md, example implementations + minimal-examples/embedded/esp32/esp-wrover-kit + - generic gpio + - generic LED (by name) lib/drivers/led/README.md + - generic PWM, sophisticated interpolated table + sequencers with crossfade + - generic button (by name), with debounce and press classification + emitting rich SMD click, long-click, double-click, + down, repeat, up JSON messages + lib/drivers/button/README.md + - bitbang i2c on generic gpio (hw support can use same + abstract API) + - bitbang spi on generic gpio (hw support can use same + abstract API) + - generic display object, can be wired up to controller + drivers that hook up by generic i2c or spi, + generic backlight PWM sequencing and + blanking timer support + - generic settings storage: get and set blobs by name + - generic network device: netdev abstract class with + WIFI / Ethernet implementations + using underlying SDK APIs; + generic 80211 Scan managements + and credentials handling via + lws_settings + This is the new way to provide embedded platform + functionality that was in the past done like + esp32-factory. Unlike the old way, the new way has no + native apis in it and can be built on other SDK / SoCs + the same. + + - NEW: Security-aware JWS JWT (JSON Web Tokens) apis are provided on top of the existing + JOSE / JWS apis. All the common algorithms are available along with some + high level apis like lws http cookie -> JWT struct -> lws http cookie. + + - REMOVED: esp32-helper and friends used by esp32-factory now lws_drivers + exists + + - REMOVED: generic sessions and friends now JWT is provided + +v4.0.0 +====== + + - NEW: Lws is now under the MIT license, see ./LICENSE for details + + - NEW: GLIB native event loop support, lws + gtk example + + - NEW: native lws MQTT client... supports client stream binding like h2 when + multiple logical connections are going to the same endpoint over MQTT, they + transparently and independently share the one connection + tls tunnel + + - NEW: "Secure Streams"... if you are making a device with client connections + to the internet or cloud, this allows separation of the communications + policy (endpoints, tls cert validation, protocols, etc) from the code, with + the goal you can combine streams, change protocols and cloud provision, and + reflect that in the device's JSON policy document without having to change + any code. + + - NEW: lws_system: New lightweight and efficient Asynchronous DNS resolver + implementation for both A and AAAA records, supports recursive (without + recursion in code) lookups, caching, and getaddrinfo() compatible results + scheme (from cache directly without per-consumer allocation). Able to + perform DNS lookups without introducing latency in the event loop. + + - NEW: lws_system: ntpclient implementation with interface for setting system + time via lws_system ops + + - NEW: lws_system: dhcpclient implementation + + - NEW: Connection validity tracking, autoproduce PING/PONG for protocols that + support it if not informed that the connection has passed data in both + directions recently enough + + - NEW: lws_retry: standardized exponential backoff and retry timing based + around backoff table and lws_sul + + - NEW: there are official public helpers for unaligned de/serialization of all + common types, see eh, lws_ser_wu16be() in include/libwebsockets/lws-misc.h + + - NEW: lws_tls_client_vhost_extra_cert_mem() api allows attaching extra certs + to a client vhost from DER in memory + + - NEW: lws_system: generic blobs support passing auth tokens, per-connection + client certs etc from platform into lws + + - NEW: public helpers to consume and produce ipv4/6 addresses in a clean way, + along with lws_sockaddr46 type now public. See eg, lws_sockaddr46-based + lws_sa46_parse_numeric_address(), lws_write_numeric_address() + in include/libwebsockets/lws-network-helper.h + + - Improved client redirect handling, h2 compatibility + + - NEW: lwsac: additional features for constant folding support (strings that + already are in the lwsac can be pointed to without copying again), backfill + (look for gaps in previous chunks that could take a new use size), and + lwsac_extend() so last use() can attempt to use more unallocated chunk space + + - NEW: lws_humanize: apis for reporting scalar quanties like 1234 as "1.234KB" + with the scaled symbol strings passed in by caller + + - NEW: freertos: support lws_cancel_service() by using UDP pair bound to lo, + since it doesn't have logical pipes + + - NEW: "esp32" plat, which implemented freertos plat compatibility on esp32, is + renamed to "freertos" plat, targeting esp32 and other freertos platforms + + - NEW: base64 has an additional api supporting stateful decode, where the input + is not all in the same place at the same time and can be processed + incrementally + + - NEW: lws ws proxy: support RFC8441 + + - NEW: lws_spawn_piped apis: generic support for vforking a process with child + wsis attached to its stdin, stdout and stderr via pipes. When processes are + reaped, a specified callback is triggered. Currently Linux + OSX. + + - NEW: lws_fsmount apis: Linux-only overlayfs mount and unmount management for + aggregating read-only layers with disposable, changeable upper layer fs + + - Improvements for RTOS / small build case bring the footprint of lws v4 below + that of v3.1 on ARM + + - lws_tokenize: flag specifying # should mark rest of line as comment + + - NEW: minimal example for integrating libasound / alsa via raw file + + - lws_struct: sqlite and json / lejp translation now usable + + v3.2.0 ====== @@ -445,627 +626,4 @@ See README.coding.md -v2.1.0 -====== - -Major new features - - - Support POST arguments, including multipart and file attachment - - - Move most of lwsws into lws, make the stub CC0 - - - Add loopback test plugin to confirm client ws / http coexistence - - - Integrate lwsws testing on Appveyor (ie, windows) - - - Introduce helpers for sql, urlencode and urldecode sanitation - - - Introduce LWS_CALLBACK_HTTP_BIND_PROTOCOL / DROP_PROTOCOL that - are compatible with http:/1.1 pipelining and different plugins - owning different parts of the URL space - - - lwsgs - Generic Sessions plugin supports serverside sessions, - cookies, hashed logins, forgot password etc - - - Added APIs for sending email to SMTP servers - - - Messageboard example plugin for lwsgs - - - Automatic PING sending at fixed intervals and close if no response - - - Change default header limit in ah to 4096 (from 1024) - - - Add SNI matching for wildcards if no specific wildcard vhost name match - - - Convert docs to Doxygen - - - ESP8266 support ^^ - -Fixes ------ - -See git log v2.0.0.. - - - -v2.0.0 -====== - -Summary -------- - - - There are only api additions, the api is compatible with v1.7.x. But - there is necessarily an soname bump to 8. - - - If you are using lws client, you mainly need to be aware the option - LWS_SERVER_OPTION_DO_SSL_GLOBAL_INIT is needed at context-creation time - if you will use SSL. - - - If you are using lws for serving, the above is also true but there are - many new features to simplify your code (and life). There is a - summany online here - - https://libwebsockets.org/lws-2.0-new-features.html - - but basically the keywords are vhosts, mounts and plugins. You can now - do the web serving part from lws without any user callback code at all. - See ./test-server/test-server-v2.0.c for an example, it has no user - code for ws either since it uses the protocol plugins... that one C file - is all that is needed to do the whole test server function. - - You now have the option to use a small generic ws-capable webserver - "lwsws" and write your ws part as a plugin. That eliminates even - cut-and-pasting the test server code and offers more configurable - features like control over http cacheability in JSON. - - -Fixes ------ - -These are already in 1.7.x series - -1) MAJOR (Windows-only) fix assert firing - -2) MAJOR http:/1.1 connections handled by lws_return_http_status() did not -get sent a content-length resulting in the link hanging until the peer closed -it. attack.sh updated to add a test for this. - -3) MINOR An error about hdr struct in _lws_ws_related is corrected, it's not -known to affect anything until after it was fixed - -4) MINOR During the close shutdown wait state introduced at v1.7, if something -requests callback on writeable for the socket it will busywait until the -socket closes - -5) MAJOR Although the test server has done it for a few versions already, it -is now required for the user code to explicitly call - - if (lws_http_transaction_completed(wsi)) - return -1; - -when it finishes replying to a transaction in http. Previously the library -did it for you, but that disallowed large, long transfers with multiple -trips around the event loop (and cgi...). - -6) MAJOR connections on ah waiting list that closed did not get removed from -the waiting list... - -7) MAJOR since we added the ability to hold an ah across http keepalive -transactions where more headers had already arrived, we broke the ability -to tell if more headers had arrived. Result was if the browser didn't -close the keepalive, we retained ah for the lifetime of the keepalive, -using up the pool. - -8) MAJOR windows-only-POLLHUP was not coming - -9) Client should not send ext hdr if no exts - -Changes -------- - -1) MINOR test-server gained some new switches - - -C use external SSL cert file - -K use external SSL key file - -A use external SSL CA cert file - - -u set effective uid - -g set effective gid - -together you can use them like this to have the test-server work with the -usual purchased SSL certs from an official CA. - - --ssl -C your.crt -K your.key -A your.cer -u 99 -g 99 - -2) MINOR the OpenSSL magic to setup ECDH cipher usage is implemented in the -library, and the ciphers restricted to use ECDH only. -Using this, the lws test server can score an A at SSLLABS test - -3) MINOR STS (SSL always) header is added to the test server if you use --ssl. With -that, we score A+ at SSLLABS test - -4) MINOR daemonize function (disabled at cmake by default) is updated to work -with systemd - -5) MINOR example systemd .service file now provided for test server -(not installed by default) - -6) test server html is updated with tabs and a new live server monitoring -feature. Input sanitization added to the js. - -7) client connections attempted when no ah is free no longer fail, they are -just deferred until an ah becomes available. - -8) The test client pays attention to if you give it an http:/ or https:// -protocol string to its argument in URL format. If so, it stays in http[s] -client mode and doesn't upgrade to ws[s], allowing you to do generic http client -operations. Receiving transfer-encoding: chunked is supported. - -9) If you enable -DLWS_WITH_HTTP_PROXY=1 at cmake, the test server has a -new URI path http://localhost:7681/proxytest If you visit here, a client -connection to http://example.com:80 is spawned, and the results piped on -to your original connection. - -10) Also with LWS_WITH_HTTP_PROXY enabled at cmake, lws wants to link to an -additional library, "libhubbub". This allows lws to do html rewriting on the -fly, adjusting proxied urls in a lightweight and fast way. - -11) There's a new context creation flag LWS_SERVER_OPTION_DO_SSL_GLOBAL_INIT, -this is included automatically if you give any other SSL-related option flag. -If you give no SSL-related option flag, nor this one directly, then even -though SSL support may be compiled in, it is never initialized nor used for the -whole lifetime of the lws context. - -Conversely in order to prepare the context to use SSL, even though, eg, you -are not listening on SSL but will use SSL client connections later, you must -give this flag explicitly to make sure SSL is initialized. - - -User API additions ------------------- - -1) MINOR APIBREAK There's a new member in struct lws_context_creation_info, ecdh_curve, -which lets you set the name of the ECDH curve OpenSSL should use. By -default (if you leave ecdh_curve NULL) it will use "prime256v1" - -2) MINOR NEWAPI It was already possible to adopt a foreign socket that had not -been read from using lws_adopt_socket() since v1.7. Now you can adopt a -partially-used socket if you don't need SSL, by passing it what you read -so it can drain that before reading from the socket. - -LWS_VISIBLE LWS_EXTERN struct lws * -lws_adopt_socket_readbuf(struct lws_context *context, lws_sockfd_type accept_fd, - const char *readbuf, size_t len); - -3) MINOR NEWAPI CGI type "network io" subprocess execution is now possible from -a simple api. - -LWS_VISIBLE LWS_EXTERN int -lws_cgi(struct lws *wsi, char * const *exec_array, int script_uri_path_len, - int timeout_secs); - -LWS_VISIBLE LWS_EXTERN int -lws_cgi_kill(struct lws *wsi); - -To use it, you must first set the cmake option - -$ cmake .. -DLWS_WITH_CGI=1 - -See test-server-http.c and test server path - -http://localhost:7681/cgitest - -stdin gets http body, you can test it with wget - -$ echo hello > hello.txt -$ wget http://localhost:7681/cgitest --post-file=hello.txt -O- --quiet -lwstest script -read="hello" - -The test script returns text/html table showing /proc/meminfo. But the cgi -support is complete enough to run cgit cgi. - -4) There is a helper api for forming logging timestamps - -LWS_VISIBLE int -lwsl_timestamp(int level, char *p, int len) - -this generates this kind of timestamp for use as logging preamble - -lwsts[13116]: [2016/01/25 14:52:52:8386] NOTICE: Initial logging level 7 - -5) struct lws_client_connect_info has a new member - - const char *method - -If it's NULL, then everything happens as before, lws_client_connect_via_info() -makes a ws or wss connection to the address given. - -If you set method to a valid http method like "GET", though, then this method -is used and the connection remains in http[s], it's not upgraded to ws[s]. - -So with this, you can perform http[s] client operations as well as ws[s] ones. - -There are 4 new related callbacks - - LWS_CALLBACK_ESTABLISHED_CLIENT_HTTP = 44, - LWS_CALLBACK_CLOSED_CLIENT_HTTP = 45, - LWS_CALLBACK_RECEIVE_CLIENT_HTTP = 46, - LWS_CALLBACK_COMPLETED_CLIENT_HTTP = 47, - -6) struct lws_client_connect_info has a new member - - const char *parent_wsi - -if non-NULL, the client wsi is set to be a child of parent_wsi. This ensures -if parent_wsi closes, then the client child is closed just before. - -7) If you're using SSL, there's a new context creation-time option flag -LWS_SERVER_OPTION_REDIRECT_HTTP_TO_HTTPS. If you give this, non-ssl -connections to the server listen port are accepted and receive a 301 -redirect to / on the same host and port using https:// - -8) User code may set per-connection extension options now, using a new api -"lws_set_extension_option()". - -This should be called from the ESTABLISHED callback like this - - lws_set_extension_option(wsi, "permessage-deflate", - "rx_buf_size", "12"); /* 1 << 12 */ - -If the extension is not active (missing or not negotiated for the -connection, or extensions are disabled on the library) the call is -just returns -1. Otherwise the connection's extension has its -named option changed. - -The extension may decide to alter or disallow the change, in the -example above permessage-deflate restricts the size of his rx -output buffer also considering the protocol's rx_buf_size member. - - -New application lwsws ---------------------- - -A libwebsockets-based general webserver is built by default now, lwsws. - -It's configured by JSON, by default in - - /etc/lwsws/conf - -which contains global lws context settings like this - -{ - "global": { - "uid": "99", - "gid": "99", - "interface": "eth0", - "count-threads": "1" - } -} - - /etc/lwsws/conf.d/* - -which contains zero or more files describing vhosts, like this - -{ - "vhosts": [ - { "name": "warmcat.com", - "port": "443", - "host-ssl-key": "/etc/pki/tls/private/warmcat.com.key", - "host-ssl-cert": "/etc/pki/tls/certs/warmcat.com.crt", - "host-ssl-ca": "/etc/pki/tls/certs/warmcat.com.cer", - "mounts": [ - { "/": [ - { "home": "file:///var/www/warmcat.com" }, - { "default": "index.html" } - ] - } - ] - } - ] -} - - - -v1.7.0 -====== - -Extension Changes ------------------ - -1) There is now a "permessage-deflate" / RFC7692 implementation. It's very -similar to "deflate-frame" we have offered for a long while; deflate-frame is -now provided as an alias of permessage-deflate. - -The main differences are that the new permessage-deflate implementation: - - - properly performs streaming respecting input and output buffer limits. The - old deflate-frame implementation could only work on complete deflate input - and produce complete inflate output for each frame. The new implementation - only mallocs buffers at initialization. - - - goes around the event loop after each input package is processed allowing - interleaved output processing. The RX flow control api can be used to - force compressed input processing to match the rate of compressed output - processing (test--echo shows an example of how to do this). - - - when being "deflate-frame" for compatibility he uses the same default zlib - settings as the old "deflate-frame", but instead of exponentially increasing - malloc allocations until the whole output will fit, he observes the default - input and output chunking buffer sizes of "permessage-deflate", that's - 1024 in and 1024 out at a time. - -2) deflate-stream has been disabled for many versions (for over a year) and is -now removed. Browsers are now standardizing on "permessage-deflate" / RFC7692 - -3) struct lws_extension is simplified, and lws extensions now have a public -api (their callback) for use in user code to compose extensions and options -the user code wants. lws_get_internal_exts() is deprecated but kept around -as a NOP. The changes allow one extension implementation to go by different -names and allows the user client code to control option offers per-ext. - -The test client and server are updated to use the new way. If you use -the old way it should still work, but extensions will be disabled until you -update your code. - -Extensions are now responsible for allocating and per-instance private struct -at instance construction time and freeing it when the instance is destroyed. -Not needing to know the size means the extension's struct can be opaque -to user code. - - -User api additions ------------------- - -1) The info struct gained three new members - - - max_http_header_data: 0 for default (1024) or set the maximum amount of known - http header payload that lws can deal with. Payload in unknown http - headers is dropped silently. If for some reason you need to send huge - cookies or other HTTP-level headers, you can now increase this at context- - creation time. - - - max_http_header_pool: 0 for default (16) or set the maximum amount of http - headers that can be tracked by lws in this context. For the server, if - the header pool is completely in use then accepts on the listen socket - are disabled until one becomes free. For the client, if you simultaneously - have pending connects for more than this number of client connections, - additional connects will fail until some of the pending connections timeout - or complete. - - - timeout_secs: 0 for default (currently 20s), or set the library's - network activity timeout to the given number of seconds - -HTTP header processing in lws only exists until just after the first main -callback after the HTTP handshake... for ws connections that is ESTABLISHED and -for HTTP connections the HTTP callback. - -So these settings are not related to the maximum number of simultaneous -connections, but the number of HTTP handshakes that may be expected or ongoing, -or have just completed, at one time. The reason it's useful is it changes the -memory allocation for header processing to be one-time at context creation -instead of every time there is a new connection, and gives you control over -the peak allocation. - -Setting max_http_header_pool to 1 is fine it will just queue incoming -connections before the accept as necessary, you can still have as many -simultaneous post-header connections as you like. Since the http header -processing is completed and the allocation released after ESTABLISHED or the -HTTP callback, even with a pool of 1 many connections can be handled rapidly. - -2) There is a new callback that allows the user code to get acccess to the -optional close code + aux data that may have been sent by the peer. - -LWS_CALLBACK_WS_PEER_INITIATED_CLOSE: - The peer has sent an unsolicited Close WS packet. @in and - @len are the optional close code (first 2 bytes, network - order) and the optional additional information which is not - defined in the standard, and may be a string or non-human- - readble data. - If you return 0 lws will echo the close and then close the - connection. If you return nonzero lws will just close the - connection. - -As usual not handling it does the right thing, if you're not interested in it -just ignore it. - -The test server has "open and close" testing buttons at the bottom, if you -open and close that connection, on close it will send a close code 3000 decimal -and the string "Bye!" as the aux data. - -The test server dumb-increment callback handles this callback reason and prints - -lwsts[15714]: LWS_CALLBACK_WS_PEER_INITIATED_CLOSE: len 6 -lwsts[15714]: 0: 0x0B -lwsts[15714]: 1: 0xB8 -lwsts[15714]: 2: 0x42 -lwsts[15714]: 3: 0x79 -lwsts[15714]: 4: 0x65 -lwsts[15714]: 5: 0x21 - -3) There is a new API to allow the user code to control the content of the -close frame sent when about to return nonzero from the user callback to -indicate the connection should close. - -/** - * lws_close_reason - Set reason and aux data to send with Close packet - * If you are going to return nonzero from the callback - * requesting the connection to close, you can optionally - * call this to set the reason the peer will be told if - * possible. - * - * @wsi: The websocket connection to set the close reason on - * @status: A valid close status from websocket standard - * @buf: NULL or buffer containing up to 124 bytes of auxiliary data - * @len: Length of data in @buf to send - */ -LWS_VISIBLE LWS_EXTERN void -lws_close_reason(struct lws *wsi, enum lws_close_status status, - unsigned char *buf, size_t len); - -An extra button is added to the "open and close" test server page that requests -that the test server close the connection from his end. - -The test server code will do so by - - lws_close_reason(wsi, LWS_CLOSE_STATUS_GOINGAWAY, - (unsigned char *)"seeya", 5); - return -1; - -The browser shows the close code and reason he received - -websocket connection CLOSED, code: 1001, reason: seeya - -4) There's a new context creation time option flag - -LWS_SERVER_OPTION_VALIDATE_UTF8 - -if you set it in info->options, then TEXT and CLOSE frames will get checked to -confirm that they contain valid UTF-8. If they don't, the connection will get -closed by lws. - -5) ECDH Certs are now supported. Enable the CMake option - -cmake .. -DLWS_SSL_SERVER_WITH_ECDH_CERT=1 - -**and** the info->options flag - -LWS_SERVER_OPTION_SSL_ECDH - -to build in support and select it at runtime. - -6) There's a new api lws_parse_uri() that simplifies chopping up -https://xxx:yyy/zzz uris into parts nicely. The test client now uses this -to allow proper uris as well as the old address style. - -7) SMP support is integrated into LWS without any internal threading. It's -very simple to use, libwebsockets-test-server-pthread shows how to do it, -use -j argument there to control the number of service threads up to 32. - -Two new members are added to the info struct - - unsigned int count_threads; - unsigned int fd_limit_per_thread; - -leave them at the default 0 to get the normal singlethreaded service loop. - -Set count_threads to n to tell lws you will have n simultaneous service threads -operating on the context. - -There is still a single listen socket on one port, no matter how many -service threads. - -When a connection is made, it is accepted by the service thread with the least -connections active to perform load balancing. - -The user code is responsible for spawning n threads running the service loop -associated to a specific tsi (Thread Service Index, 0 .. n - 1). See -the libwebsockets-test-server-pthread for how to do. - -If you leave fd_limit_per_thread at 0, then the process limit of fds is shared -between the service threads; if you process was allowed 1024 fds overall then -each thread is limited to 1024 / n. - -You can set fd_limit_per_thread to a nonzero number to control this manually, eg -the overall supported fd limit is less than the process allowance. - -You can control the context basic data allocation for multithreading from Cmake -using -DLWS_MAX_SMP=, if not given it's set to 32. The serv_buf allocation -for the threads (currently 4096) is made at runtime only for active threads. - -Because lws will limit the requested number of actual threads supported -according to LWS_MAX_SMP, there is an api lws_get_count_threads(context) to -discover how many threads were actually allowed when the context was created. - -It's required to implement locking in the user code in the same way that -libwebsockets-test-server-pthread does it, for the FD locking callbacks. - -If LWS_MAX_SMP=1, then there is no code related to pthreads compiled in the -library. If more than 1, a small amount of pthread mutex code is built into -the library. - -8) New API - -LWS_VISIBLE struct lws * -lws_adopt_socket(struct lws_context *context, lws_sockfd_type accept_fd) - -allows foreign sockets accepted by non-lws code to be adopted by lws as if they -had just been accepted by lws' own listen socket. - -9) X-Real-IP: header has been added as WSI_TOKEN_HTTP_X_REAL_IP - -10) Libuv support is added, there are new related user apis - -typedef void (lws_uv_signal_cb_t)(uv_loop_t *l, uv_signal_t *w, int revents); - -LWS_VISIBLE LWS_EXTERN int -lws_uv_sigint_cfg(struct lws_context *context, int use_uv_sigint, - lws_uv_signal_cb_t *cb); - -LWS_VISIBLE LWS_EXTERN int -lws_uv_initloop(struct lws_context *context, uv_loop_t *loop, int tsi); - -LWS_VISIBLE void -lws_uv_sigint_cb(uv_loop_t *loop, uv_signal_t *watcher, int revents); - -and CMAKE option - -LWS_WITH_LIBUV - - -User api changes ----------------- - -1) LWS_SEND_BUFFER_POST_PADDING is now 0 and deprecated. You can remove it; if -you still use it, obviously it does nothing. Old binary code with nonzero -LWS_SEND_BUFFER_POST_PADDING is perfectly compatible, the old code just -allocated a buffer bigger than the library is going to use. - -The example apps no longer use LWS_SEND_BUFFER_POST_PADDING. - -The only path who made use of it was sending with LWS_WRITE_CLOSE ---> - -2) Because of lws_close_reason() formalizing handling close frames, -LWS_WRITE_CLOSE is removed from libwebsockets.h. It was only of use to send -close frames...close frame content should be managed using lws_close_reason() -now. - -3) We check for invalid CLOSE codes and complain about protocol violation in -our close code. But it changes little since we were in the middle of closing -anyway. - -4) zero-length RX frames and zero length TX frames are now allowed. - -5) Pings and close used to be limited to 124 bytes, the correct limit is 125 -so that is now also allowed. - -6) LWS_PRE is provided as a synonym for LWS_SEND_BUFFER_PRE_PADDING, either is -valid to use now. - -7) There's generic support for RFC7462 style extension options built into the -library now. As a consequence, a field "options" is added to lws_extension. -It can be NULL if there are no options on the extension. Extension internal -info is part of the public abi because extensions may be implemented outside -the library. - -8) WSI_TOKEN_PROXY enum was accidentally defined to collide with another token -of value 73. That's now corrected and WSI_TOKEN_PROXY moved to his own place at -77. - -9) With the addition of libuv support, libev is not the only event loop -library in town and his api names must be elaborated with _ev_ - - Callback typedef: lws_signal_cb ---> lws_ev_signal_cb_t - lws_sigint_cfg --> lws_ev_sigint_cfg - lws_initloop --> lws_ev_initloop - lws_sigint_cb --> lws_ev_sigint_cb - -10) Libev support is made compatible with multithreaded service, -lws_ev_initloop (was lws_initloop) gets an extra argument for the -thread service index (use 0 if you will just have 1 service thread). - -LWS_VISIBLE LWS_EXTERN int -lws_ev_initloop(struct lws_context *context, ev_loop_t *loop, int tsi); - - (for earlier changelogs, see the tagged releases) diff -Nru libwebsockets-3.2.1/cmake/FindLibWebSockets.cmake libwebsockets-4.1.6/cmake/FindLibWebSockets.cmake --- libwebsockets-3.2.1/cmake/FindLibWebSockets.cmake 2019-12-18 14:45:31.000000000 +0000 +++ libwebsockets-4.1.6/cmake/FindLibWebSockets.cmake 1970-01-01 00:00:00.000000000 +0000 @@ -1,33 +0,0 @@ -# This module tries to find libWebsockets library and include files -# -# LIBWEBSOCKETS_INCLUDE_DIR, path where to find libwebsockets.h -# LIBWEBSOCKETS_LIBRARY_DIR, path where to find libwebsockets.so -# LIBWEBSOCKETS_LIBRARIES, the library to link against -# LIBWEBSOCKETS_FOUND, If false, do not try to use libWebSockets -# -# This currently works probably only for Linux - -FIND_PATH ( LIBWEBSOCKETS_INCLUDE_DIR libwebsockets.h - /usr/local/include - /usr/include -) - -FIND_LIBRARY ( LIBWEBSOCKETS_LIBRARIES websockets - /usr/local/lib - /usr/lib -) - -GET_FILENAME_COMPONENT( LIBWEBSOCKETS_LIBRARY_DIR ${LIBWEBSOCKETS_LIBRARIES} PATH ) - -SET ( LIBWEBSOCKETS_FOUND "NO" ) -IF ( LIBWEBSOCKETS_INCLUDE_DIR ) - IF ( LIBWEBSOCKETS_LIBRARIES ) - SET ( LIBWEBSOCKETS_FOUND "YES" ) - ENDIF ( LIBWEBSOCKETS_LIBRARIES ) -ENDIF ( LIBWEBSOCKETS_INCLUDE_DIR ) - -MARK_AS_ADVANCED( - LIBWEBSOCKETS_LIBRARY_DIR - LIBWEBSOCKETS_INCLUDE_DIR - LIBWEBSOCKETS_LIBRARIES -) \ No newline at end of file diff -Nru libwebsockets-3.2.1/cmake/FindOpenSSLbins.cmake libwebsockets-4.1.6/cmake/FindOpenSSLbins.cmake --- libwebsockets-3.2.1/cmake/FindOpenSSLbins.cmake 2019-12-18 14:45:31.000000000 +0000 +++ libwebsockets-4.1.6/cmake/FindOpenSSLbins.cmake 2020-12-01 17:40:26.000000000 +0000 @@ -1,42 +1,102 @@ - -if(OPENSSL_FOUND) - - find_program(OPENSSL_EXECUTABLE openssl openssl.exe bin/openssl.exe - HINTS ${_OPENSSL_ROOT_HINTS} - PATH - /usr/bin/ - bin/ - DOC "Openssl executable") - - mark_as_advanced(OPENSSL_EXECUTABLE) - - # On Windows, we need to copy the OpenSSL dlls - # to the output directory. - if(WIN32) - set(OPENSSL_BIN_FOUND 0) - - find_file(LIBEAY_BIN - NAMES - libeay32.dll - HINTS - ${_OPENSSL_ROOT_HINTS} - PATH_SUFFIXES - bin) - - find_file(SSLEAY_BIN - NAMES - ssleay32.dll - HINTS - ${_OPENSSL_ROOT_HINTS} - PATH_SUFFIXES - bin) - - if(LIBEAY_BIN) - if(SSLEAY_BIN) - set(OPENSSL_BIN_FOUND 1) - endif(SSLEAY_BIN) - endif(LIBEAY_BIN) - endif(WIN32) - -endif(OPENSSL_FOUND) - + +if(OPENSSL_FOUND) + + find_program(OPENSSL_EXECUTABLE openssl openssl.exe bin/openssl.exe + HINTS ${_OPENSSL_ROOT_HINTS} + PATH + /usr/bin/ + bin/ + DOC "Openssl executable") + + mark_as_advanced(OPENSSL_EXECUTABLE) + + # On Windows, we need to copy the OpenSSL dlls + # to the output directory. + # BUT only if non-static libs (referencing dlls) are used + # In this case + # ** we only want to find dlls that are compatible with the libs + # the assumption is that these are part of the same OpenSSL package + # and typically reside in the same or in a close by directory as the executable + # ** we do NOT want to find dlls in general dll directories such as C:\Windows\systemXX + # because these IN GENERAL are not compatible with the libs + if(WIN32 AND OPENSSL_VERSION) + set(OPENSSL_BIN_FOUND 0) + + # we check for OpenSSL versioning, as described in https://wiki.openssl.org/index.php/Versioning + string(REGEX MATCH "^([0-9]+)\\.([0-9]+)\\.(.*)$" REGEX_MATCH ${OPENSSL_VERSION}) + + if (NOT ${REGEX_MATCH} EQUAL "") + + message(DEBUG "Assuming OpenSSL release ${OPENSSL_VERSION} >= 1.1.0 for dll discovery") + + # the regex matched - so we assume OpenSSL release >= 1.1 + set(OVNR "${CMAKE_MATCH_1}") # OpenSSL version number + set(ORNR "${CMAKE_MATCH_2}") # OpenSSL release number + set(CRYPTO32_NAME "libcrypto-${OVNR}_${ORNR}.dll") + set(CRYPTO64_NAME "libcrypto-${OVNR}_${ORNR}-x64.dll") + message(VERBOSE "CRYPTO32_NAME=${CRYPTO32_NAME}") + message(VERBOSE "CRYPTO64_NAME=${CRYPTO64_NAME}") + set(SSL32_NAME "libssl-${OVNR}_${ORNR}.dll") + set(SSL64_NAME "libssl-${OVNR}_${ORNR}-x64.dll") + message(VERBOSE "SSL32_NAME=${SSL32_NAME}") + message(VERBOSE "SSL64_NAME=${SSL64_NAME}") + + get_filename_component(OPENSSL_EXECUTABLE_PATH ${OPENSSL_EXECUTABLE} DIRECTORY) + message(VERBOSE "OPENSSL_EXECUTABLE_PATH=${OPENSSL_EXECUTABLE_PATH}") + set(OPENSSL_EXECUTABLE_BIN_PATH "") + string(REGEX MATCH "^(.*)/tools/openssl$" REGEX_MATCH ${OPENSSL_EXECUTABLE_PATH}) + message(DEBUG "REGEX_MATCH=\"${REGEX_MATCH}\"") + message(DEBUG "CMAKE_MATCH_1=\"${CMAKE_MATCH_1}\"") + if (NOT ${REGEX_MATCH} EQUAL "") + set(OPENSSL_EXECUTABLE_BIN_PATH "${CMAKE_MATCH_1}/bin") # bin path of this openssl variant + endif() + message(VERBOSE "OPENSSL_EXECUTABLE_BIN_PATH=${OPENSSL_EXECUTABLE_BIN_PATH}") + + unset(LIBCRYPTO_BIN) # clear + unset(LIBCRYPTO_BIN CACHE) # clear as well, because otherwise find_file might use it + find_file(LIBCRYPTO_BIN + NO_DEFAULT_PATH + NAMES ${CRYPTO32_NAME} ${CRYPTO64_NAME} + PATHS ${OPENSSL_EXECUTABLE_PATH} ${OPENSSL_EXECUTABLE_BIN_PATH} + ) + message(VERBOSE "LIBCRYPTO_BIN=${LIBCRYPTO_BIN}") + + unset(LIBSSL_BIN) # clear + unset(LIBSSL_BIN CACHE) # clear as well, because otherwise find_file might use it + find_file(LIBSSL_BIN + NO_DEFAULT_PATH + NAMES ${SSL32_NAME} ${SSL64_NAME} + PATHS ${OPENSSL_EXECUTABLE_PATH} ${OPENSSL_EXECUTABLE_BIN_PATH} + ) + message(VERBOSE "LIBSSL_BIN=${LIBSSL_BIN}") + + else() # the version regex did not match + + # as a fallback, we check for "old" OpenSSL library (used before OpenSSL 1.1.0) + + find_file(LIBCRYPTO_BIN + NAMES + libeay32.dll + HINTS + ${_OPENSSL_ROOT_HINTS} + PATH_SUFFIXES + bin) + + find_file(LIBSSL_BIN + NAMES + ssleay32.dll + HINTS + ${_OPENSSL_ROOT_HINTS} + PATH_SUFFIXES + bin) + + endif() + + if(LIBCRYPTO_BIN AND LIBSSL_BIN) + set(OPENSSL_BIN_FOUND 1) + endif() + + endif(WIN32) + +endif(OPENSSL_FOUND) + diff -Nru libwebsockets-3.2.1/cmake/libwebsockets-config.cmake.in libwebsockets-4.1.6/cmake/libwebsockets-config.cmake.in --- libwebsockets-3.2.1/cmake/libwebsockets-config.cmake.in 1970-01-01 00:00:00.000000000 +0000 +++ libwebsockets-4.1.6/cmake/libwebsockets-config.cmake.in 2020-12-01 17:40:26.000000000 +0000 @@ -0,0 +1,23 @@ +# - Config file for lws + +# It defines the following variables +# LIBWEBSOCKETS_INCLUDE_DIRS - include directories for FooBar +# LIBWEBSOCKETS_LIBRARIES - libraries to link against + +# Get the path of the current file. +get_filename_component(LWS_CMAKE_DIR "${CMAKE_CURRENT_LIST_FILE}" PATH) + +# Set the include directories. +set(LIBWEBSOCKETS_INCLUDE_DIRS "@LWS__INCLUDE_DIRS@") + +# Include the project Targets file, this contains definitions for IMPORTED targets. +include(${LWS_CMAKE_DIR}/LibwebsocketsTargets.cmake) + +# IMPORTED targets from LibwebsocketsTargets.cmake +set(LIBWEBSOCKETS_LIBRARIES websockets websockets_shared) + +# These are additional libs that lws wants your app to also link to +foreach(item "@LIB_LIST_AT_END@") + list(APPEND LIBWEBSOCKETS_DEP_LIBS ${item}) +endforeach() + diff -Nru libwebsockets-3.2.1/cmake/LibwebsocketsConfig.cmake.in libwebsockets-4.1.6/cmake/LibwebsocketsConfig.cmake.in --- libwebsockets-3.2.1/cmake/LibwebsocketsConfig.cmake.in 2019-12-18 14:45:31.000000000 +0000 +++ libwebsockets-4.1.6/cmake/LibwebsocketsConfig.cmake.in 1970-01-01 00:00:00.000000000 +0000 @@ -1,17 +0,0 @@ -# - Config file for the Libevent package -# It defines the following variables -# LIBWEBSOCKETS_INCLUDE_DIRS - include directories for FooBar -# LIBWEBSOCKETS_LIBRARIES - libraries to link against - -# Get the path of the current file. -get_filename_component(LWS_CMAKE_DIR "${CMAKE_CURRENT_LIST_FILE}" PATH) - -# Set the include directories. -set(LIBWEBSOCKETS_INCLUDE_DIRS "@LWS__INCLUDE_DIRS@") - -# Include the project Targets file, this contains definitions for IMPORTED targets. -include(${LWS_CMAKE_DIR}/LibwebsocketsTargets.cmake) - -# IMPORTED targets from LibwebsocketsTargets.cmake -set(LIBWEBSOCKETS_LIBRARIES websockets websockets_shared) - diff -Nru libwebsockets-3.2.1/cmake/libwebsockets-config-version.cmake.in libwebsockets-4.1.6/cmake/libwebsockets-config-version.cmake.in --- libwebsockets-3.2.1/cmake/libwebsockets-config-version.cmake.in 1970-01-01 00:00:00.000000000 +0000 +++ libwebsockets-4.1.6/cmake/libwebsockets-config-version.cmake.in 2020-12-01 17:40:26.000000000 +0000 @@ -0,0 +1,11 @@ +set(PACKAGE_VERSION "@CPACK_PACKAGE_VERSION@") + +# Check whether the requested PACKAGE_FIND_VERSION is compatible +if("${PACKAGE_VERSION}" VERSION_LESS "${PACKAGE_FIND_VERSION}") + set(PACKAGE_VERSION_COMPATIBLE FALSE) +else() + set(PACKAGE_VERSION_COMPATIBLE TRUE) + if ("${PACKAGE_VERSION}" VERSION_EQUAL "${PACKAGE_FIND_VERSION}") + set(PACKAGE_VERSION_EXACT TRUE) + endif() +endif() diff -Nru libwebsockets-3.2.1/cmake/LibwebsocketsConfigVersion.cmake.in libwebsockets-4.1.6/cmake/LibwebsocketsConfigVersion.cmake.in --- libwebsockets-3.2.1/cmake/LibwebsocketsConfigVersion.cmake.in 2019-12-18 14:45:31.000000000 +0000 +++ libwebsockets-4.1.6/cmake/LibwebsocketsConfigVersion.cmake.in 1970-01-01 00:00:00.000000000 +0000 @@ -1,11 +0,0 @@ -set(PACKAGE_VERSION "@CPACK_PACKAGE_VERSION@") - -# Check whether the requested PACKAGE_FIND_VERSION is compatible -if("${PACKAGE_VERSION}" VERSION_LESS "${PACKAGE_FIND_VERSION}") - set(PACKAGE_VERSION_COMPATIBLE FALSE) -else() - set(PACKAGE_VERSION_COMPATIBLE TRUE) - if ("${PACKAGE_VERSION}" VERSION_EQUAL "${PACKAGE_FIND_VERSION}") - set(PACKAGE_VERSION_EXACT TRUE) - endif() -endif() diff -Nru libwebsockets-3.2.1/cmake/LwsCheckRequirements.cmake libwebsockets-4.1.6/cmake/LwsCheckRequirements.cmake --- libwebsockets-3.2.1/cmake/LwsCheckRequirements.cmake 1970-01-01 00:00:00.000000000 +0000 +++ libwebsockets-4.1.6/cmake/LwsCheckRequirements.cmake 2020-12-01 17:40:26.000000000 +0000 @@ -0,0 +1,76 @@ +# 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() + +MACRO(require_pthreads result) + CHECK_INCLUDE_FILE(pthread.h LWS_HAVE_PTHREAD_H) + if (NOT LWS_HAVE_PTHREAD_H) + if (LWS_WITH_MINIMAL_EXAMPLES) + set(${result} 0) + message("${SAMP}: skipping as no pthreads") + else() + message(FATAL_ERROR "threading support requires pthreads") + endif() + else() + if (WIN32) + set(PTHREAD_LIB ${LWS_EXT_PTHREAD_LIBRARIES}) + else() + set(PTHREAD_LIB pthread) + endif() + endif() +ENDMACRO() + diff -Nru libwebsockets-3.2.1/cmake/lws_config.h.in libwebsockets-4.1.6/cmake/lws_config.h.in --- libwebsockets-3.2.1/cmake/lws_config.h.in 2019-12-18 14:45:31.000000000 +0000 +++ libwebsockets-4.1.6/cmake/lws_config.h.in 2020-12-01 17:40:26.000000000 +0000 @@ -7,18 +7,28 @@ #endif #define LWS_INSTALL_DATADIR "${CMAKE_INSTALL_PREFIX}/share" +#define LWS_INSTALL_LIBDIR "${CMAKE_INSTALL_PREFIX}/${LWS_INSTALL_LIB_DIR}${LIB_SUFFIX}" #define LWS_LIBRARY_VERSION_MAJOR ${LWS_LIBRARY_VERSION_MAJOR} #define LWS_LIBRARY_VERSION_MINOR ${LWS_LIBRARY_VERSION_MINOR} +#define LWS_LIBRARY_VERSION_PATCH_ELABORATED ${LWS_LIBRARY_VERSION_PATCH_ELABORATED} #define LWS_LIBRARY_VERSION_PATCH ${LWS_LIBRARY_VERSION_PATCH} + /* LWS_LIBRARY_VERSION_NUMBER looks like 1005001 for e.g. version 1.5.1 */ #define LWS_LIBRARY_VERSION_NUMBER (LWS_LIBRARY_VERSION_MAJOR * 1000000) + \ (LWS_LIBRARY_VERSION_MINOR * 1000) + \ LWS_LIBRARY_VERSION_PATCH #define LWS_MAX_SMP ${LWS_MAX_SMP} +#cmakedefine LWS_ESP_PLATFORM +#cmakedefine LWS_LIBRARY_VERSION_NUMBER + +#cmakedefine LWS_EXT_PTHREAD_LIBRARIES + #cmakedefine LWS_AVOID_SIGPIPE_IGN #cmakedefine LWS_BUILD_HASH "${LWS_BUILD_HASH}" #cmakedefine LWS_BUILTIN_GETIFADDRS +#cmakedefine LWS_CLIENT_HTTP_PROXYING +#cmakedefine LWS_DETECTED_PLAT_IOS #cmakedefine LWS_FALLBACK_GETHOSTBYNAME #cmakedefine LWS_HAS_INTPTR_T #cmakedefine LWS_HAS_GETOPT_LONG @@ -37,25 +47,34 @@ #cmakedefine LWS_HAVE_EVP_aes_256_cfb8 #cmakedefine LWS_HAVE_EVP_aes_256_cfb128 #cmakedefine LWS_HAVE_EVP_aes_128_xts +#cmakedefine LWS_HAVE_EVP_PKEY_new_raw_private_key +#cmakedefine LWS_HAVE_EXECVPE #cmakedefine LWS_HAVE_LIBCAP #cmakedefine LWS_HAVE_HMAC_CTX_new #cmakedefine LWS_HAVE_MALLOC_H #cmakedefine LWS_HAVE_MALLOC_TRIM #cmakedefine LWS_HAVE_MALLOC_USABLE_SIZE +#cmakedefine LWS_HAVE_mbedtls_md_setup #cmakedefine LWS_HAVE_mbedtls_net_init +#cmakedefine LWS_HAVE_mbedtls_rsa_complete +#cmakedefine LWS_HAVE_mbedtls_internal_aes_encrypt #cmakedefine LWS_HAVE_mbedtls_ssl_conf_alpn_protocols #cmakedefine LWS_HAVE_mbedtls_ssl_get_alpn_protocol #cmakedefine LWS_HAVE_mbedtls_ssl_conf_sni #cmakedefine LWS_HAVE_mbedtls_ssl_set_hs_ca_chain #cmakedefine LWS_HAVE_mbedtls_ssl_set_hs_own_cert #cmakedefine LWS_HAVE_mbedtls_ssl_set_hs_authmode +#cmakedefine LWS_HAVE_MBEDTLS_NET_SOCKETS #cmakedefine LWS_HAVE_NEW_UV_VERSION_H #cmakedefine LWS_HAVE_OPENSSL_ECDH_H #cmakedefine LWS_HAVE_PIPE2 +#cmakedefine LWS_HAVE_EVENTFD #cmakedefine LWS_HAVE_PTHREAD_H #cmakedefine LWS_HAVE_RSA_SET0_KEY #cmakedefine LWS_HAVE_RSA_verify_pss_mgf1 #cmakedefine LWS_HAVE_SSL_CTX_get0_certificate +#cmakedefine LWS_HAVE_SSL_CTX_load_verify_file +#cmakedefine LWS_HAVE_SSL_CTX_load_verify_dir #cmakedefine LWS_HAVE_SSL_CTX_set1_param #cmakedefine LWS_HAVE_SSL_CTX_set_ciphersuites #cmakedefine LWS_HAVE_SSL_EXTRA_CHAIN_CERTS @@ -69,45 +88,62 @@ #cmakedefine LWS_HAVE_TLS_CLIENT_METHOD #cmakedefine LWS_HAVE_TLSV1_2_CLIENT_METHOD #cmakedefine LWS_HAVE_UV_VERSION_H +#cmakedefine LWS_HAVE_VFORK #cmakedefine LWS_HAVE_X509_get_key_usage #cmakedefine LWS_HAVE_X509_VERIFY_PARAM_set1_host -#cmakedefine LWS_LATENCY #cmakedefine LWS_LIBRARY_VERSION "${LWS_LIBRARY_VERSION}" +#define LWS_LOGGING_BITFIELD_CLEAR ${LWS_LOGGING_BITFIELD_CLEAR} +#define LWS_LOGGING_BITFIELD_SET ${LWS_LOGGING_BITFIELD_SET} #cmakedefine LWS_MINGW_SUPPORT #cmakedefine LWS_NO_CLIENT #cmakedefine LWS_NO_DAEMONIZE -#cmakedefine LWS_NO_SERVER #cmakedefine LWS_OPENSSL_CLIENT_CERTS "${LWS_OPENSSL_CLIENT_CERTS}" #cmakedefine LWS_OPENSSL_SUPPORT #cmakedefine LWS_PLAT_OPTEE #cmakedefine LWS_PLAT_UNIX +#cmakedefine LWS_PLAT_FREERTOS #cmakedefine LWS_ROLE_CGI #cmakedefine LWS_ROLE_DBUS #cmakedefine LWS_ROLE_H1 #cmakedefine LWS_ROLE_H2 #cmakedefine LWS_ROLE_RAW +#cmakedefine LWS_ROLE_RAW_FILE #cmakedefine LWS_ROLE_RAW_PROXY #cmakedefine LWS_ROLE_WS +#cmakedefine LWS_ROLE_MQTT #cmakedefine LWS_SHA1_USE_OPENSSL_NAME #cmakedefine LWS_SSL_CLIENT_USE_OS_CA_CERTS #cmakedefine LWS_SSL_SERVER_WITH_ECDH_CERT #cmakedefine LWS_WITH_ABSTRACT #cmakedefine LWS_WITH_ACCESS_LOG #cmakedefine LWS_WITH_ACME +#cmakedefine LWS_WITH_ALSA +#cmakedefine LWS_WITH_SYS_ASYNC_DNS #cmakedefine LWS_WITH_BORINGSSL #cmakedefine LWS_WITH_CGI #cmakedefine LWS_WITH_CUSTOM_HEADERS #cmakedefine LWS_WITH_DEPRECATED_LWS_DLL +#cmakedefine LWS_WITH_DETAILED_LATENCY #cmakedefine LWS_WITH_DIR +#cmakedefine LWS_WITH_DRIVERS #cmakedefine LWS_WITH_ESP32 +#cmakedefine LWS_HAVE_EVBACKEND_LINUXAIO +#cmakedefine LWS_HAVE_EVBACKEND_IOURING #cmakedefine LWS_WITH_EXTERNAL_POLL +#cmakedefine LWS_WITH_FILE_OPS +#cmakedefine LWS_WITH_FSMOUNT #cmakedefine LWS_WITH_FTS #cmakedefine LWS_WITH_GENCRYPTO #cmakedefine LWS_WITH_GENERIC_SESSIONS +#cmakedefine LWS_WITH_GLIB +#cmakedefine LWS_WITH_GTK #cmakedefine LWS_WITH_HTTP2 +#cmakedefine LWS_WITH_HTTP_BASIC_AUTH #cmakedefine LWS_WITH_HTTP_BROTLI +#cmakedefine LWS_HTTP_HEADERS_ALL #cmakedefine LWS_WITH_HTTP_PROXY #cmakedefine LWS_WITH_HTTP_STREAM_COMPRESSION +#cmakedefine LWS_WITH_HTTP_UNCOMMON_HEADERS #cmakedefine LWS_WITH_IPV6 #cmakedefine LWS_WITH_JOSE #cmakedefine LWS_WITH_LEJP @@ -115,32 +151,48 @@ #cmakedefine LWS_WITH_LIBEVENT #cmakedefine LWS_WITH_LIBUV #cmakedefine LWS_WITH_LWSAC +#cmakedefine LWS_LOGS_TIMESTAMP #cmakedefine LWS_WITH_MBEDTLS #cmakedefine LWS_WITH_MINIZ #cmakedefine LWS_WITH_NETWORK #cmakedefine LWS_WITH_NO_LOGS -#cmakedefine LWS_WITHOUT_CLIENT +#cmakedefine LWS_WITH_CLIENT #cmakedefine LWS_WITHOUT_EXTENSIONS -#cmakedefine LWS_WITHOUT_SERVER +#cmakedefine LWS_WITH_SERVER +#cmakedefine LWS_WITH_SPAWN #cmakedefine LWS_WITH_PEER_LIMITS #cmakedefine LWS_WITH_PLUGINS #cmakedefine LWS_WITH_POLARSSL #cmakedefine LWS_WITH_POLL #cmakedefine LWS_WITH_RANGES +#cmakedefine LWS_WITH_SECURE_STREAMS +#cmakedefine LWS_WITH_SECURE_STREAMS_SYS_AUTH_API_AMAZON_COM +#cmakedefine LWS_WITH_SECURE_STREAMS_PROXY_API +#cmakedefine LWS_WITH_SECURE_STREAMS_STATIC_POLICY_ONLY #cmakedefine LWS_WITH_SELFTESTS #cmakedefine LWS_WITH_SEQUENCER #cmakedefine LWS_WITH_SERVER_STATUS +#cmakedefine LWS_WITH_SYS_SMD #cmakedefine LWS_WITH_SMTP #cmakedefine LWS_WITH_SOCKS5 #cmakedefine LWS_WITH_STATEFUL_URLDECODE #cmakedefine LWS_WITH_STATS #cmakedefine LWS_WITH_STRUCT_SQLITE3 +#cmakedefine LWS_WITH_STRUCT_JSON +#cmakedefine LWS_WITH_SUL_DEBUGGING #cmakedefine LWS_WITH_SQLITE3 +#cmakedefine LWS_WITH_SYS_NTPCLIENT +#cmakedefine LWS_WITH_SYS_DHCP_CLIENT +#cmakedefine LWS_WITH_SYS_STATE #cmakedefine LWS_WITH_THREADPOOL #cmakedefine LWS_WITH_TLS +#cmakedefine LWS_WITH_UDP #cmakedefine LWS_WITH_UNIX_SOCK #cmakedefine LWS_WITH_ZIP_FOPS #cmakedefine USE_OLD_CYASSL #cmakedefine USE_WOLFSSL +#cmakedefine LWS_WITH_EVENT_LIBS +#cmakedefine LWS_WITH_EVLIB_PLUGINS +#cmakedefine LWS_WITH_LIBUV_INTERNAL +#cmakedefine LWS_WITH_PLUGINS_API -${LWS_SIZEOFPTR_CODE} diff -Nru libwebsockets-3.2.1/cmake/lws_config_private.h.in libwebsockets-4.1.6/cmake/lws_config_private.h.in --- libwebsockets-3.2.1/cmake/lws_config_private.h.in 2019-12-18 14:45:31.000000000 +0000 +++ libwebsockets-4.1.6/cmake/lws_config_private.h.in 2020-12-01 17:40:26.000000000 +0000 @@ -5,21 +5,16 @@ #define _DEBUG #endif #endif +#cmakedefine LWIP_PROVIDE_ERRNO /* Define to 1 to use CyaSSL as a replacement for OpenSSL. * LWS_OPENSSL_SUPPORT needs to be set also for this to work. */ #cmakedefine USE_CYASSL -/* Define to 1 if you have the header file. */ -#cmakedefine LWS_HAVE_DLFCN_H - -/* Define to 1 if you have the header file. */ -#cmakedefine LWS_HAVE_FCNTL_H - /* Define to 1 if you have the `fork' function. */ #cmakedefine LWS_HAVE_FORK -/* Define to 1 if you have the `getenv’ function. */ +/* Define to 1 if you have the `getenv' function. */ #cmakedefine LWS_HAVE_GETENV /* Define to 1 if you have the header file. */ @@ -32,19 +27,9 @@ /* Define to 1 if you have the header file. */ #cmakedefine LWS_HAVE_MEMORY_H -/* Define to 1 if you have the `memset' function. */ -#cmakedefine LWS_HAVE_MEMSET - /* Define to 1 if you have the header file. */ #cmakedefine LWS_HAVE_NETINET_IN_H -/* Define to 1 if your system has a GNU libc compatible `realloc' function, - and to 0 otherwise. */ -#cmakedefine LWS_HAVE_REALLOC - -/* Define to 1 if you have the `socket' function. */ -#cmakedefine LWS_HAVE_SOCKET - /* Define to 1 if you have the header file. */ #cmakedefine LWS_HAVE_STDINT_H @@ -63,6 +48,9 @@ /* Define to 1 if you have the header file. */ #cmakedefine LWS_HAVE_SYS_PRCTL_H +/* Define to 1 if you have the header file. */ +#cmakedefine LWS_HAVE_SYS_RESOURCE_H + /* Define to 1 if you have the header file. */ #cmakedefine LWS_HAVE_SYS_SOCKET_H diff -Nru libwebsockets-3.2.1/CMakeLists-implied-options.txt libwebsockets-4.1.6/CMakeLists-implied-options.txt --- libwebsockets-3.2.1/CMakeLists-implied-options.txt 1970-01-01 00:00:00.000000000 +0000 +++ libwebsockets-4.1.6/CMakeLists-implied-options.txt 2020-12-01 17:40:26.000000000 +0000 @@ -0,0 +1,418 @@ +# +# libwebsockets - small server side websockets and web server implementation +# +# Copyright (C) 2010 - 2020 Andy Green +# +# Permission is hereby granted, free of charge, to any person obtaining a copy +# of this software and associated documentation files (the "Software"), to +# deal in the Software without restriction, including without limitation the +# rights to use, copy, modify, merge, publish, distribute, sublicense, and/or +# sell copies of the Software, and to permit persons to whom the Software is +# furnished to do so, subject to the following conditions: +# +# The above copyright notice and this permission notice shall be included in +# all copies or substantial portions of the Software. +# +# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING +# FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS +# IN THE SOFTWARE. +# +# This part of the CMakeLists.txt defines internal logic between options + +if(IOS) + set(LWS_DETECTED_PLAT_IOS 1) +endif() + +# Workaround for ESP-IDF +# Detect ESP_PLATFORM environment flag, if exist, set LWS_WITH_ESP32. +# Otherwise the user may not be able to run configuration ESP-IDF in the first time. +if (ESP_PLATFORM) + message(STATUS "ESP-IDF enabled") + set(LWS_WITH_ESP32 ON) + set(LWS_WITH_ZLIB OFF) + set(LWS_HAVE_mbedtls_ssl_get_alpn_protocol 1) +else() + set(LWS_WITH_ESP32_HELPER OFF) +endif() + +if (LWS_WITH_ESP32) + set(LWS_PLAT_FREERTOS 1) +endif() + +if (LWS_PLAT_OPTEE) + set(LWS_WITH_UDP 0) +endif() + +if (LWS_PLAT_FREERTOS) + message(STATUS "No LWS_WITH_DIR or LWS_WITH_LEJP_CONF") + set(LWS_WITH_DIR OFF) + set(LWS_WITH_LEJP_CONF OFF) + message("LWS_WITH_DIR ${LWS_WITH_DIR}") +else() + message(STATUS "Compiled with LWS_WITH_DIR and LWS_WITH_LEJP_CONF") + set(LWS_WITH_DIR ON) + set(LWS_WITH_LEJP_CONF ON) +endif() + +if (LWS_FOR_GITOHASHI) + set(LWS_WITH_THREADPOOL 1) + set(LWS_WITH_HTTP2 1) + set(LWS_UNIX_SOCK 1) + set(LWS_WITH_HTTP_PROXY 1) + set(LWS_WITH_FTS 1) + set(LWS_WITH_DISKCACHE 1) + set(LWS_WITH_LWSAC 1) + set(LWS_WITH_LEJP_CONF 1) + set(LWS_WITH_SPAWN 1) + set(LWS_WITH_FSMOUNT 1) + set(LWS_WITH_STRUCT_JSON 1) + set(LWS_WITH_STRUCT_SQLITE3 1) +endif() + +if(LWS_WITH_DISTRO_RECOMMENDED) + set(LWS_WITH_HTTP2 1) # selfcontained + set(LWS_WITH_LWSWS 1) # libuv + set(LWS_WITH_CGI 1) # selfcontained + set(LWS_IPV6 1) # selfcontained + set(LWS_WITH_ZIP_FOPS 1) # libz + set(LWS_WITH_SOCKS5 1) # selfcontained + set(LWS_WITH_RANGES 1) # selfcontained + set(LWS_WITH_ACME 1) # selfcontained / tls + set(LWS_WITH_SERVER_STATUS 1) # selfcontained + set(LWS_WITH_GLIB 1) # glib + set(LWS_WITH_LIBUV 1) # libuv + set(LWS_WITH_LIBEV 1) # libev + set(LWS_WITH_LIBEVENT 1) # libevent + set(LWS_WITH_EVLIB_PLUGINS 1) # event libraries created as plugins / individual packages + set(LWS_WITHOUT_EXTENSIONS 0) # libz + set(LWS_ROLE_DBUS 1) # dbus-related libs + set(LWS_WITH_FTS 1) # selfcontained + set(LWS_WITH_THREADPOOL 1) # pthreads + set(LWS_UNIX_SOCK 1) # selfcontained + set(LWS_WITH_HTTP_PROXY 1) # selfcontained + set(LWS_WITH_DISKCACHE 1) # selfcontained + set(LWS_WITH_LWSAC 1) # selfcontained + set(LWS_WITH_LEJP_CONF 1) # selfcontained + set(LWS_WITH_PLUGINS 1) # libdl + set(LWS_ROLE_RAW_PROXY 1) # selfcontained + set(LWS_WITH_GENCRYPTO 1) # selfcontained / tls + set(LWS_WITH_JOSE 1) # selfcontained + set(LWS_WITH_STRUCT_JSON 1) # selfcontained + set(LWS_WITH_STRUCT_SQLITE3 1) # sqlite3 + set(LWS_WITH_SPAWN 1) # selfcontained +# libmount is problematic on Centos 8 / RHEL 8 +# set(LWS_WITH_FSMOUNT 1) + set(LWS_ROLE_MQTT 1) # selfcontained + set(LWS_WITH_SECURE_STREAMS 1) # selfcontained + set(LWS_WITH_SECURE_STREAMS_PROXY_API 1) # selfcontained + set(LWS_WITH_DIR 1) # selfcontained +endif() + +# LWS_WITH_EVENT_LIBS is set if any event lib selected + +if (LWS_WITH_LIBEV OR + LWS_WITH_LIBUV OR + LWS_WITH_LIBEVENT OR + LWS_WITH_GLIB) + set(LWS_WITH_EVENT_LIBS 1) +else() + unset(LWS_WITH_EVENT_LIBS) +endif() + +if (LWS_WITH_SECURE_STREAMS_PROXY_API) + set(LWS_WITH_LWS_DSH 1) + set(LWS_WITH_UNIX_SOCK 1) +endif() + +if (NOT LWS_WITH_NETWORK) + set(LWS_ROLE_MQTT 0) + set(LWS_ROLE_H1 0) + set(LWS_ROLE_WS 0) + set(LWS_ROLE_RAW 0) + set(LWS_WITHOUT_EXTENSIONS 1) + set(LWS_WITHOUT_SERVER 1) + set(LWS_WITHOUT_CLIENT 1) + set(LWS_WITH_HTTP2 0) + set(LWS_WITH_SOCKS5 0) + set(LWS_UNIX_SOCK 0) + set(LWS_WITH_HTTP_PROXY 0) + set(LWS_WITH_PLUGINS 0) + set(LWS_WITH_LWSWS 0) + set(LWS_WITH_CGI 0) + set(LWS_ROLE_RAW_PROXY 0) + set(LWS_WITH_PEER_LIMITS 0) + set(LWS_WITH_HTTP_STREAM_COMPRESSION 0) + set(LWS_WITH_HTTP_BROTLI 0) + set(LWS_WITH_POLL 0) + set(LWS_WITH_SEQUENCER 0) + set(LWS_ROLE_DBUS 0) + set(LWS_WITH_LWS_DSH 0) + set(LWS_WITH_THREADPOOL 0) + set(LWS_WITH_SYS_SMD 0) +endif() + +if (LWS_WITH_CGI) + set(LWS_WITH_SPAWN 1) +endif() + +if (LWS_WITH_STRUCT_SQLITE3) + set(LWS_WITH_SQLITE3 1) +endif() + +if (LWS_WITH_HTTP_BASIC_AUTH) + # WWW_AUTHENTICATE used by basic auth is an "uncommon header" + set(LWS_WITH_HTTP_UNCOMMON_HEADERS 1) +endif() + +if (APPLE) + set(LWS_ROLE_DBUS 0) +endif() + +if(NOT DEFINED CMAKE_BUILD_TYPE) + set(CMAKE_BUILD_TYPE Release CACHE STRING "Build type") +endif() + +if (LWS_PLAT_FREERTOS) + set(LWS_UNIX_SOCK 0) +endif() + +if (LWS_PLAT_FREERTOS) + set(LWS_WITH_FTS 0) +endif() + +if (LWS_WITH_HTTP2) + set(LWS_ROLE_H2 1) +endif() +if (LWS_WITH_CGI) + set(LWS_ROLE_CGI 1) +endif() + +if (NOT LWS_ROLE_WS) + set(LWS_WITHOUT_EXTENSIONS 1) +endif() + +unset(LWS_WITH_LIBUV_INTERNAL) + +if (LWS_WITH_LWSWS) + message(STATUS "LWS_WITH_LWSWS --> Enabling LWS_WITH_PLUGINS and LWS_WITH_LIBUV") + set(LWS_WITH_PLUGINS 1) + set(LWS_WITH_LIBUV 1) + set(LWS_WITH_LIBUV_INTERNAL 1) + set(LWS_WITH_EVENT_LIBS 1) # implied by LIBUV_INTERNAL + set(LWS_WITH_ACCESS_LOG 1) + set(LWS_WITH_SERVER_STATUS 1) + set(LWS_WITH_LEJP 1) + set(LWS_WITH_LEJP_CONF 1) + set(LWS_WITH_PEER_LIMITS 1) + set(LWS_ROLE_RAW_PROXY 1) +endif() + +# sshd plugin +if (LWS_WITH_PLUGINS) + set(LWS_WITH_GENCRYPTO 1) +endif() + +if (LWS_ROLE_RAW_PROXY) + set (LWS_WITH_CLIENT 1) + set (LWS_WITH_SERVER 1) +endif() + +if (LWS_WITH_ACME) + set (LWS_WITH_CLIENT 1) + set (LWS_WITH_SERVER 1) + set (LWS_WITH_JOSE 1) +endif() + +if (LWS_WITH_JOSE) + set(LWS_WITH_LEJP 1) + set(LWS_WITH_GENCRYPTO 1) +endif() + +if (LWS_WITH_PLUGINS AND NOT LWS_WITH_LIBUV) +message(STATUS "LWS_WITH_PLUGINS --> Enabling LWS_WITH_LIBUV") + set(LWS_WITH_LIBUV 1) + set(LWS_WITH_EVENT_LIBS 1) +endif() + +if (LWS_WITH_PLUGINS OR LWS_WITH_CGI) + # sshd plugin + set(LWS_WITH_GENCRYPTO 1) +endif() + +if (LWS_PLAT_FREERTOS) + set(LWS_WITH_SHARED OFF) + if (LWS_WITH_SSL) + set(LWS_WITH_MBEDTLS ON) + endif() + # set(LWS_WITHOUT_CLIENT ON) + set(LWS_WITHOUT_TESTAPPS ON) + set(LWS_WITHOUT_EXTENSIONS ON) + set(LWS_WITH_PLUGINS OFF) + set(LWS_WITH_RANGES ON) + # this implies no pthreads in the lib + set(LWS_MAX_SMP 1) + set(LWS_HAVE_MALLOC 1) + set(LWS_HAVE_REALLOC 1) + set(LWS_HAVE_GETIFADDRS 1) + set(LWS_WITH_CUSTOM_HEADERS 0) +endif() + +#if (LWS_WITH_ESP32) +# set(LWS_WITH_ZIP_FOPS 1) +#endif() + +if (WIN32) +set(LWS_MAX_SMP 1) +if (LWS_WITH_PLUGINS) +set(LWS_WITH_LIBUV_INTERNAL 1) +endif() +endif() + +if (LWS_WITHOUT_SERVER) +set(LWS_WITH_LWSWS OFF) +endif() + +if (LWS_WITH_LEJP_CONF) + set(LWS_WITH_DIR 1) +endif() + +# confirm H1 relationships + +if (NOT LWS_ROLE_H1 AND LWS_ROLE_H2) + message(FATAL_ERROR "H2 requires LWS_ROLE_H1") +endif() + +if (NOT LWS_ROLE_H1 AND LWS_ROLE_WS) + message(FATAL_ERROR "WS requires LWS_ROLE_H1") +endif() + +if (NOT LWS_ROLE_H1 AND LWS_ROLE_CGI) + message(FATAL_ERROR "CGI requires LWS_ROLE_H1") +endif() + +# confirm HTTP relationships + +if (NOT LWS_ROLE_H1 AND NOT LWS_ROLE_H2 AND LWS_WITH_HTTP_PROXY) + message(FATAL_ERROR "LWS_WITH_LWSWS requires LWS_ROLE_H1") +endif() + +if (NOT LWS_ROLE_H1 AND NOT LWS_ROLE_H2 AND LWS_WITH_HTTP_PROXY) + message(FATAL_ERROR "LWS_WITH_HTTP_PROXY requires LWS_ROLE_H1") +endif() + +if (NOT LWS_ROLE_H1 AND NOT LWS_ROLE_H2 AND LWS_WITH_RANGES) + message(FATAL_ERROR "LWS_WITH_RANGES requires LWS_ROLE_H1") +endif() + +if (NOT LWS_ROLE_H1 AND NOT LWS_ROLE_H2 AND LWS_WITH_ACCESS_LOG) + message(FATAL_ERROR "LWS_WITH_ACCESS_LOG requires LWS_ROLE_H1") +endif() + +if (LWS_WITH_HTTP_PROXY AND (LWS_WITHOUT_CLIENT OR LWS_WITHOUT_SERVER)) + message("You have to enable both client and server for http proxy") + set(LWS_WITH_HTTP_PROXY 0) +endif() + +if (NOT LWS_WITHOUT_EXTENSIONS OR LWS_WITH_ZIP_FOPS) + set(LWS_WITH_ZLIB 1) +endif() + +if (LWS_WITH_SECURE_STREAMS) + set(LWS_WITH_SECURE_STREAMS_SYS_AUTH_API_AMAZON_COM 1) +endif() + +if (NOT (LWS_WITH_STATIC OR LWS_WITH_SHARED)) + message(FATAL_ERROR "Makes no sense to compile with neither static nor shared libraries.") +endif() + +if (LWS_WITHOUT_DAEMONIZE OR WIN32) + set(LWS_NO_DAEMONIZE 1) +endif() + +if (LWS_WITH_LIBEV) + set(LWS_WITH_LIBEV 1) +endif() + +if (LWS_WITH_LIBUV) + set(LWS_WITH_LIBUV 1) +endif() + +if (LWS_WITH_LIBEVENT) + set(LWS_WITH_LIBEVENT 1) +endif() + +if (LWS_IPV6) + set(LWS_WITH_IPV6 1) +endif() + +if (LWS_UNIX_SOCK) + set(LWS_WITH_UNIX_SOCK 1) +endif() + +if (NOT LWS_MAX_SMP) + set(LWS_MAX_SMP 1) +endif() +if ("${LWS_MAX_SMP}" STREQUAL "") + set(LWS_MAX_SMP 1) +endif() + +set(LWS_WITH_CLIENT 1) +if (LWS_WITHOUT_CLIENT) + set(LWS_WITH_CLIENT) + set(LWS_WITH_SECURE_STREAMS 0) +endif() +set(LWS_WITH_SERVER 1) +if (LWS_WITHOUT_SERVER) + set(LWS_WITH_SERVER) +endif() + +# using any abstract protocol enables LWS_WITH_ABSTRACT + +#if (LWS_WITH_SMTP) +# set(LWS_WITH_ABSTRACT 1) +#endif() + +if (NOT LWS_WITH_EVLIB_PLUGINS AND (LWS_WITH_LIBEV AND LWS_WITH_LIBEVENT)) + message(FATAL_ERROR "Sorry libev and libevent conflict with each others' namespace, you can only have one or the other") +endif() + +if (LWS_SSL_SERVER_WITH_ECDH_CERT) + set(LWS_SSL_SERVER_WITH_ECDH_CERT 1) +endif() + +# LWS_OPENSSL_SUPPORT deprecated... use LWS_WITH_TLS +if (LWS_WITH_SSL OR LWS_WITH_MBEDTLS) + set(LWS_OPENSSL_SUPPORT 1) + set(LWS_WITH_TLS 1) +endif() + +if (NOT LWS_WITH_SSL) + set(LWS_WITHOUT_BUILTIN_SHA1 OFF) +endif() +# protocol plugins dont make any sense either +if (LWS_WITH_PLUGINS AND NOT LWS_WITH_SHARED) + message("Deselecting PLUGINS since building static") + set(LWS_WITH_PLUGINS 0) +endif() + + +# if we're only building static, we don't want event lib plugins +# +if (LWS_WITH_EVLIB_PLUGINS AND NOT LWS_WITH_SHARED) + message("Deselecting EVLIB_PLUGINS since building static") + set(LWS_WITH_EVLIB_PLUGINS 0) +endif() + +if (LWS_WITH_PLUGINS OR (LWS_WITH_EVLIB_PLUGINS AND LWS_WITH_EVENT_LIBS)) + set(LWS_WITH_PLUGINS_API 1) +endif() + +if (WIN32 AND NOT LWS_EXT_PTHREAD_LIBRARIES) + message("SMD requires pthreads") + set(LWS_WITH_SYS_SMD 0) +endif() + diff -Nru libwebsockets-3.2.1/CMakeLists.txt libwebsockets-4.1.6/CMakeLists.txt --- libwebsockets-3.2.1/CMakeLists.txt 2019-12-18 14:45:31.000000000 +0000 +++ libwebsockets-4.1.6/CMakeLists.txt 2020-12-01 17:40:26.000000000 +0000 @@ -1,4 +1,47 @@ -cmake_minimum_required(VERSION 2.8.9) +# +# libwebsockets - small server side websockets and web server implementation +# +# Copyright (C) 2010 - 2020 Andy Green +# +# Permission is hereby granted, free of charge, to any person obtaining a copy +# of this software and associated documentation files (the "Software"), to +# deal in the Software without restriction, including without limitation the +# rights to use, copy, modify, merge, publish, distribute, sublicense, and/or +# sell copies of the Software, and to permit persons to whom the Software is +# furnished to do so, subject to the following conditions: +# +# The above copyright notice and this permission notice shall be included in +# all copies or substantial portions of the Software. +# +# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING +# FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS +# IN THE SOFTWARE. +# + +cmake_minimum_required(VERSION 2.8.12) +include(CheckFunctionExists) +include(CheckSymbolExists) +include(CheckIncludeFile) +include(CheckIncludeFiles) +include(CheckLibraryExists) +include(CheckTypeSize) +include(CheckCSourceCompiles) + +if (POLICY CMP0048) + cmake_policy(SET CMP0048 NEW) +endif() + +#if (POLICY CMP0024) +# cmake_policy(SET CMP0024 NEW) +#endif() + +if (POLICY CMP0075) + cmake_policy(SET CMP0075 NEW) +endif() # General Advice # @@ -13,6 +56,16 @@ set(LWS_ROLE_RAW 1) set(LWS_WITH_POLL 1) +if (ESP_PLATFORM) + set(LWS_ESP_PLATFORM 1) + set(CMAKE_TOOLCHAIN_FILE contrib/cross-esp32.cmake) + set(LWIP_PROVIDE_ERRNO 1) +endif() + +# it's at this point any toolchain file is brought in +project(libwebsockets C) +include(CTest) + # # Select features recommended for PC distro packaging # @@ -20,23 +73,29 @@ option(LWS_FOR_GITOHASHI "Enable features recommended for use with gitohashi" OFF) # +# Compiler features +# +option(DISABLE_WERROR "Avoid treating compiler warnings as fatal errors" OFF) + +# # Major individual features # option(LWS_WITH_NETWORK "Compile with network-related code" ON) option(LWS_ROLE_H1 "Compile with support for http/1 (needed for ws)" ON) option(LWS_ROLE_WS "Compile with support for websockets" ON) +option(LWS_ROLE_MQTT "Build with support for MQTT client" OFF) option(LWS_ROLE_DBUS "Compile with support for DBUS" OFF) option(LWS_ROLE_RAW_PROXY "Raw packet proxy" OFF) +option(LWS_ROLE_RAW_FILE "Compile with support for raw files" ON) option(LWS_WITH_HTTP2 "Compile with server support for HTTP/2" ON) option(LWS_WITH_LWSWS "Libwebsockets Webserver" OFF) option(LWS_WITH_CGI "Include CGI (spawn process with network-connected stdin/out/err) APIs" OFF) option(LWS_IPV6 "Compile with support for ipv6" OFF) -option(LWS_UNIX_SOCK "Compile with support for UNIX domain socket" OFF) -option(LWS_WITH_PLUGINS "Support plugins for protocols and extensions" OFF) -option(LWS_WITH_HTTP_PROXY "Support for HTTP proxying" OFF) +option(LWS_UNIX_SOCK "Compile with support for UNIX domain socket if OS supports it" ON) +option(LWS_WITH_PLUGINS "Support plugins for protocols and extensions (implies LWS_WITH_PLUGINS_API)" OFF) +option(LWS_WITH_HTTP_PROXY "Support for active HTTP proxying" OFF) option(LWS_WITH_ZIP_FOPS "Support serving pre-zipped files" OFF) option(LWS_WITH_SOCKS5 "Allow use of SOCKS5 proxy on client connections" OFF) -option(LWS_WITH_GENERIC_SESSIONS "With the Generic Sessions plugin" OFF) option(LWS_WITH_PEER_LIMITS "Track peers and restrict resources a single peer can allocate" OFF) option(LWS_WITH_ACCESS_LOG "Support generating Apache-compatible access logs" OFF) option(LWS_WITH_RANGES "Support http ranges (RFC7233)" OFF) @@ -46,7 +105,37 @@ option(LWS_WITH_HTTP_BROTLI "Also offer brotli http stream compression (requires LWS_WITH_HTTP_STREAM_COMPRESSION)" OFF) option(LWS_WITH_ACME "Enable support for ACME automatic cert acquisition + maintenance (letsencrypt etc)" OFF) option(LWS_WITH_HUBBUB "Enable libhubbub rewriting support" OFF) +option(LWS_WITH_ALSA "Enable alsa audio example" OFF) +option(LWS_WITH_GTK "Enable gtk example" OFF) option(LWS_WITH_FTS "Full Text Search support" OFF) +option(LWS_WITH_SYS_ASYNC_DNS "Nonblocking internal IPv4 + IPv6 DNS resolver" OFF) +option(LWS_WITH_SYS_NTPCLIENT "Build in tiny ntpclient good for tls date validation and run via lws_system" OFF) +option(LWS_WITH_SYS_DHCP_CLIENT "Build in tiny DHCP client" OFF) +option(LWS_WITH_HTTP_BASIC_AUTH "Support Basic Auth" ON) +option(LWS_WITH_HTTP_UNCOMMON_HEADERS "Include less common http header support" ON) +option(LWS_WITH_SYS_STATE "lws_system state support" ON) +option(LWS_WITH_SYS_SMD "Lws System Message Distribution" ON) + +# +# Secure Streams +# +option(LWS_WITH_SECURE_STREAMS "Secure Streams protocol-agnostic API" OFF) +option(LWS_WITH_SECURE_STREAMS_PROXY_API "Secure Streams support to work across processes" OFF) +option(LWS_WITH_SECURE_STREAMS_SYS_AUTH_API_AMAZON_COM "Auth support for api.amazon.com" OFF) +option(LWS_WITH_SECURE_STREAMS_STATIC_POLICY_ONLY "Secure Streams Policy is hardcoded only" OFF) + +# +# CTest options +# +# +# If you build with LWS_WITH_MINIMAL_EXAMPLES, you can use CTest / make test to run +# examples that can give a pass/fail response. By default it runs tests both against +# a local server peer and warmcat.com, if your CI wants to do the tests but does not +# have internet routing, then you can still run a subset of tests with CTest / make +# test that only does local tests by disabling this option. +# +option(LWS_CTEST_INTERNET_AVAILABLE "CTest will performs tests that need the Internet" ON) + # # TLS library options... all except mbedTLS are basically OpenSSL variants. # @@ -62,6 +151,21 @@ option(LWS_WITH_LIBEV "Compile with support for libev" OFF) option(LWS_WITH_LIBUV "Compile with support for libuv" OFF) option(LWS_WITH_LIBEVENT "Compile with support for libevent" OFF) +option(LWS_WITH_GLIB "Compile with support for glib event loop" OFF) + +if (UNIX) +# since v4.1, on unix platforms default is build any event libs as runtime plugins +option(LWS_WITH_EVLIB_PLUGINS "Compile event lib support into runtime-selected plugins" ON) +else() +# otherwise default to linking the event lib(s) to libwebsockets.so +option(LWS_WITH_EVLIB_PLUGINS "Compile event lib support into runtime-selected plugins" OFF) +endif() +# +# LWS Drivers +# + +option(LWS_WITH_DRIVERS "With generic drivers for gpio, i2c, display etc" OFF) + # # Static / Dynamic build options # @@ -73,8 +177,10 @@ # Specific platforms # option(LWS_WITH_ESP32 "Build for ESP32" OFF) -option(LWS_WITH_ESP32_HELPER "Build ESP32 helper" OFF) option(LWS_PLAT_OPTEE "Build for OPTEE" OFF) +option(LWS_PLAT_FREERTOS "Build for FreeRTOS" OFF) +option(LWS_PLAT_ANDROID "Android flavour of unix platform" OFF) + # # Client / Server / Test Apps build control # @@ -95,22 +201,25 @@ option(LWS_WITHOUT_BUILTIN_GETIFADDRS "Don't use the BSD getifaddrs implementation from libwebsockets if it is missing (this will result in a compilation error) ... The default is to assume that your libc provides it. On some systems such as uclibc it doesn't exist." OFF) option(LWS_FALLBACK_GETHOSTBYNAME "Also try to do dns resolution using gethostbyname if getaddrinfo fails" OFF) option(LWS_WITHOUT_BUILTIN_SHA1 "Don't build the lws sha-1 (eg, because openssl will provide it" OFF) -option(LWS_WITH_LATENCY "Build latency measuring code into the library" OFF) option(LWS_WITHOUT_DAEMONIZE "Don't build the daemonization api" ON) option(LWS_SSL_SERVER_WITH_ECDH_CERT "Include SSL server use ECDH certificate" OFF) option(LWS_WITH_LEJP "With the Lightweight JSON Parser" ON) option(LWS_WITH_SQLITE3 "Require SQLITE3 support" OFF) -option(LWS_WITH_STRUCT_JSON "Generic struct serialization to and from JSON" ON) +option(LWS_WITH_STRUCT_JSON "Generic struct serialization to and from JSON" OFF) option(LWS_WITH_STRUCT_SQLITE3 "Generic struct serialization to and from SQLITE3" OFF) -option(LWS_WITH_SMTP "Provide SMTP support" OFF) -if (WIN32 OR LWS_WITH_ESP32) +# broken atm +#option(LWS_WITH_SMTP "Provide SMTP support" OFF) +if (LWS_WITH_ESP32) option(LWS_WITH_DIR "Directory scanning api support" OFF) option(LWS_WITH_LEJP_CONF "With LEJP configuration parser as used by lwsws" OFF) else() option(LWS_WITH_DIR "Directory scanning api support" ON) option(LWS_WITH_LEJP_CONF "With LEJP configuration parser as used by lwsws" ON) endif() -option(LWS_WITH_NO_LOGS "Disable all logging from being compiled in" OFF) +option(LWS_WITH_NO_LOGS "Disable all logging other than _err and _user from being compiled in" OFF) +set(LWS_LOGGING_BITFIELD_SET 0 CACHE STRING "Bitfield describing which log levels to force included into the build") +set(LWS_LOGGING_BITFIELD_CLEAR 0 CACHE STRING "Bitfield describing which log levels to force removed from the build") +option(LWS_LOGS_TIMESTAMP "Timestamp at start of logs" ON) option(LWS_AVOID_SIGPIPE_IGN "Android 7+ reportedly needs this" OFF) option(LWS_WITH_STATS "Keep statistics of lws internal operations" OFF) option(LWS_WITH_JOSE "JSON Web Signature / Encryption / Keys (RFC7515/6/) API" OFF) @@ -124,185 +233,87 @@ option(LWS_WITH_CUSTOM_HEADERS "Store and allow querying custom HTTP headers (H1 only)" ON) option(LWS_WITH_DISKCACHE "Hashed cache directory with lazy LRU deletion to size limit" OFF) option(LWS_WITH_ASAN "Build with gcc runtime sanitizer options enabled (needs libasan)" OFF) -option(LWS_WITH_DIR "Directory scanning api support" OFF) option(LWS_WITH_LEJP_CONF "With LEJP configuration parser as used by lwsws" OFF) option(LWS_WITH_ZLIB "Include zlib support (required for extensions)" OFF) option(LWS_WITH_BUNDLED_ZLIB "Use bundled zlib version (Windows only)" ${LWS_WITH_BUNDLED_ZLIB_DEFAULT}) option(LWS_WITH_MINIZ "Use miniz instead of zlib" OFF) -option(LWS_WITH_DEPRECATED_LWS_DLL "Migrate to lws_dll2 instead ASAP" OFF) -option(LWS_WITH_SEQUENCER "lws_seq_t support" ON) +option(LWS_WITH_DEPRECATED_THINGS "Temporary workaround for deprecated apis" OFF) +option(LWS_WITH_SEQUENCER "lws_seq_t support" OFF) option(LWS_WITH_EXTERNAL_POLL "Support external POLL integration using callback messages (not recommended)" OFF) option(LWS_WITH_LWS_DSH "Support lws_dsh_t Disordered Shared Heap" OFF) +option(LWS_CLIENT_HTTP_PROXYING "Support external http proxies for client connections" ON) +option(LWS_WITH_FILE_OPS "Support file operations vfs" ON) +option(LWS_WITH_DETAILED_LATENCY "Record detailed latency stats for each read and write" OFF) +option(LWS_WITH_UDP "Platform supports UDP" ON) +option(LWS_WITH_SPAWN "Spawn subprocesses with piped stdin/out/stderr" OFF) +option(LWS_WITH_FSMOUNT "Overlayfs and fallback mounting apis" OFF) +option(LWS_WITH_FANALYZER "Enable gcc -fanalyzer if compiler supports" OFF) +option(LWS_HTTP_HEADERS_ALL "Override header reduction optimization and include all like older lws versions" OFF) +option(LWS_WITH_SUL_DEBUGGING "Enable zombie lws_sul checking on object deletion" OFF) +option(LWS_WITH_PLUGINS_API "Build generic lws_plugins apis (see LWS_WITH_PLUGINS to also build protocol plugins)" OFF) + # # to use miniz, enable both LWS_WITH_ZLIB and LWS_WITH_MINIZ # # End of user settings # -# Workaround for ESP-IDF -# Detect ESP_PLATFORM environment flag, if exist, set LWS_WITH_ESP32. -# Otherwise the user may not be able to run configuration ESP-IDF in the first time. -if(ESP_PLATFORM) - message(STATUS "ESP-IDF enabled") - set(LWS_WITH_ESP32 ON) -else() - set(LWS_WITH_ESP32_HELPER OFF) -endif() - -if (WIN32 OR LWS_WITH_ESP32) - message(STATUS "No LWS_WITH_DIR and LWS_WITH_DIR") - set(LWS_WITH_DIR OFF) - set(LWS_WITH_LEJP_CONF OFF) - message("LWS_WITH_DIR ${LWS_WITH_DIR}") -else() - message(STATUS "Compiled with LWS_WITH_DIR and LWS_WITH_DIR") - set(LWS_WITH_DIR ON) - set(LWS_WITH_LEJP_CONF ON) -endif() - -if (LWS_FOR_GITOHASHI) - set(LWS_WITH_THREADPOOL 1) - set(LWS_WITH_HTTP2 1) - set(LWS_UNIX_SOCK 1) - set(LWS_WITH_HTTP_PROXY 1) - set(LWS_WITH_FTS 1) - set(LWS_WITH_DISKCACHE 1) - set(LWS_WITH_LWSAC 1) - set(LWS_WITH_LEJP_CONF 1) -endif() - -if(LWS_WITH_DISTRO_RECOMMENDED) - set(LWS_WITH_HTTP2 1) - set(LWS_WITH_LWSWS 1) - set(LWS_WITH_CGI 1) - set(LWS_IPV6 1) - set(LWS_WITH_ZIP_FOPS 1) - set(LWS_WITH_SOCKS5 1) - set(LWS_WITH_RANGES 1) - set(LWS_WITH_ACME 1) - set(LWS_WITH_SERVER_STATUS 1) - set(LWS_WITH_LIBUV 1) - set(LWS_WITH_LIBEV 1) - # libev + libevent cannot coexist at build-time - set(LWS_WITH_LIBEVENT 0) - set(LWS_WITHOUT_EXTENSIONS 0) - set(LWS_ROLE_DBUS 1) - set(LWS_WITH_FTS 1) - set(LWS_WITH_THREADPOOL 1) - set(LWS_UNIX_SOCK 1) - set(LWS_WITH_HTTP_PROXY 1) - set(LWS_WITH_DISKCACHE 1) - set(LWS_WITH_LWSAC 1) - set(LWS_WITH_LEJP_CONF 1) - set(LWS_WITH_PLUGINS 1) - set(LWS_ROLE_RAW_PROXY 1) - set(LWS_WITH_GENCRYPTO 1) - set(LWS_WITH_JOSE 1) -endif() - -if (NOT LWS_WITH_NETWORK) - set(LWS_ROLE_H1 0) - set(LWS_ROLE_WS 0) - set(LWS_ROLE_RAW 0) - set(LWS_WITHOUT_EXTENSIONS 1) - set(LWS_WITHOUT_SERVER 1) - set(LWS_WITHOUT_CLIENT 1) - set(LWS_WITH_HTTP2 0) - set(LWS_WITH_SOCKS5 0) - set(LWS_UNIX_SOCK 0) - set(LWS_WITH_HTTP_PROXY 0) - set(LWS_WITH_PLUGINS 0) - set(LWS_WITH_LWSWS 0) - set(LWS_WITH_CGI 0) - set(LWS_ROLE_RAW_PROXY 0) - set(LWS_WITH_PEER_LIMITS 0) - set(LWS_WITH_GENERIC_SESSIONS 0) - set(LWS_WITH_HTTP_STREAM_COMPRESSION 0) - set(LWS_WITH_HTTP_BROTLI 0) - set(LWS_WITH_POLL 0) - set(LWS_WITH_SEQUENCER 0) - set(LWS_ROLE_DBUS 0) - set(LWS_WITH_LWS_DSH 0) -endif() - -if (LWS_WITH_STRUCT_SQLITE3) - set(LWS_WITH_SQLITE3 1) -endif() - -# do you care about this? Then send me a patch where it disables it on travis -# but allows it on APPLE -if (APPLE) - set(LWS_ROLE_DBUS 0) -endif() - -if(NOT DEFINED CMAKE_BUILD_TYPE) - set(CMAKE_BUILD_TYPE Release CACHE STRING "Build type") -endif() - -# microsoft... that's why you can't have nice things - -if (WIN32 OR LWS_WITH_ESP32) - set(LWS_UNIX_SOCK 0) -endif() - -if (LWS_WITH_ESP32) - set(LWS_WITH_LWSAC 0) - set(LWS_WITH_FTS 0) -endif() - -project(libwebsockets C) - -set(PACKAGE "libwebsockets") -set(CPACK_PACKAGE_NAME "${PACKAGE}") -set(CPACK_PACKAGE_VERSION_MAJOR "3") -set(CPACK_PACKAGE_VERSION_MINOR "2") -set(CPACK_PACKAGE_VERSION_PATCH "0") -set(CPACK_PACKAGE_RELEASE 1) -set(CPACK_GENERATOR "RPM") -set(CPACK_PACKAGE_VERSION "${CPACK_PACKAGE_VERSION_MAJOR}.${CPACK_PACKAGE_VERSION_MINOR}.${CPACK_PACKAGE_VERSION_PATCH}") -set(CPACK_PACKAGE_VENDOR "andy@warmcat.com") -set(CPACK_PACKAGE_CONTACT "andy@warmcat.com") -set(CPACK_PACKAGE_DESCRIPTION_SUMMARY "${PACKAGE} ${PACKAGE_VERSION}") -set(SOVERSION "15") -if(NOT CPACK_GENERATOR) - if(UNIX) - set(CPACK_GENERATOR "TGZ") - else() - set(CPACK_GENERATOR "ZIP") - endif() -endif() -set(CPACK_SOURCE_GENERATOR "TGZ") -set(CPACK_SOURCE_PACKAGE_FILE_NAME "${CPACK_PACKAGE_NAME}-${CPACK_PACKAGE_VERSION}") -set(VERSION "${CPACK_PACKAGE_VERSION}") +# sets of sub-options implied by other options +# +set(LIB_LIST "") +set(LIB_LIST_AT_END) +set(LWS_LIBRARIES) +set(LWS_OPENSSL_SUPPORT 0) +include(CMakeLists-implied-options.txt) -set(LWS_LIBRARY_VERSION ${CPACK_PACKAGE_VERSION}) -set(LWS_LIBRARY_VERSION_MAJOR ${CPACK_PACKAGE_VERSION_MAJOR}) -set(LWS_LIBRARY_VERSION_MINOR ${CPACK_PACKAGE_VERSION_MINOR}) -set(LWS_LIBRARY_VERSION_PATCH ${CPACK_PACKAGE_VERSION_PATCH}) +# +# Structural helpers for cmake in subdirs +# -set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${PROJECT_SOURCE_DIR}/cmake/") +macro(add_subdir_include_directories arg1) + add_subdirectory(${arg1}) + include_directories(${_CMAKE_INC_LIST}) +endmacro() +macro(exports_to_parent_scope) + set(SOURCES ${SOURCES} PARENT_SCOPE) + if (LIB_LIST) + set(LIB_LIST ${LIB_LIST} PARENT_SCOPE) + endif() + get_property(_CURR DIRECTORY PROPERTY INCLUDE_DIRECTORIES) + set(_CMAKE_INC_LIST ${_CURR} PARENT_SCOPE) + if (LWS_LIB_BUILD_INC_PATHS) + set(LWS_LIB_BUILD_INC_PATHS ${LWS_LIB_BUILD_INC_PATHS} PARENT_SCOPE) + endif() +endmacro() -message(STATUS "CMAKE_TOOLCHAIN_FILE='${CMAKE_TOOLCHAIN_FILE}'") +macro(export_to_parent_intermediate) + set(SOURCES ${SOURCES} PARENT_SCOPE) + if (LIB_LIST) + set(LIB_LIST ${LIB_LIST} PARENT_SCOPE) + endif() + set(_CMAKE_INC_LIST ${_CMAKE_INC_LIST} PARENT_SCOPE) + if (LWS_LIB_BUILD_INC_PATHS) + set(LWS_LIB_BUILD_INC_PATHS ${LWS_LIB_BUILD_INC_PATHS} PARENT_SCOPE) + endif() +endmacro() -if(WIN32) - configure_file(${CMAKE_CURRENT_SOURCE_DIR}/win32port/version.rc.in ${CMAKE_CURRENT_BINARY_DIR}/win32port/version.rc @ONLY) - set(RESOURCES ${CMAKE_CURRENT_BINARY_DIR}/win32port/version.rc) -endif() +# +# Try to find the current Git hash +# -# Try to find the current Git hash. find_package(Git) if(GIT_EXECUTABLE) execute_process( WORKING_DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}" - COMMAND "${GIT_EXECUTABLE}" describe --tags + COMMAND "${GIT_EXECUTABLE}" describe --tags --always OUTPUT_VARIABLE GIT_HASH OUTPUT_STRIP_TRAILING_WHITESPACE ) set(LWS_BUILD_HASH ${GIT_HASH}) # append the build user and hostname - if(NOT LWS_REPRODUCIBLE) + if (NOT LWS_REPRODUCIBLE) execute_process( WORKING_DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}" COMMAND "whoami" @@ -322,142 +333,74 @@ message("Git commit hash: ${LWS_BUILD_HASH}") endif() -# translate old functionality enables to set up ROLE enables so nothing changes -if (LWS_WITH_HTTP2 AND LWS_WITHOUT_SERVER) - set(LWS_WITH_HTTP2 0) - message("HTTP2 disabled due to LWS_WITHOUT_SERVER") -endif() - -if (LWS_WITH_HTTP2) - set(LWS_ROLE_H2 1) -endif() -if (LWS_WITH_CGI) - set(LWS_ROLE_CGI 1) -endif() - -if (NOT LWS_ROLE_WS) - set(LWS_WITHOUT_EXTENSIONS 1) -endif() - -include_directories(include plugins) +set(PACKAGE "libwebsockets") +set(CPACK_RPM_PACKAGE_LICENSE "MIT") +set(CPACK_PACKAGE_NAME "${PACKAGE}") +set(CPACK_PACKAGE_VERSION_MAJOR "4") +set(CPACK_PACKAGE_VERSION_MINOR "1") +set(CPACK_PACKAGE_VERSION_PATCH_NUMBER "6") -if (LWS_WITH_LWSWS) - message(STATUS "LWS_WITH_LWSWS --> Enabling LWS_WITH_PLUGINS and LWS_WITH_LIBUV") - set(LWS_WITH_PLUGINS 1) - set(LWS_WITH_LIBUV 1) - set(LWS_WITH_ACCESS_LOG 1) - set(LWS_WITH_SERVER_STATUS 1) - set(LWS_WITH_LEJP 1) - set(LWS_WITH_LEJP_CONF 1) - set(LWS_WITH_PEER_LIMITS 1) - set(LWS_ROLE_RAW_PROXY 1) -endif() +set(CPACK_PACKAGE_VERSION_PATCH "${CPACK_PACKAGE_VERSION_PATCH_NUMBER}-${LWS_BUILD_HASH}") +set(CPACK_PACKAGE_RELEASE 1) -# sshd plugin -if (LWS_WITH_PLUGINS) - set(LWS_WITH_GENCRYPTO 1) +set(CPACK_PACKAGE_VERSION "${CPACK_PACKAGE_VERSION_MAJOR}.${CPACK_PACKAGE_VERSION_MINOR}.${CPACK_PACKAGE_VERSION_PATCH}") +set(CPACK_PACKAGE_VENDOR "andy@warmcat.com") +set(CPACK_PACKAGE_CONTACT "andy@warmcat.com") +set(CPACK_PACKAGE_DESCRIPTION_SUMMARY "${PACKAGE} ${CPACK_PACKAGE_VERSION}") +set(SOVERSION "17") +if(NOT CPACK_GENERATOR) + if(UNIX) + set(CPACK_GENERATOR "TGZ") + else() + set(CPACK_GENERATOR "ZIP") + endif() endif() +set(CPACK_SOURCE_GENERATOR "TGZ") +set(CPACK_SOURCE_PACKAGE_FILE_NAME "${CPACK_PACKAGE_NAME}-${CPACK_PACKAGE_VERSION}") +set(VERSION "${CPACK_PACKAGE_VERSION}") -if (LWS_ROLE_RAW_PROXY) - set (LWS_WITHOUT_CLIENT 0) - set (LWS_WITHOUT_SERVER 0) -endif() +set(CPACK_RPM_PACKAGE_RELEASE_DIST ON) +set(CPACK_RPM_FILE_NAME "RPM-DEFAULT") +# below makes path length problems in CI +set(CPACK_RPM_DEBUGINFO_PACKAGE OFF) +# below makes some kind of chimera rpm with binaries and sources +set(CPACK_RPM_PACKAGE_SOURCES OFF) +set(CPACK_RPM_INSTALL_WITH_EXEC ON) +set(CPACK_RPM_COMPONENT_INSTALL ON) + +set(CPACK_DEBIAN_FILE_NAME "DEB-DEFAULT") +set(CPACK_DEBIAN_PACKAGE_SHLIBDEPS ON) +set(CPACK_DEBIAN_DEBUGINFO_PACKAGE ON) +set(CPACK_DEBIAN_PACKAGE_SOURCE ON) +set(CPACK_DEBIAN_COMPONENT_INSTALL ON) -if (LWS_WITH_ACME) - set (LWS_WITHOUT_CLIENT 0) - set (LWS_WITHOUT_SERVER 0) - set (LWS_WITH_JOSE 1) -endif() -if (LWS_WITH_JOSE) - set(LWS_WITH_LEJP 1) - set(LWS_WITH_GENCRYPTO 1) -endif() +set(LWS_LIBRARY_VERSION ${CPACK_PACKAGE_VERSION}) +set(LWS_LIBRARY_VERSION_MAJOR ${CPACK_PACKAGE_VERSION_MAJOR}) +set(LWS_LIBRARY_VERSION_MINOR ${CPACK_PACKAGE_VERSION_MINOR}) +set(LWS_LIBRARY_VERSION_PATCH ${CPACK_PACKAGE_VERSION_PATCH_NUMBER}) +set(LWS_LIBRARY_VERSION_PATCH_ELABORATED ${CPACK_PACKAGE_VERSION_PATCH}) -if (LWS_WITH_PLUGINS AND NOT LWS_WITH_LIBUV) -message(STATUS "LWS_WITH_PLUGINS --> Enabling LWS_WITH_LIBUV") - set(LWS_WITH_LIBUV 1) +if (NOT CMAKE_MODULE_PATH) + set(CMAKE_MODULE_PATH "") endif() +set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${PROJECT_SOURCE_DIR}/cmake/") -if (LWS_WITH_PLUGINS OR LWS_WITH_CGI) - # sshd plugin - set(LWS_WITH_GENCRYPTO 1) -endif() -if (LWS_WITH_GENERIC_SESSIONS) - set(LWS_WITH_SQLITE3 1) - set(LWS_WITH_SMTP 1) - set(LWS_WITH_STRUCT_SQLITE3 1) +if (CMAKE_TOOLCHAIN_FILE) + message(STATUS "CMAKE_TOOLCHAIN_FILE='${CMAKE_TOOLCHAIN_FILE}'") endif() -if (LWS_WITH_ESP32) - set(LWS_WITH_SHARED OFF) - set(LWS_WITH_MBEDTLS ON) - # set(LWS_WITHOUT_CLIENT ON) - set(LWS_WITHOUT_TESTAPPS ON) - set(LWS_WITHOUT_EXTENSIONS ON) - set(LWS_WITH_PLUGINS OFF) - set(LWS_WITH_RANGES ON) - # this implies no pthreads in the lib - set(LWS_MAX_SMP 1) - set(LWS_HAVE_MALLOC 1) - set(LWS_HAVE_REALLOC 1) - set(LWS_HAVE_GETIFADDRS 1) - set(LWS_WITH_ZIP_FOPS 1) - set(LWS_WITH_CUSTOM_HEADERS 0) +if (NOT LIB_SUFFIX) + set(LIB_SUFFIX "") endif() - if (WIN32) -set(LWS_MAX_SMP 1) -set(LWS_WITH_THREADPOOL 0) -endif() - -if (LWS_WITHOUT_SERVER) -set(LWS_WITH_LWSWS OFF) -endif() - -if (LWS_WITH_LEJP_CONF) - set(LWS_WITH_DIR 1) -endif() - -# confirm H1 relationships - -if (NOT LWS_ROLE_H1 AND LWS_ROLE_H2) - message(FATAL_ERROR "H2 requires LWS_ROLE_H1") -endif() - -if (NOT LWS_ROLE_H1 AND LWS_ROLE_WS) - message(FATAL_ERROR "WS requires LWS_ROLE_H1") -endif() - -if (NOT LWS_ROLE_H1 AND LWS_ROLE_CGI) - message(FATAL_ERROR "CGI requires LWS_ROLE_H1") -endif() - -# confirm HTTP relationships - -if (NOT LWS_ROLE_H1 AND NOT LWS_ROLE_H2 AND LWS_WITH_HTTP_PROXY) - message(FATAL_ERROR "LWS_WITH_LWSWS requires LWS_ROLE_H1") -endif() - -if (NOT LWS_ROLE_H1 AND NOT LWS_ROLE_H2 AND LWS_WITH_HTTP_PROXY) - message(FATAL_ERROR "LWS_WITH_HTTP_PROXY requires LWS_ROLE_H1") -endif() - -if (NOT LWS_ROLE_H1 AND NOT LWS_ROLE_H2 AND LWS_WITH_RANGES) - message(FATAL_ERROR "LWS_WITH_RANGES requires LWS_ROLE_H1") -endif() - -if (NOT LWS_ROLE_H1 AND NOT LWS_ROLE_H2 AND LWS_WITH_ACCESS_LOG) - message(FATAL_ERROR "LWS_WITH_ACCESS_LOG requires LWS_ROLE_H1") + configure_file(${CMAKE_CURRENT_SOURCE_DIR}/win32port/version.rc.in ${CMAKE_CURRENT_BINARY_DIR}/win32port/version.rc @ONLY) + set(RESOURCES ${CMAKE_CURRENT_BINARY_DIR}/win32port/version.rc) endif() - -if (LWS_WITH_HTTP_PROXY AND (LWS_WITHOUT_CLIENT OR LWS_WITHOUT_SERVER)) - message("You have to enable both client and server for http proxy") - set(LWS_WITH_HTTP_PROXY 0) -endif() +include_directories(include) # Allow the user to override installation directories. set(LWS_INSTALL_LIB_DIR lib CACHE PATH "Installation directory for libraries") @@ -465,112 +408,21 @@ set(LWS_INSTALL_INCLUDE_DIR include CACHE PATH "Installation directory for header files") set(LWS_INSTALL_EXAMPLES_DIR bin CACHE PATH "Installation directory for example files") -# Allow the user to use the old CyaSSL options/library in stead of wolfSSL -if (LWS_WITH_CYASSL AND LWS_WITH_WOLFSSL) - message(FATAL_ERROR "LWS_WITH_CYASSL and LWS_WITH_WOLFSSL are mutually exclusive!") -endif() -if (LWS_WITH_CYASSL) - # Copy CyaSSL options to the wolfSSL options - set(LWS_WITH_WOLFSSL ${LWS_WITH_CYASSL} CACHE BOOL "Use wolfSSL/CyaSSL instead of OpenSSL" FORCE) - set(LWS_WOLFSSL_LIBRARIES ${LWS_CYASSL_LIBRARIES} CACHE PATH "Path to wolfSSL/CyaSSL libraries" FORCE) - set(LWS_WOLFSSL_INCLUDE_DIRS ${LWS_CYASSL_INCLUDE_DIRS} CACHE PATH "Path to wolfSSL/CyaSSL header files" FORCE) -endif() - -if (NOT (LWS_WITH_STATIC OR LWS_WITH_SHARED)) - message(FATAL_ERROR "Makes no sense to compile with neither static nor shared libraries.") -endif() - -if (NOT LWS_WITHOUT_EXTENSIONS OR LWS_WITH_ZIP_FOPS) - set(LWS_WITH_ZLIB 1) -endif() - # if you gave LWS_WITH_MINIZ, point to MINIZ here if not found # automatically set(LWS_ZLIB_LIBRARIES CACHE PATH "Path to the zlib/miniz library") set(LWS_ZLIB_INCLUDE_DIRS CACHE PATH "Path to the zlib/miniz include directory") -set(LWS_OPENSSL_LIBRARIES CACHE PATH "Path to the OpenSSL library") -set(LWS_OPENSSL_INCLUDE_DIRS CACHE PATH "Path to the OpenSSL include directory") -set(LWS_WOLFSSL_LIBRARIES CACHE PATH "Path to the wolfSSL library") -set(LWS_WOLFSSL_INCLUDE_DIRS CACHE PATH "Path to the wolfSSL include directory") -set(LWS_LIBEV_LIBRARIES CACHE PATH "Path to the libev library") -set(LWS_LIBEV_INCLUDE_DIRS CACHE PATH "Path to the libev include directory") -set(LWS_LIBUV_LIBRARIES CACHE PATH "Path to the libuv library") -set(LWS_LIBUV_INCLUDE_DIRS CACHE PATH "Path to the libuv include directory") set(LWS_SQLITE3_LIBRARIES CACHE PATH "Path to the sqlite3 library") set(LWS_SQLITE3_INCLUDE_DIRS CACHE PATH "Path to the sqlite3 include directory") -set(LWS_LIBEVENT_INCLUDE_DIRS CACHE PATH "Path to the libevent include directory") -set(LWS_LIBEVENT_LIBRARIES CACHE PATH "Path to the libevent library") +set(LWS_LIBMOUNT_INCLUDE_DIRS CACHE PATH "Path to the libmount include directory") +set(LWS_LIBMOUNT_LIBRARIES CACHE PATH "Path to the libmount library") +# on unix, these are in the toolchain. On win32 you have to put them somewhere +# yourself and point to them here +set(LWS_EXT_PTHREAD_INCLUDE_DIR CACHE PATH "Path to an external pthreads include directory") +set(LWS_EXT_PTHREAD_LIBRARIES CACHE PATH "Path to an external pthreads library") -if (NOT LWS_WITH_SSL) - set(LWS_WITHOUT_BUILTIN_SHA1 OFF) -endif() - -if (LWS_WITH_BORINGSSL) - # boringssl deprecated EVP_PKEY - set (LWS_WITH_GENHASH OFF) -endif() - -if (LWS_WITH_SSL AND NOT LWS_WITH_WOLFSSL AND NOT LWS_WITH_MBEDTLS) - if ("${LWS_OPENSSL_LIBRARIES}" STREQUAL "" OR "${LWS_OPENSSL_INCLUDE_DIRS}" STREQUAL "") - else() - if (NOT LWS_WITH_ESP32) - set(OPENSSL_LIBRARIES ${LWS_OPENSSL_LIBRARIES}) - endif() - set(OPENSSL_INCLUDE_DIRS ${LWS_OPENSSL_INCLUDE_DIRS}) - set(OPENSSL_FOUND 1) - endif() -endif() - -if (LWS_WITH_SSL AND LWS_WITH_WOLFSSL) - if ("${LWS_WOLFSSL_LIBRARIES}" STREQUAL "" OR "${LWS_WOLFSSL_INCLUDE_DIRS}" STREQUAL "") - if (NOT WOLFSSL_FOUND) - if (LWS_WITH_CYASSL) - message(FATAL_ERROR "You must set LWS_CYASSL_LIBRARIES and LWS_CYASSL_INCLUDE_DIRS when LWS_WITH_CYASSL is turned on.") - else() - message(FATAL_ERROR "You must set LWS_WOLFSSL_LIBRARIES and LWS_WOLFSSL_INCLUDE_DIRS when LWS_WITH_WOLFSSL is turned on.") - endif() - endif() - else() - set(WOLFSSL_LIBRARIES ${LWS_WOLFSSL_LIBRARIES}) - set(WOLFSSL_INCLUDE_DIRS ${LWS_WOLFSSL_INCLUDE_DIRS}) - set(WOLFSSL_FOUND 1) - endif() - set(USE_WOLFSSL 1) - set(LWS_WITH_TLS 1) - if (LWS_WITH_CYASSL) - set(USE_OLD_CYASSL 1) - endif() -endif() - -if (LWS_WITH_SSL AND LWS_WITH_MBEDTLS) - if ("${LWS_MBEDTLS_LIBRARIES}" STREQUAL "" OR "${LWS_MBEDTLS_INCLUDE_DIRS}" STREQUAL "" AND NOT LWS_WITH_ESP32) - - find_path(LWS_MBEDTLS_INCLUDE_DIRS mbedtls/ssl.h) - - find_library(MBEDTLS_LIBRARY mbedtls) - find_library(MBEDX509_LIBRARY mbedx509) - find_library(MBEDCRYPTO_LIBRARY mbedcrypto) - - set(LWS_MBEDTLS_LIBRARIES "${MBEDTLS_LIBRARY}" "${MBEDX509_LIBRARY}" "${MBEDCRYPTO_LIBRARY}") - - include(FindPackageHandleStandardArgs) - find_package_handle_standard_args(MBEDTLS DEFAULT_MSG - LWS_MBEDTLS_INCLUDE_DIRS MBEDTLS_LIBRARY MBEDX509_LIBRARY MBEDCRYPTO_LIBRARY) - - mark_as_advanced(LWS_MBEDTLS_INCLUDE_DIRS MBEDTLS_LIBRARY MBEDX509_LIBRARY MBEDCRYPTO_LIBRARY) - - if ("${LWS_MBEDTLS_LIBRARIES}" STREQUAL "" OR "${LWS_MBEDTLS_INCLUDE_DIRS}" STREQUAL "") - message(FATAL_ERROR "You must set LWS_MBEDTLS_LIBRARIES and LWS_MBEDTLS_INCLUDE_DIRS when LWS_WITH_MBEDTLS is turned on.") - endif() - endif() - set(MBEDTLS_LIBRARIES ${LWS_MBEDTLS_LIBRARIES}) - set(MBEDTLS_INCLUDE_DIRS ${LWS_MBEDTLS_INCLUDE_DIRS}) - set(MBEDTLS_FOUND 1) - set(USE_MBEDTLS 1) -endif() - if (LWS_WITH_HTTP_STREAM_COMPRESSION) set(LWS_WITH_ZLIB 1) endif() @@ -584,32 +436,6 @@ endif() endif() -if (LWS_WITH_LIBEV) - if ("${LWS_LIBEV_LIBRARIES}" STREQUAL "" OR "${LWS_LIBEV_INCLUDE_DIRS}" STREQUAL "") - else() - set(LIBEV_LIBRARIES ${LWS_LIBEV_LIBRARIES}) - set(LIBEV_INCLUDE_DIRS ${LWS_LIBEV_INCLUDE_DIRS}) - set(LIBEV_FOUND 1) - endif() -endif() - -if (LWS_WITH_LIBUV) - if ("${LWS_LIBUV_LIBRARIES}" STREQUAL "" OR "${LWS_LIBUV_INCLUDE_DIRS}" STREQUAL "") - else() - set(LIBUV_LIBRARIES ${LWS_LIBUV_LIBRARIES}) - set(LIBUV_INCLUDE_DIRS ${LWS_LIBUV_INCLUDE_DIRS}) - set(LIBUV_FOUND 1) - endif() -endif() - -if (LWS_WITH_LIBEVENT) - if ("${LWS_LIBEVENT_LIBRARIES}" STREQUAL "" OR "${LWS_LIBEVENT_INCLUDE_DIRS}" STREQUAL "") - else() - set(LIBEVENT_LIBRARIES ${LWS_LIBEVENT_LIBRARIES}) - set(LIBEVENT_INCLUDE_DIRS ${LWS_LIBEVENT_INCLUDE_DIRS}) - set(LIBEVENT_FOUND 1) - endif() -endif() if (LWS_WITH_SQLITE3) if ("${LWS_SQLITE3_LIBRARIES}" STREQUAL "" OR "${LWS_SQLITE3_INCLUDE_DIRS}" STREQUAL "") @@ -620,100 +446,8 @@ endif() endif() - -if (LWS_WITH_LIBEV AND LWS_WITH_LIBEVENT) - message(FATAL_ERROR "Sorry libev and libevent conflict with each others' namespace, you can only have one or the other") -endif() - -# The base dir where the test-apps look for the SSL certs. -set(LWS_OPENSSL_CLIENT_CERTS ../share CACHE PATH "Server SSL certificate directory") -if (WIN32) - set(LWS_OPENSSL_CLIENT_CERTS . CACHE PATH "Client SSL certificate directory") - - if (LWS_UNIX_SOCK) - set(LWS_UNIX_SOCK OFF) - message(WARNING "Windows does not support UNIX domain sockets") - endif() -else() - set(LWS_OPENSSL_CLIENT_CERTS /etc/pki/tls/certs/ CACHE PATH "Client SSL certificate directory") -endif() - -# LWS_OPENSSL_SUPPORT deprecated... use LWS_WITH_TLS -if (LWS_WITH_SSL OR LWS_WITH_MBEDTLS) - set(LWS_OPENSSL_SUPPORT 1) - set(LWS_WITH_TLS 1) -endif() - -if (LWS_SSL_CLIENT_USE_OS_CA_CERTS) - set(LWS_SSL_CLIENT_USE_OS_CA_CERTS 1) -endif() - -if (LWS_WITH_LATENCY) - set(LWS_LATENCY 1) -endif() - -if (LWS_WITHOUT_DAEMONIZE OR WIN32) - set(LWS_NO_DAEMONIZE 1) -endif() - -if (LWS_WITHOUT_SERVER) - set(LWS_NO_SERVER 1) -endif() - -if (LWS_WITHOUT_CLIENT) - set(LWS_NO_CLIENT 1) -endif() - -if (LWS_WITH_LIBEV) - set(LWS_WITH_LIBEV 1) -endif() - -if (LWS_WITH_LIBUV) - set(LWS_WITH_LIBUV 1) -endif() - -if (LWS_WITH_LIBEVENT) - set(LWS_WITH_LIBEVENT 1) -endif() - -if (LWS_IPV6) - set(LWS_WITH_IPV6 1) -endif() - -if (LWS_UNIX_SOCK) - set(LWS_WITH_UNIX_SOCK 1) -endif() - -if (LWS_WITH_HTTP2) - set(LWS_WITH_HTTP2 1) -endif() - -if ("${LWS_MAX_SMP}" STREQUAL "") - set(LWS_MAX_SMP 1) -endif() - -# using any abstract protocol enables LWS_WITH_ABSTRACT - -if (LWS_WITH_SMTP) - set(LWS_WITH_ABSTRACT 1) -endif() - - - -if (MINGW) - set(LWS_MINGW_SUPPORT 1) - set(CMAKE_C_FLAGS "-D__USE_MINGW_ANSI_STDIO ${CMAKE_C_FLAGS}") - add_definitions(-DWINVER=0x0601 -D_WIN32_WINNT=0x0601) -endif() - -if (LWS_SSL_SERVER_WITH_ECDH_CERT) - set(LWS_SSL_SERVER_WITH_ECDH_CERT 1) -endif() - include_directories("${PROJECT_BINARY_DIR}") -include(CheckCSourceCompiles) - # Check for different inline keyword versions. foreach(KEYWORD "inline" "__inline__" "__inline") set(CMAKE_REQUIRED_DEFINITIONS "-DKEYWORD=${KEYWORD}") @@ -745,22 +479,10 @@ # architectures, notably Mac OS X, need this. SET(CMAKE_INSTALL_NAME_DIR "${CMAKE_INSTALL_PREFIX}/${LWS_INSTALL_LIB_DIR}${LIB_SUFFIX}") -include(CheckFunctionExists) -include(CheckSymbolExists) -include(CheckIncludeFile) -include(CheckIncludeFiles) -include(CheckLibraryExists) -include(CheckTypeSize) -include(CheckCSourceCompiles) - if (LWS_WITHOUT_BUILTIN_SHA1) set(LWS_SHA1_USE_OPENSSL_NAME 1) endif() -if (HAIKU) - set(CMAKE_REQUIRED_LIBRARIES network) -endif() - CHECK_C_SOURCE_COMPILES( "#include int main(int argc, char **argv) { return malloc_trim(0); } @@ -789,6 +511,7 @@ CHECK_FUNCTION_EXISTS(_stat32i64 LWS_HAVE__STAT32I64) CHECK_FUNCTION_EXISTS(clock_gettime LWS_HAVE_CLOCK_GETTIME) + if (NOT LWS_HAVE_GETIFADDRS) if (LWS_WITHOUT_BUILTIN_GETIFADDRS) message(FATAL_ERROR "No getifaddrs was found on the system. Turn off the LWS_WITHOUT_BUILTIN_GETIFADDRS compile option to use the supplied BSD version.") @@ -796,8 +519,31 @@ set(LWS_BUILTIN_GETIFADDRS 1) endif() -CHECK_INCLUDE_FILE(dlfcn.h LWS_HAVE_DLFCN_H) -CHECK_INCLUDE_FILE(fcntl.h LWS_HAVE_FCNTL_H) +if (LWS_EXT_PTHREAD_INCLUDE_DIR) + set(CMAKE_REQUIRED_INCLUDES ${CMAKE_REQUIRED_INCLUDES};${LWS_EXT_PTHREAD_INCLUDE_DIR}) + include_directories(${LWS_EXT_PTHREAD_INCLUDE_DIR}) + + list(APPEND LIB_LIST_AT_END ${LWS_EXT_PTHREAD_LIBRARIES}) + set(CMAKE_REQUIRED_FLAGS ${CMAKE_REQUIRED_FLAGS} " -DHAVE_STRUCT_TIMESPEC=1") +endif() + +# +# add libs here that need to be at the end of the link order +# + +if (LWS_EXT_PTHREAD_INCLUDE_DIR) + list(APPEND LIB_LIST_AT_END ${LWS_EXT_PTHREAD_LIBRARIES}) +endif() + +if (LWS_WITH_ZLIB AND NOT LWS_WITH_BUNDLED_ZLIB) + list(APPEND LIB_LIST_AT_END "${ZLIB_LIBRARIES}") +endif() + +if (LWS_WITH_PLUGINS_API AND UNIX AND NOT (${CMAKE_SYSTEM_NAME} MATCHES "QNX")) + list(APPEND LIB_LIST_AT_END "dl") +endif() + + CHECK_INCLUDE_FILE(in6addr.h LWS_HAVE_IN6ADDR_H) CHECK_INCLUDE_FILE(memory.h LWS_HAVE_MEMORY_H) CHECK_INCLUDE_FILE(netinet/in.h LWS_HAVE_NETINET_IN_H) @@ -816,54 +562,20 @@ CHECK_INCLUDE_FILE(malloc.h LWS_HAVE_MALLOC_H) CHECK_INCLUDE_FILE(pthread.h LWS_HAVE_PTHREAD_H) CHECK_INCLUDE_FILE(inttypes.h LWS_HAVE_INTTYPES_H) +CHECK_INCLUDE_FILE(sys/resource.h LWS_HAVE_SYS_RESOURCE_H) -CHECK_LIBRARY_EXISTS(cap cap_set_flag "" LWS_HAVE_LIBCAP) - -if (LWS_ROLE_DBUS) - - if (NOT LWS_DBUS_LIB) - set(LWS_DBUS_LIB "dbus-1") - endif() - - CHECK_LIBRARY_EXISTS(${LWS_DBUS_LIB} dbus_connection_set_watch_functions "" LWS_HAVE_LIBDBUS) - if (NOT LWS_HAVE_LIBDBUS) - message(FATAL_ERROR "Install dbus-devel, or libdbus-1-dev etc") - endif() - - if (NOT LWS_DBUS_INCLUDE1) - # look in fedora and debian / ubuntu place - if (EXISTS "/usr/include/dbus-1.0") - set(LWS_DBUS_INCLUDE1 "/usr/include/dbus-1.0") - else() - message(FATAL_ERROR "Set LWS_DBUS_INCLUDE1 to /usr/include/dbus-1.0 or wherever the main dbus includes are") - endif() - endif() - - if (NOT LWS_DBUS_INCLUDE2) - # look in fedora... debian / ubuntu has the ARCH in the path... - if (EXISTS "/usr/lib64/dbus-1.0/include") - set(LWS_DBUS_INCLUDE2 "/usr/lib64/dbus-1.0/include") - else() - message(FATAL_ERROR "Set LWS_DBUS_INCLUDE2 to /usr/lib/ARCH-linux-gnu/dbus-1.0/include or wherever dbus-arch-deps.h is on your system") - endif() +if (WIN32 OR MSVC) + CHECK_C_SOURCE_COMPILES("#include + #include + int main() { return 0; }" LWS_HAVE_WIN32_AFUNIX_H) + + if (LWS_UNIX_SOCK AND NOT LWS_HAVE_WIN32_AFUNIX_H) + message("No afunix.h found. Disabling LWS_UNIX_SOCK.") + set(LWS_WITH_UNIX_SOCK OFF) endif() - - set(CMAKE_REQUIRED_INCLUDES ${CMAKE_REQUIRED_INCLUDES};${LWS_DBUS_INCLUDE1};${LWS_DBUS_INCLUDE2}) - - CHECK_C_SOURCE_COMPILES("#include - int main(void) { - return 0; - }" LWS_DBUS_CHECK_OK) endif() -if (LWS_WITH_LIBUV) -CHECK_INCLUDE_FILE(uv-version.h LWS_HAVE_UV_VERSION_H) - # libuv changed the location in 1.21.0. Retain both - # checks temporarily to ensure a smooth transition. - if (NOT LWS_HAVE_UV_VERSION_H) - CHECK_INCLUDE_FILE(uv/version.h LWS_HAVE_NEW_UV_VERSION_H) - endif() -endif() +CHECK_LIBRARY_EXISTS(cap cap_set_flag "" LWS_HAVE_LIBCAP) if (LWS_WITH_ZLIB AND NOT LWS_WITH_BUNDLED_ZLIB) @@ -874,11 +586,17 @@ endif() endif() -# TODO: These can also be tested to see whether they actually work... -set(LWS_HAVE_WORKING_FORK LWS_HAVE_FORK) -set(LWS_HAVE_WORKING_VFORK LWS_HAVE_VFORK) +CHECK_INCLUDE_FILES("stdlib.h;stdarg.h;string.h" STDC_HEADERS) -CHECK_INCLUDE_FILES("stdlib.h;stdarg.h;string.h;float.h" STDC_HEADERS) +if (NOT CMAKE_REQUIRED_FLAGS) + set(CMAKE_REQUIRED_FLAGS "") +endif() +if (NOT CMAKE_REQUIRED_INCLUDES) + set(CMAKE_REQUIRED_INCLUDES "") +endif() +if (NOT CMAKE_REQUIRED_LIBRARIES) + set(CMAKE_REQUIRED_LIBRARIES "") +endif() CHECK_C_SOURCE_COMPILES("#include int main(void) { @@ -886,18 +604,24 @@ return 0; }" LWS_HAS_INTPTR_T) -set(CMAKE_REQUIRED_FLAGS "-pthread") -CHECK_C_SOURCE_COMPILES("#define _GNU_SOURCE - #include - int main(void) { - pthread_t th = 0; - pthread_setname_np(th, NULL); - return 0; - }" LWS_HAS_PTHREAD_SETNAME_NP) +if ((CMAKE_C_COMPILER_ID MATCHES "Clang") OR + (CMAKE_CXX_COMPILER_ID MATCHES "Clang")) + set(COMPILER_IS_CLANG ON) +endif() + +if (LWS_HAVE_PTHREAD_H AND NOT LWS_PLAT_FREERTOS) + CHECK_C_SOURCE_COMPILES("#define _GNU_SOURCE + #include + int main(void) { + pthread_t th = 0; + pthread_setname_np(th, NULL); + return 0; + }" LWS_HAS_PTHREAD_SETNAME_NP) +endif() CHECK_C_SOURCE_COMPILES("#include - #include - int main(void) { + #include + int main(void) { void *p = (void *)getopt_long; return p != NULL; }" LWS_HAS_GETOPT_LONG) @@ -919,547 +643,22 @@ set(realloc rpl_realloc) endif() -if (UNIX) - execute_process(COMMAND uname -n OUTPUT_VARIABLE NODENAME) - # Need to chomp the \n at end of output. - string(REGEX REPLACE "[\n]+" "" NODENAME "${NODENAME}") - - if( NODENAME STREQUAL "smartos" ) - add_definitions( "-D__smartos__" ) - set(SMARTOS 1) - endif() -endif() - -if (MSVC) - # Turn off stupid microsoft security warnings. - add_definitions(-D_CRT_SECURE_NO_DEPRECATE -D_CRT_NONSTDC_NO_DEPRECATE) -endif(MSVC) - -include_directories("${PROJECT_SOURCE_DIR}/lib") - -# Group headers and sources. -# Some IDEs use this for nicer file structure. -set(HDR_PRIVATE - lib/core/private.h) - -set(HDR_PUBLIC - "${PROJECT_SOURCE_DIR}/include/libwebsockets.h" - "${PROJECT_BINARY_DIR}/lws_config.h" - "${PROJECT_SOURCE_DIR}/plugins/ssh-base/include/lws-plugin-ssh.h" - ) - -set(SOURCES - lib/core/alloc.c - lib/core/buflist.c - lib/core/context.c - lib/core/lws_dll2.c - lib/core/libwebsockets.c - lib/core/logs.c - lib/misc/base64-decode.c - lib/core/vfs.c - lib/misc/lws-ring.c -) - -if (LWS_WITH_DEPRECATED_LWS_DLL) - list(APPEND SOURCES - lib/core/lws_dll.c) -endif() - -if (LWS_WITH_NETWORK) - list(APPEND SOURCES - lib/core-net/dummy-callback.c - lib/core-net/output.c - lib/core-net/close.c - lib/core-net/network.c - lib/core-net/vhost.c - lib/core-net/pollfd.c - lib/core-net/service.c - lib/core-net/sorted-usec-list.c - lib/core-net/stats.c - lib/core-net/wsi.c - lib/core-net/wsi-timeout.c - lib/core-net/adopt.c - lib/roles/pipe/ops-pipe.c - ) - - if (LWS_WITH_LWS_DSH) - list(APPEND SOURCES - lib/core-net/lws-dsh.c) - endif() - - if (LWS_WITH_SEQUENCER) - list(APPEND SOURCES - lib/core-net/sequencer.c) - endif() - - if (LWS_WITH_ABSTRACT) - list(APPEND SOURCES - lib/abstract/abstract.c - ) - if (LWS_WITH_SEQUENCER) - list(APPEND SOURCES - lib/abstract/test-sequencer.c) - endif() - endif() - - if (LWS_WITH_STATS) - list(APPEND SOURCES - lib/core-net/stats.c - ) - endif() -endif() - -if (LWS_WITH_DIR) - list(APPEND SOURCES lib/misc/dir.c) -endif() - -if (LWS_WITH_THREADPOOL AND UNIX AND LWS_HAVE_PTHREAD_H) - list(APPEND SOURCES lib/misc/threadpool/threadpool.c) -endif() - -if (LWS_ROLE_H1 OR LWS_ROLE_H2) - list(APPEND SOURCES - lib/roles/http/header.c - lib/roles/http/server/parsers.c) - if (LWS_WITH_HTTP_STREAM_COMPRESSION) - list(APPEND SOURCES - lib/roles/http/compression/stream.c - lib/roles/http/compression/deflate/deflate.c) - if (LWS_WITH_HTTP_BROTLI) - list(APPEND SOURCES - lib/roles/http/compression/brotli/brotli.c) - endif() - endif() -endif() - -if (LWS_ROLE_H1) - list(APPEND SOURCES - lib/roles/h1/ops-h1.c) -endif() - -if (LWS_ROLE_WS) - list(APPEND SOURCES - lib/roles/ws/ops-ws.c) - if (NOT LWS_WITHOUT_CLIENT) - list(APPEND SOURCES - lib/roles/ws/client-ws.c - lib/roles/ws/client-parser-ws.c) - endif() - if (NOT LWS_WITHOUT_SERVER) - list(APPEND SOURCES - lib/roles/ws/server-ws.c) - endif() -endif() - -if (LWS_ROLE_RAW) - list(APPEND SOURCES - lib/roles/raw-skt/ops-raw-skt.c - lib/roles/raw-file/ops-raw-file.c) - - if (LWS_WITH_ABSTRACT) - list(APPEND SOURCES - lib/abstract/transports/raw-skt.c) - endif() -endif() - -if (LWS_ROLE_RAW_PROXY) - list(APPEND SOURCES - lib/roles/raw-proxy/ops-raw-proxy.c) -endif() - -if (LWS_ROLE_CGI) - list(APPEND SOURCES - lib/roles/cgi/cgi-server.c - lib/roles/cgi/ops-cgi.c) -endif() - -if (LWS_ROLE_DBUS) - list(APPEND SOURCES - lib/roles/dbus/dbus.c) -endif() - -if (LWS_WITH_ACCESS_LOG) - list(APPEND SOURCES - lib/roles/http/server/access-log.c) -endif() - -if (LWS_WITH_PEER_LIMITS) - list(APPEND SOURCES - lib/misc/peer-limits.c) -endif() - -if (LWS_WITH_LWSAC) - list(APPEND SOURCES - lib/misc/lwsac/lwsac.c - lib/misc/lwsac/cached-file.c) -endif() - -if (LWS_WITH_FTS) - list(APPEND SOURCES - lib/misc/fts/trie.c - lib/misc/fts/trie-fd.c) -endif() - -if (LWS_WITH_DISKCACHE) - list(APPEND SOURCES - lib/misc/diskcache.c) -endif() - -if (LWS_WITH_STRUCT_JSON) - list(APPEND SOURCES - lib/misc/lws-struct-lejp.c) -endif() - -if (LWS_WITH_STRUCT_SQLITE3) - list(APPEND SOURCES - lib/misc/lws-struct-sqlite.c) -endif() - -if (NOT LWS_WITHOUT_CLIENT) - list(APPEND SOURCES - lib/core-net/connect.c - lib/core-net/client.c - lib/roles/http/client/client.c - lib/roles/http/client/client-handshake.c) -endif() - -if (NOT LWS_WITHOUT_SERVER) - list(APPEND SOURCES - lib/core-net/server.c - lib/roles/listen/ops-listen.c) -endif() - -if (LWS_WITH_MBEDTLS) - set(LWS_WITH_SSL ON) - - include_directories(lib/tls/mbedtls/wrapper/include) - include_directories(lib/tls/mbedtls/wrapper/include/platform) - include_directories(lib/tls/mbedtls/wrapper/include/internal) - include_directories(lib/tls/mbedtls/wrapper/include/openssl) - - if (LWS_WITH_NETWORK) - list(APPEND HDR_PRIVATE - lib/tls/mbedtls/wrapper/include/internal/ssl3.h - lib/tls/mbedtls/wrapper/include/internal/ssl_cert.h - lib/tls/mbedtls/wrapper/include/internal/ssl_code.h - lib/tls/mbedtls/wrapper/include/internal/ssl_dbg.h - lib/tls/mbedtls/wrapper/include/internal/ssl_lib.h - lib/tls/mbedtls/wrapper/include/internal/ssl_methods.h - lib/tls/mbedtls/wrapper/include/internal/ssl_pkey.h - lib/tls/mbedtls/wrapper/include/internal/ssl_stack.h - lib/tls/mbedtls/wrapper/include/internal/ssl_types.h - lib/tls/mbedtls/wrapper/include/internal/ssl_x509.h - lib/tls/mbedtls/wrapper/include/internal/tls1.h - lib/tls/mbedtls/wrapper/include/internal/x509_vfy.h) - - list(APPEND HDR_PRIVATE - lib/tls/mbedtls/wrapper/include/openssl/ssl.h) - - list(APPEND HDR_PRIVATE - lib/tls/mbedtls/wrapper/include/platform/ssl_pm.h - lib/tls/mbedtls/wrapper/include/platform/ssl_port.h) - - list(APPEND SOURCES - lib/tls/mbedtls/wrapper/library/ssl_cert.c - lib/tls/mbedtls/wrapper/library/ssl_lib.c - lib/tls/mbedtls/wrapper/library/ssl_methods.c - lib/tls/mbedtls/wrapper/library/ssl_pkey.c - lib/tls/mbedtls/wrapper/library/ssl_stack.c - lib/tls/mbedtls/wrapper/library/ssl_x509.c) - - list(APPEND SOURCES - lib/tls/mbedtls/wrapper/platform/ssl_pm.c - lib/tls/mbedtls/wrapper/platform/ssl_port.c) - endif() -endif() - -if (LWS_WITH_SSL) - list(APPEND SOURCES - lib/tls/tls.c - ) - if (LWS_WITH_NETWORK) - list(APPEND SOURCES - lib/tls/tls-network.c - ) - endif() - - if (LWS_WITH_MBEDTLS) - list(APPEND SOURCES - lib/tls/mbedtls/tls.c - lib/tls/mbedtls/x509.c - ) - if (LWS_WITH_NETWORK) - list(APPEND SOURCES - lib/tls/mbedtls/ssl.c - ) - endif() - if (LWS_WITH_GENCRYPTO) - list(APPEND SOURCES - lib/tls/mbedtls/lws-genhash.c - lib/tls/mbedtls/lws-genrsa.c - lib/tls/mbedtls/lws-genaes.c - lib/tls/lws-genec-common.c - lib/tls/mbedtls/lws-genec.c - lib/tls/mbedtls/lws-gencrypto.c - ) - endif() - else() - list(APPEND SOURCES - lib/tls/openssl/tls.c - lib/tls/openssl/x509.c - ) - if (LWS_WITH_NETWORK) - list(APPEND SOURCES - lib/tls/openssl/ssl.c - ) - endif() - if (LWS_WITH_GENCRYPTO) - list(APPEND SOURCES - lib/tls/openssl/lws-genhash.c - lib/tls/openssl/lws-genrsa.c - lib/tls/openssl/lws-genaes.c - lib/tls/lws-genec-common.c - lib/tls/openssl/lws-genec.c - lib/tls/openssl/lws-gencrypto.c - ) - endif() - endif() - - if (NOT LWS_WITHOUT_SERVER) - list(APPEND SOURCES - lib/tls/tls-server.c) - if (LWS_WITH_MBEDTLS) - list(APPEND SOURCES - lib/tls/mbedtls/mbedtls-server.c) - else() - list(APPEND SOURCES - lib/tls/openssl/openssl-server.c) - endif() - endif() - if (NOT LWS_WITHOUT_CLIENT) - list(APPEND SOURCES - lib/tls/tls-client.c) - if (LWS_WITH_MBEDTLS) - list(APPEND SOURCES - lib/tls/mbedtls/mbedtls-client.c) - else() - list(APPEND SOURCES - lib/tls/openssl/openssl-client.c) - endif() - - endif() -endif() - -if (NOT LWS_WITHOUT_BUILTIN_SHA1) - list(APPEND SOURCES - lib/misc/sha-1.c) -endif() - -if (LWS_WITH_HTTP2 AND NOT LWS_WITHOUT_SERVER) - list(APPEND SOURCES - lib/roles/h2/http2.c - lib/roles/h2/hpack.c - lib/roles/h2/ops-h2.c) -endif() -# select the active platform files - -if (WIN32) - list(APPEND SOURCES - lib/plat/windows/windows-fds.c - lib/plat/windows/windows-file.c - lib/plat/windows/windows-init.c - lib/plat/windows/windows-misc.c - lib/plat/windows/windows-pipe.c - lib/plat/windows/windows-plugins.c - lib/plat/windows/windows-service.c - lib/plat/windows/windows-sockets.c - ) -else() - - if (LWS_PLAT_OPTEE) - list(APPEND SOURCES - lib/plat/optee/lws-plat-optee.c - ) - if (LWS_WITH_NETWORK) - list(APPEND SOURCES - lib/plat/optee/network.c - ) - endif() - else() - if (LWS_WITH_ESP32) - list(APPEND SOURCES - lib/plat/esp32/esp32-fds.c - lib/plat/esp32/esp32-file.c - lib/plat/esp32/esp32-init.c - lib/plat/esp32/esp32-misc.c - lib/plat/esp32/esp32-pipe.c - lib/plat/esp32/esp32-service.c - lib/plat/esp32/esp32-sockets.c - lib/misc/romfs.c) - if(LWS_WITH_ESP32_HELPER) - list(APPEND SOURCES lib/plat/esp32/esp32-helpers.c) - endif() - else() - set(LWS_PLAT_UNIX 1) - list(APPEND SOURCES - lib/plat/unix/unix-caps.c - lib/plat/unix/unix-file.c - lib/plat/unix/unix-misc.c - lib/plat/unix/unix-init.c - ) - if (LWS_WITH_NETWORK) - list(APPEND SOURCES - lib/plat/unix/unix-pipe.c - lib/plat/unix/unix-service.c - lib/plat/unix/unix-sockets.c - lib/plat/unix/unix-fds.c - ) - endif() - - if (LWS_WITH_PLUGINS AND LWS_WITH_LIBUV) - list(APPEND SOURCES lib/plat/unix/unix-plugins.c) - endif() - endif() - endif() -endif() - -if ((LWS_ROLE_H1 OR LWS_ROLE_H2) AND NOT LWS_WITHOUT_SERVER) - list(APPEND SOURCES - lib/roles/http/server/server.c - lib/roles/http/server/lws-spa.c) -endif() - -if (LWS_ROLE_WS AND NOT LWS_WITHOUT_EXTENSIONS) - list(APPEND HDR_PRIVATE - lib/roles/ws/ext/extension-permessage-deflate.h) - list(APPEND SOURCES - lib/roles/ws/ext/extension.c - lib/roles/ws/ext/extension-permessage-deflate.c) -endif() - -if (LWS_WITH_HTTP_PROXY) - list(APPEND SOURCES - lib/roles/http/server/rewrite.c) -endif() - -if (LWS_WITH_POLL AND LWS_WITH_NETWORK) - list(APPEND SOURCES - lib/event-libs/poll/poll.c) -endif() - -if (LWS_WITH_LIBUV AND LWS_WITH_NETWORK) - list(APPEND SOURCES - lib/event-libs/libuv/libuv.c) -endif() - -if (LWS_WITH_LIBEVENT AND LWS_WITH_NETWORK) - list(APPEND SOURCES - lib/event-libs/libevent/libevent.c) -endif() - -if (LWS_WITH_LIBEV AND LWS_WITH_NETWORK) - list(APPEND SOURCES - lib/event-libs/libev/libev.c) - # libev generates a big mess of warnings with gcc, maintainer claims gcc to blame - set_source_files_properties( lib/event-libs/libev/libev.c PROPERTIES COMPILE_FLAGS "-Wno-error" ) -endif() - -if (LWS_WITH_LEJP) - list(APPEND SOURCES - lib/misc/lejp.c) -endif() -if (LWS_WITH_LEJP_CONF AND LWS_WITH_NETWORK AND NOT LWS_PLAT_OPTEE) - list(APPEND SOURCES - "lib/roles/http/server/lejp-conf.c" - ) -endif() -if (LWS_WITH_ABSTRACT) - list(APPEND SOURCES - lib/abstract/transports/unit-test.c) -endif() - -if (LWS_WITH_SMTP) - list(APPEND SOURCES - lib/abstract/protocols/smtp/smtp.c) -endif() - -if (LWS_WITH_RANGES) - list(APPEND SOURCES - lib/roles/http/server/ranges.c) -endif() - -if (LWS_WITH_ZIP_FOPS) - if (LWS_WITH_ZLIB) - list(APPEND SOURCES - lib/roles/http/server/fops-zip.c) - else() - message(FATAL_ERROR "Pre-zipped file support (LWS_WITH_ZIP_FOPS) requires ZLIB (LWS_WITH_ZLIB)") - endif() -endif() - -if (LWS_WITH_JOSE) - list(APPEND SOURCES - lib/jose/jwk/jwk.c - lib/jose/jws/jose.c - lib/jose/jws/jws.c - lib/jose/jwe/jwe.c - lib/jose/jwe/enc/aescbc.c - lib/jose/jwe/enc/aesgcm.c - lib/jose/jwe/enc/aeskw.c - lib/jose/jwe/jwe-rsa-aescbc.c - lib/jose/jwe/jwe-rsa-aesgcm.c - lib/jose/jwe/jwe-ecdh-es-aeskw.c - ) -endif() - -if (LWS_WITH_JOSE OR LWS_WITH_GENCRYPTO) - list(APPEND SOURCES - lib/tls/lws-gencrypto-common.c) -endif() - -# Add helper files for Windows. -if (WIN32) - set(WIN32_HELPERS_PATH win32port/win32helpers) - include_directories(${WIN32_HELPERS_PATH}) - - if (WIN32) - list(APPEND SOURCES - ${WIN32_HELPERS_PATH}/gettimeofday.c - ) - list(APPEND HDR_PRIVATE - ${WIN32_HELPERS_PATH}/gettimeofday.h - ) - endif(WIN32) - -else() - # Unix. - if (NOT LWS_WITHOUT_DAEMONIZE) - list(APPEND SOURCES - lib/misc/daemonize.c) - endif() -endif() - -if (UNIX) - if (NOT LWS_HAVE_GETIFADDRS) - list(APPEND HDR_PRIVATE lib/misc/getifaddrs.h) - list(APPEND SOURCES lib/misc/getifaddrs.c) - endif() -endif() - -if ((CMAKE_C_COMPILER_ID MATCHES "Clang") OR (CMAKE_CXX_COMPILER_ID MATCHES "Clang")) - set(COMPILER_IS_CLANG ON) -endif() if (CMAKE_COMPILER_IS_GNUCC OR CMAKE_COMPILER_IS_GNUCXX OR COMPILER_IS_CLANG) include (CheckCCompilerFlag) CHECK_C_COMPILER_FLAG(-fvisibility=hidden LWS_HAVE_VISIBILITY) + if (LWS_WITH_FANALYZER) + CHECK_C_COMPILER_FLAG(-fanalyzer LWS_HAVE_FANALYZER) + endif() if (LWS_HAVE_VISIBILITY) set(VISIBILITY_FLAG -fvisibility=hidden) endif() if (LWS_WITH_GCOV) set (GCOV_FLAGS "-fprofile-arcs -ftest-coverage ") + else() + set(GCOV_FLAGS "") endif() if (LWS_WITH_ASAN) @@ -1468,6 +667,8 @@ set (ASAN_FLAGS "${ASAN_FLAGS} -fsanitize=pointer-compare -fsanitize=pointer-subtract -fsanitize=leak") endif() message("Enabling ASAN") + else() + set(ASAN_FLAGS "") endif() check_c_compiler_flag("-Wignored-qualifiers" LWS_GCC_HAS_IGNORED_QUALIFIERS) @@ -1481,19 +682,28 @@ set(CMAKE_C_FLAGS "-Wtype-limits ${CMAKE_C_FLAGS}" ) endif() - if (UNIX AND NOT LWS_WITH_ESP32) - set(CMAKE_C_FLAGS "-Wall -Wsign-compare -Wuninitialized -Werror ${VISIBILITY_FLAG} -Wundef ${GCOV_FLAGS} ${CMAKE_C_FLAGS} ${ASAN_FLAGS}" ) - else() - set(CMAKE_C_FLAGS "-Wall -Wsign-compare -Wuninitialized -Werror ${VISIBILITY_FLAG} ${GCOV_FLAGS} ${CMAKE_C_FLAGS}" ) - endif() -endif () + if (LWS_WITH_FANALYZER AND LWS_HAVE_FANALYZER) + set(CMAKE_C_FLAGS "-fanalyzer ${CMAKE_C_FLAGS}" ) + endif() -if (LWS_PLAT_OPTEE) - set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} --sysroot ../../../../lib/libutils/isoc/include -I../../../../lib/libutils/isoc/include -I../../../../lib/libutils/ext/include" ) -endif() + if (CMAKE_COMPILER_IS_CLANG OR CMAKE_C_COMPILER_VERSION VERSION_GREATER 4.4) + set(CMAKE_C_FLAGS "-Wuninitialized ${CMAKE_C_FLAGS}") + endif() + + # always warn all and generate debug info + if (UNIX AND NOT LWS_PLAT_FREERTOS) + set(CMAKE_C_FLAGS "-Wall -Wsign-compare -Wstrict-aliasing ${VISIBILITY_FLAG} -Wundef ${GCOV_FLAGS} ${CMAKE_C_FLAGS} ${ASAN_FLAGS}" ) + else() + set(CMAKE_C_FLAGS "-Wall -Wsign-compare ${VISIBILITY_FLAG} ${GCOV_FLAGS} ${CMAKE_C_FLAGS}" ) + endif() + + if ("${DISABLE_WERROR}" STREQUAL "OFF") + set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Werror") + endif() +endif () if ((CMAKE_COMPILER_IS_GNUCC OR CMAKE_COMPILER_IS_GNUCXX) AND NOT LWS_WITHOUT_TESTAPPS) - if (UNIX AND LWS_HAVE_PTHREAD_H) + if (UNIX AND LWS_HAVE_PTHREAD_H AND NOT (${CMAKE_SYSTEM_NAME} MATCHES "QNX")) # jeez clang understands -pthread but dies if he sees it at link time! # http://stackoverflow.com/questions/2391194/what-is-gs-pthread-equiv-in-clang set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -pthread" ) @@ -1505,155 +715,48 @@ # otherwise osx blows a bunch of openssl deprecated api errors set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wno-deprecated-declarations" ) if (UNIX AND LWS_HAVE_PTHREAD_H) - set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -pthread" ) + set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -pthread -Wno-error=unused-command-line-argument" ) endif() endif() -source_group("Headers Private" FILES ${HDR_PRIVATE}) -source_group("Headers Public" FILES ${HDR_PUBLIC}) -source_group("Sources" FILES ${SOURCES}) -source_group("Resources" FILES ${RESOURCES}) - -# -# Create the lib. -# -set(LWS_LIBRARIES) - -if (LWS_WITH_STATIC) - if (LWS_STATIC_PIC) - set(CMAKE_POSITION_INDEPENDENT_CODE ON) - endif() - add_library(websockets STATIC - ${HDR_PRIVATE} - ${HDR_PUBLIC} - ${SOURCES}) - list(APPEND LWS_LIBRARIES websockets) - - if (WIN32) - # Windows uses the same .lib ending for static libraries and shared - # library linker files, so rename the static library. - set_target_properties(websockets - PROPERTIES - OUTPUT_NAME websockets_static) - endif() - add_custom_command( - TARGET websockets - COMMAND ${CMAKE_COMMAND} -E copy ${CMAKE_CURRENT_SOURCE_DIR}/include/libwebsockets.h - ${CMAKE_CURRENT_BINARY_DIR}/include/libwebsockets.h - ) - - add_custom_command( - TARGET websockets - COMMAND ${CMAKE_COMMAND} -E copy_directory ${CMAKE_CURRENT_SOURCE_DIR}/include/libwebsockets/ - ${CMAKE_CURRENT_BINARY_DIR}/include/libwebsockets - ) - - add_custom_command( - TARGET websockets - COMMAND ${CMAKE_COMMAND} -E copy ${CMAKE_CURRENT_BINARY_DIR}/lws_config.h - ${CMAKE_CURRENT_BINARY_DIR}/include/lws_config.h - ) - +if (WINCE) + list(APPEND LIB_LIST_AT_END ws2.lib) +elseif (WIN32) + list(APPEND LIB_LIST_AT_END ws2_32.lib userenv.lib psapi.lib iphlpapi.lib crypt32.lib) endif() -if (LWS_WITH_SHARED) - add_library(websockets_shared SHARED - ${HDR_PRIVATE} - ${HDR_PUBLIC} - ${SOURCES} - ${RESOURCES}) - list(APPEND LWS_LIBRARIES websockets_shared) - - # We want the shared lib to be named "libwebsockets" - # not "libwebsocket_shared". - set_target_properties(websockets_shared - PROPERTIES - OUTPUT_NAME websockets) - - if (WIN32) - # Compile as DLL (export function declarations) - set_property( - TARGET websockets_shared - PROPERTY COMPILE_DEFINITIONS - LWS_DLL - LWS_INTERNAL) - endif() - - if (APPLE) - set_property(TARGET websockets_shared PROPERTY MACOSX_RPATH YES) - endif() - - add_custom_command( - TARGET websockets_shared - COMMAND ${CMAKE_COMMAND} -E copy ${CMAKE_CURRENT_SOURCE_DIR}/include/libwebsockets.h - ${CMAKE_CURRENT_BINARY_DIR}/include/libwebsockets.h - ) - - add_custom_command( - TARGET websockets - COMMAND ${CMAKE_COMMAND} -E copy_directory ${CMAKE_CURRENT_SOURCE_DIR}/include/libwebsockets - ${CMAKE_CURRENT_BINARY_DIR}/include/libwebsockets - ) - - add_custom_command( - TARGET websockets_shared - COMMAND ${CMAKE_COMMAND} -E copy ${CMAKE_CURRENT_BINARY_DIR}/lws_config.h - ${CMAKE_CURRENT_BINARY_DIR}/include/lws_config.h - ) - +if (MSVC) + # Turn off pointless microsoft security warnings. + add_definitions(-D_CRT_SECURE_NO_DEPRECATE -D_CRT_NONSTDC_NO_DEPRECATE) + # Fail the build if any warnings + add_compile_options(/W3 /WX) +endif(MSVC) +if (MINGW) + set(LWS_MINGW_SUPPORT 1) + set(CMAKE_C_FLAGS "-D__USE_MINGW_ANSI_STDIO ${CMAKE_C_FLAGS}") + add_definitions(-DWINVER=0x0601 -D_WIN32_WINNT=0x0601) endif() -# Set the so version of the lib. -# Equivalent to LDFLAGS=-version-info x:x:x -if(CMAKE_COMPILER_IS_GNUCC OR CMAKE_COMPILER_IS_GNUCXX OR COMPILER_IS_CLANG) - foreach(lib ${LWS_LIBRARIES}) - set_target_properties(${lib} - PROPERTIES - SOVERSION ${SOVERSION}) - endforeach() +if (HDR_PRIVATE) + source_group("Headers Private" FILES ${HDR_PRIVATE}) +endif() +if (HDR_PUBLIC) + source_group("Headers Public" FILES ${HDR_PUBLIC}) +endif() +if (SOURCES) + source_group("Sources" FILES ${SOURCES}) +endif() +if (RESOURCES) + source_group("Resources" FILES ${RESOURCES}) endif() -set(LIB_LIST) - -# -# Find libraries. -# # # ZLIB (needed for deflate extension and if LWS_WITH_HTTP_STREAM_COMPRESSION) # if (LWS_WITH_ZLIB) - if (LWS_WITH_BUNDLED_ZLIB) - if (WIN32) - set(WIN32_ZLIB_PATH "win32port/zlib") - set(ZLIB_SRCS - ${WIN32_ZLIB_PATH}/adler32.c - ${WIN32_ZLIB_PATH}/compress.c - ${WIN32_ZLIB_PATH}/crc32.c - ${WIN32_ZLIB_PATH}/deflate.c - ${WIN32_ZLIB_PATH}/gzlib.c - ${WIN32_ZLIB_PATH}/gzread.c - ${WIN32_ZLIB_PATH}/gzwrite.c - ${WIN32_ZLIB_PATH}/infback.c - ${WIN32_ZLIB_PATH}/inffast.c - ${WIN32_ZLIB_PATH}/inflate.c - ${WIN32_ZLIB_PATH}/inftrees.c - ${WIN32_ZLIB_PATH}/trees.c - ${WIN32_ZLIB_PATH}/uncompr.c - ${WIN32_ZLIB_PATH}/zutil.c) - add_library(zlib_internal STATIC ${ZLIB_SRCS}) - set(ZLIB_INCLUDE_DIRS ${WIN32_ZLIB_PATH}) - get_property(ZLIB_LIBRARIES TARGET zlib_internal PROPERTY LOCATION) - set(ZLIB_FOUND 1) - # Make sure zlib_internal is compiled before the libs. - foreach (lib ${LWS_LIBRARIES}) - add_dependencies(${lib} zlib_internal) - endforeach() - else() - message(FATAL_ERROR "Don't have bundled zlib for that platform") - endif() - elseif (NOT ZLIB_FOUND) + if (NOT ZLIB_FOUND) if (LWS_WITH_MINIZ) find_package(Miniz REQUIRED) set(ZLIB_INCLUDE_DIRS ${MINIZ_INCLUDE_DIRS}) @@ -1665,130 +768,26 @@ message("zlib/miniz include dirs: ${ZLIB_INCLUDE_DIRS}") message("zlib/miniz libraries: ${ZLIB_LIBRARIES}") include_directories(${ZLIB_INCLUDE_DIRS}) - list(APPEND LIB_LIST ${ZLIB_LIBRARIES}) -endif() - -if (LWS_WITH_HTTP_BROTLI) - list(APPEND LIB_LIST brotlienc brotlidec brotlidec) + # done later at end of link list + # list(APPEND LIB_LIST ${ZLIB_LIBRARIES}) + set(CMAKE_REQUIRED_LIBRARIES ${CMAKE_REQUIRED_LIBRARIES} ${ZLIB_LIBRARIES}) + list(APPEND LIB_LIST_AT_END ${ZLIB_LIBRARIES}) endif() -# -# OpenSSL -# -if (LWS_WITH_SSL) - message("Compiling with SSL support") - set(chose_ssl 0) - if (LWS_WITH_WOLFSSL) - # Use wolfSSL as OpenSSL replacement. - # TODO: Add a find_package command for this also. - message("wolfSSL include dir: ${WOLFSSL_INCLUDE_DIRS}") - message("wolfSSL libraries: ${WOLFSSL_LIBRARIES}") - - # Additional to the root directory we need to include - # the wolfssl/ subdirectory which contains the OpenSSL - # compatibility layer headers. - - if (LWS_WITH_CYASSL) - foreach(inc ${WOLFSSL_INCLUDE_DIRS}) - include_directories("${inc}" "${inc}/cyassl") - endforeach() - else() - foreach(inc ${WOLFSSL_INCLUDE_DIRS}) - include_directories("${inc}" "${inc}/wolfssl") - endforeach() - endif() - - list(APPEND LIB_LIST "${WOLFSSL_LIBRARIES}") - set(chose_ssl 1) - endif() - - if (LWS_WITH_MBEDTLS) - message("MBEDTLS include dir: ${MBEDTLS_INCLUDE_DIRS}") - message("MBEDTLS libraries: ${MBEDTLS_LIBRARIES}") - - foreach(inc ${MBEDTLS_INCLUDE_DIRS}) - include_directories("${inc}" "${inc}/mbedtls") - endforeach() - list(APPEND LIB_LIST "${MBEDTLS_LIBRARIES}") - set(chose_ssl 1) +if (LWS_WITH_FSMOUNT AND ${CMAKE_SYSTEM_NAME} STREQUAL "Linux") + if (NOT LWS_LIBMOUNT_INCLUDE_DIRS STREQUAL "") + include_directories(${LWS_LIBMOUNT_INCLUDE_DIRS}) + message("libmount include dir: ${LWS_LIBMOUNT_INCLUDE_DIRS}") endif() - - if (NOT chose_ssl) - if (NOT OPENSSL_FOUND AND NOT LWS_WITH_BORINGSSL) - # TODO: Add support for STATIC also. - if (NOT LWS_WITH_ESP32) - find_package(OpenSSL REQUIRED) - endif() - set(OPENSSL_INCLUDE_DIRS "${OPENSSL_INCLUDE_DIR}") - endif() - - message("OpenSSL include dir: ${OPENSSL_INCLUDE_DIRS}") - if (NOT LWS_WITH_ESP32) - message("OpenSSL libraries: ${OPENSSL_LIBRARIES}") - endif() - - include_directories("${OPENSSL_INCLUDE_DIRS}") - if (NOT LWS_WITH_ESP32) - list(APPEND LIB_LIST ${OPENSSL_LIBRARIES}) - endif() - - if (NOT LWS_WITH_MBEDTLS) - # older (0.98) Openssl lacks this - set(CMAKE_REQUIRED_INCLUDES ${OPENSSL_INCLUDE_DIRS}) - check_include_file(openssl/ecdh.h LWS_HAVE_OPENSSL_ECDH_H) - - if (LWS_SSL_SERVER_WITH_ECDH_CERT AND NOT LWS_HAVE_OPENSSL_ECDH_H) - message(FATAL_ERROR "Missing openssl/ecdh.h, so cannot use LWS_SSL_SERVER_WITH_ECDH_CERT") - endif() + if (NOT LWS_LIBMOUNT_LIBRARIES STREQUAL "") + message("libmount libraries: ${LWS_LIBMOUNT_LIBRARIES}") + list(APPEND LIB_LIST ${LWS_LIBMOUNT_LIBRARIES}) else() - unset(LWS_HAVE_OPENSSL_ECDH_H) - endif(NOT LWS_WITH_MBEDTLS) - endif() - -endif(LWS_WITH_SSL) - -if (LWS_WITH_LIBEV) - if (NOT LIBEV_FOUND) - find_path(LIBEV_INCLUDE_DIRS NAMES ev.h) - find_library(LIBEV_LIBRARIES NAMES ev) - if(LIBEV_INCLUDE_DIRS AND LIBEV_LIBRARIES) - set(LIBEV_FOUND 1) - endif() - endif() - message("libev include dir: ${LIBEV_INCLUDE_DIRS}") - message("libev libraries: ${LIBEV_LIBRARIES}") - include_directories("${LIBEV_INCLUDE_DIRS}") - list(APPEND LIB_LIST ${LIBEV_LIBRARIES}) -endif(LWS_WITH_LIBEV) - -if (LWS_WITH_LIBUV) - if (NOT LIBUV_FOUND) - find_path(LIBUV_INCLUDE_DIRS NAMES uv.h) - find_library(LIBUV_LIBRARIES NAMES uv) - if(LIBUV_INCLUDE_DIRS AND LIBUV_LIBRARIES) - set(LIBUV_FOUND 1) - endif() + list(APPEND LIB_LIST mount) endif() - message("libuv include dir: ${LIBUV_INCLUDE_DIRS}") - message("libuv libraries: ${LIBUV_LIBRARIES}") - include_directories("${LIBUV_INCLUDE_DIRS}") - list(APPEND LIB_LIST ${LIBUV_LIBRARIES}) endif() -if (LWS_WITH_LIBEVENT) - if (NOT LIBEVENT_FOUND) - find_path(LIBEVENT_INCLUDE_DIRS NAMES event2/event.h) - find_library(LIBEVENT_LIBRARIES NAMES event) - if(LIBEVENT_INCLUDE_DIRS AND LIBEVENT_LIBRARIES) - set(LIBEVENT_FOUND 1) - endif() - endif() - message("libevent include dir: ${LIBEVENT_INCLUDE_DIRS}") - message("libevent libraries: ${LIBEVENT_LIBRARIES}") - include_directories("${LIBEVENT_INCLUDE_DIRS}") - list(APPEND LIB_LIST ${LIBEVENT_LIBRARIES}) -endif(LWS_WITH_LIBEVENT) if (LWS_WITH_SQLITE3) if (NOT SQLITE3_FOUND) @@ -1810,682 +809,126 @@ list(APPEND LIB_LIST ${LIBHUBBUB_LIBRARIES} ) endif() -if (LWS_ROLE_DBUS) - message("dbus include dir 1: ${LWS_DBUS_INCLUDE1}") - message("dbus include dir 2: ${LWS_DBUS_INCLUDE2}") - include_directories("${LWS_DBUS_INCLUDE1}") - include_directories("${LWS_DBUS_INCLUDE2}") - list(APPEND LIB_LIST ${LWS_DBUS_LIB}) +if (LWS_HAVE_LIBCAP) + find_library(LIBCAP_LIBRARIES NAMES cap) + list(APPEND LIB_LIST ${LIBCAP_LIBRARIES} ) endif() + # -# Platform specific libs. +# Append the "at end" pieces to the lib list # -if (WINCE) - list(APPEND LIB_LIST ws2.lib) -elseif (WIN32) - list(APPEND LIB_LIST ws2_32.lib userenv.lib psapi.lib iphlpapi.lib) -endif() - -if (${CMAKE_SYSTEM_NAME} MATCHES "QNX") - list(APPEND LIB_LIST socket) -endif() - -if (UNIX) - list(APPEND LIB_LIST m) -endif() - -if(SMARTOS) - list(APPEND LIB_LIST socket) -endif() +list(APPEND LIB_LIST ${LIB_LIST_AT_END}) -if (HAIKU) - list(APPEND LIB_LIST network) -endif() +# +# Second-level CMakeLists +# -if (LWS_HAVE_LIBCAP) - list(APPEND LIB_LIST cap ) -endif() +include_directories("${PROJECT_SOURCE_DIR}/lib") +add_subdirectory(lib) -# Setup the linking for all libs. -foreach (lib ${LWS_LIBRARIES}) - target_link_libraries(${lib} ${LIB_LIST}) -endforeach() -set (temp ${CMAKE_REQUIRED_LIBRARIES}) -set(CMAKE_REQUIRED_LIBRARIES ${LIB_LIST}) - -if (LWS_WITH_ZLIB) - if (LWS_WITH_BUNDLED_ZLIB) - if (WIN32) - # it's trying to delete internal zlib entry - LIST(REMOVE_AT CMAKE_REQUIRED_LIBRARIES 0 ) - endif() - endif() -endif() - -CHECK_FUNCTION_EXISTS(SSL_CTX_set1_param LWS_HAVE_SSL_CTX_set1_param) -CHECK_FUNCTION_EXISTS(SSL_set_info_callback LWS_HAVE_SSL_SET_INFO_CALLBACK) -CHECK_FUNCTION_EXISTS(X509_VERIFY_PARAM_set1_host LWS_HAVE_X509_VERIFY_PARAM_set1_host) -CHECK_FUNCTION_EXISTS(RSA_set0_key LWS_HAVE_RSA_SET0_KEY) -CHECK_FUNCTION_EXISTS(X509_get_key_usage LWS_HAVE_X509_get_key_usage) -CHECK_FUNCTION_EXISTS(EVP_PKEY_new_raw_private_key LWS_HAVE_SSL_CTX_EVP_PKEY_new_raw_private_key) -CHECK_FUNCTION_EXISTS(SSL_CTX_get0_certificate LWS_HAVE_SSL_CTX_get0_certificate) -CHECK_FUNCTION_EXISTS(SSL_get0_alpn_selected LWS_HAVE_SSL_get0_alpn_selected) -CHECK_FUNCTION_EXISTS(SSL_set_alpn_protos LWS_HAVE_SSL_set_alpn_protos) -CHECK_FUNCTION_EXISTS(EVP_aes_128_cfb8 LWS_HAVE_EVP_aes_128_cfb8) -CHECK_FUNCTION_EXISTS(EVP_aes_128_cfb128 LWS_HAVE_EVP_aes_128_cfb128) -CHECK_FUNCTION_EXISTS(EVP_aes_192_cfb8 LWS_HAVE_EVP_aes_192_cfb8) -CHECK_FUNCTION_EXISTS(EVP_aes_192_cfb128 LWS_HAVE_EVP_aes_192_cfb128) -CHECK_FUNCTION_EXISTS(EVP_aes_256_cfb8 LWS_HAVE_EVP_aes_256_cfb8) -CHECK_FUNCTION_EXISTS(EVP_aes_256_cfb128 LWS_HAVE_EVP_aes_256_cfb128) -CHECK_FUNCTION_EXISTS(EVP_aes_128_xts LWS_HAVE_EVP_aes_128_xts) -CHECK_FUNCTION_EXISTS(RSA_verify_pss_mgf1 LWS_HAVE_RSA_verify_pss_mgf1) -CHECK_FUNCTION_EXISTS(HMAC_CTX_new LWS_HAVE_HMAC_CTX_new) -CHECK_FUNCTION_EXISTS(SSL_CTX_set_ciphersuites LWS_HAVE_SSL_CTX_set_ciphersuites) -if (LWS_WITH_SSL AND NOT LWS_WITH_MBEDTLS) - if (UNIX) - set(CMAKE_REQUIRED_LIBRARIES ${CMAKE_REQUIRED_LIBRARIES} dl) - endif() -CHECK_C_SOURCE_COMPILES("#include \nint main(void) { STACK_OF(X509) *c = NULL; SSL_CTX *ctx = NULL; return (int)SSL_CTX_get_extra_chain_certs_only(ctx, &c); }\n" LWS_HAVE_SSL_EXTRA_CHAIN_CERTS) -CHECK_C_SOURCE_COMPILES("#include \nint main(void) { EVP_MD_CTX *md_ctx = NULL; EVP_MD_CTX_free(md_ctx); return 0; }\n" LWS_HAVE_EVP_MD_CTX_free) -CHECK_FUNCTION_EXISTS(ECDSA_SIG_set0 LWS_HAVE_ECDSA_SIG_set0) -CHECK_FUNCTION_EXISTS(BN_bn2binpad LWS_HAVE_BN_bn2binpad) -CHECK_FUNCTION_EXISTS(EVP_aes_128_wrap LWS_HAVE_EVP_aes_128_wrap) -CHECK_FUNCTION_EXISTS(EC_POINT_get_affine_coordinates LWS_HAVE_EC_POINT_get_affine_coordinates) -endif() -if (LWS_WITH_MBEDTLS) - set(LWS_HAVE_TLS_CLIENT_METHOD 1) - if (NOT LWS_WITH_ESP32) - # not supported in esp-idf openssl wrapper yet, but is in our version - set(LWS_HAVE_X509_VERIFY_PARAM_set1_host 1) - endif() - - CHECK_FUNCTION_EXISTS(mbedtls_ssl_conf_alpn_protocols LWS_HAVE_mbedtls_ssl_conf_alpn_protocols) - CHECK_FUNCTION_EXISTS(mbedtls_ssl_get_alpn_protocol LWS_HAVE_mbedtls_ssl_get_alpn_protocol) - CHECK_FUNCTION_EXISTS(mbedtls_ssl_conf_sni LWS_HAVE_mbedtls_ssl_conf_sni) - CHECK_FUNCTION_EXISTS(mbedtls_ssl_set_hs_ca_chain LWS_HAVE_mbedtls_ssl_set_hs_ca_chain) - CHECK_FUNCTION_EXISTS(mbedtls_ssl_set_hs_own_cert LWS_HAVE_mbedtls_ssl_set_hs_own_cert) - CHECK_FUNCTION_EXISTS(mbedtls_ssl_set_hs_authmode LWS_HAVE_mbedtls_ssl_set_hs_authmode) - CHECK_FUNCTION_EXISTS(mbedtls_net_init LWS_HAVE_mbedtls_net_init) +if(WIN32 AND NOT CYGWIN) + set(DEF_INSTALL_CMAKE_DIR cmake) else() -CHECK_FUNCTION_EXISTS(TLS_client_method LWS_HAVE_TLS_CLIENT_METHOD) -CHECK_FUNCTION_EXISTS(TLSv1_2_client_method LWS_HAVE_TLSV1_2_CLIENT_METHOD) -endif() - -# ideally we want to use pipe2() - -CHECK_C_SOURCE_COMPILES("#define _GNU_SOURCE\n#include \nint main(void) {int fd[2];\n return pipe2(fd, 0);\n}\n" LWS_HAVE_PIPE2) - -# tcp keepalive needs this on linux to work practically... but it only exists -# after kernel 2.6.37 - -CHECK_C_SOURCE_COMPILES("#include \nint main(void) { return TCP_USER_TIMEOUT; }\n" LWS_HAVE_TCP_USER_TIMEOUT) - -set(CMAKE_REQUIRED_LIBRARIES ${temp}) -# Generate the lws_config.h that includes all the public compilation settings. -configure_file( - "${PROJECT_SOURCE_DIR}/cmake/lws_config.h.in" - "${PROJECT_BINARY_DIR}/lws_config.h") - -# Generate the lws_config.h that includes all the private compilation settings. -configure_file( - "${PROJECT_SOURCE_DIR}/cmake/lws_config_private.h.in" - "${PROJECT_BINARY_DIR}/lws_config_private.h") - -# Generate self-signed SSL certs for the test-server. - -if (LWS_WITH_SSL AND NOT LWS_WITH_WOLFSSL) - message("Searching for OpenSSL executable and dlls") - find_package(OpenSSLbins) - message("OpenSSL executable: ${OPENSSL_EXECUTABLE}") - if (OPENSSL_EXECUTABLE MATCHES "^$") - set(OPENSSL_EXECUTABLE openssl) - endif() - if (NOT OPENSSL_EXECUTABLE) - set(OPENSSL_EXECUTABLE openssl) - endif() - + set(DEF_INSTALL_CMAKE_DIR lib${LIB_SUFFIX}/cmake/libwebsockets) endif() -set(GENCERTS 0) - -if (LWS_WITH_SSL AND OPENSSL_EXECUTABLE AND NOT LWS_WITHOUT_TEST_SERVER AND NOT LWS_WITHOUT_SERVER AND NOT LWS_WITHOUT_TESTAPPS) - set(GENCERTS 1) -endif() -if (LWS_WITH_ESP32) - set(GENCERTS 1) -endif() -message(" GENCERTS = ${GENCERTS}") -if (GENCERTS) - message("Generating SSL Certificates for the test-server...") - - set(TEST_SERVER_SSL_KEY "${PROJECT_BINARY_DIR}/libwebsockets-test-server.key.pem") - set(TEST_SERVER_SSL_CERT "${PROJECT_BINARY_DIR}/libwebsockets-test-server.pem") - - if (WIN32) - if (MINGW) - message("cmd = \"${OPENSSL_EXECUTABLE}\" req -new -newkey rsa:1024 -days 10000 -nodes -x509 -subj \"/C=GB/ST=Erewhon/L=All around/O=libwebsockets-test/CN=localhost\" -keyout \"${TEST_SERVER_SSL_KEY}\" -out \"${TEST_SERVER_SSL_CERT}\"") - execute_process( - COMMAND "${OPENSSL_EXECUTABLE}" req -new -newkey rsa:1024 -days 10000 -nodes -x509 -subj "/C=GB/ST=Erewhon/L=All around/O=libwebsockets-test/CN=localhost" -keyout "${TEST_SERVER_SSL_KEY}" -out "${TEST_SERVER_SSL_CERT}" - RESULT_VARIABLE OPENSSL_RETURN_CODE) - else() - file(WRITE "${PROJECT_BINARY_DIR}/openssl_input.txt" - "GB\n" - "Erewhon\n" - "All around\n" - "libwebsockets-test\n" - "localhost\n" - "none@invalid.org\n\n" - ) - - # The "type" command is a bit picky with paths. - file(TO_NATIVE_PATH "${PROJECT_BINARY_DIR}/openssl_input.txt" OPENSSL_INPUT_WIN_PATH) - message("OPENSSL_INPUT_WIN_PATH = ${OPENSSL_INPUT_WIN_PATH}") - message("cmd = \"${OPENSSL_EXECUTABLE}\" req -new -newkey rsa:1024 -days 10000 -nodes -x509 -keyout \"${TEST_SERVER_SSL_KEY}\" -out \"${TEST_SERVER_SSL_CERT}\"") - - execute_process( - COMMAND cmd /c type "${OPENSSL_INPUT_WIN_PATH}" - COMMAND "${OPENSSL_EXECUTABLE}" req -new -newkey rsa:1024 -days 10000 -nodes -x509 -keyout "${TEST_SERVER_SSL_KEY}" -out "${TEST_SERVER_SSL_CERT}" - RESULT_VARIABLE OPENSSL_RETURN_CODE - OUTPUT_QUIET ERROR_QUIET) +if (DEFINED REL_INCLUDE_DIR) + set(LWS__INCLUDE_DIRS "\${LWS_CMAKE_DIR}/${REL_INCLUDE_DIR}") +endif() - message("\n") - endif() +configure_file(${PROJECT_SOURCE_DIR}/cmake/libwebsockets-config.cmake.in + ${PROJECT_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/libwebsockets-config.cmake + @ONLY) - if (OPENSSL_RETURN_CODE) - message(WARNING "!!! Failed to generate SSL certificate for Test Server using cmd.exe !!!:\nOpenSSL return code = ${OPENSSL_RETURN_CODE}") - else() - message("SUCCSESFULLY generated SSL certificate") - endif() - else() - # Unix. - execute_process( - COMMAND printf "GB\\nErewhon\\nAll around\\nlibwebsockets-test\\n\\nlocalhost\\nnone@invalid.org\\n" - COMMAND "${OPENSSL_EXECUTABLE}" - req -new -newkey rsa:1024 -days 10000 -nodes -x509 -keyout "${TEST_SERVER_SSL_KEY}" -out "${TEST_SERVER_SSL_CERT}" - RESULT_VARIABLE OPENSSL_RETURN_CODE - # OUTPUT_QUIET ERROR_QUIET - ) +# Generate version info for both build-tree and install-tree. +configure_file(${PROJECT_SOURCE_DIR}/cmake/libwebsockets-config-version.cmake.in + ${PROJECT_BINARY_DIR}/libwebsockets-config-version.cmake + @ONLY) - if (OPENSSL_RETURN_CODE) - message(WARNING "!!! Failed to generate SSL certificate for Test Server!!!:\nOpenSSL return code = ${OPENSSL_RETURN_CODE}") - else() - message("SUCCESSFULLY generated SSL certificate") - endif() - endif() +# Generate the config file for the build-tree. +set(LWS__INCLUDE_DIRS + "${PROJECT_SOURCE_DIR}/lib" + "${PROJECT_BINARY_DIR}") +set(LIBWEBSOCKETS_INCLUDE_DIRS ${LWS__INCLUDE_DIRS} CACHE PATH "Libwebsockets include directories") +configure_file(${PROJECT_SOURCE_DIR}/cmake/libwebsockets-config.cmake.in + ${PROJECT_BINARY_DIR}/libwebsockets-config.cmake + @ONLY) +set(LWS_INSTALL_CMAKE_DIR ${DEF_INSTALL_CMAKE_DIR} CACHE PATH "Installation directory for CMake files") - list(APPEND TEST_SERVER_DATA - "${TEST_SERVER_SSL_KEY}" - "${TEST_SERVER_SSL_CERT}") +# Export targets (This is used for other CMake projects to easily find the libraries and include files). +if (LWS_WITH_EXPORT_LWSTARGETS) + export(TARGETS ${LWS_LIBRARIES} + FILE "${PROJECT_BINARY_DIR}/LibwebsocketsTargets.cmake") endif() +set(libwebsockets_DIR ${PROJECT_BINARY_DIR}) +set(CMAKE_MODULE_PATH "${PROJECT_SOURCE_DIR}/cmake") +message("DIR ${libwebsockets_DIR} CMP ${CMAKE_MODULE_PATH}") -# -# Test applications -# -set(TEST_APP_LIST) -if ((LWS_ROLE_H1 OR LWS_ROLE_H2) AND NOT LWS_WITHOUT_TESTAPPS) - # - # Helper function for adding a test app. - # - macro(create_test_app TEST_NAME MAIN_SRC S2 S3 S4 S5 S6) - - set(TEST_SRCS ${MAIN_SRC}) - set(TEST_HDR) - if ("${S2}" STREQUAL "") - else() - list(APPEND TEST_SRCS ${S2}) - endif() - if ("${S3}" STREQUAL "") - else() - list(APPEND TEST_SRCS ${S3}) - endif() - if ("${S4}" STREQUAL "") - else() - list(APPEND TEST_SRCS ${S4}) - endif() - if ("${S5}" STREQUAL "") - else() - list(APPEND TEST_SRCS ${S5}) - endif() - if ("${S6}" STREQUAL "") - else() - list(APPEND TEST_SRCS ${S6}) - endif() - if (WIN32) - list(APPEND TEST_SRCS - ${WIN32_HELPERS_PATH}/getopt.c - ${WIN32_HELPERS_PATH}/getopt_long.c - ${WIN32_HELPERS_PATH}/gettimeofday.c - ) - - list(APPEND TEST_HDR - ${WIN32_HELPERS_PATH}/getopt.h - ${WIN32_HELPERS_PATH}/gettimeofday.h - ) - endif(WIN32) - - source_group("Headers Private" FILES ${TEST_HDR}) - source_group("Sources" FILES ${TEST_SRCS}) - add_executable(${TEST_NAME} ${TEST_SRCS} ${TEST_HDR}) - - if (LWS_LINK_TESTAPPS_DYNAMIC) - if (NOT LWS_WITH_SHARED) - message(FATAL_ERROR "Build of the shared library is disabled. LWS_LINK_TESTAPPS_DYNAMIC must be combined with LWS_WITH_SHARED.") - endif() - target_link_libraries(${TEST_NAME} websockets_shared) - add_dependencies(${TEST_NAME} websockets_shared) - else() - if (NOT LWS_WITH_STATIC) - message(FATAL_ERROR "Build of the static library is disabled. Disabled LWS_LINK_TESTAPPS_DYNAMIC must be combined with LWS_WITH_STATIC.") - endif() - target_link_libraries(${TEST_NAME} websockets) - add_dependencies(${TEST_NAME} websockets) - if (UNIX AND LWS_WITH_SSL AND NOT LWS_WITH_MBEDTLS) - target_link_libraries(${TEST_NAME} dl) - endif() - endif() - - if (LWS_WITH_HTTP_STREAM_COMPRESSION) - target_link_libraries(${TEST_NAME} z) - endif() - - # Set test app specific defines. - set_property(TARGET ${TEST_NAME} - PROPERTY COMPILE_DEFINITIONS - INSTALL_DATADIR="${CMAKE_INSTALL_PREFIX}/share" - ) - - # Prefix the binary names with libwebsockets. - set_target_properties(${TEST_NAME} - PROPERTIES - OUTPUT_NAME libwebsockets-${TEST_NAME}) - - # Add to the list of tests. - list(APPEND TEST_APP_LIST ${TEST_NAME}) - endmacro() - - if (UNIX AND LWS_WITH_PLUGINS) - set(CMAKE_C_FLAGS "-fPIC ${CMAKE_C_FLAGS}") - if(NOT((${CMAKE_SYSTEM_NAME} MATCHES "FreeBSD") OR (${CMAKE_SYSTEM_NAME} MATCHES "QNX"))) - target_link_libraries(websockets dl) - endif() - endif() - - if (NOT LWS_WITHOUT_SERVER) - # - # test-server - # - if (NOT LWS_WITHOUT_TEST_SERVER) - create_test_app(test-server "test-apps/test-server.c" - "" - "" - "" - "" - "") - - if (LWS_WITH_CGI) - create_test_app(test-sshd "test-apps/test-sshd.c" - "" - "" - "" - "" - "") - target_include_directories(test-sshd PRIVATE "${PROJECT_SOURCE_DIR}/plugins/ssh-base/include") - - endif() - - endif() - - # - # test-server-extpoll - # - if (NOT LWS_WITHOUT_TEST_SERVER_EXTPOLL AND NOT WIN32) - create_test_app(test-server-extpoll - "test-apps/test-server.c" - "" - "" - "" - "" - "") - # Set defines for this executable only. - set_property( - TARGET test-server-extpoll - PROPERTY COMPILE_DEFINITIONS - EXTERNAL_POLL - INSTALL_DATADIR="${CMAKE_INSTALL_PREFIX}/share" - ) - - # We need to link against winsock code. - if (WIN32) - target_link_libraries(test-server-extpoll ws2_32.lib) - endif(WIN32) - endif() - - if (LWS_WITH_LEJP) - create_test_app( - test-lejp - "test-apps/test-lejp.c" - "" - "" - "" - "" - "") - endif() - - # Data files for running the test server. - list(APPEND TEST_SERVER_DATA - "${PROJECT_SOURCE_DIR}/test-apps/favicon.ico" - "${PROJECT_SOURCE_DIR}/test-apps/leaf.jpg" - "${PROJECT_SOURCE_DIR}/test-apps/candide.zip" - "${PROJECT_SOURCE_DIR}/test-apps/libwebsockets.org-logo.svg" - "${PROJECT_SOURCE_DIR}/test-apps/http2.png" - "${PROJECT_SOURCE_DIR}/test-apps/wss-over-h2.png" - "${PROJECT_SOURCE_DIR}/test-apps/lws-common.js" - "${PROJECT_SOURCE_DIR}/test-apps/test.html" - "${PROJECT_SOURCE_DIR}/test-apps/test.css" - "${PROJECT_SOURCE_DIR}/test-apps/test.js") - - add_custom_command(TARGET test-server - POST_BUILD - COMMAND "${CMAKE_COMMAND}" -E make_directory "$/../share/libwebsockets-test-server") - - # Copy the file needed to run the server so that the test apps can - # reach them from their default output location - foreach (TEST_FILE ${TEST_SERVER_DATA}) - if (EXISTS ${TEST_FILE}) - add_custom_command(TARGET test-server - POST_BUILD - COMMAND "${CMAKE_COMMAND}" -E copy "${TEST_FILE}" "$/../share/libwebsockets-test-server" VERBATIM) - endif() - endforeach() - endif(NOT LWS_WITHOUT_SERVER) - - if (NOT LWS_WITHOUT_CLIENT) - # - # test-client - # - if (NOT LWS_WITHOUT_TEST_CLIENT) - create_test_app(test-client "test-apps/test-client.c" "" "" "" "" "") - endif() - - endif(NOT LWS_WITHOUT_CLIENT) - - - if (LWS_WITH_PLUGINS AND LWS_WITH_SHARED) - macro(create_plugin PLUGIN_NAME PLUGIN_INCLUDE MAIN_SRC S2 S3) - - set(PLUGIN_SRCS ${MAIN_SRC}) - - if ("${S2}" STREQUAL "") - else() - list(APPEND PLUGIN_SRCS ${S2}) - endif() - if ("${S3}" STREQUAL "") - else() - list(APPEND PLUGIN_SRCS ${S3}) - endif() - - if (WIN32) - list(APPEND PLUGIN_SRCS - ${WIN32_HELPERS_PATH}/getopt.c - ${WIN32_HELPERS_PATH}/getopt_long.c - ${WIN32_HELPERS_PATH}/gettimeofday.c - ) - - list(APPEND PLUGIN_HDR - ${WIN32_HELPERS_PATH}/getopt.h - ${WIN32_HELPERS_PATH}/gettimeofday.h - ) - endif(WIN32) - - source_group("Headers Private" FILES ${PLUGIN_HDR}) - source_group("Sources" FILES ${PLUGIN_SRCS}) - add_library(${PLUGIN_NAME} SHARED ${PLUGIN_SRCS} ${PLUGIN_HDR}) - - target_link_libraries(${PLUGIN_NAME} websockets_shared) - add_dependencies(${PLUGIN_NAME} websockets_shared) - include_directories(${PLUGIN_INCLUDE}) - - # Set test app specific defines. - set_property(TARGET ${PLUGIN_NAME} - PROPERTY COMPILE_DEFINITIONS - INSTALL_DATADIR="${CMAKE_INSTALL_PREFIX}/plugins" - ) - - SET_TARGET_PROPERTIES(${PLUGIN_NAME} - PROPERTIES COMPILE_FLAGS ${CMAKE_C_FLAGS}) - -# set_target_properties(${PLUGIN_NAME} -# PROPERTIES -# OUTPUT_NAME ${PLUGIN_NAME}) - - list(APPEND PLUGINS_LIST ${PLUGIN_NAME}) - - endmacro() - -if (LWS_ROLE_WS) - create_plugin(protocol_dumb_increment "" - "plugins/protocol_dumb_increment.c" "" "") - create_plugin(protocol_lws_mirror "" - "plugins/protocol_lws_mirror.c" "" "") - create_plugin(protocol_lws_status "" - "plugins/protocol_lws_status.c" "" "") - create_plugin(protocol_lws_table_dirlisting "" - "plugins/generic-table/protocol_table_dirlisting.c" "" "") - if (NOT WIN32) - create_plugin(protocol_lws_raw_test "" - "plugins/protocol_lws_raw_test.c" "" "") - - create_plugin(protocol_deaddrop "" - "plugins/deaddrop/protocol_lws_deaddrop.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" "" "") +if (LWS_WITH_MINIMAL_EXAMPLES) + add_subdirectory(minimal-examples) endif() +if (NOT LWS_WITHOUT_TESTAPPS) + add_subdirectory(test-apps) endif() - create_plugin(protocol_post_demo "" - "plugins/protocol_post_demo.c" "" "") +add_subdirectory(plugins) +add_subdirectory(lwsws) -if (LWS_ROLE_RAW_PROXY) - create_plugin(protocol_lws_raw_proxy "" - "plugins/raw-proxy/protocol_lws_raw_proxy.c" "" "") -endif() +# Generate the lws_config.h that includes all the public compilation settings. +configure_file( + "${PROJECT_SOURCE_DIR}/cmake/lws_config.h.in" + "${PROJECT_BINARY_DIR}/lws_config.h") + +add_custom_command( + OUTPUT ${PROJECT_BINARY_DIR}/include/lws_config.h + ${PROJECT_BINARY_DIR}/include/libwebsockets + ${PROJECT_BINARY_DIR}/include/libwebsockets.h + COMMENT "Creating build include dir" + COMMAND ${CMAKE_COMMAND} -E copy ${CMAKE_CURRENT_SOURCE_DIR}/include/libwebsockets.h + ${CMAKE_CURRENT_BINARY_DIR}/include/libwebsockets.h + COMMAND ${CMAKE_COMMAND} -E copy_directory ${CMAKE_CURRENT_SOURCE_DIR}/include/libwebsockets/ + ${CMAKE_CURRENT_BINARY_DIR}/include/libwebsockets + COMMAND ${CMAKE_COMMAND} -E copy ${PROJECT_BINARY_DIR}/lws_config.h + ${CMAKE_CURRENT_BINARY_DIR}/include/lws_config.h + MAIN_DEPENDENCY ${PROJECT_BINARY_DIR}/lws_config.h +) -if (LWS_WITH_FTS) - create_plugin(protocol_fulltext_demo "" - "plugins/protocol_fulltext_demo.c" "" "") -endif() +add_custom_target(GENHDR DEPENDS ${PROJECT_BINARY_DIR}/include/lws_config.h) +file(GLOB HDR_PUBLIC1 RELATIVE ${CMAKE_CURRENT_SOURCE_DIR} include/libwebsockets/*.h) +file(GLOB HDR_PUBLIC2 RELATIVE ${CMAKE_CURRENT_SOURCE_DIR} include/libwebsockets.h) +file(GLOB HDR_PUBLIC3 RELATIVE ${CMAKE_CURRENT_SOURCE_DIR} ${CMAKE_CURRENT_BINARY_DIR}/include/lws_config.h) +list(APPEND HDR_PUBLIC ${HDR_PUBLIC1} ${HDR_PUBLIC2} ${HDR_PUBLIC3}) -if (LWS_WITH_SSL) - create_plugin(protocol_lws_ssh_base "plugins/ssh-base/include" - "plugins/ssh-base/sshd.c;plugins/ssh-base/telnet.c;plugins/ssh-base/kex-25519.c" "plugins/ssh-base/crypto/chacha.c;plugins/ssh-base/crypto/ed25519.c;plugins/ssh-base/crypto/fe25519.c;plugins/ssh-base/crypto/ge25519.c;plugins/ssh-base/crypto/poly1305.c;plugins/ssh-base/crypto/sc25519.c;plugins/ssh-base/crypto/smult_curve25519_ref.c" "") - create_plugin(protocol_lws_sshd_demo "plugins/ssh-base/include" "plugins/protocol_lws_sshd_demo.c" "" "") +set_source_files_properties(${HDR_PUBLIC} PROPERTIES GENERATED 1) - include_directories("${PROJECT_SOURCE_DIR}/plugins/ssh-base/include") +if (LWS_WITH_STATIC) + add_dependencies(websockets GENHDR) endif() - - - -if (LWS_WITH_ACME) - create_plugin(protocol_lws_acme_client "" - "plugins/acme-client/protocol_lws_acme_client.c" "" "") +if (LWS_WITH_SHARED) + add_dependencies(websockets_shared GENHDR) endif() -if (LWS_WITH_GENERIC_SESSIONS AND LWS_ROLE_WS) - create_plugin(protocol_generic_sessions "" - "plugins/generic-sessions/protocol_generic_sessions.c" - "plugins/generic-sessions/utils.c" - "plugins/generic-sessions/handlers.c") - - if (WIN32) - target_link_libraries(protocol_generic_sessions ${LWS_SQLITE3_LIBRARIES}) - else() - target_link_libraries(protocol_generic_sessions sqlite3 ) - endif(WIN32) - - create_plugin(protocol_lws_messageboard "" - "plugins/generic-sessions/protocol_lws_messageboard.c" "" "") - if (WIN32) - target_link_libraries(protocol_lws_messageboard ${LWS_SQLITE3_LIBRARIES}) - else() - target_link_libraries(protocol_lws_messageboard sqlite3 ) - endif(WIN32) - -endif(LWS_WITH_GENERIC_SESSIONS AND LWS_ROLE_WS) - - - endif(LWS_WITH_PLUGINS AND LWS_WITH_SHARED) - - # - # Copy OpenSSL dlls to the output directory on Windows. - # (Otherwise we'll get an error when trying to run) - # - if (WIN32 AND LWS_WITH_SSL AND NOT LWS_WITH_WOLFSSL) - if(OPENSSL_BIN_FOUND) - message("OpenSSL dlls found:") - message(" Libeay: ${LIBEAY_BIN}") - message(" SSLeay: ${SSLEAY_BIN}") - - foreach(TARGET_BIN ${TEST_APP_LIST}) - add_custom_command(TARGET ${TARGET_BIN} - POST_BUILD - COMMAND "${CMAKE_COMMAND}" -E copy "${LIBEAY_BIN}" "$" VERBATIM) - add_custom_command(TARGET ${TARGET_BIN} - POST_BUILD - COMMAND "${CMAKE_COMMAND}" -E copy "${SSLEAY_BIN}" "$" VERBATIM) - - # - # Win32: if we are using libuv, also need to copy it in the output dir - # - if (WIN32 AND LWS_WITH_LIBUV) - STRING(REPLACE ".lib" ".dll" LIBUV_BIN ${LIBUV_LIBRARIES}) - add_custom_command(TARGET ${TARGET_BIN} - POST_BUILD - COMMAND "${CMAKE_COMMAND}" -E copy "${LIBUV_BIN}" "$" VERBATIM) - endif() - endforeach() - endif() - endif() -endif((LWS_ROLE_H1 OR LWS_ROLE_H2) AND NOT LWS_WITHOUT_TESTAPPS) - -if (LWS_WITH_LWSWS) - list(APPEND LWSWS_SRCS - "lwsws/main.c" - ) - - if (WIN32) - list(APPEND LWSWS_SRCS - ${WIN32_HELPERS_PATH}/getopt.c - ${WIN32_HELPERS_PATH}/getopt_long.c - ${WIN32_HELPERS_PATH}/gettimeofday.c - ) - - list(APPEND LWSWS_HDR - ${WIN32_HELPERS_PATH}/getopt.h - ${WIN32_HELPERS_PATH}/gettimeofday.h - ) - endif(WIN32) - - source_group("Headers Private" FILES ${LWSWS_HDR}) - source_group("Sources" FILES ${LWSWS_SRCS}) - add_executable("lwsws" ${LWSWS_SRCS} ${LWSWS_HDR}) - - target_link_libraries("lwsws" websockets_shared) - add_dependencies("lwsws" websockets_shared) - - # Set test app specific defines. - set_property(TARGET "lwsws" - PROPERTY COMPILE_DEFINITIONS - INSTALL_DATADIR="${CMAKE_INSTALL_PREFIX}/share" - ) -endif (LWS_WITH_LWSWS) - -if (UNIX) - -# Generate and install pkgconfig. -# (This is not indented, because the tabs will be part of the output) -file(WRITE "${PROJECT_BINARY_DIR}/libwebsockets.pc" -"prefix=\"${CMAKE_INSTALL_PREFIX}\" -exec_prefix=\${prefix} -libdir=\${exec_prefix}/lib${LIB_SUFFIX} -includedir=\${prefix}/include - -Name: libwebsockets -Description: Websockets server and client library -Version: ${CPACK_PACKAGE_VERSION_MAJOR}.${CPACK_PACKAGE_VERSION_MINOR}.${CPACK_PACKAGE_VERSION_PATCH} - -Libs: -L\${libdir} -lwebsockets -Cflags: -I\${includedir}" -) - - install(FILES "${PROJECT_BINARY_DIR}/libwebsockets.pc" - DESTINATION lib${LIB_SUFFIX}/pkgconfig) - -file(WRITE "${PROJECT_BINARY_DIR}/libwebsockets_static.pc" -"prefix=\"${CMAKE_INSTALL_PREFIX}\" -exec_prefix=\${prefix} -libdir=\${exec_prefix}/lib${LIB_SUFFIX} -includedir=\${prefix}/include - -Name: libwebsockets_static -Description: Websockets server and client static library -Version: ${CPACK_PACKAGE_VERSION_MAJOR}.${CPACK_PACKAGE_VERSION_MINOR}.${CPACK_PACKAGE_VERSION_PATCH} - -Libs: -L\${libdir} -lwebsockets_static -Libs.private: -Cflags: -I\${includedir}" -) - - install(FILES "${PROJECT_BINARY_DIR}/libwebsockets_static.pc" - DESTINATION lib${LIB_SUFFIX}/pkgconfig) -endif(UNIX) - +# # # Installation preparations. # -if(WIN32 AND NOT CYGWIN) - set(DEF_INSTALL_CMAKE_DIR cmake) -else() - set(DEF_INSTALL_CMAKE_DIR lib${LIB_SUFFIX}/cmake/libwebsockets) -endif() - -set(LWS_INSTALL_CMAKE_DIR ${DEF_INSTALL_CMAKE_DIR} CACHE PATH "Installation directory for CMake files") - -# Export targets (This is used for other CMake projects to easily find the libraries and include files). -if (LWS_WITH_EXPORT_LWSTARGETS) - export(TARGETS ${LWS_LIBRARIES} - FILE "${PROJECT_BINARY_DIR}/LibwebsocketsTargets.cmake") -endif() - export(PACKAGE libwebsockets) -# Generate the config file for the build-tree. -set(LWS__INCLUDE_DIRS - "${PROJECT_SOURCE_DIR}/lib" - "${PROJECT_BINARY_DIR}") -set(LIBWEBSOCKETS_INCLUDE_DIRS ${LWS__INCLUDE_DIRS} CACHE PATH "Libwebsockets include directories") -configure_file(${PROJECT_SOURCE_DIR}/cmake/LibwebsocketsConfig.cmake.in - ${PROJECT_BINARY_DIR}/LibwebsocketsConfig.cmake - @ONLY) +install(DIRECTORY include/libwebsockets + DESTINATION "${LWS_INSTALL_INCLUDE_DIR}" COMPONENT dev) +install(FILES ${PROJECT_BINARY_DIR}/include/libwebsockets.h ${PROJECT_BINARY_DIR}/include/lws_config.h + DESTINATION "${LWS_INSTALL_INCLUDE_DIR}" COMPONENT dev) # Generate the config file for the installation tree. get_filename_component(LWS_ABSOLUTE_INSTALL_CMAKE_DIR ${LWS_INSTALL_CMAKE_DIR} ABSOLUTE) @@ -2495,139 +938,14 @@ "${LWS_ABSOLUTE_INSTALL_CMAKE_DIR}" "${LWS_ABSOLUTE_INSTALL_INCLUDE_DIR}") # Calculate the relative directory from the cmake dir. -# Note the EVENT_CMAKE_DIR is defined in JanssonConfig.cmake.in, -# we escape it here so it's evaluated when it is included instead -# so that the include dirs are given relative to where the -# config file is located. -set(LWS__INCLUDE_DIRS - "\${LWS_CMAKE_DIR}/${REL_INCLUDE_DIR}") -configure_file(${PROJECT_SOURCE_DIR}/cmake/LibwebsocketsConfig.cmake.in - ${PROJECT_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/LibwebsocketsConfig.cmake - @ONLY) - -# Generate version info for both build-tree and install-tree. -configure_file(${PROJECT_SOURCE_DIR}/cmake/LibwebsocketsConfigVersion.cmake.in - ${PROJECT_BINARY_DIR}/LibwebsocketsConfigVersion.cmake - @ONLY) - - set_target_properties(${LWS_LIBRARIES} - PROPERTIES PUBLIC_HEADER "${HDR_PUBLIC}") - -# -# Installation. -# - -install(DIRECTORY include/libwebsockets - DESTINATION "${LWS_INSTALL_INCLUDE_DIR}" COMPONENT dev_headers) - -# Install libs and headers. -install(TARGETS ${LWS_LIBRARIES} - EXPORT LibwebsocketsTargets - LIBRARY DESTINATION "${LWS_INSTALL_LIB_DIR}${LIB_SUFFIX}" COMPONENT libraries - ARCHIVE DESTINATION "${LWS_INSTALL_LIB_DIR}${LIB_SUFFIX}" COMPONENT libraries - RUNTIME DESTINATION "${LWS_INSTALL_BIN_DIR}" COMPONENT libraries # Windows DLLs - PUBLIC_HEADER DESTINATION "${LWS_INSTALL_INCLUDE_DIR}" COMPONENT dev) - -set(CPACK_COMPONENT_LIBRARIES_DISPLAY_NAME "Libraries") -set(CPACK_COMPONENT_DEV_DISPLAY_NAME "Development files") - -# Install test apps. -if (NOT LWS_WITHOUT_TESTAPPS) - install(TARGETS ${TEST_APP_LIST} - RUNTIME DESTINATION ${LWS_INSTALL_EXAMPLES_DIR} - COMPONENT examples) - set(CPACK_COMPONENT_EXAMPLES_DISPLAY_NAME "Example files") -endif() - -# lwsws -if (LWS_WITH_LWSWS) - install(TARGETS lwsws - RUNTIME DESTINATION "${LWS_INSTALL_BIN_DIR}" COMPONENT lwsws ) -endif() - -# Programs shared files used by the test-server. -if (NOT LWS_WITHOUT_TESTAPPS AND NOT LWS_WITHOUT_SERVER) - install(FILES ${TEST_SERVER_DATA} - DESTINATION share/libwebsockets-test-server - COMPONENT examples) - - install(FILES "${PROJECT_SOURCE_DIR}/test-apps/private/index.html" - DESTINATION share/libwebsockets-test-server/private - COMPONENT examples) -if (LWS_WITH_CGI) - set(CGI_TEST_SCRIPT "${PROJECT_SOURCE_DIR}/test-apps/lws-cgi-test.sh") - install(FILES ${CGI_TEST_SCRIPT} - PERMISSIONS OWNER_EXECUTE GROUP_EXECUTE WORLD_EXECUTE OWNER_READ GROUP_READ WORLD_READ - DESTINATION share/libwebsockets-test-server - COMPONENT examples) - endif() -endif() - - -if (NOT LWS_WITHOUT_TEST_SERVER AND NOT LWS_WITHOUT_SERVER AND NOT LWS_WITHOUT_TESTAPPS) - install(FILES test-apps/lws-ssh-test-keys;test-apps/lws-ssh-test-keys.pub - DESTINATION share/libwebsockets-test-server - COMPONENT examples) -endif() - -# plugins - -if (LWS_WITH_PLUGINS) - install(TARGETS ${PLUGINS_LIST} - PERMISSIONS OWNER_WRITE OWNER_EXECUTE GROUP_EXECUTE WORLD_EXECUTE OWNER_READ GROUP_READ WORLD_READ - DESTINATION share/libwebsockets-test-server/plugins - COMPONENT plugins) - - if (NOT WIN32) - install(FILES plugins/deaddrop/assets/index.html;plugins/deaddrop/assets/deaddrop.js;plugins/deaddrop/assets/deaddrop.css;plugins/deaddrop/assets/drop.svg - DESTINATION share/libwebsockets-test-server/deaddrop - COMPONENT plugins) - endif() - - -if (LWS_WITH_SERVER_STATUS) - install(FILES plugins/server-status.html;plugins/server-status.js;plugins/server-status.css;plugins/lwsws-logo.png - DESTINATION share/libwebsockets-test-server/server-status - COMPONENT examples) -endif() -if (LWS_WITH_GENERIC_SESSIONS) - install(FILES - plugins/generic-sessions/assets/lwsgs-logo.png - plugins/generic-sessions/assets/seats.jpg - plugins/generic-sessions/assets/failed-login.html - plugins/generic-sessions/assets/lwsgs.js - plugins/generic-sessions/assets/lwsgs.css - plugins/generic-sessions/assets/post-register-fail.html - plugins/generic-sessions/assets/post-register-ok.html - plugins/generic-sessions/assets/post-verify-ok.html - plugins/generic-sessions/assets/post-verify-fail.html - plugins/generic-sessions/assets/sent-forgot-ok.html - plugins/generic-sessions/assets/sent-forgot-fail.html - plugins/generic-sessions/assets/post-forgot-ok.html - plugins/generic-sessions/assets/post-forgot-fail.html - plugins/generic-sessions/assets/index.html - DESTINATION share/libwebsockets-test-server/generic-sessions - COMPONENT examples) - install(FILES plugins/generic-sessions/assets/successful-login.html - DESTINATION share/libwebsockets-test-server/generic-sessions/needauth - COMPONENT examples) - install(FILES plugins/generic-sessions/assets/admin-login.html - DESTINATION share/libwebsockets-test-server/generic-sessions/needadmin - COMPONENT examples) -endif() - - install(FILES - plugins/generic-table/assets/lwsgt.js - plugins/generic-table/assets/index.html - DESTINATION share/libwebsockets-test-server/generic-table - COMPONENT examples) - -endif() +set_target_properties(${LWS_LIBRARIES} + PROPERTIES PUBLIC_HEADER "${HDR_PUBLIC}") # Install the LibwebsocketsConfig.cmake and LibwebsocketsConfigVersion.cmake install(FILES - "${PROJECT_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/LibwebsocketsConfig.cmake" - "${PROJECT_BINARY_DIR}/LibwebsocketsConfigVersion.cmake" + "${PROJECT_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/libwebsockets-config.cmake" + "${PROJECT_BINARY_DIR}/libwebsockets-config-version.cmake" + "${PROJECT_SOURCE_DIR}/cmake/LwsCheckRequirements.cmake" DESTINATION "${LWS_INSTALL_CMAKE_DIR}" COMPONENT dev) # Install exports for the install-tree. @@ -2642,114 +960,7 @@ # Most people are more used to "make dist" compared to "make package_source" add_custom_target(dist COMMAND "${CMAKE_MAKE_PROGRAM}" package_source) -include(UseRPMTools) -if (RPMTools_FOUND) - RPMTools_ADD_RPM_TARGETS(libwebsockets scripts/libwebsockets.spec) -endif() - -message("---------------------------------------------------------------------") -message(" Settings: (For more help do cmake -LH )") -message("---------------------------------------------------------------------") -message(" LWS_WITH_STATIC = ${LWS_WITH_STATIC}") -message(" LWS_WITH_SHARED = ${LWS_WITH_SHARED}") -message(" LWS_WITH_SSL = ${LWS_WITH_SSL} (SSL Support)") -message(" LWS_SSL_CLIENT_USE_OS_CA_CERTS = ${LWS_SSL_CLIENT_USE_OS_CA_CERTS}") -message(" LWS_WITH_WOLFSSL = ${LWS_WITH_WOLFSSL} (wolfSSL/CyaSSL replacement for OpenSSL)") -if (LWS_WITH_WOLFSSL) - message(" LWS_WOLFSSL_LIBRARIES = ${LWS_WOLFSSL_LIBRARIES}") - message(" LWS_WOLFSSL_INCLUDE_DIRS = ${LWS_WOLFSSL_INCLUDE_DIRS}") -endif() -message(" LWS_WITH_MBEDTLS = ${LWS_WITH_MBEDTLS} (mbedTLS replacement for OpenSSL)") -message(" LWS_WITHOUT_BUILTIN_SHA1 = ${LWS_WITHOUT_BUILTIN_SHA1}") -message(" LWS_WITHOUT_BUILTIN_GETIFADDRS = ${LWS_WITHOUT_BUILTIN_GETIFADDRS}") -message(" LWS_WITHOUT_CLIENT = ${LWS_WITHOUT_CLIENT}") -message(" LWS_WITHOUT_SERVER = ${LWS_WITHOUT_SERVER}") -message(" LWS_LINK_TESTAPPS_DYNAMIC = ${LWS_LINK_TESTAPPS_DYNAMIC}") -message(" LWS_WITHOUT_TESTAPPS = ${LWS_WITHOUT_TESTAPPS}") -message(" LWS_WITHOUT_TEST_SERVER = ${LWS_WITHOUT_TEST_SERVER}") -message(" LWS_WITHOUT_TEST_SERVER_EXTPOLL = ${LWS_WITHOUT_TEST_SERVER_EXTPOLL}") -message(" LWS_WITHOUT_TEST_PING = ${LWS_WITHOUT_TEST_PING}") -message(" LWS_WITHOUT_TEST_CLIENT = ${LWS_WITHOUT_TEST_CLIENT}") -message(" LWS_WITHOUT_EXTENSIONS = ${LWS_WITHOUT_EXTENSIONS}") -message(" LWS_WITH_LATENCY = ${LWS_WITH_LATENCY}") -message(" LWS_WITHOUT_DAEMONIZE = ${LWS_WITHOUT_DAEMONIZE}") -message(" LWS_WITH_LIBEV = ${LWS_WITH_LIBEV}") -message(" LWS_WITH_LIBUV = ${LWS_WITH_LIBUV}") -message(" LWS_WITH_LIBEVENT = ${LWS_WITH_LIBEVENT}") -message(" LWS_IPV6 = ${LWS_IPV6}") -message(" LWS_UNIX_SOCK = ${LWS_UNIX_SOCK}") -message(" LWS_WITH_HTTP2 = ${LWS_WITH_HTTP2}") -message(" LWS_SSL_SERVER_WITH_ECDH_CERT = ${LWS_SSL_SERVER_WITH_ECDH_CERT}") -message(" LWS_MAX_SMP = ${LWS_MAX_SMP}") -message(" LWS_HAVE_PTHREAD_H = ${LWS_HAVE_PTHREAD_H}") -message(" LWS_WITH_CGI = ${LWS_WITH_CGI}") -message(" LWS_HAVE_OPENSSL_ECDH_H = ${LWS_HAVE_OPENSSL_ECDH_H}") -message(" LWS_HAVE_SSL_CTX_set1_param = ${LWS_HAVE_SSL_CTX_set1_param}") -message(" LWS_HAVE_RSA_SET0_KEY = ${LWS_HAVE_RSA_SET0_KEY}") -message(" LWS_WITH_HTTP_PROXY = ${LWS_WITH_HTTP_PROXY}") -message(" LIBHUBBUB_LIBRARIES = ${LIBHUBBUB_LIBRARIES}") -message(" PLUGINS = ${PLUGINS_LIST}") -message(" LWS_WITH_ACCESS_LOG = ${LWS_WITH_ACCESS_LOG}") -message(" LWS_WITH_SERVER_STATUS = ${LWS_WITH_SERVER_STATUS}") -message(" LWS_WITH_LEJP = ${LWS_WITH_LEJP}") -message(" LWS_WITH_LEJP_CONF = ${LWS_WITH_LEJP_CONF}") -message(" LWS_WITH_SMTP = ${LWS_WITH_SMTP}") -message(" LWS_WITH_GENERIC_SESSIONS = ${LWS_WITH_GENERIC_SESSIONS}") -message(" LWS_STATIC_PIC = ${LWS_STATIC_PIC}") -message(" LWS_WITH_RANGES = ${LWS_WITH_RANGES}") -message(" LWS_PLAT_OPTEE = ${LWS_PLAT_OPTEE}") -message(" LWS_WITH_ESP32 = ${LWS_WITH_ESP32}") -message(" LWS_WITH_ZIP_FOPS = ${LWS_WITH_ZIP_FOPS}") -message(" LWS_AVOID_SIGPIPE_IGN = ${LWS_AVOID_SIGPIPE_IGN}") -message(" LWS_WITH_STATS = ${LWS_WITH_STATS}") -message(" LWS_WITH_SOCKS5 = ${LWS_WITH_SOCKS5}") -message(" LWS_HAVE_SYS_CAPABILITY_H = ${LWS_HAVE_SYS_CAPABILITY_H}") -message(" LWS_HAVE_LIBCAP = ${LWS_HAVE_LIBCAP}") -message(" LWS_WITH_PEER_LIMITS = ${LWS_WITH_PEER_LIMITS}") -message(" LWS_HAVE_ATOLL = ${LWS_HAVE_ATOLL}") -message(" LWS_HAVE__ATOI64 = ${LWS_HAVE__ATOI64}") -message(" LWS_HAVE_STAT32I64 = ${LWS_HAVE_STAT32I64}") -message(" LWS_HAS_INTPTR_T = ${LWS_HAS_INTPTR_T}") -message(" LWS_WITH_EXPORT_LWSTARGETS = ${LWS_WITH_EXPORT_LWSTARGETS}") -message(" LWS_WITH_ABSTRACT = ${LWS_WITH_ABSTRACT}") - -message("---------------------------------------------------------------------") -# These will be available to parent projects including libwebsockets using add_subdirectory() -set(LIBWEBSOCKETS_LIBRARIES ${LWS_LIBRARIES} CACHE STRING "Libwebsocket libraries") -if (LWS_WITH_STATIC) - set(LIBWEBSOCKETS_LIBRARIES_STATIC websockets CACHE STRING "Libwebsocket static library") -endif() -if (LWS_WITH_SHARED) - set(LIBWEBSOCKETS_LIBRARIES_SHARED websockets_shared CACHE STRING "Libwebsocket shared library") -endif() - -if (LWS_WITH_MINIMAL_EXAMPLES) - MACRO(SUBDIRLIST result curdir) - FILE(GLOB children RELATIVE ${curdir} ${curdir}/*) - SET(dirlist "") - - FOREACH(child ${children}) - IF(IS_DIRECTORY ${curdir}/${child}) - LIST(APPEND dirlist ${child}) - ENDIF() - ENDFOREACH() - - SET(${result} ${dirlist}) - ENDMACRO() - - SUBDIRLIST(SUBDIRS "${PROJECT_SOURCE_DIR}/minimal-examples") - FOREACH(subdir ${SUBDIRS}) - - SUBDIRLIST(SUBDIRS2 "${PROJECT_SOURCE_DIR}/minimal-examples/${subdir}") - FOREACH(subdir2 ${SUBDIRS2}) - if (EXISTS "${PROJECT_SOURCE_DIR}/minimal-examples/${subdir}/${subdir2}/CMakeLists.txt") - message("Processing ${PROJECT_SOURCE_DIR}/minimal-examples/${subdir}/${subdir2}") - add_subdirectory("${PROJECT_SOURCE_DIR}/minimal-examples/${subdir}/${subdir2}") - endif() - ENDFOREACH() - ENDFOREACH() -ENDIF() # This must always be last! include(CPack) diff -Nru libwebsockets-3.2.1/contrib/android-make-script.sh libwebsockets-4.1.6/contrib/android-make-script.sh --- libwebsockets-3.2.1/contrib/android-make-script.sh 2019-12-18 14:45:31.000000000 +0000 +++ libwebsockets-4.1.6/contrib/android-make-script.sh 1970-01-01 00:00:00.000000000 +0000 @@ -1,116 +0,0 @@ -#!/bin/bash - -# -# Build libwebsockets static library for Android -# - -# path to NDK -export NDK=/opt/ndk_r17/android-ndk-r17-beta2-linux-x86_64/android-ndk-r17-beta2 -export ANDROID_NDK=${NDK} -export TOOLCHAIN=${NDK}/toolchain -export CORSS_SYSROOT=${NDK}/sysroot -export SYSROOT=${NDK}/platforms/android-22/arch-arm -set -e - -# Download packages libz, libuv, mbedtls and libwebsockets -#zlib-1.2.8 -#libuv-1.x -#mbedtls-2.11.0 -#libwebsockets-3.0.0 - - -# create a local android toolchain -API=${3:-24} - -$NDK/build/tools/make-standalone-toolchain.sh \ - --toolchain=arm-linux-androideabi-4.9 \ - --arch=arm \ - --install-dir=`pwd`/android-toolchain-arm \ - --platform=android-$API \ - --stl=libc++ \ - --force \ - --verbose - -# setup environment to use the gcc/ld from the android toolchain -export INSTALL_PATH=/opt/libwebsockets_android/android-toolchain-arm -export TOOLCHAIN_PATH=`pwd`/android-toolchain-arm -export TOOL=arm-linux-androideabi -export NDK_TOOLCHAIN_BASENAME=${TOOLCHAIN_PATH}/bin/${TOOL} -export PATH=`pwd`/android-toolchain-arm/bin:$PATH -export CC=$NDK_TOOLCHAIN_BASENAME-gcc -export CXX=$NDK_TOOLCHAIN_BASENAME-g++ -export LINK=${CXX} -export LD=$NDK_TOOLCHAIN_BASENAME-ld -export AR=$NDK_TOOLCHAIN_BASENAME-ar -export RANLIB=$NDK_TOOLCHAIN_BASENAME-ranlib -export STRIP=$NDK_TOOLCHAIN_BASENAME-strip -export PLATFORM=android -export CFLAGS="D__ANDROID_API__=$API" - -# configure and build libuv -[ ! -f ./android-toolchain-arm/lib/libuv.so ] && { -cd libuv -echo "=============================================>> build libuv" - -PATH=$TOOLCHAIN_PATH:$PATH make clean -PATH=$TOOLCHAIN_PATH:$PATH make -PATH=$TOOLCHAIN_PATH:$PATH make install -echo "<<============================================= build libuv" -cd .. -} - -# configure and build zlib -[ ! -f ./android-toolchain-arm/lib/libz.so ] && { -cd zlib-1.2.8 -echo "=============================================>> build libz" - -PATH=$TOOLCHAIN_PATH:$PATH make clean -PATH=$TOOLCHAIN_PATH:$PATH make -PATH=$TOOLCHAIN_PATH:$PATH make install -echo "<<============================================= build libz" -cd .. -} - -# configure and build mbedtls -[ ! -f ./android-toolchain-arm/lib/libmbedtls.so ] && { -echo "=============================================>> build mbedtls" -PREFIX=$TOOLCHAIN_PATH -cd mbedtls-2.11.0 -[ ! -d build ] && mkdir build -cd build -export CFLAGS="$CFLAGS -fomit-frame-pointer" - -PATH=$TOOLCHAIN_PATH:$PATH cmake .. -DCMAKE_TOOLCHAIN_FILE=`pwd`/../cross-arm-android-gnueabi.cmake \ - -DCMAKE_INSTALL_PREFIX:PATH=${INSTALL_PATH} \ - -DCMAKE_BUILD_TYPE=RELEASE -DUSE_SHARED_MBEDTLS_LIBRARY=On - -PATH=$TOOLCHAIN_PATH:$PATH make clean -PATH=$TOOLCHAIN_PATH:$PATH make SHARED=1 -PATH=$TOOLCHAIN_PATH:$PATH make install -echo "<<============================================= build mbedtls" -cd ../.. -} - -# configure and build libwebsockets -[ ! -f ./android-toolchain-arm/lib/libwebsockets.so ] && { -cd libwebsockets -[ ! -d build ] && mkdir build -cd build -echo "=============================================>> build libwebsockets" - -PATH=$TOOLCHAIN_PATH:$PATH cmake .. -DCMAKE_TOOLCHAIN_FILE=`pwd`/../cross-arm-android-gnueabi.cmake \ - -DCMAKE_INSTALL_PREFIX:PATH=${INSTALL_PATH} \ - -DLWS_WITH_LWSWS=1 \ - -DLWS_WITH_MBEDTLS=1 \ - -DLWS_WITHOUT_TESTAPPS=1 \ - -DLWS_MBEDTLS_LIBRARIES="${INSTALL_PATH}/lib/libmbedcrypto.a;${INSTALL_PATH}/lib/libmbedtls.a;${INSTALL_PATH}/lib/libmbedx509.a" \ - -DLWS_MBEDTLS_INCLUDE_DIRS=${INSTALL_PATH}/include \ - -DLWS_LIBUV_LIBRARIES=${INSTALL_PATH}/lib/libuv.so \ - -DLWS_LIBUV_INCLUDE_DIRS=${INSTALL_PATH}/include \ - -DLWS_ZLIB_LIBRARIES=${INSTALL_PATH}/lib/libz.so \ - -DLWS_ZLIB_INCLUDE_DIRS=${INSTALL_PATH}/include -PATH=$TOOLCHAIN_PATH:$PATH make -PATH=$TOOLCHAIN_PATH:$PATH make install -echo "<<============================================= build libwebsockets" -cd ../.. -} diff -Nru libwebsockets-3.2.1/contrib/cross-aarch64-android.cmake libwebsockets-4.1.6/contrib/cross-aarch64-android.cmake --- libwebsockets-3.2.1/contrib/cross-aarch64-android.cmake 1970-01-01 00:00:00.000000000 +0000 +++ libwebsockets-4.1.6/contrib/cross-aarch64-android.cmake 2020-12-01 17:40:26.000000000 +0000 @@ -0,0 +1,58 @@ +# +# CMake Toolchain file for crosscompiling Android / aarch64 +# +# This can be used when running cmake in the following way: +# cd build/ +# cmake .. -DCMAKE_TOOLCHAIN_FILE=contrib/cross-aarch64-android.cmake +# + + +set(ANDROID_API_VER 24) +set(ABARCH1 arm64) +set(CMAKE_SYSTEM_PROCESSOR aarch64) +set(NDK /opt/android/ndk/21.1.6352462/) +set(CROSS_SYSROOT "${NDK}/platforms/android-${ANDROID_API_VER}/arch-${ABARCH1}") +set(BUILD_ARCH linux-x86_64) + +# +# Rest should be computed from the above +# +set(TC_PATH ${NDK}/toolchains/llvm/prebuilt/${BUILD_ARCH}) +set(TC_BASE ${TC_PATH}/bin/${CMAKE_SYSTEM_PROCESSOR}-linux-android) +set(PLATFORM android) +set(CMAKE_SYSTEM_NAME Linux) +set(CMAKE_C_COMPILER "${TC_BASE}${ANDROID_API_VER}-clang") +set(CMAKE_CXX_COMPILER "${TC_BASE}${ANDROID_API_VER}-clang++") +set(CMAKE_STAGING_PREFIX "${CROSS_SYSROOT}") + +# +# Different build system distros set release optimization level to different +# things according to their local policy, eg, Fedora is -O2 and Ubuntu is -O3 +# here. Actually the build system's local policy is completely unrelated to +# our desire for cross-build release optimization policy for code built to run +# on a completely different target than the build system itself. +# +# Since this goes last on the compiler commandline we have to override it to a +# sane value for cross-build here. Notice some gcc versions enable broken +# optimizations with -O3. +# +if (CMAKE_BUILD_TYPE MATCHES RELEASE OR CMAKE_BUILD_TYPE MATCHES Release OR CMAKE_BUILD_TYPE MATCHES release) + set(CMAKE_C_FLAGS_RELEASE "${CMAKE_C_FLAGS_RELEASE} -O2") + set(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} -O2") +endif() + +#-nostdlib +SET(CMAKE_C_FLAGS "-DGCC_VER=\"\\\"$(GCC_VER)\\\"\" -DARM64=1 -D__LP64__=1 -Os -g3 -fpie -mstrict-align -fPIC -ffunction-sections -fdata-sections -D__ANDROID_API__=${ANDROID_API_VER} -Wno-pointer-sign" CACHE STRING "" FORCE) + + +set(CMAKE_FIND_ROOT_PATH "${CROSS_SYSROOT}") + +# Adjust the default behavior of the FIND_XXX() commands: +# search programs in the host environment only. +set(CMAKE_FIND_ROOT_PATH_MODE_PROGRAM NEVER) + +# Search headers and libraries in the target environment only. +set(CMAKE_FIND_ROOT_PATH_MODE_LIBRARY ONLY) +set(CMAKE_FIND_ROOT_PATH_MODE_INCLUDE ONLY) + + diff -Nru libwebsockets-3.2.1/contrib/cross-aarch64.cmake libwebsockets-4.1.6/contrib/cross-aarch64.cmake --- libwebsockets-3.2.1/contrib/cross-aarch64.cmake 2019-12-18 14:45:31.000000000 +0000 +++ libwebsockets-4.1.6/contrib/cross-aarch64.cmake 2020-12-01 17:40:26.000000000 +0000 @@ -26,8 +26,8 @@ # optimizations with -O3. # if (CMAKE_BUILD_TYPE MATCHES RELEASE OR CMAKE_BUILD_TYPE MATCHES Release OR CMAKE_BUILD_TYPE MATCHES release) - set(CMAKE_C_FLAGS_RELEASE ${CMAKE_C_FLAGS_RELEASE} -O2) - set(CMAKE_CXX_FLAGS_RELEASE ${CMAKE_CXX_FLAGS_RELEASE} -O2) + set(CMAKE_C_FLAGS_RELEASE "${CMAKE_C_FLAGS_RELEASE} -O2") + set(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} -O2") endif() #-nostdlib diff -Nru libwebsockets-3.2.1/contrib/cross-arm-android-gnueabi.cmake libwebsockets-4.1.6/contrib/cross-arm-android-gnueabi.cmake --- libwebsockets-3.2.1/contrib/cross-arm-android-gnueabi.cmake 2019-12-18 14:45:31.000000000 +0000 +++ libwebsockets-4.1.6/contrib/cross-arm-android-gnueabi.cmake 2020-12-01 17:40:26.000000000 +0000 @@ -30,8 +30,8 @@ # optimizations with -O3. # if (CMAKE_BUILD_TYPE MATCHES RELEASE OR CMAKE_BUILD_TYPE MATCHES Release OR CMAKE_BUILD_TYPE MATCHES release) - set(CMAKE_C_FLAGS_RELEASE ${CMAKE_C_FLAGS_RELEASE} -O2) - set(CMAKE_CXX_FLAGS_RELEASE ${CMAKE_CXX_FLAGS_RELEASE} -O2) + set(CMAKE_C_FLAGS_RELEASE "${CMAKE_C_FLAGS_RELEASE} -O2") + set(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} -O2") endif() # Where to look for the target environment. (More paths can be added here) diff -Nru libwebsockets-3.2.1/contrib/cross-arm-linux-gnueabihf.cmake libwebsockets-4.1.6/contrib/cross-arm-linux-gnueabihf.cmake --- libwebsockets-3.2.1/contrib/cross-arm-linux-gnueabihf.cmake 2019-12-18 14:45:31.000000000 +0000 +++ libwebsockets-4.1.6/contrib/cross-arm-linux-gnueabihf.cmake 2020-12-01 17:40:26.000000000 +0000 @@ -27,8 +27,8 @@ # optimizations with -O3. # if (CMAKE_BUILD_TYPE MATCHES RELEASE OR CMAKE_BUILD_TYPE MATCHES Release OR CMAKE_BUILD_TYPE MATCHES release) - set(CMAKE_C_FLAGS_RELEASE ${CMAKE_C_FLAGS_RELEASE} -O2) - set(CMAKE_CXX_FLAGS_RELEASE ${CMAKE_CXX_FLAGS_RELEASE} -O2) + set(CMAKE_C_FLAGS_RELEASE "${CMAKE_C_FLAGS_RELEASE} -O2") + set(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} -O2") endif() # Where to look for the target environment. (More paths can be added here) diff -Nru libwebsockets-3.2.1/contrib/cross-atmel.cmake libwebsockets-4.1.6/contrib/cross-atmel.cmake --- libwebsockets-3.2.1/contrib/cross-atmel.cmake 1970-01-01 00:00:00.000000000 +0000 +++ libwebsockets-4.1.6/contrib/cross-atmel.cmake 2020-12-01 17:40:26.000000000 +0000 @@ -0,0 +1,119 @@ +# +# CMake Toolchain file for crosscompiling on Atmel Arm products +# +# To build without tls +# +# cd build/ +# cmake .. -DCMAKE_INSTALL_PREFIX:PATH=/opt/atmel/cross-root \ +# -DCMAKE_TOOLCHAIN_FILE=../contrib/cross-atmel.cmake \ +# -DLWS_PLAT_FREERTOS=1 \ +# -DLWS_WITH_ZLIB=0 \ +# -DLWS_WITHOUT_EXTENSIONS=1 \ +# -DLWS_WITH_ZIP_FOPS=0 \ +# -DLWS_WITH_HTTP_STREAM_COMPRESSION=0 \ +# -DLWS_WITH_MBEDTLS=0 \ +# -DLWS_WITH_SSL=0 \ +# -DLWS_WITH_FILE_OPS=0 +# + +# I had to edit /opt/xdk-asf-3.48.0/thirdparty/lwip/lwip-port-1.4.1-dev/sam/include/arch/cc.h +# to comment out #define LWIP_PROVIDE_ERRNO + +# if your sdk lives somewhere else, this is the only place that should need changing + +set(CROSS_BASE /opt/arm-none-eabi) +set(SDK_BASE /opt/xdk-asf-3.48.0) +set(CROSS_PATH ${CROSS_BASE}/bin/arm-none-eabi) + +set(LWIP_VER 1.4.1-dev) +set(FREERTOS_VER 10.0.0) + +# +# Target operating system name. +set(CMAKE_SYSTEM_NAME Generic) + +# Name of C compiler. +set(CMAKE_C_COMPILER "${CROSS_PATH}-gcc") + +# +# cmake believes we should link a NOP test program OK, but since we're +# baremetal, that's not true in our case. It tries to build this test +# with the cross compiler, but with no args on it, and it fails. +# So disable this test for this toolchain (we'll find out soon enough +# if we actually can't compile anything) + +set(CMAKE_C_COMPILER_WORKS 1) +set(CMAKE_CXX_COMPILER_WORKS 1) + +# +# similarly we're building a .a like this, we can't actually build +# complete test programs to probe api availability... so force some +# key ones + +set(LWS_HAVE_mbedtls_ssl_conf_alpn_protocols 1) +set(LWS_HAVE_mbedtls_ssl_conf_alpn_protocols 1) +set(LWS_HAVE_mbedtls_ssl_get_alpn_protocol 1) +set(LWS_HAVE_mbedtls_ssl_conf_sni 1) +set(LWS_HAVE_mbedtls_ssl_set_hs_ca_chain 1) +set(LWS_HAVE_mbedtls_ssl_set_hs_own_cert 1) +set(LWS_HAVE_mbedtls_ssl_set_hs_authmode 1) +set(LWS_HAVE_mbedtls_net_init 1) +set(LWS_HAVE_mbedtls_md_setup 1) # not on xenial 2.2 +set(LWS_HAVE_mbedtls_rsa_complete 1) # not on xenial 2.2 +set(LWS_HAVE_mbedtls_internal_aes_encrypt 1) +# +# Different build system distros set release optimization level to different +# things according to their local policy, eg, Fedora is -O2 and Ubuntu is -O3 +# here. Actually the build system's local policy is completely unrelated to +# our desire for cross-build release optimization policy for code built to run +# on a completely different target than the build system itself. +# +# Since this goes last on the compiler commandline we have to override it to a +# sane value for cross-build here. Notice some gcc versions enable broken +# optimizations with -O3. +# +if (CMAKE_BUILD_TYPE MATCHES RELEASE OR CMAKE_BUILD_TYPE MATCHES Release OR CMAKE_BUILD_TYPE MATCHES release) + set(CMAKE_C_FLAGS_RELEASE "${CMAKE_C_FLAGS_RELEASE} -O2") + set(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} -O2") +endif() + +set(PLAT_ARCH ARM_CM4F) +set(PLAT_ARCH_CMSIS sam4e) +set(PLAT_SOC __SAM4E16E__) +set(PLAT_BOARD SAM4E_XPLAINED_PRO) + +set(CF_LWIP "${CF_LWIP} -I${SDK_BASE}/thirdparty/lwip/lwip-${LWIP_VER}/src/include/lwip") +set(CF_LWIP "${CF_LWIP} -I${SDK_BASE}/thirdparty/lwip/lwip-${LWIP_VER}/src/include/posix") +set(CF_LWIP "${CF_LWIP} -I${SDK_BASE}/thirdparty/lwip/lwip-${LWIP_VER}/src/include") +set(CF_LWIP "${CF_LWIP} -I${SDK_BASE}/thirdparty/lwip/lwip-${LWIP_VER}/src/module_config") +set(CF_LWIP "${CF_LWIP} -I${SDK_BASE}/thirdparty/lwip/lwip-port-${LWIP_VER}/sam/include") +set(CF_LWIP "${CF_LWIP} -I${SDK_BASE}/thirdparty/lwip/lwip-${LWIP_VER}/src/include/ipv4") + +set(CF_FREERTOS "${CF_FREERTOS} -I${SDK_BASE}/thirdparty/freertos/freertos-${FREERTOS_VER}/Source/include") +set(CF_FREERTOS "${CF_FREERTOS} -I${SDK_BASE}/thirdparty/freertos/freertos-${FREERTOS_VER}/module_config") +set(CF_FREERTOS "${CF_FREERTOS} -I${SDK_BASE}/thirdparty/freertos/freertos-${FREERTOS_VER}/Source/portable/GCC/${PLAT_ARCH}") + +set(CF_SDK_GLUE "${CF_SDK_GLUE} -I${SDK_BASE}/common/boards") +set(CF_SDK_GLUE "${CF_SDK_GLUE} -I${SDK_BASE}/common/utils") +set(CF_SDK_GLUE "${CF_SDK_GLUE} -I${SDK_BASE}/sam/utils/") +set(CF_SDK_GLUE "${CF_SDK_GLUE} -I${SDK_BASE}/sam/utils/preprocessor") +set(CF_SDK_GLUE "${CF_SDK_GLUE} -I${SDK_BASE}/sam/utils/header_files") +set(CF_SDK_GLUE "${CF_SDK_GLUE} -I${SDK_BASE}/sam/boards") +set(CF_SDK_GLUE "${CF_SDK_GLUE} -I${SDK_BASE}/sam/utils/cmsis/${PLAT_ARCH_CMSIS}/source/templates") +set(CF_SDK_GLUE "${CF_SDK_GLUE} -I${SDK_BASE}/sam/utils/cmsis/${PLAT_ARCH_CMSIS}/include") +set(CF_SDK_GLUE "${CF_SDK_GLUE} -I${SDK_BASE}/thirdparty/CMSIS/Include") +set(CF_SDK_GLUE "${CF_SDK_GLUE} -I${SDK_BASE}/common/utils/osprintf") + +set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -lnosys -nostartfiles ${CF_LWIP} ${CF_FREERTOS} ${CF_SDK_GLUE} -DBOARD=${PLAT_BOARD} -D${PLAT_SOC} -DLWIP_TIMEVAL_PRIVATE=0 -DLWS_AMAZON_RTOS=1 -DLWIP_SOCKET_OFFSET=0 -DLWIP_COMPAT_SOCKETS -DLWIP_DNS=1 -DLWIP_SOCKETS=1 " CACHE STRING "" FORCE) + +# Where to look for the target environment. (More paths can be added here) +set(CMAKE_FIND_ROOT_PATH "${CROSS_PATH}") + +# Adjust the default behavior of the FIND_XXX() commands: +# search programs in the host environment only. +set(CMAKE_FIND_ROOT_PATH_MODE_PROGRAM NEVER) + +# Search headers and libraries in the target environment only. +set(CMAKE_FIND_ROOT_PATH_MODE_LIBRARY ONLY) +set(CMAKE_FIND_ROOT_PATH_MODE_INCLUDE ONLY) + diff -Nru libwebsockets-3.2.1/contrib/cross-esp32.cmake libwebsockets-4.1.6/contrib/cross-esp32.cmake --- libwebsockets-3.2.1/contrib/cross-esp32.cmake 2019-12-18 14:45:31.000000000 +0000 +++ libwebsockets-4.1.6/contrib/cross-esp32.cmake 2020-12-01 17:40:26.000000000 +0000 @@ -9,11 +9,13 @@ # Target operating system name. set(CMAKE_SYSTEM_NAME Linux) -# Name of C compiler. -set(CMAKE_C_COMPILER "${CROSS_PATH}/bin/xtensa-esp32-elf-gcc${EXECUTABLE_EXT}") -set(CMAKE_AR "${CROSS_PATH}/bin/xtensa-esp32-elf-ar${EXECUTABLE_EXT}") -set(CMAKE_RANLIB "${CROSS_PATH}/bin/xtensa-esp32-elf-ranlib${EXECUTABLE_EXT}") -set(CMAKE_LINKER "${CROSS_PATH}/bin/xtensa-esp32-elf-ld${EXECUTABLE_EXT}") +# assumed these are set up on the $PATH +set(TC xtensa-esp32-elf) + +set(CMAKE_C_COMPILER "${TC}-gcc${EXECUTABLE_EXT}") +set(CMAKE_AR "${TC}-ar${EXECUTABLE_EXT}") +set(CMAKE_RANLIB "${TC}-ranlib${EXECUTABLE_EXT}") +set(CMAKE_LINKER "${TC}-ld${EXECUTABLE_EXT}") # # Different build system distros set release optimization level to different @@ -27,8 +29,8 @@ # optimizations with -O3. # if (CMAKE_BUILD_TYPE MATCHES RELEASE OR CMAKE_BUILD_TYPE MATCHES Release OR CMAKE_BUILD_TYPE MATCHES release) - set(CMAKE_C_FLAGS_RELEASE ${CMAKE_C_FLAGS_RELEASE} -O2) - set(CMAKE_CXX_FLAGS_RELEASE ${CMAKE_CXX_FLAGS_RELEASE} -O2) + set(CMAKE_C_FLAGS_RELEASE "${CMAKE_C_FLAGS_RELEASE} -O2") + set(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} -O2") endif() SET(CMAKE_C_FLAGS "-nostdlib -Wall -Werror \ diff -Nru libwebsockets-3.2.1/contrib/cross-linkit.cmake libwebsockets-4.1.6/contrib/cross-linkit.cmake --- libwebsockets-3.2.1/contrib/cross-linkit.cmake 1970-01-01 00:00:00.000000000 +0000 +++ libwebsockets-4.1.6/contrib/cross-linkit.cmake 2020-12-01 17:40:26.000000000 +0000 @@ -0,0 +1,84 @@ +# +# CMake Toolchain file for crosscompiling on Mediatek Linkit 7967 +# +# This can be used like this (with Linkit sdk unpacked to /opt/linkit) +# +# cd build/ +# cmake .. -DCMAKE_INSTALL_PREFIX:PATH=/opt/linkit/cross-root \ +# -DCMAKE_TOOLCHAIN_FILE=../contrib/cross-linkit.cmake \ +# -DLWS_PLAT_FREERTOS=1 \ +# -DLWS_WITH_ZLIB=0 \ +# -DLWS_WITHOUT_EXTENSIONS=1 \ +# -DLWS_WITH_ZIP_FOPS=0 \ +# -DLWS_WITH_HTTP_STREAM_COMPRESSION=0 \ +# -DLWS_WITH_MBEDTLS=1 \ +# -DLWS_WITH_FILE_OPS=0 +# + +# if your sdk lives somewhere else, this is the only place that should need changing +set(CROSS_BASE /opt/linkit/sdk) +set(CROSS_PATH ${CROSS_BASE}/tools/gcc/gcc-arm-none-eabi) + +# +# Target operating system name. +set(CMAKE_SYSTEM_NAME Generic) + +# Name of C compiler. +set(CMAKE_C_COMPILER "${CROSS_PATH}/bin/arm-none-eabi-gcc") +set(CMAKE_CXX_COMPILER "${CROSS_PATH}/bin/arm-none-eabi-g++") + +# +# cmake believes we should link a NOP test program OK, but since we're +# baremetal, that's not true in our case. It tries to build this test +# with the cross compiler, but with no args on it, and it fails. +# So disable this test for this toolchain (we'll find out soon enough +# if we actually can't compile anything) + +set(CMAKE_C_COMPILER_WORKS 1) +set(CMAKE_CXX_COMPILER_WORKS 1) + +# +# similarly we're building a .a like this, we can't actually build +# complete test programs to probe api availability... so force some +# key ones + +set(LWS_HAVE_mbedtls_ssl_conf_alpn_protocols 1) +set(LWS_HAVE_mbedtls_ssl_conf_alpn_protocols 1) +set(LWS_HAVE_mbedtls_ssl_get_alpn_protocol 1) +set(LWS_HAVE_mbedtls_ssl_conf_sni 1) +set(LWS_HAVE_mbedtls_ssl_set_hs_ca_chain 1) +set(LWS_HAVE_mbedtls_ssl_set_hs_own_cert 1) +set(LWS_HAVE_mbedtls_ssl_set_hs_authmode 1) +set(LWS_HAVE_mbedtls_net_init 1) +set(LWS_HAVE_mbedtls_md_setup 1) # not on xenial 2.2 +set(LWS_HAVE_mbedtls_rsa_complete 1) # not on xenial 2.2 +set(LWS_HAVE_mbedtls_internal_aes_encrypt 1) +# +# Different build system distros set release optimization level to different +# things according to their local policy, eg, Fedora is -O2 and Ubuntu is -O3 +# here. Actually the build system's local policy is completely unrelated to +# our desire for cross-build release optimization policy for code built to run +# on a completely different target than the build system itself. +# +# Since this goes last on the compiler commandline we have to override it to a +# sane value for cross-build here. Notice some gcc versions enable broken +# optimizations with -O3. +# +if (CMAKE_BUILD_TYPE MATCHES RELEASE OR CMAKE_BUILD_TYPE MATCHES Release OR CMAKE_BUILD_TYPE MATCHES release) + set(CMAKE_C_FLAGS_RELEASE "${CMAKE_C_FLAGS_RELEASE} -O2") + set(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} -O2") +endif() + +set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -lnosys -nostartfiles -I${CROSS_BASE}/middleware/third_party/lwip/src/include/lwip -I${CROSS_BASE}/middleware/third_party/lwip/src/include -I${CROSS_BASE}/project/mt7687_hdk/apps/httpd/inc/ -I${CROSS_BASE}/kernel/service/inc/ -I${CROSS_BASE}/driver/chip/inc -I${CROSS_BASE}/driver/chip/mt7687/inc/ -I${CROSS_BASE}/driver/CMSIS/Device/MTK/mt7687/Include/ -I${CROSS_BASE}/driver/CMSIS/Include -I${CROSS_BASE}/middleware/third_party/lwip/ports/include/ -I${CROSS_BASE}/middleware/third_party/lwip/src/include/posix/ -I${CROSS_BASE}/kernel/rtos/FreeRTOS/Source/include/ -I${CROSS_BASE}/middleware/third_party/mbedtls/include/ -I${CROSS_BASE}/kernel/rtos/FreeRTOS/Source/portable/GCC/ARM_CM4F/ -I${CROSS_BASE}/middleware/third_party/sntp/inc/ -DLWS_AMAZON_RTOS=1" CACHE STRING "" FORCE) + +# Where to look for the target environment. (More paths can be added here) +set(CMAKE_FIND_ROOT_PATH "${CROSS_PATH}") + +# Adjust the default behavior of the FIND_XXX() commands: +# search programs in the host environment only. +set(CMAKE_FIND_ROOT_PATH_MODE_PROGRAM NEVER) + +# Search headers and libraries in the target environment only. +set(CMAKE_FIND_ROOT_PATH_MODE_LIBRARY ONLY) +set(CMAKE_FIND_ROOT_PATH_MODE_INCLUDE ONLY) + diff -Nru libwebsockets-3.2.1/contrib/cross-ming.cmake libwebsockets-4.1.6/contrib/cross-ming.cmake --- libwebsockets-3.2.1/contrib/cross-ming.cmake 2019-12-18 14:45:31.000000000 +0000 +++ libwebsockets-4.1.6/contrib/cross-ming.cmake 2020-12-01 17:40:26.000000000 +0000 @@ -30,8 +30,8 @@ # optimizations with -O3. # if (CMAKE_BUILD_TYPE MATCHES RELEASE OR CMAKE_BUILD_TYPE MATCHES Release OR CMAKE_BUILD_TYPE MATCHES release) - set(CMAKE_C_FLAGS_RELEASE ${CMAKE_C_FLAGS_RELEASE} -O2) - set(CMAKE_CXX_FLAGS_RELEASE ${CMAKE_CXX_FLAGS_RELEASE} -O2) + set(CMAKE_C_FLAGS_RELEASE "${CMAKE_C_FLAGS_RELEASE} -O2") + set(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} -O2") endif() # Where to look for the target environment. (More paths can be added here) diff -Nru libwebsockets-3.2.1/contrib/cross-w32.cmake libwebsockets-4.1.6/contrib/cross-w32.cmake --- libwebsockets-3.2.1/contrib/cross-w32.cmake 2019-12-18 14:45:31.000000000 +0000 +++ libwebsockets-4.1.6/contrib/cross-w32.cmake 2020-12-01 17:40:26.000000000 +0000 @@ -6,7 +6,11 @@ # cmake .. -DCMAKE_TOOLCHAIN_FILE=../contrib/cross-w32.cmake -DLWS_WITH_SSL=0 # -set(CROSS_PATH /opt/mingw32) +# the outermost path to your cross toolchain +#set(CROSS_PATH /opt/mingw32) +set(CROSS_PATH /usr) +# your cross root +set(CROSS_ROOT ${CROSS_PATH}/i686-w64-mingw32/sys-root/) # Target operating system name. set(CMAKE_SYSTEM_NAME Windows) @@ -15,7 +19,6 @@ set(CMAKE_C_COMPILER "${CROSS_PATH}/bin/i686-w64-mingw32-gcc") set(CMAKE_CXX_COMPILER "${CROSS_PATH}/bin/i686-w64-mingw32-g++") set(CMAKE_RC_COMPILER "${CROSS_PATH}/bin/i686-w64-mingw32-windres") -set(CMAKE_C_FLAGS "-Wno-error") # # Different build system distros set release optimization level to different @@ -29,12 +32,13 @@ # optimizations with -O3. # if (CMAKE_BUILD_TYPE MATCHES RELEASE OR CMAKE_BUILD_TYPE MATCHES Release OR CMAKE_BUILD_TYPE MATCHES release) - set(CMAKE_C_FLAGS_RELEASE ${CMAKE_C_FLAGS_RELEASE} -O2) - set(CMAKE_CXX_FLAGS_RELEASE ${CMAKE_CXX_FLAGS_RELEASE} -O2) + set(CMAKE_C_FLAGS_RELEASE "${CMAKE_C_FLAGS_RELEASE} -O2") + set(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} -O2") endif() # Where to look for the target environment. (More paths can be added here) -set(CMAKE_FIND_ROOT_PATH "${CROSS_PATH}") +set(CMAKE_FIND_ROOT_PATH "${CROSS_ROOT}/mingw") +set(CMAKE_SYSROOT ${CROSS_ROOT}) # Adjust the default behavior of the FIND_XXX() commands: # search programs in the host environment only. diff -Nru libwebsockets-3.2.1/contrib/cross-w64.cmake libwebsockets-4.1.6/contrib/cross-w64.cmake --- libwebsockets-3.2.1/contrib/cross-w64.cmake 2019-12-18 14:45:31.000000000 +0000 +++ libwebsockets-4.1.6/contrib/cross-w64.cmake 2020-12-01 17:40:26.000000000 +0000 @@ -3,13 +3,18 @@ # # This can be used when running cmake in the following way: # cd build/ -# cmake .. -DCMAKE_TOOLCHAIN_FILE=../contrib/cross-w64.cmake -DLWS_WITH_SSL=0 +# cmake .. -DCMAKE_TOOLCHAIN_FILE=../contrib/cross-w64.cmake # -set(CROSS_PATH /opt/mingw64) +# the outermost path to your cross toolchain +#set(CROSS_PATH /opt/mingw64) +set(CROSS_PATH /usr) +# your cross root +set(CROSS_ROOT ${CROSS_PATH}/x86_64-w64-mingw32/sys-root/) # Target operating system name. set(CMAKE_SYSTEM_NAME Windows) +set(CMAKE_SYSROOT ${CROSS_ROOT}) # Name of C compiler. set(CMAKE_C_COMPILER "${CROSS_PATH}/bin/x86_64-w64-mingw32-gcc") @@ -29,12 +34,12 @@ # optimizations with -O3. # if (CMAKE_BUILD_TYPE MATCHES RELEASE OR CMAKE_BUILD_TYPE MATCHES Release OR CMAKE_BUILD_TYPE MATCHES release) - set(CMAKE_C_FLAGS_RELEASE ${CMAKE_C_FLAGS_RELEASE} -O2) - set(CMAKE_CXX_FLAGS_RELEASE ${CMAKE_CXX_FLAGS_RELEASE} -O2) + set(CMAKE_C_FLAGS_RELEASE "${CMAKE_C_FLAGS_RELEASE} -O2") + set(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} -O2") endif() # Where to look for the target environment. (More paths can be added here) -set(CMAKE_FIND_ROOT_PATH "${CROSS_PATH}") +set(CMAKE_FIND_ROOT_PATH "${CROSS_ROOT}/mingw") # Adjust the default behavior of the FIND_XXX() commands: # search programs in the host environment only. diff -Nru libwebsockets-3.2.1/contrib/iOS.cmake libwebsockets-4.1.6/contrib/iOS.cmake --- libwebsockets-3.2.1/contrib/iOS.cmake 1970-01-01 00:00:00.000000000 +0000 +++ libwebsockets-4.1.6/contrib/iOS.cmake 2020-12-01 17:40:26.000000000 +0000 @@ -0,0 +1,229 @@ +# This file is based off of the Platform/Darwin.cmake and Platform/UnixPaths.cmake +# files which are included with CMake 2.8.4 +# It has been altered for iOS development + +# Options: +# +# IOS_PLATFORM = OS (default) or OS32 or SIMULATOR or SIMULATOR64 +# This decides if SDKS will be selected from the iPhoneOS.platform or iPhoneSimulator.platform folders +# OS - the default, used to build for iPhone and iPad physical devices, which have an arm arch. +# SIMULATOR - used to build for the Simulator platforms, which have an x86 arch. +# +# CMAKE_IOS_DEVELOPER_ROOT = automatic(default) or /path/to/platform/Developer folder +# By default this location is automatcially chosen based on the IOS_PLATFORM value above. +# If set manually, it will override the default location and force the user of a particular Developer Platform +# +# CMAKE_IOS_SDK_ROOT = automatic(default) or /path/to/platform/Developer/SDKs/SDK folder +# By default this location is automatcially chosen based on the CMAKE_IOS_DEVELOPER_ROOT value. +# In this case it will always be the most up-to-date SDK found in the CMAKE_IOS_DEVELOPER_ROOT path. +# If set manually, this will force the use of a specific SDK version +# +# IOS_BITCODE = 1/0: Enable bitcode or not. Only iOS >= 6.0 device build can enable bitcode. Default is enabled. + +# Macros: +# +# set_xcode_property (TARGET XCODE_PROPERTY XCODE_VALUE) +# A convenience macro for setting xcode specific properties on targets +# example: set_xcode_property (myioslib IPHONEOS_DEPLOYMENT_TARGET "3.1") +# +# find_host_package (PROGRAM ARGS) +# A macro used to find executable programs on the host system, not within the iOS environment. +# Thanks to the android-cmake project for providing the command + +# Standard settings +set (CMAKE_SYSTEM_NAME Darwin) +set (CMAKE_SYSTEM_VERSION 1) +set(CMAKE_CROSSCOMPILING TRUE) +set (UNIX TRUE) +set (APPLE TRUE) +set (IOS TRUE) + +if(NOT DEFINED IOS_BITCODE) # check xcode/clang version? since xcode 7 + set(IOS_BITCODE 1) +endif() +set(IOS_BITCODE_MARKER 0) + +# Required as of cmake 2.8.10 +set (CMAKE_OSX_DEPLOYMENT_TARGET "" CACHE STRING "Force unset of the deployment target for iOS" FORCE) + +# Determine the cmake host system version so we know where to find the iOS SDKs +find_program (CMAKE_UNAME uname /bin /usr/bin /usr/local/bin) +if (CMAKE_UNAME) + exec_program(uname ARGS -r OUTPUT_VARIABLE CMAKE_HOST_SYSTEM_VERSION) + string (REGEX REPLACE "^([0-9]+)\\.([0-9]+).*$" "\\1" DARWIN_MAJOR_VERSION "${CMAKE_HOST_SYSTEM_VERSION}") +endif (CMAKE_UNAME) + +# Force the compilers to gcc for iOS +include (CMakeForceCompiler) +set (CMAKE_C_COMPILER /usr/bin/clang) +set (CMAKE_CXX_COMPILER /usr/bin/clang++) +set(CMAKE_AR ar CACHE FILEPATH "" FORCE) + +# Skip the platform compiler checks for cross compiling +set (CMAKE_CXX_COMPILER_WORKS TRUE) +set (CMAKE_C_COMPILER_WORKS TRUE) + +# All iOS/Darwin specific settings - some may be redundant +set (CMAKE_SHARED_LIBRARY_PREFIX "lib") +set (CMAKE_SHARED_LIBRARY_SUFFIX ".dylib") +set (CMAKE_SHARED_MODULE_PREFIX "lib") +set (CMAKE_SHARED_MODULE_SUFFIX ".so") +set (CMAKE_MODULE_EXISTS 1) +set (CMAKE_DL_LIBS "") + +if(IOS_BITCODE) + set(BITCODE_FLAGS "-fembed-bitcode") + elseif(IOS_BITCODE_MARKER) + set(BITCODE_FLAGS "-fembed-bitcode-marker") + endif() + +set (CMAKE_C_OSX_COMPATIBILITY_VERSION_FLAG "-compatibility_version ") +set (CMAKE_C_OSX_CURRENT_VERSION_FLAG "-current_version ") +set (CMAKE_CXX_OSX_COMPATIBILITY_VERSION_FLAG "${CMAKE_C_OSX_COMPATIBILITY_VERSION_FLAG}") +set (CMAKE_CXX_OSX_CURRENT_VERSION_FLAG "${CMAKE_C_OSX_CURRENT_VERSION_FLAG}") + +# Hidden visibilty is required for cxx on iOS +set (CMAKE_C_FLAGS_INIT "${BITCODE_FLAGS}") +set (CMAKE_CXX_FLAGS_INIT "-fvisibility=hidden -fvisibility-inlines-hidden ${BITCODE_FLAGS}") + +set (CMAKE_C_LINK_FLAGS "-Wl,-search_paths_first ${CMAKE_C_LINK_FLAGS}") +set (CMAKE_CXX_LINK_FLAGS "-Wl,-search_paths_first ${CMAKE_CXX_LINK_FLAGS}") + +set (CMAKE_PLATFORM_HAS_INSTALLNAME 1) +set (CMAKE_SHARED_LIBRARY_CREATE_C_FLAGS "-dynamiclib -headerpad_max_install_names") +set (CMAKE_SHARED_MODULE_CREATE_C_FLAGS "-bundle -headerpad_max_install_names") +set (CMAKE_SHARED_MODULE_LOADER_C_FLAG "-Wl,-bundle_loader,") +set (CMAKE_SHARED_MODULE_LOADER_CXX_FLAG "-Wl,-bundle_loader,") +set (CMAKE_FIND_LIBRARY_SUFFIXES ".dylib" ".so" ".a") + +# hack: if a new cmake (which uses CMAKE_INSTALL_NAME_TOOL) runs on an old build tree +# (where install_name_tool was hardcoded) and where CMAKE_INSTALL_NAME_TOOL isn't in the cache +# and still cmake didn't fail in CMakeFindBinUtils.cmake (because it isn't rerun) +# hardcode CMAKE_INSTALL_NAME_TOOL here to install_name_tool, so it behaves as it did before, Alex +if (NOT DEFINED CMAKE_INSTALL_NAME_TOOL) + find_program(CMAKE_INSTALL_NAME_TOOL install_name_tool) +endif () + +# Setup iOS platform unless specified manually with IOS_PLATFORM +if (NOT DEFINED IOS_PLATFORM) + set (IOS_PLATFORM "OS") +endif () +set (IOS_PLATFORM ${IOS_PLATFORM} CACHE STRING "Type of iOS Platform") + +# Setup building for arm64 or not +if (NOT DEFINED BUILD_ARM64) + set (BUILD_ARM64 true) +endif () +set (BUILD_ARM64 ${BUILD_ARM64} CACHE STRING "Build arm64 arch or not") + +# Check the platform selection and setup for developer root +if (${IOS_PLATFORM} STREQUAL "OS") + set (IOS_PLATFORM_LOCATION "iPhoneOS.platform") + + # This causes the installers to properly locate the output libraries + set (CMAKE_XCODE_EFFECTIVE_PLATFORMS "-iphoneos") +elseif (${IOS_PLATFORM} STREQUAL "OS32") + set (IOS_PLATFORM_LOCATION "iPhoneOS.platform") + + # This causes the installers to properly locate the output libraries + set (CMAKE_XCODE_EFFECTIVE_PLATFORMS "-iphoneos") +elseif (${IOS_PLATFORM} STREQUAL "SIMULATOR") + set (IS_SIMULATOR true) + set (IOS_PLATFORM_LOCATION "iPhoneSimulator.platform") + + # This causes the installers to properly locate the output libraries + set (CMAKE_XCODE_EFFECTIVE_PLATFORMS "-iphonesimulator") +elseif (${IOS_PLATFORM} STREQUAL "SIMULATOR64") + set (IS_SIMULATOR true) + set (IOS_PLATFORM_LOCATION "iPhoneSimulator.platform") + + # This causes the installers to properly locate the output libraries + set (CMAKE_XCODE_EFFECTIVE_PLATFORMS "-iphonesimulator") +else () + message (FATAL_ERROR "Unsupported IOS_PLATFORM value selected. Please choose OS or SIMULATOR") +endif () + +# Setup iOS developer location unless specified manually with CMAKE_IOS_DEVELOPER_ROOT +# Note Xcode 4.3 changed the installation location, choose the most recent one available +exec_program(/usr/bin/xcode-select ARGS -print-path OUTPUT_VARIABLE CMAKE_XCODE_DEVELOPER_DIR) +set (XCODE_POST_43_ROOT "${CMAKE_XCODE_DEVELOPER_DIR}/Platforms/${IOS_PLATFORM_LOCATION}/Developer") +set (XCODE_PRE_43_ROOT "/Developer/Platforms/${IOS_PLATFORM_LOCATION}/Developer") +if (NOT DEFINED CMAKE_IOS_DEVELOPER_ROOT) + if (EXISTS ${XCODE_POST_43_ROOT}) + set (CMAKE_IOS_DEVELOPER_ROOT ${XCODE_POST_43_ROOT}) + elseif(EXISTS ${XCODE_PRE_43_ROOT}) + set (CMAKE_IOS_DEVELOPER_ROOT ${XCODE_PRE_43_ROOT}) + endif (EXISTS ${XCODE_POST_43_ROOT}) +endif () +set (CMAKE_IOS_DEVELOPER_ROOT ${CMAKE_IOS_DEVELOPER_ROOT} CACHE PATH "Location of iOS Platform") + +# Find and use the most recent iOS sdk unless specified manually with CMAKE_IOS_SDK_ROOT +if (NOT DEFINED CMAKE_IOS_SDK_ROOT) + file (GLOB _CMAKE_IOS_SDKS "${CMAKE_IOS_DEVELOPER_ROOT}/SDKs/*") + if (_CMAKE_IOS_SDKS) + list (SORT _CMAKE_IOS_SDKS) + list (REVERSE _CMAKE_IOS_SDKS) + list (GET _CMAKE_IOS_SDKS 0 CMAKE_IOS_SDK_ROOT) + else (_CMAKE_IOS_SDKS) + message (FATAL_ERROR "No iOS SDK's found in default search path ${CMAKE_IOS_DEVELOPER_ROOT}. Manually set CMAKE_IOS_SDK_ROOT or install the iOS SDK.") + endif (_CMAKE_IOS_SDKS) + message (STATUS "Toolchain using default iOS SDK: ${CMAKE_IOS_SDK_ROOT}") +endif () +set (CMAKE_IOS_SDK_ROOT ${CMAKE_IOS_SDK_ROOT} CACHE PATH "Location of the selected iOS SDK") + +# Set the sysroot default to the most recent SDK +set (CMAKE_OSX_SYSROOT ${CMAKE_IOS_SDK_ROOT} CACHE PATH "Sysroot used for iOS support") + +# set the architecture for iOS +if (${IOS_PLATFORM} STREQUAL "OS") + set (IOS_ARCH arm64) +elseif (${IOS_PLATFORM} STREQUAL "OS32") + set (IOS_ARCH armv7) +elseif (${IOS_PLATFORM} STREQUAL "SIMULATOR") + set (IOS_ARCH i386) +elseif (${IOS_PLATFORM} STREQUAL "SIMULATOR64") + set (IOS_ARCH x86_64) +endif () + +set (CMAKE_OSX_ARCHITECTURES ${IOS_ARCH} CACHE STRING "Build architecture for iOS") + +# Set the find root to the iOS developer roots and to user defined paths +set (CMAKE_FIND_ROOT_PATH ${CMAKE_IOS_DEVELOPER_ROOT} ${CMAKE_IOS_SDK_ROOT} ${CMAKE_PREFIX_PATH} CACHE STRING "iOS find search path root") + +# default to searching for frameworks first +set (CMAKE_FIND_FRAMEWORK FIRST) + +# set up the default search directories for frameworks +set (CMAKE_SYSTEM_FRAMEWORK_PATH + ${CMAKE_IOS_SDK_ROOT}/System/Library/Frameworks + ${CMAKE_IOS_SDK_ROOT}/System/Library/PrivateFrameworks + ${CMAKE_IOS_SDK_ROOT}/Developer/Library/Frameworks +) + +# only search the iOS sdks, not the remainder of the host filesystem +set (CMAKE_FIND_ROOT_PATH_MODE_PROGRAM ONLY) +set (CMAKE_FIND_ROOT_PATH_MODE_LIBRARY ONLY) +set (CMAKE_FIND_ROOT_PATH_MODE_INCLUDE ONLY) + + +# This little macro lets you set any XCode specific property +macro (set_xcode_property TARGET XCODE_PROPERTY XCODE_VALUE) + set_property (TARGET ${TARGET} PROPERTY XCODE_ATTRIBUTE_${XCODE_PROPERTY} ${XCODE_VALUE}) +endmacro (set_xcode_property) + + +# This macro lets you find executable programs on the host system +macro (find_host_package) + set (CMAKE_FIND_ROOT_PATH_MODE_PROGRAM NEVER) + set (CMAKE_FIND_ROOT_PATH_MODE_LIBRARY NEVER) + set (CMAKE_FIND_ROOT_PATH_MODE_INCLUDE NEVER) + set (IOS FALSE) + + find_package(${ARGN}) + + set (IOS TRUE) + set (CMAKE_FIND_ROOT_PATH_MODE_PROGRAM ONLY) + set (CMAKE_FIND_ROOT_PATH_MODE_LIBRARY ONLY) + set (CMAKE_FIND_ROOT_PATH_MODE_INCLUDE ONLY) +endmacro (find_host_package) + diff -Nru libwebsockets-3.2.1/debian/changelog libwebsockets-4.1.6/debian/changelog --- libwebsockets-3.2.1/debian/changelog 2019-12-28 10:13:56.000000000 +0000 +++ libwebsockets-4.1.6/debian/changelog 2023-07-24 12:56:09.000000000 +0000 @@ -1,3 +1,123 @@ +libwebsockets (4.1.6-3.1~bpo20.04.1~ppa1) focal; urgency=medium + + * No-change backport to focal. + + -- Gianfranco Costamagna Mon, 24 Jul 2023 14:56:09 +0200 + +libwebsockets (4.1.6-3.1) unstable; urgency=medium + + * Non-maintainer upload. + * debian/patches/f9d1f25abe896b9fa1de780e4a5cb41116926a29.patch: + - cherry-pick upstream patch to fix a build failure with gcc-13 + (Closes: #1037747) + + -- Gianfranco Costamagna Thu, 20 Jul 2023 17:27:19 +0200 + +libwebsockets (4.1.6-3) unstable; urgency=medium + + * Update self-testing. + + -- Laszlo Boszormenyi (GCS) Sun, 07 Aug 2022 10:46:31 +0200 + +libwebsockets (4.1.6-2) unstable; urgency=medium + + * Update -dev dependency. + * Upload to Sid. + + [ Simon Chopin ] + * d/rules: downgrade deprecation errors into warnings to fix the build + against OpenSSL3 (closes: #1006245). + + -- Laszlo Boszormenyi (GCS) Sat, 06 Aug 2022 07:42:00 +0200 + +libwebsockets (4.1.6-1) experimental; urgency=medium + + * New upstream release. + + -- Laszlo Boszormenyi (GCS) Fri, 11 Dec 2020 17:00:18 +0100 + +libwebsockets (4.1.4-1) experimental; urgency=medium + + * New upstream release. + + -- Laszlo Boszormenyi (GCS) Thu, 29 Oct 2020 22:44:45 +0100 + +libwebsockets (4.1.3-1) experimental; urgency=medium + + * New upstream release. + * Update library symbols for this release. + + -- Laszlo Boszormenyi (GCS) Wed, 14 Oct 2020 18:05:17 +0200 + +libwebsockets (4.1.2-1) experimental; urgency=medium + + * New upstream release: + - package ev, uv and glib event loops as plugins. + * Library transition from libwebsockets16 to libwebsockets17 . + * Update library symbols for this release. + * Update debhelper level to 12 . + + -- Laszlo Boszormenyi (GCS) Sun, 27 Sep 2020 17:53:20 +0200 + +libwebsockets (4.0.20-1) unstable; urgency=medium + + * New upstream release. + + -- Laszlo Boszormenyi (GCS) Tue, 14 Jul 2020 17:27:49 +0200 + +libwebsockets (4.0.19-1) unstable; urgency=medium + + * New upstream release. + * Update library symbols for this release. + + [ Matti Hamalainen ] + * Re-enable extensions support (closes: #962821). + + -- Laszlo Boszormenyi (GCS) Sat, 27 Jun 2020 17:33:41 +0200 + +libwebsockets (4.0.16-1) unstable; urgency=medium + + * New upstream release. + + -- Laszlo Boszormenyi (GCS) Sun, 14 Jun 2020 14:09:19 +0200 + +libwebsockets (4.0.15-2) unstable; urgency=medium + + * Upload to Sid. + + -- Laszlo Boszormenyi (GCS) Thu, 11 Jun 2020 07:55:41 +0200 + +libwebsockets (4.0.15-1) experimental; urgency=medium + + * New upstream release. + + [ Pino Toscano ] + * Enable to compile again on !Linux archs (closes: #955281). + + -- Laszlo Boszormenyi (GCS) Sat, 06 Jun 2020 07:49:47 +0200 + +libwebsockets (4.0.13-1) experimental; urgency=medium + + * New upstream release. + + -- Laszlo Boszormenyi (GCS) Mon, 01 Jun 2020 07:07:42 +0200 + +libwebsockets (4.0.1-1) experimental; urgency=medium + + * New upstream release. + + -- Laszlo Boszormenyi (GCS) Sat, 28 Mar 2020 08:29:58 +0000 + +libwebsockets (4.0.0-1) experimental; urgency=medium + + * New upstream release. + * Library transition from libwebsockets15 to libwebsockets16 . + * Update library symbols for this release. + * Update copyright file. + * Update Standards-Version to 4.5.0 . + + -- Laszlo Boszormenyi (GCS) Mon, 09 Mar 2020 18:04:03 +0000 + libwebsockets (3.2.1-3) unstable; urgency=medium * Build with IPv6 support. diff -Nru libwebsockets-3.2.1/debian/control libwebsockets-4.1.6/debian/control --- libwebsockets-3.2.1/debian/control 2019-12-26 21:27:29.000000000 +0000 +++ libwebsockets-4.1.6/debian/control 2022-08-06 05:42:00.000000000 +0000 @@ -3,15 +3,14 @@ Priority: optional Maintainer: Laszlo Boszormenyi (GCS) Uploaders: Peter Pentchev -Build-Depends: debhelper-compat (= 11), cmake, libcap-dev, libev-dev, libssl-dev, libuv1-dev, - openssl, zlib1g-dev -Standards-Version: 4.4.1 +Build-Depends: debhelper-compat (= 12), pkg-config, cmake, + libcap-dev [linux-any], libev-dev, libuv1-dev, libglib2.0-dev, zlib1g-dev, + libssl-dev, openssl +Standards-Version: 4.5.0 Homepage: https://libwebsockets.org/ -#Vcs-Git: https://anonscm.debian.org/git/collab-maint/libwebsockets.git -b debian-v2.4-stable -#Vcs-Browser: https://anonscm.debian.org/cgit/collab-maint/libwebsockets.git/log/?h=debian-v2.4-stable Rules-Requires-Root: no -Package: libwebsockets15 +Package: libwebsockets17 Architecture: any Multi-Arch: same Depends: ${shlibs:Depends}, ${misc:Depends} @@ -20,14 +19,54 @@ clients and servers built to use minimal CPU and memory resources and provide fast throughput in both directions. . - This package contains the shared library. + This package contains the main shared library. + +Package: libwebsockets-evlib-ev +Architecture: any +Multi-Arch: same +Depends: libwebsockets17 (= ${binary:Version}), + ${shlibs:Depends}, ${misc:Depends} +Description: lightweight C websockets library + Libwebsockets is a lightweight pure C library for both websockets + clients and servers built to use minimal CPU and memory resources + and provide fast throughput in both directions. + . + This package contains the shared library for evlib_ev plugin. + +Package: libwebsockets-evlib-uv +Architecture: any +Multi-Arch: same +Depends: libwebsockets17 (= ${binary:Version}), + ${shlibs:Depends}, ${misc:Depends} +Description: lightweight C websockets library + Libwebsockets is a lightweight pure C library for both websockets + clients and servers built to use minimal CPU and memory resources + and provide fast throughput in both directions. + . + This package contains the shared library for evlib_uv plugin. + +Package: libwebsockets-evlib-glib +Architecture: any +Multi-Arch: same +Depends: libwebsockets17 (= ${binary:Version}), + ${shlibs:Depends}, ${misc:Depends} +Description: lightweight C websockets library + Libwebsockets is a lightweight pure C library for both websockets + clients and servers built to use minimal CPU and memory resources + and provide fast throughput in both directions. + . + This package contains the shared library for evlib_glib plugin. Package: libwebsockets-dev Section: libdevel Architecture: any Multi-Arch: same -Depends: libwebsockets15 (= ${binary:Version}), libev-dev, libssl-dev, - libuv1-dev, zlib1g-dev, libcap-dev, ${misc:Depends} +Depends: libwebsockets17 (= ${binary:Version}), + libwebsockets-evlib-ev (= ${binary:Version}), + libwebsockets-evlib-uv (= ${binary:Version}), + libwebsockets-evlib-glib (= ${binary:Version}), + libev-dev, libssl-dev, libuv1-dev, zlib1g-dev, + libcap-dev [linux-any], ${misc:Depends} Description: lightweight C websockets library - development files Libwebsockets is a lightweight pure C library for both websockets clients and servers built to use minimal CPU and memory resources @@ -40,7 +79,7 @@ Section: utils Architecture: any Multi-Arch: foreign -Depends: libwebsockets15 (= ${binary:Version}), +Depends: libwebsockets17 (= ${binary:Version}), libwebsockets-test-server-common (= ${source:Version}), ${shlibs:Depends}, ${misc:Depends} Description: lightweight C websockets library - test servers diff -Nru libwebsockets-3.2.1/debian/copyright libwebsockets-4.1.6/debian/copyright --- libwebsockets-3.2.1/debian/copyright 2019-10-13 14:23:13.000000000 +0000 +++ libwebsockets-4.1.6/debian/copyright 2020-03-09 18:04:03.000000000 +0000 @@ -5,10 +5,10 @@ Files: * Copyright: (C) 2010-2019 Andy Green -License: LGPL-2.1 +License: MIT Files: cmake/FindGit.cmake -Copyright: (c) Kitware Inc. +Copyright: (C) Kitware Inc. License: BSD-1 Files: lib/misc/base64-decode.c @@ -73,9 +73,13 @@ Copyright: (C) 1995-2010 Jean-loup Gailly and Mark Adler License: BSD-3-zlib +Files: test-apps/*.c minimal-examples/* lwsws/* +Copyright: 2010-2020 by Andy Green +License: CC0-1.0 + Files: debian/* Copyright: (C) 2013, 2015, 2016, 2018 Peter Pentchev , - (C) 2013, 2015, 2017 Laszlo Boszormenyi (GCS) + (C) 2013, 2015, 2017, 2020 Laszlo Boszormenyi (GCS) License: LGPL-2.1 License: LGPL-2.1 diff -Nru libwebsockets-3.2.1/debian/libwebsockets15.install libwebsockets-4.1.6/debian/libwebsockets15.install --- libwebsockets-3.2.1/debian/libwebsockets15.install 2018-03-02 18:39:44.000000000 +0000 +++ libwebsockets-4.1.6/debian/libwebsockets15.install 1970-01-01 00:00:00.000000000 +0000 @@ -1 +0,0 @@ -usr/lib/*/lib*.so.* diff -Nru libwebsockets-3.2.1/debian/libwebsockets15.symbols libwebsockets-4.1.6/debian/libwebsockets15.symbols --- libwebsockets-3.2.1/debian/libwebsockets15.symbols 2019-10-13 14:23:13.000000000 +0000 +++ libwebsockets-4.1.6/debian/libwebsockets15.symbols 1970-01-01 00:00:00.000000000 +0000 @@ -1,294 +0,0 @@ -libwebsockets.so.15 libwebsockets15 #MINVER# - _lws_log@Base 1.2 - _lws_logv@Base 1.4 - _lws_plat_file_close@Base 2.4.1 - _lws_plat_file_open@Base 2.4.1 - _lws_plat_file_read@Base 2.4.1 - _lws_plat_file_seek_cur@Base 2.4.1 - _lws_plat_file_write@Base 2.4.1 - _lws_plat_service_tsi@Base 2.4.1 - elops_init_pt_uv@Base 3.2.0 - humanize_schema_si@Base 3.2.0 - humanize_schema_si_bytes@Base 3.2.0 - humanize_schema_us@Base 3.2.0 - lejp_change_callback@Base 3.2.0 - lejp_check_path_match@Base 3.2.0 - lejp_construct@Base 3.2.0 - lejp_destruct@Base 3.2.0 - lejp_error_to_string@Base 3.2.0 - lejp_get_wildcard@Base 3.2.0 - lejp_parse@Base 3.2.0 - lejp_parser_pop@Base 3.2.0 - lejp_parser_push@Base 3.2.0 - lws_SHA1@Base 1.6.0 - lws_add_http_common_headers@Base 3.2.0 - lws_add_http_header_by_name@Base 1.4 - lws_add_http_header_by_token@Base 1.4 - lws_add_http_header_content_length@Base 1.4 - lws_add_http_header_status@Base 1.4 - lws_adjust_protocol_psds@Base 2.4.1 - lws_adopt_descriptor_vhost@Base 2.4.1 - lws_adopt_socket@Base 1.7.0 - lws_adopt_socket_readbuf@Base 2.0.2 - lws_adopt_socket_vhost@Base 2.4.1 - lws_adopt_socket_vhost_readbuf@Base 2.4.1 - lws_b64_decode_string@Base 1.4 - lws_b64_decode_string_len@Base 3.2.0 - lws_b64_encode_string@Base 1.2 - lws_b64_encode_string_url@Base 3.2.0 - lws_buflist_append_segment@Base 3.2.0 - lws_buflist_destroy_all_segments@Base 3.2.0 - lws_buflist_next_segment_len@Base 3.2.0 - lws_buflist_use_segment@Base 3.2.0 - lws_callback_all_protocol@Base 1.6.0 - lws_callback_all_protocol_vhost@Base 2.0.2 - lws_callback_all_protocol_vhost_args@Base 2.4.1 - lws_callback_http_dummy@Base 2.4.1 - lws_callback_on_writable@Base 1.6.0 - lws_callback_on_writable_all_protocol@Base 1.6.0 - lws_callback_on_writable_all_protocol_vhost@Base 2.0.2 - lws_callback_vhost_protocols@Base 2.4.1 - lws_callback_vhost_protocols_vhost@Base 3.2.0 - lws_cancel_service@Base 1.6.0 - lws_cancel_service_pt@Base 1.7.0 - lws_canonical_hostname@Base 1.6.0 - lws_chunked_html_process@Base 2.4.1 - lws_clear_child_pending_on_writable@Base 2.4.1 - lws_client_connect_via_info@Base 1.7.0 - lws_client_http_body_pending@Base 2.4.1 - lws_client_reset@Base 1.7.0 - lws_close_all_handles_in_loop@Base 2.4.1 - lws_close_reason@Base 1.7.0 - lws_cmdline_option@Base 3.2.0 - lws_context_deprecate@Base 2.4.1 - lws_context_destroy@Base 1.6.0 - lws_context_init_server_ssl@Base 1.3 - lws_context_is_deprecated@Base 2.4.1 - lws_context_user@Base 1.6.0 - lws_create_adopt_udp@Base 3.2.0 - lws_create_context@Base 1.6.0 - lws_create_vhost@Base 2.0.2 - lws_daemonize@Base 1.2 - lws_dir@Base 3.2.0 - lws_dll2_add_before@Base 3.2.0 - lws_dll2_add_head@Base 3.2.0 - lws_dll2_add_sorted@Base 3.2.0 - lws_dll2_add_tail@Base 3.2.0 - lws_dll2_clear@Base 3.2.0 - lws_dll2_foreach_safe@Base 3.2.0 - lws_dll2_owner_clear@Base 3.2.0 - lws_dll2_remove@Base 3.2.0 - lws_ev_sigint_cb@Base 1.7.0 - lws_explicit_bzero@Base 3.2.0 - lws_extension_callback_pm_deflate@Base 1.7.0 - lws_filename_purify_inplace@Base 3.2.0 - lws_finalize_http_header@Base 1.4 - lws_finalize_startup@Base 2.0.2 - lws_finalize_write_http_header@Base 3.2.0 - lws_frame_is_binary@Base 1.2 - lws_get_child@Base 2.0.2 - lws_get_child_pending_on_writable@Base 2.4.1 - lws_get_close_length@Base 2.4.1 - lws_get_close_payload@Base 2.4.1 - lws_get_context@Base 1.6.0 - lws_get_count_threads@Base 1.7.0 - lws_get_effective_uid_gid@Base 3.2.0 - lws_get_fops@Base 1.6.0 - lws_get_library_version@Base 1.2 - lws_get_mimetype@Base 2.4.1 - lws_get_network_wsi@Base 2.4.1 - lws_get_opaque_parent_data@Base 2.4.1 - lws_get_opaque_user_data@Base 3.2.0 - lws_get_parent@Base 2.0.2 - lws_get_peer_addresses@Base 1.6.0 - lws_get_peer_simple@Base 2.4.1 - lws_get_peer_write_allowance@Base 1.4 - lws_get_protocol@Base 1.6.0 - lws_get_random@Base 1.6.0 - lws_get_reserved_bits@Base 1.6.0 - lws_get_socket_fd@Base 1.6.0 - lws_get_ssl@Base 2.4.1 - lws_get_udp@Base 3.2.0 - lws_get_urlarg_by_name@Base 2.4.1 - lws_get_vhost@Base 2.4.1 - lws_get_vhost_by_name@Base 3.2.0 - lws_get_vhost_iface@Base 3.2.0 - lws_get_vhost_listen_port@Base 3.2.0 - lws_get_vhost_name@Base 3.2.0 - lws_get_vhost_port@Base 3.2.0 - lws_get_vhost_user@Base 3.2.0 - lws_handle_POLLOUT_event@Base 2.4.1 - lws_hdr_copy@Base 1.2 - lws_hdr_copy_fragment@Base 1.6.0 - lws_hdr_custom_copy@Base 3.2.0 - lws_hdr_custom_length@Base 3.2.0 - lws_hdr_fragment_length@Base 1.7.0 - lws_hdr_total_length@Base 1.2 - lws_hex_to_byte_array@Base 3.2.0 - lws_http_client_http_response@Base 2.4.1 - lws_http_client_read@Base 2.0.2 - lws_http_compression_apply@Base 3.2.0 - lws_http_get_uri_and_method@Base 3.2.0 - lws_http_headers_detach@Base 3.2.0 - lws_http_mark_sse@Base 3.2.0 - lws_http_redirect@Base 2.0.2 - lws_http_transaction_completed@Base 1.4 - lws_humanize@Base 3.2.0 - lws_init_vhost_client_ssl@Base 2.4.1 - lws_interface_to_sa@Base 1.7.0 - lws_is_cgi@Base 2.0.2 - lws_is_final_fragment@Base 1.6.0 - lws_is_first_fragment@Base 2.4.1 - lws_is_ssl@Base 1.4 - lws_json_purify@Base 2.4.1 - lws_libuv_static_refcount_add@Base 3.2.0 - lws_libuv_static_refcount_del@Base 3.2.0 - lws_libuv_stop_without_kill@Base 2.4.1 - lws_list_ptr_insert@Base 3.2.0 - lws_now_secs@Base 2.4.1 - lws_now_usecs@Base 3.2.0 - lws_open@Base 3.2.0 - lws_parse_uri@Base 1.7.0 - lws_partial_buffered@Base 1.4 - lws_plat_read_file@Base 3.2.0 - lws_plat_recommended_rsa_bits@Base 3.2.0 - lws_plat_write_cert@Base 3.2.0 - lws_plat_write_file@Base 3.2.0 - lws_protocol_get@Base 2.0.2 - lws_protocol_init@Base 2.4.1 - lws_protocol_vh_priv_get@Base 2.0.2 - lws_protocol_vh_priv_zalloc@Base 2.0.2 - lws_pvo_get_str@Base 3.2.0 - lws_pvo_search@Base 3.2.0 - lws_raw_transaction_completed@Base 3.2.0 - lws_remaining_packet_payload@Base 1.6.0 - lws_retry_get_delay_ms@Base 3.2.0 - lws_return_http_status@Base 1.6.0 - lws_ring_bump_head@Base 2.4.1 - lws_ring_consume@Base 2.4.1 - lws_ring_create@Base 2.4.1 - lws_ring_destroy@Base 2.4.1 - lws_ring_dump@Base 3.2.0 - lws_ring_get_count_free_elements@Base 2.4.1 - lws_ring_get_count_waiting_elements@Base 2.4.1 - lws_ring_get_element@Base 2.4.1 - lws_ring_get_oldest_tail@Base 2.4.1 - lws_ring_insert@Base 2.4.1 - lws_ring_next_linear_insert_range@Base 2.4.1 - lws_ring_update_oldest_tail@Base 2.4.1 - lws_role_transition@Base 3.2.0 - lws_rx_flow_allow_all_protocol@Base 1.6.0 - lws_rx_flow_control@Base 1.6.0 - lws_send_pipe_choked@Base 1.2 - lws_seq_check_wsi@Base 3.2.0 - lws_seq_create@Base 3.2.0 - lws_seq_destroy@Base 3.2.0 - lws_seq_from_user@Base 3.2.0 - lws_seq_get_context@Base 3.2.0 - lws_seq_name@Base 3.2.0 - lws_seq_queue_event@Base 3.2.0 - lws_seq_timeout_us@Base 3.2.0 - lws_seq_us_since_creation@Base 3.2.0 - lws_serve_http_file@Base 1.6.0 - lws_serve_http_file_fragment@Base 1.6.0 - lws_server_get_canonical_hostname@Base 1.3 - lws_server_socket_service_ssl@Base 1.3 - lws_service@Base 1.6.0 - lws_service_adjust_timeout@Base 2.4.1 - lws_service_fd@Base 1.6.0 - lws_service_fd_tsi@Base 1.7.0 - lws_service_tsi@Base 1.7.0 - lws_set_allocator@Base 1.4 - lws_set_extension_option@Base 2.0.2 - lws_set_fops@Base 2.4.1 - lws_set_log_level@Base 1.2 - lws_set_opaque_parent_data@Base 2.4.1 - lws_set_opaque_user_data@Base 3.2.0 - lws_set_proxy@Base 1.6.0 - lws_set_timeout@Base 1.6.0 - lws_set_timer_usecs@Base 3.2.0 - lws_set_wsi_user@Base 2.4.1 - lws_snprintf@Base 2.0.3 - lws_spa_create@Base 2.4.1 - lws_spa_create_via_info@Base 3.2.0 - lws_spa_destroy@Base 2.4.1 - lws_spa_finalize@Base 2.4.1 - lws_spa_get_length@Base 2.4.1 - lws_spa_get_string@Base 2.4.1 - lws_spa_process@Base 2.4.1 - lws_sql_purify@Base 2.4.1 - lws_ssl_capable_read@Base 1.3 - lws_ssl_capable_read_no_ssl@Base 1.3 - lws_ssl_capable_write@Base 1.3 - lws_ssl_capable_write_no_ssl@Base 1.3 - lws_ssl_close@Base 1.3 - lws_ssl_destroy@Base 1.3 - lws_ssl_pending@Base 1.5 - lws_ssl_pending_no_ssl@Base 1.5 - lws_ssl_remove_wsi_from_buffered_list@Base 1.4 - lws_strncpy@Base 3.2.0 - lws_struct_default_lejp_cb@Base 3.2.0 - lws_struct_json_init_parse@Base 3.2.0 - lws_struct_json_serialize@Base 3.2.0 - lws_struct_json_serialize_create@Base 3.2.0 - lws_struct_json_serialize_destroy@Base 3.2.0 - lws_struct_schema_only_lejp_cb@Base 3.2.0 - lws_sul_schedule@Base 3.2.0 - lws_system_get_info@Base 3.2.0 - lws_system_reboot@Base 3.2.0 - lws_timed_callback_vh_protocol@Base 3.2.0 - lws_timed_callback_vh_protocol_us@Base 3.2.0 - lws_timingsafe_bcmp@Base 3.2.0 - lws_tls_cert_updated@Base 3.2.0 - lws_tls_peer_cert_info@Base 3.2.0 - lws_tls_vhost_cert_info@Base 3.2.0 - lws_token_to_string@Base 1.4 - lws_tokenize@Base 3.2.0 - lws_tokenize_cstr@Base 3.2.0 - lws_tokenize_init@Base 3.2.0 - lws_urldecode@Base 2.4.1 - lws_urlencode@Base 2.0.2 - lws_uv_getloop@Base 1.7.0 - lws_vfs_file_open@Base 2.4.1 - lws_vfs_file_seek_end@Base 2.4.1 - lws_vfs_file_seek_set@Base 2.4.1 - lws_vfs_get_length@Base 2.4.1 - lws_vfs_get_mod_time@Base 2.4.1 - lws_vfs_tell@Base 2.4.1 - lws_vhost_destroy@Base 2.4.1 - lws_vhost_get@Base 2.0.2 - lws_vhost_name_to_protocol@Base 2.4.1 - lws_vhost_user@Base 2.4.1 - lws_write@Base 1.6.0 - lws_wsi_user@Base 1.6.0 - lws_x509_create@Base 3.2.0 - lws_x509_destroy@Base 3.2.0 - lws_x509_info@Base 3.2.0 - lws_x509_parse_from_pem@Base 3.2.0 - lws_x509_verify@Base 3.2.0 - lwsac_align@Base 3.2.0 - lwsac_cached_file@Base 3.2.0 - lwsac_detach@Base 3.2.0 - lwsac_free@Base 3.2.0 - lwsac_get_next@Base 3.2.0 - lwsac_get_tail_pos@Base 3.2.0 - lwsac_info@Base 3.2.0 - lwsac_reference@Base 3.2.0 - lwsac_sizeof@Base 3.2.0 - lwsac_total_alloc@Base 3.2.0 - lwsac_unreference@Base 3.2.0 - lwsac_use@Base 3.2.0 - lwsac_use_cached_file_detach@Base 3.2.0 - lwsac_use_cached_file_end@Base 3.2.0 - lwsac_use_cached_file_start@Base 3.2.0 - lwsac_use_zero@Base 3.2.0 - lwsac_use_zeroed@Base 3.2.0 - lwsl_emit_stderr@Base 1.3 - lwsl_emit_stderr_notimestamp@Base 3.2.0 - lwsl_emit_syslog@Base 1.2 - lwsl_hexdump@Base 1.2 - lwsl_hexdump_level@Base 2.4.1 - lwsl_timestamp@Base 2.0.2 - lwsl_visible@Base 2.4.1 - lwsws_get_config_globals@Base 3.2.0 - lwsws_get_config_vhosts@Base 3.2.0 diff -Nru libwebsockets-3.2.1/debian/libwebsockets17.install libwebsockets-4.1.6/debian/libwebsockets17.install --- libwebsockets-3.2.1/debian/libwebsockets17.install 1970-01-01 00:00:00.000000000 +0000 +++ libwebsockets-4.1.6/debian/libwebsockets17.install 2018-03-02 18:39:44.000000000 +0000 @@ -0,0 +1 @@ +usr/lib/*/lib*.so.* diff -Nru libwebsockets-3.2.1/debian/libwebsockets17.symbols libwebsockets-4.1.6/debian/libwebsockets17.symbols --- libwebsockets-3.2.1/debian/libwebsockets17.symbols 1970-01-01 00:00:00.000000000 +0000 +++ libwebsockets-4.1.6/debian/libwebsockets17.symbols 2020-10-14 16:05:17.000000000 +0000 @@ -0,0 +1,349 @@ +libwebsockets.so.17 libwebsockets17 #MINVER# + __lws_close_free_wsi_final@Base 4.1.0 + __lws_sul_insert@Base 4.0.0 + __lws_sul_service_ripe@Base 4.0.0 + __lws_system_attach@Base 4.0.0 + _lws_dll2_search_sz_pl@Base 4.1.0 + _lws_log@Base 1.2 + _lws_logv@Base 1.4 + _lws_plat_file_close@Base 2.4.1 + _lws_plat_file_open@Base 2.4.1 + _lws_plat_file_read@Base 2.4.1 + _lws_plat_file_seek_cur@Base 2.4.1 + _lws_plat_file_write@Base 2.4.1 + _lws_plat_service_forced_tsi@Base 4.1.0 + _lws_plat_service_tsi@Base 2.4.1 + humanize_schema_si@Base 3.2.0 + humanize_schema_si_bytes@Base 3.2.0 + humanize_schema_us@Base 3.2.0 + lejp_change_callback@Base 3.2.0 + lejp_check_path_match@Base 3.2.0 + lejp_construct@Base 3.2.0 + lejp_destruct@Base 3.2.0 + lejp_error_to_string@Base 3.2.0 + lejp_get_wildcard@Base 3.2.0 + lejp_parse@Base 3.2.0 + lejp_parser_pop@Base 3.2.0 + lejp_parser_push@Base 3.2.0 + lws_SHA1@Base 1.6.0 + lws_add_http_common_headers@Base 3.2.0 + lws_add_http_header_by_name@Base 1.4 + lws_add_http_header_by_token@Base 1.4 + lws_add_http_header_content_length@Base 1.4 + lws_add_http_header_status@Base 1.4 + lws_adjust_protocol_psds@Base 2.4.1 + lws_adopt_descriptor_vhost@Base 2.4.1 + lws_adopt_descriptor_vhost_via_info@Base 4.0.0 + lws_adopt_socket@Base 1.7.0 + lws_adopt_socket_readbuf@Base 2.0.2 + lws_adopt_socket_vhost@Base 2.4.1 + lws_adopt_socket_vhost_readbuf@Base 2.4.1 + lws_b64_decode_state_init@Base 4.0.0 + lws_b64_decode_stateful@Base 4.0.0 + lws_b64_decode_string@Base 1.4 + lws_b64_decode_string_len@Base 3.2.0 + lws_b64_encode_string@Base 1.2 + lws_b64_encode_string_url@Base 3.2.0 + lws_buflist_append_segment@Base 3.2.0 + lws_buflist_describe@Base 4.0.0 + lws_buflist_destroy_all_segments@Base 3.2.0 + lws_buflist_linear_copy@Base 4.0.0 + lws_buflist_next_segment_len@Base 3.2.0 + lws_buflist_total_len@Base 4.0.0 + lws_buflist_use_segment@Base 3.2.0 + lws_callback_all_protocol@Base 1.6.0 + lws_callback_all_protocol_vhost@Base 2.0.2 + lws_callback_all_protocol_vhost_args@Base 2.4.1 + lws_callback_http_dummy@Base 2.4.1 + lws_callback_on_writable@Base 1.6.0 + lws_callback_on_writable_all_protocol@Base 1.6.0 + lws_callback_on_writable_all_protocol_vhost@Base 2.0.2 + lws_callback_vhost_protocols@Base 2.4.1 + lws_callback_vhost_protocols_vhost@Base 3.2.0 + lws_cancel_service@Base 1.6.0 + lws_cancel_service_pt@Base 1.7.0 + lws_canonical_hostname@Base 1.6.0 + lws_chunked_html_process@Base 2.4.1 + lws_clear_child_pending_on_writable@Base 2.4.1 + lws_client_connect_via_info@Base 1.7.0 + lws_client_http_body_pending@Base 2.4.1 + lws_client_http_multipart@Base 4.0.0 + lws_client_reset@Base 1.7.0 + lws_close_free_wsi@Base 4.1.0 + lws_close_reason@Base 1.7.0 + lws_cmdline_option@Base 3.2.0 + lws_cmdline_option_handle_builtin@Base 4.0.0 + lws_context_deprecate@Base 2.4.1 + lws_context_destroy2@Base 4.1.0 + lws_context_destroy@Base 1.6.0 + lws_context_init_extensions@Base 4.0.19 + lws_context_is_deprecated@Base 2.4.1 + lws_context_user@Base 1.6.0 + lws_create_adopt_udp@Base 3.2.0 + lws_create_context@Base 1.6.0 + lws_create_vhost@Base 2.0.2 + lws_daemonize@Base 1.2 + lws_destroy_event_pipe@Base 4.1.0 + lws_dir@Base 3.2.0 + lws_dir_glob_cb@Base 4.1.0 + lws_dir_rm_rf_cb@Base 4.1.0 + lws_dll2_add_before@Base 3.2.0 + lws_dll2_add_head@Base 3.2.0 + lws_dll2_add_sorted@Base 3.2.0 + lws_dll2_add_tail@Base 3.2.0 + lws_dll2_clear@Base 3.2.0 + lws_dll2_foreach_safe@Base 3.2.0 + lws_dll2_owner_clear@Base 3.2.0 + lws_dll2_remove@Base 3.2.0 + lws_explicit_bzero@Base 3.2.0 + lws_ext_parse_options@Base 4.0.19 + lws_extension_callback_pm_deflate@Base 4.0.19 + lws_filename_purify_inplace@Base 3.2.0 + lws_finalize_http_header@Base 1.4 + lws_finalize_startup@Base 2.0.2 + lws_finalize_write_http_header@Base 3.2.0 + lws_frame_is_binary@Base 1.2 + lws_get_child@Base 2.0.2 + lws_get_child_pending_on_writable@Base 2.4.1 + lws_get_close_length@Base 2.4.1 + lws_get_close_payload@Base 2.4.1 + lws_get_context@Base 1.6.0 + lws_get_count_threads@Base 1.7.0 + lws_get_effective_uid_gid@Base 3.2.0 + lws_get_fops@Base 1.6.0 + lws_get_library_version@Base 1.2 + lws_get_mimetype@Base 2.4.1 + lws_get_network_wsi@Base 2.4.1 + lws_get_opaque_parent_data@Base 2.4.1 + lws_get_opaque_user_data@Base 3.2.0 + lws_get_parent@Base 2.0.2 + lws_get_peer_addresses@Base 1.6.0 + lws_get_peer_simple@Base 2.4.1 + lws_get_peer_simple_fd@Base 4.0.0 + lws_get_peer_write_allowance@Base 1.4 + lws_get_protocol@Base 1.6.0 + lws_get_random@Base 1.6.0 + lws_get_reserved_bits@Base 1.6.0 + lws_get_socket_fd@Base 1.6.0 + lws_get_ssl@Base 2.4.1 + lws_get_tsi@Base 4.0.0 + lws_get_udp@Base 3.2.0 + lws_get_urlarg_by_name@Base 2.4.1 + lws_get_vhost@Base 2.4.1 + lws_get_vhost_by_name@Base 3.2.0 + lws_get_vhost_iface@Base 3.2.0 + lws_get_vhost_listen_port@Base 3.2.0 + lws_get_vhost_name@Base 3.2.0 + lws_get_vhost_port@Base 3.2.0 + lws_get_vhost_user@Base 3.2.0 + lws_h2_client_stream_long_poll_rxonly@Base 4.0.0 + lws_h2_get_peer_txcredit_estimate@Base 4.0.0 + lws_h2_update_peer_txcredit@Base 4.0.0 + lws_handle_POLLOUT_event@Base 2.4.1 + lws_hdr_copy@Base 1.2 + lws_hdr_copy_fragment@Base 1.6.0 + lws_hdr_custom_copy@Base 3.2.0 + lws_hdr_custom_length@Base 3.2.0 + lws_hdr_fragment_length@Base 1.7.0 + lws_hdr_total_length@Base 1.2 + lws_hex_random@Base 4.1.0 + lws_hex_to_byte_array@Base 3.2.0 + lws_http_basic_auth_gen@Base 4.0.0 + lws_http_client_http_response@Base 2.4.1 + lws_http_client_read@Base 2.0.2 + lws_http_compression_apply@Base 3.2.0 + lws_http_cookie_get@Base 4.1.0 + lws_http_get_uri_and_method@Base 3.2.0 + lws_http_headers_detach@Base 3.2.0 + lws_http_is_redirected_to_get@Base 4.0.0 + lws_http_mark_sse@Base 3.2.0 + lws_http_redirect@Base 2.0.2 + lws_http_transaction_completed@Base 1.4 + lws_humanize@Base 3.2.0 + lws_init_vhost_client_ssl@Base 2.4.1 + lws_interface_to_sa@Base 1.7.0 + lws_is_cgi@Base 2.0.2 + lws_is_final_fragment@Base 1.6.0 + lws_is_first_fragment@Base 2.4.1 + lws_is_ssl@Base 1.4 + lws_json_purify@Base 2.4.1 + lws_json_purify_len@Base 4.0.0 + lws_json_simple_find@Base 4.1.0 + lws_json_simple_strcmp@Base 4.1.0 + lws_list_ptr_insert@Base 3.2.0 + lws_now_secs@Base 2.4.1 + lws_now_usecs@Base 3.2.0 + lws_nstrstr@Base 4.1.0 + lws_open@Base 3.2.0 + lws_parse_numeric_address@Base 4.0.0 + lws_parse_uri@Base 1.7.0 + lws_partial_buffered@Base 1.4 + lws_plat_read_file@Base 3.2.0 + lws_plat_recommended_rsa_bits@Base 3.2.0 + lws_plat_write_cert@Base 3.2.0 + lws_plat_write_file@Base 3.2.0 + lws_plugins_destroy@Base 4.1.0 + lws_plugins_init@Base 4.1.0 + lws_protocol_get@Base 2.0.2 + lws_protocol_init@Base 2.4.1 + lws_protocol_vh_priv_get@Base 2.0.2 + lws_protocol_vh_priv_zalloc@Base 2.0.2 + lws_pvo_get_str@Base 3.2.0 + lws_pvo_search@Base 3.2.0 + lws_raw_transaction_completed@Base 3.2.0 + lws_realloc@Base 4.1.0 + lws_remaining_packet_payload@Base 1.6.0 + lws_retry_get_delay_ms@Base 3.2.0 + lws_retry_sul_schedule@Base 4.0.0 + lws_retry_sul_schedule_retry_wsi@Base 4.0.0 + lws_return_http_status@Base 1.6.0 + lws_ring_bump_head@Base 2.4.1 + lws_ring_consume@Base 2.4.1 + lws_ring_create@Base 2.4.1 + lws_ring_destroy@Base 2.4.1 + lws_ring_dump@Base 3.2.0 + lws_ring_get_count_free_elements@Base 2.4.1 + lws_ring_get_count_waiting_elements@Base 2.4.1 + lws_ring_get_element@Base 2.4.1 + lws_ring_get_oldest_tail@Base 2.4.1 + lws_ring_insert@Base 2.4.1 + lws_ring_next_linear_insert_range@Base 2.4.1 + lws_ring_update_oldest_tail@Base 2.4.1 + lws_rx_flow_allow_all_protocol@Base 1.6.0 + lws_rx_flow_control@Base 1.6.0 + lws_sa46_compare_ads@Base 4.0.0 + lws_sa46_parse_numeric_address@Base 4.0.0 + lws_sa46_write_numeric_address@Base 4.0.0 + lws_send_pipe_choked@Base 1.2 + lws_ser_ru16be@Base 4.0.0 + lws_ser_ru32be@Base 4.0.0 + lws_ser_ru64be@Base 4.0.0 + lws_ser_wu16be@Base 4.0.0 + lws_ser_wu32be@Base 4.0.0 + lws_ser_wu64be@Base 4.0.0 + lws_serve_http_file@Base 1.6.0 + lws_serve_http_file_fragment@Base 1.6.0 + lws_service@Base 1.6.0 + lws_service_adjust_timeout@Base 2.4.1 + lws_service_do_ripe_rxflow@Base 4.1.0 + lws_service_fd@Base 1.6.0 + lws_service_fd_tsi@Base 1.7.0 + lws_service_tsi@Base 1.7.0 + lws_set_allocator@Base 1.4 + lws_set_extension_option@Base 2.0.2 + lws_set_fops@Base 2.4.1 + lws_set_log_level@Base 1.2 + lws_set_opaque_parent_data@Base 2.4.1 + lws_set_opaque_user_data@Base 3.2.0 + lws_set_proxy@Base 1.6.0 + lws_set_timeout@Base 1.6.0 + lws_set_timer_usecs@Base 3.2.0 + lws_set_wsi_user@Base 2.4.1 + lws_smd_msg_alloc@Base 4.1.0 + lws_smd_msg_free@Base 4.1.0 + lws_smd_msg_printf@Base 4.1.0 + lws_smd_msg_send@Base 4.1.0 + lws_smd_register@Base 4.1.0 + lws_smd_unregister@Base 4.1.0 + lws_snprintf@Base 2.0.3 + lws_spa_create@Base 2.4.1 + lws_spa_create_via_info@Base 3.2.0 + lws_spa_destroy@Base 2.4.1 + lws_spa_finalize@Base 2.4.1 + lws_spa_get_length@Base 2.4.1 + lws_spa_get_string@Base 2.4.1 + lws_spa_process@Base 2.4.1 + lws_sql_purify@Base 2.4.1 + lws_ssl_remove_wsi_from_buffered_list@Base 1.4 + lws_state_reg_deregister@Base 4.0.0 + lws_state_reg_notifier@Base 4.0.0 + lws_state_reg_notifier_list@Base 4.0.0 + lws_state_transition@Base 4.0.0 + lws_state_transition_steps@Base 4.0.0 + lws_strexp_expand@Base 4.0.0 + lws_strexp_init@Base 4.0.0 + lws_strexp_reset_out@Base 4.0.0 + lws_strncpy@Base 3.2.0 + lws_sul2_schedule@Base 4.1.0 + lws_sul_cancel@Base 4.1.0 + lws_sul_earliest_wakeable_event@Base 4.1.0 + lws_sul_schedule@Base 3.2.0 + lws_sul_schedule_wakesuspend@Base 4.1.0 + lws_system_blob_destroy@Base 4.0.0 + lws_system_blob_direct_set@Base 4.0.0 + lws_system_blob_get@Base 4.0.0 + lws_system_blob_get_single_ptr@Base 4.0.0 + lws_system_blob_get_size@Base 4.0.0 + lws_system_blob_heap_append@Base 4.0.0 + lws_system_blob_heap_empty@Base 4.0.0 + lws_system_context_from_system_mgr@Base 4.0.0 + lws_system_cpd_set@Base 4.1.0 + lws_system_cpd_start@Base 4.1.0 + lws_system_cpd_state_get@Base 4.1.0 + lws_system_get_blob@Base 4.0.0 + lws_system_get_ops@Base 4.0.0 + lws_system_get_state_manager@Base 4.0.0 + lws_timingsafe_bcmp@Base 3.2.0 + lws_tls_cert_updated@Base 3.2.0 + lws_tls_client_vhost_extra_cert_mem@Base 4.0.0 + lws_tls_peer_cert_info@Base 3.2.0 + lws_tls_vhost_cert_info@Base 3.2.0 + lws_token_to_string@Base 1.4 + lws_tokenize@Base 3.2.0 + lws_tokenize_cstr@Base 3.2.0 + lws_tokenize_init@Base 3.2.0 + lws_urldecode@Base 2.4.1 + lws_urlencode@Base 2.0.2 + lws_validity_confirmed@Base 4.0.0 + lws_vbi_decode@Base 4.0.0 + lws_vbi_encode@Base 4.0.0 + lws_vfs_file_open@Base 2.4.1 + lws_vfs_file_seek_end@Base 2.4.1 + lws_vfs_file_seek_set@Base 2.4.1 + lws_vfs_get_length@Base 2.4.1 + lws_vfs_get_mod_time@Base 2.4.1 + lws_vfs_tell@Base 2.4.1 + lws_vhost_destroy1@Base 4.1.0 + lws_vhost_destroy@Base 2.4.1 + lws_vhost_name_to_protocol@Base 2.4.1 + lws_vhost_user@Base 2.4.1 + lws_write@Base 1.6.0 + lws_write_numeric_address@Base 4.0.0 + lws_wsi_tsi@Base 4.1.3 + lws_wsi_tx_credit@Base 4.0.0 + lws_wsi_user@Base 1.6.0 + lws_x509_create@Base 3.2.0 + lws_x509_destroy@Base 3.2.0 + lws_x509_info@Base 3.2.0 + lws_x509_parse_from_pem@Base 3.2.0 + lws_x509_verify@Base 3.2.0 + lwsac_align@Base 3.2.0 + lwsac_cached_file@Base 3.2.0 + lwsac_detach@Base 3.2.0 + lwsac_extend@Base 4.0.0 + lwsac_free@Base 3.2.0 + lwsac_get_next@Base 3.2.0 + lwsac_get_tail_pos@Base 3.2.0 + lwsac_info@Base 3.2.0 + lwsac_reference@Base 3.2.0 + lwsac_scan_extant@Base 4.0.0 + lwsac_sizeof@Base 3.2.0 + lwsac_total_alloc@Base 3.2.0 + lwsac_total_overhead@Base 4.0.0 + lwsac_unreference@Base 3.2.0 + lwsac_use@Base 3.2.0 + lwsac_use_backfill@Base 4.0.0 + lwsac_use_cached_file_detach@Base 3.2.0 + lwsac_use_cached_file_end@Base 3.2.0 + lwsac_use_cached_file_start@Base 3.2.0 + lwsac_use_zero@Base 3.2.0 + lwsl_emit_stderr@Base 1.3 + lwsl_emit_stderr_notimestamp@Base 3.2.0 + lwsl_emit_syslog@Base 1.2 + lwsl_hexdump@Base 1.2 + lwsl_hexdump_level@Base 2.4.1 + lwsl_timestamp@Base 2.0.2 + lwsl_visible@Base 2.4.1 + lwsws_get_config_globals@Base 3.2.0 + lwsws_get_config_vhosts@Base 3.2.0 + wsi_from_fd@Base 4.1.0 diff -Nru libwebsockets-3.2.1/debian/libwebsockets-dev.install libwebsockets-4.1.6/debian/libwebsockets-dev.install --- libwebsockets-3.2.1/debian/libwebsockets-dev.install 2019-10-13 14:23:13.000000000 +0000 +++ libwebsockets-4.1.6/debian/libwebsockets-dev.install 2020-09-07 23:12:45.000000000 +0000 @@ -1,5 +1,5 @@ usr/include/* usr/lib/*/lib*.a -usr/lib/*/lib*.so +usr/lib/*/libwebsockets.so usr/lib/*/pkgconfig/* usr/lib/*/cmake/* diff -Nru libwebsockets-3.2.1/debian/libwebsockets-evlib-ev.install libwebsockets-4.1.6/debian/libwebsockets-evlib-ev.install --- libwebsockets-3.2.1/debian/libwebsockets-evlib-ev.install 1970-01-01 00:00:00.000000000 +0000 +++ libwebsockets-4.1.6/debian/libwebsockets-evlib-ev.install 2020-09-07 23:12:45.000000000 +0000 @@ -0,0 +1 @@ +usr/lib/*/libwebsockets-evlib_ev.so diff -Nru libwebsockets-3.2.1/debian/libwebsockets-evlib-ev.lintian-overrides libwebsockets-4.1.6/debian/libwebsockets-evlib-ev.lintian-overrides --- libwebsockets-3.2.1/debian/libwebsockets-evlib-ev.lintian-overrides 1970-01-01 00:00:00.000000000 +0000 +++ libwebsockets-4.1.6/debian/libwebsockets-evlib-ev.lintian-overrides 2020-09-07 23:12:45.000000000 +0000 @@ -0,0 +1,2 @@ +# it's a plugin depending on ABI versioned library +shared-library-lacks-version usr/lib/x86_64-linux-gnu/libwebsockets-evlib_ev.so libwebsockets-evlib_ev.so diff -Nru libwebsockets-3.2.1/debian/libwebsockets-evlib-ev.triggers libwebsockets-4.1.6/debian/libwebsockets-evlib-ev.triggers --- libwebsockets-3.2.1/debian/libwebsockets-evlib-ev.triggers 1970-01-01 00:00:00.000000000 +0000 +++ libwebsockets-4.1.6/debian/libwebsockets-evlib-ev.triggers 2020-09-07 23:12:45.000000000 +0000 @@ -0,0 +1,2 @@ +# it's a plugin +activate-noawait ldconfig diff -Nru libwebsockets-3.2.1/debian/libwebsockets-evlib-glib.install libwebsockets-4.1.6/debian/libwebsockets-evlib-glib.install --- libwebsockets-3.2.1/debian/libwebsockets-evlib-glib.install 1970-01-01 00:00:00.000000000 +0000 +++ libwebsockets-4.1.6/debian/libwebsockets-evlib-glib.install 2020-09-07 23:12:45.000000000 +0000 @@ -0,0 +1 @@ +usr/lib/*/libwebsockets-evlib_glib.so diff -Nru libwebsockets-3.2.1/debian/libwebsockets-evlib-glib.lintian-overrides libwebsockets-4.1.6/debian/libwebsockets-evlib-glib.lintian-overrides --- libwebsockets-3.2.1/debian/libwebsockets-evlib-glib.lintian-overrides 1970-01-01 00:00:00.000000000 +0000 +++ libwebsockets-4.1.6/debian/libwebsockets-evlib-glib.lintian-overrides 2020-09-07 23:12:45.000000000 +0000 @@ -0,0 +1,2 @@ +# it's a plugin depending on ABI versioned library +shared-library-lacks-version usr/lib/x86_64-linux-gnu/libwebsockets-evlib_glib.so libwebsockets-evlib_glib.so diff -Nru libwebsockets-3.2.1/debian/libwebsockets-evlib-glib.triggers libwebsockets-4.1.6/debian/libwebsockets-evlib-glib.triggers --- libwebsockets-3.2.1/debian/libwebsockets-evlib-glib.triggers 1970-01-01 00:00:00.000000000 +0000 +++ libwebsockets-4.1.6/debian/libwebsockets-evlib-glib.triggers 2020-09-07 23:12:45.000000000 +0000 @@ -0,0 +1,2 @@ +# it's a plugin +activate-noawait ldconfig diff -Nru libwebsockets-3.2.1/debian/libwebsockets-evlib-uv.install libwebsockets-4.1.6/debian/libwebsockets-evlib-uv.install --- libwebsockets-3.2.1/debian/libwebsockets-evlib-uv.install 1970-01-01 00:00:00.000000000 +0000 +++ libwebsockets-4.1.6/debian/libwebsockets-evlib-uv.install 2020-09-07 23:12:45.000000000 +0000 @@ -0,0 +1 @@ +usr/lib/*/libwebsockets-evlib_uv.so diff -Nru libwebsockets-3.2.1/debian/libwebsockets-evlib-uv.lintian-overrides libwebsockets-4.1.6/debian/libwebsockets-evlib-uv.lintian-overrides --- libwebsockets-3.2.1/debian/libwebsockets-evlib-uv.lintian-overrides 1970-01-01 00:00:00.000000000 +0000 +++ libwebsockets-4.1.6/debian/libwebsockets-evlib-uv.lintian-overrides 2020-09-07 23:12:45.000000000 +0000 @@ -0,0 +1,2 @@ +# it's a plugin depending on ABI versioned library +shared-library-lacks-version usr/lib/x86_64-linux-gnu/libwebsockets-evlib_uv.so libwebsockets-evlib_uv.so diff -Nru libwebsockets-3.2.1/debian/libwebsockets-evlib-uv.triggers libwebsockets-4.1.6/debian/libwebsockets-evlib-uv.triggers --- libwebsockets-3.2.1/debian/libwebsockets-evlib-uv.triggers 1970-01-01 00:00:00.000000000 +0000 +++ libwebsockets-4.1.6/debian/libwebsockets-evlib-uv.triggers 2020-09-07 23:12:45.000000000 +0000 @@ -0,0 +1,2 @@ +# it's a plugin +activate-noawait ldconfig diff -Nru libwebsockets-3.2.1/debian/missing-sources/plugins/generic-sessions/assets/lwsgs.js libwebsockets-4.1.6/debian/missing-sources/plugins/generic-sessions/assets/lwsgs.js --- libwebsockets-3.2.1/debian/missing-sources/plugins/generic-sessions/assets/lwsgs.js 2018-03-02 18:39:44.000000000 +0000 +++ libwebsockets-4.1.6/debian/missing-sources/plugins/generic-sessions/assets/lwsgs.js 1970-01-01 00:00:00.000000000 +0000 @@ -1,280 +0,0 @@ -/* - * JavaScript MD5 - * https://github.com/blueimp/JavaScript-MD5 - * - * Copyright 2011, Sebastian Tschan - * https://blueimp.net - * - * Licensed under the MIT license: - * https://opensource.org/licenses/MIT - * - * Based on - * A JavaScript implementation of the RSA Data Security, Inc. MD5 Message - * Digest Algorithm, as defined in RFC 1321. - * Version 2.2 Copyright (C) Paul Johnston 1999 - 2009 - * Other contributors: Greg Holt, Andrew Kepert, Ydnar, Lostinet - * Distributed under the BSD License - * See http://pajhome.org.uk/crypt/md5 for more info. - */ - -/* global define */ - -;(function ($) { - 'use strict' - - /* - * Add integers, wrapping at 2^32. This uses 16-bit operations internally - * to work around bugs in some JS interpreters. - */ - function safeAdd (x, y) { - var lsw = (x & 0xffff) + (y & 0xffff) - var msw = (x >> 16) + (y >> 16) + (lsw >> 16) - return (msw << 16) | (lsw & 0xffff) - } - - /* - * Bitwise rotate a 32-bit number to the left. - */ - function bitRotateLeft (num, cnt) { - return (num << cnt) | (num >>> (32 - cnt)) - } - - /* - * These functions implement the four basic operations the algorithm uses. - */ - function md5cmn (q, a, b, x, s, t) { - return safeAdd(bitRotateLeft(safeAdd(safeAdd(a, q), safeAdd(x, t)), s), b) - } - function md5ff (a, b, c, d, x, s, t) { - return md5cmn((b & c) | (~b & d), a, b, x, s, t) - } - function md5gg (a, b, c, d, x, s, t) { - return md5cmn((b & d) | (c & ~d), a, b, x, s, t) - } - function md5hh (a, b, c, d, x, s, t) { - return md5cmn(b ^ c ^ d, a, b, x, s, t) - } - function md5ii (a, b, c, d, x, s, t) { - return md5cmn(c ^ (b | ~d), a, b, x, s, t) - } - - /* - * Calculate the MD5 of an array of little-endian words, and a bit length. - */ - function binlMD5 (x, len) { - /* append padding */ - x[len >> 5] |= 0x80 << (len % 32) - x[((len + 64) >>> 9 << 4) + 14] = len - - var i - var olda - var oldb - var oldc - var oldd - var a = 1732584193 - var b = -271733879 - var c = -1732584194 - var d = 271733878 - - for (i = 0; i < x.length; i += 16) { - olda = a - oldb = b - oldc = c - oldd = d - - a = md5ff(a, b, c, d, x[i], 7, -680876936) - d = md5ff(d, a, b, c, x[i + 1], 12, -389564586) - c = md5ff(c, d, a, b, x[i + 2], 17, 606105819) - b = md5ff(b, c, d, a, x[i + 3], 22, -1044525330) - a = md5ff(a, b, c, d, x[i + 4], 7, -176418897) - d = md5ff(d, a, b, c, x[i + 5], 12, 1200080426) - c = md5ff(c, d, a, b, x[i + 6], 17, -1473231341) - b = md5ff(b, c, d, a, x[i + 7], 22, -45705983) - a = md5ff(a, b, c, d, x[i + 8], 7, 1770035416) - d = md5ff(d, a, b, c, x[i + 9], 12, -1958414417) - c = md5ff(c, d, a, b, x[i + 10], 17, -42063) - b = md5ff(b, c, d, a, x[i + 11], 22, -1990404162) - a = md5ff(a, b, c, d, x[i + 12], 7, 1804603682) - d = md5ff(d, a, b, c, x[i + 13], 12, -40341101) - c = md5ff(c, d, a, b, x[i + 14], 17, -1502002290) - b = md5ff(b, c, d, a, x[i + 15], 22, 1236535329) - - a = md5gg(a, b, c, d, x[i + 1], 5, -165796510) - d = md5gg(d, a, b, c, x[i + 6], 9, -1069501632) - c = md5gg(c, d, a, b, x[i + 11], 14, 643717713) - b = md5gg(b, c, d, a, x[i], 20, -373897302) - a = md5gg(a, b, c, d, x[i + 5], 5, -701558691) - d = md5gg(d, a, b, c, x[i + 10], 9, 38016083) - c = md5gg(c, d, a, b, x[i + 15], 14, -660478335) - b = md5gg(b, c, d, a, x[i + 4], 20, -405537848) - a = md5gg(a, b, c, d, x[i + 9], 5, 568446438) - d = md5gg(d, a, b, c, x[i + 14], 9, -1019803690) - c = md5gg(c, d, a, b, x[i + 3], 14, -187363961) - b = md5gg(b, c, d, a, x[i + 8], 20, 1163531501) - a = md5gg(a, b, c, d, x[i + 13], 5, -1444681467) - d = md5gg(d, a, b, c, x[i + 2], 9, -51403784) - c = md5gg(c, d, a, b, x[i + 7], 14, 1735328473) - b = md5gg(b, c, d, a, x[i + 12], 20, -1926607734) - - a = md5hh(a, b, c, d, x[i + 5], 4, -378558) - d = md5hh(d, a, b, c, x[i + 8], 11, -2022574463) - c = md5hh(c, d, a, b, x[i + 11], 16, 1839030562) - b = md5hh(b, c, d, a, x[i + 14], 23, -35309556) - a = md5hh(a, b, c, d, x[i + 1], 4, -1530992060) - d = md5hh(d, a, b, c, x[i + 4], 11, 1272893353) - c = md5hh(c, d, a, b, x[i + 7], 16, -155497632) - b = md5hh(b, c, d, a, x[i + 10], 23, -1094730640) - a = md5hh(a, b, c, d, x[i + 13], 4, 681279174) - d = md5hh(d, a, b, c, x[i], 11, -358537222) - c = md5hh(c, d, a, b, x[i + 3], 16, -722521979) - b = md5hh(b, c, d, a, x[i + 6], 23, 76029189) - a = md5hh(a, b, c, d, x[i + 9], 4, -640364487) - d = md5hh(d, a, b, c, x[i + 12], 11, -421815835) - c = md5hh(c, d, a, b, x[i + 15], 16, 530742520) - b = md5hh(b, c, d, a, x[i + 2], 23, -995338651) - - a = md5ii(a, b, c, d, x[i], 6, -198630844) - d = md5ii(d, a, b, c, x[i + 7], 10, 1126891415) - c = md5ii(c, d, a, b, x[i + 14], 15, -1416354905) - b = md5ii(b, c, d, a, x[i + 5], 21, -57434055) - a = md5ii(a, b, c, d, x[i + 12], 6, 1700485571) - d = md5ii(d, a, b, c, x[i + 3], 10, -1894986606) - c = md5ii(c, d, a, b, x[i + 10], 15, -1051523) - b = md5ii(b, c, d, a, x[i + 1], 21, -2054922799) - a = md5ii(a, b, c, d, x[i + 8], 6, 1873313359) - d = md5ii(d, a, b, c, x[i + 15], 10, -30611744) - c = md5ii(c, d, a, b, x[i + 6], 15, -1560198380) - b = md5ii(b, c, d, a, x[i + 13], 21, 1309151649) - a = md5ii(a, b, c, d, x[i + 4], 6, -145523070) - d = md5ii(d, a, b, c, x[i + 11], 10, -1120210379) - c = md5ii(c, d, a, b, x[i + 2], 15, 718787259) - b = md5ii(b, c, d, a, x[i + 9], 21, -343485551) - - a = safeAdd(a, olda) - b = safeAdd(b, oldb) - c = safeAdd(c, oldc) - d = safeAdd(d, oldd) - } - return [a, b, c, d] - } - - /* - * Convert an array of little-endian words to a string - */ - function binl2rstr (input) { - var i - var output = '' - var length32 = input.length * 32 - for (i = 0; i < length32; i += 8) { - output += String.fromCharCode((input[i >> 5] >>> (i % 32)) & 0xff) - } - return output - } - - /* - * Convert a raw string to an array of little-endian words - * Characters >255 have their high-byte silently ignored. - */ - function rstr2binl (input) { - var i - var output = [] - output[(input.length >> 2) - 1] = undefined - for (i = 0; i < output.length; i += 1) { - output[i] = 0 - } - var length8 = input.length * 8 - for (i = 0; i < length8; i += 8) { - output[i >> 5] |= (input.charCodeAt(i / 8) & 0xff) << (i % 32) - } - return output - } - - /* - * Calculate the MD5 of a raw string - */ - function rstrMD5 (s) { - return binl2rstr(binlMD5(rstr2binl(s), s.length * 8)) - } - - /* - * Calculate the HMAC-MD5, of a key and some data (raw strings) - */ - function rstrHMACMD5 (key, data) { - var i - var bkey = rstr2binl(key) - var ipad = [] - var opad = [] - var hash - ipad[15] = opad[15] = undefined - if (bkey.length > 16) { - bkey = binlMD5(bkey, key.length * 8) - } - for (i = 0; i < 16; i += 1) { - ipad[i] = bkey[i] ^ 0x36363636 - opad[i] = bkey[i] ^ 0x5c5c5c5c - } - hash = binlMD5(ipad.concat(rstr2binl(data)), 512 + data.length * 8) - return binl2rstr(binlMD5(opad.concat(hash), 512 + 128)) - } - - /* - * Convert a raw string to a hex string - */ - function rstr2hex (input) { - var hexTab = '0123456789abcdef' - var output = '' - var x - var i - for (i = 0; i < input.length; i += 1) { - x = input.charCodeAt(i) - output += hexTab.charAt((x >>> 4) & 0x0f) + hexTab.charAt(x & 0x0f) - } - return output - } - - /* - * Encode a string as utf-8 - */ - function str2rstrUTF8 (input) { - return unescape(encodeURIComponent(input)) - } - - /* - * Take string arguments and return either raw or hex encoded strings - */ - function rawMD5 (s) { - return rstrMD5(str2rstrUTF8(s)) - } - function hexMD5 (s) { - return rstr2hex(rawMD5(s)) - } - function rawHMACMD5 (k, d) { - return rstrHMACMD5(str2rstrUTF8(k), str2rstrUTF8(d)) - } - function hexHMACMD5 (k, d) { - return rstr2hex(rawHMACMD5(k, d)) - } - - function md5 (string, key, raw) { - if (!key) { - if (!raw) { - return hexMD5(string) - } - return rawMD5(string) - } - if (!raw) { - return hexHMACMD5(key, string) - } - return rawHMACMD5(key, string) - } - - if (typeof define === 'function' && define.amd) { - define(function () { - return md5 - }) - } else if (typeof module === 'object' && module.exports) { - module.exports = md5 - } else { - $.md5 = md5 - } -})(this) diff -Nru libwebsockets-3.2.1/debian/missing-sources/plugins/generic-sessions/assets/md5.js libwebsockets-4.1.6/debian/missing-sources/plugins/generic-sessions/assets/md5.js --- libwebsockets-3.2.1/debian/missing-sources/plugins/generic-sessions/assets/md5.js 2018-03-02 18:39:44.000000000 +0000 +++ libwebsockets-4.1.6/debian/missing-sources/plugins/generic-sessions/assets/md5.js 1970-01-01 00:00:00.000000000 +0000 @@ -1,280 +0,0 @@ -/* - * JavaScript MD5 - * https://github.com/blueimp/JavaScript-MD5 - * - * Copyright 2011, Sebastian Tschan - * https://blueimp.net - * - * Licensed under the MIT license: - * https://opensource.org/licenses/MIT - * - * Based on - * A JavaScript implementation of the RSA Data Security, Inc. MD5 Message - * Digest Algorithm, as defined in RFC 1321. - * Version 2.2 Copyright (C) Paul Johnston 1999 - 2009 - * Other contributors: Greg Holt, Andrew Kepert, Ydnar, Lostinet - * Distributed under the BSD License - * See http://pajhome.org.uk/crypt/md5 for more info. - */ - -/* global define */ - -;(function ($) { - 'use strict' - - /* - * Add integers, wrapping at 2^32. This uses 16-bit operations internally - * to work around bugs in some JS interpreters. - */ - function safeAdd (x, y) { - var lsw = (x & 0xffff) + (y & 0xffff) - var msw = (x >> 16) + (y >> 16) + (lsw >> 16) - return (msw << 16) | (lsw & 0xffff) - } - - /* - * Bitwise rotate a 32-bit number to the left. - */ - function bitRotateLeft (num, cnt) { - return (num << cnt) | (num >>> (32 - cnt)) - } - - /* - * These functions implement the four basic operations the algorithm uses. - */ - function md5cmn (q, a, b, x, s, t) { - return safeAdd(bitRotateLeft(safeAdd(safeAdd(a, q), safeAdd(x, t)), s), b) - } - function md5ff (a, b, c, d, x, s, t) { - return md5cmn((b & c) | (~b & d), a, b, x, s, t) - } - function md5gg (a, b, c, d, x, s, t) { - return md5cmn((b & d) | (c & ~d), a, b, x, s, t) - } - function md5hh (a, b, c, d, x, s, t) { - return md5cmn(b ^ c ^ d, a, b, x, s, t) - } - function md5ii (a, b, c, d, x, s, t) { - return md5cmn(c ^ (b | ~d), a, b, x, s, t) - } - - /* - * Calculate the MD5 of an array of little-endian words, and a bit length. - */ - function binlMD5 (x, len) { - /* append padding */ - x[len >> 5] |= 0x80 << (len % 32) - x[((len + 64) >>> 9 << 4) + 14] = len - - var i - var olda - var oldb - var oldc - var oldd - var a = 1732584193 - var b = -271733879 - var c = -1732584194 - var d = 271733878 - - for (i = 0; i < x.length; i += 16) { - olda = a - oldb = b - oldc = c - oldd = d - - a = md5ff(a, b, c, d, x[i], 7, -680876936) - d = md5ff(d, a, b, c, x[i + 1], 12, -389564586) - c = md5ff(c, d, a, b, x[i + 2], 17, 606105819) - b = md5ff(b, c, d, a, x[i + 3], 22, -1044525330) - a = md5ff(a, b, c, d, x[i + 4], 7, -176418897) - d = md5ff(d, a, b, c, x[i + 5], 12, 1200080426) - c = md5ff(c, d, a, b, x[i + 6], 17, -1473231341) - b = md5ff(b, c, d, a, x[i + 7], 22, -45705983) - a = md5ff(a, b, c, d, x[i + 8], 7, 1770035416) - d = md5ff(d, a, b, c, x[i + 9], 12, -1958414417) - c = md5ff(c, d, a, b, x[i + 10], 17, -42063) - b = md5ff(b, c, d, a, x[i + 11], 22, -1990404162) - a = md5ff(a, b, c, d, x[i + 12], 7, 1804603682) - d = md5ff(d, a, b, c, x[i + 13], 12, -40341101) - c = md5ff(c, d, a, b, x[i + 14], 17, -1502002290) - b = md5ff(b, c, d, a, x[i + 15], 22, 1236535329) - - a = md5gg(a, b, c, d, x[i + 1], 5, -165796510) - d = md5gg(d, a, b, c, x[i + 6], 9, -1069501632) - c = md5gg(c, d, a, b, x[i + 11], 14, 643717713) - b = md5gg(b, c, d, a, x[i], 20, -373897302) - a = md5gg(a, b, c, d, x[i + 5], 5, -701558691) - d = md5gg(d, a, b, c, x[i + 10], 9, 38016083) - c = md5gg(c, d, a, b, x[i + 15], 14, -660478335) - b = md5gg(b, c, d, a, x[i + 4], 20, -405537848) - a = md5gg(a, b, c, d, x[i + 9], 5, 568446438) - d = md5gg(d, a, b, c, x[i + 14], 9, -1019803690) - c = md5gg(c, d, a, b, x[i + 3], 14, -187363961) - b = md5gg(b, c, d, a, x[i + 8], 20, 1163531501) - a = md5gg(a, b, c, d, x[i + 13], 5, -1444681467) - d = md5gg(d, a, b, c, x[i + 2], 9, -51403784) - c = md5gg(c, d, a, b, x[i + 7], 14, 1735328473) - b = md5gg(b, c, d, a, x[i + 12], 20, -1926607734) - - a = md5hh(a, b, c, d, x[i + 5], 4, -378558) - d = md5hh(d, a, b, c, x[i + 8], 11, -2022574463) - c = md5hh(c, d, a, b, x[i + 11], 16, 1839030562) - b = md5hh(b, c, d, a, x[i + 14], 23, -35309556) - a = md5hh(a, b, c, d, x[i + 1], 4, -1530992060) - d = md5hh(d, a, b, c, x[i + 4], 11, 1272893353) - c = md5hh(c, d, a, b, x[i + 7], 16, -155497632) - b = md5hh(b, c, d, a, x[i + 10], 23, -1094730640) - a = md5hh(a, b, c, d, x[i + 13], 4, 681279174) - d = md5hh(d, a, b, c, x[i], 11, -358537222) - c = md5hh(c, d, a, b, x[i + 3], 16, -722521979) - b = md5hh(b, c, d, a, x[i + 6], 23, 76029189) - a = md5hh(a, b, c, d, x[i + 9], 4, -640364487) - d = md5hh(d, a, b, c, x[i + 12], 11, -421815835) - c = md5hh(c, d, a, b, x[i + 15], 16, 530742520) - b = md5hh(b, c, d, a, x[i + 2], 23, -995338651) - - a = md5ii(a, b, c, d, x[i], 6, -198630844) - d = md5ii(d, a, b, c, x[i + 7], 10, 1126891415) - c = md5ii(c, d, a, b, x[i + 14], 15, -1416354905) - b = md5ii(b, c, d, a, x[i + 5], 21, -57434055) - a = md5ii(a, b, c, d, x[i + 12], 6, 1700485571) - d = md5ii(d, a, b, c, x[i + 3], 10, -1894986606) - c = md5ii(c, d, a, b, x[i + 10], 15, -1051523) - b = md5ii(b, c, d, a, x[i + 1], 21, -2054922799) - a = md5ii(a, b, c, d, x[i + 8], 6, 1873313359) - d = md5ii(d, a, b, c, x[i + 15], 10, -30611744) - c = md5ii(c, d, a, b, x[i + 6], 15, -1560198380) - b = md5ii(b, c, d, a, x[i + 13], 21, 1309151649) - a = md5ii(a, b, c, d, x[i + 4], 6, -145523070) - d = md5ii(d, a, b, c, x[i + 11], 10, -1120210379) - c = md5ii(c, d, a, b, x[i + 2], 15, 718787259) - b = md5ii(b, c, d, a, x[i + 9], 21, -343485551) - - a = safeAdd(a, olda) - b = safeAdd(b, oldb) - c = safeAdd(c, oldc) - d = safeAdd(d, oldd) - } - return [a, b, c, d] - } - - /* - * Convert an array of little-endian words to a string - */ - function binl2rstr (input) { - var i - var output = '' - var length32 = input.length * 32 - for (i = 0; i < length32; i += 8) { - output += String.fromCharCode((input[i >> 5] >>> (i % 32)) & 0xff) - } - return output - } - - /* - * Convert a raw string to an array of little-endian words - * Characters >255 have their high-byte silently ignored. - */ - function rstr2binl (input) { - var i - var output = [] - output[(input.length >> 2) - 1] = undefined - for (i = 0; i < output.length; i += 1) { - output[i] = 0 - } - var length8 = input.length * 8 - for (i = 0; i < length8; i += 8) { - output[i >> 5] |= (input.charCodeAt(i / 8) & 0xff) << (i % 32) - } - return output - } - - /* - * Calculate the MD5 of a raw string - */ - function rstrMD5 (s) { - return binl2rstr(binlMD5(rstr2binl(s), s.length * 8)) - } - - /* - * Calculate the HMAC-MD5, of a key and some data (raw strings) - */ - function rstrHMACMD5 (key, data) { - var i - var bkey = rstr2binl(key) - var ipad = [] - var opad = [] - var hash - ipad[15] = opad[15] = undefined - if (bkey.length > 16) { - bkey = binlMD5(bkey, key.length * 8) - } - for (i = 0; i < 16; i += 1) { - ipad[i] = bkey[i] ^ 0x36363636 - opad[i] = bkey[i] ^ 0x5c5c5c5c - } - hash = binlMD5(ipad.concat(rstr2binl(data)), 512 + data.length * 8) - return binl2rstr(binlMD5(opad.concat(hash), 512 + 128)) - } - - /* - * Convert a raw string to a hex string - */ - function rstr2hex (input) { - var hexTab = '0123456789abcdef' - var output = '' - var x - var i - for (i = 0; i < input.length; i += 1) { - x = input.charCodeAt(i) - output += hexTab.charAt((x >>> 4) & 0x0f) + hexTab.charAt(x & 0x0f) - } - return output - } - - /* - * Encode a string as utf-8 - */ - function str2rstrUTF8 (input) { - return unescape(encodeURIComponent(input)) - } - - /* - * Take string arguments and return either raw or hex encoded strings - */ - function rawMD5 (s) { - return rstrMD5(str2rstrUTF8(s)) - } - function hexMD5 (s) { - return rstr2hex(rawMD5(s)) - } - function rawHMACMD5 (k, d) { - return rstrHMACMD5(str2rstrUTF8(k), str2rstrUTF8(d)) - } - function hexHMACMD5 (k, d) { - return rstr2hex(rawHMACMD5(k, d)) - } - - function md5 (string, key, raw) { - if (!key) { - if (!raw) { - return hexMD5(string) - } - return rawMD5(string) - } - if (!raw) { - return hexHMACMD5(key, string) - } - return rawHMACMD5(key, string) - } - - if (typeof define === 'function' && define.amd) { - define(function () { - return md5 - }) - } else if (typeof module === 'object' && module.exports) { - module.exports = md5 - } else { - $.md5 = md5 - } -})(this) diff -Nru libwebsockets-3.2.1/debian/patches/add-missing-headers.patch libwebsockets-4.1.6/debian/patches/add-missing-headers.patch --- libwebsockets-3.2.1/debian/patches/add-missing-headers.patch 1970-01-01 00:00:00.000000000 +0000 +++ libwebsockets-4.1.6/debian/patches/add-missing-headers.patch 2020-09-07 23:12:45.000000000 +0000 @@ -0,0 +1,47 @@ +Description: + TODO: Put a short summary on the line above and replace this paragraph + with a longer explanation of this change. Complete the meta-information + with other relevant fields (see below for details). To make it easier, the + information below has been extracted from the changelog. Adjust it or drop + it. + . + libwebsockets (4.1.0-1) unstable; urgency=medium + . + * New upstream release. + * Library transition from libwebsockets16 to libwebsockets17 . + * Update library symbols for this release. +Author: Laszlo Boszormenyi (GCS) + +--- +The information above should follow the Patch Tagging Guidelines, please +checkout http://dep.debian.net/deps/dep3/ to learn about the format. Here +are templates for supplementary fields that you might want to add: + +Origin: , +Bug: +Bug-Debian: https://bugs.debian.org/ +Bug-Ubuntu: https://launchpad.net/bugs/ +Forwarded: +Reviewed-By: +Last-Update: 2020-09-08 + +--- libwebsockets-4.1.0.orig/plugins/protocol_lws_raw_test.c ++++ libwebsockets-4.1.0/plugins/protocol_lws_raw_test.c +@@ -73,6 +73,7 @@ + + #include + #include ++#include + + struct per_vhost_data__raw_test { + struct lws_context *context; +--- libwebsockets-4.1.0.orig/plugins/protocol_lws_sshd_demo.c ++++ libwebsockets-4.1.0/plugins/protocol_lws_sshd_demo.c +@@ -29,6 +29,7 @@ + #include + #include + #include ++#include + + #define TEST_SERVER_KEY_PATH "/etc/lws-test-sshd-server-key" + diff -Nru libwebsockets-3.2.1/debian/patches/f9d1f25abe896b9fa1de780e4a5cb41116926a29.patch libwebsockets-4.1.6/debian/patches/f9d1f25abe896b9fa1de780e4a5cb41116926a29.patch --- libwebsockets-3.2.1/debian/patches/f9d1f25abe896b9fa1de780e4a5cb41116926a29.patch 1970-01-01 00:00:00.000000000 +0000 +++ libwebsockets-4.1.6/debian/patches/f9d1f25abe896b9fa1de780e4a5cb41116926a29.patch 2023-07-20 15:27:19.000000000 +0000 @@ -0,0 +1,30 @@ +From f9d1f25abe896b9fa1de780e4a5cb41116926a29 Mon Sep 17 00:00:00 2001 +From: Andy Green +Date: Wed, 14 Jun 2023 07:14:23 +0100 +Subject: [PATCH] openssl-server: enum vs int disagreement + +https://github.com/warmcat/libwebsockets/issues/2907 +--- + lib/tls/openssl/openssl-server.c | 4 ++-- + 1 file changed, 2 insertions(+), 2 deletions(-) + +diff --git a/lib/tls/openssl/openssl-server.c b/lib/tls/openssl/openssl-server.c +index f2e77324f..1fc819293 100644 +--- a/lib/tls/openssl/openssl-server.c ++++ b/lib/tls/openssl/openssl-server.c +@@ -607,13 +607,13 @@ lws_tls_server_new_nonblocking(struct lw + return 0; + } + +-int ++enum lws_ssl_capable_status + lws_tls_server_abort_connection(struct lws *wsi) + { + SSL_shutdown(wsi->tls.ssl); + SSL_free(wsi->tls.ssl); + +- return 0; ++ return LWS_SSL_CAPABLE_DONE; + } + + enum lws_ssl_capable_status diff -Nru libwebsockets-3.2.1/debian/patches/series libwebsockets-4.1.6/debian/patches/series --- libwebsockets-3.2.1/debian/patches/series 2019-10-13 14:23:13.000000000 +0000 +++ libwebsockets-4.1.6/debian/patches/series 2023-07-20 15:27:19.000000000 +0000 @@ -1,2 +1,4 @@ #echo-actually-exit.patch #echo-off-by-one.patch +#add-missing-headers.patch +f9d1f25abe896b9fa1de780e4a5cb41116926a29.patch diff -Nru libwebsockets-3.2.1/debian/rules libwebsockets-4.1.6/debian/rules --- libwebsockets-3.2.1/debian/rules 2019-12-28 10:13:56.000000000 +0000 +++ libwebsockets-4.1.6/debian/rules 2022-08-06 05:42:00.000000000 +0000 @@ -10,9 +10,7 @@ DEB_BUILD_MAINT_OPTIONS= hardening=+all future=+lfs export DEB_BUILD_MAINT_OPTIONS -# TODO: remove -Wno-error=format-truncation and -Wno-error=format-overflow on -# next upstream release -DEB_CFLAGS_MAINT_APPEND= -fno-strict-aliasing -Wno-error=format-truncation -Wno-error=format-overflow +DEB_CFLAGS_MAINT_APPEND= -Wno-error=deprecated-declarations -fno-strict-aliasing export DEB_CFLAGS_MAINT_APPEND arch?= $(shell dpkg-architecture -qDEB_HOST_MULTIARCH) @@ -24,7 +22,9 @@ dh_auto_configure -- -DCMAKE_LIBRARY_ARCHITECTURE=${arch} \ -DLIB_SUFFIX=/${arch} -DLWS_WITHOUT_DAEMONIZE=OFF \ -DLWS_WITH_LIBEV=ON -DLWS_WITH_LIBUV=ON \ - -DLWS_UNIX_SOCK=ON -DLWS_IPV6=ON + -DLWS_UNIX_SOCK=ON -DLWS_IPV6=ON \ + -DLWS_WITH_ZLIB=ON -DLWS_WITHOUT_EXTENSIONS=OFF \ + -DLWS_WITH_GLIB=ON override_dh_install-arch: $(RM) $(CURDIR)/debian/tmp/usr/lib/${arch}/pkgconfig/libwebsockets_static.pc diff -Nru libwebsockets-3.2.1/debian/source/lintian-overrides libwebsockets-4.1.6/debian/source/lintian-overrides --- libwebsockets-3.2.1/debian/source/lintian-overrides 2019-10-13 14:23:13.000000000 +0000 +++ libwebsockets-4.1.6/debian/source/lintian-overrides 2022-08-06 05:42:00.000000000 +0000 @@ -1,5 +1,3 @@ # long lines or unused, uninstalled file -source-is-missing test-apps/test.js line length is 1767 characters (>512) -source-is-missing minimal-examples/http-server/minimal-http-server-eventlib-demos/mount-origin/test.js line length is 1767 characters (>512) -source-is-missing minimal-examples/http-server/minimal-http-server-generic-sessions/mount-origin/lwsgs.js line length is 3836 characters (>512) -source-is-missing minimal-examples/http-server/minimal-http-server-generic-sessions/mount-origin/md5.min.js +source-is-missing [minimal-examples/http-server/minimal-http-server-eventlib-demos/mount-origin/test.js] +source-is-missing [test-apps/test.js] diff -Nru libwebsockets-3.2.1/debian/tests/t/01-build.t libwebsockets-4.1.6/debian/tests/t/01-build.t --- libwebsockets-3.2.1/debian/tests/t/01-build.t 2018-03-02 18:39:44.000000000 +0000 +++ libwebsockets-4.1.6/debian/tests/t/01-build.t 2022-08-07 08:43:01.000000000 +0000 @@ -38,7 +38,7 @@ my ($out, $err) = get_program_output [$pc, '--modversion', '--', $mod]; my @lines = split /\r*\n/, $out; is @lines, 1, "'$pc --modversion $mod' output a single line"; - like $lines[0], qr/^ (?: \d+ ) (?: \. \d+ )* $/x, + like $lines[0], qr/^ (?: \d+ ) (?: \. \d+-? )* $/x, "'$pc --modversion $mod' output a version-number-like string"; $lws_version = $lines[0]; @@ -74,6 +74,6 @@ my ($out, $err) = get_program_output [$bin]; my @lines = split /\r*\n/, $out; is @lines, 1, 'The test program output a single line'; - like $lines[0], qr/^ \Q$lws_version\E \b /x, + like $lines[0], qr/^ \Q$lws_version\E /x, 'The test program output the correct library version'; }; Binary files /tmp/tmp2l8bmswe/3lv7Sxvgkv/libwebsockets-3.2.1/doc-assets/lws-detailed-latency-example.png and /tmp/tmp2l8bmswe/LwTwoWz49Q/libwebsockets-4.1.6/doc-assets/lws-detailed-latency-example.png differ Binary files /tmp/tmp2l8bmswe/3lv7Sxvgkv/libwebsockets-3.2.1/doc-assets/lws-overview.png and /tmp/tmp2l8bmswe/LwTwoWz49Q/libwebsockets-4.1.6/doc-assets/lws-overview.png differ Binary files /tmp/tmp2l8bmswe/3lv7Sxvgkv/libwebsockets-3.2.1/doc-assets/ss-explain.png and /tmp/tmp2l8bmswe/LwTwoWz49Q/libwebsockets-4.1.6/doc-assets/ss-explain.png differ Binary files /tmp/tmp2l8bmswe/3lv7Sxvgkv/libwebsockets-3.2.1/doc-assets/ss-operation-modes.png and /tmp/tmp2l8bmswe/LwTwoWz49Q/libwebsockets-4.1.6/doc-assets/ss-operation-modes.png differ Binary files /tmp/tmp2l8bmswe/3lv7Sxvgkv/libwebsockets-3.2.1/doc-assets/ss-state-flow.png and /tmp/tmp2l8bmswe/LwTwoWz49Q/libwebsockets-4.1.6/doc-assets/ss-state-flow.png differ Binary files /tmp/tmp2l8bmswe/3lv7Sxvgkv/libwebsockets-3.2.1/doc-assets/ss-state-flow-server.png and /tmp/tmp2l8bmswe/LwTwoWz49Q/libwebsockets-4.1.6/doc-assets/ss-state-flow-server.png differ diff -Nru libwebsockets-3.2.1/.gitignore libwebsockets-4.1.6/.gitignore --- libwebsockets-3.2.1/.gitignore 2019-12-18 14:45:31.000000000 +0000 +++ libwebsockets-4.1.6/.gitignore 2020-12-01 17:40:26.000000000 +0000 @@ -55,3 +55,10 @@ /build-mingw64/ /n9/ /bb/ +/openssl3/ +/bb-linkit/ +/bq/ +/cros/ +/q/ +/b1/ +/destdir/ diff -Nru libwebsockets-3.2.1/include/libwebsockets/abstract/abstract.h libwebsockets-4.1.6/include/libwebsockets/abstract/abstract.h --- libwebsockets-3.2.1/include/libwebsockets/abstract/abstract.h 2019-12-18 14:45:31.000000000 +0000 +++ libwebsockets-4.1.6/include/libwebsockets/abstract/abstract.h 2020-12-01 17:40:26.000000000 +0000 @@ -1,22 +1,25 @@ /* - * libwebsockets - abstract top level header + * libwebsockets - small server side websockets and web server implementation * - * Copyright (C) 2019 Andy Green + * Copyright (C) 2010 - 2019 Andy Green * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation: - * version 2.1 of the License. - * - * This library is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with this library; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, - * MA 02110-1301 USA + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to + * deal in the Software without restriction, including without limitation the + * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or + * sell copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS + * IN THE SOFTWARE. */ /* @@ -39,8 +42,7 @@ /* * The indvidual protocols and transports define their own name_index-es which * are meaningful to them. Define index 0 globally as the end of an array of - * them, and separate the ones used for protocols and transport so we can - * sanity check they are at least in the correct category. + * them, and provide bases so user protocol and transport ones don't overlap. */ enum { @@ -53,6 +55,7 @@ struct lws_abs_transport; struct lws_abs_protocol; +typedef struct lws_abs lws_abs_t; LWS_VISIBLE LWS_EXTERN const lws_token_map_t * lws_abs_get_token(const lws_token_map_t *token_map, short name_index); @@ -64,28 +67,40 @@ typedef void lws_abs_transport_inst_t; typedef void lws_abs_protocol_inst_t; -typedef struct lws_abs { - void *user; - struct lws_vhost *vh; - - const struct lws_abs_protocol *ap; - const lws_token_map_t *ap_tokens; - const struct lws_abs_transport *at; - const lws_token_map_t *at_tokens; - - lws_seq_t *seq; - void *opaque_user_data; - - /* - * These are filled in by lws_abs_bind_and_create_instance() in the - * instance copy. They do not need to be set when creating the struct - * for use by lws_abs_bind_and_create_instance() - */ - - struct lws_dll2 abstract_instances; - lws_abs_transport_inst_t *ati; - lws_abs_protocol_inst_t *api; -} lws_abs_t; +/** + * lws_abstract_alloc() - allocate and configure an lws_abs_t + * + * \param vhost: the struct lws_vhost to bind to + * \param user: opaque user pointer + * \param abstract_path: "protocol.transport" names + * \param ap_tokens: tokens for protocol options + * \param at_tokens: tokens for transport + * \param seq: optional sequencer we should bind to, or NULL + * \param opaque_user_data: data given in sequencer callback, if any + * + * Returns an allocated lws_abs_t pointer set up with the other arguments. + * + * Doesn't create a connection instance, just allocates the lws_abs_t and + * sets it up with the arguments. + * + * Returns NULL is there's any problem. + */ +LWS_VISIBLE LWS_EXTERN lws_abs_t * +lws_abstract_alloc(struct lws_vhost *vhost, void *user, + const char *abstract_path, const lws_token_map_t *ap_tokens, + const lws_token_map_t *at_tokens, struct lws_sequencer *seq, + void *opaque_user_data); + +/** + * lws_abstract_free() - free an allocated lws_abs_t + * + * \param pabs: pointer to the lws_abs_t * to free + * + * Frees and sets the pointer to NULL. + */ + +LWS_VISIBLE LWS_EXTERN void +lws_abstract_free(lws_abs_t **pabs); /** * lws_abs_bind_and_create_instance - use an abstract protocol and transport diff -Nru libwebsockets-3.2.1/include/libwebsockets/abstract/protocols/smtp.h libwebsockets-4.1.6/include/libwebsockets/abstract/protocols/smtp.h --- libwebsockets-3.2.1/include/libwebsockets/abstract/protocols/smtp.h 2019-12-18 14:45:31.000000000 +0000 +++ libwebsockets-4.1.6/include/libwebsockets/abstract/protocols/smtp.h 2020-12-01 17:40:26.000000000 +0000 @@ -1,24 +1,25 @@ /* * libwebsockets - small server side websockets and web server implementation * - * Copyright (C) 2010-2019 Andy Green + * Copyright (C) 2010 - 2019 Andy Green * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation: - * version 2.1 of the License. - * - * This library is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with this library; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, - * MA 02110-1301 USA - * - * included from libwebsockets.h + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to + * deal in the Software without restriction, including without limitation the + * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or + * sell copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS + * IN THE SOFTWARE. */ /** \defgroup smtp SMTP related functions @@ -32,65 +33,57 @@ * 25 and able to send email using the "mail" commandline app. Usually distro * MTAs are configured for this by default. * - * It runs via its own libuv events if initialized (which requires giving it - * a libuv loop to attach to). - * - * It operates using three callbacks, on_next() queries if there is a new email - * to send, on_get_body() asks for the body of the email, and on_sent() is - * called after the email is successfully sent. - * - * To use it - * - * - create an lws_email struct - * - * - initialize data, loop, the email_* strings, max_content_size and - * the callbacks - * - * - call lws_email_init() - * - * When you have at least one email to send, call lws_email_check() to - * schedule starting to send it. + * You can either use the abstract protocol layer directly, or instead use the + * provided smtp sequencer... this takes care of creating the protocol + * connections, and provides and email queue and retry management. */ //@{ + #if defined(LWS_WITH_SMTP) enum { LTMI_PSMTP_V_HELO = LTMI_PROTOCOL_BASE, /* u.value */ - LTMI_PSMTP_LV_RETRY_INTERVAL, /* u.lvalue */ - LTMI_PSMTP_LV_DELIVERY_TIMEOUT, /* u.lvalue */ - LTMI_PSMTP_LV_EMAIL_QUEUE_MAX, /* u.lvalue */ - LTMI_PSMTP_LV_MAX_CONTENT_SIZE, /* u.lvalue */ -}; - -typedef struct lws_smtp_client lws_smtp_client_t; -typedef struct lws_abs lws_abs_t; -typedef struct lws_smtp_email { - struct lws_dll2 list; + LTMI_PSMTP_V_LWS_SMTP_EMAIL_T, /* u.value */ +}; - void *data; - void *extra; +enum { + LWS_SMTP_DISPOSITION_SENT, + LWS_SMTP_DISPOSITION_FAILED, + LWS_SMTP_DISPOSITION_FAILED_DESTROY +}; - time_t added; - time_t last_try; +typedef struct lws_smtp_sequencer_args { + const char helo[32]; + struct lws_vhost *vhost; + time_t retry_interval; + time_t delivery_timeout; + size_t email_queue_max; + size_t max_content_size; +} lws_smtp_sequencer_args_t; - const char *email_from; - const char *email_to; - const char *payload; +typedef struct lws_smtp_sequencer lws_smtp_sequencer_t; +typedef struct lws_smtp_email lws_smtp_email_t; - int (*done)(struct lws_smtp_email *e, void *buf, size_t len); +LWS_VISIBLE LWS_EXTERN lws_smtp_sequencer_t * +lws_smtp_sequencer_create(const lws_smtp_sequencer_args_t *args); - int tries; -} lws_smtp_email_t; +LWS_VISIBLE LWS_EXTERN void +lws_smtp_sequencer_destroy(lws_smtp_sequencer_t *s); +typedef int (*lws_smtp_cb_t)(void *e, void *d, int disp, const void *b, size_t l); +typedef struct lws_smtp_email lws_smtp_email_t; /** - * lws_smtp_client_alloc_email_helper() - Allocates and inits an email object + * lws_smtpc_add_email() - Allocates and queues an email object * + * \param s: smtp sequencer to queue on * \param payload: the email payload string, with headers and terminating . * \param payload_len: size in bytes of the payload string * \param sender: the sender name and email * \param recipient: the recipient name and email + * \param data: opaque user data returned in the done callback + * \param done: callback called when the email send succeeded or failed * * Allocates an email object and copies the payload, sender and recipient into * it and initializes it. Returns NULL if OOM, otherwise the allocated email @@ -102,33 +95,21 @@ * The done() callback must free the email object. It doesn't have to free any * individual members. */ -LWS_VISIBLE LWS_EXTERN lws_smtp_email_t * -lws_smtp_client_alloc_email_helper(const char *payload, size_t payload_len, - const char *sender, const char *recipient, - const char *extra, size_t extra_len, void *data, - int (*done)(struct lws_smtp_email *e, - void *buf, size_t len)); +LWS_VISIBLE LWS_EXTERN int +lws_smtpc_add_email(lws_smtp_sequencer_t *s, const char *payload, + size_t payload_len, const char *sender, + const char *recipient, void *data, lws_smtp_cb_t done); /** - * lws_smtp_client_add_email() - Add email to the list of ones being sent + * lws_smtpc_free_email() - Add email to the list of ones being sent * - * \param instance: smtp client + transport * \param e: email to queue for sending on \p c * * Adds an email to the linked-list of emails to send */ LWS_VISIBLE LWS_EXTERN int -lws_smtp_client_add_email(lws_abs_t *instance, lws_smtp_email_t *e); +lws_smtpc_free_email(lws_smtp_email_t *e); -/** - * lws_smtp_client_kick() - Request check for new email - * - * \param instance: instance to kick - * - * Gives smtp client a chance to move things on - */ -LWS_VISIBLE LWS_EXTERN void -lws_smtp_client_kick(lws_abs_t *instance); #endif //@} diff -Nru libwebsockets-3.2.1/include/libwebsockets/abstract/protocols.h libwebsockets-4.1.6/include/libwebsockets/abstract/protocols.h --- libwebsockets-3.2.1/include/libwebsockets/abstract/protocols.h 2019-12-18 14:45:31.000000000 +0000 +++ libwebsockets-4.1.6/include/libwebsockets/abstract/protocols.h 2020-12-01 17:40:26.000000000 +0000 @@ -1,38 +1,72 @@ /* - * libwebsockets - abstract protocol definitions + * libwebsockets - small server side websockets and web server implementation * - * Copyright (C) 2019 Andy Green + * Copyright (C) 2010 - 2019 Andy Green * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation: - * version 2.1 of the License. - * - * This library is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with this library; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, - * MA 02110-1301 USA + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to + * deal in the Software without restriction, including without limitation the + * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or + * sell copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS + * IN THE SOFTWARE. */ +/* + * Information about how this protocol handles multiple use of connections. + * + * .flags of 0 indicates each connection must start with a fresh transport. + * + * Flags can be used to indicate the protocol itself supports different + * kinds of multiple use. However the actual use or not of these may depend on + * negotiation with the remote peer. + * + * LWS_AP_FLAG_PIPELINE_TRANSACTIONS: other instances can be queued on one + * with an existing connection and get a + * chance to "hot take over" the existing + * transport in turn, like h1 keepalive + * pipelining + * + * LWS_AP_FLAG_MUXABLE_STREAM: an existing connection can absorb more child + * connections and mux them as separate child + * streams ongoing, like h2 + */ + +enum { + LWS_AP_FLAG_PIPELINE_TRANSACTIONS = (1 << 0), + LWS_AP_FLAG_MUXABLE_STREAM = (1 << 1), +}; + typedef struct lws_abs_protocol { const char *name; int alloc; + int flags; - int (*create)(const struct lws_abs *ai); - void (*destroy)(lws_abs_protocol_inst_t **d); + int (*create)(const struct lws_abs *ai); + void (*destroy)(lws_abs_protocol_inst_t **d); + int (*compare)(lws_abs_t *abs1, lws_abs_t *abs2); /* events the transport invokes (handled by abstract protocol) */ - int (*accept)(lws_abs_protocol_inst_t *d); - int (*rx)(lws_abs_protocol_inst_t *d, uint8_t *buf, size_t len); - int (*writeable)(lws_abs_protocol_inst_t *d, size_t budget); - int (*closed)(lws_abs_protocol_inst_t *d); - int (*heartbeat)(lws_abs_protocol_inst_t *d); + int (*accept)(lws_abs_protocol_inst_t *d); + int (*rx)(lws_abs_protocol_inst_t *d, const uint8_t *b, size_t l); + int (*writeable)(lws_abs_protocol_inst_t *d, size_t budget); + int (*closed)(lws_abs_protocol_inst_t *d); + int (*heartbeat)(lws_abs_protocol_inst_t *d); + + /* as parent, we get a notification a new child / queue entry + * bound to us... this is the parent lws_abs_t as arg */ + int (*child_bind)(lws_abs_t *abs); } lws_abs_protocol_t; /** @@ -51,3 +85,4 @@ */ #include + diff -Nru libwebsockets-3.2.1/include/libwebsockets/abstract/transports/raw-skt.h libwebsockets-4.1.6/include/libwebsockets/abstract/transports/raw-skt.h --- libwebsockets-3.2.1/include/libwebsockets/abstract/transports/raw-skt.h 2019-12-18 14:45:31.000000000 +0000 +++ libwebsockets-4.1.6/include/libwebsockets/abstract/transports/raw-skt.h 2020-12-01 17:40:26.000000000 +0000 @@ -1,22 +1,25 @@ /* - * libwebsockets - raw-skt abstract transport + * libwebsockets - small server side websockets and web server implementation * - * Copyright (C) 2019 Andy Green + * Copyright (C) 2010 - 2019 Andy Green * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation: - * version 2.1 of the License. + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to + * deal in the Software without restriction, including without limitation the + * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or + * sell copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: * - * This library is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. * - * You should have received a copy of the GNU Lesser General Public - * License along with this library; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, - * MA 02110-1301 USA + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS + * IN THE SOFTWARE. */ enum { diff -Nru libwebsockets-3.2.1/include/libwebsockets/abstract/transports/unit-test.h libwebsockets-4.1.6/include/libwebsockets/abstract/transports/unit-test.h --- libwebsockets-3.2.1/include/libwebsockets/abstract/transports/unit-test.h 2019-12-18 14:45:31.000000000 +0000 +++ libwebsockets-4.1.6/include/libwebsockets/abstract/transports/unit-test.h 2020-12-01 17:40:26.000000000 +0000 @@ -1,22 +1,25 @@ -/* - * libwebsockets include/libwebsockets/abstract/transports/unit-test.c + /* + * libwebsockets - small server side websockets and web server implementation * - * Copyright (C) 2019 Andy Green + * Copyright (C) 2010 - 2019 Andy Green * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation: - * version 2.1 of the License. - * - * This library is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with this library; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, - * MA 02110-1301 USA + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to + * deal in the Software without restriction, including without limitation the + * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or + * sell copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS + * IN THE SOFTWARE. * * This is an abstract transport useful for unit testing abstract protocols. * diff -Nru libwebsockets-3.2.1/include/libwebsockets/abstract/transports.h libwebsockets-4.1.6/include/libwebsockets/abstract/transports.h --- libwebsockets-3.2.1/include/libwebsockets/abstract/transports.h 2019-12-18 14:45:31.000000000 +0000 +++ libwebsockets-4.1.6/include/libwebsockets/abstract/transports.h 2020-12-01 17:40:26.000000000 +0000 @@ -1,24 +1,25 @@ /* * libwebsockets - small server side websockets and web server implementation * - * Copyright (C) 2010-2019 Andy Green + * Copyright (C) 2010 - 2019 Andy Green * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation: - * version 2.1 of the License. + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to + * deal in the Software without restriction, including without limitation the + * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or + * sell copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: * - * This library is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. * - * You should have received a copy of the GNU Lesser General Public - * License along with this library; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, - * MA 02110-1301 USA - * - * included from libwebsockets.h + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS + * IN THE SOFTWARE. */ /* @@ -29,9 +30,12 @@ const char *name; int alloc; - int (*create)(struct lws_abs *abs); + int (*create)(lws_abs_t *abs); void (*destroy)(lws_abs_transport_inst_t **d); + /* check if the transport settings for these connections are the same */ + int (*compare)(lws_abs_t *abs1, lws_abs_t *abs2); + /* events the abstract protocol invokes (handled by transport) */ int (*tx)(lws_abs_transport_inst_t *d, uint8_t *buf, size_t len); diff -Nru libwebsockets-3.2.1/include/libwebsockets/lws-adopt.h libwebsockets-4.1.6/include/libwebsockets/lws-adopt.h --- libwebsockets-3.2.1/include/libwebsockets/lws-adopt.h 2019-12-18 14:45:31.000000000 +0000 +++ libwebsockets-4.1.6/include/libwebsockets/lws-adopt.h 2020-12-01 17:40:26.000000000 +0000 @@ -1,24 +1,25 @@ /* * libwebsockets - small server side websockets and web server implementation * - * Copyright (C) 2010-2018 Andy Green + * Copyright (C) 2010 - 2019 Andy Green * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation: - * version 2.1 of the License. - * - * This library is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with this library; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, - * MA 02110-1301 USA - * - * included from libwebsockets.h + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to + * deal in the Software without restriction, including without limitation the + * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or + * sell copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS + * IN THE SOFTWARE. */ /** \defgroup sock-adopt Socket adoption helpers @@ -78,13 +79,13 @@ lws_filefd_type filefd; } lws_sock_file_fd_type; -#if !defined(LWS_WITH_ESP32) && !defined(LWS_PLAT_OPTEE) +#if defined(LWS_WITH_UDP) struct lws_udp { - struct sockaddr sa; - socklen_t salen; + struct sockaddr sa; + socklen_t salen; - struct sockaddr sa_pending; - socklen_t salen_pending; + struct sockaddr sa_pending; + socklen_t salen_pending; }; #endif @@ -112,6 +113,40 @@ lws_sock_file_fd_type fd, const char *vh_prot_name, struct lws *parent); +typedef struct lws_adopt_desc { + struct lws_vhost *vh; /**< vhost the wsi should belong to */ + lws_adoption_type type; /**< OR-ed combinations of lws_adoption_type flags */ + lws_sock_file_fd_type fd; /**< union with either .sockfd or .filefd set */ + const char *vh_prot_name; /**< NULL or vh protocol name to bind raw connection to */ + struct lws *parent; /**< NULL or struct lws to attach new_wsi to as a child */ + void *opaque; /**< opaque pointer to set on created wsi */ +} lws_adopt_desc_t; + +/** +* lws_adopt_descriptor_vhost_via_info() - adopt foreign socket or file descriptor +* if socket descriptor, should already have been accepted from listen socket +* +* \param info: the struct containing the parameters +* +* - vh: lws vhost +* - type: OR-ed combinations of lws_adoption_type flags +* - fd: union with either .sockfd or .filefd set +* - vh_prot_name: NULL or vh protocol name to bind raw connection to +* - parent: NULL or struct lws to attach new_wsi to as a child +* - opaque: opaque pointer to set on created wsi +* +* Either returns new wsi bound to accept_fd, or closes accept_fd and +* returns NULL, having cleaned up any new wsi pieces. +* +* If LWS_ADOPT_SOCKET is set, LWS adopts the socket in http serving mode, it's +* ready to accept an upgrade to ws or just serve http. +* +* parent may be NULL, if given it should be an existing wsi that will become the +* parent of the new wsi created by this call. +*/ +LWS_VISIBLE LWS_EXTERN struct lws * +lws_adopt_descriptor_vhost_via_info(const lws_adopt_desc_t *info); + /** * lws_adopt_socket_readbuf() - adopt foreign socket and first rx as if listen socket accepted it * for the default vhost of context. @@ -165,21 +200,34 @@ lws_sockfd_type accept_fd, const char *readbuf, size_t len); -#define LWS_CAUDP_BIND 1 +#define LWS_CAUDP_BIND (1 << 0) +#define LWS_CAUDP_BROADCAST (1 << 1) +#define LWS_CAUDP_PF_PACKET (1 << 2) +#if defined(LWS_WITH_UDP) /** * lws_create_adopt_udp() - create, bind and adopt a UDP socket * * \param vhost: lws vhost + * \param ads: NULL or address to do dns lookup on * \param port: UDP port to bind to, -1 means unbound * \param flags: 0 or LWS_CAUDP_NO_BIND * \param protocol_name: Name of protocol on vhost to bind wsi to + * \param ifname: NULL, for network interface name to bind socket to * \param parent_wsi: NULL or parent wsi new wsi will be a child of + * \param opaque: set created wsi opaque ptr to this + * \param retry_policy: NULL for vhost default policy else wsi specific policy * * Either returns new wsi bound to accept_fd, or closes accept_fd and * returns NULL, having cleaned up any new wsi pieces. * */ LWS_VISIBLE LWS_EXTERN struct lws * -lws_create_adopt_udp(struct lws_vhost *vhost, int port, int flags, - const char *protocol_name, struct lws *parent_wsi); +lws_create_adopt_udp(struct lws_vhost *vhost, const char *ads, int port, + int flags, const char *protocol_name, const char *ifname, + struct lws *parent_wsi, void *opaque, + const lws_retry_bo_t *retry_policy); +#endif + + + ///@} diff -Nru libwebsockets-3.2.1/include/libwebsockets/lws-async-dns.h libwebsockets-4.1.6/include/libwebsockets/lws-async-dns.h --- libwebsockets-3.2.1/include/libwebsockets/lws-async-dns.h 1970-01-01 00:00:00.000000000 +0000 +++ libwebsockets-4.1.6/include/libwebsockets/lws-async-dns.h 2020-12-01 17:40:26.000000000 +0000 @@ -0,0 +1,87 @@ +/* + * libwebsockets - small server side websockets and web server implementation + * + * Copyright (C) 2010 - 2019 Andy Green + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to + * deal in the Software without restriction, including without limitation the + * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or + * sell copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS + * IN THE SOFTWARE. + */ + +#if defined(LWS_WITH_UDP) + +typedef enum dns_query_type { + LWS_ADNS_RECORD_A = 0x01, + LWS_ADNS_RECORD_CNAME = 0x05, + LWS_ADNS_RECORD_MX = 0x0f, + LWS_ADNS_RECORD_AAAA = 0x1c, +} adns_query_type_t; + +typedef enum { + LADNS_RET_FAILED_WSI_CLOSED = -4, + LADNS_RET_NXDOMAIN = -3, + LADNS_RET_TIMEDOUT = -2, + LADNS_RET_FAILED = -1, + LADNS_RET_FOUND, + LADNS_RET_CONTINUING +} lws_async_dns_retcode_t; + +struct addrinfo; + +typedef struct lws * (*lws_async_dns_cb_t)(struct lws *wsi, const char *ads, + const struct addrinfo *result, int n, + void *opaque); + +/** + * lws_async_dns_query() - perform a dns lookup using async dns + * + * \param context: the lws_context + * \param tsi: thread service index (usually 0) + * \param name: DNS name to look up + * \param qtype: type of query (A, AAAA etc) + * \param cb: query completion callback + * \param wsi: wsi if the query is related to one + * + * Starts an asynchronous DNS lookup, on completion the \p cb callback will + * be called. + * + * The reference count on the cached object is incremented for every callback + * that was called with the cached addrinfo results. + * + * The cached object can't be evicted until the reference count reaches zero... + * use lws_async_dns_freeaddrinfo() to indicate you're finsihed with the + * results for each callback that happened with them. + */ +LWS_VISIBLE LWS_EXTERN lws_async_dns_retcode_t +lws_async_dns_query(struct lws_context *context, int tsi, const char *name, + adns_query_type_t qtype, lws_async_dns_cb_t cb, + struct lws *wsi, void *opaque); + +/** + * lws_async_dns_freeaddrinfo() - decrement refcount on cached addrinfo results + * + * \param pai: a pointert to a pointer to first addrinfo returned as result in the callback + * + * Decrements the cache object's reference count. When it reaches zero, the + * cached object may be reaped subject to LRU rules. + * + * The pointer to the first addrinfo give in the argument is set to NULL. + */ +LWS_VISIBLE LWS_EXTERN void +lws_async_dns_freeaddrinfo(const struct addrinfo **ai); + +#endif diff -Nru libwebsockets-3.2.1/include/libwebsockets/lws-bb-i2c.h libwebsockets-4.1.6/include/libwebsockets/lws-bb-i2c.h --- libwebsockets-3.2.1/include/libwebsockets/lws-bb-i2c.h 1970-01-01 00:00:00.000000000 +0000 +++ libwebsockets-4.1.6/include/libwebsockets/lws-bb-i2c.h 2020-12-01 17:40:26.000000000 +0000 @@ -0,0 +1,66 @@ +/* + * I2C - bitbanged generic gpio implementation + * + * Copyright (C) 2019 - 2020 Andy Green + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to + * deal in the Software without restriction, including without limitation the + * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or + * sell copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS + * IN THE SOFTWARE. + * + * This is like an abstract class for gpio, a real implementation provides + * functions for the ops that use the underlying OS gpio arrangements. + */ + +typedef struct lws_bb_i2c { + lws_i2c_ops_t bb_ops; /* init to lws_bb_i2c_ops */ + + /* implementation-specific members */ + + _lws_plat_gpio_t scl; + _lws_plat_gpio_t sda; + + const lws_gpio_ops_t *gpio; + void (*delay)(void); +} lws_bb_i2c_t; + +#define lws_bb_i2c_ops \ + { \ + .init = lws_bb_i2c_init, \ + .start = lws_bb_i2c_start, \ + .stop = lws_bb_i2c_stop, \ + .write = lws_bb_i2c_write, \ + .read = lws_bb_i2c_read, \ + .set_ack = lws_bb_i2c_set_ack, \ + } + +int +lws_bb_i2c_init(const lws_i2c_ops_t *octx); + +int +lws_bb_i2c_start(const lws_i2c_ops_t *octx); + +void +lws_bb_i2c_stop(const lws_i2c_ops_t *octx); + +int +lws_bb_i2c_write(const lws_i2c_ops_t *octx, uint8_t data); + +int +lws_bb_i2c_read(const lws_i2c_ops_t *octx); + +void +lws_bb_i2c_set_ack(const lws_i2c_ops_t *octx, int ack); diff -Nru libwebsockets-3.2.1/include/libwebsockets/lws-bb-spi.h libwebsockets-4.1.6/include/libwebsockets/lws-bb-spi.h --- libwebsockets-3.2.1/include/libwebsockets/lws-bb-spi.h 1970-01-01 00:00:00.000000000 +0000 +++ libwebsockets-4.1.6/include/libwebsockets/lws-bb-spi.h 2020-12-01 17:40:26.000000000 +0000 @@ -0,0 +1,62 @@ +/* + * I2C - bitbanged generic gpio implementation + * + * Copyright (C) 2019 - 2020 Andy Green + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to + * deal in the Software without restriction, including without limitation the + * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or + * sell copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS + * IN THE SOFTWARE. + * + * This is like an abstract class for gpio, a real implementation provides + * functions for the ops that use the underlying OS gpio arrangements. + */ + +#define LWSBBSPI_FLAG_USE_NCMD3 (1 << 7) +#define LWSBBSPI_FLAG_USE_NCMD2 (1 << 6) +#define LWSBBSPI_FLAG_USE_NCMD1 (1 << 5) +#define LWSBBSPI_FLAG_USE_NCMD0 (1 << 4) +#define LWSBBSPI_FLAG_USE_NCS3 (1 << 3) +#define LWSBBSPI_FLAG_USE_NCS2 (1 << 2) +#define LWSBBSPI_FLAG_USE_NCS1 (1 << 1) +#define LWSBBSPI_FLAG_USE_NCS0 (1 << 0) + +#define LWS_SPI_BB_MAX_CH 4 + +typedef struct lws_bb_spi { + lws_spi_ops_t bb_ops; /* init to lws_bb_spi_ops */ + + /* implementation-specific members */ + const lws_gpio_ops_t *gpio; + + _lws_plat_gpio_t clk; + _lws_plat_gpio_t ncs[LWS_SPI_BB_MAX_CH]; + _lws_plat_gpio_t ncmd[LWS_SPI_BB_MAX_CH]; + _lws_plat_gpio_t mosi; + _lws_plat_gpio_t miso; + + uint8_t flags; +} lws_bb_spi_t; + +#define lws_bb_spi_ops \ + .init = lws_bb_spi_init, \ + .queue = lws_bb_spi_queue + +int +lws_bb_spi_init(const lws_spi_ops_t *octx); + +int +lws_bb_spi_queue(const lws_spi_ops_t *octx, const lws_spi_desc_t *desc); diff -Nru libwebsockets-3.2.1/include/libwebsockets/lws-button.h libwebsockets-4.1.6/include/libwebsockets/lws-button.h --- libwebsockets-3.2.1/include/libwebsockets/lws-button.h 1970-01-01 00:00:00.000000000 +0000 +++ libwebsockets-4.1.6/include/libwebsockets/lws-button.h 2020-12-01 17:40:26.000000000 +0000 @@ -0,0 +1,120 @@ +/* + * Generic button ops + * + * Copyright (C) 2019 - 2020 Andy Green + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to + * deal in the Software without restriction, including without limitation the + * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or + * sell copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS + * IN THE SOFTWARE. + * + * Leverages the lws generic gpio pieces to bind gpio buttons to smd events + */ + +#if !defined(__LWS_BUTTON_H__) +#define __LWS_BUTTON_H__ + +typedef uint16_t lws_button_idx_t; + +/* actual minimum may be 1 x RTOS tick depending on platform */ +#define LWS_BUTTON_MON_TIMER_MS 5 + +typedef void (*lws_button_cb_t)(void *opaque, lws_button_idx_t idx, int state); + +/* These are specified in ms but the granularity is LWS_BUTTON_MON_TIMER_MS, + * which may have been rounded up to an RTOS tick depending on platform */ + +enum { + LWSBTNRGMFLAG_CLASSIFY_DOUBLECLICK = (1 << 0) +}; + +typedef struct lws_button_regime { + uint16_t ms_min_down; + uint16_t ms_min_down_longpress; + uint16_t ms_up_settle; + uint16_t ms_doubleclick_grace; + uint16_t ms_repeat_down; + uint8_t flags; + /**< when double-click classification is enabled, clicks are delayed + * by ms_min_down + ms_doubleclick_grace to wait and see if it will + * become a double-click. Set LWSBTNRGMFLAG_CLASSIFY_DOUBLECLICK to + * enable it or leave that bit at 0 to get faster single-click + * classification. + */ +} lws_button_regime_t; + +/* + * This is the const part of the button controller, describing the static + * bindings to gpio, and lws_smd event name information + */ + +typedef struct lws_button_map { + _lws_plat_gpio_t gpio; + const char *smd_interaction_name; + const lws_button_regime_t *regime; + /**< a default regime is applied if this is left NULL */ +} lws_button_map_t; + +typedef struct lws_button_controller { + const char *smd_bc_name; + const lws_gpio_ops_t *gpio_ops; + const lws_button_map_t *button_map; + lws_button_idx_t active_state_bitmap; + uint8_t count_buttons; +} lws_button_controller_t; + +struct lws_button_state; /* opaque */ + +/** + * lws_button_controller_create() - instantiate a button controller + * + * \param ctx: the lws_context + * \param controller: the static controller definition + * + * Instantiates a button controller from a static definition of the buttons + * and their smd names, and active levels, and binds it to a gpio implementation + */ + +LWS_VISIBLE LWS_EXTERN struct lws_button_state * +lws_button_controller_create(struct lws_context *ctx, + const lws_button_controller_t *controller); + +/** + * lws_button_controller_destroy() - destroys a button controller + * + * \param bcs: button controller state previously created + * + * Disables all buttons and then destroys and frees a previously created + * button controller. + */ + +LWS_VISIBLE LWS_EXTERN void +lws_button_controller_destroy(struct lws_button_state *bcs); + + +LWS_VISIBLE LWS_EXTERN lws_button_idx_t +lws_button_get_bit(struct lws_button_state *bcs, const char *name); + +/* + * lws_button_enable() - enable and disable buttons + */ + +LWS_VISIBLE LWS_EXTERN void +lws_button_enable(struct lws_button_state *bcs, + lws_button_idx_t _reset, lws_button_idx_t _set); + +#endif + diff -Nru libwebsockets-3.2.1/include/libwebsockets/lws-callbacks.h libwebsockets-4.1.6/include/libwebsockets/lws-callbacks.h --- libwebsockets-3.2.1/include/libwebsockets/lws-callbacks.h 2019-12-18 14:45:31.000000000 +0000 +++ libwebsockets-4.1.6/include/libwebsockets/lws-callbacks.h 2020-12-01 17:40:26.000000000 +0000 @@ -1,24 +1,25 @@ /* * libwebsockets - small server side websockets and web server implementation * - * Copyright (C) 2010-2018 Andy Green + * Copyright (C) 2010 - 2019 Andy Green * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation: - * version 2.1 of the License. + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to + * deal in the Software without restriction, including without limitation the + * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or + * sell copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: * - * This library is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. * - * You should have received a copy of the GNU Lesser General Public - * License along with this library; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, - * MA 02110-1301 USA - * - * included from libwebsockets.h + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS + * IN THE SOFTWARE. */ /*! \defgroup usercb User Callback @@ -61,6 +62,7 @@ LWS_TLS_REQ_ELEMENT_LOCALITY, LWS_TLS_REQ_ELEMENT_ORGANIZATION, LWS_TLS_REQ_ELEMENT_COMMON_NAME, + LWS_TLS_REQ_ELEMENT_SUBJECT_ALT_NAME, LWS_TLS_REQ_ELEMENT_EMAIL, LWS_TLS_REQ_ELEMENT_COUNT, @@ -79,6 +81,17 @@ }; /* + * With LWS_CALLBACK_FILTER_NETWORK_CONNECTION callback, user_data pointer + * points to one of these + */ + +struct lws_filter_network_conn_args { + struct sockaddr_storage cli_addr; + socklen_t clilen; + lws_sockfd_type accept_fd; +}; + +/* * NOTE: These public enums are part of the abi. If you want to add one, * add it at where specified so existing users are unaffected. */ @@ -105,6 +118,9 @@ LWS_CALLBACK_WSI_DESTROY = 30, /**< outermost (latest) wsi destroy notification to protocols[0] */ + LWS_CALLBACK_WSI_TX_CREDIT_GET = 103, + /**< manually-managed connection received TX credit (len is int32) */ + /* --------------------------------------------------------------------- * ----- Callbacks related to Server TLS ----- @@ -278,6 +294,15 @@ * break; */ + LWS_CALLBACK_VERIFY_BASIC_AUTHORIZATION = 102, + /**< This gives the user code a chance to accept or reject credentials + * provided HTTP to basic authorization. It will only be called if the + * http mount's authentication_mode is set to LWSAUTHM_BASIC_AUTH_CALLBACK + * `in` points to a credential string of the form `username:password` If + * the callback returns zero (the default if unhandled), then the + * transaction ends with HTTP_STATUS_UNAUTHORIZED, otherwise the request + * will be processed */ + LWS_CALLBACK_CHECK_ACCESS_RIGHTS = 51, /**< This gives the user code a chance to forbid an http access. * `in` points to a `struct lws_process_html_args`, which @@ -376,6 +401,9 @@ * lws know by calling lws_client_http_body_pending(wsi, 0) */ + LWS_CALLBACK_CLIENT_HTTP_REDIRECT = 104, + /**< we're handling a 3xx redirect... return nonzero to hang up */ + LWS_CALLBACK_CLIENT_HTTP_BIND_PROTOCOL = 85, LWS_CALLBACK_CLIENT_HTTP_DROP_PROTOCOL = 76, @@ -564,9 +592,17 @@ /**< called when a client connects to * the server at network level; the connection is accepted but then * passed to this callback to decide whether to hang up immediately - * or not, based on the client IP. in contains the connection - * socket's descriptor. Since the client connection information is - * not available yet, wsi still pointing to the main server socket. + * or not, based on the client IP. + * + * user_data in the callback points to a + * struct lws_filter_network_conn_args that is prepared with the + * sockfd, and the peer's address information. + * + * in contains the connection socket's descriptor. + * + * Since the client connection information is not available yet, + * wsi still pointing to the main server socket. + * * Return non-zero to terminate the connection before sending or * receiving anything. Because this happens immediately after the * network connection from the client, there's no websocket protocol @@ -813,6 +849,30 @@ * and failure. in points to optional JSON, and len represents the * connection state using enum lws_cert_update_state */ + /* --------------------------------------------------------------------- + * ----- Callbacks related to MQTT Client ----- + */ + + LWS_CALLBACK_MQTT_NEW_CLIENT_INSTANTIATED = 200, + LWS_CALLBACK_MQTT_IDLE = 201, + LWS_CALLBACK_MQTT_CLIENT_ESTABLISHED = 202, + LWS_CALLBACK_MQTT_SUBSCRIBED = 203, + LWS_CALLBACK_MQTT_CLIENT_WRITEABLE = 204, + LWS_CALLBACK_MQTT_CLIENT_RX = 205, + LWS_CALLBACK_MQTT_UNSUBSCRIBED = 206, + LWS_CALLBACK_MQTT_DROP_PROTOCOL = 207, + LWS_CALLBACK_MQTT_CLIENT_CLOSED = 208, + LWS_CALLBACK_MQTT_ACK = 209, + /**< When a message is fully sent, if QoS0 this callback is generated + * to locally "acknowledge" it. For QoS1, this callback is only + * generated when the matching PUBACK is received. Return nonzero to + * close the wsi. + */ + LWS_CALLBACK_MQTT_RESEND = 210, + /**< In QoS1, this callback is generated instead of the _ACK one if + * we timed out waiting for a PUBACK and we must resend the message. + * Return nonzero to close the wsi. + */ /****** add new things just above ---^ ******/ diff -Nru libwebsockets-3.2.1/include/libwebsockets/lws-cgi.h libwebsockets-4.1.6/include/libwebsockets/lws-cgi.h --- libwebsockets-3.2.1/include/libwebsockets/lws-cgi.h 2019-12-18 14:45:31.000000000 +0000 +++ libwebsockets-4.1.6/include/libwebsockets/lws-cgi.h 2020-12-01 17:40:26.000000000 +0000 @@ -1,24 +1,25 @@ /* * libwebsockets - small server side websockets and web server implementation * - * Copyright (C) 2010-2018 Andy Green + * Copyright (C) 2010 - 2019 Andy Green * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation: - * version 2.1 of the License. + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to + * deal in the Software without restriction, including without limitation the + * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or + * sell copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: * - * This library is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. * - * You should have received a copy of the GNU Lesser General Public - * License along with this library; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, - * MA 02110-1301 USA - * - * included from libwebsockets.h + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS + * IN THE SOFTWARE. */ /*! \defgroup cgi cgi handling diff -Nru libwebsockets-3.2.1/include/libwebsockets/lws-client.h libwebsockets-4.1.6/include/libwebsockets/lws-client.h --- libwebsockets-3.2.1/include/libwebsockets/lws-client.h 2019-12-18 14:45:31.000000000 +0000 +++ libwebsockets-4.1.6/include/libwebsockets/lws-client.h 2020-12-01 17:40:26.000000000 +0000 @@ -1,24 +1,25 @@ /* * libwebsockets - small server side websockets and web server implementation * - * Copyright (C) 2010-2018 Andy Green + * Copyright (C) 2010 - 2019 Andy Green * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation: - * version 2.1 of the License. - * - * This library is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with this library; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, - * MA 02110-1301 USA - * - * included from libwebsockets.h + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to + * deal in the Software without restriction, including without limitation the + * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or + * sell copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS + * IN THE SOFTWARE. */ /*! \defgroup client Client related functions @@ -39,6 +40,14 @@ LCCSCF_SKIP_SERVER_CERT_HOSTNAME_CHECK = (1 << 2), LCCSCF_ALLOW_EXPIRED = (1 << 3), LCCSCF_ALLOW_INSECURE = (1 << 4), + LCCSCF_H2_QUIRK_NGHTTP2_END_STREAM = (1 << 5), + LCCSCF_H2_QUIRK_OVERFLOWS_TXCR = (1 << 6), + LCCSCF_H2_AUTH_BEARER = (1 << 7), + LCCSCF_H2_HEXIFY_AUTH_TOKEN = (1 << 8), + LCCSCF_H2_MANUAL_RXFLOW = (1 << 9), + LCCSCF_HTTP_MULTIPART_MIME = (1 << 10), + LCCSCF_HTTP_X_WWW_FORM_URLENCODED = (1 << 11), + LCCSCF_HTTP_NO_FOLLOW_REDIRECT = (1 << 12), LCCSCF_PIPELINE = (1 << 16), /**< Serialize / pipeline multiple client connections @@ -47,7 +56,22 @@ * HTTP/1.0: possible if Keep-Alive: yes sent by server * HTTP/1.1: always possible... uses pipelining * HTTP/2: always possible... uses parallel streams - * */ + */ + LCCSCF_MUXABLE_STREAM = (1 << 17), + LCCSCF_H2_PRIOR_KNOWLEDGE = (1 << 18), + LCCSCF_WAKE_SUSPEND__VALIDITY = (1 << 19), + /* our validity checks are important enough to wake from suspend */ + LCCSCF_PRIORITIZE_READS = (1 << 20), + /**< + * Normally lws balances reads and writes on all connections, so both + * are possible even on busy connections, and we go around the event + * loop more often to facilitate that, even if there is pending data. + * + * This flag indicates that you want to handle any pending reads on this + * connection without yielding the service loop for anything else. This + * means you may block other connection processing in favour of incoming + * data processing on this one if it receives back to back incoming rx. + */ }; /** struct lws_client_connect_info - parameters to connect with when using @@ -120,7 +144,7 @@ * tokens */ - lws_seq_t *seq; + struct lws_sequencer *seq; /**< NULL, or an lws_seq_t that wants to be given messages about * this wsi's lifecycle as it connects, errors or closes. */ @@ -132,6 +156,33 @@ * an lws_seq_t. */ + const lws_retry_bo_t *retry_and_idle_policy; + /**< optional retry and idle policy to apply to this connection. + * Currently only the idle parts are applied to the connection. + */ + + int manual_initial_tx_credit; + /**< if LCCSCF_H2_MANUAL_REFLOW is set, this becomes the initial tx + * credit for the stream. + */ + + uint8_t sys_tls_client_cert; + /**< 0 means no client cert. 1+ means apply lws_system client cert 0+ + * to the client connection. + */ + +#if defined(LWS_ROLE_MQTT) + const lws_mqtt_client_connect_param_t *mqtt_cp; +#else + void *mqtt_cp; +#endif + + uint16_t keep_warm_secs; + /**< 0 means 5s. If the client connection to the endpoint becomes idle, + * defer closing it for this many seconds in case another outgoing + * connection to the same endpoint turns up. + */ + /* Add new things just above here ---^ * This is part of the ABI, don't needlessly break compatibility * @@ -218,11 +269,23 @@ LWS_VISIBLE LWS_EXTERN unsigned int lws_http_client_http_response(struct lws *wsi); -LWS_VISIBLE LWS_EXTERN void -lws_client_http_body_pending(struct lws *wsi, int something_left_to_send); +/** + * lws_tls_client_vhost_extra_cert_mem() - add more certs to vh client tls ctx + * + * \param vh: the vhost to give more client certs to + * \param der: pointer to der format additional cert + * \param der_len: size in bytes of der + * + * After the vhost is created with one cert for client verification, you + * can add additional, eg, intermediate, certs to the client tls context + * of the vhost, for use with validating the incoming server cert(s). + */ +LWS_VISIBLE LWS_EXTERN int +lws_tls_client_vhost_extra_cert_mem(struct lws_vhost *vh, + const uint8_t *der, size_t der_len); /** - * lws_client_http_body_pending() - control if client connection neeeds to send body + * lws_client_http_body_pending() - control if client connection needs to send body * * \param wsi: client connection * \param something_left_to_send: nonzero if need to send more body, 0 (default) @@ -240,5 +303,41 @@ * if there is more to come, or lws_client_http_body_pending(wsi, 0); to * let lws know the last part is sent and the connection can move on. */ +LWS_VISIBLE LWS_EXTERN void +lws_client_http_body_pending(struct lws *wsi, int something_left_to_send); + +/** + * lws_client_http_multipart() - issue appropriate multipart header or trailer + * + * \param wsi: client connection + * \param name: multipart header name field, or NULL if end of multipart + * \param filename: multipart header filename field, or NULL if none + * \param content_type: multipart header content-type part, or NULL if none + * \param p: pointer to position in buffer + * \param end: end of buffer + * + * This issues a multipart mime boundary, or terminator if name = NULL. + * + * Returns 0 if OK or nonzero if couldn't fit in buffer + */ +LWS_VISIBLE LWS_EXTERN int +lws_client_http_multipart(struct lws *wsi, const char *name, + const char *filename, const char *content_type, + char **p, char *end); + +/** + * lws_http_basic_auth_gen() - helper to encode client basic auth string + * + * \param user: user name + * \param pw: password + * \param buf: where to store base64 result + * \param len: max usable size of buf + * + * Encodes a username and password in Basic Auth format for use with the + * Authorization header. On return, buf is filled with something like + * "Basic QWxhZGRpbjpPcGVuU2VzYW1l". + */ +LWS_VISIBLE LWS_EXTERN int +lws_http_basic_auth_gen(const char *user, const char *pw, char *buf, size_t len); ///@} diff -Nru libwebsockets-3.2.1/include/libwebsockets/lws-context-vhost.h libwebsockets-4.1.6/include/libwebsockets/lws-context-vhost.h --- libwebsockets-3.2.1/include/libwebsockets/lws-context-vhost.h 2019-12-18 14:45:31.000000000 +0000 +++ libwebsockets-4.1.6/include/libwebsockets/lws-context-vhost.h 2020-12-01 17:40:26.000000000 +0000 @@ -1,24 +1,25 @@ /* * libwebsockets - small server side websockets and web server implementation * - * Copyright (C) 2010-2018 Andy Green + * Copyright (C) 2010 - 2019 Andy Green * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation: - * version 2.1 of the License. - * - * This library is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with this library; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, - * MA 02110-1301 USA - * - * included from libwebsockets.h + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to + * deal in the Software without restriction, including without limitation the + * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or + * sell copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS + * IN THE SOFTWARE. */ /*! \defgroup context-and-vhost context and vhost related functions @@ -41,41 +42,40 @@ * add it at where specified so existing users are unaffected. */ -/** enum lws_context_options - context and vhost options */ -enum lws_context_options { - LWS_SERVER_OPTION_REQUIRE_VALID_OPENSSL_CLIENT_CERT = (1 << 1) | - (1 << 12), + +#define LWS_SERVER_OPTION_REQUIRE_VALID_OPENSSL_CLIENT_CERT ((1ll << 1) | \ + (1ll << 12)) /**< (VH) Don't allow the connection unless the client has a * client cert that we recognize; provides * LWS_SERVER_OPTION_DO_SSL_GLOBAL_INIT */ - LWS_SERVER_OPTION_SKIP_SERVER_CANONICAL_NAME = (1 << 2), +#define LWS_SERVER_OPTION_SKIP_SERVER_CANONICAL_NAME (1ll << 2) /**< (CTX) Don't try to get the server's hostname */ - LWS_SERVER_OPTION_ALLOW_NON_SSL_ON_SSL_PORT = (1 << 3) | - (1 << 12), +#define LWS_SERVER_OPTION_ALLOW_NON_SSL_ON_SSL_PORT ((1ll << 3) | \ + (1ll << 12)) /**< (VH) Allow non-SSL (plaintext) connections on the same * port as SSL is listening. If combined with * LWS_SERVER_OPTION_REDIRECT_HTTP_TO_HTTPS it will try to * force http connections on an https listener (eg, http://x.com:443) to * redirect to an explicit https connection (eg, https://x.com) */ - LWS_SERVER_OPTION_LIBEV = (1 << 4), +#define LWS_SERVER_OPTION_LIBEV (1ll << 4) /**< (CTX) Use libev event loop */ - LWS_SERVER_OPTION_DISABLE_IPV6 = (1 << 5), +#define LWS_SERVER_OPTION_DISABLE_IPV6 (1ll << 5) /**< (VH) Disable IPV6 support */ - LWS_SERVER_OPTION_DISABLE_OS_CA_CERTS = (1 << 6), +#define LWS_SERVER_OPTION_DISABLE_OS_CA_CERTS (1ll << 6) /**< (VH) Don't load OS CA certs, you will need to load your * own CA cert(s) */ - LWS_SERVER_OPTION_PEER_CERT_NOT_REQUIRED = (1 << 7), +#define LWS_SERVER_OPTION_PEER_CERT_NOT_REQUIRED (1ll << 7) /**< (VH) Accept connections with no valid Cert (eg, selfsigned) */ - LWS_SERVER_OPTION_VALIDATE_UTF8 = (1 << 8), +#define LWS_SERVER_OPTION_VALIDATE_UTF8 (1ll << 8) /**< (VH) Check UT-8 correctness */ - LWS_SERVER_OPTION_SSL_ECDH = (1 << 9) | - (1 << 12), +#define LWS_SERVER_OPTION_SSL_ECDH ((1ll << 9) | \ + (1ll << 12)) /**< (VH) initialize ECDH ciphers */ - LWS_SERVER_OPTION_LIBUV = (1 << 10), +#define LWS_SERVER_OPTION_LIBUV (1ll << 10) /**< (CTX) Use libuv event loop */ - LWS_SERVER_OPTION_REDIRECT_HTTP_TO_HTTPS = (1 << 11) | - (1 << 12), +#define LWS_SERVER_OPTION_REDIRECT_HTTP_TO_HTTPS ((1ll << 11) |\ + (1ll << 12)) /**< (VH) Use an http redirect to force the client to ask for https. * Notice if your http server issues the STS header and the client has * ever seen that, the client will fail the http connection before it @@ -85,35 +85,35 @@ * http://x.com:443 -> https://x.com * * (deprecated: use mount redirection) */ - LWS_SERVER_OPTION_DO_SSL_GLOBAL_INIT = (1 << 12), +#define LWS_SERVER_OPTION_DO_SSL_GLOBAL_INIT (1ll << 12) /**< (CTX) Initialize the SSL library at all */ - LWS_SERVER_OPTION_EXPLICIT_VHOSTS = (1 << 13), +#define LWS_SERVER_OPTION_EXPLICIT_VHOSTS (1ll << 13) /**< (CTX) Only create the context when calling context * create api, implies user code will create its own vhosts */ - LWS_SERVER_OPTION_UNIX_SOCK = (1 << 14), +#define LWS_SERVER_OPTION_UNIX_SOCK (1ll << 14) /**< (VH) Use Unix socket */ - LWS_SERVER_OPTION_STS = (1 << 15), +#define LWS_SERVER_OPTION_STS (1ll << 15) /**< (VH) Send Strict Transport Security header, making * clients subsequently go to https even if user asked for http */ - LWS_SERVER_OPTION_IPV6_V6ONLY_MODIFY = (1 << 16), +#define LWS_SERVER_OPTION_IPV6_V6ONLY_MODIFY (1ll << 16) /**< (VH) Enable LWS_SERVER_OPTION_IPV6_V6ONLY_VALUE to take effect */ - LWS_SERVER_OPTION_IPV6_V6ONLY_VALUE = (1 << 17), +#define LWS_SERVER_OPTION_IPV6_V6ONLY_VALUE (1ll << 17) /**< (VH) if set, only ipv6 allowed on the vhost */ - LWS_SERVER_OPTION_UV_NO_SIGSEGV_SIGFPE_SPIN = (1 << 18), +#define LWS_SERVER_OPTION_UV_NO_SIGSEGV_SIGFPE_SPIN (1ll << 18) /**< (CTX) Libuv only: Do not spin on SIGSEGV / SIGFPE. A segfault * normally makes the lib spin so you can attach a debugger to it * even if it happened without a debugger in place. You can disable * that by giving this option. */ - LWS_SERVER_OPTION_JUST_USE_RAW_ORIGIN = (1 << 19), +#define LWS_SERVER_OPTION_JUST_USE_RAW_ORIGIN (1ll << 19) /**< For backwards-compatibility reasons, by default * lws prepends "http://" to the origin you give in the client * connection info struct. If you give this flag when you create * the context, only the string you give in the client connect * info for .origin (if any) will be used directly. */ - LWS_SERVER_OPTION_FALLBACK_TO_RAW /* use below name */ = (1 << 20), - LWS_SERVER_OPTION_FALLBACK_TO_APPLY_LISTEN_ACCEPT_CONFIG= (1 << 20), +#define LWS_SERVER_OPTION_FALLBACK_TO_RAW /* use below name */ (1ll << 20) +#define LWS_SERVER_OPTION_FALLBACK_TO_APPLY_LISTEN_ACCEPT_CONFIG (1ll << 20) /**< (VH) if invalid http is coming in the first line, then abandon * trying to treat the connection as http, and belatedly apply the * .listen_accept_role / .listen_accept_protocol info struct members to @@ -126,11 +126,11 @@ * to work with a socket listening with tls. */ - LWS_SERVER_OPTION_LIBEVENT = (1 << 21), +#define LWS_SERVER_OPTION_LIBEVENT (1ll << 21) /**< (CTX) Use libevent event loop */ - LWS_SERVER_OPTION_ONLY_RAW /* Use below name instead */ = (1 << 22), - LWS_SERVER_OPTION_ADOPT_APPLY_LISTEN_ACCEPT_CONFIG = (1 << 22), +#define LWS_SERVER_OPTION_ONLY_RAW /* Use below name instead */ (1ll << 22) +#define LWS_SERVER_OPTION_ADOPT_APPLY_LISTEN_ACCEPT_CONFIG (1ll << 22) /**< (VH) All connections to this vhost / port are bound to the * role and protocol given in .listen_accept_role / * .listen_accept_protocol. @@ -143,31 +143,31 @@ * It's much preferred to specify the role + protocol using the * .listen_accept_role and .listen_accept_protocol in the info struct. */ - LWS_SERVER_OPTION_ALLOW_LISTEN_SHARE = (1 << 23), +#define LWS_SERVER_OPTION_ALLOW_LISTEN_SHARE (1ll << 23) /**< (VH) Set to allow multiple listen sockets on one interface + * address + port. The default is to strictly allow only one * listen socket at a time. This is automatically selected if you * have multiple service threads. Linux only. */ - LWS_SERVER_OPTION_CREATE_VHOST_SSL_CTX = (1 << 24), +#define LWS_SERVER_OPTION_CREATE_VHOST_SSL_CTX (1ll << 24) /**< (VH) Force setting up the vhost SSL_CTX, even though the user * code doesn't explicitly provide a cert in the info struct. It * implies the user code is going to provide a cert at the * LWS_CALLBACK_OPENSSL_LOAD_EXTRA_SERVER_VERIFY_CERTS callback, which * provides the vhost SSL_CTX * in the user parameter. */ - LWS_SERVER_OPTION_SKIP_PROTOCOL_INIT = (1 << 25), +#define LWS_SERVER_OPTION_SKIP_PROTOCOL_INIT (1ll << 25) /**< (VH) You probably don't want this. It forces this vhost to not * call LWS_CALLBACK_PROTOCOL_INIT on its protocols. It's used in the * special case of a temporary vhost bound to a single protocol. */ - LWS_SERVER_OPTION_IGNORE_MISSING_CERT = (1 << 26), +#define LWS_SERVER_OPTION_IGNORE_MISSING_CERT (1ll << 26) /**< (VH) Don't fail if the vhost TLS cert or key are missing, just * continue. The vhost won't be able to serve anything, but if for * example the ACME plugin was configured to fetch a cert, this lets * you bootstrap your vhost from having no cert to start with. */ - LWS_SERVER_OPTION_VHOST_UPG_STRICT_HOST_CHECK = (1 << 27), +#define LWS_SERVER_OPTION_VHOST_UPG_STRICT_HOST_CHECK (1ll << 27) /**< (VH) On this vhost, if the connection is being upgraded, insist * that there's a Host: header and that the contents match the vhost * name + port (443 / 80 are assumed if no :port given based on if the @@ -178,7 +178,7 @@ * allow lax hostname mappings like localhost / 127.0.0.1, and CNAME * mappings like www.mysite.com / mysite.com */ - LWS_SERVER_OPTION_HTTP_HEADERS_SECURITY_BEST_PRACTICES_ENFORCE = (1 << 28), +#define LWS_SERVER_OPTION_HTTP_HEADERS_SECURITY_BEST_PRACTICES_ENFORCE (1ll << 28) /**< (VH) Send lws default HTTP headers recommended by Mozilla * Observatory for security. This is a helper option that sends canned * headers on each http response enabling a VERY strict Content Security @@ -195,7 +195,7 @@ * yourself. */ - LWS_SERVER_OPTION_ALLOW_HTTP_ON_HTTPS_LISTENER = (1 << 29), +#define LWS_SERVER_OPTION_ALLOW_HTTP_ON_HTTPS_LISTENER (1ll << 29) /**< (VH) If you really want to allow HTTP connections on a tls * listener, you can do it with this combined with * LWS_SERVER_OPTION_ALLOW_NON_SSL_ON_SSL_PORT. But this is allowing @@ -203,21 +203,47 @@ * on the client using http when he meant https... it's not * recommended. */ - LWS_SERVER_OPTION_FAIL_UPON_UNABLE_TO_BIND = (1 << 30), +#define LWS_SERVER_OPTION_FAIL_UPON_UNABLE_TO_BIND (1ll << 30) /**< (VH) When instantiating a new vhost and the specified port is * already in use, a null value shall be return to signal the error. */ - LWS_SERVER_OPTION_H2_JUST_FIX_WINDOW_UPDATE_OVERFLOW = (1 << 31), +#define LWS_SERVER_OPTION_H2_JUST_FIX_WINDOW_UPDATE_OVERFLOW (1ll << 31) /**< (VH) Indicates the connections using this vhost should ignore * h2 WINDOW_UPDATE from broken peers and fix them up */ +#define LWS_SERVER_OPTION_VH_H2_HALF_CLOSED_LONG_POLL (1ll << 32) + /**< (VH) Tell the vhost to treat half-closed remote clients as + * entered into an immortal (ie, not subject to normal timeouts) long + * poll mode. + */ + +#define LWS_SERVER_OPTION_GLIB (1ll << 33) + /**< (CTX) Use glib event loop */ + +#define LWS_SERVER_OPTION_H2_PRIOR_KNOWLEDGE (1ll << 34) + /**< (VH) Tell the vhost to treat plain text http connections as + * H2 with prior knowledge (no upgrade request involved) + */ + +#define LWS_SERVER_OPTION_NO_LWS_SYSTEM_STATES (1ll << 35) + /**< (CTX) Disable lws_system state, eg, because we are a secure streams + * proxy client that is not trying to track system state by itself. */ + /****** add new things just above ---^ ******/ -}; -#define lws_check_opt(c, f) (((c) & (f)) == (f)) + +#define lws_check_opt(c, f) ((((uint64_t)c) & ((uint64_t)f)) == ((uint64_t)f)) struct lws_plat_file_ops; +struct lws_ss_policy; +struct lws_ss_plugin; + +typedef int (*lws_context_ready_cb_t)(struct lws_context *context); + +typedef int (*lws_peer_limits_notify_t)(struct lws_context *ctx, + lws_sockfd_type sockfd, + lws_sockaddr46 *sa46); /** struct lws_context_creation_info - parameters to create context and /or vhost with * @@ -229,15 +255,7 @@ * at the same time as the context, they are expected to be created afterwards. */ struct lws_context_creation_info { - int port; - /**< VHOST: Port to listen on. Use CONTEXT_PORT_NO_LISTEN to suppress - * listening for a client. Use CONTEXT_PORT_NO_LISTEN_SERVER if you are - * writing a server but you are using \ref sock-adopt instead of the - * built-in listener. - * - * You can also set port to 0, in which case the kernel will pick - * a random port that is not already in use. You can find out what - * port the vhost is listening on using lws_get_vhost_listen_port() */ +#if defined(LWS_WITH_NETWORK) const char *iface; /**< VHOST: NULL to bind the listen socket to all interfaces, or the * interface name, eg, "eth2" @@ -251,12 +269,94 @@ * entry that has a NULL callback pointer. SEE ALSO .pprotocols below, * which gives an alternative way to provide an array of pointers to * protocol structs. */ +#if defined(LWS_ROLE_WS) const struct lws_extension *extensions; /**< VHOST: NULL or array of lws_extension structs listing the * extensions this context supports. */ +#endif +#if defined(LWS_ROLE_H1) || defined(LWS_ROLE_H2) const struct lws_token_limits *token_limits; /**< CONTEXT: NULL or struct lws_token_limits pointer which is * initialized with a token length limit for each possible WSI_TOKEN_ */ + const char *http_proxy_address; + /**< VHOST: If non-NULL, attempts to proxy via the given address. + * If proxy auth is required, use format + * "username:password\@server:port" */ + const struct lws_protocol_vhost_options *headers; + /**< VHOST: pointer to optional linked list of per-vhost + * canned headers that are added to server responses */ + + const struct lws_protocol_vhost_options *reject_service_keywords; + /**< CONTEXT: Optional list of keywords and rejection codes + text. + * + * The keywords are checked for existing in the user agent string. + * + * Eg, "badrobot" "404 Not Found" + */ + const struct lws_protocol_vhost_options *pvo; + /**< VHOST: pointer to optional linked list of per-vhost + * options made accessible to protocols */ + const char *log_filepath; + /**< VHOST: filepath to append logs to... this is opened before + * any dropping of initial privileges */ + const struct lws_http_mount *mounts; + /**< VHOST: optional linked list of mounts for this vhost */ + const char *server_string; + /**< CONTEXT: string used in HTTP headers to identify server + * software, if NULL, "libwebsockets". */ + + const char *error_document_404; + /**< VHOST: If non-NULL, when asked to serve a non-existent file, + * lws attempts to server this url path instead. Eg, + * "/404.html" */ + int port; + /**< VHOST: Port to listen on. Use CONTEXT_PORT_NO_LISTEN to suppress + * listening for a client. Use CONTEXT_PORT_NO_LISTEN_SERVER if you are + * writing a server but you are using \ref sock-adopt instead of the + * built-in listener. + * + * You can also set port to 0, in which case the kernel will pick + * a random port that is not already in use. You can find out what + * port the vhost is listening on using lws_get_vhost_listen_port() */ + + unsigned int http_proxy_port; + /**< VHOST: If http_proxy_address was non-NULL, uses this port */ + unsigned int max_http_header_data2; + /**< CONTEXT: if max_http_header_data is 0 and this + * is nonzero, this will be used in place of the default. It's + * like this for compatibility with the original short version, + * this is unsigned int length. */ + unsigned int max_http_header_pool2; + /**< CONTEXT: if max_http_header_pool is 0 and this + * is nonzero, this will be used in place of the default. It's + * like this for compatibility with the original short version: + * this is unsigned int length. */ + + int keepalive_timeout; + /**< VHOST: (default = 0 = 5s, 31s for http/2) seconds to allow remote + * client to hold on to an idle HTTP/1.1 connection. Timeout lifetime + * applied to idle h2 network connections */ + uint32_t http2_settings[7]; + /**< VHOST: if http2_settings[0] is nonzero, the values given in + * http2_settings[1]..[6] are used instead of the lws + * platform default values. + * Just leave all at 0 if you don't care. + */ + + unsigned short max_http_header_data; + /**< CONTEXT: The max amount of header payload that can be handled + * in an http request (unrecognized header payload is dropped) */ + unsigned short max_http_header_pool; + /**< CONTEXT: The max number of connections with http headers that + * can be processed simultaneously (the corresponding memory is + * allocated and deallocated dynamically as needed). If the pool is + * fully busy new incoming connections must wait for accept until one + * becomes free. 0 = allow as many ah as number of availble fds for + * the process */ + +#endif + +#if defined(LWS_WITH_TLS) const char *ssl_private_key_password; /**< VHOST: NULL or the passphrase needed for the private key. (For * backwards compatibility, this can also be used to pass the client @@ -307,19 +407,166 @@ * SEE .tls1_3_plus_cipher_list and .client_tls_1_3_plus_cipher_list * for the equivalent for tls1.3. */ - const char *http_proxy_address; - /**< VHOST: If non-NULL, attempts to proxy via the given address. - * If proxy auth is required, use format - * "username:password\@server:port" */ - unsigned int http_proxy_port; - /**< VHOST: If http_proxy_address was non-NULL, uses this port */ + const char *ecdh_curve; + /**< VHOST: if NULL, defaults to initializing server with + * "prime256v1" */ + const char *tls1_3_plus_cipher_list; + /**< VHOST: List of valid ciphers to use for incoming server connections + * ON TLS1.3 AND ABOVE (eg, "TLS_CHACHA20_POLY1305_SHA256" on this vhost + * or you can leave it as NULL to get "DEFAULT". + * SEE .client_tls_1_3_plus_cipher_list to do the same on the vhost + * client SSL_CTX. + */ + + const void *server_ssl_cert_mem; + /**< VHOST: Alternative for \p ssl_cert_filepath that allows setting + * from memory instead of from a file. At most one of + * \p ssl_cert_filepath or \p server_ssl_cert_mem should be non-NULL. */ + const void *server_ssl_private_key_mem; + /**< VHOST: Alternative for \p ssl_private_key_filepath allowing + * init from a private key in memory instead of a file. At most one + * of \p ssl_private_key_filepath or \p server_ssl_private_key_mem + * should be non-NULL. */ + const void *server_ssl_ca_mem; + /**< VHOST: Alternative for \p ssl_ca_filepath allowing + * init from a CA cert in memory instead of a file. At most one + * of \p ssl_ca_filepath or \p server_ssl_ca_mem should be non-NULL. */ + + long ssl_options_set; + /**< VHOST: Any bits set here will be set as server SSL options */ + long ssl_options_clear; + /**< VHOST: Any bits set here will be cleared as server SSL options */ + int simultaneous_ssl_restriction; + /**< CONTEXT: 0 (no limit) or limit of simultaneous SSL sessions + * possible.*/ + int ssl_info_event_mask; + /**< VHOST: mask of ssl events to be reported on LWS_CALLBACK_SSL_INFO + * callback for connections on this vhost. The mask values are of + * the form SSL_CB_ALERT, defined in openssl/ssl.h. The default of + * 0 means no info events will be reported. + */ + unsigned int server_ssl_cert_mem_len; + /**< VHOST: Server SSL context init: length of server_ssl_cert_mem in + * bytes */ + unsigned int server_ssl_private_key_mem_len; + /**< VHOST: length of \p server_ssl_private_key_mem in memory */ + unsigned int server_ssl_ca_mem_len; + /**< VHOST: length of \p server_ssl_ca_mem in memory */ + + const char *alpn; + /**< CONTEXT: If non-NULL, default list of advertised alpn, comma- + * separated + * + * VHOST: If non-NULL, per-vhost list of advertised alpn, comma- + * separated + */ + + +#if defined(LWS_WITH_CLIENT) + const char *client_ssl_private_key_password; + /**< VHOST: Client SSL context init: NULL or the passphrase needed + * for the private key */ + const char *client_ssl_cert_filepath; + /**< VHOST: Client SSL context init: The certificate the client + * should present to the peer on connection */ + const void *client_ssl_cert_mem; + /**< VHOST: Client SSL context init: client certificate memory buffer or + * NULL... use this to load client cert from memory instead of file */ + unsigned int client_ssl_cert_mem_len; + /**< VHOST: Client SSL context init: length of client_ssl_cert_mem in + * bytes */ + const char *client_ssl_private_key_filepath; + /**< VHOST: Client SSL context init: filepath to client private key + * if this is set to NULL but client_ssl_cert_filepath is set, you + * can handle the LWS_CALLBACK_OPENSSL_LOAD_EXTRA_CLIENT_VERIFY_CERTS + * callback of protocols[0] to allow setting of the private key directly + * via tls library calls */ + const void *client_ssl_key_mem; + /**< VHOST: Client SSL context init: client key memory buffer or + * NULL... use this to load client key from memory instead of file */ + const char *client_ssl_ca_filepath; + /**< VHOST: Client SSL context init: CA certificate filepath or NULL */ + const void *client_ssl_ca_mem; + /**< VHOST: Client SSL context init: CA certificate memory buffer or + * NULL... use this to load CA cert from memory instead of file */ + + const char *client_ssl_cipher_list; + /**< VHOST: Client SSL context init: List of valid ciphers to use (eg, + * "RC4-MD5:RC4-SHA:AES128-SHA:AES256-SHA:HIGH:!DSS:!aNULL" + * or you can leave it as NULL to get "DEFAULT" */ + const char *client_tls_1_3_plus_cipher_list; + /**< VHOST: List of valid ciphers to use for outgoing client connections + * ON TLS1.3 AND ABOVE on this vhost (eg, + * "TLS_CHACHA20_POLY1305_SHA256") or you can leave it as NULL to get + * "DEFAULT". + */ + + long ssl_client_options_set; + /**< VHOST: Any bits set here will be set as CLIENT SSL options */ + long ssl_client_options_clear; + /**< VHOST: Any bits set here will be cleared as CLIENT SSL options */ + + + unsigned int client_ssl_ca_mem_len; + /**< VHOST: Client SSL context init: length of client_ssl_ca_mem in + * bytes */ + unsigned int client_ssl_key_mem_len; + /**< VHOST: Client SSL context init: length of client_ssl_key_mem in + * bytes */ + +#endif + +#if !defined(LWS_WITH_MBEDTLS) + SSL_CTX *provided_client_ssl_ctx; + /**< CONTEXT: If non-null, swap out libwebsockets ssl + * implementation for the one provided by provided_ssl_ctx. + * Libwebsockets no longer is responsible for freeing the context + * if this option is selected. */ +#endif +#endif + + int ka_time; + /**< CONTEXT: 0 for no TCP keepalive, otherwise apply this keepalive + * timeout to all libwebsocket sockets, client or server */ + int ka_probes; + /**< CONTEXT: if ka_time was nonzero, after the timeout expires how many + * times to try to get a response from the peer before giving up + * and killing the connection */ + int ka_interval; + /**< CONTEXT: if ka_time was nonzero, how long to wait before each ka_probes + * attempt */ + unsigned int timeout_secs; + /**< VHOST: various processes involving network roundtrips in the + * library are protected from hanging forever by timeouts. If + * nonzero, this member lets you set the timeout used in seconds. + * Otherwise a default timeout is used. */ + unsigned int connect_timeout_secs; + /**< VHOST: client connections have this long to find a working server + * from the DNS results, or the whole connection times out. If zero, + * a default timeout is used */ + int bind_iface; + /**< VHOST: nonzero to strictly bind sockets to the interface name in + * .iface (eg, "eth2"), using SO_BIND_TO_DEVICE. + * + * Requires SO_BINDTODEVICE support from your OS and CAP_NET_RAW + * capability. + * + * Notice that common things like access network interface IP from + * your local machine use your lo / loopback interface and will be + * disallowed by this. + */ + unsigned int timeout_secs_ah_idle; + /**< VHOST: seconds to allow a client to hold an ah without using it. + * 0 defaults to 10s. */ +#endif /* WITH_NETWORK */ + int gid; /**< CONTEXT: group id to change to after setting listen socket, * or -1. See also .username below. */ int uid; /**< CONTEXT: user id to change to after setting listen socket, * or -1. See also .groupname below. */ - unsigned int options; + uint64_t options; /**< VHOST + CONTEXT: 0, or LWS_SERVER_OPTION_... bitfields */ void *user; /**< VHOST + CONTEXT: optional user pointer that will be associated @@ -330,37 +577,6 @@ * if you care about giving the context and vhost different user pointer * values. */ - int ka_time; - /**< CONTEXT: 0 for no TCP keepalive, otherwise apply this keepalive - * timeout to all libwebsocket sockets, client or server */ - int ka_probes; - /**< CONTEXT: if ka_time was nonzero, after the timeout expires how many - * times to try to get a response from the peer before giving up - * and killing the connection */ - int ka_interval; - /**< CONTEXT: if ka_time was nonzero, how long to wait before each ka_probes - * attempt */ -#if defined(LWS_WITH_TLS) && !defined(LWS_WITH_MBEDTLS) - SSL_CTX *provided_client_ssl_ctx; - /**< CONTEXT: If non-null, swap out libwebsockets ssl - * implementation for the one provided by provided_ssl_ctx. - * Libwebsockets no longer is responsible for freeing the context - * if this option is selected. */ -#else /* maintain structure layout either way */ - void *provided_client_ssl_ctx; /**< dummy if ssl disabled */ -#endif - - unsigned short max_http_header_data; - /**< CONTEXT: The max amount of header payload that can be handled - * in an http request (unrecognized header payload is dropped) */ - unsigned short max_http_header_pool; - /**< CONTEXT: The max number of connections with http headers that - * can be processed simultaneously (the corresponding memory is - * allocated and deallocated dynamically as needed). If the pool is - * fully busy new incoming connections must wait for accept until one - * becomes free. 0 = allow as many ah as number of availble fds for - * the process */ - unsigned int count_threads; /**< CONTEXT: how many contexts to create in an array, 0 = 1 */ unsigned int fd_limit_per_thread; @@ -379,73 +595,15 @@ * cancel pipe, so you may need to allow for some extras for normal * operation. */ - unsigned int timeout_secs; - /**< VHOST: various processes involving network roundtrips in the - * library are protected from hanging forever by timeouts. If - * nonzero, this member lets you set the timeout used in seconds. - * Otherwise a default timeout is used. */ - const char *ecdh_curve; - /**< VHOST: if NULL, defaults to initializing server with - * "prime256v1" */ const char *vhost_name; /**< VHOST: name of vhost, must match external DNS name used to * access the site, like "warmcat.com" as it's used to match * Host: header and / or SNI name for SSL. */ +#if defined(LWS_WITH_PLUGINS) const char * const *plugin_dirs; /**< CONTEXT: NULL, or NULL-terminated array of directories to * scan for lws protocol plugins at context creation time */ - const struct lws_protocol_vhost_options *pvo; - /**< VHOST: pointer to optional linked list of per-vhost - * options made accessible to protocols */ - int keepalive_timeout; - /**< VHOST: (default = 0 = 5s) seconds to allow remote - * client to hold on to an idle HTTP/1.1 connection */ - const char *log_filepath; - /**< VHOST: filepath to append logs to... this is opened before - * any dropping of initial privileges */ - const struct lws_http_mount *mounts; - /**< VHOST: optional linked list of mounts for this vhost */ - const char *server_string; - /**< CONTEXT: string used in HTTP headers to identify server - * software, if NULL, "libwebsockets". */ - unsigned int pt_serv_buf_size; - /**< CONTEXT: 0 = default of 4096. This buffer is used by - * various service related features including file serving, it - * defines the max chunk of file that can be sent at once. - * At the risk of lws having to buffer failed large sends, it - * can be increased to, eg, 128KiB to improve throughput. */ - unsigned int max_http_header_data2; - /**< CONTEXT: if max_http_header_data is 0 and this - * is nonzero, this will be used in place of the default. It's - * like this for compatibility with the original short version, - * this is unsigned int length. */ - long ssl_options_set; - /**< VHOST: Any bits set here will be set as server SSL options */ - long ssl_options_clear; - /**< VHOST: Any bits set here will be cleared as server SSL options */ - unsigned short ws_ping_pong_interval; - /**< CONTEXT: 0 for none, else interval in seconds between sending - * PINGs on idle websocket connections. When the PING is sent, - * the PONG must come within the normal timeout_secs timeout period - * or the connection will be dropped. - * Any RX or TX traffic on the connection restarts the interval timer, - * so a connection which always sends or receives something at intervals - * less than the interval given here will never send PINGs / expect - * PONGs. Conversely as soon as the ws connection is established, an - * idle connection will do the PING / PONG roundtrip as soon as - * ws_ping_pong_interval seconds has passed without traffic - */ - const struct lws_protocol_vhost_options *headers; - /**< VHOST: pointer to optional linked list of per-vhost - * canned headers that are added to server responses */ - - const struct lws_protocol_vhost_options *reject_service_keywords; - /**< CONTEXT: Optional list of keywords and rejection codes + text. - * - * The keywords are checked for existing in the user agent string. - * - * Eg, "badrobot" "404 Not Found" - */ +#endif void *external_baggage_free_on_destroy; /**< CONTEXT: NULL, or pointer to something externally malloc'd, that * should be freed when the context is destroyed. This allows you to @@ -454,38 +612,14 @@ * succeeded to create. */ - const char *client_ssl_private_key_password; - /**< VHOST: Client SSL context init: NULL or the passphrase needed - * for the private key */ - const char *client_ssl_cert_filepath; - /**< VHOST: Client SSL context init: The certificate the client - * should present to the peer on connection */ - const void *client_ssl_cert_mem; - /**< VHOST: Client SSL context init: client certificate memory buffer or - * NULL... use this to load client cert from memory instead of file */ - unsigned int client_ssl_cert_mem_len; - /**< VHOST: Client SSL context init: length of client_ssl_cert_mem in - * bytes */ - const char *client_ssl_private_key_filepath; - /**< VHOST: Client SSL context init: filepath to client private key - * if this is set to NULL but client_ssl_cert_filepath is set, you - * can handle the LWS_CALLBACK_OPENSSL_LOAD_EXTRA_CLIENT_VERIFY_CERTS - * callback of protocols[0] to allow setting of the private key directly - * via tls library calls */ - const char *client_ssl_ca_filepath; - /**< VHOST: Client SSL context init: CA certificate filepath or NULL */ - const void *client_ssl_ca_mem; - /**< VHOST: Client SSL context init: CA certificate memory buffer or - * NULL... use this to load CA cert from memory instead of file */ - unsigned int client_ssl_ca_mem_len; - /**< VHOST: Client SSL context init: length of client_ssl_ca_mem in - * bytes */ - - const char *client_ssl_cipher_list; - /**< VHOST: Client SSL context init: List of valid ciphers to use (eg, - * "RC4-MD5:RC4-SHA:AES128-SHA:AES256-SHA:HIGH:!DSS:!aNULL" - * or you can leave it as NULL to get "DEFAULT" */ + unsigned int pt_serv_buf_size; + /**< CONTEXT: 0 = default of 4096. This buffer is used by + * various service related features including file serving, it + * defines the max chunk of file that can be sent at once. + * At the risk of lws having to buffer failed large sends, it + * can be increased to, eg, 128KiB to improve throughput. */ +#if defined(LWS_WITH_FILE_OPS) const struct lws_plat_file_ops *fops; /**< CONTEXT: NULL, or pointer to an array of fops structs, terminated * by a sentinel with NULL .open. @@ -493,15 +627,19 @@ * If NULL, lws provides just the platform file operations struct for * backwards compatibility. */ - int simultaneous_ssl_restriction; - /**< CONTEXT: 0 (no limit) or limit of simultaneous SSL sessions - * possible.*/ +#endif + +#if defined(LWS_WITH_SOCKS5) const char *socks_proxy_address; /**< VHOST: If non-NULL, attempts to proxy via the given address. * If proxy auth is required, use format * "username:password\@server:port" */ unsigned int socks_proxy_port; - /**< VHOST: If socks_proxy_address was non-NULL, uses this port */ + /**< VHOST: If socks_proxy_address was non-NULL, uses this port + * if nonzero, otherwise requires "server:port" in .socks_proxy_address + */ +#endif + #if defined(LWS_HAVE_SYS_CAPABILITY_H) && defined(LWS_HAVE_LIBCAP) cap_value_t caps[4]; /**< CONTEXT: array holding Linux capabilities you want to @@ -514,58 +652,6 @@ /**< CONTEXT: count of Linux capabilities in .caps[]. 0 means * no capabilities will be inherited from root (the default) */ #endif - int bind_iface; - /**< VHOST: nonzero to strictly bind sockets to the interface name in - * .iface (eg, "eth2"), using SO_BIND_TO_DEVICE. - * - * Requires SO_BINDTODEVICE support from your OS and CAP_NET_RAW - * capability. - * - * Notice that common things like access network interface IP from - * your local machine use your lo / loopback interface and will be - * disallowed by this. - */ - int ssl_info_event_mask; - /**< VHOST: mask of ssl events to be reported on LWS_CALLBACK_SSL_INFO - * callback for connections on this vhost. The mask values are of - * the form SSL_CB_ALERT, defined in openssl/ssl.h. The default of - * 0 means no info events will be reported. - */ - unsigned int timeout_secs_ah_idle; - /**< VHOST: seconds to allow a client to hold an ah without using it. - * 0 defaults to 10s. */ - unsigned short ip_limit_ah; - /**< CONTEXT: max number of ah a single IP may use simultaneously - * 0 is no limit. This is a soft limit: if the limit is - * reached, connections from that IP will wait in the ah - * waiting list and not be able to acquire an ah until - * a connection belonging to the IP relinquishes one it - * already has. - */ - unsigned short ip_limit_wsi; - /**< CONTEXT: max number of wsi a single IP may use simultaneously. - * 0 is no limit. This is a hard limit, connections from - * the same IP will simply be dropped once it acquires the - * amount of simultaneous wsi / accepted connections - * given here. - */ - uint32_t http2_settings[7]; - /**< VHOST: if http2_settings[0] is nonzero, the values given in - * http2_settings[1]..[6] are used instead of the lws - * platform default values. - * Just leave all at 0 if you don't care. - */ - const char *error_document_404; - /**< VHOST: If non-NULL, when asked to serve a non-existent file, - * lws attempts to server this url path instead. Eg, - * "/404.html" */ - const char *alpn; - /**< CONTEXT: If non-NULL, default list of advertised alpn, comma- - * separated - * - * VHOST: If non-NULL, per-vhost list of advertised alpn, comma- - * separated - */ void **foreign_loops; /**< CONTEXT: This is ignored if the context is not being started with * an event loop, ie, .options has a flag like @@ -601,30 +687,6 @@ /**< VHOST: opaque pointer lws ignores but passes to the finalize * callback. If you don't care, leave it NULL. */ - unsigned int max_http_header_pool2; - /**< CONTEXT: if max_http_header_pool is 0 and this - * is nonzero, this will be used in place of the default. It's - * like this for compatibility with the original short version: - * this is unsigned int length. */ - - long ssl_client_options_set; - /**< VHOST: Any bits set here will be set as CLIENT SSL options */ - long ssl_client_options_clear; - /**< VHOST: Any bits set here will be cleared as CLIENT SSL options */ - - const char *tls1_3_plus_cipher_list; - /**< VHOST: List of valid ciphers to use for incoming server connections - * ON TLS1.3 AND ABOVE (eg, "TLS_CHACHA20_POLY1305_SHA256" on this vhost - * or you can leave it as NULL to get "DEFAULT". - * SEE .client_tls_1_3_plus_cipher_list to do the same on the vhost - * client SSL_CTX. - */ - const char *client_tls_1_3_plus_cipher_list; - /**< VHOST: List of valid ciphers to use for outgoing client connections - * ON TLS1.3 AND ABOVE on this vhost (eg, - * "TLS_CHACHA20_POLY1305_SHA256") or you can leave it as NULL to get - * "DEFAULT". - */ const char *listen_accept_role; /**< VHOST: NULL for default, or force accepted incoming connections to * bind to this role. Uses the role names from their ops struct, eg, @@ -645,26 +707,6 @@ * the type of the user data to be known so its size can be given. */ - const void *server_ssl_cert_mem; - /**< VHOST: Alternative for \p ssl_cert_filepath that allows setting - * from memory instead of from a file. At most one of - * \p ssl_cert_filepath or \p server_ssl_cert_mem should be non-NULL. */ - unsigned int server_ssl_cert_mem_len; - /**< VHOST: Server SSL context init: length of server_ssl_cert_mem in - * bytes */ - const void *server_ssl_private_key_mem; - /**< VHOST: Alternative for \p ssl_private_key_filepath allowing - * init from a private key in memory instead of a file. At most one - * of \p ssl_private_key_filepath or \p server_ssl_private_key_mem - * should be non-NULL. */ - unsigned int server_ssl_private_key_mem_len; - /**< VHOST: length of \p server_ssl_private_key_mem in memory */ - const void *server_ssl_ca_mem; - /**< VHOST: Alternative for \p ssl_ca_filepath allowing - * init from a CA cert in memory instead of a file. At most one - * of \p ssl_ca_filepath or \p server_ssl_ca_mem should be non-NULL. */ - unsigned int server_ssl_ca_mem_len; - /**< VHOST: length of \p server_ssl_ca_mem in memory */ const char *username; /**< CONTEXT: string username for post-init * permissions. Like .uid but takes a string username. */ const char *groupname; /**< CONTEXT: string groupname for post-init @@ -676,6 +718,98 @@ const lws_system_ops_t *system_ops; /**< CONTEXT: hook up lws_system_ apis to system-specific * implementations */ +#if defined(LWS_WITH_DETAILED_LATENCY) + det_lat_buf_cb_t detailed_latency_cb; + /**< CONTEXT: NULL, or callback to receive detailed latency information + * collected for each read and write */ + const char *detailed_latency_filepath; + /**< CONTEXT: NULL, or filepath to put latency data into */ +#endif + const lws_retry_bo_t *retry_and_idle_policy; + /**< VHOST: optional retry and idle policy to apply to this vhost. + * Currently only the idle parts are applied to the connections. + */ +#if defined(LWS_WITH_SYS_STATE) + lws_state_notify_link_t * const *register_notifier_list; + /**< CONTEXT: NULL, or pointer to an array of notifiers that should + * be registered during context creation, so they can see state change + * events from very early on. The array should end with a NULL. */ +#endif +#if defined(LWS_WITH_SECURE_STREAMS) +#if defined(LWS_WITH_SECURE_STREAMS_STATIC_POLICY_ONLY) + const struct lws_ss_policy *pss_policies; /**< CONTEXT: point to first + * in a linked-list of streamtype policies prepared by user code */ +#else + const char *pss_policies_json; /**< CONTEXT: point to a string + * containing a JSON description of the secure streams policies. Set + * to NULL if not using Secure Streams. */ +#endif + const struct lws_ss_plugin **pss_plugins; /**< CONTEXT: point to an array + * of pointers to plugin structs here, terminated with a NULL ptr. + * Set to NULL if not using Secure Streams. */ + const char *ss_proxy_bind; /**< CONTEXT: NULL, or: ss_proxy_port == 0: + * point to a string giving the Unix Domain Socket address to use (start + * with @ for abstract namespace), ss_proxy_port nonzero: set the + * network interface address (not name, it's ambiguous for ipv4/6) to + * bind the tcp connection to the proxy to */ + const char *ss_proxy_address; /**< CONTEXT: NULL, or if ss_proxy_port + * nonzero: the tcp address of the ss proxy to connect to */ + uint16_t ss_proxy_port; /* 0 = if connecting to ss proxy, do it via a + * Unix Domain Socket, "+@proxy.ss.lws" if ss_proxy_bind is NULL else + * the socket path given in ss_proxy_bind (start it with a + or +@); + * nonzero means connect via a tcp socket to the tcp address in + * ss_proxy_bind and the given port */ +#endif + + int rlimit_nofile; + /**< 0 = inherit the initial ulimit for files / sockets from the startup + * environment. Nonzero = try to set the limit for this process. + */ +#if defined(LWS_WITH_PEER_LIMITS) + lws_peer_limits_notify_t pl_notify_cb; + /**< CONTEXT: NULL, or a callback to receive notifications each time a + * connection is being dropped because of peer limits. + * + * The callback provides the context, and an lws_sockaddr46 with the + * peer address and port. + */ + unsigned short ip_limit_ah; + /**< CONTEXT: max number of ah a single IP may use simultaneously + * 0 is no limit. This is a soft limit: if the limit is + * reached, connections from that IP will wait in the ah + * waiting list and not be able to acquire an ah until + * a connection belonging to the IP relinquishes one it + * already has. + */ + unsigned short ip_limit_wsi; + /**< CONTEXT: max number of wsi a single IP may use simultaneously. + * 0 is no limit. This is a hard limit, connections from + * the same IP will simply be dropped once it acquires the + * amount of simultaneous wsi / accepted connections + * given here. + */ + +#endif /* PEER_LIMITS */ +#if defined(LWS_WITH_UDP) + uint8_t udp_loss_sim_tx_pc; + /**< CONTEXT: percentage of udp writes we could have performed + * to instead not do, in order to simulate and test udp retry flow */ + uint8_t udp_loss_sim_rx_pc; + /**< CONTEXT: percentage of udp reads we actually received + * to make disappear, in order to simulate and test udp retry flow */ +#endif + +#if defined(LWS_WITH_SYS_SMD) + lws_smd_notification_cb_t early_smd_cb; + /**< CONTEXT: NULL, or an smd notification callback that will be registered + * immediately after the smd in the context is initialized. This ensures + * you can get all notifications without having to intercept the event loop + * creation, eg, when using an event library. Other callbacks can be + * registered later manually without problems. + */ + void *early_smd_opaque; + lws_smd_class_t early_smd_class_filter; +#endif /* Add new things just above here ---^ * This is part of the ABI, don't needlessly break compatibility @@ -685,7 +819,7 @@ * was not built against the newer headers. */ - void *_unused[4]; /**< dummy */ + void *_unused[2]; /**< dummy */ }; /** @@ -1012,6 +1146,18 @@ LWSMPRO_CALLBACK = 6, /**< hand by named protocol's callback */ }; +/** enum lws_authentication_mode + * This specifies the authentication mode of the mount. The basic_auth_login_file mount parameter + * is ignored unless LWSAUTHM_DEFAULT is set. + */ +enum lws_authentication_mode { + LWSAUTHM_DEFAULT = 0, /**< default authenticate only if basic_auth_login_file is provided */ + LWSAUTHM_BASIC_AUTH_CALLBACK = 1 << 28 /**< Basic auth with a custom verifier */ +}; + +/** The authentication mode is stored in the top 4 bits of lws_http_mount.auth_mask */ +#define AUTH_MODE_MASK 0xF0000000 + /** struct lws_http_mount * * arguments for mounting something in a vhost's url namespace @@ -1052,7 +1198,7 @@ unsigned char mountpoint_len; /**< length of mountpoint string */ const char *basic_auth_login_file; - /** + * Copyright (C) 2010 - 2019 Andy Green * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation: - * version 2.1 of the License. - * - * This library is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with this library; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, - * MA 02110-1301 USA + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to + * deal in the Software without restriction, including without limitation the + * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or + * sell copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS + * IN THE SOFTWARE. * * must be included manually as * diff -Nru libwebsockets-3.2.1/include/libwebsockets/lws-detailed-latency.h libwebsockets-4.1.6/include/libwebsockets/lws-detailed-latency.h --- libwebsockets-3.2.1/include/libwebsockets/lws-detailed-latency.h 1970-01-01 00:00:00.000000000 +0000 +++ libwebsockets-4.1.6/include/libwebsockets/lws-detailed-latency.h 2020-12-01 17:40:26.000000000 +0000 @@ -0,0 +1,140 @@ +/* + * libwebsockets - small server side websockets and web server implementation + * + * Copyright (C) 2010 - 2019 Andy Green + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to + * deal in the Software without restriction, including without limitation the + * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or + * sell copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS + * IN THE SOFTWARE. + * + * included from libwebsockets.h + */ + +enum { + + /* types of latency, all nonblocking except name resolution */ + + LDLT_READ, /* time taken to read LAT_DUR_PROXY_RX_TO_CLIENT_WRITE */ + LDLT_WRITE, + LDLT_NAME_RESOLUTION, /* BLOCKING: LAT_DUR_PROXY_CLIENT_REQ_TO_WRITE */ + LDLT_CONNECTION, /* conn duration: LAT_DUR_PROXY_CLIENT_REQ_TO_WRITE */ + LDLT_TLS_NEG_CLIENT, /* tls conn duration: LAT_DUR_PROXY_CLIENT_REQ_TO_WRITE */ + LDLT_TLS_NEG_SERVER, /* tls conn duration: LAT_DUR_PROXY_CLIENT_REQ_TO_WRITE */ + + LDLT_USER, + + /* interval / duration elements in latencies array */ + + LAT_DUR_PROXY_CLIENT_REQ_TO_WRITE = 0, + /* us the client spent waiting to write to proxy */ + LAT_DUR_PROXY_CLIENT_WRITE_TO_PROXY_RX, + /* us the packet took to be received by proxy */ + LAT_DUR_PROXY_PROXY_REQ_TO_WRITE, + /* us the proxy has to wait before it could write */ + LAT_DUR_PROXY_RX_TO_ONWARD_TX, + /* us the proxy spent waiting to write to destination, or + * if nonproxied, then time between write request and write */ + + LAT_DUR_USERCB, /* us duration of user callback */ + + LAT_DUR_STEPS /* last */ +}; + +typedef struct lws_detlat { + lws_usec_t earliest_write_req; + lws_usec_t earliest_write_req_pre_write; + /**< use this for interval comparison */ + const char *aux; /* name for name resolution timing */ + int type; + uint32_t latencies[LAT_DUR_STEPS]; + size_t req_size; + size_t acc_size; +} lws_detlat_t; + +typedef int (*det_lat_buf_cb_t)(struct lws_context *context, + const lws_detlat_t *d); + +/** + * lws_det_lat_cb() - inject your own latency records + * + * \param context: the lws_context + * \param d: the lws_detlat_t you have prepared + * + * For proxying or similar cases where latency information is available from + * user code rather than lws itself, you can generate your own latency callback + * events with your own lws_detlat_t. + */ + +LWS_VISIBLE LWS_EXTERN int +lws_det_lat_cb(struct lws_context *context, lws_detlat_t *d); + +/* + * detailed_latency_plot_cb() - canned save to file in plottable format cb + * + * \p context: the lws_context + * \p d: the detailed latency event information + * + * This canned callback makes it easy to export the detailed latency information + * to a file. Just set the context creation members like this + * + * #if defined(LWS_WITH_DETAILED_LATENCY) + * info.detailed_latency_cb = lws_det_lat_plot_cb; + * info.detailed_latency_filepath = "/tmp/lws-latency-results"; + * #endif + * + * and you will get a file containing information like this + * + * 718823864615 N 10589 0 0 10589 0 0 0 + * 718823880837 C 16173 0 0 16173 0 0 0 + * 718823913063 T 32212 0 0 32212 0 0 0 + * 718823931835 r 0 0 0 0 232 30 256 + * 718823948757 r 0 0 0 0 40 30 256 + * 718823948799 r 0 0 0 0 83 30 256 + * 718823965602 r 0 0 0 0 27 30 256 + * 718823965617 r 0 0 0 0 43 30 256 + * 718823965998 r 0 0 0 0 12 28 256 + * 718823983887 r 0 0 0 0 74 3 4096 + * 718823986411 w 16 87 7 110 9 80 80 + * 718824006358 w 8 68 6 82 6 80 80 + * + * which is easy to grep and pass to gnuplot. + * + * The columns are + * + * - unix time in us + * - N = Name resolution, C = TCP Connection, T = TLS negotiation server, + * t = TLS negotiation client, r = Read, w = Write + * - us duration, for w time client spent waiting to write + * - us duration, for w time data spent in transit to proxy + * - us duration, for w time proxy waited to send data + * - as a convenience, sum of last 3 columns above + * - us duration, time spent in callback + * - last 2 are actual / requested size in bytes + */ +LWS_VISIBLE LWS_EXTERN int +lws_det_lat_plot_cb(struct lws_context *context, const lws_detlat_t *d); + +/** + * lws_det_lat_active() - indicates if latencies are being measured + * + * \context: lws_context + * + * Returns 0 if latency measurement has not been set up (the callback is NULL). + * Otherwise returns 1 + */ +LWS_VISIBLE LWS_EXTERN int +lws_det_lat_active(struct lws_context *context); diff -Nru libwebsockets-3.2.1/include/libwebsockets/lws-diskcache.h libwebsockets-4.1.6/include/libwebsockets/lws-diskcache.h --- libwebsockets-3.2.1/include/libwebsockets/lws-diskcache.h 2019-12-18 14:45:31.000000000 +0000 +++ libwebsockets-4.1.6/include/libwebsockets/lws-diskcache.h 2020-12-01 17:40:26.000000000 +0000 @@ -1,24 +1,25 @@ /* - * libwebsockets - disk cache helpers + * libwebsockets - small server side websockets and web server implementation * - * Copyright (C) 2010-2018 Andy Green + * Copyright (C) 2010 - 2019 Andy Green * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation: - * version 2.1 of the License. + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to + * deal in the Software without restriction, including without limitation the + * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or + * sell copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: * - * This library is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. * - * You should have received a copy of the GNU Lesser General Public - * License along with this library; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, - * MA 02110-1301 USA - * - * included from libwebsockets.h + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS + * IN THE SOFTWARE. */ /*! \defgroup diskcache LWS disk cache diff -Nru libwebsockets-3.2.1/include/libwebsockets/lws-display.h libwebsockets-4.1.6/include/libwebsockets/lws-display.h --- libwebsockets-3.2.1/include/libwebsockets/lws-display.h 1970-01-01 00:00:00.000000000 +0000 +++ libwebsockets-4.1.6/include/libwebsockets/lws-display.h 2020-12-01 17:40:26.000000000 +0000 @@ -0,0 +1,158 @@ +/* + * lws abstract display + * + * Copyright (C) 2019 - 2020 Andy Green + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to + * deal in the Software without restriction, including without limitation the + * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or + * sell copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS + * IN THE SOFTWARE. + */ + +#if !defined(__LWS_DISPLAY_H__) +#define __LWS_DISPLAY_H__ + +#include + +typedef uint16_t lws_display_scalar; + +/* + * This is embedded in the actual display implementation object at the top, + * so a pointer to this can be cast to a pointer to the implementation object + * by any code that is specific to how it was implemented. + * + * Notice for the backlight / display intensity we contain pwm_ops... these can + * be some other pwm_ops like existing gpio pwm ops, or handled in a customized + * way like set oled contrast. Either way, the pwm level is arrived at via a + * full set of lws_led_sequences capable of generic lws transitions + */ + +typedef struct lws_display { + int (*init)(const struct lws_display *disp); + const lws_pwm_ops_t *bl_pwm_ops; + int (*contrast)(const struct lws_display *disp, uint8_t contrast); + int (*blit)(const struct lws_display *disp, const uint8_t *src, + lws_display_scalar x, lws_display_scalar y, + lws_display_scalar w, lws_display_scalar h); + int (*power)(const struct lws_display *disp, int state); + + const lws_led_sequence_def_t *bl_active; + const lws_led_sequence_def_t *bl_dim; + const lws_led_sequence_def_t *bl_transition; + + void *variant; + + int bl_index; + + lws_display_scalar w; + /**< display surface width in pixels */ + lws_display_scalar h; + /**< display surface height in pixels */ + + uint8_t latency_wake_ms; + /**< ms required after wake from sleep before display usable again... + * delay bringing up the backlight for this amount of time on wake. + * This is managed via a sul on the event loop, not blocking. */ +} lws_display_t; + +/* + * This contains dynamic data related to display state + */ + +enum lws_display_controller_state { + LWSDISPS_OFF, + LWSDISPS_AUTODIMMED, /* is in pre- blanking static dim mode */ + LWSDISPS_BECOMING_ACTIVE, /* waiting for wake latency before active */ + LWSDISPS_ACTIVE, /* is active */ + LWSDISPS_GOING_OFF /* dimming then off */ +}; + +typedef struct lws_display_state { + + lws_sorted_usec_list_t sul_autodim; + const lws_display_t *disp; + struct lws_context *ctx; + + int autodim_ms; + int off_ms; + + struct lws_led_state *bl_lcs; + + lws_led_state_chs_t chs; + /* set of sequencer transition channels */ + + enum lws_display_controller_state state; + +} lws_display_state_t; + +/** + * lws_display_state_init() - initialize display states + * + * \param lds: the display state object + * \param ctx: the lws context + * \param autodim_ms: ms since last active report to dim display (<0 = never) + * \param off_ms: ms since dim to turn display off (<0 = never) + * \param bl_lcs: the led controller instance that has the backlight + * \param disp: generic display object we belong to + * + * This initializes a display's state, and sets up the optional screen auto-dim + * and blanking on inactive, and gradual brightness change timer. + * + * - auto-dim then off: set autodim to some ms and off_ms to some ms + * - auto-dim only: set autodim to some ms and off_ms to -1 + * - off-only: set autodim to some ms and off_ms to 0 + * - neither: set both autodim and off_ms to -1 + */ +LWS_VISIBLE LWS_EXTERN void +lws_display_state_init(lws_display_state_t *lds, struct lws_context *ctx, + int autodim_ms, int off_ms, struct lws_led_state *bl_lcs, + const lws_display_t *disp); + +/** + * lws_display_state_set_brightness() - gradually change the brightness + * + * \param lds: the display state we are changing + * \param target: the target brightness to transition to + * + * Adjusts the brightness gradually twoards the target at 20Hz + */ +LWS_VISIBLE LWS_EXTERN void +lws_display_state_set_brightness(lws_display_state_t *lds, + const lws_led_sequence_def_t *pwmseq); + +/* + * lws_display_state_active() - inform the system the display is active + * + * \param lds: the display state we are marking as active + * + * Resets the auto-dim and auto-off timers and makes sure the display is on and + * at the active brightness level + */ +LWS_VISIBLE LWS_EXTERN void +lws_display_state_active(lws_display_state_t *lds); + +/* + * lws_display_state_off() - turns off the related display + * + * \param lds: the display state we are turning off + * + * Turns the display to least power mode or completely off if possible. + * Disables the timers related to dimming and blanking. + */ +LWS_VISIBLE LWS_EXTERN void +lws_display_state_off(lws_display_state_t *lds); + +#endif diff -Nru libwebsockets-3.2.1/include/libwebsockets/lws-dll2.h libwebsockets-4.1.6/include/libwebsockets/lws-dll2.h --- libwebsockets-3.2.1/include/libwebsockets/lws-dll2.h 1970-01-01 00:00:00.000000000 +0000 +++ libwebsockets-4.1.6/include/libwebsockets/lws-dll2.h 2020-12-01 17:40:26.000000000 +0000 @@ -0,0 +1,298 @@ +/* + * libwebsockets - small server side websockets and web server implementation + * + * Copyright (C) 2010 - 2019 Andy Green + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to + * deal in the Software without restriction, including without limitation the + * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or + * sell copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS + * IN THE SOFTWARE. + */ + +/** \defgroup ll linked-lists +* ##Linked list apis +* +* simple single and doubly-linked lists +*/ +///@{ + +/** + * lws_start_foreach_ll(): linkedlist iterator helper start + * + * \param type: type of iteration, eg, struct xyz * + * \param it: iterator var name to create + * \param start: start of list + * + * This helper creates an iterator and starts a while (it) { + * loop. The iterator runs through the linked list starting at start and + * ends when it gets a NULL. + * The while loop should be terminated using lws_start_foreach_ll(). + */ +#define lws_start_foreach_ll(type, it, start)\ +{ \ + type it = start; \ + while (it) { + +/** + * lws_end_foreach_ll(): linkedlist iterator helper end + * + * \param it: same iterator var name given when starting + * \param nxt: member name in the iterator pointing to next list element + * + * This helper is the partner for lws_start_foreach_ll() that ends the + * while loop. + */ + +#define lws_end_foreach_ll(it, nxt) \ + it = it->nxt; \ + } \ +} + +/** + * lws_start_foreach_ll_safe(): linkedlist iterator helper start safe against delete + * + * \param type: type of iteration, eg, struct xyz * + * \param it: iterator var name to create + * \param start: start of list + * \param nxt: member name in the iterator pointing to next list element + * + * This helper creates an iterator and starts a while (it) { + * loop. The iterator runs through the linked list starting at start and + * ends when it gets a NULL. + * The while loop should be terminated using lws_end_foreach_ll_safe(). + * Performs storage of next increment for situations where iterator can become invalidated + * during iteration. + */ +#define lws_start_foreach_ll_safe(type, it, start, nxt)\ +{ \ + type it = start; \ + while (it) { \ + type next_##it = it->nxt; + +/** + * lws_end_foreach_ll_safe(): linkedlist iterator helper end (pre increment storage) + * + * \param it: same iterator var name given when starting + * + * This helper is the partner for lws_start_foreach_ll_safe() that ends the + * while loop. It uses the precreated next_ variable already stored during + * start. + */ + +#define lws_end_foreach_ll_safe(it) \ + it = next_##it; \ + } \ +} + +/** + * lws_start_foreach_llp(): linkedlist pointer iterator helper start + * + * \param type: type of iteration, eg, struct xyz ** + * \param it: iterator var name to create + * \param start: start of list + * + * This helper creates an iterator and starts a while (it) { + * loop. The iterator runs through the linked list starting at the + * address of start and ends when it gets a NULL. + * The while loop should be terminated using lws_start_foreach_llp(). + * + * This helper variant iterates using a pointer to the previous linked-list + * element. That allows you to easily delete list members by rewriting the + * previous pointer to the element's next pointer. + */ +#define lws_start_foreach_llp(type, it, start)\ +{ \ + type it = &(start); \ + while (*(it)) { + +#define lws_start_foreach_llp_safe(type, it, start, nxt)\ +{ \ + type it = &(start); \ + type next; \ + while (*(it)) { \ + next = &((*(it))->nxt); \ + +/** + * lws_end_foreach_llp(): linkedlist pointer iterator helper end + * + * \param it: same iterator var name given when starting + * \param nxt: member name in the iterator pointing to next list element + * + * This helper is the partner for lws_start_foreach_llp() that ends the + * while loop. + */ + +#define lws_end_foreach_llp(it, nxt) \ + it = &(*(it))->nxt; \ + } \ +} + +#define lws_end_foreach_llp_safe(it) \ + it = next; \ + } \ +} + +#define lws_ll_fwd_insert(\ + ___new_object, /* pointer to new object */ \ + ___m_list, /* member for next list object ptr */ \ + ___list_head /* list head */ \ + ) {\ + ___new_object->___m_list = ___list_head; \ + ___list_head = ___new_object; \ + } + +#define lws_ll_fwd_remove(\ + ___type, /* type of listed object */ \ + ___m_list, /* member for next list object ptr */ \ + ___target, /* object to remove from list */ \ + ___list_head /* list head */ \ + ) { \ + lws_start_foreach_llp(___type **, ___ppss, ___list_head) { \ + if (*___ppss == ___target) { \ + *___ppss = ___target->___m_list; \ + break; \ + } \ + } lws_end_foreach_llp(___ppss, ___m_list); \ + } + + +/* + * doubly linked-list + */ + +/* + * lws_dll2_owner / lws_dll2 : more capable version of lws_dll. Differences: + * + * - there's an explicit lws_dll2_owner struct which holds head, tail and + * count of members. + * + * - list members all hold a pointer to their owner. So user code does not + * have to track anything about exactly what lws_dll2_owner list the object + * is a member of. + * + * - you can use lws_dll unless you want the member count or the ability to + * not track exactly which list it's on. + * + * - layout is compatible with lws_dll (but lws_dll apis will not update the + * new stuff) + */ + + +struct lws_dll2; +struct lws_dll2_owner; + +typedef struct lws_dll2 { + struct lws_dll2 *prev; + struct lws_dll2 *next; + struct lws_dll2_owner *owner; +} lws_dll2_t; + +typedef struct lws_dll2_owner { + struct lws_dll2 *tail; + struct lws_dll2 *head; + + uint32_t count; +} lws_dll2_owner_t; + +static LWS_INLINE int +lws_dll2_is_detached(const struct lws_dll2 *d) { return !d->owner; } + +static LWS_INLINE const struct lws_dll2_owner * +lws_dll2_owner(const struct lws_dll2 *d) { return d->owner; } + +static LWS_INLINE struct lws_dll2 * +lws_dll2_get_head(struct lws_dll2_owner *owner) { return owner->head; } + +static LWS_INLINE struct lws_dll2 * +lws_dll2_get_tail(struct lws_dll2_owner *owner) { return owner->tail; } + +LWS_VISIBLE LWS_EXTERN void +lws_dll2_add_head(struct lws_dll2 *d, struct lws_dll2_owner *owner); + +LWS_VISIBLE LWS_EXTERN void +lws_dll2_add_tail(struct lws_dll2 *d, struct lws_dll2_owner *owner); + +LWS_VISIBLE LWS_EXTERN void +lws_dll2_remove(struct lws_dll2 *d); + +LWS_VISIBLE LWS_EXTERN int +lws_dll2_foreach_safe(struct lws_dll2_owner *owner, void *user, + int (*cb)(struct lws_dll2 *d, void *user)); + +LWS_VISIBLE LWS_EXTERN void +lws_dll2_clear(struct lws_dll2 *d); + +LWS_VISIBLE LWS_EXTERN void +lws_dll2_owner_clear(struct lws_dll2_owner *d); + +LWS_VISIBLE LWS_EXTERN void +lws_dll2_add_before(struct lws_dll2 *d, struct lws_dll2 *after); + +LWS_VISIBLE LWS_EXTERN void +lws_dll2_add_sorted(lws_dll2_t *d, lws_dll2_owner_t *own, + int (*compare)(const lws_dll2_t *d, const lws_dll2_t *i)); + +LWS_VISIBLE LWS_EXTERN void * +_lws_dll2_search_sz_pl(lws_dll2_owner_t *own, const char *name, size_t namelen, + size_t dll2_ofs, size_t ptr_ofs); + +/* + * Searches objects in an owner list linearly and returns one with a given + * member C-string matching a supplied length-provided string if it exists, else + * NULL. + */ + +#define lws_dll2_search_sz_pl(own, name, namelen, type, membd2list, membptr) \ + ((type *)_lws_dll2_search_sz_pl(own, name, namelen, \ + offsetof(type, membd2list), \ + offsetof(type, membptr))) + +#if defined(_DEBUG) +void +lws_dll2_describe(struct lws_dll2_owner *owner, const char *desc); +#else +#define lws_dll2_describe(x, y) +#endif + +/* + * these are safe against the current container object getting deleted, + * since the hold his next in a temp and go to that next. ___tmp is + * the temp. + */ + +#define lws_start_foreach_dll_safe(___type, ___it, ___tmp, ___start) \ +{ \ + ___type ___it = ___start; \ + while (___it) { \ + ___type ___tmp = (___it)->next; + +#define lws_end_foreach_dll_safe(___it, ___tmp) \ + ___it = ___tmp; \ + } \ +} + +#define lws_start_foreach_dll(___type, ___it, ___start) \ +{ \ + ___type ___it = ___start; \ + while (___it) { + +#define lws_end_foreach_dll(___it) \ + ___it = (___it)->next; \ + } \ +} + +///@} + diff -Nru libwebsockets-3.2.1/include/libwebsockets/lws-dsh.h libwebsockets-4.1.6/include/libwebsockets/lws-dsh.h --- libwebsockets-3.2.1/include/libwebsockets/lws-dsh.h 2019-12-18 14:45:31.000000000 +0000 +++ libwebsockets-4.1.6/include/libwebsockets/lws-dsh.h 2020-12-01 17:40:26.000000000 +0000 @@ -1,24 +1,25 @@ /* * libwebsockets - small server side websockets and web server implementation * - * Copyright (C) 2010-2019 Andy Green + * Copyright (C) 2010 - 2019 Andy Green * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation: - * version 2.1 of the License. - * - * This library is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with this library; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, - * MA 02110-1301 USA - * - * included from libwebsockets.h + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to + * deal in the Software without restriction, including without limitation the + * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or + * sell copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS + * IN THE SOFTWARE. */ /* @@ -61,7 +62,7 @@ * * Returns an opaque pointer to the dsh, or NULL if allocation failed. */ -LWS_VISIBLE LWS_EXTERN lws_dsh_t * +LWS_VISIBLE LWS_EXTERN struct lws_dsh * lws_dsh_create(lws_dll2_owner_t *owner, size_t buffer_size, int count_kinds); /** @@ -79,7 +80,7 @@ * unmigratable objects are cleanly destroyed. */ LWS_VISIBLE LWS_EXTERN void -lws_dsh_destroy(lws_dsh_t **pdsh); +lws_dsh_destroy(struct lws_dsh **pdsh); /** * lws_dsh_alloc_tail() - make a suballocation inside a dsh @@ -100,8 +101,8 @@ * The suballocation is added to the kind-specific FIFO at the tail. */ LWS_VISIBLE LWS_EXTERN int -lws_dsh_alloc_tail(lws_dsh_t *dsh, int kind, const void *src1, size_t size1, - const void *src2, size_t size2); +lws_dsh_alloc_tail(struct lws_dsh *dsh, int kind, const void *src1, + size_t size1, const void *src2, size_t size2); /** * lws_dsh_free() - free a suballocation from the dsh @@ -115,7 +116,7 @@ lws_dsh_free(void **obj); /** - * lws_dsh_get_head() - free a suballocation from the dsh + * lws_dsh_get_head() - get the head allocation inside the dsh * * \param dsh: the dsh tracking the allocation * \param kind: the kind of allocation @@ -130,7 +131,7 @@ * free list. */ LWS_VISIBLE LWS_EXTERN int -lws_dsh_get_head(lws_dsh_t *dsh, int kind, void **obj, size_t *size); +lws_dsh_get_head(struct lws_dsh *dsh, int kind, void **obj, size_t *size); /** * lws_dsh_describe() - DEBUG BUILDS ONLY dump the dsh to the logs @@ -141,4 +142,4 @@ * Useful information for debugging lws_dsh */ LWS_VISIBLE LWS_EXTERN void -lws_dsh_describe(lws_dsh_t *dsh, const char *desc); +lws_dsh_describe(struct lws_dsh *dsh, const char *desc); diff -Nru libwebsockets-3.2.1/include/libwebsockets/lws-esp32.h libwebsockets-4.1.6/include/libwebsockets/lws-esp32.h --- libwebsockets-3.2.1/include/libwebsockets/lws-esp32.h 2019-12-18 14:45:31.000000000 +0000 +++ libwebsockets-4.1.6/include/libwebsockets/lws-esp32.h 1970-01-01 00:00:00.000000000 +0000 @@ -1,250 +0,0 @@ -/* - * libwebsockets - small server side websockets and web server implementation - * - * Copyright (C) 2010-2018 Andy Green - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation: - * version 2.1 of the License. - * - * This library is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with this library; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, - * MA 02110-1301 USA - * - * included from libwebsockets.h - */ - -typedef int lws_sockfd_type; -typedef int lws_filefd_type; - -/* - * Later lwip (at least 2.1.12) already defines these in its own headers - * protected by the same test as used here... if POLLIN / POLLOUT already exist - * then assume no need to declare those and struct pollfd. - * - * Older lwip needs these declarations done here. - */ - -#if !defined(POLLIN) && !defined(POLLOUT) - -struct pollfd { - lws_sockfd_type fd; /**< fd related to */ - short events; /**< which POLL... events to respond to */ - short revents; /**< which POLL... events occurred */ -}; -#define POLLIN 0x0001 -#define POLLPRI 0x0002 -#define POLLOUT 0x0004 -#define POLLERR 0x0008 -#define POLLHUP 0x0010 -#define POLLNVAL 0x0020 - -#endif - -#if defined(LWS_AMAZON_RTOS) -#include -#include -#include -#include "timers.h" -#else /* LWS_AMAZON_RTOS */ -#include -#include -#include -#include "esp_wifi.h" -#include "esp_system.h" -#include "esp_event.h" -#include "esp_event_loop.h" -#include "nvs.h" -#include "driver/gpio.h" -#include "esp_spi_flash.h" -#include "freertos/timers.h" -#endif /* LWS_AMAZON_RTOS */ - -#if !defined(CONFIG_FREERTOS_HZ) -#define CONFIG_FREERTOS_HZ 100 -#endif - -typedef TimerHandle_t uv_timer_t; -typedef void uv_cb_t(uv_timer_t *); -typedef void * uv_handle_t; - -struct timer_mapping { - uv_cb_t *cb; - uv_timer_t *t; -}; - -#define UV_VERSION_MAJOR 1 - -#define lws_uv_getloop(a, b) (NULL) - -static LWS_INLINE void uv_timer_init(void *l, uv_timer_t *t) -{ - (void)l; - *t = NULL; -} - -extern void esp32_uvtimer_cb(TimerHandle_t t); - -static LWS_INLINE void uv_timer_start(uv_timer_t *t, uv_cb_t *cb, int first, int rep) -{ - struct timer_mapping *tm = (struct timer_mapping *)malloc(sizeof(*tm)); - - if (!tm) - return; - - tm->t = t; - tm->cb = cb; - - *t = xTimerCreate("x", pdMS_TO_TICKS(first), !!rep, tm, - (TimerCallbackFunction_t)esp32_uvtimer_cb); - xTimerStart(*t, 0); -} - -static LWS_INLINE void uv_timer_stop(uv_timer_t *t) -{ - xTimerStop(*t, 0); -} - -static LWS_INLINE void uv_close(uv_handle_t *h, void *v) -{ - free(pvTimerGetTimerID((uv_timer_t)h)); - xTimerDelete(*(uv_timer_t *)h, 0); -} - - -#if !defined(LWS_AMAZON_RTOS) - -/* ESP32 helper declarations */ - -#include -#include - -#define LWS_PLUGIN_STATIC -#define LWS_MAGIC_REBOOT_TYPE_ADS 0x50001ffc -#define LWS_MAGIC_REBOOT_TYPE_REQ_FACTORY 0xb00bcafe -#define LWS_MAGIC_REBOOT_TYPE_FORCED_FACTORY 0xfaceb00b -#define LWS_MAGIC_REBOOT_TYPE_FORCED_FACTORY_BUTTON 0xf0cedfac -#define LWS_MAGIC_REBOOT_TYPE_REQ_FACTORY_ERASE_OTA 0xfac0eeee - -/* user code provides these */ - -extern void -lws_esp32_identify_physical_device(void); - -/* lws-plat-esp32 provides these */ - -typedef void (*lws_cb_scan_done)(uint16_t count, wifi_ap_record_t *recs, void *arg); - -enum genled_state { - LWSESP32_GENLED__INIT, - LWSESP32_GENLED__LOST_NETWORK, - LWSESP32_GENLED__NO_NETWORK, - LWSESP32_GENLED__CONN_AP, - LWSESP32_GENLED__GOT_IP, - LWSESP32_GENLED__OK, -}; - -struct lws_group_member { - struct lws_group_member *next; - uint64_t last_seen; - char model[16]; - char role[16]; - char host[32]; - char mac[20]; - int width, height; - struct ip4_addr addr; - struct ip6_addr addrv6; - uint8_t flags; -}; - -#define LWS_SYSTEM_GROUP_MEMBER_ADD 1 -#define LWS_SYSTEM_GROUP_MEMBER_CHANGE 2 -#define LWS_SYSTEM_GROUP_MEMBER_REMOVE 3 - -#define LWS_GROUP_FLAG_SELF 1 - -struct lws_esp32 { - char sta_ip[16]; - char sta_mask[16]; - char sta_gw[16]; - char serial[16]; - char opts[16]; - char model[16]; - char group[16]; - char role[16]; - char ssid[4][64]; - char password[4][64]; - char active_ssid[64]; - char access_pw[16]; - char hostname[32]; - char mac[20]; - char le_dns[64]; - char le_email[64]; - char region; - char inet; - char conn_ap; - - enum genled_state genled; - uint64_t genled_t; - - lws_cb_scan_done scan_consumer; - void *scan_consumer_arg; - struct lws_group_member *first; - int extant_group_members; - - char acme; - char upload; - - volatile char button_is_down; -}; - -struct lws_esp32_image { - uint32_t romfs; - uint32_t romfs_len; - uint32_t json; - uint32_t json_len; -}; - -extern struct lws_esp32 lws_esp32; -struct lws_vhost; - -extern esp_err_t -lws_esp32_event_passthru(void *ctx, system_event_t *event); -extern void -lws_esp32_wlan_config(void); -extern void -lws_esp32_wlan_start_ap(void); -extern void -lws_esp32_wlan_start_station(void); -struct lws_context_creation_info; -extern void -lws_esp32_set_creation_defaults(struct lws_context_creation_info *info); -extern struct lws_context * -lws_esp32_init(struct lws_context_creation_info *, struct lws_vhost **pvh); -extern int -lws_esp32_wlan_nvs_get(int retry); -extern esp_err_t -lws_nvs_set_str(nvs_handle handle, const char* key, const char* value); -extern void -lws_esp32_restart_guided(uint32_t type); -extern const esp_partition_t * -lws_esp_ota_get_boot_partition(void); -extern int -lws_esp32_get_image_info(const esp_partition_t *part, struct lws_esp32_image *i, char *json, int json_len); -extern int -lws_esp32_leds_network_indication(void); - -extern uint32_t lws_esp32_get_reboot_type(void); -extern uint16_t lws_esp32_sine_interp(int n); - -/* required in external code by esp32 plat (may just return if no leds) */ -extern void lws_esp32_leds_timer_cb(TimerHandle_t th); - -#endif /* LWS_AMAZON_RTOS */ diff -Nru libwebsockets-3.2.1/include/libwebsockets/lws-eventlib-exports.h libwebsockets-4.1.6/include/libwebsockets/lws-eventlib-exports.h --- libwebsockets-3.2.1/include/libwebsockets/lws-eventlib-exports.h 1970-01-01 00:00:00.000000000 +0000 +++ libwebsockets-4.1.6/include/libwebsockets/lws-eventlib-exports.h 2020-12-01 17:40:26.000000000 +0000 @@ -0,0 +1,86 @@ +/* + * libwebsockets - small server side websockets and web server implementation + * + * Copyright (C) 2010 - 2020 Andy Green + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to + * deal in the Software without restriction, including without limitation the + * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or + * sell copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS + * IN THE SOFTWARE. + * + * These are exports needed by event lib plugins. + * + * You should consider these opaque for normal user code. + */ + +LWS_VISIBLE LWS_EXTERN void * +lws_realloc(void *ptr, size_t size, const char *reason); + +LWS_VISIBLE LWS_EXTERN void +lws_vhost_destroy1(struct lws_vhost *vh); + +LWS_VISIBLE LWS_EXTERN void +lws_close_free_wsi(struct lws *wsi, enum lws_close_status reason, + const char *caller); + +struct lws_context_per_thread; +LWS_VISIBLE LWS_EXTERN void +lws_service_do_ripe_rxflow(struct lws_context_per_thread *pt); + +#if !defined(wsi_from_fd) && !defined(WIN32) && !defined(_WIN32) +struct lws_context; +LWS_VISIBLE LWS_EXTERN struct lws * +wsi_from_fd(const struct lws_context *context, int fd); +#endif + +LWS_VISIBLE LWS_EXTERN int +_lws_plat_service_forced_tsi(struct lws_context *context, int tsi); + +LWS_VISIBLE LWS_EXTERN void +lws_context_destroy2(struct lws_context *context); + +LWS_VISIBLE LWS_EXTERN void +lws_destroy_event_pipe(struct lws *wsi); + +LWS_VISIBLE LWS_EXTERN void +__lws_close_free_wsi_final(struct lws *wsi); + +#if LWS_MAX_SMP > 1 + +struct lws_mutex_refcount { + pthread_mutex_t lock; + pthread_t lock_owner; + const char *last_lock_reason; + char lock_depth; + char metadata; +}; + +LWS_VISIBLE LWS_EXTERN void +lws_mutex_refcount_assert_held(struct lws_mutex_refcount *mr); + +LWS_VISIBLE LWS_EXTERN void +lws_mutex_refcount_init(struct lws_mutex_refcount *mr); + +LWS_VISIBLE LWS_EXTERN void +lws_mutex_refcount_destroy(struct lws_mutex_refcount *mr); + +LWS_VISIBLE LWS_EXTERN void +lws_mutex_refcount_lock(struct lws_mutex_refcount *mr, const char *reason); + +LWS_VISIBLE LWS_EXTERN void +lws_mutex_refcount_unlock(struct lws_mutex_refcount *mr); + +#endif diff -Nru libwebsockets-3.2.1/include/libwebsockets/lws-freertos.h libwebsockets-4.1.6/include/libwebsockets/lws-freertos.h --- libwebsockets-3.2.1/include/libwebsockets/lws-freertos.h 1970-01-01 00:00:00.000000000 +0000 +++ libwebsockets-4.1.6/include/libwebsockets/lws-freertos.h 2020-12-01 17:40:26.000000000 +0000 @@ -0,0 +1,87 @@ +/* + * libwebsockets - small server side websockets and web server implementation + * + * Copyright (C) 2010 - 2020 Andy Green + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to + * deal in the Software without restriction, including without limitation the + * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or + * sell copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS + * IN THE SOFTWARE. + * + * This is included from libwebsockets.h if LWS_PLAT_FREERTOS + */ + +typedef int lws_sockfd_type; +typedef int lws_filefd_type; + +#if defined(LWS_AMAZON_RTOS) +#include +#include +#include +#include "timers.h" +#include + +/* + * Later lwip (at least 2.1.12) already defines these in its own headers + * protected by the same test as used here... if POLLIN / POLLOUT already exist + * then assume no need to declare those and struct pollfd. + * + * Older lwip needs these declarations done here. + */ + +#if !defined(POLLIN) && !defined(POLLOUT) + +struct pollfd { + lws_sockfd_type fd; /**< fd related to */ + short events; /**< which POLL... events to respond to */ + short revents; /**< which POLL... events occurred */ +}; +#define POLLIN 0x0001 +#define POLLPRI 0x0002 +#define POLLOUT 0x0004 +#define POLLERR 0x0008 +#define POLLHUP 0x0010 +#define POLLNVAL 0x0020 + +#endif + +#else /* LWS_AMAZON_RTOS */ +#include +#include +#include +#include "esp_wifi.h" +#include "esp_system.h" +#include "esp_event.h" +//#include "esp_event_loop.h" +#include "nvs.h" +#include "driver/gpio.h" +#include "esp_spi_flash.h" +#include "freertos/timers.h" + +#if defined(LWS_ESP_PLATFORM) +#include "lwip/sockets.h" +#include "lwip/netdb.h" +#if defined(LWS_WITH_DRIVERS) +#include "libwebsockets/lws-gpio.h" +extern const lws_gpio_ops_t lws_gpio_plat; +#endif +#endif + +#endif /* LWS_AMAZON_RTOS */ + +#if !defined(CONFIG_FREERTOS_HZ) +#define CONFIG_FREERTOS_HZ 100 +#endif diff -Nru libwebsockets-3.2.1/include/libwebsockets/lws-fts.h libwebsockets-4.1.6/include/libwebsockets/lws-fts.h --- libwebsockets-3.2.1/include/libwebsockets/lws-fts.h 2019-12-18 14:45:31.000000000 +0000 +++ libwebsockets-4.1.6/include/libwebsockets/lws-fts.h 2020-12-01 17:40:26.000000000 +0000 @@ -1,24 +1,25 @@ /* - * libwebsockets - fulltext search + * libwebsockets - small server side websockets and web server implementation * - * Copyright (C) 2010-2018 Andy Green + * Copyright (C) 2010 - 2019 Andy Green * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation: - * version 2.1 of the License. + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to + * deal in the Software without restriction, including without limitation the + * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or + * sell copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: * - * This library is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. * - * You should have received a copy of the GNU Lesser General Public - * License along with this library; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, - * MA 02110-1301 USA - * - * included from libwebsockets.h + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS + * IN THE SOFTWARE. */ /** \defgroup search Search diff -Nru libwebsockets-3.2.1/include/libwebsockets/lws-genaes.h libwebsockets-4.1.6/include/libwebsockets/lws-genaes.h --- libwebsockets-3.2.1/include/libwebsockets/lws-genaes.h 2019-12-18 14:45:31.000000000 +0000 +++ libwebsockets-4.1.6/include/libwebsockets/lws-genaes.h 2020-12-01 17:40:26.000000000 +0000 @@ -1,24 +1,25 @@ /* * libwebsockets - small server side websockets and web server implementation * - * Copyright (C) 2010 - 2018 Andy Green + * Copyright (C) 2010 - 2020 Andy Green * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation: - * version 2.1 of the License. - * - * This library is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with this library; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, - * MA 02110-1301 USA - * - * included from libwebsockets.h + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to + * deal in the Software without restriction, including without limitation the + * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or + * sell copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS + * IN THE SOFTWARE. */ /*! \defgroup generic AES @@ -62,6 +63,7 @@ /* include/libwebsockets/lws-jwk.h must be included before this */ #define LWS_AES_BLOCKSIZE 128 +#define LWS_AES_CBC_BLOCKLEN 16 struct lws_genaes_ctx { #if defined(LWS_WITH_MBEDTLS) diff -Nru libwebsockets-3.2.1/include/libwebsockets/lws-gencrypto.h libwebsockets-4.1.6/include/libwebsockets/lws-gencrypto.h --- libwebsockets-3.2.1/include/libwebsockets/lws-gencrypto.h 2019-12-18 14:45:31.000000000 +0000 +++ libwebsockets-4.1.6/include/libwebsockets/lws-gencrypto.h 2020-12-01 17:40:26.000000000 +0000 @@ -1,24 +1,25 @@ /* * libwebsockets - small server side websockets and web server implementation * - * Copyright (C) 2010 - 2018 Andy Green + * Copyright (C) 2010 - 2020 Andy Green * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation: - * version 2.1 of the License. - * - * This library is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with this library; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, - * MA 02110-1301 USA - * - * included from libwebsockets.h + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to + * deal in the Software without restriction, including without limitation the + * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or + * sell copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS + * IN THE SOFTWARE. */ /* @@ -115,3 +116,15 @@ */ LWS_VISIBLE LWS_EXTERN int lws_base64_size(int bytes); + +/** + * lws_gencrypto_padded_length() - returns PKCS#5/#7 padded length + * + * @param blocksize - blocksize to pad to + * @param len - Length of input to pad + * + * Returns the length of a buffer originally of size len after PKCS#5 or PKCS#7 + * padding has been applied to it. + */ +LWS_VISIBLE LWS_EXTERN size_t +lws_gencrypto_padded_length(size_t block_size, size_t len); diff -Nru libwebsockets-3.2.1/include/libwebsockets/lws-genec.h libwebsockets-4.1.6/include/libwebsockets/lws-genec.h --- libwebsockets-3.2.1/include/libwebsockets/lws-genec.h 2019-12-18 14:45:31.000000000 +0000 +++ libwebsockets-4.1.6/include/libwebsockets/lws-genec.h 2020-12-01 17:40:26.000000000 +0000 @@ -1,24 +1,25 @@ /* - * libwebsockets - Generic Elliptic Curve Encryption + * libwebsockets - small server side websockets and web server implementation * - * Copyright (C) 2010 - 2018 Andy Green + * Copyright (C) 2010 - 2019 Andy Green * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation: - * version 2.1 of the License. + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to + * deal in the Software without restriction, including without limitation the + * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or + * sell copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: * - * This library is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. * - * You should have received a copy of the GNU Lesser General Public - * License along with this library; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, - * MA 02110-1301 USA - * - * included from libwebsockets.h + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS + * IN THE SOFTWARE. */ enum enum_genec_alg { diff -Nru libwebsockets-3.2.1/include/libwebsockets/lws-genhash.h libwebsockets-4.1.6/include/libwebsockets/lws-genhash.h --- libwebsockets-3.2.1/include/libwebsockets/lws-genhash.h 2019-12-18 14:45:31.000000000 +0000 +++ libwebsockets-4.1.6/include/libwebsockets/lws-genhash.h 2020-12-01 17:40:26.000000000 +0000 @@ -1,24 +1,25 @@ /* * libwebsockets - small server side websockets and web server implementation * - * Copyright (C) 2010-2018 Andy Green + * Copyright (C) 2010 - 2019 Andy Green * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation: - * version 2.1 of the License. - * - * This library is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with this library; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, - * MA 02110-1301 USA - * - * included from libwebsockets.h + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to + * deal in the Software without restriction, including without limitation the + * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or + * sell copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS + * IN THE SOFTWARE. */ /*! \defgroup generichash Generic Hash @@ -73,12 +74,19 @@ mbedtls_md_context_t ctx; #else const EVP_MD *evp_type; + +#if defined(LWS_HAVE_EVP_PKEY_new_raw_private_key) + EVP_MD_CTX *ctx; + EVP_PKEY *key; +#else #if defined(LWS_HAVE_HMAC_CTX_new) HMAC_CTX *ctx; #else HMAC_CTX ctx; #endif #endif + +#endif }; /** lws_genhash_size() - get hash size in bytes diff -Nru libwebsockets-3.2.1/include/libwebsockets/lws-genrsa.h libwebsockets-4.1.6/include/libwebsockets/lws-genrsa.h --- libwebsockets-3.2.1/include/libwebsockets/lws-genrsa.h 2019-12-18 14:45:31.000000000 +0000 +++ libwebsockets-4.1.6/include/libwebsockets/lws-genrsa.h 2020-12-01 17:40:26.000000000 +0000 @@ -1,24 +1,25 @@ /* * libwebsockets - small server side websockets and web server implementation * - * Copyright (C) 2010-2018 Andy Green + * Copyright (C) 2010 - 2019 Andy Green * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation: - * version 2.1 of the License. + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to + * deal in the Software without restriction, including without limitation the + * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or + * sell copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: * - * This library is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. * - * You should have received a copy of the GNU Lesser General Public - * License along with this library; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, - * MA 02110-1301 USA - * - * included from libwebsockets.h + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS + * IN THE SOFTWARE. */ /*! \defgroup genericRSA Generic RSA diff -Nru libwebsockets-3.2.1/include/libwebsockets/lws-gpio.h libwebsockets-4.1.6/include/libwebsockets/lws-gpio.h --- libwebsockets-3.2.1/include/libwebsockets/lws-gpio.h 1970-01-01 00:00:00.000000000 +0000 +++ libwebsockets-4.1.6/include/libwebsockets/lws-gpio.h 2020-12-01 17:40:26.000000000 +0000 @@ -0,0 +1,60 @@ +/* + * Generic GPIO ops + * + * Copyright (C) 2019 - 2020 Andy Green + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to + * deal in the Software without restriction, including without limitation the + * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or + * sell copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS + * IN THE SOFTWARE. + * + * This is like an abstract class for gpio, a real implementation provides + * functions for the ops that use the underlying OS gpio arrangements. + */ + +#if !defined(__LWS_GPIO_H__) +#define __LWS_GPIO_H__ + +typedef int _lws_plat_gpio_t; + +typedef enum { + LWSGGPIO_IRQ_NONE, + LWSGGPIO_IRQ_RISING, + LWSGGPIO_IRQ_FALLING, + LWSGGPIO_IRQ_CHANGE, + LWSGGPIO_IRQ_LOW, + LWSGGPIO_IRQ_HIGH +} lws_gpio_irq_t; + +enum { + LWSGGPIO_FL_READ = (1 << 0), + LWSGGPIO_FL_WRITE = (1 << 1), + LWSGGPIO_FL_PULLUP = (1 << 2), + LWSGGPIO_FL_PULLDOWN = (1 << 3), + LWSGGPIO_FL_START_LOW = (1 << 4), +}; + +typedef void (*lws_gpio_irq_cb_t)(void *arg); + +typedef struct lws_gpio_ops { + void (*mode)(_lws_plat_gpio_t gpio, int flags); + int (*read)(_lws_plat_gpio_t gpio); + void (*set)(_lws_plat_gpio_t gpio, int val); + int (*irq_mode)(_lws_plat_gpio_t gpio, lws_gpio_irq_t irq, + lws_gpio_irq_cb_t cb, void *arg); +} lws_gpio_ops_t; + +#endif diff -Nru libwebsockets-3.2.1/include/libwebsockets/lws-http.h libwebsockets-4.1.6/include/libwebsockets/lws-http.h --- libwebsockets-3.2.1/include/libwebsockets/lws-http.h 2019-12-18 14:45:31.000000000 +0000 +++ libwebsockets-4.1.6/include/libwebsockets/lws-http.h 2020-12-01 17:40:26.000000000 +0000 @@ -1,24 +1,25 @@ /* * libwebsockets - small server side websockets and web server implementation * - * Copyright (C) 2010-2018 Andy Green + * Copyright (C) 2010 - 2020 Andy Green * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation: - * version 2.1 of the License. - * - * This library is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with this library; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, - * MA 02110-1301 USA - * - * included from libwebsockets.h + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to + * deal in the Software without restriction, including without limitation the + * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or + * sell copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS + * IN THE SOFTWARE. */ /* minimal space for typical headers and CSP stuff */ @@ -212,97 +213,129 @@ * add it at where specified so existing users are unaffected. */ enum lws_token_indexes { - WSI_TOKEN_GET_URI = 0, - WSI_TOKEN_POST_URI = 1, - WSI_TOKEN_OPTIONS_URI = 2, - WSI_TOKEN_HOST = 3, - WSI_TOKEN_CONNECTION = 4, - WSI_TOKEN_UPGRADE = 5, - WSI_TOKEN_ORIGIN = 6, - WSI_TOKEN_DRAFT = 7, - WSI_TOKEN_CHALLENGE = 8, - WSI_TOKEN_EXTENSIONS = 9, - WSI_TOKEN_KEY1 = 10, - WSI_TOKEN_KEY2 = 11, - WSI_TOKEN_PROTOCOL = 12, - WSI_TOKEN_ACCEPT = 13, - WSI_TOKEN_NONCE = 14, - WSI_TOKEN_HTTP = 15, - WSI_TOKEN_HTTP2_SETTINGS = 16, - WSI_TOKEN_HTTP_ACCEPT = 17, - WSI_TOKEN_HTTP_AC_REQUEST_HEADERS = 18, - WSI_TOKEN_HTTP_IF_MODIFIED_SINCE = 19, - WSI_TOKEN_HTTP_IF_NONE_MATCH = 20, - WSI_TOKEN_HTTP_ACCEPT_ENCODING = 21, - WSI_TOKEN_HTTP_ACCEPT_LANGUAGE = 22, - WSI_TOKEN_HTTP_PRAGMA = 23, - WSI_TOKEN_HTTP_CACHE_CONTROL = 24, - WSI_TOKEN_HTTP_AUTHORIZATION = 25, - WSI_TOKEN_HTTP_COOKIE = 26, - WSI_TOKEN_HTTP_CONTENT_LENGTH = 27, - WSI_TOKEN_HTTP_CONTENT_TYPE = 28, - WSI_TOKEN_HTTP_DATE = 29, - WSI_TOKEN_HTTP_RANGE = 30, - WSI_TOKEN_HTTP_REFERER = 31, - WSI_TOKEN_KEY = 32, - WSI_TOKEN_VERSION = 33, - WSI_TOKEN_SWORIGIN = 34, - - WSI_TOKEN_HTTP_COLON_AUTHORITY = 35, - WSI_TOKEN_HTTP_COLON_METHOD = 36, - WSI_TOKEN_HTTP_COLON_PATH = 37, - WSI_TOKEN_HTTP_COLON_SCHEME = 38, - WSI_TOKEN_HTTP_COLON_STATUS = 39, - - WSI_TOKEN_HTTP_ACCEPT_CHARSET = 40, - WSI_TOKEN_HTTP_ACCEPT_RANGES = 41, - WSI_TOKEN_HTTP_ACCESS_CONTROL_ALLOW_ORIGIN = 42, - WSI_TOKEN_HTTP_AGE = 43, - WSI_TOKEN_HTTP_ALLOW = 44, - WSI_TOKEN_HTTP_CONTENT_DISPOSITION = 45, - WSI_TOKEN_HTTP_CONTENT_ENCODING = 46, - WSI_TOKEN_HTTP_CONTENT_LANGUAGE = 47, - WSI_TOKEN_HTTP_CONTENT_LOCATION = 48, - WSI_TOKEN_HTTP_CONTENT_RANGE = 49, - WSI_TOKEN_HTTP_ETAG = 50, - WSI_TOKEN_HTTP_EXPECT = 51, - WSI_TOKEN_HTTP_EXPIRES = 52, - WSI_TOKEN_HTTP_FROM = 53, - WSI_TOKEN_HTTP_IF_MATCH = 54, - WSI_TOKEN_HTTP_IF_RANGE = 55, - WSI_TOKEN_HTTP_IF_UNMODIFIED_SINCE = 56, - WSI_TOKEN_HTTP_LAST_MODIFIED = 57, - WSI_TOKEN_HTTP_LINK = 58, - WSI_TOKEN_HTTP_LOCATION = 59, - WSI_TOKEN_HTTP_MAX_FORWARDS = 60, - WSI_TOKEN_HTTP_PROXY_AUTHENTICATE = 61, - WSI_TOKEN_HTTP_PROXY_AUTHORIZATION = 62, - WSI_TOKEN_HTTP_REFRESH = 63, - WSI_TOKEN_HTTP_RETRY_AFTER = 64, - WSI_TOKEN_HTTP_SERVER = 65, - WSI_TOKEN_HTTP_SET_COOKIE = 66, - WSI_TOKEN_HTTP_STRICT_TRANSPORT_SECURITY = 67, - WSI_TOKEN_HTTP_TRANSFER_ENCODING = 68, - WSI_TOKEN_HTTP_USER_AGENT = 69, - WSI_TOKEN_HTTP_VARY = 70, - WSI_TOKEN_HTTP_VIA = 71, - WSI_TOKEN_HTTP_WWW_AUTHENTICATE = 72, - - WSI_TOKEN_PATCH_URI = 73, - WSI_TOKEN_PUT_URI = 74, - WSI_TOKEN_DELETE_URI = 75, - - WSI_TOKEN_HTTP_URI_ARGS = 76, - WSI_TOKEN_PROXY = 77, - WSI_TOKEN_HTTP_X_REAL_IP = 78, - WSI_TOKEN_HTTP1_0 = 79, - WSI_TOKEN_X_FORWARDED_FOR = 80, - WSI_TOKEN_CONNECT = 81, - WSI_TOKEN_HEAD_URI = 82, - WSI_TOKEN_TE = 83, - WSI_TOKEN_REPLAY_NONCE = 84, - WSI_TOKEN_COLON_PROTOCOL = 85, - WSI_TOKEN_X_AUTH_TOKEN = 86, + WSI_TOKEN_GET_URI, /* 0 */ + WSI_TOKEN_POST_URI, +#if defined(LWS_WITH_HTTP_UNCOMMON_HEADERS) || defined(LWS_HTTP_HEADERS_ALL) + WSI_TOKEN_OPTIONS_URI, +#endif + WSI_TOKEN_HOST, + WSI_TOKEN_CONNECTION, + WSI_TOKEN_UPGRADE, /* 5 */ + WSI_TOKEN_ORIGIN, +#if defined(LWS_ROLE_WS) || defined(LWS_HTTP_HEADERS_ALL) + WSI_TOKEN_DRAFT, +#endif + WSI_TOKEN_CHALLENGE, +#if defined(LWS_ROLE_WS) || defined(LWS_HTTP_HEADERS_ALL) + WSI_TOKEN_EXTENSIONS, + WSI_TOKEN_KEY1, /* 10 */ + WSI_TOKEN_KEY2, + WSI_TOKEN_PROTOCOL, + WSI_TOKEN_ACCEPT, + WSI_TOKEN_NONCE, +#endif + WSI_TOKEN_HTTP, +#if defined(LWS_ROLE_H2) || defined(LWS_HTTP_HEADERS_ALL) + WSI_TOKEN_HTTP2_SETTINGS, /* 16 */ +#endif + WSI_TOKEN_HTTP_ACCEPT, +#if defined(LWS_WITH_HTTP_UNCOMMON_HEADERS) || defined(LWS_HTTP_HEADERS_ALL) + WSI_TOKEN_HTTP_AC_REQUEST_HEADERS, +#endif + WSI_TOKEN_HTTP_IF_MODIFIED_SINCE, + WSI_TOKEN_HTTP_IF_NONE_MATCH, /* 20 */ + WSI_TOKEN_HTTP_ACCEPT_ENCODING, + WSI_TOKEN_HTTP_ACCEPT_LANGUAGE, + WSI_TOKEN_HTTP_PRAGMA, + WSI_TOKEN_HTTP_CACHE_CONTROL, + WSI_TOKEN_HTTP_AUTHORIZATION, + WSI_TOKEN_HTTP_COOKIE, + WSI_TOKEN_HTTP_CONTENT_LENGTH, /* 27 */ + WSI_TOKEN_HTTP_CONTENT_TYPE, + WSI_TOKEN_HTTP_DATE, + WSI_TOKEN_HTTP_RANGE, +#if defined(LWS_WITH_HTTP_UNCOMMON_HEADERS) || defined(LWS_ROLE_H2) || defined(LWS_HTTP_HEADERS_ALL) + WSI_TOKEN_HTTP_REFERER, +#endif +#if defined(LWS_ROLE_WS) || defined(LWS_HTTP_HEADERS_ALL) + WSI_TOKEN_KEY, + WSI_TOKEN_VERSION, + WSI_TOKEN_SWORIGIN, +#endif +#if defined(LWS_ROLE_H2) || defined(LWS_HTTP_HEADERS_ALL) + WSI_TOKEN_HTTP_COLON_AUTHORITY, + WSI_TOKEN_HTTP_COLON_METHOD, + WSI_TOKEN_HTTP_COLON_PATH, + WSI_TOKEN_HTTP_COLON_SCHEME, + WSI_TOKEN_HTTP_COLON_STATUS, +#endif + +#if defined(LWS_WITH_HTTP_UNCOMMON_HEADERS) || defined(LWS_ROLE_H2) || defined(LWS_HTTP_HEADERS_ALL) + WSI_TOKEN_HTTP_ACCEPT_CHARSET, +#endif + WSI_TOKEN_HTTP_ACCEPT_RANGES, +#if defined(LWS_WITH_HTTP_UNCOMMON_HEADERS) || defined(LWS_ROLE_H2) || defined(LWS_HTTP_HEADERS_ALL) + WSI_TOKEN_HTTP_ACCESS_CONTROL_ALLOW_ORIGIN, +#endif + WSI_TOKEN_HTTP_AGE, + WSI_TOKEN_HTTP_ALLOW, + WSI_TOKEN_HTTP_CONTENT_DISPOSITION, + WSI_TOKEN_HTTP_CONTENT_ENCODING, + WSI_TOKEN_HTTP_CONTENT_LANGUAGE, + WSI_TOKEN_HTTP_CONTENT_LOCATION, + WSI_TOKEN_HTTP_CONTENT_RANGE, + WSI_TOKEN_HTTP_ETAG, + WSI_TOKEN_HTTP_EXPECT, + WSI_TOKEN_HTTP_EXPIRES, + WSI_TOKEN_HTTP_FROM, + WSI_TOKEN_HTTP_IF_MATCH, + WSI_TOKEN_HTTP_IF_RANGE, + WSI_TOKEN_HTTP_IF_UNMODIFIED_SINCE, + WSI_TOKEN_HTTP_LAST_MODIFIED, + WSI_TOKEN_HTTP_LINK, + WSI_TOKEN_HTTP_LOCATION, +#if defined(LWS_WITH_HTTP_UNCOMMON_HEADERS) || defined(LWS_ROLE_H2) || defined(LWS_HTTP_HEADERS_ALL) + WSI_TOKEN_HTTP_MAX_FORWARDS, + WSI_TOKEN_HTTP_PROXY_AUTHENTICATE, + WSI_TOKEN_HTTP_PROXY_AUTHORIZATION, +#endif + WSI_TOKEN_HTTP_REFRESH, + WSI_TOKEN_HTTP_RETRY_AFTER, + WSI_TOKEN_HTTP_SERVER, + WSI_TOKEN_HTTP_SET_COOKIE, +#if defined(LWS_WITH_HTTP_UNCOMMON_HEADERS) || defined(LWS_ROLE_H2) || defined(LWS_HTTP_HEADERS_ALL) + WSI_TOKEN_HTTP_STRICT_TRANSPORT_SECURITY, +#endif + WSI_TOKEN_HTTP_TRANSFER_ENCODING, +#if defined(LWS_WITH_HTTP_UNCOMMON_HEADERS) || defined(LWS_ROLE_H2) || defined(LWS_HTTP_HEADERS_ALL) + WSI_TOKEN_HTTP_USER_AGENT, + WSI_TOKEN_HTTP_VARY, + WSI_TOKEN_HTTP_VIA, + WSI_TOKEN_HTTP_WWW_AUTHENTICATE, +#endif +#if defined(LWS_WITH_HTTP_UNCOMMON_HEADERS) || defined(LWS_HTTP_HEADERS_ALL) + WSI_TOKEN_PATCH_URI, + WSI_TOKEN_PUT_URI, + WSI_TOKEN_DELETE_URI, +#endif + + WSI_TOKEN_HTTP_URI_ARGS, +#if defined(LWS_WITH_HTTP_UNCOMMON_HEADERS) || defined(LWS_HTTP_HEADERS_ALL) + WSI_TOKEN_PROXY, + WSI_TOKEN_HTTP_X_REAL_IP, +#endif + WSI_TOKEN_HTTP1_0, + WSI_TOKEN_X_FORWARDED_FOR, + WSI_TOKEN_CONNECT, + WSI_TOKEN_HEAD_URI, +#if defined(LWS_WITH_HTTP_UNCOMMON_HEADERS) || defined(LWS_ROLE_H2) || defined(LWS_HTTP_HEADERS_ALL) + WSI_TOKEN_TE, + WSI_TOKEN_REPLAY_NONCE, /* ACME */ +#endif +#if defined(LWS_ROLE_H2) || defined(LWS_HTTP_HEADERS_ALL) + WSI_TOKEN_COLON_PROTOCOL, +#endif + WSI_TOKEN_X_AUTH_TOKEN, /****** add new things just above ---^ ******/ @@ -323,7 +356,7 @@ /* parser state additions, no storage associated */ WSI_TOKEN_NAME_PART, -#if defined(LWS_WITH_CUSTOM_HEADERS) +#if defined(LWS_WITH_CUSTOM_HEADERS) || defined(LWS_HTTP_HEADERS_ALL) WSI_TOKEN_UNKNOWN_VALUE_PART, #endif WSI_TOKEN_SKIPPING, @@ -336,6 +369,19 @@ unsigned short token_limit[WSI_TOKEN_COUNT]; /**< max chars for this token */ }; +enum lws_h2_settings { + H2SET_HEADER_TABLE_SIZE = 1, + H2SET_ENABLE_PUSH, + H2SET_MAX_CONCURRENT_STREAMS, + H2SET_INITIAL_WINDOW_SIZE, + H2SET_MAX_FRAME_SIZE, + H2SET_MAX_HEADER_LIST_SIZE, + H2SET_RESERVED7, + H2SET_ENABLE_CONNECT_PROTOCOL, /* defined in mcmanus-httpbis-h2-ws-02 */ + + H2SET_COUNT /* always last */ +}; + /** * lws_token_to_string() - returns a textual representation of a hdr token index * @@ -606,6 +652,18 @@ const char *content_type, lws_filepos_t content_len, unsigned char **p, unsigned char *end); +enum { + LWSHUMETH_GET, + LWSHUMETH_POST, + LWSHUMETH_OPTIONS, + LWSHUMETH_PUT, + LWSHUMETH_PATCH, + LWSHUMETH_DELETE, + LWSHUMETH_CONNECT, + LWSHUMETH_HEAD, + LWSHUMETH_COLON_PATH, +}; + /** * lws_http_get_uri_and_method() - Get information on method and url * @@ -613,17 +671,7 @@ * \param puri_ptr: points to pointer to set to url * \param puri_len: points to int to set to uri length * - * Returns -1 or method index - * - * GET 0 - * POST 1 - * OPTIONS 2 - * PUT 3 - * PATCH 4 - * DELETE 5 - * CONNECT 6 - * HEAD 7 - * :path 8 + * Returns -1 or method index as one of the LWSHUMETH_ constants * * If returns method, *puri_ptr is set to the method's URI string and *puri_len * to its length @@ -745,6 +793,24 @@ lws_http_mark_sse(struct lws *wsi); /** + * lws_h2_client_stream_long_poll_rxonly() - h2 stream to immortal read-only + * + * \param wsi: h2 stream client wsi + * + * Send END_STREAM-flagged zero-length DATA frame to set client stream wsi into + * half-closed (local) and remote into half-closed (remote). Set the client + * stream wsi to be immortal (not subject to timeouts). + * + * Used if the remote server supports immortal long poll to put the stream into + * a read-only state where it can wait as long as needed for rx. + * + * Returns 0 if the process (which happens asynchronously) started or non-zero + * if it wasn't an h2 stream. + */ +LWS_VISIBLE LWS_EXTERN int +lws_h2_client_stream_long_poll_rxonly(struct lws *wsi); + +/** * lws_http_compression_apply() - apply an http compression transform * * \param wsi: the wsi to apply the compression transform to @@ -769,8 +835,94 @@ * LWS_WITH_HTTP_STREAM_COMPRESSION set, then a NOP is provided for this api, * allowing user code to build either way and use compression if available. */ -LWS_VISIBLE int +LWS_VISIBLE LWS_EXTERN int lws_http_compression_apply(struct lws *wsi, const char *name, unsigned char **p, unsigned char *end, char decomp); + +/** + * lws_http_is_redirected_to_get() - true if redirected to GET + * + * \param wsi: the wsi to check + * + * Check if the wsi is currently in GET mode, after, eg, doing a POST and + * receiving a 303. + */ +LWS_VISIBLE LWS_EXTERN int +lws_http_is_redirected_to_get(struct lws *wsi); + +/** + * lws_http_cookie_get() - return copy of named cookie if present + * + * \param wsi: the wsi to check + * \param name: name of the cookie + * \param buf: buffer to store the cookie contents into + * \param max_len: on entry, maximum length of buf... on exit, used len of buf + * + * If no cookie header, or no cookie of the requested name, or the value is + * larger than can fit in buf, returns nonzero. + * + * If the cookie is found, copies its value into buf with a terminating NUL, + * sets *max_len to the used length, and returns 0. + * + * This handles the parsing of the possibly multi-cookie header string and + * terminating the requested cookie at the next ; if present. + */ +LWS_VISIBLE LWS_EXTERN int +lws_http_cookie_get(struct lws *wsi, const char *name, char *buf, size_t *max); + +/** + * lws_http_client_http_error() - determine if the response code indicates an error + * + * \param code: the response code to test + * + * Returns nonzero if the code indicates an error, else zero if reflects a + * non-error condition + */ +#define lws_http_client_http_resp_is_error(code) (!(code < 400)) + +/** + * lws_h2_update_peer_txcredit() - manually update stream peer tx credit + * + * \param wsi: the h2 child stream whose peer credit to change + * \param sid: the stream ID, or LWS_H2_STREAM_SID for the wsi stream ID + * \param bump: signed change to confer upon peer tx credit for sid + * + * In conjunction with LCCSCF_H2_MANUAL_RXFLOW flag, allows the user code to + * selectively starve the remote peer of the ability to send us data on a client + * connection. + * + * Normally lws sends an initial window size for the peer to send to it of 0, + * but during the header phase it sends a WINDOW_UPDATE to increase the amount + * available. LCCSCF_H2_MANUAL_RXFLOW restricts this initial increase in tx + * credit for the stream, before it has been asked to send us anything, to the + * amount specified in the client info .manual_initial_tx_credit member, and + * this api can be called to send the other side permission to send us up to + * \p bump additional bytes. + * + * The nwsi tx credit is updated automatically for exactly what was sent to us + * on a stream with LCCSCF_H2_MANUAL_RXFLOW flag, but the stream's own tx credit + * must be handled manually by user code via this api. + * + * Returns 0 for success or nonzero for failure. + */ +#define LWS_H2_STREAM_SID -1 +LWS_VISIBLE LWS_EXTERN int +lws_h2_update_peer_txcredit(struct lws *wsi, int sid, int bump); + + +/** + * lws_h2_get_peer_txcredit_estimate() - return peer tx credit estimate + * + * \param wsi: the h2 child stream whose peer credit estimate to return + * + * Returns the estimated amount of tx credit at the peer, in other words the + * number of bytes the peer is authorized to send to us. + * + * It's an 'estimate' because we don't know how much is already in flight + * towards us and actually already used. + */ +LWS_VISIBLE LWS_EXTERN int +lws_h2_get_peer_txcredit_estimate(struct lws *wsi); + ///@} diff -Nru libwebsockets-3.2.1/include/libwebsockets/lws-i2c.h libwebsockets-4.1.6/include/libwebsockets/lws-i2c.h --- libwebsockets-3.2.1/include/libwebsockets/lws-i2c.h 1970-01-01 00:00:00.000000000 +0000 +++ libwebsockets-4.1.6/include/libwebsockets/lws-i2c.h 2020-12-01 17:40:26.000000000 +0000 @@ -0,0 +1,54 @@ +/* + * Generic I2C ops + * + * Copyright (C) 2019 - 2020 Andy Green + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to + * deal in the Software without restriction, including without limitation the + * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or + * sell copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS + * IN THE SOFTWARE. + * + * This is like an abstract class for i2c, a real implementation provides + * functions for the ops that use the underlying OS arrangements. + */ + +#if !defined(__LWS_I2C_H__) +#define __LWS_I2C_H__ + +#include +#include + +typedef struct lws_i2c_ops { + int (*init)(const struct lws_i2c_ops *ctx); + int (*start)(const struct lws_i2c_ops *ctx); + void (*stop)(const struct lws_i2c_ops *ctx); + int (*write)(const struct lws_i2c_ops *ctx, uint8_t data); + int (*read)(const struct lws_i2c_ops *ctx); + void (*set_ack)(const struct lws_i2c_ops *octx, int ack); +} lws_i2c_ops_t; + +/* + * These are implemented by calling the ops above, and so are generic + */ + +LWS_VISIBLE LWS_EXTERN int +lws_i2c_command(const lws_i2c_ops_t *ctx, uint8_t ads7, uint8_t c); + +LWS_VISIBLE LWS_EXTERN int +lws_i2c_command_list(const lws_i2c_ops_t *ctx, uint8_t ads7, const uint8_t *buf, + size_t len); + +#endif diff -Nru libwebsockets-3.2.1/include/libwebsockets/lws-ili9341-spi.h libwebsockets-4.1.6/include/libwebsockets/lws-ili9341-spi.h --- libwebsockets-3.2.1/include/libwebsockets/lws-ili9341-spi.h 1970-01-01 00:00:00.000000000 +0000 +++ libwebsockets-4.1.6/include/libwebsockets/lws-ili9341-spi.h 2020-12-01 17:40:26.000000000 +0000 @@ -0,0 +1,54 @@ +/* + * lws abstract display implementation for ili9341 on spi + * + * Copyright (C) 2019 - 2020 Andy Green + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to + * deal in the Software without restriction, including without limitation the + * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or + * sell copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS + * IN THE SOFTWARE. + */ + +#if !defined(__LWS_DISPLAY_ILI9341_SPI_H__) +#define __LWS_DISPLAY_ILI9341_SPI_H__ + + +typedef struct lws_display_ili9341 { + + lws_display_t disp; /* use lws_display_ili9341_ops to set */ + const lws_spi_ops_t *spi; /* spi ops */ + + const lws_gpio_ops_t *gpio; /* NULL or gpio ops */ + _lws_plat_gpio_t reset_gpio; /* if gpio ops, nReset gpio # */ + + uint8_t spi_index; /* cs index starting from 0 */ + +} lws_display_ili9341_t; + +int +lws_display_ili9341_spi_init(const struct lws_display *disp); +int +lws_display_ili9341_spi_blit(const struct lws_display *disp, const uint8_t *src, + lws_display_scalar x, lws_display_scalar y, + lws_display_scalar w, lws_display_scalar h); +int +lws_display_ili9341_spi_power(const struct lws_display *disp, int state); + +#define lws_display_ili9341_ops \ + .init = lws_display_ili9341_spi_init, \ + .blit = lws_display_ili9341_spi_blit, \ + .power = lws_display_ili9341_spi_power +#endif diff -Nru libwebsockets-3.2.1/include/libwebsockets/lws-jose.h libwebsockets-4.1.6/include/libwebsockets/lws-jose.h --- libwebsockets-3.2.1/include/libwebsockets/lws-jose.h 2019-12-18 14:45:31.000000000 +0000 +++ libwebsockets-4.1.6/include/libwebsockets/lws-jose.h 2020-12-01 17:40:26.000000000 +0000 @@ -1,24 +1,25 @@ /* * libwebsockets - small server side websockets and web server implementation * - * Copyright (C) 2010-2018 Andy Green + * Copyright (C) 2010 - 2019 Andy Green * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation: - * version 2.1 of the License. - * - * This library is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with this library; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, - * MA 02110-1301 USA - * - * included from libwebsockets.h + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to + * deal in the Software without restriction, including without limitation the + * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or + * sell copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS + * IN THE SOFTWARE. */ enum lws_jws_jose_hdr_indexes { @@ -118,6 +119,8 @@ struct lws_jws_recpient recipient[LWS_JWS_MAX_RECIPIENTS]; + char typ[32]; + /* information from the protected header part */ const struct lws_jose_jwe_alg *alg; const struct lws_jose_jwe_alg *enc_alg; diff -Nru libwebsockets-3.2.1/include/libwebsockets/lws-jwe.h libwebsockets-4.1.6/include/libwebsockets/lws-jwe.h --- libwebsockets-3.2.1/include/libwebsockets/lws-jwe.h 2019-12-18 14:45:31.000000000 +0000 +++ libwebsockets-4.1.6/include/libwebsockets/lws-jwe.h 2020-12-01 17:40:26.000000000 +0000 @@ -1,24 +1,25 @@ -/* - * libwebsockets - JSON Web Encryption + /* + * libwebsockets - small server side websockets and web server implementation * - * Copyright (C) 2010-2018 Andy Green + * Copyright (C) 2010 - 2019 Andy Green * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation: - * version 2.1 of the License. - * - * This library is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with this library; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, - * MA 02110-1301 USA - * - * included from libwebsockets.h + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to + * deal in the Software without restriction, including without limitation the + * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or + * sell copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS + * IN THE SOFTWARE. * * JWE Compact Serialization consists of * diff -Nru libwebsockets-3.2.1/include/libwebsockets/lws-jwk.h libwebsockets-4.1.6/include/libwebsockets/lws-jwk.h --- libwebsockets-3.2.1/include/libwebsockets/lws-jwk.h 2019-12-18 14:45:31.000000000 +0000 +++ libwebsockets-4.1.6/include/libwebsockets/lws-jwk.h 2020-12-01 17:40:26.000000000 +0000 @@ -1,24 +1,25 @@ /* * libwebsockets - small server side websockets and web server implementation * - * Copyright (C) 2010 - 2018 Andy Green + * Copyright (C) 2010 - 2019 Andy Green * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation: - * version 2.1 of the License. - * - * This library is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with this library; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, - * MA 02110-1301 USA - * - * included from libwebsockets.h + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to + * deal in the Software without restriction, including without limitation the + * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or + * sell copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS + * IN THE SOFTWARE. */ /*! \defgroup jwk JSON Web Keys @@ -114,19 +115,30 @@ LWS_VISIBLE LWS_EXTERN int lws_jwk_dup_oct(struct lws_jwk *jwk, const void *key, int len); +#define LWSJWKF_EXPORT_PRIVATE (1 << 0) +#define LWSJWKF_EXPORT_NOCRLF (1 << 1) + /** lws_jwk_export() - Export a JSON Web key to a textual representation * * \param jwk: the JWK object to export - * \param _private: 0 = just export public parts, 1 = export everything + * \param flags: control export options * \param p: the buffer to write the exported JWK to * \param len: the length of the buffer \p p in bytes... reduced by used amount * * Returns length of the used part of the buffer if OK, or -1 for error. * + * \p flags can be OR-ed together + * + * LWSJWKF_EXPORT_PRIVATE: default is only public part, set this to also export + * the private part + * + * LWSJWKF_EXPORT_NOCRLF: normally adds a CRLF at the end of the export, if + * you need to suppress it, set this flag + * * Serializes the content of the JWK into a char buffer. */ LWS_VISIBLE LWS_EXTERN int -lws_jwk_export(struct lws_jwk *jwk, int _private, char *p, int *len); +lws_jwk_export(struct lws_jwk *jwk, int flags, char *p, int *len); /** lws_jwk_load() - Import a JSON Web key from a file * diff -Nru libwebsockets-3.2.1/include/libwebsockets/lws-jws.h libwebsockets-4.1.6/include/libwebsockets/lws-jws.h --- libwebsockets-3.2.1/include/libwebsockets/lws-jws.h 2019-12-18 14:45:31.000000000 +0000 +++ libwebsockets-4.1.6/include/libwebsockets/lws-jws.h 2020-12-01 17:40:26.000000000 +0000 @@ -1,24 +1,25 @@ /* * libwebsockets - small server side websockets and web server implementation * - * Copyright (C) 2010-2018 Andy Green + * Copyright (C) 2010 - 2019 Andy Green * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation: - * version 2.1 of the License. - * - * This library is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with this library; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, - * MA 02110-1301 USA - * - * included from libwebsockets.h + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to + * deal in the Software without restriction, including without limitation the + * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or + * sell copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS + * IN THE SOFTWARE. */ /*! \defgroup jws JSON Web Signature @@ -397,8 +398,162 @@ * Returns either -1 if problems, or the number of bytes written to \p out. * If the section is not the first one, '.' is prepended. */ - LWS_VISIBLE LWS_EXTERN int lws_jws_encode_section(const char *in, size_t in_len, int first, char **p, char *end); + +/** + * lws_jwt_signed_validate() - check a compact JWT against a key and alg + * + * \param ctx: the lws_context + * \param jwk: the key for checking the signature + * \param alg_list: the expected alg name, like "ES512" + * \param com: the compact JWT + * \param len: the length of com + * \param temp: a temp scratchpad + * \param tl: available length of temp scratchpad + * \param out: the output buffer to hold the validated plaintext + * \param out_len: on entry, max length of out; on exit, used length of out + * + * Returns nonzero if the JWT cannot be validated or the plaintext can't fit the + * provided output buffer, or 0 if it is validated as being signed by the + * provided jwk. + * + * If validated, the plaintext in the JWT is copied into out and out_len set to + * the used length. + * + * temp can be discarded or reused after the call returned, it's used to hold + * transformations of the B64 JWS in the JWT. + */ +LWS_VISIBLE LWS_EXTERN int +lws_jwt_signed_validate(struct lws_context *ctx, struct lws_jwk *jwk, + const char *alg_list, const char *com, size_t len, + char *temp, int tl, char *out, size_t *out_len); + +/** + * lws_jwt_sign_compact() - generate a compact JWT using a key and alg + * + * \param ctx: the lws_context + * \param jwk: the signing key + * \param alg: the signing alg name, like "ES512" + * \param out: the output buffer to hold the signed JWT in compact form + * \param out_len: on entry, the length of out; on exit, the used amount of out + * \param temp: a temp scratchpad + * \param tl: available length of temp scratchpad + * \param format: a printf style format specification + * \param ...: zero or more args for the format specification + * + * Creates a JWT in a single step, from the format string and args through to + * outputting a well-formed compact JWT representation in out. + * + * Returns 0 if all is well and *out_len is the amount of data in out, else + * nonzero if failed. Temp must be large enough to hold various intermediate + * representations. + */ +LWS_VISIBLE LWS_EXTERN int +lws_jwt_sign_compact(struct lws_context *ctx, struct lws_jwk *jwk, + const char *alg, char *out, size_t *out_len, char *temp, + int tl, const char *format, ...) LWS_FORMAT(8); + +/** + * lws_jwt_token_sanity() - check a validated jwt payload for sanity + * + * \param in: the JWT payload + * \param in_len: the length of the JWT payload + * \param iss: the expected issuer of the token + * \param aud: the expected audience of the token + * \param csrf_in: NULL, or the csrf token that came in on a URL + * \param sub: a buffer to hold the subject name in the JWT (eg, account name) + * \param sub_len: the max length of the sub buffer + * \param secs_left: set to the number of seconds of valid auth left if valid + * + * This performs some generic sanity tests on validated JWT payload... + * + * - the issuer is as expected + * - the audience is us + * - current time is OK for nbf ("not before") in the token + * - current time is OK for exp ("expiry") in the token + * - if csrf_in is not NULL, that the JWK has a csrf and it matches it + * - if sub is not NULL, that the JWK provides a subject (and copies it to sub) + * + * If the tests pass, *secs_left is set to the number of remaining seconds the + * auth is valid. + * + * Returns 0 if no inconsistency, else nonzero. + */ +LWS_VISIBLE LWS_EXTERN int +lws_jwt_token_sanity(const char *in, size_t in_len, + const char *iss, const char *aud, const char *csrf_in, + char *sub, size_t sub_len, unsigned long *exp_unix_time); + +#if defined(LWS_ROLE_H1) || defined(LWS_ROLE_H2) + +struct lws_jwt_sign_set_cookie { + struct lws_jwk *jwk; + /**< entry: required signing key */ + const char *alg; + /**< entry: required signing alg, eg, "ES512" */ + const char *iss; + /**< entry: issuer name to use */ + const char *aud; + /**< entry: audience */ + const char *cookie_name; + /**< entry: the name of the cookie */ + char sub[33]; + /**< sign-entry, validate-exit: subject */ + const char *extra_json; + /**< sign-entry, validate-exit: + * optional "ext" JSON object contents for the JWT */ + size_t extra_json_len; + /**< validate-exit: + * length of optional "ext" JSON object contents for the JWT */ + const char *csrf_in; + /**< validate-entry: + * NULL, or an external CSRF token to check against what is in the JWT */ + unsigned long expiry_unix_time; + /**< sign-entry: seconds the JWT and cookie may live, + * validate-exit: expiry unix time */ +}; + +/** + * lws_jwt_sign_token_set_cookie() - creates sets a JWT in a wsi cookie + * + * \param wsi: the wsi to create the cookie header on + * \param i: structure describing what should be in the JWT + * \param p: wsi headers area + * \param end: end of wsi headers area + * + * Creates a JWT specified \p i, and attaches it to the outgoing headers on + * wsi. Returns 0 if successful. + * + * Best-practice security restrictions are applied to the cookie set action, + * including forcing httponly, and __Host- prefix. As required by __Host-, the + * cookie Path is set to /. __Host- is applied by the function, the cookie_name + * should just be "xyz" for "__Host-xyz". + * + * \p extra_json should just be the bare JSON, a { } is provided around it by + * the function if it's non-NULL. For example, "\"authorization\": 1". + * + * It's recommended the secs parameter is kept as small as consistent with one + * user session on the site if possible, eg, 10 minutes or 20 minutes. At the + * server, it can determine how much time is left in the auth and inform the + * client; if the JWT validity expires, the page should reload so the UI always + * reflects what's possible to do with the authorization state correctly. If + * the JWT expires, the user can log back in using credentials usually stored in + * the browser and auto-filled-in, so this is not very inconvenient. + * + * This is a helper on top of the other JOSE and JWT apis that somewhat crosses + * over between JWT and HTTP, since it knows about cookies. So it is only built + * if both LWS_WITH_JOSE and one of the http-related roles enabled. + */ +LWS_VISIBLE LWS_EXTERN int +lws_jwt_sign_token_set_http_cookie(struct lws *wsi, + const struct lws_jwt_sign_set_cookie *i, + uint8_t **p, uint8_t *end); +LWS_VISIBLE LWS_EXTERN int +lws_jwt_get_http_cookie_validate_jwt(struct lws *wsi, + struct lws_jwt_sign_set_cookie *i, + char *out, size_t *out_len); +#endif + ///@} diff -Nru libwebsockets-3.2.1/include/libwebsockets/lws-led.h libwebsockets-4.1.6/include/libwebsockets/lws-led.h --- libwebsockets-3.2.1/include/libwebsockets/lws-led.h 1970-01-01 00:00:00.000000000 +0000 +++ libwebsockets-4.1.6/include/libwebsockets/lws-led.h 2020-12-01 17:40:26.000000000 +0000 @@ -0,0 +1,146 @@ +/* + * Generic LED controller ops + * + * Copyright (C) 2019 - 2020 Andy Green + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to + * deal in the Software without restriction, including without limitation the + * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or + * sell copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS + * IN THE SOFTWARE. + * + * This is like an abstract class for leds, a real implementation provides + * functions for the ops that use the underlying, eg, OS gpio arrangements. + */ + +/* only b15 significant for GPIO */ +typedef uint16_t lws_led_intensity_t; +typedef uint16_t lws_led_seq_phase_t; + +/* the normalized max intensity */ +#define LWS_LED_MAX_INTENSITY (0xffff) + +/* the normalized 360 degree phase count for intensity functions */ +#define LWS_LED_FUNC_PHASE 65536 +/* used when the sequence doesn't stop by itself and goes around forever */ +#define LWS_SEQ_LEDPHASE_TOTAL_ENDLESS (-1) + +#define LWS_LED_SEQUENCER_UPDATE_INTERVAL_MS 33 + +struct lws_led_state; /* opaque */ +struct lws_pwm_ops; /* forward ref */ + +typedef lws_led_intensity_t (*lws_led_lookup_t)(lws_led_seq_phase_t ph); + +typedef struct lws_led_sequence_def_t { + lws_led_lookup_t func; + lws_led_seq_phase_t ledphase_offset; + int ledphase_total; /* 65536= one cycle */ + uint16_t ms; + uint8_t flags; +} lws_led_sequence_def_t; + +enum { + LLSI_CURR, + LLSI_NEXT, + LLSI_TRANS +}; + +typedef struct lws_led_state_ch +{ + const lws_led_sequence_def_t *seq; /* NULL = inactive */ + lws_led_seq_phase_t ph; + lws_led_seq_phase_t step; + int phase_budget; + lws_led_intensity_t last; + /**< at the end of the sequence we decouple the sequencer, but leave + * the last computed sample behind for further transitions to base off + */ +} lws_led_state_ch_t; + +typedef struct lws_led_state_chs +{ + lws_led_state_ch_t seqs[3]; +} lws_led_state_chs_t; + +/* this should always be first in the subclassed implementation types */ + +typedef struct lws_led_ops { + void (*intensity)(const struct lws_led_ops *lo, const char *name, + lws_led_intensity_t inten); + /**< for BOOL led control like GPIO, only inten b15 is significant */ + struct lws_led_state * (*create)(const struct lws_led_ops *led_ops); + void (*destroy)(struct lws_led_state *); +} lws_led_ops_t; + +typedef struct lws_led_gpio_map { + const char *name; + _lws_plat_gpio_t gpio; + lws_led_lookup_t intensity_correction; + /**< May be NULL. If GPIO-based LED, ignored. If pwm_ops provided, + * NULL means use default CIE 100% correction function. If non-NULL, + * use the pointed-to correction function. This is useful to provide + * LED-specific intensity correction / scaling so different types of + * LED can "look the same". */ + const struct lws_pwm_ops *pwm_ops; + /**< if NULL, gpio controls the led directly. If set to a pwm_ops, + * the led control is outsourced to the pwm controller. */ + uint8_t active_level; +} lws_led_gpio_map_t; + +typedef struct lws_led_gpio_controller { + const lws_led_ops_t led_ops; + + const lws_gpio_ops_t *gpio_ops; + const lws_led_gpio_map_t *led_map; + uint8_t count_leds; +} lws_led_gpio_controller_t; + +/* ops */ + +LWS_VISIBLE LWS_EXTERN struct lws_led_state * +lws_led_gpio_create(const lws_led_ops_t *led_ops); + +LWS_VISIBLE LWS_EXTERN void +lws_led_gpio_destroy(struct lws_led_state *lcs); + +/** + * lws_led_gpio_intensity() - set the static intensity of an led + * + * \param lo: the base class of the led controller + * \param index: which led in the controller set + * \param inten: 16-bit unsigned intensity + * + * For LEDs controlled by a BOOL like GPIO, only inten b15 is significant. + * For PWM type LED control, as many bits as the hardware can support from b15 + * down are significant. + */ +LWS_VISIBLE LWS_EXTERN void +lws_led_gpio_intensity(const struct lws_led_ops *lo, const char *name, + lws_led_intensity_t inten); + +LWS_VISIBLE LWS_EXTERN int +lws_led_transition(struct lws_led_state *lcs, const char *name, + const lws_led_sequence_def_t *next, + const lws_led_sequence_def_t *trans); + + +#define lws_led_gpio_ops \ + { \ + .create = lws_led_gpio_create, \ + .destroy = lws_led_gpio_destroy, \ + .intensity = lws_led_gpio_intensity, \ + } + diff -Nru libwebsockets-3.2.1/include/libwebsockets/lws-lejp.h libwebsockets-4.1.6/include/libwebsockets/lws-lejp.h --- libwebsockets-3.2.1/include/libwebsockets/lws-lejp.h 2019-12-18 14:45:31.000000000 +0000 +++ libwebsockets-4.1.6/include/libwebsockets/lws-lejp.h 2020-12-01 17:40:26.000000000 +0000 @@ -1,24 +1,25 @@ /* * libwebsockets - small server side websockets and web server implementation * - * Copyright (C) 2010-2018 Andy Green + * Copyright (C) 2010 - 2019 Andy Green * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation: - * version 2.1 of the License. - * - * This library is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with this library; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, - * MA 02110-1301 USA - * - * included from libwebsockets.h + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to + * deal in the Software without restriction, including without limitation the + * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or + * sell copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS + * IN THE SOFTWARE. */ /** \defgroup lejp JSON parser @@ -152,11 +153,12 @@ * * LEJPCB_VAL_STR_START: We are starting to parse a string, no data yet * - * LEJPCB_VAL_STR_CHUNK: We parsed LEJP_STRING_CHUNK -1 bytes of string data in - * ctx->buf, which is as much as we can buffer, so we are - * spilling it. If all your strings are less than - * LEJP_STRING_CHUNK - 1 bytes, you will never see this - * callback. + * LEJPCB_VAL_STR_CHUNK: We filled the string buffer in the ctx, but it's not + * the end of the string. We produce this to spill the + * intermediate buffer to the user code, so we can handle + * huge JSON strings using only the small buffer in the + * ctx. If the whole JSON string fits in the ctx buffer, + * you won't get these callbacks. * * LEJPCB_VAL_STR_END: String parsing has completed, the last chunk of the * string is in ctx->buf. @@ -254,6 +256,7 @@ uint8_t path_match_len; uint8_t wildcount; uint8_t pst_sp; /* parsing stack head */ + uint8_t outer_array; }; LWS_VISIBLE LWS_EXTERN void diff -Nru libwebsockets-3.2.1/include/libwebsockets/lws-logs.h libwebsockets-4.1.6/include/libwebsockets/lws-logs.h --- libwebsockets-3.2.1/include/libwebsockets/lws-logs.h 2019-12-18 14:45:31.000000000 +0000 +++ libwebsockets-4.1.6/include/libwebsockets/lws-logs.h 2020-12-01 17:40:26.000000000 +0000 @@ -1,24 +1,25 @@ /* * libwebsockets - small server side websockets and web server implementation * - * Copyright (C) 2010-2018 Andy Green + * Copyright (C) 2010 - 2019 Andy Green * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation: - * version 2.1 of the License. - * - * This library is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with this library; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, - * MA 02110-1301 USA - * - * included from libwebsockets.h + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to + * deal in the Software without restriction, including without limitation the + * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or + * sell copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS + * IN THE SOFTWARE. */ /** \defgroup log Logging @@ -33,22 +34,20 @@ */ ///@{ -enum lws_log_levels { - LLL_ERR = 1 << 0, - LLL_WARN = 1 << 1, - LLL_NOTICE = 1 << 2, - LLL_INFO = 1 << 3, - LLL_DEBUG = 1 << 4, - LLL_PARSER = 1 << 5, - LLL_HEADER = 1 << 6, - LLL_EXT = 1 << 7, - LLL_CLIENT = 1 << 8, - LLL_LATENCY = 1 << 9, - LLL_USER = 1 << 10, - LLL_THREAD = 1 << 11, +#define LLL_ERR (1 << 0) +#define LLL_WARN (1 << 1) +#define LLL_NOTICE (1 << 2) +#define LLL_INFO (1 << 3) +#define LLL_DEBUG (1 << 4) +#define LLL_PARSER (1 << 5) +#define LLL_HEADER (1 << 6) +#define LLL_EXT (1 << 7) +#define LLL_CLIENT (1 << 8) +#define LLL_LATENCY (1 << 9) +#define LLL_USER (1 << 10) +#define LLL_THREAD (1 << 11) - LLL_COUNT = 12 /* set to count of valid flags */ -}; +#define LLL_COUNT (12) /* set to count of valid flags */ /** * lwsl_timestamp: generate logging timestamp string @@ -69,51 +68,124 @@ LWS_VISIBLE LWS_EXTERN void _lws_logv(int filter, const char *format, va_list vl); #endif -/* these guys are unconditionally included */ +/* + * Figure out which logs to build in or not + */ -#define lwsl_err(...) _lws_log(LLL_ERR, __VA_ARGS__) -#define lwsl_user(...) _lws_log(LLL_USER, __VA_ARGS__) +#if defined(_DEBUG) + /* + * In DEBUG build, select all logs unless NO_LOGS + */ + #if defined(LWS_WITH_NO_LOGS) + #define _LWS_LINIT (LLL_ERR | LLL_USER) + #else + #define _LWS_LINIT ((1 << LLL_COUNT) - 1) + #endif +#else /* not _DEBUG */ + #define _LWS_LINIT (LLL_ERR | LLL_USER | LLL_WARN | LLL_NOTICE) +#endif /* _DEBUG */ -#if !defined(LWS_WITH_NO_LOGS) -/* notice and warn are usually included by being compiled in */ -#define lwsl_warn(...) _lws_log(LLL_WARN, __VA_ARGS__) -#define lwsl_notice(...) _lws_log(LLL_NOTICE, __VA_ARGS__) +/* + * Create either empty overrides or the ones forced at build-time. + * These overrides have the final say... any bits set in + * LWS_LOGGING_BITFIELD_SET force the build of those logs, any bits + * set in LWS_LOGGING_BITFIELD_CLEAR disable the build of those logs. + * + * If not defined lws decides based on CMAKE_BUILD_TYPE=DEBUG or not + */ + +#if defined(LWS_LOGGING_BITFIELD_SET) + #define _LWS_LBS (LWS_LOGGING_BITFIELD_SET) +#else + #define _LWS_LBS 0 #endif + +#if defined(LWS_LOGGING_BITFIELD_CLEAR) + #define _LWS_LBC (LWS_LOGGING_BITFIELD_CLEAR) +#else + #define _LWS_LBC 0 +#endif + /* - * weaker logging can be deselected by telling CMake to build in RELEASE mode - * that gets rid of the overhead of checking while keeping _warn and _err - * active + * Compute the final active logging bitfield for build */ +#define _LWS_ENABLED_LOGS (((_LWS_LINIT) | (_LWS_LBS)) & ~(_LWS_LBC)) -#if defined(_DEBUG) -#if defined(LWS_WITH_NO_LOGS) -/* notice, warn and log are always compiled in */ -#define lwsl_warn(...) _lws_log(LLL_WARN, __VA_ARGS__) -#define lwsl_notice(...) _lws_log(LLL_NOTICE, __VA_ARGS__) +/* + * Individually enable or disable log levels for build + * depending on what was computed + */ + +#if (_LWS_ENABLED_LOGS & LLL_ERR) +#define lwsl_err(...) _lws_log(LLL_ERR, __VA_ARGS__) +#else +#define lwsl_err(...) do {} while(0) #endif -#define lwsl_info(...) _lws_log(LLL_INFO, __VA_ARGS__) -#define lwsl_debug(...) _lws_log(LLL_DEBUG, __VA_ARGS__) -#define lwsl_parser(...) _lws_log(LLL_PARSER, __VA_ARGS__) -#define lwsl_header(...) _lws_log(LLL_HEADER, __VA_ARGS__) -#define lwsl_ext(...) _lws_log(LLL_EXT, __VA_ARGS__) -#define lwsl_client(...) _lws_log(LLL_CLIENT, __VA_ARGS__) -#define lwsl_latency(...) _lws_log(LLL_LATENCY, __VA_ARGS__) -#define lwsl_thread(...) _lws_log(LLL_THREAD, __VA_ARGS__) -#else /* no debug */ -#if defined(LWS_WITH_NO_LOGS) +#if (_LWS_ENABLED_LOGS & LLL_WARN) +#define lwsl_warn(...) _lws_log(LLL_WARN, __VA_ARGS__) +#else #define lwsl_warn(...) do {} while(0) +#endif + +#if (_LWS_ENABLED_LOGS & LLL_NOTICE) +#define lwsl_notice(...) _lws_log(LLL_NOTICE, __VA_ARGS__) +#else #define lwsl_notice(...) do {} while(0) #endif + +#if (_LWS_ENABLED_LOGS & LLL_INFO) +#define lwsl_info(...) _lws_log(LLL_INFO, __VA_ARGS__) +#else #define lwsl_info(...) do {} while(0) +#endif + +#if (_LWS_ENABLED_LOGS & LLL_DEBUG) +#define lwsl_debug(...) _lws_log(LLL_DEBUG, __VA_ARGS__) +#else #define lwsl_debug(...) do {} while(0) +#endif + +#if (_LWS_ENABLED_LOGS & LLL_PARSER) +#define lwsl_parser(...) _lws_log(LLL_PARSER, __VA_ARGS__) +#else #define lwsl_parser(...) do {} while(0) +#endif + +#if (_LWS_ENABLED_LOGS & LLL_HEADER) +#define lwsl_header(...) _lws_log(LLL_HEADER, __VA_ARGS__) +#else #define lwsl_header(...) do {} while(0) +#endif + +#if (_LWS_ENABLED_LOGS & LLL_EXT) +#define lwsl_ext(...) _lws_log(LLL_EXT, __VA_ARGS__) +#else #define lwsl_ext(...) do {} while(0) +#endif + +#if (_LWS_ENABLED_LOGS & LLL_CLIENT) +#define lwsl_client(...) _lws_log(LLL_CLIENT, __VA_ARGS__) +#else #define lwsl_client(...) do {} while(0) +#endif + +#if (_LWS_ENABLED_LOGS & LLL_LATENCY) +#define lwsl_latency(...) _lws_log(LLL_LATENCY, __VA_ARGS__) +#else #define lwsl_latency(...) do {} while(0) +#endif + +#if (_LWS_ENABLED_LOGS & LLL_THREAD) +#define lwsl_thread(...) _lws_log(LLL_THREAD, __VA_ARGS__) +#else #define lwsl_thread(...) do {} while(0) +#endif +#if (_LWS_ENABLED_LOGS & LLL_USER) +#define lwsl_user(...) _lws_log(LLL_USER, __VA_ARGS__) +#else +#define lwsl_user(...) do {} while(0) #endif diff -Nru libwebsockets-3.2.1/include/libwebsockets/lws-lwsac.h libwebsockets-4.1.6/include/libwebsockets/lws-lwsac.h --- libwebsockets-3.2.1/include/libwebsockets/lws-lwsac.h 2019-12-18 14:45:31.000000000 +0000 +++ libwebsockets-4.1.6/include/libwebsockets/lws-lwsac.h 2020-12-01 17:40:26.000000000 +0000 @@ -1,24 +1,25 @@ /* - * libwebsockets - lws alloc chunk + * libwebsockets - small server side websockets and web server implementation * - * Copyright (C) 2018 Andy Green + * Copyright (C) 2010 - 2020 Andy Green * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation: - * version 2.1 of the License. - * - * This library is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with this library; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, - * MA 02110-1301 USA - * - * included from libwebsockets.h + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to + * deal in the Software without restriction, including without limitation the + * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or + * sell copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS + * IN THE SOFTWARE. */ /** \defgroup lwsac lwsac @@ -94,13 +95,16 @@ * whatever is necessary to return you a pointer to ensure bytes of memory * reserved for the caller. * + * This always allocates in the current chunk or a new chunk... see the + * lwsac_use_backfill() variant to try first to find space in earlier chunks. + * * Returns NULL if OOM. */ LWS_VISIBLE LWS_EXTERN void * lwsac_use(struct lwsac **head, size_t ensure, size_t chunk_size); /** - * lwsac_use_zero - allocate / use some memory from a lwsac and zero it + * lwsac_use_backfill - allocate / use some memory from a lwsac * * \param head: pointer to the lwsac list object * \param ensure: the number of bytes we want to use @@ -113,12 +117,13 @@ * whatever is necessary to return you a pointer to ensure bytes of memory * reserved for the caller. * - * \p ensure bytes at the return address are zeroed if the allocation succeeded. + * Also checks if earlier blocks have enough remaining space to take the + * allocation before making a new allocation. * * Returns NULL if OOM. */ LWS_VISIBLE LWS_EXTERN void * -lwsac_use_zero(struct lwsac **head, size_t ensure, size_t chunk_size); +lwsac_use_backfill(struct lwsac **head, size_t ensure, size_t chunk_size); /** * lwsac_use - allocate / use some memory from a lwsac @@ -136,7 +141,9 @@ * Returns NULL if OOM. */ LWS_VISIBLE LWS_EXTERN void * -lwsac_use_zeroed(struct lwsac **head, size_t ensure, size_t chunk_size); +lwsac_use_zero(struct lwsac **head, size_t ensure, size_t chunk_size); + +#define lwsac_use_zeroed lwsac_use_zero /** * lwsac_free - deallocate all chunks in the lwsac and set head NULL @@ -191,6 +198,38 @@ LWS_VISIBLE LWS_EXTERN void lwsac_unreference(struct lwsac **head); +/** + * lwsac_extend() - try to increase the size of the last block + * + * \param head: pointer to the lwsac list object + * \param amount: amount to try to increase usage for + * + * This will either increase the usage reservation of the last allocated block + * by amount and return 0, or fail and return 1. + * + * This is very cheap to call and is designed to optimize usage after a static + * struct for vari-sized additional content which may flow into an additional + * block in a new chunk if necessary, but wants to make the most of the space + * in front of it first to try to avoid gaps and the new chunk if it can. + * + * The additional area if the call succeeds will have been memset to 0. + * + * To use it, the following must be true: + * + * - only the last lwsac use can be extended + * + * - if another use happens inbetween the use and extend, it will break + * + * - the use cannot have been using backfill + * + * - a user object must be tracking the current allocated size of the last use + * (lwsac doesn't know it) and increment by amount if the extend call succeeds + * + * Despite these restrictions this can be an important optimization for some + * cases + */ +LWS_VISIBLE LWS_EXTERN int +lwsac_extend(struct lwsac *head, int amount); /* helpers to keep a file cached in memory */ @@ -209,8 +248,9 @@ /* more advanced helpers */ +/* offset from lac to start of payload, first = 1 = first lac in chain */ LWS_VISIBLE LWS_EXTERN size_t -lwsac_sizeof(void); +lwsac_sizeof(int first); LWS_VISIBLE LWS_EXTERN size_t lwsac_get_tail_pos(struct lwsac *lac); @@ -227,4 +267,24 @@ LWS_VISIBLE LWS_EXTERN uint64_t lwsac_total_alloc(struct lwsac *head); +LWS_VISIBLE LWS_EXTERN uint64_t +lwsac_total_overhead(struct lwsac *head); + +/** + * lwsac_scan_extant() - returns existing copy of blob, or NULL + * + * \param head: the lwsac to scan + * \param find: the blob to look for + * \param len: the length of the blob to look for + * \param nul: nonzero if the next byte must be NUL + * + * Helper that looks through a whole lwsac for a given binary blob already + * present. Used in the case that lwsac contents are const once written, and + * strings or blobs may be repeated in the input: this allows the earlier + * copy to be pointed to by subsequent references without repeating the string + * or blob redundantly. + */ +LWS_VISIBLE LWS_EXTERN uint8_t * +lwsac_scan_extant(struct lwsac *head, uint8_t *find, size_t len, int nul); + ///@} diff -Nru libwebsockets-3.2.1/include/libwebsockets/lws-misc.h libwebsockets-4.1.6/include/libwebsockets/lws-misc.h --- libwebsockets-3.2.1/include/libwebsockets/lws-misc.h 2019-12-18 14:45:31.000000000 +0000 +++ libwebsockets-4.1.6/include/libwebsockets/lws-misc.h 2020-12-01 17:40:26.000000000 +0000 @@ -1,26 +1,36 @@ /* * libwebsockets - small server side websockets and web server implementation * - * Copyright (C) 2010-2018 Andy Green + * Copyright (C) 2010 - 2019 Andy Green * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation: - * version 2.1 of the License. - * - * This library is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with this library; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, - * MA 02110-1301 USA - * - * included from libwebsockets.h + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to + * deal in the Software without restriction, including without limitation the + * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or + * sell copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS + * IN THE SOFTWARE. */ +#if defined(LWS_WITH_SPAWN) + +#if defined(WIN32) || defined(_WIN32) +#else +#include +#include +#endif +#endif + /** \defgroup misc Miscellaneous APIs * ##Miscellaneous APIs * @@ -28,313 +38,6 @@ */ ///@{ -/** - * lws_start_foreach_ll(): linkedlist iterator helper start - * - * \param type: type of iteration, eg, struct xyz * - * \param it: iterator var name to create - * \param start: start of list - * - * This helper creates an iterator and starts a while (it) { - * loop. The iterator runs through the linked list starting at start and - * ends when it gets a NULL. - * The while loop should be terminated using lws_start_foreach_ll(). - */ -#define lws_start_foreach_ll(type, it, start)\ -{ \ - type it = start; \ - while (it) { - -/** - * lws_end_foreach_ll(): linkedlist iterator helper end - * - * \param it: same iterator var name given when starting - * \param nxt: member name in the iterator pointing to next list element - * - * This helper is the partner for lws_start_foreach_ll() that ends the - * while loop. - */ - -#define lws_end_foreach_ll(it, nxt) \ - it = it->nxt; \ - } \ -} - -/** - * lws_start_foreach_ll_safe(): linkedlist iterator helper start safe against delete - * - * \param type: type of iteration, eg, struct xyz * - * \param it: iterator var name to create - * \param start: start of list - * \param nxt: member name in the iterator pointing to next list element - * - * This helper creates an iterator and starts a while (it) { - * loop. The iterator runs through the linked list starting at start and - * ends when it gets a NULL. - * The while loop should be terminated using lws_end_foreach_ll_safe(). - * Performs storage of next increment for situations where iterator can become invalidated - * during iteration. - */ -#define lws_start_foreach_ll_safe(type, it, start, nxt)\ -{ \ - type it = start; \ - while (it) { \ - type next_##it = it->nxt; - -/** - * lws_end_foreach_ll_safe(): linkedlist iterator helper end (pre increment storage) - * - * \param it: same iterator var name given when starting - * - * This helper is the partner for lws_start_foreach_ll_safe() that ends the - * while loop. It uses the precreated next_ variable already stored during - * start. - */ - -#define lws_end_foreach_ll_safe(it) \ - it = next_##it; \ - } \ -} - -/** - * lws_start_foreach_llp(): linkedlist pointer iterator helper start - * - * \param type: type of iteration, eg, struct xyz ** - * \param it: iterator var name to create - * \param start: start of list - * - * This helper creates an iterator and starts a while (it) { - * loop. The iterator runs through the linked list starting at the - * address of start and ends when it gets a NULL. - * The while loop should be terminated using lws_start_foreach_llp(). - * - * This helper variant iterates using a pointer to the previous linked-list - * element. That allows you to easily delete list members by rewriting the - * previous pointer to the element's next pointer. - */ -#define lws_start_foreach_llp(type, it, start)\ -{ \ - type it = &(start); \ - while (*(it)) { - -#define lws_start_foreach_llp_safe(type, it, start, nxt)\ -{ \ - type it = &(start); \ - type next; \ - while (*(it)) { \ - next = &((*(it))->nxt); \ - -/** - * lws_end_foreach_llp(): linkedlist pointer iterator helper end - * - * \param it: same iterator var name given when starting - * \param nxt: member name in the iterator pointing to next list element - * - * This helper is the partner for lws_start_foreach_llp() that ends the - * while loop. - */ - -#define lws_end_foreach_llp(it, nxt) \ - it = &(*(it))->nxt; \ - } \ -} - -#define lws_end_foreach_llp_safe(it) \ - it = next; \ - } \ -} - -#define lws_ll_fwd_insert(\ - ___new_object, /* pointer to new object */ \ - ___m_list, /* member for next list object ptr */ \ - ___list_head /* list head */ \ - ) {\ - ___new_object->___m_list = ___list_head; \ - ___list_head = ___new_object; \ - } - -#define lws_ll_fwd_remove(\ - ___type, /* type of listed object */ \ - ___m_list, /* member for next list object ptr */ \ - ___target, /* object to remove from list */ \ - ___list_head /* list head */ \ - ) { \ - lws_start_foreach_llp(___type **, ___ppss, ___list_head) { \ - if (*___ppss == ___target) { \ - *___ppss = ___target->___m_list; \ - break; \ - } \ - } lws_end_foreach_llp(___ppss, ___m_list); \ - } - -/* - * doubly linked-list - */ - -#if defined (LWS_WITH_DEPRECATED_LWS_DLL) - -/* - * This is going away in v4.1. You can set the cmake option above to keep it - * around temporarily. Migrate your stuff to the more capable and robust - * lws_dll2 below - */ - -struct lws_dll { - struct lws_dll *prev; - struct lws_dll *next; -}; - -/* - * these all point to the composed list objects... you have to use the - * lws_container_of() helper to recover the start of the containing struct - */ - -#define lws_dll_add_front lws_dll_add_head - -LWS_VISIBLE LWS_EXTERN void -lws_dll_add_head(struct lws_dll *d, struct lws_dll *phead); - -LWS_VISIBLE LWS_EXTERN void -lws_dll_add_tail(struct lws_dll *d, struct lws_dll *phead); - -LWS_VISIBLE LWS_EXTERN void -lws_dll_insert(struct lws_dll *d, struct lws_dll *target, - struct lws_dll *phead, int before); - -static LWS_INLINE struct lws_dll * -lws_dll_get_head(struct lws_dll *phead) { return phead->next; } - -static LWS_INLINE struct lws_dll * -lws_dll_get_tail(struct lws_dll *phead) { return phead->prev; } - -/* - * caution, this doesn't track the tail in the head struct. Use - * lws_dll_remove_track_tail() instead of this if you want tail tracking. Using - * this means you can't use lws_dll_add_tail() amd - */ -LWS_VISIBLE LWS_EXTERN void -lws_dll_remove(struct lws_dll *d) LWS_WARN_DEPRECATED; - -LWS_VISIBLE LWS_EXTERN void -lws_dll_remove_track_tail(struct lws_dll *d, struct lws_dll *phead); - -/* another way to do lws_start_foreach_dll_safe() on a list via a cb */ - -LWS_VISIBLE LWS_EXTERN int -lws_dll_foreach_safe(struct lws_dll *phead, void *user, - int (*cb)(struct lws_dll *d, void *user)); - -#define lws_dll_is_detached(___dll, __head) \ - (!(___dll)->prev && !(___dll)->next && (__head)->prev != (___dll)) - -#endif - -/* - * lws_dll2_owner / lws_dll2 : more capable version of lws_dll. Differences: - * - * - there's an explicit lws_dll2_owner struct which holds head, tail and - * count of members. - * - * - list members all hold a pointer to their owner. So user code does not - * have to track anything about exactly what lws_dll2_owner list the object - * is a member of. - * - * - you can use lws_dll unless you want the member count or the ability to - * not track exactly which list it's on. - * - * - layout is compatible with lws_dll (but lws_dll apis will not update the - * new stuff) - */ - - -struct lws_dll2; -struct lws_dll2_owner; - -typedef struct lws_dll2 { - struct lws_dll2 *prev; - struct lws_dll2 *next; - struct lws_dll2_owner *owner; -} lws_dll2_t; - -typedef struct lws_dll2_owner { - struct lws_dll2 *tail; - struct lws_dll2 *head; - - uint32_t count; -} lws_dll2_owner_t; - -static LWS_INLINE int -lws_dll2_is_detached(const struct lws_dll2 *d) { return !d->owner; } - -static LWS_INLINE const struct lws_dll2_owner * -lws_dll2_owner(const struct lws_dll2 *d) { return d->owner; } - -static LWS_INLINE struct lws_dll2 * -lws_dll2_get_head(struct lws_dll2_owner *owner) { return owner->head; } - -static LWS_INLINE struct lws_dll2 * -lws_dll2_get_tail(struct lws_dll2_owner *owner) { return owner->tail; } - -LWS_VISIBLE LWS_EXTERN void -lws_dll2_add_head(struct lws_dll2 *d, struct lws_dll2_owner *owner); - -LWS_VISIBLE LWS_EXTERN void -lws_dll2_add_tail(struct lws_dll2 *d, struct lws_dll2_owner *owner); - -LWS_VISIBLE LWS_EXTERN void -lws_dll2_remove(struct lws_dll2 *d); - -LWS_VISIBLE LWS_EXTERN int -lws_dll2_foreach_safe(struct lws_dll2_owner *owner, void *user, - int (*cb)(struct lws_dll2 *d, void *user)); - -LWS_VISIBLE LWS_EXTERN void -lws_dll2_clear(struct lws_dll2 *d); - -LWS_VISIBLE LWS_EXTERN void -lws_dll2_owner_clear(struct lws_dll2_owner *d); - -LWS_VISIBLE LWS_EXTERN void -lws_dll2_add_before(struct lws_dll2 *d, struct lws_dll2 *after); - -LWS_VISIBLE LWS_EXTERN void -lws_dll2_add_sorted(lws_dll2_t *d, lws_dll2_owner_t *own, - int (*compare)(const lws_dll2_t *d, const lws_dll2_t *i)); - -#if defined(_DEBUG) -void -lws_dll2_describe(struct lws_dll2_owner *owner, const char *desc); -#else -#define lws_dll2_describe(x, y) -#endif - -/* - * these are safe against the current container object getting deleted, - * since the hold his next in a temp and go to that next. ___tmp is - * the temp. - */ - -#define lws_start_foreach_dll_safe(___type, ___it, ___tmp, ___start) \ -{ \ - ___type ___it = ___start; \ - while (___it) { \ - ___type ___tmp = (___it)->next; - -#define lws_end_foreach_dll_safe(___it, ___tmp) \ - ___it = ___tmp; \ - } \ -} - -#define lws_start_foreach_dll(___type, ___it, ___start) \ -{ \ - ___type ___it = ___start; \ - while (___it) { - -#define lws_end_foreach_dll(___it) \ - ___it = (___it)->next; \ - } \ -} - struct lws_buflist; /** @@ -378,10 +81,35 @@ * Returns the number of bytes left in the current segment. 0 indicates * that the buflist is empty (there are no segments on the buflist). */ -LWS_VISIBLE LWS_EXTERN int +LWS_VISIBLE LWS_EXTERN size_t lws_buflist_use_segment(struct lws_buflist **head, size_t len); /** + * lws_buflist_total_len(): Get the total size of the buflist + * + * \param head: list head + * + * Returns the total number of bytes held on all segments of the buflist + */ +LWS_VISIBLE LWS_EXTERN size_t +lws_buflist_total_len(struct lws_buflist **head); + +/** + * lws_buflist_linear_copy(): copy everything out as one without consuming + * + * \param head: list head + * \param ofs: start offset into buflist in bytes + * \param buf: buffer to copy linearly into + * \param len: length of buffer available + * + * Returns -1 if len is too small, or bytes copied. Happy to do partial + * copies, returns 0 when there are no more bytes to copy. + */ +LWS_VISIBLE LWS_EXTERN int +lws_buflist_linear_copy(struct lws_buflist **head, size_t ofs, uint8_t *buf, + size_t len); + +/** * lws_buflist_destroy_all_segments(): free all segments on the list * * \param head: list head @@ -392,8 +120,18 @@ LWS_VISIBLE LWS_EXTERN void lws_buflist_destroy_all_segments(struct lws_buflist **head); -void -lws_buflist_describe(struct lws_buflist **head, void *id); +/** + * lws_buflist_describe(): debug helper logging buflist status + * + * \param head: list head + * \param id: pointer shown in debug list + * \param reason: reason string show in debug list + * + * Iterates through the buflist segments showing position and size. + * This only exists when lws was built in debug mode + */ +LWS_VISIBLE LWS_EXTERN void +lws_buflist_describe(struct lws_buflist **head, void *id, const char *reason); /** * lws_ptr_diff(): helper to report distance between pointers as an int @@ -434,6 +172,76 @@ LWS_VISIBLE LWS_EXTERN char * lws_strncpy(char *dest, const char *src, size_t size); +/* + * Variation where we want to use the smaller of two lengths, useful when the + * source string is not NUL terminated + */ +#define lws_strnncpy(dest, src, size1, destsize) \ + lws_strncpy(dest, src, (size_t)(size1 + 1) < (size_t)(destsize) ? \ + (size_t)(size1 + 1) : (size_t)(destsize)) + +/** + * lws_nstrstr(): like strstr for length-based strings without terminating NUL + * + * \param buf: the string to search + * \param len: the length of the string to search + * \param name: the substring to search for + * \param nl: the length of name + * + * Returns NULL if \p name is not present in \p buf. Otherwise returns the + * address of the first instance of \p name in \p buf. + * + * Neither buf nor name need to be NUL-terminated. + */ +LWS_VISIBLE LWS_EXTERN const char * +lws_nstrstr(const char *buf, size_t len, const char *name, size_t nl); + +/** + * lws_json_simple_find(): dumb JSON string parser + * + * \param buf: the JSON to search + * \param len: the length of the JSON to search + * \param name: the name field to search the JSON for, eg, "\"myname\":" + * \param alen: set to the length of the argument part if non-NULL return + * + * Either returns NULL if \p name is not present in buf, or returns a pointer + * to the argument body of the first instance of \p name, and sets *alen to the + * length of the argument body. + * + * This can cheaply handle fishing out, eg, myarg from {"myname": "myarg"} by + * searching for "\"myname\":". It will return a pointer to myarg and set *alen + * to 5. It equally handles args like "myname": true, or "myname":false, and + * null or numbers are all returned as delimited strings. + * + * Anything more complicated like the value is a subobject or array, you should + * parse it using a full parser like lejp. This is suitable is the JSON is + * and will remain short and simple, and contains well-known names amongst other + * extensible JSON members. + */ +LWS_VISIBLE LWS_EXTERN const char * +lws_json_simple_find(const char *buf, size_t len, const char *name, size_t *alen); + +/** + * lws_json_simple_strcmp(): dumb JSON string comparison + * + * \param buf: the JSON to search + * \param len: the length of the JSON to search + * \param name: the name field to search the JSON for, eg, "\"myname\":" + * \param comp: return a strcmp of this and the discovered argument + * + * Helper that combines lws_json_simple_find() with strcmp() if it was found. + * If the \p name was not found, returns -1. Otherwise returns a strcmp() + * between what was found and \p comp, ie, return 0 if they match or something + * else if they don't. + * + * If the JSON is relatively simple and you want to target constrained + * devices, this can be a good choice. If the JSON may be complex, you + * should use a full JSON parser. + */ +LWS_VISIBLE LWS_EXTERN int +lws_json_simple_strcmp(const char *buf, size_t len, const char *name, const char *comp); + + /** * lws_hex_to_byte_array(): convert hex string like 0123456789ab into byte data * @@ -453,6 +261,26 @@ LWS_VISIBLE LWS_EXTERN int lws_hex_to_byte_array(const char *h, uint8_t *dest, int max); + +/** + * lws_hex_random(): generate len - 1 or - 2 characters of random ascii hex + * + * \param context: the lws_context used to get the random + * \param dest: destination for hex ascii chars + * \param len: the number of bytes the buffer dest points to can hold + * + * This creates random ascii-hex strings up to a given length, with a + * terminating NUL. Hex characters are produced in pairs, if the length of + * the destination buffer is even, after accounting for the NUL there will be + * an unused byte at the end after the NUL. So lengths should be odd to get + * length - 1 characters exactly followed by the NUL. + * + * There will not be any characters produced that are not 0-9, a-f, so it's + * safe to go straight into, eg, JSON. + */ +LWS_VISIBLE LWS_EXTERN int +lws_hex_random(struct lws_context *context, char *dest, size_t len); + /* * lws_timingsafe_bcmp(): constant time memcmp * @@ -479,8 +307,8 @@ * Fills buf with len bytes of random. Returns the number of bytes set, if * not equal to len, then getting the random failed. */ -LWS_VISIBLE LWS_EXTERN int -lws_get_random(struct lws_context *context, void *buf, int len); +LWS_VISIBLE LWS_EXTERN size_t +lws_get_random(struct lws_context *context, void *buf, size_t len); /** * lws_daemonize(): make current process run in the background * @@ -508,6 +336,15 @@ lws_wsi_user(struct lws *wsi); /** + * lws_wsi_tsi() - get the service thread index the wsi is bound to + * \param wsi: lws connection + * + * Only useful is LWS_MAX_SMP > 1 + */ +LWS_VISIBLE LWS_EXTERN int +lws_wsi_tsi(struct lws *wsi); + +/** * lws_set_wsi_user() - set the user data associated with the client connection * \param wsi: lws connection * \param user: user data @@ -566,6 +403,22 @@ lws_cmdline_option(int argc, const char **argv, const char *val); /** + * lws_cmdline_option_handle_builtin(): apply standard cmdline options + * + * \param argc: count of argument strings + * \param argv: argument strings + * \param info: context creation info + * + * Applies standard options to the context creation info to save them having + * to be (unevenly) copied into the minimal examples. + * + * Applies default log levels that can be overriden by -d + */ +LWS_VISIBLE LWS_EXTERN void +lws_cmdline_option_handle_builtin(int argc, const char **argv, + struct lws_context_creation_info *info); + +/** * lws_now_secs(): return seconds since 1970-1-1 */ LWS_VISIBLE LWS_EXTERN unsigned long @@ -815,6 +668,53 @@ */ LWS_VISIBLE LWS_EXTERN int lws_dir(const char *dirpath, void *user, lws_dir_callback_function cb); + +/** + * lws_dir_rm_rf_cb() - callback for lws_dir that performs recursive rm -rf + * + * \param dirpath: directory we are at in lws_dir + * \param user: ignored + * \param lde: lws_dir info on the file or directory we are at + * + * This is a readymade rm -rf callback for use with lws_dir. It recursively + * removes everything below the starting dir and then the starting dir itself. + * Works on linux, OSX and Windows at least. + */ +LWS_VISIBLE LWS_EXTERN int +lws_dir_rm_rf_cb(const char *dirpath, void *user, struct lws_dir_entry *lde); + +/* + * We pass every file in the base dir through a filter, and call back on the + * ones that match. Directories are ignored. + * + * The original path filter string may look like, eg, "sai-*.deb" or "*.txt" + */ + +typedef int (*lws_dir_glob_cb_t)(void *data, const char *path); + +typedef struct lws_dir_glob { + const char *filter; + lws_dir_glob_cb_t cb; + void *user; +} lws_dir_glob_t; + +/** + * lws_dir_glob_cb() - callback for lws_dir that performs filename globbing + * + * \param dirpath: directory we are at in lws_dir + * \param user: pointer to your prepared lws_dir_glob_cb_t + * \param lde: lws_dir info on the file or directory we are at + * + * \p user is prepared with an `lws_dir_glob_t` containing a callback for paths + * that pass the filtering, a user pointer to pass to that callback, and a + * glob string like "*.txt". It may not contain directories, the lws_dir musr + * be started at the correct dir. + * + * Only the base path passed to lws_dir is scanned, it does not look in subdirs. + */ +LWS_VISIBLE LWS_EXTERN int +lws_dir_glob_cb(const char *dirpath, void *user, struct lws_dir_entry *lde); + #endif /** @@ -835,12 +735,19 @@ size_t lws_get_allocated_heap(void); /** + * lws_get_tsi() - Get thread service index wsi belong to + * \param wsi: websocket connection to check + * + * Returns more than zero (or zero if only one service thread as is the default). + */ +LWS_VISIBLE LWS_EXTERN int +lws_get_tsi(struct lws *wsi); + +/** * lws_is_ssl() - Find out if connection is using SSL * \param wsi: websocket connection to check * - * Returns 0 if the connection is not using SSL, 1 if using SSL and - * using verified cert, and 2 if using SSL but the cert was not - * checked (appears for client wsi told to skip check on connection) + * Returns nonzero if the wsi is inside a tls tunnel, else zero. */ LWS_VISIBLE LWS_EXTERN int lws_is_ssl(struct lws *wsi); @@ -894,19 +801,19 @@ uint64_t factor; } lws_humanize_unit_t; -LWS_VISIBLE LWS_EXTERN const lws_humanize_unit_t humanize_schema_si[]; -LWS_VISIBLE LWS_EXTERN const lws_humanize_unit_t humanize_schema_si_bytes[]; -LWS_VISIBLE LWS_EXTERN const lws_humanize_unit_t humanize_schema_us[]; +LWS_VISIBLE extern const lws_humanize_unit_t humanize_schema_si[7]; +LWS_VISIBLE extern const lws_humanize_unit_t humanize_schema_si_bytes[7]; +LWS_VISIBLE extern const lws_humanize_unit_t humanize_schema_us[8]; /** - * lws_humanize() - Convert possibly large number to himan-readable uints + * lws_humanize() - Convert possibly large number to human-readable uints * * \param buf: result string buffer * \param len: remaining length in \p buf * \param value: the uint64_t value to represent * \param schema: and array of scaling factors and units * - * This produces a concise string representation of \p value, referening the + * This produces a concise string representation of \p value, referencing the * schema \p schema of scaling factors and units to find the smallest way to * render it. * @@ -923,4 +830,216 @@ lws_humanize(char *buf, int len, uint64_t value, const lws_humanize_unit_t *schema); +LWS_VISIBLE LWS_EXTERN void +lws_ser_wu16be(uint8_t *b, uint16_t u); + +LWS_VISIBLE LWS_EXTERN void +lws_ser_wu32be(uint8_t *b, uint32_t u32); + +LWS_VISIBLE LWS_EXTERN void +lws_ser_wu64be(uint8_t *b, uint64_t u64); + +LWS_VISIBLE LWS_EXTERN uint16_t +lws_ser_ru16be(const uint8_t *b); + +LWS_VISIBLE LWS_EXTERN uint32_t +lws_ser_ru32be(const uint8_t *b); + +LWS_VISIBLE LWS_EXTERN uint64_t +lws_ser_ru64be(const uint8_t *b); + +LWS_VISIBLE LWS_EXTERN int +lws_vbi_encode(uint64_t value, void *buf); + +LWS_VISIBLE LWS_EXTERN int +lws_vbi_decode(const void *buf, uint64_t *value, size_t len); + ///@} + +#if defined(LWS_WITH_SPAWN) + +/* opaque internal struct */ +struct lws_spawn_piped; + +#if defined(WIN32) +struct _lws_siginfo_t { + int retcode; +}; +typedef struct _lws_siginfo_t siginfo_t; +#endif + +typedef void (*lsp_cb_t)(void *opaque, lws_usec_t *accounting, siginfo_t *si, + int we_killed_him); + + +/** + * lws_spawn_piped_info - details given to create a spawned pipe + * + * \p owner: lws_dll2_owner_t that lists all active spawns, or NULL + * \p vh: vhost to bind stdwsi to... from opt_parent if given + * \p opt_parent: optional parent wsi for stdwsi + * \p exec_array: argv for process to spawn + * \p env_array: environment for spawned process, NULL ends env list + * \p protocol_name: NULL, or vhost protocol name to bind stdwsi to + * \p chroot_path: NULL, or chroot patch for child process + * \p wd: working directory to cd to after fork, NULL defaults to /tmp + * \p plsp: NULL, or pointer to the outer lsp pointer so it can be set NULL when destroyed + * \p opaque: pointer passed to the reap callback, if any + * \p timeout: optional us-resolution timeout, or zero + * \p reap_cb: callback when child process has been reaped and the lsp destroyed + * \p tsi: tsi to bind stdwsi to... from opt_parent if given + */ +struct lws_spawn_piped_info { + struct lws_dll2_owner *owner; + struct lws_vhost *vh; + struct lws *opt_parent; + + const char * const *exec_array; + char **env_array; + const char *protocol_name; + const char *chroot_path; + const char *wd; + + struct lws_spawn_piped **plsp; + + void *opaque; + + lsp_cb_t reap_cb; + + lws_usec_t timeout_us; + int max_log_lines; + int tsi; + + const struct lws_role_ops *ops; /* NULL is raw file */ + + uint8_t disable_ctrlc; +}; + +/** + * lws_spawn_piped() - spawn a child process with stdxxx redirected + * + * \p lspi: info struct describing details of spawn to create + * + * This spawns a child process managed in the lsp object and with attributes + * set in the arguments. The stdin/out/err streams are redirected to pipes + * which are instantiated into wsi that become child wsi of \p parent if non- + * NULL. .opaque_user_data on the stdwsi created is set to point to the + * lsp object, so this can be recovered easily in the protocol handler. + * + * If \p owner is non-NULL, successful spawns join the given dll2 owner in the + * original process. + * + * If \p timeout is non-zero, successful spawns register a sul with the us- + * resolution timeout to callback \p timeout_cb, in the original process. + * + * Returns 0 if the spawn went OK or nonzero if it failed and was cleaned up. + * The spawned process continues asynchronously and this will return after + * starting it if all went well. + */ +LWS_VISIBLE LWS_EXTERN struct lws_spawn_piped * +lws_spawn_piped(const struct lws_spawn_piped_info *lspi); + +/* + * lws_spawn_piped_kill_child_process() - attempt to kill child process + * + * \p lsp: child object to kill + * + * Attempts to signal the child process in \p lsp to terminate. + */ +LWS_VISIBLE LWS_EXTERN int +lws_spawn_piped_kill_child_process(struct lws_spawn_piped *lsp); + +/** + * lws_spawn_stdwsi_closed() - inform the spawn one of its stdxxx pipes closed + * + * \p lsp: the spawn object + * \p wsi: the wsi that is closing + * + * When you notice one of the spawn stdxxx pipes closed, inform the spawn + * instance using this api. When it sees all three have closed, it will + * automatically try to reap the child process. + * + * This is the mechanism whereby the spawn object can understand its child + * has closed. + */ +LWS_VISIBLE LWS_EXTERN void +lws_spawn_stdwsi_closed(struct lws_spawn_piped *lsp, struct lws *wsi); + +/** + * lws_spawn_get_stdfd() - return std channel index for stdwsi + * + * \p wsi: the wsi + * + * If you know wsi is a stdwsi from a spawn, you can determine its original + * channel index / fd before the pipes replaced the default fds. It will return + * one of 0 (STDIN), 1 (STDOUT) or 2 (STDERR). You can handle all three in the + * same protocol handler and then disambiguate them using this api. + */ +LWS_VISIBLE LWS_EXTERN int +lws_spawn_get_stdfd(struct lws *wsi); + +#endif + +struct lws_fsmount { + const char *layers_path; /* where layers live */ + const char *overlay_path; /* where overlay instantiations live */ + + char mp[256]; /* mountpoint path */ + char ovname[64]; /* unique name for mount instance */ + char distro[64]; /* unique name for layer source */ + +#if defined(__linux__) + const char *layers[4]; /* distro layers, like "base", "env" */ +#endif +}; + +/** + * lws_fsmount_mount() - Mounts an overlayfs stack of layers + * + * \p fsm: struct lws_fsmount specifying the mount layout + * + * This api is able to assemble up to 4 layer directories on to a mountpoint + * using overlayfs mount (Linux only). + * + * Set fsm.layers_path to the base dir where the layers themselves live, the + * entries in fsm.layers[] specifies the relative path to the layer, comprising + * fsm.layers_path/fsm.distro/fsm.layers[], with [0] being the deepest, earliest + * layer and the rest being progressively on top of [0]; NULL indicates the + * layer is unused. + * + * fsm.overlay_path is the base path of the overlayfs instantiations... empty + * dirs must exist at + * + * fsm.overlay_path/overlays/fsm.ovname/work + * fsm.overlay_path/overlays/fsm.ovname/session + * + * Set fsm.mp to the path of an already-existing empty dir that will be the + * mountpoint, this can be whereever you like. + * + * Overlayfs merges the union of all the contributing layers at the mountpoint, + * the mount is writeable but the layer themselves are immutable, all additions + * and changes are stored in + * + * fsm.overlay_path/overlays/fsm.ovname/session + * + * Returns 0 if mounted OK, nonzero if errors. + * + * Retain fsm for use with unmounting. + */ +LWS_VISIBLE LWS_EXTERN int +lws_fsmount_mount(struct lws_fsmount *fsm); + +/** + * lws_fsmount_unmount() - Unmounts an overlayfs dir + * + * \p fsm: struct lws_fsmount specifying the mount layout + * + * Unmounts the mountpoint in fsm.mp. + * + * Delete fsm.overlay_path/overlays/fsm.ovname/session to permanently eradicate + * all changes from the time the mountpoint was in use. + * + * Returns 0 if unmounted OK. + */ +LWS_VISIBLE LWS_EXTERN int +lws_fsmount_unmount(struct lws_fsmount *fsm); diff -Nru libwebsockets-3.2.1/include/libwebsockets/lws-mqtt.h libwebsockets-4.1.6/include/libwebsockets/lws-mqtt.h --- libwebsockets-3.2.1/include/libwebsockets/lws-mqtt.h 1970-01-01 00:00:00.000000000 +0000 +++ libwebsockets-4.1.6/include/libwebsockets/lws-mqtt.h 2020-12-01 17:40:26.000000000 +0000 @@ -0,0 +1,330 @@ +/* + * libwebsockets - protocol - mqtt + * + * Copyright (C) 2010 - 2020 Andy Green + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation: + * version 2.1 of the License. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, + * MA 02110-1301 USA + * + * included from libwebsockets.h + */ + +#ifndef _LWS_MQTT_H +#define _LWS_MQTT_H 1 + +struct _lws_mqtt_related; +typedef struct _lws_mqtt_related lws_mqtt_related_t; +struct lws_mqtt_str_st; +typedef struct lws_mqtt_str_st lws_mqtt_str_t; + +#define MQTT_VER_3_1_1 4 + +#define LWS_MQTT_FINAL_PART 1 + +typedef enum { + QOS0, + QOS1, + QOS2, /* not supported */ + RESERVED_QOS_LEVEL, + FAILURE_QOS_LEVEL = 0x80 +} lws_mqtt_qos_levels_t; + +typedef union { + struct { + uint8_t retain:1; + uint8_t qos:2; + uint8_t dup:1; + uint8_t ctrl_pkt_type:4; + } flags; + uint8_t bits; +} lws_mqtt_fixed_hdr_t; + +/* + * MQTT connection parameters, passed into struct + * lws_client_connect_info to establish a connection using + * lws_client_connect_via_info(). +*/ +typedef struct lws_mqtt_client_connect_param_s { + const char *client_id; /* Client ID */ + uint16_t keep_alive; /* MQTT keep alive + interval in + seconds */ + uint8_t clean_start; /* MQTT clean + session */ + struct { + const char *topic; + const char *message; + lws_mqtt_qos_levels_t qos; + uint8_t retain; + } will_param; /* MQTT LWT + parameters */ + const char *username; + const char *password; +} lws_mqtt_client_connect_param_t; + +/* + * MQTT publish parameters +*/ +typedef struct lws_mqtt_publish_param_s { + char *topic; /* Topic Name */ + uint16_t topic_len; + const void *payload; /* Publish Payload */ + uint32_t payload_len; /* Size of the + complete payload */ + uint32_t payload_pos; /* where we are in payload */ + lws_mqtt_qos_levels_t qos; + + /*--v-Following will be used by LWS-v--*/ + uint16_t packet_id; /* Packet ID for QoS > + 0 */ + uint8_t dup:1; /* Retried PUBLISH, + for QoS > 0 */ +} lws_mqtt_publish_param_t; + +typedef struct topic_elem { + const char *name; /* Topic Name */ + lws_mqtt_qos_levels_t qos; /* Requested QoS */ + + /*--v-Following will be used by LWS-v--*/ + uint8_t acked; +} lws_mqtt_topic_elem_t; + +/* + * MQTT publish parameters +*/ +typedef struct lws_mqtt_subscribe_param_s { + uint32_t num_topics; /* Number of topics */ + lws_mqtt_topic_elem_t *topic; /* Array of topic elements */ + + /*--v-Following will be used by LWS-v--*/ + uint16_t packet_id; +} lws_mqtt_subscribe_param_t; + +typedef enum { + LMQCP_RESERVED, + LMQCP_CTOS_CONNECT, /* Connection request */ + LMQCP_STOC_CONNACK, /* Connection acknowledgment */ + LMQCP_PUBLISH, /* Publish Message */ + LMQCP_PUBACK, /* QoS 1: Publish acknowledgment */ + LMQCP_PUBREC, /* QoS 2.1: Publish received */ + LMQCP_PUBREL, /* QoS 2.2: Publish release */ + LMQCP_PUBCOMP, /* QoS 2.3: Publish complete */ + LMQCP_CTOS_SUBSCRIBE, /* Subscribe request */ + LMQCP_STOC_SUBACK, /* Subscribe acknowledgment */ + LMQCP_CTOS_UNSUBSCRIBE, /* Unsubscribe request */ + LMQCP_STOC_UNSUBACK, /* Unsubscribe acknowledgment */ + LMQCP_CTOS_PINGREQ, /* PING request */ + LMQCP_STOC_PINGRESP, /* PONG response */ + LMQCP_DISCONNECT, /* Disconnect notification */ + LMQCP_AUTH /* Authentication exchange */ +} lws_mqtt_control_packet_t; + +/* flags from byte 8 of C_TO_S CONNECT */ +typedef enum { + LMQCFT_USERNAME = (1 << 7), + LMQCFT_PASSWORD = (1 << 6), + LMQCFT_WILL_RETAIN = (1 << 5), + LMQCFT_WILL_QOS = (1 << 3), + LMQCFT_WILL_FLAG = (1 << 2), + LMQCFT_CLEAN_START = (1 << 1), + LMQCFT_RESERVED = (1 << 0), + + LMQCFT_WILL_QOS_MASK = (3 << 3), +} lws_mqtt_connect_flags_t; + +/* flags for S_TO_C CONNACK */ +typedef enum { + LMQCFT_SESSION_PRESENT = (1 << 0), +} lws_mqtt_connack_flags_t; + +typedef enum { + LMQCP_REASON_SUCCESS = 0x00, + LMQCP_REASON_NORMAL_DISCONNECTION = 0x00, + LMQCP_REASON_GRANTED_QOS0 = 0x00, + LMQCP_REASON_GRANTED_QOS1 = 0x01, + LMQCP_REASON_GRANTED_QOS2 = 0x02, + LMQCP_REASON_DISCONNECT_WILL = 0x04, + LMQCP_REASON_NO_MATCHING_SUBSCRIBER = 0x10, + LMQCP_REASON_NO_SUBSCRIPTION_EXISTED = 0x11, + LMQCP_REASON_CONTINUE_AUTHENTICATION = 0x18, + LMQCP_REASON_RE_AUTHENTICATE = 0x19, + + LMQCP_REASON_UNSPECIFIED_ERROR = 0x80, + LMQCP_REASON_MALFORMED_PACKET = 0x81, + LMQCP_REASON_PROTOCOL_ERROR = 0x82, + LMQCP_REASON_IMPLEMENTATION_SPECIFIC_ERROR = 0x83, + + /* Begin - Error codes for CONNACK */ + LMQCP_REASON_UNSUPPORTED_PROTOCOL = 0x84, + LMQCP_REASON_CLIENT_ID_INVALID = 0x85, + LMQCP_REASON_BAD_CREDENTIALS = 0x86, + LMQCP_REASON_NOT_AUTHORIZED = 0x87, + /* End - Error codes for CONNACK */ + + LMQCP_REASON_SERVER_UNAVAILABLE = 0x88, + LMQCP_REASON_SERVER_BUSY = 0x89, + LMQCP_REASON_BANNED = 0x8a, + LMQCP_REASON_SERVER_SHUTTING_DOWN = 0x8b, + LMQCP_REASON_BAD_AUTHENTICATION_METHOD = 0x8c, + LMQCP_REASON_KEEPALIVE_TIMEOUT = 0x8d, + LMQCP_REASON_SESSION_TAKEN_OVER = 0x8e, + LMQCP_REASON_TOPIC_FILTER_INVALID = 0x8f, + LMQCP_REASON_TOPIC_NAME_INVALID = 0x90, + LMQCP_REASON_PACKET_ID_IN_USE = 0x91, + LMQCP_REASON_PACKET_ID_NOT_FOUND = 0x92, + LMQCP_REASON_MAX_RX_EXCEEDED = 0x93, + LMQCP_REASON_TOPIC_ALIAS_INVALID = 0x94, + LMQCP_REASON_PACKET_TOO_LARGE = 0x95, + LMQCP_REASON_RATELIMIT = 0x96, + LMQCP_REASON_QUOTA_EXCEEDED = 0x97, + LMQCP_REASON_ADMINISTRATIVE_ACTION = 0x98, + LMQCP_REASON_PAYLOAD_FORMAT_INVALID = 0x99, + LMQCP_REASON_RETAIN_NOT_SUPPORTED = 0x9a, + LMQCP_REASON_QOS_NOT_SUPPORTED = 0x9b, + LMQCP_REASON_USE_ANOTHER_SERVER = 0x9c, + LMQCP_REASON_SERVER_MOVED = 0x9d, + LMQCP_REASON_SHARED_SUBSCRIPTIONS_NOT_SUPPORTED = 0x9e, + LMQCP_REASON_CONNECTION_RATE_EXCEEDED = 0x9f, + LMQCP_REASON_MAXIMUM_CONNECT_TIME = 0xa0, + LMQCP_REASON_SUBSCRIPTION_IDS_NOT_SUPPORTED = 0xa1, + LMQCP_REASON_WILDCARD_SUBSCRIPTIONS_NOT_SUPPORTED = 0xa2, +} lws_mqtt_reason_t; + +typedef enum { + LMQPROP_INVALID, + LMQPROP_PAYLOAD_FORMAT_INDICATOR = 0x01, + LMQPROP_MESSAGE_EXPIRY_INTERVAL = 0x02, + LMQPROP_CONTENT_TYPE = 0x03, + LMQPROP_RESPONSE_TOPIC = 0x08, + LMQPROP_CORRELATION_DATA = 0x09, + LMQPROP_SUBSCRIPTION_IDENTIFIER = 0x0b, + LMQPROP_SESSION_EXPIRY_INTERVAL = 0x11, + LMQPROP_ASSIGNED_CLIENT_IDENTIFIER = 0x12, + LMQPROP_SERVER_KEEP_ALIVE = 0x13, + LMQPROP_AUTHENTICATION_METHOD = 0x15, + LMQPROP_AUTHENTICATION_DATA = 0x16, + LMQPROP_REQUEST_PROBLEM_INFORMATION = 0x17, + LMQPROP_WILL_DELAY_INTERVAL = 0x18, + LMQPROP_REQUEST_RESPONSE_INFORMATION = 0x19, + LMQPROP_RESPONSE_INFORMATION = 0x1a, + LMQPROP_SERVER_REFERENCE = 0x1c, + LMQPROP_REASON_STRING = 0x1f, + LMQPROP_RECEIVE_MAXIMUM = 0x21, + LMQPROP_TOPIC_ALIAS_MAXIMUM = 0x22, + LMQPROP_TOPIC_ALIAS = 0x23, + LMQPROP_MAXIMUM_QOS = 0x24, + LMQPROP_RETAIN_AVAILABLE = 0x25, + LMQPROP_USER_PROPERTY = 0x26, + LMQPROP_MAXIMUM_PACKET_SIZE = 0x27, + LMQPROP_WILDCARD_SUBSCRIPTION_AVAIL = 0x28, + LMQPROP_SUBSCRIPTION_IDENTIFIER_AVAIL = 0x29, + LMQPROP_SHARED_SUBSCRIPTION_AVAIL = 0x2a +} lws_mqtt_property; + +int +lws_read_mqtt(struct lws *wsi, unsigned char *buf, lws_filepos_t len); + +/* returns 0 if bd1 and bd2 are "the same", that includes empty, else nonzero */ +LWS_VISIBLE LWS_EXTERN int +lws_mqtt_bindata_cmp(const lws_mqtt_str_t *bd1, const lws_mqtt_str_t *bd2); + +LWS_VISIBLE LWS_EXTERN void +lws_mqtt_str_init(lws_mqtt_str_t *s, uint8_t *buf, uint16_t lim, char nf); + +LWS_VISIBLE LWS_EXTERN lws_mqtt_str_t * +lws_mqtt_str_create(uint16_t lim); + +LWS_VISIBLE LWS_EXTERN lws_mqtt_str_t * +lws_mqtt_str_create_init(uint8_t *buf, uint16_t len, uint16_t lim); + +LWS_VISIBLE LWS_EXTERN lws_mqtt_str_t * +lws_mqtt_str_create_cstr_dup(const char *buf, uint16_t lim); + +LWS_VISIBLE LWS_EXTERN uint8_t * +lws_mqtt_str_next(lws_mqtt_str_t *s, uint16_t *budget); + +LWS_VISIBLE LWS_EXTERN int +lws_mqtt_str_advance(lws_mqtt_str_t *s, int n); + +LWS_VISIBLE LWS_EXTERN void +lws_mqtt_str_free(lws_mqtt_str_t **s); + + +/** + * lws_mqtt_client_send_publish() - lws_write a publish packet + * + * \param wsi: the mqtt child wsi + * \param pub: additional information on what we're publishing + * \param buf: payload to send + * \param len: length of data in buf + * \param final: flag indicating this is the last part + * + * Issues part of, or the whole of, a PUBLISH frame. The first part of the + * frame contains the header, and uses the .qos and .payload_len parts of \p pub + * since MQTT requires the frame to specify the PUBLISH message length at the + * start. The \p len paramter may be less than \p pub.payload_len, in which + * case subsequent calls with more payload are needed to complete the frame. + * + * Although the connection is stuck waiting for the remainder, in that it can't + * issue any other frames until the current one is completed, lws returns to the + * event loop normally and can continue the calls with additional payload even + * for huge frames as the data becomes available, consistent with timeout needs + * and latency to start any new frame (even, eg, related to ping / pong). + * + * If you're sending large frames, the OS will typically not allow the data to + * be sent all at once to kernel side. So you should ideally cut the payload + * up into 1 or 2- mtu sized chunks and send that. + * + * Final should be set when you're calling with the last part of the payload. + */ +LWS_VISIBLE LWS_EXTERN int +lws_mqtt_client_send_publish(struct lws *wsi, lws_mqtt_publish_param_t *pub, + const void *buf, uint32_t len, int final); + +/** + * lws_mqtt_client_send_subcribe() - lws_write a subscribe packet + * + * \param wsi: the mqtt child wsi + * \param sub: which topic(s) we want to subscribe to + * + * For topics other child streams have not already subscribed to, send a packet + * to the server asking to subscribe to them. If all topics listed are already + * subscribed to be the shared network connection, just trigger the + * LWS_CALLBACK_MQTT_SUBSCRIBED callback as if a SUBACK had come. + * + * \p sub doesn't need to exist after the return from this function. + */ +LWS_VISIBLE LWS_EXTERN int +lws_mqtt_client_send_subcribe(struct lws *wsi, lws_mqtt_subscribe_param_t *sub); + +/** + * lws_mqtt_client_send_unsubcribe() - lws_write a unsubscribe packet + * + * \param wsi: the mqtt child wsi + * \param sub: which topic(s) we want to unsubscribe from + * + * For topics other child streams are not subscribed to, send a packet + * to the server asking to unsubscribe from them. If all topics + * listed are already subscribed by other child streams on the shared + * network connection, just trigger the LWS_CALLBACK_MQTT_UNSUBSCRIBED + * callback as if a UNSUBACK had come. + * + * \p unsub doesn't need to exist after the return from this function. + */ +LWS_VISIBLE LWS_EXTERN int LWS_WARN_UNUSED_RESULT +lws_mqtt_client_send_unsubcribe(struct lws *wsi, + const lws_mqtt_subscribe_param_t *unsub); + +#endif /* _LWS_MQTT_H */ diff -Nru libwebsockets-3.2.1/include/libwebsockets/lws-netdev.h libwebsockets-4.1.6/include/libwebsockets/lws-netdev.h --- libwebsockets-3.2.1/include/libwebsockets/lws-netdev.h 1970-01-01 00:00:00.000000000 +0000 +++ libwebsockets-4.1.6/include/libwebsockets/lws-netdev.h 2020-12-01 17:40:26.000000000 +0000 @@ -0,0 +1,283 @@ +/* + * libwebsockets - small server side websockets and web server implementation + * + * Copyright (C) 2010 - 2020 Andy Green + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to + * deal in the Software without restriction, including without limitation the + * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or + * sell copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS + * IN THE SOFTWARE. + */ + +#define LWS_WIFI_MAX_SCAN_TRACK 16 +#define LWS_ETH_ALEN 6 + +typedef uint8_t lws_wifi_ch_t; +typedef int8_t lws_wifi_rssi_t; +struct lws_netdev_instance; + +typedef enum { + LWSNDTYP_UNKNOWN, + LWSNDTYP_WIFI, + LWSNDTYP_ETH, +} lws_netdev_type_t; + +/* + * Base class for netdev configuration + */ + +typedef struct lws_netdev_config { + void *plat_config; +} lws_netdev_config_t; + +/* + * Const Logical generic network interface ops + */ + +typedef struct lws_netdev_ops { + struct lws_netdev_instance * (*create)(struct lws_context *ctx, + const struct lws_netdev_ops *ops, + const char *name, void *platinfo); + int (*configure)(struct lws_netdev_instance *nd, + lws_netdev_config_t *config); + int (*up)(struct lws_netdev_instance *nd); + int (*down)(struct lws_netdev_instance *nd); + int (*event)(struct lws_netdev_instance *nd, lws_usec_t timestamp, + void *buf, size_t len); + /**< these are SMD events coming from lws event loop thread context */ + void (*destroy)(struct lws_netdev_instance **pnd); + int (*connect)(struct lws_netdev_instance *wnd, const char *ssid, + const char *passphrase, uint8_t *bssid); + void (*scan)(struct lws_netdev_instance *nd); +} lws_netdev_ops_t; + +/* + * Network devices on this platform + * + * We also hold a list of all known network credentials (when they are needed + * because there is a network interface without anything to connect to) and + * the lws_settings instance they are stored in + */ + +typedef struct lws_netdevs { + lws_dll2_owner_t owner; + /**< list of netdevs / lws_netdev_instance_t -based objects */ + + lws_dll2_owner_t owner_creds; + /**< list of known credentials */ + struct lwsac *ac_creds; + /**< lwsac holding retreived credentials settings, or NULL */ + lws_settings_instance_t *si; + + lws_sockaddr46 sa46_dns_resolver; + + uint8_t refcount_creds; + /**< when there are multiple netdevs, must refcount creds in mem */ +} lws_netdevs_t; + +/* + * Base class for an allocated instantiated derived object using lws_netdev_ops, + * ie, a specific ethernet device + */ + +typedef struct lws_netdev_instance { + const char *name; + const lws_netdev_ops_t *ops; + void *platinfo; + lws_dll2_t list; + uint8_t mac[LWS_ETH_ALEN]; + uint8_t type; /* lws_netdev_type_t */ +} lws_netdev_instance_t; + +enum { + LNDIW_ALG_OPEN, + LNDIW_ALG_WPA2, + + LNDIW_MODE_STA = (1 << 0), + LNDIW_MODE_AP = (1 << 1), + LNDIW_UP = (1 << 7), + + LNDIW_ACQ_IPv4 = (1 << 0), + LNDIW_ACQ_IPv6 = (1 << 1), +}; + +/* + * Group AP / Station State + */ + +typedef enum { + LWSNDVWIFI_STATE_INITIAL, + /* + * We should gratuitously try whatever last worked for us, then + * if that fails, worry about the rest of the logic + */ + LWSNDVWIFI_STATE_SCAN, + /* + * Unconnected, scanning: AP known in one of the config slots -> + * configure it, start timeout + LWSNDVWIFI_STATE_STAT, if no AP + * already up in same group with lower MAC, after a random + * period start up our AP (LWSNDVWIFI_STATE_AP) + */ + LWSNDVWIFI_STATE_AP, + /* Trying to be the group AP... periodically do a scan + * LWSNDVWIFI_STATE_AP_SCAN, faster and then slower + */ + LWSNDVWIFI_STATE_AP_SCAN, + /* + * doing a scan while trying to be the group AP... if we see a + * lower MAC being the AP for the same group AP, abandon being + * an AP and join that AP as a station + */ + LWSNDVWIFI_STATE_STAT_GRP_AP, + /* + * We have decided to join another group member who is being the + * AP, as its MAC is lower than ours. This is a stable state, + * but we still do periodic scans + * LWSNDVWIFI_STATE_STAT_GRP_AP_SCAN and will always prefer an + * AP configured in a slot. + */ + LWSNDVWIFI_STATE_STAT_GRP_AP_SCAN, + /* + * We have joined a group member who is doing the AP job... we + * want to check every now and then if a configured AP has + * appeared that we should better use instead. Otherwise stay + * in LWSNDVWIFI_STATE_STAT_GRP_AP + */ + LWSNDVWIFI_STATE_STAT, + /* + * trying to connect to another non-group AP. If we don't get an + * IP within a timeout and retries, blacklist it and go back + */ + LWSNDVWIFI_STATE_STAT_HAPPY, +} lws_netdev_wifi_state_t; + +/* + * Generic WIFI credentials + */ + +typedef struct lws_wifi_creds { + lws_dll2_t list; + + uint8_t bssid[LWS_ETH_ALEN]; + char passphrase[64]; + char ssid[33]; + uint8_t alg; +} lws_wifi_creds_t; + +/* + * Generic WIFI Network Device Instance + */ + +typedef struct lws_netdev_instance_wifi { + lws_netdev_instance_t inst; + lws_dll2_owner_t scan; /* sorted scan results */ + lws_sorted_usec_list_t sul_scan; + + lws_wifi_creds_t *ap_cred; + const char *ap_ip; + + const char *sta_ads; + + char current_attempt_ssid[33]; + uint8_t current_attempt_bssid[LWS_ETH_ALEN]; + + uint8_t flags; + uint8_t state; /* lws_netdev_wifi_state_t */ +} lws_netdev_instance_wifi_t; + +/* + * Logical scan results sorted list item + */ + +typedef struct lws_wifi_sta { + lws_dll2_t list; + + uint32_t last_seen; /* unix time */ + uint32_t last_tried; /* unix time */ + + uint8_t bssid[LWS_ETH_ALEN]; + char *ssid; /* points to overallocation */ + uint8_t ssid_len; + lws_wifi_ch_t ch; + lws_wifi_rssi_t rssi[8]; + int16_t rssi_avg; + uint8_t authmode; + + uint8_t rssi_count; + uint8_t rssi_next; + + /* ssid overallocated afterwards */ +} lws_wifi_sta_t; + +#define rssi_averaged(_x) (_x->rssi_count ? \ + ((int)_x->rssi_avg / (int)_x->rssi_count) : \ + -200) + +LWS_VISIBLE LWS_EXTERN lws_netdevs_t * +lws_netdevs_from_ctx(struct lws_context *ctx); + +LWS_VISIBLE LWS_EXTERN int +lws_netdev_credentials_settings_set(lws_netdevs_t *nds); + +LWS_VISIBLE LWS_EXTERN int +lws_netdev_credentials_settings_get(lws_netdevs_t *nds); + +LWS_VISIBLE LWS_EXTERN struct lws_netdev_instance * +lws_netdev_wifi_create_plat(struct lws_context *ctx, + const lws_netdev_ops_t *ops, const char *name, + void *platinfo); +LWS_VISIBLE LWS_EXTERN int +lws_netdev_wifi_configure_plat(struct lws_netdev_instance *nd, + lws_netdev_config_t *config); +LWS_VISIBLE LWS_EXTERN int +lws_netdev_wifi_event_plat(struct lws_netdev_instance *nd, lws_usec_t timestamp, + void *buf, size_t len); +LWS_VISIBLE LWS_EXTERN int +lws_netdev_wifi_up_plat(struct lws_netdev_instance *nd); +LWS_VISIBLE LWS_EXTERN int +lws_netdev_wifi_down_plat(struct lws_netdev_instance *nd); +LWS_VISIBLE LWS_EXTERN void +lws_netdev_wifi_destroy_plat(struct lws_netdev_instance **pnd); +LWS_VISIBLE LWS_EXTERN void +lws_netdev_wifi_scan_plat(lws_netdev_instance_t *nd); + +LWS_VISIBLE LWS_EXTERN int +lws_netdev_wifi_connect_plat(lws_netdev_instance_t *wnd, const char *ssid, + const char *passphrase, uint8_t *bssid); + +LWS_VISIBLE LWS_EXTERN lws_netdev_instance_t * +lws_netdev_find(lws_netdevs_t *netdevs, const char *ifname); + +#define lws_netdev_wifi_plat_ops \ + .create = lws_netdev_wifi_create_plat, \ + .configure = lws_netdev_wifi_configure_plat, \ + .event = lws_netdev_wifi_event_plat, \ + .up = lws_netdev_wifi_up_plat, \ + .down = lws_netdev_wifi_down_plat, \ + .connect = lws_netdev_wifi_connect_plat, \ + .scan = lws_netdev_wifi_scan_plat, \ + .destroy = lws_netdev_wifi_destroy_plat + +/* + * This is for plat / OS level init that is necessary to be able to use + * networking or wifi at all, without mentioning any specific device + */ + +LWS_VISIBLE LWS_EXTERN int +lws_netdev_plat_init(void); + +LWS_VISIBLE LWS_EXTERN int +lws_netdev_plat_wifi_init(void); diff -Nru libwebsockets-3.2.1/include/libwebsockets/lws-network-helper.h libwebsockets-4.1.6/include/libwebsockets/lws-network-helper.h --- libwebsockets-3.2.1/include/libwebsockets/lws-network-helper.h 2019-12-18 14:45:31.000000000 +0000 +++ libwebsockets-4.1.6/include/libwebsockets/lws-network-helper.h 2020-12-01 17:40:26.000000000 +0000 @@ -1,24 +1,25 @@ /* * libwebsockets - small server side websockets and web server implementation * - * Copyright (C) 2010-2018 Andy Green + * Copyright (C) 2010 - 2019 Andy Green * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation: - * version 2.1 of the License. - * - * This library is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with this library; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, - * MA 02110-1301 USA - * - * included from libwebsockets.h + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to + * deal in the Software without restriction, including without limitation the + * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or + * sell copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS + * IN THE SOFTWARE. */ /** \defgroup net Network related helper APIs @@ -28,6 +29,17 @@ */ ///@{ +#if defined(LWS_ESP_PLATFORM) +#include +#endif + +typedef union { +#if defined(LWS_WITH_IPV6) + struct sockaddr_in6 sa6; +#endif + struct sockaddr_in sa4; +} lws_sockaddr46; + /** * lws_canonical_hostname() - returns this host's hostname * @@ -69,7 +81,10 @@ * peer that has connected to wsi */ LWS_VISIBLE LWS_EXTERN const char * -lws_get_peer_simple(struct lws *wsi, char *name, int namelen); +lws_get_peer_simple(struct lws *wsi, char *name, size_t namelen); + +LWS_VISIBLE LWS_EXTERN const char * +lws_get_peer_simple_fd(lws_sockfd_type fd, char *name, size_t namelen); #define LWS_ITOSA_USABLE 0 #define LWS_ITOSA_NOT_EXIST -1 @@ -77,7 +92,7 @@ #define LWS_ITOSA_BUSY -3 /* only returned by lws_socket_bind() on EADDRINUSE */ -#if !defined(LWS_WITH_ESP32) && !defined(LWS_PLAT_OPTEE) +#if !defined(LWS_PLAT_FREERTOS) && !defined(LWS_PLAT_OPTEE) /** * lws_interface_to_sa() - Convert interface name or IP to sockaddr struct * @@ -102,4 +117,77 @@ lws_interface_to_sa(int ipv6, const char *ifname, struct sockaddr_in *addr, size_t addrlen); #endif + +/** + * lws_sa46_compare_ads() - checks if two sa46 have the same address + * + * \param sa46a: first + * \param sa46b: second + * + * Returns 0 if the address family and address are the same, otherwise nonzero. + */ +LWS_VISIBLE LWS_EXTERN int +lws_sa46_compare_ads(const lws_sockaddr46 *sa46a, const lws_sockaddr46 *sa46b); + +/* + * lws_parse_numeric_address() - converts numeric ipv4 or ipv6 to byte address + * + * \param ads: the numeric ipv4 or ipv6 address string + * \param result: result array + * \param max_len: max length of result array + * + * Converts a 1.2.3.4 or 2001:abcd:123:: or ::ffff:1.2.3.4 formatted numeric + * address into an array of network ordered byte address elements. + * + * Returns < 0 on error, else length of result set, either 4 or 16 for ipv4 / + * ipv6. + */ +LWS_VISIBLE LWS_EXTERN int +lws_parse_numeric_address(const char *ads, uint8_t *result, size_t max_len); + +/* + * lws_sa46_parse_numeric_address() - converts numeric ipv4 or ipv6 to sa46 + * + * \param ads: the numeric ipv4 or ipv6 address string + * \param sa46: pointer to sa46 to set + * + * Converts a 1.2.3.4 or 2001:abcd:123:: or ::ffff:1.2.3.4 formatted numeric + * address into an sa46, a union of sockaddr_in or sockaddr_in6 depending on + * what kind of address was found. sa46->sa4.sin_fmaily will be AF_INET if + * ipv4, or AF_INET6 if ipv6. + * + * Returns 0 if the sa46 was set, else < 0 on error. + */ +LWS_VISIBLE LWS_EXTERN int +lws_sa46_parse_numeric_address(const char *ads, lws_sockaddr46 *sa46); + +/** + * lws_write_numeric_address() - convert network byte order ads to text + * + * \param ads: network byte order address array + * \param size: number of bytes valid in ads + * \param buf: result buffer to take text format + * \param len: max size of text buffer + * + * Converts an array of network-ordered byte address elements to a textual + * representation of the numeric address, like "1.2.3.4" or "::1". Return 0 + * if OK else < 0. ipv6 only supported with LWS_IPV6=1 at cmake. + */ +LWS_VISIBLE LWS_EXTERN int +lws_write_numeric_address(const uint8_t *ads, int size, char *buf, size_t len); + +/** + * lws_sa46_write_numeric_address() - convert sa46 ads to textual numeric ads + * + * \param sa46: the sa46 whose address to show + * \param buf: result buffer to take text format + * \param len: max size of text buffer + * + * Converts the ipv4 or ipv6 address in an lws_sockaddr46 to a textual + * representation of the numeric address, like "1.2.3.4" or "::1". Return 0 + * if OK else < 0. ipv6 only supported with LWS_IPV6=1 at cmake. + */ +LWS_VISIBLE LWS_EXTERN int +lws_sa46_write_numeric_address(lws_sockaddr46 *sa46, char *buf, size_t len); + ///@} diff -Nru libwebsockets-3.2.1/include/libwebsockets/lws-optee.h libwebsockets-4.1.6/include/libwebsockets/lws-optee.h --- libwebsockets-3.2.1/include/libwebsockets/lws-optee.h 2019-12-18 14:45:31.000000000 +0000 +++ libwebsockets-4.1.6/include/libwebsockets/lws-optee.h 2020-12-01 17:40:26.000000000 +0000 @@ -1,25 +1,25 @@ /* * libwebsockets - small server side websockets and web server implementation - * SPDX-License-Identifier: LGPL-2.1-only * - * Copyright (C) 2019 Akira Tsukamoto + * Copyright (C) 2010 - 2019 Andy Green * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation: - * version 2.1 of the License. + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to + * deal in the Software without restriction, including without limitation the + * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or + * sell copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: * - * This library is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. * - * You should have received a copy of the GNU Lesser General Public - * License along with this library; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, - * MA 02110-1301 USA - * - * included from libwebsockets.h + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS + * IN THE SOFTWARE. */ #ifndef __LWS_OPTEE_H diff -Nru libwebsockets-3.2.1/include/libwebsockets/lws-plugin-generic-sessions.h libwebsockets-4.1.6/include/libwebsockets/lws-plugin-generic-sessions.h --- libwebsockets-3.2.1/include/libwebsockets/lws-plugin-generic-sessions.h 2019-12-18 14:45:31.000000000 +0000 +++ libwebsockets-4.1.6/include/libwebsockets/lws-plugin-generic-sessions.h 1970-01-01 00:00:00.000000000 +0000 @@ -1,74 +0,0 @@ -/* - * libwebsockets - small server side websockets and web server implementation - * - * Copyright (C) 2010-2018 Andy Green - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation: - * version 2.1 of the License. - * - * This library is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with this library; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, - * MA 02110-1301 USA - * - * included from libwebsockets.h - */ - -/*! \defgroup generic-sessions plugin: generic-sessions - * \ingroup Protocols-and-Plugins - * - * ##Plugin Generic-sessions related - * - * generic-sessions plugin provides a reusable, generic session and login / - * register / forgot password framework including email verification. - */ -///@{ - -#define LWSGS_EMAIL_CONTENT_SIZE 16384 -/**< Maximum size of email we might send */ - -/* SHA-1 binary and hexified versions */ -/** typedef struct lwsgw_hash_bin */ -typedef struct { unsigned char bin[32]; /**< binary representation of hash */} lwsgw_hash_bin; -/** typedef struct lwsgw_hash */ -typedef struct { char id[65]; /**< ascii hex representation of hash */ } lwsgw_hash; - -/** enum lwsgs_auth_bits */ -enum lwsgs_auth_bits { - LWSGS_AUTH_LOGGED_IN = 1, /**< user is logged in as somebody */ - LWSGS_AUTH_ADMIN = 2, /**< logged in as the admin user */ - LWSGS_AUTH_VERIFIED = 4, /**< user has verified his email */ - LWSGS_AUTH_FORGOT_FLOW = 8, /**< just completed "forgot password" */ -}; - -/** struct lws_session_info - information about user session status */ -struct lws_session_info { - char username[32]; /**< username logged in as, or empty string */ - char email[100]; /**< email address associated with login, or empty string */ - char ip[72]; /**< ip address session was started from */ - unsigned int mask; /**< access rights mask associated with session - * see enum lwsgs_auth_bits */ - char session[42]; /**< session id string, usable as opaque uid when not logged in */ -}; - -/** enum lws_gs_event */ -enum lws_gs_event { - LWSGSE_CREATED, /**< a new user was created */ - LWSGSE_DELETED /**< an existing user was deleted */ -}; - -/** struct lws_gs_event_args */ -struct lws_gs_event_args { - enum lws_gs_event event; /**< which event happened */ - const char *username; /**< which username the event happened to */ - const char *email; /**< the email address of that user */ -}; - -///@} diff -Nru libwebsockets-3.2.1/include/libwebsockets/lws-protocols-plugins.h libwebsockets-4.1.6/include/libwebsockets/lws-protocols-plugins.h --- libwebsockets-3.2.1/include/libwebsockets/lws-protocols-plugins.h 2019-12-18 14:45:31.000000000 +0000 +++ libwebsockets-4.1.6/include/libwebsockets/lws-protocols-plugins.h 2020-12-01 17:40:26.000000000 +0000 @@ -1,24 +1,25 @@ /* * libwebsockets - small server side websockets and web server implementation * - * Copyright (C) 2010-2018 Andy Green + * Copyright (C) 2010 - 2019 Andy Green * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation: - * version 2.1 of the License. - * - * This library is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with this library; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, - * MA 02110-1301 USA - * - * included from libwebsockets.h + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to + * deal in the Software without restriction, including without limitation the + * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or + * sell copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS + * IN THE SOFTWARE. */ /*! \defgroup Protocols-and-Plugins Protocols and Plugins @@ -67,7 +68,7 @@ * to the selected protocol. For example if this protocol was * called "myprotocol-v2", you might set id to 2, and the user * code that acts differently according to the version can do so by - * switch (wsi->protocol->id), user code might use some bits as + * switch (wsi->a.protocol->id), user code might use some bits as * capability flags based on selected protocol version, etc. */ void *user; /**< ignored by lws, but user code can pass a pointer here it can later access from the protocol callback */ @@ -193,36 +194,116 @@ LWS_VISIBLE LWS_EXTERN int lws_protocol_init(struct lws_context *context); -#ifdef LWS_WITH_PLUGINS +#define LWS_PLUGIN_API_MAGIC 190 + +/* + * Abstract plugin header for any kind of plugin class, always at top of + * actual class plugin export type. + * + * The export type object must be exported with the same name as the plugin + * file, eg, libmyplugin.so must export a const one of these as the symbol + * "myplugin". + * + * That is the only expected export from the plugin. + */ + +typedef struct lws_plugin_header { + const char *name; + const char *_class; -/* PLUGINS implies LIBUV */ + unsigned int api_magic; + /* set to LWS_PLUGIN_API_MAGIC at plugin build time */ -#define LWS_PLUGIN_API_MAGIC 180 + /* plugin-class specific superclass data follows */ +} lws_plugin_header_t; + +/* + * "lws_protocol_plugin" class export, for lws_protocol implementations done + * as plugins + */ +typedef struct lws_plugin_protocol { + lws_plugin_header_t hdr; -/** struct lws_plugin_capability - how a plugin introduces itself to lws */ -struct lws_plugin_capability { - unsigned int api_magic; /**< caller fills this in, plugin fills rest */ const struct lws_protocols *protocols; /**< array of supported protocols provided by plugin */ - int count_protocols; /**< how many protocols */ const struct lws_extension *extensions; /**< array of extensions provided by plugin */ + int count_protocols; /**< how many protocols */ int count_extensions; /**< how many extensions */ -}; +} lws_plugin_protocol_t; -typedef int (*lws_plugin_init_func)(struct lws_context *, - struct lws_plugin_capability *); -typedef int (*lws_plugin_destroy_func)(struct lws_context *); -/** struct lws_plugin */ +/* + * This is the dynamic, runtime created part of the plugin instantiation. + * These are kept in a linked-list and destroyed with the context. + */ + struct lws_plugin { struct lws_plugin *list; /**< linked list */ + + const lws_plugin_header_t *hdr; + + union { +#if defined(LWS_WITH_LIBUV) && defined(UV_ERRNO_MAP) #if (UV_VERSION_MAJOR > 0) - uv_lib_t lib; /**< shared library pointer */ + uv_lib_t lib; /**< shared library pointer */ #endif - void *l; /**< so we can compile on ancient libuv */ - char name[64]; /**< name of the plugin */ - struct lws_plugin_capability caps; /**< plugin capabilities */ +#endif + void *l; /**< */ + } u; }; -#endif +/* + * Event lib library plugin type (when LWS_WITH_EVLIB_PLUGINS) + * Public so new event libs can equally be supported outside lws itself + */ + +typedef struct lws_plugin_evlib { + lws_plugin_header_t hdr; + const struct lws_event_loop_ops *ops; +} lws_plugin_evlib_t; + +typedef int (*each_plugin_cb_t)(struct lws_plugin *p, void *user); + +/** + * lws_plugins_init() - dynamically load plugins of matching class from dirs + * + * \param pplugin: pointer to linked-list for this kind of plugin + * \param d: array of directory paths to look in + * \param _class: class string that plugin must declare + * \param filter: NULL, or a string that must appear after the third char of the plugin filename + * \param each: NULL, or each_plugin_cb_t callback for each instantiated plugin + * \param each_user: pointer passed to each callback + * + * Allows you to instantiate a class of plugins to a specified linked-list. + * The each callback allows you to init each inistantiated callback and pass a + * pointer each_user to it. + * + * To take down the plugins, pass a pointer to the linked-list head to + * lws_plugins_destroy. + * + * This is used for lws protocol plugins but you can define your own plugin + * class name like "mypluginclass", declare it in your plugin headers, and load + * your own plugins to your own list using this api the same way. + */ +LWS_VISIBLE LWS_EXTERN int +lws_plugins_init(struct lws_plugin **pplugin, const char * const *d, + const char *_class, const char *filter, + each_plugin_cb_t each, void *each_user); + +/** + * lws_plugins_destroy() - dynamically unload list of plugins + * + * \param pplugin: pointer to linked-list for this kind of plugin + * \param each: NULL, or each_plugin_cb_t callback for each instantiated plugin + * \param each_user: pointer passed to each callback + * + * Allows you to destroy a class of plugins from a specified linked-list + * created by a call to lws_plugins_init(). + * + * The each callback allows you to deinit each inistantiated callback and pass a + * pointer each_user to it, just before its footprint is destroyed. + */ +LWS_VISIBLE LWS_EXTERN int +lws_plugins_destroy(struct lws_plugin **pplugin, each_plugin_cb_t each, + void *each_user); ///@} diff -Nru libwebsockets-3.2.1/include/libwebsockets/lws-purify.h libwebsockets-4.1.6/include/libwebsockets/lws-purify.h --- libwebsockets-3.2.1/include/libwebsockets/lws-purify.h 2019-12-18 14:45:31.000000000 +0000 +++ libwebsockets-4.1.6/include/libwebsockets/lws-purify.h 2020-12-01 17:40:26.000000000 +0000 @@ -1,27 +1,27 @@ /* * libwebsockets - small server side websockets and web server implementation * - * Copyright (C) 2010-2018 Andy Green + * Copyright (C) 2010 - 2019 Andy Green * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation: - * version 2.1 of the License. - * - * This library is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with this library; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, - * MA 02110-1301 USA - * - * included from libwebsockets.h + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to + * deal in the Software without restriction, including without limitation the + * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or + * sell copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS + * IN THE SOFTWARE. */ - /*! \defgroup pur Sanitize / purify SQL and JSON helpers * * ##Sanitize / purify SQL and JSON helpers @@ -44,17 +44,41 @@ lws_sql_purify(char *escaped, const char *string, int len); /** + * lws_sql_purify_len() - return length of purified version of input string + * + * \param string: input buffer ('/0' terminated) + * + * Calculates any character escaping without writing it anywhere and returns the + * calculated length of the purified string. + */ +int +lws_sql_purify_len(const char *p); + +/** * lws_json_purify() - like strncpy but with escaping for json chars * * \param escaped: output buffer * \param string: input buffer ('/0' terminated) * \param len: output buffer max length + * \param in_used: number of bytes of string we could escape in len * * Because escaping expands the output string, it's not * possible to do it in-place, ie, with escaped == string */ LWS_VISIBLE LWS_EXTERN const char * -lws_json_purify(char *escaped, const char *string, int len); +lws_json_purify(char *escaped, const char *string, int len, int *in_used); + +/** + * lws_json_purify_len() - find out the escaped length of a string + * + * \param string: input buffer ('/0' terminated) + * + * JSON may have to expand escapes by up to 6x the original depending on what + * it is. This doesn't actually do the escaping but goes through the motions + * and computes the length of the escaped string. + */ +LWS_VISIBLE LWS_EXTERN int +lws_json_purify_len(const char *string); /** * lws_filename_purify_inplace() - replace scary filename chars with underscore diff -Nru libwebsockets-3.2.1/include/libwebsockets/lws-pwm.h libwebsockets-4.1.6/include/libwebsockets/lws-pwm.h --- libwebsockets-3.2.1/include/libwebsockets/lws-pwm.h 1970-01-01 00:00:00.000000000 +0000 +++ libwebsockets-4.1.6/include/libwebsockets/lws-pwm.h 2020-12-01 17:40:26.000000000 +0000 @@ -0,0 +1,67 @@ +/* + * Generic PWM controller ops + * + * Copyright (C) 2019 - 2020 Andy Green + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to + * deal in the Software without restriction, including without limitation the + * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or + * sell copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS + * IN THE SOFTWARE. + */ + +typedef struct lws_pwm_map { + _lws_plat_gpio_t gpio; + uint8_t index; + uint8_t active_level; +} lws_pwm_map_t; + +typedef struct lws_pwm_ops { + int (*init)(const struct lws_pwm_ops *lo); + void (*intensity)(const struct lws_pwm_ops *lo, _lws_plat_gpio_t gpio, + lws_led_intensity_t inten); + const lws_pwm_map_t *pwm_map; + uint8_t count_pwm_map; +} lws_pwm_ops_t; + +LWS_VISIBLE LWS_EXTERN int +lws_pwm_plat_init(const struct lws_pwm_ops *lo); + +LWS_VISIBLE LWS_EXTERN void +lws_pwm_plat_intensity(const struct lws_pwm_ops *lo, _lws_plat_gpio_t gpio, + lws_led_intensity_t inten); + +#define lws_pwm_plat_ops \ + .init = lws_pwm_plat_init, \ + .intensity = lws_pwm_plat_intensity + +/* + * May be useful for making your own transitions or sequences + */ + +LWS_VISIBLE LWS_EXTERN lws_led_intensity_t +lws_led_func_linear(lws_led_seq_phase_t n); +LWS_VISIBLE LWS_EXTERN lws_led_intensity_t +lws_led_func_sine(lws_led_seq_phase_t n); + +/* canned sequences that can work out of the box */ + +extern const lws_led_sequence_def_t lws_pwmseq_sine_endless_slow, + lws_pwmseq_sine_endless_fast, + lws_pwmseq_linear_wipe, + lws_pwmseq_sine_up, lws_pwmseq_sine_down, + lws_pwmseq_static_on, + lws_pwmseq_static_half, + lws_pwmseq_static_off; diff -Nru libwebsockets-3.2.1/include/libwebsockets/lws-retry.h libwebsockets-4.1.6/include/libwebsockets/lws-retry.h --- libwebsockets-3.2.1/include/libwebsockets/lws-retry.h 2019-12-18 14:45:31.000000000 +0000 +++ libwebsockets-4.1.6/include/libwebsockets/lws-retry.h 2020-12-01 17:40:26.000000000 +0000 @@ -1,48 +1,43 @@ /* * libwebsockets - small server side websockets and web server implementation * - * Copyright (C) 2010-2019 Andy Green + * Copyright (C) 2010 - 2019 Andy Green * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation: - * version 2.1 of the License. - * - * This library is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with this library; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, - * MA 02110-1301 USA - * - * included from libwebsockets.h - */ - -/* - * Specifies backoff ranges using a pair of uint32_t in ms for the min, max. - * - * The actual backoff timing is picked randomly within the range. + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to + * deal in the Software without restriction, including without limitation the + * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or + * sell copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS + * IN THE SOFTWARE. */ -typedef struct lws_retry_range { - uint32_t min_ms; - uint32_t max_ms; -} lws_retry_range_t; - typedef struct lws_retry_bo { - const lws_retry_range_t *retry_ms_table; /* backoff range pair */ - uint16_t retry_ms_table_count; /* ranges in table */ - uint16_t conceal_count; /* max retries to conceal */ + const uint32_t *retry_ms_table; /* base delay in ms */ + uint16_t retry_ms_table_count; /* entries in table */ + uint16_t conceal_count; /* max retries to conceal */ + uint16_t secs_since_valid_ping; /* idle before PING issued */ + uint16_t secs_since_valid_hangup; /* idle before hangup conn */ + uint8_t jitter_percent; /* % additional random jitter */ } lws_retry_bo_t; +#define LWS_RETRY_CONCEAL_ALWAYS (0xffff) + /** * lws_retry_get_delay_ms() - get next delay from backoff table * * \param lws_context: the lws context (used for getting random) - * \param retry: the retry backoff table we are using + * \param retry: the retry backoff table we are using, or NULL for default * \param ctry: pointer to the try counter * \param conceal: pointer to flag set to nonzero if the try should be concealed * in terms of creating an error @@ -52,9 +47,49 @@ * set if the number of tries is less than the backoff table conceal_count, or * is zero if it exceeded it. This lets you conceal a certain number of retries * before alerting the caller there is a problem. + * + * If \p retry is NULL, a default of 3s + (0..300ms jitter) is used. If it's + * non-NULL but jitter_percent is 0, the default of 30% jitter is retained. */ LWS_VISIBLE LWS_EXTERN unsigned int lws_retry_get_delay_ms(struct lws_context *context, const lws_retry_bo_t *retry, - uint16_t *ctry, char *conceal); + uint16_t *ctry, char *conceal); + +/** + * lws_retry_sul_schedule() - schedule a sul according to the backoff table + * + * \param lws_context: the lws context (used for getting random) + * \param sul: pointer to the sul to schedule + * \param retry: the retry backoff table we are using, or NULL for default + * \param cb: the callback for when the sul schedule time arrives + * \param ctry: pointer to the try counter + * + * Helper that combines interpreting the retry table with scheduling a sul to + * the computed delay. If conceal is not set, it will not schedule the sul + * and just return 1. Otherwise the sul is scheduled and it returns 0. + */ +LWS_VISIBLE LWS_EXTERN int +lws_retry_sul_schedule(struct lws_context *context, int tid, + lws_sorted_usec_list_t *sul, const lws_retry_bo_t *retry, + sul_cb_t cb, uint16_t *ctry); +/** + * lws_retry_sul_schedule_retry_wsi() - retry sul schedule helper using wsi + * + * \param wsi: the wsi to set the hrtimer sul on to the next retry interval + * \param sul: pointer to the sul to schedule + * \param cb: the callback for when the sul schedule time arrives + * \param ctry: pointer to the try counter + * + * Helper that uses context, tid and retry policy from a wsi to call + * lws_retry_sul_schedule. + * + * Since a udp connection can have many writes in flight, the retry count and + * the sul used to track each thing that wants to be written have to be handled + * individually, not the wsi. But the retry policy and the other things can + * be filled in from the wsi conveniently. + */ +LWS_VISIBLE LWS_EXTERN int +lws_retry_sul_schedule_retry_wsi(struct lws *wsi, lws_sorted_usec_list_t *sul, + sul_cb_t cb, uint16_t *ctry); diff -Nru libwebsockets-3.2.1/include/libwebsockets/lws-ring.h libwebsockets-4.1.6/include/libwebsockets/lws-ring.h --- libwebsockets-3.2.1/include/libwebsockets/lws-ring.h 2019-12-18 14:45:31.000000000 +0000 +++ libwebsockets-4.1.6/include/libwebsockets/lws-ring.h 2020-12-01 17:40:26.000000000 +0000 @@ -1,24 +1,25 @@ /* * libwebsockets - small server side websockets and web server implementation * - * Copyright (C) 2010-2018 Andy Green + * Copyright (C) 2010 - 2019 Andy Green * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation: - * version 2.1 of the License. - * - * This library is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with this library; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, - * MA 02110-1301 USA - * - * included from libwebsockets.h + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to + * deal in the Software without restriction, including without limitation the + * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or + * sell copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS + * IN THE SOFTWARE. */ /** \defgroup lws_ring LWS Ringbuffer APIs @@ -276,11 +277,11 @@ ___n = 0; \ ___oldest = *(___ptail); \ lws_start_foreach_llp(___type **, ___ppss, ___list_head) { \ - ___m = lws_ring_get_count_waiting_elements( \ - ___ring, &(*___ppss)->tail); \ + ___m = (int)lws_ring_get_count_waiting_elements( \ + ___ring, &(*___ppss)->___mtail); \ if (___m >= ___n) { \ ___n = ___m; \ - ___oldest = (*___ppss)->tail; \ + ___oldest = (*___ppss)->___mtail; \ } \ } lws_end_foreach_llp(___ppss, ___mlist); \ \ diff -Nru libwebsockets-3.2.1/include/libwebsockets/lws-secure-streams-client.h libwebsockets-4.1.6/include/libwebsockets/lws-secure-streams-client.h --- libwebsockets-3.2.1/include/libwebsockets/lws-secure-streams-client.h 1970-01-01 00:00:00.000000000 +0000 +++ libwebsockets-4.1.6/include/libwebsockets/lws-secure-streams-client.h 2020-12-01 17:40:26.000000000 +0000 @@ -0,0 +1,218 @@ +/* + * libwebsockets - small server side websockets and web server implementation + * + * Copyright (C) 2019 - 2020 Andy Green + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to + * deal in the Software without restriction, including without limitation the + * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or + * sell copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS + * IN THE SOFTWARE. + * + * This is the headers for secure stream api variants that deal with clients in + * different threads or even different processes. + * + * lws_ss_ when client is directly using the event loop + * lws_sstc_ when client is in a different thread to the event loop + * lws_sspc_ when client is in a different process to the event loop + * + * The client api is almost the same except the slightly diffent names. + */ + +/* + * lws_sspc_ apis... different process + */ + +/* + * Helper translation so user code written to lws_ss_ can be built for + * lws_sspc_ in one step by #define LWS_SS_USE_SSPC before including + */ + +#if defined(LWS_SS_USE_SSPC) +#define lws_ss_handle lws_sspc_handle +#define lws_ss_create lws_sspc_create +#define lws_ss_destroy lws_sspc_destroy +#define lws_ss_request_tx lws_sspc_request_tx +#define lws_ss_request_tx_len lws_sspc_request_tx_len +#define lws_ss_client_connect lws_sspc_client_connect +#define lws_ss_get_sequencer lws_sspc_get_sequencer +#define lws_ss_proxy_create lws_sspc_proxy_create +#define lws_ss_get_context lws_sspc_get_context +#define lws_ss_rideshare lws_sspc_rideshare +#define lws_ss_set_metadata lws_sspc_set_metadata +#define lws_ss_add_peer_tx_credit lws_sspc_add_peer_tx_credit +#define lws_ss_get_est_peer_tx_credit lws_sspc_get_est_peer_tx_credit +#define lws_ss_start_timeout lws_sspc_start_timeout +#define lws_ss_cancel_timeout lws_sspc_cancel_timeout +#define lws_ss_to_user_object lws_sspc_to_user_object +#define lws_ss_change_handlers lws_sspc_change_handlers +#endif + + +struct lws_sspc_handle; + +LWS_VISIBLE LWS_EXTERN int +lws_sspc_create(struct lws_context *context, int tsi, const lws_ss_info_t *ssi, + void *opaque_user_data, struct lws_sspc_handle **ppss, + struct lws_sequencer *seq_owner, const char **ppayload_fmt); + +/** + * lws_sspc_destroy() - Destroy secure stream + * + * \param ppss: pointer to lws_ss_t pointer to be destroyed + * + * Destroys the lws_ss_t pointed to by *ppss, and sets *ppss to NULL. + */ +LWS_VISIBLE LWS_EXTERN void +lws_sspc_destroy(struct lws_sspc_handle **ppss); + +/** + * lws_sspc_request_tx() - Schedule stream for tx + * + * \param pss: pointer to lws_ss_t representing stream that wants to transmit + * + * Schedules a write on the stream represented by \p pss. When it's possible to + * write on this stream, the *tx callback will occur with an empty buffer for + * the stream owner to fill in. + */ +LWS_VISIBLE LWS_EXTERN lws_ss_state_return_t +lws_sspc_request_tx(struct lws_sspc_handle *pss); + +/** + * lws_sspc_request_tx_len() - Schedule stream for tx with length hint + * + * \param h: pointer to handle representing stream that wants to transmit + * \param len: the length of the write in bytes + * + * Schedules a write on the stream represented by \p pss. When it's possible to + * write on this stream, the *tx callback will occur with an empty buffer for + * the stream owner to fill in. + * + * This api variant should be used when it's possible the payload will go out + * over h1 with x-web-form-urlencoded or similar Content-Type. + * + * The serialized, sspc type api actually serializes and forwards the length + * hint to its upstream proxy, where it's available for use to produce the + * internet-capable protocol framing. + */ +LWS_VISIBLE LWS_EXTERN lws_ss_state_return_t +lws_sspc_request_tx_len(struct lws_sspc_handle *h, unsigned long len); + +/** + * lws_sspc_client_connect() - Attempt the client connect + * + * \param h: secure streams handle + * + * Starts the connection process for the secure stream. Returns 0 if OK or + * nonzero if we have already failed. + */ +LWS_VISIBLE LWS_EXTERN int +lws_sspc_client_connect(struct lws_sspc_handle *h); + +/** + * lws_sspc_get_sequencer() - Return parent sequencer pointer if any + * + * \param h: secure streams handle + * + * Returns NULL if the secure stream is not associated with a sequencer. + * Otherwise returns a pointer to the owning sequencer. You can use this to + * identify which sequencer to direct messages to, from the secure stream + * callback. + */ +LWS_VISIBLE LWS_EXTERN struct lws_sequencer * +lws_sspc_get_sequencer(struct lws_sspc_handle *h); + +/** + * lws_sspc_proxy_create() - Start a unix domain socket proxy for Secure Streams + * + * \param context: lws_context + * + * Creates a vhost that listens on an abstract namespace unix domain socket at + * address "proxy.ss.lws". Client connections to this proxy to Secure Streams + */ +LWS_VISIBLE LWS_EXTERN int +lws_sspc_proxy_create(struct lws_context *context); + +/** + * lws_ss_get_context() - convenience helper to recover the lws context + * + * \h: secure streams handle + * + * Returns the lws context. Dispenses with the need to pass a copy of it into + * your secure streams handler. + */ + +LWS_VISIBLE LWS_EXTERN struct lws_context * +lws_sspc_get_context(struct lws_sspc_handle *h); + +LWS_VISIBLE LWS_EXTERN const struct lws_protocols lws_sspc_protocols[]; + +LWS_VISIBLE LWS_EXTERN const char * +lws_sspc_rideshare(struct lws_sspc_handle *h); + + +/** + * lws_sspc_set_metadata() - allow user to bind external data to defined ss metadata + * + * \h: secure streams handle + * \name: metadata name from the policy + * \value: pointer to user-managed data to bind to name + * \len: length of the user-managed data in value + * + * Binds user-managed data to the named metadata item from the ss policy. + * If present, the metadata item is handled in a protocol-specific way using + * the associated policy information. For example, in the policy + * + * "\"metadata\":" "[" + * "{\"uptag\":" "\"X-Upload-Tag:\"}," + * "{\"ctype\":" "\"Content-Type:\"}," + * "{\"xctype\":" "\"X-Content-Type:\"}" + * "]," + * + * when the policy is using h1 is interpreted to add h1 headers of the given + * name with the value of the metadata on the left. + * + * Return 0 if OK. + */ +LWS_VISIBLE LWS_EXTERN int +lws_sspc_set_metadata(struct lws_sspc_handle *h, const char *name, + const void *value, size_t len); + +LWS_VISIBLE LWS_EXTERN int +lws_sspc_add_peer_tx_credit(struct lws_sspc_handle *h, int32_t add); + +LWS_VISIBLE LWS_EXTERN int +lws_sspc_get_est_peer_tx_credit(struct lws_sspc_handle *h); + +LWS_VISIBLE LWS_EXTERN void +lws_sspc_start_timeout(struct lws_sspc_handle *h, unsigned int timeout_ms); + +LWS_VISIBLE LWS_EXTERN void +lws_sspc_cancel_timeout(struct lws_sspc_handle *h); + +LWS_VISIBLE LWS_EXTERN void * +lws_sspc_to_user_object(struct lws_sspc_handle *h); + +LWS_VISIBLE LWS_EXTERN void +lws_sspc_change_handlers(struct lws_sspc_handle *h, + lws_ss_state_return_t (*rx)(void *userobj, const uint8_t *buf, + size_t len, int flags), + lws_ss_state_return_t (*tx)(void *userobj, lws_ss_tx_ordinal_t ord, + uint8_t *buf, size_t *len, int *flags), + lws_ss_state_return_t (*state)(void *userobj, void *h_src + /* ss handle type */, + lws_ss_constate_t state, + lws_ss_tx_ordinal_t ack)); + diff -Nru libwebsockets-3.2.1/include/libwebsockets/lws-secure-streams.h libwebsockets-4.1.6/include/libwebsockets/lws-secure-streams.h --- libwebsockets-3.2.1/include/libwebsockets/lws-secure-streams.h 1970-01-01 00:00:00.000000000 +0000 +++ libwebsockets-4.1.6/include/libwebsockets/lws-secure-streams.h 2020-12-01 17:40:26.000000000 +0000 @@ -0,0 +1,645 @@ +/* + * libwebsockets - small server side websockets and web server implementation + * + * Copyright (C) 2019 - 2020 Andy Green + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to + * deal in the Software without restriction, including without limitation the + * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or + * sell copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS + * IN THE SOFTWARE. + * + * included from libwebsockets.h + * + * + * Secure Streams is a *payload-only* client communication channel where all the + * details about the connection are held in a systemwide policy database and + * are keyed by the streamtype field... the user of the communication channel + * does not know or manage the choice of endpoint, tls CA, or even wire + * protocol. The advantage is he then does not have any dependency on any of + * those and they can be changed just by changing the policy database without + * touching the code using the stream. + * + * There are two ways secure streams interfaces to user code: + * + * 1) [Linux / RTOS] the natural, smallest interface is to call back to user + * code that only operates directly from the lws event loop thread context + * (direct callbacks from lws_ss_t) + * + * lws_thread( [user code] ---- lws ) + * + * 2) [Linux] where the user code is in a different process and communicates + * asynchronously via a proxy socket + * + * user_process{ [user code] | shim | socket-}------ lws_process{ lws } + * + * In the second, IPC, case, all packets are prepended by one or more bytes + * indicating the packet type and serializing any associated data, known as + * Serialized Secure Streams or SSS. + * + * Serialized Secure Streams + * ------------------------- + * + * On the transport, adjacent packets may be coalesced, that is, the original + * packet sizes are lost and two or more packets are combined. For that reason + * the serialization format always contains a 1-byte type and then a 2-byte + * frame length. + * + * Client to proxy + * + * - Proxied connection setup + * + * - 0: LWSSS_SER_TXPRE_STREAMTYPE + * - 1: 2-byte MSB-first rest-of-frame length + * - 3: 4 byte MSB-first initial tx credit + * - 7: the streamtype name with no NUL + * + * - Proxied tx + * + * - 0: LWSSS_SER_TXPRE_TX_PAYLOAD + * - 1: 2 byte MSB-first rest-of-frame length + * - 3: 4-byte MSB-first flags + * - 7: 4-byte MSB-first us between client requested write and wrote to proxy + * - 11: 8-byte MSB-first us resolution unix time client wrote to proxy + * - 19: payload + * + * - Proxied secure stream destroy + * + * - 0: LWSSS_SER_TXPRE_DESTROYING + * - 1: 00, 00 + * + * - Proxied metadata - sent when one metadata item set clientside + * + * - 0: LWSSS_SER_TXPRE_METADATA + * - 1: 2-byte MSB-first rest-of-frame length + * - 3: 1-byte metadata name length + * - 4: metadata name + * - ...: metadata value (for rest of packet) + * + * - TX credit management - sent when using tx credit apis, cf METADATA + * + * - 0: LWSSS_SER_TXPRE_TXCR_UPDATE + * - 1: 2-byte MSB-first rest-of-frame length 00, 04 + * - 3: 4-byte additional tx credit adjust value + * + * - Stream timeout management - forwarded when user applying or cancelling t.o. + * + * - 0: LWSSS_SER_TXPRE_TIMEOUT_UPDATE + * - 1: 2-byte MSB-first rest-of-frame length 00, 04 + * - 3: 4-byte MSB-first unsigned 32-bit timeout, 0 = use policy, -1 = cancel + * + * - Passing up payload length hint + * + * - 0: LWSSS_SER_TXPRE_PAYLOAD_LENGTH_HINT + * - 1: 2-byte MSB-first rest-of-frame length 00, 04 + * - 3: 4-byte MSB-first unsigned 32-bit payload length hint + * + * Proxy to client + * + * - Proxied connection setup result + * + * - 0: LWSSS_SER_RXPRE_CREATE_RESULT + * - 1: 2 byte MSB-first rest-of-frame length (usually 00, 03) + * - 3: 1 byte result, 0 = success. On failure, proxy will close connection. + * - 4: 2 byte MSB-first initial tx credit + * - 6: if present, comma-sep list of rideshare types from policy + * + * - Proxied rx + * + * - 0: LWSSS_SER_RXPRE_RX_PAYLOAD + * - 1: 2 byte MSB-first rest-of-frame length + * - 3: 4-byte MSB-first flags + * - 7: 4-byte MSB-first us between inbound read and wrote to client + * - 11: 8-byte MSB-first us resolution unix time proxy wrote to client + * - 17: (rideshare name len + rideshare name if flags & LWSSS_FLAG_RIDESHARE) + * payload + * + * - Proxied tx credit + * + * - 0: LWSSS_SER_RXPRE_TXCR_UPDATE + * - 1: 00, 04 + * - 3: 4-byte MSB-first addition tx credit bytes + * + * - Proxied state + * + * - 0: LWSSS_SER_RXPRE_CONNSTATE + * - 1: 00, 05 if state < 256, else 00, 08 + * - 3: 1 byte state index if state < 256, else 4-byte MSB-first state index + * - 4 or 7: 4-byte MSB-first ordinal + * + * + * Proxied tx may be read by the proxy but rejected due to lack of buffer space + * at the proxy. For that reason, tx must be held at the sender until it has + * been acknowledged or denied. + * + * Sinks + * ----- + * + * Sinks are logical "servers", you can register as a sink for a particular + * streamtype by using the lws_ss_create() api with ssi->register_sink set to 1. + * + * For directly fulfilled Secure Streams, new streams of that streamtype bind + * to the rx, tx and state handlers given when it was registered. + * + * - When new streams are created the registered sink handler for (*state) is + * called with event LWSSSCS_SINK_JOIN and the new client stream handle in + * the h_src parameter. + * + * - When the client stream sends something to the sink, it calls the sink's + * (*rx) with the client stream's + */ + +#define LWS_SS_MTU 1540 + +struct lws_ss_handle; +typedef uint32_t lws_ss_tx_ordinal_t; + +/* + * connection state events + */ +typedef enum { + LWSSSCS_CREATING, + LWSSSCS_DISCONNECTED, + LWSSSCS_UNREACHABLE, + LWSSSCS_AUTH_FAILED, + LWSSSCS_CONNECTED, + LWSSSCS_CONNECTING, + LWSSSCS_DESTROYING, + LWSSSCS_POLL, + LWSSSCS_ALL_RETRIES_FAILED, /* all retries in bo policy failed */ + LWSSSCS_QOS_ACK_REMOTE, /* remote peer received and acked tx */ + LWSSSCS_QOS_NACK_REMOTE, + LWSSSCS_QOS_ACK_LOCAL, /* local proxy accepted our tx */ + LWSSSCS_QOS_NACK_LOCAL, /* local proxy refused our tx */ + LWSSSCS_TIMEOUT, /* optional timeout timer fired */ + + LWSSSCS_SERVER_TXN, + LWSSSCS_SERVER_UPGRADE, /* the server protocol upgraded */ + + LWSSSCS_SINK_JOIN, /* sinks get this when a new source + * stream joins the sink */ + LWSSSCS_SINK_PART, /* sinks get this when a new source + * stream leaves the sink */ +} lws_ss_constate_t; + +enum { + LWSSS_FLAG_SOM = (1 << 0), + /* payload contains the start of new message */ + LWSSS_FLAG_EOM = (1 << 1), + /* payload contains the end of message */ + LWSSS_FLAG_POLL = (1 << 2), + /* Not a real transmit... poll for rx if protocol needs it */ + LWSSS_FLAG_RELATED_START = (1 << 3), + /* Appears in a zero-length message indicating a message group of zero + * or more messages is now starting. */ + LWSSS_FLAG_RELATED_END = (1 << 4), + /* Appears in a zero-length message indicating a message group of zero + * or more messages has now finished. */ + LWSSS_FLAG_RIDESHARE = (1 << 5), + /* Serialized payload starts with non-default rideshare name length and + * name string without NUL, then payload */ + + /* + * In the case the secure stream is proxied across a process or thread + * boundary, eg by proxying through a socket for IPC, metadata must be + * carried in-band. A byte is prepended to each rx payload to + * differentiate what it is. + * + * Secure streams where the user is called back directly does not need + * any of this and only pure payloads are passed. + * + * rx (received by client) prepends for proxied connections + */ + + LWSSS_SER_RXPRE_RX_PAYLOAD = 0x55, + LWSSS_SER_RXPRE_CREATE_RESULT, + LWSSS_SER_RXPRE_CONNSTATE, + LWSSS_SER_RXPRE_TXCR_UPDATE, + LWSSS_SER_RXPRE_TLSNEG_ENCLAVE_SIGN, + + /* tx (send by client) prepends for proxied connections */ + + LWSSS_SER_TXPRE_STREAMTYPE = 0xaa, + LWSSS_SER_TXPRE_ONWARD_CONNECT, + LWSSS_SER_TXPRE_DESTROYING, + LWSSS_SER_TXPRE_TX_PAYLOAD, + LWSSS_SER_TXPRE_METADATA, + LWSSS_SER_TXPRE_TXCR_UPDATE, + LWSSS_SER_TXPRE_TIMEOUT_UPDATE, + LWSSS_SER_TXPRE_PAYLOAD_LENGTH_HINT, + LWSSS_SER_TXPRE_TLSNEG_ENCLAVE_SIGNED, +}; + +typedef enum { + LPCSPROX_WAIT_INITIAL_TX = 1, /* after connect, must send streamtype */ + LPCSPROX_REPORTING_FAIL, /* stream creation failed, wait to to tell */ + LPCSPROX_REPORTING_OK, /* stream creation succeeded, wait to to tell */ + LPCSPROX_OPERATIONAL, /* ready for payloads */ + LPCSPROX_DESTROYED, + + LPCSCLI_SENDING_INITIAL_TX, /* after connect, must send streamtype */ + LPCSCLI_WAITING_CREATE_RESULT, /* wait to hear if proxy ss create OK */ + LPCSCLI_LOCAL_CONNECTED, /* we are in touch with the proxy */ + LPCSCLI_ONWARD_CONNECT, /* request onward ss connection */ + LPCSCLI_OPERATIONAL, /* ready for payloads */ + +} lws_ss_conn_states_t; + +/* + * Returns from state() callback can tell the caller what the user code + * wants to do + */ + +typedef enum lws_ss_state_return { + LWSSSSRET_TX_DONT_SEND = 1, /* (*tx) only */ + + LWSSSSRET_OK = 0, /* no error */ + LWSSSSRET_DISCONNECT_ME = -1, /* caller should disconnect us */ + LWSSSSRET_DESTROY_ME = -2, /* caller should destroy us */ +} lws_ss_state_return_t; + +/** + * lws_ss_info_t: information about stream to be created + * + * Prepare this struct with information about what the stream type is and how + * the stream should interface with your code, and pass it to lws_ss_create() + * to create the requested stream. + */ + +enum { + LWSSSINFLAGS_REGISTER_SINK = (1 << 0), + /**< If set, we're not creating a specific stream, but registering + * ourselves as the "sink" for .streamtype. It's analogous to saying + * we want to be the many-to-one "server" for .streamtype; when other + * streams are created with that streamtype, they should be forwarded + * to this stream owner, where they join and part from the sink via + * (*state) LWSSSCS_SINK_JOIN / _PART events, the new client handle + * being provided in the h_src parameter. + */ + LWSSSINFLAGS_PROXIED = (1 << 1), + /**< Set if the stream is being created as a stand-in at the proxy */ + LWSSSINFLAGS_SERVER = (1 << 2), + /**< Set on the server object copy of the ssi / info to indicate that + * stream creation using this ssi is for Accepted connections belonging + * to a server */ + LWSSSINFLAGS_ACCEPTED = (1 << 3), + /**< Set on the accepted object copy of the ssi / info to indicate that + * we are an accepted connection from a server's listening socket */ +}; + +typedef struct lws_ss_info { + const char *streamtype; /**< type of stream we want to create */ + size_t user_alloc; /**< size of user allocation */ + size_t handle_offset; /**< offset of handle stg in user_alloc type, + set to offsetof(mytype, my_handle_member) */ + size_t opaque_user_data_offset; + /**< offset of opaque user data ptr in user_alloc type, set to + offsetof(mytype, opaque_ud_member) */ + + lws_ss_state_return_t (*rx)(void *userobj, const uint8_t *buf, + size_t len, int flags); + /**< callback with rx payload for this stream */ + lws_ss_state_return_t (*tx)(void *userobj, lws_ss_tx_ordinal_t ord, + uint8_t *buf, size_t *len, int *flags); + /**< callback to send payload on this stream... 0 = send as set in + * len and flags, 1 = do not send anything (ie, not even 0 len frame) */ + lws_ss_state_return_t (*state)(void *userobj, void *h_src /* ss handle type */, + lws_ss_constate_t state, lws_ss_tx_ordinal_t ack); + /**< advisory cb about state of stream and QoS status if applicable... + * h_src is only used with sinks and LWSSSCS_SINK_JOIN/_PART events. + * Return nonzero to indicate you want to destroy the stream. */ + int manual_initial_tx_credit; + /**< 0 = manage any tx credit automatically, nonzero explicitly sets the + * peer stream to have the given amount of tx credit, if the protocol + * can support it. + * + * In the special case of _lws_smd streamtype, this is used to indicate + * the connection's rx class mask. + * */ + uint8_t flags; + +} lws_ss_info_t; + +/** + * lws_ss_create() - Create secure stream + * + * \param context: the lws context to create this inside + * \param tsi: service thread index to create on (normally 0) + * \param ssi: pointer to lws_ss_info_t filled in with info about desired stream + * \param opaque_user_data: opaque data to set in the stream's user object + * \param ppss: pointer to secure stream handle pointer set on exit + * \param ppayload_fmt: NULL or pointer to a string ptr to take payload format + * name from the policy + * + * Requests a new secure stream described by \p ssi be created. If successful, + * the stream is created, its state callback called with LWSSSCS_CREATING, *ppss + * is set to point to the handle, and it returns 0. If it failed, it returns + * nonzero. + * + * Along with the opaque stream object, streams overallocate + * + * 1) a user data struct whose size is set in ssi + * 2) nauth plugin instantiation data (size set in the plugin struct) + * 3) sauth plugin instantiation data (size set in the plugin struct) + * 4) space for a copy of the stream type name + * + * The user data struct is initialized to all zeros, then the .handle_offset and + * .opaque_user_data_offset fields of the ssi are used to prepare the user data + * struct with the ss handle that was created, and a copy of the + * opaque_user_data pointer given as an argument. + * + * If you want to set up the stream with specific information, point to it in + * opaque_user_data and use the copy of that pointer in your user data member + * for it starting from the LWSSSCS_CREATING state call. + * + * Since different endpoints chosen by the policy may require different payload + * formats, \p ppayload_fmt is set to point to the name of the needed payload + * format from the policy database if non-NULL. + */ +LWS_VISIBLE LWS_EXTERN int +lws_ss_create(struct lws_context *context, int tsi, const lws_ss_info_t *ssi, + void *opaque_user_data, struct lws_ss_handle **ppss, + struct lws_sequencer *seq_owner, const char **ppayload_fmt); + +/** + * lws_ss_destroy() - Destroy secure stream + * + * \param ppss: pointer to lws_ss_t pointer to be destroyed + * + * Destroys the lws_ss_t pointed to by *ppss, and sets *ppss to NULL. + */ +LWS_VISIBLE LWS_EXTERN void +lws_ss_destroy(struct lws_ss_handle **ppss); + +/** + * lws_ss_request_tx() - Schedule stream for tx + * + * \param pss: pointer to lws_ss_t representing stream that wants to transmit + * + * Schedules a write on the stream represented by \p pss. When it's possible to + * write on this stream, the *tx callback will occur with an empty buffer for + * the stream owner to fill in. + * + * Returns 0 or LWSSSSRET_SS_HANDLE_DESTROYED + */ +LWS_VISIBLE LWS_EXTERN lws_ss_state_return_t +lws_ss_request_tx(struct lws_ss_handle *pss); + +/** + * lws_ss_request_tx() - Schedule stream for tx + * + * \param pss: pointer to lws_ss_t representing stream that wants to transmit + * \param len: the length of the write in bytes + * + * Schedules a write on the stream represented by \p pss. When it's possible to + * write on this stream, the *tx callback will occur with an empty buffer for + * the stream owner to fill in. + * + * This api variant should be used when it's possible the payload will go out + * over h1 with x-web-form-urlencoded or similar Content-Type. + */ +LWS_VISIBLE LWS_EXTERN lws_ss_state_return_t +lws_ss_request_tx_len(struct lws_ss_handle *pss, unsigned long len); + +/** + * lws_ss_client_connect() - Attempt the client connect + * + * \param h: secure streams handle + * + * Starts the connection process for the secure stream. Returns 0 if OK or + * nonzero if we have already failed. + */ +LWS_VISIBLE LWS_EXTERN int +lws_ss_client_connect(struct lws_ss_handle *h); + +/** + * lws_ss_get_sequencer() - Return parent sequencer pointer if any + * + * \param h: secure streams handle + * + * Returns NULL if the secure stream is not associated with a sequencer. + * Otherwise returns a pointer to the owning sequencer. You can use this to + * identify which sequencer to direct messages to, from the secure stream + * callback. + */ +LWS_VISIBLE LWS_EXTERN struct lws_sequencer * +lws_ss_get_sequencer(struct lws_ss_handle *h); + +/** + * lws_ss_proxy_create() - Start a unix domain socket proxy for Secure Streams + * + * \param context: lws_context + * \param bind: if port is 0, unix domain path with leading @ for abstract. + * if port nonzero, NULL, or network interface to bind listen to + * \param port: tcp port to listen on + * + * Creates a vhost that listens either on an abstract namespace unix domain + * socket (port = 0) or a tcp listen socket (port nonzero). If bind is NULL + * and port is 0, the abstract unix domain socket defaults to "proxy.ss.lws". + * + * Client connections to this proxy to Secure Streams are fulfilled using the + * policy local to the proxy and the data passed between the client and the + * proxy using serialized Secure Streams protocol. + */ +LWS_VISIBLE LWS_EXTERN int +lws_ss_proxy_create(struct lws_context *context, const char *bind, int port); + +/** + * lws_ss_state_name() - convenience helper to get a printable conn state name + * + * \param state: the connection state index + * + * Returns a printable name for the connection state index passed in. + */ +LWS_VISIBLE LWS_EXTERN const char * +lws_ss_state_name(int state); + +/** + * lws_ss_get_context() - convenience helper to recover the lws context + * + * \param h: secure streams handle + * + * Returns the lws context. Dispenses with the need to pass a copy of it into + * your secure streams handler. + */ +LWS_VISIBLE LWS_EXTERN struct lws_context * +lws_ss_get_context(struct lws_ss_handle *h); + +#define LWSSS_TIMEOUT_FROM_POLICY 0 + +/** + * lws_ss_start_timeout() - start or restart the timeout on the stream + * + * \param h: secure streams handle + * \param timeout_ms: LWSSS_TIMEOUT_FROM_POLICY for policy value, else use timeout_ms + * + * Starts or restarts the stream's own timeout timer. If the specified time + * passes without lws_ss_cancel_timeout() being called on the stream, then the + * stream state callback receives LWSSSCS_TIMEOUT + * + * The process being protected by the timeout is up to the user code, it may be + * arbitrarily long and cross multiple protocol transactions or involve other + * streams. It's up to the user to decide when to start and when / if to cancel + * the stream timeout. + */ +LWS_VISIBLE LWS_EXTERN void +lws_ss_start_timeout(struct lws_ss_handle *h, unsigned int timeout_ms); + +/** + * lws_ss_cancel_timeout() - remove any timeout on the stream + * + * \param h: secure streams handle + * + * Disable any timeout that was applied to the stream by lws_ss_start_timeout(). + */ +LWS_VISIBLE LWS_EXTERN void +lws_ss_cancel_timeout(struct lws_ss_handle *h); + +/** + * lws_ss_to_user_object() - convenience helper to get user object from handle + * + * \param h: secure streams handle + * + * Returns the user allocation related to the handle. Normally you won't need + * this since it's available in the rx, tx and state callbacks as "userdata" + * already. + */ +LWS_VISIBLE LWS_EXTERN void * +lws_ss_to_user_object(struct lws_ss_handle *h); + +/** + * lws_ss_rideshare() - find the current streamtype when types rideshare + * + * \param h: the stream handle + * + * Under some conditions, the payloads may be structured using protocol- + * specific formatting, eg, http multipart mime. It's possible to map the + * logical partitions in the payload to different stream types using + * the policy "rideshare" feature. + * + * This api lets the callback code find out which rideshare stream type the + * current payload chunk belongs to. + */ +LWS_VISIBLE LWS_EXTERN const char * +lws_ss_rideshare(struct lws_ss_handle *h); + + +/** + * lws_ss_set_metadata() - allow user to bind external data to defined ss metadata + * + * \param h: secure streams handle + * \param name: metadata name from the policy + * \param value: pointer to user-managed data to bind to name + * \param len: length of the user-managed data in value + * + * Binds user-managed data to the named metadata item from the ss policy. + * If present, the metadata item is handled in a protocol-specific way using + * the associated policy information. For example, in the policy + * + * "\"metadata\":" "[" + * "{\"uptag\":" "\"X-Upload-Tag:\"}," + * "{\"ctype\":" "\"Content-Type:\"}," + * "{\"xctype\":" "\"\"}" + * "]," + * + * when the policy is using h1 is interpreted to add h1 headers of the given + * name with the value of the metadata on the left. + * + * Return 0 if OK or nonzero if, eg, metadata name does not exist on the + * streamtype. + */ +LWS_VISIBLE LWS_EXTERN int +lws_ss_set_metadata(struct lws_ss_handle *h, const char *name, + const void *value, size_t len); + +/* + * lws_ss_server_ack() - indicate how we feel about what the server has sent + * + * \param h: ss handle of accepted connection + * \param nack: 0 means we are OK with it, else some problem + * + * For SERVER secure streams + * + * Depending on the protocol, the server sending us something may be + * transactional, ie, built into it sending something is the idea we will + * respond somehow out-of-band; HTTP is like this with, eg, 200 response code. + * + * Calling this with nack=0 indicates that when we later respond, we want to + * acknowledge the transaction (eg, it means a 200 if http underneath), if + * nonzero that the transaction should act like it failed. + * + * If the underlying protocol doesn't understand transactions (eg, ws) then this + * has no effect either way. + */ +LWS_VISIBLE LWS_EXTERN void +lws_ss_server_ack(struct lws_ss_handle *h, int nack); + +/** + * lws_ss_change_handlers() - helper for dynamically changing stream handlers + * + * \param h: ss handle + * \param rx: the new RX handler + * \param tx: the new TX handler + * \param state: the new state handler + * + * Handlers set to NULL are left unchanged. + * + * This works on any handle, client or server and takes effect immediately. + * + * Depending on circumstances this may be helpful when + * + * a) a server stream undergoes an LWSSSCS_SERVER_UPGRADE (as in http -> ws) and + * the payloads in the new protocol have a different purpose that is best + * handled in their own rx and tx callbacks, and + * + * b) you may want to serve several different, possibly large things based on + * what was requested. Setting a customized handler allows clean encapsulation + * of the different serving strategies. + * + * If the stream is long-lived, like ws, you should set the changed handler back + * to the default when the transaction wanting it is completed. + */ +LWS_VISIBLE LWS_EXTERN void +lws_ss_change_handlers(struct lws_ss_handle *h, + int (*rx)(void *userobj, const uint8_t *buf, size_t len, int flags), + int (*tx)(void *userobj, lws_ss_tx_ordinal_t ord, uint8_t *buf, + size_t *len, int *flags), + int (*state)(void *userobj, void *h_src /* ss handle type */, + lws_ss_constate_t state, lws_ss_tx_ordinal_t ack)); + +/** + * lws_ss_add_peer_tx_credit() - allow peer to transmit more to us + * + * \param h: secure streams handle + * \param add: additional tx credit (signed) + * + * Indicate to remote peer that we can accept \p add bytes more payload being + * sent to us. + */ +LWS_VISIBLE LWS_EXTERN int +lws_ss_add_peer_tx_credit(struct lws_ss_handle *h, int32_t add); + +/** + * lws_ss_get_est_peer_tx_credit() - get our current estimate of peer's tx credit + * + * \param h: secure streams handle + * + * Based on what credit we gave it, and what we have received, report our + * estimate of peer's tx credit usable to transmit to us. This may be outdated + * in that some or all of its credit may already have been expended by sending + * stuff to us that is in flight already. + */ +LWS_VISIBLE LWS_EXTERN int +lws_ss_get_est_peer_tx_credit(struct lws_ss_handle *h); diff -Nru libwebsockets-3.2.1/include/libwebsockets/lws-secure-streams-policy.h libwebsockets-4.1.6/include/libwebsockets/lws-secure-streams-policy.h --- libwebsockets-3.2.1/include/libwebsockets/lws-secure-streams-policy.h 1970-01-01 00:00:00.000000000 +0000 +++ libwebsockets-4.1.6/include/libwebsockets/lws-secure-streams-policy.h 2020-12-01 17:40:26.000000000 +0000 @@ -0,0 +1,317 @@ +/* + * libwebsockets - small server side websockets and web server implementation + * + * Copyright (C) 2019 - 2020 Andy Green + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to + * deal in the Software without restriction, including without limitation the + * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or + * sell copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS + * IN THE SOFTWARE. + * + * included from libwebsockets.h + */ + +typedef int (*plugin_auth_status_cb)(struct lws_ss_handle *ss, int status); + +/** + * lws_ss_plugin_auth_t - api for an auth plugin + * + * Auth plugins create and sequence authenticated connections that can carry one + * or more streams to an endpoint. That may involve other connections to other + * places to eg, gather authenticated tokens and then make the real connection + * using the tokens. + * + * The secure stream object contains members to record which auth plugin the + * stream is bound to and an over-allocation of the secure stream object to + * contain the plugin auth private data. + * + * The auth plugin controls the state of the stream connection via the status + * callback, and handles retries. + * + * Network connections may require one kind of auth sequencing, and streams + * inside those connections another kind of auth sequencing depending on their + * role. So the secure stream object allows defining plugins for both kinds. + * + * Streams may disappear at any time and require reauth to bring a new one up. + * The auth plugin sequencer will connect / reconnect either on demand, or from + * the start and after any connectivity loss if any stream using the connection + * has the LWSSSPOLF_NAILED_UP flag. + */ + +#if defined(LWS_WITH_SSPLUGINS) +typedef struct lws_ss_plugin { + struct lws_ss_plugin *next; + const char *name; /**< auth plugin name */ + size_t alloc; /**< size of private allocation */ + + int (*create)(struct lws_ss_handle *ss, void *info, + plugin_auth_status_cb status); + /**< called when the auth plugin is instantiated + and bound to the secure stream. status is + called back with advisory information about + the authenticated stream state as it + proceeds */ + int (*destroy)(struct lws_ss_handle *ss); + /**< called when the related secure stream is + being destroyed, and anything the auth + plugin is doing should also be destroyed */ + int (*munge)(struct lws_ss_handle *ss, char *path, + size_t path_len); + /**< if the plugin needs to munge transactions + that have metadata outside the payload (eg, + add http headers) this callback will give + it the opportunity to do so */ +} lws_ss_plugin_t; +#endif + +typedef struct lws_ss_x509 { + struct lws_ss_x509 *next; + const char *vhost_name; /**< vhost name using cert ctx */ + const uint8_t *ca_der; /**< DER x.509 cert */ + size_t ca_der_len; /**< length of DER cert */ + uint8_t keep:1; /**< ie, if used in server tls */ +} lws_ss_x509_t; + +enum { + LWSSSPOLF_OPPORTUNISTIC = (1 << 0), + /**< the connection doesn't exist unless client asks to write */ + LWSSSPOLF_NAILED_UP = (1 << 1), + /**< the connection tries to be connected the whole life of the ss */ + LWSSSPOLF_URGENT_TX = (1 << 2), + /**< this connection carries critical tx data */ + LWSSSPOLF_URGENT_RX = (1 << 3), + /**< this connection carries critical rx data */ + LWSSSPOLF_TLS = (1 << 4), + /**< stream must be connected via a tls tunnel */ + LWSSSPOLF_LONG_POLL = (1 << 5), + /**< stream used to receive async rx at arbitrary intervals */ + LWSSSPOLF_AUTH_BEARER = (1 << 6), + /**< for http, use lws_system auth token 0 in authentication: bearer */ + LWSSSPOLF_HTTP_NO_CONTENT_LENGTH = (1 << 7), + /**< don't add any content length even if we have it */ + LWSSSPOLF_QUIRK_NGHTTP2_END_STREAM = (1 << 8), + /**< set the client flag LCCSCF_H2_QUIRK_NGHTTP2_END_STREAM */ + LWSSSPOLF_H2_QUIRK_OVERFLOWS_TXCR = (1 << 9), + /**< set the client flag LCCSCF_H2_QUIRK_OVERFLOWS_TXCR */ + LWSSSPOLF_H2_QUIRK_UNCLEAN_HPACK_STATE = (1 << 10), + /**< HPACK decoder state does not end cleanly */ + LWSSSPOLF_HTTP_MULTIPART = (1 << 11), + /**< indicates stream goes out as specifically a multipart mime POST + * section... if the tx has LWSSS_FLAG_COALESCE_CONTINUES flag then more + * multipart sections are expected. Without it, the multipart wrapper + * is closed and the http transaction issue completed when this message + * finishes. */ + LWSSSPOLF_HTTP_X_WWW_FORM_URLENCODED = (1 << 12), + /**< set up lws_system client cert */ + LWSSSPOLF_LOCAL_SINK = (1 << 13), + /**< expected to bind to a local sink only */ + LWSSSPOLF_WAKE_SUSPEND__VALIDITY = (1 << 14), + /**< this stream's idle validity checks are critical enough we + * should arrange to wake from suspend to perform them + */ + LWSSSPOLF_SERVER = (1 << 15), + /**< we listen on a socket as a server */ + LWSSSPOLF_ALLOW_REDIRECTS = (1 << 16), + /**< follow redirects */ + LWSSSPOLF_HTTP_MULTIPART_IN = (1 << 17), + /**< handle inbound multipart mime at SS level */ +}; + +typedef struct lws_ss_trust_store { + struct lws_ss_trust_store *next; + const char *name; + + const lws_ss_x509_t *ssx509[6]; + int count; +} lws_ss_trust_store_t; + +enum { + LWSSSP_H1, + LWSSSP_H2, + LWSSSP_WS, + LWSSSP_MQTT, + LWSSSP_RAW, + + + LWSSS_HBI_AUTH = 0, + LWSSS_HBI_DSN, + LWSSS_HBI_FWV, + LWSSS_HBI_TYPE, + + _LWSSS_HBI_COUNT /* always last */ +}; + +typedef struct lws_ss_metadata { + struct lws_ss_metadata *next; + const char *name; + void *value; + size_t length; + + uint8_t value_on_lws_heap; /* proxy does this */ +} lws_ss_metadata_t; + + +/** + * lws_ss_policy_t: policy database entry for a stream type + * + * Decides the system policy for how to implement connections of name + * .streamtype. + * + * Streams may need one kind of auth sequencing for the network connection and + * another kind of auth sequencing for the streams that are carried inside it, + * this is the purpose of .nauth and .sauth. Both are optional and may be NULL. + * + * An array of these is set at context creation time, ending with one with a + * NULL streamtype. + */ +typedef struct lws_ss_policy { + struct lws_ss_policy *next; + const char *streamtype; /**< stream type lhs to match on */ + + const char *endpoint; /**< DNS address to connect to */ + const char *rideshare_streamtype; /**< optional transport + * on another, preexisting stream of this + * streamtype name */ + const char *payload_fmt; + const char *socks5_proxy; + lws_ss_metadata_t *metadata; /* linked-list of metadata */ + + /* protocol-specific connection policy details */ + + union { + +#if defined(LWS_ROLE_H1) || defined(LWS_ROLE_H2) || defined(LWS_ROLE_WS) + + /* details for http-related protocols... */ + + struct { + + /* common to all http-related protocols */ + + const char *method; + const char *url; + + const char *multipart_name; + const char *multipart_filename; + const char *multipart_content_type; + + const char *blob_header[_LWSSS_HBI_COUNT]; + const char *auth_preamble; + + union { +// struct { /* LWSSSP_H1 */ +// } h1; +// struct { /* LWSSSP_H2 */ +// } h2; + struct { /* LWSSSP_WS */ + const char *subprotocol; + uint8_t binary; + /* false = TEXT, true = BINARY */ + } ws; + } u; + + uint16_t resp_expect; + uint8_t fail_redirect:1; + } http; + +#endif + +#if defined(LWS_ROLE_MQTT) + + struct { + const char *topic; /* stream sends on this topic */ + const char *subscribe; /* stream subscribes to this topic */ + + const char *will_topic; + const char *will_message; + + uint16_t keep_alive; + uint8_t qos; + uint8_t clean_start; + uint8_t will_qos; + uint8_t will_retain; + + } mqtt; + +#endif + + /* details for non-http related protocols... */ + } u; + +#if defined(LWS_WITH_SSPLUGINS) + const + struct lws_ss_plugin *plugins[2]; /**< NULL or auth plugin */ + const void *plugins_info[2]; /**< plugin-specific data */ +#endif + + /* + * We're either a client connection policy that wants a trust store, + * or we're a server policy that wants a mem cert and key... Hold + * these mutually-exclusive things in a union. + */ + + union { + const lws_ss_trust_store_t *store; + /**< CA certs needed for conn validation, only set between + * policy parsing and vhost creation */ + struct { + const lws_ss_x509_t *cert; + /**< the server's signed cert with the pubkey */ + const lws_ss_x509_t *key; + /**< the server's matching private key */ + } server; + } trust; + + const lws_retry_bo_t *retry_bo; /**< retry policy to use */ + + uint32_t timeout_ms; /**< default message response + * timeout in ms */ + uint32_t flags; /**< stream attribute flags */ + + uint16_t port; /**< endpoint port */ + + uint8_t metadata_count; /**< metadata count */ + uint8_t protocol; /**< protocol index */ + uint8_t client_cert; /**< which client cert to apply + 0 = none, 1+ = cc 0+ */ +} lws_ss_policy_t; + +#if !defined(LWS_WITH_SECURE_STREAMS_STATIC_POLICY_ONLY) + +/* + * These only exist / have meaning if there's a dynamic JSON policy enabled + */ + +LWS_VISIBLE LWS_EXTERN int +lws_ss_policy_parse_begin(struct lws_context *context, int overlay); + +LWS_VISIBLE LWS_EXTERN int +lws_ss_policy_parse_abandon(struct lws_context *context); + +LWS_VISIBLE LWS_EXTERN int +lws_ss_policy_parse(struct lws_context *context, const uint8_t *buf, size_t len); + +LWS_VISIBLE LWS_EXTERN int +lws_ss_policy_overlay(struct lws_context *context, const char *overlay); + +/* + * You almost certainly don't want this, it returns the first policy object + * in a linked-list of objects created by lws_ss_policy_parse above + */ +LWS_VISIBLE LWS_EXTERN const lws_ss_policy_t * +lws_ss_policy_get(struct lws_context *context); + +#endif diff -Nru libwebsockets-3.2.1/include/libwebsockets/lws-sequencer.h libwebsockets-4.1.6/include/libwebsockets/lws-sequencer.h --- libwebsockets-3.2.1/include/libwebsockets/lws-sequencer.h 2019-12-18 14:45:31.000000000 +0000 +++ libwebsockets-4.1.6/include/libwebsockets/lws-sequencer.h 2020-12-01 17:40:26.000000000 +0000 @@ -1,24 +1,25 @@ -/* + /* * libwebsockets - small server side websockets and web server implementation * - * Copyright (C) 2010-2019 Andy Green - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation: - * version 2.1 of the License. - * - * This library is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with this library; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, - * MA 02110-1301 USA + * Copyright (C) 2010 - 2019 Andy Green * - * included from libwebsockets.h + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to + * deal in the Software without restriction, including without limitation the + * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or + * sell copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS + * IN THE SOFTWARE. * * lws_sequencer is intended to help implement sequences that: * @@ -48,6 +49,14 @@ LWSSEQ_WSI_CONN_FAIL, /* wsi we bound to us has failed to connect */ LWSSEQ_WSI_CONN_CLOSE, /* wsi we bound to us has closed */ + + LWSSEQ_SS_STATE_BASE, /* secure streams owned by a sequencer provide + * automatic messages about state changes on + * the sequencer, passing the oridinal in the + * event argument field. The message index is + * LWSSEQ_SS_STATE_BASE + the enum from + * lws_ss_constate_t */ + LWSSEQ_USER_BASE = 100 /* define your events from here */ } lws_seq_events_t; @@ -78,6 +87,8 @@ lws_seq_event_cb cb; /* seq callback */ const char *name; /* seq name */ const lws_retry_bo_t *retry; /* retry policy */ + uint8_t wakesuspend:1; /* important enough to + * wake system */ } lws_seq_info_t; /** @@ -95,7 +106,7 @@ * * pt locking is used to protect the related data structures. */ -LWS_VISIBLE LWS_EXTERN lws_seq_t * +LWS_VISIBLE LWS_EXTERN struct lws_sequencer * lws_seq_create(lws_seq_info_t *info); /** @@ -109,7 +120,7 @@ * set to NULL. */ LWS_VISIBLE LWS_EXTERN void -lws_seq_destroy(lws_seq_t **seq); +lws_seq_destroy(struct lws_sequencer **seq); /** * lws_seq_queue_event() - queue an event on the given sequencer @@ -129,7 +140,7 @@ * values here. */ LWS_VISIBLE LWS_EXTERN int -lws_seq_queue_event(lws_seq_t *seq, lws_seq_events_t e, void *data, +lws_seq_queue_event(struct lws_sequencer *seq, lws_seq_events_t e, void *data, void *aux); /** @@ -149,7 +160,7 @@ * close message yet. */ LWS_VISIBLE LWS_EXTERN int -lws_seq_check_wsi(lws_seq_t *seq, struct lws *wsi); +lws_seq_check_wsi(struct lws_sequencer *seq, struct lws *wsi); #define LWSSEQTO_NONE 0 @@ -179,7 +190,7 @@ * react appropriately. */ LWS_VISIBLE LWS_EXTERN int -lws_seq_timeout_us(lws_seq_t *seq, lws_usec_t us); +lws_seq_timeout_us(struct lws_sequencer *seq, lws_usec_t us); /** * lws_seq_from_user(): get the lws_seq_t pointer from the user ptr @@ -194,7 +205,7 @@ * size of the lws_seq_t is unknown to user code, this helper does it for * you. */ -LWS_VISIBLE LWS_EXTERN lws_seq_t * +LWS_VISIBLE LWS_EXTERN struct lws_sequencer * lws_seq_from_user(void *u); /** @@ -207,7 +218,7 @@ * step considering a global sequencer lifetime limit. */ LWS_VISIBLE LWS_EXTERN lws_usec_t -lws_seq_us_since_creation(lws_seq_t *seq); +lws_seq_us_since_creation(struct lws_sequencer *seq); /** * lws_seq_name(): get the name of this sequencer @@ -218,7 +229,7 @@ * annotate logging when then are multiple sequencers in play. */ LWS_VISIBLE LWS_EXTERN const char * -lws_seq_name(lws_seq_t *seq); +lws_seq_name(struct lws_sequencer *seq); /** * lws_seq_get_context(): get the lws_context sequencer was created on @@ -229,4 +240,4 @@ * pointer handy. */ LWS_VISIBLE LWS_EXTERN struct lws_context * -lws_seq_get_context(lws_seq_t *seq); +lws_seq_get_context(struct lws_sequencer *seq); diff -Nru libwebsockets-3.2.1/include/libwebsockets/lws-service.h libwebsockets-4.1.6/include/libwebsockets/lws-service.h --- libwebsockets-3.2.1/include/libwebsockets/lws-service.h 2019-12-18 14:45:31.000000000 +0000 +++ libwebsockets-4.1.6/include/libwebsockets/lws-service.h 2020-12-01 17:40:26.000000000 +0000 @@ -1,24 +1,25 @@ /* * libwebsockets - small server side websockets and web server implementation * - * Copyright (C) 2010-2018 Andy Green + * Copyright (C) 2010 - 2019 Andy Green * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation: - * version 2.1 of the License. - * - * This library is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with this library; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, - * MA 02110-1301 USA - * - * included from libwebsockets.h + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to + * deal in the Software without restriction, including without limitation the + * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or + * sell copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS + * IN THE SOFTWARE. */ /** \defgroup service Built-in service loop entry @@ -166,7 +167,8 @@ * APIs specific to libuv event loop itegration */ ///@{ -#ifdef LWS_WITH_LIBUV +#if defined(LWS_WITH_LIBUV) && defined(UV_ERRNO_MAP) + /* * Any direct libuv allocations in lws protocol handlers must participate in the * lws reference counting scheme. Two apis are provided: @@ -192,7 +194,7 @@ #endif /* LWS_WITH_LIBUV */ -#if defined(LWS_WITH_ESP32) +#if defined(LWS_PLAT_FREERTOS) #define lws_libuv_static_refcount_add(_a, _b) #define lws_libuv_static_refcount_del NULL #endif diff -Nru libwebsockets-3.2.1/include/libwebsockets/lws-settings.h libwebsockets-4.1.6/include/libwebsockets/lws-settings.h --- libwebsockets-3.2.1/include/libwebsockets/lws-settings.h 1970-01-01 00:00:00.000000000 +0000 +++ libwebsockets-4.1.6/include/libwebsockets/lws-settings.h 2020-12-01 17:40:26.000000000 +0000 @@ -0,0 +1,112 @@ +/* + * Generic Settings storage + * + * Copyright (C) 2020 Andy Green + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to + * deal in the Software without restriction, including without limitation the + * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or + * sell copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS + * IN THE SOFTWARE. + * + * + * This is like an abstract class for non-volatile storage, whether in a file- + * system or flash-backed blocks, etc. Named blobs of variable size are stored + * in nonvolatile media of some sort. Typically, these are JSON objects under + * a naming scheme like, eg, "network". + * + * There's a platform-specific storage identifier opaque_plat provided when the + * storage object is instantiated, this describes eg the storage device or + * partition in instantiation-specific terms. + * + * Blobs have a further "filename" associated with them. + */ + +#define LSOOPEN_FLAG_WRITEABLE (1 << 0) + +struct lws_settings_ops; + +typedef struct { + void *handle_plat; + const struct lws_settings_ops *so; + uint8_t refcount; + void *opaque_plat; +} lws_settings_instance_t; + +typedef struct lws_settings_ops { + int (*get)(lws_settings_instance_t *si, const char *name, + uint8_t *dest, size_t *max_actual); + /**< if dest is NULL, max_actual is set to the actual length without + * copying anything out */ + int (*set)(lws_settings_instance_t *si, const char *name, + const uint8_t *src, size_t len); +} lws_settings_ops_t; + +/** + * lws_settings_plat_get() - read a named blob from a settings instance + * + * \param si: the settings instance + * \param name: the name of the setting blob in the instance + * \param dest: NULL, or the buffer to copy the setting blob info + * \param max_actual: point to size of dest, or zero; actual blob size on exit + * + * If the named blob doesn't exist in the si, or can't read, returns nonzero. + * Otherwise, returns 0 and sets *max_actual to the true blob size. If dest is + * non-NULL, as much of the blob as will fit in the amount specified by + * *max_actual on entry is copied to dest. + */ +LWS_VISIBLE LWS_EXTERN int +lws_settings_plat_get(lws_settings_instance_t *si, const char *name, + uint8_t *dest, size_t *max_actual); + +/** + * lws_settings_plat_get() - read a named blob from a settings instance + * + * \param si: the settings instance + * \param name: the name of the setting blob in the instance + * \param src: blob to copy to settings instance + * \param len: length of blob to copy + * + * Creates or replaces a settings blob of the given name made up of the \p len + * bytes of data from \p src. + */ +LWS_VISIBLE LWS_EXTERN int +lws_settings_plat_set(lws_settings_instance_t *si, const char *name, + const uint8_t *src, size_t len); + +/** + * lws_settings_plat_printf() - read a named blob from a settings instance + * + * \param si: the settings instance + * \param name: the name of the setting blob in the instance + * \param format: printf-style format string + * + * Creates or replaces a settings blob of the given name from the printf-style + * format string and arguments provided. There's no specific limit to the size, + * the size is computed and then a temp heap buffer used. + */ +LWS_VISIBLE LWS_EXTERN int +lws_settings_plat_printf(lws_settings_instance_t *si, const char *name, + const char *format, ...) LWS_FORMAT(3); + +#define lws_settings_ops_plat \ + .get = lws_settings_plat_get, \ + .set = lws_settings_plat_set, + +LWS_VISIBLE LWS_EXTERN lws_settings_instance_t * +lws_settings_init(const lws_settings_ops_t *so, void *opaque_plat); + +LWS_VISIBLE LWS_EXTERN void +lws_settings_deinit(lws_settings_instance_t **si); diff -Nru libwebsockets-3.2.1/include/libwebsockets/lws-sha1-base64.h libwebsockets-4.1.6/include/libwebsockets/lws-sha1-base64.h --- libwebsockets-3.2.1/include/libwebsockets/lws-sha1-base64.h 2019-12-18 14:45:31.000000000 +0000 +++ libwebsockets-4.1.6/include/libwebsockets/lws-sha1-base64.h 2020-12-01 17:40:26.000000000 +0000 @@ -1,24 +1,25 @@ /* * libwebsockets - small server side websockets and web server implementation * - * Copyright (C) 2010-2018 Andy Green + * Copyright (C) 2010 - 2019 Andy Green * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation: - * version 2.1 of the License. - * - * This library is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with this library; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, - * MA 02110-1301 USA - * - * included from libwebsockets.h + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to + * deal in the Software without restriction, including without limitation the + * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or + * sell copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS + * IN THE SOFTWARE. */ /** \defgroup sha SHA and B64 helpers @@ -89,5 +90,20 @@ */ LWS_VISIBLE LWS_EXTERN int lws_b64_decode_string_len(const char *in, int in_len, char *out, int out_size); + +struct lws_b64state { + unsigned char quad[4]; + size_t done; + size_t len; + int i; + int c; +}; + +LWS_VISIBLE LWS_EXTERN void +lws_b64_decode_state_init(struct lws_b64state *state); + +LWS_VISIBLE LWS_EXTERN int +lws_b64_decode_stateful(struct lws_b64state *s, const char *in, size_t *in_len, + uint8_t *out, size_t *out_size, int final); ///@} diff -Nru libwebsockets-3.2.1/include/libwebsockets/lws-smd.h libwebsockets-4.1.6/include/libwebsockets/lws-smd.h --- libwebsockets-3.2.1/include/libwebsockets/lws-smd.h 1970-01-01 00:00:00.000000000 +0000 +++ libwebsockets-4.1.6/include/libwebsockets/lws-smd.h 2020-12-01 17:40:26.000000000 +0000 @@ -0,0 +1,175 @@ +/* + * lws System Message Distribution + * + * Copyright (C) 2010 - 2020 Andy Green + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to + * deal in the Software without restriction, including without limitation the + * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or + * sell copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS + * IN THE SOFTWARE. + */ + +#define LWS_SMD_MAX_PAYLOAD 384 +#define LWS_SMD_CLASS_BITFIELD_BYTES 4 + +#define LWS_SMD_STREAMTYPENAME "_lws_smd" +#define LWS_SMD_SS_RX_HEADER_LEN 16 + +typedef uint32_t lws_smd_class_t; + +struct lws_smd_msg; /* opaque */ +struct lws_smd_peer; /* opaque */ + +/* + * Well-known device classes + */ + +enum { + LWSSMDCL_INTERACTION = (1 << 0), + /**< + * Any kind of event indicating a user was interacting with the device, + * eg, press a button, touched the screen, lifted the device etc + */ + LWSSMDCL_SYSTEM_STATE = (1 << 1), + /**< + * The lws_system state changed, eg, to OPERATIONAL + */ + LWSSMDCL_NETWORK = (1 << 2), + /**< + * Something happened on the network, eg, link-up or DHCP, or captive + * portal state update + */ +}; + +/** + * lws_smd_msg_alloc() - allocate a message of length len + * + * \param ctx: the lws_context + * \param _class: the smd message class, recipients filter on this + * \param len: the required payload length + * + * This helper returns an opaque lws_smd_msg pointer and sets *buf to a buffer + * associated with it of length \p len. + * + * In this way the lws_msg_smd type remains completely opaque and the allocated + * area can be prepared by the caller directly, without copying. + * + * On failure, it returns NULL... it may fail for OOM but it may also fail if + * you request to allocate for a message class that the system has no + * participant who is listening for that class of event currently... the event + * generation action at the caller should be bypassed without error then. + * + * This is useful if you have a message you know the length of. For text-based + * messages like JSON, lws_smd_msg_printf() is more convenient. + */ +LWS_VISIBLE LWS_EXTERN void * /* payload */ +lws_smd_msg_alloc(struct lws_context *ctx, lws_smd_class_t _class, size_t len); + +/** + * lws_smd_msg_free() - abandon a previously allocated message before sending + * + * \param payload: pointer the previously-allocated message payload + * + * Destroys a previously-allocated opaque message object and the requested + * buffer space, in the case that between allocating it and sending it, some + * condition was met that means it can no longer be sent, eg, an error + * generating the content. Otherwise there is no need to destroy allocated + * message objects with this, lws will take care of it. + */ +LWS_VISIBLE LWS_EXTERN void +lws_smd_msg_free(void **payload); + +/** + * lws_smd_msg_send() - queue a previously allocated message + * + * \param ctx: the lws_context + * \param msg: the prepared message + * + * Queues an allocated, prepared message for delivery to smd clients + * + * This is threadsafe to call from a non-service thread. + */ +LWS_VISIBLE LWS_EXTERN int +lws_smd_msg_send(struct lws_context *ctx, void *payload); + +/** + * lws_smd_msg_printf() - queue a previously allocated message + * + * \param ctx: the lws_context + * \param _class: the message class + * \param format: the format string to prepare the payload with + * \param ...: arguments for the format string, if any + * + * For string-based messages, eg, JSON, allows formatted creating of the payload + * size discovery, allocation and message send all in one step. + * + * Unlike lws_smd_msg_alloc() you do not need to know the length beforehand as + * this computes it and calls lws_smd_msg_alloc() with the correct length. + * + * To be clear this also calls through to lws_smd_msg_send(), it really does + * everything in one step. If there are no registered participants that want + * messages of \p _class, this function returns immediately without doing any + * allocation or anything else. + * + * This is threadsafe to call from a non-service thread. + */ +LWS_VISIBLE LWS_EXTERN int +lws_smd_msg_printf(struct lws_context *ctx, lws_smd_class_t _class, + const char *format, ...) LWS_FORMAT(3); + +typedef int (*lws_smd_notification_cb_t)(void *opaque, lws_smd_class_t _class, + lws_usec_t timestamp, void *buf, + size_t len); + +#define LWSSMDREG_FLAG_PROXIED_SS (1 << 0) +/**< It's actually a proxied SS connection registering, opaque is the ss h */ + +/* + * lws_smd_register() - register to receive smd messages + * + * \param ctx: the lws_context + * \param opaque: an opaque pointer handed to the callback + * \param flags: typically 0 + * \param _class_filter: bitmap of message classes we care about + * \param cb: the callback to receive messages + * + * Queues an allocated, prepared message for delivery to smd clients. + * + * Returns NULL on failure, or an opaque handle which may be given to + * lws_smd_unregister() to stop participating in the shared message queue. + * + * This is threadsafe to call from a non-service thread. + */ + +LWS_VISIBLE LWS_EXTERN struct lws_smd_peer * +lws_smd_register(struct lws_context *ctx, void *opaque, int flags, + lws_smd_class_t _class_filter, lws_smd_notification_cb_t cb); + +/* + * lws_smd_unregister() - unregister receiving smd messages + * + * \param pr: the handle returned from the registration + * + * Destroys the registration of the callback for messages and ability to send + * messages. + * + * It's not necessary to call this if the registration wants to survive for as + * long as the lws_context... lws_context_destroy will also clean up any + * registrations still active by then. + */ + +LWS_VISIBLE LWS_EXTERN void +lws_smd_unregister(struct lws_smd_peer *pr); diff -Nru libwebsockets-3.2.1/include/libwebsockets/lws-spa.h libwebsockets-4.1.6/include/libwebsockets/lws-spa.h --- libwebsockets-3.2.1/include/libwebsockets/lws-spa.h 2019-12-18 14:45:31.000000000 +0000 +++ libwebsockets-4.1.6/include/libwebsockets/lws-spa.h 2020-12-01 17:40:26.000000000 +0000 @@ -1,24 +1,25 @@ /* * libwebsockets - small server side websockets and web server implementation * - * Copyright (C) 2010-2018 Andy Green + * Copyright (C) 2010 - 2019 Andy Green * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation: - * version 2.1 of the License. + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to + * deal in the Software without restriction, including without limitation the + * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or + * sell copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: * - * This library is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. * - * You should have received a copy of the GNU Lesser General Public - * License along with this library; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, - * MA 02110-1301 USA - * - * included from libwebsockets.h + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS + * IN THE SOFTWARE. */ /** \defgroup form-parsing Form Parsing diff -Nru libwebsockets-3.2.1/include/libwebsockets/lws-spi.h libwebsockets-4.1.6/include/libwebsockets/lws-spi.h --- libwebsockets-3.2.1/include/libwebsockets/lws-spi.h 1970-01-01 00:00:00.000000000 +0000 +++ libwebsockets-4.1.6/include/libwebsockets/lws-spi.h 2020-12-01 17:40:26.000000000 +0000 @@ -0,0 +1,73 @@ +/* + * Generic I2C ops + * + * Copyright (C) 2019 - 2020 Andy Green + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to + * deal in the Software without restriction, including without limitation the + * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or + * sell copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS + * IN THE SOFTWARE. + * + * This is like an abstract class for spi, a real implementation provides + * functions for the ops that use the underlying OS arrangements. + * + * It uses descriptor / queuing semantics but eg the GPIO BB implementantion is + * synchronous. + */ + +#if !defined(__LWS_SPI_H__) +#define __LWS_SPI_H__ + +#include +#include + +typedef int (*lws_spi_cb_t)(void *opaque); + +enum { + LWSSPIMODE_CPOL = (1 << 0), + LWSSPIMODE_CPHA = (1 << 1), + + LWS_SPI_BUSMODE_CLK_IDLE_LOW_SAMP_RISING = 0, + LWS_SPI_BUSMODE_CLK_IDLE_HIGH_SAMP_RISING = LWSSPIMODE_CPOL, + LWS_SPI_BUSMODE_CLK_IDLE_LOW_SAMP_FALLING = LWSSPIMODE_CPHA, + LWS_SPI_BUSMODE_CLK_IDLE_HIGH_SAMP_FALLING = LWSSPIMODE_CPHA | + LWSSPIMODE_CPOL, + + LWS_SPI_TXN_HALF_DUPLEX_DISCRETE = 0, + /**< separate MISO and MOSI, but only either MISO or MOSI has data at + * one time... i2c style in SPI */ +}; + +typedef struct lws_spi_desc { + const uint8_t *src; + const uint8_t *data; + uint8_t *dest; + void *opaque; + lws_spi_cb_t completion_cb; + uint16_t count_cmd; + uint16_t count_write; + uint16_t count_read; + uint8_t txn_type; + uint8_t channel; +} lws_spi_desc_t; + +typedef struct lws_spi_ops { + int (*init)(const struct lws_spi_ops *ctx); + int (*queue)(const struct lws_spi_ops *ctx, const lws_spi_desc_t *desc); + uint8_t bus_mode; +} lws_spi_ops_t; + +#endif diff -Nru libwebsockets-3.2.1/include/libwebsockets/lws-ssd1306-i2c.h libwebsockets-4.1.6/include/libwebsockets/lws-ssd1306-i2c.h --- libwebsockets-3.2.1/include/libwebsockets/lws-ssd1306-i2c.h 1970-01-01 00:00:00.000000000 +0000 +++ libwebsockets-4.1.6/include/libwebsockets/lws-ssd1306-i2c.h 2020-12-01 17:40:26.000000000 +0000 @@ -0,0 +1,64 @@ +/* + * lws abstract display implementation for ssd1306 on i2c + * + * Copyright (C) 2019 - 2020 Andy Green + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to + * deal in the Software without restriction, including without limitation the + * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or + * sell copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS + * IN THE SOFTWARE. + */ + +#if !defined(__LWS_DISPLAY_SSD1306_I2C_H__) +#define __LWS_DISPLAY_SSD1306_I2C_H__ + +/* + * D/C# pin on SSD1306 sets the I2C slave ads + * from these two options (7-bit address) + */ + +#define SSD1306_I2C7_ADS1 0x3c +#define SSD1306_I2C7_ADS2 0x3d + +typedef struct lws_display_ssd1306 { + + lws_display_t disp; /* use lws_display_ssd1306_ops to set ops */ + const lws_i2c_ops_t *i2c; /* i2c ops */ + + const lws_gpio_ops_t *gpio; /* NULL or gpio ops */ + _lws_plat_gpio_t reset_gpio; /* if gpio ops, nReset gpio # */ + + uint8_t i2c7_address; /* one of SSD1306_I2C7_ADS... */ + +} lws_display_ssd1306_t; + +int +lws_display_ssd1306_i2c_init(const struct lws_display *disp); +int +lws_display_ssd1306_i2c_contrast(const struct lws_display *disp, uint8_t b); +int +lws_display_ssd1306_i2c_blit(const struct lws_display *disp, const uint8_t *src, + lws_display_scalar x, lws_display_scalar y, + lws_display_scalar w, lws_display_scalar h); +int +lws_display_ssd1306_i2c_power(const struct lws_display *disp, int state); + +#define lws_display_ssd1306_ops \ + .init = lws_display_ssd1306_i2c_init, \ + .contrast = lws_display_ssd1306_i2c_contrast, \ + .blit = lws_display_ssd1306_i2c_blit, \ + .power = lws_display_ssd1306_i2c_power +#endif diff -Nru libwebsockets-3.2.1/include/libwebsockets/lws-state.h libwebsockets-4.1.6/include/libwebsockets/lws-state.h --- libwebsockets-3.2.1/include/libwebsockets/lws-state.h 1970-01-01 00:00:00.000000000 +0000 +++ libwebsockets-4.1.6/include/libwebsockets/lws-state.h 2020-12-01 17:40:26.000000000 +0000 @@ -0,0 +1,119 @@ + /* + * libwebsockets - small server side websockets and web server implementation + * + * Copyright (C) 2010 - 2019 Andy Green + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to + * deal in the Software without restriction, including without limitation the + * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or + * sell copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS + * IN THE SOFTWARE. + */ + +struct lws_state_notify_link; +struct lws_state_manager; + +#if defined(LWS_WITH_SYS_STATE) + +typedef int (*lws_state_notify_t)(struct lws_state_manager *mgr, + struct lws_state_notify_link *link, + int current, int target); + +typedef struct lws_state_notify_link { + lws_dll2_t list; + lws_state_notify_t notify_cb; + const char *name; +} lws_state_notify_link_t; + +typedef struct lws_state_manager { + lws_dll2_owner_t notify_list; + struct lws_context *context; + void *parent; +#if defined(LWS_WITH_SYS_SMD) + lws_smd_class_t smd_class; +#endif + /**< optional opaque pointer to owning object... useful to make such + * a pointer available to a notification callback. Ignored by lws */ + const char **state_names; + const char *name; + int state; +} lws_state_manager_t; + +/** + * lws_state_reg_notifier() - add dep handler for state notifications + * + * \param context: the lws_context + * \param nl: the handler to add to the notifier linked-list + * + * Add \p notify_link to the context's list of notification handlers for system + * state changes. The handlers can defeat or take over responsibility for + * retrying the change after they have initiated some dependency. + */ + +LWS_EXTERN LWS_VISIBLE void +lws_state_reg_notifier(lws_state_manager_t *mgr, lws_state_notify_link_t *nl); + +/** + * lws_state_reg_deregister() - deregister a notifier + * + * \param nl: notification hardler to deregister + * + * Remove a notification handler from its state manager + */ + +LWS_EXTERN LWS_VISIBLE void +lws_state_reg_deregister(lws_state_notify_link_t *nl); + +/** + * lws_state_reg_notifier_list() - add dep handlers for state notifications + * + * \param context: the lws_context + * \param nl: list of notification handlers + * + * Add a NULL-terminated list of notification handler pointers to a notification + * manager object + */ + +LWS_EXTERN LWS_VISIBLE void +lws_state_reg_notifier_list(lws_state_manager_t *mgr, + lws_state_notify_link_t * const *nl); + +/** + * lws_state_transition_steps() - move to state via starting any deps + * + * \param mgr: the state manager object + * \param target: the state we wish to move to + * + * Advance state by state towards state \p target. At each state, notifiers + * may veto the change and be triggered to perform dependencies, stopping the + * advance towards the target state. + */ +LWS_EXTERN LWS_VISIBLE int +lws_state_transition_steps(lws_state_manager_t *mgr, int target); + +/** + * lws_state_transition() - move to state via starting any deps + * + * \param mgr: the state manager object + * \param target: the state we wish to move to + * + * Jump to state target atomically. Notifiers may veto it. + */ +LWS_EXTERN LWS_VISIBLE int +lws_state_transition(lws_state_manager_t *mgr, int target); + +#else + +#endif diff -Nru libwebsockets-3.2.1/include/libwebsockets/lws-stats.h libwebsockets-4.1.6/include/libwebsockets/lws-stats.h --- libwebsockets-3.2.1/include/libwebsockets/lws-stats.h 2019-12-18 14:45:31.000000000 +0000 +++ libwebsockets-4.1.6/include/libwebsockets/lws-stats.h 2020-12-01 17:40:26.000000000 +0000 @@ -1,24 +1,25 @@ /* * libwebsockets - small server side websockets and web server implementation * - * Copyright (C) 2010-2018 Andy Green + * Copyright (C) 2010 - 2019 Andy Green * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation: - * version 2.1 of the License. + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to + * deal in the Software without restriction, including without limitation the + * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or + * sell copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: * - * This library is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. * - * You should have received a copy of the GNU Lesser General Public - * License along with this library; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, - * MA 02110-1301 USA - * - * included from libwebsockets.h + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS + * IN THE SOFTWARE. */ /* diff -Nru libwebsockets-3.2.1/include/libwebsockets/lws-struct.h libwebsockets-4.1.6/include/libwebsockets/lws-struct.h --- libwebsockets-3.2.1/include/libwebsockets/lws-struct.h 2019-12-18 14:45:31.000000000 +0000 +++ libwebsockets-4.1.6/include/libwebsockets/lws-struct.h 2020-12-01 17:40:26.000000000 +0000 @@ -1,24 +1,25 @@ /* * libwebsockets - small server side websockets and web server implementation * - * Copyright (C) 2010-2019 Andy Green + * Copyright (C) 2010 - 2020 Andy Green * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation: - * version 2.1 of the License. + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to + * deal in the Software without restriction, including without limitation the + * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or + * sell copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: * - * This library is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. * - * You should have received a copy of the GNU Lesser General Public - * License along with this library; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, - * MA 02110-1301 USA - * - * included from libwebsockets.h + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS + * IN THE SOFTWARE. */ #if defined(LWS_WITH_STRUCT_SQLITE3) @@ -34,6 +35,7 @@ LSMT_LIST, LSMT_CHILD_PTR, LSMT_SCHEMA, + LSMT_BLOB_PTR, } lws_struct_map_type_eum; @@ -69,6 +71,8 @@ size_t ac_block_size; int subtype; + int top_schema_index; + /* * temp ac used to collate unknown possibly huge strings before final * allocation and copy @@ -186,6 +190,23 @@ LSMT_SCHEMA \ } +/* + * This is just used to create the table schema, it is not part of serialization + * and deserialization. Blobs should be accessed separately. + */ + +#define LSM_BLOB_PTR(type, blobptr_name, qname) \ + { \ + qname, /* JSON item, or sqlite3 column name */ \ + NULL, \ + NULL, \ + offsetof(type, blobptr_name), /* member that points to blob */ \ + sizeof (((type *)0)->blobptr_name), /* size of blob pointer */ \ + 0, /* member holding blob len */ \ + 0, /* size of blob length member */ \ + LSMT_BLOB_PTR \ + } + typedef struct lws_struct_serialize_st { const struct lws_dll2 *dllpos; const lws_struct_map_t *map; @@ -198,7 +219,8 @@ } lws_struct_serialize_st_t; enum { - LSSERJ_FLAG_PRETTY = 1 + LSSERJ_FLAG_PRETTY = (1 << 0), + LSSERJ_FLAG_OMIT_SCHEMA = (1 << 1) }; typedef struct lws_struct_serialize { @@ -229,7 +251,8 @@ LWS_VISIBLE LWS_EXTERN lws_struct_serialize_t * lws_struct_json_serialize_create(const lws_struct_map_t *map, - size_t map_entries, int flags, void *ptoplevel); + size_t map_entries, int flags, + const void *ptoplevel); LWS_VISIBLE LWS_EXTERN void lws_struct_json_serialize_destroy(lws_struct_serialize_t **pjs); @@ -238,21 +261,24 @@ lws_struct_json_serialize(lws_struct_serialize_t *js, uint8_t *buf, size_t len, size_t *written); -#if defined(LWS_WITH_STRUCT_SQLITE3) +typedef struct sqlite3 sqlite3; LWS_VISIBLE LWS_EXTERN int -lws_struct_sq3_deserialize(sqlite3 *pdb, const lws_struct_map_t *schema, - lws_dll2_owner_t *o, struct lwsac **ac, - uint64_t start, int limit); +lws_struct_sq3_serialize(sqlite3 *pdb, const lws_struct_map_t *schema, + lws_dll2_owner_t *owner, uint32_t manual_idx); + +LWS_VISIBLE LWS_EXTERN int +lws_struct_sq3_deserialize(sqlite3 *pdb, const char *filter, const char *order, + const lws_struct_map_t *schema, lws_dll2_owner_t *o, + struct lwsac **ac, int start, int limit); LWS_VISIBLE LWS_EXTERN int lws_struct_sq3_create_table(sqlite3 *pdb, const lws_struct_map_t *schema); LWS_VISIBLE LWS_EXTERN int lws_struct_sq3_open(struct lws_context *context, const char *sqlite3_path, - sqlite3 **pdb); + char create_if_missing, sqlite3 **pdb); LWS_VISIBLE LWS_EXTERN int lws_struct_sq3_close(sqlite3 **pdb); -#endif diff -Nru libwebsockets-3.2.1/include/libwebsockets/lws-system.h libwebsockets-4.1.6/include/libwebsockets/lws-system.h --- libwebsockets-3.2.1/include/libwebsockets/lws-system.h 2019-12-18 14:45:31.000000000 +0000 +++ libwebsockets-4.1.6/include/libwebsockets/lws-system.h 2020-12-01 17:40:26.000000000 +0000 @@ -1,84 +1,336 @@ -/* + /* * libwebsockets - small server side websockets and web server implementation * - * Copyright (C) 2010-2019 Andy Green - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation: - * version 2.1 of the License. - * - * This library is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with this library; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, - * MA 02110-1301 USA + * Copyright (C) 2010 - 2020 Andy Green * - * included from libwebsockets.h + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to + * deal in the Software without restriction, including without limitation the + * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or + * sell copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS + * IN THE SOFTWARE. * * This provides a clean way to interface lws user code to be able to * work unchanged on different systems for fetching common system information, * and performing common system operations like reboot. + */ + +/* + * Types of system blob that can be set and retreived + */ + +typedef enum { + LWS_SYSBLOB_TYPE_AUTH, + LWS_SYSBLOB_TYPE_CLIENT_CERT_DER = LWS_SYSBLOB_TYPE_AUTH + 2, + LWS_SYSBLOB_TYPE_CLIENT_KEY_DER, + LWS_SYSBLOB_TYPE_DEVICE_SERIAL, + LWS_SYSBLOB_TYPE_DEVICE_FW_VERSION, + LWS_SYSBLOB_TYPE_DEVICE_TYPE, + LWS_SYSBLOB_TYPE_NTP_SERVER, + + LWS_SYSBLOB_TYPE_COUNT /* ... always last */ +} lws_system_blob_item_t; + +/* opaque generic blob whose content may be on-the-heap or pointed-to + * directly case by case. When it's on the heap, it can be produced by + * appending (it's a buflist underneath). Either way, it can be consumed by + * copying out a given length from a given offset. + */ + +typedef struct lws_system_blob lws_system_blob_t; + +LWS_EXTERN LWS_VISIBLE void +lws_system_blob_direct_set(lws_system_blob_t *b, const uint8_t *ptr, size_t len); + +LWS_EXTERN LWS_VISIBLE void +lws_system_blob_heap_empty(lws_system_blob_t *b); + +LWS_EXTERN LWS_VISIBLE int +lws_system_blob_heap_append(lws_system_blob_t *b, const uint8_t *ptr, size_t len); + +LWS_EXTERN LWS_VISIBLE size_t +lws_system_blob_get_size(lws_system_blob_t *b); + +/* return 0 and sets *ptr to point to blob data if possible, nonzero = fail */ +LWS_EXTERN LWS_VISIBLE int +lws_system_blob_get_single_ptr(lws_system_blob_t *b, const uint8_t **ptr); + +LWS_EXTERN LWS_VISIBLE int +lws_system_blob_get(lws_system_blob_t *b, uint8_t *ptr, size_t *len, size_t ofs); + +LWS_EXTERN LWS_VISIBLE void +lws_system_blob_destroy(lws_system_blob_t *b); + +/* + * Get the opaque blob for index idx of various system blobs. Returns 0 if + * *b was set otherwise nonzero means out of range + */ + +LWS_EXTERN LWS_VISIBLE lws_system_blob_t * +lws_system_get_blob(struct lws_context *context, lws_system_blob_item_t type, + int idx); + +/* + * Lws view of system state... normal operation from user code perspective is + * dependent on implicit (eg, knowing the date for cert validation) and + * explicit dependencies. * - * An ops struct with the system-specific implementations is set at - * context creation time, and apis are provided that call through to - * those where they exist. + * Bit of lws and user code can register notification handlers that can enforce + * dependent operations before state transitions can complete. */ +typedef enum { /* keep system_state_names[] in sync in context.c */ + LWS_SYSTATE_UNKNOWN, + + LWS_SYSTATE_CONTEXT_CREATED, /* context was just created */ + LWS_SYSTATE_INITIALIZED, /* protocols initialized. Lws itself + * can operate normally */ + LWS_SYSTATE_IFACE_COLDPLUG, /* existing net ifaces iterated */ + LWS_SYSTATE_DHCP, /* at least one net iface configured */ + LWS_SYSTATE_CPD_PRE_TIME, /* Captive portal detect without valid + * time, good for non-https tests... if + * you care about it, implement and + * call lws_system_ops_t + * .captive_portal_detect_request() + * and move the state forward according + * to the result. */ + LWS_SYSTATE_TIME_VALID, /* ntpclient ran, or hw time valid... + * tls cannot work until we reach here + */ + LWS_SYSTATE_CPD_POST_TIME, /* Captive portal detect after time was + * time, good for https tests... if + * you care about it, implement and + * call lws_system_ops_t + * .captive_portal_detect_request() + * and move the state forward according + * to the result. */ + + LWS_SYSTATE_POLICY_VALID, /* user code knows how to operate... */ + LWS_SYSTATE_REGISTERED, /* device has an identity... */ + LWS_SYSTATE_AUTH1, /* identity used for main auth token */ + LWS_SYSTATE_AUTH2, /* identity used for optional auth */ + + LWS_SYSTATE_OPERATIONAL, /* user code can operate normally */ + + LWS_SYSTATE_POLICY_INVALID, /* user code is changing its policies + * drop everything done with old + * policy, switch to new then enter + * LWS_SYSTATE_POLICY_VALID */ +} lws_system_states_t; + +/* Captive Portal Detect -related */ + typedef enum { - LWS_SYSI_HRS_DEVICE_MODEL = 1, - LWS_SYSI_HRS_DEVICE_SERIAL, - LWS_SYSI_HRS_FIRMWARE_VERSION, - - LWS_SYSI_USER_BASE = 100 -} lws_system_item_t; - -typedef union { - const char *hrs; /* human readable string */ - void *data; - time_t t; -} lws_system_arg_t; + LWS_CPD_UNKNOWN = 0, /* test didn't happen ince last DHCP acq yet */ + LWS_CPD_INTERNET_OK, /* no captive portal: our CPD test passed OK, + * we can go out on the internet */ + LWS_CPD_CAPTIVE_PORTAL, /* we inferred we're behind a captive portal */ + LWS_CPD_NO_INTERNET, /* we couldn't touch anything */ +} lws_cpd_result_t; + + +typedef void (*lws_attach_cb_t)(struct lws_context *context, int tsi, void *opaque); +struct lws_attach_item; typedef struct lws_system_ops { - int (*get_info)(lws_system_item_t i, lws_system_arg_t arg, size_t *len); int (*reboot)(void); + int (*set_clock)(lws_usec_t us); + int (*attach)(struct lws_context *context, int tsi, lws_attach_cb_t cb, + lws_system_states_t state, void *opaque, + struct lws_attach_item **get); + /**< if \p get is NULL, add an attach callback request to the pt for + * \p cb with arg \p opaque, that should be called when we're at or past + * system state \p state. + * + * If \p get is non-NULL, look for the first listed item on the pt whose + * state situation is ready, and set *get to point to it. If no items, + * or none where the system state is right, set *get to NULL. + * + * It's done like this so (*attach) can perform system-specific + * locking outside of lws core, for both getting and adding items the + * same so it is thread-safe. A non-threadsafe helper + * __lws_system_attach() is provided to do the actual work inside the + * system-specific locking. + */ + int (*captive_portal_detect_request)(struct lws_context *context); + /**< Check if we can go out on the internet cleanly, or if we are being + * redirected or intercepted by a captive portal. + * Start the check that proceeds asynchronously, and report the results + * by calling lws_captive_portal_detect_result() api + */ + + uint32_t wake_latency_us; + /**< time taken for this device to wake from suspend, in us + */ } lws_system_ops_t; +#if defined(LWS_WITH_SYS_STATE) + +/** + * lws_system_get_state_manager() - return the state mgr object for system state + * + * \param context: the lws_context + * + * The returned pointer can be used with the lws_state_ apis + */ + +LWS_EXTERN LWS_VISIBLE lws_state_manager_t * +lws_system_get_state_manager(struct lws_context *context); + +#endif + /* wrappers handle NULL members or no ops struct set at all cleanly */ +#define LWSSYSGAUTH_HEX (1 << 0) + /** - * lws_system_get_info() - get standardized system information + * lws_system_get_ops() - get ahold of the system ops struct from the context * * \param context: the lws_context - * \param item: which information to fetch - * \param arg: where to place the result - * \param len: incoming: max length of result, outgoing: used length of result * - * This queries a standardized information-fetching ops struct that can be - * applied to the context... the advantage is it allows you to get common items - * of information like a device serial number writing the code once, even if the - * actual serial number muse be fetched in wildly different ways depending on - * the exact platform it's running on. + * Returns the system ops struct. It may return NULL and if not, anything in + * there may be NULL. + */ +LWS_EXTERN LWS_VISIBLE const lws_system_ops_t * +lws_system_get_ops(struct lws_context *context); + +#if defined(LWS_WITH_SYS_STATE) + +/** + * lws_system_context_from_system_mgr() - return context from system state mgr + * + * \param mgr: pointer to specifically the system state mgr + * + * Returns the context from the system state mgr. Helper since the lws_context + * is opaque. + */ +LWS_EXTERN LWS_VISIBLE struct lws_context * +lws_system_context_from_system_mgr(lws_state_manager_t *mgr); + +#endif + +/** + * __lws_system_attach() - get and set items on context attach list + * + * \param context: context to get or set attach items to + * \param tsi: thread service index (normally 0) + * \param cb: callback to call from context event loop thread + * \param state: the lws_system state we have to be in or have passed through + * \param opaque: optional pointer to user specific info given to callback + * \param get: NULL, or pointer to pointer to take detached tail item on exit + * + * This allows other threads to enqueue callback requests to happen from a pt's + * event loop thread safely. The callback gets the context pointer and a user + * opaque pointer that can be optionally given when the item is added to the + * attach list. + * + * This api is the no-locking core function for getting and setting items on the + * pt's attach list. The lws_system operation (*attach) is the actual + * api that user and internal code calls for this feature, it should perform + * system-specific locking, call this helper, release the locking and then + * return the result. This api is public only so it can be used in the locked + * implementation of (*attach). + * + * If get is NULL, then the call adds to the head of the pt attach list using + * cb, state, and opaque; if get is non-NULL, then *get is set to the first + * waiting attached item that meets the state criteria and that item is removed + * from the list. + * + * This is a non-threadsafe helper only designed to be called from + * implementations of struct lws_system's (*attach) operation where system- + * specific locking has been applied around it, making it threadsafe. + */ +LWS_EXTERN LWS_VISIBLE int +__lws_system_attach(struct lws_context *context, int tsi, lws_attach_cb_t cb, + lws_system_states_t state, void *opaque, + struct lws_attach_item **get); + + +typedef int (*dhcpc_cb_t)(void *opaque, int af, uint8_t *ip, int ip_len); + +/** + * lws_dhcpc_request() - add a network interface to dhcpc management + * + * \param c: the lws_context + * \param i: the interface name, like "eth0" + * \param af: address family + * \param cb: the change callback + * \param opaque: opaque pointer given to the callback + * + * Register a network interface as being managed by DHCP. lws will proceed to + * try to acquire an IP. Requires LWS_WITH_SYS_DHCP_CLIENT at cmake. + */ +LWS_EXTERN LWS_VISIBLE int +lws_dhcpc_request(struct lws_context *c, const char *i, int af, dhcpc_cb_t cb, + void *opaque); + +/** + * lws_dhcpc_remove() - remove a network interface to dhcpc management + * + * \param context: the lws_context + * \param iface: the interface name, like "eth0" * - * Set arg and *len on entry to be the result location and the max length that - * can be used there, on seccessful exit *len is set to the actual length and - * 0 is returned. On error, 1 is returned. + * Remove handling of the network interface from dhcp. */ LWS_EXTERN LWS_VISIBLE int -lws_system_get_info(struct lws_context *context, lws_system_item_t item, - lws_system_arg_t arg, size_t *len); +lws_dhcpc_remove(struct lws_context *context, const char *iface); +/** + * lws_dhcpc_status() - has any interface reached BOUND state + * + * \param context: the lws_context + * \param sa46: set to a DNS server from a bound interface, or NULL + * + * Returns 1 if any network interface managed by dhcpc has reached the BOUND + * state (has acquired an IP, gateway and DNS server), otherwise 0. + */ +LWS_EXTERN LWS_VISIBLE int +lws_dhcpc_status(struct lws_context *context, lws_sockaddr46 *sa46); /** - * lws_system_reboot() - if provided, use the lws_system ops to reboot + * lws_system_cpd_start() - helper to initiate captive portal detection * * \param context: the lws_context * - * If possible, the system will reboot. Otherwise returns 1. + * Resets the context's captive portal state to LWS_CPD_UNKNOWN and calls the + * lws_system_ops_t captive_portal_detect_request() implementation to begin + * testing the captive portal state. */ LWS_EXTERN LWS_VISIBLE int -lws_system_reboot(struct lws_context *context); +lws_system_cpd_start(struct lws_context *context); + + +/** + * lws_system_cpd_set() - report the result of the captive portal detection + * + * \param context: the lws_context + * \param result: one of the LWS_CPD_ constants representing captive portal state + * + * Sets the context's captive portal detection state to result. User captive + * portal detection code would call this once it had a result from its test. + */ +LWS_EXTERN LWS_VISIBLE void +lws_system_cpd_set(struct lws_context *context, lws_cpd_result_t result); + + +/** + * lws_system_cpd_state_get() - returns the last tested captive portal state + * + * \param context: the lws_context + * + * Returns one of the LWS_CPD_ constants indicating the system's understanding + * of the current captive portal situation. + */ +LWS_EXTERN LWS_VISIBLE lws_cpd_result_t +lws_system_cpd_state_get(struct lws_context *context); diff -Nru libwebsockets-3.2.1/include/libwebsockets/lws-test-sequencer.h libwebsockets-4.1.6/include/libwebsockets/lws-test-sequencer.h --- libwebsockets-3.2.1/include/libwebsockets/lws-test-sequencer.h 2019-12-18 14:45:31.000000000 +0000 +++ libwebsockets-4.1.6/include/libwebsockets/lws-test-sequencer.h 2020-12-01 17:40:26.000000000 +0000 @@ -1,24 +1,25 @@ -/* + /* * libwebsockets - small server side websockets and web server implementation * - * Copyright (C) 2010-2019 Andy Green + * Copyright (C) 2010 - 2019 Andy Green * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation: - * version 2.1 of the License. - * - * This library is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with this library; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, - * MA 02110-1301 USA - * - * included from libwebsockets.h + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to + * deal in the Software without restriction, including without limitation the + * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or + * sell copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS + * IN THE SOFTWARE. * * lws_test_sequencer manages running an array of unit tests. */ diff -Nru libwebsockets-3.2.1/include/libwebsockets/lws-threadpool.h libwebsockets-4.1.6/include/libwebsockets/lws-threadpool.h --- libwebsockets-3.2.1/include/libwebsockets/lws-threadpool.h 2019-12-18 14:45:31.000000000 +0000 +++ libwebsockets-4.1.6/include/libwebsockets/lws-threadpool.h 2020-12-01 17:40:26.000000000 +0000 @@ -1,24 +1,25 @@ /* * libwebsockets - small server side websockets and web server implementation * - * Copyright (C) 2010-2018 Andy Green + * Copyright (C) 2010 - 2020 Andy Green * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation: - * version 2.1 of the License. - * - * This library is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with this library; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, - * MA 02110-1301 USA - * - * included from libwebsockets.h + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to + * deal in the Software without restriction, including without limitation the + * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or + * sell copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS + * IN THE SOFTWARE. */ /** \defgroup threadpool Threadpool related functions @@ -70,7 +71,11 @@ }; struct lws_threadpool_task_args { - struct lws *wsi; /**< user must set to wsi task is bound to */ +#if defined(LWS_WITH_SECURE_STREAMS) + struct lws_ss_handle *ss; /**< either wsi or ss must be set */ +#endif + struct lws *wsi; /**< either wsi or ss must be set */ + void *user; /**< user may set (user-private pointer) */ const char *name; /**< user may set to describe task */ char async_task; /**< set to allow the task to shrug off the loss @@ -172,12 +177,21 @@ * This doesn't free the task. It only shortcuts it to state * LWS_TP_STATUS_STOPPED. lws_threadpool_task_status() must be performed on * the task separately once it is in LWS_TP_STATUS_STOPPED to free the task. + * + * DEPRECATED: You should use lws_threadpool_dequeue_task() with + * lws_threadpool_get_task_wsi() / _ss() if you know there can only be one task + * per connection, or call it via lws_threadpool_foreach_task_wsi() / _ss() to + * get the tasks bound to the connection. */ LWS_VISIBLE LWS_EXTERN int -lws_threadpool_dequeue(struct lws *wsi); +lws_threadpool_dequeue(struct lws *wsi) LWS_WARN_DEPRECATED; + +LWS_VISIBLE LWS_EXTERN int +lws_threadpool_dequeue_task(struct lws_threadpool_task *task); + /** - * lws_threadpool_task_status() - Dequeue or try to stop a running task + * lws_threadpool_task_status() - reap completed tasks * * \param wsi: the wsi to query the current task of * \param task: receives a pointer to the opaque task @@ -192,10 +206,21 @@ * * Its use is to make sure the service thread has seen the state of the task * before deleting it. + * + * DEPRECATED... use lws_threadpool_task_status() instead and get the task + * pointer from lws_threadpool_get_task_wsi() / _ss() if you know there can only + * be one, else call it via lws_threadpool_foreach_task_wsi() / _ss() */ LWS_VISIBLE LWS_EXTERN enum lws_threadpool_task_status lws_threadpool_task_status_wsi(struct lws *wsi, - struct lws_threadpool_task **task, void **user); + struct lws_threadpool_task **task, void **user) + LWS_WARN_DEPRECATED; + +LWS_VISIBLE LWS_EXTERN enum lws_threadpool_task_status +lws_threadpool_task_status(struct lws_threadpool_task *task, void **user); + +LWS_VISIBLE LWS_EXTERN enum lws_threadpool_task_status +lws_threadpool_task_status_noreap(struct lws_threadpool_task *task); /** * lws_threadpool_task_sync() - Indicate to a stalled task it may continue @@ -228,4 +253,28 @@ LWS_VISIBLE LWS_EXTERN void lws_threadpool_dump(struct lws_threadpool *tp); + + + +LWS_VISIBLE LWS_EXTERN struct lws_threadpool_task * +lws_threadpool_get_task_wsi(struct lws *wsi); + +#if defined(LWS_WITH_SECURE_STREAMS) +LWS_VISIBLE LWS_EXTERN struct lws_threadpool_task * +lws_threadpool_get_task_ss(struct lws_ss_handle *ss); +#endif + + +LWS_VISIBLE LWS_EXTERN int +lws_threadpool_foreach_task_wsi(struct lws *wsi, void *user, + int (*cb)(struct lws_threadpool_task *task, + void *user)); + +#if defined(LWS_WITH_SECURE_STREAMS) +LWS_VISIBLE LWS_EXTERN int +lws_threadpool_foreach_task_ss(struct lws_ss_handle *ss, void *user, + int (*cb)(struct lws_threadpool_task *task, void *user)); +#endif + + //@} diff -Nru libwebsockets-3.2.1/include/libwebsockets/lws-timeout-timer.h libwebsockets-4.1.6/include/libwebsockets/lws-timeout-timer.h --- libwebsockets-3.2.1/include/libwebsockets/lws-timeout-timer.h 2019-12-18 14:45:31.000000000 +0000 +++ libwebsockets-4.1.6/include/libwebsockets/lws-timeout-timer.h 2020-12-01 17:40:26.000000000 +0000 @@ -1,24 +1,25 @@ /* * libwebsockets - small server side websockets and web server implementation * - * Copyright (C) 2010-2018 Andy Green + * Copyright (C) 2010 - 2019 Andy Green * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation: - * version 2.1 of the License. - * - * This library is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with this library; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, - * MA 02110-1301 USA - * - * included from libwebsockets.h + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to + * deal in the Software without restriction, including without limitation the + * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or + * sell copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS + * IN THE SOFTWARE. */ /*! \defgroup timeout Connection timeouts @@ -112,6 +113,10 @@ void lws_set_timeout_us(struct lws *wsi, enum pending_timeout reason, lws_usec_t us); +/* helper for clearer LWS_TO_KILL_ASYNC / LWS_TO_KILL_SYNC usage */ +#define lws_wsi_close(w, to_kill) lws_set_timeout(wsi, 1, to_kill) + + #define LWS_SET_TIMER_USEC_CANCEL ((lws_usec_t)-1ll) #define LWS_USEC_PER_SEC ((lws_usec_t)1000000) @@ -145,6 +150,8 @@ LWS_VISIBLE LWS_EXTERN void lws_set_timer_usecs(struct lws *wsi, lws_usec_t usecs); +#if defined(LWS_WITH_DEPRECATED_THINGS) + /* * lws_timed_callback_vh_protocol() - calls back a protocol on a vhost after * the specified delay in seconds @@ -154,6 +161,8 @@ * \param reason: callback reason * \param secs: how many seconds in the future to do the callback. * + * DEPRECATED since v4.1 + * * Callback the specified protocol with a fake wsi pointing to the specified * vhost and protocol, with the specified reason, at the specified time in the * future. @@ -167,7 +176,8 @@ LWS_VISIBLE LWS_EXTERN int lws_timed_callback_vh_protocol(struct lws_vhost *vh, const struct lws_protocols *prot, - int reason, int secs); + int reason, int secs) +LWS_WARN_DEPRECATED; /* * lws_timed_callback_vh_protocol_us() - calls back a protocol on a vhost after @@ -178,6 +188,8 @@ * \param reason: callback reason * \param us: how many us in the future to do the callback. * + * DEPRECATED since v4.1 + * * Callback the specified protocol with a fake wsi pointing to the specified * vhost and protocol, with the specified reason, at the specified time in the * future. @@ -191,40 +203,160 @@ LWS_VISIBLE LWS_EXTERN int lws_timed_callback_vh_protocol_us(struct lws_vhost *vh, const struct lws_protocols *prot, int reason, - lws_usec_t us); + lws_usec_t us) +LWS_WARN_DEPRECATED; + +#endif +struct lws_sorted_usec_list; -typedef void (*sul_cb_t)(lws_sorted_usec_list_t *sul); +typedef void (*sul_cb_t)(struct lws_sorted_usec_list *sul); -struct lws_sorted_usec_list { +typedef struct lws_sorted_usec_list { struct lws_dll2 list; /* simplify the code by keeping this at start */ - sul_cb_t cb; lws_usec_t us; -}; + sul_cb_t cb; + uint32_t latency_us; /* us it may safely be delayed */ +} lws_sorted_usec_list_t; + +/* + * There are multiple sul owners to allow accounting for, a) events that must + * wake from suspend, and b) events that can be missued due to suspend + */ +#define LWS_COUNT_PT_SUL_OWNERS 2 +#define LWSSULLI_MISS_IF_SUSPENDED 0 +#define LWSSULLI_WAKE_IF_SUSPENDED 1 /* - * lws_sul_schedule() - schedule a callback + * lws_sul2_schedule() - schedule a callback * * \param context: the lws_context * \param tsi: the thread service index (usually 0) + * \param flags: LWSSULLI_... * \param sul: pointer to the sul element - * \param cb: the scheduled callback - * \param us: the delay before the callback arrives, or - * LWS_SET_TIMER_USEC_CANCEL to cancel it. * * Generic callback-at-a-later time function. The callback happens on the * event loop thread context. * * Although the api has us resultion, the actual resolution depends on the - * platform and is commonly 1ms. + * platform and may be, eg, 1ms. * * This doesn't allocate and doesn't fail. * - * You can call it again with another us value to change the delay. + * If flags contains LWSSULLI_WAKE_IF_SUSPENDED, the scheduled event is placed + * on a sul owner list that, if the system has entered low power suspend mode, + * tries to arrange that the system should wake from platform suspend just + * before the event is due. Scheduled events without this flag will be missed + * in the case the system is in suspend and nothing else happens to have woken + * it. + * + * You can call it again with another us value to change the delay or move the + * event to a different owner (ie, wake or miss on suspend). */ LWS_VISIBLE LWS_EXTERN void -lws_sul_schedule(struct lws_context *context, int tsi, - lws_sorted_usec_list_t *sul, sul_cb_t cb, lws_usec_t us); +lws_sul2_schedule(struct lws_context *context, int tsi, int flags, + lws_sorted_usec_list_t *sul); + +/* + * lws_sul_cancel() - cancel scheduled callback + * + * \param sul: pointer to the sul element + * + * If it's scheduled, remove the sul from its owning sorted list. + * If not scheduled, it's a NOP. + */ +LWS_VISIBLE LWS_EXTERN void +lws_sul_cancel(lws_sorted_usec_list_t *sul); + +/* + * lws_sul_earliest_wakeable_event() - get earliest wake-from-suspend event + * + * \param ctx: the lws context + * \param pearliest: pointer to lws_usec_t to take the result + * + * Either returns 1 if no pending event, or 0 and sets *pearliest to the + * MONOTONIC time of the current earliest next expected event. + */ +LWS_VISIBLE LWS_EXTERN int +lws_sul_earliest_wakeable_event(struct lws_context *ctx, lws_usec_t *pearliest); + +/* + * For backwards compatibility + * + * If us is LWS_SET_TIMER_USEC_CANCEL, the sul is removed from the scheduler. + * New code can use lws_sul_cancel() + */ + +LWS_VISIBLE LWS_EXTERN void +lws_sul_schedule(struct lws_context *ctx, int tsi, lws_sorted_usec_list_t *sul, + sul_cb_t _cb, lws_usec_t _us); +LWS_VISIBLE LWS_EXTERN void +lws_sul_schedule_wakesuspend(struct lws_context *ctx, int tsi, + lws_sorted_usec_list_t *sul, sul_cb_t _cb, + lws_usec_t _us); + +#if defined(LWS_WITH_SUL_DEBUGGING) +/** + * lws_sul_debug_zombies() - assert there are no scheduled sul in a given object + * + * \param ctx: lws_context + * \param po: pointer to the object that is about to be destroyed + * \param len: length of the object that is about to be destroyed + * \param destroy_description: string clue what any failure is related to + * + * This is an optional debugging helper that walks the sul scheduler lists + * confirming that there are no suls scheduled that live inside the object + * footprint described by po and len. When internal objects are about to be + * destroyed, like wsi / user_data or secure stream handles, if + * LWS_WITH_SUL_DEBUGGING is enabled the scheduler is checked for anything + * in the object being destroyed. If something found, an error is printed and + * an assert fired. + * + * Internal sul like timeouts should always be cleaned up correctly, but user + * suls in, eg, wsi user_data area, or in secure stream user allocation, may be + * the cause of difficult to find bugs if valgrind not available and the user + * code left a sul in the scheduler after destroying the object the sul was + * living in. + */ +LWS_VISIBLE LWS_EXTERN void +lws_sul_debug_zombies(struct lws_context *ctx, void *po, size_t len, + const char *destroy_description); +#else +#define lws_sul_debug_zombies(_a, _b, _c, _d) +#endif + +/* + * lws_validity_confirmed() - reset the validity timer for a network connection + * + * \param wsi: the connection that saw traffic proving the connection valid + * + * Network connections are subject to intervals defined by the context, the + * vhost if server connections, or the client connect info if a client + * connection. If the connection goes longer than the specified time since + * last observing traffic that can only happen if traffic is passing in both + * directions, then lws will try to create a PING transaction on the network + * connection. + * + * If the connection reaches the specified `.secs_since_valid_hangup` time + * still without any proof of validity, the connection will be closed. + * + * If the PONG comes, or user code observes traffic that satisfies the proof + * that both directions are passing traffic to the peer and calls this api, + * the connection validity timer is reset and the scheme repeats. + */ +LWS_VISIBLE LWS_EXTERN void +lws_validity_confirmed(struct lws *wsi); + +/* + * These are not normally needed, they're exported for the case there's code + * using lws_sul for which lws is an optional link dependency. + */ + +LWS_VISIBLE LWS_EXTERN int +__lws_sul_insert(lws_dll2_owner_t *own, lws_sorted_usec_list_t *sul); + +LWS_VISIBLE LWS_EXTERN lws_usec_t +__lws_sul_service_ripe(lws_dll2_owner_t *own, int own_len, lws_usec_t usnow); ///@} diff -Nru libwebsockets-3.2.1/include/libwebsockets/lws-tokenize.h libwebsockets-4.1.6/include/libwebsockets/lws-tokenize.h --- libwebsockets-3.2.1/include/libwebsockets/lws-tokenize.h 2019-12-18 14:45:31.000000000 +0000 +++ libwebsockets-4.1.6/include/libwebsockets/lws-tokenize.h 2020-12-01 17:40:26.000000000 +0000 @@ -1,24 +1,25 @@ /* * libwebsockets - small server side websockets and web server implementation * - * Copyright (C) 2010-2018 Andy Green + * Copyright (C) 2010 - 2019 Andy Green * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation: - * version 2.1 of the License. - * - * This library is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with this library; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, - * MA 02110-1301 USA - * - * included from libwebsockets.h + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to + * deal in the Software without restriction, including without limitation the + * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or + * sell copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS + * IN THE SOFTWARE. */ /* Do not treat - as a terminal character, so "my-token" is one token */ @@ -38,6 +39,10 @@ #define LWS_TOKENIZE_F_NO_FLOATS (1 << 5) /* Instead of LWS_TOKZE_INTEGER, report integers as any other string token */ #define LWS_TOKENIZE_F_NO_INTEGERS (1 << 6) +/* # makes the rest of the line a comment */ +#define LWS_TOKENIZE_F_HASH_COMMENT (1 << 7) +/* Do not treat / as a terminal character, so "multipart/related" is one token */ +#define LWS_TOKENIZE_F_SLASH_NONTERM (1 << 8) typedef enum { @@ -75,15 +80,17 @@ LWSTZ_DT_NEED_NEXT_CONTENT, }; -struct lws_tokenize { +typedef struct lws_tokenize { const char *start; /**< set to the start of the string to tokenize */ const char *token; /**< the start of an identified token or delimiter */ - int len; /**< set to the length of the string to tokenize */ - int token_len; /**< the length of the identied token or delimiter */ + size_t len; /**< set to the length of the string to tokenize */ + size_t token_len; /**< the length of the identied token or delimiter */ - int flags; /**< optional LWS_TOKENIZE_F_ flags, or 0 */ - int delim; -}; + uint16_t flags; /**< optional LWS_TOKENIZE_F_ flags, or 0 */ + uint8_t delim; + + int8_t e; /**< convenient for storing lws_tokenize return */ +} lws_tokenize_t; /** * lws_tokenize() - breaks down a string into tokens and delimiters in-place @@ -135,4 +142,112 @@ */ LWS_VISIBLE LWS_EXTERN int -lws_tokenize_cstr(struct lws_tokenize *ts, char *str, int max); +lws_tokenize_cstr(struct lws_tokenize *ts, char *str, size_t max); + + +/* + * lws_strexp: flexible string expansion helper api + * + * This stateful helper can handle multiple separate input chunks and multiple + * output buffer loads with arbitrary boundaries between literals and expanded + * symbols. This allows it to handle fragmented input as well as arbitrarily + * long symbol expansions that are bigger than the output buffer itself. + * + * A user callback is used to convert symbol names to the symbol value. + * + * A single byte buffer for input and another for output can process any + * length substitution then. The state object is around 64 bytes on a 64-bit + * system and it only uses 8 bytes stack. + */ + + +typedef int (*lws_strexp_expand_cb)(void *priv, const char *name, char *out, + size_t *pos, size_t olen, size_t *exp_ofs); + +typedef struct lws_strexp { + char name[32]; + lws_strexp_expand_cb cb; + void *priv; + char *out; + size_t olen; + size_t pos; + + size_t exp_ofs; + + uint8_t name_pos; + char state; +} lws_strexp_t; + +enum { + LSTRX_DONE, /* it completed OK */ + LSTRX_FILLED_OUT, /* out buf filled and needs resetting */ + LSTRX_FATAL_NAME_TOO_LONG = -1, /* fatal */ + LSTRX_FATAL_NAME_UNKNOWN = -2, +}; + + +/** + * lws_strexp_init() - initialize an lws_strexp_t for use + * + * \p exp: the exp object to init + * \p priv: the user's object pointer to pass to callback + * \p cb: the callback to expand named objects + * \p out: the start of the output buffer, or NULL just to get the length + * \p olen: the length of the output buffer in bytes + * + * Prepares an lws_strexp_t for use and sets the initial output buffer + * + * If \p out is NULL, substitution proceeds normally, but no output is produced, + * only the length is returned. olen should be set to the largest feasible + * overall length. To use this mode, the substitution callback must also check + * for NULL \p out and avoid producing the output. + */ +LWS_VISIBLE LWS_EXTERN void +lws_strexp_init(lws_strexp_t *exp, void *priv, lws_strexp_expand_cb cb, + char *out, size_t olen); + +/** + * lws_strexp_reset_out() - reset the output buffer on an existing strexp + * + * \p exp: the exp object to init + * \p out: the start of the output buffer, or NULL to just get length + * \p olen: the length of the output buffer in bytes + * + * Provides a new output buffer for lws_strexp_expand() to continue to write + * into. It can be the same as the old one if it has been copied out or used. + * The position of the next write will be reset to the start of the given buf. + * + * If \p out is NULL, substitution proceeds normally, but no output is produced, + * only the length is returned. \p olen should be set to the largest feasible + * overall length. To use this mode, the substitution callback must also check + * for NULL \p out and avoid producing the output. + */ +LWS_VISIBLE LWS_EXTERN void +lws_strexp_reset_out(lws_strexp_t *exp, char *out, size_t olen); + +/** + * lws_strexp_expand() - copy / expand a string into the output buffer + * + * \p exp: the exp object for the copy / expansion + * \p in: the start of the next input data + * \p len: the length of the input data + * \p pused_in: pointer to write the amount of input used + * \p pused_out: pointer to write the amount of output used + * + * Copies in to the output buffer set in exp, expanding any ${name} tokens using + * the callback. \p *pused_in is set to the number of input chars used and + * \p *pused_out the number of output characters used + * + * May return LSTRX_FILLED_OUT early with *pused < len if the output buffer is + * filled. Handle the output buffer and reset it with lws_strexp_reset_out() + * before calling again with adjusted in / len to continue. + * + * In the case of large expansions, the expansion itself may fill the output + * buffer, in which case the expansion callback returns the LSTRX_FILLED_OUT + * and will be called again to continue with its *exp_ofs parameter set + * appropriately. + */ +LWS_VISIBLE LWS_EXTERN int +lws_strexp_expand(lws_strexp_t *exp, const char *in, size_t len, + size_t *pused_in, size_t *pused_out); + diff -Nru libwebsockets-3.2.1/include/libwebsockets/lws-vfs.h libwebsockets-4.1.6/include/libwebsockets/lws-vfs.h --- libwebsockets-3.2.1/include/libwebsockets/lws-vfs.h 2019-12-18 14:45:31.000000000 +0000 +++ libwebsockets-4.1.6/include/libwebsockets/lws-vfs.h 2020-12-01 17:40:26.000000000 +0000 @@ -1,24 +1,25 @@ /* * libwebsockets - small server side websockets and web server implementation * - * Copyright (C) 2010-2018 Andy Green + * Copyright (C) 2010 - 2019 Andy Green * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation: - * version 2.1 of the License. - * - * This library is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with this library; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, - * MA 02110-1301 USA - * - * included from libwebsockets.h + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to + * deal in the Software without restriction, including without limitation the + * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or + * sell copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS + * IN THE SOFTWARE. */ /*! \defgroup fops file operation wrapping @@ -44,7 +45,7 @@ * library and in the user code. */ -#if defined(LWS_WITH_ESP32) +#if defined(LWS_PLAT_FREERTOS) /* sdk preprocessor defs? compiler issue? gets confused with member names */ #define LWS_FOP_OPEN _open #define LWS_FOP_CLOSE _close diff -Nru libwebsockets-3.2.1/include/libwebsockets/lws-writeable.h libwebsockets-4.1.6/include/libwebsockets/lws-writeable.h --- libwebsockets-3.2.1/include/libwebsockets/lws-writeable.h 2019-12-18 14:45:31.000000000 +0000 +++ libwebsockets-4.1.6/include/libwebsockets/lws-writeable.h 2020-12-01 17:40:26.000000000 +0000 @@ -1,24 +1,25 @@ /* * libwebsockets - small server side websockets and web server implementation * - * Copyright (C) 2010-2018 Andy Green + * Copyright (C) 2010 - 2019 Andy Green * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation: - * version 2.1 of the License. - * - * This library is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with this library; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, - * MA 02110-1301 USA - * - * included from libwebsockets.h + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to + * deal in the Software without restriction, including without limitation the + * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or + * sell copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS + * IN THE SOFTWARE. */ /** \defgroup callback-when-writeable Callback when writeable @@ -222,4 +223,24 @@ */ LWS_VISIBLE LWS_EXTERN lws_fileofs_t lws_get_peer_write_allowance(struct lws *wsi); + +/** + * lws_wsi_tx_credit() - get / set generic tx credit if role supports it + * + * \param wsi: connection to set / get tx credit on + * \param peer_to_us: 0 = set / get us-to-peer direction, else peer-to-us + * \param add: amount of credit to add + * + * If the wsi does not support tx credit, returns 0. + * + * If add is zero, returns one of the wsi tx credit values for the wsi. + * If add is nonzero, \p add is added to the selected tx credit value + * for the wsi. + */ +#define LWSTXCR_US_TO_PEER 0 +#define LWSTXCR_PEER_TO_US 1 + +LWS_VISIBLE LWS_EXTERN int +lws_wsi_tx_credit(struct lws *wsi, char peer_to_us, int add); + ///@} diff -Nru libwebsockets-3.2.1/include/libwebsockets/lws-write.h libwebsockets-4.1.6/include/libwebsockets/lws-write.h --- libwebsockets-3.2.1/include/libwebsockets/lws-write.h 2019-12-18 14:45:31.000000000 +0000 +++ libwebsockets-4.1.6/include/libwebsockets/lws-write.h 2020-12-01 17:40:26.000000000 +0000 @@ -1,24 +1,25 @@ /* * libwebsockets - small server side websockets and web server implementation * - * Copyright (C) 2010-2018 Andy Green + * Copyright (C) 2010 - 2019 Andy Green * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation: - * version 2.1 of the License. + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to + * deal in the Software without restriction, including without limitation the + * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or + * sell copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: * - * This library is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. * - * You should have received a copy of the GNU Lesser General Public - * License along with this library; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, - * MA 02110-1301 USA - * - * included from libwebsockets.h + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS + * IN THE SOFTWARE. */ /*! \defgroup sending-data Sending data diff -Nru libwebsockets-3.2.1/include/libwebsockets/lws-ws-close.h libwebsockets-4.1.6/include/libwebsockets/lws-ws-close.h --- libwebsockets-3.2.1/include/libwebsockets/lws-ws-close.h 2019-12-18 14:45:31.000000000 +0000 +++ libwebsockets-4.1.6/include/libwebsockets/lws-ws-close.h 2020-12-01 17:40:26.000000000 +0000 @@ -1,24 +1,25 @@ /* * libwebsockets - small server side websockets and web server implementation * - * Copyright (C) 2010-2018 Andy Green + * Copyright (C) 2010 - 2019 Andy Green * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation: - * version 2.1 of the License. + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to + * deal in the Software without restriction, including without limitation the + * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or + * sell copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: * - * This library is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. * - * You should have received a copy of the GNU Lesser General Public - * License along with this library; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, - * MA 02110-1301 USA - * - * included from libwebsockets.h + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS + * IN THE SOFTWARE. */ /*! \defgroup wsclose Websocket Close diff -Nru libwebsockets-3.2.1/include/libwebsockets/lws-ws-ext.h libwebsockets-4.1.6/include/libwebsockets/lws-ws-ext.h --- libwebsockets-3.2.1/include/libwebsockets/lws-ws-ext.h 2019-12-18 14:45:31.000000000 +0000 +++ libwebsockets-4.1.6/include/libwebsockets/lws-ws-ext.h 2020-12-01 17:40:26.000000000 +0000 @@ -1,24 +1,25 @@ /* * libwebsockets - small server side websockets and web server implementation * - * Copyright (C) 2010-2018 Andy Green + * Copyright (C) 2010 - 2019 Andy Green * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation: - * version 2.1 of the License. + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to + * deal in the Software without restriction, including without limitation the + * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or + * sell copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: * - * This library is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. * - * You should have received a copy of the GNU Lesser General Public - * License along with this library; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, - * MA 02110-1301 USA - * - * included from libwebsockets.h + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS + * IN THE SOFTWARE. */ /*! \defgroup extensions Extension related functions diff -Nru libwebsockets-3.2.1/include/libwebsockets/lws-ws-state.h libwebsockets-4.1.6/include/libwebsockets/lws-ws-state.h --- libwebsockets-3.2.1/include/libwebsockets/lws-ws-state.h 2019-12-18 14:45:31.000000000 +0000 +++ libwebsockets-4.1.6/include/libwebsockets/lws-ws-state.h 2020-12-01 17:40:26.000000000 +0000 @@ -1,24 +1,25 @@ /* * libwebsockets - small server side websockets and web server implementation * - * Copyright (C) 2010-2018 Andy Green + * Copyright (C) 2010 - 2019 Andy Green * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation: - * version 2.1 of the License. + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to + * deal in the Software without restriction, including without limitation the + * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or + * sell copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: * - * This library is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. * - * You should have received a copy of the GNU Lesser General Public - * License along with this library; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, - * MA 02110-1301 USA - * - * included from libwebsockets.h + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS + * IN THE SOFTWARE. */ /** \defgroup wsstatus Websocket status APIs diff -Nru libwebsockets-3.2.1/include/libwebsockets/lws-x509.h libwebsockets-4.1.6/include/libwebsockets/lws-x509.h --- libwebsockets-3.2.1/include/libwebsockets/lws-x509.h 2019-12-18 14:45:31.000000000 +0000 +++ libwebsockets-4.1.6/include/libwebsockets/lws-x509.h 2020-12-01 17:40:26.000000000 +0000 @@ -3,22 +3,23 @@ * * Copyright (C) 2010 - 2019 Andy Green * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation: - * version 2.1 of the License. + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to + * deal in the Software without restriction, including without limitation the + * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or + * sell copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: * - * This library is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. * - * You should have received a copy of the GNU Lesser General Public - * License along with this library; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, - * MA 02110-1301 USA - * - * included from libwebsockets.h + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS + * IN THE SOFTWARE. */ enum lws_tls_cert_info { diff -Nru libwebsockets-3.2.1/include/libwebsockets.h libwebsockets-4.1.6/include/libwebsockets.h --- libwebsockets-3.2.1/include/libwebsockets.h 2019-12-18 14:45:31.000000000 +0000 +++ libwebsockets-4.1.6/include/libwebsockets.h 2020-12-01 17:40:26.000000000 +0000 @@ -1,22 +1,25 @@ /* * libwebsockets - small server side websockets and web server implementation * - * Copyright (C) 2010-2019 Andy Green + * Copyright (C) 2010 - 2019 Andy Green * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation: - * version 2.1 of the License. + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to + * deal in the Software without restriction, including without limitation the + * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or + * sell copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: * - * This library is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. * - * You should have received a copy of the GNU Lesser General Public - * License along with this library; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, - * MA 02110-1301 USA + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS + * IN THE SOFTWARE. */ /** @file */ @@ -40,9 +43,8 @@ /* place for one-shot opaque forward references */ -typedef struct lws_sequencer lws_seq_t; /* opaque */ -typedef struct lws_sorted_usec_list lws_sorted_usec_list_t; /* opaque */ -typedef struct lws_dsh lws_dsh_t; +struct lws_sequencer; +struct lws_dsh; /* * CARE: everything using cmake defines needs to be below here @@ -98,8 +100,6 @@ #else #define LWS_EXTERN extern __declspec(dllimport) #endif -#else -#define LWS_EXTERN #endif #endif @@ -131,14 +131,14 @@ #define LWS_O_CREAT O_CREAT #define LWS_O_TRUNC O_TRUNC -#if !defined(LWS_PLAT_OPTEE) && !defined(OPTEE_TA) && !defined(LWS_WITH_ESP32) +#if !defined(LWS_PLAT_OPTEE) && !defined(OPTEE_TA) && !defined(LWS_PLAT_FREERTOS) #include #include #define LWS_INVALID_FILE -1 #define LWS_SOCK_INVALID (-1) #else #define getdtablesize() (30) -#if defined(LWS_WITH_ESP32) +#if defined(LWS_PLAT_FREERTOS) #define LWS_INVALID_FILE NULL #define LWS_SOCK_INVALID (-1) #else @@ -147,6 +147,10 @@ #endif #endif +#if defined(__FreeBSD__) +#include +#endif + #if defined(__GNUC__) /* warn_unused_result attribute only supported by GCC 3.4 or later */ @@ -173,22 +177,6 @@ #endif -#if defined(LWS_WITH_LIBEV) -#include -#endif /* LWS_WITH_LIBEV */ -#ifdef LWS_WITH_LIBUV -#include -#ifdef LWS_HAVE_UV_VERSION_H -#include -#endif -#ifdef LWS_HAVE_NEW_UV_VERSION_H -#include -#endif -#endif /* LWS_WITH_LIBUV */ -#if defined(LWS_WITH_LIBEVENT) -#include -#endif /* LWS_WITH_LIBEVENT */ - #ifndef LWS_EXTERN #define LWS_EXTERN extern #endif @@ -202,6 +190,18 @@ #endif #endif +#if defined(LWS_WITH_LIBUV_INTERNAL) +#include + +#ifdef LWS_HAVE_UV_VERSION_H +#include +#endif + +#ifdef LWS_HAVE_NEW_UV_VERSION_H +#include +#endif +#endif + #if defined(LWS_WITH_TLS) #ifdef USE_WOLFSSL @@ -235,7 +235,7 @@ #endif /* not USE_OLD_CYASSL */ #else #if defined(LWS_WITH_MBEDTLS) -#if defined(LWS_WITH_ESP32) +#if defined(LWS_PLAT_FREERTOS) /* this filepath is passed to us but without quotes or <> */ #if !defined(LWS_AMAZON_RTOS) /* AMAZON RTOS has its own setting via MTK_MBEDTLS_CONFIG_FILE */ @@ -243,9 +243,11 @@ #define MBEDTLS_CONFIG_FILE #endif #endif +#if defined(LWS_WITH_TLS) #include #include #include +#endif #else #include #if !defined(LWS_WITH_MBEDTLS) @@ -312,6 +314,7 @@ #ifndef lws_container_of #define lws_container_of(P,T,M) ((T *)((char *)(P) - offsetof(T, M))) #endif +#define LWS_ALIGN_TO(x, bou) x += ((bou) - ((x) % (bou))) % (bou) struct lws; @@ -342,15 +345,17 @@ lws_sockfd_type fd; /**< file descriptor */ SHORT events; /**< which events to respond to */ SHORT revents; /**< which events happened */ + uint8_t write_blocked; }; #define LWS_POLLHUP (FD_CLOSE) #define LWS_POLLIN (FD_READ | FD_ACCEPT) #define LWS_POLLOUT (FD_WRITE) + #else -#if defined(LWS_WITH_ESP32) -#include +#if defined(LWS_PLAT_FREERTOS) +#include #else typedef int lws_sockfd_type; typedef int lws_filefd_type; @@ -518,36 +523,50 @@ struct lws_extension; /* needed even with ws exts disabled for create context */ struct lws_token_limits; +struct lws_protocols; struct lws_context; struct lws_tokens; struct lws_vhost; struct lws; +#include +#include +#if defined(LWS_WITH_SYS_SMD) +#include +#endif +#include +#include +#include +#include #include +#include #include #include #include #include #include -#include + #include + +#if defined(LWS_ROLE_MQTT) +#include +#endif #include #include #include #include #include #include -#include #include #include #include -#include -#include #include #include #include #include +#if defined(LWS_WITH_FILE_OPS) #include +#endif #include #include #include @@ -556,12 +575,17 @@ #include #include #include -#include #include +#include +#include +#include +#if !defined(LWS_PLAT_FREERTOS) #include #include +#endif +#include #if defined(LWS_WITH_TLS) @@ -585,6 +609,21 @@ #endif +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + #ifdef __cplusplus } #endif diff -Nru libwebsockets-3.2.1/lib/abstract/abstract.c libwebsockets-4.1.6/lib/abstract/abstract.c --- libwebsockets-3.2.1/lib/abstract/abstract.c 2019-12-18 14:45:31.000000000 +0000 +++ libwebsockets-4.1.6/lib/abstract/abstract.c 2020-12-01 17:40:26.000000000 +0000 @@ -1,44 +1,52 @@ /* * libwebsockets - small server side websockets and web server implementation * - * Copyright (C) 2010-2019 Andy Green + * Copyright (C) 2010 - 2019 Andy Green * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation: - * version 2.1 of the License. + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to + * deal in the Software without restriction, including without limitation the + * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or + * sell copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: * - * This library is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. * - * You should have received a copy of the GNU Lesser General Public - * License along with this library; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, - * MA 02110-1301 USA + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS + * IN THE SOFTWARE. */ -#include -#include +#include +#include extern const lws_abs_transport_t lws_abs_transport_cli_raw_skt, lws_abs_transport_cli_unit_test; #if defined(LWS_WITH_SMTP) extern const lws_abs_protocol_t lws_abs_protocol_smtp; #endif +#if defined(LWS_WITH_MQTT) +extern const lws_abs_protocol_t lws_abs_protocol_mqttc; +#endif static const lws_abs_transport_t * const available_abs_transports[] = { &lws_abs_transport_cli_raw_skt, &lws_abs_transport_cli_unit_test, }; -/* HACK: microsoft compiler can't handle zero length array definition */ -#if defined(LWS_WITH_SMTP) +#if defined(LWS_WITH_ABSTRACT) static const lws_abs_protocol_t * const available_abs_protocols[] = { #if defined(LWS_WITH_SMTP) &lws_abs_protocol_smtp, #endif +#if defined(LWS_WITH_MQTT) + &lws_abs_protocol_mqttc, +#endif }; #endif @@ -59,7 +67,7 @@ const lws_abs_protocol_t * lws_abs_protocol_get_by_name(const char *name) { -#if defined(LWS_WITH_SMTP) +#if defined(LWS_WITH_ABSTRACT) int n; for (n = 0; n < (int)LWS_ARRAY_SIZE(available_abs_protocols); n++) @@ -86,20 +94,59 @@ return NULL; } -void -lws_abs_destroy_instance(lws_abs_t **ai) +static int +lws_abstract_compare_connection(lws_abs_t *abs1, lws_abs_t *abs2) { - lws_abs_t *a = *ai; + /* it has to be using the same protocol */ + if (abs1->ap != abs2->ap) + return 1; + + /* protocol has to allow some kind of binding */ + if (!abs1->ap->flags) + return 1; + + /* it has to be using the same transport */ + if (abs1->at != abs2->at) + return 1; - if (a->api) - a->ap->destroy(&a->api); - if (a->ati) - a->at->destroy(&a->ati); + /* + * The transport must feel the endpoint and conditions in use match the + * requested endpoint and conditions... and the transport type must be + * willing to allow it + */ + if (abs1->at->compare(abs1, abs2)) + return 1; - lws_dll2_remove(&a->abstract_instances); + /* + * The protocol must feel they are in compatible modes if any + * (and the protocol type must be willing to allow it) + */ + if (abs1->ap->compare(abs1, abs2)) + return 1; - *ai = NULL; - free(a); + /* + * If no objection by now, we can say there's already a comparable + * connection and both the protocol and transport feel we can make + * use of it. + */ + + return 0; +} + +static int +find_compatible(struct lws_dll2 *d, void *user) +{ + lws_abs_t *ai1 = (lws_abs_t *)user, + *ai2 = lws_container_of(d, lws_abs_t, abstract_instances); + + if (!lws_abstract_compare_connection(ai1, ai2)) { + /* we can bind to it */ + lws_dll2_add_tail(&ai1->bound, &ai2->children_owner); + + return 1; + } + + return 0; } lws_abs_t * @@ -107,6 +154,7 @@ { size_t size = sizeof(lws_abs_t) + abs->ap->alloc + abs->at->alloc; lws_abs_t *ai; + int n; /* * since we know we will allocate the lws_abs_t, the protocol's @@ -121,10 +169,27 @@ ai->ati = NULL; ai->api = (char *)ai + sizeof(lws_abs_t); - if (ai->ap->create(ai)) { - ai->api = NULL; - goto bail; - } + + if (!ai->ap->flags) /* protocol only understands single connections */ + goto fresh; + + lws_vhost_lock(ai->vh); /* ----------------------------------- vh { */ + + /* + * Let's have a look for any already-connected transport we can use + */ + + n = lws_dll2_foreach_safe(&ai->vh->abstract_instances_owner, ai, + find_compatible); + + lws_vhost_unlock(ai->vh); /* } vh --------------------------------- */ + + if (n) + goto vh_list_add; + + /* there's no existing connection doing what we want */ + +fresh: ai->ati = (char *)ai->api + abs->ap->alloc; if (ai->at->create(ai)) { @@ -132,12 +197,36 @@ goto bail; } +vh_list_add: /* add us to the vhost's dll2 of instances */ lws_dll2_clear(&ai->abstract_instances); lws_dll2_add_head(&ai->abstract_instances, &ai->vh->abstract_instances_owner); + if (ai->ap->create(ai)) { + ai->api = NULL; + goto bail; + } + + if (ai->bound.owner) { /* we are a piggybacker */ + lws_abs_t *ai2 = lws_container_of(ai->bound.owner, lws_abs_t, + children_owner); + /* + * Provide an 'event' in the parent context to start handling + * the bind if it's otherwise idle. We give the parent abs + * because we don't know if we're "next" or whatever. Just that + * a child joined him and he should look into his child + * situation in case he was waiting for one to appear. + */ + if (ai2->ap->child_bind(ai2)) { + lwsl_info("%s: anticpated child bind fail\n", __func__); + lws_dll2_remove(&ai->bound); + + goto bail; + } + } + return ai; bail: @@ -145,3 +234,122 @@ return NULL; } + +/* + * We get called to clean up each child that was still bound to a parent + * at the time the parent is getting destroyed. + */ + +static void +__lws_abs_destroy_instance2(lws_abs_t **ai) +{ + lws_abs_t *a = *ai; + + if (a->api) + a->ap->destroy(&a->api); + if (a->ati) + a->at->destroy(&a->ati); + + lws_dll2_remove(&a->abstract_instances); + + *ai = NULL; + free(a); +} + +static int +__reap_children(struct lws_dll2 *d, void *user) +{ + lws_abs_t *ac = lws_container_of(d, lws_abs_t, bound); + + lws_dll2_foreach_safe(&ac->children_owner, NULL, __reap_children); + + /* then destroy ourselves */ + + __lws_abs_destroy_instance2(&ac); + + return 0; +} + +void +lws_abs_destroy_instance(lws_abs_t **ai) +{ + lws_abs_t *a = *ai; + + /* destroy child instances that are bound to us first... */ + + lws_vhost_lock(a->vh); /* ----------------------------------- vh { */ + + lws_dll2_foreach_safe(&a->children_owner, NULL, __reap_children); + + /* ...then destroy ourselves */ + + __lws_abs_destroy_instance2(ai); + + lws_vhost_unlock(a->vh); /* } vh --------------------------------- */ +} + +lws_abs_t * +lws_abstract_alloc(struct lws_vhost *vhost, void *user, + const char *abstract_path, const lws_token_map_t *ap_tokens, + const lws_token_map_t *at_tokens, struct lws_sequencer *seq, + void *opaque_user_data) +{ + lws_abs_t *abs = lws_zalloc(sizeof(*abs), __func__); + struct lws_tokenize ts; + lws_tokenize_elem e; + char tmp[30]; + + if (!abs) + return NULL; + + lws_tokenize_init(&ts, abstract_path, LWS_TOKENIZE_F_MINUS_NONTERM); + + e = lws_tokenize(&ts); + if (e != LWS_TOKZE_TOKEN) + goto abs_path_problem; + + if (lws_tokenize_cstr(&ts, tmp, sizeof(tmp))) + goto abs_path_problem; + + abs->ap = lws_abs_protocol_get_by_name(tmp); + if (!abs->ap) + goto abs_path_problem; + + e = lws_tokenize(&ts); + if (e != LWS_TOKZE_DELIMITER) + goto abs_path_problem; + + e = lws_tokenize(&ts); + if (e != LWS_TOKZE_TOKEN) + goto abs_path_problem; + + if (lws_tokenize_cstr(&ts, tmp, sizeof(tmp))) + goto abs_path_problem; + + abs->at = lws_abs_transport_get_by_name(tmp); + if (!abs->at) + goto abs_path_problem; + + abs->vh = vhost; + abs->ap_tokens = ap_tokens; + abs->at_tokens = at_tokens; + abs->seq = seq; + abs->opaque_user_data = opaque_user_data; + + lwsl_info("%s: allocated %s\n", __func__, abstract_path); + + return abs; + +abs_path_problem: + lwsl_err("%s: bad abs path '%s'\n", __func__, abstract_path); + lws_free_set_NULL(abs); + + return NULL; +} + +void +lws_abstract_free(lws_abs_t **pabs) +{ + if (*pabs) + lws_free_set_NULL(*pabs); +} diff -Nru libwebsockets-3.2.1/lib/abstract/CMakeLists.txt libwebsockets-4.1.6/lib/abstract/CMakeLists.txt --- libwebsockets-3.2.1/lib/abstract/CMakeLists.txt 1970-01-01 00:00:00.000000000 +0000 +++ libwebsockets-4.1.6/lib/abstract/CMakeLists.txt 2020-12-01 17:40:26.000000000 +0000 @@ -0,0 +1,57 @@ +# +# libwebsockets - small server side websockets and web server implementation +# +# Copyright (C) 2010 - 2020 Andy Green +# +# Permission is hereby granted, free of charge, to any person obtaining a copy +# of this software and associated documentation files (the "Software"), to +# deal in the Software without restriction, including without limitation the +# rights to use, copy, modify, merge, publish, distribute, sublicense, and/or +# sell copies of the Software, and to permit persons to whom the Software is +# furnished to do so, subject to the following conditions: +# +# The above copyright notice and this permission notice shall be included in +# all copies or substantial portions of the Software. +# +# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING +# FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS +# IN THE SOFTWARE. +# +# The strategy is to only export to PARENT_SCOPE +# +# - changes to LIB_LIST +# - changes to SOURCES +# - includes via include_directories +# +# and keep everything else private + +include_directories(.) + +list(APPEND SOURCES + abstract/abstract.c +) +if (LWS_WITH_SEQUENCER) + list(APPEND SOURCES + abstract/test-sequencer.c) +endif() + +list(APPEND SOURCES + abstract/transports/unit-test.c) + +#if (LWS_WITH_SMTP) +# list(APPEND SOURCES +# abstract/protocols/smtp/smtp.c +# abstract/protocols/smtp/smtp-sequencer.c +# ) +#endif() + +# +# Keep explicit parent scope exports at end +# + +exports_to_parent_scope() + diff -Nru libwebsockets-3.2.1/lib/abstract/private.h libwebsockets-4.1.6/lib/abstract/private.h --- libwebsockets-3.2.1/lib/abstract/private.h 2019-12-18 14:45:31.000000000 +0000 +++ libwebsockets-4.1.6/lib/abstract/private.h 1970-01-01 00:00:00.000000000 +0000 @@ -1,24 +0,0 @@ -/* - * libwebsockets - small server side websockets and web server implementation - * - * Copyright (C) 2010-2019 Andy Green - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation: - * version 2.1 of the License. - * - * This library is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with this library; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, - * MA 02110-1301 USA - */ - - - - diff -Nru libwebsockets-3.2.1/lib/abstract/private-lib-abstract.h libwebsockets-4.1.6/lib/abstract/private-lib-abstract.h --- libwebsockets-3.2.1/lib/abstract/private-lib-abstract.h 1970-01-01 00:00:00.000000000 +0000 +++ libwebsockets-4.1.6/lib/abstract/private-lib-abstract.h 2020-12-01 17:40:26.000000000 +0000 @@ -0,0 +1,55 @@ +/* + * libwebsockets - small server side websockets and web server implementation + * + * Copyright (C) 2010 - 2019 Andy Green + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to + * deal in the Software without restriction, including without limitation the + * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or + * sell copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS + * IN THE SOFTWARE. + */ + +#if !defined(__PRIVATE_LIB_ABSTRACT_H__) +#define __PRIVATE_LIB_ABSTRACT_H__ + +typedef struct lws_token_map lws_token_map_t; +typedef void lws_abs_transport_inst_t; +typedef void lws_abs_protocol_inst_t; + +typedef struct lws_abs { + void *user; + struct lws_vhost *vh; + + const struct lws_abs_protocol *ap; + const lws_token_map_t *ap_tokens; + const struct lws_abs_transport *at; + const lws_token_map_t *at_tokens; + + struct lws_sequencer *seq; + void *opaque_user_data; + + /* vh lock */ + struct lws_dll2_owner children_owner; /* our children / queue */ + /* vh lock */ + struct lws_dll2 bound; /* parent or encapsulator */ + /* vh lock */ + struct lws_dll2 abstract_instances; + lws_abs_transport_inst_t *ati; + lws_abs_protocol_inst_t *api; +} lws_abs_t; + +#endif + diff -Nru libwebsockets-3.2.1/lib/abstract/protocols/smtp/private-lib-abstract-protocols-smtp.h libwebsockets-4.1.6/lib/abstract/protocols/smtp/private-lib-abstract-protocols-smtp.h --- libwebsockets-3.2.1/lib/abstract/protocols/smtp/private-lib-abstract-protocols-smtp.h 1970-01-01 00:00:00.000000000 +0000 +++ libwebsockets-4.1.6/lib/abstract/protocols/smtp/private-lib-abstract-protocols-smtp.h 2020-12-01 17:40:26.000000000 +0000 @@ -0,0 +1,24 @@ +#define LWS_SMTP_MAX_EMAIL_LEN 32 + + +/* + * These are allocated on to the heap with an over-allocation to hold the + * payload at the end + */ + +typedef struct lws_smtp_email { + struct lws_dll2 list; + void *data; + + char from[LWS_SMTP_MAX_EMAIL_LEN]; + char to[LWS_SMTP_MAX_EMAIL_LEN]; + + time_t added; + time_t last_try; + + lws_smtp_cb_t done; + + int tries; + + /* email payload follows */ +} lws_smtp_email_t; diff -Nru libwebsockets-3.2.1/lib/abstract/protocols/smtp/smtp.c libwebsockets-4.1.6/lib/abstract/protocols/smtp/smtp.c --- libwebsockets-3.2.1/lib/abstract/protocols/smtp/smtp.c 2019-12-18 14:45:31.000000000 +0000 +++ libwebsockets-4.1.6/lib/abstract/protocols/smtp/smtp.c 2020-12-01 17:40:26.000000000 +0000 @@ -1,59 +1,65 @@ /* - * Abstract SMTP support for libwebsockets + * libwebsockets - small server side websockets and web server implementation * - * Copyright (C) 2016-2019 Andy Green + * Copyright (C) 2010 - 2019 Andy Green * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation: - * version 2.1 of the License. + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to + * deal in the Software without restriction, including without limitation the + * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or + * sell copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: * - * This library is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * General Public License for more details. + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. * - * You should have received a copy of the GNU General Public - * License along with this library; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, - * MA 02110-1301 USA + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS + * IN THE SOFTWARE. */ -#include "core/private.h" -#include "abstract/private.h" +#include "private-lib-core.h" +#include "private-lib-abstract.h" /** enum lwsgs_smtp_states - where we are in SMTP protocol sequence */ typedef enum lwsgs_smtp_states { LGSSMTP_IDLE, /**< awaiting new email */ LGSSMTP_CONNECTING, /**< opening tcp connection to MTA */ LGSSMTP_CONNECTED, /**< tcp connection to MTA is connected */ + /* (server sends greeting) */ LGSSMTP_SENT_HELO, /**< sent the HELO */ + LGSSMTP_SENT_FROM, /**< sent FROM */ LGSSMTP_SENT_TO, /**< sent TO */ LGSSMTP_SENT_DATA, /**< sent DATA request */ LGSSMTP_SENT_BODY, /**< sent the email body */ - LGSSMTP_SENT_QUIT, /**< sent the session quit */ -} lwsgs_smtp_states_t; -/** struct lws_email - abstract context for performing SMTP operations */ -typedef struct lws_smtp_client { - struct lws_dll2_owner pending_owner; + /* + * (server sends, eg, "250 Ok: queued as 12345") + * at this point we can return to LGSSMTP_SENT_HELO and send a + * new email, or continue below to QUIT, or just wait + */ - const struct lws_abs *abs; + LGSSMTP_SENT_QUIT, /**< sent the session quit */ - const char *helo; + /* (server sends, eg, "221 Bye" and closes the connection) */ +} lwsgs_smtp_states_t; - lwsgs_smtp_states_t estate; - time_t email_connect_started; +/** abstract protocol instance data */ - time_t retry_interval; - time_t delivery_timeout; +typedef struct lws_smtp_client_protocol { + const struct lws_abs *abs; + lwsgs_smtp_states_t estate; - size_t email_queue_max; - size_t max_content_size; + lws_smtp_email_t *e; /* the email we are trying to send */ + const char *helo; - unsigned char send_pending:1; -} lws_smtp_client_t; + unsigned char send_pending:1; +} lws_smtpcp_t; static const short retcodes[] = { 0, /* idle */ @@ -68,80 +74,71 @@ }; static void -lws_smtp_client_state_transition(lws_smtp_client_t *c, lwsgs_smtp_states_t s) +lws_smtpc_state_transition(lws_smtpcp_t *c, lwsgs_smtp_states_t s) { lwsl_debug("%s: cli %p: state %d -> %d\n", __func__, c, c->estate, s); c->estate = s; } -static void -lws_smtp_client_kick_internal(lws_smtp_client_t *c) +static lws_smtp_email_t * +lws_smtpc_get_email(lws_smtpcp_t *c) { - lws_smtp_email_t *e; - lws_dll2_t *d; - char buf[64]; - int n; - - if (c->estate != LGSSMTP_IDLE) - return; - - /* is there something to do? */ - -again: - d = lws_dll2_get_head(&c->pending_owner); - if (!d) - return; + const lws_token_map_t *tm; - e = lws_container_of(d, lws_smtp_email_t, list); + /* ... the email we want to send */ + tm = lws_abs_get_token(c->abs->ap_tokens, LTMI_PSMTP_V_LWS_SMTP_EMAIL_T); + if (!tm) { + assert(0); - /* do we need to time out this guy? */ + return NULL; + } - if ((time_t)lws_now_secs() - e->added > (time_t)c->delivery_timeout) { - lwsl_err("%s: timing out email\n", __func__); - lws_dll2_remove(&e->list); - n = lws_snprintf(buf, sizeof(buf), "0 Timed out retrying send"); - e->done(e, buf, n); + return (lws_smtp_email_t *)tm->u.value; +} - if (lws_dll2_get_head(&c->pending_owner)) - goto again; +/* + * Called when something happened so that we know now the final disposition of + * the email send attempt, for good or ill. + * + * Inform the owner via the done callback and set up the next queued one if any. + * + * Returns nonzero if we queued a new one + */ - return; - } +static int +lws_smtpc_email_disposition(lws_smtpcp_t *c, int disp, const void *buf, + size_t len) +{ + lws_smtpcp_t *ch; + lws_abs_t *ach; + lws_dll2_t *d; - /* is it time for his retry yet? */ + lws_smtpc_state_transition(c, LGSSMTP_SENT_HELO); - if (e->last_try && - (time_t)lws_now_secs() - e->last_try < (time_t)c->retry_interval) { - /* no... send him to the tail */ - lws_dll2_remove(&e->list); - lws_dll2_add_tail(&e->list, &c->pending_owner); - return; - } + /* lifetime of the email object is handled by done callback */ + c->e->done(c->e, c->e->data, disp, buf, len); + c->e = NULL; - /* ask the transport if we have a connection to the server ongoing */ + /* this may not be the time to try to send anything else... */ - if (c->abs->at->state(c->abs->ati)) { - /* - * there's a connection, it could be still trying to connect - * or established - */ - c->abs->at->ask_for_writeable(c->abs->ati); + if (disp == LWS_SMTP_DISPOSITION_FAILED_DESTROY) + return 0; - return; - } + /* ... otherwise... do we have another queued? */ - /* there's no existing connection */ + d = lws_dll2_get_tail(&c->abs->children_owner); + if (!d) + return 0; - lws_smtp_client_state_transition(c, LGSSMTP_CONNECTING); + ach = lws_container_of(d, lws_abs_t, bound); + ch = (lws_smtpcp_t *)ach->api; - if (c->abs->at->client_conn(c->abs)) { - lwsl_err("%s: failed to connect\n", __func__); + c->e = lws_smtpc_get_email(ch); - return; - } + /* since we took it on, remove it from the queue */ + lws_dll2_remove(d); - e->tries++; - e->last_try = lws_now_secs(); + return 1; } /* @@ -149,53 +146,85 @@ */ static int -lws_smtp_client_abs_accept(lws_abs_protocol_inst_t *api) +lws_smtpc_abs_accept(lws_abs_protocol_inst_t *api) { - lws_smtp_client_t *c = (lws_smtp_client_t *)api; + lws_smtpcp_t *c = (lws_smtpcp_t *)api; - lws_smtp_client_state_transition(c, LGSSMTP_CONNECTED); + /* we have become connected in the tcp sense */ + + lws_smtpc_state_transition(c, LGSSMTP_CONNECTED); + + /* + * From the accept(), the next thing that should happen is the SMTP + * server sends its greeting like "220 smtp2.example.com ESMTP Postfix", + * we'll hear about it in the rx callback, or time out + */ + + c->abs->at->set_timeout(c->abs->ati, + PENDING_TIMEOUT_AWAITING_SERVER_RESPONSE, 3); return 0; } static int -lws_smtp_client_abs_rx(lws_abs_protocol_inst_t *api, uint8_t *buf, size_t len) +lws_smtpc_abs_rx(lws_abs_protocol_inst_t *api, const uint8_t *buf, size_t len) { - lws_smtp_client_t *c = (lws_smtp_client_t *)api; - lws_smtp_email_t *e; - lws_dll2_t *pd2; + lws_smtpcp_t *c = (lws_smtpcp_t *)api; + char dotstar[96], at[5]; int n; - pd2 = lws_dll2_get_head(&c->pending_owner); - if (!pd2) - return 0; - - e = lws_container_of(pd2, lws_smtp_email_t, list); - if (!e) - return 0; + c->abs->at->set_timeout(c->abs->ati, NO_PENDING_TIMEOUT, 0); - n = atoi((char *)buf); - if (n != retcodes[c->estate]) { - lwsl_notice("%s: bad response from server: %d (state %d) %.*s\n", - __func__, n, c->estate, (int)len, buf); - - lws_dll2_remove(&e->list); - lws_dll2_add_tail(&e->list, &c->pending_owner); - lws_smtp_client_state_transition(c, LGSSMTP_IDLE); - lws_smtp_client_kick_internal(c); + lws_strncpy(at, (const char *)buf, sizeof(at)); + n = atoi(at); - return 0; - } + switch (c->estate) { + case LGSSMTP_CONNECTED: + if (n != 220) { + /* + * The server did not properly greet us... we can't + * even get started, so fail the transport connection + * (and anything queued on it) + */ - if (c->estate == LGSSMTP_SENT_QUIT) { - lwsl_debug("%s: done\n", __func__); - lws_smtp_client_state_transition(c, LGSSMTP_IDLE); + lws_strnncpy(dotstar, (const char *)buf, len, sizeof(dotstar)); + lwsl_err("%s: server: %s\n", __func__, dotstar); - lws_dll2_remove(&e->list); - if (e->done && e->done(e, "sent OK", 7)) return 1; + } + break; + + case LGSSMTP_SENT_BODY: + /* + * We finished one way or another... let's prepare to send a + * new one... or wait until server hangs up on us + */ + if (!lws_smtpc_email_disposition(c, + n == 250 ? LWS_SMTP_DISPOSITION_SENT : + LWS_SMTP_DISPOSITION_FAILED, + "destroyed", 0)) + return 0; /* become idle */ + + break; /* ask to send */ + + case LGSSMTP_SENT_QUIT: + lwsl_debug("%s: done\n", __func__); + lws_smtpc_state_transition(c, LGSSMTP_IDLE); return 1; + + default: + if (n != retcodes[c->estate]) { + lws_strnncpy(dotstar, buf, len, sizeof(dotstar)); + lwsl_notice("%s: bad response: %d (state %d) %s\n", + __func__, n, c->estate, dotstar); + + lws_smtpc_email_disposition(c, + LWS_SMTP_DISPOSITION_FAILED, buf, len); + + return 0; + } + break; } c->send_pending = 1; @@ -205,24 +234,13 @@ } static int -lws_smtp_client_abs_writeable(lws_abs_protocol_inst_t *api, size_t budget) +lws_smtpc_abs_writeable(lws_abs_protocol_inst_t *api, size_t budget) { - lws_smtp_client_t *c = (lws_smtp_client_t *)api; char b[256 + LWS_PRE], *p = b + LWS_PRE; - lws_smtp_email_t *e; - lws_dll2_t *pd2; + lws_smtpcp_t *c = (lws_smtpcp_t *)api; int n; - pd2 = lws_dll2_get_head(&c->pending_owner); - if (!pd2) - return 0; - - e = lws_container_of(pd2, lws_smtp_email_t, list); - if (!e) - return 0; - - - if (!c->send_pending) + if (!c->send_pending || !c->e) return 0; c->send_pending = 0; @@ -232,31 +250,37 @@ switch (c->estate) { case LGSSMTP_CONNECTED: n = lws_snprintf(p, sizeof(b) - LWS_PRE, "HELO %s\n", c->helo); - lws_smtp_client_state_transition(c, LGSSMTP_SENT_HELO); + lws_smtpc_state_transition(c, LGSSMTP_SENT_HELO); break; + case LGSSMTP_SENT_HELO: n = lws_snprintf(p, sizeof(b) - LWS_PRE, "MAIL FROM: <%s>\n", - e->email_from); - lws_smtp_client_state_transition(c, LGSSMTP_SENT_FROM); + c->e->from); + lws_smtpc_state_transition(c, LGSSMTP_SENT_FROM); break; + case LGSSMTP_SENT_FROM: n = lws_snprintf(p, sizeof(b) - LWS_PRE, - "RCPT TO: <%s>\n", e->email_to); - lws_smtp_client_state_transition(c, LGSSMTP_SENT_TO); + "RCPT TO: <%s>\n", c->e->to); + lws_smtpc_state_transition(c, LGSSMTP_SENT_TO); break; + case LGSSMTP_SENT_TO: n = lws_snprintf(p, sizeof(b) - LWS_PRE, "DATA\n"); - lws_smtp_client_state_transition(c, LGSSMTP_SENT_DATA); + lws_smtpc_state_transition(c, LGSSMTP_SENT_DATA); break; + case LGSSMTP_SENT_DATA: - p = (char *)e->payload; - n = strlen(e->payload); - lws_smtp_client_state_transition(c, LGSSMTP_SENT_BODY); + p = (char *)&c->e[1]; + n = strlen(p); + lws_smtpc_state_transition(c, LGSSMTP_SENT_BODY); break; + case LGSSMTP_SENT_BODY: n = lws_snprintf(p, sizeof(b) - LWS_PRE, "quit\n"); - lws_smtp_client_state_transition(c, LGSSMTP_SENT_QUIT); + lws_smtpc_state_transition(c, LGSSMTP_SENT_QUIT); break; + case LGSSMTP_SENT_QUIT: return 0; @@ -271,179 +295,88 @@ } static int -lws_smtp_client_abs_closed(lws_abs_protocol_inst_t *api) +lws_smtpc_abs_closed(lws_abs_protocol_inst_t *api) { - lws_smtp_client_t *c = (lws_smtp_client_t *)api; + lws_smtpcp_t *c = (lws_smtpcp_t *)api; if (c) - lws_smtp_client_state_transition(c, LGSSMTP_IDLE); + lws_smtpc_state_transition(c, LGSSMTP_IDLE); return 0; } +/* + * Creating for initial transport and for piggybacking on another transport + * both get created here the same. But piggybackers have ai->bound attached. + */ + static int -lws_smtp_client_abs_heartbeat(lws_abs_protocol_inst_t *api) +lws_smtpc_create(const lws_abs_t *ai) { - lws_smtp_client_t *c = (lws_smtp_client_t *)api; - - lws_smtp_client_kick_internal(c); - - return 0; -} + lws_smtpcp_t *c = (lws_smtpcp_t *)ai->api; -lws_smtp_email_t * -lws_smtp_client_alloc_email_helper(const char *payload, size_t payload_len, - const char *sender, const char *recipient, - const char *extra, size_t extra_len, void *data, - int (*done)(struct lws_smtp_email *e, - void *buf, size_t len)) -{ - size_t ls = strlen(sender), lr = strlen(recipient); - lws_smtp_email_t *em; - char *p; - - em = malloc(sizeof(*em) + payload_len + ls + lr + extra_len + 4); - if (!em) { - lwsl_err("OOM\n"); - return NULL; - } - - p = (char *)&em[1]; + memset(c, 0, sizeof(*c)); - memset(em, 0, sizeof(*em)); + c->abs = ai; + c->e = lws_smtpc_get_email(c); - em->data = data; - em->done = done; + lws_smtpc_state_transition(c, lws_dll2_is_detached(&ai->bound) ? + LGSSMTP_CONNECTING : LGSSMTP_IDLE); - em->email_from = p; - memcpy(p, sender, ls + 1); - p += ls + 1; - em->email_to = p; - memcpy(p, recipient, lr + 1); - p += lr + 1; - em->payload = p; - memcpy(p, payload, payload_len + 1); - p += payload_len + 1; - - if (extra) { - em->extra = p; - memcpy(p, extra, extra_len + 1); - } + /* If we are initiating the transport, we will get an accept() next... + * + * If we are piggybacking, the parent will get a .child_bind() after + * this to give it a chance to act on us joining (eg, it was completely + * idle and we joined). + */ - return em; + return 0; } -int -lws_smtp_client_add_email(lws_abs_t *instance, lws_smtp_email_t *e) +static void +lws_smtpc_destroy(lws_abs_protocol_inst_t **_c) { - lws_smtp_client_t *c = (lws_smtp_client_t *)instance->api; - - if (c->pending_owner.count > c->email_queue_max) { - lwsl_err("%s: email queue at limit of %d\n", __func__, - (int)c->email_queue_max); - - return 1; - } - - e->added = lws_now_secs(); - e->last_try = 0; - e->tries = 0; + lws_smtpcp_t *c = (lws_smtpcp_t *)*_c; - lws_dll2_clear(&e->list); - lws_dll2_add_tail(&e->list, &c->pending_owner); + if (!c) + return; - lws_smtp_client_kick_internal(c); + /* so if we are still holding on to c->e, we have failed to send it */ + if (c->e) + lws_smtpc_email_disposition(c, + LWS_SMTP_DISPOSITION_FAILED_DESTROY, "destroyed", 0); - return 0; + *_c = NULL; } -void -lws_smtp_client_kick(lws_abs_t *instance) -{ - lws_smtp_client_t *c = (lws_smtp_client_t *)instance->api; - - lws_smtp_client_kick_internal(c); -} static int -lws_smtp_client_create(const lws_abs_t *ai) +lws_smtpc_compare(lws_abs_t *abs1, lws_abs_t *abs2) { - lws_smtp_client_t *c = (lws_smtp_client_t *)ai->api; - const lws_token_map_t *tm; - - memset(c, 0, sizeof(*c)); - - c->abs = ai; - - tm = lws_abs_get_token(ai->ap_tokens, LTMI_PSMTP_V_HELO); - if (!tm) { - lwsl_err("%s: LTMI_PSMTP_V_HELO is required\n", __func__); - - return 1; - } - c->helo = tm->u.value; - - c->email_queue_max = 8; - c->retry_interval = 15 * 60; - c->delivery_timeout = 12 * 60 * 60; - - tm = lws_abs_get_token(ai->ap_tokens, LTMI_PSMTP_LV_EMAIL_QUEUE_MAX); - if (tm) - c->email_queue_max = tm->u.lvalue; - tm = lws_abs_get_token(ai->ap_tokens, LTMI_PSMTP_LV_RETRY_INTERVAL); - if (tm) - c->retry_interval = tm->u.lvalue; - tm = lws_abs_get_token(ai->ap_tokens, LTMI_PSMTP_LV_DELIVERY_TIMEOUT); - if (tm) - c->delivery_timeout = tm->u.lvalue; - - lws_smtp_client_state_transition(c, LGSSMTP_IDLE); - return 0; } static int -cleanup(struct lws_dll2 *d, void *user) +lws_smtpc_child_bind(lws_abs_t *abs) { - lws_smtp_email_t *e; - - e = lws_container_of(d, lws_smtp_email_t, list); - if (e->done && e->done(e, "destroying", 10)) - return 1; - return 0; } -static void -lws_smtp_client_destroy(lws_abs_protocol_inst_t **_c) -{ - lws_smtp_client_t *c = (lws_smtp_client_t *)*_c; - - if (!c) - return; - - lws_dll2_foreach_safe(&c->pending_owner, NULL, cleanup); - - /* - * We don't free anything because the abstract layer combined our - * allocation with that of the instance, and it will free the whole - * thing after this. - */ - - *_c = NULL; -} - /* events the transport invokes (handled by abstract protocol) */ const lws_abs_protocol_t lws_abs_protocol_smtp = { .name = "smtp", - .alloc = sizeof(lws_smtp_client_t), + .alloc = sizeof(lws_smtpcp_t), + .flags = LWSABSPR_FLAG_PIPELINE, - .create = lws_smtp_client_create, - .destroy = lws_smtp_client_destroy, + .create = lws_smtpc_create, + .destroy = lws_smtpc_destroy, + .compare = lws_smtpc_compare, + + .accept = lws_smtpc_abs_accept, + .rx = lws_smtpc_abs_rx, + .writeable = lws_smtpc_abs_writeable, + .closed = lws_smtpc_abs_closed, + .heartbeat = NULL, - .accept = lws_smtp_client_abs_accept, - .rx = lws_smtp_client_abs_rx, - .writeable = lws_smtp_client_abs_writeable, - .closed = lws_smtp_client_abs_closed, - .heartbeat = lws_smtp_client_abs_heartbeat, + .child_bind = lws_smtpc_child_bind, }; diff -Nru libwebsockets-3.2.1/lib/abstract/protocols/smtp/smtp-sequencer.c libwebsockets-4.1.6/lib/abstract/protocols/smtp/smtp-sequencer.c --- libwebsockets-3.2.1/lib/abstract/protocols/smtp/smtp-sequencer.c 1970-01-01 00:00:00.000000000 +0000 +++ libwebsockets-4.1.6/lib/abstract/protocols/smtp/smtp-sequencer.c 2020-12-01 17:40:26.000000000 +0000 @@ -0,0 +1,320 @@ +/* + * Abstract SMTP support for libwebsockets - SMTP sequencer + * + * Copyright (C) 2016-2019 Andy Green + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation: + * version 2.1 of the License. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * General Public License for more details. + * + * You should have received a copy of the GNU General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, + * MA 02110-1301 USA + * + * This sequencer sits above the abstract protocol, and manages queueing, + * retrying mail transmission, and retry limits. + * + * Having the sequencer means that, eg, we can manage retries after complete + * connection failure. + * + * Connections to the smtp server are serialized + */ + +#include "private-lib-core.h" +#include "private-lib-abstract-protocols-smtp.h" + +typedef enum { + LSMTPSS_DISCONNECTED, + LSMTPSS_CONNECTING, + LSMTPSS_CONNECTED, + LSMTPSS_BUSY, +} smtpss_connstate_t; + +typedef struct lws_smtp_sequencer { + struct lws_dll2_owner emails_owner; /* email queue */ + + lws_abs_t *abs, *instance; + lws_smtp_sequencer_args_t args; + struct lws_sequencer *seq; + + smtpss_connstate_t connstate; + + time_t email_connect_started; + + /* holds the HELO for the smtp protocol to consume */ + lws_token_map_t apt[3]; +} lws_smtp_sequencer_t; + +/* sequencer messages specific to this sequencer */ + +enum { + SEQ_MSG_CLIENT_FAILED = LWSSEQ_USER_BASE, + SEQ_MSG_CLIENT_DONE, +}; + +/* + * We're going to bind to the raw-skt transport, so tell that what we want it + * to connect to + */ + +static const lws_token_map_t smtp_rs_transport_tokens[] = { + { + .u = { .value = "127.0.0.1" }, + .name_index = LTMI_PEER_V_DNS_ADDRESS, + }, { + .u = { .lvalue = 25 }, + .name_index = LTMI_PEER_LV_PORT, + }, { + } +}; + +static void +lws_smtpc_kick_internal(lws_smtp_sequencer_t *s) +{ + lws_smtp_email_t *e; + lws_dll2_t *d; + char buf[64]; + int n; + lws_dll2_t *pd2; + + pd2 = lws_dll2_get_head(&s->emails_owner); + if (!pd2) + return; + + e = lws_container_of(pd2, lws_smtp_email_t, list); + if (!e) + return; + + /* Is there something to do? If so, we need a connection... */ + + if (s->connstate == LSMTPSS_DISCONNECTED) { + + s->apt[0].u.value = s->args.helo; + s->apt[0].name_index = LTMI_PSMTP_V_HELO; + s->apt[1].u.value = (void *)e; + s->apt[1].name_index = LTMI_PSMTP_V_LWS_SMTP_EMAIL_T; + + /* + * create and connect the smtp protocol + transport + */ + + s->abs = lws_abstract_alloc(s->args.vhost, NULL, "smtp.raw_skt", + s->apt, smtp_rs_transport_tokens, + s->seq, NULL); + if (!s->abs) + return; + + s->instance = lws_abs_bind_and_create_instance(s->abs); + if (!s->instance) { + lws_abstract_free(&s->abs); + lwsl_err("%s: failed to create SMTP client\n", __func__); + + goto bail1; + } + + s->connstate = LSMTPSS_CONNECTING; + lws_seq_timeout_us(s->seq, 10 * LWS_USEC_PER_SEC); + return; + } + + /* ask the transport if we have a connection to the server ongoing */ + + if (s->abs->at->state(s->abs->ati)) { + /* + * there's a connection, it could be still trying to connect + * or established + */ + s->abs->at->ask_for_writeable(s->abs->ati); + + return; + } + + /* there's no existing connection */ + + lws_smtpc_state_transition(c, LGSSMTP_CONNECTING); + + if (s->abs->at->client_conn(s->abs)) { + lwsl_err("%s: failed to connect\n", __func__); + + return; + } + + e->tries++; + e->last_try = lws_now_secs(); +} + + +/* + * The callback we get from the smtp protocol... we use this to drive + * decisions about destroy email, retry and fail. + * + * Sequencer will handle it via the event loop. + */ + +static int +email_result(void *e, void *d, int disp, void *b, size_t l) +{ + lws_smtp_sequencer_t *s = (lws_smtp_sequencer_t *)d; + + lws_sequencer_event(s->seq, LWSSEQ_USER_BASE + disp, e); + + return 0; +} + +static int +cleanup(struct lws_dll2 *d, void *user) +{ + lws_smtp_email_t *e; + + e = lws_container_of(d, lws_smtp_email_t, list); + if (e->done) + e->done(e, "destroying", 10); + + lws_dll2_remove(d); + lws_free(e); + + return 0; +} + +static lws_seq_cb_return_t +smtp_sequencer_cb(struct lws_sequencer *seq, void *user, int event, void *data) +{ + struct lws_smtp_sequencer_t *s = (struct lws_smtp_sequencer_t *)user; + + switch ((int)event) { + case LWSSEQ_CREATED: /* our sequencer just got started */ + lwsl_notice("%s: %s: created\n", __func__, + lws_sequencer_name(seq)); + s->connstate = LSMTPSS_DISCONNECTED; + s->state = 0; /* first thing we'll do is the first url */ + goto step; + + case LWSSEQ_DESTROYED: + lws_dll2_foreach_safe(&s->pending_owner, NULL, cleanup); + break; + + case LWSSEQ_TIMED_OUT: + lwsl_notice("%s: LWSSEQ_TIMED_OUT\n", __func__); + break; + + case LWSSEQ_USER_BASE + LWS_SMTP_DISPOSITION_SENT: + lws_smtpc_free_email(data); + break; + + case LWSSEQ_WSI_CONNECTED: + s->connstate = LSMTPSS_CONNECTED; + lws_smtpc_kick_internal(s); + break; + + case LWSSEQ_WSI_CONN_FAIL: + case LWSSEQ_WSI_CONN_CLOSE: + s->connstate = LSMTPSS_DISCONNECTED; + lws_smtpc_kick_internal(s); + break; + + case SEQ_MSG_SENT: + break; + + default: + break; + } + + return LWSSEQ_RET_CONTINUE; +} + +/* + * Creates an lws_sequencer to manage the test sequence + */ + +lws_smtp_sequencer_t * +lws_smtp_sequencer_create(const lws_smtp_sequencer_args_t *args) +{ + lws_smtp_sequencer_t *s; + struct lws_sequencer *seq; + + /* + * Create a sequencer in the event loop to manage the SMTP queue + */ + + seq = lws_sequencer_create(args->vhost->context, 0, + sizeof(lws_smtp_sequencer_t), (void **)&s, + smtp_sequencer_cb, "smtp-seq"); + if (!seq) { + lwsl_err("%s: unable to create sequencer\n", __func__); + return NULL; + } + + s->abs = *args->abs; + s->args = *args; + s->seq = seq; + + /* set defaults in our copy of the args */ + + if (!s->args.helo[0]) + strcpy(s->args.helo, "default-helo"); + if (!s->args.email_queue_max) + s->args.email_queue_max = 8; + if (!s->args.retry_interval) + s->args.retry_interval = 15 * 60; + if (!s->args.delivery_timeout) + s->args.delivery_timeout = 12 * 60 * 60; + + return s; +} + +void +lws_smtp_sequencer_destroy(lws_smtp_sequencer_t *s) +{ + /* sequencer destruction destroys all assets */ + lws_sequencer_destroy(&s->seq); +} + +int +lws_smtpc_add_email(lws_smtp_sequencer_t *s, const char *payload, + size_t payload_len, const char *sender, + const char *recipient, void *data, lws_smtp_cb_t done) +{ + lws_smtp_email_t *e; + + if (s->emails_owner.count > s->args.email_queue_max) { + lwsl_err("%s: email queue at limit of %d\n", __func__, + (int)s->args.email_queue_max); + + return 1; + } + + if (!done) + return 1; + + e = malloc(sizeof(*e) + payload_len + 1); + if (!e) + return 1; + + memset(e, 0, sizeof(*e)); + + e->data = data; + e->done = done; + + lws_strncpy(e->from, sender, sizeof(e->from)); + lws_strncpy(e->to, recipient, sizeof(e->to)); + + memcpy((char *)&e[1], payload, payload_len + 1); + + e->added = lws_now_secs(); + e->last_try = 0; + e->tries = 0; + + lws_dll2_clear(&e->list); + lws_dll2_add_tail(&e->list, &s->emails_owner); + + lws_smtpc_kick_internal(s); + + return 0; +} diff -Nru libwebsockets-3.2.1/lib/abstract/test-sequencer.c libwebsockets-4.1.6/lib/abstract/test-sequencer.c --- libwebsockets-3.2.1/lib/abstract/test-sequencer.c 2019-12-18 14:45:31.000000000 +0000 +++ libwebsockets-4.1.6/lib/abstract/test-sequencer.c 2020-12-01 17:40:26.000000000 +0000 @@ -1,23 +1,25 @@ -/* - * libwebsockets lib/abstract/test-sequencer.c - * - * Copyright (C) 2019 Andy Green + /* + * libwebsockets - small server side websockets and web server implementation * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation: - * version 2.1 of the License. - * - * This library is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with this library; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, - * MA 02110-1301 USA + * Copyright (C) 2010 - 2019 Andy Green * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to + * deal in the Software without restriction, including without limitation the + * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or + * sell copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS + * IN THE SOFTWARE. * * A helper for running multiple unit tests against abstract protocols. * @@ -26,7 +28,7 @@ * for each test using te */ -#include +#include struct lws_seq_test_sequencer { lws_abs_t original_abs; @@ -35,7 +37,7 @@ struct lws_context *context; struct lws_vhost *vhost; - lws_seq_t *unit_test_seq; + struct lws_sequencer *unit_test_seq; /* holds the per-test token for the unit-test transport to consume */ lws_token_map_t uttt[4]; @@ -233,7 +235,7 @@ lws_abs_unit_test_sequencer(const lws_test_sequencer_args_t *args) { struct lws_seq_test_sequencer *s; - lws_seq_t *seq; + struct lws_sequencer *seq; lws_seq_info_t i; memset(&i, 0, sizeof(i)); diff -Nru libwebsockets-3.2.1/lib/abstract/transports/raw-skt.c libwebsockets-4.1.6/lib/abstract/transports/raw-skt.c --- libwebsockets-3.2.1/lib/abstract/transports/raw-skt.c 2019-12-18 14:45:31.000000000 +0000 +++ libwebsockets-4.1.6/lib/abstract/transports/raw-skt.c 2020-12-01 17:40:26.000000000 +0000 @@ -1,26 +1,29 @@ /* - * libwebsockets lib/abstract/transports/raw-skt.c + * libwebsockets - small server side websockets and web server implementation * - * Copyright (C) 2019 Andy Green + * Copyright (C) 2010 - 2019 Andy Green * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation: - * version 2.1 of the License. + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to + * deal in the Software without restriction, including without limitation the + * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or + * sell copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: * - * This library is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. * - * You should have received a copy of the GNU Lesser General Public - * License along with this library; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, - * MA 02110-1301 USA + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS + * IN THE SOFTWARE. */ -#include "core/private.h" -#include "abstract/private.h" +#include "private-lib-core.h" +#include "private-lib-abstract.h" typedef struct lws_abstxp_raw_skt_priv { struct lws_abs *abs; @@ -210,7 +213,7 @@ return 0; } -#if !defined(LWS_WITHOUT_CLIENT) +#if defined(LWS_WITH_CLIENT) static int lws_atcrs_client_conn(const lws_abs_t *abs) { @@ -270,6 +273,16 @@ i.seq = abs->seq; i.opaque_user_data = abs->opaque_user_data; + /* + * the protocol itself has some natural attributes we should pass on + */ + + if (abs->ap->flags & LWS_AP_FLAG_PIPELINE_TRANSACTIONS) + i.ssl_connection |= LCCSCF_PIPELINE; + + if (abs->ap->flags & LWS_AP_FLAG_MUXABLE_STREAM) + i.ssl_connection |= LCCSCF_MUXABLE_STREAM; + priv->wsi = lws_client_connect_via_info(&i); if (!priv->wsi) return 1; @@ -308,9 +321,9 @@ lws_atcrs_destroy(lws_abs_transport_inst_t **pati) { /* - * We don't free anything because the abstract layer combined our - * allocation with that of the instance, and it will free the whole - * thing after this. + * For ourselves, we don't free anything because the abstract layer + * combined our allocation with that of the abs instance, and it will + * free the whole thing after this. */ *pati = NULL; } @@ -336,15 +349,54 @@ return 1; } +static int +lws_atcrs_compare(lws_abs_t *abs1, lws_abs_t *abs2) +{ + const lws_token_map_t *tm1, *tm2; + + tm1 = lws_abs_get_token(abs1->at_tokens, LTMI_PEER_V_DNS_ADDRESS); + tm2 = lws_abs_get_token(abs2->at_tokens, LTMI_PEER_V_DNS_ADDRESS); + + /* Address token is mandatory and must match */ + if (!tm1 || !tm2 || strcmp(tm1->u.value, tm2->u.value)) + return 1; + + /* Port token is mandatory and must match */ + tm1 = lws_abs_get_token(abs1->at_tokens, LTMI_PEER_LV_PORT); + tm2 = lws_abs_get_token(abs2->at_tokens, LTMI_PEER_LV_PORT); + if (!tm1 || !tm2 || tm1->u.lvalue != tm2->u.lvalue) + return 1; + + /* TLS is optional... */ + tm1 = lws_abs_get_token(abs1->at_tokens, LTMI_PEER_LV_TLS_FLAGS); + tm2 = lws_abs_get_token(abs2->at_tokens, LTMI_PEER_LV_TLS_FLAGS); + + /* ... but both must have the same situation with it given or not... */ + if (!!tm1 != !!tm2) + return 1; + + /* if not using TLS, then that's enough to call it */ + if (!tm1) + return 0; + + /* ...and if there are tls flags, both must have the same tls flags */ + if (tm1->u.lvalue != tm2->u.lvalue) + return 1; + + /* ... and both must use the same client tls ctx / vhost */ + return abs1->vh != abs2->vh; +} + const lws_abs_transport_t lws_abs_transport_cli_raw_skt = { .name = "raw_skt", .alloc = sizeof(abs_raw_skt_priv_t), .create = lws_atcrs_create, .destroy = lws_atcrs_destroy, + .compare = lws_atcrs_compare, .tx = lws_atcrs_tx, -#if defined(LWS_WITHOUT_CLIENT) +#if !defined(LWS_WITH_CLIENT) .client_conn = NULL, #else .client_conn = lws_atcrs_client_conn, diff -Nru libwebsockets-3.2.1/lib/abstract/transports/unit-test.c libwebsockets-4.1.6/lib/abstract/transports/unit-test.c --- libwebsockets-3.2.1/lib/abstract/transports/unit-test.c 2019-12-18 14:45:31.000000000 +0000 +++ libwebsockets-4.1.6/lib/abstract/transports/unit-test.c 2020-12-01 17:40:26.000000000 +0000 @@ -1,31 +1,33 @@ -/* - * libwebsockets lib/abstract/transports/unit-test.c - * - * Copyright (C) 2019 Andy Green + /* + * libwebsockets - small server side websockets and web server implementation * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation: - * version 2.1 of the License. + * Copyright (C) 2010 - 2019 Andy Green * - * This library is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to + * deal in the Software without restriction, including without limitation the + * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or + * sell copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: * - * You should have received a copy of the GNU Lesser General Public - * License along with this library; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, - * MA 02110-1301 USA + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS + * IN THE SOFTWARE. * * An abstract transport that is useful for unit testing an abstract protocol. * It doesn't actually connect to anything, but checks the protocol's response * to provided canned packets from an array of test vectors. */ -#include "core/private.h" -#include "abstract/private.h" +#include "private-lib-core.h" +#include "private-lib-abstract.h" /* this is the transport priv instantiated at abs->ati */ @@ -33,7 +35,7 @@ char note[128]; struct lws_abs *abs; - lws_seq_t *seq; + struct lws_sequencer *seq; lws_unit_test_t *current_test; lws_unit_test_packet_t *expect; lws_unit_test_packet_test_cb result_cb; @@ -339,7 +341,7 @@ return 0; } -#if !defined(LWS_WITHOUT_CLIENT) +#if defined(LWS_WITH_CLIENT) static int lws_atcut_client_conn(const lws_abs_t *abs) { @@ -417,7 +419,7 @@ lws_atcut_create(lws_abs_t *ai) { abs_unit_test_priv_t *priv; - lws_seq_t *seq; + struct lws_sequencer *seq; lws_seq_info_t i; seq_priv_t *s; @@ -511,15 +513,22 @@ return dnames[in]; } +static int +lws_atcut_compare(lws_abs_t *abs1, lws_abs_t *abs2) +{ + return 0; +} + const lws_abs_transport_t lws_abs_transport_cli_unit_test = { .name = "unit_test", .alloc = sizeof(abs_unit_test_priv_t), .create = lws_atcut_create, .destroy = lws_atcut_destroy, + .compare = lws_atcut_compare, .tx = lws_atcut_tx, -#if defined(LWS_WITHOUT_CLIENT) +#if !defined(LWS_WITH_CLIENT) .client_conn = NULL, #else .client_conn = lws_atcut_client_conn, diff -Nru libwebsockets-3.2.1/lib/CMakeLists.txt libwebsockets-4.1.6/lib/CMakeLists.txt --- libwebsockets-3.2.1/lib/CMakeLists.txt 1970-01-01 00:00:00.000000000 +0000 +++ libwebsockets-4.1.6/lib/CMakeLists.txt 2020-12-01 17:40:26.000000000 +0000 @@ -0,0 +1,357 @@ +# +# libwebsockets - small server side websockets and web server implementation +# +# Copyright (C) 2010 - 2020 Andy Green +# +# Permission is hereby granted, free of charge, to any person obtaining a copy +# of this software and associated documentation files (the "Software"), to +# deal in the Software without restriction, including without limitation the +# rights to use, copy, modify, merge, publish, distribute, sublicense, and/or +# sell copies of the Software, and to permit persons to whom the Software is +# furnished to do so, subject to the following conditions: +# +# The above copyright notice and this permission notice shall be included in +# all copies or substantial portions of the Software. +# +# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING +# FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS +# IN THE SOFTWARE. +# + +include_directories(.) + +macro(add_subdir_include_dirs arg1) + add_subdirectory(${arg1}) + list(APPEND LWS_LIB_BUILD_INC_PATHS ${_CMAKE_INC_LIST}) +endmacro() + +set(LWS_LIB_INCLUDES "") + +# +# Plat specific build items +# + +if (LWS_PLAT_FREERTOS) + add_subdir_include_dirs(plat/freertos) + if (ESP_PLATFORM) + include_directories($ENV{IDF_PATH}/components/freertos/include + $ENV{IDF_PATH}/components/freertos/xtensa/include + $ENV{IDF_PATH}/components/xtensa/include + $ENV{IDF_PATH}/components/xtensa/esp32/include + $ENV{IDF_PATH}/components/esp_common/include + $ENV{IDF_PATH}/components/esp_timer/include + $ENV{IDF_PATH}/components/soc/include + $ENV{IDF_PATH}/components/soc/src/esp32/include + $ENV{IDF_PATH}/components/lwip/port/esp32/include + $ENV{IDF_PATH}/components/lwip/lwip/src/include + $ENV{IDF_PATH}/components/lwip/port/esp32/include + ${CMAKE_BINARY_DIR}/config + $ENV{IDF_PATH}/components/esp_rom/include + $ENV{IDF_PATH}/components/esp_system/include + $ENV{IDF_PATH}/components/lwip/include/apps/sntp + $ENV{IDF_PATH}/components/soc/soc/esp32/include + $ENV{IDF_PATH}/components/heap/include + $ENV{IDF_PATH}/components/mbedtls/mbedtls/include + $ENV{IDF_PATH}/components/mbedtls/port/include + $ENV{IDF_PATH}/components/esp_wifi/include + $ENV{IDF_PATH}/components/esp_event/include + $ENV{IDF_PATH}/components/esp_netif/include + $ENV{IDF_PATH}/components/esp_eth/include + $ENV{IDF_PATH}/components/driver/include + $ENV{IDF_PATH}/components/soc/soc/include + $ENV{IDF_PATH}/components/tcpip_adapter/include + $ENV{IDF_PATH}/components/lwip/include/apps + $ENV{IDF_PATH}/components/nvs_flash/include + $ENV{IDF_PATH}/components/esp32/include + $ENV{IDF_PATH}/components/spi_flash/include + $ENV{IDF_PATH}/components/mdns/include + $ENV{IDF_PATH}/components/lwip/lwip/src/include/lwip + $ENV{IDF_PATH}/components/lwip/lwip/src/include + $ENV{IDF_PATH}/components/lwip/lwip/src/include/lwip + $ENV{IDF_PATH}/components/newlib/platform_include ) + endif() + +else() + if (LWS_PLAT_OPTEE) + add_subdir_include_dirs(plat/optee) + else() + if (WIN32) + add_subdir_include_dirs(plat/windows) + else() + add_subdir_include_dirs(plat/unix) + endif() + endif() +endif() + +if (LIB_LIST) + set(CMAKE_REQUIRED_LIBRARIES ${LIB_LIST} ${CMAKE_REQUIRED_LIBRARIES}) +endif() + +if (LWS_WITH_ZLIB) + if (LWS_WITH_BUNDLED_ZLIB) + if (WIN32) + # it's trying to delete internal zlib entry + LIST(REMOVE_AT CMAKE_REQUIRED_LIBRARIES 0 ) + endif() + endif() +endif() + + +# ideally we want to use pipe2() + +CHECK_C_SOURCE_COMPILES("#define _GNU_SOURCE\n#include \nint main(void) {int fd[2];\n return pipe2(fd, 0);\n}\n" LWS_HAVE_PIPE2) + +# tcp keepalive needs this on linux to work practically... but it only exists +# after kernel 2.6.37 + +CHECK_C_SOURCE_COMPILES("#include \nint main(void) { return TCP_USER_TIMEOUT; }\n" LWS_HAVE_TCP_USER_TIMEOUT) + +if (LWS_WITH_TLS) + add_subdir_include_dirs(tls) +endif() + +# Generate the lws_config.h that includes all the private compilation settings. +configure_file( + "${PROJECT_SOURCE_DIR}/cmake/lws_config_private.h.in" + "${PROJECT_BINARY_DIR}/lws_config_private.h") + +add_subdir_include_dirs(core) +add_subdir_include_dirs(misc) +add_subdir_include_dirs(system) + +if (LWS_WITH_DRIVERS) + add_subdir_include_dirs(drivers) +endif() + +if (LWS_WITH_NETWORK) + add_subdir_include_dirs(core-net) + if (LWS_WITH_ABSTRACT) + add_subdir_include_dirs(abstract) + endif() + add_subdir_include_dirs(roles) +endif() + +if (LWS_WITH_JOSE) + add_subdir_include_dirs(jose) +endif() + +if (LWS_WITH_SECURE_STREAMS) + add_subdir_include_dirs(secure-streams) +endif() + +add_subdir_include_dirs(event-libs) + +if (LWS_WITH_STATIC) + if (LWS_STATIC_PIC) + set(CMAKE_POSITION_INDEPENDENT_CODE ON) + endif() + + add_library(websockets STATIC ${SOURCES})# ${HDR_PUBLIC}) + set_target_properties(websockets PROPERTIES LINKER_LANGUAGE C) + list(APPEND LWS_LIBRARIES websockets) + target_include_directories(websockets PRIVATE ${LWS_LIB_BUILD_INC_PATHS}) + + if (WIN32) + # Windows uses the same .lib ending for static libraries and shared + # library linker files, so rename the static library. + set_target_properties(websockets + PROPERTIES + OUTPUT_NAME websockets_static) + endif() + +endif() + +if (LWS_WITH_SHARED) + if (NOT RESOURCES) + set(RESOURCES "") + endif() + + add_library(websockets_shared SHARED ${SOURCES} ${RESOURCES})# ${HDR_PUBLIC}) + set_target_properties(websockets_shared PROPERTIES LINKER_LANGUAGE C) + list(APPEND LWS_LIBRARIES websockets_shared) + target_include_directories(websockets_shared PRIVATE ${LWS_LIB_BUILD_INC_PATHS}) + + # We want the shared lib to be named "libwebsockets" + # not "libwebsocket_shared". + set_target_properties(websockets_shared + PROPERTIES + OUTPUT_NAME websockets) + + if (WIN32) + # Compile as DLL (export function declarations) + set_property( + TARGET websockets_shared + PROPERTY COMPILE_DEFINITIONS + LWS_DLL + LWS_INTERNAL) + endif() + + if (APPLE) + set_property(TARGET websockets_shared PROPERTY MACOSX_RPATH YES) + endif() + + if (UNIX AND LWS_WITH_PLUGINS_API) + set (CMAKE_POSITION_INDEPENDENT_CODE ON) + if (NOT((${CMAKE_SYSTEM_NAME} MATCHES "FreeBSD") OR + (${CMAKE_SYSTEM_NAME} MATCHES "QNX"))) + if (LWS_WITH_SHARED) + target_link_libraries(websockets_shared dl) + endif() + endif() + endif() + +endif() + +# +# expose the library private include dirs to plugins, test apps etc that are +# part of the lib build but different targets +# + +if (LWS_WITH_SHARED) + get_target_property(LWS_LIB_INCLUDES websockets_shared INCLUDE_DIRECTORIES) +else() + get_target_property(LWS_LIB_INCLUDES websockets INCLUDE_DIRECTORIES) +endif() + + +# Set the so version of the lib. +# Equivalent to LDFLAGS=-version-info x:x:x + +if (CMAKE_COMPILER_IS_GNUCC OR CMAKE_COMPILER_IS_GNUCXX OR COMPILER_IS_CLANG) + foreach(lib ${LWS_LIBRARIES}) + set_target_properties(${lib} + PROPERTIES + SOVERSION ${SOVERSION}) + endforeach() +endif() + + +# Setup the linking for all libs. +foreach (lib ${LWS_LIBRARIES}) + target_link_libraries(${lib} ${LIB_LIST}) +endforeach() + +# +# These will be available to parent projects including libwebsockets +# using add_subdirectory() +# +set(LIBWEBSOCKETS_LIBRARIES ${LWS_LIBRARIES} CACHE STRING "Libwebsocket libraries") +if (LWS_WITH_STATIC) + set(LIBWEBSOCKETS_LIBRARIES_STATIC websockets CACHE STRING "Libwebsocket static library") +endif() +if (LWS_WITH_SHARED) + set(LIBWEBSOCKETS_LIBRARIES_SHARED websockets_shared CACHE STRING "Libwebsocket shared library") +endif() + +# Install libs and headers. +install(TARGETS ${LWS_LIBRARIES} + EXPORT LibwebsocketsTargets + LIBRARY DESTINATION "${LWS_INSTALL_LIB_DIR}${LIB_SUFFIX}" COMPONENT core + ARCHIVE DESTINATION "${LWS_INSTALL_LIB_DIR}${LIB_SUFFIX}" COMPONENT core + RUNTIME DESTINATION "${LWS_INSTALL_BIN_DIR}" COMPONENT core # Windows DLLs + PUBLIC_HEADER DESTINATION "${LWS_INSTALL_INCLUDE_DIR}" COMPONENT dev) + + #set(CPACK_COMPONENT_LIBRARIES_DISPLAY_NAME "Libraries" PARENT_SCOPE) +set(CPACK_COMPONENT_DEV_DISPLAY_NAME "Development files" PARENT_SCOPE) + + +if (UNIX) + +# figure out pkfcfg required libs here + +set(lws_requires "") +if (LWS_HAVE_LIBCAP) + if (NOT lws_requires STREQUAL "") + set(lws_requires "${lws_requires},libcap") + else() + set(lws_requires "libcap") + endif() +endif() + + +# Generate and install pkgconfig. +# (This is not indented, because the tabs will be part of the output) +file(WRITE "${PROJECT_BINARY_DIR}/libwebsockets.pc" +"prefix=\"${CMAKE_INSTALL_PREFIX}\" +exec_prefix=\${prefix} +libdir=\${exec_prefix}/lib${LIB_SUFFIX} +includedir=\${prefix}/include + +Name: libwebsockets +Description: Websockets server and client library +Version: ${CPACK_PACKAGE_VERSION_MAJOR}.${CPACK_PACKAGE_VERSION_MINOR}.${CPACK_PACKAGE_VERSION_PATCH} + +Libs: -L\${libdir} -lwebsockets +Cflags: -I\${includedir} +" +) +if (NOT ${lws_requires} STREQUAL "") + file(APPEND "${PROJECT_BINARY_DIR}/libwebsockets.pc" "Requires: ${lws_requires}") +endif() + + + install(FILES "${PROJECT_BINARY_DIR}/libwebsockets.pc" + DESTINATION lib${LIB_SUFFIX}/pkgconfig) + +file(WRITE "${PROJECT_BINARY_DIR}/libwebsockets_static.pc" +"prefix=\"${CMAKE_INSTALL_PREFIX}\" +exec_prefix=\${prefix} +libdir=\${exec_prefix}/lib${LIB_SUFFIX} +includedir=\${prefix}/include + +Name: libwebsockets_static +Description: Websockets server and client static library +Version: ${CPACK_PACKAGE_VERSION_MAJOR}.${CPACK_PACKAGE_VERSION_MINOR}.${CPACK_PACKAGE_VERSION_PATCH} + +Libs: -L\${libdir} -lwebsockets_static +Libs.private: +Cflags: -I\${includedir} +" +) + +if (NOT ${lws_requires} STREQUAL "") + file(APPEND "${PROJECT_BINARY_DIR}/libwebsockets_static.pc" "Requires: ${lws_requires}") +endif() + + + install(FILES "${PROJECT_BINARY_DIR}/libwebsockets_static.pc" + DESTINATION lib${LIB_SUFFIX}/pkgconfig) + +endif(UNIX) + + +# Keep explicit parent scope exports at end +# + +export_to_parent_intermediate() +if (DEFINED LWS_PLAT_UNIX) + set(LWS_PLAT_UNIX ${LWS_PLAT_UNIX} PARENT_SCOPE) + if (ILLUMOS) + add_definitions("-D__illumos__") + endif() +endif() +set(LWS_HAVE_MBEDTLS_NET_SOCKETS ${LWS_HAVE_MBEDTLS_NET_SOCKETS} PARENT_SCOPE) +set(TEST_SERVER_SSL_KEY "${TEST_SERVER_SSL_KEY}" PARENT_SCOPE) +set(TEST_SERVER_SSL_CERT "${TEST_SERVER_SSL_CERT}" PARENT_SCOPE) +set(TEST_SERVER_DATA ${TEST_SERVER_DATA} PARENT_SCOPE) +set(LWS_HAVE_PIPE2 ${LWS_HAVE_PIPE2} PARENT_SCOPE) +set(LWS_LIBRARIES ${LWS_LIBRARIES} PARENT_SCOPE) +if (DEFINED WIN32_HELPERS_PATH) + set(WIN32_HELPERS_PATH ${WIN32_HELPERS_PATH} PARENT_SCOPE) +endif() +if (DEFINED HDR_PRIVATE) +set(HDR_PRIVATE ${HDR_PRIVATE} PARENT_SCOPE) +endif() +if (DEFINED ZLIB_FOUND) + set(ZLIB_FOUND ${ZLIB_FOUND} PARENT_SCOPE) +endif() +if (DEFINED LIB_LIST_AT_END) +set(LIB_LIST_AT_END ${LIB_LIST_AT_END} PARENT_SCOPE) +endif() +set(USE_WOLFSSL ${USE_WOLFSSL} PARENT_SCOPE) +set(LWS_DEPS_LIB_PATHS ${LWS_DEPS_LIB_PATHS} PARENT_SCOPE) + diff -Nru libwebsockets-3.2.1/lib/core/alloc.c libwebsockets-4.1.6/lib/core/alloc.c --- libwebsockets-3.2.1/lib/core/alloc.c 2019-12-18 14:45:31.000000000 +0000 +++ libwebsockets-4.1.6/lib/core/alloc.c 2020-12-01 17:40:26.000000000 +0000 @@ -1,4 +1,28 @@ -#include "core/private.h" +/* + * libwebsockets - small server side websockets and web server implementation + * + * Copyright (C) 2010 - 2020 Andy Green + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to + * deal in the Software without restriction, including without limitation the + * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or + * sell copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS + * IN THE SOFTWARE. + */ + +#include "private-lib-core.h" #if defined(LWS_HAVE_MALLOC_USABLE_SIZE) @@ -86,8 +110,8 @@ void *v; if (size) { -#if defined(LWS_WITH_ESP32) - lwsl_notice("%s: size %lu: %s (free heap %d)\n", __func__, +#if defined(LWS_PLAT_FREERTOS) + lwsl_debug("%s: size %lu: %s (free heap %d)\n", __func__, #if defined(LWS_AMAZON_RTOS) (unsigned long)size, reason, (unsigned int)xPortGetFreeHeapSize() - (int)size); #else diff -Nru libwebsockets-3.2.1/lib/core/buflist.c libwebsockets-4.1.6/lib/core/buflist.c --- libwebsockets-3.2.1/lib/core/buflist.c 2019-12-18 14:45:31.000000000 +0000 +++ libwebsockets-4.1.6/lib/core/buflist.c 2020-12-01 17:40:26.000000000 +0000 @@ -1,25 +1,28 @@ /* * libwebsockets - small server side websockets and web server implementation * - * Copyright (C) 2010-2019 Andy Green + * Copyright (C) 2010 - 2019 Andy Green * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation: - * version 2.1 of the License. + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to + * deal in the Software without restriction, including without limitation the + * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or + * sell copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: * - * This library is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. * - * You should have received a copy of the GNU Lesser General Public - * License along with this library; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, - * MA 02110-1301 USA + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS + * IN THE SOFTWARE. */ -#include "core/private.h" +#include "private-lib-core.h" #ifdef LWS_HAVE_SYS_TYPES_H #include @@ -56,7 +59,8 @@ lwsl_info("%s: len %u first %d %p\n", __func__, (unsigned int)len, first, p); - nbuf = (struct lws_buflist *)lws_malloc(sizeof(**head) + len, __func__); + nbuf = (struct lws_buflist *)lws_malloc(sizeof(struct lws_buflist) + + len + LWS_PRE + 1, __func__); if (!nbuf) { lwsl_err("%s: OOM\n", __func__); return -1; @@ -66,7 +70,8 @@ nbuf->pos = 0; nbuf->next = NULL; - p = (void *)nbuf->buf; + /* whoever consumes this might need LWS_PRE from the start... */ + p = (uint8_t *)nbuf + sizeof(*nbuf) + LWS_PRE; memcpy(p, buf, len); *head = nbuf; @@ -82,6 +87,7 @@ assert(*head); *head = old->next; old->next = NULL; + old->pos = old->len = 0; lws_free(old); return !*head; /* returns 1 if last segment just destroyed */ @@ -105,59 +111,105 @@ size_t lws_buflist_next_segment_len(struct lws_buflist **head, uint8_t **buf) { - if (!*head) { - if (buf) - *buf = NULL; + struct lws_buflist *b = (*head); - return 0; - } + if (buf) + *buf = NULL; - if (!(*head)->len && (*head)->next) - lws_buflist_destroy_segment(head); + if (!b) + return 0; /* there is no next segment len */ - if (!*head) { - if (buf) - *buf = NULL; + if (!b->len && b->next) + if (lws_buflist_destroy_segment(head)) + return 0; - return 0; - } + b = (*head); + if (!b) + return 0; /* there is no next segment len */ - assert((*head)->pos < (*head)->len); + assert(b->pos < b->len); if (buf) - *buf = (*head)->buf + (*head)->pos; + *buf = ((uint8_t *)b) + sizeof(*b) + b->pos + LWS_PRE; - return (*head)->len - (*head)->pos; + return b->len - b->pos; } -int +size_t lws_buflist_use_segment(struct lws_buflist **head, size_t len) { - assert(*head); + struct lws_buflist *b = (*head); + + assert(b); assert(len); - assert((*head)->pos + len <= (*head)->len); + assert(b->pos + len <= b->len); + + b->pos = b->pos + (size_t)len; - (*head)->pos += len; - if ((*head)->pos == (*head)->len) - lws_buflist_destroy_segment(head); + assert(b->pos <= b->len); - if (!*head) + if (b->pos < b->len) + return (int)(b->len - b->pos); + + if (lws_buflist_destroy_segment(head)) + /* last segment was just destroyed */ return 0; - return (int)((*head)->len - (*head)->pos); + return lws_buflist_next_segment_len(head, NULL); +} + +size_t +lws_buflist_total_len(struct lws_buflist **head) +{ + struct lws_buflist *p = *head; + size_t size = 0; + + while (p) { + size += p->len; + p = p->next; + } + + return size; } +int +lws_buflist_linear_copy(struct lws_buflist **head, size_t ofs, uint8_t *buf, + size_t len) +{ + struct lws_buflist *p = *head; + uint8_t *obuf = buf; + size_t s; + + while (p && len) { + if (ofs < p->len) { + s = p->len - ofs; + if (s > len) + s = len; + memcpy(buf, ((uint8_t *)&p[1]) + LWS_PRE + ofs, s); + len -= s; + buf += s; + ofs = 0; + } else + ofs -= p->len; + p = p->next; + } + + return lws_ptr_diff(buf, obuf); +} + +#if defined(_DEBUG) void -lws_buflist_describe(struct lws_buflist **head, void *id) +lws_buflist_describe(struct lws_buflist **head, void *id, const char *reason) { struct lws_buflist *old; int n = 0; if (*head == NULL) - lwsl_notice("%p: buflist empty\n", id); + lwsl_notice("%p: %s: buflist empty\n", id, reason); while (*head) { - lwsl_notice("%p: %d: %llu / %llu (%llu left)\n", id, n, + lwsl_notice("%p: %s: %d: %llu / %llu (%llu left)\n", id, + reason, n, (unsigned long long)(*head)->pos, (unsigned long long)(*head)->len, (unsigned long long)(*head)->len - (*head)->pos); @@ -170,3 +222,4 @@ n++; } } +#endif diff -Nru libwebsockets-3.2.1/lib/core/CMakeLists.txt libwebsockets-4.1.6/lib/core/CMakeLists.txt --- libwebsockets-3.2.1/lib/core/CMakeLists.txt 1970-01-01 00:00:00.000000000 +0000 +++ libwebsockets-4.1.6/lib/core/CMakeLists.txt 2020-12-01 17:40:26.000000000 +0000 @@ -0,0 +1,41 @@ +# +# libwebsockets - small server side websockets and web server implementation +# +# Copyright (C) 2010 - 2020 Andy Green +# +# Permission is hereby granted, free of charge, to any person obtaining a copy +# of this software and associated documentation files (the "Software"), to +# deal in the Software without restriction, including without limitation the +# rights to use, copy, modify, merge, publish, distribute, sublicense, and/or +# sell copies of the Software, and to permit persons to whom the Software is +# furnished to do so, subject to the following conditions: +# +# The above copyright notice and this permission notice shall be included in +# all copies or substantial portions of the Software. +# +# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING +# FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS +# IN THE SOFTWARE. +# + +include_directories(.) + +list(APPEND SOURCES + core/alloc.c + core/buflist.c + core/context.c + core/lws_dll2.c + core/libwebsockets.c + core/logs.c +) + +if (LWS_WITH_FILE_OPS) + list(APPEND SOURCES core/vfs.c) +endif() + +exports_to_parent_scope() + diff -Nru libwebsockets-3.2.1/lib/core/context.c libwebsockets-4.1.6/lib/core/context.c --- libwebsockets-3.2.1/lib/core/context.c 2019-12-18 14:45:31.000000000 +0000 +++ libwebsockets-4.1.6/lib/core/context.c 2020-12-01 17:40:26.000000000 +0000 @@ -1,32 +1,44 @@ /* * libwebsockets - small server side websockets and web server implementation * - * Copyright (C) 2010-2019 Andy Green + * Copyright (C) 2010 - 2020 Andy Green * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation: - * version 2.1 of the License. + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to + * deal in the Software without restriction, including without limitation the + * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or + * sell copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: * - * This library is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. * - * You should have received a copy of the GNU Lesser General Public - * License along with this library; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, - * MA 02110-1301 USA + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS + * IN THE SOFTWARE. */ -#include "core/private.h" +#include "private-lib-core.h" #ifndef LWS_BUILD_HASH #define LWS_BUILD_HASH "unknown-build-hash" #endif +static const char *library_version = LWS_LIBRARY_VERSION; -static const char *library_version = LWS_LIBRARY_VERSION " " LWS_BUILD_HASH; +#if defined(LWS_HAVE_SYS_RESOURCE_H) +/* for setrlimit */ +#include +#endif + +#if defined(LWS_WITH_NETWORK) +/* in ms */ +static uint32_t default_backoff_table[] = { 1000, 3000, 9000, 17000 }; +#endif /** * lws_get_library_version: get version and git hash library built from @@ -35,7 +47,7 @@ * representing the library version followed by the git head hash it * was built from */ -LWS_VISIBLE const char * +const char * lws_get_library_version(void) { return library_version; @@ -50,7 +62,8 @@ lws_stats_log_dump(pt->context); - __lws_sul_insert(&pt->pt_sul_owner, &pt->sul_stats, 10 * LWS_US_PER_SEC); + __lws_sul_insert_us(&pt->pt_sul_owner[LWSSULLI_MISS_IF_SUSPENDED], + &pt->sul_stats, 10 * LWS_US_PER_SEC); } #endif #if defined(LWS_WITH_PEER_LIMITS) @@ -62,71 +75,543 @@ lws_peer_cull_peer_wait_list(pt->context); - __lws_sul_insert(&pt->pt_sul_owner, &pt->sul_peer_limits, 10 * LWS_US_PER_SEC); + __lws_sul_insert_us(&pt->pt_sul_owner[LWSSULLI_MISS_IF_SUSPENDED], + &pt->sul_peer_limits, 10 * LWS_US_PER_SEC); +} +#endif + +#if defined(LWS_WITH_NETWORK) + +#if defined(LWS_WITH_SYS_STATE) + +static const char * system_state_names[] = { + "undef", + "CONTEXT_CREATED", + "INITIALIZED", + "IFACE_COLDPLUG", + "DHCP", + "CPD_PRE_TIME", + "TIME_VALID", + "CPD_POST_TIME", + "POLICY_VALID", + "REGISTERED", + "AUTH1", + "AUTH2", + "OPERATIONAL", + "POLICY_INVALID" +}; + + +/* + * Handle provoking protocol init when we pass through the right system state + */ + +static int +lws_state_notify_protocol_init(struct lws_state_manager *mgr, + struct lws_state_notify_link *link, int current, + int target) +{ + struct lws_context *context = lws_container_of(mgr, struct lws_context, + mgr_system); +#if defined(LWS_WITH_SECURE_STREAMS) && defined(LWS_WITH_SECURE_STREAMS_SYS_AUTH_API_AMAZON_COM) + lws_system_blob_t *ab0, *ab1; +#endif + int n; + + /* + * Deal with any attachments that were waiting for the right state + * to come along + */ + + for (n = 0; n < context->count_threads; n++) + lws_system_do_attach(&context->pt[n]); + +#if defined(LWS_WITH_SYS_DHCP_CLIENT) + if (target == LWS_SYSTATE_DHCP) { + /* + * Don't let it past here until at least one iface has been + * configured for operation with DHCP + */ + + if (!lws_dhcpc_status(context, NULL)) + return 1; + } +#endif + +#if defined(LWS_WITH_SYS_NTPCLIENT) + if (target == LWS_SYSTATE_TIME_VALID && + lws_now_secs() < 1594017754) /* 06:42 Mon Jul 6 2020 UTC */ { + lws_ntpc_trigger(context); + + return 1; + } +#endif + +#if defined(LWS_WITH_SECURE_STREAMS) && defined(LWS_WITH_SECURE_STREAMS_SYS_AUTH_API_AMAZON_COM) + /* + * Skip this if we are running something without the policy for it + * + * If root token is empty, skip too. + */ + + ab0 = lws_system_get_blob(context, LWS_SYSBLOB_TYPE_AUTH, 0); + ab1 = lws_system_get_blob(context, LWS_SYSBLOB_TYPE_AUTH, 1); + + if (target == LWS_SYSTATE_AUTH1 && + context->pss_policies && ab0 && ab1 && + !lws_system_blob_get_size(ab0) && + lws_system_blob_get_size(ab1)) { + lwsl_info("%s: AUTH1 state triggering api.amazon.com auth\n", __func__); + /* + * Start trying to acquire it if it's not already in progress + * returns nonzero if we determine it's not needed + */ + if (!lws_ss_sys_auth_api_amazon_com(context)) + return 1; + } +#endif + +#if defined(LWS_WITH_SECURE_STREAMS) +#if defined(LWS_WITH_DRIVERS) + /* + * See if we should do the SS Captive Portal Detection + */ + if (target == LWS_SYSTATE_CPD_PRE_TIME) { + if (lws_system_cpd_state_get(context) == LWS_CPD_INTERNET_OK) + return 0; /* allow it */ + + /* + * Don't allow it to move past here until we get an IP and + * CPD passes, driven by SMD + */ + + return 1; + } +#endif + +#if !defined(LWS_WITH_SECURE_STREAMS_STATIC_POLICY_ONLY) + /* + * Skip this if we are running something without the policy for it + */ + if (target == LWS_SYSTATE_POLICY_VALID && + context->pss_policies && !context->policy_updated) { + /* + * Start trying to acquire it if it's not already in progress + * returns nonzero if we determine it's not needed + */ + if (!lws_ss_sys_fetch_policy(context)) + return 1; + } +#endif +#endif + + /* protocol part */ + + if (context->protocol_init_done) + return 0; + + if (target != LWS_SYSTATE_POLICY_VALID) + return 0; + + lwsl_info("%s: doing protocol init on POLICY_VALID\n", __func__); + + return lws_protocol_init(context); +} + +static void +lws_context_creation_completion_cb(lws_sorted_usec_list_t *sul) +{ + struct lws_context *context = lws_container_of(sul, struct lws_context, + sul_system_state); + + /* if nothing is there to intercept anything, go all the way */ + lws_state_transition_steps(&context->mgr_system, + LWS_SYSTATE_OPERATIONAL); +} +#endif /* WITH_SYS_STATE */ + +#if defined(LWS_WITH_SYS_SMD) +static int +lws_system_smd_cb(void *opaque, lws_smd_class_t _class, lws_usec_t timestamp, + void *buf, size_t len) +{ + struct lws_context *cx = (struct lws_context *)opaque; + + if (_class != LWSSMDCL_NETWORK) + return 0; + + /* something external requested CPD check */ + + if (!lws_json_simple_strcmp(buf, len, "\"trigger\":", "cpdcheck")) + lws_system_cpd_start(cx); + else + /* + * IP acquisition on any interface triggers captive portal + * check on default route + */ + if (!lws_json_simple_strcmp(buf, len, "\"type\":", "ipacq")) + lws_system_cpd_start(cx); + +#if defined(LWS_WITH_SYS_NTPCLIENT) + /* + * Captive portal detect showing internet workable triggers NTP Client + */ + if (!lws_json_simple_strcmp(buf, len, "\"type\":", "cps") && + !lws_json_simple_strcmp(buf, len, "\"result\":", "OK") && + lws_now_secs() < 1594017754) /* 06:42 Mon Jul 6 2020 UTC */ + lws_ntpc_trigger(cx); +#endif + +#if defined(LWS_WITH_SYS_DHCP_CLIENT) + /* + * Any network interface linkup triggers DHCP + */ + if (!lws_json_simple_strcmp(buf, len, "\"type\":", "linkup")) + lws_ntpc_trigger(cx); + +#endif + +#if defined(LWS_WITH_DRIVERS) && defined(LWS_WITH_NETWORK) + lws_netdev_smd_cb(opaque, _class, timestamp, buf, len); +#endif + + return 0; } #endif -LWS_VISIBLE struct lws_context * + +#endif /* NETWORK */ + +#if !defined(LWS_WITH_NO_LOGS) + +static const char * const opts_str = +#if defined(LWS_WITH_NETWORK) + "NET " +#else + "NoNET " +#endif +#if defined(LWS_WITH_CLIENT) + "CLI " +#endif +#if defined(LWS_WITH_SERVER) + "SRV " +#endif +#if defined(LWS_ROLE_H1) + "H1 " +#endif +#if defined(LWS_ROLE_H2) + "H2 " +#endif +#if defined(LWS_ROLE_WS) + "WS " +#endif +#if defined(LWS_ROLE_MQTT) + "MQTT " +#endif +#if defined(LWS_WITH_SECURE_STREAMS) && !defined(LWS_WITH_SECURE_STREAMS_STATIC_POLICY_ONLY) + "SS-JSON-POL " +#endif +#if defined(LWS_WITH_SECURE_STREAMS) && defined(LWS_WITH_SECURE_STREAMS_STATIC_POLICY_ONLY) + "SS-STATIC-POL " +#endif +#if defined(LWS_WITH_SECURE_STREAMS_PROXY_API) + "SSPROX " +#endif +#if defined(LWS_WITH_SYS_ASYNC_DNS) + "ASYNC_DNS " +#endif +#if defined(LWS_WITH_SYS_NTPCLIENT) + "NTPCLIENT " +#endif +#if defined(LWS_WITH_SYS_DHCP_CLIENT) + "DHCP_CLIENT " +#endif +; + +#endif + +#if defined(LWS_WITH_EVLIB_PLUGINS) && defined(LWS_WITH_EVENT_LIBS) +static const struct lws_evlib_map { + uint64_t flag; + const char *name; +} map[] = { + { LWS_SERVER_OPTION_LIBUV, "evlib_uv" }, + { LWS_SERVER_OPTION_LIBEVENT, "evlib_event" }, + { LWS_SERVER_OPTION_GLIB, "evlib_glib" }, + { LWS_SERVER_OPTION_LIBEV, "evlib_ev" }, +}; +static const char * const dlist[] = { + LWS_INSTALL_LIBDIR, + NULL +}; +#endif + +struct lws_context * lws_create_context(const struct lws_context_creation_info *info) { struct lws_context *context = NULL; +#if !defined(LWS_WITH_NO_LOGS) + const char *s = "IPv6-absent"; +#endif +#if defined(LWS_WITH_FILE_OPS) struct lws_plat_file_ops *prev; +#endif #ifndef LWS_NO_DAEMONIZE pid_t pid_daemon = get_daemonize_pid(); #endif #if defined(LWS_WITH_NETWORK) - int n; + int count_threads = 1; + uint8_t *u; #endif #if defined(__ANDROID__) struct rlimit rt; #endif + size_t +#if defined(LWS_PLAT_FREERTOS) + /* smaller default, can set in info->pt_serv_buf_size */ + s1 = 2048, +#else + s1 = 4096, +#endif + size = sizeof(struct lws_context); + int n, lpf = info->fd_limit_per_thread; + const lws_plugin_evlib_t *plev = NULL; +#if defined(LWS_WITH_EVLIB_PLUGINS) && defined(LWS_WITH_EVENT_LIBS) + struct lws_plugin *evlib_plugin_list = NULL; +#endif +#if defined(LWS_WITH_LIBUV) + char fatal_exit_defer = 0; +#endif + + if (lpf) { + lpf+= 2; +#if defined(LWS_WITH_SYS_ASYNC_DNS) + lpf++; +#endif +#if defined(LWS_WITH_SYS_NTPCLIENT) + lpf++; +#endif +#if defined(LWS_WITH_SYS_DHCP_CLIENT) + lpf++; +#endif + } - lwsl_info("Initial logging level %d\n", log_level); - lwsl_info("Libwebsockets version: %s\n", library_version); + lwsl_notice("LWS: %s, loglevel %d\n", library_version, log_level); -#ifdef LWS_WITH_IPV6 +#if defined(LWS_WITH_IPV6) && !defined(LWS_WITH_NO_LOGS) if (!lws_check_opt(info->options, LWS_SERVER_OPTION_DISABLE_IPV6)) - lwsl_info("IPV6 compiled in and enabled\n"); + s = "IPV6-on"; else - lwsl_info("IPV6 compiled in but disabled\n"); -#else - lwsl_info("IPV6 not compiled in\n"); + s = "IPV6-off"; #endif - lwsl_info(" LWS_DEF_HEADER_LEN : %u\n", LWS_DEF_HEADER_LEN); - lwsl_info(" LWS_MAX_PROTOCOLS : %u\n", LWS_MAX_PROTOCOLS); - lwsl_info(" LWS_MAX_SMP : %u\n", LWS_MAX_SMP); - lwsl_info(" sizeof (*info) : %ld\n", (long)sizeof(*info)); #if defined(LWS_WITH_STATS) lwsl_info(" LWS_WITH_STATS : on\n"); #endif - lwsl_info(" SYSTEM_RANDOM_FILEPATH: '%s'\n", SYSTEM_RANDOM_FILEPATH); -#if defined(LWS_WITH_HTTP2) - lwsl_info(" HTTP2 support : available\n"); -#else - lwsl_info(" HTTP2 support : not configured\n"); -#endif + + lwsl_notice("%s%s\n", opts_str, s); + if (lws_plat_context_early_init()) return NULL; - context = lws_zalloc(sizeof(struct lws_context), "context"); +#if defined(LWS_WITH_NETWORK) + if (info->count_threads) + count_threads = info->count_threads; + + if (count_threads > LWS_MAX_SMP) + count_threads = LWS_MAX_SMP; + + if (info->pt_serv_buf_size) + s1 = info->pt_serv_buf_size; + + /* pt fakewsi and the pt serv buf allocations ride after the context */ + size += count_threads * s1; +#if !defined(LWS_PLAT_FREERTOS) + size += (count_threads * sizeof(struct lws)); +#endif +#endif /* network */ + +#if defined(LWS_WITH_POLL) + { + extern const lws_plugin_evlib_t evlib_poll; + plev = &evlib_poll; + } +#endif + +#if defined(LWS_WITH_EVLIB_PLUGINS) && defined(LWS_WITH_EVENT_LIBS) + + /* + * New style dynamically loaded event lib support + * + * We have to pick and load the event lib plugin before we allocate + * the context object, so we can overallocate it correctly + */ + + lwsl_info("%s: ev lib path %s\n", __func__, LWS_INSTALL_LIBDIR); + + for (n = 0; n < (int)LWS_ARRAY_SIZE(map); n++) { + if (!lws_check_opt(info->options, map[n].flag)) + continue; + + if (lws_plugins_init(&evlib_plugin_list, + dlist, "lws_evlib_plugin", + map[n].name, NULL, NULL)) { + lwsl_err("%s: failed to load %s\n", __func__, + map[n].name); + goto bail; + } + +#if defined(LWS_WITH_LIBUV) + if (!n) /* libuv */ + fatal_exit_defer = !!info->foreign_loops; +#endif + + if (!evlib_plugin_list) { + lwsl_err("%s: unable to load evlib plugin %s\n", + __func__, map[n].name); + + goto bail; + } + plev = (const lws_plugin_evlib_t *)evlib_plugin_list->hdr; + break; + } +#else +#if defined(LWS_WITH_EVENT_LIBS) + /* + * set the context event loops ops struct + * + * after this, all event_loop actions use the generic ops + */ + + /* + * oldstyle built-in event lib support + * + * We have composed them into the libwebsockets lib itself, we can + * just pick the ops we want and done + */ + +#if defined(LWS_WITH_LIBUV) + if (lws_check_opt(info->options, LWS_SERVER_OPTION_LIBUV)) { + extern const lws_plugin_evlib_t evlib_uv; + plev = &evlib_uv; + fatal_exit_defer = !!info->foreign_loops; + } +#endif + +#if defined(LWS_WITH_LIBEVENT) + if (lws_check_opt(info->options, LWS_SERVER_OPTION_LIBEVENT)) { + extern const lws_plugin_evlib_t evlib_event; + plev = &evlib_event; + } +#endif + +#if defined(LWS_WITH_GLIB) + if (lws_check_opt(info->options, LWS_SERVER_OPTION_GLIB)) { + extern const lws_plugin_evlib_t evlib_glib; + plev = &evlib_glib; + } +#endif + +#if defined(LWS_WITH_LIBEV) + if (lws_check_opt(info->options, LWS_SERVER_OPTION_LIBEV)) { + extern const lws_plugin_evlib_t evlib_ev; + plev = &evlib_ev; + } +#endif + +#endif /* with event libs */ + +#endif /* not with ev plugins */ + + if (!plev) + goto fail_event_libs; + +#if defined(LWS_WITH_NETWORK) + size += (size_t)plev->ops->evlib_size_ctx /* the ctx evlib priv */ + + (count_threads * (size_t)plev->ops->evlib_size_pt) /* the pt evlib priv */; + + lwsl_info("Event loop: %s\n", plev->ops->name); +#endif + + context = lws_zalloc(size, "context"); if (!context) { lwsl_err("No memory for websocket context\n"); return NULL; } +#if defined(LWS_WITH_NETWORK) + context->event_loop_ops = plev->ops; +#endif +#if defined(LWS_WITH_EVENT_LIBS) + /* at the very end */ + context->evlib_ctx = (uint8_t *)context + size - + plev->ops->evlib_size_ctx; +#endif +#if defined(LWS_WITH_EVLIB_PLUGINS) && defined(LWS_WITH_EVENT_LIBS) + context->evlib_plugin_list = evlib_plugin_list; +#endif + +#if !defined(LWS_PLAT_FREERTOS) context->uid = info->uid; context->gid = info->gid; context->username = info->username; context->groupname = info->groupname; +#endif context->system_ops = info->system_ops; + context->pt_serv_buf_size = (unsigned int)s1; + +#if defined(LWS_WITH_UDP) + context->udp_loss_sim_tx_pc = info->udp_loss_sim_tx_pc; + context->udp_loss_sim_rx_pc = info->udp_loss_sim_rx_pc; + + if (context->udp_loss_sim_tx_pc || context->udp_loss_sim_rx_pc) + lwsl_warn("%s: simulating udp loss tx: %d%%, rx: %d%%\n", + __func__, context->udp_loss_sim_tx_pc, + context->udp_loss_sim_rx_pc); +#endif + +#if defined(LWS_WITH_SECURE_STREAMS_STATIC_POLICY_ONLY) + /* directly use the user-provided policy object list */ + context->pss_policies = info->pss_policies; +#endif + +#if defined(LWS_WITH_SECURE_STREAMS_PROXY_API) + context->ss_proxy_bind = info->ss_proxy_bind; + context->ss_proxy_port = info->ss_proxy_port; + context->ss_proxy_address = info->ss_proxy_address; + if (context->ss_proxy_bind && context->ss_proxy_address) + lwsl_notice("%s: using ss proxy bind '%s', port %d, ads '%s'\n", + __func__, context->ss_proxy_bind, context->ss_proxy_port, + context->ss_proxy_address); +#endif + +#if defined(LWS_WITH_NETWORK) + context->count_threads = count_threads; +#if defined(LWS_WITH_DETAILED_LATENCY) + context->detailed_latency_cb = info->detailed_latency_cb; + context->detailed_latency_filepath = info->detailed_latency_filepath; + context->latencies_fd = -1; +#endif +#if defined(LWS_ROLE_WS) && defined(LWS_WITHOUT_EXTENSIONS) + if (info->extensions) + lwsl_warn("%s: LWS_WITHOUT_EXTENSIONS but extensions ptr set\n", __func__); +#endif +#endif /* network */ + +#if defined(LWS_WITH_SECURE_STREAMS) +#if !defined(LWS_WITH_SECURE_STREAMS_STATIC_POLICY_ONLY) + context->pss_policies_json = info->pss_policies_json; +#endif +#if defined(LWS_WITH_SSPLUGINS) + context->pss_plugins = info->pss_plugins; +#endif +#endif /* if he gave us names, set the uid / gid */ if (lws_plat_drop_app_privileges(context, 0)) goto bail; -lwsl_info("context created\n"); #if defined(LWS_WITH_TLS) && defined(LWS_WITH_NETWORK) #if defined(LWS_WITH_MBEDTLS) context->tls_ops = &tls_ops_mbedtls; @@ -135,23 +620,19 @@ #endif #endif - if (info->pt_serv_buf_size) - context->pt_serv_buf_size = info->pt_serv_buf_size; - else - context->pt_serv_buf_size = 4096; - -#if defined(LWS_ROLE_H2) - role_ops_h2.init_context(context, info); -#endif - #if LWS_MAX_SMP > 1 lws_mutex_refcount_init(&context->mr); #endif -#if defined(LWS_WITH_ESP32) +#if defined(LWS_PLAT_FREERTOS) +#if defined(LWS_AMAZON_RTOS) + context->last_free_heap = xPortGetFreeHeapSize(); +#else context->last_free_heap = esp_get_free_heap_size(); #endif +#endif +#if defined(LWS_WITH_FILE_OPS) /* default to just the platform fops implementation */ context->fops_platform.LWS_FOP_OPEN = _lws_plat_file_open; @@ -182,8 +663,11 @@ /* if user provided fops, tack them on the end of the list */ if (info->fops) prev->next = info->fops; +#endif +#if defined(LWS_WITH_SERVER) context->reject_service_keywords = info->reject_service_keywords; +#endif if (info->external_baggage_free_on_destroy) context->external_baggage_free_on_destroy = info->external_baggage_free_on_destroy; @@ -192,11 +676,27 @@ #endif context->pcontext_finalize = info->pcontext; +#if defined(LWS_WITH_TLS) && defined(LWS_WITH_NETWORK) context->simultaneous_ssl_restriction = info->simultaneous_ssl_restriction; +#endif context->options = info->options; +#if !defined(LWS_PLAT_FREERTOS) && !defined(LWS_PLAT_OPTEE) && !defined(WIN32) + /* + * If asked, try to set the rlimit / ulimit for process sockets / files. + * We read the effective limit in a moment, so we will find out the + * real limit according to system constraints then. + */ + if (info->rlimit_nofile) { + struct rlimit rl; + + rl.rlim_cur = rl.rlim_max = info->rlimit_nofile; + setrlimit(RLIMIT_NOFILE, &rl); + } +#endif + #ifndef LWS_NO_DAEMONIZE if (pid_daemon) { context->started_with_parent = pid_daemon; @@ -204,35 +704,37 @@ } #endif #if defined(__ANDROID__) - n = getrlimit(RLIMIT_NOFILE, &rt); - if (n == -1) { - lwsl_err("Get RLIMIT_NOFILE failed!\n"); + n = getrlimit(RLIMIT_NOFILE, &rt); + if (n == -1) { + lwsl_err("Get RLIMIT_NOFILE failed!\n"); - return NULL; - } - context->max_fds = rt.rlim_cur; + goto free_context_fail; + } + context->max_fds = rt.rlim_cur; #else -#if defined(WIN32) || defined(_WIN32) || defined(LWS_AMAZON_RTOS) - context->max_fds = getdtablesize(); +#if defined(WIN32) || defined(_WIN32) || defined(LWS_AMAZON_RTOS) || defined(LWS_ESP_PLATFORM) + context->max_fds = getdtablesize(); #else - context->max_fds = sysconf(_SC_OPEN_MAX); -#endif -#endif - - if (context->max_fds < 0) { - lwsl_err("%s: problem getting process max files\n", - __func__); + { + long l = sysconf(_SC_OPEN_MAX); - return NULL; - } + context->max_fds = 2560; - if (info->count_threads) - context->count_threads = info->count_threads; - else - context->count_threads = 1; + if (l > 10000000) + lwsl_warn("%s: unreasonable ulimit -n workaround\n", + __func__); + else + if (l != -1l) + context->max_fds = (int)l; + } +#endif + if (context->max_fds < 0) { + lwsl_err("%s: problem getting process max files\n", + __func__); - if (context->count_threads > LWS_MAX_SMP) - context->count_threads = LWS_MAX_SMP; + goto free_context_fail; + } +#endif /* * deal with any max_fds override, if it's reducing (setting it to @@ -240,7 +742,7 @@ * figure out what if this is something it can deal with. */ if (info->fd_limit_per_thread) { - int mf = info->fd_limit_per_thread * context->count_threads; + int mf = lpf * context->count_threads; if (mf < context->max_fds) { context->max_fds_unrelated_to_ulimit = 1; @@ -248,46 +750,10 @@ } } - context->token_limits = info->token_limits; - #if defined(LWS_WITH_NETWORK) - - /* - * set the context event loops ops struct - * - * after this, all event_loop actions use the generic ops - */ - -#if defined(LWS_WITH_POLL) - context->event_loop_ops = &event_loop_ops_poll; -#endif - - if (lws_check_opt(context->options, LWS_SERVER_OPTION_LIBUV)) -#if defined(LWS_WITH_LIBUV) - context->event_loop_ops = &event_loop_ops_uv; -#else - goto fail_event_libs; -#endif - - if (lws_check_opt(context->options, LWS_SERVER_OPTION_LIBEV)) -#if defined(LWS_WITH_LIBEV) - context->event_loop_ops = &event_loop_ops_ev; -#else - goto fail_event_libs; -#endif - - if (lws_check_opt(context->options, LWS_SERVER_OPTION_LIBEVENT)) -#if defined(LWS_WITH_LIBEVENT) - context->event_loop_ops = &event_loop_ops_event; -#else - goto fail_event_libs; + context->token_limits = info->token_limits; #endif - if (!context->event_loop_ops) - goto fail_event_libs; - - lwsl_info("Using event loop: %s\n", context->event_loop_ops->name); -#endif #if defined(LWS_WITH_TLS) && defined(LWS_WITH_NETWORK) time(&context->tls.last_cert_check_s); @@ -311,18 +777,15 @@ context->tls.alpn_default = context->tls.alpn_discovered; } - lwsl_info("Default ALPN advertisment: %s\n", context->tls.alpn_default); #endif - +#if defined(LWS_WITH_NETWORK) if (info->timeout_secs) context->timeout_secs = info->timeout_secs; else - context->timeout_secs = AWAITING_TIMEOUT; - - context->ws_ping_pong_interval = info->ws_ping_pong_interval; - - lwsl_info(" default timeout (secs): %u\n", context->timeout_secs); +#endif + context->timeout_secs = 5; +#if defined(LWS_ROLE_H1) || defined(LWS_ROLE_H2) if (info->max_http_header_data) context->max_http_header_data = info->max_http_header_data; else @@ -340,30 +803,68 @@ info->max_http_header_pool2; else context->max_http_header_pool = context->max_fds; +#endif if (info->fd_limit_per_thread) - context->fd_limit_per_thread = info->fd_limit_per_thread; + context->fd_limit_per_thread = lpf; else - context->fd_limit_per_thread = context->max_fds / - context->count_threads; + if (context->count_threads) + context->fd_limit_per_thread = context->max_fds / + context->count_threads; + +#if defined(LWS_WITH_SYS_SMD) + lws_mutex_init(context->smd.lock_messages); + lws_mutex_init(context->smd.lock_peers); + + /* lws_system smd participant */ + + if (!lws_smd_register(context, context, 0, LWSSMDCL_NETWORK, + lws_system_smd_cb)) { + lwsl_err("%s: early smd register failed\n", __func__); + } + + /* user smd participant */ + + if (info->early_smd_cb && + !lws_smd_register(context, info->early_smd_opaque, 0, + info->early_smd_class_filter, + info->early_smd_cb)) { + lwsl_err("%s: early smd register failed\n", __func__); + } +#endif + n = 0; #if defined(LWS_WITH_NETWORK) + + context->default_retry.retry_ms_table = default_backoff_table; + context->default_retry.conceal_count = + context->default_retry.retry_ms_table_count = + LWS_ARRAY_SIZE(default_backoff_table); + context->default_retry.jitter_percent = 20; + context->default_retry.secs_since_valid_ping = 300; + context->default_retry.secs_since_valid_hangup = 310; + + if (info->retry_and_idle_policy && + info->retry_and_idle_policy->secs_since_valid_ping) { + context->default_retry.secs_since_valid_ping = + info->retry_and_idle_policy->secs_since_valid_ping; + context->default_retry.secs_since_valid_hangup = + info->retry_and_idle_policy->secs_since_valid_hangup; + } + /* * Allocate the per-thread storage for scratchpad buffers, * and header data pool */ + u = (uint8_t *)&context[1]; for (n = 0; n < context->count_threads; n++) { - context->pt[n].serv_buf = lws_malloc( - context->pt_serv_buf_size + sizeof(struct lws), - "pt_serv_buf"); - if (!context->pt[n].serv_buf) { - lwsl_err("OOM\n"); - return NULL; - } + context->pt[n].serv_buf = u; + u += context->pt_serv_buf_size; context->pt[n].context = context; context->pt[n].tid = n; +#if !defined(LWS_PLAT_FREERTOS) /* * We overallocated for a fakewsi (can't compose it in the * pt because size isn't known at that time). point to it @@ -371,10 +872,16 @@ * when the source of the callback is not actually from a wsi * context. */ - context->pt[n].fake_wsi = (struct lws *)(context->pt[n].serv_buf + - context->pt_serv_buf_size); + context->pt[n].fake_wsi = (struct lws *)u; + u += sizeof(struct lws); memset(context->pt[n].fake_wsi, 0, sizeof(struct lws)); +#endif + +#if defined(LWS_WITH_EVENT_LIBS) + context->pt[n].evlib_pt = u; + u += plev->ops->evlib_size_pt; +#endif #if defined(LWS_ROLE_H1) || defined(LWS_ROLE_H2) context->pt[n].http.ah_list = NULL; @@ -384,10 +891,17 @@ #if defined(LWS_WITH_SEQUENCER) lws_seq_pt_init(&context->pt[n]); #endif - } - lwsl_info(" Threads: %d each %d fds\n", context->count_threads, - context->fd_limit_per_thread); + LWS_FOR_EVERY_AVAILABLE_ROLE_START(ar) { + if (ar->pt_init_destroy) + ar->pt_init_destroy(context, info, + &context->pt[n], 0); + } LWS_FOR_EVERY_AVAILABLE_ROLE_END; + +#if defined(LWS_WITH_CGI) + role_ops_cgi.pt_init_destroy(context, info, &context->pt[n], 0); +#endif + } if (!info->ka_interval && info->ka_time > 0) { lwsl_err("info->ka_interval can't be 0 if ka_time used\n"); @@ -407,19 +921,7 @@ context->ip_limit_ah = info->ip_limit_ah; context->ip_limit_wsi = info->ip_limit_wsi; -#endif - - lwsl_info(" mem: context: %5lu B (%ld ctx + (%ld thr x %d))\n", - (long)sizeof(struct lws_context) + - (context->count_threads * context->pt_serv_buf_size), - (long)sizeof(struct lws_context), - (long)context->count_threads, - context->pt_serv_buf_size); -#if defined(LWS_ROLE_H1) || defined(LWS_ROLE_H2) - lwsl_info(" mem: http hdr size: (%u + %lu), max count %u\n", - context->max_http_header_data, - (long)sizeof(struct allocated_headers), - context->max_http_header_pool); + context->pl_notify_cb = info->pl_notify_cb; #endif /* @@ -433,13 +935,31 @@ lwsl_err("OOM allocating %d fds\n", context->max_fds); goto bail; } - lwsl_info(" mem: pollfd map: %5u B\n", n); #endif + + lwsl_info(" ctx: %5luB (%ld ctx + pt(%ld thr x %d)), " + "pt-fds: %d, fdmap: %d\n", + (long)sizeof(struct lws_context) + + (context->count_threads * context->pt_serv_buf_size), + (long)sizeof(struct lws_context), + (long)context->count_threads, + context->pt_serv_buf_size, + context->fd_limit_per_thread, n); + +#if defined(LWS_ROLE_H1) || defined(LWS_ROLE_H2) + lwsl_info(" http: ah_data: %u, ah: %lu, max count %u\n", + context->max_http_header_data, + (long)sizeof(struct allocated_headers), + context->max_http_header_pool); +#endif + +#if defined(LWS_WITH_SERVER) if (info->server_string) { context->server_string = info->server_string; context->server_string_len = (short) strlen(context->server_string); } +#endif #if LWS_MAX_SMP > 1 /* each thread serves his own chunk of fds */ @@ -448,13 +968,19 @@ context->fd_limit_per_thread; #endif + + /* + * Past here, we may have added handles to the event lib + * loop and if libuv, have to take care about how to unpick them... + */ + if (lws_plat_init(context, info)) - goto bail; + goto bail_libuv_aware; #if defined(LWS_WITH_NETWORK) if (context->event_loop_ops->init_context) if (context->event_loop_ops->init_context(context, info)) - goto bail; + goto bail_libuv_aware; if (context->event_loop_ops->init_pt) @@ -465,19 +991,128 @@ lp = info->foreign_loops[n]; if (context->event_loop_ops->init_pt(context, lp, n)) - goto bail; + goto bail_libuv_aware; } -#if !defined(LWS_AMAZON_RTOS) if (lws_create_event_pipes(context)) - goto bail; -#endif + goto bail_libuv_aware; #endif lws_context_init_ssl_library(info); context->user_space = info->user; + +#if defined(LWS_WITH_SERVER) + strcpy(context->canonical_hostname, "unknown"); +#if defined(LWS_WITH_NETWORK) + lws_server_get_canonical_hostname(context, info); +#endif +#endif + +#if defined(LWS_WITH_STATS) + context->pt[0].sul_stats.cb = lws_sul_stats_cb; + __lws_sul_insert_us(&context->pt[0].pt_sul_owner[LWSSULLI_MISS_IF_SUSPENDED], + &context->pt[0].sul_stats, 10 * LWS_US_PER_SEC); +#endif +#if defined(LWS_WITH_PEER_LIMITS) + context->pt[0].sul_peer_limits.cb = lws_sul_peer_limits_cb; + __lws_sul_insert_us(&context->pt[0].pt_sul_owner[LWSSULLI_MISS_IF_SUSPENDED], + &context->pt[0].sul_peer_limits, 10 * LWS_US_PER_SEC); +#endif + +#if defined(LWS_HAVE_SYS_CAPABILITY_H) && defined(LWS_HAVE_LIBCAP) + memcpy(context->caps, info->caps, sizeof(context->caps)); + context->count_caps = info->count_caps; +#endif + + #if defined(LWS_WITH_NETWORK) + +#if defined(LWS_WITH_SYS_ASYNC_DNS) || defined(LWS_WITH_SYS_NTPCLIENT) || \ + defined(LWS_WITH_SYS_DHCP_CLIENT) + { + /* + * system vhost + */ + + struct lws_context_creation_info ii; + const struct lws_protocols *pp[4]; + struct lws_vhost *vh; +#if defined(LWS_WITH_SYS_ASYNC_DNS) + extern const struct lws_protocols lws_async_dns_protocol; +#endif +#if defined(LWS_WITH_SYS_NTPCLIENT) + extern const struct lws_protocols lws_system_protocol_ntpc; +#endif +#if defined(LWS_WITH_SYS_DHCP_CLIENT) + extern const struct lws_protocols lws_system_protocol_dhcpc; +#endif + + n = 0; +#if defined(LWS_WITH_SYS_ASYNC_DNS) + pp[n++] = &lws_async_dns_protocol; +#endif +#if defined(LWS_WITH_SYS_NTPCLIENT) + pp[n++] = &lws_system_protocol_ntpc; +#endif +#if defined(LWS_WITH_SYS_DHCP_CLIENT) + pp[n++] = &lws_system_protocol_dhcpc; +#endif + pp[n] = NULL; + + memset(&ii, 0, sizeof(ii)); + ii.vhost_name = "system"; + ii.pprotocols = pp; + + vh = lws_create_vhost(context, &ii); + if (!vh) { + lwsl_err("%s: failed to create system vhost\n", + __func__); + goto bail_libuv_aware; + } + + context->vhost_system = vh; + + if (lws_protocol_init_vhost(vh, NULL)) { + lwsl_err("%s: failed to init system vhost\n", __func__); + goto bail_libuv_aware; + } +#if defined(LWS_WITH_SYS_ASYNC_DNS) + if (lws_async_dns_init(context)) + goto bail_libuv_aware; +#endif + } +#endif + +#if defined(LWS_WITH_SYS_STATE) + /* + * init the lws_state mgr for the system state + */ + + context->mgr_system.state_names = system_state_names; + context->mgr_system.name = "system"; + context->mgr_system.state = LWS_SYSTATE_CONTEXT_CREATED; + context->mgr_system.parent = context; + context->mgr_system.context = context; +#if defined(LWS_WITH_SYS_SMD) + context->mgr_system.smd_class = LWSSMDCL_SYSTEM_STATE; +#endif + + context->protocols_notify.name = "prot_init"; + context->protocols_notify.notify_cb = lws_state_notify_protocol_init; + + lws_state_reg_notifier(&context->mgr_system, &context->protocols_notify); + + /* + * insert user notifiers here so they can participate with vetoing us + * trying to jump straight to operational, or at least observe us + * reaching 'operational', before we returned from context creation. + */ + + lws_state_reg_notifier_list(&context->mgr_system, + info->register_notifier_list); +#endif + /* * if he's not saying he'll make his own vhosts later then act * compatibly and make a default vhost using the data in the info @@ -485,39 +1120,55 @@ if (!lws_check_opt(info->options, LWS_SERVER_OPTION_EXPLICIT_VHOSTS)) if (!lws_create_vhost(context, info)) { lwsl_err("Failed to create default vhost\n"); - for (n = 0; n < context->count_threads; n++) - lws_free_set_NULL(context->pt[n].serv_buf); + #if defined(LWS_WITH_PEER_LIMITS) lws_free_set_NULL(context->pl_hash_table); #endif goto fail_clean_pipes; } - lws_context_init_extensions(info, context); +#if defined(LWS_WITH_SECURE_STREAMS) - lwsl_info(" mem: per-conn: %5lu bytes + protocol rx buf\n", - (unsigned long)sizeof(struct lws)); -#endif - strcpy(context->canonical_hostname, "unknown"); -#if defined(LWS_WITH_NETWORK) - lws_server_get_canonical_hostname(context, info); -#endif +#if !defined(LWS_WITH_SECURE_STREAMS_STATIC_POLICY_ONLY) + if (context->pss_policies_json) { + /* + * You must create your context with the explicit vhosts flag + * in order to use secure streams + */ + assert(lws_check_opt(info->options, + LWS_SERVER_OPTION_EXPLICIT_VHOSTS)); -#if defined(LWS_WITH_STATS) - context->pt[0].sul_stats.cb = lws_sul_stats_cb; - __lws_sul_insert(&context->pt[0].pt_sul_owner, &context->pt[0].sul_stats, - 10 * LWS_US_PER_SEC); + if (lws_ss_policy_parse_begin(context, 0)) + goto bail_libuv_aware; + + n = lws_ss_policy_parse(context, + (uint8_t *)context->pss_policies_json, + strlen(context->pss_policies_json)); + if (n != LEJP_CONTINUE && n < 0) + goto bail_libuv_aware; + + if (lws_ss_policy_set(context, "hardcoded")) { + lwsl_err("%s: policy set failed\n", __func__); + goto bail_libuv_aware; + } + } else +#else + if (context->pss_policies) { + /* user code set the policy objects directly, no parsing step */ + + if (lws_ss_policy_set(context, "hardcoded")) { + lwsl_err("%s: policy set failed\n", __func__); + goto bail_libuv_aware; + } + } //else #endif -#if defined(LWS_WITH_PEER_LIMITS) - context->pt[0].sul_peer_limits.cb = lws_sul_peer_limits_cb; - __lws_sul_insert(&context->pt[0].pt_sul_owner, - &context->pt[0].sul_peer_limits, 10 * LWS_US_PER_SEC); + // lws_create_vhost(context, info); #endif -#if defined(LWS_HAVE_SYS_CAPABILITY_H) && defined(LWS_HAVE_LIBCAP) - memcpy(context->caps, info->caps, sizeof(context->caps)); - context->count_caps = info->count_caps; -#endif + lws_context_init_extensions(info, context); + + lwsl_info(" mem: per-conn: %5lu bytes + protocol rx buf\n", + (unsigned long)sizeof(struct lws)); /* * drop any root privs for this process @@ -526,9 +1177,22 @@ */ if (!lws_check_opt(info->options, LWS_SERVER_OPTION_EXPLICIT_VHOSTS)) if (lws_plat_drop_app_privileges(context, 1)) - goto bail; + goto bail_libuv_aware; + +#if defined(LWS_WITH_SYS_STATE) + /* + * We want to move on the syste, state as far as it can go towards + * OPERATIONAL now. But we have to return from here first so the user + * code that called us can set its copy of context, which it may be + * relying on to perform operations triggered by the state change. + * + * We set up a sul to come back immediately and do the state change. + */ + + lws_sul_schedule(context, 0, &context->sul_system_state, + lws_context_creation_completion_cb, 1); +#endif -#if defined(LWS_WITH_NETWORK) /* expedite post-context init (eg, protocols) */ lws_cancel_service(context); #endif @@ -537,6 +1201,14 @@ #if defined(LWS_WITH_NETWORK) fail_clean_pipes: + +#if defined(LWS_WITH_LIBUV) + if (fatal_exit_defer) { + lws_context_destroy(context); + return context; + } +#endif + for (n = 0; n < context->count_threads; n++) lws_destroy_event_pipe(context->pt[n].pipe_wsi); @@ -552,28 +1224,83 @@ return NULL; -#if defined(LWS_WITH_NETWORK) +bail_libuv_aware: + lws_context_destroy(context); +#if defined(LWS_WITH_LIBUV) + return fatal_exit_defer ? context : NULL; +#else + return NULL; +#endif + fail_event_libs: - lwsl_err("Requested event library support not configured, available:\n"); - { - extern const struct lws_event_loop_ops *available_event_libs[]; - const struct lws_event_loop_ops **elops = available_event_libs; + lwsl_err("Requested event library support not configured\n"); - while (*elops) { - lwsl_err(" - %s\n", (*elops)->name); - elops++; - } - } -#endif +free_context_fail: lws_free(context); return NULL; } -LWS_VISIBLE LWS_EXTERN int -lws_context_is_deprecated(struct lws_context *context) +#if defined(LWS_WITH_NETWORK) +int +lws_system_cpd_start(struct lws_context *cx) +{ + cx->captive_portal_detect = LWS_CPD_UNKNOWN; + + /* if there's a platform implementation, use it */ + + if (lws_system_get_ops(cx) && + lws_system_get_ops(cx)->captive_portal_detect_request) + return lws_system_get_ops(cx)->captive_portal_detect_request(cx); + +#if defined(LWS_WITH_SECURE_STREAMS) + /* + * Otherwise try to use SS "captive_portal_detect" if that's enabled + */ + return lws_ss_sys_cpd(cx); +#else + return 0; +#endif +} + +static const char *cname[] = { "Unknown", "OK", "Captive", "No internet" }; + +void +lws_system_cpd_set(struct lws_context *cx, lws_cpd_result_t result) +{ + if (cx->captive_portal_detect != LWS_CPD_UNKNOWN) + return; + + lwsl_notice("%s: setting CPD result %s\n", __func__, cname[result]); + + cx->captive_portal_detect = (uint8_t)result; + +#if defined(LWS_WITH_SYS_STATE) +#if defined(LWS_WITH_SYS_SMD) + lws_smd_msg_printf(cx, LWSSMDCL_NETWORK, + "{\"type\":\"cpd\",\"result\":\"%s\"}", + cname[cx->captive_portal_detect]); +#endif + + /* if nothing is there to intercept anything, go all the way */ + if (cx->mgr_system.state != LWS_SYSTATE_POLICY_INVALID) + lws_state_transition_steps(&cx->mgr_system, + LWS_SYSTATE_OPERATIONAL); +#endif +} + +lws_cpd_result_t +lws_system_cpd_state_get(struct lws_context *cx) +{ + return (lws_cpd_result_t)cx->captive_portal_detect; +} + +#endif + +int +lws_context_is_deprecated(struct lws_context *cx) { - return context->deprecated; + return cx->deprecated; } /* @@ -607,10 +1334,13 @@ lws_context_destroy3(struct lws_context *context) { struct lws_context **pcontext_finalize = context->pcontext_finalize; -#if defined(LWS_WITH_NETWORK) int n; - lwsl_debug("%s\n", __func__); +#if defined(LWS_WITH_NETWORK) + + context->finalize_destroy_after_internal_loops_stopped = 1; + if (context->event_loop_ops->destroy_context2) + context->event_loop_ops->destroy_context2(context); for (n = 0; n < context->count_threads; n++) { struct lws_context_per_thread *pt = &context->pt[n]; @@ -618,11 +1348,18 @@ #if defined(LWS_WITH_SEQUENCER) lws_seq_destroy_all_on_pt(pt); #endif + LWS_FOR_EVERY_AVAILABLE_ROLE_START(ar) { + if (ar->pt_init_destroy) + ar->pt_init_destroy(context, NULL, pt, 1); + } LWS_FOR_EVERY_AVAILABLE_ROLE_END; +#if defined(LWS_WITH_CGI) + role_ops_cgi.pt_init_destroy(context, NULL, pt, 1); +#endif +#if 0 if (context->event_loop_ops->destroy_pt) context->event_loop_ops->destroy_pt(context, n); - - lws_free_set_NULL(context->pt[n].serv_buf); +#endif #if defined(LWS_ROLE_H1) || defined(LWS_ROLE_H2) while (pt->http.ah_list) @@ -630,13 +1367,51 @@ #endif } +#if defined(LWS_WITH_SYS_SMD) + _lws_smd_destroy(context); +#endif + +#if defined(LWS_WITH_SYS_ASYNC_DNS) + lws_async_dns_deinit(&context->async_dns); +#endif +#if defined(LWS_WITH_SYS_DHCP_CLIENT) + lws_dhcpc_remove(context, NULL); +#endif + if (context->pt[0].fds) lws_free_set_NULL(context->pt[0].fds); #endif lws_context_deinit_ssl_library(context); +#if defined(LWS_WITH_DETAILED_LATENCIES) + if (context->latencies_fd != -1) + compatible_close(context->latencies_fd); +#endif + + for (n = 0; n < LWS_SYSBLOB_TYPE_COUNT; n++) + lws_system_blob_destroy( + lws_system_get_blob(context, n, 0)); + +#if LWS_MAX_SMP > 1 + lws_mutex_refcount_destroy(&context->mr); +#endif + + /* drop any lingering deferred vhost frees */ + + while (context->deferred_free_list) { + struct lws_deferred_free *df = context->deferred_free_list; + + context->deferred_free_list = df->next; + lws_free(df); + }; + +#if defined(LWS_WITH_EVLIB_PLUGINS) && defined(LWS_WITH_EVENT_LIBS) + if (context->evlib_plugin_list) + lws_plugins_destroy(&context->evlib_plugin_list, NULL, NULL); +#endif + lws_free(context); - lwsl_info("%s: ctx %p freed\n", __func__, context); + lwsl_debug("%s: ctx %p freed\n", __func__, context); if (pcontext_finalize) *pcontext_finalize = NULL; @@ -651,6 +1426,7 @@ { #if defined(LWS_WITH_NETWORK) struct lws_vhost *vh = NULL, *vh1; + int n; #endif #if defined(LWS_WITH_PEER_LIMITS) uint32_t nu; @@ -662,6 +1438,58 @@ context->being_destroyed2 = 1; #if defined(LWS_WITH_NETWORK) + + /* + * We're going to trash things like vhost-protocols + * So we need to finish dealing with wsi close that + * might make callbacks first + */ + for (n = 0; n < context->count_threads; n++) { + struct lws_context_per_thread *pt = &context->pt[n]; + + (void)pt; + +#if defined(LWS_WITH_SECURE_STREAMS) + lws_dll2_foreach_safe(&pt->ss_owner, NULL, lws_ss_destroy_dll); +#if !defined(LWS_WITH_SECURE_STREAMS_STATIC_POLICY_ONLY) + + while (context->server_der_list) { + struct lws_ss_x509 *x = context->server_der_list; + + context->server_der_list = x->next; + lws_free((void *)x->ca_der); + } + + if (context->ac_policy) + lwsac_free(&context->ac_policy); +#endif +#endif + +#if defined(LWS_WITH_SECURE_STREAMS_PROXY_API) + lws_dll2_foreach_safe(&pt->ss_client_owner, NULL, lws_sspc_destroy_dll); +#endif + +#if defined(LWS_WITH_SEQUENCER) + lws_seq_destroy_all_on_pt(pt); +#endif + LWS_FOR_EVERY_AVAILABLE_ROLE_START(ar) { + if (ar->pt_init_destroy) + ar->pt_init_destroy(context, NULL, pt, 1); + } LWS_FOR_EVERY_AVAILABLE_ROLE_END; + +#if defined(LWS_WITH_CGI) + role_ops_cgi.pt_init_destroy(context, NULL, pt, 1); +#endif + + if (context->event_loop_ops->destroy_pt) + context->event_loop_ops->destroy_pt(context, n); + +#if defined(LWS_ROLE_H1) || defined(LWS_ROLE_H2) + while (pt->http.ah_list) + _lws_destroy_ah(pt, pt->http.ah_list); +#endif + } + /* * free all the per-vhost allocations */ @@ -712,57 +1540,97 @@ lws_check_deferred_free(context, 0, 1); #endif -#if LWS_MAX_SMP > 1 - lws_mutex_refcount_destroy(&context->mr); -#endif + lws_context_unlock(context); /* } context ------ */ + #if defined(LWS_WITH_NETWORK) if (context->event_loop_ops->destroy_context2) if (context->event_loop_ops->destroy_context2(context)) { - lws_context_unlock(context); /* } context ----------- */ context->finalize_destroy_after_internal_loops_stopped = 1; return; } lwsl_debug("%p: post dc2\n", __func__); - if (!context->pt[0].event_loop_foreign) { - int n; +// if (!context->pt[0].event_loop_foreign) { +// int n; for (n = 0; n < context->count_threads; n++) if (context->pt[n].inside_service) { lwsl_debug("%p: bailing as inside service\n", __func__); - lws_context_unlock(context); /* } context --- */ return; } - } +// } #endif - lws_context_unlock(context); /* } context ------------------- */ lws_context_destroy3(context); } +#if defined(LWS_WITH_NETWORK) +static void +lws_pt_destroy(struct lws_context_per_thread *pt) +{ + volatile struct lws_foreign_thread_pollfd *ftp, *next; + volatile struct lws_context_per_thread *vpt; + + assert(!pt->is_destroyed); + pt->destroy_self = 0; + + vpt = (volatile struct lws_context_per_thread *)pt; + ftp = vpt->foreign_pfd_list; + while (ftp) { + next = ftp->next; + lws_free((void *)ftp); + ftp = next; + } + vpt->foreign_pfd_list = NULL; + + lws_pt_lock(pt, __func__); + if (pt->pipe_wsi) + lws_destroy_event_pipe(pt->pipe_wsi); + lws_pt_unlock(pt); + pt->pipe_wsi = NULL; + + while (pt->fds_count) { + struct lws *wsi = wsi_from_fd(pt->context, pt->fds[0].fd); + + if (!wsi) + break; + + lws_close_free_wsi(wsi, + LWS_CLOSE_STATUS_NOSTATUS_CONTEXT_DESTROY, + "ctx destroy" + /* no protocol close */); + } + lws_pt_mutex_destroy(pt); + + pt->is_destroyed = 1; + + lwsl_info("%s: pt destroyed\n", __func__); +} +#endif + /* * Begin the context takedown */ -LWS_VISIBLE void +void lws_context_destroy(struct lws_context *context) { #if defined(LWS_WITH_NETWORK) - volatile struct lws_foreign_thread_pollfd *ftp, *next; - volatile struct lws_context_per_thread *vpt; struct lws_vhost *vh = NULL; - struct lws wsi; - int n, m; + int m, deferred_pt = 0; #endif - if (!context) + if (!context || context->inside_context_destroy) return; + + context->inside_context_destroy = 1; + #if defined(LWS_WITH_NETWORK) if (context->finalize_destroy_after_internal_loops_stopped) { if (context->event_loop_ops->destroy_context2) context->event_loop_ops->destroy_context2(context); lws_context_destroy3(context); - + /* context is invalid, no need to reset inside flag */ return; } #endif @@ -776,54 +1644,44 @@ __func__, context); lws_context_destroy3(context); + /* context is invalid, no need to reset inside flag */ return; } lwsl_info("%s: ctx %p\n", __func__, context); context->being_destroyed = 1; - context->being_destroyed1 = 1; - context->requested_kill = 1; #if defined(LWS_WITH_NETWORK) - m = context->count_threads; - memset(&wsi, 0, sizeof(wsi)); - wsi.context = context; - -#ifdef LWS_LATENCY - if (context->worst_latency_info[0]) - lwsl_notice("Worst latency: %s\n", context->worst_latency_info); +#if defined(LWS_WITH_SYS_STATE) + lws_state_transition(&context->mgr_system, LWS_SYSTATE_POLICY_INVALID); #endif + m = context->count_threads; while (m--) { struct lws_context_per_thread *pt = &context->pt[m]; - vpt = (volatile struct lws_context_per_thread *)pt; - ftp = vpt->foreign_pfd_list; - while (ftp) { - next = ftp->next; - lws_free((void *)ftp); - ftp = next; - } - vpt->foreign_pfd_list = NULL; - - for (n = 0; (unsigned int)n < context->pt[m].fds_count; n++) { - struct lws *wsi = wsi_from_fd(context, pt->fds[n].fd); - if (!wsi) - continue; - - if (wsi->event_pipe) - lws_destroy_event_pipe(wsi); - else - lws_close_free_wsi(wsi, - LWS_CLOSE_STATUS_NOSTATUS_CONTEXT_DESTROY, - "ctx destroy" - /* no protocol close */); - n--; + if (pt->is_destroyed) + continue; + + if (pt->inside_lws_service) { + pt->destroy_self = 1; + deferred_pt = 1; + continue; } - lws_pt_mutex_destroy(pt); + + lws_pt_destroy(pt); + } + + if (deferred_pt) { + lwsl_info("%s: waiting for deferred pt close\n", __func__); + lws_cancel_service(context); + goto out; } + context->being_destroyed1 = 1; + context->requested_kill = 1; + /* * inform all the protocols that they are done and will have no more * callbacks. @@ -863,11 +1721,11 @@ if (context->event_loop_ops->destroy_context1) { context->event_loop_ops->destroy_context1(context); - return; + goto out; } #endif -#if defined(LWS_WITH_ESP32) +#if defined(LWS_PLAT_FREERTOS) #if defined(LWS_AMAZON_RTOS) context->last_free_heap = xPortGetFreeHeapSize(); #else @@ -875,6 +1733,25 @@ #endif #endif + context->inside_context_destroy = 0; lws_context_destroy2(context); + + return; + +#if defined(LWS_WITH_NETWORK) +out: + context->inside_context_destroy = 0; +#endif } +#if defined(LWS_WITH_SYS_STATE) +struct lws_context * +lws_system_context_from_system_mgr(lws_state_manager_t *mgr) +{ +#if defined(LWS_WITH_NETWORK) + return mgr->context; +#else + return NULL; +#endif +} +#endif diff -Nru libwebsockets-3.2.1/lib/core/libwebsockets.c libwebsockets-4.1.6/lib/core/libwebsockets.c --- libwebsockets-3.2.1/lib/core/libwebsockets.c 2019-12-18 14:45:31.000000000 +0000 +++ libwebsockets-4.1.6/lib/core/libwebsockets.c 2020-12-01 17:40:26.000000000 +0000 @@ -1,29 +1,119 @@ /* * libwebsockets - small server side websockets and web server implementation * - * Copyright (C) 2010-2019 Andy Green + * Copyright (C) 2010 - 2020 Andy Green * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation: - * version 2.1 of the License. + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to + * deal in the Software without restriction, including without limitation the + * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or + * sell copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: * - * This library is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. * - * You should have received a copy of the GNU Lesser General Public - * License along with this library; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, - * MA 02110-1301 USA + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS + * IN THE SOFTWARE. */ -#include "core/private.h" +#include "private-lib-core.h" #ifdef LWS_HAVE_SYS_TYPES_H #include #endif +#include + +void +lws_ser_wu16be(uint8_t *b, uint16_t u) +{ + *b++ = (uint8_t)(u >> 8); + *b = (uint8_t)u; +} + +void +lws_ser_wu32be(uint8_t *b, uint32_t u32) +{ + *b++ = (uint8_t)(u32 >> 24); + *b++ = (uint8_t)(u32 >> 16); + *b++ = (uint8_t)(u32 >> 8); + *b = (uint8_t)u32; +} + +void +lws_ser_wu64be(uint8_t *b, uint64_t u64) +{ + lws_ser_wu32be(b, (uint32_t)(u64 >> 32)); + lws_ser_wu32be(b + 4, (uint32_t)u64); +} + +uint16_t +lws_ser_ru16be(const uint8_t *b) +{ + return (b[0] << 8) | b[1]; +} + +uint32_t +lws_ser_ru32be(const uint8_t *b) +{ + return (b[0] << 24) | (b[1] << 16) | (b[2] << 8) | b[3]; +} + +uint64_t +lws_ser_ru64be(const uint8_t *b) +{ + return (((uint64_t)lws_ser_ru32be(b)) << 32) | lws_ser_ru32be(b + 4); +} + +int +lws_vbi_encode(uint64_t value, void *buf) +{ + uint8_t *p = (uint8_t *)buf, b; + + if (value > 0xfffffff) { + assert(0); + return -1; + } + + do { + b = value & 0x7f; + value >>= 7; + if (value) + *p++ = (0x80 | b); + else + *p++ = b; + } while (value); + + return lws_ptr_diff(p, buf); +} + +int +lws_vbi_decode(const void *buf, uint64_t *value, size_t len) +{ + const uint8_t *p = (const uint8_t *)buf, *end = p + len; + uint64_t v = 0; + int s = 0; + + while (p < end) { + v |= (((uint64_t)(*p)) & 0x7f) << s; + if (*p & 0x80) { + *value = v; + + return lws_ptr_diff(p, buf); + } + s += 7; + if (s >= 64) + return 0; + p++; + } + + return 0; +} signed char char_to_hex(const char c) { @@ -60,13 +150,34 @@ if (max < 0) return -1; - return dest - odest; + return lws_ptr_diff(dest, odest); } +static char *hexch = "0123456789abcdef"; + +int +lws_hex_random(struct lws_context *context, char *dest, size_t len) +{ + size_t n = (len - 1) / 2; + uint8_t b, *r = (uint8_t *)dest + len - n; + + if (lws_get_random(context, r, n) != n) + return 1; + + while (n--) { + b = *r++; + *dest++ = hexch[b >> 4]; + *dest++ = hexch[b & 0xf]; + } + + *dest = '\0'; + + return 0; +} #if !defined(LWS_PLAT_OPTEE) -#if !defined(LWS_AMAZON_RTOS) +#if defined(LWS_WITH_FILE_OPS) int lws_open(const char *__file, int __oflag, ...) { va_list ap; @@ -115,13 +226,13 @@ #endif } -LWS_EXTERN void * +void * lws_context_user(struct lws_context *context) { return context->user_space; } -LWS_VISIBLE void +void lws_explicit_bzero(void *p, size_t len) { volatile uint8_t *vp = p; @@ -136,7 +247,7 @@ * lws_now_secs() - seconds since 1970-1-1 * */ -LWS_VISIBLE LWS_EXTERN unsigned long +unsigned long lws_now_secs(void) { struct timeval tv; @@ -147,85 +258,16 @@ } #endif -LWS_VISIBLE extern const char * + +#if defined(LWS_WITH_SERVER) +const char * lws_canonical_hostname(struct lws_context *context) { return (const char *)context->canonical_hostname; } - -#if defined(LWS_WITH_SOCKS5) -LWS_VISIBLE int -lws_set_socks(struct lws_vhost *vhost, const char *socks) -{ - char *p_at, *p_colon; - char user[96]; - char password[96]; - - if (!socks) - return -1; - - vhost->socks_user[0] = '\0'; - vhost->socks_password[0] = '\0'; - - p_at = strrchr(socks, '@'); - if (p_at) { /* auth is around */ - if ((unsigned int)(p_at - socks) > (sizeof(user) - + sizeof(password) - 2)) { - lwsl_err("Socks auth too long\n"); - goto bail; - } - - p_colon = strchr(socks, ':'); - if (p_colon) { - if ((unsigned int)(p_colon - socks) > (sizeof(user) - - 1) ) { - lwsl_err("Socks user too long\n"); - goto bail; - } - if ((unsigned int)(p_at - p_colon) > (sizeof(password) - - 1) ) { - lwsl_err("Socks password too long\n"); - goto bail; - } - - lws_strncpy(vhost->socks_user, socks, p_colon - socks + 1); - lws_strncpy(vhost->socks_password, p_colon + 1, - p_at - (p_colon + 1) + 1); - } - - lwsl_info(" Socks auth, user: %s, password: %s\n", - vhost->socks_user, vhost->socks_password ); - - socks = p_at + 1; - } - - lws_strncpy(vhost->socks_proxy_address, socks, - sizeof(vhost->socks_proxy_address)); - - p_colon = strchr(vhost->socks_proxy_address, ':'); - if (!p_colon && !vhost->socks_proxy_port) { - lwsl_err("socks_proxy needs to be address:port\n"); - return -1; - } else { - if (p_colon) { - *p_colon = '\0'; - vhost->socks_proxy_port = atoi(p_colon + 1); - } - } - - lwsl_info(" Socks %s:%u\n", vhost->socks_proxy_address, - vhost->socks_proxy_port); - - return 0; - -bail: - return -1; -} #endif - - -LWS_VISIBLE LWS_EXTERN int +int lws_get_count_threads(struct lws_context *context) { return context->count_threads; @@ -259,7 +301,7 @@ 0x80 | ((4 - 1) << 2) | 1, /* s3 */ }; -LWS_EXTERN int +int lws_check_byte_utf8(unsigned char state, unsigned char c) { unsigned char s = state; @@ -282,7 +324,7 @@ return e0f4[21 + (s & 3)]; } -LWS_EXTERN int +int lws_check_utf8(unsigned char *state, unsigned char *buf, size_t len) { unsigned char s = *state; @@ -324,9 +366,117 @@ return d; } +const char * +lws_nstrstr(const char *buf, size_t len, const char *name, size_t nl) +{ + const char *end = buf + len - nl + 1; + size_t n; + + if (nl > len) + /* it cannot be found if the needle is longer than the haystack */ + return NULL; + + while (buf < end) { + if (*buf != name[0]) { + buf++; + continue; + } + + if (nl == 1) + /* single char match, we are done */ + return buf; + + if (buf[nl - 1] == name[nl - 1]) { + /* + * This is looking interesting then... the first + * and last chars match, let's check the insides + */ + n = 1; + while (n < nl && buf[n] == name[n]) + n++; + + if (n == nl) + /* it's a hit */ + return buf; + } + + buf++; + } + + return NULL; +} + +/* + * name wants to be something like "\"myname\":" + */ + +const char * +lws_json_simple_find(const char *buf, size_t len, const char *name, size_t *alen) +{ + size_t nl = strlen(name); + const char *np = lws_nstrstr(buf, len, name, nl), + *end = buf + len, *as; + int qu = 0; + + if (!np) + return NULL; + + np += nl; + + while (np < end && (*np == ' ' || *np == '\t')) + np++; + + if (np >= end) + return NULL; + + /* + * The arg could be lots of things after "name": with JSON, commonly a + * string like "mystring", true, false, null, [...] or {...} ... we want + * to handle common, simple cases cheaply with this; the user can choose + * a full JSON parser like lejp if it's complicated. So if no opening + * quote, return until a terminator like , ] }. If there's an opening + * quote, return until closing quote, handling escaped quotes. + */ + + if (*np == '\"') { + qu = 1; + np++; + } + + as = np; + while (np < end && + (!qu || *np != '\"') && /* end quote is EOT if quoted */ + (qu || (*np != '}' && *np != ']' && *np != ',')) /* delimiters */ + ) { + if (qu && *np == '\\') /* skip next char if quoted escape */ + np++; + np++; + } + + *alen = lws_ptr_diff(np, as); + + return as; +} + +int +lws_json_simple_strcmp(const char *buf, size_t len, const char *name, + const char *comp) +{ + size_t al; + const char *hit = lws_json_simple_find(buf, len, name, &al); + + if (!hit) + return -1; + + if (al != strlen(comp)) + return -1; + + return strncmp(hit, comp, al); +} + static const char *hex = "0123456789ABCDEF"; -LWS_VISIBLE LWS_EXTERN const char * +const char * lws_sql_purify(char *escaped, const char *string, int len) { const char *p = string; @@ -346,8 +496,22 @@ return escaped; } -LWS_VISIBLE LWS_EXTERN const char * -lws_json_purify(char *escaped, const char *string, int len) +int +lws_sql_purify_len(const char *p) +{ + int olen = 0; + + while (*p) { + if (*p++ == '\'') + olen++; + olen++; + } + + return olen; +} + +const char * +lws_json_purify(char *escaped, const char *string, int len, int *in_used) { const char *p = string; char *q = escaped; @@ -379,7 +543,14 @@ continue; } - if (*p == '\"' || *p == '\\' || *p < 0x20) { + if (*p == '\\') { + p++; + *q++ = '\\'; + *q++ = '\\'; + continue; + } + + if (*p == '\"' || *p < 0x20) { *q++ = '\\'; *q++ = 'u'; *q++ = '0'; @@ -393,10 +564,38 @@ } *q = '\0'; + if (in_used) + *in_used = lws_ptr_diff(p, string); + return escaped; } -LWS_VISIBLE LWS_EXTERN void +int +lws_json_purify_len(const char *string) +{ + int len = 0; + const char *p = string; + + while (*p) { + if (*p == '\t' || *p == '\n' || *p == '\r') { + p++; + len += 2; + continue; + } + + if (*p == '\"' || *p == '\\' || *p < 0x20) { + len += 6; + p++; + continue; + } + p++; + len++; + } + + return len; +} + +void lws_filename_purify_inplace(char *filename) { while (*filename) { @@ -407,7 +606,9 @@ } if (*filename == ':' || +#if !defined(WIN32) *filename == '\\' || +#endif *filename == '$' || *filename == '%') *filename = '_'; @@ -416,7 +617,7 @@ } } -LWS_VISIBLE LWS_EXTERN const char * +const char * lws_urlencode(char *escaped, const char *string, int len) { const char *p = string; @@ -446,7 +647,7 @@ return escaped; } -LWS_VISIBLE LWS_EXTERN int +int lws_urldecode(char *string, const char *escaped, int len) { int state = 0, n; @@ -495,7 +696,7 @@ return 0; } -LWS_VISIBLE LWS_EXTERN int +int lws_finalize_startup(struct lws_context *context) { if (lws_check_opt(context->options, LWS_SERVER_OPTION_EXPLICIT_VHOSTS)) @@ -505,12 +706,14 @@ return 0; } -LWS_VISIBLE LWS_EXTERN void +#if !defined(LWS_PLAT_FREERTOS) +void lws_get_effective_uid_gid(struct lws_context *context, int *uid, int *gid) { *uid = context->uid; *gid = context->gid; } +#endif int lws_snprintf(char *str, size_t size, const char *format, ...) @@ -560,18 +763,14 @@ LWS_TOKZS_TOKEN_POST_TERMINAL } lws_tokenize_state; -#if defined(LWS_AMAZON_RTOS) lws_tokenize_elem -#else -int -#endif lws_tokenize(struct lws_tokenize *ts) { const char *rfc7230_delims = "(),/:;<=>?@[\\]{}"; lws_tokenize_state state = LWS_TOKZS_LEADING_WHITESPACE; char c, flo = 0, d_minus = '-', d_dot = '.', s_minus = '\0', - s_dot = '\0'; - signed char num = ts->flags & LWS_TOKENIZE_F_NO_INTEGERS ? 0 : -1; + s_dot = '\0', skipping = 0; + signed char num = (ts->flags & LWS_TOKENIZE_F_NO_INTEGERS) ? 0 : -1; int utf8 = 0; /* for speed, compute the effect of the flags outside the loop */ @@ -599,6 +798,22 @@ if (!c) break; + if (skipping) { + if (c != '\r' && c != '\n') + continue; + else + skipping = 0; + } + + /* comment */ + + if (ts->flags & LWS_TOKENIZE_F_HASH_COMMENT && + state != LWS_TOKZS_QUOTED_STRING && + c == '#') { + skipping = 1; + continue; + } + /* whitespace */ if (c == ' ' || c == '\t' || c == '\n' || c == '\r' || @@ -692,7 +907,8 @@ (c < 'a' || c > 'z') && c != '_') && c != s_minus && c != s_dot) || c == d_minus || c == d_dot - )) { + ) && + !((ts->flags & LWS_TOKENIZE_F_SLASH_NONTERM) && c == '/')) { switch (state) { case LWS_TOKZS_LEADING_WHITESPACE: if (ts->flags & LWS_TOKENIZE_F_COMMA_SEP_LIST) { @@ -786,8 +1002,8 @@ } -LWS_VISIBLE LWS_EXTERN int -lws_tokenize_cstr(struct lws_tokenize *ts, char *str, int max) +int +lws_tokenize_cstr(struct lws_tokenize *ts, char *str, size_t max) { if (ts->token_len + 1 >= max) return 1; @@ -798,7 +1014,7 @@ return 0; } -LWS_VISIBLE LWS_EXTERN void +void lws_tokenize_init(struct lws_tokenize *ts, const char *start, int flags) { ts->start = start; @@ -807,6 +1023,119 @@ ts->delim = LWSTZ_DT_NEED_FIRST_CONTENT; } + +typedef enum { + LWS_EXPS_LITERAL, + LWS_EXPS_OPEN_OR_LIT, + LWS_EXPS_NAME_OR_CLOSE, + LWS_EXPS_DRAIN, +} lws_strexp_state; + +void +lws_strexp_init(lws_strexp_t *exp, void *priv, lws_strexp_expand_cb cb, + char *out, size_t olen) +{ + memset(exp, 0, sizeof(*exp)); + exp->cb = cb; + exp->out = out; + exp->olen = olen; + exp->state = LWS_EXPS_LITERAL; + exp->priv = priv; +} + +void +lws_strexp_reset_out(lws_strexp_t *exp, char *out, size_t olen) +{ + exp->out = out; + exp->olen = olen; + exp->pos = 0; +} + +int +lws_strexp_expand(lws_strexp_t *exp, const char *in, size_t len, + size_t *pused_in, size_t *pused_out) +{ + size_t used = 0; + int n; + + while (used < len) { + + switch (exp->state) { + case LWS_EXPS_LITERAL: + if (*in == '$') { + exp->state = LWS_EXPS_OPEN_OR_LIT; + break; + } + + if (exp->out) + exp->out[exp->pos] = *in; + exp->pos++; + if (exp->olen - exp->pos < 1) { + *pused_in = used + 1; + *pused_out = exp->pos; + return LSTRX_FILLED_OUT; + } + break; + + case LWS_EXPS_OPEN_OR_LIT: + if (*in == '{') { + exp->state = LWS_EXPS_NAME_OR_CLOSE; + exp->name_pos = 0; + exp->exp_ofs = 0; + break; + } + /* treat as a literal */ + if (exp->olen - exp->pos < 3) + return -1; + + if (exp->out) { + exp->out[exp->pos++] = '$'; + exp->out[exp->pos++] = *in; + } else + exp->pos += 2; + if (*in != '$') + exp->state = LWS_EXPS_LITERAL; + break; + + case LWS_EXPS_NAME_OR_CLOSE: + if (*in == '}') { + exp->name[exp->name_pos] = '\0'; + exp->state = LWS_EXPS_DRAIN; + goto drain; + } + if (exp->name_pos >= sizeof(exp->name) - 1) + return LSTRX_FATAL_NAME_TOO_LONG; + + exp->name[exp->name_pos++] = *in; + break; + + case LWS_EXPS_DRAIN: +drain: + *pused_in = used; + n = exp->cb(exp->priv, exp->name, exp->out, &exp->pos, + exp->olen, &exp->exp_ofs); + *pused_out = exp->pos; + if (n == LSTRX_FILLED_OUT || + n == LSTRX_FATAL_NAME_UNKNOWN) + return n; + + exp->state = LWS_EXPS_LITERAL; + break; + } + + used++; + in++; + } + + if (exp->out) + exp->out[exp->pos] = '\0'; + *pused_in = used; + *pused_out = exp->pos; + + return LSTRX_DONE; +} + + #if LWS_MAX_SMP > 1 void @@ -865,6 +1194,12 @@ pthread_mutex_unlock(&mr->lock); } +void +lws_mutex_refcount_assert_held(struct lws_mutex_refcount *mr) +{ + assert(mr->lock_owner == pthread_self() && mr->lock_depth); +} + #endif /* SMP */ @@ -883,6 +1218,8 @@ return argv[c + 1]; } + if (argv[c][n] == '=') + return &argv[c][n + 1]; return argv[c] + n; } } @@ -890,6 +1227,61 @@ return NULL; } +static const char * const builtins[] = { + "-d", +#if defined(LWS_WITH_UDP) + "--udp-tx-loss", + "--udp-rx-loss", +#endif + "--ignore-sigterm" +}; + +#if !defined(LWS_PLAT_FREERTOS) +static void +lws_sigterm_catch(int sig) +{ +} +#endif + +void +lws_cmdline_option_handle_builtin(int argc, const char **argv, + struct lws_context_creation_info *info) +{ + const char *p; + int n, m, logs = LLL_USER | LLL_ERR | LLL_WARN | LLL_NOTICE; + + for (n = 0; n < (int)LWS_ARRAY_SIZE(builtins); n++) { + p = lws_cmdline_option(argc, argv, builtins[n]); + if (!p) + continue; + + m = atoi(p); + + switch (n) { + case 0: + logs = m; + break; +#if defined(LWS_WITH_UDP) + case 1: + info->udp_loss_sim_tx_pc = m; + break; + case 2: + info->udp_loss_sim_rx_pc = m; + break; + case 3: +#else + case 1: +#endif +#if !defined(LWS_PLAT_FREERTOS) + signal(SIGTERM, lws_sigterm_catch); +#endif + break; + } + } + + lws_set_log_level(logs, NULL); +} + const lws_humanize_unit_t humanize_schema_si[] = { { "Pi ", LWS_PI }, { "Ti ", LWS_TI }, { "Gi ", LWS_GI }, @@ -912,44 +1304,58 @@ { NULL, 0 } }; +static int +decim(char *r, uint64_t v, char chars, char leading) +{ + int n = chars - 1; + uint64_t q = 1; + + r += n; + + while (n >= 0) { + if (v / q) + *r-- = '0' + ((v / q) % 10); + else + *r-- = leading ? '0' : ' '; + q = q * 10; + n--; + } + + if (v / q) + /* the number is bigger than the allowed chars! */ + r[1] = '!'; + + return chars; +} + int lws_humanize(char *p, int len, uint64_t v, const lws_humanize_unit_t *schema) { + char *end = p + len; + do { if (v >= schema->factor || schema->factor == 1) { - if (schema->factor == 1) - return lws_snprintf(p, len, - " %4"PRIu64"%s ", - v / schema->factor, schema->name); - - return lws_snprintf(p, len, " %4"PRIu64".%03"PRIu64"%s", - v / schema->factor, - (v % schema->factor) / (schema->factor / 1000), - schema->name); + if (schema->factor == 1) { + *p++ = ' '; + p += decim(p, v, 4, 0); + return lws_snprintf(p, lws_ptr_diff(end, p), + "%s ", schema->name); + } + + *p++ = ' '; + p += decim(p, v / schema->factor, 4, 0); + *p++ = '.'; + p += decim(p, (v % schema->factor) / + (schema->factor / 1000), 3, 1); + + return lws_snprintf(p, lws_ptr_diff(end, p), + "%s", schema->name); } schema++; } while (schema->name); assert(0); + strncpy(p, "unknown value", len); return 0; } - -int -lws_system_get_info(struct lws_context *context, lws_system_item_t item, - lws_system_arg_t arg, size_t *len) -{ - if (!context->system_ops || !context->system_ops->get_info) - return 1; - - return context->system_ops->get_info(item, arg, len); -} - -int -lws_system_reboot(struct lws_context *context) -{ - if (!context->system_ops || !context->system_ops->reboot) - return 1; - - return context->system_ops->reboot(); -} diff -Nru libwebsockets-3.2.1/lib/core/logs.c libwebsockets-4.1.6/lib/core/logs.c --- libwebsockets-3.2.1/lib/core/logs.c 2019-12-18 14:45:31.000000000 +0000 +++ libwebsockets-4.1.6/lib/core/logs.c 2020-12-01 17:40:26.000000000 +0000 @@ -1,25 +1,28 @@ /* * libwebsockets - small server side websockets and web server implementation * - * Copyright (C) 2010-2019 Andy Green + * Copyright (C) 2010 - 2019 Andy Green * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation: - * version 2.1 of the License. + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to + * deal in the Software without restriction, including without limitation the + * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or + * sell copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: * - * This library is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. * - * You should have received a copy of the GNU Lesser General Public - * License along with this library; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, - * MA 02110-1301 USA + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS + * IN THE SOFTWARE. */ -#include "core/private.h" +#include "private-lib-core.h" #ifdef LWS_HAVE_SYS_TYPES_H #include @@ -38,38 +41,27 @@ #endif ; #ifndef LWS_PLAT_OPTEE -static const char * const log_level_names[] = { - "E", - "W", - "N", - "I", - "D", - "P", - "H", - "EXT", - "C", - "L", - "U", - "T", - "?", - "?" -}; +static const char * log_level_names ="EWNIDPHXCLUT??"; #endif -LWS_VISIBLE int +#if defined(LWS_LOGS_TIMESTAMP) +int lwsl_timestamp(int level, char *p, int len) { #ifndef LWS_PLAT_OPTEE -#ifndef _WIN32_WCE - time_t o_now = time(NULL); -#endif + time_t o_now; unsigned long long now; + struct timeval tv; struct tm *ptm = NULL; #ifndef WIN32 struct tm tm; #endif int n; + gettimeofday(&tv, NULL); + o_now = tv.tv_sec; + now = ((unsigned long long)tv.tv_sec * 10000) + (tv.tv_usec / 100); + #ifndef _WIN32_WCE #ifdef WIN32 ptm = localtime(&o_now); @@ -82,10 +74,10 @@ for (n = 0; n < LLL_COUNT; n++) { if (level != (1 << n)) continue; - now = lws_now_usecs() / 100; + if (ptm) n = lws_snprintf(p, len, - "[%04d/%02d/%02d %02d:%02d:%02d:%04d] %s: ", + "[%04d/%02d/%02d %02d:%02d:%02d:%04d] %c: ", ptm->tm_year + 1900, ptm->tm_mon + 1, ptm->tm_mday, @@ -94,7 +86,7 @@ ptm->tm_sec, (int)(now % 10000), log_level_names[n]); else - n = lws_snprintf(p, len, "[%llu:%04d] %s: ", + n = lws_snprintf(p, len, "[%llu:%04d] %c: ", (unsigned long long) now / 10000, (int)(now % 10000), log_level_names[n]); return n; @@ -105,6 +97,7 @@ return 0; } +#endif #ifndef LWS_PLAT_OPTEE static const char * const colours[] = { @@ -118,21 +111,26 @@ "[33m", /* LLL_EXT */ "[33m", /* LLL_CLIENT */ "[33;1m", /* LLL_LATENCY */ - "[30;1m", /* LLL_USER */ + "[0;1m", /* LLL_USER */ "[31m", /* LLL_THREAD */ }; static char tty; -LWS_VISIBLE void -lwsl_emit_stderr(int level, const char *line) +static void +_lwsl_emit_stderr(int level, const char *line, int ts) { char buf[50]; int n, m = LWS_ARRAY_SIZE(colours) - 1; if (!tty) tty = isatty(2) | 2; - lwsl_timestamp(level, buf, sizeof(buf)); + + buf[0] = '\0'; +#if defined(LWS_LOGS_TIMESTAMP) + if (ts) + lwsl_timestamp(level, buf, sizeof(buf)); +#endif if (tty == 3) { n = 1 << (LWS_ARRAY_SIZE(colours) - 1); @@ -147,33 +145,29 @@ fprintf(stderr, "%s%s", buf, line); } -LWS_VISIBLE void -lwsl_emit_stderr_notimestamp(int level, const char *line) +void +lwsl_emit_stderr(int level, const char *line) { - int n, m = LWS_ARRAY_SIZE(colours) - 1; - - if (!tty) - tty = isatty(2) | 2; + _lwsl_emit_stderr(level, line, 1); +} - if (tty == 3) { - n = 1 << (LWS_ARRAY_SIZE(colours) - 1); - while (n) { - if (level & n) - break; - m--; - n >>= 1; - } - fprintf(stderr, "%c%s%s%c[0m", 27, colours[m], line, 27); - } else - fprintf(stderr, "%s", line); +void +lwsl_emit_stderr_notimestamp(int level, const char *line) +{ + _lwsl_emit_stderr(level, line, 0); } #endif #if !(defined(LWS_PLAT_OPTEE) && !defined(LWS_WITH_NETWORK)) -LWS_VISIBLE void _lws_logv(int filter, const char *format, va_list vl) +void _lws_logv(int filter, const char *format, va_list vl) { +#if LWS_MAX_SMP == 1 && !defined(LWS_WITH_THREADPOOL) + /* this is incompatible with multithreaded logging */ static char buf[256]; +#else + char buf[1024]; +#endif int n; if (!(log_level & filter)) @@ -195,7 +189,7 @@ lwsl_emit(filter, buf); } -LWS_VISIBLE void _lws_log(int filter, const char *format, ...) +void _lws_log(int filter, const char *format, ...) { va_list ap; @@ -204,20 +198,19 @@ va_end(ap); } #endif -LWS_VISIBLE void lws_set_log_level(int level, - void (*func)(int level, const char *line)) +void lws_set_log_level(int level, void (*func)(int level, const char *line)) { log_level = level; if (func) lwsl_emit = func; } -LWS_VISIBLE int lwsl_visible(int level) +int lwsl_visible(int level) { return log_level & level; } -LWS_VISIBLE void +void lwsl_hexdump_level(int hexdump_level, const void *vbuf, size_t len) { unsigned char *buf = (unsigned char *)vbuf; @@ -232,8 +225,7 @@ } if (!vbuf) { - _lws_log(hexdump_level, "(hexdump: trying to dump %d at NULL)\n", - (int)len); + _lws_log(hexdump_level, "(hexdump: NULL ptr)\n"); return; } @@ -270,7 +262,7 @@ _lws_log(hexdump_level, "\n"); } -LWS_VISIBLE void +void lwsl_hexdump(const void *vbuf, size_t len) { #if defined(_DEBUG) diff -Nru libwebsockets-3.2.1/lib/core/lws_dll2.c libwebsockets-4.1.6/lib/core/lws_dll2.c --- libwebsockets-3.2.1/lib/core/lws_dll2.c 2019-12-18 14:45:31.000000000 +0000 +++ libwebsockets-4.1.6/lib/core/lws_dll2.c 2020-12-01 17:40:26.000000000 +0000 @@ -1,25 +1,28 @@ /* * libwebsockets - small server side websockets and web server implementation * - * Copyright (C) 2010-2019 Andy Green + * Copyright (C) 2010 - 2019 Andy Green * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation: - * version 2.1 of the License. + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to + * deal in the Software without restriction, including without limitation the + * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or + * sell copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: * - * This library is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. * - * You should have received a copy of the GNU Lesser General Public - * License along with this library; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, - * MA 02110-1301 USA + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS + * IN THE SOFTWARE. */ -#include "core/private.h" +#include "private-lib-core.h" #ifdef LWS_HAVE_SYS_TYPES_H #include @@ -206,21 +209,42 @@ lws_dll2_add_tail(d, own); } +void * +_lws_dll2_search_sz_pl(lws_dll2_owner_t *own, const char *name, size_t namelen, + size_t dll2_ofs, size_t ptr_ofs) +{ + lws_start_foreach_dll(struct lws_dll2 *, p, lws_dll2_get_head(own)) { + uint8_t *ref = ((uint8_t *)p) - dll2_ofs; + /* + * We have to read the const char * at the computed place and + * the string is where that points + */ + const char *str = *((const char **)(ref + ptr_ofs)); + + if (str && !strncmp(str, name, namelen) && !str[namelen]) + return (void *)ref; + } lws_end_foreach_dll(p); + + return NULL; +} + #if defined(_DEBUG) void lws_dll2_describe(lws_dll2_owner_t *owner, const char *desc) { +#if _LWS_ENABLED_LOGS & LLL_INFO int n = 1; lwsl_info("%s: %s: owner %p: count %d, head %p, tail %p\n", - __func__, desc, owner, owner->count, owner->head, owner->tail); + __func__, desc, owner, (int)owner->count, owner->head, owner->tail); lws_start_foreach_dll_safe(struct lws_dll2 *, p, tp, lws_dll2_get_head(owner)) { lwsl_info("%s: %d: %p: owner %p, prev %p, next %p\n", __func__, n++, p, p->owner, p->prev, p->next); } lws_end_foreach_dll_safe(p, tp); +#endif } #endif diff -Nru libwebsockets-3.2.1/lib/core/lws_dll.c libwebsockets-4.1.6/lib/core/lws_dll.c --- libwebsockets-3.2.1/lib/core/lws_dll.c 2019-12-18 14:45:31.000000000 +0000 +++ libwebsockets-4.1.6/lib/core/lws_dll.c 1970-01-01 00:00:00.000000000 +0000 @@ -1,246 +0,0 @@ -/* - * libwebsockets - small server side websockets and web server implementation - * - * Copyright (C) 2010-2019 Andy Green - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation: - * version 2.1 of the License. - * - * This library is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with this library; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, - * MA 02110-1301 USA - */ - -#include "core/private.h" - -#ifdef LWS_HAVE_SYS_TYPES_H -#include -#endif - - -void -lws_dll_add_head(struct lws_dll *d, struct lws_dll *phead) -{ - if (!lws_dll_is_detached(d, phead)) { - assert(0); /* only wholly detached things can be added */ - return; - } - - /* our next guy is current first guy, if any */ - if (phead->next != d) - d->next = phead->next; - - /* if there is a next guy, set his prev ptr to our next ptr */ - if (d->next) - d->next->prev = d; - /* there is nobody previous to us, we are the head */ - d->prev = NULL; - - /* set the first guy to be us */ - phead->next = d; - - /* if there was nothing on the list before, we are also now the tail */ - if (!phead->prev) - phead->prev = d; - - assert(d->prev != d); - assert(d->next != d); -} - -void -lws_dll_add_tail(struct lws_dll *d, struct lws_dll *phead) -{ - if (!lws_dll_is_detached(d, phead)) { - assert(0); /* only wholly detached things can be added */ - return; - } - - /* our previous guy is current last guy */ - d->prev = phead->prev; - /* if there is a prev guy, set his next ptr to our prev ptr */ - if (d->prev) - d->prev->next = d; - /* our next ptr is NULL */ - d->next = NULL; - /* set the last guy to be us */ - phead->prev = d; - - /* list head is also us if we're the first */ - if (!phead->next) - phead->next = d; - - assert(d->prev != d); - assert(d->next != d); -} - -void -lws_dll_insert(struct lws_dll *n, struct lws_dll *target, - struct lws_dll *phead, int before) -{ - if (!lws_dll_is_detached(n, phead)) { - assert(0); /* only wholly detached things can be inserted */ - return; - } - if (!target) { - /* - * the case where there's no target identified degenerates to - * a simple add at head or tail - */ - if (before) { - lws_dll_add_head(n, phead); - return; - } - lws_dll_add_tail(n, phead); - return; - } - - /* - * in the case there's a target "cursor", we have to do the work to - * stitch the new guy in appropriately - */ - - if (before) { - /* - * we go before dd - * DDp <-> DD <-> DDn --> DDp <-> us <-> DD <-> DDn - */ - /* we point forward to dd */ - n->next = target; - /* we point back to what dd used to point back to */ - n->prev = target->prev; - /* DDp points forward to us now */ - if (target->prev) - target->prev->next = n; - /* DD points back to us now */ - target->prev = n; - - /* if target was the head, we are now the head */ - if (phead->next == target) - phead->next = n; - - /* since we are before another guy, we cannot become the tail */ - - } else { - /* - * we go after dd - * DDp <-> DD <-> DDn --> DDp <-> DD <-> us <-> DDn - */ - /* we point forward to what dd used to point forward to */ - n->next = target->next; - /* we point back to dd */ - n->prev = target; - /* DDn points back to us */ - if (target->next) - target->next->prev = n; - /* DD points forward to us */ - target->next = n; - - /* if target was the tail, we are now the tail */ - if (phead->prev == target) - phead->prev = n; - - /* since we go after another guy, we cannot become the head */ - } -} - -/* situation is: - * - * HEAD: struct lws_dll * = &entry1 - * - * Entry 1: struct lws_dll .pprev = &HEAD , .next = Entry 2 - * Entry 2: struct lws_dll .pprev = &entry1 , .next = &entry2 - * Entry 3: struct lws_dll .pprev = &entry2 , .next = NULL - * - * Delete Entry1: - * - * - HEAD = &entry2 - * - Entry2: .pprev = &HEAD, .next = &entry3 - * - Entry3: .pprev = &entry2, .next = NULL - * - * Delete Entry2: - * - * - HEAD = &entry1 - * - Entry1: .pprev = &HEAD, .next = &entry3 - * - Entry3: .pprev = &entry1, .next = NULL - * - * Delete Entry3: - * - * - HEAD = &entry1 - * - Entry1: .pprev = &HEAD, .next = &entry2 - * - Entry2: .pprev = &entry1, .next = NULL - * - */ - -void -lws_dll_remove(struct lws_dll *d) -{ - if (!d->prev && !d->next) - return; - - /* - * remove us - * - * USp <-> us <-> USn --> USp <-> USn - */ - - /* if we have a next guy, set his prev to our prev */ - if (d->next) - d->next->prev = d->prev; - - /* set our prev guy to our next guy instead of us */ - if (d->prev) - d->prev->next = d->next; - - /* we're out of the list, we should not point anywhere any more */ - d->prev = NULL; - d->next = NULL; -} - -void -lws_dll_remove_track_tail(struct lws_dll *d, struct lws_dll *phead) -{ - if (lws_dll_is_detached(d, phead)) { - assert(phead->prev != d); - assert(phead->next != d); - return; - } - - /* if we have a next guy, set his prev to our prev */ - if (d->next) - d->next->prev = d->prev; - - /* if we have a previous guy, set his next to our next */ - if (d->prev) - d->prev->next = d->next; - - if (phead->prev == d) - phead->prev = d->prev; - - if (phead->next == d) - phead->next = d->next; - - /* we're out of the list, we should not point anywhere any more */ - d->prev = NULL; - d->next = NULL; -} - - -int -lws_dll_foreach_safe(struct lws_dll *phead, void *user, - int (*cb)(struct lws_dll *d, void *user)) -{ - lws_start_foreach_dll_safe(struct lws_dll *, p, tp, phead->next) { - if (cb(p, user)) - return 1; - } lws_end_foreach_dll_safe(p, tp); - - return 0; -} diff -Nru libwebsockets-3.2.1/lib/core/private.h libwebsockets-4.1.6/lib/core/private.h --- libwebsockets-3.2.1/lib/core/private.h 2019-12-18 14:45:31.000000000 +0000 +++ libwebsockets-4.1.6/lib/core/private.h 1970-01-01 00:00:00.000000000 +0000 @@ -1,621 +0,0 @@ -/* - * libwebsockets - small server side websockets and web server implementation - * - * Copyright (C) 2010 - 2019 Andy Green - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation: - * version 2.1 of the License. - * - * This library is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with this library; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, - * MA 02110-1301 USA - */ - -#include "lws_config.h" -#include "lws_config_private.h" - -#if defined(LWS_WITH_CGI) && defined(LWS_HAVE_VFORK) && \ - !defined(NO_GNU_SOURCE_THIS_TIME) - #define _GNU_SOURCE -#endif - -/* -#if !defined(_POSIX_C_SOURCE) -#define _POSIX_C_SOURCE 200112L -#endif -*/ - -#include -#include -#include -#include -#include -#include -#include - -#ifdef LWS_HAVE_INTTYPES_H -#include -#endif - -#include - -#ifdef LWS_HAVE_SYS_TYPES_H - #include -#endif -#if defined(LWS_HAVE_SYS_STAT_H) && !defined(LWS_PLAT_OPTEE) - #include -#endif - -#if LWS_MAX_SMP > 1 - #include -#endif - -#ifndef LWS_DEF_HEADER_LEN -#define LWS_DEF_HEADER_LEN 4096 -#endif -#ifndef LWS_DEF_HEADER_POOL -#define LWS_DEF_HEADER_POOL 4 -#endif -#ifndef LWS_MAX_PROTOCOLS -#define LWS_MAX_PROTOCOLS 5 -#endif -#ifndef LWS_MAX_EXTENSIONS_ACTIVE -#define LWS_MAX_EXTENSIONS_ACTIVE 1 -#endif -#ifndef LWS_MAX_EXT_OFFERS -#define LWS_MAX_EXT_OFFERS 8 -#endif -#ifndef SPEC_LATEST_SUPPORTED -#define SPEC_LATEST_SUPPORTED 13 -#endif -#ifndef AWAITING_TIMEOUT -#define AWAITING_TIMEOUT 20 -#endif -#ifndef CIPHERS_LIST_STRING -#define CIPHERS_LIST_STRING "DEFAULT" -#endif -#ifndef LWS_SOMAXCONN -#define LWS_SOMAXCONN SOMAXCONN -#endif - -#define MAX_WEBSOCKET_04_KEY_LEN 128 - -#ifndef SYSTEM_RANDOM_FILEPATH -#define SYSTEM_RANDOM_FILEPATH "/dev/urandom" -#endif - -#define LWS_H2_RX_SCRATCH_SIZE 512 - -#define lws_socket_is_valid(x) (x != LWS_SOCK_INVALID) - -#ifndef LWS_HAVE_STRERROR - #define strerror(x) "" -#endif - - - /* - * - * ------ private platform defines ------ - * - */ - -#if defined(LWS_WITH_ESP32) - #include "plat/esp32/private.h" -#else - #if defined(WIN32) || defined(_WIN32) - #include "plat/windows/private.h" - #else - #if defined(LWS_PLAT_OPTEE) - #include "plat/optee/private.h" - #else - #include "plat/unix/private.h" - #endif - #endif -#endif - - /* - * - * ------ public api ------ - * - */ - -#include "libwebsockets.h" - -#include "tls/private.h" - -#if defined(WIN32) || defined(_WIN32) - // Visual studio older than 2015 and WIN_CE has only _stricmp - #if (defined(_MSC_VER) && _MSC_VER < 1900) || defined(_WIN32_WCE) - #define strcasecmp _stricmp - #define strncasecmp _strnicmp - #elif !defined(__MINGW32__) - #define strcasecmp stricmp - #define strncasecmp strnicmp - #endif - #define getdtablesize() 30000 -#endif - -#ifndef LWS_ARRAY_SIZE -#define LWS_ARRAY_SIZE(x) (sizeof(x) / sizeof(x[0])) -#endif - -#ifdef __cplusplus -extern "C" { -#endif - - - -#if defined(__clang__) -#define lws_memory_barrier() __sync_synchronize() -#elif defined(__GNUC__) -#define lws_memory_barrier() __sync_synchronize() -#else -#define lws_memory_barrier() -#endif - - -struct lws_ring { - void *buf; - void (*destroy_element)(void *element); - uint32_t buflen; - uint32_t element_len; - uint32_t head; - uint32_t oldest_tail; -}; - -struct lws_protocols; -struct lws; - -#if defined(LWS_WITH_NETWORK) -#include "event-libs/private.h" - - -struct lws_io_watcher { -#ifdef LWS_WITH_LIBEV - struct lws_io_watcher_libev ev; -#endif -#ifdef LWS_WITH_LIBUV - struct lws_io_watcher_libuv uv; -#endif -#ifdef LWS_WITH_LIBEVENT - struct lws_io_watcher_libevent event; -#endif - struct lws_context *context; - - uint8_t actual_events; -}; - -struct lws_signal_watcher { -#ifdef LWS_WITH_LIBEV - struct lws_signal_watcher_libev ev; -#endif -#ifdef LWS_WITH_LIBUV - struct lws_signal_watcher_libuv uv; -#endif -#ifdef LWS_WITH_LIBEVENT - struct lws_signal_watcher_libevent event; -#endif - struct lws_context *context; -}; - -struct lws_foreign_thread_pollfd { - struct lws_foreign_thread_pollfd *next; - int fd_index; - int _and; - int _or; -}; -#endif - -#if LWS_MAX_SMP > 1 - -struct lws_mutex_refcount { - pthread_mutex_t lock; - pthread_t lock_owner; - const char *last_lock_reason; - char lock_depth; - char metadata; -}; - -void -lws_mutex_refcount_init(struct lws_mutex_refcount *mr); - -void -lws_mutex_refcount_destroy(struct lws_mutex_refcount *mr); - -void -lws_mutex_refcount_lock(struct lws_mutex_refcount *mr, const char *reason); - -void -lws_mutex_refcount_unlock(struct lws_mutex_refcount *mr); -#endif - -#if defined(LWS_WITH_NETWORK) -#include "core-net/private.h" -#endif - -struct lws_deferred_free -{ - struct lws_deferred_free *next; - time_t deadline; - void *payload; -}; - -/* - * the rest is managed per-context, that includes - * - * - processwide single fd -> wsi lookup - * - contextwide headers pool - */ - -struct lws_context { - time_t last_ws_ping_pong_check_s; - lws_usec_t time_up; /* monotonic */ - const struct lws_plat_file_ops *fops; - struct lws_plat_file_ops fops_platform; - struct lws_context **pcontext_finalize; - - const struct lws_tls_ops *tls_ops; - - const char *username, *groupname; - -#if defined(LWS_WITH_HTTP2) - struct http2_settings set; -#endif -#if defined(LWS_WITH_ZIP_FOPS) - struct lws_plat_file_ops fops_zip; -#endif -#if defined(LWS_WITH_NETWORK) - struct lws_context_per_thread pt[LWS_MAX_SMP]; - struct lws_conn_stats conn_stats; - struct lws_vhost *vhost_list; - struct lws_vhost *no_listener_vhost_list; - struct lws_vhost *vhost_pending_destruction_list; - struct lws_plugin *plugin_list; -#ifdef _WIN32 -/* different implementation between unix and windows */ - struct lws_fd_hashtable fd_hashtable[FD_HASHTABLE_MODULUS]; -#else - struct lws **lws_lookup; - -#endif -#endif -#if LWS_MAX_SMP > 1 - struct lws_mutex_refcount mr; -#endif - -#if defined(LWS_AMAZON_RTOS) - mbedtls_entropy_context mec; - mbedtls_ctr_drbg_context mcdc; -#endif - - struct lws_deferred_free *deferred_free_list; - -#if defined(LWS_WITH_THREADPOOL) - struct lws_threadpool *tp_list_head; -#endif - -#if defined(LWS_WITH_PEER_LIMITS) - struct lws_peer **pl_hash_table; - struct lws_peer *peer_wait_list; - time_t next_cull; -#endif - - const lws_system_ops_t *system_ops; - void *external_baggage_free_on_destroy; - const struct lws_token_limits *token_limits; - void *user_space; - const struct lws_protocol_vhost_options *reject_service_keywords; - lws_reload_func deprecation_cb; - void (*eventlib_signal_cb)(void *event_lib_handle, int signum); - -#if defined(LWS_HAVE_SYS_CAPABILITY_H) && defined(LWS_HAVE_LIBCAP) - cap_value_t caps[4]; - char count_caps; -#endif - -#if defined(LWS_WITH_NETWORK) -#if defined(LWS_WITH_LIBEV) - struct lws_context_eventlibs_libev ev; -#endif -#if defined(LWS_WITH_LIBUV) - struct lws_context_eventlibs_libuv uv; -#endif -#if defined(LWS_WITH_LIBEVENT) - struct lws_context_eventlibs_libevent event; -#endif - struct lws_event_loop_ops *event_loop_ops; -#endif - -#if defined(LWS_WITH_TLS) && defined(LWS_WITH_NETWORK) - struct lws_context_tls tls; -#endif - - char canonical_hostname[128]; - const char *server_string; - -#ifdef LWS_LATENCY - unsigned long worst_latency; - char worst_latency_info[256]; -#endif - -#if defined(LWS_WITH_ESP32) - unsigned long time_last_state_dump; - uint32_t last_free_heap; -#endif - - int max_fds; - int count_event_loop_static_asset_handles; -#if !defined(LWS_NO_DAEMONIZE) - pid_t started_with_parent; -#endif - int uid, gid; - - int fd_random; - - int count_wsi_allocated; - int count_cgi_spawned; - unsigned int options; - unsigned int fd_limit_per_thread; - unsigned int timeout_secs; - unsigned int pt_serv_buf_size; - int max_http_header_data; - int max_http_header_pool; - int simultaneous_ssl_restriction; - int simultaneous_ssl; -#if defined(LWS_WITH_PEER_LIMITS) - uint32_t pl_hash_elements; /* protected by context->lock */ - uint32_t count_peers; /* protected by context->lock */ - unsigned short ip_limit_ah; - unsigned short ip_limit_wsi; -#endif - unsigned int deprecated:1; - unsigned int being_destroyed:1; - unsigned int being_destroyed1:1; - unsigned int being_destroyed2:1; - unsigned int requested_kill:1; - unsigned int protocol_init_done:1; - unsigned int doing_protocol_init:1; - unsigned int done_protocol_destroy_cb:1; - unsigned int finalize_destroy_after_internal_loops_stopped:1; - unsigned int max_fds_unrelated_to_ulimit:1; - - short count_threads; - short plugin_protocol_count; - short plugin_extension_count; - short server_string_len; - unsigned short ws_ping_pong_interval; - unsigned short deprecation_pending_listen_close_count; - - uint8_t max_fi; - -#if defined(LWS_WITH_STATS) - uint8_t updated; -#endif -}; - -int -lws_check_deferred_free(struct lws_context *context, int tsi, int force); - -#define lws_get_context_protocol(ctx, x) ctx->vhost_list->protocols[x] -#define lws_get_vh_protocol(vh, x) vh->protocols[x] - -int -lws_jws_base64_enc(const char *in, size_t in_len, char *out, size_t out_max); - -void -lws_vhost_destroy1(struct lws_vhost *vh); - - -#if defined(LWS_WITH_ESP32) -LWS_EXTERN int -lws_find_string_in_file(const char *filename, const char *str, int stringlen); -#endif - - -signed char char_to_hex(const char c); - - -struct lws_buflist { - struct lws_buflist *next; - - size_t len; - size_t pos; - - uint8_t buf[1]; /* true length of this is set by the oversize malloc */ -}; - - -LWS_EXTERN char * -lws_strdup(const char *s); - -LWS_EXTERN int log_level; - - - -#ifndef LWS_LATENCY -static LWS_INLINE void -lws_latency(struct lws_context *context, struct lws *wsi, const char *action, - int ret, int completion) { - do { - (void)context; (void)wsi; (void)action; (void)ret; - (void)completion; - } while (0); -} -static LWS_INLINE void -lws_latency_pre(struct lws_context *context, struct lws *wsi) { - do { (void)context; (void)wsi; } while (0); -} -#else -#define lws_latency_pre(_context, _wsi) lws_latency(_context, _wsi, NULL, 0, 0) -extern void -lws_latency(struct lws_context *context, struct lws *wsi, const char *action, - int ret, int completion); -#endif - - -LWS_EXTERN int -lws_b64_selftest(void); - - - - - -#ifndef LWS_NO_DAEMONIZE - LWS_EXTERN pid_t get_daemonize_pid(); -#else - #define get_daemonize_pid() (0) -#endif - -LWS_EXTERN void lwsl_emit_stderr(int level, const char *line); - -#if !defined(LWS_WITH_TLS) - #define LWS_SSL_ENABLED(context) (0) - #define lws_context_init_server_ssl(_a, _b) (0) - #define lws_ssl_destroy(_a) - #define lws_context_init_alpn(_a) - #define lws_ssl_capable_read lws_ssl_capable_read_no_ssl - #define lws_ssl_capable_write lws_ssl_capable_write_no_ssl - #define lws_ssl_pending lws_ssl_pending_no_ssl - #define lws_server_socket_service_ssl(_b, _c) (0) - #define lws_ssl_close(_a) (0) - #define lws_ssl_context_destroy(_a) - #define lws_ssl_SSL_CTX_destroy(_a) - #define lws_ssl_remove_wsi_from_buffered_list(_a) - #define __lws_ssl_remove_wsi_from_buffered_list(_a) - #define lws_context_init_ssl_library(_a) - #define lws_context_deinit_ssl_library(_a) - #define lws_tls_check_all_cert_lifetimes(_a) - #define lws_tls_acme_sni_cert_destroy(_a) -#endif - - - -#if LWS_MAX_SMP > 1 -#define lws_context_lock(c, reason) lws_mutex_refcount_lock(&c->mr, reason) -#define lws_context_unlock(c) lws_mutex_refcount_unlock(&c->mr) - -static LWS_INLINE void -lws_vhost_lock(struct lws_vhost *vhost) -{ - pthread_mutex_lock(&vhost->lock); -} - -static LWS_INLINE void -lws_vhost_unlock(struct lws_vhost *vhost) -{ - pthread_mutex_unlock(&vhost->lock); -} - - -#else -#define lws_pt_mutex_init(_a) (void)(_a) -#define lws_pt_mutex_destroy(_a) (void)(_a) -#define lws_pt_lock(_a, b) (void)(_a) -#define lws_pt_unlock(_a) (void)(_a) -#define lws_context_lock(_a, _b) (void)(_a) -#define lws_context_unlock(_a) (void)(_a) -#define lws_vhost_lock(_a) (void)(_a) -#define lws_vhost_unlock(_a) (void)(_a) -#define lws_pt_stats_lock(_a) (void)(_a) -#define lws_pt_stats_unlock(_a) (void)(_a) -#endif - -LWS_EXTERN int LWS_WARN_UNUSED_RESULT -lws_ssl_capable_read_no_ssl(struct lws *wsi, unsigned char *buf, int len); - -LWS_EXTERN int LWS_WARN_UNUSED_RESULT -lws_ssl_capable_write_no_ssl(struct lws *wsi, unsigned char *buf, int len); - -LWS_EXTERN int LWS_WARN_UNUSED_RESULT -lws_ssl_pending_no_ssl(struct lws *wsi); - -int -lws_tls_check_cert_lifetime(struct lws_vhost *vhost); - -int lws_jws_selftest(void); -int lws_jwe_selftest(void); - -int -lws_protocol_init(struct lws_context *context); - -int -lws_bind_protocol(struct lws *wsi, const struct lws_protocols *p, - const char *reason); - -const struct lws_protocol_vhost_options * -lws_vhost_protocol_options(struct lws_vhost *vh, const char *name); - -const struct lws_http_mount * -lws_find_mount(struct lws *wsi, const char *uri_ptr, int uri_len); - -/* - * custom allocator - */ -LWS_EXTERN void * -lws_realloc(void *ptr, size_t size, const char *reason); - -LWS_EXTERN void * LWS_WARN_UNUSED_RESULT -lws_zalloc(size_t size, const char *reason); - -#ifdef LWS_PLAT_OPTEE -void *lws_malloc(size_t size, const char *reason); -void lws_free(void *p); -#define lws_free_set_NULL(P) do { lws_free(P); (P) = NULL; } while(0) -#else -#define lws_malloc(S, R) lws_realloc(NULL, S, R) -#define lws_free(P) lws_realloc(P, 0, "lws_free") -#define lws_free_set_NULL(P) do { lws_realloc(P, 0, "free"); (P) = NULL; } while(0) -#endif - -int -lws_create_event_pipes(struct lws_context *context); - -int -lws_plat_apply_FD_CLOEXEC(int n); - -const struct lws_plat_file_ops * -lws_vfs_select_fops(const struct lws_plat_file_ops *fops, const char *vfs_path, - const char **vpath); - -/* lws_plat_ */ - -LWS_EXTERN int -lws_plat_context_early_init(void); -LWS_EXTERN void -lws_plat_context_early_destroy(struct lws_context *context); -LWS_EXTERN void -lws_plat_context_late_destroy(struct lws_context *context); - -LWS_EXTERN int -lws_plat_init(struct lws_context *context, - const struct lws_context_creation_info *info); -LWS_EXTERN int -lws_plat_drop_app_privileges(struct lws_context *context, int actually_drop); - -#if defined(LWS_WITH_UNIX_SOCK) -int -lws_plat_user_colon_group_to_ids(const char *u_colon_g, uid_t *puid, gid_t *pgid); -#endif - -LWS_EXTERN int -lws_check_byte_utf8(unsigned char state, unsigned char c); -LWS_EXTERN int LWS_WARN_UNUSED_RESULT -lws_check_utf8(unsigned char *state, unsigned char *buf, size_t len); -LWS_EXTERN int alloc_file(struct lws_context *context, const char *filename, - uint8_t **buf, lws_filepos_t *amount); - -void -lws_context_destroy2(struct lws_context *context); - - -#ifdef __cplusplus -}; -#endif diff -Nru libwebsockets-3.2.1/lib/core/private-lib-core.h libwebsockets-4.1.6/lib/core/private-lib-core.h --- libwebsockets-3.2.1/lib/core/private-lib-core.h 1970-01-01 00:00:00.000000000 +0000 +++ libwebsockets-4.1.6/lib/core/private-lib-core.h 2020-12-01 17:40:26.000000000 +0000 @@ -0,0 +1,741 @@ +/* + * libwebsockets - small server side websockets and web server implementation + * + * Copyright (C) 2010 - 2019 Andy Green + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to + * deal in the Software without restriction, including without limitation the + * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or + * sell copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS + * IN THE SOFTWARE. + */ + +#if !defined(__LWS_PRIVATE_LIB_CORE_H__) +#define __LWS_PRIVATE_LIB_CORE_H__ + +#include "lws_config.h" +#include "lws_config_private.h" + + +#if defined(LWS_WITH_CGI) && defined(LWS_HAVE_VFORK) && \ + !defined(NO_GNU_SOURCE_THIS_TIME) && !defined(_GNU_SOURCE) + #define _GNU_SOURCE +#endif + +/* +#if !defined(_POSIX_C_SOURCE) +#define _POSIX_C_SOURCE 200112L +#endif +*/ + +#include +#include +#include +#include +#include +#include +#include +#include + +#ifdef LWS_HAVE_INTTYPES_H +#include +#endif + +#include + +#ifdef LWS_HAVE_SYS_TYPES_H + #include +#endif +#if defined(LWS_HAVE_SYS_STAT_H) && !defined(LWS_PLAT_OPTEE) + #include +#endif + +#if LWS_MAX_SMP > 1 || defined(LWS_WITH_SYS_SMD) + /* https://stackoverflow.com/questions/33557506/timespec-redefinition-error */ + #define HAVE_STRUCT_TIMESPEC + #include +#else + #if !defined(pid_t) && defined(WIN32) + #define pid_t int + #endif +#endif + +#ifndef LWS_DEF_HEADER_LEN +#define LWS_DEF_HEADER_LEN 4096 +#endif +#ifndef LWS_DEF_HEADER_POOL +#define LWS_DEF_HEADER_POOL 4 +#endif +#ifndef LWS_MAX_PROTOCOLS +#define LWS_MAX_PROTOCOLS 5 +#endif +#ifndef LWS_MAX_EXTENSIONS_ACTIVE +#define LWS_MAX_EXTENSIONS_ACTIVE 1 +#endif +#ifndef LWS_MAX_EXT_OFFERS +#define LWS_MAX_EXT_OFFERS 8 +#endif +#ifndef SPEC_LATEST_SUPPORTED +#define SPEC_LATEST_SUPPORTED 13 +#endif +#ifndef CIPHERS_LIST_STRING +#define CIPHERS_LIST_STRING "DEFAULT" +#endif +#ifndef LWS_SOMAXCONN +#define LWS_SOMAXCONN SOMAXCONN +#endif + +#define MAX_WEBSOCKET_04_KEY_LEN 128 + +#ifndef SYSTEM_RANDOM_FILEPATH +#define SYSTEM_RANDOM_FILEPATH "/dev/urandom" +#endif + +#define LWS_H2_RX_SCRATCH_SIZE 512 + +#define lws_socket_is_valid(x) (x != LWS_SOCK_INVALID) + +#ifndef LWS_HAVE_STRERROR + #define strerror(x) "" +#endif + + + /* + * + * ------ private platform defines ------ + * + */ + +#if defined(LWS_PLAT_FREERTOS) + #include "private-lib-plat-freertos.h" +#else + #if defined(WIN32) || defined(_WIN32) + #include "private-lib-plat-windows.h" + #else + #if defined(LWS_PLAT_OPTEE) + #include "private-lib-plat.h" + #else + #include "private-lib-plat-unix.h" + #endif + #endif +#endif + + /* + * + * ------ public api ------ + * + */ + +#include "libwebsockets.h" + + +/* + * Generic bidi tx credit management + */ + +struct lws_tx_credit { + int32_t tx_cr; /* our credit to write peer */ + int32_t peer_tx_cr_est; /* peer's credit to write us */ + + int32_t manual_initial_tx_credit; + + uint8_t skint; /* unable to write anything */ + uint8_t manual; +}; + +#ifdef LWS_WITH_IPV6 +#if defined(WIN32) || defined(_WIN32) +#include +#else +#include +#endif +#endif + +#undef X509_NAME + +#if defined(LWS_WITH_TLS) +#include "private-lib-tls.h" +#endif + +#if defined(WIN32) || defined(_WIN32) + // Visual studio older than 2015 and WIN_CE has only _stricmp + #if (defined(_MSC_VER) && _MSC_VER < 1900) || defined(_WIN32_WCE) + #define strcasecmp _stricmp + #define strncasecmp _strnicmp + #elif !defined(__MINGW32__) + #define strcasecmp stricmp + #define strncasecmp strnicmp + #endif + #define getdtablesize() 30000 +#endif + +#ifndef LWS_ARRAY_SIZE +#define LWS_ARRAY_SIZE(x) (sizeof(x) / sizeof(x[0])) +#endif + +#ifdef __cplusplus +extern "C" { +#endif + +#define lws_safe_modulo(_a, _b) ((_b) ? ((_a) % (_b)) : 0) + +#if defined(__clang__) +#define lws_memory_barrier() __sync_synchronize() +#elif defined(__GNUC__) +#define lws_memory_barrier() __sync_synchronize() +#else +#define lws_memory_barrier() +#endif + + +struct lws_ring { + void *buf; + void (*destroy_element)(void *element); + uint32_t buflen; + uint32_t element_len; + uint32_t head; + uint32_t oldest_tail; +}; + +struct lws_protocols; +struct lws; + +#if defined(LWS_WITH_NETWORK) /* network */ +#include "private-lib-event-libs.h" + +#if defined(LWS_WITH_SECURE_STREAMS) +#include "private-lib-secure-streams.h" +#endif + +#if defined(LWS_WITH_SYS_SMD) +#include "private-lib-system-smd.h" +#endif + +struct lws_foreign_thread_pollfd { + struct lws_foreign_thread_pollfd *next; + int fd_index; + int _and; + int _or; +}; +#endif /* network */ + +#if defined(LWS_WITH_NETWORK) +#include "private-lib-core-net.h" +#endif + +struct lws_deferred_free +{ + struct lws_deferred_free *next; + time_t deadline; + void *payload; +}; + +struct lws_system_blob { + union { + struct lws_buflist *bl; + struct { + const uint8_t *ptr; + size_t len; + } direct; + } u; + char is_direct; +}; + + +typedef struct lws_attach_item { + lws_dll2_t list; + lws_attach_cb_t cb; + void *opaque; + lws_system_states_t state; +} lws_attach_item_t; + +/* + * the rest is managed per-context, that includes + * + * - processwide single fd -> wsi lookup + * - contextwide headers pool + */ + +struct lws_context { + #if defined(LWS_WITH_SERVER) + char canonical_hostname[96]; + #endif + +#if defined(LWS_WITH_FILE_OPS) + struct lws_plat_file_ops fops_platform; +#endif + +#if defined(LWS_WITH_ZIP_FOPS) + struct lws_plat_file_ops fops_zip; +#endif + + lws_system_blob_t system_blobs[LWS_SYSBLOB_TYPE_COUNT]; + +#if defined(LWS_WITH_SYS_SMD) + lws_smd_t smd; +#endif + +#if defined(LWS_WITH_NETWORK) + struct lws_context_per_thread pt[LWS_MAX_SMP]; + lws_retry_bo_t default_retry; + lws_sorted_usec_list_t sul_system_state; + +#if defined(LWS_PLAT_FREERTOS) + struct sockaddr_in frt_pipe_si; +#endif + +#if defined(LWS_WITH_HTTP2) + struct http2_settings set; +#endif + +#if defined(LWS_WITH_SERVER_STATUS) + struct lws_conn_stats conn_stats; +#endif +#if LWS_MAX_SMP > 1 + struct lws_mutex_refcount mr; +#endif + +#if defined(LWS_WITH_NETWORK) + +/* + * LWS_WITH_NETWORK =====> + */ + +#if defined(LWS_WITH_EVENT_LIBS) + struct lws_plugin *evlib_plugin_list; + void *evlib_ctx; /* overallocated */ +#endif + +#if defined(LWS_WITH_TLS) + struct lws_context_tls tls; +#endif +#if defined(LWS_WITH_DRIVERS) + lws_netdevs_t netdevs; +#endif + +#if defined(LWS_WITH_SYS_ASYNC_DNS) + lws_async_dns_t async_dns; +#endif + +#if defined(LWS_WITH_SYS_NTPCLIENT) + void *ntpclient_priv; +#endif + +#if defined(LWS_WITH_SECURE_STREAMS) + struct lws_ss_handle *hss_fetch_policy; +#if defined(LWS_WITH_SECURE_STREAMS_SYS_AUTH_API_AMAZON_COM) + struct lws_ss_handle *hss_auth; + lws_sorted_usec_list_t sul_api_amazon_com; + lws_sorted_usec_list_t sul_api_amazon_com_kick; +#endif +#if !defined(LWS_WITH_SECURE_STREAMS_STATIC_POLICY_ONLY) + struct lws_ss_x509 *server_der_list; +#endif +#endif + +#if defined(LWS_WITH_SYS_STATE) + lws_state_manager_t mgr_system; + lws_state_notify_link_t protocols_notify; +#endif +#if defined (LWS_WITH_SYS_DHCP_CLIENT) + lws_dll2_owner_t dhcpc_owner; + /**< list of ifaces with dhcpc */ +#endif + + /* pointers */ + + struct lws_vhost *vhost_list; + struct lws_vhost *no_listener_vhost_list; + struct lws_vhost *vhost_pending_destruction_list; + struct lws_vhost *vhost_system; + +#if defined(LWS_WITH_SERVER) + const char *server_string; +#endif + + const struct lws_event_loop_ops *event_loop_ops; +#endif + +#if defined(LWS_WITH_TLS) + const struct lws_tls_ops *tls_ops; +#endif + +#if defined(LWS_WITH_DETAILED_LATENCY) + det_lat_buf_cb_t detailed_latency_cb; +#endif +#if defined(LWS_WITH_PLUGINS) + struct lws_plugin *plugin_list; +#endif +#ifdef _WIN32 +/* different implementation between unix and windows */ + struct lws_fd_hashtable fd_hashtable[FD_HASHTABLE_MODULUS]; +#else + struct lws **lws_lookup; + +#endif + +/* + * <====== LWS_WITH_NETWORK end + */ + +#endif /* NETWORK */ + +#if defined(LWS_WITH_SECURE_STREAMS_PROXY_API) + const char *ss_proxy_bind; + const char *ss_proxy_address; +#endif + +#if defined(LWS_WITH_FILE_OPS) + const struct lws_plat_file_ops *fops; +#endif + + struct lws_context **pcontext_finalize; +#if !defined(LWS_PLAT_FREERTOS) + const char *username, *groupname; +#endif +#if defined(LWS_WITH_DETAILED_LATENCY) + const char *detailed_latency_filepath; +#endif + +#if defined(LWS_AMAZON_RTOS) && defined(LWS_WITH_MBEDTLS) + mbedtls_entropy_context mec; + mbedtls_ctr_drbg_context mcdc; +#endif + + struct lws_deferred_free *deferred_free_list; + +#if defined(LWS_WITH_THREADPOOL) + struct lws_threadpool *tp_list_head; +#endif + +#if defined(LWS_WITH_PEER_LIMITS) + struct lws_peer **pl_hash_table; + struct lws_peer *peer_wait_list; + lws_peer_limits_notify_t pl_notify_cb; + time_t next_cull; +#endif + + const lws_system_ops_t *system_ops; + +#if defined(LWS_WITH_SECURE_STREAMS) +#if !defined(LWS_WITH_SECURE_STREAMS_STATIC_POLICY_ONLY) + const char *pss_policies_json; + struct lwsac *ac_policy; + void *pol_args; +#endif + const lws_ss_policy_t *pss_policies; +#if defined(LWS_WITH_SSPLUGINS) + const lws_ss_plugin_t **pss_plugins; +#endif +#endif + + void *external_baggage_free_on_destroy; + const struct lws_token_limits *token_limits; + void *user_space; +#if defined(LWS_WITH_SERVER) + const struct lws_protocol_vhost_options *reject_service_keywords; + lws_reload_func deprecation_cb; +#endif +#if !defined(LWS_PLAT_FREERTOS) + void (*eventlib_signal_cb)(void *event_lib_handle, int signum); +#endif + +#if defined(LWS_HAVE_SYS_CAPABILITY_H) && defined(LWS_HAVE_LIBCAP) + cap_value_t caps[4]; + char count_caps; +#endif + + lws_usec_t time_up; /* monotonic */ + + uint64_t options; + + time_t last_ws_ping_pong_check_s; + +#if defined(LWS_PLAT_FREERTOS) + unsigned long time_last_state_dump; + uint32_t last_free_heap; +#endif + + int max_fds; +#if !defined(LWS_NO_DAEMONIZE) + pid_t started_with_parent; +#endif + +#if !defined(LWS_PLAT_FREERTOS) + int uid, gid; + int count_event_loop_static_asset_handles; + int fd_random; + int count_cgi_spawned; +#endif + +#if defined(LWS_WITH_DETAILED_LATENCY) + int latencies_fd; +#endif + int count_wsi_allocated; + unsigned int fd_limit_per_thread; + unsigned int timeout_secs; + unsigned int pt_serv_buf_size; + int max_http_header_data; + int max_http_header_pool; + int simultaneous_ssl_restriction; + int simultaneous_ssl; +#if defined(LWS_WITH_PEER_LIMITS) + uint32_t pl_hash_elements; /* protected by context->lock */ + uint32_t count_peers; /* protected by context->lock */ + unsigned short ip_limit_ah; + unsigned short ip_limit_wsi; +#endif + unsigned int deprecated:1; + unsigned int inside_context_destroy:1; + unsigned int being_destroyed:1; + unsigned int being_destroyed1:1; + unsigned int being_destroyed2:1; + unsigned int requested_kill:1; + unsigned int protocol_init_done:1; + unsigned int doing_protocol_init:1; + unsigned int done_protocol_destroy_cb:1; + unsigned int finalize_destroy_after_internal_loops_stopped:1; + unsigned int max_fds_unrelated_to_ulimit:1; + unsigned int policy_updated:1; + + short count_threads; + short plugin_protocol_count; + short plugin_extension_count; + short server_string_len; + unsigned short deprecation_pending_listen_close_count; +#if defined(LWS_WITH_SECURE_STREAMS_PROXY_API) + uint16_t ss_proxy_port; +#endif + + uint8_t max_fi; + uint8_t udp_loss_sim_tx_pc; + uint8_t udp_loss_sim_rx_pc; + uint8_t captive_portal_detect; + uint8_t captive_portal_detect_type; + +#if defined(LWS_WITH_STATS) + uint8_t updated; +#endif +}; + +int +lws_check_deferred_free(struct lws_context *context, int tsi, int force); + +#define lws_get_context_protocol(ctx, x) ctx->vhost_list->protocols[x] +#define lws_get_vh_protocol(vh, x) vh->protocols[x] + +int +lws_jws_base64_enc(const char *in, size_t in_len, char *out, size_t out_max); + +void +lws_vhost_destroy1(struct lws_vhost *vh); + + +#if defined(LWS_PLAT_FREERTOS) +LWS_EXTERN int +lws_find_string_in_file(const char *filename, const char *str, int stringlen); +#endif + +signed char char_to_hex(const char c); + +#if defined(LWS_WITH_NETWORK) +int +lws_system_do_attach(struct lws_context_per_thread *pt); +#endif + +struct lws_buflist { + struct lws_buflist *next; + size_t len; + size_t pos; +}; + +LWS_EXTERN char * +lws_strdup(const char *s); + +LWS_EXTERN int log_level; + +LWS_EXTERN int +lws_b64_selftest(void); + + +#ifndef LWS_NO_DAEMONIZE + LWS_EXTERN pid_t get_daemonize_pid(); +#else + #define get_daemonize_pid() (0) +#endif + +LWS_EXTERN void lwsl_emit_stderr(int level, const char *line); + +#if !defined(LWS_WITH_TLS) + #define LWS_SSL_ENABLED(context) (0) + #define lws_context_init_server_ssl(_a, _b) (0) + #define lws_ssl_destroy(_a) + #define lws_context_init_alpn(_a) + #define lws_ssl_capable_read lws_ssl_capable_read_no_ssl + #define lws_ssl_capable_write lws_ssl_capable_write_no_ssl + #define lws_ssl_pending lws_ssl_pending_no_ssl + #define lws_server_socket_service_ssl(_b, _c, _d) (0) + #define lws_ssl_close(_a) (0) + #define lws_ssl_context_destroy(_a) + #define lws_ssl_SSL_CTX_destroy(_a) + #define lws_ssl_remove_wsi_from_buffered_list(_a) + #define __lws_ssl_remove_wsi_from_buffered_list(_a) + #define lws_context_init_ssl_library(_a) + #define lws_context_deinit_ssl_library(_a) + #define lws_tls_check_all_cert_lifetimes(_a) + #define lws_tls_acme_sni_cert_destroy(_a) +#endif + + + +#if LWS_MAX_SMP > 1 +#define lws_context_lock(c, reason) lws_mutex_refcount_lock(&c->mr, reason) +#define lws_context_unlock(c) lws_mutex_refcount_unlock(&c->mr) + +static LWS_INLINE void +lws_vhost_lock(struct lws_vhost *vhost) +{ + pthread_mutex_lock(&vhost->lock); +} + +static LWS_INLINE void +lws_vhost_unlock(struct lws_vhost *vhost) +{ + pthread_mutex_unlock(&vhost->lock); +} + + +#else +#define lws_pt_mutex_init(_a) (void)(_a) +#define lws_pt_mutex_destroy(_a) (void)(_a) +#define lws_pt_lock(_a, b) (void)(_a) +#define lws_pt_assert_lock_held(_a) (void)(_a) +#define lws_pt_unlock(_a) (void)(_a) +#define lws_context_lock(_a, _b) (void)(_a) +#define lws_context_unlock(_a) (void)(_a) +#define lws_vhost_lock(_a) (void)(_a) +#define lws_vhost_unlock(_a) (void)(_a) +#define lws_pt_stats_lock(_a) (void)(_a) +#define lws_pt_stats_unlock(_a) (void)(_a) +#endif + +LWS_EXTERN int LWS_WARN_UNUSED_RESULT +lws_ssl_capable_read_no_ssl(struct lws *wsi, unsigned char *buf, int len); + +LWS_EXTERN int LWS_WARN_UNUSED_RESULT +lws_ssl_capable_write_no_ssl(struct lws *wsi, unsigned char *buf, int len); + +LWS_EXTERN int LWS_WARN_UNUSED_RESULT +lws_ssl_pending_no_ssl(struct lws *wsi); + +int +lws_tls_check_cert_lifetime(struct lws_vhost *vhost); + +int lws_jws_selftest(void); +int lws_jwe_selftest(void); + +int +lws_protocol_init(struct lws_context *context); + +int +lws_bind_protocol(struct lws *wsi, const struct lws_protocols *p, + const char *reason); + +const struct lws_protocol_vhost_options * +lws_vhost_protocol_options(struct lws_vhost *vh, const char *name); + +const struct lws_http_mount * +lws_find_mount(struct lws *wsi, const char *uri_ptr, int uri_len); + +/* + * custom allocator + */ +LWS_EXTERN void * +lws_realloc(void *ptr, size_t size, const char *reason); + +LWS_EXTERN void * LWS_WARN_UNUSED_RESULT +lws_zalloc(size_t size, const char *reason); + +#ifdef LWS_PLAT_OPTEE +void *lws_malloc(size_t size, const char *reason); +void lws_free(void *p); +#define lws_free_set_NULL(P) do { lws_free(P); (P) = NULL; } while(0) +#else +#define lws_malloc(S, R) lws_realloc(NULL, S, R) +#define lws_free(P) lws_realloc(P, 0, "lws_free") +#define lws_free_set_NULL(P) do { lws_realloc(P, 0, "free"); (P) = NULL; } while(0) +#endif + +int +lws_create_event_pipes(struct lws_context *context); + +int +lws_plat_apply_FD_CLOEXEC(int n); + +const struct lws_plat_file_ops * +lws_vfs_select_fops(const struct lws_plat_file_ops *fops, const char *vfs_path, + const char **vpath); + +/* lws_plat_ */ + +LWS_EXTERN int +lws_plat_context_early_init(void); +LWS_EXTERN void +lws_plat_context_early_destroy(struct lws_context *context); +LWS_EXTERN void +lws_plat_context_late_destroy(struct lws_context *context); + +LWS_EXTERN int +lws_plat_init(struct lws_context *context, + const struct lws_context_creation_info *info); +LWS_EXTERN int +lws_plat_drop_app_privileges(struct lws_context *context, int actually_drop); + +#if defined(LWS_WITH_UNIX_SOCK) && !defined(WIN32) +int +lws_plat_user_colon_group_to_ids(const char *u_colon_g, uid_t *puid, gid_t *pgid); +#endif + +int +lws_plat_ntpclient_config(struct lws_context *context); + +int +lws_plat_ifname_to_hwaddr(int fd, const char *ifname, uint8_t *hwaddr, int len); + +LWS_EXTERN int +lws_check_byte_utf8(unsigned char state, unsigned char c); +LWS_EXTERN int LWS_WARN_UNUSED_RESULT +lws_check_utf8(unsigned char *state, unsigned char *buf, size_t len); +LWS_EXTERN int alloc_file(struct lws_context *context, const char *filename, + uint8_t **buf, lws_filepos_t *amount); + +void lws_msleep(unsigned int); + +void +lws_context_destroy2(struct lws_context *context); + +#if !defined(PRIu64) +#define PRIu64 "llu" +#endif + +#if defined(LWS_WITH_ABSTRACT) +#include "private-lib-abstract.h" +#endif + +#ifdef __cplusplus +}; +#endif + +#endif diff -Nru libwebsockets-3.2.1/lib/core/vfs.c libwebsockets-4.1.6/lib/core/vfs.c --- libwebsockets-3.2.1/lib/core/vfs.c 2019-12-18 14:45:31.000000000 +0000 +++ libwebsockets-4.1.6/lib/core/vfs.c 2020-12-01 17:40:26.000000000 +0000 @@ -1,52 +1,54 @@ /* * libwebsockets - small server side websockets and web server implementation * - * Copyright (C) 2010-2019 Andy Green + * Copyright (C) 2010 - 2019 Andy Green * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation: - * version 2.1 of the License. + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to + * deal in the Software without restriction, including without limitation the + * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or + * sell copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: * - * This library is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. * - * You should have received a copy of the GNU Lesser General Public - * License along with this library; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, - * MA 02110-1301 USA + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS + * IN THE SOFTWARE. */ -#include "core/private.h" +#include "private-lib-core.h" - -LWS_VISIBLE LWS_EXTERN void +void lws_set_fops(struct lws_context *context, const struct lws_plat_file_ops *fops) { context->fops = fops; } -LWS_VISIBLE LWS_EXTERN lws_filepos_t +lws_filepos_t lws_vfs_tell(lws_fop_fd_t fop_fd) { return fop_fd->pos; } -LWS_VISIBLE LWS_EXTERN lws_filepos_t +lws_filepos_t lws_vfs_get_length(lws_fop_fd_t fop_fd) { return fop_fd->len; } -LWS_VISIBLE LWS_EXTERN uint32_t +uint32_t lws_vfs_get_mod_time(lws_fop_fd_t fop_fd) { return fop_fd->mod_time; } -LWS_VISIBLE lws_fileofs_t +lws_fileofs_t lws_vfs_file_seek_set(lws_fop_fd_t fop_fd, lws_fileofs_t offset) { lws_fileofs_t ofs; @@ -57,7 +59,7 @@ } -LWS_VISIBLE lws_fileofs_t +lws_fileofs_t lws_vfs_file_seek_end(lws_fop_fd_t fop_fd, lws_fileofs_t offset) { return fop_fd->fops->LWS_FOP_SEEK_CUR(fop_fd, fop_fd->len + @@ -113,7 +115,7 @@ return fops; } -LWS_VISIBLE LWS_EXTERN lws_fop_fd_t LWS_WARN_UNUSED_RESULT +lws_fop_fd_t LWS_WARN_UNUSED_RESULT lws_vfs_file_open(const struct lws_plat_file_ops *fops, const char *vfs_path, lws_fop_flags_t *flags) { @@ -126,7 +128,7 @@ } -LWS_VISIBLE struct lws_plat_file_ops * +struct lws_plat_file_ops * lws_get_fops(struct lws_context *context) { return (struct lws_plat_file_ops *)context->fops; diff -Nru libwebsockets-3.2.1/lib/core-net/adopt.c libwebsockets-4.1.6/lib/core-net/adopt.c --- libwebsockets-3.2.1/lib/core-net/adopt.c 2019-12-18 14:45:31.000000000 +0000 +++ libwebsockets-4.1.6/lib/core-net/adopt.c 2020-12-01 17:40:26.000000000 +0000 @@ -1,26 +1,28 @@ /* * libwebsockets - small server side websockets and web server implementation * - * Copyright (C) 2010-2018 Andy Green + * Copyright (C) 2010 - 2019 Andy Green * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation: - * version 2.1 of the License. + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to + * deal in the Software without restriction, including without limitation the + * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or + * sell copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: * - * This library is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. * - * You should have received a copy of the GNU Lesser General Public - * License along with this library; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, - * MA 02110-1301 USA + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS + * IN THE SOFTWARE. */ -#include "core/private.h" - +#include "private-lib-core.h" static int lws_get_idlest_tsi(struct lws_context *context) @@ -29,6 +31,8 @@ int n = 0, hit = -1; for (; n < context->count_threads; n++) { + lwsl_debug("%s: %d %d\n", __func__, context->pt[n].fds_count, + context->fd_limit_per_thread - 1); if ((unsigned int)context->pt[n].fds_count != context->fd_limit_per_thread - 1 && (unsigned int)context->pt[n].fds_count < lowest) { @@ -45,6 +49,7 @@ { struct lws *new_wsi; int n = fixed_tsi; + size_t s = sizeof(struct lws); if (n < 0) n = lws_get_idlest_tsi(vhost->context); @@ -54,21 +59,35 @@ return NULL; } - new_wsi = lws_zalloc(sizeof(struct lws), "new server wsi"); +#if defined(LWS_WITH_EVENT_LIBS) + s += vhost->context->event_loop_ops->evlib_size_wsi; +#endif + + new_wsi = lws_zalloc(s, "new server wsi"); if (new_wsi == NULL) { lwsl_err("Out of memory for new connection\n"); return NULL; } +#if defined(LWS_WITH_EVENT_LIBS) + new_wsi->evlib_wsi = (uint8_t *)new_wsi + sizeof(*new_wsi); +#endif + new_wsi->wsistate |= LWSIFR_SERVER; new_wsi->tsi = n; lwsl_debug("new wsi %p joining vhost %s, tsi %d\n", new_wsi, vhost->name, new_wsi->tsi); lws_vhost_bind_wsi(vhost, new_wsi); - new_wsi->context = vhost->context; + new_wsi->a.context = vhost->context; new_wsi->pending_timeout = NO_PENDING_TIMEOUT; new_wsi->rxflow_change_to = LWS_RXFLOW_ALLOW; + new_wsi->retry_policy = vhost->retry_policy; + +#if defined(LWS_WITH_DETAILED_LATENCY) + if (vhost->context->detailed_latency_cb) + new_wsi->detlat.earliest_write_req_pre_write = lws_now_usecs(); +#endif /* initialize the instance struct */ @@ -85,7 +104,7 @@ * to the start of the supported list, so it can look * for matching ones during the handshake */ - new_wsi->protocol = vhost->protocols; + new_wsi->a.protocol = vhost->protocols; new_wsi->user_space = NULL; new_wsi->desc.sockfd = LWS_SOCK_INVALID; new_wsi->position_in_fds_table = LWS_NO_FDS_POS; @@ -105,54 +124,38 @@ /* if not a socket, it's a raw, non-ssl file descriptor */ -LWS_VISIBLE struct lws * -lws_adopt_descriptor_vhost(struct lws_vhost *vh, lws_adoption_type type, - lws_sock_file_fd_type fd, const char *vh_prot_name, - struct lws *parent) +static struct lws * +lws_adopt_descriptor_vhost1(struct lws_vhost *vh, lws_adoption_type type, + const char *vh_prot_name, struct lws *parent, + void *opaque) { struct lws_context *context = vh->context; struct lws_context_per_thread *pt; struct lws *new_wsi; int n; -#if defined(LWS_WITH_PEER_LIMITS) - struct lws_peer *peer = NULL; - - if (type & LWS_ADOPT_SOCKET) { - peer = lws_get_or_create_peer(vh, fd.sockfd); - - if (peer && context->ip_limit_wsi && - peer->count_wsi >= context->ip_limit_wsi) { - lwsl_notice("Peer reached wsi limit %d\n", - context->ip_limit_wsi); - lws_stats_bump(&context->pt[0], - LWSSTATS_C_PEER_LIMIT_WSI_DENIED, - 1); - return NULL; - } - } -#endif - /* * Notice that in SMP case, the wsi may be being created on an * entirely different pt / tsi for load balancing. In that case as * we initialize it, it may become "live" concurrently unexpectedly... */ + lws_context_lock(vh->context, __func__); + n = -1; if (parent) n = parent->tsi; new_wsi = lws_create_new_server_wsi(vh, n); if (!new_wsi) { - if (type & LWS_ADOPT_SOCKET) - compatible_close(fd.sockfd); + lws_context_unlock(vh->context); return NULL; } -#if defined(LWS_WITH_PEER_LIMITS) - if (peer) - lws_peer_add_wsi(context, peer, new_wsi); -#endif + + new_wsi->a.opaque_user_data = opaque; + pt = &context->pt[(int)new_wsi->tsi]; + lws_pt_lock(pt, __func__); + lws_stats_bump(pt, LWSSTATS_C_CONNECTIONS, 1); if (parent) { @@ -161,13 +164,173 @@ parent->child_list = new_wsi; } + if (vh_prot_name) { + new_wsi->a.protocol = lws_vhost_name_to_protocol(new_wsi->a.vhost, + vh_prot_name); + if (!new_wsi->a.protocol) { + lwsl_err("Protocol %s not enabled on vhost %s\n", + vh_prot_name, new_wsi->a.vhost->name); + goto bail; + } + if (lws_ensure_user_space(new_wsi)) { + lwsl_notice("OOM trying to get user_space\n"); + goto bail; + } + } + + if (!LWS_SSL_ENABLED(new_wsi->a.vhost) || + !(type & LWS_ADOPT_SOCKET)) + type &= ~LWS_ADOPT_ALLOW_SSL; + + if (lws_role_call_adoption_bind(new_wsi, type, vh_prot_name)) { + lwsl_err("%s: no role for desc type 0x%x\n", __func__, type); + goto bail; + } + + lws_pt_unlock(pt); + + /* + * he's an allocated wsi, but he's not on any fds list or child list, + * join him to the vhost's list of these kinds of incomplete wsi until + * he gets another identity (he may do async dns now...) + */ + lws_vhost_lock(new_wsi->a.vhost); + lws_dll2_add_head(&new_wsi->vh_awaiting_socket, + &new_wsi->a.vhost->vh_awaiting_socket_owner); + lws_vhost_unlock(new_wsi->a.vhost); + + lws_context_unlock(vh->context); + + return new_wsi; + +bail: + lwsl_notice("%s: exiting on bail\n", __func__); + if (parent) + parent->child_list = new_wsi->sibling_list; + if (new_wsi->user_space) + lws_free(new_wsi->user_space); + + vh->context->count_wsi_allocated--; + + lws_vhost_unbind_wsi(new_wsi); + + lws_free(new_wsi); + + lws_pt_unlock(pt); + lws_context_unlock(vh->context); + + return NULL; +} + +#if defined(LWS_WITH_SERVER) && defined(LWS_WITH_SECURE_STREAMS) + +/* + * If the incoming wsi is bound to a vhost that is a ss server, this creates + * an accepted ss bound to the wsi. + * + * For h1 or raw, we can do the binding here, but for muxed protocols like h2 + * or mqtt we have to do it not on the nwsi but on the stream. And for h2 we + * start off bound to h1 role, since we don't know if we will upgrade to h2 + * until we meet the server. + * + * 1) No tls is assumed to mean no muxed protocol so can do it at adopt. + * + * 2) After alpn if not muxed we can do it. + * + * 3) For muxed, do it at the nwsi migration and on new stream + */ + +int +lws_adopt_ss_server_accept(struct lws *new_wsi) +{ + lws_ss_handle_t *h; + void *pv, **ppv; + + if (!new_wsi->a.vhost->ss_handle) + return 0; + + pv = (char *)&new_wsi->a.vhost->ss_handle[1]; + + /* + * Yes... the vhost is pointing to its secure stream representing the + * server... we want to create an accepted SS and bind it to new_wsi, + * the info/ssi from the server SS (so the SS callbacks defined there), + * the opaque_user_data of the server object and the policy of it. + */ + + ppv = (void **)((char *)pv + + new_wsi->a.vhost->ss_handle->info.opaque_user_data_offset); + + /* + * indicate we are an accepted connection referencing the + * server object + */ + + new_wsi->a.vhost->ss_handle->info.flags |= LWSSSINFLAGS_SERVER; + + if (lws_ss_create(new_wsi->a.context, new_wsi->tsi, + &new_wsi->a.vhost->ss_handle->info, + *ppv, &h, NULL, NULL)) { + lwsl_err("%s: accept ss creation failed\n", __func__); + goto fail1; + } + + /* + * We made a fresh accepted SS conn from the server pieces, + * now bind the wsi... the problem is, this is the nwsi if it's + * h2. + */ + + h->wsi = new_wsi; + new_wsi->a.opaque_user_data = h; + h->info.flags |= LWSSSINFLAGS_ACCEPTED; + new_wsi->for_ss = 1; /* indicate wsi should invalidate any ss link to it on close */ + + // lwsl_notice("%s: opaq %p, role %s\n", __func__, + // new_wsi->a.opaque_user_data, new_wsi->role_ops->name); + + h->policy = new_wsi->a.vhost->ss_handle->policy; + + /* + * Let's give it appropriate state notifications + */ + + if (lws_ss_event_helper(h, LWSSSCS_CREATING)) + goto fail; + if (lws_ss_event_helper(h, LWSSSCS_CONNECTING)) + goto fail; + if (lws_ss_event_helper(h, LWSSSCS_CONNECTED)) + goto fail; + + // lwsl_notice("%s: accepted ss complete, pcol %s\n", __func__, + // new_wsi->a.protocol->name); + + return 0; + +fail: + lws_ss_destroy(&h); +fail1: + return 1; +} + +#endif + + +static struct lws * +lws_adopt_descriptor_vhost2(struct lws *new_wsi, lws_adoption_type type, + lws_sock_file_fd_type fd) +{ + struct lws_context_per_thread *pt = + &new_wsi->a.context->pt[(int)new_wsi->tsi]; + int n; + /* enforce that every fd is nonblocking */ if (type & LWS_ADOPT_SOCKET) { if (lws_plat_set_nonblocking(fd.sockfd)) { - lwsl_err("%s: unable to set sockfd nonblocking\n", - __func__); - goto bail; + lwsl_err("%s: unable to set sockfd %d nonblocking\n", + __func__, fd.sockfd); + goto fail; } } #if !defined(WIN32) @@ -175,34 +338,16 @@ if (lws_plat_set_nonblocking(fd.filefd)) { lwsl_err("%s: unable to set filefd nonblocking\n", __func__); - goto bail; + goto fail; } #endif new_wsi->desc = fd; - if (vh_prot_name) { - new_wsi->protocol = lws_vhost_name_to_protocol(new_wsi->vhost, - vh_prot_name); - if (!new_wsi->protocol) { - lwsl_err("Protocol %s not enabled on vhost %s\n", - vh_prot_name, new_wsi->vhost->name); - goto bail; - } - if (lws_ensure_user_space(new_wsi)) { - lwsl_notice("OOM trying to get user_space\n"); - goto bail; - } - } - - if (!LWS_SSL_ENABLED(new_wsi->vhost) || !(type & LWS_ADOPT_SOCKET)) + if (!LWS_SSL_ENABLED(new_wsi->a.vhost) || + !(type & LWS_ADOPT_SOCKET)) type &= ~LWS_ADOPT_ALLOW_SSL; - if (lws_role_call_adoption_bind(new_wsi, type, vh_prot_name)) { - lwsl_err("Unable to find a role that can adopt descriptor type 0x%x\n", type); - goto bail; - } - /* * A new connection was accepted. Give the user a chance to * set properties of the newly created wsi. There's no protocol @@ -214,11 +359,9 @@ if (new_wsi->role_ops->adoption_cb[lwsi_role_server(new_wsi)]) n = new_wsi->role_ops->adoption_cb[lwsi_role_server(new_wsi)]; -#if !defined(LWS_AMAZON_RTOS) - if (context->event_loop_ops->accept) - if (context->event_loop_ops->accept(new_wsi)) + if (new_wsi->a.context->event_loop_ops->sock_accept) + if (new_wsi->a.context->event_loop_ops->sock_accept(new_wsi)) goto fail; -#endif #if LWS_MAX_SMP > 1 /* @@ -231,33 +374,59 @@ if (!(type & LWS_ADOPT_ALLOW_SSL)) { lws_pt_lock(pt, __func__); - if (__insert_wsi_socket_into_fds(context, new_wsi)) { + if (__insert_wsi_socket_into_fds(new_wsi->a.context, new_wsi)) { lws_pt_unlock(pt); lwsl_err("%s: fail inserting socket\n", __func__); goto fail; } lws_pt_unlock(pt); } -#if !defined(LWS_WITHOUT_SERVER) +#if defined(LWS_WITH_SERVER) else - if (lws_server_socket_service_ssl(new_wsi, fd.sockfd)) { + if (lws_server_socket_service_ssl(new_wsi, fd.sockfd, 0)) { +#if defined(LWS_WITH_ACCESS_LOG) + lwsl_notice("%s: fail ssl negotiation: %s\n", __func__, + new_wsi->simple_ip); +#else lwsl_info("%s: fail ssl negotiation\n", __func__); +#endif goto fail; } #endif + lws_vhost_lock(new_wsi->a.vhost); + /* he has fds visibility now, remove from vhost orphan list */ + lws_dll2_remove(&new_wsi->vh_awaiting_socket); + lws_vhost_unlock(new_wsi->a.vhost); + /* * by deferring callback to this point, after insertion to fds, * lws_callback_on_writable() can work from the callback */ - if ((new_wsi->protocol->callback)(new_wsi, n, new_wsi->user_space, + if ((new_wsi->a.protocol->callback)(new_wsi, n, new_wsi->user_space, NULL, 0)) goto fail; /* role may need to do something after all adoption completed */ lws_role_call_adoption_bind(new_wsi, type | _LWS_ADOPT_FINISH, - vh_prot_name); + new_wsi->a.protocol->name); + +#if defined(LWS_WITH_SERVER) && defined(LWS_WITH_SECURE_STREAMS) + /* + * Did we come from an accepted client connection to a ss server? + * + * !!! For mux protocols, this will cause an additional inactive ss + * representing the nwsi. Doing that allows us to support both h1 + * (here) and h2 (at lws_wsi_server_new()) + */ + + lwsl_info("%s: wsi %p, vhost %s ss_handle %p\n", __func__, new_wsi, + new_wsi->a.vhost->name, new_wsi->a.vhost->ss_handle); + + if (lws_adopt_ss_server_accept(new_wsi)) + goto fail; +#endif #if LWS_MAX_SMP > 1 /* its actual pt can service it now */ @@ -275,25 +444,80 @@ "adopt skt fail"); return NULL; +} -bail: - lwsl_notice("%s: exiting on bail\n", __func__); - if (parent) - parent->child_list = new_wsi->sibling_list; - if (new_wsi->user_space) - lws_free(new_wsi->user_space); - vh->context->count_wsi_allocated--; +/* if not a socket, it's a raw, non-ssl file descriptor */ - lws_vhost_unbind_wsi(new_wsi); - lws_free(new_wsi); +struct lws * +lws_adopt_descriptor_vhost(struct lws_vhost *vh, lws_adoption_type type, + lws_sock_file_fd_type fd, const char *vh_prot_name, + struct lws *parent) +{ + lws_adopt_desc_t info; - compatible_close(fd.sockfd); + memset(&info, 0, sizeof(info)); - return NULL; + info.vh = vh; + info.type = type; + info.fd = fd; + info.vh_prot_name = vh_prot_name; + info.parent = parent; + + return lws_adopt_descriptor_vhost_via_info(&info); +} + +struct lws * +lws_adopt_descriptor_vhost_via_info(const lws_adopt_desc_t *info) +{ + struct lws *new_wsi; +#if defined(LWS_WITH_PEER_LIMITS) + struct lws_peer *peer = NULL; + + if (info->type & LWS_ADOPT_SOCKET) { + peer = lws_get_or_create_peer(info->vh, info->fd.sockfd); + + if (peer && info->vh->context->ip_limit_wsi && + peer->count_wsi >= info->vh->context->ip_limit_wsi) { + lwsl_info("Peer reached wsi limit %d\n", + info->vh->context->ip_limit_wsi); + lws_stats_bump(&info->vh->context->pt[0], + LWSSTATS_C_PEER_LIMIT_WSI_DENIED, + 1); + if (info->vh->context->pl_notify_cb) + info->vh->context->pl_notify_cb( + info->vh->context, + info->fd.sockfd, + &peer->sa46); + compatible_close(info->fd.sockfd); + return NULL; + } + } +#endif + + new_wsi = lws_adopt_descriptor_vhost1(info->vh, info->type, + info->vh_prot_name, info->parent, + info->opaque); + if (!new_wsi) { + if (info->type & LWS_ADOPT_SOCKET) + compatible_close(info->fd.sockfd); + return NULL; + } + +#if defined(LWS_WITH_ACCESS_LOG) + lws_get_peer_simple_fd(info->fd.sockfd, new_wsi->simple_ip, + sizeof(new_wsi->simple_ip)); +#endif + +#if defined(LWS_WITH_PEER_LIMITS) + if (peer) + lws_peer_add_wsi(info->vh->context, peer, new_wsi); +#endif + + return lws_adopt_descriptor_vhost2(new_wsi, info->type, info->fd); } -LWS_VISIBLE struct lws * +struct lws * lws_adopt_socket_vhost(struct lws_vhost *vh, lws_sockfd_type accept_fd) { lws_sock_file_fd_type fd; @@ -303,7 +527,7 @@ LWS_ADOPT_HTTP | LWS_ADOPT_ALLOW_SSL, fd, NULL, NULL); } -LWS_VISIBLE struct lws * +struct lws * lws_adopt_socket(struct lws_context *context, lws_sockfd_type accept_fd) { return lws_adopt_socket_vhost(context->vhost_list, accept_fd); @@ -326,7 +550,7 @@ if (wsi->position_in_fds_table == LWS_NO_FDS_POS) return wsi; - pt = &wsi->context->pt[(int)wsi->tsi]; + pt = &wsi->a.context->pt[(int)wsi->tsi]; n = lws_buflist_append_segment(&wsi->buflist, (const uint8_t *)readbuf, len); @@ -358,7 +582,7 @@ pfd = &pt->fds[wsi->position_in_fds_table]; pfd->revents |= LWS_POLLIN; lwsl_err("%s: calling service\n", __func__); - if (lws_service_fd_tsi(wsi->context, pfd, wsi->tsi)) + if (lws_service_fd_tsi(wsi->a.context, pfd, wsi->tsi)) /* service closed us */ return NULL; @@ -375,78 +599,248 @@ return NULL; } -LWS_EXTERN struct lws * -lws_create_adopt_udp(struct lws_vhost *vhost, int port, int flags, - const char *protocol_name, struct lws *parent_wsi) +#if defined(LWS_WITH_UDP) +#if defined(LWS_WITH_CLIENT) +static struct lws * +lws_create_adopt_udp2(struct lws *wsi, const char *ads, + const struct addrinfo *r, int n, void *opaque) { -#if !defined(LWS_PLAT_OPTEE) lws_sock_file_fd_type sock; - struct addrinfo h, *r, *rp; - struct lws *wsi = NULL; - char buf[16]; - int n; + int bc = 1; - memset(&h, 0, sizeof(h)); - h.ai_family = AF_UNSPEC; /* Allow IPv4 or IPv6 */ - h.ai_socktype = SOCK_DGRAM; - h.ai_protocol = IPPROTO_UDP; - h.ai_flags = AI_PASSIVE; -#ifdef AI_ADDRCONFIG - h.ai_flags |= AI_ADDRCONFIG; -#endif + assert(wsi); - lws_snprintf(buf, sizeof(buf), "%u", port); - n = getaddrinfo(NULL, buf, &h, &r); - if (n) { -#ifndef LWS_WITH_ESP32 - lwsl_info("%s: getaddrinfo error: %s\n", __func__, gai_strerror(n)); + if (!wsi->dns_results) + wsi->dns_results_next = wsi->dns_results = r; + + if (ads && (n < 0 || !r)) { + /* + * DNS lookup failed: there are no usable results. Fail the + * overall connection request. + */ + lwsl_notice("%s: bad: n %d, r %p\n", __func__, n, r); + + /* + * We didn't get a callback on a cache item and bump the + * refcount. So don't let the cleanup continue to think it + * needs to decrement any refcount. + */ + wsi->dns_results_next = wsi->dns_results = NULL; + goto bail; + } + + while (wsi->dns_results_next) { + + /* + * We have done the dns lookup, identify the result we want + * if any, and then complete the adoption by binding wsi to + * socket opened on it. + * + * Ignore the weak assumptions about protocol driven by port + * number and force to DGRAM / UDP since that's what this + * function is for. + */ + +#if !defined(__linux__) + /* PF_PACKET is linux-only */ + sock.sockfd = socket(wsi->dns_results_next->ai_family, + SOCK_DGRAM, IPPROTO_UDP); #else - lwsl_info("%s: getaddrinfo error: %s\n", __func__, strerror(n)); + sock.sockfd = socket(wsi->pf_packet ? PF_PACKET : + wsi->dns_results_next->ai_family, + SOCK_DGRAM, wsi->pf_packet ? + htons(0x800) : IPPROTO_UDP); +#endif + if (sock.sockfd == LWS_SOCK_INVALID) + goto resume; + + ((struct sockaddr_in *)wsi->dns_results_next->ai_addr)->sin_port = + htons(wsi->c_port); + + if (setsockopt(sock.sockfd, SOL_SOCKET, SO_REUSEADDR, (const char *)&bc, + sizeof(bc)) < 0) + lwsl_err("%s: failed to set reuse\n", __func__); + + if (wsi->do_broadcast && + setsockopt(sock.sockfd, SOL_SOCKET, SO_BROADCAST, (const char *)&bc, + sizeof(bc)) < 0) + lwsl_err("%s: failed to set broadcast\n", + __func__); + + /* Bind the udp socket to a particular network interface */ + + if (opaque && + lws_plat_BINDTODEVICE(sock.sockfd, (const char *)opaque)) + goto resume; + + if (wsi->do_bind && + bind(sock.sockfd, wsi->dns_results_next->ai_addr, +#if defined(_WIN32) + (int)wsi->dns_results_next->ai_addrlen +#else + sizeof(struct sockaddr)//wsi->dns_results_next->ai_addrlen #endif - goto bail; + ) == -1) { + lwsl_err("%s: bind failed\n", __func__); + goto resume; + } + + if (!wsi->do_bind && !wsi->pf_packet) { +#if !defined(__APPLE__) + if (connect(sock.sockfd, wsi->dns_results_next->ai_addr, + (socklen_t)wsi->dns_results_next->ai_addrlen) == -1) { + lwsl_err("%s: conn fd %d fam %d %s:%u failed " + "(salen %d) errno %d\n", __func__, + sock.sockfd, + wsi->dns_results_next->ai_addr->sa_family, + ads ? ads : "null", wsi->c_port, + (int)wsi->dns_results_next->ai_addrlen, + LWS_ERRNO); + compatible_close(sock.sockfd); + goto resume; + } +#endif + memcpy(&wsi->udp->sa, wsi->dns_results_next->ai_addr, + wsi->dns_results_next->ai_addrlen); + wsi->udp->salen = (socklen_t)wsi->dns_results_next->ai_addrlen; + } + + /* we connected: complete the udp socket adoption flow */ + + lws_addrinfo_clean(wsi); + return lws_adopt_descriptor_vhost2(wsi, + LWS_ADOPT_RAW_SOCKET_UDP, sock); + +resume: + wsi->dns_results_next = wsi->dns_results_next->ai_next; } - for (rp = r; rp; rp = rp->ai_next) { - sock.sockfd = socket(rp->ai_family, rp->ai_socktype, - rp->ai_protocol); - if (sock.sockfd != LWS_SOCK_INVALID) - break; - } - if (!rp) { - lwsl_err("%s: unable to create INET socket\n", __func__); - goto bail1; + lwsl_err("%s: unable to create INET socket %d\n", __func__, LWS_ERRNO); + lws_addrinfo_clean(wsi); + +bail: + lws_close_free_wsi(wsi, LWS_CLOSE_STATUS_NOSTATUS, "adopt udp2 fail"); + + return NULL; +} + +struct lws * +lws_create_adopt_udp(struct lws_vhost *vhost, const char *ads, int port, + int flags, const char *protocol_name, const char *ifname, + struct lws *parent_wsi, void *opaque, + const lws_retry_bo_t *retry_policy) +{ +#if !defined(LWS_PLAT_OPTEE) + struct lws *wsi; + int n; + + lwsl_info("%s: %s:%u\n", __func__, ads ? ads : "null", port); + + /* create the logical wsi without any valid fd */ + + wsi = lws_adopt_descriptor_vhost1(vhost, LWS_ADOPT_RAW_SOCKET_UDP, + protocol_name, parent_wsi, opaque); + if (!wsi) { + lwsl_err("%s: udp wsi creation failed\n", __func__); + goto bail; } + wsi->do_bind = !!(flags & LWS_CAUDP_BIND); + wsi->do_broadcast = !!(flags & LWS_CAUDP_BROADCAST); + wsi->pf_packet = !!(flags & LWS_CAUDP_PF_PACKET); + wsi->c_port = port; + if (retry_policy) + wsi->retry_policy = retry_policy; + else + wsi->retry_policy = vhost->retry_policy; - if ((flags & LWS_CAUDP_BIND) && bind(sock.sockfd, rp->ai_addr, -#if defined(_WIN32) - (int)rp->ai_addrlen +#if !defined(LWS_WITH_SYS_ASYNC_DNS) + { + struct addrinfo *r, h; + char buf[16]; + + memset(&h, 0, sizeof(h)); + h.ai_family = AF_UNSPEC; /* Allow IPv4 or IPv6 */ + h.ai_socktype = SOCK_DGRAM; + h.ai_protocol = IPPROTO_UDP; +#if defined(AI_PASSIVE) + h.ai_flags = AI_PASSIVE; +#endif +#ifdef AI_ADDRCONFIG + h.ai_flags |= AI_ADDRCONFIG; +#endif + + /* if the dns lookup is synchronous, do the whole thing now */ + lws_snprintf(buf, sizeof(buf), "%u", port); + n = getaddrinfo(ads, buf, &h, &r); + if (n) { +#if !defined(LWS_PLAT_FREERTOS) + lwsl_info("%s: getaddrinfo error: %s\n", __func__, + gai_strerror(n)); #else - rp->ai_addrlen + lwsl_info("%s: getaddrinfo error: %s\n", __func__, + strerror(n)); #endif - ) == -1) { - lwsl_err("%s: bind failed\n", __func__); - goto bail2; + //freeaddrinfo(r); + goto bail1; + } + /* complete it immediately after the blocking dns lookup + * finished... free r when connect either completed or failed */ + wsi = lws_create_adopt_udp2(wsi, ads, r, 0, NULL); + + return wsi; + } +#else + if (ads) { + /* + * with async dns, use the wsi as the point about which to do + * the dns lookup and have it call the second part when it's + * done. + * + * Keep a refcount on the results and free it when we connected + * or definitively failed. + * + * Notice wsi has no socket at this point (we don't know what + * kind to ask for until we get the dns back). But it is bound + * to a vhost and can be cleaned up from that at vhost destroy. + */ + n = lws_async_dns_query(vhost->context, 0, ads, + LWS_ADNS_RECORD_A, + lws_create_adopt_udp2, wsi, (void *)ifname); + lwsl_debug("%s: dns query returned %d\n", __func__, n); + if (n == LADNS_RET_FAILED) { + lwsl_err("%s: async dns failed\n", __func__); + wsi = NULL; + /* + * It was already closed by calling callback with error + * from lws_async_dns_query() + */ + goto bail; + } + } else { + lwsl_debug("%s: udp adopt has no ads\n", __func__); + wsi = lws_create_adopt_udp2(wsi, ads, NULL, 0, (void *)ifname); } - wsi = lws_adopt_descriptor_vhost(vhost, LWS_ADOPT_RAW_SOCKET_UDP, sock, - protocol_name, parent_wsi); - if (!wsi) - lwsl_err("%s: udp adoption failed\n", __func__); + /* dns lookup is happening asynchronously */ -bail2: - if (!wsi) - compatible_close((int)sock.sockfd); + lwsl_debug("%s: returning wsi %p\n", __func__, wsi); + return wsi; +#endif +#if !defined(LWS_WITH_SYS_ASYNC_DNS) bail1: - freeaddrinfo(r); - + lws_close_free_wsi(wsi, LWS_CLOSE_STATUS_NOSTATUS, "adopt udp2 fail"); + wsi = NULL; +#endif bail: return wsi; #else return NULL; #endif } +#endif +#endif -LWS_VISIBLE struct lws * +struct lws * lws_adopt_socket_readbuf(struct lws_context *context, lws_sockfd_type accept_fd, const char *readbuf, size_t len) { @@ -454,7 +848,7 @@ readbuf, len); } -LWS_VISIBLE struct lws * +struct lws * lws_adopt_socket_vhost_readbuf(struct lws_vhost *vhost, lws_sockfd_type accept_fd, const char *readbuf, size_t len) diff -Nru libwebsockets-3.2.1/lib/core-net/client.c libwebsockets-4.1.6/lib/core-net/client.c --- libwebsockets-3.2.1/lib/core-net/client.c 2019-12-18 14:45:31.000000000 +0000 +++ libwebsockets-4.1.6/lib/core-net/client.c 2020-12-01 17:40:26.000000000 +0000 @@ -1,28 +1,32 @@ /* * libwebsockets - small server side websockets and web server implementation * - * Copyright (C) 2010-2019 Andy Green + * Copyright (C) 2010 - 2019 Andy Green * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation: - * version 2.1 of the License. + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to + * deal in the Software without restriction, including without limitation the + * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or + * sell copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: * - * This library is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. * - * You should have received a copy of the GNU Lesser General Public - * License along with this library; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, - * MA 02110-1301 USA + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS + * IN THE SOFTWARE. */ -#include "core/private.h" +#include "private-lib-core.h" +#if defined(LWS_CLIENT_HTTP_PROXYING) -LWS_VISIBLE int +int lws_set_proxy(struct lws_vhost *vhost, const char *proxy) { char authstring[96]; @@ -114,4 +118,4 @@ return -1; } - +#endif diff -Nru libwebsockets-3.2.1/lib/core-net/close.c libwebsockets-4.1.6/lib/core-net/close.c --- libwebsockets-3.2.1/lib/core-net/close.c 2019-12-18 14:45:31.000000000 +0000 +++ libwebsockets-4.1.6/lib/core-net/close.c 2020-12-01 17:40:26.000000000 +0000 @@ -1,67 +1,142 @@ /* * libwebsockets - small server side websockets and web server implementation * - * Copyright (C) 2010-2019 Andy Green + * Copyright (C) 2010 - 2019 Andy Green * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation: - * version 2.1 of the License. + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to + * deal in the Software without restriction, including without limitation the + * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or + * sell copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: * - * This library is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. * - * You should have received a copy of the GNU Lesser General Public - * License along with this library; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, - * MA 02110-1301 USA + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS + * IN THE SOFTWARE. */ -#include "core/private.h" +#include "private-lib-core.h" +#if defined(LWS_WITH_CLIENT) +static int +lws_close_trans_q_leader(struct lws_dll2 *d, void *user) +{ + struct lws *w = lws_container_of(d, struct lws, dll2_cli_txn_queue); + + __lws_close_free_wsi(w, -1, "trans q leader closing"); + + return 0; +} +#endif void -__lws_free_wsi(struct lws *wsi) +__lws_reset_wsi(struct lws *wsi) { if (!wsi) return; +#if defined(LWS_WITH_CLIENT) + + lws_free_set_NULL(wsi->cli_hostname_copy); + + /* + * if we have wsi in our transaction queue, if we are closing we + * must go through and close all those first + */ + if (wsi->a.vhost) { + + /* we are no longer an active client connection that can piggyback */ + lws_dll2_remove(&wsi->dll_cli_active_conns); + + lws_dll2_foreach_safe(&wsi->dll2_cli_txn_queue_owner, NULL, + lws_close_trans_q_leader); + + /* + * !!! If we are closing, but we have pending pipelined + * transaction results we already sent headers for, that's going + * to destroy sync for HTTP/1 and leave H2 stream with no live + * swsi.` + * + * However this is normal if we are being closed because the + * transaction queue leader is closing. + */ + lws_dll2_remove(&wsi->dll2_cli_txn_queue); + } +#endif + + if (wsi->a.vhost) { + lws_vhost_lock(wsi->a.vhost); + lws_dll2_remove(&wsi->vh_awaiting_socket); + lws_vhost_unlock(wsi->a.vhost); + } + /* * Protocol user data may be allocated either internally by lws * or by specified the user. We should only free what we allocated. */ - if (wsi->protocol && wsi->protocol->per_session_data_size && - wsi->user_space && !wsi->user_space_externally_allocated) - lws_free(wsi->user_space); + if (wsi->a.protocol && wsi->a.protocol->per_session_data_size && + wsi->user_space && !wsi->user_space_externally_allocated) { + /* confirm no sul left scheduled in user data itself */ + lws_sul_debug_zombies(wsi->a.context, wsi->user_space, + wsi->a.protocol->per_session_data_size, __func__); + lws_free_set_NULL(wsi->user_space); + } + + /* + * Don't let buflist content or state from the wsi's previous life + * carry over to the new life + */ lws_buflist_destroy_all_segments(&wsi->buflist); + lws_dll2_remove(&wsi->dll_buflist); lws_buflist_destroy_all_segments(&wsi->buflist_out); - lws_free_set_NULL(wsi->udp); +#if defined(LWS_WITH_UDP) + if (wsi->udp) { + /* confirm no sul left scheduled in wsi->udp itself */ + lws_sul_debug_zombies(wsi->a.context, wsi->udp, + sizeof(*wsi->udp), "close udp wsi"); + lws_free_set_NULL(wsi->udp); + } +#endif + wsi->retry = 0; - if (wsi->vhost && wsi->vhost->lserv_wsi == wsi) - wsi->vhost->lserv_wsi = NULL; -#if !defined(LWS_NO_CLIENT) - if (wsi->vhost) - lws_dll2_remove(&wsi->dll_cli_active_conns); +#if defined(LWS_WITH_CLIENT) + lws_dll2_remove(&wsi->dll2_cli_txn_queue); + lws_dll2_remove(&wsi->dll_cli_active_conns); #endif - wsi->context->count_wsi_allocated--; -#if defined(LWS_ROLE_H1) || defined(LWS_ROLE_H2) - __lws_header_table_detach(wsi, 0); +#if defined(LWS_WITH_SYS_ASYNC_DNS) + lws_async_dns_cancel(wsi); +#endif + +#if defined(LWS_WITH_HTTP_PROXY) + if (wsi->http.buflist_post_body) + lws_buflist_destroy_all_segments(&wsi->http.buflist_post_body); +#endif + + if (wsi->a.vhost && wsi->a.vhost->lserv_wsi == wsi) + wsi->a.vhost->lserv_wsi = NULL; +#if defined(LWS_WITH_CLIENT) + if (wsi->a.vhost) + lws_dll2_remove(&wsi->dll_cli_active_conns); #endif + wsi->a.context->count_wsi_allocated--; + __lws_same_vh_protocol_remove(wsi); -#if !defined(LWS_NO_CLIENT) - lws_client_stash_destroy(wsi); +#if defined(LWS_WITH_CLIENT) + lws_free_set_NULL(wsi->stash); lws_free_set_NULL(wsi->cli_hostname_copy); #endif - if (wsi->role_ops->destroy_role) - wsi->role_ops->destroy_role(wsi); - #if defined(LWS_WITH_PEER_LIMITS) - lws_peer_track_wsi_close(wsi->context, wsi->peer); + lws_peer_track_wsi_close(wsi->a.context, wsi->peer); wsi->peer = NULL; #endif @@ -72,13 +147,34 @@ #endif __lws_wsi_remove_from_sul(wsi); - if (wsi->context->event_loop_ops->destroy_wsi) - wsi->context->event_loop_ops->destroy_wsi(wsi); + if (wsi->role_ops->destroy_role) + wsi->role_ops->destroy_role(wsi); + +#if defined(LWS_ROLE_H1) || defined(LWS_ROLE_H2) + __lws_header_table_detach(wsi, 0); +#endif +} + +void +__lws_free_wsi(struct lws *wsi) +{ + if (!wsi) + return; + + __lws_reset_wsi(wsi); + __lws_wsi_remove_from_sul(wsi); + + if (wsi->a.context->event_loop_ops->destroy_wsi) + wsi->a.context->event_loop_ops->destroy_wsi(wsi); lws_vhost_unbind_wsi(wsi); - lwsl_debug("%s: %p, remaining wsi %d\n", __func__, wsi, - wsi->context->count_wsi_allocated); + lwsl_debug("%s: %p, remaining wsi %d, tsi fds count %d\n", __func__, wsi, + wsi->a.context->count_wsi_allocated, + wsi->a.context->pt[(int)wsi->tsi].fds_count); + + /* confirm no sul left scheduled in wsi itself */ + lws_sul_debug_zombies(wsi->a.context, wsi, sizeof(wsi), __func__); lws_free(wsi); } @@ -100,8 +196,8 @@ lwsl_info("%s: detach %p from parent %p\n", __func__, wsi, wsi->parent); - if (wsi->parent->protocol) - wsi->parent->protocol->callback(wsi, + if (wsi->parent->a.protocol) + wsi->parent->a.protocol->callback(wsi, LWS_CALLBACK_CHILD_CLOSING, wsi->parent->user_space, wsi, 0); @@ -117,47 +213,54 @@ wsi->parent = NULL; } -#if !defined(LWS_NO_CLIENT) -static int -lws_close_trans_q_leader(struct lws_dll2 *d, void *user) -{ - struct lws *w = lws_container_of(d, struct lws, dll2_cli_txn_queue); - - __lws_close_free_wsi(w, -1, "trans q leader closing"); - - return 0; -} - +#if defined(LWS_WITH_CLIENT) void lws_inform_client_conn_fail(struct lws *wsi, void *arg, size_t len) { + lws_addrinfo_clean(wsi); + if (wsi->already_did_cce) return; wsi->already_did_cce = 1; - lws_stats_bump(&wsi->context->pt[(int)wsi->tsi], + lws_stats_bump(&wsi->a.context->pt[(int)wsi->tsi], LWSSTATS_C_CONNS_CLIENT_FAILED, 1); - if (!wsi->protocol) + if (!wsi->a.protocol) return; - wsi->protocol->callback(wsi, - LWS_CALLBACK_CLIENT_CONNECTION_ERROR, - wsi->user_space, arg, len); + if (!wsi->client_suppress_CONNECTION_ERROR) + wsi->a.protocol->callback(wsi, + LWS_CALLBACK_CLIENT_CONNECTION_ERROR, + wsi->user_space, arg, len); } #endif void +lws_addrinfo_clean(struct lws *wsi) +{ +#if defined(LWS_WITH_CLIENT) + if (!wsi->dns_results) + return; + +#if defined(LWS_WITH_SYS_ASYNC_DNS) + lws_async_dns_freeaddrinfo(&wsi->dns_results); +#else + freeaddrinfo((struct addrinfo *)wsi->dns_results); +#endif + wsi->dns_results = NULL; +#endif +} + +void __lws_close_free_wsi(struct lws *wsi, enum lws_close_status reason, const char *caller) { struct lws_context_per_thread *pt; - struct lws *wsi1, *wsi2; + const struct lws_protocols *pro; struct lws_context *context; -#if !defined(LWS_NO_CLIENT) - long rl = (long)(int)reason; -#endif - int n; + struct lws *wsi1, *wsi2; + int n, ccb; lwsl_info("%s: %p: caller: %s\n", __func__, wsi, caller); @@ -166,42 +269,27 @@ lws_access_log(wsi); - context = wsi->context; - pt = &context->pt[(int)wsi->tsi]; - lws_stats_bump(pt, LWSSTATS_C_API_CLOSE, 1); + if (!lws_dll2_is_detached(&wsi->dll_buflist)) { + lwsl_info("%s: wsi %p: going down with stuff in buflist\n", + __func__, wsi); } -#if !defined(LWS_NO_CLIENT) + context = wsi->a.context; + pt = &context->pt[(int)wsi->tsi]; - lws_free_set_NULL(wsi->cli_hostname_copy); + lws_pt_assert_lock_held(pt); - /* - * if we have wsi in our transaction queue, if we are closing we - * must go through and close all those first - */ - if (wsi->vhost) { + lws_stats_bump(pt, LWSSTATS_C_API_CLOSE, 1); - /* we are no longer an active client connection that can piggyback */ - lws_dll2_remove(&wsi->dll_cli_active_conns); +#if defined(LWS_WITH_CLIENT) - if (rl != -1l) - lws_vhost_lock(wsi->vhost); + lws_free_set_NULL(wsi->cli_hostname_copy); - lws_dll2_foreach_safe(&wsi->dll2_cli_txn_queue_owner, NULL, - lws_close_trans_q_leader); + lws_addrinfo_clean(wsi); +#endif - /* - * !!! If we are closing, but we have pending pipelined - * transaction results we already sent headers for, that's going - * to destroy sync for HTTP/1 and leave H2 stream with no live - * swsi.` - * - * However this is normal if we are being closed because the - * transaction queue leader is closing. - */ - lws_dll2_remove(&wsi->dll2_cli_txn_queue); - if (rl != -1l) - lws_vhost_unlock(wsi->vhost); - } +#if defined(LWS_WITH_HTTP2) + if (wsi->mux_stream_immortal) + lws_http_close_immortal(wsi); #endif /* if we have children, close them first */ @@ -209,7 +297,7 @@ wsi2 = wsi->child_list; while (wsi2) { wsi1 = wsi2->sibling_list; - wsi2->parent = NULL; +// wsi2->parent = NULL; /* stop it doing shutdown processing */ wsi2->socket_is_permanently_unusable = 1; __lws_close_free_wsi(wsi2, reason, @@ -219,30 +307,38 @@ wsi->child_list = NULL; } +#if defined(LWS_ROLE_RAW_FILE) if (wsi->role_ops == &role_ops_raw_file) { lws_remove_child_from_any_parent(wsi); __remove_wsi_socket_from_fds(wsi); - if (wsi->protocol) - wsi->protocol->callback(wsi, wsi->role_ops->close_cb[0], + if (wsi->a.protocol) + wsi->a.protocol->callback(wsi, wsi->role_ops->close_cb[0], wsi->user_space, NULL, 0); goto async_close; } +#endif wsi->wsistate_pre_close = wsi->wsistate; #ifdef LWS_WITH_CGI if (wsi->role_ops == &role_ops_cgi) { - // lwsl_debug("%s: closing stdwsi index %d\n", __func__, (int)wsi->cgi_channel); + // lwsl_debug("%s: closing stdwsi index %d\n", __func__, (int)wsi->lsp_channel); /* we are not a network connection, but a handler for CGI io */ if (wsi->parent && wsi->parent->http.cgi) { - if (wsi->parent->child_list == wsi && !wsi->sibling_list) - lws_cgi_remove_and_kill(wsi->parent); + /* + * We need to keep the logical cgi around so we can + * drain it + */ + +// if (wsi->parent->child_list == wsi && !wsi->sibling_list) +// lws_cgi_remove_and_kill(wsi->parent); /* end the binding between us and master */ - wsi->parent->http.cgi->stdwsi[(int)wsi->cgi_channel] = + if (wsi->parent->http.cgi && wsi->parent->http.cgi->lsp) + wsi->parent->http.cgi->lsp->stdwsi[(int)wsi->lsp_channel] = NULL; } wsi->socket_is_permanently_unusable = 1; @@ -254,15 +350,15 @@ lws_cgi_remove_and_kill(wsi); #endif -#if !defined(LWS_NO_CLIENT) - lws_client_stash_destroy(wsi); +#if defined(LWS_WITH_CLIENT) + lws_free_set_NULL(wsi->stash); #endif if (wsi->role_ops == &role_ops_raw_skt) { wsi->socket_is_permanently_unusable = 1; goto just_kill_connection; } -#if defined(LWS_ROLE_H1) || defined(LWS_ROLE_H2) +#if defined(LWS_WITH_FILE_OPS) && (defined(LWS_ROLE_H1) || defined(LWS_ROLE_H2)) if (lwsi_role_http(wsi) && lwsi_role_server(wsi) && wsi->http.fop_fd != NULL) lws_vfs_file_close(&wsi->http.fop_fd); @@ -315,12 +411,13 @@ } if (lwsi_state(wsi) == LRS_WAITING_CONNECT || + lwsi_state(wsi) == LRS_WAITING_DNS || lwsi_state(wsi) == LRS_H1C_ISSUE_HANDSHAKE) goto just_kill_connection; - if (!wsi->told_user_closed && wsi->user_space && wsi->protocol && + if (!wsi->told_user_closed && wsi->user_space && wsi->a.protocol && wsi->protocol_bind_balance) { - wsi->protocol->callback(wsi, + wsi->a.protocol->callback(wsi, wsi->role_ops->protocol_unbind_cb[ !!lwsi_role_server(wsi)], wsi->user_space, (void *)__func__, 0); @@ -346,15 +443,29 @@ just_kill_connection: #if defined(LWS_WITH_FILE_OPS) && (defined(LWS_ROLE_H1) || defined(LWS_ROLE_H2)) - if (lwsi_role_http(wsi) && lwsi_role_server(wsi) && - wsi->http.fop_fd != NULL) - lws_vfs_file_close(&wsi->http.fop_fd); + if (lwsi_role_http(wsi) && lwsi_role_server(wsi) && + wsi->http.fop_fd != NULL) + lws_vfs_file_close(&wsi->http.fop_fd); +#endif + + lws_sul_cancel(&wsi->sul_connect_timeout); +#if defined(LWS_WITH_SYS_ASYNC_DNS) + lws_async_dns_cancel(wsi); #endif #if defined(LWS_WITH_HTTP_PROXY) if (wsi->http.buflist_post_body) lws_buflist_destroy_all_segments(&wsi->http.buflist_post_body); #endif +#if defined(LWS_WITH_UDP) + if (wsi->udp) { + /* confirm no sul left scheduled in wsi->udp itself */ + lws_sul_debug_zombies(wsi->a.context, wsi->udp, + sizeof(*wsi->udp), "close udp wsi"); + + lws_free_set_NULL(wsi->udp); + } +#endif if (wsi->role_ops->close_kill_connection) wsi->role_ops->close_kill_connection(wsi, reason); @@ -362,23 +473,53 @@ n = 0; if (!wsi->told_user_closed && wsi->user_space && - wsi->protocol_bind_balance && wsi->protocol) { + wsi->protocol_bind_balance && wsi->a.protocol) { lwsl_debug("%s: %p: DROP_PROTOCOL %s\n", __func__, wsi, - wsi->protocol ? wsi->protocol->name: "NULL"); - if (wsi->protocol) - wsi->protocol->callback(wsi, + wsi->a.protocol ? wsi->a.protocol->name: "NULL"); + if (wsi->a.protocol) + wsi->a.protocol->callback(wsi, wsi->role_ops->protocol_unbind_cb[ !!lwsi_role_server(wsi)], wsi->user_space, (void *)__func__, 0); wsi->protocol_bind_balance = 0; } -#if !defined(LWS_NO_CLIENT) - if ((lwsi_state(wsi) == LRS_WAITING_SERVER_REPLY || +#if defined(LWS_WITH_SECURE_STREAMS) && defined(LWS_WITH_SERVER) + if (wsi->for_ss) { + /* + * We were adopted for a particular ss, but, eg, we may not + * have succeeded with the connection... we are closing which is + * good, but we have to invalidate any pointer the related ss + * handle may be holding on us + */ + lws_ss_handle_t *h = (lws_ss_handle_t *)wsi->a.opaque_user_data; + + if (h) { + h->wsi = NULL; + wsi->a.opaque_user_data = NULL; + } + } +#endif + +#if defined(LWS_WITH_CLIENT) + if (( +#if defined(LWS_ROLE_WS) + /* + * If our goal is a ws upgrade, effectively we did not reach + * ESTABLISHED if we did not get the upgrade server reply + */ + (lwsi_state(wsi) == LRS_WAITING_SERVER_REPLY && + wsi->role_ops == &role_ops_ws) || +#endif + lwsi_state(wsi) == LRS_WAITING_DNS || lwsi_state(wsi) == LRS_WAITING_CONNECT) && - !wsi->already_did_cce && wsi->protocol) { + !wsi->already_did_cce && wsi->a.protocol) { static const char _reason[] = "closed before established"; + lwsl_debug("%s: closing in unestablished state 0x%x\n", + __func__, lwsi_state(wsi)); + wsi->socket_is_permanently_unusable = 1; + lws_inform_client_conn_fail(wsi, (void *)_reason, sizeof(_reason)); } @@ -412,7 +553,7 @@ #endif { lwsl_info("%s: shutdown conn: %p (sk %d, state 0x%x)\n", - __func__, wsi, (int)(long)wsi->desc.sockfd, + __func__, wsi, (int)(lws_intptr_t)wsi->desc.sockfd, lwsi_state(wsi)); if (!wsi->socket_is_permanently_unusable && lws_socket_is_valid(wsi->desc.sockfd)) { @@ -428,12 +569,12 @@ * This causes problems on WINCE / ESP32 with disconnection * when the events are half closing connection */ -#if !defined(_WIN32_WCE) && !defined(LWS_WITH_ESP32) +#if !defined(_WIN32_WCE) && !defined(LWS_PLAT_FREERTOS) /* libuv: no event available to guarantee completion */ if (!wsi->socket_is_permanently_unusable && lws_socket_is_valid(wsi->desc.sockfd) && lwsi_state(wsi) != LRS_SHUTDOWN && - context->event_loop_ops->periodic_events_available) { + (context->event_loop_ops->flags & LELOF_ISPOLL)) { __lws_change_pollfd(wsi, LWS_POLLOUT, LWS_POLLIN); lwsi_set_state(wsi, LRS_SHUTDOWN); __lws_set_timeout(wsi, PENDING_TIMEOUT_SHUTDOWN_FLUSH, @@ -470,10 +611,7 @@ // lwsl_notice("%s: wsi %p, fd %d\n", __func__, wsi, wsi->desc.sockfd); /* checking return redundant since we anyway close */ - if (wsi->desc.sockfd != LWS_SOCK_INVALID) - __remove_wsi_socket_from_fds(wsi); - else - __lws_same_vh_protocol_remove(wsi); + __remove_wsi_socket_from_fds(wsi); lwsi_set_state(wsi, LRS_DEAD_SOCKET); lws_buflist_destroy_all_segments(&wsi->buflist); @@ -484,18 +622,15 @@ /* tell the user it's all over for this guy */ + ccb = 0; if ((lwsi_state_est_PRE_CLOSE(wsi) || /* raw skt adopted but didn't complete tls hs should CLOSE */ (wsi->role_ops == &role_ops_raw_skt && !lwsi_role_client(wsi)) || lwsi_state_PRE_CLOSE(wsi) == LRS_WAITING_SERVER_REPLY) && !wsi->told_user_closed && wsi->role_ops->close_cb[lwsi_role_server(wsi)]) { - const struct lws_protocols *pro = wsi->protocol; - - if (!wsi->protocol && wsi->vhost && wsi->vhost->protocols) - pro = &wsi->vhost->protocols[0]; - - if (pro && (!wsi->upgraded_to_http2 || !lwsi_role_client(wsi))) + if (!wsi->upgraded_to_http2 || !lwsi_role_client(wsi)) + ccb = 1; /* * The network wsi for a client h2 connection shouldn't * call back for its role: the child stream connections @@ -503,18 +638,52 @@ * one too many times as the children do it and then * the closing network stream. */ + } + + if (!wsi->told_user_closed && + !lws_dll2_is_detached(&wsi->vh_awaiting_socket)) + /* + * He's a guy who go started with dns, but failed or is + * caught with a shutdown before he got the result. We have + * to issue him a close cb + */ + ccb = 1; + + pro = wsi->a.protocol; + + if (wsi->already_did_cce) + /* + * If we handled this by CLIENT_CONNECTION_ERROR, it's + * mutually exclusive with CLOSE + */ + ccb = 0; + +#if defined(LWS_WITH_CLIENT) + if (!ccb && (lwsi_state_PRE_CLOSE(wsi) & LWSIFS_NOT_EST) && + lwsi_role_client(wsi)) { + lws_inform_client_conn_fail(wsi, "Closed before conn", 18); + } +#endif + if (ccb) { + + if (!wsi->a.protocol && wsi->a.vhost && wsi->a.vhost->protocols) + pro = &wsi->a.vhost->protocols[0]; + + if (pro) pro->callback(wsi, - wsi->role_ops->close_cb[lwsi_role_server(wsi)], - wsi->user_space, NULL, 0); + wsi->role_ops->close_cb[lwsi_role_server(wsi)], + wsi->user_space, NULL, 0); wsi->told_user_closed = 1; } +#if defined(LWS_ROLE_RAW_FILE) async_close: +#endif lws_remove_child_from_any_parent(wsi); wsi->socket_is_permanently_unusable = 1; - if (wsi->context->event_loop_ops->wsi_logical_close) - if (wsi->context->event_loop_ops->wsi_logical_close(wsi)) + if (wsi->a.context->event_loop_ops->wsi_logical_close) + if (wsi->a.context->event_loop_ops->wsi_logical_close(wsi)) return; __lws_close_free_wsi_final(wsi); @@ -532,31 +701,34 @@ if (n) lwsl_debug("closing: close ret %d\n", LWS_ERRNO); + __remove_wsi_socket_from_fds(wsi); + if (lws_socket_is_valid(wsi->desc.sockfd)) + delete_from_fd(wsi->a.context, wsi->desc.sockfd); + +#if !defined(LWS_PLAT_FREERTOS) && !defined(WIN32) && !defined(LWS_PLAT_OPTEE) + delete_from_fdwsi(wsi->a.context, wsi); +#endif + + sanity_assert_no_sockfd_traces(wsi->a.context, wsi->desc.sockfd); + wsi->desc.sockfd = LWS_SOCK_INVALID; } /* outermost destroy notification for wsi (user_space still intact) */ - if (wsi->vhost) - wsi->vhost->protocols[0].callback(wsi, LWS_CALLBACK_WSI_DESTROY, + if (wsi->a.vhost) + wsi->a.vhost->protocols[0].callback(wsi, LWS_CALLBACK_WSI_DESTROY, wsi->user_space, NULL, 0); #ifdef LWS_WITH_CGI if (wsi->http.cgi) { - - for (n = 0; n < 3; n++) { - if (wsi->http.cgi->pipe_fds[n][!!(n == 0)] == 0) - lwsl_err("ZERO FD IN CGI CLOSE"); - - if (wsi->http.cgi->pipe_fds[n][!!(n == 0)] >= 0) { - close(wsi->http.cgi->pipe_fds[n][!!(n == 0)]); - wsi->http.cgi->pipe_fds[n][!!(n == 0)] = LWS_SOCK_INVALID; - } - } - + lws_spawn_piped_destroy(&wsi->http.cgi->lsp); + lws_sul_cancel(&wsi->http.cgi->sul_grace); lws_free_set_NULL(wsi->http.cgi); } #endif + __lws_wsi_remove_from_sul(wsi); + sanity_assert_no_wsi_traces(wsi->a.context, wsi); __lws_free_wsi(wsi); } @@ -564,7 +736,7 @@ void lws_close_free_wsi(struct lws *wsi, enum lws_close_status reason, const char *caller) { - struct lws_context_per_thread *pt = &wsi->context->pt[(int)wsi->tsi]; + struct lws_context_per_thread *pt = &wsi->a.context->pt[(int)wsi->tsi]; lws_pt_lock(pt, __func__); __lws_close_free_wsi(wsi, reason, caller); diff -Nru libwebsockets-3.2.1/lib/core-net/CMakeLists.txt libwebsockets-4.1.6/lib/core-net/CMakeLists.txt --- libwebsockets-3.2.1/lib/core-net/CMakeLists.txt 1970-01-01 00:00:00.000000000 +0000 +++ libwebsockets-4.1.6/lib/core-net/CMakeLists.txt 2020-12-01 17:40:26.000000000 +0000 @@ -0,0 +1,85 @@ +# +# libwebsockets - small server side websockets and web server implementation +# +# Copyright (C) 2010 - 2020 Andy Green +# +# Permission is hereby granted, free of charge, to any person obtaining a copy +# of this software and associated documentation files (the "Software"), to +# deal in the Software without restriction, including without limitation the +# rights to use, copy, modify, merge, publish, distribute, sublicense, and/or +# sell copies of the Software, and to permit persons to whom the Software is +# furnished to do so, subject to the following conditions: +# +# The above copyright notice and this permission notice shall be included in +# all copies or substantial portions of the Software. +# +# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING +# FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS +# IN THE SOFTWARE. +# + +include_directories(.) + +list(APPEND SOURCES + core-net/dummy-callback.c + core-net/output.c + core-net/close.c + core-net/network.c + core-net/vhost.c + core-net/pollfd.c + core-net/service.c + core-net/sorted-usec-list.c + core-net/wsi.c + core-net/wsi-timeout.c + core-net/adopt.c + roles/pipe/ops-pipe.c +) + +if (LWS_WITH_SYS_STATE) + list(APPEND SOURCES + core-net/state.c + ) +endif() + +if (LWS_WITH_DETAILED_LATENCY) + list(APPEND SOURCES + core-net/detailed-latency.c) +endif() + +if (LWS_WITH_LWS_DSH) + list(APPEND SOURCES + core-net/lws-dsh.c) +endif() + +if (LWS_WITH_SEQUENCER) + list(APPEND SOURCES + core-net/sequencer.c) +endif() + +if (NOT LWS_WITHOUT_CLIENT) + list(APPEND SOURCES + core-net/connect.c + core-net/client.c) +endif() + +if (NOT LWS_WITHOUT_SERVER) + list(APPEND SOURCES + core-net/server.c) +endif() + +if (LWS_WITH_SOCKS5 AND NOT LWS_WITHOUT_CLIENT) + list(APPEND SOURCES + core-net/socks5-client.c) +endif() + +if (LWS_WITH_NETWORK AND LWS_WITH_STATS) + list(APPEND SOURCES + core-net/stats.c + ) +endif() + +exports_to_parent_scope() diff -Nru libwebsockets-3.2.1/lib/core-net/connect.c libwebsockets-4.1.6/lib/core-net/connect.c --- libwebsockets-3.2.1/lib/core-net/connect.c 2019-12-18 14:45:31.000000000 +0000 +++ libwebsockets-4.1.6/lib/core-net/connect.c 2020-12-01 17:40:26.000000000 +0000 @@ -1,54 +1,41 @@ /* * libwebsockets - small server side websockets and web server implementation * - * Copyright (C) 2010-2018 Andy Green + * Copyright (C) 2010 - 2019 Andy Green * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation: - * version 2.1 of the License. + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to + * deal in the Software without restriction, including without limitation the + * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or + * sell copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: * - * This library is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. * - * You should have received a copy of the GNU Lesser General Public - * License along with this library; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, - * MA 02110-1301 USA + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS + * IN THE SOFTWARE. */ -#include "core/private.h" +#include +#include "private-lib-core.h" -void -lws_client_stash_destroy(struct lws *wsi) -{ - if (!wsi || !wsi->stash) - return; - - lws_free_set_NULL(wsi->stash->address); - lws_free_set_NULL(wsi->stash->path); - lws_free_set_NULL(wsi->stash->host); - lws_free_set_NULL(wsi->stash->origin); - lws_free_set_NULL(wsi->stash->protocol); - lws_free_set_NULL(wsi->stash->method); - lws_free_set_NULL(wsi->stash->iface); - lws_free_set_NULL(wsi->stash->alpn); - - lws_free_set_NULL(wsi->stash); -} - -LWS_VISIBLE struct lws * +struct lws * lws_client_connect_via_info(const struct lws_client_connect_info *i) { + const char *local = i->protocol; struct lws *wsi, *safe = NULL; const struct lws_protocols *p; - const char *local = i->protocol; - int tid = 0; -#if LWS_MAX_SMP > 1 - int n; -#endif + size_t s = sizeof(struct lws); + const char *cisin[CIS_COUNT]; + int tid = 0, n, m; + size_t size; + char *pc; if (i->context->requested_kill) return NULL; @@ -68,28 +55,68 @@ /* PHASE 1: create a bare wsi */ - wsi = lws_zalloc(sizeof(struct lws), "client wsi"); +#if defined(LWS_WITH_EVENT_LIBS) + s += i->context->event_loop_ops->evlib_size_wsi; +#endif + + wsi = lws_zalloc(s, "client wsi"); if (wsi == NULL) goto bail; - wsi->context = i->context; +#if defined(LWS_WITH_EVENT_LIBS) + wsi->evlib_wsi = (uint8_t *)wsi + sizeof(*wsi); +#endif + + /* + * Until we exit, we can report connection failure directly to the + * caller without needing to call through to protocol CONNECTION_ERROR. + */ + wsi->client_suppress_CONNECTION_ERROR = 1; + + if (i->keep_warm_secs) + wsi->keep_warm_secs = i->keep_warm_secs; + else + wsi->keep_warm_secs = 5; + + wsi->a.context = i->context; wsi->desc.sockfd = LWS_SOCK_INVALID; wsi->seq = i->seq; - - wsi->vhost = NULL; - if (!i->vhost) - lws_vhost_bind_wsi(i->context->vhost_list, wsi); + wsi->flags = i->ssl_connection; + if (i->retry_and_idle_policy) + wsi->retry_policy = i->retry_and_idle_policy; else + wsi->retry_policy = &i->context->default_retry; + +#if defined(LWS_WITH_DETAILED_LATENCY) + if (i->context->detailed_latency_cb) + wsi->detlat.earliest_write_req_pre_write = lws_now_usecs(); +#endif + + if (i->ssl_connection & LCCSCF_WAKE_SUSPEND__VALIDITY) + wsi->conn_validity_wakesuspend = 1; + + wsi->a.vhost = NULL; + if (!i->vhost) { + struct lws_vhost *v = i->context->vhost_list; + + if (!v) { /* coverity */ + lwsl_err("%s: no vhost\n", __func__); + goto bail; + } + if (!strcmp(v->name, "system")) + v = v->vhost_next; + lws_vhost_bind_wsi(v, wsi); + } else lws_vhost_bind_wsi(i->vhost, wsi); - if (!wsi->vhost) { + if (!wsi->a.vhost) { lwsl_err("%s: No vhost in the context\n", __func__); goto bail; } #if LWS_MAX_SMP > 1 - tid = wsi->vhost->protocols[0].callback(wsi, LWS_CALLBACK_GET_THREAD_ID, + tid = wsi->a.vhost->protocols[0].callback(wsi, LWS_CALLBACK_GET_THREAD_ID, NULL, NULL, 0); #endif @@ -106,6 +133,9 @@ lwsl_info("%s: client binds to caller tsi %d\n", __func__, n); wsi->tsi = n; +#if defined(LWS_WITH_DETAILED_LATENCY) + wsi->detlat.tsi = n; +#endif break; } @@ -142,25 +172,38 @@ wsi->pending_timeout = NO_PENDING_TIMEOUT; wsi->position_in_fds_table = LWS_NO_FDS_POS; wsi->ocport = wsi->c_port = i->port; + wsi->sys_tls_client_cert = i->sys_tls_client_cert; + +#if defined(LWS_ROLE_H2) + wsi->txc.manual_initial_tx_credit = (int32_t)i->manual_initial_tx_credit; +#endif - wsi->protocol = &wsi->vhost->protocols[0]; + wsi->a.protocol = &wsi->a.vhost->protocols[0]; wsi->client_pipeline = !!(i->ssl_connection & LCCSCF_PIPELINE); + wsi->client_no_follow_redirect = !!(i->ssl_connection & + LCCSCF_HTTP_NO_FOLLOW_REDIRECT); /* * PHASE 5: handle external user_space now, generic alloc is done in * role finalization */ - if (!wsi->user_space && i->userdata) { + if (i->userdata) { wsi->user_space_externally_allocated = 1; wsi->user_space = i->userdata; } if (local) { - lwsl_info("%s: protocol binding to %s\n", __func__, local); - p = lws_vhost_name_to_protocol(wsi->vhost, local); + lwsl_info("%s: vh %s protocol binding to %s\n", __func__, wsi->a.vhost->name, local); + p = lws_vhost_name_to_protocol(wsi->a.vhost, local); if (p) lws_bind_protocol(wsi, p, __func__); + else + lwsl_info("%s: unknown protocol %s\n", __func__, local); + + lwsl_info("%s: wsi %p: %s %s entry\n", + __func__, wsi, wsi->role_ops->name, + wsi->a.protocol ? wsi->a.protocol->name : "none"); } /* @@ -193,45 +236,44 @@ * with no relationship to http or ah */ - wsi->stash = lws_zalloc(sizeof(*wsi->stash), "client stash"); + cisin[CIS_ADDRESS] = i->address; + cisin[CIS_PATH] = i->path; + cisin[CIS_HOST] = i->host; + cisin[CIS_ORIGIN] = i->origin; + cisin[CIS_PROTOCOL] = i->protocol; + cisin[CIS_METHOD] = i->method; + cisin[CIS_IFACE] = i->iface; + cisin[CIS_ALPN] = i->alpn; + + size = sizeof(*wsi->stash); + + /* + * Let's overallocate the stash object with space for all the args + * in one hit. + */ + for (n = 0; n < CIS_COUNT; n++) + if (cisin[n]) + size += strlen(cisin[n]) + 1; + + wsi->stash = lws_malloc(size, "client stash"); if (!wsi->stash) { lwsl_err("%s: OOM\n", __func__); goto bail1; } + /* all the pointers default to NULL, but no need to zero the args */ + memset(wsi->stash, 0, sizeof(*wsi->stash)); - wsi->stash->address = lws_strdup(i->address); - wsi->stash->path = lws_strdup(i->path); - wsi->stash->host = lws_strdup(i->host); - wsi->stash->opaque_user_data = i->opaque_user_data; - - if (!wsi->stash->address || !wsi->stash->path || !wsi->stash->host) - goto bail1; - - if (i->origin) { - wsi->stash->origin = lws_strdup(i->origin); - if (!wsi->stash->origin) - goto bail1; - } - if (i->protocol) { - wsi->stash->protocol = lws_strdup(i->protocol); - if (!wsi->stash->protocol) - goto bail1; - } - if (i->method) { - wsi->stash->method = lws_strdup(i->method); - if (!wsi->stash->method) - goto bail1; - } - if (i->iface) { - wsi->stash->iface = lws_strdup(i->iface); - if (!wsi->stash->iface) - goto bail1; - } - if (i->alpn) { - wsi->stash->alpn = lws_strdup(i->alpn); - if (!wsi->stash->alpn) - goto bail1; - } + wsi->a.opaque_user_data = wsi->stash->opaque_user_data = + i->opaque_user_data; + pc = (char *)&wsi->stash[1]; + + for (n = 0; n < CIS_COUNT; n++) + if (cisin[n]) { + wsi->stash->cis[n] = pc; + m = (int)strlen(cisin[n]) + 1; + memcpy(pc, cisin[n], m); + pc += m; + } /* * at this point user callbacks like @@ -278,13 +320,18 @@ /* PHASE 8: notify protocol with role-specific connected callback */ - lwsl_debug("%s: wsi %p: cb %d to %s %s\n", __func__, - wsi, wsi->role_ops->adoption_cb[0], - wsi->role_ops->name, wsi->protocol->name); - - wsi->protocol->callback(wsi, - wsi->role_ops->adoption_cb[0], - wsi->user_space, NULL, 0); + /* raw socket per se doesn't want this... raw socket proxy wants it... */ + + if (wsi->role_ops != &role_ops_raw_skt || + (i->local_protocol_name && + !strcmp(i->local_protocol_name, "raw-proxy"))) { + lwsl_debug("%s: wsi %p: adoption cb %d to %s %s\n", __func__, + wsi, wsi->role_ops->adoption_cb[0], + wsi->role_ops->name, wsi->a.protocol->name); + + wsi->a.protocol->callback(wsi, wsi->role_ops->adoption_cb[0], + wsi->user_space, NULL, 0); + } #if defined(LWS_WITH_HUBBUB) if (i->uri_replace_to) @@ -293,19 +340,75 @@ i->uri_replace_to); #endif - if (i->method && !strcmp(i->method, "RAW")) - lws_http_client_connect_via_info2(wsi); + if (i->method && (!strcmp(i->method, "RAW") // || +// !strcmp(i->method, "MQTT") + )) { + + /* + * Not for MQTT here, since we don't know if we will + * pipeline it or not... + */ + +#if defined(LWS_WITH_TLS) + + wsi->tls.ssl = NULL; + + if (wsi->tls.use_ssl & LCCSCF_USE_SSL) { + const char *cce = NULL; + + switch ( +#if !defined(LWS_WITH_SYS_ASYNC_DNS) + lws_client_create_tls(wsi, &cce, 1) +#else + lws_client_create_tls(wsi, &cce, 0) +#endif + ) { + case 1: + return wsi; + case 0: + break; + default: + goto bail3; + } + } +#endif + + + /* fallthru */ + + wsi = lws_http_client_connect_via_info2(wsi); + } + + if (wsi) + /* + * If it subsequently fails, report CONNECTION_ERROR, + * because we're going to return a non-error return now. + */ + wsi->client_suppress_CONNECTION_ERROR = 0; return wsi; +#if defined(LWS_WITH_TLS) +bail3: + lws_close_free_wsi(wsi, LWS_CLOSE_STATUS_NOSTATUS, "tls start fail"); + + return NULL; +#endif + bail1: - lws_client_stash_destroy(wsi); + lws_free_set_NULL(wsi->stash); bail: lws_free(wsi); #if defined(LWS_ROLE_H1) || defined(LWS_ROLE_H2) bail2: #endif + +#if defined(LWS_WITH_TLS) + if (i->ssl_connection & LCCSCF_USE_SSL) + lws_tls_restrict_return(i->context); +#endif + if (i->pwsi) *i->pwsi = NULL; diff -Nru libwebsockets-3.2.1/lib/core-net/detailed-latency.c libwebsockets-4.1.6/lib/core-net/detailed-latency.c --- libwebsockets-3.2.1/lib/core-net/detailed-latency.c 1970-01-01 00:00:00.000000000 +0000 +++ libwebsockets-4.1.6/lib/core-net/detailed-latency.c 2020-12-01 17:40:26.000000000 +0000 @@ -0,0 +1,79 @@ +/* + * libwebsockets - small server side websockets and web server implementation + * + * Copyright (C) 2010 - 2019 Andy Green + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to + * deal in the Software without restriction, including without limitation the + * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or + * sell copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS + * IN THE SOFTWARE. + */ + +#include "private-lib-core.h" + +int +lws_det_lat_active(struct lws_context *context) +{ + return !!context->detailed_latency_cb; +} + +int +lws_det_lat_cb(struct lws_context *context, lws_detlat_t *d) +{ + int n; + + if (!context->detailed_latency_cb) + return 0; + + n = context->detailed_latency_cb(context, d); + + memset(&d->latencies, 0, sizeof(d->latencies)); + + return n; +} + +static const char types[] = "rwNCTt????"; +int +lws_det_lat_plot_cb(struct lws_context *context, const lws_detlat_t *d) +{ + char buf[80], *p = buf, *end = &p[sizeof(buf) - 1]; + + if (!context->detailed_latency_filepath) + return 1; + + if (context->latencies_fd == -1) { + context->latencies_fd = open(context->detailed_latency_filepath, + LWS_O_CREAT | LWS_O_TRUNC | LWS_O_WRONLY, 0600); + if (context->latencies_fd == -1) + return 1; + } + + p += lws_snprintf(p, lws_ptr_diff(end, p), + "%llu %c %u %u %u %u %u %zu %zu\n", + (unsigned long long)lws_now_usecs(), types[d->type], + d->latencies[LAT_DUR_PROXY_CLIENT_REQ_TO_WRITE], + d->latencies[LAT_DUR_PROXY_CLIENT_WRITE_TO_PROXY_RX], + d->latencies[LAT_DUR_PROXY_PROXY_REQ_TO_WRITE], + d->latencies[LAT_DUR_PROXY_CLIENT_REQ_TO_WRITE] + + d->latencies[LAT_DUR_PROXY_CLIENT_WRITE_TO_PROXY_RX] + + d->latencies[LAT_DUR_PROXY_PROXY_REQ_TO_WRITE], + d->latencies[LAT_DUR_PROXY_RX_TO_ONWARD_TX], + d->acc_size, d->req_size); + + write(context->latencies_fd, buf, lws_ptr_diff(p, buf)); + + return 0; +} diff -Nru libwebsockets-3.2.1/lib/core-net/dummy-callback.c libwebsockets-4.1.6/lib/core-net/dummy-callback.c --- libwebsockets-3.2.1/lib/core-net/dummy-callback.c 2019-12-18 14:45:31.000000000 +0000 +++ libwebsockets-4.1.6/lib/core-net/dummy-callback.c 2020-12-01 17:40:26.000000000 +0000 @@ -1,25 +1,31 @@ /* * libwebsockets - small server side websockets and web server implementation * - * Copyright (C) 2010-2018 Andy Green + * Copyright (C) 2010 - 2019 Andy Green * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation: - * version 2.1 of the License. + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to + * deal in the Software without restriction, including without limitation the + * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or + * sell copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: * - * This library is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. * - * You should have received a copy of the GNU Lesser General Public - * License along with this library; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, - * MA 02110-1301 USA + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS + * IN THE SOFTWARE. */ -#include "core/private.h" +#include "private-lib-core.h" + +/* max individual proxied header payload size */ +#define MAXHDRVAL 1024 #if defined(LWS_WITH_HTTP_PROXY) static int @@ -30,16 +36,23 @@ if (n < 1) { lwsl_debug("%s: no index %d:\n", __func__, index); + return 0; } - if (lws_hdr_copy(par, (char *)temp, temp_len, index) < 0) + if (lws_hdr_copy(par, (char *)temp, temp_len, index) < 0) { + lwsl_notice("%s: unable to copy par hdr idx %d (len %d)\n", + __func__, index, n); return -1; + } lwsl_debug("%s: index %d: %s\n", __func__, index, (char *)temp); - if (lws_add_http_header_by_token(wsi, index, temp, n, p, end)) + if (lws_add_http_header_by_token(wsi, index, temp, n, p, end)) { + lwsl_notice("%s: unable to append par hdr idx %d (len %d)\n", + __func__, index, n); return -1; + } return 0; } @@ -54,7 +67,7 @@ wsi->http.did_stream_close = 1; - if (wsi->http2_substream) { + if (wsi->mux_substream) { if (lws_write(wsi, (unsigned char *)buf + LWS_PRE, 0, LWS_WRITE_HTTP_FINAL) < 0) { lwsl_info("%s: COMPL_CLIENT_HTTP: h2 fin wr failed\n", @@ -109,10 +122,11 @@ if (!wsi->h1_ws_proxied || !wsi->parent) break; - lws_process_ws_upgrade2(wsi->parent); + if (lws_process_ws_upgrade2(wsi->parent)) + return -1; #if defined(LWS_WITH_HTTP2) - if (wsi->parent->http2_substream) + if (wsi->parent->mux_substream) lwsl_info("%s: proxied h2 -> h1 ws established\n", __func__); #endif break; @@ -122,17 +136,15 @@ case LWS_CALLBACK_CLIENT_CONNECTION_ERROR: case LWS_CALLBACK_CLIENT_CLOSED: - lwsl_user("%s: client closed: parent %p\n", __func__, wsi->parent); + lwsl_info("%s: client closed: parent %p\n", __func__, wsi->parent); if (wsi->parent) - lws_set_timeout(wsi->parent, - PENDING_TIMEOUT_KILLED_BY_PROXY_CLIENT_CLOSE, - LWS_TO_KILL_ASYNC); + lws_set_timeout(wsi->parent, 1, LWS_TO_KILL_ASYNC); break; case LWS_CALLBACK_CLIENT_APPEND_HANDSHAKE_HEADER: { unsigned char **p = (unsigned char **)in, *end = (*p) + len, - tmp[128]; + tmp[MAXHDRVAL]; proxy_header(wsi, wsi->parent, tmp, sizeof(tmp), WSI_TOKEN_HTTP_ACCEPT_LANGUAGE, p, end); @@ -156,7 +168,6 @@ if (!pkt) return -1; - pkt->pkt_list.prev = pkt->pkt_list.next = NULL; pkt->len = len; pkt->first = lws_is_first_fragment(wsi); pkt->final = lws_is_final_fragment(wsi); @@ -169,7 +180,7 @@ break; case LWS_CALLBACK_CLIENT_WRITEABLE: - dll = lws_dll2_get_tail(&wsi->ws->proxy_owner); + dll = lws_dll2_get_head(&wsi->ws->proxy_owner); if (!dll) break; @@ -180,12 +191,10 @@ pkt->first, pkt->final)) < 0) return -1; - wsi->parent->ws->proxy_buffered -= pkt->len; - lws_dll2_remove(dll); lws_free(pkt); - if (lws_dll2_get_tail(&wsi->ws->proxy_owner)) + if (lws_dll2_get_head(&wsi->ws->proxy_owner)) lws_callback_on_writable(wsi); break; @@ -195,7 +204,7 @@ return 1; case LWS_CALLBACK_CLOSED: - lwsl_user("%s: closed\n", __func__); + lwsl_info("%s: closed\n", __func__); return -1; case LWS_CALLBACK_RECEIVE: @@ -203,7 +212,6 @@ if (!pkt) return -1; - pkt->pkt_list.prev = pkt->pkt_list.next = NULL; pkt->len = len; pkt->first = lws_is_first_fragment(wsi); pkt->final = lws_is_final_fragment(wsi); @@ -216,7 +224,7 @@ break; case LWS_CALLBACK_SERVER_WRITEABLE: - dll = lws_dll2_get_tail(&wsi->ws->proxy_owner); + dll = lws_dll2_get_head(&wsi->ws->proxy_owner); if (!dll) break; @@ -227,10 +235,12 @@ pkt->first, pkt->final)) < 0) return -1; + wsi->ws->proxy_buffered -= pkt->len; + lws_dll2_remove(dll); lws_free(pkt); - if (lws_dll2_get_tail(&wsi->ws->proxy_owner)) + if (lws_dll2_get_head(&wsi->ws->proxy_owner)) lws_callback_on_writable(wsi); break; @@ -251,7 +261,8 @@ #endif -LWS_VISIBLE int + +int lws_callback_http_dummy(struct lws *wsi, enum lws_callback_reasons reason, void *user, void *in, size_t len) { @@ -260,7 +271,7 @@ struct lws_cgi_args *args; #endif #if defined(LWS_WITH_CGI) || defined(LWS_WITH_HTTP_PROXY) - char buf[8192]; + char buf[LWS_PRE + 32 + 8192]; int n; #endif #if defined(LWS_WITH_HTTP_PROXY) @@ -271,7 +282,7 @@ switch (reason) { #if defined(LWS_ROLE_H1) || defined(LWS_ROLE_H2) case LWS_CALLBACK_HTTP: -#ifndef LWS_NO_SERVER +#if defined(LWS_WITH_SERVER) if (lws_return_http_status(wsi, HTTP_STATUS_NOT_FOUND, NULL)) return -1; @@ -279,11 +290,11 @@ #endif return -1; break; -#if !defined(LWS_NO_SERVER) +#if defined(LWS_WITH_SERVER) case LWS_CALLBACK_HTTP_BODY_COMPLETION: #if defined(LWS_WITH_HTTP_PROXY) if (wsi->child_list) { - lwsl_user("%s: LWS_CALLBACK_HTTP_BODY_COMPLETION: %d\n", __func__, (int)len); + lwsl_info("%s: LWS_CALLBACK_HTTP_BODY_COMPLETION: %d\n", __func__, (int)len); break; } #endif @@ -297,7 +308,7 @@ #if defined(LWS_WITH_HTTP_PROXY) case LWS_CALLBACK_HTTP_BODY: if (wsi->child_list) { - lwsl_user("%s: LWS_CALLBACK_HTTP_BODY: stashing %d\n", __func__, (int)len); + lwsl_info("%s: LWS_CALLBACK_HTTP_BODY: stashing %d\n", __func__, (int)len); if (lws_buflist_append_segment(&wsi->http.buflist_post_body, in, len) < 0) return -1; lws_callback_on_writable(wsi->child_list); @@ -315,9 +326,10 @@ lwsl_debug("AUX_BF__CGI forcing close\n"); return -1; } - if (!n && wsi->http.cgi && wsi->http.cgi->stdwsi[LWS_STDOUT]) + if (!n && wsi->http.cgi && wsi->http.cgi->lsp && + wsi->http.cgi->lsp->stdwsi[LWS_STDOUT]) lws_rx_flow_control( - wsi->http.cgi->stdwsi[LWS_STDOUT], 1); + wsi->http.cgi->lsp->stdwsi[LWS_STDOUT], 1); if (wsi->reason_bf & LWS_CB_REASON_AUX_BF__CGI_HEADERS) wsi->reason_bf &= @@ -325,19 +337,23 @@ else wsi->reason_bf &= ~LWS_CB_REASON_AUX_BF__CGI; - if (wsi->http.cgi && wsi->http.cgi->cgi_transaction_over) + if (wsi->http.cgi && wsi->http.cgi->cgi_transaction_over) { + lwsl_info("%s: txn over\n", __func__); return -1; + } + break; } - if (wsi->reason_bf & LWS_CB_REASON_AUX_BF__CGI_CHUNK_END) { - if (!wsi->http2_substream) { + if ((wsi->http.cgi && wsi->http.cgi->cgi_transaction_over) || + (wsi->reason_bf & LWS_CB_REASON_AUX_BF__CGI_CHUNK_END)) { + if (!wsi->mux_substream) { memcpy(buf + LWS_PRE, "0\x0d\x0a\x0d\x0a", 5); lwsl_debug("writing chunk term and exiting\n"); - n = lws_write(wsi, (unsigned char *)buf + + lws_write(wsi, (unsigned char *)buf + LWS_PRE, 5, LWS_WRITE_HTTP); } else - n = lws_write(wsi, (unsigned char *)buf + + lws_write(wsi, (unsigned char *)buf + LWS_PRE, 0, LWS_WRITE_HTTP_FINAL); @@ -482,7 +498,7 @@ return 0; start = p = (unsigned char *)buf + LWS_PRE; - end = p + sizeof(buf) - LWS_PRE - 256; + end = p + sizeof(buf) - LWS_PRE - MAXHDRVAL; if (lws_add_http_header_status(lws_get_parent(wsi), lws_http_client_http_response(wsi), &p, end)) @@ -492,24 +508,24 @@ * copy these headers from the client connection to the parent */ - proxy_header(parent, wsi, end, 256, + proxy_header(parent, wsi, end, MAXHDRVAL, WSI_TOKEN_HTTP_CONTENT_LENGTH, &p, end); - proxy_header(parent, wsi, end, 256, + proxy_header(parent, wsi, end, MAXHDRVAL, WSI_TOKEN_HTTP_CONTENT_TYPE, &p, end); - proxy_header(parent, wsi, end, 256, + proxy_header(parent, wsi, end, MAXHDRVAL, WSI_TOKEN_HTTP_ETAG, &p, end); - proxy_header(parent, wsi, end, 256, + proxy_header(parent, wsi, end, MAXHDRVAL, WSI_TOKEN_HTTP_ACCEPT_LANGUAGE, &p, end); - proxy_header(parent, wsi, end, 256, + proxy_header(parent, wsi, end, MAXHDRVAL, WSI_TOKEN_HTTP_CONTENT_ENCODING, &p, end); - proxy_header(parent, wsi, end, 256, + proxy_header(parent, wsi, end, MAXHDRVAL, WSI_TOKEN_HTTP_CACHE_CONTROL, &p, end); - proxy_header(parent, wsi, end, 256, + proxy_header(parent, wsi, end, MAXHDRVAL, WSI_TOKEN_HTTP_SET_COOKIE, &p, end); - proxy_header(parent, wsi, end, 256, + proxy_header(parent, wsi, end, MAXHDRVAL, WSI_TOKEN_HTTP_LOCATION, &p, end); - if (!parent->http2_substream) + if (!parent->mux_substream) if (lws_add_http_header_by_token(parent, WSI_TOKEN_CONNECTION, (unsigned char *)"close", 5, &p, end)) @@ -523,7 +539,7 @@ * our own chunking since we still don't know the size. */ - if (!parent->http2_substream && + if (!parent->mux_substream && !lws_hdr_total_length(wsi, WSI_TOKEN_HTTP_CONTENT_LENGTH)) { lwsl_debug("downstream parent chunked\n"); if (lws_add_http_header_by_token(parent, @@ -583,10 +599,9 @@ case LWS_CALLBACK_CLOSED_CLIENT_HTTP: if (!lws_get_parent(wsi)) break; - lwsl_err("%s: LWS_CALLBACK_CLOSED_CLIENT_HTTP\n", __func__); - lws_set_timeout(lws_get_parent(wsi), - PENDING_TIMEOUT_KILLED_BY_PROXY_CLIENT_CLOSE, - LWS_TO_KILL_ASYNC); + // lwsl_err("%s: LWS_CALLBACK_CLOSED_CLIENT_HTTP\n", __func__); + lws_set_timeout(lws_get_parent(wsi), LWS_TO_KILL_ASYNC, + PENDING_TIMEOUT_KILLED_BY_PROXY_CLIENT_CLOSE); break; case LWS_CALLBACK_CLIENT_APPEND_HANDSHAKE_HEADER: @@ -638,8 +653,9 @@ /* TBD stdin rx flow control */ break; case LWS_STDOUT: - /* quench POLLIN on STDOUT until MASTER got writeable */ - lws_rx_flow_control(args->stdwsi[LWS_STDOUT], 0); + if (args->stdwsi[LWS_STDOUT]) + /* quench POLLIN on STDOUT until MASTER got writeable */ + lws_rx_flow_control(args->stdwsi[LWS_STDOUT], 0); wsi->reason_bf |= LWS_CB_REASON_AUX_BF__CGI; /* when writing to MASTER would not block */ lws_callback_on_writable(wsi); @@ -663,7 +679,7 @@ lwsl_debug("LWS_CALLBACK_CGI_TERMINATED: %d %" PRIu64 "\n", wsi->http.cgi->explicitly_chunked, (uint64_t)wsi->http.cgi->content_length); - if (!wsi->http.cgi->explicitly_chunked && + if (!(wsi->http.cgi->explicitly_chunked && wsi->mux_substream) && !wsi->http.cgi->content_length) { /* send terminating chunk */ lwsl_debug("LWS_CALLBACK_CGI_TERMINATED: ending\n"); @@ -672,6 +688,10 @@ lws_set_timeout(wsi, PENDING_TIMEOUT_CGI, 3); break; } + if (wsi->mux_substream && !wsi->cgi_stdout_zero_length) + lws_write(wsi, (unsigned char *)buf + LWS_PRE, 0, + LWS_WRITE_HTTP_FINAL); + if (lws_http_transaction_completed(wsi)) return -1; return 0; @@ -770,33 +790,38 @@ lwsl_notice("LWS_CALLBACK_CGI_STDIN_DATA: " "sent %d only %d went", n, args->len); + lwsl_info("%s: proxied %d bytes\n", __func__, n); + if (wsi->http.cgi->post_in_expected && args->stdwsi[LWS_STDIN] && args->stdwsi[LWS_STDIN]->desc.filefd > 0) { wsi->http.cgi->post_in_expected -= n; + if (!wsi->http.cgi->post_in_expected) { struct lws *siwsi = args->stdwsi[LWS_STDIN]; - lwsl_debug("%s: expected POST in end: " - "closing stdin wsi %p, fd %d\n", - __func__, siwsi, siwsi->desc.sockfd); - - __remove_wsi_socket_from_fds(siwsi); - lwsi_set_state(siwsi, LRS_DEAD_SOCKET); - siwsi->socket_is_permanently_unusable = 1; -// lws_remove_child_from_any_parent(siwsi); - if (wsi->context->event_loop_ops-> - close_handle_manually) { - - wsi->context->event_loop_ops-> - close_handle_manually(siwsi); - siwsi->told_event_loop_closed = 1; - } else { - compatible_close(siwsi->desc.sockfd); - __lws_free_wsi(siwsi); - } - wsi->http.cgi->pipe_fds[LWS_STDIN][1] = -1; - -// args->stdwsi[LWS_STDIN] = NULL; + /* + * The situation here is that we finished + * proxying the incoming body from the net to + * the STDIN stdwsi... and we want to close it + * so it can understand we are done (necessary + * if no content-length)... + */ + + lwsl_info("%s: expected POST in end: " + "closing stdin wsi %p, fd %d\n", + __func__, siwsi, + siwsi->desc.sockfd); + + /* + * We don't want the child / parent relationship + * to be handled in close, since we want the + * rest of the cgi and children to stay up + */ + + lws_remove_child_from_any_parent(siwsi); + lws_wsi_close(siwsi, LWS_TO_KILL_ASYNC); + wsi->http.cgi->lsp->stdwsi[LWS_STDIN] = NULL; + lws_spawn_stdwsi_closed(wsi->http.cgi->lsp, siwsi); } } @@ -813,7 +838,7 @@ #if LWS_MAX_SMP > 1 case LWS_CALLBACK_GET_THREAD_ID: - return (int)(unsigned long long)pthread_self(); + return (int)(lws_intptr_t)pthread_self(); #endif default: diff -Nru libwebsockets-3.2.1/lib/core-net/lws-dsh.c libwebsockets-4.1.6/lib/core-net/lws-dsh.c --- libwebsockets-3.2.1/lib/core-net/lws-dsh.c 2019-12-18 14:45:31.000000000 +0000 +++ libwebsockets-4.1.6/lib/core-net/lws-dsh.c 2020-12-01 17:40:26.000000000 +0000 @@ -1,25 +1,28 @@ /* * libwebsockets - small server side websockets and web server implementation * - * Copyright (C) 2010-2019 Andy Green + * Copyright (C) 2010 - 2019 Andy Green * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation: - * version 2.1 of the License. + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to + * deal in the Software without restriction, including without limitation the + * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or + * sell copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: * - * This library is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. * - * You should have received a copy of the GNU Lesser General Public - * License along with this library; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, - * MA 02110-1301 USA + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS + * IN THE SOFTWARE. */ -#include "core/private.h" +#include "private-lib-core.h" struct lws_dsh_search { size_t required; diff -Nru libwebsockets-3.2.1/lib/core-net/network.c libwebsockets-4.1.6/lib/core-net/network.c --- libwebsockets-3.2.1/lib/core-net/network.c 2019-12-18 14:45:31.000000000 +0000 +++ libwebsockets-4.1.6/lib/core-net/network.c 2020-12-01 17:40:26.000000000 +0000 @@ -1,27 +1,31 @@ /* * libwebsockets - small server side websockets and web server implementation * - * Copyright (C) 2010-2019 Andy Green + * Copyright (C) 2010 - 2019 Andy Green * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation: - * version 2.1 of the License. - * - * This library is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with this library; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, - * MA 02110-1301 USA + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to + * deal in the Software without restriction, including without limitation the + * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or + * sell copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS + * IN THE SOFTWARE. */ -#include "core/private.h" +#include "private-lib-core.h" +#include -#if !defined(LWS_WITH_ESP32) && !defined(LWS_PLAT_OPTEE) +#if !defined(LWS_PLAT_FREERTOS) && !defined(LWS_PLAT_OPTEE) static int interface_to_sa(struct lws_vhost *vh, const char *ifname, struct sockaddr_in *addr, size_t addrlen, int allow_ipv6) @@ -74,7 +78,7 @@ memset(&ai, 0, sizeof ai); ai.ai_family = PF_UNSPEC; ai.ai_socktype = SOCK_STREAM; -#if !defined(LWS_WITH_ESP32) +#if !defined(LWS_PLAT_FREERTOS) if (getnameinfo((struct sockaddr *)ads, sizeof(struct sockaddr_in), name, name_len, NULL, 0, 0)) @@ -108,45 +112,32 @@ return 0; } - -LWS_VISIBLE const char * -lws_get_peer_simple(struct lws *wsi, char *name, int namelen) +const char * +lws_get_peer_simple_fd(lws_sockfd_type fd, char *name, size_t namelen) { - socklen_t len, olen; -#ifdef LWS_WITH_IPV6 - struct sockaddr_in6 sin6; -#endif - struct sockaddr_in sin4; - int af = AF_INET; - void *p, *q; - - wsi = lws_get_network_wsi(wsi); + lws_sockaddr46 sa46; + socklen_t len = sizeof(sa46); -#ifdef LWS_WITH_IPV6 - if (LWS_IPV6_ENABLED(wsi->vhost)) { - len = sizeof(sin6); - p = &sin6; - af = AF_INET6; - q = &sin6.sin6_addr; - } else -#endif - { - len = sizeof(sin4); - p = &sin4; - q = &sin4.sin_addr; + if (getpeername(fd, (struct sockaddr *)&sa46, &len) < 0) { + lws_snprintf(name, namelen, "getpeername: %s", + strerror(LWS_ERRNO)); + return name; } - olen = len; - if (getpeername(wsi->desc.sockfd, p, &len) < 0 || len > olen) { - lwsl_warn("getpeername: %s\n", strerror(LWS_ERRNO)); - return NULL; - } + lws_sa46_write_numeric_address(&sa46, name, namelen); + + return name; +} - return lws_plat_inet_ntop(af, q, name, namelen); +const char * +lws_get_peer_simple(struct lws *wsi, char *name, size_t namelen) +{ + wsi = lws_get_network_wsi(wsi); + return lws_get_peer_simple_fd(wsi->desc.sockfd, name, namelen); } #endif -LWS_VISIBLE void +void lws_get_peer_addresses(struct lws *wsi, lws_sockfd_type fd, char *name, int name_len, char *rip, int rip_len) { @@ -156,17 +147,13 @@ struct sockaddr_in6 sin6; #endif struct sockaddr_in sin4; - struct lws_context *context = wsi->context; - int ret = -1; void *p; rip[0] = '\0'; name[0] = '\0'; - lws_latency_pre(context, wsi); - #ifdef LWS_WITH_IPV6 - if (LWS_IPV6_ENABLED(wsi->vhost)) { + if (LWS_IPV6_ENABLED(wsi->a.vhost)) { len = sizeof(sin6); p = &sin6; } else @@ -181,10 +168,9 @@ goto bail; } - ret = lws_get_addresses(wsi->vhost, p, name, name_len, rip, rip_len); + lws_get_addresses(wsi->a.vhost, p, name, name_len, rip, rip_len); bail: - lws_latency(context, wsi, "lws_get_peer_addresses", ret, 1); #endif (void)wsi; (void)fd; @@ -204,7 +190,7 @@ * LWS_ITOSA_BUSY: the port at the requested iface + port is already in use */ -LWS_EXTERN int +int lws_socket_bind(struct lws_vhost *vhost, lws_sockfd_type sockfd, int port, const char *iface, int ipv6_allowed) { @@ -219,7 +205,7 @@ socklen_t len = sizeof(struct sockaddr_storage); #endif int n; -#if !defined(LWS_WITH_ESP32) && !defined(LWS_PLAT_OPTEE) +#if !defined(LWS_PLAT_FREERTOS) && !defined(LWS_PLAT_OPTEE) int m; #endif struct sockaddr_storage sin; @@ -228,9 +214,8 @@ memset(&sin, 0, sizeof(sin)); #if defined(LWS_WITH_UNIX_SOCK) - if (LWS_UNIX_SOCK_ENABLED(vhost)) { + if (!port && LWS_UNIX_SOCK_ENABLED(vhost)) { v = (struct sockaddr *)&serv_unix; - n = sizeof(struct sockaddr_un); memset(&serv_unix, 0, sizeof(serv_unix)); serv_unix.sun_family = AF_UNIX; if (!iface) @@ -240,15 +225,18 @@ iface); return LWS_ITOSA_NOT_EXIST; } + n = (int)(sizeof(uint16_t) + strlen(iface)); strcpy(serv_unix.sun_path, iface); if (serv_unix.sun_path[0] == '@') serv_unix.sun_path[0] = '\0'; else unlink(serv_unix.sun_path); + // lwsl_hexdump_notice(v, n); + } else #endif -#if defined(LWS_WITH_IPV6) && !defined(LWS_WITH_ESP32) +#if defined(LWS_WITH_IPV6) && !defined(LWS_PLAT_FREERTOS) if (ipv6_allowed && LWS_IPV6_ENABLED(vhost)) { v = (struct sockaddr *)&serv_addr6; n = sizeof(struct sockaddr_in6); @@ -280,7 +268,7 @@ serv_addr4.sin_addr.s_addr = INADDR_ANY; serv_addr4.sin_family = AF_INET; -#if !defined(LWS_WITH_ESP32) && !defined(LWS_PLAT_OPTEE) +#if !defined(LWS_PLAT_FREERTOS) && !defined(LWS_PLAT_OPTEE) if (iface) { m = interface_to_sa(vhost, iface, (struct sockaddr_in *)v, n, 0); @@ -312,12 +300,14 @@ } else #endif if (n < 0) { + int _lws_errno = LWS_ERRNO; + lwsl_err("ERROR on binding fd %d to port %d (%d %d)\n", - sockfd, port, n, LWS_ERRNO); + sockfd, port, n, _lws_errno); /* if something already listening, tell caller to fail permanently */ - if (LWS_ERRNO == LWS_EADDRINUSE) + if (_lws_errno == LWS_EADDRINUSE) return LWS_ITOSA_BUSY; /* otherwise ask caller to retry later */ @@ -325,8 +315,8 @@ return LWS_ITOSA_NOT_EXIST; } -#if defined(LWS_WITH_UNIX_SOCK) - if (LWS_UNIX_SOCK_ENABLED(vhost)) { +#if defined(LWS_WITH_UNIX_SOCK) && !defined(WIN32) + if (!port && LWS_UNIX_SOCK_ENABLED(vhost)) { uid_t uid = vhost->context->uid; gid_t gid = vhost->context->gid; @@ -338,21 +328,21 @@ return LWS_ITOSA_NOT_EXIST; } } - if (uid && gid) { - if (chown(serv_unix.sun_path, uid, gid)) { + if (iface && iface[0] != '@' && uid && gid) { + if (chown(iface, uid, gid)) { lwsl_err("%s: failed to set %s perms %u:%u\n", - __func__, serv_unix.sun_path, + __func__, iface, (unsigned int)uid, (unsigned int)gid); return LWS_ITOSA_NOT_EXIST; } lwsl_notice("%s: vh %s unix skt %s perms %u:%u\n", - __func__, vhost->name, serv_unix.sun_path, + __func__, vhost->name, iface, (unsigned int)uid, (unsigned int)gid); - if (chmod(serv_unix.sun_path, 0660)) { + if (chmod(iface, 0660)) { lwsl_err("%s: failed to set %s to 0600 mode\n", - __func__, serv_unix.sun_path); + __func__, iface); return LWS_ITOSA_NOT_EXIST; } @@ -380,14 +370,12 @@ return port; } -static const lws_retry_range_t default_bo = { 3000, 7000 }; - unsigned int lws_retry_get_delay_ms(struct lws_context *context, - const lws_retry_bo_t *retry, uint16_t *ctry, char *conceal) + const lws_retry_bo_t *retry, uint16_t *ctry, + char *conceal) { - const lws_retry_range_t *r = &default_bo; - unsigned int ms; + uint64_t ms = 3000, pc = 30; /* sane-ish defaults if no retry table */ uint16_t ra; if (conceal) @@ -395,15 +383,20 @@ if (retry) { if (*ctry < retry->retry_ms_table_count) - r = &retry->retry_ms_table[*ctry]; + ms = retry->retry_ms_table[*ctry]; else - r = &retry->retry_ms_table[ + ms = retry->retry_ms_table[ retry->retry_ms_table_count - 1]; + + /* if no percent given, use the default 30% */ + if (retry->jitter_percent) + pc = retry->jitter_percent; } - ms = r->min_ms; if (lws_get_random(context, &ra, sizeof(ra)) == sizeof(ra)) - ms += ((r->max_ms - ms) * ra) / 65535; + ms += ((ms * pc * ra) >> 16) / 100; + else + assert(0); if (*ctry < 0xffff) (*ctry)++; @@ -411,19 +404,71 @@ if (retry && conceal) *conceal = (int)*ctry <= retry->conceal_count; - return ms; + return (unsigned int)ms; } -#if defined(LWS_WITH_IPV6) -LWS_EXTERN unsigned long -lws_get_addr_scope(const char *ipaddr) +int +lws_retry_sul_schedule(struct lws_context *context, int tid, + lws_sorted_usec_list_t *sul, + const lws_retry_bo_t *retry, sul_cb_t cb, uint16_t *ctry) { - unsigned long scope = 0; + char conceal; + uint64_t ms = lws_retry_get_delay_ms(context, retry, ctry, &conceal); -#ifndef WIN32 - struct ifaddrs *addrs, *addr; + if (!conceal) + return 1; + + lwsl_info("%s: sul %p: scheduling retry in %dms\n", __func__, sul, + (int)ms); + + lws_sul_schedule(context, tid, sul, cb, ms * 1000); + + return 0; +} + +int +lws_retry_sul_schedule_retry_wsi(struct lws *wsi, lws_sorted_usec_list_t *sul, + sul_cb_t cb, uint16_t *ctry) +{ + return lws_retry_sul_schedule(wsi->a.context, wsi->tsi, sul, + wsi->retry_policy, cb, ctry); +} + +#if defined(LWS_WITH_IPV6) +unsigned long +lws_get_addr_scope(const char *ifname_or_ipaddr) +{ + unsigned long scope; char ip[NI_MAXHOST]; unsigned int i; +#if !defined(WIN32) + struct ifaddrs *addrs, *addr; +#else + PIP_ADAPTER_ADDRESSES adapter, addrs = NULL; + PIP_ADAPTER_UNICAST_ADDRESS addr; + struct sockaddr_in6 *sockaddr; + ULONG size = 0; + int found = 0; + DWORD ret; +#endif + + /* + * First see if we can look the string up as a network interface name... + * windows vista+ also has this + */ + + scope = if_nametoindex(ifname_or_ipaddr); + if (scope > 0) + /* we found it from the interface name lookup */ + return scope; + + /* + * if not, try to look it up as an IP -> interface -> interface index + */ + + scope = 0; + +#if !defined(WIN32) getifaddrs(&addrs); for (addr = addrs; addr; addr = addr->ifa_next) { @@ -431,6 +476,7 @@ addr->ifa_addr->sa_family != AF_INET6) continue; + ip[0] = '\0'; getnameinfo(addr->ifa_addr, sizeof(struct sockaddr_in6), ip, sizeof(ip), @@ -443,21 +489,13 @@ break; } - if (!strcmp(ip, ipaddr)) { + if (!strcmp(ip, ifname_or_ipaddr)) { scope = if_nametoindex(addr->ifa_name); break; } } freeifaddrs(addrs); #else - PIP_ADAPTER_ADDRESSES adapter, addrs = NULL; - PIP_ADAPTER_UNICAST_ADDRESS addr; - ULONG size = 0; - DWORD ret; - struct sockaddr_in6 *sockaddr; - char ip[NI_MAXHOST]; - unsigned int i; - int found = 0; for (i = 0; i < 5; i++) { @@ -496,7 +534,7 @@ &sockaddr->sin6_addr, ip, sizeof(ip)); - if (!strcmp(ip, ipaddr)) { + if (!strcmp(ip, ifname_or_ipaddr)) { scope = sockaddr->sin6_scope_id; found = 1; break; @@ -515,5 +553,308 @@ } #endif +/* + * https://en.wikipedia.org/wiki/IPv6_address + * + * An IPv6 address is represented as eight groups of four hexadecimal digits, + * each group representing 16 bits (two octets, a group sometimes also called a + * hextet[6][7]). The groups are separated by colons (:). An example of an IPv6 + * address is: + * + * 2001:0db8:85a3:0000:0000:8a2e:0370:7334 + * + * The hexadecimal digits are case-insensitive, but IETF recommendations suggest + * the use of lower case letters. The full representation of eight 4-digit + * groups may be simplified by several techniques, eliminating parts of the + * representation. + * + * Leading zeroes in a group may be omitted, but each group must retain at least + * one hexadecimal digit.[1] Thus, the example address may be written as: + * + * 2001:db8:85a3:0:0:8a2e:370:7334 + * + * One or more consecutive groups containing zeros only may be replaced with a + * single empty group, using two consecutive colons (::).[1] The substitution + * may only be applied once in the address, however, because multiple + * occurrences would create an ambiguous representation. Thus, the example + * address can be further simplified: + * + * 2001:db8:85a3::8a2e:370:7334 + * + * The localhost (loopback) address, 0:0:0:0:0:0:0:1, and the IPv6 unspecified + * address, 0:0:0:0:0:0:0:0, are reduced to ::1 and ::, respectively. + * + * During the transition of the Internet from IPv4 to IPv6, it is typical to + * operate in a mixed addressing environment. For such use cases, a special + * notation has been introduced, which expresses IPv4-mapped and IPv4-compatible + * IPv6 addresses by writing the least-significant 32 bits of an address in the + * familiar IPv4 dot-decimal notation, whereas the other 96 (most significant) + * bits are written in IPv6 format. For example, the IPv4-mapped IPv6 address + * ::ffff:c000:0280 is written as ::ffff:192.0.2.128, thus expressing clearly + * the original IPv4 address that was mapped to IPv6. + */ + +int +lws_parse_numeric_address(const char *ads, uint8_t *result, size_t max_len) +{ + struct lws_tokenize ts; + uint8_t *orig = result, temp[16]; + int sects = 0, ipv6 = !!strchr(ads, ':'), skip_point = -1, dm = 0; + char t[5]; + size_t n; + long u; + + lws_tokenize_init(&ts, ads, LWS_TOKENIZE_F_NO_INTEGERS | + LWS_TOKENIZE_F_MINUS_NONTERM); + ts.len = strlen(ads); + if (!ipv6 && ts.len < 7) + return -1; + + if (ipv6 && ts.len < 2) + return -2; + + if (!ipv6 && max_len < 4) + return -3; + + if (ipv6 && max_len < 16) + return -4; + + if (ipv6) + memset(result, 0, max_len); + + do { + ts.e = lws_tokenize(&ts); + switch (ts.e) { + case LWS_TOKZE_TOKEN: + dm = 0; + if (ipv6) { + if (ts.token_len > 4) + return -1; + memcpy(t, ts.token, ts.token_len); + t[ts.token_len] = '\0'; + for (n = 0; n < ts.token_len; n++) + if (t[n] < '0' || t[n] > 'f' || + (t[n] > '9' && t[n] < 'A') || + (t[n] > 'F' && t[n] < 'a')) + return -1; + u = strtol(t, NULL, 16); + if (u > 0xffff) + return -5; + *result++ = (uint8_t)(u >> 8); + } else { + if (ts.token_len > 3) + return -1; + memcpy(t, ts.token, ts.token_len); + t[ts.token_len] = '\0'; + for (n = 0; n < ts.token_len; n++) + if (t[n] < '0' || t[n] > '9') + return -1; + u = strtol(t, NULL, 10); + if (u > 0xff) + return -6; + } + if (u < 0) + return -7; + *result++ = (uint8_t)u; + sects++; + break; + + case LWS_TOKZE_DELIMITER: + if (dm++) { + if (dm > 2) + return -8; + if (*ts.token != ':') + return -9; + /* back to back : */ + *result++ = 0; + *result++ = 0; + skip_point = lws_ptr_diff(result, orig); + break; + } + if (ipv6 && orig[2] == 0xff && orig[3] == 0xff && + skip_point == 2) { + /* ipv4 backwards compatible format */ + ipv6 = 0; + memset(orig, 0, max_len); + orig[10] = 0xff; + orig[11] = 0xff; + skip_point = -1; + result = &orig[12]; + sects = 0; + break; + } + if (ipv6 && *ts.token != ':') + return -10; + if (!ipv6 && *ts.token != '.') + return -11; + break; + + case LWS_TOKZE_ENDED: + if (!ipv6 && sects == 4) + return lws_ptr_diff(result, orig); + if (ipv6 && sects == 8) + return lws_ptr_diff(result, orig); + if (skip_point != -1) { + int ow = lws_ptr_diff(result, orig); + /* + * contains ...::... + */ + if (ow == 16) + return 16; + memcpy(temp, &orig[skip_point], ow - skip_point); + memset(&orig[skip_point], 0, 16 - skip_point); + memcpy(&orig[16 - (ow - skip_point)], temp, + ow - skip_point); + + return 16; + } + return -12; + + default: /* includes ENDED */ + lwsl_err("%s: malformed ip address\n", + __func__); + + return -13; + } + } while (ts.e > 0 && result - orig <= (int)max_len); + + lwsl_err("%s: ended on e %d\n", __func__, ts.e); + + return -14; +} + +int +lws_sa46_parse_numeric_address(const char *ads, lws_sockaddr46 *sa46) +{ + uint8_t a[16]; + int n; + + n = lws_parse_numeric_address(ads, a, sizeof(a)); + if (n < 0) + return -1; + +#if defined(LWS_WITH_IPV6) + if (n == 16) { + sa46->sa6.sin6_family = AF_INET6; + memcpy(sa46->sa6.sin6_addr.s6_addr, a, + sizeof(sa46->sa6.sin6_addr.s6_addr)); + + return 0; + } +#endif + + if (n != 4) + return -1; + + sa46->sa4.sin_family = AF_INET; + memcpy(&sa46->sa4.sin_addr.s_addr, a, + sizeof(sa46->sa4.sin_addr.s_addr)); + + return 0; +} + +int +lws_write_numeric_address(const uint8_t *ads, int size, char *buf, size_t len) +{ + char c, elided = 0, soe = 0, zb = -1, n, ipv4 = 0; + const char *e = buf + len; + char *obuf = buf; + int q = 0; + + if (size == 4) + return lws_snprintf(buf, len, "%u.%u.%u.%u", + ads[0], ads[1], ads[2], ads[3]); + + if (size != 16) + return -1; + + for (c = 0; c < (char)size / 2; c++) { + uint16_t v = (ads[q] << 8) | ads[q + 1]; + + if (buf + 8 > e) + return -1; + + q += 2; + if (soe) { + if (v) + *buf++ = ':'; + /* fall thru to print hex value */ + } else + if (!elided && !soe && !v) { + elided = soe = 1; + zb = c; + continue; + } + + if (ipv4) { + n = lws_snprintf(buf, e - buf, "%u.%u", + ads[q - 2], ads[q - 1]); + buf += n; + if (c == 6) + *buf++ = '.'; + } else { + if (soe && !v) + continue; + if (c) + *buf++ = ':'; + + buf += lws_snprintf(buf, e - buf, "%x", v); + + if (soe && v) { + soe = 0; + if (c == 5 && v == 0xffff && !zb) { + ipv4 = 1; + *buf++ = ':'; + } + } + } + } + if (buf + 3 > e) + return -1; + + if (soe) { /* as is the case for all zeros */ + *buf++ = ':'; + *buf++ = ':'; + *buf = '\0'; + } + + return lws_ptr_diff(buf, obuf); +} + +int +lws_sa46_write_numeric_address(lws_sockaddr46 *sa46, char *buf, size_t len) +{ + *buf = '\0'; +#if defined(LWS_WITH_IPV6) + if (sa46->sa4.sin_family == AF_INET6) + return lws_write_numeric_address( + (uint8_t *)&sa46->sa6.sin6_addr, 16, buf, len); +#endif + if (sa46->sa4.sin_family == AF_INET) + return lws_write_numeric_address( + (uint8_t *)&sa46->sa4.sin_addr, 4, buf, len); + + return -1; +} + +int +lws_sa46_compare_ads(const lws_sockaddr46 *sa46a, const lws_sockaddr46 *sa46b) +{ + if (sa46a->sa4.sin_family != sa46b->sa4.sin_family) + return 1; +#if defined(LWS_WITH_IPV6) + if (sa46a->sa4.sin_family == AF_INET6) + return memcmp(&sa46a->sa6.sin6_addr, &sa46b->sa6.sin6_addr, 16); +#endif + return sa46a->sa4.sin_addr.s_addr != sa46b->sa4.sin_addr.s_addr; +} + +#if defined(LWS_WITH_SYS_STATE) +lws_state_manager_t * +lws_system_get_state_manager(struct lws_context *context) +{ + return &context->mgr_system; +} +#endif diff -Nru libwebsockets-3.2.1/lib/core-net/output.c libwebsockets-4.1.6/lib/core-net/output.c --- libwebsockets-3.2.1/lib/core-net/output.c 2019-12-18 14:45:31.000000000 +0000 +++ libwebsockets-4.1.6/lib/core-net/output.c 2020-12-01 17:40:26.000000000 +0000 @@ -1,38 +1,49 @@ /* * libwebsockets - small server side websockets and web server implementation * - * Copyright (C) 2010-2018 Andy Green + * Copyright (C) 2010 - 2019 Andy Green * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation: - * version 2.1 of the License. + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to + * deal in the Software without restriction, including without limitation the + * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or + * sell copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: * - * This library is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. * - * You should have received a copy of the GNU Lesser General Public - * License along with this library; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, - * MA 02110-1301 USA + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS + * IN THE SOFTWARE. */ -#include "core/private.h" +#include "private-lib-core.h" /* * notice this returns number of bytes consumed, or -1 */ -int lws_issue_raw(struct lws *wsi, unsigned char *buf, size_t len) +int +lws_issue_raw(struct lws *wsi, unsigned char *buf, size_t len) { struct lws_context *context = lws_get_context(wsi); - struct lws_context_per_thread *pt = &wsi->context->pt[(int)wsi->tsi]; + struct lws_context_per_thread *pt = &wsi->a.context->pt[(int)wsi->tsi]; size_t real_len = len; unsigned int n, m; - // lwsl_notice("%s: len %d\n", __func__, (int)len); - // lwsl_hexdump_level(LLL_NOTICE, buf, len); + /* + * If you're looking to dump data being sent down the tls tunnel, see + * lws_ssl_capable_write() in lib/tls/mbedtls/mbedtls-ssl.c or + * lib/tls/openssl/openssl-ssl.c. + * + * There's also a corresponding lws_ssl_capable_read() in those files + * where you can enable a dump of decrypted data as soon as it was + * read. + */ /* * Detect if we got called twice without going through the @@ -43,8 +54,8 @@ lwsl_hexdump_level(LLL_INFO, buf, len); lwsl_info("** %p: vh: %s, prot: %s, role %s: " "Inefficient back-to-back write of %lu detected...\n", - wsi, wsi->vhost ? wsi->vhost->name : "no vhost", - wsi->protocol->name, wsi->role_ops->name, + wsi, wsi->a.vhost ? wsi->a.vhost->name : "no vhost", + wsi->a.protocol->name, wsi->role_ops->name, (unsigned long)len); } @@ -61,8 +72,8 @@ if (buf && lws_has_buffered_out(wsi)) { lwsl_info("** %p: vh: %s, prot: %s, incr buflist_out by %lu\n", - wsi, wsi->vhost ? wsi->vhost->name : "no vhost", - wsi->protocol->name, (unsigned long)len); + wsi, wsi->a.vhost ? wsi->a.vhost->name : "no vhost", + wsi->a.protocol->name, (unsigned long)len); /* * already buflist ahead of this, add it on the tail of the @@ -89,14 +100,14 @@ if (!len || !buf) return 0; - if (!wsi->http2_substream && !lws_socket_is_valid(wsi->desc.sockfd)) - lwsl_warn("** error invalid sock but expected to send\n"); + if (!wsi->mux_substream && !lws_socket_is_valid(wsi->desc.sockfd)) + lwsl_err("%s: invalid sock %p\n", __func__, wsi); /* limit sending */ - if (wsi->protocol->tx_packet_size) - n = (int)wsi->protocol->tx_packet_size; + if (wsi->a.protocol->tx_packet_size) + n = (int)wsi->a.protocol->tx_packet_size; else { - n = (int)wsi->protocol->rx_buffer_size; + n = (int)wsi->a.protocol->rx_buffer_size; if (!n) n = context->pt_serv_buf_size; } @@ -105,10 +116,8 @@ n = (int)len; /* nope, send it on the socket directly */ - lws_latency_pre(context, wsi); - m = lws_ssl_capable_write(wsi, buf, n); - lws_latency(context, wsi, "send lws_issue_raw", n, n == m); + m = lws_ssl_capable_write(wsi, buf, n); lwsl_info("%s: ssl_capable_write (%d) says %d\n", __func__, n, m); /* something got written, it can have been truncated now */ @@ -160,7 +169,7 @@ } #if defined(LWS_ROLE_H1) || defined(LWS_ROLE_H2) -#if !defined(LWS_WITHOUT_SERVER) +#if defined(LWS_WITH_SERVER) if (wsi->http.deferred_transaction_completed) { lwsl_notice("%s: partial completed, doing " "deferred transaction completed\n", @@ -171,6 +180,11 @@ } #endif #endif +#if defined(LWS_ROLE_WS) + /* Since buflist_out flushed, we're not inside a frame any more */ + if (wsi->ws) + wsi->ws->inside_frame = 0; +#endif } /* always callback on writeable */ lws_callback_on_writable(wsi); @@ -203,7 +217,7 @@ lws_stats_bump(pt, LWSSTATS_C_WRITE_PARTIALS, 1); lws_stats_bump(pt, LWSSTATS_B_PARTIALS_ACCEPTED_PARTS, m); -#if !defined(LWS_WITH_ESP32) && !defined(LWS_PLAT_OPTEE) +#if defined(LWS_WITH_UDP) if (lws_wsi_is_udp(wsi)) { /* stash original destination for fulfilling UDP partials */ wsi->udp->sa_pending = wsi->udp->sa; @@ -217,10 +231,15 @@ return (int)real_len; } -LWS_VISIBLE int lws_write(struct lws *wsi, unsigned char *buf, size_t len, - enum lws_write_protocol wp) +int +lws_write(struct lws *wsi, unsigned char *buf, size_t len, + enum lws_write_protocol wp) { - struct lws_context_per_thread *pt = &wsi->context->pt[(int)wsi->tsi]; + struct lws_context_per_thread *pt = &wsi->a.context->pt[(int)wsi->tsi]; +#if defined(LWS_WITH_DETAILED_LATENCY) + lws_usec_t us; +#endif + int m; lws_stats_bump(pt, LWSSTATS_C_API_LWS_WRITE, 1); @@ -235,33 +254,58 @@ #ifdef LWS_WITH_ACCESS_LOG wsi->http.access_log.sent += len; #endif - if (wsi->vhost) - wsi->vhost->conn_stats.tx += len; +#if defined(LWS_WITH_SERVER_STATUS) + if (wsi->a.vhost) + wsi->a.vhost->conn_stats.tx += len; +#endif +#if defined(LWS_WITH_DETAILED_LATENCY) + us = lws_now_usecs(); +#endif assert(wsi->role_ops); if (!wsi->role_ops->write_role_protocol) return lws_issue_raw(wsi, buf, len); - return wsi->role_ops->write_role_protocol(wsi, buf, len, &wp); + m = wsi->role_ops->write_role_protocol(wsi, buf, len, &wp); + if (m < 0) + return m; + +#if defined(LWS_WITH_DETAILED_LATENCY) + if (wsi->a.context->detailed_latency_cb) { + wsi->detlat.req_size = len; + wsi->detlat.acc_size = m; + wsi->detlat.type = LDLT_WRITE; + if (wsi->detlat.earliest_write_req_pre_write) + wsi->detlat.latencies[LAT_DUR_PROXY_PROXY_REQ_TO_WRITE] = + us - wsi->detlat.earliest_write_req_pre_write; + else + wsi->detlat.latencies[LAT_DUR_PROXY_PROXY_REQ_TO_WRITE] = 0; + wsi->detlat.latencies[LAT_DUR_USERCB] = lws_now_usecs() - us; + lws_det_lat_cb(wsi->a.context, &wsi->detlat); + + } +#endif + + return m; } -LWS_VISIBLE int +int lws_ssl_capable_read_no_ssl(struct lws *wsi, unsigned char *buf, int len) { - struct lws_context *context = wsi->context; + struct lws_context *context = wsi->a.context; struct lws_context_per_thread *pt = &context->pt[(int)wsi->tsi]; int n = 0; lws_stats_bump(pt, LWSSTATS_C_API_READ, 1); errno = 0; +#if defined(LWS_WITH_UDP) if (lws_wsi_is_udp(wsi)) { -#if !defined(LWS_WITH_ESP32) && !defined(LWS_PLAT_OPTEE) wsi->udp->salen = sizeof(wsi->udp->sa); n = recvfrom(wsi->desc.sockfd, (char *)buf, len, 0, &wsi->udp->sa, &wsi->udp->salen); -#endif } else +#endif n = recv(wsi->desc.sockfd, (char *)buf, len, 0); if (n >= 0) { @@ -276,8 +320,10 @@ if (!n) return LWS_SSL_CAPABLE_ERROR; - if (wsi->vhost) - wsi->vhost->conn_stats.rx += n; +#if defined(LWS_WITH_SERVER_STATUS) + if (wsi->a.vhost) + wsi->a.vhost->conn_stats.rx += n; +#endif lws_stats_bump(pt, LWSSTATS_B_READ, n); return n; @@ -292,7 +338,7 @@ return LWS_SSL_CAPABLE_ERROR; } -LWS_VISIBLE int +int lws_ssl_capable_write_no_ssl(struct lws *wsi, unsigned char *buf, int len) { int n = 0; @@ -300,8 +346,23 @@ ssize_t send(int sockfd, const void *buf, size_t len, int flags); #endif +#if defined(LWS_WITH_UDP) if (lws_wsi_is_udp(wsi)) { -#if !defined(LWS_WITH_ESP32) && !defined(LWS_PLAT_OPTEE) + if (wsi->a.context->udp_loss_sim_tx_pc) { + uint16_t u16; + /* + * We should randomly drop some of these + */ + + if (lws_get_random(wsi->a.context, &u16, 2) == 2 && + ((u16 * 100) / 0xffff) <= + wsi->a.context->udp_loss_sim_tx_pc) { + lwsl_warn("%s: dropping udp tx\n", __func__); + /* pretend it was sent */ + n = len; + goto post_send; + } + } if (lws_has_buffered_out(wsi)) n = sendto(wsi->desc.sockfd, (const char *)buf, len, 0, &wsi->udp->sa_pending, @@ -309,10 +370,17 @@ else n = sendto(wsi->desc.sockfd, (const char *)buf, len, 0, &wsi->udp->sa, wsi->udp->salen); -#endif } else - n = send(wsi->desc.sockfd, (char *)buf, len, MSG_NOSIGNAL); +#endif + if (wsi->role_ops->file_handle) + n = write((int)(lws_intptr_t)wsi->desc.filefd, buf, len); + else + n = send(wsi->desc.sockfd, (char *)buf, len, MSG_NOSIGNAL); // lwsl_info("%s: sent len %d result %d", __func__, len, n); + +#if defined(LWS_WITH_UDP) +post_send: +#endif if (n >= 0) return n; @@ -332,11 +400,11 @@ return LWS_SSL_CAPABLE_ERROR; } -LWS_VISIBLE int +int lws_ssl_pending_no_ssl(struct lws *wsi) { (void)wsi; -#if defined(LWS_WITH_ESP32) +#if defined(LWS_PLAT_FREERTOS) return 100; #else return 0; diff -Nru libwebsockets-3.2.1/lib/core-net/pollfd.c libwebsockets-4.1.6/lib/core-net/pollfd.c --- libwebsockets-3.2.1/lib/core-net/pollfd.c 2019-12-18 14:45:31.000000000 +0000 +++ libwebsockets-4.1.6/lib/core-net/pollfd.c 2020-12-01 17:40:26.000000000 +0000 @@ -1,30 +1,33 @@ /* * libwebsockets - small server side websockets and web server implementation * - * Copyright (C) 2010-2017 Andy Green + * Copyright (C) 2010 - 2020 Andy Green * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation: - * version 2.1 of the License. + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to + * deal in the Software without restriction, including without limitation the + * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or + * sell copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: * - * This library is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. * - * You should have received a copy of the GNU Lesser General Public - * License along with this library; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, - * MA 02110-1301 USA + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS + * IN THE SOFTWARE. */ -#include "core/private.h" +#include "private-lib-core.h" int _lws_change_pollfd(struct lws *wsi, int _and, int _or, struct lws_pollargs *pa) { -#if !defined(LWS_WITH_LIBUV) && !defined(LWS_WITH_LIBEV) && !defined(LWS_WITH_LIBEVENT) +#if !defined(LWS_WITH_EVENT_LIBS) volatile struct lws_context_per_thread *vpt; #endif struct lws_context_per_thread *pt; @@ -63,14 +66,12 @@ return 0; } - context = wsi->context; + context = wsi->a.context; pt = &context->pt[(int)wsi->tsi]; assert(wsi->position_in_fds_table < (int)pt->fds_count); -#if !defined(LWS_WITH_LIBUV) && \ - !defined(LWS_WITH_LIBEV) && \ - !defined(LWS_WITH_LIBEVENT) +#if !defined(LWS_WITH_EVENT_LIBS) /* * This only applies when we use the default poll() event loop. * @@ -137,6 +138,11 @@ lws_memory_barrier(); #endif +#if !defined(__linux__) + /* OSX couldn't see close on stdin pipe side otherwise */ + _or |= LWS_POLLHUP; +#endif + pfd = &pt->fds[wsi->position_in_fds_table]; pa->fd = wsi->desc.sockfd; lwsl_debug("%s: wsi %p: fd %d events %d -> %d\n", __func__, wsi, @@ -144,13 +150,13 @@ pa->prev_events = pfd->events; pa->events = pfd->events = (pfd->events & ~_and) | _or; - if (wsi->http2_substream) + if (wsi->mux_substream) return 0; #if defined(LWS_WITH_EXTERNAL_POLL) - if (wsi->vhost && - wsi->vhost->protocols[0].callback(wsi, + if (wsi->a.vhost && + wsi->a.vhost->protocols[0].callback(wsi, LWS_CALLBACK_CHANGE_MODE_POLL_FD, wsi->user_space, (void *)pa, 0)) { ret = -1; @@ -192,8 +198,8 @@ goto bail; } sampled_tid = pt->service_tid; - if (sampled_tid && wsi->vhost) { - tid = wsi->vhost->protocols[0].callback(wsi, + if (sampled_tid && wsi->a.vhost) { + tid = wsi->a.vhost->protocols[0].callback(wsi, LWS_CALLBACK_GET_THREAD_ID, NULL, NULL, 0); if (tid == -1) { ret = -1; @@ -208,7 +214,7 @@ return ret; } -#ifndef LWS_NO_SERVER +#if defined(LWS_WITH_SERVER) /* * Enable or disable listen sockets on this pt globally... * it's modulated according to the pt having space for a new accept. @@ -234,7 +240,7 @@ } #endif -#if defined(_DEBUG) +#if _LWS_ENABLED_LOGS & LLL_WARN void __dump_fds(struct lws_context_per_thread *pt, const char *s) { @@ -265,6 +271,8 @@ // __dump_fds(pt, "pre insert"); + lws_pt_assert_lock_held(pt); + lwsl_debug("%s: %p: tsi=%d, sock=%d, pos-in-fds=%d\n", __func__, wsi, wsi->tsi, wsi->desc.sockfd, pt->fds_count); @@ -275,7 +283,7 @@ } #if !defined(_WIN32) - if (!wsi->context->max_fds_unrelated_to_ulimit && + if (!wsi->a.context->max_fds_unrelated_to_ulimit && wsi->desc.sockfd - lws_plat_socket_offset() >= context->max_fds) { lwsl_err("Socket fd %d is too high (%d) offset %d\n", wsi->desc.sockfd, context->max_fds, @@ -285,13 +293,13 @@ #endif assert(wsi); - assert(wsi->event_pipe || wsi->vhost); + assert(wsi->event_pipe || wsi->a.vhost); assert(lws_socket_is_valid(wsi->desc.sockfd)); #if defined(LWS_WITH_EXTERNAL_POLL) - if (wsi->vhost && - wsi->vhost->protocols[0].callback(wsi, LWS_CALLBACK_LOCK_POLL, + if (wsi->a.vhost && + wsi->a.vhost->protocols[0].callback(wsi, LWS_CALLBACK_LOCK_POLL, wsi->user_space, (void *) &pa, 1)) return -1; #endif @@ -312,20 +320,20 @@ #if defined(LWS_WITH_EXTERNAL_POLL) /* external POLL support via protocol 0 */ - if (wsi->vhost && - wsi->vhost->protocols[0].callback(wsi, LWS_CALLBACK_ADD_POLL_FD, + if (wsi->a.vhost && + wsi->a.vhost->protocols[0].callback(wsi, LWS_CALLBACK_ADD_POLL_FD, wsi->user_space, (void *) &pa, 0)) ret = -1; #endif -#ifndef LWS_NO_SERVER - /* if no more room, defeat accepts on this thread */ +#if defined(LWS_WITH_SERVER) + /* if no more room, defeat accepts on this service thread */ if ((unsigned int)pt->fds_count == context->fd_limit_per_thread - 1) lws_accept_modulation(context, pt, 0); #endif #if defined(LWS_WITH_EXTERNAL_POLL) - if (wsi->vhost && - wsi->vhost->protocols[0].callback(wsi, LWS_CALLBACK_UNLOCK_POLL, + if (wsi->a.vhost && + wsi->a.vhost->protocols[0].callback(wsi, LWS_CALLBACK_UNLOCK_POLL, wsi->user_space, (void *)&pa, 1)) ret = -1; #endif @@ -338,7 +346,7 @@ int __remove_wsi_socket_from_fds(struct lws *wsi) { - struct lws_context *context = wsi->context; + struct lws_context *context = wsi->a.context; #if defined(LWS_WITH_EXTERNAL_POLL) struct lws_pollargs pa = { wsi->desc.sockfd, 0, 0 }; #endif @@ -346,10 +354,12 @@ struct lws *end_wsi; int v, m, ret = 0; + lws_pt_assert_lock_held(pt); + // __dump_fds(pt, "pre remove"); #if !defined(_WIN32) - if (!wsi->context->max_fds_unrelated_to_ulimit && + if (!wsi->a.context->max_fds_unrelated_to_ulimit && wsi->desc.sockfd - lws_plat_socket_offset() > context->max_fds) { lwsl_err("fd %d too high (%d)\n", wsi->desc.sockfd, context->max_fds); @@ -358,20 +368,19 @@ } #endif #if defined(LWS_WITH_EXTERNAL_POLL) - if (wsi->vhost && wsi->vhost->protocols && - wsi->vhost->protocols[0].callback(wsi, LWS_CALLBACK_LOCK_POLL, + if (wsi->a.vhost && wsi->a.vhost->protocols && + wsi->a.vhost->protocols[0].callback(wsi, LWS_CALLBACK_LOCK_POLL, wsi->user_space, (void *)&pa, 1)) return -1; #endif - lws_same_vh_protocol_remove(wsi); + __lws_same_vh_protocol_remove(wsi); /* the guy who is to be deleted's slot index in pt->fds */ m = wsi->position_in_fds_table; /* these are the only valid possibilities for position_in_fds_table */ - assert(m == LWS_NO_FDS_POS || (m >= 0 && - (unsigned int)m < pt->fds_count)); + assert(m == LWS_NO_FDS_POS || (m >= 0 && (unsigned int)m < pt->fds_count)); if (context->event_loop_ops->io) context->event_loop_ops->io(wsi, @@ -410,7 +419,7 @@ lwsl_err("no wsi for fd %d pos %d, " "pt->fds_count=%d\n", (int)pt->fds[m].fd, m, pt->fds_count); - assert(0); + // assert(0); } else end_wsi->position_in_fds_table = m; } @@ -421,13 +430,13 @@ #if defined(LWS_WITH_EXTERNAL_POLL) /* remove also from external POLL support via protocol 0 */ - if (lws_socket_is_valid(wsi->desc.sockfd) && wsi->vhost && - wsi->vhost->protocols[0].callback(wsi, LWS_CALLBACK_DEL_POLL_FD, + if (lws_socket_is_valid(wsi->desc.sockfd) && wsi->a.vhost && + wsi->a.vhost->protocols[0].callback(wsi, LWS_CALLBACK_DEL_POLL_FD, wsi->user_space, (void *) &pa, 0)) ret = -1; #endif -#ifndef LWS_NO_SERVER +#if defined(LWS_WITH_SERVER) if (!context->being_destroyed && /* if this made some room, accept connects on this thread */ (unsigned int)pt->fds_count < context->fd_limit_per_thread - 1) @@ -435,8 +444,8 @@ #endif #if defined(LWS_WITH_EXTERNAL_POLL) - if (wsi->vhost && - wsi->vhost->protocols[0].callback(wsi, LWS_CALLBACK_UNLOCK_POLL, + if (wsi->a.vhost && + wsi->a.vhost->protocols[0].callback(wsi, LWS_CALLBACK_UNLOCK_POLL, wsi->user_space, (void *) &pa, 1)) ret = -1; #endif @@ -453,7 +462,7 @@ struct lws_pollargs pa; int ret = 0; - if (!wsi || (!wsi->protocol && !wsi->event_pipe) || + if (!wsi || (!wsi->a.protocol && !wsi->event_pipe) || wsi->position_in_fds_table == LWS_NO_FDS_POS) return 0; @@ -462,8 +471,8 @@ return 1; #if defined(LWS_WITH_EXTERNAL_POLL) - if (wsi->vhost && - wsi->vhost->protocols[0].callback(wsi, LWS_CALLBACK_LOCK_POLL, + if (wsi->a.vhost && + wsi->a.vhost->protocols[0].callback(wsi, LWS_CALLBACK_LOCK_POLL, wsi->user_space, (void *) &pa, 0)) return -1; #endif @@ -471,8 +480,8 @@ ret = _lws_change_pollfd(wsi, _and, _or, &pa); #if defined(LWS_WITH_EXTERNAL_POLL) - if (wsi->vhost && - wsi->vhost->protocols[0].callback(wsi, LWS_CALLBACK_UNLOCK_POLL, + if (wsi->a.vhost && + wsi->a.vhost->protocols[0].callback(wsi, LWS_CALLBACK_UNLOCK_POLL, wsi->user_space, (void *) &pa, 0)) ret = -1; #endif @@ -486,7 +495,7 @@ struct lws_context_per_thread *pt; int ret = 0; - pt = &wsi->context->pt[(int)wsi->tsi]; + pt = &wsi->a.context->pt[(int)wsi->tsi]; lws_pt_lock(pt, __func__); ret = __lws_change_pollfd(wsi, _and, _or); @@ -495,10 +504,11 @@ return ret; } -LWS_VISIBLE int +int lws_callback_on_writable(struct lws *wsi) { struct lws_context_per_thread *pt; + struct lws *w = wsi; if (lwsi_state(wsi) == LRS_SHUTDOWN) return 0; @@ -506,7 +516,12 @@ if (wsi->socket_is_permanently_unusable) return 0; - pt = &wsi->context->pt[(int)wsi->tsi]; + pt = &wsi->a.context->pt[(int)wsi->tsi]; + +#if defined(LWS_WITH_DETAILED_LATENCY) + if (!wsi->detlat.earliest_write_req) + wsi->detlat.earliest_write_req = lws_now_usecs(); +#endif lws_stats_bump(pt, LWSSTATS_C_WRITEABLE_CB_REQ, 1); #if defined(LWS_WITH_STATS) @@ -516,20 +531,23 @@ } #endif - if (wsi->role_ops->callback_on_writable) { - if (wsi->role_ops->callback_on_writable(wsi)) + int q = wsi->role_ops->callback_on_writable(wsi); + //lwsl_notice("%s: rops_cow says %d\n", __func__, q); + if (q) return 1; - wsi = lws_get_network_wsi(wsi); - } + w = lws_get_network_wsi(wsi); + } else - if (wsi->position_in_fds_table == LWS_NO_FDS_POS) { - lwsl_debug("%s: failed to find socket %d\n", __func__, - wsi->desc.sockfd); - return -1; - } + if (w->position_in_fds_table == LWS_NO_FDS_POS) { + lwsl_debug("%s: failed to find socket %d\n", __func__, + wsi->desc.sockfd); + return -1; + } + + //lwsl_notice("%s: marking for POLLOUT %p (wsi %p)\n", __func__, w, wsi); - if (__lws_change_pollfd(wsi, 0, LWS_POLLOUT)) + if (__lws_change_pollfd(w, 0, LWS_POLLOUT)) return -1; return 1; @@ -548,39 +566,39 @@ void lws_same_vh_protocol_insert(struct lws *wsi, int n) { - lws_vhost_lock(wsi->vhost); + lws_vhost_lock(wsi->a.vhost); lws_dll2_remove(&wsi->same_vh_protocol); lws_dll2_add_head(&wsi->same_vh_protocol, - &wsi->vhost->same_vh_protocol_owner[n]); + &wsi->a.vhost->same_vh_protocol_owner[n]); wsi->bound_vhost_index = n; - lws_vhost_unlock(wsi->vhost); + lws_vhost_unlock(wsi->a.vhost); } void __lws_same_vh_protocol_remove(struct lws *wsi) { - if (wsi->vhost && wsi->vhost->same_vh_protocol_owner) + if (wsi->a.vhost && wsi->a.vhost->same_vh_protocol_owner) lws_dll2_remove(&wsi->same_vh_protocol); } void lws_same_vh_protocol_remove(struct lws *wsi) { - if (!wsi->vhost) + if (!wsi->a.vhost) return; - lws_vhost_lock(wsi->vhost); + lws_vhost_lock(wsi->a.vhost); __lws_same_vh_protocol_remove(wsi); - lws_vhost_unlock(wsi->vhost); + lws_vhost_unlock(wsi->a.vhost); } -LWS_VISIBLE int +int lws_callback_on_writable_all_protocol_vhost(const struct lws_vhost *vhost, const struct lws_protocols *protocol) { @@ -602,7 +620,7 @@ lws_dll2_get_head(&vhost->same_vh_protocol_owner[n])) { wsi = lws_container_of(d, struct lws, same_vh_protocol); - assert(wsi->protocol == protocol); + assert(wsi->a.protocol == protocol); lws_callback_on_writable(wsi); } lws_end_foreach_dll_safe(d, d1); @@ -610,7 +628,7 @@ return 0; } -LWS_VISIBLE int +int lws_callback_on_writable_all_protocol(const struct lws_context *context, const struct lws_protocols *protocol) { diff -Nru libwebsockets-3.2.1/lib/core-net/private.h libwebsockets-4.1.6/lib/core-net/private.h --- libwebsockets-3.2.1/lib/core-net/private.h 2019-12-18 14:45:31.000000000 +0000 +++ libwebsockets-4.1.6/lib/core-net/private.h 1970-01-01 00:00:00.000000000 +0000 @@ -1,1168 +0,0 @@ -/* - * libwebsockets - small server side websockets and web server implementation - * - * Copyright (C) 2010 - 2019 Andy Green - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation: - * version 2.1 of the License. - * - * This library is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with this library; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, - * MA 02110-1301 USA - */ - -#if !defined(__LWS_CORE_NET_PRIVATE_H__) -#define __LWS_CORE_NET_PRIVATE_H__ - -#if !defined(_POSIX_C_SOURCE) -#define _POSIX_C_SOURCE 200112L -#endif - -#include "roles/private.h" - -#ifdef LWS_WITH_IPV6 -#if defined(WIN32) || defined(_WIN32) -#include -#else -#include -#endif -#endif - -#ifdef __cplusplus -extern "C" { -#endif - -/* - * All lws_tls...() functions must return this type, converting the - * native backend result and doing the extra work to determine which one - * as needed. - * - * Native TLS backend return codes are NOT ALLOWED outside the backend. - * - * Non-SSL mode also uses these types. - */ -enum lws_ssl_capable_status { - LWS_SSL_CAPABLE_ERROR = -1, /* it failed */ - LWS_SSL_CAPABLE_DONE = 0, /* it succeeded */ - LWS_SSL_CAPABLE_MORE_SERVICE_READ = -2, /* retry WANT_READ */ - LWS_SSL_CAPABLE_MORE_SERVICE_WRITE = -3, /* retry WANT_WRITE */ - LWS_SSL_CAPABLE_MORE_SERVICE = -4, /* general retry */ -}; - - -/* - * - * ------ roles ------ - * - */ - -/* null-terminated array of pointers to roles lws built with */ -extern const struct lws_role_ops *available_roles[]; - -#define LWS_FOR_EVERY_AVAILABLE_ROLE_START(xx) { \ - const struct lws_role_ops **ppxx = available_roles; \ - while (*ppxx) { \ - const struct lws_role_ops *xx = *ppxx++; - -#define LWS_FOR_EVERY_AVAILABLE_ROLE_END }} - -/* - * - * ------ event_loop ops ------ - * - */ - -/* enums of socks version */ -enum socks_version { - SOCKS_VERSION_4 = 4, - SOCKS_VERSION_5 = 5 -}; - -/* enums of subnegotiation version */ -enum socks_subnegotiation_version { - SOCKS_SUBNEGOTIATION_VERSION_1 = 1, -}; - -/* enums of socks commands */ -enum socks_command { - SOCKS_COMMAND_CONNECT = 1, - SOCKS_COMMAND_BIND = 2, - SOCKS_COMMAND_UDP_ASSOCIATE = 3 -}; - -/* enums of socks address type */ -enum socks_atyp { - SOCKS_ATYP_IPV4 = 1, - SOCKS_ATYP_DOMAINNAME = 3, - SOCKS_ATYP_IPV6 = 4 -}; - -/* enums of socks authentication methods */ -enum socks_auth_method { - SOCKS_AUTH_NO_AUTH = 0, - SOCKS_AUTH_GSSAPI = 1, - SOCKS_AUTH_USERNAME_PASSWORD = 2 -}; - -/* enums of subnegotiation status */ -enum socks_subnegotiation_status { - SOCKS_SUBNEGOTIATION_STATUS_SUCCESS = 0, -}; - -/* enums of socks request reply */ -enum socks_request_reply { - SOCKS_REQUEST_REPLY_SUCCESS = 0, - SOCKS_REQUEST_REPLY_FAILURE_GENERAL = 1, - SOCKS_REQUEST_REPLY_CONNECTION_NOT_ALLOWED = 2, - SOCKS_REQUEST_REPLY_NETWORK_UNREACHABLE = 3, - SOCKS_REQUEST_REPLY_HOST_UNREACHABLE = 4, - SOCKS_REQUEST_REPLY_CONNECTION_REFUSED = 5, - SOCKS_REQUEST_REPLY_TTL_EXPIRED = 6, - SOCKS_REQUEST_REPLY_COMMAND_NOT_SUPPORTED = 7, - SOCKS_REQUEST_REPLY_ATYP_NOT_SUPPORTED = 8 -}; - -/* enums used to generate socks messages */ -enum socks_msg_type { - /* greeting */ - SOCKS_MSG_GREETING, - /* credential, user name and password */ - SOCKS_MSG_USERNAME_PASSWORD, - /* connect command */ - SOCKS_MSG_CONNECT -}; - -enum { - LWS_RXFLOW_ALLOW = (1 << 0), - LWS_RXFLOW_PENDING_CHANGE = (1 << 1), -}; - -enum lws_parser_return { - LPR_OK = 0, - LPR_FAIL = -1, - LPR_DO_FALLBACK = 2, - LPR_FORBIDDEN = -2 -}; - -enum pmd_return { - PMDR_UNKNOWN, - PMDR_DID_NOTHING, - PMDR_HAS_PENDING, - PMDR_EMPTY_NONFINAL, - PMDR_EMPTY_FINAL, - - PMDR_FAILED = -1 -}; - -typedef union { -#ifdef LWS_WITH_IPV6 - struct sockaddr_in6 sa6; -#endif - struct sockaddr_in sa4; -} sockaddr46; - - -#if defined(LWS_WITH_PEER_LIMITS) -struct lws_peer { - struct lws_peer *next; - struct lws_peer *peer_wait_list; - - time_t time_created; - time_t time_closed_all; - - uint8_t addr[32]; - uint32_t hash; - uint32_t count_wsi; - uint32_t total_wsi; - -#if defined(LWS_ROLE_H1) || defined(LWS_ROLE_H2) - struct lws_peer_role_http http; -#endif - - uint8_t af; -}; -#endif - -enum { - LWS_EV_READ = (1 << 0), - LWS_EV_WRITE = (1 << 1), - LWS_EV_START = (1 << 2), - LWS_EV_STOP = (1 << 3), - - LWS_EV_PREPARE_DELETION = (1u << 31), -}; - -#ifdef LWS_WITH_IPV6 -#define LWS_IPV6_ENABLED(vh) \ - (!lws_check_opt(vh->context->options, LWS_SERVER_OPTION_DISABLE_IPV6) && \ - !lws_check_opt(vh->options, LWS_SERVER_OPTION_DISABLE_IPV6)) -#else -#define LWS_IPV6_ENABLED(context) (0) -#endif - -#ifdef LWS_WITH_UNIX_SOCK -#define LWS_UNIX_SOCK_ENABLED(vhost) \ - (vhost->options & LWS_SERVER_OPTION_UNIX_SOCK) -#else -#define LWS_UNIX_SOCK_ENABLED(vhost) (0) -#endif - -enum uri_path_states { - URIPS_IDLE, - URIPS_SEEN_SLASH, - URIPS_SEEN_SLASH_DOT, - URIPS_SEEN_SLASH_DOT_DOT, -}; - -enum uri_esc_states { - URIES_IDLE, - URIES_SEEN_PERCENT, - URIES_SEEN_PERCENT_H1, -}; - - -#ifndef LWS_NO_CLIENT -struct client_info_stash { - char *address; - char *path; - char *host; - char *origin; - char *protocol; - char *method; - char *iface; - char *alpn; - void *opaque_user_data; /* not allocated or freed by lws */ -}; -#endif - -#define lws_wsi_is_udp(___wsi) (!!___wsi->udp) - -#define LWS_H2_FRAME_HEADER_LENGTH 9 - -int -__lws_sul_insert(lws_dll2_owner_t *own, lws_sorted_usec_list_t *sul, - lws_usec_t us); - -lws_usec_t -__lws_sul_service_ripe(lws_dll2_owner_t *own, lws_usec_t usnow); - -struct lws_timed_vh_protocol { - struct lws_timed_vh_protocol *next; - lws_sorted_usec_list_t sul; - const struct lws_protocols *protocol; - struct lws_vhost *vhost; /* only used for pending processing */ - int reason; - int tsi_req; -}; - -/* - * lws_dsh -*/ - -typedef struct lws_dsh_obj_head { - lws_dll2_owner_t owner; - int kind; -} lws_dsh_obj_head_t; - -typedef struct lws_dsh_obj { - lws_dll2_t list; /* must be first */ - lws_dsh_t *dsh; /* invalid when on free list */ - size_t size; /* invalid when on free list */ - size_t asize; -} lws_dsh_obj_t; - -struct lws_dsh { - lws_dll2_t list; - uint8_t *buf; - lws_dsh_obj_head_t *oha; /* array of object heads/kind */ - size_t buffer_size; - size_t locally_in_use; - size_t locally_free; - int count_kinds; - uint8_t being_destroyed; - /* - * Overallocations at create: - * - * - the buffer itself - * - the object heads array - */ -}; - -/* - * so we can have n connections being serviced simultaneously, - * these things need to be isolated per-thread. - */ - -struct lws_context_per_thread { -#if LWS_MAX_SMP > 1 - pthread_mutex_t lock_stats; - struct lws_mutex_refcount mr; - pthread_t self; -#endif - struct lws_dll2_owner dll_buflist_owner; /* guys with pending rxflow */ - struct lws_dll2_owner seq_owner; /* list of lws_sequencer-s */ - - struct lws_dll2_owner pt_sul_owner; - -#if defined (LWS_WITH_SEQUENCER) - lws_sorted_usec_list_t sul_seq_heartbeat; -#endif -#if defined(LWS_ROLE_H1) || defined(LWS_ROLE_H2) - lws_sorted_usec_list_t sul_ah_lifecheck; -#endif -#if defined(LWS_WITH_TLS) && !defined(LWS_NO_SERVER) - lws_sorted_usec_list_t sul_tls; -#endif -#if defined(LWS_PLAT_UNIX) - lws_sorted_usec_list_t sul_plat; -#endif -#if defined(LWS_WITH_STATS) - uint64_t lws_stats[LWSSTATS_SIZE]; - int updated; - lws_sorted_usec_list_t sul_stats; -#endif -#if defined(LWS_WITH_PEER_LIMITS) - lws_sorted_usec_list_t sul_peer_limits; -#endif - -#if defined(LWS_WITH_TLS) - struct lws_pt_tls tls; -#endif - struct lws *fake_wsi; /* used for callbacks where there's no wsi */ - - struct lws_context *context; - - /* - * usable by anything in the service code, but only if the scope - * does not last longer than the service action (since next service - * of any socket can likewise use it and overwrite) - */ - unsigned char *serv_buf; - - struct lws_pollfd *fds; - volatile struct lws_foreign_thread_pollfd * volatile foreign_pfd_list; -#ifdef _WIN32 - WSAEVENT events; - CRITICAL_SECTION interrupt_lock; -#endif - lws_sockfd_type dummy_pipe_fds[2]; - struct lws *pipe_wsi; - - /* --- role based members --- */ - -#if defined(LWS_ROLE_WS) && !defined(LWS_WITHOUT_EXTENSIONS) - struct lws_pt_role_ws ws; -#endif -#if defined(LWS_ROLE_H1) || defined(LWS_ROLE_H2) - struct lws_pt_role_http http; -#endif -#if defined(LWS_ROLE_DBUS) - struct lws_pt_role_dbus dbus; -#endif - - /* --- event library based members --- */ - -#if defined(LWS_WITH_LIBEV) - struct lws_pt_eventlibs_libev ev; -#endif -#if defined(LWS_WITH_LIBUV) - struct lws_pt_eventlibs_libuv uv; -#endif -#if defined(LWS_WITH_LIBEVENT) - struct lws_pt_eventlibs_libevent event; -#endif - -#if defined(LWS_WITH_LIBEV) || defined(LWS_WITH_LIBUV) || \ - defined(LWS_WITH_LIBEVENT) - struct lws_signal_watcher w_sigint; -#endif - - /* --- */ - - unsigned long count_conns; - unsigned int fds_count; - - /* - * set to the Thread ID that's doing the service loop just before entry - * to poll indicates service thread likely idling in poll() - * volatile because other threads may check it as part of processing - * for pollfd event change. - */ - volatile int service_tid; - int service_tid_detected; - - volatile unsigned char inside_poll; - volatile unsigned char foreign_spinlock; - - unsigned char tid; - - unsigned char inside_service:1; - unsigned char event_loop_foreign:1; - unsigned char event_loop_destroy_processing_done:1; -#ifdef _WIN32 - unsigned char interrupt_requested:1; -#endif -}; - -struct lws_conn_stats { - unsigned long long rx, tx; - unsigned long h1_conn, h1_trans, h2_trans, ws_upg, h2_alpn, h2_subs, - h2_upg, rejected; -}; - -/* - * virtual host -related context information - * vhostwide SSL context - * vhostwide proxy - * - * hierarchy: - * - * context -> vhost -> wsi - * - * incoming connection non-SSL vhost binding: - * - * listen socket -> wsi -> select vhost after first headers - * - * incoming connection SSL vhost binding: - * - * SSL SNI -> wsi -> bind after SSL negotiation - */ - - -struct lws_vhost { -#if !defined(LWS_WITHOUT_CLIENT) - char proxy_basic_auth_token[128]; -#endif -#if LWS_MAX_SMP > 1 - pthread_mutex_t lock; - char close_flow_vs_tsi[LWS_MAX_SMP]; -#endif - -#if defined(LWS_ROLE_H2) - struct lws_vhost_role_h2 h2; -#endif -#if defined(LWS_ROLE_H1) || defined(LWS_ROLE_H2) - struct lws_vhost_role_http http; -#endif -#if defined(LWS_ROLE_WS) && !defined(LWS_WITHOUT_EXTENSIONS) - struct lws_vhost_role_ws ws; -#endif - -#if defined(LWS_WITH_SOCKS5) - char socks_proxy_address[128]; - char socks_user[96]; - char socks_password[96]; -#endif -#if defined(LWS_WITH_LIBEV) - struct lws_io_watcher w_accept; -#endif - struct lws_conn_stats conn_stats; - struct lws_context *context; - struct lws_vhost *vhost_next; - - struct lws *lserv_wsi; - const char *name; - const char *iface; - const char *listen_accept_role; - const char *listen_accept_protocol; - const char *unix_socket_perms; - - void (*finalize)(struct lws_vhost *vh, void *arg); - void *finalize_arg; - -#if !defined(LWS_WITH_ESP32) && !defined(OPTEE_TA) && !defined(WIN32) - int bind_iface; -#endif - const struct lws_protocols *protocols; - void **protocol_vh_privs; - const struct lws_protocol_vhost_options *pvo; - const struct lws_protocol_vhost_options *headers; - struct lws_dll2_owner *same_vh_protocol_owner; - struct lws_vhost *no_listener_vhost_list; - struct lws_dll2_owner abstract_instances_owner; - -#if !defined(LWS_NO_CLIENT) - struct lws_dll2_owner dll_cli_active_conns_owner; -#endif - -#if defined(LWS_WITH_TLS) - struct lws_vhost_tls tls; -#endif - - struct lws_timed_vh_protocol *timed_vh_protocol_list; - void *user; - - int listen_port; - -#if defined(LWS_WITH_SOCKS5) - unsigned int socks_proxy_port; -#endif - unsigned int options; - int count_protocols; - int ka_time; - int ka_probes; - int ka_interval; - int keepalive_timeout; - int timeout_secs_ah_idle; - - int count_bound_wsi; - -#ifdef LWS_WITH_ACCESS_LOG - int log_fd; -#endif - - unsigned int allocated_vhost_protocols:1; - unsigned int created_vhost_protocols:1; - unsigned int being_destroyed:1; - - unsigned char default_protocol_index; - unsigned char raw_protocol_index; -}; - -void -__lws_vhost_destroy2(struct lws_vhost *vh); - -struct lws { - /* structs */ - -#if defined(LWS_ROLE_H1) || defined(LWS_ROLE_H2) - struct _lws_http_mode_related http; -#endif -#if defined(LWS_ROLE_H2) - struct _lws_h2_related h2; -#endif -#if defined(LWS_ROLE_WS) - struct _lws_websocket_related *ws; /* allocated if we upgrade to ws */ - lws_sorted_usec_list_t sul_ping; -#endif -#if defined(LWS_ROLE_DBUS) - struct _lws_dbus_mode_related dbus; -#endif - - - const struct lws_role_ops *role_ops; - lws_wsi_state_t wsistate; - lws_wsi_state_t wsistate_pre_close; - - /* lifetime members */ - -#if defined(LWS_WITH_LIBEV) || defined(LWS_WITH_LIBUV) || \ - defined(LWS_WITH_LIBEVENT) - struct lws_io_watcher w_read; -#endif -#if defined(LWS_WITH_LIBEV) || defined(LWS_WITH_LIBEVENT) - struct lws_io_watcher w_write; -#endif - - lws_sorted_usec_list_t sul_timeout; - lws_sorted_usec_list_t sul_hrtimer; - - /* pointers */ - - struct lws_context *context; - struct lws_vhost *vhost; - struct lws *parent; /* points to parent, if any */ - struct lws *child_list; /* points to first child */ - struct lws *sibling_list; /* subsequent children at same level */ - - const struct lws_protocols *protocol; - struct lws_dll2 same_vh_protocol; - - lws_seq_t *seq; /* associated sequencer if any */ - - struct lws_dll2 dll_buflist; /* guys with pending rxflow */ - -#if defined(LWS_WITH_THREADPOOL) - struct lws_threadpool_task *tp_task; -#endif - -#if defined(LWS_WITH_PEER_LIMITS) - struct lws_peer *peer; -#endif - - struct lws_udp *udp; -#ifndef LWS_NO_CLIENT - struct client_info_stash *stash; - char *cli_hostname_copy; - struct lws_dll2 dll_cli_active_conns; - struct lws_dll2_owner dll2_cli_txn_queue_owner; - struct lws_dll2 dll2_cli_txn_queue; -#endif - void *user_space; - void *opaque_parent_data; - void *opaque_user_data; - - struct lws_buflist *buflist; /* input-side buflist */ - struct lws_buflist *buflist_out; /* output-side buflist */ - -#if defined(LWS_WITH_TLS) - struct lws_lws_tls tls; -#endif - - lws_sock_file_fd_type desc; /* .filefd / .sockfd */ -#if defined(LWS_WITH_STATS) - uint64_t active_writable_req_us; -#if defined(LWS_WITH_TLS) - uint64_t accept_start_us; -#endif -#endif - -#ifdef LWS_LATENCY - unsigned long action_start; - unsigned long latency_start; -#endif - - /* ints */ -#define LWS_NO_FDS_POS (-1) - int position_in_fds_table; - -#ifndef LWS_NO_CLIENT - int chunk_remaining; -#endif - unsigned int cache_secs; - - unsigned int hdr_parsing_completed:1; - unsigned int http2_substream:1; - unsigned int upgraded_to_http2:1; - unsigned int h2_stream_carries_ws:1; - unsigned int h2_stream_carries_sse:1; - unsigned int seen_nonpseudoheader:1; - unsigned int listener:1; - unsigned int user_space_externally_allocated:1; - unsigned int socket_is_permanently_unusable:1; - unsigned int rxflow_change_to:2; - unsigned int conn_stat_done:1; - unsigned int cache_reuse:1; - unsigned int cache_revalidate:1; - unsigned int cache_intermediaries:1; - unsigned int favoured_pollin:1; - unsigned int sending_chunked:1; - unsigned int interpreting:1; - unsigned int already_did_cce:1; - unsigned int told_user_closed:1; - unsigned int told_event_loop_closed:1; - unsigned int waiting_to_send_close_frame:1; - unsigned int close_needs_ack:1; - unsigned int ipv6:1; - unsigned int parent_pending_cb_on_writable:1; - unsigned int cgi_stdout_zero_length:1; - unsigned int seen_zero_length_recv:1; - unsigned int rxflow_will_be_applied:1; - unsigned int event_pipe:1; - unsigned int handling_404:1; - unsigned int protocol_bind_balance:1; - unsigned int unix_skt:1; - unsigned int close_when_buffered_out_drained:1; - unsigned int h1_ws_proxied; - unsigned int proxied_ws_parent; - - unsigned int could_have_pending:1; /* detect back-to-back writes */ - unsigned int outer_will_close:1; - unsigned int shadow:1; /* we do not control fd lifecycle at all */ - -#ifdef LWS_WITH_ACCESS_LOG - unsigned int access_log_pending:1; -#endif -#ifndef LWS_NO_CLIENT - unsigned int do_ws:1; /* whether we are doing http or ws flow */ - unsigned int chunked:1; /* if the clientside connection is chunked */ - unsigned int client_rx_avail:1; - unsigned int client_http_body_pending:1; - unsigned int transaction_from_pipeline_queue:1; - unsigned int keepalive_active:1; - unsigned int keepalive_rejected:1; - unsigned int client_pipeline:1; - unsigned int client_h2_alpn:1; - unsigned int client_h2_substream:1; -#endif - -#ifdef _WIN32 - unsigned int sock_send_blocking:1; -#endif - -#ifndef LWS_NO_CLIENT - unsigned short ocport, c_port; -#endif - - /* chars */ - - char lws_rx_parse_state; /* enum lws_rx_parse_state */ - char rx_frame_type; /* enum lws_write_protocol */ - char pending_timeout; /* enum pending_timeout */ - char tsi; /* thread service index we belong to */ - char protocol_interpret_idx; - char redirects; - uint8_t rxflow_bitmap; - uint8_t bound_vhost_index; -#ifdef LWS_WITH_CGI - char cgi_channel; /* which of stdin/out/err */ - char hdr_state; -#endif -#ifndef LWS_NO_CLIENT - char chunk_parser; /* enum lws_chunk_parser */ -#endif -#if defined(LWS_WITH_CGI) || !defined(LWS_NO_CLIENT) - char reason_bf; /* internal writeable callback reason bitfield */ -#endif -#if defined(LWS_WITH_STATS) && defined(LWS_WITH_TLS) - char seen_rx; -#endif - uint8_t immortal_substream_count; - /* volatile to make sure code is aware other thread can change */ - volatile char handling_pollout; - volatile char leave_pollout_active; -#if LWS_MAX_SMP > 1 - volatile char undergoing_init_from_other_pt; -#endif - -}; - -#define lws_is_flowcontrolled(w) (!!(wsi->rxflow_bitmap)) - -void -lws_service_do_ripe_rxflow(struct lws_context_per_thread *pt); - -const struct lws_role_ops * -lws_role_by_name(const char *name); - -LWS_EXTERN int -lws_socket_bind(struct lws_vhost *vhost, lws_sockfd_type sockfd, int port, - const char *iface, int ipv6_allowed); - -#if defined(LWS_WITH_IPV6) -LWS_EXTERN unsigned long -lws_get_addr_scope(const char *ipaddr); -#endif - -LWS_EXTERN void -lws_close_free_wsi(struct lws *wsi, enum lws_close_status, const char *caller); -LWS_EXTERN void -__lws_close_free_wsi(struct lws *wsi, enum lws_close_status, const char *caller); - -LWS_EXTERN void -__lws_free_wsi(struct lws *wsi); - -#if LWS_MAX_SMP > 1 - -static LWS_INLINE void -lws_pt_mutex_init(struct lws_context_per_thread *pt) -{ - lws_mutex_refcount_init(&pt->mr); - pthread_mutex_init(&pt->lock_stats, NULL); -} - -static LWS_INLINE void -lws_pt_mutex_destroy(struct lws_context_per_thread *pt) -{ - pthread_mutex_destroy(&pt->lock_stats); - lws_mutex_refcount_destroy(&pt->mr); -} - -#define lws_pt_lock(pt, reason) lws_mutex_refcount_lock(&pt->mr, reason) -#define lws_pt_unlock(pt) lws_mutex_refcount_unlock(&pt->mr) - -static LWS_INLINE void -lws_pt_stats_lock(struct lws_context_per_thread *pt) -{ - pthread_mutex_lock(&pt->lock_stats); -} - -static LWS_INLINE void -lws_pt_stats_unlock(struct lws_context_per_thread *pt) -{ - pthread_mutex_unlock(&pt->lock_stats); -} -#endif - -/* - * EXTENSIONS - */ - -#if defined(LWS_WITHOUT_EXTENSIONS) -#define lws_any_extension_handled(_a, _b, _c, _d) (0) -#define lws_ext_cb_active(_a, _b, _c, _d) (0) -#define lws_ext_cb_all_exts(_a, _b, _c, _d, _e) (0) -#define lws_issue_raw_ext_access lws_issue_raw -#define lws_context_init_extensions(_a, _b) -#endif - -LWS_EXTERN int LWS_WARN_UNUSED_RESULT -lws_client_interpret_server_handshake(struct lws *wsi); - -LWS_EXTERN int LWS_WARN_UNUSED_RESULT -lws_ws_rx_sm(struct lws *wsi, char already_processed, unsigned char c); - -LWS_EXTERN int LWS_WARN_UNUSED_RESULT -lws_issue_raw_ext_access(struct lws *wsi, unsigned char *buf, size_t len); - -LWS_EXTERN void -lws_role_transition(struct lws *wsi, enum lwsi_role role, enum lwsi_state state, - const struct lws_role_ops *ops); - -int -lws_http_to_fallback(struct lws *wsi, unsigned char *buf, size_t len); - -LWS_EXTERN int LWS_WARN_UNUSED_RESULT -user_callback_handle_rxflow(lws_callback_function, struct lws *wsi, - enum lws_callback_reasons reason, void *user, - void *in, size_t len); - -LWS_EXTERN int -lws_plat_set_nonblocking(int fd); - -LWS_EXTERN int -lws_plat_set_socket_options(struct lws_vhost *vhost, lws_sockfd_type fd, - int unix_skt); - -LWS_EXTERN int -lws_plat_check_connection_error(struct lws *wsi); - -LWS_EXTERN int LWS_WARN_UNUSED_RESULT -lws_header_table_attach(struct lws *wsi, int autoservice); - -LWS_EXTERN int -lws_header_table_detach(struct lws *wsi, int autoservice); -LWS_EXTERN int -__lws_header_table_detach(struct lws *wsi, int autoservice); - -LWS_EXTERN void -lws_header_table_reset(struct lws *wsi, int autoservice); - -void -__lws_header_table_reset(struct lws *wsi, int autoservice); - -LWS_EXTERN char * LWS_WARN_UNUSED_RESULT -lws_hdr_simple_ptr(struct lws *wsi, enum lws_token_indexes h); - -LWS_EXTERN int LWS_WARN_UNUSED_RESULT -lws_hdr_simple_create(struct lws *wsi, enum lws_token_indexes h, const char *s); - -LWS_EXTERN int LWS_WARN_UNUSED_RESULT -lws_ensure_user_space(struct lws *wsi); - -LWS_EXTERN int LWS_WARN_UNUSED_RESULT -lws_change_pollfd(struct lws *wsi, int _and, int _or); - -#ifndef LWS_NO_SERVER - int _lws_vhost_init_server(const struct lws_context_creation_info *info, - struct lws_vhost *vhost); - LWS_EXTERN struct lws_vhost * - lws_select_vhost(struct lws_context *context, int port, const char *servername); - LWS_EXTERN int LWS_WARN_UNUSED_RESULT - lws_parse_ws(struct lws *wsi, unsigned char **buf, size_t len); - LWS_EXTERN void - lws_server_get_canonical_hostname(struct lws_context *context, - const struct lws_context_creation_info *info); -#else - #define _lws_vhost_init_server(_a, _b) (0) - #define lws_parse_ws(_a, _b, _c) (0) - #define lws_server_get_canonical_hostname(_a, _b) -#endif - -LWS_EXTERN int -__remove_wsi_socket_from_fds(struct lws *wsi); - -enum { - LWSRXFC_ERROR = -1, - LWSRXFC_CACHED = 0, - LWSRXFC_ADDITIONAL = 1, - LWSRXFC_TRIMMED = 2, -}; - - -int -_lws_plat_service_forced_tsi(struct lws_context *context, int tsi); - -LWS_EXTERN int -lws_rxflow_cache(struct lws *wsi, unsigned char *buf, int n, int len); - -LWS_EXTERN int -lws_service_flag_pending(struct lws_context *context, int tsi); - -LWS_EXTERN void -lws_client_stash_destroy(struct lws *wsi); - -static LWS_INLINE int -lws_has_buffered_out(struct lws *wsi) { return !!wsi->buflist_out; } - -LWS_EXTERN int LWS_WARN_UNUSED_RESULT -lws_ws_client_rx_sm(struct lws *wsi, unsigned char c); - -LWS_EXTERN int LWS_WARN_UNUSED_RESULT -lws_parse(struct lws *wsi, unsigned char *buf, int *len); - -LWS_EXTERN int LWS_WARN_UNUSED_RESULT -lws_parse_urldecode(struct lws *wsi, uint8_t *_c); - -LWS_EXTERN int LWS_WARN_UNUSED_RESULT -lws_http_action(struct lws *wsi); - -LWS_EXTERN void -__lws_close_free_wsi_final(struct lws *wsi); -LWS_EXTERN void -lws_libuv_closehandle(struct lws *wsi); -LWS_EXTERN int -lws_libuv_check_watcher_active(struct lws *wsi); - -LWS_VISIBLE LWS_EXTERN int -lws_plat_plugins_init(struct lws_context * context, const char * const *d); - -LWS_VISIBLE LWS_EXTERN int -lws_plat_plugins_destroy(struct lws_context * context); - -LWS_EXTERN void -lws_restart_ws_ping_pong_timer(struct lws *wsi); - -struct lws * -lws_adopt_socket_vhost(struct lws_vhost *vh, lws_sockfd_type accept_fd); - -void -lws_vhost_bind_wsi(struct lws_vhost *vh, struct lws *wsi); -void -lws_vhost_unbind_wsi(struct lws *wsi); - -void -__lws_set_timeout(struct lws *wsi, enum pending_timeout reason, int secs); -int -__lws_change_pollfd(struct lws *wsi, int _and, int _or); - - -int -lws_callback_as_writeable(struct lws *wsi); - -int -lws_role_call_client_bind(struct lws *wsi, - const struct lws_client_connect_info *i); -void -lws_remove_child_from_any_parent(struct lws *wsi); - -char * -lws_generate_client_ws_handshake(struct lws *wsi, char *p, const char *conn1); -int -lws_client_ws_upgrade(struct lws *wsi, const char **cce); -int -lws_create_client_ws_object(const struct lws_client_connect_info *i, - struct lws *wsi); -int -lws_alpn_comma_to_openssl(const char *comma, uint8_t *os, int len); -int -lws_role_call_alpn_negotiated(struct lws *wsi, const char *alpn); -int -lws_tls_server_conn_alpn(struct lws *wsi); - -int -lws_ws_client_rx_sm_block(struct lws *wsi, unsigned char **buf, size_t len); -void -lws_destroy_event_pipe(struct lws *wsi); - -/* socks */ -int -socks_generate_msg(struct lws *wsi, enum socks_msg_type type, ssize_t *msg_len); - - -void -lws_sum_stats(const struct lws_context *ctx, struct lws_conn_stats *cs); - -LWS_EXTERN int -__lws_timed_callback_remove(struct lws_vhost *vh, struct lws_timed_vh_protocol *p); - -LWS_EXTERN int LWS_WARN_UNUSED_RESULT -__insert_wsi_socket_into_fds(struct lws_context *context, struct lws *wsi); - -LWS_EXTERN int LWS_WARN_UNUSED_RESULT -lws_issue_raw(struct lws *wsi, unsigned char *buf, size_t len); - -LWS_EXTERN lws_usec_t -__lws_seq_timeout_check(struct lws_context_per_thread *pt, lws_usec_t usnow); - -LWS_EXTERN struct lws * LWS_WARN_UNUSED_RESULT -lws_client_connect_2(struct lws *wsi); - -LWS_VISIBLE struct lws * LWS_WARN_UNUSED_RESULT -lws_client_reset(struct lws **wsi, int ssl, const char *address, int port, - const char *path, const char *host); - -LWS_EXTERN struct lws * LWS_WARN_UNUSED_RESULT -lws_create_new_server_wsi(struct lws_vhost *vhost, int fixed_tsi); - -LWS_EXTERN char * LWS_WARN_UNUSED_RESULT -lws_generate_client_handshake(struct lws *wsi, char *pkt); - -LWS_EXTERN int -lws_handle_POLLOUT_event(struct lws *wsi, struct lws_pollfd *pollfd); - -LWS_EXTERN struct lws * -lws_http_client_connect_via_info2(struct lws *wsi); - - -#ifndef LWS_NO_CLIENT -LWS_EXTERN int lws_client_socket_service(struct lws *wsi, - struct lws_pollfd *pollfd, - struct lws *wsi_conn); -LWS_EXTERN struct lws * -lws_client_wsi_effective(struct lws *wsi); -LWS_EXTERN int LWS_WARN_UNUSED_RESULT -lws_http_transaction_completed_client(struct lws *wsi); -#if !defined(LWS_WITH_TLS) - #define lws_context_init_client_ssl(_a, _b) (0) -#endif -LWS_EXTERN void -lws_decode_ssl_error(void); -#else -#define lws_context_init_client_ssl(_a, _b) (0) -#endif - -LWS_EXTERN int -__lws_rx_flow_control(struct lws *wsi); - -LWS_EXTERN int -_lws_change_pollfd(struct lws *wsi, int _and, int _or, struct lws_pollargs *pa); - -#ifndef LWS_NO_SERVER -LWS_EXTERN int -lws_handshake_server(struct lws *wsi, unsigned char **buf, size_t len); -#else -#define lws_server_socket_service(_b, _c) (0) -#define lws_handshake_server(_a, _b, _c) (0) -#endif - -#ifdef LWS_WITH_ACCESS_LOG -LWS_EXTERN int -lws_access_log(struct lws *wsi); -LWS_EXTERN void -lws_prepare_access_log_info(struct lws *wsi, char *uri_ptr, int len, int meth); -#else -#define lws_access_log(_a) -#endif - -LWS_EXTERN int -lws_cgi_kill_terminated(struct lws_context_per_thread *pt); - -LWS_EXTERN void -lws_cgi_remove_and_kill(struct lws *wsi); - -LWS_EXTERN void -lws_plat_delete_socket_from_fds(struct lws_context *context, - struct lws *wsi, int m); -LWS_EXTERN void -lws_plat_insert_socket_into_fds(struct lws_context *context, - struct lws *wsi); - -LWS_EXTERN int -lws_plat_change_pollfd(struct lws_context *context, struct lws *wsi, - struct lws_pollfd *pfd); - - -int -lws_plat_pipe_create(struct lws *wsi); -int -lws_plat_pipe_signal(struct lws *wsi); -void -lws_plat_pipe_close(struct lws *wsi); - -LWS_EXTERN void -lws_add_wsi_to_draining_ext_list(struct lws *wsi); -LWS_EXTERN void -lws_remove_wsi_from_draining_ext_list(struct lws *wsi); -LWS_EXTERN int -lws_poll_listen_fd(struct lws_pollfd *fd); -LWS_EXTERN int -lws_plat_service(struct lws_context *context, int timeout_ms); -LWS_EXTERN LWS_VISIBLE int -_lws_plat_service_tsi(struct lws_context *context, int timeout_ms, int tsi); - -LWS_EXTERN int -lws_pthread_self_to_tsi(struct lws_context *context); -LWS_EXTERN const char * LWS_WARN_UNUSED_RESULT -lws_plat_inet_ntop(int af, const void *src, char *dst, int cnt); -LWS_EXTERN int LWS_WARN_UNUSED_RESULT -lws_plat_inet_pton(int af, const char *src, void *dst); - -LWS_EXTERN void -lws_same_vh_protocol_remove(struct lws *wsi); -LWS_EXTERN void -__lws_same_vh_protocol_remove(struct lws *wsi); -LWS_EXTERN void -lws_same_vh_protocol_insert(struct lws *wsi, int n); - -void -lws_seq_destroy_all_on_pt(struct lws_context_per_thread *pt); - -LWS_EXTERN int -lws_broadcast(struct lws_context_per_thread *pt, int reason, void *in, size_t len); - -#if defined(LWS_WITH_STATS) - void - lws_stats_bump(struct lws_context_per_thread *pt, int i, uint64_t bump); - void - lws_stats_max(struct lws_context_per_thread *pt, int index, uint64_t val); -#else - static LWS_INLINE uint64_t lws_stats_bump( - struct lws_context_per_thread *pt, int index, uint64_t bump) { - (void)pt; (void)index; (void)bump; return 0; } - static LWS_INLINE uint64_t lws_stats_max( - struct lws_context_per_thread *pt, int index, uint64_t val) { - (void)pt; (void)index; (void)val; return 0; } -#endif - - - -#if defined(LWS_WITH_PEER_LIMITS) -void -lws_peer_track_wsi_close(struct lws_context *context, struct lws_peer *peer); -int -lws_peer_confirm_ah_attach_ok(struct lws_context *context, - struct lws_peer *peer); -void -lws_peer_track_ah_detach(struct lws_context *context, struct lws_peer *peer); -void -lws_peer_cull_peer_wait_list(struct lws_context *context); -struct lws_peer * -lws_get_or_create_peer(struct lws_vhost *vhost, lws_sockfd_type sockfd); -void -lws_peer_add_wsi(struct lws_context *context, struct lws_peer *peer, - struct lws *wsi); -void -lws_peer_dump_from_wsi(struct lws *wsi); -#endif - -#ifdef LWS_WITH_HUBBUB -hubbub_error -html_parser_cb(const hubbub_token *token, void *pw); -#endif - -int -lws_threadpool_tsi_context(struct lws_context *context, int tsi); - -void -__lws_wsi_remove_from_sul(struct lws *wsi); - -int -lws_seq_pt_init(struct lws_context_per_thread *pt); - -int -lws_buflist_aware_read(struct lws_context_per_thread *pt, struct lws *wsi, - struct lws_tokens *ebuf); -int -lws_buflist_aware_consume(struct lws *wsi, struct lws_tokens *ebuf, int used, - int buffered); - -extern const struct lws_protocols protocol_abs_client_raw_skt, - protocol_abs_client_unit_test; - -void -lws_inform_client_conn_fail(struct lws *wsi, void *arg, size_t len); - -#ifdef __cplusplus -}; -#endif - -#endif diff -Nru libwebsockets-3.2.1/lib/core-net/private-lib-core-net.h libwebsockets-4.1.6/lib/core-net/private-lib-core-net.h --- libwebsockets-3.2.1/lib/core-net/private-lib-core-net.h 1970-01-01 00:00:00.000000000 +0000 +++ libwebsockets-4.1.6/lib/core-net/private-lib-core-net.h 2020-12-01 17:40:26.000000000 +0000 @@ -0,0 +1,1557 @@ +/* + * libwebsockets - small server side websockets and web server implementation + * + * Copyright (C) 2010 - 2019 Andy Green + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to + * deal in the Software without restriction, including without limitation the + * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or + * sell copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS + * IN THE SOFTWARE. + */ + +#if !defined(__LWS_CORE_NET_PRIVATE_H__) +#define __LWS_CORE_NET_PRIVATE_H__ + +#if !defined(_POSIX_C_SOURCE) +#define _POSIX_C_SOURCE 200112L +#endif + +/* + * Generic pieces needed to manage muxable stream protocols like h2 + */ + +struct lws_muxable { + struct lws *parent_wsi; + struct lws *child_list; + struct lws *sibling_list; + + unsigned int my_sid; + unsigned int child_count; + + uint32_t highest_sid; + + uint8_t requested_POLLOUT; +}; + +#include "private-lib-roles.h" + +#ifdef __cplusplus +extern "C" { +#endif + +/* + * All lws_tls...() functions must return this type, converting the + * native backend result and doing the extra work to determine which one + * as needed. + * + * Native TLS backend return codes are NOT ALLOWED outside the backend. + * + * Non-SSL mode also uses these types. + */ +enum lws_ssl_capable_status { + LWS_SSL_CAPABLE_ERROR = -1, /* it failed */ + LWS_SSL_CAPABLE_DONE = 0, /* it succeeded */ + LWS_SSL_CAPABLE_MORE_SERVICE_READ = -2, /* retry WANT_READ */ + LWS_SSL_CAPABLE_MORE_SERVICE_WRITE = -3, /* retry WANT_WRITE */ + LWS_SSL_CAPABLE_MORE_SERVICE = -4, /* general retry */ +}; + +#define __lws_sul_insert_us(owner, sul, _us) \ + (sul)->us = lws_now_usecs() + _us; \ + __lws_sul_insert(owner, sul) + + +/* + * + * ------ roles ------ + * + */ + +/* null-terminated array of pointers to roles lws built with */ +extern const struct lws_role_ops *available_roles[]; + +#define LWS_FOR_EVERY_AVAILABLE_ROLE_START(xx) { \ + const struct lws_role_ops **ppxx = available_roles; \ + while (*ppxx) { \ + const struct lws_role_ops *xx = *ppxx++; + +#define LWS_FOR_EVERY_AVAILABLE_ROLE_END }} + +/* + * + * ------ event_loop ops ------ + * + */ + +/* enums of socks version */ +enum socks_version { + SOCKS_VERSION_4 = 4, + SOCKS_VERSION_5 = 5 +}; + +/* enums of subnegotiation version */ +enum socks_subnegotiation_version { + SOCKS_SUBNEGOTIATION_VERSION_1 = 1, +}; + +/* enums of socks commands */ +enum socks_command { + SOCKS_COMMAND_CONNECT = 1, + SOCKS_COMMAND_BIND = 2, + SOCKS_COMMAND_UDP_ASSOCIATE = 3 +}; + +/* enums of socks address type */ +enum socks_atyp { + SOCKS_ATYP_IPV4 = 1, + SOCKS_ATYP_DOMAINNAME = 3, + SOCKS_ATYP_IPV6 = 4 +}; + +/* enums of socks authentication methods */ +enum socks_auth_method { + SOCKS_AUTH_NO_AUTH = 0, + SOCKS_AUTH_GSSAPI = 1, + SOCKS_AUTH_USERNAME_PASSWORD = 2 +}; + +/* enums of subnegotiation status */ +enum socks_subnegotiation_status { + SOCKS_SUBNEGOTIATION_STATUS_SUCCESS = 0, +}; + +/* enums of socks request reply */ +enum socks_request_reply { + SOCKS_REQUEST_REPLY_SUCCESS = 0, + SOCKS_REQUEST_REPLY_FAILURE_GENERAL = 1, + SOCKS_REQUEST_REPLY_CONNECTION_NOT_ALLOWED = 2, + SOCKS_REQUEST_REPLY_NETWORK_UNREACHABLE = 3, + SOCKS_REQUEST_REPLY_HOST_UNREACHABLE = 4, + SOCKS_REQUEST_REPLY_CONNECTION_REFUSED = 5, + SOCKS_REQUEST_REPLY_TTL_EXPIRED = 6, + SOCKS_REQUEST_REPLY_COMMAND_NOT_SUPPORTED = 7, + SOCKS_REQUEST_REPLY_ATYP_NOT_SUPPORTED = 8 +}; + +/* enums used to generate socks messages */ +enum socks_msg_type { + /* greeting */ + SOCKS_MSG_GREETING, + /* credential, user name and password */ + SOCKS_MSG_USERNAME_PASSWORD, + /* connect command */ + SOCKS_MSG_CONNECT +}; + +enum { + LWS_RXFLOW_ALLOW = (1 << 0), + LWS_RXFLOW_PENDING_CHANGE = (1 << 1), +}; + +typedef enum lws_parser_return { + LPR_FORBIDDEN = -2, + LPR_FAIL = -1, + LPR_OK = 0, + LPR_DO_FALLBACK = 2, +} lws_parser_return_t; + +enum pmd_return { + PMDR_UNKNOWN, + PMDR_DID_NOTHING, + PMDR_HAS_PENDING, + PMDR_EMPTY_NONFINAL, + PMDR_EMPTY_FINAL, + PMDR_NOTHING_WE_SHOULD_DO, + + PMDR_FAILED = -1 +}; + +#if defined(LWS_WITH_PEER_LIMITS) +struct lws_peer { + struct lws_peer *next; + struct lws_peer *peer_wait_list; + + lws_sockaddr46 sa46; + + time_t time_created; + time_t time_closed_all; + + uint32_t hash; + uint32_t count_wsi; + uint32_t total_wsi; + +#if defined(LWS_ROLE_H1) || defined(LWS_ROLE_H2) + struct lws_peer_role_http http; +#endif +}; +#endif + +enum { + LWS_EV_READ = (1 << 0), + LWS_EV_WRITE = (1 << 1), + LWS_EV_START = (1 << 2), + LWS_EV_STOP = (1 << 3), + + LWS_EV_PREPARE_DELETION = (1u << 31), +}; + +#ifdef LWS_WITH_IPV6 +#define LWS_IPV6_ENABLED(vh) \ + (!lws_check_opt(vh->context->options, LWS_SERVER_OPTION_DISABLE_IPV6) && \ + !lws_check_opt(vh->options, LWS_SERVER_OPTION_DISABLE_IPV6)) +#else +#define LWS_IPV6_ENABLED(context) (0) +#endif + +#ifdef LWS_WITH_UNIX_SOCK +#define LWS_UNIX_SOCK_ENABLED(vhost) \ + (vhost->options & LWS_SERVER_OPTION_UNIX_SOCK) +#else +#define LWS_UNIX_SOCK_ENABLED(vhost) (0) +#endif + +enum uri_path_states { + URIPS_IDLE, + URIPS_SEEN_SLASH, + URIPS_SEEN_SLASH_DOT, + URIPS_SEEN_SLASH_DOT_DOT, +}; + +enum uri_esc_states { + URIES_IDLE, + URIES_SEEN_PERCENT, + URIES_SEEN_PERCENT_H1, +}; + +#if defined(LWS_WITH_CLIENT) + +enum { + CIS_ADDRESS, + CIS_PATH, + CIS_HOST, + CIS_ORIGIN, + CIS_PROTOCOL, + CIS_METHOD, + CIS_IFACE, + CIS_ALPN, + + + CIS_COUNT +}; + +struct client_info_stash { + char *cis[CIS_COUNT]; + void *opaque_user_data; /* not allocated or freed by lws */ +}; +#endif + +#if defined(LWS_WITH_UDP) +#define lws_wsi_is_udp(___wsi) (!!___wsi->udp) +#endif + +#define LWS_H2_FRAME_HEADER_LENGTH 9 + + +lws_usec_t +__lws_sul_service_ripe(lws_dll2_owner_t *own, int num_own, lws_usec_t usnow); + +#if defined(LWS_WITH_DEPRECATED_THINGS) + +struct lws_timed_vh_protocol { + struct lws_timed_vh_protocol *next; + lws_sorted_usec_list_t sul; + const struct lws_protocols *protocol; + struct lws_vhost *vhost; /* only used for pending processing */ + int reason; + int tsi_req; +}; + +#endif + +/* + * lws_dsh +*/ + +typedef struct lws_dsh_obj_head { + lws_dll2_owner_t owner; + int kind; +} lws_dsh_obj_head_t; + +typedef struct lws_dsh_obj { + lws_dll2_t list; /* must be first */ + struct lws_dsh *dsh; /* invalid when on free list */ + size_t size; /* invalid when on free list */ + size_t asize; +} lws_dsh_obj_t; + +typedef struct lws_dsh { + lws_dll2_t list; + uint8_t *buf; + lws_dsh_obj_head_t *oha; /* array of object heads/kind */ + size_t buffer_size; + size_t locally_in_use; + size_t locally_free; + int count_kinds; + uint8_t being_destroyed; + /* + * Overallocations at create: + * + * - the buffer itself + * - the object heads array + */ +} lws_dsh_t; + +/* + * lws_async_dns + */ + +typedef struct lws_async_dns { + lws_sockaddr46 sa46; /* nameserver */ + lws_dll2_owner_t waiting; + lws_dll2_owner_t cached; + struct lws *wsi; + time_t time_set_server; + char dns_server_set; +} lws_async_dns_t; + +typedef enum { + LADNS_CONF_SERVER_UNKNOWN = -1, + LADNS_CONF_SERVER_SAME, + LADNS_CONF_SERVER_CHANGED +} lws_async_dns_server_check_t; + +#if defined(LWS_WITH_SYS_ASYNC_DNS) +void +lws_aysnc_dns_completed(struct lws *wsi, void *sa, size_t salen, + lws_async_dns_retcode_t ret); +#endif +void +lws_async_dns_cancel(struct lws *wsi); + +/* + * so we can have n connections being serviced simultaneously, + * these things need to be isolated per-thread. + */ + +struct lws_context_per_thread { +#if LWS_MAX_SMP > 1 + pthread_mutex_t lock_stats; + struct lws_mutex_refcount mr; + pthread_t self; +#endif + struct lws_dll2_owner dll_buflist_owner; /* guys with pending rxflow */ + struct lws_dll2_owner seq_owner; /* list of lws_sequencer-s */ + lws_dll2_owner_t attach_owner; /* pending lws_attach */ + +#if defined(LWS_WITH_SECURE_STREAMS) + lws_dll2_owner_t ss_owner; +#endif +#if defined(LWS_WITH_SECURE_STREAMS_PROXY_API) || \ + defined(LWS_WITH_SECURE_STREAMS_THREAD_API) + lws_dll2_owner_t ss_dsh_owner; + lws_dll2_owner_t ss_client_owner; +#endif + + struct lws_dll2_owner pt_sul_owner[LWS_COUNT_PT_SUL_OWNERS]; + +#if defined (LWS_WITH_SEQUENCER) + lws_sorted_usec_list_t sul_seq_heartbeat; +#endif +#if (defined(LWS_ROLE_H1) || defined(LWS_ROLE_H2)) && defined(LWS_WITH_SERVER) + lws_sorted_usec_list_t sul_ah_lifecheck; +#endif +#if defined(LWS_WITH_TLS) && defined(LWS_WITH_SERVER) + lws_sorted_usec_list_t sul_tls; +#endif +#if defined(LWS_PLAT_UNIX) + lws_sorted_usec_list_t sul_plat; +#endif +#if defined(LWS_ROLE_CGI) + lws_sorted_usec_list_t sul_cgi; +#endif +#if defined(LWS_WITH_STATS) + uint64_t lws_stats[LWSSTATS_SIZE]; + int updated; + lws_sorted_usec_list_t sul_stats; +#endif +#if defined(LWS_WITH_PEER_LIMITS) + lws_sorted_usec_list_t sul_peer_limits; +#endif + +#if !defined(LWS_PLAT_FREERTOS) + struct lws *fake_wsi; /* used for callbacks where there's no wsi */ +#endif + +#if defined(LWS_WITH_TLS) + struct lws_pt_tls tls; +#endif + struct lws_context *context; + + /* + * usable by anything in the service code, but only if the scope + * does not last longer than the service action (since next service + * of any socket can likewise use it and overwrite) + */ + unsigned char *serv_buf; + + struct lws_pollfd *fds; + volatile struct lws_foreign_thread_pollfd * volatile foreign_pfd_list; +#ifdef _WIN32 + WSAEVENT events[WSA_MAXIMUM_WAIT_EVENTS]; + CRITICAL_SECTION interrupt_lock; +#endif + lws_sockfd_type dummy_pipe_fds[2]; + struct lws *pipe_wsi; + + /* --- role based members --- */ + +#if defined(LWS_ROLE_WS) && !defined(LWS_WITHOUT_EXTENSIONS) + struct lws_pt_role_ws ws; +#endif +#if defined(LWS_ROLE_H1) || defined(LWS_ROLE_H2) + struct lws_pt_role_http http; +#endif +#if defined(LWS_ROLE_DBUS) + struct lws_pt_role_dbus dbus; +#endif + /* --- event library based members --- */ + +#if defined(LWS_WITH_EVENT_LIBS) + void *evlib_pt; /* overallocated */ +#endif + +#if defined(LWS_WITH_DETAILED_LATENCY) + lws_usec_t ust_left_poll; +#endif + + /* --- */ + + unsigned long count_conns; + unsigned int fds_count; + + /* + * set to the Thread ID that's doing the service loop just before entry + * to poll indicates service thread likely idling in poll() + * volatile because other threads may check it as part of processing + * for pollfd event change. + */ + volatile int service_tid; + int service_tid_detected; + + volatile unsigned char inside_poll; + volatile unsigned char foreign_spinlock; + + unsigned char tid; + + unsigned char inside_service:1; + unsigned char inside_lws_service:1; + unsigned char event_loop_foreign:1; + unsigned char event_loop_destroy_processing_done:1; + unsigned char destroy_self:1; + unsigned char is_destroyed:1; +}; + +#if defined(LWS_WITH_SERVER_STATUS) +struct lws_conn_stats { + unsigned long long rx, tx; + unsigned long h1_conn, h1_trans, h2_trans, ws_upg, h2_alpn, h2_subs, + h2_upg, rejected, mqtt_subs; +}; +#endif + +/* + * virtual host -related context information + * vhostwide SSL context + * vhostwide proxy + * + * hierarchy: + * + * context -> vhost -> wsi + * + * incoming connection non-SSL vhost binding: + * + * listen socket -> wsi -> select vhost after first headers + * + * incoming connection SSL vhost binding: + * + * SSL SNI -> wsi -> bind after SSL negotiation + */ + +struct lws_vhost { +#if defined(LWS_WITH_CLIENT) && defined(LWS_CLIENT_HTTP_PROXYING) + char proxy_basic_auth_token[128]; +#endif +#if LWS_MAX_SMP > 1 + pthread_mutex_t lock; + char close_flow_vs_tsi[LWS_MAX_SMP]; +#endif + +#if defined(LWS_ROLE_H2) + struct lws_vhost_role_h2 h2; +#endif +#if defined(LWS_ROLE_H1) || defined(LWS_ROLE_H2) + struct lws_vhost_role_http http; +#endif +#if defined(LWS_ROLE_WS) && !defined(LWS_WITHOUT_EXTENSIONS) + struct lws_vhost_role_ws ws; +#endif + +#if defined(LWS_WITH_SOCKS5) + char socks_proxy_address[128]; + char socks_user[96]; + char socks_password[96]; +#endif +#if defined(LWS_WITH_EVENT_LIBS) + void *evlib_vh; /* overallocated */ +#endif +#if defined(LWS_WITH_SERVER_STATUS) + struct lws_conn_stats conn_stats; +#endif + + uint64_t options; + + struct lws_context *context; + struct lws_vhost *vhost_next; + + const lws_retry_bo_t *retry_policy; + +#if defined(LWS_WITH_SERVER) && defined(LWS_WITH_SECURE_STREAMS) + lws_ss_handle_t *ss_handle; /* ss handle for the server obj */ +#endif + + struct lws *lserv_wsi; + const char *name; + const char *iface; + const char *listen_accept_role; + const char *listen_accept_protocol; + const char *unix_socket_perms; + + void (*finalize)(struct lws_vhost *vh, void *arg); + void *finalize_arg; + + const struct lws_protocols *protocols; + void **protocol_vh_privs; + const struct lws_protocol_vhost_options *pvo; + const struct lws_protocol_vhost_options *headers; + struct lws_dll2_owner *same_vh_protocol_owner; + struct lws_vhost *no_listener_vhost_list; + struct lws_dll2_owner abstract_instances_owner; /* vh lock */ + +#if defined(LWS_WITH_CLIENT) + struct lws_dll2_owner dll_cli_active_conns_owner; +#endif + struct lws_dll2_owner vh_awaiting_socket_owner; + +#if defined(LWS_WITH_TLS) + struct lws_vhost_tls tls; +#endif + +#if defined(LWS_WITH_DEPRECATED_THINGS) + struct lws_timed_vh_protocol *timed_vh_protocol_list; +#endif + void *user; + + int listen_port; +#if !defined(LWS_PLAT_FREERTOS) && !defined(OPTEE_TA) && !defined(WIN32) + int bind_iface; +#endif + +#if defined(LWS_WITH_SOCKS5) + unsigned int socks_proxy_port; +#endif + int count_protocols; + int ka_time; + int ka_probes; + int ka_interval; + int keepalive_timeout; + int timeout_secs_ah_idle; + int connect_timeout_secs; + + int count_bound_wsi; + +#ifdef LWS_WITH_ACCESS_LOG + int log_fd; +#endif + +#if defined(LWS_WITH_SECURE_STREAMS_STATIC_POLICY_ONLY) + int8_t ss_refcount; + /**< refcount of number of ss connections with streamtypes using this + * trust store */ +#endif + + uint8_t allocated_vhost_protocols:1; + uint8_t created_vhost_protocols:1; + uint8_t being_destroyed:1; + uint8_t from_ss_policy:1; + + unsigned char default_protocol_index; + unsigned char raw_protocol_index; +}; + +void +__lws_vhost_destroy2(struct lws_vhost *vh); + +#define mux_to_wsi(_m) lws_container_of(_m, struct lws, mux) + +void +lws_wsi_mux_insert(struct lws *wsi, struct lws *parent_wsi, int sid); +int +lws_wsi_mux_mark_parents_needing_writeable(struct lws *wsi); +struct lws * +lws_wsi_mux_move_child_to_tail(struct lws **wsi2); +int +lws_wsi_mux_action_pending_writeable_reqs(struct lws *wsi); + +void +lws_wsi_mux_dump_children(struct lws *wsi); + +void +lws_wsi_mux_close_children(struct lws *wsi, int reason); + +void +lws_wsi_mux_sibling_disconnect(struct lws *wsi); + +void +lws_wsi_mux_dump_waiting_children(struct lws *wsi); + +int +lws_wsi_mux_apply_queue(struct lws *wsi); + +/* + * struct lws + */ + +/* + * These pieces are very commonly used (via accessors) in user protocol handlers + * and have to be valid, even in the case no real wsi is available for the cb. + * + * We put all this category of pointers in there and compose it at the top of + * struct lws, so a dummy wsi providing these only needs to be this big, while + * still being castable for being a struct wsi * + */ + +struct lws_a { + struct lws_context *context; + struct lws_vhost *vhost; + const struct lws_protocols *protocol; + void *opaque_user_data; +}; + +/* + * For RTOS-class platforms, their code is relatively new, post-minimal examples + * and tend to not have legacy user protocol handler baggage touching unexpected + * things in fakewsi unconditionally... we can use an lws_a on the stack and + * don't need to define the rest of the wsi content, just cast it, this saves + * a wsi footprint in heap (typ 800 bytes nowadays even on RTOS). + * + * For other platforms that have been around for years and have thousands of + * different user protocol handler implementations, it's likely some of them + * will be touching the struct lws content unconditionally in the handler even + * when we are calling back with a non wsi-specific reason, and may react badly + * to it being garbage. So continue to implement those as a full, zero-ed down + * prepared fakewsi on heap at context creation time. + */ + +#if defined(LWS_PLAT_FREERTOS) +#define lws_fakewsi_def_plwsa(pt) struct lws_a lwsa, *plwsa = &lwsa +#else +#define lws_fakewsi_def_plwsa(pt) struct lws_a *plwsa = &(pt)->fake_wsi->a +#endif +/* since we reuse the pt version, also correct to zero down the lws_a part */ +#define lws_fakewsi_prep_plwsa_ctx(_c) \ + memset(plwsa, 0, sizeof(*plwsa)); plwsa->context = _c + +struct lws { + + struct lws_a a; + + /* structs */ + +#if defined(LWS_ROLE_H1) || defined(LWS_ROLE_H2) + struct _lws_http_mode_related http; +#endif +#if defined(LWS_ROLE_H2) + struct _lws_h2_related h2; +#endif +#if defined(LWS_ROLE_WS) + struct _lws_websocket_related *ws; /* allocated if we upgrade to ws */ +#endif +#if defined(LWS_ROLE_DBUS) + struct _lws_dbus_mode_related dbus; +#endif +#if defined(LWS_ROLE_MQTT) + struct _lws_mqtt_related *mqtt; +#endif + +#if defined(LWS_ROLE_H2) || defined(LWS_ROLE_MQTT) + struct lws_muxable mux; + struct lws_tx_credit txc; +#endif + + /* lifetime members */ + +#if defined(LWS_WITH_EVENT_LIBS) + void *evlib_wsi; /* overallocated */ +#endif + +#if defined(LWS_WITH_DETAILED_LATENCY) + lws_detlat_t detlat; +#endif + + lws_sorted_usec_list_t sul_timeout; + lws_sorted_usec_list_t sul_hrtimer; + lws_sorted_usec_list_t sul_validity; + lws_sorted_usec_list_t sul_connect_timeout; + + struct lws_dll2 dll_buflist; /* guys with pending rxflow */ + struct lws_dll2 same_vh_protocol; + struct lws_dll2 vh_awaiting_socket; +#if defined(LWS_WITH_SYS_ASYNC_DNS) + struct lws_dll2 adns; /* on adns list of guys to tell result */ + lws_async_dns_cb_t adns_cb; /* callback with result */ +#endif +#if defined(LWS_WITH_CLIENT) + struct lws_dll2 dll_cli_active_conns; + struct lws_dll2 dll2_cli_txn_queue; + struct lws_dll2_owner dll2_cli_txn_queue_owner; +#endif + +#if defined(LWS_WITH_ACCESS_LOG) + char simple_ip[(8 * 5)]; +#endif + /* pointers */ + + struct lws *parent; /* points to parent, if any */ + struct lws *child_list; /* points to first child */ + struct lws *sibling_list; /* subsequent children at same level */ + const struct lws_role_ops *role_ops; + struct lws_sequencer *seq; /* associated sequencer if any */ + const lws_retry_bo_t *retry_policy; + +#if defined(LWS_WITH_THREADPOOL) + lws_dll2_owner_t tp_task_owner; /* struct lws_threadpool_task */ +#endif + +#if defined(LWS_WITH_PEER_LIMITS) + struct lws_peer *peer; +#endif + +#if defined(LWS_WITH_UDP) + struct lws_udp *udp; +#endif +#if defined(LWS_WITH_CLIENT) + struct client_info_stash *stash; + char *cli_hostname_copy; + const struct addrinfo *dns_results; + const struct addrinfo *dns_results_next; +#endif + void *user_space; + void *opaque_parent_data; + + struct lws_buflist *buflist; /* input-side buflist */ + struct lws_buflist *buflist_out; /* output-side buflist */ + +#if defined(LWS_WITH_TLS) + struct lws_lws_tls tls; +#endif + + lws_sock_file_fd_type desc; /* .filefd / .sockfd */ +#if defined(LWS_WITH_STATS) + uint64_t active_writable_req_us; +#if defined(LWS_WITH_TLS) + uint64_t accept_start_us; +#endif +#endif + lws_wsi_state_t wsistate; + lws_wsi_state_t wsistate_pre_close; + + /* ints */ +#define LWS_NO_FDS_POS (-1) + int position_in_fds_table; + +#if defined(LWS_WITH_CLIENT) + int chunk_remaining; + int flags; +#endif + unsigned int cache_secs; + + unsigned int hdr_parsing_completed:1; + unsigned int mux_substream:1; + unsigned int upgraded_to_http2:1; + unsigned int mux_stream_immortal:1; + unsigned int h2_stream_carries_ws:1; /* immortal set as well */ + unsigned int h2_stream_carries_sse:1; /* immortal set as well */ + unsigned int h2_acked_settings:1; + unsigned int seen_nonpseudoheader:1; + unsigned int listener:1; + unsigned int pf_packet:1; + unsigned int do_broadcast:1; + unsigned int user_space_externally_allocated:1; + unsigned int socket_is_permanently_unusable:1; + unsigned int rxflow_change_to:2; + unsigned int conn_stat_done:1; + unsigned int cache_reuse:1; + unsigned int cache_revalidate:1; + unsigned int cache_intermediaries:1; + unsigned int favoured_pollin:1; + unsigned int sending_chunked:1; + unsigned int interpreting:1; + unsigned int already_did_cce:1; + unsigned int told_user_closed:1; + unsigned int told_event_loop_closed:1; + unsigned int waiting_to_send_close_frame:1; + unsigned int close_needs_ack:1; + unsigned int ipv6:1; + unsigned int parent_pending_cb_on_writable:1; + unsigned int cgi_stdout_zero_length:1; + unsigned int seen_zero_length_recv:1; + unsigned int rxflow_will_be_applied:1; + unsigned int event_pipe:1; + unsigned int handling_404:1; + unsigned int protocol_bind_balance:1; + unsigned int unix_skt:1; + unsigned int close_when_buffered_out_drained:1; + unsigned int h1_ws_proxied:1; + unsigned int proxied_ws_parent:1; + unsigned int do_bind:1; + unsigned int validity_hup:1; + unsigned int skip_fallback:1; + unsigned int file_desc:1; + unsigned int conn_validity_wakesuspend:1; + + unsigned int could_have_pending:1; /* detect back-to-back writes */ + unsigned int outer_will_close:1; + unsigned int shadow:1; /* we do not control fd lifecycle at all */ +#if defined(LWS_WITH_SECURE_STREAMS) + unsigned int for_ss:1; +#endif + +#ifdef LWS_WITH_ACCESS_LOG + unsigned int access_log_pending:1; +#endif +#if defined(LWS_WITH_CLIENT) + unsigned int do_ws:1; /* whether we are doing http or ws flow */ + unsigned int chunked:1; /* if the clientside connection is chunked */ + unsigned int client_rx_avail:1; + unsigned int client_http_body_pending:1; + unsigned int transaction_from_pipeline_queue:1; + unsigned int keepalive_active:1; + unsigned int keepalive_rejected:1; + unsigned int redirected_to_get:1; + unsigned int client_pipeline:1; + unsigned int client_h2_alpn:1; + unsigned int client_mux_substream:1; + unsigned int client_mux_migrated:1; + unsigned int client_subsequent_mime_part:1; + unsigned int client_no_follow_redirect:1; + unsigned int client_suppress_CONNECTION_ERROR:1; + /**< because the client connection creation api is still the parent of + * this activity, and will report the failure */ +#endif + +#ifdef _WIN32 + unsigned int sock_send_blocking:1; +#endif + + uint16_t ocport, c_port; + uint16_t retry; +#if defined(LWS_WITH_CLIENT) + uint16_t keep_warm_secs; +#endif + + /* chars */ + + char lws_rx_parse_state; /* enum lws_rx_parse_state */ + char rx_frame_type; /* enum lws_write_protocol */ + char pending_timeout; /* enum pending_timeout */ + char tsi; /* thread service index we belong to */ + char protocol_interpret_idx; + char redirects; + uint8_t rxflow_bitmap; + uint8_t bound_vhost_index; + uint8_t lsp_channel; /* which of stdin/out/err */ +#ifdef LWS_WITH_CGI + char hdr_state; +#endif +#if defined(LWS_WITH_CLIENT) + char chunk_parser; /* enum lws_chunk_parser */ + uint8_t addrinfo_idx; + uint8_t sys_tls_client_cert; +#endif +#if defined(LWS_WITH_CGI) || defined(LWS_WITH_CLIENT) + char reason_bf; /* internal writeable callback reason bitfield */ +#endif +#if defined(LWS_WITH_STATS) && defined(LWS_WITH_TLS) + char seen_rx; +#endif + uint8_t immortal_substream_count; + /* volatile to make sure code is aware other thread can change */ + volatile char handling_pollout; + volatile char leave_pollout_active; +#if LWS_MAX_SMP > 1 + volatile char undergoing_init_from_other_pt; +#endif + +}; + +#define lws_is_flowcontrolled(w) (!!(wsi->rxflow_bitmap)) + +#if defined(LWS_WITH_SPAWN) + +#if defined(WIN32) || defined(_WIN32) +#else +#include +#include +#endif + +struct lws_spawn_piped { + + struct lws_spawn_piped_info info; + + struct lws_dll2 dll; + lws_sorted_usec_list_t sul; + lws_sorted_usec_list_t sul_reap; + + struct lws_context *context; + struct lws *stdwsi[3]; + lws_filefd_type pipe_fds[3][2]; + int count_log_lines; + + lws_usec_t created; /* set by lws_spawn_piped() */ + lws_usec_t reaped; + + lws_usec_t accounting[4]; + +#if defined(WIN32) + HANDLE child_pid; + lws_sorted_usec_list_t sul_poll; +#else + pid_t child_pid; + + siginfo_t si; +#endif + int reap_retry_budget; + + uint8_t pipes_alive:2; + uint8_t we_killed_him_timeout:1; + uint8_t we_killed_him_spew:1; + uint8_t ungraceful:1; +}; + +void +lws_spawn_piped_destroy(struct lws_spawn_piped **lsp); + +int +lws_spawn_reap(struct lws_spawn_piped *lsp); + +#endif + +void +lws_service_do_ripe_rxflow(struct lws_context_per_thread *pt); + +const struct lws_role_ops * +lws_role_by_name(const char *name); + +int +lws_socket_bind(struct lws_vhost *vhost, lws_sockfd_type sockfd, int port, + const char *iface, int ipv6_allowed); + +#if defined(LWS_WITH_IPV6) +unsigned long +lws_get_addr_scope(const char *ipaddr); +#endif + +void +lws_close_free_wsi(struct lws *wsi, enum lws_close_status, const char *caller); +void +__lws_close_free_wsi(struct lws *wsi, enum lws_close_status, const char *caller); + +void +__lws_free_wsi(struct lws *wsi); + +#if LWS_MAX_SMP > 1 + +static LWS_INLINE void +lws_pt_mutex_init(struct lws_context_per_thread *pt) +{ + lws_mutex_refcount_init(&pt->mr); + pthread_mutex_init(&pt->lock_stats, NULL); +} + +static LWS_INLINE void +lws_pt_mutex_destroy(struct lws_context_per_thread *pt) +{ + pthread_mutex_destroy(&pt->lock_stats); + lws_mutex_refcount_destroy(&pt->mr); +} + +#define lws_pt_lock(pt, reason) lws_mutex_refcount_lock(&pt->mr, reason) +#define lws_pt_unlock(pt) lws_mutex_refcount_unlock(&pt->mr) +#define lws_pt_assert_lock_held(pt) lws_mutex_refcount_assert_held(&pt->mr) + +static LWS_INLINE void +lws_pt_stats_lock(struct lws_context_per_thread *pt) +{ + pthread_mutex_lock(&pt->lock_stats); +} + +static LWS_INLINE void +lws_pt_stats_unlock(struct lws_context_per_thread *pt) +{ + pthread_mutex_unlock(&pt->lock_stats); +} +#endif + +/* + * EXTENSIONS + */ + +#if defined(LWS_WITHOUT_EXTENSIONS) +#define lws_any_extension_handled(_a, _b, _c, _d) (0) +#define lws_ext_cb_active(_a, _b, _c, _d) (0) +#define lws_ext_cb_all_exts(_a, _b, _c, _d, _e) (0) +#define lws_issue_raw_ext_access lws_issue_raw +#define lws_context_init_extensions(_a, _b) +#endif + +int LWS_WARN_UNUSED_RESULT +lws_client_interpret_server_handshake(struct lws *wsi); + +int LWS_WARN_UNUSED_RESULT +lws_ws_rx_sm(struct lws *wsi, char already_processed, unsigned char c); + +int LWS_WARN_UNUSED_RESULT +lws_issue_raw_ext_access(struct lws *wsi, unsigned char *buf, size_t len); + +void +lws_role_transition(struct lws *wsi, enum lwsi_role role, enum lwsi_state state, + const struct lws_role_ops *ops); + +int +lws_http_to_fallback(struct lws *wsi, unsigned char *buf, size_t len); + +int LWS_WARN_UNUSED_RESULT +user_callback_handle_rxflow(lws_callback_function, struct lws *wsi, + enum lws_callback_reasons reason, void *user, + void *in, size_t len); + +int +lws_plat_set_nonblocking(lws_sockfd_type fd); + +int +lws_plat_set_socket_options(struct lws_vhost *vhost, lws_sockfd_type fd, + int unix_skt); + +int +lws_plat_check_connection_error(struct lws *wsi); + +int LWS_WARN_UNUSED_RESULT +lws_header_table_attach(struct lws *wsi, int autoservice); + +int +lws_header_table_detach(struct lws *wsi, int autoservice); +int +__lws_header_table_detach(struct lws *wsi, int autoservice); + +void +lws_header_table_reset(struct lws *wsi, int autoservice); + +void +__lws_header_table_reset(struct lws *wsi, int autoservice); + +char * LWS_WARN_UNUSED_RESULT +lws_hdr_simple_ptr(struct lws *wsi, enum lws_token_indexes h); + +int LWS_WARN_UNUSED_RESULT +lws_hdr_simple_create(struct lws *wsi, enum lws_token_indexes h, const char *s); + +int LWS_WARN_UNUSED_RESULT +lws_ensure_user_space(struct lws *wsi); + +int LWS_WARN_UNUSED_RESULT +lws_change_pollfd(struct lws *wsi, int _and, int _or); + +#if defined(LWS_WITH_SERVER) + int _lws_vhost_init_server(const struct lws_context_creation_info *info, + struct lws_vhost *vhost); + LWS_EXTERN struct lws_vhost * + lws_select_vhost(struct lws_context *context, int port, const char *servername); + LWS_EXTERN int LWS_WARN_UNUSED_RESULT + lws_parse_ws(struct lws *wsi, unsigned char **buf, size_t len); + LWS_EXTERN void + lws_server_get_canonical_hostname(struct lws_context *context, + const struct lws_context_creation_info *info); +#else + #define _lws_vhost_init_server(_a, _b) (0) + #define lws_parse_ws(_a, _b, _c) (0) + #define lws_server_get_canonical_hostname(_a, _b) +#endif + +int +__remove_wsi_socket_from_fds(struct lws *wsi); + +enum { + LWSRXFC_ERROR = -1, + LWSRXFC_CACHED = 0, + LWSRXFC_ADDITIONAL = 1, + LWSRXFC_TRIMMED = 2, +}; + + +int +_lws_plat_service_forced_tsi(struct lws_context *context, int tsi); + +int +lws_rxflow_cache(struct lws *wsi, unsigned char *buf, int n, int len); + +int +lws_service_flag_pending(struct lws_context *context, int tsi); + +static LWS_INLINE int +lws_has_buffered_out(struct lws *wsi) { return !!wsi->buflist_out; } + +int LWS_WARN_UNUSED_RESULT +lws_ws_client_rx_sm(struct lws *wsi, unsigned char c); + +lws_parser_return_t LWS_WARN_UNUSED_RESULT +lws_parse(struct lws *wsi, unsigned char *buf, int *len); + +int LWS_WARN_UNUSED_RESULT +lws_parse_urldecode(struct lws *wsi, uint8_t *_c); + +int LWS_WARN_UNUSED_RESULT +lws_http_action(struct lws *wsi); + +void +__lws_close_free_wsi_final(struct lws *wsi); +void +lws_libuv_closehandle(struct lws *wsi); +int +lws_libuv_check_watcher_active(struct lws *wsi); + +#if defined(LWS_WITH_EVLIB_PLUGINS) || defined(LWS_WITH_PLUGINS) +const lws_plugin_header_t * +lws_plat_dlopen(struct lws_plugin **pplugin, const char *libpath, + const char *sofilename, const char *_class, + each_plugin_cb_t each, void *each_user); + +int +lws_plat_destroy_dl(struct lws_plugin *p); +#endif + +struct lws * +lws_adopt_socket_vhost(struct lws_vhost *vh, lws_sockfd_type accept_fd); + +void +lws_vhost_bind_wsi(struct lws_vhost *vh, struct lws *wsi); +void +lws_vhost_unbind_wsi(struct lws *wsi); + +void +__lws_set_timeout(struct lws *wsi, enum pending_timeout reason, int secs); +int +__lws_change_pollfd(struct lws *wsi, int _and, int _or); + + +int +lws_callback_as_writeable(struct lws *wsi); + +int +lws_role_call_client_bind(struct lws *wsi, + const struct lws_client_connect_info *i); +void +lws_remove_child_from_any_parent(struct lws *wsi); + +char * +lws_generate_client_ws_handshake(struct lws *wsi, char *p, const char *conn1); +int +lws_client_ws_upgrade(struct lws *wsi, const char **cce); +int +lws_create_client_ws_object(const struct lws_client_connect_info *i, + struct lws *wsi); +int +lws_alpn_comma_to_openssl(const char *comma, uint8_t *os, int len); +int +lws_role_call_alpn_negotiated(struct lws *wsi, const char *alpn); +int +lws_tls_server_conn_alpn(struct lws *wsi); + +int +lws_ws_client_rx_sm_block(struct lws *wsi, unsigned char **buf, size_t len); +void +lws_destroy_event_pipe(struct lws *wsi); + +/* socks */ +int +lws_socks5c_generate_msg(struct lws *wsi, enum socks_msg_type type, ssize_t *msg_len); + +#if defined(LWS_WITH_SERVER_STATUS) +void +lws_sum_stats(const struct lws_context *ctx, struct lws_conn_stats *cs); +#endif + +#if defined(LWS_WITH_DEPRECATED_THINGS) +int +__lws_timed_callback_remove(struct lws_vhost *vh, struct lws_timed_vh_protocol *p); +#endif + +int LWS_WARN_UNUSED_RESULT +__insert_wsi_socket_into_fds(struct lws_context *context, struct lws *wsi); + +int LWS_WARN_UNUSED_RESULT +lws_issue_raw(struct lws *wsi, unsigned char *buf, size_t len); + +lws_usec_t +__lws_seq_timeout_check(struct lws_context_per_thread *pt, lws_usec_t usnow); + +lws_usec_t +__lws_ss_timeout_check(struct lws_context_per_thread *pt, lws_usec_t usnow); + +struct lws * LWS_WARN_UNUSED_RESULT +lws_client_connect_2_dnsreq(struct lws *wsi); + +LWS_VISIBLE struct lws * LWS_WARN_UNUSED_RESULT +lws_client_reset(struct lws **wsi, int ssl, const char *address, int port, + const char *path, const char *host, char weak); + +struct lws * LWS_WARN_UNUSED_RESULT +lws_create_new_server_wsi(struct lws_vhost *vhost, int fixed_tsi); + +char * LWS_WARN_UNUSED_RESULT +lws_generate_client_handshake(struct lws *wsi, char *pkt); + +int +lws_handle_POLLOUT_event(struct lws *wsi, struct lws_pollfd *pollfd); + +struct lws * +lws_http_client_connect_via_info2(struct lws *wsi); + + +#if defined(LWS_WITH_CLIENT) +int +lws_client_socket_service(struct lws *wsi, struct lws_pollfd *pollfd); + +int LWS_WARN_UNUSED_RESULT +lws_http_transaction_completed_client(struct lws *wsi); +#if !defined(LWS_WITH_TLS) + #define lws_context_init_client_ssl(_a, _b) (0) +#endif +void +lws_decode_ssl_error(void); +#else +#define lws_context_init_client_ssl(_a, _b) (0) +#endif + +int +__lws_rx_flow_control(struct lws *wsi); + +int +_lws_change_pollfd(struct lws *wsi, int _and, int _or, struct lws_pollargs *pa); + +#if defined(LWS_WITH_SERVER) +int +lws_handshake_server(struct lws *wsi, unsigned char **buf, size_t len); +#else +#define lws_server_socket_service(_b, _c) (0) +#define lws_handshake_server(_a, _b, _c) (0) +#endif + +#ifdef LWS_WITH_ACCESS_LOG +int +lws_access_log(struct lws *wsi); +void +lws_prepare_access_log_info(struct lws *wsi, char *uri_ptr, int len, int meth); +#else +#define lws_access_log(_a) +#endif + +#if defined(_DEBUG) +void +lws_wsi_txc_describe(struct lws_tx_credit *txc, const char *at, uint32_t sid); +#else +#define lws_wsi_txc_describe(x, y, z) { (void)x; } +#endif + +int +lws_wsi_txc_check_skint(struct lws_tx_credit *txc, int32_t tx_cr); + +int +lws_wsi_txc_report_manual_txcr_in(struct lws *wsi, int32_t bump); + +void +lws_mux_mark_immortal(struct lws *wsi); +void +lws_http_close_immortal(struct lws *wsi); + +int +lws_cgi_kill_terminated(struct lws_context_per_thread *pt); + +void +lws_cgi_remove_and_kill(struct lws *wsi); + +void +lws_plat_delete_socket_from_fds(struct lws_context *context, + struct lws *wsi, int m); +void +lws_plat_insert_socket_into_fds(struct lws_context *context, + struct lws *wsi); + +int +lws_plat_change_pollfd(struct lws_context *context, struct lws *wsi, + struct lws_pollfd *pfd); + +#if defined(LWS_WITH_SERVER) && defined(LWS_WITH_SECURE_STREAMS) +int +lws_adopt_ss_server_accept(struct lws *new_wsi); +#endif + +int +lws_plat_pipe_create(struct lws *wsi); +int +lws_plat_pipe_signal(struct lws *wsi); +void +lws_plat_pipe_close(struct lws *wsi); + +void +lws_addrinfo_clean(struct lws *wsi); + +void +lws_add_wsi_to_draining_ext_list(struct lws *wsi); +void +lws_remove_wsi_from_draining_ext_list(struct lws *wsi); +int +lws_poll_listen_fd(struct lws_pollfd *fd); +int +lws_plat_service(struct lws_context *context, int timeout_ms); +LWS_VISIBLE int +_lws_plat_service_tsi(struct lws_context *context, int timeout_ms, int tsi); + +int +lws_pthread_self_to_tsi(struct lws_context *context); +const char * LWS_WARN_UNUSED_RESULT +lws_plat_inet_ntop(int af, const void *src, char *dst, int cnt); +int LWS_WARN_UNUSED_RESULT +lws_plat_inet_pton(int af, const char *src, void *dst); + +void +lws_same_vh_protocol_remove(struct lws *wsi); +void +__lws_same_vh_protocol_remove(struct lws *wsi); +void +lws_same_vh_protocol_insert(struct lws *wsi, int n); + +void +lws_seq_destroy_all_on_pt(struct lws_context_per_thread *pt); + +int +lws_broadcast(struct lws_context_per_thread *pt, int reason, void *in, size_t len); + +#if defined(LWS_WITH_STATS) + void + lws_stats_bump(struct lws_context_per_thread *pt, int i, uint64_t bump); + void + lws_stats_max(struct lws_context_per_thread *pt, int index, uint64_t val); +#else + static LWS_INLINE uint64_t lws_stats_bump( + struct lws_context_per_thread *pt, int index, uint64_t bump) { + (void)pt; (void)index; (void)bump; return 0; } + static LWS_INLINE uint64_t lws_stats_max( + struct lws_context_per_thread *pt, int index, uint64_t val) { + (void)pt; (void)index; (void)val; return 0; } +#endif + + + +#if defined(LWS_WITH_PEER_LIMITS) +void +lws_peer_track_wsi_close(struct lws_context *context, struct lws_peer *peer); +int +lws_peer_confirm_ah_attach_ok(struct lws_context *context, + struct lws_peer *peer); +void +lws_peer_track_ah_detach(struct lws_context *context, struct lws_peer *peer); +void +lws_peer_cull_peer_wait_list(struct lws_context *context); +struct lws_peer * +lws_get_or_create_peer(struct lws_vhost *vhost, lws_sockfd_type sockfd); +void +lws_peer_add_wsi(struct lws_context *context, struct lws_peer *peer, + struct lws *wsi); +void +lws_peer_dump_from_wsi(struct lws *wsi); +#endif + +#ifdef LWS_WITH_HUBBUB +hubbub_error +html_parser_cb(const hubbub_token *token, void *pw); +#endif + +int +lws_threadpool_tsi_context(struct lws_context *context, int tsi); + +void +__lws_wsi_remove_from_sul(struct lws *wsi); + +void +lws_validity_confirmed(struct lws *wsi); +void +_lws_validity_confirmed_role(struct lws *wsi); + +int +lws_seq_pt_init(struct lws_context_per_thread *pt); + +int +lws_buflist_aware_read(struct lws_context_per_thread *pt, struct lws *wsi, + struct lws_tokens *ebuf, char fr, const char *hint); +int +lws_buflist_aware_finished_consuming(struct lws *wsi, struct lws_tokens *ebuf, + int used, int buffered, const char *hint); + +extern const struct lws_protocols protocol_abs_client_raw_skt, + protocol_abs_client_unit_test; + +void +__lws_reset_wsi(struct lws *wsi); + +void +lws_inform_client_conn_fail(struct lws *wsi, void *arg, size_t len); + +#if defined(LWS_WITH_SYS_ASYNC_DNS) +lws_async_dns_server_check_t +lws_plat_asyncdns_init(struct lws_context *context, lws_sockaddr46 *sa); +int +lws_async_dns_init(struct lws_context *context); +void +lws_async_dns_deinit(lws_async_dns_t *dns); +#endif + +int +lws_protocol_init_vhost(struct lws_vhost *vh, int *any); +int +_lws_generic_transaction_completed_active_conn(struct lws **wsi, char take_vh_lock); + +#define ACTIVE_CONNS_SOLO 0 +#define ACTIVE_CONNS_MUXED 1 +#define ACTIVE_CONNS_QUEUED 2 +#define ACTIVE_CONNS_FAILED 3 + +#if defined(_DEBUG) && !defined(LWS_PLAT_FREERTOS) && !defined(WIN32) && !defined(LWS_PLAT_OPTEE) + +int +sanity_assert_no_wsi_traces(const struct lws_context *context, struct lws *wsi); +int +sanity_assert_no_sockfd_traces(const struct lws_context *context, + lws_sockfd_type sfd); +#else +static inline int sanity_assert_no_wsi_traces(const struct lws_context *context, struct lws *wsi) { (void)context; (void)wsi; return 0; } +static inline int sanity_assert_no_sockfd_traces(const struct lws_context *context, lws_sockfd_type sfd) { (void)context; (void)sfd; return 0; } +#endif + + +void +delete_from_fdwsi(const struct lws_context *context, struct lws *wsi); + +int +lws_vhost_active_conns(struct lws *wsi, struct lws **nwsi, const char *adsin); + +const char * +lws_wsi_client_stash_item(struct lws *wsi, int stash_idx, int hdr_idx); + +int +lws_plat_BINDTODEVICE(lws_sockfd_type fd, const char *ifname); + +int +lws_socks5c_ads_server(struct lws_vhost *vh, + const struct lws_context_creation_info *info); + +int +lws_socks5c_handle_state(struct lws *wsi, struct lws_pollfd *pollfd, + const char **pcce); + +int +lws_socks5c_greet(struct lws *wsi, const char **pcce); + +int +lws_plat_mbedtls_net_send(void *ctx, const uint8_t *buf, size_t len); + +int +lws_plat_mbedtls_net_recv(void *ctx, unsigned char *buf, size_t len); + +lws_usec_t +lws_sul_nonmonotonic_adjust(struct lws_context *ctx, int64_t step_us); + +void +lws_netdev_instance_remove_destroy(struct lws_netdev_instance *ni); + +#if defined(LWS_WITH_SYS_SMD) +int +lws_netdev_smd_cb(void *opaque, lws_smd_class_t _class, lws_usec_t timestamp, + void *buf, size_t len); +#endif + +void +lws_netdev_instance_create(lws_netdev_instance_t *ni, struct lws_context *ctx, + const lws_netdev_ops_t *ops, const char *name, + void *platinfo); + +int +lws_netdev_wifi_rssi_sort_compare(const lws_dll2_t *d, const lws_dll2_t *i); +void +lws_netdev_wifi_scan_empty(lws_netdev_instance_wifi_t *wnd); + +lws_wifi_sta_t * +lws_netdev_wifi_scan_find(lws_netdev_instance_wifi_t *wnd, const char *ssid, + const uint8_t *bssid); + +int +lws_netdev_wifi_scan_select(lws_netdev_instance_wifi_t *wnd); + +lws_wifi_creds_t * +lws_netdev_credentials_find(lws_netdevs_t *netdevs, const char *ssid, + const uint8_t *bssid); + +int +lws_netdev_wifi_redo_last(lws_netdev_instance_wifi_t *wnd); + +void +lws_ntpc_trigger(struct lws_context *ctx); + +void +lws_netdev_wifi_scan(lws_sorted_usec_list_t *sul); + +#define lws_netdevs_from_ndi(ni) \ + lws_container_of((ni)->list.owner, lws_netdevs_t, owner) + +#define lws_context_from_netdevs(nd) \ + lws_container_of(nd, struct lws_context, netdevs) + +/* get the owner of the ni, then compute the context the owner is embedded in */ +#define netdev_instance_to_ctx(ni) \ + lws_container_of(lws_netdevs_from_ndi(ni), \ + struct lws_context, netdevs) + +enum { + LW5CHS_RET_RET0, + LW5CHS_RET_BAIL3, + LW5CHS_RET_STARTHS, + LW5CHS_RET_NOTHING +}; + +#ifdef __cplusplus +}; +#endif + +#endif diff -Nru libwebsockets-3.2.1/lib/core-net/README.md libwebsockets-4.1.6/lib/core-net/README.md --- libwebsockets-3.2.1/lib/core-net/README.md 1970-01-01 00:00:00.000000000 +0000 +++ libwebsockets-4.1.6/lib/core-net/README.md 2020-12-01 17:40:26.000000000 +0000 @@ -0,0 +1,58 @@ +# Implementation background + +## Client connection Queueing + +By default lws treats each client connection as completely separate, and each is +made from scratch with its own network connection independently. + +If the user code sets the `LCCSCF_PIPELINE` bit on `info.ssl_connection` when +creating the client connection though, lws attempts to optimize multiple client +connections to the same place by sharing any existing connection and its tls +tunnel where possible. + +There are two basic approaches, for h1 additional connections of the same type +and endpoint basically queue on a leader and happen sequentially. + +For muxed protocols like h2, they may also queue if the initial connection is +not up yet, but subsequently the will all join the existing connection +simultaneously "broadside". + +## h1 queueing + +The initial wsi to start the network connection becomes the "leader" that +subsequent connection attempts will queue against. Each vhost has a dll2_owner +`wsi->dll_cli_active_conns_owner` that "leaders" who are actually making network +connections themselves can register on as "active client connections". + +Other client wsi being created who find there is already a leader on the active +client connection list for the vhost, can join their dll2 wsi->dll2_cli_txn_queue +to the leader's wsi->dll2_cli_txn_queue_owner to "queue" on the leader. + +The user code does not know which wsi was first or is queued, it just waits for +stuff to happen the same either way. + +When the "leader" wsi connects, it performs its client transaction as normal, +and at the end arrives at `lws_http_transaction_completed_client()`. Here, it +calls through to the lws_mux `_lws_generic_transaction_completed_active_conn()` +helper. This helper sees if anything else is queued, and if so, migrates assets +like the SSL *, the socket fd, and any remaining queue from the original leader +to the head of the list, which replaces the old leader as the "active client +connection" any subsequent connects would queue on. + +It has to be done this way so that user code which may know each client wsi by +its wsi, or have marked it with an opaque_user_data pointer, is getting its +specific request handled by the wsi it expects it to be handled by. + +A side effect of this, and in order to be able to handle POSTs cleanly, lws +does not attempt to send the headers for the next queued child before the +previous child has finished. + +The process of moving the SSL context and fd etc between the queued wsi continues +until the queue is all handled. + +## muxed protocol queueing and stream binding + +h2 connections act the same as h1 before the initial connection has been made, +but once it is made all the queued connections join the network connection as +child mux streams immediately, "broadside", binding the stream to the existing +network connection. diff -Nru libwebsockets-3.2.1/lib/core-net/sequencer.c libwebsockets-4.1.6/lib/core-net/sequencer.c --- libwebsockets-3.2.1/lib/core-net/sequencer.c 2019-12-18 14:45:31.000000000 +0000 +++ libwebsockets-4.1.6/lib/core-net/sequencer.c 2020-12-01 17:40:26.000000000 +0000 @@ -1,25 +1,28 @@ /* - * libwebsockets - lib/core-net/sequencer.c + * libwebsockets - small server side websockets and web server implementation * - * Copyright (C) 2019 Andy Green + * Copyright (C) 2010 - 2019 Andy Green * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation: - * version 2.1 of the License. + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to + * deal in the Software without restriction, including without limitation the + * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or + * sell copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: * - * This library is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. * - * You should have received a copy of the GNU Lesser General Public - * License along with this library; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, - * MA 02110-1301 USA + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS + * IN THE SOFTWARE. */ -#include "core/private.h" +#include "private-lib-core.h" /* * per pending event @@ -35,7 +38,7 @@ /* * per sequencer */ -struct lws_sequencer { +typedef struct lws_sequencer { struct lws_dll2 seq_list; lws_sorted_usec_list_t sul_timeout; @@ -50,8 +53,9 @@ lws_usec_t time_created; lws_usec_t timeout; /* 0 or time we timeout */ - char going_down; -}; + uint8_t going_down:1; + uint8_t wakesuspend:1; +} lws_seq_t; #define QUEUE_SANITY_LIMIT 10 @@ -74,8 +78,8 @@ /* schedule the next one */ - __lws_sul_insert(&pt->pt_sul_owner, &pt->sul_seq_heartbeat, - LWS_US_PER_SEC); + __lws_sul_insert_us(&pt->pt_sul_owner[LWSSULLI_MISS_IF_SUSPENDED], + &pt->sul_seq_heartbeat, LWS_US_PER_SEC); } int @@ -84,8 +88,8 @@ pt->sul_seq_heartbeat.cb = lws_sul_seq_heartbeat_cb; /* schedule the first heartbeat */ - __lws_sul_insert(&pt->pt_sul_owner, &pt->sul_seq_heartbeat, - LWS_US_PER_SEC); + __lws_sul_insert_us(&pt->pt_sul_owner[LWSSULLI_MISS_IF_SUSPENDED], + &pt->sul_seq_heartbeat, LWS_US_PER_SEC); return 0; } @@ -103,6 +107,7 @@ seq->pt = pt; seq->name = i->name; seq->retry = i->retry; + seq->wakesuspend = i->wakesuspend; *i->puser = (void *)&seq[1]; @@ -239,7 +244,8 @@ lws_dll2_add_tail(&seqe->seq_event_list, &seq->seq_event_owner); seq->sul_pending.cb = lws_seq_sul_pending_cb; - __lws_sul_insert(&seq->pt->pt_sul_owner, &seq->sul_pending, 1); + __lws_sul_insert_us(&seq->pt->pt_sul_owner[seq->wakesuspend], + &seq->sul_pending, 1); lws_pt_unlock(seq->pt); /* } pt ------------------------------------- */ @@ -297,8 +303,10 @@ { seq->sul_timeout.cb = lws_seq_sul_timeout_cb; /* list is always at the very top of the sul */ - return __lws_sul_insert(&seq->pt->pt_sul_owner, + __lws_sul_insert_us(&seq->pt->pt_sul_owner[seq->wakesuspend], (lws_sorted_usec_list_t *)&seq->sul_timeout.list, us); + + return 0; } lws_seq_t * diff -Nru libwebsockets-3.2.1/lib/core-net/server.c libwebsockets-4.1.6/lib/core-net/server.c --- libwebsockets-3.2.1/lib/core-net/server.c 2019-12-18 14:45:31.000000000 +0000 +++ libwebsockets-4.1.6/lib/core-net/server.c 2020-12-01 17:40:26.000000000 +0000 @@ -1,25 +1,28 @@ /* * libwebsockets - small server side websockets and web server implementation * - * Copyright (C) 2010-2019 Andy Green + * Copyright (C) 2010 - 2019 Andy Green * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation: - * version 2.1 of the License. + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to + * deal in the Software without restriction, including without limitation the + * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or + * sell copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: * - * This library is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. * - * You should have received a copy of the GNU Lesser General Public - * License along with this library; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, - * MA 02110-1301 USA + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS + * IN THE SOFTWARE. */ -#include "core/private.h" +#include "private-lib-core.h" #if defined(LWS_WITH_SERVER_STATUS) @@ -45,7 +48,7 @@ } } -LWS_EXTERN int +int lws_json_dump_vhost(const struct lws_vhost *vh, char *buf, int len) { #if defined(LWS_ROLE_H1) || defined(LWS_ROLE_H2) @@ -59,8 +62,8 @@ "callback://" }; #endif - char *orig = buf, *end = buf + len - 1, first = 1; - int n = 0; + char *orig = buf, *end = buf + len - 1, first; + int n; if (len < 100) return 0; @@ -103,6 +106,7 @@ const struct lws_http_mount *m = vh->http.mount_list; buf += lws_snprintf(buf, end - buf, ",\n \"mounts\":["); + first = 1; while (m) { if (!first) buf += lws_snprintf(buf, end - buf, ","); @@ -157,7 +161,7 @@ } -LWS_EXTERN LWS_VISIBLE int +int lws_json_dump_context(const struct lws_context *context, char *buf, int len, int hide_vhosts) { @@ -171,9 +175,9 @@ struct lws_cgi * const *pcgi; #endif -#ifdef LWS_WITH_LIBUV - uv_uptime(&d); -#endif +//#ifdef LWS_WITH_LIBUV && +// uv_uptime(&d); +//#endif buf += lws_snprintf(buf, end - buf, "{ " "\"version\":\"%s\",\n" @@ -182,6 +186,9 @@ (long)d); #ifdef LWS_HAVE_GETLOADAVG +#if defined(__sun) +#include +#endif { double d[3]; int m; @@ -203,7 +210,7 @@ contents[n] = '\0'; if (contents[n - 1] == '\n') contents[--n] = '\0'; - lws_json_purify(pure, contents, sizeof(pure)); + lws_json_purify(pure, contents, sizeof(pure), NULL); buf += lws_snprintf(buf, end - buf, "\"statm\": \"%s\",\n", pure); @@ -221,7 +228,8 @@ "\"ah_pool_max\":\"%d\",\n" "\"deprecated\":\"%d\",\n" "\"wsi_alive\":\"%d\",\n", - (unsigned long long)(lws_now_usecs() - context->time_up), + (unsigned long long)(lws_now_usecs() - context->time_up) / + LWS_US_PER_SEC, context->count_cgi_spawned, context->fd_limit_per_thread, context->max_http_header_pool, diff -Nru libwebsockets-3.2.1/lib/core-net/service.c libwebsockets-4.1.6/lib/core-net/service.c --- libwebsockets-3.2.1/lib/core-net/service.c 2019-12-18 14:45:31.000000000 +0000 +++ libwebsockets-4.1.6/lib/core-net/service.c 2020-12-01 17:40:26.000000000 +0000 @@ -1,30 +1,33 @@ /* * libwebsockets - small server side websockets and web server implementation * - * Copyright (C) 2010-2018 Andy Green + * Copyright (C) 2010 - 2019 Andy Green * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation: - * version 2.1 of the License. + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to + * deal in the Software without restriction, including without limitation the + * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or + * sell copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: * - * This library is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. * - * You should have received a copy of the GNU Lesser General Public - * License along with this library; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, - * MA 02110-1301 USA + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS + * IN THE SOFTWARE. */ -#include "core/private.h" +#include "private-lib-core.h" int lws_callback_as_writeable(struct lws *wsi) { - struct lws_context_per_thread *pt = &wsi->context->pt[(int)wsi->tsi]; + struct lws_context_per_thread *pt = &wsi->a.context->pt[(int)wsi->tsi]; int n, m; lws_stats_bump(pt, LWSSTATS_C_WRITEABLE_CB, 1); @@ -38,17 +41,26 @@ wsi->active_writable_req_us = 0; } #endif - +#if defined(LWS_WITH_DETAILED_LATENCY) + if (wsi->a.context->detailed_latency_cb && lwsi_state_est(wsi)) { + lws_usec_t us = lws_now_usecs(); + + wsi->detlat.earliest_write_req_pre_write = + wsi->detlat.earliest_write_req; + wsi->detlat.earliest_write_req = 0; + wsi->detlat.latencies[LAT_DUR_PROXY_RX_TO_ONWARD_TX] = + ((uint32_t)us - wsi->detlat.earliest_write_req_pre_write); + } +#endif n = wsi->role_ops->writeable_cb[lwsi_role_server(wsi)]; - - m = user_callback_handle_rxflow(wsi->protocol->callback, + m = user_callback_handle_rxflow(wsi->a.protocol->callback, wsi, (enum lws_callback_reasons) n, wsi->user_space, NULL, 0); return m; } -LWS_VISIBLE int +int lws_handle_POLLOUT_event(struct lws *wsi, struct lws_pollfd *pollfd) { volatile struct lws *vwsi = (volatile struct lws *)wsi; @@ -134,11 +146,13 @@ if (!wsi->role_ops->handle_POLLOUT) goto bail_ok; - switch ((wsi->role_ops->handle_POLLOUT)(wsi)) { + n = wsi->role_ops->handle_POLLOUT(wsi); + switch (n) { case LWS_HP_RET_BAIL_OK: goto bail_ok; case LWS_HP_RET_BAIL_DIE: goto bail_die; + case LWS_HP_RET_DROP_POLLOUT: case LWS_HP_RET_USER_SERVICE: break; default: @@ -180,6 +194,9 @@ lwsi_state(wsi) != LRS_ISSUE_HTTP_BODY) goto bail_ok; + if (n == LWS_HP_RET_DROP_POLLOUT) + goto bail_ok; + #ifdef LWS_WITH_CGI user_service_go_again: @@ -191,7 +208,7 @@ else goto bail_ok; } - + lwsl_debug("%s: %p: non mux: wsistate 0x%lx, ops %s\n", __func__, wsi, (unsigned long)wsi->wsistate, wsi->role_ops->name); @@ -228,7 +245,7 @@ int lws_rxflow_cache(struct lws *wsi, unsigned char *buf, int n, int len) { - struct lws_context_per_thread *pt = &wsi->context->pt[(int)wsi->tsi]; + struct lws_context_per_thread *pt = &wsi->a.context->pt[(int)wsi->tsi]; uint8_t *buffered; size_t blen; int ret = LWSRXFC_CACHED, m; @@ -256,13 +273,15 @@ /* a new rxflow, buffer it and warn caller */ + lwsl_debug("%s: rxflow append %d\n", __func__, len - n); m = lws_buflist_append_segment(&wsi->buflist, buf + n, len - n); if (m < 0) return LWSRXFC_ERROR; if (m) { lwsl_debug("%s: added %p to rxflow list\n", __func__, wsi); - lws_dll2_add_head(&wsi->dll_buflist, &pt->dll_buflist_owner); + if (lws_dll2_is_detached(&wsi->dll_buflist)) + lws_dll2_add_head(&wsi->dll_buflist, &pt->dll_buflist_owner); } return ret; @@ -272,10 +291,32 @@ * activity in poll() when we have something that already needs service */ -LWS_VISIBLE LWS_EXTERN int +int lws_service_adjust_timeout(struct lws_context *context, int timeout_ms, int tsi) { - struct lws_context_per_thread *pt = &context->pt[tsi]; + struct lws_context_per_thread *pt; + + if (!context) + return 1; + +#if defined(LWS_WITH_SYS_SMD) + if (!tsi && lws_smd_message_pending(context)) { + lws_smd_msg_distribute(context); + if (lws_smd_message_pending(context)) + return 0; + } +#endif + + pt = &context->pt[tsi]; + +#if defined(LWS_WITH_EXTERNAL_POLL) + { + lws_usec_t u = __lws_sul_service_ripe(pt->pt_sul_owner, + LWS_COUNT_PT_SUL_OWNERS, lws_now_usecs()); + if (u < timeout_ms * 1000) + timeout_ms = u / 1000; + } +#endif /* * Figure out if we really want to wait in poll()... we only need to @@ -327,64 +368,117 @@ */ int lws_buflist_aware_read(struct lws_context_per_thread *pt, struct lws *wsi, - struct lws_tokens *ebuf) + struct lws_tokens *ebuf, char fr, const char *hint) { - int n, prior = (int)lws_buflist_next_segment_len(&wsi->buflist, NULL); + int n, e, bns; + uint8_t *ep, *b; - ebuf->token = pt->serv_buf; - ebuf->len = lws_ssl_capable_read(wsi, pt->serv_buf, - wsi->context->pt_serv_buf_size); + // lwsl_debug("%s: wsi %p: %s: prior %d\n", __func__, wsi, hint, prior); + // lws_buflist_describe(&wsi->buflist, wsi, __func__); - if (ebuf->len == LWS_SSL_CAPABLE_MORE_SERVICE && prior) - goto get_from_buflist; + (void)hint; + if (!ebuf->token) + ebuf->token = pt->serv_buf + LWS_PRE; + if (!ebuf->len || + (unsigned int)ebuf->len > wsi->a.context->pt_serv_buf_size - LWS_PRE) + ebuf->len = wsi->a.context->pt_serv_buf_size - LWS_PRE; - if (ebuf->len <= 0) - return 0; + e = ebuf->len; + ep = ebuf->token; - /* nothing in buflist already? Then just use what we read */ + /* h2 or muxed stream... must force the read due to HOL blocking */ - if (!prior) - return 0; + if (wsi->mux_substream) + fr = 1; + + /* there's something on the buflist? */ + + bns = (int)lws_buflist_next_segment_len(&wsi->buflist, &ebuf->token); + b = ebuf->token; + + if (!fr && bns) + goto buflist_material; + + /* we're going to read something */ + + ebuf->token = ep; + ebuf->len = n = lws_ssl_capable_read(wsi, ep, e); - /* stash what we read */ + lwsl_debug("%s: wsi %p: %s: ssl_capable_read %d\n", __func__, + wsi, hint, ebuf->len); - n = lws_buflist_append_segment(&wsi->buflist, ebuf->token, - ebuf->len); - if (n < 0) + if (!bns && /* only acknowledge error when we handled buflist content */ + n == LWS_SSL_CAPABLE_ERROR) { + lwsl_debug("%s: SSL_CAPABLE_ERROR\n", __func__); return -1; - if (n) { - lwsl_debug("%s: added %p to rxflow list\n", __func__, wsi); - lws_dll2_add_head(&wsi->dll_buflist, &pt->dll_buflist_owner); } - /* get the first buflist guy in line */ + if (n <= 0 && bns) + /* + * There wasn't anything to read yet, but there's something + * on the buflist to give him + */ + goto buflist_material; + + /* we read something */ + + if (fr && bns) { + /* + * Stash what we read, since there's earlier buflist material + */ + + n = lws_buflist_append_segment(&wsi->buflist, ebuf->token, ebuf->len); + if (n < 0) + return -1; + if (n && lws_dll2_is_detached(&wsi->dll_buflist)) + lws_dll2_add_head(&wsi->dll_buflist, + &pt->dll_buflist_owner); + + goto buflist_material; + } + + /* + * directly return what we read + */ + + return 0; -get_from_buflist: +buflist_material: - ebuf->len = (int)lws_buflist_next_segment_len(&wsi->buflist, - &ebuf->token); + ebuf->token = b; + if (e < bns) + /* restrict to e, if more than e available */ + ebuf->len = e; + else + ebuf->len = bns; - return 1; /* came from buflist */ + return 1; /* from buflist */ } int -lws_buflist_aware_consume(struct lws *wsi, struct lws_tokens *ebuf, int used, - int buffered) +lws_buflist_aware_finished_consuming(struct lws *wsi, struct lws_tokens *ebuf, + int used, int buffered, const char *hint) { - struct lws_context_per_thread *pt = &wsi->context->pt[(int)wsi->tsi]; + struct lws_context_per_thread *pt = &wsi->a.context->pt[(int)wsi->tsi]; int m; + //lwsl_debug("%s %s consuming buffered %d used %zu / %zu\n", __func__, hint, + // buffered, (size_t)used, (size_t)ebuf->len); + // lws_buflist_describe(&wsi->buflist, wsi, __func__); + /* it's in the buflist; we didn't use any */ if (!used && buffered) return 0; if (used && buffered) { - m = lws_buflist_use_segment(&wsi->buflist, used); - lwsl_info("%s: draining rxflow: used %d, next %d\n", - __func__, used, m); - if (m) - return 0; + if (wsi->buflist) { + m = (int)lws_buflist_use_segment(&wsi->buflist, (size_t)used); + // lwsl_notice("%s: used %d, next %d\n", __func__, used, m); + // lws_buflist_describe(&wsi->buflist, wsi, __func__); + if (m) + return 0; + } lwsl_info("%s: removed %p from dll_buflist\n", __func__, wsi); lws_dll2_remove(&wsi->dll_buflist); @@ -395,6 +489,8 @@ /* any remainder goes on the buflist */ if (used != ebuf->len) { + // lwsl_notice("%s %s bac appending %d\n", __func__, hint, + // ebuf->len - used); m = lws_buflist_append_segment(&wsi->buflist, ebuf->token + used, ebuf->len - used); @@ -403,9 +499,11 @@ if (m) { lwsl_debug("%s: added %p to rxflow list\n", __func__, wsi); - lws_dll2_add_head(&wsi->dll_buflist, + if (lws_dll2_is_detached(&wsi->dll_buflist)) + lws_dll2_add_head(&wsi->dll_buflist, &pt->dll_buflist_owner); } + // lws_buflist_describe(&wsi->buflist, wsi, __func__); } return 0; @@ -439,11 +537,15 @@ (unsigned long)wsi->wsistate); if (!lws_is_flowcontrolled(wsi) && - lwsi_state(wsi) != LRS_DEFERRING_ACTION && - (wsi->role_ops->handle_POLLIN)(pt, wsi, &pfd) == + lwsi_state(wsi) != LRS_DEFERRING_ACTION) { + pt->inside_lws_service = 1; + + if ((wsi->role_ops->handle_POLLIN)(pt, wsi, &pfd) == LWS_HPI_RET_PLEASE_CLOSE_ME) - lws_close_free_wsi(wsi, LWS_CLOSE_STATUS_NOSTATUS, - "close_and_handled"); + lws_close_free_wsi(wsi, LWS_CLOSE_STATUS_NOSTATUS, + "close_and_handled"); + pt->inside_lws_service = 0; + } } lws_end_foreach_dll_safe(d, d1); @@ -459,9 +561,14 @@ int lws_service_flag_pending(struct lws_context *context, int tsi) { - struct lws_context_per_thread *pt = &context->pt[tsi]; + struct lws_context_per_thread *pt; int forced = 0; + if (!context) + return 1; + + pt = &context->pt[tsi]; + lws_pt_lock(pt, __func__); /* @@ -495,17 +602,19 @@ struct lws *wsi = lws_container_of(p, struct lws, tls.dll_pending_tls); - pt->fds[wsi->position_in_fds_table].revents |= - pt->fds[wsi->position_in_fds_table].events & LWS_POLLIN; - if (pt->fds[wsi->position_in_fds_table].revents & LWS_POLLIN) { - forced = 1; - /* - * he's going to get serviced now, take him off the - * list of guys with buffered SSL. If he still has some - * at the end of the service, he'll get put back on the - * list then. - */ - __lws_ssl_remove_wsi_from_buffered_list(wsi); + if (wsi->position_in_fds_table >= 0) { + + pt->fds[wsi->position_in_fds_table].revents |= + pt->fds[wsi->position_in_fds_table].events & + LWS_POLLIN; + if (pt->fds[wsi->position_in_fds_table].revents & + LWS_POLLIN) + /* + * We're not going to remove the wsi from the + * pending tls list. The processing will have + * to do it if he exhausts the pending tls. + */ + forced = 1; } } lws_end_foreach_dll_safe(p, p1); @@ -516,16 +625,18 @@ return forced; } -LWS_VISIBLE int +int lws_service_fd_tsi(struct lws_context *context, struct lws_pollfd *pollfd, int tsi) { - struct lws_context_per_thread *pt = &context->pt[tsi]; + struct lws_context_per_thread *pt; struct lws *wsi; - if (!context || context->being_destroyed1 ) + if (!context || context->being_destroyed1) return -1; + pt = &context->pt[tsi]; + if (!pollfd) { /* * calling with NULL pollfd for periodic background processing @@ -595,6 +706,7 @@ } #endif wsi->could_have_pending = 0; /* clear back-to-back write detection */ + pt->inside_lws_service = 1; /* okay, what we came here to do... */ @@ -606,10 +718,13 @@ switch ((wsi->role_ops->handle_POLLIN)(pt, wsi, pollfd)) { case LWS_HPI_RET_WSI_ALREADY_DIED: + pt->inside_lws_service = 0; return 1; case LWS_HPI_RET_HANDLED: break; case LWS_HPI_RET_PLEASE_CLOSE_ME: + //lwsl_notice("%s: %s pollin says please close me\n", __func__, + // wsi->role_ops->name); close_and_handled: lwsl_debug("%p: Close and handled\n", wsi); lws_close_free_wsi(wsi, LWS_CLOSE_STATUS_NOSTATUS, @@ -620,7 +735,7 @@ * it waits for libuv service to complete the first async * close */ - if (context->event_loop_ops == &event_loop_ops_uv) + if (!strcmp(context->event_loop_ops->name, "libuv")) lws_close_free_wsi(wsi, LWS_CLOSE_STATUS_NOSTATUS, "close_and_handled uv repeat test"); #endif @@ -630,6 +745,7 @@ * we can't clear revents now because it'd be the wrong guy's * revents */ + pt->inside_lws_service = 0; return 1; default: assert(0); @@ -638,31 +754,27 @@ handled: #endif pollfd->revents = 0; - - if (!context->protocol_init_done) - if (lws_protocol_init(context)) { - lwsl_err("%s: lws_protocol_init failed\n", __func__); - return -1; - } + pt->inside_lws_service = 0; return 0; } -LWS_VISIBLE int +int lws_service_fd(struct lws_context *context, struct lws_pollfd *pollfd) { return lws_service_fd_tsi(context, pollfd, 0); } -LWS_VISIBLE int +int lws_service(struct lws_context *context, int timeout_ms) { - struct lws_context_per_thread *pt = &context->pt[0]; + struct lws_context_per_thread *pt; int n; if (!context) return 1; + pt = &context->pt[0]; pt->inside_service = 1; if (context->event_loop_ops->run_pt) { @@ -680,12 +792,16 @@ return n; } -LWS_VISIBLE int +int lws_service_tsi(struct lws_context *context, int timeout_ms, int tsi) { - struct lws_context_per_thread *pt = &context->pt[tsi]; + struct lws_context_per_thread *pt; int n; + if (!context) + return 1; + + pt = &context->pt[tsi]; pt->inside_service = 1; #if LWS_MAX_SMP > 1 pt->self = pthread_self(); diff -Nru libwebsockets-3.2.1/lib/core-net/socks5-client.c libwebsockets-4.1.6/lib/core-net/socks5-client.c --- libwebsockets-3.2.1/lib/core-net/socks5-client.c 1970-01-01 00:00:00.000000000 +0000 +++ libwebsockets-4.1.6/lib/core-net/socks5-client.c 2020-12-01 17:40:26.000000000 +0000 @@ -0,0 +1,378 @@ +/* + * libwebsockets - small server side websockets and web server implementation + * + * Copyright (C) 2010 - 2020 Andy Green + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to + * deal in the Software without restriction, including without limitation the + * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or + * sell copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS + * IN THE SOFTWARE. + * + * Socks5 Client -related helpers + */ + +#include "private-lib-core.h" + +int +lws_set_socks(struct lws_vhost *vhost, const char *socks) +{ + char *p_at, *p_colon; + char user[96]; + char password[96]; + + if (!socks) + return -1; + + vhost->socks_user[0] = '\0'; + vhost->socks_password[0] = '\0'; + + p_at = strrchr(socks, '@'); + if (p_at) { /* auth is around */ + if ((unsigned int)(p_at - socks) > (sizeof(user) + + sizeof(password) - 2)) { + lwsl_err("Socks auth too long\n"); + goto bail; + } + + p_colon = strchr(socks, ':'); + if (p_colon) { + if ((unsigned int)(p_colon - socks) > (sizeof(user) + - 1) ) { + lwsl_err("Socks user too long\n"); + goto bail; + } + if ((unsigned int)(p_at - p_colon) > (sizeof(password) + - 1) ) { + lwsl_err("Socks password too long\n"); + goto bail; + } + + lws_strncpy(vhost->socks_user, socks, + p_colon - socks + 1); + lws_strncpy(vhost->socks_password, p_colon + 1, + p_at - (p_colon + 1) + 1); + } + + lwsl_info(" Socks auth, user: %s, password: %s\n", + vhost->socks_user, vhost->socks_password ); + + socks = p_at + 1; + } + + lws_strncpy(vhost->socks_proxy_address, socks, + sizeof(vhost->socks_proxy_address)); + + p_colon = strchr(vhost->socks_proxy_address, ':'); + if (!p_colon && !vhost->socks_proxy_port) { + lwsl_err("socks_proxy needs to be address:port\n"); + return -1; + } else { + if (p_colon) { + *p_colon = '\0'; + vhost->socks_proxy_port = atoi(p_colon + 1); + } + } + + lwsl_debug("%s: Connections via Socks5 %s:%u\n", __func__, + vhost->socks_proxy_address, vhost->socks_proxy_port); + + return 0; + +bail: + return -1; +} + +int +lws_socks5c_generate_msg(struct lws *wsi, enum socks_msg_type type, + ssize_t *msg_len) +{ + struct lws_context *context = wsi->a.context; + struct lws_context_per_thread *pt = &context->pt[(int)wsi->tsi]; + uint8_t *p = pt->serv_buf, *end = &p[context->pt_serv_buf_size]; + ssize_t n, passwd_len; + short net_num; + char *cp; + + switch (type) { + case SOCKS_MSG_GREETING: + if (lws_ptr_diff(end, p) < 4) + return 1; + /* socks version, version 5 only */ + *p++ = SOCKS_VERSION_5; + /* number of methods */ + *p++ = 2; + /* username password method */ + *p++ = SOCKS_AUTH_USERNAME_PASSWORD; + /* no authentication method */ + *p++ = SOCKS_AUTH_NO_AUTH; + break; + + case SOCKS_MSG_USERNAME_PASSWORD: + n = strlen(wsi->a.vhost->socks_user); + passwd_len = strlen(wsi->a.vhost->socks_password); + + if (n > 254 || passwd_len > 254) + return 1; + + if (lws_ptr_diff(end, p) < 3 + n + passwd_len) + return 1; + + /* the subnegotiation version */ + *p++ = SOCKS_SUBNEGOTIATION_VERSION_1; + + /* length of the user name */ + *p++ = n; + /* user name */ + memcpy(p, wsi->a.vhost->socks_user, n); + p += n; + + /* length of the password */ + *p++ = passwd_len; + + /* password */ + memcpy(p, wsi->a.vhost->socks_password, passwd_len); + p += passwd_len; + break; + + case SOCKS_MSG_CONNECT: + n = strlen(wsi->stash->cis[CIS_ADDRESS]); + + if (n > 254 || lws_ptr_diff(end, p) < 5 + n + 2) + return 1; + + cp = (char *)&net_num; + + /* socks version */ + *p++ = SOCKS_VERSION_5; + /* socks command */ + *p++ = SOCKS_COMMAND_CONNECT; + /* reserved */ + *p++ = 0; + /* address type */ + *p++ = SOCKS_ATYP_DOMAINNAME; + /* length of ---> */ + *p++ = n; + + /* the address we tell SOCKS proxy to connect to */ + memcpy(p, wsi->stash->cis[CIS_ADDRESS], n); + p += n; + + net_num = htons(wsi->c_port); + + /* the port we tell SOCKS proxy to connect to */ + *p++ = cp[0]; + *p++ = cp[1]; + + break; + + default: + return 1; + } + + *msg_len = lws_ptr_diff(p, pt->serv_buf); + + return 0; +} + +int +lws_socks5c_ads_server(struct lws_vhost *vh, + const struct lws_context_creation_info *info) +{ + /* socks proxy */ + if (info->socks_proxy_address) { + /* override for backwards compatibility */ + if (info->socks_proxy_port) + vh->socks_proxy_port = info->socks_proxy_port; + lws_set_socks(vh, info->socks_proxy_address); + + return 0; + } +#ifdef LWS_HAVE_GETENV + { + char *p = getenv("socks_proxy"); + + if (p && strlen(p) > 0 && strlen(p) < 95) + lws_set_socks(vh, p); + } +#endif + + return 0; +} + +/* + * Returns 0 = nothing for caller to do, 1 = return wsi, -1 = goto failed + */ + +int +lws_socks5c_greet(struct lws *wsi, const char **pcce) +{ + struct lws_context_per_thread *pt = &wsi->a.context->pt[(int)wsi->tsi]; + ssize_t plen; + int n; + + /* socks proxy */ + if (!wsi->a.vhost->socks_proxy_port) + return 0; + + if (lws_socks5c_generate_msg(wsi, SOCKS_MSG_GREETING, &plen)) { + *pcce = "socks msg too large"; + return -1; + } + // lwsl_hexdump_notice(pt->serv_buf, plen); + n = send(wsi->desc.sockfd, (char *)pt->serv_buf, plen, + MSG_NOSIGNAL); + if (n < 0) { + lwsl_debug("ERROR writing socks greeting\n"); + *pcce = "socks write failed"; + return -1; + } + + lws_set_timeout(wsi, PENDING_TIMEOUT_AWAITING_SOCKS_GREETING_REPLY, + wsi->a.context->timeout_secs); + + lwsi_set_state(wsi, LRS_WAITING_SOCKS_GREETING_REPLY); + + return 1; +} + +int +lws_socks5c_handle_state(struct lws *wsi, struct lws_pollfd *pollfd, + const char **pcce) +{ + struct lws_context_per_thread *pt = &wsi->a.context->pt[(int)wsi->tsi]; + int conn_mode = 0, pending_timeout = 0; + ssize_t len; + int n; + + /* handle proxy hung up on us */ + + if (pollfd->revents & LWS_POLLHUP) { + lwsl_warn("SOCKS connection %p (fd=%d) dead\n", + (void *)wsi, pollfd->fd); + *pcce = "socks conn dead"; + return LW5CHS_RET_BAIL3; + } + + n = recv(wsi->desc.sockfd, pt->serv_buf, + wsi->a.context->pt_serv_buf_size, 0); + if (n < 0) { + if (LWS_ERRNO == LWS_EAGAIN) { + lwsl_debug("SOCKS read EAGAIN, retrying\n"); + return LW5CHS_RET_RET0; + } + lwsl_err("ERROR reading from SOCKS socket\n"); + *pcce = "socks recv fail"; + return LW5CHS_RET_BAIL3; + } + + // lwsl_hexdump_warn(pt->serv_buf, n); + + switch (lwsi_state(wsi)) { + + case LRS_WAITING_SOCKS_GREETING_REPLY: + if (pt->serv_buf[0] != SOCKS_VERSION_5) + goto socks_reply_fail; + + if (pt->serv_buf[1] == SOCKS_AUTH_NO_AUTH) { + lwsl_client("SOCKS GR: No Auth Method\n"); + if (lws_socks5c_generate_msg(wsi, SOCKS_MSG_CONNECT, + &len)) { + lwsl_err("%s: failed to generate connect msg\n", + __func__); + goto socks_send_msg_fail; + } + conn_mode = LRS_WAITING_SOCKS_CONNECT_REPLY; + pending_timeout = + PENDING_TIMEOUT_AWAITING_SOCKS_CONNECT_REPLY; + goto socks_send; + } + + if (pt->serv_buf[1] == SOCKS_AUTH_USERNAME_PASSWORD) { + lwsl_client("SOCKS GR: User/Pw Method\n"); + if (lws_socks5c_generate_msg(wsi, + SOCKS_MSG_USERNAME_PASSWORD, + &len)) + goto socks_send_msg_fail; + conn_mode = LRS_WAITING_SOCKS_AUTH_REPLY; + pending_timeout = + PENDING_TIMEOUT_AWAITING_SOCKS_AUTH_REPLY; + goto socks_send; + } + goto socks_reply_fail; + + case LRS_WAITING_SOCKS_AUTH_REPLY: + if (pt->serv_buf[0] != SOCKS_SUBNEGOTIATION_VERSION_1 || + pt->serv_buf[1] != + SOCKS_SUBNEGOTIATION_STATUS_SUCCESS) + goto socks_reply_fail; + + lwsl_client("SOCKS password OK, sending connect\n"); + if (lws_socks5c_generate_msg(wsi, SOCKS_MSG_CONNECT, &len)) { +socks_send_msg_fail: + *pcce = "socks gen msg fail"; + return LW5CHS_RET_BAIL3; + } + conn_mode = LRS_WAITING_SOCKS_CONNECT_REPLY; + pending_timeout = + PENDING_TIMEOUT_AWAITING_SOCKS_CONNECT_REPLY; +socks_send: + // lwsl_hexdump_notice(pt->serv_buf, len); + n = send(wsi->desc.sockfd, (char *)pt->serv_buf, len, + MSG_NOSIGNAL); + if (n < 0) { + lwsl_debug("ERROR writing to socks proxy\n"); + *pcce = "socks write fail"; + return LW5CHS_RET_BAIL3; + } + + lws_set_timeout(wsi, pending_timeout, + wsi->a.context->timeout_secs); + lwsi_set_state(wsi, conn_mode); + break; + +socks_reply_fail: + lwsl_err("%s: socks reply: v%d, err %d\n", __func__, + pt->serv_buf[0], pt->serv_buf[1]); + *pcce = "socks reply fail"; + return LW5CHS_RET_BAIL3; + + case LRS_WAITING_SOCKS_CONNECT_REPLY: + if (pt->serv_buf[0] != SOCKS_VERSION_5 || + pt->serv_buf[1] != SOCKS_REQUEST_REPLY_SUCCESS) + goto socks_reply_fail; + + lwsl_client("%s: socks connect OK\n", __func__); + +#if defined(LWS_ROLE_H1) || defined(LWS_ROLE_H2) + if (lwsi_role_http(wsi) && + lws_hdr_simple_create(wsi, _WSI_TOKEN_CLIENT_PEER_ADDRESS, + wsi->a.vhost->socks_proxy_address)) { + *pcce = "socks connect fail"; + return LW5CHS_RET_BAIL3; + } +#endif + + wsi->c_port = wsi->a.vhost->socks_proxy_port; + + /* clear his proxy connection timeout */ + lws_set_timeout(wsi, NO_PENDING_TIMEOUT, 0); + return LW5CHS_RET_STARTHS; + default: + break; + } + + return LW5CHS_RET_NOTHING; +} diff -Nru libwebsockets-3.2.1/lib/core-net/sorted-usec-list.c libwebsockets-4.1.6/lib/core-net/sorted-usec-list.c --- libwebsockets-3.2.1/lib/core-net/sorted-usec-list.c 2019-12-18 14:45:31.000000000 +0000 +++ libwebsockets-4.1.6/lib/core-net/sorted-usec-list.c 2020-12-01 17:40:26.000000000 +0000 @@ -1,25 +1,28 @@ /* * libwebsockets - small server side websockets and web server implementation * - * Copyright (C) 2010-2019 Andy Green + * Copyright (C) 2010 - 2019 Andy Green * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation: - * version 2.1 of the License. + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to + * deal in the Software without restriction, including without limitation the + * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or + * sell copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: * - * This library is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. * - * You should have received a copy of the GNU Lesser General Public - * License along with this library; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, - * MA 02110-1301 USA + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS + * IN THE SOFTWARE. */ -#include "core/private.h" +#include "private-lib-core.h" static int sul_compare(const lws_dll2_t *d, const lws_dll2_t *i) @@ -40,99 +43,330 @@ return 0; } +/* + * notice owner was chosen already, and sul->us was already computed + */ + int -__lws_sul_insert(lws_dll2_owner_t *own, lws_sorted_usec_list_t *sul, - lws_usec_t us) +__lws_sul_insert(lws_dll2_owner_t *own, lws_sorted_usec_list_t *sul) { - lws_usec_t now = lws_now_usecs(); lws_dll2_remove(&sul->list); - if (us == LWS_SET_TIMER_USEC_CANCEL) { - /* we are clearing the timeout */ - sul->us = 0; - - return 0; - } - - sul->us = now + us; assert(sul->cb); /* * we sort the pt's list of sequencers with pending timeouts, so it's - * cheap to check it every second + * cheap to check it every poll wait */ lws_dll2_add_sorted(&sul->list, own, sul_compare); -#if 0 // defined(_DEBUG) - { - lws_usec_t worst = 0; - int n = 1; - - lwsl_info("%s: own %p: count %d\n", __func__, own, own->count); - - lws_start_foreach_dll_safe(struct lws_dll2 *, p, tp, - lws_dll2_get_head(own)) { - lws_sorted_usec_list_t *sul = (lws_sorted_usec_list_t *)p; - lwsl_info("%s: %d: %llu (+%lld)\n", __func__, n++, - (unsigned long long)sul->us, - (long long)(sul->us - now)); - if (sul->us < worst) { - lwsl_err("%s: wrongly sorted sul entry!\n", - __func__); - assert(0); - } - worst = sul->us; - } lws_end_foreach_dll_safe(p, tp); - } -#endif - return 0; } void -lws_sul_schedule(struct lws_context *context, int tsi, - lws_sorted_usec_list_t *sul, sul_cb_t cb, lws_usec_t us) +lws_sul_cancel(lws_sorted_usec_list_t *sul) +{ + lws_dll2_remove(&sul->list); + + /* we are clearing the timeout and leaving ourselves detached */ + sul->us = 0; +} + +void +lws_sul2_schedule(struct lws_context *context, int tsi, int flags, + lws_sorted_usec_list_t *sul) { struct lws_context_per_thread *pt = &context->pt[tsi]; - sul->cb = cb; + lws_pt_assert_lock_held(pt); - __lws_sul_insert(&pt->pt_sul_owner, sul, us); + __lws_sul_insert( + &pt->pt_sul_owner[!!(flags & LWSSULLI_WAKE_IF_SUSPENDED)], sul); } +/* + * own points to the first in an array of length own_len + * + * While any sul list owner has a "ripe", ie, ready to handle sul we do them + * strictly in order of sul time. When nobody has a ripe sul we return 0, if + * actually nobody has any sul, or the interval between usnow and the next + * earliest scheduled event on any list. + */ + lws_usec_t -__lws_sul_service_ripe(lws_dll2_owner_t *own, lws_usec_t usnow) +__lws_sul_service_ripe(lws_dll2_owner_t *own, int own_len, lws_usec_t usnow) { - while (lws_dll2_get_head(own)) { - /* .list is always first member in lws_sorted_usec_list_t */ - lws_sorted_usec_list_t *sul = (lws_sorted_usec_list_t *) - lws_dll2_get_head(own); - assert(sul->us); /* shouldn't be on the list otherwise */ - if (sul->us > usnow) - /* - * No need to look further if we met one later than now: - * the list is sorted in ascending time order - */ - return sul->us - usnow; - - /* his moment has come... remove him from timeout list */ - - lws_dll2_remove(&sul->list); - sul->us = 0; - sul->cb(sul); - /* - * The callback may have done any mixture of delete - * and add sul entries... eg, close a wsi may pull out - * multiple entries making iterating it statefully - * unsafe. Always restart at the current head of list. - */ - } + struct lws_context_per_thread *pt = (struct lws_context_per_thread *) + lws_container_of(own, struct lws_context_per_thread, + pt_sul_owner); + + if (pt->attach_owner.count) + lws_system_do_attach(pt); + + lws_pt_assert_lock_held(pt); + + /* must be at least 1 */ + assert(own_len > 0); + + /* + * Of the own_len sul owning lists, the earliest next sul could be on + * any of them. We have to find it and handle each in turn until no + * ripe sul left on any owning list, and we can exit. + * + * This ensures the ripe sul are handled strictly in the right order no + * matter which owning list they are on. + */ + + do { + lws_sorted_usec_list_t *hit = NULL; + lws_usec_t lowest = 0; + int n = 0; + + for (n = 0; n < own_len; n++) { + lws_sorted_usec_list_t *sul; + if (!own[n].count) + continue; + sul = (lws_sorted_usec_list_t *) + lws_dll2_get_head(&own[n]); + + if (!hit || sul->us <= lowest) { + hit = sul; + lowest = sul->us; + } + } + + if (!hit) + return 0; + + if (lowest > usnow) + return lowest - usnow; + + /* his moment has come... remove him from his owning list */ + + lws_dll2_remove(&hit->list); + hit->us = 0; + + pt->inside_lws_service = 1; + hit->cb(hit); + pt->inside_lws_service = 0; + + } while (1); + + /* unreachable */ + + return 0; +} + +/* + * Normally we use the OS monotonic time, which does not step when the + * gettimeofday() time is adjusted after, eg, ntpclient. But on some OSes, + * high resolution monotonic time doesn't exist; sul time is computed from and + * compared against gettimeofday() time and breaks when that steps. + * + * For those cases, this allows us to retrospectively adjust existing suls on + * all owning lists by the step amount, at the same time we adjust the + * nonmonotonic clock. Then nothing breaks so long as we do this when the + * gettimeofday() clock is stepped. + * + * Linux and so on offer Posix MONOTONIC, which lws uses. FreeRTOS doesn't + * have a high-resolution monotonic clock and has to use gettimeofday(), which + * requires this adjustment when it is stepped. + */ + +lws_usec_t +lws_sul_nonmonotonic_adjust(struct lws_context *ctx, int64_t step_us) +{ + struct lws_context_per_thread *pt = &ctx->pt[0]; + int n, m; /* - * Nothing left to take care of in the list (cannot return 0 otherwise - * because we will service anything equal to usnow rather than return) + * for each pt */ + for (m = 0; m < ctx->count_threads; m++) { + + /* + * For each owning list... + */ + + lws_pt_lock(pt, __func__); + + for (n = 0; n < LWS_COUNT_PT_SUL_OWNERS; n++) { + + if (!pt->pt_sul_owner[n].count) + continue; + + /* ... and for every existing sul on a list... */ + + lws_start_foreach_dll(struct lws_dll2 *, p, + lws_dll2_get_head( + &pt->pt_sul_owner[n])) { + lws_sorted_usec_list_t *sul = lws_container_of( + p, lws_sorted_usec_list_t, list); + + /* + * ... retrospectively step its ripe time by the + * step we will adjust the gettimeofday() clock + * with + */ + + sul->us += step_us; + + } lws_end_foreach_dll(p); + } + + lws_pt_unlock(pt); + + pt++; + } + return 0; } + +/* + * Earliest wakeable event on any pt + */ + +int +lws_sul_earliest_wakeable_event(struct lws_context *ctx, lws_usec_t *pearliest) +{ + struct lws_context_per_thread *pt; + int n = 0, hit = -1; + lws_usec_t lowest = 0; + + for (n = 0; n < ctx->count_threads; n++) { + pt = &ctx->pt[n]; + + lws_pt_lock(pt, __func__); + + if (pt->pt_sul_owner[LWSSULLI_WAKE_IF_SUSPENDED].count) { + lws_sorted_usec_list_t *sul = (lws_sorted_usec_list_t *) + lws_dll2_get_head(&pt->pt_sul_owner[ + LWSSULLI_WAKE_IF_SUSPENDED]); + + if (hit == -1 || sul->us < lowest) { + hit = n; + lowest = sul->us; + } + } + + lws_pt_unlock(pt); + } + + + if (hit == -1) + /* there is no pending event */ + return 1; + + *pearliest = lowest; + + return 0; +} + +void +lws_sul_schedule(struct lws_context *ctx, int tsi, lws_sorted_usec_list_t *sul, + sul_cb_t _cb, lws_usec_t _us) +{ + struct lws_context_per_thread *_pt = &ctx->pt[tsi]; + + lws_pt_lock(_pt, __func__); + + if (_us == (lws_usec_t)LWS_SET_TIMER_USEC_CANCEL) + lws_sul_cancel(sul); + else { + sul->cb = _cb; + sul->us = lws_now_usecs() + _us; + lws_sul2_schedule(ctx, tsi, LWSSULLI_MISS_IF_SUSPENDED, sul); + } + + lws_pt_unlock(_pt); +} + +void +lws_sul_schedule_wakesuspend(struct lws_context *ctx, int tsi, + lws_sorted_usec_list_t *sul, sul_cb_t _cb, + lws_usec_t _us) +{ + struct lws_context_per_thread *_pt = &ctx->pt[tsi]; + + lws_pt_lock(_pt, __func__); + + if (_us == (lws_usec_t)LWS_SET_TIMER_USEC_CANCEL) + lws_sul_cancel(sul); + else { + sul->cb = _cb; + sul->us = lws_now_usecs() + _us; + lws_sul2_schedule(ctx, tsi, LWSSULLI_WAKE_IF_SUSPENDED, sul); + } + + lws_pt_unlock(_pt); +} + +#if defined(LWS_WITH_SUL_DEBUGGING) + +/* + * Sanity checker for any sul left scheduled when its containing object is + * freed... code scheduling suls must take care to cancel them when destroying + * their object. This optional debugging helper checks that when an object is + * being destroyed, there is no live sul scheduled from inside the object. + */ + +void +lws_sul_debug_zombies(struct lws_context *ctx, void *po, size_t len, + const char *destroy_description) +{ + struct lws_context_per_thread *pt; + int n, m; + + for (n = 0; n < ctx->count_threads; n++) { + pt = &ctx->pt[n]; + + lws_pt_lock(pt, __func__); + + for (m = 0; m < LWS_COUNT_PT_SUL_OWNERS; m++) { + + lws_start_foreach_dll(struct lws_dll2 *, p, + lws_dll2_get_head(&pt->pt_sul_owner[m])) { + lws_sorted_usec_list_t *sul = + lws_container_of(p, + lws_sorted_usec_list_t, list); + + /* + * Is the sul resident inside the object that is + * indicated as being deleted? + */ + + if ((void *)sul >= po && + (size_t)lws_ptr_diff(sul, po) < len) { + lwsl_err("%s: ERROR: Zombie Sul " + "(on list %d) %s, cb %p\n", + __func__, m, + destroy_description, sul->cb); + /* + * This assert fires if you have left + * a sul scheduled to fire later, but + * are about to destroy the object the + * sul lives in. You must take care to + * do lws_sul_cancel(&sul) on any suls + * that may be scheduled before + * destroying the object the sul lives + * inside. + * + * You can look up the cb pointer in + * your mapfile to find out which + * callback function the sul was using + * which usually tells you which sul + * it is. + */ + assert(0); + } + + } lws_end_foreach_dll(p); + } + + lws_pt_unlock(pt); + } +} + +#endif diff -Nru libwebsockets-3.2.1/lib/core-net/state.c libwebsockets-4.1.6/lib/core-net/state.c --- libwebsockets-3.2.1/lib/core-net/state.c 1970-01-01 00:00:00.000000000 +0000 +++ libwebsockets-4.1.6/lib/core-net/state.c 2020-12-01 17:40:26.000000000 +0000 @@ -0,0 +1,152 @@ +/* + * libwebsockets - small server side websockets and web server implementation + * + * Copyright (C) 2010 - 2020 Andy Green + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to + * deal in the Software without restriction, including without limitation the + * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or + * sell copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS + * IN THE SOFTWARE. + */ + +#include "private-lib-core.h" + +void +lws_state_reg_notifier(lws_state_manager_t *mgr, + lws_state_notify_link_t *notify_link) +{ + lws_dll2_add_head(¬ify_link->list, &mgr->notify_list); +} + +void +lws_state_reg_deregister(lws_state_notify_link_t *nl) +{ + lws_dll2_remove(&nl->list); +} + +void +lws_state_reg_notifier_list(lws_state_manager_t *mgr, + lws_state_notify_link_t * const *notify_link_array) +{ + if (notify_link_array) + while (*notify_link_array) + lws_state_reg_notifier(mgr, *notify_link_array++); +} + +#if (_LWS_ENABLED_LOGS & (LLL_INFO | LLL_DEBUG)) +static const char * +_systnm(lws_state_manager_t *mgr, int state, char *temp8) +{ + if (!mgr->state_names) { + lws_snprintf(temp8, 8, "%d", state); + return temp8; + } + + return mgr->state_names[state]; +} +#endif + +static int +_report(lws_state_manager_t *mgr, int a, int b) +{ +#if (_LWS_ENABLED_LOGS & LLL_INFO) + char temp8[8]; +#endif + + lws_start_foreach_dll(struct lws_dll2 *, d, mgr->notify_list.head) { + lws_state_notify_link_t *l = + lws_container_of(d, lws_state_notify_link_t, list); + + if (l->notify_cb(mgr, l, a, b)) { + /* a dependency took responsibility for retry */ + +#if (_LWS_ENABLED_LOGS & LLL_INFO) + lwsl_info("%s: %s: %s: rejected '%s' -> '%s'\n", + __func__, mgr->name, l->name, + _systnm(mgr, a, temp8), + _systnm(mgr, b, temp8)); +#endif + + return 1; + } + + } lws_end_foreach_dll(d); + + return 0; +} + +static int +_lws_state_transition(lws_state_manager_t *mgr, int target) +{ +#if (_LWS_ENABLED_LOGS & LLL_DEBUG) + char temp8[8]; +#endif + + if (_report(mgr, mgr->state, target)) + return 1; + +#if (_LWS_ENABLED_LOGS & LLL_DEBUG) + lwsl_debug("%s: %s: changed %d '%s' -> %d '%s'\n", __func__, mgr->name, + mgr->state, _systnm(mgr, mgr->state, temp8), target, + _systnm(mgr, target, temp8)); +#endif + + mgr->state = target; + + /* Indicate success by calling the notifers again with both args same */ + _report(mgr, target, target); + +#if defined(LWS_WITH_SYS_SMD) + if (mgr->smd_class) + (void)lws_smd_msg_printf(mgr->context, + mgr->smd_class, "{\"state\":\"%s\"}", + mgr->state_names[target]); +#endif + + return 0; +} + +int +lws_state_transition_steps(lws_state_manager_t *mgr, int target) +{ + int n = 0; +#if (_LWS_ENABLED_LOGS & LLL_INFO) + int i = mgr->state; + char temp8[8]; +#endif + + if (mgr->state > target) + return 0; + + while (!n && mgr->state != target) + n = _lws_state_transition(mgr, mgr->state + 1); + +#if (_LWS_ENABLED_LOGS & LLL_INFO) + lwsl_info("%s: %s -> %s\n", __func__, _systnm(mgr, i, temp8), + _systnm(mgr, mgr->state, temp8)); +#endif + + return 0; +} + +int +lws_state_transition(lws_state_manager_t *mgr, int target) +{ + if (mgr->state != target) + _lws_state_transition(mgr, target); + + return 0; +} diff -Nru libwebsockets-3.2.1/lib/core-net/stats.c libwebsockets-4.1.6/lib/core-net/stats.c --- libwebsockets-3.2.1/lib/core-net/stats.c 2019-12-18 14:45:31.000000000 +0000 +++ libwebsockets-4.1.6/lib/core-net/stats.c 2020-12-01 17:40:26.000000000 +0000 @@ -1,30 +1,32 @@ /* * libwebsockets - small server side websockets and web server implementation * - * Copyright (C) 2010-2019 Andy Green + * Copyright (C) 2010 - 2019 Andy Green * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation: - * version 2.1 of the License. + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to + * deal in the Software without restriction, including without limitation the + * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or + * sell copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: * - * This library is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. * - * You should have received a copy of the GNU Lesser General Public - * License along with this library; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, - * MA 02110-1301 USA + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS + * IN THE SOFTWARE. */ -#include "core/private.h" - +#include "private-lib-core.h" #if defined(LWS_WITH_STATS) -LWS_VISIBLE LWS_EXTERN uint64_t +uint64_t lws_stats_get(struct lws_context *context, int index) { struct lws_context_per_thread *pt = &context->pt[0]; @@ -111,7 +113,7 @@ } -LWS_VISIBLE LWS_EXTERN void +void lws_stats_log_dump(struct lws_context *context) { struct lws_vhost *v = context->vhost_list; @@ -157,8 +159,6 @@ lwsl_notice("Live wsi: %8d\n", context->count_wsi_allocated); - context->updated = 1; - while (v) { if (v->lserv_wsi && v->lserv_wsi->position_in_fds_table != LWS_NO_FDS_POS) { diff -Nru libwebsockets-3.2.1/lib/core-net/vhost.c libwebsockets-4.1.6/lib/core-net/vhost.c --- libwebsockets-3.2.1/lib/core-net/vhost.c 2019-12-18 14:45:31.000000000 +0000 +++ libwebsockets-4.1.6/lib/core-net/vhost.c 2020-12-01 17:40:26.000000000 +0000 @@ -1,25 +1,28 @@ /* * libwebsockets - small server side websockets and web server implementation * - * Copyright (C) 2010-2019 Andy Green + * Copyright (C) 2010 - 2019 Andy Green * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation: - * version 2.1 of the License. + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to + * deal in the Software without restriction, including without limitation the + * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or + * sell copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: * - * This library is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. * - * You should have received a copy of the GNU Lesser General Public - * License along with this library; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, - * MA 02110-1301 USA + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS + * IN THE SOFTWARE. */ -#include "core/private.h" +#include "private-lib-core.h" const struct lws_role_ops *available_roles[] = { #if defined(LWS_ROLE_H2) @@ -37,21 +40,8 @@ #if defined(LWS_ROLE_RAW_PROXY) &role_ops_raw_proxy, #endif - NULL -}; - -const struct lws_event_loop_ops *available_event_libs[] = { -#if defined(LWS_WITH_POLL) - &event_loop_ops_poll, -#endif -#if defined(LWS_WITH_LIBUV) - &event_loop_ops_uv, -#endif -#if defined(LWS_WITH_LIBEVENT) - &event_loop_ops_event, -#endif -#if defined(LWS_WITH_LIBEV) - &event_loop_ops_ev, +#if defined(LWS_ROLE_MQTT) && defined(LWS_WITH_CLIENT) + &role_ops_mqtt, #endif NULL }; @@ -65,6 +55,25 @@ }; #endif +#if defined(LWS_WITH_SECURE_STREAMS) +const struct lws_protocols *available_secstream_protocols[] = { +#if defined(LWS_ROLE_H1) + &protocol_secstream_h1, +#endif +#if defined(LWS_ROLE_H2) + &protocol_secstream_h2, +#endif +#if defined(LWS_ROLE_WS) + &protocol_secstream_ws, +#endif +#if defined(LWS_ROLE_MQTT) + &protocol_secstream_mqtt, +#endif + &protocol_secstream_raw, + NULL +}; +#endif + static const char * const mount_protocols[] = { "http://", "https://", @@ -86,8 +95,10 @@ if (!strcmp(name, role_ops_raw_skt.name)) return &role_ops_raw_skt; +#if defined(LWS_ROLE_RAW_FILE) if (!strcmp(name, role_ops_raw_file.name)) return &role_ops_raw_file; +#endif return NULL; } @@ -99,7 +110,9 @@ if (!alpn) return 0; +#if !defined(LWS_ESP_PLATFORM) lwsl_info("%s: '%s'\n", __func__, alpn); +#endif LWS_FOR_EVERY_AVAILABLE_ROLE_START(ar) if (ar->alpn && !strcmp(ar->alpn, alpn) && ar->alpn_negotiated) @@ -109,7 +122,6 @@ return 0; } -//#if !defined(LWS_WITHOUT_SERVER) int lws_role_call_adoption_bind(struct lws *wsi, int type, const char *prot) { @@ -119,18 +131,18 @@ * if the vhost is told to bind accepted sockets to a given role, * then look it up by name and try to bind to the specific role. */ - if (lws_check_opt(wsi->vhost->options, + if (lws_check_opt(wsi->a.vhost->options, LWS_SERVER_OPTION_ADOPT_APPLY_LISTEN_ACCEPT_CONFIG) && - wsi->vhost->listen_accept_role) { + wsi->a.vhost->listen_accept_role) { const struct lws_role_ops *role = - lws_role_by_name(wsi->vhost->listen_accept_role); + lws_role_by_name(wsi->a.vhost->listen_accept_role); if (!prot) - prot = wsi->vhost->listen_accept_protocol; + prot = wsi->a.vhost->listen_accept_protocol; if (!role) lwsl_err("%s: can't find role '%s'\n", __func__, - wsi->vhost->listen_accept_role); + wsi->a.vhost->listen_accept_role); if (role && role->adoption_bind) { n = role->adoption_bind(wsi, type, prot); @@ -149,7 +161,7 @@ lwsl_warn("%s: adoption bind to role '%s', " "protocol '%s', type 0x%x, failed\n", __func__, - wsi->vhost->listen_accept_role, prot, type); + wsi->a.vhost->listen_accept_role, prot, type); } /* @@ -168,17 +180,19 @@ role_ops_raw_skt.adoption_bind(wsi, type, prot)) return 0; +#if defined(LWS_ROLE_RAW_FILE) + /* fall back to raw file role if, eg, h1 not configured */ if (role_ops_raw_file.adoption_bind && role_ops_raw_file.adoption_bind(wsi, type, prot)) return 0; +#endif return 1; } -//#endif -#if !defined(LWS_WITHOUT_CLIENT) +#if defined(LWS_WITH_CLIENT) int lws_role_call_client_bind(struct lws *wsi, const struct lws_client_connect_info *i) @@ -203,7 +217,7 @@ } #endif -LWS_VISIBLE void * +void * lws_protocol_vh_priv_zalloc(struct lws_vhost *vhost, const struct lws_protocols *prot, int size) { @@ -235,7 +249,7 @@ return vhost->protocol_vh_privs[n]; } -LWS_VISIBLE void * +void * lws_protocol_vh_priv_get(struct lws_vhost *vhost, const struct lws_protocols *prot) { @@ -279,107 +293,118 @@ return NULL; } +int +lws_protocol_init_vhost(struct lws_vhost *vh, int *any) +{ + const struct lws_protocol_vhost_options *pvo, *pvo1; + lws_fakewsi_def_plwsa(&vh->context->pt[0]); + int n; + + lws_fakewsi_prep_plwsa_ctx(vh->context); + + plwsa->vhost = vh; + + /* initialize supported protocols on this vhost */ + + for (n = 0; n < vh->count_protocols; n++) { + plwsa->protocol = &vh->protocols[n]; + if (!vh->protocols[n].name) + continue; + pvo = lws_vhost_protocol_options(vh, vh->protocols[n].name); + if (pvo) { + /* + * linked list of options specific to + * vh + protocol + */ + pvo1 = pvo; + pvo = pvo1->options; + + while (pvo) { + lwsl_debug( + " vhost \"%s\", " + "protocol \"%s\", " + "option \"%s\"\n", + vh->name, + vh->protocols[n].name, + pvo->name); + + if (!strcmp(pvo->name, "default")) { + lwsl_info("Setting default " + "protocol for vh %s to %s\n", + vh->name, + vh->protocols[n].name); + vh->default_protocol_index = n; + } + if (!strcmp(pvo->name, "raw")) { + lwsl_info("Setting raw " + "protocol for vh %s to %s\n", + vh->name, + vh->protocols[n].name); + vh->raw_protocol_index = n; + } + pvo = pvo->next; + } + + pvo = pvo1->options; + } + +#if defined(LWS_WITH_TLS) + if (any) + *any |= !!vh->tls.ssl_ctx; +#endif + + /* + * inform all the protocols that they are doing their + * one-time initialization if they want to. + * + * NOTE the fakewsi is garbage, except the key pointers that are + * prepared in case the protocol handler wants to touch them + */ + if (vh->protocols[n].callback((struct lws *)plwsa, + LWS_CALLBACK_PROTOCOL_INIT, NULL, + (void *)pvo, 0)) { + if (vh->protocol_vh_privs[n]) { + lws_free(vh->protocol_vh_privs[n]); + vh->protocol_vh_privs[n] = NULL; + } + lwsl_err("%s: protocol %s failed init\n", + __func__, vh->protocols[n].name); + + return 1; + } + } + + vh->created_vhost_protocols = 1; + + return 0; +} + /* * inform every vhost that hasn't already done it, that * his protocols are initializing */ -LWS_VISIBLE int +int lws_protocol_init(struct lws_context *context) { struct lws_vhost *vh = context->vhost_list; - const struct lws_protocol_vhost_options *pvo, *pvo1; - struct lws wsi; - int n, any = 0; + int any = 0; if (context->doing_protocol_init) return 0; context->doing_protocol_init = 1; - memset(&wsi, 0, sizeof(wsi)); - wsi.context = context; - lwsl_info("%s\n", __func__); while (vh) { - wsi.vhost = vh; /* only do the protocol init once for a given vhost */ if (vh->created_vhost_protocols || - (vh->options & LWS_SERVER_OPTION_SKIP_PROTOCOL_INIT)) + (lws_check_opt(vh->options, LWS_SERVER_OPTION_SKIP_PROTOCOL_INIT))) goto next; - /* initialize supported protocols on this vhost */ - - for (n = 0; n < vh->count_protocols; n++) { - wsi.protocol = &vh->protocols[n]; - if (!vh->protocols[n].name) - continue; - pvo = lws_vhost_protocol_options(vh, - vh->protocols[n].name); - if (pvo) { - /* - * linked list of options specific to - * vh + protocol - */ - pvo1 = pvo; - pvo = pvo1->options; - - while (pvo) { - lwsl_debug( - " vhost \"%s\", " - "protocol \"%s\", " - "option \"%s\"\n", - vh->name, - vh->protocols[n].name, - pvo->name); - - if (!strcmp(pvo->name, "default")) { - lwsl_info("Setting default " - "protocol for vh %s to %s\n", - vh->name, - vh->protocols[n].name); - vh->default_protocol_index = n; - } - if (!strcmp(pvo->name, "raw")) { - lwsl_info("Setting raw " - "protocol for vh %s to %s\n", - vh->name, - vh->protocols[n].name); - vh->raw_protocol_index = n; - } - pvo = pvo->next; - } - - pvo = pvo1->options; - } - -#if defined(LWS_WITH_TLS) - any |= !!vh->tls.ssl_ctx; -#endif - - /* - * inform all the protocols that they are doing their - * one-time initialization if they want to. - * - * NOTE the wsi is all zeros except for the context, vh - * + protocol ptrs so lws_get_context(wsi) etc can work - */ - if (vh->protocols[n].callback(&wsi, - LWS_CALLBACK_PROTOCOL_INIT, NULL, - (void *)pvo, 0)) { - if (vh->protocol_vh_privs[n]) { - lws_free(vh->protocol_vh_privs[n]); - vh->protocol_vh_privs[n] = NULL; - } - lwsl_err("%s: protocol %s failed init\n", - __func__, vh->protocols[n].name); - - return 1; - } - } - - vh->created_vhost_protocols = 1; + if (lws_protocol_init_vhost(vh, &any)) + return 1; next: vh = vh->vhost_next; } @@ -391,8 +416,11 @@ context->protocol_init_done = 1; - if (any) +#if defined(LWS_WITH_SERVER) + if (any) { lws_tls_check_all_cert_lifetimes(context); + } +#endif return 0; } @@ -423,28 +451,41 @@ #undef LWS_HAVE_GETENV #endif -LWS_VISIBLE struct lws_vhost * +struct lws_vhost * lws_create_vhost(struct lws_context *context, const struct lws_context_creation_info *info) { - struct lws_vhost *vh = lws_zalloc(sizeof(*vh), "create vhost"), - **vh1 = &context->vhost_list; + struct lws_vhost *vh, **vh1 = &context->vhost_list; const struct lws_http_mount *mounts; const struct lws_protocols *pcols = info->protocols; #ifdef LWS_WITH_PLUGINS struct lws_plugin *plugin = context->plugin_list; #endif struct lws_protocols *lwsp; - int m, f = !info->pvo, fx = 0, abs_pcol_count = 0; + int m, f = !info->pvo, fx = 0, abs_pcol_count = 0, sec_pcol_count = 0; char buf[96]; -#if !defined(LWS_WITHOUT_CLIENT) && defined(LWS_HAVE_GETENV) +#if defined(LWS_CLIENT_HTTP_PROXYING) && defined(LWS_WITH_CLIENT) \ + && defined(LWS_HAVE_GETENV) char *p; #endif +#if defined(LWS_WITH_SYS_ASYNC_DNS) + extern struct lws_protocols lws_async_dns_protocol; +#endif int n; + + vh = lws_zalloc(sizeof(*vh) +#if defined(LWS_WITH_EVENT_LIBS) + + context->event_loop_ops->evlib_size_vh +#endif + , __func__); if (!vh) return NULL; +#if defined(LWS_WITH_EVENT_LIBS) + vh->evlib_vh = (void *)&vh[1]; +#endif + #if LWS_MAX_SMP > 1 pthread_mutex_init(&vh->lock, NULL); #endif @@ -462,14 +503,25 @@ vh->http.error_document_404 = info->error_document_404; #endif - if (info->options & LWS_SERVER_OPTION_ONLY_RAW) + if (lws_check_opt(info->options, LWS_SERVER_OPTION_ONLY_RAW)) lwsl_info("%s set to only support RAW\n", vh->name); vh->iface = info->iface; -#if !defined(LWS_WITH_ESP32) && \ - !defined(OPTEE_TA) && !defined(WIN32) +#if !defined(LWS_PLAT_FREERTOS) && !defined(OPTEE_TA) && !defined(WIN32) vh->bind_iface = info->bind_iface; #endif +#if defined(LWS_WITH_CLIENT) + if (info->connect_timeout_secs) + vh->connect_timeout_secs = info->connect_timeout_secs; + else + vh->connect_timeout_secs = 20; +#endif + /* apply the context default lws_retry */ + + if (info->retry_and_idle_policy) + vh->retry_policy = info->retry_and_idle_policy; + else + vh->retry_policy = &context->default_retry; /* * let's figure out how many protocols the user is handing us, using the @@ -551,17 +603,21 @@ #if defined(LWS_WITH_ABSTRACT) abs_pcol_count = (int)LWS_ARRAY_SIZE(available_abstract_protocols) - 1; #endif +#if defined(LWS_WITH_SECURE_STREAMS) + sec_pcol_count = (int)LWS_ARRAY_SIZE(available_secstream_protocols) - 1; +#endif /* * give the vhost a unified list of protocols including: * + * - internal, async_dns if enabled (first vhost only) * - internal, abstracted ones * - the ones that came from plugins * - his user protocols */ lwsp = lws_zalloc(sizeof(struct lws_protocols) * (vh->count_protocols + - abs_pcol_count + + abs_pcol_count + sec_pcol_count + context->plugin_protocol_count + fx + 1), "vhost-specific plugin table"); @@ -591,6 +647,24 @@ vh->count_protocols++; } #endif + /* + * 3: async dns protocol (first vhost only) + */ +#if defined(LWS_WITH_SYS_ASYNC_DNS) + if (!context->vhost_list) { + memcpy(&lwsp[m++], &lws_async_dns_protocol, + sizeof(struct lws_protocols)); + vh->count_protocols++; + } +#endif + +#if defined(LWS_WITH_SECURE_STREAMS) + for (n = 0; n < sec_pcol_count; n++) { + memcpy(&lwsp[m++], available_secstream_protocols[n], + sizeof(*lwsp)); + vh->count_protocols++; + } +#endif /* * 3: For compatibility, all protocols enabled on vhost if only @@ -604,15 +678,18 @@ #ifdef LWS_WITH_PLUGINS if (plugin) { while (plugin) { - for (n = 0; n < plugin->caps.count_protocols; n++) { + const lws_plugin_protocol_t *plpr = + (const lws_plugin_protocol_t *)plugin->hdr; + + for (n = 0; n < plpr->count_protocols; n++) { /* * for compatibility's sake, no pvo implies * allow all protocols */ if (f || lws_vhost_protocol_options(vh, - plugin->caps.protocols[n].name)) { + plpr->protocols[n].name)) { memcpy(&lwsp[m], - &plugin->caps.protocols[n], + &plpr->protocols[n], sizeof(struct lws_protocols)); m++; vh->count_protocols++; @@ -671,18 +748,17 @@ } vh->listen_port = info->port; -#if defined(LWS_ROLE_H1) || defined(LWS_ROLE_H2) - vh->http.http_proxy_port = 0; - vh->http.http_proxy_address[0] = '\0'; -#endif + #if defined(LWS_WITH_SOCKS5) vh->socks_proxy_port = 0; vh->socks_proxy_address[0] = '\0'; #endif -#if !defined(LWS_WITHOUT_CLIENT) +#if defined(LWS_WITH_CLIENT) && defined(LWS_CLIENT_HTTP_PROXYING) /* either use proxy from info, or try get it from env var */ #if defined(LWS_ROLE_H1) || defined(LWS_ROLE_H2) + vh->http.http_proxy_port = 0; + vh->http.http_proxy_address[0] = '\0'; /* http proxy */ if (info->http_proxy_address) { /* override for backwards compatibility */ @@ -693,29 +769,20 @@ #endif { #ifdef LWS_HAVE_GETENV - p = getenv("http_proxy"); +#if defined(__COVERITY__) + p = NULL; +#else + p = getenv("http_proxy"); /* coverity[tainted_scalar] */ if (p) { lws_strncpy(buf, p, sizeof(buf)); - lws_set_proxy(vh, buf); } #endif +#endif } #endif #if defined(LWS_WITH_SOCKS5) - /* socks proxy */ - if (info->socks_proxy_address) { - /* override for backwards compatibility */ - if (info->socks_proxy_port) - vh->socks_proxy_port = info->socks_proxy_port; - lws_set_socks(vh, info->socks_proxy_address); - } else { -#ifdef LWS_HAVE_GETENV - p = getenv("socks_proxy"); - if (p && strlen(p) > 0 && strlen(p) < 95) - lws_set_socks(vh, p); -#endif - } + lws_socks5c_ads_server(vh, info); #endif vh->ka_time = info->ka_time; @@ -752,6 +819,7 @@ lwsl_err("%s: lws_context_init_client_ssl failed\n", __func__); goto bail1; } +#if defined(LWS_WITH_SERVER) lws_context_lock(context, "create_vhost"); n = _lws_vhost_init_server(info, vh); lws_context_unlock(context); @@ -759,6 +827,11 @@ lwsl_err("init server failed\n"); goto bail1; } +#endif + +#if defined(LWS_WITH_SYS_ASYNC_DNS) + n = !!context->vhost_list; +#endif while (1) { if (!(*vh1)) { @@ -768,6 +841,11 @@ vh1 = &(*vh1)->vhost_next; }; +#if defined(LWS_WITH_SYS_ASYNC_DNS) + if (!n && lws_async_dns_init(context)) + goto bail1; +#endif + /* for the case we are adding a vhost much later, after server init */ if (context->protocol_init_done) @@ -791,7 +869,7 @@ return NULL; } -LWS_VISIBLE int +int lws_init_vhost_client_ssl(const struct lws_context_creation_info *info, struct lws_vhost *vhost) { @@ -803,13 +881,13 @@ return lws_context_init_client_ssl(&i, vhost); } -LWS_VISIBLE void +void lws_cancel_service_pt(struct lws *wsi) { lws_plat_pipe_signal(wsi); } -LWS_VISIBLE void +void lws_cancel_service(struct lws_context *context) { struct lws_context_per_thread *pt = &context->pt[0]; @@ -818,7 +896,7 @@ if (context->being_destroyed1) return; - lwsl_info("%s\n", __func__); + lwsl_debug("%s\n", __func__); while (m--) { if (pt->pipe_wsi) @@ -830,6 +908,8 @@ int lws_create_event_pipes(struct lws_context *context) { + struct lws_context_per_thread *pt; + size_t s = sizeof(struct lws); struct lws *wsi; int n; @@ -838,26 +918,42 @@ * not bound to a vhost or protocol (both are NULL) */ +#if LWS_MAX_SMP > 1 for (n = 0; n < context->count_threads; n++) { - if (context->pt[n].pipe_wsi) - continue; +#else + n = 0; + { +#endif + pt = &context->pt[n]; - wsi = lws_zalloc(sizeof(*wsi), "event pipe wsi"); + if (pt->pipe_wsi) + return 0; + +#if defined(LWS_WITH_EVENT_LIBS) + s += context->event_loop_ops->evlib_size_wsi; +#endif + + wsi = lws_zalloc(s, "event pipe wsi"); if (!wsi) { lwsl_err("%s: Out of mem\n", __func__); return 1; } - wsi->context = context; +#if defined(LWS_WITH_EVENT_LIBS) + wsi->evlib_wsi = (uint8_t *)wsi + sizeof(*wsi); +#endif + wsi->a.context = context; lws_role_transition(wsi, 0, LRS_UNCONNECTED, &role_ops_pipe); - wsi->protocol = NULL; + wsi->a.protocol = NULL; wsi->tsi = n; - wsi->vhost = NULL; + wsi->a.vhost = NULL; wsi->event_pipe = 1; wsi->desc.sockfd = LWS_SOCK_INVALID; context->pt[n].pipe_wsi = wsi; context->count_wsi_allocated++; - if (lws_plat_pipe_create(wsi)) + lws_pt_lock(pt, __func__); /* -------------- pt { */ + + if (!lws_plat_pipe_create(wsi)) { /* * platform code returns 0 if it actually created pipes * and initialized pt->dummy_pipe_fds[]. If it used @@ -866,40 +962,48 @@ * related to dummy_pipe_fds[], adding it to the fds, * etc. */ - continue; - wsi->desc.sockfd = context->pt[n].dummy_pipe_fds[0]; - lwsl_debug("event pipe fd %d\n", wsi->desc.sockfd); + wsi->desc.sockfd = context->pt[n].dummy_pipe_fds[0]; + lwsl_debug("event pipe fd %d\n", wsi->desc.sockfd); -#if !defined(LWS_AMAZON_RTOS) - if (context->event_loop_ops->accept) - if (context->event_loop_ops->accept(wsi)) - return 1; -#endif + if (context->event_loop_ops->sock_accept) + if (context->event_loop_ops->sock_accept(wsi)) + goto bail; - if (__insert_wsi_socket_into_fds(context, wsi)) - return 1; + if (__insert_wsi_socket_into_fds(context, wsi)) + goto bail; + } + + lws_pt_unlock(pt); } return 0; + +bail: + lws_pt_unlock(pt); + + return 1; } void lws_destroy_event_pipe(struct lws *wsi) { lwsl_info("%s\n", __func__); - __remove_wsi_socket_from_fds(wsi); - if (wsi->context->event_loop_ops->wsi_logical_close) { - wsi->context->event_loop_ops->wsi_logical_close(wsi); + if (lws_socket_is_valid(wsi->desc.sockfd)) + __remove_wsi_socket_from_fds(wsi); + + if (!wsi->a.context->event_loop_ops->destroy_wsi && + wsi->a.context->event_loop_ops->wsi_logical_close) { + wsi->a.context->event_loop_ops->wsi_logical_close(wsi); lws_plat_pipe_close(wsi); return; } - if (wsi->context->event_loop_ops->destroy_wsi) - wsi->context->event_loop_ops->destroy_wsi(wsi); + if (wsi->a.context->event_loop_ops->destroy_wsi) + wsi->a.context->event_loop_ops->destroy_wsi(wsi); lws_plat_pipe_close(wsi); - wsi->context->count_wsi_allocated--; + wsi->a.context->count_wsi_allocated--; lws_free(wsi); } @@ -918,7 +1022,6 @@ lws_vhost_lock(vh); /* -------------- vh { */ - vh->being_destroyed = 1; #if defined(LWS_WITH_NETWORK) /* * PHASE 1: take down or reassign any listen wsi @@ -1000,25 +1103,44 @@ struct lws wsi; int n; + vh->being_destroyed = 0; + +#if defined(LWS_WITH_CLIENT) + /* + * destroy any wsi that are associated with us but have no socket + * (and will otherwise be missed for destruction) + */ + lws_start_foreach_dll_safe(struct lws_dll2 *, d, d1, + vh->vh_awaiting_socket_owner.head) { + struct lws *w = + lws_container_of(d, struct lws, vh_awaiting_socket); + + lws_close_free_wsi(w, LWS_CLOSE_STATUS_NOSTATUS, + "awaiting skt"); + + } lws_end_foreach_dll_safe(d, d1); +#endif + +#if defined(LWS_WITH_DEPRECATED_THINGS) /* * destroy any pending timed events */ while (vh->timed_vh_protocol_list) __lws_timed_callback_remove(vh, vh->timed_vh_protocol_list); - +#endif /* * let the protocols destroy the per-vhost protocol objects */ memset(&wsi, 0, sizeof(wsi)); - wsi.context = vh->context; - wsi.vhost = vh; /* not a real bound wsi */ + wsi.a.context = vh->context; + wsi.a.vhost = vh; /* not a real bound wsi */ protocol = vh->protocols; if (protocol && vh->created_vhost_protocols) { n = 0; while (n < vh->count_protocols) { - wsi.protocol = protocol; + wsi.a.protocol = protocol; if (protocol->callback) protocol->callback(&wsi, LWS_CALLBACK_PROTOCOL_DESTROY, @@ -1041,8 +1163,10 @@ /* add ourselves to the pending destruction list */ - vh->vhost_next = vh->context->vhost_pending_destruction_list; - vh->context->vhost_pending_destruction_list = vh; + if (vh->context->vhost_pending_destruction_list != vh) { + vh->vhost_next = vh->context->vhost_pending_destruction_list; + vh->context->vhost_pending_destruction_list = vh; + } lwsl_info("%s: %p\n", __func__, vh); @@ -1090,7 +1214,10 @@ lws_ssl_SSL_CTX_destroy(vh); lws_free(vh->same_vh_protocol_owner); - if (context->plugin_list || + if ( +#if defined(LWS_WITH_PLUGINS) + context->plugin_list || +#endif (context->options & LWS_SERVER_OPTION_EXPLICIT_VHOSTS) || vh->allocated_vhost_protocols) lws_free((void *)vh->protocols); @@ -1188,7 +1315,7 @@ struct lws *wsi = wsi_from_fd(context, pt->fds[n].fd); if (!wsi) continue; - if (wsi->vhost != v) + if (wsi->a.vhost != v) continue; __lws_close_free_wsi(wsi, @@ -1209,7 +1336,7 @@ } -LWS_VISIBLE void +void lws_vhost_destroy(struct lws_vhost *vh) { struct lws_deferred_free *df = lws_malloc(sizeof(*df), "deferred free"); @@ -1222,6 +1349,8 @@ lws_vhost_destroy1(vh); + lwsl_debug("%s: count_bound_wsi %d\n", __func__, vh->count_bound_wsi); + if (!vh->count_bound_wsi) { /* * After listen handoff, there are already no wsi bound to this @@ -1248,20 +1377,20 @@ } -LWS_EXTERN void * +void * lws_vhost_user(struct lws_vhost *vhost) { return vhost->user; } -LWS_VISIBLE LWS_EXTERN int +int lws_get_vhost_listen_port(struct lws_vhost *vhost) { return vhost->listen_port; } - -LWS_VISIBLE LWS_EXTERN void +#if defined(LWS_WITH_SERVER) +void lws_context_deprecate(struct lws_context *context, lws_reload_func cb) { struct lws_vhost *vh = context->vhost_list, *vh1; @@ -1283,7 +1412,7 @@ if (wsi) { wsi->socket_is_permanently_unusable = 1; lws_close_free_wsi(wsi, LWS_CLOSE_STATUS_NOSTATUS, "ctx deprecate"); - wsi->context->deprecation_pending_listen_close_count++; + wsi->a.context->deprecation_pending_listen_close_count++; /* * other vhosts can share the listen port, they * point to the same wsi. So zap those too. @@ -1301,8 +1430,10 @@ context->deprecated = 1; context->deprecation_cb = cb; } +#endif #if defined(LWS_WITH_NETWORK) + struct lws_vhost * lws_get_vhost_by_name(struct lws_context *context, const char *name) { @@ -1315,4 +1446,175 @@ return NULL; } + + +#if defined(LWS_WITH_CLIENT) +/* + * This is the logic checking to see if the new connection wsi should have a + * pipelining or muxing relationship with an existing "active connection" to + * the same endpoint under the same conditions. + * + * This was originally in the client code but since the list is held on the + * vhost (to ensure the same client tls ctx is involved) it's cleaner in vhost.c + * + * ACTIVE_CONNS_QUEUED: We're queued on an active connection, set *nwsi to that + * ACTIVE_CONNS_MUXED: We are joining an active mux conn *nwsi as a child + * ACTIVE_CONNS_SOLO: There's no existing conn to join either way + */ + +int +lws_vhost_active_conns(struct lws *wsi, struct lws **nwsi, const char *adsin) +{ + if (!lws_dll2_is_detached(&wsi->dll2_cli_txn_queue)) { + struct lws *w = lws_container_of( + wsi->dll2_cli_txn_queue.owner, struct lws, + dll2_cli_txn_queue_owner); + *nwsi = w; + + return ACTIVE_CONNS_QUEUED; + } + +#if defined(LWS_ROLE_H2) || defined(LWS_ROLE_MQTT) + if (wsi->mux.parent_wsi) { + /* + * We already decided... + */ + + *nwsi = wsi->mux.parent_wsi; + + return ACTIVE_CONNS_MUXED; + } +#endif + + lws_vhost_lock(wsi->a.vhost); /* ----------------------------------- { */ + + lws_start_foreach_dll_safe(struct lws_dll2 *, d, d1, + wsi->a.vhost->dll_cli_active_conns_owner.head) { + struct lws *w = lws_container_of(d, struct lws, + dll_cli_active_conns); + + lwsl_debug("%s: check %p %p %s %s %d %d\n", __func__, wsi, w, + adsin, w->cli_hostname_copy, wsi->c_port, w->c_port); + + if (w != wsi && + /* + * "same internet protocol"... this is a bit tricky, + * since h2 start out as h1 + */ + (w->role_ops == wsi->role_ops || + (lwsi_role_http(w) && lwsi_role_http(wsi))) && + w->cli_hostname_copy && + !strcmp(adsin, w->cli_hostname_copy) && +#if defined(LWS_WITH_TLS) + (wsi->tls.use_ssl & LCCSCF_USE_SSL) == + (w->tls.use_ssl & LCCSCF_USE_SSL) && +#endif + wsi->c_port == w->c_port) { + + /* + * There's already an active connection. + * + * The server may have told the existing active + * connection that it doesn't support pipelining... + */ + if (w->keepalive_rejected) { + lwsl_notice("defeating pipelining due to no " + "keepalive on server\n"); + goto solo; + } + +#if defined(LWS_WITH_HTTP2) + /* + * h2: if in usable state already: just use it without + * going through the queue + */ + if (w->client_h2_alpn && w->client_mux_migrated && + (lwsi_state(w) == LRS_H2_WAITING_TO_SEND_HEADERS || + lwsi_state(w) == LRS_ESTABLISHED || + lwsi_state(w) == LRS_IDLING)) { + + lwsl_notice("%s: just join h2 directly 0x%x\n", + __func__, lwsi_state(w)); + + if (lwsi_state(w) == LRS_IDLING) { + // lwsi_set_state(w, LRS_ESTABLISHED); + _lws_generic_transaction_completed_active_conn(&w, 0); + } + + //lwsi_set_state(w, LRS_H1C_ISSUE_HANDSHAKE2); + + wsi->client_h2_alpn = 1; + lws_wsi_h2_adopt(w, wsi); + lws_vhost_unlock(wsi->a.vhost); /* } ---------- */ + + *nwsi = w; + + return ACTIVE_CONNS_MUXED; + } +#endif + +#if defined(LWS_ROLE_MQTT) + /* + * MQTT: if in usable state already: just use it without + * going through the queue + */ + + if (lwsi_role_mqtt(wsi) && w->client_mux_migrated && + lwsi_state(w) == LRS_ESTABLISHED) { + + if (lws_wsi_mqtt_adopt(w, wsi)) { + lwsl_notice("%s: join mqtt directly\n", __func__); + lws_dll2_remove(&wsi->dll2_cli_txn_queue); + wsi->client_mux_substream = 1; + + lws_vhost_unlock(wsi->a.vhost); /* } ---------- */ + + + return ACTIVE_CONNS_MUXED; + } + } +#endif + + /* + * If the connection is viable but not yet in a usable + * state, let's attach ourselves to it and wait for it + * to get there or fail. + */ + + lwsl_notice("%s: apply %p to txn queue on %p state 0x%lx\n", + __func__, wsi, w, (unsigned long)w->wsistate); + /* + * ...let's add ourselves to his transaction queue... + * we are adding ourselves at the TAIL + */ + lws_dll2_add_tail(&wsi->dll2_cli_txn_queue, + &w->dll2_cli_txn_queue_owner); + + if (lwsi_state(w) == LRS_IDLING) { + // lwsi_set_state(w, LRS_ESTABLISHED); + _lws_generic_transaction_completed_active_conn(&w, 0); + } + + /* + * For eg, h1 next we'd pipeline our headers out on him, + * and wait for our turn at client transaction_complete + * to take over parsing the rx. + */ + lws_vhost_unlock(wsi->a.vhost); /* } ---------- */ + + *nwsi = w; + + return ACTIVE_CONNS_QUEUED; + } + + } lws_end_foreach_dll_safe(d, d1); + +solo: + lws_vhost_unlock(wsi->a.vhost); /* } ---------------------------------- */ + + /* there is nobody already connected in the same way */ + + return ACTIVE_CONNS_SOLO; +} +#endif #endif diff -Nru libwebsockets-3.2.1/lib/core-net/wsi.c libwebsockets-4.1.6/lib/core-net/wsi.c --- libwebsockets-3.2.1/lib/core-net/wsi.c 2019-12-18 14:45:31.000000000 +0000 +++ libwebsockets-4.1.6/lib/core-net/wsi.c 2020-12-01 17:40:26.000000000 +0000 @@ -1,25 +1,28 @@ /* * libwebsockets - small server side websockets and web server implementation * - * Copyright (C) 2010-2019 Andy Green + * Copyright (C) 2010 - 2019 Andy Green * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation: - * version 2.1 of the License. + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to + * deal in the Software without restriction, including without limitation the + * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or + * sell copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: * - * This library is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. * - * You should have received a copy of the GNU Lesser General Public - * License along with this library; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, - * MA 02110-1301 USA + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS + * IN THE SOFTWARE. */ -#include "core/private.h" +#include "private-lib-core.h" #if defined (_DEBUG) void lwsi_set_role(struct lws *wsi, lws_wsi_state_t role) @@ -43,32 +46,34 @@ void lws_vhost_bind_wsi(struct lws_vhost *vh, struct lws *wsi) { - if (wsi->vhost == vh) + if (wsi->a.vhost == vh) return; lws_context_lock(vh->context, __func__); /* ---------- context { */ - wsi->vhost = vh; + wsi->a.vhost = vh; vh->count_bound_wsi++; lws_context_unlock(vh->context); /* } context ---------- */ - lwsl_info("%s: vh %s: count_bound_wsi %d\n", - __func__, vh->name, vh->count_bound_wsi); - assert(wsi->vhost->count_bound_wsi > 0); + lwsl_debug("%s: vh %s: wsi %s/%s, count_bound_wsi %d\n", __func__, + vh->name, wsi->role_ops ? wsi->role_ops->name : "none", + wsi->a.protocol ? wsi->a.protocol->name : "none", + vh->count_bound_wsi); + assert(wsi->a.vhost->count_bound_wsi > 0); } void lws_vhost_unbind_wsi(struct lws *wsi) { - if (!wsi->vhost) + if (!wsi->a.vhost) return; - lws_context_lock(wsi->context, __func__); /* ---------- context { */ + lws_context_lock(wsi->a.context, __func__); /* ---------- context { */ - assert(wsi->vhost->count_bound_wsi > 0); - wsi->vhost->count_bound_wsi--; - lwsl_info("%s: vh %s: count_bound_wsi %d\n", __func__, - wsi->vhost->name, wsi->vhost->count_bound_wsi); + assert(wsi->a.vhost->count_bound_wsi > 0); + wsi->a.vhost->count_bound_wsi--; + lwsl_debug("%s: vh %s: count_bound_wsi %d\n", __func__, + wsi->a.vhost->name, wsi->a.vhost->count_bound_wsi); - if (!wsi->vhost->count_bound_wsi && - wsi->vhost->being_destroyed) { + if (!wsi->a.vhost->count_bound_wsi && + wsi->a.vhost->being_destroyed) { /* * We have closed all wsi that were bound to this vhost * by any pt: nothing can be servicing any wsi belonging @@ -76,36 +81,36 @@ * * Finalize the vh destruction */ - __lws_vhost_destroy2(wsi->vhost); + __lws_vhost_destroy2(wsi->a.vhost); } - wsi->vhost = NULL; + wsi->a.vhost = NULL; - lws_context_unlock(wsi->context); /* } context ---------- */ + lws_context_unlock(wsi->a.context); /* } context ---------- */ } -LWS_VISIBLE struct lws * +struct lws * lws_get_network_wsi(struct lws *wsi) { if (!wsi) return NULL; -#if defined(LWS_WITH_HTTP2) - if (!wsi->http2_substream -#if !defined(LWS_NO_CLIENT) - && !wsi->client_h2_substream +#if defined(LWS_WITH_HTTP2) || defined(LWS_ROLE_MQTT) + if (!wsi->mux_substream +#if defined(LWS_WITH_CLIENT) + && !wsi->client_mux_substream #endif ) return wsi; - while (wsi->h2.parent_wsi) - wsi = wsi->h2.parent_wsi; + while (wsi->mux.parent_wsi) + wsi = wsi->mux.parent_wsi; #endif return wsi; } -LWS_VISIBLE LWS_EXTERN const struct lws_protocols * +const struct lws_protocols * lws_vhost_name_to_protocol(struct lws_vhost *vh, const char *name) { int n; @@ -117,7 +122,7 @@ return NULL; } -LWS_VISIBLE int +int lws_callback_all_protocol(struct lws_context *context, const struct lws_protocols *protocol, int reason) { @@ -130,7 +135,7 @@ wsi = wsi_from_fd(context, pt->fds[n].fd); if (!wsi) continue; - if (wsi->protocol == protocol) + if (wsi->a.protocol == protocol) protocol->callback(wsi, reason, wsi->user_space, NULL, 0); } @@ -140,7 +145,7 @@ return 0; } -LWS_VISIBLE int +int lws_callback_all_protocol_vhost_args(struct lws_vhost *vh, const struct lws_protocols *protocol, int reason, void *argp, size_t len) @@ -155,9 +160,9 @@ wsi = wsi_from_fd(context, pt->fds[n].fd); if (!wsi) continue; - if (wsi->vhost == vh && (wsi->protocol == protocol || + if (wsi->a.vhost == vh && (wsi->a.protocol == protocol || !protocol)) - wsi->protocol->callback(wsi, reason, + wsi->a.protocol->callback(wsi, reason, wsi->user_space, argp, len); } pt++; @@ -166,26 +171,26 @@ return 0; } -LWS_VISIBLE int +int lws_callback_all_protocol_vhost(struct lws_vhost *vh, const struct lws_protocols *protocol, int reason) { return lws_callback_all_protocol_vhost_args(vh, protocol, reason, NULL, 0); } -LWS_VISIBLE LWS_EXTERN int +int lws_callback_vhost_protocols(struct lws *wsi, int reason, void *in, int len) { int n; - for (n = 0; n < wsi->vhost->count_protocols; n++) - if (wsi->vhost->protocols[n].callback(wsi, reason, NULL, in, len)) + for (n = 0; n < wsi->a.vhost->count_protocols; n++) + if (wsi->a.vhost->protocols[n].callback(wsi, reason, NULL, in, len)) return 1; return 0; } -LWS_VISIBLE LWS_EXTERN int +int lws_callback_vhost_protocols_vhost(struct lws_vhost *vh, int reason, void *in, size_t len) { @@ -195,12 +200,12 @@ if (!wsi) return 1; - wsi->context = vh->context; + wsi->a.context = vh->context; lws_vhost_bind_wsi(vh, wsi); - for (n = 0; n < wsi->vhost->count_protocols; n++) { - wsi->protocol = &vh->protocols[n]; - if (wsi->protocol->callback(wsi, reason, NULL, in, len)) { + for (n = 0; n < wsi->a.vhost->count_protocols; n++) { + wsi->a.protocol = &vh->protocols[n]; + if (wsi->a.protocol->callback(wsi, reason, NULL, in, len)) { lws_free(wsi); return 1; } @@ -212,14 +217,14 @@ } -LWS_VISIBLE int +int lws_rx_flow_control(struct lws *wsi, int _enable) { - struct lws_context_per_thread *pt = &wsi->context->pt[(int)wsi->tsi]; + struct lws_context_per_thread *pt = &wsi->a.context->pt[(int)wsi->tsi]; int en = _enable; // h2 ignores rx flow control atm - if (lwsi_role_h2(wsi) || wsi->http2_substream || + if (lwsi_role_h2(wsi) || wsi->mux_substream || lwsi_role_h2_ENCAPSULATION(wsi)) return 0; // !!! @@ -267,7 +272,7 @@ return 0; } -LWS_VISIBLE void +void lws_rx_flow_allow_all_protocol(const struct lws_context *context, const struct lws_protocols *protocol) { @@ -280,7 +285,7 @@ wsi = wsi_from_fd(context, pt->fds[n].fd); if (!wsi) continue; - if (wsi->protocol == protocol) + if (wsi->a.protocol == protocol) lws_rx_flow_control(wsi, LWS_RXFLOW_ALLOW); } pt++; @@ -303,13 +308,13 @@ return n; } -LWS_EXTERN int +int __lws_rx_flow_control(struct lws *wsi) { struct lws *wsic = wsi->child_list; // h2 ignores rx flow control atm - if (lwsi_role_h2(wsi) || wsi->http2_substream || + if (lwsi_role_h2(wsi) || wsi->mux_substream || lwsi_role_h2_ENCAPSULATION(wsi)) return 0; // !!! @@ -343,7 +348,7 @@ if (wsi->rxflow_change_to & LWS_RXFLOW_ALLOW) { lwsl_info("%s: reenable POLLIN\n", __func__); - // lws_buflist_describe(&wsi->buflist, NULL); + // lws_buflist_describe(&wsi->buflist, NULL, __func__); if (__lws_change_pollfd(wsi, 0, LWS_POLLIN)) { lwsl_info("%s: fail\n", __func__); return -1; @@ -356,36 +361,36 @@ } -LWS_VISIBLE const struct lws_protocols * +const struct lws_protocols * lws_get_protocol(struct lws *wsi) { - return wsi->protocol; + return wsi->a.protocol; } int lws_ensure_user_space(struct lws *wsi) { - if (!wsi->protocol) + if (!wsi->a.protocol) return 0; /* allocate the per-connection user memory (if any) */ - if (wsi->protocol->per_session_data_size && !wsi->user_space) { + if (wsi->a.protocol->per_session_data_size && !wsi->user_space) { wsi->user_space = lws_zalloc( - wsi->protocol->per_session_data_size, "user space"); + wsi->a.protocol->per_session_data_size, "user space"); if (wsi->user_space == NULL) { lwsl_err("%s: OOM\n", __func__); return 1; } } else lwsl_debug("%s: %p protocol pss %lu, user_space=%p\n", __func__, - wsi, (long)wsi->protocol->per_session_data_size, + wsi, (long)wsi->a.protocol->per_session_data_size, wsi->user_space); return 0; } -LWS_VISIBLE void * +void * lws_adjust_protocol_psds(struct lws *wsi, size_t new_size) { ((struct lws_protocols *)lws_get_protocol(wsi))->per_session_data_size = @@ -397,9 +402,13 @@ return wsi->user_space; } +int +lws_get_tsi(struct lws *wsi) +{ + return (int)wsi->tsi; +} - -LWS_VISIBLE int +int lws_is_ssl(struct lws *wsi) { #if defined(LWS_WITH_TLS) @@ -411,38 +420,38 @@ } #if defined(LWS_WITH_TLS) && !defined(LWS_WITH_MBEDTLS) -LWS_VISIBLE lws_tls_conn* +lws_tls_conn* lws_get_ssl(struct lws *wsi) { return wsi->tls.ssl; } #endif -LWS_VISIBLE int +int lws_partial_buffered(struct lws *wsi) { return lws_has_buffered_out(wsi); } -LWS_VISIBLE lws_fileofs_t +lws_fileofs_t lws_get_peer_write_allowance(struct lws *wsi) { if (!wsi->role_ops->tx_credit) return -1; - return wsi->role_ops->tx_credit(wsi); + return wsi->role_ops->tx_credit(wsi, LWSTXCR_US_TO_PEER, 0); } -LWS_VISIBLE void +void lws_role_transition(struct lws *wsi, enum lwsi_role role, enum lwsi_state state, const struct lws_role_ops *ops) { -#if defined(_DEBUG) +#if (_LWS_ENABLED_LOGS & LLL_DEBUG) const char *name = "(unset)"; #endif wsi->wsistate = role | state; if (ops) wsi->role_ops = ops; -#if defined(_DEBUG) +#if (_LWS_ENABLED_LOGS & LLL_DEBUG) if (wsi->role_ops) name = wsi->role_ops->name; lwsl_debug("%s: %p: wsistate 0x%lx, ops %s\n", __func__, wsi, @@ -450,7 +459,7 @@ #endif } -LWS_VISIBLE LWS_EXTERN int +int lws_parse_uri(char *p, const char **prot, const char **ads, int *port, const char **path) { @@ -506,7 +515,7 @@ /* ... */ -LWS_VISIBLE LWS_EXTERN const char * +const char * lws_get_urlarg_by_name(struct lws *wsi, const char *name, char *buf, int len) { int n = 0, sl = (int)strlen(name); @@ -531,7 +540,7 @@ * extensions disabled. */ -LWS_VISIBLE int +int lws_extension_callback_pm_deflate(struct lws_context *context, const struct lws_extension *ext, struct lws *wsi, @@ -549,7 +558,7 @@ return 0; } -LWS_EXTERN int +int lws_set_extension_option(struct lws *wsi, const char *ext_name, const char *opt_name, const char *opt_val) { @@ -557,7 +566,7 @@ } #endif -LWS_VISIBLE LWS_EXTERN int +int lws_is_cgi(struct lws *wsi) { #ifdef LWS_WITH_CGI return !!wsi->http.cgi; @@ -598,86 +607,99 @@ lws_broadcast(struct lws_context_per_thread *pt, int reason, void *in, size_t len) { struct lws_vhost *v = pt->context->vhost_list; + lws_fakewsi_def_plwsa(pt); int n, ret = 0; - pt->fake_wsi->context = pt->context; + lws_fakewsi_prep_plwsa_ctx(pt->context); +#if !defined(LWS_PLAT_FREERTOS) && LWS_MAX_SMP > 1 + ((struct lws *)plwsa)->tsi = (int)(pt - &pt->context->pt[0]); +#endif while (v) { const struct lws_protocols *p = v->protocols; - pt->fake_wsi->vhost = v; /* not a real bound wsi */ + + plwsa->vhost = v; /* not a real bound wsi */ for (n = 0; n < v->count_protocols; n++) { - pt->fake_wsi->protocol = p; + plwsa->protocol = p; if (p->callback && - p->callback(pt->fake_wsi, reason, NULL, in, len)) + p->callback((struct lws *)plwsa, reason, NULL, in, len)) ret |= 1; p++; } + v = v->vhost_next; } return ret; } -LWS_VISIBLE LWS_EXTERN void * +void * lws_wsi_user(struct lws *wsi) { return wsi->user_space; } -LWS_VISIBLE LWS_EXTERN void +int +lws_wsi_tsi(struct lws *wsi) +{ + return wsi->tsi; +} + + +void lws_set_wsi_user(struct lws *wsi, void *data) { - if (wsi->user_space_externally_allocated) - wsi->user_space = data; - else - lwsl_err("%s: Cannot set internally-allocated user_space\n", - __func__); + if (!wsi->user_space_externally_allocated && wsi->user_space) + lws_free(wsi->user_space); + + wsi->user_space_externally_allocated = 1; + wsi->user_space = data; } -LWS_VISIBLE LWS_EXTERN struct lws * +struct lws * lws_get_parent(const struct lws *wsi) { return wsi->parent; } -LWS_VISIBLE LWS_EXTERN struct lws * +struct lws * lws_get_child(const struct lws *wsi) { return wsi->child_list; } -LWS_VISIBLE LWS_EXTERN void * +void * lws_get_opaque_parent_data(const struct lws *wsi) { return wsi->opaque_parent_data; } -LWS_VISIBLE LWS_EXTERN void +void lws_set_opaque_parent_data(struct lws *wsi, void *data) { wsi->opaque_parent_data = data; } -LWS_VISIBLE LWS_EXTERN void * +void * lws_get_opaque_user_data(const struct lws *wsi) { - return wsi->opaque_user_data; + return wsi->a.opaque_user_data; } -LWS_VISIBLE LWS_EXTERN void +void lws_set_opaque_user_data(struct lws *wsi, void *data) { - wsi->opaque_user_data = data; + wsi->a.opaque_user_data = data; } -LWS_VISIBLE LWS_EXTERN int +int lws_get_child_pending_on_writable(const struct lws *wsi) { return wsi->parent_pending_cb_on_writable; } -LWS_VISIBLE LWS_EXTERN void +void lws_clear_child_pending_on_writable(struct lws *wsi) { wsi->parent_pending_cb_on_writable = 0; @@ -685,31 +707,31 @@ -LWS_VISIBLE LWS_EXTERN const char * +const char * lws_get_vhost_name(struct lws_vhost *vhost) { return vhost->name; } -LWS_VISIBLE LWS_EXTERN int +int lws_get_vhost_port(struct lws_vhost *vhost) { return vhost->listen_port; } -LWS_VISIBLE LWS_EXTERN void * +void * lws_get_vhost_user(struct lws_vhost *vhost) { return vhost->user; } -LWS_VISIBLE LWS_EXTERN const char * +const char * lws_get_vhost_iface(struct lws_vhost *vhost) { return vhost->iface; } -LWS_VISIBLE lws_sockfd_type +lws_sockfd_type lws_get_socket_fd(struct lws *wsi) { if (!wsi) @@ -718,78 +740,201 @@ } -LWS_VISIBLE struct lws_vhost * +struct lws_vhost * lws_vhost_get(struct lws *wsi) { - return wsi->vhost; + return wsi->a.vhost; } -LWS_VISIBLE struct lws_vhost * +struct lws_vhost * lws_get_vhost(struct lws *wsi) { - return wsi->vhost; + return wsi->a.vhost; } -LWS_VISIBLE const struct lws_protocols * +const struct lws_protocols * lws_protocol_get(struct lws *wsi) { - return wsi->protocol; + return wsi->a.protocol; } -LWS_VISIBLE const struct lws_udp * +#if defined(LWS_WITH_UDP) +const struct lws_udp * lws_get_udp(const struct lws *wsi) { return wsi->udp; } +#endif -LWS_VISIBLE LWS_EXTERN struct lws_context * +struct lws_context * lws_get_context(const struct lws *wsi) { - return wsi->context; + return wsi->a.context; } -#ifdef LWS_LATENCY -void -lws_latency(struct lws_context *context, struct lws *wsi, const char *action, - int ret, int completed) +#if defined(LWS_WITH_CLIENT) +int +_lws_generic_transaction_completed_active_conn(struct lws **_wsi, char take_vh_lock) { - unsigned long long u; - char buf[256]; + struct lws *wnew, *wsi = *_wsi; - u = lws_now_usecs(); + /* + * Are we constitutionally capable of having a queue, ie, we are on + * the "active client connections" list? + * + * If not, that's it for us. + */ + + if (lws_dll2_is_detached(&wsi->dll_cli_active_conns)) + return 0; /* no new transaction */ + + /* + * With h1 queuing, the original "active client" moves his attributes + * like fd, ssl, queue and active client list entry to the next guy in + * the queue before closing... it's because the user code knows the + * individual wsi and the action must take place in the correct wsi + * context. Note this means we don't truly pipeline headers. + * + * Trying to keep the original "active client" in place to do the work + * of the wsi breaks down when dealing with queued POSTs otherwise; it's + * also competing with the real mux child arrangements and complicating + * the code. + * + * For that reason, see if we have any queued child now... + */ - if (!action) { - wsi->latency_start = u; - if (!wsi->action_start) - wsi->action_start = u; - return; - } - if (completed) { - if (wsi->action_start == wsi->latency_start) - sprintf(buf, - "Completion first try lat %lluus: %p: ret %d: %s\n", - u - wsi->latency_start, - (void *)wsi, ret, action); - else - sprintf(buf, - "Completion %lluus: lat %lluus: %p: ret %d: %s\n", - u - wsi->action_start, - u - wsi->latency_start, - (void *)wsi, ret, action); - wsi->action_start = 0; - } else - sprintf(buf, "lat %lluus: %p: ret %d: %s\n", - u - wsi->latency_start, (void *)wsi, ret, action); + if (!wsi->dll2_cli_txn_queue_owner.head) { + /* + * Nothing pipelined... we should hang around a bit + * in case something turns up... otherwise we'll close + */ + lwsl_info("%s: nothing pipelined waiting\n", __func__); + lwsi_set_state(wsi, LRS_IDLING); - if (u - wsi->latency_start > context->worst_latency) { - context->worst_latency = u - wsi->latency_start; - strcpy(context->worst_latency_info, buf); + lws_set_timeout(wsi, PENDING_TIMEOUT_CLIENT_CONN_IDLE, + wsi->keep_warm_secs); + + return 0; /* no new transaction right now */ } - lwsl_latency("%s", buf); + + /* + * We have a queued child wsi we should bequeath our assets to, before + * closing ourself + */ + + if (take_vh_lock) + lws_vhost_lock(wsi->a.vhost); + + wnew = lws_container_of(wsi->dll2_cli_txn_queue_owner.head, struct lws, + dll2_cli_txn_queue); + + assert(wsi != wnew); + + lws_dll2_remove(&wnew->dll2_cli_txn_queue); + + assert(lws_socket_is_valid(wsi->desc.sockfd)); + + __lws_change_pollfd(wsi, LWS_POLLOUT | LWS_POLLIN, 0); + + /* copy the fd */ + wnew->desc = wsi->desc; + + assert(lws_socket_is_valid(wnew->desc.sockfd)); + + /* disconnect the fd from association with old wsi */ + + if (__remove_wsi_socket_from_fds(wsi)) + return -1; + + sanity_assert_no_wsi_traces(wsi->a.context, wsi); + sanity_assert_no_sockfd_traces(wsi->a.context, wsi->desc.sockfd); + wsi->desc.sockfd = LWS_SOCK_INVALID; + + __lws_wsi_remove_from_sul(wsi); + + /* + * ... we're doing some magic here in terms of handing off the socket + * that has been active to a wsi that has not yet itself been active... + * depending on the event lib we may need to give a magic spark to the + * new guy and snuff out the old guy's magic spark at that level as well + */ + +#if defined(LWS_WITH_EVENT_LIBS) + if (wsi->a.context->event_loop_ops->destroy_wsi) + wsi->a.context->event_loop_ops->destroy_wsi(wsi); + if (wsi->a.context->event_loop_ops->sock_accept) + wsi->a.context->event_loop_ops->sock_accept(wnew); +#endif + + /* point the fd table entry to new guy */ + + assert(lws_socket_is_valid(wnew->desc.sockfd)); + + if (__insert_wsi_socket_into_fds(wsi->a.context, wnew)) + return -1; + +#if defined(LWS_WITH_TLS) + /* pass on the tls */ + + wnew->tls = wsi->tls; + wsi->tls.client_bio = NULL; + wsi->tls.ssl = NULL; + wsi->tls.use_ssl = 0; +#endif + + /* take over his copy of his endpoint as an active connection */ + + wnew->cli_hostname_copy = wsi->cli_hostname_copy; + wsi->cli_hostname_copy = NULL; + wnew->keep_warm_secs = wsi->keep_warm_secs; + + /* + * selected queued guy now replaces the original leader on the + * active client conn list + */ + + lws_dll2_remove(&wsi->dll_cli_active_conns); + lws_dll2_add_tail(&wnew->dll_cli_active_conns, + &wsi->a.vhost->dll_cli_active_conns_owner); + + /* move any queued guys to queue on new active conn */ + + lws_start_foreach_dll_safe(struct lws_dll2 *, d, d1, + wsi->dll2_cli_txn_queue_owner.head) { + struct lws *ww = lws_container_of(d, struct lws, + dll2_cli_txn_queue); + + lws_dll2_remove(&ww->dll2_cli_txn_queue); + lws_dll2_add_tail(&ww->dll2_cli_txn_queue, + &wnew->dll2_cli_txn_queue_owner); + + } lws_end_foreach_dll_safe(d, d1); + + if (take_vh_lock) + lws_vhost_unlock(wsi->a.vhost); + + /* + * The original leader who passed on all his powers already can die... + * in the call stack above us there are guys who still want to touch + * him, so have him die next time around the event loop, not now. + */ + + wsi->already_did_cce = 1; /* so the close doesn't trigger a CCE */ + lws_set_timeout(wsi, 1, LWS_TO_KILL_ASYNC); + + /* after the first one, they can only be coming from the queue */ + wnew->transaction_from_pipeline_queue = 1; + + lwsl_notice("%s: pipeline queue passed wsi %p on to queued wsi %p\n", + __func__, wsi, wnew); + + *_wsi = wnew; /* inform caller we swapped */ + + return 1; /* new transaction */ } #endif -LWS_VISIBLE int LWS_WARN_UNUSED_RESULT +int LWS_WARN_UNUSED_RESULT lws_raw_transaction_completed(struct lws *wsi) { if (lws_has_buffered_out(wsi)) { @@ -815,12 +960,12 @@ lws_bind_protocol(struct lws *wsi, const struct lws_protocols *p, const char *reason) { -// if (wsi->protocol == p) +// if (wsi->a.protocol == p) // return 0; - const struct lws_protocols *vp = wsi->vhost->protocols, *vpo; + const struct lws_protocols *vp = wsi->a.vhost->protocols, *vpo; - if (wsi->protocol && wsi->protocol_bind_balance) { - wsi->protocol->callback(wsi, + if (wsi->a.protocol && wsi->protocol_bind_balance) { + wsi->a.protocol->callback(wsi, wsi->role_ops->protocol_unbind_cb[!!lwsi_role_server(wsi)], wsi->user_space, (void *)reason, 0); wsi->protocol_bind_balance = 0; @@ -830,17 +975,17 @@ lws_same_vh_protocol_remove(wsi); - wsi->protocol = p; + wsi->a.protocol = p; if (!p) return 0; if (lws_ensure_user_space(wsi)) return 1; - if (p > vp && p < &vp[wsi->vhost->count_protocols]) + if (p > vp && p < &vp[wsi->a.vhost->count_protocols]) lws_same_vh_protocol_insert(wsi, (int)(p - vp)); else { - int n = wsi->vhost->count_protocols; + int n = wsi->a.vhost->count_protocols; int hit = 0; vpo = vp; @@ -855,10 +1000,10 @@ } if (!hit) lwsl_err("%s: %p is not in vhost '%s' protocols list\n", - __func__, p, wsi->vhost->name); + __func__, p, wsi->a.vhost->name); } - if (wsi->protocol->callback(wsi, wsi->role_ops->protocol_bind_cb[ + if (wsi->a.protocol->callback(wsi, wsi->role_ops->protocol_bind_cb[ !!lwsi_role_server(wsi)], wsi->user_space, NULL, 0)) return 1; @@ -868,20 +1013,405 @@ return 0; } +void +lws_http_close_immortal(struct lws *wsi) +{ + struct lws *nwsi; + + if (!wsi->mux_substream) + return; + + assert(wsi->mux_stream_immortal); + wsi->mux_stream_immortal = 0; + + nwsi = lws_get_network_wsi(wsi); + lwsl_debug("%s: %p %p %d\n", __func__, wsi, nwsi, + nwsi->immortal_substream_count); + assert(nwsi->immortal_substream_count); + nwsi->immortal_substream_count--; + if (!nwsi->immortal_substream_count) + /* + * since we closed the only immortal stream on this nwsi, we + * need to reapply a normal timeout regime to the nwsi + */ + lws_set_timeout(nwsi, PENDING_TIMEOUT_HTTP_KEEPALIVE_IDLE, + wsi->a.vhost->keepalive_timeout ? + wsi->a.vhost->keepalive_timeout : 31); +} + +void +lws_mux_mark_immortal(struct lws *wsi) +{ + struct lws *nwsi; + + lws_set_timeout(wsi, NO_PENDING_TIMEOUT, 0); + + if (!wsi->mux_substream +#if defined(LWS_WITH_CLIENT) + && !wsi->client_mux_substream +#endif + ) { + lwsl_err("%s: not h2 substream\n", __func__); + return; + } + + nwsi = lws_get_network_wsi(wsi); + if (!nwsi) + return; + + lwsl_debug("%s: %p %p %d\n", __func__, wsi, nwsi, + nwsi->immortal_substream_count); + + wsi->mux_stream_immortal = 1; + assert(nwsi->immortal_substream_count < 255); /* largest count */ + nwsi->immortal_substream_count++; + if (nwsi->immortal_substream_count == 1) + lws_set_timeout(nwsi, NO_PENDING_TIMEOUT, 0); +} + + int lws_http_mark_sse(struct lws *wsi) { - lws_http_headers_detach(wsi); - lws_set_timeout(wsi, NO_PENDING_TIMEOUT, 0); + if (!wsi) + return 0; - if (wsi->http2_substream) { - struct lws *nwsi = lws_get_network_wsi(wsi); + lws_http_headers_detach(wsi); + lws_mux_mark_immortal(wsi); + if (wsi->mux_substream) wsi->h2_stream_carries_sse = 1; - nwsi->immortal_substream_count++; - if (nwsi->immortal_substream_count == 1) - lws_set_timeout(nwsi, NO_PENDING_TIMEOUT, 0); + + return 0; +} + +#if defined(LWS_WITH_CLIENT) + +const char * +lws_wsi_client_stash_item(struct lws *wsi, int stash_idx, int hdr_idx) +{ + /* try the generic client stash */ + if (wsi->stash) + return wsi->stash->cis[stash_idx]; + +#if defined(LWS_ROLE_H1) || defined(LWS_ROLE_H2) + /* if not, use the ah stash if applicable */ + return lws_hdr_simple_ptr(wsi, hdr_idx); +#else + return NULL; +#endif +} +#endif + +#if defined(LWS_ROLE_H2) || defined(LWS_ROLE_MQTT) + +void +lws_wsi_mux_insert(struct lws *wsi, struct lws *parent_wsi, int sid) +{ + lwsl_info("%s: wsi %p, par %p: assign sid %d (curr %d)\n", __func__, + wsi, parent_wsi, sid, wsi->mux.my_sid); + + if (wsi->mux.my_sid && wsi->mux.my_sid != (unsigned int)sid) + assert(0); + + wsi->mux.my_sid = sid; + wsi->mux.parent_wsi = parent_wsi; + wsi->role_ops = parent_wsi->role_ops; + + /* new guy's sibling is whoever was the first child before */ + wsi->mux.sibling_list = parent_wsi->mux.child_list; + + /* first child is now the new guy */ + parent_wsi->mux.child_list = wsi; + + parent_wsi->mux.child_count++; +} + +struct lws * +lws_wsi_mux_from_id(struct lws *parent_wsi, unsigned int sid) +{ + lws_start_foreach_ll(struct lws *, wsi, parent_wsi->mux.child_list) { + if (wsi->mux.my_sid == sid) + return wsi; + } lws_end_foreach_ll(wsi, mux.sibling_list); + + return NULL; +} + +void +lws_wsi_mux_dump_children(struct lws *wsi) +{ +#if defined(_DEBUG) + if (!wsi->mux.parent_wsi || !lwsl_visible(LLL_INFO)) + return; + + lws_start_foreach_llp(struct lws **, w, + wsi->mux.parent_wsi->mux.child_list) { + lwsl_info(" \\---- child %s %p\n", + (*w)->role_ops ? (*w)->role_ops->name : "?", *w); + assert(*w != (*w)->mux.sibling_list); + } lws_end_foreach_llp(w, mux.sibling_list); +#endif +} + +void +lws_wsi_mux_close_children(struct lws *wsi, int reason) +{ + struct lws *wsi2; + struct lws **w; + + if (!wsi->mux.child_list) + return; + + w = &wsi->mux.child_list; + while (*w) { + lwsl_info(" closing child %p\n", *w); + /* disconnect from siblings */ + wsi2 = (*w)->mux.sibling_list; + assert (wsi2 != *w); + (*w)->mux.sibling_list = NULL; + (*w)->socket_is_permanently_unusable = 1; + __lws_close_free_wsi(*w, reason, "mux child recurse"); + *w = wsi2; + } +} + + +void +lws_wsi_mux_sibling_disconnect(struct lws *wsi) +{ + struct lws *wsi2; + + lws_start_foreach_llp(struct lws **, w, + wsi->mux.parent_wsi->mux.child_list) { + + /* disconnect from siblings */ + if (*w == wsi) { + wsi2 = (*w)->mux.sibling_list; + (*w)->mux.sibling_list = NULL; + *w = wsi2; + lwsl_debug(" %p disentangled from sibling %p\n", + wsi, wsi2); + break; + } + } lws_end_foreach_llp(w, mux.sibling_list); + wsi->mux.parent_wsi->mux.child_count--; + + wsi->mux.parent_wsi = NULL; +} + +void +lws_wsi_mux_dump_waiting_children(struct lws *wsi) +{ +#if defined(_DEBUG) + lwsl_info("%s: %p: children waiting for POLLOUT service:\n", + __func__, wsi); + + wsi = wsi->mux.child_list; + while (wsi) { + lwsl_info(" %c %p: sid %u: 0x%x %s %s\n", + wsi->mux.requested_POLLOUT ? '*' : ' ', + wsi, wsi->mux.my_sid, lwsi_state(wsi), + wsi->role_ops->name, + wsi->a.protocol ? wsi->a.protocol->name : "noprotocol"); + + wsi = wsi->mux.sibling_list; + } +#endif +} + +int +lws_wsi_mux_mark_parents_needing_writeable(struct lws *wsi) +{ + struct lws /* *network_wsi = lws_get_network_wsi(wsi), */ *wsi2; + //int already = network_wsi->mux.requested_POLLOUT; + + /* mark everybody above him as requesting pollout */ + + wsi2 = wsi; + while (wsi2) { + wsi2->mux.requested_POLLOUT = 1; + lwsl_info("%s: mark wsi: %p, sid %u, pending writable\n", + __func__, wsi2, wsi2->mux.my_sid); + wsi2 = wsi2->mux.parent_wsi; + } + + return 0; // already; +} + +struct lws * +lws_wsi_mux_move_child_to_tail(struct lws **wsi2) +{ + struct lws *w = *wsi2; + + while (w) { + if (!w->mux.sibling_list) { /* w is the current last */ + lwsl_debug("w=%p, *wsi2 = %p\n", w, *wsi2); + + if (w == *wsi2) /* we are already last */ + break; + + /* last points to us as new last */ + w->mux.sibling_list = *wsi2; + + /* guy pointing to us until now points to + * our old next */ + *wsi2 = (*wsi2)->mux.sibling_list; + + /* we point to nothing because we are last */ + w->mux.sibling_list->mux.sibling_list = NULL; + + /* w becomes us */ + w = w->mux.sibling_list; + break; + } + w = w->mux.sibling_list; + } + + /* clear the waiting for POLLOUT on the guy that was chosen */ + + if (w) + w->mux.requested_POLLOUT = 0; + + return w; +} + +int +lws_wsi_mux_action_pending_writeable_reqs(struct lws *wsi) +{ + struct lws *w = wsi->mux.child_list; + + while (w) { + if (w->mux.requested_POLLOUT) { + if (lws_change_pollfd(wsi, 0, LWS_POLLOUT)) + return -1; + return 0; + } + w = w->mux.sibling_list; } + if (lws_change_pollfd(wsi, LWS_POLLOUT, 0)) + return -1; + + return 0; +} + +int +lws_wsi_txc_check_skint(struct lws_tx_credit *txc, int32_t tx_cr) +{ + if (txc->tx_cr <= 0) { + /* + * If other side is not able to cope with us sending any DATA + * so no matter if we have POLLOUT on our side if it's DATA we + * want to send. + */ + + if (!txc->skint) + lwsl_info("%s: %p: skint (%d)\n", __func__, txc, + (int)txc->tx_cr); + + txc->skint = 1; + + return 1; + } + + if (txc->skint) + lwsl_info("%s: %p: unskint (%d)\n", __func__, txc, + (int)txc->tx_cr); + + txc->skint = 0; + return 0; } + +#if defined(_DEBUG) +void +lws_wsi_txc_describe(struct lws_tx_credit *txc, const char *at, uint32_t sid) +{ + lwsl_info("%s: %p: %s: sid %d: %speer-to-us: %d, us-to-peer: %d\n", + __func__, txc, at, (int)sid, txc->skint ? "SKINT, " : "", + (int)txc->peer_tx_cr_est, (int)txc->tx_cr); +} +#endif + +int +lws_wsi_tx_credit(struct lws *wsi, char peer_to_us, int add) +{ + if (wsi->role_ops && wsi->role_ops->tx_credit) + return wsi->role_ops->tx_credit(wsi, peer_to_us, add); + + return 0; +} + +/* + * Let the protocol know about incoming tx credit window updates if it's + * managing the flow control manually (it may want to proxy this information) + */ + +int +lws_wsi_txc_report_manual_txcr_in(struct lws *wsi, int32_t bump) +{ + if (!wsi->txc.manual) + /* + * If we don't care about managing it manually, no need to + * report it + */ + return 0; + + return user_callback_handle_rxflow(wsi->a.protocol->callback, + wsi, LWS_CALLBACK_WSI_TX_CREDIT_GET, + wsi->user_space, NULL, (size_t)bump); +} + +#if defined(LWS_WITH_CLIENT) + +int +lws_wsi_mux_apply_queue(struct lws *wsi) +{ + /* we have a transaction queue that wants to pipeline */ + + lws_vhost_lock(wsi->a.vhost); + + lws_start_foreach_dll_safe(struct lws_dll2 *, d, d1, + wsi->dll2_cli_txn_queue_owner.head) { + struct lws *w = lws_container_of(d, struct lws, + dll2_cli_txn_queue); + +#if defined(LWS_ROLE_H2) + if (lwsi_role_http(wsi) && + lwsi_state(w) == LRS_H2_WAITING_TO_SEND_HEADERS) { + lwsl_info("%s: cli pipeq %p to be h2\n", __func__, w); + + lwsi_set_state(w, LRS_H1C_ISSUE_HANDSHAKE2); + + /* remove ourselves from client queue */ + lws_dll2_remove(&w->dll2_cli_txn_queue); + + /* attach ourselves as an h2 stream */ + lws_wsi_h2_adopt(wsi, w); + } +#endif + +#if defined(LWS_ROLE_MQTT) + if (lwsi_role_mqtt(wsi) && + lwsi_state(wsi) == LRS_ESTABLISHED) { + lwsl_info("%s: cli pipeq %p to be mqtt\n", __func__, w); + + /* remove ourselves from client queue */ + lws_dll2_remove(&w->dll2_cli_txn_queue); + + /* attach ourselves as an h2 stream */ + lws_wsi_mqtt_adopt(wsi, w); + } +#endif + + } lws_end_foreach_dll_safe(d, d1); + + lws_vhost_unlock(wsi->a.vhost); + + return 0; +} + +#endif + +#endif diff -Nru libwebsockets-3.2.1/lib/core-net/wsi-timeout.c libwebsockets-4.1.6/lib/core-net/wsi-timeout.c --- libwebsockets-3.2.1/lib/core-net/wsi-timeout.c 2019-12-18 14:45:31.000000000 +0000 +++ libwebsockets-4.1.6/lib/core-net/wsi-timeout.c 2020-12-01 17:40:26.000000000 +0000 @@ -1,30 +1,33 @@ /* * libwebsockets - small server side websockets and web server implementation * - * Copyright (C) 2010-2019 Andy Green + * Copyright (C) 2010 - 2019 Andy Green * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation: - * version 2.1 of the License. + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to + * deal in the Software without restriction, including without limitation the + * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or + * sell copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: * - * This library is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. * - * You should have received a copy of the GNU Lesser General Public - * License along with this library; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, - * MA 02110-1301 USA + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS + * IN THE SOFTWARE. */ -#include "core/private.h" +#include "private-lib-core.h" void __lws_wsi_remove_from_sul(struct lws *wsi) { - //struct lws_context_per_thread *pt = &wsi->context->pt[(int)wsi->tsi]; + //struct lws_context_per_thread *pt = &wsi->a.context->pt[(int)wsi->tsi]; //lwsl_notice("%s: wsi %p, to %p, hr %p\n", __func__, wsi, // &wsi->sul_timeout.list, &wsi->sul_hrtimer.list); @@ -32,6 +35,7 @@ // lws_dll2_describe(&pt->pt_sul_owner, "pre-remove"); lws_dll2_remove(&wsi->sul_timeout.list); lws_dll2_remove(&wsi->sul_hrtimer.list); + lws_dll2_remove(&wsi->sul_validity.list); // lws_dll2_describe(&pt->pt_sul_owner, "post-remove"); } @@ -44,8 +48,8 @@ { struct lws *wsi = lws_container_of(sul, struct lws, sul_hrtimer); - if (wsi->protocol && - wsi->protocol->callback(wsi, LWS_CALLBACK_TIMER, + if (wsi->a.protocol && + wsi->a.protocol->callback(wsi, LWS_CALLBACK_TIMER, wsi->user_space, NULL, 0)) __lws_close_free_wsi(wsi, LWS_CLOSE_STATUS_NOSTATUS, "hrtimer cb errored"); @@ -54,13 +58,14 @@ void __lws_set_timer_usecs(struct lws *wsi, lws_usec_t us) { - struct lws_context_per_thread *pt = &wsi->context->pt[(int)wsi->tsi]; + struct lws_context_per_thread *pt = &wsi->a.context->pt[(int)wsi->tsi]; wsi->sul_hrtimer.cb = lws_sul_hrtimer_cb; - __lws_sul_insert(&pt->pt_sul_owner, &wsi->sul_hrtimer, us); + __lws_sul_insert_us(&pt->pt_sul_owner[LWSSULLI_MISS_IF_SUSPENDED], + &wsi->sul_hrtimer, us); } -LWS_VISIBLE void +void lws_set_timer_usecs(struct lws *wsi, lws_usec_t usecs) { __lws_set_timer_usecs(wsi, usecs); @@ -74,7 +79,7 @@ lws_sul_wsitimeout_cb(lws_sorted_usec_list_t *sul) { struct lws *wsi = lws_container_of(sul, struct lws, sul_timeout); - struct lws_context_per_thread *pt = &wsi->context->pt[(int)wsi->tsi]; + struct lws_context_per_thread *pt = &wsi->a.context->pt[(int)wsi->tsi]; if (wsi->pending_timeout != PENDING_TIMEOUT_USER_OK) lws_stats_bump(pt, LWSSTATS_C_TIMEOUTS, 1); @@ -107,23 +112,26 @@ * don't try to do protocol cleanup like flush partials. */ wsi->socket_is_permanently_unusable = 1; -#if !defined(LWS_NO_CLIENT) +#if defined(LWS_WITH_CLIENT) if (lwsi_state(wsi) == LRS_WAITING_SSL) lws_inform_client_conn_fail(wsi, (void *)"Timed out waiting SSL", 21); #endif + lws_pt_lock(pt, __func__); __lws_close_free_wsi(wsi, LWS_CLOSE_STATUS_NOSTATUS, "timeout"); + lws_pt_unlock(pt); } void __lws_set_timeout(struct lws *wsi, enum pending_timeout reason, int secs) { - struct lws_context_per_thread *pt = &wsi->context->pt[(int)wsi->tsi]; + struct lws_context_per_thread *pt = &wsi->a.context->pt[(int)wsi->tsi]; wsi->sul_timeout.cb = lws_sul_wsitimeout_cb; - __lws_sul_insert(&pt->pt_sul_owner, &wsi->sul_timeout, - ((lws_usec_t)secs) * LWS_US_PER_SEC); + __lws_sul_insert_us(&pt->pt_sul_owner[LWSSULLI_MISS_IF_SUSPENDED], + &wsi->sul_timeout, + ((lws_usec_t)secs) * LWS_US_PER_SEC); lwsl_debug("%s: %p: %d secs, reason %d\n", __func__, wsi, secs, reason); @@ -133,17 +141,19 @@ void lws_set_timeout(struct lws *wsi, enum pending_timeout reason, int secs) { - struct lws_context_per_thread *pt = &wsi->context->pt[(int)wsi->tsi]; + struct lws_context_per_thread *pt = &wsi->a.context->pt[(int)wsi->tsi]; + lws_context_lock(pt->context, __func__); lws_pt_lock(pt, __func__); lws_dll2_remove(&wsi->sul_timeout.list); lws_pt_unlock(pt); if (!secs) - return; + goto bail; if (secs == LWS_TO_KILL_SYNC) { lwsl_debug("synchronously killing %p\n", wsi); + lws_context_unlock(pt->context); lws_close_free_wsi(wsi, LWS_CLOSE_STATUS_NOSTATUS, "to sync kill"); return; @@ -152,15 +162,22 @@ if (secs == LWS_TO_KILL_ASYNC) secs = 0; + // assert(!secs || !wsi->mux_stream_immortal); + if (secs && wsi->mux_stream_immortal) + lwsl_err("%s: on immortal stream %d %d\n", __func__, reason, secs); + lws_pt_lock(pt, __func__); __lws_set_timeout(wsi, reason, secs); lws_pt_unlock(pt); + +bail: + lws_context_unlock(pt->context); } void lws_set_timeout_us(struct lws *wsi, enum pending_timeout reason, lws_usec_t us) { - struct lws_context_per_thread *pt = &wsi->context->pt[(int)wsi->tsi]; + struct lws_context_per_thread *pt = &wsi->a.context->pt[(int)wsi->tsi]; lws_pt_lock(pt, __func__); lws_dll2_remove(&wsi->sul_timeout.list); @@ -170,7 +187,8 @@ return; lws_pt_lock(pt, __func__); - __lws_sul_insert(&pt->pt_sul_owner, &wsi->sul_timeout, us); + __lws_sul_insert_us(&pt->pt_sul_owner[LWSSULLI_MISS_IF_SUSPENDED], + &wsi->sul_timeout, us); lwsl_notice("%s: %p: %llu us, reason %d\n", __func__, wsi, (unsigned long long)us, reason); @@ -179,6 +197,8 @@ lws_pt_unlock(pt); } +#if defined(LWS_WITH_DEPRECATED_THINGS) + /* requires context + vh lock */ int @@ -203,23 +223,21 @@ { struct lws_timed_vh_protocol *tvp = lws_container_of(sul, struct lws_timed_vh_protocol, sul); - struct lws_context_per_thread *pt = - &tvp->vhost->context->pt[tvp->tsi_req]; - - pt->fake_wsi->context = tvp->vhost->context; + lws_fakewsi_def_plwsa(&tvp->vhost->context->pt[0]); - pt->fake_wsi->vhost = tvp->vhost; /* not a real bound wsi */ - pt->fake_wsi->protocol = tvp->protocol; + lws_fakewsi_prep_plwsa_ctx(tvp->vhost->context); + plwsa->vhost = tvp->vhost; /* not a real bound wsi */ + plwsa->protocol = tvp->protocol; lwsl_debug("%s: timed cb: vh %s, protocol %s, reason %d\n", __func__, tvp->vhost->name, tvp->protocol->name, tvp->reason); - tvp->protocol->callback(pt->fake_wsi, tvp->reason, NULL, NULL, 0); + tvp->protocol->callback((struct lws *)plwsa, tvp->reason, NULL, NULL, 0); __lws_timed_callback_remove(tvp->vhost, tvp); } -LWS_VISIBLE LWS_EXTERN int +int lws_timed_callback_vh_protocol_us(struct lws_vhost *vh, const struct lws_protocols *prot, int reason, lws_usec_t us) @@ -259,7 +277,7 @@ return 0; } -LWS_VISIBLE LWS_EXTERN int +int lws_timed_callback_vh_protocol(struct lws_vhost *vh, const struct lws_protocols *prot, int reason, int secs) @@ -267,3 +285,89 @@ return lws_timed_callback_vh_protocol_us(vh, prot, reason, ((lws_usec_t)secs) * LWS_US_PER_SEC); } + +#endif + +static void +lws_validity_cb(lws_sorted_usec_list_t *sul) +{ + struct lws *wsi = lws_container_of(sul, struct lws, sul_validity); + struct lws_context_per_thread *pt = &wsi->a.context->pt[(int)wsi->tsi]; + const lws_retry_bo_t *rbo = wsi->retry_policy; + + /* one of either the ping or hangup validity threshold was crossed */ + + if (wsi->validity_hup) { + lwsl_info("%s: wsi %p: validity too old\n", __func__, wsi); + __lws_close_free_wsi(wsi, LWS_CLOSE_STATUS_NOSTATUS, + "validity timeout"); + return; + } + + /* schedule a protocol-dependent ping */ + + lwsl_info("%s: wsi %p: scheduling validity check\n", __func__, wsi); + + if (wsi->role_ops && wsi->role_ops->issue_keepalive) + wsi->role_ops->issue_keepalive(wsi, 0); + + /* + * We arrange to come back here after the additional ping to hangup time + * and do the hangup, unless we get validated (by, eg, a PONG) and + * reset the timer + */ + + assert(rbo->secs_since_valid_hangup > rbo->secs_since_valid_ping); + + wsi->validity_hup = 1; + __lws_sul_insert_us(&pt->pt_sul_owner[!!wsi->conn_validity_wakesuspend], + &wsi->sul_validity, + ((uint64_t)rbo->secs_since_valid_hangup - + rbo->secs_since_valid_ping) * LWS_US_PER_SEC); +} + +/* + * The role calls this back to actually confirm validity on a particular wsi + * (which may not be the original wsi) + */ + +void +_lws_validity_confirmed_role(struct lws *wsi) +{ + struct lws_context_per_thread *pt = &wsi->a.context->pt[(int)wsi->tsi]; + const lws_retry_bo_t *rbo = wsi->retry_policy; + + if (!rbo || !rbo->secs_since_valid_hangup) + return; + + wsi->validity_hup = 0; + wsi->sul_validity.cb = lws_validity_cb; + + wsi->validity_hup = rbo->secs_since_valid_ping >= + rbo->secs_since_valid_hangup; + + lwsl_info("%s: wsi %p: setting validity timer %ds (hup %d)\n", + __func__, wsi, + wsi->validity_hup ? rbo->secs_since_valid_hangup : + rbo->secs_since_valid_ping, + wsi->validity_hup); + + __lws_sul_insert_us(&pt->pt_sul_owner[!!wsi->conn_validity_wakesuspend], + &wsi->sul_validity, + ((uint64_t)(wsi->validity_hup ? + rbo->secs_since_valid_hangup : + rbo->secs_since_valid_ping)) * LWS_US_PER_SEC); +} + +void +lws_validity_confirmed(struct lws *wsi) +{ + /* + * This may be a stream inside a muxed network connection... leave it + * to the role to figure out who actually needs to understand their + * validity was confirmed. + */ + if (!wsi->h2_stream_carries_ws && /* only if not encapsulated */ + wsi->role_ops && wsi->role_ops->issue_keepalive) + wsi->role_ops->issue_keepalive(wsi, 1); +} diff -Nru libwebsockets-3.2.1/lib/drivers/button/lws-button.c libwebsockets-4.1.6/lib/drivers/button/lws-button.c --- libwebsockets-3.2.1/lib/drivers/button/lws-button.c 1970-01-01 00:00:00.000000000 +0000 +++ libwebsockets-4.1.6/lib/drivers/button/lws-button.c 2020-12-01 17:40:26.000000000 +0000 @@ -0,0 +1,532 @@ +/* + * Generic GPIO / irq buttons + * + * Copyright (C) 2019 - 2020 Andy Green + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to + * deal in the Software without restriction, including without limitation the + * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or + * sell copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS + * IN THE SOFTWARE. + */ +#include "private-lib-core.h" + +typedef enum lws_button_classify_states { + LBCS_IDLE, /* nothing happening */ + LBCS_MIN_DOWN_QUALIFY, + + LBCS_ASSESS_DOWN_HOLD, + LBCS_UP_SETTLE1, + LBCS_WAIT_DOUBLECLICK, + LBCS_MIN_DOWN_QUALIFY2, + + LBCS_WAIT_UP, + LBCS_UP_SETTLE2, +} lws_button_classify_states_t; + +/* + * This is the opaque, allocated, non-const, dynamic footprint of the + * button controller + */ + +typedef struct lws_button_state { +#if defined(LWS_PLAT_TIMER_TYPE) + LWS_PLAT_TIMER_TYPE timer; /* bh timer */ + LWS_PLAT_TIMER_TYPE timer_mon; /* monitor timer */ +#endif + const lws_button_controller_t *controller; + struct lws_context *ctx; + short mon_refcount; + lws_button_idx_t enable_bitmap; + lws_button_idx_t state_bitmap; + + uint16_t mon_timer_count; + /* incremented each time the mon timer cb happens */ + + /* lws_button_each_t per button overallocated after this */ +} lws_button_state_t; + +typedef struct lws_button_each { + lws_button_state_t *bcs; + uint16_t mon_timer_comp; + uint16_t mon_timer_repeat; + uint8_t state; + /**^ lws_button_classify_states_t */ + uint8_t isr_pending; +} lws_button_each_t; + +#if defined(LWS_PLAT_TIMER_START) +static const lws_button_regime_t default_regime = { + .ms_min_down = 20, + .ms_min_down_longpress = 300, + .ms_up_settle = 20, + .ms_doubleclick_grace = 120, + .flags = LWSBTNRGMFLAG_CLASSIFY_DOUBLECLICK +}; +#endif + + +/* + * This is happening in interrupt context, we have to schedule a bottom half to + * do the foreground lws_smd queueing, using, eg, a platform timer. + * + * All the buttons point here and use one timer per button controller. An + * interrupt here means, "something happened to one or more buttons" + */ +#if defined(LWS_PLAT_TIMER_START) +void +lws_button_irq_cb_t(void *arg) +{ + lws_button_each_t *each = (lws_button_each_t *)arg; + + each->isr_pending = 1; + LWS_PLAT_TIMER_START(each->bcs->timer); +} +#endif + +/* + * This is the bottom-half scheduled via a timer set in the ISR. From here we + * are allowed to hold mutexes etc. We are coming here because any button + * interrupt arrived, we have to run another timer that tries to put whatever is + * observed on any active button into context and either discard it or arrive at + * a definitive event classification. + */ + +#if defined(LWS_PLAT_TIMER_CB) +static LWS_PLAT_TIMER_CB(lws_button_bh, th) +{ + lws_button_state_t *bcs = LWS_PLAT_TIMER_CB_GET_OPAQUE(th); + lws_button_each_t *each = (lws_button_each_t *)&bcs[1]; + const lws_button_controller_t *bc = bcs->controller; + size_t n; + + /* + * The ISR and bottom-half is shared by all the buttons. Each gpio + * IRQ has an individual opaque ptr pointing to the corresponding + * button's dynamic lws_button_each_t, the ISR marks the button's + * each->isr_pending and schedules this bottom half. + * + * So now the bh timer has fired and something to do, we need to go + * through all the buttons that have isr_pending set and service their + * state. Intermediate states should start / bump the refcount on the + * mon timer. That's refcounted so it only runs when a button down. + */ + + for (n = 0; n < bc->count_buttons; n++) { + + if (!each[n].isr_pending) + continue; + + /* + * Hide what we're about to do from the delicate eyes of the + * IRQ controller... + */ + + bc->gpio_ops->irq_mode(bc->button_map[n].gpio, + LWSGGPIO_IRQ_NONE, NULL, NULL); + + each[n].isr_pending = 0; + + /* + * Force the network around the switch to the + * active level briefly + */ + + bc->gpio_ops->set(bc->button_map[n].gpio, + !!(bc->active_state_bitmap & (1 << n))); + bc->gpio_ops->mode(bc->button_map[n].gpio, LWSGGPIO_FL_WRITE); + + if (each[n].state == LBCS_IDLE) { + /* + * If this is the first sign something happening on this + * button, make sure the monitor timer is running to + * classify its response over time + */ + + each[n].state = LBCS_MIN_DOWN_QUALIFY; + each[n].mon_timer_comp = bcs->mon_timer_count; + + if (!bcs->mon_refcount++) { +#if defined(LWS_PLAT_TIMER_START) + LWS_PLAT_TIMER_START(bcs->timer_mon); +#endif + } + } + + /* + * Just for a us or two inbetween here, we're driving it to the + * level we were informed by the interrupt it had enetered, to + * force to charge on the actual and parasitic network around + * the switch to a deterministic-ish state. + * + * If the switch remains in that state, well, it makes no + * difference; if it was a pre-contact and the charge on the + * network was left indeterminate, this will dispose it to act + * consistently in the short term until the pullup / pulldown + * has time to act on it or the switch comes and forces the + * network charge state itself. + */ + bc->gpio_ops->mode(bc->button_map[n].gpio, LWSGGPIO_FL_READ); + + /* + * We could do a better job manipulating the irq mode according + * to the switch state. But if an interrupt comes and we have + * done that, we can't tell if it's from before or after the + * mode change... ie, we don't know what the interrupt was + * telling us. We can't trust the gpio state if we read it now + * to be related to what the irq from some time before was + * trying to tell us. So always set it back to the same mode + * and accept the limitation. + */ + + bc->gpio_ops->irq_mode(bc->button_map[n].gpio, + bc->active_state_bitmap & (1 << n) ? + LWSGGPIO_IRQ_RISING : + LWSGGPIO_IRQ_FALLING, + lws_button_irq_cb_t, &each[n]); + } +} +#endif + +#if defined(LWS_PLAT_TIMER_CB) +static LWS_PLAT_TIMER_CB(lws_button_mon, th) +{ + lws_button_state_t *bcs = LWS_PLAT_TIMER_CB_GET_OPAQUE(th); + lws_button_each_t *each = (lws_button_each_t *)&bcs[1]; + const lws_button_controller_t *bc = bcs->controller; + const lws_button_regime_t *regime; + const char *event_name; + int comp_age_ms; + char active; + size_t n; + + bcs->mon_timer_count++; + + for (n = 0; n < bc->count_buttons; n++) { + + if (each->state == LBCS_IDLE) { + each++; + continue; + } + + if (bc->button_map[n].regime) + regime = bc->button_map[n].regime; + else + regime = &default_regime; + + comp_age_ms = (bcs->mon_timer_count - each->mon_timer_comp) * + LWS_BUTTON_MON_TIMER_MS; + + active = bc->gpio_ops->read(bc->button_map[n].gpio) ^ + (!(bc->active_state_bitmap & (1 << n))); + + // lwsl_notice("%d\n", each->state); + + switch (each->state) { + case LBCS_MIN_DOWN_QUALIFY: + /* + * We're trying to figure out if the initial down event + * is a glitch, or if it meets the criteria for being + * treated as the definitive start of some kind of click + * action. To get past this, he has to be solidly down + * for the time mentioned in the applied regime (at + * least when we sample it). + * + * Significant bounce at the start will abort this try, + * but if it's really down there will be a subsequent + * solid down period... it will simply restart this flow + * from a new interrupt and pass the filter then. + * + * The "brief drive on edge" strategy considerably + * reduces inconsistencies here. But physical bounce + * will continue to be observed. + */ + + if (!active) { + /* We ignore stuff for a bit after discard */ + each->mon_timer_comp = bcs->mon_timer_count; + each->state = LBCS_UP_SETTLE2; + break; + } + + if (comp_age_ms >= regime->ms_min_down) { + + /* We made it through the initial regime filter, + * the next step is wait and see if this down + * event evolves into a single/double click or + * we can call it as a long-click + */ + + each->mon_timer_repeat = bcs->mon_timer_count; + each->state = LBCS_ASSESS_DOWN_HOLD; + event_name = "down"; + goto emit; + } + break; + + case LBCS_ASSESS_DOWN_HOLD: + + /* + * How long is he going to hold it? If he holds it + * past the long-click threshold, we can call it as a + * long-click and do the up processing afterwards. + */ + if (comp_age_ms >= regime->ms_min_down_longpress) { + /* call it as a longclick */ + event_name = "longclick"; + each->state = LBCS_WAIT_UP; + goto emit; + } + + if (!active) { + /* + * He didn't hold it past the long-click + * threshold... we could end up classifying it + * as either a click or a double-click then. + * + * If double-clicks are not allowed to be + * classified, then we can already classify it + * as a single-click. + */ + if (!(regime->flags & + LWSBTNRGMFLAG_CLASSIFY_DOUBLECLICK)) + goto classify_single; + + /* + * Just wait for the up settle time then start + * looking for a second down. + */ + each->mon_timer_comp = bcs->mon_timer_count; + each->state = LBCS_UP_SETTLE1; + event_name = "up"; + goto emit; + } + + goto stilldown; + + case LBCS_UP_SETTLE1: + if (comp_age_ms > regime->ms_up_settle) + /* + * Just block anything for the up settle time + */ + each->state = LBCS_WAIT_DOUBLECLICK; + break; + + case LBCS_WAIT_DOUBLECLICK: + if (active) { + /* + * He has gone down again inside the regime's + * doubleclick grace period... he's going down + * the double-click path + */ + each->mon_timer_comp = bcs->mon_timer_count; + each->state = LBCS_MIN_DOWN_QUALIFY2; + break; + } + + if (comp_age_ms >= regime->ms_doubleclick_grace) { + /* + * The grace period expired, the second click + * was either not forthcoming at all, or coming + * quick enough to count: we classify it as a + * single-click + */ + + goto classify_single; + } + break; + + case LBCS_MIN_DOWN_QUALIFY2: + if (!active) { + + /* + * He went up again too quickly, classify it + * as a single-click. It could be bounce in + * which case you might want to increase the + * ms_up_settle in the regime + */ +classify_single: + event_name = "click"; + each->mon_timer_comp = bcs->mon_timer_count; + each->state = LBCS_UP_SETTLE2; + goto emit; + } + + if (comp_age_ms == regime->ms_min_down) { + event_name = "down"; + goto emit; + } + + if (comp_age_ms > regime->ms_min_down) { + /* + * It's a double-click + */ + event_name = "doubleclick"; + each->state = LBCS_WAIT_UP; + goto emit; + } + break; + + case LBCS_WAIT_UP: + if (!active) { + /* + * He has stopped pressing it + */ + each->mon_timer_comp = bcs->mon_timer_count; + each->state = LBCS_UP_SETTLE2; + event_name = "up"; + goto emit; + } +stilldown: + if (regime->ms_repeat_down && + (bcs->mon_timer_count - each->mon_timer_repeat) * + LWS_BUTTON_MON_TIMER_MS > regime->ms_repeat_down) { + each->mon_timer_repeat = bcs->mon_timer_count; + event_name = "stilldown"; + goto emit; + } + break; + + case LBCS_UP_SETTLE2: + if (comp_age_ms < regime->ms_up_settle) + break; + + each->state = LBCS_IDLE; + if (!(--bcs->mon_refcount)) { +#if defined(LWS_PLAT_TIMER_STOP) + LWS_PLAT_TIMER_STOP(bcs->timer_mon); +#endif + } + } + + each++; + continue; + +emit: + lws_smd_msg_printf(bcs->ctx, LWSSMDCL_INTERACTION, + "{\"type\":\"button\"," + "\"src\":\"%s/%s\",\"event\":\"%s\"}", + bc->smd_bc_name, + bc->button_map[n].smd_interaction_name, + event_name); + + each++; + } +} +#endif + +struct lws_button_state * +lws_button_controller_create(struct lws_context *ctx, + const lws_button_controller_t *controller) +{ + lws_button_state_t *bcs = lws_zalloc(sizeof(lws_button_state_t) + + (controller->count_buttons * sizeof(lws_button_each_t)), + __func__); + lws_button_each_t *each = (lws_button_each_t *)&bcs[1]; + size_t n; + + if (!bcs) + return NULL; + + bcs->controller = controller; + bcs->ctx = ctx; + + for (n = 0; n < controller->count_buttons; n++) + each[n].bcs = bcs; + +#if defined(LWS_PLAT_TIMER_CREATE) + /* this only runs inbetween a gpio ISR and the bottom half */ + bcs->timer = LWS_PLAT_TIMER_CREATE("bcst", + 1, 0, bcs, (TimerCallbackFunction_t)lws_button_bh); + if (!bcs->timer) + return NULL; + + /* this only runs when a button activity is being classified */ + bcs->timer_mon = LWS_PLAT_TIMER_CREATE("bcmon", LWS_BUTTON_MON_TIMER_MS, + 1, bcs, (TimerCallbackFunction_t) + lws_button_mon); + if (!bcs->timer_mon) + return NULL; +#endif + + return bcs; +} + +void +lws_button_controller_destroy(struct lws_button_state *bcs) +{ + /* disable them all */ + lws_button_enable(bcs, 0, 0); + +#if defined(LWS_PLAT_TIMER_DELETE) + LWS_PLAT_TIMER_DELETE(&bcs->timer); + LWS_PLAT_TIMER_DELETE(&bcs->timer_mon); +#endif + + lws_free(bcs); +} + +lws_button_idx_t +lws_button_get_bit(struct lws_button_state *bcs, const char *name) +{ + const lws_button_controller_t *bc = bcs->controller; + int n; + + for (n = 0; n < bc->count_buttons; n++) + if (!strcmp(name, bc->button_map[n].smd_interaction_name)) + return 1 << n; + + return 0; /* not found */ +} + +void +lws_button_enable(lws_button_state_t *bcs, + lws_button_idx_t _reset, lws_button_idx_t _set) +{ + lws_button_idx_t u = (bcs->enable_bitmap & (~_reset)) | _set; + const lws_button_controller_t *bc = bcs->controller; +#if defined(LWS_PLAT_TIMER_START) + lws_button_each_t *each = (lws_button_each_t *)&bcs[1]; +#endif + int n; + + for (n = 0; n < bcs->controller->count_buttons; n++) { + if (!(bcs->enable_bitmap & (1 << n)) && (u & (1 << n))) { + /* set as input with pullup or pulldown appropriately */ + bc->gpio_ops->mode(bc->button_map[n].gpio, + LWSGGPIO_FL_READ | + ((bc->active_state_bitmap & (1 << n)) ? + LWSGGPIO_FL_PULLDOWN : LWSGGPIO_FL_PULLUP)); +#if defined(LWS_PLAT_TIMER_START) + /* + * This one is becoming enabled... the opaque for the + * ISR is the indvidual lws_button_each_t, they all + * point to the same ISR + */ + bc->gpio_ops->irq_mode(bc->button_map[n].gpio, + bc->active_state_bitmap & (1 << n) ? + LWSGGPIO_IRQ_RISING : + LWSGGPIO_IRQ_FALLING, + lws_button_irq_cb_t, &each[n]); +#endif + } + if ((bcs->enable_bitmap & (1 << n)) && !(u & (1 << n))) + /* this one is becoming disabled */ + bc->gpio_ops->irq_mode(bc->button_map[n].gpio, + LWSGGPIO_IRQ_NONE, NULL, NULL); + } + + bcs->enable_bitmap = u; +} diff -Nru libwebsockets-3.2.1/lib/drivers/button/README.md libwebsockets-4.1.6/lib/drivers/button/README.md --- libwebsockets-3.2.1/lib/drivers/button/README.md 1970-01-01 00:00:00.000000000 +0000 +++ libwebsockets-4.1.6/lib/drivers/button/README.md 2020-12-01 17:40:26.000000000 +0000 @@ -0,0 +1,156 @@ +# LWS GPIO Button class drivers + +Lws provides an GPIO button controller class, this centralizes handling a set of +up to 31 buttons for resource efficiency. Each controller has two OS timers, +one for interrupt to bottom-half event triggering and another that runs at 5ms +intervals only when one or more button is down. + +Each button has its own active level control and sophisticated state tracking; +each button can apply its own classification regime, to allow for different +physical button characteristics, if not overridden a default one is provided. + +Both the controller and individual buttons specify names that are used in the +JSON events produced when the buttons perform actions. + +## Button electronic to logical event processing + +Buttons are monitored using GPIO interrupts since this is very cheap in the +usual case no interaction is ongoing. There is assumed to be one interrupt +per GPIO, but they are pointed at the same ISR, with an opaque pointer to an +internal struct passed per-interrupt to differentiate them and bind them to a +particular button. + +The interrupt is set for notification of the active-going edge, usually if +the button is pulled-up, that's the downgoing edge only. This avoids any +ambiguity about the interrupt meaning, although oscillation is common around +the transition region when the signal is becoming inactive too. + +An OS timer is used to schedule a bottom-half handler outside of interrupt +context. + +To combat commonly-seen partial charging of the actual and parasitic network +around the button causing drift and oscillation, the bottom-half briefly drives +the button signal to the active level, forcing a more deterministic charge level +if it reached the point the interrupt was triggered. This removes much of the +unpredictable behaviour in the us range. It would be better done in the ISR +but many OS apis cannot perform GPIO operations in interrupt context. + +The bottom-half makes sure a monitoring timer is enabled, by refcount. This +is the engine of the rest of the classification while any button is down. The +monitoring timer happens per OS tick or 5ms, whichever is longer. + +## Declaring button controllers + +An array of button map elements if provided first mapping at least GPIOs to +button names, and also optionally the classification regime for that button. + +Then the button controller definition which points back to the button map. + +``` +static const lws_button_map_t bcm[] = { + { + .gpio = GPIO_NUM_0, + .smd_interaction_name = "user" + }, +}; + +static const lws_button_controller_t bc = { + .smd_bc_name = "bc", + .gpio_ops = &lws_gpio_plat, + .button_map = &bcm[0], + .active_state_bitmap = 0, + .count_buttons = LWS_ARRAY_SIZE(bcm), +}; + + struct lws_button_state *bcs; + + bcs = lws_button_controller_create(context, &bc); + if (!bcs) { + lwsl_err("%s: could not create buttons\n", __func__); + goto spin; + } +``` + +That is all that is needed for init, button events will be issued on lws_smd +when buttons are pressed. + +### Regime settings + +The classification regime is designed to reflect both the user interaction +style and the characteristics of a particular type of button. + +Member|Default|Meaning +---|---|--- +ms_min_down|20ms|Down events shorter than this are ignored +ms_min_down_longpress|300ms|Down events longer than this are reported as a long-click +ms_up_settle|20ms|After the first indication a button is no longer down, the button is ignored for this interval +ms_doubleclick_grace|120ms|The time allowed after a click to see if a second, double-click, is forthcoming +ms_repeat_down|0 / disabled|If held down, interval at which to issue `stilldown` events +flags|LWSBTNRGMFLAG_CLASSIFY_DOUBLECLICK|Control which classifications can apply + +### lws_smd System Message Distribution Events + +The button controller emits system messages of class `LWSSMDCL_INTERACTION`, +using a JSON formatted payload + +``` +{ + "type": "button", + "src": "controller-name/button-name", + "event": "event-name" +} +``` + +For example, `{"type":"button","src":"bc/user","event":"doubleclick"}` + +JSON is used because it is maintainable, extensible, self-documenting and does +not require a central, fragile-against-versioning specification of mappings. +Using button names allows the same code to adapt to different hardware or +button mappings. Button events may be synthesized for test or other purposes +cleanly and clearly. + +All the events are somewhat filtered, too short glitches from EMI or whatever +are not reported. "up" and "down" events are reported for the buttons in case +the intention is the duration of the press is meaningful to the user code, but +more typically the user code wants to consume a higher-level classification of +the interaction, eg, that it can be understood as a single "double-click" event. + +Event name|Meaning +---|--- +down|The button passes a filter for being down, useful for duration-based response +stilldown|The regime can be configured to issue "repeat" notifications at intervals +up|The button has come up, useful for duration-based response +click|The button activity resulted in a classification as a single-click +longclick|The button activity resulted in a classification as a long-click +doubleclick|The button activity resulted in a classification as a double-click + +Since double-click detection requires delaying click reporting until it becomes +clear a second click isn't coming, it is enabled as a possible classification in +the regime structure and the regime structure chosen per-button. + +Typically user code is interested in, eg, a high level classification of what +the button is doing, eg, a "click" event on a specific button. Rather than +perform a JSON parse, these events can be processed as strings cheaply using +`lws_json_simple_strcmp()`, it's dumb enough to be cheap but smart enough to +understand enough JSON semantics to be accurate, while retaining the ability to +change and extend the JSON, eg + +``` + if (!lws_json_simple_strcmp(buf, len, "\"src\":", "bc/user")) { + if (!lws_json_simple_strcmp(buf, len, "\"event\":", "click")) { + ... + } + ... + } +``` + +### Relationship between up / down and classification + +Classification|Sequencing +---|--- +click|down-up-click (it's classified when it went up and cannot be a longclick) +longclick|down-longclick-up (it's classified while still down) +doubleclick|down-up-down-doubleclick-up (classified as soon as second click down long enough) + +If the regime is configured for it, any "down" may be followed by one or more +"stilldown" at intervals if the button is down long enough diff -Nru libwebsockets-3.2.1/lib/drivers/CMakeLists.txt libwebsockets-4.1.6/lib/drivers/CMakeLists.txt --- libwebsockets-3.2.1/lib/drivers/CMakeLists.txt 1970-01-01 00:00:00.000000000 +0000 +++ libwebsockets-4.1.6/lib/drivers/CMakeLists.txt 2020-12-01 17:40:26.000000000 +0000 @@ -0,0 +1,30 @@ +list(APPEND SOURCES + drivers/display/lws-display.c + drivers/display/ssd1306-i2c.c + drivers/display/ili9341-spi.c + drivers/i2c/lws-i2c.c + drivers/i2c/bitbang/lws-bb-i2c.c + drivers/spi/lws-spi.c + drivers/spi/bitbang/lws-bb-spi.c + drivers/button/lws-button.c + drivers/led/led-gpio.c + drivers/led/led-seq.c + drivers/pwm/pwm.c + drivers/settings/settings.c +) + +if (LWS_WITH_NETWORK) + list(APPEND SOURCES + drivers/netdev/netdev.c + drivers/netdev/wifi.c) +endif() + +if (LWS_ESP_PLATFORM) + list(APPEND SOURCES + plat/freertos/esp32/drivers/gpio-esp32.c + plat/freertos/esp32/drivers/pwm-esp32.c + ) +endif() + +exports_to_parent_scope() + diff -Nru libwebsockets-3.2.1/lib/drivers/devices/display/ili9341.h libwebsockets-4.1.6/lib/drivers/devices/display/ili9341.h --- libwebsockets-3.2.1/lib/drivers/devices/display/ili9341.h 1970-01-01 00:00:00.000000000 +0000 +++ libwebsockets-4.1.6/lib/drivers/devices/display/ili9341.h 2020-12-01 17:40:26.000000000 +0000 @@ -0,0 +1,95 @@ +/* + * Private register map for ILI9341 + * + * Copyright (C) 2019 - 2020 Andy Green + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to + * deal in the Software without restriction, including without limitation the + * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or + * sell copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS + * IN THE SOFTWARE. + * + */ + +#if !defined(__LWS_ILI9341_H__) +#define __LWS_ILI9341_H__ + +enum { + + ILI9341_NOP = 0x00, + ILI9341_SWRESET = 0x01, + ILI9341_RDDID = 0x04, + ILI9341_RDDST = 0x09, + + ILI9341_SLPIN = 0x10, + ILI9341_SLPOUT = 0x11, + ILI9341_PTLON = 0x12, + ILI9341_NORON = 0x13, + + ILI9341_RDMODE = 0x0a, + ILI9341_RDMADCTL = 0x0b, + ILI9341_RDPIXFMT = 0x0c, + ILI9341_RDIMGFMT = 0x0d, + ILI9341_RDSELFDIAG = 0x0f, + + ILI9341_INVOFF = 0x20, + ILI9341_INVON = 0x21, + ILI9341_GAMMASET = 0x26, + ILI9341_DISPOFF = 0x28, + ILI9341_DISPON = 0x29, + ILI9341_CASET = 0x2a, + ILI9341_PASET = 0x2b, + ILI9341_RAMWR = 0x2c, + ILI9341_RAMRD = 0x2e, + + ILI9341_PTLAR = 0x30, + ILI9341_VSCRDEF = 0x33, + ILI9341_MADCTL = 0x36, + ILI9341_VSCRSADD = 0x37, + ILI9341_PIXFMT = 0x3a, + + ILI9341_FRMCTR1 = 0xb1, + ILI9341_FRMCTR2 = 0xb2, + ILI9341_FRMCTR3 = 0xb3, + ILI9341_INVCTR = 0xb4, + ILI9341_DFUNCTR = 0xb6, + + ILI9341_PWCTR1 = 0xc0, + ILI9341_PWCTR2 = 0xc1, + ILI9341_PWCTR3 = 0xc2, + ILI9341_PWCTR4 = 0xc3, + ILI9341_PWCTR5 = 0xc4, + ILI9341_VMCTR1 = 0xc5, + ILI9341_VMCTR2 = 0xc7, + ILI9341_FACPUMPRAT = 0xcb, + ILI9341_FACPWCTRB = 0xcf, + + ILI9341_RDID1 = 0xda, + ILI9341_RDID2 = 0xdb, + ILI9341_RDID3 = 0xdc, + ILI9341_RDID4 = 0xdd, + + ILI9341_GMCTRP1 = 0xe0, + ILI9341_GMCTRN1 = 0xe1, + ILI9341_FACPWCTRA = 0xe8, + ILI9341_FACPWCTR1 = 0xea, + ILI9341_FACDRTIMCTRA = 0xed, + + ILI9341_FACSETGAMMACRV = 0xf2, + ILI9341_FACDRTIMCTR = 0xf7, +}; + +#endif + diff -Nru libwebsockets-3.2.1/lib/drivers/devices/display/ssd1306.h libwebsockets-4.1.6/lib/drivers/devices/display/ssd1306.h --- libwebsockets-3.2.1/lib/drivers/devices/display/ssd1306.h 1970-01-01 00:00:00.000000000 +0000 +++ libwebsockets-4.1.6/lib/drivers/devices/display/ssd1306.h 2020-12-01 17:40:26.000000000 +0000 @@ -0,0 +1,66 @@ +/* + * Private register map for SSD1306 + * + * Copyright (C) 2019 - 2020 Andy Green + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to + * deal in the Software without restriction, including without limitation the + * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or + * sell copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS + * IN THE SOFTWARE. + * + */ + +#if !defined(__LWS_SSD1306_H__) +#define __LWS_SSD1306_H__ + +enum { + SSD1306_SETLOWCOLUMN = 0x00, + SSD1306_SETHIGHCOLUMN = 0x10, + + SSD1306_MEMORYMODE = 0x20, + SSD1306_COLUMNADDR = 0x21, + SSD1306_PAGEADDR = 0x22, + SSD1306_DEACTIVATE_SCROLL = 0x2e, + + SSD1306_SETSTARTLINE = 0x40, + + SSD1306_SETCONTRAST = 0x81, + SSD1306_CHARGEPUMP = 0x8d, + + SSD1306_SEGREMAP = 0xa0, + SSD1306_SETSEGMENTREMAP = 0xa1, + SSD1306_DISPLAYALLON_RESUME = 0xa4, + SSD1306_DISPLAYALLON = 0xa5, + SSD1306_NORMALDISPLAY = 0xa6, + SSD1306_INVERTDISPLAY = 0xa7, + SSD1306_SETMULTIPLEX = 0xa8, + SSD1306_DISPLAYOFF = 0xae, + SSD1306_DISPLAYON = 0xaf, + + SSD1306_COMSCANINC = 0xc0, + SSD1306_COMSCANDEC = 0xc8, + + SSD1306_SETDISPLAYOFFSET = 0xd3, + SSD1306_SETDISPLAYCLOCKDIV = 0xd5, + SSD1306_SETPRECHARGE = 0xd9, + SSD1306_SETCOMPINS = 0xda, + SSD1306_SETVCOMDESELECT = 0xdb, + + SSD1306_NOP = 0xe3, +}; + +#endif + diff -Nru libwebsockets-3.2.1/lib/drivers/display/ili9341-spi.c libwebsockets-4.1.6/lib/drivers/display/ili9341-spi.c --- libwebsockets-3.2.1/lib/drivers/display/ili9341-spi.c 1970-01-01 00:00:00.000000000 +0000 +++ libwebsockets-4.1.6/lib/drivers/display/ili9341-spi.c 2020-12-01 17:40:26.000000000 +0000 @@ -0,0 +1,187 @@ +/* + * lws abstract display implementation for ili9341 on spi + * + * Copyright (C) 2019 - 2020 Andy Green + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to + * deal in the Software without restriction, including without limitation the + * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or + * sell copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS + * IN THE SOFTWARE. + */ + +#include +#include + + +static uint8_t ili9341_320x240_init[] = { + /* + * This provides 70Hz 320x240 at RGB565, we assume im[3:0] is 1110 + * which is 4-bit SPI + */ + + 3, ILI9341_FACPWCTRB, 0x00, 0x83, 0x30, + 4, ILI9341_FACDRTIMCTRA, 0x64, 0x03, 0x12, 0x81, + 3, ILI9341_FACPWCTRA, 0x85, 0x01, 0x79, + 5, ILI9341_FACPUMPRAT, 0x39, 0x2c, 0x00, 0x34, 0x02, + 1, ILI9341_FACDRTIMCTR, 0x20, + 2, ILI9341_FACPWCTR1, 0x00, 0x00, + + 1, ILI9341_PWCTR1, 0x26, + 1, ILI9341_PWCTR2, 0x11, + 2, ILI9341_VMCTR1, 0x35, 0x3e, + 1, ILI9341_VMCTR2, 0xbe, + 1, ILI9341_MADCTL, 0x28, + 1, ILI9341_VSCRSADD, 0x00, + 1, ILI9341_PIXFMT, 0x55, + 2, ILI9341_FRMCTR1, 0x00, 0x1b, + 1, ILI9341_FACSETGAMMACRV, 0x00, + 1, ILI9341_GAMMASET, 0x01, + 15, ILI9341_GMCTRP1, 0x0f, 0x31, 0x2b, 0x0c, 0x0e, 0x08, 0x4e, + 0xf1, 0x37, 0x07, 0x10, 0x03, 0x0e, 0x09, + 0x00, + 15, ILI9341_GMCTRN1, 0x00, 0x0e, 0x14, 0x03, 0x11, 0x07, 0x31, + 0xc1, 0x48, 0x08, 0x0f, 0x0c, 0x31, 0x36, + 0x0f, + 4, ILI9341_DFUNCTR, 0x0a, 0x82, 0x27, 0x00, +}; + +int +lws_display_ili9341_spi_init(const struct lws_display *disp) +{ + const lws_display_ili9341_t *ili = (const lws_display_ili9341_t *)disp; + lws_spi_desc_t desc; + size_t pos = 0; + uint8_t u[8]; + + lwsl_user("%s\n", __func__); + + /* hardware nRESET */ + + if (ili->gpio) { + ili->gpio->mode(ili->reset_gpio, LWSGGPIO_FL_WRITE | + LWSGGPIO_FL_PULLUP); + ili->gpio->set(ili->reset_gpio, 0); + + lws_msleep(1); + ili->gpio->set(ili->reset_gpio, 1); + lws_msleep(1); + } + + /* + * We cut the init table up into transactions... atm we just go with + * the fact that bb spi is synchronous, using async / dma we can't use + * a single desc on the stack like this + */ + + memset(&desc, 0, sizeof(desc)); + desc.count_cmd = 1; + + while (pos < LWS_ARRAY_SIZE(ili9341_320x240_init)) { + desc.count_write = ili9341_320x240_init[pos++]; + desc.src = &ili9341_320x240_init[pos++]; + desc.data = &ili9341_320x240_init[pos]; + pos += desc.count_write; + + ili->spi->queue(ili->spi, &desc); + } + + u[0] = ILI9341_SLPOUT; + desc.src = &u[0]; + desc.count_write = 0; + ili->spi->queue(ili->spi, &desc); + + lws_msleep(5); + + u[0] = ILI9341_DISPON; + ili->spi->queue(ili->spi, &desc); + + return 0; +} + +/* backlight handled by PWM */ + +int +lws_display_ili9341_spi_brightness(const struct lws_display *disp, uint8_t b) +{ + return 0; +} + +int +lws_display_ili9341_spi_blit(const struct lws_display *disp, const uint8_t *src, + lws_display_scalar x, lws_display_scalar y, + lws_display_scalar w, lws_display_scalar h) +{ + const lws_display_ili9341_t *ili = (const lws_display_ili9341_t *)disp; + lws_spi_desc_t desc; + uint8_t u[5]; + + memset(&desc, 0, sizeof(desc)); + desc.count_cmd = 1; + desc.src = &u[0]; + desc.count_write = 0; + + /* + * Blit a line at a time + */ + + while (h--) { + + u[0] = ILI9341_CASET; + desc.data = &u[1]; + u[1] = x; + u[2] = x; + u[3] = w >> 8; + u[4] = w & 0xff; + desc.count_write = 4; + ili->spi->queue(ili->spi, &desc); + + u[0] = ILI9341_PASET; + u[1] = y >> 8; + u[2] = y & 0xff; + u[3] = (y + 1) >> 8; + u[4] = (y + 1) & 0xff; + desc.count_write = 4; + ili->spi->queue(ili->spi, &desc); + + u[0] = ILI9341_RAMWR; + desc.data = src; + desc.count_write = w * 2; + ili->spi->queue(ili->spi, &desc); + src += w * 2; + y++; + } + + return 0; +} + +int +lws_display_ili9341_spi_power(const struct lws_display *disp, int state) +{ + + const lws_display_ili9341_t *ili = (const lws_display_ili9341_t *)disp; + lws_spi_desc_t desc; + uint8_t u[1]; + + memset(&desc, 0, sizeof(desc)); + desc.count_cmd = 1; + desc.data = desc.src = &u[0]; + u[0] = state ? ILI9341_SLPOUT : ILI9341_SLPIN; + ili->spi->queue(ili->spi, &desc); + + /* we're not going to do anything useful for 5ms after this */ + + return 0; +} diff -Nru libwebsockets-3.2.1/lib/drivers/display/lws-display.c libwebsockets-4.1.6/lib/drivers/display/lws-display.c --- libwebsockets-3.2.1/lib/drivers/display/lws-display.c 1970-01-01 00:00:00.000000000 +0000 +++ libwebsockets-4.1.6/lib/drivers/display/lws-display.c 2020-12-01 17:40:26.000000000 +0000 @@ -0,0 +1,132 @@ +/* + * lws abstract display + * + * Copyright (C) 2019 - 2020 Andy Green + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to + * deal in the Software without restriction, including without limitation the + * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or + * sell copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS + * IN THE SOFTWARE. + */ + +#include + +static void +sul_autodim_cb(lws_sorted_usec_list_t *sul) +{ + lws_display_state_t *lds = lws_container_of(sul, lws_display_state_t, + sul_autodim); + int next_ms = -1; + + /* we fire both to dim and to blank... if already in dim state, blank */ + + switch (lds->state) { + case LWSDISPS_BECOMING_ACTIVE: + lws_display_state_set_brightness(lds, lds->disp->bl_active); + lds->state = LWSDISPS_ACTIVE; + next_ms = lds->autodim_ms; + break; + + case LWSDISPS_ACTIVE: + /* active -> autodimmed */ + lds->state = LWSDISPS_AUTODIMMED; + next_ms = lds->off_ms; + lws_display_state_set_brightness(lds, lds->disp->bl_dim); + break; + + case LWSDISPS_AUTODIMMED: + /* dimmed -> OFF */ + lws_display_state_set_brightness(lds, &lws_pwmseq_static_off); + lds->state = LWSDISPS_GOING_OFF; + next_ms = 600; + break; + + case LWSDISPS_GOING_OFF: + /* off dimming completed, actual display OFF */ + lws_display_state_off(lds); + return; + + default: + return; + } + + if (next_ms >= 0) + lws_sul_schedule(lds->ctx, 0, &lds->sul_autodim, sul_autodim_cb, + next_ms * LWS_US_PER_MS); +} + +void +lws_display_state_init(lws_display_state_t *lds, struct lws_context *ctx, + int dim_ms, int off_ms, struct lws_led_state *bl_lcs, + const lws_display_t *disp) +{ + memset(lds, 0, sizeof(*lds)); + + lds->disp = disp; + lds->ctx = ctx; + lds->autodim_ms = dim_ms; + lds->off_ms = off_ms; + lds->bl_lcs = bl_lcs; + lds->state = LWSDISPS_OFF; + + lws_led_transition(lds->bl_lcs, "backlight", &lws_pwmseq_static_off, + &lws_pwmseq_static_on); + + disp->init(disp); +} + +void +lws_display_state_set_brightness(lws_display_state_t *lds, + const lws_led_sequence_def_t *pwmseq) +{ + lws_led_transition(lds->bl_lcs, "backlight", pwmseq, + lds->disp->bl_transition); +} + +void +lws_display_state_active(lws_display_state_t *lds) +{ + int waiting_ms; + + if (lds->state == LWSDISPS_OFF) { + /* power us up */ + lds->disp->power(lds->disp, 1); + lds->state = LWSDISPS_BECOMING_ACTIVE; + waiting_ms = lds->disp->latency_wake_ms; + } else { + + if (lds->state != LWSDISPS_ACTIVE) + lws_display_state_set_brightness(lds, + lds->disp->bl_active); + + lds->state = LWSDISPS_ACTIVE; + waiting_ms = lds->autodim_ms; + } + + /* reset the autodim timer */ + if (waiting_ms >= 0) + lws_sul_schedule(lds->ctx, 0, &lds->sul_autodim, sul_autodim_cb, + waiting_ms * LWS_US_PER_MS); + +} + +void +lws_display_state_off(lws_display_state_t *lds) +{ + lds->disp->power(lds->disp, 0); + lws_sul_cancel(&lds->sul_autodim); + lds->state = LWSDISPS_OFF; +} diff -Nru libwebsockets-3.2.1/lib/drivers/display/README.md libwebsockets-4.1.6/lib/drivers/display/README.md --- libwebsockets-3.2.1/lib/drivers/display/README.md 1970-01-01 00:00:00.000000000 +0000 +++ libwebsockets-4.1.6/lib/drivers/display/README.md 2020-12-01 17:40:26.000000000 +0000 @@ -0,0 +1,36 @@ +# lws_display + +lws provides a generic "display" object that is independent of the connection +to the display, i2c and spi implementations are provided. + +Its purpose is to provide basic blit, backlight binding to lws_pwm, backlight / +power management and display info like pixels wide and high in a generic way. + +The generic display object `lws_display_t` can be included at the top of a +specific display implementation object, eg, binding it to additional members +to define the actual IO operations to be used, eg, i2c or spi. + +When the display is instantiated, it allocates an additional structure on heap +that contains dynamic information about display state, `lws_display_state_t`. + +## Power state machine + +lws_display objects have convenient power state management using a single lws +sul event loop timer that is managed automatically. + +State|Meaning +---|--- +OFF|The display is in sleep and not showing anything +BECOMING_ACTIVE|The display was asked to come out of sleep and is waiting for .latency_wake_ms befor proceeding to ACTIVE. The backlight if any is off. After the delay, the backlight is sequenced up to `.bl_active` using `.bl_transition` sequencer +ACTIVE|The backlight is ON and the dim timer is running +AUTODIMMED|The dim timer was not told the display was active for `.autodim_ms`, we are at `.bl_dim` brightness. After `.off_ms` we will transition to OFF + +The lws_pwm sequencers are used to provide customizable, smooth transitions for +the backlight, which may be nonlinear. + +## Active notification + +Calling `lws_display_state_active(&lds)` on eg, user interaction causes the +display state to transition to ACTIVE smoothly, taking care of waking the display +and waiting out a display-specific wake period, and sequencing the backlight +transition to active level as specified in the display structure. diff -Nru libwebsockets-3.2.1/lib/drivers/display/ssd1306-i2c.c libwebsockets-4.1.6/lib/drivers/display/ssd1306-i2c.c --- libwebsockets-3.2.1/lib/drivers/display/ssd1306-i2c.c 1970-01-01 00:00:00.000000000 +0000 +++ libwebsockets-4.1.6/lib/drivers/display/ssd1306-i2c.c 2020-12-01 17:40:26.000000000 +0000 @@ -0,0 +1,142 @@ +/* + * lws abstract display implementation for ssd1306 on i2c + * + * Copyright (C) 2019 - 2020 Andy Green + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to + * deal in the Software without restriction, including without limitation the + * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or + * sell copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS + * IN THE SOFTWARE. + */ + +#include +#include + + +static uint8_t ssd1306_128x64_init[] = { + SSD1306_DISPLAYOFF, + SSD1306_SETDISPLAYCLOCKDIV, 0xf0, + SSD1306_SETMULTIPLEX, 64 - 1, + SSD1306_SETDISPLAYOFFSET, 0, + SSD1306_CHARGEPUMP, 0x14, + SSD1306_MEMORYMODE, 0, + SSD1306_SEGREMAP | (0 << 0), + SSD1306_COMSCANDEC, + SSD1306_SETCOMPINS, (1 << 4) | 0x02, + SSD1306_SETCONTRAST, 0, /* start at lowest */ + SSD1306_SETPRECHARGE, (0xf << 4) | (1 << 0), + SSD1306_SETVCOMDESELECT, (4 << 4), + SSD1306_DEACTIVATE_SCROLL, + SSD1306_DISPLAYALLON_RESUME, + SSD1306_NORMALDISPLAY, + SSD1306_DISPLAYON +}; + +int +lws_display_ssd1306_i2c_init(const struct lws_display *disp) +{ + const lws_display_ssd1306_t *si = (const lws_display_ssd1306_t *)disp; + + si->i2c->init(si->i2c); + + if (si->gpio) { + si->gpio->mode(si->reset_gpio, LWSGGPIO_FL_WRITE | + LWSGGPIO_FL_PULLUP); + si->gpio->set(si->reset_gpio, 0); + lws_msleep(1); + si->gpio->set(si->reset_gpio, 1); + lws_msleep(1); + } + + if (lws_i2c_command_list(si->i2c, si->i2c7_address, + ssd1306_128x64_init, + LWS_ARRAY_SIZE(ssd1306_128x64_init))) { + lwsl_err("%s: fail\n", __func__); + return 1; + } + + return 0; +} + +int +lws_display_ssd1306_i2c_contrast(const struct lws_display *disp, uint8_t b) +{ + const lws_display_ssd1306_t *si = (const lws_display_ssd1306_t *)disp; + uint8_t ba[2]; + + ba[0] = SSD1306_SETCONTRAST; + ba[1] = b; + + return lws_i2c_command_list(si->i2c, si->i2c7_address, + ba, LWS_ARRAY_SIZE(ba)); +} + +int +lws_display_ssd1306_i2c_blit(const struct lws_display *disp, const uint8_t *src, + lws_display_scalar x, lws_display_scalar y, + lws_display_scalar w, lws_display_scalar h) +{ + const lws_display_ssd1306_t *si = (const lws_display_ssd1306_t *)disp; + uint8_t ba[6]; + int n, m; + + /* + * The display is arranged in 128x8 bands, with one byte containing + * the 8 vertical pixels of the band. + */ + + if (h < 8) + h = 8; + + ba[0] = SSD1306_COLUMNADDR; + ba[1] = x; + ba[2] = x + w - 1; + ba[3] = SSD1306_PAGEADDR; + ba[4] = y / 8; + ba[5] = ba[4] + (h / 8) - 1; + + if (lws_i2c_command_list(si->i2c, si->i2c7_address, + ba, LWS_ARRAY_SIZE(ba))) { + lwsl_err("%s: fail\n", __func__); + return 1; + } + + for (n = 0; n < (w * h) / 8;) { + lws_bb_i2c_start(si->i2c); + lws_bb_i2c_write(si->i2c, si->i2c7_address << 1); + lws_bb_i2c_write(si->i2c, SSD1306_SETSTARTLINE | y); + + for (m = 0; m < w; m++) + lws_bb_i2c_write(si->i2c, src[n++]); + + lws_bb_i2c_stop(si->i2c); + y += 8; + } + + return 0; +} + +int +lws_display_ssd1306_i2c_power(const struct lws_display *disp, int state) +{ + const lws_display_ssd1306_t *si = (const lws_display_ssd1306_t *)disp; + + if (!state) + return lws_i2c_command(si->i2c, si->i2c7_address, + SSD1306_DISPLAYOFF | !!state); + + return lws_display_ssd1306_i2c_init(disp); +} diff -Nru libwebsockets-3.2.1/lib/drivers/i2c/bitbang/lws-bb-i2c.c libwebsockets-4.1.6/lib/drivers/i2c/bitbang/lws-bb-i2c.c --- libwebsockets-3.2.1/lib/drivers/i2c/bitbang/lws-bb-i2c.c 1970-01-01 00:00:00.000000000 +0000 +++ libwebsockets-4.1.6/lib/drivers/i2c/bitbang/lws-bb-i2c.c 2020-12-01 17:40:26.000000000 +0000 @@ -0,0 +1,135 @@ +/* + * I2C bitbang implementation using generic gpio + * + * Copyright (C) 2019 - 2020 Andy Green + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to + * deal in the Software without restriction, including without limitation the + * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or + * sell copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS + * IN THE SOFTWARE. + * + * This is like an abstract class for gpio, a real implementation provides + * functions for the ops that use the underlying OS gpio arrangements. + */ +#include + +int +lws_bb_i2c_init(const lws_i2c_ops_t *octx) +{ + lws_bb_i2c_t *ctx = (lws_bb_i2c_t *)octx; + + ctx->gpio->mode(ctx->scl, LWSGGPIO_FL_WRITE | LWSGGPIO_FL_READ | LWSGGPIO_FL_PULLUP); + ctx->gpio->mode(ctx->sda, LWSGGPIO_FL_WRITE | LWSGGPIO_FL_READ | LWSGGPIO_FL_PULLUP); + + return 0; +} + +int +lws_bb_i2c_start(const lws_i2c_ops_t *octx) +{ + lws_bb_i2c_t *ctx = (lws_bb_i2c_t *)octx; + + ctx->gpio->set(ctx->sda, 1); + ctx->gpio->set(ctx->scl, 1); + ctx->delay(); + + if (!ctx->gpio->read(ctx->sda)) + return 1; + + ctx->gpio->set(ctx->sda, 0); + ctx->delay(); + ctx->gpio->set(ctx->scl, 0); + + return 0; +} + +void +lws_bb_i2c_stop(const lws_i2c_ops_t *octx) +{ + lws_bb_i2c_t *ctx = (lws_bb_i2c_t *)octx; + + ctx->gpio->set(ctx->sda, 0); + ctx->gpio->set(ctx->scl, 1); + ctx->delay(); + + while (!ctx->gpio->read(ctx->scl)) + ; + + ctx->gpio->set(ctx->sda, 1); + ctx->delay(); +} + +int +lws_bb_i2c_write(const lws_i2c_ops_t *octx, uint8_t data) +{ + lws_bb_i2c_t *ctx = (lws_bb_i2c_t *)octx; + int n; + + for (n = 0; n < 8; n++) { + ctx->gpio->set(ctx->sda, !!(data & (1 << 7))); + ctx->delay(); + ctx->gpio->set(ctx->scl, 1); + ctx->delay(); + data <<= 1; + ctx->gpio->set(ctx->scl, 0); + } + + ctx->gpio->set(ctx->sda, 1); + ctx->delay(); + ctx->gpio->set(ctx->scl, 1); + ctx->delay(); + n = ctx->gpio->read(ctx->sda); + ctx->gpio->set(ctx->scl, 0); + ctx->delay(); + + return !!n; /* 0 = ACKED = OK */ +} + +int +lws_bb_i2c_read(const lws_i2c_ops_t *octx) +{ + lws_bb_i2c_t *ctx = (lws_bb_i2c_t *)octx; + int n, r = 0; + + ctx->gpio->set(ctx->sda, 1); + + for (n = 7; n <= 0; n--) { + ctx->gpio->set(ctx->scl, 0); + ctx->delay(); + ctx->gpio->set(ctx->scl, 1); + ctx->delay(); + if (ctx->gpio->read(ctx->sda)) + r |= 1 << n; + } + ctx->gpio->set(ctx->scl, 0); + + return r; +} + +void +lws_bb_i2c_set_ack(const lws_i2c_ops_t *octx, int ack) +{ + lws_bb_i2c_t *ctx = (lws_bb_i2c_t *)octx; + + ctx->gpio->set(ctx->scl, 0); + ctx->gpio->set(ctx->sda, !!ack); + ctx->delay(); + ctx->gpio->set(ctx->scl, 1); + ctx->delay(); + ctx->gpio->set(ctx->scl, 0); + ctx->delay(); + ctx->gpio->set(ctx->sda, 1); +} diff -Nru libwebsockets-3.2.1/lib/drivers/i2c/lws-i2c.c libwebsockets-4.1.6/lib/drivers/i2c/lws-i2c.c --- libwebsockets-3.2.1/lib/drivers/i2c/lws-i2c.c 1970-01-01 00:00:00.000000000 +0000 +++ libwebsockets-4.1.6/lib/drivers/i2c/lws-i2c.c 2020-12-01 17:40:26.000000000 +0000 @@ -0,0 +1,59 @@ +/* + * Generic I2C + * + * Copyright (C) 2019 - 2020 Andy Green + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to + * deal in the Software without restriction, including without limitation the + * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or + * sell copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS + * IN THE SOFTWARE. + * + * These are generic helpers made up of calls to the i2c driver ops, so they + * just need implementing once like this and are usable for any i2c underlying + * implementation via the ops. + */ + +#include + +int +lws_i2c_command(const lws_i2c_ops_t *ctx, uint8_t ads7, uint8_t c) +{ + if (ctx->start(ctx)) + return 1; + + if (ctx->write(ctx, ads7 << 1)) { + ctx->stop(ctx); + + return 1; + } + + ctx->write(ctx, 0); + ctx->write(ctx, c); + ctx->stop(ctx); + + return 0; +} + +int +lws_i2c_command_list(const lws_i2c_ops_t *ctx, uint8_t ads7, const uint8_t *buf, + size_t len) +{ + while (len--) + if (lws_i2c_command(ctx, ads7, *buf++)) + return 1; + + return 0; +} diff -Nru libwebsockets-3.2.1/lib/drivers/led/led-gpio.c libwebsockets-4.1.6/lib/drivers/led/led-gpio.c --- libwebsockets-3.2.1/lib/drivers/led/led-gpio.c 1970-01-01 00:00:00.000000000 +0000 +++ libwebsockets-4.1.6/lib/drivers/led/led-gpio.c 2020-12-01 17:40:26.000000000 +0000 @@ -0,0 +1,120 @@ +/* + * Generic GPIO led + * + * Copyright (C) 2019 - 2020 Andy Green + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to + * deal in the Software without restriction, including without limitation the + * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or + * sell copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS + * IN THE SOFTWARE. + */ +#include "private-lib-core.h" +#include "drivers/led/private-lib-drivers-led.h" + +#if defined(LWS_PLAT_TIMER_CB) +static LWS_PLAT_TIMER_CB(lws_led_timer_cb, th) +{ + lws_led_state_t *lcs = LWS_PLAT_TIMER_CB_GET_OPAQUE(th); + + lws_seq_timer_handle(lcs); +} +#endif + +struct lws_led_state * +lws_led_gpio_create(const lws_led_ops_t *led_ops) +{ + lws_led_gpio_controller_t *lgc = (lws_led_gpio_controller_t *)led_ops; + /* + * We allocate the main state object, and a 3 x seq dynamic footprint + * for each led, since it may be sequencing the transition between two + * other sequences. + */ + + lws_led_state_t *lcs = lws_zalloc(sizeof(lws_led_state_t) + + (lgc->count_leds * sizeof(lws_led_state_chs_t)), + __func__); + int n; + + if (!lcs) + return NULL; + + lcs->controller = lgc; + +#if defined(LWS_PLAT_TIMER_CREATE) + lcs->timer = LWS_PLAT_TIMER_CREATE("leds", + LWS_LED_SEQUENCER_UPDATE_INTERVAL_MS, 1, lcs, + (TimerCallbackFunction_t)lws_led_timer_cb); + if (!lcs->timer) + return NULL; +#endif + + for (n = 0; n < lgc->count_leds; n++) { + const lws_led_gpio_map_t *map = &lgc->led_map[n]; + + if (map->pwm_ops) { + lgc->gpio_ops->mode(map->gpio, LWSGGPIO_FL_READ); + lgc->gpio_ops->set(map->gpio, 0); + } else { + lgc->gpio_ops->mode(map->gpio, LWSGGPIO_FL_WRITE); + lgc->gpio_ops->set(map->gpio, + !lgc->led_map[n].active_level); + } + } + + return lcs; +} + +void +lws_led_gpio_destroy(struct lws_led_state *lcs) +{ +#if defined(LWS_PLAT_TIMER_DELETE) + LWS_PLAT_TIMER_DELETE(&lcs->timer); +#endif + lws_free(lcs); +} + +int +lws_led_gpio_lookup(const struct lws_led_ops *lo, const char *name) +{ + const lws_led_gpio_controller_t *lgc = (lws_led_gpio_controller_t *)lo; + int n; + + for (n = 0; n < lgc->count_leds; n++) + if (!strcmp(name, lgc->led_map[n].name)) + return n; + + return -1; +} + +void +lws_led_gpio_intensity(const struct lws_led_ops *lo, const char *name, + lws_led_intensity_t inten) +{ + const lws_led_gpio_controller_t *lgc = (lws_led_gpio_controller_t *)lo; + int idx = lws_led_gpio_lookup(lo, name); + const lws_led_gpio_map_t *map; + + if (idx < 0) + return; + + map = &lgc->led_map[idx]; + + if (map->pwm_ops) + map->pwm_ops->intensity(map->pwm_ops, map->gpio, inten); + else + lgc->gpio_ops->set(map->gpio, + (!!map->active_level) ^ !(inten & 0x8000)); +} diff -Nru libwebsockets-3.2.1/lib/drivers/led/led-seq.c libwebsockets-4.1.6/lib/drivers/led/led-seq.c --- libwebsockets-3.2.1/lib/drivers/led/led-seq.c 1970-01-01 00:00:00.000000000 +0000 +++ libwebsockets-4.1.6/lib/drivers/led/led-seq.c 2020-12-01 17:40:26.000000000 +0000 @@ -0,0 +1,200 @@ +/* + * Generic GPIO led + * + * Copyright (C) 2019 - 2020 Andy Green + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to + * deal in the Software without restriction, including without limitation the + * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or + * sell copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS + * IN THE SOFTWARE. + */ +#include "private-lib-core.h" + +#include "drivers/led/private-lib-drivers-led.h" + +/* + * 64 entry interpolated CIE correction + * https://en.wikipedia.org/wiki/Lightness + */ + +uint16_t cie[] = { + 0, 113, 227, 340, 454, 568, 688, 824, 976, 1146, + 1335, 1543, 1772, 2023, 2296, 2592, 2914, 3260, 3633, 4034, + 4463, 4921, 5409, 5929, 6482, 7067, 7687, 8341, 9032, 9761, + 10527, 11332, 12178, 13064, 13993, 14964, 15980, 17040, 18146, 19299, + 20500, 21750, 23049, 24400, 25802, 27256, 28765, 30328, 31946, 33622, + 35354, 37146, 38996, 40908, 42881, 44916, 47014, 49177, 51406, 53700, + 56062, 58492, 60992, 63561, + 65535 /* for interpolation */ +}; + +/* + * This is the default intensity correction function, it can be overridden + * per-led to eg, normalize intensity of different leds + */ + +static lws_led_intensity_t +cie_antilog(lws_led_intensity_t lin) +{ + return (cie[lin >> 10] * (0x3ff - (lin & 0x3ff)) + + cie[(lin >> 10) + 1] * (lin & 0x3ff)) / 0x3ff; +} + +static void +lws_seq_advance(lws_led_state_t *lcs, lws_led_state_ch_t *ch) +{ + if (!ch->seq) + return; + + if (ch->phase_budget != LWS_SEQ_LEDPHASE_TOTAL_ENDLESS && + (ch->phase_budget < ch->step || !ch->phase_budget)) { + + /* we are done */ + + ch->seq = NULL; + if (!(--lcs->timer_refcount)) { +#if defined(LWS_PLAT_TIMER_STOP) + LWS_PLAT_TIMER_STOP(lcs->timer); +#endif + } + + return; + } + + ch->ph += ch->step; + if (ch->phase_budget != LWS_SEQ_LEDPHASE_TOTAL_ENDLESS) + ch->phase_budget -= ch->step; +} + +static lws_led_intensity_t +lws_seq_sample(const lws_led_gpio_map_t *map, lws_led_state_chs_t *chs) +{ + unsigned int i; + + if (chs->seqs[LLSI_CURR].seq) + chs->seqs[LLSI_CURR].last = chs->seqs[LLSI_CURR].seq-> + func(chs->seqs[LLSI_CURR].ph); + + if (chs->seqs[LLSI_TRANS].seq) { + /* + * If a transition is ongoing, we need to use the transition + * intensity as the mixing factor between the still-live current + * and newly-live next sequences + */ + chs->seqs[LLSI_TRANS].last = chs->seqs[LLSI_TRANS].seq-> + func(chs->seqs[LLSI_TRANS].ph); + + if (chs->seqs[LLSI_NEXT].seq) + chs->seqs[LLSI_NEXT].last = chs->seqs[LLSI_NEXT].seq-> + func(chs->seqs[LLSI_NEXT].ph); + + i = (lws_led_intensity_t)((( + (unsigned int)chs->seqs[LLSI_CURR].last * + (65535 - chs->seqs[LLSI_TRANS].last) >> 16) + + (((unsigned int)chs->seqs[LLSI_NEXT].last * + (unsigned int)chs->seqs[LLSI_TRANS].last) >> 16))); + } else + i = chs->seqs[LLSI_CURR].last; + + return map->intensity_correction ? map->intensity_correction(i) : + cie_antilog((lws_led_intensity_t)i); +} + +void +lws_seq_timer_handle(lws_led_state_t *lcs) +{ + lws_led_gpio_controller_t *lgc = lcs->controller; + lws_led_state_chs_t *chs = (lws_led_state_chs_t *)&lcs[1]; + const lws_led_gpio_map_t *map = &lgc->led_map[0]; + unsigned int n; + + for (n = 0; n < lgc->count_leds; n++) { + + lgc->led_ops.intensity(&lgc->led_ops, map->name, + lws_seq_sample(map, chs)); + + lws_seq_advance(lcs, &chs->seqs[LLSI_CURR]); + + if (chs->seqs[LLSI_TRANS].seq) { + lws_seq_advance(lcs, &chs->seqs[LLSI_NEXT]); + lws_seq_advance(lcs, &chs->seqs[LLSI_TRANS]); + + /* + * When we finished the transition, we can make the + * "next" sequence the current sequence and no need for + * a "next" or a transition any more. + */ + + if (!chs->seqs[LLSI_TRANS].seq) { + chs->seqs[LLSI_CURR] = chs->seqs[LLSI_NEXT]; + chs->seqs[LLSI_NEXT].seq = NULL; + } + } + + map++; + chs++; + } +} + +static int +lws_led_set_chs_seq(struct lws_led_state *lcs, lws_led_state_ch_t *dest, + const lws_led_sequence_def_t *def) +{ + int steps; + + dest->seq = def; + dest->ph = def->ledphase_offset; + dest->phase_budget = def->ledphase_total; + + /* + * We need to compute the incremental phase angle step to cover the + * total number of phases in the indicated ms, incrementing at the + * timer rate of LWS_LED_SEQUENCER_UPDATE_RATE_HZ. Eg, + * + * 65536 phase steps (one cycle) in 2000ms at 30Hz timer rate means we + * will update 2000ms / 33ms = 60 times, so we must step at at + * 65536 / 60 = 1092 phase angle resolution + */ + + steps = def->ms / LWS_LED_SEQUENCER_UPDATE_INTERVAL_MS; + dest->step = (def->ledphase_total != LWS_SEQ_LEDPHASE_TOTAL_ENDLESS ? + def->ledphase_total : LWS_LED_FUNC_PHASE) / (steps ? steps : 1); + + if (!lcs->timer_refcount++) { +#if defined(LWS_PLAT_TIMER_START) + LWS_PLAT_TIMER_START(lcs->timer); +#endif + } + + return steps; +} + +int +lws_led_transition(struct lws_led_state *lcs, const char *name, + const lws_led_sequence_def_t *next, + const lws_led_sequence_def_t *trans) +{ + lws_led_state_chs_t *chs = (lws_led_state_chs_t *)&lcs[1]; + int index = lws_led_gpio_lookup(&lcs->controller->led_ops, name); + + if (index < 0) + return 1; + + lws_led_set_chs_seq(lcs, &chs[index].seqs[LLSI_TRANS], trans); + lws_led_set_chs_seq(lcs, &chs[index].seqs[LLSI_NEXT], next); + + return 0; +} diff -Nru libwebsockets-3.2.1/lib/drivers/led/private-lib-drivers-led.h libwebsockets-4.1.6/lib/drivers/led/private-lib-drivers-led.h --- libwebsockets-3.2.1/lib/drivers/led/private-lib-drivers-led.h 1970-01-01 00:00:00.000000000 +0000 +++ libwebsockets-4.1.6/lib/drivers/led/private-lib-drivers-led.h 2020-12-01 17:40:26.000000000 +0000 @@ -0,0 +1,39 @@ +/* + * Generic GPIO led + * + * Copyright (C) 2019 - 2020 Andy Green + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to + * deal in the Software without restriction, including without limitation the + * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or + * sell copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS + * IN THE SOFTWARE. + */ + +typedef struct lws_led_state +{ +#if defined(LWS_PLAT_TIMER_TYPE) + LWS_PLAT_TIMER_TYPE timer; +#endif + + lws_led_gpio_controller_t *controller; + int timer_refcount; +} lws_led_state_t; + +void +lws_seq_timer_handle(lws_led_state_t *lcs); + +int +lws_led_gpio_lookup(const struct lws_led_ops *lo, const char *name); diff -Nru libwebsockets-3.2.1/lib/drivers/led/README.md libwebsockets-4.1.6/lib/drivers/led/README.md --- libwebsockets-3.2.1/lib/drivers/led/README.md 1970-01-01 00:00:00.000000000 +0000 +++ libwebsockets-4.1.6/lib/drivers/led/README.md 2020-12-01 17:40:26.000000000 +0000 @@ -0,0 +1,155 @@ +# lws_led gpio and pwm class drivers + +Lws provides an abstract led controller class that can bind an array of LEDs +to gpio and pwm controllers, and automatically handled pwm sequencers. + +Lumience intensity is corrected for IEC curves to match perceptual intensity, +and the correction can be overridden per led for curve adaptation matching. + +Intensity is normalized to a 16-bit scale, when controlled by a GPIO b15 is +significant and the rest ignored. When controlled by PWM, as many bits from +b15 down are significant as the PWM arrangements can represent. + +The PWM sequencers use arbitrary function generation callbacks on a normalized +16-bit phase space, they can choose how much to interpolate and how much to put +in a table, a 64-sample, 16-bit sine function is provided along with 16-bit +linear sawtooth. + +Changing the sequencer is subject to a third transition function sequencer, this +can for example mix the transition linearly over, eg, 500ms so the leds look +very smooth. + +## Defining an led controller + +An array of inidividual LED information is provided first, and referenced by +the LED controller definintion. Leds are named so code does not introduce +dependencies on specific implementations. + +``` +static const lws_led_gpio_map_t lgm[] = { + { + .name = "alert", + .gpio = GPIO_NUM_25, + .pwm_ops = &pwm_ops, + .active_level = 1, + }, +}; + +static const lws_led_gpio_controller_t lgc = { + .led_ops = lws_led_gpio_ops, + .gpio_ops = &lws_gpio_plat, + .led_map = &lgm[0], + .count_leds = LWS_ARRAY_SIZE(lgm) +}; + + struct lws_led_state *lls; + + lls = lgc.led_ops.create(&lgc.led_ops); + if (!lls) { + lwsl_err("%s: could not create led\n", __func__); + goto spin; + } + +``` + +For GPIO control, the active level of the GPIO to light the LED may be set. + +Each LED may bind to a pwm controller, in which case setting the intensity +programs the pwm controller corresponding to the GPIO. + +## Setting the intensity directly + +``` + lgc.led_ops.intensity(&lgc.led_ops, "alert", 0); +``` + +## Defining Sequencer + +Some common sequencers are provided out of the box, you can also define your +own arbitrary ones. + +The main point is sequencers have a function that returns an intensity for each +of 65536 phase steps in its cycle. For example, this is the linear function +that is included + +``` +lws_led_intensity_t +lws_led_func_linear(lws_led_seq_phase_t n) +{ + return (lws_led_intensity_t)n; +} +``` + +It simply returns an intensity between 0 - 65535 matching the phase angle of +0 - 65535 that it was given, so it's a sawtooth ramp. + +An interpolated sine function is also provided that returns an intensity +between 0 - 65535 reflecting one cycle of sine wave for the phase angle of 0 - +65535. + +These functions are packaged into sequencer structures like this + +``` +const lws_led_sequence_def_t lws_pwmseq_sine_endless_fast = { + .func = lws_led_func_sine, + .ledphase_offset = 0, /* already at 0 amp at 0 phase */ + .ledphase_total = LWS_SEQ_LEDPHASE_TOTAL_ENDLESS, + .ms = 750 +}; +``` + +This "endless" sequencer cycles through the sine function at 750ms per cycle. +Non-endless sequencers have a specific start and end in the phase space, eg + +``` +const lws_led_sequence_def_t lws_pwmseq_sine_up = { + .func = lws_led_func_sine, + .ledphase_offset = 0, /* already at 0 amp at 0 phase */ + .ledphase_total = LWS_LED_FUNC_PHASE / 2, /* 180 degree ./^ */ + .ms = 300 +}; +``` + +... this one traverses 180 degrees of the sine wave starting from 0 and ending +at full intensity, over 300ms. + +A commonly-used, provided one is like this, as used in the next section + +``` +const lws_led_sequence_def_t lws_pwmseq_linear_wipe = { + .func = lws_led_func_linear, + .ledphase_offset = 0, + .ledphase_total = LWS_LED_FUNC_PHASE - 1, + .ms = 300 +}; +``` + +## Setting the intensity using sequencer transitions + +The main api for high level sequenced control is + +``` +int +lws_led_transition(struct lws_led_state *lcs, const char *name, + const lws_led_sequence_def_t *next, + const lws_led_sequence_def_t *trans); +``` + +This fades from the current sequence to a new sequence, using `trans` sequencer +intensity as the mix factor. `trans` is typically `lws_pwmseq_linear_wipe`, +fading between the current and new linearly over 300ms. At the end of the +`trans` sequence, the new sequence simply replaces the current one and the +transition is completed. + +Sequencers use a single 30Hz OS timer while any sequence is active. + +exported sequencer symbol|description +---|--- +lws_pwmseq_sine_endless_slow|continuous 100% sine, 1.5s cycle +lws_pwmseq_sine_endless_fast|continuous 100% sine, 0.75s cycle +lws_pwmseq_linear_wipe|single 0 - 100% ramp over 0.3s +lws_pwmseq_sine_up|single 0 - 100% using sine curve over 0.3s +lws_pwmseq_sine_down|single 100% - 0 using sine curve over 0.3s +lws_pwmseq_static_on|100% static +lws_pwmseq_static_half|50% static +lws_pwmseq_static_off|0% static diff -Nru libwebsockets-3.2.1/lib/drivers/netdev/netdev.c libwebsockets-4.1.6/lib/drivers/netdev/netdev.c --- libwebsockets-3.2.1/lib/drivers/netdev/netdev.c 1970-01-01 00:00:00.000000000 +0000 +++ libwebsockets-4.1.6/lib/drivers/netdev/netdev.c 2020-12-01 17:40:26.000000000 +0000 @@ -0,0 +1,272 @@ +/* + * libwebsockets - small server side websockets and web server implementation + * + * Copyright (C) 2010 - 2020 Andy Green + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to + * deal in the Software without restriction, including without limitation the + * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or + * sell copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS + * IN THE SOFTWARE. + */ + +#include + +static const lws_struct_map_t lsm_wifi_creds[] = { + LSM_CARRAY (lws_wifi_creds_t, ssid, "ssid"), + LSM_CARRAY (lws_wifi_creds_t, passphrase, "passphrase"), + LSM_UNSIGNED (lws_wifi_creds_t, alg, "alg"), + LSM_STRING_PTR (lws_wifi_creds_t, bssid, "bssid"), +}; + +static const lws_struct_map_t lsm_netdev_credentials[] = { + LSM_LIST (lws_netdevs_t, owner_creds, lws_wifi_creds_t, list, + NULL, lsm_wifi_creds, "credentials"), +}; + +static const lws_struct_map_t lsm_netdev_schema[] = { + LSM_SCHEMA (lws_netdevs_t, NULL, lsm_netdev_credentials, + "lws-netdev-creds"), +}; + + +//LSM_CHILD_PTR (lws_netdev_instance_wifi_t, ap_cred, lws_wifi_creds_t, +// NULL, lsm_wifi_creds, "ap_cred"), +//LSM_STRING_PTR (lws_netdev_instance_wifi_t, ap_ip, "ap_ip"), + +int +lws_netdev_credentials_settings_set(lws_netdevs_t *nds) +{ + lws_struct_serialize_t *js; + size_t w = 0, max = 2048; + int n, r = 1; + uint8_t *buf; + + buf = lws_malloc(max, __func__); /* length should be computed */ + + js = lws_struct_json_serialize_create(lsm_netdev_schema, + LWS_ARRAY_SIZE(lsm_netdev_schema), 0, nds); + if (!js) + goto bail; + + n = lws_struct_json_serialize(js, buf, max, &w); + lws_struct_json_serialize_destroy(&js); + if (n != LSJS_RESULT_FINISH) + goto bail; + + lwsl_notice("%s: setting %s\n", __func__, buf); + + if (!lws_settings_plat_set(nds->si, "netdev.creds", buf, w)) + r = 0; + +bail: + if (r) + lwsl_err("%s: failed\n", __func__); + lws_free(buf); + + return r; +} + +int +lws_netdev_credentials_settings_get(lws_netdevs_t *nds) +{ + struct lejp_ctx ctx; + lws_struct_args_t a; + size_t l = 0; + uint8_t *buf; + int m; + + memset(&a, 0, sizeof(a)); + + if (lws_settings_plat_get(nds->si, "netdev.creds", NULL, &l)) { + lwsl_notice("%s: not in settings\n", __func__); + return 1; + } + + buf = lws_malloc(l, __func__); + if (!buf) + return 1; + + if (lws_settings_plat_get(nds->si, "netdev.creds", buf, &l)) { + lwsl_err("%s: unexpected settings get fail\n", __func__); + goto bail; + } + + a.map_st[0] = lsm_netdev_schema; + a.map_entries_st[0] = LWS_ARRAY_SIZE(lsm_netdev_schema); + a.ac_block_size = 512; + + lws_struct_json_init_parse(&ctx, NULL, &a); + m = lejp_parse(&ctx, (uint8_t *)buf, l); + lws_free(buf); + if (m < 0 || !a.dest) { + lwsl_notice("%s: JSON decode failed '%s'\n", + __func__, lejp_error_to_string(m)); + goto bail1; + } + + /* + * Forcibly set the state of the nds creds owner to the synthesized + * one in the ac, and keep the ac for as long as we keep the creds out + */ + nds->owner_creds = ((lws_netdevs_t *)a.dest)->owner_creds; + nds->ac_creds = a.ac; + + return 0; + +bail: + lws_free(buf); +bail1: + lwsac_free(&a.ac); + + return 1; +} + +lws_wifi_creds_t * +lws_netdev_credentials_find(lws_netdevs_t *netdevs, const char *ssid, + const uint8_t *bssid) +{ + lws_start_foreach_dll(struct lws_dll2 *, p, lws_dll2_get_head( + &netdevs->owner_creds)) { + lws_wifi_creds_t *w = lws_container_of(p, lws_wifi_creds_t, list); + + if (!strcmp(ssid, (const char *)&w[1]) && + !memcmp(bssid, w->bssid, 6)) + return w; + + } lws_end_foreach_dll(p); + + return NULL; +} + +lws_netdev_instance_t * +lws_netdev_find(lws_netdevs_t *netdevs, const char *ifname) +{ + lws_start_foreach_dll(struct lws_dll2 *, p, lws_dll2_get_head( + &netdevs->owner)) { + lws_netdev_instance_t *ni = lws_container_of(p, + lws_netdev_instance_t, list); + + if (!strcmp(ifname, ni->name)) + return ni; + + } lws_end_foreach_dll(p); + + return NULL; +} + +/* + * Context forwards NETWORK related smd here, in lws thread context + */ + +int +lws_netdev_smd_cb(void *opaque, lws_smd_class_t _class, lws_usec_t timestamp, + void *buf, size_t len) +{ + struct lws_context *ctx = (struct lws_context *)opaque; + const char *iface; + char setname[16]; + size_t al = 0; + + /* deal with anything from whole-network perspective */ + + /* pass through netdev-specific messages to correct platform handler */ + + iface = lws_json_simple_find(buf, len, "\"if\":", &al); + if (!iface) + return 0; + + lws_start_foreach_dll(struct lws_dll2 *, p, lws_dll2_get_head( + &ctx->netdevs.owner)) { + lws_netdev_instance_t *ni = lws_container_of( + p, lws_netdev_instance_t, list); + + if (!strncmp(ni->name, iface, al)) { + + /* + * IP assignment on our netif? We can deal with marking + * the last successful association generically... + */ + + if (ni->type == LWSNDTYP_WIFI && + !lws_json_simple_strcmp(buf, len, "\"type\":", + "ipacq")) { + const char *ev = lws_json_simple_find(buf, len, + "\"ipv4\":", &al); + lws_netdev_instance_wifi_t *wnd = + (lws_netdev_instance_wifi_t *)ni; + + if (!ev) + return 0; + + lws_snprintf(setname, sizeof(setname), + "netdev.last.%s", iface); + + lws_settings_plat_printf(ctx->netdevs.si, + setname, "{\"ssid\":\"%s\",\"bssid\":" + "\"%02X%02X%02X%02X%02X%02X\"}", + wnd->current_attempt_ssid, + wnd->current_attempt_bssid[0], + wnd->current_attempt_bssid[1], + wnd->current_attempt_bssid[2], + wnd->current_attempt_bssid[3], + wnd->current_attempt_bssid[4], + wnd->current_attempt_bssid[5]); + } + + /* + * Pass it through to related netdev instance for + * private actions + */ + + return ni->ops->event(ni, timestamp, buf, len); + } + + } lws_end_foreach_dll(p); + + return 0; +} + +/* + * This is the generic part of the netdev instance initialization that's always + * the same, regardless of the netdev type + */ + +void +lws_netdev_instance_create(lws_netdev_instance_t *ni, struct lws_context *ctx, + const lws_netdev_ops_t *ops, const char *name, + void *platinfo) +{ + ni->ops = ops; + ni->name = name; + ni->platinfo = platinfo; + + /* add us to the list of active netdevs */ + + lws_dll2_add_tail(&ni->list, &ctx->netdevs.owner); +} + +void +lws_netdev_instance_remove_destroy(struct lws_netdev_instance *ni) +{ + lws_dll2_remove(&ni->list); + lws_free(ni); +} + +lws_netdevs_t * +lws_netdevs_from_ctx(struct lws_context *ctx) +{ + return &ctx->netdevs; +} diff -Nru libwebsockets-3.2.1/lib/drivers/netdev/wifi.c libwebsockets-4.1.6/lib/drivers/netdev/wifi.c --- libwebsockets-3.2.1/lib/drivers/netdev/wifi.c 1970-01-01 00:00:00.000000000 +0000 +++ libwebsockets-4.1.6/lib/drivers/netdev/wifi.c 2020-12-01 17:40:26.000000000 +0000 @@ -0,0 +1,243 @@ +/* + * libwebsockets - lws_netdev_wifi generic state handling + * + * Copyright (C) 2010 - 2020 Andy Green + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to + * deal in the Software without restriction, including without limitation the + * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or + * sell copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS + * IN THE SOFTWARE. + * + * The generic wifi netdevs follow a + */ + +#include "private-lib-core.h" + +int +lws_netdev_wifi_rssi_sort_compare(const lws_dll2_t *d, const lws_dll2_t *i) +{ + const lws_wifi_sta_t *wsd = (const lws_wifi_sta_t *)d, + *wsi = (const lws_wifi_sta_t *)i; + return rssi_averaged(wsd) > rssi_averaged(wsi); +} + +void +lws_netdev_wifi_scan_empty(lws_netdev_instance_wifi_t *wnd) +{ + lws_start_foreach_dll_safe(struct lws_dll2 *, p, p1, lws_dll2_get_head( + &wnd->scan)) { + lws_wifi_sta_t *s = lws_container_of(p, lws_wifi_sta_t, list); + + lws_dll2_remove(p); + lws_free(s); + + } lws_end_foreach_dll_safe(p, p1); +} + +void +lws_netdev_wifi_scan(lws_sorted_usec_list_t *sul) +{ + lws_netdev_instance_wifi_t *wnd = lws_container_of(sul, + lws_netdev_instance_wifi_t, sul_scan); + + wnd->inst.ops->scan(&wnd->inst); +} + +lws_wifi_sta_t * +lws_netdev_wifi_scan_find(lws_netdev_instance_wifi_t *wnd, const char *ssid, + const uint8_t *bssid) +{ + lws_start_foreach_dll(struct lws_dll2 *, p, lws_dll2_get_head( + &wnd->scan)) { + lws_wifi_sta_t *w = lws_container_of(p, lws_wifi_sta_t, list); + + if (!strcmp(ssid, (const char *)&w[1]) && + !memcmp(bssid, w->bssid, 6)) + return w; + + } lws_end_foreach_dll(p); + + return NULL; +} + +int +lws_netdev_wifi_scan_select(lws_netdev_instance_wifi_t *wnd) +{ + lws_netdevs_t *netdevs = lws_netdevs_from_ndi(&wnd->inst); + struct lws_context *cx = lws_context_from_netdevs(netdevs); + uint32_t least_recent = 0xffffffff; + lws_wifi_creds_t *pc = NULL; + lws_wifi_sta_t *pw = NULL; + + /* + * Trim enough of the lowest RSSI guys in order to get us below the + * limit we are allowed to keep track of... + */ + + while (wnd->scan.count > LWS_WIFI_MAX_SCAN_TRACK) { + struct lws_dll2 *p = lws_dll2_get_tail(&wnd->scan); + lws_wifi_sta_t *w = lws_container_of(p, lws_wifi_sta_t, list); + + lws_dll2_remove(p); + lws_free(w); + } + + /* + * ... let's dump what's left + */ + + lws_start_foreach_dll(struct lws_dll2 *, p, lws_dll2_get_head( + &wnd->scan)) { + lws_wifi_sta_t *w = lws_container_of(p, lws_wifi_sta_t, list); + + lwsl_notice("%s: %s, %02X:%02X:%02X:%02X:%02X:%02X, ch %d, rssi %d\n", + __func__, (const char *)&w[1], w->bssid[0], + w->bssid[1], w->bssid[2], w->bssid[3], w->bssid[4], + w->bssid[5], w->ch, rssi_averaged(w)); + + } lws_end_foreach_dll(p); + + /* + * make sure we have our device's connection credentials at hand + */ + + if (!netdevs->ac_creds && + lws_netdev_credentials_settings_get(netdevs)) + return 0; + netdevs->refcount_creds++; + + /* + * Let's go through each starting from the best RSSI seeing if we + * have credentials... if we do, pick the one we least-recently tried + */ + + lws_start_foreach_dll(struct lws_dll2 *, p1, wnd->scan.head) { + lws_wifi_sta_t *w = lws_container_of(p1, lws_wifi_sta_t, list); + + lws_start_foreach_dll(struct lws_dll2 *, q, + netdevs->owner_creds.head) { + lws_wifi_creds_t *c = lws_container_of(q, + lws_wifi_creds_t, + list); + + if (!strcmp((const char *)&w[1], c->ssid) && + w->last_seen < least_recent) { + /* + * Not <= so we stick with higher RSSI when + * all 0 + */ + pc = c; + pw = w; + least_recent = w->last_seen; + } + + } lws_end_foreach_dll(q); + + } lws_end_foreach_dll(p1); + + + if (least_recent != 0xffffffff) { + /* + * We picked one to try... note what we're trying so we can + * record it in settings as last successful + */ + lws_strncpy(wnd->current_attempt_ssid, (const char *)&pw[1], + sizeof(wnd->current_attempt_ssid)); + memcpy(wnd->current_attempt_bssid, pw->bssid, LWS_ETH_ALEN); + wnd->inst.ops->connect(&wnd->inst, pc->ssid, pc->passphrase, + pw->bssid); + } else { + /* + * We couldn't see anyone we recognized on this scan, let's + * rescan in a bit + */ + + lwsl_notice("%s: nothing usable in scan, redoing in 3s\n", __func__); + lws_sul_schedule(cx, 0, &wnd->sul_scan, lws_netdev_wifi_scan, + 3 * LWS_US_PER_SEC); + } + + if (!--netdevs->refcount_creds) { + lws_dll2_owner_clear(&netdevs->owner_creds); + lwsac_free(&netdevs->ac_creds); + } + + return 0; +} + +/* + * Initially our best bet is just try to reconnect to whatever we last + * succeeded to connect to + */ + +int +lws_netdev_wifi_redo_last(lws_netdev_instance_wifi_t *wnd) +{ + lws_netdevs_t *netdevs = lws_netdevs_from_ndi(&wnd->inst); + uint8_t buf[256], bssid[LWS_ETH_ALEN]; + const char *ssid, *pp = "", *pb; + char setname[16], ssid_copy[33]; + size_t l = sizeof(buf), al; + lws_wifi_creds_t *cred; + + /* + * Let's try to retreive the last successful connect info for this + * netdev + */ + + lws_snprintf(setname, sizeof(setname), "netdev.last.%s", wnd->inst.name); + if (lws_settings_plat_get(netdevs->si, setname, buf, &l)) + return 1; + + lwsl_notice("%s: last successful %s\n", __func__, buf); + + ssid = lws_json_simple_find((const char *)buf, l, "\"ssid\":", &al); + if (!ssid || al > 32) + return 1; + + memcpy(ssid_copy, ssid, al); + ssid_copy[al + 1] = '\0'; + + pb = lws_json_simple_find((const char *)buf, l, "\"bssid\":", &al); + if (!pb) + return 1; + lws_hex_to_byte_array(pb, bssid, sizeof(bssid)); + + /* + * make sure we have our device's connection credentials at hand + */ + + if (!netdevs->ac_creds && + lws_netdev_credentials_settings_get(netdevs)) + return 1; + netdevs->refcount_creds++; + + cred = lws_netdev_credentials_find(netdevs, ssid_copy, bssid); + if (cred) + pp = cred->passphrase; + + lws_strncpy(wnd->current_attempt_ssid, ssid_copy, + sizeof(wnd->current_attempt_ssid)); + memcpy(wnd->current_attempt_bssid, bssid, LWS_ETH_ALEN); + wnd->inst.ops->connect(&wnd->inst, ssid_copy, pp, bssid); + + if (!--netdevs->refcount_creds) { + lws_dll2_owner_clear(&netdevs->owner_creds); + lwsac_free(&netdevs->ac_creds); + } + + return 0; +} diff -Nru libwebsockets-3.2.1/lib/drivers/pwm/pwm.c libwebsockets-4.1.6/lib/drivers/pwm/pwm.c --- libwebsockets-3.2.1/lib/drivers/pwm/pwm.c 1970-01-01 00:00:00.000000000 +0000 +++ libwebsockets-4.1.6/lib/drivers/pwm/pwm.c 2020-12-01 17:40:26.000000000 +0000 @@ -0,0 +1,156 @@ +/* + * Generic GPIO led + * + * Copyright (C) 2019 - 2020 Andy Green + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to + * deal in the Software without restriction, including without limitation the + * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or + * sell copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS + * IN THE SOFTWARE. + */ +#include "private-lib-core.h" + +static const lws_led_intensity_t sineq16[] = { + + /* + * Quadrant at sin(270) in 16 samples, normalized so + * -1 == 0 and 0 == 32767 + */ + + 0, 158, 630, 1411, 2494, 3869, 5522, 7437, + 9597, 11980, 14562, 17321, 20228, 23225, 26374, 29555, + 32767 /* to interpolate against */ +}; + +/* + * Elaborate the 90 degree phase table to 360 degrees and offset to +32768, + * notice for the last sample we have to interpolate against a 17th sample + * reflecting full scale to avoid clipping due to interpolation against the + * 16th sample again + */ + +static lws_led_intensity_t +sine_lu(int n, int next) +{ + switch ((n >> 4) & 3) { + case 1: + /* forwards */ + return 32768 + sineq16[(n & 15) + next]; + case 2: + /* scan it backwards */ + return 32768 + sineq16[15 - (n & 15) + (!next)]; + case 3: + /* forwards */ + return 32768 - sineq16[(n & 15) + next]; + default: + /* scan it backwards */ + return 32768 - sineq16[15 - (n & 15) + (!next)]; + } +} + +/* + * The normalized phase resolution is 16-bit, however much table you decide to + * have needs interpolating or indexing in a reduced number of significant + * phase bits if it doesn't have the same phase resolution. + * + * In this sine table we have a 16 x 15-bit sample quadrant reflected 4 times + * to make 360 degrees, so 64 accurate sample points, with the rest of the + * intermediate phases generated by linear interpolation. That probably would + * sound a bit funky, but for modulating light dynamically it's more than + * enough. + */ + +lws_led_intensity_t +lws_led_func_sine(lws_led_seq_phase_t n) +{ + /* + * 2: quadrant + * 4: table entry in quadrant + * 10: interp (LSB) + */ + + return (sine_lu(n >> 10, 0) * (0x3ff - (n & 0x3ff)) + + sine_lu(n >> 10, 1) * (n & 0x3ff)) / 0x3ff; +} + +lws_led_intensity_t +lws_led_func_linear(lws_led_seq_phase_t n) +{ + return (lws_led_intensity_t)n; +} + + +static lws_led_intensity_t +lws_led_func_static(lws_led_seq_phase_t n) +{ + return ((int)n * LWS_LED_MAX_INTENSITY) / 2; +} + +const lws_led_sequence_def_t lws_pwmseq_static_off = { + .func = lws_led_func_static, + .ledphase_offset = 0, + .ledphase_total = 0, + .ms = 0 +}; + +const lws_led_sequence_def_t lws_pwmseq_static_half = { + .func = lws_led_func_static, + .ledphase_offset = 1, + .ledphase_total = 0, + .ms = 0 +}; + +const lws_led_sequence_def_t lws_pwmseq_static_on = { + .func = lws_led_func_static, + .ledphase_offset = 2, + .ledphase_total = 0, + .ms = 0 +}; + +const lws_led_sequence_def_t lws_pwmseq_sine_up = { + .func = lws_led_func_sine, + .ledphase_offset = 0, /* already at 0 amp at 0 phase */ + .ledphase_total = LWS_LED_FUNC_PHASE / 2, /* 180 degree ./^ */ + .ms = 300 +}; + +const lws_led_sequence_def_t lws_pwmseq_sine_down = { + .func = lws_led_func_sine, + .ledphase_offset = LWS_LED_FUNC_PHASE / 2, /* start at peak */ + .ledphase_total = LWS_LED_FUNC_PHASE / 2, /* 180 degree ./^ */ + .ms = 300 +}; + +const lws_led_sequence_def_t lws_pwmseq_linear_wipe = { + .func = lws_led_func_linear, + .ledphase_offset = 0, + .ledphase_total = LWS_LED_FUNC_PHASE - 1, + .ms = 300 +}; + +const lws_led_sequence_def_t lws_pwmseq_sine_endless_slow = { + .func = lws_led_func_sine, + .ledphase_offset = 0, /* already at 0 amp at 0 phase */ + .ledphase_total = LWS_SEQ_LEDPHASE_TOTAL_ENDLESS, + .ms = 1500 +}; + +const lws_led_sequence_def_t lws_pwmseq_sine_endless_fast = { + .func = lws_led_func_sine, + .ledphase_offset = 0, /* already at 0 amp at 0 phase */ + .ledphase_total = LWS_SEQ_LEDPHASE_TOTAL_ENDLESS, + .ms = 750 +}; diff -Nru libwebsockets-3.2.1/lib/drivers/README.md libwebsockets-4.1.6/lib/drivers/README.md --- libwebsockets-3.2.1/lib/drivers/README.md 1970-01-01 00:00:00.000000000 +0000 +++ libwebsockets-4.1.6/lib/drivers/README.md 2020-12-01 17:40:26.000000000 +0000 @@ -0,0 +1,44 @@ +# lws meta-drivers + +Although drivers in lws (enabled in cmake by `LWS_WITH_DRIVERS`) provide +actual drivers for some devices like I2C OLED controllers, their main job is +to conceal from user code the underlying OS APIs being used to interface +to the SoC hardware assets. + +CMake already allows lws to be platform-agnostic for build, the plat adaptations +allow lws to be platform-agnostic within itself for runtime. The lws +drivers intend to extend that agnosticism to user code. + +Using this technique on supported OSes frees the user code from dependencies +on the underlying OS choice... for example, although ESP32 is very good, it +comes with a highly specific set of apis in esp-idf that mean your code is +locked in to esp-idf if you follow them. Esp-idf uses freertos apis for things +like OS timers, again if you follow those you are locked into freertos, the +end result is your work is non-portable to other platforms and completely +dependent on esp. + +LWS drivers provide a thin wrapper to eliminate the OS dependencies while +still taking advantage of the work, drivers and maintenance of the underlying +OS layer without duplicating them, but bringing the flexibility to retarget +your work to other scenarios... for example, there is a generic gpio object +subclassed for specific implementations, an i2c object which may be subclassed +to use OS drivers or bitbang using the generic gpio object, buttons on top of +generic gpio, led class that can use generic gpio or pwm interchangeably, +platform-specific gpio, i2c, pwm implementations that can be used at the generic +level are defined to use underlying OS native apis and drivers. + +## Building on the next layer up + +At these generic objects like buttons or led controllers, there is a stable +codebase used by multiple implementations and the intention is to provide +best-of-breed features there generically, like + + - sophisticated button press debounce and classification + + - high quality transitions and log-response compensation and mixing for led pwm + + - display dimming timers, blanking timers, generic interaction detection to unblank + +which are automatically available on top of any implementation that is ported to +lws drivers. + diff -Nru libwebsockets-3.2.1/lib/drivers/settings/settings.c libwebsockets-4.1.6/lib/drivers/settings/settings.c --- libwebsockets-3.2.1/lib/drivers/settings/settings.c 1970-01-01 00:00:00.000000000 +0000 +++ libwebsockets-4.1.6/lib/drivers/settings/settings.c 2020-12-01 17:40:26.000000000 +0000 @@ -0,0 +1,69 @@ +/* + * lws_settings + * + * Copyright (C) 2019 - 2020 Andy Green + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to + * deal in the Software without restriction, including without limitation the + * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or + * sell copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS + * IN THE SOFTWARE. + */ + +#include + +lws_settings_instance_t * +lws_settings_init(const lws_settings_ops_t *so, void *opaque_plat) +{ + lws_settings_instance_t *si = lws_zalloc(sizeof(*si), __func__); + + if (!si) + return NULL; + + si->so = so; + si->opaque_plat = opaque_plat; + + return si; +} + +void +lws_settings_deinit(lws_settings_instance_t **si) +{ + lws_free(*si); + *si = NULL; +} + +int +lws_settings_plat_printf(lws_settings_instance_t *si, const char *name, + const char *format, ...) +{ + va_list ap; + uint8_t *p; + int n; + + va_start(ap, format); + n = vsnprintf(NULL, 0, format, ap); + va_end(ap); + + p = lws_malloc(n + 2, __func__); + va_start(ap, format); + vsnprintf((char *)p, n + 2, format, ap); + va_end(ap); + + n = si->so->set(si, name, p, n); + lws_free(p); + + return n; +} diff -Nru libwebsockets-3.2.1/lib/drivers/spi/bitbang/lws-bb-spi.c libwebsockets-4.1.6/lib/drivers/spi/bitbang/lws-bb-spi.c --- libwebsockets-3.2.1/lib/drivers/spi/bitbang/lws-bb-spi.c 1970-01-01 00:00:00.000000000 +0000 +++ libwebsockets-4.1.6/lib/drivers/spi/bitbang/lws-bb-spi.c 2020-12-01 17:40:26.000000000 +0000 @@ -0,0 +1,126 @@ +/* + * SPI bitbang implementation using generic gpio + * + * Copyright (C) 2019 - 2020 Andy Green + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to + * deal in the Software without restriction, including without limitation the + * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or + * sell copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS + * IN THE SOFTWARE. + */ +#include + +int +lws_bb_spi_init(const lws_spi_ops_t *octx) +{ + lws_bb_spi_t *ctx = (lws_bb_spi_t *)octx; + int n; + + for (n = 0; n < LWS_SPI_BB_MAX_CH; n++) { + if (ctx->flags & (1 << n)) + ctx->gpio->mode(ctx->ncs[n], LWSGGPIO_FL_WRITE); + if (ctx->flags & (1 << (n + 4))) + ctx->gpio->mode(ctx->ncmd[n], LWSGGPIO_FL_WRITE); + } + + ctx->gpio->mode(ctx->clk, LWSGGPIO_FL_WRITE | + ((octx->bus_mode & LWSSPIMODE_CPOL) ? + 0 : LWSGGPIO_FL_START_LOW)); + ctx->gpio->mode(ctx->mosi, LWSGGPIO_FL_WRITE | LWSGGPIO_FL_START_LOW); + ctx->gpio->mode(ctx->miso, LWSGGPIO_FL_READ | LWSGGPIO_FL_PULLUP); + + return 0; +} + +/* if active, prepare DnC before this and call separately for Cmd / Data */ + +static void +lws_bb_spi_write(lws_bb_spi_t *ctx, const uint8_t *buf, size_t len) +{ + uint8_t u, inv = !!(ctx->bb_ops.bus_mode & LWSSPIMODE_CPOL); + + while (len--) { + int n; + + u = *buf++; + + for (n = 0; n < 4; n++) { + ctx->gpio->set(ctx->clk, inv); + ctx->gpio->set(ctx->mosi, !!(u & 0x80)); + ctx->gpio->set(ctx->clk, !inv); + ctx->gpio->set(ctx->clk, inv); + ctx->gpio->set(ctx->mosi, !!(u & 0x40)); + ctx->gpio->set(ctx->clk, !inv); + u <<= 2; + } + } + + ctx->gpio->set(ctx->clk, 0 ^ inv); +} + +static void +lws_bb_spi_read(lws_bb_spi_t *ctx, uint8_t *buf, size_t len) +{ + uint8_t u, inv = !!(ctx->bb_ops.bus_mode & LWSSPIMODE_CPOL); + + while (len--) { + int n; + + for (n = 0; n < 8; n++) { + ctx->gpio->set(ctx->clk, inv); + u = (u << 1) | !!ctx->gpio->read(ctx->miso); + ctx->gpio->set(ctx->mosi, !!(u & 0x80)); + ctx->gpio->set(ctx->clk, !inv); + } + *buf++ = u; + } + + ctx->gpio->set(ctx->clk, 0 ^ inv); +} + +int +lws_bb_spi_queue(const lws_spi_ops_t *octx, const lws_spi_desc_t *desc) +{ + lws_bb_spi_t *ctx = (lws_bb_spi_t *)octx; + const uint8_t *src = desc->src; + + /* clock to idle */ + ctx->gpio->set(ctx->clk, 0 ^ !!(octx->bus_mode & LWSSPIMODE_CPOL)); + /* enable nCS */ + ctx->gpio->set(ctx->ncs[desc->channel], 0); + + if (desc->count_cmd) { + ctx->gpio->set(ctx->ncmd[desc->channel], 0); + lws_bb_spi_write(ctx, src, desc->count_cmd); + ctx->gpio->set(ctx->ncmd[desc->channel], 1); + + src += desc->count_cmd; + } + + if (desc->count_write) + lws_bb_spi_write(ctx, desc->data, desc->count_write); + + if (desc->count_read) + lws_bb_spi_read(ctx, desc->dest, desc->count_read); + + /* disable nCS */ + ctx->gpio->set(ctx->ncs[desc->channel], 1); + + /* clock to idle */ + ctx->gpio->set(ctx->clk, 0 ^ !!(octx->bus_mode & LWSSPIMODE_CPOL)); + + return 0; +} diff -Nru libwebsockets-3.2.1/lib/drivers/spi/lws-spi.c libwebsockets-4.1.6/lib/drivers/spi/lws-spi.c --- libwebsockets-3.2.1/lib/drivers/spi/lws-spi.c 1970-01-01 00:00:00.000000000 +0000 +++ libwebsockets-4.1.6/lib/drivers/spi/lws-spi.c 2020-12-01 17:40:26.000000000 +0000 @@ -0,0 +1,26 @@ +/* + * Generic SPI + * + * Copyright (C) 2019 - 2020 Andy Green + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to + * deal in the Software without restriction, including without limitation the + * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or + * sell copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS + * IN THE SOFTWARE. + */ + +#include + diff -Nru libwebsockets-3.2.1/lib/event-libs/CMakeLists.txt libwebsockets-4.1.6/lib/event-libs/CMakeLists.txt --- libwebsockets-3.2.1/lib/event-libs/CMakeLists.txt 1970-01-01 00:00:00.000000000 +0000 +++ libwebsockets-4.1.6/lib/event-libs/CMakeLists.txt 2020-12-01 17:40:26.000000000 +0000 @@ -0,0 +1,102 @@ +# +# libwebsockets - small server side websockets and web server implementation +# +# Copyright (C) 2010 - 2020 Andy Green +# +# Permission is hereby granted, free of charge, to any person obtaining a copy +# of this software and associated documentation files (the "Software"), to +# deal in the Software without restriction, including without limitation the +# rights to use, copy, modify, merge, publish, distribute, sublicense, and/or +# sell copies of the Software, and to permit persons to whom the Software is +# furnished to do so, subject to the following conditions: +# +# The above copyright notice and this permission notice shall be included in +# all copies or substantial portions of the Software. +# +# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING +# FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS +# IN THE SOFTWARE. +# + +include_directories(.) + +macro(create_evlib_plugin PLUGIN_NAME MAIN_SRC PLUGIN_HDR EVLIB) + + set(PLUGIN_SRCS ${MAIN_SRC}) + + source_group("Headers Private" FILES ${PLUGIN_HDR}) + source_group("Sources" FILES ${MAIN_SRC}) + add_library(websockets-${PLUGIN_NAME} SHARED ${MAIN_SRC} ${PLUGIN_HDR}) + + if (APPLE) + set_property(TARGET websockets-${PLUGIN_NAME} PROPERTY MACOSX_RPATH YES) + endif() + + foreach(libpath ${LWS_DEP_LIB_PATHS}) + target_link_directories(${TEST_NAME} ${libpath}) + endforeach() + + target_link_libraries(websockets-${PLUGIN_NAME} websockets_shared ${EVLIB}) + add_dependencies(websockets-${PLUGIN_NAME} websockets_shared) + + target_include_directories(websockets-${PLUGIN_NAME} PRIVATE + ${PLUGIN_INCLUDE} ${LWS_LIB_BUILD_INC_PATHS}) + + # Set test app specific defines. + # set_property(TARGET ${PLUGIN_NAME} + # PROPERTY COMPILE_DEFINITIONS + # INSTALL_DATADIR="${CMAKE_INSTALL_PREFIX}/evlib-plugins" + #) + + set(CMAKE_POSITION_INDEPENDENT_CODE ON) + + install(TARGETS websockets-${PLUGIN_NAME} + EXPORT LibwebsocketsTargets + LIBRARY DESTINATION "${LWS_INSTALL_LIB_DIR}${LIB_SUFFIX}" + COMPONENT ${PLUGIN_NAME}) + + list(APPEND EVLIB_PLUGINS_LIST websockets-${PLUGIN_NAME}) + +endmacro() + +# +# poll support gets built into the lib as the default +# + +if (LWS_WITH_POLL) + add_subdir_include_directories(poll) +endif() + +if (LWS_WITH_LIBUV OR LWS_WITH_LIBUV_INTERNAL) + add_subdir_include_directories(libuv) + set(LWS_HAVE_UV_VERSION_H ${LWS_HAVE_UV_VERSION_H} PARENT_SCOPE) + set(LWS_HAVE_NEW_UV_VERSION_H ${LWS_HAVE_NEW_UV_VERSION_H} PARENT_SCOPE) +endif() + +if (LWS_WITH_LIBEVENT) + add_subdir_include_directories(libevent) +endif() + +if (LWS_WITH_GLIB) + add_subdir_include_directories(glib) +endif() + +if (LWS_WITH_LIBEV) + add_subdir_include_directories(libev) + set(LWS_HAVE_EVBACKEND_LINUXAIO ${LWS_HAVE_EVBACKEND_LINUXAIO} PARENT_SCOPE) + set(LWS_HAVE_EVBACKEND_IOURING ${LWS_HAVE_EVBACKEND_IOURING} PARENT_SCOPE) +endif() + + + +# +# Keep explicit parent scope exports at end +# + +export_to_parent_intermediate() +set(EVLIB_PLUGINS_LIST ${EVLIB_PLUGINS_LIST} PARENT_SCOPE) + diff -Nru libwebsockets-3.2.1/lib/event-libs/glib/CMakeLists.txt libwebsockets-4.1.6/lib/event-libs/glib/CMakeLists.txt --- libwebsockets-3.2.1/lib/event-libs/glib/CMakeLists.txt 1970-01-01 00:00:00.000000000 +0000 +++ libwebsockets-4.1.6/lib/event-libs/glib/CMakeLists.txt 2020-12-01 17:40:26.000000000 +0000 @@ -0,0 +1,77 @@ +# +# libwebsockets - small server side websockets and web server implementation +# +# Copyright (C) 2010 - 2020 Andy Green +# +# Permission is hereby granted, free of charge, to any person obtaining a copy +# of this software and associated documentation files (the "Software"), to +# deal in the Software without restriction, including without limitation the +# rights to use, copy, modify, merge, publish, distribute, sublicense, and/or +# sell copies of the Software, and to permit persons to whom the Software is +# furnished to do so, subject to the following conditions: +# +# The above copyright notice and this permission notice shall be included in +# all copies or substantial portions of the Software. +# +# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING +# FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS +# IN THE SOFTWARE. +# +# The strategy is to only export to PARENT_SCOPE +# +# - changes to LIB_LIST +# - includes via include_directories +# +# and keep everything else private + +include_directories(.) + +set(LWS_GLIB_INCLUDE_DIRS CACHE PATH "Path to the glib include directory") +set(LWS_GLIB_LIBRARIES CACHE PATH "Path to the glib library") + +include (FindPkgConfig) +if (NOT GLIB_FOUND) + find_path(GLIB_INCLUDE_DIRS NAMES glib-2.0/glib.h) + find_library(GLIB_LIBRARIES NAMES glib-2.0) + if (GLIB_INCLUDE_DIRS AND GLIB_LIBRARIES) + set(GLIB_FOUND) + endif() + if (GLIB_INCLUDE_DIRS) + set(GLIB_INCLUDE_DIRS "${GLIB_INCLUDE_DIRS}/glib-2.0" PARENT_SCOPE) + endif() +endif() +PKG_SEARCH_MODULE(LWS_GLIB2 glib-2.0) +if (LWS_GLIB2_FOUND) + list(APPEND GLIB_INCLUDE_DIRS "${LWS_GLIB2_INCLUDE_DIRS}") +endif() + +message("glib include dir: ${GLIB_INCLUDE_DIRS}") +message("glib libraries: ${GLIB_LIBRARIES}") +include_directories("${GLIB_INCLUDE_DIRS}") + +if (LWS_WITH_EVLIB_PLUGINS) + + create_evlib_plugin(evlib_glib + glib.c + private-lib-event-libs-glib.h + ${GLIB_LIBRARIES}) + +else() + + list(APPEND LIB_LIST ${GLIB_LIBRARIES}) + + if (LWS_WITH_NETWORK) + list(APPEND SOURCES + event-libs/glib/glib.c) + endif() + +endif() +# +# Keep explicit parent scope exports at end +# + +exports_to_parent_scope() diff -Nru libwebsockets-3.2.1/lib/event-libs/glib/glib.c libwebsockets-4.1.6/lib/event-libs/glib/glib.c --- libwebsockets-3.2.1/lib/event-libs/glib/glib.c 1970-01-01 00:00:00.000000000 +0000 +++ libwebsockets-4.1.6/lib/event-libs/glib/glib.c 2020-12-01 17:40:26.000000000 +0000 @@ -0,0 +1,513 @@ +/* + * libwebsockets - small server side websockets and web server implementation + * + * Copyright (C) 2010 - 2020 Andy Green + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to + * deal in the Software without restriction, including without limitation the + * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or + * sell copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS + * IN THE SOFTWARE. + */ + +#include "private-lib-core.h" + +#include + +#include "private-lib-event-libs-glib.h" + +#if !defined(G_SOURCE_FUNC) +#define G_SOURCE_FUNC(f) ((GSourceFunc) (void (*)(void)) (f)) +#endif + +#define pt_to_priv_glib(_pt) ((struct lws_pt_eventlibs_glib *)(_pt)->evlib_pt) +#define wsi_to_priv_glib(_w) ((struct lws_wsi_eventlibs_glib *)(_w)->evlib_wsi) + +#define wsi_to_subclass(_w) (wsi_to_priv_glib(_w)->w_read.source) +#define wsi_to_gsource(_w) ((GSource *)wsi_to_subclass(_w)) +#define pt_to_loop(_pt) (pt_to_priv_glib(_pt)->loop) +#define pt_to_g_main_context(_pt) g_main_loop_get_context(pt_to_loop(_pt)) + +#define lws_gs_valid(t) (t.gs) +#define lws_gs_destroy(t) if (lws_gs_valid(t)) { \ + g_source_destroy(t.gs); \ + g_source_unref(t.gs); \ + t.gs = NULL; t.tag = 0; } + +static gboolean +lws_glib_idle_timer_cb(void *p); + +static gboolean +lws_glib_hrtimer_cb(void *p); + +static gboolean +lws_glib_check(GSource *src) +{ + struct lws_io_watcher_glib_subclass *sub = + (struct lws_io_watcher_glib_subclass *)src; + + return !!g_source_query_unix_fd(src, sub->tag); +} + +/* + * These helpers attach only to the main_context that belongs to the pt's glib + * mainloop. The simpler g_timeout_add() and g_idle_add() are forbidden + * because they implicitly choose the default main context to attach to + * instead of specifically the loop bound to the pt. + * + * https://developer.gnome.org/programming-guidelines/unstable/main-contexts.html.en#what-is-gmaincontext + */ + +static int +lws_glib_set_idle(struct lws_context_per_thread *pt) +{ + if (lws_gs_valid(pt_to_priv_glib(pt)->idle)) + return 0; + + pt_to_priv_glib(pt)->idle.gs = g_idle_source_new(); + if (!pt_to_priv_glib(pt)->idle.gs) + return 1; + + g_source_set_callback(pt_to_priv_glib(pt)->idle.gs, + lws_glib_idle_timer_cb, pt, NULL); + pt_to_priv_glib(pt)->idle.tag = g_source_attach( + pt_to_priv_glib(pt)->idle.gs, pt_to_g_main_context(pt)); + + return 0; +} + +static int +lws_glib_set_timeout(struct lws_context_per_thread *pt, unsigned int ms) +{ + lws_gs_destroy(pt_to_priv_glib(pt)->hrtimer); + + pt_to_priv_glib(pt)->hrtimer.gs = g_timeout_source_new(ms); + if (!pt_to_priv_glib(pt)->hrtimer.gs) + return 1; + + g_source_set_callback(pt_to_priv_glib(pt)->hrtimer.gs, + lws_glib_hrtimer_cb, pt, NULL); + pt_to_priv_glib(pt)->hrtimer.tag = g_source_attach( + pt_to_priv_glib(pt)->hrtimer.gs, + pt_to_g_main_context(pt)); + + return 0; +} + +static gboolean +lws_glib_dispatch(GSource *src, GSourceFunc x, gpointer userData) +{ + struct lws_io_watcher_glib_subclass *sub = + (struct lws_io_watcher_glib_subclass *)src; + struct lws_context_per_thread *pt; + struct lws_pollfd eventfd; + GIOCondition cond; + + cond = g_source_query_unix_fd(src, sub->tag); + eventfd.revents = cond; + + /* translate from glib event namespace to platform */ + + if (cond & G_IO_IN) + eventfd.revents |= LWS_POLLIN; + if (cond & G_IO_OUT) + eventfd.revents |= LWS_POLLOUT; + if (cond & G_IO_ERR) + eventfd.revents |= LWS_POLLHUP; + if (cond & G_IO_HUP) + eventfd.revents |= LWS_POLLHUP; + + eventfd.events = eventfd.revents; + eventfd.fd = sub->wsi->desc.sockfd; + + lwsl_debug("%s: wsi %p: fd %d, events %d\n", __func__, sub->wsi, + eventfd.fd, eventfd.revents); + + pt = &sub->wsi->a.context->pt[(int)sub->wsi->tsi]; + if (pt->is_destroyed) + return G_SOURCE_CONTINUE; + + lws_service_fd_tsi(sub->wsi->a.context, &eventfd, sub->wsi->tsi); + + if (!lws_gs_valid(pt_to_priv_glib(pt)->idle)) + lws_glib_set_idle(pt); + + if (pt->destroy_self) + lws_context_destroy(pt->context); + + return G_SOURCE_CONTINUE; +} + +static const GSourceFuncs lws_glib_source_ops = { + .prepare = NULL, + .check = lws_glib_check, + .dispatch = lws_glib_dispatch, + .finalize = NULL, +}; + +/* + * This is the callback for a timer object that is set to the earliest scheduled + * lws event... it services any lws scheduled events that are ready, and then + * resets the event loop timer to the earliest remaining event, if any. + */ + +static gboolean +lws_glib_hrtimer_cb(void *p) +{ + struct lws_context_per_thread *pt = (struct lws_context_per_thread *)p; + unsigned int ms; + lws_usec_t us; + + lws_pt_lock(pt, __func__); + + lws_gs_destroy(pt_to_priv_glib(pt)->hrtimer); + + us = __lws_sul_service_ripe(pt->pt_sul_owner, LWS_COUNT_PT_SUL_OWNERS, + lws_now_usecs()); + if (us) { + ms = us / LWS_US_PER_MS; + if (!ms) + ms = 1; + + lws_glib_set_timeout(pt, ms); + } + + lws_pt_unlock(pt); + + lws_glib_set_idle(pt); + + return FALSE; /* stop it repeating */ +} + +static gboolean +lws_glib_idle_timer_cb(void *p) +{ + struct lws_context_per_thread *pt = (struct lws_context_per_thread *)p; + + if (pt->is_destroyed) + return FALSE; + + lws_service_do_ripe_rxflow(pt); + lws_glib_hrtimer_cb(pt); + + /* + * is there anybody with pending stuff that needs service forcing? + */ + if (!lws_service_adjust_timeout(pt->context, 1, pt->tid)) { + /* -1 timeout means just do forced service */ + _lws_plat_service_forced_tsi(pt->context, pt->tid); + /* still somebody left who wants forced service? */ + if (!lws_service_adjust_timeout(pt->context, 1, pt->tid)) + return TRUE; + } + + if (pt->destroy_self) + lws_context_destroy(pt->context); + + /* + * For glib, this disables the idle callback. Otherwise we keep + * coming back here immediately endlessly. + * + * We reenable the idle callback on the next network or scheduled event + */ + + lws_gs_destroy(pt_to_priv_glib(pt)->idle); + + return FALSE; +} + +void +lws_glib_sigint_cb(void *ctx) +{ + struct lws_context_per_thread *pt = ctx; + + pt->inside_service = 1; + + if (pt->context->eventlib_signal_cb) { + pt->context->eventlib_signal_cb(NULL, 0); + + return; + } + if (!pt->event_loop_foreign) + g_main_loop_quit(pt_to_loop(pt)); +} + +static int +elops_init_context_glib(struct lws_context *context, + const struct lws_context_creation_info *info) +{ +// int n; + + context->eventlib_signal_cb = info->signal_cb; + +// for (n = 0; n < context->count_threads; n++) +// pt_to_priv_glib(&context->pt[n])->w_sigint.context = context; + + return 0; +} + +static int +elops_accept_glib(struct lws *wsi) +{ + struct lws_context_per_thread *pt = &wsi->a.context->pt[(int)wsi->tsi]; + struct lws_wsi_eventlibs_glib *wsipr = wsi_to_priv_glib(wsi); + int fd; + + assert(!wsi_to_subclass(wsi)); + + wsi_to_subclass(wsi) = (struct lws_io_watcher_glib_subclass *) + g_source_new((GSourceFuncs *)&lws_glib_source_ops, + sizeof(*wsi_to_subclass(wsi))); + if (!wsi_to_subclass(wsi)) + return 1; + + wsipr->w_read.context = wsi->a.context; + wsi_to_subclass(wsi)->wsi = wsi; + + if (wsi->role_ops->file_handle) + fd = wsi->desc.filefd; + else + fd = wsi->desc.sockfd; + + wsi_to_subclass(wsi)->tag = g_source_add_unix_fd(wsi_to_gsource(wsi), + fd, (GIOCondition)LWS_POLLIN); + wsipr->w_read.actual_events = LWS_POLLIN; + + g_source_set_callback(wsi_to_gsource(wsi), + G_SOURCE_FUNC(lws_service_fd), wsi->a.context, NULL); + + g_source_attach(wsi_to_gsource(wsi), pt_to_g_main_context(pt)); + + return 0; +} + +static int +elops_init_pt_glib(struct lws_context *context, void *_loop, int tsi) +{ + struct lws_context_per_thread *pt = &context->pt[tsi]; + struct lws_pt_eventlibs_glib *ptpr = pt_to_priv_glib(pt); + struct lws_vhost *vh = context->vhost_list; + GMainLoop *loop = (GMainLoop *)_loop; + + if (!loop) + loop = g_main_loop_new(NULL, 0); + else + context->pt[tsi].event_loop_foreign = 1; + + if (!loop) { + lwsl_err("%s: creating glib loop failed\n", __func__); + + return -1; + } + + ptpr->loop = loop; + + /* + * Initialize all events with the listening sockets + * and register a callback for read operations + */ + + while (vh) { + if (vh->lserv_wsi) + elops_accept_glib(vh->lserv_wsi); + + vh = vh->vhost_next; + } + + lws_glib_set_idle(pt); + + /* Register the signal watcher unless it's a foreign loop */ + + if (pt->event_loop_foreign) + return 0; + + ptpr->sigint.tag = g_unix_signal_add(SIGINT, + G_SOURCE_FUNC(lws_glib_sigint_cb), pt); + + return 0; +} + +/* + * We are changing the event wait for this guy + */ + +static void +elops_io_glib(struct lws *wsi, int flags) +{ + struct lws_context_per_thread *pt = &wsi->a.context->pt[(int)wsi->tsi]; + struct lws_wsi_eventlibs_glib *wsipr = wsi_to_priv_glib(wsi); + GIOCondition cond = wsipr->w_read.actual_events | G_IO_ERR; + + if (!pt_to_loop(pt) || wsi->a.context->being_destroyed || + pt->is_destroyed) + return; + + if (!wsi_to_subclass(wsi)) + return; + + /* + * We are being given individual set / clear operations using + * LWS_EV_ common namespace, convert them to glib namespace bitfield + */ + + if (flags & LWS_EV_READ) { + if (flags & LWS_EV_STOP) + cond &= ~(G_IO_IN | G_IO_HUP); + else + cond |= G_IO_IN | G_IO_HUP; + } + + if (flags & LWS_EV_WRITE) { + if (flags & LWS_EV_STOP) + cond &= ~G_IO_OUT; + else + cond |= G_IO_OUT; + } + + wsipr->w_read.actual_events = cond; + + lwsl_debug("%s: wsi %p, fd %d, 0x%x/0x%x\n", __func__, wsi, + wsi->desc.sockfd, flags, (int)cond); + + g_source_modify_unix_fd(wsi_to_gsource(wsi), wsi_to_subclass(wsi)->tag, + cond); +} + +static void +elops_run_pt_glib(struct lws_context *context, int tsi) +{ + struct lws_context_per_thread *pt = &context->pt[tsi]; + + if (pt_to_loop(pt)) + g_main_loop_run(pt_to_loop(pt)); +} + +static void +elops_destroy_wsi_glib(struct lws *wsi) +{ + struct lws_context_per_thread *pt; + + if (!wsi) + return; + + pt = &wsi->a.context->pt[(int)wsi->tsi]; + if (pt->is_destroyed) + return; + + if (!wsi_to_gsource(wsi)) + return; + + if (wsi_to_subclass(wsi)->tag) { + g_source_remove_unix_fd(wsi_to_gsource(wsi), + wsi_to_subclass(wsi)->tag); + wsi_to_subclass(wsi)->tag = NULL; + } + + g_source_destroy(wsi_to_gsource(wsi)); + g_source_unref(wsi_to_gsource(wsi)); + wsi_to_subclass(wsi) = NULL; +} + +static void +elops_destroy_pt_glib(struct lws_context *context, int tsi) +{ + struct lws_context_per_thread *pt = &context->pt[tsi]; + struct lws_pt_eventlibs_glib *ptpr = pt_to_priv_glib(pt); + struct lws_vhost *vh = context->vhost_list; + + if (!pt_to_loop(pt)) + return; + + /* + * Free all events with the listening sockets + */ + while (vh) { + if (vh->lserv_wsi) + elops_destroy_wsi_glib(vh->lserv_wsi); + + vh = vh->vhost_next; + } + + lws_gs_destroy(ptpr->idle); + lws_gs_destroy(ptpr->hrtimer); + + if (!pt->event_loop_foreign) { + g_main_loop_quit(pt_to_loop(pt)); + lws_gs_destroy(ptpr->sigint); + g_main_loop_unref(pt_to_loop(pt)); + } + + pt_to_loop(pt) = NULL; +} + +static int +elops_destroy_context2_glib(struct lws_context *context) +{ + struct lws_context_per_thread *pt = &context->pt[0]; + int n; + + for (n = 0; n < (int)context->count_threads; n++) { + if (!pt->event_loop_foreign) + g_main_loop_quit(pt_to_loop(pt)); + pt++; + } + + return 0; +} + +static int +elops_wsi_logical_close_glib(struct lws *wsi) +{ + elops_destroy_wsi_glib(wsi); + + return 0; +} + +static const struct lws_event_loop_ops event_loop_ops_glib = { + /* name */ "glib", + /* init_context */ elops_init_context_glib, + /* destroy_context1 */ NULL, + /* destroy_context2 */ elops_destroy_context2_glib, + /* init_vhost_listen_wsi */ elops_accept_glib, + /* init_pt */ elops_init_pt_glib, + /* wsi_logical_close */ elops_wsi_logical_close_glib, + /* check_client_connect_ok */ NULL, + /* close_handle_manually */ NULL, + /* accept */ elops_accept_glib, + /* io */ elops_io_glib, + /* run_pt */ elops_run_pt_glib, + /* destroy_pt */ elops_destroy_pt_glib, + /* destroy wsi */ elops_destroy_wsi_glib, + + /* flags */ LELOF_DESTROY_FINAL, + + /* evlib_size_ctx */ 0, + /* evlib_size_pt */ sizeof(struct lws_pt_eventlibs_glib), + /* evlib_size_vh */ 0, + /* evlib_size_wsi */ sizeof(struct lws_io_watcher_glib), +}; + +#if defined(LWS_WITH_EVLIB_PLUGINS) +LWS_VISIBLE +#endif +const lws_plugin_evlib_t evlib_glib = { + .hdr = { + "glib event loop", + "lws_evlib_plugin", + LWS_PLUGIN_API_MAGIC + }, + + .ops = &event_loop_ops_glib +}; diff -Nru libwebsockets-3.2.1/lib/event-libs/glib/private-lib-event-libs-glib.h libwebsockets-4.1.6/lib/event-libs/glib/private-lib-event-libs-glib.h --- libwebsockets-3.2.1/lib/event-libs/glib/private-lib-event-libs-glib.h 1970-01-01 00:00:00.000000000 +0000 +++ libwebsockets-4.1.6/lib/event-libs/glib/private-lib-event-libs-glib.h 2020-12-01 17:40:26.000000000 +0000 @@ -0,0 +1,67 @@ +/* + * libwebsockets - small server side websockets and web server implementation + * + * Copyright (C) 2010 - 2020 Andy Green + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to + * deal in the Software without restriction, including without limitation the + * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or + * sell copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS + * IN THE SOFTWARE. + */ + +#if defined(LWS_WITH_GLIB) +#if defined(__APPLE__) +#include +#else +#include +#endif +#endif /* LWS_WITH_GLIB */ + +typedef struct lws_glib_tag { + GSource *gs; + guint tag; +} lws_glib_tag_t; + +struct lws_pt_eventlibs_glib { + GMainLoop *loop; + + lws_glib_tag_t hrtimer; + lws_glib_tag_t sigint; + lws_glib_tag_t idle; + + //struct lws_signal_watcher_libuv w_sigint; +}; + +struct lws_io_watcher_glib_subclass { + GSource base; + struct lws *wsi; + gpointer tag; +}; + +/* + * One of these is embedded in each wsi + */ + +struct lws_io_watcher_glib { + struct lws_io_watcher_glib_subclass *source; /* these are created and destroyed by glib */ + struct lws_context *context; + uint8_t actual_events; +}; + +struct lws_wsi_eventlibs_glib { + struct lws_io_watcher_glib w_read; +}; + diff -Nru libwebsockets-3.2.1/lib/event-libs/libev/CMakeLists.txt libwebsockets-4.1.6/lib/event-libs/libev/CMakeLists.txt --- libwebsockets-3.2.1/lib/event-libs/libev/CMakeLists.txt 1970-01-01 00:00:00.000000000 +0000 +++ libwebsockets-4.1.6/lib/event-libs/libev/CMakeLists.txt 2020-12-01 17:40:26.000000000 +0000 @@ -0,0 +1,88 @@ +# +# libwebsockets - small server side websockets and web server implementation +# +# Copyright (C) 2010 - 2020 Andy Green +# +# Permission is hereby granted, free of charge, to any person obtaining a copy +# of this software and associated documentation files (the "Software"), to +# deal in the Software without restriction, including without limitation the +# rights to use, copy, modify, merge, publish, distribute, sublicense, and/or +# sell copies of the Software, and to permit persons to whom the Software is +# furnished to do so, subject to the following conditions: +# +# The above copyright notice and this permission notice shall be included in +# all copies or substantial portions of the Software. +# +# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING +# FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS +# IN THE SOFTWARE. +# +# The strategy is to only export to PARENT_SCOPE +# +# - changes to LIB_LIST +# - includes via include_directories +# +# and keep everything else private + +include_directories(.) + +set(LWS_LIBEV_LIBRARIES CACHE PATH "Path to the libev library") +set(LWS_LIBEV_INCLUDE_DIRS CACHE PATH "Path to the libev include directory") + +if (NOT LIBEV_FOUND) + find_path(LIBEV_INCLUDE_DIRS NAMES ev.h) + find_library(LIBEV_LIBRARIES NAMES ev) +endif() +message("libev include dir: ${LIBEV_INCLUDE_DIRS}") +message("libev libraries: ${LIBEV_LIBRARIES}") +include_directories("${LIBEV_INCLUDE_DIRS}") + +if ("${LWS_LIBEV_LIBRARIES}" STREQUAL "" OR "${LWS_LIBEV_INCLUDE_DIRS}" STREQUAL "") +else() + set(LIBEV_LIBRARIES ${LWS_LIBEV_LIBRARIES}) + set(LIBEV_INCLUDE_DIRS ${LWS_LIBEV_INCLUDE_DIRS}) +endif() + +if (LWS_WITH_EVLIB_PLUGINS) + + create_evlib_plugin( + evlib_ev + libev.c + private-lib-event-libs-libev.h + ${LIBEV_LIBRARIES}) + +else() + + list(APPEND LIB_LIST ${LIBEV_LIBRARIES}) + + list(APPEND SOURCES + event-libs/libev/libev.c) +# see README.build.md for discussion of why of the supported event libs, +# only libev cannot cope with -Werror + set_source_files_properties(event-libs/libev/libev.c + PROPERTIES COMPILE_FLAGS "-Wno-error" ) +endif() + +set(CMAKE_REQUIRED_LIBRARIES ${LIB_LIST}) + +CHECK_C_SOURCE_COMPILES( + "#include + int main(int argc, char **argv) { return EVBACKEND_LINUXAIO; } + " LWS_HAVE_EVBACKEND_LINUXAIO) + +CHECK_C_SOURCE_COMPILES( + "#include + int main(int argc, char **argv) { return EVBACKEND_IOURING; } + " LWS_HAVE_EVBACKEND_IOURING) + +# +# Keep explicit parent scope exports at end +# + +exports_to_parent_scope() +set(LWS_HAVE_EVBACKEND_LINUXAIO ${LWS_HAVE_EVBACKEND_LINUXAIO} PARENT_SCOPE) +set(LWS_HAVE_EVBACKEND_IOURING ${LWS_HAVE_EVBACKEND_IOURING} PARENT_SCOPE) diff -Nru libwebsockets-3.2.1/lib/event-libs/libev/libev.c libwebsockets-4.1.6/lib/event-libs/libev/libev.c --- libwebsockets-3.2.1/lib/event-libs/libev/libev.c 2019-12-18 14:45:31.000000000 +0000 +++ libwebsockets-4.1.6/lib/event-libs/libev/libev.c 2020-12-01 17:40:26.000000000 +0000 @@ -1,38 +1,48 @@ /* * libwebsockets - small server side websockets and web server implementation * - * Copyright (C) 2010-2018 Andy Green + * Copyright (C) 2010 - 2020 Andy Green * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation: - * version 2.1 of the License. + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to + * deal in the Software without restriction, including without limitation the + * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or + * sell copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: * - * This library is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. * - * You should have received a copy of the GNU Lesser General Public - * License along with this library; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, - * MA 02110-1301 USA + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS + * IN THE SOFTWARE. */ -#include "core/private.h" +#include "private-lib-core.h" +#include "private-lib-event-libs-libev.h" + +#define pt_to_priv_ev(_pt) ((struct lws_pt_eventlibs_libev *)(_pt)->evlib_pt) +#define vh_to_priv_ev(_vh) ((struct lws_vh_eventlibs_libev *)(_vh)->evlib_vh) +#define wsi_to_priv_ev(_w) ((struct lws_wsi_eventlibs_libev *)(_w)->evlib_wsi) static void lws_ev_hrtimer_cb(struct ev_loop *loop, struct ev_timer *watcher, int revents) { - struct lws_context_per_thread *pt = - (struct lws_context_per_thread *)watcher->data; + struct lws_pt_eventlibs_libev *ptpr = lws_container_of(watcher, + struct lws_pt_eventlibs_libev, hrtimer); + struct lws_context_per_thread *pt = ptpr->pt; lws_usec_t us; lws_pt_lock(pt, __func__); - us = __lws_sul_service_ripe(&pt->pt_sul_owner, lws_now_usecs()); + us = __lws_sul_service_ripe(pt->pt_sul_owner, LWS_COUNT_PT_SUL_OWNERS, + lws_now_usecs()); if (us) { - ev_timer_set(&pt->ev.hrtimer, ((float)us) / 1000000.0, 0); - ev_timer_start(pt->ev.io_loop, &pt->ev.hrtimer); + ev_timer_set(&ptpr->hrtimer, ((float)us) / 1000000.0, 0); + ev_timer_start(ptpr->io_loop, &ptpr->hrtimer); } lws_pt_unlock(pt); } @@ -40,8 +50,10 @@ static void lws_ev_idle_cb(struct ev_loop *loop, struct ev_idle *handle, int revents) { - struct lws_context_per_thread *pt = lws_container_of(handle, - struct lws_context_per_thread, ev.idle); + struct lws_pt_eventlibs_libev *ptpr = lws_container_of(handle, + struct lws_pt_eventlibs_libev, idle); + struct lws_context_per_thread *pt = ptpr->pt; + int reschedule = 0; lws_usec_t us; lws_service_do_ripe_rxflow(pt); @@ -51,29 +63,35 @@ */ if (!lws_service_adjust_timeout(pt->context, 1, pt->tid)) /* -1 timeout means just do forced service */ - _lws_plat_service_forced_tsi(pt->context, pt->tid); + reschedule = _lws_plat_service_forced_tsi(pt->context, pt->tid); /* account for hrtimer */ lws_pt_lock(pt, __func__); - us = __lws_sul_service_ripe(&pt->pt_sul_owner, lws_now_usecs()); + us = __lws_sul_service_ripe(pt->pt_sul_owner, LWS_COUNT_PT_SUL_OWNERS, + lws_now_usecs()); if (us) { - ev_timer_set(&pt->ev.hrtimer, ((float)us) / 1000000.0, 0); - ev_timer_start(pt->ev.io_loop, &pt->ev.hrtimer); + ev_timer_set(&ptpr->hrtimer, ((float)us) / 1000000.0, 0); + ev_timer_start(ptpr->io_loop, &ptpr->hrtimer); } lws_pt_unlock(pt); /* there is nobody who needs service forcing, shut down idle */ - ev_idle_stop(loop, handle); + if (!reschedule) + ev_idle_stop(loop, handle); + + if (pt->destroy_self) + lws_context_destroy(pt->context); } static void lws_accept_cb(struct ev_loop *loop, struct ev_io *watcher, int revents) { - struct lws_context_per_thread *pt; - struct lws_io_watcher *lws_io = lws_container_of(watcher, - struct lws_io_watcher, ev.watcher); + struct lws_io_watcher_libev *lws_io = lws_container_of(watcher, + struct lws_io_watcher_libev, watcher); struct lws_context *context = lws_io->context; + struct lws_pt_eventlibs_libev *ptpr; + struct lws_context_per_thread *pt; struct lws_pollfd eventfd; struct lws *wsi; @@ -95,13 +113,14 @@ wsi = wsi_from_fd(context, watcher->fd); pt = &context->pt[(int)wsi->tsi]; + ptpr = pt_to_priv_ev(pt); lws_service_fd_tsi(context, &eventfd, (int)wsi->tsi); - ev_idle_start(pt->ev.io_loop, &pt->ev.idle); + ev_idle_start(ptpr->io_loop, &ptpr->idle); } -LWS_VISIBLE void +void lws_ev_sigint_cb(struct ev_loop *loop, struct ev_signal *watcher, int revents) { struct lws_context *context = watcher->data; @@ -118,15 +137,18 @@ elops_init_pt_ev(struct lws_context *context, void *_loop, int tsi) { struct lws_context_per_thread *pt = &context->pt[tsi]; - struct ev_signal *w_sigint = &context->pt[tsi].w_sigint.ev.watcher; + struct lws_pt_eventlibs_libev *ptpr = pt_to_priv_ev(pt); + struct ev_signal *w_sigint = &ptpr->w_sigint.watcher; + struct ev_loop *loop = (struct ev_loop *)_loop; struct lws_vhost *vh = context->vhost_list; const char *backend_name; - struct ev_loop *loop = (struct ev_loop *)_loop; int status = 0; int backend; lwsl_info("%s: loop %p\n", __func__, _loop); + ptpr->pt = pt; + if (!loop) loop = ev_loop_new(0); else @@ -138,7 +160,7 @@ return -1; } - pt->ev.io_loop = loop; + ptpr->io_loop = loop; /* * Initialize the accept w_accept with all the listening sockets @@ -146,13 +168,17 @@ */ while (vh) { if (vh->lserv_wsi) { - vh->lserv_wsi->w_read.context = context; - vh->w_accept.context = context; + struct lws_wsi_eventlibs_libev *w = + wsi_to_priv_ev(vh->lserv_wsi); - ev_io_init(&vh->w_accept.ev.watcher, lws_accept_cb, - vh->lserv_wsi->desc.sockfd, EV_READ); - ev_io_start(loop, &vh->w_accept.ev.watcher); + w->w_read.context = context; + w->w_write.context = context; + vh_to_priv_ev(vh)->w_accept.context = context; + ev_io_init(&vh_to_priv_ev(vh)->w_accept.watcher, + lws_accept_cb, + vh->lserv_wsi->desc.sockfd, EV_READ); + ev_io_start(loop, &vh_to_priv_ev(vh)->w_accept.watcher); } vh = vh->vhost_next; } @@ -175,7 +201,17 @@ case EVBACKEND_EPOLL: backend_name = "epoll"; break; - case EVBACKEND_KQUEUE: +#if defined(LWS_HAVE_EVBACKEND_LINUXAIO) + case EVBACKEND_LINUXAIO: + backend_name = "Linux AIO"; + break; +#endif +#if defined(LWS_HAVE_EVBACKEND_IOURING) + case EVBACKEND_IOURING: + backend_name = "Linux io_uring"; + break; +#endif + case EVBACKEND_KQUEUE: backend_name = "kqueue"; break; case EVBACKEND_DEVPOLL: @@ -192,10 +228,10 @@ lwsl_info(" libev backend: %s\n", backend_name); (void)backend_name; - ev_timer_init(&pt->ev.hrtimer, lws_ev_hrtimer_cb, 0, 0); - pt->ev.hrtimer.data = pt; + ev_timer_init(&ptpr->hrtimer, lws_ev_hrtimer_cb, 0, 0); + ptpr->hrtimer.data = pt; - ev_idle_init(&pt->ev.idle, lws_ev_idle_cb); + ev_idle_init(&ptpr->idle, lws_ev_idle_cb); return status; } @@ -204,24 +240,23 @@ elops_destroy_pt_ev(struct lws_context *context, int tsi) { struct lws_context_per_thread *pt = &context->pt[tsi]; + struct lws_pt_eventlibs_libev *ptpr = pt_to_priv_ev(pt); struct lws_vhost *vh = context->vhost_list; while (vh) { if (vh->lserv_wsi) - ev_io_stop(pt->ev.io_loop, &vh->w_accept.ev.watcher); + ev_io_stop(ptpr->io_loop, + &vh_to_priv_ev(vh)->w_accept.watcher); vh = vh->vhost_next; } /* static assets */ - ev_timer_stop(pt->ev.io_loop, &pt->ev.hrtimer); - ev_idle_stop(pt->ev.io_loop, &pt->ev.idle); + ev_timer_stop(ptpr->io_loop, &ptpr->hrtimer); + ev_idle_stop(ptpr->io_loop, &ptpr->idle); - if (!pt->event_loop_foreign) { - ev_signal_stop(pt->ev.io_loop, &pt->w_sigint.ev.watcher); - - ev_loop_destroy(pt->ev.io_loop); - } + if (!pt->event_loop_foreign) + ev_signal_stop(ptpr->io_loop, &ptpr->w_sigint.watcher); } static int @@ -233,7 +268,7 @@ context->eventlib_signal_cb = info->signal_cb; for (n = 0; n < context->count_threads; n++) - context->pt[n].w_sigint.context = context; + pt_to_priv_ev(&context->pt[n])->w_sigint.context = context; return 0; } @@ -241,18 +276,21 @@ static int elops_accept_ev(struct lws *wsi) { + struct lws_wsi_eventlibs_libev *w = wsi_to_priv_ev(wsi); int fd; + lwsl_notice("%s\n", __func__); + if (wsi->role_ops->file_handle) fd = wsi->desc.filefd; else fd = wsi->desc.sockfd; - wsi->w_read.context = wsi->context; - wsi->w_write.context = wsi->context; + w->w_read.context = wsi->a.context; + w->w_write.context = wsi->a.context; - ev_io_init(&wsi->w_read.ev.watcher, lws_accept_cb, fd, EV_READ); - ev_io_init(&wsi->w_write.ev.watcher, lws_accept_cb, fd, EV_WRITE); + ev_io_init(&w->w_read.watcher, lws_accept_cb, fd, EV_READ); + ev_io_init(&w->w_write.watcher, lws_accept_cb, fd, EV_WRITE); return 0; } @@ -260,9 +298,15 @@ static void elops_io_ev(struct lws *wsi, int flags) { - struct lws_context_per_thread *pt = &wsi->context->pt[(int)wsi->tsi]; + struct lws_context_per_thread *pt = &wsi->a.context->pt[(int)wsi->tsi]; + struct lws_pt_eventlibs_libev *ptpr = pt_to_priv_ev(pt); + struct lws_wsi_eventlibs_libev *w = wsi_to_priv_ev(wsi); + + lwsl_notice("%s: wsi %p %s flags 0x%x %p %d\n", __func__, + wsi, wsi->role_ops->name, flags, + ptpr->io_loop, pt->is_destroyed); - if (!pt->ev.io_loop) + if (!ptpr->io_loop || pt->is_destroyed) return; assert((flags & (LWS_EV_START | LWS_EV_STOP)) && @@ -270,28 +314,32 @@ if (flags & LWS_EV_START) { if (flags & LWS_EV_WRITE) - ev_io_start(pt->ev.io_loop, &wsi->w_write.ev.watcher); + ev_io_start(ptpr->io_loop, &w->w_write.watcher); if (flags & LWS_EV_READ) - ev_io_start(pt->ev.io_loop, &wsi->w_read.ev.watcher); + ev_io_start(ptpr->io_loop, &w->w_read.watcher); } else { if (flags & LWS_EV_WRITE) - ev_io_stop(pt->ev.io_loop, &wsi->w_write.ev.watcher); + ev_io_stop(ptpr->io_loop, &w->w_write.watcher); if (flags & LWS_EV_READ) - ev_io_stop(pt->ev.io_loop, &wsi->w_read.ev.watcher); + ev_io_stop(ptpr->io_loop, &w->w_read.watcher); } + + if (pt->destroy_self) + lws_context_destroy(pt->context); } static void elops_run_pt_ev(struct lws_context *context, int tsi) { - if (context->pt[tsi].ev.io_loop) - ev_run(context->pt[tsi].ev.io_loop, 0); + if (pt_to_priv_ev(&context->pt[tsi])->io_loop) + ev_run(pt_to_priv_ev(&context->pt[tsi])->io_loop, 0); } static int elops_destroy_context2_ev(struct lws_context *context) { struct lws_context_per_thread *pt; + struct lws_pt_eventlibs_libev *ptpr; int n, m; lwsl_debug("%s\n", __func__); @@ -300,21 +348,22 @@ int budget = 1000; pt = &context->pt[n]; + ptpr = pt_to_priv_ev(pt); /* only for internal loops... */ - if (pt->event_loop_foreign || !pt->ev.io_loop) + if (pt->event_loop_foreign || !ptpr->io_loop) continue; if (!context->finalize_destroy_after_internal_loops_stopped) { - ev_break(pt->ev.io_loop, EVBREAK_ONE); + ev_break(ptpr->io_loop, EVBREAK_ONE); continue; } while (budget-- && - (m = ev_run(pt->ev.io_loop, 0))) + (m = ev_run(ptpr->io_loop, 0))) ; - ev_loop_destroy(pt->ev.io_loop); + ev_loop_destroy(ptpr->io_loop); } return 0; @@ -323,6 +372,7 @@ static int elops_init_vhost_listen_wsi_ev(struct lws *wsi) { + struct lws_wsi_eventlibs_libev *w; int fd; if (!wsi) { @@ -330,16 +380,17 @@ return 0; } - wsi->w_read.context = wsi->context; - wsi->w_write.context = wsi->context; + w = wsi_to_priv_ev(wsi); + w->w_read.context = wsi->a.context; + w->w_write.context = wsi->a.context; if (wsi->role_ops->file_handle) fd = wsi->desc.filefd; else fd = wsi->desc.sockfd; - ev_io_init(&wsi->w_read.ev.watcher, lws_accept_cb, fd, EV_READ); - ev_io_init(&wsi->w_write.ev.watcher, lws_accept_cb, fd, EV_WRITE); + ev_io_init(&w->w_read.watcher, lws_accept_cb, fd, EV_READ); + //ev_io_init(&w->w_write.watcher, lws_accept_cb, fd, EV_WRITE); elops_io_ev(wsi, LWS_EV_START | LWS_EV_READ); @@ -349,13 +400,15 @@ static void elops_destroy_wsi_ev(struct lws *wsi) { - struct lws_context_per_thread *pt = &wsi->context->pt[(int)wsi->tsi]; + struct lws_context_per_thread *pt = &wsi->a.context->pt[(int)wsi->tsi]; + struct lws_pt_eventlibs_libev *ptpr = pt_to_priv_ev(pt); + struct lws_wsi_eventlibs_libev *w = wsi_to_priv_ev(wsi); - ev_io_stop(pt->ev.io_loop, &wsi->w_read.ev.watcher); - ev_io_stop(pt->ev.io_loop, &wsi->w_write.ev.watcher); + ev_io_stop(ptpr->io_loop, &w->w_read.watcher); + ev_io_stop(ptpr->io_loop, &w->w_write.watcher); } -struct lws_event_loop_ops event_loop_ops_ev = { +static const struct lws_event_loop_ops event_loop_ops_ev = { /* name */ "libev", /* init_context */ elops_init_context_ev, /* destroy_context1 */ NULL, @@ -371,5 +424,23 @@ /* destroy_pt */ elops_destroy_pt_ev, /* destroy wsi */ elops_destroy_wsi_ev, - /* periodic_events_available */ 0, + /* flags */ 0, + + /* evlib_size_ctx */ 0, + /* evlib_size_pt */ sizeof(struct lws_pt_eventlibs_libev), + /* evlib_size_vh */ sizeof(struct lws_vh_eventlibs_libev), + /* evlib_size_wsi */ sizeof(struct lws_wsi_eventlibs_libev), +}; + +#if defined(LWS_WITH_EVLIB_PLUGINS) +LWS_VISIBLE +#endif +const lws_plugin_evlib_t evlib_ev = { + .hdr = { + "libev event loop", + "lws_evlib_plugin", + LWS_PLUGIN_API_MAGIC + }, + + .ops = &event_loop_ops_ev }; diff -Nru libwebsockets-3.2.1/lib/event-libs/libev/private.h libwebsockets-4.1.6/lib/event-libs/libev/private.h --- libwebsockets-3.2.1/lib/event-libs/libev/private.h 2019-12-18 14:45:31.000000000 +0000 +++ libwebsockets-4.1.6/lib/event-libs/libev/private.h 1970-01-01 00:00:00.000000000 +0000 @@ -1,53 +0,0 @@ -/* - * libwebsockets - small server side websockets and web server implementation - * - * Copyright (C) 2010 - 2018 Andy Green - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation: - * version 2.1 of the License. - * - * This library is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with this library; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, - * MA 02110-1301 USA - * - * This is included from core/private.h if LWS_WITH_LIBEV - */ - -#include - -#define LWS_EV_REFCOUNT_STATIC_HANDLE_NEW(_x, _ctx) \ - { (_x)->data = _ctx; \ - _ctx->count_event_loop_static_asset_handles++; } -#define LWS_EV_REFCOUNT_STATIC_HANDLE_TO_CONTEXT(_x) \ - ((struct lws_context *)(_x)->data))) -#define LWS_EV_REFCOUNT_STATIC_HANDLE_DESTROYED(_x) \ - (--(LWS_UV_REFCOUNT_STATIC_HANDLE_TO_CONTEXT(_x)-> \ - count_event_loop_static_asset_handles)) - -struct lws_pt_eventlibs_libev { - struct ev_loop *io_loop; - struct ev_timer hrtimer; - struct ev_idle idle; -}; - -struct lws_io_watcher_libev { - ev_io watcher; -}; - -struct lws_signal_watcher_libev { - ev_signal watcher; -}; - -struct lws_context_eventlibs_libev { - int placeholder; -}; - -extern struct lws_event_loop_ops event_loop_ops_ev; diff -Nru libwebsockets-3.2.1/lib/event-libs/libev/private-lib-event-libs-libev.h libwebsockets-4.1.6/lib/event-libs/libev/private-lib-event-libs-libev.h --- libwebsockets-3.2.1/lib/event-libs/libev/private-lib-event-libs-libev.h 1970-01-01 00:00:00.000000000 +0000 +++ libwebsockets-4.1.6/lib/event-libs/libev/private-lib-event-libs-libev.h 2020-12-01 17:40:26.000000000 +0000 @@ -0,0 +1,62 @@ +/* + * libwebsockets - small server side websockets and web server implementation + * + * Copyright (C) 2010 - 2019 Andy Green + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to + * deal in the Software without restriction, including without limitation the + * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or + * sell copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS + * IN THE SOFTWARE. + */ + +#include + +#define LWS_EV_REFCOUNT_STATIC_HANDLE_NEW(_x, _ctx) \ + { (_x)->data = _ctx; \ + _ctx->count_event_loop_static_asset_handles++; } +#define LWS_EV_REFCOUNT_STATIC_HANDLE_TO_CONTEXT(_x) \ + ((struct lws_context *)(_x)->data))) +#define LWS_EV_REFCOUNT_STATIC_HANDLE_DESTROYED(_x) \ + (--(LWS_UV_REFCOUNT_STATIC_HANDLE_TO_CONTEXT(_x)-> \ + count_event_loop_static_asset_handles)) + +struct lws_signal_watcher_libev { + ev_signal watcher; + struct lws_context *context; +}; + +struct lws_pt_eventlibs_libev { + struct ev_loop *io_loop; + struct ev_timer hrtimer; + struct ev_idle idle; + struct lws_signal_watcher_libev w_sigint; + struct lws_context_per_thread *pt; +}; + +struct lws_io_watcher_libev { + ev_io watcher; + struct lws_context *context; +}; + +struct lws_vh_eventlibs_libev { + struct lws_io_watcher_libev w_accept; +}; + +struct lws_wsi_eventlibs_libev { + struct lws_io_watcher_libev w_read; + struct lws_io_watcher_libev w_write; +}; + diff -Nru libwebsockets-3.2.1/lib/event-libs/libevent/CMakeLists.txt libwebsockets-4.1.6/lib/event-libs/libevent/CMakeLists.txt --- libwebsockets-3.2.1/lib/event-libs/libevent/CMakeLists.txt 1970-01-01 00:00:00.000000000 +0000 +++ libwebsockets-4.1.6/lib/event-libs/libevent/CMakeLists.txt 2020-12-01 17:40:26.000000000 +0000 @@ -0,0 +1,72 @@ +# +# libwebsockets - small server side websockets and web server implementation +# +# Copyright (C) 2010 - 2020 Andy Green +# +# Permission is hereby granted, free of charge, to any person obtaining a copy +# of this software and associated documentation files (the "Software"), to +# deal in the Software without restriction, including without limitation the +# rights to use, copy, modify, merge, publish, distribute, sublicense, and/or +# sell copies of the Software, and to permit persons to whom the Software is +# furnished to do so, subject to the following conditions: +# +# The above copyright notice and this permission notice shall be included in +# all copies or substantial portions of the Software. +# +# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING +# FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS +# IN THE SOFTWARE. +# +# The strategy is to only export to PARENT_SCOPE +# +# - changes to LIB_LIST +# - includes via include_directories +# +# and keep everything else private + +include_directories(.) + +set(LWS_LIBEVENT_INCLUDE_DIRS CACHE PATH "Path to the libevent include directory") +set(LWS_LIBEVENT_LIBRARIES CACHE PATH "Path to the libevent library") + +if (NOT LIBEVENT_FOUND) + find_path(LIBEVENT_INCLUDE_DIRS NAMES event2/event.h) + find_library(LIBEVENT_LIBRARIES NAMES event) +endif() +message("libevent include dir: ${LIBEVENT_INCLUDE_DIRS}") +message("libevent libraries: ${LIBEVENT_LIBRARIES}") +include_directories("${LIBEVENT_INCLUDE_DIRS}") + +if ("${LWS_LIBEVENT_LIBRARIES}" STREQUAL "" OR "${LWS_LIBEVENT_INCLUDE_DIRS}" STREQUAL "") +else() + set(LIBEVENT_LIBRARIES ${LWS_LIBEVENT_LIBRARIES}) + set(LIBEVENT_INCLUDE_DIRS ${LWS_LIBEVENT_INCLUDE_DIRS}) +endif() + + +if (LWS_WITH_EVLIB_PLUGINS) + + create_evlib_plugin(evlib_event + libevent.c + private-lib-event-libs-libevent.h + ${LIBEVENT_LIBRARIES}) + +else() + + list(APPEND LIB_LIST ${LIBEVENT_LIBRARIES}) + set(LIBEVENT_FOUND 1 PARENT_SCOPE) + if (LWS_WITH_NETWORK) + list(APPEND SOURCES + event-libs/libevent/libevent.c) + endif() +endif() + +# +# Keep explicit parent scope exports at end +# + +exports_to_parent_scope() diff -Nru libwebsockets-3.2.1/lib/event-libs/libevent/libevent.c libwebsockets-4.1.6/lib/event-libs/libevent/libevent.c --- libwebsockets-3.2.1/lib/event-libs/libevent/libevent.c 2019-12-18 14:45:31.000000000 +0000 +++ libwebsockets-4.1.6/lib/event-libs/libevent/libevent.c 2020-12-01 17:40:26.000000000 +0000 @@ -1,50 +1,63 @@ /* * libwebsockets - small server side websockets and web server implementation * - * Copyright (C) 2010-2018 Andy Green + * Copyright (C) 2010 - 2019 Andy Green * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation: - * version 2.1 of the License. + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to + * deal in the Software without restriction, including without limitation the + * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or + * sell copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: * - * This library is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. * - * You should have received a copy of the GNU Lesser General Public - * License along with this library; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, - * MA 02110-1301 USA + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS + * IN THE SOFTWARE. */ -#include "core/private.h" +#include "private-lib-core.h" +#include "private-lib-event-libs-libevent.h" + +#define pt_to_priv_event(_pt) ((struct lws_pt_eventlibs_libevent *)(_pt)->evlib_pt) +#define wsi_to_priv_event(_w) ((struct lws_wsi_eventlibs_libevent *)(_w)->evlib_wsi) static void -lws_event_hrtimer_cb(int fd, short event, void *p) +lws_event_hrtimer_cb(evutil_socket_t fd, short event, void *p) { struct lws_context_per_thread *pt = (struct lws_context_per_thread *)p; + struct lws_pt_eventlibs_libevent *ptpr = pt_to_priv_event(pt); struct timeval tv; lws_usec_t us; lws_pt_lock(pt, __func__); - us = __lws_sul_service_ripe(&pt->pt_sul_owner, lws_now_usecs()); + us = __lws_sul_service_ripe(pt->pt_sul_owner, LWS_COUNT_PT_SUL_OWNERS, + lws_now_usecs()); if (us) { tv.tv_sec = us / LWS_US_PER_SEC; tv.tv_usec = us - (tv.tv_sec * LWS_US_PER_SEC); - evtimer_add(pt->event.hrtimer, &tv); + evtimer_add(ptpr->hrtimer, &tv); } lws_pt_unlock(pt); } static void -lws_event_idle_timer_cb(int fd, short event, void *p) +lws_event_idle_timer_cb(evutil_socket_t fd, short event, void *p) { struct lws_context_per_thread *pt = (struct lws_context_per_thread *)p; + struct lws_pt_eventlibs_libevent *ptpr = pt_to_priv_event(pt); struct timeval tv; lws_usec_t us; + if (pt->is_destroyed) + return; + lws_service_do_ripe_rxflow(pt); /* @@ -59,7 +72,7 @@ tv.tv_sec = 0; tv.tv_usec = 1000; - evtimer_add(pt->event.idle_timer, &tv); + evtimer_add(ptpr->idle_timer, &tv); return; } @@ -70,19 +83,24 @@ /* account for hrtimer */ lws_pt_lock(pt, __func__); - us = __lws_sul_service_ripe(&pt->pt_sul_owner, lws_now_usecs()); + us = __lws_sul_service_ripe(pt->pt_sul_owner, LWS_COUNT_PT_SUL_OWNERS, + lws_now_usecs()); if (us) { tv.tv_sec = us / LWS_US_PER_SEC; tv.tv_usec = us - (tv.tv_sec * LWS_US_PER_SEC); - evtimer_add(pt->event.hrtimer, &tv); + evtimer_add(ptpr->hrtimer, &tv); } lws_pt_unlock(pt); + + if (pt->destroy_self) + lws_context_destroy(pt->context); } static void lws_event_cb(evutil_socket_t sock_fd, short revents, void *ctx) { - struct lws_io_watcher *lws_io = (struct lws_io_watcher *)ctx; + struct lws_signal_watcher_libevent *lws_io = + (struct lws_signal_watcher_libevent *)ctx; struct lws_context *context = lws_io->context; struct lws_context_per_thread *pt; struct lws_pollfd eventfd; @@ -114,25 +132,33 @@ } wsi = wsi_from_fd(context, sock_fd); - if (!wsi) { + if (!wsi) return; - } + pt = &context->pt[(int)wsi->tsi]; + if (pt->is_destroyed) + return; lws_service_fd_tsi(context, &eventfd, wsi->tsi); + if (pt->destroy_self) { + lwsl_notice("%s: pt destroy self coming true\n", __func__); + lws_context_destroy(pt->context); + return; + } + /* set the idle timer for 1ms ahead */ tv.tv_sec = 0; tv.tv_usec = 1000; - evtimer_add(pt->event.idle_timer, &tv); + evtimer_add(pt_to_priv_event(pt)->idle_timer, &tv); } -LWS_VISIBLE void +void lws_event_sigint_cb(evutil_socket_t sock_fd, short revents, void *ctx) { struct lws_context_per_thread *pt = ctx; - struct event *signal = (struct event *)ctx; + struct event *signal = pt_to_priv_event(pt)->w_sigint.watcher; if (pt->context->eventlib_signal_cb) { pt->context->eventlib_signal_cb((void *)(lws_intptr_t)sock_fd, @@ -141,16 +167,16 @@ return; } if (!pt->event_loop_foreign) - event_base_loopbreak(pt->event.io_loop); + event_base_loopbreak(pt_to_priv_event(pt)->io_loop); } - static int elops_init_pt_event(struct lws_context *context, void *_loop, int tsi) { struct lws_vhost *vh = context->vhost_list; struct event_base *loop = (struct event_base *)_loop; struct lws_context_per_thread *pt = &context->pt[tsi]; + struct lws_pt_eventlibs_libevent *ptpr = pt_to_priv_event(pt); lwsl_info("%s: loop %p\n", __func__, _loop); @@ -165,7 +191,7 @@ return -1; } - pt->event.io_loop = loop; + ptpr->io_loop = loop; /* * Initialize all events with the listening sockets @@ -174,22 +200,26 @@ while (vh) { if (vh->lserv_wsi) { - vh->lserv_wsi->w_read.context = context; - vh->lserv_wsi->w_read.event.watcher = event_new( + struct lws_io_watcher_libevent *w_read = + &(wsi_to_priv_event(vh->lserv_wsi)->w_read); + + w_read->context = context; + w_read->watcher = event_new( loop, vh->lserv_wsi->desc.sockfd, (EV_READ | EV_PERSIST), lws_event_cb, - &vh->lserv_wsi->w_read); - event_add(vh->lserv_wsi->w_read.event.watcher, NULL); + w_read); + event_add(w_read->watcher, NULL); + w_read->set = 1; } vh = vh->vhost_next; } /* static event loop objects */ - pt->event.hrtimer = event_new(loop, -1, EV_PERSIST, + ptpr->hrtimer = event_new(loop, -1, EV_PERSIST, lws_event_hrtimer_cb, pt); - pt->event.idle_timer = event_new(loop, -1, 0, + ptpr->idle_timer = event_new(loop, -1, 0, lws_event_idle_timer_cb, pt); /* Register the signal watcher unless it's a foreign loop */ @@ -197,9 +227,9 @@ if (pt->event_loop_foreign) return 0; - pt->w_sigint.event.watcher = evsignal_new(loop, SIGINT, + ptpr->w_sigint.watcher = evsignal_new(loop, SIGINT, lws_event_sigint_cb, pt); - event_add(pt->w_sigint.event.watcher, NULL); + event_add(ptpr->w_sigint.watcher, NULL); return 0; } @@ -213,7 +243,7 @@ context->eventlib_signal_cb = info->signal_cb; for (n = 0; n < context->count_threads; n++) - context->pt[n].w_sigint.context = context; + pt_to_priv_event(&context->pt[n])->w_sigint.context = context; return 0; } @@ -223,23 +253,26 @@ { struct lws_context *context = lws_get_context(wsi); struct lws_context_per_thread *pt; - int fd; + struct lws_pt_eventlibs_libevent *ptpr; + struct lws_wsi_eventlibs_libevent *wpr = wsi_to_priv_event(wsi); + evutil_socket_t fd; - wsi->w_read.context = context; - wsi->w_write.context = context; + wpr->w_read.context = context; + wpr->w_write.context = context; // Initialize the event pt = &context->pt[(int)wsi->tsi]; + ptpr = pt_to_priv_event(pt); if (wsi->role_ops->file_handle) - fd = wsi->desc.filefd; + fd = (ev_intptr_t) wsi->desc.filefd; else fd = wsi->desc.sockfd; - wsi->w_read.event.watcher = event_new(pt->event.io_loop, fd, - (EV_READ | EV_PERSIST), lws_event_cb, &wsi->w_read); - wsi->w_write.event.watcher = event_new(pt->event.io_loop, fd, - (EV_WRITE | EV_PERSIST), lws_event_cb, &wsi->w_write); + wpr->w_read.watcher = event_new(ptpr->io_loop, fd, + (EV_READ | EV_PERSIST), lws_event_cb, &wpr->w_read); + wpr->w_write.watcher = event_new(ptpr->io_loop, fd, + (EV_WRITE | EV_PERSIST), lws_event_cb, &wpr->w_write); return 0; } @@ -247,26 +280,37 @@ static void elops_io_event(struct lws *wsi, int flags) { - struct lws_context_per_thread *pt = &wsi->context->pt[(int)wsi->tsi]; + struct lws_context_per_thread *pt = &wsi->a.context->pt[(int)wsi->tsi]; + struct lws_pt_eventlibs_libevent *ptpr = pt_to_priv_event(pt); + struct lws_wsi_eventlibs_libevent *wpr = wsi_to_priv_event(wsi); - if (!pt->event.io_loop || wsi->context->being_destroyed) + if (!ptpr->io_loop || wsi->a.context->being_destroyed || + pt->is_destroyed) return; assert((flags & (LWS_EV_START | LWS_EV_STOP)) && (flags & (LWS_EV_READ | LWS_EV_WRITE))); if (flags & LWS_EV_START) { - if (flags & LWS_EV_WRITE) - event_add(wsi->w_write.event.watcher, NULL); + if ((flags & LWS_EV_WRITE) && !wpr->w_write.set) { + event_add(wpr->w_write.watcher, NULL); + wpr->w_write.set = 1; + } - if (flags & LWS_EV_READ) - event_add(wsi->w_read.event.watcher, NULL); + if ((flags & LWS_EV_READ) && !wpr->w_read.set) { + event_add(wpr->w_read.watcher, NULL); + wpr->w_read.set = 1; + } } else { - if (flags & LWS_EV_WRITE) - event_del(wsi->w_write.event.watcher); + if ((flags & LWS_EV_WRITE) && wpr->w_write.set) { + event_del(wpr->w_write.watcher); + wpr->w_write.set = 0; + } - if (flags & LWS_EV_READ) - event_del(wsi->w_read.event.watcher); + if ((flags & LWS_EV_READ) && wpr->w_read.set) { + event_del(wpr->w_read.watcher); + wpr->w_read.set = 0; + } } } @@ -274,19 +318,21 @@ elops_run_pt_event(struct lws_context *context, int tsi) { /* Run / Dispatch the event_base loop */ - if (context->pt[tsi].event.io_loop) - event_base_dispatch(context->pt[tsi].event.io_loop); + if (pt_to_priv_event(&context->pt[tsi])->io_loop) + event_base_dispatch( + pt_to_priv_event(&context->pt[tsi])->io_loop); } static void elops_destroy_pt_event(struct lws_context *context, int tsi) { struct lws_context_per_thread *pt = &context->pt[tsi]; + struct lws_pt_eventlibs_libevent *ptpr = pt_to_priv_event(pt); struct lws_vhost *vh = context->vhost_list; lwsl_info("%s\n", __func__); - if (!pt->event.io_loop) + if (!ptpr->io_loop) return; /* @@ -294,65 +340,95 @@ */ while (vh) { if (vh->lserv_wsi) { - event_free(vh->lserv_wsi->w_read.event.watcher); - vh->lserv_wsi->w_read.event.watcher = NULL; - event_free(vh->lserv_wsi->w_write.event.watcher); - vh->lserv_wsi->w_write.event.watcher = NULL; + struct lws_wsi_eventlibs_libevent *w = + wsi_to_priv_event(vh->lserv_wsi); + + event_free(w->w_read.watcher); + w->w_read.watcher = NULL; + event_free(w->w_write.watcher); + w->w_write.watcher = NULL; } vh = vh->vhost_next; } - event_free(pt->event.hrtimer); - event_free(pt->event.idle_timer); + event_free(ptpr->hrtimer); + event_free(ptpr->idle_timer); if (!pt->event_loop_foreign) { - event_del(pt->w_sigint.event.watcher); - event_free(pt->w_sigint.event.watcher); - - event_base_free(pt->event.io_loop); + event_del(ptpr->w_sigint.watcher); + event_free(ptpr->w_sigint.watcher); + event_base_loopexit(ptpr->io_loop, NULL); + // event_base_free(pt->event.io_loop); + // pt->event.io_loop = NULL; + lwsl_notice("%s: set to exit loop\n", __func__); } } static void elops_destroy_wsi_event(struct lws *wsi) { + struct lws_context_per_thread *pt; + struct lws_wsi_eventlibs_libevent *w; + if (!wsi) return; - if (wsi->w_read.event.watcher) - event_free(wsi->w_read.event.watcher); + pt = &wsi->a.context->pt[(int)wsi->tsi]; + if (pt->is_destroyed) + return; + + w = wsi_to_priv_event(wsi); + + if (w->w_read.watcher) { + event_free(w->w_read.watcher); + w->w_read.watcher = NULL; + } + + if (w->w_write.watcher) { + event_free(w->w_write.watcher); + w->w_write.watcher = NULL; + } +} + +static int +elops_wsi_logical_close_event(struct lws *wsi) +{ + elops_destroy_wsi_event(wsi); - if (wsi->w_write.event.watcher) - event_free(wsi->w_write.event.watcher); + return 0; } static int elops_init_vhost_listen_wsi_event(struct lws *wsi) { struct lws_context_per_thread *pt; - int fd; + struct lws_pt_eventlibs_libevent *ptpr; + struct lws_wsi_eventlibs_libevent *w; + evutil_socket_t fd; if (!wsi) { assert(0); return 0; } - wsi->w_read.context = wsi->context; - wsi->w_write.context = wsi->context; + w = wsi_to_priv_event(wsi); - pt = &wsi->context->pt[(int)wsi->tsi]; + w->w_read.context = wsi->a.context; + w->w_write.context = wsi->a.context; + + pt = &wsi->a.context->pt[(int)wsi->tsi]; + ptpr = pt_to_priv_event(pt); if (wsi->role_ops->file_handle) - fd = wsi->desc.filefd; + fd = (evutil_socket_t) wsi->desc.filefd; else fd = wsi->desc.sockfd; - wsi->w_read.event.watcher = event_new(pt->event.io_loop, fd, - (EV_READ | EV_PERSIST), - lws_event_cb, &wsi->w_read); - wsi->w_write.event.watcher = event_new(pt->event.io_loop, fd, - (EV_WRITE | EV_PERSIST), - lws_event_cb, &wsi->w_write); + w->w_read.watcher = event_new(ptpr->io_loop, fd, (EV_READ | EV_PERSIST), + lws_event_cb, &w->w_read); + w->w_write.watcher = event_new(ptpr->io_loop, fd, + (EV_WRITE | EV_PERSIST), + lws_event_cb, &w->w_write); elops_io_event(wsi, LWS_EV_START | LWS_EV_READ); @@ -363,6 +439,7 @@ elops_destroy_context2_event(struct lws_context *context) { struct lws_context_per_thread *pt; + struct lws_pt_eventlibs_libevent *ptpr; int n, m; lwsl_debug("%s: in\n", __func__); @@ -371,29 +448,31 @@ int budget = 1000; pt = &context->pt[n]; + ptpr = pt_to_priv_event(pt); /* only for internal loops... */ - if (pt->event_loop_foreign || !pt->event.io_loop) + if (pt->event_loop_foreign || !ptpr->io_loop) continue; if (!context->finalize_destroy_after_internal_loops_stopped) { - event_base_loopexit(pt->event.io_loop, NULL); + event_base_loopexit(ptpr->io_loop, NULL); continue; } while (budget-- && - (m = event_base_loop(pt->event.io_loop, EVLOOP_NONBLOCK))) + (m = event_base_loop(ptpr->io_loop, EVLOOP_NONBLOCK))) ; #if 0 if (m) { lwsl_err("%s: tsi %d: NOT everything closed\n", __func__, n); - event_base_dump_events(pt->event.io_loop, stderr); + event_base_dump_events(ptpr->io_loop, stderr); } else lwsl_debug("%s: %d: everything closed OK\n", __func__, n); #endif - event_base_free(pt->event.io_loop); - + lwsl_err("%s: event_base_free\n", __func__); + event_base_free(ptpr->io_loop); + ptpr->io_loop = NULL; } lwsl_debug("%s: out\n", __func__); @@ -401,14 +480,14 @@ return 0; } -struct lws_event_loop_ops event_loop_ops_event = { +static const struct lws_event_loop_ops event_loop_ops_event = { /* name */ "libevent", /* init_context */ elops_init_context_event, /* destroy_context1 */ NULL, /* destroy_context2 */ elops_destroy_context2_event, /* init_vhost_listen_wsi */ elops_init_vhost_listen_wsi_event, /* init_pt */ elops_init_pt_event, - /* wsi_logical_close */ NULL, + /* wsi_logical_close */ elops_wsi_logical_close_event, /* check_client_connect_ok */ NULL, /* close_handle_manually */ NULL, /* accept */ elops_accept_event, @@ -417,5 +496,23 @@ /* destroy_pt */ elops_destroy_pt_event, /* destroy wsi */ elops_destroy_wsi_event, - /* periodic_events_available */ 0, + /* flags */ 0, + + /* evlib_size_ctx */ 0, + /* evlib_size_pt */ sizeof(struct lws_pt_eventlibs_libevent), + /* evlib_size_vh */ 0, + /* evlib_size_wsi */ sizeof(struct lws_wsi_eventlibs_libevent), +}; + +#if defined(LWS_WITH_EVLIB_PLUGINS) +LWS_VISIBLE +#endif +const lws_plugin_evlib_t evlib_event = { + .hdr = { + "libevent event loop", + "lws_evlib_plugin", + LWS_PLUGIN_API_MAGIC + }, + + .ops = &event_loop_ops_event }; diff -Nru libwebsockets-3.2.1/lib/event-libs/libevent/private.h libwebsockets-4.1.6/lib/event-libs/libevent/private.h --- libwebsockets-3.2.1/lib/event-libs/libevent/private.h 2019-12-18 14:45:31.000000000 +0000 +++ libwebsockets-4.1.6/lib/event-libs/libevent/private.h 1970-01-01 00:00:00.000000000 +0000 @@ -1,44 +0,0 @@ -/* - * libwebsockets - small server side websockets and web server implementation - * - * Copyright (C) 2010 - 2018 Andy Green - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation: - * version 2.1 of the License. - * - * This library is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with this library; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, - * MA 02110-1301 USA - * - * This is included from core/private.h if LWS_WITH_LIBEVENT - */ - -#include - -struct lws_pt_eventlibs_libevent { - struct event_base *io_loop; - struct event *hrtimer; - struct event *idle_timer; -}; - -struct lws_io_watcher_libevent { - struct event *watcher; -}; - -struct lws_signal_watcher_libevent { - struct event *watcher; -}; - -struct lws_context_eventlibs_libevent { - int placeholder; -}; - -extern struct lws_event_loop_ops event_loop_ops_event; diff -Nru libwebsockets-3.2.1/lib/event-libs/libevent/private-lib-event-libs-libevent.h libwebsockets-4.1.6/lib/event-libs/libevent/private-lib-event-libs-libevent.h --- libwebsockets-3.2.1/lib/event-libs/libevent/private-lib-event-libs-libevent.h 1970-01-01 00:00:00.000000000 +0000 +++ libwebsockets-4.1.6/lib/event-libs/libevent/private-lib-event-libs-libevent.h 2020-12-01 17:40:26.000000000 +0000 @@ -0,0 +1,49 @@ +/* + * libwebsockets - small server side websockets and web server implementation + * + * Copyright (C) 2010 - 2019 Andy Green + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to + * deal in the Software without restriction, including without limitation the + * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or + * sell copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS + * IN THE SOFTWARE. + */ + +#include + +struct lws_signal_watcher_libevent { + struct event *watcher; + struct lws_context *context; +}; + +struct lws_pt_eventlibs_libevent { + struct event_base *io_loop; + struct event *hrtimer; + struct event *idle_timer; + struct lws_signal_watcher_libevent w_sigint; +}; + +struct lws_io_watcher_libevent { + struct event *watcher; + struct lws_context *context; + uint8_t actual_events; + char set; +}; + +struct lws_wsi_eventlibs_libevent { + struct lws_io_watcher_libevent w_read; + struct lws_io_watcher_libevent w_write; +}; diff -Nru libwebsockets-3.2.1/lib/event-libs/libuv/CMakeLists.txt libwebsockets-4.1.6/lib/event-libs/libuv/CMakeLists.txt --- libwebsockets-3.2.1/lib/event-libs/libuv/CMakeLists.txt 1970-01-01 00:00:00.000000000 +0000 +++ libwebsockets-4.1.6/lib/event-libs/libuv/CMakeLists.txt 2020-12-01 17:40:26.000000000 +0000 @@ -0,0 +1,85 @@ +# +# libwebsockets - small server side websockets and web server implementation +# +# Copyright (C) 2010 - 2020 Andy Green +# +# Permission is hereby granted, free of charge, to any person obtaining a copy +# of this software and associated documentation files (the "Software"), to +# deal in the Software without restriction, including without limitation the +# rights to use, copy, modify, merge, publish, distribute, sublicense, and/or +# sell copies of the Software, and to permit persons to whom the Software is +# furnished to do so, subject to the following conditions: +# +# The above copyright notice and this permission notice shall be included in +# all copies or substantial portions of the Software. +# +# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING +# FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS +# IN THE SOFTWARE. +# +# The strategy is to only export to PARENT_SCOPE +# +# - changes to LIB_LIST +# - includes via include_directories +# +# and keep everything else private + +include_directories(.) + +set(LWS_LIBUV_LIBRARIES CACHE PATH "Path to the libuv library") +set(LWS_LIBUV_INCLUDE_DIRS CACHE PATH "Path to the libuv include directory") + +if ("${LWS_LIBUV_LIBRARIES}" STREQUAL "" OR "${LWS_LIBUV_INCLUDE_DIRS}" STREQUAL "") + if (NOT LIBUV_FOUND) + find_path(LIBUV_INCLUDE_DIRS NAMES uv.h) + find_library(LIBUV_LIBRARIES NAMES uv) + endif() +else() + set(LIBUV_LIBRARIES ${LWS_LIBUV_LIBRARIES}) + set(LIBUV_INCLUDE_DIRS ${LWS_LIBUV_INCLUDE_DIRS}) +endif() + +message("libuv include dir: ${LIBUV_INCLUDE_DIRS}") +message("libuv libraries: ${LIBUV_LIBRARIES}") + +include_directories("${LIBUV_INCLUDE_DIRS}") + +CHECK_INCLUDE_FILE(uv-version.h LWS_HAVE_UV_VERSION_H) + # libuv changed the location in 1.21.0. Retain both + # checks temporarily to ensure a smooth transition. + if (NOT LWS_HAVE_UV_VERSION_H) + CHECK_INCLUDE_FILE(uv/version.h LWS_HAVE_NEW_UV_VERSION_H) + endif() + + if (LWS_WITH_EVLIB_PLUGINS AND LWS_WITH_LIBUV) + + create_evlib_plugin(evlib_uv + libuv.c + private-lib-event-libs-libuv.h + ${LIBUV_LIBRARIES}) + endif() + + # wanting libuv in the library is a separate question than + # wanting libuv as a selectable event loop plugin + # we only came here because LWS_WITH_LIBUV or LWS_WITH_LIBUV_INTERNAL + + if ((NOT LWS_WITH_EVLIB_PLUGINS) OR LWS_WITH_LIBUV_INTERNAL) + list(APPEND LIB_LIST ${LIBUV_LIBRARIES}) + + if (LWS_WITH_NETWORK) + list(APPEND SOURCES + event-libs/libuv/libuv.c) + endif() + endif() + +# +# Keep explicit parent scope exports at end +# + +exports_to_parent_scope() +set(LWS_HAVE_UV_VERSION_H ${LWS_HAVE_UV_VERSION_H} PARENT_SCOPE) +set(LWS_HAVE_NEW_UV_VERSION_H ${LWS_HAVE_NEW_UV_VERSION_H} PARENT_SCOPE) diff -Nru libwebsockets-3.2.1/lib/event-libs/libuv/libuv.c libwebsockets-4.1.6/lib/event-libs/libuv/libuv.c --- libwebsockets-3.2.1/lib/event-libs/libuv/libuv.c 2019-12-18 14:45:31.000000000 +0000 +++ libwebsockets-4.1.6/lib/event-libs/libuv/libuv.c 2020-12-01 17:40:26.000000000 +0000 @@ -1,25 +1,32 @@ /* * libwebsockets - small server side websockets and web server implementation * - * Copyright (C) 2010-2018 Andy Green + * Copyright (C) 2010 - 2019 Andy Green * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation: - * version 2.1 of the License. + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to + * deal in the Software without restriction, including without limitation the + * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or + * sell copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: * - * This library is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. * - * You should have received a copy of the GNU Lesser General Public - * License along with this library; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, - * MA 02110-1301 USA + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS + * IN THE SOFTWARE. */ -#include "core/private.h" +#include "private-lib-core.h" +#include "private-lib-event-libs-libuv.h" + +#define pt_to_priv_uv(_pt) ((struct lws_pt_eventlibs_libuv *)(_pt)->evlib_pt) +#define wsi_to_priv_uv(_w) ((struct lws_wsi_eventlibs_libuv *)(_w)->evlib_wsi) static void lws_uv_sultimer_cb(uv_timer_t *timer @@ -28,16 +35,20 @@ #endif ) { - struct lws_context_per_thread *pt = lws_container_of(timer, - struct lws_context_per_thread, uv.sultimer); + struct lws_pt_eventlibs_libuv *ptpr = lws_container_of(timer, + struct lws_pt_eventlibs_libuv, sultimer); + struct lws_context_per_thread *pt = ptpr->pt; lws_usec_t us; + lws_context_lock(pt->context, __func__); lws_pt_lock(pt, __func__); - us = __lws_sul_service_ripe(&pt->pt_sul_owner, lws_now_usecs()); + us = __lws_sul_service_ripe(pt->pt_sul_owner, LWS_COUNT_PT_SUL_OWNERS, + lws_now_usecs()); if (us) - uv_timer_start(&pt->uv.sultimer, lws_uv_sultimer_cb, + uv_timer_start(&pt_to_priv_uv(pt)->sultimer, lws_uv_sultimer_cb, LWS_US_TO_MS(us), 0); lws_pt_unlock(pt); + lws_context_unlock(pt->context); } static void @@ -46,13 +57,16 @@ , int status #endif ) -{ - struct lws_context_per_thread *pt = lws_container_of(handle, - struct lws_context_per_thread, uv.idle); +{ struct lws_pt_eventlibs_libuv *ptpr = lws_container_of(handle, + struct lws_pt_eventlibs_libuv, idle); + struct lws_context_per_thread *pt = ptpr->pt; lws_usec_t us; lws_service_do_ripe_rxflow(pt); + lws_context_lock(pt->context, __func__); + lws_pt_lock(pt, __func__); + /* * is there anybody with pending stuff that needs service forcing? */ @@ -62,25 +76,33 @@ /* account for sultimer */ - lws_pt_lock(pt, __func__); - us = __lws_sul_service_ripe(&pt->pt_sul_owner, lws_now_usecs()); + us = __lws_sul_service_ripe(pt->pt_sul_owner, LWS_COUNT_PT_SUL_OWNERS, + lws_now_usecs()); if (us) - uv_timer_start(&pt->uv.sultimer, lws_uv_sultimer_cb, + uv_timer_start(&pt_to_priv_uv(pt)->sultimer, lws_uv_sultimer_cb, LWS_US_TO_MS(us), 0); - lws_pt_unlock(pt); /* there is nobody who needs service forcing, shut down idle */ uv_idle_stop(handle); + + lws_pt_unlock(pt); + lws_context_unlock(pt->context); } static void lws_io_cb(uv_poll_t *watcher, int status, int revents) { struct lws *wsi = (struct lws *)((uv_handle_t *)watcher)->data; - struct lws_context *context = wsi->context; + struct lws_context *context = wsi->a.context; struct lws_context_per_thread *pt = &context->pt[(int)wsi->tsi]; struct lws_pollfd eventfd; + lws_context_lock(pt->context, __func__); + lws_pt_lock(pt, __func__); + + if (pt->is_destroyed) + goto bail; + #if defined(WIN32) || defined(_WIN32) eventfd.fd = watcher->socket; #else @@ -97,7 +119,7 @@ * You might want to return; instead of servicing the fd in * some cases */ if (status == UV_EAGAIN) - return; + goto bail; eventfd.events |= LWS_POLLHUP; eventfd.revents |= LWS_POLLHUP; @@ -111,9 +133,23 @@ eventfd.revents |= LWS_POLLOUT; } } + + lws_pt_unlock(pt); + lws_context_unlock(pt->context); + lws_service_fd_tsi(context, &eventfd, wsi->tsi); - uv_idle_start(&pt->uv.idle, lws_uv_idle); + if (pt->destroy_self) { + lws_context_destroy(pt->context); + return; + } + + uv_idle_start(&pt_to_priv_uv(pt)->idle, lws_uv_idle); + return; + +bail: + lws_pt_unlock(pt); + lws_context_unlock(pt->context); } /* @@ -148,7 +184,7 @@ pt = &context->pt[m]; if (pt->pipe_wsi) { - uv_poll_stop(pt->pipe_wsi->w_read.uv.pwatcher); + uv_poll_stop(wsi_to_priv_uv(pt->pipe_wsi)->w_read.pwatcher); lws_destroy_event_pipe(pt->pipe_wsi); pt->pipe_wsi = NULL; } @@ -218,8 +254,8 @@ for (n = 0; n < context->count_threads; n++) { struct lws_context_per_thread *pt = &context->pt[n]; - if (pt->uv.io_loop && !pt->event_loop_foreign) - uv_stop(pt->uv.io_loop); + if (pt_to_priv_uv(pt)->io_loop && !pt->event_loop_foreign) + uv_stop(pt_to_priv_uv(pt)->io_loop); } if (!context->pt[0].event_loop_foreign) { @@ -236,7 +272,7 @@ * .... when the libuv object is created... */ -LWS_VISIBLE void +void lws_libuv_static_refcount_add(uv_handle_t *h, struct lws_context *context) { LWS_UV_REFCOUNT_STATIC_HANDLE_NEW(h, context); @@ -246,7 +282,7 @@ * ... and in the close callback when the object is closed. */ -LWS_VISIBLE void +void lws_libuv_static_refcount_del(uv_handle_t *h) { lws_uv_close_cb_sa(h); @@ -263,27 +299,27 @@ uv_close(handle, lws_uv_close_cb); } -LWS_VISIBLE void +void lws_close_all_handles_in_loop(uv_loop_t *loop) { uv_walk(loop, lws_uv_walk_cb, NULL); } -LWS_VISIBLE void +void lws_libuv_stop_without_kill(const struct lws_context *context, int tsi) { - if (context->pt[tsi].uv.io_loop) - uv_stop(context->pt[tsi].uv.io_loop); + if (pt_to_priv_uv(&context->pt[tsi])->io_loop) + uv_stop(pt_to_priv_uv(&context->pt[tsi])->io_loop); } -LWS_VISIBLE uv_loop_t * +uv_loop_t * lws_uv_getloop(struct lws_context *context, int tsi) { - if (context->pt[tsi].uv.io_loop) - return context->pt[tsi].uv.io_loop; + if (pt_to_priv_uv(&context->pt[tsi])->io_loop) + return pt_to_priv_uv(&context->pt[tsi])->io_loop; return NULL; } @@ -291,7 +327,7 @@ int lws_libuv_check_watcher_active(struct lws *wsi) { - uv_handle_t *h = (uv_handle_t *)wsi->w_read.uv.pwatcher; + uv_handle_t *h = (uv_handle_t *)wsi_to_priv_uv(wsi)->w_read.pwatcher; if (!h) return 0; @@ -299,169 +335,6 @@ return uv_is_active(h); } - -#if defined(LWS_WITH_PLUGINS) && (UV_VERSION_MAJOR > 0) - -int -lws_uv_plugins_init(struct lws_context *context, const char * const *d) -{ - struct lws_plugin_capability lcaps; - struct lws_plugin *plugin; - lws_plugin_init_func initfunc; - int m, ret = 0; - void *v; - uv_dirent_t dent; - uv_fs_t req; - char path[256]; - uv_lib_t lib; - int pofs = 0; - -#if defined(__MINGW32__) || !defined(WIN32) - pofs = 3; -#endif - - lib.errmsg = NULL; - lib.handle = NULL; - - uv_loop_init(&context->uv.loop); - - lwsl_notice(" Plugins:\n"); - - while (d && *d) { - - lwsl_notice(" Scanning %s\n", *d); - m =uv_fs_scandir(&context->uv.loop, &req, *d, 0, NULL); - if (m < 1) { - lwsl_err("Scandir on %s failed\n", *d); - return 1; - } - - while (uv_fs_scandir_next(&req, &dent) != UV_EOF) { - if (strlen(dent.name) < 7) - continue; - - lwsl_notice(" %s\n", dent.name); - - lws_snprintf(path, sizeof(path) - 1, "%s/%s", *d, - dent.name); - if (uv_dlopen(path, &lib)) { - uv_dlerror(&lib); - lwsl_err("Error loading DSO: %s\n", lib.errmsg); - uv_dlclose(&lib); - goto bail; - } - - /* we could open it, can we get his init function? */ - -#if !defined(WIN32) && !defined(__MINGW32__) - m = lws_snprintf(path, sizeof(path) - 1, "init_%s", - dent.name + pofs /* snip lib... */); - path[m - 3] = '\0'; /* snip the .so */ -#else - m = lws_snprintf(path, sizeof(path) - 1, "init_%s", - dent.name + pofs); - path[m - 4] = '\0'; /* snip the .dll */ -#endif - if (uv_dlsym(&lib, path, &v)) { - uv_dlerror(&lib); - lwsl_err("Failed to get %s on %s: %s", path, - dent.name, lib.errmsg); - uv_dlclose(&lib); - goto bail; - } - initfunc = (lws_plugin_init_func)v; - lcaps.api_magic = LWS_PLUGIN_API_MAGIC; - m = initfunc(context, &lcaps); - if (m) { - lwsl_err("Init %s failed %d\n", dent.name, m); - goto skip; - } - - plugin = lws_malloc(sizeof(*plugin), "plugin"); - if (!plugin) { - uv_dlclose(&lib); - lwsl_err("OOM\n"); - goto bail; - } - plugin->list = context->plugin_list; - context->plugin_list = plugin; - lws_strncpy(plugin->name, dent.name, sizeof(plugin->name)); - plugin->lib = lib; - plugin->caps = lcaps; - context->plugin_protocol_count += lcaps.count_protocols; - context->plugin_extension_count += lcaps.count_extensions; - - continue; - -skip: - uv_dlclose(&lib); - } -bail: - uv_fs_req_cleanup(&req); - d++; - } - - return ret; -} - -int -lws_uv_plugins_destroy(struct lws_context *context) -{ - struct lws_plugin *plugin = context->plugin_list, *p; - lws_plugin_destroy_func func; - char path[256]; - int pofs = 0; - void *v; - int m; - -#if defined(__MINGW32__) || !defined(WIN32) - pofs = 3; -#endif - - if (!plugin) - return 0; - - while (plugin) { - p = plugin; - -#if !defined(WIN32) && !defined(__MINGW32__) - m = lws_snprintf(path, sizeof(path) - 1, "destroy_%s", - plugin->name + pofs); - path[m - 3] = '\0'; -#else - m = lws_snprintf(path, sizeof(path) - 1, "destroy_%s", - plugin->name + pofs); - path[m - 4] = '\0'; -#endif - - if (uv_dlsym(&plugin->lib, path, &v)) { - uv_dlerror(&plugin->lib); - lwsl_err("Failed to get %s on %s: %s", path, - plugin->name, plugin->lib.errmsg); - } else { - func = (lws_plugin_destroy_func)v; - m = func(context); - if (m) - lwsl_err("Destroying %s failed %d\n", - plugin->name, m); - } - - uv_dlclose(&p->lib); - plugin = p->list; - p->list = NULL; - free(p); - } - - context->plugin_list = NULL; - - while (uv_loop_close(&context->uv.loop)) - ; - - return 0; -} - -#endif - static int elops_init_context_uv(struct lws_context *context, const struct lws_context_creation_info *info) @@ -471,7 +344,7 @@ context->eventlib_signal_cb = info->signal_cb; for (n = 0; n < context->count_threads; n++) - context->pt[n].w_sigint.context = context; + pt_to_priv_uv(&context->pt[n])->w_sigint.context = context; return 0; } @@ -490,11 +363,11 @@ if (!pt->event_loop_foreign) { - while (budget-- && (m = uv_run(pt->uv.io_loop, + while (budget-- && (m = uv_run(pt_to_priv_uv(pt)->io_loop, UV_RUN_NOWAIT))) ; if (m) - lwsl_err("%s: tsi %d: not all closed\n", + lwsl_info("%s: tsi %d: not all closed\n", __func__, n); } @@ -515,15 +388,15 @@ /* only for internal loops... */ - if (!pt->event_loop_foreign && pt->uv.io_loop) { + if (!pt->event_loop_foreign && pt_to_priv_uv(pt)->io_loop) { internal = 1; if (!context->finalize_destroy_after_internal_loops_stopped) - uv_stop(pt->uv.io_loop); + uv_stop(pt_to_priv_uv(pt)->io_loop); else { #if UV_VERSION_MAJOR > 0 - uv_loop_close(pt->uv.io_loop); + uv_loop_close(pt_to_priv_uv(pt)->io_loop); #endif - lws_free_set_NULL(pt->uv.io_loop); + lws_free_set_NULL(pt_to_priv_uv(pt)->io_loop); } } } @@ -534,14 +407,15 @@ static int elops_wsi_logical_close_uv(struct lws *wsi) { - if (!lws_socket_is_valid(wsi->desc.sockfd)) + if (!lws_socket_is_valid(wsi->desc.sockfd) && + wsi->role_ops && strcmp(wsi->role_ops->name, "raw-file")) return 0; if (wsi->listener || wsi->event_pipe) { lwsl_debug("%s: %p: %d %d stop listener / pipe poll\n", __func__, wsi, wsi->listener, wsi->event_pipe); - if (wsi->w_read.uv.pwatcher) - uv_poll_stop(wsi->w_read.uv.pwatcher); + if (wsi_to_priv_uv(wsi)->w_read.pwatcher) + uv_poll_stop(wsi_to_priv_uv(wsi)->w_read.pwatcher); } lwsl_debug("%s: lws_libuv_closehandle: wsi %p\n", __func__, wsi); /* @@ -575,7 +449,7 @@ static void elops_close_handle_manually_uv(struct lws *wsi) { - uv_handle_t *h = (uv_handle_t *)wsi->w_read.uv.pwatcher; + uv_handle_t *h = (uv_handle_t *)wsi_to_priv_uv(wsi)->w_read.pwatcher; lwsl_debug("%s: lws_libuv_closehandle: wsi %p\n", __func__, wsi); @@ -591,7 +465,7 @@ */ wsi->desc.sockfd = LWS_SOCK_INVALID; - wsi->w_read.uv.pwatcher = NULL; + wsi_to_priv_uv(wsi)->w_read.pwatcher = NULL; wsi->told_event_loop_closed = 1; uv_close(h, lws_libuv_closewsi_m); @@ -600,24 +474,23 @@ static int elops_accept_uv(struct lws *wsi) { - struct lws_context_per_thread *pt = &wsi->context->pt[(int)wsi->tsi]; + struct lws_context_per_thread *pt = &wsi->a.context->pt[(int)wsi->tsi]; + struct lws_io_watcher_libuv *w_read = &wsi_to_priv_uv(wsi)->w_read; - wsi->w_read.context = wsi->context; + w_read->context = wsi->a.context; - wsi->w_read.uv.pwatcher = - lws_malloc(sizeof(*wsi->w_read.uv.pwatcher), "uvh"); - if (!wsi->w_read.uv.pwatcher) + w_read->pwatcher = lws_malloc(sizeof(*w_read->pwatcher), "uvh"); + if (!w_read->pwatcher) return -1; if (wsi->role_ops->file_handle) - uv_poll_init(pt->uv.io_loop, wsi->w_read.uv.pwatcher, - (int)(long long)wsi->desc.filefd); + uv_poll_init(pt_to_priv_uv(pt)->io_loop, w_read->pwatcher, + (int)(lws_intptr_t)wsi->desc.filefd); else - uv_poll_init_socket(pt->uv.io_loop, - wsi->w_read.uv.pwatcher, - wsi->desc.sockfd); + uv_poll_init_socket(pt_to_priv_uv(pt)->io_loop, + w_read->pwatcher, wsi->desc.sockfd); - ((uv_handle_t *)wsi->w_read.uv.pwatcher)->data = (void *)wsi; + ((uv_handle_t *)w_read->pwatcher)->data = (void *)wsi; return 0; } @@ -625,15 +498,15 @@ static void elops_io_uv(struct lws *wsi, int flags) { - struct lws_context_per_thread *pt = &wsi->context->pt[(int)wsi->tsi]; - struct lws_io_watcher *w = &wsi->w_read; + struct lws_context_per_thread *pt = &wsi->a.context->pt[(int)wsi->tsi]; + struct lws_io_watcher_libuv *w = &(wsi_to_priv_uv(wsi)->w_read); int current_events = w->actual_events & (UV_READABLE | UV_WRITABLE); lwsl_debug("%s: %p: %d\n", __func__, wsi, flags); /* w->context is set after the loop is initialized */ - if (!pt->uv.io_loop || !w->context) { + if (!pt_to_priv_uv(pt)->io_loop || !w->context) { lwsl_info("%s: no io loop yet\n", __func__); return; } @@ -644,8 +517,8 @@ assert(0); } - if (!w->uv.pwatcher || wsi->told_event_loop_closed) { - lwsl_err("%s: no watcher\n", __func__); + if (!w->pwatcher || wsi->told_event_loop_closed) { + lwsl_info("%s: no watcher\n", __func__); return; } @@ -657,7 +530,7 @@ if (flags & LWS_EV_READ) current_events |= UV_READABLE; - uv_poll_start(w->uv.pwatcher, current_events, lws_io_cb); + uv_poll_start(w->pwatcher, current_events, lws_io_cb); } else { if (flags & LWS_EV_WRITE) current_events &= ~UV_WRITABLE; @@ -666,10 +539,9 @@ current_events &= ~UV_READABLE; if (!(current_events & (UV_READABLE | UV_WRITABLE))) - uv_poll_stop(w->uv.pwatcher); + uv_poll_stop(w->pwatcher); else - uv_poll_start(w->uv.pwatcher, current_events, - lws_io_cb); + uv_poll_start(w->pwatcher, current_events, lws_io_cb); } w->actual_events = current_events; @@ -679,26 +551,29 @@ elops_init_vhost_listen_wsi_uv(struct lws *wsi) { struct lws_context_per_thread *pt; + struct lws_io_watcher_libuv *w_read; int n; if (!wsi) return 0; - if (wsi->w_read.context) + + w_read = &wsi_to_priv_uv(wsi)->w_read; + + if (w_read->context) return 0; - pt = &wsi->context->pt[(int)wsi->tsi]; - if (!pt->uv.io_loop) + pt = &wsi->a.context->pt[(int)wsi->tsi]; + if (!pt_to_priv_uv(pt)->io_loop) return 0; - wsi->w_read.context = wsi->context; + w_read->context = wsi->a.context; - wsi->w_read.uv.pwatcher = - lws_malloc(sizeof(*wsi->w_read.uv.pwatcher), "uvh"); - if (!wsi->w_read.uv.pwatcher) + w_read->pwatcher = lws_malloc(sizeof(*w_read->pwatcher), "uvh"); + if (!w_read->pwatcher) return -1; - n = uv_poll_init_socket(pt->uv.io_loop, wsi->w_read.uv.pwatcher, - wsi->desc.sockfd); + n = uv_poll_init_socket(pt_to_priv_uv(pt)->io_loop, + w_read->pwatcher, wsi->desc.sockfd); if (n) { lwsl_err("uv_poll_init failed %d, sockfd=%p\n", n, (void *)(lws_intptr_t)wsi->desc.sockfd); @@ -706,7 +581,7 @@ return -1; } - ((uv_handle_t *)wsi->w_read.uv.pwatcher)->data = (void *)wsi; + ((uv_handle_t *)w_read->pwatcher)->data = (void *)wsi; elops_io_uv(wsi, LWS_EV_START | LWS_EV_READ); @@ -716,8 +591,8 @@ static void elops_run_pt_uv(struct lws_context *context, int tsi) { - if (context->pt[tsi].uv.io_loop) - uv_run(context->pt[tsi].uv.io_loop, 0); + if (pt_to_priv_uv(&context->pt[tsi])->io_loop) + uv_run(pt_to_priv_uv(&context->pt[tsi])->io_loop, 0); } static void @@ -731,7 +606,7 @@ if (!lws_check_opt(context->options, LWS_SERVER_OPTION_LIBUV)) return; - if (!pt->uv.io_loop) + if (!pt_to_priv_uv(pt)->io_loop) return; if (pt->event_loop_destroy_processing_done) @@ -740,7 +615,7 @@ pt->event_loop_destroy_processing_done = 1; if (!pt->event_loop_foreign) { - uv_signal_stop(&pt->w_sigint.uv.watcher); + uv_signal_stop(&pt_to_priv_uv(pt)->w_sigint.watcher); ns = LWS_ARRAY_SIZE(sigs); if (lws_check_opt(context->options, @@ -748,18 +623,18 @@ ns = 2; for (m = 0; m < ns; m++) { - uv_signal_stop(&pt->uv.signals[m]); - uv_close((uv_handle_t *)&pt->uv.signals[m], + uv_signal_stop(&pt_to_priv_uv(pt)->signals[m]); + uv_close((uv_handle_t *)&pt_to_priv_uv(pt)->signals[m], lws_uv_close_cb_sa); } } else lwsl_debug("%s: not closing pt signals\n", __func__); - uv_timer_stop(&pt->uv.sultimer); - uv_close((uv_handle_t *)&pt->uv.sultimer, lws_uv_close_cb_sa); + uv_timer_stop(&pt_to_priv_uv(pt)->sultimer); + uv_close((uv_handle_t *)&pt_to_priv_uv(pt)->sultimer, lws_uv_close_cb_sa); - uv_idle_stop(&pt->uv.idle); - uv_close((uv_handle_t *)&pt->uv.idle, lws_uv_close_cb_sa); + uv_idle_stop(&pt_to_priv_uv(pt)->idle); + uv_close((uv_handle_t *)&pt_to_priv_uv(pt)->idle, lws_uv_close_cb_sa); } /* @@ -769,15 +644,18 @@ * called again to bind the vhost */ -LWS_VISIBLE int +int elops_init_pt_uv(struct lws_context *context, void *_loop, int tsi) { struct lws_context_per_thread *pt = &context->pt[tsi]; + struct lws_pt_eventlibs_libuv *ptpriv = pt_to_priv_uv(pt); struct lws_vhost *vh = context->vhost_list; int status = 0, n, ns, first = 1; uv_loop_t *loop = (uv_loop_t *)_loop; - if (!pt->uv.io_loop) { + ptpriv->pt = pt; + + if (!ptpriv->io_loop) { if (!loop) { loop = lws_malloc(sizeof(*loop), "libuv loop"); if (!loop) { @@ -796,10 +674,10 @@ pt->event_loop_foreign = 1; } - pt->uv.io_loop = loop; - uv_idle_init(loop, &pt->uv.idle); - LWS_UV_REFCOUNT_STATIC_HANDLE_NEW(&pt->uv.idle, context); - + ptpriv->io_loop = loop; + uv_idle_init(loop, &ptpriv->idle); + LWS_UV_REFCOUNT_STATIC_HANDLE_NEW(&ptpriv->idle, context); + uv_idle_start(&ptpriv->idle, lws_uv_idle); ns = LWS_ARRAY_SIZE(sigs); if (lws_check_opt(context->options, @@ -807,13 +685,13 @@ ns = 2; if (!pt->event_loop_foreign) { - assert(ns <= (int)LWS_ARRAY_SIZE(pt->uv.signals)); + assert(ns <= (int)LWS_ARRAY_SIZE(ptpriv->signals)); for (n = 0; n < ns; n++) { - uv_signal_init(loop, &pt->uv.signals[n]); - LWS_UV_REFCOUNT_STATIC_HANDLE_NEW(&pt->uv.signals[n], + uv_signal_init(loop, &ptpriv->signals[n]); + LWS_UV_REFCOUNT_STATIC_HANDLE_NEW(&ptpriv->signals[n], context); - pt->uv.signals[n].data = pt->context; - uv_signal_start(&pt->uv.signals[n], + ptpriv->signals[n].data = pt->context; + uv_signal_start(&ptpriv->signals[n], lws_uv_signal_handler, sigs[n]); } } @@ -836,8 +714,8 @@ if (!first) return status; - uv_timer_init(pt->uv.io_loop, &pt->uv.sultimer); - LWS_UV_REFCOUNT_STATIC_HANDLE_NEW(&pt->uv.sultimer, context); + uv_timer_init(ptpriv->io_loop, &ptpriv->sultimer); + LWS_UV_REFCOUNT_STATIC_HANDLE_NEW(&ptpriv->sultimer, context); return status; } @@ -848,18 +726,21 @@ struct lws *wsi = (struct lws *)handle->data; struct lws_context *context = lws_get_context(wsi); struct lws_context_per_thread *pt = &context->pt[(int)wsi->tsi]; -#if !defined(LWS_WITHOUT_SERVER) +#if defined(LWS_WITH_SERVER) int lspd = 0; #endif lwsl_info("%s: %p\n", __func__, wsi); + lws_context_lock(context, __func__); + /* * We get called back here for every wsi that closes */ -#if !defined(LWS_WITHOUT_SERVER) - if (wsi->role_ops == &role_ops_listen && wsi->context->deprecated) { +#if defined(LWS_WITH_SERVER) + if (wsi->role_ops && !strcmp(wsi->role_ops->name, "listen") && + wsi->a.context->deprecated) { lspd = 1; context->deprecation_pending_listen_close_count--; if (!context->deprecation_pending_listen_close_count) @@ -874,7 +755,7 @@ /* it's our job to close the handle finally */ lws_free(handle); -#if !defined(LWS_WITHOUT_SERVER) +#if defined(LWS_WITH_SERVER) if (lspd == 2 && context->deprecation_cb) { lwsl_notice("calling deprecation callback\n"); context->deprecation_cb(); @@ -913,17 +794,22 @@ if (!context->count_event_loop_static_asset_handles && context->pt[0].event_loop_foreign) { lwsl_info("%s: call lws_context_destroy2\n", __func__); + lws_context_unlock(context); lws_context_destroy2(context); + return; } } + + lws_context_unlock(context); } void lws_libuv_closehandle(struct lws *wsi) { uv_handle_t* handle; + struct lws_io_watcher_libuv *w_read = &wsi_to_priv_uv(wsi)->w_read; - if (!wsi->w_read.uv.pwatcher) + if (!w_read->pwatcher) return; if (wsi->told_event_loop_closed) { @@ -940,16 +826,16 @@ * handle->data. */ - handle = (uv_handle_t *)wsi->w_read.uv.pwatcher; + handle = (uv_handle_t *)w_read->pwatcher; /* ensure we can only do this once */ - wsi->w_read.uv.pwatcher = NULL; + w_read->pwatcher = NULL; uv_close(handle, lws_libuv_closewsi); } -struct lws_event_loop_ops event_loop_ops_uv = { +static const struct lws_event_loop_ops event_loop_ops_uv = { /* name */ "libuv", /* init_context */ elops_init_context_uv, /* destroy_context1 */ elops_destroy_context1_uv, @@ -965,5 +851,24 @@ /* destroy_pt */ elops_destroy_pt_uv, /* destroy wsi */ NULL, - /* periodic_events_available */ 0, + /* flags */ 0, + + /* evlib_size_ctx */ sizeof(struct lws_context_eventlibs_libuv), + /* evlib_size_pt */ sizeof(struct lws_pt_eventlibs_libuv), + /* evlib_size_vh */ 0, + /* evlib_size_wsi */ sizeof(struct lws_io_watcher_libuv), +}; + +#if defined(LWS_WITH_EVLIB_PLUGINS) +LWS_VISIBLE +#endif +const lws_plugin_evlib_t evlib_uv = { + .hdr = { + "libuv event loop", + "lws_evlib_plugin", + LWS_PLUGIN_API_MAGIC + }, + + .ops = &event_loop_ops_uv }; + diff -Nru libwebsockets-3.2.1/lib/event-libs/libuv/private.h libwebsockets-4.1.6/lib/event-libs/libuv/private.h --- libwebsockets-3.2.1/lib/event-libs/libuv/private.h 2019-12-18 14:45:31.000000000 +0000 +++ libwebsockets-4.1.6/lib/event-libs/libuv/private.h 1970-01-01 00:00:00.000000000 +0000 @@ -1,76 +0,0 @@ -/* - * libwebsockets - small server side websockets and web server implementation - * - * Copyright (C) 2010 - 2018 Andy Green - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation: - * version 2.1 of the License. - * - * This library is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with this library; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, - * MA 02110-1301 USA - * - * This is included from core/private.h if LWS_WITH_LIBUV - */ - -#include - -/* - * libuv's async destroy cb means that asking to close something doesn't mean - * you can destroy it or parent things until after the close completes. - * - * So we must reference-count creation and close completions with libuv. - * - * All "static" (per-pt or per-context) uv handles must - * - * - have their .data set to point to the context - * - * - contribute to context->uv_count_static_asset_handles - * counting - */ -#define LWS_UV_REFCOUNT_STATIC_HANDLE_NEW(_x, _ctx) \ - { uv_handle_t *_uht = (uv_handle_t *)(_x); _uht->data = _ctx; \ - _ctx->count_event_loop_static_asset_handles++; } -#define LWS_UV_REFCOUNT_STATIC_HANDLE_TO_CONTEXT(_x) \ - ((struct lws_context *)((uv_handle_t *)((_x)->data))) -#define LWS_UV_REFCOUNT_STATIC_HANDLE_DESTROYED(_x) \ - (--(LWS_UV_REFCOUNT_STATIC_HANDLE_TO_CONTEXT(_x)-> \ - count_event_loop_static_asset_handles)) - -struct lws_pt_eventlibs_libuv { - uv_loop_t *io_loop; - uv_signal_t signals[8]; - uv_timer_t sultimer; - uv_idle_t idle; -}; - -struct lws_context_eventlibs_libuv { - uv_loop_t loop; -}; - -struct lws_io_watcher_libuv { - uv_poll_t *pwatcher; -}; - -struct lws_signal_watcher_libuv { - uv_signal_t watcher; -}; - -extern struct lws_event_loop_ops event_loop_ops_uv; - -uv_loop_t * -lws_uv_getloop(struct lws_context *context, int tsi); - -int -lws_uv_plugins_init(struct lws_context *context, const char * const *d); - -int -lws_uv_plugins_destroy(struct lws_context *context); diff -Nru libwebsockets-3.2.1/lib/event-libs/libuv/private-lib-event-libs-libuv.h libwebsockets-4.1.6/lib/event-libs/libuv/private-lib-event-libs-libuv.h --- libwebsockets-3.2.1/lib/event-libs/libuv/private-lib-event-libs-libuv.h 1970-01-01 00:00:00.000000000 +0000 +++ libwebsockets-4.1.6/lib/event-libs/libuv/private-lib-event-libs-libuv.h 2020-12-01 17:40:26.000000000 +0000 @@ -0,0 +1,84 @@ +/* + * libwebsockets - small server side websockets and web server implementation + * + * Copyright (C) 2010 - 2019 Andy Green + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to + * deal in the Software without restriction, including without limitation the + * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or + * sell copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS + * IN THE SOFTWARE. + */ + +#include + +/* + * libuv's async destroy cb means that asking to close something doesn't mean + * you can destroy it or parent things until after the close completes. + * + * So we must reference-count creation and close completions with libuv. + * + * All "static" (per-pt or per-context) uv handles must + * + * - have their .data set to point to the context + * + * - contribute to context->uv_count_static_asset_handles + * counting + */ +#define LWS_UV_REFCOUNT_STATIC_HANDLE_NEW(_x, _ctx) \ + { uv_handle_t *_uht = (uv_handle_t *)(_x); _uht->data = _ctx; \ + _ctx->count_event_loop_static_asset_handles++; } +#define LWS_UV_REFCOUNT_STATIC_HANDLE_TO_CONTEXT(_x) \ + ((struct lws_context *)((uv_handle_t *)((_x)->data))) +#define LWS_UV_REFCOUNT_STATIC_HANDLE_DESTROYED(_x) \ + (--(LWS_UV_REFCOUNT_STATIC_HANDLE_TO_CONTEXT(_x)-> \ + count_event_loop_static_asset_handles)) + +struct lws_signal_watcher_libuv { + uv_signal_t watcher; + struct lws_context *context; +}; + +struct lws_pt_eventlibs_libuv { + uv_loop_t *io_loop; + struct lws_context_per_thread *pt; + uv_signal_t signals[8]; + uv_timer_t sultimer; + uv_idle_t idle; + struct lws_signal_watcher_libuv w_sigint; +}; + +struct lws_context_eventlibs_libuv { + uv_loop_t loop; +}; + +struct lws_io_watcher_libuv { + uv_poll_t *pwatcher; + struct lws_context *context; + uint8_t actual_events; +}; + +struct lws_wsi_eventlibs_libuv { + struct lws_io_watcher_libuv w_read; +}; + +uv_loop_t * +lws_uv_getloop(struct lws_context *context, int tsi); + +int +lws_uv_plugins_init(struct lws_context *context, const char * const *d); + +int +lws_uv_plugins_destroy(struct lws_context *context); diff -Nru libwebsockets-3.2.1/lib/event-libs/poll/CMakeLists.txt libwebsockets-4.1.6/lib/event-libs/poll/CMakeLists.txt --- libwebsockets-3.2.1/lib/event-libs/poll/CMakeLists.txt 1970-01-01 00:00:00.000000000 +0000 +++ libwebsockets-4.1.6/lib/event-libs/poll/CMakeLists.txt 2020-12-01 17:40:26.000000000 +0000 @@ -0,0 +1,42 @@ +# +# libwebsockets - small server side websockets and web server implementation +# +# Copyright (C) 2010 - 2020 Andy Green +# +# Permission is hereby granted, free of charge, to any person obtaining a copy +# of this software and associated documentation files (the "Software"), to +# deal in the Software without restriction, including without limitation the +# rights to use, copy, modify, merge, publish, distribute, sublicense, and/or +# sell copies of the Software, and to permit persons to whom the Software is +# furnished to do so, subject to the following conditions: +# +# The above copyright notice and this permission notice shall be included in +# all copies or substantial portions of the Software. +# +# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING +# FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS +# IN THE SOFTWARE. +# +# The strategy is to only export to PARENT_SCOPE +# +# - changes to LIB_LIST +# - includes via include_directories +# +# and keep everything else private + +include_directories(../poll) + +if (LWS_WITH_NETWORK) + list(APPEND SOURCES + event-libs/poll/poll.c) +endif() + +# +# Keep explicit parent scope exports at end +# + +exports_to_parent_scope() diff -Nru libwebsockets-3.2.1/lib/event-libs/poll/poll.c libwebsockets-4.1.6/lib/event-libs/poll/poll.c --- libwebsockets-3.2.1/lib/event-libs/poll/poll.c 2019-12-18 14:45:31.000000000 +0000 +++ libwebsockets-4.1.6/lib/event-libs/poll/poll.c 2020-12-01 17:40:26.000000000 +0000 @@ -1,27 +1,29 @@ -/* + /* * libwebsockets - small server side websockets and web server implementation * - * Copyright (C) 2010 - 2018 Andy Green + * Copyright (C) 2010 - 2019 Andy Green * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation: - * version 2.1 of the License. + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to + * deal in the Software without restriction, including without limitation the + * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or + * sell copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: * - * This library is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. * - * You should have received a copy of the GNU Lesser General Public - * License along with this library; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, - * MA 02110-1301 USA - * - * This is included from core/private.h if LWS_ROLE_WS + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS + * IN THE SOFTWARE */ -#include +#include +#include "private-lib-event-libs-poll.h" struct lws_event_loop_ops event_loop_ops_poll = { /* name */ "poll", @@ -39,5 +41,20 @@ /* destroy_pt */ NULL, /* destroy wsi */ NULL, - /* periodic_events_available */ 1, + /* flags */ LELOF_ISPOLL, + + /* evlib_size_ctx */ 0, + /* evlib_size_pt */ 0, + /* evlib_size_vh */ 0, + /* evlib_size_wsi */ 0, +}; + +const lws_plugin_evlib_t evlib_poll = { + .hdr = { + "poll", + "lws_evlib_plugin", + LWS_PLUGIN_API_MAGIC + }, + + .ops = &event_loop_ops_poll }; diff -Nru libwebsockets-3.2.1/lib/event-libs/poll/private.h libwebsockets-4.1.6/lib/event-libs/poll/private.h --- libwebsockets-3.2.1/lib/event-libs/poll/private.h 2019-12-18 14:45:31.000000000 +0000 +++ libwebsockets-4.1.6/lib/event-libs/poll/private.h 1970-01-01 00:00:00.000000000 +0000 @@ -1,23 +0,0 @@ -/* - * libwebsockets - small server side websockets and web server implementation - * - * Copyright (C) 2010 - 2018 Andy Green - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation: - * version 2.1 of the License. - * - * This library is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with this library; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, - * MA 02110-1301 USA - * - */ - -extern struct lws_event_loop_ops event_loop_ops_poll; diff -Nru libwebsockets-3.2.1/lib/event-libs/poll/private-lib-event-libs-poll.h libwebsockets-4.1.6/lib/event-libs/poll/private-lib-event-libs-poll.h --- libwebsockets-3.2.1/lib/event-libs/poll/private-lib-event-libs-poll.h 1970-01-01 00:00:00.000000000 +0000 +++ libwebsockets-4.1.6/lib/event-libs/poll/private-lib-event-libs-poll.h 2020-12-01 17:40:26.000000000 +0000 @@ -0,0 +1,25 @@ +/* + * libwebsockets - small server side websockets and web server implementation + * + * Copyright (C) 2010 - 2019 Andy Green + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to + * deal in the Software without restriction, including without limitation the + * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or + * sell copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS + * IN THE SOFTWARE. + */ + +extern struct lws_event_loop_ops event_loop_ops_poll; diff -Nru libwebsockets-3.2.1/lib/event-libs/private.h libwebsockets-4.1.6/lib/event-libs/private.h --- libwebsockets-3.2.1/lib/event-libs/private.h 2019-12-18 14:45:31.000000000 +0000 +++ libwebsockets-4.1.6/lib/event-libs/private.h 1970-01-01 00:00:00.000000000 +0000 @@ -1,74 +0,0 @@ -/* - * libwebsockets - small server side websockets and web server implementation - * - * Copyright (C) 2010 - 2018 Andy Green - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation: - * version 2.1 of the License. - * - * This library is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with this library; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, - * MA 02110-1301 USA - * - * This is included from core/private.h - */ - -struct lws_event_loop_ops { - const char *name; - /* event loop-specific context init during context creation */ - int (*init_context)(struct lws_context *context, - const struct lws_context_creation_info *info); - /* called during lws_destroy_context */ - int (*destroy_context1)(struct lws_context *context); - /* called during lws_destroy_context2 */ - int (*destroy_context2)(struct lws_context *context); - /* init vhost listening wsi */ - int (*init_vhost_listen_wsi)(struct lws *wsi); - /* init the event loop for a pt */ - int (*init_pt)(struct lws_context *context, void *_loop, int tsi); - /* called at end of first phase of close_free_wsi() */ - int (*wsi_logical_close)(struct lws *wsi); - /* return nonzero if client connect not allowed */ - int (*check_client_connect_ok)(struct lws *wsi); - /* close handle manually */ - void (*close_handle_manually)(struct lws *wsi); - /* event loop accept processing */ - int (*accept)(struct lws *wsi); - /* control wsi active events */ - void (*io)(struct lws *wsi, int flags); - /* run the event loop for a pt */ - void (*run_pt)(struct lws_context *context, int tsi); - /* called before pt is destroyed */ - void (*destroy_pt)(struct lws_context *context, int tsi); - /* called just before wsi is freed */ - void (*destroy_wsi)(struct lws *wsi); - - unsigned int periodic_events_available:1; -}; - -/* bring in event libs private declarations */ - -#if defined(LWS_WITH_POLL) -#include "event-libs/poll/private.h" -#endif - -#if defined(LWS_WITH_LIBUV) -#include "event-libs/libuv/private.h" -#endif - -#if defined(LWS_WITH_LIBEVENT) -#include "event-libs/libevent/private.h" -#endif - -#if defined(LWS_WITH_LIBEV) -#include "event-libs/libev/private.h" -#endif - diff -Nru libwebsockets-3.2.1/lib/event-libs/private-lib-event-libs.h libwebsockets-4.1.6/lib/event-libs/private-lib-event-libs.h --- libwebsockets-3.2.1/lib/event-libs/private-lib-event-libs.h 1970-01-01 00:00:00.000000000 +0000 +++ libwebsockets-4.1.6/lib/event-libs/private-lib-event-libs.h 2020-12-01 17:40:26.000000000 +0000 @@ -0,0 +1,68 @@ + /* + * libwebsockets - small server side websockets and web server implementation + * + * Copyright (C) 2010 - 2019 Andy Green + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to + * deal in the Software without restriction, including without limitation the + * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or + * sell copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS + * IN THE SOFTWARE. + * + * This is included from private-lib-core.h + */ + +enum lws_event_lib_ops_flags { + LELOF_ISPOLL = (1 >> 0), + LELOF_DESTROY_FINAL = (1 >> 1), +}; + +struct lws_event_loop_ops { + const char *name; + /* event loop-specific context init during context creation */ + int (*init_context)(struct lws_context *context, + const struct lws_context_creation_info *info); + /* called during lws_destroy_context */ + int (*destroy_context1)(struct lws_context *context); + /* called during lws_destroy_context2 */ + int (*destroy_context2)(struct lws_context *context); + /* init vhost listening wsi */ + int (*init_vhost_listen_wsi)(struct lws *wsi); + /* init the event loop for a pt */ + int (*init_pt)(struct lws_context *context, void *_loop, int tsi); + /* called at end of first phase of close_free_wsi() */ + int (*wsi_logical_close)(struct lws *wsi); + /* return nonzero if client connect not allowed */ + int (*check_client_connect_ok)(struct lws *wsi); + /* close handle manually */ + void (*close_handle_manually)(struct lws *wsi); + /* event loop accept processing */ + int (*sock_accept)(struct lws *wsi); + /* control wsi active events */ + void (*io)(struct lws *wsi, int flags); + /* run the event loop for a pt */ + void (*run_pt)(struct lws_context *context, int tsi); + /* called before pt is destroyed */ + void (*destroy_pt)(struct lws_context *context, int tsi); + /* called just before wsi is freed */ + void (*destroy_wsi)(struct lws *wsi); + + uint8_t flags; + + uint16_t evlib_size_ctx; + uint16_t evlib_size_pt; + uint16_t evlib_size_vh; + uint16_t evlib_size_wsi; +}; diff -Nru libwebsockets-3.2.1/lib/event-libs/README.md libwebsockets-4.1.6/lib/event-libs/README.md --- libwebsockets-3.2.1/lib/event-libs/README.md 2019-12-18 14:45:31.000000000 +0000 +++ libwebsockets-4.1.6/lib/event-libs/README.md 2020-12-01 17:40:26.000000000 +0000 @@ -2,12 +2,30 @@ ### Introduction -By default lws has built-in support for POSIX poll() as the event loop. +By default lws has built-in support for POSIX poll() as the event loop on unix, +and native WSA on windows. -However either to get access to epoll() or other platform specific better -poll waits, or to integrate with existing applications already using a -specific event loop, it can be desirable for lws to use another external -event library, like libuv, libevent or libev. +To get access to epoll() or other platform specific better poll waits, or to +integrate with existing applications already using a specific event loop, it can +be desirable for lws to use another external event library, like libuv, glib, +libevent or libev. + +Lws supports wholesale replacement of its wait selectable at runtime, either by +building support for one or more event lib into the libwebsockets library, or by +building runtime-loadable plugins. CMake symbol `LWS_WITH_EVLIB_PLUGINS` +decides if the support is built as plugins or included into the lws lib. + +Due to their history libevent and libev have conflicting defines in the same +namespace and cannot be built together if included into the lib, however when +built as plugins they are built separately without problems. +See ./READMEs/README.event-libs.md for more details. + +Despite it may be more work, lws event lib implementations must support +"foreign" loops cleanly, that is integration with an already-existing loop and +the ability to destroy the lws_context without stopping or leaving the foreign +loop in any different state than when lws found it. For most loops this is +fairly simple, but with libuv async close, it required refcounting lws libuv +handles and deferring the actual destroy until they were all really closed. ### Code placement @@ -15,89 +33,114 @@ ### Allowing control over enabling event libs -All event libs should add a cmake define `LWS_WITH_**lib name**` and make its build -dependent on it in CMakeLists.txt. Export the cmakedefine in `./cmake/lws_config.h.in` -as well so user builds can understand if the event lib is available in the lws build it is -trying to bind to. +All event libs should add a cmake define `LWS_WITH_**lib name**` and make its +build dependent on it in CMakeLists.txt. Export the cmakedefine in +`./cmake/lws_config.h.in` as well so user builds can understand if the event +lib is available in the lws build it is trying to bind to. -If the event lib is disabled in cmake, nothing in its directory is built or referenced. +If the event lib is disabled in cmake, nothing in its directory is built or +referenced. ### Event loop ops struct -The event lib support is defined by `struct lws_event_loop_ops` in `lib/event-libs/private.h`, -each event lib support instantiates one of these and fills in the appropriate ops -callbacks to perform its job. By convention that lives in +The event lib support is defined by `struct lws_event_loop_ops` in +`lib/event-libs/private-lib-event-libs.h`, +each event lib support instantiates one of these and fills in the appropriate +ops callbacks to perform its job. By convention that lives in `./lib/event-libs/**lib name**/**lib_name**.c`. +The ops struct must be public, not static, and must be named using `**lib_name**`, +eg + +``` +``` + ### Private event lib declarations -Truly private declarations for the event lib can go in the event-libs directory as you like. -However when the declarations must be accessible to other things in lws build, eg, -the event lib support adds members to `struct lws` when enabled, they should be in the -event lib supporr directory in a file `private.h`. - -Search for "bring in event libs private declarations" in `./lib/core/private.h -and add your private event lib support file there following the style used for the other -event libs, eg, +Truly private declarations for the event lib support that are only referenced by +that code can go in the event-libs directory as you like. The convention is +they should be in the event lib support directory in a file +`private-lib-event-libs-**lib name**.h`. + +### Integration with lws + +There are a couple of places to add refererences in ./lib/core/context.c, in a +table of context creation time server option flags mapped to the **lib_name**, +used for plugin mode, like this... + +``` +#if defined(LWS_WITH_EVLIB_PLUGINS) && defined(LWS_WITH_EVENT_LIBS) +static const struct lws_evlib_map { + uint64_t flag; + const char *name; +} map[] = { + { LWS_SERVER_OPTION_LIBUV, "evlib_uv" }, + { LWS_SERVER_OPTION_LIBEVENT, "evlib_event" }, + { LWS_SERVER_OPTION_GLIB, "evlib_glib" }, + { LWS_SERVER_OPTION_LIBEV, "evlib_ev" }, +}; +``` + +and for backwards compatibility add a stanza to the built-in checks like this ``` #if defined(LWS_WITH_LIBUV) - #include "event-libs/libuv/private.h" + if (lws_check_opt(info->options, LWS_SERVER_OPTION_LIBUV)) { + extern const lws_plugin_evlib_t evlib_uv; + plev = &evlib_uv; + } #endif ``` -If the event lib support is disabled at cmake, nothing from its private.h should be used anywhere. +Both entries are the way the main libs hook up to the selected event lib ops +struct at runtime. ### Integrating event lib assets to lws -If your event lib needs special storage in lws objects, that's no problem. But to keep -things sane, there are some rules. - - - declare a "container struct" in your private.h for everything, eg, the libuv event - lib support need to add its own assets in the perthread struct, it declares in its private.h +Declare "container structs" in your private....h for anything you need at +wsi, pt, vhost and context levels, eg, the libuv event lib support need to +add its own assets in the perthread struct, it declares in its private....h ``` struct lws_pt_eventlibs_libuv { uv_loop_t *io_loop; + struct lws_context_per_thread *pt; uv_signal_t signals[8]; - uv_timer_t timeout_watcher; - uv_timer_t hrtimer; + uv_timer_t sultimer; uv_idle_t idle; + struct lws_signal_watcher_libuv w_sigint; }; ``` - - add your event lib content in one place in the related lws struct, protected by `#if defined(LWS_WITH_**lib name**)`, - eg, again for LWS_WITH_LIBUV +this is completely private and opaque, but in the ops struct there are provided +four entries to export the sizes of these event-lib specific objects ``` -struct lws_context_per_thread { - -... - -#if defined(LWS_WITH_LIBUV) - struct lws_pt_eventlibs_libuv uv; -#endif - ... + /* evlib_size_ctx */ sizeof(struct lws_context_eventlibs_libuv), + /* evlib_size_pt */ sizeof(struct lws_pt_eventlibs_libuv), + /* evlib_size_vh */ 0, + /* evlib_size_wsi */ sizeof(struct lws_io_watcher_libuv), +}; ``` -### Adding to lws available event libs list +If the particular event lib doesn't need to have a private footprint in an +object, it can just set the size it needs there to 0. -Edit the NULL-terminated array `available_event_libs` at the top of `./lib/context.c` to include -a pointer to your new event lib support's ops struct, following the style already there. +When the context, pts, vhosts or wsis are created in lws, they over-allocate +to also allow for the event lib object, and set a pointer in the lws object +being created to point at the over-allocation. For example for the wsi ``` -const struct lws_event_loop_ops *available_event_libs[] = { -#if defined(LWS_WITH_POLL) - &event_loop_ops_poll, +#if defined(LWS_WITH_EVENT_LIBS) + void *evlib_wsi; /* overallocated */ #endif -#if defined(LWS_WITH_LIBUV) - &event_loop_ops_uv, -#endif -... ``` -This is used to provide a list of avilable configured backends. +and similarly there are `evlib_pt` and so on for those objects, usable by the +event lib and opaque to everyone else. Once the event lib is selected at +runtime, all of these objects are guaranteed to have the right size object at +`wsi->evlib_wsi` initialized to zeroes. ### Enabling event lib adoption @@ -112,13 +155,15 @@ ### Destruction -Ending the event loop is generally a bit tricky, because if the event loop is internal -to the lws context, you cannot destroy it while the event loop is running. - -Don't add special exports... we tried that, it's a huge mess. The same user code should be able -work with any of the event loops including poll. - -The solution we found was hide the different processing necessary for the different cases in -lws_destroy_context(). To help with that there are ops available at two different places in -the context destroy processing. +Ending the event loop is generally a bit tricky, because if the event loop is +internal to the lws context, you cannot destroy it while the event loop is +running. + +Don't add special exports... we tried that, it's a huge mess. The same user +code should be able work with any of the event loops including poll. + +The solution we found was hide the different processing necessary for the +different cases in `lws_destroy_context()`. To help with that there are event +lib ops available that will be called at two different places in the context +destroy processing. diff -Nru libwebsockets-3.2.1/lib/jose/CMakeLists.txt libwebsockets-4.1.6/lib/jose/CMakeLists.txt --- libwebsockets-3.2.1/lib/jose/CMakeLists.txt 1970-01-01 00:00:00.000000000 +0000 +++ libwebsockets-4.1.6/lib/jose/CMakeLists.txt 2020-12-01 17:40:26.000000000 +0000 @@ -0,0 +1,46 @@ +# +# libwebsockets - small server side websockets and web server implementation +# +# Copyright (C) 2010 - 2020 Andy Green +# +# Permission is hereby granted, free of charge, to any person obtaining a copy +# of this software and associated documentation files (the "Software"), to +# deal in the Software without restriction, including without limitation the +# rights to use, copy, modify, merge, publish, distribute, sublicense, and/or +# sell copies of the Software, and to permit persons to whom the Software is +# furnished to do so, subject to the following conditions: +# +# The above copyright notice and this permission notice shall be included in +# all copies or substantial portions of the Software. +# +# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING +# FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS +# IN THE SOFTWARE. +# + +include_directories(. ./jwe ./jws ./jwk) + +if (LWS_WITH_JOSE) + list(APPEND SOURCES + jose/jwk/jwk.c + jose/jws/jose.c + jose/jws/jws.c + jose/jwe/jwe.c + jose/jwe/enc/aescbc.c + jose/jwe/enc/aesgcm.c + jose/jwe/enc/aeskw.c + jose/jwe/jwe-rsa-aescbc.c + jose/jwe/jwe-rsa-aesgcm.c + jose/jwe/jwe-ecdh-es-aeskw.c + ) +endif() + +# +# Keep explicit parent scope exports at end +# + +exports_to_parent_scope() diff -Nru libwebsockets-3.2.1/lib/jose/jwe/enc/aescbc.c libwebsockets-4.1.6/lib/jose/jwe/enc/aescbc.c --- libwebsockets-3.2.1/lib/jose/jwe/enc/aescbc.c 2019-12-18 14:45:31.000000000 +0000 +++ libwebsockets-4.1.6/lib/jose/jwe/enc/aescbc.c 2020-12-01 17:40:26.000000000 +0000 @@ -1,39 +1,40 @@ /* - * libwebsockets - JSON Web Encryption support + * libwebsockets - small server side websockets and web server implementation * - * Copyright (C) 2018 Andy Green + * Copyright (C) 2010 - 2019 Andy Green * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation: - * version 2.1 of the License. + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to + * deal in the Software without restriction, including without limitation the + * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or + * sell copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: * - * This library is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with this library; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, - * MA 02110-1301 USA - * - * - * JWE code for payload encrypt / decrypt using aescbc + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS + * IN THE SOFTWARE. */ -#include "core/private.h" -#include "jose/jwe/private.h" + +#include "private-lib-core.h" +#include "private-lib-jose-jwe.h" int lws_jwe_encrypt_cbc_hs(struct lws_jwe *jwe, uint8_t *cek, uint8_t *aad, int aad_len) { - int n, hlen = lws_genhmac_size(jwe->jose.enc_alg->hmac_type); + int n, hlen = (int)lws_genhmac_size(jwe->jose.enc_alg->hmac_type); uint8_t digest[LWS_GENHASH_LARGEST]; struct lws_gencrypto_keyelem el; struct lws_genhmac_ctx hmacctx; struct lws_genaes_ctx aesctx; + size_t paddedlen; uint8_t al[8]; /* Caller must have prepared space for the results */ @@ -81,22 +82,27 @@ el.len = hlen / 2; if (lws_genaes_create(&aesctx, LWS_GAESO_ENC, LWS_GAESM_CBC, &el, - LWS_GAESP_NO_PADDING, NULL)) { + LWS_GAESP_WITH_PADDING, NULL)) { lwsl_err("%s: lws_genaes_create failed\n", __func__); return -1; } /* - * the plaintext gets delivered to us in LJWE_CTXT, this replaces - * the plaintext there with the same amount of ciphertext + * the plaintext gets delivered to us in LJWE_CTXT, this replaces the + * plaintext there with the ciphertext, which will be larger by some + * padding bytes */ n = lws_genaes_crypt(&aesctx, (uint8_t *)jwe->jws.map.buf[LJWE_CTXT], jwe->jws.map.len[LJWE_CTXT], (uint8_t *)jwe->jws.map.buf[LJWE_CTXT], (uint8_t *)jwe->jws.map.buf[LJWE_IV], - NULL, NULL, 16); - lws_genaes_destroy(&aesctx, NULL, 0); + NULL, NULL, LWS_AES_CBC_BLOCKLEN); + paddedlen = lws_gencrypto_padded_length(LWS_AES_CBC_BLOCKLEN, + jwe->jws.map.len[LJWE_CTXT]); + jwe->jws.map.len[LJWE_CTXT] = (uint32_t)paddedlen; + lws_genaes_destroy(&aesctx, (uint8_t *)jwe->jws.map.buf[LJWE_CTXT] + + paddedlen - LWS_AES_CBC_BLOCKLEN, LWS_AES_CBC_BLOCKLEN); if (n) { lwsl_err("%s: lws_genaes_crypt failed\n", __func__); return -1; @@ -156,7 +162,7 @@ lws_jwe_auth_and_decrypt_cbc_hs(struct lws_jwe *jwe, uint8_t *enc_cek, uint8_t *aad, int aad_len) { - int n, hlen = lws_genhmac_size(jwe->jose.enc_alg->hmac_type); + int n, hlen = (int)lws_genhmac_size(jwe->jose.enc_alg->hmac_type); uint8_t digest[LWS_GENHASH_LARGEST]; struct lws_gencrypto_keyelem el; struct lws_genhmac_ctx hmacctx; @@ -241,6 +247,19 @@ jwe->jws.map.len[LJWE_CTXT], (uint8_t *)jwe->jws.map.buf[LJWE_CTXT], (uint8_t *)jwe->jws.map.buf[LJWE_IV], NULL, NULL, 16); + + /* Strip the PKCS #7 padding */ + + if (jwe->jws.map.len[LJWE_CTXT] < LWS_AES_CBC_BLOCKLEN || + jwe->jws.map.len[LJWE_CTXT] <= (unsigned char)jwe->jws.map.buf[LJWE_CTXT] + [jwe->jws.map.len[LJWE_CTXT] - 1]) { + lwsl_err("%s: invalid padded ciphertext length: %d. Corrupt data?\n", + __func__, jwe->jws.map.len[LJWE_CTXT]); + return -1; + } + jwe->jws.map.len[LJWE_CTXT] -= jwe->jws.map.buf[LJWE_CTXT][ + jwe->jws.map.len[LJWE_CTXT] - 1]; + n |= lws_genaes_destroy(&aesctx, NULL, 0); if (n) { lwsl_err("%s: lws_genaes_crypt failed\n", __func__); diff -Nru libwebsockets-3.2.1/lib/jose/jwe/enc/aesgcm.c libwebsockets-4.1.6/lib/jose/jwe/enc/aesgcm.c --- libwebsockets-3.2.1/lib/jose/jwe/enc/aesgcm.c 2019-12-18 14:45:31.000000000 +0000 +++ libwebsockets-4.1.6/lib/jose/jwe/enc/aesgcm.c 2020-12-01 17:40:26.000000000 +0000 @@ -1,29 +1,29 @@ /* - * libwebsockets - JSON Web Encryption support + * libwebsockets - small server side websockets and web server implementation * - * Copyright (C) 2018 Andy Green - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation: - * version 2.1 of the License. - * - * This library is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with this library; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, - * MA 02110-1301 USA - * - * - * JWE code related to aes gcm + * Copyright (C) 2010 - 2019 Andy Green * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to + * deal in the Software without restriction, including without limitation the + * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or + * sell copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS + * IN THE SOFTWARE. */ -#include "core/private.h" -#include "jose/jwe/private.h" + +#include "private-lib-core.h" +#include "private-lib-jose-jwe.h" /* * NOTICE this is AESGCM content encryption, it's not AES GCM key wrapping diff -Nru libwebsockets-3.2.1/lib/jose/jwe/enc/aeskw.c libwebsockets-4.1.6/lib/jose/jwe/enc/aeskw.c --- libwebsockets-3.2.1/lib/jose/jwe/enc/aeskw.c 2019-12-18 14:45:31.000000000 +0000 +++ libwebsockets-4.1.6/lib/jose/jwe/enc/aeskw.c 2020-12-01 17:40:26.000000000 +0000 @@ -1,30 +1,29 @@ /* - * libwebsockets - JSON Web Encryption support + * libwebsockets - small server side websockets and web server implementation * - * Copyright (C) 2018 Andy Green - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation: - * version 2.1 of the License. - * - * This library is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with this library; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, - * MA 02110-1301 USA - * - * - * JWE code related to aeskw cbc + * Copyright (C) 2010 - 2019 Andy Green * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to + * deal in the Software without restriction, including without limitation the + * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or + * sell copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS + * IN THE SOFTWARE. */ -#include "core/private.h" -#include "jose/jwe/private.h" +#include "private-lib-core.h" +#include "private-lib-jose-jwe.h" /* * RFC3394 Key Wrap uses a 128-bit key, and bloats what it is wrapping by @@ -42,7 +41,7 @@ /* we are wrapping a key, so size for the worst case after wrap */ uint8_t enc_cek[LWS_JWE_LIMIT_KEY_ELEMENT_BYTES + LWS_JWE_RFC3394_OVERHEAD_BYTES]; - int n, m, hlen = lws_genhmac_size(jwe->jose.enc_alg->hmac_type), + int n, m, hlen = (int)lws_genhmac_size(jwe->jose.enc_alg->hmac_type), ot = *temp_len; if (jwe->jws.jwk->kty != LWS_GENCRYPTO_KTY_OCT) { @@ -54,7 +53,7 @@ /* create a b64 version of the JOSE header, needed for hashing */ if (lws_jws_encode_b64_element(&jwe->jws.map_b64, LJWE_JOSE, - temp + (ot - *temp_len), temp_len, + temp, temp_len, jwe->jws.map.buf[LJWE_JOSE], jwe->jws.map.len[LJWE_JOSE])) return -1; diff -Nru libwebsockets-3.2.1/lib/jose/jwe/jwe.c libwebsockets-4.1.6/lib/jose/jwe/jwe.c --- libwebsockets-3.2.1/lib/jose/jwe/jwe.c 2019-12-18 14:45:31.000000000 +0000 +++ libwebsockets-4.1.6/lib/jose/jwe/jwe.c 2020-12-01 17:40:26.000000000 +0000 @@ -1,30 +1,30 @@ /* - * libwebsockets - JSON Web Encryption support + * libwebsockets - small server side websockets and web server implementation * - * Copyright (C) 2018 Andy Green - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation: - * version 2.1 of the License. - * - * This library is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with this library; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, - * MA 02110-1301 USA - * - * - * This supports RFC7516 JSON Web Encryption + * Copyright (C) 2010 - 2019 Andy Green * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to + * deal in the Software without restriction, including without limitation the + * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or + * sell copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS + * IN THE SOFTWARE. */ -#include "core/private.h" -#include "jose/private.h" -#include "jose/jwe/private.h" + +#include "private-lib-core.h" +#include "private-lib-jose.h" +#include "private-lib-jose-jwe.h" /* * Currently only support flattened or compact (implicitly single signature) @@ -148,7 +148,7 @@ lejp_construct(&jctx, lws_jwe_json_cb, &args, jwe_json, LWS_ARRAY_SIZE(jwe_json)); - m = (int)(signed char)lejp_parse(&jctx, (uint8_t *)buf, len); + m = lejp_parse(&jctx, (uint8_t *)buf, len); lejp_destruct(&jctx); if (m < 0) { lwsl_notice("%s: parse returned %d\n", __func__, m); @@ -209,7 +209,7 @@ lws_jwa_concat_kdf(struct lws_jwe *jwe, int direct, uint8_t *out, const uint8_t *shared_secret, int sslen) { - int hlen = lws_genhash_size(LWS_GENHASH_TYPE_SHA256), aidlen; + int hlen = (int)lws_genhash_size(LWS_GENHASH_TYPE_SHA256), aidlen; struct lws_genhash_ctx hash_ctx; uint32_t ctr = 1, t; const char *aid; @@ -236,7 +236,7 @@ */ aid = direct ? jwe->jose.enc_alg->alg : jwe->jose.alg->alg; - aidlen = strlen(aid); + aidlen = (int)strlen(aid); /* * PartyUInfo (PartyVInfo is the same deal) @@ -284,7 +284,7 @@ /* Z */ lws_genhash_update(&hash_ctx, shared_secret, sslen) || /* other info */ - lws_genhash_update(&hash_ctx, be32(strlen(aid), &t), 4) || + lws_genhash_update(&hash_ctx, be32((uint32_t)strlen(aid), &t), 4) || lws_genhash_update(&hash_ctx, aid, aidlen) || lws_genhash_update(&hash_ctx, be32(jwe->jose.e[LJJHI_APU].len, &t), 4) || @@ -310,7 +310,7 @@ return 0; } -LWS_VISIBLE void +void lws_jwe_be64(uint64_t c, uint8_t *p8) { int n; @@ -319,24 +319,25 @@ *p8++ = (uint8_t)((c >> n) & 0xff); } -LWS_VISIBLE int +int lws_jwe_auth_and_decrypt(struct lws_jwe *jwe, char *temp, int *temp_len) { int valid_aescbc_hmac, valid_aesgcm; + char dotstar[96]; if (lws_jwe_parse_jose(&jwe->jose, jwe->jws.map.buf[LJWS_JOSE], jwe->jws.map.len[LJWS_JOSE], temp, temp_len) < 0) { - lwsl_err("%s: JOSE parse '%.*s' failed\n", __func__, - jwe->jws.map.len[LJWS_JOSE], - jwe->jws.map.buf[LJWS_JOSE]); + lws_strnncpy(dotstar, jwe->jws.map.buf[LJWS_JOSE], + jwe->jws.map.len[LJWS_JOSE], sizeof(dotstar)); + lwsl_err("%s: JOSE parse '%s' failed\n", __func__, dotstar); return -1; } if (!jwe->jose.alg) { - lwsl_err("%s: no jose.alg: %.*s\n", __func__, - jwe->jws.map.len[LJWS_JOSE], - jwe->jws.map.buf[LJWS_JOSE]); + lws_strnncpy(dotstar, jwe->jws.map.buf[LJWS_JOSE], + jwe->jws.map.len[LJWS_JOSE], sizeof(dotstar)); + lwsl_err("%s: no jose.alg: %s\n", __func__, dotstar); return -1; } @@ -379,7 +380,7 @@ return -1; } -LWS_VISIBLE int +int lws_jwe_encrypt(struct lws_jwe *jwe, char *temp, int *temp_len) { int valid_aescbc_hmac, valid_aesgcm, ot = *temp_len, ret = -1; @@ -473,7 +474,7 @@ * - You can't emit Compact representation if there are multiple recipients */ -LWS_VISIBLE int +int lws_jwe_render_compact(struct lws_jwe *jwe, char *out, size_t out_len) { size_t orig = out_len; @@ -491,7 +492,7 @@ jwe->jws.map.len[LJWS_JOSE], out, out_len); if (n < 0 || (int)out_len == n) { lwsl_info("%s: unable to encode JOSE\n", __func__); - return n; + return -1; } out += n; @@ -502,7 +503,7 @@ jwe->jws.map.len[LJWE_EKEY], out, out_len); if (n < 0 || (int)out_len == n) { lwsl_info("%s: unable to encode EKEY\n", __func__); - return n; + return -1; } out += n; @@ -512,7 +513,7 @@ jwe->jws.map.len[LJWE_IV], out, out_len); if (n < 0 || (int)out_len == n) { lwsl_info("%s: unable to encode IV\n", __func__); - return n; + return -1; } out += n; @@ -523,7 +524,7 @@ jwe->jws.map.len[LJWE_CTXT], out, out_len); if (n < 0 || (int)out_len == n) { lwsl_info("%s: unable to encode CTXT\n", __func__); - return n; + return -1; } out += n; @@ -533,17 +534,17 @@ jwe->jws.map.len[LJWE_ATAG], out, out_len); if (n < 0 || (int)out_len == n) { lwsl_info("%s: unable to encode ATAG\n", __func__); - return n; + return -1; } out += n; *out++ = '\0'; out_len -= n; - return orig - out_len; + return (int)(orig - out_len); } -LWS_VISIBLE int +int lws_jwe_create_packet(struct lws_jwe *jwe, const char *payload, size_t len, const char *nonce, char *out, size_t out_len, struct lws_context *context) @@ -577,9 +578,9 @@ if (!jwe->jose.alg || !jwe->jose.alg->alg) goto bail; - p += lws_snprintf(p, end - p, "{\"alg\":\"%s\",\"jwk\":", + p += lws_snprintf(p, lws_ptr_diff(end, p), "{\"alg\":\"%s\",\"jwk\":", jwe->jose.alg->alg); - m = end - p; + m = lws_ptr_diff(end, p); n = lws_jwk_export(&jwe->jwk, 0, p, &m); if (n < 0) { lwsl_notice("failed to export jwk\n"); @@ -646,7 +647,7 @@ free(buf); - return p1 - out; + return lws_ptr_diff(p1, out); bail: lws_jws_destroy(&jws); @@ -717,7 +718,7 @@ * } */ -LWS_VISIBLE int +int lws_jwe_render_flattened(struct lws_jwe *jwe, char *out, size_t out_len) { char buf[3072], *p1, *end1, protected[128]; @@ -757,7 +758,9 @@ /* unprotected not supported atm */ - p1 += lws_snprintf(p1, end1 - p1, "\",\n\"header\":%.*s", jlen, buf); + p1 += lws_snprintf(p1, end1 - p1, "\",\n\"header\":"); + lws_strnncpy(p1, buf, jlen, end1 - p1); + p1 += strlen(p1); for (m = 0; m < (int)LWS_ARRAY_SIZE(protected_en); m++) if (jwe->jws.map.buf[protected_idx[m]]) { @@ -779,7 +782,7 @@ p1 += lws_snprintf(p1, end1 - p1, "\n}\n"); - return p1 - out; + return lws_ptr_diff(p1, out); bail: lws_jws_destroy(&jwe->jws); diff -Nru libwebsockets-3.2.1/lib/jose/jwe/jwe-ecdh-es-aeskw.c libwebsockets-4.1.6/lib/jose/jwe/jwe-ecdh-es-aeskw.c --- libwebsockets-3.2.1/lib/jose/jwe/jwe-ecdh-es-aeskw.c 2019-12-18 14:45:31.000000000 +0000 +++ libwebsockets-4.1.6/lib/jose/jwe/jwe-ecdh-es-aeskw.c 2020-12-01 17:40:26.000000000 +0000 @@ -1,29 +1,29 @@ /* - * libwebsockets - JSON Web Encryption support + * libwebsockets - small server side websockets and web server implementation * - * Copyright (C) 2018 Andy Green - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation: - * version 2.1 of the License. - * - * This library is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with this library; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, - * MA 02110-1301 USA - * - * - * JWE code related to ecdh-es + Concat KDF and aes kw + * Copyright (C) 2010 - 2019 Andy Green * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to + * deal in the Software without restriction, including without limitation the + * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or + * sell copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS + * IN THE SOFTWARE. */ -#include "core/private.h" -#include "jose/jwe/private.h" + +#include "private-lib-core.h" +#include "private-lib-jose-jwe.h" /* * From RFC7518 JWA @@ -203,7 +203,7 @@ derived[LWS_JWE_LIMIT_KEY_ELEMENT_BYTES]; int m, n, ret = -1, ot = *temp_len, ss_len = sizeof(shared_secret), // kw_hlen = lws_genhash_size(jwe->jose.alg->hash_type), - enc_hlen = lws_genhmac_size(jwe->jose.enc_alg->hmac_type), + enc_hlen = (int)lws_genhmac_size(jwe->jose.enc_alg->hmac_type), ekbytes = 32; //jwe->jose.alg->keybits_fixed / 8; struct lws_genec_ctx ecctx; struct lws_jwk *ephem = &jwe->jose.recipient[jwe->recip].jwk_ephemeral; @@ -293,7 +293,8 @@ /* generate the actual CEK in cek */ - if (lws_get_random(jwe->jws.context, cek, enc_hlen) != enc_hlen) { + if (lws_get_random(jwe->jws.context, cek, enc_hlen) != + (size_t)enc_hlen) { lwsl_err("Problem getting random\n"); goto bail; } @@ -334,9 +335,9 @@ /* rewrite the protected JOSE header to have the epk pieces */ - jwe->jws.map.buf[LJWE_JOSE] = temp + (ot - *temp_len); + jwe->jws.map.buf[LJWE_JOSE] = temp; - m = n = lws_snprintf(temp + (ot - *temp_len), *temp_len, + m = n = lws_snprintf(temp, *temp_len, "{\"alg\":\"%s\", \"enc\":\"%s\", \"epk\":", jwe->jose.alg->alg, jwe->jose.enc_alg->alg); *temp_len -= n; @@ -377,7 +378,7 @@ lws_jwe_encrypt_ecdh_cbc_hs(struct lws_jwe *jwe, char *temp, int *temp_len) { int ss_len, // kw_hlen = lws_genhash_size(jwe->jose.alg->hash_type), - enc_hlen = lws_genhmac_size(jwe->jose.enc_alg->hmac_type); + enc_hlen = (int)lws_genhmac_size(jwe->jose.enc_alg->hmac_type); uint8_t cek[LWS_JWE_LIMIT_KEY_ELEMENT_BYTES]; int ekbytes = jwe->jose.alg->keybits_fixed / 8; int n, ot = *temp_len, ret = -1; @@ -454,7 +455,7 @@ uint8_t shared_secret[LWS_JWE_LIMIT_KEY_ELEMENT_BYTES], derived[LWS_JWE_LIMIT_KEY_ELEMENT_BYTES]; int ekbytes = jwe->jose.enc_alg->keybits_fixed / 8, - enc_hlen = lws_genhmac_size(jwe->jose.enc_alg->hmac_type); + enc_hlen = (int)lws_genhmac_size(jwe->jose.enc_alg->hmac_type); struct lws_genec_ctx ecctx; int n, ret = -1, ss_len = sizeof(shared_secret); diff -Nru libwebsockets-3.2.1/lib/jose/jwe/jwe-rsa-aescbc.c libwebsockets-4.1.6/lib/jose/jwe/jwe-rsa-aescbc.c --- libwebsockets-3.2.1/lib/jose/jwe/jwe-rsa-aescbc.c 2019-12-18 14:45:31.000000000 +0000 +++ libwebsockets-4.1.6/lib/jose/jwe/jwe-rsa-aescbc.c 2020-12-01 17:40:26.000000000 +0000 @@ -1,29 +1,29 @@ /* - * libwebsockets - JSON Web Encryption support + * libwebsockets - small server side websockets and web server implementation * - * Copyright (C) 2018 Andy Green - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation: - * version 2.1 of the License. - * - * This library is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with this library; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, - * MA 02110-1301 USA - * - * - * JWE code related to rsa + aescbc + * Copyright (C) 2010 - 2019 Andy Green * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to + * deal in the Software without restriction, including without limitation the + * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or + * sell copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS + * IN THE SOFTWARE. */ -#include "core/private.h" -#include "jose/jwe/private.h" + +#include "private-lib-core.h" +#include "private-lib-jose-jwe.h" /* * Requirements on entry: @@ -46,7 +46,8 @@ lws_jwe_encrypt_rsa_aes_cbc_hs(struct lws_jwe *jwe, char *temp, int *temp_len) { - int n, hlen = lws_genhmac_size(jwe->jose.enc_alg->hmac_type), ot = *temp_len; + int n, hlen = (int)lws_genhmac_size(jwe->jose.enc_alg->hmac_type), + ot = *temp_len; char ekey[LWS_GENHASH_LARGEST]; struct lws_genrsa_ctx rsactx; @@ -63,7 +64,7 @@ * Create a b64 version of the JOSE header, needed as aad */ if (lws_jws_encode_b64_element(&jwe->jws.map_b64, LJWE_JOSE, - temp + (ot - *temp_len), temp_len, + temp, temp_len, jwe->jws.map.buf[LJWE_JOSE], jwe->jws.map.len[LJWE_JOSE])) return -1; diff -Nru libwebsockets-3.2.1/lib/jose/jwe/jwe-rsa-aesgcm.c libwebsockets-4.1.6/lib/jose/jwe/jwe-rsa-aesgcm.c --- libwebsockets-3.2.1/lib/jose/jwe/jwe-rsa-aesgcm.c 2019-12-18 14:45:31.000000000 +0000 +++ libwebsockets-4.1.6/lib/jose/jwe/jwe-rsa-aesgcm.c 2020-12-01 17:40:26.000000000 +0000 @@ -1,29 +1,29 @@ /* - * libwebsockets - JSON Web Encryption support + * libwebsockets - small server side websockets and web server implementation * - * Copyright (C) 2018 Andy Green - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation: - * version 2.1 of the License. - * - * This library is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with this library; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, - * MA 02110-1301 USA - * - * - * JWE code related to aes gcm + * Copyright (C) 2010 - 2019 Andy Green * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to + * deal in the Software without restriction, including without limitation the + * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or + * sell copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS + * IN THE SOFTWARE. */ -#include "core/private.h" -#include "jose/jwe/private.h" + +#include "private-lib-core.h" +#include "private-lib-jose-jwe.h" #define LWS_AESGCM_IV 12 @@ -44,7 +44,7 @@ /* create the IV + CEK */ if (lws_jws_randomize_element(jwe->jws.context, &jwe->jws.map, LJWE_IV, - temp + (ot - *temp_len), temp_len, + temp, temp_len, LWS_AESGCM_IV, 0)) return -1; @@ -68,7 +68,7 @@ */ if (!jwe->cek_valid) { if (lws_get_random(jwe->jws.context, jwe->cek, ekbytes) != - ekbytes) { + (size_t)ekbytes) { lwsl_err("%s: Problem getting random\n", __func__); return -1; } diff -Nru libwebsockets-3.2.1/lib/jose/jwe/private.h libwebsockets-4.1.6/lib/jose/jwe/private.h --- libwebsockets-3.2.1/lib/jose/jwe/private.h 2019-12-18 14:45:31.000000000 +0000 +++ libwebsockets-4.1.6/lib/jose/jwe/private.h 1970-01-01 00:00:00.000000000 +0000 @@ -1,85 +0,0 @@ -/* - * libwebsockets - JSON Web Encryption support - * - * Copyright (C) 2018 Andy Green - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation: - * version 2.1 of the License. - * - * This library is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with this library; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, - * MA 02110-1301 USA - * - */ -#define LWS_AESGCM_IV 12 -#define LWS_AESGCM_TAG 16 - -/* jwe-rsa-aescbc.c */ - -int -lws_jwe_auth_and_decrypt_rsa_aes_cbc_hs(struct lws_jwe *jwe); - - -int -lws_jwe_encrypt_rsa_aes_cbc_hs(struct lws_jwe *jwe, - char *temp, int *temp_len); - -int -lws_jwe_auth_and_decrypt_cbc_hs(struct lws_jwe *jwe, uint8_t *enc_cek, - uint8_t *aad, int aad_len); - - -/* jws-rsa-aesgcm.c */ - -int -lws_jwe_auth_and_decrypt_gcm(struct lws_jwe *jwe, uint8_t *enc_cek, - uint8_t *aad, int aad_len); - -int -lws_jwe_auth_and_decrypt_rsa_aes_gcm(struct lws_jwe *jwe); - -int -lws_jwe_encrypt_gcm(struct lws_jwe *jwe, - uint8_t *enc_cek, uint8_t *aad, int aad_len); - -int -lws_jwe_encrypt_rsa_aes_gcm(struct lws_jwe *jwe, - char *temp, int *temp_len); - - - - -/* jwe-rsa-aeskw.c */ - -int -lws_jwe_encrypt_aeskw_cbc_hs(struct lws_jwe *jwe, - char *temp, int *temp_len); - -int -lws_jwe_auth_and_decrypt_aeskw_cbc_hs(struct lws_jwe *jwe); - -/* aescbc.c */ - -int -lws_jwe_auth_and_decrypt_cbc_hs(struct lws_jwe *jwe, uint8_t *enc_cek, - uint8_t *aad, int aad_len); - -int -lws_jwe_encrypt_cbc_hs(struct lws_jwe *jwe, - uint8_t *cek, uint8_t *aad, int aad_len); - -int -lws_jwe_auth_and_decrypt_ecdh_cbc_hs(struct lws_jwe *jwe, - char *temp, int *temp_len); - -int -lws_jwe_encrypt_ecdh_cbc_hs(struct lws_jwe *jwe, - char *temp, int *temp_len); diff -Nru libwebsockets-3.2.1/lib/jose/jwe/private-lib-jose-jwe.h libwebsockets-4.1.6/lib/jose/jwe/private-lib-jose-jwe.h --- libwebsockets-3.2.1/lib/jose/jwe/private-lib-jose-jwe.h 1970-01-01 00:00:00.000000000 +0000 +++ libwebsockets-4.1.6/lib/jose/jwe/private-lib-jose-jwe.h 2020-12-01 17:40:26.000000000 +0000 @@ -0,0 +1,88 @@ +/* + * libwebsockets - small server side websockets and web server implementation + * + * Copyright (C) 2010 - 2019 Andy Green + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to + * deal in the Software without restriction, including without limitation the + * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or + * sell copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS + * IN THE SOFTWARE. + */ + +#define LWS_AESGCM_IV 12 +#define LWS_AESGCM_TAG 16 + +/* jwe-rsa-aescbc.c */ + +int +lws_jwe_auth_and_decrypt_rsa_aes_cbc_hs(struct lws_jwe *jwe); + + +int +lws_jwe_encrypt_rsa_aes_cbc_hs(struct lws_jwe *jwe, + char *temp, int *temp_len); + +int +lws_jwe_auth_and_decrypt_cbc_hs(struct lws_jwe *jwe, uint8_t *enc_cek, + uint8_t *aad, int aad_len); + + +/* jws-rsa-aesgcm.c */ + +int +lws_jwe_auth_and_decrypt_gcm(struct lws_jwe *jwe, uint8_t *enc_cek, + uint8_t *aad, int aad_len); + +int +lws_jwe_auth_and_decrypt_rsa_aes_gcm(struct lws_jwe *jwe); + +int +lws_jwe_encrypt_gcm(struct lws_jwe *jwe, + uint8_t *enc_cek, uint8_t *aad, int aad_len); + +int +lws_jwe_encrypt_rsa_aes_gcm(struct lws_jwe *jwe, + char *temp, int *temp_len); + + + + +/* jwe-rsa-aeskw.c */ + +int +lws_jwe_encrypt_aeskw_cbc_hs(struct lws_jwe *jwe, + char *temp, int *temp_len); + +int +lws_jwe_auth_and_decrypt_aeskw_cbc_hs(struct lws_jwe *jwe); + +/* aescbc.c */ + +int +lws_jwe_auth_and_decrypt_cbc_hs(struct lws_jwe *jwe, uint8_t *enc_cek, + uint8_t *aad, int aad_len); + +int +lws_jwe_encrypt_cbc_hs(struct lws_jwe *jwe, + uint8_t *cek, uint8_t *aad, int aad_len); + +int +lws_jwe_auth_and_decrypt_ecdh_cbc_hs(struct lws_jwe *jwe, + char *temp, int *temp_len); + +int +lws_jwe_encrypt_ecdh_cbc_hs(struct lws_jwe *jwe, + char *temp, int *temp_len); diff -Nru libwebsockets-3.2.1/lib/jose/jwk/jwk.c libwebsockets-4.1.6/lib/jose/jwk/jwk.c --- libwebsockets-3.2.1/lib/jose/jwk/jwk.c 2019-12-18 14:45:31.000000000 +0000 +++ libwebsockets-4.1.6/lib/jose/jwk/jwk.c 2020-12-01 17:40:26.000000000 +0000 @@ -1,26 +1,29 @@ /* - * libwebsockets - JSON Web Key support + * libwebsockets - small server side websockets and web server implementation * - * Copyright (C) 2017 - 2018 Andy Green + * Copyright (C) 2010 - 2019 Andy Green * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation: - * version 2.1 of the License. + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to + * deal in the Software without restriction, including without limitation the + * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or + * sell copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: * - * This library is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. * - * You should have received a copy of the GNU Lesser General Public - * License along with this library; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, - * MA 02110-1301 USA + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS + * IN THE SOFTWARE. */ -#include "core/private.h" -#include "jose/private.h" +#include "private-lib-core.h" +#include "private-lib-jose.h" #if !defined(LWS_PLAT_OPTEE) && !defined(OPTEE_DEV_KIT) #include @@ -161,7 +164,7 @@ }; static const char ec_b64[] = { 0, 1, 1, 1 }; -LWS_VISIBLE int +int lws_jwk_dump(struct lws_jwk *jwk) { const char **enames, *b64; @@ -284,7 +287,7 @@ } } -LWS_VISIBLE void +void lws_jwk_destroy(struct lws_jwk *jwk) { lws_jwk_destroy_elements(jwk->e, LWS_ARRAY_SIZE(jwk->e)); @@ -297,6 +300,7 @@ struct lws_jwk_parse_state *jps = (struct lws_jwk_parse_state *)ctx->user; struct lws_jwk *jwk = jps->jwk; unsigned int idx, poss, n; + char dotstar[64]; if (reason == LEJPCB_VAL_STR_START) jps->pos = 0; @@ -457,8 +461,8 @@ jps->possible = F_EC; goto cont; } - lwsl_err("%s: Unknown KTY '%.*s'\n", __func__, ctx->npos, - ctx->buf); + lws_strnncpy(dotstar, ctx->buf, ctx->npos, sizeof(dotstar)); + lwsl_err("%s: Unknown KTY '%s'\n", __func__, dotstar); return -1; default: @@ -546,7 +550,7 @@ LWS_ARRAY_SIZE(jwk_tok)); } -LWS_VISIBLE int +int lws_jwk_dup_oct(struct lws_jwk *jwk, const void *key, int len) { jwk->e[LWS_GENCRYPTO_KTY_OCT].buf = lws_malloc(len, __func__); @@ -561,10 +565,11 @@ return 0; } -LWS_VISIBLE int +int lws_jwk_generate(struct lws_context *context, struct lws_jwk *jwk, enum lws_gencrypto_kty kty, int bits, const char *curve) { + size_t sn; int n; memset(jwk, 0, sizeof(*jwk)); @@ -588,11 +593,11 @@ } break; case LWS_GENCRYPTO_KTY_OCT: - n = lws_gencrypto_bits_to_bytes(bits); - jwk->e[LWS_GENCRYPTO_OCT_KEYEL_K].buf = lws_malloc(n, "oct"); - jwk->e[LWS_GENCRYPTO_OCT_KEYEL_K].len = n; + sn = lws_gencrypto_bits_to_bytes(bits); + jwk->e[LWS_GENCRYPTO_OCT_KEYEL_K].buf = lws_malloc(sn, "oct"); + jwk->e[LWS_GENCRYPTO_OCT_KEYEL_K].len = (uint32_t)sn; if (lws_get_random(context, - jwk->e[LWS_GENCRYPTO_OCT_KEYEL_K].buf, n) != n) { + jwk->e[LWS_GENCRYPTO_OCT_KEYEL_K].buf, sn) != sn) { lwsl_err("%s: problem getting random\n", __func__); return 1; } @@ -631,7 +636,7 @@ return 0; } -LWS_VISIBLE int +int lws_jwk_import(struct lws_jwk *jwk, lws_jwk_key_import_callback cb, void *user, const char *in, size_t len) { @@ -641,7 +646,7 @@ lws_jwk_init_jps(&jctx, &jps, jwk, cb, user); - m = (int)(signed char)lejp_parse(&jctx, (uint8_t *)in, len); + m = lejp_parse(&jctx, (uint8_t *)in, (int)len); lejp_destruct(&jctx); if (m < 0) { @@ -663,8 +668,8 @@ } -LWS_VISIBLE int -lws_jwk_export(struct lws_jwk *jwk, int private, char *p, int *len) +int +lws_jwk_export(struct lws_jwk *jwk, int flags, char *p, int *len) { char *start = p, *end = &p[*len - 1]; int n, m, limit, first = 1, asym = 0; @@ -737,9 +742,9 @@ } tok[pos] = '\0'; pos = 0; - if (private || !asym || - (strcmp(tok, "sign") && - strcmp(tok, "encrypt"))) { + if ((flags & LWSJWKF_EXPORT_PRIVATE) || + !asym || (strcmp(tok, "sign") && + strcmp(tok, "encrypt"))) { if (!f) *p++ = ','; f = 0; @@ -755,20 +760,24 @@ default: /* both sig and enc require asym private key */ - if (!private && asym && l->idx == (int)JWK_META_USE) + if (!(flags & LWSJWKF_EXPORT_PRIVATE) && + asym && l->idx == (int)JWK_META_USE) break; if (!first) *p++ = ','; first = 0; - p += lws_snprintf(p, end - p, "\"%s\":\"%.*s\"", - l->name, jwk->meta[l->idx].len, - jwk->meta[l->idx].buf); + p += lws_snprintf(p, end - p, "\"%s\":\"", + l->name); + lws_strnncpy(p, (const char *)jwk->meta[l->idx].buf, + jwk->meta[l->idx].len, end - p); + p += strlen(p); + p += lws_snprintf(p, end - p, "\""); break; } } if ((!(l->meta & 1)) && jwk->e[l->idx].buf && - (private || !(l->meta & 2))) { + ((flags & LWSJWKF_EXPORT_PRIVATE) || !(l->meta & 2))) { if (!first) *p++ = ','; first = 0; @@ -776,11 +785,12 @@ p += lws_snprintf(p, end - p, "\"%s\":\"", l->name); if (jwk->kty == LWS_GENCRYPTO_KTY_EC && - l->idx == (int)LWS_GENCRYPTO_EC_KEYEL_CRV) - m = lws_snprintf(p, end - p, "%.*s", - jwk->e[l->idx].len, - (const char *)jwk->e[l->idx].buf); - else + l->idx == (int)LWS_GENCRYPTO_EC_KEYEL_CRV) { + lws_strnncpy(p, + (const char *)jwk->e[l->idx].buf, + jwk->e[l->idx].len, end - p); + m = (int)strlen(p); + } else m = lws_jws_base64_enc( (const char *)jwk->e[l->idx].buf, jwk->e[l->idx].len, p, end - p - 4); @@ -795,14 +805,15 @@ l++; } - p += lws_snprintf(p, end - p, "}\n"); + p += lws_snprintf(p, end - p, + (flags & LWSJWKF_EXPORT_NOCRLF) ? "}" : "}\n"); - *len -= p - start; + *len -= lws_ptr_diff(p, start); - return p - start; + return lws_ptr_diff(p, start); } -LWS_VISIBLE int +int lws_jwk_rfc7638_fingerprint(struct lws_jwk *jwk, char *digest32) { struct lws_genhash_ctx hash_ctx; @@ -811,7 +822,7 @@ tmp = lws_malloc(tmpsize, "rfc7638 tmp"); - n = lws_jwk_export(jwk, 0, tmp, &tmpsize); + n = lws_jwk_export(jwk, LWSJWKF_EXPORT_NOCRLF, tmp, &tmpsize); if (n < 0) goto bail; @@ -836,7 +847,7 @@ return -1; } -LWS_VISIBLE int +int lws_jwk_strdup_meta(struct lws_jwk *jwk, enum enum_jwk_meta_tok idx, const char *in, int len) { @@ -849,7 +860,7 @@ return 0; } -LWS_VISIBLE int +int lws_jwk_load(struct lws_jwk *jwk, const char *filename, lws_jwk_key_import_callback cb, void *user) { @@ -874,7 +885,7 @@ return -1; } -LWS_VISIBLE int +int lws_jwk_save(struct lws_jwk *jwk, const char *filename) { int buflen = 4096; @@ -884,7 +895,7 @@ if (!buf) return -1; - n = lws_jwk_export(jwk, 1, buf, &buflen); + n = lws_jwk_export(jwk, LWSJWKF_EXPORT_PRIVATE, buf, &buflen); if (n < 0) goto bail; diff -Nru libwebsockets-3.2.1/lib/jose/jws/jose.c libwebsockets-4.1.6/lib/jose/jws/jose.c --- libwebsockets-3.2.1/lib/jose/jws/jose.c 2019-12-18 14:45:31.000000000 +0000 +++ libwebsockets-4.1.6/lib/jose/jws/jose.c 2020-12-01 17:40:26.000000000 +0000 @@ -1,29 +1,32 @@ -/* - * libwebsockets - JSON Web Signature support + /* + * libwebsockets - small server side websockets and web server implementation * - * Copyright (C) 2017 - 2018 Andy Green + * Copyright (C) 2010 - 2019 Andy Green * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation: - * version 2.1 of the License. - * - * This library is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with this library; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, - * MA 02110-1301 USA + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to + * deal in the Software without restriction, including without limitation the + * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or + * sell copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS + * IN THE SOFTWARE. * * JOSE is actually specified as part of JWS RFC7515. JWE references RFC7515 * to specify its JOSE JSON object. So it lives in ./lib/jose/jws/jose.c. */ -#include "core/private.h" -#include "jose/private.h" +#include "private-lib-core.h" +#include "jose/private-lib-jose.h" #include @@ -225,8 +228,8 @@ return 0; case LJJHI_TYP: /* Optional: string: media type */ - if (strcmp(ctx->buf, "JWT")) - return -1; + lws_strnncpy(args->jose->typ, ctx->buf, ctx->npos, + sizeof(args->jose->typ)); break; case LJJHI_JKU: /* Optional: string */ @@ -427,10 +430,10 @@ lejp_construct(&jctx, lws_jws_jose_cb, &args, jws_jose, LWS_ARRAY_SIZE(jws_jose)); - m = (int)(signed char)lejp_parse(&jctx, (uint8_t *)buf, n); + m = lejp_parse(&jctx, (uint8_t *)buf, n); lejp_destruct(&jctx); if (m < 0) { - lwsl_notice("%s: parse %.*s returned %d\n", __func__, n, buf, m); + lwsl_notice("%s: parse returned %d\n", __func__, m); return -1; } @@ -506,7 +509,7 @@ sub = 1; m = lws_b64_encode_string_url((const char *) jose->e[n].buf, jose->e[n].len, - out, end - out); + out, lws_ptr_diff(end, out)); if (m < 0) return -1; out += m; @@ -525,7 +528,7 @@ sub = 1; m = lws_b64_encode_string((const char *) jose->e[n].buf, jose->e[n].len, - out, end - out); + out, lws_ptr_diff(end, out)); if (m < 0) return -1; out += m; @@ -543,7 +546,7 @@ out += lws_snprintf(out, end - out, "%s\"%s\":", sub ? ",\n" : "", jws_jose[n]); sub = 1; - vl = end - out; + vl = lws_ptr_diff(end, out); m = lws_jwk_export(jwk, 0, out, &vl); if (m < 0) { lwsl_notice("%s: failed to export key\n", @@ -595,7 +598,7 @@ if (out > end - 2) return -1; - return out_len - (end - out) - 1; + return lws_ptr_diff(out_len, (end - out)) - 1; bail: return -1; diff -Nru libwebsockets-3.2.1/lib/jose/jws/jws.c libwebsockets-4.1.6/lib/jose/jws/jws.c --- libwebsockets-3.2.1/lib/jose/jws/jws.c 2019-12-18 14:45:31.000000000 +0000 +++ libwebsockets-4.1.6/lib/jose/jws/jws.c 2020-12-01 17:40:26.000000000 +0000 @@ -1,26 +1,29 @@ /* - * libwebsockets - JSON Web Signature support + * libwebsockets - small server side websockets and web server implementation * - * Copyright (C) 2017 - 2018 Andy Green + * Copyright (C) 2010 - 2019 Andy Green * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation: - * version 2.1 of the License. + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to + * deal in the Software without restriction, including without limitation the + * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or + * sell copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: * - * This library is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. * - * You should have received a copy of the GNU Lesser General Public - * License along with this library; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, - * MA 02110-1301 USA + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS + * IN THE SOFTWARE. */ -#include "core/private.h" -#include "private.h" +#include "private-lib-core.h" +#include "private-lib-jose-jws.h" /* * Currently only support flattened or compact (implicitly single signature) @@ -147,7 +150,7 @@ lejp_construct(&jctx, lws_jws_json_cb, &args, jws_json, LWS_ARRAY_SIZE(jws_json)); - m = (int)(signed char)lejp_parse(&jctx, (uint8_t *)buf, len); + m = lejp_parse(&jctx, (uint8_t *)buf, len); lejp_destruct(&jctx); if (m < 0) { lwsl_notice("%s: parse returned %d\n", __func__, m); @@ -157,7 +160,7 @@ return 0; } -LWS_VISIBLE void +void lws_jws_init(struct lws_jws *jws, struct lws_jwk *jwk, struct lws_context *context) { @@ -178,14 +181,14 @@ lws_explicit_bzero((void *)map->buf[n], map->len[n]); } -LWS_VISIBLE void +void lws_jws_destroy(struct lws_jws *jws) { lws_jws_map_bzero(&jws->map); jws->jwk = NULL; } -LWS_VISIBLE int +int lws_jws_dup_element(struct lws_jws_map *map, int idx, char *temp, int *temp_len, const void *in, size_t in_len, size_t actual_alloc) { @@ -197,15 +200,15 @@ memcpy(temp, in, in_len); - map->len[idx] = in_len; + map->len[idx] = (uint32_t)in_len; map->buf[idx] = temp; - *temp_len -= actual_alloc; + *temp_len -= (int)actual_alloc; return 0; } -LWS_VISIBLE int +int lws_jws_encode_b64_element(struct lws_jws_map *map, int idx, char *temp, int *temp_len, const void *in, size_t in_len) @@ -227,7 +230,7 @@ return 0; } -LWS_VISIBLE int +int lws_jws_randomize_element(struct lws_context *context, struct lws_jws_map *map, int idx, char *temp, int *temp_len, size_t random_len, size_t actual_alloc) @@ -238,20 +241,20 @@ if ((size_t)*temp_len < actual_alloc) return -1; - map->len[idx] = random_len; + map->len[idx] = (uint32_t)random_len; map->buf[idx] = temp; - if (lws_get_random(context, temp, random_len) != (int)random_len) { + if (lws_get_random(context, temp, random_len) != random_len) { lwsl_err("Problem getting random\n"); return -1; } - *temp_len -= actual_alloc; + *temp_len -= (int)actual_alloc; return 0; } -LWS_VISIBLE int +int lws_jws_alloc_element(struct lws_jws_map *map, int idx, char *temp, int *temp_len, size_t len, size_t actual_alloc) { @@ -261,19 +264,19 @@ if ((size_t)*temp_len < actual_alloc) return -1; - map->len[idx] = len; + map->len[idx] = (uint32_t)len; map->buf[idx] = temp; - *temp_len -= actual_alloc; + *temp_len -= (int)actual_alloc; return 0; } -LWS_VISIBLE int +int lws_jws_base64_enc(const char *in, size_t in_len, char *out, size_t out_max) { int n; - n = lws_b64_encode_string_url(in, in_len, out, out_max - 1); + n = lws_b64_encode_string_url(in, (int)in_len, out, (int)out_max - 1); if (n < 0) { lwsl_notice("%s: in len %d too large for %d out buf\n", __func__, (int)in_len, (int)out_max); @@ -289,7 +292,7 @@ return n; } -LWS_VISIBLE int +int lws_jws_b64_compact_map(const char *in, int len, struct lws_jws_map *map) { int me = 0; @@ -317,7 +320,7 @@ * map_b64 set to b64 elements */ -LWS_VISIBLE int +int lws_jws_compact_decode(const char *in, int len, struct lws_jws_map *map, struct lws_jws_map *map_b64, char *out, int *out_len) @@ -384,11 +387,11 @@ return 0; } -LWS_VISIBLE int +int lws_jws_encode_section(const char *in, size_t in_len, int first, char **p, char *end) { - int n, len = (end - *p) - 1; + int n, len = lws_ptr_diff(end, (*p)) - 1; char *p_entry = *p; if (len < 3) @@ -403,10 +406,10 @@ *p += n; - return (*p) - p_entry; + return lws_ptr_diff((*p), p_entry); } -LWS_VISIBLE int +int lws_jws_compact_encode(struct lws_jws_map *map_b64, /* b64-encoded */ const struct lws_jws_map *map, /* non-b64 */ char *buf, int *len) @@ -438,7 +441,7 @@ * the JOSE header and signature, decoded versions too. */ -LWS_VISIBLE int +int lws_jws_sig_confirm(struct lws_jws_map *map_b64, struct lws_jws_map *map, struct lws_jwk *jwk, struct lws_context *context) { @@ -513,7 +516,7 @@ return -1; } - h_len = lws_genhash_size(jose.alg->hash_type); + // h_len = lws_genhash_size(jose.alg->hash_type); if (lws_genrsa_create(&rsactx, jwk->e, context, padding, LWS_GENHASH_TYPE_UNKNOWN)) { @@ -539,7 +542,7 @@ /* SHA256/384/512 HMAC */ - h_len = lws_genhmac_size(jose.alg->hmac_type); + h_len = (int)lws_genhmac_size(jose.alg->hmac_type); /* 6) compute HMAC over payload */ @@ -626,7 +629,7 @@ return -1; } - h_len = lws_genhash_size(jose.alg->hash_type); + h_len = (int)lws_genhash_size(jose.alg->hash_type); if (lws_genecdsa_create(&ecdsactx, context, NULL)) { lwsl_notice("%s: lws_genrsa_public_decrypt_create\n", @@ -663,7 +666,7 @@ /* it's already a b64 map, we will make a temp plain version */ -LWS_VISIBLE int +int lws_jws_sig_confirm_compact_b64_map(struct lws_jws_map *map_b64, struct lws_jwk *jwk, struct lws_context *context, @@ -684,7 +687,7 @@ * plain version */ -LWS_VISIBLE int +int lws_jws_sig_confirm_compact_b64(const char *in, size_t len, struct lws_jws_map *map, struct lws_jwk *jwk, struct lws_context *context, @@ -693,10 +696,10 @@ struct lws_jws_map map_b64; int n; - if (lws_jws_b64_compact_map(in, len, &map_b64) < 0) + if (lws_jws_b64_compact_map(in, (int)len, &map_b64) < 0) return -1; - n = lws_jws_compact_decode(in, len, map, &map_b64, temp, temp_len); + n = lws_jws_compact_decode(in, (int)len, map, &map_b64, temp, temp_len); if (n > 3 || n < 0) return -1; @@ -705,7 +708,7 @@ /* it's already plain, we will make a temp b64 version */ -LWS_VISIBLE int +int lws_jws_sig_confirm_compact(struct lws_jws_map *map, struct lws_jwk *jwk, struct lws_context *context, char *temp, int *temp_len) @@ -724,7 +727,8 @@ struct lws_context *context, char *temp, int *temp_len) { - if (lws_jws_json_parse(jws, (const uint8_t *)in, len, temp, temp_len)) { + if (lws_jws_json_parse(jws, (const uint8_t *)in, + (int)len, temp, temp_len)) { lwsl_err("%s: lws_jws_json_parse failed\n", __func__); return -1; @@ -884,7 +888,7 @@ * } */ -LWS_VISIBLE int +int lws_jws_write_flattened_json(struct lws_jws *jws, char *flattened, size_t len) { size_t n = 0; @@ -892,25 +896,34 @@ if (len < 1) return 1; - n += lws_snprintf(flattened + n, len - n , "{\"payload\": \"%.*s\",\n", - jws->map_b64.len[LJWS_PYLD], - jws->map_b64.buf[LJWS_PYLD]); - - n += lws_snprintf(flattened + n, len - n , " \"protected\": \"%.*s\",\n", - jws->map_b64.len[LJWS_JOSE], - jws->map_b64.buf[LJWS_JOSE]); - - if (jws->map_b64.buf[LJWS_UHDR]) - n += lws_snprintf(flattened + n, len - n , " \"header\": %.*s,\n", - jws->map_b64.len[LJWS_UHDR], jws->map_b64.buf[LJWS_UHDR]); + n += lws_snprintf(flattened + n, len - n , "{\"payload\": \""); + lws_strnncpy(flattened + n, jws->map_b64.buf[LJWS_PYLD], + jws->map_b64.len[LJWS_PYLD], len - n); + n += strlen(flattened + n); + + n += lws_snprintf(flattened + n, len - n , "\",\n \"protected\": \""); + lws_strnncpy(flattened + n, jws->map_b64.buf[LJWS_JOSE], + jws->map_b64.len[LJWS_JOSE], len - n); + n += strlen(flattened + n); + + if (jws->map_b64.buf[LJWS_UHDR]) { + n += lws_snprintf(flattened + n, len - n , "\",\n \"header\": "); + lws_strnncpy(flattened + n, jws->map_b64.buf[LJWS_UHDR], + jws->map_b64.len[LJWS_UHDR], len - n); + n += strlen(flattened + n); + } + + n += lws_snprintf(flattened + n, len - n , "\",\n \"signature\": \""); + lws_strnncpy(flattened + n, jws->map_b64.buf[LJWS_SIG], + jws->map_b64.len[LJWS_SIG], len - n); + n += strlen(flattened + n); - n += lws_snprintf(flattened + n, len - n , " \"signature\": \"%.*s\"}\n", - jws->map_b64.len[LJWS_SIG], jws->map_b64.buf[LJWS_SIG]); + n += lws_snprintf(flattened + n, len - n , "\"}\n"); return (n >= len - 1); } -LWS_VISIBLE int +int lws_jws_write_compact(struct lws_jws *jws, char *compact, size_t len) { size_t n = 0; @@ -918,12 +931,306 @@ if (len < 1) return 1; - n += lws_snprintf(compact + n, len - n , "%.*s", - jws->map_b64.len[LJWS_JOSE], jws->map_b64.buf[LJWS_JOSE]); - n += lws_snprintf(compact + n, len - n , ".%.*s", - jws->map_b64.len[LJWS_PYLD], jws->map_b64.buf[LJWS_PYLD]); - n += lws_snprintf(compact + n, len - n , ".%.*s", - jws->map_b64.len[LJWS_SIG], jws->map_b64.buf[LJWS_SIG]); + lws_strnncpy(compact + n, jws->map_b64.buf[LJWS_JOSE], + jws->map_b64.len[LJWS_JOSE], len - n); + n += strlen(compact + n); + if (n >= len - 1) + return 1; + compact[n++] = '.'; + lws_strnncpy(compact + n, jws->map_b64.buf[LJWS_PYLD], + jws->map_b64.len[LJWS_PYLD], len - n); + n += strlen(compact + n); + if (n >= len - 1) + return 1; + compact[n++] = '.'; + lws_strnncpy(compact + n, jws->map_b64.buf[LJWS_SIG], + jws->map_b64.len[LJWS_SIG], len - n); + n += strlen(compact + n); return n >= len - 1; } + +int +lws_jwt_signed_validate(struct lws_context *ctx, struct lws_jwk *jwk, + const char *alg_list, const char *com, size_t len, + char *temp, int tl, char *out, size_t *out_len) +{ + struct lws_tokenize ts; + struct lws_jose jose; + int otl = tl, r = 1; + struct lws_jws jws; + size_t n; + + memset(&jws, 0, sizeof(jws)); + lws_jose_init(&jose); + + /* + * Decode the b64.b64[.b64] compact serialization + * blocks + */ + + n = lws_jws_compact_decode(com, (int)len, &jws.map, &jws.map_b64, + temp, &tl); + if (n != 3) { + lwsl_err("%s: concat_map failed: %d\n", __func__, (int)n); + goto bail; + } + + temp += otl - tl; + otl = tl; + + /* + * Parse the JOSE header + */ + + if (lws_jws_parse_jose(&jose, jws.map.buf[LJWS_JOSE], + jws.map.len[LJWS_JOSE], temp, &tl) < 0) { + lwsl_err("%s: JOSE parse failed\n", __func__); + goto bail; + } + + /* + * Insist to see an alg in there that we list as acceptable + */ + + lws_tokenize_init(&ts, alg_list, LWS_TOKENIZE_F_COMMA_SEP_LIST | + LWS_TOKENIZE_F_RFC7230_DELIMS); + n = strlen(jose.alg->alg); + + do { + ts.e = lws_tokenize(&ts); + if (ts.e == LWS_TOKZE_TOKEN && ts.token_len == n && + !strncmp(jose.alg->alg, ts.token, ts.token_len)) + break; + } while (ts.e != LWS_TOKZE_ENDED); + + if (ts.e != LWS_TOKZE_TOKEN) { + lwsl_err("%s: JOSE using alg %s (accepted: %s)\n", __func__, + jose.alg->alg, alg_list); + goto bail; + } + + /* we liked the alg... now how about the crypto? */ + + if (lws_jws_sig_confirm(&jws.map_b64, &jws.map, jwk, ctx) < 0) { + lwsl_notice("%s: confirm JWT sig failed\n", + __func__); + goto bail; + } + + /* yeah, it's validated... see about copying it out */ + + if (*out_len < jws.map.len[LJWS_PYLD] + 1) { + /* we don't have enough room */ + r = 2; + goto bail; + } + + memcpy(out, jws.map.buf[LJWS_PYLD], jws.map.len[LJWS_PYLD]); + *out_len = jws.map.len[LJWS_PYLD]; + out[jws.map.len[LJWS_PYLD]] = '\0'; + + r = 0; + +bail: + lws_jws_destroy(&jws); + lws_jose_destroy(&jose); + + return r; +} + +int +lws_jwt_sign_compact(struct lws_context *ctx, struct lws_jwk *jwk, + const char *alg, char *out, size_t *out_len, char *temp, + int tl, const char *format, ...) +{ + int n, r = 1, otl = tl; + struct lws_jose jose; + struct lws_jws jws; + va_list ap; + char *q; + + lws_jws_init(&jws, jwk, ctx); + lws_jose_init(&jose); + + if (lws_gencrypto_jws_alg_to_definition(alg, &jose.alg)) { + lwsl_err("%s: unknown alg %s\n", __func__, alg); + + goto bail; + } + + /* create JOSE header, also needed for output */ + + if (lws_jws_alloc_element(&jws.map, LJWS_JOSE, temp, &tl, + strlen(alg) + 10, 0)) { + lwsl_err("%s: temp space too small\n", __func__); + return 1; + } + + jws.map.len[LJWS_JOSE] = lws_snprintf((char *)jws.map.buf[LJWS_JOSE], + tl, "{\"alg\":\"%s\"}", alg); + + temp += otl - tl; + otl = tl; + + va_start(ap, format); + n = vsnprintf(NULL, 0, format, ap); + va_end(ap); + if (n + 2 >= tl) + goto bail; + + q = lws_malloc(n + 2, __func__); + if (!q) + goto bail; + + va_start(ap, format); + vsnprintf(q, n + 2, format, ap); + va_end(ap); + + /* add the plaintext from stdin to the map and a b64 version */ + + jws.map.buf[LJWS_PYLD] = q; + jws.map.len[LJWS_PYLD] = n; + + if (lws_jws_encode_b64_element(&jws.map_b64, LJWS_PYLD, temp, &tl, + jws.map.buf[LJWS_PYLD], + jws.map.len[LJWS_PYLD])) + goto bail1; + + temp += otl - tl; + otl = tl; + + /* add the b64 JOSE header to the b64 map */ + + if (lws_jws_encode_b64_element(&jws.map_b64, LJWS_JOSE, temp, &tl, + jws.map.buf[LJWS_JOSE], + jws.map.len[LJWS_JOSE])) + goto bail1; + + temp += otl - tl; + otl = tl; + + /* prepare the space for the b64 signature in the map */ + + if (lws_jws_alloc_element(&jws.map_b64, LJWS_SIG, temp, &tl, + lws_base64_size(LWS_JWE_LIMIT_KEY_ELEMENT_BYTES), + 0)) + goto bail1; + + /* sign the plaintext */ + + n = lws_jws_sign_from_b64(&jose, &jws, + (char *)jws.map_b64.buf[LJWS_SIG], + jws.map_b64.len[LJWS_SIG]); + if (n < 0) + goto bail1; + + /* set the actual b64 signature size */ + jws.map_b64.len[LJWS_SIG] = n; + + /* create the compact JWS representation */ + if (lws_jws_write_compact(&jws, out, *out_len)) + goto bail1; + + *out_len = strlen(out); + + r = 0; + +bail1: + lws_free(q); + +bail: + jws.map.buf[LJWS_PYLD] = NULL; + jws.map.len[LJWS_PYLD] = 0; + lws_jws_destroy(&jws); + lws_jose_destroy(&jose); + + return r; +} + +int +lws_jwt_token_sanity(const char *in, size_t in_len, + const char *iss, const char *aud, + const char *csrf_in, + char *sub, size_t sub_len, unsigned long *expiry_unix_time) +{ + unsigned long now = lws_now_secs(), exp; + const char *cp; + size_t len; + + /* + * It has our issuer? + */ + + if (lws_json_simple_strcmp(in, in_len, "\"iss\":", iss)) { + lwsl_notice("%s: iss mismatch\n", __func__); + return 1; + } + + /* + * ... it is indended for us to consume? (this is set + * to the public base url for this sai instance) + */ + if (lws_json_simple_strcmp(in, in_len, "\"aud\":", aud)) { + lwsl_notice("%s: aud mismatch\n", __func__); + return 1; + } + + /* + * ...it's not too early for it? + */ + cp = lws_json_simple_find(in, in_len, "\"nbf\":", &len); + if (!cp || (unsigned long)atol(cp) > now) { + lwsl_notice("%s: nbf fail\n", __func__); + return 1; + } + + /* + * ... and not too late for it? + */ + cp = lws_json_simple_find(in, in_len, "\"exp\":", &len); + exp = (unsigned long)atol(cp); + if (!cp || (unsigned long)atol(cp) < now) { + lwsl_notice("%s: exp fail %lu vs %lu\n", __func__, + cp ? (unsigned long)atol(cp) : 0, now); + return 1; + } + + /* + * Caller cares about subject? Then we must have it, and it can't be + * empty. + */ + + if (sub) { + cp = lws_json_simple_find(in, in_len, "\"sub\":", &len); + if (!cp || !len) { + lwsl_notice("%s: missing subject\n", __func__); + return 1; + } + lws_strnncpy(sub, cp, len, sub_len); + } + + /* + * If caller has been told a Cross Site Request Forgery (CSRF) nonce, + * require this JWT to express the same CSRF... this makes generated + * links for dangerous privileged auth'd actions expire with the JWT + * that was accessing the site when the links were generated. And it + * leaves an attacker not knowing what links to synthesize unless he + * can read the token or pages generated with it. + * + * Using this is very good for security, but it implies you must refresh + * generated pages still when the auth token is expiring (and the user + * must log in again). + */ + + if (csrf_in && + lws_json_simple_strcmp(in, in_len, "\"csrf\":", csrf_in)) { + lwsl_notice("%s: csrf mismatch\n", __func__); + return 1; + } + + if (expiry_unix_time) + *expiry_unix_time = exp; + + return 0; +} diff -Nru libwebsockets-3.2.1/lib/jose/jws/private.h libwebsockets-4.1.6/lib/jose/jws/private.h --- libwebsockets-3.2.1/lib/jose/jws/private.h 2019-12-18 14:45:31.000000000 +0000 +++ libwebsockets-4.1.6/lib/jose/jws/private.h 1970-01-01 00:00:00.000000000 +0000 @@ -1,24 +0,0 @@ -/* - * libwebsockets - JSON Web Signature support - * - * Copyright (C) 2018 Andy Green - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation: - * version 2.1 of the License. - * - * This library is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with this library; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, - * MA 02110-1301 USA - * - * JOSE is actually specified as part of JWS RFC7515. JWE references RFC7515 - * to specify its JOSE JSON object. So it lives in ./lib/jose/jws/jose.c. - */ - diff -Nru libwebsockets-3.2.1/lib/jose/jws/private-lib-jose-jws.h libwebsockets-4.1.6/lib/jose/jws/private-lib-jose-jws.h --- libwebsockets-3.2.1/lib/jose/jws/private-lib-jose-jws.h 1970-01-01 00:00:00.000000000 +0000 +++ libwebsockets-4.1.6/lib/jose/jws/private-lib-jose-jws.h 2020-12-01 17:40:26.000000000 +0000 @@ -0,0 +1,27 @@ + /* + * libwebsockets - small server side websockets and web server implementation + * + * Copyright (C) 2010 - 2019 Andy Green + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to + * deal in the Software without restriction, including without limitation the + * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or + * sell copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS + * IN THE SOFTWARE. + * + * JOSE is actually specified as part of JWS RFC7515. JWE references RFC7515 + * to specify its JOSE JSON object. So it lives in ./lib/jose/jws/jose.c. + */ + diff -Nru libwebsockets-3.2.1/lib/jose/private.h libwebsockets-4.1.6/lib/jose/private.h --- libwebsockets-3.2.1/lib/jose/private.h 2019-12-18 14:45:31.000000000 +0000 +++ libwebsockets-4.1.6/lib/jose/private.h 1970-01-01 00:00:00.000000000 +0000 @@ -1,32 +0,0 @@ -/* - * libwebsockets - jose private header - * - * Copyright (C) 2018 Andy Green - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation: - * version 2.1 of the License. - * - * This library is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with this library; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, - * MA 02110-1301 USA - */ - -void -lws_jwk_destroy_elements(struct lws_gencrypto_keyelem *el, int m); - -void -lws_jwk_init_jps(struct lejp_ctx *jctx, struct lws_jwk_parse_state *jps, - struct lws_jwk *jwk, lws_jwk_key_import_callback cb, - void *user); - -int -lws_jose_render(struct lws_jose *jose, struct lws_jwk *aux_jwk, - char *out, size_t out_len); diff -Nru libwebsockets-3.2.1/lib/jose/private-lib-jose.h libwebsockets-4.1.6/lib/jose/private-lib-jose.h --- libwebsockets-3.2.1/lib/jose/private-lib-jose.h 1970-01-01 00:00:00.000000000 +0000 +++ libwebsockets-4.1.6/lib/jose/private-lib-jose.h 2020-12-01 17:40:26.000000000 +0000 @@ -0,0 +1,35 @@ +/* + * libwebsockets - small server side websockets and web server implementation + * + * Copyright (C) 2010 - 2019 Andy Green + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to + * deal in the Software without restriction, including without limitation the + * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or + * sell copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS + * IN THE SOFTWARE. + */ + +void +lws_jwk_destroy_elements(struct lws_gencrypto_keyelem *el, int m); + +void +lws_jwk_init_jps(struct lejp_ctx *jctx, struct lws_jwk_parse_state *jps, + struct lws_jwk *jwk, lws_jwk_key_import_callback cb, + void *user); + +int +lws_jose_render(struct lws_jose *jose, struct lws_jwk *aux_jwk, + char *out, size_t out_len); diff -Nru libwebsockets-3.2.1/lib/misc/base64-decode.c libwebsockets-4.1.6/lib/misc/base64-decode.c --- libwebsockets-3.2.1/lib/misc/base64-decode.c 2019-12-18 14:45:31.000000000 +0000 +++ libwebsockets-4.1.6/lib/misc/base64-decode.c 2020-12-01 17:40:26.000000000 +0000 @@ -3,7 +3,7 @@ * * http://base64.sourceforge.net/b64.c * - * with the following license: + * already with MIT license, which is retained. * * LICENCE: Copyright (c) 2001 Bob Trower, Trantor Standard Systems Inc. * @@ -33,14 +33,14 @@ * Bob Trower 08/04/01 -- Create Version 0.00.00B * * I cleaned it up quite a bit to match the (linux kernel) style of the rest - * of libwebsockets; this version is under LGPL2.1 + SLE like the rest of lws - * since he explicitly allows sublicensing, but I give the URL above so you can - * get the original with Bob's super-liberal terms directly if you prefer. + * of libwebsockets */ +#include + #include #include -#include "core/private.h" +#include "private-lib-core.h" static const char encode_orig[] = "ABCDEFGHIJKLMNOPQRSTUVWXYZ" "abcdefghijklmnopqrstuvwxyz0123456789+/"; @@ -54,9 +54,7 @@ char *out, int out_size) { unsigned char triple[3]; - int i; - int line = 0; - int done = 0; + int i, done = 0; while (in_len) { int len = 0; @@ -73,14 +71,13 @@ return -1; *out++ = encode[triple[0] >> 2]; - *out++ = encode[((triple[0] & 0x03) << 4) | - ((triple[1] & 0xf0) >> 4)]; - *out++ = (len > 1 ? encode[((triple[1] & 0x0f) << 2) | - ((triple[2] & 0xc0) >> 6)] : '='); + *out++ = encode[(((triple[0] & 0x03) << 4) & 0x30) | + (((triple[1] & 0xf0) >> 4) & 0x0f)]; + *out++ = (len > 1 ? encode[(((triple[1] & 0x0f) << 2) & 0x3c) | + (((triple[2] & 0xc0) >> 6) & 3)] : '='); *out++ = (len > 2 ? encode[triple[2] & 0x3f] : '='); done += 4; - line += 4; } if (done + 1 >= out_size) @@ -91,62 +88,62 @@ return done; } -LWS_VISIBLE int +int lws_b64_encode_string(const char *in, int in_len, char *out, int out_size) { return _lws_b64_encode_string(encode_orig, in, in_len, out, out_size); } -LWS_VISIBLE int +int lws_b64_encode_string_url(const char *in, int in_len, char *out, int out_size) { return _lws_b64_encode_string(encode_url, in, in_len, out, out_size); } -/* - * returns length of decoded string in out, or -1 if out was too small - * according to out_size - * - * Only reads up to in_len chars, otherwise if in_len is -1 on entry reads until - * the first NUL in the input. - */ -static int -_lws_b64_decode_string(const char *in, int in_len, char *out, int out_size) +void +lws_b64_decode_state_init(struct lws_b64state *state) { - int len, i, c = 0, done = 0; - unsigned char v, quad[4]; + memset(state, 0, sizeof(*state)); +} + +int +lws_b64_decode_stateful(struct lws_b64state *s, const char *in, size_t *in_len, + uint8_t *out, size_t *out_size, int final) +{ + const char *orig_in = in, *end_in = in + *in_len; + uint8_t *orig_out = out, *end_out = out + *out_size; - while (in_len && *in) { + while (in < end_in && *in && out + 4 < end_out) { - len = 0; - for (i = 0; i < 4 && in_len && *in; i++) { + for (; s->i < 4 && in < end_in && *in; s->i++) { + uint8_t v; v = 0; - c = 0; - while (in_len && *in && !v) { - c = v = *in++; - in_len--; + s->c = 0; + while (in < end_in && *in && !v) { + s->c = v = *in++; /* support the url base64 variant too */ if (v == '-') - c = v = '+'; + s->c = v = '+'; if (v == '_') - c = v = '/'; + s->c = v = '/'; v = (v < 43 || v > 122) ? 0 : decode[v - 43]; if (v) v = (v == '$') ? 0 : v - 61; } - if (c) { - len++; + if (s->c) { + s->len++; if (v) - quad[i] = v - 1; + s->quad[s->i] = v - 1; } else - quad[i] = 0; + s->quad[s->i] = 0; } - if (out_size < (done + len + 1)) - /* out buffer is too small */ - return -1; + if (s->i != 4 && !final) + continue; + + s->i = 0; /* * "The '==' sequence indicates that the last group contained @@ -154,65 +151,96 @@ * bytes." (wikipedia) */ - if ((!in_len || !*in) && c == '=') - len--; + if ((in >= end_in || !*in) && s->c == '=') + s->len--; - if (len >= 2) - *out++ = quad[0] << 2 | quad[1] >> 4; - if (len >= 3) - *out++ = quad[1] << 4 | quad[2] >> 2; - if (len >= 4) - *out++ = ((quad[2] << 6) & 0xc0) | quad[3]; + if (s->len >= 2) + *out++ = s->quad[0] << 2 | s->quad[1] >> 4; + if (s->len >= 3) + *out++ = s->quad[1] << 4 | s->quad[2] >> 2; + if (s->len >= 4) + *out++ = ((s->quad[2] << 6) & 0xc0) | s->quad[3]; - done += len - 1; + s->done += s->len - 1; + s->len = 0; } - if (done + 1 >= out_size) - return -1; - *out = '\0'; + *in_len = in - orig_in; + *out_size = out - orig_out; - return done; + return 0; } -LWS_VISIBLE int + +/* + * returns length of decoded string in out, or -1 if out was too small + * according to out_size + * + * Only reads up to in_len chars, otherwise if in_len is -1 on entry reads until + * the first NUL in the input. + */ + +static size_t +_lws_b64_decode_string(const char *in, int in_len, char *out, int out_size) +{ + struct lws_b64state state; + size_t il = (size_t)in_len, ol = out_size; + + if (in_len == -1) + il = strlen(in); + + lws_b64_decode_state_init(&state); + lws_b64_decode_stateful(&state, in, &il, (uint8_t *)out, &ol, 1); + + if (!il) + return 0; + + return ol; +} + +int lws_b64_decode_string(const char *in, char *out, int out_size) { - return _lws_b64_decode_string(in, -1, out, out_size); + return (int)_lws_b64_decode_string(in, -1, out, out_size); } -LWS_VISIBLE int +int lws_b64_decode_string_len(const char *in, int in_len, char *out, int out_size) { - return _lws_b64_decode_string(in, in_len, out, out_size); + return (int)_lws_b64_decode_string(in, in_len, out, out_size); } #if 0 +static const char * const plaintext[] = { + "any carnal pleasure.", + "any carnal pleasure", + "any carnal pleasur", + "any carnal pleasu", + "any carnal pleas", + "Admin:kloikloi" +}; +static const char * const coded[] = { + "YW55IGNhcm5hbCBwbGVhc3VyZS4=", + "YW55IGNhcm5hbCBwbGVhc3VyZQ==", + "YW55IGNhcm5hbCBwbGVhc3Vy", + "YW55IGNhcm5hbCBwbGVhc3U=", + "YW55IGNhcm5hbCBwbGVhcw==", + "QWRtaW46a2xvaWtsb2k=" +}; + int lws_b64_selftest(void) { char buf[64]; unsigned int n, r = 0; unsigned int test; + + lwsl_notice("%s\n", __func__); + /* examples from https://en.wikipedia.org/wiki/Base64 */ - static const char * const plaintext[] = { - "any carnal pleasure.", - "any carnal pleasure", - "any carnal pleasur", - "any carnal pleasu", - "any carnal pleas", - "Admin:kloikloi" - }; - static const char * const coded[] = { - "YW55IGNhcm5hbCBwbGVhc3VyZS4=", - "YW55IGNhcm5hbCBwbGVhc3VyZQ==", - "YW55IGNhcm5hbCBwbGVhc3Vy", - "YW55IGNhcm5hbCBwbGVhc3U=", - "YW55IGNhcm5hbCBwbGVhcw==", - "QWRtaW46a2xvaWtsb2k=" - }; - for (test = 0; test < sizeof plaintext / sizeof(plaintext[0]); test++) { + for (test = 0; test < (int)LWS_ARRAY_SIZE(plaintext); test++) { buf[sizeof(buf) - 1] = '\0'; n = lws_b64_encode_string(plaintext[test], @@ -226,15 +254,20 @@ buf[sizeof(buf) - 1] = '\0'; n = lws_b64_decode_string(coded[test], buf, sizeof buf); if (n != strlen(plaintext[test]) || - strcmp(buf, plaintext[test])) { + strcmp(buf, plaintext[test])) { lwsl_err("Failed lws_b64 decode selftest " - "%d result '%s' / '%s', %d / %d\n", - test, buf, plaintext[test], n, strlen(plaintext[test])); + "%d result '%s' / '%s', %d / %zu\n", + test, buf, plaintext[test], n, + strlen(plaintext[test])); + lwsl_hexdump_err(buf, n); r = -1; } } - lwsl_notice("Base 64 selftests passed\n"); + if (!r) + lwsl_notice("Base 64 selftests passed\n"); + else + lwsl_notice("Base64 selftests failed\n"); return r; } diff -Nru libwebsockets-3.2.1/lib/misc/CMakeLists.txt libwebsockets-4.1.6/lib/misc/CMakeLists.txt --- libwebsockets-3.2.1/lib/misc/CMakeLists.txt 1970-01-01 00:00:00.000000000 +0000 +++ libwebsockets-4.1.6/lib/misc/CMakeLists.txt 2020-12-01 17:40:26.000000000 +0000 @@ -0,0 +1,111 @@ +# +# libwebsockets - small server side websockets and web server implementation +# +# Copyright (C) 2010 - 2020 Andy Green +# +# Permission is hereby granted, free of charge, to any person obtaining a copy +# of this software and associated documentation files (the "Software"), to +# deal in the Software without restriction, including without limitation the +# rights to use, copy, modify, merge, publish, distribute, sublicense, and/or +# sell copies of the Software, and to permit persons to whom the Software is +# furnished to do so, subject to the following conditions: +# +# The above copyright notice and this permission notice shall be included in +# all copies or substantial portions of the Software. +# +# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING +# FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS +# IN THE SOFTWARE. +# +# The strategy is to only export to PARENT_SCOPE +# +# - changes to LIB_LIST +# - changes to SOURCES +# - includes via include_directories +# +# and keep everything else private + +include_directories(.) + +list(APPEND SOURCES + misc/base64-decode.c + misc/lws-ring.c) + +if (LWS_WITH_FTS) + list(APPEND SOURCES + misc/fts/trie.c + misc/fts/trie-fd.c) +endif() + +if (LWS_WITH_DISKCACHE) + list(APPEND SOURCES + misc/diskcache.c) +endif() + +if (LWS_WITH_STRUCT_JSON) + list(APPEND SOURCES + misc/lws-struct-lejp.c) +endif() + +if (LWS_WITH_STRUCT_SQLITE3) + list(APPEND SOURCES + misc/lws-struct-sqlite.c) +endif() + +if (LWS_WITH_FSMOUNT AND ${CMAKE_SYSTEM_NAME} STREQUAL "Linux") + list(APPEND SOURCES misc/fsmount.c) +endif() + +if (LWS_WITH_DIR) + list(APPEND SOURCES misc/dir.c) +endif() + +if (LWS_WITH_THREADPOOL AND LWS_HAVE_PTHREAD_H) + list(APPEND SOURCES misc/threadpool/threadpool.c) +endif() + +if (LWS_WITH_PEER_LIMITS) + list(APPEND SOURCES + misc/peer-limits.c) +endif() + +if (LWS_WITH_LWSAC) + list(APPEND SOURCES + misc/lwsac/lwsac.c) + if (NOT LWS_PLAT_FREERTOS) + list(APPEND SOURCES + misc/lwsac/cached-file.c) + endif() +endif() + +if (NOT LWS_WITHOUT_BUILTIN_SHA1) + list(APPEND SOURCES + misc/sha-1.c) +endif() + +if (LWS_WITH_LEJP) + list(APPEND SOURCES + misc/lejp.c) +endif() + +if (UNIX) + if (NOT LWS_HAVE_GETIFADDRS) + list(APPEND HDR_PRIVATE misc/getifaddrs.h) + list(APPEND SOURCES misc/getifaddrs.c) + endif() +endif() + +if (NOT WIN32 AND NOT LWS_WITHOUT_DAEMONIZE) + list(APPEND SOURCES + misc/daemonize.c) +endif() + +# +# Keep explicit parent scope exports at end +# + +exports_to_parent_scope() diff -Nru libwebsockets-3.2.1/lib/misc/daemonize.c libwebsockets-4.1.6/lib/misc/daemonize.c --- libwebsockets-3.2.1/lib/misc/daemonize.c 2019-12-18 14:45:31.000000000 +0000 +++ libwebsockets-4.1.6/lib/misc/daemonize.c 2020-12-01 17:40:26.000000000 +0000 @@ -7,7 +7,7 @@ * he replied it is Public Domain. Use the URL above to get the original * Public Domain version if you want it. * - * This version is LGPL2.1+SLE like the rest of libwebsockets and is + * This version is MIT like the rest of libwebsockets and is * Copyright (c)2006 - 2013 Andy Green * * @@ -26,7 +26,8 @@ #include #include -#include "core/private.h" +#include +#include "private-lib-core.h" pid_t pid_daemon; static char *lock_path; @@ -99,7 +100,7 @@ * The process context you called from has been terminated then. */ -LWS_VISIBLE int +int lws_daemonize(const char *_lock_path) { struct sigaction act; diff -Nru libwebsockets-3.2.1/lib/misc/dir.c libwebsockets-4.1.6/lib/misc/dir.c --- libwebsockets-3.2.1/lib/misc/dir.c 2019-12-18 14:45:31.000000000 +0000 +++ libwebsockets-4.1.6/lib/misc/dir.c 2020-12-01 17:40:26.000000000 +0000 @@ -1,76 +1,64 @@ /* - * Lws directory scan wrapper + * libwebsockets - small server side websockets and web server implementation * - * Copyright (C) 2019 Andy Green + * Copyright (C) 2010 - 2019 Andy Green * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation: - * version 2.1 of the License. + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to + * deal in the Software without restriction, including without limitation the + * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or + * sell copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: * - * This library is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. * - * You should have received a copy of the GNU Lesser General Public - * License along with this library; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, - * MA 02110-1301 USA + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS + * IN THE SOFTWARE. */ +#if !defined(NO_GNU_SOURCE_THIS_TIME) #define NO_GNU_SOURCE_THIS_TIME +#endif +#if !defined(_DARWIN_C_SOURCE) #define _DARWIN_C_SOURCE +#endif #include -#include "core/private.h" +#include "private-lib-core.h" #include #include -#if defined(LWS_WITH_LIBUV) && UV_VERSION_MAJOR > 0 - -int -lws_dir(const char *dirpath, void *user, lws_dir_callback_function cb) -{ - struct lws_dir_entry lde; - uv_dirent_t dent; - uv_fs_t req; - int ret = 1, ir; - uv_loop_t loop; - - ir = uv_loop_init(&loop); - if (ir) { - lwsl_err("%s: loop init failed %d\n", __func__, ir); - } - - ir = uv_fs_scandir(&loop, &req, dirpath, 0, NULL); - if (ir < 0) { - lwsl_err("Scandir on %s failed, errno %d\n", dirpath, LWS_ERRNO); - return 2; - } - - while (uv_fs_scandir_next(&req, &dent) != UV_EOF) { - lde.name = dent.name; - lde.type = (int)dent.type; - if (cb(dirpath, user, &lde)) - goto bail; - } - - ret = 0; +#include +#if defined(WIN32) +#include +#define read _read +#define open _open +#define close _close +#define write _write +#define mkdir(x,y) _mkdir(x) +#define rmdir _rmdir +#define unlink _unlink +#define HAVE_STRUCT_TIMESPEC +#if defined(pid_t) +#undef pid_t +#endif +#endif /* win32 */ -bail: - uv_fs_req_cleanup(&req); - while (uv_loop_close(&loop)) - ; +#define COMBO_SIZEOF 512 - return ret; -} +#if !defined(LWS_PLAT_FREERTOS) +#if defined(WIN32) +#include "../../win32port/dirent/dirent-win32.h" #else - -#if !defined(_WIN32) && !defined(LWS_WITH_ESP32) - #include +#endif static int filter(const struct dirent *ent) { @@ -80,12 +68,62 @@ return 1; } + +#if !defined(WIN32) +static char csep = '/'; +#else +static char csep = '\\'; +#endif + +static void +lws_dir_via_stat(char *combo, size_t l, const char *path, struct lws_dir_entry *lde) +{ + struct stat s; + + lws_strncpy(combo + l, path, COMBO_SIZEOF - l); + + lde->type = LDOT_UNKNOWN; + + if (!stat(combo, &s)) { + switch (s.st_mode & S_IFMT) { + case S_IFBLK: + lde->type = LDOT_BLOCK; + break; + case S_IFCHR: + lde->type = LDOT_CHAR; + break; + case S_IFDIR: + lde->type = LDOT_DIR; + break; + case S_IFIFO: + lde->type = LDOT_FIFO; + break; +#if !defined(WIN32) + case S_IFLNK: + lde->type = LDOT_LINK; + break; +#endif + case S_IFREG: + lde->type = LDOT_FILE; + break; + default: + break; + } + } +} + int lws_dir(const char *dirpath, void *user, lws_dir_callback_function cb) { struct lws_dir_entry lde; struct dirent **namelist; int n, i, ret = 1; + char combo[COMBO_SIZEOF]; + size_t l; + + l = lws_snprintf(combo, COMBO_SIZEOF - 2, "%s", dirpath); + combo[l++] = csep; + combo[l] = '\0'; n = scandir((char *)dirpath, &namelist, filter, alphasort); if (n < 0) { @@ -94,6 +132,7 @@ } for (i = 0; i < n; i++) { + unsigned int type = namelist[i]->d_type; if (strchr(namelist[i]->d_name, '~')) goto skip; lde.name = namelist[i]->d_name; @@ -103,62 +142,34 @@ * files are LDOT_UNKNOWN */ -#if defined(__smartos__) - struct stat s; - stat(namelist[i]->d_name, &s); - switch (s.st_mode) { - case S_IFBLK: - lde.type = LDOT_BLOCK; - break; - case S_IFCHR: - lde.type = LDOT_CHAR; - break; - case S_IFDIR: - lde.type = LDOT_DIR; - break; - case S_IFIFO: - lde.type = LDOT_FIFO; - break; - case S_IFLNK: - lde.type = LDOT_LINK; - break; - case S_IFREG: - lde.type = LDOT_FILE; - break; - default: - lde.type = LDOT_UNKNOWN; - break; - } +#if defined(__sun) + lws_dir_via_stat(combo, l, namelist[i]->d_name, &lde); #else - switch (namelist[i]->d_type) { - case DT_BLK: + /* + * XFS on Linux doesn't fill in d_type at all, always zero. + */ + + if (DT_BLK != DT_UNKNOWN && type == DT_BLK) lde.type = LDOT_BLOCK; - break; - case DT_CHR: + else if (DT_CHR != DT_UNKNOWN && type == DT_CHR) lde.type = LDOT_CHAR; - break; - case DT_DIR: + else if (DT_DIR != DT_UNKNOWN && type == DT_DIR) lde.type = LDOT_DIR; - break; - case DT_FIFO: + else if (DT_FIFO != DT_UNKNOWN && type == DT_FIFO) lde.type = LDOT_FIFO; - break; - case DT_LNK: + else if (DT_LNK != DT_UNKNOWN && type == DT_LNK) lde.type = LDOT_LINK; - break; - case DT_REG: + else if (DT_REG != DT_UNKNOWN && type == DT_REG) lde.type = LDOT_FILE; - break; - case DT_SOCK: + else if (DT_SOCK != DT_UNKNOWN && type == DT_SOCK) lde.type = LDOTT_SOCKET; - break; - default: + else { lde.type = LDOT_UNKNOWN; - break; + lws_dir_via_stat(combo, l, namelist[i]->d_name, &lde); } #endif if (cb(dirpath, user, &lde)) { - while (i++ < n) + while (++i < n) free(namelist[i]); goto bail; } @@ -174,7 +185,193 @@ return ret; } +/* + * Check filename against one globby filter + * + * We can support things like "*.rpm" + */ + +static int +lws_dir_glob_check(const char *nm, const char *filt) +{ + while (*nm) { + if (*filt == '*') { + if (!strcmp(nm, filt + 1)) + return 1; + } else { + if (*nm != *filt) + return 0; + filt++; + } + nm++; + } + + return 0; +} + +/* + * We get passed a single filter string, like "*.txt" or "mydir/\*.rpm" or so. + */ + +int +lws_dir_glob_cb(const char *dirpath, void *user, struct lws_dir_entry *lde) +{ + lws_dir_glob_t *filter = (lws_dir_glob_t*)user; + char path[384]; + + if (!strcmp(lde->name, ".") || !strcmp(lde->name, "..")) + return 0; + + if (lde->type == LDOT_DIR) + return 0; + + if (lws_dir_glob_check(lde->name, filter->filter)) { + lws_snprintf(path, sizeof(path), "%s%c%s", dirpath, csep, + lde->name); + filter->cb(filter->user, path); + } + + return 0; +} + +int +lws_dir_rm_rf_cb(const char *dirpath, void *user, struct lws_dir_entry *lde) +{ + char path[384]; + + if (!strcmp(lde->name, ".") || !strcmp(lde->name, "..")) + return 0; + + lws_snprintf(path, sizeof(path), "%s%c%s", dirpath, csep, lde->name); + + if (lde->type == LDOT_DIR) { +#if !defined(WIN32) && !defined(_WIN32) && !defined(__COVERITY__) + char dummy[8]; + /* + * hm... eg, recursive dir symlinks can show up a LDOT_DIR + * here. If it's a symlink, don't recurse into it. + * + * Notice we immediately discard dummy without looking in it. + * There is no way to get into trouble from its lack of NUL + * termination in dummy[]. We just wanted to know if it was + * a symlink at all. + * + * Hide this from Coverity since it flags any use of readlink() + * even if safe. + */ + if (readlink(path, dummy, sizeof(dummy)) < 0) +#endif + lws_dir(path, NULL, lws_dir_rm_rf_cb); + + if (rmdir(path)) + lwsl_warn("%s: rmdir %s failed %d\n", __func__, path, errno); + } else { + if (unlink(path)) { +#if defined(WIN32) + SetFileAttributesA(path, FILE_ATTRIBUTE_NORMAL); + if (unlink(path)) #else -#error "If you want lws_dir onw windows, you need libuv" + if (rmdir(path)) +#endif + lwsl_warn("%s: unlink %s failed %d (type %d)\n", + __func__, path, errno, lde->type); + } + } + + return 0; +} + + #endif + +#if defined(LWS_WITH_PLUGINS_API) + +struct lws_plugins_args { + struct lws_plugin **pplugin; + const char *_class; + const char *filter; + each_plugin_cb_t each; + void *each_user; +}; + +static int +lws_plugins_dir_cb(const char *dirpath, void *user, struct lws_dir_entry *lde) +{ + struct lws_plugins_args *pa = (struct lws_plugins_args *)user; + char path[256], base[64], *q = base; + const char *p; + + if (strlen(lde->name) < 7) + return 0; + + /* + * The actual plugin names for protocol plugins look like + * "libprotocol_lws_ssh_base.so" and for event libs + * "libwebsockets-evlib_ev.so"... to recover the base name of + * "lws_ssh_base" and "evlib_ev" we strip from the left to after the + * first _ or -, and then truncate at the first . + */ + + p = lde->name; + while (*p && *p != '_' && *p != '-') + p++; + if (!*p) + return 0; + p++; + while (*p && *p != '.' && lws_ptr_diff(q, base) < (int)sizeof(base) - 1) + *q++ = *p++; + *q = '\0'; + + /* if he's given a filter, only match if base matches it */ + if (pa->filter && strcmp(base, pa->filter)) + return 0; + + lws_snprintf(path, sizeof(path) - 1, "%s/%s", dirpath, lde->name); + lwsl_notice(" %s\n", path); + + return !lws_plat_dlopen(pa->pplugin, path, base, pa->_class, + pa->each, pa->each_user); +} + +int +lws_plugins_init(struct lws_plugin **pplugin, const char * const *d, + const char *_class, const char *filter, + each_plugin_cb_t each, void *each_user) +{ + struct lws_plugins_args pa; + + pa.pplugin = pplugin; + pa._class = _class; + pa.each = each; + pa.each_user = each_user; + pa.filter = filter; + + while (d && *d) { + lws_dir(*d, &pa, lws_plugins_dir_cb); + d++; + } + + return 0; +} + +int +lws_plugins_destroy(struct lws_plugin **pplugin, each_plugin_cb_t each, + void *each_user) +{ + struct lws_plugin *p = *pplugin, *p1; + + while (p) { + if (each) + each(p, each_user); + lws_plat_destroy_dl(p); + p1 = p->list; + p->list = NULL; + lws_free(p); + p = p1; + } + + *pplugin = NULL; + + return 0; +} #endif diff -Nru libwebsockets-3.2.1/lib/misc/diskcache.c libwebsockets-4.1.6/lib/misc/diskcache.c --- libwebsockets-3.2.1/lib/misc/diskcache.c 2019-12-18 14:45:31.000000000 +0000 +++ libwebsockets-4.1.6/lib/misc/diskcache.c 2020-12-01 17:40:26.000000000 +0000 @@ -1,28 +1,34 @@ /* - * libwebsockets - disk cache helpers + * libwebsockets - small server side websockets and web server implementation * - * Copyright (C) 2018 Andy Green + * Copyright (C) 2010 - 2019 Andy Green * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation: - * version 2.1 of the License. + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to + * deal in the Software without restriction, including without limitation the + * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or + * sell copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: * - * This library is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. * - * You should have received a copy of the GNU Lesser General Public - * License along with this library; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, - * MA 02110-1301 USA + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS + * IN THE SOFTWARE. */ +#if !defined(_GNU_SOURCE) #define _GNU_SOURCE +#endif #include -#include "core/private.h" +#include +#include "private-lib-core.h" #include #include @@ -37,6 +43,14 @@ #include #include +#if defined(__APPLE__) +#include +/* Travis OSX does not have DT_REG... */ +#if !defined(DT_REG) +#define DT_REG 8 +#endif +#endif + struct file_entry { lws_list_ptr sorted; lws_list_ptr prev; diff -Nru libwebsockets-3.2.1/lib/misc/fsmount.c libwebsockets-4.1.6/lib/misc/fsmount.c --- libwebsockets-3.2.1/lib/misc/fsmount.c 1970-01-01 00:00:00.000000000 +0000 +++ libwebsockets-4.1.6/lib/misc/fsmount.c 2020-12-01 17:40:26.000000000 +0000 @@ -0,0 +1,156 @@ +/* + * libwebsockets - small server side websockets and web server implementation + * + * Copyright (C) 2010 - 2020 Andy Green + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to + * deal in the Software without restriction, including without limitation the + * rights to use, copy, modify, merge, publish, distribute, sublicefsme, and/or + * sell copies of the Software, and to permit persofsm to whom the Software is + * furnished to do so, subject to the following conditiofsm: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portiofsm of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS + * IN THE SOFTWARE. + * + * Mount and unmount overlayfs mountpoints (linux only) + */ + +#include "private-lib-core.h" +#include + +#include + +#include +#include + +#include +#include +#include +#include + +static int +rm_rf_cb(const char *dirpath, void *user, struct lws_dir_entry *lde) +{ + char path[384]; + + if (!strcmp(lde->name, ".") || !strcmp(lde->name, "..")) + return 0; + + lws_snprintf(path, sizeof(path), "%s/%s", dirpath, lde->name); + + if (lde->type == LDOT_DIR) { + lws_dir(path, NULL, rm_rf_cb); + rmdir(path); + } else + unlink(path); + + return 0; +} + +int +lws_fsmount_mount(struct lws_fsmount *fsm) +{ + struct libmnt_context *ctx; + char opts[512], c; + int n, m; + + /* + * For robustness, there are a couple of sticky situations caused by + * previous mounts not cleaning up... 1) still mounted on the mountpoint + * and 2) junk in the session dir from the dead session. + * + * For 1), do a gratuitous umount attempts until it feels nothing to + * umount... + */ + + c = fsm->mp[0]; + while (!lws_fsmount_unmount(fsm)) + fsm->mp[0] = c; + fsm->mp[0] = c; + + /* + * ... for 2), generate the session dir basepath and destroy everything + * in it... it's less dangerous than it sounds because there are + * hardcoded unusual dir names in the base path, so it can't go wild + * even if the overlay path is empty or / + */ + + lws_snprintf(opts, sizeof(opts), "%s/overlays/%s/session", + fsm->overlay_path, fsm->ovname); + lwsl_info("%s: emptying session dir %s\n", __func__, opts); + lws_dir(opts, NULL, rm_rf_cb); + + /* + * Piece together the options for the overlay mount... + */ + + n = lws_snprintf(opts, sizeof(opts), "lowerdir="); + for (m = LWS_ARRAY_SIZE(fsm->layers) - 1; m >= 0; m--) + if (fsm->layers[m]) { + if (n != 9) + opts[n++] = ':'; + + n += lws_snprintf(&opts[n], sizeof(opts) - n, + "%s/%s/%s", fsm->layers_path, + fsm->distro, fsm->layers[m]); + } + + n += lws_snprintf(&opts[n], sizeof(opts) - n, + ",upperdir=%s/overlays/%s/session", + fsm->overlay_path, fsm->ovname); + + n += lws_snprintf(&opts[n], sizeof(opts) - n, + ",workdir=%s/overlays/%s/work", + fsm->overlay_path, fsm->ovname); + + ctx = mnt_new_context(); + if (!ctx) + return 1; + + mnt_context_set_fstype(ctx, "overlay"); + mnt_context_set_options(ctx, opts); + mnt_context_set_mflags(ctx, MS_NOATIME /* |MS_NOEXEC */); + mnt_context_set_target(ctx, fsm->mp); + mnt_context_set_source(ctx, "none"); + + lwsl_notice("%s: mount opts %s\n", __func__, opts); + puts(opts); + + m = mnt_context_mount(ctx); + lwsl_notice("%s: mountpoint %s: %d\n", __func__, fsm->mp, m); + + mnt_free_context(ctx); + + return m; +} + +int +lws_fsmount_unmount(struct lws_fsmount *fsm) +{ + struct libmnt_context *ctx; + int m; + + lwsl_notice("%s: %s\n", __func__, fsm->mp); + + ctx = mnt_new_context(); + if (!ctx) + return 1; + + mnt_context_set_target(ctx, fsm->mp); + + m = mnt_context_umount(ctx); + mnt_free_context(ctx); + + fsm->mp[0] = '\0'; + + return m; +} diff -Nru libwebsockets-3.2.1/lib/misc/fts/private.h libwebsockets-4.1.6/lib/misc/fts/private.h --- libwebsockets-3.2.1/lib/misc/fts/private.h 2019-12-18 14:45:31.000000000 +0000 +++ libwebsockets-4.1.6/lib/misc/fts/private.h 1970-01-01 00:00:00.000000000 +0000 @@ -1,23 +0,0 @@ -#include - -/* if you need > 2GB trie files */ -//typedef off_t jg2_file_offset; -typedef uint32_t jg2_file_offset; - -struct lws_fts_file { - int fd; - jg2_file_offset root, flen, filepath_table; - int max_direct_hits; - int max_completion_hits; - int filepaths; -}; - - - -#define TRIE_FILE_HDR_SIZE 20 -#define MAX_VLI 5 - -#define LWS_FTS_LINES_PER_CHUNK 200 - -int -rq32(unsigned char *b, uint32_t *d); diff -Nru libwebsockets-3.2.1/lib/misc/fts/private-lib-misc-fts.h libwebsockets-4.1.6/lib/misc/fts/private-lib-misc-fts.h --- libwebsockets-3.2.1/lib/misc/fts/private-lib-misc-fts.h 1970-01-01 00:00:00.000000000 +0000 +++ libwebsockets-4.1.6/lib/misc/fts/private-lib-misc-fts.h 2020-12-01 17:40:26.000000000 +0000 @@ -0,0 +1,23 @@ +#include + +/* if you need > 2GB trie files */ +//typedef off_t jg2_file_offset; +typedef uint32_t jg2_file_offset; + +struct lws_fts_file { + int fd; + jg2_file_offset root, flen, filepath_table; + int max_direct_hits; + int max_completion_hits; + int filepaths; +}; + + + +#define TRIE_FILE_HDR_SIZE 20 +#define MAX_VLI 5 + +#define LWS_FTS_LINES_PER_CHUNK 200 + +int +rq32(unsigned char *b, uint32_t *d); diff -Nru libwebsockets-3.2.1/lib/misc/fts/trie.c libwebsockets-4.1.6/lib/misc/fts/trie.c --- libwebsockets-3.2.1/lib/misc/fts/trie.c 2019-12-18 14:45:31.000000000 +0000 +++ libwebsockets-4.1.6/lib/misc/fts/trie.c 2020-12-01 17:40:26.000000000 +0000 @@ -1,22 +1,25 @@ -/* - * libwebsockets - trie + /* + * libwebsockets - small server side websockets and web server implementation * - * Copyright (C) 2018 Andy Green + * Copyright (C) 2010 - 2019 Andy Green * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation: - * version 2.1 of the License. - * - * This library is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with this library; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, - * MA 02110-1301 USA + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to + * deal in the Software without restriction, including without limitation the + * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or + * sell copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS + * IN THE SOFTWARE. * * The functions allow * @@ -30,8 +33,8 @@ * having to load it all in memory */ -#include "core/private.h" -#include "misc/fts/private.h" +#include "private-lib-core.h" +#include "private-lib-misc-fts.h" #include #include diff -Nru libwebsockets-3.2.1/lib/misc/fts/trie-fd.c libwebsockets-4.1.6/lib/misc/fts/trie-fd.c --- libwebsockets-3.2.1/lib/misc/fts/trie-fd.c 2019-12-18 14:45:31.000000000 +0000 +++ libwebsockets-4.1.6/lib/misc/fts/trie-fd.c 2020-12-01 17:40:26.000000000 +0000 @@ -1,26 +1,29 @@ /* - * libjsongit2 - trie file functions + * libwebsockets - small server side websockets and web server implementation * - * Copyright (C) 2018 Andy Green + * Copyright (C) 2010 - 2019 Andy Green * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation: - * version 2.1 of the License. + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to + * deal in the Software without restriction, including without limitation the + * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or + * sell copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: * - * This library is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. * - * You should have received a copy of the GNU Lesser General Public - * License along with this library; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, - * MA 02110-1301 USA + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS + * IN THE SOFTWARE. */ -#include "core/private.h" -#include "misc/fts/private.h" +#include "private-lib-core.h" +#include "private-lib-misc-fts.h" #include #include @@ -726,7 +729,7 @@ lbuf[m] = '\0'; lws_json_purify(ebuf, (const char *)lbuf, - sizeof(ebuf) - 1); + sizeof(ebuf) - 1, NULL); m = (int)strlen(ebuf); p = lwsac_use(&ftsp->results_head, m + 1, 0); diff -Nru libwebsockets-3.2.1/lib/misc/getifaddrs.c libwebsockets-4.1.6/lib/misc/getifaddrs.c --- libwebsockets-3.2.1/lib/misc/getifaddrs.c 2019-12-18 14:45:31.000000000 +0000 +++ libwebsockets-4.1.6/lib/misc/getifaddrs.c 2020-12-01 17:40:26.000000000 +0000 @@ -43,7 +43,9 @@ #include #include #include -#include "core/private.h" + +#include +#include "private-lib-core.h" #ifdef LWS_HAVE_SYS_SOCKIO_H #include diff -Nru libwebsockets-3.2.1/lib/misc/lejp.c libwebsockets-4.1.6/lib/misc/lejp.c --- libwebsockets-3.2.1/lib/misc/lejp.c 2019-12-18 14:45:31.000000000 +0000 +++ libwebsockets-4.1.6/lib/misc/lejp.c 2020-12-01 17:40:26.000000000 +0000 @@ -1,26 +1,29 @@ /* - * Lightweight Embedded JSON Parser + * libwebsockets - small server side websockets and web server implementation * - * Copyright (C) 2013-2018 Andy Green + * Copyright (C) 2010 - 2020 Andy Green * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation: - * version 2.1 of the License. - * - * This library is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with this library; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, - * MA 02110-1301 USA + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to + * deal in the Software without restriction, including without limitation the + * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or + * sell copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS + * IN THE SOFTWARE. */ #include -#include "core/private.h" +#include "private-lib-core.h" #include #include @@ -74,6 +77,7 @@ ctx->st[0].b = 0; ctx->sp = 0; ctx->ipos = 0; + ctx->outer_array = 0; ctx->path_match = 0; ctx->path_stride = 0; ctx->path[0] = '\0'; @@ -143,7 +147,8 @@ lejp_check_path_match(struct lejp_ctx *ctx) { const char *p, *q; - int n, s = sizeof(char *); + int n; + size_t s = sizeof(char *); if (ctx->path_stride) s = ctx->path_stride; @@ -225,13 +230,15 @@ * unused. */ +static const char esc_char[] = "\"\\/bfnrt"; +static const char esc_tran[] = "\"\\/\b\f\n\r\t"; +static const char tokens[] = "rue alse ull "; + int lejp_parse(struct lejp_ctx *ctx, const unsigned char *json, int len) { - unsigned char c, n, s, ret = LEJP_REJECT_UNKNOWN; - static const char esc_char[] = "\"\\/bfnrt"; - static const char esc_tran[] = "\"\\/\b\f\n\r\t"; - static const char tokens[] = "rue alse ull "; + unsigned char c, n, s; + int ret = LEJP_REJECT_UNKNOWN; if (!ctx->sp && !ctx->pst[ctx->pst_sp].ppos) ctx->pst[ctx->pst_sp].callback(ctx, LEJPCB_START); @@ -259,18 +266,37 @@ switch (s) { case LEJP_IDLE: + if (!ctx->sp && c == '[') { + /* push */ + ctx->outer_array = 1; + ctx->st[ctx->sp].s = LEJP_MP_ARRAY_END; + c = LEJP_MP_VALUE; + ctx->path[ctx->pst[ctx->pst_sp].ppos++] = '['; + ctx->path[ctx->pst[ctx->pst_sp].ppos++] = ']'; + ctx->path[ctx->pst[ctx->pst_sp].ppos] = '\0'; + if (ctx->pst[ctx->pst_sp].callback(ctx, LEJPCB_ARRAY_START)) + goto reject_callback; + ctx->i[ctx->ipos++] = 0; + if (ctx->ipos > LWS_ARRAY_SIZE(ctx->i)) { + ret = LEJP_REJECT_MP_DELIM_ISTACK; + goto reject; + } + goto add_stack_level; + } if (c != '{') { ret = LEJP_REJECT_IDLE_NO_BRACE; goto reject; } - if (ctx->pst[ctx->pst_sp].callback(ctx, LEJPCB_OBJECT_START)) { - ret = LEJP_REJECT_CALLBACK; - goto reject; - } + if (ctx->pst[ctx->pst_sp].callback(ctx, + LEJPCB_OBJECT_START)) + goto reject_callback; ctx->st[ctx->sp].s = LEJP_MEMBERS; break; case LEJP_MEMBERS: if (c == '}') { + if (ctx->sp >= 1) + goto pop_level; + ctx->st[ctx->sp].s = LEJP_IDLE; ret = LEJP_REJECT_MEMBERS_NO_CLOSE; goto reject; @@ -296,10 +322,8 @@ if (ctx->st[ctx->sp - 1].s != LEJP_MP_DELIM) { ctx->buf[ctx->npos] = '\0'; if (ctx->pst[ctx->pst_sp].callback(ctx, - LEJPCB_VAL_STR_END) < 0) { - ret = LEJP_REJECT_CALLBACK; - goto reject; - } + LEJPCB_VAL_STR_END) < 0) + goto reject_callback; } /* pop */ ctx->sp--; @@ -342,10 +366,10 @@ ctx->uni |= c - '0'; else if (c >= 'a' && c <= 'f') - ctx->uni = c - 'a' + 10; + ctx->uni |= c - 'a' + 10; else if (c >= 'A' && c <= 'F') - ctx->uni = c - 'A' + 10; + ctx->uni |= c - 'A' + 10; else { ret = LEJP_REJECT_ILLEGAL_HEX; goto reject; @@ -405,14 +429,12 @@ ctx->path[ctx->pst[ctx->pst_sp].ppos] = '\0'; lejp_check_path_match(ctx); - if (ctx->pst[ctx->pst_sp].callback(ctx, LEJPCB_PAIR_NAME)) { - ret = LEJP_REJECT_CALLBACK; - goto reject; - } + if (ctx->pst[ctx->pst_sp].callback(ctx, LEJPCB_PAIR_NAME)) + goto reject_callback; break; case LEJP_MP_VALUE: - if (c >= '0' && c <= '9') { + if (c == '-' || (c >= '0' && c <= '9')) { ctx->npos = 0; ctx->dcount = 0; ctx->f = 0; @@ -426,10 +448,9 @@ c = LEJP_MP_STRING; ctx->npos = 0; ctx->buf[0] = '\0'; - if (ctx->pst[ctx->pst_sp].callback(ctx, LEJPCB_VAL_STR_START)) { - ret = LEJP_REJECT_CALLBACK; - goto reject; - } + if (ctx->pst[ctx->pst_sp].callback(ctx, + LEJPCB_VAL_STR_START)) + goto reject_callback; goto add_stack_level; case '{': @@ -437,10 +458,9 @@ ctx->st[ctx->sp].s = LEJP_MP_COMMA_OR_END; c = LEJP_MEMBERS; lejp_check_path_match(ctx); - if (ctx->pst[ctx->pst_sp].callback(ctx, LEJPCB_OBJECT_START)) { - ret = LEJP_REJECT_CALLBACK; - goto reject; - } + if (ctx->pst[ctx->pst_sp].callback(ctx, + LEJPCB_OBJECT_START)) + goto reject_callback; ctx->path_match = 0; goto add_stack_level; @@ -451,10 +471,8 @@ ctx->path[ctx->pst[ctx->pst_sp].ppos++] = '['; ctx->path[ctx->pst[ctx->pst_sp].ppos++] = ']'; ctx->path[ctx->pst[ctx->pst_sp].ppos] = '\0'; - if (ctx->pst[ctx->pst_sp].callback(ctx, LEJPCB_ARRAY_START)) { - ret = LEJP_REJECT_CALLBACK; - goto reject; - } + if (ctx->pst[ctx->pst_sp].callback(ctx, LEJPCB_ARRAY_START)) + goto reject_callback; ctx->i[ctx->ipos++] = 0; if (ctx->ipos > LWS_ARRAY_SIZE(ctx->i)) { ret = LEJP_REJECT_MP_DELIM_ISTACK; @@ -475,7 +493,8 @@ } /* drop the path [n] bit */ if (ctx->sp) { - ctx->pst[ctx->pst_sp].ppos = ctx->st[ctx->sp - 1].p; + ctx->pst[ctx->pst_sp].ppos = + ctx->st[ctx->sp - 1].p; ctx->ipos = ctx->st[ctx->sp - 1].i; } ctx->path[ctx->pst[ctx->pst_sp].ppos] = '\0'; @@ -486,6 +505,10 @@ * smaller than the matching point */ ctx->path_match = 0; + if (ctx->outer_array && !ctx->sp) { /* ended on ] */ + n = LEJPCB_ARRAY_END; + goto completed; + } goto array_end; case 't': /* true */ @@ -555,15 +578,13 @@ ctx->buf[ctx->npos] = '\0'; if (ctx->f & LEJP_SEEN_POINT) { - if (ctx->pst[ctx->pst_sp].callback(ctx, LEJPCB_VAL_NUM_FLOAT)) { - ret = LEJP_REJECT_CALLBACK; - goto reject; - } + if (ctx->pst[ctx->pst_sp].callback(ctx, + LEJPCB_VAL_NUM_FLOAT)) + goto reject_callback; } else { - if (ctx->pst[ctx->pst_sp].callback(ctx, LEJPCB_VAL_NUM_INT)) { - ret = LEJP_REJECT_CALLBACK; - goto reject; - } + if (ctx->pst[ctx->pst_sp].callback(ctx, + LEJPCB_VAL_NUM_INT)) + goto reject_callback; } /* then this is the post-number character, loop */ @@ -591,25 +612,22 @@ case 3: ctx->buf[0] = '1'; ctx->buf[1] = '\0'; - if (ctx->pst[ctx->pst_sp].callback(ctx, LEJPCB_VAL_TRUE)) { - ret = LEJP_REJECT_CALLBACK; - goto reject; - } + if (ctx->pst[ctx->pst_sp].callback(ctx, + LEJPCB_VAL_TRUE)) + goto reject_callback; break; case 8: ctx->buf[0] = '0'; ctx->buf[1] = '\0'; - if (ctx->pst[ctx->pst_sp].callback(ctx, LEJPCB_VAL_FALSE)) { - ret = LEJP_REJECT_CALLBACK; - goto reject; - } + if (ctx->pst[ctx->pst_sp].callback(ctx, + LEJPCB_VAL_FALSE)) + goto reject_callback; break; case 12: ctx->buf[0] = '\0'; - if (ctx->pst[ctx->pst_sp].callback(ctx, LEJPCB_VAL_NULL)) { - ret = LEJP_REJECT_CALLBACK; - goto reject; - } + if (ctx->pst[ctx->pst_sp].callback(ctx, + LEJPCB_VAL_NULL)) + goto reject_callback; break; } ctx->st[ctx->sp].s = LEJP_MP_COMMA_OR_END; @@ -632,7 +650,7 @@ ctx->pst[ctx->pst_sp].ppos = ctx->st[ctx->sp - 1].p; ctx->path[ctx->pst[ctx->pst_sp].ppos] = '\0'; if (ctx->path_match && - ctx->pst[ctx->pst_sp].ppos <= ctx->path_match_len) + ctx->pst[ctx->pst_sp].ppos <= ctx->path_match_len) /* * we shrank the path to be * smaller than the matching point @@ -648,7 +666,7 @@ break; } if (c == ']') { - if (!ctx->sp) { /* JSON can't end on ] */ + if (!ctx->sp) { ret = LEJP_REJECT_MP_C_OR_E_UNDERF; goto reject; } @@ -658,66 +676,68 @@ ret = LEJP_REJECT_MP_C_OR_E_NOTARRAY; goto reject; } + /* drop the path [n] bit */ if (ctx->sp) { - ctx->pst[ctx->pst_sp].ppos = ctx->st[ctx->sp - 1].p; + ctx->pst[ctx->pst_sp].ppos = + ctx->st[ctx->sp - 1].p; ctx->ipos = ctx->st[ctx->sp - 1].i; } ctx->path[ctx->pst[ctx->pst_sp].ppos] = '\0'; if (ctx->path_match && - ctx->pst[ctx->pst_sp].ppos <= ctx->path_match_len) + ctx->pst[ctx->pst_sp].ppos <= ctx->path_match_len) /* * we shrank the path to be * smaller than the matching point */ ctx->path_match = 0; + if (ctx->outer_array && !ctx->sp) { /* ended on ] */ + n = LEJPCB_ARRAY_END; + goto completed; + } + /* do LEJP_MP_ARRAY_END processing */ goto redo_character; } - if (c == '}') { - if (!ctx->sp) { - lejp_check_path_match(ctx); - if (ctx->pst[ctx->pst_sp].callback(ctx, LEJPCB_OBJECT_END)) { - ret = LEJP_REJECT_CALLBACK; - goto reject; - } - if (ctx->pst[ctx->pst_sp].callback(ctx, LEJPCB_COMPLETE)) - goto reject; - else - /* done, return unused amount */ - return len; - } - - /* pop */ - - ctx->sp--; - if (ctx->sp) { - ctx->pst[ctx->pst_sp].ppos = - ctx->st[ctx->sp].p; - ctx->ipos = ctx->st[ctx->sp].i; - } - ctx->path[ctx->pst[ctx->pst_sp].ppos] = '\0'; - if (ctx->path_match && - ctx->pst[ctx->pst_sp].ppos <= - ctx->path_match_len) - /* - * we shrank the path to be - * smaller than the matching point - */ - ctx->path_match = 0; - + if (c != '}') { + ret = LEJP_REJECT_MP_C_OR_E_NEITHER; + goto reject; + } + if (!ctx->sp) { + n = LEJPCB_OBJECT_END; +completed: lejp_check_path_match(ctx); - if (ctx->pst[ctx->pst_sp].callback(ctx, - LEJPCB_OBJECT_END)) { - ret = LEJP_REJECT_CALLBACK; - goto reject; - } - break; + if (ctx->pst[ctx->pst_sp].callback(ctx, n) || + ctx->pst[ctx->pst_sp].callback(ctx, + LEJPCB_COMPLETE)) + goto reject_callback; + + /* done, return unused amount */ + return len; } - ret = LEJP_REJECT_MP_C_OR_E_NEITHER; - goto reject; + /* pop */ +pop_level: + ctx->sp--; + if (ctx->sp) { + ctx->pst[ctx->pst_sp].ppos = ctx->st[ctx->sp].p; + ctx->ipos = ctx->st[ctx->sp].i; + } + ctx->path[ctx->pst[ctx->pst_sp].ppos] = '\0'; + if (ctx->path_match && + ctx->pst[ctx->pst_sp].ppos <= ctx->path_match_len) + /* + * we shrank the path to be + * smaller than the matching point + */ + ctx->path_match = 0; + + lejp_check_path_match(ctx); + if (ctx->pst[ctx->pst_sp].callback(ctx, + LEJPCB_OBJECT_END)) + goto reject_callback; + break; case LEJP_MP_ARRAY_END: array_end: @@ -728,7 +748,8 @@ ctx->i[ctx->ipos - 1]++; ctx->st[ctx->sp].s = LEJP_MP_VALUE; if (ctx->sp) - ctx->pst[ctx->pst_sp].ppos = ctx->st[ctx->sp - 1].p; + ctx->pst[ctx->pst_sp].ppos = + ctx->st[ctx->sp - 1].p; ctx->path[ctx->pst[ctx->pst_sp].ppos] = '\0'; break; } @@ -749,10 +770,9 @@ /* assemble the string value into chunks */ ctx->buf[ctx->npos++] = c; if (ctx->npos == sizeof(ctx->buf) - 1) { - if (ctx->pst[ctx->pst_sp].callback(ctx, LEJPCB_VAL_STR_CHUNK)) { - ret = LEJP_REJECT_CALLBACK; - goto reject; - } + if (ctx->pst[ctx->pst_sp].callback(ctx, + LEJPCB_VAL_STR_CHUNK)) + goto reject_callback; ctx->npos = 0; } continue; @@ -794,6 +814,10 @@ return LEJP_CONTINUE; + +reject_callback: + ret = LEJP_REJECT_CALLBACK; + reject: ctx->pst[ctx->pst_sp].callback(ctx, LEJPCB_FAILED); return ret; diff -Nru libwebsockets-3.2.1/lib/misc/lwsac/cached-file.c libwebsockets-4.1.6/lib/misc/lwsac/cached-file.c --- libwebsockets-3.2.1/lib/misc/lwsac/cached-file.c 2019-12-18 14:45:31.000000000 +0000 +++ libwebsockets-4.1.6/lib/misc/lwsac/cached-file.c 2020-12-01 17:40:26.000000000 +0000 @@ -1,28 +1,31 @@ /* - * libwebsockets - lws alloc chunk live file caching + * libwebsockets - small server side websockets and web server implementation * - * Copyright (C) 2018 Andy Green + * Copyright (C) 2010 - 2019 Andy Green * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation: - * version 2.1 of the License. - * - * This library is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with this library; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, - * MA 02110-1301 USA + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to + * deal in the Software without restriction, including without limitation the + * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or + * sell copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS + * IN THE SOFTWARE. */ #if !defined(LWS_PLAT_OPTEE) && !defined(OPTEE_DEV_KIT) -#include "core/private.h" -#include "misc/lwsac/private.h" +#include "private-lib-core.h" +#include "private-lib-misc-lwsac.h" /* * Helper for caching a file in memory in a lac, but also to check at intervals @@ -68,31 +71,35 @@ #define cache_file_to_lac(c) ((struct lwsac *)((char *)c - \ sizeof(struct cached_file_info) - \ + sizeof(struct lwsac_head) - \ sizeof(struct lwsac))) void lwsac_use_cached_file_start(lwsac_cached_file_t cache) { struct lwsac *lac = cache_file_to_lac(cache); + struct lwsac_head *lachead = (struct lwsac_head *)&lac->head[1]; - lac->refcount++; - // lwsl_debug("%s: html refcount: %d\n", __func__, lac->refcount); + lachead->refcount++; + // lwsl_debug("%s: html refcount: %d\n", __func__, lachead->refcount); } void lwsac_use_cached_file_end(lwsac_cached_file_t *cache) { struct lwsac *lac; + struct lwsac_head *lachead; if (!cache || !*cache) return; lac = cache_file_to_lac(*cache); + lachead = (struct lwsac_head *)&lac->head[1]; - if (!lac->refcount) + if (!lachead->refcount) lwsl_err("%s: html refcount zero on entry\n", __func__); - if (lac->refcount && !--lac->refcount && lac->detached) { + if (lachead->refcount && !--lachead->refcount && lachead->detached) { *cache = NULL; /* not usable any more */ lwsac_free(&lac); } @@ -102,10 +109,15 @@ lwsac_use_cached_file_detach(lwsac_cached_file_t *cache) { struct lwsac *lac = cache_file_to_lac(*cache); + struct lwsac_head *lachead = NULL; - lac->detached = 1; - if (lac->refcount) - return; + if (lac) { + lachead = (struct lwsac_head *)&lac->head[1]; + + lachead->detached = 1; + if (lachead->refcount) + return; + } *cache = NULL; lwsac_free(&lac); @@ -165,7 +177,7 @@ * it... reload in a new lac and then detach the old lac. */ - all = sizeof(*info) + s.st_size + 1; + all = sizeof(*info) + s.st_size + 2; info = lwsac_use(&lac, all, all); if (!info) diff -Nru libwebsockets-3.2.1/lib/misc/lwsac/lwsac.c libwebsockets-4.1.6/lib/misc/lwsac/lwsac.c --- libwebsockets-3.2.1/lib/misc/lwsac/lwsac.c 2019-12-18 14:45:31.000000000 +0000 +++ libwebsockets-4.1.6/lib/misc/lwsac/lwsac.c 2020-12-01 17:40:26.000000000 +0000 @@ -1,26 +1,29 @@ /* - * libwebsockets - lws alloc chunk + * libwebsockets - small server side websockets and web server implementation * - * Copyright (C) 2018 Andy Green + * Copyright (C) 2010 - 2020 Andy Green * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation: - * version 2.1 of the License. + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to + * deal in the Software without restriction, including without limitation the + * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or + * sell copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: * - * This library is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. * - * You should have received a copy of the GNU Lesser General Public - * License along with this library; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, - * MA 02110-1301 USA + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS + * IN THE SOFTWARE. */ -#include "core/private.h" -#include "misc/lwsac/private.h" +#include "private-lib-core.h" +#include "private-lib-misc-lwsac.h" void lws_list_ptr_insert(lws_list_ptr *head, lws_list_ptr *add, @@ -49,9 +52,9 @@ } size_t -lwsac_sizeof(void) +lwsac_sizeof(int first) { - return sizeof(struct lwsac); + return sizeof(struct lwsac) + (first ? sizeof(struct lwsac_head) : 0); } size_t @@ -66,91 +69,193 @@ return lac->next; } -void * -lwsac_use(struct lwsac **head, size_t ensure, size_t chunk_size) +int +lwsac_extend(struct lwsac *head, int amount) { - struct lwsac *chunk; - size_t ofs, alloc; + struct lwsac_head *lachead; + struct lwsac *bf; + + assert(head); + lachead = (struct lwsac_head *)&head[1]; + + bf = lachead->curr; + assert(bf); + + if (bf->alloc_size - bf->ofs < lwsac_align(amount)) + return 1; - /* ensure there's a chunk and enough space in it for this name */ + /* memset so constant folding never sees uninitialized data */ + + memset(((uint8_t *)bf) + bf->ofs, 0, lwsac_align(amount)); + bf->ofs += lwsac_align(amount); + + return 0; +} + +static void * +_lwsac_use(struct lwsac **head, size_t ensure, size_t chunk_size, char backfill) +{ + struct lwsac_head *lachead = NULL; + size_t ofs, alloc, al, hp; + struct lwsac *bf = *head; - if (!*head || (*head)->curr->alloc_size - (*head)->curr->ofs < ensure) { + if (bf) + lachead = (struct lwsac_head *)&bf[1]; - if (!chunk_size) - alloc = LWSAC_CHUNK_SIZE + sizeof(*chunk); - else - alloc = chunk_size + sizeof(*chunk); + al = lwsac_align(ensure); + /* backfill into earlier chunks if that is allowed */ + + if (backfill) /* - * If we get asked for something outside our expectation, - * allocate to meet it + * check if anything can take it, from the start */ + while (bf) { + if (bf->alloc_size - bf->ofs >= ensure) + goto do_use; - if (ensure >= alloc - sizeof(*chunk)) - alloc = ensure + sizeof(*chunk); - - chunk = malloc(alloc); - if (!chunk) { - lwsl_err("%s: OOM trying to alloc %llud\n", __func__, - (unsigned long long)alloc); - return NULL; + bf = bf->next; } - - if (!*head) { - *head = chunk; - chunk->total_alloc_size = 0; - chunk->total_blocks = 0; + else { + /* + * If there's a current chunk, just check if he can take it + */ + if (lachead && lachead->curr) { + bf = lachead->curr; + if (bf->alloc_size - bf->ofs >= ensure) + goto do_use; } - else - (*head)->curr->next = chunk; + } + + /* nothing can currently take it... so we must allocate */ - (*head)->curr = chunk; - (*head)->curr->head = *head; + hp = sizeof(*bf); /* always need the normal header part... */ + if (!*head) + hp += sizeof(struct lwsac_head); - chunk->next = NULL; - chunk->alloc_size = alloc; - chunk->detached = 0; - chunk->refcount = 0; + if (!chunk_size) + alloc = LWSAC_CHUNK_SIZE + hp; + else + alloc = chunk_size + hp; - (*head)->total_alloc_size += alloc; - (*head)->total_blocks++; + /* + * If we get asked for something outside our expectation, + * increase the allocation to meet it + */ + + if (al >= alloc - hp) + alloc = al + hp; + + lwsl_debug("%s: alloc %d for %d\n", __func__, (int)alloc, (int)ensure); + bf = malloc(alloc); + if (!bf) { + lwsl_err("%s: OOM trying to alloc %llud\n", __func__, + (unsigned long long)alloc); + return NULL; + } + /* + * belabouring the point... ofs is aligned to the platform's + * generic struct alignment at the start then + */ + bf->ofs = sizeof(*bf); + + if (!*head) { /* - * belabouring the point... ofs is aligned to the platform's - * generic struct alignment at the start then + * We are the first, head, entry... */ - (*head)->curr->ofs = sizeof(*chunk); - } + *head = bf; + /* + * ... allocate for the special head block + */ + bf->ofs += sizeof(*lachead); + lachead = (struct lwsac_head *)&bf[1]; + memset(lachead, 0, sizeof(*lachead)); + } else + if (lachead->curr) + lachead->curr->next = bf; + + lachead->curr = bf; + bf->head = *head; + bf->next = NULL; + bf->alloc_size = alloc; + + lachead->total_alloc_size += alloc; + lachead->total_blocks++; + +do_use: + + ofs = bf->ofs; - ofs = (*head)->curr->ofs; + if (al > ensure) + /* zero down the alignment padding part */ + memset((char *)bf + ofs + ensure, 0, al - ensure); - (*head)->curr->ofs += lwsac_align(ensure); - if ((*head)->curr->ofs >= (*head)->curr->alloc_size) - (*head)->curr->ofs = (*head)->curr->alloc_size; + bf->ofs += al; + if (bf->ofs >= bf->alloc_size) + bf->ofs = bf->alloc_size; - return (char *)(*head)->curr + ofs; + return (char *)bf + ofs; } void * -lwsac_use_zero(struct lwsac **head, size_t ensure, size_t chunk_size) +lwsac_use(struct lwsac **head, size_t ensure, size_t chunk_size) { - void *p = lwsac_use(head, ensure, chunk_size); + return _lwsac_use(head, ensure, chunk_size, 0); +} - if (p) - memset(p, 0, ensure); +void * +lwsac_use_backfill(struct lwsac **head, size_t ensure, size_t chunk_size) +{ + return _lwsac_use(head, ensure, chunk_size, 1); +} - return p; +uint8_t * +lwsac_scan_extant(struct lwsac *head, uint8_t *find, size_t len, int nul) +{ + while (head) { + uint8_t *pos = (uint8_t *)&head[1], + *end = ((uint8_t *)head) + head->ofs - len; + + if (head->ofs - sizeof(*head) >= len) + while (pos < end) { + if (*pos == *find && (!nul || !pos[len]) && + pos[len - 1] == find[len - 1] && + !memcmp(pos, find, len)) + /* found the blob */ + return pos; + pos++; + } + + head = head->next; + } + + return NULL; +} + +uint64_t +lwsac_total_overhead(struct lwsac *head) +{ + uint64_t overhead = 0; + + while (head) { + overhead += (head->alloc_size - head->ofs) + sizeof(*head); + + head = head->next; + } + + return overhead; } void * -lwsac_use_zeroed(struct lwsac **head, size_t ensure, size_t chunk_size) +lwsac_use_zero(struct lwsac **head, size_t ensure, size_t chunk_size) { - void *r = lwsac_use(head, ensure, chunk_size); + void *p = lwsac_use(head, ensure, chunk_size); - if (r) - memset(r, 0, ensure); + if (p) + memset(p, 0, ensure); - return r; + return p; } void @@ -172,42 +277,62 @@ void lwsac_info(struct lwsac *head) { - if (!head) +#if _LWS_ENABLED_LOGS & LLL_DEBUG + struct lwsac_head *lachead; + + if (!head) { lwsl_debug("%s: empty\n", __func__); - else - lwsl_debug("%s: lac %p: %dKiB in %d blocks\n", __func__, head, - (int)(head->total_alloc_size >> 10), head->total_blocks); + return; + } + + lachead = (struct lwsac_head *)&head[1]; + + lwsl_debug("%s: lac %p: %dKiB in %d blocks\n", __func__, head, + (int)(lachead->total_alloc_size >> 10), lachead->total_blocks); +#endif } uint64_t lwsac_total_alloc(struct lwsac *head) { - return head->total_alloc_size; + struct lwsac_head *lachead; + + if (!head) + return 0; + + lachead = (struct lwsac_head *)&head[1]; + return lachead->total_alloc_size; } void lwsac_reference(struct lwsac *head) { - head->refcount++; + struct lwsac_head *lachead = (struct lwsac_head *)&head[1]; + + lachead->refcount++; lwsl_debug("%s: head %p: (det %d) refcount -> %d\n", - __func__, head, head->detached, head->refcount); + __func__, head, lachead->detached, lachead->refcount); } void lwsac_unreference(struct lwsac **head) { + struct lwsac_head *lachead; + if (!(*head)) return; - if (!(*head)->refcount) + lachead = (struct lwsac_head *)&(*head)[1]; + + if (!lachead->refcount) lwsl_warn("%s: refcount going below zero\n", __func__); - (*head)->refcount--; + lachead->refcount--; lwsl_debug("%s: head %p: (det %d) refcount -> %d\n", - __func__, *head, (*head)->detached, (*head)->refcount); + __func__, *head, lachead->detached, lachead->refcount); - if ((*head)->detached && !(*head)->refcount) { + if (lachead->detached && !lachead->refcount) { lwsl_debug("%s: head %p: FREED\n", __func__, *head); lwsac_free(head); } @@ -216,11 +341,18 @@ void lwsac_detach(struct lwsac **head) { - (*head)->detached = 1; - if (!(*head)->refcount) { + struct lwsac_head *lachead; + + if (!(*head)) + return; + + lachead = (struct lwsac_head *)&(*head)[1]; + + lachead->detached = 1; + if (!lachead->refcount) { lwsl_debug("%s: head %p: FREED\n", __func__, *head); lwsac_free(head); } else lwsl_debug("%s: head %p: refcount %d: Marked as detached\n", - __func__, *head, (*head)->refcount); + __func__, *head, lachead->refcount); } diff -Nru libwebsockets-3.2.1/lib/misc/lwsac/private.h libwebsockets-4.1.6/lib/misc/lwsac/private.h --- libwebsockets-3.2.1/lib/misc/lwsac/private.h 2019-12-18 14:45:31.000000000 +0000 +++ libwebsockets-4.1.6/lib/misc/lwsac/private.h 1970-01-01 00:00:00.000000000 +0000 @@ -1,52 +0,0 @@ -/* - * libwebsockets - lws alloc chunk - * - * Copyright (C) 2018 Andy Green - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation: - * version 2.1 of the License. - * - * This library is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with this library; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, - * MA 02110-1301 USA - */ - -#if !defined(LWS_PLAT_OPTEE) -#include -#endif - -/* under page size of 4096 to allow overhead */ -#define LWSAC_CHUNK_SIZE 4000 - -/* - * the chunk list members all point back to the head themselves so the list - * can be detached from the formal head and free itself when its reference - * count reaches zero. - */ - -struct lwsac { - struct lwsac *next; - struct lwsac *head; /* pointer back to the first chunk */ - struct lwsac *curr; /* applies to head chunk only */ - size_t total_alloc_size; /* applies to head chunk only */ - size_t alloc_size; - size_t ofs; /* next writeable position inside chunk */ - int refcount; /* applies to head chunk only */ - int total_blocks; /* applies to head chunk only */ - char detached; /* if our refcount gets to zero, free the chunk list */ -}; - -#if !defined(LWS_PLAT_OPTEE) -struct cached_file_info { - struct stat s; - time_t last_confirm; -}; -#endif diff -Nru libwebsockets-3.2.1/lib/misc/lwsac/private-lib-misc-lwsac.h libwebsockets-4.1.6/lib/misc/lwsac/private-lib-misc-lwsac.h --- libwebsockets-3.2.1/lib/misc/lwsac/private-lib-misc-lwsac.h 1970-01-01 00:00:00.000000000 +0000 +++ libwebsockets-4.1.6/lib/misc/lwsac/private-lib-misc-lwsac.h 2020-12-01 17:40:26.000000000 +0000 @@ -0,0 +1,70 @@ +/* + * libwebsockets - small server side websockets and web server implementation + * + * Copyright (C) 2010 - 2020 Andy Green + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to + * deal in the Software without restriction, including without limitation the + * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or + * sell copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS + * IN THE SOFTWARE. + */ + +#if !defined(__LWS_PRIVATE_LIB_MISC_LWSAC_H__) +#define __LWS_PRIVATE_LIB_MISC_LWSAC_H__ + +#if !defined(LWS_PLAT_OPTEE) +#include +#endif + +/* under page size of 4096 to allow overhead */ +#define LWSAC_CHUNK_SIZE 4000 + +/* + * the chunk list members all point back to the head themselves so the list + * can be detached from the formal head and free itself when its reference + * count reaches zero. + */ + +/* + * One of these per chunk + */ + +struct lwsac { + struct lwsac *next; + struct lwsac *head; /* pointer back to the first chunk */ + size_t alloc_size; /* alloc size of the whole chunk */ + size_t ofs; /* next writeable position inside chunk */ +}; + +/* + * One of these per lwsac, at start of first chunk + */ + +struct lwsac_head { + struct lwsac *curr; + size_t total_alloc_size; + int refcount; + int total_blocks; + char detached; /* if our refcount gets to zero, free the chunk list */ +}; + +#if !defined(LWS_PLAT_OPTEE) +struct cached_file_info { + struct stat s; + time_t last_confirm; +}; +#endif +#endif diff -Nru libwebsockets-3.2.1/lib/misc/lwsac/README.md libwebsockets-4.1.6/lib/misc/lwsac/README.md --- libwebsockets-3.2.1/lib/misc/lwsac/README.md 2019-12-18 14:45:31.000000000 +0000 +++ libwebsockets-4.1.6/lib/misc/lwsac/README.md 2020-12-01 17:40:26.000000000 +0000 @@ -90,7 +90,7 @@ like clearing up after a kids' party by gathering up a disposable tablecloth: no matter what was left on the table, it's all gone in one step. -## lws_list_ptr helpers +## `lws_list_ptr` helpers ``` /* sort may be NULL if you don't care about order */ @@ -100,7 +100,49 @@ ``` A common pattern needed with sub-allocated structs is they are on one or more -linked-list. To make that simple to do cleanly, lws_list... apis are provided +linked-list. To make that simple to do cleanly, `lws_list...` apis are provided along with a generic insertion function that can take a sort callback. These allow a struct to participate on multiple linked-lists simultaneously. +## common const string and blob folding + +In some cases the input to be stored in the lwsac may repeat the same tokens +multiple times... if the pattern is to store the string or blob in the lwsac +and then point to it, you can make use of a helper api + +``` +uint8_t * +lwsac_scan_extant(struct lwsac *head, uint8_t *find, size_t len, int nul); +``` + +This lets you check in all previous used parts of the lwsac for the same +string or blob, plus optionally a terminal NUL afterwards. If not found, +it returns `NULL` and you can copy it into the lwsac as usual. If it is +found, a pointer is returned, and you can use this directly without copying +the string or blob in again. + +## optimizations to minimize overhead + +If the lwsac will persist in the system for some time, it's desirable to reduce +the memory needed as overhead. Overhead is created + + - once per chunk... in addition to the malloc overhead, there's an lwsac + chunk header of 2 x pointers and 2 x size_t + + - at the unused part at the end that was allocated but not used + +A good strategy is to make the initial allocation reflect the minimum expected +size of the overall lwsac in one hit. Then use a chunk size that is a tradeoff +between the number of chunks that might be needed and the fact that on average, +you can expect to waste half a chunk. For example if the storage is typically +between 4K - 6K, you could allocate 4K or 4.5K for the first chunk and then fill +in using 256 or 512 byte chunks. + +You can measure the overhead in an lwsac using `lwsac_total_overhead()`. + +The lwsac apis look first in the unused part of previous chunks, if any, and +will place new allocations there preferentially if they fit. This helps for the +case lwsac was forced to allocate a new chunk because you asked for something +large, while there was actually significant free space left in the old chunk, +just not enough for that particular allocation. Subsequent lwsac use can then +"backfill" smaller things there to make best use of allocated space. diff -Nru libwebsockets-3.2.1/lib/misc/lws-ring.c libwebsockets-4.1.6/lib/misc/lws-ring.c --- libwebsockets-3.2.1/lib/misc/lws-ring.c 2019-12-18 14:45:31.000000000 +0000 +++ libwebsockets-4.1.6/lib/misc/lws-ring.c 2020-12-01 17:40:26.000000000 +0000 @@ -1,27 +1,31 @@ /* - * libwebsockets - lws-ring multi-tail abstract ringbuffer api + * libwebsockets - small server side websockets and web server implementation * - * Copyright (C) 2017 Andy Green + * Copyright (C) 2010 - 2019 Andy Green * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation: - * version 2.1 of the License. + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to + * deal in the Software without restriction, including without limitation the + * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or + * sell copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: * - * This library is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. * - * You should have received a copy of the GNU Lesser General Public - * License along with this library; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, - * MA 02110-1301 USA + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS + * IN THE SOFTWARE. */ -#include "core/private.h" +#include +#include "private-lib-core.h" -LWS_VISIBLE LWS_EXTERN struct lws_ring * +struct lws_ring * lws_ring_create(size_t element_len, size_t count, void (*destroy_element)(void *)) { @@ -46,7 +50,7 @@ return ring; } -LWS_VISIBLE LWS_EXTERN void +void lws_ring_destroy(struct lws_ring *ring) { if (ring->destroy_element) @@ -63,7 +67,7 @@ lws_free(ring); } -LWS_VISIBLE LWS_EXTERN size_t +size_t lws_ring_get_count_free_elements(struct lws_ring *ring) { int f; @@ -93,7 +97,7 @@ return f / ring->element_len; } -LWS_VISIBLE LWS_EXTERN size_t +size_t lws_ring_get_count_waiting_elements(struct lws_ring *ring, uint32_t *tail) { int f; @@ -119,7 +123,7 @@ return f / ring->element_len; } -LWS_VISIBLE LWS_EXTERN int +int lws_ring_next_linear_insert_range(struct lws_ring *ring, void **start, size_t *bytes) { @@ -144,13 +148,13 @@ return 0; } -LWS_VISIBLE LWS_EXTERN void +void lws_ring_bump_head(struct lws_ring *ring, size_t bytes) { ring->head = (ring->head + (uint32_t)bytes) % ring->buflen; } -LWS_VISIBLE LWS_EXTERN size_t +size_t lws_ring_insert(struct lws_ring *ring, const void *src, size_t max_count) { const uint8_t *osrc = src; @@ -191,7 +195,7 @@ return (((uint8_t *)src + n) - osrc) / ring->element_len; } -LWS_VISIBLE LWS_EXTERN size_t +size_t lws_ring_consume(struct lws_ring *ring, uint32_t *tail, void *dest, size_t max_count) { @@ -247,7 +251,7 @@ return (((uint8_t *)dest + n) - odest) / ring->element_len; } -LWS_VISIBLE LWS_EXTERN const void * +const void * lws_ring_get_element(struct lws_ring *ring, uint32_t *tail) { if (!tail) @@ -259,7 +263,7 @@ return ((uint8_t *)ring->buf) + *tail; } -LWS_VISIBLE LWS_EXTERN void +void lws_ring_update_oldest_tail(struct lws_ring *ring, uint32_t tail) { if (!ring->destroy_element) { @@ -274,21 +278,21 @@ } } -LWS_VISIBLE LWS_EXTERN uint32_t +uint32_t lws_ring_get_oldest_tail(struct lws_ring *ring) { return ring->oldest_tail; } -LWS_VISIBLE LWS_EXTERN void +void lws_ring_dump(struct lws_ring *ring, uint32_t *tail) { if (tail == NULL) tail = &ring->oldest_tail; lwsl_notice("ring %p: buflen %u, elem_len %u, head %u, oldest_tail %u\n" " free_elems: %u; for tail %u, waiting elements: %u\n", - ring, ring->buflen, ring->element_len, ring->head, - ring->oldest_tail, - (int)lws_ring_get_count_free_elements(ring), *tail, + ring, (int)ring->buflen, (int)ring->element_len, + (int)ring->head, (int)ring->oldest_tail, + (int)lws_ring_get_count_free_elements(ring), (int)*tail, (int)lws_ring_get_count_waiting_elements(ring, tail)); } diff -Nru libwebsockets-3.2.1/lib/misc/lws-struct-lejp.c libwebsockets-4.1.6/lib/misc/lws-struct-lejp.c --- libwebsockets-3.2.1/lib/misc/lws-struct-lejp.c 2019-12-18 14:45:31.000000000 +0000 +++ libwebsockets-4.1.6/lib/misc/lws-struct-lejp.c 2020-12-01 17:40:26.000000000 +0000 @@ -1,26 +1,29 @@ /* - * libwebsockets - lws_struct JSON serialization helpers + * libwebsockets - small server side websockets and web server implementation * - * Copyright (C) 2019 Andy Green + * Copyright (C) 2010 - 2020 Andy Green * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation: - * version 2.1 of the License. + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to + * deal in the Software without restriction, including without limitation the + * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or + * sell copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: * - * This library is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. * - * You should have received a copy of the GNU Lesser General Public - * License along with this library; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, - * MA 02110-1301 USA + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS + * IN THE SOFTWARE. */ #include -#include +#include #include @@ -29,18 +32,62 @@ { lws_struct_args_t *a = (lws_struct_args_t *)ctx->user; const lws_struct_map_t *map = a->map_st[ctx->pst_sp]; - int n = a->map_entries_st[ctx->pst_sp]; + size_t n = a->map_entries_st[ctx->pst_sp], imp = 0; lejp_callback cb = map->lejp_cb; + if (reason == LEJPCB_PAIR_NAME && strcmp(ctx->path, "schema")) { + /* + * If not "schema", the schema is implicit rather than + * explicitly given, ie, he just goes ahead and starts using + * member names that imply a particular type. For example, he + * may have an implicit type normally, and a different one for + * exceptions that just starts using "error-message" or whatever + * and we can understand that's the exception type now. + * + * Let's look into each of the maps in the top level array + * and match the first one that mentions the name he gave here, + * and bind to the associated type / create a toplevel object + * of that type. + */ + + while (n--) { + const lws_struct_map_t *child = map->child_map; + int m, child_members = (int)map->child_map_size; + + for (m = 0; m < child_members; m++) { + if (!strcmp(ctx->path, child->colname)) { + /* + * We matched on him... map is pointing + * to the right toplevel type, let's + * just pick up from there as if we + * matched the explicit schema name... + */ + ctx->path_match = 1; + imp = 1; + goto matched; + } + } + map++; + } + lwsl_notice("%s: can't match implicit schema %s\n", + __func__, ctx->path); + + return -1; + } + if (reason != LEJPCB_VAL_STR_END || ctx->path_match != 1) return 0; + /* If "schema", then look for a matching name in the map array */ + while (n--) { if (strcmp(ctx->buf, map->colname)) { map++; continue; } +matched: + a->dest = lwsac_use_zero(&a->ac, map->aux, a->ac_block_size); if (!a->dest) { lwsl_err("%s: OOT\n", __func__); @@ -48,6 +95,8 @@ return 1; } a->dest_len = map->aux; + if (!ctx->pst_sp) + a->top_schema_index = (int)(map - a->map_st[ctx->pst_sp]); if (!cb) cb = lws_struct_default_lejp_cb; @@ -57,6 +106,12 @@ a->map_st[ctx->pst_sp] = map->child_map; a->map_entries_st[ctx->pst_sp] = map->child_map_size; + // lwsl_notice("%s: child map ofs_clist %d\n", __func__, + // (int)a->map_st[ctx->pst_sp]->ofs_clist); + + if (imp) + return cb(ctx, reason); + return 0; } @@ -89,8 +144,8 @@ lws_struct_args_t *args = (lws_struct_args_t *)ctx->user; const lws_struct_map_t *map, *pmap = NULL; uint8_t *ch; + size_t n; char *u; - int n; if (reason == LEJPCB_ARRAY_END) { lejp_parser_pop(ctx); @@ -99,8 +154,9 @@ } if (reason == LEJPCB_ARRAY_START) { + if (!ctx->path_match) + lwsl_err("%s: ARRAY_START with ctx->path_match 0\n", __func__); map = &args->map_st[ctx->pst_sp][ctx->path_match - 1]; - n = args->map_entries_st[ctx->pst_sp]; if (map->type == LSMT_LIST) lws_struct_lejp_push(ctx, args, map, NULL); @@ -111,30 +167,47 @@ if (ctx->pst_sp) pmap = &args->map_st[ctx->pst_sp - 1] [ctx->pst[ctx->pst_sp - 1].path_match - 1]; - map = &args->map_st[ctx->pst_sp][ctx->path_match - 1]; - n = args->map_entries_st[ctx->pst_sp]; if (reason == LEJPCB_OBJECT_START) { - if (map->type != LSMT_CHILD_PTR) { + if (!ctx->path_match) { ctx->pst[ctx->pst_sp].user = NULL; return 0; } - pmap = map; - lws_struct_lejp_push(ctx, args, map, NULL); map = &args->map_st[ctx->pst_sp][ctx->path_match - 1]; n = args->map_entries_st[ctx->pst_sp]; + + if (map->type != LSMT_CHILD_PTR && map->type != LSMT_LIST) { + ctx->pst[ctx->pst_sp].user = NULL; + + return 0; + } + pmap = map; + + lws_struct_lejp_push(ctx, args, map, NULL); } - if (reason == LEJPCB_OBJECT_END && pmap && pmap->type == LSMT_CHILD_PTR) - lejp_parser_pop(ctx); + if (reason == LEJPCB_OBJECT_END && pmap) { + if (pmap->type == LSMT_CHILD_PTR) + lejp_parser_pop(ctx); + + if (ctx->pst_sp) + pmap = &args->map_st[ctx->pst_sp - 1] + [ctx->pst[ctx->pst_sp - 1].path_match - 1]; + } + + if (!ctx->path_match) + return 0; + + map = &args->map_st[ctx->pst_sp][ctx->path_match - 1]; + n = args->map_entries_st[ctx->pst_sp]; if (map->type == LSMT_SCHEMA) { while (n--) { - if (strcmp(map->colname, ctx->buf)) { + if (strncmp(map->colname, ctx->buf, ctx->npos)) { map++; continue; } @@ -153,7 +226,9 @@ return 0; } - lwsl_notice("%s: unknown schema\n", __func__); + lwsl_notice("%s: unknown schema %.*s, tried %d\n", __func__, + ctx->npos, ctx->buf, + (int)args->map_entries_st[ctx->pst_sp]); goto cleanup; } @@ -170,6 +245,9 @@ map = &args->map_st[ctx->pst_sp - 1][ctx->path_match - 1]; n = args->map_entries_st[ctx->pst_sp - 1]; + if (!ctx->pst_sp) + return 0; + if (pmap->type != LSMT_LIST && pmap->type != LSMT_CHILD_PTR) return 1; @@ -189,12 +267,13 @@ return 1; } - lwsl_notice("%s: created child object size %d\n", __func__, - (int)pmap->aux); + lwsl_info("%s: created '%s' object size %d\n", __func__, + pmap->colname, (int)pmap->aux); if (pmap->type == LSMT_LIST) { - list = (struct lws_dll2 *)((char *)ctx->pst[ctx->pst_sp].user + - map->ofs_clist); + list = (struct lws_dll2 *) + ((char *)ctx->pst[ctx->pst_sp].user + + pmap->ofs_clist); lws_dll2_add_tail(list, owner); } @@ -363,6 +442,7 @@ if (b > lim) b = lim; memcpy(s, ctx->buf, b); + s[b] = '\0'; } break; default: @@ -390,6 +470,10 @@ int lws_struct_json_init_parse(struct lejp_ctx *ctx, lejp_callback cb, void *user) { + /* + * By default we are looking to match on a toplevel member called + * "schema", against an LSM_SCHEMA + */ if (!cb) cb = lws_struct_schema_only_lejp_cb; lejp_construct(ctx, cb, user, schema, 1); @@ -402,7 +486,7 @@ lws_struct_serialize_t * lws_struct_json_serialize_create(const lws_struct_map_t *map, size_t map_entries, int flags, - void *ptoplevel) + const void *ptoplevel) { lws_struct_serialize_t *js = lws_zalloc(sizeof(*js), __func__); lws_struct_serialize_st_t *j; @@ -453,14 +537,14 @@ { lws_struct_serialize_st_t *j; const lws_struct_map_t *map; - size_t budget = 0, olen = len; + size_t budget = 0, olen = len, m; struct lws_dll2_owner *o; unsigned long long uli; const char *q; const void *p; char dbuf[72]; long long li; - int n; + int n, used; *written = 0; *buf = '\0'; @@ -473,6 +557,10 @@ /* early check if the entry should be elided */ switch (map->type) { + case LSMT_STRING_CHAR_ARRAY: + if (!q) + goto up; + break; case LSMT_STRING_PTR: case LSMT_CHILD_PTR: q = (char *)*(char **)q; @@ -487,6 +575,9 @@ goto up; break; + case LSMT_BLOB_PTR: + goto up; + default: break; } @@ -552,20 +643,13 @@ break; case LSMT_STRING_CHAR_ARRAY: - budget = strlen(q); - if (!js->offset) { - *buf++ = '\"'; - len--; - } - break; - case LSMT_STRING_PTR: - budget = strlen(q); if (!js->offset) { *buf++ = '\"'; len--; } break; + case LSMT_LIST: *buf++ = '['; len--; @@ -606,7 +690,7 @@ if (js->sp + 1 == LEJP_MAX_PARSING_STACK_DEPTH) return LSJS_RESULT_ERROR; - /* add a stack level tto handle parsing child members */ + /* add a stack level to handle parsing child members */ n = j->idt; j = &js->st[++js->sp]; @@ -620,6 +704,7 @@ len--; lws_struct_pretty(js, &buf, &len); j->obj = q; + continue; case LSMT_SCHEMA: @@ -628,13 +713,15 @@ len--; j = &js->st[++js->sp]; lws_struct_pretty(js, &buf, &len); - budget = lws_snprintf(dbuf, 15, "\"schema\":"); - if (js->flags & LSSERJ_FLAG_PRETTY) - dbuf[budget++] = ' '; - - budget += lws_snprintf(dbuf + budget, - sizeof(dbuf) - budget, - "\"%s\"", map->colname); + if (!(js->flags & LSSERJ_FLAG_OMIT_SCHEMA)) { + budget = lws_snprintf(dbuf, 15, "\"schema\":"); + if (js->flags & LSSERJ_FLAG_PRETTY) + dbuf[budget++] = ' '; + + budget += lws_snprintf(dbuf + budget, + sizeof(dbuf) - budget, + "\"%s\"", map->colname); + } if (js->sp != 1) @@ -646,28 +733,66 @@ j->map_entry = 0; j->obj = js->st[js->sp - 1].obj; j->dllpos = NULL; - /* we're actually at the same level */ - j->subsequent = 1; + if (!(js->flags & LSSERJ_FLAG_OMIT_SCHEMA)) + /* we're actually at the same level */ + j->subsequent = 1; j->idt = 1; break; + default: + break; } - q += js->offset; - budget -= js->remaining; + switch (map->type) { + case LSMT_STRING_CHAR_ARRAY: + case LSMT_STRING_PTR: + /* + * This is a bit tricky... we have to escape the string + * which may 6x its length depending on what the + * contents are. + * + * We offset the unescaped string starting point first + */ - if (budget > len) { - js->remaining = budget - len; - js->offset = len; - budget = len; - } else { - js->remaining = 0; - js->offset = 0; + q += js->offset; + budget = strlen(q); /* how much unescaped is left */ + + /* + * This is going to escape as much as it can fit, and + * let us know the amount of input that was consumed + * in "used". + */ + + lws_json_purify((char *)buf, q, (int)len, &used); + m = strlen((const char *)buf); + buf += m; + len -= m; + js->remaining = budget - used; + js->offset = used; + if (!js->remaining) + js->offset = 0; + + break; + default: + q += js->offset; + budget -= js->remaining; + + if (budget > len) { + js->remaining = budget - len; + js->offset = len; + budget = len; + } else { + js->remaining = 0; + js->offset = 0; + } + + memcpy(buf, q, budget); + buf += budget; + *buf = '\0'; + len -= budget; + break; } - memcpy(buf, q, budget); - buf += budget; - *buf = '\0'; - len -= budget; + switch (map->type) { case LSMT_STRING_CHAR_ARRAY: @@ -727,7 +852,7 @@ if (j->dllpos) { /* * there was another item in the array to do... let's - * move on to that nd do it + * move on to that and do it */ *buf++ = ','; len--; diff -Nru libwebsockets-3.2.1/lib/misc/lws-struct-sqlite.c libwebsockets-4.1.6/lib/misc/lws-struct-sqlite.c --- libwebsockets-3.2.1/lib/misc/lws-struct-sqlite.c 2019-12-18 14:45:31.000000000 +0000 +++ libwebsockets-4.1.6/lib/misc/lws-struct-sqlite.c 2020-12-01 17:40:26.000000000 +0000 @@ -1,26 +1,29 @@ /* - * libwebsockets - lws_struct JSON serialization helpers + * libwebsockets - small server side websockets and web server implementation * - * Copyright (C) 2019 Andy Green + * Copyright (C) 2010 - 2020 Andy Green * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation: - * version 2.1 of the License. + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to + * deal in the Software without restriction, including without limitation the + * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or + * sell copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: * - * This library is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. * - * You should have received a copy of the GNU Lesser General Public - * License along with this library; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, - * MA 02110-1301 USA + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS + * IN THE SOFTWARE. */ #include -#include +#include #include @@ -32,10 +35,10 @@ lws_struct_sq3_deser_cb(void *priv, int cols, char **cv, char **cn) { lws_struct_args_t *a = (lws_struct_args_t *)priv; + char *u = lwsac_use_zero(&a->ac, a->dest_len, a->ac_block_size); + lws_dll2_owner_t *o = (lws_dll2_owner_t *)a->cb_arg; const lws_struct_map_t *map = a->map_st[0]; int n, mems = a->map_entries_st[0]; - lws_dll2_owner_t *o = (lws_dll2_owner_t *)a->cb_arg; - char *u = lwsac_use_zero(&a->ac, a->dest_len, a->ac_block_size); long long li; size_t lim; char **pp; @@ -62,6 +65,12 @@ *pc = atoi(cv[n]); break; } + if (map->aux == sizeof(short)) { + short *ps; + ps = (short *)(u + map->ofs); + *ps = atoi(cv[n]); + break; + } if (map->aux == sizeof(int)) { int *pi; pi = (int *)(u + map->ofs); @@ -88,6 +97,12 @@ *pc = atoi(cv[n]); break; } + if (map->aux == sizeof(unsigned short)) { + unsigned short *ps; + ps = (unsigned short *)(u + map->ofs); + *ps = atoi(cv[n]); + break; + } if (map->aux == sizeof(unsigned int)) { unsigned int *pi; pi = (unsigned int *)(u + map->ofs); @@ -131,7 +146,7 @@ case LSMT_STRING_CHAR_ARRAY: s = (char *)(u + map->ofs); - lim = map->aux - 1; + lim = map->aux; lws_strncpy(s, cv[n], lim); break; @@ -162,12 +177,17 @@ */ int -lws_struct_sq3_deserialize(sqlite3 *pdb, const lws_struct_map_t *schema, - lws_dll2_owner_t *o, struct lwsac **ac, - uint64_t start, int limit) +lws_struct_sq3_deserialize(sqlite3 *pdb, const char *filter, const char *order, + const lws_struct_map_t *schema, lws_dll2_owner_t *o, + struct lwsac **ac, int start, int _limit) { - char s[150], where[32]; + int limit = _limit < 0 ? -_limit : _limit; + char s[768], results[512], where[250]; lws_struct_args_t a; + int n, m; + + if (!order) + order = "_lws_idx"; memset(&a, 0, sizeof(a)); a.cb_arg = o; /* lws_dll2_owner tracking query result objects */ @@ -178,17 +198,29 @@ lws_dll2_owner_clear(o); + /* + * Explicitly list the columns instead of use *, so we can skip blobs + */ + + m = 0; + for (n = 0; n < (int)schema->child_map_size; n++) + m += lws_snprintf(&results[m], sizeof(results) - n - 1, + "%s%c", schema->child_map[n].colname, + n + 1 == (int)schema->child_map_size ? ' ' : ','); + where[0] = '\0'; - if (start) - lws_snprintf(where, sizeof(where), " where when < %llu ", - (unsigned long long)start); - - lws_snprintf(s, sizeof(s) - 1, "select * " - "from %s %s order by created desc limit %d;", - schema->colname, where, limit); + lws_snprintf(where, sizeof(where), " where _lws_idx >= %llu %s", + (unsigned long long)start, filter ? filter : ""); + + lws_snprintf(s, sizeof(s) - 1, "select %s " + "from %s %s order by %s %slimit %d;", results, + schema->colname, where, order, + _limit < 0 ? "desc " : "", limit); + + if (sqlite3_exec(pdb, s, lws_struct_sq3_deser_cb, &a, NULL) != SQLITE_OK) { - lwsl_err("%s: fail\n", sqlite3_errmsg(pdb)); + lwsl_err("%s: %s: fail %s\n", __func__, sqlite3_errmsg(pdb), s); lwsac_free(&a.ac); return -1; } @@ -198,31 +230,261 @@ return 0; } +/* + * This takes a struct and turns it into an sqlite3 UPDATE, using the given + * schema... which has one LSM_SCHEMA_DLL2 entry wrapping the actual schema + */ + +static int +_lws_struct_sq3_ser_one(sqlite3 *pdb, const lws_struct_map_t *schema, + uint32_t idx, void *st) +{ + const lws_struct_map_t *map = schema->child_map; + int n, m, pk = 0, nentries = schema->child_map_size, nef = 0, did; + size_t sql_est = 46 + strlen(schema->colname) + 1; + /* "insert into (_lws_idx, ) values (00000001,);" ... + * plus the table name */ + uint8_t *stb = (uint8_t *)st; + const char *p; + char *sql; + + /* + * Figure out effective number of columns, exluding BLOB. + * + * The first UNSIGNED is a hidden index. Blobs are not handled by + * lws_struct except to create the column in the schema. + */ + + pk = 0; + nef = 0; + for (n = 0; n < nentries; n++) { + if (!pk && map[n].type == LSMT_UNSIGNED) { + pk = 1; + continue; + } + if (map[n].type == LSMT_BLOB_PTR) + continue; + + nef++; + } + + /* + * Figure out an estimate for the length of the populated sqlite + * command, and then malloc it up + */ + + for (n = 0; n < nentries; n++) { + sql_est += strlen(map[n].colname) + 2; + switch (map[n].type) { + case LSMT_SIGNED: + case LSMT_UNSIGNED: + case LSMT_BOOLEAN: + + switch (map[n].aux) { + case 1: + sql_est += 3 + 2; + break; + case 2: + sql_est += 5 + 2; + break; + case 4: + sql_est += 10 + 2; + break; + case 8: + sql_est += 20 + 2; + break; + } + + if (map[n].type == LSMT_SIGNED) + sql_est++; /* minus sign */ + + break; + case LSMT_STRING_CHAR_ARRAY: + sql_est += lws_sql_purify_len((const char *)st + + map[n].ofs) + 2; + break; + + case LSMT_STRING_PTR: + p = *((const char * const *)&stb[map[n].ofs]); + sql_est += (p ? lws_sql_purify_len(p) : 0) + 2; + break; + + case LSMT_BLOB_PTR: + /* we don't deal with blobs actually */ + sql_est -= strlen(map[n].colname) + 2; + break; + + default: + lwsl_err("%s: unsupported type\n", __func__); + assert(0); + break; + } + } + + sql = malloc(sql_est); + if (!sql) + return -1; + + m = lws_snprintf(sql, sql_est, "insert into %s(_lws_idx, ", + schema->colname); + + /* + * First explicit integer type is primary key autoincrement, should + * not be specified + */ + + pk = 0; + did = 0; + for (n = 0; n < nentries; n++) { + if (!pk && map[n].type == LSMT_UNSIGNED) { + pk = 1; + continue; + } + if (map[n].type == LSMT_BLOB_PTR) + continue; + + did++; + m += lws_snprintf(sql + m, sql_est - m, + did == nef ? "%s" : "%s, ", + map[n].colname); + } + + m += lws_snprintf(sql + m, sql_est - m, ") values(%u, ", idx); + + pk = 0; + did = 0; + for (n = 0; n < nentries; n++) { + uint64_t uu64; + size_t q; + + if (!pk && map[n].type == LSMT_UNSIGNED) { + pk = 1; + continue; + } + + switch (map[n].type) { + case LSMT_SIGNED: + case LSMT_UNSIGNED: + case LSMT_BOOLEAN: + + uu64 = 0; + for (q = 0; q < map[n].aux; q++) + uu64 |= ((uint64_t)stb[map[n].ofs + q] << + (q << 3)); + + if (map[n].type == LSMT_SIGNED) + m += lws_snprintf(sql + m, sql_est - m, "%lld", + (long long)(int64_t)uu64); + else + m += lws_snprintf(sql + m, sql_est - m, "%llu", + (unsigned long long)uu64); + break; + + case LSMT_STRING_CHAR_ARRAY: + sql[m++] = '\''; + lws_sql_purify(sql + m, (const char *)&stb[map[n].ofs], + sql_est - m - 4); + m += strlen(sql + m); + sql[m++] = '\''; + break; + case LSMT_STRING_PTR: + p = *((const char * const *)&stb[map[n].ofs]); + sql[m++] = '\''; + if (p) { + lws_sql_purify(sql + m, p, sql_est - m - 4); + m += strlen(sql + m); + } + sql[m++] = '\''; + break; + + case LSMT_BLOB_PTR: + continue; + + default: + lwsl_err("%s: unsupported type\n", __func__); + assert(0); + break; + } + + did++; + if (did != nef) { + if (sql_est - m < 6) + return -1; + sql[m++] = ','; + sql[m++] = ' '; + } + } + + lws_snprintf(sql + m, sql_est - m, ");"); + + n = sqlite3_exec(pdb, sql, NULL, NULL, NULL); + if (n != SQLITE_OK) { + lwsl_err("%s\n", sql); + free(sql); + lwsl_err("%s: %s: fail\n", __func__, sqlite3_errmsg(pdb)); + return -1; + } + free(sql); + + return 0; +} + +int +lws_struct_sq3_serialize(sqlite3 *pdb, const lws_struct_map_t *schema, + lws_dll2_owner_t *owner, uint32_t manual_idx) +{ + uint32_t idx = manual_idx; + + lws_start_foreach_dll(struct lws_dll2 *, p, owner->head) { + void *item = (void *)((uint8_t *)p - schema->ofs_clist); + if (_lws_struct_sq3_ser_one(pdb, schema, idx++, item)) + return 1; + + } lws_end_foreach_dll(p); + + return 0; +} + int lws_struct_sq3_create_table(sqlite3 *pdb, const lws_struct_map_t *schema) { const lws_struct_map_t *map = schema->child_map; int map_size = schema->child_map_size, subsequent = 0; - char s[2048], *p = s, *end = &s[sizeof(s) - 1], *pri = "primary key"; + char s[2048], *p = s, *end = &s[sizeof(s) - 1], + *pri = " primary key autoincrement", *use; - p += lws_snprintf(p, end - p, "create table if not exists %s (", + p += lws_snprintf(p, end - p, + "create table if not exists %s (_lws_idx integer, ", schema->colname); while (map_size--) { - if (map->type > LSMT_STRING_PTR) { + if (map->type > LSMT_STRING_PTR && map->type != LSMT_BLOB_PTR) { map++; continue; } - if (subsequent && (end - p) > 3) + if (subsequent && (end - p) > 4) { *p++ = ','; + *p++ = ' '; + } subsequent = 1; - if (map->type < LSMT_STRING_CHAR_ARRAY) - p += lws_snprintf(p, end - p, "%s integer %s", - map->colname, pri); - else - p += lws_snprintf(p, end - p, "%s varchar %s", - map->colname, pri); - pri = ""; + if (map->type == LSMT_BLOB_PTR) { + + p += lws_snprintf(p, end - p, "%s blob", map->colname); + + } else { + if (map->type < LSMT_STRING_CHAR_ARRAY) { + use = ""; + if (map->colname[0] != '_') /* _lws_idx is not primary key */ + use = pri; + p += lws_snprintf(p, end - p, "%s integer%s", + map->colname, use); + if (map->colname[0] != '_') + pri = ""; + } else + p += lws_snprintf(p, end - p, "%s varchar", + map->colname); + } + map++; } @@ -239,27 +501,34 @@ int lws_struct_sq3_open(struct lws_context *context, const char *sqlite3_path, - sqlite3 **pdb) + char create_if_missing, sqlite3 **pdb) { +#if !defined(WIN32) int uid = 0, gid = 0; +#endif if (sqlite3_open_v2(sqlite3_path, pdb, - SQLITE_OPEN_READWRITE | SQLITE_OPEN_CREATE, + SQLITE_OPEN_READWRITE | + (create_if_missing ? SQLITE_OPEN_CREATE : 0), NULL) != SQLITE_OK) { - lwsl_err("%s: Unable to open db %s: %s\n", + lwsl_info("%s: Unable to open db %s: %s\n", __func__, sqlite3_path, sqlite3_errmsg(*pdb)); return 1; } +#if !defined(WIN32) lws_get_effective_uid_gid(context, &uid, &gid); if (uid) - chown(sqlite3_path, uid, gid); + if (chown(sqlite3_path, uid, gid)) + lwsl_err("%s: failed to chown %s\n", __func__, sqlite3_path); chmod(sqlite3_path, 0600); - lwsl_notice("%s: created %s owned by %u:%u mode 0600\n", __func__, + lwsl_debug("%s: created %s owned by %u:%u mode 0600\n", __func__, sqlite3_path, (unsigned int)uid, (unsigned int)gid); - +#else + lwsl_debug("%s: created %s\n", __func__, sqlite3_path); +#endif sqlite3_extended_result_codes(*pdb, 1); return 0; @@ -268,10 +537,19 @@ int lws_struct_sq3_close(sqlite3 **pdb) { + int n; + if (!*pdb) return 0; - sqlite3_close(*pdb); + n = sqlite3_close(*pdb); + if (n != SQLITE_OK) { + /* + * trouble... + */ + lwsl_err("%s: failed to close: %d\n", __func__, n); + return 1; + } *pdb = NULL; return 0; diff -Nru libwebsockets-3.2.1/lib/misc/peer-limits.c libwebsockets-4.1.6/lib/misc/peer-limits.c --- libwebsockets-3.2.1/lib/misc/peer-limits.c 2019-12-18 14:45:31.000000000 +0000 +++ libwebsockets-4.1.6/lib/misc/peer-limits.c 2020-12-01 17:40:26.000000000 +0000 @@ -1,25 +1,29 @@ /* - * libwebsockets - peer limits tracking + * libwebsockets - small server side websockets and web server implementation * - * Copyright (C) 2010-2017 Andy Green + * Copyright (C) 2010 - 2020 Andy Green * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation: - * version 2.1 of the License. + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to + * deal in the Software without restriction, including without limitation the + * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or + * sell copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: * - * This library is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. * - * You should have received a copy of the GNU Lesser General Public - * License along with this library; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, - * MA 02110-1301 USA + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS + * IN THE SOFTWARE. */ -#include "core/private.h" +#include +#include "private-lib-core.h" /* requires context->lock */ static void @@ -56,42 +60,32 @@ lws_get_or_create_peer(struct lws_vhost *vhost, lws_sockfd_type sockfd) { struct lws_context *context = vhost->context; - socklen_t rlen = 0; - void *q; - uint8_t *q8; struct lws_peer *peer; + lws_sockaddr46 sa46; + socklen_t rlen = 0; uint32_t hash = 0; - int n, af = AF_INET; - struct sockaddr_storage addr; + uint8_t *q8; + void *q; + int n; if (vhost->options & LWS_SERVER_OPTION_UNIX_SOCK) return NULL; -#ifdef LWS_WITH_IPV6 - if (LWS_IPV6_ENABLED(vhost)) { - af = AF_INET6; - } -#endif - rlen = sizeof(addr); - if (getpeername(sockfd, (struct sockaddr*)&addr, &rlen)) + rlen = sizeof(sa46); + if (getpeername(sockfd, (struct sockaddr*)&sa46, &rlen)) /* eg, udp doesn't have to have a peer */ return NULL; #ifdef LWS_WITH_IPV6 - if (af == AF_INET) + if (sa46.sa4.sin_family == AF_INET6) { + q = &sa46.sa6.sin6_addr; + rlen = sizeof(sa46.sa6.sin6_addr); + } else #endif { - struct sockaddr_in *s = (struct sockaddr_in *)&addr; - q = &s->sin_addr; - rlen = sizeof(s->sin_addr); - } -#ifdef LWS_WITH_IPV6 - else { - struct sockaddr_in6 *s = (struct sockaddr_in6 *)&addr; - q = &s->sin6_addr; - rlen = sizeof(s->sin6_addr); + q = &sa46.sa4.sin_addr; + rlen = sizeof(sa46.sa4.sin_addr); } -#endif q8 = q; for (n = 0; n < (int)rlen; n++) @@ -103,9 +97,21 @@ lws_start_foreach_ll(struct lws_peer *, peerx, context->pl_hash_table[hash]) { - if (peerx->af == af && !memcmp(q, peerx->addr, rlen)) { - lws_context_unlock(context); /* === */ - return peerx; + if (peerx->sa46.sa4.sin_family == sa46.sa4.sin_family) { +#if defined(LWS_WITH_IPV6) + if (sa46.sa4.sin_family == AF_INET6 && + !memcmp(q, &peerx->sa46.sa6.sin6_addr, rlen)) + goto hit; +#endif + if (sa46.sa4.sin_family == AF_INET && + !memcmp(q, &peerx->sa46.sa4.sin_addr, rlen)) { +#if defined(LWS_WITH_IPV6) +hit: +#endif + lws_context_unlock(context); /* === */ + + return peerx; + } } } lws_end_foreach_ll(peerx, next); @@ -121,9 +127,8 @@ context->count_peers++; peer->next = context->pl_hash_table[hash]; peer->hash = hash; - peer->af = af; + peer->sa46 = sa46; context->pl_hash_table[hash] = peer; - memcpy(peer->addr, q, rlen); time(&peer->time_created); /* * On creation, the peer has no wsi attached, so is created on the diff -Nru libwebsockets-3.2.1/lib/misc/romfs.c libwebsockets-4.1.6/lib/misc/romfs.c --- libwebsockets-3.2.1/lib/misc/romfs.c 2019-12-18 14:45:31.000000000 +0000 +++ libwebsockets-4.1.6/lib/misc/romfs.c 2020-12-01 17:40:26.000000000 +0000 @@ -31,11 +31,14 @@ * POSSIBILITY OF SUCH DAMAGE. */ +#include #include #include #include #include "romfs.h" +#if defined(LWS_WITH_ESP32) #include "esp_spi_flash.h" +#endif #define RFS_STRING_MAX 96 @@ -46,11 +49,13 @@ static void set_cache(romfs_inode_t inode, size_t len) { +#if defined(LWS_WITH_ESP32) spi_flash_read((uint32_t)inode, cache, len); +#endif } static uint32_t -ntohl(const u32_be_t be) +untohl(const u32_be_t be) { return ((be >> 24) & 0xff) | ((be >> 16) & 0xff) << 8 | @@ -91,7 +96,7 @@ cr->magic2 != 0x2d736631) return 0; - return ntohl(cr->size); + return untohl(cr->size); } static romfs_inode_t @@ -112,7 +117,7 @@ { set_cache(i, sizeof(*i)); return (romfs_inode_t)((const uint8_t *)romfs + - ntohl(ci->dir_start)); + untohl(ci->dir_start)); } static romfs_inode_t @@ -148,16 +153,16 @@ p++; if (!*cp && (!*p || *p == '/') && - (ntohl(next_be) & 7) == RFST_HARDLINK) { + (untohl(next_be) & 7) == RFST_HARDLINK) { set_cache(i, sizeof(*i)); return (romfs_inode_t) ((const uint8_t *)romfs + - (ntohl(ci->dir_start) & ~15)); + (untohl(ci->dir_start) & ~15)); } if (!*p && !*cp) { set_cache(i, sizeof(*i)); - if ((ntohl(ci->next) & 7) == RFST_SYMLINK) { + if ((untohl(ci->next) & 7) == RFST_SYMLINK) { i = romfs_symlink(romfs, level, i); continue; } @@ -172,7 +177,7 @@ if (*p == '/' && !*cp) { set_cache(i, sizeof(*i)); - switch (ntohl(ci->next) & 7) { + switch (untohl(ci->next) & 7) { case RFST_SYMLINK: i = romfs_symlink(romfs, level, i); if (!i) @@ -198,11 +203,11 @@ } set_cache(i, sizeof(*i)); - if (!(ntohl(ci->next) & ~15)) + if (!(untohl(ci->next) & ~15)) return NULL; i = (romfs_inode_t)((const uint8_t *)romfs + - (ntohl(ci->next) & ~15)); + (untohl(ci->next) & ~15)); if (i == i_in) return NULL; } @@ -224,9 +229,9 @@ return NULL; set_cache(i, sizeof(*i)); - *len = ntohl(ci->size); + *len = untohl(ci->size); if (csum) - *csum = ntohl(ci->checksum); + *csum = untohl(ci->checksum); return (void *)skip_and_pad(i); } diff -Nru libwebsockets-3.2.1/lib/misc/sha-1.c libwebsockets-4.1.6/lib/misc/sha-1.c --- libwebsockets-3.2.1/lib/misc/sha-1.c 2019-12-18 14:45:31.000000000 +0000 +++ libwebsockets-4.1.6/lib/misc/sha-1.c 2020-12-01 17:40:26.000000000 +0000 @@ -32,7 +32,8 @@ * implemented by Jun-ichiro itojun Itoh */ -#include "core/private.h" +#include +#include "private-lib-core.h" #ifdef LWS_HAVE_SYS_TYPES_H #include @@ -281,7 +282,7 @@ * This should look and work like the libcrypto implementation */ -LWS_VISIBLE unsigned char * +unsigned char * lws_SHA1(const unsigned char *d, size_t n, unsigned char *md) { struct sha1_ctxt ctx; diff -Nru libwebsockets-3.2.1/lib/misc/threadpool/threadpool.c libwebsockets-4.1.6/lib/misc/threadpool/threadpool.c --- libwebsockets-3.2.1/lib/misc/threadpool/threadpool.c 2019-12-18 14:45:31.000000000 +0000 +++ libwebsockets-4.1.6/lib/misc/threadpool/threadpool.c 2020-12-01 17:40:26.000000000 +0000 @@ -1,28 +1,40 @@ /* - * libwebsockets - threadpool api + * libwebsockets - small server side websockets and web server implementation * - * Copyright (C) 2018 Andy Green + * Copyright (C) 2010 - 2020 Andy Green * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation: - * version 2.1 of the License. + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to + * deal in the Software without restriction, including without limitation the + * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or + * sell copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: * - * This library is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. * - * You should have received a copy of the GNU Lesser General Public - * License along with this library; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, - * MA 02110-1301 USA + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS + * IN THE SOFTWARE. */ +#if !defined(_GNU_SOURCE) #define _GNU_SOURCE +#endif + +#if defined(WIN32) +#define HAVE_STRUCT_TIMESPEC +#if defined(pid_t) +#undef pid_t +#endif +#endif #include -#include "core/private.h" +#include "private-lib-core.h" #include #include @@ -30,59 +42,61 @@ struct lws_threadpool; struct lws_threadpool_task { - struct lws_threadpool_task *task_queue_next; + struct lws_threadpool_task *task_queue_next; - struct lws_threadpool *tp; - char name[32]; + struct lws_threadpool *tp; + char name[32]; struct lws_threadpool_task_args args; - lws_usec_t created; - lws_usec_t acquired; - lws_usec_t done; - lws_usec_t entered_state; + lws_dll2_t list; + + lws_usec_t created; + lws_usec_t acquired; + lws_usec_t done; + lws_usec_t entered_state; - lws_usec_t acc_running; - lws_usec_t acc_syncing; + lws_usec_t acc_running; + lws_usec_t acc_syncing; - pthread_cond_t wake_idle; + pthread_cond_t wake_idle; enum lws_threadpool_task_status status; - int late_sync_retries; + int late_sync_retries; - char wanted_writeable_cb; - char outlive; + char wanted_writeable_cb; + char outlive; }; struct lws_pool { - struct lws_threadpool *tp; - pthread_t thread; - pthread_mutex_t lock; /* part of task wake_idle */ - struct lws_threadpool_task *task; - lws_usec_t acquired; - int worker_index; + struct lws_threadpool *tp; + pthread_t thread; + pthread_mutex_t lock; /* part of task wake_idle */ + struct lws_threadpool_task *task; + lws_usec_t acquired; + int worker_index; }; struct lws_threadpool { - pthread_mutex_t lock; /* protects all pool lists */ - pthread_cond_t wake_idle; - struct lws_pool *pool_list; + pthread_mutex_t lock; /* protects all pool lists */ + pthread_cond_t wake_idle; + struct lws_pool *pool_list; - struct lws_context *context; - struct lws_threadpool *tp_list; /* context list of threadpools */ + struct lws_context *context; + struct lws_threadpool *tp_list; /* context list of threadpools */ - struct lws_threadpool_task *task_queue_head; - struct lws_threadpool_task *task_done_head; + struct lws_threadpool_task *task_queue_head; + struct lws_threadpool_task *task_done_head; - char name[32]; + char name[32]; - int threads_in_pool; - int queue_depth; - int done_queue_depth; - int max_queue_depth; - int running_tasks; + int threads_in_pool; + int queue_depth; + int done_queue_depth; + int max_queue_depth; + int running_tasks; - unsigned int destroying:1; + unsigned int destroying:1; }; static int @@ -123,10 +137,10 @@ } if (task->acc_running) - runms = task->acc_running; + runms = (int)task->acc_running; if (task->acc_syncing) - syncms = task->acc_syncing; + syncms = (int)task->acc_syncing; if (!task->done) { buf += lws_snprintf(buf, end - buf, @@ -143,7 +157,7 @@ return; } - buf += lws_snprintf(buf, end - buf, + lws_snprintf(buf, end - buf, "task: %s, DONE state %d lived: %dms " "(queued %dms, on thread: %dms, " "ran: %d%%, synced: %d%%)", task->name, task->status, @@ -157,7 +171,8 @@ void lws_threadpool_dump(struct lws_threadpool *tp) { -#if defined(_DEBUG) +#if 0 + //defined(_DEBUG) struct lws_threadpool_task **c; char buf[160]; int n, count; @@ -226,17 +241,26 @@ task->status = status; } +static struct lws * +task_to_wsi(struct lws_threadpool_task *task) +{ +#if defined(LWS_WITH_SECURE_STREAMS) + if (task->args.ss) + return task->args.ss->wsi; +#endif + return task->args.wsi; +} + static void lws_threadpool_task_cleanup_destroy(struct lws_threadpool_task *task) { if (task->args.cleanup) - task->args.cleanup(task->args.wsi, task->args.user); + task->args.cleanup(task_to_wsi(task), task->args.user); - if (task->args.wsi) - task->args.wsi->tp_task = NULL; + lws_dll2_remove(&task->list); lwsl_thread("%s: tp %p: cleaned finished task for wsi %p\n", - __func__, task->tp, task->args.wsi); + __func__, task->tp, task_to_wsi(task)); lws_free(task); } @@ -249,25 +273,34 @@ /* remove the task from the done queue */ - c = &tp->task_done_head; + if (tp) { + c = &tp->task_done_head; - while (*c) { - if ((*c) == task) { - t = *c; - *c = t->task_queue_next; - t->task_queue_next = NULL; - tp->done_queue_depth--; + while (*c) { + if ((*c) == task) { + t = *c; + *c = t->task_queue_next; + t->task_queue_next = NULL; + tp->done_queue_depth--; - lwsl_thread("%s: tp %s: reaped task wsi %p\n", __func__, - tp->name, task->args.wsi); + lwsl_thread("%s: tp %s: reaped task wsi %p\n", __func__, + tp->name, task_to_wsi(task)); - break; + break; + } + c = &(*c)->task_queue_next; } - c = &(*c)->task_queue_next; - } - if (!t) - lwsl_err("%s: task %p not in done queue\n", __func__, task); + if (!t) { + lwsl_err("%s: task %p not in done queue\n", __func__, task); + /* + * This shouldn't occur, but in this case not really + * safe to assume there's a task to destroy + */ + return; + } + } else + lwsl_err("%s: task->tp NULL already\n", __func__); /* call the task's cleanup and delete the task itself */ @@ -302,9 +335,10 @@ if (!task) continue; - wsi = task->args.wsi; + wsi = task_to_wsi(task); if (!wsi || wsi->tsi != tsi || - !task->wanted_writeable_cb) + (!task->wanted_writeable_cb && + task->status != LWS_TP_STATUS_SYNCING)) continue; task->wanted_writeable_cb = 0; @@ -325,10 +359,11 @@ while (*c) { task = *c; - wsi = task->args.wsi; + wsi = task_to_wsi(task); if (wsi && wsi->tsi == tsi && - task->wanted_writeable_cb) { + (task->wanted_writeable_cb || + task->status == LWS_TP_STATUS_SYNCING)) { task->wanted_writeable_cb = 0; lws_memory_barrier(); @@ -367,12 +402,12 @@ pthread_mutex_lock(&pool->lock); /* ======================= pool lock */ lwsl_info("%s: %s: task %p (%s): syncing with wsi %p\n", __func__, - pool->tp->name, task, task->name, task->args.wsi); + pool->tp->name, task, task->name, task_to_wsi(task)); temp = task->status; state_transition(task, LWS_TP_STATUS_SYNCING); while (tries--) { - wsi = task->args.wsi; + wsi = task_to_wsi(task); /* * if the wsi is no longer attached to this task, there is @@ -425,7 +460,7 @@ lwsl_err("%s: %s: task %p (%s): SYNC timed out " "(associated wsi %p)\n", __func__, pool->tp->name, task, - task->name, task->args.wsi); + task->name, task_to_wsi(task)); state_transition(task, LWS_TP_STATUS_STOPPING); goto done; @@ -447,6 +482,10 @@ return 0; } +#if !defined(WIN32) +static int dummy; +#endif + static void * lws_threadpool_worker(void *d) { @@ -469,8 +508,8 @@ pthread_cond_wait(&tp->wake_idle, &tp->lock); if (tp->destroying) { - pthread_mutex_unlock(&tp->lock); /* ------ tp unlock */ - continue; + lwsl_notice("%s: bailing\n", __func__); + goto doneski; } c = &tp->task_queue_head; @@ -541,7 +580,7 @@ lws_usec_t then; int n; - if (tp->destroying || !task->args.wsi) { + if (tp->destroying || !task_to_wsi(task)) { lwsl_info("%s: stopping on wsi gone\n", __func__); state_transition(task, LWS_TP_STATUS_STOPPING); } @@ -557,7 +596,7 @@ /* if not destroying the tp, continue */ break; case LWS_TP_RETURN_SYNC: - if (!task->args.wsi) { + if (!task_to_wsi(task)) { lwsl_debug("%s: task that wants to " "outlive lost wsi asked " "to sync: bypassed\n", @@ -617,21 +656,25 @@ /* signal the associated wsi to take a fresh look at * task status */ - if (pool->task->args.wsi) { + if (task_to_wsi(pool->task)) { task->wanted_writeable_cb = 1; lws_cancel_service( - lws_get_context(pool->task->args.wsi)); + lws_get_context(task_to_wsi(pool->task))); } } +doneski: pool->task = NULL; pthread_mutex_unlock(&tp->lock); /* --------------- tp unlock */ } - /* threadpool is being destroyed */ + lwsl_notice("%s: Exiting\n", __func__); - pthread_exit(NULL); + /* threadpool is being destroyed */ +#if !defined(WIN32) + pthread_exit(&dummy); +#endif return NULL; } @@ -718,9 +761,8 @@ c = &task->task_queue_next; } - pthread_mutex_unlock(&tp->lock); /* -------------------- tpool unlock */ - pthread_cond_broadcast(&tp->wake_idle); + pthread_mutex_unlock(&tp->lock); /* -------------------- tpool unlock */ } void @@ -734,8 +776,8 @@ /* remove us from the context list of threadpools */ lws_context_lock(tp->context, __func__); - ptp = &tp->context->tp_list_head; + while (*ptp) { if (*ptp == tp) { *ptp = tp->tp_list; @@ -746,27 +788,32 @@ lws_context_unlock(tp->context); + /* + * Wake up the threadpool guys and tell them to exit + */ pthread_mutex_lock(&tp->lock); /* ======================== tpool lock */ - tp->destroying = 1; pthread_cond_broadcast(&tp->wake_idle); pthread_mutex_unlock(&tp->lock); /* -------------------- tpool unlock */ lws_threadpool_dump(tp); + lwsl_info("%s: waiting for threads to rejoin\n", __func__); +#if defined(WIN32) + Sleep(1000); +#endif + for (n = 0; n < tp->threads_in_pool; n++) { task = tp->pool_list[n].task; - /* he could be sitting waiting for SYNC */ - - if (task != NULL) - pthread_cond_broadcast(&task->wake_idle); - pthread_join(tp->pool_list[n].thread, &retval); pthread_mutex_destroy(&tp->pool_list[n].lock); } lwsl_info("%s: all threadpools exited\n", __func__); +#if defined(WIN32) + Sleep(1000); +#endif task = tp->task_done_head; while (task) { @@ -778,25 +825,21 @@ pthread_mutex_destroy(&tp->lock); + memset(tp, 0xdd, sizeof(*tp)); lws_free(tp); } /* - * we want to stop and destroy the task and related priv. The wsi may no - * longer exist. + * We want to stop and destroy the tasks and related priv. */ int -lws_threadpool_dequeue(struct lws *wsi) +lws_threadpool_dequeue_task(struct lws_threadpool_task *task) { struct lws_threadpool *tp; - struct lws_threadpool_task **c, *task; + struct lws_threadpool_task **c; int n; - task = wsi->tp_task; - if (!task) - return 0; - tp = task->tp; pthread_mutex_lock(&tp->lock); /* ======================== tpool lock */ @@ -804,8 +847,11 @@ /* disconnect from wsi, and wsi from task */ - wsi->tp_task = NULL; + lws_dll2_remove(&task->list); task->args.wsi = NULL; +#if defined(LWS_WITH_SECURE_STREAMS) + task->args.ss = NULL; +#endif goto bail; } @@ -827,7 +873,7 @@ task->done = lws_now_usecs(); lwsl_debug("%s: tp %p: removed queued task wsi %p\n", - __func__, tp, task->args.wsi); + __func__, tp, task_to_wsi(task)); break; } @@ -869,13 +915,16 @@ /* disconnect from wsi, and wsi from task */ - task->args.wsi->tp_task = NULL; + lws_dll2_remove(&task->list); task->args.wsi = NULL; +#if defined(LWS_WITH_SECURE_STREAMS) + task->args.ss = NULL; +#endif pthread_mutex_unlock(&tp->pool_list[n].lock); lwsl_debug("%s: tp %p: request stop running task " - "for wsi %p\n", __func__, tp, task->args.wsi); + "for wsi %p\n", __func__, tp, task_to_wsi(task)); break; } @@ -883,9 +932,12 @@ if (n == tp->threads_in_pool) { /* can't find it */ lwsl_notice("%s: tp %p: no task for wsi %p, decoupling\n", - __func__, tp, task->args.wsi); - task->args.wsi->tp_task = NULL; + __func__, tp, task_to_wsi(task)); + lws_dll2_remove(&task->list); task->args.wsi = NULL; +#if defined(LWS_WITH_SECURE_STREAMS) + task->args.ss = NULL; +#endif } bail: @@ -894,6 +946,21 @@ return 0; } +int +lws_threadpool_dequeue(struct lws *wsi) /* deprecated */ +{ + struct lws_threadpool_task *task; + + if (!wsi->tp_task_owner.count) + return 0; + assert(wsi->tp_task_owner.count != 1); + + task = lws_container_of(wsi->tp_task_owner.head, + struct lws_threadpool_task, list); + + return lws_threadpool_dequeue_task(task); +} + struct lws_threadpool_task * lws_threadpool_enqueue(struct lws_threadpool *tp, const struct lws_threadpool_task_args *args, @@ -905,6 +972,10 @@ if (tp->destroying) return NULL; +#if defined(LWS_WITH_SECURE_STREAMS) + assert(args->ss || args->wsi); +#endif + pthread_mutex_lock(&tp->lock); /* ======================== tpool lock */ /* @@ -951,10 +1022,15 @@ * whatever reason can clean up) */ - args->wsi->tp_task = task; +#if defined(LWS_WITH_SECURE_STREAMS) + if (args->ss) + lws_dll2_add_tail(&task->list, &args->ss->wsi->tp_task_owner); + else +#endif + lws_dll2_add_tail(&task->list, &args->wsi->tp_task_owner); lwsl_thread("%s: tp %s: enqueued task %p (%s) for wsi %p, depth %d\n", - __func__, tp->name, task, task->name, args->wsi, + __func__, tp->name, task, task->name, task_to_wsi(task), tp->queue_depth); /* alert any idle thread there's something new on the task list */ @@ -971,29 +1047,26 @@ /* this should be called from the service thread */ enum lws_threadpool_task_status -lws_threadpool_task_status_wsi(struct lws *wsi, - struct lws_threadpool_task **task, void **user) +lws_threadpool_task_status(struct lws_threadpool_task *task, void **user) { enum lws_threadpool_task_status status; - struct lws_threadpool *tp; + struct lws_threadpool *tp = task->tp; - *task = wsi->tp_task; - if (!*task) - return -1; - - tp = (*task)->tp; - *user = (*task)->args.user; - status = (*task)->status; + if (!tp) + return LWS_TP_STATUS_FINISHED; + + *user = task->args.user; + status = task->status; if (status == LWS_TP_STATUS_FINISHED || status == LWS_TP_STATUS_STOPPED) { char buf[160]; pthread_mutex_lock(&tp->lock); /* ================ tpool lock */ - __lws_threadpool_task_dump(*task, buf, sizeof(buf)); + __lws_threadpool_task_dump(task, buf, sizeof(buf)); lwsl_thread("%s: %s: service thread REAPING: %s\n", __func__, tp->name, buf); - __lws_threadpool_reap(*task); + __lws_threadpool_reap(task); lws_memory_barrier(); pthread_mutex_unlock(&tp->lock); /* ------------ tpool unlock */ } @@ -1001,13 +1074,107 @@ return status; } +enum lws_threadpool_task_status +lws_threadpool_task_status_noreap(struct lws_threadpool_task *task) +{ + return task->status; +} + +enum lws_threadpool_task_status +lws_threadpool_task_status_wsi(struct lws *wsi, + struct lws_threadpool_task **_task, void **user) +{ + struct lws_threadpool_task *task; + + if (!wsi->tp_task_owner.count) { + lwsl_notice("%s: wsi has no task, ~=FINISHED\n", __func__); + return LWS_TP_STATUS_FINISHED; + } + + assert(wsi->tp_task_owner.count == 1); /* see deprecation docs in hdr */ + + task = lws_container_of(wsi->tp_task_owner.head, + struct lws_threadpool_task, list); + + *_task = task; + + return lws_threadpool_task_status(task, user); +} + void lws_threadpool_task_sync(struct lws_threadpool_task *task, int stop) { lwsl_debug("%s\n", __func__); + if (!task) + return; if (stop) state_transition(task, LWS_TP_STATUS_STOPPING); + pthread_mutex_lock(&task->tp->lock); pthread_cond_signal(&task->wake_idle); + pthread_mutex_unlock(&task->tp->lock); } + +int +lws_threadpool_foreach_task_wsi(struct lws *wsi, void *user, + int (*cb)(struct lws_threadpool_task *task, + void *user)) +{ + struct lws_threadpool_task *task1; + + if (wsi->tp_task_owner.head == NULL) + return 0; + + task1 = lws_container_of(wsi->tp_task_owner.head, + struct lws_threadpool_task, list); + + pthread_mutex_lock(&task1->tp->lock); /* ================ tpool lock */ + + lws_start_foreach_dll_safe(struct lws_dll2 *, d, d1, + wsi->tp_task_owner.head) { + struct lws_threadpool_task *task = lws_container_of(d, + struct lws_threadpool_task, list); + + if (cb(task, user)) { + pthread_mutex_unlock(&task1->tp->lock); /* ------------ tpool unlock */ + return 1; + } + + } lws_end_foreach_dll_safe(d, d1); + + pthread_mutex_unlock(&task1->tp->lock); /* ------------ tpool unlock */ + + return 0; +} + +#if defined(LWS_WITH_SECURE_STREAMS) +int +lws_threadpool_foreach_task_ss(struct lws_ss_handle *ss, void *user, + int (*cb)(struct lws_threadpool_task *task, + void *user)) +{ + if (!ss->wsi) + return 0; + + return lws_threadpool_foreach_task_wsi(ss->wsi, user, cb); +} +#endif + +struct lws_threadpool_task * +lws_threadpool_get_task_wsi(struct lws *wsi) +{ + if (wsi->tp_task_owner.head == NULL) + return NULL; + + return lws_container_of(wsi->tp_task_owner.head, + struct lws_threadpool_task, list); +} + +#if defined(LWS_WITH_SECURE_STREAMS) +struct lws_threadpool_task * +lws_threadpool_get_task_ss(struct lws_ss_handle *ss) +{ + return lws_threadpool_get_task_wsi(ss->wsi); +} +#endif diff -Nru libwebsockets-3.2.1/lib/plat/esp32/esp32-fds.c libwebsockets-4.1.6/lib/plat/esp32/esp32-fds.c --- libwebsockets-3.2.1/lib/plat/esp32/esp32-fds.c 2019-12-18 14:45:31.000000000 +0000 +++ libwebsockets-4.1.6/lib/plat/esp32/esp32-fds.c 1970-01-01 00:00:00.000000000 +0000 @@ -1,58 +0,0 @@ -/* - * libwebsockets - lib/plat/lws-plat-esp32.c - * - * Copyright (C) 2010-2017 Andy Green - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation: - * version 2.1 of the License. - * - * This library is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with this library; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, - * MA 02110-1301 USA - */ - -#include "core/private.h" - -void -lws_plat_insert_socket_into_fds(struct lws_context *context, struct lws *wsi) -{ - struct lws_context_per_thread *pt = &context->pt[(int)wsi->tsi]; - - pt->fds[pt->fds_count++].revents = 0; -} - -void -lws_plat_delete_socket_from_fds(struct lws_context *context, - struct lws *wsi, int m) -{ - struct lws_context_per_thread *pt = &context->pt[(int)wsi->tsi]; - - pt->fds_count--; -} - -int -lws_plat_change_pollfd(struct lws_context *context, - struct lws *wsi, struct lws_pollfd *pfd) -{ - return 0; -} - -int -insert_wsi(const struct lws_context *context, struct lws *wsi) -{ - assert(context->lws_lookup[wsi->desc.sockfd - - lws_plat_socket_offset()] == 0); - - context->lws_lookup[wsi->desc.sockfd - \ - lws_plat_socket_offset()] = wsi; - - return 0; -} \ No newline at end of file diff -Nru libwebsockets-3.2.1/lib/plat/esp32/esp32-file.c libwebsockets-4.1.6/lib/plat/esp32/esp32-file.c --- libwebsockets-3.2.1/lib/plat/esp32/esp32-file.c 2019-12-18 14:45:31.000000000 +0000 +++ libwebsockets-4.1.6/lib/plat/esp32/esp32-file.c 1970-01-01 00:00:00.000000000 +0000 @@ -1,223 +0,0 @@ -/* - * libwebsockets - lib/plat/lws-plat-esp32.c - * - * Copyright (C) 2010-2017 Andy Green - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation: - * version 2.1 of the License. - * - * This library is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with this library; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, - * MA 02110-1301 USA - */ - -#include "core/private.h" - -int lws_plat_apply_FD_CLOEXEC(int n) -{ - return 0; -} - - -LWS_VISIBLE lws_fop_fd_t IRAM_ATTR -_lws_plat_file_open(const struct lws_plat_file_ops *fops, const char *filename, - const char *vpath, lws_fop_flags_t *flags) -{ - struct stat stat_buf; - lws_fop_fd_t fop_fd; - int ret = open(filename, *flags, 0664); - - if (ret < 0) - return NULL; - - if (fstat(ret, &stat_buf) < 0) - goto bail; - - fop_fd = lws_malloc(sizeof(*fop_fd), "fops open"); - if (!fop_fd) - goto bail; - - fop_fd->fops = fops; - fop_fd->fd = ret; - fop_fd->flags = *flags; - fop_fd->filesystem_priv = NULL; /* we don't use it */ - fop_fd->pos = 0; - fop_fd->len = stat_buf.st_size; - - return fop_fd; - -bail: - close(ret); - - return NULL; -} - -LWS_VISIBLE int IRAM_ATTR -_lws_plat_file_close(lws_fop_fd_t *fops_fd) -{ - int fd = (*fops_fd)->fd; - - lws_free(*fops_fd); - *fops_fd = NULL; - - return close(fd); -} - -LWS_VISIBLE lws_fileofs_t IRAM_ATTR -_lws_plat_file_seek_cur(lws_fop_fd_t fops_fd, lws_fileofs_t offset) -{ - return lseek(fops_fd->fd, offset, SEEK_CUR); -} - -LWS_VISIBLE int IRAM_ATTR -_lws_plat_file_read(lws_fop_fd_t fops_fd, lws_filepos_t *amount, - uint8_t *buf, lws_filepos_t len) -{ - long n; - - n = read(fops_fd->fd, buf, len); - if (n == -1) { - *amount = 0; - return -1; - } - fops_fd->pos += n; - *amount = n; - - return 0; -} - -LWS_VISIBLE int IRAM_ATTR -_lws_plat_file_write(lws_fop_fd_t fops_fd, lws_filepos_t *amount, - uint8_t *buf, lws_filepos_t len) -{ - long n; - - n = write(fops_fd->fd, buf, len); - if (n == -1) { - *amount = 0; - return -1; - } - fops_fd->pos += n; - *amount = n; - - return 0; -} - -#if defined(LWS_AMAZON_RTOS) -int -lws_find_string_in_file(const char *filename, const char *string, int stringlen) -{ - return 0; -} -#else -int -lws_find_string_in_file(const char *filename, const char *string, int stringlen) -{ - nvs_handle nvh; - size_t s; - int n; - char buf[64], result[64]; - const char *p = strchr(string, ':'), *q; - - if (!p) - return 0; - - q = string; - n = 0; - while (n < sizeof(buf) - 1 && q != p) - buf[n++] = *q++; - buf[n] = '\0'; - - ESP_ERROR_CHECK(nvs_open(filename, NVS_READWRITE, &nvh)); - - s = sizeof(result) - 1; - n = nvs_get_str(nvh, buf, result, &s); - nvs_close(nvh); - - if (n != ESP_OK) - return 0; - - return !strcmp(p + 1, result); -} -#endif - -#if !defined(LWS_AMAZON_RTOS) -LWS_VISIBLE int -lws_plat_write_file(const char *filename, void *buf, int len) -{ - nvs_handle nvh; - int n; - - if (nvs_open("lws-station", NVS_READWRITE, &nvh)) { - lwsl_notice("%s: failed to open nvs\n", __func__); - return -1; - } - - n = nvs_set_blob(nvh, filename, buf, len); - if (n >= 0) - nvs_commit(nvh); - - nvs_close(nvh); - - lwsl_notice("%s: wrote %s (%d)\n", __func__, filename, n); - - return n; -} - -/* we write vhostname.cert.pem and vhostname.key.pem, 0 return means OK */ - -LWS_VISIBLE int -lws_plat_write_cert(struct lws_vhost *vhost, int is_key, int fd, void *buf, - int len) -{ - const char *name = vhost->tls.alloc_cert_path; - - if (is_key) - name = vhost->tls.key_path; - - return lws_plat_write_file(name, buf, len) < 0; -} - -LWS_VISIBLE int -lws_plat_read_file(const char *filename, void *buf, int len) -{ - nvs_handle nvh; - size_t s = 0; - int n = 0; - - if (nvs_open("lws-station", NVS_READWRITE, &nvh)) { - lwsl_notice("%s: failed to open nvs\n", __func__); - return 1; - } - - ESP_ERROR_CHECK(nvs_open("lws-station", NVS_READWRITE, &nvh)); - if (nvs_get_blob(nvh, filename, NULL, &s) != ESP_OK) - goto bail; - if (s > (size_t)len) - goto bail; - - n = nvs_get_blob(nvh, filename, buf, &s); - - nvs_close(nvh); - - lwsl_notice("%s: read %s (%d)\n", __func__, filename, (int)s); - - if (n) - return -1; - - return (int)s; - -bail: - nvs_close(nvh); - - return -1; -} -#endif /* LWS_AMAZON_RTOS */ diff -Nru libwebsockets-3.2.1/lib/plat/esp32/esp32-helpers.c libwebsockets-4.1.6/lib/plat/esp32/esp32-helpers.c --- libwebsockets-3.2.1/lib/plat/esp32/esp32-helpers.c 2019-12-18 14:45:31.000000000 +0000 +++ libwebsockets-4.1.6/lib/plat/esp32/esp32-helpers.c 1970-01-01 00:00:00.000000000 +0000 @@ -1,1367 +0,0 @@ -/* - * libwebsockets - lib/plat/lws-plat-esp32.c - * - * Copyright (C) 2010-2017 Andy Green - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation: - * version 2.1 of the License. - * - * This library is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with this library; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, - * MA 02110-1301 USA - */ - -#include "core/private.h" - -#include "misc/romfs.h" -#include -#include -#include -#include -#include "soc/ledc_reg.h" -#include "driver/ledc.h" - -struct lws_esp32 lws_esp32 = { - .model = CONFIG_LWS_MODEL_NAME, - .serial = "unknown", -}; - -/* - * Group AP / Station State - */ - -enum lws_gapss { - LWS_GAPSS_INITIAL, /* just started up, init and move to - * LWS_GAPSS_SCAN */ - LWS_GAPSS_SCAN, /* - * Unconnected, scanning: AP known in one of the - * config slots -> configure it, start timeout + - * LWS_GAPSS_STAT, if no AP already up in same - * group with lower MAC, after a random period - * start up our AP (LWS_GAPSS_AP) - */ - LWS_GAPSS_AP, /* - * Trying to be the group AP... periodically do - * a scan LWS_GAPSS_AP_SCAN, faster and then - * slower - */ - LWS_GAPSS_AP_SCAN, /* - * doing a scan while trying to be the group - * AP... if we see a lower MAC being the AP for - * the same group AP, abandon being an AP and - * join that AP as a station - */ - LWS_GAPSS_STAT_GRP_AP, /* - * We have decided to join another group member - * who is being the AP, as its MAC is lower than - * ours. This is a stable state, but we still - * do periodic scans LWS_GAPSS_STAT_GRP_AP_SCAN - * and will always prefer an AP configured in a - * slot. - */ - LWS_GAPSS_STAT_GRP_AP_SCAN, - /* - * We have joined a group member who is doing - * the AP job... we want to check every now and - * then if a configured AP has appeared that we - * should better use instead. Otherwise stay in - * LWS_GAPSS_STAT_GRP_AP - */ - LWS_GAPSS_STAT, /* - * trying to connect to another non-group AP. - * If we don't get an IP within a timeout and - * retries, blacklist it and go back - */ - LWS_GAPSS_STAT_HAPPY, -}; - -static const char *gapss_str[] = { - "LWS_GAPSS_INITIAL", - "LWS_GAPSS_SCAN", - "LWS_GAPSS_AP", - "LWS_GAPSS_AP_SCAN", - "LWS_GAPSS_STAT_GRP_AP", - "LWS_GAPSS_STAT_GRP_AP_SCAN", - "LWS_GAPSS_STAT", - "LWS_GAPSS_STAT_HAPPY", -}; - -static romfs_t lws_esp32_romfs; -static TimerHandle_t leds_timer, scan_timer, debounce_timer, association_timer -#if !defined(CONFIG_LWS_IS_FACTORY_APPLICATION) -, mdns_timer -#endif -; -static enum lws_gapss gapss = LWS_GAPSS_INITIAL; -#if !defined(CONFIG_LWS_IS_FACTORY_APPLICATION) -static mdns_result_t *mdns_results_head; -#endif - -#define GPIO_SW 14 - -struct esp32_file { - const struct inode *i; -}; - -static void lws_gapss_to(enum lws_gapss to) -{ - lwsl_notice("gapss from %s to %s\n", gapss_str[gapss], gapss_str[to]); - gapss = to; -} - -uint32_t lws_esp32_get_reboot_type(void) -{ - uint32_t *p = (uint32_t *)LWS_MAGIC_REBOOT_TYPE_ADS, val = *p; - nvs_handle nvh; - size_t s = 0; - int n = 0; - - ESP_ERROR_CHECK(nvs_open("lws-station", NVS_READWRITE, &nvh)); - if (nvs_get_blob(nvh, "ssl-pub.pem", NULL, &s) == ESP_OK) - n = 1; - if (nvs_get_blob(nvh, "ssl-pri.pem", NULL, &s) == ESP_OK) - n |= 2; - nvs_close(nvh); - - /* - * in the case the SSL certs are not there, don't require - * the button to be down to access all features. - */ - if (n != 3) - val = LWS_MAGIC_REBOOT_TYPE_FORCED_FACTORY_BUTTON; - - return val; -} - -static void render_ip(char *dest, int len, uint8_t *ip) -{ - snprintf(dest, len, "%u.%u.%u.%u", ip[0], ip[1], ip[2], ip[3]); -} - -void lws_esp32_restart_guided(uint32_t type) -{ - uint32_t *p_force_factory_magic = (uint32_t *)LWS_MAGIC_REBOOT_TYPE_ADS; - - lwsl_notice("%s: %x\n", __func__, type); - *p_force_factory_magic = type; - - esp_restart(); -} - -/* - * esp-idf goes crazy with zero length str nvs. Use this as a workaround - * to delete the key in that case. - */ - -esp_err_t lws_nvs_set_str(nvs_handle handle, const char* key, const char* value) -{ - if (*value) - return nvs_set_str(handle, key, value); - - return nvs_erase_key(handle, key); -} - -static wifi_scan_config_t scan_config = { - .ssid = 0, - .bssid = 0, - .channel = 0, - .show_hidden = true -}; - -static char scan_ongoing = 0, scan_timer_exists = 0; -static int try_slot = -1; - -static wifi_config_t config = { - .ap = { - .channel = 6, - .authmode = WIFI_AUTH_OPEN, - .max_connection = 1, - } }, sta_config = { - .sta = { - .bssid_set = 0, - } }; - -static void lws_esp32_scan_timer_cb(TimerHandle_t th) -{ - int n; - - lwsl_notice("%s\n", __func__); - scan_ongoing = 0; - n = esp_wifi_scan_start(&scan_config, false); - if (n != ESP_OK) - lwsl_err("scan start failed %d\n", n); -} - -static void lws_esp32_assoc_timer_cb(TimerHandle_t th) -{ - int n; - - xTimerStop(association_timer, 0); - - if (gapss == LWS_GAPSS_STAT_HAPPY) { - lwsl_debug("%s: saw we were happy\n", __func__); - - return; - } - - lwsl_notice("%s: forcing rescan\n", __func__); - - lws_gapss_to(LWS_GAPSS_SCAN); - scan_ongoing = 0; - n = esp_wifi_scan_start(&scan_config, false); - if (n != ESP_OK) - lwsl_err("scan start failed %d\n", n); -} - - -#if !defined(CONFIG_LWS_IS_FACTORY_APPLICATION) - -void __attribute__(( weak )) -lws_group_member_event(int e, void *p) -{ -} - -void __attribute__(( weak )) -lws_get_iframe_size(int *w, int *h) -{ - *w = 320; - *h = 160; -} - -void lws_group_member_event_call(int e, void *p) -{ - lws_group_member_event(e, p); -} - -static int -get_txt_param(const mdns_result_t *mr, const char *param, char *result, int len) -{ - const char *p; - - *result = '\0'; - - p = strstr(mr->txt->key, param); - if (!p) { - *result = '\0'; - return 1; - } - - lws_strncpy(result, mr->txt->value, len); - - return 0; -} - -static void lws_esp32_mdns_timer_cb(TimerHandle_t th) -{ - uint64_t now = lws_now_usecs(); - struct lws_group_member *p, **p1; - const mdns_result_t *r = mdns_results_head; - - while (r) { - char ch = 0, group[16]; - - get_txt_param(r, "group", group, sizeof(group)); - if (strcmp(group, lws_esp32.group)) /* not our group */ { - lwsl_notice("group %s vs %s %s\n", - group, lws_esp32.group, r->txt->value); - continue; - } - - p = lws_esp32.first; - while (p) { - if (strcmp(r->hostname, p->host)) - goto next; - if (memcmp(&r->addr, &p->addr, sizeof(r->addr))) - goto next; - - p->last_seen = now; - break; -next: - p = p->next; - } - if (!p) { /* did not find */ - char temp[8]; - - p = lws_malloc(sizeof(*p), "group"); - if (!p) - continue; - lws_strncpy(p->host, r->hostname, sizeof(p->host)); - - get_txt_param(r, "model", p->model, sizeof(p->model)); - get_txt_param(r, "role", p->role, sizeof(p->role)); - get_txt_param(r, "mac", p->mac, sizeof(p->mac)); - get_txt_param(r, "width", temp, sizeof(temp)); - p->width = atoi(temp); - get_txt_param(r, "height", temp, sizeof(temp)); - p->height = atoi(temp); - - memcpy(&p->addr, &r->addr, sizeof(p->addr)); -// memcpy(&p->addrv6, &r->addrv6, sizeof(p->addrv6)); - p->last_seen = now; - p->flags = 0; - p->next = lws_esp32.first; - lws_esp32.first = p; - lws_esp32.extant_group_members++; - - lws_group_member_event_call(LWS_SYSTEM_GROUP_MEMBER_ADD, p); - } else { - if (memcmp(&p->addr, &r->addr, sizeof(p->addr))) { - memcpy(&p->addr, &r->addr, sizeof(p->addr)); - ch = 1; - } -/* if (memcmp(&p->addrv6, &r->addrv6, sizeof(p->addrv6))) { - memcpy(&p->addrv6, &r->addrv6, sizeof(p->addrv6)); - ch = 1; - } */ - if (ch) - lws_group_member_event_call(LWS_SYSTEM_GROUP_MEMBER_CHANGE, p); - } - } - - mdns_query_results_free(mdns_results_head); - - /* garbage-collect group members not seen for too long */ - p1 = &lws_esp32.first; - while (*p1) { - p = *p1; - if (!(p->flags & LWS_GROUP_FLAG_SELF) && - now - p->last_seen > 60000000) { - lws_esp32.extant_group_members--; - *p1 = p->next; - - lws_group_member_event_call(LWS_SYSTEM_GROUP_MEMBER_REMOVE, p); - lws_free(p); - continue; - } - p1 = &(*p1)->next; - } - - mdns_query_txt(lws_esp32.group, "_lwsgrmem", "_tcp", 0, - &mdns_results_head); - xTimerStart(mdns_timer, 0); -} -#endif - -void __attribute__(( weak )) -lws_esp32_button(int down) -{ -} - -void IRAM_ATTR -gpio_irq(void *arg) -{ - gpio_set_intr_type(GPIO_SW, GPIO_INTR_DISABLE); - xTimerStart(debounce_timer, 0); -} - -static void lws_esp32_debounce_timer_cb(TimerHandle_t th) -{ - if (lws_esp32.button_is_down) - gpio_set_intr_type(GPIO_SW, GPIO_INTR_POSEDGE); - else - gpio_set_intr_type(GPIO_SW, GPIO_INTR_NEGEDGE); - - lws_esp32.button_is_down = gpio_get_level(GPIO_SW); - - lws_esp32_button(lws_esp32.button_is_down); -} - - -static int -start_scan() -{ - /* if no APs configured, no point... */ - - if (!lws_esp32.ssid[0][0] && - !lws_esp32.ssid[1][0] && - !lws_esp32.ssid[2][0] && - !lws_esp32.ssid[3][0]) - return 0; - - if (scan_timer_exists && !scan_ongoing) { - // lwsl_notice("Starting scan timer...\n"); - scan_ongoing = 1; - xTimerStart(scan_timer, 0); - } - - return 0; -} - - - -static void -end_scan() -{ - wifi_ap_record_t ap_records[10]; - uint16_t count_ap_records; - int n, m; - - count_ap_records = LWS_ARRAY_SIZE(ap_records); - if (esp_wifi_scan_get_ap_records(&count_ap_records, ap_records)) { - lwsl_err("%s: failed\n", __func__); - return; - } - - if (!count_ap_records) - goto passthru; - - if (gapss != LWS_GAPSS_SCAN) { - lwsl_info("ignoring scan as gapss %s\n", gapss_str[gapss]); - goto passthru; - } - - /* no point if no APs set up */ - if (!lws_esp32.ssid[0][0] && - !lws_esp32.ssid[1][0] && - !lws_esp32.ssid[2][0] && - !lws_esp32.ssid[3][0]) - goto passthru; - - lwsl_info("checking %d scan records\n", count_ap_records); - - for (n = 0; n < 4; n++) { - - if (!lws_esp32.ssid[(n + try_slot + 1) & 3][0]) - continue; - - lwsl_debug("looking for %s\n", - lws_esp32.ssid[(n + try_slot + 1) & 3]); - - /* this ssid appears in scan results? */ - - for (m = 0; m < count_ap_records; m++) { - // lwsl_notice(" %s\n", ap_records[m].ssid); - if (!strcmp((char *)ap_records[m].ssid, - lws_esp32.ssid[(n + try_slot + 1) & 3])) - goto hit; - } - - continue; - -hit: - m = (n + try_slot + 1) & 3; - try_slot = m; - lwsl_info("Attempting connection with slot %d: %s:\n", m, - lws_esp32.ssid[m]); - /* set the ssid we last tried to connect to */ - lws_strncpy(lws_esp32.active_ssid, lws_esp32.ssid[m], - sizeof(lws_esp32.active_ssid)); - - lws_strncpy((char *)sta_config.sta.ssid, lws_esp32.ssid[m], - sizeof(sta_config.sta.ssid)); - lws_strncpy((char *)sta_config.sta.password, lws_esp32.password[m], - sizeof(sta_config.sta.password)); - - tcpip_adapter_set_hostname(TCPIP_ADAPTER_IF_STA, - (const char *)&config.ap.ssid[7]); - lws_gapss_to(LWS_GAPSS_STAT); - xTimerStop(association_timer, 0); - xTimerStart(association_timer, 0); - - esp_wifi_set_config(WIFI_IF_STA, &sta_config); - esp_wifi_connect(); - break; - } - - if (n == 4) - start_scan(); - -passthru: - if (lws_esp32.scan_consumer) - lws_esp32.scan_consumer(count_ap_records, ap_records, - lws_esp32.scan_consumer_arg); - -} - -static void -lws_set_genled(int n) -{ - lws_esp32.genled_t = lws_now_usecs(); - lws_esp32.genled = n; -} - -int -lws_esp32_leds_network_indication(void) -{ - uint64_t us, r; - int n, fadein = 100, speed = 1199, div = 1, base = 0; - - r = lws_now_usecs(); - us = r - lws_esp32.genled_t; - - switch (lws_esp32.genled) { - case LWSESP32_GENLED__INIT: - lws_esp32.genled = LWSESP32_GENLED__LOST_NETWORK; - /* fallthru */ - case LWSESP32_GENLED__LOST_NETWORK: - fadein = us / 10000; /* 100 steps in 1s */ - if (fadein > 100) { - fadein = 100; - lws_esp32.genled = LWSESP32_GENLED__NO_NETWORK; - } - /* fallthru */ - case LWSESP32_GENLED__NO_NETWORK: - break; - case LWSESP32_GENLED__CONN_AP: - base = 4096; - speed = 933; - div = 2; - break; - case LWSESP32_GENLED__GOT_IP: - fadein = us / 10000; /* 100 steps in 1s */ - if (fadein > 100) { - fadein = 100; - lws_esp32.genled = LWSESP32_GENLED__OK; - } - fadein = 100 - fadein; /* we are fading out */ - /* fallthru */ - case LWSESP32_GENLED__OK: - if (lws_esp32.genled == LWSESP32_GENLED__OK) - return 0; - - base = 4096; - speed = 766; - div = 3; - break; - } - - n = base + (lws_esp32_sine_interp(r / speed) / div); - return (n * fadein) / 100; -} - -esp_err_t lws_esp32_event_passthru(void *ctx, system_event_t *event) -{ -#if !defined(CONFIG_LWS_IS_FACTORY_APPLICATION) - struct lws_group_member *mem; - int n; -#endif - nvs_handle nvh; - uint32_t use; - - switch((int)event->event_id) { - case SYSTEM_EVENT_STA_START: - //esp_wifi_connect(); -// break; - /* fallthru */ - case SYSTEM_EVENT_STA_DISCONNECTED: - lwsl_notice("SYSTEM_EVENT_STA_DISCONNECTED\n"); - if (sntp_enabled()) - sntp_stop(); - lws_esp32.conn_ap = 0; - lws_esp32.inet = 0; - lws_esp32.sta_ip[0] = '\0'; - lws_esp32.sta_mask[0] = '\0'; - lws_esp32.sta_gw[0] = '\0'; - lws_gapss_to(LWS_GAPSS_SCAN); - mdns_free(); - lws_set_genled(LWSESP32_GENLED__LOST_NETWORK); - start_scan(); - esp_wifi_connect(); - break; - - case SYSTEM_EVENT_STA_CONNECTED: - lws_esp32.conn_ap = 1; - lws_set_genled(LWSESP32_GENLED__CONN_AP); - break; - - case SYSTEM_EVENT_STA_GOT_IP: - lwsl_notice("SYSTEM_EVENT_STA_GOT_IP\n"); - - lws_esp32.inet = 1; - lws_set_genled(LWSESP32_GENLED__GOT_IP); - - render_ip(lws_esp32.sta_ip, sizeof(lws_esp32.sta_ip) - 1, - (uint8_t *)&event->event_info.got_ip.ip_info.ip); - render_ip(lws_esp32.sta_mask, sizeof(lws_esp32.sta_mask) - 1, - (uint8_t *)&event->event_info.got_ip.ip_info.netmask); - render_ip(lws_esp32.sta_gw, sizeof(lws_esp32.sta_gw) - 1, - (uint8_t *)&event->event_info.got_ip.ip_info.gw); - - if (!nvs_open("lws-station", NVS_READWRITE, &nvh)) { - char slot[8]; - - lws_snprintf(slot, sizeof(slot) - 1, "%duse", try_slot); - use = 0; - nvs_get_u32(nvh, slot, &use); - nvs_set_u32(nvh, slot, use + 1); - nvs_commit(nvh); - nvs_close(nvh); - } - - lws_gapss_to(LWS_GAPSS_STAT_HAPPY); - -#if !defined(CONFIG_LWS_IS_FACTORY_APPLICATION) - n = mdns_init(); - if (!n) { - static mdns_txt_item_t txta[6]; - static char wh[2][6]; - int w, h; - - mdns_hostname_set(lws_esp32.hostname); - mdns_instance_name_set(lws_esp32.group); - - lws_get_iframe_size(&w, &h); - - txta[0].key = "model"; - txta[1].key = "group"; - txta[2].key = "role"; - txta[3].key = "mac"; - txta[4].key = "width"; - txta[5].key = "height"; - - txta[0].value = lws_esp32.model; - txta[1].value = lws_esp32.group; - txta[2].value = lws_esp32.role; - txta[3].value = lws_esp32.mac; - txta[4].value = wh[0]; - txta[5].value = wh[1]; - - lws_snprintf(wh[0], 6, "%d", w); - lws_snprintf(wh[1], 6, "%d", h); - - mdns_service_add(lws_esp32.group, - "_lwsgrmem", "_tcp", 443, txta, - LWS_ARRAY_SIZE(txta)); - - mem = lws_esp32.first; - while (mem) { - if (mem->flags & 1) - break; - mem = mem->next; - } - - if (!mem) { - struct lws_group_member *mem = - lws_malloc(sizeof(*mem), "group"); - if (mem) { - mem->last_seen = ~(uint64_t)0; - strcpy(mem->model, lws_esp32.model); - strcpy(mem->role, lws_esp32.role); - strcpy(mem->host, lws_esp32.hostname); - strcpy(mem->mac, lws_esp32.mac); - mem->flags = LWS_GROUP_FLAG_SELF; - lws_get_iframe_size(&mem->width, - &mem->height); - memcpy(&mem->addr, - &event->event_info.got_ip.ip_info.ip, - sizeof(mem->addr)); - memcpy(&mem->addrv6, - &event->event_info.got_ip6.ip6_info.ip, - sizeof(mem->addrv6)); - mem->next = lws_esp32.first; - lws_esp32.first = mem; - lws_esp32.extant_group_members++; - - lws_group_member_event_call( - LWS_SYSTEM_GROUP_MEMBER_ADD, mem); - } - } else { /* update our IP */ - memcpy(&mem->addr, - &event->event_info.got_ip.ip_info.ip, - sizeof(mem->addr)); - memcpy(&mem->addrv6, - &event->event_info.got_ip6.ip6_info.ip, - sizeof(mem->addrv6)); - lws_group_member_event_call( - LWS_SYSTEM_GROUP_MEMBER_CHANGE, mem); - } - - } else - lwsl_err("unable to init mdns on STA: %d\n", n); - - mdns_query_txt(lws_esp32.group, "_lwsgrmem", "_tcp", 0, - &mdns_results_head); - xTimerStart(mdns_timer, 0); -#endif - - lwsl_notice(" --- Got IP %s\n", lws_esp32.sta_ip); - if (!sntp_enabled()) { - sntp_setoperatingmode(SNTP_OPMODE_POLL); - sntp_setservername(0, "pool.ntp.org"); - sntp_init(); - } - break; - - case SYSTEM_EVENT_SCAN_DONE: - lwsl_notice("SYSTEM_EVENT_SCAN_DONE\n"); - end_scan(); - break; - - default: - break; - } - - return ESP_OK; -} - -static lws_fop_fd_t IRAM_ATTR -esp32_lws_fops_open(const struct lws_plat_file_ops *fops, const char *filename, - const char *vfs_path, lws_fop_flags_t *flags) -{ - struct esp32_file *f = malloc(sizeof(*f)); - lws_fop_fd_t fop_fd; - size_t len, csum; - - lwsl_notice("%s: %s\n", __func__, filename); - - if (!f) - return NULL; - f->i = romfs_get_info(lws_esp32_romfs, filename, &len, &csum); - if (!f->i) - goto bail; - - fop_fd = malloc(sizeof(*fop_fd)); - if (!fop_fd) - goto bail; - - fop_fd->fops = fops; - fop_fd->filesystem_priv = f; - fop_fd->mod_time = csum; - *flags |= LWS_FOP_FLAG_MOD_TIME_VALID; - fop_fd->flags = *flags; - - fop_fd->len = len; - fop_fd->pos = 0; - - return fop_fd; - -bail: - free(f); - - return NULL; -} - -static int IRAM_ATTR -esp32_lws_fops_close(lws_fop_fd_t *fop_fd) -{ - free((*fop_fd)->filesystem_priv); - free(*fop_fd); - - *fop_fd = NULL; - - return 0; -} -static lws_fileofs_t IRAM_ATTR -esp32_lws_fops_seek_cur(lws_fop_fd_t fop_fd, lws_fileofs_t offset_from_cur_pos) -{ - fop_fd->pos += offset_from_cur_pos; - - if (fop_fd->pos > fop_fd->len) - fop_fd->pos = fop_fd->len; - - return 0; -} - -static int IRAM_ATTR -esp32_lws_fops_read(lws_fop_fd_t fop_fd, lws_filepos_t *amount, uint8_t *buf, - lws_filepos_t len) -{ - struct esp32_file *f = fop_fd->filesystem_priv; -#if 0 - if ((long)buf & 3) { - lwsl_err("misaligned buf\n"); - - return -1; - } -#endif - if (fop_fd->pos >= fop_fd->len) - return 0; - - if (len > fop_fd->len - fop_fd->pos) - len = fop_fd->len - fop_fd->pos; - - spi_flash_read((uint32_t)(char *)f->i + fop_fd->pos, buf, len); - - *amount = len; - fop_fd->pos += len; - - return 0; -} - -static const struct lws_plat_file_ops fops = { - .next = &fops_zip, - .LWS_FOP_OPEN = esp32_lws_fops_open, - .LWS_FOP_CLOSE = esp32_lws_fops_close, - .LWS_FOP_READ = esp32_lws_fops_read, - .LWS_FOP_SEEK_CUR = esp32_lws_fops_seek_cur, -}; - -int -lws_esp32_wlan_nvs_get(int retry) -{ - nvs_handle nvh; - char lws_esp32_force_ap = 0, slot[12]; - size_t s; - uint8_t mac[6]; - int n; - - esp_efuse_mac_get_default(mac); - mac[5] |= 1; /* match the AP MAC */ - snprintf(lws_esp32.serial, sizeof(lws_esp32.serial) - 1, - "%02X%02X%02X", mac[3], mac[4], mac[5]); - snprintf(lws_esp32.mac, sizeof(lws_esp32.mac) - 1, - "%02X%02X%02X%02X%02X%02X", mac[0], mac[1], mac[2], mac[3], - mac[4], mac[5]); - - ESP_ERROR_CHECK(nvs_open("lws-station", NVS_READWRITE, &nvh)); - - config.sta.ssid[0] = '\0'; - config.sta.password[0] = '\0'; - - for (n = 0; n < 4; n++) { - lws_snprintf(slot, sizeof(slot) - 1, "%dssid", n); - s = sizeof(lws_esp32.ssid[0]) - 1; - lws_esp32.ssid[n][0] = '\0'; - nvs_get_str(nvh, slot, lws_esp32.ssid[n], &s); - - lws_snprintf(slot, sizeof(slot) - 1, "%dpassword", n); - s = sizeof(lws_esp32.password[0]) - 1; - lws_esp32.password[n][0] = '\0'; - nvs_get_str(nvh, slot, lws_esp32.password[n], &s); - } - - s = sizeof(lws_esp32.serial) - 1; - if (nvs_get_str(nvh, "serial", lws_esp32.serial, &s) != ESP_OK) - lws_esp32_force_ap = 1; - else - snprintf((char *)config.ap.ssid, sizeof(config.ap.ssid) - 1, - "config-%s-%s", lws_esp32.model, lws_esp32.serial); - s = sizeof(lws_esp32.opts) - 1; - if (nvs_get_str(nvh, "opts", lws_esp32.opts, &s) != ESP_OK) - lws_esp32_force_ap = 1; - - lws_esp32.access_pw[0] = '\0'; - nvs_get_str(nvh, "access_pw", lws_esp32.access_pw, &s); - - lws_esp32.group[0] = '\0'; - s = sizeof(lws_esp32.group); - nvs_get_str(nvh, "group", lws_esp32.group, &s); - - lws_esp32.role[0] = '\0'; - s = sizeof(lws_esp32.role); - nvs_get_str(nvh, "role", lws_esp32.role, &s); - - /* if group and role defined: group-role */ - if (lws_esp32.group[0] && lws_esp32.role[0]) - lws_snprintf(lws_esp32.hostname, sizeof(lws_esp32.hostname) - 1, - "%s-%s", lws_esp32.group, lws_esp32.role); - else /* otherwise model-serial */ - lws_snprintf(lws_esp32.hostname, sizeof(lws_esp32.hostname) - 1, - "%s-%s", lws_esp32.model, lws_esp32.serial); - - nvs_close(nvh); - - lws_gapss_to(LWS_GAPSS_SCAN); - start_scan(); - - return lws_esp32_force_ap; -} - - -void -lws_esp32_wlan_config(void) -{ - ledc_timer_config_t ledc_timer = { - .bit_num = LEDC_TIMER_13_BIT, - .freq_hz = 5000, - .speed_mode = LEDC_HIGH_SPEED_MODE, - .timer_num = LEDC_TIMER_0 - }; - int n; - - lwsl_debug("%s\n", __func__); - - ledc_timer_config(&ledc_timer); - - lws_set_genled(LWSESP32_GENLED__INIT); - - /* user code needs to provide lws_esp32_leds_timer_cb */ - - leds_timer = xTimerCreate("lws_leds", pdMS_TO_TICKS(25), 1, NULL, - (TimerCallbackFunction_t)lws_esp32_leds_timer_cb); - scan_timer = xTimerCreate("lws_scan", pdMS_TO_TICKS(10000), 0, NULL, - (TimerCallbackFunction_t)lws_esp32_scan_timer_cb); - debounce_timer = xTimerCreate("lws_db", pdMS_TO_TICKS(100), 0, NULL, - (TimerCallbackFunction_t)lws_esp32_debounce_timer_cb); - association_timer = xTimerCreate("lws_assoc", pdMS_TO_TICKS(10000), 0, NULL, - (TimerCallbackFunction_t)lws_esp32_assoc_timer_cb); - -#if !defined(CONFIG_LWS_IS_FACTORY_APPLICATION) - mdns_timer = xTimerCreate("lws_mdns", pdMS_TO_TICKS(5000), 0, NULL, - (TimerCallbackFunction_t)lws_esp32_mdns_timer_cb); -#endif - scan_timer_exists = 1; - xTimerStart(leds_timer, 0); - - *(volatile uint32_t *)PERIPHS_IO_MUX_MTMS_U = FUNC_MTMS_GPIO14; - - gpio_output_set(0, 0, 0, (1 << GPIO_SW)); - - n = gpio_install_isr_service(0); - if (!n) { - gpio_config_t c; - - c.intr_type = GPIO_INTR_NEGEDGE; - c.mode = GPIO_MODE_INPUT; - c.pin_bit_mask = 1 << GPIO_SW; - c.pull_down_en = 0; - c.pull_up_en = 0; - gpio_config(&c); - - if (gpio_isr_handler_add(GPIO_SW, gpio_irq, NULL)) - lwsl_notice("isr handler add for 14 failed\n"); - } else - lwsl_notice("failed to install gpio isr service: %d\n", n); - - lws_esp32_wlan_nvs_get(0); - tcpip_adapter_init(); -} - -void -lws_esp32_wlan_start_ap(void) -{ - wifi_init_config_t cfg = WIFI_INIT_CONFIG_DEFAULT(); - - ESP_ERROR_CHECK( esp_wifi_init(&cfg)); - ESP_ERROR_CHECK( esp_wifi_set_storage(WIFI_STORAGE_RAM)); - - ESP_ERROR_CHECK( esp_wifi_set_mode(WIFI_MODE_APSTA) ); - ESP_ERROR_CHECK( esp_wifi_set_config(WIFI_IF_AP, &config) ); - ESP_ERROR_CHECK( esp_wifi_set_config(WIFI_IF_STA, &sta_config)); - ESP_ERROR_CHECK( esp_wifi_start()); - - esp_wifi_scan_start(&scan_config, false); - - if (sta_config.sta.ssid[0]) { - tcpip_adapter_set_hostname(TCPIP_ADAPTER_IF_STA, - (const char *)&config.ap.ssid[7]); - // esp_wifi_set_auto_connect(1); - ESP_ERROR_CHECK( esp_wifi_connect()); - ESP_ERROR_CHECK( esp_wifi_set_config(WIFI_IF_STA, &sta_config)); - ESP_ERROR_CHECK( esp_wifi_connect()); - } -} - -void -lws_esp32_wlan_start_station(void) -{ - wifi_init_config_t cfg = WIFI_INIT_CONFIG_DEFAULT(); - - ESP_ERROR_CHECK( esp_wifi_init(&cfg)); - ESP_ERROR_CHECK( esp_wifi_set_storage(WIFI_STORAGE_RAM)); - - ESP_ERROR_CHECK( esp_wifi_set_mode(WIFI_MODE_STA)); - ESP_ERROR_CHECK( esp_wifi_set_config(WIFI_IF_STA, &sta_config)); - - ESP_ERROR_CHECK( esp_wifi_start()); - - tcpip_adapter_set_hostname(TCPIP_ADAPTER_IF_STA, - (const char *)&config.ap.ssid[7]); - //esp_wifi_set_auto_connect(1); - //ESP_ERROR_CHECK( esp_wifi_connect()); - - lws_esp32_scan_timer_cb(NULL); -} - -const esp_partition_t * -lws_esp_ota_get_boot_partition(void) -{ - const esp_partition_t *part = esp_ota_get_boot_partition(), - *factory_part, *ota; - esp_image_header_t eih, ota_eih; - uint32_t *p_force_factory_magic = (uint32_t *)LWS_MAGIC_REBOOT_TYPE_ADS; - - /* confirm what we are told is the boot part is sane */ - spi_flash_read(part->address , &eih, sizeof(eih)); - factory_part = esp_partition_find_first(ESP_PARTITION_TYPE_APP, - ESP_PARTITION_SUBTYPE_APP_FACTORY, NULL); - ota = esp_partition_find_first(ESP_PARTITION_TYPE_APP, - ESP_PARTITION_SUBTYPE_APP_OTA_0, NULL); - spi_flash_read(ota->address , &ota_eih, sizeof(ota_eih)); - - if (eih.spi_mode == 0xff || - *p_force_factory_magic == LWS_MAGIC_REBOOT_TYPE_FORCED_FACTORY || - *p_force_factory_magic == LWS_MAGIC_REBOOT_TYPE_FORCED_FACTORY_BUTTON - ) { - /* - * we believed we were going to boot OTA, but we fell - * back to FACTORY in the bootloader when we saw it - * had been erased. esp_ota_get_boot_partition() still - * says the OTA partition then even if we are in the - * factory partition right now. - */ - part = factory_part; - } - -#ifdef CONFIG_LWS_IS_FACTORY_APPLICATION - else - if (ota_eih.spi_mode != 0xff && - part->address != factory_part->address) { - uint8_t buf[4096]; - uint32_t n; - /* - * we are a FACTORY image running in an OTA slot... - * it means we were just written and need to copy - * ourselves into the FACTORY slot. - */ - lwsl_notice("Copying FACTORY update into place " - "0x%x len 0x%x\n", factory_part->address, - factory_part->size); - esp_task_wdt_reset(); - if (spi_flash_erase_range(factory_part->address, - factory_part->size)) { - lwsl_err("spi: Failed to erase\n"); - goto retry; - } - - for (n = 0; n < factory_part->size; n += sizeof(buf)) { - esp_task_wdt_reset(); - spi_flash_read(part->address + n , buf, - sizeof(buf)); - if (spi_flash_write(factory_part->address + n, - buf, sizeof(buf))) { - lwsl_err("spi: Failed to write\n"); - goto retry; - } - } - - /* - * We send a message to the bootloader to erase the OTA header, we will come back up in - * factory where the user can reload the OTA image - */ - lwsl_notice(" FACTORY copy successful, rebooting\n"); - lws_esp32_restart_guided(LWS_MAGIC_REBOOT_TYPE_REQ_FACTORY_ERASE_OTA); -retry: - esp_restart(); - } -#endif - - return part; -} - - -void -lws_esp32_set_creation_defaults(struct lws_context_creation_info *info) -{ - const esp_partition_t *part; - - memset(info, 0, sizeof(*info)); - - lws_set_log_level(63, lwsl_emit_syslog); - - part = lws_esp_ota_get_boot_partition(); - (void)part; - - info->vhost_name = "default"; - info->port = 443; - info->fd_limit_per_thread = 16; - info->max_http_header_pool = 5; - info->max_http_header_data = 1024; - info->pt_serv_buf_size = 4096; - info->keepalive_timeout = 30; - info->timeout_secs = 30; - info->simultaneous_ssl_restriction = 2; - info->options = LWS_SERVER_OPTION_EXPLICIT_VHOSTS | - LWS_SERVER_OPTION_DO_SSL_GLOBAL_INIT; -} - -int -lws_esp32_get_image_info(const esp_partition_t *part, struct lws_esp32_image *i, - char *json, int json_len) -{ - esp_image_segment_header_t eis; - esp_image_header_t eih; - uint32_t hdr; - - spi_flash_read(part->address , &eih, sizeof(eih)); - hdr = part->address + sizeof(eih); - - if (eih.magic != ESP_IMAGE_HEADER_MAGIC) { - lwsl_notice("%s: bad image header magic\n", __func__); - return 1; - } - - eis.data_len = 0; - while (eih.segment_count-- && eis.data_len != 0xffffffff) { - spi_flash_read(hdr, &eis, sizeof(eis)); - hdr += sizeof(eis) + eis.data_len; - } - hdr += (~hdr & 15) + 1; - - if (eih.hash_appended) - hdr += 0x20; - -// lwsl_notice("romfs estimated at 0x%x\n", hdr); - - i->romfs = hdr + 0x4; - spi_flash_read(hdr, &i->romfs_len, sizeof(i->romfs_len)); - i->json = i->romfs + i->romfs_len + 4; - spi_flash_read(i->json - 4, &i->json_len, sizeof(i->json_len)); - - if (i->json_len < json_len - 1) - json_len = i->json_len; - spi_flash_read(i->json, json, json_len); - json[json_len] = '\0'; - - return 0; -} - -static int -_rngf(void *context, unsigned char *buf, size_t len) -{ - if ((size_t)lws_get_random(context, buf, len) == len) - return 0; - - return -1; -} - -int -lws_esp32_selfsigned(struct lws_vhost *vhost) -{ - mbedtls_x509write_cert crt; - char subject[200]; - mbedtls_pk_context mpk; - int buf_size = 4096, n; - uint8_t *buf = malloc(buf_size); /* malloc because given to user code */ - mbedtls_mpi mpi; - nvs_handle nvh; - size_t s; - - lwsl_notice("%s: %s\n", __func__, vhost->name); - - if (!buf) - return -1; - - if (nvs_open("lws-station", NVS_READWRITE, &nvh)) { - lwsl_notice("%s: can't open nvs\n", __func__); - free(buf); - return 1; - } - - n = 0; - if (!nvs_get_blob(nvh, vhost->tls.alloc_cert_path, NULL, &s)) - n |= 1; - if (!nvs_get_blob(nvh, vhost->tls.key_path, NULL, &s)) - n |= 2; - - nvs_close(nvh); - if (n == 3) { - lwsl_notice("%s: certs exist\n", __func__); - free(buf); - return 0; /* certs already exist */ - } - - lwsl_notice("%s: creating selfsigned initial certs\n", __func__); - - mbedtls_x509write_crt_init(&crt); - - mbedtls_pk_init(&mpk); - if (mbedtls_pk_setup(&mpk, mbedtls_pk_info_from_type(MBEDTLS_PK_RSA))) { - lwsl_notice("%s: pk_setup failed\n", __func__); - goto fail; - } - lwsl_notice("%s: generating 2048-bit RSA keypair... " - "this may take a minute or so...\n", __func__); - n = mbedtls_rsa_gen_key(mbedtls_pk_rsa(mpk), _rngf, vhost->context, - 2048, 65537); - if (n) { - lwsl_notice("%s: failed to generate keys\n", __func__); - goto fail1; - } - lwsl_notice("%s: keys done\n", __func__); - - /* subject must be formatted like "C=TW,O=warmcat,CN=myserver" */ - - lws_snprintf(subject, sizeof(subject) - 1, - "C=TW,ST=New Taipei City,L=Taipei,O=warmcat,CN=%s", - lws_esp32.hostname); - - if (mbedtls_x509write_crt_set_subject_name(&crt, subject)) { - lwsl_notice("set SN failed\n"); - goto fail1; - } - mbedtls_x509write_crt_set_subject_key(&crt, &mpk); - if (mbedtls_x509write_crt_set_issuer_name(&crt, subject)) { - lwsl_notice("set IN failed\n"); - goto fail1; - } - mbedtls_x509write_crt_set_issuer_key(&crt, &mpk); - - lws_get_random(vhost->context, &n, sizeof(n)); - lws_snprintf(subject, sizeof(subject), "%d", n); - - mbedtls_mpi_init(&mpi); - mbedtls_mpi_read_string(&mpi, 10, subject); - mbedtls_x509write_crt_set_serial(&crt, &mpi); - mbedtls_mpi_free(&mpi); - - mbedtls_x509write_crt_set_validity(&crt, "20171105235959", - "20491231235959"); - - mbedtls_x509write_crt_set_key_usage(&crt, - MBEDTLS_X509_KU_DIGITAL_SIGNATURE | - MBEDTLS_X509_KU_KEY_ENCIPHERMENT); - - - mbedtls_x509write_crt_set_md_alg(&crt, MBEDTLS_MD_SHA256); - - n = mbedtls_x509write_crt_pem(&crt, buf, buf_size, _rngf, - vhost->context); - if (n < 0) { - lwsl_notice("%s: write crt der failed\n", __func__); - goto fail1; - } - - lws_plat_write_cert(vhost, 0, 0, buf, strlen((const char *)buf)); - - if (mbedtls_pk_write_key_pem(&mpk, buf, buf_size)) { - lwsl_notice("write key pem failed\n"); - goto fail1; - } - - lws_plat_write_cert(vhost, 1, 0, buf, strlen((const char *)buf)); - - mbedtls_pk_free(&mpk); - mbedtls_x509write_crt_free(&crt); - - lwsl_notice("%s: cert creation complete\n", __func__); - - return n; - -fail1: - mbedtls_pk_free(&mpk); -fail: - mbedtls_x509write_crt_free(&crt); - free(buf); - - nvs_close(nvh); - - return -1; -} - -void -lws_esp32_update_acme_info(void) -{ - int n; - - n = lws_plat_read_file("acme-email", lws_esp32.le_email, - sizeof(lws_esp32.le_email) - 1); - if (n >= 0) - lws_esp32.le_email[n] = '\0'; - - n = lws_plat_read_file("acme-cn", lws_esp32.le_dns, - sizeof(lws_esp32.le_dns) - 1); - if (n >= 0) - lws_esp32.le_dns[n] = '\0'; -} - -struct lws_context * -lws_esp32_init(struct lws_context_creation_info *info, struct lws_vhost **pvh) -{ - const esp_partition_t *part = lws_esp_ota_get_boot_partition(); - struct lws_context *context; - struct lws_esp32_image i; - struct lws_vhost *vhost; - struct lws wsi; - char buf[512]; - - context = lws_create_context(info); - if (context == NULL) { - lwsl_err("Failed to create context\n"); - return NULL; - } - - lws_esp32_get_image_info(part, &i, buf, sizeof(buf) - 1); - - lws_esp32_romfs = (romfs_t)i.romfs; - if (!romfs_mount_check(lws_esp32_romfs)) { - lwsl_err("mount error on ROMFS at %p 0x%x\n", lws_esp32_romfs, - i.romfs); - return NULL; - } - - lwsl_notice("ROMFS length %uKiB\n", i.romfs_len >> 10); - - puts(buf); - - /* set the lws vfs to use our romfs */ - - lws_set_fops(context, &fops); - - info->options |= LWS_SERVER_OPTION_CREATE_VHOST_SSL_CTX | - LWS_SERVER_OPTION_IGNORE_MISSING_CERT; - - vhost = lws_create_vhost(context, info); - if (!vhost) { - lwsl_err("Failed to create vhost\n"); - return NULL; - } - - lws_esp32_update_acme_info(); - - lws_esp32_selfsigned(vhost); - wsi.context = vhost->context; - wsi.vhost = vhost; - - lws_tls_server_certs_load(vhost, &wsi, info->ssl_cert_filepath, - info->ssl_private_key_filepath, NULL, 0, NULL, 0); - - lws_init_vhost_client_ssl(info, vhost); - - if (pvh) - *pvh = vhost; - - if (lws_protocol_init(context)) - return NULL; - - return context; -} - -static const uint16_t sineq16[] = { - 0x0000, 0x0191, 0x031e, 0x04a4, 0x061e, 0x0789, 0x08e2, 0x0a24, - 0x0b4e, 0x0c5c, 0x0d4b, 0x0e1a, 0x0ec6, 0x0f4d, 0x0faf, 0x0fea, -}; - -static uint16_t sine_lu(int n) -{ - switch ((n >> 4) & 3) { - case 1: - return 4096 + sineq16[n & 15]; - case 2: - return 4096 + sineq16[15 - (n & 15)]; - case 3: - return 4096 - sineq16[n & 15]; - default: - return 4096 - sineq16[15 - (n & 15)]; - } -} - -/* useful for sine led fade patterns */ - -uint16_t lws_esp32_sine_interp(int n) -{ - /* - * 2: quadrant - * 4: table entry in quadrant - * 4: interp (LSB) - * - * total 10 bits / 1024 steps per cycle - * - * + 0: 0 - * + 256: 4096 - * + 512: 8192 - * + 768: 4096 - * +1023: 0 - */ - - return (sine_lu(n >> 4) * (15 - (n & 15)) + - sine_lu((n >> 4) + 1) * (n & 15)) / 15; -} diff -Nru libwebsockets-3.2.1/lib/plat/esp32/esp32-init.c libwebsockets-4.1.6/lib/plat/esp32/esp32-init.c --- libwebsockets-3.2.1/lib/plat/esp32/esp32-init.c 2019-12-18 14:45:31.000000000 +0000 +++ libwebsockets-4.1.6/lib/plat/esp32/esp32-init.c 1970-01-01 00:00:00.000000000 +0000 @@ -1,112 +0,0 @@ -/* - * libwebsockets - lib/plat/lws-plat-esp32.c - * - * Copyright (C) 2010-2017 Andy Green - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation: - * version 2.1 of the License. - * - * This library is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with this library; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, - * MA 02110-1301 USA - */ - -#include "core/private.h" - -int -lws_plat_context_early_init(void) -{ - return 0; -} - -void -lws_plat_context_early_destroy(struct lws_context *context) -{ -#if defined(LWS_AMAZON_RTOS) - mbedtls_ctr_drbg_free(&context->mcdc); - mbedtls_entropy_free(&context->mec); -#endif -} - -void -lws_plat_context_late_destroy(struct lws_context *context) -{ -#ifdef LWS_WITH_PLUGINS - if (context->plugin_list) - lws_plat_plugins_destroy(context); -#endif - - if (context->lws_lookup) - lws_free(context->lws_lookup); -} - -#if defined(LWS_WITH_HTTP2) -/* - * These are the default SETTINGS used on this platform. The user - * can selectively modify them for a vhost during vhost creation. - */ -const struct http2_settings lws_h2_defaults_esp32 = { { - 1, - /* H2SET_HEADER_TABLE_SIZE */ 512, - /* H2SET_ENABLE_PUSH */ 0, - /* H2SET_MAX_CONCURRENT_STREAMS */ 8, - /* H2SET_INITIAL_WINDOW_SIZE */ 65535, - /* H2SET_MAX_FRAME_SIZE */ 16384, - /* H2SET_MAX_HEADER_LIST_SIZE */ 512, - /* H2SET_RESERVED7 */ 0, - /* H2SET_ENABLE_CONNECT_PROTOCOL */ 1, -}}; -#endif - -int -lws_plat_init(struct lws_context *context, - const struct lws_context_creation_info *info) -{ -#if defined(LWS_AMAZON_RTOS) - int n; - - /* initialize platform random through mbedtls */ - mbedtls_entropy_init(&context->mec); - mbedtls_ctr_drbg_init(&context->mcdc); - - n = mbedtls_ctr_drbg_seed(&context->mcdc, mbedtls_entropy_func, - &context->mec, NULL, 0); - if (n) { - lwsl_err("%s: mbedtls_ctr_drbg_seed() returned 0x%x\n", - __func__, n); - - return 1; - } -#endif - - /* master context has the global fd lookup array */ - context->lws_lookup = lws_zalloc(sizeof(struct lws *) * - context->max_fds, "esp32 lws_lookup"); - if (context->lws_lookup == NULL) { - lwsl_err("OOM on lws_lookup array for %d connections\n", - context->max_fds); - return 1; - } - - lwsl_notice(" mem: platform fd map: %5lu bytes\n", - (unsigned long)(sizeof(struct lws *) * context->max_fds)); - -#ifdef LWS_WITH_PLUGINS - if (info->plugin_dirs) - lws_plat_plugins_init(context, info->plugin_dirs); -#endif -#if defined(LWS_WITH_HTTP2) - /* override settings */ - context->set = lws_h2_defaults_esp32; -#endif - - return 0; -} diff -Nru libwebsockets-3.2.1/lib/plat/esp32/esp32-misc.c libwebsockets-4.1.6/lib/plat/esp32/esp32-misc.c --- libwebsockets-3.2.1/lib/plat/esp32/esp32-misc.c 2019-12-18 14:45:31.000000000 +0000 +++ libwebsockets-4.1.6/lib/plat/esp32/esp32-misc.c 1970-01-01 00:00:00.000000000 +0000 @@ -1,96 +0,0 @@ -/* - * libwebsockets - lib/plat/lws-plat-esp32.c - * - * Copyright (C) 2010-2017 Andy Green - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation: - * version 2.1 of the License. - * - * This library is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with this library; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, - * MA 02110-1301 USA - */ - -#include "core/private.h" - -lws_usec_t -lws_now_usecs(void) -{ - struct timeval tv; - gettimeofday(&tv, NULL); - return ((unsigned long long)tv.tv_sec * 1000000LL) + tv.tv_usec; -} - -LWS_VISIBLE int -lws_get_random(struct lws_context *context, void *buf, int len) -{ -#if defined(LWS_AMAZON_RTOS) - int n; - - n = mbedtls_ctr_drbg_random(&context->mcdc, buf, len); - if (!n) - return len; - - /* failed */ - - lwsl_err("%s: mbedtls_ctr_drbg_random returned 0x%x\n", __func__, n); - - return 0; -#else - uint8_t *pb = buf; - - while (len) { - uint32_t r = esp_random(); - uint8_t *p = (uint8_t *)&r; - int b = 4; - - if (len < b) - b = len; - - len -= b; - - while (b--) - *pb++ = p[b]; - } - - return pb - (uint8_t *)buf; -#endif -} - - -LWS_VISIBLE void lwsl_emit_syslog(int level, const char *line) -{ - lwsl_emit_stderr(level, line); -} - -int -lws_plat_drop_app_privileges(struct lws_context *context, int actually_init) -{ - return 0; -} - -int -lws_plat_recommended_rsa_bits(void) -{ - /* - * 2048-bit key generation takes up to a minute on ESP32, 4096 - * is like 15 minutes + - */ - return 2048; -} - -void esp32_uvtimer_cb(TimerHandle_t t) -{ - struct timer_mapping *p = pvTimerGetTimerID(t); - - p->cb(p->t); -} - diff -Nru libwebsockets-3.2.1/lib/plat/esp32/esp32-pipe.c libwebsockets-4.1.6/lib/plat/esp32/esp32-pipe.c --- libwebsockets-3.2.1/lib/plat/esp32/esp32-pipe.c 2019-12-18 14:45:31.000000000 +0000 +++ libwebsockets-4.1.6/lib/plat/esp32/esp32-pipe.c 1970-01-01 00:00:00.000000000 +0000 @@ -1,39 +0,0 @@ -/* - * libwebsockets - lib/plat/lws-plat-esp32.c - * - * Copyright (C) 2010-2017 Andy Green - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation: - * version 2.1 of the License. - * - * This library is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with this library; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, - * MA 02110-1301 USA - */ - -#include "core/private.h" - -int -lws_plat_pipe_create(struct lws *wsi) -{ - return 1; -} - -int -lws_plat_pipe_signal(struct lws *wsi) -{ - return 1; -} - -void -lws_plat_pipe_close(struct lws *wsi) -{ -} diff -Nru libwebsockets-3.2.1/lib/plat/esp32/esp32-service.c libwebsockets-4.1.6/lib/plat/esp32/esp32-service.c --- libwebsockets-3.2.1/lib/plat/esp32/esp32-service.c 2019-12-18 14:45:31.000000000 +0000 +++ libwebsockets-4.1.6/lib/plat/esp32/esp32-service.c 1970-01-01 00:00:00.000000000 +0000 @@ -1,217 +0,0 @@ -/* - * libwebsockets - lib/plat/lws-plat-esp32.c - * - * Copyright (C) 2010-2017 Andy Green - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation: - * version 2.1 of the License. - * - * This library is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with this library; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, - * MA 02110-1301 USA - */ - -#include "core/private.h" - -int -lws_plat_service(struct lws_context *context, int timeout_ms) -{ - int n = _lws_plat_service_tsi(context, timeout_ms, 0); - -#if !defined(LWS_AMAZON_RTOS) - esp_task_wdt_reset(); -#endif - - return n; -} - - -LWS_EXTERN int -_lws_plat_service_tsi(struct lws_context *context, int timeout_ms, int tsi) -{ - struct lws_context_per_thread *pt; - lws_usec_t timeout_us; - int n = -1, m, c, a = 0; - - /* stay dead once we are dead */ - - if (!context || !context->vhost_list) - return 1; - - pt = &context->pt[tsi]; - lws_stats_bump(pt, LWSSTATS_C_SERVICE_ENTRY, 1); - - { - unsigned long m = lws_now_secs(); - - if (m > context->time_last_state_dump) { - context->time_last_state_dump = m; -#if defined(LWS_AMAZON_RTOS) - n = xPortGetFreeHeapSize(); -#else - n = esp_get_free_heap_size(); -#endif - if ((unsigned int)n != context->last_free_heap) { - if ((unsigned int)n > context->last_free_heap) - lwsl_notice(" heap :%ld (+%ld)\n", - (unsigned long)n, - (unsigned long)(n - - context->last_free_heap)); - else - lwsl_notice(" heap :%ld (-%ld)\n", - (unsigned long)n, - (unsigned long)( - context->last_free_heap - - n)); - context->last_free_heap = n; - } - } - } - - if (timeout_ms < 0) - timeout_ms = 0; - else - /* force a default timeout of 23 days */ - timeout_ms = 2000000000; - timeout_us = ((lws_usec_t)timeout_ms) * LWS_US_PER_MS; - - if (!pt->service_tid_detected) { - struct lws *_lws = lws_zalloc(sizeof(*_lws), "tid probe"); - - if (!_lws) - return 1; - _lws->context = context; - - pt->service_tid = context->vhost_list->protocols[0].callback( - _lws, LWS_CALLBACK_GET_THREAD_ID, NULL, NULL, 0); - pt->service_tid_detected = 1; - lws_free(_lws); - } - - /* - * is there anybody with pending stuff that needs service forcing? - */ - if (lws_service_adjust_timeout(context, 1, tsi)) { - -again: - a = 0; - if (timeout_us) { - lws_usec_t us; - - lws_pt_lock(pt, __func__); - /* don't stay in poll wait longer than next hr timeout */ - us = __lws_sul_service_ripe(&pt->pt_sul_owner, lws_now_usecs()); - if (us && us < timeout_us) - timeout_us = us; - - lws_pt_unlock(pt); - } - - // n = poll(pt->fds, pt->fds_count, timeout_ms); - { - fd_set readfds, writefds, errfds; - struct timeval tv = { timeout_us / LWS_US_PER_SEC, - timeout_us % LWS_US_PER_SEC }, *ptv = &tv; - int max_fd = 0; - FD_ZERO(&readfds); - FD_ZERO(&writefds); - FD_ZERO(&errfds); - - for (n = 0; n < (int)pt->fds_count; n++) { - pt->fds[n].revents = 0; - if (pt->fds[n].fd >= max_fd) - max_fd = pt->fds[n].fd; - if (pt->fds[n].events & LWS_POLLIN) - FD_SET(pt->fds[n].fd, &readfds); - if (pt->fds[n].events & LWS_POLLOUT) - FD_SET(pt->fds[n].fd, &writefds); - FD_SET(pt->fds[n].fd, &errfds); - } - - n = select(max_fd + 1, &readfds, &writefds, &errfds, ptv); - n = 0; - - #if defined(LWS_WITH_DETAILED_LATENCY) - /* - * so we can track how long it took before we actually read a POLLIN - * that was signalled when we last exited poll() - */ - if (context->detailed_latency_cb) - pt->ust_left_poll = lws_now_usecs(); - #endif - - for (m = 0; m < (int)pt->fds_count; m++) { - c = 0; - if (FD_ISSET(pt->fds[m].fd, &readfds)) { - pt->fds[m].revents |= LWS_POLLIN; - c = 1; - } - if (FD_ISSET(pt->fds[m].fd, &writefds)) { - pt->fds[m].revents |= LWS_POLLOUT; - c = 1; - } - if (FD_ISSET(pt->fds[m].fd, &errfds)) { - // lwsl_notice("errfds %d\n", pt->fds[m].fd); - pt->fds[m].revents |= LWS_POLLHUP; - c = 1; - } - - if (c) - n++; - } - } - - m = 0; - - #if defined(LWS_ROLE_WS) && !defined(LWS_WITHOUT_EXTENSIONS) - m |= !!pt->ws.rx_draining_ext_list; - #endif - - if (pt->context->tls_ops && - pt->context->tls_ops->fake_POLLIN_for_buffered) - m |= pt->context->tls_ops->fake_POLLIN_for_buffered(pt); - - if (!m && !n) - return 0; - } else - a = 1; - - m = lws_service_flag_pending(context, tsi); - if (m) - c = -1; /* unknown limit */ - else - if (n < 0) { - if (LWS_ERRNO != LWS_EINTR) - return -1; - return 0; - } else - c = n; - - /* any socket with events to service? */ - for (n = 0; n < (int)pt->fds_count && c; n++) { - if (!pt->fds[n].revents) - continue; - - c--; - - m = lws_service_fd_tsi(context, &pt->fds[n], tsi); - if (m < 0) - return -1; - /* if something closed, retry this slot */ - if (m) - n--; - } - - if (a) - goto again; - - return 0; -} diff -Nru libwebsockets-3.2.1/lib/plat/esp32/esp32-sockets.c libwebsockets-4.1.6/lib/plat/esp32/esp32-sockets.c --- libwebsockets-3.2.1/lib/plat/esp32/esp32-sockets.c 2019-12-18 14:45:31.000000000 +0000 +++ libwebsockets-4.1.6/lib/plat/esp32/esp32-sockets.c 1970-01-01 00:00:00.000000000 +0000 @@ -1,226 +0,0 @@ -/* - * libwebsockets - lib/plat/lws-plat-esp32.c - * - * Copyright (C) 2010-2017 Andy Green - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation: - * version 2.1 of the License. - * - * This library is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with this library; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, - * MA 02110-1301 USA - */ - -#include "core/private.h" - -int -lws_send_pipe_choked(struct lws *wsi) -{ - struct lws *wsi_eff = wsi; - fd_set writefds; - struct timeval tv = { 0, 0 }; - int n; -#if defined(LWS_WITH_HTTP2) - wsi_eff = lws_get_network_wsi(wsi); -#endif - - /* the fact we checked implies we avoided back-to-back writes */ - wsi_eff->could_have_pending = 0; - - /* treat the fact we got a truncated send pending as if we're choked */ - if (lws_has_buffered_out(wsi) -#if defined(LWS_WITH_HTTP_STREAM_COMPRESSION) - || wsi->http.comp_ctx.buflist_comp || - wsi->http.comp_ctx.may_have_more -#endif - ) - return 1; - - FD_ZERO(&writefds); - FD_SET(wsi_eff->desc.sockfd, &writefds); - - n = select(wsi_eff->desc.sockfd + 1, NULL, &writefds, NULL, &tv); - if (n < 0) - return 1; /* choked */ - - return !n; /* n = 0 = not writable = choked */ -} - -int -lws_poll_listen_fd(struct lws_pollfd *fd) -{ - fd_set readfds; - struct timeval tv = { 0, 0 }; - - FD_ZERO(&readfds); - FD_SET(fd->fd, &readfds); - - return select(fd->fd + 1, &readfds, NULL, NULL, &tv); -} - -int -lws_plat_check_connection_error(struct lws *wsi) -{ - return 0; -} - -int -lws_plat_set_nonblocking(int fd) -{ - return fcntl(fd, F_SETFL, O_NONBLOCK) < 0; -} - -int -lws_plat_set_socket_options(struct lws_vhost *vhost, int fd, int unix_skt) -{ - int optval = 1; - socklen_t optlen = sizeof(optval); - -#if defined(__APPLE__) || \ - defined(__FreeBSD__) || defined(__FreeBSD_kernel__) || \ - defined(__NetBSD__) || \ - defined(__OpenBSD__) - struct protoent *tcp_proto; -#endif - - if (vhost->ka_time) { - /* enable keepalive on this socket */ - optval = 1; - if (setsockopt(fd, SOL_SOCKET, SO_KEEPALIVE, - (const void *)&optval, optlen) < 0) - return 1; - -#if defined(__APPLE__) || \ - defined(__FreeBSD__) || defined(__FreeBSD_kernel__) || \ - defined(__NetBSD__) || \ - defined(__CYGWIN__) || defined(__OpenBSD__) || defined (__sun) - - /* - * didn't find a way to set these per-socket, need to - * tune kernel systemwide values - */ -#else - /* set the keepalive conditions we want on it too */ - optval = vhost->ka_time; - if (setsockopt(fd, IPPROTO_TCP, TCP_KEEPIDLE, - (const void *)&optval, optlen) < 0) - return 1; - - optval = vhost->ka_interval; - if (setsockopt(fd, IPPROTO_TCP, TCP_KEEPINTVL, - (const void *)&optval, optlen) < 0) - return 1; - - optval = vhost->ka_probes; - if (setsockopt(fd, IPPROTO_TCP, TCP_KEEPCNT, - (const void *)&optval, optlen) < 0) - return 1; -#endif - } - - /* Disable Nagle */ - optval = 1; - if (setsockopt(fd, IPPROTO_TCP, TCP_NODELAY, &optval, optlen) < 0) - return 1; - - return lws_plat_set_nonblocking(fd); -} - -/* cast a struct sockaddr_in6 * into addr for ipv6 */ - -int -lws_interface_to_sa(int ipv6, const char *ifname, struct sockaddr_in *addr, - size_t addrlen) -{ -#if 0 - int rc = LWS_ITOSA_NOT_EXIST; - - struct ifaddrs *ifr; - struct ifaddrs *ifc; -#ifdef LWS_WITH_IPV6 - struct sockaddr_in6 *addr6 = (struct sockaddr_in6 *)addr; -#endif - - getifaddrs(&ifr); - for (ifc = ifr; ifc != NULL && rc; ifc = ifc->ifa_next) { - if (!ifc->ifa_addr) - continue; - - lwsl_info(" interface %s vs %s\n", ifc->ifa_name, ifname); - - if (strcmp(ifc->ifa_name, ifname)) - continue; - - switch (ifc->ifa_addr->sa_family) { - case AF_INET: -#ifdef LWS_WITH_IPV6 - if (ipv6) { - /* map IPv4 to IPv6 */ - memset((char *)&addr6->sin6_addr, 0, - sizeof(struct in6_addr)); - addr6->sin6_addr.s6_addr[10] = 0xff; - addr6->sin6_addr.s6_addr[11] = 0xff; - memcpy(&addr6->sin6_addr.s6_addr[12], - &((struct sockaddr_in *)ifc->ifa_addr)->sin_addr, - sizeof(struct in_addr)); - } else -#endif - memcpy(addr, - (struct sockaddr_in *)ifc->ifa_addr, - sizeof(struct sockaddr_in)); - break; -#ifdef LWS_WITH_IPV6 - case AF_INET6: - memcpy(&addr6->sin6_addr, - &((struct sockaddr_in6 *)ifc->ifa_addr)->sin6_addr, - sizeof(struct in6_addr)); - break; -#endif - default: - continue; - } - rc = LWS_ITOSA_USABLE; - } - - freeifaddrs(ifr); - - if (rc == LWS_ITOSA_NOT_EXIST) { - /* check if bind to IP address */ -#ifdef LWS_WITH_IPV6 - if (inet_pton(AF_INET6, ifname, &addr6->sin6_addr) == 1) - rc = LWS_ITOSA_USABLE; - else -#endif - if (inet_pton(AF_INET, ifname, &addr->sin_addr) == 1) - rc = LWS_ITOSA_USABLE; - } - - return rc; -#endif - - return LWS_ITOSA_NOT_EXIST; -} - -const char * -lws_plat_inet_ntop(int af, const void *src, char *dst, int cnt) -{ - return inet_ntop(af, src, dst, cnt); -} - -int -lws_plat_inet_pton(int af, const char *src, void *dst) -{ - return 1; // inet_pton(af, src, dst); -} - - - - diff -Nru libwebsockets-3.2.1/lib/plat/esp32/esp_attr.h libwebsockets-4.1.6/lib/plat/esp32/esp_attr.h --- libwebsockets-3.2.1/lib/plat/esp32/esp_attr.h 2019-12-18 14:45:31.000000000 +0000 +++ libwebsockets-4.1.6/lib/plat/esp32/esp_attr.h 1970-01-01 00:00:00.000000000 +0000 @@ -1,58 +0,0 @@ -// Copyright 2015-2016 Espressif Systems (Shanghai) PTE LTD -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at - -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. -#ifndef __ESP_ATTR_H__ -#define __ESP_ATTR_H__ - -#define ROMFN_ATTR - -//Normally, the linker script will put all code and rodata in flash, -//and all variables in shared RAM. These macros can be used to redirect -//particular functions/variables to other memory regions. - -// Forces code into IRAM instead of flash. -#define IRAM_ATTR __attribute__((section(".iram1"))) - -// Forces data into DRAM instead of flash -#define DRAM_ATTR __attribute__((section(".dram1"))) - -// Forces data to be 4 bytes aligned -#define WORD_ALIGNED_ATTR __attribute__((aligned(4))) - -// Forces data to be placed to DMA-capable places -#define DMA_ATTR WORD_ALIGNED_ATTR DRAM_ATTR - -// Forces a string into DRAM instead of flash -// Use as ets_printf(DRAM_STR("Hello world!\n")); -#define DRAM_STR(str) (__extension__({static const DRAM_ATTR char __c[] = (str); (const char *)&__c;})) - -// Forces code into RTC fast memory. See "docs/deep-sleep-stub.rst" -#define RTC_IRAM_ATTR __attribute__((section(".rtc.text"))) - -// Forces data into RTC slow memory. See "docs/deep-sleep-stub.rst" -// Any variable marked with this attribute will keep its value -// during a deep sleep / wake cycle. -#define RTC_DATA_ATTR __attribute__((section(".rtc.data"))) - -// Forces read-only data into RTC slow memory. See "docs/deep-sleep-stub.rst" -#define RTC_RODATA_ATTR __attribute__((section(".rtc.rodata"))) - -// Forces data into noinit section to avoid initialization after restart. -#define __NOINIT_ATTR __attribute__((section(".noinit"))) - -// Forces data into RTC slow memory of .noinit section. -// Any variable marked with this attribute will keep its value -// after restart or during a deep sleep / wake cycle. -#define RTC_NOINIT_ATTR __attribute__((section(".rtc_noinit"))) - -#endif /* __ESP_ATTR_H__ */ diff -Nru libwebsockets-3.2.1/lib/plat/esp32/private.h libwebsockets-4.1.6/lib/plat/esp32/private.h --- libwebsockets-3.2.1/lib/plat/esp32/private.h 2019-12-18 14:45:31.000000000 +0000 +++ libwebsockets-4.1.6/lib/plat/esp32/private.h 1970-01-01 00:00:00.000000000 +0000 @@ -1,101 +0,0 @@ -/* - * libwebsockets - small server side websockets and web server implementation - * - * Copyright (C) 2010 - 2018 Andy Green - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation: - * version 2.1 of the License. - * - * This library is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with this library; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, - * MA 02110-1301 USA - * - * Included from lib/core/private.h if LWS_WITH_ESP32 - */ - -#define MSG_NOSIGNAL 0 -#define SOMAXCONN 3 - -#if defined(LWS_AMAZON_RTOS) - int - open(const char *path, int oflag, ...); -#else - #include -#endif - - #include - #include - #include - #include - #include - #include - - #ifndef __cplusplus - #include - #endif - #include - #include -#if defined(LWS_AMAZON_RTOS) -const char * -gai_strerror(int); -#else - #include -#endif - -#if defined(LWS_AMAZON_RTOS) - #include "FreeRTOS.h" - #include "timers.h" - #include -#else - #include "freertos/timers.h" - #include - #include - #include -#endif - -#include "lwip/apps/sntp.h" - -#include - - #if defined(LWS_BUILTIN_GETIFADDRS) - #include "./misc/getifaddrs.h" - #endif - - #define LWS_ERRNO errno - #define LWS_EAGAIN EAGAIN - #define LWS_EALREADY EALREADY - #define LWS_EINPROGRESS EINPROGRESS - #define LWS_EINTR EINTR - #define LWS_EISCONN EISCONN - #define LWS_ENOTCONN ENOTCONN - #define LWS_EWOULDBLOCK EWOULDBLOCK - #define LWS_EADDRINUSE EADDRINUSE - - #define lws_set_blocking_send(wsi) - - #ifndef LWS_NO_FORK - #ifdef LWS_HAVE_SYS_PRCTL_H - #include - #endif - #endif - -#define compatible_close(x) close(x) -#define lws_plat_socket_offset() LWIP_SOCKET_OFFSET -#define wsi_from_fd(A,B) A->lws_lookup[B - lws_plat_socket_offset()] - -struct lws_context; -struct lws; - -int -insert_wsi(const struct lws_context *context, struct lws *wsi); - -#define delete_from_fd(A,B) A->lws_lookup[B - lws_plat_socket_offset()] = 0 - diff -Nru libwebsockets-3.2.1/lib/plat/freertos/CMakeLists.txt libwebsockets-4.1.6/lib/plat/freertos/CMakeLists.txt --- libwebsockets-3.2.1/lib/plat/freertos/CMakeLists.txt 1970-01-01 00:00:00.000000000 +0000 +++ libwebsockets-4.1.6/lib/plat/freertos/CMakeLists.txt 2020-12-01 17:40:26.000000000 +0000 @@ -0,0 +1,60 @@ +# +# libwebsockets - small server side websockets and web server implementation +# +# Copyright (C) 2010 - 2020 Andy Green +# +# Permission is hereby granted, free of charge, to any person obtaining a copy +# of this software and associated documentation files (the "Software"), to +# deal in the Software without restriction, including without limitation the +# rights to use, copy, modify, merge, publish, distribute, sublicense, and/or +# sell copies of the Software, and to permit persons to whom the Software is +# furnished to do so, subject to the following conditions: +# +# The above copyright notice and this permission notice shall be included in +# all copies or substantial portions of the Software. +# +# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING +# FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS +# IN THE SOFTWARE. +# +# The strategy is to only export to PARENT_SCOPE +# +# - changes to LIB_LIST +# - changes to SOURCES +# - includes via include_directories +# +# and keep everything else private + +include_directories(. esp32) + +list(APPEND SOURCES + plat/freertos/freertos-fds.c + plat/freertos/freertos-init.c + plat/freertos/freertos-misc.c + plat/freertos/freertos-pipe.c + plat/freertos/freertos-service.c + plat/freertos/freertos-sockets.c + misc/romfs.c) + +if (LWS_ESP_PLATFORM AND LWS_WITH_DRIVERS) + list(APPEND SOURCES plat/freertos/esp32/drivers/settings-esp32.c) + if (LWS_WITH_NETWORK) + list(APPEND SOURCES plat/freertos/esp32/drivers/netdev/wifi-esp32.c) + endif() +endif() +if (LWS_WITH_FILE_OPS) + list(APPEND SOURCES plat/freertos/freertos-file.c) +endif() +if (LWS_WITH_SYS_ASYNC_DNS OR LWS_WITH_SYS_NTPCLIENT) + list(APPEND SOURCES plat/freertos/freertos-resolv.c) +endif() + +# +# Keep explicit parent scope exports at end +# + +exports_to_parent_scope() diff -Nru libwebsockets-3.2.1/lib/plat/freertos/esp32/drivers/gpio-esp32.c libwebsockets-4.1.6/lib/plat/freertos/esp32/drivers/gpio-esp32.c --- libwebsockets-3.2.1/lib/plat/freertos/esp32/drivers/gpio-esp32.c 1970-01-01 00:00:00.000000000 +0000 +++ libwebsockets-4.1.6/lib/plat/freertos/esp32/drivers/gpio-esp32.c 2020-12-01 17:40:26.000000000 +0000 @@ -0,0 +1,96 @@ +/* + * esp32 / esp-idf gpio + * + * Copyright (C) 2019 - 2020 Andy Green + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to + * deal in the Software without restriction, including without limitation the + * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or + * sell copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS + * IN THE SOFTWARE. + */ + +#include + +static void +lws_gpio_esp32_mode(_lws_plat_gpio_t gpio, int flags) +{ + int mode, pup = GPIO_FLOATING; + + switch (flags & (LWSGGPIO_FL_READ | LWSGGPIO_FL_WRITE)) { + default: + lwsl_err("%s: neither read nor write\n", __func__); + return; + case LWSGGPIO_FL_READ: + mode = GPIO_MODE_INPUT; + break; + case LWSGGPIO_FL_WRITE: + mode = GPIO_MODE_OUTPUT; + break; + case LWSGGPIO_FL_READ | LWSGGPIO_FL_WRITE: + mode = GPIO_MODE_INPUT_OUTPUT; + break; + } + + switch (flags & (LWSGGPIO_FL_PULLUP | LWSGGPIO_FL_PULLDOWN)) { + default: + break; + case LWSGGPIO_FL_PULLUP: + pup = GPIO_PULLUP_ONLY; + break; + case LWSGGPIO_FL_PULLDOWN: + pup = GPIO_PULLDOWN_ONLY; + break; + case LWSGGPIO_FL_PULLUP | LWSGGPIO_FL_PULLDOWN: + pup = GPIO_PULLUP_PULLDOWN; + break; + } + + gpio_reset_pin(gpio); + gpio_set_direction(gpio, mode); + gpio_set_pull_mode(gpio, pup); + gpio_set_level(gpio, flags & LWSGGPIO_FL_START_LOW ? 0 : 1); +} + +static int +lws_gpio_esp32_read(_lws_plat_gpio_t gpio) +{ + return gpio_get_level(gpio); +} +static void +lws_gpio_esp32_set(_lws_plat_gpio_t gpio, int val) +{ + gpio_set_level(gpio, val); +} + +static int +lws_gpio_esp32_irq_mode(_lws_plat_gpio_t gpio, lws_gpio_irq_t irq_type, + lws_gpio_irq_cb_t cb, void *arg) +{ + if (gpio_set_intr_type(gpio, irq_type)) + return 1; + + if (cb) + return gpio_isr_handler_add(gpio, cb, arg); + + return gpio_isr_handler_remove(gpio); +} + +const lws_gpio_ops_t lws_gpio_plat = { + .mode = lws_gpio_esp32_mode, + .read = lws_gpio_esp32_read, + .set = lws_gpio_esp32_set, + .irq_mode = lws_gpio_esp32_irq_mode, +}; diff -Nru libwebsockets-3.2.1/lib/plat/freertos/esp32/drivers/lws-plat-gpio.h libwebsockets-4.1.6/lib/plat/freertos/esp32/drivers/lws-plat-gpio.h --- libwebsockets-3.2.1/lib/plat/freertos/esp32/drivers/lws-plat-gpio.h 1970-01-01 00:00:00.000000000 +0000 +++ libwebsockets-4.1.6/lib/plat/freertos/esp32/drivers/lws-plat-gpio.h 2020-12-01 17:40:26.000000000 +0000 @@ -0,0 +1,25 @@ +/* + * lws generic gpio - esp32 platform wrapper + * + * Written in 2010-2020 by Andy Green + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to + * deal in the Software without restriction, including without limitation the + * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or + * sell copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS + * IN THE SOFTWARE. + */ + +extern const lws_gpio_ops_t lws_gpio_plat; diff -Nru libwebsockets-3.2.1/lib/plat/freertos/esp32/drivers/netdev/wifi-esp32.c libwebsockets-4.1.6/lib/plat/freertos/esp32/drivers/netdev/wifi-esp32.c --- libwebsockets-3.2.1/lib/plat/freertos/esp32/drivers/netdev/wifi-esp32.c 1970-01-01 00:00:00.000000000 +0000 +++ libwebsockets-4.1.6/lib/plat/freertos/esp32/drivers/netdev/wifi-esp32.c 2020-12-01 17:40:26.000000000 +0000 @@ -0,0 +1,496 @@ +/* + * libwebsockets - esp32 wifi -> lws_netdev_wifi + * + * Copyright (C) 2010 - 2020 Andy Green + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to + * deal in the Software without restriction, including without limitation the + * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or + * sell copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS + * IN THE SOFTWARE. + * + * + * These are the esp platform wifi-specific netdev pieces. Nothing else should + * know any esp-specific apis. + * + * Operations happen via the generic lws_detdev instantiation for the platform + * wifi device, which point in here for operations. We also set up native OS + * event hooks per device for wifi and IP stack events, and post them as lws_smd + * NETWORK events on the if in the "platform private" namespace. We then + * service the events in the lws event loop thread context, which may again + * generate lws_smd NETWORK events in the public namespace depending on what + * happened. + * + * Scan requests go through a sul to make sure we don't get "piling on" from + * scheduled, timed scans. Scan results go through the lws_smd "washing" and + * are actually parsed in lws thread context, where they are converted to lws + * netdev scan results and processed by generic code. + */ + +#include "private-lib-core.h" + +#include "esp_system.h" +#include "esp_spi_flash.h" +#include "esp_wifi.h" +#include +#include + +/* + * lws_netdev_instance_t: + * lws_netdev_instance_wifi_t: + * lws_netdev_instance_wifi_esp32_t + */ + +typedef struct lws_netdev_instance_wifi_esp32 { + lws_netdev_instance_wifi_t wnd; + esp_event_handler_instance_t instance_any_id; + esp_event_handler_instance_t instance_got_ip; + wifi_config_t sta_config; +} lws_netdev_instance_wifi_esp32_t; + +/* +static wifi_config_t config = { + .ap = { + .channel = 6, + .authmode = WIFI_AUTH_OPEN, + .max_connection = 1, + } }; + */ + +/* + * Platform-specific connect / associate + */ + +int +lws_netdev_wifi_connect_plat(lws_netdev_instance_t *nd, const char *ssid, + const char *passphrase, uint8_t *bssid) +{ + lws_netdev_instance_wifi_esp32_t *wnde32 = + (lws_netdev_instance_wifi_esp32_t *)nd; + + wnde32->wnd.inst.ops->up(&wnde32->wnd.inst); + + wnde32->wnd.flags |= LNDIW_MODE_STA; + esp_wifi_set_mode(WIFI_MODE_STA); + +#if 0 + /* we will do our own dhcp */ + tcpip_adapter_dhcpc_stop(TCPIP_ADAPTER_IF_STA); +#endif + + lws_strncpy((char *)wnde32->sta_config.sta.ssid, ssid, + sizeof(wnde32->sta_config.sta.ssid)); + lws_strncpy((char *)wnde32->sta_config.sta.password, passphrase, + sizeof(wnde32->sta_config.sta.password)); + + esp_wifi_set_config(WIFI_IF_STA, &wnde32->sta_config); + esp_wifi_connect(); + + return 0; +} + +/* + * This is called from the SMD / lws thread context, after we heard there were + * scan results on this netdev + */ + +static void +lws_esp32_scan_update(lws_netdev_instance_wifi_t *wnd) +{ +// lws_netdevs_t *netdevs = lws_netdevs_from_ndi(&wnd->inst); + wifi_ap_record_t ap_records[LWS_WIFI_MAX_SCAN_TRACK], *ar; + uint32_t now = lws_now_secs(); + uint16_t count_ap_records; + int n; + + count_ap_records = LWS_ARRAY_SIZE(ap_records); + if (esp_wifi_scan_get_ap_records(&count_ap_records, ap_records)) { + lwsl_err("%s: failed\n", __func__); + return; + } + + if (!count_ap_records) + return; + + if (wnd->state != LWSNDVWIFI_STATE_SCAN) + return; + + /* + * ... let's collect the OS-specific scan results, and convert then to + * lws_netdev sorted by rssi. If we already have it in the scan list, + * keep it and keep a little ringbuffer of its rssi along with an + * averaging. If it's new, add it into the linked-list sorted by rssi. + */ + + ar = &ap_records[0]; + for (n = 0; n < count_ap_records; n++) { + lws_wifi_sta_t *w; + int m; + + m = strlen((const char *)ar->ssid); + if (!m) + goto next; + + /* + * We know this guy from before? + */ + + w = lws_netdev_wifi_scan_find(wnd, (const char *)ar->ssid, + ar->bssid); + if (!w) { + w = lws_zalloc(sizeof(*w) + m + 1, __func__); + if (!w) + goto next; + + w->ssid = (char *)&w[1]; + memcpy(w->ssid, ar->ssid, m + 1); + w->ssid_len = m; + + memcpy(w->bssid, ar->bssid, 6); + + lws_dll2_add_sorted(&w->list, &wnd->scan, + lws_netdev_wifi_rssi_sort_compare); + } + + if (w->rssi_count == LWS_ARRAY_SIZE(w->rssi)) + w->rssi_avg -= w->rssi[w->rssi_next]; + else + w->rssi_count++; + w->rssi[w->rssi_next] = ar->rssi; + w->rssi_avg += w->rssi[w->rssi_next++]; + w->rssi_next = w->rssi_next & (LWS_ARRAY_SIZE(w->rssi) - 1); + + w->ch = ar->primary; + w->authmode = ar->authmode; + w->last_seen = now; + +next: + ar++; + } + + /* + * We can do the rest of it using the generic scan list and credentials + */ + + lws_netdev_wifi_scan_select(wnd); +} + +static wifi_scan_config_t scan_config = { + .ssid = 0, + .bssid = 0, + .channel = 0, + .show_hidden = true +}; + +void +lws_netdev_wifi_scan_plat(lws_netdev_instance_t *nd) +{ + lws_netdev_instance_wifi_t *wnd = (lws_netdev_instance_wifi_t *)nd; + + if (esp_wifi_scan_start(&scan_config, false)) + lwsl_err("%s: %s scan failed\n", __func__, wnd->inst.name); +} + +/* + * Platform-private interface events turn up here after going through SMD and + * passed down by matching network interface name via generic lws_netdev. All + * that messing around gets us from an OS-specific thread with an event to back + * here in lws event loop thread context, with the same event bound to a the + * netdev it belongs to. + */ + +int +lws_netdev_wifi_event_plat(struct lws_netdev_instance *nd, lws_usec_t timestamp, + void *buf, size_t len) +{ + lws_netdev_instance_wifi_t *wnd = (lws_netdev_instance_wifi_t *)nd; + struct lws_context *ctx = netdev_instance_to_ctx(&wnd->inst); + size_t al; + + /* + * netdev-private sync messages? + */ + + if (!lws_json_simple_strcmp(buf, len, "\"type\":", "priv")) { + const char *ev = lws_json_simple_find(buf, len, "\"ev\":", &al); + + if (!ev) + return 0; + + lwsl_notice("%s: smd priv ev %.*s\n", __func__, (int)al, ev); + + switch (atoi(ev)) { + case WIFI_EVENT_STA_START: + wnd->state = LWSNDVWIFI_STATE_INITIAL; + if (!lws_netdev_wifi_redo_last(wnd)) + break; + + /* + * if the "try last successful" one fails, start the + * scan by falling through + */ + + case WIFI_EVENT_STA_DISCONNECTED: + lws_smd_msg_printf(ctx, LWSSMDCL_NETWORK, + "{\"type\":\"linkdown\"," + "\"if\":\"%s\"}", wnd->inst.name); + wnd->state = LWSNDVWIFI_STATE_SCAN; + /* + * We do it via the sul so we don't get timed scans + * on top of each other + */ + lws_sul_schedule(ctx, 0, &wnd->sul_scan, + lws_netdev_wifi_scan, 1); + break; + + case WIFI_EVENT_STA_CONNECTED: + lws_smd_msg_printf(ctx, LWSSMDCL_NETWORK, + "{\"type\":\"linkup\"," + "\"if\":\"%s\"}", wnd->inst.name); + break; + + case WIFI_EVENT_SCAN_DONE: + lws_esp32_scan_update(wnd); + break; + default: + return 0; + } + + return 0; + } + + return 0; +} + +/* + * This is coming from a thread context unrelated to lws... the first order is + * to turn these into lws_smd events synchronized on lws thread, since we want + * to change correspsonding lws netdev object states without locking. + */ + +static void +_event_handler_wifi(void *arg, esp_event_base_t event_base, int32_t event_id, + void *event_data) +{ + lws_netdev_instance_wifi_t *wnd = (lws_netdev_instance_wifi_t *)arg; + struct lws_context *ctx = netdev_instance_to_ctx(&wnd->inst); + + switch (event_id) { + case WIFI_EVENT_STA_START: + case WIFI_EVENT_STA_DISCONNECTED: + case WIFI_EVENT_SCAN_DONE: + case WIFI_EVENT_STA_CONNECTED: + /* + * These are events in the platform's private namespace, + * interpreted only by the lws_smd handler above, ** in the lws + * event thread context **. The point of this is to requeue the + * event in the lws thread context like a bottom-half. + * + * To save on registrations, the context's NETWORK smd + * participant passes messages to lws_netdev, who passes ones + * that have if matching the netdev name to that netdev's + * (*event) handler. + * + * The other handler may emit generic network state SMD events + * for other things to consume. + */ + + lws_smd_msg_printf(ctx, LWSSMDCL_NETWORK, + "{\"type\":\"priv\",\"if\":\"%s\",\"ev\":%d}", + wnd->inst.name, event_id); + break; + default: + return; + } +} + +#if 0 +static int +espip_to_sa46(lws_sockaddr46 *sa46, esp_ip_addr_t *eip) +{ + memset(sa46, 0, sizeof(sa46)); + + switch (eip->type) { + case ESP_IPADDR_TYPE_V4: + sa46->sa4.sin_family = AF_INET; + memcpy(sa46->sa4.sin_addr, &eip->u_addr.ip4.addr, ); + return; + case ESP_IPADDR_TYPE_V6: + } +} +#endif + +/* + * This is coming from a thread context unrelated to lws + */ + +static void +_event_handler_ip(void *arg, esp_event_base_t event_base, int32_t event_id, + void *event_data) +{ + lws_netdev_instance_wifi_t *wnd = (lws_netdev_instance_wifi_t *)arg; + lws_netdevs_t *netdevs = lws_netdevs_from_ndi(&wnd->inst); + struct lws_context *ctx = lws_context_from_netdevs(netdevs); + + if (event_id == IP_EVENT_STA_GOT_IP) { + ip_event_got_ip_t *e = (ip_event_got_ip_t *)event_data; + char ip[16]; +#if 0 + tcpip_adapter_dns_info_t e32ip; + + /* + * Since atm we get this via DHCP, presumably we can get ahold + * of related info set by the router + */ + + if (tcpip_adapter_get_dns_info(TCPIP_ADAPTER_IF_STA, + TCPIP_ADAPTER_DNS_MAIN, + /* also _BACKUP, _FALLBACK */ + &e32ip)) { + lwsl_err("%s: there's no dns server set\n", __func__); + e32ip.ip.u_addr.ipv4 = 0x08080808; + e32ip.ip.type = ESP_IPADDR_TYPE_V4; + } + + netdevs->sa46_dns_resolver. +#endif + + lws_write_numeric_address((void *)&e->ip_info.ip, 4, ip, + sizeof(ip)); + lws_smd_msg_printf(ctx, LWSSMDCL_NETWORK, + "{\"type\":\"ipacq\",\"if\":\"%s\"," + "\"ipv4\":\"%s\"}", wnd->inst.name, ip); + } +} + +/* + * This is the platform (esp-idf) init for any kind of networking to be + * available at all + */ +int +lws_netdev_plat_init(void) +{ + nvs_flash_init(); + esp_netif_init(); + ESP_ERROR_CHECK(esp_event_loop_create_default()); + + return 0; +} + +/* + * This is the platform (esp-idf) init for any wifi to be available at all + */ +int +lws_netdev_plat_wifi_init(void) +{ + wifi_init_config_t wic = WIFI_INIT_CONFIG_DEFAULT(); + int n; + + esp_netif_create_default_wifi_sta(); + + n = esp_wifi_init(&wic); + if (n) { + lwsl_err("%s: wifi init fail: %d\n", __func__, n); + return 1; + } + + return 0; +} + + +struct lws_netdev_instance * +lws_netdev_wifi_create_plat(struct lws_context *ctx, + const lws_netdev_ops_t *ops, + const char *name, void *platinfo) +{ + lws_netdev_instance_wifi_esp32_t *wnde32 = lws_zalloc( + sizeof(*wnde32), __func__); + + if (!wnde32) + return NULL; + + wnde32->wnd.inst.type = LWSNDTYP_WIFI; + lws_netdev_instance_create(&wnde32->wnd.inst, ctx, ops, name, platinfo); + + return &wnde32->wnd.inst; +} + +int +lws_netdev_wifi_configure_plat(struct lws_netdev_instance *nd, + lws_netdev_config_t *config) +{ + return 0; +} + +int +lws_netdev_wifi_up_plat(struct lws_netdev_instance *nd) +{ + lws_netdev_instance_wifi_esp32_t *wnde32 = + (lws_netdev_instance_wifi_esp32_t *)nd; + struct lws_context *ctx = netdev_instance_to_ctx(&wnde32->wnd.inst); + + if (wnde32->wnd.flags & LNDIW_UP) + return 0; + + ESP_ERROR_CHECK(esp_event_handler_instance_register(IP_EVENT, + IP_EVENT_STA_GOT_IP, &_event_handler_ip, nd, + &wnde32->instance_got_ip)); + + ESP_ERROR_CHECK(esp_event_handler_instance_register(WIFI_EVENT, + ESP_EVENT_ANY_ID, &_event_handler_wifi, nd, + &wnde32->instance_any_id)); + + esp_wifi_start(); + wnde32->wnd.flags |= LNDIW_UP; + + lws_smd_msg_printf(ctx, LWSSMDCL_NETWORK, + "{\"type\":\"up\",\"if\":\"%s\"}", + wnde32->wnd.inst.name); + + return 0; +} + +int +lws_netdev_wifi_down_plat(struct lws_netdev_instance *nd) +{ + lws_netdev_instance_wifi_esp32_t *wnde32 = + (lws_netdev_instance_wifi_esp32_t *)nd; + struct lws_context *ctx = netdev_instance_to_ctx(&wnde32->wnd.inst); + + if (!(wnde32->wnd.flags & LNDIW_UP)) + return 0; + + lws_smd_msg_printf(ctx, LWSSMDCL_NETWORK, + "{\"type\":\"down\",\"if\":\"%s\"}", + wnde32->wnd.inst.name); + + esp_wifi_stop(); + + esp_event_handler_instance_unregister(IP_EVENT, IP_EVENT_STA_GOT_IP, + &wnde32->instance_got_ip); + esp_event_handler_instance_unregister(WIFI_EVENT, ESP_EVENT_ANY_ID, + &wnde32->instance_any_id); + + wnde32->wnd.flags &= ~LNDIW_UP; + + return 0; +} + +void +lws_netdev_wifi_destroy_plat(struct lws_netdev_instance **pnd) +{ + lws_free(*pnd); + *pnd = NULL; +} diff -Nru libwebsockets-3.2.1/lib/plat/freertos/esp32/drivers/pwm-esp32.c libwebsockets-4.1.6/lib/plat/freertos/esp32/drivers/pwm-esp32.c --- libwebsockets-3.2.1/lib/plat/freertos/esp32/drivers/pwm-esp32.c 1970-01-01 00:00:00.000000000 +0000 +++ libwebsockets-4.1.6/lib/plat/freertos/esp32/drivers/pwm-esp32.c 2020-12-01 17:40:26.000000000 +0000 @@ -0,0 +1,80 @@ +/* + * esp32 / esp-idf pwm + * + * Copyright (C) 2019 - 2020 Andy Green + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to + * deal in the Software without restriction, including without limitation the + * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or + * sell copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS + * IN THE SOFTWARE. + */ + +#include "private-lib-core.h" +#include "soc/ledc_reg.h" +#include "driver/ledc.h" + +static const ledc_timer_config_t tc = { + .speed_mode = LEDC_HIGH_SPEED_MODE, + .duty_resolution = LEDC_TIMER_13_BIT, + .timer_num = LEDC_TIMER_0, + .freq_hz = 5000, + .clk_cfg = LEDC_AUTO_CLK +}; + +int +lws_pwm_plat_init(const struct lws_pwm_ops *lo) +{ + ledc_channel_config_t lc = { + .duty = 8191, + .intr_type = LEDC_INTR_FADE_END, + .speed_mode = LEDC_HIGH_SPEED_MODE, + .timer_sel = LEDC_TIMER_0, + }; + size_t n; + + ledc_timer_config(&tc); + + for (n = 0; n < lo->count_pwm_map; n++) { + lc.channel = LEDC_CHANNEL_0 + lo->pwm_map[n].index; + lc.gpio_num = lo->pwm_map[n].gpio; + ledc_channel_config(&lc); + ledc_set_duty(LEDC_HIGH_SPEED_MODE, lc.channel, 0); + ledc_update_duty(LEDC_HIGH_SPEED_MODE, lc.channel); + } + + return 0; +} + +void +lws_pwm_plat_intensity(const struct lws_pwm_ops *lo, _lws_plat_gpio_t gpio, + lws_led_intensity_t inten) +{ + size_t n; + + for (n = 0; n < lo->count_pwm_map; n++) { + if (lo->pwm_map[n].gpio == gpio) { + if (!lo->pwm_map[n].active_level) + inten = 65535 - inten; + ledc_set_duty(LEDC_HIGH_SPEED_MODE, LEDC_CHANNEL_0 + + lo->pwm_map[n].index, inten >> 3); + ledc_update_duty(LEDC_HIGH_SPEED_MODE, LEDC_CHANNEL_0 + + lo->pwm_map[n].index); + return; + } + } + + lwsl_err("%s: unknown gpio for pwm\n", __func__); +} diff -Nru libwebsockets-3.2.1/lib/plat/freertos/esp32/drivers/settings-esp32.c libwebsockets-4.1.6/lib/plat/freertos/esp32/drivers/settings-esp32.c --- libwebsockets-3.2.1/lib/plat/freertos/esp32/drivers/settings-esp32.c 1970-01-01 00:00:00.000000000 +0000 +++ libwebsockets-4.1.6/lib/plat/freertos/esp32/drivers/settings-esp32.c 2020-12-01 17:40:26.000000000 +0000 @@ -0,0 +1,75 @@ +/* + * esp32 / esp-idf NV settings shim + * + * Copyright (C) 2019 - 2020 Andy Green + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to + * deal in the Software without restriction, including without limitation the + * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or + * sell copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS + * IN THE SOFTWARE. + */ + +#include + +#include + +int +lws_settings_plat_get(lws_settings_instance_t *si, const char *name, + uint8_t *dest, size_t *max_actual) +{ + int n; + + n = nvs_flash_init_partition((const char *)si->opaque_plat); + + lwsl_notice("%s: init partition %d\n", __func__, n); + if (n == ESP_ERR_NOT_FOUND) + return 1; + + if (nvs_open_from_partition((const char *)si->opaque_plat, + "_lws_settings", NVS_READONLY, + (nvs_handle_t *)&si->handle_plat)) + return 1; + + n = nvs_get_blob((nvs_handle_t)si->handle_plat, + name, dest, max_actual); + + nvs_close((nvs_handle_t)si->handle_plat); + + return !!n; +} + +int +lws_settings_plat_set(lws_settings_instance_t *si, const char *name, + const uint8_t *src, size_t len) +{ + int n = nvs_flash_init_partition((const char *)si->opaque_plat); + + lwsl_notice("%s: init partition %d\n", __func__, n); + if (n == ESP_ERR_NOT_FOUND) + return 1; + + if (nvs_open_from_partition((const char *)si->opaque_plat, + "_lws_settings", NVS_READWRITE, + (nvs_handle_t *)&si->handle_plat)) + return 1; + + n = nvs_set_blob((nvs_handle_t)si->handle_plat, name, src, len); + + nvs_commit((nvs_handle_t)si->handle_plat); + nvs_close((nvs_handle_t)si->handle_plat); + + return 0; +} diff -Nru libwebsockets-3.2.1/lib/plat/freertos/esp32/esp_attr.h libwebsockets-4.1.6/lib/plat/freertos/esp32/esp_attr.h --- libwebsockets-3.2.1/lib/plat/freertos/esp32/esp_attr.h 1970-01-01 00:00:00.000000000 +0000 +++ libwebsockets-4.1.6/lib/plat/freertos/esp32/esp_attr.h 2020-12-01 17:40:26.000000000 +0000 @@ -0,0 +1,58 @@ +// Copyright 2015-2016 Espressif Systems (Shanghai) PTE LTD +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at + +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +#ifndef __ESP_ATTR_H__ +#define __ESP_ATTR_H__ + +#define ROMFN_ATTR + +//Normally, the linker script will put all code and rodata in flash, +//and all variables in shared RAM. These macros can be used to redirect +//particular functions/variables to other memory regions. + +// Forces code into IRAM instead of flash. +#define IRAM_ATTR __attribute__((section(".iram1"))) + +// Forces data into DRAM instead of flash +#define DRAM_ATTR __attribute__((section(".dram1"))) + +// Forces data to be 4 bytes aligned +#define WORD_ALIGNED_ATTR __attribute__((aligned(4))) + +// Forces data to be placed to DMA-capable places +#define DMA_ATTR WORD_ALIGNED_ATTR DRAM_ATTR + +// Forces a string into DRAM instead of flash +// Use as ets_printf(DRAM_STR("Hello world!\n")); +#define DRAM_STR(str) (__extension__({static const DRAM_ATTR char __c[] = (str); (const char *)&__c;})) + +// Forces code into RTC fast memory. See "docs/deep-sleep-stub.rst" +#define RTC_IRAM_ATTR __attribute__((section(".rtc.text"))) + +// Forces data into RTC slow memory. See "docs/deep-sleep-stub.rst" +// Any variable marked with this attribute will keep its value +// during a deep sleep / wake cycle. +#define RTC_DATA_ATTR __attribute__((section(".rtc.data"))) + +// Forces read-only data into RTC slow memory. See "docs/deep-sleep-stub.rst" +#define RTC_RODATA_ATTR __attribute__((section(".rtc.rodata"))) + +// Forces data into noinit section to avoid initialization after restart. +#define __NOINIT_ATTR __attribute__((section(".noinit"))) + +// Forces data into RTC slow memory of .noinit section. +// Any variable marked with this attribute will keep its value +// after restart or during a deep sleep / wake cycle. +#define RTC_NOINIT_ATTR __attribute__((section(".rtc_noinit"))) + +#endif /* __ESP_ATTR_H__ */ diff -Nru libwebsockets-3.2.1/lib/plat/freertos/freertos-fds.c libwebsockets-4.1.6/lib/plat/freertos/freertos-fds.c --- libwebsockets-3.2.1/lib/plat/freertos/freertos-fds.c 1970-01-01 00:00:00.000000000 +0000 +++ libwebsockets-4.1.6/lib/plat/freertos/freertos-fds.c 2020-12-01 17:40:26.000000000 +0000 @@ -0,0 +1,61 @@ +/* + * libwebsockets - small server side websockets and web server implementation + * + * Copyright (C) 2010 - 2019 Andy Green + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to + * deal in the Software without restriction, including without limitation the + * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or + * sell copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS + * IN THE SOFTWARE. + */ + +#include "private-lib-core.h" + +void +lws_plat_insert_socket_into_fds(struct lws_context *context, struct lws *wsi) +{ + struct lws_context_per_thread *pt = &context->pt[(int)wsi->tsi]; + + pt->fds[pt->fds_count++].revents = 0; +} + +void +lws_plat_delete_socket_from_fds(struct lws_context *context, + struct lws *wsi, int m) +{ + struct lws_context_per_thread *pt = &context->pt[(int)wsi->tsi]; + + pt->fds_count--; +} + +int +lws_plat_change_pollfd(struct lws_context *context, + struct lws *wsi, struct lws_pollfd *pfd) +{ + return 0; +} + +int +insert_wsi(const struct lws_context *context, struct lws *wsi) +{ + assert(context->lws_lookup[wsi->desc.sockfd - + lws_plat_socket_offset()] == 0); + + context->lws_lookup[wsi->desc.sockfd - \ + lws_plat_socket_offset()] = wsi; + + return 0; +} diff -Nru libwebsockets-3.2.1/lib/plat/freertos/freertos-file.c libwebsockets-4.1.6/lib/plat/freertos/freertos-file.c --- libwebsockets-3.2.1/lib/plat/freertos/freertos-file.c 1970-01-01 00:00:00.000000000 +0000 +++ libwebsockets-4.1.6/lib/plat/freertos/freertos-file.c 2020-12-01 17:40:26.000000000 +0000 @@ -0,0 +1,226 @@ +/* + * libwebsockets - small server side websockets and web server implementation + * + * Copyright (C) 2010 - 2019 Andy Green + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to + * deal in the Software without restriction, including without limitation the + * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or + * sell copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS + * IN THE SOFTWARE. + */ + +#include "private-lib-core.h" + +int lws_plat_apply_FD_CLOEXEC(int n) +{ + return 0; +} + + +lws_fop_fd_t IRAM_ATTR +_lws_plat_file_open(const struct lws_plat_file_ops *fops, const char *filename, + const char *vpath, lws_fop_flags_t *flags) +{ + struct stat stat_buf; + lws_fop_fd_t fop_fd; + int ret = open(filename, *flags, 0664); + + if (ret < 0) + return NULL; + + if (fstat(ret, &stat_buf) < 0) + goto bail; + + fop_fd = lws_malloc(sizeof(*fop_fd), "fops open"); + if (!fop_fd) + goto bail; + + fop_fd->fops = fops; + fop_fd->fd = ret; + fop_fd->flags = *flags; + fop_fd->filesystem_priv = NULL; /* we don't use it */ + fop_fd->pos = 0; + fop_fd->len = stat_buf.st_size; + + return fop_fd; + +bail: + close(ret); + + return NULL; +} + +int IRAM_ATTR +_lws_plat_file_close(lws_fop_fd_t *fops_fd) +{ + int fd = (*fops_fd)->fd; + + lws_free(*fops_fd); + *fops_fd = NULL; + + return close(fd); +} + +lws_fileofs_t IRAM_ATTR +_lws_plat_file_seek_cur(lws_fop_fd_t fops_fd, lws_fileofs_t offset) +{ + return lseek(fops_fd->fd, offset, SEEK_CUR); +} + +int IRAM_ATTR +_lws_plat_file_read(lws_fop_fd_t fops_fd, lws_filepos_t *amount, + uint8_t *buf, lws_filepos_t len) +{ + long n; + + n = read(fops_fd->fd, buf, len); + if (n == -1) { + *amount = 0; + return -1; + } + fops_fd->pos += n; + *amount = n; + + return 0; +} + +int IRAM_ATTR +_lws_plat_file_write(lws_fop_fd_t fops_fd, lws_filepos_t *amount, + uint8_t *buf, lws_filepos_t len) +{ + long n; + + n = write(fops_fd->fd, buf, len); + if (n == -1) { + *amount = 0; + return -1; + } + fops_fd->pos += n; + *amount = n; + + return 0; +} + +#if defined(LWS_AMAZON_RTOS) +int +lws_find_string_in_file(const char *filename, const char *string, int stringlen) +{ + return 0; +} +#else +int +lws_find_string_in_file(const char *filename, const char *string, int stringlen) +{ + nvs_handle nvh; + size_t s; + int n; + char buf[64], result[64]; + const char *p = strchr(string, ':'), *q; + + if (!p) + return 0; + + q = string; + n = 0; + while ((size_t)n < sizeof(buf) - 1 && q != p) + buf[n++] = *q++; + buf[n] = '\0'; + + ESP_ERROR_CHECK(nvs_open(filename, NVS_READWRITE, &nvh)); + + s = sizeof(result) - 1; + n = nvs_get_str(nvh, buf, result, &s); + nvs_close(nvh); + + if (n != ESP_OK) + return 0; + + return !strcmp(p + 1, result); +} +#endif + +#if !defined(LWS_AMAZON_RTOS) +int +lws_plat_write_file(const char *filename, void *buf, int len) +{ + nvs_handle nvh; + int n; + + if (nvs_open("lws-station", NVS_READWRITE, &nvh)) { + lwsl_notice("%s: failed to open nvs\n", __func__); + return -1; + } + + n = nvs_set_blob(nvh, filename, buf, len); + if (n >= 0) + nvs_commit(nvh); + + nvs_close(nvh); + + lwsl_notice("%s: wrote %s (%d)\n", __func__, filename, n); + + return n; +} + +/* we write vhostname.cert.pem and vhostname.key.pem, 0 return means OK */ + +int +lws_plat_write_cert(struct lws_vhost *vhost, int is_key, int fd, void *buf, + int len) +{ + const char *name = vhost->tls.alloc_cert_path; + + if (is_key) + name = vhost->tls.key_path; + + return lws_plat_write_file(name, buf, len) < 0; +} + +int +lws_plat_read_file(const char *filename, void *buf, int len) +{ + nvs_handle nvh; + size_t s = 0; + int n = 0; + + if (nvs_open("lws-station", NVS_READWRITE, &nvh)) { + lwsl_notice("%s: failed to open nvs\n", __func__); + return 1; + } + + ESP_ERROR_CHECK(nvs_open("lws-station", NVS_READWRITE, &nvh)); + if (nvs_get_blob(nvh, filename, NULL, &s) != ESP_OK) + goto bail; + if (s > (size_t)len) + goto bail; + + n = nvs_get_blob(nvh, filename, buf, &s); + + nvs_close(nvh); + + lwsl_notice("%s: read %s (%d)\n", __func__, filename, (int)s); + + if (n) + return -1; + + return (int)s; + +bail: + nvs_close(nvh); + + return -1; +} +#endif /* LWS_AMAZON_RTOS */ diff -Nru libwebsockets-3.2.1/lib/plat/freertos/freertos-init.c libwebsockets-4.1.6/lib/plat/freertos/freertos-init.c --- libwebsockets-3.2.1/lib/plat/freertos/freertos-init.c 1970-01-01 00:00:00.000000000 +0000 +++ libwebsockets-4.1.6/lib/plat/freertos/freertos-init.c 2020-12-01 17:40:26.000000000 +0000 @@ -0,0 +1,119 @@ +/* + * libwebsockets - small server side websockets and web server implementation + * + * Copyright (C) 2010 - 2019 Andy Green + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to + * deal in the Software without restriction, including without limitation the + * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or + * sell copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS + * IN THE SOFTWARE. + */ + +#include "private-lib-core.h" + +int +lws_plat_context_early_init(void) +{ + return 0; +} + +void +lws_plat_context_early_destroy(struct lws_context *context) +{ +#if defined(LWS_AMAZON_RTOS) && defined(LWS_WITH_MBEDTLS) + mbedtls_ctr_drbg_free(&context->mcdc); + mbedtls_entropy_free(&context->mec); +#endif +} + +void +lws_plat_context_late_destroy(struct lws_context *context) +{ +#ifdef LWS_WITH_PLUGINS + if (context->plugin_list) + lws_plat_plugins_destroy(context); +#endif + + if (context->lws_lookup) + lws_free(context->lws_lookup); +} + +#if defined(LWS_WITH_HTTP2) +/* + * These are the default SETTINGS used on this platform. The user + * can selectively modify them for a vhost during vhost creation. + */ +const struct http2_settings lws_h2_defaults_esp32 = { { + 1, + /* H2SET_HEADER_TABLE_SIZE */ 512, + /* H2SET_ENABLE_PUSH */ 0, + /* H2SET_MAX_CONCURRENT_STREAMS */ 8, + /* H2SET_INITIAL_WINDOW_SIZE */ 0, + /* H2SET_MAX_FRAME_SIZE */ 16384, + /* H2SET_MAX_HEADER_LIST_SIZE */ 512, + /* H2SET_RESERVED7 */ 0, + /* H2SET_ENABLE_CONNECT_PROTOCOL */ 1, +}}; +#endif + +int +lws_plat_init(struct lws_context *context, + const struct lws_context_creation_info *info) +{ +#if defined(LWS_AMAZON_RTOS) && defined(LWS_WITH_MBEDTLS) + int n; + + /* initialize platform random through mbedtls */ + mbedtls_entropy_init(&context->mec); + mbedtls_ctr_drbg_init(&context->mcdc); + + n = mbedtls_ctr_drbg_seed(&context->mcdc, mbedtls_entropy_func, + &context->mec, NULL, 0); + if (n) { + lwsl_err("%s: mbedtls_ctr_drbg_seed() returned 0x%x\n", + __func__, n); + + return 1; + } +#endif + + /* master context has the global fd lookup array */ + context->lws_lookup = lws_zalloc(sizeof(struct lws *) * + context->max_fds, "esp32 lws_lookup"); + if (context->lws_lookup == NULL) { + lwsl_err("OOM on lws_lookup array for %d connections\n", + context->max_fds); + return 1; + } + + lwsl_notice(" mem: platform fd map: %5lu bytes\n", + (unsigned long)(sizeof(struct lws *) * context->max_fds)); + +#ifdef LWS_WITH_PLUGINS + if (info->plugin_dirs) + lws_plat_plugins_init(context, info->plugin_dirs); +#endif +#if defined(LWS_WITH_HTTP2) + /* override settings */ + context->set = lws_h2_defaults_esp32; +#endif + +#if defined(LWS_ESP_PLATFORM) + gpio_install_isr_service(0); +#endif + + return 0; +} diff -Nru libwebsockets-3.2.1/lib/plat/freertos/freertos-misc.c libwebsockets-4.1.6/lib/plat/freertos/freertos-misc.c --- libwebsockets-3.2.1/lib/plat/freertos/freertos-misc.c 1970-01-01 00:00:00.000000000 +0000 +++ libwebsockets-4.1.6/lib/plat/freertos/freertos-misc.c 2020-12-01 17:40:26.000000000 +0000 @@ -0,0 +1,104 @@ +/* + * libwebsockets - small server side websockets and web server implementation + * + * Copyright (C) 2010 - 2019 Andy Green + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to + * deal in the Software without restriction, including without limitation the + * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or + * sell copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS + * IN THE SOFTWARE. + */ + +#include "private-lib-core.h" + +/* + * Normally you don't want this, use lws_sul instead inside the event loop. + * But sometimes for drivers it makes sense, so there's an internal-only + * crossplatform api for it. + */ + +void +lws_msleep(unsigned int ms) +{ + vTaskDelay(portTICK_PERIOD_MS > ms ? 1 : ms / portTICK_PERIOD_MS); +} + +lws_usec_t +lws_now_usecs(void) +{ + struct timeval tv; + gettimeofday(&tv, NULL); + return ((unsigned long long)tv.tv_sec * 1000000LL) + tv.tv_usec; +} + +size_t +lws_get_random(struct lws_context *context, void *buf, size_t len) +{ +#if defined(LWS_WITH_ESP32) + uint8_t *pb = buf; + + while (len) { + uint32_t r = esp_random(); + uint8_t *p = (uint8_t *)&r; + int b = 4; + + if (len < (size_t)b) + b = len; + + len -= b; + + while (b--) + *pb++ = p[b]; + } + + return pb - (uint8_t *)buf; +#else +#if defined(LWS_WITH_MBEDTLS) + int n; + + n = mbedtls_ctr_drbg_random(&context->mcdc, buf, len); + if (!n) + return len; + + /* failed */ + + lwsl_err("%s: mbedtls_ctr_drbg_random returned 0x%x\n", __func__, n); +#endif + return 0; +#endif +} + + +void lwsl_emit_syslog(int level, const char *line) +{ + lwsl_emit_stderr(level, line); +} + +int +lws_plat_drop_app_privileges(struct lws_context *context, int actually_init) +{ + return 0; +} + +int +lws_plat_recommended_rsa_bits(void) +{ + /* + * 2048-bit key generation takes up to a minute on ESP32, 4096 + * is like 15 minutes + + */ + return 2048; +} diff -Nru libwebsockets-3.2.1/lib/plat/freertos/freertos-pipe.c libwebsockets-4.1.6/lib/plat/freertos/freertos-pipe.c --- libwebsockets-3.2.1/lib/plat/freertos/freertos-pipe.c 1970-01-01 00:00:00.000000000 +0000 +++ libwebsockets-4.1.6/lib/plat/freertos/freertos-pipe.c 2020-12-01 17:40:26.000000000 +0000 @@ -0,0 +1,126 @@ +/* + * libwebsockets - small server side websockets and web server implementation + * + * Copyright (C) 2010 - 2020 Andy Green + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to + * deal in the Software without restriction, including without limitation the + * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or + * sell copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS + * IN THE SOFTWARE. + */ + +#include "private-lib-core.h" + +int +lws_plat_pipe_create(struct lws *wsi) +{ + struct lws_context_per_thread *pt = &wsi->a.context->pt[(int)wsi->tsi]; + struct sockaddr_in *si = &wsi->a.context->frt_pipe_si; + lws_sockfd_type *fd = pt->dummy_pipe_fds; + socklen_t sl; + + /* + * There's no pipe abstraction on lwip / freertos... use a UDP socket + * listening on 127.0.0.1:xxxx and send a byte to it from a second UDP + * socket to cancel the wait. + * + * Set the port to 0 at the bind, so lwip will choose a free one in the + * ephemeral range for us. + */ + + fd[0] = socket(AF_INET, SOCK_DGRAM, 0); + if (fd[0] < 0) + goto bail; + + fd[1] = socket(AF_INET, SOCK_DGRAM, 0); + if (fd[1] < 0) + goto bail; + + /* + * No need for memset since it's in zalloc'd context... it's in the + * context so we can reuse the prepared sockaddr to send tp fd[0] whem + * we want to cancel the wait + */ + + si->sin_family = AF_INET; + si->sin_addr.s_addr = htonl(INADDR_LOOPBACK); + si->sin_port = 0; + + if (bind(fd[0], (const struct sockaddr *)si, sizeof(*si)) < 0) + goto bail; + + /* + * Query the socket to set context->frt_pipe_si to the full sockaddr it + * wants to be addressed by, including the port that lwip chose. + * + * Afterwards, we can use this prepared sockaddr stashed in the context + * to trigger the "pipe" without any other preliminaries. + */ + + sl = sizeof(*si); + if (getsockname(fd[0], (struct sockaddr *)si, &sl)) + goto bail; + + lwsl_info("%s: cancel UDP skt port %d\n", __func__, + ntohs(si->sin_port)); + + return 0; + +bail: + lwsl_err("%s: failed\n", __func__); + + return 1; +} + +int +lws_plat_pipe_signal(struct lws *wsi) +{ + struct lws_context_per_thread *pt = &wsi->a.context->pt[(int)wsi->tsi]; + struct sockaddr_in *si = &wsi->a.context->frt_pipe_si; + lws_sockfd_type *fd = pt->dummy_pipe_fds; + uint8_t u = 0; + int n; + + /* + * Send a single UDP byte payload to the listening socket fd[0], forcing + * the event loop wait to wake. fd[1] and context->frt_pipe_si are + * set at context creation and are static, the UDP sendto is supposed to + * be threadsafe for lwip: + * + * https://lwip.fandom.com/wiki/LwIP_and_multithreading + * + * Sockets generally can't be used by more than one application thread + * (on udp/raw netconn, doing a sendto/recv is currently possible). + */ + + n = sendto(fd[1], &u, 1, 0, (struct sockaddr *)si, sizeof(*si)); + + return n != 1; +} + +void +lws_plat_pipe_close(struct lws *wsi) +{ + struct lws_context_per_thread *pt = &wsi->a.context->pt[(int)wsi->tsi]; + lws_sockfd_type *fd = pt->dummy_pipe_fds; + + if (fd[0] && fd[0] != -1) + close(fd[0]); + if (fd[1] && fd[1] != -1) + close(fd[1]); + + fd[0] = fd[1] = -1; +} diff -Nru libwebsockets-3.2.1/lib/plat/freertos/freertos-resolv.c libwebsockets-4.1.6/lib/plat/freertos/freertos-resolv.c --- libwebsockets-3.2.1/lib/plat/freertos/freertos-resolv.c 1970-01-01 00:00:00.000000000 +0000 +++ libwebsockets-4.1.6/lib/plat/freertos/freertos-resolv.c 2020-12-01 17:40:26.000000000 +0000 @@ -0,0 +1,54 @@ +/* + * libwebsockets - small server side websockets and web server implementation + * + * Copyright (C) 2010 - 2019 Andy Green + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to + * deal in the Software without restriction, including without limitation the + * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or + * sell copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS + * IN THE SOFTWARE. + */ + +#include "private-lib-core.h" + +#if defined(LWS_WITH_SYS_ASYNC_DNS) +lws_async_dns_server_check_t +lws_plat_asyncdns_init(struct lws_context *context, lws_sockaddr46 *sa46) +{ + uint32_t ipv4; + lws_async_dns_server_check_t s = LADNS_CONF_SERVER_CHANGED; + + FreeRTOS_GetAddressConfiguration(NULL, NULL, NULL, &ipv4); + + sa46->sa4.sin_family = AF_INET; + if (sa46->sa4.sin_addr.s_addr == ipv4) + s = LADNS_CONF_SERVER_SAME; + + sa46->sa4.sin_addr.s_addr = ipv4; + + return s; +} +#endif + +int +lws_plat_ntpclient_config(struct lws_context *context) +{ + lws_system_blob_heap_append(lws_system_get_blob(context, + LWS_SYSBLOB_TYPE_NTP_SERVER, 0), + (const uint8_t *)"pool.ntp.org", 12); + + return 0; +} diff -Nru libwebsockets-3.2.1/lib/plat/freertos/freertos-service.c libwebsockets-4.1.6/lib/plat/freertos/freertos-service.c --- libwebsockets-3.2.1/lib/plat/freertos/freertos-service.c 1970-01-01 00:00:00.000000000 +0000 +++ libwebsockets-4.1.6/lib/plat/freertos/freertos-service.c 2020-12-01 17:40:26.000000000 +0000 @@ -0,0 +1,221 @@ +/* + * libwebsockets - small server side websockets and web server implementation + * + * Copyright (C) 2010 - 2019 Andy Green + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to + * deal in the Software without restriction, including without limitation the + * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or + * sell copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS + * IN THE SOFTWARE. + */ + +#include "private-lib-core.h" + +int +lws_plat_service(struct lws_context *context, int timeout_ms) +{ + int n = _lws_plat_service_tsi(context, timeout_ms, 0); + +#if !defined(LWS_AMAZON_RTOS) + esp_task_wdt_reset(); +#endif + + return n; +} + + +int +_lws_plat_service_tsi(struct lws_context *context, int timeout_ms, int tsi) +{ + struct lws_context_per_thread *pt; + lws_usec_t timeout_us; + int n = -1, m, c, a = 0; + + /* stay dead once we are dead */ + + if (!context) + return 1; + + pt = &context->pt[tsi]; + lws_stats_bump(pt, LWSSTATS_C_SERVICE_ENTRY, 1); + + { + unsigned long m = lws_now_secs(); + + if (m > context->time_last_state_dump) { + context->time_last_state_dump = m; +#if defined(LWS_ESP_PLATFORM) + n = esp_get_free_heap_size(); +#else + n = xPortGetFreeHeapSize(); +#endif + if ((unsigned int)n != context->last_free_heap) { + if ((unsigned int)n > context->last_free_heap) + lwsl_debug(" heap :%ld (+%ld)\n", + (unsigned long)n, + (unsigned long)(n - + context->last_free_heap)); + else + lwsl_debug(" heap :%ld (-%ld)\n", + (unsigned long)n, + (unsigned long)( + context->last_free_heap - + n)); + context->last_free_heap = n; + } + } + } + + if (timeout_ms < 0) + timeout_ms = 0; + else + /* force a default timeout of 23 days */ + timeout_ms = 2000000000; + timeout_us = ((lws_usec_t)timeout_ms) * LWS_US_PER_MS; + + if (!pt->service_tid_detected && context->vhost_list) { + lws_fakewsi_def_plwsa(pt); + + lws_fakewsi_prep_plwsa_ctx(context); + + pt->service_tid = context->vhost_list->protocols[0].callback( + (struct lws *)plwsa, LWS_CALLBACK_GET_THREAD_ID, + NULL, NULL, 0); + pt->service_tid_detected = 1; + } + + /* + * is there anybody with pending stuff that needs service forcing? + */ + if (lws_service_adjust_timeout(context, 1, tsi)) { + +again: + a = 0; + if (timeout_us) { + lws_usec_t us; + + lws_pt_lock(pt, __func__); + /* don't stay in poll wait longer than next hr timeout */ + us = __lws_sul_service_ripe(pt->pt_sul_owner, + LWS_COUNT_PT_SUL_OWNERS, + lws_now_usecs()); + if (us && us < timeout_us) + timeout_us = us; + + lws_pt_unlock(pt); + } + + // n = poll(pt->fds, pt->fds_count, timeout_ms); + { + fd_set readfds, writefds, errfds; + struct timeval tv = { timeout_us / LWS_US_PER_SEC, + timeout_us % LWS_US_PER_SEC }, *ptv = &tv; + int max_fd = 0; + FD_ZERO(&readfds); + FD_ZERO(&writefds); + FD_ZERO(&errfds); + + for (n = 0; n < (int)pt->fds_count; n++) { + pt->fds[n].revents = 0; + if (pt->fds[n].fd >= max_fd) + max_fd = pt->fds[n].fd; + if (pt->fds[n].events & LWS_POLLIN) + FD_SET(pt->fds[n].fd, &readfds); + if (pt->fds[n].events & LWS_POLLOUT) + FD_SET(pt->fds[n].fd, &writefds); + FD_SET(pt->fds[n].fd, &errfds); + } + + n = select(max_fd + 1, &readfds, &writefds, &errfds, ptv); + n = 0; + + #if defined(LWS_WITH_DETAILED_LATENCY) + /* + * so we can track how long it took before we actually read a POLLIN + * that was signalled when we last exited poll() + */ + if (context->detailed_latency_cb) + pt->ust_left_poll = lws_now_usecs(); + #endif + + for (m = 0; m < (int)pt->fds_count; m++) { + c = 0; + if (FD_ISSET(pt->fds[m].fd, &readfds)) { + pt->fds[m].revents |= LWS_POLLIN; + c = 1; + } + if (FD_ISSET(pt->fds[m].fd, &writefds)) { + pt->fds[m].revents |= LWS_POLLOUT; + c = 1; + } + if (FD_ISSET(pt->fds[m].fd, &errfds)) { + // lwsl_notice("errfds %d\n", pt->fds[m].fd); + pt->fds[m].revents |= LWS_POLLHUP; + c = 1; + } + + if (c) + n++; + } + } + + m = 0; + + #if defined(LWS_ROLE_WS) && !defined(LWS_WITHOUT_EXTENSIONS) + m |= !!pt->ws.rx_draining_ext_list; + #endif + +#if defined(LWS_WITH_TLS) + if (pt->context->tls_ops && + pt->context->tls_ops->fake_POLLIN_for_buffered) + m |= pt->context->tls_ops->fake_POLLIN_for_buffered(pt); +#endif + if (!m && !n) + return 0; + } else + a = 1; + + m = lws_service_flag_pending(context, tsi); + if (m) + c = -1; /* unknown limit */ + else + if (n < 0) { + if (LWS_ERRNO != LWS_EINTR) + return -1; + return 0; + } else + c = n; + + /* any socket with events to service? */ + for (n = 0; n < (int)pt->fds_count && c; n++) { + if (!pt->fds[n].revents) + continue; + + c--; + + m = lws_service_fd_tsi(context, &pt->fds[n], tsi); + if (m < 0) + return -1; + /* if something closed, retry this slot */ + if (m) + n--; + } + + if (a) + goto again; + + return 0; +} diff -Nru libwebsockets-3.2.1/lib/plat/freertos/freertos-sockets.c libwebsockets-4.1.6/lib/plat/freertos/freertos-sockets.c --- libwebsockets-3.2.1/lib/plat/freertos/freertos-sockets.c 1970-01-01 00:00:00.000000000 +0000 +++ libwebsockets-4.1.6/lib/plat/freertos/freertos-sockets.c 2020-12-01 17:40:26.000000000 +0000 @@ -0,0 +1,322 @@ +/* + * libwebsockets - small server side websockets and web server implementation + * + * Copyright (C) 2010 - 2019 Andy Green + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to + * deal in the Software without restriction, including without limitation the + * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or + * sell copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS + * IN THE SOFTWARE. + */ + +#include "private-lib-core.h" +#include +#if defined(LWS_WITH_MBEDTLS) +#if defined(LWS_HAVE_MBEDTLS_NET_SOCKETS) +#include "mbedtls/net_sockets.h" +#else +#include "mbedtls/net.h" +#endif +#endif + +int +lws_send_pipe_choked(struct lws *wsi) +{ + struct lws *wsi_eff = wsi; + fd_set writefds; + struct timeval tv = { 0, 0 }; + int n; +#if defined(LWS_WITH_HTTP2) + wsi_eff = lws_get_network_wsi(wsi); +#endif + + /* the fact we checked implies we avoided back-to-back writes */ + wsi_eff->could_have_pending = 0; + + /* treat the fact we got a truncated send pending as if we're choked */ + if (lws_has_buffered_out(wsi) +#if defined(LWS_WITH_HTTP_STREAM_COMPRESSION) + || wsi->http.comp_ctx.buflist_comp || + wsi->http.comp_ctx.may_have_more +#endif + ) + return 1; + + FD_ZERO(&writefds); + FD_SET(wsi_eff->desc.sockfd, &writefds); + + n = select(wsi_eff->desc.sockfd + 1, NULL, &writefds, NULL, &tv); + if (n < 0) + return 1; /* choked */ + + return !n; /* n = 0 = not writable = choked */ +} + +int +lws_poll_listen_fd(struct lws_pollfd *fd) +{ + fd_set readfds; + struct timeval tv = { 0, 0 }; + + FD_ZERO(&readfds); + FD_SET(fd->fd, &readfds); + + return select(fd->fd + 1, &readfds, NULL, NULL, &tv); +} + +int +lws_plat_set_nonblocking(lws_sockfd_type fd) +{ + return fcntl(fd, F_SETFL, O_NONBLOCK) < 0; +} + +int +lws_plat_set_socket_options(struct lws_vhost *vhost, int fd, int unix_skt) +{ + int optval = 1; + socklen_t optlen = sizeof(optval); + +#if defined(__APPLE__) || \ + defined(__FreeBSD__) || defined(__FreeBSD_kernel__) || \ + defined(__NetBSD__) || \ + defined(__OpenBSD__) + struct protoent *tcp_proto; +#endif + + if (vhost->ka_time) { + /* enable keepalive on this socket */ + optval = 1; + if (setsockopt(fd, SOL_SOCKET, SO_KEEPALIVE, + (const void *)&optval, optlen) < 0) + return 1; + +#if defined(__APPLE__) || \ + defined(__FreeBSD__) || defined(__FreeBSD_kernel__) || \ + defined(__NetBSD__) || \ + defined(__CYGWIN__) || defined(__OpenBSD__) || defined (__sun) + + /* + * didn't find a way to set these per-socket, need to + * tune kernel systemwide values + */ +#else + /* set the keepalive conditions we want on it too */ + optval = vhost->ka_time; + if (setsockopt(fd, IPPROTO_TCP, TCP_KEEPIDLE, + (const void *)&optval, optlen) < 0) + return 1; + + optval = vhost->ka_interval; + if (setsockopt(fd, IPPROTO_TCP, TCP_KEEPINTVL, + (const void *)&optval, optlen) < 0) + return 1; + + optval = vhost->ka_probes; + if (setsockopt(fd, IPPROTO_TCP, TCP_KEEPCNT, + (const void *)&optval, optlen) < 0) + return 1; +#endif + } + + /* Disable Nagle */ + optval = 1; + if (setsockopt(fd, IPPROTO_TCP, TCP_NODELAY, &optval, optlen) < 0) + return 1; + + return lws_plat_set_nonblocking(fd); +} + +/* cast a struct sockaddr_in6 * into addr for ipv6 */ + +int +lws_interface_to_sa(int ipv6, const char *ifname, struct sockaddr_in *addr, + size_t addrlen) +{ +#if 0 + int rc = LWS_ITOSA_NOT_EXIST; + + struct ifaddrs *ifr; + struct ifaddrs *ifc; +#ifdef LWS_WITH_IPV6 + struct sockaddr_in6 *addr6 = (struct sockaddr_in6 *)addr; +#endif + + getifaddrs(&ifr); + for (ifc = ifr; ifc != NULL && rc; ifc = ifc->ifa_next) { + if (!ifc->ifa_addr) + continue; + + lwsl_info(" interface %s vs %s\n", ifc->ifa_name, ifname); + + if (strcmp(ifc->ifa_name, ifname)) + continue; + + switch (ifc->ifa_addr->sa_family) { + case AF_INET: +#ifdef LWS_WITH_IPV6 + if (ipv6) { + /* map IPv4 to IPv6 */ + memset((char *)&addr6->sin6_addr, 0, + sizeof(struct in6_addr)); + addr6->sin6_addr.s6_addr[10] = 0xff; + addr6->sin6_addr.s6_addr[11] = 0xff; + memcpy(&addr6->sin6_addr.s6_addr[12], + &((struct sockaddr_in *)ifc->ifa_addr)->sin_addr, + sizeof(struct in_addr)); + } else +#endif + memcpy(addr, + (struct sockaddr_in *)ifc->ifa_addr, + sizeof(struct sockaddr_in)); + break; +#ifdef LWS_WITH_IPV6 + case AF_INET6: + memcpy(&addr6->sin6_addr, + &((struct sockaddr_in6 *)ifc->ifa_addr)->sin6_addr, + sizeof(struct in6_addr)); + break; +#endif + default: + continue; + } + rc = LWS_ITOSA_USABLE; + } + + freeifaddrs(ifr); + + if (rc == LWS_ITOSA_NOT_EXIST) { + /* check if bind to IP address */ +#ifdef LWS_WITH_IPV6 + if (inet_pton(AF_INET6, ifname, &addr6->sin6_addr) == 1) + rc = LWS_ITOSA_USABLE; + else +#endif + if (inet_pton(AF_INET, ifname, &addr->sin_addr) == 1) + rc = LWS_ITOSA_USABLE; + } + + return rc; +#endif + + return LWS_ITOSA_NOT_EXIST; +} + +const char * +lws_plat_inet_ntop(int af, const void *src, char *dst, int cnt) +{ + return inet_ntop(af, src, dst, cnt); +} + +int +lws_plat_inet_pton(int af, const char *src, void *dst) +{ + return 1; // inet_pton(af, src, dst); +} + +int +lws_plat_ifname_to_hwaddr(int fd, const char *ifname, uint8_t *hwaddr, int len) +{ + lwsl_err("%s: UNIMPLEMENTED on this platform\n", __func__); + + return -1; +} + +int +lws_plat_rawudp_broadcast(uint8_t *p, const uint8_t *canned, int canned_len, + int n, int fd, const char *iface) +{ + lwsl_err("%s: UNIMPLEMENTED on this platform\n", __func__); + + return -1; +} + +int +lws_plat_if_up(const char *ifname, int fd, int up) +{ + lwsl_err("%s: UNIMPLEMENTED on this platform\n", __func__); + + return -1; +} + +int +lws_plat_BINDTODEVICE(lws_sockfd_type fd, const char *ifname) +{ + lwsl_err("%s: UNIMPLEMENTED on this platform\n", __func__); + + return -1; +} + +int +lws_plat_ifconfig_ip(const char *ifname, int fd, uint8_t *ip, uint8_t *mask_ip, + uint8_t *gateway_ip) +{ + lwsl_err("%s: UNIMPLEMENTED on this platform\n", __func__); + + return -1; +} + +#if defined(LWS_WITH_MBEDTLS) +int +lws_plat_mbedtls_net_send(void *ctx, const uint8_t *buf, size_t len) +{ + int fd = ((mbedtls_net_context *) ctx)->fd; + int ret; + + if (fd < 0) + return MBEDTLS_ERR_NET_INVALID_CONTEXT; + + ret = write(fd, buf, len); + if (ret >= 0) + return ret; + + if (errno == EAGAIN || errno == EWOULDBLOCK) + return MBEDTLS_ERR_SSL_WANT_WRITE; + + if (errno == EPIPE || errno == ECONNRESET) + return MBEDTLS_ERR_NET_CONN_RESET; + + if( errno == EINTR ) + return MBEDTLS_ERR_SSL_WANT_WRITE; + + return MBEDTLS_ERR_NET_SEND_FAILED; +} + +int +lws_plat_mbedtls_net_recv(void *ctx, unsigned char *buf, size_t len) +{ + int fd = ((mbedtls_net_context *) ctx)->fd; + int ret; + + if (fd < 0) + return MBEDTLS_ERR_NET_INVALID_CONTEXT; + + ret = (int)read(fd, buf, len); + if (ret >= 0) + return ret; + + if (errno == EAGAIN || errno == EWOULDBLOCK) + return MBEDTLS_ERR_SSL_WANT_READ; + + if (errno == EPIPE || errno == ECONNRESET) + return MBEDTLS_ERR_NET_CONN_RESET; + + if (errno == EINTR || !errno) + return MBEDTLS_ERR_SSL_WANT_READ; + + return MBEDTLS_ERR_NET_RECV_FAILED; +} +#endif + diff -Nru libwebsockets-3.2.1/lib/plat/freertos/private-lib-plat-freertos.h libwebsockets-4.1.6/lib/plat/freertos/private-lib-plat-freertos.h --- libwebsockets-3.2.1/lib/plat/freertos/private-lib-plat-freertos.h 1970-01-01 00:00:00.000000000 +0000 +++ libwebsockets-4.1.6/lib/plat/freertos/private-lib-plat-freertos.h 2020-12-01 17:40:26.000000000 +0000 @@ -0,0 +1,132 @@ + /* + * libwebsockets - small server side websockets and web server implementation + * + * Copyright (C) 2010 - 2019 Andy Green + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to + * deal in the Software without restriction, including without limitation the + * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or + * sell copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS + * IN THE SOFTWARE. + * + * Included from lib/private-lib-core.h if LWS_PLAT_FREERTOS + */ + +#if !defined(LWS_ESP_PLATFORM) +#define SOMAXCONN 3 +#endif + +#if defined(LWS_AMAZON_RTOS) + int + open(const char *path, int oflag, ...); +#else + #include +#endif + + #include + #include + #include + #include + #include + #include + + #ifndef __cplusplus + #include + #endif + #include +#if defined(LWS_AMAZON_RTOS) +const char * +gai_strerror(int); +#else + #include +#endif + +#if defined(LWS_AMAZON_RTOS) + #include "FreeRTOS.h" +#if defined(LWS_WITH_SYS_ASYNC_DNS) + #include "FreeRTOS_IP.h" +#endif + #include "timers.h" + #include + #include +#else + #include "freertos/timers.h" + #include + #include + #include +#endif + +#if defined(LWS_WITH_ESP32) +#include "lwip/apps/sntp.h" +#include +#endif + +typedef SemaphoreHandle_t lws_mutex_t; +#define lws_mutex_init(x) x = xSemaphoreCreateMutex() +#define lws_mutex_destroy(x) vSemaphoreDelete(x) +#define lws_mutex_lock(x) xSemaphoreTake(x, portMAX_DELAY) +#define lws_mutex_unlock(x) xSemaphoreGive(x) + +#include + + #if defined(LWS_BUILTIN_GETIFADDRS) + #include "./misc/getifaddrs.h" + #endif + + #define LWS_ERRNO errno + #define LWS_EAGAIN EAGAIN + #define LWS_EALREADY EALREADY + #define LWS_EINPROGRESS EINPROGRESS + #define LWS_EINTR EINTR + #define LWS_EISCONN EISCONN + #define LWS_ENOTCONN ENOTCONN + #define LWS_EWOULDBLOCK EWOULDBLOCK + #define LWS_EADDRINUSE EADDRINUSE + + #define lws_set_blocking_send(wsi) + + #ifndef LWS_NO_FORK + #ifdef LWS_HAVE_SYS_PRCTL_H + #include + #endif + #endif + +#if !defined(MSG_NOSIGNAL) +#define MSG_NOSIGNAL 0 +#endif + +#define compatible_close(x) close(x) +#define lws_plat_socket_offset() LWIP_SOCKET_OFFSET +#define wsi_from_fd(A,B) A->lws_lookup[B - lws_plat_socket_offset()] + +struct lws_context; +struct lws; + +int +insert_wsi(const struct lws_context *context, struct lws *wsi); + +#define delete_from_fd(A,B) A->lws_lookup[B - lws_plat_socket_offset()] = 0 + +#define LWS_PLAT_TIMER_TYPE TimerHandle_t +#define LWS_PLAT_TIMER_CB(name, var) void name(TimerHandle_t var) +#define LWS_PLAT_TIMER_CB_GET_OPAQUE(x) pvTimerGetTimerID(x) +#define LWS_PLAT_TIMER_CREATE(name, interval, repeat, opaque, cb) \ + xTimerCreate(name, pdMS_TO_TICKS(interval) ? pdMS_TO_TICKS(interval) : 1, \ + repeat ? pdTRUE : 0, opaque, cb) +#define LWS_PLAT_TIMER_DELETE(ptr) xTimerDelete(ptr, 0) +#define LWS_PLAT_TIMER_START(ptr) xTimerStart(ptr, 0) +#define LWS_PLAT_TIMER_STOP(ptr) xTimerStop(ptr, 0) + + diff -Nru libwebsockets-3.2.1/lib/plat/optee/CMakeLists.txt libwebsockets-4.1.6/lib/plat/optee/CMakeLists.txt --- libwebsockets-3.2.1/lib/plat/optee/CMakeLists.txt 1970-01-01 00:00:00.000000000 +0000 +++ libwebsockets-4.1.6/lib/plat/optee/CMakeLists.txt 2020-12-01 17:40:26.000000000 +0000 @@ -0,0 +1,49 @@ +# +# libwebsockets - small server side websockets and web server implementation +# +# Copyright (C) 2010 - 2020 Andy Green +# +# Permission is hereby granted, free of charge, to any person obtaining a copy +# of this software and associated documentation files (the "Software"), to +# deal in the Software without restriction, including without limitation the +# rights to use, copy, modify, merge, publish, distribute, sublicense, and/or +# sell copies of the Software, and to permit persons to whom the Software is +# furnished to do so, subject to the following conditions: +# +# The above copyright notice and this permission notice shall be included in +# all copies or substantial portions of the Software. +# +# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING +# FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS +# IN THE SOFTWARE. +# +# The strategy is to only export to PARENT_SCOPE +# +# - changes to LIB_LIST +# - changes to SOURCES +# - includes via include_directories +# +# and keep everything else private + +include_directories(.) + +list(APPEND SOURCES + plat/optee/lws-plat-optee.c +) +if (LWS_WITH_NETWORK) + list(APPEND SOURCES + plat/optee/network.c + ) +endif() + +set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} --sysroot ../../../../lib/libutils/isoc/include -I../../../../lib/libutils/isoc/include -I../../../../lib/libutils/ext/include" ) + +# +# Keep explicit parent scope exports at end +# + +exports_to_parent_scope() diff -Nru libwebsockets-3.2.1/lib/plat/optee/lws-plat-optee.c libwebsockets-4.1.6/lib/plat/optee/lws-plat-optee.c --- libwebsockets-3.2.1/lib/plat/optee/lws-plat-optee.c 2019-12-18 14:45:31.000000000 +0000 +++ libwebsockets-4.1.6/lib/plat/optee/lws-plat-optee.c 2020-12-01 17:40:26.000000000 +0000 @@ -1,4 +1,28 @@ -#include "core/private.h" +/* + * libwebsockets - small server side websockets and web server implementation + * + * Copyright (C) 2010 - 2019 Andy Green + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to + * deal in the Software without restriction, including without limitation the + * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or + * sell copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS + * IN THE SOFTWARE. + */ + +#include "private-lib-core.h" #if !defined(LWS_WITH_NETWORK) #include @@ -49,8 +73,8 @@ } #endif -int -lws_get_random(struct lws_context *context, void *buf, int len) +size_t +lws_get_random(struct lws_context *context, void *buf, size_t len) { #if defined(LWS_WITH_NETWORK) TEE_GenerateRandom(buf, len); @@ -102,7 +126,7 @@ } int -lws_plat_set_nonblocking(int fd) +lws_plat_set_nonblocking(lws_sockfd_type fd) { return 0; } @@ -211,3 +235,27 @@ { return 4096; } + +int +lws_plat_ntpclient_config(struct lws_context *context) +{ +#if 0 + char *ntpsrv = getenv("LWS_NTP_SERVER"); + + if (ntpsrv && strlen(ntpsrv) < 64) { + lws_system_blob_heap_append(lws_system_get_blob(context, + LWS_SYSBLOB_TYPE_NTP_SERVER, 0), + (const uint8_t *)ntpsrv, + strlen(ntpsrv)); + return 1; + } +#endif + return 0; +} + +void +lws_msleep(unsigned int ms) +{ +} + + diff -Nru libwebsockets-3.2.1/lib/plat/optee/network.c libwebsockets-4.1.6/lib/plat/optee/network.c --- libwebsockets-3.2.1/lib/plat/optee/network.c 2019-12-18 14:45:31.000000000 +0000 +++ libwebsockets-4.1.6/lib/plat/optee/network.c 2020-12-01 17:40:26.000000000 +0000 @@ -1,5 +1,36 @@ -#include "core/private.h" - +/* + * libwebsockets - small server side websockets and web server implementation + * + * Copyright (C) 2010 - 2019 Andy Green + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to + * deal in the Software without restriction, including without limitation the + * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or + * sell copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS + * IN THE SOFTWARE. + */ + +#include "private-lib-core.h" + +#if defined(LWS_WITH_MBEDTLS) +#if defined(LWS_HAVE_MBEDTLS_NET_SOCKETS) +#include "mbedtls/net_sockets.h" +#else +#include "mbedtls/net.h" +#endif +#endif int lws_plat_pipe_create(struct lws *wsi) @@ -18,7 +49,7 @@ { } -LWS_VISIBLE int +int lws_send_pipe_choked(struct lws *wsi) { struct lws *wsi_eff; @@ -55,7 +86,7 @@ } -LWS_EXTERN int +int _lws_plat_service_tsi(struct lws_context *context, int timeout_ms, int tsi) { lws_usec_t timeout_us = timeout_ms * LWS_US_PER_MS; @@ -65,7 +96,7 @@ /* stay dead once we are dead */ - if (!context || !context->vhost_list) + if (!context) return 1; pt = &context->pt[tsi]; @@ -75,7 +106,7 @@ else timeout_ms = 2000000000; - if (!pt->service_tid_detected) { + if (!pt->service_tid_detected && context->vhost_list) { struct lws _lws; memset(&_lws, 0, sizeof(_lws)); @@ -97,7 +128,9 @@ lws_pt_lock(pt, __func__); /* don't stay in poll wait longer than next hr timeout */ - us = __lws_sul_service_ripe(&pt->pt_sul_owner, lws_now_usecs()); + us = __lws_sul_service_ripe(pt->pt_sul_owner, + LWS_COUNT_PT_SUL_OWNERS, + lws_now_usecs()); if (us && us < timeout_us) timeout_us = us; @@ -156,12 +189,6 @@ } int -lws_plat_check_connection_error(struct lws *wsi) -{ - return 0; -} - -int lws_plat_service(struct lws_context *context, int timeout_ms) { return _lws_plat_service_tsi(context, timeout_ms, 0); @@ -229,4 +256,55 @@ return 1; } +#if defined(LWS_WITH_MBEDTLS) +int +lws_plat_mbedtls_net_send(void *ctx, const uint8_t *buf, size_t len) +{ + int fd = ((mbedtls_net_context *) ctx)->fd; + int ret; + + if (fd < 0) + return MBEDTLS_ERR_NET_INVALID_CONTEXT; + + ret = write(fd, buf, len); + if (ret >= 0) + return ret; + + if (errno == EAGAIN || errno == EWOULDBLOCK) + return MBEDTLS_ERR_SSL_WANT_WRITE; + if (errno == EPIPE || errno == ECONNRESET) + return MBEDTLS_ERR_NET_CONN_RESET; + + if( errno == EINTR ) + return MBEDTLS_ERR_SSL_WANT_WRITE; + + return MBEDTLS_ERR_NET_SEND_FAILED; +} + +int +lws_plat_mbedtls_net_recv(void *ctx, unsigned char *buf, size_t len) +{ + int fd = ((mbedtls_net_context *) ctx)->fd; + int ret; + + if (fd < 0) + return MBEDTLS_ERR_NET_INVALID_CONTEXT; + + ret = (int)read(fd, buf, len); + if (ret >= 0) + return ret; + + if (errno == EAGAIN || errno == EWOULDBLOCK) + return MBEDTLS_ERR_SSL_WANT_READ; + + if (errno == EPIPE || errno == ECONNRESET) + return MBEDTLS_ERR_NET_CONN_RESET; + + if (errno == EINTR) + return MBEDTLS_ERR_SSL_WANT_READ; + + return MBEDTLS_ERR_NET_RECV_FAILED; +} + +#endif diff -Nru libwebsockets-3.2.1/lib/plat/optee/private.h libwebsockets-4.1.6/lib/plat/optee/private.h --- libwebsockets-3.2.1/lib/plat/optee/private.h 2019-12-18 14:45:31.000000000 +0000 +++ libwebsockets-4.1.6/lib/plat/optee/private.h 1970-01-01 00:00:00.000000000 +0000 @@ -1,47 +0,0 @@ -/* - * libwebsockets - small server side websockets and web server implementation - * - * Copyright (C) 2010 - 2018 Andy Green - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation: - * version 2.1 of the License. - * - * This library is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with this library; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, - * MA 02110-1301 USA - * - * Included from lib/core/private.h if LWS_WITH_OPTEE - */ - - #include - #include - - #define LWS_ERRNO errno - #define LWS_EAGAIN EAGAIN - #define LWS_EALREADY EALREADY - #define LWS_EINPROGRESS EINPROGRESS - #define LWS_EINTR EINTR - #define LWS_EISCONN EISCONN - #define LWS_ENOTCONN ENOTCONN - #define LWS_EWOULDBLOCK EWOULDBLOCK - #define LWS_EADDRINUSE EADDRINUSE - - #define lws_set_blocking_send(wsi) - -#define compatible_close(x) close(x) -#define lws_plat_socket_offset() (0) -#define wsi_from_fd(A,B) A->lws_lookup[B - lws_plat_socket_offset()] -#define insert_wsi(A,B) assert(A->lws_lookup[B->desc.sockfd - \ - lws_plat_socket_offset()] == 0); \ - A->lws_lookup[B->desc.sockfd - \ - lws_plat_socket_offset()] = B -#define delete_from_fd(A,B) A->lws_lookup[B - lws_plat_socket_offset()] = 0 - diff -Nru libwebsockets-3.2.1/lib/plat/optee/private-lib-plat-optee.h libwebsockets-4.1.6/lib/plat/optee/private-lib-plat-optee.h --- libwebsockets-3.2.1/lib/plat/optee/private-lib-plat-optee.h 1970-01-01 00:00:00.000000000 +0000 +++ libwebsockets-4.1.6/lib/plat/optee/private-lib-plat-optee.h 2020-12-01 17:40:26.000000000 +0000 @@ -0,0 +1,50 @@ + /* + * libwebsockets - small server side websockets and web server implementation + * + * Copyright (C) 2010 - 2019 Andy Green + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to + * deal in the Software without restriction, including without limitation the + * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or + * sell copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS + * IN THE SOFTWARE. + * + * Included from lib/private-lib-core.h if LWS_WITH_OPTEE + */ + + #include + #include + + #define LWS_ERRNO errno + #define LWS_EAGAIN EAGAIN + #define LWS_EALREADY EALREADY + #define LWS_EINPROGRESS EINPROGRESS + #define LWS_EINTR EINTR + #define LWS_EISCONN EISCONN + #define LWS_ENOTCONN ENOTCONN + #define LWS_EWOULDBLOCK EWOULDBLOCK + #define LWS_EADDRINUSE EADDRINUSE + + #define lws_set_blocking_send(wsi) + +#define compatible_close(x) close(x) +#define lws_plat_socket_offset() (0) +#define wsi_from_fd(A,B) A->lws_lookup[B - lws_plat_socket_offset()] +#define insert_wsi(A,B) assert(A->lws_lookup[B->desc.sockfd - \ + lws_plat_socket_offset()] == 0); \ + A->lws_lookup[B->desc.sockfd - \ + lws_plat_socket_offset()] = B +#define delete_from_fd(A,B) A->lws_lookup[B - lws_plat_socket_offset()] = 0 + diff -Nru libwebsockets-3.2.1/lib/plat/unix/android/android-resolv.c libwebsockets-4.1.6/lib/plat/unix/android/android-resolv.c --- libwebsockets-3.2.1/lib/plat/unix/android/android-resolv.c 1970-01-01 00:00:00.000000000 +0000 +++ libwebsockets-4.1.6/lib/plat/unix/android/android-resolv.c 2020-12-01 17:40:26.000000000 +0000 @@ -0,0 +1,54 @@ +/* + * libwebsockets - small server side websockets and web server implementation + * + * Copyright (C) 2010 - 2019 Andy Green + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to + * deal in the Software without restriction, including without limitation the + * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or + * sell copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS + * IN THE SOFTWARE. + */ + +#include "private-lib-core.h" +#include + +lws_async_dns_server_check_t +lws_plat_asyncdns_init(struct lws_context *context, lws_sockaddr46 *sa46) +{ + char d[PROP_VALUE_MAX], *p; + uint32_t ip32; + uint8_t i[4]; + int n; + + d[0] = '\0'; + if (__system_property_get("net.dns1", d) <= 0) + return LADNS_CONF_SERVER_UNKNOWN; + + for (n = 0; n < 4; n++) { + i[n] = atoi(d); + p = strchr(d, '.'); + if (n != 3 && !p) + return LADNS_CONF_SERVER_UNKNOWN; + } + + ip32 = (i[0] << 24) | (i[1] << 16) | (i[2] << 8) | i[3]; + n = ip32 == sa46->sa4.sin_addr.s_addr; + sa46->sa4.sin_family = AF_INET; + sa46->sa4.sin_addr.s_addr = ip32; + + return n ? LADNS_CONF_SERVER_SAME : LADNS_CONF_SERVER_CHANGED; +} + diff -Nru libwebsockets-3.2.1/lib/plat/unix/CMakeLists.txt libwebsockets-4.1.6/lib/plat/unix/CMakeLists.txt --- libwebsockets-3.2.1/lib/plat/unix/CMakeLists.txt 1970-01-01 00:00:00.000000000 +0000 +++ libwebsockets-4.1.6/lib/plat/unix/CMakeLists.txt 2020-12-01 17:40:26.000000000 +0000 @@ -0,0 +1,109 @@ +# +# libwebsockets - small server side websockets and web server implementation +# +# Copyright (C) 2010 - 2020 Andy Green +# +# Permission is hereby granted, free of charge, to any person obtaining a copy +# of this software and associated documentation files (the "Software"), to +# deal in the Software without restriction, including without limitation the +# rights to use, copy, modify, merge, publish, distribute, sublicense, and/or +# sell copies of the Software, and to permit persons to whom the Software is +# furnished to do so, subject to the following conditions: +# +# The above copyright notice and this permission notice shall be included in +# all copies or substantial portions of the Software. +# +# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING +# FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS +# IN THE SOFTWARE. +# +# The strategy is to only export to PARENT_SCOPE +# +# - changes to LIB_LIST +# - changes to SOURCES +# - includes via include_directories +# +# and keep everything else private + +include_directories(.) + +execute_process( COMMAND grep -c illumos /lib/ld.so.1 + OUTPUT_VARIABLE ILLUMOS ERROR_QUIET ) +# Chomp the \n at end of output. +string(REGEX REPLACE "[\n]+" "" ILLUMOS "${ILLUMOS}") + +if (NOT ${ILLUMOS} MATCHES "0") + set(ILLUMOS 1) +endif() + +set(LWS_PLAT_UNIX 1) +list(APPEND SOURCES + plat/unix/unix-caps.c + plat/unix/unix-misc.c + plat/unix/unix-init.c +) +if (LWS_WITH_FILE_OPS) + list(APPEND SOURCES plat/unix/unix-file.c) +endif() +if (LWS_WITH_NETWORK) + list(APPEND SOURCES + plat/unix/unix-pipe.c + plat/unix/unix-service.c + plat/unix/unix-sockets.c + plat/unix/unix-fds.c + ) + if (LWS_WITH_SYS_ASYNC_DNS) + if (LWS_PLAT_ANDROID) + list(APPEND SOURCES plat/unix/android/android-resolv.c) + else() + list(APPEND SOURCES plat/unix/unix-resolv.c) + endif() + endif() +endif() + +if (LWS_WITH_PLUGINS_API) + list(APPEND SOURCES plat/unix/unix-plugins.c) +endif() + +if (LWS_WITH_SPAWN) + list(APPEND SOURCES plat/unix/unix-spawn.c) +endif() + +if (HAIKU) + set(CMAKE_REQUIRED_LIBRARIES network) + list(APPEND LIB_LIST_AT_END network) +endif() + +IF (CMAKE_SYSTEM_NAME STREQUAL Linux) + CHECK_FUNCTION_EXISTS(eventfd_read LWS_HAVE_EVENTFD) +endif() + +list(APPEND LIB_LIST_AT_END m) + +if (ILLUMOS) + list(APPEND LIB_LIST_AT_END socket) +endif() + +if (LWS_HAVE_LIBCAP) + list(APPEND LIB_LIST_AT_END cap) +endif() + +if (${CMAKE_SYSTEM_NAME} MATCHES "QNX") + list(APPEND LIB_LIST_AT_END socket) +endif() + +list(APPEND LIB_LIST_AT_END dl) + +# +# Keep explicit parent scope exports at end +# + +exports_to_parent_scope() +set(LWS_PLAT_UNIX ${LWS_PLAT_UNIX} PARENT_SCOPE) +set(ILLUMOS ${ILLUMOS} PARENT_SCOPE) +set(LIB_LIST_AT_END ${LIB_LIST_AT_END} PARENT_SCOPE) +set(LWS_PLAT_UNIX ${LWS_PLAT_UNIX} PARENT_SCOPE) diff -Nru libwebsockets-3.2.1/lib/plat/unix/private.h libwebsockets-4.1.6/lib/plat/unix/private.h --- libwebsockets-3.2.1/lib/plat/unix/private.h 2019-12-18 14:45:31.000000000 +0000 +++ libwebsockets-4.1.6/lib/plat/unix/private.h 1970-01-01 00:00:00.000000000 +0000 @@ -1,173 +0,0 @@ -/* - * libwebsockets - small server side websockets and web server implementation - * - * Copyright (C) 2010 - 2018 Andy Green - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation: - * version 2.1 of the License. - * - * This library is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with this library; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, - * MA 02110-1301 USA - * - * Included from lib/core/private.h if no explicit platform - */ - -#include -#include -#include - -#include -#include -#include -#include -#include - -#ifndef __cplusplus -#include -#endif -#include -#include - -#include -#include -#include -#include -#include -#include - -#if defined(__APPLE__) -#include -#endif -#if defined(__FreeBSD__) -#include -#endif -#if defined(__linux__) -#include -#endif -#if defined(__QNX__) - #include - #if defined(__LITTLEENDIAN__) - #define BYTE_ORDER __LITTLEENDIAN__ - #define LITTLE_ENDIAN __LITTLEENDIAN__ - #define BIG_ENDIAN 4321 /* to show byte order (taken from gcc); for suppres warning that BIG_ENDIAN is not defined. */ - #endif - #if defined(__BIGENDIAN__) - #define BYTE_ORDER __BIGENDIAN__ - #define LITTLE_ENDIAN 1234 /* to show byte order (taken from gcc); for suppres warning that LITTLE_ENDIAN is not defined. */ - #define BIG_ENDIAN __BIGENDIAN__ - #endif -#endif - -#if defined(__sun) && defined(__GNUC__) - -#include - -#if !defined (BYTE_ORDER) -#define BYTE_ORDER __BYTE_ORDER__ -#endif - -#if !defined(LITTLE_ENDIAN) -#define LITTLE_ENDIAN __ORDER_LITTLE_ENDIAN__ -#endif - -#if !defined(BIG_ENDIAN) -#define BIG_ENDIAN __ORDER_BIG_ENDIAN__ -#endif - -#endif /* sun + GNUC */ - -#if !defined(BYTE_ORDER) -#define BYTE_ORDER __BYTE_ORDER -#endif -#if !defined(LITTLE_ENDIAN) -#define LITTLE_ENDIAN __LITTLE_ENDIAN -#endif -#if !defined(BIG_ENDIAN) -#define BIG_ENDIAN __BIG_ENDIAN -#endif - -#if defined(LWS_BUILTIN_GETIFADDRS) -#include "./misc/getifaddrs.h" -#else - -#if defined(__HAIKU__) -#define _BSD_SOURCE -#endif -#include - -#endif - -#if defined (__sun) || defined(__HAIKU__) || defined(__QNX__) || defined(__ANDROID__) -#include - -#if defined(__ANDROID__) -#include -#endif - -#else -#include -#endif - -#ifdef __QNX__ -# include "netinet/tcp_var.h" -# define TCP_KEEPINTVL TCPCTL_KEEPINTVL -# define TCP_KEEPIDLE TCPCTL_KEEPIDLE -# define TCP_KEEPCNT TCPCTL_KEEPCNT -#endif - -#define LWS_ERRNO errno -#define LWS_EAGAIN EAGAIN -#define LWS_EALREADY EALREADY -#define LWS_EINPROGRESS EINPROGRESS -#define LWS_EINTR EINTR -#define LWS_EISCONN EISCONN -#define LWS_ENOTCONN ENOTCONN -#define LWS_EWOULDBLOCK EWOULDBLOCK -#define LWS_EADDRINUSE EADDRINUSE -#define lws_set_blocking_send(wsi) -#define LWS_SOCK_INVALID (-1) - -struct lws_context; - -struct lws * -wsi_from_fd(const struct lws_context *context, int fd); - -int -insert_wsi(const struct lws_context *context, struct lws *wsi); - -void -delete_from_fd(const struct lws_context *context, int fd); - -#ifndef LWS_NO_FORK -#ifdef LWS_HAVE_SYS_PRCTL_H -#include -#endif -#endif - -#define compatible_close(x) close(x) -#define lws_plat_socket_offset() (0) - -/* - * Mac OSX as well as iOS do not define the MSG_NOSIGNAL flag, - * but happily have something equivalent in the SO_NOSIGPIPE flag. - */ -#ifdef __APPLE__ -#define MSG_NOSIGNAL SO_NOSIGPIPE -#endif - -/* - * Solaris 11.X only supports POSIX 2001, MSG_NOSIGNAL appears in - * POSIX 2008. - */ -#if defined(__sun) && !defined(MSG_NOSIGNAL) - #define MSG_NOSIGNAL 0 -#endif diff -Nru libwebsockets-3.2.1/lib/plat/unix/private-lib-plat-unix.h libwebsockets-4.1.6/lib/plat/unix/private-lib-plat-unix.h --- libwebsockets-3.2.1/lib/plat/unix/private-lib-plat-unix.h 1970-01-01 00:00:00.000000000 +0000 +++ libwebsockets-4.1.6/lib/plat/unix/private-lib-plat-unix.h 2020-12-01 17:40:26.000000000 +0000 @@ -0,0 +1,207 @@ + /* + * libwebsockets - small server side websockets and web server implementation + * + * Copyright (C) 2010 - 2019 Andy Green + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to + * deal in the Software without restriction, including without limitation the + * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or + * sell copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS + * IN THE SOFTWARE. + * + * Included from lib/private-lib-core.h if no explicit platform + */ + +#include +#include +#include + +#include +#include +#include +#include +#include + +#ifndef __cplusplus +#include +#endif +#include +#include + +#include +#include +#include +#include +#include +#include +#if defined(LWS_HAVE_EVENTFD) +#include +#endif + +#if defined(__APPLE__) +#include +#endif +#if defined(__FreeBSD__) +#include +#endif +#if defined(__linux__) +#include +#include +#include +#endif +#if defined(__QNX__) + #include + #if defined(__LITTLEENDIAN__) + #define BYTE_ORDER __LITTLEENDIAN__ + #define LITTLE_ENDIAN __LITTLEENDIAN__ + #define BIG_ENDIAN 4321 /* to show byte order (taken from gcc); for suppres warning that BIG_ENDIAN is not defined. */ + #endif + #if defined(__BIGENDIAN__) + #define BYTE_ORDER __BIGENDIAN__ + #define LITTLE_ENDIAN 1234 /* to show byte order (taken from gcc); for suppres warning that LITTLE_ENDIAN is not defined. */ + #define BIG_ENDIAN __BIGENDIAN__ + #endif +#endif + +#if defined(LWS_HAVE_PTHREAD_H) +#include +typedef pthread_mutex_t lws_mutex_t; +#define lws_mutex_init(x) pthread_mutex_init(&(x), NULL) +#define lws_mutex_destroy(x) pthread_mutex_destroy(&(x)) +#define lws_mutex_lock(x) pthread_mutex_lock(&(x)) +#define lws_mutex_unlock(x) pthread_mutex_unlock(&(x)) +#endif + +#if defined(__sun) && defined(__GNUC__) + +#include + +#if !defined (BYTE_ORDER) +#define BYTE_ORDER __BYTE_ORDER__ +#endif + +#if !defined(LITTLE_ENDIAN) +#define LITTLE_ENDIAN __ORDER_LITTLE_ENDIAN__ +#endif + +#if !defined(BIG_ENDIAN) +#define BIG_ENDIAN __ORDER_BIG_ENDIAN__ +#endif + +#endif /* sun + GNUC */ + +#if !defined(BYTE_ORDER) +#define BYTE_ORDER __BYTE_ORDER +#endif +#if !defined(LITTLE_ENDIAN) +#define LITTLE_ENDIAN __LITTLE_ENDIAN +#endif +#if !defined(BIG_ENDIAN) +#define BIG_ENDIAN __BIG_ENDIAN +#endif + +#if defined(LWS_BUILTIN_GETIFADDRS) +#include "./misc/getifaddrs.h" +#else + +#if defined(__HAIKU__) +#define _BSD_SOURCE +#endif +#include + +#endif + +#if defined (__sun) || defined(__HAIKU__) || defined(__QNX__) || defined(__ANDROID__) +#include + +#if defined(__ANDROID__) +#include +#endif + +#else +#include +#endif + +#ifdef __QNX__ +# include "netinet/tcp_var.h" +# define TCP_KEEPINTVL TCPCTL_KEEPINTVL +# define TCP_KEEPIDLE TCPCTL_KEEPIDLE +# define TCP_KEEPCNT TCPCTL_KEEPCNT +#endif + +#define LWS_ERRNO errno +#define LWS_EAGAIN EAGAIN +#define LWS_EALREADY EALREADY +#define LWS_EINPROGRESS EINPROGRESS +#define LWS_EINTR EINTR +#define LWS_EISCONN EISCONN +#define LWS_ENOTCONN ENOTCONN +#define LWS_EWOULDBLOCK EWOULDBLOCK +#define LWS_EADDRINUSE EADDRINUSE +#define lws_set_blocking_send(wsi) +#define LWS_SOCK_INVALID (-1) + +struct lws_context; + +struct lws * +wsi_from_fd(const struct lws_context *context, int fd); + +int +insert_wsi(const struct lws_context *context, struct lws *wsi); + +int +lws_plat_ifconfig_ip(const char *ifname, int fd, uint8_t *ip, uint8_t *mask_ip, + uint8_t *gateway_ip); + +void +delete_from_fd(const struct lws_context *context, int fd); + +#ifndef LWS_NO_FORK +#ifdef LWS_HAVE_SYS_PRCTL_H +#include +#endif +#endif + +#define compatible_close(x) close(x) +#define compatible_file_close(fd) close(fd) +#define lws_plat_socket_offset() (0) + +/* + * Mac OSX as well as iOS do not define the MSG_NOSIGNAL flag, + * but happily have something equivalent in the SO_NOSIGPIPE flag. + */ +#ifdef __APPLE__ +/* iOS SDK 12+ seems to define it, undef it for compatibility both ways */ +#undef MSG_NOSIGNAL +#define MSG_NOSIGNAL SO_NOSIGPIPE +#endif + +/* + * Solaris 11.X only supports POSIX 2001, MSG_NOSIGNAL appears in + * POSIX 2008. + */ +#if defined(__sun) && !defined(MSG_NOSIGNAL) + #define MSG_NOSIGNAL 0 +#endif + +int +lws_plat_BINDTODEVICE(int fd, const char *ifname); + +int +lws_plat_rawudp_broadcast(uint8_t *p, const uint8_t *canned, int canned_len, + int n, int fd, const char *iface); + +int +lws_plat_if_up(const char *ifname, int fd, int up); diff -Nru libwebsockets-3.2.1/lib/plat/unix/unix-caps.c libwebsockets-4.1.6/lib/plat/unix/unix-caps.c --- libwebsockets-3.2.1/lib/plat/unix/unix-caps.c 2019-12-18 14:45:31.000000000 +0000 +++ libwebsockets-4.1.6/lib/plat/unix/unix-caps.c 2020-12-01 17:40:26.000000000 +0000 @@ -1,26 +1,31 @@ /* * libwebsockets - small server side websockets and web server implementation * - * Copyright (C) 2010-2018 Andy Green + * Copyright (C) 2010 - 2019 Andy Green * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation: - * version 2.1 of the License. + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to + * deal in the Software without restriction, including without limitation the + * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or + * sell copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: * - * This library is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. * - * You should have received a copy of the GNU Lesser General Public - * License along with this library; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, - * MA 02110-1301 USA + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS + * IN THE SOFTWARE. */ +#if !defined(_GNU_SOURCE) #define _GNU_SOURCE -#include "core/private.h" +#endif +#include "private-lib-core.h" #include #include @@ -167,7 +172,9 @@ context->count_caps); #endif - initgroups(p->pw_name, context->gid); + if (initgroups(p->pw_name, context->gid)) + return 1; + if (setuid(context->uid)) { lwsl_err("%s: setuid: %s failed\n", __func__, strerror(LWS_ERRNO)); diff -Nru libwebsockets-3.2.1/lib/plat/unix/unix-fds.c libwebsockets-4.1.6/lib/plat/unix/unix-fds.c --- libwebsockets-3.2.1/lib/plat/unix/unix-fds.c 2019-12-18 14:45:31.000000000 +0000 +++ libwebsockets-4.1.6/lib/plat/unix/unix-fds.c 2020-12-01 17:40:26.000000000 +0000 @@ -1,26 +1,31 @@ /* * libwebsockets - small server side websockets and web server implementation * - * Copyright (C) 2010-2019 Andy Green + * Copyright (C) 2010 - 2019 Andy Green * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation: - * version 2.1 of the License. + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to + * deal in the Software without restriction, including without limitation the + * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or + * sell copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: * - * This library is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. * - * You should have received a copy of the GNU Lesser General Public - * License along with this library; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, - * MA 02110-1301 USA + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS + * IN THE SOFTWARE. */ +#if !defined(_GNU_SOURCE) #define _GNU_SOURCE -#include "core/private.h" +#endif +#include "private-lib-core.h" struct lws * wsi_from_fd(const struct lws_context *context, int fd) @@ -44,11 +49,85 @@ return NULL; } +#if defined(_DEBUG) +int +sanity_assert_no_wsi_traces(const struct lws_context *context, struct lws *wsi) +{ + struct lws **p, **done; + + if (!context->max_fds_unrelated_to_ulimit) + /* can't tell */ + return 0; + + /* slow fds handling */ + + p = context->lws_lookup; + done = &p[context->max_fds]; + + /* confirm the wsi doesn't already exist */ + + while (p != done && *p != wsi) + p++; + + if (p == done) + return 0; + + assert(0); /* this wsi is still mentioned inside lws */ + + return 1; +} + +int +sanity_assert_no_sockfd_traces(const struct lws_context *context, + lws_sockfd_type sfd) +{ +#if LWS_MAX_SMP > 1 + /* + * We can't really do this test... another thread can accept and + * reuse the closed fd + */ + return 0; +#else + struct lws **p, **done; + + if (sfd == LWS_SOCK_INVALID) + return 0; + + if (!context->max_fds_unrelated_to_ulimit && + context->lws_lookup[sfd - lws_plat_socket_offset()]) { + assert(0); /* the fd is still in use */ + return 1; + } + + /* slow fds handling */ + + p = context->lws_lookup; + done = &p[context->max_fds]; + + /* confirm the sfd not already in use */ + + while (p != done && (!*p || (*p)->desc.sockfd != sfd)) + p++; + + if (p == done) + return 0; + + assert(0); /* this fd is still in the tables */ + + return 1; +#endif +} +#endif + + int insert_wsi(const struct lws_context *context, struct lws *wsi) { struct lws **p, **done; + if (sanity_assert_no_wsi_traces(context, wsi)) + return 0; + if (!context->max_fds_unrelated_to_ulimit) { assert(context->lws_lookup[wsi->desc.sockfd - lws_plat_socket_offset()] == 0); @@ -64,29 +143,13 @@ p = context->lws_lookup; done = &p[context->max_fds]; -#if defined(_DEBUG) - - /* confirm it doesn't already exist */ + /* confirm fd isn't already in use by a wsi */ - while (p != done && *p != wsi) - p++; + if (sanity_assert_no_sockfd_traces(context, wsi->desc.sockfd)) + return 0; - assert(p == done); p = context->lws_lookup; - /* confirm fd doesn't already exist */ - - while (p != done && (!*p || (*p && (*p)->desc.sockfd != wsi->desc.sockfd))) - p++; - - if (p != done) { - lwsl_err("%s: wsi %p already says it has fd %d\n", - __func__, *p, wsi->desc.sockfd); - assert(0); - } - p = context->lws_lookup; -#endif - /* find an empty slot */ while (p != done && *p) @@ -102,6 +165,8 @@ return 0; } + + void delete_from_fd(const struct lws_context *context, int fd) { @@ -121,17 +186,17 @@ /* find the match */ - while (p != done && (!*p || (*p && (*p)->desc.sockfd != fd))) + while (p != done && (!*p || (*p)->desc.sockfd != fd)) p++; if (p == done) - lwsl_err("%s: fd %d not found\n", __func__, fd); + lwsl_debug("%s: fd %d not found\n", __func__, fd); else *p = NULL; #if defined(_DEBUG) p = context->lws_lookup; - while (p != done && (!*p || (*p && (*p)->desc.sockfd != fd))) + while (p != done && (!*p || (*p)->desc.sockfd != fd)) p++; if (p != done) { @@ -143,6 +208,30 @@ } void +delete_from_fdwsi(const struct lws_context *context, struct lws *wsi) +{ + + struct lws **p, **done; + + if (!context->max_fds_unrelated_to_ulimit) + return; + + + /* slow fds handling */ + + p = context->lws_lookup; + done = &p[context->max_fds]; + + /* find the match */ + + while (p != done && (!*p || (*p) != wsi)) + p++; + + if (p != done) + *p = NULL; +} + +void lws_plat_insert_socket_into_fds(struct lws_context *context, struct lws *wsi) { struct lws_context_per_thread *pt = &context->pt[(int)wsi->tsi]; diff -Nru libwebsockets-3.2.1/lib/plat/unix/unix-file.c libwebsockets-4.1.6/lib/plat/unix/unix-file.c --- libwebsockets-3.2.1/lib/plat/unix/unix-file.c 2019-12-18 14:45:31.000000000 +0000 +++ libwebsockets-4.1.6/lib/plat/unix/unix-file.c 2020-12-01 17:40:26.000000000 +0000 @@ -1,26 +1,31 @@ /* * libwebsockets - small server side websockets and web server implementation * - * Copyright (C) 2010-2018 Andy Green + * Copyright (C) 2010 - 2019 Andy Green * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation: - * version 2.1 of the License. + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to + * deal in the Software without restriction, including without limitation the + * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or + * sell copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: * - * This library is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. * - * You should have received a copy of the GNU Lesser General Public - * License along with this library; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, - * MA 02110-1301 USA + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS + * IN THE SOFTWARE. */ +#if !defined(_GNU_SOURCE) #define _GNU_SOURCE -#include "core/private.h" +#endif +#include "private-lib-core.h" #include #include diff -Nru libwebsockets-3.2.1/lib/plat/unix/unix-init.c libwebsockets-4.1.6/lib/plat/unix/unix-init.c --- libwebsockets-3.2.1/lib/plat/unix/unix-init.c 2019-12-18 14:45:31.000000000 +0000 +++ libwebsockets-4.1.6/lib/plat/unix/unix-init.c 2020-12-01 17:40:26.000000000 +0000 @@ -1,26 +1,31 @@ /* * libwebsockets - small server side websockets and web server implementation * - * Copyright (C) 2010-2018 Andy Green + * Copyright (C) 2010 - 2019 Andy Green * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation: - * version 2.1 of the License. + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to + * deal in the Software without restriction, including without limitation the + * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or + * sell copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: * - * This library is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. * - * You should have received a copy of the GNU Lesser General Public - * License along with this library; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, - * MA 02110-1301 USA + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS + * IN THE SOFTWARE. */ +#if !defined(_GNU_SOURCE) #define _GNU_SOURCE -#include "core/private.h" +#endif +#include "private-lib-core.h" #include #include @@ -30,10 +35,6 @@ #endif #include -#if defined(LWS_HAVE_MALLOC_TRIM) -#include -#endif - #if defined(LWS_WITH_NETWORK) static void lws_sul_plat_unix(lws_sorted_usec_list_t *sul) @@ -41,9 +42,6 @@ struct lws_context_per_thread *pt = lws_container_of(sul, struct lws_context_per_thread, sul_plat); struct lws_context *context = pt->context; -#if defined(LWS_ROLE_CGI) || defined(LWS_ROLE_DBUS) - time_t now = time(NULL); -#endif #if !defined(LWS_NO_DAEMONIZE) /* if our parent went down, don't linger around */ @@ -51,9 +49,6 @@ kill(pt->context->started_with_parent, 0) < 0) kill(getpid(), SIGTERM); #endif -#if defined(LWS_HAVE_MALLOC_TRIM) - malloc_trim(4 * 1024); -#endif if (pt->context->deprecated && !pt->context->count_wsi_allocated) { lwsl_notice("%s: ending deprecated context\n", __func__); @@ -63,6 +58,7 @@ lws_check_deferred_free(context, 0, 0); +#if defined(LWS_WITH_SERVER) lws_context_lock(context, "periodic checks"); lws_start_foreach_llp(struct lws_vhost **, pv, context->no_listener_vhost_list) { @@ -77,15 +73,25 @@ } } lws_end_foreach_llp(pv, no_listener_vhost_list); lws_context_unlock(context); - -#if defined(LWS_ROLE_CGI) - role_ops_cgi.periodic_checks(context, 0, now); #endif -#if defined(LWS_ROLE_DBUS) - role_ops_dbus.periodic_checks(context, 0, now); + + __lws_sul_insert_us(&pt->pt_sul_owner[LWSSULLI_MISS_IF_SUSPENDED], + &pt->sul_plat, 30 * LWS_US_PER_SEC); +} #endif - __lws_sul_insert(&pt->pt_sul_owner, &pt->sul_plat, 30 * LWS_US_PER_SEC); +#if defined(LWS_WITH_PLUGINS) +static int +protocol_plugin_cb(struct lws_plugin *pin, void *each_user) +{ + struct lws_context *context = (struct lws_context *)each_user; + const lws_plugin_protocol_t *plpr = + (const lws_plugin_protocol_t *)pin->hdr; + + context->plugin_protocol_count += plpr->count_protocols; + context->plugin_extension_count += plpr->count_extensions; + + return 0; } #endif @@ -129,18 +135,23 @@ lwsl_info(" mem: platform fd map: %5lu B\n", (unsigned long)(sizeof(struct lws *) * context->max_fds)); #endif +#if defined(LWS_WITH_FILE_OPS) fd = lws_open(SYSTEM_RANDOM_FILEPATH, O_RDONLY); - +#else + fd = open(SYSTEM_RANDOM_FILEPATH, O_RDONLY); +#endif context->fd_random = fd; if (context->fd_random < 0) { - lwsl_err("Unable to open random device %s %d\n", - SYSTEM_RANDOM_FILEPATH, context->fd_random); + lwsl_err("Unable to open random device %s %d, errno %d\n", + SYSTEM_RANDOM_FILEPATH, context->fd_random, errno); return 1; } #if defined(LWS_WITH_PLUGINS) if (info->plugin_dirs) - lws_plat_plugins_init(context, info->plugin_dirs); + lws_plugins_init(&context->plugin_list, info->plugin_dirs, + "lws_protocol_plugin", NULL, + protocol_plugin_cb, context); #endif @@ -148,8 +159,8 @@ /* we only need to do this on pt[0] */ context->pt[0].sul_plat.cb = lws_sul_plat_unix; - __lws_sul_insert(&context->pt[0].pt_sul_owner, &context->pt[0].sul_plat, - 30 * LWS_US_PER_SEC); + __lws_sul_insert_us(&context->pt[0].pt_sul_owner[LWSSULLI_MISS_IF_SUSPENDED], + &context->pt[0].sul_plat, 30 * LWS_US_PER_SEC); #endif return 0; @@ -173,9 +184,9 @@ void lws_plat_context_late_destroy(struct lws_context *context) { -#ifdef LWS_WITH_PLUGINS +#if defined(LWS_WITH_PLUGINS) if (context->plugin_list) - lws_plat_plugins_destroy(context); + lws_plugins_destroy(&context->plugin_list, NULL, NULL); #endif #if defined(LWS_WITH_NETWORK) if (context->lws_lookup) diff -Nru libwebsockets-3.2.1/lib/plat/unix/unix-misc.c libwebsockets-4.1.6/lib/plat/unix/unix-misc.c --- libwebsockets-3.2.1/lib/plat/unix/unix-misc.c 2019-12-18 14:45:31.000000000 +0000 +++ libwebsockets-4.1.6/lib/plat/unix/unix-misc.c 2020-12-01 17:40:26.000000000 +0000 @@ -1,26 +1,43 @@ /* * libwebsockets - small server side websockets and web server implementation * - * Copyright (C) 2010-2018 Andy Green + * Copyright (C) 2010 - 2019 Andy Green * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation: - * version 2.1 of the License. + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to + * deal in the Software without restriction, including without limitation the + * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or + * sell copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: * - * This library is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. * - * You should have received a copy of the GNU Lesser General Public - * License along with this library; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, - * MA 02110-1301 USA + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS + * IN THE SOFTWARE. */ +#if !defined(_GNU_SOURCE) #define _GNU_SOURCE -#include "core/private.h" +#endif +#include "private-lib-core.h" + +/* + * Normally you don't want this, use lws_sul instead inside the event loop. + * But sometimes for drivers it makes sense, so there's an internal-only + * crossplatform api for it. + */ + +void +lws_msleep(unsigned int ms) +{ + usleep(ms * LWS_US_PER_MS); +} lws_usec_t lws_now_usecs(void) @@ -42,13 +59,19 @@ #endif } -LWS_VISIBLE int -lws_get_random(struct lws_context *context, void *buf, int len) +size_t +lws_get_random(struct lws_context *context, void *buf, size_t len) { - return read(context->fd_random, (char *)buf, len); +#if defined(__COVERITY__) + memset(buf, 0, len); + return len; +#else + /* coverity[tainted_scalar] */ + return (size_t)read(context->fd_random, (char *)buf, len); +#endif } -LWS_VISIBLE void lwsl_emit_syslog(int level, const char *line) +void lwsl_emit_syslog(int level, const char *line) { int syslog_level = LOG_DEBUG; @@ -78,7 +101,8 @@ n = write(fd, buf, len); - fsync(fd); + if (fsync(fd)) + return 1; if (lseek(fd, 0, SEEK_SET) < 0) return 1; diff -Nru libwebsockets-3.2.1/lib/plat/unix/unix-pipe.c libwebsockets-4.1.6/lib/plat/unix/unix-pipe.c --- libwebsockets-3.2.1/lib/plat/unix/unix-pipe.c 2019-12-18 14:45:31.000000000 +0000 +++ libwebsockets-4.1.6/lib/plat/unix/unix-pipe.c 2020-12-01 17:40:26.000000000 +0000 @@ -1,34 +1,44 @@ /* * libwebsockets - small server side websockets and web server implementation * - * Copyright (C) 2010-2018 Andy Green + * Copyright (C) 2010 - 2020 Andy Green * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation: - * version 2.1 of the License. + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to + * deal in the Software without restriction, including without limitation the + * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or + * sell copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: * - * This library is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. * - * You should have received a copy of the GNU Lesser General Public - * License along with this library; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, - * MA 02110-1301 USA + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS + * IN THE SOFTWARE. */ +#if !defined(_GNU_SOURCE) #define _GNU_SOURCE -#include "core/private.h" - +#endif +#include "private-lib-core.h" int lws_plat_pipe_create(struct lws *wsi) { - struct lws_context_per_thread *pt = &wsi->context->pt[(int)wsi->tsi]; + struct lws_context_per_thread *pt = &wsi->a.context->pt[(int)wsi->tsi]; + +#if defined(LWS_HAVE_EVENTFD) + pt->dummy_pipe_fds[0] = eventfd(0, EFD_CLOEXEC | EFD_NONBLOCK); + pt->dummy_pipe_fds[1] = -1; + + return pt->dummy_pipe_fds[0] < 0 ? -1 : 0; -#if defined(LWS_HAVE_PIPE2) +#elif defined(LWS_HAVE_PIPE2) return pipe2(pt->dummy_pipe_fds, O_NONBLOCK); #else return pipe(pt->dummy_pipe_fds); @@ -38,19 +48,25 @@ int lws_plat_pipe_signal(struct lws *wsi) { - struct lws_context_per_thread *pt = &wsi->context->pt[(int)wsi->tsi]; + struct lws_context_per_thread *pt = &wsi->a.context->pt[(int)wsi->tsi]; +#if defined(LWS_HAVE_EVENTFD) + eventfd_t value = 1; + + return eventfd_write(pt->dummy_pipe_fds[0], value); +#else char buf = 0; int n; n = write(pt->dummy_pipe_fds[1], &buf, 1); return n != 1; +#endif } void lws_plat_pipe_close(struct lws *wsi) { - struct lws_context_per_thread *pt = &wsi->context->pt[(int)wsi->tsi]; + struct lws_context_per_thread *pt = &wsi->a.context->pt[(int)wsi->tsi]; if (pt->dummy_pipe_fds[0] && pt->dummy_pipe_fds[0] != -1) close(pt->dummy_pipe_fds[0]); diff -Nru libwebsockets-3.2.1/lib/plat/unix/unix-plugins.c libwebsockets-4.1.6/lib/plat/unix/unix-plugins.c --- libwebsockets-3.2.1/lib/plat/unix/unix-plugins.c 2019-12-18 14:45:31.000000000 +0000 +++ libwebsockets-4.1.6/lib/plat/unix/unix-plugins.c 2020-12-01 17:40:26.000000000 +0000 @@ -1,177 +1,105 @@ /* * libwebsockets - small server side websockets and web server implementation * - * Copyright (C) 2010-2018 Andy Green + * Copyright (C) 2010 - 2020 Andy Green * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation: - * version 2.1 of the License. + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to + * deal in the Software without restriction, including without limitation the + * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or + * sell copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: * - * This library is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. * - * You should have received a copy of the GNU Lesser General Public - * License along with this library; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, - * MA 02110-1301 USA + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS + * IN THE SOFTWARE. */ +#if !defined(_GNU_SOURCE) #define _GNU_SOURCE -#include "core/private.h" +#endif +#include "private-lib-core.h" #include #include - -#ifdef LWS_WITH_PLUGINS #include -#endif -#include - -static int filter(const struct dirent *ent) -{ - if (!strcmp(ent->d_name, ".") || !strcmp(ent->d_name, "..")) - return 0; - - return 1; -} -int -lws_plat_plugins_init(struct lws_context * context, const char * const *d) +const lws_plugin_header_t * +lws_plat_dlopen(struct lws_plugin **pplugin, const char *libpath, + const char *sofilename, const char *_class, + each_plugin_cb_t each, void *each_user) { - struct lws_plugin_capability lcaps; - struct lws_plugin *plugin; - lws_plugin_init_func initfunc; - struct dirent **namelist; - int n, i, m, ret = 0; - char path[256]; + const lws_plugin_header_t *hdr; + struct lws_plugin *pin; + char sym[96]; void *l; + int m; -#if defined(LWS_WITH_PLUGINS) && (UV_VERSION_MAJOR > 0) - if (lws_check_opt(context->options, LWS_SERVER_OPTION_LIBUV)) - return lws_uv_plugins_init(context, d); -#endif + if (strlen(sofilename) < 6) + /* [lib]...[.so] */ + return NULL; + + l = dlopen(libpath, RTLD_NOW); + if (!l) { + lwsl_err("%s: Error loading DSO: %s\n", __func__, dlerror()); - lwsl_notice(" Plugins:\n"); + return NULL; + } - while (d && *d) { - n = scandir(*d, &namelist, filter, alphasort); - if (n < 0) { - lwsl_err("Scandir on %s failed\n", *d); - return 1; - } - - for (i = 0; i < n; i++) { - if (strlen(namelist[i]->d_name) < 7) - goto inval; - - lwsl_notice(" %s\n", namelist[i]->d_name); - - lws_snprintf(path, sizeof(path) - 1, "%s/%s", *d, - namelist[i]->d_name); - l = dlopen(path, RTLD_NOW); - if (!l) { - lwsl_err("Error loading DSO: %s\n", dlerror()); - while (i++ < n) - free(namelist[i]); - goto bail; - } - /* we could open it, can we get his init function? */ - m = lws_snprintf(path, sizeof(path) - 1, "init_%s", - namelist[i]->d_name + 3 /* snip lib... */); - path[m - 3] = '\0'; /* snip the .so */ - initfunc = dlsym(l, path); - if (!initfunc) { - lwsl_err("Failed to get init on %s: %s", - namelist[i]->d_name, dlerror()); - dlclose(l); - } - lcaps.api_magic = LWS_PLUGIN_API_MAGIC; - m = initfunc(context, &lcaps); - if (m) { - lwsl_err("Initializing %s failed %d\n", - namelist[i]->d_name, m); - dlclose(l); - goto skip; - } - - plugin = lws_malloc(sizeof(*plugin), "plugin"); - if (!plugin) { - lwsl_err("OOM\n"); - goto bail; - } - plugin->list = context->plugin_list; - context->plugin_list = plugin; - lws_strncpy(plugin->name, namelist[i]->d_name, - sizeof(plugin->name)); - plugin->l = l; - plugin->caps = lcaps; - context->plugin_protocol_count += lcaps.count_protocols; - context->plugin_extension_count += lcaps.count_extensions; - - free(namelist[i]); - continue; - - skip: - dlclose(l); - inval: - free(namelist[i]); - } - free(namelist); - d++; + /* we could open it... can we get his export struct? */ + m = lws_snprintf(sym, sizeof(sym) - 1, "%s", sofilename); + if (m < 4) + goto bail; + if (!strcmp(&sym[m - 3], ".so")) + sym[m - 3] = '\0'; /* snip the .so */ + + hdr = (const lws_plugin_header_t *)dlsym(l, sym); + if (!hdr) { + lwsl_err("%s: Failed to get export '%s' from %s: %s\n", + __func__, sym, libpath, dlerror()); + goto bail; } - return 0; + if (hdr->api_magic != LWS_PLUGIN_API_MAGIC) { + lwsl_err("%s: plugin %s has outdated api %d (vs %d)\n", + __func__, libpath, hdr->api_magic, + LWS_PLUGIN_API_MAGIC); + goto bail; + } -bail: - free(namelist); + if (strcmp(hdr->_class, _class)) + goto bail; - return ret; -} + pin = lws_malloc(sizeof(*pin), __func__); + if (!pin) + goto bail; -int -lws_plat_plugins_destroy(struct lws_context * context) -{ - struct lws_plugin *plugin = context->plugin_list, *p; - lws_plugin_destroy_func func; - char path[256]; - int m; + pin->list = *pplugin; + *pplugin = pin; -#if defined(LWS_WITH_PLUGINS) && (UV_VERSION_MAJOR > 0) - if (lws_check_opt(context->options, LWS_SERVER_OPTION_LIBUV)) - return lws_uv_plugins_destroy(context); -#endif + pin->u.l = l; + pin->hdr = hdr; - if (!plugin) - return 0; + if (each) + each(pin, each_user); - lwsl_notice("%s\n", __func__); + return hdr; - while (plugin) { - p = plugin; - m = lws_snprintf(path, sizeof(path) - 1, "destroy_%s", - plugin->name + 3); - path[m - 3] = '\0'; - func = dlsym(plugin->l, path); - if (!func) { - lwsl_err("Failed to get destroy on %s: %s", - plugin->name, dlerror()); - goto next; - } - m = func(context); - if (m) - lwsl_err("Initializing %s failed %d\n", - plugin->name, m); -next: - dlclose(p->l); - plugin = p->list; - p->list = NULL; - free(p); - } +bail: + dlclose(l); - context->plugin_list = NULL; + return NULL; +} - return 0; +int +lws_plat_destroy_dl(struct lws_plugin *p) +{ + return dlclose(p->u.l); } diff -Nru libwebsockets-3.2.1/lib/plat/unix/unix-resolv.c libwebsockets-4.1.6/lib/plat/unix/unix-resolv.c --- libwebsockets-3.2.1/lib/plat/unix/unix-resolv.c 1970-01-01 00:00:00.000000000 +0000 +++ libwebsockets-4.1.6/lib/plat/unix/unix-resolv.c 2020-12-01 17:40:26.000000000 +0000 @@ -0,0 +1,111 @@ +/* + * libwebsockets - small server side websockets and web server implementation + * + * Copyright (C) 2010 - 2019 Andy Green + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to + * deal in the Software without restriction, including without limitation the + * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or + * sell copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS + * IN THE SOFTWARE. + */ + +#include "private-lib-core.h" + +lws_async_dns_server_check_t +lws_plat_asyncdns_init(struct lws_context *context, lws_sockaddr46 *sa46) +{ + lws_async_dns_server_check_t s = LADNS_CONF_SERVER_CHANGED; + lws_sockaddr46 sa46t; + lws_tokenize_t ts; + int fd, n, ns = 0; + char ads[48], *r; + + r = (char *)context->pt[0].serv_buf; + + /* grab the first chunk of /etc/resolv.conf */ + + fd = open("/etc/resolv.conf", LWS_O_RDONLY); + if (fd < 0) + return LADNS_CONF_SERVER_UNKNOWN; + + n = read(fd, r, context->pt_serv_buf_size - 1); + close(fd); + if (n < 0) + return LADNS_CONF_SERVER_UNKNOWN; + + r[n] = '\0'; + lws_tokenize_init(&ts, r, LWS_TOKENIZE_F_DOT_NONTERM | + LWS_TOKENIZE_F_NO_FLOATS | + LWS_TOKENIZE_F_NO_INTEGERS | + LWS_TOKENIZE_F_MINUS_NONTERM | + LWS_TOKENIZE_F_HASH_COMMENT); + do { + ts.e = lws_tokenize(&ts); + if (ts.e != LWS_TOKZE_TOKEN) { + ns = 0; + continue; + } + + if (!ns && !strncmp("nameserver", ts.token, ts.token_len)) { + ns = 1; + continue; + } + if (!ns) + continue; + + /* we are a token just after the "nameserver" token */ + + ns = 0; + if (ts.token_len > (int)sizeof(ads) - 1) + continue; + + memcpy(ads, ts.token, ts.token_len); + ads[ts.token_len] = '\0'; + if (lws_sa46_parse_numeric_address(ads, &sa46t) < 0) + continue; + + if (!lws_sa46_compare_ads(sa46, &sa46t)) + s = LADNS_CONF_SERVER_SAME; + + *sa46 = sa46t; + + return s; + + } while (ts.e > 0); + + return LADNS_CONF_SERVER_UNKNOWN; +} + +/* + * Platform-specific ntpclient server configuration + */ + +int +lws_plat_ntpclient_config(struct lws_context *context) +{ +#if defined(LWS_HAVE_GETENV) + char *ntpsrv = getenv("LWS_NTP_SERVER"); + + if (ntpsrv && strlen(ntpsrv) < 64) { + lws_system_blob_direct_set(lws_system_get_blob(context, + LWS_SYSBLOB_TYPE_NTP_SERVER, 0), + (const uint8_t *)ntpsrv, + strlen(ntpsrv)); + return 1; + } +#endif + return 0; +} diff -Nru libwebsockets-3.2.1/lib/plat/unix/unix-service.c libwebsockets-4.1.6/lib/plat/unix/unix-service.c --- libwebsockets-3.2.1/lib/plat/unix/unix-service.c 2019-12-18 14:45:31.000000000 +0000 +++ libwebsockets-4.1.6/lib/plat/unix/unix-service.c 2020-12-01 17:40:26.000000000 +0000 @@ -1,26 +1,31 @@ /* * libwebsockets - small server side websockets and web server implementation * - * Copyright (C) 2010-2018 Andy Green + * Copyright (C) 2010 - 2019 Andy Green * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation: - * version 2.1 of the License. + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to + * deal in the Software without restriction, including without limitation the + * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or + * sell copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: * - * This library is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. * - * You should have received a copy of the GNU Lesser General Public - * License along with this library; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, - * MA 02110-1301 USA + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS + * IN THE SOFTWARE. */ +#if !defined(_GNU_SOURCE) #define _GNU_SOURCE -#include "core/private.h" +#endif +#include "private-lib-core.h" int lws_poll_listen_fd(struct lws_pollfd *fd) @@ -32,9 +37,9 @@ _lws_plat_service_forced_tsi(struct lws_context *context, int tsi) { struct lws_context_per_thread *pt = &context->pt[tsi]; - int m, n; + int m, n, r; - lws_service_flag_pending(context, tsi); + r = lws_service_flag_pending(context, tsi); /* any socket with events to service? */ for (n = 0; n < (int)pt->fds_count; n++) { @@ -54,7 +59,7 @@ lws_service_do_ripe_rxflow(pt); - return 0; + return r; } #define LWS_POLL_WAIT_LIMIT 2000000000 @@ -66,14 +71,14 @@ volatile struct lws_context_per_thread *vpt; struct lws_context_per_thread *pt; lws_usec_t timeout_us, us; - int n = -1; + int n; #if (defined(LWS_ROLE_WS) && !defined(LWS_WITHOUT_EXTENSIONS)) || defined(LWS_WITH_TLS) int m; #endif /* stay dead once we are dead */ - if (!context || !context->vhost_list) + if (!context) return 1; pt = &context->pt[tsi]; @@ -91,14 +96,14 @@ if (context->event_loop_ops->run_pt) context->event_loop_ops->run_pt(context, tsi); - if (!pt->service_tid_detected) { - struct lws _lws; + if (!pt->service_tid_detected && context->vhost_list) { + lws_fakewsi_def_plwsa(pt); - memset(&_lws, 0, sizeof(_lws)); - _lws.context = context; + lws_fakewsi_prep_plwsa_ctx(context); pt->service_tid = context->vhost_list->protocols[0].callback( - &_lws, LWS_CALLBACK_GET_THREAD_ID, + (struct lws *)plwsa, + LWS_CALLBACK_GET_THREAD_ID, NULL, NULL, 0); pt->service_tid_detected = 1; } @@ -108,7 +113,7 @@ /* * service ripe scheduled events, and limit wait to next expected one */ - us = __lws_sul_service_ripe(&pt->pt_sul_owner, us); + us = __lws_sul_service_ripe(pt->pt_sul_owner, LWS_COUNT_PT_SUL_OWNERS, us); if (us && us < timeout_us) timeout_us = us; @@ -123,8 +128,6 @@ /* ensure we don't wrap at 2^31 with poll()'s signed int ms */ timeout_us /= LWS_US_PER_MS; /* ms now */ - if (timeout_us > LWS_POLL_WAIT_LIMIT) - timeout_us = LWS_POLL_WAIT_LIMIT; vpt->inside_poll = 1; lws_memory_barrier(); @@ -201,15 +204,14 @@ return 0; } - if (_lws_plat_service_forced_tsi(context, tsi)) + if (_lws_plat_service_forced_tsi(context, tsi) < 0) return -1; - return 0; -} + if (pt->destroy_self) { + lws_context_destroy(pt->context); + return -1; + } -int -lws_plat_check_connection_error(struct lws *wsi) -{ return 0; } diff -Nru libwebsockets-3.2.1/lib/plat/unix/unix-sockets.c libwebsockets-4.1.6/lib/plat/unix/unix-sockets.c --- libwebsockets-3.2.1/lib/plat/unix/unix-sockets.c 2019-12-18 14:45:31.000000000 +0000 +++ libwebsockets-4.1.6/lib/plat/unix/unix-sockets.c 2020-12-01 17:40:26.000000000 +0000 @@ -1,31 +1,50 @@ /* * libwebsockets - small server side websockets and web server implementation * - * Copyright (C) 2010-2018 Andy Green + * Copyright (C) 2010 - 2019 Andy Green * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation: - * version 2.1 of the License. + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to + * deal in the Software without restriction, including without limitation the + * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or + * sell copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: * - * This library is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. * - * You should have received a copy of the GNU Lesser General Public - * License along with this library; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, - * MA 02110-1301 USA + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS + * IN THE SOFTWARE. */ +#if !defined(_GNU_SOURCE) #define _GNU_SOURCE -#include "core/private.h" +#endif +#include "private-lib-core.h" + +#include + +#if !defined(LWS_DETECTED_PLAT_IOS) +#include +#endif + +#include #include #include - +#if defined(LWS_WITH_MBEDTLS) +#if defined(LWS_HAVE_MBEDTLS_NET_SOCKETS) +#include "mbedtls/net_sockets.h" +#else +#include "mbedtls/net.h" +#endif +#endif int lws_send_pipe_choked(struct lws *wsi) @@ -72,7 +91,7 @@ } int -lws_plat_set_nonblocking(int fd) +lws_plat_set_nonblocking(lws_sockfd_type fd) { return fcntl(fd, F_SETFL, O_NONBLOCK) < 0; } @@ -184,9 +203,13 @@ struct sockaddr_in6 *addr6 = (struct sockaddr_in6 *)addr; #endif - getifaddrs(&ifr); + if (getifaddrs(&ifr)) { + lwsl_err("%s: unable to getifaddrs: errno %d\n", __func__, errno); + + return LWS_ITOSA_USABLE; + } for (ifc = ifr; ifc != NULL && rc; ifc = ifc->ifa_next) { - if (!ifc->ifa_addr) + if (!ifc->ifa_addr || !ifc->ifa_name) continue; lwsl_debug(" interface %s vs %s (fam %d) ipv6 %d\n", @@ -263,3 +286,232 @@ { return inet_pton(af, src, dst); } + +int +lws_plat_ifname_to_hwaddr(int fd, const char *ifname, uint8_t *hwaddr, int len) +{ +#if defined(__linux__) + struct ifreq i; + + memset(&i, 0, sizeof(i)); + lws_strncpy(i.ifr_name, ifname, sizeof(i.ifr_name)); + + if (ioctl(fd, SIOCGIFHWADDR, &i) < 0) + return -1; + + memcpy(hwaddr, &i.ifr_hwaddr.sa_data, 6); + + return 6; +#else + lwsl_err("%s: UNIMPLEMENTED on this platform\n", __func__); + + return -1; +#endif +} + +int +lws_plat_rawudp_broadcast(uint8_t *p, const uint8_t *canned, int canned_len, + int n, int fd, const char *iface) +{ +#if defined(__linux__) + struct sockaddr_ll sll; + uint16_t *p16 = (uint16_t *)p; + uint32_t ucs = 0; + + memcpy(p, canned, canned_len); + + p[2] = n >> 8; + p[3] = n; + + while (p16 < (uint16_t *)(p + 20)) + ucs += ntohs(*p16++); + + ucs += ucs >> 16; + ucs ^= 0xffff; + + p[10] = ucs >> 8; + p[11] = ucs; + p[24] = (n - 20) >> 8; + p[25] = (n - 20); + + memset(&sll, 0, sizeof(sll)); + sll.sll_family = AF_PACKET; + sll.sll_protocol = htons(0x800); + sll.sll_halen = 6; + sll.sll_ifindex = if_nametoindex(iface); + memset(sll.sll_addr, 0xff, 6); + + return sendto(fd, p, n, 0, (struct sockaddr *)&sll, sizeof(sll)); +#else + lwsl_err("%s: UNIMPLEMENTED on this platform\n", __func__); + + return -1; +#endif +} + +int +lws_plat_if_up(const char *ifname, int fd, int up) +{ +#if defined(__linux__) + struct ifreq ifr; + + memset(&ifr, 0, sizeof(ifr)); + lws_strncpy(ifr.ifr_name, ifname, IFNAMSIZ); + + if (ioctl(fd, SIOCGIFFLAGS, &ifr) < 0) { + lwsl_err("%s: SIOCGIFFLAGS fail\n", __func__); + return 1; + } + + if (up) + ifr.ifr_flags |= IFF_UP; + else + ifr.ifr_flags &= ~IFF_UP; + + if (ioctl(fd, SIOCSIFFLAGS, &ifr) < 0) { + lwsl_err("%s: SIOCSIFFLAGS fail\n", __func__); + return 1; + } + + return 0; +#else + lwsl_err("%s: UNIMPLEMENTED on this platform\n", __func__); + + return -1; +#endif +} + +int +lws_plat_BINDTODEVICE(lws_sockfd_type fd, const char *ifname) +{ +#if defined(__linux__) + struct ifreq i; + + memset(&i, 0, sizeof(i)); + i.ifr_addr.sa_family = AF_INET; + lws_strncpy(i.ifr_ifrn.ifrn_name, ifname, + sizeof(i.ifr_ifrn.ifrn_name)); + if (setsockopt(fd, SOL_SOCKET, SO_BINDTODEVICE, &i, sizeof(i)) < 0) { + lwsl_notice("%s: failed %d\n", __func__, LWS_ERRNO); + return 1; + } + + return 0; +#else + lwsl_err("%s: UNIMPLEMENTED on this platform\n", __func__); + + return -1; +#endif +} + +int +lws_plat_ifconfig_ip(const char *ifname, int fd, uint8_t *ip, uint8_t *mask_ip, + uint8_t *gateway_ip) +{ +#if defined(__linux__) + struct sockaddr_in sin; + struct rtentry route; + struct ifreq ifr; + + memset(&ifr, 0, sizeof(ifr)); + memset(&route, 0, sizeof(route)); + memset(&sin, 0, sizeof(sin)); + + lws_strncpy(ifr.ifr_name, ifname, IFNAMSIZ); + + lws_plat_if_up(ifname, fd, 0); + + sin.sin_family = AF_INET; + sin.sin_addr.s_addr = htonl(*(uint32_t *)ip); + + memcpy(&ifr.ifr_addr, &sin, sizeof(struct sockaddr)); + if (ioctl(fd, SIOCSIFADDR, &ifr) < 0) { + lwsl_err("%s: SIOCSIFADDR fail\n", __func__); + return 1; + } + + sin.sin_addr.s_addr = htonl(*(uint32_t *)mask_ip); + memcpy(&ifr.ifr_addr, &sin, sizeof(struct sockaddr)); + if (ioctl(fd, SIOCSIFNETMASK, &ifr) < 0) { + lwsl_err("%s: SIOCSIFNETMASK fail\n", __func__); + return 1; + } + + lws_plat_if_up(ifname, fd, 1); + + sin.sin_addr.s_addr = htonl(*(uint32_t *)gateway_ip); + memcpy(&route.rt_gateway, &sin, sizeof(struct sockaddr)); + + sin.sin_addr.s_addr = 0; + memcpy(&route.rt_dst, &sin, sizeof(struct sockaddr)); + memcpy(&route.rt_genmask, &sin, sizeof(struct sockaddr)); + + route.rt_flags = RTF_UP | RTF_GATEWAY; + route.rt_metric = 100; + route.rt_dev = (char *)ifname; + + if (ioctl(fd, SIOCADDRT, &route) < 0) { + lwsl_err("%s: SIOCADDRT 0x%x fail: %d\n", __func__, + (unsigned int)htonl(*(uint32_t *)gateway_ip), LWS_ERRNO); + return 1; + } + + return 0; +#else + lwsl_err("%s: UNIMPLEMENTED on this platform\n", __func__); + + return -1; +#endif +} + +#if defined(LWS_WITH_MBEDTLS) +int +lws_plat_mbedtls_net_send(void *ctx, const uint8_t *buf, size_t len) +{ + int fd = ((mbedtls_net_context *) ctx)->fd; + int ret; + + if (fd < 0) + return MBEDTLS_ERR_NET_INVALID_CONTEXT; + + ret = write(fd, buf, len); + if (ret >= 0) + return ret; + + if (errno == EAGAIN || errno == EWOULDBLOCK) + return MBEDTLS_ERR_SSL_WANT_WRITE; + + if (errno == EPIPE || errno == ECONNRESET) + return MBEDTLS_ERR_NET_CONN_RESET; + + if( errno == EINTR ) + return MBEDTLS_ERR_SSL_WANT_WRITE; + + return MBEDTLS_ERR_NET_SEND_FAILED; +} + +int +lws_plat_mbedtls_net_recv(void *ctx, unsigned char *buf, size_t len) +{ + int fd = ((mbedtls_net_context *) ctx)->fd; + int ret; + + if (fd < 0) + return MBEDTLS_ERR_NET_INVALID_CONTEXT; + + ret = (int)read(fd, buf, len); + if (ret >= 0) + return ret; + + if (errno == EAGAIN || errno == EWOULDBLOCK) + return MBEDTLS_ERR_SSL_WANT_READ; + + if (errno == EPIPE || errno == ECONNRESET) + return MBEDTLS_ERR_NET_CONN_RESET; + + if (errno == EINTR) + return MBEDTLS_ERR_SSL_WANT_READ; + + return MBEDTLS_ERR_NET_RECV_FAILED; +} +#endif diff -Nru libwebsockets-3.2.1/lib/plat/unix/unix-spawn.c libwebsockets-4.1.6/lib/plat/unix/unix-spawn.c --- libwebsockets-3.2.1/lib/plat/unix/unix-spawn.c 1970-01-01 00:00:00.000000000 +0000 +++ libwebsockets-4.1.6/lib/plat/unix/unix-spawn.c 2020-12-01 17:40:26.000000000 +0000 @@ -0,0 +1,593 @@ +/* + * libwebsockets - small server side websockets and web server implementation + * + * Copyright (C) 2010 - 2020 Andy Green + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to + * deal in the Software without restriction, including without limitation the + * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or + * sell copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS + * IN THE SOFTWARE. + */ + +#if !defined(_GNU_SOURCE) +#define _GNU_SOURCE +#endif + +#include "private-lib-core.h" +#include + +void +lws_spawn_timeout(struct lws_sorted_usec_list *sul) +{ + struct lws_spawn_piped *lsp = lws_container_of(sul, + struct lws_spawn_piped, sul); + + lwsl_warn("%s: spawn exceeded timeout, killing\n", __func__); + + lws_spawn_piped_kill_child_process(lsp); +} + +void +lws_spawn_sul_reap(struct lws_sorted_usec_list *sul) +{ + struct lws_spawn_piped *lsp = lws_container_of(sul, + struct lws_spawn_piped, sul_reap); + + lwsl_notice("%s: reaping spawn after last stdpipe, tries left %d\n", + __func__, lsp->reap_retry_budget); + if (!lws_spawn_reap(lsp) && !lsp->pipes_alive) { + if (--lsp->reap_retry_budget) { + lws_sul_schedule(lsp->info.vh->context, lsp->info.tsi, + &lsp->sul_reap, lws_spawn_sul_reap, + 250 * LWS_US_PER_MS); + } else { + lwsl_err("%s: Unable to reap lsp %p, killing\n", + __func__, lsp); + lsp->reap_retry_budget = 20; + lws_spawn_piped_kill_child_process(lsp); + } + } +} + +static struct lws * +lws_create_basic_wsi(struct lws_context *context, int tsi, + const struct lws_role_ops *ops) +{ + size_t s = sizeof(struct lws); + struct lws *new_wsi; + + if (!context->vhost_list) + return NULL; + + if ((unsigned int)context->pt[tsi].fds_count == + context->fd_limit_per_thread - 1) { + lwsl_err("no space for new conn\n"); + return NULL; + } + +#if defined(LWS_WITH_EVENT_LIBS) + s += context->event_loop_ops->evlib_size_wsi; +#endif + + new_wsi = lws_zalloc(s, "new wsi"); + if (new_wsi == NULL) { + lwsl_err("Out of memory for new connection\n"); + return NULL; + } + +#if defined(LWS_WITH_EVENT_LIBS) + new_wsi->evlib_wsi = (uint8_t *)new_wsi + sizeof(*new_wsi); +#endif + + new_wsi->tsi = tsi; + new_wsi->a.context = context; + new_wsi->pending_timeout = NO_PENDING_TIMEOUT; + new_wsi->rxflow_change_to = LWS_RXFLOW_ALLOW; + + /* initialize the instance struct */ + + lws_role_transition(new_wsi, 0, LRS_ESTABLISHED, ops); + + new_wsi->hdr_parsing_completed = 0; + new_wsi->position_in_fds_table = LWS_NO_FDS_POS; + + /* + * these can only be set once the protocol is known + * we set an unestablished connection's protocol pointer + * to the start of the defauly vhost supported list, so it can look + * for matching ones during the handshake + */ + + new_wsi->user_space = NULL; + new_wsi->desc.sockfd = LWS_SOCK_INVALID; + context->count_wsi_allocated++; + + return new_wsi; +} + +void +lws_spawn_piped_destroy(struct lws_spawn_piped **_lsp) +{ + struct lws_spawn_piped *lsp = *_lsp; + int n; + + if (!lsp) + return; + + lws_dll2_remove(&lsp->dll); + + lws_sul_cancel(&lsp->sul); + lws_sul_cancel(&lsp->sul_reap); + + for (n = 0; n < 3; n++) { +#if 0 + if (lsp->pipe_fds[n][!!(n == 0)] == 0) + lwsl_err("ZERO FD IN CGI CLOSE"); + + if (lsp->pipe_fds[n][!!(n == 0)] >= 0) { + close(lsp->pipe_fds[n][!!(n == 0)]); + lsp->pipe_fds[n][!!(n == 0)] = LWS_SOCK_INVALID; + } +#endif + if (lsp->stdwsi[n]) { + lws_set_timeout(lsp->stdwsi[n], 1, LWS_TO_KILL_ASYNC); + lsp->stdwsi[n] = NULL; + } + } + + lws_free_set_NULL((*_lsp)); +} + +int +lws_spawn_reap(struct lws_spawn_piped *lsp) +{ + long hz = sysconf(_SC_CLK_TCK); /* accounting Hz */ + void *opaque = lsp->info.opaque; + lsp_cb_t cb = lsp->info.reap_cb; + struct lws_spawn_piped temp; + struct tms tms; + int n; + + if (lsp->child_pid < 1) + return 0; + + /* check if exited, do not reap yet */ + + memset(&lsp->si, 0, sizeof(lsp->si)); + n = waitid(P_PID, lsp->child_pid, &lsp->si, WEXITED | WNOHANG | WNOWAIT); + if (n < 0) { + lwsl_info("%s: child %d still running\n", __func__, lsp->child_pid); + return 0; + } + + if (!lsp->si.si_code) + return 0; + + /* his process has exited... */ + + if (!lsp->reaped) { + /* mark the earliest time we knew he had gone */ + lsp->reaped = lws_now_usecs(); + + /* + * Switch the timeout to restrict the amount of grace time + * to drain stdwsi + */ + + lws_sul_schedule(lsp->info.vh->context, lsp->info.tsi, + &lsp->sul, lws_spawn_timeout, + 5 * LWS_US_PER_SEC); + } + + /* + * Stage finalizing our reaction to the process going down until the + * stdwsi flushed whatever is in flight and all noticed they were + * closed. For that reason, each stdwsi close must call lws_spawn_reap + * to check if that was the last one and we can proceed with the reap. + */ + + if (!lsp->ungraceful && lsp->pipes_alive) { + lwsl_info("%s: %d stdwsi alive, not reaping\n", __func__, + lsp->pipes_alive); + return 0; + } + + /* we reached the reap point, no need for timeout wait */ + + lws_sul_cancel(&lsp->sul); + + /* + * All the stdwsi went down, nothing more is coming... it's over + * Collect the final information and then reap the dead process + */ + + if (times(&tms) != (clock_t) -1) { + /* + * Cpu accounting in us + */ + lsp->accounting[0] = ((uint64_t)tms.tms_cstime * 1000000) / hz; + lsp->accounting[1] = ((uint64_t)tms.tms_cutime * 1000000) / hz; + lsp->accounting[2] = ((uint64_t)tms.tms_stime * 1000000) / hz; + lsp->accounting[3] = ((uint64_t)tms.tms_utime * 1000000) / hz; + } + + temp = *lsp; + n = waitid(P_PID, lsp->child_pid, &temp.si, WEXITED | WNOHANG); + temp.si.si_status &= 0xff; /* we use b8 + for flags */ + lwsl_info("%s: waitd says %d, process exit %d\n", + __func__, n, temp.si.si_status); + + lsp->child_pid = -1; + + /* destroy the lsp itself first (it's freed and plsp set NULL */ + + if (lsp->info.plsp) + lws_spawn_piped_destroy(lsp->info.plsp); + + /* then do the parent callback informing it's destroyed */ + + if (cb) + cb(opaque, temp.accounting, &temp.si, + temp.we_killed_him_timeout | + (temp.we_killed_him_spew << 1)); + + return 1; /* was reaped */ +} + +int +lws_spawn_piped_kill_child_process(struct lws_spawn_piped *lsp) +{ + int status, n; + + if (lsp->child_pid <= 0) + return 1; + + lsp->ungraceful = 1; /* don't wait for flushing, just kill it */ + + if (lws_spawn_reap(lsp)) + /* that may have invalidated lsp */ + return 0; + + /* kill the process group */ + n = kill(-lsp->child_pid, SIGTERM); + lwsl_debug("%s: SIGTERM child PID %d says %d (errno %d)\n", __func__, + lsp->child_pid, n, errno); + if (n < 0) { + /* + * hum seen errno=3 when process is listed in ps, + * it seems we don't always retain process grouping + * + * Direct these fallback attempt to the exact child + */ + n = kill(lsp->child_pid, SIGTERM); + if (n < 0) { + n = kill(lsp->child_pid, SIGPIPE); + if (n < 0) { + n = kill(lsp->child_pid, SIGKILL); + if (n < 0) + lwsl_info("%s: SIGKILL PID %d " + "failed errno %d " + "(maybe zombie)\n", __func__, + lsp->child_pid, errno); + } + } + } + + /* He could be unkillable because he's a zombie */ + + n = 1; + while (n > 0) { + n = waitpid(-lsp->child_pid, &status, WNOHANG); + if (n > 0) + lwsl_debug("%s: reaped PID %d\n", __func__, n); + if (n <= 0) { + n = waitpid(lsp->child_pid, &status, WNOHANG); + if (n > 0) + lwsl_debug("%s: reaped PID %d\n", __func__, n); + } + } + + lws_spawn_reap(lsp); + /* that may have invalidated lsp */ + + return 0; +} + +/* + * Deals with spawning a subprocess and executing it securely with stdin/out/err + * diverted into pipes + */ + +struct lws_spawn_piped * +lws_spawn_piped(const struct lws_spawn_piped_info *i) +{ + const struct lws_protocols *pcol = i->vh->context->vhost_list->protocols; + struct lws_context *context = i->vh->context; + struct lws_spawn_piped *lsp; + const char *wd; + int n, m; + + if (i->protocol_name) + pcol = lws_vhost_name_to_protocol(i->vh, i->protocol_name); + if (!pcol) { + lwsl_err("%s: unknown protocol %s\n", __func__, + i->protocol_name ? i->protocol_name : "default"); + + return NULL; + } + + lsp = lws_zalloc(sizeof(*lsp), __func__); + if (!lsp) + return NULL; + + /* wholesale take a copy of info */ + lsp->info = *i; + lsp->reap_retry_budget = 20; + + /* + * Prepare the stdin / out / err pipes + */ + + for (n = 0; n < 3; n++) { + lsp->pipe_fds[n][0] = -1; + lsp->pipe_fds[n][1] = -1; + } + + /* create pipes for [stdin|stdout] and [stderr] */ + + for (n = 0; n < 3; n++) { + if (pipe(lsp->pipe_fds[n]) == -1) + goto bail1; + lws_plat_apply_FD_CLOEXEC(lsp->pipe_fds[n][n == 0]); + } + + /* + * At this point, we have 6 pipe fds open on lws side and no wsis + * bound to them + */ + + /* create wsis for each stdin/out/err fd */ + + for (n = 0; n < 3; n++) { + lsp->stdwsi[n] = lws_create_basic_wsi(i->vh->context, i->tsi, + i->ops ? i->ops : &role_ops_raw_file); + if (!lsp->stdwsi[n]) { + lwsl_err("%s: unable to create lsp stdwsi\n", __func__); + goto bail2; + } + lsp->stdwsi[n]->lsp_channel = n; + lws_vhost_bind_wsi(i->vh, lsp->stdwsi[n]); + lsp->stdwsi[n]->a.protocol = pcol; + lsp->stdwsi[n]->a.opaque_user_data = i->opaque; + + lwsl_debug("%s: lsp stdwsi %p: pipe idx %d -> fd %d / %d\n", __func__, + lsp->stdwsi[n], n, lsp->pipe_fds[n][n == 0], + lsp->pipe_fds[n][n != 0]); + + /* read side is 0, stdin we want the write side, others read */ + + lsp->stdwsi[n]->desc.sockfd = lsp->pipe_fds[n][n == 0]; + if (fcntl(lsp->pipe_fds[n][n == 0], F_SETFL, O_NONBLOCK) < 0) { + lwsl_err("%s: setting NONBLOCK failed\n", __func__); + goto bail2; + } + + /* + * We have bound 3 x pipe fds to wsis, wr side of stdin and rd + * side of stdout / stderr... those are marked CLOEXEC so they + * won't go through the fork + * + * rd side of stdin and wr side of stdout / stderr are open but + * not bound to anything on lws side. + */ + } + + /* + * Stitch the wsi fd into the poll wait + */ + + for (n = 0; n < 3; n++) { + if (context->event_loop_ops->sock_accept) + if (context->event_loop_ops->sock_accept(lsp->stdwsi[n])) + goto bail3; + + if (__insert_wsi_socket_into_fds(context, lsp->stdwsi[n])) + goto bail3; + if (i->opt_parent) { + lsp->stdwsi[n]->parent = i->opt_parent; + lsp->stdwsi[n]->sibling_list = i->opt_parent->child_list; + i->opt_parent->child_list = lsp->stdwsi[n]; + } + } + + if (lws_change_pollfd(lsp->stdwsi[LWS_STDIN], LWS_POLLIN, LWS_POLLOUT)) + goto bail3; + if (lws_change_pollfd(lsp->stdwsi[LWS_STDOUT], LWS_POLLOUT, LWS_POLLIN)) + goto bail3; + if (lws_change_pollfd(lsp->stdwsi[LWS_STDERR], LWS_POLLOUT, LWS_POLLIN)) + goto bail3; + + lwsl_info("%s: fds in %d, out %d, err %d\n", __func__, + lsp->stdwsi[LWS_STDIN]->desc.sockfd, + lsp->stdwsi[LWS_STDOUT]->desc.sockfd, + lsp->stdwsi[LWS_STDERR]->desc.sockfd); + + /* we are ready with the redirection pipes... do the (v)fork */ +#if !defined(LWS_HAVE_VFORK) || !defined(LWS_HAVE_EXECVPE) + lsp->child_pid = fork(); +#else + lsp->child_pid = vfork(); +#endif + if (lsp->child_pid < 0) { + lwsl_err("%s: fork failed, errno %d", __func__, errno); + goto bail3; + } + +#if defined(__linux__) + if (!lsp->child_pid) + prctl(PR_SET_PDEATHSIG, SIGTERM); +#endif + + if (lsp->info.disable_ctrlc) + /* stops non-daemonized main processess getting SIGINT + * from TTY */ +#if defined(__FreeBSD__) + setpgid(0, 0); +#else + setpgrp(); +#endif + + if (lsp->child_pid) { + + /* + * We are the parent process. We can close our copy of the + * "other" side of the pipe fds, ie, rd for stdin and wr for + * stdout / stderr. + */ + for (n = 0; n < 3; n++) + /* these guys didn't have any wsi footprint */ + close(lsp->pipe_fds[n][n != 0]); + + lsp->pipes_alive = 3; + lsp->created = lws_now_usecs(); + + lwsl_info("%s: lsp %p spawned PID %d\n", __func__, lsp, + lsp->child_pid); + + lws_sul_schedule(context, i->tsi, &lsp->sul, lws_spawn_timeout, + i->timeout_us ? i->timeout_us : + 300 * LWS_US_PER_SEC); + + if (i->owner) + lws_dll2_add_head(&lsp->dll, i->owner); + + if (i->timeout_us) + lws_sul_schedule(context, i->tsi, &lsp->sul, + lws_spawn_timeout, i->timeout_us); + + return lsp; + } + + /* + * We are the forked process, redirect and kill inherited things. + * + * Because of vfork(), we cannot do anything that changes pages in + * the parent environment. Stuff that changes kernel state for the + * process is OK. Stuff that happens after the execvpe() is OK. + */ + + if (i->chroot_path && chroot(i->chroot_path)) { + lwsl_err("%s: child chroot %s failed, errno %d\n", + __func__, i->chroot_path, errno); + + exit(2); + } + + /* cwd: somewhere we can at least read things and enter it */ + + wd = i->wd; + if (!wd) + wd = "/tmp"; + if (chdir(wd)) + lwsl_notice("%s: Failed to cd to %s\n", __func__, wd); + + /* + * Bind the child's stdin / out / err to its side of our pipes + */ + + for (m = 0; m < 3; m++) { + if (dup2(lsp->pipe_fds[m][m != 0], m) < 0) { + lwsl_err("%s: stdin dup2 failed\n", __func__); + goto bail3; + } + /* + * CLOEXEC on the lws-side of the pipe fds should have already + * dealt with closing those for the child perspective. + * + * Now it has done the dup, the child should close its original + * copies of its side of the pipes. + */ + + close(lsp->pipe_fds[m][m != 0]); + } + +#if !defined(LWS_HAVE_VFORK) || !defined(LWS_HAVE_EXECVPE) +#if defined(__linux__) || defined(__APPLE__) + m = 0; + while (i->env_array[m]){ + char *p = strchr(i->env_array[m], '='); + *p++ = '\0'; + setenv(i->env_array[m], p, 1); + m++; + } +#endif + execvp(i->exec_array[0], (char * const *)&i->exec_array[0]); +#else + execvpe(i->exec_array[0], (char * const *)&i->exec_array[0], + &i->env_array[0]); +#endif + + lwsl_err("%s: child exec of %s failed %d\n", __func__, i->exec_array[0], + LWS_ERRNO); + + _exit(1); + +bail3: + + while (--n >= 0) + __remove_wsi_socket_from_fds(lsp->stdwsi[n]); +bail2: + for (n = 0; n < 3; n++) + if (lsp->stdwsi[n]) + __lws_free_wsi(lsp->stdwsi[n]); + +bail1: + for (n = 0; n < 3; n++) { + if (lsp->pipe_fds[n][0] >= 0) + close(lsp->pipe_fds[n][0]); + if (lsp->pipe_fds[n][1] >= 0) + close(lsp->pipe_fds[n][1]); + } + + lws_free(lsp); + + lwsl_err("%s: failed\n", __func__); + + return NULL; +} + +void +lws_spawn_stdwsi_closed(struct lws_spawn_piped *lsp, struct lws *wsi) +{ + int n; + + assert(lsp); + lsp->pipes_alive--; + lwsl_debug("%s: pipes alive %d\n", __func__, lsp->pipes_alive); + if (!lsp->pipes_alive) + lws_sul_schedule(lsp->info.vh->context, lsp->info.tsi, + &lsp->sul_reap, lws_spawn_sul_reap, 1); + + for (n = 0; n < 3; n++) + if (lsp->stdwsi[n] == wsi) + lsp->stdwsi[n] = NULL; +} + +int +lws_spawn_get_stdfd(struct lws *wsi) +{ + return wsi->lsp_channel; +} diff -Nru libwebsockets-3.2.1/lib/plat/windows/CMakeLists.txt libwebsockets-4.1.6/lib/plat/windows/CMakeLists.txt --- libwebsockets-3.2.1/lib/plat/windows/CMakeLists.txt 1970-01-01 00:00:00.000000000 +0000 +++ libwebsockets-4.1.6/lib/plat/windows/CMakeLists.txt 2020-12-01 17:40:26.000000000 +0000 @@ -0,0 +1,103 @@ +# +# libwebsockets - small server side websockets and web server implementation +# +# Copyright (C) 2010 - 2020 Andy Green +# +# Permission is hereby granted, free of charge, to any person obtaining a copy +# of this software and associated documentation files (the "Software"), to +# deal in the Software without restriction, including without limitation the +# rights to use, copy, modify, merge, publish, distribute, sublicense, and/or +# sell copies of the Software, and to permit persons to whom the Software is +# furnished to do so, subject to the following conditions: +# +# The above copyright notice and this permission notice shall be included in +# all copies or substantial portions of the Software. +# +# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING +# FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS +# IN THE SOFTWARE. +# +# The strategy is to only export to PARENT_SCOPE +# +# - changes to LIB_LIST +# - changes to SOURCES +# - includes via include_directories +# +# and keep everything else private + +include_directories(.) + +list(APPEND SOURCES + plat/windows/windows-fds.c + plat/windows/windows-file.c + plat/windows/windows-init.c + plat/windows/windows-misc.c + plat/windows/windows-pipe.c + plat/windows/windows-plugins.c + plat/windows/windows-service.c + plat/windows/windows-sockets.c + ) +if (LWS_WITH_SYS_ASYNC_DNS) + list(APPEND SOURCES plat/windows/windows-resolv.c) +endif() + +if (LWS_WITH_SPAWN) + list(APPEND SOURCES plat/windows/windows-spawn.c) +endif() + +if (LWS_WITH_ZLIB AND LWS_WITH_BUNDLED_ZLIB) + set(WIN32_ZLIB_PATH "${CMAKE_CURRENT_SOURCE_DIR}/../../../win32port/zlib") + set(ZLIB_SRCS + ${WIN32_ZLIB_PATH}/adler32.c + ${WIN32_ZLIB_PATH}/compress.c + ${WIN32_ZLIB_PATH}/crc32.c + ${WIN32_ZLIB_PATH}/deflate.c + ${WIN32_ZLIB_PATH}/gzlib.c + ${WIN32_ZLIB_PATH}/gzread.c + ${WIN32_ZLIB_PATH}/gzwrite.c + ${WIN32_ZLIB_PATH}/infback.c + ${WIN32_ZLIB_PATH}/inffast.c + ${WIN32_ZLIB_PATH}/inflate.c + ${WIN32_ZLIB_PATH}/inftrees.c + ${WIN32_ZLIB_PATH}/trees.c + ${WIN32_ZLIB_PATH}/uncompr.c + ${WIN32_ZLIB_PATH}/zutil.c) + add_library(zlib_internal STATIC ${ZLIB_SRCS}) + set(ZLIB_INCLUDE_DIRS ${WIN32_ZLIB_PATH}) + set(ZLIB_LIBRARIES "") + set(ZLIB_FOUND 1) + # Make sure zlib_internal is compiled before the libs. + foreach (lib ${LWS_LIBRARIES}) + add_dependencies(${lib} zlib_internal) + endforeach() +endif() + +# Add helper files for Windows + +# (from ./lib perspective) +set(WIN32_HELPERS_PATH ../win32port/win32helpers) + +# from our perspective in ./lib/plat/windows +include_directories(../../${WIN32_HELPERS_PATH}) + +list(APPEND SOURCES + ${WIN32_HELPERS_PATH}/gettimeofday.c +) + +list(APPEND HDR_PRIVATE + ${WIN32_HELPERS_PATH}/gettimeofday.h +) + +# +# Keep explicit parent scope exports at end +# + +exports_to_parent_scope() +set(WIN32_HELPERS_PATH ${WIN32_HELPERS_PATH} PARENT_SCOPE) +set(HDR_PRIVATE ${HDR_PRIVATE} PARENT_SCOPE) +set(ZLIB_FOUND ${ZLIB_FOUND} PARENT_SCOPE) +set(LIB_LIST_AT_END ${LIB_LIST_AT_END} PARENT_SCOPE) diff -Nru libwebsockets-3.2.1/lib/plat/windows/private.h libwebsockets-4.1.6/lib/plat/windows/private.h --- libwebsockets-3.2.1/lib/plat/windows/private.h 2019-12-18 14:45:31.000000000 +0000 +++ libwebsockets-4.1.6/lib/plat/windows/private.h 1970-01-01 00:00:00.000000000 +0000 @@ -1,147 +0,0 @@ -/* - * libwebsockets - small server side websockets and web server implementation - * - * Copyright (C) 2010 - 2018 Andy Green - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation: - * version 2.1 of the License. - * - * This library is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with this library; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, - * MA 02110-1301 USA - * - * Included from lib/core/private.h if defined(WIN32) || defined(_WIN32) - */ - - #ifndef WIN32_LEAN_AND_MEAN - #define WIN32_LEAN_AND_MEAN - #endif - - #if defined(WINVER) && (WINVER < 0x0501) - #undef WINVER - #undef _WIN32_WINNT - #define WINVER 0x0501 - #define _WIN32_WINNT WINVER - #endif - - #define LWS_NO_DAEMONIZE - #define LWS_ERRNO WSAGetLastError() - #define LWS_EAGAIN WSAEWOULDBLOCK - #define LWS_EALREADY WSAEALREADY - #define LWS_EINPROGRESS WSAEINPROGRESS - #define LWS_EINTR WSAEINTR - #define LWS_EISCONN WSAEISCONN - #define LWS_ENOTCONN WSAENOTCONN - #define LWS_EWOULDBLOCK WSAEWOULDBLOCK - #define LWS_EADDRINUSE WSAEADDRINUSE - #define MSG_NOSIGNAL 0 - #define SHUT_RDWR SD_BOTH - #define SOL_TCP IPPROTO_TCP - #define SHUT_WR SD_SEND - - #define compatible_close(fd) closesocket(fd) - #define lws_set_blocking_send(wsi) wsi->sock_send_blocking = 1 - - #include - #include - #include - #include - #ifdef LWS_HAVE_IN6ADDR_H - #include - #endif - #include - #include - - #if !defined(LWS_HAVE_ATOLL) - #if defined(LWS_HAVE__ATOI64) - #define atoll _atoi64 - #else - #warning No atoll or _atoi64 available, using atoi - #define atoll atoi - #endif - #endif - - #ifndef __func__ - #define __func__ __FUNCTION__ - #endif - - #ifdef LWS_HAVE__VSNPRINTF - #define vsnprintf _vsnprintf - #endif - -/* we don't have an implementation for this on windows... */ -int kill(int pid, int sig); -int fork(void); -#ifndef SIGINT -#define SIGINT 2 -#endif - -#include - -#ifndef BIG_ENDIAN - #define BIG_ENDIAN 4321 /* to show byte order (taken from gcc) */ -#endif -#ifndef LITTLE_ENDIAN - #define LITTLE_ENDIAN 1234 -#endif -#ifndef BYTE_ORDER - #define BYTE_ORDER LITTLE_ENDIAN -#endif - -#undef __P -#ifndef __P - #if __STDC__ - #define __P(protos) protos - #else - #define __P(protos) () - #endif -#endif - -#ifdef _WIN32 - #ifndef FD_HASHTABLE_MODULUS - #define FD_HASHTABLE_MODULUS 32 - #endif -#endif - -#define lws_plat_socket_offset() (0) - -struct lws; -struct lws_context; - -#define LWS_FD_HASH(fd) ((fd ^ (fd >> 8) ^ (fd >> 16)) % FD_HASHTABLE_MODULUS) -struct lws_fd_hashtable { - struct lws **wsi; - int length; -}; - - -#ifdef LWS_DLL -#ifdef LWS_INTERNAL -#define LWS_EXTERN extern __declspec(dllexport) -#else -#define LWS_EXTERN extern __declspec(dllimport) -#endif -#else -#define LWS_EXTERN -#endif - -typedef SOCKET lws_sockfd_type; -typedef HANDLE lws_filefd_type; -#define LWS_WIN32_HANDLE_TYPES - -LWS_EXTERN struct lws * -wsi_from_fd(const struct lws_context *context, lws_sockfd_type fd); - -LWS_EXTERN int -insert_wsi(struct lws_context *context, struct lws *wsi); - -LWS_EXTERN int -delete_from_fd(struct lws_context *context, lws_sockfd_type fd); diff -Nru libwebsockets-3.2.1/lib/plat/windows/private-lib-plat-windows.h libwebsockets-4.1.6/lib/plat/windows/private-lib-plat-windows.h --- libwebsockets-3.2.1/lib/plat/windows/private-lib-plat-windows.h 1970-01-01 00:00:00.000000000 +0000 +++ libwebsockets-4.1.6/lib/plat/windows/private-lib-plat-windows.h 2020-12-01 17:40:26.000000000 +0000 @@ -0,0 +1,163 @@ + /* + * libwebsockets - small server side websockets and web server implementation + * + * Copyright (C) 2010 - 2019 Andy Green + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to + * deal in the Software without restriction, including without limitation the + * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or + * sell copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS + * IN THE SOFTWARE. + * + * Included from lib/private-lib-core.h if defined(WIN32) || defined(_WIN32) + */ + + #ifndef WIN32_LEAN_AND_MEAN + #define WIN32_LEAN_AND_MEAN + #endif + + #if defined(WINVER) && (WINVER < 0x0501) + #undef WINVER + #undef _WIN32_WINNT + #define WINVER 0x0501 + #define _WIN32_WINNT WINVER + #endif + + #define LWS_NO_DAEMONIZE + #define LWS_ERRNO WSAGetLastError() + #define LWS_EAGAIN WSAEWOULDBLOCK + #define LWS_EALREADY WSAEALREADY + #define LWS_EINPROGRESS WSAEINPROGRESS + #define LWS_EINTR WSAEINTR + #define LWS_EISCONN WSAEISCONN + #define LWS_ENOTCONN WSAENOTCONN + #define LWS_EWOULDBLOCK WSAEWOULDBLOCK + #define LWS_EADDRINUSE WSAEADDRINUSE + #define MSG_NOSIGNAL 0 + #define SHUT_RDWR SD_BOTH + #define SOL_TCP IPPROTO_TCP + #define SHUT_WR SD_SEND + + #define compatible_close(fd) closesocket(fd) + #define compatible_file_close(fd) CloseHandle(fd) + #define lws_set_blocking_send(wsi) wsi->sock_send_blocking = 1 + + #include + #include + #include + #include + #ifdef LWS_HAVE_IN6ADDR_H + #include + #endif + #include + #include + +#if defined(LWS_WITH_UNIX_SOCK) +#include +#endif + +#if defined(LWS_HAVE_PTHREAD_H) +#define lws_mutex_t pthread_mutex_t +#define lws_mutex_init(x) pthread_mutex_init(&(x), NULL) +#define lws_mutex_destroy(x) pthread_mutex_destroy(&(x)) +#define lws_mutex_lock(x) pthread_mutex_lock(&(x)) +#define lws_mutex_unlock(x) pthread_mutex_unlock(&(x)) +#endif + + #if !defined(LWS_HAVE_ATOLL) + #if defined(LWS_HAVE__ATOI64) + #define atoll _atoi64 + #else + #warning No atoll or _atoi64 available, using atoi + #define atoll atoi + #endif + #endif + + #ifndef __func__ + #define __func__ __FUNCTION__ + #endif + + #ifdef LWS_HAVE__VSNPRINTF + #define vsnprintf _vsnprintf + #endif + +/* we don't have an implementation for this on windows... */ +int kill(int pid, int sig); +int fork(void); +#ifndef SIGINT +#define SIGINT 2 +#endif + +#include + +#ifndef BIG_ENDIAN + #define BIG_ENDIAN 4321 /* to show byte order (taken from gcc) */ +#endif +#ifndef LITTLE_ENDIAN + #define LITTLE_ENDIAN 1234 +#endif +#ifndef BYTE_ORDER + #define BYTE_ORDER LITTLE_ENDIAN +#endif + +#undef __P +#ifndef __P + #if __STDC__ + #define __P(protos) protos + #else + #define __P(protos) () + #endif +#endif + +#ifdef _WIN32 + #ifndef FD_HASHTABLE_MODULUS + #define FD_HASHTABLE_MODULUS 32 + #endif +#endif + +#define lws_plat_socket_offset() (0) + +struct lws; +struct lws_context; + +#define LWS_FD_HASH(fd) ((fd ^ (fd >> 8) ^ (fd >> 16)) % FD_HASHTABLE_MODULUS) +struct lws_fd_hashtable { + struct lws **wsi; + int length; +}; + + +#ifdef LWS_DLL +#ifdef LWS_INTERNAL +#define LWS_EXTERN extern __declspec(dllexport) +#else +#define LWS_EXTERN extern __declspec(dllimport) +#endif +#else +#define LWS_EXTERN extern +#endif + +typedef SOCKET lws_sockfd_type; +typedef HANDLE lws_filefd_type; +#define LWS_WIN32_HANDLE_TYPES + +LWS_EXTERN struct lws * +wsi_from_fd(const struct lws_context *context, lws_sockfd_type fd); + +LWS_EXTERN int +insert_wsi(struct lws_context *context, struct lws *wsi); + +LWS_EXTERN int +delete_from_fd(struct lws_context *context, lws_sockfd_type fd); diff -Nru libwebsockets-3.2.1/lib/plat/windows/windows-fds.c libwebsockets-4.1.6/lib/plat/windows/windows-fds.c --- libwebsockets-3.2.1/lib/plat/windows/windows-fds.c 2019-12-18 14:45:31.000000000 +0000 +++ libwebsockets-4.1.6/lib/plat/windows/windows-fds.c 2020-12-01 17:40:26.000000000 +0000 @@ -1,28 +1,31 @@ /* * libwebsockets - small server side websockets and web server implementation * - * Copyright (C) 2010 - 2018 Andy Green + * Copyright (C) 2010 - 2019 Andy Green * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation: - * version 2.1 of the License. + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to + * deal in the Software without restriction, including without limitation the + * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or + * sell copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: * - * This library is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. * - * You should have received a copy of the GNU Lesser General Public - * License along with this library; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, - * MA 02110-1301 USA + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS + * IN THE SOFTWARE. */ #ifndef _WINSOCK_DEPRECATED_NO_WARNINGS #define _WINSOCK_DEPRECATED_NO_WARNINGS #endif -#include "core/private.h" +#include "private-lib-core.h" struct lws * wsi_from_fd(const struct lws_context *context, lws_sockfd_type fd) @@ -70,7 +73,7 @@ return 0; } - lwsl_err("Failed to find fd %d requested for " + lwsl_debug("Failed to find fd %d requested for " "delete in hashtable\n", fd); return 1; } diff -Nru libwebsockets-3.2.1/lib/plat/windows/windows-file.c libwebsockets-4.1.6/lib/plat/windows/windows-file.c --- libwebsockets-3.2.1/lib/plat/windows/windows-file.c 2019-12-18 14:45:31.000000000 +0000 +++ libwebsockets-4.1.6/lib/plat/windows/windows-file.c 2020-12-01 17:40:26.000000000 +0000 @@ -1,28 +1,31 @@ /* * libwebsockets - small server side websockets and web server implementation * - * Copyright (C) 2010 - 2018 Andy Green + * Copyright (C) 2010 - 2019 Andy Green * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation: - * version 2.1 of the License. + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to + * deal in the Software without restriction, including without limitation the + * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or + * sell copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: * - * This library is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. * - * You should have received a copy of the GNU Lesser General Public - * License along with this library; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, - * MA 02110-1301 USA + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS + * IN THE SOFTWARE. */ #ifndef _WINSOCK_DEPRECATED_NO_WARNINGS #define _WINSOCK_DEPRECATED_NO_WARNINGS #endif -#include "core/private.h" +#include "private-lib-core.h" int lws_plat_apply_FD_CLOEXEC(int n) { diff -Nru libwebsockets-3.2.1/lib/plat/windows/windows-init.c libwebsockets-4.1.6/lib/plat/windows/windows-init.c --- libwebsockets-3.2.1/lib/plat/windows/windows-init.c 2019-12-18 14:45:31.000000000 +0000 +++ libwebsockets-4.1.6/lib/plat/windows/windows-init.c 2020-12-01 17:40:26.000000000 +0000 @@ -1,28 +1,31 @@ /* * libwebsockets - small server side websockets and web server implementation * - * Copyright (C) 2010 - 2018 Andy Green + * Copyright (C) 2010 - 2019 Andy Green * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation: - * version 2.1 of the License. + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to + * deal in the Software without restriction, including without limitation the + * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or + * sell copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: * - * This library is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. * - * You should have received a copy of the GNU Lesser General Public - * License along with this library; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, - * MA 02110-1301 USA + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS + * IN THE SOFTWARE. */ #ifndef _WINSOCK_DEPRECATED_NO_WARNINGS #define _WINSOCK_DEPRECATED_NO_WARNINGS #endif -#include "core/private.h" +#include "private-lib-core.h" int lws_plat_drop_app_privileges(struct lws_context *context, int actually_set) @@ -52,6 +55,21 @@ return 1; } +#if defined(LWS_WITH_PLUGINS) +static int +protocol_plugin_cb(struct lws_plugin *pin, void *each_user) +{ + struct lws_context *context = (struct lws_context *)each_user; + const lws_plugin_protocol_t *plpr = + (const lws_plugin_protocol_t *)pin->hdr; + + context->plugin_protocol_count += plpr->count_protocols; + context->plugin_extension_count += plpr->count_extensions; + + return 0; +} +#endif + int lws_plat_init(struct lws_context *context, const struct lws_context_creation_info *info) @@ -69,8 +87,10 @@ } while (n--) { + int m; pt->fds_count = 0; - pt->events = WSACreateEvent(); /* the cancel event */ + for (m = 0; m < WSA_MAXIMUM_WAIT_EVENTS; m++) + pt->events[m] = WSACreateEvent(); InitializeCriticalSection(&pt->interrupt_lock); pt++; @@ -78,9 +98,11 @@ context->fd_random = 0; -#ifdef LWS_WITH_PLUGINS +#if defined(LWS_WITH_PLUGINS) if (info->plugin_dirs) - lws_plat_plugins_init(context, info->plugin_dirs); + lws_plat_plugins_init(&context->plugin_list, info->plugin_dirs, + "lws_protocol_plugin", + protocol_plugin_cb, context); #endif return 0; @@ -93,7 +115,9 @@ int n = context->count_threads; while (n--) { - WSACloseEvent(pt->events); + int m; + for (m = 0; m < WSA_MAXIMUM_WAIT_EVENTS; m++) + WSACloseEvent(pt->events[m]); DeleteCriticalSection(&pt->interrupt_lock); pt++; } @@ -104,6 +128,11 @@ { int n; +#ifdef LWS_WITH_PLUGINS + if (context->plugin_list) + lws_plugins_destroy(&context->plugin_list); +#endif + for (n = 0; n < FD_HASHTABLE_MODULUS; n++) { if (context->fd_hashtable[n].wsi) lws_free(context->fd_hashtable[n].wsi); diff -Nru libwebsockets-3.2.1/lib/plat/windows/windows-misc.c libwebsockets-4.1.6/lib/plat/windows/windows-misc.c --- libwebsockets-3.2.1/lib/plat/windows/windows-misc.c 2019-12-18 14:45:31.000000000 +0000 +++ libwebsockets-4.1.6/lib/plat/windows/windows-misc.c 2020-12-01 17:40:26.000000000 +0000 @@ -1,29 +1,43 @@ /* * libwebsockets - small server side websockets and web server implementation * - * Copyright (C) 2010 - 2018 Andy Green + * Copyright (C) 2010 - 2019 Andy Green * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation: - * version 2.1 of the License. + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to + * deal in the Software without restriction, including without limitation the + * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or + * sell copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: * - * This library is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. * - * You should have received a copy of the GNU Lesser General Public - * License along with this library; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, - * MA 02110-1301 USA + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS + * IN THE SOFTWARE. */ #ifndef _WINSOCK_DEPRECATED_NO_WARNINGS #define _WINSOCK_DEPRECATED_NO_WARNINGS #endif -#include "core/private.h" +#include "private-lib-core.h" +/* + * Normally you don't want this, use lws_sul instead inside the event loop. + * But sometimes for drivers it makes sense, so there's an internal-only + * crossplatform api for it. + */ + +void +lws_msleep(unsigned int ms) +{ + Sleep(ms); +} lws_usec_t lws_now_usecs(void) @@ -65,10 +79,10 @@ } #endif -LWS_VISIBLE int -lws_get_random(struct lws_context *context, void *buf, int len) +size_t +lws_get_random(struct lws_context *context, void *buf, size_t len) { - int n; + size_t n; char *p = (char *)buf; for (n = 0; n < len; n++) @@ -78,7 +92,7 @@ } -LWS_VISIBLE void +void lwsl_emit_syslog(int level, const char *line) { lwsl_emit_stderr(level, line); diff -Nru libwebsockets-3.2.1/lib/plat/windows/windows-pipe.c libwebsockets-4.1.6/lib/plat/windows/windows-pipe.c --- libwebsockets-3.2.1/lib/plat/windows/windows-pipe.c 2019-12-18 14:45:31.000000000 +0000 +++ libwebsockets-4.1.6/lib/plat/windows/windows-pipe.c 2020-12-01 17:40:26.000000000 +0000 @@ -1,28 +1,31 @@ /* * libwebsockets - small server side websockets and web server implementation * - * Copyright (C) 2010 - 2018 Andy Green + * Copyright (C) 2010 - 2019 Andy Green * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation: - * version 2.1 of the License. + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to + * deal in the Software without restriction, including without limitation the + * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or + * sell copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: * - * This library is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. * - * You should have received a copy of the GNU Lesser General Public - * License along with this library; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, - * MA 02110-1301 USA + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS + * IN THE SOFTWARE. */ #ifndef _WINSOCK_DEPRECATED_NO_WARNINGS #define _WINSOCK_DEPRECATED_NO_WARNINGS #endif -#include "core/private.h" +#include "private-lib-core.h" int lws_plat_pipe_create(struct lws *wsi) @@ -33,12 +36,17 @@ int lws_plat_pipe_signal(struct lws *wsi) { - struct lws_context_per_thread *pt = &wsi->context->pt[(int)wsi->tsi]; + struct lws_context_per_thread *pt = &wsi->a.context->pt[(int)wsi->tsi]; + + /* + * We need the critical section so that we are either setting it or + * clearing it, no matter how many threads competing there is a clear + * atomic state for the event + */ EnterCriticalSection(&pt->interrupt_lock); - pt->interrupt_requested = 1; + WSASetEvent(pt->events[0]); /* trigger the cancel event */ LeaveCriticalSection(&pt->interrupt_lock); - WSASetEvent(pt->events); /* trigger the cancel event */ return 0; } diff -Nru libwebsockets-3.2.1/lib/plat/windows/windows-plugins.c libwebsockets-4.1.6/lib/plat/windows/windows-plugins.c --- libwebsockets-3.2.1/lib/plat/windows/windows-plugins.c 2019-12-18 14:45:31.000000000 +0000 +++ libwebsockets-4.1.6/lib/plat/windows/windows-plugins.c 2020-12-01 17:40:26.000000000 +0000 @@ -3,33 +3,143 @@ * * Copyright (C) 2010 - 2019 Andy Green * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation: - * version 2.1 of the License. + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to + * deal in the Software without restriction, including without limitation the + * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or + * sell copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: * - * This library is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. * - * You should have received a copy of the GNU Lesser General Public - * License along with this library; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, - * MA 02110-1301 USA + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS + * IN THE SOFTWARE. */ #ifndef _WINSOCK_DEPRECATED_NO_WARNINGS #define _WINSOCK_DEPRECATED_NO_WARNINGS #endif -#include "core/private.h" +#include "private-lib-core.h" + +/* + * ie, if the plugins api needed at all + */ + +#if defined(LWS_WITH_PLUGINS_API) && (UV_VERSION_MAJOR > 0) + +const lws_plugin_header_t * +lws_plat_dlopen(struct lws_plugin **pplugin, const char *libpath, + const char *sofilename, const char *_class, + each_plugin_cb_t each, void *each_user) +{ + const lws_plugin_header_t *hdr; + struct lws_plugin *pin; + char sym[96], *dot; + uv_lib_t lib; + void *v; + int m; + + lib.errmsg = NULL; + lib.handle = NULL; + + if (uv_dlopen(libpath, &lib)) { + uv_dlerror(&lib); + lwsl_err("Error loading DSO: %s\n", lib.errmsg); + uv_dlclose(&lib); + return NULL; + } + + /* we could open it... can we get his export struct? */ + m = lws_snprintf(sym, sizeof(sym) - 1, "%s", sofilename); + if (m < 4) + goto bail; + dot = strchr(sym, '.'); + if (dot) + *dot = '\0'; /* snip the .so or .lib or what-have-you*/ + + if (uv_dlsym(&lib, sym, &v)) { + uv_dlerror(&lib); + lwsl_err("%s: Failed to get '%s' on %s: %s\n", + __func__, path, dent.name, lib.errmsg); + goto bail; + } + + hdr = (const lws_plugin_header_t *)v; + if (hdr->api_magic != LWS_PLUGIN_API_MAGIC) { + lwsl_err("%s: plugin %s has outdated api %d (vs %d)\n", + __func__, libpath, hdr->api_magic, + LWS_PLUGIN_API_MAGIC); + goto bail; + } + + if (strcmp(hdr->_class, _class)) + goto bail; + + pin = lws_malloc(sizeof(*pin), __func__); + if (!pin) + goto bail; + + pin->list = *pplugin; + *pplugin = pin; + + pin->u.lib = lib; + pin->hdr = hdr; + + if (each) + each(pin, each_user); + + return hdr; + +bail: + uv_dlclose(&lib); + + return NULL; +} + +int +lws_plat_destroy_dl(struct lws_plugin *p) +{ + return uv_dlclose(&p->u.lib); +} + +#endif + +/* + * Specifically for protocol plugins support + */ + +#if defined(LWS_WITH_PLUGINS) && (UV_VERSION_MAJOR > 0) + +static int +protocol_plugin_cb(struct lws_plugin *pin, void *each_user) +{ + struct lws_context *context = (struct lws_context *)each_user; + const lws_plugin_protocol_t *plpr = + (const lws_plugin_protocol_t *)pin->hdr; + + context->plugin_protocol_count += plpr->count_protocols; + context->plugin_extension_count += plpr->count_extensions; + + return 0; +} +#endif int -lws_plat_plugins_init(struct lws_context * context, const char * const *d) +lws_plat_plugins_init(struct lws_context *context, const char * const *d) { #if defined(LWS_WITH_PLUGINS) && (UV_VERSION_MAJOR > 0) - if (lws_check_opt(context->options, LWS_SERVER_OPTION_LIBUV)) - return lws_uv_plugins_init(context, d); + if (info->plugin_dirs) { + uv_loop_init(&context->uv.loop); + lws_plugins_init(&context->plugin_list, info->plugin_dirs, + "lws_protocol_plugin", NULL, + protocol_plugin_cb, context); + } #endif return 0; @@ -39,8 +149,12 @@ lws_plat_plugins_destroy(struct lws_context * context) { #if defined(LWS_WITH_PLUGINS) && (UV_VERSION_MAJOR > 0) - if (lws_check_opt(context->options, LWS_SERVER_OPTION_LIBUV)) - return lws_uv_plugins_destroy(context); + if (lws_check_opt(context->options, LWS_SERVER_OPTION_LIBUV) && + context->plugin_list) { + lws_plugins_destroy(&context->plugin_list, NULL, NULL); + while (uv_loop_close(&context->uv.loop)) + ; + } #endif return 0; diff -Nru libwebsockets-3.2.1/lib/plat/windows/windows-resolv.c libwebsockets-4.1.6/lib/plat/windows/windows-resolv.c --- libwebsockets-3.2.1/lib/plat/windows/windows-resolv.c 1970-01-01 00:00:00.000000000 +0000 +++ libwebsockets-4.1.6/lib/plat/windows/windows-resolv.c 2020-12-01 17:40:26.000000000 +0000 @@ -0,0 +1,66 @@ +/* + * libwebsockets - small server side websockets and web server implementation + * + * Copyright (C) 2010 - 2019 Andy Green + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to + * deal in the Software without restriction, including without limitation the + * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or + * sell copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS + * IN THE SOFTWARE. + */ + +#include "private-lib-core.h" +#include + +lws_async_dns_server_check_t +lws_plat_asyncdns_init(struct lws_context *context, lws_sockaddr46 *sa46) +{ + unsigned long ul; + FIXED_INFO fi; + int n; + + ul = sizeof(fi); + if (GetNetworkParams(&fi, &ul) != NO_ERROR) { + lwsl_err("%s: can't get dns servers\n", __func__); + + return LADNS_CONF_SERVER_UNKNOWN; + } + + lwsl_info("%s: trying %s\n", __func__, + fi.DnsServerList.IpAddress.String); + n = lws_sa46_parse_numeric_address( + fi.DnsServerList.IpAddress.String, sa46); + + return n == 0 ? LADNS_CONF_SERVER_CHANGED : + LADNS_CONF_SERVER_UNKNOWN; +} + +int +lws_plat_ntpclient_config(struct lws_context *context) +{ +#if defined(LWS_HAVE_GETENV) + char *ntpsrv = getenv("LWS_NTP_SERVER"); + + if (ntpsrv && strlen(ntpsrv) < 64) { + lws_system_blob_heap_append(lws_system_get_blob(context, + LWS_SYSBLOB_TYPE_NTP_SERVER, 0), + (const uint8_t *)ntpsrv, + strlen(ntpsrv)); + return 1; + } +#endif + return 0; +} diff -Nru libwebsockets-3.2.1/lib/plat/windows/windows-service.c libwebsockets-4.1.6/lib/plat/windows/windows-service.c --- libwebsockets-3.2.1/lib/plat/windows/windows-service.c 2019-12-18 14:45:31.000000000 +0000 +++ libwebsockets-4.1.6/lib/plat/windows/windows-service.c 2020-12-01 17:40:26.000000000 +0000 @@ -1,37 +1,40 @@ /* * libwebsockets - small server side websockets and web server implementation * - * Copyright (C) 2010 - 2018 Andy Green + * Copyright (C) 2010 - 2019 Andy Green * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation: - * version 2.1 of the License. + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to + * deal in the Software without restriction, including without limitation the + * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or + * sell copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: * - * This library is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. * - * You should have received a copy of the GNU Lesser General Public - * License along with this library; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, - * MA 02110-1301 USA + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS + * IN THE SOFTWARE. */ #ifndef _WINSOCK_DEPRECATED_NO_WARNINGS #define _WINSOCK_DEPRECATED_NO_WARNINGS #endif -#include "core/private.h" +#include "private-lib-core.h" int _lws_plat_service_forced_tsi(struct lws_context *context, int tsi) { struct lws_context_per_thread *pt = &context->pt[tsi]; - int m, n; + int m, n, r; - lws_service_flag_pending(context, tsi); + r = lws_service_flag_pending(context, tsi); /* any socket with events to service? */ for (n = 0; n < (int)pt->fds_count; n++) { @@ -48,11 +51,12 @@ lws_service_do_ripe_rxflow(pt); - return 0; + return r; } +extern void lws_client_conn_wait_timeout(lws_sorted_usec_list_t *sul); -LWS_EXTERN int +int _lws_plat_service_tsi(struct lws_context *context, int timeout_ms, int tsi) { struct lws_context_per_thread *pt; @@ -63,23 +67,21 @@ unsigned int i; DWORD ev; int n; - unsigned int eIdx; - int interrupt_requested; /* stay dead once we are dead */ - if (context == NULL || !context->vhost_list) + if (context == NULL) return 1; pt = &context->pt[tsi]; - if (!pt->service_tid_detected) { - struct lws _lws; + if (!pt->service_tid_detected && context->vhost_list) { + lws_fakewsi_def_plwsa(pt); - memset(&_lws, 0, sizeof(_lws)); - _lws.context = context; + lws_fakewsi_prep_plwsa_ctx(context); pt->service_tid = context->vhost_list-> - protocols[0].callback(&_lws, LWS_CALLBACK_GET_THREAD_ID, + protocols[0].callback((struct lws *)plwsa, + LWS_CALLBACK_GET_THREAD_ID, NULL, NULL, 0); pt->service_tid_detected = 1; } @@ -122,100 +124,193 @@ } /* - * is there anybody with pending stuff that needs service forcing? - */ - if (!lws_service_adjust_timeout(context, 1, tsi)) - _lws_plat_service_forced_tsi(context, tsi); - - /* - * service pending callbakcs and get maximum wait time + * service pending callbacks and get maximum wait time */ { lws_usec_t us; lws_pt_lock(pt, __func__); /* don't stay in poll wait longer than next hr timeout */ - us = __lws_sul_service_ripe(&pt->pt_sul_owner, lws_now_usecs()); + us = __lws_sul_service_ripe(pt->pt_sul_owner, + LWS_COUNT_PT_SUL_OWNERS, + lws_now_usecs()); if (us && us < timeout_us) timeout_us = us; lws_pt_unlock(pt); } + if (_lws_plat_service_forced_tsi(context, tsi)) + timeout_us = 0; + + /* + * is there anybody with pending stuff that needs service forcing? + */ + + if (!lws_service_adjust_timeout(context, 1, tsi)) + timeout_us = 0; + + /* + * WSA cannot actually tell us this from the wait... if anyone wants + * POLLOUT and is not blocked for it, no need to wait since we will want + * to service at least those. Still enter the wait so we can pick up + * other pending things... + */ + for (n = 0; n < (int)pt->fds_count; n++) - WSAEventSelect(pt->fds[n].fd, pt->events, - FD_READ | (!!(pt->fds[n].events & LWS_POLLOUT) * FD_WRITE) | - FD_OOB | FD_ACCEPT | - FD_CONNECT | FD_CLOSE | FD_QOS | - FD_ROUTING_INTERFACE_CHANGE | - FD_ADDRESS_LIST_CHANGE); - - ev = WSAWaitForMultipleEvents(1, &pt->events, FALSE, - (DWORD)(timeout_us / LWS_US_PER_MS), FALSE); - if (ev == WSA_WAIT_EVENT_0) { + if (pt->fds[n].fd != LWS_SOCK_INVALID && + pt->fds[n].events & LWS_POLLOUT && + !pt->fds[n].write_blocked) { + timeout_us = 0; + break; + } + + // lwsl_notice("%s: to %dms\n", __func__, (int)(timeout_us / 1000)); + ev = WSAWaitForMultipleEvents(pt->fds_count + 1, pt->events, FALSE, + (DWORD)(timeout_us / LWS_US_PER_MS), + FALSE); + //lwsl_notice("%s: ev 0x%x\n", __func__, ev); + + /* + * The wait returns indicating the one event that had something, or + * that we timed out, or something broken. + * + * Amazingly WSA can only handle 64 events, because the errors start + * at ordinal 64. + */ + + if (ev >= WSA_MAXIMUM_WAIT_EVENTS && + ev != WSA_WAIT_TIMEOUT) + /* some kind of error */ + return 0; + + if (!ev) { + /* + * The zero'th event is the cancel event specifically. Lock + * the event reset so we are definitely clearing it while we + * try to clear it. + */ EnterCriticalSection(&pt->interrupt_lock); - interrupt_requested = pt->interrupt_requested; - pt->interrupt_requested = 0; + WSAResetEvent(pt->events[0]); LeaveCriticalSection(&pt->interrupt_lock); - if (interrupt_requested) { - lws_broadcast(pt, LWS_CALLBACK_EVENT_WAIT_CANCELLED, - NULL, 0); - return 0; - } + lws_broadcast(pt, LWS_CALLBACK_EVENT_WAIT_CANCELLED, NULL, 0); + + return 0; + } + + /* + * Otherwise at least fds[ev - 1] has something to do... + */ #if defined(LWS_WITH_TLS) - if (pt->context->tls_ops && - pt->context->tls_ops->fake_POLLIN_for_buffered) - pt->context->tls_ops->fake_POLLIN_for_buffered(pt); + if (pt->context->tls_ops && + pt->context->tls_ops->fake_POLLIN_for_buffered) + pt->context->tls_ops->fake_POLLIN_for_buffered(pt); #endif - for (eIdx = 0; eIdx < pt->fds_count; ++eIdx) { - unsigned int err; + /* + * POLLOUT for any fds that can + */ - if (WSAEnumNetworkEvents(pt->fds[eIdx].fd, pt->events, - &networkevents) == SOCKET_ERROR) { - lwsl_err("WSAEnumNetworkEvents() failed " - "with error %d\n", LWS_ERRNO); - return -1; + for (n = 0; n < (int)pt->fds_count; n++) + if (pt->fds[n].fd != LWS_SOCK_INVALID && + pt->fds[n].events & LWS_POLLOUT && + !pt->fds[n].write_blocked) { + struct timeval tv; + fd_set se; + + /* + * We have to check if it is blocked... + * if not, do the POLLOUT handling + */ + + FD_ZERO(&se); + FD_SET(pt->fds[n].fd, &se); + tv.tv_sec = tv.tv_usec = 0; + if (select(1, NULL, &se, NULL, &tv) != 1) + pt->fds[n].write_blocked = 1; + else { + pt->fds[n].revents |= LWS_POLLOUT; + lws_service_fd_tsi(context, &pt->fds[n], tsi); } + } - if (!networkevents.lNetworkEvents) - networkevents.lNetworkEvents = LWS_POLLOUT; + if (ev && ev < WSA_MAXIMUM_WAIT_EVENTS) { + unsigned int err; - pfd = &pt->fds[eIdx]; - pfd->revents = (short)networkevents.lNetworkEvents; + /* handle fds[ev - 1] */ - err = networkevents.iErrorCode[FD_CONNECT_BIT]; + if (WSAEnumNetworkEvents(pt->fds[ev - 1].fd, pt->events[ev], + &networkevents) == SOCKET_ERROR) { + lwsl_err("WSAEnumNetworkEvents() failed " + "with error %d\n", LWS_ERRNO); + return -1; + } - if ((networkevents.lNetworkEvents & FD_CONNECT) && - err && err != LWS_EALREADY && - err != LWS_EINPROGRESS && err != LWS_EWOULDBLOCK && - err != WSAEINVAL) { + pfd = &pt->fds[ev - 1]; + pfd->revents = (short)networkevents.lNetworkEvents; + + if (!pfd->write_blocked && pfd->revents & FD_WRITE) + pfd->write_blocked = 0; + + err = networkevents.iErrorCode[FD_CONNECT_BIT]; + if ((networkevents.lNetworkEvents & FD_CONNECT) && + wsi_from_fd(context, pfd->fd) && + !wsi_from_fd(context, pfd->fd)->udp) { + lwsl_debug("%s: FD_CONNECT: %p\n", __func__, + wsi_from_fd(context, pfd->fd)); + pfd->revents &= ~LWS_POLLOUT; + if (err && err != LWS_EALREADY && + err != LWS_EINPROGRESS && + err != LWS_EWOULDBLOCK && + err != WSAEINVAL) { lwsl_debug("Unable to connect errno=%d\n", err); - pfd->revents |= LWS_POLLHUP; - } - if (pfd->revents & LWS_POLLOUT) { - wsi = wsi_from_fd(context, pfd->fd); - if (wsi) - wsi->sock_send_blocking = 0; - } - /* if something closed, retry this slot */ - if (pfd->revents & LWS_POLLHUP) - --eIdx; + /* + * the connection has definitively failed... but + * do we have more DNS entries to try? + */ + if (wsi_from_fd(context, pfd->fd)->dns_results_next) { + lws_sul_schedule(context, 0, + &wsi_from_fd(context, pfd->fd)-> + sul_connect_timeout, + lws_client_conn_wait_timeout, 1); + return 0; + } else + pfd->revents |= LWS_POLLHUP; + } else + if (wsi_from_fd(context, pfd->fd)) { + if (wsi_from_fd(context, pfd->fd)->udp) + pfd->revents |= LWS_POLLHUP; + else + lws_client_connect_3_connect( + wsi_from_fd(context, pfd->fd), + NULL, NULL, + LWS_CONNECT_COMPLETION_GOOD, + NULL); + } + } - if (pfd->revents) { - recv(pfd->fd, NULL, 0, 0); - lws_service_fd_tsi(context, pfd, tsi); - } + if (pfd->revents & LWS_POLLOUT) { + wsi = wsi_from_fd(context, pfd->fd); + if (wsi) + wsi->sock_send_blocking = 0; } - return 0; - } + if (pfd->revents) { + /* + * On windows is somehow necessary to "acknowledge" the + * POLLIN event, otherwise we never receive another one + * on the TCP connection. But it breaks UDP, so only + * do it on non-UDP. + */ + wsi = wsi_from_fd(context, pfd->fd); + if (wsi && !wsi->udp) + recv(pfd->fd, NULL, 0, 0); - // if (ev == WSA_WAIT_TIMEOUT) { } - // if (ev == WSA_WAIT_FAILED) - // return 0; + lws_service_fd_tsi(context, pfd, tsi); + } + } return 0; } diff -Nru libwebsockets-3.2.1/lib/plat/windows/windows-sockets.c libwebsockets-4.1.6/lib/plat/windows/windows-sockets.c --- libwebsockets-3.2.1/lib/plat/windows/windows-sockets.c 2019-12-18 14:45:31.000000000 +0000 +++ libwebsockets-4.1.6/lib/plat/windows/windows-sockets.c 2020-12-01 17:40:26.000000000 +0000 @@ -1,10 +1,41 @@ +/* + * libwebsockets - small server side websockets and web server implementation + * + * Copyright (C) 2010 - 2019 Andy Green + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to + * deal in the Software without restriction, including without limitation the + * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or + * sell copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS + * IN THE SOFTWARE. + */ + #ifndef _WINSOCK_DEPRECATED_NO_WARNINGS #define _WINSOCK_DEPRECATED_NO_WARNINGS #endif -#include "core/private.h" +#include "private-lib-core.h" +#if defined(LWS_WITH_MBEDTLS) +#if defined(LWS_HAVE_MBEDTLS_NET_SOCKETS) +#include "mbedtls/net_sockets.h" +#else +#include "mbedtls/net.h" +#endif +#endif -LWS_VISIBLE int +int lws_send_pipe_choked(struct lws *wsi) { struct lws *wsi_eff; @@ -43,7 +74,7 @@ } int -lws_plat_set_nonblocking(int fd) +lws_plat_set_nonblocking(lws_sockfd_type fd) { u_long optl = 1; int result = !!ioctlsocket(fd, FIONBIO, &optl); @@ -114,10 +145,11 @@ } -LWS_EXTERN int +int lws_interface_to_sa(int ipv6, const char *ifname, struct sockaddr_in *addr, size_t addrlen) { + long long address; #ifdef LWS_WITH_IPV6 struct sockaddr_in6 *addr6 = (struct sockaddr_in6 *)addr; @@ -128,7 +160,7 @@ } #endif - long long address = inet_addr(ifname); + address = inet_addr(ifname); if (address == INADDR_NONE) { struct hostent *entry = gethostbyname(ifname); @@ -148,15 +180,15 @@ lws_plat_insert_socket_into_fds(struct lws_context *context, struct lws *wsi) { struct lws_context_per_thread *pt = &context->pt[(int)wsi->tsi]; - int n = LWS_POLLIN | LWS_POLLHUP | FD_CONNECT; if (wsi->udp) { lwsl_info("%s: UDP\n", __func__); - n = LWS_POLLIN; + pt->fds[pt->fds_count].events |= LWS_POLLIN; } pt->fds[pt->fds_count++].revents = 0; - WSAEventSelect(wsi->desc.sockfd, pt->events, n); + + lws_plat_change_pollfd(context, wsi, &pt->fds[pt->fds_count - 1]); } void @@ -187,31 +219,33 @@ } int -lws_plat_change_pollfd(struct lws_context *context, - struct lws *wsi, struct lws_pollfd *pfd) +lws_plat_change_pollfd(struct lws_context *context, struct lws *wsi, + struct lws_pollfd *pfd) { struct lws_context_per_thread *pt = &context->pt[(int)wsi->tsi]; - long e = LWS_POLLHUP | FD_CONNECT; + long e = LWS_POLLHUP | FD_CONNECT | FD_ACCEPT | FD_CLOSE | FD_WRITE; - if ((pfd->events & LWS_POLLIN)) - e |= LWS_POLLIN; + /* + * On windows, FD_WRITE is only coming to indicate that we are writable + * again after being choked. So we must always listen for it. + */ - if ((pfd->events & LWS_POLLOUT)) - e |= LWS_POLLOUT; + if (pfd->events & LWS_POLLIN) + e |= FD_READ; - if (WSAEventSelect(wsi->desc.sockfd, pt->events, e) != SOCKET_ERROR) - return 0; - - lwsl_err("WSAEventSelect() failed with error %d\n", LWS_ERRNO); + if (WSAEventSelect(wsi->desc.sockfd, pt->events[(pfd - pt->fds) + 1], e)) { + lwsl_err("WSAEventSelect() failed with error %d\n", LWS_ERRNO); + return 1; + } - return 1; + return 0; } 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"); @@ -226,7 +260,9 @@ 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) { @@ -235,7 +271,9 @@ 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 @@ -245,7 +283,8 @@ 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; } @@ -257,7 +296,7 @@ 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"); @@ -266,7 +305,8 @@ 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; @@ -307,3 +347,92 @@ lws_free(buffer); return ok ? 1 : -1; } + +int +lws_plat_ifname_to_hwaddr(int fd, const char *ifname, uint8_t *hwaddr, int len) +{ + lwsl_err("%s: UNIMPLEMENTED on this platform\n", __func__); + + return -1; +} + +int +lws_plat_rawudp_broadcast(uint8_t *p, const uint8_t *canned, int canned_len, + int n, int fd, const char *iface) +{ + lwsl_err("%s: UNIMPLEMENTED on this platform\n", __func__); + + return -1; +} + +int +lws_plat_if_up(const char *ifname, int fd, int up) +{ + lwsl_err("%s: UNIMPLEMENTED on this platform\n", __func__); + + return -1; +} + +int +lws_plat_BINDTODEVICE(lws_sockfd_type fd, const char *ifname) +{ + lwsl_err("%s: UNIMPLEMENTED on this platform\n", __func__); + + return -1; +} + +int +lws_plat_ifconfig_ip(const char *ifname, int fd, uint8_t *ip, uint8_t *mask_ip, + uint8_t *gateway_ip) +{ + lwsl_err("%s: UNIMPLEMENTED on this platform\n", __func__); + + return -1; +} + +#if defined(LWS_WITH_MBEDTLS) +int +lws_plat_mbedtls_net_send(void *ctx, const uint8_t *buf, size_t len) +{ + int fd = ((mbedtls_net_context *) ctx)->fd; + int ret; + + if (fd < 0) + return MBEDTLS_ERR_NET_INVALID_CONTEXT; + + ret = write(fd, buf, len); + if (ret >= 0) + return ret; + + if (errno == EAGAIN || errno == EWOULDBLOCK) + return MBEDTLS_ERR_SSL_WANT_WRITE; + + if (WSAGetLastError() == WSAECONNRESET ) + return( MBEDTLS_ERR_NET_CONN_RESET ); + + return MBEDTLS_ERR_NET_SEND_FAILED; +} + +int +lws_plat_mbedtls_net_recv(void *ctx, unsigned char *buf, size_t len) +{ + int fd = ((mbedtls_net_context *) ctx)->fd; + int ret; + + if (fd < 0) + return MBEDTLS_ERR_NET_INVALID_CONTEXT; + + ret = (int)read(fd, buf, len); + if (ret >= 0) + return ret; + + if (errno == EAGAIN || errno == EWOULDBLOCK) + return MBEDTLS_ERR_SSL_WANT_READ; + + if (WSAGetLastError() == WSAECONNRESET) + return MBEDTLS_ERR_NET_CONN_RESET; + + return MBEDTLS_ERR_NET_RECV_FAILED; +} +#endif + diff -Nru libwebsockets-3.2.1/lib/plat/windows/windows-spawn.c libwebsockets-4.1.6/lib/plat/windows/windows-spawn.c --- libwebsockets-3.2.1/lib/plat/windows/windows-spawn.c 1970-01-01 00:00:00.000000000 +0000 +++ libwebsockets-4.1.6/lib/plat/windows/windows-spawn.c 2020-12-01 17:40:26.000000000 +0000 @@ -0,0 +1,581 @@ +/* + * libwebsockets - small server side websockets and web server implementation + * + * Copyright (C) 2010 - 2020 Andy Green + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to + * deal in the Software without restriction, including without limitation the + * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or + * sell copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS + * IN THE SOFTWARE. + */ + +#include "private-lib-core.h" + +#include +#include +#include + +void +lws_spawn_timeout(struct lws_sorted_usec_list *sul) +{ + struct lws_spawn_piped *lsp = lws_container_of(sul, + struct lws_spawn_piped, sul); + + lwsl_warn("%s: spawn exceeded timeout, killing\n", __func__); + + lws_spawn_piped_kill_child_process(lsp); +} + +void +lws_spawn_sul_reap(struct lws_sorted_usec_list *sul) +{ + struct lws_spawn_piped *lsp = lws_container_of(sul, + struct lws_spawn_piped, sul_reap); + + lwsl_notice("%s: reaping spawn after last stdpipe, tries left %d\n", + __func__, lsp->reap_retry_budget); + if (!lws_spawn_reap(lsp) && !lsp->pipes_alive) { + if (--lsp->reap_retry_budget) { + lws_sul_schedule(lsp->info.vh->context, lsp->info.tsi, + &lsp->sul_reap, lws_spawn_sul_reap, + 250 * LWS_US_PER_MS); + } else { + lwsl_err("%s: Unable to reap lsp %p, killing\n", + __func__, lsp); + lsp->reap_retry_budget = 20; + lws_spawn_piped_kill_child_process(lsp); + } + } +} + +static struct lws * +lws_create_basic_wsi(struct lws_context *context, int tsi, + const struct lws_role_ops *ops) +{ + struct lws *new_wsi; + size_t s = sizeof(*new_wsi); + + if (!context->vhost_list) + return NULL; + + if ((unsigned int)context->pt[tsi].fds_count == + context->fd_limit_per_thread - 1) { + lwsl_err("no space for new conn\n"); + return NULL; + } + +#if defined(LWS_WITH_EVENT_LIBS) + s += vhost->context->event_loop_ops->evlib_size_wsi; +#endif + + new_wsi = lws_zalloc(s, "new wsi"); + if (new_wsi == NULL) { + lwsl_err("Out of memory for new connection\n"); + return NULL; + } + +#if defined(LWS_WITH_EVENT_LIBS) + new_wsi->evlib_wsi = (uint8_t *)new_wsi + sizeof(*new_wsi); +#endif + + new_wsi->tsi = tsi; + new_wsi->a.context = context; + new_wsi->pending_timeout = NO_PENDING_TIMEOUT; + new_wsi->rxflow_change_to = LWS_RXFLOW_ALLOW; + + /* initialize the instance struct */ + + lws_role_transition(new_wsi, 0, LRS_ESTABLISHED, ops); + + new_wsi->hdr_parsing_completed = 0; + new_wsi->position_in_fds_table = LWS_NO_FDS_POS; + + /* + * these can only be set once the protocol is known + * we set an unestablished connection's protocol pointer + * to the start of the defauly vhost supported list, so it can look + * for matching ones during the handshake + */ + + new_wsi->user_space = NULL; + new_wsi->desc.sockfd = LWS_SOCK_INVALID; + context->count_wsi_allocated++; + + return new_wsi; +} + +void +lws_spawn_piped_destroy(struct lws_spawn_piped **_lsp) +{ + struct lws_spawn_piped *lsp = *_lsp; + struct lws *wsi; + int n; + + if (!lsp) + return; + + for (n = 0; n < 3; n++) { + if (lsp->pipe_fds[n][!!(n == 0)]) { + CloseHandle(lsp->pipe_fds[n][n == 0]); + lsp->pipe_fds[n][n == 0] = NULL; + } + + for (n = 0; n < 3; n++) { + if (lsp->stdwsi[n]) { + lwsl_notice("%s: closing stdwsi %d\n", __func__, n); + wsi = lsp->stdwsi[n]; + lsp->stdwsi[n]->desc.filefd = NULL; + lsp->stdwsi[n] = NULL; + lws_set_timeout(wsi, 1, LWS_TO_KILL_SYNC); + } + } + } + + lws_dll2_remove(&lsp->dll); + + lws_sul_cancel(&lsp->sul); + lws_sul_cancel(&lsp->sul_reap); + lws_sul_cancel(&lsp->sul_poll); + + lwsl_warn("%s: deleting lsp\n", __func__); + + lws_free_set_NULL((*_lsp)); +} + +int +lws_spawn_reap(struct lws_spawn_piped *lsp) +{ + + void *opaque = lsp->info.opaque; + lsp_cb_t cb = lsp->info.reap_cb; + struct _lws_siginfo_t lsi; + lws_usec_t acct[4]; + DWORD ex; + + if (!lsp->child_pid) + return 0; + + if (!GetExitCodeProcess(lsp->child_pid, &ex)) { + lwsl_notice("%s: GetExitCodeProcess failed\n", __func__); + return 0; + } + + /* nonzero = success */ + + if (ex == STILL_ACTIVE) { + lwsl_notice("%s: still active\n", __func__); + return 0; + } + + /* mark the earliest time we knew he had gone */ + if (!lsp->reaped) { + lsp->reaped = lws_now_usecs(); + + /* + * Switch the timeout to restrict the amount of grace time + * to drain stdwsi + */ + + lws_sul_schedule(lsp->info.vh->context, lsp->info.tsi, + &lsp->sul, lws_spawn_timeout, + 5 * LWS_US_PER_SEC); + } + + /* + * Stage finalizing our reaction to the process going down until the + * stdwsi flushed whatever is in flight and all noticed they were + * closed. For that reason, each stdwsi close must call lws_spawn_reap + * to check if that was the last one and we can proceed with the reap. + */ + + if (!lsp->ungraceful && lsp->pipes_alive) { + lwsl_notice("%s: stdwsi alive, not reaping\n", __func__); + return 0; + } + + /* we reached the reap point, no need for timeout wait */ + + lws_sul_cancel(&lsp->sul); + + /* + * All the stdwsi went down, nothing more is coming... it's over + * Collect the final information and then reap the dead process + */ + + lsi.retcode = 0x10000 | (int)ex; + lwsl_notice("%s: process exit 0x%x\n", __func__, lsi.retcode); + lsp->child_pid = NULL; + + /* destroy the lsp itself first (it's freed and plsp set NULL */ + + if (lsp->info.plsp) + lws_spawn_piped_destroy(lsp->info.plsp); + + /* then do the parent callback informing it's destroyed */ + + memset(acct, 0, sizeof(acct)); + if (cb) + cb(opaque, acct, &lsi, 0); + + lwsl_notice("%s: completed reap\n", __func__); + + return 1; /* was reaped */ +} + +int +lws_spawn_piped_kill_child_process(struct lws_spawn_piped *lsp) +{ + if (!lsp->child_pid) + return 1; + + lsp->ungraceful = 1; /* don't wait for flushing, just kill it */ + + if (lws_spawn_reap(lsp)) + /* that may have invalidated lsp */ + return 0; + + lwsl_warn("%s: calling TerminateProcess on child pid\n", __func__); + TerminateProcess(lsp->child_pid, 252); + lws_spawn_reap(lsp); + + /* that may have invalidated lsp */ + + return 0; +} + +static void +windows_pipe_poll_hack(lws_sorted_usec_list_t *sul) +{ + struct lws_spawn_piped *lsp = lws_container_of(sul, + struct lws_spawn_piped, sul_poll); + struct lws *wsi, *wsi1; + DWORD br; + char c; + + /* + * Do it first, we know lsp exists and if it's destroyed inbetweentimes, + * it will already have cancelled this + */ + + lws_sul_schedule(lsp->context, 0, &lsp->sul_poll, + windows_pipe_poll_hack, 50 * LWS_US_PER_MS); + + wsi = lsp->stdwsi[LWS_STDOUT]; + wsi1 = lsp->stdwsi[LWS_STDERR]; + if (wsi && lsp->pipe_fds[LWS_STDOUT][0] != NULL) { + if (!PeekNamedPipe(lsp->pipe_fds[LWS_STDOUT][0], &c, 1, &br, + NULL, NULL)) { + + lwsl_notice("%s: stdout pipe errored\n", __func__); + CloseHandle(lsp->stdwsi[LWS_STDOUT]->desc.filefd); + lsp->pipe_fds[LWS_STDOUT][0] = NULL; + lsp->stdwsi[LWS_STDOUT]->desc.filefd = NULL; + lsp->stdwsi[LWS_STDOUT] = NULL; + lws_set_timeout(wsi, 1, LWS_TO_KILL_SYNC); + + if (lsp->stdwsi[LWS_STDIN]) { + lwsl_notice("%s: closing stdin from stdout close\n", + __func__); + CloseHandle(lsp->stdwsi[LWS_STDIN]->desc.filefd); + wsi = lsp->stdwsi[LWS_STDIN]; + lsp->stdwsi[LWS_STDIN]->desc.filefd = NULL; + lsp->stdwsi[LWS_STDIN] = NULL; + lsp->pipe_fds[LWS_STDIN][1] = NULL; + lws_set_timeout(wsi, 1, LWS_TO_KILL_SYNC); + } + + /* + * lsp may be destroyed by here... if we wanted to + * handle a still-extant stderr we'll get it next time + */ + + return; + } else + if (br) + wsi->a.protocol->callback(wsi, + LWS_CALLBACK_RAW_RX_FILE, + NULL, NULL, 0); + } + + /* + * lsp may have been destroyed above + */ + + if (wsi1 && lsp->pipe_fds[LWS_STDERR][0]) { + if (!PeekNamedPipe(lsp->pipe_fds[LWS_STDERR][0], &c, 1, &br, + NULL, NULL)) { + + lwsl_notice("%s: stderr pipe errored\n", __func__); + CloseHandle(wsi1->desc.filefd); + /* + * Assume is stderr still extant on entry, lsp can't + * have been destroyed by stdout/stdin processing + */ + lsp->stdwsi[LWS_STDERR]->desc.filefd = NULL; + lsp->stdwsi[LWS_STDERR] = NULL; + lsp->pipe_fds[LWS_STDERR][0] = NULL; + lws_set_timeout(wsi1, 1, LWS_TO_KILL_SYNC); + /* + * lsp may have been destroyed above + */ + } else + if (br) + wsi1->a.protocol->callback(wsi1, + LWS_CALLBACK_RAW_RX_FILE, + NULL, NULL, 0); + } +} + + + +/* + * Deals with spawning a subprocess and executing it securely with stdin/out/err + * diverted into pipes + */ + +struct lws_spawn_piped * +lws_spawn_piped(const struct lws_spawn_piped_info *i) +{ + const struct lws_protocols *pcol = i->vh->context->vhost_list->protocols; + struct lws_context *context = i->vh->context; + struct lws_spawn_piped *lsp; + PROCESS_INFORMATION pi; + SECURITY_ATTRIBUTES sa; + char cli[300], *p; + STARTUPINFO si; + int n; + + if (i->protocol_name) + pcol = lws_vhost_name_to_protocol(i->vh, i->protocol_name); + if (!pcol) { + lwsl_err("%s: unknown protocol %s\n", __func__, + i->protocol_name ? i->protocol_name : "default"); + + return NULL; + } + + lsp = lws_zalloc(sizeof(*lsp), __func__); + if (!lsp) { + lwsl_err("%s: OOM\n", __func__); + return NULL; + } + + /* wholesale take a copy of info */ + lsp->info = *i; + lsp->context = context; + lsp->reap_retry_budget = 20; + + /* + * Prepare the stdin / out / err pipes + */ + + for (n = 0; n < 3; n++) { + lsp->pipe_fds[n][0] = NULL; + lsp->pipe_fds[n][1] = NULL; + } + + /* create pipes for [stdin|stdout] and [stderr] */ + + memset(&sa, 0, sizeof(sa)); + sa.nLength = sizeof(SECURITY_ATTRIBUTES); + sa.bInheritHandle = TRUE; /* inherit the pipes */ + sa.lpSecurityDescriptor = NULL; + + for (n = 0; n < 3; n++) { + DWORD waitmode = PIPE_NOWAIT; + + if (!CreatePipe(&lsp->pipe_fds[n][0], &lsp->pipe_fds[n][1], + &sa, 0)) { + lwsl_err("%s: CreatePipe() failed\n", __func__); + goto bail1; + } + + SetNamedPipeHandleState(lsp->pipe_fds[1][0], &waitmode, NULL, NULL); + SetNamedPipeHandleState(lsp->pipe_fds[2][0], &waitmode, NULL, NULL); + + /* don't inherit the pipe side that belongs to the parent */ + + if (!SetHandleInformation(&lsp->pipe_fds[n][!n], + HANDLE_FLAG_INHERIT, 0)) { + lwsl_err("%s: SetHandleInformation() failed\n", __func__); + //goto bail1; + } + } + + /* create wsis for each stdin/out/err fd */ + + for (n = 0; n < 3; n++) { + lsp->stdwsi[n] = lws_create_basic_wsi(i->vh->context, i->tsi, + i->ops ? i->ops : &role_ops_raw_file); + if (!lsp->stdwsi[n]) { + lwsl_err("%s: unable to create lsp stdwsi\n", __func__); + goto bail2; + } + lsp->stdwsi[n]->lsp_channel = n; + lws_vhost_bind_wsi(i->vh, lsp->stdwsi[n]); + lsp->stdwsi[n]->a.protocol = pcol; + lsp->stdwsi[n]->a.opaque_user_data = i->opaque; + + lsp->stdwsi[n]->desc.filefd = lsp->pipe_fds[n][!n]; + lsp->stdwsi[n]->file_desc = 1; + + lwsl_debug("%s: lsp stdwsi %p: pipe idx %d -> fd %d / %d\n", + __func__, lsp->stdwsi[n], n, + lsp->pipe_fds[n][!!(n == 0)], + lsp->pipe_fds[n][!(n == 0)]); + +#if 0 + + /* read side is 0, stdin we want the write side, others read */ + + lsp->stdwsi[n]->desc.filefd = lsp->pipe_fds[n][!!(n == 0)]; + if (fcntl(lsp->pipe_fds[n][!!(n == 0)], F_SETFL, O_NONBLOCK) < 0) { + lwsl_err("%s: setting NONBLOCK failed\n", __func__); + goto bail2; + } +#endif + } + + for (n = 0; n < 3; n++) + if (i->opt_parent) { + lsp->stdwsi[n]->parent = i->opt_parent; + lsp->stdwsi[n]->sibling_list = i->opt_parent->child_list; + i->opt_parent->child_list = lsp->stdwsi[n]; + } + + lwsl_notice("%s: pipe handles in %p, out %p, err %p\n", __func__, + lsp->stdwsi[LWS_STDIN]->desc.sockfd, + lsp->stdwsi[LWS_STDOUT]->desc.sockfd, + lsp->stdwsi[LWS_STDERR]->desc.sockfd); + + /* + * Windows nonblocking pipe handling is a mess that is unable + * to interoperate with WSA-based wait as far as I can tell. + * + * Let's set up a sul to poll the pipes and synthesize the + * protocol callbacks if anything coming. + */ + lws_sul_schedule(context, 0, &lsp->sul_poll, windows_pipe_poll_hack, + 50 * LWS_US_PER_MS); + + + /* + * Windows wants a single string commandline + */ + p = cli; + n = 0; + while (i->exec_array[n]) { + lws_strncpy(p, i->exec_array[n], + sizeof(cli) - lws_ptr_diff(p, cli)); + if (sizeof(cli) - lws_ptr_diff(p, cli) < 4) + break; + p += strlen(p); + *p++ = ' '; + *p = '\0'; + n++; + } + + puts(cli); + + memset(&pi, 0, sizeof(pi)); + memset(&si, 0, sizeof(si)); + + si.cb = sizeof(STARTUPINFO); + si.hStdInput = lsp->pipe_fds[LWS_STDIN][0]; + si.hStdOutput = lsp->pipe_fds[LWS_STDOUT][1]; + si.hStdError = lsp->pipe_fds[LWS_STDERR][1]; + si.dwFlags = STARTF_USESTDHANDLES | CREATE_NO_WINDOW; + si.wShowWindow = TRUE; + + if (!CreateProcess(NULL, cli, NULL, NULL, TRUE, 0, NULL, NULL, &si, &pi)) { + lwsl_err("%s: CreateProcess failed 0x%x\n", __func__, + (unsigned long)GetLastError()); + goto bail3; + } + + lsp->child_pid = pi.hProcess; + + lwsl_notice("%s: lsp %p spawned PID %d\n", __func__, lsp, lsp->child_pid); + + lws_sul_schedule(context, i->tsi, &lsp->sul, lws_spawn_timeout, + i->timeout_us ? i->timeout_us : 300 * LWS_US_PER_SEC); + + /* + * close: stdin:r, stdout:w, stderr:w + */ + for (n = 0; n < 3; n++) + CloseHandle(lsp->pipe_fds[n][n != 0]); + + lsp->pipes_alive = 3; + lsp->created = lws_now_usecs(); + + if (i->owner) + lws_dll2_add_head(&lsp->dll, i->owner); + + if (i->timeout_us) + lws_sul_schedule(context, i->tsi, &lsp->sul, + lws_spawn_timeout, i->timeout_us); + + return lsp; + +bail3: + + lws_sul_cancel(&lsp->sul_poll); + + while (--n >= 0) + __remove_wsi_socket_from_fds(lsp->stdwsi[n]); +bail2: + for (n = 0; n < 3; n++) + if (lsp->stdwsi[n]) + __lws_free_wsi(lsp->stdwsi[n]); + +bail1: + for (n = 0; n < 3; n++) { + if (lsp->pipe_fds[n][0] >= 0) + CloseHandle(lsp->pipe_fds[n][0]); + if (lsp->pipe_fds[n][1] >= 0) + CloseHandle(lsp->pipe_fds[n][1]); + } + + lws_free(lsp); + + lwsl_err("%s: failed\n", __func__); + + return NULL; +} + +void +lws_spawn_stdwsi_closed(struct lws_spawn_piped *lsp, struct lws *wsi) +{ + int n; + + assert(lsp); + lsp->pipes_alive--; + lwsl_debug("%s: pipes alive %d\n", __func__, lsp->pipes_alive); + if (!lsp->pipes_alive) + lws_sul_schedule(lsp->info.vh->context, lsp->info.tsi, + &lsp->sul_reap, lws_spawn_sul_reap, 1); + + for (n = 0; n < 3; n++) + if (lsp->stdwsi[n] == wsi) + lsp->stdwsi[n] = NULL; +} + +int +lws_spawn_get_stdfd(struct lws *wsi) +{ + return wsi->lsp_channel; +} diff -Nru libwebsockets-3.2.1/lib/README.md libwebsockets-4.1.6/lib/README.md --- libwebsockets-3.2.1/lib/README.md 2019-12-18 14:45:31.000000000 +0000 +++ libwebsockets-4.1.6/lib/README.md 2020-12-01 17:40:26.000000000 +0000 @@ -5,11 +5,12 @@ Path|Sources ---|--- lib/core|Core lws code related to generic fd and wsi servicing and management +lib/core-net|Core lws code that applies only if networking enabled lib/event-libs|Code containing optional event-lib specific adaptations lib/jose|JOSE / JWS / JWK / JWE implementations 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/system|Code for system-level features, eg, dhcpclient lib/tls|Code supporting the various TLS libraries -libwebsockets.h|Public API header for the whole of lws diff -Nru libwebsockets-3.2.1/lib/roles/cgi/cgi-server.c libwebsockets-4.1.6/lib/roles/cgi/cgi-server.c --- libwebsockets-3.2.1/lib/roles/cgi/cgi-server.c 2019-12-18 14:45:31.000000000 +0000 +++ libwebsockets-4.1.6/lib/roles/cgi/cgi-server.c 2020-12-01 17:40:26.000000000 +0000 @@ -1,27 +1,32 @@ /* - * libwebsockets - CGI management + * libwebsockets - small server side websockets and web server implementation * - * Copyright (C) 2010-2017 Andy Green + * Copyright (C) 2010 - 2019 Andy Green * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation: - * version 2.1 of the License. + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to + * deal in the Software without restriction, including without limitation the + * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or + * sell copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: * - * This library is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. * - * You should have received a copy of the GNU Lesser General Public - * License along with this library; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, - * MA 02110-1301 USA + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS + * IN THE SOFTWARE. */ -#define _GNU_SOURCE +#if !defined(_GNU_SOURCE) +#define _GNU_SOURCE +#endif -#include "core/private.h" +#include "private-lib-core.h" #if defined(WIN32) || defined(_WIN32) #else @@ -63,58 +68,50 @@ return out - start; } -static struct lws * -lws_create_basic_wsi(struct lws_context *context, int tsi) +static void +lws_cgi_grace(lws_sorted_usec_list_t *sul) { - struct lws *new_wsi; + struct lws_cgi *cgi = lws_container_of(sul, struct lws_cgi, sul_grace); - if (!context->vhost_list) - return NULL; + /* act on the reap cb from earlier */ - if ((unsigned int)context->pt[tsi].fds_count == - context->fd_limit_per_thread - 1) { - lwsl_err("no space for new conn\n"); - return NULL; - } + lwsl_info("%s: wsi %p\n", __func__, cgi->wsi); - new_wsi = lws_zalloc(sizeof(struct lws), "new wsi"); - if (new_wsi == NULL) { - lwsl_err("Out of memory for new connection\n"); - return NULL; - } + if (!cgi->wsi->http.cgi->post_in_expected) + cgi->wsi->http.cgi->cgi_transaction_over = 1; + + lws_callback_on_writable(cgi->wsi); +} - new_wsi->tsi = tsi; - new_wsi->context = context; - new_wsi->pending_timeout = NO_PENDING_TIMEOUT; - new_wsi->rxflow_change_to = LWS_RXFLOW_ALLOW; - /* initialize the instance struct */ +static void +lws_cgi_reap_cb(void *opaque, lws_usec_t *accounting, siginfo_t *si, + int we_killed_him) +{ + struct lws *wsi = (struct lws *)opaque; - lws_role_transition(new_wsi, 0, LRS_ESTABLISHED, &role_ops_cgi); + /* + * The cgi has come to an end, by itself or with a signal... + */ - new_wsi->hdr_parsing_completed = 0; - new_wsi->position_in_fds_table = LWS_NO_FDS_POS; + lwsl_info("%s: wsi %p post_in_expected %d\n", __func__, wsi, + (int)wsi->http.cgi->post_in_expected); /* - * these can only be set once the protocol is known - * we set an unestablished connection's protocol pointer - * to the start of the defauly vhost supported list, so it can look - * for matching ones during the handshake + * Grace period to handle the incoming stdout */ - new_wsi->protocol = context->vhost_list->protocols; - new_wsi->user_space = NULL; - new_wsi->desc.sockfd = LWS_SOCK_INVALID; - context->count_wsi_allocated++; - return new_wsi; + lws_sul_schedule(wsi->a.context, wsi->tsi, &wsi->http.cgi->sul_grace, + lws_cgi_grace, 1 * LWS_US_PER_SEC); } -LWS_VISIBLE LWS_EXTERN int +int lws_cgi(struct lws *wsi, const char * const *exec_array, int script_uri_path_len, int timeout_secs, const struct lws_protocol_vhost_options *mp_cgienv) { - struct lws_context_per_thread *pt = &wsi->context->pt[(int)wsi->tsi]; + struct lws_context_per_thread *pt = &wsi->a.context->pt[(int)wsi->tsi]; + struct lws_spawn_piped_info info; char *env_array[30], cgi_path[500], e[1024], *p = e, *end = p + sizeof(e) - 1, tok[256], *t, *sum, *sumend; struct lws_cgi *cgi; @@ -137,65 +134,6 @@ sum = cgi->summary; sumend = sum + strlen(cgi->summary) - 1; - for (n = 0; n < 3; n++) { - cgi->pipe_fds[n][0] = -1; - cgi->pipe_fds[n][1] = -1; - } - - /* create pipes for [stdin|stdout] and [stderr] */ - - for (n = 0; n < 3; n++) - if (pipe(cgi->pipe_fds[n]) == -1) - goto bail1; - - /* create cgi wsis for each stdin/out/err fd */ - - for (n = 0; n < 3; n++) { - cgi->stdwsi[n] = lws_create_basic_wsi(wsi->context, wsi->tsi); - if (!cgi->stdwsi[n]) { - lwsl_err("%s: unable to create cgi stdwsi\n", __func__); - goto bail2; - } - cgi->stdwsi[n]->cgi_channel = n; - lws_vhost_bind_wsi(wsi->vhost, cgi->stdwsi[n]); - - lwsl_debug("%s: cgi stdwsi %p: pipe idx %d -> fd %d / %d\n", __func__, - cgi->stdwsi[n], n, cgi->pipe_fds[n][!!(n == 0)], - cgi->pipe_fds[n][!(n == 0)]); - - /* read side is 0, stdin we want the write side, others read */ - cgi->stdwsi[n]->desc.sockfd = cgi->pipe_fds[n][!!(n == 0)]; - if (fcntl(cgi->pipe_fds[n][!!(n == 0)], F_SETFL, - O_NONBLOCK) < 0) { - lwsl_err("%s: setting NONBLOCK failed\n", __func__); - goto bail2; - } - } - - for (n = 0; n < 3; n++) { - if (wsi->context->event_loop_ops->accept) - if (wsi->context->event_loop_ops->accept(cgi->stdwsi[n])) - goto bail3; - - if (__insert_wsi_socket_into_fds(wsi->context, cgi->stdwsi[n])) - goto bail3; - cgi->stdwsi[n]->parent = wsi; - cgi->stdwsi[n]->sibling_list = wsi->child_list; - wsi->child_list = cgi->stdwsi[n]; - } - - if (lws_change_pollfd(cgi->stdwsi[LWS_STDIN], LWS_POLLIN, LWS_POLLOUT)) - goto bail3; - if (lws_change_pollfd(cgi->stdwsi[LWS_STDOUT], LWS_POLLOUT, LWS_POLLIN)) - goto bail3; - if (lws_change_pollfd(cgi->stdwsi[LWS_STDERR], LWS_POLLOUT, LWS_POLLIN)) - goto bail3; - - lwsl_debug("%s: fds in %d, out %d, err %d\n", __func__, - cgi->stdwsi[LWS_STDIN]->desc.sockfd, - cgi->stdwsi[LWS_STDOUT]->desc.sockfd, - cgi->stdwsi[LWS_STDERR]->desc.sockfd); - if (timeout_secs) lws_set_timeout(wsi, PENDING_TIMEOUT_CGI, timeout_secs); @@ -231,10 +169,12 @@ static const unsigned char meths[] = { WSI_TOKEN_GET_URI, WSI_TOKEN_POST_URI, +#if defined(LWS_WITH_HTTP_UNCOMMON_HEADERS) WSI_TOKEN_OPTIONS_URI, WSI_TOKEN_PUT_URI, WSI_TOKEN_PATCH_URI, WSI_TOKEN_DELETE_URI, +#endif WSI_TOKEN_CONNECT, WSI_TOKEN_HEAD_URI, #ifdef LWS_WITH_HTTP2 @@ -242,7 +182,10 @@ #endif }; static const char * const meth_names[] = { - "GET", "POST", "OPTIONS", "PUT", "PATCH", "DELETE", + "GET", "POST", +#if defined(LWS_WITH_HTTP_UNCOMMON_HEADERS) + "OPTIONS", "PUT", "PATCH", "DELETE", +#endif "CONNECT", "HEAD", ":path" }; @@ -255,18 +198,19 @@ } if (script_uri_path_len < 0 && uritok < 0) - goto bail3; + goto bail; // if (script_uri_path_len < 0) // uritok = 0; if (m >= 0) { env_array[n++] = p; - if (m < 8) { + if (m < (int)LWS_ARRAY_SIZE(meths) - 1) { p += lws_snprintf(p, end - p, "REQUEST_METHOD=%s", meth_names[m]); sum += lws_snprintf(sum, sumend - sum, "%s ", meth_names[m]); +#if defined(LWS_ROLE_H2) } else { p += lws_snprintf(p, end - p, "REQUEST_METHOD=%s", @@ -274,6 +218,7 @@ sum += lws_snprintf(sum, sumend - sum, "%s ", lws_hdr_simple_ptr(wsi, WSI_TOKEN_HTTP_COLON_METHOD)); +#endif } p++; } @@ -312,7 +257,7 @@ c = lws_hdr_copy(wsi, cgi_path + 12, sizeof(cgi_path) - 12, uritok); if (c < 0) - goto bail3; + goto bail; cgi_path[sizeof(cgi_path) - 1] = '\0'; env_array[n++] = cgi_path; @@ -327,6 +272,7 @@ p++; } } +#if defined(LWS_WITH_HTTP_UNCOMMON_HEADERS) if (script_uri_path_len >= 0 && lws_hdr_total_length(wsi, WSI_TOKEN_HTTP_REFERER)) { env_array[n++] = p; @@ -334,6 +280,7 @@ lws_hdr_simple_ptr(wsi, WSI_TOKEN_HTTP_REFERER)); p++; } +#endif if (script_uri_path_len >= 0 && lws_hdr_total_length(wsi, WSI_TOKEN_HOST)) { env_array[n++] = p; @@ -350,6 +297,7 @@ p += lws_hdr_total_length(wsi, WSI_TOKEN_HTTP_COOKIE); *p++ = '\0'; } +#if defined(LWS_WITH_HTTP_UNCOMMON_HEADERS) if (script_uri_path_len >= 0 && lws_hdr_total_length(wsi, WSI_TOKEN_HTTP_USER_AGENT)) { env_array[n++] = p; @@ -357,6 +305,7 @@ lws_hdr_simple_ptr(wsi, WSI_TOKEN_HTTP_USER_AGENT)); p++; } +#endif if (script_uri_path_len >= 0 && lws_hdr_total_length(wsi, WSI_TOKEN_HTTP_CONTENT_ENCODING)) { env_array[n++] = p; @@ -425,7 +374,7 @@ } env_array[n++] = p; - p += lws_snprintf(p, end - p, "SERVER_SOFTWARE=libwebsockets"); + p += lws_snprintf(p, end - p, "SERVER_SOFTWARE=lws"); p++; env_array[n] = NULL; @@ -435,108 +384,48 @@ lwsl_notice(" %s\n", env_array[m]); #endif + memset(&info, 0, sizeof(info)); + info.env_array = env_array; + info.exec_array = exec_array; + info.max_log_lines = 20000; + info.opt_parent = wsi; + info.timeout_us = 5 * 60 * LWS_US_PER_SEC; + info.tsi = wsi->tsi; + info.vh = wsi->a.vhost; + info.ops = &role_ops_cgi; + info.plsp = &wsi->http.cgi->lsp; + info.opaque = wsi; + info.reap_cb = lws_cgi_reap_cb; + /* * Actually having made the env, as a cgi we don't need the ah * any more */ - if (script_uri_path_len >= 0) + if (script_uri_path_len >= 0) { lws_header_table_detach(wsi, 0); - - /* we are ready with the redirection pipes... run the thing */ -#if !defined(LWS_HAVE_VFORK) || !defined(LWS_HAVE_EXECVPE) - cgi->pid = fork(); -#else - cgi->pid = vfork(); -#endif - if (cgi->pid < 0) { - lwsl_err("fork failed, errno %d", errno); - goto bail3; + info.disable_ctrlc = 1; } -#if defined(__linux__) - prctl(PR_SET_PDEATHSIG, SIGTERM); -#endif - if (script_uri_path_len >= 0) - /* stops non-daemonized main processess getting SIGINT - * from TTY */ - setpgrp(); - - if (cgi->pid) { - /* we are the parent process */ - wsi->context->count_cgi_spawned++; - lwsl_info("%s: cgi %p spawned PID %d\n", __func__, - cgi, cgi->pid); - - /* - * close: stdin:r, stdout:w, stderr:w - * hide from other forks: stdin:w, stdout:r, stderr:r - */ - for (n = 0; n < 3; n++) { - lws_plat_apply_FD_CLOEXEC(cgi->pipe_fds[n][!!(n == 0)]); - close(cgi->pipe_fds[n][!(n == 0)]); - } - - /* inform cgi owner of the child PID */ - n = user_callback_handle_rxflow(wsi->protocol->callback, wsi, - LWS_CALLBACK_CGI_PROCESS_ATTACH, - wsi->user_space, NULL, cgi->pid); - (void)n; - - return 0; + wsi->http.cgi->lsp = lws_spawn_piped(&info); + if (!wsi->http.cgi->lsp) { + lwsl_err("%s: spawn failed\n", __func__); + goto bail; } - /* somewhere we can at least read things and enter it */ - if (chdir("/tmp")) - lwsl_notice("%s: Failed to chdir\n", __func__); - - /* We are the forked process, redirect and kill inherited things. - * - * Because of vfork(), we cannot do anything that changes pages in - * the parent environment. Stuff that changes kernel state for the - * process is OK. Stuff that happens after the execvpe() is OK. - */ + /* we are the parent process */ - for (m = 0; m < 3; m++) { - if (dup2(cgi->pipe_fds[m][!(m == 0)], m) < 0) { - lwsl_err("%s: stdin dup2 failed\n", __func__); - goto bail3; - } - close(cgi->pipe_fds[m][0]); - close(cgi->pipe_fds[m][1]); - } + wsi->a.context->count_cgi_spawned++; -#if !defined(LWS_HAVE_VFORK) || !defined(LWS_HAVE_EXECVPE) - for (m = 0; m < n; m++) { - p = strchr(env_array[m], '='); - *p++ = '\0'; - setenv(env_array[m], p, 1); - } - execvp(exec_array[0], (char * const *)&exec_array[0]); -#else - execvpe(exec_array[0], (char * const *)&exec_array[0], &env_array[0]); -#endif - - exit(1); + /* inform cgi owner of the child PID */ + n = user_callback_handle_rxflow(wsi->a.protocol->callback, wsi, + LWS_CALLBACK_CGI_PROCESS_ATTACH, + wsi->user_space, NULL, cgi->lsp->child_pid); + (void)n; -bail3: - /* drop us from the pt cgi list */ - pt->http.cgi_list = cgi->cgi_list; - - while (--n >= 0) - __remove_wsi_socket_from_fds(wsi->http.cgi->stdwsi[n]); -bail2: - for (n = 0; n < 3; n++) - if (wsi->http.cgi->stdwsi[n]) - __lws_free_wsi(cgi->stdwsi[n]); - -bail1: - for (n = 0; n < 3; n++) { - if (cgi->pipe_fds[n][0] >= 0) - close(cgi->pipe_fds[n][0]); - if (cgi->pipe_fds[n][1] >= 0) - close(cgi->pipe_fds[n][1]); - } + return 0; +bail: + lws_sul_cancel(&wsi->http.cgi->sul_grace); lws_free_set_NULL(wsi->http.cgi); lwsl_err("%s: failed\n", __func__); @@ -561,7 +450,7 @@ HR_CRLF, }; -LWS_VISIBLE LWS_EXTERN int +int lws_cgi_write_split_stdout_headers(struct lws *wsi) { int n, m, cmd; @@ -592,7 +481,7 @@ WSI_TOKEN_HTTP_TRANSFER_ENCODING, (unsigned char *)"chunked", 7, &p, end)) return 1; - if (!(wsi->http2_substream)) + if (!(wsi->mux_substream)) if (lws_add_http_header_by_token(wsi, WSI_TOKEN_CONNECTION, (unsigned char *)"close", 5, @@ -610,7 +499,7 @@ * Let's redo them at headers_pos forward using the * correct coding for http/1 or http/2 */ - if (!wsi->http2_substream) + if (!wsi->mux_substream) goto post_hpack_recode; p = wsi->http.cgi->headers_start; @@ -712,7 +601,7 @@ cmd = LWS_WRITE_HTTP_HEADERS_CONTINUATION; if (wsi->http.cgi->headers_dumped + n != - wsi->http.cgi->headers_pos) { + wsi->http.cgi->headers_pos) { lwsl_notice("adding no fin flag\n"); cmd |= LWS_WRITE_NO_FIN; } @@ -729,14 +618,23 @@ wsi->http.cgi->headers_pos) { wsi->hdr_state = LHCS_PAYLOAD; lws_free_set_NULL(wsi->http.cgi->headers_buf); - lwsl_debug("freed cgi headers\n"); + lwsl_debug("%s: freed cgi headers\n", __func__); + + if (wsi->http.cgi->post_in_expected) { + lwsl_info("%s: post data still expected, " + "asking for writeable\n", + __func__); + lws_callback_on_writable(wsi); + } + } else { wsi->reason_bf |= LWS_CB_REASON_AUX_BF__CGI_HEADERS; lws_callback_on_writable(wsi); } - /* writeability becomes uncertain now we wrote + /* + * writeability becomes uncertain now we wrote * something, we must return to the event loop */ return 0; @@ -745,7 +643,7 @@ if (!wsi->http.cgi->headers_buf) { /* if we don't already have a headers buf, cook one */ n = 2048; - if (wsi->http2_substream) + if (wsi->mux_substream) n = 4096; wsi->http.cgi->headers_buf = lws_malloc(n + LWS_PRE, "cgi hdr buf"); @@ -768,7 +666,7 @@ } } - n = lws_get_socket_fd(wsi->http.cgi->stdwsi[LWS_STDOUT]); + n = lws_get_socket_fd(wsi->http.cgi->lsp->stdwsi[LWS_STDOUT]); if (n < 0) return -1; n = read(n, &c, 1); @@ -916,28 +814,12 @@ /* payload processing */ - m = !wsi->http.cgi->implied_chunked && !wsi->http2_substream && - !wsi->http.cgi->explicitly_chunked && + m = !wsi->http.cgi->implied_chunked && !wsi->mux_substream && + // !wsi->http.cgi->explicitly_chunked && !wsi->http.cgi->content_length; - n = lws_get_socket_fd(wsi->http.cgi->stdwsi[LWS_STDOUT]); + n = lws_get_socket_fd(wsi->http.cgi->lsp->stdwsi[LWS_STDOUT]); if (n < 0) return -1; - if (m) { - uint8_t term[LWS_PRE + 6]; - - lwsl_info("%s: zero chunk\n", __func__); - - memcpy(term + LWS_PRE, (uint8_t *)"0\x0d\x0a\x0d\x0a", 5); - - if (lws_write(wsi, term + LWS_PRE, 5, - LWS_WRITE_HTTP_FINAL) != 5) - return -1; - - wsi->http.cgi->cgi_transaction_over = 1; - - return 0; - } - n = read(n, start, sizeof(buf) - LWS_PRE); if (n < 0 && errno != EAGAIN) { @@ -945,8 +827,9 @@ return -1; } if (n > 0) { -/* - if (!wsi->http2_substream && m) { + // lwsl_hexdump_notice(buf, n); + + if (!wsi->mux_substream && m) { char chdr[LWS_HTTP_CHUNK_HDR_SIZE]; m = lws_snprintf(chdr, LWS_HTTP_CHUNK_HDR_SIZE - 3, "%X\x0d\x0a", n); @@ -955,10 +838,10 @@ memcpy(start + m + n, "\x0d\x0a", 2); n += m + 2; } - */ + #if defined(LWS_WITH_HTTP2) - if (wsi->http2_substream) { + if (wsi->mux_substream) { struct lws *nwsi = lws_get_network_wsi(wsi); __lws_set_timeout(wsi, @@ -983,9 +866,25 @@ } wsi->http.cgi->content_length_seen += n; } else { + + if (!wsi->mux_substream && m) { + uint8_t term[LWS_PRE + 6]; + + lwsl_info("%s: sent trailer\n", __func__); + memcpy(term + LWS_PRE, (uint8_t *)"0\x0d\x0a\x0d\x0a", 5); + + if (lws_write(wsi, term + LWS_PRE, 5, + LWS_WRITE_HTTP_FINAL) != 5) + return -1; + + wsi->http.cgi->cgi_transaction_over = 1; + + return 0; + } + if (wsi->cgi_stdout_zero_length) { lwsl_debug("%s: stdout is POLLHUP'd\n", __func__); - if (wsi->http2_substream) + if (wsi->mux_substream) m = lws_write(wsi, (unsigned char *)start, 0, LWS_WRITE_HTTP_FINAL); else @@ -997,81 +896,38 @@ return 0; } -LWS_VISIBLE LWS_EXTERN int +int lws_cgi_kill(struct lws *wsi) { struct lws_cgi_args args; - int status, n; + pid_t pid; + int n, m; lwsl_debug("%s: %p\n", __func__, wsi); - if (!wsi->http.cgi) + if (!wsi->http.cgi || !wsi->http.cgi->lsp) return 0; - if (wsi->http.cgi->pid > 0) { - n = waitpid(wsi->http.cgi->pid, &status, WNOHANG); - if (n > 0) { - lwsl_debug("%s: PID %d reaped\n", __func__, - wsi->http.cgi->pid); - goto handled; - } - /* kill the process group */ - n = kill(-wsi->http.cgi->pid, SIGTERM); - lwsl_debug("%s: SIGTERM child PID %d says %d (errno %d)\n", - __func__, wsi->http.cgi->pid, n, errno); - if (n < 0) { - /* - * hum seen errno=3 when process is listed in ps, - * it seems we don't always retain process grouping - * - * Direct these fallback attempt to the exact child - */ - n = kill(wsi->http.cgi->pid, SIGTERM); - if (n < 0) { - n = kill(wsi->http.cgi->pid, SIGPIPE); - if (n < 0) { - n = kill(wsi->http.cgi->pid, SIGKILL); - if (n < 0) - lwsl_info("%s: SIGKILL PID %d " - "failed errno %d " - "(maybe zombie)\n", - __func__, - wsi->http.cgi->pid, errno); - } - } - } - /* He could be unkillable because he's a zombie */ - n = 1; - while (n > 0) { - n = waitpid(-wsi->http.cgi->pid, &status, WNOHANG); - if (n > 0) - lwsl_debug("%s: reaped PID %d\n", __func__, n); - if (n <= 0) { - n = waitpid(wsi->http.cgi->pid, &status, WNOHANG); - if (n > 0) - lwsl_debug("%s: reaped PID %d\n", - __func__, n); - } - } - } - -handled: - args.stdwsi = &wsi->http.cgi->stdwsi[0]; + pid = wsi->http.cgi->lsp->child_pid; - if (wsi->http.cgi->pid != -1) { - n = user_callback_handle_rxflow(wsi->protocol->callback, wsi, + args.stdwsi = &wsi->http.cgi->lsp->stdwsi[0]; + lws_spawn_piped_kill_child_process(wsi->http.cgi->lsp); + /* that has invalidated and NULL'd wsi->http.cgi->lsp */ + + if (pid != -1) { + m = wsi->http.cgi->being_closed; + n = user_callback_handle_rxflow(wsi->a.protocol->callback, wsi, LWS_CALLBACK_CGI_TERMINATED, wsi->user_space, (void *)&args, - wsi->http.cgi->pid); - wsi->http.cgi->pid = -1; - if (n && !wsi->http.cgi->being_closed) + pid); + if (n && !m) lws_close_free_wsi(wsi, 0, "lws_cgi_kill"); } return 0; } -LWS_EXTERN int +int lws_cgi_kill_terminated(struct lws_context_per_thread *pt) { struct lws_cgi **pcgi, *cgi = NULL; @@ -1092,7 +948,7 @@ cgi = *pcgi; pcgi = &(*pcgi)->cgi_list; - if (cgi->pid <= 0) + if (cgi->lsp->child_pid <= 0) continue; /* finish sending cached headers */ @@ -1117,7 +973,7 @@ * but we should do the terminated cgi callback * and close him if he's not already closing */ - if (n == cgi->pid) { + if (n == cgi->lsp->child_pid) { lwsl_debug("%s: found PID %d on cgi list\n", __func__, n); @@ -1132,7 +988,7 @@ } /* defeat kill() */ - cgi->pid = 0; + cgi->lsp->child_pid = 0; lws_cgi_kill(cgi->wsi); break; @@ -1155,7 +1011,7 @@ cgi = *pcgi; pcgi = &(*pcgi)->cgi_list; - if (cgi->pid <= 0) + if (!cgi || !cgi->lsp || cgi->lsp->child_pid <= 0) continue; /* we deferred killing him after reaping his PID */ @@ -1181,7 +1037,7 @@ (unsigned long long)cgi->content_length_seen); /* reap it */ - if (waitpid(cgi->pid, &status, WNOHANG) > 0) { + if (waitpid(cgi->lsp->child_pid, &status, WNOHANG) > 0) { if (!cgi->content_length) { /* @@ -1194,10 +1050,10 @@ } finish_him: lwsl_debug("%s: found PID %d on cgi list\n", - __func__, cgi->pid); + __func__, cgi->lsp->child_pid); /* defeat kill() */ - cgi->pid = 0; + cgi->lsp->child_pid = 0; lws_cgi_kill(cgi->wsi); break; @@ -1207,19 +1063,19 @@ return 0; } -LWS_VISIBLE LWS_EXTERN struct lws * +struct lws * lws_cgi_get_stdwsi(struct lws *wsi, enum lws_enum_stdinouterr ch) { if (!wsi->http.cgi) return NULL; - return wsi->http.cgi->stdwsi[ch]; + return wsi->http.cgi->lsp->stdwsi[ch]; } void lws_cgi_remove_and_kill(struct lws *wsi) { - struct lws_context_per_thread *pt = &wsi->context->pt[(int)wsi->tsi]; + struct lws_context_per_thread *pt = &wsi->a.context->pt[(int)wsi->tsi]; struct lws_cgi **pcgi = &pt->http.cgi_list; /* remove us from the cgi list */ @@ -1233,7 +1089,7 @@ pcgi = &(*pcgi)->cgi_list; } if (wsi->http.cgi->headers_buf) { - lwsl_debug("close: freed cgi headers\n"); + lwsl_debug("%s: close: freed cgi headers\n", __func__); lws_free_set_NULL(wsi->http.cgi->headers_buf); } /* we have a cgi going, we must kill it */ diff -Nru libwebsockets-3.2.1/lib/roles/cgi/CMakeLists.txt libwebsockets-4.1.6/lib/roles/cgi/CMakeLists.txt --- libwebsockets-3.2.1/lib/roles/cgi/CMakeLists.txt 1970-01-01 00:00:00.000000000 +0000 +++ libwebsockets-4.1.6/lib/roles/cgi/CMakeLists.txt 2020-12-01 17:40:26.000000000 +0000 @@ -0,0 +1,42 @@ +# +# libwebsockets - small server side websockets and web server implementation +# +# Copyright (C) 2010 - 2020 Andy Green +# +# Permission is hereby granted, free of charge, to any person obtaining a copy +# of this software and associated documentation files (the "Software"), to +# deal in the Software without restriction, including without limitation the +# rights to use, copy, modify, merge, publish, distribute, sublicense, and/or +# sell copies of the Software, and to permit persons to whom the Software is +# furnished to do so, subject to the following conditions: +# +# The above copyright notice and this permission notice shall be included in +# all copies or substantial portions of the Software. +# +# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING +# FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS +# IN THE SOFTWARE. +# +# The strategy is to only export to PARENT_SCOPE +# +# - changes to LIB_LIST +# - changes to SOURCES +# - includes via include_directories +# +# and keep everything else private + +include_directories(.) + +list(APPEND SOURCES + roles/cgi/cgi-server.c + roles/cgi/ops-cgi.c) + +# +# Keep explicit parent scope exports at end +# + +exports_to_parent_scope() diff -Nru libwebsockets-3.2.1/lib/roles/cgi/ops-cgi.c libwebsockets-4.1.6/lib/roles/cgi/ops-cgi.c --- libwebsockets-3.2.1/lib/roles/cgi/ops-cgi.c 2019-12-18 14:45:31.000000000 +0000 +++ libwebsockets-4.1.6/lib/roles/cgi/ops-cgi.c 2020-12-01 17:40:26.000000000 +0000 @@ -1,25 +1,28 @@ /* * libwebsockets - small server side websockets and web server implementation * - * Copyright (C) 2010-2018 Andy Green + * Copyright (C) 2010 - 2019 Andy Green * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation: - * version 2.1 of the License. + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to + * deal in the Software without restriction, including without limitation the + * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or + * sell copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: * - * This library is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. * - * You should have received a copy of the GNU Lesser General Public - * License along with this library; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, - * MA 02110-1301 USA + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS + * IN THE SOFTWARE. */ -#include +#include static int rops_handle_POLLIN_cgi(struct lws_context_per_thread *pt, struct lws *wsi, @@ -29,28 +32,49 @@ assert(wsi->role_ops == &role_ops_cgi); - if (wsi->cgi_channel >= LWS_STDOUT && + if (wsi->lsp_channel >= LWS_STDOUT && !(pollfd->revents & pollfd->events & LWS_POLLIN)) return LWS_HPI_RET_HANDLED; - if (wsi->cgi_channel == LWS_STDIN && + if (wsi->lsp_channel == LWS_STDIN && !(pollfd->revents & pollfd->events & LWS_POLLOUT)) return LWS_HPI_RET_HANDLED; - if (wsi->cgi_channel == LWS_STDIN && + if (wsi->lsp_channel == LWS_STDIN && lws_change_pollfd(wsi, LWS_POLLOUT, 0)) { lwsl_info("failed at set pollfd\n"); return LWS_HPI_RET_WSI_ALREADY_DIED; } - args.ch = wsi->cgi_channel; - args.stdwsi = &wsi->parent->http.cgi->stdwsi[0]; + if (!wsi->parent) { + lwsl_debug("%s: stdwsi content with parent\n", + __func__); + + return LWS_HPI_RET_HANDLED; + } + + if (!wsi->parent->http.cgi) { + lwsl_notice("%s: stdwsi content with deleted cgi object\n", + __func__); + + return LWS_HPI_RET_HANDLED; + } + + if (!wsi->parent->http.cgi->lsp) { + lwsl_notice("%s: stdwsi content with reaped lsp\n", + __func__); + + return LWS_HPI_RET_HANDLED; + } + + args.ch = wsi->lsp_channel; + args.stdwsi = &wsi->parent->http.cgi->lsp->stdwsi[0]; args.hdr_state = wsi->hdr_state; lwsl_debug("CGI LWS_STDOUT %p wsistate 0x%x\n", wsi->parent, wsi->wsistate); - if (user_callback_handle_rxflow(wsi->parent->protocol->callback, + if (user_callback_handle_rxflow(wsi->parent->a.protocol->callback, wsi->parent, LWS_CALLBACK_CGI, wsi->parent->user_space, (void *)&args, 0)) @@ -66,16 +90,6 @@ } static int -rops_periodic_checks_cgi(struct lws_context *context, int tsi, time_t now) -{ - struct lws_context_per_thread *pt = &context->pt[tsi]; - - lws_cgi_kill_terminated(pt); - - return 0; -} - -static int rops_destroy_role_cgi(struct lws *wsi) { #if defined(LWS_WITH_ZLIB) @@ -91,14 +105,52 @@ return 0; } -struct lws_role_ops role_ops_cgi = { +static void +lws_cgi_sul_cb(lws_sorted_usec_list_t *sul) +{ + struct lws_context_per_thread *pt = lws_container_of(sul, + struct lws_context_per_thread, sul_cgi); + + lws_cgi_kill_terminated(pt); + + __lws_sul_insert_us(&pt->pt_sul_owner[LWSSULLI_MISS_IF_SUSPENDED], + &pt->sul_cgi, 3 * LWS_US_PER_SEC); +} + +static int +rops_pt_init_destroy_cgi(struct lws_context *context, + const struct lws_context_creation_info *info, + struct lws_context_per_thread *pt, int destroy) +{ + if (!destroy) { + + pt->sul_cgi.cb = lws_cgi_sul_cb; + + __lws_sul_insert_us(&pt->pt_sul_owner[LWSSULLI_MISS_IF_SUSPENDED], + &pt->sul_cgi, 3 * LWS_US_PER_SEC); + } else + lws_dll2_remove(&pt->sul_cgi.list); + + return 0; +} + +static int +rops_close_role_cgi(struct lws_context_per_thread *pt, struct lws *wsi) +{ + if (wsi->parent && wsi->parent->http.cgi && wsi->parent->http.cgi->lsp) + lws_spawn_stdwsi_closed(wsi->parent->http.cgi->lsp, wsi); + + return 0; +} + + +const struct lws_role_ops role_ops_cgi = { /* role name */ "cgi", /* alpn id */ NULL, /* check_upgrades */ NULL, - /* init_context */ NULL, + /* pt_init_destroy */ rops_pt_init_destroy_cgi, /* init_vhost */ NULL, /* destroy_vhost */ NULL, - /* periodic_checks */ rops_periodic_checks_cgi, /* service_flag_pending */ NULL, /* handle_POLLIN */ rops_handle_POLLIN_cgi, /* handle_POLLOUT */ rops_handle_POLLOUT_cgi, @@ -109,11 +161,12 @@ /* encapsulation_parent */ NULL, /* alpn_negotiated */ NULL, /* close_via_role_protocol */ NULL, - /* close_role */ NULL, + /* close_role */ rops_close_role_cgi, /* close_kill_connection */ NULL, /* destroy_role */ rops_destroy_role_cgi, /* adoption_bind */ NULL, /* client_bind */ NULL, + /* issue_keepalive */ NULL, /* adoption_cb clnt, srv */ { 0, 0 }, /* rx_cb clnt, srv */ { 0, 0 }, /* writeable cb clnt, srv */ { 0, 0 }, diff -Nru libwebsockets-3.2.1/lib/roles/cgi/private.h libwebsockets-4.1.6/lib/roles/cgi/private.h --- libwebsockets-3.2.1/lib/roles/cgi/private.h 2019-12-18 14:45:31.000000000 +0000 +++ libwebsockets-4.1.6/lib/roles/cgi/private.h 1970-01-01 00:00:00.000000000 +0000 @@ -1,87 +0,0 @@ -/* - * libwebsockets - small server side websockets and web server implementation - * - * Copyright (C) 2010 - 2018 Andy Green - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation: - * version 2.1 of the License. - * - * This library is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with this library; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, - * MA 02110-1301 USA - * - * This is included from core/private.h if LWS_ROLE_WS - */ - -#if defined(LWS_WITH_ZLIB) -#if defined(LWS_WITH_MINIZ) -#include -#else -#include -#endif -#endif - -extern struct lws_role_ops role_ops_cgi; - -#define lwsi_role_cgi(wsi) (wsi->role_ops == &role_ops_cgi) - -#define LWS_HTTP_CHUNK_HDR_SIZE 16 - -enum { - SIGNIFICANT_HDR_CONTENT_LENGTH, /* numeric */ - SIGNIFICANT_HDR_LOCATION, - SIGNIFICANT_HDR_STATUS, /* numeric */ - SIGNIFICANT_HDR_TRANSFER_ENCODING, - SIGNIFICANT_HDR_CONTENT_ENCODING_GZIP, - - SIGNIFICANT_HDR_COUNT -}; - -struct lws; - -/* wsi who is master of the cgi points to an lws_cgi */ - -struct lws_cgi { - struct lws_cgi *cgi_list; - struct lws *stdwsi[3]; /* points to the associated stdin/out/err wsis */ - struct lws *wsi; /* owner */ - unsigned char *headers_buf; - unsigned char *headers_start; - unsigned char *headers_pos; - unsigned char *headers_dumped; - unsigned char *headers_end; - - char summary[128]; -#if defined(LWS_WITH_ZLIB) - z_stream inflate; - uint8_t inflate_buf[1024]; -#endif - - lws_filepos_t post_in_expected; - lws_filepos_t content_length; - lws_filepos_t content_length_seen; - - int pipe_fds[3][2]; - int match[SIGNIFICANT_HDR_COUNT]; - char l[12]; - int pid; - int response_code; - int lp; - - unsigned char being_closed:1; - unsigned char explicitly_chunked:1; - unsigned char cgi_transaction_over:1; - unsigned char implied_chunked:1; - unsigned char gzip_inflate:1; - unsigned char gzip_init:1; - - unsigned char chunked_grace; -}; diff -Nru libwebsockets-3.2.1/lib/roles/cgi/private-lib-roles-cgi.h libwebsockets-4.1.6/lib/roles/cgi/private-lib-roles-cgi.h --- libwebsockets-3.2.1/lib/roles/cgi/private-lib-roles-cgi.h 1970-01-01 00:00:00.000000000 +0000 +++ libwebsockets-4.1.6/lib/roles/cgi/private-lib-roles-cgi.h 2020-12-01 17:40:26.000000000 +0000 @@ -0,0 +1,91 @@ + /* + * libwebsockets - small server side websockets and web server implementation + * + * Copyright (C) 2010 - 2019 Andy Green + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to + * deal in the Software without restriction, including without limitation the + * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or + * sell copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS + * IN THE SOFTWARE. + * + * This is included from private-lib-core.h if LWS_ROLE_WS + */ + +#if defined(LWS_WITH_ZLIB) +#if defined(LWS_WITH_MINIZ) +#include +#else +#include +#endif +#endif + +extern const struct lws_role_ops role_ops_cgi; + +#define lwsi_role_cgi(wsi) (wsi->role_ops == &role_ops_cgi) + +#define LWS_HTTP_CHUNK_HDR_SIZE 16 + +enum { + SIGNIFICANT_HDR_CONTENT_LENGTH, /* numeric */ + SIGNIFICANT_HDR_LOCATION, + SIGNIFICANT_HDR_STATUS, /* numeric */ + SIGNIFICANT_HDR_TRANSFER_ENCODING, + SIGNIFICANT_HDR_CONTENT_ENCODING_GZIP, + + SIGNIFICANT_HDR_COUNT +}; + +struct lws; + +/* wsi who is master of the cgi points to an lws_cgi */ + +struct lws_cgi { + struct lws_cgi *cgi_list; + + struct lws_spawn_piped *lsp; + lws_sorted_usec_list_t sul_grace; + + struct lws *wsi; /* owner */ + unsigned char *headers_buf; + unsigned char *headers_start; + unsigned char *headers_pos; + unsigned char *headers_dumped; + unsigned char *headers_end; + + char summary[128]; +#if defined(LWS_WITH_ZLIB) + z_stream inflate; + uint8_t inflate_buf[1024]; +#endif + + lws_filepos_t post_in_expected; + lws_filepos_t content_length; + lws_filepos_t content_length_seen; + + int match[SIGNIFICANT_HDR_COUNT]; + char l[12]; + int response_code; + int lp; + + unsigned char being_closed:1; + unsigned char explicitly_chunked:1; + unsigned char cgi_transaction_over:1; + unsigned char implied_chunked:1; + unsigned char gzip_inflate:1; + unsigned char gzip_init:1; + + unsigned char chunked_grace; +}; diff -Nru libwebsockets-3.2.1/lib/roles/CMakeLists.txt libwebsockets-4.1.6/lib/roles/CMakeLists.txt --- libwebsockets-3.2.1/lib/roles/CMakeLists.txt 1970-01-01 00:00:00.000000000 +0000 +++ libwebsockets-4.1.6/lib/roles/CMakeLists.txt 2020-12-01 17:40:26.000000000 +0000 @@ -0,0 +1,90 @@ +# +# libwebsockets - small server side websockets and web server implementation +# +# Copyright (C) 2010 - 2020 Andy Green +# +# Permission is hereby granted, free of charge, to any person obtaining a copy +# of this software and associated documentation files (the "Software"), to +# deal in the Software without restriction, including without limitation the +# rights to use, copy, modify, merge, publish, distribute, sublicense, and/or +# sell copies of the Software, and to permit persons to whom the Software is +# furnished to do so, subject to the following conditions: +# +# The above copyright notice and this permission notice shall be included in +# all copies or substantial portions of the Software. +# +# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING +# FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS +# IN THE SOFTWARE. +# +# The strategy is to only export to PARENT_SCOPE +# +# - changes to LIB_LIST +# - changes to SOURCES +# - includes via include_directories +# +# and keep everything else private + +include_directories(.) + +if (LWS_ROLE_MQTT) + add_subdir_include_directories(mqtt) +endif() + +if (LWS_ROLE_DBUS AND NOT LWS_PLAT_FREERTOS) + add_subdir_include_directories(dbus) +endif() + +if (LWS_ROLE_H1 OR LWS_ROLE_H2) + add_subdir_include_directories(http) +endif() + +if (LWS_ROLE_H1) + add_subdir_include_directories(h1) +endif() + +if (LWS_ROLE_H2) + add_subdir_include_directories(h2) +endif() + +if (LWS_ROLE_WS) + add_subdir_include_directories(ws) +endif() + +if (LWS_ROLE_RAW) + add_subdir_include_directories(raw-skt) +endif() + +if (LWS_ROLE_RAW_FILE) + add_subdir_include_directories(raw-file) +endif() + +if (LWS_WITH_CGI) + add_subdir_include_directories(cgi) +endif() + +if (LWS_ROLE_RAW_PROXY) + add_subdir_include_directories(raw-proxy) +endif() + +if (NOT LWS_WITHOUT_SERVER OR LWS_WITH_SECURE_STREAMS_PROCESS_API) + add_subdir_include_directories(listen) +endif() + +if (NOT LWS_WITHOUT_CLIENT) + list(APPEND SOURCES + roles/http/client/client-http.c + roles/http/client/client-handshake.c) +endif() + +# +# Keep explicit parent scope exports at end +# + +exports_to_parent_scope() +set(LWS_DEPS_LIB_PATHS ${LWS_DEPS_LIB_PATHS} PARENT_SCOPE) + diff -Nru libwebsockets-3.2.1/lib/roles/dbus/CMakeLists.txt libwebsockets-4.1.6/lib/roles/dbus/CMakeLists.txt --- libwebsockets-3.2.1/lib/roles/dbus/CMakeLists.txt 1970-01-01 00:00:00.000000000 +0000 +++ libwebsockets-4.1.6/lib/roles/dbus/CMakeLists.txt 2020-12-01 17:40:26.000000000 +0000 @@ -0,0 +1,65 @@ +# +# libwebsockets - small server side websockets and web server implementation +# +# Copyright (C) 2010 - 2020 Andy Green +# +# Permission is hereby granted, free of charge, to any person obtaining a copy +# of this software and associated documentation files (the "Software"), to +# deal in the Software without restriction, including without limitation the +# rights to use, copy, modify, merge, publish, distribute, sublicense, and/or +# sell copies of the Software, and to permit persons to whom the Software is +# furnished to do so, subject to the following conditions: +# +# The above copyright notice and this permission notice shall be included in +# all copies or substantial portions of the Software. +# +# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING +# FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS +# IN THE SOFTWARE. +# +# The strategy is to only export to PARENT_SCOPE +# +# - changes to LIB_LIST +# - changes to SOURCES +# - includes via include_directories +# +# and keep everything else private + +include_directories(.) + +list(APPEND SOURCES + roles/dbus/dbus.c) + +if (NOT LWS_DBUS_LIB) + set(LWS_DBUS_LIB "dbus-1") +endif() + +find_package(PkgConfig QUIET) +pkg_check_modules(PC_DBUS1 dbus-1 QUIET) +list(APPEND LWS_DBUS_INCLUDE1 ${PC_DBUS1_INCLUDE_DIRS}) +list(APPEND LWS_DBUS_LIB ${PC_DBUS1_LIBRARIES}) +list(APPEND LWS_DEPS_LIB_PATHS ${PC_DBUS1_LIBRARY_DIRS}) + +set(CMAKE_REQUIRED_INCLUDES ${CMAKE_REQUIRED_INCLUDES};${LWS_DBUS_INCLUDE1}) + +CHECK_C_SOURCE_COMPILES("#include +int main(void) { + return 0; +}" LWS_DBUS_CHECK_OK) + +message("dbus include dir 1: ${LWS_DBUS_INCLUDE1}") +include_directories("${LWS_DBUS_INCLUDE1}") +list(APPEND LIB_LIST ${LWS_DBUS_LIB}) + +# +# Keep explicit parent scope exports at end +# + +exports_to_parent_scope() +set(LWS_DBUS_CHECK_OK ${LWS_DBUS_CHECK_OK} PARENT_SCOPE) +set(LWS_DEPS_LIB_PATHS ${LWS_DEPS_LIB_PATHS} PARENT_SCOPE) + diff -Nru libwebsockets-3.2.1/lib/roles/dbus/dbus.c libwebsockets-4.1.6/lib/roles/dbus/dbus.c --- libwebsockets-3.2.1/lib/roles/dbus/dbus.c 2019-12-18 14:45:31.000000000 +0000 +++ libwebsockets-4.1.6/lib/roles/dbus/dbus.c 2020-12-01 17:40:26.000000000 +0000 @@ -1,23 +1,25 @@ -/* - * libwebsockets - dbus role - * - * Copyright (C) 2010-2018 Andy Green - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation: - * version 2.1 of the License. - * - * This library is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. + /* + * libwebsockets - small server side websockets and web server implementation * - * You should have received a copy of the GNU Lesser General Public - * License along with this library; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, - * MA 02110-1301 USA + * Copyright (C) 2010 - 2019 Andy Green * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to + * deal in the Software without restriction, including without limitation the + * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or + * sell copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS + * IN THE SOFTWARE. * * This role for wrapping dbus fds in a wsi + role is unusual in that the * wsi it creates and binds to the role do not have control over the related fd @@ -33,7 +35,7 @@ * worries we create a new shadow wsi until it looks like it is closing again. */ -#include +#include #include @@ -46,6 +48,7 @@ static struct lws * __lws_shadow_wsi(struct lws_dbus_ctx *ctx, DBusWatch *w, int fd, int create_ok) { + size_t s = sizeof(struct lws); struct lws *wsi; if (fd < 0 || fd >= (int)ctx->vh->context->fd_limit_per_thread) { @@ -66,18 +69,26 @@ if (!create_ok) return NULL; - wsi = lws_zalloc(sizeof(*wsi), "shadow wsi"); +#if defined(LWS_WITH_EVENT_LIBS) + s += ctx->vh->context->event_loop_ops->evlib_size_wsi; +#endif + + wsi = lws_zalloc(s, "shadow wsi"); if (wsi == NULL) { lwsl_err("Out of mem\n"); return NULL; } +#if defined(LWS_WITH_EVENT_LIBS) + wsi->evlib_wsi = (uint8_t *)wsi + sizeof(*wsi); +#endif + lwsl_info("%s: creating shadow wsi\n", __func__); - wsi->context = ctx->vh->context; + wsi->a.context = ctx->vh->context; wsi->desc.sockfd = fd; lws_role_transition(wsi, 0, LRS_ESTABLISHED, &role_ops_dbus); - wsi->protocol = ctx->vh->protocols; + wsi->a.protocol = ctx->vh->protocols; wsi->tsi = ctx->tsi; wsi->shadow = 1; wsi->opaque_parent_data = ctx; @@ -470,23 +481,18 @@ return LWS_HPI_RET_HANDLED; } -static int -rops_periodic_checks_dbus(struct lws_context *context, int tsi, time_t now) +static void +lws_dbus_sul_cb(lws_sorted_usec_list_t *sul) { - struct lws_context_per_thread *pt = &context->pt[tsi]; - - /* - * locking shouldn't be needed here, because periodic_checks is called - * from the tsi-specific service thread context, and only the same - * service thread can modify stuff on the same pt. - */ + struct lws_context_per_thread *pt = lws_container_of(sul, + struct lws_context_per_thread, dbus.sul); lws_start_foreach_dll_safe(struct lws_dll2 *, rdt, nx, lws_dll2_get_head(&pt->dbus.timer_list_owner)) { struct lws_role_dbus_timer *r = lws_container_of(rdt, struct lws_role_dbus_timer, timer_list); - if (now > r->fire) { + if (time(NULL) > r->fire) { lwsl_notice("%s: firing timer\n", __func__); dbus_timeout_handle(r->data); lws_dll2_remove(rdt); @@ -494,17 +500,31 @@ } } lws_end_foreach_dll_safe(rdt, nx); + lws_sul_schedule(pt->context, pt->tid, &pt->dbus.sul, lws_dbus_sul_cb, + 3 * LWS_US_PER_SEC); +} + +static int +rops_pt_init_destroy_dbus(struct lws_context *context, + const struct lws_context_creation_info *info, + struct lws_context_per_thread *pt, int destroy) +{ + if (!destroy) { + lws_sul_schedule(context, pt->tid, &pt->dbus.sul, lws_dbus_sul_cb, + 3 * LWS_US_PER_SEC); + } else + lws_sul_cancel(&pt->dbus.sul); + return 0; } -struct lws_role_ops role_ops_dbus = { +const struct lws_role_ops role_ops_dbus = { /* role name */ "dbus", /* alpn id */ NULL, /* check_upgrades */ NULL, - /* init_context */ NULL, + /* pt_init_destroy */ rops_pt_init_destroy_dbus, /* init_vhost */ NULL, /* destroy_vhost */ NULL, - /* periodic_checks */ rops_periodic_checks_dbus, /* service_flag_pending */ NULL, /* handle_POLLIN */ rops_handle_POLLIN_dbus, /* handle_POLLOUT */ NULL, @@ -520,6 +540,7 @@ /* destroy_role */ NULL, /* adoption_bind */ NULL, /* client_bind */ NULL, + /* issue_keepalive */ NULL, /* adoption_cb clnt, srv */ { 0, 0 }, /* rx_cb clnt, srv */ { 0, 0 }, /* writeable cb clnt, srv */ { 0, 0 }, diff -Nru libwebsockets-3.2.1/lib/roles/dbus/private.h libwebsockets-4.1.6/lib/roles/dbus/private.h --- libwebsockets-3.2.1/lib/roles/dbus/private.h 2019-12-18 14:45:31.000000000 +0000 +++ libwebsockets-4.1.6/lib/roles/dbus/private.h 1970-01-01 00:00:00.000000000 +0000 @@ -1,42 +0,0 @@ -/* - * libwebsockets - small server side websockets and web server implementation - * - * Copyright (C) 2010 - 2018 Andy Green - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation: - * version 2.1 of the License. - * - * This library is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with this library; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, - * MA 02110-1301 USA - * - * This is included from core/private.h if LWS_ROLE_DBUS - */ - -#include - -extern struct lws_role_ops role_ops_dbus; - -#define lwsi_role_dbus(wsi) (wsi->role_ops == &role_ops_dbus) - -struct lws_role_dbus_timer { - struct lws_dll2 timer_list; - void *data; - time_t fire; -}; - -struct lws_pt_role_dbus { - struct lws_dll2_owner timer_list_owner; -}; - -struct _lws_dbus_mode_related { - DBusConnection *conn; -}; diff -Nru libwebsockets-3.2.1/lib/roles/dbus/private-lib-roles-dbus.h libwebsockets-4.1.6/lib/roles/dbus/private-lib-roles-dbus.h --- libwebsockets-3.2.1/lib/roles/dbus/private-lib-roles-dbus.h 1970-01-01 00:00:00.000000000 +0000 +++ libwebsockets-4.1.6/lib/roles/dbus/private-lib-roles-dbus.h 2020-12-01 17:40:26.000000000 +0000 @@ -0,0 +1,46 @@ + /* + * libwebsockets - small server side websockets and web server implementation + * + * Copyright (C) 2010 - 2019 Andy Green + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to + * deal in the Software without restriction, including without limitation the + * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or + * sell copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS + * IN THE SOFTWARE. + * + * This is included from private-lib-core.h if LWS_ROLE_DBUS + */ + +#include + +extern const struct lws_role_ops role_ops_dbus; + +#define lwsi_role_dbus(wsi) (wsi->role_ops == &role_ops_dbus) + +struct lws_role_dbus_timer { + struct lws_dll2 timer_list; + void *data; + time_t fire; +}; + +struct lws_pt_role_dbus { + struct lws_dll2_owner timer_list_owner; + lws_sorted_usec_list_t sul; +}; + +struct _lws_dbus_mode_related { + DBusConnection *conn; +}; diff -Nru libwebsockets-3.2.1/lib/roles/h1/CMakeLists.txt libwebsockets-4.1.6/lib/roles/h1/CMakeLists.txt --- libwebsockets-3.2.1/lib/roles/h1/CMakeLists.txt 1970-01-01 00:00:00.000000000 +0000 +++ libwebsockets-4.1.6/lib/roles/h1/CMakeLists.txt 2020-12-01 17:40:26.000000000 +0000 @@ -0,0 +1,41 @@ +# +# libwebsockets - small server side websockets and web server implementation +# +# Copyright (C) 2010 - 2020 Andy Green +# +# Permission is hereby granted, free of charge, to any person obtaining a copy +# of this software and associated documentation files (the "Software"), to +# deal in the Software without restriction, including without limitation the +# rights to use, copy, modify, merge, publish, distribute, sublicense, and/or +# sell copies of the Software, and to permit persons to whom the Software is +# furnished to do so, subject to the following conditions: +# +# The above copyright notice and this permission notice shall be included in +# all copies or substantial portions of the Software. +# +# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING +# FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS +# IN THE SOFTWARE. +# +# The strategy is to only export to PARENT_SCOPE +# +# - changes to LIB_LIST +# - changes to SOURCES +# - includes via include_directories +# +# and keep everything else private + +include_directories(.) + +list(APPEND SOURCES + roles/h1/ops-h1.c) + +# +# Keep explicit parent scope exports at end +# + +exports_to_parent_scope() diff -Nru libwebsockets-3.2.1/lib/roles/h1/ops-h1.c libwebsockets-4.1.6/lib/roles/h1/ops-h1.c --- libwebsockets-3.2.1/lib/roles/h1/ops-h1.c 2019-12-18 14:45:31.000000000 +0000 +++ libwebsockets-4.1.6/lib/roles/h1/ops-h1.c 2020-12-01 17:40:26.000000000 +0000 @@ -1,25 +1,28 @@ /* * libwebsockets - small server side websockets and web server implementation * - * Copyright (C) 2010-2018 Andy Green + * Copyright (C) 2010 - 2019 Andy Green * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation: - * version 2.1 of the License. + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to + * deal in the Software without restriction, including without limitation the + * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or + * sell copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: * - * This library is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. * - * You should have received a copy of the GNU Lesser General Public - * License along with this library; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, - * MA 02110-1301 USA + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS + * IN THE SOFTWARE. */ -#include +#include #ifndef min #define min(a, b) ((a) < (b) ? (a) : (b)) @@ -67,7 +70,7 @@ assert(0); } lwsl_parser("issuing %d bytes to parser\n", (int)len); -#if defined(LWS_ROLE_WS) && !defined(LWS_NO_CLIENT) +#if defined(LWS_ROLE_WS) && defined(LWS_WITH_CLIENT) if (lws_ws_handshake_client(wsi, &buf, (size_t)len)) goto bail; #endif @@ -77,8 +80,12 @@ goto bail; /* we might have transitioned to RAW */ - if (wsi->role_ops == &role_ops_raw_skt || - wsi->role_ops == &role_ops_raw_file) + if (wsi->role_ops == &role_ops_raw_skt +#if defined(LWS_ROLE_RAW_FILE) + || + wsi->role_ops == &role_ops_raw_file +#endif + ) /* we gave the read buffer to RAW handler already */ goto read_ok; @@ -137,13 +144,13 @@ struct lws_cgi_args args; args.ch = LWS_STDIN; - args.stdwsi = &wsi->http.cgi->stdwsi[0]; + args.stdwsi = &wsi->http.cgi->lsp->stdwsi[0]; args.data = buf; args.len = body_chunk_len; /* returns how much used */ n = user_callback_handle_rxflow( - wsi->protocol->callback, + wsi->a.protocol->callback, wsi, LWS_CALLBACK_CGI_STDIN_DATA, wsi->user_space, (void *)&args, 0); @@ -152,7 +159,7 @@ } else { #endif if (lwsi_state(wsi) != LRS_DISCARD_BODY) { - n = wsi->protocol->callback(wsi, + n = wsi->a.protocol->callback(wsi, LWS_CALLBACK_HTTP_BODY, wsi->user_space, buf, (size_t)body_chunk_len); if (n) @@ -167,7 +174,7 @@ if (wsi->http.rx_content_remain) { lws_set_timeout(wsi, PENDING_TIMEOUT_HTTP_CONTENT, - wsi->context->timeout_secs); + wsi->a.context->timeout_secs); break; } /* he sent all the content in time */ @@ -179,7 +186,7 @@ */ if (wsi->http.cgi) lws_set_timeout(wsi, PENDING_TIMEOUT_CGI, - wsi->context->timeout_secs); + wsi->a.context->timeout_secs); else #endif lws_set_timeout(wsi, NO_PENDING_TIMEOUT, 0); @@ -187,7 +194,7 @@ if (!wsi->http.cgi) #endif { -#if !defined(LWS_NO_SERVER) +#if defined(LWS_WITH_SERVER) if (lwsi_state(wsi) == LRS_DISCARD_BODY) { /* * repeat the transaction completed @@ -196,20 +203,20 @@ */ if (lws_http_transaction_completed(wsi)) - return -1; + goto bail; break; } #endif lwsl_info("HTTP_BODY_COMPLETION: %p (%s)\n", - wsi, wsi->protocol->name); + wsi, wsi->a.protocol->name); - n = wsi->protocol->callback(wsi, + n = wsi->a.protocol->callback(wsi, LWS_CALLBACK_HTTP_BODY_COMPLETION, wsi->user_space, NULL, 0); if (n) goto bail; - if (wsi->http2_substream) + if (wsi->mux_substream) lwsi_set_state(wsi, LRS_ESTABLISHED); } @@ -223,7 +230,7 @@ case LRS_SHUTDOWN: ws_mode: -#if !defined(LWS_NO_CLIENT) && defined(LWS_ROLE_WS) +#if defined(LWS_WITH_CLIENT) && defined(LWS_ROLE_WS) // lwsl_notice("%s: ws_mode\n", __func__); if (lws_ws_handshake_client(wsi, &buf, (size_t)len)) goto bail; @@ -249,6 +256,9 @@ case LRS_SSL_ACK_PENDING: break; + case LRS_FLUSHING_BEFORE_CLOSE: + break; + case LRS_DEAD_SOCKET: lwsl_err("%s: Unhandled state LRS_DEAD_SOCKET\n", __func__); goto bail; @@ -287,11 +297,11 @@ return -1; } -#if !defined(LWS_NO_SERVER) +#if defined(LWS_WITH_SERVER) static int lws_h1_server_socket_service(struct lws *wsi, struct lws_pollfd *pollfd) { - struct lws_context_per_thread *pt = &wsi->context->pt[(int)wsi->tsi]; + struct lws_context_per_thread *pt = &wsi->a.context->pt[(int)wsi->tsi]; struct lws_tokens ebuf; int n, buffered; @@ -349,7 +359,9 @@ * exhausted and we tried to do a read of some kind. */ - buffered = lws_buflist_aware_read(pt, wsi, &ebuf); + ebuf.token = NULL; + ebuf.len = 0; + buffered = lws_buflist_aware_read(pt, wsi, &ebuf, 0, __func__); switch (ebuf.len) { case 0: lwsl_info("%s: read 0 len a\n", __func__); @@ -386,7 +398,8 @@ if (lwsi_state(wsi) == LRS_ISSUING_FILE) { // lwsl_notice("stashing: wsi %p: bd %d\n", wsi, buffered); - if (lws_buflist_aware_consume(wsi, &ebuf, 0, buffered)) + if (lws_buflist_aware_finished_consuming(wsi, &ebuf, 0, + buffered, __func__)) return LWS_HPI_RET_PLEASE_CLOSE_ME; goto try_pollout; @@ -405,9 +418,10 @@ if (n < 0) /* we closed wsi */ return LWS_HPI_RET_WSI_ALREADY_DIED; - lwsl_debug("%s: consumed %d\n", __func__, n); + // lwsl_notice("%s: consumed %d\n", __func__, n); - if (lws_buflist_aware_consume(wsi, &ebuf, n, buffered)) + if (lws_buflist_aware_finished_consuming(wsi, &ebuf, n, + buffered, __func__)) return LWS_HPI_RET_PLEASE_CLOSE_ME; /* @@ -493,7 +507,7 @@ } #endif - n = user_callback_handle_rxflow(wsi->protocol->callback, wsi, + n = user_callback_handle_rxflow(wsi->a.protocol->callback, wsi, LWS_CALLBACK_HTTP_WRITEABLE, wsi->user_space, NULL, 0); if (n < 0) { @@ -504,6 +518,8 @@ return LWS_HPI_RET_HANDLED; } +#if defined(LWS_WITH_FILE_OPS) + /* >0 == completion, <0 == error * * We'll get a LWS_CALLBACK_HTTP_FILE_COMPLETION callback when @@ -513,6 +529,7 @@ n = lws_serve_http_file_fragment(wsi); if (n < 0) goto fail; +#endif return LWS_HPI_RET_HANDLED; @@ -615,25 +632,26 @@ */ return LWS_HPI_RET_HANDLED; -#if !defined(LWS_NO_SERVER) +#if defined(LWS_WITH_SERVER) if (!lwsi_role_client(wsi)) { int n; lwsl_debug("%s: %p: wsistate 0x%x\n", __func__, wsi, - wsi->wsistate); + (int)wsi->wsistate); n = lws_h1_server_socket_service(wsi, pollfd); if (n != LWS_HPI_RET_HANDLED) return n; if (lwsi_state(wsi) != LRS_SSL_INIT) if (lws_server_socket_service_ssl(wsi, - LWS_SOCK_INVALID)) + LWS_SOCK_INVALID, + !!(pollfd->revents & LWS_POLLIN))) return LWS_HPI_RET_PLEASE_CLOSE_ME; return LWS_HPI_RET_HANDLED; } #endif -#ifndef LWS_NO_CLIENT +#if defined(LWS_WITH_CLIENT) if ((pollfd->revents & LWS_POLLIN) && wsi->hdr_parsing_completed && !wsi->told_user_closed) { @@ -652,12 +670,12 @@ if (lws_change_pollfd(wsi, LWS_POLLIN, 0)) return LWS_HPI_RET_PLEASE_CLOSE_ME; - //lwsl_notice("calling back %s\n", wsi->protocol->name); + //lwsl_notice("calling back %s\n", wsi->a.protocol->name); /* let user code know, he'll usually ask for writeable * callback and drain / re-enable it there */ - if (user_callback_handle_rxflow(wsi->protocol->callback, wsi, + if (user_callback_handle_rxflow(wsi->a.protocol->callback, wsi, LWS_CALLBACK_RECEIVE_CLIENT_HTTP, wsi->user_space, NULL, 0)) { lwsl_info("RECEIVE_CLIENT_HTTP closed it\n"); @@ -671,14 +689,14 @@ // if (lwsi_state(wsi) == LRS_ESTABLISHED) // return LWS_HPI_RET_HANDLED; -#if !defined(LWS_NO_CLIENT) +#if defined(LWS_WITH_CLIENT) if ((pollfd->revents & LWS_POLLOUT) && lws_handle_POLLOUT_event(wsi, pollfd)) { lwsl_debug("POLLOUT event closed it\n"); return LWS_HPI_RET_PLEASE_CLOSE_ME; } - if (lws_client_socket_service(wsi, pollfd, NULL)) + if (lws_client_socket_service(wsi, pollfd)) return LWS_HPI_RET_WSI_ALREADY_DIED; #endif @@ -735,7 +753,7 @@ #endif lwsi_set_state(wsi, LRS_WAITING_SERVER_REPLY); lws_set_timeout(wsi, PENDING_TIMEOUT_AWAITING_SERVER_RESPONSE, - wsi->context->timeout_secs); + wsi->a.context->timeout_secs); } } #endif @@ -758,7 +776,7 @@ #if defined(LWS_WITH_HTTP_STREAM_COMPRESSION) if (wsi->http.lcs && (((*wp) & 0x1f) == LWS_WRITE_HTTP_FINAL || ((*wp) & 0x1f) == LWS_WRITE_HTTP)) { - unsigned char mtubuf[1400 + LWS_PRE + + unsigned char mtubuf[1500 + LWS_PRE + LWS_HTTP_CHUNK_HDR_MAX_SIZE + LWS_HTTP_CHUNK_TRL_MAX_SIZE], *out = mtubuf + LWS_PRE + @@ -820,7 +838,7 @@ rops_alpn_negotiated_h1(struct lws *wsi, const char *alpn) { lwsl_debug("%s: client %d\n", __func__, lwsi_role_client(wsi)); -#if !defined(LWS_NO_CLIENT) +#if defined(LWS_WITH_CLIENT) if (lwsi_role_client(wsi)) { /* * If alpn asserts it is http/1.1, server support for KA is @@ -839,7 +857,7 @@ static int rops_destroy_role_h1(struct lws *wsi) { - struct lws_context_per_thread *pt = &wsi->context->pt[(int)wsi->tsi]; + struct lws_context_per_thread *pt = &wsi->a.context->pt[(int)wsi->tsi]; struct allocated_headers *ah; /* we may not have an ah, but may be on the waiting list... */ @@ -869,7 +887,7 @@ return 0; } -#if !defined(LWS_NO_SERVER) +#if defined(LWS_WITH_SERVER) static int rops_adoption_bind_h1(struct lws *wsi, int type, const char *vh_prot_name) @@ -889,35 +907,53 @@ return 1; } - lws_role_transition(wsi, LWSIFR_SERVER, (type & LWS_ADOPT_ALLOW_SSL) ? - LRS_SSL_INIT : LRS_HEADERS, &role_ops_h1); +#if defined(LWS_WITH_SERVER) && defined(LWS_WITH_SECURE_STREAMS) + if (wsi->a.vhost->ss_handle && + wsi->a.vhost->ss_handle->policy->protocol == LWSSSP_RAW) { + lws_role_transition(wsi, LWSIFR_SERVER, (type & LWS_ADOPT_ALLOW_SSL) ? + LRS_SSL_INIT : LRS_ESTABLISHED, &role_ops_raw_skt); + return 1; + } +#endif + + /* If Non-TLS and HTTP2 prior knowledge is enabled, skip to clear text HTTP2 */ + +#if defined(LWS_WITH_HTTP2) + if ((!(type & LWS_ADOPT_ALLOW_SSL)) && (wsi->a.vhost->options & LWS_SERVER_OPTION_H2_PRIOR_KNOWLEDGE)) { + lwsl_info("http/2 prior knowledge\n"); + lws_role_call_alpn_negotiated(wsi, "h2"); + } + else +#endif + lws_role_transition(wsi, LWSIFR_SERVER, (type & LWS_ADOPT_ALLOW_SSL) ? + LRS_SSL_INIT : LRS_HEADERS, &role_ops_h1); /* - * We have to bind to h1 as a default even when we're actually going to + * Otherwise, we have to bind to h1 as a default even when we're actually going to * replace it as an h2 bind later. So don't take this seriously if the * default is disabled (ws upgrade caees properly about it) */ - if (!vh_prot_name && wsi->vhost->default_protocol_index < - wsi->vhost->count_protocols) - wsi->protocol = &wsi->vhost->protocols[ - wsi->vhost->default_protocol_index]; + if (!vh_prot_name && wsi->a.vhost->default_protocol_index < + wsi->a.vhost->count_protocols) + wsi->a.protocol = &wsi->a.vhost->protocols[ + wsi->a.vhost->default_protocol_index]; else - wsi->protocol = &wsi->vhost->protocols[0]; + wsi->a.protocol = &wsi->a.vhost->protocols[0]; /* the transport is accepted... give him time to negotiate */ lws_set_timeout(wsi, PENDING_TIMEOUT_ESTABLISH_WITH_SERVER, - wsi->context->timeout_secs); + wsi->a.context->timeout_secs); return 1; /* bound */ } #endif -#if !defined(LWS_NO_CLIENT) +#if defined(LWS_WITH_CLIENT) static const char * const http_methods[] = { - "GET", "POST", "OPTIONS", "PUT", "PATCH", "DELETE", "CONNECT" + "GET", "POST", "OPTIONS", "HEAD", "PUT", "PATCH", "DELETE", "CONNECT" }; static int @@ -934,7 +970,7 @@ * we can assign the user space now, otherwise do it after the * ws subprotocol negotiated */ - if (!wsi->user_space && wsi->stash->method) + if (!wsi->user_space && wsi->stash->cis[CIS_METHOD]) if (lws_ensure_user_space(wsi)) return 1; @@ -948,11 +984,8 @@ * only try h2 if he assertively said to use h2 alpn, otherwise * ws implies alpn restriction to h1. */ - if (!wsi->stash->method && !wsi->stash->alpn) { - wsi->stash->alpn = lws_strdup("http/1.1"); - if (!wsi->stash->alpn) - return 1; - } + if (!wsi->stash->cis[CIS_METHOD] && !wsi->stash->cis[CIS_ALPN]) + wsi->stash->cis[CIS_ALPN] = "http/1.1"; /* if we went on the ah waiting list, it's ok, we can wait. * @@ -960,7 +993,7 @@ * lws_http_client_connect_via_info2(). */ if (lws_header_table_attach(wsi, 0) -#ifndef LWS_NO_CLIENT +#if defined(LWS_WITH_CLIENT) < 0) /* * if we failed here, the connection is already closed @@ -977,19 +1010,24 @@ /* * Clients that want to be h1, h2, or ws all start out as h1 - * (we don't yet know if the server supports h2 or ws) + * (we don't yet know if the server supports h2 or ws), unless their + * alpn is only "h2" */ +// if (i->alpn && !strcmp(i->alpn, "h2")) +// return 0; /* we are h1, he only wants h2 */ + if (!i->method) { /* websockets */ #if defined(LWS_ROLE_WS) if (lws_create_client_ws_object(i, wsi)) goto fail_wsi; + + goto bind_h1; #else lwsl_err("%s: ws role not configured\n", __func__); goto fail_wsi; #endif - goto bind_h1; } /* if a recognized http method, bind to it */ @@ -1084,53 +1122,49 @@ rops_close_kill_connection_h1(struct lws *wsi, enum lws_close_status reason) { #if defined(LWS_WITH_HTTP_PROXY) - struct lws *wsi_eff = lws_client_wsi_effective(wsi); - - if (!wsi_eff->http.proxy_clientside) + if (!wsi->http.proxy_clientside) return 0; - wsi_eff->http.proxy_clientside = 0; + wsi->http.proxy_clientside = 0; - if (user_callback_handle_rxflow(wsi_eff->protocol->callback, wsi_eff, + if (user_callback_handle_rxflow(wsi->a.protocol->callback, wsi, LWS_CALLBACK_COMPLETED_CLIENT_HTTP, - wsi_eff->user_space, NULL, 0)) + wsi->user_space, NULL, 0)) return 0; #endif return 0; } int -rops_init_context_h1(struct lws_context *context, - const struct lws_context_creation_info *info) +rops_pt_init_destroy_h1(struct lws_context *context, + const struct lws_context_creation_info *info, + struct lws_context_per_thread *pt, int destroy) { /* * We only want to do this once... we will do it if no h2 support * otherwise let h2 ops do it. */ -#if !defined(LWS_ROLE_H2) - int n; - - for (n = 0; n < context->count_threads; n++) { - struct lws_context_per_thread *pt = &context->pt[n]; +#if !defined(LWS_ROLE_H2) && defined(LWS_WITH_SERVER) + if (!destroy) { pt->sul_ah_lifecheck.cb = lws_sul_http_ah_lifecheck; - __lws_sul_insert(&pt->pt_sul_owner, &pt->sul_ah_lifecheck, - 30 * LWS_US_PER_SEC); - } + __lws_sul_insert_us(&pt->pt_sul_owner[LWSSULLI_MISS_IF_SUSPENDED], + &pt->sul_ah_lifecheck, 30 * LWS_US_PER_SEC); + } else + lws_dll2_remove(&pt->sul_ah_lifecheck.list); #endif return 0; } -struct lws_role_ops role_ops_h1 = { +const struct lws_role_ops role_ops_h1 = { /* role name */ "h1", /* alpn id */ "http/1.1", /* check_upgrades */ NULL, - /* init_context */ rops_init_context_h1, + /* pt_init_destroy */ rops_pt_init_destroy_h1, /* init_vhost */ NULL, /* destroy_vhost */ NULL, - /* periodic_checks */ NULL, /* service_flag_pending */ NULL, /* handle_POLLIN */ rops_handle_POLLIN_h1, /* handle_POLLOUT */ rops_handle_POLLOUT_h1, @@ -1144,16 +1178,17 @@ /* close_role */ NULL, /* close_kill_connection */ rops_close_kill_connection_h1, /* destroy_role */ rops_destroy_role_h1, -#if !defined(LWS_NO_SERVER) +#if defined(LWS_WITH_SERVER) /* adoption_bind */ rops_adoption_bind_h1, #else NULL, #endif -#if !defined(LWS_NO_CLIENT) +#if defined(LWS_WITH_CLIENT) /* client_bind */ rops_client_bind_h1, #else NULL, #endif + /* issue_keepalive */ NULL, /* adoption_cb clnt, srv */ { LWS_CALLBACK_SERVER_NEW_CLIENT_INSTANTIATED, LWS_CALLBACK_SERVER_NEW_CLIENT_INSTANTIATED }, /* rx_cb clnt, srv */ { LWS_CALLBACK_RECEIVE_CLIENT_HTTP, diff -Nru libwebsockets-3.2.1/lib/roles/h1/private.h libwebsockets-4.1.6/lib/roles/h1/private.h --- libwebsockets-3.2.1/lib/roles/h1/private.h 2019-12-18 14:45:31.000000000 +0000 +++ libwebsockets-4.1.6/lib/roles/h1/private.h 1970-01-01 00:00:00.000000000 +0000 @@ -1,27 +0,0 @@ -/* - * libwebsockets - small server side websockets and web server implementation - * - * Copyright (C) 2010 - 2018 Andy Green - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation: - * version 2.1 of the License. - * - * This library is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with this library; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, - * MA 02110-1301 USA - * - * 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 - */ - -extern struct lws_role_ops role_ops_h1; -#define lwsi_role_h1(wsi) (wsi->role_ops == &role_ops_h1) diff -Nru libwebsockets-3.2.1/lib/roles/h1/private-lib-roles-h1.h libwebsockets-4.1.6/lib/roles/h1/private-lib-roles-h1.h --- libwebsockets-3.2.1/lib/roles/h1/private-lib-roles-h1.h 1970-01-01 00:00:00.000000000 +0000 +++ libwebsockets-4.1.6/lib/roles/h1/private-lib-roles-h1.h 2020-12-01 17:40:26.000000000 +0000 @@ -0,0 +1,30 @@ + /* + * libwebsockets - small server side websockets and web server implementation + * + * Copyright (C) 2010 - 2019 Andy Green + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to + * deal in the Software without restriction, including without limitation the + * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or + * sell copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS + * IN THE SOFTWARE. + * + * This is included from private-lib-core.h if LWS_ROLE_H1 + * + * Most of the h1 business is defined in the h1 / h2 common roles/http dir + */ + +extern const struct lws_role_ops role_ops_h1; +#define lwsi_role_h1(wsi) (wsi->role_ops == &role_ops_h1) diff -Nru libwebsockets-3.2.1/lib/roles/h2/CMakeLists.txt libwebsockets-4.1.6/lib/roles/h2/CMakeLists.txt --- libwebsockets-3.2.1/lib/roles/h2/CMakeLists.txt 1970-01-01 00:00:00.000000000 +0000 +++ libwebsockets-4.1.6/lib/roles/h2/CMakeLists.txt 2020-12-01 17:40:26.000000000 +0000 @@ -0,0 +1,44 @@ +# +# libwebsockets - small server side websockets and web server implementation +# +# Copyright (C) 2010 - 2020 Andy Green +# +# Permission is hereby granted, free of charge, to any person obtaining a copy +# of this software and associated documentation files (the "Software"), to +# deal in the Software without restriction, including without limitation the +# rights to use, copy, modify, merge, publish, distribute, sublicense, and/or +# sell copies of the Software, and to permit persons to whom the Software is +# furnished to do so, subject to the following conditions: +# +# The above copyright notice and this permission notice shall be included in +# all copies or substantial portions of the Software. +# +# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING +# FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS +# IN THE SOFTWARE. +# +# The strategy is to only export to PARENT_SCOPE +# +# - changes to LIB_LIST +# - changes to SOURCES +# - includes via include_directories +# +# and keep everything else private + +include_directories(.) + +list(APPEND SOURCES + roles/h2/http2.c + roles/h2/hpack.c + roles/h2/ops-h2.c) + +# +# Keep explicit parent scope exports at end +# + +exports_to_parent_scope() + diff -Nru libwebsockets-3.2.1/lib/roles/h2/hpack.c libwebsockets-4.1.6/lib/roles/h2/hpack.c --- libwebsockets-3.2.1/lib/roles/h2/hpack.c 2019-12-18 14:45:31.000000000 +0000 +++ libwebsockets-4.1.6/lib/roles/h2/hpack.c 2020-12-01 17:40:26.000000000 +0000 @@ -1,25 +1,28 @@ /* - * lib/hpack.c + * libwebsockets - small server side websockets and web server implementation * - * Copyright (C) 2014-2019 Andy Green + * Copyright (C) 2010 - 2019 Andy Green * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation: - * version 2.1 of the License. + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to + * deal in the Software without restriction, including without limitation the + * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or + * sell copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: * - * This library is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. * - * You should have received a copy of the GNU Lesser General Public - * License along with this library; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, - * MA 02110-1301 USA + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS + * IN THE SOFTWARE. */ -#include "core/private.h" +#include "private-lib-core.h" /* * Official static header table for HPACK @@ -280,7 +283,7 @@ ah->data[ah->pos++] = c; ah->frags[ah->nfrag].len++; - return (int)ah->pos >= wsi->context->max_http_header_data; + return (int)ah->pos >= wsi->a.context->max_http_header_data; } static int lws_frag_end(struct lws *wsi) @@ -330,9 +333,11 @@ strcpy(s, "(too big to show)"); else s[len] = '\0'; +#if defined(_DEBUG) p = lws_token_to_string(hdr); lwsl_header(" hdr tok %d (%s) = '%s' (len %d)\n", hdr, p ? (char *)p : (char *)"null", s, len); +#endif } /* @@ -391,17 +396,16 @@ return -1; } - if (index < (int)LWS_ARRAY_SIZE(static_token) || - index >= (int)LWS_ARRAY_SIZE(static_token) + dyn->used_entries) { + if (index >= (int)LWS_ARRAY_SIZE(static_token) + dyn->used_entries) { lwsl_info(" %s: adjusted index %d >= %d\n", __func__, index, - dyn->used_entries); + (int)LWS_ARRAY_SIZE(static_token) + dyn->used_entries); lws_h2_goaway(wsi, H2_ERR_COMPRESSION_ERROR, "index out of range"); return -1; } index -= (int)LWS_ARRAY_SIZE(static_token); - index = (dyn->pos - 1 - index) % dyn->num_entries; + index = lws_safe_modulo(dyn->pos - 1 - index, dyn->num_entries); if (index < 0) index += dyn->num_entries; @@ -439,7 +443,7 @@ dyn->virtual_payload_usage, dyn->virtual_payload_max); for (n = 0; n < dyn->used_entries; n++) { - m = (dyn->pos - 1 - n) % dyn->num_entries; + m = lws_safe_modulo(dyn->pos - 1 - n, dyn->num_entries); if (m < 0) m += dyn->num_entries; if (dyn->entries[m].lws_hdr_idx != LWS_HPACK_IGNORE_ENTRY) @@ -504,7 +508,7 @@ } lws_h2_dynamic_table_dump(wsi); - new_index = (dyn->pos) % dyn->num_entries; + new_index = lws_safe_modulo(dyn->pos, dyn->num_entries); if (dyn->num_entries && dyn->used_entries == dyn->num_entries) { if (dyn->virtual_payload_usage < dyn->virtual_payload_max) lwsl_err("Dropping header content before limit!\n"); @@ -522,7 +526,8 @@ dyn->used_entries && dyn->virtual_payload_usage + hdr_len + len > dyn->virtual_payload_max + 1024) { - int n = (dyn->pos - dyn->used_entries) % dyn->num_entries; + int n = lws_safe_modulo(dyn->pos - dyn->used_entries, + dyn->num_entries); if (n < 0) n += dyn->num_entries; lws_dynamic_free(dyn, n); @@ -557,7 +562,7 @@ lws_hdr_index, hdr_len, dyn->entries[new_index].value ? dyn->entries[new_index].value : "null", len); - dyn->pos = (dyn->pos + 1) % dyn->num_entries; + dyn->pos = lws_safe_modulo(dyn->pos + 1, dyn->num_entries); lws_h2_dynamic_table_dump(wsi); @@ -593,29 +598,29 @@ goto bail; dyn = &nwsi->h2.h2n->hpack_dyn_table; - lwsl_info("%s: from %d to %d, lim %d\n", __func__, + lwsl_info("%s: from %d to %d, lim %u\n", __func__, (int)dyn->num_entries, size, - nwsi->vhost->h2.set.s[H2SET_HEADER_TABLE_SIZE]); + (unsigned int)nwsi->a.vhost->h2.set.s[H2SET_HEADER_TABLE_SIZE]); if (!size) { size = dyn->num_entries * 8; lws_hpack_destroy_dynamic_header(wsi); } - if (size > (int)nwsi->vhost->h2.set.s[H2SET_HEADER_TABLE_SIZE]) { + if (size > (int)nwsi->a.vhost->h2.set.s[H2SET_HEADER_TABLE_SIZE]) { lwsl_info("rejecting hpack dyn size %u vs %u\n", size, - nwsi->vhost->h2.set.s[H2SET_HEADER_TABLE_SIZE]); + (unsigned int)nwsi->a.vhost->h2.set.s[H2SET_HEADER_TABLE_SIZE]); // this seems necessary to work with some browsers - if (nwsi->vhost->h2.set.s[H2SET_HEADER_TABLE_SIZE] == 65536 && + if (nwsi->a.vhost->h2.set.s[H2SET_HEADER_TABLE_SIZE] == 65536 && size == 65537) { /* h2spec */ lws_h2_goaway(nwsi, H2_ERR_COMPRESSION_ERROR, "Asked for header table bigger than we told"); goto bail; } - size = nwsi->vhost->h2.set.s[H2SET_HEADER_TABLE_SIZE]; + size = nwsi->a.vhost->h2.set.s[H2SET_HEADER_TABLE_SIZE]; } dyn->virtual_payload_max = size; @@ -639,7 +644,7 @@ while (dyn->virtual_payload_usage && dyn->used_entries && dyn->virtual_payload_usage > dyn->virtual_payload_max) { - n = (dyn->pos - dyn->used_entries) % dyn->num_entries; + n = lws_safe_modulo(dyn->pos - dyn->used_entries, dyn->num_entries); if (n < 0) n += dyn->num_entries; lws_dynamic_free(dyn, n); @@ -664,7 +669,7 @@ dyn->num_entries = size; dyn->used_entries = min; if (size) - dyn->pos = min % size; + dyn->pos = lws_safe_modulo(min, size); else dyn->pos = 0; @@ -752,10 +757,47 @@ return 0; } +#if !defined(LWS_HTTP_HEADERS_ALL) && !defined(LWS_WITH_HTTP_UNCOMMON_HEADERS) && !defined(LWS_ROLE_WS) && !defined(LWS_ROLE_H2) +static uint8_t lws_header_implies_psuedoheader_map[] = { + 0x03,0x00,0x00,0x00,0x00,0x00,0x01,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, +}; +#endif +#if !defined(LWS_HTTP_HEADERS_ALL) && defined(LWS_WITH_HTTP_UNCOMMON_HEADERS) && !defined(LWS_ROLE_WS) && !defined(LWS_ROLE_H2) +static uint8_t lws_header_implies_psuedoheader_map[] = { + 0x07,0x00,0x00,0x00,0x00,0x00,0x00,0x0e,0x04,0x00,0x00,0x00,0x00,0x00,0x00,0x00, +}; +#endif +#if !defined(LWS_HTTP_HEADERS_ALL) && !defined(LWS_WITH_HTTP_UNCOMMON_HEADERS) && defined(LWS_ROLE_WS) && !defined(LWS_ROLE_H2) +static uint8_t lws_header_implies_psuedoheader_map[] = { + 0x03,0x00,0x00,0x00,0x00,0x00,0x00,0x04,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, +}; +#endif +#if !defined(LWS_HTTP_HEADERS_ALL) && defined(LWS_WITH_HTTP_UNCOMMON_HEADERS) && defined(LWS_ROLE_WS) && !defined(LWS_ROLE_H2) static uint8_t lws_header_implies_psuedoheader_map[] = { - 0x07, 0x00, 0x00, 0x00, 0xf8, 0x00, 0x00, 0x00, 0x00 /* <-64 */, - 0x0e /* <- 72 */, 0x04 /* <- 80 */, 0, 0, 0, 0 + 0x07,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x38,0x10,0x00,0x00,0x00,0x00,0x00,0x00, }; +#endif +#if !defined(LWS_HTTP_HEADERS_ALL) && !defined(LWS_WITH_HTTP_UNCOMMON_HEADERS) && !defined(LWS_ROLE_WS) && defined(LWS_ROLE_H2) +static uint8_t lws_header_implies_psuedoheader_map[] = { + 0x03,0x00,0x80,0x0f,0x00,0x00,0x00,0x00,0x12,0x00,0x00,0x00,0x00,0x00,0x00,0x00, +}; +#endif +#if !defined(LWS_HTTP_HEADERS_ALL) && defined(LWS_WITH_HTTP_UNCOMMON_HEADERS) && !defined(LWS_ROLE_WS) && defined(LWS_ROLE_H2) +static uint8_t lws_header_implies_psuedoheader_map[] = { + 0x07,0x00,0x00,0x3e,0x00,0x00,0x00,0x80,0x03,0x09,0x00,0x00,0x00,0x00,0x00,0x00, +}; +#endif +#if !defined(LWS_HTTP_HEADERS_ALL) && !defined(LWS_WITH_HTTP_UNCOMMON_HEADERS) && defined(LWS_ROLE_WS) && defined(LWS_ROLE_H2) +static uint8_t lws_header_implies_psuedoheader_map[] = { + 0x03,0x00,0x00,0x00,0x3e,0x00,0x00,0x00,0x00,0x48,0x00,0x00,0x00,0x00,0x00,0x00, +}; +#endif +#if defined(LWS_HTTP_HEADERS_ALL) || ( defined(LWS_WITH_HTTP_UNCOMMON_HEADERS) && defined(LWS_ROLE_WS) && defined(LWS_ROLE_H2)) +static uint8_t lws_header_implies_psuedoheader_map[] = { + 0x07,0x00,0x00,0x00,0xf8,0x00,0x00,0x00,0x00,0x0e,0x24,0x00,0x00,0x00,0x00,0x00, +}; +#endif + static int lws_hpack_handle_pseudo_rules(struct lws *nwsi, struct lws *wsi, int m) @@ -956,7 +998,7 @@ /* extended integer done */ h2n->hpack_len += h2n->hpack_m; - lwsl_header("HPKS_IDX_EXT: hpack_len %d\n", h2n->hpack_len); + lwsl_header("HPKS_IDX_EXT: hpack_len %u\n", (unsigned int)h2n->hpack_len); switch (h2n->hpack_type) { case HPKT_INDEXED_HDR_7: @@ -1000,6 +1042,13 @@ h2n->hpack = HPKS_HLEN_EXT; break; } + + if (h2n->value && !h2n->hpack_len) { + lwsl_debug("%s: zero-length header data\n", __func__); + h2n->hpack = HPKS_TYPE; + goto fin; + } + pre_data: h2n->hpack = HPKS_DATA; if (!h2n->value || !h2n->hdr_idx) { @@ -1021,8 +1070,8 @@ } else { n = lws_token_from_index(wsi, h2n->hdr_idx, NULL, NULL, NULL); - lwsl_header(" lws_tok_from_idx(%d) says %d\n", - h2n->hdr_idx, n); + lwsl_header(" lws_tok_from_idx(%u) says %d\n", + (unsigned int)h2n->hdr_idx, n); } if (n == LWS_HPACK_IGNORE_ENTRY || n == -1) @@ -1177,7 +1226,7 @@ "Huffman padding excessive or wrong"); return 1; } - +fin: if (!h2n->value && ( h2n->hpack_type == HPKT_LITERAL_HDR_VALUE || h2n->hpack_type == HPKT_LITERAL_HDR_VALUE_INCR || @@ -1205,8 +1254,6 @@ } } - n = 8; - /* we have the header */ if (!h2n->value) { h2n->value = 1; @@ -1231,6 +1278,13 @@ /* header length is determined by known index */ m = lws_token_from_index(wsi, h2n->hdr_idx, NULL, NULL, &h2n->hpack_hdr_len); + if (m < 0) + /* + * The peer may only send known 6-bit indexes, + * there's still the possibility it sends an unset + * dynamic index that we can't succeed to look up + */ + return 1; goto add_it; /* NEW literal hdr with value */ case HPKT_LITERAL_HDR_VALUE_INCR: @@ -1346,14 +1400,22 @@ { int len; - lwsl_header("%s: %p %s:%s\n", __func__, *p, name, value); +#if defined(_DEBUG) + /* value does not have to be NUL-terminated... %.*s not available on + * all platforms */ + lws_strnncpy((char *)*p, (const char *)value, length, + lws_ptr_diff(end, (*p))); + + lwsl_header("%s: %p %s:%s (len %d)\n", __func__, *p, name, + (const char *)*p, length); +#endif len = (int)strlen((char *)name); if (len) if (name[len - 1] == ':') len--; - if (wsi->http2_substream && !strncmp((const char *)name, + if (wsi->mux_substream && !strncmp((const char *)name, "transfer-encoding", len)) { lwsl_header("rejecting %s\n", name); diff -Nru libwebsockets-3.2.1/lib/roles/h2/http2.c libwebsockets-4.1.6/lib/roles/h2/http2.c --- libwebsockets-3.2.1/lib/roles/h2/http2.c 2019-12-18 14:45:31.000000000 +0000 +++ libwebsockets-4.1.6/lib/roles/h2/http2.c 2020-12-01 17:40:26.000000000 +0000 @@ -1,26 +1,28 @@ /* * libwebsockets - small server side websockets and web server implementation * - * Copyright (C) 2010-2018 Andy Green + * Copyright (C) 2010 - 2019 Andy Green * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation: - * version 2.1 of the License. + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to + * deal in the Software without restriction, including without limitation the + * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or + * sell copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: * - * This library is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. * - * You should have received a copy of the GNU Lesser General Public - * License along with this library; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, - * MA 02110-1301 USA + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS + * IN THE SOFTWARE. */ - -#include "core/private.h" +#include "private-lib-core.h" /* * bitmap of control messages that are valid to receive for each http2 state @@ -118,7 +120,7 @@ } #endif -static struct lws_h2_protocol_send * +struct lws_h2_protocol_send * lws_h2_new_pps(enum lws_h2_protocol_send_type type) { struct lws_h2_protocol_send *pps = lws_malloc(sizeof(*pps), "pps"); @@ -131,7 +133,8 @@ void lws_h2_init(struct lws *wsi) { - wsi->h2.h2n->set = wsi->vhost->h2.set; + wsi->h2.h2n->our_set = wsi->a.vhost->h2.set; + wsi->h2.h2n->peer_set = lws_h2_defaults; } void @@ -147,6 +150,66 @@ wsi->h2.h2_state = (uint8_t)s; } +int +lws_h2_update_peer_txcredit(struct lws *wsi, int sid, int bump) +{ + struct lws *nwsi = lws_get_network_wsi(wsi); + struct lws_h2_protocol_send *pps; + + assert(wsi); + + if (!bump) + return 0; + + if (sid == -1) + sid = wsi->mux.my_sid; + + lwsl_info("%s: sid %d: bump %d -> %d\n", __func__, sid, bump, + (int)wsi->txc.peer_tx_cr_est + bump); + + pps = lws_h2_new_pps(LWS_H2_PPS_UPDATE_WINDOW); + if (!pps) + return 1; + + pps->u.update_window.sid = sid; + pps->u.update_window.credit = bump; + wsi->txc.peer_tx_cr_est += bump; + + lws_wsi_txc_describe(&wsi->txc, __func__, wsi->mux.my_sid); + + lws_pps_schedule(wsi, pps); + + pps = lws_h2_new_pps(LWS_H2_PPS_UPDATE_WINDOW); + if (!pps) + return 1; + + pps->u.update_window.sid = 0; + pps->u.update_window.credit = bump; + nwsi->txc.peer_tx_cr_est += bump; + + lws_wsi_txc_describe(&nwsi->txc, __func__, nwsi->mux.my_sid); + + lws_pps_schedule(nwsi, pps); + + return 0; +} + +int +lws_h2_get_peer_txcredit_estimate(struct lws *wsi) +{ + lws_wsi_txc_describe(&wsi->txc, __func__, wsi->mux.my_sid); + return (int)wsi->txc.peer_tx_cr_est; +} + +static int +lws_h2_update_peer_txcredit_thresh(struct lws *wsi, int sid, int threshold, int bump) +{ + if (wsi->txc.peer_tx_cr_est > threshold) + return 0; + + return lws_h2_update_peer_txcredit(wsi, sid, bump); +} + struct lws * lws_wsi_server_new(struct lws_vhost *vh, struct lws *parent_wsi, unsigned int sid) @@ -164,14 +227,15 @@ * connection error (Section 5.4.1) of type PROTOCOL_ERROR. */ if (sid <= h2n->highest_sid_opened) { - lwsl_info("%s: tried to open lower sid %d\n", __func__, sid); + lwsl_info("%s: tried to open lower sid %d (%d)\n", __func__, + sid, (int)h2n->highest_sid_opened); lws_h2_goaway(nwsi, H2_ERR_PROTOCOL_ERROR, "Bad sid"); return NULL; } /* no more children allowed by parent */ - if (parent_wsi->h2.child_count + 1 > - parent_wsi->h2.h2n->set.s[H2SET_MAX_CONCURRENT_STREAMS]) { + if (parent_wsi->mux.child_count + 1 > + parent_wsi->h2.h2n->our_set.s[H2SET_MAX_CONCURRENT_STREAMS]) { lwsl_notice("reached concurrent stream limit\n"); return NULL; } @@ -182,43 +246,49 @@ } h2n->highest_sid_opened = sid; - wsi->h2.my_sid = sid; - wsi->http2_substream = 1; + + lws_wsi_mux_insert(wsi, parent_wsi, sid); + if (sid >= h2n->highest_sid) + h2n->highest_sid = sid + 2; + + wsi->mux_substream = 1; wsi->seen_nonpseudoheader = 0; - wsi->h2.parent_wsi = parent_wsi; - wsi->role_ops = parent_wsi->role_ops; - /* new guy's sibling is whoever was the first child before */ - wsi->h2.sibling_list = parent_wsi->h2.child_list; - /* first child is now the new guy */ - parent_wsi->h2.child_list = wsi; - parent_wsi->h2.child_count++; - - wsi->h2.my_priority = 16; - wsi->h2.tx_cr = nwsi->h2.h2n->set.s[H2SET_INITIAL_WINDOW_SIZE]; - wsi->h2.peer_tx_cr_est = - nwsi->vhost->h2.set.s[H2SET_INITIAL_WINDOW_SIZE]; + wsi->txc.tx_cr = nwsi->h2.h2n->peer_set.s[H2SET_INITIAL_WINDOW_SIZE]; + wsi->txc.peer_tx_cr_est = + nwsi->h2.h2n->our_set.s[H2SET_INITIAL_WINDOW_SIZE]; lwsi_set_state(wsi, LRS_ESTABLISHED); lwsi_set_role(wsi, lwsi_role(parent_wsi)); - wsi->protocol = &vh->protocols[0]; + wsi->a.protocol = &vh->protocols[0]; if (lws_ensure_user_space(wsi)) goto bail1; - wsi->vhost->conn_stats.h2_subs++; +#if defined(LWS_WITH_SERVER_STATUS) + wsi->a.vhost->conn_stats.h2_subs++; +#endif + +#if defined(LWS_WITH_SERVER) && defined(LWS_WITH_SECURE_STREAMS) + if (lws_adopt_ss_server_accept(wsi)) + goto bail1; +#endif + + /* get the ball rolling */ + lws_validity_confirmed(wsi); - lwsl_info("%s: %p new ch %p, sid %d, usersp=%p, tx cr %d, " - "peer_credit %d (nwsi tx_cr %d)\n", - __func__, parent_wsi, wsi, sid, wsi->user_space, - wsi->h2.tx_cr, wsi->h2.peer_tx_cr_est, nwsi->h2.tx_cr); + lwsl_info("%s: %p new ch %p, sid %d, usersp=%p\n", __func__, + parent_wsi, wsi, sid, wsi->user_space); + + lws_wsi_txc_describe(&wsi->txc, __func__, wsi->mux.my_sid); + lws_wsi_txc_describe(&nwsi->txc, __func__, 0); return wsi; bail1: /* undo the insert */ - parent_wsi->h2.child_list = wsi->h2.sibling_list; - parent_wsi->h2.child_count--; + parent_wsi->mux.child_list = wsi->mux.sibling_list; + parent_wsi->mux.child_count--; vh->context->count_wsi_allocated--; @@ -237,8 +307,8 @@ struct lws *nwsi = lws_get_network_wsi(parent_wsi); /* no more children allowed by parent */ - if (parent_wsi->h2.child_count + 1 > - parent_wsi->h2.h2n->set.s[H2SET_MAX_CONCURRENT_STREAMS]) { + if (parent_wsi->mux.child_count + 1 > + parent_wsi->h2.h2n->our_set.s[H2SET_MAX_CONCURRENT_STREAMS]) { lwsl_notice("reached concurrent stream limit\n"); return NULL; } @@ -246,22 +316,29 @@ /* sid is set just before issuing the headers, ensuring monoticity */ wsi->seen_nonpseudoheader = 0; -#if !defined(LWS_NO_CLIENT) - wsi->client_h2_substream = 1; +#if defined(LWS_WITH_CLIENT) + wsi->client_mux_substream = 1; #endif wsi->h2.initialized = 1; - wsi->h2.parent_wsi = parent_wsi; - /* new guy's sibling is whoever was the first child before */ - wsi->h2.sibling_list = parent_wsi->h2.child_list; - /* first child is now the new guy */ - parent_wsi->h2.child_list = wsi; - parent_wsi->h2.child_count++; - - wsi->h2.my_priority = 16; - wsi->h2.tx_cr = nwsi->h2.h2n->set.s[H2SET_INITIAL_WINDOW_SIZE]; - wsi->h2.peer_tx_cr_est = - nwsi->vhost->h2.set.s[H2SET_INITIAL_WINDOW_SIZE]; +#if 0 + /* only assign sid at header send time when we know it */ + if (!wsi->mux.my_sid) { + wsi->mux.my_sid = nwsi->h2.h2n->highest_sid; + nwsi->h2.h2n->highest_sid += 2; + } +#endif + + lwsl_info("%s: binding wsi %p to sid %d (next %d)\n", __func__, + wsi, (int)wsi->mux.my_sid, (int)nwsi->h2.h2n->highest_sid); + + lws_wsi_mux_insert(wsi, parent_wsi, wsi->mux.my_sid); + + wsi->txc.tx_cr = nwsi->h2.h2n->peer_set.s[H2SET_INITIAL_WINDOW_SIZE]; + wsi->txc.peer_tx_cr_est = + nwsi->h2.h2n->our_set.s[H2SET_INITIAL_WINDOW_SIZE]; + + lws_wsi_txc_describe(&wsi->txc, __func__, wsi->mux.my_sid); if (lws_ensure_user_space(wsi)) goto bail1; @@ -271,18 +348,20 @@ lws_callback_on_writable(wsi); - wsi->vhost->conn_stats.h2_subs++; +#if defined(LWS_WITH_SERVER_STATUS) + wsi->a.vhost->conn_stats.h2_subs++; +#endif return wsi; bail1: /* undo the insert */ - parent_wsi->h2.child_list = wsi->h2.sibling_list; - parent_wsi->h2.child_count--; + parent_wsi->mux.child_list = wsi->mux.sibling_list; + parent_wsi->mux.child_count--; if (wsi->user_space) lws_free_set_NULL(wsi->user_space); - wsi->protocol->callback(wsi, LWS_CALLBACK_WSI_DESTROY, NULL, NULL, 0); + wsi->a.protocol->callback(wsi, LWS_CALLBACK_WSI_DESTROY, NULL, NULL, 0); lws_free(wsi); return NULL; @@ -302,7 +381,7 @@ &role_ops_h2); h2n->count = 0; - wsi->h2.tx_cr = 65535; + wsi->txc.tx_cr = 65535; /* * we must send a settings frame @@ -316,32 +395,6 @@ return 0; } -struct lws * -lws_h2_wsi_from_id(struct lws *parent_wsi, unsigned int sid) -{ - lws_start_foreach_ll(struct lws *, wsi, parent_wsi->h2.child_list) { - if (wsi->h2.my_sid == sid) - return wsi; - } lws_end_foreach_ll(wsi, h2.sibling_list); - - return NULL; -} - -int lws_remove_server_child_wsi(struct lws_context *context, struct lws *wsi) -{ - lws_start_foreach_llp(struct lws **, w, wsi->h2.child_list) { - if (*w == wsi) { - *w = wsi->h2.sibling_list; - (wsi->h2.parent_wsi)->h2.child_count--; - return 0; - } - } lws_end_foreach_llp(w, h2.sibling_list); - - lwsl_err("%s: can't find %p\n", __func__, wsi); - - return 1; -} - void lws_pps_schedule(struct lws *wsi, struct lws_h2_protocol_send *pps) { @@ -368,7 +421,7 @@ if (!pps) return 1; - lwsl_info("%s: %p: ERR 0x%x, '%s'\n", __func__, wsi, err, reason); + lwsl_info("%s: %p: ERR 0x%x, '%s'\n", __func__, wsi, (int)err, reason); pps->u.ga.err = err; pps->u.ga.highest_sid = h2n->highest_sid; @@ -397,10 +450,10 @@ if (!pps) return 1; - lwsl_info("%s: RST_STREAM 0x%x, sid %d, REASON '%s'\n", __func__, err, - wsi->h2.my_sid, reason); + lwsl_info("%s: RST_STREAM 0x%x, sid %d, REASON '%s'\n", __func__, + (int)err, wsi->mux.my_sid, reason); - pps->u.rs.sid = wsi->h2.my_sid; + pps->u.rs.sid = wsi->mux.my_sid; pps->u.rs.err = err; lws_pps_schedule(wsi, pps); @@ -413,7 +466,7 @@ int lws_h2_settings(struct lws *wsi, struct http2_settings *settings, - unsigned char *buf, int len) + unsigned char *buf, int len) { struct lws *nwsi = lws_get_network_wsi(wsi); unsigned int a, b; @@ -449,14 +502,17 @@ return 1; } +#if defined(LWS_WITH_CLIENT) #if defined(LWS_AMAZON_RTOS) || defined(LWS_AMAZON_LINUX) - //FIXME: Workaround for FIRMWARE-4632 until cloud-side issue is fixed. - if (b == 0x7fffffff) { - b = 65535; - lwsl_info("init window size 0x7fffffff\n"); + if ( +#else + if (wsi->flags & LCCSCF_H2_QUIRK_OVERFLOWS_TXCR && +#endif + b == 0x7fffffff) { + b >>= 4; + break; } - //FIXME: end of FIRMWARE-4632 workaround #endif /* @@ -473,21 +529,23 @@ */ lws_start_foreach_ll(struct lws *, w, - nwsi->h2.child_list) { + nwsi->mux.child_list) { lwsl_info("%s: adi child tc cr %d +%d -> %d", - __func__, - w->h2.tx_cr, b - settings->s[a], - w->h2.tx_cr + b - settings->s[a]); - w->h2.tx_cr += b - settings->s[a]; - if (w->h2.tx_cr > 0 && - w->h2.tx_cr <= + __func__, (int)w->txc.tx_cr, + b - (unsigned int)settings->s[a], + (int)w->txc.tx_cr + b - + (unsigned int)settings->s[a]); + w->txc.tx_cr += b - settings->s[a]; + if (w->txc.tx_cr > 0 && + w->txc.tx_cr <= (int32_t)(b - settings->s[a])) + lws_callback_on_writable(w); - } lws_end_foreach_ll(w, h2.sibling_list); + } lws_end_foreach_ll(w, mux.sibling_list); break; case H2SET_MAX_FRAME_SIZE: - if (b < wsi->vhost->h2.set.s[H2SET_MAX_FRAME_SIZE]) { + if (b < wsi->a.vhost->h2.set.s[H2SET_MAX_FRAME_SIZE]) { lws_h2_goaway(nwsi, H2_ERR_PROTOCOL_ERROR, "Frame size < initial"); return 1; @@ -537,19 +595,17 @@ int lws_h2_tx_cr_get(struct lws *wsi) { - int c = wsi->h2.tx_cr; - struct lws *nwsi; + int c = wsi->txc.tx_cr; + struct lws *nwsi = lws_get_network_wsi(wsi); - if (!wsi->http2_substream && !wsi->upgraded_to_http2) + if (!wsi->mux_substream && !nwsi->upgraded_to_http2) return ~0x80000000; - nwsi = lws_get_network_wsi(wsi); - lwsl_info ("%s: %p: own tx credit %d: nwsi credit %d\n", - __func__, wsi, c, nwsi->h2.tx_cr); + __func__, wsi, c, (int)nwsi->txc.tx_cr); - if (nwsi->h2.tx_cr < c) - c = nwsi->h2.tx_cr; + if (nwsi->txc.tx_cr < c) + c = nwsi->txc.tx_cr; if (c < 0) return 0; @@ -562,10 +618,10 @@ { struct lws *nwsi = lws_get_network_wsi(wsi); - wsi->h2.tx_cr -= consumed; + wsi->txc.tx_cr -= consumed; if (nwsi != wsi) - nwsi->h2.tx_cr -= consumed; + nwsi->txc.tx_cr -= consumed; } int lws_h2_frame_write(struct lws *wsi, int type, int flags, @@ -590,13 +646,13 @@ lwsl_debug("%s: %p (eff %p). typ %d, fl 0x%x, sid=%d, len=%d, " "txcr=%d, nwsi->txcr=%d\n", __func__, wsi, nwsi, type, flags, - sid, len, wsi->h2.tx_cr, nwsi->h2.tx_cr); + sid, len, (int)wsi->txc.tx_cr, (int)nwsi->txc.tx_cr); if (type == LWS_H2_FRAME_TYPE_DATA) { - if (wsi->h2.tx_cr < (int)len) - lwsl_err("%s: %p: sending payload len %d" + if (wsi->txc.tx_cr < (int)len) + lwsl_info("%s: %p: sending payload len %d" " but tx_cr only %d!\n", __func__, wsi, - len, wsi->h2.tx_cr); + len, (int)wsi->txc.tx_cr); lws_h2_tx_cr_consume(wsi, len); } @@ -615,10 +671,10 @@ { *buf++ = n >> 8; *buf++ = n; - *buf++ = wsi->h2.h2n->set.s[n] >> 24; - *buf++ = wsi->h2.h2n->set.s[n] >> 16; - *buf++ = wsi->h2.h2n->set.s[n] >> 8; - *buf = wsi->h2.h2n->set.s[n]; + *buf++ = wsi->h2.h2n->our_set.s[n] >> 24; + *buf++ = wsi->h2.h2n->our_set.s[n] >> 16; + *buf++ = wsi->h2.h2n->our_set.s[n] >> 8; + *buf = wsi->h2.h2n->our_set.s[n]; } /* we get called on the network connection */ @@ -658,9 +714,11 @@ * then we must inform the peer */ for (n = 1; n < H2SET_COUNT; n++) - if (h2n->set.s[n] != lws_h2_defaults.s[n]) { + if (h2n->our_set.s[n] != lws_h2_defaults.s[n]) { lwsl_debug("sending SETTING %d 0x%x\n", n, - wsi->h2.h2n->set.s[n]); + (unsigned int) + wsi->h2.h2n->our_set.s[n]); + lws_h2_set_bin(wsi, n, &set[LWS_PRE + m]); m += sizeof(h2n->one_setting); } @@ -673,6 +731,27 @@ } break; + case LWS_H2_PPS_SETTINGS_INITIAL_UPDATE_WINDOW: + q = &set[LWS_PRE]; + *q++ = H2SET_INITIAL_WINDOW_SIZE >> 8; + *q++ = H2SET_INITIAL_WINDOW_SIZE; + *q++ = pps->u.update_window.credit >> 24; + *q++ = pps->u.update_window.credit >> 16; + *q++ = pps->u.update_window.credit >> 8; + *q = pps->u.update_window.credit; + + lwsl_debug("%s: resetting initial window to %d\n", __func__, + (int)pps->u.update_window.credit); + + n = lws_h2_frame_write(wsi, LWS_H2_FRAME_TYPE_SETTINGS, + flags, LWS_H2_STREAM_ID_MASTER, 6, + &set[LWS_PRE]); + if (n != 6) { + lwsl_info("send %d %d\n", n, m); + goto bail; + } + break; + case LWS_H2_PPS_ACK_SETTINGS: /* send ack ... always empty */ n = lws_h2_frame_write(wsi, LWS_H2_FRAME_TYPE_SETTINGS, 1, @@ -682,17 +761,25 @@ lwsl_err("ack tells %d\n", n); goto bail; } + wsi->h2_acked_settings = 0; /* this is the end of the preface dance then? */ if (lwsi_state(wsi) == LRS_H2_AWAIT_SETTINGS) { lwsi_set_state(wsi, LRS_ESTABLISHED); +#if defined(LWS_WITH_FILE_OPS) wsi->http.fop_fd = NULL; +#endif if (lws_is_ssl(lws_get_network_wsi(wsi))) break; + + if (wsi->a.vhost->options & + LWS_SERVER_OPTION_H2_PRIOR_KNOWLEDGE) + break; + /* * we need to treat the headers from the upgrade as the * first job. So these need to get shifted to sid 1. */ - h2n->swsi = lws_wsi_server_new(wsi->vhost, wsi, 1); + h2n->swsi = lws_wsi_server_new(wsi->a.vhost, wsi, 1); if (!h2n->swsi) goto bail; @@ -702,34 +789,46 @@ lwsl_info("%s: inherited headers %p\n", __func__, h2n->swsi->http.ah); - h2n->swsi->h2.tx_cr = - h2n->set.s[H2SET_INITIAL_WINDOW_SIZE]; + h2n->swsi->txc.tx_cr = + h2n->our_set.s[H2SET_INITIAL_WINDOW_SIZE]; lwsl_info("initial tx credit on conn %p: %d\n", - h2n->swsi, h2n->swsi->h2.tx_cr); + h2n->swsi, (int)h2n->swsi->txc.tx_cr); h2n->swsi->h2.initialized = 1; /* demanded by HTTP2 */ h2n->swsi->h2.END_STREAM = 1; lwsl_info("servicing initial http request\n"); - wsi->vhost->conn_stats.h2_trans++; - +#if defined(LWS_WITH_SERVER_STATUS) + wsi->a.vhost->conn_stats.h2_trans++; +#endif +#if defined(LWS_WITH_SERVER) if (lws_http_action(h2n->swsi)) goto bail; - +#endif break; } break; + + /* + * h2 only has PING... ACK = 0 = ping, ACK = 1 = pong + */ + + case LWS_H2_PPS_PING: case LWS_H2_PPS_PONG: - lwsl_debug("sending PONG\n"); + if (pps->type == LWS_H2_PPS_PING) + lwsl_info("sending PING\n"); + else { + lwsl_info("sending PONG\n"); + flags = LWS_H2_FLAG_SETTINGS_ACK; + } + memcpy(&set[LWS_PRE], pps->u.ping.ping_payload, 8); - n = lws_h2_frame_write(wsi, LWS_H2_FRAME_TYPE_PING, - LWS_H2_FLAG_SETTINGS_ACK, + n = lws_h2_frame_write(wsi, LWS_H2_FRAME_TYPE_PING, flags, LWS_H2_STREAM_ID_MASTER, 8, &set[LWS_PRE]); - if (n != 8) { - lwsl_info("send %d %d\n", n, m); + if (n != 8) goto bail; - } + break; case LWS_H2_PPS_GOAWAY: @@ -769,20 +868,20 @@ lwsl_info("send %d %d\n", n, m); goto bail; } - cwsi = lws_h2_wsi_from_id(wsi, pps->u.rs.sid); + cwsi = lws_wsi_mux_from_id(wsi, pps->u.rs.sid); if (cwsi) { lwsl_debug("%s: closing cwsi %p %s %s (wsi %p)\n", __func__, cwsi, cwsi->role_ops->name, - cwsi->protocol->name, wsi); + cwsi->a.protocol->name, wsi); lws_close_free_wsi(cwsi, 0, "reset stream"); } break; case LWS_H2_PPS_UPDATE_WINDOW: - lwsl_debug("Issuing LWS_H2_PPS_UPDATE_WINDOW: sid %d: add %d\n", - pps->u.update_window.sid, - pps->u.update_window.credit); - *p++ = pps->u.update_window.credit >> 24; + lwsl_info("Issuing LWS_H2_PPS_UPDATE_WINDOW: sid %d: add %d\n", + (int)pps->u.update_window.sid, + (int)pps->u.update_window.credit); + *p++ = (pps->u.update_window.credit >> 24) & 0x7f; /* 31b */ *p++ = pps->u.update_window.credit >> 16; *p++ = pps->u.update_window.credit >> 8; *p++ = pps->u.update_window.credit; @@ -809,6 +908,9 @@ return 1; } +static int +lws_h2_parse_end_of_frame(struct lws *wsi); + /* * The frame header part has just completely arrived. * Perform actions for header completion. @@ -837,31 +939,38 @@ /* let the network wsi live a bit longer if subs are active */ if (!wsi->immortal_substream_count) -#if defined(LWS_AMAZON_RTOS) || defined(LWS_AMAZON_LINUX) - lws_set_timeout(wsi, PENDING_TIMEOUT_HTTP_KEEPALIVE_IDLE, wsi->vhost->keepalive_timeout); -#else - lws_set_timeout(wsi, PENDING_TIMEOUT_HTTP_KEEPALIVE_IDLE, 31); -#endif + lws_set_timeout(wsi, PENDING_TIMEOUT_HTTP_KEEPALIVE_IDLE, + wsi->a.vhost->keepalive_timeout ? + wsi->a.vhost->keepalive_timeout : 31); if (h2n->sid) - h2n->swsi = lws_h2_wsi_from_id(wsi, h2n->sid); + h2n->swsi = lws_wsi_mux_from_id(wsi, h2n->sid); lwsl_debug("%p (%p): fr hdr: typ 0x%x, fla 0x%x, sid 0x%x, len 0x%x\n", - wsi, h2n->swsi, h2n->type, h2n->flags, h2n->sid, - h2n->length); + wsi, h2n->swsi, h2n->type, h2n->flags, (unsigned int)h2n->sid, + (unsigned int)h2n->length); if (h2n->we_told_goaway && h2n->sid > h2n->highest_sid) h2n->type = LWS_H2_FRAME_TYPE_COUNT; /* ie, IGNORE */ - if (h2n->type == LWS_H2_FRAME_TYPE_COUNT) - return 0; + if (h2n->type >= LWS_H2_FRAME_TYPE_COUNT) { + lwsl_info("%s: ignoring unknown frame type %d (len %d)\n", __func__, h2n->type, (unsigned int)h2n->length); + /* we MUST ignore frames we don't understand */ + h2n->type = LWS_H2_FRAME_TYPE_COUNT; + } + + /* + * Even if we have decided to logically ignore this frame, we must + * consume the correct "frame length" amount of data to retain sync + */ - if (h2n->length > h2n->set.s[H2SET_MAX_FRAME_SIZE]) { + if (h2n->length > h2n->our_set.s[H2SET_MAX_FRAME_SIZE]) { /* * peer sent us something bigger than we told * it we would allow */ - lwsl_info("received oversize frame %d\n", h2n->length); + lwsl_info("%s: received oversize frame %d\n", __func__, + (unsigned int)h2n->length); lws_h2_goaway(wsi, H2_ERR_FRAME_SIZE_ERROR, "Peer ignored our frame size setting"); return 1; @@ -875,11 +984,12 @@ /* if it's data, either way no swsi means CLOSED state */ if (h2n->type == LWS_H2_FRAME_TYPE_DATA) { if (h2n->sid <= h2n->highest_sid_opened -#if !defined(LWS_NO_CLIENT) +#if defined(LWS_WITH_CLIENT) && wsi->client_h2_alpn #endif ) { - lwsl_notice("ignoring straggling data\n"); + lwsl_notice("ignoring straggling data fl 0x%x\n", + h2n->flags); /* ie, IGNORE */ h2n->type = LWS_H2_FRAME_TYPE_COUNT; } else { @@ -894,14 +1004,14 @@ h2n->type != LWS_H2_FRAME_TYPE_PRIORITY) { /* if not credible, reject it */ lwsl_info("%s: wsi %p, No child for sid %d, rxcmd %d\n", - __func__, h2n->swsi, h2n->sid, h2n->type); + __func__, h2n->swsi, (unsigned int)h2n->sid, h2n->type); lws_h2_goaway(wsi, H2_ERR_STREAM_CLOSED, "Data for nonexistent sid"); return 0; } } - if (h2n->swsi && h2n->sid && + if (h2n->swsi && h2n->sid && h2n->type != LWS_H2_FRAME_TYPE_COUNT && !(http2_rx_validity[h2n->swsi->h2.h2_state] & (1 << h2n->type))) { lwsl_info("%s: wsi %p, State: %s, ILLEGAL cmdrx %d (OK 0x%x)\n", __func__, h2n->swsi, @@ -918,10 +1028,12 @@ return 0; } - if (h2n->cont_exp && (h2n->cont_exp_sid != h2n->sid || + if (h2n->cont_exp && h2n->type != LWS_H2_FRAME_TYPE_COUNT && + (h2n->cont_exp_sid != h2n->sid || h2n->type != LWS_H2_FRAME_TYPE_CONTINUATION)) { - lwsl_info("%s: expected cont on sid %d (got %d on sid %d)\n", - __func__, h2n->cont_exp_sid, h2n->type, h2n->sid); + lwsl_info("%s: expected cont on sid %u (got %d on sid %u)\n", + __func__, (unsigned int)h2n->cont_exp_sid, h2n->type, + (unsigned int)h2n->sid); h2n->cont_exp = 0; if (h2n->cont_exp_headers) n = H2_ERR_COMPRESSION_ERROR; @@ -940,7 +1052,9 @@ lws_h2_goaway(wsi, H2_ERR_PROTOCOL_ERROR, "DATA 0 sid"); break; } - lwsl_info("Frame header DATA: sid %d\n", h2n->sid); + lwsl_info("Frame header DATA: sid %u, flags 0x%x, len %u\n", + (unsigned int)h2n->sid, h2n->flags, + (unsigned int)h2n->length); if (!h2n->swsi) { lwsl_notice("DATA: NULL swsi\n"); @@ -955,7 +1069,12 @@ lws_h2_goaway(wsi, H2_ERR_STREAM_CLOSED, "conn closed"); break; } + + if (h2n->length == 0) + lws_h2_parse_end_of_frame(wsi); + break; + case LWS_H2_FRAME_TYPE_PRIORITY: lwsl_info("LWS_H2_FRAME_TYPE_PRIORITY complete frame\n"); if (!h2n->sid) { @@ -1006,7 +1125,7 @@ } if (!(h2n->flags & LWS_H2_FLAG_SETTINGS_ACK)) { - if ((!h2n->length) || h2n->length % 6) { + if (h2n->length % 6) { lws_h2_goaway(wsi, H2_ERR_FRAME_SIZE_ERROR, "Settings length error"); break; @@ -1015,11 +1134,19 @@ if (h2n->type == LWS_H2_FRAME_TYPE_COUNT) return 0; - if (wsi->upgraded_to_http2) { + if (wsi->upgraded_to_http2 && +#if defined(LWS_WITH_CLIENT) + (!(wsi->flags & LCCSCF_H2_QUIRK_NGHTTP2_END_STREAM) || +#else + ( +#endif + !wsi->h2_acked_settings)) { + pps = lws_h2_new_pps(LWS_H2_PPS_ACK_SETTINGS); if (!pps) return 1; lws_pps_schedule(wsi, pps); + wsi->h2_acked_settings = 1; } break; } @@ -1044,8 +1171,9 @@ } break; case LWS_H2_FRAME_TYPE_CONTINUATION: - lwsl_info("LWS_H2_FRAME_TYPE_CONTINUATION: sid = %d\n", - h2n->sid); + lwsl_info("LWS_H2_FRAME_TYPE_CONTINUATION: sid = %u %d %d\n", + (unsigned int)h2n->sid, (int)h2n->cont_exp, + (int)h2n->cont_exp_sid); if (!h2n->cont_exp || h2n->cont_exp_sid != h2n->sid || @@ -1055,6 +1183,7 @@ "unexpected CONTINUATION"); break; } + if (h2n->swsi->h2.END_HEADERS) { lws_h2_goaway(wsi, H2_ERR_PROTOCOL_ERROR, "END_HEADERS already seen"); @@ -1064,7 +1193,8 @@ goto update_end_headers; case LWS_H2_FRAME_TYPE_HEADERS: - lwsl_info("HEADERS: frame header: sid = %d\n", h2n->sid); + lwsl_info("HEADERS: frame header: sid = %u\n", + (unsigned int)h2n->sid); if (!h2n->sid) { lws_h2_goaway(wsi, H2_ERR_PROTOCOL_ERROR, "sid 0"); return 1; @@ -1078,13 +1208,13 @@ return 1; } -#if !defined(LWS_NO_CLIENT) +#if defined(LWS_WITH_CLIENT) if (wsi->client_h2_alpn) { if (h2n->sid) { - h2n->swsi = lws_h2_wsi_from_id(wsi, h2n->sid); - lwsl_info("HEADERS: nwsi %p: sid %d mapped " - "to wsi %p\n", wsi, h2n->sid, - h2n->swsi); + h2n->swsi = lws_wsi_mux_from_id(wsi, h2n->sid); + lwsl_info("HEADERS: nwsi %p: sid %u mapped " + "to wsi %p\n", wsi, + (unsigned int)h2n->sid, h2n->swsi); if (!h2n->swsi) break; } @@ -1094,15 +1224,20 @@ if (!h2n->swsi) { /* no more children allowed by parent */ - if (wsi->h2.child_count + 1 > - wsi->h2.h2n->set.s[H2SET_MAX_CONCURRENT_STREAMS]) { + if (wsi->mux.child_count + 1 > + wsi->h2.h2n->our_set.s[H2SET_MAX_CONCURRENT_STREAMS]) { lws_h2_goaway(wsi, H2_ERR_PROTOCOL_ERROR, "Another stream not allowed"); return 1; } - h2n->swsi = lws_wsi_server_new(wsi->vhost, wsi, + /* + * The peer has sent us a HEADERS implying the creation + * of a new stream + */ + + h2n->swsi = lws_wsi_server_new(wsi->a.vhost, wsi, h2n->sid); if (!h2n->swsi) { lws_h2_goaway(wsi, H2_ERR_PROTOCOL_ERROR, @@ -1111,22 +1246,14 @@ return 1; } - pps = lws_h2_new_pps(LWS_H2_PPS_UPDATE_WINDOW); - if (!pps) - goto cleanup_wsi; - pps->u.update_window.sid = h2n->sid; - pps->u.update_window.credit = 4 * 65536; - h2n->swsi->h2.peer_tx_cr_est += - pps->u.update_window.credit; - lws_pps_schedule(wsi, pps); + if (h2n->sid >= h2n->highest_sid) + h2n->highest_sid = h2n->sid + 2; - pps = lws_h2_new_pps(LWS_H2_PPS_UPDATE_WINDOW); - if (!pps) + h2n->swsi->h2.initialized = 1; + + if (lws_h2_update_peer_txcredit(h2n->swsi, + h2n->swsi->mux.my_sid, 4 * 65536)) goto cleanup_wsi; - pps->u.update_window.sid = 0; - pps->u.update_window.credit = 4 * 65536; - wsi->h2.peer_tx_cr_est += pps->u.update_window.credit; - lws_pps_schedule(wsi, pps); } /* @@ -1149,19 +1276,31 @@ * transitions to the "closed" state when the first frame for * stream 7 is sent or received. */ - lws_start_foreach_ll(struct lws *, w, wsi->h2.child_list) { - if (w->h2.my_sid < h2n->sid && + lws_start_foreach_ll(struct lws *, w, wsi->mux.child_list) { + if (w->mux.my_sid < h2n->sid && w->h2.h2_state == LWS_H2_STATE_IDLE) lws_close_free_wsi(w, 0, "h2 sid close"); - assert(w->h2.sibling_list != w); - } lws_end_foreach_ll(w, h2.sibling_list); + assert(w->mux.sibling_list != w); + } lws_end_foreach_ll(w, mux.sibling_list); + + if (lws_check_opt(h2n->swsi->a.vhost->options, + LWS_SERVER_OPTION_VH_H2_HALF_CLOSED_LONG_POLL)) { + /* + * We don't directly timeout streams that enter the + * half-closed remote state, allowing immortal long + * poll + */ + lws_mux_mark_immortal(h2n->swsi); + lwsl_info("%s: %p: h2 stream entering long poll\n", + __func__, h2n->swsi); - /* END_STREAM means after servicing this, close the stream */ - h2n->swsi->h2.END_STREAM = + } else { + h2n->swsi->h2.END_STREAM = !!(h2n->flags & LWS_H2_FLAG_END_STREAM); - lwsl_info("%s: hdr END_STREAM = %d\n",__func__, + lwsl_debug("%s: hdr END_STREAM = %d\n",__func__, h2n->swsi->h2.END_STREAM); + } h2n->cont_exp = !(h2n->flags & LWS_H2_FLAG_END_HEADERS); h2n->cont_exp_sid = h2n->sid; @@ -1192,6 +1331,10 @@ lwsl_info("LWS_H2_FRAME_TYPE_WINDOW_UPDATE\n"); break; case LWS_H2_FRAME_TYPE_COUNT: + if (h2n->length == 0) + lws_h2_parse_end_of_frame(wsi); + else + lwsl_debug("%s: going on to deal with unknown frame remaining len %d\n", __func__, (unsigned int)h2n->length); break; default: lwsl_info("%s: ILLEGAL FRAME TYPE %d\n", __func__, h2n->type); @@ -1205,15 +1348,21 @@ } static const char * const method_names[] = { - "GET", "POST", "OPTIONS", "PUT", "PATCH", "DELETE", "CONNECT", "HEAD" + "GET", "POST", +#if defined(LWS_WITH_HTTP_UNCOMMON_HEADERS) + "OPTIONS", "PUT", "PATCH", "DELETE", +#endif + "CONNECT", "HEAD" }; static unsigned char method_index[] = { WSI_TOKEN_GET_URI, WSI_TOKEN_POST_URI, +#if defined(LWS_WITH_HTTP_UNCOMMON_HEADERS) WSI_TOKEN_OPTIONS_URI, WSI_TOKEN_PUT_URI, WSI_TOKEN_PATCH_URI, WSI_TOKEN_DELETE_URI, +#endif WSI_TOKEN_CONNECT, WSI_TOKEN_HEAD_URI, }; @@ -1241,19 +1390,11 @@ h2n->count = 0; if (h2n->sid) - h2n->swsi = lws_h2_wsi_from_id(wsi, h2n->sid); + h2n->swsi = lws_wsi_mux_from_id(wsi, h2n->sid); if (h2n->sid > h2n->highest_sid) h2n->highest_sid = h2n->sid; - /* set our initial window size */ - if (!wsi->h2.initialized) { - wsi->h2.tx_cr = h2n->set.s[H2SET_INITIAL_WINDOW_SIZE]; - lwsl_info("initial tx credit on master %p: %d\n", wsi, - wsi->h2.tx_cr); - wsi->h2.initialized = 1; - } - if (h2n->collected_priority && (h2n->dep & ~(1u << 31)) == h2n->sid) { lws_h2_goaway(wsi, H2_ERR_PROTOCOL_ERROR, "depends on own sid"); return 0; @@ -1263,25 +1404,27 @@ case LWS_H2_FRAME_TYPE_SETTINGS: -#if !defined(LWS_NO_CLIENT) - if (wsi->client_h2_alpn && +#if defined(LWS_WITH_CLIENT) + if (wsi->client_h2_alpn && !wsi->client_mux_migrated && !(h2n->flags & LWS_H2_FLAG_SETTINGS_ACK)) { struct lws_h2_protocol_send *pps; /* migrate original client ask on to substream 1 */ - +#if defined(LWS_WITH_FILE_OPS) wsi->http.fop_fd = NULL; - +#endif + lwsl_info("%s: migrating\n", __func__); + wsi->client_mux_migrated = 1; /* * we need to treat the headers from the upgrade as the * first job. So these need to get shifted to sid 1. */ - h2n->swsi = lws_wsi_server_new(wsi->vhost, wsi, 1); + h2n->swsi = lws_wsi_server_new(wsi->a.vhost, wsi, 1); if (!h2n->swsi) return 1; h2n->sid = 1; - assert(lws_h2_wsi_from_id(wsi, 1) == h2n->swsi); + assert(lws_wsi_mux_from_id(wsi, 1) == h2n->swsi); lws_role_transition(wsi, LWSIFR_CLIENT, LRS_H2_WAITING_TO_SEND_HEADERS, @@ -1293,16 +1436,23 @@ /* pass on the initial headers to SID 1 */ h2n->swsi->http.ah = wsi->http.ah; - h2n->swsi->client_h2_substream = 1; + h2n->swsi->client_mux_substream = 1; + h2n->swsi->client_h2_alpn = 1; +#if defined(LWS_WITH_CLIENT) + h2n->swsi->flags = wsi->flags; +#endif - h2n->swsi->protocol = wsi->protocol; - if (h2n->swsi->user_space && !h2n->swsi->user_space_externally_allocated) + h2n->swsi->a.protocol = wsi->a.protocol; + if (h2n->swsi->user_space && + !h2n->swsi->user_space_externally_allocated) lws_free(h2n->swsi->user_space); h2n->swsi->user_space = wsi->user_space; h2n->swsi->user_space_externally_allocated = wsi->user_space_externally_allocated; - h2n->swsi->opaque_user_data = wsi->opaque_user_data; - wsi->opaque_user_data = NULL; + h2n->swsi->a.opaque_user_data = wsi->a.opaque_user_data; + wsi->a.opaque_user_data = NULL; + h2n->swsi->txc.manual_initial_tx_credit = + wsi->txc.manual_initial_tx_credit; wsi->user_space = NULL; @@ -1312,40 +1462,39 @@ lwsl_info("%s: MIGRATING nwsi %p: swsi %p\n", __func__, wsi, h2n->swsi); - h2n->swsi->h2.tx_cr = - h2n->set.s[H2SET_INITIAL_WINDOW_SIZE]; - lwsl_info("initial tx credit on conn %p: %d\n", - h2n->swsi, h2n->swsi->h2.tx_cr); + h2n->swsi->txc.tx_cr = + h2n->peer_set.s[H2SET_INITIAL_WINDOW_SIZE]; + lwsl_info("%s: initial tx credit on conn %p: %d\n", + __func__, h2n->swsi, (int)h2n->swsi->txc.tx_cr); h2n->swsi->h2.initialized = 1; + /* set our initial window size */ + if (!wsi->h2.initialized) { + wsi->txc.tx_cr = + h2n->peer_set.s[H2SET_INITIAL_WINDOW_SIZE]; + + lwsl_info("%s: initial tx credit for us to " + "write on master %p: %d\n", __func__, + wsi, (int)wsi->txc.tx_cr); + wsi->h2.initialized = 1; + } + lws_callback_on_writable(h2n->swsi); - pps = lws_h2_new_pps(LWS_H2_PPS_ACK_SETTINGS); - if (!pps) - return 1; - lws_pps_schedule(wsi, pps); - lwsl_info("%s: scheduled settings ack PPS\n", __func__); + if (!wsi->h2_acked_settings || + !(wsi->flags & LCCSCF_H2_QUIRK_NGHTTP2_END_STREAM) + ) { + pps = lws_h2_new_pps(LWS_H2_PPS_ACK_SETTINGS); + if (!pps) + return 1; + lws_pps_schedule(wsi, pps); + lwsl_info("%s: SETTINGS ack PPS\n", __func__); + wsi->h2_acked_settings = 1; + } /* also attach any queued guys */ - /* we have a transaction queue that wants to pipeline */ - lws_vhost_lock(wsi->vhost); - lws_start_foreach_dll_safe(struct lws_dll2 *, d, d1, - wsi->dll2_cli_txn_queue_owner.head) { - struct lws *w = lws_container_of(d, struct lws, - dll2_cli_txn_queue); - - if (lwsi_state(w) == LRS_H1C_ISSUE_HANDSHAKE2) { - lwsl_info("%s: cli pipeq %p to be h2\n", - __func__, w); - /* remove ourselves from client queue */ - lws_dll2_remove(&w->dll2_cli_txn_queue); - - /* attach ourselves as an h2 stream */ - lws_wsi_h2_adopt(wsi, w); - } - } lws_end_foreach_dll_safe(d, d1); - lws_vhost_unlock(wsi->vhost); + lws_wsi_mux_apply_queue(wsi); } #endif break; @@ -1367,6 +1516,8 @@ if (!h2n->swsi->h2.END_HEADERS) { /* we are not finished yet */ lwsl_info("witholding http action for continuation\n"); + h2n->cont_exp_sid = h2n->sid; + h2n->cont_exp = 1; break; } @@ -1374,8 +1525,9 @@ if (h2n->hpack != HPKS_TYPE) { /* hpack incomplete */ - lwsl_info("hpack incomplete %d (type %d, len %d)\n", - h2n->hpack, h2n->type, h2n->hpack_len); + lwsl_info("hpack incomplete %d (type %d, len %u)\n", + h2n->hpack, h2n->type, + (unsigned int)h2n->hpack_len); lws_h2_goaway(wsi, H2_ERR_COMPRESSION_ERROR, "hpack incomplete"); break; @@ -1394,21 +1546,21 @@ lwsl_info("http req, wsi=%p, h2n->swsi=%p\n", wsi, h2n->swsi); h2n->swsi->hdr_parsing_completed = 1; -#if !defined(LWS_NO_CLIENT) - if (h2n->swsi->client_h2_substream) { - if (lws_client_interpret_server_handshake(h2n->swsi)) { - lws_h2_rst_stream(h2n->swsi, - H2_ERR_STREAM_CLOSED, - "protocol CLI_EST closed it"); - break; - } +#if defined(LWS_WITH_CLIENT) + if (h2n->swsi->client_mux_substream && + lws_client_interpret_server_handshake(h2n->swsi)) { + lwsl_info("%s: cli int serv hs closed it\n", __func__); + break; } #endif if (lws_hdr_extant(h2n->swsi, WSI_TOKEN_HTTP_CONTENT_LENGTH)) { - h2n->swsi->http.rx_content_length = atoll( - lws_hdr_simple_ptr(h2n->swsi, - WSI_TOKEN_HTTP_CONTENT_LENGTH)); + const char *simp = lws_hdr_simple_ptr(h2n->swsi, + WSI_TOKEN_HTTP_CONTENT_LENGTH); + + if (!simp) /* coverity */ + return 1; + h2n->swsi->http.rx_content_length = atoll(simp); h2n->swsi->http.rx_content_remain = h2n->swsi->http.rx_content_length; lwsl_info("setting rx_content_length %lld\n", @@ -1455,6 +1607,9 @@ } switch (h2n->swsi->h2.h2_state) { + case LWS_H2_STATE_IDLE: + lws_h2_state(h2n->swsi, LWS_H2_STATE_OPEN); + break; case LWS_H2_STATE_OPEN: if (h2n->swsi->h2.END_STREAM) lws_h2_state(h2n->swsi, @@ -1466,9 +1621,10 @@ break; } -#if !defined(LWS_NO_CLIENT) - if (h2n->swsi->client_h2_substream) { - lwsl_info("%s: headers: client path\n", __func__); +#if defined(LWS_WITH_CLIENT) + if (h2n->swsi->client_mux_substream) { + lwsl_info("%s: wsi %p: headers: client path (h2 state %s)\n", + __func__, wsi, h2_state_names[h2n->swsi->h2.h2_state]); break; } #endif @@ -1483,11 +1639,11 @@ break; } - if (lws_hdr_extant(h2n->swsi, WSI_TOKEN_TE)) { n = lws_hdr_total_length(h2n->swsi, WSI_TOKEN_TE); if (n != 8 || + !lws_hdr_simple_ptr(h2n->swsi, WSI_TOKEN_TE) || strncmp(lws_hdr_simple_ptr(h2n->swsi, WSI_TOKEN_TE), "trailers", n)) { lws_h2_goaway(wsi, H2_ERR_PROTOCOL_ERROR, @@ -1500,14 +1656,16 @@ lws_http_compression_validate(h2n->swsi); #endif - wsi->vhost->conn_stats.h2_trans++; +#if defined(LWS_WITH_SERVER_STATUS) + wsi->a.vhost->conn_stats.h2_trans++; +#endif p = lws_hdr_simple_ptr(h2n->swsi, WSI_TOKEN_HTTP_COLON_METHOD); /* * duplicate :path into the individual method uri header * index, so that it looks the same as h1 in the ah */ for (n = 0; n < (int)LWS_ARRAY_SIZE(method_names); n++) - if (!strcasecmp(p, method_names[n])) { + if (p && !strcasecmp(p, method_names[n])) { h2n->swsi->http.ah->frag_index[method_index[n]] = h2n->swsi->http.ah->frag_index[ WSI_TOKEN_HTTP_COLON_PATH]; @@ -1515,12 +1673,13 @@ } lwsl_debug("%s: setting DEF_ACT from 0x%x\n", __func__, - h2n->swsi->wsistate); + (unsigned int)h2n->swsi->wsistate); lwsi_set_state(h2n->swsi, LRS_DEFERRING_ACTION); lws_callback_on_writable(h2n->swsi); break; case LWS_H2_FRAME_TYPE_DATA: + lwsl_info("%s: DATA flags 0x%x\n", __func__, h2n->flags); if (!h2n->swsi) break; @@ -1543,14 +1702,14 @@ h2n->swsi->h2.h2_state == LWS_H2_STATE_HALF_CLOSED_LOCAL) lws_h2_state(h2n->swsi, LWS_H2_STATE_CLOSED); -#if !defined(LWS_NO_CLIENT) +#if defined(LWS_WITH_CLIENT) /* * client... remote END_STREAM implies we weren't going to * send anything else anyway. */ - if (h2n->swsi->client_h2_substream && - h2n->flags & LWS_H2_FLAG_END_STREAM) { + if (h2n->swsi->client_mux_substream && + (h2n->flags & LWS_H2_FLAG_END_STREAM)) { lwsl_info("%s: %p: DATA: end stream\n", __func__, h2n->swsi); @@ -1579,8 +1738,10 @@ break; case LWS_H2_FRAME_TYPE_PING: - if (h2n->flags & LWS_H2_FLAG_SETTINGS_ACK) { // ack - } else {/* they're sending us a ping request */ + if (h2n->flags & LWS_H2_FLAG_SETTINGS_ACK) + lws_validity_confirmed(wsi); + else { + /* they're sending us a ping request */ struct lws_h2_protocol_send *pps = lws_h2_new_pps(LWS_H2_PPS_PONG); if (!pps) @@ -1595,9 +1756,14 @@ break; case LWS_H2_FRAME_TYPE_WINDOW_UPDATE: + /* + * We only have an unsigned 31-bit (positive) increment possible + */ h2n->hpack_e_dep &= ~(1u << 31); - lwsl_info("WINDOW_UPDATE: sid %d %u (0x%x)\n", h2n->sid, - h2n->hpack_e_dep, h2n->hpack_e_dep); + lwsl_info("WINDOW_UPDATE: sid %u %u (0x%x)\n", + (unsigned int)h2n->sid, + (unsigned int)h2n->hpack_e_dep, + (unsigned int)h2n->hpack_e_dep); if (h2n->sid) eff_wsi = h2n->swsi; @@ -1609,13 +1775,13 @@ break; /* ignore */ } - if (eff_wsi->vhost->options & + if (eff_wsi->a.vhost->options & LWS_SERVER_OPTION_H2_JUST_FIX_WINDOW_UPDATE_OVERFLOW && - (uint64_t)eff_wsi->h2.tx_cr + (uint64_t)h2n->hpack_e_dep > + (uint64_t)eff_wsi->txc.tx_cr + (uint64_t)h2n->hpack_e_dep > (uint64_t)0x7fffffff) - h2n->hpack_e_dep = 0x7fffffff - eff_wsi->h2.tx_cr; + h2n->hpack_e_dep = 0x7fffffff - eff_wsi->txc.tx_cr; - if ((uint64_t)eff_wsi->h2.tx_cr + (uint64_t)h2n->hpack_e_dep > + if ((uint64_t)eff_wsi->txc.tx_cr + (uint64_t)h2n->hpack_e_dep > (uint64_t)0x7fffffff) { if (h2n->sid) lws_h2_rst_stream(h2n->swsi, @@ -1632,39 +1798,50 @@ "Zero length window update"); break; } - n = eff_wsi->h2.tx_cr; - eff_wsi->h2.tx_cr += h2n->hpack_e_dep; + n = eff_wsi->txc.tx_cr; + eff_wsi->txc.tx_cr += h2n->hpack_e_dep; + + lws_wsi_txc_report_manual_txcr_in(eff_wsi, + (int32_t)h2n->hpack_e_dep); - if (n <= 0 && eff_wsi->h2.tx_cr <= 0) + lws_wsi_txc_describe(&eff_wsi->txc, "WINDOW_UPDATE in", + eff_wsi->mux.my_sid); + + if (n <= 0 && eff_wsi->txc.tx_cr <= 0) /* it helps, but won't change sendability for anyone */ break; /* - * It did change sendability... for us and any children waiting - * on us... reassess blockage for all children first + * It may have changed sendability (depends on SID 0 tx credit + * too)... for us and any children waiting on us... reassess + * blockage for all children first */ - lws_start_foreach_ll(struct lws *, w, wsi->h2.child_list) { + lws_start_foreach_ll(struct lws *, w, wsi->mux.child_list) { lws_callback_on_writable(w); - } lws_end_foreach_ll(w, h2.sibling_list); + } lws_end_foreach_ll(w, mux.sibling_list); - if (eff_wsi->h2.skint && lws_h2_tx_cr_get(eff_wsi)) { - lwsl_info("%s: %p: skint\n", __func__, wsi); - eff_wsi->h2.skint = 0; + if (eff_wsi->txc.skint && + !lws_wsi_txc_check_skint(&eff_wsi->txc, + lws_h2_tx_cr_get(eff_wsi))) + /* + * This one became un-skint, schedule a writeable + * callback + */ lws_callback_on_writable(eff_wsi); - } + break; case LWS_H2_FRAME_TYPE_GOAWAY: - lwsl_info("GOAWAY: last sid %d, error 0x%08X, string '%s'\n", - h2n->goaway_last_sid, h2n->goaway_err, - h2n->goaway_str); - wsi->h2.GOING_AWAY = 1; + lwsl_notice("GOAWAY: last sid %u, error 0x%08X, string '%s'\n", + (unsigned int)h2n->goaway_last_sid, + (unsigned int)h2n->goaway_err, h2n->goaway_str); return 1; case LWS_H2_FRAME_TYPE_RST_STREAM: - lwsl_info("LWS_H2_FRAME_TYPE_RST_STREAM: sid %d: reason 0x%x\n", - h2n->sid, h2n->hpack_e_dep); + lwsl_info("LWS_H2_FRAME_TYPE_RST_STREAM: sid %u: reason 0x%x\n", + (unsigned int)h2n->sid, + (unsigned int)h2n->hpack_e_dep); break; case LWS_H2_FRAME_TYPE_COUNT: /* IGNORING FRAME */ @@ -1706,7 +1883,7 @@ c = *in++; - // lwsl_notice("%s: 0x%x\n", __func__, c); + lwsl_debug("%s: 0x%x, count %u, len %u (type %d)\n", __func__, c, (unsigned int)h2n->count, (unsigned int)h2n->length, h2n->type); switch (lwsi_state(wsi)) { case LRS_H2_AWAIT_PREFACE: @@ -1718,8 +1895,9 @@ lwsl_info("http2: %p: established\n", wsi); lwsi_set_state(wsi, LRS_H2_AWAIT_SETTINGS); + lws_validity_confirmed(wsi); h2n->count = 0; - wsi->h2.tx_cr = 65535; + wsi->txc.tx_cr = 65535; /* * we must send a settings frame -- empty one is OK... @@ -1735,6 +1913,7 @@ case LRS_H2_WAITING_TO_SEND_HEADERS: case LRS_ESTABLISHED: case LRS_H2_AWAIT_SETTINGS: + if (h2n->frame_state != LWS_H2_FRAME_HEADER_LENGTH) goto try_frame_start; @@ -1743,6 +1922,12 @@ */ h2n->count++; + if (h2n->type == LWS_H2_FRAME_TYPE_COUNT) { /* IGNORING FRAME */ + lwsl_debug("%s: consuming for ignored %u %u\n", __func__, (unsigned int)h2n->count, (unsigned int)h2n->length); + goto frame_end; + } + + if (h2n->flags & LWS_H2_FLAG_PADDED && !h2n->pad_length) { /* @@ -1773,14 +1958,14 @@ h2n->weight_temp = c; h2n->collected_priority = 1; lwsl_debug("PRI FL: dep 0x%x, weight 0x%02X\n", - h2n->dep, h2n->weight_temp); + (unsigned int)h2n->dep, + h2n->weight_temp); break; /* we consumed this */ } if (h2n->padding && h2n->count > (h2n->length - h2n->padding)) { if (c) { - lws_h2_goaway(wsi, - H2_ERR_PROTOCOL_ERROR, + lws_h2_goaway(wsi, H2_ERR_PROTOCOL_ERROR, "nonzero padding"); break; } @@ -1796,7 +1981,7 @@ h2n->one_setting[n] = c; if (n != LWS_H2_SETTINGS_LEN - 1) break; - lws_h2_settings(wsi, &h2n->set, + lws_h2_settings(wsi, &h2n->peer_set, h2n->one_setting, LWS_H2_SETTINGS_LEN); break; @@ -1844,8 +2029,8 @@ case LWS_H2_FRAME_TYPE_DATA: - lwsl_info("%s: LWS_H2_FRAME_TYPE_DATA\n", - __func__); + lwsl_info("%s: LWS_H2_FRAME_TYPE_DATA: fl 0x%x\n", + __func__, h2n->flags); /* * let the network wsi live a bit longer if @@ -1854,12 +2039,9 @@ */ if (!wsi->immortal_substream_count) lws_set_timeout(wsi, - PENDING_TIMEOUT_HTTP_KEEPALIVE_IDLE, -#if defined(LWS_AMAZON_RTOS) || defined(LWS_AMAZON_LINUX) - wsi->vhost->keepalive_timeout); -#else - 31); -#endif + PENDING_TIMEOUT_HTTP_KEEPALIVE_IDLE, + wsi->a.vhost->keepalive_timeout ? + wsi->a.vhost->keepalive_timeout : 31); if (!h2n->swsi) break; @@ -1882,6 +2064,10 @@ h2n->swsi->http.rx_content_remain < inlen + 1 && /* last */ h2n->inside < h2n->length) { + lwsl_warn("%s: rem %d, inlen %d\n", + __func__, + (int)h2n->swsi->http.rx_content_remain, + (int)inlen + 1); /* unread data in frame */ lws_h2_goaway(wsi, H2_ERR_PROTOCOL_ERROR, @@ -1897,17 +2083,28 @@ n = (int)inlen + 1; if (n > (int)(h2n->length - h2n->count + 1)) { n = h2n->length - h2n->count + 1; - lwsl_debug("---- restricting len to %d vs %ld\n", n, (long)inlen + 1); + lwsl_debug("---- restricting len to %d " + "vs %ld\n", n, (long)inlen + 1); } -#if !defined(LWS_NO_CLIENT) - if (h2n->swsi->client_h2_substream) { - +#if defined(LWS_WITH_CLIENT) + if (h2n->swsi->client_mux_substream) { + if (!h2n->swsi->a.protocol) { + lwsl_err("%s: swsi %p doesn't have protocol\n", + __func__, h2n->swsi); + m = 1; + } else { + h2n->swsi->txc.peer_tx_cr_est -= n; + wsi->txc.peer_tx_cr_est -= n; + lws_wsi_txc_describe(&h2n->swsi->txc, + __func__, + h2n->swsi->mux.my_sid); m = user_callback_handle_rxflow( - h2n->swsi->protocol->callback, + h2n->swsi->a.protocol->callback, h2n->swsi, LWS_CALLBACK_RECEIVE_CLIENT_HTTP_READ, h2n->swsi->user_space, in - 1, n); + } in += n - 1; h2n->inside += n; @@ -1921,110 +2118,118 @@ } break; - } else + } #endif - { - - if (lwsi_state(h2n->swsi) == LRS_DEFERRING_ACTION) { - // lwsl_notice("appending because we are in LRS_DEFERRING_ACTION\n"); - m = lws_buflist_append_segment( - &h2n->swsi->buflist, - in - 1, n); - if (m < 0) - return -1; - if (m) { - struct lws_context_per_thread *pt = &wsi->context->pt[(int)wsi->tsi]; - lwsl_debug("%s: added %p to rxflow list\n", __func__, wsi); - lws_dll2_add_head(&h2n->swsi->dll_buflist, &pt->dll_buflist_owner); - } - in += n - 1; - h2n->inside += n; - h2n->count += n - 1; - inlen -= n - 1; - - lwsl_debug("%s: deferred %d\n", __func__, n); - goto do_windows; - } - h2n->swsi->outer_will_close = 1; - /* - * choose the length for this go so that we end at - * the frame boundary, in the case there is already - * more waiting leave it for next time around - */ - - n = lws_read_h1(h2n->swsi, in - 1, n); - // lwsl_notice("%s: lws_read_h1 %d\n", __func__, n); - h2n->swsi->outer_will_close = 0; - /* - * can return 0 in POST body with - * content len exhausted somehow. - */ - if (n < 0 || - (!n && !lws_buflist_next_segment_len(&wsi->buflist, NULL))) { - lwsl_info("%s: lws_read_h1 told %d %d / %d\n", - __func__, n, h2n->count, h2n->length); - in += h2n->length - h2n->count; - h2n->inside = h2n->length; - h2n->count = h2n->length - 1; + if (lwsi_state(h2n->swsi) == LRS_DEFERRING_ACTION) { + m = lws_buflist_append_segment( + &h2n->swsi->buflist, in - 1, n); + if (m < 0) + return -1; + if (m) { + struct lws_context_per_thread *pt; - //if (n < 0) - // goto already_closed_swsi; - goto close_swsi_and_return; + pt = &wsi->a.context->pt[(int)wsi->tsi]; + lwsl_debug("%s: added %p to rxflow list\n", + __func__, wsi); + lws_dll2_add_head( + &h2n->swsi->dll_buflist, + &pt->dll_buflist_owner); } - - inlen -= n - 1; in += n - 1; h2n->inside += n; h2n->count += n - 1; + inlen -= n - 1; + + lwsl_debug("%s: deferred %d\n", __func__, n); + goto do_windows; + } + + h2n->swsi->outer_will_close = 1; + /* + * choose the length for this go so that we end at + * the frame boundary, in the case there is already + * more waiting leave it for next time around + */ + + n = lws_read_h1(h2n->swsi, in - 1, n); + // lwsl_notice("%s: lws_read_h1 %d\n", __func__, n); + h2n->swsi->outer_will_close = 0; + /* + * can return 0 in POST body with + * content len exhausted somehow. + */ + if (n < 0 || + (!n && !lws_buflist_next_segment_len( + &wsi->buflist, NULL))) { + lwsl_info("%s: lws_read_h1 told %d %u / %u\n", + __func__, n, + (unsigned int)h2n->count, + (unsigned int)h2n->length); + in += h2n->length - h2n->count; + h2n->inside = h2n->length; + h2n->count = h2n->length - 1; + + //if (n < 0) + // goto already_closed_swsi; + goto close_swsi_and_return; } + inlen -= n - 1; + in += n - 1; + h2n->inside += n; + h2n->count += n - 1; + h2n->swsi->txc.peer_tx_cr_est -= n; + wsi->txc.peer_tx_cr_est -= n; + do_windows: - /* account for both network and stream wsi windows */ - wsi->h2.peer_tx_cr_est -= n; - h2n->swsi->h2.peer_tx_cr_est -= n; +#if defined(LWS_WITH_CLIENT) + if (!(h2n->swsi->flags & LCCSCF_H2_MANUAL_RXFLOW)) +#endif + { + /* + * The default behaviour is we just keep + * cranking the other side's tx credit + * back up, for simple bulk transfer as + * fast as we can take it + */ + + m = n; //(2 * h2n->length) + 65536; - // lwsl_notice(" peer_tx_cr_est %d, parent %d\n", - // h2n->swsi->h2.peer_tx_cr_est, wsi->h2.peer_tx_cr_est); + /* update both the stream and nwsi */ - if (h2n->swsi->h2.peer_tx_cr_est < (int)(2 * h2n->length) + 65536) { - pps = lws_h2_new_pps(LWS_H2_PPS_UPDATE_WINDOW); - if (!pps) - return 1; - pps->u.update_window.sid = h2n->sid; - pps->u.update_window.credit = (2 * h2n->length + 65536); - h2n->swsi->h2.peer_tx_cr_est += pps->u.update_window.credit; - lws_pps_schedule(wsi, pps); + lws_h2_update_peer_txcredit_thresh(h2n->swsi, + h2n->sid, m, m); } - if (wsi->h2.peer_tx_cr_est < (int)(2 * h2n->length) + 65536) { - pps = lws_h2_new_pps(LWS_H2_PPS_UPDATE_WINDOW); - if (!pps) - return 1; - pps->u.update_window.sid = 0; - pps->u.update_window.credit = (2 * h2n->length + 65536); - wsi->h2.peer_tx_cr_est += pps->u.update_window.credit; - lws_pps_schedule(wsi, pps); +#if defined(LWS_WITH_CLIENT) + else { + /* + * If he's handling it himself, only + * repair the nwsi credit but allow the + * stream credit to run down until the + * user code deals with it + */ + lws_h2_update_peer_txcredit(wsi, 0, n); + h2n->swsi->txc.manual = 1; } - - // lwsl_notice("%s: count %d len %d\n", __func__, (int)h2n->count, (int)h2n->length); - +#endif break; case LWS_H2_FRAME_TYPE_PRIORITY: if (h2n->count <= 4) { h2n->dep <<= 8; h2n->dep |= c; - } else { - h2n->weight_temp = c; - lwsl_info("PRIORITY: dep 0x%x, weight 0x%02X\n", - h2n->dep, h2n->weight_temp); - - if ((h2n->dep & ~(1u << 31)) == h2n->sid) { - lws_h2_goaway(wsi, H2_ERR_PROTOCOL_ERROR, - "cant depend on own sid"); - break; - } + break; + } + h2n->weight_temp = c; + lwsl_info("PRIORITY: dep 0x%x, weight 0x%02X\n", + (unsigned int)h2n->dep, h2n->weight_temp); + + if ((h2n->dep & ~(1u << 31)) == h2n->sid) { + lws_h2_goaway(wsi, H2_ERR_PROTOCOL_ERROR, + "cant depend on own sid"); + break; } break; @@ -2051,6 +2256,8 @@ break; case LWS_H2_FRAME_TYPE_COUNT: /* IGNORING FRAME */ + lwsl_debug("%s: consuming for ignored %u %u\n", __func__, (unsigned int)h2n->count, (unsigned int)h2n->length); + h2n->count++; break; default: @@ -2062,12 +2269,13 @@ frame_end: if (h2n->count > h2n->length) { - lwsl_notice("%s: count > length %d %d\n", - __func__, h2n->count, h2n->length); - goto fail; - } - if (h2n->count != h2n->length) - break; + lwsl_notice("%s: count > length %u %u (type %d)\n", + __func__, (unsigned int)h2n->count, + (unsigned int)h2n->length, h2n->type); + + } else + if (h2n->count != h2n->length) + break; /* * end of frame just happened @@ -2111,12 +2319,16 @@ } } - if (h2n->frame_state == LWS_H2_FRAME_HEADER_LENGTH) - if (lws_h2_parse_frame_header(wsi)) - goto fail; + if (h2n->frame_state == LWS_H2_FRAME_HEADER_LENGTH && + lws_h2_parse_frame_header(wsi)) + goto fail; break; default: + if (h2n->type == LWS_H2_FRAME_TYPE_COUNT) { /* IGNORING FRAME */ + lwsl_debug("%s: consuming for ignored %u %u\n", __func__, (unsigned int)h2n->count, (unsigned int)h2n->length); + h2n->count++; + } break; } } @@ -2143,16 +2355,16 @@ return 1; } +#if defined(LWS_WITH_CLIENT) int lws_h2_client_handshake(struct lws *wsi) { - struct lws_context_per_thread *pt = &wsi->context->pt[(int)wsi->tsi]; - uint8_t *buf, *start, *p, *end; + struct lws_context_per_thread *pt = &wsi->a.context->pt[(int)wsi->tsi]; + uint8_t *buf, *start, *p, *p1, *end; char *meth = lws_hdr_simple_ptr(wsi, _WSI_TOKEN_CLIENT_METHOD), - *uri = lws_hdr_simple_ptr(wsi, _WSI_TOKEN_CLIENT_URI); + *uri = lws_hdr_simple_ptr(wsi, _WSI_TOKEN_CLIENT_URI), *simp; struct lws *nwsi = lws_get_network_wsi(wsi); - struct lws_h2_protocol_send *pps; - int n; + int n, m; /* * The identifier of a newly established stream MUST be numerically * greater than all streams that the initiating endpoint has opened or @@ -2163,30 +2375,25 @@ */ int sid = nwsi->h2.h2n->highest_sid_opened + 2; - nwsi->h2.h2n->highest_sid_opened = sid; - wsi->h2.my_sid = sid; + lwsl_debug("%s\n", __func__); - lwsl_info("%s: CLIENT_WAITING_TO_SEND_HEADERS: pollout (sid %d)\n", - __func__, wsi->h2.my_sid); + /* + * We MUST allocate our sid here at the point we're about to send the + * stream open. It's because we don't know the order in which multiple + * open streams will send their headers... in h2, sending the headers + * is the point the stream is opened. The peer requires that we only + * open streams in ascending sid order + */ - pps = lws_h2_new_pps(LWS_H2_PPS_UPDATE_WINDOW); - if (!pps) - return 1; - pps->u.update_window.sid = sid; - pps->u.update_window.credit = 4 * 65536; - wsi->h2.peer_tx_cr_est += pps->u.update_window.credit; - lws_pps_schedule(wsi, pps); + wsi->mux.my_sid = nwsi->h2.h2n->highest_sid_opened = sid; + lwsl_info("%s: wsi %p: assigning SID %d at header send\n", __func__, wsi, sid); - pps = lws_h2_new_pps(LWS_H2_PPS_UPDATE_WINDOW); - if (!pps) - return 1; - pps->u.update_window.sid = 0; - pps->u.update_window.credit = 4 * 65536; - wsi->h2.peer_tx_cr_est += pps->u.update_window.credit; - lws_pps_schedule(wsi, pps); + + lwsl_info("%s: CLIENT_WAITING_TO_SEND_HEADERS: pollout (sid %d)\n", + __func__, wsi->mux.my_sid); p = start = buf = pt->serv_buf + LWS_PRE; - end = start + wsi->context->pt_serv_buf_size - LWS_PRE - 1; + end = start + (wsi->a.context->pt_serv_buf_size / 2) - LWS_PRE - 1; /* it's time for us to send our client stream headers */ @@ -2201,28 +2408,54 @@ if (lws_add_http_header_by_token(wsi, WSI_TOKEN_HTTP_COLON_SCHEME, - (unsigned char *)"https", 4, + (unsigned char *)"https", 5, &p, end)) goto fail_length; - if (lws_add_http_header_by_token(wsi, + n = lws_hdr_total_length(wsi, _WSI_TOKEN_CLIENT_URI); + if (n && lws_add_http_header_by_token(wsi, WSI_TOKEN_HTTP_COLON_PATH, - (unsigned char *)uri, - lws_hdr_total_length(wsi, _WSI_TOKEN_CLIENT_URI), - &p, end)) + (unsigned char *)uri, n, &p, end)) goto fail_length; - if (lws_add_http_header_by_token(wsi, + n = lws_hdr_total_length(wsi, _WSI_TOKEN_CLIENT_ORIGIN); + simp = lws_hdr_simple_ptr(wsi, _WSI_TOKEN_CLIENT_ORIGIN); + if (n && simp && lws_add_http_header_by_token(wsi, WSI_TOKEN_HTTP_COLON_AUTHORITY, - (unsigned char *)lws_hdr_simple_ptr(wsi, - _WSI_TOKEN_CLIENT_ORIGIN), - lws_hdr_total_length(wsi, _WSI_TOKEN_CLIENT_ORIGIN), + (unsigned char *)simp, n, &p, end)) + goto fail_length; + + n = lws_hdr_total_length(wsi, _WSI_TOKEN_CLIENT_HOST); + simp = lws_hdr_simple_ptr(wsi, _WSI_TOKEN_CLIENT_HOST); + + if (!wsi->client_h2_alpn && n && simp && + lws_add_http_header_by_token(wsi, WSI_TOKEN_HOST, + (unsigned char *)simp, n, &p, end)) + goto fail_length; + + if (lws_add_http_header_by_token(wsi, WSI_TOKEN_HTTP_USER_AGENT, + (unsigned char *)"lwsss", 5, &p, end)) goto fail_length; + if (wsi->flags & LCCSCF_HTTP_MULTIPART_MIME) { + p1 = lws_http_multipart_headers(wsi, p); + if (!p1) + goto fail_length; + p = p1; + } + + if (wsi->flags & LCCSCF_HTTP_X_WWW_FORM_URLENCODED) { + if (lws_add_http_header_by_token(wsi, WSI_TOKEN_HTTP_CONTENT_TYPE, + (unsigned char *)"application/x-www-form-urlencoded", + 33, &p, end)) + goto fail_length; + lws_client_http_body_pending(wsi, 1); + } + /* give userland a chance to append, eg, cookies */ - if (wsi->protocol->callback(wsi, + if (wsi->a.protocol->callback(wsi, LWS_CALLBACK_CLIENT_APPEND_HANDSHAKE_HEADER, wsi->user_space, &p, (end - p) - 12)) goto fail_length; @@ -2230,17 +2463,50 @@ if (lws_finalize_http_header(wsi, &p, end)) goto fail_length; - n = lws_write(wsi, start, p - start, - LWS_WRITE_HTTP_HEADERS); +#if defined(LWS_WITH_DETAILED_LATENCY) + wsi->detlat.earliest_write_req_pre_write = lws_now_usecs(); +#endif + + m = LWS_WRITE_HTTP_HEADERS; +#if defined(LWS_WITH_CLIENT) + /* below is not needed in spec, indeed it destroys the long poll + * feature, but required by nghttp2 */ + if ((wsi->flags & LCCSCF_H2_QUIRK_NGHTTP2_END_STREAM) && + !(wsi->client_http_body_pending)) + m |= LWS_WRITE_H2_STREAM_END; +#endif + + // lwsl_hexdump_notice(start, p - start); + + n = lws_write(wsi, start, p - start, m); + if (n != (p - start)) { lwsl_err("_write returned %d from %ld\n", n, (long)(p - start)); return -1; } + /* + * Normally let's charge up the peer tx credit a bit. But if + * MANUAL_REFLOW is set, just set it to the initial credit given in + * the client create info + */ + + n = 4 * 65536; + if (wsi->flags & LCCSCF_H2_MANUAL_RXFLOW) { + n = wsi->txc.manual_initial_tx_credit; + wsi->txc.manual = 1; + } + + if (lws_h2_update_peer_txcredit(wsi, wsi->mux.my_sid, n)) + return 1; + lws_h2_state(wsi, LWS_H2_STATE_OPEN); lwsi_set_state(wsi, LRS_ESTABLISHED); + if (wsi->flags & LCCSCF_HTTP_MULTIPART_MIME) + lws_callback_on_writable(wsi); + return 0; fail_length: @@ -2248,7 +2514,9 @@ return -1; } +#endif +#if defined(LWS_ROLE_WS) && defined(LWS_WITH_SERVER) int lws_h2_ws_handshake(struct lws *wsi) { @@ -2280,12 +2548,50 @@ * - one came in, and ... */ if (lws_hdr_total_length(wsi, WSI_TOKEN_PROTOCOL) && /* - it is not an empty string */ - wsi->protocol->name && wsi->protocol->name[0]) { + wsi->a.protocol->name && wsi->a.protocol->name[0]) { + +#if defined(LWS_WITH_SECURE_STREAMS) && defined(LWS_WITH_SERVER) + + /* + * This is the h2 version of server-ws.c understanding that it + * did the ws upgrade on a ss server object, therefore it needs + * to pass back to the peer the policy ws-protocol name, not + * the generic ss-ws.c protocol name + */ + + if (wsi->a.vhost && wsi->a.vhost->ss_handle && + wsi->a.vhost->ss_handle->policy->u.http.u.ws.subprotocol) { + lws_ss_handle_t *h = + (lws_ss_handle_t *)wsi->a.opaque_user_data; + + lwsl_notice("%s: Server SS %p .wsi %p switching to ws protocol\n", + __func__, h, h->wsi); + + wsi->a.protocol = &protocol_secstream_ws; + + /* + * inform the SS user code that this has done a one-way + * upgrade to some other protocol... it will likely + * want to treat subsequent payloads differently + */ + + lws_ss_event_helper(h, LWSSSCS_SERVER_UPGRADE); + + lws_mux_mark_immortal(wsi); + if (lws_add_http_header_by_token(wsi, WSI_TOKEN_PROTOCOL, - (unsigned char *)wsi->protocol->name, - (int)strlen(wsi->protocol->name), - &p, end)) - return -1; + (unsigned char *)wsi->a.vhost->ss_handle->policy-> + u.http.u.ws.subprotocol, + (int)strlen(wsi->a.vhost->ss_handle->policy-> + u.http.u.ws.subprotocol), &p, end)) + return -1; + } else +#endif + + if (lws_add_http_header_by_token(wsi, WSI_TOKEN_PROTOCOL, + (unsigned char *)wsi->a.protocol->name, + (int)strlen(wsi->a.protocol->name), &p, end)) + return -1; } } @@ -2314,12 +2620,15 @@ hit = lws_find_mount(wsi, uri_ptr, n); if (hit && hit->cgienv && - wsi->protocol->callback(wsi, LWS_CALLBACK_HTTP_PMO, wsi->user_space, + wsi->a.protocol->callback(wsi, LWS_CALLBACK_HTTP_PMO, wsi->user_space, (void *)hit->cgienv, 0)) return 1; + lws_validity_confirmed(wsi); + return 0; } +#endif int lws_read_h2(struct lws *wsi, unsigned char *buf, lws_filepos_t len) @@ -2349,7 +2658,6 @@ if (lws_is_flowcontrolled(wsi)) { lws_rxflow_cache(wsi, buf, 0, (int)len); buf += len; - len = 0; break; } @@ -2386,7 +2694,6 @@ if (m == 2) { /* swsi has been closed */ buf += body_chunk_len; - len -= body_chunk_len; break; } @@ -2397,3 +2704,23 @@ return lws_ptr_diff(buf, oldbuf); } +int +lws_h2_client_stream_long_poll_rxonly(struct lws *wsi) +{ + + if (!wsi->mux_substream) + return 1; + + /* + * Elect to send an empty DATA with END_STREAM, to force the stream + * into HALF_CLOSED LOCAL + */ + wsi->h2.long_poll = 1; + wsi->h2.send_END_STREAM = 1; + + // lws_header_table_detach(wsi, 0); + + lws_callback_on_writable(wsi); + + return 0; +} diff -Nru libwebsockets-3.2.1/lib/roles/h2/minihuf.c libwebsockets-4.1.6/lib/roles/h2/minihuf.c --- libwebsockets-3.2.1/lib/roles/h2/minihuf.c 2019-12-18 14:45:31.000000000 +0000 +++ libwebsockets-4.1.6/lib/roles/h2/minihuf.c 2020-12-01 17:40:26.000000000 +0000 @@ -5,7 +5,7 @@ * * Copyright (C)2011-2014 Andy Green * - * Licensed under LGPL2 + * Licensed under MIT * * Usage: gcc minihuf.c -o minihuf && ./minihuf > huftable.h * @@ -334,7 +334,6 @@ int saw; int y; int j; - int q; int pos = 0; int biggest = 0; int fails = 0; @@ -401,9 +400,8 @@ walk = 0; pos = 0; - q = 0; + for (n = 0; n < next; n++) { - q = pos; for (m = 0; m < 2; m++) { saw = state[n].state[m]; diff -Nru libwebsockets-3.2.1/lib/roles/h2/ops-h2.c libwebsockets-4.1.6/lib/roles/h2/ops-h2.c --- libwebsockets-3.2.1/lib/roles/h2/ops-h2.c 2019-12-18 14:45:31.000000000 +0000 +++ libwebsockets-4.1.6/lib/roles/h2/ops-h2.c 2020-12-01 17:40:26.000000000 +0000 @@ -1,25 +1,28 @@ /* * libwebsockets - small server side websockets and web server implementation * - * Copyright (C) 2010-2018 Andy Green + * Copyright (C) 2010 - 2019 Andy Green * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation: - * version 2.1 of the License. + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to + * deal in the Software without restriction, including without limitation the + * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or + * sell copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: * - * This library is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. * - * You should have received a copy of the GNU Lesser General Public - * License along with this library; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, - * MA 02110-1301 USA + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS + * IN THE SOFTWARE. */ -#include +#include /* * These are the standardized defaults. @@ -68,9 +71,12 @@ * * Can't pass h2spec with less than 4096 here... */ - /* H2SET_ENABLE_PUSH */ 1, + /* H2SET_ENABLE_PUSH */ 0, /* H2SET_MAX_CONCURRENT_STREAMS */ 24, - /* H2SET_INITIAL_WINDOW_SIZE */ 65535, + /* H2SET_INITIAL_WINDOW_SIZE */ 0, + /*< This is managed by explicit WINDOW_UPDATE. Because otherwise no + * way to precisely control it when we do want to. + */ /* H2SET_MAX_FRAME_SIZE */ 16384, /* H2SET_MAX_HEADER_LIST_SIZE */ 4096, /*< This advisory setting informs a peer of the maximum size of @@ -107,7 +113,7 @@ #endif lwsl_info("%s: wsistate 0x%x, pollout %d\n", __func__, - wsi->wsistate, pollfd->revents & LWS_POLLOUT); + (unsigned int)wsi->wsistate, pollfd->revents & LWS_POLLOUT); /* * something went wrong with parsing the handshake, and @@ -119,14 +125,14 @@ } if (lwsi_state(wsi) == LRS_WAITING_CONNECT) { -#if !defined(LWS_NO_CLIENT) +#if defined(LWS_WITH_CLIENT) if ((pollfd->revents & LWS_POLLOUT) && lws_handle_POLLOUT_event(wsi, pollfd)) { lwsl_debug("POLLOUT event closed it\n"); return LWS_HPI_RET_PLEASE_CLOSE_ME; } - n = lws_client_socket_service(wsi, pollfd, NULL); + n = lws_client_socket_service(wsi, pollfd); if (n) return LWS_HPI_RET_WSI_ALREADY_DIED; #endif @@ -161,7 +167,7 @@ #endif } - if (wsi->http2_substream || wsi->upgraded_to_http2) { + if (wsi->mux_substream || wsi->upgraded_to_http2) { wsi1 = lws_get_network_wsi(wsi); if (wsi1 && lws_has_buffered_out(wsi1)) /* @@ -176,7 +182,7 @@ read: /* 3: network wsi buflist needs to be drained */ - // lws_buflist_describe(&wsi->buflist, wsi); + // lws_buflist_describe(&wsi->buflist, wsi, __func__); ebuf.len = (int)lws_buflist_next_segment_len(&wsi->buflist, &ebuf.token); @@ -197,7 +203,7 @@ ebuf.token = pt->serv_buf; ebuf.len = lws_ssl_capable_read(wsi, ebuf.token, - wsi->context->pt_serv_buf_size); + wsi->a.context->pt_serv_buf_size); switch (ebuf.len) { case 0: lwsl_info("%s: zero length read\n", __func__); @@ -219,7 +225,7 @@ return LWS_HPI_RET_PLEASE_CLOSE_ME; drain: -#ifndef LWS_NO_CLIENT +#if defined(LWS_WITH_CLIENT) if (lwsi_role_http(wsi) && lwsi_role_client(wsi) && wsi->hdr_parsing_completed && !wsi->told_user_closed) { @@ -242,7 +248,7 @@ * callback and drain / re-enable it there */ if (user_callback_handle_rxflow( - wsi->protocol->callback, + wsi->a.protocol->callback, wsi, LWS_CALLBACK_RECEIVE_CLIENT_HTTP, wsi->user_space, NULL, 0)) { lwsl_info("RECEIVE_CLIENT_HTTP closed it\n"); @@ -265,12 +271,12 @@ if (n < 0) { /* we closed wsi */ - n = 0; return LWS_HPI_RET_WSI_ALREADY_DIED; } if (n && buffered) { - m = lws_buflist_use_segment(&wsi->buflist, n); + // lwsl_notice("%s: h2 use %d\n", __func__, n); + m = (int)lws_buflist_use_segment(&wsi->buflist, (size_t)n); lwsl_info("%s: draining rxflow: used %d, next %d\n", __func__, n, m); if (!m) { @@ -280,6 +286,7 @@ } } else if (n && n != ebuf.len) { + // lwsl_notice("%s: h2 append seg %d\n", __func__, ebuf.len - n); m = lws_buflist_append_segment(&wsi->buflist, ebuf.token + n, ebuf.len - n); @@ -288,13 +295,14 @@ if (m) { lwsl_debug("%s: added %p to rxflow list\n", __func__, wsi); - lws_dll2_add_head(&wsi->dll_buflist, + if (lws_dll2_is_detached(&wsi->dll_buflist)) + lws_dll2_add_head(&wsi->dll_buflist, &pt->dll_buflist_owner); } } } - // lws_buflist_describe(&wsi->buflist, wsi); + // lws_buflist_describe(&wsi->buflist, wsi, __func__); #if 0 @@ -305,7 +313,7 @@ */ if (wsi->http.ah -#if !defined(LWS_NO_CLIENT) +#if defined(LWS_WITH_CLIENT) && !wsi->client_h2_alpn #endif ) { @@ -332,10 +340,10 @@ return LWS_HP_RET_USER_SERVICE; /* - * Priority 2: H2 protocol packets + * Priority 1: H2 protocol packets */ if ((wsi->upgraded_to_http2 -#if !defined(LWS_NO_CLIENT) +#if defined(LWS_WITH_CLIENT) || wsi->client_h2_alpn #endif ) && wsi->h2.h2n->pps) { @@ -358,7 +366,7 @@ return LWS_HP_RET_BAIL_OK; /* leave POLLOUT active */ } - /* Priority 4: if we are closing, not allowed to send more data frags + /* Priority 2: if we are closing, not allowed to send more data frags * which means user callback or tx ext flush banned now */ if (lwsi_state(wsi) == LRS_RETURNED_CLOSE) @@ -380,20 +388,24 @@ /* if not in a state to send stuff, then just send nothing */ - if (!lwsi_role_ws(wsi) && + if (!lwsi_role_ws(wsi) && !wsi->mux_stream_immortal && base != LWS_WRITE_HTTP && base != LWS_WRITE_HTTP_FINAL && base != LWS_WRITE_HTTP_HEADERS_CONTINUATION && - base != LWS_WRITE_HTTP_HEADERS && + base != LWS_WRITE_HTTP_HEADERS && lwsi_state(wsi) != LRS_BODY && ((lwsi_state(wsi) != LRS_RETURNED_CLOSE && lwsi_state(wsi) != LRS_WAITING_TO_SEND_CLOSE && + lwsi_state(wsi) != LRS_ESTABLISHED && lwsi_state(wsi) != LRS_AWAITING_CLOSE_ACK) #if defined(LWS_ROLE_WS) || base != LWS_WRITE_CLOSE #endif )) { //assert(0); - lwsl_notice("binning wsistate 0x%x %d\n", wsi->wsistate, *wp); + lwsl_notice("%s: binning wsistate 0x%x %d: %s\n", __func__, + (unsigned int)wsi->wsistate, *wp, wsi->a.protocol ? + wsi->a.protocol->name : "no protocol"); + return 0; } @@ -467,7 +479,7 @@ wsi->h2.send_END_STREAM = 1; } - n = lws_h2_frame_write(wsi, n, flags, wsi->h2.my_sid, (int)len, buf); + n = lws_h2_frame_write(wsi, n, flags, wsi->mux.my_sid, (int)len, buf); if (n < 0) return n; @@ -476,11 +488,11 @@ return (int)olen; } +#if defined(LWS_WITH_SERVER) static int rops_check_upgrades_h2(struct lws *wsi) { #if defined(LWS_ROLE_WS) - struct lws *nwsi; char *p; /* @@ -490,27 +502,24 @@ * SETTINGS saying that we support it though. */ p = lws_hdr_simple_ptr(wsi, WSI_TOKEN_HTTP_COLON_METHOD); - if (!wsi->vhost->h2.set.s[H2SET_ENABLE_CONNECT_PROTOCOL] || - !wsi->http2_substream || !p || strcmp(p, "CONNECT")) + if (!wsi->a.vhost->h2.set.s[H2SET_ENABLE_CONNECT_PROTOCOL] || + !wsi->mux_substream || !p || strcmp(p, "CONNECT")) return LWS_UPG_RET_CONTINUE; p = lws_hdr_simple_ptr(wsi, WSI_TOKEN_COLON_PROTOCOL); if (!p || strcmp(p, "websocket")) return LWS_UPG_RET_CONTINUE; - nwsi = lws_get_network_wsi(wsi); - - wsi->vhost->conn_stats.ws_upg++; +#if defined(LWS_WITH_SERVER_STATUS) + wsi->a.vhost->conn_stats.ws_upg++; +#endif lwsl_info("Upgrade h2 to ws\n"); + lws_mux_mark_immortal(wsi); wsi->h2_stream_carries_ws = 1; - nwsi->immortal_substream_count++; + if (lws_process_ws_upgrade(wsi)) return LWS_UPG_RET_BAIL; - if (nwsi->immortal_substream_count == 1) - lws_set_timeout(nwsi, NO_PENDING_TIMEOUT, 0); - - lws_set_timeout(wsi, NO_PENDING_TIMEOUT, 0); lwsl_info("Upgraded h2 to ws OK\n"); return LWS_UPG_RET_DONE; @@ -518,6 +527,7 @@ return LWS_UPG_RET_CONTINUE; #endif } +#endif static int rops_init_vhost_h2(struct lws_vhost *vh, @@ -534,45 +544,76 @@ return 0; } -static int -rops_init_context_h2(struct lws_context *context, - const struct lws_context_creation_info *info) +int +rops_pt_init_destroy_h2(struct lws_context *context, + const struct lws_context_creation_info *info, + struct lws_context_per_thread *pt, int destroy) { - int n; - context->set = lws_h2_stock_settings; /* * We only want to do this once... we will do it if we are built * otherwise h1 ops will do it (or nobody if no http at all) */ - - for (n = 0; n < context->count_threads; n++) { - struct lws_context_per_thread *pt = &context->pt[n]; +#if !defined(LWS_ROLE_H2) && defined(LWS_WITH_SERVER) + if (!destroy) { pt->sul_ah_lifecheck.cb = lws_sul_http_ah_lifecheck; - __lws_sul_insert(&pt->pt_sul_owner, &pt->sul_ah_lifecheck, - 30 * LWS_US_PER_SEC); - } + __lws_sul_insert_us(&pt->pt_sul_owner[LWSSULLI_MISS_IF_SUSPENDED], + &pt->sul_ah_lifecheck, 30 * LWS_US_PER_SEC); + } else + lws_dll2_remove(&pt->sul_ah_lifecheck.list); +#endif return 0; } -static lws_fileofs_t -rops_tx_credit_h2(struct lws *wsi) + +static int +rops_tx_credit_h2(struct lws *wsi, char peer_to_us, int add) { - return lws_h2_tx_cr_get(wsi); + struct lws *nwsi = lws_get_network_wsi(wsi); + int n; + + if (add) { + if (peer_to_us == LWSTXCR_PEER_TO_US) { + /* + * We want to tell the peer they can write an additional + * "add" bytes to us + */ + return lws_h2_update_peer_txcredit(wsi, -1, add); + } + + /* + * We're being told we can write an additional "add" bytes + * to the peer + */ + + wsi->txc.tx_cr += add; + nwsi->txc.tx_cr += add; + + return 0; + } + + if (peer_to_us == LWSTXCR_US_TO_PEER) + return lws_h2_tx_cr_get(wsi); + + n = wsi->txc.peer_tx_cr_est; + if (n > nwsi->txc.peer_tx_cr_est) + n = nwsi->txc.peer_tx_cr_est; + + return n; } static int rops_destroy_role_h2(struct lws *wsi) { - struct lws_context_per_thread *pt = &wsi->context->pt[(int)wsi->tsi]; + struct lws_context_per_thread *pt = &wsi->a.context->pt[(int)wsi->tsi]; struct allocated_headers *ah; /* we may not have an ah, but may be on the waiting list... */ - lwsl_info("%s: ah det due to close\n", __func__); + lwsl_info("%s: wsi %p: ah det due to close\n", __func__, wsi); __lws_header_table_detach(wsi, 0); ah = pt->http.ah_list; @@ -592,7 +633,7 @@ lws_http_compression_destroy(wsi); #endif - if (wsi->upgraded_to_http2 || wsi->http2_substream) { + if (wsi->upgraded_to_http2 || wsi->mux_substream) { lws_hpack_destroy_dynamic_header(wsi); if (wsi->h2.h2n) @@ -605,65 +646,42 @@ static int rops_close_kill_connection_h2(struct lws *wsi, enum lws_close_status reason) { - struct lws *wsi2; #if defined(LWS_WITH_HTTP_PROXY) if (wsi->http.proxy_clientside) { - struct lws *wsi_eff = lws_client_wsi_effective(wsi); wsi->http.proxy_clientside = 0; - if (user_callback_handle_rxflow(wsi_eff->protocol->callback, - wsi_eff, + if (user_callback_handle_rxflow(wsi->a.protocol->callback, + wsi, LWS_CALLBACK_COMPLETED_CLIENT_HTTP, - wsi_eff->user_space, NULL, 0)) + wsi->user_space, NULL, 0)) wsi->http.proxy_clientside = 0; } #endif - if (wsi->http2_substream && wsi->h2_stream_carries_ws) + if (wsi->mux_substream && wsi->h2_stream_carries_ws) lws_h2_rst_stream(wsi, 0, "none"); - - if (wsi->h2.parent_wsi && lwsl_visible(LLL_INFO)) { - lwsl_info(" wsi: %p, his parent %p: siblings:\n", wsi, - wsi->h2.parent_wsi); - lws_start_foreach_llp(struct lws **, w, - wsi->h2.parent_wsi->h2.child_list) { - lwsl_info(" \\---- child %s %p\n", - (*w)->role_ops ? (*w)->role_ops->name : "?", *w); - } lws_end_foreach_llp(w, h2.sibling_list); - } - - if (wsi->upgraded_to_http2 || wsi->http2_substream -#if !defined(LWS_NO_CLIENT) - || wsi->client_h2_substream +/* else + if (wsi->mux_substream) + lws_h2_rst_stream(wsi, H2_ERR_STREAM_CLOSED, "swsi got closed"); +*/ + + lwsl_info(" wsi: %p, his parent %p: siblings:\n", wsi, wsi->mux.parent_wsi); + lws_wsi_mux_dump_children(wsi); + + if (wsi->upgraded_to_http2 || wsi->mux_substream +#if defined(LWS_WITH_CLIENT) + || wsi->client_mux_substream #endif ) { - lwsl_info("closing %p: parent %p\n", wsi, wsi->h2.parent_wsi); + lwsl_info("closing %p: parent %p\n", wsi, wsi->mux.parent_wsi); - if (wsi->h2.child_list && lwsl_visible(LLL_INFO)) { + if (wsi->mux.child_list && lwsl_visible(LLL_INFO)) { lwsl_info(" parent %p: closing children: list:\n", wsi); - lws_start_foreach_llp(struct lws **, w, - wsi->h2.child_list) { - lwsl_info(" \\---- child %s %p\n", - (*w)->role_ops ? (*w)->role_ops->name : "?", - *w); - } lws_end_foreach_llp(w, h2.sibling_list); - } - if (wsi->h2.child_list) { - /* trigger closing of all of our http2 children first */ - lws_start_foreach_llp(struct lws **, w, - wsi->h2.child_list) { - lwsl_info(" closing child %p\n", *w); - /* disconnect from siblings */ - wsi2 = (*w)->h2.sibling_list; - (*w)->h2.sibling_list = NULL; - (*w)->socket_is_permanently_unusable = 1; - __lws_close_free_wsi(*w, reason, "h2 child recurse"); - *w = wsi2; - continue; - } lws_end_foreach_llp(w, h2.sibling_list); + lws_wsi_mux_dump_children(wsi); } + lws_wsi_mux_close_children(wsi, reason); } if (wsi->upgraded_to_http2) { @@ -679,99 +697,62 @@ } if (( -#if !defined(LWS_NO_CLIENT) - wsi->client_h2_substream || +#if defined(LWS_WITH_CLIENT) + wsi->client_mux_substream || #endif - wsi->http2_substream) && - wsi->h2.parent_wsi) { - lwsl_info(" %p: disentangling from siblings\n", wsi); - lws_start_foreach_llp(struct lws **, w, - wsi->h2.parent_wsi->h2.child_list) { - /* disconnect from siblings */ - if (*w == wsi) { - wsi2 = (*w)->h2.sibling_list; - (*w)->h2.sibling_list = NULL; - *w = wsi2; - lwsl_info(" %p disentangled from sibling %p\n", - wsi, wsi2); - break; - } - } lws_end_foreach_llp(w, h2.sibling_list); - wsi->h2.parent_wsi->h2.child_count--; - wsi->h2.parent_wsi = NULL; + wsi->mux_substream) && + wsi->mux.parent_wsi) { + lws_wsi_mux_sibling_disconnect(wsi); if (wsi->h2.pending_status_body) lws_free_set_NULL(wsi->h2.pending_status_body); } - if (wsi->h2_stream_carries_ws || wsi->h2_stream_carries_sse) { - struct lws *nwsi = lws_get_network_wsi(wsi); - - nwsi->immortal_substream_count--; - /* if no ws, then put a timeout on the parent wsi */ - if (!nwsi->immortal_substream_count) - __lws_set_timeout(nwsi, - PENDING_TIMEOUT_HTTP_KEEPALIVE_IDLE, 31); - } - return 0; } static int rops_callback_on_writable_h2(struct lws *wsi) { - struct lws *network_wsi, *wsi2; +#if defined(LWS_WITH_CLIENT) + struct lws *network_wsi; +#endif int already; - //lwsl_notice("%s: %p (wsistate 0x%x)\n", __func__, wsi, wsi->wsistate); - // if (!lwsi_role_h2(wsi) && !lwsi_role_h2_ENCAPSULATION(wsi)) // return 0; - if (wsi->h2.requested_POLLOUT -#if !defined(LWS_NO_CLIENT) + if (wsi->mux.requested_POLLOUT +#if defined(LWS_WITH_CLIENT) && !wsi->client_h2_alpn #endif ) { lwsl_debug("already pending writable\n"); - return 1; + // return 1; } /* is this for DATA or for control messages? */ + if (wsi->upgraded_to_http2 && !wsi->h2.h2n->pps && - !lws_h2_tx_cr_get(wsi)) { + lws_wsi_txc_check_skint(&wsi->txc, lws_h2_tx_cr_get(wsi))) { /* - * other side is not able to cope with us sending DATA - * anything so no matter if we have POLLOUT on our side if it's - * DATA we want to send. - * - * Delay waiting for our POLLOUT until peer indicates he has - * space for more using tx window command in http2 layer + * refuse his efforts to get WRITABLE if we have no credit and + * no non-DATA pps to send */ - lwsl_notice("%s: %p: skint (%d)\n", __func__, wsi, - wsi->h2.tx_cr); - wsi->h2.skint = 1; + lwsl_err("%s: skint\n", __func__); return 0; } - wsi->h2.skint = 0; +#if defined(LWS_WITH_CLIENT) network_wsi = lws_get_network_wsi(wsi); - already = network_wsi->h2.requested_POLLOUT; - - /* mark everybody above him as requesting pollout */ - - wsi2 = wsi; - while (wsi2) { - wsi2->h2.requested_POLLOUT = 1; - lwsl_info("mark %p pending writable\n", wsi2); - wsi2 = wsi2->h2.parent_wsi; - } +#endif + already = lws_wsi_mux_mark_parents_needing_writeable(wsi); /* for network action, act only on the network wsi */ if (already -#if !defined(LWS_NO_CLIENT) +#if defined(LWS_WITH_CLIENT) && !network_wsi->client_h2_alpn - && !network_wsi->client_h2_substream + && !network_wsi->client_mux_substream #endif ) return 1; @@ -779,24 +760,7 @@ return 0; } -static void -lws_h2_dump_waiting_children(struct lws *wsi) -{ -#if defined(_DEBUG) - lwsl_info("%s: %p: children waiting for POLLOUT service:\n", - __func__, wsi); - - wsi = wsi->h2.child_list; - while (wsi) { - lwsl_info(" %c %p %s %s\n", - wsi->h2.requested_POLLOUT ? '*' : ' ', - wsi, wsi->role_ops->name, wsi->protocol->name); - - wsi = wsi->h2.sibling_list; - } -#endif -} - +#if defined(LWS_WITH_SERVER) static int lws_h2_bind_for_post_before_action(struct lws *wsi) { @@ -804,12 +768,22 @@ p = lws_hdr_simple_ptr(wsi, WSI_TOKEN_HTTP_COLON_METHOD); if (p && !strcmp(p, "POST")) { - const struct lws_http_mount *hit = - lws_find_mount(wsi, - lws_hdr_simple_ptr(wsi, - WSI_TOKEN_HTTP_COLON_PATH), - lws_hdr_total_length(wsi, - WSI_TOKEN_HTTP_COLON_PATH)); + const struct lws_http_mount *hit; + + if (!lws_hdr_total_length(wsi, WSI_TOKEN_HTTP_COLON_PATH) || + !lws_hdr_simple_ptr(wsi, WSI_TOKEN_HTTP_COLON_PATH)) + /* + * There must be a path. Actually this is checked at + * http2.c along with the other required header + * presence before we can get here. + * + * But Coverity insists to see us check it. + */ + return 1; + + hit = lws_find_mount(wsi, + lws_hdr_simple_ptr(wsi, WSI_TOKEN_HTTP_COLON_PATH), + lws_hdr_total_length(wsi, WSI_TOKEN_HTTP_COLON_PATH)); lwsl_debug("%s: %s: hit %p: %s\n", __func__, lws_hdr_simple_ptr(wsi, WSI_TOKEN_HTTP_COLON_PATH), @@ -821,7 +795,7 @@ if (hit->protocol) name = hit->protocol; - pp = lws_vhost_name_to_protocol(wsi->vhost, name); + pp = lws_vhost_name_to_protocol(wsi->a.vhost, name); if (!pp) { lwsl_info("Unable to find protocol '%s'\n", name); return 1; @@ -832,12 +806,13 @@ } lwsl_info("%s: setting LRS_BODY from 0x%x (%s)\n", __func__, - wsi->wsistate, wsi->protocol->name); + (int)wsi->wsistate, wsi->a.protocol->name); lwsi_set_state(wsi, LRS_BODY); } return 0; } +#endif /* * we are the 'network wsi' for potentially many muxed child wsi with @@ -855,7 +830,7 @@ static int rops_perform_user_POLLOUT_h2(struct lws *wsi) { - struct lws **wsi2, *wsi2a; + struct lws **wsi2; #if defined(LWS_ROLE_WS) int write_type = LWS_WRITE_PONG; #endif @@ -863,23 +838,23 @@ wsi = lws_get_network_wsi(wsi); - wsi->h2.requested_POLLOUT = 0; - if (!wsi->h2.initialized) { - lwsl_info("pollout on uninitialized http2 conn\n"); - return 0; - } + wsi->mux.requested_POLLOUT = 0; +// if (!wsi->h2.initialized) { +// lwsl_info("pollout on uninitialized http2 conn\n"); +// return 0; +// } - lws_h2_dump_waiting_children(wsi); + lws_wsi_mux_dump_waiting_children(wsi); - wsi2 = &wsi->h2.child_list; + wsi2 = &wsi->mux.child_list; if (!*wsi2) return 0; do { struct lws *w, **wa; - wa = &(*wsi2)->h2.sibling_list; - if (!(*wsi2)->h2.requested_POLLOUT) + wa = &(*wsi2)->mux.sibling_list; + if (!(*wsi2)->mux.requested_POLLOUT) goto next_child; /* @@ -889,34 +864,15 @@ lwsl_debug("servicing child %p\n", *wsi2); - w = *wsi2; - while (w) { - if (!w->h2.sibling_list) { /* w is the current last */ - lwsl_debug("w=%p, *wsi2 = %p\n", w, *wsi2); - if (w == *wsi2) /* we are already last */ - break; - /* last points to us as new last */ - w->h2.sibling_list = *wsi2; - /* guy pointing to us until now points to - * our old next */ - *wsi2 = (*wsi2)->h2.sibling_list; - /* we point to nothing because we are last */ - w->h2.sibling_list->h2.sibling_list = NULL; - /* w becomes us */ - w = w->h2.sibling_list; - break; - } - w = w->h2.sibling_list; - } + w = lws_wsi_mux_move_child_to_tail(wsi2); if (!w) { - wa = &wsi->h2.child_list; + wa = &wsi->mux.child_list; goto next_child; } - w->h2.requested_POLLOUT = 0; - lwsl_info("%s: child %p (wsistate 0x%x)\n", __func__, w, - w->wsistate); + lwsl_info("%s: child wsi %p, sid %d, (wsistate 0x%x)\n", + __func__, w, w->mux.my_sid, (unsigned int)w->wsistate); /* priority 1: post compression-transform buffered output */ @@ -926,11 +882,11 @@ lwsl_info("%s signalling to close\n", __func__); lws_close_free_wsi(w, LWS_CLOSE_STATUS_NOSTATUS, "h2 end stream 1"); - wa = &wsi->h2.child_list; + wa = &wsi->mux.child_list; goto next_child; } lws_callback_on_writable(w); - wa = &wsi->h2.child_list; + wa = &wsi->mux.child_list; goto next_child; } @@ -952,7 +908,7 @@ "comp write fail"); } lws_callback_on_writable(w); - wa = &wsi->h2.child_list; + wa = &wsi->mux.child_list; goto next_child; } #endif @@ -963,7 +919,7 @@ w->socket_is_permanently_unusable = 1; lws_close_free_wsi(w, LWS_CLOSE_STATUS_NOSTATUS, "h2 end stream 1"); - wa = &wsi->h2.child_list; + wa = &wsi->mux.child_list; goto next_child; } @@ -980,17 +936,20 @@ lws_free_set_NULL(w->h2.pending_status_body); lws_close_free_wsi(w, LWS_CLOSE_STATUS_NOSTATUS, "h2 end stream 1"); - wa = &wsi->h2.child_list; + wa = &wsi->mux.child_list; goto next_child; } +#if defined(LWS_WITH_CLIENT) if (lwsi_state(w) == LRS_H2_WAITING_TO_SEND_HEADERS) { if (lws_h2_client_handshake(w)) return -1; goto next_child; } +#endif +#if defined(LWS_WITH_SERVER) if (lwsi_state(w) == LRS_DEFERRING_ACTION) { /* @@ -1024,17 +983,25 @@ lwsl_info("closing stream after h2 action\n"); lws_close_free_wsi(w, LWS_CLOSE_STATUS_NOSTATUS, "h2 end stream"); - wa = &wsi->h2.child_list; + wa = &wsi->mux.child_list; } if (n < 0) - wa = &wsi->h2.child_list; + wa = &wsi->mux.child_list; goto next_child; } +#if defined(LWS_WITH_FILE_OPS) + if (lwsi_state(w) == LRS_ISSUING_FILE) { + if (lws_wsi_txc_check_skint(&w->txc, + lws_h2_tx_cr_get(w))) { + wa = &wsi->mux.child_list; + goto next_child; + } + ((volatile struct lws *)w)->leave_pollout_active = 0; /* >0 == completion, <0 == error @@ -1054,7 +1021,7 @@ lwsl_debug("Closing POLLOUT child %p\n", w); lws_close_free_wsi(w, LWS_CLOSE_STATUS_NOSTATUS, "h2 end stream file"); - wa = &wsi->h2.child_list; + wa = &wsi->mux.child_list; goto next_child; } if (n > 0) @@ -1062,11 +1029,13 @@ return -1; if (!n) { lws_callback_on_writable(w); - (w)->h2.requested_POLLOUT = 1; + (w)->mux.requested_POLLOUT = 1; } goto next_child; } +#endif +#endif #if defined(LWS_ROLE_WS) @@ -1115,23 +1084,47 @@ lwsi_set_state(w, LRS_RETURNED_CLOSE); lws_close_free_wsi(w, LWS_CLOSE_STATUS_NOSTATUS, "returned close packet"); - wa = &wsi->h2.child_list; + wa = &wsi->mux.child_list; goto next_child; } lws_callback_on_writable(w); - (w)->h2.requested_POLLOUT = 1; + (w)->mux.requested_POLLOUT = 1; /* otherwise for PING, leave POLLOUT active both ways */ goto next_child; } #endif + + /* + * set client wsi to immortal long-poll mode; send END_STREAM + * flag on headers to indicate to a server, that allows + * it, that you want them to leave the stream in a long poll + * ro immortal state. We have to send headers so the client + * understands the http connection is ongoing. + */ + + if (w->h2.send_END_STREAM && w->h2.long_poll) { + uint8_t buf[LWS_PRE + 1]; + enum lws_write_protocol wp = 0; + + if (!rops_write_role_protocol_h2(w, buf + LWS_PRE, 0, + &wp)) { + lwsl_info("%s: wsi %p: entering ro long poll\n", + __func__, w); + lws_mux_mark_immortal(w); + } else + lwsl_err("%s: wsi %p: failed to set long poll\n", + __func__, w); + goto next_child; + } + if (lws_callback_as_writeable(w)) { lwsl_info("Closing POLLOUT child (end stream %d)\n", w->h2.send_END_STREAM); lws_close_free_wsi(w, LWS_CLOSE_STATUS_NOSTATUS, "h2 pollout handle"); - wa = &wsi->h2.child_list; + wa = &wsi->mux.child_list; } else if (w->h2.send_END_STREAM) lws_h2_state(w, LWS_H2_STATE_HALF_CLOSED_LOCAL); @@ -1140,17 +1133,10 @@ wsi2 = wa; } while (wsi2 && *wsi2 && !lws_send_pipe_choked(wsi)); - // lws_h2_dump_waiting_children(wsi); + // lws_wsi_mux_dump_waiting_children(wsi); - wsi2a = wsi->h2.child_list; - while (wsi2a) { - if (wsi2a->h2.requested_POLLOUT) { - if (lws_change_pollfd(wsi, 0, LWS_POLLOUT)) - return -1; - break; - } - wsi2a = wsi2a->h2.sibling_list; - } + if (lws_wsi_mux_action_pending_writeable_reqs(wsi)) + return -1; return 0; } @@ -1158,8 +1144,8 @@ static struct lws * rops_encapsulation_parent_h2(struct lws *wsi) { - if (wsi->h2.parent_wsi) - return wsi->h2.parent_wsi; + if (wsi->mux.parent_wsi) + return wsi->mux.parent_wsi; return NULL; } @@ -1170,7 +1156,7 @@ struct allocated_headers *ah; lwsl_debug("%s: client %d\n", __func__, lwsi_role_client(wsi)); -#if !defined(LWS_NO_CLIENT) +#if defined(LWS_WITH_CLIENT) if (lwsi_role_client(wsi)) { lwsl_info("%s: upgraded to H2\n", __func__); wsi->client_h2_alpn = 1; @@ -1178,7 +1164,9 @@ #endif wsi->upgraded_to_http2 = 1; - wsi->vhost->conn_stats.h2_alpn++; +#if defined(LWS_WITH_SERVER_STATUS) + wsi->a.vhost->conn_stats.h2_alpn++; +#endif /* adopt the header info */ @@ -1200,22 +1188,63 @@ /* HTTP2 union */ lws_hpack_dynamic_size(wsi, - wsi->h2.h2n->set.s[H2SET_HEADER_TABLE_SIZE]); - wsi->h2.tx_cr = 65535; + wsi->h2.h2n->our_set.s[H2SET_HEADER_TABLE_SIZE]); + wsi->txc.tx_cr = 65535; lwsl_info("%s: wsi %p: configured for h2\n", __func__, wsi); return 0; } -struct lws_role_ops role_ops_h2 = { +static int +rops_issue_keepalive_h2(struct lws *wsi, int isvalid) +{ + struct lws *nwsi = lws_get_network_wsi(wsi); + struct lws_h2_protocol_send *pps; + uint64_t us = lws_now_usecs(); + + if (isvalid) { + _lws_validity_confirmed_role(nwsi); + + return 0; + } + + /* + * We can only send these frames on the network connection itself... + * we shouldn't be tracking validity on anything else + */ + + assert(wsi == nwsi); + + pps = lws_h2_new_pps(LWS_H2_PPS_PING); + if (!pps) + return 1; + + /* + * The peer is defined to copy us back the unchanged payload in another + * PING frame this time with ACK set. So by sending that out with the + * current time, it's an interesting opportunity to learn the effective + * RTT on the link when the PONG comes in, plus or minus the time to + * schedule the PPS. + */ + + memcpy(pps->u.ping.ping_payload, &us, 8); + lws_pps_schedule(nwsi, pps); + + return 0; +} + +const struct lws_role_ops role_ops_h2 = { /* role name */ "h2", /* alpn id */ "h2", +#if defined(LWS_WITH_SERVER) /* check_upgrades */ rops_check_upgrades_h2, - /* init_context */ rops_init_context_h2, +#else + NULL, +#endif + /* pt_init_destroy */ rops_pt_init_destroy_h2, /* init_vhost */ rops_init_vhost_h2, /* destroy_vhost */ NULL, - /* periodic_checks */ NULL, /* service_flag_pending */ NULL, /* handle_POLLIN */ rops_handle_POLLIN_h2, /* handle_POLLOUT */ rops_handle_POLLOUT_h2, @@ -1231,6 +1260,7 @@ /* destroy_role */ rops_destroy_role_h2, /* adoption_bind */ NULL, /* client_bind */ NULL, + /* issue_keepalive */ rops_issue_keepalive_h2, /* adoption_cb clnt, srv */ { LWS_CALLBACK_SERVER_NEW_CLIENT_INSTANTIATED, LWS_CALLBACK_SERVER_NEW_CLIENT_INSTANTIATED }, /* rx cb clnt, srv */ { LWS_CALLBACK_RECEIVE_CLIENT_HTTP, diff -Nru libwebsockets-3.2.1/lib/roles/h2/private.h libwebsockets-4.1.6/lib/roles/h2/private.h --- libwebsockets-3.2.1/lib/roles/h2/private.h 2019-12-18 14:45:31.000000000 +0000 +++ libwebsockets-4.1.6/lib/roles/h2/private.h 1970-01-01 00:00:00.000000000 +0000 @@ -1,406 +0,0 @@ -/* - * libwebsockets - small server side websockets and web server implementation - * - * Copyright (C) 2010 - 2018 Andy Green - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation: - * version 2.1 of the License. - * - * This library is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with this library; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, - * MA 02110-1301 USA - * - * This is included from core/private.h if LWS_ROLE_H2 - */ - -extern struct lws_role_ops role_ops_h2; -#define lwsi_role_h2(wsi) (wsi->role_ops == &role_ops_h2) - -enum lws_h2_settings { - H2SET_HEADER_TABLE_SIZE = 1, - H2SET_ENABLE_PUSH, - H2SET_MAX_CONCURRENT_STREAMS, - H2SET_INITIAL_WINDOW_SIZE, - H2SET_MAX_FRAME_SIZE, - H2SET_MAX_HEADER_LIST_SIZE, - H2SET_RESERVED7, - H2SET_ENABLE_CONNECT_PROTOCOL, /* defined in mcmanus-httpbis-h2-ws-02 */ - - H2SET_COUNT /* always last */ -}; - -struct http2_settings { - uint32_t s[H2SET_COUNT]; -}; - -struct lws_vhost_role_h2 { - struct http2_settings set; -}; - -enum lws_h2_wellknown_frame_types { - LWS_H2_FRAME_TYPE_DATA, - LWS_H2_FRAME_TYPE_HEADERS, - LWS_H2_FRAME_TYPE_PRIORITY, - LWS_H2_FRAME_TYPE_RST_STREAM, - LWS_H2_FRAME_TYPE_SETTINGS, - LWS_H2_FRAME_TYPE_PUSH_PROMISE, - LWS_H2_FRAME_TYPE_PING, - LWS_H2_FRAME_TYPE_GOAWAY, - LWS_H2_FRAME_TYPE_WINDOW_UPDATE, - LWS_H2_FRAME_TYPE_CONTINUATION, - - LWS_H2_FRAME_TYPE_COUNT /* always last */ -}; - -enum lws_h2_flags { - LWS_H2_FLAG_END_STREAM = 1, - LWS_H2_FLAG_END_HEADERS = 4, - LWS_H2_FLAG_PADDED = 8, - LWS_H2_FLAG_PRIORITY = 0x20, - - LWS_H2_FLAG_SETTINGS_ACK = 1, -}; - -enum lws_h2_errors { - H2_ERR_NO_ERROR, /* Graceful shutdown */ - H2_ERR_PROTOCOL_ERROR, /* Protocol error detected */ - H2_ERR_INTERNAL_ERROR, /* Implementation fault */ - H2_ERR_FLOW_CONTROL_ERROR, /* Flow-control limits exceeded */ - H2_ERR_SETTINGS_TIMEOUT, /* Settings not acknowledged */ - H2_ERR_STREAM_CLOSED, /* Frame received for closed stream */ - H2_ERR_FRAME_SIZE_ERROR, /* Frame size incorrect */ - H2_ERR_REFUSED_STREAM, /* Stream not processed */ - H2_ERR_CANCEL, /* Stream cancelled */ - H2_ERR_COMPRESSION_ERROR, /* Compression state not updated */ - H2_ERR_CONNECT_ERROR, /* TCP connection error for CONNECT method */ - H2_ERR_ENHANCE_YOUR_CALM, /* Processing capacity exceeded */ - H2_ERR_INADEQUATE_SECURITY, /* Negotiated TLS parameters not acceptable */ - H2_ERR_HTTP_1_1_REQUIRED, /* Use HTTP/1.1 for the request */ -}; - -enum lws_h2_states { - LWS_H2_STATE_IDLE, - /* - * Send PUSH_PROMISE -> LWS_H2_STATE_RESERVED_LOCAL - * Recv PUSH_PROMISE -> LWS_H2_STATE_RESERVED_REMOTE - * Send HEADERS -> LWS_H2_STATE_OPEN - * Recv HEADERS -> LWS_H2_STATE_OPEN - * - * - Only PUSH_PROMISE + HEADERS valid to send - * - Only HEADERS or PRIORITY valid to receive - */ - LWS_H2_STATE_RESERVED_LOCAL, - /* - * Send RST_STREAM -> LWS_H2_STATE_CLOSED - * Recv RST_STREAM -> LWS_H2_STATE_CLOSED - * Send HEADERS -> LWS_H2_STATE_HALF_CLOSED_REMOTE - * - * - Only HEADERS, RST_STREAM, or PRIORITY valid to send - * - Only RST_STREAM, PRIORITY, or WINDOW_UPDATE valid to receive - */ - LWS_H2_STATE_RESERVED_REMOTE, - /* - * Send RST_STREAM -> LWS_H2_STATE_CLOSED - * Recv RST_STREAM -> LWS_H2_STATE_CLOSED - * Recv HEADERS -> LWS_H2_STATE_HALF_CLOSED_LOCAL - * - * - Only RST_STREAM, WINDOW_UPDATE, or PRIORITY valid to send - * - Only HEADERS, RST_STREAM, or PRIORITY valid to receive - */ - LWS_H2_STATE_OPEN, - /* - * Send RST_STREAM -> LWS_H2_STATE_CLOSED - * Recv RST_STREAM -> LWS_H2_STATE_CLOSED - * Send END_STREAM flag -> LWS_H2_STATE_HALF_CLOSED_LOCAL - * Recv END_STREAM flag -> LWS_H2_STATE_HALF_CLOSED_REMOTE - */ - LWS_H2_STATE_HALF_CLOSED_REMOTE, - /* - * Send RST_STREAM -> LWS_H2_STATE_CLOSED - * Recv RST_STREAM -> LWS_H2_STATE_CLOSED - * Send END_STREAM flag -> LWS_H2_STATE_CLOSED - * - * - Any frame valid to send - * - Only WINDOW_UPDATE, PRIORITY, or RST_STREAM valid to receive - */ - LWS_H2_STATE_HALF_CLOSED_LOCAL, - /* - * Send RST_STREAM -> LWS_H2_STATE_CLOSED - * Recv RST_STREAM -> LWS_H2_STATE_CLOSED - * Recv END_STREAM flag -> LWS_H2_STATE_CLOSED - * - * - Only WINDOW_UPDATE, PRIORITY, and RST_STREAM valid to send - * - Any frame valid to receive - */ - LWS_H2_STATE_CLOSED, - /* - * - Only PRIORITY, WINDOW_UPDATE (IGNORE) and RST_STREAM (IGNORE) - * may be received - * - * - Only PRIORITY valid to send - */ -}; - -void -lws_h2_state(struct lws *wsi, enum lws_h2_states s); - -#define LWS_H2_STREAM_ID_MASTER 0 -#define LWS_H2_SETTINGS_LEN 6 -#define LWS_H2_FLAG_SETTINGS_ACK 1 - -enum http2_hpack_state { - HPKS_TYPE, - - HPKS_IDX_EXT, - - HPKS_HLEN, - HPKS_HLEN_EXT, - - HPKS_DATA, -}; - -/* - * lws general parsimonious header strategy is only store values from known - * headers, and refer to them by index. - * - * That means if we can't map the peer header name to one that lws knows, we - * will drop the content but track the indexing with associated_lws_hdr_idx = - * LWS_HPACK_IGNORE_ENTRY. - */ - -enum http2_hpack_type { - HPKT_INDEXED_HDR_7, /* 1xxxxxxx: just "header field" */ - HPKT_INDEXED_HDR_6_VALUE_INCR, /* 01xxxxxx: NEW indexed hdr with value */ - HPKT_LITERAL_HDR_VALUE_INCR, /* 01000000: NEW literal hdr with value */ - HPKT_INDEXED_HDR_4_VALUE, /* 0000xxxx: indexed hdr with value */ - HPKT_INDEXED_HDR_4_VALUE_NEVER, /* 0001xxxx: indexed hdr with value NEVER NEW */ - HPKT_LITERAL_HDR_VALUE, /* 00000000: literal hdr with value */ - HPKT_LITERAL_HDR_VALUE_NEVER, /* 00010000: literal hdr with value NEVER NEW */ - HPKT_SIZE_5 -}; - -#define LWS_HPACK_IGNORE_ENTRY 0xffff - - -struct hpack_dt_entry { - char *value; /* malloc'd */ - uint16_t value_len; - uint16_t hdr_len; /* virtual, for accounting */ - uint16_t lws_hdr_idx; /* LWS_HPACK_IGNORE_ENTRY = IGNORE */ -}; - -struct hpack_dynamic_table { - struct hpack_dt_entry *entries; /* malloc'd */ - uint32_t virtual_payload_usage; - uint32_t virtual_payload_max; - uint16_t pos; - uint16_t used_entries; - uint16_t num_entries; -}; - -enum lws_h2_protocol_send_type { - LWS_PPS_NONE, - LWS_H2_PPS_MY_SETTINGS, - LWS_H2_PPS_ACK_SETTINGS, - LWS_H2_PPS_PONG, - LWS_H2_PPS_GOAWAY, - LWS_H2_PPS_RST_STREAM, - LWS_H2_PPS_UPDATE_WINDOW, -}; - -struct lws_h2_protocol_send { - struct lws_h2_protocol_send *next; /* linked list */ - enum lws_h2_protocol_send_type type; - - union uu { - struct { - char str[32]; - uint32_t highest_sid; - uint32_t err; - } ga; - struct { - uint32_t sid; - uint32_t err; - } rs; - struct { - uint8_t ping_payload[8]; - } ping; - struct { - uint32_t sid; - uint32_t credit; - } update_window; - } u; -}; - -struct lws_h2_ghost_sid { - struct lws_h2_ghost_sid *next; - uint32_t sid; -}; - -/* - * http/2 connection info that is only used by the root connection that has - * the network connection. - * - * h2 tends to spawn many child connections from one network connection, so - * it's necessary to make members only needed by the network connection - * distinct and only malloc'd on network connections. - * - * There's only one HPACK parser per network connection. - * - * But there is an ah per logical child connection... the network connection - * fills it but it belongs to the logical child. - */ -struct lws_h2_netconn { - struct http2_settings set; - struct hpack_dynamic_table hpack_dyn_table; - uint8_t ping_payload[8]; - uint8_t one_setting[LWS_H2_SETTINGS_LEN]; - char goaway_str[32]; /* for rx */ - struct lws *swsi; - struct lws_h2_protocol_send *pps; /* linked list */ - - enum http2_hpack_state hpack; - enum http2_hpack_type hpack_type; - - unsigned int huff:1; - unsigned int value:1; - unsigned int unknown_header:1; - unsigned int cont_exp:1; - unsigned int cont_exp_headers:1; - unsigned int we_told_goaway:1; - unsigned int pad_length:1; - unsigned int collected_priority:1; - unsigned int is_first_header_char:1; - unsigned int zero_huff_padding:1; - unsigned int last_action_dyntable_resize:1; - - uint32_t hdr_idx; - uint32_t hpack_len; - uint32_t hpack_e_dep; - uint32_t count; - uint32_t preamble; - uint32_t length; - uint32_t sid; - uint32_t inside; - uint32_t highest_sid; - uint32_t highest_sid_opened; - uint32_t cont_exp_sid; - uint32_t dep; - uint32_t goaway_last_sid; - uint32_t goaway_err; - uint32_t hpack_hdr_len; - - uint16_t hpack_pos; - - uint8_t frame_state; - uint8_t type; - uint8_t flags; - uint8_t padding; - uint8_t weight_temp; - uint8_t huff_pad; - char first_hdr_char; - uint8_t hpack_m; - uint8_t ext_count; -}; - -struct _lws_h2_related { - - struct lws_h2_netconn *h2n; /* malloc'd for root net conn */ - struct lws *parent_wsi; - struct lws *child_list; - struct lws *sibling_list; - - char *pending_status_body; - - int tx_cr; - int peer_tx_cr_est; - unsigned int my_sid; - unsigned int child_count; - int my_priority; - uint32_t dependent_on; - - unsigned int END_STREAM:1; - unsigned int END_HEADERS:1; - unsigned int send_END_STREAM:1; - unsigned int GOING_AWAY; - unsigned int requested_POLLOUT:1; - unsigned int skint:1; - - uint16_t round_robin_POLLOUT; - uint16_t count_POLLOUT_children; - - uint8_t h2_state; /* the RFC7540 state of the connection */ - uint8_t weight; - uint8_t initialized; -}; - -#define HTTP2_IS_TOPLEVEL_WSI(wsi) (!wsi->h2.parent_wsi) - -int -lws_h2_rst_stream(struct lws *wsi, uint32_t err, const char *reason); -struct lws * lws_h2_get_nth_child(struct lws *wsi, int n); -LWS_EXTERN void lws_h2_init(struct lws *wsi); -LWS_EXTERN int -lws_h2_settings(struct lws *nwsi, struct http2_settings *settings, - unsigned char *buf, int len); -LWS_EXTERN int -lws_h2_parser(struct lws *wsi, unsigned char *in, lws_filepos_t inlen, - lws_filepos_t *inused); -LWS_EXTERN int -lws_h2_do_pps_send(struct lws *wsi); -LWS_EXTERN int -lws_h2_frame_write(struct lws *wsi, int type, int flags, unsigned int sid, - unsigned int len, unsigned char *buf); -LWS_EXTERN struct lws * -lws_h2_wsi_from_id(struct lws *wsi, unsigned int sid); -LWS_EXTERN int -lws_hpack_interpret(struct lws *wsi, unsigned char c); -LWS_EXTERN int -lws_add_http2_header_by_name(struct lws *wsi, - const unsigned char *name, - const unsigned char *value, int length, - unsigned char **p, unsigned char *end); -LWS_EXTERN int -lws_add_http2_header_by_token(struct lws *wsi, - enum lws_token_indexes token, - const unsigned char *value, int length, - unsigned char **p, unsigned char *end); -LWS_EXTERN int -lws_add_http2_header_status(struct lws *wsi, - unsigned int code, unsigned char **p, - unsigned char *end); -LWS_EXTERN void -lws_hpack_destroy_dynamic_header(struct lws *wsi); -LWS_EXTERN int -lws_hpack_dynamic_size(struct lws *wsi, int size); -LWS_EXTERN int -lws_h2_goaway(struct lws *wsi, uint32_t err, const char *reason); -LWS_EXTERN int -lws_h2_tx_cr_get(struct lws *wsi); -LWS_EXTERN void -lws_h2_tx_cr_consume(struct lws *wsi, int consumed); -LWS_EXTERN int -lws_hdr_extant(struct lws *wsi, enum lws_token_indexes h); -LWS_EXTERN void -lws_pps_schedule(struct lws *wsi, struct lws_h2_protocol_send *pss); - -LWS_EXTERN const struct http2_settings lws_h2_defaults; -LWS_EXTERN int -lws_h2_ws_handshake(struct lws *wsi); -LWS_EXTERN int lws_h2_issue_preface(struct lws *wsi); -LWS_EXTERN int -lws_h2_client_handshake(struct lws *wsi); -LWS_EXTERN struct lws * -lws_wsi_h2_adopt(struct lws *parent_wsi, struct lws *wsi); -int -lws_handle_POLLOUT_event_h2(struct lws *wsi); -int -lws_read_h2(struct lws *wsi, unsigned char *buf, lws_filepos_t len); diff -Nru libwebsockets-3.2.1/lib/roles/h2/private-lib-roles-h2.h libwebsockets-4.1.6/lib/roles/h2/private-lib-roles-h2.h --- libwebsockets-3.2.1/lib/roles/h2/private-lib-roles-h2.h 1970-01-01 00:00:00.000000000 +0000 +++ libwebsockets-4.1.6/lib/roles/h2/private-lib-roles-h2.h 2020-12-01 17:40:26.000000000 +0000 @@ -0,0 +1,383 @@ +/* + * libwebsockets - small server side websockets and web server implementation + * + * Copyright (C) 2010 - 2019 Andy Green + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to + * deal in the Software without restriction, including without limitation the + * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or + * sell copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS + * IN THE SOFTWARE. + */ + +extern const struct lws_role_ops role_ops_h2; +#define lwsi_role_h2(wsi) (wsi->role_ops == &role_ops_h2) + +struct http2_settings { + uint32_t s[H2SET_COUNT]; +}; + +struct lws_vhost_role_h2 { + struct http2_settings set; +}; + +enum lws_h2_wellknown_frame_types { + LWS_H2_FRAME_TYPE_DATA, + LWS_H2_FRAME_TYPE_HEADERS, + LWS_H2_FRAME_TYPE_PRIORITY, + LWS_H2_FRAME_TYPE_RST_STREAM, + LWS_H2_FRAME_TYPE_SETTINGS, + LWS_H2_FRAME_TYPE_PUSH_PROMISE, + LWS_H2_FRAME_TYPE_PING, + LWS_H2_FRAME_TYPE_GOAWAY, + LWS_H2_FRAME_TYPE_WINDOW_UPDATE, + LWS_H2_FRAME_TYPE_CONTINUATION, + + LWS_H2_FRAME_TYPE_COUNT /* always last */ +}; + +enum lws_h2_flags { + LWS_H2_FLAG_END_STREAM = 1, + LWS_H2_FLAG_END_HEADERS = 4, + LWS_H2_FLAG_PADDED = 8, + LWS_H2_FLAG_PRIORITY = 0x20, + + LWS_H2_FLAG_SETTINGS_ACK = 1, +}; + +enum lws_h2_errors { + H2_ERR_NO_ERROR, /* Graceful shutdown */ + H2_ERR_PROTOCOL_ERROR, /* Protocol error detected */ + H2_ERR_INTERNAL_ERROR, /* Implementation fault */ + H2_ERR_FLOW_CONTROL_ERROR, /* Flow-control limits exceeded */ + H2_ERR_SETTINGS_TIMEOUT, /* Settings not acknowledged */ + H2_ERR_STREAM_CLOSED, /* Frame received for closed stream */ + H2_ERR_FRAME_SIZE_ERROR, /* Frame size incorrect */ + H2_ERR_REFUSED_STREAM, /* Stream not processed */ + H2_ERR_CANCEL, /* Stream cancelled */ + H2_ERR_COMPRESSION_ERROR, /* Compression state not updated */ + H2_ERR_CONNECT_ERROR, /* TCP connection error for CONNECT method */ + H2_ERR_ENHANCE_YOUR_CALM, /* Processing capacity exceeded */ + H2_ERR_INADEQUATE_SECURITY, /* Negotiated TLS parameters not acceptable */ + H2_ERR_HTTP_1_1_REQUIRED, /* Use HTTP/1.1 for the request */ +}; + +enum lws_h2_states { + LWS_H2_STATE_IDLE, + /* + * Send PUSH_PROMISE -> LWS_H2_STATE_RESERVED_LOCAL + * Recv PUSH_PROMISE -> LWS_H2_STATE_RESERVED_REMOTE + * Send HEADERS -> LWS_H2_STATE_OPEN + * Recv HEADERS -> LWS_H2_STATE_OPEN + * + * - Only PUSH_PROMISE + HEADERS valid to send + * - Only HEADERS or PRIORITY valid to receive + */ + LWS_H2_STATE_RESERVED_LOCAL, + /* + * Send RST_STREAM -> LWS_H2_STATE_CLOSED + * Recv RST_STREAM -> LWS_H2_STATE_CLOSED + * Send HEADERS -> LWS_H2_STATE_HALF_CLOSED_REMOTE + * + * - Only HEADERS, RST_STREAM, or PRIORITY valid to send + * - Only RST_STREAM, PRIORITY, or WINDOW_UPDATE valid to receive + */ + LWS_H2_STATE_RESERVED_REMOTE, + /* + * Send RST_STREAM -> LWS_H2_STATE_CLOSED + * Recv RST_STREAM -> LWS_H2_STATE_CLOSED + * Recv HEADERS -> LWS_H2_STATE_HALF_CLOSED_LOCAL + * + * - Only RST_STREAM, WINDOW_UPDATE, or PRIORITY valid to send + * - Only HEADERS, RST_STREAM, or PRIORITY valid to receive + */ + LWS_H2_STATE_OPEN, + /* + * Send RST_STREAM -> LWS_H2_STATE_CLOSED + * Recv RST_STREAM -> LWS_H2_STATE_CLOSED + * Send END_STREAM flag -> LWS_H2_STATE_HALF_CLOSED_LOCAL + * Recv END_STREAM flag -> LWS_H2_STATE_HALF_CLOSED_REMOTE + */ + LWS_H2_STATE_HALF_CLOSED_REMOTE, + /* + * Send RST_STREAM -> LWS_H2_STATE_CLOSED + * Recv RST_STREAM -> LWS_H2_STATE_CLOSED + * Send END_STREAM flag -> LWS_H2_STATE_CLOSED + * + * - Any frame valid to send + * - Only WINDOW_UPDATE, PRIORITY, or RST_STREAM valid to receive + */ + LWS_H2_STATE_HALF_CLOSED_LOCAL, + /* + * Send RST_STREAM -> LWS_H2_STATE_CLOSED + * Recv RST_STREAM -> LWS_H2_STATE_CLOSED + * Recv END_STREAM flag -> LWS_H2_STATE_CLOSED + * + * - Only WINDOW_UPDATE, PRIORITY, and RST_STREAM valid to send + * - Any frame valid to receive + */ + LWS_H2_STATE_CLOSED, + /* + * - Only PRIORITY, WINDOW_UPDATE (IGNORE) and RST_STREAM (IGNORE) + * may be received + * + * - Only PRIORITY valid to send + */ +}; + +void +lws_h2_state(struct lws *wsi, enum lws_h2_states s); + +#define LWS_H2_STREAM_ID_MASTER 0 +#define LWS_H2_SETTINGS_LEN 6 +#define LWS_H2_FLAG_SETTINGS_ACK 1 + +enum http2_hpack_state { + HPKS_TYPE, + + HPKS_IDX_EXT, + + HPKS_HLEN, + HPKS_HLEN_EXT, + + HPKS_DATA, +}; + +/* + * lws general parsimonious header strategy is only store values from known + * headers, and refer to them by index. + * + * That means if we can't map the peer header name to one that lws knows, we + * will drop the content but track the indexing with associated_lws_hdr_idx = + * LWS_HPACK_IGNORE_ENTRY. + */ + +enum http2_hpack_type { + HPKT_INDEXED_HDR_7, /* 1xxxxxxx: just "header field" */ + HPKT_INDEXED_HDR_6_VALUE_INCR, /* 01xxxxxx: NEW indexed hdr with value */ + HPKT_LITERAL_HDR_VALUE_INCR, /* 01000000: NEW literal hdr with value */ + HPKT_INDEXED_HDR_4_VALUE, /* 0000xxxx: indexed hdr with value */ + HPKT_INDEXED_HDR_4_VALUE_NEVER, /* 0001xxxx: indexed hdr with value NEVER NEW */ + HPKT_LITERAL_HDR_VALUE, /* 00000000: literal hdr with value */ + HPKT_LITERAL_HDR_VALUE_NEVER, /* 00010000: literal hdr with value NEVER NEW */ + HPKT_SIZE_5 +}; + +#define LWS_HPACK_IGNORE_ENTRY 0xffff + + +struct hpack_dt_entry { + char *value; /* malloc'd */ + uint16_t value_len; + uint16_t hdr_len; /* virtual, for accounting */ + uint16_t lws_hdr_idx; /* LWS_HPACK_IGNORE_ENTRY = IGNORE */ +}; + +struct hpack_dynamic_table { + struct hpack_dt_entry *entries; /* malloc'd */ + uint32_t virtual_payload_usage; + uint32_t virtual_payload_max; + uint16_t pos; + uint16_t used_entries; + uint16_t num_entries; +}; + +enum lws_h2_protocol_send_type { + LWS_PPS_NONE, + LWS_H2_PPS_MY_SETTINGS, + LWS_H2_PPS_ACK_SETTINGS, + LWS_H2_PPS_PING, + LWS_H2_PPS_PONG, + LWS_H2_PPS_GOAWAY, + LWS_H2_PPS_RST_STREAM, + LWS_H2_PPS_UPDATE_WINDOW, + LWS_H2_PPS_SETTINGS_INITIAL_UPDATE_WINDOW +}; + +struct lws_h2_protocol_send { + struct lws_h2_protocol_send *next; /* linked list */ + enum lws_h2_protocol_send_type type; + + union uu { + struct { + char str[32]; + uint32_t highest_sid; + uint32_t err; + } ga; + struct { + uint32_t sid; + uint32_t err; + } rs; + struct { + uint8_t ping_payload[8]; + } ping; + struct { + uint32_t sid; + uint32_t credit; + } update_window; + } u; +}; + +struct lws_h2_ghost_sid { + struct lws_h2_ghost_sid *next; + uint32_t sid; +}; + +/* + * http/2 connection info that is only used by the root connection that has + * the network connection. + * + * h2 tends to spawn many child connections from one network connection, so + * it's necessary to make members only needed by the network connection + * distinct and only malloc'd on network connections. + * + * There's only one HPACK parser per network connection. + * + * But there is an ah per logical child connection... the network connection + * fills it but it belongs to the logical child. + */ +struct lws_h2_netconn { + struct http2_settings our_set; + struct http2_settings peer_set; + struct hpack_dynamic_table hpack_dyn_table; + uint8_t ping_payload[8]; + uint8_t one_setting[LWS_H2_SETTINGS_LEN]; + char goaway_str[32]; /* for rx */ + struct lws *swsi; + struct lws_h2_protocol_send *pps; /* linked list */ + + enum http2_hpack_state hpack; + enum http2_hpack_type hpack_type; + + unsigned int huff:1; + unsigned int value:1; + unsigned int unknown_header:1; + unsigned int cont_exp:1; + unsigned int cont_exp_headers:1; + unsigned int we_told_goaway:1; + unsigned int pad_length:1; + unsigned int collected_priority:1; + unsigned int is_first_header_char:1; + unsigned int zero_huff_padding:1; + unsigned int last_action_dyntable_resize:1; + + uint32_t hdr_idx; + uint32_t hpack_len; + uint32_t hpack_e_dep; + uint32_t count; + uint32_t preamble; + uint32_t length; + uint32_t sid; + uint32_t inside; + uint32_t highest_sid; + uint32_t highest_sid_opened; + uint32_t cont_exp_sid; + uint32_t dep; + uint32_t goaway_last_sid; + uint32_t goaway_err; + uint32_t hpack_hdr_len; + + uint16_t hpack_pos; + + uint8_t frame_state; + uint8_t type; + uint8_t flags; + uint8_t padding; + uint8_t weight_temp; + uint8_t huff_pad; + char first_hdr_char; + uint8_t hpack_m; + uint8_t ext_count; +}; + +struct _lws_h2_related { + + struct lws_h2_netconn *h2n; /* malloc'd for root net conn */ + + char *pending_status_body; + + uint8_t h2_state; /* RFC7540 state of the connection */ + + uint8_t END_STREAM:1; + uint8_t END_HEADERS:1; + uint8_t send_END_STREAM:1; + uint8_t long_poll:1; + uint8_t initialized:1; +}; + +#define HTTP2_IS_TOPLEVEL_WSI(wsi) (!wsi->mux.parent_wsi) + +int +lws_h2_rst_stream(struct lws *wsi, uint32_t err, const char *reason); +struct lws * lws_h2_get_nth_child(struct lws *wsi, int n); +LWS_EXTERN void lws_h2_init(struct lws *wsi); +LWS_EXTERN int +lws_h2_settings(struct lws *nwsi, struct http2_settings *settings, + unsigned char *buf, int len); +LWS_EXTERN int +lws_h2_parser(struct lws *wsi, unsigned char *in, lws_filepos_t inlen, + lws_filepos_t *inused); +LWS_EXTERN int +lws_h2_do_pps_send(struct lws *wsi); +LWS_EXTERN int +lws_h2_frame_write(struct lws *wsi, int type, int flags, unsigned int sid, + unsigned int len, unsigned char *buf); +LWS_EXTERN struct lws * +lws_wsi_mux_from_id(struct lws *wsi, unsigned int sid); +LWS_EXTERN int +lws_hpack_interpret(struct lws *wsi, unsigned char c); +LWS_EXTERN int +lws_add_http2_header_by_name(struct lws *wsi, + const unsigned char *name, + const unsigned char *value, int length, + unsigned char **p, unsigned char *end); +LWS_EXTERN int +lws_add_http2_header_by_token(struct lws *wsi, + enum lws_token_indexes token, + const unsigned char *value, int length, + unsigned char **p, unsigned char *end); +LWS_EXTERN int +lws_add_http2_header_status(struct lws *wsi, + unsigned int code, unsigned char **p, + unsigned char *end); +LWS_EXTERN void +lws_hpack_destroy_dynamic_header(struct lws *wsi); +LWS_EXTERN int +lws_hpack_dynamic_size(struct lws *wsi, int size); +LWS_EXTERN int +lws_h2_goaway(struct lws *wsi, uint32_t err, const char *reason); +LWS_EXTERN int +lws_h2_tx_cr_get(struct lws *wsi); +LWS_EXTERN void +lws_h2_tx_cr_consume(struct lws *wsi, int consumed); +LWS_EXTERN int +lws_hdr_extant(struct lws *wsi, enum lws_token_indexes h); +LWS_EXTERN void +lws_pps_schedule(struct lws *wsi, struct lws_h2_protocol_send *pss); + +LWS_EXTERN const struct http2_settings lws_h2_defaults; +LWS_EXTERN int +lws_h2_ws_handshake(struct lws *wsi); +LWS_EXTERN int lws_h2_issue_preface(struct lws *wsi); +LWS_EXTERN int +lws_h2_client_handshake(struct lws *wsi); +LWS_EXTERN struct lws * +lws_wsi_h2_adopt(struct lws *parent_wsi, struct lws *wsi); +int +lws_handle_POLLOUT_event_h2(struct lws *wsi); +int +lws_read_h2(struct lws *wsi, unsigned char *buf, lws_filepos_t len); +struct lws_h2_protocol_send * +lws_h2_new_pps(enum lws_h2_protocol_send_type type); diff -Nru libwebsockets-3.2.1/lib/roles/http/client/client.c libwebsockets-4.1.6/lib/roles/http/client/client.c --- libwebsockets-3.2.1/lib/roles/http/client/client.c 2019-12-18 14:45:31.000000000 +0000 +++ libwebsockets-4.1.6/lib/roles/http/client/client.c 1970-01-01 00:00:00.000000000 +0000 @@ -1,1337 +0,0 @@ -/* - * libwebsockets - lib/client/client.c - * - * Copyright (C) 2010-2018 Andy Green - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation: - * version 2.1 of the License. - * - * This library is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with this library; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, - * MA 02110-1301 USA - */ - -#include "core/private.h" - -LWS_VISIBLE LWS_EXTERN void -lws_client_http_body_pending(struct lws *wsi, int something_left_to_send) -{ - wsi->client_http_body_pending = !!something_left_to_send; -} - -/* - * return self, or queued client wsi we are acting on behalf of - * - * That is the TAIL of the queue (new queue elements are added at the HEAD) - */ - -struct lws * -lws_client_wsi_effective(struct lws *wsi) -{ - struct lws_dll2 *tail = lws_dll2_get_tail(&wsi->dll2_cli_txn_queue_owner); - - if (!wsi->transaction_from_pipeline_queue || !tail) - return wsi; - - return lws_container_of(tail, struct lws, dll2_cli_txn_queue); -} - -/* - * return self or the guy we are queued under - * - * REQUIRES VHOST LOCK HELD - */ - -static struct lws * -_lws_client_wsi_master(struct lws *wsi) -{ - struct lws_dll2_owner *o = wsi->dll2_cli_txn_queue.owner; - - if (!o) - return wsi; - - return lws_container_of(o, struct lws, dll2_cli_txn_queue_owner); -} - -int -lws_client_socket_service(struct lws *wsi, struct lws_pollfd *pollfd, - struct lws *wsi_conn) -{ - struct lws_context *context = wsi->context; - struct lws_context_per_thread *pt = &context->pt[(int)wsi->tsi]; - char *p = (char *)&pt->serv_buf[0]; - struct lws *w; -#if defined(LWS_WITH_TLS) - char ebuf[128]; -#endif - const char *cce = NULL; -#if defined(LWS_ROLE_H1) || defined(LWS_ROLE_H2) - ssize_t len = 0; - unsigned char c; -#endif - char *sb = p; - int n = 0; -#if defined(LWS_WITH_SOCKS5) - int conn_mode = 0, pending_timeout = 0; -#endif - - if ((pollfd->revents & LWS_POLLOUT) && - wsi->keepalive_active && - wsi->dll2_cli_txn_queue_owner.head) { - struct lws *wfound = NULL; - - lwsl_debug("%s: pollout HANDSHAKE2\n", __func__); - - /* - * We have a transaction queued that wants to pipeline. - * - * We have to allow it to send headers strictly in the order - * that it was queued, ie, tail-first. - */ - lws_vhost_lock(wsi->vhost); - lws_start_foreach_dll_safe(struct lws_dll2 *, d, d1, - wsi->dll2_cli_txn_queue_owner.head) { - struct lws *w = lws_container_of(d, struct lws, - dll2_cli_txn_queue); - - lwsl_debug("%s: %p states 0x%lx\n", __func__, w, - (unsigned long)w->wsistate); - if (lwsi_state(w) == LRS_H1C_ISSUE_HANDSHAKE2) - wfound = w; - } lws_end_foreach_dll_safe(d, d1); - - if (wfound) { - /* - * pollfd has the master sockfd in it... we - * need to use that in HANDSHAKE2 to understand - * which wsi to actually write on - */ - if (lws_client_socket_service(wfound, pollfd, wsi) < 0) { - /* closed */ - - lws_vhost_unlock(wsi->vhost); - - return -1; - } - - lws_callback_on_writable(wsi); - } else - lwsl_debug("%s: didn't find anything in txn q in HS2\n", - __func__); - - lws_vhost_unlock(wsi->vhost); - - return 0; - } - - switch (lwsi_state(wsi)) { - - case LRS_WAITING_CONNECT: - - /* - * we are under PENDING_TIMEOUT_SENT_CLIENT_HANDSHAKE - * timeout protection set in client-handshake.c - */ - - if (!lws_client_connect_2(wsi)) { - /* closed */ - lwsl_client("closed\n"); - return -1; - } - - /* either still pending connection, or changed mode */ - return 0; - -#if defined(LWS_WITH_SOCKS5) - /* SOCKS Greeting Reply */ - case LRS_WAITING_SOCKS_GREETING_REPLY: - case LRS_WAITING_SOCKS_AUTH_REPLY: - case LRS_WAITING_SOCKS_CONNECT_REPLY: - - /* handle proxy hung up on us */ - - if (pollfd->revents & LWS_POLLHUP) { - lwsl_warn("SOCKS connection %p (fd=%d) dead\n", - (void *)wsi, pollfd->fd); - cce = "socks conn dead"; - goto bail3; - } - - n = recv(wsi->desc.sockfd, sb, context->pt_serv_buf_size, 0); - if (n < 0) { - if (LWS_ERRNO == LWS_EAGAIN) { - lwsl_debug("SOCKS read EAGAIN, retrying\n"); - return 0; - } - lwsl_err("ERROR reading from SOCKS socket\n"); - cce = "socks recv fail"; - goto bail3; - } - - switch (lwsi_state(wsi)) { - - case LRS_WAITING_SOCKS_GREETING_REPLY: - if (pt->serv_buf[0] != SOCKS_VERSION_5) - goto socks_reply_fail; - - if (pt->serv_buf[1] == SOCKS_AUTH_NO_AUTH) { - lwsl_client("SOCKS GR: No Auth Method\n"); - if (socks_generate_msg(wsi, SOCKS_MSG_CONNECT, &len)) - goto socks_send_msg_fail; - conn_mode = LRS_WAITING_SOCKS_CONNECT_REPLY; - pending_timeout = - PENDING_TIMEOUT_AWAITING_SOCKS_CONNECT_REPLY; - goto socks_send; - } - - if (pt->serv_buf[1] == SOCKS_AUTH_USERNAME_PASSWORD) { - lwsl_client("SOCKS GR: User/Pw Method\n"); - if (socks_generate_msg(wsi, - SOCKS_MSG_USERNAME_PASSWORD, - &len)) - goto socks_send_msg_fail; - conn_mode = LRS_WAITING_SOCKS_AUTH_REPLY; - pending_timeout = - PENDING_TIMEOUT_AWAITING_SOCKS_AUTH_REPLY; - goto socks_send; - } - goto socks_reply_fail; - - case LRS_WAITING_SOCKS_AUTH_REPLY: - if (pt->serv_buf[0] != SOCKS_SUBNEGOTIATION_VERSION_1 || - pt->serv_buf[1] != - SOCKS_SUBNEGOTIATION_STATUS_SUCCESS) - goto socks_reply_fail; - - lwsl_client("SOCKS password OK, sending connect\n"); - if (socks_generate_msg(wsi, SOCKS_MSG_CONNECT, &len)) { -socks_send_msg_fail: - cce = "socks gen msg fail"; - goto bail3; - } - conn_mode = LRS_WAITING_SOCKS_CONNECT_REPLY; - pending_timeout = - PENDING_TIMEOUT_AWAITING_SOCKS_CONNECT_REPLY; -socks_send: - n = send(wsi->desc.sockfd, (char *)pt->serv_buf, len, - MSG_NOSIGNAL); - if (n < 0) { - lwsl_debug("ERROR writing to socks proxy\n"); - cce = "socks write fail"; - goto bail3; - } - - lws_set_timeout(wsi, pending_timeout, AWAITING_TIMEOUT); - lwsi_set_state(wsi, conn_mode); - break; - -socks_reply_fail: - lwsl_notice("socks reply: v%d, err %d\n", - pt->serv_buf[0], pt->serv_buf[1]); - cce = "socks reply fail"; - goto bail3; - - case LRS_WAITING_SOCKS_CONNECT_REPLY: - if (pt->serv_buf[0] != SOCKS_VERSION_5 || - pt->serv_buf[1] != SOCKS_REQUEST_REPLY_SUCCESS) - goto socks_reply_fail; - - lwsl_client("socks connect OK\n"); - - /* free stash since we are done with it */ - lws_client_stash_destroy(wsi); - if (lws_hdr_simple_create(wsi, - _WSI_TOKEN_CLIENT_PEER_ADDRESS, - wsi->vhost->socks_proxy_address)) { - cce = "socks connect fail"; - goto bail3; - } - - wsi->c_port = wsi->vhost->socks_proxy_port; - - /* clear his proxy connection timeout */ - lws_set_timeout(wsi, NO_PENDING_TIMEOUT, 0); - goto start_ws_handshake; - default: - break; - } - break; -#endif - - case LRS_WAITING_PROXY_REPLY: - - /* handle proxy hung up on us */ - - if (pollfd->revents & LWS_POLLHUP) { - - lwsl_warn("Proxy connection %p (fd=%d) dead\n", - (void *)wsi, pollfd->fd); - - cce = "proxy conn dead"; - goto bail3; - } - - n = recv(wsi->desc.sockfd, sb, context->pt_serv_buf_size, 0); - if (n < 0) { - if (LWS_ERRNO == LWS_EAGAIN) { - lwsl_debug("Proxy read EAGAIN... retrying\n"); - return 0; - } - lwsl_err("ERROR reading from proxy socket\n"); - cce = "proxy read err"; - goto bail3; - } - - pt->serv_buf[13] = '\0'; - if (n < 13 || (strncmp(sb, "HTTP/1.0 200 ", 13) && - strncmp(sb, "HTTP/1.1 200 ", 13))) { - lwsl_err("%s: ERROR proxy did not reply with h1\n", - __func__); - /* lwsl_hexdump_notice(sb, n); */ - cce = "proxy not h1"; - goto bail3; - } - - lwsl_info("%s: proxy connection extablished\n", __func__); - - /* clear his proxy connection timeout */ - - lws_set_timeout(wsi, NO_PENDING_TIMEOUT, 0); - - /* fallthru */ - - case LRS_H1C_ISSUE_HANDSHAKE: - - /* - * we are under PENDING_TIMEOUT_SENT_CLIENT_HANDSHAKE - * timeout protection set in client-handshake.c - * - * take care of our lws_callback_on_writable - * happening at a time when there's no real connection yet - */ -#if defined(LWS_WITH_SOCKS5) -start_ws_handshake: -#endif - if (lws_change_pollfd(wsi, LWS_POLLOUT, 0)) - return -1; - -#if defined(LWS_WITH_TLS) - /* we can retry this... just cook the SSL BIO the first time */ - - if ((wsi->tls.use_ssl & LCCSCF_USE_SSL) && !wsi->tls.ssl && - lws_ssl_client_bio_create(wsi) < 0) { - cce = "bio_create failed"; - goto bail3; - } - - if (wsi->tls.use_ssl & LCCSCF_USE_SSL) { - n = lws_ssl_client_connect1(wsi); - if (!n) - return 0; - if (n < 0) { - cce = "lws_ssl_client_connect1 failed"; - goto bail3; - } - } else - wsi->tls.ssl = NULL; - - /* fallthru */ - - case LRS_WAITING_SSL: - - if (wsi->tls.use_ssl & LCCSCF_USE_SSL) { - n = lws_ssl_client_connect2(wsi, ebuf, sizeof(ebuf)); - if (!n) - return 0; - if (n < 0) { - cce = ebuf; - goto bail3; - } - } else - wsi->tls.ssl = NULL; -#endif -#if defined (LWS_WITH_HTTP2) - if (wsi->client_h2_alpn) { - /* - * We connected to the server and set up tls, and - * negotiated "h2". - * - * So this is it, we are an h2 master client connection - * now, not an h1 client connection. - */ -#if defined (LWS_WITH_TLS) - lws_tls_server_conn_alpn(wsi); -#endif - - /* send the H2 preface to legitimize the connection */ - if (lws_h2_issue_preface(wsi)) { - cce = "error sending h2 preface"; - goto bail3; - } - - break; - } -#endif - lwsi_set_state(wsi, LRS_H1C_ISSUE_HANDSHAKE2); - lws_set_timeout(wsi, PENDING_TIMEOUT_AWAITING_CLIENT_HS_SEND, - context->timeout_secs); - - /* fallthru */ - - case LRS_H1C_ISSUE_HANDSHAKE2: - p = lws_generate_client_handshake(wsi, p); - if (p == NULL) { - if (wsi->role_ops == &role_ops_raw_skt || - wsi->role_ops == &role_ops_raw_file) - return 0; - - lwsl_err("Failed to generate handshake for client\n"); - lws_close_free_wsi(wsi, LWS_CLOSE_STATUS_NOSTATUS, - "chs"); - return 0; - } - - /* send our request to the server */ - lws_latency_pre(context, wsi); - - w = _lws_client_wsi_master(wsi); - lwsl_info("%s: HANDSHAKE2: %p: sending headers on %p " - "(wsistate 0x%lx 0x%lx), w sock %d, wsi sock %d\n", - __func__, wsi, w, (unsigned long)wsi->wsistate, - (unsigned long)w->wsistate, w->desc.sockfd, - wsi->desc.sockfd); - - n = lws_ssl_capable_write(w, (unsigned char *)sb, (int)(p - sb)); - lws_latency(context, wsi, "send lws_issue_raw", n, - n == p - sb); - switch (n) { - case LWS_SSL_CAPABLE_ERROR: - lwsl_debug("ERROR writing to client socket\n"); - lws_close_free_wsi(wsi, LWS_CLOSE_STATUS_NOSTATUS, - "cws"); - return 0; - case LWS_SSL_CAPABLE_MORE_SERVICE: - lws_callback_on_writable(wsi); - break; - } - - if (wsi->client_http_body_pending) { - lwsl_debug("body pending\n"); - lwsi_set_state(wsi, LRS_ISSUE_HTTP_BODY); - lws_set_timeout(wsi, - PENDING_TIMEOUT_CLIENT_ISSUE_PAYLOAD, - context->timeout_secs); -#if defined(LWS_WITH_HTTP_PROXY) - if (wsi->http.proxy_clientside) - lws_callback_on_writable(wsi); -#endif - /* user code must ask for writable callback */ - break; - } - - lwsi_set_state(wsi, LRS_WAITING_SERVER_REPLY); - wsi->hdr_parsing_completed = 0; - - if (lwsi_state(w) == LRS_IDLING) { - lwsi_set_state(w, LRS_WAITING_SERVER_REPLY); - w->hdr_parsing_completed = 0; -#if defined(LWS_ROLE_H1) || defined(LWS_ROLE_H2) - w->http.ah->parser_state = WSI_TOKEN_NAME_PART; - w->http.ah->lextable_pos = 0; -#if defined(LWS_WITH_CUSTOM_HEADERS) - w->http.ah->unk_pos = 0; -#endif - /* If we're (re)starting on hdr, need other implied init */ - wsi->http.ah->ues = URIES_IDLE; -#endif - } - - lws_set_timeout(wsi, PENDING_TIMEOUT_AWAITING_SERVER_RESPONSE, - wsi->context->timeout_secs); - - lws_callback_on_writable(w); - - goto client_http_body_sent; - - case LRS_ISSUE_HTTP_BODY: -#if defined(LWS_WITH_HTTP_PROXY) - if (wsi->http.proxy_clientside) { - lws_callback_on_writable(wsi); - break; - } -#endif - if (wsi->client_http_body_pending) { - //lws_set_timeout(wsi, - // PENDING_TIMEOUT_CLIENT_ISSUE_PAYLOAD, - // context->timeout_secs); - /* user code must ask for writable callback */ - break; - } -client_http_body_sent: -#if defined(LWS_ROLE_H1) || defined(LWS_ROLE_H2) - /* prepare ourselves to do the parsing */ - wsi->http.ah->parser_state = WSI_TOKEN_NAME_PART; - wsi->http.ah->lextable_pos = 0; -#if defined(LWS_WITH_CUSTOM_HEADERS) - wsi->http.ah->unk_pos = 0; -#endif -#endif - lwsi_set_state(wsi, LRS_WAITING_SERVER_REPLY); - lws_set_timeout(wsi, PENDING_TIMEOUT_AWAITING_SERVER_RESPONSE, - context->timeout_secs); - break; - - case LRS_WAITING_SERVER_REPLY: - /* - * handle server hanging up on us... - * but if there is POLLIN waiting, handle that first - */ - if ((pollfd->revents & (LWS_POLLIN | LWS_POLLHUP)) == - LWS_POLLHUP) { - - lwsl_debug("Server connection %p (fd=%d) dead\n", - (void *)wsi, pollfd->fd); - cce = "Peer hung up"; - goto bail3; - } - - if (!(pollfd->revents & LWS_POLLIN)) - break; - -#if defined(LWS_ROLE_H1) || defined(LWS_ROLE_H2) - /* interpret the server response - * - * HTTP/1.1 101 Switching Protocols - * Upgrade: websocket - * Connection: Upgrade - * Sec-WebSocket-Accept: me89jWimTRKTWwrS3aRrL53YZSo= - * Sec-WebSocket-Nonce: AQIDBAUGBwgJCgsMDQ4PEC== - * Sec-WebSocket-Protocol: chat - * - * we have to take some care here to only take from the - * socket bytewise. The browser may (and has been seen to - * in the case that onopen() performs websocket traffic) - * coalesce both handshake response and websocket traffic - * in one packet, since at that point the connection is - * definitively ready from browser pov. - */ - len = 1; - while (wsi->http.ah->parser_state != WSI_PARSING_COMPLETE && - len > 0) { - int plen = 1; - - n = lws_ssl_capable_read(wsi, &c, 1); - lws_latency(context, wsi, "send lws_issue_raw", n, - n == 1); - switch (n) { - case 0: - case LWS_SSL_CAPABLE_ERROR: - cce = "read failed"; - goto bail3; - case LWS_SSL_CAPABLE_MORE_SERVICE: - return 0; - } - - if (lws_parse(wsi, &c, &plen)) { - lwsl_warn("problems parsing header\n"); - cce = "problems parsing header"; - goto bail3; - } - } - - /* - * hs may also be coming in multiple packets, there is a 5-sec - * libwebsocket timeout still active here too, so if parsing did - * not complete just wait for next packet coming in this state - */ - if (wsi->http.ah->parser_state != WSI_PARSING_COMPLETE) - break; - -#endif - - /* - * otherwise deal with the handshake. If there's any - * packet traffic already arrived we'll trigger poll() again - * right away and deal with it that way - */ - return lws_client_interpret_server_handshake(wsi); - -bail3: - lwsl_info("closing conn at LWS_CONNMODE...SERVER_REPLY\n"); - if (cce) - lwsl_info("reason: %s\n", cce); - lws_inform_client_conn_fail(wsi, (void *)cce, strlen(cce)); - - lws_close_free_wsi(wsi, LWS_CLOSE_STATUS_NOSTATUS, "cbail3"); - return -1; - - default: - break; - } - - return 0; -} - -#if defined(LWS_ROLE_H1) || defined(LWS_ROLE_H2) - -int LWS_WARN_UNUSED_RESULT -lws_http_transaction_completed_client(struct lws *wsi) -{ - struct lws *wsi_eff = lws_client_wsi_effective(wsi); - - lwsl_info("%s: wsi: %p, wsi_eff: %p (%s)\n", __func__, wsi, wsi_eff, - wsi_eff->protocol->name); - - if (user_callback_handle_rxflow(wsi_eff->protocol->callback, wsi_eff, - LWS_CALLBACK_COMPLETED_CLIENT_HTTP, - wsi_eff->user_space, NULL, 0)) { - lwsl_debug("%s: Completed call returned nonzero (role 0x%lx)\n", - __func__, (unsigned long)lwsi_role(wsi_eff)); - return -1; - } - - /* - * Are we constitutionally capable of having a queue, ie, we are on - * the "active client connections" list? - * - * If not, that's it for us. - */ - - if (lws_dll2_is_detached(&wsi->dll_cli_active_conns)) - return -1; - - /* if this was a queued guy, close him and remove from queue */ - - if (wsi->transaction_from_pipeline_queue) { - lwsl_debug("closing queued wsi %p\n", wsi_eff); - /* so the close doesn't trigger a CCE */ - wsi_eff->already_did_cce = 1; - __lws_close_free_wsi(wsi_eff, - LWS_CLOSE_STATUS_CLIENT_TRANSACTION_DONE, - "queued client done"); - } - - _lws_header_table_reset(wsi->http.ah); - - /* after the first one, they can only be coming from the queue */ - wsi->transaction_from_pipeline_queue = 1; - - wsi->http.rx_content_length = 0; - wsi->hdr_parsing_completed = 0; - - /* is there a new tail after removing that one? */ - wsi_eff = lws_client_wsi_effective(wsi); - - /* - * Do we have something pipelined waiting? - * it's OK if he hasn't managed to send his headers yet... he's next - * in line to do that... - */ - if (wsi_eff == wsi) { - /* - * Nothing pipelined... we should hang around a bit - * in case something turns up... - */ - lwsl_info("%s: nothing pipelined waiting\n", __func__); - lwsi_set_state(wsi, LRS_IDLING); - - lws_set_timeout(wsi, PENDING_TIMEOUT_CLIENT_CONN_IDLE, 5); - - return 0; - } - - /* - * H1: we can serialize the queued guys into the same ah - * H2: everybody needs their own ah until their own STREAM_END - */ - - /* otherwise set ourselves up ready to go again */ - lwsi_set_state(wsi, LRS_WAITING_SERVER_REPLY); - - wsi->http.ah->parser_state = WSI_TOKEN_NAME_PART; - wsi->http.ah->lextable_pos = 0; -#if defined(LWS_WITH_CUSTOM_HEADERS) - wsi->http.ah->unk_pos = 0; -#endif - - lws_set_timeout(wsi, PENDING_TIMEOUT_AWAITING_SERVER_RESPONSE, - wsi->context->timeout_secs); - - /* If we're (re)starting on headers, need other implied init */ - wsi->http.ah->ues = URIES_IDLE; - - lwsl_info("%s: %p: new queued transaction as %p\n", __func__, wsi, - wsi_eff); - lws_callback_on_writable(wsi); - - return 0; -} - -LWS_VISIBLE LWS_EXTERN unsigned int -lws_http_client_http_response(struct lws *_wsi) -{ - struct lws *wsi; - unsigned int resp; - - if (_wsi->http.ah && _wsi->http.ah->http_response) - return _wsi->http.ah->http_response; - - lws_vhost_lock(_wsi->vhost); - wsi = _lws_client_wsi_master(_wsi); - resp = wsi->http.ah->http_response; - lws_vhost_unlock(_wsi->vhost); - - return resp; -} -#endif - -#if defined(LWS_ROLE_H1) || defined(LWS_ROLE_H2) -int -lws_client_interpret_server_handshake(struct lws *wsi) -{ - int n, port = 0, ssl = 0; - int close_reason = LWS_CLOSE_STATUS_PROTOCOL_ERR; - const char *prot, *ads = NULL, *path, *cce = NULL; - struct allocated_headers *ah; - struct lws *w = lws_client_wsi_effective(wsi); - char *p, *q; - char new_path[300]; - - lws_client_stash_destroy(wsi); - - ah = wsi->http.ah; - if (!wsi->do_ws) { - /* we are being an http client... - */ -#if defined(LWS_ROLE_H2) - if (wsi->client_h2_alpn || wsi->client_h2_substream) { - lwsl_debug("%s: %p: transitioning to h2 client\n", - __func__, wsi); - lws_role_transition(wsi, LWSIFR_CLIENT, - LRS_ESTABLISHED, &role_ops_h2); - } else -#endif - { -#if defined(LWS_ROLE_H1) - { - lwsl_debug("%s: %p: transitioning to h1 client\n", - __func__, wsi); - lws_role_transition(wsi, LWSIFR_CLIENT, - LRS_ESTABLISHED, &role_ops_h1); - } -#else - return -1; -#endif - } - - wsi->http.ah = ah; - ah->http_response = 0; - } - - /* - * well, what the server sent looked reasonable for syntax. - * Now let's confirm it sent all the necessary headers - * - * http (non-ws) client will expect something like this - * - * HTTP/1.0.200 - * server:.libwebsockets - * content-type:.text/html - * content-length:.17703 - * set-cookie:.test=LWS_1456736240_336776_COOKIE;Max-Age=360000 - */ - - wsi->http.conn_type = HTTP_CONNECTION_KEEP_ALIVE; - if (!wsi->client_h2_substream) { - p = lws_hdr_simple_ptr(wsi, WSI_TOKEN_HTTP); - if (wsi->do_ws && !p) { - lwsl_info("no URI\n"); - cce = "HS: URI missing"; - goto bail3; - } - if (!p) { - p = lws_hdr_simple_ptr(wsi, WSI_TOKEN_HTTP1_0); - wsi->http.conn_type = HTTP_CONNECTION_CLOSE; - } - if (!p) { - cce = "HS: URI missing"; - lwsl_info("no URI\n"); - goto bail3; - } - } else { - p = lws_hdr_simple_ptr(wsi, WSI_TOKEN_HTTP_COLON_STATUS); - if (!p) { - cce = "HS: :status missing"; - lwsl_info("no status\n"); - goto bail3; - } - } - n = atoi(p); - if (ah) - ah->http_response = n; - - if ( -#if defined(LWS_WITH_HTTP_PROXY) - !wsi->http.proxy_clientside && -#endif - (n == 301 || n == 302 || n == 303 || n == 307 || n == 308)) { - p = lws_hdr_simple_ptr(wsi, WSI_TOKEN_HTTP_LOCATION); - if (!p) { - cce = "HS: Redirect code but no Location"; - goto bail3; - } - - /* Relative reference absolute path */ - if (p[0] == '/') { -#if defined(LWS_WITH_TLS) - ssl = wsi->tls.use_ssl & LCCSCF_USE_SSL; -#endif - ads = lws_hdr_simple_ptr(wsi, - _WSI_TOKEN_CLIENT_PEER_ADDRESS); - port = wsi->c_port; - /* +1 as lws_client_reset expects leading / omitted */ - path = p + 1; - } - /* Absolute (Full) URI */ - else if (strchr(p, ':')) { - if (lws_parse_uri(p, &prot, &ads, &port, &path)) { - cce = "HS: URI did not parse"; - goto bail3; - } - - if (!strcmp(prot, "wss") || !strcmp(prot, "https")) - ssl = 1; - } - /* Relative reference relative path */ - else { - /* This doesn't try to calculate an absolute path, - * that will be left to the server */ -#if defined(LWS_WITH_TLS) - ssl = wsi->tls.use_ssl & LCCSCF_USE_SSL; -#endif - ads = lws_hdr_simple_ptr(wsi, - _WSI_TOKEN_CLIENT_PEER_ADDRESS); - port = wsi->c_port; - /* +1 as lws_client_reset expects leading / omitted */ - path = new_path + 1; - if (lws_hdr_simple_ptr(wsi,_WSI_TOKEN_CLIENT_URI)) - lws_strncpy(new_path, lws_hdr_simple_ptr(wsi, - _WSI_TOKEN_CLIENT_URI), sizeof(new_path)); - else { - new_path[0] = '/'; - new_path[1] = '\0'; - } - q = strrchr(new_path, '/'); - if (q) - lws_strncpy(q + 1, p, sizeof(new_path) - - (q - new_path) - 1); - else - path = p; - } - -#if defined(LWS_WITH_TLS) - if ((wsi->tls.use_ssl & LCCSCF_USE_SSL) && !ssl) { - cce = "HS: Redirect attempted SSL downgrade"; - goto bail3; - } -#endif - - if (!ads) /* make coverity happy */ { - cce = "no ads"; - goto bail3; - } - - if (!lws_client_reset(&wsi, ssl, ads, port, path, ads)) { - /* there are two ways to fail out with NULL return... - * simple, early problem where the wsi is intact, or - * we went through with the reconnect attempt and the - * wsi is already closed. In the latter case, the wsi - * has beet set to NULL additionally. - */ - lwsl_err("Redirect failed\n"); - cce = "HS: Redirect failed"; - if (wsi) - goto bail3; - - return 1; - } - return 0; - } - - if (!wsi->do_ws) { - - /* if h1 KA is allowed, enable the queued pipeline guys */ - - if (!wsi->client_h2_alpn && !wsi->client_h2_substream && - w == wsi) { /* ie, coming to this for the first time */ - if (wsi->http.conn_type == HTTP_CONNECTION_KEEP_ALIVE) - wsi->keepalive_active = 1; - else { - /* - * Ugh... now the main http connection has seen - * both sides, we learn the server doesn't - * support keepalive. - * - * That means any guys queued on us are going - * to have to be restarted from connect2 with - * their own connections. - */ - - /* - * stick around telling any new guys they can't - * pipeline to this server - */ - wsi->keepalive_rejected = 1; - - lws_vhost_lock(wsi->vhost); - lws_start_foreach_dll_safe(struct lws_dll2 *, - d, d1, - wsi->dll2_cli_txn_queue_owner.head) { - struct lws *ww = lws_container_of(d, - struct lws, - dll2_cli_txn_queue); - - /* remove him from our queue */ - lws_dll2_remove(&ww->dll2_cli_txn_queue); - /* give up on pipelining */ - ww->client_pipeline = 0; - - /* go back to "trying to connect" state */ - lws_role_transition(ww, LWSIFR_CLIENT, - LRS_UNCONNECTED, -#if defined(LWS_ROLE_H1) - &role_ops_h1); -#else -#if defined (LWS_ROLE_H2) - &role_ops_h2); -#else - &role_ops_raw); -#endif -#endif - ww->user_space = NULL; - } lws_end_foreach_dll_safe(d, d1); - lws_vhost_unlock(wsi->vhost); - } - } - -#ifdef LWS_WITH_HTTP_PROXY - wsi->http.perform_rewrite = 0; - if (lws_hdr_total_length(wsi, WSI_TOKEN_HTTP_CONTENT_TYPE)) { - if (!strncmp(lws_hdr_simple_ptr(wsi, - WSI_TOKEN_HTTP_CONTENT_TYPE), - "text/html", 9)) - wsi->http.perform_rewrite = 0; - } -#endif - - /* allocate the per-connection user memory (if any) */ - if (lws_ensure_user_space(wsi)) { - lwsl_err("Problem allocating wsi user mem\n"); - cce = "HS: OOM"; - goto bail2; - } - - /* he may choose to send us stuff in chunked transfer-coding */ - wsi->chunked = 0; - wsi->chunk_remaining = 0; /* ie, next thing is chunk size */ - if (lws_hdr_total_length(wsi, - WSI_TOKEN_HTTP_TRANSFER_ENCODING)) { - wsi->chunked = !strcmp(lws_hdr_simple_ptr(wsi, - WSI_TOKEN_HTTP_TRANSFER_ENCODING), - "chunked"); - /* first thing is hex, after payload there is crlf */ - wsi->chunk_parser = ELCP_HEX; - } - - if (lws_hdr_total_length(wsi, WSI_TOKEN_HTTP_CONTENT_LENGTH)) { - wsi->http.rx_content_length = - atoll(lws_hdr_simple_ptr(wsi, - WSI_TOKEN_HTTP_CONTENT_LENGTH)); - lwsl_info("%s: incoming content length %llu\n", - __func__, (unsigned long long) - wsi->http.rx_content_length); - wsi->http.rx_content_remain = - wsi->http.rx_content_length; - } else /* can't do 1.1 without a content length or chunked */ - if (!wsi->chunked) - wsi->http.conn_type = HTTP_CONNECTION_CLOSE; - - /* - * we seem to be good to go, give client last chance to check - * headers and OK it - */ - if (w->protocol->callback(w, - LWS_CALLBACK_CLIENT_FILTER_PRE_ESTABLISH, - w->user_space, NULL, 0)) { - - cce = "HS: disallowed by client filter"; - goto bail2; - } - - /* clear his proxy connection timeout */ - lws_set_timeout(wsi, NO_PENDING_TIMEOUT, 0); - - wsi->rxflow_change_to = LWS_RXFLOW_ALLOW; - - /* call him back to inform him he is up */ - if (w->protocol->callback(w, - LWS_CALLBACK_ESTABLISHED_CLIENT_HTTP, - w->user_space, NULL, 0)) { - cce = "HS: disallowed at ESTABLISHED"; - goto bail3; - } - - /* - * for pipelining, master needs to keep his ah... guys who - * queued on him can drop it now though. - */ - - if (w != wsi) - /* free up parsing allocations for queued guy */ - lws_header_table_detach(w, 0); - - lwsl_info("%s: client connection up\n", __func__); - - /* - * Did we get a response from the server with an explicit - * content-length of zero? If so, this transaction is already - * completed at the end of the header processing... - */ - if (lws_hdr_total_length(wsi, WSI_TOKEN_HTTP_CONTENT_LENGTH) && - !wsi->http.rx_content_length) - return !!lws_http_transaction_completed_client(wsi); - - return 0; - } - -#if defined(LWS_ROLE_WS) - switch (lws_client_ws_upgrade(wsi, &cce)) { - case 2: - goto bail2; - case 3: - goto bail3; - } - - return 0; -#endif - -bail3: - close_reason = LWS_CLOSE_STATUS_NOSTATUS; - -bail2: - if (wsi->protocol) { - n = 0; - if (cce) - n = (int)strlen(cce); - - lws_inform_client_conn_fail(wsi, (void *)cce, (unsigned int)n); - } - - lwsl_info("closing connection (prot %s) " - "due to bail2 connection error: %s\n", wsi->protocol ? - wsi->protocol->name : "unknown", cce); - - /* closing will free up his parsing allocations */ - lws_close_free_wsi(wsi, close_reason, "c hs interp"); - - return 1; -} -#endif - -char * -lws_generate_client_handshake(struct lws *wsi, char *pkt) -{ - char *p = pkt; - const char *meth; - const char *pp = lws_hdr_simple_ptr(wsi, - _WSI_TOKEN_CLIENT_SENT_PROTOCOLS); - - meth = lws_hdr_simple_ptr(wsi, _WSI_TOKEN_CLIENT_METHOD); - if (!meth) { - meth = "GET"; - wsi->do_ws = 1; - } else { - wsi->do_ws = 0; - } - - if (!strcmp(meth, "RAW")) { - lws_set_timeout(wsi, NO_PENDING_TIMEOUT, 0); - lwsl_notice("client transition to raw\n"); - - if (pp) { - const struct lws_protocols *pr; - - pr = lws_vhost_name_to_protocol(wsi->vhost, pp); - - if (!pr) { - lwsl_err("protocol %s not enabled on vhost\n", - pp); - return NULL; - } - - lws_bind_protocol(wsi, pr, __func__); - } - - if ((wsi->protocol->callback)(wsi, LWS_CALLBACK_RAW_ADOPT, - wsi->user_space, NULL, 0)) - return NULL; - - lws_role_transition(wsi, LWSIFR_CLIENT, LRS_ESTABLISHED, - &role_ops_raw_skt); - lws_header_table_detach(wsi, 1); - - return NULL; - } - - /* - * 04 example client handshake - * - * GET /chat HTTP/1.1 - * Host: server.example.com - * Upgrade: websocket - * Connection: Upgrade - * Sec-WebSocket-Key: dGhlIHNhbXBsZSBub25jZQ== - * Sec-WebSocket-Origin: http://example.com - * Sec-WebSocket-Protocol: chat, superchat - * Sec-WebSocket-Version: 4 - */ - - p += lws_snprintf(p, 2048, "%s %s HTTP/1.1\x0d\x0a", meth, - lws_hdr_simple_ptr(wsi, _WSI_TOKEN_CLIENT_URI)); - - p += lws_snprintf(p, 64, "Pragma: no-cache\x0d\x0a" - "Cache-Control: no-cache\x0d\x0a"); - - p += lws_snprintf(p, 128, "Host: %s\x0d\x0a", - lws_hdr_simple_ptr(wsi, _WSI_TOKEN_CLIENT_HOST)); - - if (lws_hdr_simple_ptr(wsi, _WSI_TOKEN_CLIENT_ORIGIN)) { - if (lws_check_opt(wsi->context->options, - LWS_SERVER_OPTION_JUST_USE_RAW_ORIGIN)) - p += lws_snprintf(p, 128, "Origin: %s\x0d\x0a", - lws_hdr_simple_ptr(wsi, - _WSI_TOKEN_CLIENT_ORIGIN)); - else - p += lws_snprintf(p, 128, "Origin: http://%s\x0d\x0a", - lws_hdr_simple_ptr(wsi, - _WSI_TOKEN_CLIENT_ORIGIN)); - } - -#if defined(LWS_WITH_HTTP_PROXY) - if (wsi->parent && - lws_hdr_total_length(wsi->parent, WSI_TOKEN_HTTP_CONTENT_LENGTH)) { - p += lws_snprintf(p, 128, "Content-Length: %s\x0d\x0a", - lws_hdr_simple_ptr(wsi->parent, WSI_TOKEN_HTTP_CONTENT_LENGTH)); - if (atoi(lws_hdr_simple_ptr(wsi->parent, WSI_TOKEN_HTTP_CONTENT_LENGTH))) - wsi->client_http_body_pending = 1; - } - if (wsi->parent && - lws_hdr_total_length(wsi->parent, WSI_TOKEN_HTTP_AUTHORIZATION)) { - p += lws_snprintf(p, 128, "Authorization: %s\x0d\x0a", - lws_hdr_simple_ptr(wsi->parent, WSI_TOKEN_HTTP_AUTHORIZATION)); - } - if (wsi->parent && - lws_hdr_total_length(wsi->parent, WSI_TOKEN_HTTP_CONTENT_TYPE)) { - p += lws_snprintf(p, 128, "Content-Type: %s\x0d\x0a", - lws_hdr_simple_ptr(wsi->parent, WSI_TOKEN_HTTP_CONTENT_TYPE)); - } -#endif - -#if defined(LWS_ROLE_WS) - if (wsi->do_ws) { - const char *conn1 = ""; - // if (!wsi->client_pipeline) - // conn1 = "close, "; - p = lws_generate_client_ws_handshake(wsi, p, conn1); - } else -#endif - { - if (!wsi->client_pipeline) - p += lws_snprintf(p, 64, "connection: close\x0d\x0a"); - } - - /* give userland a chance to append, eg, cookies */ - - if (wsi->protocol->callback(wsi, - LWS_CALLBACK_CLIENT_APPEND_HANDSHAKE_HEADER, - wsi->user_space, &p, - (pkt + wsi->context->pt_serv_buf_size) - p - 12)) - return NULL; - - p += lws_snprintf(p, 4, "\x0d\x0a"); - - // puts(pkt); - - return p; -} - -#if defined(LWS_ROLE_H1) || defined(LWS_ROLE_H2) - -LWS_VISIBLE int -lws_http_client_read(struct lws *wsi, char **buf, int *len) -{ - int rlen, n; - - rlen = lws_ssl_capable_read(wsi, (unsigned char *)*buf, *len); - *len = 0; - - // lwsl_notice("%s: rlen %d\n", __func__, rlen); - - /* allow the source to signal he has data again next time */ - if (lws_change_pollfd(wsi, 0, LWS_POLLIN)) - return -1; - - if (rlen == LWS_SSL_CAPABLE_ERROR) { - lwsl_debug("%s: SSL capable error\n", __func__); - return -1; - } - - if (rlen <= 0) - return 0; - - *len = rlen; - wsi->client_rx_avail = 0; - - /* - * server may insist on transfer-encoding: chunked, - * so http client must deal with it - */ -spin_chunks: - while (wsi->chunked && (wsi->chunk_parser != ELCP_CONTENT) && *len) { - switch (wsi->chunk_parser) { - case ELCP_HEX: - if ((*buf)[0] == '\x0d') { - wsi->chunk_parser = ELCP_CR; - break; - } - n = char_to_hex((*buf)[0]); - if (n < 0) { - lwsl_info("%s: chunking failure\n", __func__); - return -1; - } - wsi->chunk_remaining <<= 4; - wsi->chunk_remaining |= n; - break; - case ELCP_CR: - if ((*buf)[0] != '\x0a') { - lwsl_info("%s: chunking failure\n", __func__); - return -1; - } - wsi->chunk_parser = ELCP_CONTENT; - lwsl_info("chunk %d\n", wsi->chunk_remaining); - if (wsi->chunk_remaining) - break; - lwsl_info("final chunk\n"); - goto completed; - - case ELCP_CONTENT: - break; - - case ELCP_POST_CR: - if ((*buf)[0] != '\x0d') { - lwsl_info("%s: chunking failure\n", __func__); - - return -1; - } - - wsi->chunk_parser = ELCP_POST_LF; - break; - - case ELCP_POST_LF: - if ((*buf)[0] != '\x0a') { - lwsl_info("%s: chunking failure\n", __func__); - - return -1; - } - - wsi->chunk_parser = ELCP_HEX; - wsi->chunk_remaining = 0; - break; - } - (*buf)++; - (*len)--; - } - - if (wsi->chunked && !wsi->chunk_remaining) - return 0; - - if (wsi->http.rx_content_remain && - wsi->http.rx_content_remain < (unsigned int)*len) - n = (int)wsi->http.rx_content_remain; - else - n = *len; - - if (wsi->chunked && wsi->chunk_remaining && - wsi->chunk_remaining < n) - n = wsi->chunk_remaining; - -#if defined(LWS_WITH_HTTP_PROXY) && defined(LWS_WITH_HUBBUB) - /* hubbub */ - if (wsi->http.perform_rewrite) - lws_rewrite_parse(wsi->http.rw, (unsigned char *)*buf, n); - else -#endif - { - struct lws *wsi_eff = lws_client_wsi_effective(wsi); - - if ( -#if defined(LWS_WITH_HTTP_PROXY) - !wsi_eff->protocol_bind_balance == - !!wsi_eff->http.proxy_clientside && -#else - !!wsi_eff->protocol_bind_balance && -#endif - user_callback_handle_rxflow(wsi_eff->protocol->callback, - wsi_eff, LWS_CALLBACK_RECEIVE_CLIENT_HTTP_READ, - wsi_eff->user_space, *buf, n)) { - lwsl_info("%s: RECEIVE_CLIENT_HTTP_READ returned -1\n", - __func__); - - return -1; - } - } - - if (wsi->chunked && wsi->chunk_remaining) { - (*buf) += n; - wsi->chunk_remaining -= n; - *len -= n; - } - - if (wsi->chunked && !wsi->chunk_remaining) - wsi->chunk_parser = ELCP_POST_CR; - - if (wsi->chunked && *len) - goto spin_chunks; - - if (wsi->chunked) - return 0; - - /* if we know the content length, decrement the content remaining */ - if (wsi->http.rx_content_length > 0) - wsi->http.rx_content_remain -= n; - - // lwsl_notice("rx_content_remain %lld, rx_content_length %lld\n", - // wsi->http.rx_content_remain, wsi->http.rx_content_length); - - if (wsi->http.rx_content_remain || !wsi->http.rx_content_length) - return 0; - -completed: - - if (lws_http_transaction_completed_client(wsi)) { - lwsl_notice("%s: transaction completed says -1\n", __func__); - return -1; - } - - return 0; -} - -#endif diff -Nru libwebsockets-3.2.1/lib/roles/http/client/client-handshake.c libwebsockets-4.1.6/lib/roles/http/client/client-handshake.c --- libwebsockets-3.2.1/lib/roles/http/client/client-handshake.c 2019-12-18 14:45:31.000000000 +0000 +++ libwebsockets-4.1.6/lib/roles/http/client/client-handshake.c 2020-12-01 17:40:26.000000000 +0000 @@ -1,9 +1,35 @@ -#include "core/private.h" +/* + * libwebsockets - small server side websockets and web server implementation + * + * Copyright (C) 2010 - 2019 Andy Green + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to + * deal in the Software without restriction, including without limitation the + * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or + * sell copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS + * IN THE SOFTWARE. + */ +#include "private-lib-core.h" + +#if !defined(LWS_WITH_SYS_ASYNC_DNS) static int lws_getaddrinfo46(struct lws *wsi, const char *ads, struct addrinfo **result) { struct addrinfo hints; + int n; memset(&hints, 0, sizeof(hints)); *result = NULL; @@ -14,7 +40,7 @@ if (wsi->ipv6) { #if !defined(__ANDROID__) - hints.ai_family = AF_INET6; + hints.ai_family = AF_UNSPEC; hints.ai_flags = AI_V4MAPPED; #endif } else @@ -23,54 +49,83 @@ hints.ai_family = PF_UNSPEC; } - return getaddrinfo(ads, NULL, &hints, result); -} + n = getaddrinfo(ads, NULL, &hints, result); + lwsl_info("%s: getaddrinfo '%s' says %d\n", __func__, ads, n); + + return n; +} +#endif struct lws * -lws_client_connect_3(struct lws *wsi, struct lws *wsi_piggyback, ssize_t plen) +lws_client_connect_4_established(struct lws *wsi, struct lws *wsi_piggyback, + ssize_t plen) { - struct lws_context_per_thread *pt = &wsi->context->pt[(int)wsi->tsi]; - const char *meth = NULL; +#if defined(LWS_CLIENT_HTTP_PROXYING) + struct lws_context_per_thread *pt = &wsi->a.context->pt[(int)wsi->tsi]; +#endif + const char *meth; struct lws_pollfd pfd; const char *cce = ""; int n, m, rawish = 0; - if (wsi->stash) - meth = wsi->stash->method; - else - meth = lws_hdr_simple_ptr(wsi, _WSI_TOKEN_CLIENT_METHOD); + meth = lws_wsi_client_stash_item(wsi, CIS_METHOD, + _WSI_TOKEN_CLIENT_METHOD); - if (meth && !strcmp(meth, "RAW")) + if (meth && (!strcmp(meth, "RAW") +#if defined(LWS_ROLE_MQTT) + || !strcmp(meth, "MQTT") +#endif + )) rawish = 1; if (wsi_piggyback) goto send_hs; +#if defined(LWS_CLIENT_HTTP_PROXYING) #if defined(LWS_ROLE_H1) || defined(LWS_ROLE_H2) /* we are connected to server, or proxy */ /* http proxy */ - if (wsi->vhost->http.http_proxy_port) { + if (wsi->a.vhost->http.http_proxy_port) { + const char *cpa; + + cpa = lws_wsi_client_stash_item(wsi, CIS_ADDRESS, + _WSI_TOKEN_CLIENT_PEER_ADDRESS); + if (!cpa) + goto failed; + + lwsl_info("%s: going via proxy\n", __func__); + + plen = lws_snprintf((char *)pt->serv_buf, 256, + "CONNECT %s:%u HTTP/1.1\x0d\x0a" + "Host: %s:%u\x0d\x0a" + "User-agent: lws\x0d\x0a", cpa, wsi->ocport, + cpa, wsi->ocport); + +#if defined(LWS_WITH_HTTP_BASIC_AUTH) + if (wsi->a.vhost->proxy_basic_auth_token[0]) + plen += lws_snprintf((char *)pt->serv_buf + plen, 256, + "Proxy-authorization: basic %s\x0d\x0a", + wsi->a.vhost->proxy_basic_auth_token); +#endif + + plen += lws_snprintf((char *)pt->serv_buf + plen, 5, "\x0d\x0a"); + + /* lwsl_hexdump_notice(pt->serv_buf, plen); */ /* * OK from now on we talk via the proxy, so connect to that - * - * (will overwrite existing pointer, - * leaving old string/frag there but unreferenced) */ - if (wsi->stash) { - lws_free(wsi->stash->address); - wsi->stash->address = - lws_strdup(wsi->vhost->http.http_proxy_address); - if (!wsi->stash->address) - goto failed; - } else + if (wsi->stash) + wsi->stash->cis[CIS_ADDRESS] = + wsi->a.vhost->http.http_proxy_address; + else if (lws_hdr_simple_create(wsi, _WSI_TOKEN_CLIENT_PEER_ADDRESS, - wsi->vhost->http.http_proxy_address)) + wsi->a.vhost->http.http_proxy_address)) goto failed; - wsi->c_port = wsi->vhost->http.http_proxy_port; + wsi->c_port = wsi->a.vhost->http.http_proxy_port; n = send(wsi->desc.sockfd, (char *)pt->serv_buf, (int)plen, MSG_NOSIGNAL); @@ -81,33 +136,31 @@ } lws_set_timeout(wsi, PENDING_TIMEOUT_AWAITING_PROXY_RESPONSE, - AWAITING_TIMEOUT); + wsi->a.context->timeout_secs); lwsi_set_state(wsi, LRS_WAITING_PROXY_REPLY); return wsi; } #endif +#endif + + /* coverity */ + if (!wsi->a.protocol) + return NULL; + #if defined(LWS_WITH_SOCKS5) - /* socks proxy */ - else if (wsi->vhost->socks_proxy_port) { - n = send(wsi->desc.sockfd, (char *)pt->serv_buf, plen, - MSG_NOSIGNAL); - if (n < 0) { - lwsl_debug("ERROR writing socks greeting\n"); - cce = "socks write failed"; + if (lwsi_state(wsi) != LRS_ESTABLISHED) + switch (lws_socks5c_greet(wsi, &cce)) { + case -1: goto failed; + case 1: + return wsi; + default: + break; } - - lws_set_timeout(wsi, - PENDING_TIMEOUT_AWAITING_SOCKS_GREETING_REPLY, - AWAITING_TIMEOUT); - - lwsi_set_state(wsi, LRS_WAITING_SOCKS_GREETING_REPLY); - - return wsi; - } #endif + #if defined(LWS_ROLE_H1) || defined(LWS_ROLE_H2) send_hs: @@ -116,9 +169,12 @@ /* * We are pipelining on an already-established connection... * we can skip tls establishment. + * + * Set these queued guys to a state where they won't actually + * send their headers until we decide later. */ - lwsi_set_state(wsi, LRS_H1C_ISSUE_HANDSHAKE2); + lwsi_set_state(wsi, LRS_H2_WAITING_TO_SEND_HEADERS); /* * we can't send our headers directly, because they have to @@ -131,27 +187,77 @@ * wait in the queue until it's possible to send them. */ lws_callback_on_writable(wsi_piggyback); +#if defined(LWS_WITH_DETAILED_LATENCY) + wsi->detlat.earliest_write_req = + wsi->detlat.earliest_write_req_pre_write = lws_now_usecs(); +#endif lwsl_info("%s: wsi %p: waiting to send hdrs (par state 0x%x)\n", __func__, wsi, lwsi_state(wsi_piggyback)); } else { - lwsl_info("%s: wsi %p: %s %s client created own conn (raw %d)\n", + lwsl_info("%s: wsi %p: %s %s client created own conn (raw %d) vh %sm st 0x%x\n", __func__, wsi, wsi->role_ops->name, - wsi->protocol->name, rawish); + wsi->a.protocol->name, rawish, wsi->a.vhost->name, + lwsi_state(wsi)); /* we are making our own connection */ - if (!rawish) - lwsi_set_state(wsi, LRS_H1C_ISSUE_HANDSHAKE); - else { + + if (!rawish) { + if (lwsi_state(wsi) != LRS_H1C_ISSUE_HANDSHAKE2) + lwsi_set_state(wsi, LRS_H1C_ISSUE_HANDSHAKE); + } else { /* for a method = "RAW" connection, this makes us * established */ +#if defined(LWS_WITH_TLS) && !defined(LWS_WITH_MBEDTLS) + + /* we have connected if we got here */ + + if (lwsi_state(wsi) == LRS_WAITING_CONNECT && + (wsi->tls.use_ssl & LCCSCF_USE_SSL)) { + int result; + + /* + * We can retry this... just cook the SSL BIO + * the first time + */ + + result = lws_client_create_tls(wsi, &cce, 1); + lwsl_debug("%s: create_tls said %d\n", __func__, result); + switch (result) { + case CCTLS_RETURN_DONE: + break; + case CCTLS_RETURN_RETRY: + return wsi; + default: + goto failed; + } + + /* + * We succeeded to negotiate a new client tls tunnel. + * If it's h2 alpn, we have arranged to send to h2 + * prefix and set our state to + * LRS_H2_WAITING_TO_SEND_HEADERS already. + */ + + lwsl_notice("%s: wsi %p: tls established st 0x%x\n", + __func__, wsi, lwsi_state(wsi)); + + if (lwsi_state(wsi) != LRS_H2_WAITING_TO_SEND_HEADERS) + lwsi_set_state(wsi, LRS_H1C_ISSUE_HANDSHAKE2); + lws_set_timeout(wsi, PENDING_TIMEOUT_AWAITING_CLIENT_HS_SEND, + wsi->a.context->timeout_secs); + + goto provoke_service; + } +#endif + /* clear his established timeout */ lws_set_timeout(wsi, NO_PENDING_TIMEOUT, 0); m = wsi->role_ops->adoption_cb[0]; if (m) { n = user_callback_handle_rxflow( - wsi->protocol->callback, wsi, + wsi->a.protocol->callback, wsi, m, wsi->user_space, NULL, 0); if (n < 0) { lwsl_info("LWS_CALLBACK_RAW_PROXY_CLI_ADOPT failed\n"); @@ -161,6 +267,41 @@ /* service.c pollout processing wants this */ wsi->hdr_parsing_completed = 1; +#if defined(LWS_ROLE_MQTT) + if (!strcmp(meth, "MQTT")) { +#if defined(LWS_WITH_TLS) + if (wsi->tls.use_ssl & LCCSCF_USE_SSL) { + lwsi_set_state(wsi, LRS_WAITING_SSL); + return wsi; + } +#endif + lwsl_info("%s: settings LRS_MQTTC_IDLE\n", + __func__); + lwsi_set_state(wsi, LRS_MQTTC_IDLE); + + /* + * provoke service to issue the CONNECT directly. + */ + lws_set_timeout(wsi, PENDING_TIMEOUT_SENT_CLIENT_HANDSHAKE, + wsi->a.context->timeout_secs); + + assert(lws_socket_is_valid(wsi->desc.sockfd)); + + pfd.fd = wsi->desc.sockfd; + pfd.events = LWS_POLLIN; + pfd.revents = LWS_POLLOUT; + + lwsl_info("%s: going to service fd\n", __func__); + n = lws_service_fd(wsi->a.context, &pfd); + if (n < 0) { + cce = "first service failed"; + goto failed; + } + if (n) /* returns 1 on failure after closing wsi */ + return NULL; + return wsi; + } +#endif lwsl_info("%s: setting ESTABLISHED\n", __func__); lwsi_set_state(wsi, LRS_ESTABLISHED); @@ -177,9 +318,11 @@ * and won't until many retries from main loop. To stop that * becoming endless, cover with a timeout. */ - +#if defined(LWS_WITH_TLS) && !defined(LWS_WITH_MBEDTLS) +provoke_service: +#endif lws_set_timeout(wsi, PENDING_TIMEOUT_SENT_CLIENT_HANDSHAKE, - AWAITING_TIMEOUT); + wsi->a.context->timeout_secs); assert(lws_socket_is_valid(wsi->desc.sockfd)); @@ -187,7 +330,7 @@ pfd.events = LWS_POLLIN; pfd.revents = LWS_POLLIN; - n = lws_service_fd(wsi->context, &pfd); + n = lws_service_fd(wsi->a.context, &pfd); if (n < 0) { cce = "first service failed"; goto failed; @@ -206,184 +349,114 @@ return NULL; } +void +lws_client_conn_wait_timeout(lws_sorted_usec_list_t *sul) +{ + struct lws *wsi = lws_container_of(sul, struct lws, sul_connect_timeout); + + /* + * This is used to constrain the time we're willing to wait for a + * connection before giving up on it and retrying. + */ + + lwsl_info("%s: connect wait timeout has fired\n", __func__); + lws_client_connect_3_connect(wsi, NULL, NULL, 0, NULL); +} + struct lws * -lws_client_connect_2(struct lws *wsi) +lws_client_connect_3_connect(struct lws *wsi, const char *ads, + const struct addrinfo *result, int n, void *opaque) { -#if defined(LWS_ROLE_H1) || defined(LWS_ROLE_H2) - struct lws_context *context = wsi->context; - struct lws_context_per_thread *pt = &context->pt[(int)wsi->tsi]; - const char *adsin; - ssize_t plen = 0; -#endif #if defined(LWS_WITH_UNIX_SOCK) struct sockaddr_un sau; - char unix_skt = 0; #endif - int n, port = 0; - const char *cce = "", *iface; - const struct sockaddr *psa; - const char *meth = NULL; - struct addrinfo *result; - const char *ads; - sockaddr46 sa46; - #ifdef LWS_WITH_IPV6 - char ipv6only = lws_check_opt(wsi->vhost->options, - LWS_SERVER_OPTION_IPV6_V6ONLY_MODIFY | - LWS_SERVER_OPTION_IPV6_V6ONLY_VALUE); - struct sockaddr_in addr; -#if defined(__ANDROID__) - ipv6only = 0; -#endif -#endif - -#if defined(LWS_ROLE_H1) || defined(LWS_ROLE_H2) - if (!wsi->http.ah && !wsi->stash) { - cce = "ah was NULL at cc2"; - lwsl_err("%s\n", cce); - goto oom4; - } - - /* we can only piggyback GET or POST */ - - if (wsi->stash) - meth = wsi->stash->method; - else - meth = lws_hdr_simple_ptr(wsi, _WSI_TOKEN_CLIENT_METHOD); - - if (meth && strcmp(meth, "GET") && strcmp(meth, "POST")) - goto create_new_conn; + char ipv6only = lws_check_opt(wsi->a.vhost->options, + LWS_SERVER_OPTION_IPV6_V6ONLY_MODIFY | + LWS_SERVER_OPTION_IPV6_V6ONLY_VALUE); +#endif + struct lws_context_per_thread *pt = &wsi->a.context->pt[(int)wsi->tsi]; + const struct sockaddr *psa = NULL; + uint16_t port = wsi->c_port; + const char *cce, *iface; + lws_sockaddr46 sa46; + ssize_t plen = 0; + char ni[48]; + int m; - /* we only pipeline connections that said it was okay */ + if (n == LWS_CONNECT_COMPLETION_GOOD) + goto conn_good; - if (!wsi->client_pipeline) - goto create_new_conn; +#if defined(LWS_WITH_IPV6) && defined(__ANDROID__) + ipv6only = 0; +#endif /* - * let's take a look first and see if there are any already-active - * client connections we can piggy-back on. + * async dns calls back here for everybody who cares when it gets a + * result... but if we are piggybacking, we do not want to connect + * ourselves */ - adsin = lws_hdr_simple_ptr(wsi, _WSI_TOKEN_CLIENT_PEER_ADDRESS); - - lws_vhost_lock(wsi->vhost); /* ----------------------------------- { */ - - lws_start_foreach_dll_safe(struct lws_dll2 *, d, d1, - lws_dll2_get_head(&wsi->vhost->dll_cli_active_conns_owner)) { - struct lws *w = lws_container_of(d, struct lws, - dll_cli_active_conns); - - lwsl_debug("%s: check %s %s %d %d\n", __func__, adsin, - w->cli_hostname_copy, wsi->c_port, w->c_port); - - if (w != wsi && w->cli_hostname_copy && - !strcmp(adsin, w->cli_hostname_copy) && -#if defined(LWS_WITH_TLS) - (wsi->tls.use_ssl & LCCSCF_USE_SSL) == - (w->tls.use_ssl & LCCSCF_USE_SSL) && -#endif - wsi->c_port == w->c_port) { - - /* someone else is already connected to the right guy */ + if (!lws_dll2_is_detached(&wsi->dll2_cli_txn_queue)) + return wsi; - /* do we know for a fact pipelining won't fly? */ - if (w->keepalive_rejected) { - lwsl_info("defeating pipelining due to no " - "keepalive on server\n"); - lws_vhost_unlock(wsi->vhost); /* } ---------- */ - goto create_new_conn; + /* + * We can check using getsockopt if our connect actually completed. + * Posix connect() allows nonblocking to redo the connect to + * find out if it succeeded, for win32 we have to use this path + * and take WSAEALREADY as a successful connect. + */ + + if (lwsi_state(wsi) == LRS_WAITING_CONNECT && + lws_socket_is_valid(wsi->desc.sockfd)) { +#if !defined(WIN32) + socklen_t sl = sizeof(int); + int e = 0; +#endif + + if (!result && /* no dns results... */ + !wsi->sul_connect_timeout.list.owner /* no ongoing connect timeout */) + goto connect_to; +#if defined(WIN32) + if (!connect(wsi->desc.sockfd, NULL, 0)) { + goto conn_good; + } else { + if (!LWS_ERRNO || LWS_ERRNO == WSAEINVAL || + LWS_ERRNO == WSAEWOULDBLOCK || LWS_ERRNO == WSAEALREADY) { + lwsl_info("%s: errno %d\n", __func__, errno); + return NULL; } -#if defined (LWS_WITH_HTTP2) - /* - * h2: in usable state already: just use it without - * going through the queue - */ - if (w->client_h2_alpn && - (lwsi_state(w) == LRS_H2_WAITING_TO_SEND_HEADERS || - lwsi_state(w) == LRS_ESTABLISHED)) { - - lwsl_info("%s: just join h2 directly\n", - __func__); - - wsi->client_h2_alpn = 1; - lws_wsi_h2_adopt(w, wsi); - lws_vhost_unlock(wsi->vhost); /* } ---------- */ + lwsl_info("%s: connect check take as FAILED\n", __func__); + } +#else + /* + * this resets SO_ERROR after reading it. If there's an error + * condition the connect definitively failed. + */ + + if (!getsockopt(wsi->desc.sockfd, SOL_SOCKET, SO_ERROR, + &e, &sl)) { + if (!e) { + lwsl_debug("%s: getsockopt check: conn OK errno %d\n", + __func__, errno); - return wsi; + goto conn_good; } -#endif - lwsl_info("apply %p to txn queue on %p state 0x%lx\n", - wsi, w, (unsigned long)w->wsistate); - /* - * ...let's add ourselves to his transaction queue... - * we are adding ourselves at the HEAD - */ - lws_dll2_add_head(&wsi->dll2_cli_txn_queue, - &w->dll2_cli_txn_queue_owner); - - /* - * h1: pipeline our headers out on him, - * and wait for our turn at client transaction_complete - * to take over parsing the rx. - */ - lws_vhost_unlock(wsi->vhost); /* } ---------- */ - return lws_client_connect_3(wsi, w, plen); + lwsl_debug("%s: getsockopt fd %d says err %d\n", __func__, + wsi->desc.sockfd, e); } - - } lws_end_foreach_dll_safe(d, d1); - - lws_vhost_unlock(wsi->vhost); /* } ---------------------------------- */ - -create_new_conn: #endif - /* - * clients who will create their own fresh connection keep a copy of - * the hostname they originally connected to, in case other connections - * want to use it too - */ - - if (!wsi->cli_hostname_copy) { - if (wsi->stash) - wsi->cli_hostname_copy = lws_strdup(wsi->stash->host); - else { - char *pa = lws_hdr_simple_ptr(wsi, - _WSI_TOKEN_CLIENT_PEER_ADDRESS); - if (pa) - wsi->cli_hostname_copy = lws_strdup(pa); - } - } - - /* - * If we made our own connection, and we're doing a method that can take - * a pipeline, we are an "active client connection". - * - * Add ourselves to the vhost list of those so that others can - * piggyback on our transaction queue - */ - - if (meth && (!strcmp(meth, "GET") || !strcmp(meth, "POST")) && - lws_dll2_is_detached(&wsi->dll2_cli_txn_queue) && - lws_dll2_is_detached(&wsi->dll_cli_active_conns)) { - lws_vhost_lock(wsi->vhost); - /* caution... we will have to unpick this on oom4 path */ - lws_dll2_add_head(&wsi->dll_cli_active_conns, - &wsi->vhost->dll_cli_active_conns_owner); - lws_vhost_unlock(wsi->vhost); + lwsl_debug("%s: getsockopt check: conn fail: errno %d\n", + __func__, LWS_ERRNO); + goto try_next_result_fds; } - /* - * unix socket destination? - */ - - if (wsi->stash) - ads = wsi->stash->address; - else - ads = lws_hdr_simple_ptr(wsi, _WSI_TOKEN_CLIENT_PEER_ADDRESS); #if defined(LWS_WITH_UNIX_SOCK) - if (*ads == '+') { + if (ads && *ads == '+') { ads++; + memset(&sa46, 0, sizeof(sa46)); memset(&sau, 0, sizeof(sau)); sau.sun_family = AF_UNIX; strncpy(sau.sun_path, ads, sizeof(sau.sun_path)); @@ -394,52 +467,49 @@ if (sau.sun_path[0] == '@') sau.sun_path[0] = '\0'; - unix_skt = 1; goto ads_known; } #endif - /* - * start off allowing ipv6 on connection if vhost allows it - */ - wsi->ipv6 = LWS_IPV6_ENABLED(wsi->vhost); -#ifdef LWS_WITH_IPV6 - if (wsi->stash) - iface = wsi->stash->iface; - else - iface = lws_hdr_simple_ptr(wsi, _WSI_TOKEN_CLIENT_IFACE); - - if (wsi->ipv6 && iface && - inet_pton(AF_INET, iface, &addr.sin_addr) == 1) { - lwsl_notice("%s: client connection forced to IPv4\n", __func__); - wsi->ipv6 = 0; +#if defined(LWS_WITH_SYS_ASYNC_DNS) + if (n == LADNS_RET_FAILED) { + lwsl_notice("%s: adns failed %s\n", __func__, ads); + /* + * Caller that is giving us LADNS_RET_FAILED will deal + * with cleanup + */ + return NULL; } #endif -#if defined(LWS_ROLE_H1) || defined(LWS_ROLE_H2) + if (!wsi->dns_results) { + wsi->dns_results_next = wsi->dns_results = result; + if (result) + lwsl_debug("%s: result %p result->ai_next %p\n", + __func__, result, result->ai_next); + } + +#if defined(LWS_WITH_DETAILED_LATENCY) + if (lwsi_state(wsi) == LRS_WAITING_DNS && + wsi->a.context->detailed_latency_cb) { + wsi->detlat.type = LDLT_NAME_RESOLUTION; + wsi->detlat.latencies[LAT_DUR_PROXY_CLIENT_REQ_TO_WRITE] = + lws_now_usecs() - + wsi->detlat.earliest_write_req_pre_write; + wsi->detlat.latencies[LAT_DUR_USERCB] = 0; + lws_det_lat_cb(wsi->a.context, &wsi->detlat); + wsi->detlat.earliest_write_req_pre_write = lws_now_usecs(); + } +#endif +#if defined(LWS_CLIENT_HTTP_PROXYING) && \ + (defined(LWS_ROLE_H1) || defined(LWS_ROLE_H2)) /* Decide what it is we need to connect to: * * Priority 1: connect to http proxy */ - if (wsi->vhost->http.http_proxy_port) { - - lwsl_info("%s: going via proxy\n", __func__); - - plen = lws_snprintf((char *)pt->serv_buf, 256, - "CONNECT %s:%u HTTP/1.0\x0d\x0a" - "Host: %s:%u\x0d\x0a" - "User-agent: libwebsockets\x0d\x0a", - ads, wsi->ocport, ads, wsi->ocport); - - if (wsi->vhost->proxy_basic_auth_token[0]) - plen += lws_snprintf((char *)pt->serv_buf + plen, 256, - "Proxy-authorization: basic %s\x0d\x0a", - wsi->vhost->proxy_basic_auth_token); - - plen += lws_snprintf((char *)pt->serv_buf + plen, 5, "\x0d\x0a"); - ads = wsi->vhost->http.http_proxy_address; - port = wsi->vhost->http.http_proxy_port; + if (wsi->a.vhost->http.http_proxy_port) { + port = wsi->a.vhost->http.http_proxy_port; #else if (0) { #endif @@ -448,300 +518,297 @@ /* Priority 2: Connect to SOCK5 Proxy */ - } else if (wsi->vhost->socks_proxy_port) { - if (socks_generate_msg(wsi, SOCKS_MSG_GREETING, &plen)) { + } else if (wsi->a.vhost->socks_proxy_port) { + if (lws_socks5c_generate_msg(wsi, SOCKS_MSG_GREETING, &plen)) { cce = "socks msg too large"; goto oom4; } lwsl_client("Sending SOCKS Greeting\n"); - ads = wsi->vhost->socks_proxy_address; - port = wsi->vhost->socks_proxy_port; + ads = wsi->a.vhost->socks_proxy_address; + port = wsi->a.vhost->socks_proxy_port; #endif - } else { + } - /* Priority 3: Connect directly */ + memset(&sa46, 0, sizeof(sa46)); - /* ads already set */ - port = wsi->c_port; + if (n || !wsi->dns_results) { + /* lws_getaddrinfo46 failed, there is no usable result */ + lwsl_notice("%s: lws_getaddrinfo46 failed %d\n", + __func__, n); + + cce = "ipv6 lws_getaddrinfo46 failed"; + goto oom4; } /* - * prepare the actual connection - * to whatever we decided to connect to + * Let's try connecting to each of the results in turn until one works + * or we run out of results */ - lwsl_info("%s: %p: address %s:%u\n", __func__, wsi, ads, port); +next_result: - n = lws_getaddrinfo46(wsi, ads, &result); + psa = (const struct sockaddr *)&sa46; + n = sizeof(sa46); memset(&sa46, 0, sizeof(sa46)); -#ifdef LWS_WITH_IPV6 - if (wsi->ipv6) { - struct sockaddr_in6 *sa6; - if (n || !result) { - /* lws_getaddrinfo46 failed, there is no usable result */ - lwsl_notice("%s: lws_getaddrinfo46 failed %d\n", - __func__, n); - cce = "ipv6 lws_getaddrinfo46 failed"; - goto oom4; - } + switch (wsi->dns_results_next->ai_family) { + case AF_INET: +#if defined(LWS_WITH_IPV6) + if (ipv6only) { + sa46.sa4.sin_family = AF_INET6; - sa6 = ((struct sockaddr_in6 *)result->ai_addr); - sa46.sa6.sin6_family = AF_INET6; - switch (result->ai_family) { - case AF_INET: - if (ipv6only) - break; /* map IPv4 to IPv6 */ memset((char *)&sa46.sa6.sin6_addr, 0, sizeof(sa46.sa6.sin6_addr)); sa46.sa6.sin6_addr.s6_addr[10] = 0xff; sa46.sa6.sin6_addr.s6_addr[11] = 0xff; memcpy(&sa46.sa6.sin6_addr.s6_addr[12], - &((struct sockaddr_in *)result->ai_addr)->sin_addr, + &((struct sockaddr_in *) + wsi->dns_results_next->ai_addr)->sin_addr, sizeof(struct in_addr)); - lwsl_notice("uplevelling AF_INET to AF_INET6\n"); - break; - - case AF_INET6: - memcpy(&sa46.sa6.sin6_addr, &sa6->sin6_addr, - sizeof(struct in6_addr)); - sa46.sa6.sin6_scope_id = sa6->sin6_scope_id; - sa46.sa6.sin6_flowinfo = sa6->sin6_flowinfo; + sa46.sa6.sin6_port = htons(port); + ni[0] = '\0'; + lws_write_numeric_address(sa46.sa6.sin6_addr.s6_addr, + 16, ni, sizeof(ni)); + lwsl_info("%s: %s ipv4->ipv6 %s\n", __func__, + ads ? ads : "(null)", ni); break; - default: - lwsl_err("Unknown address family\n"); - freeaddrinfo(result); - cce = "unknown address family"; - goto oom4; } - } else -#endif /* use ipv6 */ - - /* use ipv4 */ - { - void *p = NULL; - - if (!n) { - struct addrinfo *res = result; - - /* pick the first AF_INET (IPv4) result */ - - while (!p && res) { - switch (res->ai_family) { - case AF_INET: - p = &((struct sockaddr_in *)res->ai_addr)->sin_addr; - break; - } - - res = res->ai_next; - } -#if defined(LWS_FALLBACK_GETHOSTBYNAME) - } else if (n == EAI_SYSTEM) { - struct hostent *host; - - lwsl_info("ipv4 getaddrinfo err, try gethostbyname\n"); - host = gethostbyname(ads); - if (host) { - p = host->h_addr; - } else { - lwsl_err("gethostbyname failed\n"); - cce = "gethostbyname (ipv4) failed"; - goto oom4; - } #endif - } else { - lwsl_err("getaddrinfo failed: %d\n", n); - cce = "getaddrinfo failed"; - goto oom4; - } - - if (!p) { - if (result) - freeaddrinfo(result); - lwsl_err("Couldn't identify address\n"); - cce = "unable to lookup address"; - goto oom4; - } - sa46.sa4.sin_family = AF_INET; - sa46.sa4.sin_addr = *((struct in_addr *)p); + sa46.sa4.sin_addr.s_addr = + ((struct sockaddr_in *)wsi->dns_results_next->ai_addr)-> + sin_addr.s_addr; memset(&sa46.sa4.sin_zero, 0, sizeof(sa46.sa4.sin_zero)); + sa46.sa4.sin_port = htons(port); + n = sizeof(struct sockaddr_in); + lws_write_numeric_address((uint8_t *)&sa46.sa4.sin_addr.s_addr, + 4, ni, sizeof(ni)); + lwsl_info("%s: %s ipv4 %s\n", __func__, ads ? ads : "(null)", ni); + break; + case AF_INET6: +#if defined(LWS_WITH_IPV6) + if (!wsi->ipv6) + goto try_next_result; + sa46.sa4.sin_family = AF_INET6; + memcpy(&sa46.sa6.sin6_addr, + &((struct sockaddr_in6 *)wsi->dns_results_next->ai_addr)-> + sin6_addr, sizeof(struct in6_addr)); + sa46.sa6.sin6_scope_id = ((struct sockaddr_in6 *) + wsi->dns_results_next->ai_addr)->sin6_scope_id; + sa46.sa6.sin6_flowinfo = ((struct sockaddr_in6 *) + wsi->dns_results_next->ai_addr)->sin6_flowinfo; + sa46.sa6.sin6_port = htons(port); + lws_write_numeric_address((uint8_t *)&sa46.sa6.sin6_addr, + 16, ni, sizeof(ni)); + lwsl_info("%s: %s ipv6 %s\n", __func__, ads ? ads : "(null)", ni); +#else + goto try_next_result; /* ipv4 only can't use this */ +#endif + break; } - if (result) - freeaddrinfo(result); - #if defined(LWS_WITH_UNIX_SOCK) ads_known: #endif - /* now we decided on ipv4 or ipv6, set the port */ + /* now we decided on ipv4 or ipv6, set the port and create socket*/ if (!lws_socket_is_valid(wsi->desc.sockfd)) { - if (wsi->context->event_loop_ops->check_client_connect_ok && - wsi->context->event_loop_ops->check_client_connect_ok(wsi)) { + if (wsi->a.context->event_loop_ops->check_client_connect_ok && + wsi->a.context->event_loop_ops->check_client_connect_ok(wsi)) { cce = "waiting for event loop watcher to close"; goto oom4; } #if defined(LWS_WITH_UNIX_SOCK) - if (unix_skt) { - wsi->unix_skt = 1; + if (wsi->unix_skt) wsi->desc.sockfd = socket(AF_UNIX, SOCK_STREAM, 0); - } else -#endif - { - -#ifdef LWS_WITH_IPV6 - if (wsi->ipv6) - wsi->desc.sockfd = socket(AF_INET6, SOCK_STREAM, 0); else #endif - wsi->desc.sockfd = socket(AF_INET, SOCK_STREAM, 0); - } + wsi->desc.sockfd = socket(sa46.sa4.sin_family, + SOCK_STREAM, 0); if (!lws_socket_is_valid(wsi->desc.sockfd)) { lwsl_warn("Unable to open socket\n"); - cce = "unable to open socket"; - goto oom4; + goto try_next_result; } - if (lws_plat_set_socket_options(wsi->vhost, wsi->desc.sockfd, + if (lws_plat_set_socket_options(wsi->a.vhost, wsi->desc.sockfd, #if defined(LWS_WITH_UNIX_SOCK) - unix_skt)) { + wsi->unix_skt)) { #else 0)) { #endif lwsl_err("Failed to set wsi socket options\n"); - compatible_close(wsi->desc.sockfd); - cce = "set socket opts failed"; - goto oom4; + goto try_next_result_closesock; } + lwsl_debug("%s: %p: WAITING_CONNECT\n", __func__, wsi); lwsi_set_state(wsi, LRS_WAITING_CONNECT); -#if !defined(LWS_AMAZON_RTOS) - if (wsi->context->event_loop_ops->accept) - if (wsi->context->event_loop_ops->accept(wsi)) { - compatible_close(wsi->desc.sockfd); - cce = "event loop accept failed"; - goto oom4; - } -#endif - - if (__insert_wsi_socket_into_fds(wsi->context, wsi)) { - compatible_close(wsi->desc.sockfd); - cce = "insert wsi failed"; - goto oom4; - } - - if (lws_change_pollfd(wsi, 0, LWS_POLLIN)) { - compatible_close(wsi->desc.sockfd); - cce = "change_pollfd failed"; - goto oom4; + if (wsi->a.context->event_loop_ops->sock_accept) + if (wsi->a.context->event_loop_ops->sock_accept(wsi)) + goto try_next_result_closesock; + + lws_pt_lock(pt, __func__); + if (__insert_wsi_socket_into_fds(wsi->a.context, wsi)) { + lws_pt_unlock(pt); + goto try_next_result_closesock; } + lws_pt_unlock(pt); /* - * past here, we can't simply free the structs as error - * handling as oom4 does. We have to run the whole close flow. + * The fd + wsi combination is entered into the wsi tables + * at this point, with a pollfd + * + * Past here, we can't simply free the structs as error + * handling as oom4 does. + * + * We can run the whole close flow, or unpick the fds inclusion + * and anything else we have done. */ - if (!wsi->protocol) - wsi->protocol = &wsi->vhost->protocols[0]; + if (lws_change_pollfd(wsi, 0, LWS_POLLIN)) + goto try_next_result_fds; - wsi->protocol->callback(wsi, LWS_CALLBACK_WSI_CREATE, - wsi->user_space, NULL, 0); + if (!wsi->a.protocol) + wsi->a.protocol = &wsi->a.vhost->protocols[0]; lws_set_timeout(wsi, PENDING_TIMEOUT_AWAITING_CONNECT_RESPONSE, - AWAITING_TIMEOUT); + wsi->a.vhost->connect_timeout_secs); - if (wsi->stash) - iface = wsi->stash->iface; - else - iface = lws_hdr_simple_ptr(wsi, _WSI_TOKEN_CLIENT_IFACE); + iface = lws_wsi_client_stash_item(wsi, CIS_IFACE, + _WSI_TOKEN_CLIENT_IFACE); - if (iface) { - n = lws_socket_bind(wsi->vhost, wsi->desc.sockfd, 0, + if (iface && *iface) { + m = lws_socket_bind(wsi->a.vhost, wsi->desc.sockfd, 0, iface, wsi->ipv6); - if (n < 0) { - cce = "unable to bind socket"; - goto failed; - } + if (m < 0) + goto try_next_result_fds; } } #if defined(LWS_WITH_UNIX_SOCK) - if (unix_skt) { + if (wsi->unix_skt) { psa = (const struct sockaddr *)&sau; - n = sizeof(sau); + if (sau.sun_path[0]) + n = (int)(sizeof(uint16_t) + strlen(sau.sun_path)); + else + n = (int)(sizeof(uint16_t) + strlen(&sau.sun_path[1]) + 1); } else #endif - { -#ifdef LWS_WITH_IPV6 - if (wsi->ipv6) { - sa46.sa6.sin6_port = htons(port); - n = sizeof(struct sockaddr_in6); - psa = (const struct sockaddr *)&sa46; - } else -#endif - { - sa46.sa4.sin_port = htons(port); - n = sizeof(struct sockaddr); - psa = (const struct sockaddr *)&sa46; - } - } + if (!psa) /* coverity */ + goto try_next_result_fds; - if (connect(wsi->desc.sockfd, (const struct sockaddr *)psa, n) == -1 || - LWS_ERRNO == LWS_EISCONN) { - if (LWS_ERRNO == LWS_EALREADY || - LWS_ERRNO == LWS_EINPROGRESS || - LWS_ERRNO == LWS_EWOULDBLOCK + /* + * The actual connection attempt + */ + +#if defined(LWS_WITH_DETAILED_LATENCY) + wsi->detlat.earliest_write_req = + wsi->detlat.earliest_write_req_pre_write = lws_now_usecs(); +#endif + +#if defined(LWS_ESP_PLATFORM) + errno = 0; +#endif + m = connect(wsi->desc.sockfd, (const struct sockaddr *)psa, n); + if (m == -1) { + int errno_copy = LWS_ERRNO; + + lwsl_debug("%s: connect says errno: %d\n", __func__, errno_copy); + + if (errno_copy && errno_copy != LWS_EALREADY && + errno_copy != LWS_EINPROGRESS && + errno_copy != LWS_EWOULDBLOCK #ifdef _WIN32 - || LWS_ERRNO == WSAEINVAL + && errno_copy != WSAEINVAL + && errno_copy != WSAEISCONN #endif ) { - lwsl_client("nonblocking connect retry (errno = %d)\n", - LWS_ERRNO); +#if defined(_DEBUG) + char nads[48]; + lws_sa46_write_numeric_address(&sa46, nads, sizeof(nads)); + lwsl_info("%s: Connect failed: %s port %d\n", + __func__, nads, port); +#endif + goto try_next_result_fds; + } - if (lws_plat_check_connection_error(wsi)) { - cce = "socket connect failed"; - goto failed; - } +#if defined(WIN32) + if (lws_plat_check_connection_error(wsi)) + goto try_next_result_fds; + if (errno_copy == WSAEISCONN) + goto conn_good; +#endif - /* - * must do specifically a POLLOUT poll to hear - * about the connect completion - */ - if (lws_change_pollfd(wsi, 0, LWS_POLLOUT)) { - cce = "POLLOUT set failed"; - goto failed; - } + /* + * Let's set a specialized timeout for this connect attempt + * completion, it uses wsi->sul_connect_timeout just for this + * purpose + */ - return wsi; - } + lws_sul_schedule(wsi->a.context, 0, &wsi->sul_connect_timeout, + lws_client_conn_wait_timeout, + wsi->a.context->timeout_secs * LWS_USEC_PER_SEC); - if (LWS_ERRNO != LWS_EISCONN) { - lwsl_notice("Connect failed errno=%d\n", LWS_ERRNO); - cce = "connect failed"; - goto failed; - } + /* + * must do specifically a POLLOUT poll to hear + * about the connect completion + */ +#if !defined(WIN32) + if (lws_change_pollfd(wsi, 0, LWS_POLLOUT)) + goto try_next_result_fds; +#endif + + return wsi; } +conn_good: + lws_sul_cancel(&wsi->sul_connect_timeout); + lwsl_info("%s: Connection started %p\n", __func__, wsi->dns_results); + + /* the tcp connection has happend */ + +#if defined(LWS_WITH_DETAILED_LATENCY) + if (wsi->a.context->detailed_latency_cb) { + wsi->detlat.type = LDLT_CONNECTION; + wsi->detlat.latencies[LAT_DUR_PROXY_CLIENT_REQ_TO_WRITE] = + lws_now_usecs() - + wsi->detlat.earliest_write_req_pre_write; + wsi->detlat.latencies[LAT_DUR_USERCB] = 0; + lws_det_lat_cb(wsi->a.context, &wsi->detlat); + wsi->detlat.earliest_write_req = + wsi->detlat.earliest_write_req_pre_write = + lws_now_usecs(); + } +#endif + lws_addrinfo_clean(wsi); - return lws_client_connect_3(wsi, NULL, plen); + if (wsi->a.protocol) + wsi->a.protocol->callback(wsi, LWS_CALLBACK_WSI_CREATE, + wsi->user_space, NULL, 0); + lwsl_debug("%s: going into connect_4\n", __func__); + return lws_client_connect_4_established(wsi, NULL, plen); oom4: - if (lwsi_role_client(wsi) && wsi->protocol /* && lwsi_state_est(wsi) */) + /* + * We get here if we're trying to clean up a connection attempt that + * didn't make it as far as getting inserted into the wsi / fd tables + */ + + if (lwsi_role_client(wsi) && wsi->a.protocol /* && lwsi_state_est(wsi) */) lws_inform_client_conn_fail(wsi,(void *)cce, strlen(cce)); /* take care that we might be inserted in fds already */ if (wsi->position_in_fds_table != LWS_NO_FDS_POS) + /* do the full wsi close flow */ goto failed1; /* @@ -752,16 +819,46 @@ * so nobody else should have had a chance to queue on us. */ { - struct lws_vhost *vhost = wsi->vhost; + struct lws_vhost *vhost = wsi->a.vhost; + lws_sockfd_type sfd = wsi->desc.sockfd; lws_vhost_lock(vhost); __lws_free_wsi(wsi); lws_vhost_unlock(vhost); + + sanity_assert_no_wsi_traces(vhost->context, wsi); + sanity_assert_no_sockfd_traces(vhost->context, sfd); } return NULL; -failed: +connect_to: + /* + * It looks like the sul_connect_timeout fired + */ + lwsl_info("%s: abandoning connect due to timeout\n", __func__); + +try_next_result_fds: + __remove_wsi_socket_from_fds(wsi); + +try_next_result_closesock: + /* + * We are killing the socket but leaving + */ + compatible_close(wsi->desc.sockfd); + wsi->desc.sockfd = LWS_SOCK_INVALID; + +try_next_result: + lws_sul_cancel(&wsi->sul_connect_timeout); + if (wsi->dns_results_next) { + wsi->dns_results_next = wsi->dns_results_next->ai_next; + if (wsi->dns_results_next) + goto next_result; + } + lws_addrinfo_clean(wsi); + cce = "Unable to connect"; + +//failed: lws_inform_client_conn_fail(wsi, (void *)cce, strlen(cce)); failed1: @@ -770,9 +867,275 @@ return NULL; } +struct lws * +lws_client_connect_2_dnsreq(struct lws *wsi) +{ + struct addrinfo *result = NULL; + const char *meth = NULL, *ads; +#if defined(LWS_WITH_IPV6) + struct sockaddr_in addr; + const char *iface; +#endif + const char *adsin; + int n, port = 0; + struct lws *w; + + if (lwsi_state(wsi) == LRS_WAITING_DNS || + lwsi_state(wsi) == LRS_WAITING_CONNECT) { + lwsl_info("%s: LRS_WAITING_DNS / CONNECT\n", __func__); + + return wsi; + } + + /* + * The first job is figure out if we want to pipeline on or just join + * an existing "active connection" to the same place + */ + + meth = lws_wsi_client_stash_item(wsi, CIS_METHOD, + _WSI_TOKEN_CLIENT_METHOD); + + /* we only pipeline connections that said it was okay */ + + if (!wsi->client_pipeline) { + lwsl_debug("%s: new conn on no pipeline flag\n", __func__); + + goto solo; + } + + /* only pipeline things we associate with being a stream */ + + if (meth && strcmp(meth, "RAW") && strcmp(meth, "GET") && + strcmp(meth, "POST") && strcmp(meth, "PUT") && + strcmp(meth, "UDP") && strcmp(meth, "MQTT")) + goto solo; + + /* consult active connections to find out disposition */ + + adsin = lws_wsi_client_stash_item(wsi, CIS_ADDRESS, + _WSI_TOKEN_CLIENT_PEER_ADDRESS); + + if (!adsin) + /* + * This cannot happen since user code must provide the client + * address to get this far, it's here to satisfy Coverity + */ + return NULL; + + switch (lws_vhost_active_conns(wsi, &w, adsin)) { + case ACTIVE_CONNS_SOLO: + break; + case ACTIVE_CONNS_MUXED: + lwsl_notice("%s: ACTIVE_CONNS_MUXED\n", __func__); + if (lwsi_role_h2(wsi)) { + + if (wsi->a.protocol->callback(wsi, + LWS_CALLBACK_ESTABLISHED_CLIENT_HTTP, + wsi->user_space, NULL, 0)) + goto failed1; + + //lwsi_set_state(wsi, LRS_H1C_ISSUE_HANDSHAKE2); + //lwsi_set_state(w, LRS_ESTABLISHED); + lws_callback_on_writable(wsi); + } + + return wsi; + case ACTIVE_CONNS_QUEUED: + lwsl_debug("%s: ACTIVE_CONNS_QUEUED st 0x%x: \n", __func__, lwsi_state(wsi)); + if (lwsi_state(wsi) == LRS_UNCONNECTED) { + if (lwsi_role_h2(w)) + lwsi_set_state(wsi, LRS_H2_WAITING_TO_SEND_HEADERS); + else + lwsi_set_state(wsi, LRS_H1C_ISSUE_HANDSHAKE2); + } + + return lws_client_connect_4_established(wsi, w, 0); + } + +solo: + wsi->addrinfo_idx = 0; + + /* + * clients who will create their own fresh connection keep a copy of + * the hostname they originally connected to, in case other connections + * want to use it too + */ + + if (!wsi->cli_hostname_copy) { + if (wsi->stash && wsi->stash->cis[CIS_HOST]) + wsi->cli_hostname_copy = + lws_strdup(wsi->stash->cis[CIS_HOST]); +#if defined(LWS_ROLE_H1) || defined(LWS_ROLE_H2) + else { + char *pa = lws_hdr_simple_ptr(wsi, + _WSI_TOKEN_CLIENT_PEER_ADDRESS); + if (pa) + wsi->cli_hostname_copy = lws_strdup(pa); + } +#endif + } + + /* + * If we made our own connection, and we're doing a method that can + * take a pipeline, we are an "active client connection". + * + * Add ourselves to the vhost list of those so that others can + * piggyback on our transaction queue + */ + + if (meth && (!strcmp(meth, "RAW") || !strcmp(meth, "GET") || + !strcmp(meth, "POST") || !strcmp(meth, "PUT") || + !strcmp(meth, "MQTT")) && + lws_dll2_is_detached(&wsi->dll2_cli_txn_queue) && + lws_dll2_is_detached(&wsi->dll_cli_active_conns)) { + lws_vhost_lock(wsi->a.vhost); + lwsl_info("%s: adding active conn %p\n", __func__, wsi); + /* caution... we will have to unpick this on oom4 path */ + lws_dll2_add_head(&wsi->dll_cli_active_conns, + &wsi->a.vhost->dll_cli_active_conns_owner); + lws_vhost_unlock(wsi->a.vhost); + } + + /* + * unix socket destination? + */ + + if (wsi->stash) + ads = wsi->stash->cis[CIS_ADDRESS]; + else + ads = lws_hdr_simple_ptr(wsi, _WSI_TOKEN_CLIENT_PEER_ADDRESS); + + /* + * Since address must be given at client creation, should not be + * possible, but necessary to satisfy coverity + */ + if (!ads) + return NULL; + +#if defined(LWS_WITH_UNIX_SOCK) + if (*ads == '+') { + wsi->unix_skt = 1; + n = 0; + goto next_step; + } +#endif + + /* + * start off allowing ipv6 on connection if vhost allows it + */ + wsi->ipv6 = LWS_IPV6_ENABLED(wsi->a.vhost); +#ifdef LWS_WITH_IPV6 + if (wsi->stash) + iface = wsi->stash->cis[CIS_IFACE]; + else + iface = lws_hdr_simple_ptr(wsi, _WSI_TOKEN_CLIENT_IFACE); + + if (wsi->ipv6 && iface && + inet_pton(AF_INET, iface, &addr.sin_addr) == 1) { + lwsl_notice("%s: client connection forced to IPv4\n", __func__); + wsi->ipv6 = 0; + } +#endif + +#if defined(LWS_WITH_DETAILED_LATENCY) + if (lwsi_state(wsi) == LRS_WAITING_DNS && + wsi->a.context->detailed_latency_cb) { + wsi->detlat.type = LDLT_NAME_RESOLUTION; + wsi->detlat.latencies[LAT_DUR_PROXY_CLIENT_REQ_TO_WRITE] = + lws_now_usecs() - + wsi->detlat.earliest_write_req_pre_write; + wsi->detlat.latencies[LAT_DUR_USERCB] = 0; + lws_det_lat_cb(wsi->a.context, &wsi->detlat); + wsi->detlat.earliest_write_req_pre_write = lws_now_usecs(); + } +#endif + +#if defined(LWS_CLIENT_HTTP_PROXYING) && \ + (defined(LWS_ROLE_H1) || defined(LWS_ROLE_H2)) + + /* Decide what it is we need to connect to: + * + * Priority 1: connect to http proxy */ + + if (wsi->a.vhost->http.http_proxy_port) { + ads = wsi->a.vhost->http.http_proxy_address; + port = wsi->a.vhost->http.http_proxy_port; +#else + if (0) { +#endif + +#if defined(LWS_WITH_SOCKS5) + + /* Priority 2: Connect to SOCK5 Proxy */ + + } else if (wsi->a.vhost->socks_proxy_port) { + lwsl_client("Sending SOCKS Greeting\n"); + ads = wsi->a.vhost->socks_proxy_address; + port = wsi->a.vhost->socks_proxy_port; +#endif + } else { + + /* Priority 3: Connect directly */ + + /* ads already set */ + port = wsi->c_port; + } + + /* + * prepare the actual connection + * to whatever we decided to connect to + */ + lwsi_set_state(wsi, LRS_WAITING_DNS); + + lwsl_info("%s: %p: lookup %s:%u\n", __func__, wsi, ads, port); + (void)port; + +#if defined(LWS_WITH_DETAILED_LATENCY) + wsi->detlat.earliest_write_req_pre_write = lws_now_usecs(); +#endif +#if !defined(LWS_WITH_SYS_ASYNC_DNS) + if (wsi->dns_results) + n = 0; + else + n = lws_getaddrinfo46(wsi, ads, &result); +#else + lwsi_set_state(wsi, LRS_WAITING_DNS); + /* this is either FAILED, CONTINUING, or already called connect_4 */ + + n = lws_async_dns_query(wsi->a.context, wsi->tsi, ads, LWS_ADNS_RECORD_A, + lws_client_connect_3_connect, wsi, NULL); + if (n == LADNS_RET_FAILED_WSI_CLOSED) + return NULL; + + if (n == LADNS_RET_FAILED) + goto failed1; + + return wsi; +#endif + +#if defined(LWS_WITH_UNIX_SOCK) +next_step: +#endif + return lws_client_connect_3_connect(wsi, ads, result, n, NULL); + +//#if defined(LWS_WITH_SYS_ASYNC_DNS) +failed1: + lws_close_free_wsi(wsi, LWS_CLOSE_STATUS_NOSTATUS, "client_connect2"); + + return NULL; +//#endif +} #if defined(LWS_ROLE_H1) || defined(LWS_ROLE_H2) +static uint8_t hnames2[] = { + _WSI_TOKEN_CLIENT_ORIGIN, + _WSI_TOKEN_CLIENT_SENT_PROTOCOLS, + _WSI_TOKEN_CLIENT_METHOD, + _WSI_TOKEN_CLIENT_IFACE, + _WSI_TOKEN_CLIENT_ALPN +}; + /** * lws_client_reset() - retarget a connected wsi to start over with a new * connection (ie, redirect) @@ -783,52 +1146,106 @@ * path: uri path to connect to on the new server * host: host header to send to the new server */ -LWS_VISIBLE struct lws * +struct lws * lws_client_reset(struct lws **pwsi, int ssl, const char *address, int port, - const char *path, const char *host) + const char *path, const char *host, char weak) { - char origin[300] = "", protocol[300] = "", method[32] = "", - iface[16] = "", alpn[32] = "", *p; +#if defined(LWS_ROLE_WS) + struct _lws_websocket_related *ws; +#endif + char *stash, *p; struct lws *wsi; + size_t size = 0; + int n; if (!pwsi) return NULL; wsi = *pwsi; + lwsl_debug("%s: wsi %p: redir %d: %s\n", __func__, wsi, wsi->redirects, + address); + if (wsi->redirects == 3) { lwsl_err("%s: Too many redirects\n", __func__); return NULL; } wsi->redirects++; - p = lws_hdr_simple_ptr(wsi, _WSI_TOKEN_CLIENT_ORIGIN); - if (p) - lws_strncpy(origin, p, sizeof(origin)); - - p = lws_hdr_simple_ptr(wsi, _WSI_TOKEN_CLIENT_SENT_PROTOCOLS); - if (p) - lws_strncpy(protocol, p, sizeof(protocol)); - - p = lws_hdr_simple_ptr(wsi, _WSI_TOKEN_CLIENT_METHOD); - if (p) - lws_strncpy(method, p, sizeof(method)); - - p = lws_hdr_simple_ptr(wsi, _WSI_TOKEN_CLIENT_IFACE); - if (p) - lws_strncpy(iface, p, sizeof(iface)); - - p = lws_hdr_simple_ptr(wsi, _WSI_TOKEN_CLIENT_ALPN); - if (p) - lws_strncpy(alpn, p, sizeof(alpn)); + /* + * goal is to close our role part, close the sockfd, detach the ah + * but leave our wsi extant and still bound to whatever vhost it was + */ + + for (n = 0; n < (int)LWS_ARRAY_SIZE(hnames2); n++) + size += lws_hdr_total_length(wsi, hnames2[n]) + (size_t)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 + * we are going to detach and reattch + */ + + size += strlen(path) + 1 + strlen(address) + 1 + strlen(host) + 1 + 1; + + p = stash = lws_malloc(size, __func__); + if (!stash) + return NULL; + + /* + * _WSI_TOKEN_CLIENT_ORIGIN, + * _WSI_TOKEN_CLIENT_SENT_PROTOCOLS, + * _WSI_TOKEN_CLIENT_METHOD, + * _WSI_TOKEN_CLIENT_IFACE, + * _WSI_TOKEN_CLIENT_ALPN + * address + * host + * path + */ + + for (n = 0; n < (int)LWS_ARRAY_SIZE(hnames2); n++) + if (lws_hdr_total_length(wsi, hnames2[n]) && + lws_hdr_simple_ptr(wsi, hnames2[n])) { + 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) + (size_t)1); + address = p; + p += strlen(address) + 1; + memcpy(p, host, strlen(host) + (size_t)1); + host = p; + p += strlen(host) + 1; + memcpy(p, path, strlen(path) + (size_t)1); + path = p; if (!port) { + lwsl_info("%s: forcing port 443\n", __func__); + port = 443; ssl = 1; } - lwsl_info("redirect ads='%s', port=%d, path='%s', ssl = %d\n", - address, port, path, ssl); + lwsl_info("redirect ads='%s', port=%d, path='%s', ssl = %d, pifds %d\n", + address, port, path, ssl, wsi->position_in_fds_table); + + __remove_wsi_socket_from_fds(wsi); +#if defined(LWS_ROLE_WS) + if (weak) { + ws = wsi->ws; + wsi->ws = NULL; + } +#endif + __lws_reset_wsi(wsi); /* detaches ah here */ +#if defined(LWS_ROLE_WS) + if (weak) + wsi->ws = ws; +#endif + wsi->client_pipeline = 1; /* close the connection by hand */ @@ -836,66 +1253,96 @@ lws_ssl_close(wsi); #endif - __remove_wsi_socket_from_fds(wsi); + if (wsi->role_ops && wsi->role_ops->close_kill_connection) + wsi->role_ops->close_kill_connection(wsi, 1); - if (wsi->context->event_loop_ops->close_handle_manually) - wsi->context->event_loop_ops->close_handle_manually(wsi); + if (wsi->a.context->event_loop_ops->close_handle_manually) + wsi->a.context->event_loop_ops->close_handle_manually(wsi); else - compatible_close(wsi->desc.sockfd); + if (wsi->desc.sockfd != LWS_SOCK_INVALID) + compatible_close(wsi->desc.sockfd); #if defined(LWS_WITH_TLS) - wsi->tls.use_ssl = ssl; + if (!ssl) + wsi->tls.use_ssl &= ~LCCSCF_USE_SSL; + else + wsi->tls.use_ssl |= LCCSCF_USE_SSL; #else if (ssl) { lwsl_err("%s: not configured for ssl\n", __func__); - return NULL; + goto bail; } #endif + if (wsi->a.protocol && wsi->role_ops && wsi->protocol_bind_balance) { + wsi->a.protocol->callback(wsi, + wsi->role_ops->protocol_unbind_cb[ + !!lwsi_role_server(wsi)], + wsi->user_space, (void *)__func__, 0); + + wsi->protocol_bind_balance = 0; + } + wsi->desc.sockfd = LWS_SOCK_INVALID; - lwsi_set_state(wsi, LRS_UNCONNECTED); - // wsi->protocol = NULL; + lws_role_transition(wsi, LWSIFR_CLIENT, LRS_UNCONNECTED, &role_ops_h1); +// wsi->a.protocol = NULL; + if (wsi->a.protocol) + lws_bind_protocol(wsi, wsi->a.protocol, "client_reset"); wsi->pending_timeout = NO_PENDING_TIMEOUT; wsi->c_port = port; wsi->hdr_parsing_completed = 0; - _lws_header_table_reset(wsi->http.ah); + + if (lws_header_table_attach(wsi, 0)) { + lwsl_err("%s: failed to get ah\n", __func__); + goto bail; + } + //_lws_header_table_reset(wsi->http.ah); if (lws_hdr_simple_create(wsi, _WSI_TOKEN_CLIENT_PEER_ADDRESS, address)) - return NULL; + goto bail; if (lws_hdr_simple_create(wsi, _WSI_TOKEN_CLIENT_HOST, host)) - return NULL; + goto bail; - if (origin[0]) - if (lws_hdr_simple_create(wsi, _WSI_TOKEN_CLIENT_ORIGIN, - origin)) - return NULL; - if (protocol[0]) - if (lws_hdr_simple_create(wsi, _WSI_TOKEN_CLIENT_SENT_PROTOCOLS, - protocol)) - return NULL; - if (method[0]) - if (lws_hdr_simple_create(wsi, _WSI_TOKEN_CLIENT_METHOD, - method)) - return NULL; + /* + * _WSI_TOKEN_CLIENT_ORIGIN, + * _WSI_TOKEN_CLIENT_SENT_PROTOCOLS, + * _WSI_TOKEN_CLIENT_METHOD, + * _WSI_TOKEN_CLIENT_IFACE, + * _WSI_TOKEN_CLIENT_ALPN + * address + * host + * path + */ - if (iface[0]) - if (lws_hdr_simple_create(wsi, _WSI_TOKEN_CLIENT_IFACE, - iface)) - return NULL; - if (alpn[0]) - if (lws_hdr_simple_create(wsi, _WSI_TOKEN_CLIENT_ALPN, - alpn)) - return NULL; + p = stash; + 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]) + (size_t)1; + } - origin[0] = '/'; - strncpy(&origin[1], path, sizeof(origin) - 2); - if (lws_hdr_simple_create(wsi, _WSI_TOKEN_CLIENT_URI, origin)) - return NULL; + stash[0] = '/'; + 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; - *pwsi = lws_client_connect_2(wsi); + lws_free_set_NULL(stash); + +#if defined(LWS_WITH_HTTP2) + if (wsi->client_mux_substream) + wsi->h2.END_STREAM = wsi->h2.END_HEADERS = 0; +#endif + + *pwsi = lws_client_connect_2_dnsreq(wsi); return *pwsi; + +bail: + lws_free_set_NULL(stash); + + return NULL; } #if defined(LWS_WITH_HTTP_PROXY) && defined(LWS_WITH_HUBBUB) @@ -904,36 +1351,43 @@ { struct lws_rewrite *r = (struct lws_rewrite *)pw; char buf[1024], *start = buf + LWS_PRE, *p = start, - *end = &buf[sizeof(buf) - 1]; + *end = &buf[sizeof(buf) - 1], dotstar[128]; size_t i; switch (token->type) { case HUBBUB_TOKEN_DOCTYPE: - p += lws_snprintf(p, end - p, "data.doctype.name.len, - token->data.doctype.name.ptr, - token->data.doctype.force_quirks ? + lws_strnncpy(dotstar, token->data.doctype.name.ptr, + token->data.doctype.name.len, sizeof(dotstar)); + + p += lws_snprintf(p, end - p, "data.doctype.force_quirks ? "(force-quirks) " : ""); if (token->data.doctype.public_missing) lwsl_debug("\tpublic: missing\n"); - else - p += lws_snprintf(p, end - p, "PUBLIC \"%.*s\"\n", - (int) token->data.doctype.public_id.len, - token->data.doctype.public_id.ptr); + else { + lws_strnncpy(dotstar, token->data.doctype.public_id.ptr, + token->data.doctype.public_id.len, + sizeof(dotstar)); + p += lws_snprintf(p, end - p, "PUBLIC \"%s\"\n", + dotstar); + } if (token->data.doctype.system_missing) lwsl_debug("\tsystem: missing\n"); - else - p += lws_snprintf(p, end - p, " \"%.*s\">\n", - (int) token->data.doctype.system_id.len, - token->data.doctype.system_id.ptr); + else { + lws_strnncpy(dotstar, token->data.doctype.system_id.ptr, + token->data.doctype.system_id.len, + sizeof(dotstar)); + p += lws_snprintf(p, end - p, " \"%s\">\n", dotstar); + } break; case HUBBUB_TOKEN_START_TAG: - p += lws_snprintf(p, end - p, "<%.*s", (int)token->data.tag.name.len, - token->data.tag.name.ptr); + lws_strnncpy(dotstar, token->data.tag.name.ptr, + token->data.tag.name.len, sizeof(dotstar)); + p += lws_snprintf(p, end - p, "<%s", dotstar); /* (token->data.tag.self_closing) ? "(self-closing) " : "", @@ -954,25 +1408,37 @@ pp += r->from_len; plen -= r->from_len; } - p += lws_snprintf(p, end - p, " %.*s=\"%s/%.*s\"", - (int) token->data.tag.attributes[i].name.len, - token->data.tag.attributes[i].name.ptr, - r->to, plen, pp); + lws_strnncpy(dotstar, + token->data.tag.attributes[i].name.ptr, + token->data.tag.attributes[i].name.len, + sizeof(dotstar)); + + p += lws_snprintf(p, end - p, " %s=\"%s", + dotstar, r->to); + lws_strnncpy(dotstar, pp, plen, sizeof(dotstar)); + p += lws_snprintf(p, end - p, " /%s\"", dotstar); continue; } } - p += lws_snprintf(p, end - p, " %.*s=\"%.*s\"", - (int) token->data.tag.attributes[i].name.len, + lws_strnncpy(dotstar, token->data.tag.attributes[i].name.ptr, - (int) token->data.tag.attributes[i].value.len, - token->data.tag.attributes[i].value.ptr); + token->data.tag.attributes[i].name.len, + sizeof(dotstar)); + + p += lws_snprintf(p, end - p, " %s=\"", dotstar); + lws_strnncpy(dotstar, + token->data.tag.attributes[i].value.ptr, + token->data.tag.attributes[i].value.len, + sizeof(dotstar)); + p += lws_snprintf(p, end - p, "%s\"", dotstar); } p += lws_snprintf(p, end - p, ">"); break; case HUBBUB_TOKEN_END_TAG: - p += lws_snprintf(p, end - p, "data.tag.name.len, - token->data.tag.name.ptr); + lws_strnncpy(dotstar, token->data.tag.name.ptr, + token->data.tag.name.len, sizeof(dotstar)); + p += lws_snprintf(p, end - p, "data.tag.self_closing) ? "(self-closing) " : "", @@ -980,18 +1446,23 @@ "attributes:" : ""); */ for (i = 0; i < token->data.tag.n_attributes; i++) { - p += lws_snprintf(p, end - p, " %.*s='%.*s'\n", - (int) token->data.tag.attributes[i].name.len, - token->data.tag.attributes[i].name.ptr, - (int) token->data.tag.attributes[i].value.len, - token->data.tag.attributes[i].value.ptr); + lws_strnncpy(dotstar, + token->data.tag.attributes[i].name.ptr, + token->data.tag.attributes[i].name.len, + sizeof(dotstar)); + p += lws_snprintf(p, end - p, " %s='", dotstar); + lws_strnncpy(dotstar, + token->data.tag.attributes[i].value.ptr, + token->data.tag.attributes[i].value.len, + sizeof(dotstar)); + p += lws_snprintf(p, end - p, "%s'\n", dotstar); } p += lws_snprintf(p, end - p, ">"); break; case HUBBUB_TOKEN_COMMENT: - p += lws_snprintf(p, end - p, "\n", - (int) token->data.comment.len, - token->data.comment.ptr); + lws_strnncpy(dotstar, token->data.comment.ptr, + token->data.comment.len, sizeof(dotstar)); + p += lws_snprintf(p, end - p, "\n", dotstar); break; case HUBBUB_TOKEN_CHARACTER: if (token->data.character.len == 1) { @@ -1008,17 +1479,17 @@ break; } } - - p += lws_snprintf(p, end - p, "%.*s", (int) token->data.character.len, - token->data.character.ptr); + lws_strnncpy(dotstar, token->data.character.ptr, + token->data.character.len, sizeof(dotstar)); + p += lws_snprintf(p, end - p, "%s", dotstar); break; case HUBBUB_TOKEN_EOF: p += lws_snprintf(p, end - p, "\n"); break; } - if (r->wsi->protocol_bind_balance && - user_callback_handle_rxflow(r->wsi->protocol->callback, + if (r->wsi->a.protocol_bind_balance && + user_callback_handle_rxflow(r->wsi->a.protocol->callback, r->wsi, LWS_CALLBACK_RECEIVE_CLIENT_HTTP_READ, r->wsi->user_space, start, p - start)) return -1; @@ -1029,19 +1500,32 @@ #endif +static const uint8_t hnames[] = { + _WSI_TOKEN_CLIENT_PEER_ADDRESS, + _WSI_TOKEN_CLIENT_URI, + _WSI_TOKEN_CLIENT_HOST, + _WSI_TOKEN_CLIENT_ORIGIN, + _WSI_TOKEN_CLIENT_SENT_PROTOCOLS, + _WSI_TOKEN_CLIENT_METHOD, + _WSI_TOKEN_CLIENT_IFACE, + _WSI_TOKEN_CLIENT_ALPN +}; + struct lws * lws_http_client_connect_via_info2(struct lws *wsi) { struct client_info_stash *stash = wsi->stash; + int n; lwsl_debug("%s: %p (stash %p)\n", __func__, wsi, stash); if (!stash) return wsi; - wsi->opaque_user_data = wsi->stash->opaque_user_data; + wsi->a.opaque_user_data = wsi->stash->opaque_user_data; - if (stash->method && !strcmp(stash->method, "RAW")) + if (stash->cis[CIS_METHOD] && (!strcmp(stash->cis[CIS_METHOD], "RAW") || + !strcmp(stash->cis[CIS_METHOD], "MQTT"))) goto no_ah; /* @@ -1049,149 +1533,27 @@ * stash them... we only need during connect phase so into a temp * allocated stash */ - if (lws_hdr_simple_create(wsi, _WSI_TOKEN_CLIENT_PEER_ADDRESS, - stash->address)) - goto bail1; - - if (lws_hdr_simple_create(wsi, _WSI_TOKEN_CLIENT_URI, stash->path)) - goto bail1; - - if (lws_hdr_simple_create(wsi, _WSI_TOKEN_CLIENT_HOST, stash->host)) - goto bail1; - - if (stash->origin) - if (lws_hdr_simple_create(wsi, _WSI_TOKEN_CLIENT_ORIGIN, - stash->origin)) - goto bail1; - /* - * this is a list of protocols we tell the server we're okay with - * stash it for later when we compare server response with it - */ - if (stash->protocol) - if (lws_hdr_simple_create(wsi, _WSI_TOKEN_CLIENT_SENT_PROTOCOLS, - stash->protocol)) - goto bail1; - if (stash->method) - if (lws_hdr_simple_create(wsi, _WSI_TOKEN_CLIENT_METHOD, - stash->method)) - goto bail1; - if (stash->iface) - if (lws_hdr_simple_create(wsi, _WSI_TOKEN_CLIENT_IFACE, - stash->iface)) - goto bail1; - if (stash->alpn) - if (lws_hdr_simple_create(wsi, _WSI_TOKEN_CLIENT_ALPN, - stash->alpn)) - goto bail1; + for (n = 0; n < (int)LWS_ARRAY_SIZE(hnames); n++) + if (hnames[n] && stash->cis[n]) { + if (lws_hdr_simple_create(wsi, hnames[n], stash->cis[n])) + goto bail1; + } #if defined(LWS_WITH_SOCKS5) - if (!wsi->vhost->socks_proxy_port) - lws_client_stash_destroy(wsi); + if (!wsi->a.vhost->socks_proxy_port) + lws_free_set_NULL(wsi->stash); #endif no_ah: - wsi->context->count_wsi_allocated++; + wsi->a.context->count_wsi_allocated++; - return lws_client_connect_2(wsi); + return lws_client_connect_2_dnsreq(wsi); bail1: #if defined(LWS_WITH_SOCKS5) - if (!wsi->vhost->socks_proxy_port) + if (!wsi->a.vhost->socks_proxy_port) lws_free_set_NULL(wsi->stash); #endif return NULL; } - -#if defined(LWS_WITH_SOCKS5) -int -socks_generate_msg(struct lws *wsi, enum socks_msg_type type, ssize_t *msg_len) -{ - struct lws_context *context = wsi->context; - struct lws_context_per_thread *pt = &context->pt[(int)wsi->tsi]; - uint8_t *p = pt->serv_buf, *end = &p[context->pt_serv_buf_size]; - ssize_t n, passwd_len; - short net_num; - char *cp; - - switch (type) { - case SOCKS_MSG_GREETING: - if (lws_ptr_diff(end, p) < 4) - return 1; - /* socks version, version 5 only */ - *p++ = SOCKS_VERSION_5; - /* number of methods */ - *p++ = 2; - /* username password method */ - *p++ = SOCKS_AUTH_USERNAME_PASSWORD; - /* no authentication method */ - *p++ = SOCKS_AUTH_NO_AUTH; - break; - - case SOCKS_MSG_USERNAME_PASSWORD: - n = strlen(wsi->vhost->socks_user); - passwd_len = strlen(wsi->vhost->socks_password); - - if (n > 254 || passwd_len > 254) - return 1; - - if (lws_ptr_diff(end, p) < 3 + n + passwd_len) - return 1; - - /* the subnegotiation version */ - *p++ = SOCKS_SUBNEGOTIATION_VERSION_1; - - /* length of the user name */ - *p++ = n; - /* user name */ - memcpy(p, wsi->vhost->socks_user, n); - p += n; - - /* length of the password */ - *p++ = passwd_len; - - /* password */ - memcpy(p, wsi->vhost->socks_password, passwd_len); - p += passwd_len; - break; - - case SOCKS_MSG_CONNECT: - n = strlen(wsi->stash->address); - - if (n > 254 || lws_ptr_diff(end, p) < 5 + n + 2) - return 1; - - cp = (char *)&net_num; - - /* socks version */ - *p++ = SOCKS_VERSION_5; - /* socks command */ - *p++ = SOCKS_COMMAND_CONNECT; - /* reserved */ - *p++ = 0; - /* address type */ - *p++ = SOCKS_ATYP_DOMAINNAME; - /* length of ---> */ - *p++ = n; - - /* the address we tell SOCKS proxy to connect to */ - memcpy(p, wsi->stash->address, n); - p += n; - - net_num = htons(wsi->c_port); - - /* the port we tell SOCKS proxy to connect to */ - *p++ = cp[0]; - *p++ = cp[1]; - - break; - - default: - return 1; - } - - *msg_len = lws_ptr_diff(p, pt->serv_buf); - - return 0; -} -#endif diff -Nru libwebsockets-3.2.1/lib/roles/http/client/client-http.c libwebsockets-4.1.6/lib/roles/http/client/client-http.c --- libwebsockets-3.2.1/lib/roles/http/client/client-http.c 1970-01-01 00:00:00.000000000 +0000 +++ libwebsockets-4.1.6/lib/roles/http/client/client-http.c 2020-12-01 17:40:26.000000000 +0000 @@ -0,0 +1,1508 @@ +/* + * libwebsockets - small server side websockets and web server implementation + * + * Copyright (C) 2010 - 2020 Andy Green + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to + * deal in the Software without restriction, including without limitation the + * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or + * sell copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS + * IN THE SOFTWARE. + */ + +#include "private-lib-core.h" + +#if defined(LWS_WITH_TLS) +int +lws_client_create_tls(struct lws *wsi, const char **pcce, int do_c1) +{ + + /* we can retry this... just cook the SSL BIO the first time */ + + if (wsi->tls.use_ssl & LCCSCF_USE_SSL) { + int n; + + if (!wsi->tls.ssl) { + if (lws_ssl_client_bio_create(wsi) < 0) { + *pcce = "bio_create failed"; + return CCTLS_RETURN_ERROR; + } + +#if defined(LWS_WITH_TLS) + if (!wsi->transaction_from_pipeline_queue && + lws_tls_restrict_borrow(wsi->a.context)) { + *pcce = "tls restriction limit"; + return CCTLS_RETURN_ERROR; + } +#endif + } + + if (!do_c1) + return 0; + + n = lws_ssl_client_connect1(wsi, (char *)wsi->a.context->pt[(int)wsi->tsi].serv_buf, + wsi->a.context->pt_serv_buf_size); + lwsl_debug("%s: lws_ssl_client_connect1: %d\n", __func__, n); + if (!n) + return CCTLS_RETURN_RETRY; /* caller should return 0 */ + if (n < 0) { + *pcce = (const char *)wsi->a.context->pt[(int)wsi->tsi].serv_buf; + return CCTLS_RETURN_ERROR; + } + } else + wsi->tls.ssl = NULL; + +#if defined (LWS_WITH_HTTP2) + if (wsi->client_h2_alpn) { + /* + * We connected to the server and set up tls, and + * negotiated "h2". + * + * So this is it, we are an h2 master client connection + * now, not an h1 client connection. + */ +#if defined(LWS_WITH_TLS) + lws_tls_server_conn_alpn(wsi); +#endif + + /* send the H2 preface to legitimize the connection */ + if (lws_h2_issue_preface(wsi)) { + *pcce = "error sending h2 preface"; + return CCTLS_RETURN_ERROR; + } + } +#endif + + return CCTLS_RETURN_DONE; /* OK */ +} + +#endif + +void +lws_client_http_body_pending(struct lws *wsi, int something_left_to_send) +{ + wsi->client_http_body_pending = !!something_left_to_send; +} + +int +lws_client_socket_service(struct lws *wsi, struct lws_pollfd *pollfd) +{ + struct lws_context *context = wsi->a.context; + struct lws_context_per_thread *pt = &context->pt[(int)wsi->tsi]; + char *p = (char *)&pt->serv_buf[0]; +#if defined(LWS_WITH_TLS) + char ebuf[128]; +#endif + const char *cce = NULL; + char *sb = p; + int n = 0; + + switch (lwsi_state(wsi)) { + + case LRS_WAITING_DNS: + /* + * we are under PENDING_TIMEOUT_SENT_CLIENT_HANDSHAKE + * timeout protection set in client-handshake.c + */ + lwsl_err("%s: wsi %p: WAITING_DNS\n", __func__, wsi); + if (!lws_client_connect_2_dnsreq(wsi)) { + /* closed */ + lwsl_client("closed\n"); + return -1; + } + + /* either still pending connection, or changed mode */ + return 0; + + case LRS_WAITING_CONNECT: + + /* + * we are under PENDING_TIMEOUT_SENT_CLIENT_HANDSHAKE + * timeout protection set in client-handshake.c + */ + if (pollfd->revents & LWS_POLLOUT) + lws_client_connect_3_connect(wsi, NULL, NULL, 0, NULL); + break; + +#if defined(LWS_WITH_SOCKS5) + /* SOCKS Greeting Reply */ + case LRS_WAITING_SOCKS_GREETING_REPLY: + case LRS_WAITING_SOCKS_AUTH_REPLY: + case LRS_WAITING_SOCKS_CONNECT_REPLY: + + switch (lws_socks5c_handle_state(wsi, pollfd, &cce)) { + case LW5CHS_RET_RET0: + return 0; + case LW5CHS_RET_BAIL3: + goto bail3; + case LW5CHS_RET_STARTHS: + goto start_ws_handshake; + default: + break; + } + break; +#endif + +#if defined(LWS_CLIENT_HTTP_PROXYING) && (defined(LWS_ROLE_H1) || defined(LWS_ROLE_H2)) + + case LRS_WAITING_PROXY_REPLY: + + /* handle proxy hung up on us */ + + if (pollfd->revents & LWS_POLLHUP) { + + lwsl_warn("Proxy connection %p (fd=%d) dead\n", + (void *)wsi, pollfd->fd); + + cce = "proxy conn dead"; + goto bail3; + } + + n = recv(wsi->desc.sockfd, sb, context->pt_serv_buf_size, 0); + if (n < 0) { + if (LWS_ERRNO == LWS_EAGAIN) { + lwsl_debug("Proxy read EAGAIN... retrying\n"); + return 0; + } + lwsl_err("ERROR reading from proxy socket\n"); + cce = "proxy read err"; + goto bail3; + } + + pt->serv_buf[13] = '\0'; + if (n < 13 || (strncmp(sb, "HTTP/1.0 200 ", 13) && + strncmp(sb, "HTTP/1.1 200 ", 13))) { + lwsl_err("%s: ERROR proxy did not reply with h1\n", + __func__); + /* lwsl_hexdump_notice(sb, n); */ + cce = "proxy not h1"; + goto bail3; + } + + lwsl_info("%s: proxy connection extablished\n", __func__); + + /* clear his proxy connection timeout */ + + lws_set_timeout(wsi, NO_PENDING_TIMEOUT, 0); + + /* fallthrough */ + +#endif + + case LRS_H1C_ISSUE_HANDSHAKE: + + /* + * we are under PENDING_TIMEOUT_SENT_CLIENT_HANDSHAKE + * timeout protection set in client-handshake.c + * + * take care of our lws_callback_on_writable + * happening at a time when there's no real connection yet + */ +#if defined(LWS_WITH_SOCKS5) +start_ws_handshake: +#endif + if (lws_change_pollfd(wsi, LWS_POLLOUT, 0)) + return -1; + +#if defined(LWS_WITH_TLS) + n = lws_client_create_tls(wsi, &cce, 1); + if (n < 0) + goto bail3; + if (n == 1) + return 0; + + /* fallthru */ + + case LRS_WAITING_SSL: + + if (wsi->tls.use_ssl & LCCSCF_USE_SSL) { + n = lws_ssl_client_connect2(wsi, ebuf, sizeof(ebuf)); + if (!n) + return 0; + if (n < 0) { + cce = ebuf; + goto bail3; + } + } else { + wsi->tls.ssl = NULL; + if(wsi->flags & LCCSCF_H2_PRIOR_KNOWLEDGE) { + lwsl_info("h2 prior knowledge\n"); + lws_role_call_alpn_negotiated(wsi, "h2"); + } + } +#endif +#if defined(LWS_WITH_DETAILED_LATENCY) + if (context->detailed_latency_cb) { + wsi->detlat.type = LDLT_TLS_NEG_CLIENT; + wsi->detlat.latencies[LAT_DUR_PROXY_CLIENT_REQ_TO_WRITE] = + lws_now_usecs() - + wsi->detlat.earliest_write_req_pre_write; + wsi->detlat.latencies[LAT_DUR_USERCB] = 0; + lws_det_lat_cb(wsi->a.context, &wsi->detlat); + } +#endif +#if defined (LWS_WITH_HTTP2) + if (wsi->client_h2_alpn) { + /* + * We connected to the server and set up tls and + * negotiated "h2" or connected as clear text + * with http/2 prior knowledge. + * + * So this is it, we are an h2 master client connection + * now, not an h1 client connection. + */ + +#if defined(LWS_WITH_TLS) + if (wsi->tls.use_ssl & LCCSCF_USE_SSL) { + lws_tls_server_conn_alpn(wsi); + } +#endif + + /* send the H2 preface to legitimize the connection */ + if (lws_h2_issue_preface(wsi)) { + cce = "error sending h2 preface"; + goto bail3; + } + + // lwsi_set_state(wsi, LRS_H1C_ISSUE_HANDSHAKE2); + lws_set_timeout(wsi, PENDING_TIMEOUT_AWAITING_CLIENT_HS_SEND, + context->timeout_secs); + + break; + } +#endif + + /* fallthru */ + + case LRS_H1C_ISSUE_HANDSHAKE2: + p = lws_generate_client_handshake(wsi, p); + if (p == NULL) { + if (wsi->role_ops == &role_ops_raw_skt +#if defined(LWS_ROLE_RAW_FILE) + || wsi->role_ops == &role_ops_raw_file +#endif + ) + return 0; + + lwsl_err("Failed to generate handshake for client\n"); + lws_close_free_wsi(wsi, LWS_CLOSE_STATUS_NOSTATUS, + "chs"); + return 0; + } + + /* send our request to the server */ + + lwsl_info("%s: HANDSHAKE2: %p: sending headers " + "(wsistate 0x%lx), w sock %d\n", + __func__, wsi, (unsigned long)wsi->wsistate, + wsi->desc.sockfd); +#if defined(LWS_WITH_DETAILED_LATENCY) + wsi->detlat.earliest_write_req_pre_write = lws_now_usecs(); +#endif + n = lws_ssl_capable_write(wsi, (unsigned char *)sb, (int)(p - sb)); + switch (n) { + case LWS_SSL_CAPABLE_ERROR: + lwsl_debug("ERROR writing to client socket\n"); + lws_close_free_wsi(wsi, LWS_CLOSE_STATUS_NOSTATUS, + "cws"); + return 0; + case LWS_SSL_CAPABLE_MORE_SERVICE: + lws_callback_on_writable(wsi); + break; + } + + if (wsi->client_http_body_pending) { + lwsl_debug("body pending\n"); + lwsi_set_state(wsi, LRS_ISSUE_HTTP_BODY); + lws_set_timeout(wsi, + PENDING_TIMEOUT_CLIENT_ISSUE_PAYLOAD, + context->timeout_secs); + + if (wsi->flags & LCCSCF_HTTP_X_WWW_FORM_URLENCODED) + lws_callback_on_writable(wsi); +#if defined(LWS_WITH_HTTP_PROXY) + if (wsi->http.proxy_clientside) + lws_callback_on_writable(wsi); +#endif + /* user code must ask for writable callback */ + break; + } + + lwsi_set_state(wsi, LRS_WAITING_SERVER_REPLY); + wsi->hdr_parsing_completed = 0; + + if (lwsi_state(wsi) == LRS_IDLING) { + lwsi_set_state(wsi, LRS_WAITING_SERVER_REPLY); + wsi->hdr_parsing_completed = 0; +#if defined(LWS_ROLE_H1) || defined(LWS_ROLE_H2) + wsi->http.ah->parser_state = WSI_TOKEN_NAME_PART; + wsi->http.ah->lextable_pos = 0; + wsi->http.ah->unk_pos = 0; + /* If we're (re)starting on hdr, need other implied init */ + wsi->http.ah->ues = URIES_IDLE; +#endif + } + + lws_set_timeout(wsi, PENDING_TIMEOUT_AWAITING_SERVER_RESPONSE, + wsi->a.context->timeout_secs); + + lws_callback_on_writable(wsi); + + goto client_http_body_sent; + + case LRS_ISSUE_HTTP_BODY: +#if defined(LWS_WITH_HTTP_PROXY) + if (wsi->http.proxy_clientside) { + lws_callback_on_writable(wsi); + break; + } +#endif + if (wsi->client_http_body_pending) { + //lws_set_timeout(wsi, + // PENDING_TIMEOUT_CLIENT_ISSUE_PAYLOAD, + // context->timeout_secs); + /* user code must ask for writable callback */ + break; + } +client_http_body_sent: +#if defined(LWS_ROLE_H1) || defined(LWS_ROLE_H2) + /* prepare ourselves to do the parsing */ + wsi->http.ah->parser_state = WSI_TOKEN_NAME_PART; + wsi->http.ah->lextable_pos = 0; + wsi->http.ah->unk_pos = 0; +#endif + lwsi_set_state(wsi, LRS_WAITING_SERVER_REPLY); + lws_set_timeout(wsi, PENDING_TIMEOUT_AWAITING_SERVER_RESPONSE, + context->timeout_secs); + break; + + case LRS_WAITING_SERVER_REPLY: + /* + * handle server hanging up on us... + * but if there is POLLIN waiting, handle that first + */ + if ((pollfd->revents & (LWS_POLLIN | LWS_POLLHUP)) == + LWS_POLLHUP) { + + lwsl_debug("Server connection %p (fd=%d) dead\n", + (void *)wsi, pollfd->fd); + cce = "Peer hung up"; + goto bail3; + } + + if (!(pollfd->revents & LWS_POLLIN)) + break; + +#if defined(LWS_ROLE_H1) || defined(LWS_ROLE_H2) + /* interpret the server response + * + * HTTP/1.1 101 Switching Protocols + * Upgrade: websocket + * Connection: Upgrade + * Sec-WebSocket-Accept: me89jWimTRKTWwrS3aRrL53YZSo= + * Sec-WebSocket-Nonce: AQIDBAUGBwgJCgsMDQ4PEC== + * Sec-WebSocket-Protocol: chat + * + * we have to take some care here to only take from the + * socket bytewise. The browser may (and has been seen to + * in the case that onopen() performs websocket traffic) + * coalesce both handshake response and websocket traffic + * in one packet, since at that point the connection is + * definitively ready from browser pov. + */ + while (wsi->http.ah->parser_state != WSI_PARSING_COMPLETE) { + struct lws_tokens eb; + int n, m, buffered; + + eb.token = NULL; + eb.len = 0; + buffered = lws_buflist_aware_read(pt, wsi, &eb, 0, __func__); + lwsl_debug("%s: buflist-aware-read %d %d\n", __func__, + buffered, eb.len); + if (eb.len == LWS_SSL_CAPABLE_MORE_SERVICE) + return 0; + if (buffered < 0 || eb.len < 0) { + cce = "read failed"; + goto bail3; + } + if (!eb.len) + return 0; + + n = eb.len; + if (lws_parse(wsi, eb.token, &n)) { + lwsl_warn("problems parsing header\n"); + cce = "problems parsing header"; + goto bail3; + } + + m = eb.len - n; + if (lws_buflist_aware_finished_consuming(wsi, &eb, m, + buffered, + __func__)) + return -1; + + /* + * coverity: uncomment if extended + * + * eb.token += m; + * eb.len -= m; + */ + + if (n) { + assert(wsi->http.ah->parser_state == + WSI_PARSING_COMPLETE); + + break; + } + } + + /* + * hs may also be coming in multiple packets, there is a 5-sec + * libwebsocket timeout still active here too, so if parsing did + * not complete just wait for next packet coming in this state + */ + if (wsi->http.ah->parser_state != WSI_PARSING_COMPLETE) + break; +#endif + + /* + * otherwise deal with the handshake. If there's any + * packet traffic already arrived we'll trigger poll() again + * right away and deal with it that way + */ + return lws_client_interpret_server_handshake(wsi); + +bail3: + lwsl_info("%s: closing conn at LWS_CONNMODE...SERVER_REPLY, wsi %p, state 0x%x\n", + __func__, wsi, lwsi_state(wsi)); + if (cce) + lwsl_info("reason: %s\n", cce); + else + cce = "unknown"; + lws_inform_client_conn_fail(wsi, (void *)cce, strlen(cce)); + + lws_close_free_wsi(wsi, LWS_CLOSE_STATUS_NOSTATUS, "cbail3"); + return -1; + + default: + break; + } + + return 0; +} + +#if defined(LWS_ROLE_H1) || defined(LWS_ROLE_H2) + +int LWS_WARN_UNUSED_RESULT +lws_http_transaction_completed_client(struct lws *wsi) +{ + struct lws_context_per_thread *pt = &wsi->a.context->pt[(int)wsi->tsi]; + int n; + + lwsl_info("%s: wsi: %p (%s)\n", __func__, wsi, wsi->a.protocol->name); + + if (user_callback_handle_rxflow(wsi->a.protocol->callback, wsi, + LWS_CALLBACK_COMPLETED_CLIENT_HTTP, + wsi->user_space, NULL, 0)) { + lwsl_debug("%s: Completed call returned nonzero (role 0x%lx)\n", + __func__, (unsigned long)lwsi_role(wsi)); + return -1; + } + + wsi->http.rx_content_length = 0; + + /* + * For h1, wsi may pass some assets on to a queued child and be + * destroyed during this. + */ + lws_pt_lock(pt, __func__); + n = _lws_generic_transaction_completed_active_conn(&wsi, 1); + lws_pt_unlock(pt); + + if (wsi->http.ah) { + if (wsi->client_mux_substream) + /* + * As an h2 client, once we did our transaction, that is + * it for us. Further transactions will happen as new + * SIDs on the connection. + */ + __lws_header_table_detach(wsi, 0); + else + if (!n) + _lws_header_table_reset(wsi->http.ah); + } + + if (!n || !wsi->http.ah) + return 0; + + /* + * H1: we can serialize the queued guys into the same ah + * H2: everybody needs their own ah until their own STREAM_END + */ + + /* otherwise set ourselves up ready to go again */ + lwsi_set_state(wsi, LRS_WAITING_SERVER_REPLY); + + wsi->http.ah->parser_state = WSI_TOKEN_NAME_PART; + wsi->http.ah->lextable_pos = 0; + wsi->http.ah->unk_pos = 0; + + lws_set_timeout(wsi, PENDING_TIMEOUT_AWAITING_SERVER_RESPONSE, + wsi->a.context->timeout_secs); + + /* If we're (re)starting on headers, need other implied init */ + wsi->http.ah->ues = URIES_IDLE; + lwsi_set_state(wsi, LRS_H1C_ISSUE_HANDSHAKE2); + + lwsl_info("%s: %p: new queued transaction\n", __func__, wsi); + lws_callback_on_writable(wsi); + + return 0; +} + +unsigned int +lws_http_client_http_response(struct lws *wsi) +{ + if (wsi->http.ah && wsi->http.ah->http_response) + return wsi->http.ah->http_response; + + return 0; +} +#endif + +#if defined(LWS_ROLE_H1) || defined(LWS_ROLE_H2) + +int +lws_http_is_redirected_to_get(struct lws *wsi) +{ + return wsi->redirected_to_get; +} + +int +lws_client_interpret_server_handshake(struct lws *wsi) +{ + int n, port = 0, ssl = 0; + int close_reason = LWS_CLOSE_STATUS_PROTOCOL_ERR; + const char *prot, *ads = NULL, *path, *cce = NULL; + struct allocated_headers *ah, *ah1; + struct lws *nwsi = lws_get_network_wsi(wsi); + char *p = NULL, *q, *simp; + char new_path[300]; + + lws_free_set_NULL(wsi->stash); + + ah = wsi->http.ah; + if (!wsi->do_ws) { + /* we are being an http client... + */ +#if defined(LWS_ROLE_H2) + if (wsi->client_h2_alpn || wsi->client_mux_substream) { + lwsl_debug("%s: %p: transitioning to h2 client\n", + __func__, wsi); + lws_role_transition(wsi, LWSIFR_CLIENT, + LRS_ESTABLISHED, &role_ops_h2); + } else +#endif + { +#if defined(LWS_ROLE_H1) + { + lwsl_debug("%s: %p: transitioning to h1 client\n", + __func__, wsi); + lws_role_transition(wsi, LWSIFR_CLIENT, + LRS_ESTABLISHED, &role_ops_h1); + } +#else + return -1; +#endif + } + + wsi->http.ah = ah; + ah->http_response = 0; + } + + /* + * well, what the server sent looked reasonable for syntax. + * Now let's confirm it sent all the necessary headers + * + * http (non-ws) client will expect something like this + * + * HTTP/1.0.200 + * server:.libwebsockets + * content-type:.text/html + * content-length:.17703 + * set-cookie:.test=LWS_1456736240_336776_COOKIE;Max-Age=360000 + */ + + wsi->http.conn_type = HTTP_CONNECTION_KEEP_ALIVE; + if (!wsi->client_mux_substream) { + p = lws_hdr_simple_ptr(wsi, WSI_TOKEN_HTTP); + /* + if (wsi->do_ws && !p) { + lwsl_info("no URI\n"); + cce = "HS: URI missing"; + goto bail3; + } + */ + if (!p) { + p = lws_hdr_simple_ptr(wsi, WSI_TOKEN_HTTP1_0); + wsi->http.conn_type = HTTP_CONNECTION_CLOSE; + } + if (!p) { + cce = "HS: URI missing"; + lwsl_info("no URI\n"); + goto bail3; + } +#if defined(LWS_ROLE_H2) + } else { + p = lws_hdr_simple_ptr(wsi, WSI_TOKEN_HTTP_COLON_STATUS); + if (!p) { + cce = "HS: :status missing"; + lwsl_info("no status\n"); + goto bail3; + } +#endif + } +#if !defined(LWS_ROLE_H2) + if (!p) { + cce = "HS: :status missing"; + lwsl_info("no status\n"); + goto bail3; + } +#endif + n = atoi(p); + if (ah) + ah->http_response = n; + + if (!wsi->client_no_follow_redirect && +#if defined(LWS_WITH_HTTP_PROXY) + !wsi->http.proxy_clientside && +#endif + (n == 301 || n == 302 || n == 303 || n == 307 || n == 308)) { + p = lws_hdr_simple_ptr(wsi, WSI_TOKEN_HTTP_LOCATION); + if (!p) { + cce = "HS: Redirect code but no Location"; + goto bail3; + } + + /* let's let the user code know, if he cares */ + + if (wsi->a.protocol->callback(wsi, + LWS_CALLBACK_CLIENT_HTTP_REDIRECT, + wsi->user_space, p, n)) { + cce = "HS: user code rejected redirect"; + goto bail3; + } + + /* + * Some redirect codes imply we have to change the method + * used for the subsequent transaction, commonly POST -> + * 303 -> GET. + */ + + if (n == 303) { + char *mp = lws_hdr_simple_ptr(wsi,_WSI_TOKEN_CLIENT_METHOD); + int ml = lws_hdr_total_length(wsi, _WSI_TOKEN_CLIENT_METHOD); + + if (ml >= 3 && mp) { + lwsl_info("%s: 303 switching to GET\n", __func__); + memcpy(mp, "GET", 4); + wsi->redirected_to_get = 1; + wsi->http.ah->frags[wsi->http.ah->frag_index[ + _WSI_TOKEN_CLIENT_METHOD]].len = 3; + } + } + + /* Relative reference absolute path */ + if (p[0] == '/' || !strchr(p, ':')) { +#if defined(LWS_WITH_TLS) + ssl = nwsi->tls.use_ssl & LCCSCF_USE_SSL; +#endif + ads = lws_hdr_simple_ptr(wsi, + _WSI_TOKEN_CLIENT_PEER_ADDRESS); + port = nwsi->c_port; + path = p; + /* lws_client_reset expects leading / omitted */ + if (*path == '/') + path++; + } + /* Absolute (Full) URI */ + else if (strchr(p, ':')) { + if (lws_parse_uri(p, &prot, &ads, &port, &path)) { + cce = "HS: URI did not parse"; + goto bail3; + } + + if (!strcmp(prot, "wss") || !strcmp(prot, "https")) + ssl = LCCSCF_USE_SSL; + } + /* Relative reference relative path */ + else { + /* This doesn't try to calculate an absolute path, + * that will be left to the server */ +#if defined(LWS_WITH_TLS) + ssl = nwsi->tls.use_ssl & LCCSCF_USE_SSL; +#endif + ads = lws_hdr_simple_ptr(wsi, + _WSI_TOKEN_CLIENT_PEER_ADDRESS); + port = wsi->c_port; + /* +1 as lws_client_reset expects leading / omitted */ + path = new_path + 1; + if (lws_hdr_simple_ptr(wsi, _WSI_TOKEN_CLIENT_URI)) + lws_strncpy(new_path, lws_hdr_simple_ptr(wsi, + _WSI_TOKEN_CLIENT_URI), sizeof(new_path)); + else { + new_path[0] = '/'; + new_path[1] = '\0'; + } + q = strrchr(new_path, '/'); + if (q) + lws_strncpy(q + 1, p, sizeof(new_path) - + (q - new_path) - 1); + else + path = p; + } + +#if defined(LWS_WITH_TLS) + if ((wsi->tls.use_ssl & LCCSCF_USE_SSL) && !ssl) { + cce = "HS: Redirect attempted SSL downgrade"; + goto bail3; + } +#endif + + if (!ads) /* make coverity happy */ { + cce = "no ads"; + goto bail3; + } + + if (!lws_client_reset(&wsi, ssl, ads, port, path, ads, 1)) { + /* + * There are two ways to fail out with NULL return... + * simple, early problem where the wsi is intact, or + * we went through with the reconnect attempt and the + * wsi is already closed. In the latter case, the wsi + * has been set to NULL additionally. + */ + lwsl_err("Redirect failed\n"); + cce = "HS: Redirect failed"; + /* coverity[reverse_inull] */ + if (wsi) + goto bail3; + + /* wsi has closed */ + return 1; + } + return 0; + } + + /* if h1 KA is allowed, enable the queued pipeline guys */ + + if (!wsi->client_h2_alpn && !wsi->client_mux_substream) { + /* ie, coming to this for the first time */ + if (wsi->http.conn_type == HTTP_CONNECTION_KEEP_ALIVE) + wsi->keepalive_active = 1; + else { + /* + * Ugh... now the main http connection has seen + * both sides, we learn the server doesn't + * support keepalive. + * + * That means any guys queued on us are going + * to have to be restarted from connect2 with + * their own connections. + */ + + /* + * stick around telling any new guys they can't + * pipeline to this server + */ + wsi->keepalive_rejected = 1; + + lws_vhost_lock(wsi->a.vhost); + lws_start_foreach_dll_safe(struct lws_dll2 *, + d, d1, + wsi->dll2_cli_txn_queue_owner.head) { + struct lws *ww = lws_container_of(d, + struct lws, + dll2_cli_txn_queue); + + /* remove him from our queue */ + lws_dll2_remove(&ww->dll2_cli_txn_queue); + /* give up on pipelining */ + ww->client_pipeline = 0; + + /* go back to "trying to connect" state */ + lws_role_transition(ww, LWSIFR_CLIENT, + LRS_UNCONNECTED, +#if defined(LWS_ROLE_H1) + &role_ops_h1); +#else +#if defined (LWS_ROLE_H2) + &role_ops_h2); +#else + &role_ops_raw); +#endif +#endif + ww->user_space = NULL; + } lws_end_foreach_dll_safe(d, d1); + lws_vhost_unlock(wsi->a.vhost); + } + } + +#ifdef LWS_WITH_HTTP_PROXY + wsi->http.perform_rewrite = 0; + if (lws_hdr_total_length(wsi, WSI_TOKEN_HTTP_CONTENT_TYPE)) { + if (!strncmp(lws_hdr_simple_ptr(wsi, + WSI_TOKEN_HTTP_CONTENT_TYPE), + "text/html", 9)) + wsi->http.perform_rewrite = 0; + } +#endif + + /* he may choose to send us stuff in chunked transfer-coding */ + wsi->chunked = 0; + wsi->chunk_remaining = 0; /* ie, next thing is chunk size */ + if (lws_hdr_total_length(wsi, WSI_TOKEN_HTTP_TRANSFER_ENCODING)) { + simp = lws_hdr_simple_ptr(wsi, WSI_TOKEN_HTTP_TRANSFER_ENCODING); + + /* cannot be NULL, since it has nonzero length... coverity */ + if (!simp) + goto bail2; + wsi->chunked = !strcmp(simp, "chunked"); + /* first thing is hex, after payload there is crlf */ + wsi->chunk_parser = ELCP_HEX; + } + + wsi->http.content_length_given = 0; + if (lws_hdr_total_length(wsi, WSI_TOKEN_HTTP_CONTENT_LENGTH)) { + simp = lws_hdr_simple_ptr(wsi, WSI_TOKEN_HTTP_CONTENT_LENGTH); + + /* cannot be NULL, since it has nonzero length... coverity */ + if (!simp) + goto bail2; + + wsi->http.rx_content_length = atoll(simp); + lwsl_info("%s: incoming content length %llu\n", + __func__, (unsigned long long) + wsi->http.rx_content_length); + wsi->http.rx_content_remain = + wsi->http.rx_content_length; + wsi->http.content_length_given = 1; + } else { /* can't do 1.1 without a content length or chunked */ + if (!wsi->chunked) + wsi->http.conn_type = HTTP_CONNECTION_CLOSE; + lwsl_debug("%s: no content length\n", __func__); + } + + if (wsi->do_ws) { + /* + * Give one last opportunity to ws protocols to inspect server reply + * before the ws upgrade code discard it. ie: download reply body in case + * of any other response code than 101. + */ + if (wsi->a.protocol->callback(wsi, + LWS_CALLBACK_ESTABLISHED_CLIENT_HTTP, + wsi->user_space, NULL, 0)) { + + cce = "HS: disallowed by client filter"; + goto bail2; + } + } else { + /* allocate the per-connection user memory (if any) */ + if (lws_ensure_user_space(wsi)) { + lwsl_err("Problem allocating wsi user mem\n"); + cce = "HS: OOM"; + goto bail2; + } + + + /* + * we seem to be good to go, give client last chance to check + * headers and OK it + */ + ah1 = wsi->http.ah; + wsi->http.ah = ah; + if (wsi->a.protocol->callback(wsi, + LWS_CALLBACK_CLIENT_FILTER_PRE_ESTABLISH, + wsi->user_space, NULL, 0)) { + wsi->http.ah = ah1; + cce = "HS: disallowed by client filter"; + goto bail2; + } + + /* clear his proxy connection timeout */ + lws_set_timeout(wsi, NO_PENDING_TIMEOUT, 0); + + wsi->rxflow_change_to = LWS_RXFLOW_ALLOW; + + /* call him back to inform him he is up */ + if (wsi->a.protocol->callback(wsi, + LWS_CALLBACK_ESTABLISHED_CLIENT_HTTP, + wsi->user_space, NULL, 0)) { + wsi->http.ah = ah1; + cce = "HS: disallowed at ESTABLISHED"; + goto bail3; + } + + wsi->http.ah = ah1; + + lwsl_info("%s: wsi %p: client connection up\n", __func__, wsi); + + /* + * Did we get a response from the server with an explicit + * content-length of zero? If so, this transaction is already + * completed at the end of the header processing... + */ + if (lws_hdr_total_length(wsi, WSI_TOKEN_HTTP_CONTENT_LENGTH) && + !wsi->http.rx_content_length) + return !!lws_http_transaction_completed_client(wsi); + + /* + * We can also get a case where it's http/1 and there's no + * content-length at all, so anything that comes is the body + * until it hangs up on us. With that situation, hanging up + * on us past this point should generate a valid + * LWS_CALLBACK_COMPLETED_CLIENT_HTTP. + * + * In that situation, he can't pipeline because in h1 there's + * no post-header in-band way to signal the end of the + * transaction except hangup. + * + * lws_http_transaction_completed_client() is the right guy to + * issue it when we see the peer has hung up on us. + */ + + return 0; + } + +#if defined(LWS_ROLE_WS) + switch (lws_client_ws_upgrade(wsi, &cce)) { + case 2: + goto bail2; + case 3: + goto bail3; + } + + return 0; +#endif + +bail3: + close_reason = LWS_CLOSE_STATUS_NOSTATUS; + +bail2: + if (wsi->a.protocol) { + n = 0; + if (cce) + n = (int)strlen(cce); + + lws_inform_client_conn_fail(wsi, (void *)cce, (unsigned int)n); + } + + lwsl_info("closing connection (prot %s) " + "due to bail2 connection error: %s\n", wsi->a.protocol ? + wsi->a.protocol->name : "unknown", cce); + + /* closing will free up his parsing allocations */ + lws_close_free_wsi(wsi, close_reason, "c hs interp"); + + return 1; +} +#endif + +/* + * set the boundary string and the content-type for client multipart mime + */ + +uint8_t * +lws_http_multipart_headers(struct lws *wsi, uint8_t *p) +{ + char buf[10], arg[48]; + int n; + + if (lws_get_random(wsi->a.context, (uint8_t *)buf, sizeof(buf)) != + sizeof(buf)) + return NULL; + + lws_b64_encode_string(buf, sizeof(buf), + wsi->http.multipart_boundary, + sizeof(wsi->http.multipart_boundary)); + + n = lws_snprintf(arg, sizeof(arg), "multipart/form-data; boundary=\"%s\"", + wsi->http.multipart_boundary); + + if (lws_add_http_header_by_token(wsi, WSI_TOKEN_HTTP_CONTENT_TYPE, + (uint8_t *)arg, n, &p, p + 100)) + return NULL; + + wsi->http.multipart = wsi->http.multipart_issue_boundary = 1; + lws_client_http_body_pending(wsi, 1); + + return p; +} + +int +lws_client_http_multipart(struct lws *wsi, const char *name, + const char *filename, const char *content_type, + char **p, char *end) +{ + /* + * Client conn must have been created with LCCSCF_HTTP_MULTIPART_MIME + * flag to use this api + */ + assert(wsi->http.multipart); + + if (!name) { + *p += lws_snprintf((char *)(*p), lws_ptr_diff(end, *p), + "\xd\xa--%s--\xd\xa", + wsi->http.multipart_boundary); + + return 0; + } + + if (wsi->client_subsequent_mime_part) + *p += lws_snprintf((char *)(*p), lws_ptr_diff(end, *p), "\xd\xa"); + wsi->client_subsequent_mime_part = 1; + + *p += lws_snprintf((char *)(*p), lws_ptr_diff(end, *p), "--%s\xd\xa" + "Content-Disposition: form-data; " + "name=\"%s\"", + wsi->http.multipart_boundary, name); + if (filename) + *p += lws_snprintf((char *)(*p), lws_ptr_diff(end, *p), + "; filename=\"%s\"", filename); + + if (content_type) + *p += lws_snprintf((char *)(*p), lws_ptr_diff(end, *p), "\xd\xa" + "Content-Type: %s", content_type); + + *p += lws_snprintf((char *)(*p), lws_ptr_diff(end, *p), "\xd\xa\xd\xa"); + + return *p == end; +} + +char * +lws_generate_client_handshake(struct lws *wsi, char *pkt) +{ + const char *meth, *pp = lws_hdr_simple_ptr(wsi, + _WSI_TOKEN_CLIENT_SENT_PROTOCOLS); + char *p = pkt, *p1; + + meth = lws_hdr_simple_ptr(wsi, _WSI_TOKEN_CLIENT_METHOD); + if (!meth) { + meth = "GET"; + wsi->do_ws = 1; + } else { + wsi->do_ws = 0; + } + + if (!strcmp(meth, "RAW")) { + lws_set_timeout(wsi, NO_PENDING_TIMEOUT, 0); + lwsl_notice("client transition to raw\n"); + + if (pp) { + const struct lws_protocols *pr; + + pr = lws_vhost_name_to_protocol(wsi->a.vhost, pp); + + if (!pr) { + lwsl_err("protocol %s not enabled on vhost\n", + pp); + return NULL; + } + + lws_bind_protocol(wsi, pr, __func__); + } + + if ((wsi->a.protocol->callback)(wsi, LWS_CALLBACK_RAW_ADOPT, + wsi->user_space, NULL, 0)) + return NULL; + + lws_role_transition(wsi, LWSIFR_CLIENT, LRS_ESTABLISHED, + &role_ops_raw_skt); + lws_header_table_detach(wsi, 1); + + return NULL; + } + + /* + * 04 example client handshake + * + * GET /chat HTTP/1.1 + * Host: server.example.com + * Upgrade: websocket + * Connection: Upgrade + * Sec-WebSocket-Key: dGhlIHNhbXBsZSBub25jZQ== + * Sec-WebSocket-Origin: http://example.com + * Sec-WebSocket-Protocol: chat, superchat + * Sec-WebSocket-Version: 4 + */ + + p += lws_snprintf(p, 2048, "%s %s HTTP/1.1\x0d\x0a", meth, + lws_hdr_simple_ptr(wsi, _WSI_TOKEN_CLIENT_URI)); + + p += lws_snprintf(p, 64, "Pragma: no-cache\x0d\x0a" + "Cache-Control: no-cache\x0d\x0a"); + + p += lws_snprintf(p, 128, "Host: %s\x0d\x0a", + lws_hdr_simple_ptr(wsi, _WSI_TOKEN_CLIENT_HOST)); + + if (lws_hdr_simple_ptr(wsi, _WSI_TOKEN_CLIENT_ORIGIN)) { + if (lws_check_opt(wsi->a.context->options, + LWS_SERVER_OPTION_JUST_USE_RAW_ORIGIN)) + p += lws_snprintf(p, 128, "Origin: %s\x0d\x0a", + lws_hdr_simple_ptr(wsi, + _WSI_TOKEN_CLIENT_ORIGIN)); + else + p += lws_snprintf(p, 128, "Origin: http://%s\x0d\x0a", + lws_hdr_simple_ptr(wsi, + _WSI_TOKEN_CLIENT_ORIGIN)); + } + + if (wsi->flags & LCCSCF_HTTP_MULTIPART_MIME) { + p1 = (char *)lws_http_multipart_headers(wsi, (uint8_t *)p); + if (!p1) + return NULL; + p = p1; + } + +#if defined(LWS_WITH_HTTP_PROXY) + if (wsi->parent && + lws_hdr_total_length(wsi->parent, WSI_TOKEN_HTTP_CONTENT_LENGTH)) { + p += lws_snprintf(p, 128, "Content-Length: %s\x0d\x0a", + lws_hdr_simple_ptr(wsi->parent, WSI_TOKEN_HTTP_CONTENT_LENGTH)); + if (atoi(lws_hdr_simple_ptr(wsi->parent, WSI_TOKEN_HTTP_CONTENT_LENGTH))) + wsi->client_http_body_pending = 1; + } + if (wsi->parent && + lws_hdr_total_length(wsi->parent, WSI_TOKEN_HTTP_AUTHORIZATION)) { + p += lws_snprintf(p, 128, "Authorization: %s\x0d\x0a", + lws_hdr_simple_ptr(wsi->parent, WSI_TOKEN_HTTP_AUTHORIZATION)); + } + if (wsi->parent && + lws_hdr_total_length(wsi->parent, WSI_TOKEN_HTTP_CONTENT_TYPE)) { + p += lws_snprintf(p, 128, "Content-Type: %s\x0d\x0a", + lws_hdr_simple_ptr(wsi->parent, WSI_TOKEN_HTTP_CONTENT_TYPE)); + } +#endif + +#if defined(LWS_ROLE_WS) + if (wsi->do_ws) { + const char *conn1 = ""; + // if (!wsi->client_pipeline) + // conn1 = "close, "; + p = lws_generate_client_ws_handshake(wsi, p, conn1); + } else +#endif + { + if (!wsi->client_pipeline) + p += lws_snprintf(p, 64, "connection: close\x0d\x0a"); + } + + /* give userland a chance to append, eg, cookies */ + + if (wsi->a.protocol->callback(wsi, + LWS_CALLBACK_CLIENT_APPEND_HANDSHAKE_HEADER, + wsi->user_space, &p, + (pkt + wsi->a.context->pt_serv_buf_size) - p - 12)) + return NULL; + + if (wsi->flags & LCCSCF_HTTP_X_WWW_FORM_URLENCODED) { + p += lws_snprintf(p, 128, "Content-Type: application/x-www-form-urlencoded\x0d\x0a"); + p += lws_snprintf(p, 128, "Content-Length: %lu\x0d\x0a", wsi->http.writeable_len); + lws_client_http_body_pending(wsi, 1); + } + + p += lws_snprintf(p, 4, "\x0d\x0a"); + + if (wsi->client_http_body_pending) + lws_callback_on_writable(wsi); + + // puts(pkt); + + return p; +} + +#if defined(LWS_ROLE_H1) || defined(LWS_ROLE_H2) +#if defined(LWS_WITH_HTTP_BASIC_AUTH) + +int +lws_http_basic_auth_gen(const char *user, const char *pw, char *buf, size_t len) +{ + size_t n = strlen(user), m = strlen(pw); + char b[128]; + + if (len < 6 + ((4 * (n + m + 1)) / 3) + 1) + return 1; + + memcpy(buf, "Basic ", 6); + + n = lws_snprintf(b, sizeof(b), "%s:%s", user, pw); + if (n >= sizeof(b) - 2) + return 2; + + lws_b64_encode_string(b, (int)n, buf + 6, (int)len - 6); + buf[len - 1] = '\0'; + + return 0; +} + +#endif + +int +lws_http_client_read(struct lws *wsi, char **buf, int *len) +{ + struct lws_context_per_thread *pt = &wsi->a.context->pt[(int)wsi->tsi]; + struct lws_tokens eb; + int buffered, n, consumed = 0; + + /* + * If the caller provided a non-NULL *buf and nonzero *len, we should + * use that as the buffer for the read action, limititing it to *len + * (actual payload will be less if chunked headers inside). + * + * If it's NULL / 0 length, buflist_aware_read will use the pt_serv_buf + */ + + eb.token = (unsigned char *)*buf; + eb.len = *len; + + buffered = lws_buflist_aware_read(pt, wsi, &eb, 0, __func__); + *buf = (char *)eb.token; /* may be pointing to buflist or pt_serv_buf */ + *len = 0; + + /* + * we're taking on responsibility for handling used / unused eb + * when we leave, via lws_buflist_aware_finished_consuming() + */ + +// lwsl_notice("%s: eb.len %d ENTRY chunk remaining %d\n", __func__, eb.len, +// wsi->chunk_remaining); + + /* allow the source to signal he has data again next time */ + if (lws_change_pollfd(wsi, 0, LWS_POLLIN)) + return -1; + + if (buffered < 0) { + lwsl_debug("%s: SSL capable error\n", __func__); + + if (wsi->http.ah && + wsi->http.ah->parser_state == WSI_PARSING_COMPLETE && + !lws_hdr_total_length(wsi, WSI_TOKEN_HTTP_CONTENT_LENGTH)) + /* + * We had the headers from this stream, but as there + * was no content-length: we had to wait until the + * stream ended to inform the user code the transaction + * has completed to the best of our knowledge + */ + if (lws_http_transaction_completed_client(wsi)) + /* + * We're going to close anyway, but that api has + * warn_unused_result + */ + return -1; + + return -1; + } + + if (eb.len <= 0) + return 0; + + *len = eb.len; + wsi->client_rx_avail = 0; + + /* + * server may insist on transfer-encoding: chunked, + * so http client must deal with it + */ +spin_chunks: + //lwsl_notice("%s: len %d SPIN chunk remaining %d\n", __func__, *len, + // wsi->chunk_remaining); + while (wsi->chunked && (wsi->chunk_parser != ELCP_CONTENT) && *len) { + switch (wsi->chunk_parser) { + case ELCP_HEX: + if ((*buf)[0] == '\x0d') { + wsi->chunk_parser = ELCP_CR; + break; + } + n = char_to_hex((*buf)[0]); + if (n < 0) { + lwsl_err("%s: chunking failure A\n", __func__); + return -1; + } + wsi->chunk_remaining <<= 4; + wsi->chunk_remaining |= n; + break; + case ELCP_CR: + if ((*buf)[0] != '\x0a') { + lwsl_err("%s: chunking failure B\n", __func__); + return -1; + } + if (wsi->chunk_remaining) { + wsi->chunk_parser = ELCP_CONTENT; + //lwsl_notice("starting chunk size %d (block rem %d)\n", + // wsi->chunk_remaining, *len); + break; + } + + wsi->chunk_parser = ELCP_TRAILER_CR; + break; + + case ELCP_CONTENT: + break; + + case ELCP_POST_CR: + if ((*buf)[0] != '\x0d') { + lwsl_err("%s: chunking failure C\n", __func__); + lwsl_hexdump_err(*buf, *len); + + return -1; + } + + wsi->chunk_parser = ELCP_POST_LF; + break; + + case ELCP_POST_LF: + if ((*buf)[0] != '\x0a') { + lwsl_err("%s: chunking failure D\n", __func__); + + return -1; + } + + wsi->chunk_parser = ELCP_HEX; + wsi->chunk_remaining = 0; + break; + + case ELCP_TRAILER_CR: + if ((*buf)[0] != '\x0d') { + lwsl_err("%s: chunking failure F\n", __func__); + lwsl_hexdump_err(*buf, *len); + + return -1; + } + + wsi->chunk_parser = ELCP_TRAILER_LF; + break; + + case ELCP_TRAILER_LF: + if ((*buf)[0] != '\x0a') { + lwsl_err("%s: chunking failure F\n", __func__); + lwsl_hexdump_err(*buf, *len); + + return -1; + } + + (*buf)++; + (*len)--; + consumed++; + + lwsl_info("final chunk\n"); + goto completed; + } + (*buf)++; + (*len)--; + consumed++; + } + + if (wsi->chunked && !wsi->chunk_remaining) + goto account_and_ret; + + if (wsi->http.rx_content_remain && + wsi->http.rx_content_remain < (unsigned int)*len) + n = (int)wsi->http.rx_content_remain; + else + n = *len; + + if (wsi->chunked && wsi->chunk_remaining && + wsi->chunk_remaining < n) + n = wsi->chunk_remaining; + +#if defined(LWS_WITH_HTTP_PROXY) && defined(LWS_WITH_HUBBUB) + /* hubbub */ + if (wsi->http.perform_rewrite) + lws_rewrite_parse(wsi->http.rw, (unsigned char *)*buf, n); + else +#endif + { + if ( +#if defined(LWS_WITH_HTTP_PROXY) + !wsi->protocol_bind_balance == + !!wsi->http.proxy_clientside +#else + !!wsi->protocol_bind_balance +#endif + ) { + int q; + + q = user_callback_handle_rxflow(wsi->a.protocol->callback, + wsi, LWS_CALLBACK_RECEIVE_CLIENT_HTTP_READ, + wsi->user_space, *buf, n); + if (q) { + lwsl_info("%s: RECEIVE_CLIENT_HTTP_READ returned %d\n", + __func__, q); + + return q; + } + } else + lwsl_notice("%s: swallowed read (%d)\n", __func__, n); + } + + (*buf) += n; + *len -= n; + if (wsi->chunked && wsi->chunk_remaining) + wsi->chunk_remaining -= n; + + //lwsl_notice("chunk_remaining <- %d, block remaining %d\n", + // wsi->chunk_remaining, *len); + + consumed += n; + //eb.token += n; + //eb.len -= n; + + if (wsi->chunked && !wsi->chunk_remaining) + wsi->chunk_parser = ELCP_POST_CR; + + if (wsi->chunked && *len) + goto spin_chunks; + + if (wsi->chunked) + goto account_and_ret; + + /* if we know the content length, decrement the content remaining */ + if (wsi->http.rx_content_length > 0) + wsi->http.rx_content_remain -= n; + + // lwsl_notice("rx_content_remain %lld, rx_content_length %lld, giv %d\n", + // wsi->http.rx_content_remain, wsi->http.rx_content_length, + // wsi->http.content_length_given); + + if (wsi->http.rx_content_remain || !wsi->http.content_length_given) + goto account_and_ret; + +completed: + + if (lws_http_transaction_completed_client(wsi)) { + lwsl_notice("%s: transaction completed says -1\n", __func__); + return -1; + } + +account_and_ret: +// lwsl_warn("%s: on way out, consuming %d / %d\n", __func__, consumed, eb.len); + if (lws_buflist_aware_finished_consuming(wsi, &eb, consumed, buffered, + __func__)) + return -1; + + return 0; +} + +#endif diff -Nru libwebsockets-3.2.1/lib/roles/http/CMakeLists.txt libwebsockets-4.1.6/lib/roles/http/CMakeLists.txt --- libwebsockets-3.2.1/lib/roles/http/CMakeLists.txt 1970-01-01 00:00:00.000000000 +0000 +++ libwebsockets-4.1.6/lib/roles/http/CMakeLists.txt 2020-12-01 17:40:26.000000000 +0000 @@ -0,0 +1,90 @@ +# +# libwebsockets - small server side websockets and web server implementation +# +# Copyright (C) 2010 - 2020 Andy Green +# +# Permission is hereby granted, free of charge, to any person obtaining a copy +# of this software and associated documentation files (the "Software"), to +# deal in the Software without restriction, including without limitation the +# rights to use, copy, modify, merge, publish, distribute, sublicense, and/or +# sell copies of the Software, and to permit persons to whom the Software is +# furnished to do so, subject to the following conditions: +# +# The above copyright notice and this permission notice shall be included in +# all copies or substantial portions of the Software. +# +# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING +# FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS +# IN THE SOFTWARE. +# +# The strategy is to only export to PARENT_SCOPE +# +# - changes to LIB_LIST +# - changes to SOURCES +# - includes via include_directories +# +# and keep everything else private + +include_directories(. ./compression) + +list(APPEND SOURCES + roles/http/header.c + roles/http/parsers.c) + +if (NOT LWS_WITHOUT_SERVER) + list(APPEND SOURCES + roles/http/server/server.c + roles/http/server/lws-spa.c) +endif() + +if (LWS_WITH_HTTP_PROXY AND LWS_WITH_HUBBUB) + list(APPEND SOURCES + roles/http/server/rewrite.c) +endif() + +if (LWS_WITH_ACCESS_LOG) + list(APPEND SOURCES + roles/http/server/access-log.c) +endif() + +if (LWS_WITH_HTTP_STREAM_COMPRESSION) + list(APPEND SOURCES + roles/http/compression/stream.c + roles/http/compression/deflate/deflate.c) + + if (LWS_WITH_HTTP_BROTLI) + list(APPEND SOURCES + roles/http/compression/brotli/brotli.c) + list(APPEND LIB_LIST brotlienc brotlidec brotlidec) + endif() +endif() + +if (LWS_WITH_LEJP_CONF AND LWS_WITH_NETWORK AND NOT LWS_PLAT_OPTEE) + list(APPEND SOURCES + roles/http/server/lejp-conf.c + ) +endif() + +if (LWS_WITH_RANGES) + list(APPEND SOURCES + roles/http/server/ranges.c) +endif() + +if (LWS_WITH_ZIP_FOPS) + if (LWS_WITH_ZLIB) + list(APPEND SOURCES + roles/http/server/fops-zip.c) + else() + message(FATAL_ERROR "Pre-zipped file support (LWS_WITH_ZIP_FOPS) requires ZLIB (LWS_WITH_ZLIB)") + endif() +endif() + +# +# Keep explicit parent scope exports at end +# + +exports_to_parent_scope() \ No newline at end of file diff -Nru libwebsockets-3.2.1/lib/roles/http/compression/brotli/brotli.c libwebsockets-4.1.6/lib/roles/http/compression/brotli/brotli.c --- libwebsockets-3.2.1/lib/roles/http/compression/brotli/brotli.c 2019-12-18 14:45:31.000000000 +0000 +++ libwebsockets-4.1.6/lib/roles/http/compression/brotli/brotli.c 2020-12-01 17:40:26.000000000 +0000 @@ -1,26 +1,28 @@ /* * libwebsockets - small server side websockets and web server implementation * - * Copyright (C) 2010 - 2018 Andy Green + * Copyright (C) 2010 - 2019 Andy Green * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation: - * version 2.1 of the License. + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to + * deal in the Software without restriction, including without limitation the + * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or + * sell copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: * - * This library is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. * - * You should have received a copy of the GNU Lesser General Public - * License along with this library; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, - * MA 02110-1301 USA + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS + * IN THE SOFTWARE. */ -#include "core/private.h" - +#include "private-lib-core.h" static int lcs_init_compression_brotli(lws_comp_ctx_t *ctx, int decomp) diff -Nru libwebsockets-3.2.1/lib/roles/http/compression/deflate/deflate.c libwebsockets-4.1.6/lib/roles/http/compression/deflate/deflate.c --- libwebsockets-3.2.1/lib/roles/http/compression/deflate/deflate.c 2019-12-18 14:45:31.000000000 +0000 +++ libwebsockets-4.1.6/lib/roles/http/compression/deflate/deflate.c 2020-12-01 17:40:26.000000000 +0000 @@ -1,25 +1,28 @@ /* * libwebsockets - small server side websockets and web server implementation * - * Copyright (C) 2010 - 2018 Andy Green + * Copyright (C) 2010 - 2019 Andy Green * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation: - * version 2.1 of the License. + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to + * deal in the Software without restriction, including without limitation the + * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or + * sell copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: * - * This library is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. * - * You should have received a copy of the GNU Lesser General Public - * License along with this library; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, - * MA 02110-1301 USA + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS + * IN THE SOFTWARE. */ -#include "core/private.h" +#include "private-lib-core.h" static int lcs_init_compression_deflate(lws_comp_ctx_t *ctx, int decomp) diff -Nru libwebsockets-3.2.1/lib/roles/http/compression/private.h libwebsockets-4.1.6/lib/roles/http/compression/private.h --- libwebsockets-3.2.1/lib/roles/http/compression/private.h 2019-12-18 14:45:31.000000000 +0000 +++ libwebsockets-4.1.6/lib/roles/http/compression/private.h 1970-01-01 00:00:00.000000000 +0000 @@ -1,84 +0,0 @@ -/* - * libwebsockets - small server side websockets and web server implementation - * - * Copyright (C) 2010 - 2018 Andy Green - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation: - * version 2.1 of the License. - * - * This library is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with this library; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, - * MA 02110-1301 USA - * - * This is included from core/private.h if LWS_WITH_HTTP_STREAM_COMPRESSION - */ - -#if defined(LWS_WITH_MINIZ) -#include -#else -#include -#endif -#if defined(LWS_WITH_HTTP_BROTLI) -#include -#include -#endif - -/* - * struct holding union of all the available compression methods' context data, - * and state if it's compressing or decompressing - */ - -typedef struct lws_compression_ctx { - union { - -#if defined(LWS_WITH_HTTP_BROTLI) - BrotliEncoderState *br_en; - BrotliDecoderState *br_de; -#endif - z_stream *deflate; - void *generic_ctx_ptr; - } u; - - struct lws_buflist *buflist_comp; - - unsigned int is_decompression:1; - unsigned int final_on_input_side:1; - unsigned int may_have_more:1; - unsigned int chunking:1; -} lws_comp_ctx_t; - -/* generic structure defining the interface to a compression method */ - -struct lws_compression_support { - /** compression name as used by, eg, content-ecoding */ - const char *encoding_name; - /** create a compression context for the compression method, or NULL */ - int (*init_compression)(lws_comp_ctx_t *ctx, int decomp); - /** pass data into the context to be processed */ - int (*process)(lws_comp_ctx_t *ctx, const void *in, size_t *ilen_iused, - void *out, size_t *olen_oused); - /** destroy the de/compression context */ - void (*destroy)(lws_comp_ctx_t *ctx); -}; - -extern struct lws_compression_support lcs_deflate; -extern struct lws_compression_support lcs_brotli; - -int -lws_http_compression_validate(struct lws *wsi); - -int -lws_http_compression_transform(struct lws *wsi, unsigned char *buf, - size_t len, enum lws_write_protocol *wp, - unsigned char **outbuf, size_t *olen_oused); - -void -lws_http_compression_destroy(struct lws *wsi); diff -Nru libwebsockets-3.2.1/lib/roles/http/compression/private-lib-roles-http-compression.h libwebsockets-4.1.6/lib/roles/http/compression/private-lib-roles-http-compression.h --- libwebsockets-3.2.1/lib/roles/http/compression/private-lib-roles-http-compression.h 1970-01-01 00:00:00.000000000 +0000 +++ libwebsockets-4.1.6/lib/roles/http/compression/private-lib-roles-http-compression.h 2020-12-01 17:40:26.000000000 +0000 @@ -0,0 +1,87 @@ + /* + * libwebsockets - small server side websockets and web server implementation + * + * Copyright (C) 2010 - 2019 Andy Green + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to + * deal in the Software without restriction, including without limitation the + * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or + * sell copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS + * IN THE SOFTWARE. + * + * This is included from private-lib-core.h if LWS_WITH_HTTP_STREAM_COMPRESSION + */ + +#if defined(LWS_WITH_MINIZ) +#include +#else +#include +#endif +#if defined(LWS_WITH_HTTP_BROTLI) +#include +#include +#endif + +/* + * struct holding union of all the available compression methods' context data, + * and state if it's compressing or decompressing + */ + +typedef struct lws_compression_ctx { + union { + +#if defined(LWS_WITH_HTTP_BROTLI) + BrotliEncoderState *br_en; + BrotliDecoderState *br_de; +#endif + z_stream *deflate; + void *generic_ctx_ptr; + } u; + + struct lws_buflist *buflist_comp; + + unsigned int is_decompression:1; + unsigned int final_on_input_side:1; + unsigned int may_have_more:1; + unsigned int chunking:1; +} lws_comp_ctx_t; + +/* generic structure defining the interface to a compression method */ + +struct lws_compression_support { + /** compression name as used by, eg, content-ecoding */ + const char *encoding_name; + /** create a compression context for the compression method, or NULL */ + int (*init_compression)(lws_comp_ctx_t *ctx, int decomp); + /** pass data into the context to be processed */ + int (*process)(lws_comp_ctx_t *ctx, const void *in, size_t *ilen_iused, + void *out, size_t *olen_oused); + /** destroy the de/compression context */ + void (*destroy)(lws_comp_ctx_t *ctx); +}; + +extern struct lws_compression_support lcs_deflate; +extern struct lws_compression_support lcs_brotli; + +int +lws_http_compression_validate(struct lws *wsi); + +int +lws_http_compression_transform(struct lws *wsi, unsigned char *buf, + size_t len, enum lws_write_protocol *wp, + unsigned char **outbuf, size_t *olen_oused); + +void +lws_http_compression_destroy(struct lws *wsi); diff -Nru libwebsockets-3.2.1/lib/roles/http/compression/README.md libwebsockets-4.1.6/lib/roles/http/compression/README.md --- libwebsockets-3.2.1/lib/roles/http/compression/README.md 2019-12-18 14:45:31.000000000 +0000 +++ libwebsockets-4.1.6/lib/roles/http/compression/README.md 2020-12-01 17:40:26.000000000 +0000 @@ -6,7 +6,7 @@ The compression transforms expose an "ops" type struct and a compressor name as used by `content-encoding`... the ops struct definition can be found in -./private.h. +./private-lib-roles-http-compression.h. Because the compression transform depends on being able to send on its output before it can process new input, the transform adds a new kind of buflist diff -Nru libwebsockets-3.2.1/lib/roles/http/compression/stream.c libwebsockets-4.1.6/lib/roles/http/compression/stream.c --- libwebsockets-3.2.1/lib/roles/http/compression/stream.c 2019-12-18 14:45:31.000000000 +0000 +++ libwebsockets-4.1.6/lib/roles/http/compression/stream.c 2020-12-01 17:40:26.000000000 +0000 @@ -1,25 +1,28 @@ /* * libwebsockets - small server side websockets and web server implementation * - * Copyright (C) 2010 - 2018 Andy Green + * Copyright (C) 2010 - 2019 Andy Green * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation: - * version 2.1 of the License. + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to + * deal in the Software without restriction, including without limitation the + * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or + * sell copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: * - * This library is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. * - * You should have received a copy of the GNU Lesser General Public - * License along with this library; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, - * MA 02110-1301 USA + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS + * IN THE SOFTWARE. */ -#include "core/private.h" +#include "private-lib-core.h" /* compression methods listed in order of preference */ @@ -54,7 +57,7 @@ return 0; } -LWS_VISIBLE int +int lws_http_compression_apply(struct lws *wsi, const char *name, unsigned char **p, unsigned char *end, char decomp) { @@ -151,7 +154,7 @@ *wp = LWS_WRITE_HTTP | ((*wp) & ~0x1f); } - if (ctx->buflist_comp || ctx->may_have_more) { + if (ctx->buflist_comp) { /* * we can't send this new stuff when we have old stuff * buffered and not compressed yet. Add it to the tail diff -Nru libwebsockets-3.2.1/lib/roles/http/header.c libwebsockets-4.1.6/lib/roles/http/header.c --- libwebsockets-3.2.1/lib/roles/http/header.c 2019-12-18 14:45:31.000000000 +0000 +++ libwebsockets-4.1.6/lib/roles/http/header.c 2020-12-01 17:40:26.000000000 +0000 @@ -1,25 +1,28 @@ /* * libwebsockets - small server side websockets and web server implementation * - * Copyright (C) 2010-2018 Andy Green + * Copyright (C) 2010 - 2019 Andy Green * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation: - * version 2.1 of the License. + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to + * deal in the Software without restriction, including without limitation the + * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or + * sell copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: * - * This library is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. * - * You should have received a copy of the GNU Lesser General Public - * License along with this library; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, - * MA 02110-1301 USA + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS + * IN THE SOFTWARE. */ -#include "core/private.h" +#include "private-lib-core.h" #include "lextable-strings.h" @@ -92,6 +95,9 @@ p = *pp; len = lws_ptr_diff(p, start); +#if defined(LWS_WITH_DETAILED_LATENCY) + wsi->detlat.earliest_write_req_pre_write = lws_now_usecs(); +#endif if (lws_write(wsi, start, len, LWS_WRITE_HTTP_HEADERS) != len) return 1; @@ -137,6 +143,8 @@ return 0; } +#if defined(LWS_WITH_SERVER) + int lws_add_http_common_headers(struct lws *wsi, unsigned int code, const char *content_type, lws_filepos_t content_len, @@ -149,7 +157,8 @@ if (lws_add_http_header_status(wsi, code, p, end)) return 1; - if (lws_add_http_header_by_token(wsi, WSI_TOKEN_HTTP_CONTENT_TYPE, + if (content_type && + lws_add_http_header_by_token(wsi, WSI_TOKEN_HTTP_CONTENT_TYPE, (unsigned char *)content_type, (int)strlen(content_type), p, end)) return 1; @@ -178,7 +187,7 @@ /* there was no length... it normally means CONNECTION_CLOSE */ #if defined(LWS_WITH_HTTP_STREAM_COMPRESSION) - if (!wsi->http2_substream && wsi->http.lcs) { + if (!wsi->mux_substream && wsi->http.lcs) { /* so... * - h1 connection * - http compression transform active @@ -200,7 +209,7 @@ t = 1; } #endif - if (!wsi->http2_substream) { + if (!wsi->mux_substream) { if (lws_add_http_header_by_token(wsi, WSI_TOKEN_CONNECTION, (unsigned char *)ka[t], @@ -259,7 +268,7 @@ &pvo_hsbph[3], NULL, "content-security-policy:", "default-src 'none'; img-src 'self' data: ; " "script-src 'self'; font-src 'self'; " - "style-src 'self'; connect-src 'self'; " + "style-src 'self'; connect-src 'self' ws: wss:; " "frame-ancestors 'none'; base-uri 'none';" "form-action 'self';" }}; @@ -309,15 +318,16 @@ else p1 = hver[0]; - n = lws_snprintf((char *)code_and_desc, sizeof(code_and_desc) - 1, "%s %u %s", p1, code, - description); + n = lws_snprintf((char *)code_and_desc, + sizeof(code_and_desc) - 1, "%s %u %s", + p1, code, description); if (lws_add_http_header_by_name(wsi, NULL, code_and_desc, n, p, end)) return 1; } - headers = wsi->vhost->headers; + headers = wsi->a.vhost->headers; while (headers) { if (lws_add_http_header_by_name(wsi, (const unsigned char *)headers->name, @@ -328,7 +338,7 @@ headers = headers->next; } - if (wsi->vhost->options & + if (wsi->a.vhost->options & LWS_SERVER_OPTION_HTTP_HEADERS_SECURITY_BEST_PRACTICES_ENFORCE) { headers = &pvo_hsbph[LWS_ARRAY_SIZE(pvo_hsbph) - 1]; while (headers) { @@ -342,14 +352,16 @@ } } - if (wsi->context->server_string && - !(_code & LWSAHH_FLAG_NO_SERVER_NAME)) + if (wsi->a.context->server_string && + !(_code & LWSAHH_FLAG_NO_SERVER_NAME)) { + assert(wsi->a.context->server_string_len > 0); if (lws_add_http_header_by_token(wsi, WSI_TOKEN_HTTP_SERVER, - (unsigned char *)wsi->context->server_string, - wsi->context->server_string_len, p, end)) + (unsigned char *)wsi->a.context->server_string, + wsi->a.context->server_string_len, p, end)) return 1; + } - if (wsi->vhost->options & LWS_SERVER_OPTION_STS) + if (wsi->a.vhost->options & LWS_SERVER_OPTION_STS) if (lws_add_http_header_by_name(wsi, (unsigned char *) "Strict-Transport-Security:", (unsigned char *)"max-age=15768000 ; " @@ -365,7 +377,7 @@ return 0; } -LWS_VISIBLE int +int lws_return_http_status(struct lws *wsi, unsigned int code, const char *html_body) { @@ -378,19 +390,19 @@ int n = 0, m = 0, len; char slen[20]; - if (!wsi->vhost) { + if (!wsi->a.vhost) { lwsl_err("%s: wsi not bound to vhost\n", __func__); return 1; } #if defined(LWS_ROLE_H1) || defined(LWS_ROLE_H2) if (!wsi->handling_404 && - wsi->vhost->http.error_document_404 && + wsi->a.vhost->http.error_document_404 && code == HTTP_STATUS_NOT_FOUND) /* we should do a redirect, and do the 404 there */ if (lws_http_redirect(wsi, HTTP_STATUS_FOUND, - (uint8_t *)wsi->vhost->http.error_document_404, - (int)strlen(wsi->vhost->http.error_document_404), + (uint8_t *)wsi->a.vhost->http.error_document_404, + (int)strlen(wsi->a.vhost->http.error_document_404), &p, end) > 0) return 0; #endif @@ -426,7 +438,7 @@ return 1; #if defined(LWS_WITH_HTTP2) - if (wsi->http2_substream) { + if (wsi->mux_substream) { /* * for HTTP/2, the headers must be sent separately, since they @@ -440,6 +452,9 @@ * * Solve it by writing the headers now... */ +#if defined(LWS_WITH_DETAILED_LATENCY) + wsi->detlat.earliest_write_req_pre_write = lws_now_usecs(); +#endif m = lws_write(wsi, start, lws_ptr_diff(p, start), LWS_WRITE_HTTP_HEADERS); if (m != lws_ptr_diff(p, start)) @@ -479,7 +494,7 @@ return m != n; } -LWS_VISIBLE int +int lws_http_redirect(struct lws *wsi, int code, const unsigned char *loc, int len, unsigned char **p, unsigned char *end) { @@ -510,9 +525,10 @@ return lws_write(wsi, start, *p - start, LWS_WRITE_HTTP_HEADERS | LWS_WRITE_H2_STREAM_END); } +#endif #if !defined(LWS_WITH_HTTP_STREAM_COMPRESSION) -LWS_VISIBLE int +int lws_http_compression_apply(struct lws *wsi, const char *name, unsigned char **p, unsigned char *end, char decomp) { @@ -532,6 +548,8 @@ return lws_header_table_detach(wsi, 0); } +#if defined(LWS_WITH_SERVER) + void lws_sul_http_ah_lifecheck(lws_sorted_usec_list_t *sul) { @@ -553,9 +571,9 @@ const unsigned char *c; if (!ah->in_use || !ah->wsi || !ah->assigned || - (ah->wsi->vhost && + (ah->wsi->a.vhost && (now - ah->assigned) < - ah->wsi->vhost->timeout_secs_ah_idle + 360)) { + ah->wsi->a.vhost->timeout_secs_ah_idle + 360)) { ah = ah->next; continue; } @@ -614,3 +632,4 @@ lws_pt_unlock(pt); } +#endif diff -Nru libwebsockets-3.2.1/lib/roles/http/lextable.h libwebsockets-4.1.6/lib/roles/http/lextable.h --- libwebsockets-3.2.1/lib/roles/http/lextable.h 2019-12-18 14:45:31.000000000 +0000 +++ libwebsockets-4.1.6/lib/roles/http/lextable.h 2020-12-01 17:40:26.000000000 +0000 @@ -1,838 +1,6733 @@ +#if !defined(LWS_HTTP_HEADERS_ALL) && !defined(LWS_WITH_HTTP_UNCOMMON_HEADERS) && !defined(LWS_ROLE_WS) && !defined(LWS_ROLE_H2) + /* 0: 0: get */ + /* 1: 1: post */ + /* 2: 3: host: */ + /* 3: 4: connection: */ + /* 4: 5: upgrade: */ + /* 5: 6: origin: */ + /* 6: 8: + */ + /* 7: 15: http/1.1 */ + /* 8: 17: accept: */ + /* 9: 19: if-modified-since: */ + /* 10: 20: if-none-match: */ + /* 11: 21: accept-encoding: */ + /* 12: 22: accept-language: */ + /* 13: 23: pragma: */ + /* 14: 24: cache-control: */ + /* 15: 25: authorization: */ + /* 16: 26: cookie: */ + /* 17: 27: content-length: */ + /* 18: 28: content-type: */ + /* 19: 29: date: */ + /* 20: 30: range: */ + /* 21: 41: accept-ranges: */ + /* 22: 43: age: */ + /* 23: 44: allow: */ + /* 24: 45: content-disposition: */ + /* 25: 46: content-encoding: */ + /* 26: 47: content-language: */ + /* 27: 48: content-location: */ + /* 28: 49: content-range: */ + /* 29: 50: etag: */ + /* 30: 51: expect: */ + /* 31: 52: expires: */ + /* 32: 53: from: */ + /* 33: 54: if-match: */ + /* 34: 55: if-range: */ + /* 35: 56: if-unmodified-since: */ + /* 36: 57: last-modified: */ + /* 37: 58: link: */ + /* 38: 59: location: */ + /* 39: 63: refresh: */ + /* 40: 64: retry-after: */ + /* 41: 65: server: */ + /* 42: 66: set-cookie: */ + /* 43: 68: transfer-encoding: */ + /* 44: 76: uri-args */ + /* 45: 79: http/1.0 */ + /* 46: 80: x-forwarded-for: */ + /* 47: 81: connect */ + /* 48: 82: head */ + /* 49: 86: x-auth-token: */ + /* 50: 87: */ +/* pos 0000: 0 */ 0x67 /* 'g' */, 0x34, 0x00 /* (to 0x0034 state 1) */, + 0x70 /* 'p' */, 0x36, 0x00 /* (to 0x0039 state 5) */, + 0x68 /* 'h' */, 0x3F, 0x00 /* (to 0x0045 state 10) */, + 0x63 /* 'c' */, 0x4B, 0x00 /* (to 0x0054 state 15) */, + 0x75 /* 'u' */, 0x6C, 0x00 /* (to 0x0078 state 26) */, + 0x6F /* 'o' */, 0x78, 0x00 /* (to 0x0087 state 34) */, + 0x0D /* '.' */, 0x7D, 0x00 /* (to 0x008F state 41) */, + 0x61 /* 'a' */, 0x8C, 0x00 /* (to 0x00A1 state 51) */, + 0x69 /* 'i' */, 0xA3, 0x00 /* (to 0x00BB state 58) */, + 0x64 /* 'd' */, 0x43, 0x01 /* (to 0x015E state 160) */, + 0x72 /* 'r' */, 0x46, 0x01 /* (to 0x0164 state 165) */, + 0x65 /* 'e' */, 0x92, 0x01 /* (to 0x01B3 state 229) */, + 0x66 /* 'f' */, 0xAE, 0x01 /* (to 0x01D2 state 245) */, + 0x6C /* 'l' */, 0xD0, 0x01 /* (to 0x01F7 state 278) */, + 0x73 /* 's' */, 0x0C, 0x02 /* (to 0x0236 state 321) */, + 0x74 /* 't' */, 0x21, 0x02 /* (to 0x024E state 337) */, + 0x78 /* 'x' */, 0x3C, 0x02 /* (to 0x026C state 364) */, + 0x08, /* fail */ +/* pos 0034: 1 */ 0xE5 /* 'e' -> */, +/* pos 0035: 2 */ 0xF4 /* 't' -> */, +/* pos 0036: 3 */ 0xA0 /* ' ' -> */, +/* pos 0037: 4 */ 0x00, 0x00 /* - terminal marker 0 - */, +/* pos 0039: 5 */ 0x6F /* 'o' */, 0x07, 0x00 /* (to 0x0040 state 6) */, + 0x72 /* 'r' */, 0xCE, 0x00 /* (to 0x010A state 106) */, + 0x08, /* fail */ +/* pos 0040: 6 */ 0xF3 /* 's' -> */, +/* pos 0041: 7 */ 0xF4 /* 't' -> */, +/* pos 0042: 8 */ 0xA0 /* ' ' -> */, +/* pos 0043: 9 */ 0x00, 0x01 /* - terminal marker 1 - */, +/* pos 0045: 10 */ 0x6F /* 'o' */, 0x0A, 0x00 /* (to 0x004F state 11) */, + 0x74 /* 't' */, 0x4A, 0x00 /* (to 0x0092 state 43) */, + 0x65 /* 'e' */, 0x3A, 0x02 /* (to 0x0285 state 381) */, + 0x08, /* fail */ +/* pos 004f: 11 */ 0xF3 /* 's' -> */, +/* pos 0050: 12 */ 0xF4 /* 't' -> */, +/* pos 0051: 13 */ 0xBA /* ':' -> */, +/* pos 0052: 14 */ 0x00, 0x02 /* - terminal marker 2 - */, +/* pos 0054: 15 */ 0x6F /* 'o' */, 0x07, 0x00 /* (to 0x005B state 16) */, + 0x61 /* 'a' */, 0xBA, 0x00 /* (to 0x0111 state 112) */, + 0x08, /* fail */ +/* pos 005b: 16 */ 0x6E /* 'n' */, 0x07, 0x00 /* (to 0x0062 state 17) */, + 0x6F /* 'o' */, 0xCF, 0x00 /* (to 0x012D state 138) */, + 0x08, /* fail */ +/* pos 0062: 17 */ 0x6E /* 'n' */, 0x07, 0x00 /* (to 0x0069 state 18) */, + 0x74 /* 't' */, 0xCE, 0x00 /* (to 0x0133 state 143) */, + 0x08, /* fail */ +/* pos 0069: 18 */ 0xE5 /* 'e' -> */, +/* pos 006a: 19 */ 0xE3 /* 'c' -> */, +/* pos 006b: 20 */ 0xF4 /* 't' -> */, +/* pos 006c: 21 */ 0x69 /* 'i' */, 0x07, 0x00 /* (to 0x0073 state 22) */, + 0x20 /* ' ' */, 0x14, 0x02 /* (to 0x0283 state 380) */, + 0x08, /* fail */ +/* pos 0073: 22 */ 0xEF /* 'o' -> */, +/* pos 0074: 23 */ 0xEE /* 'n' -> */, +/* pos 0075: 24 */ 0xBA /* ':' -> */, +/* pos 0076: 25 */ 0x00, 0x03 /* - terminal marker 3 - */, +/* pos 0078: 26 */ 0x70 /* 'p' */, 0x07, 0x00 /* (to 0x007F state 27) */, + 0x72 /* 'r' */, 0xE6, 0x01 /* (to 0x0261 state 355) */, + 0x08, /* fail */ +/* pos 007f: 27 */ 0xE7 /* 'g' -> */, +/* pos 0080: 28 */ 0xF2 /* 'r' -> */, +/* pos 0081: 29 */ 0xE1 /* 'a' -> */, +/* pos 0082: 30 */ 0xE4 /* 'd' -> */, +/* pos 0083: 31 */ 0xE5 /* 'e' -> */, +/* pos 0084: 32 */ 0xBA /* ':' -> */, +/* pos 0085: 33 */ 0x00, 0x04 /* - terminal marker 4 - */, +/* pos 0087: 34 */ 0xF2 /* 'r' -> */, +/* pos 0088: 35 */ 0xE9 /* 'i' -> */, +/* pos 0089: 36 */ 0xE7 /* 'g' -> */, +/* pos 008a: 37 */ 0xE9 /* 'i' -> */, +/* pos 008b: 38 */ 0xEE /* 'n' -> */, +/* pos 008c: 39 */ 0xBA /* ':' -> */, +/* pos 008d: 40 */ 0x00, 0x05 /* - terminal marker 5 - */, +/* pos 008f: 41 */ 0x8A /* '.' -> */, +/* pos 0090: 42 */ 0x00, 0x06 /* - terminal marker 6 - */, +/* pos 0092: 43 */ 0xF4 /* 't' -> */, +/* pos 0093: 44 */ 0xF0 /* 'p' -> */, +/* pos 0094: 45 */ 0xAF /* '/' -> */, +/* pos 0095: 46 */ 0xB1 /* '1' -> */, +/* pos 0096: 47 */ 0xAE /* '.' -> */, +/* pos 0097: 48 */ 0x31 /* '1' */, 0x07, 0x00 /* (to 0x009E state 49) */, + 0x30 /* '0' */, 0xCF, 0x01 /* (to 0x0269 state 362) */, + 0x08, /* fail */ +/* pos 009e: 49 */ 0xA0 /* ' ' -> */, +/* pos 009f: 50 */ 0x00, 0x07 /* - terminal marker 7 - */, +/* pos 00a1: 51 */ 0x63 /* 'c' */, 0x0D, 0x00 /* (to 0x00AE state 52) */, + 0x75 /* 'u' */, 0x7B, 0x00 /* (to 0x011F state 125) */, + 0x67 /* 'g' */, 0xD2, 0x00 /* (to 0x0179 state 178) */, + 0x6C /* 'l' */, 0xD3, 0x00 /* (to 0x017D state 181) */, + 0x08, /* fail */ +/* pos 00ae: 52 */ 0xE3 /* 'c' -> */, +/* pos 00af: 53 */ 0xE5 /* 'e' -> */, +/* pos 00b0: 54 */ 0xF0 /* 'p' -> */, +/* pos 00b1: 55 */ 0xF4 /* 't' -> */, +/* pos 00b2: 56 */ 0x3A /* ':' */, 0x07, 0x00 /* (to 0x00B9 state 57) */, + 0x2D /* '-' */, 0x37, 0x00 /* (to 0x00EC state 87) */, + 0x08, /* fail */ +/* pos 00b9: 57 */ 0x00, 0x08 /* - terminal marker 8 - */, +/* pos 00bb: 58 */ 0xE6 /* 'f' -> */, +/* pos 00bc: 59 */ 0xAD /* '-' -> */, +/* pos 00bd: 60 */ 0x6D /* 'm' */, 0x0D, 0x00 /* (to 0x00CA state 61) */, + 0x6E /* 'n' */, 0x20, 0x00 /* (to 0x00E0 state 76) */, + 0x72 /* 'r' */, 0x1B, 0x01 /* (to 0x01DE state 255) */, + 0x75 /* 'u' */, 0x1F, 0x01 /* (to 0x01E5 state 261) */, + 0x08, /* fail */ +/* pos 00ca: 61 */ 0x6F /* 'o' */, 0x07, 0x00 /* (to 0x00D1 state 62) */, + 0x61 /* 'a' */, 0x0B, 0x01 /* (to 0x01D8 state 250) */, + 0x08, /* fail */ +/* pos 00d1: 62 */ 0xE4 /* 'd' -> */, +/* pos 00d2: 63 */ 0xE9 /* 'i' -> */, +/* pos 00d3: 64 */ 0xE6 /* 'f' -> */, +/* pos 00d4: 65 */ 0xE9 /* 'i' -> */, +/* pos 00d5: 66 */ 0xE5 /* 'e' -> */, +/* pos 00d6: 67 */ 0xE4 /* 'd' -> */, +/* pos 00d7: 68 */ 0xAD /* '-' -> */, +/* pos 00d8: 69 */ 0xF3 /* 's' -> */, +/* pos 00d9: 70 */ 0xE9 /* 'i' -> */, +/* pos 00da: 71 */ 0xEE /* 'n' -> */, +/* pos 00db: 72 */ 0xE3 /* 'c' -> */, +/* pos 00dc: 73 */ 0xE5 /* 'e' -> */, +/* pos 00dd: 74 */ 0xBA /* ':' -> */, +/* pos 00de: 75 */ 0x00, 0x09 /* - terminal marker 9 - */, +/* pos 00e0: 76 */ 0xEF /* 'o' -> */, +/* pos 00e1: 77 */ 0xEE /* 'n' -> */, +/* pos 00e2: 78 */ 0xE5 /* 'e' -> */, +/* pos 00e3: 79 */ 0xAD /* '-' -> */, +/* pos 00e4: 80 */ 0xED /* 'm' -> */, +/* pos 00e5: 81 */ 0xE1 /* 'a' -> */, +/* pos 00e6: 82 */ 0xF4 /* 't' -> */, +/* pos 00e7: 83 */ 0xE3 /* 'c' -> */, +/* pos 00e8: 84 */ 0xE8 /* 'h' -> */, +/* pos 00e9: 85 */ 0xBA /* ':' -> */, +/* pos 00ea: 86 */ 0x00, 0x0A /* - terminal marker 10 - */, +/* pos 00ec: 87 */ 0x65 /* 'e' */, 0x0A, 0x00 /* (to 0x00F6 state 88) */, + 0x6C /* 'l' */, 0x11, 0x00 /* (to 0x0100 state 97) */, + 0x72 /* 'r' */, 0x7F, 0x00 /* (to 0x0171 state 171) */, + 0x08, /* fail */ +/* pos 00f6: 88 */ 0xEE /* 'n' -> */, +/* pos 00f7: 89 */ 0xE3 /* 'c' -> */, +/* pos 00f8: 90 */ 0xEF /* 'o' -> */, +/* pos 00f9: 91 */ 0xE4 /* 'd' -> */, +/* pos 00fa: 92 */ 0xE9 /* 'i' -> */, +/* pos 00fb: 93 */ 0xEE /* 'n' -> */, +/* pos 00fc: 94 */ 0xE7 /* 'g' -> */, +/* pos 00fd: 95 */ 0xBA /* ':' -> */, +/* pos 00fe: 96 */ 0x00, 0x0B /* - terminal marker 11 - */, +/* pos 0100: 97 */ 0xE1 /* 'a' -> */, +/* pos 0101: 98 */ 0xEE /* 'n' -> */, +/* pos 0102: 99 */ 0xE7 /* 'g' -> */, +/* pos 0103: 100 */ 0xF5 /* 'u' -> */, +/* pos 0104: 101 */ 0xE1 /* 'a' -> */, +/* pos 0105: 102 */ 0xE7 /* 'g' -> */, +/* pos 0106: 103 */ 0xE5 /* 'e' -> */, +/* pos 0107: 104 */ 0xBA /* ':' -> */, +/* pos 0108: 105 */ 0x00, 0x0C /* - terminal marker 12 - */, +/* pos 010a: 106 */ 0xE1 /* 'a' -> */, +/* pos 010b: 107 */ 0xE7 /* 'g' -> */, +/* pos 010c: 108 */ 0xED /* 'm' -> */, +/* pos 010d: 109 */ 0xE1 /* 'a' -> */, +/* pos 010e: 110 */ 0xBA /* ':' -> */, +/* pos 010f: 111 */ 0x00, 0x0D /* - terminal marker 13 - */, +/* pos 0111: 112 */ 0xE3 /* 'c' -> */, +/* pos 0112: 113 */ 0xE8 /* 'h' -> */, +/* pos 0113: 114 */ 0xE5 /* 'e' -> */, +/* pos 0114: 115 */ 0xAD /* '-' -> */, +/* pos 0115: 116 */ 0xE3 /* 'c' -> */, +/* pos 0116: 117 */ 0xEF /* 'o' -> */, +/* pos 0117: 118 */ 0xEE /* 'n' -> */, +/* pos 0118: 119 */ 0xF4 /* 't' -> */, +/* pos 0119: 120 */ 0xF2 /* 'r' -> */, +/* pos 011a: 121 */ 0xEF /* 'o' -> */, +/* pos 011b: 122 */ 0xEC /* 'l' -> */, +/* pos 011c: 123 */ 0xBA /* ':' -> */, +/* pos 011d: 124 */ 0x00, 0x0E /* - terminal marker 14 - */, +/* pos 011f: 125 */ 0xF4 /* 't' -> */, +/* pos 0120: 126 */ 0xE8 /* 'h' -> */, +/* pos 0121: 127 */ 0xEF /* 'o' -> */, +/* pos 0122: 128 */ 0xF2 /* 'r' -> */, +/* pos 0123: 129 */ 0xE9 /* 'i' -> */, +/* pos 0124: 130 */ 0xFA /* 'z' -> */, +/* pos 0125: 131 */ 0xE1 /* 'a' -> */, +/* pos 0126: 132 */ 0xF4 /* 't' -> */, +/* pos 0127: 133 */ 0xE9 /* 'i' -> */, +/* pos 0128: 134 */ 0xEF /* 'o' -> */, +/* pos 0129: 135 */ 0xEE /* 'n' -> */, +/* pos 012a: 136 */ 0xBA /* ':' -> */, +/* pos 012b: 137 */ 0x00, 0x0F /* - terminal marker 15 - */, +/* pos 012d: 138 */ 0xEB /* 'k' -> */, +/* pos 012e: 139 */ 0xE9 /* 'i' -> */, +/* pos 012f: 140 */ 0xE5 /* 'e' -> */, +/* pos 0130: 141 */ 0xBA /* ':' -> */, +/* pos 0131: 142 */ 0x00, 0x10 /* - terminal marker 16 - */, +/* pos 0133: 143 */ 0xE5 /* 'e' -> */, +/* pos 0134: 144 */ 0xEE /* 'n' -> */, +/* pos 0135: 145 */ 0xF4 /* 't' -> */, +/* pos 0136: 146 */ 0xAD /* '-' -> */, +/* pos 0137: 147 */ 0x6C /* 'l' */, 0x10, 0x00 /* (to 0x0147 state 148) */, + 0x74 /* 't' */, 0x1E, 0x00 /* (to 0x0158 state 155) */, + 0x64 /* 'd' */, 0x46, 0x00 /* (to 0x0183 state 186) */, + 0x65 /* 'e' */, 0x50, 0x00 /* (to 0x0190 state 198) */, + 0x72 /* 'r' */, 0x69, 0x00 /* (to 0x01AC state 223) */, + 0x08, /* fail */ +/* pos 0147: 148 */ 0x65 /* 'e' */, 0x0A, 0x00 /* (to 0x0151 state 149) */, + 0x61 /* 'a' */, 0x50, 0x00 /* (to 0x019A state 207) */, + 0x6F /* 'o' */, 0x56, 0x00 /* (to 0x01A3 state 215) */, + 0x08, /* fail */ +/* pos 0151: 149 */ 0xEE /* 'n' -> */, +/* pos 0152: 150 */ 0xE7 /* 'g' -> */, +/* pos 0153: 151 */ 0xF4 /* 't' -> */, +/* pos 0154: 152 */ 0xE8 /* 'h' -> */, +/* pos 0155: 153 */ 0xBA /* ':' -> */, +/* pos 0156: 154 */ 0x00, 0x11 /* - terminal marker 17 - */, +/* pos 0158: 155 */ 0xF9 /* 'y' -> */, +/* pos 0159: 156 */ 0xF0 /* 'p' -> */, +/* pos 015a: 157 */ 0xE5 /* 'e' -> */, +/* pos 015b: 158 */ 0xBA /* ':' -> */, +/* pos 015c: 159 */ 0x00, 0x12 /* - terminal marker 18 - */, +/* pos 015e: 160 */ 0xE1 /* 'a' -> */, +/* pos 015f: 161 */ 0xF4 /* 't' -> */, +/* pos 0160: 162 */ 0xE5 /* 'e' -> */, +/* pos 0161: 163 */ 0xBA /* ':' -> */, +/* pos 0162: 164 */ 0x00, 0x13 /* - terminal marker 19 - */, +/* pos 0164: 165 */ 0x61 /* 'a' */, 0x07, 0x00 /* (to 0x016B state 166) */, + 0x65 /* 'e' */, 0xB6, 0x00 /* (to 0x021D state 304) */, + 0x08, /* fail */ +/* pos 016b: 166 */ 0xEE /* 'n' -> */, +/* pos 016c: 167 */ 0xE7 /* 'g' -> */, +/* pos 016d: 168 */ 0xE5 /* 'e' -> */, +/* pos 016e: 169 */ 0xBA /* ':' -> */, +/* pos 016f: 170 */ 0x00, 0x14 /* - terminal marker 20 - */, +/* pos 0171: 171 */ 0xE1 /* 'a' -> */, +/* pos 0172: 172 */ 0xEE /* 'n' -> */, +/* pos 0173: 173 */ 0xE7 /* 'g' -> */, +/* pos 0174: 174 */ 0xE5 /* 'e' -> */, +/* pos 0175: 175 */ 0xF3 /* 's' -> */, +/* pos 0176: 176 */ 0xBA /* ':' -> */, +/* pos 0177: 177 */ 0x00, 0x15 /* - terminal marker 21 - */, +/* pos 0179: 178 */ 0xE5 /* 'e' -> */, +/* pos 017a: 179 */ 0xBA /* ':' -> */, +/* pos 017b: 180 */ 0x00, 0x16 /* - terminal marker 22 - */, +/* pos 017d: 181 */ 0xEC /* 'l' -> */, +/* pos 017e: 182 */ 0xEF /* 'o' -> */, +/* pos 017f: 183 */ 0xF7 /* 'w' -> */, +/* pos 0180: 184 */ 0xBA /* ':' -> */, +/* pos 0181: 185 */ 0x00, 0x17 /* - terminal marker 23 - */, +/* pos 0183: 186 */ 0xE9 /* 'i' -> */, +/* pos 0184: 187 */ 0xF3 /* 's' -> */, +/* pos 0185: 188 */ 0xF0 /* 'p' -> */, +/* pos 0186: 189 */ 0xEF /* 'o' -> */, +/* pos 0187: 190 */ 0xF3 /* 's' -> */, +/* pos 0188: 191 */ 0xE9 /* 'i' -> */, +/* pos 0189: 192 */ 0xF4 /* 't' -> */, +/* pos 018a: 193 */ 0xE9 /* 'i' -> */, +/* pos 018b: 194 */ 0xEF /* 'o' -> */, +/* pos 018c: 195 */ 0xEE /* 'n' -> */, +/* pos 018d: 196 */ 0xBA /* ':' -> */, +/* pos 018e: 197 */ 0x00, 0x18 /* - terminal marker 24 - */, +/* pos 0190: 198 */ 0xEE /* 'n' -> */, +/* pos 0191: 199 */ 0xE3 /* 'c' -> */, +/* pos 0192: 200 */ 0xEF /* 'o' -> */, +/* pos 0193: 201 */ 0xE4 /* 'd' -> */, +/* pos 0194: 202 */ 0xE9 /* 'i' -> */, +/* pos 0195: 203 */ 0xEE /* 'n' -> */, +/* pos 0196: 204 */ 0xE7 /* 'g' -> */, +/* pos 0197: 205 */ 0xBA /* ':' -> */, +/* pos 0198: 206 */ 0x00, 0x19 /* - terminal marker 25 - */, +/* pos 019a: 207 */ 0xEE /* 'n' -> */, +/* pos 019b: 208 */ 0xE7 /* 'g' -> */, +/* pos 019c: 209 */ 0xF5 /* 'u' -> */, +/* pos 019d: 210 */ 0xE1 /* 'a' -> */, +/* pos 019e: 211 */ 0xE7 /* 'g' -> */, +/* pos 019f: 212 */ 0xE5 /* 'e' -> */, +/* pos 01a0: 213 */ 0xBA /* ':' -> */, +/* pos 01a1: 214 */ 0x00, 0x1A /* - terminal marker 26 - */, +/* pos 01a3: 215 */ 0xE3 /* 'c' -> */, +/* pos 01a4: 216 */ 0xE1 /* 'a' -> */, +/* pos 01a5: 217 */ 0xF4 /* 't' -> */, +/* pos 01a6: 218 */ 0xE9 /* 'i' -> */, +/* pos 01a7: 219 */ 0xEF /* 'o' -> */, +/* pos 01a8: 220 */ 0xEE /* 'n' -> */, +/* pos 01a9: 221 */ 0xBA /* ':' -> */, +/* pos 01aa: 222 */ 0x00, 0x1B /* - terminal marker 27 - */, +/* pos 01ac: 223 */ 0xE1 /* 'a' -> */, +/* pos 01ad: 224 */ 0xEE /* 'n' -> */, +/* pos 01ae: 225 */ 0xE7 /* 'g' -> */, +/* pos 01af: 226 */ 0xE5 /* 'e' -> */, +/* pos 01b0: 227 */ 0xBA /* ':' -> */, +/* pos 01b1: 228 */ 0x00, 0x1C /* - terminal marker 28 - */, +/* pos 01b3: 229 */ 0x74 /* 't' */, 0x07, 0x00 /* (to 0x01BA state 230) */, + 0x78 /* 'x' */, 0x09, 0x00 /* (to 0x01BF state 234) */, + 0x08, /* fail */ +/* pos 01ba: 230 */ 0xE1 /* 'a' -> */, +/* pos 01bb: 231 */ 0xE7 /* 'g' -> */, +/* pos 01bc: 232 */ 0xBA /* ':' -> */, +/* pos 01bd: 233 */ 0x00, 0x1D /* - terminal marker 29 - */, +/* pos 01bf: 234 */ 0xF0 /* 'p' -> */, +/* pos 01c0: 235 */ 0x65 /* 'e' */, 0x07, 0x00 /* (to 0x01C7 state 236) */, + 0x69 /* 'i' */, 0x09, 0x00 /* (to 0x01CC state 240) */, + 0x08, /* fail */ +/* pos 01c7: 236 */ 0xE3 /* 'c' -> */, +/* pos 01c8: 237 */ 0xF4 /* 't' -> */, +/* pos 01c9: 238 */ 0xBA /* ':' -> */, +/* pos 01ca: 239 */ 0x00, 0x1E /* - terminal marker 30 - */, +/* pos 01cc: 240 */ 0xF2 /* 'r' -> */, +/* pos 01cd: 241 */ 0xE5 /* 'e' -> */, +/* pos 01ce: 242 */ 0xF3 /* 's' -> */, +/* pos 01cf: 243 */ 0xBA /* ':' -> */, +/* pos 01d0: 244 */ 0x00, 0x1F /* - terminal marker 31 - */, +/* pos 01d2: 245 */ 0xF2 /* 'r' -> */, +/* pos 01d3: 246 */ 0xEF /* 'o' -> */, +/* pos 01d4: 247 */ 0xED /* 'm' -> */, +/* pos 01d5: 248 */ 0xBA /* ':' -> */, +/* pos 01d6: 249 */ 0x00, 0x20 /* - terminal marker 32 - */, +/* pos 01d8: 250 */ 0xF4 /* 't' -> */, +/* pos 01d9: 251 */ 0xE3 /* 'c' -> */, +/* pos 01da: 252 */ 0xE8 /* 'h' -> */, +/* pos 01db: 253 */ 0xBA /* ':' -> */, +/* pos 01dc: 254 */ 0x00, 0x21 /* - terminal marker 33 - */, +/* pos 01de: 255 */ 0xE1 /* 'a' -> */, +/* pos 01df: 256 */ 0xEE /* 'n' -> */, +/* pos 01e0: 257 */ 0xE7 /* 'g' -> */, +/* pos 01e1: 258 */ 0xE5 /* 'e' -> */, +/* pos 01e2: 259 */ 0xBA /* ':' -> */, +/* pos 01e3: 260 */ 0x00, 0x22 /* - terminal marker 34 - */, +/* pos 01e5: 261 */ 0xEE /* 'n' -> */, +/* pos 01e6: 262 */ 0xED /* 'm' -> */, +/* pos 01e7: 263 */ 0xEF /* 'o' -> */, +/* pos 01e8: 264 */ 0xE4 /* 'd' -> */, +/* pos 01e9: 265 */ 0xE9 /* 'i' -> */, +/* pos 01ea: 266 */ 0xE6 /* 'f' -> */, +/* pos 01eb: 267 */ 0xE9 /* 'i' -> */, +/* pos 01ec: 268 */ 0xE5 /* 'e' -> */, +/* pos 01ed: 269 */ 0xE4 /* 'd' -> */, +/* pos 01ee: 270 */ 0xAD /* '-' -> */, +/* pos 01ef: 271 */ 0xF3 /* 's' -> */, +/* pos 01f0: 272 */ 0xE9 /* 'i' -> */, +/* pos 01f1: 273 */ 0xEE /* 'n' -> */, +/* pos 01f2: 274 */ 0xE3 /* 'c' -> */, +/* pos 01f3: 275 */ 0xE5 /* 'e' -> */, +/* pos 01f4: 276 */ 0xBA /* ':' -> */, +/* pos 01f5: 277 */ 0x00, 0x23 /* - terminal marker 35 - */, +/* pos 01f7: 278 */ 0x61 /* 'a' */, 0x0A, 0x00 /* (to 0x0201 state 279) */, + 0x69 /* 'i' */, 0x15, 0x00 /* (to 0x020F state 292) */, + 0x6F /* 'o' */, 0x17, 0x00 /* (to 0x0214 state 296) */, + 0x08, /* fail */ +/* pos 0201: 279 */ 0xF3 /* 's' -> */, +/* pos 0202: 280 */ 0xF4 /* 't' -> */, +/* pos 0203: 281 */ 0xAD /* '-' -> */, +/* pos 0204: 282 */ 0xED /* 'm' -> */, +/* pos 0205: 283 */ 0xEF /* 'o' -> */, +/* pos 0206: 284 */ 0xE4 /* 'd' -> */, +/* pos 0207: 285 */ 0xE9 /* 'i' -> */, +/* pos 0208: 286 */ 0xE6 /* 'f' -> */, +/* pos 0209: 287 */ 0xE9 /* 'i' -> */, +/* pos 020a: 288 */ 0xE5 /* 'e' -> */, +/* pos 020b: 289 */ 0xE4 /* 'd' -> */, +/* pos 020c: 290 */ 0xBA /* ':' -> */, +/* pos 020d: 291 */ 0x00, 0x24 /* - terminal marker 36 - */, +/* pos 020f: 292 */ 0xEE /* 'n' -> */, +/* pos 0210: 293 */ 0xEB /* 'k' -> */, +/* pos 0211: 294 */ 0xBA /* ':' -> */, +/* pos 0212: 295 */ 0x00, 0x25 /* - terminal marker 37 - */, +/* pos 0214: 296 */ 0xE3 /* 'c' -> */, +/* pos 0215: 297 */ 0xE1 /* 'a' -> */, +/* pos 0216: 298 */ 0xF4 /* 't' -> */, +/* pos 0217: 299 */ 0xE9 /* 'i' -> */, +/* pos 0218: 300 */ 0xEF /* 'o' -> */, +/* pos 0219: 301 */ 0xEE /* 'n' -> */, +/* pos 021a: 302 */ 0xBA /* ':' -> */, +/* pos 021b: 303 */ 0x00, 0x26 /* - terminal marker 38 - */, +/* pos 021d: 304 */ 0x66 /* 'f' */, 0x07, 0x00 /* (to 0x0224 state 305) */, + 0x74 /* 't' */, 0x0B, 0x00 /* (to 0x022B state 311) */, + 0x08, /* fail */ +/* pos 0224: 305 */ 0xF2 /* 'r' -> */, +/* pos 0225: 306 */ 0xE5 /* 'e' -> */, +/* pos 0226: 307 */ 0xF3 /* 's' -> */, +/* pos 0227: 308 */ 0xE8 /* 'h' -> */, +/* pos 0228: 309 */ 0xBA /* ':' -> */, +/* pos 0229: 310 */ 0x00, 0x27 /* - terminal marker 39 - */, +/* pos 022b: 311 */ 0xF2 /* 'r' -> */, +/* pos 022c: 312 */ 0xF9 /* 'y' -> */, +/* pos 022d: 313 */ 0xAD /* '-' -> */, +/* pos 022e: 314 */ 0xE1 /* 'a' -> */, +/* pos 022f: 315 */ 0xE6 /* 'f' -> */, +/* pos 0230: 316 */ 0xF4 /* 't' -> */, +/* pos 0231: 317 */ 0xE5 /* 'e' -> */, +/* pos 0232: 318 */ 0xF2 /* 'r' -> */, +/* pos 0233: 319 */ 0xBA /* ':' -> */, +/* pos 0234: 320 */ 0x00, 0x28 /* - terminal marker 40 - */, +/* pos 0236: 321 */ 0xE5 /* 'e' -> */, +/* pos 0237: 322 */ 0x72 /* 'r' */, 0x07, 0x00 /* (to 0x023E state 323) */, + 0x74 /* 't' */, 0x0A, 0x00 /* (to 0x0244 state 328) */, + 0x08, /* fail */ +/* pos 023e: 323 */ 0xF6 /* 'v' -> */, +/* pos 023f: 324 */ 0xE5 /* 'e' -> */, +/* pos 0240: 325 */ 0xF2 /* 'r' -> */, +/* pos 0241: 326 */ 0xBA /* ':' -> */, +/* pos 0242: 327 */ 0x00, 0x29 /* - terminal marker 41 - */, +/* pos 0244: 328 */ 0xAD /* '-' -> */, +/* pos 0245: 329 */ 0xE3 /* 'c' -> */, +/* pos 0246: 330 */ 0xEF /* 'o' -> */, +/* pos 0247: 331 */ 0xEF /* 'o' -> */, +/* pos 0248: 332 */ 0xEB /* 'k' -> */, +/* pos 0249: 333 */ 0xE9 /* 'i' -> */, +/* pos 024a: 334 */ 0xE5 /* 'e' -> */, +/* pos 024b: 335 */ 0xBA /* ':' -> */, +/* pos 024c: 336 */ 0x00, 0x2A /* - terminal marker 42 - */, +/* pos 024e: 337 */ 0xF2 /* 'r' -> */, +/* pos 024f: 338 */ 0xE1 /* 'a' -> */, +/* pos 0250: 339 */ 0xEE /* 'n' -> */, +/* pos 0251: 340 */ 0xF3 /* 's' -> */, +/* pos 0252: 341 */ 0xE6 /* 'f' -> */, +/* pos 0253: 342 */ 0xE5 /* 'e' -> */, +/* pos 0254: 343 */ 0xF2 /* 'r' -> */, +/* pos 0255: 344 */ 0xAD /* '-' -> */, +/* pos 0256: 345 */ 0xE5 /* 'e' -> */, +/* pos 0257: 346 */ 0xEE /* 'n' -> */, +/* pos 0258: 347 */ 0xE3 /* 'c' -> */, +/* pos 0259: 348 */ 0xEF /* 'o' -> */, +/* pos 025a: 349 */ 0xE4 /* 'd' -> */, +/* pos 025b: 350 */ 0xE9 /* 'i' -> */, +/* pos 025c: 351 */ 0xEE /* 'n' -> */, +/* pos 025d: 352 */ 0xE7 /* 'g' -> */, +/* pos 025e: 353 */ 0xBA /* ':' -> */, +/* pos 025f: 354 */ 0x00, 0x2B /* - terminal marker 43 - */, +/* pos 0261: 355 */ 0xE9 /* 'i' -> */, +/* pos 0262: 356 */ 0xAD /* '-' -> */, +/* pos 0263: 357 */ 0xE1 /* 'a' -> */, +/* pos 0264: 358 */ 0xF2 /* 'r' -> */, +/* pos 0265: 359 */ 0xE7 /* 'g' -> */, +/* pos 0266: 360 */ 0xF3 /* 's' -> */, +/* pos 0267: 361 */ 0x00, 0x2C /* - terminal marker 44 - */, +/* pos 0269: 362 */ 0xA0 /* ' ' -> */, +/* pos 026a: 363 */ 0x00, 0x2D /* - terminal marker 45 - */, +/* pos 026c: 364 */ 0xAD /* '-' -> */, +/* pos 026d: 365 */ 0x66 /* 'f' */, 0x07, 0x00 /* (to 0x0274 state 366) */, + 0x61 /* 'a' */, 0x1A, 0x00 /* (to 0x028A state 385) */, + 0x08, /* fail */ +/* pos 0274: 366 */ 0xEF /* 'o' -> */, +/* pos 0275: 367 */ 0xF2 /* 'r' -> */, +/* pos 0276: 368 */ 0xF7 /* 'w' -> */, +/* pos 0277: 369 */ 0xE1 /* 'a' -> */, +/* pos 0278: 370 */ 0xF2 /* 'r' -> */, +/* pos 0279: 371 */ 0xE4 /* 'd' -> */, +/* pos 027a: 372 */ 0xE5 /* 'e' -> */, +/* pos 027b: 373 */ 0xE4 /* 'd' -> */, +/* pos 027c: 374 */ 0xAD /* '-' -> */, +/* pos 027d: 375 */ 0xE6 /* 'f' -> */, +/* pos 027e: 376 */ 0xEF /* 'o' -> */, +/* pos 027f: 377 */ 0xF2 /* 'r' -> */, +/* pos 0280: 378 */ 0xBA /* ':' -> */, +/* pos 0281: 379 */ 0x00, 0x2E /* - terminal marker 46 - */, +/* pos 0283: 380 */ 0x00, 0x2F /* - terminal marker 47 - */, +/* pos 0285: 381 */ 0xE1 /* 'a' -> */, +/* pos 0286: 382 */ 0xE4 /* 'd' -> */, +/* pos 0287: 383 */ 0xA0 /* ' ' -> */, +/* pos 0288: 384 */ 0x00, 0x30 /* - terminal marker 48 - */, +/* pos 028a: 385 */ 0xF5 /* 'u' -> */, +/* pos 028b: 386 */ 0xF4 /* 't' -> */, +/* pos 028c: 387 */ 0xE8 /* 'h' -> */, +/* pos 028d: 388 */ 0xAD /* '-' -> */, +/* pos 028e: 389 */ 0xF4 /* 't' -> */, +/* pos 028f: 390 */ 0xEF /* 'o' -> */, +/* pos 0290: 391 */ 0xEB /* 'k' -> */, +/* pos 0291: 392 */ 0xE5 /* 'e' -> */, +/* pos 0292: 393 */ 0xEE /* 'n' -> */, +/* pos 0293: 394 */ 0xBA /* ':' -> */, +/* pos 0294: 395 */ 0x00, 0x31 /* - terminal marker 49 - */, +/* total size 662 bytes */ +#endif + +#if !defined(LWS_HTTP_HEADERS_ALL) && defined(LWS_WITH_HTTP_UNCOMMON_HEADERS) && !defined(LWS_ROLE_WS) && !defined(LWS_ROLE_H2) + /* 0: 0: get */ + /* 1: 1: post */ + /* 2: 2: options */ + /* 3: 3: host: */ + /* 4: 4: connection: */ + /* 5: 5: upgrade: */ + /* 6: 6: origin: */ + /* 7: 8: + */ + /* 8: 15: http/1.1 */ + /* 9: 17: accept: */ + /* 10: 18: access-control-request-headers: */ + /* 11: 19: if-modified-since: */ + /* 12: 20: if-none-match: */ + /* 13: 21: accept-encoding: */ + /* 14: 22: accept-language: */ + /* 15: 23: pragma: */ + /* 16: 24: cache-control: */ + /* 17: 25: authorization: */ + /* 18: 26: cookie: */ + /* 19: 27: content-length: */ + /* 20: 28: content-type: */ + /* 21: 29: date: */ + /* 22: 30: range: */ + /* 23: 31: referer: */ + /* 24: 40: accept-charset: */ + /* 25: 41: accept-ranges: */ + /* 26: 42: access-control-allow-origin: */ + /* 27: 43: age: */ + /* 28: 44: allow: */ + /* 29: 45: content-disposition: */ + /* 30: 46: content-encoding: */ + /* 31: 47: content-language: */ + /* 32: 48: content-location: */ + /* 33: 49: content-range: */ + /* 34: 50: etag: */ + /* 35: 51: expect: */ + /* 36: 52: expires: */ + /* 37: 53: from: */ + /* 38: 54: if-match: */ + /* 39: 55: if-range: */ + /* 40: 56: if-unmodified-since: */ + /* 41: 57: last-modified: */ + /* 42: 58: link: */ + /* 43: 59: location: */ + /* 44: 60: max-forwards: */ + /* 45: 61: proxy-authenticate: */ + /* 46: 62: proxy-authorization: */ + /* 47: 63: refresh: */ + /* 48: 64: retry-after: */ + /* 49: 65: server: */ + /* 50: 66: set-cookie: */ + /* 51: 67: strict-transport-security: */ + /* 52: 68: transfer-encoding: */ + /* 53: 69: user-agent: */ + /* 54: 70: vary: */ + /* 55: 71: via: */ + /* 56: 72: www-authenticate: */ + /* 57: 73: patch */ + /* 58: 74: put */ + /* 59: 75: delete */ + /* 60: 76: uri-args */ + /* 61: 77: proxy */ + /* 62: 78: x-real-ip: */ + /* 63: 79: http/1.0 */ + /* 64: 80: x-forwarded-for: */ + /* 65: 81: connect */ + /* 66: 82: head */ + /* 67: 83: te: */ + /* 68: 84: replay-nonce: */ + /* 69: 86: x-auth-token: */ + /* 70: 87: */ +/* pos 0000: 0 */ 0x67 /* 'g' */, 0x3D, 0x00 /* (to 0x003D state 1) */, + 0x70 /* 'p' */, 0x3F, 0x00 /* (to 0x0042 state 5) */, + 0x68 /* 'h' */, 0x4E, 0x00 /* (to 0x0054 state 10) */, + 0x63 /* 'c' */, 0x5A, 0x00 /* (to 0x0063 state 15) */, + 0x75 /* 'u' */, 0x7B, 0x00 /* (to 0x0087 state 26) */, + 0x6F /* 'o' */, 0x8A, 0x00 /* (to 0x0099 state 34) */, + 0x0D /* '.' */, 0x95, 0x00 /* (to 0x00A7 state 41) */, + 0x61 /* 'a' */, 0xA4, 0x00 /* (to 0x00B9 state 51) */, + 0x69 /* 'i' */, 0xC1, 0x00 /* (to 0x00D9 state 58) */, + 0x64 /* 'd' */, 0x6A, 0x01 /* (to 0x0185 state 160) */, + 0x72 /* 'r' */, 0x73, 0x01 /* (to 0x0191 state 165) */, + 0x65 /* 'e' */, 0xBF, 0x01 /* (to 0x01E0 state 229) */, + 0x66 /* 'f' */, 0xDB, 0x01 /* (to 0x01FF state 245) */, + 0x6C /* 'l' */, 0xFD, 0x01 /* (to 0x0224 state 278) */, + 0x73 /* 's' */, 0x42, 0x02 /* (to 0x026C state 321) */, + 0x74 /* 't' */, 0x5D, 0x02 /* (to 0x028A state 337) */, + 0x78 /* 'x' */, 0x7E, 0x02 /* (to 0x02AE state 364) */, + 0x6D /* 'm' */, 0xEF, 0x02 /* (to 0x0322 state 456) */, + 0x76 /* 'v' */, 0x48, 0x03 /* (to 0x037E state 531) */, + 0x77 /* 'w' */, 0x55, 0x03 /* (to 0x038E state 539) */, + 0x08, /* fail */ +/* pos 003d: 1 */ 0xE5 /* 'e' -> */, +/* pos 003e: 2 */ 0xF4 /* 't' -> */, +/* pos 003f: 3 */ 0xA0 /* ' ' -> */, +/* pos 0040: 4 */ 0x00, 0x00 /* - terminal marker 0 - */, +/* pos 0042: 5 */ 0x6F /* 'o' */, 0x0D, 0x00 /* (to 0x004F state 6) */, + 0x72 /* 'r' */, 0xE6, 0x00 /* (to 0x012B state 106) */, + 0x61 /* 'a' */, 0x58, 0x03 /* (to 0x03A0 state 556) */, + 0x75 /* 'u' */, 0x5A, 0x03 /* (to 0x03A5 state 560) */, + 0x08, /* fail */ +/* pos 004f: 6 */ 0xF3 /* 's' -> */, +/* pos 0050: 7 */ 0xF4 /* 't' -> */, +/* pos 0051: 8 */ 0xA0 /* ' ' -> */, +/* pos 0052: 9 */ 0x00, 0x01 /* - terminal marker 1 - */, +/* pos 0054: 10 */ 0x6F /* 'o' */, 0x0A, 0x00 /* (to 0x005E state 11) */, + 0x74 /* 't' */, 0x53, 0x00 /* (to 0x00AA state 43) */, + 0x65 /* 'e' */, 0x70, 0x02 /* (to 0x02CA state 381) */, + 0x08, /* fail */ +/* pos 005e: 11 */ 0xF3 /* 's' -> */, +/* pos 005f: 12 */ 0xF4 /* 't' -> */, +/* pos 0060: 13 */ 0xBA /* ':' -> */, +/* pos 0061: 14 */ 0x00, 0x03 /* - terminal marker 3 - */, +/* pos 0063: 15 */ 0x6F /* 'o' */, 0x07, 0x00 /* (to 0x006A state 16) */, + 0x61 /* 'a' */, 0xD2, 0x00 /* (to 0x0138 state 112) */, + 0x08, /* fail */ +/* pos 006a: 16 */ 0x6E /* 'n' */, 0x07, 0x00 /* (to 0x0071 state 17) */, + 0x6F /* 'o' */, 0xE7, 0x00 /* (to 0x0154 state 138) */, + 0x08, /* fail */ +/* pos 0071: 17 */ 0x6E /* 'n' */, 0x07, 0x00 /* (to 0x0078 state 18) */, + 0x74 /* 't' */, 0xE6, 0x00 /* (to 0x015A state 143) */, + 0x08, /* fail */ +/* pos 0078: 18 */ 0xE5 /* 'e' -> */, +/* pos 0079: 19 */ 0xE3 /* 'c' -> */, +/* pos 007a: 20 */ 0xF4 /* 't' -> */, +/* pos 007b: 21 */ 0x69 /* 'i' */, 0x07, 0x00 /* (to 0x0082 state 22) */, + 0x20 /* ' ' */, 0x4A, 0x02 /* (to 0x02C8 state 380) */, + 0x08, /* fail */ +/* pos 0082: 22 */ 0xEF /* 'o' -> */, +/* pos 0083: 23 */ 0xEE /* 'n' -> */, +/* pos 0084: 24 */ 0xBA /* ':' -> */, +/* pos 0085: 25 */ 0x00, 0x04 /* - terminal marker 4 - */, +/* pos 0087: 26 */ 0x70 /* 'p' */, 0x0A, 0x00 /* (to 0x0091 state 27) */, + 0x72 /* 'r' */, 0x19, 0x02 /* (to 0x02A3 state 355) */, + 0x73 /* 's' */, 0xE6, 0x02 /* (to 0x0373 state 521) */, + 0x08, /* fail */ +/* pos 0091: 27 */ 0xE7 /* 'g' -> */, +/* pos 0092: 28 */ 0xF2 /* 'r' -> */, +/* pos 0093: 29 */ 0xE1 /* 'a' -> */, +/* pos 0094: 30 */ 0xE4 /* 'd' -> */, +/* pos 0095: 31 */ 0xE5 /* 'e' -> */, +/* pos 0096: 32 */ 0xBA /* ':' -> */, +/* pos 0097: 33 */ 0x00, 0x05 /* - terminal marker 5 - */, +/* pos 0099: 34 */ 0x72 /* 'r' */, 0x07, 0x00 /* (to 0x00A0 state 35) */, + 0x70 /* 'p' */, 0x3F, 0x02 /* (to 0x02DB state 396) */, + 0x08, /* fail */ +/* pos 00a0: 35 */ 0xE9 /* 'i' -> */, +/* pos 00a1: 36 */ 0xE7 /* 'g' -> */, +/* pos 00a2: 37 */ 0xE9 /* 'i' -> */, +/* pos 00a3: 38 */ 0xEE /* 'n' -> */, +/* pos 00a4: 39 */ 0xBA /* ':' -> */, +/* pos 00a5: 40 */ 0x00, 0x06 /* - terminal marker 6 - */, +/* pos 00a7: 41 */ 0x8A /* '.' -> */, +/* pos 00a8: 42 */ 0x00, 0x07 /* - terminal marker 7 - */, +/* pos 00aa: 43 */ 0xF4 /* 't' -> */, +/* pos 00ab: 44 */ 0xF0 /* 'p' -> */, +/* pos 00ac: 45 */ 0xAF /* '/' -> */, +/* pos 00ad: 46 */ 0xB1 /* '1' -> */, +/* pos 00ae: 47 */ 0xAE /* '.' -> */, +/* pos 00af: 48 */ 0x31 /* '1' */, 0x07, 0x00 /* (to 0x00B6 state 49) */, + 0x30 /* '0' */, 0xF9, 0x01 /* (to 0x02AB state 362) */, + 0x08, /* fail */ +/* pos 00b6: 49 */ 0xA0 /* ' ' -> */, +/* pos 00b7: 50 */ 0x00, 0x08 /* - terminal marker 8 - */, +/* pos 00b9: 51 */ 0x63 /* 'c' */, 0x0D, 0x00 /* (to 0x00C6 state 52) */, + 0x75 /* 'u' */, 0x8A, 0x00 /* (to 0x0146 state 125) */, + 0x67 /* 'g' */, 0xE7, 0x00 /* (to 0x01A6 state 178) */, + 0x6C /* 'l' */, 0xE8, 0x00 /* (to 0x01AA state 181) */, + 0x08, /* fail */ +/* pos 00c6: 52 */ 0xE3 /* 'c' -> */, +/* pos 00c7: 53 */ 0xE5 /* 'e' -> */, +/* pos 00c8: 54 */ 0x70 /* 'p' */, 0x07, 0x00 /* (to 0x00CF state 55) */, + 0x73 /* 's' */, 0x18, 0x02 /* (to 0x02E3 state 403) */, + 0x08, /* fail */ +/* pos 00cf: 55 */ 0xF4 /* 't' -> */, +/* pos 00d0: 56 */ 0x3A /* ':' */, 0x07, 0x00 /* (to 0x00D7 state 57) */, + 0x2D /* '-' */, 0x37, 0x00 /* (to 0x010A state 87) */, + 0x08, /* fail */ +/* pos 00d7: 57 */ 0x00, 0x09 /* - terminal marker 9 - */, +/* pos 00d9: 58 */ 0xE6 /* 'f' -> */, +/* pos 00da: 59 */ 0xAD /* '-' -> */, +/* pos 00db: 60 */ 0x6D /* 'm' */, 0x0D, 0x00 /* (to 0x00E8 state 61) */, + 0x6E /* 'n' */, 0x20, 0x00 /* (to 0x00FE state 76) */, + 0x72 /* 'r' */, 0x2A, 0x01 /* (to 0x020B state 255) */, + 0x75 /* 'u' */, 0x2E, 0x01 /* (to 0x0212 state 261) */, + 0x08, /* fail */ +/* pos 00e8: 61 */ 0x6F /* 'o' */, 0x07, 0x00 /* (to 0x00EF state 62) */, + 0x61 /* 'a' */, 0x1A, 0x01 /* (to 0x0205 state 250) */, + 0x08, /* fail */ +/* pos 00ef: 62 */ 0xE4 /* 'd' -> */, +/* pos 00f0: 63 */ 0xE9 /* 'i' -> */, +/* pos 00f1: 64 */ 0xE6 /* 'f' -> */, +/* pos 00f2: 65 */ 0xE9 /* 'i' -> */, +/* pos 00f3: 66 */ 0xE5 /* 'e' -> */, +/* pos 00f4: 67 */ 0xE4 /* 'd' -> */, +/* pos 00f5: 68 */ 0xAD /* '-' -> */, +/* pos 00f6: 69 */ 0xF3 /* 's' -> */, +/* pos 00f7: 70 */ 0xE9 /* 'i' -> */, +/* pos 00f8: 71 */ 0xEE /* 'n' -> */, +/* pos 00f9: 72 */ 0xE3 /* 'c' -> */, +/* pos 00fa: 73 */ 0xE5 /* 'e' -> */, +/* pos 00fb: 74 */ 0xBA /* ':' -> */, +/* pos 00fc: 75 */ 0x00, 0x0B /* - terminal marker 11 - */, +/* pos 00fe: 76 */ 0xEF /* 'o' -> */, +/* pos 00ff: 77 */ 0xEE /* 'n' -> */, +/* pos 0100: 78 */ 0xE5 /* 'e' -> */, +/* pos 0101: 79 */ 0xAD /* '-' -> */, +/* pos 0102: 80 */ 0xED /* 'm' -> */, +/* pos 0103: 81 */ 0xE1 /* 'a' -> */, +/* pos 0104: 82 */ 0xF4 /* 't' -> */, +/* pos 0105: 83 */ 0xE3 /* 'c' -> */, +/* pos 0106: 84 */ 0xE8 /* 'h' -> */, +/* pos 0107: 85 */ 0xBA /* ':' -> */, +/* pos 0108: 86 */ 0x00, 0x0C /* - terminal marker 12 - */, +/* pos 010a: 87 */ 0x65 /* 'e' */, 0x0D, 0x00 /* (to 0x0117 state 88) */, + 0x6C /* 'l' */, 0x14, 0x00 /* (to 0x0121 state 97) */, + 0x72 /* 'r' */, 0x8E, 0x00 /* (to 0x019E state 171) */, + 0x63 /* 'c' */, 0xF8, 0x01 /* (to 0x030B state 435) */, + 0x08, /* fail */ +/* pos 0117: 88 */ 0xEE /* 'n' -> */, +/* pos 0118: 89 */ 0xE3 /* 'c' -> */, +/* pos 0119: 90 */ 0xEF /* 'o' -> */, +/* pos 011a: 91 */ 0xE4 /* 'd' -> */, +/* pos 011b: 92 */ 0xE9 /* 'i' -> */, +/* pos 011c: 93 */ 0xEE /* 'n' -> */, +/* pos 011d: 94 */ 0xE7 /* 'g' -> */, +/* pos 011e: 95 */ 0xBA /* ':' -> */, +/* pos 011f: 96 */ 0x00, 0x0D /* - terminal marker 13 - */, +/* pos 0121: 97 */ 0xE1 /* 'a' -> */, +/* pos 0122: 98 */ 0xEE /* 'n' -> */, +/* pos 0123: 99 */ 0xE7 /* 'g' -> */, +/* pos 0124: 100 */ 0xF5 /* 'u' -> */, +/* pos 0125: 101 */ 0xE1 /* 'a' -> */, +/* pos 0126: 102 */ 0xE7 /* 'g' -> */, +/* pos 0127: 103 */ 0xE5 /* 'e' -> */, +/* pos 0128: 104 */ 0xBA /* ':' -> */, +/* pos 0129: 105 */ 0x00, 0x0E /* - terminal marker 14 - */, +/* pos 012b: 106 */ 0x61 /* 'a' */, 0x07, 0x00 /* (to 0x0132 state 107) */, + 0x6F /* 'o' */, 0x02, 0x02 /* (to 0x0330 state 469) */, + 0x08, /* fail */ +/* pos 0132: 107 */ 0xE7 /* 'g' -> */, +/* pos 0133: 108 */ 0xED /* 'm' -> */, +/* pos 0134: 109 */ 0xE1 /* 'a' -> */, +/* pos 0135: 110 */ 0xBA /* ':' -> */, +/* pos 0136: 111 */ 0x00, 0x0F /* - terminal marker 15 - */, +/* pos 0138: 112 */ 0xE3 /* 'c' -> */, +/* pos 0139: 113 */ 0xE8 /* 'h' -> */, +/* pos 013a: 114 */ 0xE5 /* 'e' -> */, +/* pos 013b: 115 */ 0xAD /* '-' -> */, +/* pos 013c: 116 */ 0xE3 /* 'c' -> */, +/* pos 013d: 117 */ 0xEF /* 'o' -> */, +/* pos 013e: 118 */ 0xEE /* 'n' -> */, +/* pos 013f: 119 */ 0xF4 /* 't' -> */, +/* pos 0140: 120 */ 0xF2 /* 'r' -> */, +/* pos 0141: 121 */ 0xEF /* 'o' -> */, +/* pos 0142: 122 */ 0xEC /* 'l' -> */, +/* pos 0143: 123 */ 0xBA /* ':' -> */, +/* pos 0144: 124 */ 0x00, 0x10 /* - terminal marker 16 - */, +/* pos 0146: 125 */ 0xF4 /* 't' -> */, +/* pos 0147: 126 */ 0xE8 /* 'h' -> */, +/* pos 0148: 127 */ 0xEF /* 'o' -> */, +/* pos 0149: 128 */ 0xF2 /* 'r' -> */, +/* pos 014a: 129 */ 0xE9 /* 'i' -> */, +/* pos 014b: 130 */ 0xFA /* 'z' -> */, +/* pos 014c: 131 */ 0xE1 /* 'a' -> */, +/* pos 014d: 132 */ 0xF4 /* 't' -> */, +/* pos 014e: 133 */ 0xE9 /* 'i' -> */, +/* pos 014f: 134 */ 0xEF /* 'o' -> */, +/* pos 0150: 135 */ 0xEE /* 'n' -> */, +/* pos 0151: 136 */ 0xBA /* ':' -> */, +/* pos 0152: 137 */ 0x00, 0x11 /* - terminal marker 17 - */, +/* pos 0154: 138 */ 0xEB /* 'k' -> */, +/* pos 0155: 139 */ 0xE9 /* 'i' -> */, +/* pos 0156: 140 */ 0xE5 /* 'e' -> */, +/* pos 0157: 141 */ 0xBA /* ':' -> */, +/* pos 0158: 142 */ 0x00, 0x12 /* - terminal marker 18 - */, +/* pos 015a: 143 */ 0xE5 /* 'e' -> */, +/* pos 015b: 144 */ 0xEE /* 'n' -> */, +/* pos 015c: 145 */ 0xF4 /* 't' -> */, +/* pos 015d: 146 */ 0xAD /* '-' -> */, +/* pos 015e: 147 */ 0x6C /* 'l' */, 0x10, 0x00 /* (to 0x016E state 148) */, + 0x74 /* 't' */, 0x1E, 0x00 /* (to 0x017F state 155) */, + 0x64 /* 'd' */, 0x4C, 0x00 /* (to 0x01B0 state 186) */, + 0x65 /* 'e' */, 0x56, 0x00 /* (to 0x01BD state 198) */, + 0x72 /* 'r' */, 0x6F, 0x00 /* (to 0x01D9 state 223) */, + 0x08, /* fail */ +/* pos 016e: 148 */ 0x65 /* 'e' */, 0x0A, 0x00 /* (to 0x0178 state 149) */, + 0x61 /* 'a' */, 0x56, 0x00 /* (to 0x01C7 state 207) */, + 0x6F /* 'o' */, 0x5C, 0x00 /* (to 0x01D0 state 215) */, + 0x08, /* fail */ +/* pos 0178: 149 */ 0xEE /* 'n' -> */, +/* pos 0179: 150 */ 0xE7 /* 'g' -> */, +/* pos 017a: 151 */ 0xF4 /* 't' -> */, +/* pos 017b: 152 */ 0xE8 /* 'h' -> */, +/* pos 017c: 153 */ 0xBA /* ':' -> */, +/* pos 017d: 154 */ 0x00, 0x13 /* - terminal marker 19 - */, +/* pos 017f: 155 */ 0xF9 /* 'y' -> */, +/* pos 0180: 156 */ 0xF0 /* 'p' -> */, +/* pos 0181: 157 */ 0xE5 /* 'e' -> */, +/* pos 0182: 158 */ 0xBA /* ':' -> */, +/* pos 0183: 159 */ 0x00, 0x14 /* - terminal marker 20 - */, +/* pos 0185: 160 */ 0x61 /* 'a' */, 0x07, 0x00 /* (to 0x018C state 161) */, + 0x65 /* 'e' */, 0x20, 0x02 /* (to 0x03A8 state 562) */, + 0x08, /* fail */ +/* pos 018c: 161 */ 0xF4 /* 't' -> */, +/* pos 018d: 162 */ 0xE5 /* 'e' -> */, +/* pos 018e: 163 */ 0xBA /* ':' -> */, +/* pos 018f: 164 */ 0x00, 0x15 /* - terminal marker 21 - */, +/* pos 0191: 165 */ 0x61 /* 'a' */, 0x07, 0x00 /* (to 0x0198 state 166) */, + 0x65 /* 'e' */, 0xB6, 0x00 /* (to 0x024A state 304) */, + 0x08, /* fail */ +/* pos 0198: 166 */ 0xEE /* 'n' -> */, +/* pos 0199: 167 */ 0xE7 /* 'g' -> */, +/* pos 019a: 168 */ 0xE5 /* 'e' -> */, +/* pos 019b: 169 */ 0xBA /* ':' -> */, +/* pos 019c: 170 */ 0x00, 0x16 /* - terminal marker 22 - */, +/* pos 019e: 171 */ 0xE1 /* 'a' -> */, +/* pos 019f: 172 */ 0xEE /* 'n' -> */, +/* pos 01a0: 173 */ 0xE7 /* 'g' -> */, +/* pos 01a1: 174 */ 0xE5 /* 'e' -> */, +/* pos 01a2: 175 */ 0xF3 /* 's' -> */, +/* pos 01a3: 176 */ 0xBA /* ':' -> */, +/* pos 01a4: 177 */ 0x00, 0x19 /* - terminal marker 25 - */, +/* pos 01a6: 178 */ 0xE5 /* 'e' -> */, +/* pos 01a7: 179 */ 0xBA /* ':' -> */, +/* pos 01a8: 180 */ 0x00, 0x1B /* - terminal marker 27 - */, +/* pos 01aa: 181 */ 0xEC /* 'l' -> */, +/* pos 01ab: 182 */ 0xEF /* 'o' -> */, +/* pos 01ac: 183 */ 0xF7 /* 'w' -> */, +/* pos 01ad: 184 */ 0xBA /* ':' -> */, +/* pos 01ae: 185 */ 0x00, 0x1C /* - terminal marker 28 - */, +/* pos 01b0: 186 */ 0xE9 /* 'i' -> */, +/* pos 01b1: 187 */ 0xF3 /* 's' -> */, +/* pos 01b2: 188 */ 0xF0 /* 'p' -> */, +/* pos 01b3: 189 */ 0xEF /* 'o' -> */, +/* pos 01b4: 190 */ 0xF3 /* 's' -> */, +/* pos 01b5: 191 */ 0xE9 /* 'i' -> */, +/* pos 01b6: 192 */ 0xF4 /* 't' -> */, +/* pos 01b7: 193 */ 0xE9 /* 'i' -> */, +/* pos 01b8: 194 */ 0xEF /* 'o' -> */, +/* pos 01b9: 195 */ 0xEE /* 'n' -> */, +/* pos 01ba: 196 */ 0xBA /* ':' -> */, +/* pos 01bb: 197 */ 0x00, 0x1D /* - terminal marker 29 - */, +/* pos 01bd: 198 */ 0xEE /* 'n' -> */, +/* pos 01be: 199 */ 0xE3 /* 'c' -> */, +/* pos 01bf: 200 */ 0xEF /* 'o' -> */, +/* pos 01c0: 201 */ 0xE4 /* 'd' -> */, +/* pos 01c1: 202 */ 0xE9 /* 'i' -> */, +/* pos 01c2: 203 */ 0xEE /* 'n' -> */, +/* pos 01c3: 204 */ 0xE7 /* 'g' -> */, +/* pos 01c4: 205 */ 0xBA /* ':' -> */, +/* pos 01c5: 206 */ 0x00, 0x1E /* - terminal marker 30 - */, +/* pos 01c7: 207 */ 0xEE /* 'n' -> */, +/* pos 01c8: 208 */ 0xE7 /* 'g' -> */, +/* pos 01c9: 209 */ 0xF5 /* 'u' -> */, +/* pos 01ca: 210 */ 0xE1 /* 'a' -> */, +/* pos 01cb: 211 */ 0xE7 /* 'g' -> */, +/* pos 01cc: 212 */ 0xE5 /* 'e' -> */, +/* pos 01cd: 213 */ 0xBA /* ':' -> */, +/* pos 01ce: 214 */ 0x00, 0x1F /* - terminal marker 31 - */, +/* pos 01d0: 215 */ 0xE3 /* 'c' -> */, +/* pos 01d1: 216 */ 0xE1 /* 'a' -> */, +/* pos 01d2: 217 */ 0xF4 /* 't' -> */, +/* pos 01d3: 218 */ 0xE9 /* 'i' -> */, +/* pos 01d4: 219 */ 0xEF /* 'o' -> */, +/* pos 01d5: 220 */ 0xEE /* 'n' -> */, +/* pos 01d6: 221 */ 0xBA /* ':' -> */, +/* pos 01d7: 222 */ 0x00, 0x20 /* - terminal marker 32 - */, +/* pos 01d9: 223 */ 0xE1 /* 'a' -> */, +/* pos 01da: 224 */ 0xEE /* 'n' -> */, +/* pos 01db: 225 */ 0xE7 /* 'g' -> */, +/* pos 01dc: 226 */ 0xE5 /* 'e' -> */, +/* pos 01dd: 227 */ 0xBA /* ':' -> */, +/* pos 01de: 228 */ 0x00, 0x21 /* - terminal marker 33 - */, +/* pos 01e0: 229 */ 0x74 /* 't' */, 0x07, 0x00 /* (to 0x01E7 state 230) */, + 0x78 /* 'x' */, 0x09, 0x00 /* (to 0x01EC state 234) */, + 0x08, /* fail */ +/* pos 01e7: 230 */ 0xE1 /* 'a' -> */, +/* pos 01e8: 231 */ 0xE7 /* 'g' -> */, +/* pos 01e9: 232 */ 0xBA /* ':' -> */, +/* pos 01ea: 233 */ 0x00, 0x22 /* - terminal marker 34 - */, +/* pos 01ec: 234 */ 0xF0 /* 'p' -> */, +/* pos 01ed: 235 */ 0x65 /* 'e' */, 0x07, 0x00 /* (to 0x01F4 state 236) */, + 0x69 /* 'i' */, 0x09, 0x00 /* (to 0x01F9 state 240) */, + 0x08, /* fail */ +/* pos 01f4: 236 */ 0xE3 /* 'c' -> */, +/* pos 01f5: 237 */ 0xF4 /* 't' -> */, +/* pos 01f6: 238 */ 0xBA /* ':' -> */, +/* pos 01f7: 239 */ 0x00, 0x23 /* - terminal marker 35 - */, +/* pos 01f9: 240 */ 0xF2 /* 'r' -> */, +/* pos 01fa: 241 */ 0xE5 /* 'e' -> */, +/* pos 01fb: 242 */ 0xF3 /* 's' -> */, +/* pos 01fc: 243 */ 0xBA /* ':' -> */, +/* pos 01fd: 244 */ 0x00, 0x24 /* - terminal marker 36 - */, +/* pos 01ff: 245 */ 0xF2 /* 'r' -> */, +/* pos 0200: 246 */ 0xEF /* 'o' -> */, +/* pos 0201: 247 */ 0xED /* 'm' -> */, +/* pos 0202: 248 */ 0xBA /* ':' -> */, +/* pos 0203: 249 */ 0x00, 0x25 /* - terminal marker 37 - */, +/* pos 0205: 250 */ 0xF4 /* 't' -> */, +/* pos 0206: 251 */ 0xE3 /* 'c' -> */, +/* pos 0207: 252 */ 0xE8 /* 'h' -> */, +/* pos 0208: 253 */ 0xBA /* ':' -> */, +/* pos 0209: 254 */ 0x00, 0x26 /* - terminal marker 38 - */, +/* pos 020b: 255 */ 0xE1 /* 'a' -> */, +/* pos 020c: 256 */ 0xEE /* 'n' -> */, +/* pos 020d: 257 */ 0xE7 /* 'g' -> */, +/* pos 020e: 258 */ 0xE5 /* 'e' -> */, +/* pos 020f: 259 */ 0xBA /* ':' -> */, +/* pos 0210: 260 */ 0x00, 0x27 /* - terminal marker 39 - */, +/* pos 0212: 261 */ 0xEE /* 'n' -> */, +/* pos 0213: 262 */ 0xED /* 'm' -> */, +/* pos 0214: 263 */ 0xEF /* 'o' -> */, +/* pos 0215: 264 */ 0xE4 /* 'd' -> */, +/* pos 0216: 265 */ 0xE9 /* 'i' -> */, +/* pos 0217: 266 */ 0xE6 /* 'f' -> */, +/* pos 0218: 267 */ 0xE9 /* 'i' -> */, +/* pos 0219: 268 */ 0xE5 /* 'e' -> */, +/* pos 021a: 269 */ 0xE4 /* 'd' -> */, +/* pos 021b: 270 */ 0xAD /* '-' -> */, +/* pos 021c: 271 */ 0xF3 /* 's' -> */, +/* pos 021d: 272 */ 0xE9 /* 'i' -> */, +/* pos 021e: 273 */ 0xEE /* 'n' -> */, +/* pos 021f: 274 */ 0xE3 /* 'c' -> */, +/* pos 0220: 275 */ 0xE5 /* 'e' -> */, +/* pos 0221: 276 */ 0xBA /* ':' -> */, +/* pos 0222: 277 */ 0x00, 0x28 /* - terminal marker 40 - */, +/* pos 0224: 278 */ 0x61 /* 'a' */, 0x0A, 0x00 /* (to 0x022E state 279) */, + 0x69 /* 'i' */, 0x15, 0x00 /* (to 0x023C state 292) */, + 0x6F /* 'o' */, 0x17, 0x00 /* (to 0x0241 state 296) */, + 0x08, /* fail */ +/* pos 022e: 279 */ 0xF3 /* 's' -> */, +/* pos 022f: 280 */ 0xF4 /* 't' -> */, +/* pos 0230: 281 */ 0xAD /* '-' -> */, +/* pos 0231: 282 */ 0xED /* 'm' -> */, +/* pos 0232: 283 */ 0xEF /* 'o' -> */, +/* pos 0233: 284 */ 0xE4 /* 'd' -> */, +/* pos 0234: 285 */ 0xE9 /* 'i' -> */, +/* pos 0235: 286 */ 0xE6 /* 'f' -> */, +/* pos 0236: 287 */ 0xE9 /* 'i' -> */, +/* pos 0237: 288 */ 0xE5 /* 'e' -> */, +/* pos 0238: 289 */ 0xE4 /* 'd' -> */, +/* pos 0239: 290 */ 0xBA /* ':' -> */, +/* pos 023a: 291 */ 0x00, 0x29 /* - terminal marker 41 - */, +/* pos 023c: 292 */ 0xEE /* 'n' -> */, +/* pos 023d: 293 */ 0xEB /* 'k' -> */, +/* pos 023e: 294 */ 0xBA /* ':' -> */, +/* pos 023f: 295 */ 0x00, 0x2A /* - terminal marker 42 - */, +/* pos 0241: 296 */ 0xE3 /* 'c' -> */, +/* pos 0242: 297 */ 0xE1 /* 'a' -> */, +/* pos 0243: 298 */ 0xF4 /* 't' -> */, +/* pos 0244: 299 */ 0xE9 /* 'i' -> */, +/* pos 0245: 300 */ 0xEF /* 'o' -> */, +/* pos 0246: 301 */ 0xEE /* 'n' -> */, +/* pos 0247: 302 */ 0xBA /* ':' -> */, +/* pos 0248: 303 */ 0x00, 0x2B /* - terminal marker 43 - */, +/* pos 024a: 304 */ 0x66 /* 'f' */, 0x0A, 0x00 /* (to 0x0254 state 305) */, + 0x74 /* 't' */, 0x14, 0x00 /* (to 0x0261 state 311) */, + 0x70 /* 'p' */, 0x6C, 0x01 /* (to 0x03BC state 578) */, + 0x08, /* fail */ +/* pos 0254: 305 */ 0x72 /* 'r' */, 0x07, 0x00 /* (to 0x025B state 306) */, + 0x65 /* 'e' */, 0xAE, 0x00 /* (to 0x0305 state 430) */, + 0x08, /* fail */ +/* pos 025b: 306 */ 0xE5 /* 'e' -> */, +/* pos 025c: 307 */ 0xF3 /* 's' -> */, +/* pos 025d: 308 */ 0xE8 /* 'h' -> */, +/* pos 025e: 309 */ 0xBA /* ':' -> */, +/* pos 025f: 310 */ 0x00, 0x2F /* - terminal marker 47 - */, +/* pos 0261: 311 */ 0xF2 /* 'r' -> */, +/* pos 0262: 312 */ 0xF9 /* 'y' -> */, +/* pos 0263: 313 */ 0xAD /* '-' -> */, +/* pos 0264: 314 */ 0xE1 /* 'a' -> */, +/* pos 0265: 315 */ 0xE6 /* 'f' -> */, +/* pos 0266: 316 */ 0xF4 /* 't' -> */, +/* pos 0267: 317 */ 0xE5 /* 'e' -> */, +/* pos 0268: 318 */ 0xF2 /* 'r' -> */, +/* pos 0269: 319 */ 0xBA /* ':' -> */, +/* pos 026a: 320 */ 0x00, 0x30 /* - terminal marker 48 - */, +/* pos 026c: 321 */ 0x65 /* 'e' */, 0x07, 0x00 /* (to 0x0273 state 322) */, + 0x74 /* 't' */, 0xEA, 0x00 /* (to 0x0359 state 496) */, + 0x08, /* fail */ +/* pos 0273: 322 */ 0x72 /* 'r' */, 0x07, 0x00 /* (to 0x027A state 323) */, + 0x74 /* 't' */, 0x0A, 0x00 /* (to 0x0280 state 328) */, + 0x08, /* fail */ +/* pos 027a: 323 */ 0xF6 /* 'v' -> */, +/* pos 027b: 324 */ 0xE5 /* 'e' -> */, +/* pos 027c: 325 */ 0xF2 /* 'r' -> */, +/* pos 027d: 326 */ 0xBA /* ':' -> */, +/* pos 027e: 327 */ 0x00, 0x31 /* - terminal marker 49 - */, +/* pos 0280: 328 */ 0xAD /* '-' -> */, +/* pos 0281: 329 */ 0xE3 /* 'c' -> */, +/* pos 0282: 330 */ 0xEF /* 'o' -> */, +/* pos 0283: 331 */ 0xEF /* 'o' -> */, +/* pos 0284: 332 */ 0xEB /* 'k' -> */, +/* pos 0285: 333 */ 0xE9 /* 'i' -> */, +/* pos 0286: 334 */ 0xE5 /* 'e' -> */, +/* pos 0287: 335 */ 0xBA /* ':' -> */, +/* pos 0288: 336 */ 0x00, 0x32 /* - terminal marker 50 - */, +/* pos 028a: 337 */ 0x72 /* 'r' */, 0x07, 0x00 /* (to 0x0291 state 338) */, + 0x65 /* 'e' */, 0x2C, 0x01 /* (to 0x03B9 state 576) */, + 0x08, /* fail */ +/* pos 0291: 338 */ 0xE1 /* 'a' -> */, +/* pos 0292: 339 */ 0xEE /* 'n' -> */, +/* pos 0293: 340 */ 0xF3 /* 's' -> */, +/* pos 0294: 341 */ 0xE6 /* 'f' -> */, +/* pos 0295: 342 */ 0xE5 /* 'e' -> */, +/* pos 0296: 343 */ 0xF2 /* 'r' -> */, +/* pos 0297: 344 */ 0xAD /* '-' -> */, +/* pos 0298: 345 */ 0xE5 /* 'e' -> */, +/* pos 0299: 346 */ 0xEE /* 'n' -> */, +/* pos 029a: 347 */ 0xE3 /* 'c' -> */, +/* pos 029b: 348 */ 0xEF /* 'o' -> */, +/* pos 029c: 349 */ 0xE4 /* 'd' -> */, +/* pos 029d: 350 */ 0xE9 /* 'i' -> */, +/* pos 029e: 351 */ 0xEE /* 'n' -> */, +/* pos 029f: 352 */ 0xE7 /* 'g' -> */, +/* pos 02a0: 353 */ 0xBA /* ':' -> */, +/* pos 02a1: 354 */ 0x00, 0x34 /* - terminal marker 52 - */, +/* pos 02a3: 355 */ 0xE9 /* 'i' -> */, +/* pos 02a4: 356 */ 0xAD /* '-' -> */, +/* pos 02a5: 357 */ 0xE1 /* 'a' -> */, +/* pos 02a6: 358 */ 0xF2 /* 'r' -> */, +/* pos 02a7: 359 */ 0xE7 /* 'g' -> */, +/* pos 02a8: 360 */ 0xF3 /* 's' -> */, +/* pos 02a9: 361 */ 0x00, 0x3C /* - terminal marker 60 - */, +/* pos 02ab: 362 */ 0xA0 /* ' ' -> */, +/* pos 02ac: 363 */ 0x00, 0x3F /* - terminal marker 63 - */, +/* pos 02ae: 364 */ 0xAD /* '-' -> */, +/* pos 02af: 365 */ 0x66 /* 'f' */, 0x0A, 0x00 /* (to 0x02B9 state 366) */, + 0x61 /* 'a' */, 0x1D, 0x00 /* (to 0x02CF state 385) */, + 0x72 /* 'r' */, 0xFB, 0x00 /* (to 0x03B0 state 568) */, + 0x08, /* fail */ +/* pos 02b9: 366 */ 0xEF /* 'o' -> */, +/* pos 02ba: 367 */ 0xF2 /* 'r' -> */, +/* pos 02bb: 368 */ 0xF7 /* 'w' -> */, +/* pos 02bc: 369 */ 0xE1 /* 'a' -> */, +/* pos 02bd: 370 */ 0xF2 /* 'r' -> */, +/* pos 02be: 371 */ 0xE4 /* 'd' -> */, +/* pos 02bf: 372 */ 0xE5 /* 'e' -> */, +/* pos 02c0: 373 */ 0xE4 /* 'd' -> */, +/* pos 02c1: 374 */ 0xAD /* '-' -> */, +/* pos 02c2: 375 */ 0xE6 /* 'f' -> */, +/* pos 02c3: 376 */ 0xEF /* 'o' -> */, +/* pos 02c4: 377 */ 0xF2 /* 'r' -> */, +/* pos 02c5: 378 */ 0xBA /* ':' -> */, +/* pos 02c6: 379 */ 0x00, 0x40 /* - terminal marker 64 - */, +/* pos 02c8: 380 */ 0x00, 0x41 /* - terminal marker 65 - */, +/* pos 02ca: 381 */ 0xE1 /* 'a' -> */, +/* pos 02cb: 382 */ 0xE4 /* 'd' -> */, +/* pos 02cc: 383 */ 0xA0 /* ' ' -> */, +/* pos 02cd: 384 */ 0x00, 0x42 /* - terminal marker 66 - */, +/* pos 02cf: 385 */ 0xF5 /* 'u' -> */, +/* pos 02d0: 386 */ 0xF4 /* 't' -> */, +/* pos 02d1: 387 */ 0xE8 /* 'h' -> */, +/* pos 02d2: 388 */ 0xAD /* '-' -> */, +/* pos 02d3: 389 */ 0xF4 /* 't' -> */, +/* pos 02d4: 390 */ 0xEF /* 'o' -> */, +/* pos 02d5: 391 */ 0xEB /* 'k' -> */, +/* pos 02d6: 392 */ 0xE5 /* 'e' -> */, +/* pos 02d7: 393 */ 0xEE /* 'n' -> */, +/* pos 02d8: 394 */ 0xBA /* ':' -> */, +/* pos 02d9: 395 */ 0x00, 0x45 /* - terminal marker 69 - */, +/* pos 02db: 396 */ 0xF4 /* 't' -> */, +/* pos 02dc: 397 */ 0xE9 /* 'i' -> */, +/* pos 02dd: 398 */ 0xEF /* 'o' -> */, +/* pos 02de: 399 */ 0xEE /* 'n' -> */, +/* pos 02df: 400 */ 0xF3 /* 's' -> */, +/* pos 02e0: 401 */ 0xA0 /* ' ' -> */, +/* pos 02e1: 402 */ 0x00, 0x02 /* - terminal marker 2 - */, +/* pos 02e3: 403 */ 0xF3 /* 's' -> */, +/* pos 02e4: 404 */ 0xAD /* '-' -> */, +/* pos 02e5: 405 */ 0xE3 /* 'c' -> */, +/* pos 02e6: 406 */ 0xEF /* 'o' -> */, +/* pos 02e7: 407 */ 0xEE /* 'n' -> */, +/* pos 02e8: 408 */ 0xF4 /* 't' -> */, +/* pos 02e9: 409 */ 0xF2 /* 'r' -> */, +/* pos 02ea: 410 */ 0xEF /* 'o' -> */, +/* pos 02eb: 411 */ 0xEC /* 'l' -> */, +/* pos 02ec: 412 */ 0xAD /* '-' -> */, +/* pos 02ed: 413 */ 0x72 /* 'r' */, 0x07, 0x00 /* (to 0x02F4 state 414) */, + 0x61 /* 'a' */, 0x24, 0x00 /* (to 0x0314 state 443) */, + 0x08, /* fail */ +/* pos 02f4: 414 */ 0xE5 /* 'e' -> */, +/* pos 02f5: 415 */ 0xF1 /* 'q' -> */, +/* pos 02f6: 416 */ 0xF5 /* 'u' -> */, +/* pos 02f7: 417 */ 0xE5 /* 'e' -> */, +/* pos 02f8: 418 */ 0xF3 /* 's' -> */, +/* pos 02f9: 419 */ 0xF4 /* 't' -> */, +/* pos 02fa: 420 */ 0xAD /* '-' -> */, +/* pos 02fb: 421 */ 0xE8 /* 'h' -> */, +/* pos 02fc: 422 */ 0xE5 /* 'e' -> */, +/* pos 02fd: 423 */ 0xE1 /* 'a' -> */, +/* pos 02fe: 424 */ 0xE4 /* 'd' -> */, +/* pos 02ff: 425 */ 0xE5 /* 'e' -> */, +/* pos 0300: 426 */ 0xF2 /* 'r' -> */, +/* pos 0301: 427 */ 0xF3 /* 's' -> */, +/* pos 0302: 428 */ 0xBA /* ':' -> */, +/* pos 0303: 429 */ 0x00, 0x0A /* - terminal marker 10 - */, +/* pos 0305: 430 */ 0xF2 /* 'r' -> */, +/* pos 0306: 431 */ 0xE5 /* 'e' -> */, +/* pos 0307: 432 */ 0xF2 /* 'r' -> */, +/* pos 0308: 433 */ 0xBA /* ':' -> */, +/* pos 0309: 434 */ 0x00, 0x17 /* - terminal marker 23 - */, +/* pos 030b: 435 */ 0xE8 /* 'h' -> */, +/* pos 030c: 436 */ 0xE1 /* 'a' -> */, +/* pos 030d: 437 */ 0xF2 /* 'r' -> */, +/* pos 030e: 438 */ 0xF3 /* 's' -> */, +/* pos 030f: 439 */ 0xE5 /* 'e' -> */, +/* pos 0310: 440 */ 0xF4 /* 't' -> */, +/* pos 0311: 441 */ 0xBA /* ':' -> */, +/* pos 0312: 442 */ 0x00, 0x18 /* - terminal marker 24 - */, +/* pos 0314: 443 */ 0xEC /* 'l' -> */, +/* pos 0315: 444 */ 0xEC /* 'l' -> */, +/* pos 0316: 445 */ 0xEF /* 'o' -> */, +/* pos 0317: 446 */ 0xF7 /* 'w' -> */, +/* pos 0318: 447 */ 0xAD /* '-' -> */, +/* pos 0319: 448 */ 0xEF /* 'o' -> */, +/* pos 031a: 449 */ 0xF2 /* 'r' -> */, +/* pos 031b: 450 */ 0xE9 /* 'i' -> */, +/* pos 031c: 451 */ 0xE7 /* 'g' -> */, +/* pos 031d: 452 */ 0xE9 /* 'i' -> */, +/* pos 031e: 453 */ 0xEE /* 'n' -> */, +/* pos 031f: 454 */ 0xBA /* ':' -> */, +/* pos 0320: 455 */ 0x00, 0x1A /* - terminal marker 26 - */, +/* pos 0322: 456 */ 0xE1 /* 'a' -> */, +/* pos 0323: 457 */ 0xF8 /* 'x' -> */, +/* pos 0324: 458 */ 0xAD /* '-' -> */, +/* pos 0325: 459 */ 0xE6 /* 'f' -> */, +/* pos 0326: 460 */ 0xEF /* 'o' -> */, +/* pos 0327: 461 */ 0xF2 /* 'r' -> */, +/* pos 0328: 462 */ 0xF7 /* 'w' -> */, +/* pos 0329: 463 */ 0xE1 /* 'a' -> */, +/* pos 032a: 464 */ 0xF2 /* 'r' -> */, +/* pos 032b: 465 */ 0xE4 /* 'd' -> */, +/* pos 032c: 466 */ 0xF3 /* 's' -> */, +/* pos 032d: 467 */ 0xBA /* ':' -> */, +/* pos 032e: 468 */ 0x00, 0x2C /* - terminal marker 44 - */, +/* pos 0330: 469 */ 0xF8 /* 'x' -> */, +/* pos 0331: 470 */ 0xF9 /* 'y' -> */, +/* pos 0332: 471 */ 0x2D /* '-' */, 0x07, 0x00 /* (to 0x0339 state 472) */, + 0x20 /* ' ' */, 0x79, 0x00 /* (to 0x03AE state 567) */, + 0x08, /* fail */ +/* pos 0339: 472 */ 0xE1 /* 'a' -> */, +/* pos 033a: 473 */ 0xF5 /* 'u' -> */, +/* pos 033b: 474 */ 0xF4 /* 't' -> */, +/* pos 033c: 475 */ 0xE8 /* 'h' -> */, +/* pos 033d: 476 */ 0x65 /* 'e' */, 0x07, 0x00 /* (to 0x0344 state 477) */, + 0x6F /* 'o' */, 0x0E, 0x00 /* (to 0x034E state 486) */, + 0x08, /* fail */ +/* pos 0344: 477 */ 0xEE /* 'n' -> */, +/* pos 0345: 478 */ 0xF4 /* 't' -> */, +/* pos 0346: 479 */ 0xE9 /* 'i' -> */, +/* pos 0347: 480 */ 0xE3 /* 'c' -> */, +/* pos 0348: 481 */ 0xE1 /* 'a' -> */, +/* pos 0349: 482 */ 0xF4 /* 't' -> */, +/* pos 034a: 483 */ 0xE5 /* 'e' -> */, +/* pos 034b: 484 */ 0xBA /* ':' -> */, +/* pos 034c: 485 */ 0x00, 0x2D /* - terminal marker 45 - */, +/* pos 034e: 486 */ 0xF2 /* 'r' -> */, +/* pos 034f: 487 */ 0xE9 /* 'i' -> */, +/* pos 0350: 488 */ 0xFA /* 'z' -> */, +/* pos 0351: 489 */ 0xE1 /* 'a' -> */, +/* pos 0352: 490 */ 0xF4 /* 't' -> */, +/* pos 0353: 491 */ 0xE9 /* 'i' -> */, +/* pos 0354: 492 */ 0xEF /* 'o' -> */, +/* pos 0355: 493 */ 0xEE /* 'n' -> */, +/* pos 0356: 494 */ 0xBA /* ':' -> */, +/* pos 0357: 495 */ 0x00, 0x2E /* - terminal marker 46 - */, +/* pos 0359: 496 */ 0xF2 /* 'r' -> */, +/* pos 035a: 497 */ 0xE9 /* 'i' -> */, +/* pos 035b: 498 */ 0xE3 /* 'c' -> */, +/* pos 035c: 499 */ 0xF4 /* 't' -> */, +/* pos 035d: 500 */ 0xAD /* '-' -> */, +/* pos 035e: 501 */ 0xF4 /* 't' -> */, +/* pos 035f: 502 */ 0xF2 /* 'r' -> */, +/* pos 0360: 503 */ 0xE1 /* 'a' -> */, +/* pos 0361: 504 */ 0xEE /* 'n' -> */, +/* pos 0362: 505 */ 0xF3 /* 's' -> */, +/* pos 0363: 506 */ 0xF0 /* 'p' -> */, +/* pos 0364: 507 */ 0xEF /* 'o' -> */, +/* pos 0365: 508 */ 0xF2 /* 'r' -> */, +/* pos 0366: 509 */ 0xF4 /* 't' -> */, +/* pos 0367: 510 */ 0xAD /* '-' -> */, +/* pos 0368: 511 */ 0xF3 /* 's' -> */, +/* pos 0369: 512 */ 0xE5 /* 'e' -> */, +/* pos 036a: 513 */ 0xE3 /* 'c' -> */, +/* pos 036b: 514 */ 0xF5 /* 'u' -> */, +/* pos 036c: 515 */ 0xF2 /* 'r' -> */, +/* pos 036d: 516 */ 0xE9 /* 'i' -> */, +/* pos 036e: 517 */ 0xF4 /* 't' -> */, +/* pos 036f: 518 */ 0xF9 /* 'y' -> */, +/* pos 0370: 519 */ 0xBA /* ':' -> */, +/* pos 0371: 520 */ 0x00, 0x33 /* - terminal marker 51 - */, +/* pos 0373: 521 */ 0xE5 /* 'e' -> */, +/* pos 0374: 522 */ 0xF2 /* 'r' -> */, +/* pos 0375: 523 */ 0xAD /* '-' -> */, +/* pos 0376: 524 */ 0xE1 /* 'a' -> */, +/* pos 0377: 525 */ 0xE7 /* 'g' -> */, +/* pos 0378: 526 */ 0xE5 /* 'e' -> */, +/* pos 0379: 527 */ 0xEE /* 'n' -> */, +/* pos 037a: 528 */ 0xF4 /* 't' -> */, +/* pos 037b: 529 */ 0xBA /* ':' -> */, +/* pos 037c: 530 */ 0x00, 0x35 /* - terminal marker 53 - */, +/* pos 037e: 531 */ 0x61 /* 'a' */, 0x07, 0x00 /* (to 0x0385 state 532) */, + 0x69 /* 'i' */, 0x09, 0x00 /* (to 0x038A state 536) */, + 0x08, /* fail */ +/* pos 0385: 532 */ 0xF2 /* 'r' -> */, +/* pos 0386: 533 */ 0xF9 /* 'y' -> */, +/* pos 0387: 534 */ 0xBA /* ':' -> */, +/* pos 0388: 535 */ 0x00, 0x36 /* - terminal marker 54 - */, +/* pos 038a: 536 */ 0xE1 /* 'a' -> */, +/* pos 038b: 537 */ 0xBA /* ':' -> */, +/* pos 038c: 538 */ 0x00, 0x37 /* - terminal marker 55 - */, +/* pos 038e: 539 */ 0xF7 /* 'w' -> */, +/* pos 038f: 540 */ 0xF7 /* 'w' -> */, +/* pos 0390: 541 */ 0xAD /* '-' -> */, +/* pos 0391: 542 */ 0xE1 /* 'a' -> */, +/* pos 0392: 543 */ 0xF5 /* 'u' -> */, +/* pos 0393: 544 */ 0xF4 /* 't' -> */, +/* pos 0394: 545 */ 0xE8 /* 'h' -> */, +/* pos 0395: 546 */ 0xE5 /* 'e' -> */, +/* pos 0396: 547 */ 0xEE /* 'n' -> */, +/* pos 0397: 548 */ 0xF4 /* 't' -> */, +/* pos 0398: 549 */ 0xE9 /* 'i' -> */, +/* pos 0399: 550 */ 0xE3 /* 'c' -> */, +/* pos 039a: 551 */ 0xE1 /* 'a' -> */, +/* pos 039b: 552 */ 0xF4 /* 't' -> */, +/* pos 039c: 553 */ 0xE5 /* 'e' -> */, +/* pos 039d: 554 */ 0xBA /* ':' -> */, +/* pos 039e: 555 */ 0x00, 0x38 /* - terminal marker 56 - */, +/* pos 03a0: 556 */ 0xF4 /* 't' -> */, +/* pos 03a1: 557 */ 0xE3 /* 'c' -> */, +/* pos 03a2: 558 */ 0xE8 /* 'h' -> */, +/* pos 03a3: 559 */ 0x00, 0x39 /* - terminal marker 57 - */, +/* pos 03a5: 560 */ 0xF4 /* 't' -> */, +/* pos 03a6: 561 */ 0x00, 0x3A /* - terminal marker 58 - */, +/* pos 03a8: 562 */ 0xEC /* 'l' -> */, +/* pos 03a9: 563 */ 0xE5 /* 'e' -> */, +/* pos 03aa: 564 */ 0xF4 /* 't' -> */, +/* pos 03ab: 565 */ 0xE5 /* 'e' -> */, +/* pos 03ac: 566 */ 0x00, 0x3B /* - terminal marker 59 - */, +/* pos 03ae: 567 */ 0x00, 0x3D /* - terminal marker 61 - */, +/* pos 03b0: 568 */ 0xE5 /* 'e' -> */, +/* pos 03b1: 569 */ 0xE1 /* 'a' -> */, +/* pos 03b2: 570 */ 0xEC /* 'l' -> */, +/* pos 03b3: 571 */ 0xAD /* '-' -> */, +/* pos 03b4: 572 */ 0xE9 /* 'i' -> */, +/* pos 03b5: 573 */ 0xF0 /* 'p' -> */, +/* pos 03b6: 574 */ 0xBA /* ':' -> */, +/* pos 03b7: 575 */ 0x00, 0x3E /* - terminal marker 62 - */, +/* pos 03b9: 576 */ 0xBA /* ':' -> */, +/* pos 03ba: 577 */ 0x00, 0x43 /* - terminal marker 67 - */, +/* pos 03bc: 578 */ 0xEC /* 'l' -> */, +/* pos 03bd: 579 */ 0xE1 /* 'a' -> */, +/* pos 03be: 580 */ 0xF9 /* 'y' -> */, +/* pos 03bf: 581 */ 0xAD /* '-' -> */, +/* pos 03c0: 582 */ 0xEE /* 'n' -> */, +/* pos 03c1: 583 */ 0xEF /* 'o' -> */, +/* pos 03c2: 584 */ 0xEE /* 'n' -> */, +/* pos 03c3: 585 */ 0xE3 /* 'c' -> */, +/* pos 03c4: 586 */ 0xE5 /* 'e' -> */, +/* pos 03c5: 587 */ 0xBA /* ':' -> */, +/* pos 03c6: 588 */ 0x00, 0x44 /* - terminal marker 68 - */, +/* total size 968 bytes */ +#endif + +#if !defined(LWS_HTTP_HEADERS_ALL) && !defined(LWS_WITH_HTTP_UNCOMMON_HEADERS) && defined(LWS_ROLE_WS) && !defined(LWS_ROLE_H2) + /* 0: 0: get */ + /* 1: 1: post */ + /* 2: 3: host: */ + /* 3: 4: connection: */ + /* 4: 5: upgrade: */ + /* 5: 6: origin: */ + /* 6: 7: sec-websocket-draft: */ + /* 7: 8: + */ + /* 8: 9: sec-websocket-extensions: */ + /* 9: 10: sec-websocket-key1: */ + /* 10: 11: sec-websocket-key2: */ + /* 11: 12: sec-websocket-protocol: */ + /* 12: 13: sec-websocket-accept: */ + /* 13: 14: sec-websocket-nonce: */ + /* 14: 15: http/1.1 */ + /* 15: 17: accept: */ + /* 16: 19: if-modified-since: */ + /* 17: 20: if-none-match: */ + /* 18: 21: accept-encoding: */ + /* 19: 22: accept-language: */ + /* 20: 23: pragma: */ + /* 21: 24: cache-control: */ + /* 22: 25: authorization: */ + /* 23: 26: cookie: */ + /* 24: 27: content-length: */ + /* 25: 28: content-type: */ + /* 26: 29: date: */ + /* 27: 30: range: */ + /* 28: 32: sec-websocket-key: */ + /* 29: 33: sec-websocket-version: */ + /* 30: 34: sec-websocket-origin: */ + /* 31: 41: accept-ranges: */ + /* 32: 43: age: */ + /* 33: 44: allow: */ + /* 34: 45: content-disposition: */ + /* 35: 46: content-encoding: */ + /* 36: 47: content-language: */ + /* 37: 48: content-location: */ + /* 38: 49: content-range: */ + /* 39: 50: etag: */ + /* 40: 51: expect: */ + /* 41: 52: expires: */ + /* 42: 53: from: */ + /* 43: 54: if-match: */ + /* 44: 55: if-range: */ + /* 45: 56: if-unmodified-since: */ + /* 46: 57: last-modified: */ + /* 47: 58: link: */ + /* 48: 59: location: */ + /* 49: 63: refresh: */ + /* 50: 64: retry-after: */ + /* 51: 65: server: */ + /* 52: 66: set-cookie: */ + /* 53: 68: transfer-encoding: */ + /* 54: 76: uri-args */ + /* 55: 79: http/1.0 */ + /* 56: 80: x-forwarded-for: */ + /* 57: 81: connect */ + /* 58: 82: head */ + /* 59: 86: x-auth-token: */ + /* 60: 87: */ +/* pos 0000: 0 */ 0x67 /* 'g' */, 0x3D, 0x00 /* (to 0x003D state 1) */, + 0x70 /* 'p' */, 0x3F, 0x00 /* (to 0x0042 state 5) */, + 0x68 /* 'h' */, 0x4E, 0x00 /* (to 0x0054 state 10) */, + 0x63 /* 'c' */, 0x5A, 0x00 /* (to 0x0063 state 15) */, + 0x75 /* 'u' */, 0x7B, 0x00 /* (to 0x0087 state 26) */, + 0x6F /* 'o' */, 0x8A, 0x00 /* (to 0x0099 state 34) */, + 0x0D /* '.' */, 0x95, 0x00 /* (to 0x00A7 state 41) */, + 0x61 /* 'a' */, 0xA4, 0x00 /* (to 0x00B9 state 51) */, + 0x69 /* 'i' */, 0xC1, 0x00 /* (to 0x00D9 state 58) */, + 0x64 /* 'd' */, 0x6A, 0x01 /* (to 0x0185 state 160) */, + 0x72 /* 'r' */, 0x73, 0x01 /* (to 0x0191 state 165) */, + 0x65 /* 'e' */, 0xBF, 0x01 /* (to 0x01E0 state 229) */, + 0x66 /* 'f' */, 0xDB, 0x01 /* (to 0x01FF state 245) */, + 0x6C /* 'l' */, 0xFD, 0x01 /* (to 0x0224 state 278) */, + 0x73 /* 's' */, 0x42, 0x02 /* (to 0x026C state 321) */, + 0x74 /* 't' */, 0x60, 0x02 /* (to 0x028D state 337) */, + 0x78 /* 'x' */, 0x81, 0x02 /* (to 0x02B1 state 364) */, + 0x6D /* 'm' */, 0xF2, 0x02 /* (to 0x0325 state 456) */, + 0x76 /* 'v' */, 0x4B, 0x03 /* (to 0x0381 state 531) */, + 0x77 /* 'w' */, 0x58, 0x03 /* (to 0x0391 state 539) */, + 0x08, /* fail */ +/* pos 003d: 1 */ 0xE5 /* 'e' -> */, +/* pos 003e: 2 */ 0xF4 /* 't' -> */, +/* pos 003f: 3 */ 0xA0 /* ' ' -> */, +/* pos 0040: 4 */ 0x00, 0x00 /* - terminal marker 0 - */, +/* pos 0042: 5 */ 0x6F /* 'o' */, 0x0D, 0x00 /* (to 0x004F state 6) */, + 0x72 /* 'r' */, 0xE6, 0x00 /* (to 0x012B state 106) */, + 0x61 /* 'a' */, 0x5B, 0x03 /* (to 0x03A3 state 556) */, + 0x75 /* 'u' */, 0x5D, 0x03 /* (to 0x03A8 state 560) */, + 0x08, /* fail */ +/* pos 004f: 6 */ 0xF3 /* 's' -> */, +/* pos 0050: 7 */ 0xF4 /* 't' -> */, +/* pos 0051: 8 */ 0xA0 /* ' ' -> */, +/* pos 0052: 9 */ 0x00, 0x01 /* - terminal marker 1 - */, +/* pos 0054: 10 */ 0x6F /* 'o' */, 0x0A, 0x00 /* (to 0x005E state 11) */, + 0x74 /* 't' */, 0x53, 0x00 /* (to 0x00AA state 43) */, + 0x65 /* 'e' */, 0x73, 0x02 /* (to 0x02CD state 381) */, + 0x08, /* fail */ +/* pos 005e: 11 */ 0xF3 /* 's' -> */, +/* pos 005f: 12 */ 0xF4 /* 't' -> */, +/* pos 0060: 13 */ 0xBA /* ':' -> */, +/* pos 0061: 14 */ 0x00, 0x02 /* - terminal marker 2 - */, +/* pos 0063: 15 */ 0x6F /* 'o' */, 0x07, 0x00 /* (to 0x006A state 16) */, + 0x61 /* 'a' */, 0xD2, 0x00 /* (to 0x0138 state 112) */, + 0x08, /* fail */ +/* pos 006a: 16 */ 0x6E /* 'n' */, 0x07, 0x00 /* (to 0x0071 state 17) */, + 0x6F /* 'o' */, 0xE7, 0x00 /* (to 0x0154 state 138) */, + 0x08, /* fail */ +/* pos 0071: 17 */ 0x6E /* 'n' */, 0x07, 0x00 /* (to 0x0078 state 18) */, + 0x74 /* 't' */, 0xE6, 0x00 /* (to 0x015A state 143) */, + 0x08, /* fail */ +/* pos 0078: 18 */ 0xE5 /* 'e' -> */, +/* pos 0079: 19 */ 0xE3 /* 'c' -> */, +/* pos 007a: 20 */ 0xF4 /* 't' -> */, +/* pos 007b: 21 */ 0x69 /* 'i' */, 0x07, 0x00 /* (to 0x0082 state 22) */, + 0x20 /* ' ' */, 0x4D, 0x02 /* (to 0x02CB state 380) */, + 0x08, /* fail */ +/* pos 0082: 22 */ 0xEF /* 'o' -> */, +/* pos 0083: 23 */ 0xEE /* 'n' -> */, +/* pos 0084: 24 */ 0xBA /* ':' -> */, +/* pos 0085: 25 */ 0x00, 0x03 /* - terminal marker 3 - */, +/* pos 0087: 26 */ 0x70 /* 'p' */, 0x0A, 0x00 /* (to 0x0091 state 27) */, + 0x72 /* 'r' */, 0x1C, 0x02 /* (to 0x02A6 state 355) */, + 0x73 /* 's' */, 0xE9, 0x02 /* (to 0x0376 state 521) */, + 0x08, /* fail */ +/* pos 0091: 27 */ 0xE7 /* 'g' -> */, +/* pos 0092: 28 */ 0xF2 /* 'r' -> */, +/* pos 0093: 29 */ 0xE1 /* 'a' -> */, +/* pos 0094: 30 */ 0xE4 /* 'd' -> */, +/* pos 0095: 31 */ 0xE5 /* 'e' -> */, +/* pos 0096: 32 */ 0xBA /* ':' -> */, +/* pos 0097: 33 */ 0x00, 0x04 /* - terminal marker 4 - */, +/* pos 0099: 34 */ 0x72 /* 'r' */, 0x07, 0x00 /* (to 0x00A0 state 35) */, + 0x70 /* 'p' */, 0x42, 0x02 /* (to 0x02DE state 396) */, + 0x08, /* fail */ +/* pos 00a0: 35 */ 0xE9 /* 'i' -> */, +/* pos 00a1: 36 */ 0xE7 /* 'g' -> */, +/* pos 00a2: 37 */ 0xE9 /* 'i' -> */, +/* pos 00a3: 38 */ 0xEE /* 'n' -> */, +/* pos 00a4: 39 */ 0xBA /* ':' -> */, +/* pos 00a5: 40 */ 0x00, 0x05 /* - terminal marker 5 - */, +/* pos 00a7: 41 */ 0x8A /* '.' -> */, +/* pos 00a8: 42 */ 0x00, 0x07 /* - terminal marker 7 - */, +/* pos 00aa: 43 */ 0xF4 /* 't' -> */, +/* pos 00ab: 44 */ 0xF0 /* 'p' -> */, +/* pos 00ac: 45 */ 0xAF /* '/' -> */, +/* pos 00ad: 46 */ 0xB1 /* '1' -> */, +/* pos 00ae: 47 */ 0xAE /* '.' -> */, +/* pos 00af: 48 */ 0x31 /* '1' */, 0x07, 0x00 /* (to 0x00B6 state 49) */, + 0x30 /* '0' */, 0xFC, 0x01 /* (to 0x02AE state 362) */, + 0x08, /* fail */ +/* pos 00b6: 49 */ 0xA0 /* ' ' -> */, +/* pos 00b7: 50 */ 0x00, 0x0E /* - terminal marker 14 - */, +/* pos 00b9: 51 */ 0x63 /* 'c' */, 0x0D, 0x00 /* (to 0x00C6 state 52) */, + 0x75 /* 'u' */, 0x8A, 0x00 /* (to 0x0146 state 125) */, + 0x67 /* 'g' */, 0xE7, 0x00 /* (to 0x01A6 state 178) */, + 0x6C /* 'l' */, 0xE8, 0x00 /* (to 0x01AA state 181) */, + 0x08, /* fail */ +/* pos 00c6: 52 */ 0xE3 /* 'c' -> */, +/* pos 00c7: 53 */ 0xE5 /* 'e' -> */, +/* pos 00c8: 54 */ 0x70 /* 'p' */, 0x07, 0x00 /* (to 0x00CF state 55) */, + 0x73 /* 's' */, 0x1B, 0x02 /* (to 0x02E6 state 403) */, + 0x08, /* fail */ +/* pos 00cf: 55 */ 0xF4 /* 't' -> */, +/* pos 00d0: 56 */ 0x3A /* ':' */, 0x07, 0x00 /* (to 0x00D7 state 57) */, + 0x2D /* '-' */, 0x37, 0x00 /* (to 0x010A state 87) */, + 0x08, /* fail */ +/* pos 00d7: 57 */ 0x00, 0x0F /* - terminal marker 15 - */, +/* pos 00d9: 58 */ 0xE6 /* 'f' -> */, +/* pos 00da: 59 */ 0xAD /* '-' -> */, +/* pos 00db: 60 */ 0x6D /* 'm' */, 0x0D, 0x00 /* (to 0x00E8 state 61) */, + 0x6E /* 'n' */, 0x20, 0x00 /* (to 0x00FE state 76) */, + 0x72 /* 'r' */, 0x2A, 0x01 /* (to 0x020B state 255) */, + 0x75 /* 'u' */, 0x2E, 0x01 /* (to 0x0212 state 261) */, + 0x08, /* fail */ +/* pos 00e8: 61 */ 0x6F /* 'o' */, 0x07, 0x00 /* (to 0x00EF state 62) */, + 0x61 /* 'a' */, 0x1A, 0x01 /* (to 0x0205 state 250) */, + 0x08, /* fail */ +/* pos 00ef: 62 */ 0xE4 /* 'd' -> */, +/* pos 00f0: 63 */ 0xE9 /* 'i' -> */, +/* pos 00f1: 64 */ 0xE6 /* 'f' -> */, +/* pos 00f2: 65 */ 0xE9 /* 'i' -> */, +/* pos 00f3: 66 */ 0xE5 /* 'e' -> */, +/* pos 00f4: 67 */ 0xE4 /* 'd' -> */, +/* pos 00f5: 68 */ 0xAD /* '-' -> */, +/* pos 00f6: 69 */ 0xF3 /* 's' -> */, +/* pos 00f7: 70 */ 0xE9 /* 'i' -> */, +/* pos 00f8: 71 */ 0xEE /* 'n' -> */, +/* pos 00f9: 72 */ 0xE3 /* 'c' -> */, +/* pos 00fa: 73 */ 0xE5 /* 'e' -> */, +/* pos 00fb: 74 */ 0xBA /* ':' -> */, +/* pos 00fc: 75 */ 0x00, 0x10 /* - terminal marker 16 - */, +/* pos 00fe: 76 */ 0xEF /* 'o' -> */, +/* pos 00ff: 77 */ 0xEE /* 'n' -> */, +/* pos 0100: 78 */ 0xE5 /* 'e' -> */, +/* pos 0101: 79 */ 0xAD /* '-' -> */, +/* pos 0102: 80 */ 0xED /* 'm' -> */, +/* pos 0103: 81 */ 0xE1 /* 'a' -> */, +/* pos 0104: 82 */ 0xF4 /* 't' -> */, +/* pos 0105: 83 */ 0xE3 /* 'c' -> */, +/* pos 0106: 84 */ 0xE8 /* 'h' -> */, +/* pos 0107: 85 */ 0xBA /* ':' -> */, +/* pos 0108: 86 */ 0x00, 0x11 /* - terminal marker 17 - */, +/* pos 010a: 87 */ 0x65 /* 'e' */, 0x0D, 0x00 /* (to 0x0117 state 88) */, + 0x6C /* 'l' */, 0x14, 0x00 /* (to 0x0121 state 97) */, + 0x72 /* 'r' */, 0x8E, 0x00 /* (to 0x019E state 171) */, + 0x63 /* 'c' */, 0xFB, 0x01 /* (to 0x030E state 435) */, + 0x08, /* fail */ +/* pos 0117: 88 */ 0xEE /* 'n' -> */, +/* pos 0118: 89 */ 0xE3 /* 'c' -> */, +/* pos 0119: 90 */ 0xEF /* 'o' -> */, +/* pos 011a: 91 */ 0xE4 /* 'd' -> */, +/* pos 011b: 92 */ 0xE9 /* 'i' -> */, +/* pos 011c: 93 */ 0xEE /* 'n' -> */, +/* pos 011d: 94 */ 0xE7 /* 'g' -> */, +/* pos 011e: 95 */ 0xBA /* ':' -> */, +/* pos 011f: 96 */ 0x00, 0x12 /* - terminal marker 18 - */, +/* pos 0121: 97 */ 0xE1 /* 'a' -> */, +/* pos 0122: 98 */ 0xEE /* 'n' -> */, +/* pos 0123: 99 */ 0xE7 /* 'g' -> */, +/* pos 0124: 100 */ 0xF5 /* 'u' -> */, +/* pos 0125: 101 */ 0xE1 /* 'a' -> */, +/* pos 0126: 102 */ 0xE7 /* 'g' -> */, +/* pos 0127: 103 */ 0xE5 /* 'e' -> */, +/* pos 0128: 104 */ 0xBA /* ':' -> */, +/* pos 0129: 105 */ 0x00, 0x13 /* - terminal marker 19 - */, +/* pos 012b: 106 */ 0x61 /* 'a' */, 0x07, 0x00 /* (to 0x0132 state 107) */, + 0x6F /* 'o' */, 0x05, 0x02 /* (to 0x0333 state 469) */, + 0x08, /* fail */ +/* pos 0132: 107 */ 0xE7 /* 'g' -> */, +/* pos 0133: 108 */ 0xED /* 'm' -> */, +/* pos 0134: 109 */ 0xE1 /* 'a' -> */, +/* pos 0135: 110 */ 0xBA /* ':' -> */, +/* pos 0136: 111 */ 0x00, 0x14 /* - terminal marker 20 - */, +/* pos 0138: 112 */ 0xE3 /* 'c' -> */, +/* pos 0139: 113 */ 0xE8 /* 'h' -> */, +/* pos 013a: 114 */ 0xE5 /* 'e' -> */, +/* pos 013b: 115 */ 0xAD /* '-' -> */, +/* pos 013c: 116 */ 0xE3 /* 'c' -> */, +/* pos 013d: 117 */ 0xEF /* 'o' -> */, +/* pos 013e: 118 */ 0xEE /* 'n' -> */, +/* pos 013f: 119 */ 0xF4 /* 't' -> */, +/* pos 0140: 120 */ 0xF2 /* 'r' -> */, +/* pos 0141: 121 */ 0xEF /* 'o' -> */, +/* pos 0142: 122 */ 0xEC /* 'l' -> */, +/* pos 0143: 123 */ 0xBA /* ':' -> */, +/* pos 0144: 124 */ 0x00, 0x15 /* - terminal marker 21 - */, +/* pos 0146: 125 */ 0xF4 /* 't' -> */, +/* pos 0147: 126 */ 0xE8 /* 'h' -> */, +/* pos 0148: 127 */ 0xEF /* 'o' -> */, +/* pos 0149: 128 */ 0xF2 /* 'r' -> */, +/* pos 014a: 129 */ 0xE9 /* 'i' -> */, +/* pos 014b: 130 */ 0xFA /* 'z' -> */, +/* pos 014c: 131 */ 0xE1 /* 'a' -> */, +/* pos 014d: 132 */ 0xF4 /* 't' -> */, +/* pos 014e: 133 */ 0xE9 /* 'i' -> */, +/* pos 014f: 134 */ 0xEF /* 'o' -> */, +/* pos 0150: 135 */ 0xEE /* 'n' -> */, +/* pos 0151: 136 */ 0xBA /* ':' -> */, +/* pos 0152: 137 */ 0x00, 0x16 /* - terminal marker 22 - */, +/* pos 0154: 138 */ 0xEB /* 'k' -> */, +/* pos 0155: 139 */ 0xE9 /* 'i' -> */, +/* pos 0156: 140 */ 0xE5 /* 'e' -> */, +/* pos 0157: 141 */ 0xBA /* ':' -> */, +/* pos 0158: 142 */ 0x00, 0x17 /* - terminal marker 23 - */, +/* pos 015a: 143 */ 0xE5 /* 'e' -> */, +/* pos 015b: 144 */ 0xEE /* 'n' -> */, +/* pos 015c: 145 */ 0xF4 /* 't' -> */, +/* pos 015d: 146 */ 0xAD /* '-' -> */, +/* pos 015e: 147 */ 0x6C /* 'l' */, 0x10, 0x00 /* (to 0x016E state 148) */, + 0x74 /* 't' */, 0x1E, 0x00 /* (to 0x017F state 155) */, + 0x64 /* 'd' */, 0x4C, 0x00 /* (to 0x01B0 state 186) */, + 0x65 /* 'e' */, 0x56, 0x00 /* (to 0x01BD state 198) */, + 0x72 /* 'r' */, 0x6F, 0x00 /* (to 0x01D9 state 223) */, + 0x08, /* fail */ +/* pos 016e: 148 */ 0x65 /* 'e' */, 0x0A, 0x00 /* (to 0x0178 state 149) */, + 0x61 /* 'a' */, 0x56, 0x00 /* (to 0x01C7 state 207) */, + 0x6F /* 'o' */, 0x5C, 0x00 /* (to 0x01D0 state 215) */, + 0x08, /* fail */ +/* pos 0178: 149 */ 0xEE /* 'n' -> */, +/* pos 0179: 150 */ 0xE7 /* 'g' -> */, +/* pos 017a: 151 */ 0xF4 /* 't' -> */, +/* pos 017b: 152 */ 0xE8 /* 'h' -> */, +/* pos 017c: 153 */ 0xBA /* ':' -> */, +/* pos 017d: 154 */ 0x00, 0x18 /* - terminal marker 24 - */, +/* pos 017f: 155 */ 0xF9 /* 'y' -> */, +/* pos 0180: 156 */ 0xF0 /* 'p' -> */, +/* pos 0181: 157 */ 0xE5 /* 'e' -> */, +/* pos 0182: 158 */ 0xBA /* ':' -> */, +/* pos 0183: 159 */ 0x00, 0x19 /* - terminal marker 25 - */, +/* pos 0185: 160 */ 0x61 /* 'a' */, 0x07, 0x00 /* (to 0x018C state 161) */, + 0x65 /* 'e' */, 0x23, 0x02 /* (to 0x03AB state 562) */, + 0x08, /* fail */ +/* pos 018c: 161 */ 0xF4 /* 't' -> */, +/* pos 018d: 162 */ 0xE5 /* 'e' -> */, +/* pos 018e: 163 */ 0xBA /* ':' -> */, +/* pos 018f: 164 */ 0x00, 0x1A /* - terminal marker 26 - */, +/* pos 0191: 165 */ 0x61 /* 'a' */, 0x07, 0x00 /* (to 0x0198 state 166) */, + 0x65 /* 'e' */, 0xB6, 0x00 /* (to 0x024A state 304) */, + 0x08, /* fail */ +/* pos 0198: 166 */ 0xEE /* 'n' -> */, +/* pos 0199: 167 */ 0xE7 /* 'g' -> */, +/* pos 019a: 168 */ 0xE5 /* 'e' -> */, +/* pos 019b: 169 */ 0xBA /* ':' -> */, +/* pos 019c: 170 */ 0x00, 0x1B /* - terminal marker 27 - */, +/* pos 019e: 171 */ 0xE1 /* 'a' -> */, +/* pos 019f: 172 */ 0xEE /* 'n' -> */, +/* pos 01a0: 173 */ 0xE7 /* 'g' -> */, +/* pos 01a1: 174 */ 0xE5 /* 'e' -> */, +/* pos 01a2: 175 */ 0xF3 /* 's' -> */, +/* pos 01a3: 176 */ 0xBA /* ':' -> */, +/* pos 01a4: 177 */ 0x00, 0x1F /* - terminal marker 31 - */, +/* pos 01a6: 178 */ 0xE5 /* 'e' -> */, +/* pos 01a7: 179 */ 0xBA /* ':' -> */, +/* pos 01a8: 180 */ 0x00, 0x20 /* - terminal marker 32 - */, +/* pos 01aa: 181 */ 0xEC /* 'l' -> */, +/* pos 01ab: 182 */ 0xEF /* 'o' -> */, +/* pos 01ac: 183 */ 0xF7 /* 'w' -> */, +/* pos 01ad: 184 */ 0xBA /* ':' -> */, +/* pos 01ae: 185 */ 0x00, 0x21 /* - terminal marker 33 - */, +/* pos 01b0: 186 */ 0xE9 /* 'i' -> */, +/* pos 01b1: 187 */ 0xF3 /* 's' -> */, +/* pos 01b2: 188 */ 0xF0 /* 'p' -> */, +/* pos 01b3: 189 */ 0xEF /* 'o' -> */, +/* pos 01b4: 190 */ 0xF3 /* 's' -> */, +/* pos 01b5: 191 */ 0xE9 /* 'i' -> */, +/* pos 01b6: 192 */ 0xF4 /* 't' -> */, +/* pos 01b7: 193 */ 0xE9 /* 'i' -> */, +/* pos 01b8: 194 */ 0xEF /* 'o' -> */, +/* pos 01b9: 195 */ 0xEE /* 'n' -> */, +/* pos 01ba: 196 */ 0xBA /* ':' -> */, +/* pos 01bb: 197 */ 0x00, 0x22 /* - terminal marker 34 - */, +/* pos 01bd: 198 */ 0xEE /* 'n' -> */, +/* pos 01be: 199 */ 0xE3 /* 'c' -> */, +/* pos 01bf: 200 */ 0xEF /* 'o' -> */, +/* pos 01c0: 201 */ 0xE4 /* 'd' -> */, +/* pos 01c1: 202 */ 0xE9 /* 'i' -> */, +/* pos 01c2: 203 */ 0xEE /* 'n' -> */, +/* pos 01c3: 204 */ 0xE7 /* 'g' -> */, +/* pos 01c4: 205 */ 0xBA /* ':' -> */, +/* pos 01c5: 206 */ 0x00, 0x23 /* - terminal marker 35 - */, +/* pos 01c7: 207 */ 0xEE /* 'n' -> */, +/* pos 01c8: 208 */ 0xE7 /* 'g' -> */, +/* pos 01c9: 209 */ 0xF5 /* 'u' -> */, +/* pos 01ca: 210 */ 0xE1 /* 'a' -> */, +/* pos 01cb: 211 */ 0xE7 /* 'g' -> */, +/* pos 01cc: 212 */ 0xE5 /* 'e' -> */, +/* pos 01cd: 213 */ 0xBA /* ':' -> */, +/* pos 01ce: 214 */ 0x00, 0x24 /* - terminal marker 36 - */, +/* pos 01d0: 215 */ 0xE3 /* 'c' -> */, +/* pos 01d1: 216 */ 0xE1 /* 'a' -> */, +/* pos 01d2: 217 */ 0xF4 /* 't' -> */, +/* pos 01d3: 218 */ 0xE9 /* 'i' -> */, +/* pos 01d4: 219 */ 0xEF /* 'o' -> */, +/* pos 01d5: 220 */ 0xEE /* 'n' -> */, +/* pos 01d6: 221 */ 0xBA /* ':' -> */, +/* pos 01d7: 222 */ 0x00, 0x25 /* - terminal marker 37 - */, +/* pos 01d9: 223 */ 0xE1 /* 'a' -> */, +/* pos 01da: 224 */ 0xEE /* 'n' -> */, +/* pos 01db: 225 */ 0xE7 /* 'g' -> */, +/* pos 01dc: 226 */ 0xE5 /* 'e' -> */, +/* pos 01dd: 227 */ 0xBA /* ':' -> */, +/* pos 01de: 228 */ 0x00, 0x26 /* - terminal marker 38 - */, +/* pos 01e0: 229 */ 0x74 /* 't' */, 0x07, 0x00 /* (to 0x01E7 state 230) */, + 0x78 /* 'x' */, 0x09, 0x00 /* (to 0x01EC state 234) */, + 0x08, /* fail */ +/* pos 01e7: 230 */ 0xE1 /* 'a' -> */, +/* pos 01e8: 231 */ 0xE7 /* 'g' -> */, +/* pos 01e9: 232 */ 0xBA /* ':' -> */, +/* pos 01ea: 233 */ 0x00, 0x27 /* - terminal marker 39 - */, +/* pos 01ec: 234 */ 0xF0 /* 'p' -> */, +/* pos 01ed: 235 */ 0x65 /* 'e' */, 0x07, 0x00 /* (to 0x01F4 state 236) */, + 0x69 /* 'i' */, 0x09, 0x00 /* (to 0x01F9 state 240) */, + 0x08, /* fail */ +/* pos 01f4: 236 */ 0xE3 /* 'c' -> */, +/* pos 01f5: 237 */ 0xF4 /* 't' -> */, +/* pos 01f6: 238 */ 0xBA /* ':' -> */, +/* pos 01f7: 239 */ 0x00, 0x28 /* - terminal marker 40 - */, +/* pos 01f9: 240 */ 0xF2 /* 'r' -> */, +/* pos 01fa: 241 */ 0xE5 /* 'e' -> */, +/* pos 01fb: 242 */ 0xF3 /* 's' -> */, +/* pos 01fc: 243 */ 0xBA /* ':' -> */, +/* pos 01fd: 244 */ 0x00, 0x29 /* - terminal marker 41 - */, +/* pos 01ff: 245 */ 0xF2 /* 'r' -> */, +/* pos 0200: 246 */ 0xEF /* 'o' -> */, +/* pos 0201: 247 */ 0xED /* 'm' -> */, +/* pos 0202: 248 */ 0xBA /* ':' -> */, +/* pos 0203: 249 */ 0x00, 0x2A /* - terminal marker 42 - */, +/* pos 0205: 250 */ 0xF4 /* 't' -> */, +/* pos 0206: 251 */ 0xE3 /* 'c' -> */, +/* pos 0207: 252 */ 0xE8 /* 'h' -> */, +/* pos 0208: 253 */ 0xBA /* ':' -> */, +/* pos 0209: 254 */ 0x00, 0x2B /* - terminal marker 43 - */, +/* pos 020b: 255 */ 0xE1 /* 'a' -> */, +/* pos 020c: 256 */ 0xEE /* 'n' -> */, +/* pos 020d: 257 */ 0xE7 /* 'g' -> */, +/* pos 020e: 258 */ 0xE5 /* 'e' -> */, +/* pos 020f: 259 */ 0xBA /* ':' -> */, +/* pos 0210: 260 */ 0x00, 0x2C /* - terminal marker 44 - */, +/* pos 0212: 261 */ 0xEE /* 'n' -> */, +/* pos 0213: 262 */ 0xED /* 'm' -> */, +/* pos 0214: 263 */ 0xEF /* 'o' -> */, +/* pos 0215: 264 */ 0xE4 /* 'd' -> */, +/* pos 0216: 265 */ 0xE9 /* 'i' -> */, +/* pos 0217: 266 */ 0xE6 /* 'f' -> */, +/* pos 0218: 267 */ 0xE9 /* 'i' -> */, +/* pos 0219: 268 */ 0xE5 /* 'e' -> */, +/* pos 021a: 269 */ 0xE4 /* 'd' -> */, +/* pos 021b: 270 */ 0xAD /* '-' -> */, +/* pos 021c: 271 */ 0xF3 /* 's' -> */, +/* pos 021d: 272 */ 0xE9 /* 'i' -> */, +/* pos 021e: 273 */ 0xEE /* 'n' -> */, +/* pos 021f: 274 */ 0xE3 /* 'c' -> */, +/* pos 0220: 275 */ 0xE5 /* 'e' -> */, +/* pos 0221: 276 */ 0xBA /* ':' -> */, +/* pos 0222: 277 */ 0x00, 0x2D /* - terminal marker 45 - */, +/* pos 0224: 278 */ 0x61 /* 'a' */, 0x0A, 0x00 /* (to 0x022E state 279) */, + 0x69 /* 'i' */, 0x15, 0x00 /* (to 0x023C state 292) */, + 0x6F /* 'o' */, 0x17, 0x00 /* (to 0x0241 state 296) */, + 0x08, /* fail */ +/* pos 022e: 279 */ 0xF3 /* 's' -> */, +/* pos 022f: 280 */ 0xF4 /* 't' -> */, +/* pos 0230: 281 */ 0xAD /* '-' -> */, +/* pos 0231: 282 */ 0xED /* 'm' -> */, +/* pos 0232: 283 */ 0xEF /* 'o' -> */, +/* pos 0233: 284 */ 0xE4 /* 'd' -> */, +/* pos 0234: 285 */ 0xE9 /* 'i' -> */, +/* pos 0235: 286 */ 0xE6 /* 'f' -> */, +/* pos 0236: 287 */ 0xE9 /* 'i' -> */, +/* pos 0237: 288 */ 0xE5 /* 'e' -> */, +/* pos 0238: 289 */ 0xE4 /* 'd' -> */, +/* pos 0239: 290 */ 0xBA /* ':' -> */, +/* pos 023a: 291 */ 0x00, 0x2E /* - terminal marker 46 - */, +/* pos 023c: 292 */ 0xEE /* 'n' -> */, +/* pos 023d: 293 */ 0xEB /* 'k' -> */, +/* pos 023e: 294 */ 0xBA /* ':' -> */, +/* pos 023f: 295 */ 0x00, 0x2F /* - terminal marker 47 - */, +/* pos 0241: 296 */ 0xE3 /* 'c' -> */, +/* pos 0242: 297 */ 0xE1 /* 'a' -> */, +/* pos 0243: 298 */ 0xF4 /* 't' -> */, +/* pos 0244: 299 */ 0xE9 /* 'i' -> */, +/* pos 0245: 300 */ 0xEF /* 'o' -> */, +/* pos 0246: 301 */ 0xEE /* 'n' -> */, +/* pos 0247: 302 */ 0xBA /* ':' -> */, +/* pos 0248: 303 */ 0x00, 0x30 /* - terminal marker 48 - */, +/* pos 024a: 304 */ 0x66 /* 'f' */, 0x0A, 0x00 /* (to 0x0254 state 305) */, + 0x74 /* 't' */, 0x14, 0x00 /* (to 0x0261 state 311) */, + 0x70 /* 'p' */, 0x6F, 0x01 /* (to 0x03BF state 578) */, + 0x08, /* fail */ +/* pos 0254: 305 */ 0x72 /* 'r' */, 0x07, 0x00 /* (to 0x025B state 306) */, + 0x65 /* 'e' */, 0xB1, 0x00 /* (to 0x0308 state 430) */, + 0x08, /* fail */ +/* pos 025b: 306 */ 0xE5 /* 'e' -> */, +/* pos 025c: 307 */ 0xF3 /* 's' -> */, +/* pos 025d: 308 */ 0xE8 /* 'h' -> */, +/* pos 025e: 309 */ 0xBA /* ':' -> */, +/* pos 025f: 310 */ 0x00, 0x31 /* - terminal marker 49 - */, +/* pos 0261: 311 */ 0xF2 /* 'r' -> */, +/* pos 0262: 312 */ 0xF9 /* 'y' -> */, +/* pos 0263: 313 */ 0xAD /* '-' -> */, +/* pos 0264: 314 */ 0xE1 /* 'a' -> */, +/* pos 0265: 315 */ 0xE6 /* 'f' -> */, +/* pos 0266: 316 */ 0xF4 /* 't' -> */, +/* pos 0267: 317 */ 0xE5 /* 'e' -> */, +/* pos 0268: 318 */ 0xF2 /* 'r' -> */, +/* pos 0269: 319 */ 0xBA /* ':' -> */, +/* pos 026a: 320 */ 0x00, 0x32 /* - terminal marker 50 - */, +/* pos 026c: 321 */ 0x65 /* 'e' */, 0x07, 0x00 /* (to 0x0273 state 322) */, + 0x74 /* 't' */, 0xED, 0x00 /* (to 0x035C state 496) */, + 0x08, /* fail */ +/* pos 0273: 322 */ 0x72 /* 'r' */, 0x0A, 0x00 /* (to 0x027D state 323) */, + 0x74 /* 't' */, 0x0D, 0x00 /* (to 0x0283 state 328) */, + 0x63 /* 'c' */, 0x52, 0x01 /* (to 0x03CB state 589) */, + 0x08, /* fail */ +/* pos 027d: 323 */ 0xF6 /* 'v' -> */, +/* pos 027e: 324 */ 0xE5 /* 'e' -> */, +/* pos 027f: 325 */ 0xF2 /* 'r' -> */, +/* pos 0280: 326 */ 0xBA /* ':' -> */, +/* pos 0281: 327 */ 0x00, 0x33 /* - terminal marker 51 - */, +/* pos 0283: 328 */ 0xAD /* '-' -> */, +/* pos 0284: 329 */ 0xE3 /* 'c' -> */, +/* pos 0285: 330 */ 0xEF /* 'o' -> */, +/* pos 0286: 331 */ 0xEF /* 'o' -> */, +/* pos 0287: 332 */ 0xEB /* 'k' -> */, +/* pos 0288: 333 */ 0xE9 /* 'i' -> */, +/* pos 0289: 334 */ 0xE5 /* 'e' -> */, +/* pos 028a: 335 */ 0xBA /* ':' -> */, +/* pos 028b: 336 */ 0x00, 0x34 /* - terminal marker 52 - */, +/* pos 028d: 337 */ 0x72 /* 'r' */, 0x07, 0x00 /* (to 0x0294 state 338) */, + 0x65 /* 'e' */, 0x2C, 0x01 /* (to 0x03BC state 576) */, + 0x08, /* fail */ +/* pos 0294: 338 */ 0xE1 /* 'a' -> */, +/* pos 0295: 339 */ 0xEE /* 'n' -> */, +/* pos 0296: 340 */ 0xF3 /* 's' -> */, +/* pos 0297: 341 */ 0xE6 /* 'f' -> */, +/* pos 0298: 342 */ 0xE5 /* 'e' -> */, +/* pos 0299: 343 */ 0xF2 /* 'r' -> */, +/* pos 029a: 344 */ 0xAD /* '-' -> */, +/* pos 029b: 345 */ 0xE5 /* 'e' -> */, +/* pos 029c: 346 */ 0xEE /* 'n' -> */, +/* pos 029d: 347 */ 0xE3 /* 'c' -> */, +/* pos 029e: 348 */ 0xEF /* 'o' -> */, +/* pos 029f: 349 */ 0xE4 /* 'd' -> */, +/* pos 02a0: 350 */ 0xE9 /* 'i' -> */, +/* pos 02a1: 351 */ 0xEE /* 'n' -> */, +/* pos 02a2: 352 */ 0xE7 /* 'g' -> */, +/* pos 02a3: 353 */ 0xBA /* ':' -> */, +/* pos 02a4: 354 */ 0x00, 0x35 /* - terminal marker 53 - */, +/* pos 02a6: 355 */ 0xE9 /* 'i' -> */, +/* pos 02a7: 356 */ 0xAD /* '-' -> */, +/* pos 02a8: 357 */ 0xE1 /* 'a' -> */, +/* pos 02a9: 358 */ 0xF2 /* 'r' -> */, +/* pos 02aa: 359 */ 0xE7 /* 'g' -> */, +/* pos 02ab: 360 */ 0xF3 /* 's' -> */, +/* pos 02ac: 361 */ 0x00, 0x36 /* - terminal marker 54 - */, +/* pos 02ae: 362 */ 0xA0 /* ' ' -> */, +/* pos 02af: 363 */ 0x00, 0x37 /* - terminal marker 55 - */, +/* pos 02b1: 364 */ 0xAD /* '-' -> */, +/* pos 02b2: 365 */ 0x66 /* 'f' */, 0x0A, 0x00 /* (to 0x02BC state 366) */, + 0x61 /* 'a' */, 0x1D, 0x00 /* (to 0x02D2 state 385) */, + 0x72 /* 'r' */, 0xFB, 0x00 /* (to 0x03B3 state 568) */, + 0x08, /* fail */ +/* pos 02bc: 366 */ 0xEF /* 'o' -> */, +/* pos 02bd: 367 */ 0xF2 /* 'r' -> */, +/* pos 02be: 368 */ 0xF7 /* 'w' -> */, +/* pos 02bf: 369 */ 0xE1 /* 'a' -> */, +/* pos 02c0: 370 */ 0xF2 /* 'r' -> */, +/* pos 02c1: 371 */ 0xE4 /* 'd' -> */, +/* pos 02c2: 372 */ 0xE5 /* 'e' -> */, +/* pos 02c3: 373 */ 0xE4 /* 'd' -> */, +/* pos 02c4: 374 */ 0xAD /* '-' -> */, +/* pos 02c5: 375 */ 0xE6 /* 'f' -> */, +/* pos 02c6: 376 */ 0xEF /* 'o' -> */, +/* pos 02c7: 377 */ 0xF2 /* 'r' -> */, +/* pos 02c8: 378 */ 0xBA /* ':' -> */, +/* pos 02c9: 379 */ 0x00, 0x38 /* - terminal marker 56 - */, +/* pos 02cb: 380 */ 0x00, 0x39 /* - terminal marker 57 - */, +/* pos 02cd: 381 */ 0xE1 /* 'a' -> */, +/* pos 02ce: 382 */ 0xE4 /* 'd' -> */, +/* pos 02cf: 383 */ 0xA0 /* ' ' -> */, +/* pos 02d0: 384 */ 0x00, 0x3A /* - terminal marker 58 - */, +/* pos 02d2: 385 */ 0xF5 /* 'u' -> */, +/* pos 02d3: 386 */ 0xF4 /* 't' -> */, +/* pos 02d4: 387 */ 0xE8 /* 'h' -> */, +/* pos 02d5: 388 */ 0xAD /* '-' -> */, +/* pos 02d6: 389 */ 0xF4 /* 't' -> */, +/* pos 02d7: 390 */ 0xEF /* 'o' -> */, +/* pos 02d8: 391 */ 0xEB /* 'k' -> */, +/* pos 02d9: 392 */ 0xE5 /* 'e' -> */, +/* pos 02da: 393 */ 0xEE /* 'n' -> */, +/* pos 02db: 394 */ 0xBA /* ':' -> */, +/* pos 02dc: 395 */ 0x00, 0x3B /* - terminal marker 59 - */, +/* pos 02de: 396 */ 0xF4 /* 't' -> */, +/* pos 02df: 397 */ 0xE9 /* 'i' -> */, +/* pos 02e0: 398 */ 0xEF /* 'o' -> */, +/* pos 02e1: 399 */ 0xEE /* 'n' -> */, +/* pos 02e2: 400 */ 0xF3 /* 's' -> */, +/* pos 02e3: 401 */ 0xA0 /* ' ' -> */, +/* pos 02e4: 402 */ 0x00, 0x02 /* - terminal marker 2 - */, +/* pos 02e6: 403 */ 0xF3 /* 's' -> */, +/* pos 02e7: 404 */ 0xAD /* '-' -> */, +/* pos 02e8: 405 */ 0xE3 /* 'c' -> */, +/* pos 02e9: 406 */ 0xEF /* 'o' -> */, +/* pos 02ea: 407 */ 0xEE /* 'n' -> */, +/* pos 02eb: 408 */ 0xF4 /* 't' -> */, +/* pos 02ec: 409 */ 0xF2 /* 'r' -> */, +/* pos 02ed: 410 */ 0xEF /* 'o' -> */, +/* pos 02ee: 411 */ 0xEC /* 'l' -> */, +/* pos 02ef: 412 */ 0xAD /* '-' -> */, +/* pos 02f0: 413 */ 0x72 /* 'r' */, 0x07, 0x00 /* (to 0x02F7 state 414) */, + 0x61 /* 'a' */, 0x24, 0x00 /* (to 0x0317 state 443) */, + 0x08, /* fail */ +/* pos 02f7: 414 */ 0xE5 /* 'e' -> */, +/* pos 02f8: 415 */ 0xF1 /* 'q' -> */, +/* pos 02f9: 416 */ 0xF5 /* 'u' -> */, +/* pos 02fa: 417 */ 0xE5 /* 'e' -> */, +/* pos 02fb: 418 */ 0xF3 /* 's' -> */, +/* pos 02fc: 419 */ 0xF4 /* 't' -> */, +/* pos 02fd: 420 */ 0xAD /* '-' -> */, +/* pos 02fe: 421 */ 0xE8 /* 'h' -> */, +/* pos 02ff: 422 */ 0xE5 /* 'e' -> */, +/* pos 0300: 423 */ 0xE1 /* 'a' -> */, +/* pos 0301: 424 */ 0xE4 /* 'd' -> */, +/* pos 0302: 425 */ 0xE5 /* 'e' -> */, +/* pos 0303: 426 */ 0xF2 /* 'r' -> */, +/* pos 0304: 427 */ 0xF3 /* 's' -> */, +/* pos 0305: 428 */ 0xBA /* ':' -> */, +/* pos 0306: 429 */ 0x00, 0x0A /* - terminal marker 10 - */, +/* pos 0308: 430 */ 0xF2 /* 'r' -> */, +/* pos 0309: 431 */ 0xE5 /* 'e' -> */, +/* pos 030a: 432 */ 0xF2 /* 'r' -> */, +/* pos 030b: 433 */ 0xBA /* ':' -> */, +/* pos 030c: 434 */ 0x00, 0x17 /* - terminal marker 23 - */, +/* pos 030e: 435 */ 0xE8 /* 'h' -> */, +/* pos 030f: 436 */ 0xE1 /* 'a' -> */, +/* pos 0310: 437 */ 0xF2 /* 'r' -> */, +/* pos 0311: 438 */ 0xF3 /* 's' -> */, +/* pos 0312: 439 */ 0xE5 /* 'e' -> */, +/* pos 0313: 440 */ 0xF4 /* 't' -> */, +/* pos 0314: 441 */ 0xBA /* ':' -> */, +/* pos 0315: 442 */ 0x00, 0x18 /* - terminal marker 24 - */, +/* pos 0317: 443 */ 0xEC /* 'l' -> */, +/* pos 0318: 444 */ 0xEC /* 'l' -> */, +/* pos 0319: 445 */ 0xEF /* 'o' -> */, +/* pos 031a: 446 */ 0xF7 /* 'w' -> */, +/* pos 031b: 447 */ 0xAD /* '-' -> */, +/* pos 031c: 448 */ 0xEF /* 'o' -> */, +/* pos 031d: 449 */ 0xF2 /* 'r' -> */, +/* pos 031e: 450 */ 0xE9 /* 'i' -> */, +/* pos 031f: 451 */ 0xE7 /* 'g' -> */, +/* pos 0320: 452 */ 0xE9 /* 'i' -> */, +/* pos 0321: 453 */ 0xEE /* 'n' -> */, +/* pos 0322: 454 */ 0xBA /* ':' -> */, +/* pos 0323: 455 */ 0x00, 0x1A /* - terminal marker 26 - */, +/* pos 0325: 456 */ 0xE1 /* 'a' -> */, +/* pos 0326: 457 */ 0xF8 /* 'x' -> */, +/* pos 0327: 458 */ 0xAD /* '-' -> */, +/* pos 0328: 459 */ 0xE6 /* 'f' -> */, +/* pos 0329: 460 */ 0xEF /* 'o' -> */, +/* pos 032a: 461 */ 0xF2 /* 'r' -> */, +/* pos 032b: 462 */ 0xF7 /* 'w' -> */, +/* pos 032c: 463 */ 0xE1 /* 'a' -> */, +/* pos 032d: 464 */ 0xF2 /* 'r' -> */, +/* pos 032e: 465 */ 0xE4 /* 'd' -> */, +/* pos 032f: 466 */ 0xF3 /* 's' -> */, +/* pos 0330: 467 */ 0xBA /* ':' -> */, +/* pos 0331: 468 */ 0x00, 0x2C /* - terminal marker 44 - */, +/* pos 0333: 469 */ 0xF8 /* 'x' -> */, +/* pos 0334: 470 */ 0xF9 /* 'y' -> */, +/* pos 0335: 471 */ 0x2D /* '-' */, 0x07, 0x00 /* (to 0x033C state 472) */, + 0x20 /* ' ' */, 0x79, 0x00 /* (to 0x03B1 state 567) */, + 0x08, /* fail */ +/* pos 033c: 472 */ 0xE1 /* 'a' -> */, +/* pos 033d: 473 */ 0xF5 /* 'u' -> */, +/* pos 033e: 474 */ 0xF4 /* 't' -> */, +/* pos 033f: 475 */ 0xE8 /* 'h' -> */, +/* pos 0340: 476 */ 0x65 /* 'e' */, 0x07, 0x00 /* (to 0x0347 state 477) */, + 0x6F /* 'o' */, 0x0E, 0x00 /* (to 0x0351 state 486) */, + 0x08, /* fail */ +/* pos 0347: 477 */ 0xEE /* 'n' -> */, +/* pos 0348: 478 */ 0xF4 /* 't' -> */, +/* pos 0349: 479 */ 0xE9 /* 'i' -> */, +/* pos 034a: 480 */ 0xE3 /* 'c' -> */, +/* pos 034b: 481 */ 0xE1 /* 'a' -> */, +/* pos 034c: 482 */ 0xF4 /* 't' -> */, +/* pos 034d: 483 */ 0xE5 /* 'e' -> */, +/* pos 034e: 484 */ 0xBA /* ':' -> */, +/* pos 034f: 485 */ 0x00, 0x2D /* - terminal marker 45 - */, +/* pos 0351: 486 */ 0xF2 /* 'r' -> */, +/* pos 0352: 487 */ 0xE9 /* 'i' -> */, +/* pos 0353: 488 */ 0xFA /* 'z' -> */, +/* pos 0354: 489 */ 0xE1 /* 'a' -> */, +/* pos 0355: 490 */ 0xF4 /* 't' -> */, +/* pos 0356: 491 */ 0xE9 /* 'i' -> */, +/* pos 0357: 492 */ 0xEF /* 'o' -> */, +/* pos 0358: 493 */ 0xEE /* 'n' -> */, +/* pos 0359: 494 */ 0xBA /* ':' -> */, +/* pos 035a: 495 */ 0x00, 0x2E /* - terminal marker 46 - */, +/* pos 035c: 496 */ 0xF2 /* 'r' -> */, +/* pos 035d: 497 */ 0xE9 /* 'i' -> */, +/* pos 035e: 498 */ 0xE3 /* 'c' -> */, +/* pos 035f: 499 */ 0xF4 /* 't' -> */, +/* pos 0360: 500 */ 0xAD /* '-' -> */, +/* pos 0361: 501 */ 0xF4 /* 't' -> */, +/* pos 0362: 502 */ 0xF2 /* 'r' -> */, +/* pos 0363: 503 */ 0xE1 /* 'a' -> */, +/* pos 0364: 504 */ 0xEE /* 'n' -> */, +/* pos 0365: 505 */ 0xF3 /* 's' -> */, +/* pos 0366: 506 */ 0xF0 /* 'p' -> */, +/* pos 0367: 507 */ 0xEF /* 'o' -> */, +/* pos 0368: 508 */ 0xF2 /* 'r' -> */, +/* pos 0369: 509 */ 0xF4 /* 't' -> */, +/* pos 036a: 510 */ 0xAD /* '-' -> */, +/* pos 036b: 511 */ 0xF3 /* 's' -> */, +/* pos 036c: 512 */ 0xE5 /* 'e' -> */, +/* pos 036d: 513 */ 0xE3 /* 'c' -> */, +/* pos 036e: 514 */ 0xF5 /* 'u' -> */, +/* pos 036f: 515 */ 0xF2 /* 'r' -> */, +/* pos 0370: 516 */ 0xE9 /* 'i' -> */, +/* pos 0371: 517 */ 0xF4 /* 't' -> */, +/* pos 0372: 518 */ 0xF9 /* 'y' -> */, +/* pos 0373: 519 */ 0xBA /* ':' -> */, +/* pos 0374: 520 */ 0x00, 0x33 /* - terminal marker 51 - */, +/* pos 0376: 521 */ 0xE5 /* 'e' -> */, +/* pos 0377: 522 */ 0xF2 /* 'r' -> */, +/* pos 0378: 523 */ 0xAD /* '-' -> */, +/* pos 0379: 524 */ 0xE1 /* 'a' -> */, +/* pos 037a: 525 */ 0xE7 /* 'g' -> */, +/* pos 037b: 526 */ 0xE5 /* 'e' -> */, +/* pos 037c: 527 */ 0xEE /* 'n' -> */, +/* pos 037d: 528 */ 0xF4 /* 't' -> */, +/* pos 037e: 529 */ 0xBA /* ':' -> */, +/* pos 037f: 530 */ 0x00, 0x35 /* - terminal marker 53 - */, +/* pos 0381: 531 */ 0x61 /* 'a' */, 0x07, 0x00 /* (to 0x0388 state 532) */, + 0x69 /* 'i' */, 0x09, 0x00 /* (to 0x038D state 536) */, + 0x08, /* fail */ +/* pos 0388: 532 */ 0xF2 /* 'r' -> */, +/* pos 0389: 533 */ 0xF9 /* 'y' -> */, +/* pos 038a: 534 */ 0xBA /* ':' -> */, +/* pos 038b: 535 */ 0x00, 0x36 /* - terminal marker 54 - */, +/* pos 038d: 536 */ 0xE1 /* 'a' -> */, +/* pos 038e: 537 */ 0xBA /* ':' -> */, +/* pos 038f: 538 */ 0x00, 0x37 /* - terminal marker 55 - */, +/* pos 0391: 539 */ 0xF7 /* 'w' -> */, +/* pos 0392: 540 */ 0xF7 /* 'w' -> */, +/* pos 0393: 541 */ 0xAD /* '-' -> */, +/* pos 0394: 542 */ 0xE1 /* 'a' -> */, +/* pos 0395: 543 */ 0xF5 /* 'u' -> */, +/* pos 0396: 544 */ 0xF4 /* 't' -> */, +/* pos 0397: 545 */ 0xE8 /* 'h' -> */, +/* pos 0398: 546 */ 0xE5 /* 'e' -> */, +/* pos 0399: 547 */ 0xEE /* 'n' -> */, +/* pos 039a: 548 */ 0xF4 /* 't' -> */, +/* pos 039b: 549 */ 0xE9 /* 'i' -> */, +/* pos 039c: 550 */ 0xE3 /* 'c' -> */, +/* pos 039d: 551 */ 0xE1 /* 'a' -> */, +/* pos 039e: 552 */ 0xF4 /* 't' -> */, +/* pos 039f: 553 */ 0xE5 /* 'e' -> */, +/* pos 03a0: 554 */ 0xBA /* ':' -> */, +/* pos 03a1: 555 */ 0x00, 0x38 /* - terminal marker 56 - */, +/* pos 03a3: 556 */ 0xF4 /* 't' -> */, +/* pos 03a4: 557 */ 0xE3 /* 'c' -> */, +/* pos 03a5: 558 */ 0xE8 /* 'h' -> */, +/* pos 03a6: 559 */ 0x00, 0x39 /* - terminal marker 57 - */, +/* pos 03a8: 560 */ 0xF4 /* 't' -> */, +/* pos 03a9: 561 */ 0x00, 0x3A /* - terminal marker 58 - */, +/* pos 03ab: 562 */ 0xEC /* 'l' -> */, +/* pos 03ac: 563 */ 0xE5 /* 'e' -> */, +/* pos 03ad: 564 */ 0xF4 /* 't' -> */, +/* pos 03ae: 565 */ 0xE5 /* 'e' -> */, +/* pos 03af: 566 */ 0x00, 0x3B /* - terminal marker 59 - */, +/* pos 03b1: 567 */ 0x00, 0x3D /* - terminal marker 61 - */, +/* pos 03b3: 568 */ 0xE5 /* 'e' -> */, +/* pos 03b4: 569 */ 0xE1 /* 'a' -> */, +/* pos 03b5: 570 */ 0xEC /* 'l' -> */, +/* pos 03b6: 571 */ 0xAD /* '-' -> */, +/* pos 03b7: 572 */ 0xE9 /* 'i' -> */, +/* pos 03b8: 573 */ 0xF0 /* 'p' -> */, +/* pos 03b9: 574 */ 0xBA /* ':' -> */, +/* pos 03ba: 575 */ 0x00, 0x3E /* - terminal marker 62 - */, +/* pos 03bc: 576 */ 0xBA /* ':' -> */, +/* pos 03bd: 577 */ 0x00, 0x43 /* - terminal marker 67 - */, +/* pos 03bf: 578 */ 0xEC /* 'l' -> */, +/* pos 03c0: 579 */ 0xE1 /* 'a' -> */, +/* pos 03c1: 580 */ 0xF9 /* 'y' -> */, +/* pos 03c2: 581 */ 0xAD /* '-' -> */, +/* pos 03c3: 582 */ 0xEE /* 'n' -> */, +/* pos 03c4: 583 */ 0xEF /* 'o' -> */, +/* pos 03c5: 584 */ 0xEE /* 'n' -> */, +/* pos 03c6: 585 */ 0xE3 /* 'c' -> */, +/* pos 03c7: 586 */ 0xE5 /* 'e' -> */, +/* pos 03c8: 587 */ 0xBA /* ':' -> */, +/* pos 03c9: 588 */ 0x00, 0x44 /* - terminal marker 68 - */, +/* pos 03cb: 589 */ 0xAD /* '-' -> */, +/* pos 03cc: 590 */ 0xF7 /* 'w' -> */, +/* pos 03cd: 591 */ 0xE5 /* 'e' -> */, +/* pos 03ce: 592 */ 0xE2 /* 'b' -> */, +/* pos 03cf: 593 */ 0xF3 /* 's' -> */, +/* pos 03d0: 594 */ 0xEF /* 'o' -> */, +/* pos 03d1: 595 */ 0xE3 /* 'c' -> */, +/* pos 03d2: 596 */ 0xEB /* 'k' -> */, +/* pos 03d3: 597 */ 0xE5 /* 'e' -> */, +/* pos 03d4: 598 */ 0xF4 /* 't' -> */, +/* pos 03d5: 599 */ 0xAD /* '-' -> */, +/* pos 03d6: 600 */ 0x64 /* 'd' */, 0x19, 0x00 /* (to 0x03EF state 601) */, + 0x65 /* 'e' */, 0x1D, 0x00 /* (to 0x03F6 state 607) */, + 0x6B /* 'k' */, 0x26, 0x00 /* (to 0x0402 state 618) */, + 0x70 /* 'p' */, 0x35, 0x00 /* (to 0x0414 state 625) */, + 0x61 /* 'a' */, 0x3C, 0x00 /* (to 0x041E state 634) */, + 0x6E /* 'n' */, 0x41, 0x00 /* (to 0x0426 state 641) */, + 0x76 /* 'v' */, 0x47, 0x00 /* (to 0x042F state 648) */, + 0x6F /* 'o' */, 0x4D, 0x00 /* (to 0x0438 state 656) */, + 0x08, /* fail */ +/* pos 03ef: 601 */ 0xF2 /* 'r' -> */, +/* pos 03f0: 602 */ 0xE1 /* 'a' -> */, +/* pos 03f1: 603 */ 0xE6 /* 'f' -> */, +/* pos 03f2: 604 */ 0xF4 /* 't' -> */, +/* pos 03f3: 605 */ 0xBA /* ':' -> */, +/* pos 03f4: 606 */ 0x00, 0x06 /* - terminal marker 6 - */, +/* pos 03f6: 607 */ 0xF8 /* 'x' -> */, +/* pos 03f7: 608 */ 0xF4 /* 't' -> */, +/* pos 03f8: 609 */ 0xE5 /* 'e' -> */, +/* pos 03f9: 610 */ 0xEE /* 'n' -> */, +/* pos 03fa: 611 */ 0xF3 /* 's' -> */, +/* pos 03fb: 612 */ 0xE9 /* 'i' -> */, +/* pos 03fc: 613 */ 0xEF /* 'o' -> */, +/* pos 03fd: 614 */ 0xEE /* 'n' -> */, +/* pos 03fe: 615 */ 0xF3 /* 's' -> */, +/* pos 03ff: 616 */ 0xBA /* ':' -> */, +/* pos 0400: 617 */ 0x00, 0x08 /* - terminal marker 8 - */, +/* pos 0402: 618 */ 0xE5 /* 'e' -> */, +/* pos 0403: 619 */ 0xF9 /* 'y' -> */, +/* pos 0404: 620 */ 0x31 /* '1' */, 0x0A, 0x00 /* (to 0x040E state 621) */, + 0x32 /* '2' */, 0x0A, 0x00 /* (to 0x0411 state 623) */, + 0x3A /* ':' */, 0x23, 0x00 /* (to 0x042D state 647) */, + 0x08, /* fail */ +/* pos 040e: 621 */ 0xBA /* ':' -> */, +/* pos 040f: 622 */ 0x00, 0x09 /* - terminal marker 9 - */, +/* pos 0411: 623 */ 0xBA /* ':' -> */, +/* pos 0412: 624 */ 0x00, 0x0A /* - terminal marker 10 - */, +/* pos 0414: 625 */ 0xF2 /* 'r' -> */, +/* pos 0415: 626 */ 0xEF /* 'o' -> */, +/* pos 0416: 627 */ 0xF4 /* 't' -> */, +/* pos 0417: 628 */ 0xEF /* 'o' -> */, +/* pos 0418: 629 */ 0xE3 /* 'c' -> */, +/* pos 0419: 630 */ 0xEF /* 'o' -> */, +/* pos 041a: 631 */ 0xEC /* 'l' -> */, +/* pos 041b: 632 */ 0xBA /* ':' -> */, +/* pos 041c: 633 */ 0x00, 0x0B /* - terminal marker 11 - */, +/* pos 041e: 634 */ 0xE3 /* 'c' -> */, +/* pos 041f: 635 */ 0xE3 /* 'c' -> */, +/* pos 0420: 636 */ 0xE5 /* 'e' -> */, +/* pos 0421: 637 */ 0xF0 /* 'p' -> */, +/* pos 0422: 638 */ 0xF4 /* 't' -> */, +/* pos 0423: 639 */ 0xBA /* ':' -> */, +/* pos 0424: 640 */ 0x00, 0x0C /* - terminal marker 12 - */, +/* pos 0426: 641 */ 0xEF /* 'o' -> */, +/* pos 0427: 642 */ 0xEE /* 'n' -> */, +/* pos 0428: 643 */ 0xE3 /* 'c' -> */, +/* pos 0429: 644 */ 0xE5 /* 'e' -> */, +/* pos 042a: 645 */ 0xBA /* ':' -> */, +/* pos 042b: 646 */ 0x00, 0x0D /* - terminal marker 13 - */, +/* pos 042d: 647 */ 0x00, 0x1C /* - terminal marker 28 - */, +/* pos 042f: 648 */ 0xE5 /* 'e' -> */, +/* pos 0430: 649 */ 0xF2 /* 'r' -> */, +/* pos 0431: 650 */ 0xF3 /* 's' -> */, +/* pos 0432: 651 */ 0xE9 /* 'i' -> */, +/* pos 0433: 652 */ 0xEF /* 'o' -> */, +/* pos 0434: 653 */ 0xEE /* 'n' -> */, +/* pos 0435: 654 */ 0xBA /* ':' -> */, +/* pos 0436: 655 */ 0x00, 0x1D /* - terminal marker 29 - */, +/* pos 0438: 656 */ 0xF2 /* 'r' -> */, +/* pos 0439: 657 */ 0xE9 /* 'i' -> */, +/* pos 043a: 658 */ 0xE7 /* 'g' -> */, +/* pos 043b: 659 */ 0xE9 /* 'i' -> */, +/* pos 043c: 660 */ 0xEE /* 'n' -> */, +/* pos 043d: 661 */ 0xBA /* ':' -> */, +/* pos 043e: 662 */ 0x00, 0x1E /* - terminal marker 30 - */, +/* total size 1088 bytes */ +#endif + +#if !defined(LWS_HTTP_HEADERS_ALL) && defined(LWS_WITH_HTTP_UNCOMMON_HEADERS) && defined(LWS_ROLE_WS) && !defined(LWS_ROLE_H2) + /* 0: 0: get */ + /* 1: 1: post */ + /* 2: 2: options */ + /* 3: 3: host: */ + /* 4: 4: connection: */ + /* 5: 5: upgrade: */ + /* 6: 6: origin: */ + /* 7: 7: sec-websocket-draft: */ + /* 8: 8: + */ + /* 9: 9: sec-websocket-extensions: */ + /* 10: 10: sec-websocket-key1: */ + /* 11: 11: sec-websocket-key2: */ + /* 12: 12: sec-websocket-protocol: */ + /* 13: 13: sec-websocket-accept: */ + /* 14: 14: sec-websocket-nonce: */ + /* 15: 15: http/1.1 */ + /* 16: 17: accept: */ + /* 17: 18: access-control-request-headers: */ + /* 18: 19: if-modified-since: */ + /* 19: 20: if-none-match: */ + /* 20: 21: accept-encoding: */ + /* 21: 22: accept-language: */ + /* 22: 23: pragma: */ + /* 23: 24: cache-control: */ + /* 24: 25: authorization: */ + /* 25: 26: cookie: */ + /* 26: 27: content-length: */ + /* 27: 28: content-type: */ + /* 28: 29: date: */ + /* 29: 30: range: */ + /* 30: 31: referer: */ + /* 31: 32: sec-websocket-key: */ + /* 32: 33: sec-websocket-version: */ + /* 33: 34: sec-websocket-origin: */ + /* 34: 40: accept-charset: */ + /* 35: 41: accept-ranges: */ + /* 36: 42: access-control-allow-origin: */ + /* 37: 43: age: */ + /* 38: 44: allow: */ + /* 39: 45: content-disposition: */ + /* 40: 46: content-encoding: */ + /* 41: 47: content-language: */ + /* 42: 48: content-location: */ + /* 43: 49: content-range: */ + /* 44: 50: etag: */ + /* 45: 51: expect: */ + /* 46: 52: expires: */ + /* 47: 53: from: */ + /* 48: 54: if-match: */ + /* 49: 55: if-range: */ + /* 50: 56: if-unmodified-since: */ + /* 51: 57: last-modified: */ + /* 52: 58: link: */ + /* 53: 59: location: */ + /* 54: 60: max-forwards: */ + /* 55: 61: proxy-authenticate: */ + /* 56: 62: proxy-authorization: */ + /* 57: 63: refresh: */ + /* 58: 64: retry-after: */ + /* 59: 65: server: */ + /* 60: 66: set-cookie: */ + /* 61: 67: strict-transport-security: */ + /* 62: 68: transfer-encoding: */ + /* 63: 69: user-agent: */ + /* 64: 70: vary: */ + /* 65: 71: via: */ + /* 66: 72: www-authenticate: */ + /* 67: 73: patch */ + /* 68: 74: put */ + /* 69: 75: delete */ + /* 70: 76: uri-args */ + /* 71: 77: proxy */ + /* 72: 78: x-real-ip: */ + /* 73: 79: http/1.0 */ + /* 74: 80: x-forwarded-for: */ + /* 75: 81: connect */ + /* 76: 82: head */ + /* 77: 83: te: */ + /* 78: 84: replay-nonce: */ + /* 79: 86: x-auth-token: */ + /* 80: 87: */ +/* pos 0000: 0 */ 0x67 /* 'g' */, 0x3D, 0x00 /* (to 0x003D state 1) */, + 0x70 /* 'p' */, 0x3F, 0x00 /* (to 0x0042 state 5) */, + 0x68 /* 'h' */, 0x4E, 0x00 /* (to 0x0054 state 10) */, + 0x63 /* 'c' */, 0x5A, 0x00 /* (to 0x0063 state 15) */, + 0x75 /* 'u' */, 0x7B, 0x00 /* (to 0x0087 state 26) */, + 0x6F /* 'o' */, 0x8A, 0x00 /* (to 0x0099 state 34) */, + 0x0D /* '.' */, 0x95, 0x00 /* (to 0x00A7 state 41) */, + 0x61 /* 'a' */, 0xA4, 0x00 /* (to 0x00B9 state 51) */, + 0x69 /* 'i' */, 0xC1, 0x00 /* (to 0x00D9 state 58) */, + 0x64 /* 'd' */, 0x6A, 0x01 /* (to 0x0185 state 160) */, + 0x72 /* 'r' */, 0x73, 0x01 /* (to 0x0191 state 165) */, + 0x65 /* 'e' */, 0xBF, 0x01 /* (to 0x01E0 state 229) */, + 0x66 /* 'f' */, 0xDB, 0x01 /* (to 0x01FF state 245) */, + 0x6C /* 'l' */, 0xFD, 0x01 /* (to 0x0224 state 278) */, + 0x73 /* 's' */, 0x42, 0x02 /* (to 0x026C state 321) */, + 0x74 /* 't' */, 0x60, 0x02 /* (to 0x028D state 337) */, + 0x78 /* 'x' */, 0x81, 0x02 /* (to 0x02B1 state 364) */, + 0x6D /* 'm' */, 0xF2, 0x02 /* (to 0x0325 state 456) */, + 0x76 /* 'v' */, 0x4B, 0x03 /* (to 0x0381 state 531) */, + 0x77 /* 'w' */, 0x58, 0x03 /* (to 0x0391 state 539) */, + 0x08, /* fail */ +/* pos 003d: 1 */ 0xE5 /* 'e' -> */, +/* pos 003e: 2 */ 0xF4 /* 't' -> */, +/* pos 003f: 3 */ 0xA0 /* ' ' -> */, +/* pos 0040: 4 */ 0x00, 0x00 /* - terminal marker 0 - */, +/* pos 0042: 5 */ 0x6F /* 'o' */, 0x0D, 0x00 /* (to 0x004F state 6) */, + 0x72 /* 'r' */, 0xE6, 0x00 /* (to 0x012B state 106) */, + 0x61 /* 'a' */, 0x5B, 0x03 /* (to 0x03A3 state 556) */, + 0x75 /* 'u' */, 0x5D, 0x03 /* (to 0x03A8 state 560) */, + 0x08, /* fail */ +/* pos 004f: 6 */ 0xF3 /* 's' -> */, +/* pos 0050: 7 */ 0xF4 /* 't' -> */, +/* pos 0051: 8 */ 0xA0 /* ' ' -> */, +/* pos 0052: 9 */ 0x00, 0x01 /* - terminal marker 1 - */, +/* pos 0054: 10 */ 0x6F /* 'o' */, 0x0A, 0x00 /* (to 0x005E state 11) */, + 0x74 /* 't' */, 0x53, 0x00 /* (to 0x00AA state 43) */, + 0x65 /* 'e' */, 0x73, 0x02 /* (to 0x02CD state 381) */, + 0x08, /* fail */ +/* pos 005e: 11 */ 0xF3 /* 's' -> */, +/* pos 005f: 12 */ 0xF4 /* 't' -> */, +/* pos 0060: 13 */ 0xBA /* ':' -> */, +/* pos 0061: 14 */ 0x00, 0x03 /* - terminal marker 3 - */, +/* pos 0063: 15 */ 0x6F /* 'o' */, 0x07, 0x00 /* (to 0x006A state 16) */, + 0x61 /* 'a' */, 0xD2, 0x00 /* (to 0x0138 state 112) */, + 0x08, /* fail */ +/* pos 006a: 16 */ 0x6E /* 'n' */, 0x07, 0x00 /* (to 0x0071 state 17) */, + 0x6F /* 'o' */, 0xE7, 0x00 /* (to 0x0154 state 138) */, + 0x08, /* fail */ +/* pos 0071: 17 */ 0x6E /* 'n' */, 0x07, 0x00 /* (to 0x0078 state 18) */, + 0x74 /* 't' */, 0xE6, 0x00 /* (to 0x015A state 143) */, + 0x08, /* fail */ +/* pos 0078: 18 */ 0xE5 /* 'e' -> */, +/* pos 0079: 19 */ 0xE3 /* 'c' -> */, +/* pos 007a: 20 */ 0xF4 /* 't' -> */, +/* pos 007b: 21 */ 0x69 /* 'i' */, 0x07, 0x00 /* (to 0x0082 state 22) */, + 0x20 /* ' ' */, 0x4D, 0x02 /* (to 0x02CB state 380) */, + 0x08, /* fail */ +/* pos 0082: 22 */ 0xEF /* 'o' -> */, +/* pos 0083: 23 */ 0xEE /* 'n' -> */, +/* pos 0084: 24 */ 0xBA /* ':' -> */, +/* pos 0085: 25 */ 0x00, 0x04 /* - terminal marker 4 - */, +/* pos 0087: 26 */ 0x70 /* 'p' */, 0x0A, 0x00 /* (to 0x0091 state 27) */, + 0x72 /* 'r' */, 0x1C, 0x02 /* (to 0x02A6 state 355) */, + 0x73 /* 's' */, 0xE9, 0x02 /* (to 0x0376 state 521) */, + 0x08, /* fail */ +/* pos 0091: 27 */ 0xE7 /* 'g' -> */, +/* pos 0092: 28 */ 0xF2 /* 'r' -> */, +/* pos 0093: 29 */ 0xE1 /* 'a' -> */, +/* pos 0094: 30 */ 0xE4 /* 'd' -> */, +/* pos 0095: 31 */ 0xE5 /* 'e' -> */, +/* pos 0096: 32 */ 0xBA /* ':' -> */, +/* pos 0097: 33 */ 0x00, 0x05 /* - terminal marker 5 - */, +/* pos 0099: 34 */ 0x72 /* 'r' */, 0x07, 0x00 /* (to 0x00A0 state 35) */, + 0x70 /* 'p' */, 0x42, 0x02 /* (to 0x02DE state 396) */, + 0x08, /* fail */ +/* pos 00a0: 35 */ 0xE9 /* 'i' -> */, +/* pos 00a1: 36 */ 0xE7 /* 'g' -> */, +/* pos 00a2: 37 */ 0xE9 /* 'i' -> */, +/* pos 00a3: 38 */ 0xEE /* 'n' -> */, +/* pos 00a4: 39 */ 0xBA /* ':' -> */, +/* pos 00a5: 40 */ 0x00, 0x06 /* - terminal marker 6 - */, +/* pos 00a7: 41 */ 0x8A /* '.' -> */, +/* pos 00a8: 42 */ 0x00, 0x08 /* - terminal marker 8 - */, +/* pos 00aa: 43 */ 0xF4 /* 't' -> */, +/* pos 00ab: 44 */ 0xF0 /* 'p' -> */, +/* pos 00ac: 45 */ 0xAF /* '/' -> */, +/* pos 00ad: 46 */ 0xB1 /* '1' -> */, +/* pos 00ae: 47 */ 0xAE /* '.' -> */, +/* pos 00af: 48 */ 0x31 /* '1' */, 0x07, 0x00 /* (to 0x00B6 state 49) */, + 0x30 /* '0' */, 0xFC, 0x01 /* (to 0x02AE state 362) */, + 0x08, /* fail */ +/* pos 00b6: 49 */ 0xA0 /* ' ' -> */, +/* pos 00b7: 50 */ 0x00, 0x0F /* - terminal marker 15 - */, +/* pos 00b9: 51 */ 0x63 /* 'c' */, 0x0D, 0x00 /* (to 0x00C6 state 52) */, + 0x75 /* 'u' */, 0x8A, 0x00 /* (to 0x0146 state 125) */, + 0x67 /* 'g' */, 0xE7, 0x00 /* (to 0x01A6 state 178) */, + 0x6C /* 'l' */, 0xE8, 0x00 /* (to 0x01AA state 181) */, + 0x08, /* fail */ +/* pos 00c6: 52 */ 0xE3 /* 'c' -> */, +/* pos 00c7: 53 */ 0xE5 /* 'e' -> */, +/* pos 00c8: 54 */ 0x70 /* 'p' */, 0x07, 0x00 /* (to 0x00CF state 55) */, + 0x73 /* 's' */, 0x1B, 0x02 /* (to 0x02E6 state 403) */, + 0x08, /* fail */ +/* pos 00cf: 55 */ 0xF4 /* 't' -> */, +/* pos 00d0: 56 */ 0x3A /* ':' */, 0x07, 0x00 /* (to 0x00D7 state 57) */, + 0x2D /* '-' */, 0x37, 0x00 /* (to 0x010A state 87) */, + 0x08, /* fail */ +/* pos 00d7: 57 */ 0x00, 0x10 /* - terminal marker 16 - */, +/* pos 00d9: 58 */ 0xE6 /* 'f' -> */, +/* pos 00da: 59 */ 0xAD /* '-' -> */, +/* pos 00db: 60 */ 0x6D /* 'm' */, 0x0D, 0x00 /* (to 0x00E8 state 61) */, + 0x6E /* 'n' */, 0x20, 0x00 /* (to 0x00FE state 76) */, + 0x72 /* 'r' */, 0x2A, 0x01 /* (to 0x020B state 255) */, + 0x75 /* 'u' */, 0x2E, 0x01 /* (to 0x0212 state 261) */, + 0x08, /* fail */ +/* pos 00e8: 61 */ 0x6F /* 'o' */, 0x07, 0x00 /* (to 0x00EF state 62) */, + 0x61 /* 'a' */, 0x1A, 0x01 /* (to 0x0205 state 250) */, + 0x08, /* fail */ +/* pos 00ef: 62 */ 0xE4 /* 'd' -> */, +/* pos 00f0: 63 */ 0xE9 /* 'i' -> */, +/* pos 00f1: 64 */ 0xE6 /* 'f' -> */, +/* pos 00f2: 65 */ 0xE9 /* 'i' -> */, +/* pos 00f3: 66 */ 0xE5 /* 'e' -> */, +/* pos 00f4: 67 */ 0xE4 /* 'd' -> */, +/* pos 00f5: 68 */ 0xAD /* '-' -> */, +/* pos 00f6: 69 */ 0xF3 /* 's' -> */, +/* pos 00f7: 70 */ 0xE9 /* 'i' -> */, +/* pos 00f8: 71 */ 0xEE /* 'n' -> */, +/* pos 00f9: 72 */ 0xE3 /* 'c' -> */, +/* pos 00fa: 73 */ 0xE5 /* 'e' -> */, +/* pos 00fb: 74 */ 0xBA /* ':' -> */, +/* pos 00fc: 75 */ 0x00, 0x12 /* - terminal marker 18 - */, +/* pos 00fe: 76 */ 0xEF /* 'o' -> */, +/* pos 00ff: 77 */ 0xEE /* 'n' -> */, +/* pos 0100: 78 */ 0xE5 /* 'e' -> */, +/* pos 0101: 79 */ 0xAD /* '-' -> */, +/* pos 0102: 80 */ 0xED /* 'm' -> */, +/* pos 0103: 81 */ 0xE1 /* 'a' -> */, +/* pos 0104: 82 */ 0xF4 /* 't' -> */, +/* pos 0105: 83 */ 0xE3 /* 'c' -> */, +/* pos 0106: 84 */ 0xE8 /* 'h' -> */, +/* pos 0107: 85 */ 0xBA /* ':' -> */, +/* pos 0108: 86 */ 0x00, 0x13 /* - terminal marker 19 - */, +/* pos 010a: 87 */ 0x65 /* 'e' */, 0x0D, 0x00 /* (to 0x0117 state 88) */, + 0x6C /* 'l' */, 0x14, 0x00 /* (to 0x0121 state 97) */, + 0x72 /* 'r' */, 0x8E, 0x00 /* (to 0x019E state 171) */, + 0x63 /* 'c' */, 0xFB, 0x01 /* (to 0x030E state 435) */, + 0x08, /* fail */ +/* pos 0117: 88 */ 0xEE /* 'n' -> */, +/* pos 0118: 89 */ 0xE3 /* 'c' -> */, +/* pos 0119: 90 */ 0xEF /* 'o' -> */, +/* pos 011a: 91 */ 0xE4 /* 'd' -> */, +/* pos 011b: 92 */ 0xE9 /* 'i' -> */, +/* pos 011c: 93 */ 0xEE /* 'n' -> */, +/* pos 011d: 94 */ 0xE7 /* 'g' -> */, +/* pos 011e: 95 */ 0xBA /* ':' -> */, +/* pos 011f: 96 */ 0x00, 0x14 /* - terminal marker 20 - */, +/* pos 0121: 97 */ 0xE1 /* 'a' -> */, +/* pos 0122: 98 */ 0xEE /* 'n' -> */, +/* pos 0123: 99 */ 0xE7 /* 'g' -> */, +/* pos 0124: 100 */ 0xF5 /* 'u' -> */, +/* pos 0125: 101 */ 0xE1 /* 'a' -> */, +/* pos 0126: 102 */ 0xE7 /* 'g' -> */, +/* pos 0127: 103 */ 0xE5 /* 'e' -> */, +/* pos 0128: 104 */ 0xBA /* ':' -> */, +/* pos 0129: 105 */ 0x00, 0x15 /* - terminal marker 21 - */, +/* pos 012b: 106 */ 0x61 /* 'a' */, 0x07, 0x00 /* (to 0x0132 state 107) */, + 0x6F /* 'o' */, 0x05, 0x02 /* (to 0x0333 state 469) */, + 0x08, /* fail */ +/* pos 0132: 107 */ 0xE7 /* 'g' -> */, +/* pos 0133: 108 */ 0xED /* 'm' -> */, +/* pos 0134: 109 */ 0xE1 /* 'a' -> */, +/* pos 0135: 110 */ 0xBA /* ':' -> */, +/* pos 0136: 111 */ 0x00, 0x16 /* - terminal marker 22 - */, +/* pos 0138: 112 */ 0xE3 /* 'c' -> */, +/* pos 0139: 113 */ 0xE8 /* 'h' -> */, +/* pos 013a: 114 */ 0xE5 /* 'e' -> */, +/* pos 013b: 115 */ 0xAD /* '-' -> */, +/* pos 013c: 116 */ 0xE3 /* 'c' -> */, +/* pos 013d: 117 */ 0xEF /* 'o' -> */, +/* pos 013e: 118 */ 0xEE /* 'n' -> */, +/* pos 013f: 119 */ 0xF4 /* 't' -> */, +/* pos 0140: 120 */ 0xF2 /* 'r' -> */, +/* pos 0141: 121 */ 0xEF /* 'o' -> */, +/* pos 0142: 122 */ 0xEC /* 'l' -> */, +/* pos 0143: 123 */ 0xBA /* ':' -> */, +/* pos 0144: 124 */ 0x00, 0x17 /* - terminal marker 23 - */, +/* pos 0146: 125 */ 0xF4 /* 't' -> */, +/* pos 0147: 126 */ 0xE8 /* 'h' -> */, +/* pos 0148: 127 */ 0xEF /* 'o' -> */, +/* pos 0149: 128 */ 0xF2 /* 'r' -> */, +/* pos 014a: 129 */ 0xE9 /* 'i' -> */, +/* pos 014b: 130 */ 0xFA /* 'z' -> */, +/* pos 014c: 131 */ 0xE1 /* 'a' -> */, +/* pos 014d: 132 */ 0xF4 /* 't' -> */, +/* pos 014e: 133 */ 0xE9 /* 'i' -> */, +/* pos 014f: 134 */ 0xEF /* 'o' -> */, +/* pos 0150: 135 */ 0xEE /* 'n' -> */, +/* pos 0151: 136 */ 0xBA /* ':' -> */, +/* pos 0152: 137 */ 0x00, 0x18 /* - terminal marker 24 - */, +/* pos 0154: 138 */ 0xEB /* 'k' -> */, +/* pos 0155: 139 */ 0xE9 /* 'i' -> */, +/* pos 0156: 140 */ 0xE5 /* 'e' -> */, +/* pos 0157: 141 */ 0xBA /* ':' -> */, +/* pos 0158: 142 */ 0x00, 0x19 /* - terminal marker 25 - */, +/* pos 015a: 143 */ 0xE5 /* 'e' -> */, +/* pos 015b: 144 */ 0xEE /* 'n' -> */, +/* pos 015c: 145 */ 0xF4 /* 't' -> */, +/* pos 015d: 146 */ 0xAD /* '-' -> */, +/* pos 015e: 147 */ 0x6C /* 'l' */, 0x10, 0x00 /* (to 0x016E state 148) */, + 0x74 /* 't' */, 0x1E, 0x00 /* (to 0x017F state 155) */, + 0x64 /* 'd' */, 0x4C, 0x00 /* (to 0x01B0 state 186) */, + 0x65 /* 'e' */, 0x56, 0x00 /* (to 0x01BD state 198) */, + 0x72 /* 'r' */, 0x6F, 0x00 /* (to 0x01D9 state 223) */, + 0x08, /* fail */ +/* pos 016e: 148 */ 0x65 /* 'e' */, 0x0A, 0x00 /* (to 0x0178 state 149) */, + 0x61 /* 'a' */, 0x56, 0x00 /* (to 0x01C7 state 207) */, + 0x6F /* 'o' */, 0x5C, 0x00 /* (to 0x01D0 state 215) */, + 0x08, /* fail */ +/* pos 0178: 149 */ 0xEE /* 'n' -> */, +/* pos 0179: 150 */ 0xE7 /* 'g' -> */, +/* pos 017a: 151 */ 0xF4 /* 't' -> */, +/* pos 017b: 152 */ 0xE8 /* 'h' -> */, +/* pos 017c: 153 */ 0xBA /* ':' -> */, +/* pos 017d: 154 */ 0x00, 0x1A /* - terminal marker 26 - */, +/* pos 017f: 155 */ 0xF9 /* 'y' -> */, +/* pos 0180: 156 */ 0xF0 /* 'p' -> */, +/* pos 0181: 157 */ 0xE5 /* 'e' -> */, +/* pos 0182: 158 */ 0xBA /* ':' -> */, +/* pos 0183: 159 */ 0x00, 0x1B /* - terminal marker 27 - */, +/* pos 0185: 160 */ 0x61 /* 'a' */, 0x07, 0x00 /* (to 0x018C state 161) */, + 0x65 /* 'e' */, 0x23, 0x02 /* (to 0x03AB state 562) */, + 0x08, /* fail */ +/* pos 018c: 161 */ 0xF4 /* 't' -> */, +/* pos 018d: 162 */ 0xE5 /* 'e' -> */, +/* pos 018e: 163 */ 0xBA /* ':' -> */, +/* pos 018f: 164 */ 0x00, 0x1C /* - terminal marker 28 - */, +/* pos 0191: 165 */ 0x61 /* 'a' */, 0x07, 0x00 /* (to 0x0198 state 166) */, + 0x65 /* 'e' */, 0xB6, 0x00 /* (to 0x024A state 304) */, + 0x08, /* fail */ +/* pos 0198: 166 */ 0xEE /* 'n' -> */, +/* pos 0199: 167 */ 0xE7 /* 'g' -> */, +/* pos 019a: 168 */ 0xE5 /* 'e' -> */, +/* pos 019b: 169 */ 0xBA /* ':' -> */, +/* pos 019c: 170 */ 0x00, 0x1D /* - terminal marker 29 - */, +/* pos 019e: 171 */ 0xE1 /* 'a' -> */, +/* pos 019f: 172 */ 0xEE /* 'n' -> */, +/* pos 01a0: 173 */ 0xE7 /* 'g' -> */, +/* pos 01a1: 174 */ 0xE5 /* 'e' -> */, +/* pos 01a2: 175 */ 0xF3 /* 's' -> */, +/* pos 01a3: 176 */ 0xBA /* ':' -> */, +/* pos 01a4: 177 */ 0x00, 0x23 /* - terminal marker 35 - */, +/* pos 01a6: 178 */ 0xE5 /* 'e' -> */, +/* pos 01a7: 179 */ 0xBA /* ':' -> */, +/* pos 01a8: 180 */ 0x00, 0x25 /* - terminal marker 37 - */, +/* pos 01aa: 181 */ 0xEC /* 'l' -> */, +/* pos 01ab: 182 */ 0xEF /* 'o' -> */, +/* pos 01ac: 183 */ 0xF7 /* 'w' -> */, +/* pos 01ad: 184 */ 0xBA /* ':' -> */, +/* pos 01ae: 185 */ 0x00, 0x26 /* - terminal marker 38 - */, +/* pos 01b0: 186 */ 0xE9 /* 'i' -> */, +/* pos 01b1: 187 */ 0xF3 /* 's' -> */, +/* pos 01b2: 188 */ 0xF0 /* 'p' -> */, +/* pos 01b3: 189 */ 0xEF /* 'o' -> */, +/* pos 01b4: 190 */ 0xF3 /* 's' -> */, +/* pos 01b5: 191 */ 0xE9 /* 'i' -> */, +/* pos 01b6: 192 */ 0xF4 /* 't' -> */, +/* pos 01b7: 193 */ 0xE9 /* 'i' -> */, +/* pos 01b8: 194 */ 0xEF /* 'o' -> */, +/* pos 01b9: 195 */ 0xEE /* 'n' -> */, +/* pos 01ba: 196 */ 0xBA /* ':' -> */, +/* pos 01bb: 197 */ 0x00, 0x27 /* - terminal marker 39 - */, +/* pos 01bd: 198 */ 0xEE /* 'n' -> */, +/* pos 01be: 199 */ 0xE3 /* 'c' -> */, +/* pos 01bf: 200 */ 0xEF /* 'o' -> */, +/* pos 01c0: 201 */ 0xE4 /* 'd' -> */, +/* pos 01c1: 202 */ 0xE9 /* 'i' -> */, +/* pos 01c2: 203 */ 0xEE /* 'n' -> */, +/* pos 01c3: 204 */ 0xE7 /* 'g' -> */, +/* pos 01c4: 205 */ 0xBA /* ':' -> */, +/* pos 01c5: 206 */ 0x00, 0x28 /* - terminal marker 40 - */, +/* pos 01c7: 207 */ 0xEE /* 'n' -> */, +/* pos 01c8: 208 */ 0xE7 /* 'g' -> */, +/* pos 01c9: 209 */ 0xF5 /* 'u' -> */, +/* pos 01ca: 210 */ 0xE1 /* 'a' -> */, +/* pos 01cb: 211 */ 0xE7 /* 'g' -> */, +/* pos 01cc: 212 */ 0xE5 /* 'e' -> */, +/* pos 01cd: 213 */ 0xBA /* ':' -> */, +/* pos 01ce: 214 */ 0x00, 0x29 /* - terminal marker 41 - */, +/* pos 01d0: 215 */ 0xE3 /* 'c' -> */, +/* pos 01d1: 216 */ 0xE1 /* 'a' -> */, +/* pos 01d2: 217 */ 0xF4 /* 't' -> */, +/* pos 01d3: 218 */ 0xE9 /* 'i' -> */, +/* pos 01d4: 219 */ 0xEF /* 'o' -> */, +/* pos 01d5: 220 */ 0xEE /* 'n' -> */, +/* pos 01d6: 221 */ 0xBA /* ':' -> */, +/* pos 01d7: 222 */ 0x00, 0x2A /* - terminal marker 42 - */, +/* pos 01d9: 223 */ 0xE1 /* 'a' -> */, +/* pos 01da: 224 */ 0xEE /* 'n' -> */, +/* pos 01db: 225 */ 0xE7 /* 'g' -> */, +/* pos 01dc: 226 */ 0xE5 /* 'e' -> */, +/* pos 01dd: 227 */ 0xBA /* ':' -> */, +/* pos 01de: 228 */ 0x00, 0x2B /* - terminal marker 43 - */, +/* pos 01e0: 229 */ 0x74 /* 't' */, 0x07, 0x00 /* (to 0x01E7 state 230) */, + 0x78 /* 'x' */, 0x09, 0x00 /* (to 0x01EC state 234) */, + 0x08, /* fail */ +/* pos 01e7: 230 */ 0xE1 /* 'a' -> */, +/* pos 01e8: 231 */ 0xE7 /* 'g' -> */, +/* pos 01e9: 232 */ 0xBA /* ':' -> */, +/* pos 01ea: 233 */ 0x00, 0x2C /* - terminal marker 44 - */, +/* pos 01ec: 234 */ 0xF0 /* 'p' -> */, +/* pos 01ed: 235 */ 0x65 /* 'e' */, 0x07, 0x00 /* (to 0x01F4 state 236) */, + 0x69 /* 'i' */, 0x09, 0x00 /* (to 0x01F9 state 240) */, + 0x08, /* fail */ +/* pos 01f4: 236 */ 0xE3 /* 'c' -> */, +/* pos 01f5: 237 */ 0xF4 /* 't' -> */, +/* pos 01f6: 238 */ 0xBA /* ':' -> */, +/* pos 01f7: 239 */ 0x00, 0x2D /* - terminal marker 45 - */, +/* pos 01f9: 240 */ 0xF2 /* 'r' -> */, +/* pos 01fa: 241 */ 0xE5 /* 'e' -> */, +/* pos 01fb: 242 */ 0xF3 /* 's' -> */, +/* pos 01fc: 243 */ 0xBA /* ':' -> */, +/* pos 01fd: 244 */ 0x00, 0x2E /* - terminal marker 46 - */, +/* pos 01ff: 245 */ 0xF2 /* 'r' -> */, +/* pos 0200: 246 */ 0xEF /* 'o' -> */, +/* pos 0201: 247 */ 0xED /* 'm' -> */, +/* pos 0202: 248 */ 0xBA /* ':' -> */, +/* pos 0203: 249 */ 0x00, 0x2F /* - terminal marker 47 - */, +/* pos 0205: 250 */ 0xF4 /* 't' -> */, +/* pos 0206: 251 */ 0xE3 /* 'c' -> */, +/* pos 0207: 252 */ 0xE8 /* 'h' -> */, +/* pos 0208: 253 */ 0xBA /* ':' -> */, +/* pos 0209: 254 */ 0x00, 0x30 /* - terminal marker 48 - */, +/* pos 020b: 255 */ 0xE1 /* 'a' -> */, +/* pos 020c: 256 */ 0xEE /* 'n' -> */, +/* pos 020d: 257 */ 0xE7 /* 'g' -> */, +/* pos 020e: 258 */ 0xE5 /* 'e' -> */, +/* pos 020f: 259 */ 0xBA /* ':' -> */, +/* pos 0210: 260 */ 0x00, 0x31 /* - terminal marker 49 - */, +/* pos 0212: 261 */ 0xEE /* 'n' -> */, +/* pos 0213: 262 */ 0xED /* 'm' -> */, +/* pos 0214: 263 */ 0xEF /* 'o' -> */, +/* pos 0215: 264 */ 0xE4 /* 'd' -> */, +/* pos 0216: 265 */ 0xE9 /* 'i' -> */, +/* pos 0217: 266 */ 0xE6 /* 'f' -> */, +/* pos 0218: 267 */ 0xE9 /* 'i' -> */, +/* pos 0219: 268 */ 0xE5 /* 'e' -> */, +/* pos 021a: 269 */ 0xE4 /* 'd' -> */, +/* pos 021b: 270 */ 0xAD /* '-' -> */, +/* pos 021c: 271 */ 0xF3 /* 's' -> */, +/* pos 021d: 272 */ 0xE9 /* 'i' -> */, +/* pos 021e: 273 */ 0xEE /* 'n' -> */, +/* pos 021f: 274 */ 0xE3 /* 'c' -> */, +/* pos 0220: 275 */ 0xE5 /* 'e' -> */, +/* pos 0221: 276 */ 0xBA /* ':' -> */, +/* pos 0222: 277 */ 0x00, 0x32 /* - terminal marker 50 - */, +/* pos 0224: 278 */ 0x61 /* 'a' */, 0x0A, 0x00 /* (to 0x022E state 279) */, + 0x69 /* 'i' */, 0x15, 0x00 /* (to 0x023C state 292) */, + 0x6F /* 'o' */, 0x17, 0x00 /* (to 0x0241 state 296) */, + 0x08, /* fail */ +/* pos 022e: 279 */ 0xF3 /* 's' -> */, +/* pos 022f: 280 */ 0xF4 /* 't' -> */, +/* pos 0230: 281 */ 0xAD /* '-' -> */, +/* pos 0231: 282 */ 0xED /* 'm' -> */, +/* pos 0232: 283 */ 0xEF /* 'o' -> */, +/* pos 0233: 284 */ 0xE4 /* 'd' -> */, +/* pos 0234: 285 */ 0xE9 /* 'i' -> */, +/* pos 0235: 286 */ 0xE6 /* 'f' -> */, +/* pos 0236: 287 */ 0xE9 /* 'i' -> */, +/* pos 0237: 288 */ 0xE5 /* 'e' -> */, +/* pos 0238: 289 */ 0xE4 /* 'd' -> */, +/* pos 0239: 290 */ 0xBA /* ':' -> */, +/* pos 023a: 291 */ 0x00, 0x33 /* - terminal marker 51 - */, +/* pos 023c: 292 */ 0xEE /* 'n' -> */, +/* pos 023d: 293 */ 0xEB /* 'k' -> */, +/* pos 023e: 294 */ 0xBA /* ':' -> */, +/* pos 023f: 295 */ 0x00, 0x34 /* - terminal marker 52 - */, +/* pos 0241: 296 */ 0xE3 /* 'c' -> */, +/* pos 0242: 297 */ 0xE1 /* 'a' -> */, +/* pos 0243: 298 */ 0xF4 /* 't' -> */, +/* pos 0244: 299 */ 0xE9 /* 'i' -> */, +/* pos 0245: 300 */ 0xEF /* 'o' -> */, +/* pos 0246: 301 */ 0xEE /* 'n' -> */, +/* pos 0247: 302 */ 0xBA /* ':' -> */, +/* pos 0248: 303 */ 0x00, 0x35 /* - terminal marker 53 - */, +/* pos 024a: 304 */ 0x66 /* 'f' */, 0x0A, 0x00 /* (to 0x0254 state 305) */, + 0x74 /* 't' */, 0x14, 0x00 /* (to 0x0261 state 311) */, + 0x70 /* 'p' */, 0x6F, 0x01 /* (to 0x03BF state 578) */, + 0x08, /* fail */ +/* pos 0254: 305 */ 0x72 /* 'r' */, 0x07, 0x00 /* (to 0x025B state 306) */, + 0x65 /* 'e' */, 0xB1, 0x00 /* (to 0x0308 state 430) */, + 0x08, /* fail */ +/* pos 025b: 306 */ 0xE5 /* 'e' -> */, +/* pos 025c: 307 */ 0xF3 /* 's' -> */, +/* pos 025d: 308 */ 0xE8 /* 'h' -> */, +/* pos 025e: 309 */ 0xBA /* ':' -> */, +/* pos 025f: 310 */ 0x00, 0x39 /* - terminal marker 57 - */, +/* pos 0261: 311 */ 0xF2 /* 'r' -> */, +/* pos 0262: 312 */ 0xF9 /* 'y' -> */, +/* pos 0263: 313 */ 0xAD /* '-' -> */, +/* pos 0264: 314 */ 0xE1 /* 'a' -> */, +/* pos 0265: 315 */ 0xE6 /* 'f' -> */, +/* pos 0266: 316 */ 0xF4 /* 't' -> */, +/* pos 0267: 317 */ 0xE5 /* 'e' -> */, +/* pos 0268: 318 */ 0xF2 /* 'r' -> */, +/* pos 0269: 319 */ 0xBA /* ':' -> */, +/* pos 026a: 320 */ 0x00, 0x3A /* - terminal marker 58 - */, +/* pos 026c: 321 */ 0x65 /* 'e' */, 0x07, 0x00 /* (to 0x0273 state 322) */, + 0x74 /* 't' */, 0xED, 0x00 /* (to 0x035C state 496) */, + 0x08, /* fail */ +/* pos 0273: 322 */ 0x72 /* 'r' */, 0x0A, 0x00 /* (to 0x027D state 323) */, + 0x74 /* 't' */, 0x0D, 0x00 /* (to 0x0283 state 328) */, + 0x63 /* 'c' */, 0x52, 0x01 /* (to 0x03CB state 589) */, + 0x08, /* fail */ +/* pos 027d: 323 */ 0xF6 /* 'v' -> */, +/* pos 027e: 324 */ 0xE5 /* 'e' -> */, +/* pos 027f: 325 */ 0xF2 /* 'r' -> */, +/* pos 0280: 326 */ 0xBA /* ':' -> */, +/* pos 0281: 327 */ 0x00, 0x3B /* - terminal marker 59 - */, +/* pos 0283: 328 */ 0xAD /* '-' -> */, +/* pos 0284: 329 */ 0xE3 /* 'c' -> */, +/* pos 0285: 330 */ 0xEF /* 'o' -> */, +/* pos 0286: 331 */ 0xEF /* 'o' -> */, +/* pos 0287: 332 */ 0xEB /* 'k' -> */, +/* pos 0288: 333 */ 0xE9 /* 'i' -> */, +/* pos 0289: 334 */ 0xE5 /* 'e' -> */, +/* pos 028a: 335 */ 0xBA /* ':' -> */, +/* pos 028b: 336 */ 0x00, 0x3C /* - terminal marker 60 - */, +/* pos 028d: 337 */ 0x72 /* 'r' */, 0x07, 0x00 /* (to 0x0294 state 338) */, + 0x65 /* 'e' */, 0x2C, 0x01 /* (to 0x03BC state 576) */, + 0x08, /* fail */ +/* pos 0294: 338 */ 0xE1 /* 'a' -> */, +/* pos 0295: 339 */ 0xEE /* 'n' -> */, +/* pos 0296: 340 */ 0xF3 /* 's' -> */, +/* pos 0297: 341 */ 0xE6 /* 'f' -> */, +/* pos 0298: 342 */ 0xE5 /* 'e' -> */, +/* pos 0299: 343 */ 0xF2 /* 'r' -> */, +/* pos 029a: 344 */ 0xAD /* '-' -> */, +/* pos 029b: 345 */ 0xE5 /* 'e' -> */, +/* pos 029c: 346 */ 0xEE /* 'n' -> */, +/* pos 029d: 347 */ 0xE3 /* 'c' -> */, +/* pos 029e: 348 */ 0xEF /* 'o' -> */, +/* pos 029f: 349 */ 0xE4 /* 'd' -> */, +/* pos 02a0: 350 */ 0xE9 /* 'i' -> */, +/* pos 02a1: 351 */ 0xEE /* 'n' -> */, +/* pos 02a2: 352 */ 0xE7 /* 'g' -> */, +/* pos 02a3: 353 */ 0xBA /* ':' -> */, +/* pos 02a4: 354 */ 0x00, 0x3E /* - terminal marker 62 - */, +/* pos 02a6: 355 */ 0xE9 /* 'i' -> */, +/* pos 02a7: 356 */ 0xAD /* '-' -> */, +/* pos 02a8: 357 */ 0xE1 /* 'a' -> */, +/* pos 02a9: 358 */ 0xF2 /* 'r' -> */, +/* pos 02aa: 359 */ 0xE7 /* 'g' -> */, +/* pos 02ab: 360 */ 0xF3 /* 's' -> */, +/* pos 02ac: 361 */ 0x00, 0x46 /* - terminal marker 70 - */, +/* pos 02ae: 362 */ 0xA0 /* ' ' -> */, +/* pos 02af: 363 */ 0x00, 0x49 /* - terminal marker 73 - */, +/* pos 02b1: 364 */ 0xAD /* '-' -> */, +/* pos 02b2: 365 */ 0x66 /* 'f' */, 0x0A, 0x00 /* (to 0x02BC state 366) */, + 0x61 /* 'a' */, 0x1D, 0x00 /* (to 0x02D2 state 385) */, + 0x72 /* 'r' */, 0xFB, 0x00 /* (to 0x03B3 state 568) */, + 0x08, /* fail */ +/* pos 02bc: 366 */ 0xEF /* 'o' -> */, +/* pos 02bd: 367 */ 0xF2 /* 'r' -> */, +/* pos 02be: 368 */ 0xF7 /* 'w' -> */, +/* pos 02bf: 369 */ 0xE1 /* 'a' -> */, +/* pos 02c0: 370 */ 0xF2 /* 'r' -> */, +/* pos 02c1: 371 */ 0xE4 /* 'd' -> */, +/* pos 02c2: 372 */ 0xE5 /* 'e' -> */, +/* pos 02c3: 373 */ 0xE4 /* 'd' -> */, +/* pos 02c4: 374 */ 0xAD /* '-' -> */, +/* pos 02c5: 375 */ 0xE6 /* 'f' -> */, +/* pos 02c6: 376 */ 0xEF /* 'o' -> */, +/* pos 02c7: 377 */ 0xF2 /* 'r' -> */, +/* pos 02c8: 378 */ 0xBA /* ':' -> */, +/* pos 02c9: 379 */ 0x00, 0x4A /* - terminal marker 74 - */, +/* pos 02cb: 380 */ 0x00, 0x4B /* - terminal marker 75 - */, +/* pos 02cd: 381 */ 0xE1 /* 'a' -> */, +/* pos 02ce: 382 */ 0xE4 /* 'd' -> */, +/* pos 02cf: 383 */ 0xA0 /* ' ' -> */, +/* pos 02d0: 384 */ 0x00, 0x4C /* - terminal marker 76 - */, +/* pos 02d2: 385 */ 0xF5 /* 'u' -> */, +/* pos 02d3: 386 */ 0xF4 /* 't' -> */, +/* pos 02d4: 387 */ 0xE8 /* 'h' -> */, +/* pos 02d5: 388 */ 0xAD /* '-' -> */, +/* pos 02d6: 389 */ 0xF4 /* 't' -> */, +/* pos 02d7: 390 */ 0xEF /* 'o' -> */, +/* pos 02d8: 391 */ 0xEB /* 'k' -> */, +/* pos 02d9: 392 */ 0xE5 /* 'e' -> */, +/* pos 02da: 393 */ 0xEE /* 'n' -> */, +/* pos 02db: 394 */ 0xBA /* ':' -> */, +/* pos 02dc: 395 */ 0x00, 0x4F /* - terminal marker 79 - */, +/* pos 02de: 396 */ 0xF4 /* 't' -> */, +/* pos 02df: 397 */ 0xE9 /* 'i' -> */, +/* pos 02e0: 398 */ 0xEF /* 'o' -> */, +/* pos 02e1: 399 */ 0xEE /* 'n' -> */, +/* pos 02e2: 400 */ 0xF3 /* 's' -> */, +/* pos 02e3: 401 */ 0xA0 /* ' ' -> */, +/* pos 02e4: 402 */ 0x00, 0x02 /* - terminal marker 2 - */, +/* pos 02e6: 403 */ 0xF3 /* 's' -> */, +/* pos 02e7: 404 */ 0xAD /* '-' -> */, +/* pos 02e8: 405 */ 0xE3 /* 'c' -> */, +/* pos 02e9: 406 */ 0xEF /* 'o' -> */, +/* pos 02ea: 407 */ 0xEE /* 'n' -> */, +/* pos 02eb: 408 */ 0xF4 /* 't' -> */, +/* pos 02ec: 409 */ 0xF2 /* 'r' -> */, +/* pos 02ed: 410 */ 0xEF /* 'o' -> */, +/* pos 02ee: 411 */ 0xEC /* 'l' -> */, +/* pos 02ef: 412 */ 0xAD /* '-' -> */, +/* pos 02f0: 413 */ 0x72 /* 'r' */, 0x07, 0x00 /* (to 0x02F7 state 414) */, + 0x61 /* 'a' */, 0x24, 0x00 /* (to 0x0317 state 443) */, + 0x08, /* fail */ +/* pos 02f7: 414 */ 0xE5 /* 'e' -> */, +/* pos 02f8: 415 */ 0xF1 /* 'q' -> */, +/* pos 02f9: 416 */ 0xF5 /* 'u' -> */, +/* pos 02fa: 417 */ 0xE5 /* 'e' -> */, +/* pos 02fb: 418 */ 0xF3 /* 's' -> */, +/* pos 02fc: 419 */ 0xF4 /* 't' -> */, +/* pos 02fd: 420 */ 0xAD /* '-' -> */, +/* pos 02fe: 421 */ 0xE8 /* 'h' -> */, +/* pos 02ff: 422 */ 0xE5 /* 'e' -> */, +/* pos 0300: 423 */ 0xE1 /* 'a' -> */, +/* pos 0301: 424 */ 0xE4 /* 'd' -> */, +/* pos 0302: 425 */ 0xE5 /* 'e' -> */, +/* pos 0303: 426 */ 0xF2 /* 'r' -> */, +/* pos 0304: 427 */ 0xF3 /* 's' -> */, +/* pos 0305: 428 */ 0xBA /* ':' -> */, +/* pos 0306: 429 */ 0x00, 0x11 /* - terminal marker 17 - */, +/* pos 0308: 430 */ 0xF2 /* 'r' -> */, +/* pos 0309: 431 */ 0xE5 /* 'e' -> */, +/* pos 030a: 432 */ 0xF2 /* 'r' -> */, +/* pos 030b: 433 */ 0xBA /* ':' -> */, +/* pos 030c: 434 */ 0x00, 0x1E /* - terminal marker 30 - */, +/* pos 030e: 435 */ 0xE8 /* 'h' -> */, +/* pos 030f: 436 */ 0xE1 /* 'a' -> */, +/* pos 0310: 437 */ 0xF2 /* 'r' -> */, +/* pos 0311: 438 */ 0xF3 /* 's' -> */, +/* pos 0312: 439 */ 0xE5 /* 'e' -> */, +/* pos 0313: 440 */ 0xF4 /* 't' -> */, +/* pos 0314: 441 */ 0xBA /* ':' -> */, +/* pos 0315: 442 */ 0x00, 0x22 /* - terminal marker 34 - */, +/* pos 0317: 443 */ 0xEC /* 'l' -> */, +/* pos 0318: 444 */ 0xEC /* 'l' -> */, +/* pos 0319: 445 */ 0xEF /* 'o' -> */, +/* pos 031a: 446 */ 0xF7 /* 'w' -> */, +/* pos 031b: 447 */ 0xAD /* '-' -> */, +/* pos 031c: 448 */ 0xEF /* 'o' -> */, +/* pos 031d: 449 */ 0xF2 /* 'r' -> */, +/* pos 031e: 450 */ 0xE9 /* 'i' -> */, +/* pos 031f: 451 */ 0xE7 /* 'g' -> */, +/* pos 0320: 452 */ 0xE9 /* 'i' -> */, +/* pos 0321: 453 */ 0xEE /* 'n' -> */, +/* pos 0322: 454 */ 0xBA /* ':' -> */, +/* pos 0323: 455 */ 0x00, 0x24 /* - terminal marker 36 - */, +/* pos 0325: 456 */ 0xE1 /* 'a' -> */, +/* pos 0326: 457 */ 0xF8 /* 'x' -> */, +/* pos 0327: 458 */ 0xAD /* '-' -> */, +/* pos 0328: 459 */ 0xE6 /* 'f' -> */, +/* pos 0329: 460 */ 0xEF /* 'o' -> */, +/* pos 032a: 461 */ 0xF2 /* 'r' -> */, +/* pos 032b: 462 */ 0xF7 /* 'w' -> */, +/* pos 032c: 463 */ 0xE1 /* 'a' -> */, +/* pos 032d: 464 */ 0xF2 /* 'r' -> */, +/* pos 032e: 465 */ 0xE4 /* 'd' -> */, +/* pos 032f: 466 */ 0xF3 /* 's' -> */, +/* pos 0330: 467 */ 0xBA /* ':' -> */, +/* pos 0331: 468 */ 0x00, 0x36 /* - terminal marker 54 - */, +/* pos 0333: 469 */ 0xF8 /* 'x' -> */, +/* pos 0334: 470 */ 0xF9 /* 'y' -> */, +/* pos 0335: 471 */ 0x2D /* '-' */, 0x07, 0x00 /* (to 0x033C state 472) */, + 0x20 /* ' ' */, 0x79, 0x00 /* (to 0x03B1 state 567) */, + 0x08, /* fail */ +/* pos 033c: 472 */ 0xE1 /* 'a' -> */, +/* pos 033d: 473 */ 0xF5 /* 'u' -> */, +/* pos 033e: 474 */ 0xF4 /* 't' -> */, +/* pos 033f: 475 */ 0xE8 /* 'h' -> */, +/* pos 0340: 476 */ 0x65 /* 'e' */, 0x07, 0x00 /* (to 0x0347 state 477) */, + 0x6F /* 'o' */, 0x0E, 0x00 /* (to 0x0351 state 486) */, + 0x08, /* fail */ +/* pos 0347: 477 */ 0xEE /* 'n' -> */, +/* pos 0348: 478 */ 0xF4 /* 't' -> */, +/* pos 0349: 479 */ 0xE9 /* 'i' -> */, +/* pos 034a: 480 */ 0xE3 /* 'c' -> */, +/* pos 034b: 481 */ 0xE1 /* 'a' -> */, +/* pos 034c: 482 */ 0xF4 /* 't' -> */, +/* pos 034d: 483 */ 0xE5 /* 'e' -> */, +/* pos 034e: 484 */ 0xBA /* ':' -> */, +/* pos 034f: 485 */ 0x00, 0x37 /* - terminal marker 55 - */, +/* pos 0351: 486 */ 0xF2 /* 'r' -> */, +/* pos 0352: 487 */ 0xE9 /* 'i' -> */, +/* pos 0353: 488 */ 0xFA /* 'z' -> */, +/* pos 0354: 489 */ 0xE1 /* 'a' -> */, +/* pos 0355: 490 */ 0xF4 /* 't' -> */, +/* pos 0356: 491 */ 0xE9 /* 'i' -> */, +/* pos 0357: 492 */ 0xEF /* 'o' -> */, +/* pos 0358: 493 */ 0xEE /* 'n' -> */, +/* pos 0359: 494 */ 0xBA /* ':' -> */, +/* pos 035a: 495 */ 0x00, 0x38 /* - terminal marker 56 - */, +/* pos 035c: 496 */ 0xF2 /* 'r' -> */, +/* pos 035d: 497 */ 0xE9 /* 'i' -> */, +/* pos 035e: 498 */ 0xE3 /* 'c' -> */, +/* pos 035f: 499 */ 0xF4 /* 't' -> */, +/* pos 0360: 500 */ 0xAD /* '-' -> */, +/* pos 0361: 501 */ 0xF4 /* 't' -> */, +/* pos 0362: 502 */ 0xF2 /* 'r' -> */, +/* pos 0363: 503 */ 0xE1 /* 'a' -> */, +/* pos 0364: 504 */ 0xEE /* 'n' -> */, +/* pos 0365: 505 */ 0xF3 /* 's' -> */, +/* pos 0366: 506 */ 0xF0 /* 'p' -> */, +/* pos 0367: 507 */ 0xEF /* 'o' -> */, +/* pos 0368: 508 */ 0xF2 /* 'r' -> */, +/* pos 0369: 509 */ 0xF4 /* 't' -> */, +/* pos 036a: 510 */ 0xAD /* '-' -> */, +/* pos 036b: 511 */ 0xF3 /* 's' -> */, +/* pos 036c: 512 */ 0xE5 /* 'e' -> */, +/* pos 036d: 513 */ 0xE3 /* 'c' -> */, +/* pos 036e: 514 */ 0xF5 /* 'u' -> */, +/* pos 036f: 515 */ 0xF2 /* 'r' -> */, +/* pos 0370: 516 */ 0xE9 /* 'i' -> */, +/* pos 0371: 517 */ 0xF4 /* 't' -> */, +/* pos 0372: 518 */ 0xF9 /* 'y' -> */, +/* pos 0373: 519 */ 0xBA /* ':' -> */, +/* pos 0374: 520 */ 0x00, 0x3D /* - terminal marker 61 - */, +/* pos 0376: 521 */ 0xE5 /* 'e' -> */, +/* pos 0377: 522 */ 0xF2 /* 'r' -> */, +/* pos 0378: 523 */ 0xAD /* '-' -> */, +/* pos 0379: 524 */ 0xE1 /* 'a' -> */, +/* pos 037a: 525 */ 0xE7 /* 'g' -> */, +/* pos 037b: 526 */ 0xE5 /* 'e' -> */, +/* pos 037c: 527 */ 0xEE /* 'n' -> */, +/* pos 037d: 528 */ 0xF4 /* 't' -> */, +/* pos 037e: 529 */ 0xBA /* ':' -> */, +/* pos 037f: 530 */ 0x00, 0x3F /* - terminal marker 63 - */, +/* pos 0381: 531 */ 0x61 /* 'a' */, 0x07, 0x00 /* (to 0x0388 state 532) */, + 0x69 /* 'i' */, 0x09, 0x00 /* (to 0x038D state 536) */, + 0x08, /* fail */ +/* pos 0388: 532 */ 0xF2 /* 'r' -> */, +/* pos 0389: 533 */ 0xF9 /* 'y' -> */, +/* pos 038a: 534 */ 0xBA /* ':' -> */, +/* pos 038b: 535 */ 0x00, 0x40 /* - terminal marker 64 - */, +/* pos 038d: 536 */ 0xE1 /* 'a' -> */, +/* pos 038e: 537 */ 0xBA /* ':' -> */, +/* pos 038f: 538 */ 0x00, 0x41 /* - terminal marker 65 - */, +/* pos 0391: 539 */ 0xF7 /* 'w' -> */, +/* pos 0392: 540 */ 0xF7 /* 'w' -> */, +/* pos 0393: 541 */ 0xAD /* '-' -> */, +/* pos 0394: 542 */ 0xE1 /* 'a' -> */, +/* pos 0395: 543 */ 0xF5 /* 'u' -> */, +/* pos 0396: 544 */ 0xF4 /* 't' -> */, +/* pos 0397: 545 */ 0xE8 /* 'h' -> */, +/* pos 0398: 546 */ 0xE5 /* 'e' -> */, +/* pos 0399: 547 */ 0xEE /* 'n' -> */, +/* pos 039a: 548 */ 0xF4 /* 't' -> */, +/* pos 039b: 549 */ 0xE9 /* 'i' -> */, +/* pos 039c: 550 */ 0xE3 /* 'c' -> */, +/* pos 039d: 551 */ 0xE1 /* 'a' -> */, +/* pos 039e: 552 */ 0xF4 /* 't' -> */, +/* pos 039f: 553 */ 0xE5 /* 'e' -> */, +/* pos 03a0: 554 */ 0xBA /* ':' -> */, +/* pos 03a1: 555 */ 0x00, 0x42 /* - terminal marker 66 - */, +/* pos 03a3: 556 */ 0xF4 /* 't' -> */, +/* pos 03a4: 557 */ 0xE3 /* 'c' -> */, +/* pos 03a5: 558 */ 0xE8 /* 'h' -> */, +/* pos 03a6: 559 */ 0x00, 0x43 /* - terminal marker 67 - */, +/* pos 03a8: 560 */ 0xF4 /* 't' -> */, +/* pos 03a9: 561 */ 0x00, 0x44 /* - terminal marker 68 - */, +/* pos 03ab: 562 */ 0xEC /* 'l' -> */, +/* pos 03ac: 563 */ 0xE5 /* 'e' -> */, +/* pos 03ad: 564 */ 0xF4 /* 't' -> */, +/* pos 03ae: 565 */ 0xE5 /* 'e' -> */, +/* pos 03af: 566 */ 0x00, 0x45 /* - terminal marker 69 - */, +/* pos 03b1: 567 */ 0x00, 0x47 /* - terminal marker 71 - */, +/* pos 03b3: 568 */ 0xE5 /* 'e' -> */, +/* pos 03b4: 569 */ 0xE1 /* 'a' -> */, +/* pos 03b5: 570 */ 0xEC /* 'l' -> */, +/* pos 03b6: 571 */ 0xAD /* '-' -> */, +/* pos 03b7: 572 */ 0xE9 /* 'i' -> */, +/* pos 03b8: 573 */ 0xF0 /* 'p' -> */, +/* pos 03b9: 574 */ 0xBA /* ':' -> */, +/* pos 03ba: 575 */ 0x00, 0x48 /* - terminal marker 72 - */, +/* pos 03bc: 576 */ 0xBA /* ':' -> */, +/* pos 03bd: 577 */ 0x00, 0x4D /* - terminal marker 77 - */, +/* pos 03bf: 578 */ 0xEC /* 'l' -> */, +/* pos 03c0: 579 */ 0xE1 /* 'a' -> */, +/* pos 03c1: 580 */ 0xF9 /* 'y' -> */, +/* pos 03c2: 581 */ 0xAD /* '-' -> */, +/* pos 03c3: 582 */ 0xEE /* 'n' -> */, +/* pos 03c4: 583 */ 0xEF /* 'o' -> */, +/* pos 03c5: 584 */ 0xEE /* 'n' -> */, +/* pos 03c6: 585 */ 0xE3 /* 'c' -> */, +/* pos 03c7: 586 */ 0xE5 /* 'e' -> */, +/* pos 03c8: 587 */ 0xBA /* ':' -> */, +/* pos 03c9: 588 */ 0x00, 0x4E /* - terminal marker 78 - */, +/* pos 03cb: 589 */ 0xAD /* '-' -> */, +/* pos 03cc: 590 */ 0xF7 /* 'w' -> */, +/* pos 03cd: 591 */ 0xE5 /* 'e' -> */, +/* pos 03ce: 592 */ 0xE2 /* 'b' -> */, +/* pos 03cf: 593 */ 0xF3 /* 's' -> */, +/* pos 03d0: 594 */ 0xEF /* 'o' -> */, +/* pos 03d1: 595 */ 0xE3 /* 'c' -> */, +/* pos 03d2: 596 */ 0xEB /* 'k' -> */, +/* pos 03d3: 597 */ 0xE5 /* 'e' -> */, +/* pos 03d4: 598 */ 0xF4 /* 't' -> */, +/* pos 03d5: 599 */ 0xAD /* '-' -> */, +/* pos 03d6: 600 */ 0x64 /* 'd' */, 0x19, 0x00 /* (to 0x03EF state 601) */, + 0x65 /* 'e' */, 0x1D, 0x00 /* (to 0x03F6 state 607) */, + 0x6B /* 'k' */, 0x26, 0x00 /* (to 0x0402 state 618) */, + 0x70 /* 'p' */, 0x35, 0x00 /* (to 0x0414 state 625) */, + 0x61 /* 'a' */, 0x3C, 0x00 /* (to 0x041E state 634) */, + 0x6E /* 'n' */, 0x41, 0x00 /* (to 0x0426 state 641) */, + 0x76 /* 'v' */, 0x47, 0x00 /* (to 0x042F state 648) */, + 0x6F /* 'o' */, 0x4D, 0x00 /* (to 0x0438 state 656) */, + 0x08, /* fail */ +/* pos 03ef: 601 */ 0xF2 /* 'r' -> */, +/* pos 03f0: 602 */ 0xE1 /* 'a' -> */, +/* pos 03f1: 603 */ 0xE6 /* 'f' -> */, +/* pos 03f2: 604 */ 0xF4 /* 't' -> */, +/* pos 03f3: 605 */ 0xBA /* ':' -> */, +/* pos 03f4: 606 */ 0x00, 0x07 /* - terminal marker 7 - */, +/* pos 03f6: 607 */ 0xF8 /* 'x' -> */, +/* pos 03f7: 608 */ 0xF4 /* 't' -> */, +/* pos 03f8: 609 */ 0xE5 /* 'e' -> */, +/* pos 03f9: 610 */ 0xEE /* 'n' -> */, +/* pos 03fa: 611 */ 0xF3 /* 's' -> */, +/* pos 03fb: 612 */ 0xE9 /* 'i' -> */, +/* pos 03fc: 613 */ 0xEF /* 'o' -> */, +/* pos 03fd: 614 */ 0xEE /* 'n' -> */, +/* pos 03fe: 615 */ 0xF3 /* 's' -> */, +/* pos 03ff: 616 */ 0xBA /* ':' -> */, +/* pos 0400: 617 */ 0x00, 0x09 /* - terminal marker 9 - */, +/* pos 0402: 618 */ 0xE5 /* 'e' -> */, +/* pos 0403: 619 */ 0xF9 /* 'y' -> */, +/* pos 0404: 620 */ 0x31 /* '1' */, 0x0A, 0x00 /* (to 0x040E state 621) */, + 0x32 /* '2' */, 0x0A, 0x00 /* (to 0x0411 state 623) */, + 0x3A /* ':' */, 0x23, 0x00 /* (to 0x042D state 647) */, + 0x08, /* fail */ +/* pos 040e: 621 */ 0xBA /* ':' -> */, +/* pos 040f: 622 */ 0x00, 0x0A /* - terminal marker 10 - */, +/* pos 0411: 623 */ 0xBA /* ':' -> */, +/* pos 0412: 624 */ 0x00, 0x0B /* - terminal marker 11 - */, +/* pos 0414: 625 */ 0xF2 /* 'r' -> */, +/* pos 0415: 626 */ 0xEF /* 'o' -> */, +/* pos 0416: 627 */ 0xF4 /* 't' -> */, +/* pos 0417: 628 */ 0xEF /* 'o' -> */, +/* pos 0418: 629 */ 0xE3 /* 'c' -> */, +/* pos 0419: 630 */ 0xEF /* 'o' -> */, +/* pos 041a: 631 */ 0xEC /* 'l' -> */, +/* pos 041b: 632 */ 0xBA /* ':' -> */, +/* pos 041c: 633 */ 0x00, 0x0C /* - terminal marker 12 - */, +/* pos 041e: 634 */ 0xE3 /* 'c' -> */, +/* pos 041f: 635 */ 0xE3 /* 'c' -> */, +/* pos 0420: 636 */ 0xE5 /* 'e' -> */, +/* pos 0421: 637 */ 0xF0 /* 'p' -> */, +/* pos 0422: 638 */ 0xF4 /* 't' -> */, +/* pos 0423: 639 */ 0xBA /* ':' -> */, +/* pos 0424: 640 */ 0x00, 0x0D /* - terminal marker 13 - */, +/* pos 0426: 641 */ 0xEF /* 'o' -> */, +/* pos 0427: 642 */ 0xEE /* 'n' -> */, +/* pos 0428: 643 */ 0xE3 /* 'c' -> */, +/* pos 0429: 644 */ 0xE5 /* 'e' -> */, +/* pos 042a: 645 */ 0xBA /* ':' -> */, +/* pos 042b: 646 */ 0x00, 0x0E /* - terminal marker 14 - */, +/* pos 042d: 647 */ 0x00, 0x1F /* - terminal marker 31 - */, +/* pos 042f: 648 */ 0xE5 /* 'e' -> */, +/* pos 0430: 649 */ 0xF2 /* 'r' -> */, +/* pos 0431: 650 */ 0xF3 /* 's' -> */, +/* pos 0432: 651 */ 0xE9 /* 'i' -> */, +/* pos 0433: 652 */ 0xEF /* 'o' -> */, +/* pos 0434: 653 */ 0xEE /* 'n' -> */, +/* pos 0435: 654 */ 0xBA /* ':' -> */, +/* pos 0436: 655 */ 0x00, 0x20 /* - terminal marker 32 - */, +/* pos 0438: 656 */ 0xF2 /* 'r' -> */, +/* pos 0439: 657 */ 0xE9 /* 'i' -> */, +/* pos 043a: 658 */ 0xE7 /* 'g' -> */, +/* pos 043b: 659 */ 0xE9 /* 'i' -> */, +/* pos 043c: 660 */ 0xEE /* 'n' -> */, +/* pos 043d: 661 */ 0xBA /* ':' -> */, +/* pos 043e: 662 */ 0x00, 0x21 /* - terminal marker 33 - */, +/* total size 1088 bytes */ +#endif + +#if !defined(LWS_HTTP_HEADERS_ALL) && !defined(LWS_WITH_HTTP_UNCOMMON_HEADERS) && !defined(LWS_ROLE_WS) && defined(LWS_ROLE_H2) + /* 0: 0: get */ + /* 1: 1: post */ + /* 2: 3: host: */ + /* 3: 4: connection: */ + /* 4: 5: upgrade: */ + /* 5: 6: origin: */ + /* 6: 8: + */ + /* 7: 15: http/1.1 */ + /* 8: 16: http2-settings: */ + /* 9: 17: accept: */ + /* 10: 19: if-modified-since: */ + /* 11: 20: if-none-match: */ + /* 12: 21: accept-encoding: */ + /* 13: 22: accept-language: */ + /* 14: 23: pragma: */ + /* 15: 24: cache-control: */ + /* 16: 25: authorization: */ + /* 17: 26: cookie: */ + /* 18: 27: content-length: */ + /* 19: 28: content-type: */ + /* 20: 29: date: */ + /* 21: 30: range: */ + /* 22: 31: referer: */ + /* 23: 35: :authority */ + /* 24: 36: :method */ + /* 25: 37: :path */ + /* 26: 38: :scheme */ + /* 27: 39: :status */ + /* 28: 40: accept-charset: */ + /* 29: 41: accept-ranges: */ + /* 30: 42: access-control-allow-origin: */ + /* 31: 43: age: */ + /* 32: 44: allow: */ + /* 33: 45: content-disposition: */ + /* 34: 46: content-encoding: */ + /* 35: 47: content-language: */ + /* 36: 48: content-location: */ + /* 37: 49: content-range: */ + /* 38: 50: etag: */ + /* 39: 51: expect: */ + /* 40: 52: expires: */ + /* 41: 53: from: */ + /* 42: 54: if-match: */ + /* 43: 55: if-range: */ + /* 44: 56: if-unmodified-since: */ + /* 45: 57: last-modified: */ + /* 46: 58: link: */ + /* 47: 59: location: */ + /* 48: 60: max-forwards: */ + /* 49: 61: proxy-authenticate: */ + /* 50: 62: proxy-authorization: */ + /* 51: 63: refresh: */ + /* 52: 64: retry-after: */ + /* 53: 65: server: */ + /* 54: 66: set-cookie: */ + /* 55: 67: strict-transport-security: */ + /* 56: 68: transfer-encoding: */ + /* 57: 69: user-agent: */ + /* 58: 70: vary: */ + /* 59: 71: via: */ + /* 60: 72: www-authenticate: */ + /* 61: 76: uri-args */ + /* 62: 79: http/1.0 */ + /* 63: 80: x-forwarded-for: */ + /* 64: 81: connect */ + /* 65: 82: head */ + /* 66: 83: te: */ + /* 67: 84: replay-nonce: */ + /* 68: 85: :protocol */ + /* 69: 86: x-auth-token: */ + /* 70: 87: */ /* pos 0000: 0 */ 0x67 /* 'g' */, 0x40, 0x00 /* (to 0x0040 state 1) */, 0x70 /* 'p' */, 0x42, 0x00 /* (to 0x0045 state 5) */, - 0x6F /* 'o' */, 0x51, 0x00 /* (to 0x0057 state 10) */, - 0x68 /* 'h' */, 0x5D, 0x00 /* (to 0x0066 state 18) */, - 0x63 /* 'c' */, 0x69, 0x00 /* (to 0x0075 state 23) */, - 0x75 /* 'u' */, 0x8A, 0x00 /* (to 0x0099 state 34) */, - 0x73 /* 's' */, 0xA0, 0x00 /* (to 0x00B2 state 48) */, - 0x0D /* '.' */, 0xD9, 0x00 /* (to 0x00EE state 68) */, - 0x61 /* 'a' */, 0x31, 0x01 /* (to 0x0149 state 129) */, - 0x69 /* 'i' */, 0x70, 0x01 /* (to 0x018B state 163) */, - 0x64 /* 'd' */, 0x19, 0x02 /* (to 0x0237 state 265) */, - 0x72 /* 'r' */, 0x22, 0x02 /* (to 0x0243 state 270) */, - 0x3A /* ':' */, 0x56, 0x02 /* (to 0x027A state 299) */, - 0x65 /* 'e' */, 0xE8, 0x02 /* (to 0x030F state 409) */, - 0x66 /* 'f' */, 0x04, 0x03 /* (to 0x032E state 425) */, - 0x6C /* 'l' */, 0x26, 0x03 /* (to 0x0353 state 458) */, - 0x6D /* 'm' */, 0x49, 0x03 /* (to 0x0379 state 484) */, - 0x74 /* 't' */, 0xB8, 0x03 /* (to 0x03EB state 578) */, - 0x76 /* 'v' */, 0xD9, 0x03 /* (to 0x040F state 606) */, - 0x77 /* 'w' */, 0xE6, 0x03 /* (to 0x041F state 614) */, - 0x78 /* 'x' */, 0x0D, 0x04 /* (to 0x0449 state 650) */, + 0x68 /* 'h' */, 0x51, 0x00 /* (to 0x0057 state 10) */, + 0x63 /* 'c' */, 0x5D, 0x00 /* (to 0x0066 state 15) */, + 0x75 /* 'u' */, 0x7E, 0x00 /* (to 0x008A state 26) */, + 0x6F /* 'o' */, 0x8D, 0x00 /* (to 0x009C state 34) */, + 0x0D /* '.' */, 0x98, 0x00 /* (to 0x00AA state 41) */, + 0x61 /* 'a' */, 0xAD, 0x00 /* (to 0x00C2 state 51) */, + 0x69 /* 'i' */, 0xCA, 0x00 /* (to 0x00E2 state 58) */, + 0x64 /* 'd' */, 0x73, 0x01 /* (to 0x018E state 160) */, + 0x72 /* 'r' */, 0x7C, 0x01 /* (to 0x019A state 165) */, + 0x65 /* 'e' */, 0xC8, 0x01 /* (to 0x01E9 state 229) */, + 0x66 /* 'f' */, 0xE4, 0x01 /* (to 0x0208 state 245) */, + 0x6C /* 'l' */, 0x06, 0x02 /* (to 0x022D state 278) */, + 0x73 /* 's' */, 0x4B, 0x02 /* (to 0x0275 state 321) */, + 0x74 /* 't' */, 0x69, 0x02 /* (to 0x0296 state 337) */, + 0x78 /* 'x' */, 0x8A, 0x02 /* (to 0x02BA state 364) */, + 0x6D /* 'm' */, 0xFB, 0x02 /* (to 0x032E state 456) */, + 0x76 /* 'v' */, 0x54, 0x03 /* (to 0x038A state 531) */, + 0x77 /* 'w' */, 0x61, 0x03 /* (to 0x039A state 539) */, + 0x3A /* ':' */, 0x19, 0x04 /* (to 0x0455 state 674) */, 0x08, /* fail */ /* pos 0040: 1 */ 0xE5 /* 'e' -> */, /* pos 0041: 2 */ 0xF4 /* 't' -> */, /* pos 0042: 3 */ 0xA0 /* ' ' -> */, /* pos 0043: 4 */ 0x00, 0x00 /* - terminal marker 0 - */, /* pos 0045: 5 */ 0x6F /* 'o' */, 0x0D, 0x00 /* (to 0x0052 state 6) */, - 0x72 /* 'r' */, 0x95, 0x01 /* (to 0x01DD state 211) */, - 0x61 /* 'a' */, 0xE6, 0x03 /* (to 0x0431 state 631) */, - 0x75 /* 'u' */, 0xE8, 0x03 /* (to 0x0436 state 635) */, + 0x72 /* 'r' */, 0xEC, 0x00 /* (to 0x0134 state 106) */, + 0x61 /* 'a' */, 0x61, 0x03 /* (to 0x03AC state 556) */, + 0x75 /* 'u' */, 0x63, 0x03 /* (to 0x03B1 state 560) */, 0x08, /* fail */ /* pos 0052: 6 */ 0xF3 /* 's' -> */, /* pos 0053: 7 */ 0xF4 /* 't' -> */, /* pos 0054: 8 */ 0xA0 /* ' ' -> */, /* pos 0055: 9 */ 0x00, 0x01 /* - terminal marker 1 - */, -/* pos 0057: 10 */ 0x70 /* 'p' */, 0x07, 0x00 /* (to 0x005E state 11) */, - 0x72 /* 'r' */, 0x51, 0x00 /* (to 0x00AB state 42) */, +/* pos 0057: 10 */ 0x6F /* 'o' */, 0x0A, 0x00 /* (to 0x0061 state 11) */, + 0x74 /* 't' */, 0x53, 0x00 /* (to 0x00AD state 43) */, + 0x65 /* 'e' */, 0x79, 0x02 /* (to 0x02D6 state 381) */, 0x08, /* fail */ -/* pos 005e: 11 */ 0xF4 /* 't' -> */, -/* pos 005f: 12 */ 0xE9 /* 'i' -> */, -/* pos 0060: 13 */ 0xEF /* 'o' -> */, -/* pos 0061: 14 */ 0xEE /* 'n' -> */, -/* pos 0062: 15 */ 0xF3 /* 's' -> */, -/* pos 0063: 16 */ 0xA0 /* ' ' -> */, -/* pos 0064: 17 */ 0x00, 0x02 /* - terminal marker 2 - */, -/* pos 0066: 18 */ 0x6F /* 'o' */, 0x0A, 0x00 /* (to 0x0070 state 19) */, - 0x74 /* 't' */, 0xBF, 0x00 /* (to 0x0128 state 110) */, - 0x65 /* 'e' */, 0x04, 0x04 /* (to 0x0470 state 676) */, - 0x08, /* fail */ -/* pos 0070: 19 */ 0xF3 /* 's' -> */, -/* pos 0071: 20 */ 0xF4 /* 't' -> */, -/* pos 0072: 21 */ 0xBA /* ':' -> */, -/* pos 0073: 22 */ 0x00, 0x03 /* - terminal marker 3 - */, -/* pos 0075: 23 */ 0x6F /* 'o' */, 0x07, 0x00 /* (to 0x007C state 24) */, - 0x61 /* 'a' */, 0x72, 0x01 /* (to 0x01EA state 217) */, - 0x08, /* fail */ -/* pos 007c: 24 */ 0x6E /* 'n' */, 0x07, 0x00 /* (to 0x0083 state 25) */, - 0x6F /* 'o' */, 0x87, 0x01 /* (to 0x0206 state 243) */, - 0x08, /* fail */ -/* pos 0083: 25 */ 0x6E /* 'n' */, 0x07, 0x00 /* (to 0x008A state 26) */, - 0x74 /* 't' */, 0x86, 0x01 /* (to 0x020C state 248) */, - 0x08, /* fail */ -/* pos 008a: 26 */ 0xE5 /* 'e' -> */, -/* pos 008b: 27 */ 0xE3 /* 'c' -> */, -/* pos 008c: 28 */ 0xF4 /* 't' -> */, -/* pos 008d: 29 */ 0x69 /* 'i' */, 0x07, 0x00 /* (to 0x0094 state 30) */, - 0x20 /* ' ' */, 0xDE, 0x03 /* (to 0x046E state 675) */, +/* pos 0061: 11 */ 0xF3 /* 's' -> */, +/* pos 0062: 12 */ 0xF4 /* 't' -> */, +/* pos 0063: 13 */ 0xBA /* ':' -> */, +/* pos 0064: 14 */ 0x00, 0x02 /* - terminal marker 2 - */, +/* pos 0066: 15 */ 0x6F /* 'o' */, 0x07, 0x00 /* (to 0x006D state 16) */, + 0x61 /* 'a' */, 0xD8, 0x00 /* (to 0x0141 state 112) */, 0x08, /* fail */ -/* pos 0094: 30 */ 0xEF /* 'o' -> */, -/* pos 0095: 31 */ 0xEE /* 'n' -> */, -/* pos 0096: 32 */ 0xBA /* ':' -> */, -/* pos 0097: 33 */ 0x00, 0x04 /* - terminal marker 4 - */, -/* pos 0099: 34 */ 0x70 /* 'p' */, 0x0A, 0x00 /* (to 0x00A3 state 35) */, - 0x73 /* 's' */, 0x68, 0x03 /* (to 0x0404 state 596) */, - 0x72 /* 'r' */, 0xA0, 0x03 /* (to 0x043F state 642) */, - 0x08, /* fail */ -/* pos 00a3: 35 */ 0xE7 /* 'g' -> */, -/* pos 00a4: 36 */ 0xF2 /* 'r' -> */, -/* pos 00a5: 37 */ 0xE1 /* 'a' -> */, -/* pos 00a6: 38 */ 0xE4 /* 'd' -> */, -/* pos 00a7: 39 */ 0xE5 /* 'e' -> */, -/* pos 00a8: 40 */ 0xBA /* ':' -> */, -/* pos 00a9: 41 */ 0x00, 0x05 /* - terminal marker 5 - */, -/* pos 00ab: 42 */ 0xE9 /* 'i' -> */, -/* pos 00ac: 43 */ 0xE7 /* 'g' -> */, -/* pos 00ad: 44 */ 0xE9 /* 'i' -> */, -/* pos 00ae: 45 */ 0xEE /* 'n' -> */, -/* pos 00af: 46 */ 0xBA /* ':' -> */, -/* pos 00b0: 47 */ 0x00, 0x06 /* - terminal marker 6 - */, -/* pos 00b2: 48 */ 0x65 /* 'e' */, 0x07, 0x00 /* (to 0x00B9 state 49) */, - 0x74 /* 't' */, 0x1C, 0x03 /* (to 0x03D1 state 553) */, - 0x08, /* fail */ -/* pos 00b9: 49 */ 0x63 /* 'c' */, 0x0A, 0x00 /* (to 0x00C3 state 50) */, - 0x72 /* 'r' */, 0x05, 0x03 /* (to 0x03C1 state 539) */, - 0x74 /* 't' */, 0x08, 0x03 /* (to 0x03C7 state 544) */, - 0x08, /* fail */ -/* pos 00c3: 50 */ 0xAD /* '-' -> */, -/* pos 00c4: 51 */ 0xF7 /* 'w' -> */, -/* pos 00c5: 52 */ 0xE5 /* 'e' -> */, -/* pos 00c6: 53 */ 0xE2 /* 'b' -> */, -/* pos 00c7: 54 */ 0xF3 /* 's' -> */, -/* pos 00c8: 55 */ 0xEF /* 'o' -> */, -/* pos 00c9: 56 */ 0xE3 /* 'c' -> */, -/* pos 00ca: 57 */ 0xEB /* 'k' -> */, -/* pos 00cb: 58 */ 0xE5 /* 'e' -> */, -/* pos 00cc: 59 */ 0xF4 /* 't' -> */, -/* pos 00cd: 60 */ 0xAD /* '-' -> */, -/* pos 00ce: 61 */ 0x64 /* 'd' */, 0x19, 0x00 /* (to 0x00E7 state 62) */, - 0x65 /* 'e' */, 0x20, 0x00 /* (to 0x00F1 state 70) */, - 0x6B /* 'k' */, 0x29, 0x00 /* (to 0x00FD state 81) */, - 0x70 /* 'p' */, 0x38, 0x00 /* (to 0x010F state 88) */, - 0x61 /* 'a' */, 0x3F, 0x00 /* (to 0x0119 state 97) */, - 0x6E /* 'n' */, 0x44, 0x00 /* (to 0x0121 state 104) */, - 0x76 /* 'v' */, 0x89, 0x01 /* (to 0x0269 state 284) */, - 0x6F /* 'o' */, 0x8F, 0x01 /* (to 0x0272 state 292) */, - 0x08, /* fail */ -/* pos 00e7: 62 */ 0xF2 /* 'r' -> */, -/* pos 00e8: 63 */ 0xE1 /* 'a' -> */, -/* pos 00e9: 64 */ 0xE6 /* 'f' -> */, -/* pos 00ea: 65 */ 0xF4 /* 't' -> */, -/* pos 00eb: 66 */ 0xBA /* ':' -> */, -/* pos 00ec: 67 */ 0x00, 0x07 /* - terminal marker 7 - */, -/* pos 00ee: 68 */ 0x8A /* '.' -> */, -/* pos 00ef: 69 */ 0x00, 0x08 /* - terminal marker 8 - */, -/* pos 00f1: 70 */ 0xF8 /* 'x' -> */, -/* pos 00f2: 71 */ 0xF4 /* 't' -> */, -/* pos 00f3: 72 */ 0xE5 /* 'e' -> */, -/* pos 00f4: 73 */ 0xEE /* 'n' -> */, -/* pos 00f5: 74 */ 0xF3 /* 's' -> */, -/* pos 00f6: 75 */ 0xE9 /* 'i' -> */, -/* pos 00f7: 76 */ 0xEF /* 'o' -> */, -/* pos 00f8: 77 */ 0xEE /* 'n' -> */, -/* pos 00f9: 78 */ 0xF3 /* 's' -> */, -/* pos 00fa: 79 */ 0xBA /* ':' -> */, -/* pos 00fb: 80 */ 0x00, 0x09 /* - terminal marker 9 - */, -/* pos 00fd: 81 */ 0xE5 /* 'e' -> */, -/* pos 00fe: 82 */ 0xF9 /* 'y' -> */, -/* pos 00ff: 83 */ 0x31 /* '1' */, 0x0A, 0x00 /* (to 0x0109 state 84) */, - 0x32 /* '2' */, 0x0A, 0x00 /* (to 0x010C state 86) */, - 0x3A /* ':' */, 0x62, 0x01 /* (to 0x0267 state 283) */, - 0x08, /* fail */ -/* pos 0109: 84 */ 0xBA /* ':' -> */, -/* pos 010a: 85 */ 0x00, 0x0A /* - terminal marker 10 - */, -/* pos 010c: 86 */ 0xBA /* ':' -> */, -/* pos 010d: 87 */ 0x00, 0x0B /* - terminal marker 11 - */, -/* pos 010f: 88 */ 0xF2 /* 'r' -> */, -/* pos 0110: 89 */ 0xEF /* 'o' -> */, -/* pos 0111: 90 */ 0xF4 /* 't' -> */, -/* pos 0112: 91 */ 0xEF /* 'o' -> */, -/* pos 0113: 92 */ 0xE3 /* 'c' -> */, -/* pos 0114: 93 */ 0xEF /* 'o' -> */, -/* pos 0115: 94 */ 0xEC /* 'l' -> */, -/* pos 0116: 95 */ 0xBA /* ':' -> */, -/* pos 0117: 96 */ 0x00, 0x0C /* - terminal marker 12 - */, -/* pos 0119: 97 */ 0xE3 /* 'c' -> */, -/* pos 011a: 98 */ 0xE3 /* 'c' -> */, -/* pos 011b: 99 */ 0xE5 /* 'e' -> */, -/* pos 011c: 100 */ 0xF0 /* 'p' -> */, -/* pos 011d: 101 */ 0xF4 /* 't' -> */, -/* pos 011e: 102 */ 0xBA /* ':' -> */, -/* pos 011f: 103 */ 0x00, 0x0D /* - terminal marker 13 - */, -/* pos 0121: 104 */ 0xEF /* 'o' -> */, -/* pos 0122: 105 */ 0xEE /* 'n' -> */, -/* pos 0123: 106 */ 0xE3 /* 'c' -> */, -/* pos 0124: 107 */ 0xE5 /* 'e' -> */, -/* pos 0125: 108 */ 0xBA /* ':' -> */, -/* pos 0126: 109 */ 0x00, 0x0E /* - terminal marker 14 - */, -/* pos 0128: 110 */ 0xF4 /* 't' -> */, -/* pos 0129: 111 */ 0xF0 /* 'p' -> */, -/* pos 012a: 112 */ 0x2F /* '/' */, 0x07, 0x00 /* (to 0x0131 state 113) */, - 0x32 /* '2' */, 0x10, 0x00 /* (to 0x013D state 118) */, - 0x08, /* fail */ -/* pos 0131: 113 */ 0xB1 /* '1' -> */, -/* pos 0132: 114 */ 0xAE /* '.' -> */, -/* pos 0133: 115 */ 0x31 /* '1' */, 0x07, 0x00 /* (to 0x013A state 116) */, - 0x30 /* '0' */, 0x27, 0x03 /* (to 0x045D state 660) */, - 0x08, /* fail */ -/* pos 013a: 116 */ 0xA0 /* ' ' -> */, -/* pos 013b: 117 */ 0x00, 0x0F /* - terminal marker 15 - */, -/* pos 013d: 118 */ 0xAD /* '-' -> */, -/* pos 013e: 119 */ 0xF3 /* 's' -> */, -/* pos 013f: 120 */ 0xE5 /* 'e' -> */, -/* pos 0140: 121 */ 0xF4 /* 't' -> */, -/* pos 0141: 122 */ 0xF4 /* 't' -> */, -/* pos 0142: 123 */ 0xE9 /* 'i' -> */, -/* pos 0143: 124 */ 0xEE /* 'n' -> */, -/* pos 0144: 125 */ 0xE7 /* 'g' -> */, -/* pos 0145: 126 */ 0xF3 /* 's' -> */, -/* pos 0146: 127 */ 0xBA /* ':' -> */, -/* pos 0147: 128 */ 0x00, 0x10 /* - terminal marker 16 - */, -/* pos 0149: 129 */ 0x63 /* 'c' */, 0x0D, 0x00 /* (to 0x0156 state 130) */, - 0x75 /* 'u' */, 0xAC, 0x00 /* (to 0x01F8 state 230) */, - 0x67 /* 'g' */, 0x86, 0x01 /* (to 0x02D5 state 358) */, - 0x6C /* 'l' */, 0x87, 0x01 /* (to 0x02D9 state 361) */, - 0x08, /* fail */ -/* pos 0156: 130 */ 0xE3 /* 'c' -> */, -/* pos 0157: 131 */ 0xE5 /* 'e' -> */, -/* pos 0158: 132 */ 0x70 /* 'p' */, 0x07, 0x00 /* (to 0x015F state 133) */, - 0x73 /* 's' */, 0x0E, 0x00 /* (to 0x0169 state 136) */, - 0x08, /* fail */ -/* pos 015f: 133 */ 0xF4 /* 't' -> */, -/* pos 0160: 134 */ 0x3A /* ':' */, 0x07, 0x00 /* (to 0x0167 state 135) */, - 0x2D /* '-' */, 0x59, 0x00 /* (to 0x01BC state 192) */, - 0x08, /* fail */ -/* pos 0167: 135 */ 0x00, 0x11 /* - terminal marker 17 - */, -/* pos 0169: 136 */ 0xF3 /* 's' -> */, -/* pos 016a: 137 */ 0xAD /* '-' -> */, -/* pos 016b: 138 */ 0xE3 /* 'c' -> */, -/* pos 016c: 139 */ 0xEF /* 'o' -> */, -/* pos 016d: 140 */ 0xEE /* 'n' -> */, -/* pos 016e: 141 */ 0xF4 /* 't' -> */, -/* pos 016f: 142 */ 0xF2 /* 'r' -> */, -/* pos 0170: 143 */ 0xEF /* 'o' -> */, -/* pos 0171: 144 */ 0xEC /* 'l' -> */, -/* pos 0172: 145 */ 0xAD /* '-' -> */, -/* pos 0173: 146 */ 0x72 /* 'r' */, 0x07, 0x00 /* (to 0x017A state 147) */, - 0x61 /* 'a' */, 0x51, 0x01 /* (to 0x02C7 state 345) */, - 0x08, /* fail */ -/* pos 017a: 147 */ 0xE5 /* 'e' -> */, -/* pos 017b: 148 */ 0xF1 /* 'q' -> */, -/* pos 017c: 149 */ 0xF5 /* 'u' -> */, -/* pos 017d: 150 */ 0xE5 /* 'e' -> */, -/* pos 017e: 151 */ 0xF3 /* 's' -> */, -/* pos 017f: 152 */ 0xF4 /* 't' -> */, -/* pos 0180: 153 */ 0xAD /* '-' -> */, -/* pos 0181: 154 */ 0xE8 /* 'h' -> */, -/* pos 0182: 155 */ 0xE5 /* 'e' -> */, -/* pos 0183: 156 */ 0xE1 /* 'a' -> */, -/* pos 0184: 157 */ 0xE4 /* 'd' -> */, -/* pos 0185: 158 */ 0xE5 /* 'e' -> */, -/* pos 0186: 159 */ 0xF2 /* 'r' -> */, -/* pos 0187: 160 */ 0xF3 /* 's' -> */, -/* pos 0188: 161 */ 0xBA /* ':' -> */, -/* pos 0189: 162 */ 0x00, 0x12 /* - terminal marker 18 - */, -/* pos 018b: 163 */ 0xE6 /* 'f' -> */, -/* pos 018c: 164 */ 0xAD /* '-' -> */, -/* pos 018d: 165 */ 0x6D /* 'm' */, 0x0D, 0x00 /* (to 0x019A state 166) */, - 0x6E /* 'n' */, 0x20, 0x00 /* (to 0x01B0 state 181) */, - 0x72 /* 'r' */, 0xA7, 0x01 /* (to 0x033A state 435) */, - 0x75 /* 'u' */, 0xAB, 0x01 /* (to 0x0341 state 441) */, - 0x08, /* fail */ -/* pos 019a: 166 */ 0x6F /* 'o' */, 0x07, 0x00 /* (to 0x01A1 state 167) */, - 0x61 /* 'a' */, 0x97, 0x01 /* (to 0x0334 state 430) */, - 0x08, /* fail */ -/* pos 01a1: 167 */ 0xE4 /* 'd' -> */, -/* pos 01a2: 168 */ 0xE9 /* 'i' -> */, -/* pos 01a3: 169 */ 0xE6 /* 'f' -> */, -/* pos 01a4: 170 */ 0xE9 /* 'i' -> */, -/* pos 01a5: 171 */ 0xE5 /* 'e' -> */, -/* pos 01a6: 172 */ 0xE4 /* 'd' -> */, -/* pos 01a7: 173 */ 0xAD /* '-' -> */, -/* pos 01a8: 174 */ 0xF3 /* 's' -> */, -/* pos 01a9: 175 */ 0xE9 /* 'i' -> */, -/* pos 01aa: 176 */ 0xEE /* 'n' -> */, -/* pos 01ab: 177 */ 0xE3 /* 'c' -> */, -/* pos 01ac: 178 */ 0xE5 /* 'e' -> */, -/* pos 01ad: 179 */ 0xBA /* ':' -> */, -/* pos 01ae: 180 */ 0x00, 0x13 /* - terminal marker 19 - */, -/* pos 01b0: 181 */ 0xEF /* 'o' -> */, -/* pos 01b1: 182 */ 0xEE /* 'n' -> */, -/* pos 01b2: 183 */ 0xE5 /* 'e' -> */, -/* pos 01b3: 184 */ 0xAD /* '-' -> */, -/* pos 01b4: 185 */ 0xED /* 'm' -> */, -/* pos 01b5: 186 */ 0xE1 /* 'a' -> */, -/* pos 01b6: 187 */ 0xF4 /* 't' -> */, -/* pos 01b7: 188 */ 0xE3 /* 'c' -> */, -/* pos 01b8: 189 */ 0xE8 /* 'h' -> */, -/* pos 01b9: 190 */ 0xBA /* ':' -> */, -/* pos 01ba: 191 */ 0x00, 0x14 /* - terminal marker 20 - */, -/* pos 01bc: 192 */ 0x65 /* 'e' */, 0x0D, 0x00 /* (to 0x01C9 state 193) */, - 0x6C /* 'l' */, 0x14, 0x00 /* (to 0x01D3 state 202) */, - 0x63 /* 'c' */, 0xF4, 0x00 /* (to 0x02B6 state 330) */, - 0x72 /* 'r' */, 0xFA, 0x00 /* (to 0x02BF state 338) */, - 0x08, /* fail */ -/* pos 01c9: 193 */ 0xEE /* 'n' -> */, -/* pos 01ca: 194 */ 0xE3 /* 'c' -> */, -/* pos 01cb: 195 */ 0xEF /* 'o' -> */, -/* pos 01cc: 196 */ 0xE4 /* 'd' -> */, -/* pos 01cd: 197 */ 0xE9 /* 'i' -> */, -/* pos 01ce: 198 */ 0xEE /* 'n' -> */, -/* pos 01cf: 199 */ 0xE7 /* 'g' -> */, -/* pos 01d0: 200 */ 0xBA /* ':' -> */, -/* pos 01d1: 201 */ 0x00, 0x15 /* - terminal marker 21 - */, -/* pos 01d3: 202 */ 0xE1 /* 'a' -> */, -/* pos 01d4: 203 */ 0xEE /* 'n' -> */, -/* pos 01d5: 204 */ 0xE7 /* 'g' -> */, -/* pos 01d6: 205 */ 0xF5 /* 'u' -> */, -/* pos 01d7: 206 */ 0xE1 /* 'a' -> */, -/* pos 01d8: 207 */ 0xE7 /* 'g' -> */, -/* pos 01d9: 208 */ 0xE5 /* 'e' -> */, -/* pos 01da: 209 */ 0xBA /* ':' -> */, -/* pos 01db: 210 */ 0x00, 0x16 /* - terminal marker 22 - */, -/* pos 01dd: 211 */ 0x61 /* 'a' */, 0x07, 0x00 /* (to 0x01E4 state 212) */, - 0x6F /* 'o' */, 0xA7, 0x01 /* (to 0x0387 state 497) */, - 0x08, /* fail */ -/* pos 01e4: 212 */ 0xE7 /* 'g' -> */, -/* pos 01e5: 213 */ 0xED /* 'm' -> */, -/* pos 01e6: 214 */ 0xE1 /* 'a' -> */, -/* pos 01e7: 215 */ 0xBA /* ':' -> */, -/* pos 01e8: 216 */ 0x00, 0x17 /* - terminal marker 23 - */, -/* pos 01ea: 217 */ 0xE3 /* 'c' -> */, -/* pos 01eb: 218 */ 0xE8 /* 'h' -> */, -/* pos 01ec: 219 */ 0xE5 /* 'e' -> */, -/* pos 01ed: 220 */ 0xAD /* '-' -> */, -/* pos 01ee: 221 */ 0xE3 /* 'c' -> */, -/* pos 01ef: 222 */ 0xEF /* 'o' -> */, -/* pos 01f0: 223 */ 0xEE /* 'n' -> */, -/* pos 01f1: 224 */ 0xF4 /* 't' -> */, -/* pos 01f2: 225 */ 0xF2 /* 'r' -> */, -/* pos 01f3: 226 */ 0xEF /* 'o' -> */, -/* pos 01f4: 227 */ 0xEC /* 'l' -> */, -/* pos 01f5: 228 */ 0xBA /* ':' -> */, -/* pos 01f6: 229 */ 0x00, 0x18 /* - terminal marker 24 - */, -/* pos 01f8: 230 */ 0xF4 /* 't' -> */, -/* pos 01f9: 231 */ 0xE8 /* 'h' -> */, -/* pos 01fa: 232 */ 0xEF /* 'o' -> */, -/* pos 01fb: 233 */ 0xF2 /* 'r' -> */, -/* pos 01fc: 234 */ 0xE9 /* 'i' -> */, -/* pos 01fd: 235 */ 0xFA /* 'z' -> */, -/* pos 01fe: 236 */ 0xE1 /* 'a' -> */, -/* pos 01ff: 237 */ 0xF4 /* 't' -> */, -/* pos 0200: 238 */ 0xE9 /* 'i' -> */, -/* pos 0201: 239 */ 0xEF /* 'o' -> */, -/* pos 0202: 240 */ 0xEE /* 'n' -> */, -/* pos 0203: 241 */ 0xBA /* ':' -> */, -/* pos 0204: 242 */ 0x00, 0x19 /* - terminal marker 25 - */, -/* pos 0206: 243 */ 0xEB /* 'k' -> */, -/* pos 0207: 244 */ 0xE9 /* 'i' -> */, -/* pos 0208: 245 */ 0xE5 /* 'e' -> */, -/* pos 0209: 246 */ 0xBA /* ':' -> */, -/* pos 020a: 247 */ 0x00, 0x1A /* - terminal marker 26 - */, -/* pos 020c: 248 */ 0xE5 /* 'e' -> */, -/* pos 020d: 249 */ 0xEE /* 'n' -> */, +/* pos 006d: 16 */ 0x6E /* 'n' */, 0x07, 0x00 /* (to 0x0074 state 17) */, + 0x6F /* 'o' */, 0xED, 0x00 /* (to 0x015D state 138) */, + 0x08, /* fail */ +/* pos 0074: 17 */ 0x6E /* 'n' */, 0x07, 0x00 /* (to 0x007B state 18) */, + 0x74 /* 't' */, 0xEC, 0x00 /* (to 0x0163 state 143) */, + 0x08, /* fail */ +/* pos 007b: 18 */ 0xE5 /* 'e' -> */, +/* pos 007c: 19 */ 0xE3 /* 'c' -> */, +/* pos 007d: 20 */ 0xF4 /* 't' -> */, +/* pos 007e: 21 */ 0x69 /* 'i' */, 0x07, 0x00 /* (to 0x0085 state 22) */, + 0x20 /* ' ' */, 0x53, 0x02 /* (to 0x02D4 state 380) */, + 0x08, /* fail */ +/* pos 0085: 22 */ 0xEF /* 'o' -> */, +/* pos 0086: 23 */ 0xEE /* 'n' -> */, +/* pos 0087: 24 */ 0xBA /* ':' -> */, +/* pos 0088: 25 */ 0x00, 0x03 /* - terminal marker 3 - */, +/* pos 008a: 26 */ 0x70 /* 'p' */, 0x0A, 0x00 /* (to 0x0094 state 27) */, + 0x72 /* 'r' */, 0x22, 0x02 /* (to 0x02AF state 355) */, + 0x73 /* 's' */, 0xEF, 0x02 /* (to 0x037F state 521) */, + 0x08, /* fail */ +/* pos 0094: 27 */ 0xE7 /* 'g' -> */, +/* pos 0095: 28 */ 0xF2 /* 'r' -> */, +/* pos 0096: 29 */ 0xE1 /* 'a' -> */, +/* pos 0097: 30 */ 0xE4 /* 'd' -> */, +/* pos 0098: 31 */ 0xE5 /* 'e' -> */, +/* pos 0099: 32 */ 0xBA /* ':' -> */, +/* pos 009a: 33 */ 0x00, 0x04 /* - terminal marker 4 - */, +/* pos 009c: 34 */ 0x72 /* 'r' */, 0x07, 0x00 /* (to 0x00A3 state 35) */, + 0x70 /* 'p' */, 0x48, 0x02 /* (to 0x02E7 state 396) */, + 0x08, /* fail */ +/* pos 00a3: 35 */ 0xE9 /* 'i' -> */, +/* pos 00a4: 36 */ 0xE7 /* 'g' -> */, +/* pos 00a5: 37 */ 0xE9 /* 'i' -> */, +/* pos 00a6: 38 */ 0xEE /* 'n' -> */, +/* pos 00a7: 39 */ 0xBA /* ':' -> */, +/* pos 00a8: 40 */ 0x00, 0x05 /* - terminal marker 5 - */, +/* pos 00aa: 41 */ 0x8A /* '.' -> */, +/* pos 00ab: 42 */ 0x00, 0x06 /* - terminal marker 6 - */, +/* pos 00ad: 43 */ 0xF4 /* 't' -> */, +/* pos 00ae: 44 */ 0xF0 /* 'p' -> */, +/* pos 00af: 45 */ 0x2F /* '/' */, 0x07, 0x00 /* (to 0x00B6 state 46) */, + 0x32 /* '2' */, 0x97, 0x03 /* (to 0x0449 state 663) */, + 0x08, /* fail */ +/* pos 00b6: 46 */ 0xB1 /* '1' -> */, +/* pos 00b7: 47 */ 0xAE /* '.' -> */, +/* pos 00b8: 48 */ 0x31 /* '1' */, 0x07, 0x00 /* (to 0x00BF state 49) */, + 0x30 /* '0' */, 0xFC, 0x01 /* (to 0x02B7 state 362) */, + 0x08, /* fail */ +/* pos 00bf: 49 */ 0xA0 /* ' ' -> */, +/* pos 00c0: 50 */ 0x00, 0x07 /* - terminal marker 7 - */, +/* pos 00c2: 51 */ 0x63 /* 'c' */, 0x0D, 0x00 /* (to 0x00CF state 52) */, + 0x75 /* 'u' */, 0x8A, 0x00 /* (to 0x014F state 125) */, + 0x67 /* 'g' */, 0xE7, 0x00 /* (to 0x01AF state 178) */, + 0x6C /* 'l' */, 0xE8, 0x00 /* (to 0x01B3 state 181) */, + 0x08, /* fail */ +/* pos 00cf: 52 */ 0xE3 /* 'c' -> */, +/* pos 00d0: 53 */ 0xE5 /* 'e' -> */, +/* pos 00d1: 54 */ 0x70 /* 'p' */, 0x07, 0x00 /* (to 0x00D8 state 55) */, + 0x73 /* 's' */, 0x1B, 0x02 /* (to 0x02EF state 403) */, + 0x08, /* fail */ +/* pos 00d8: 55 */ 0xF4 /* 't' -> */, +/* pos 00d9: 56 */ 0x3A /* ':' */, 0x07, 0x00 /* (to 0x00E0 state 57) */, + 0x2D /* '-' */, 0x37, 0x00 /* (to 0x0113 state 87) */, + 0x08, /* fail */ +/* pos 00e0: 57 */ 0x00, 0x09 /* - terminal marker 9 - */, +/* pos 00e2: 58 */ 0xE6 /* 'f' -> */, +/* pos 00e3: 59 */ 0xAD /* '-' -> */, +/* pos 00e4: 60 */ 0x6D /* 'm' */, 0x0D, 0x00 /* (to 0x00F1 state 61) */, + 0x6E /* 'n' */, 0x20, 0x00 /* (to 0x0107 state 76) */, + 0x72 /* 'r' */, 0x2A, 0x01 /* (to 0x0214 state 255) */, + 0x75 /* 'u' */, 0x2E, 0x01 /* (to 0x021B state 261) */, + 0x08, /* fail */ +/* pos 00f1: 61 */ 0x6F /* 'o' */, 0x07, 0x00 /* (to 0x00F8 state 62) */, + 0x61 /* 'a' */, 0x1A, 0x01 /* (to 0x020E state 250) */, + 0x08, /* fail */ +/* pos 00f8: 62 */ 0xE4 /* 'd' -> */, +/* pos 00f9: 63 */ 0xE9 /* 'i' -> */, +/* pos 00fa: 64 */ 0xE6 /* 'f' -> */, +/* pos 00fb: 65 */ 0xE9 /* 'i' -> */, +/* pos 00fc: 66 */ 0xE5 /* 'e' -> */, +/* pos 00fd: 67 */ 0xE4 /* 'd' -> */, +/* pos 00fe: 68 */ 0xAD /* '-' -> */, +/* pos 00ff: 69 */ 0xF3 /* 's' -> */, +/* pos 0100: 70 */ 0xE9 /* 'i' -> */, +/* pos 0101: 71 */ 0xEE /* 'n' -> */, +/* pos 0102: 72 */ 0xE3 /* 'c' -> */, +/* pos 0103: 73 */ 0xE5 /* 'e' -> */, +/* pos 0104: 74 */ 0xBA /* ':' -> */, +/* pos 0105: 75 */ 0x00, 0x0A /* - terminal marker 10 - */, +/* pos 0107: 76 */ 0xEF /* 'o' -> */, +/* pos 0108: 77 */ 0xEE /* 'n' -> */, +/* pos 0109: 78 */ 0xE5 /* 'e' -> */, +/* pos 010a: 79 */ 0xAD /* '-' -> */, +/* pos 010b: 80 */ 0xED /* 'm' -> */, +/* pos 010c: 81 */ 0xE1 /* 'a' -> */, +/* pos 010d: 82 */ 0xF4 /* 't' -> */, +/* pos 010e: 83 */ 0xE3 /* 'c' -> */, +/* pos 010f: 84 */ 0xE8 /* 'h' -> */, +/* pos 0110: 85 */ 0xBA /* ':' -> */, +/* pos 0111: 86 */ 0x00, 0x0B /* - terminal marker 11 - */, +/* pos 0113: 87 */ 0x65 /* 'e' */, 0x0D, 0x00 /* (to 0x0120 state 88) */, + 0x6C /* 'l' */, 0x14, 0x00 /* (to 0x012A state 97) */, + 0x72 /* 'r' */, 0x8E, 0x00 /* (to 0x01A7 state 171) */, + 0x63 /* 'c' */, 0xFB, 0x01 /* (to 0x0317 state 435) */, + 0x08, /* fail */ +/* pos 0120: 88 */ 0xEE /* 'n' -> */, +/* pos 0121: 89 */ 0xE3 /* 'c' -> */, +/* pos 0122: 90 */ 0xEF /* 'o' -> */, +/* pos 0123: 91 */ 0xE4 /* 'd' -> */, +/* pos 0124: 92 */ 0xE9 /* 'i' -> */, +/* pos 0125: 93 */ 0xEE /* 'n' -> */, +/* pos 0126: 94 */ 0xE7 /* 'g' -> */, +/* pos 0127: 95 */ 0xBA /* ':' -> */, +/* pos 0128: 96 */ 0x00, 0x0C /* - terminal marker 12 - */, +/* pos 012a: 97 */ 0xE1 /* 'a' -> */, +/* pos 012b: 98 */ 0xEE /* 'n' -> */, +/* pos 012c: 99 */ 0xE7 /* 'g' -> */, +/* pos 012d: 100 */ 0xF5 /* 'u' -> */, +/* pos 012e: 101 */ 0xE1 /* 'a' -> */, +/* pos 012f: 102 */ 0xE7 /* 'g' -> */, +/* pos 0130: 103 */ 0xE5 /* 'e' -> */, +/* pos 0131: 104 */ 0xBA /* ':' -> */, +/* pos 0132: 105 */ 0x00, 0x0D /* - terminal marker 13 - */, +/* pos 0134: 106 */ 0x61 /* 'a' */, 0x07, 0x00 /* (to 0x013B state 107) */, + 0x6F /* 'o' */, 0x05, 0x02 /* (to 0x033C state 469) */, + 0x08, /* fail */ +/* pos 013b: 107 */ 0xE7 /* 'g' -> */, +/* pos 013c: 108 */ 0xED /* 'm' -> */, +/* pos 013d: 109 */ 0xE1 /* 'a' -> */, +/* pos 013e: 110 */ 0xBA /* ':' -> */, +/* pos 013f: 111 */ 0x00, 0x0E /* - terminal marker 14 - */, +/* pos 0141: 112 */ 0xE3 /* 'c' -> */, +/* pos 0142: 113 */ 0xE8 /* 'h' -> */, +/* pos 0143: 114 */ 0xE5 /* 'e' -> */, +/* pos 0144: 115 */ 0xAD /* '-' -> */, +/* pos 0145: 116 */ 0xE3 /* 'c' -> */, +/* pos 0146: 117 */ 0xEF /* 'o' -> */, +/* pos 0147: 118 */ 0xEE /* 'n' -> */, +/* pos 0148: 119 */ 0xF4 /* 't' -> */, +/* pos 0149: 120 */ 0xF2 /* 'r' -> */, +/* pos 014a: 121 */ 0xEF /* 'o' -> */, +/* pos 014b: 122 */ 0xEC /* 'l' -> */, +/* pos 014c: 123 */ 0xBA /* ':' -> */, +/* pos 014d: 124 */ 0x00, 0x0F /* - terminal marker 15 - */, +/* pos 014f: 125 */ 0xF4 /* 't' -> */, +/* pos 0150: 126 */ 0xE8 /* 'h' -> */, +/* pos 0151: 127 */ 0xEF /* 'o' -> */, +/* pos 0152: 128 */ 0xF2 /* 'r' -> */, +/* pos 0153: 129 */ 0xE9 /* 'i' -> */, +/* pos 0154: 130 */ 0xFA /* 'z' -> */, +/* pos 0155: 131 */ 0xE1 /* 'a' -> */, +/* pos 0156: 132 */ 0xF4 /* 't' -> */, +/* pos 0157: 133 */ 0xE9 /* 'i' -> */, +/* pos 0158: 134 */ 0xEF /* 'o' -> */, +/* pos 0159: 135 */ 0xEE /* 'n' -> */, +/* pos 015a: 136 */ 0xBA /* ':' -> */, +/* pos 015b: 137 */ 0x00, 0x10 /* - terminal marker 16 - */, +/* pos 015d: 138 */ 0xEB /* 'k' -> */, +/* pos 015e: 139 */ 0xE9 /* 'i' -> */, +/* pos 015f: 140 */ 0xE5 /* 'e' -> */, +/* pos 0160: 141 */ 0xBA /* ':' -> */, +/* pos 0161: 142 */ 0x00, 0x11 /* - terminal marker 17 - */, +/* pos 0163: 143 */ 0xE5 /* 'e' -> */, +/* pos 0164: 144 */ 0xEE /* 'n' -> */, +/* pos 0165: 145 */ 0xF4 /* 't' -> */, +/* pos 0166: 146 */ 0xAD /* '-' -> */, +/* pos 0167: 147 */ 0x6C /* 'l' */, 0x10, 0x00 /* (to 0x0177 state 148) */, + 0x74 /* 't' */, 0x1E, 0x00 /* (to 0x0188 state 155) */, + 0x64 /* 'd' */, 0x4C, 0x00 /* (to 0x01B9 state 186) */, + 0x65 /* 'e' */, 0x56, 0x00 /* (to 0x01C6 state 198) */, + 0x72 /* 'r' */, 0x6F, 0x00 /* (to 0x01E2 state 223) */, + 0x08, /* fail */ +/* pos 0177: 148 */ 0x65 /* 'e' */, 0x0A, 0x00 /* (to 0x0181 state 149) */, + 0x61 /* 'a' */, 0x56, 0x00 /* (to 0x01D0 state 207) */, + 0x6F /* 'o' */, 0x5C, 0x00 /* (to 0x01D9 state 215) */, + 0x08, /* fail */ +/* pos 0181: 149 */ 0xEE /* 'n' -> */, +/* pos 0182: 150 */ 0xE7 /* 'g' -> */, +/* pos 0183: 151 */ 0xF4 /* 't' -> */, +/* pos 0184: 152 */ 0xE8 /* 'h' -> */, +/* pos 0185: 153 */ 0xBA /* ':' -> */, +/* pos 0186: 154 */ 0x00, 0x12 /* - terminal marker 18 - */, +/* pos 0188: 155 */ 0xF9 /* 'y' -> */, +/* pos 0189: 156 */ 0xF0 /* 'p' -> */, +/* pos 018a: 157 */ 0xE5 /* 'e' -> */, +/* pos 018b: 158 */ 0xBA /* ':' -> */, +/* pos 018c: 159 */ 0x00, 0x13 /* - terminal marker 19 - */, +/* pos 018e: 160 */ 0x61 /* 'a' */, 0x07, 0x00 /* (to 0x0195 state 161) */, + 0x65 /* 'e' */, 0x23, 0x02 /* (to 0x03B4 state 562) */, + 0x08, /* fail */ +/* pos 0195: 161 */ 0xF4 /* 't' -> */, +/* pos 0196: 162 */ 0xE5 /* 'e' -> */, +/* pos 0197: 163 */ 0xBA /* ':' -> */, +/* pos 0198: 164 */ 0x00, 0x14 /* - terminal marker 20 - */, +/* pos 019a: 165 */ 0x61 /* 'a' */, 0x07, 0x00 /* (to 0x01A1 state 166) */, + 0x65 /* 'e' */, 0xB6, 0x00 /* (to 0x0253 state 304) */, + 0x08, /* fail */ +/* pos 01a1: 166 */ 0xEE /* 'n' -> */, +/* pos 01a2: 167 */ 0xE7 /* 'g' -> */, +/* pos 01a3: 168 */ 0xE5 /* 'e' -> */, +/* pos 01a4: 169 */ 0xBA /* ':' -> */, +/* pos 01a5: 170 */ 0x00, 0x15 /* - terminal marker 21 - */, +/* pos 01a7: 171 */ 0xE1 /* 'a' -> */, +/* pos 01a8: 172 */ 0xEE /* 'n' -> */, +/* pos 01a9: 173 */ 0xE7 /* 'g' -> */, +/* pos 01aa: 174 */ 0xE5 /* 'e' -> */, +/* pos 01ab: 175 */ 0xF3 /* 's' -> */, +/* pos 01ac: 176 */ 0xBA /* ':' -> */, +/* pos 01ad: 177 */ 0x00, 0x1D /* - terminal marker 29 - */, +/* pos 01af: 178 */ 0xE5 /* 'e' -> */, +/* pos 01b0: 179 */ 0xBA /* ':' -> */, +/* pos 01b1: 180 */ 0x00, 0x1F /* - terminal marker 31 - */, +/* pos 01b3: 181 */ 0xEC /* 'l' -> */, +/* pos 01b4: 182 */ 0xEF /* 'o' -> */, +/* pos 01b5: 183 */ 0xF7 /* 'w' -> */, +/* pos 01b6: 184 */ 0xBA /* ':' -> */, +/* pos 01b7: 185 */ 0x00, 0x20 /* - terminal marker 32 - */, +/* pos 01b9: 186 */ 0xE9 /* 'i' -> */, +/* pos 01ba: 187 */ 0xF3 /* 's' -> */, +/* pos 01bb: 188 */ 0xF0 /* 'p' -> */, +/* pos 01bc: 189 */ 0xEF /* 'o' -> */, +/* pos 01bd: 190 */ 0xF3 /* 's' -> */, +/* pos 01be: 191 */ 0xE9 /* 'i' -> */, +/* pos 01bf: 192 */ 0xF4 /* 't' -> */, +/* pos 01c0: 193 */ 0xE9 /* 'i' -> */, +/* pos 01c1: 194 */ 0xEF /* 'o' -> */, +/* pos 01c2: 195 */ 0xEE /* 'n' -> */, +/* pos 01c3: 196 */ 0xBA /* ':' -> */, +/* pos 01c4: 197 */ 0x00, 0x21 /* - terminal marker 33 - */, +/* pos 01c6: 198 */ 0xEE /* 'n' -> */, +/* pos 01c7: 199 */ 0xE3 /* 'c' -> */, +/* pos 01c8: 200 */ 0xEF /* 'o' -> */, +/* pos 01c9: 201 */ 0xE4 /* 'd' -> */, +/* pos 01ca: 202 */ 0xE9 /* 'i' -> */, +/* pos 01cb: 203 */ 0xEE /* 'n' -> */, +/* pos 01cc: 204 */ 0xE7 /* 'g' -> */, +/* pos 01cd: 205 */ 0xBA /* ':' -> */, +/* pos 01ce: 206 */ 0x00, 0x22 /* - terminal marker 34 - */, +/* pos 01d0: 207 */ 0xEE /* 'n' -> */, +/* pos 01d1: 208 */ 0xE7 /* 'g' -> */, +/* pos 01d2: 209 */ 0xF5 /* 'u' -> */, +/* pos 01d3: 210 */ 0xE1 /* 'a' -> */, +/* pos 01d4: 211 */ 0xE7 /* 'g' -> */, +/* pos 01d5: 212 */ 0xE5 /* 'e' -> */, +/* pos 01d6: 213 */ 0xBA /* ':' -> */, +/* pos 01d7: 214 */ 0x00, 0x23 /* - terminal marker 35 - */, +/* pos 01d9: 215 */ 0xE3 /* 'c' -> */, +/* pos 01da: 216 */ 0xE1 /* 'a' -> */, +/* pos 01db: 217 */ 0xF4 /* 't' -> */, +/* pos 01dc: 218 */ 0xE9 /* 'i' -> */, +/* pos 01dd: 219 */ 0xEF /* 'o' -> */, +/* pos 01de: 220 */ 0xEE /* 'n' -> */, +/* pos 01df: 221 */ 0xBA /* ':' -> */, +/* pos 01e0: 222 */ 0x00, 0x24 /* - terminal marker 36 - */, +/* pos 01e2: 223 */ 0xE1 /* 'a' -> */, +/* pos 01e3: 224 */ 0xEE /* 'n' -> */, +/* pos 01e4: 225 */ 0xE7 /* 'g' -> */, +/* pos 01e5: 226 */ 0xE5 /* 'e' -> */, +/* pos 01e6: 227 */ 0xBA /* ':' -> */, +/* pos 01e7: 228 */ 0x00, 0x25 /* - terminal marker 37 - */, +/* pos 01e9: 229 */ 0x74 /* 't' */, 0x07, 0x00 /* (to 0x01F0 state 230) */, + 0x78 /* 'x' */, 0x09, 0x00 /* (to 0x01F5 state 234) */, + 0x08, /* fail */ +/* pos 01f0: 230 */ 0xE1 /* 'a' -> */, +/* pos 01f1: 231 */ 0xE7 /* 'g' -> */, +/* pos 01f2: 232 */ 0xBA /* ':' -> */, +/* pos 01f3: 233 */ 0x00, 0x26 /* - terminal marker 38 - */, +/* pos 01f5: 234 */ 0xF0 /* 'p' -> */, +/* pos 01f6: 235 */ 0x65 /* 'e' */, 0x07, 0x00 /* (to 0x01FD state 236) */, + 0x69 /* 'i' */, 0x09, 0x00 /* (to 0x0202 state 240) */, + 0x08, /* fail */ +/* pos 01fd: 236 */ 0xE3 /* 'c' -> */, +/* pos 01fe: 237 */ 0xF4 /* 't' -> */, +/* pos 01ff: 238 */ 0xBA /* ':' -> */, +/* pos 0200: 239 */ 0x00, 0x27 /* - terminal marker 39 - */, +/* pos 0202: 240 */ 0xF2 /* 'r' -> */, +/* pos 0203: 241 */ 0xE5 /* 'e' -> */, +/* pos 0204: 242 */ 0xF3 /* 's' -> */, +/* pos 0205: 243 */ 0xBA /* ':' -> */, +/* pos 0206: 244 */ 0x00, 0x28 /* - terminal marker 40 - */, +/* pos 0208: 245 */ 0xF2 /* 'r' -> */, +/* pos 0209: 246 */ 0xEF /* 'o' -> */, +/* pos 020a: 247 */ 0xED /* 'm' -> */, +/* pos 020b: 248 */ 0xBA /* ':' -> */, +/* pos 020c: 249 */ 0x00, 0x29 /* - terminal marker 41 - */, +/* pos 020e: 250 */ 0xF4 /* 't' -> */, +/* pos 020f: 251 */ 0xE3 /* 'c' -> */, +/* pos 0210: 252 */ 0xE8 /* 'h' -> */, +/* pos 0211: 253 */ 0xBA /* ':' -> */, +/* pos 0212: 254 */ 0x00, 0x2A /* - terminal marker 42 - */, +/* pos 0214: 255 */ 0xE1 /* 'a' -> */, +/* pos 0215: 256 */ 0xEE /* 'n' -> */, +/* pos 0216: 257 */ 0xE7 /* 'g' -> */, +/* pos 0217: 258 */ 0xE5 /* 'e' -> */, +/* pos 0218: 259 */ 0xBA /* ':' -> */, +/* pos 0219: 260 */ 0x00, 0x2B /* - terminal marker 43 - */, +/* pos 021b: 261 */ 0xEE /* 'n' -> */, +/* pos 021c: 262 */ 0xED /* 'm' -> */, +/* pos 021d: 263 */ 0xEF /* 'o' -> */, +/* pos 021e: 264 */ 0xE4 /* 'd' -> */, +/* pos 021f: 265 */ 0xE9 /* 'i' -> */, +/* pos 0220: 266 */ 0xE6 /* 'f' -> */, +/* pos 0221: 267 */ 0xE9 /* 'i' -> */, +/* pos 0222: 268 */ 0xE5 /* 'e' -> */, +/* pos 0223: 269 */ 0xE4 /* 'd' -> */, +/* pos 0224: 270 */ 0xAD /* '-' -> */, +/* pos 0225: 271 */ 0xF3 /* 's' -> */, +/* pos 0226: 272 */ 0xE9 /* 'i' -> */, +/* pos 0227: 273 */ 0xEE /* 'n' -> */, +/* pos 0228: 274 */ 0xE3 /* 'c' -> */, +/* pos 0229: 275 */ 0xE5 /* 'e' -> */, +/* pos 022a: 276 */ 0xBA /* ':' -> */, +/* pos 022b: 277 */ 0x00, 0x2C /* - terminal marker 44 - */, +/* pos 022d: 278 */ 0x61 /* 'a' */, 0x0A, 0x00 /* (to 0x0237 state 279) */, + 0x69 /* 'i' */, 0x15, 0x00 /* (to 0x0245 state 292) */, + 0x6F /* 'o' */, 0x17, 0x00 /* (to 0x024A state 296) */, + 0x08, /* fail */ +/* pos 0237: 279 */ 0xF3 /* 's' -> */, +/* pos 0238: 280 */ 0xF4 /* 't' -> */, +/* pos 0239: 281 */ 0xAD /* '-' -> */, +/* pos 023a: 282 */ 0xED /* 'm' -> */, +/* pos 023b: 283 */ 0xEF /* 'o' -> */, +/* pos 023c: 284 */ 0xE4 /* 'd' -> */, +/* pos 023d: 285 */ 0xE9 /* 'i' -> */, +/* pos 023e: 286 */ 0xE6 /* 'f' -> */, +/* pos 023f: 287 */ 0xE9 /* 'i' -> */, +/* pos 0240: 288 */ 0xE5 /* 'e' -> */, +/* pos 0241: 289 */ 0xE4 /* 'd' -> */, +/* pos 0242: 290 */ 0xBA /* ':' -> */, +/* pos 0243: 291 */ 0x00, 0x2D /* - terminal marker 45 - */, +/* pos 0245: 292 */ 0xEE /* 'n' -> */, +/* pos 0246: 293 */ 0xEB /* 'k' -> */, +/* pos 0247: 294 */ 0xBA /* ':' -> */, +/* pos 0248: 295 */ 0x00, 0x2E /* - terminal marker 46 - */, +/* pos 024a: 296 */ 0xE3 /* 'c' -> */, +/* pos 024b: 297 */ 0xE1 /* 'a' -> */, +/* pos 024c: 298 */ 0xF4 /* 't' -> */, +/* pos 024d: 299 */ 0xE9 /* 'i' -> */, +/* pos 024e: 300 */ 0xEF /* 'o' -> */, +/* pos 024f: 301 */ 0xEE /* 'n' -> */, +/* pos 0250: 302 */ 0xBA /* ':' -> */, +/* pos 0251: 303 */ 0x00, 0x2F /* - terminal marker 47 - */, +/* pos 0253: 304 */ 0x66 /* 'f' */, 0x0A, 0x00 /* (to 0x025D state 305) */, + 0x74 /* 't' */, 0x14, 0x00 /* (to 0x026A state 311) */, + 0x70 /* 'p' */, 0x6F, 0x01 /* (to 0x03C8 state 578) */, + 0x08, /* fail */ +/* pos 025d: 305 */ 0x72 /* 'r' */, 0x07, 0x00 /* (to 0x0264 state 306) */, + 0x65 /* 'e' */, 0xB1, 0x00 /* (to 0x0311 state 430) */, + 0x08, /* fail */ +/* pos 0264: 306 */ 0xE5 /* 'e' -> */, +/* pos 0265: 307 */ 0xF3 /* 's' -> */, +/* pos 0266: 308 */ 0xE8 /* 'h' -> */, +/* pos 0267: 309 */ 0xBA /* ':' -> */, +/* pos 0268: 310 */ 0x00, 0x33 /* - terminal marker 51 - */, +/* pos 026a: 311 */ 0xF2 /* 'r' -> */, +/* pos 026b: 312 */ 0xF9 /* 'y' -> */, +/* pos 026c: 313 */ 0xAD /* '-' -> */, +/* pos 026d: 314 */ 0xE1 /* 'a' -> */, +/* pos 026e: 315 */ 0xE6 /* 'f' -> */, +/* pos 026f: 316 */ 0xF4 /* 't' -> */, +/* pos 0270: 317 */ 0xE5 /* 'e' -> */, +/* pos 0271: 318 */ 0xF2 /* 'r' -> */, +/* pos 0272: 319 */ 0xBA /* ':' -> */, +/* pos 0273: 320 */ 0x00, 0x34 /* - terminal marker 52 - */, +/* pos 0275: 321 */ 0x65 /* 'e' */, 0x07, 0x00 /* (to 0x027C state 322) */, + 0x74 /* 't' */, 0xED, 0x00 /* (to 0x0365 state 496) */, + 0x08, /* fail */ +/* pos 027c: 322 */ 0x72 /* 'r' */, 0x0A, 0x00 /* (to 0x0286 state 323) */, + 0x74 /* 't' */, 0x0D, 0x00 /* (to 0x028C state 328) */, + 0x63 /* 'c' */, 0x52, 0x01 /* (to 0x03D4 state 589) */, + 0x08, /* fail */ +/* pos 0286: 323 */ 0xF6 /* 'v' -> */, +/* pos 0287: 324 */ 0xE5 /* 'e' -> */, +/* pos 0288: 325 */ 0xF2 /* 'r' -> */, +/* pos 0289: 326 */ 0xBA /* ':' -> */, +/* pos 028a: 327 */ 0x00, 0x35 /* - terminal marker 53 - */, +/* pos 028c: 328 */ 0xAD /* '-' -> */, +/* pos 028d: 329 */ 0xE3 /* 'c' -> */, +/* pos 028e: 330 */ 0xEF /* 'o' -> */, +/* pos 028f: 331 */ 0xEF /* 'o' -> */, +/* pos 0290: 332 */ 0xEB /* 'k' -> */, +/* pos 0291: 333 */ 0xE9 /* 'i' -> */, +/* pos 0292: 334 */ 0xE5 /* 'e' -> */, +/* pos 0293: 335 */ 0xBA /* ':' -> */, +/* pos 0294: 336 */ 0x00, 0x36 /* - terminal marker 54 - */, +/* pos 0296: 337 */ 0x72 /* 'r' */, 0x07, 0x00 /* (to 0x029D state 338) */, + 0x65 /* 'e' */, 0x2C, 0x01 /* (to 0x03C5 state 576) */, + 0x08, /* fail */ +/* pos 029d: 338 */ 0xE1 /* 'a' -> */, +/* pos 029e: 339 */ 0xEE /* 'n' -> */, +/* pos 029f: 340 */ 0xF3 /* 's' -> */, +/* pos 02a0: 341 */ 0xE6 /* 'f' -> */, +/* pos 02a1: 342 */ 0xE5 /* 'e' -> */, +/* pos 02a2: 343 */ 0xF2 /* 'r' -> */, +/* pos 02a3: 344 */ 0xAD /* '-' -> */, +/* pos 02a4: 345 */ 0xE5 /* 'e' -> */, +/* pos 02a5: 346 */ 0xEE /* 'n' -> */, +/* pos 02a6: 347 */ 0xE3 /* 'c' -> */, +/* pos 02a7: 348 */ 0xEF /* 'o' -> */, +/* pos 02a8: 349 */ 0xE4 /* 'd' -> */, +/* pos 02a9: 350 */ 0xE9 /* 'i' -> */, +/* pos 02aa: 351 */ 0xEE /* 'n' -> */, +/* pos 02ab: 352 */ 0xE7 /* 'g' -> */, +/* pos 02ac: 353 */ 0xBA /* ':' -> */, +/* pos 02ad: 354 */ 0x00, 0x38 /* - terminal marker 56 - */, +/* pos 02af: 355 */ 0xE9 /* 'i' -> */, +/* pos 02b0: 356 */ 0xAD /* '-' -> */, +/* pos 02b1: 357 */ 0xE1 /* 'a' -> */, +/* pos 02b2: 358 */ 0xF2 /* 'r' -> */, +/* pos 02b3: 359 */ 0xE7 /* 'g' -> */, +/* pos 02b4: 360 */ 0xF3 /* 's' -> */, +/* pos 02b5: 361 */ 0x00, 0x3D /* - terminal marker 61 - */, +/* pos 02b7: 362 */ 0xA0 /* ' ' -> */, +/* pos 02b8: 363 */ 0x00, 0x3E /* - terminal marker 62 - */, +/* pos 02ba: 364 */ 0xAD /* '-' -> */, +/* pos 02bb: 365 */ 0x66 /* 'f' */, 0x0A, 0x00 /* (to 0x02C5 state 366) */, + 0x61 /* 'a' */, 0x1D, 0x00 /* (to 0x02DB state 385) */, + 0x72 /* 'r' */, 0xFB, 0x00 /* (to 0x03BC state 568) */, + 0x08, /* fail */ +/* pos 02c5: 366 */ 0xEF /* 'o' -> */, +/* pos 02c6: 367 */ 0xF2 /* 'r' -> */, +/* pos 02c7: 368 */ 0xF7 /* 'w' -> */, +/* pos 02c8: 369 */ 0xE1 /* 'a' -> */, +/* pos 02c9: 370 */ 0xF2 /* 'r' -> */, +/* pos 02ca: 371 */ 0xE4 /* 'd' -> */, +/* pos 02cb: 372 */ 0xE5 /* 'e' -> */, +/* pos 02cc: 373 */ 0xE4 /* 'd' -> */, +/* pos 02cd: 374 */ 0xAD /* '-' -> */, +/* pos 02ce: 375 */ 0xE6 /* 'f' -> */, +/* pos 02cf: 376 */ 0xEF /* 'o' -> */, +/* pos 02d0: 377 */ 0xF2 /* 'r' -> */, +/* pos 02d1: 378 */ 0xBA /* ':' -> */, +/* pos 02d2: 379 */ 0x00, 0x3F /* - terminal marker 63 - */, +/* pos 02d4: 380 */ 0x00, 0x40 /* - terminal marker 64 - */, +/* pos 02d6: 381 */ 0xE1 /* 'a' -> */, +/* pos 02d7: 382 */ 0xE4 /* 'd' -> */, +/* pos 02d8: 383 */ 0xA0 /* ' ' -> */, +/* pos 02d9: 384 */ 0x00, 0x41 /* - terminal marker 65 - */, +/* pos 02db: 385 */ 0xF5 /* 'u' -> */, +/* pos 02dc: 386 */ 0xF4 /* 't' -> */, +/* pos 02dd: 387 */ 0xE8 /* 'h' -> */, +/* pos 02de: 388 */ 0xAD /* '-' -> */, +/* pos 02df: 389 */ 0xF4 /* 't' -> */, +/* pos 02e0: 390 */ 0xEF /* 'o' -> */, +/* pos 02e1: 391 */ 0xEB /* 'k' -> */, +/* pos 02e2: 392 */ 0xE5 /* 'e' -> */, +/* pos 02e3: 393 */ 0xEE /* 'n' -> */, +/* pos 02e4: 394 */ 0xBA /* ':' -> */, +/* pos 02e5: 395 */ 0x00, 0x45 /* - terminal marker 69 - */, +/* pos 02e7: 396 */ 0xF4 /* 't' -> */, +/* pos 02e8: 397 */ 0xE9 /* 'i' -> */, +/* pos 02e9: 398 */ 0xEF /* 'o' -> */, +/* pos 02ea: 399 */ 0xEE /* 'n' -> */, +/* pos 02eb: 400 */ 0xF3 /* 's' -> */, +/* pos 02ec: 401 */ 0xA0 /* ' ' -> */, +/* pos 02ed: 402 */ 0x00, 0x02 /* - terminal marker 2 - */, +/* pos 02ef: 403 */ 0xF3 /* 's' -> */, +/* pos 02f0: 404 */ 0xAD /* '-' -> */, +/* pos 02f1: 405 */ 0xE3 /* 'c' -> */, +/* pos 02f2: 406 */ 0xEF /* 'o' -> */, +/* pos 02f3: 407 */ 0xEE /* 'n' -> */, +/* pos 02f4: 408 */ 0xF4 /* 't' -> */, +/* pos 02f5: 409 */ 0xF2 /* 'r' -> */, +/* pos 02f6: 410 */ 0xEF /* 'o' -> */, +/* pos 02f7: 411 */ 0xEC /* 'l' -> */, +/* pos 02f8: 412 */ 0xAD /* '-' -> */, +/* pos 02f9: 413 */ 0x72 /* 'r' */, 0x07, 0x00 /* (to 0x0300 state 414) */, + 0x61 /* 'a' */, 0x24, 0x00 /* (to 0x0320 state 443) */, + 0x08, /* fail */ +/* pos 0300: 414 */ 0xE5 /* 'e' -> */, +/* pos 0301: 415 */ 0xF1 /* 'q' -> */, +/* pos 0302: 416 */ 0xF5 /* 'u' -> */, +/* pos 0303: 417 */ 0xE5 /* 'e' -> */, +/* pos 0304: 418 */ 0xF3 /* 's' -> */, +/* pos 0305: 419 */ 0xF4 /* 't' -> */, +/* pos 0306: 420 */ 0xAD /* '-' -> */, +/* pos 0307: 421 */ 0xE8 /* 'h' -> */, +/* pos 0308: 422 */ 0xE5 /* 'e' -> */, +/* pos 0309: 423 */ 0xE1 /* 'a' -> */, +/* pos 030a: 424 */ 0xE4 /* 'd' -> */, +/* pos 030b: 425 */ 0xE5 /* 'e' -> */, +/* pos 030c: 426 */ 0xF2 /* 'r' -> */, +/* pos 030d: 427 */ 0xF3 /* 's' -> */, +/* pos 030e: 428 */ 0xBA /* ':' -> */, +/* pos 030f: 429 */ 0x00, 0x11 /* - terminal marker 17 - */, +/* pos 0311: 430 */ 0xF2 /* 'r' -> */, +/* pos 0312: 431 */ 0xE5 /* 'e' -> */, +/* pos 0313: 432 */ 0xF2 /* 'r' -> */, +/* pos 0314: 433 */ 0xBA /* ':' -> */, +/* pos 0315: 434 */ 0x00, 0x16 /* - terminal marker 22 - */, +/* pos 0317: 435 */ 0xE8 /* 'h' -> */, +/* pos 0318: 436 */ 0xE1 /* 'a' -> */, +/* pos 0319: 437 */ 0xF2 /* 'r' -> */, +/* pos 031a: 438 */ 0xF3 /* 's' -> */, +/* pos 031b: 439 */ 0xE5 /* 'e' -> */, +/* pos 031c: 440 */ 0xF4 /* 't' -> */, +/* pos 031d: 441 */ 0xBA /* ':' -> */, +/* pos 031e: 442 */ 0x00, 0x1C /* - terminal marker 28 - */, +/* pos 0320: 443 */ 0xEC /* 'l' -> */, +/* pos 0321: 444 */ 0xEC /* 'l' -> */, +/* pos 0322: 445 */ 0xEF /* 'o' -> */, +/* pos 0323: 446 */ 0xF7 /* 'w' -> */, +/* pos 0324: 447 */ 0xAD /* '-' -> */, +/* pos 0325: 448 */ 0xEF /* 'o' -> */, +/* pos 0326: 449 */ 0xF2 /* 'r' -> */, +/* pos 0327: 450 */ 0xE9 /* 'i' -> */, +/* pos 0328: 451 */ 0xE7 /* 'g' -> */, +/* pos 0329: 452 */ 0xE9 /* 'i' -> */, +/* pos 032a: 453 */ 0xEE /* 'n' -> */, +/* pos 032b: 454 */ 0xBA /* ':' -> */, +/* pos 032c: 455 */ 0x00, 0x1E /* - terminal marker 30 - */, +/* pos 032e: 456 */ 0xE1 /* 'a' -> */, +/* pos 032f: 457 */ 0xF8 /* 'x' -> */, +/* pos 0330: 458 */ 0xAD /* '-' -> */, +/* pos 0331: 459 */ 0xE6 /* 'f' -> */, +/* pos 0332: 460 */ 0xEF /* 'o' -> */, +/* pos 0333: 461 */ 0xF2 /* 'r' -> */, +/* pos 0334: 462 */ 0xF7 /* 'w' -> */, +/* pos 0335: 463 */ 0xE1 /* 'a' -> */, +/* pos 0336: 464 */ 0xF2 /* 'r' -> */, +/* pos 0337: 465 */ 0xE4 /* 'd' -> */, +/* pos 0338: 466 */ 0xF3 /* 's' -> */, +/* pos 0339: 467 */ 0xBA /* ':' -> */, +/* pos 033a: 468 */ 0x00, 0x30 /* - terminal marker 48 - */, +/* pos 033c: 469 */ 0xF8 /* 'x' -> */, +/* pos 033d: 470 */ 0xF9 /* 'y' -> */, +/* pos 033e: 471 */ 0x2D /* '-' */, 0x07, 0x00 /* (to 0x0345 state 472) */, + 0x20 /* ' ' */, 0x79, 0x00 /* (to 0x03BA state 567) */, + 0x08, /* fail */ +/* pos 0345: 472 */ 0xE1 /* 'a' -> */, +/* pos 0346: 473 */ 0xF5 /* 'u' -> */, +/* pos 0347: 474 */ 0xF4 /* 't' -> */, +/* pos 0348: 475 */ 0xE8 /* 'h' -> */, +/* pos 0349: 476 */ 0x65 /* 'e' */, 0x07, 0x00 /* (to 0x0350 state 477) */, + 0x6F /* 'o' */, 0x0E, 0x00 /* (to 0x035A state 486) */, + 0x08, /* fail */ +/* pos 0350: 477 */ 0xEE /* 'n' -> */, +/* pos 0351: 478 */ 0xF4 /* 't' -> */, +/* pos 0352: 479 */ 0xE9 /* 'i' -> */, +/* pos 0353: 480 */ 0xE3 /* 'c' -> */, +/* pos 0354: 481 */ 0xE1 /* 'a' -> */, +/* pos 0355: 482 */ 0xF4 /* 't' -> */, +/* pos 0356: 483 */ 0xE5 /* 'e' -> */, +/* pos 0357: 484 */ 0xBA /* ':' -> */, +/* pos 0358: 485 */ 0x00, 0x31 /* - terminal marker 49 - */, +/* pos 035a: 486 */ 0xF2 /* 'r' -> */, +/* pos 035b: 487 */ 0xE9 /* 'i' -> */, +/* pos 035c: 488 */ 0xFA /* 'z' -> */, +/* pos 035d: 489 */ 0xE1 /* 'a' -> */, +/* pos 035e: 490 */ 0xF4 /* 't' -> */, +/* pos 035f: 491 */ 0xE9 /* 'i' -> */, +/* pos 0360: 492 */ 0xEF /* 'o' -> */, +/* pos 0361: 493 */ 0xEE /* 'n' -> */, +/* pos 0362: 494 */ 0xBA /* ':' -> */, +/* pos 0363: 495 */ 0x00, 0x32 /* - terminal marker 50 - */, +/* pos 0365: 496 */ 0xF2 /* 'r' -> */, +/* pos 0366: 497 */ 0xE9 /* 'i' -> */, +/* pos 0367: 498 */ 0xE3 /* 'c' -> */, +/* pos 0368: 499 */ 0xF4 /* 't' -> */, +/* pos 0369: 500 */ 0xAD /* '-' -> */, +/* pos 036a: 501 */ 0xF4 /* 't' -> */, +/* pos 036b: 502 */ 0xF2 /* 'r' -> */, +/* pos 036c: 503 */ 0xE1 /* 'a' -> */, +/* pos 036d: 504 */ 0xEE /* 'n' -> */, +/* pos 036e: 505 */ 0xF3 /* 's' -> */, +/* pos 036f: 506 */ 0xF0 /* 'p' -> */, +/* pos 0370: 507 */ 0xEF /* 'o' -> */, +/* pos 0371: 508 */ 0xF2 /* 'r' -> */, +/* pos 0372: 509 */ 0xF4 /* 't' -> */, +/* pos 0373: 510 */ 0xAD /* '-' -> */, +/* pos 0374: 511 */ 0xF3 /* 's' -> */, +/* pos 0375: 512 */ 0xE5 /* 'e' -> */, +/* pos 0376: 513 */ 0xE3 /* 'c' -> */, +/* pos 0377: 514 */ 0xF5 /* 'u' -> */, +/* pos 0378: 515 */ 0xF2 /* 'r' -> */, +/* pos 0379: 516 */ 0xE9 /* 'i' -> */, +/* pos 037a: 517 */ 0xF4 /* 't' -> */, +/* pos 037b: 518 */ 0xF9 /* 'y' -> */, +/* pos 037c: 519 */ 0xBA /* ':' -> */, +/* pos 037d: 520 */ 0x00, 0x37 /* - terminal marker 55 - */, +/* pos 037f: 521 */ 0xE5 /* 'e' -> */, +/* pos 0380: 522 */ 0xF2 /* 'r' -> */, +/* pos 0381: 523 */ 0xAD /* '-' -> */, +/* pos 0382: 524 */ 0xE1 /* 'a' -> */, +/* pos 0383: 525 */ 0xE7 /* 'g' -> */, +/* pos 0384: 526 */ 0xE5 /* 'e' -> */, +/* pos 0385: 527 */ 0xEE /* 'n' -> */, +/* pos 0386: 528 */ 0xF4 /* 't' -> */, +/* pos 0387: 529 */ 0xBA /* ':' -> */, +/* pos 0388: 530 */ 0x00, 0x39 /* - terminal marker 57 - */, +/* pos 038a: 531 */ 0x61 /* 'a' */, 0x07, 0x00 /* (to 0x0391 state 532) */, + 0x69 /* 'i' */, 0x09, 0x00 /* (to 0x0396 state 536) */, + 0x08, /* fail */ +/* pos 0391: 532 */ 0xF2 /* 'r' -> */, +/* pos 0392: 533 */ 0xF9 /* 'y' -> */, +/* pos 0393: 534 */ 0xBA /* ':' -> */, +/* pos 0394: 535 */ 0x00, 0x3A /* - terminal marker 58 - */, +/* pos 0396: 536 */ 0xE1 /* 'a' -> */, +/* pos 0397: 537 */ 0xBA /* ':' -> */, +/* pos 0398: 538 */ 0x00, 0x3B /* - terminal marker 59 - */, +/* pos 039a: 539 */ 0xF7 /* 'w' -> */, +/* pos 039b: 540 */ 0xF7 /* 'w' -> */, +/* pos 039c: 541 */ 0xAD /* '-' -> */, +/* pos 039d: 542 */ 0xE1 /* 'a' -> */, +/* pos 039e: 543 */ 0xF5 /* 'u' -> */, +/* pos 039f: 544 */ 0xF4 /* 't' -> */, +/* pos 03a0: 545 */ 0xE8 /* 'h' -> */, +/* pos 03a1: 546 */ 0xE5 /* 'e' -> */, +/* pos 03a2: 547 */ 0xEE /* 'n' -> */, +/* pos 03a3: 548 */ 0xF4 /* 't' -> */, +/* pos 03a4: 549 */ 0xE9 /* 'i' -> */, +/* pos 03a5: 550 */ 0xE3 /* 'c' -> */, +/* pos 03a6: 551 */ 0xE1 /* 'a' -> */, +/* pos 03a7: 552 */ 0xF4 /* 't' -> */, +/* pos 03a8: 553 */ 0xE5 /* 'e' -> */, +/* pos 03a9: 554 */ 0xBA /* ':' -> */, +/* pos 03aa: 555 */ 0x00, 0x3C /* - terminal marker 60 - */, +/* pos 03ac: 556 */ 0xF4 /* 't' -> */, +/* pos 03ad: 557 */ 0xE3 /* 'c' -> */, +/* pos 03ae: 558 */ 0xE8 /* 'h' -> */, +/* pos 03af: 559 */ 0x00, 0x43 /* - terminal marker 67 - */, +/* pos 03b1: 560 */ 0xF4 /* 't' -> */, +/* pos 03b2: 561 */ 0x00, 0x44 /* - terminal marker 68 - */, +/* pos 03b4: 562 */ 0xEC /* 'l' -> */, +/* pos 03b5: 563 */ 0xE5 /* 'e' -> */, +/* pos 03b6: 564 */ 0xF4 /* 't' -> */, +/* pos 03b7: 565 */ 0xE5 /* 'e' -> */, +/* pos 03b8: 566 */ 0x00, 0x45 /* - terminal marker 69 - */, +/* pos 03ba: 567 */ 0x00, 0x47 /* - terminal marker 71 - */, +/* pos 03bc: 568 */ 0xE5 /* 'e' -> */, +/* pos 03bd: 569 */ 0xE1 /* 'a' -> */, +/* pos 03be: 570 */ 0xEC /* 'l' -> */, +/* pos 03bf: 571 */ 0xAD /* '-' -> */, +/* pos 03c0: 572 */ 0xE9 /* 'i' -> */, +/* pos 03c1: 573 */ 0xF0 /* 'p' -> */, +/* pos 03c2: 574 */ 0xBA /* ':' -> */, +/* pos 03c3: 575 */ 0x00, 0x48 /* - terminal marker 72 - */, +/* pos 03c5: 576 */ 0xBA /* ':' -> */, +/* pos 03c6: 577 */ 0x00, 0x42 /* - terminal marker 66 - */, +/* pos 03c8: 578 */ 0xEC /* 'l' -> */, +/* pos 03c9: 579 */ 0xE1 /* 'a' -> */, +/* pos 03ca: 580 */ 0xF9 /* 'y' -> */, +/* pos 03cb: 581 */ 0xAD /* '-' -> */, +/* pos 03cc: 582 */ 0xEE /* 'n' -> */, +/* pos 03cd: 583 */ 0xEF /* 'o' -> */, +/* pos 03ce: 584 */ 0xEE /* 'n' -> */, +/* pos 03cf: 585 */ 0xE3 /* 'c' -> */, +/* pos 03d0: 586 */ 0xE5 /* 'e' -> */, +/* pos 03d1: 587 */ 0xBA /* ':' -> */, +/* pos 03d2: 588 */ 0x00, 0x43 /* - terminal marker 67 - */, +/* pos 03d4: 589 */ 0xAD /* '-' -> */, +/* pos 03d5: 590 */ 0xF7 /* 'w' -> */, +/* pos 03d6: 591 */ 0xE5 /* 'e' -> */, +/* pos 03d7: 592 */ 0xE2 /* 'b' -> */, +/* pos 03d8: 593 */ 0xF3 /* 's' -> */, +/* pos 03d9: 594 */ 0xEF /* 'o' -> */, +/* pos 03da: 595 */ 0xE3 /* 'c' -> */, +/* pos 03db: 596 */ 0xEB /* 'k' -> */, +/* pos 03dc: 597 */ 0xE5 /* 'e' -> */, +/* pos 03dd: 598 */ 0xF4 /* 't' -> */, +/* pos 03de: 599 */ 0xAD /* '-' -> */, +/* pos 03df: 600 */ 0x64 /* 'd' */, 0x19, 0x00 /* (to 0x03F8 state 601) */, + 0x65 /* 'e' */, 0x1D, 0x00 /* (to 0x03FF state 607) */, + 0x6B /* 'k' */, 0x26, 0x00 /* (to 0x040B state 618) */, + 0x70 /* 'p' */, 0x35, 0x00 /* (to 0x041D state 625) */, + 0x61 /* 'a' */, 0x3C, 0x00 /* (to 0x0427 state 634) */, + 0x6E /* 'n' */, 0x41, 0x00 /* (to 0x042F state 641) */, + 0x76 /* 'v' */, 0x47, 0x00 /* (to 0x0438 state 648) */, + 0x6F /* 'o' */, 0x4D, 0x00 /* (to 0x0441 state 656) */, + 0x08, /* fail */ +/* pos 03f8: 601 */ 0xF2 /* 'r' -> */, +/* pos 03f9: 602 */ 0xE1 /* 'a' -> */, +/* pos 03fa: 603 */ 0xE6 /* 'f' -> */, +/* pos 03fb: 604 */ 0xF4 /* 't' -> */, +/* pos 03fc: 605 */ 0xBA /* ':' -> */, +/* pos 03fd: 606 */ 0x00, 0x07 /* - terminal marker 7 - */, +/* pos 03ff: 607 */ 0xF8 /* 'x' -> */, +/* pos 0400: 608 */ 0xF4 /* 't' -> */, +/* pos 0401: 609 */ 0xE5 /* 'e' -> */, +/* pos 0402: 610 */ 0xEE /* 'n' -> */, +/* pos 0403: 611 */ 0xF3 /* 's' -> */, +/* pos 0404: 612 */ 0xE9 /* 'i' -> */, +/* pos 0405: 613 */ 0xEF /* 'o' -> */, +/* pos 0406: 614 */ 0xEE /* 'n' -> */, +/* pos 0407: 615 */ 0xF3 /* 's' -> */, +/* pos 0408: 616 */ 0xBA /* ':' -> */, +/* pos 0409: 617 */ 0x00, 0x09 /* - terminal marker 9 - */, +/* pos 040b: 618 */ 0xE5 /* 'e' -> */, +/* pos 040c: 619 */ 0xF9 /* 'y' -> */, +/* pos 040d: 620 */ 0x31 /* '1' */, 0x0A, 0x00 /* (to 0x0417 state 621) */, + 0x32 /* '2' */, 0x0A, 0x00 /* (to 0x041A state 623) */, + 0x3A /* ':' */, 0x23, 0x00 /* (to 0x0436 state 647) */, + 0x08, /* fail */ +/* pos 0417: 621 */ 0xBA /* ':' -> */, +/* pos 0418: 622 */ 0x00, 0x0A /* - terminal marker 10 - */, +/* pos 041a: 623 */ 0xBA /* ':' -> */, +/* pos 041b: 624 */ 0x00, 0x0B /* - terminal marker 11 - */, +/* pos 041d: 625 */ 0xF2 /* 'r' -> */, +/* pos 041e: 626 */ 0xEF /* 'o' -> */, +/* pos 041f: 627 */ 0xF4 /* 't' -> */, +/* pos 0420: 628 */ 0xEF /* 'o' -> */, +/* pos 0421: 629 */ 0xE3 /* 'c' -> */, +/* pos 0422: 630 */ 0xEF /* 'o' -> */, +/* pos 0423: 631 */ 0xEC /* 'l' -> */, +/* pos 0424: 632 */ 0xBA /* ':' -> */, +/* pos 0425: 633 */ 0x00, 0x0C /* - terminal marker 12 - */, +/* pos 0427: 634 */ 0xE3 /* 'c' -> */, +/* pos 0428: 635 */ 0xE3 /* 'c' -> */, +/* pos 0429: 636 */ 0xE5 /* 'e' -> */, +/* pos 042a: 637 */ 0xF0 /* 'p' -> */, +/* pos 042b: 638 */ 0xF4 /* 't' -> */, +/* pos 042c: 639 */ 0xBA /* ':' -> */, +/* pos 042d: 640 */ 0x00, 0x0D /* - terminal marker 13 - */, +/* pos 042f: 641 */ 0xEF /* 'o' -> */, +/* pos 0430: 642 */ 0xEE /* 'n' -> */, +/* pos 0431: 643 */ 0xE3 /* 'c' -> */, +/* pos 0432: 644 */ 0xE5 /* 'e' -> */, +/* pos 0433: 645 */ 0xBA /* ':' -> */, +/* pos 0434: 646 */ 0x00, 0x0E /* - terminal marker 14 - */, +/* pos 0436: 647 */ 0x00, 0x1F /* - terminal marker 31 - */, +/* pos 0438: 648 */ 0xE5 /* 'e' -> */, +/* pos 0439: 649 */ 0xF2 /* 'r' -> */, +/* pos 043a: 650 */ 0xF3 /* 's' -> */, +/* pos 043b: 651 */ 0xE9 /* 'i' -> */, +/* pos 043c: 652 */ 0xEF /* 'o' -> */, +/* pos 043d: 653 */ 0xEE /* 'n' -> */, +/* pos 043e: 654 */ 0xBA /* ':' -> */, +/* pos 043f: 655 */ 0x00, 0x20 /* - terminal marker 32 - */, +/* pos 0441: 656 */ 0xF2 /* 'r' -> */, +/* pos 0442: 657 */ 0xE9 /* 'i' -> */, +/* pos 0443: 658 */ 0xE7 /* 'g' -> */, +/* pos 0444: 659 */ 0xE9 /* 'i' -> */, +/* pos 0445: 660 */ 0xEE /* 'n' -> */, +/* pos 0446: 661 */ 0xBA /* ':' -> */, +/* pos 0447: 662 */ 0x00, 0x21 /* - terminal marker 33 - */, +/* pos 0449: 663 */ 0xAD /* '-' -> */, +/* pos 044a: 664 */ 0xF3 /* 's' -> */, +/* pos 044b: 665 */ 0xE5 /* 'e' -> */, +/* pos 044c: 666 */ 0xF4 /* 't' -> */, +/* pos 044d: 667 */ 0xF4 /* 't' -> */, +/* pos 044e: 668 */ 0xE9 /* 'i' -> */, +/* pos 044f: 669 */ 0xEE /* 'n' -> */, +/* pos 0450: 670 */ 0xE7 /* 'g' -> */, +/* pos 0451: 671 */ 0xF3 /* 's' -> */, +/* pos 0452: 672 */ 0xBA /* ':' -> */, +/* pos 0453: 673 */ 0x00, 0x08 /* - terminal marker 8 - */, +/* pos 0455: 674 */ 0x61 /* 'a' */, 0x0D, 0x00 /* (to 0x0462 state 675) */, + 0x6D /* 'm' */, 0x14, 0x00 /* (to 0x046C state 684) */, + 0x70 /* 'p' */, 0x18, 0x00 /* (to 0x0473 state 690) */, + 0x73 /* 's' */, 0x20, 0x00 /* (to 0x047E state 694) */, + 0x08, /* fail */ +/* pos 0462: 675 */ 0xF5 /* 'u' -> */, +/* pos 0463: 676 */ 0xF4 /* 't' -> */, +/* pos 0464: 677 */ 0xE8 /* 'h' -> */, +/* pos 0465: 678 */ 0xEF /* 'o' -> */, +/* pos 0466: 679 */ 0xF2 /* 'r' -> */, +/* pos 0467: 680 */ 0xE9 /* 'i' -> */, +/* pos 0468: 681 */ 0xF4 /* 't' -> */, +/* pos 0469: 682 */ 0xF9 /* 'y' -> */, +/* pos 046a: 683 */ 0x00, 0x17 /* - terminal marker 23 - */, +/* pos 046c: 684 */ 0xE5 /* 'e' -> */, +/* pos 046d: 685 */ 0xF4 /* 't' -> */, +/* pos 046e: 686 */ 0xE8 /* 'h' -> */, +/* pos 046f: 687 */ 0xEF /* 'o' -> */, +/* pos 0470: 688 */ 0xE4 /* 'd' -> */, +/* pos 0471: 689 */ 0x00, 0x18 /* - terminal marker 24 - */, +/* pos 0473: 690 */ 0x61 /* 'a' */, 0x07, 0x00 /* (to 0x047A state 691) */, + 0x72 /* 'r' */, 0x1B, 0x00 /* (to 0x0491 state 705) */, + 0x08, /* fail */ +/* pos 047a: 691 */ 0xF4 /* 't' -> */, +/* pos 047b: 692 */ 0xE8 /* 'h' -> */, +/* pos 047c: 693 */ 0x00, 0x19 /* - terminal marker 25 - */, +/* pos 047e: 694 */ 0x63 /* 'c' */, 0x07, 0x00 /* (to 0x0485 state 695) */, + 0x74 /* 't' */, 0x0A, 0x00 /* (to 0x048B state 700) */, + 0x08, /* fail */ +/* pos 0485: 695 */ 0xE8 /* 'h' -> */, +/* pos 0486: 696 */ 0xE5 /* 'e' -> */, +/* pos 0487: 697 */ 0xED /* 'm' -> */, +/* pos 0488: 698 */ 0xE5 /* 'e' -> */, +/* pos 0489: 699 */ 0x00, 0x1A /* - terminal marker 26 - */, +/* pos 048b: 700 */ 0xE1 /* 'a' -> */, +/* pos 048c: 701 */ 0xF4 /* 't' -> */, +/* pos 048d: 702 */ 0xF5 /* 'u' -> */, +/* pos 048e: 703 */ 0xF3 /* 's' -> */, +/* pos 048f: 704 */ 0x00, 0x1B /* - terminal marker 27 - */, +/* pos 0491: 705 */ 0xEF /* 'o' -> */, +/* pos 0492: 706 */ 0xF4 /* 't' -> */, +/* pos 0493: 707 */ 0xEF /* 'o' -> */, +/* pos 0494: 708 */ 0xE3 /* 'c' -> */, +/* pos 0495: 709 */ 0xEF /* 'o' -> */, +/* pos 0496: 710 */ 0xEC /* 'l' -> */, +/* pos 0497: 711 */ 0x00, 0x44 /* - terminal marker 68 - */, +/* total size 1177 bytes */ +#endif + +#if !defined(LWS_HTTP_HEADERS_ALL) && defined(LWS_WITH_HTTP_UNCOMMON_HEADERS) && !defined(LWS_ROLE_WS) && defined(LWS_ROLE_H2) + /* 0: 0: get */ + /* 1: 1: post */ + /* 2: 2: options */ + /* 3: 3: host: */ + /* 4: 4: connection: */ + /* 5: 5: upgrade: */ + /* 6: 6: origin: */ + /* 7: 8: + */ + /* 8: 15: http/1.1 */ + /* 9: 16: http2-settings: */ + /* 10: 17: accept: */ + /* 11: 18: access-control-request-headers: */ + /* 12: 19: if-modified-since: */ + /* 13: 20: if-none-match: */ + /* 14: 21: accept-encoding: */ + /* 15: 22: accept-language: */ + /* 16: 23: pragma: */ + /* 17: 24: cache-control: */ + /* 18: 25: authorization: */ + /* 19: 26: cookie: */ + /* 20: 27: content-length: */ + /* 21: 28: content-type: */ + /* 22: 29: date: */ + /* 23: 30: range: */ + /* 24: 31: referer: */ + /* 25: 35: :authority */ + /* 26: 36: :method */ + /* 27: 37: :path */ + /* 28: 38: :scheme */ + /* 29: 39: :status */ + /* 30: 40: accept-charset: */ + /* 31: 41: accept-ranges: */ + /* 32: 42: access-control-allow-origin: */ + /* 33: 43: age: */ + /* 34: 44: allow: */ + /* 35: 45: content-disposition: */ + /* 36: 46: content-encoding: */ + /* 37: 47: content-language: */ + /* 38: 48: content-location: */ + /* 39: 49: content-range: */ + /* 40: 50: etag: */ + /* 41: 51: expect: */ + /* 42: 52: expires: */ + /* 43: 53: from: */ + /* 44: 54: if-match: */ + /* 45: 55: if-range: */ + /* 46: 56: if-unmodified-since: */ + /* 47: 57: last-modified: */ + /* 48: 58: link: */ + /* 49: 59: location: */ + /* 50: 60: max-forwards: */ + /* 51: 61: proxy-authenticate: */ + /* 52: 62: proxy-authorization: */ + /* 53: 63: refresh: */ + /* 54: 64: retry-after: */ + /* 55: 65: server: */ + /* 56: 66: set-cookie: */ + /* 57: 67: strict-transport-security: */ + /* 58: 68: transfer-encoding: */ + /* 59: 69: user-agent: */ + /* 60: 70: vary: */ + /* 61: 71: via: */ + /* 62: 72: www-authenticate: */ + /* 63: 73: patch */ + /* 64: 74: put */ + /* 65: 75: delete */ + /* 66: 76: uri-args */ + /* 67: 77: proxy */ + /* 68: 78: x-real-ip: */ + /* 69: 79: http/1.0 */ + /* 70: 80: x-forwarded-for: */ + /* 71: 81: connect */ + /* 72: 82: head */ + /* 73: 83: te: */ + /* 74: 84: replay-nonce: */ + /* 75: 85: :protocol */ + /* 76: 86: x-auth-token: */ + /* 77: 87: */ +/* pos 0000: 0 */ 0x67 /* 'g' */, 0x40, 0x00 /* (to 0x0040 state 1) */, + 0x70 /* 'p' */, 0x42, 0x00 /* (to 0x0045 state 5) */, + 0x68 /* 'h' */, 0x51, 0x00 /* (to 0x0057 state 10) */, + 0x63 /* 'c' */, 0x5D, 0x00 /* (to 0x0066 state 15) */, + 0x75 /* 'u' */, 0x7E, 0x00 /* (to 0x008A state 26) */, + 0x6F /* 'o' */, 0x8D, 0x00 /* (to 0x009C state 34) */, + 0x0D /* '.' */, 0x98, 0x00 /* (to 0x00AA state 41) */, + 0x61 /* 'a' */, 0xAD, 0x00 /* (to 0x00C2 state 51) */, + 0x69 /* 'i' */, 0xCA, 0x00 /* (to 0x00E2 state 58) */, + 0x64 /* 'd' */, 0x73, 0x01 /* (to 0x018E state 160) */, + 0x72 /* 'r' */, 0x7C, 0x01 /* (to 0x019A state 165) */, + 0x65 /* 'e' */, 0xC8, 0x01 /* (to 0x01E9 state 229) */, + 0x66 /* 'f' */, 0xE4, 0x01 /* (to 0x0208 state 245) */, + 0x6C /* 'l' */, 0x06, 0x02 /* (to 0x022D state 278) */, + 0x73 /* 's' */, 0x4B, 0x02 /* (to 0x0275 state 321) */, + 0x74 /* 't' */, 0x69, 0x02 /* (to 0x0296 state 337) */, + 0x78 /* 'x' */, 0x8A, 0x02 /* (to 0x02BA state 364) */, + 0x6D /* 'm' */, 0xFB, 0x02 /* (to 0x032E state 456) */, + 0x76 /* 'v' */, 0x54, 0x03 /* (to 0x038A state 531) */, + 0x77 /* 'w' */, 0x61, 0x03 /* (to 0x039A state 539) */, + 0x3A /* ':' */, 0x19, 0x04 /* (to 0x0455 state 674) */, + 0x08, /* fail */ +/* pos 0040: 1 */ 0xE5 /* 'e' -> */, +/* pos 0041: 2 */ 0xF4 /* 't' -> */, +/* pos 0042: 3 */ 0xA0 /* ' ' -> */, +/* pos 0043: 4 */ 0x00, 0x00 /* - terminal marker 0 - */, +/* pos 0045: 5 */ 0x6F /* 'o' */, 0x0D, 0x00 /* (to 0x0052 state 6) */, + 0x72 /* 'r' */, 0xEC, 0x00 /* (to 0x0134 state 106) */, + 0x61 /* 'a' */, 0x61, 0x03 /* (to 0x03AC state 556) */, + 0x75 /* 'u' */, 0x63, 0x03 /* (to 0x03B1 state 560) */, + 0x08, /* fail */ +/* pos 0052: 6 */ 0xF3 /* 's' -> */, +/* pos 0053: 7 */ 0xF4 /* 't' -> */, +/* pos 0054: 8 */ 0xA0 /* ' ' -> */, +/* pos 0055: 9 */ 0x00, 0x01 /* - terminal marker 1 - */, +/* pos 0057: 10 */ 0x6F /* 'o' */, 0x0A, 0x00 /* (to 0x0061 state 11) */, + 0x74 /* 't' */, 0x53, 0x00 /* (to 0x00AD state 43) */, + 0x65 /* 'e' */, 0x79, 0x02 /* (to 0x02D6 state 381) */, + 0x08, /* fail */ +/* pos 0061: 11 */ 0xF3 /* 's' -> */, +/* pos 0062: 12 */ 0xF4 /* 't' -> */, +/* pos 0063: 13 */ 0xBA /* ':' -> */, +/* pos 0064: 14 */ 0x00, 0x03 /* - terminal marker 3 - */, +/* pos 0066: 15 */ 0x6F /* 'o' */, 0x07, 0x00 /* (to 0x006D state 16) */, + 0x61 /* 'a' */, 0xD8, 0x00 /* (to 0x0141 state 112) */, + 0x08, /* fail */ +/* pos 006d: 16 */ 0x6E /* 'n' */, 0x07, 0x00 /* (to 0x0074 state 17) */, + 0x6F /* 'o' */, 0xED, 0x00 /* (to 0x015D state 138) */, + 0x08, /* fail */ +/* pos 0074: 17 */ 0x6E /* 'n' */, 0x07, 0x00 /* (to 0x007B state 18) */, + 0x74 /* 't' */, 0xEC, 0x00 /* (to 0x0163 state 143) */, + 0x08, /* fail */ +/* pos 007b: 18 */ 0xE5 /* 'e' -> */, +/* pos 007c: 19 */ 0xE3 /* 'c' -> */, +/* pos 007d: 20 */ 0xF4 /* 't' -> */, +/* pos 007e: 21 */ 0x69 /* 'i' */, 0x07, 0x00 /* (to 0x0085 state 22) */, + 0x20 /* ' ' */, 0x53, 0x02 /* (to 0x02D4 state 380) */, + 0x08, /* fail */ +/* pos 0085: 22 */ 0xEF /* 'o' -> */, +/* pos 0086: 23 */ 0xEE /* 'n' -> */, +/* pos 0087: 24 */ 0xBA /* ':' -> */, +/* pos 0088: 25 */ 0x00, 0x04 /* - terminal marker 4 - */, +/* pos 008a: 26 */ 0x70 /* 'p' */, 0x0A, 0x00 /* (to 0x0094 state 27) */, + 0x72 /* 'r' */, 0x22, 0x02 /* (to 0x02AF state 355) */, + 0x73 /* 's' */, 0xEF, 0x02 /* (to 0x037F state 521) */, + 0x08, /* fail */ +/* pos 0094: 27 */ 0xE7 /* 'g' -> */, +/* pos 0095: 28 */ 0xF2 /* 'r' -> */, +/* pos 0096: 29 */ 0xE1 /* 'a' -> */, +/* pos 0097: 30 */ 0xE4 /* 'd' -> */, +/* pos 0098: 31 */ 0xE5 /* 'e' -> */, +/* pos 0099: 32 */ 0xBA /* ':' -> */, +/* pos 009a: 33 */ 0x00, 0x05 /* - terminal marker 5 - */, +/* pos 009c: 34 */ 0x72 /* 'r' */, 0x07, 0x00 /* (to 0x00A3 state 35) */, + 0x70 /* 'p' */, 0x48, 0x02 /* (to 0x02E7 state 396) */, + 0x08, /* fail */ +/* pos 00a3: 35 */ 0xE9 /* 'i' -> */, +/* pos 00a4: 36 */ 0xE7 /* 'g' -> */, +/* pos 00a5: 37 */ 0xE9 /* 'i' -> */, +/* pos 00a6: 38 */ 0xEE /* 'n' -> */, +/* pos 00a7: 39 */ 0xBA /* ':' -> */, +/* pos 00a8: 40 */ 0x00, 0x06 /* - terminal marker 6 - */, +/* pos 00aa: 41 */ 0x8A /* '.' -> */, +/* pos 00ab: 42 */ 0x00, 0x07 /* - terminal marker 7 - */, +/* pos 00ad: 43 */ 0xF4 /* 't' -> */, +/* pos 00ae: 44 */ 0xF0 /* 'p' -> */, +/* pos 00af: 45 */ 0x2F /* '/' */, 0x07, 0x00 /* (to 0x00B6 state 46) */, + 0x32 /* '2' */, 0x97, 0x03 /* (to 0x0449 state 663) */, + 0x08, /* fail */ +/* pos 00b6: 46 */ 0xB1 /* '1' -> */, +/* pos 00b7: 47 */ 0xAE /* '.' -> */, +/* pos 00b8: 48 */ 0x31 /* '1' */, 0x07, 0x00 /* (to 0x00BF state 49) */, + 0x30 /* '0' */, 0xFC, 0x01 /* (to 0x02B7 state 362) */, + 0x08, /* fail */ +/* pos 00bf: 49 */ 0xA0 /* ' ' -> */, +/* pos 00c0: 50 */ 0x00, 0x08 /* - terminal marker 8 - */, +/* pos 00c2: 51 */ 0x63 /* 'c' */, 0x0D, 0x00 /* (to 0x00CF state 52) */, + 0x75 /* 'u' */, 0x8A, 0x00 /* (to 0x014F state 125) */, + 0x67 /* 'g' */, 0xE7, 0x00 /* (to 0x01AF state 178) */, + 0x6C /* 'l' */, 0xE8, 0x00 /* (to 0x01B3 state 181) */, + 0x08, /* fail */ +/* pos 00cf: 52 */ 0xE3 /* 'c' -> */, +/* pos 00d0: 53 */ 0xE5 /* 'e' -> */, +/* pos 00d1: 54 */ 0x70 /* 'p' */, 0x07, 0x00 /* (to 0x00D8 state 55) */, + 0x73 /* 's' */, 0x1B, 0x02 /* (to 0x02EF state 403) */, + 0x08, /* fail */ +/* pos 00d8: 55 */ 0xF4 /* 't' -> */, +/* pos 00d9: 56 */ 0x3A /* ':' */, 0x07, 0x00 /* (to 0x00E0 state 57) */, + 0x2D /* '-' */, 0x37, 0x00 /* (to 0x0113 state 87) */, + 0x08, /* fail */ +/* pos 00e0: 57 */ 0x00, 0x0A /* - terminal marker 10 - */, +/* pos 00e2: 58 */ 0xE6 /* 'f' -> */, +/* pos 00e3: 59 */ 0xAD /* '-' -> */, +/* pos 00e4: 60 */ 0x6D /* 'm' */, 0x0D, 0x00 /* (to 0x00F1 state 61) */, + 0x6E /* 'n' */, 0x20, 0x00 /* (to 0x0107 state 76) */, + 0x72 /* 'r' */, 0x2A, 0x01 /* (to 0x0214 state 255) */, + 0x75 /* 'u' */, 0x2E, 0x01 /* (to 0x021B state 261) */, + 0x08, /* fail */ +/* pos 00f1: 61 */ 0x6F /* 'o' */, 0x07, 0x00 /* (to 0x00F8 state 62) */, + 0x61 /* 'a' */, 0x1A, 0x01 /* (to 0x020E state 250) */, + 0x08, /* fail */ +/* pos 00f8: 62 */ 0xE4 /* 'd' -> */, +/* pos 00f9: 63 */ 0xE9 /* 'i' -> */, +/* pos 00fa: 64 */ 0xE6 /* 'f' -> */, +/* pos 00fb: 65 */ 0xE9 /* 'i' -> */, +/* pos 00fc: 66 */ 0xE5 /* 'e' -> */, +/* pos 00fd: 67 */ 0xE4 /* 'd' -> */, +/* pos 00fe: 68 */ 0xAD /* '-' -> */, +/* pos 00ff: 69 */ 0xF3 /* 's' -> */, +/* pos 0100: 70 */ 0xE9 /* 'i' -> */, +/* pos 0101: 71 */ 0xEE /* 'n' -> */, +/* pos 0102: 72 */ 0xE3 /* 'c' -> */, +/* pos 0103: 73 */ 0xE5 /* 'e' -> */, +/* pos 0104: 74 */ 0xBA /* ':' -> */, +/* pos 0105: 75 */ 0x00, 0x0C /* - terminal marker 12 - */, +/* pos 0107: 76 */ 0xEF /* 'o' -> */, +/* pos 0108: 77 */ 0xEE /* 'n' -> */, +/* pos 0109: 78 */ 0xE5 /* 'e' -> */, +/* pos 010a: 79 */ 0xAD /* '-' -> */, +/* pos 010b: 80 */ 0xED /* 'm' -> */, +/* pos 010c: 81 */ 0xE1 /* 'a' -> */, +/* pos 010d: 82 */ 0xF4 /* 't' -> */, +/* pos 010e: 83 */ 0xE3 /* 'c' -> */, +/* pos 010f: 84 */ 0xE8 /* 'h' -> */, +/* pos 0110: 85 */ 0xBA /* ':' -> */, +/* pos 0111: 86 */ 0x00, 0x0D /* - terminal marker 13 - */, +/* pos 0113: 87 */ 0x65 /* 'e' */, 0x0D, 0x00 /* (to 0x0120 state 88) */, + 0x6C /* 'l' */, 0x14, 0x00 /* (to 0x012A state 97) */, + 0x72 /* 'r' */, 0x8E, 0x00 /* (to 0x01A7 state 171) */, + 0x63 /* 'c' */, 0xFB, 0x01 /* (to 0x0317 state 435) */, + 0x08, /* fail */ +/* pos 0120: 88 */ 0xEE /* 'n' -> */, +/* pos 0121: 89 */ 0xE3 /* 'c' -> */, +/* pos 0122: 90 */ 0xEF /* 'o' -> */, +/* pos 0123: 91 */ 0xE4 /* 'd' -> */, +/* pos 0124: 92 */ 0xE9 /* 'i' -> */, +/* pos 0125: 93 */ 0xEE /* 'n' -> */, +/* pos 0126: 94 */ 0xE7 /* 'g' -> */, +/* pos 0127: 95 */ 0xBA /* ':' -> */, +/* pos 0128: 96 */ 0x00, 0x0E /* - terminal marker 14 - */, +/* pos 012a: 97 */ 0xE1 /* 'a' -> */, +/* pos 012b: 98 */ 0xEE /* 'n' -> */, +/* pos 012c: 99 */ 0xE7 /* 'g' -> */, +/* pos 012d: 100 */ 0xF5 /* 'u' -> */, +/* pos 012e: 101 */ 0xE1 /* 'a' -> */, +/* pos 012f: 102 */ 0xE7 /* 'g' -> */, +/* pos 0130: 103 */ 0xE5 /* 'e' -> */, +/* pos 0131: 104 */ 0xBA /* ':' -> */, +/* pos 0132: 105 */ 0x00, 0x0F /* - terminal marker 15 - */, +/* pos 0134: 106 */ 0x61 /* 'a' */, 0x07, 0x00 /* (to 0x013B state 107) */, + 0x6F /* 'o' */, 0x05, 0x02 /* (to 0x033C state 469) */, + 0x08, /* fail */ +/* pos 013b: 107 */ 0xE7 /* 'g' -> */, +/* pos 013c: 108 */ 0xED /* 'm' -> */, +/* pos 013d: 109 */ 0xE1 /* 'a' -> */, +/* pos 013e: 110 */ 0xBA /* ':' -> */, +/* pos 013f: 111 */ 0x00, 0x10 /* - terminal marker 16 - */, +/* pos 0141: 112 */ 0xE3 /* 'c' -> */, +/* pos 0142: 113 */ 0xE8 /* 'h' -> */, +/* pos 0143: 114 */ 0xE5 /* 'e' -> */, +/* pos 0144: 115 */ 0xAD /* '-' -> */, +/* pos 0145: 116 */ 0xE3 /* 'c' -> */, +/* pos 0146: 117 */ 0xEF /* 'o' -> */, +/* pos 0147: 118 */ 0xEE /* 'n' -> */, +/* pos 0148: 119 */ 0xF4 /* 't' -> */, +/* pos 0149: 120 */ 0xF2 /* 'r' -> */, +/* pos 014a: 121 */ 0xEF /* 'o' -> */, +/* pos 014b: 122 */ 0xEC /* 'l' -> */, +/* pos 014c: 123 */ 0xBA /* ':' -> */, +/* pos 014d: 124 */ 0x00, 0x11 /* - terminal marker 17 - */, +/* pos 014f: 125 */ 0xF4 /* 't' -> */, +/* pos 0150: 126 */ 0xE8 /* 'h' -> */, +/* pos 0151: 127 */ 0xEF /* 'o' -> */, +/* pos 0152: 128 */ 0xF2 /* 'r' -> */, +/* pos 0153: 129 */ 0xE9 /* 'i' -> */, +/* pos 0154: 130 */ 0xFA /* 'z' -> */, +/* pos 0155: 131 */ 0xE1 /* 'a' -> */, +/* pos 0156: 132 */ 0xF4 /* 't' -> */, +/* pos 0157: 133 */ 0xE9 /* 'i' -> */, +/* pos 0158: 134 */ 0xEF /* 'o' -> */, +/* pos 0159: 135 */ 0xEE /* 'n' -> */, +/* pos 015a: 136 */ 0xBA /* ':' -> */, +/* pos 015b: 137 */ 0x00, 0x12 /* - terminal marker 18 - */, +/* pos 015d: 138 */ 0xEB /* 'k' -> */, +/* pos 015e: 139 */ 0xE9 /* 'i' -> */, +/* pos 015f: 140 */ 0xE5 /* 'e' -> */, +/* pos 0160: 141 */ 0xBA /* ':' -> */, +/* pos 0161: 142 */ 0x00, 0x13 /* - terminal marker 19 - */, +/* pos 0163: 143 */ 0xE5 /* 'e' -> */, +/* pos 0164: 144 */ 0xEE /* 'n' -> */, +/* pos 0165: 145 */ 0xF4 /* 't' -> */, +/* pos 0166: 146 */ 0xAD /* '-' -> */, +/* pos 0167: 147 */ 0x6C /* 'l' */, 0x10, 0x00 /* (to 0x0177 state 148) */, + 0x74 /* 't' */, 0x1E, 0x00 /* (to 0x0188 state 155) */, + 0x64 /* 'd' */, 0x4C, 0x00 /* (to 0x01B9 state 186) */, + 0x65 /* 'e' */, 0x56, 0x00 /* (to 0x01C6 state 198) */, + 0x72 /* 'r' */, 0x6F, 0x00 /* (to 0x01E2 state 223) */, + 0x08, /* fail */ +/* pos 0177: 148 */ 0x65 /* 'e' */, 0x0A, 0x00 /* (to 0x0181 state 149) */, + 0x61 /* 'a' */, 0x56, 0x00 /* (to 0x01D0 state 207) */, + 0x6F /* 'o' */, 0x5C, 0x00 /* (to 0x01D9 state 215) */, + 0x08, /* fail */ +/* pos 0181: 149 */ 0xEE /* 'n' -> */, +/* pos 0182: 150 */ 0xE7 /* 'g' -> */, +/* pos 0183: 151 */ 0xF4 /* 't' -> */, +/* pos 0184: 152 */ 0xE8 /* 'h' -> */, +/* pos 0185: 153 */ 0xBA /* ':' -> */, +/* pos 0186: 154 */ 0x00, 0x14 /* - terminal marker 20 - */, +/* pos 0188: 155 */ 0xF9 /* 'y' -> */, +/* pos 0189: 156 */ 0xF0 /* 'p' -> */, +/* pos 018a: 157 */ 0xE5 /* 'e' -> */, +/* pos 018b: 158 */ 0xBA /* ':' -> */, +/* pos 018c: 159 */ 0x00, 0x15 /* - terminal marker 21 - */, +/* pos 018e: 160 */ 0x61 /* 'a' */, 0x07, 0x00 /* (to 0x0195 state 161) */, + 0x65 /* 'e' */, 0x23, 0x02 /* (to 0x03B4 state 562) */, + 0x08, /* fail */ +/* pos 0195: 161 */ 0xF4 /* 't' -> */, +/* pos 0196: 162 */ 0xE5 /* 'e' -> */, +/* pos 0197: 163 */ 0xBA /* ':' -> */, +/* pos 0198: 164 */ 0x00, 0x16 /* - terminal marker 22 - */, +/* pos 019a: 165 */ 0x61 /* 'a' */, 0x07, 0x00 /* (to 0x01A1 state 166) */, + 0x65 /* 'e' */, 0xB6, 0x00 /* (to 0x0253 state 304) */, + 0x08, /* fail */ +/* pos 01a1: 166 */ 0xEE /* 'n' -> */, +/* pos 01a2: 167 */ 0xE7 /* 'g' -> */, +/* pos 01a3: 168 */ 0xE5 /* 'e' -> */, +/* pos 01a4: 169 */ 0xBA /* ':' -> */, +/* pos 01a5: 170 */ 0x00, 0x17 /* - terminal marker 23 - */, +/* pos 01a7: 171 */ 0xE1 /* 'a' -> */, +/* pos 01a8: 172 */ 0xEE /* 'n' -> */, +/* pos 01a9: 173 */ 0xE7 /* 'g' -> */, +/* pos 01aa: 174 */ 0xE5 /* 'e' -> */, +/* pos 01ab: 175 */ 0xF3 /* 's' -> */, +/* pos 01ac: 176 */ 0xBA /* ':' -> */, +/* pos 01ad: 177 */ 0x00, 0x1F /* - terminal marker 31 - */, +/* pos 01af: 178 */ 0xE5 /* 'e' -> */, +/* pos 01b0: 179 */ 0xBA /* ':' -> */, +/* pos 01b1: 180 */ 0x00, 0x21 /* - terminal marker 33 - */, +/* pos 01b3: 181 */ 0xEC /* 'l' -> */, +/* pos 01b4: 182 */ 0xEF /* 'o' -> */, +/* pos 01b5: 183 */ 0xF7 /* 'w' -> */, +/* pos 01b6: 184 */ 0xBA /* ':' -> */, +/* pos 01b7: 185 */ 0x00, 0x22 /* - terminal marker 34 - */, +/* pos 01b9: 186 */ 0xE9 /* 'i' -> */, +/* pos 01ba: 187 */ 0xF3 /* 's' -> */, +/* pos 01bb: 188 */ 0xF0 /* 'p' -> */, +/* pos 01bc: 189 */ 0xEF /* 'o' -> */, +/* pos 01bd: 190 */ 0xF3 /* 's' -> */, +/* pos 01be: 191 */ 0xE9 /* 'i' -> */, +/* pos 01bf: 192 */ 0xF4 /* 't' -> */, +/* pos 01c0: 193 */ 0xE9 /* 'i' -> */, +/* pos 01c1: 194 */ 0xEF /* 'o' -> */, +/* pos 01c2: 195 */ 0xEE /* 'n' -> */, +/* pos 01c3: 196 */ 0xBA /* ':' -> */, +/* pos 01c4: 197 */ 0x00, 0x23 /* - terminal marker 35 - */, +/* pos 01c6: 198 */ 0xEE /* 'n' -> */, +/* pos 01c7: 199 */ 0xE3 /* 'c' -> */, +/* pos 01c8: 200 */ 0xEF /* 'o' -> */, +/* pos 01c9: 201 */ 0xE4 /* 'd' -> */, +/* pos 01ca: 202 */ 0xE9 /* 'i' -> */, +/* pos 01cb: 203 */ 0xEE /* 'n' -> */, +/* pos 01cc: 204 */ 0xE7 /* 'g' -> */, +/* pos 01cd: 205 */ 0xBA /* ':' -> */, +/* pos 01ce: 206 */ 0x00, 0x24 /* - terminal marker 36 - */, +/* pos 01d0: 207 */ 0xEE /* 'n' -> */, +/* pos 01d1: 208 */ 0xE7 /* 'g' -> */, +/* pos 01d2: 209 */ 0xF5 /* 'u' -> */, +/* pos 01d3: 210 */ 0xE1 /* 'a' -> */, +/* pos 01d4: 211 */ 0xE7 /* 'g' -> */, +/* pos 01d5: 212 */ 0xE5 /* 'e' -> */, +/* pos 01d6: 213 */ 0xBA /* ':' -> */, +/* pos 01d7: 214 */ 0x00, 0x25 /* - terminal marker 37 - */, +/* pos 01d9: 215 */ 0xE3 /* 'c' -> */, +/* pos 01da: 216 */ 0xE1 /* 'a' -> */, +/* pos 01db: 217 */ 0xF4 /* 't' -> */, +/* pos 01dc: 218 */ 0xE9 /* 'i' -> */, +/* pos 01dd: 219 */ 0xEF /* 'o' -> */, +/* pos 01de: 220 */ 0xEE /* 'n' -> */, +/* pos 01df: 221 */ 0xBA /* ':' -> */, +/* pos 01e0: 222 */ 0x00, 0x26 /* - terminal marker 38 - */, +/* pos 01e2: 223 */ 0xE1 /* 'a' -> */, +/* pos 01e3: 224 */ 0xEE /* 'n' -> */, +/* pos 01e4: 225 */ 0xE7 /* 'g' -> */, +/* pos 01e5: 226 */ 0xE5 /* 'e' -> */, +/* pos 01e6: 227 */ 0xBA /* ':' -> */, +/* pos 01e7: 228 */ 0x00, 0x27 /* - terminal marker 39 - */, +/* pos 01e9: 229 */ 0x74 /* 't' */, 0x07, 0x00 /* (to 0x01F0 state 230) */, + 0x78 /* 'x' */, 0x09, 0x00 /* (to 0x01F5 state 234) */, + 0x08, /* fail */ +/* pos 01f0: 230 */ 0xE1 /* 'a' -> */, +/* pos 01f1: 231 */ 0xE7 /* 'g' -> */, +/* pos 01f2: 232 */ 0xBA /* ':' -> */, +/* pos 01f3: 233 */ 0x00, 0x28 /* - terminal marker 40 - */, +/* pos 01f5: 234 */ 0xF0 /* 'p' -> */, +/* pos 01f6: 235 */ 0x65 /* 'e' */, 0x07, 0x00 /* (to 0x01FD state 236) */, + 0x69 /* 'i' */, 0x09, 0x00 /* (to 0x0202 state 240) */, + 0x08, /* fail */ +/* pos 01fd: 236 */ 0xE3 /* 'c' -> */, +/* pos 01fe: 237 */ 0xF4 /* 't' -> */, +/* pos 01ff: 238 */ 0xBA /* ':' -> */, +/* pos 0200: 239 */ 0x00, 0x29 /* - terminal marker 41 - */, +/* pos 0202: 240 */ 0xF2 /* 'r' -> */, +/* pos 0203: 241 */ 0xE5 /* 'e' -> */, +/* pos 0204: 242 */ 0xF3 /* 's' -> */, +/* pos 0205: 243 */ 0xBA /* ':' -> */, +/* pos 0206: 244 */ 0x00, 0x2A /* - terminal marker 42 - */, +/* pos 0208: 245 */ 0xF2 /* 'r' -> */, +/* pos 0209: 246 */ 0xEF /* 'o' -> */, +/* pos 020a: 247 */ 0xED /* 'm' -> */, +/* pos 020b: 248 */ 0xBA /* ':' -> */, +/* pos 020c: 249 */ 0x00, 0x2B /* - terminal marker 43 - */, /* pos 020e: 250 */ 0xF4 /* 't' -> */, -/* pos 020f: 251 */ 0xAD /* '-' -> */, -/* pos 0210: 252 */ 0x6C /* 'l' */, 0x10, 0x00 /* (to 0x0220 state 253) */, - 0x74 /* 't' */, 0x1E, 0x00 /* (to 0x0231 state 260) */, - 0x64 /* 'd' */, 0xC9, 0x00 /* (to 0x02DF state 366) */, - 0x65 /* 'e' */, 0xD3, 0x00 /* (to 0x02EC state 378) */, - 0x72 /* 'r' */, 0xEC, 0x00 /* (to 0x0308 state 403) */, - 0x08, /* fail */ -/* pos 0220: 253 */ 0x65 /* 'e' */, 0x0A, 0x00 /* (to 0x022A state 254) */, - 0x61 /* 'a' */, 0xD3, 0x00 /* (to 0x02F6 state 387) */, - 0x6F /* 'o' */, 0xD9, 0x00 /* (to 0x02FF state 395) */, - 0x08, /* fail */ -/* pos 022a: 254 */ 0xEE /* 'n' -> */, -/* pos 022b: 255 */ 0xE7 /* 'g' -> */, -/* pos 022c: 256 */ 0xF4 /* 't' -> */, -/* pos 022d: 257 */ 0xE8 /* 'h' -> */, -/* pos 022e: 258 */ 0xBA /* ':' -> */, -/* pos 022f: 259 */ 0x00, 0x1B /* - terminal marker 27 - */, -/* pos 0231: 260 */ 0xF9 /* 'y' -> */, -/* pos 0232: 261 */ 0xF0 /* 'p' -> */, -/* pos 0233: 262 */ 0xE5 /* 'e' -> */, -/* pos 0234: 263 */ 0xBA /* ':' -> */, -/* pos 0235: 264 */ 0x00, 0x1C /* - terminal marker 28 - */, -/* pos 0237: 265 */ 0x61 /* 'a' */, 0x07, 0x00 /* (to 0x023E state 266) */, - 0x65 /* 'e' */, 0xFF, 0x01 /* (to 0x0439 state 637) */, - 0x08, /* fail */ -/* pos 023e: 266 */ 0xF4 /* 't' -> */, -/* pos 023f: 267 */ 0xE5 /* 'e' -> */, -/* pos 0240: 268 */ 0xBA /* ':' -> */, -/* pos 0241: 269 */ 0x00, 0x1D /* - terminal marker 29 - */, -/* pos 0243: 270 */ 0x61 /* 'a' */, 0x07, 0x00 /* (to 0x024A state 271) */, - 0x65 /* 'e' */, 0x0A, 0x00 /* (to 0x0250 state 276) */, - 0x08, /* fail */ -/* pos 024a: 271 */ 0xEE /* 'n' -> */, -/* pos 024b: 272 */ 0xE7 /* 'g' -> */, -/* pos 024c: 273 */ 0xE5 /* 'e' -> */, -/* pos 024d: 274 */ 0xBA /* ':' -> */, -/* pos 024e: 275 */ 0x00, 0x1E /* - terminal marker 30 - */, -/* pos 0250: 276 */ 0x66 /* 'f' */, 0x0A, 0x00 /* (to 0x025A state 277) */, - 0x74 /* 't' */, 0x63, 0x01 /* (to 0x03B6 state 529) */, - 0x70 /* 'p' */, 0x22, 0x02 /* (to 0x0478 state 682) */, - 0x08, /* fail */ -/* pos 025a: 277 */ 0x65 /* 'e' */, 0x07, 0x00 /* (to 0x0261 state 278) */, - 0x72 /* 'r' */, 0x53, 0x01 /* (to 0x03B0 state 524) */, - 0x08, /* fail */ -/* pos 0261: 278 */ 0xF2 /* 'r' -> */, -/* pos 0262: 279 */ 0xE5 /* 'e' -> */, -/* pos 0263: 280 */ 0xF2 /* 'r' -> */, -/* pos 0264: 281 */ 0xBA /* ':' -> */, -/* pos 0265: 282 */ 0x00, 0x1F /* - terminal marker 31 - */, -/* pos 0267: 283 */ 0x00, 0x20 /* - terminal marker 32 - */, -/* pos 0269: 284 */ 0xE5 /* 'e' -> */, -/* pos 026a: 285 */ 0xF2 /* 'r' -> */, -/* pos 026b: 286 */ 0xF3 /* 's' -> */, -/* pos 026c: 287 */ 0xE9 /* 'i' -> */, -/* pos 026d: 288 */ 0xEF /* 'o' -> */, -/* pos 026e: 289 */ 0xEE /* 'n' -> */, -/* pos 026f: 290 */ 0xBA /* ':' -> */, -/* pos 0270: 291 */ 0x00, 0x21 /* - terminal marker 33 - */, -/* pos 0272: 292 */ 0xF2 /* 'r' -> */, -/* pos 0273: 293 */ 0xE9 /* 'i' -> */, -/* pos 0274: 294 */ 0xE7 /* 'g' -> */, -/* pos 0275: 295 */ 0xE9 /* 'i' -> */, -/* pos 0276: 296 */ 0xEE /* 'n' -> */, -/* pos 0277: 297 */ 0xBA /* ':' -> */, -/* pos 0278: 298 */ 0x00, 0x22 /* - terminal marker 34 - */, -/* pos 027a: 299 */ 0x61 /* 'a' */, 0x0D, 0x00 /* (to 0x0287 state 300) */, - 0x6D /* 'm' */, 0x14, 0x00 /* (to 0x0291 state 309) */, - 0x70 /* 'p' */, 0x18, 0x00 /* (to 0x0298 state 315) */, - 0x73 /* 's' */, 0x20, 0x00 /* (to 0x02A3 state 319) */, - 0x08, /* fail */ -/* pos 0287: 300 */ 0xF5 /* 'u' -> */, -/* pos 0288: 301 */ 0xF4 /* 't' -> */, -/* pos 0289: 302 */ 0xE8 /* 'h' -> */, -/* pos 028a: 303 */ 0xEF /* 'o' -> */, -/* pos 028b: 304 */ 0xF2 /* 'r' -> */, -/* pos 028c: 305 */ 0xE9 /* 'i' -> */, -/* pos 028d: 306 */ 0xF4 /* 't' -> */, -/* pos 028e: 307 */ 0xF9 /* 'y' -> */, -/* pos 028f: 308 */ 0x00, 0x23 /* - terminal marker 35 - */, -/* pos 0291: 309 */ 0xE5 /* 'e' -> */, -/* pos 0292: 310 */ 0xF4 /* 't' -> */, -/* pos 0293: 311 */ 0xE8 /* 'h' -> */, -/* pos 0294: 312 */ 0xEF /* 'o' -> */, -/* pos 0295: 313 */ 0xE4 /* 'd' -> */, -/* pos 0296: 314 */ 0x00, 0x24 /* - terminal marker 36 - */, -/* pos 0298: 315 */ 0x61 /* 'a' */, 0x07, 0x00 /* (to 0x029F state 316) */, - 0x72 /* 'r' */, 0xE9, 0x01 /* (to 0x0484 state 693) */, - 0x08, /* fail */ -/* pos 029f: 316 */ 0xF4 /* 't' -> */, -/* pos 02a0: 317 */ 0xE8 /* 'h' -> */, -/* pos 02a1: 318 */ 0x00, 0x25 /* - terminal marker 37 - */, -/* pos 02a3: 319 */ 0x63 /* 'c' */, 0x07, 0x00 /* (to 0x02AA state 320) */, - 0x74 /* 't' */, 0x0A, 0x00 /* (to 0x02B0 state 325) */, - 0x08, /* fail */ -/* pos 02aa: 320 */ 0xE8 /* 'h' -> */, -/* pos 02ab: 321 */ 0xE5 /* 'e' -> */, -/* pos 02ac: 322 */ 0xED /* 'm' -> */, -/* pos 02ad: 323 */ 0xE5 /* 'e' -> */, -/* pos 02ae: 324 */ 0x00, 0x26 /* - terminal marker 38 - */, -/* pos 02b0: 325 */ 0xE1 /* 'a' -> */, -/* pos 02b1: 326 */ 0xF4 /* 't' -> */, -/* pos 02b2: 327 */ 0xF5 /* 'u' -> */, -/* pos 02b3: 328 */ 0xF3 /* 's' -> */, -/* pos 02b4: 329 */ 0x00, 0x27 /* - terminal marker 39 - */, -/* pos 02b6: 330 */ 0xE8 /* 'h' -> */, -/* pos 02b7: 331 */ 0xE1 /* 'a' -> */, -/* pos 02b8: 332 */ 0xF2 /* 'r' -> */, -/* pos 02b9: 333 */ 0xF3 /* 's' -> */, -/* pos 02ba: 334 */ 0xE5 /* 'e' -> */, -/* pos 02bb: 335 */ 0xF4 /* 't' -> */, -/* pos 02bc: 336 */ 0xBA /* ':' -> */, -/* pos 02bd: 337 */ 0x00, 0x28 /* - terminal marker 40 - */, -/* pos 02bf: 338 */ 0xE1 /* 'a' -> */, -/* pos 02c0: 339 */ 0xEE /* 'n' -> */, -/* pos 02c1: 340 */ 0xE7 /* 'g' -> */, -/* pos 02c2: 341 */ 0xE5 /* 'e' -> */, -/* pos 02c3: 342 */ 0xF3 /* 's' -> */, -/* pos 02c4: 343 */ 0xBA /* ':' -> */, -/* pos 02c5: 344 */ 0x00, 0x29 /* - terminal marker 41 - */, -/* pos 02c7: 345 */ 0xEC /* 'l' -> */, -/* pos 02c8: 346 */ 0xEC /* 'l' -> */, -/* pos 02c9: 347 */ 0xEF /* 'o' -> */, -/* pos 02ca: 348 */ 0xF7 /* 'w' -> */, -/* pos 02cb: 349 */ 0xAD /* '-' -> */, -/* pos 02cc: 350 */ 0xEF /* 'o' -> */, -/* pos 02cd: 351 */ 0xF2 /* 'r' -> */, -/* pos 02ce: 352 */ 0xE9 /* 'i' -> */, -/* pos 02cf: 353 */ 0xE7 /* 'g' -> */, -/* pos 02d0: 354 */ 0xE9 /* 'i' -> */, -/* pos 02d1: 355 */ 0xEE /* 'n' -> */, -/* pos 02d2: 356 */ 0xBA /* ':' -> */, -/* pos 02d3: 357 */ 0x00, 0x2A /* - terminal marker 42 - */, -/* pos 02d5: 358 */ 0xE5 /* 'e' -> */, -/* pos 02d6: 359 */ 0xBA /* ':' -> */, -/* pos 02d7: 360 */ 0x00, 0x2B /* - terminal marker 43 - */, -/* pos 02d9: 361 */ 0xEC /* 'l' -> */, -/* pos 02da: 362 */ 0xEF /* 'o' -> */, -/* pos 02db: 363 */ 0xF7 /* 'w' -> */, -/* pos 02dc: 364 */ 0xBA /* ':' -> */, -/* pos 02dd: 365 */ 0x00, 0x2C /* - terminal marker 44 - */, -/* pos 02df: 366 */ 0xE9 /* 'i' -> */, -/* pos 02e0: 367 */ 0xF3 /* 's' -> */, -/* pos 02e1: 368 */ 0xF0 /* 'p' -> */, -/* pos 02e2: 369 */ 0xEF /* 'o' -> */, -/* pos 02e3: 370 */ 0xF3 /* 's' -> */, -/* pos 02e4: 371 */ 0xE9 /* 'i' -> */, -/* pos 02e5: 372 */ 0xF4 /* 't' -> */, -/* pos 02e6: 373 */ 0xE9 /* 'i' -> */, -/* pos 02e7: 374 */ 0xEF /* 'o' -> */, -/* pos 02e8: 375 */ 0xEE /* 'n' -> */, -/* pos 02e9: 376 */ 0xBA /* ':' -> */, -/* pos 02ea: 377 */ 0x00, 0x2D /* - terminal marker 45 - */, -/* pos 02ec: 378 */ 0xEE /* 'n' -> */, -/* pos 02ed: 379 */ 0xE3 /* 'c' -> */, -/* pos 02ee: 380 */ 0xEF /* 'o' -> */, -/* pos 02ef: 381 */ 0xE4 /* 'd' -> */, -/* pos 02f0: 382 */ 0xE9 /* 'i' -> */, -/* pos 02f1: 383 */ 0xEE /* 'n' -> */, -/* pos 02f2: 384 */ 0xE7 /* 'g' -> */, -/* pos 02f3: 385 */ 0xBA /* ':' -> */, -/* pos 02f4: 386 */ 0x00, 0x2E /* - terminal marker 46 - */, -/* pos 02f6: 387 */ 0xEE /* 'n' -> */, -/* pos 02f7: 388 */ 0xE7 /* 'g' -> */, -/* pos 02f8: 389 */ 0xF5 /* 'u' -> */, -/* pos 02f9: 390 */ 0xE1 /* 'a' -> */, -/* pos 02fa: 391 */ 0xE7 /* 'g' -> */, -/* pos 02fb: 392 */ 0xE5 /* 'e' -> */, -/* pos 02fc: 393 */ 0xBA /* ':' -> */, -/* pos 02fd: 394 */ 0x00, 0x2F /* - terminal marker 47 - */, -/* pos 02ff: 395 */ 0xE3 /* 'c' -> */, -/* pos 0300: 396 */ 0xE1 /* 'a' -> */, -/* pos 0301: 397 */ 0xF4 /* 't' -> */, -/* pos 0302: 398 */ 0xE9 /* 'i' -> */, -/* pos 0303: 399 */ 0xEF /* 'o' -> */, -/* pos 0304: 400 */ 0xEE /* 'n' -> */, -/* pos 0305: 401 */ 0xBA /* ':' -> */, -/* pos 0306: 402 */ 0x00, 0x30 /* - terminal marker 48 - */, -/* pos 0308: 403 */ 0xE1 /* 'a' -> */, -/* pos 0309: 404 */ 0xEE /* 'n' -> */, -/* pos 030a: 405 */ 0xE7 /* 'g' -> */, -/* pos 030b: 406 */ 0xE5 /* 'e' -> */, -/* pos 030c: 407 */ 0xBA /* ':' -> */, -/* pos 030d: 408 */ 0x00, 0x31 /* - terminal marker 49 - */, -/* pos 030f: 409 */ 0x74 /* 't' */, 0x07, 0x00 /* (to 0x0316 state 410) */, - 0x78 /* 'x' */, 0x09, 0x00 /* (to 0x031B state 414) */, - 0x08, /* fail */ -/* pos 0316: 410 */ 0xE1 /* 'a' -> */, -/* pos 0317: 411 */ 0xE7 /* 'g' -> */, -/* pos 0318: 412 */ 0xBA /* ':' -> */, -/* pos 0319: 413 */ 0x00, 0x32 /* - terminal marker 50 - */, -/* pos 031b: 414 */ 0xF0 /* 'p' -> */, -/* pos 031c: 415 */ 0x65 /* 'e' */, 0x07, 0x00 /* (to 0x0323 state 416) */, - 0x69 /* 'i' */, 0x09, 0x00 /* (to 0x0328 state 420) */, - 0x08, /* fail */ -/* pos 0323: 416 */ 0xE3 /* 'c' -> */, -/* pos 0324: 417 */ 0xF4 /* 't' -> */, -/* pos 0325: 418 */ 0xBA /* ':' -> */, -/* pos 0326: 419 */ 0x00, 0x33 /* - terminal marker 51 - */, -/* pos 0328: 420 */ 0xF2 /* 'r' -> */, -/* pos 0329: 421 */ 0xE5 /* 'e' -> */, -/* pos 032a: 422 */ 0xF3 /* 's' -> */, -/* pos 032b: 423 */ 0xBA /* ':' -> */, -/* pos 032c: 424 */ 0x00, 0x34 /* - terminal marker 52 - */, -/* pos 032e: 425 */ 0xF2 /* 'r' -> */, -/* pos 032f: 426 */ 0xEF /* 'o' -> */, -/* pos 0330: 427 */ 0xED /* 'm' -> */, -/* pos 0331: 428 */ 0xBA /* ':' -> */, -/* pos 0332: 429 */ 0x00, 0x35 /* - terminal marker 53 - */, -/* pos 0334: 430 */ 0xF4 /* 't' -> */, -/* pos 0335: 431 */ 0xE3 /* 'c' -> */, -/* pos 0336: 432 */ 0xE8 /* 'h' -> */, -/* pos 0337: 433 */ 0xBA /* ':' -> */, -/* pos 0338: 434 */ 0x00, 0x36 /* - terminal marker 54 - */, -/* pos 033a: 435 */ 0xE1 /* 'a' -> */, -/* pos 033b: 436 */ 0xEE /* 'n' -> */, -/* pos 033c: 437 */ 0xE7 /* 'g' -> */, -/* pos 033d: 438 */ 0xE5 /* 'e' -> */, -/* pos 033e: 439 */ 0xBA /* ':' -> */, -/* pos 033f: 440 */ 0x00, 0x37 /* - terminal marker 55 - */, -/* pos 0341: 441 */ 0xEE /* 'n' -> */, -/* pos 0342: 442 */ 0xED /* 'm' -> */, -/* pos 0343: 443 */ 0xEF /* 'o' -> */, -/* pos 0344: 444 */ 0xE4 /* 'd' -> */, -/* pos 0345: 445 */ 0xE9 /* 'i' -> */, -/* pos 0346: 446 */ 0xE6 /* 'f' -> */, -/* pos 0347: 447 */ 0xE9 /* 'i' -> */, -/* pos 0348: 448 */ 0xE5 /* 'e' -> */, -/* pos 0349: 449 */ 0xE4 /* 'd' -> */, -/* pos 034a: 450 */ 0xAD /* '-' -> */, -/* pos 034b: 451 */ 0xF3 /* 's' -> */, -/* pos 034c: 452 */ 0xE9 /* 'i' -> */, -/* pos 034d: 453 */ 0xEE /* 'n' -> */, -/* pos 034e: 454 */ 0xE3 /* 'c' -> */, -/* pos 034f: 455 */ 0xE5 /* 'e' -> */, -/* pos 0350: 456 */ 0xBA /* ':' -> */, -/* pos 0351: 457 */ 0x00, 0x38 /* - terminal marker 56 - */, -/* pos 0353: 458 */ 0x61 /* 'a' */, 0x0A, 0x00 /* (to 0x035D state 459) */, - 0x69 /* 'i' */, 0x15, 0x00 /* (to 0x036B state 472) */, - 0x6F /* 'o' */, 0x17, 0x00 /* (to 0x0370 state 476) */, - 0x08, /* fail */ -/* pos 035d: 459 */ 0xF3 /* 's' -> */, -/* pos 035e: 460 */ 0xF4 /* 't' -> */, -/* pos 035f: 461 */ 0xAD /* '-' -> */, -/* pos 0360: 462 */ 0xED /* 'm' -> */, -/* pos 0361: 463 */ 0xEF /* 'o' -> */, -/* pos 0362: 464 */ 0xE4 /* 'd' -> */, -/* pos 0363: 465 */ 0xE9 /* 'i' -> */, -/* pos 0364: 466 */ 0xE6 /* 'f' -> */, -/* pos 0365: 467 */ 0xE9 /* 'i' -> */, -/* pos 0366: 468 */ 0xE5 /* 'e' -> */, -/* pos 0367: 469 */ 0xE4 /* 'd' -> */, -/* pos 0368: 470 */ 0xBA /* ':' -> */, -/* pos 0369: 471 */ 0x00, 0x39 /* - terminal marker 57 - */, -/* pos 036b: 472 */ 0xEE /* 'n' -> */, -/* pos 036c: 473 */ 0xEB /* 'k' -> */, -/* pos 036d: 474 */ 0xBA /* ':' -> */, -/* pos 036e: 475 */ 0x00, 0x3A /* - terminal marker 58 - */, -/* pos 0370: 476 */ 0xE3 /* 'c' -> */, -/* pos 0371: 477 */ 0xE1 /* 'a' -> */, -/* pos 0372: 478 */ 0xF4 /* 't' -> */, -/* pos 0373: 479 */ 0xE9 /* 'i' -> */, -/* pos 0374: 480 */ 0xEF /* 'o' -> */, -/* pos 0375: 481 */ 0xEE /* 'n' -> */, -/* pos 0376: 482 */ 0xBA /* ':' -> */, -/* pos 0377: 483 */ 0x00, 0x3B /* - terminal marker 59 - */, -/* pos 0379: 484 */ 0xE1 /* 'a' -> */, -/* pos 037a: 485 */ 0xF8 /* 'x' -> */, -/* pos 037b: 486 */ 0xAD /* '-' -> */, -/* pos 037c: 487 */ 0xE6 /* 'f' -> */, -/* pos 037d: 488 */ 0xEF /* 'o' -> */, -/* pos 037e: 489 */ 0xF2 /* 'r' -> */, -/* pos 037f: 490 */ 0xF7 /* 'w' -> */, -/* pos 0380: 491 */ 0xE1 /* 'a' -> */, -/* pos 0381: 492 */ 0xF2 /* 'r' -> */, -/* pos 0382: 493 */ 0xE4 /* 'd' -> */, -/* pos 0383: 494 */ 0xF3 /* 's' -> */, -/* pos 0384: 495 */ 0xBA /* ':' -> */, -/* pos 0385: 496 */ 0x00, 0x3C /* - terminal marker 60 - */, -/* pos 0387: 497 */ 0xF8 /* 'x' -> */, -/* pos 0388: 498 */ 0xF9 /* 'y' -> */, -/* pos 0389: 499 */ 0x2D /* '-' */, 0x07, 0x00 /* (to 0x0390 state 500) */, - 0x20 /* ' ' */, 0xBB, 0x00 /* (to 0x0447 state 649) */, - 0x08, /* fail */ -/* pos 0390: 500 */ 0xE1 /* 'a' -> */, -/* pos 0391: 501 */ 0xF5 /* 'u' -> */, -/* pos 0392: 502 */ 0xF4 /* 't' -> */, -/* pos 0393: 503 */ 0xE8 /* 'h' -> */, -/* pos 0394: 504 */ 0x65 /* 'e' */, 0x07, 0x00 /* (to 0x039B state 505) */, - 0x6F /* 'o' */, 0x0E, 0x00 /* (to 0x03A5 state 514) */, - 0x08, /* fail */ -/* pos 039b: 505 */ 0xEE /* 'n' -> */, -/* pos 039c: 506 */ 0xF4 /* 't' -> */, -/* pos 039d: 507 */ 0xE9 /* 'i' -> */, -/* pos 039e: 508 */ 0xE3 /* 'c' -> */, -/* pos 039f: 509 */ 0xE1 /* 'a' -> */, -/* pos 03a0: 510 */ 0xF4 /* 't' -> */, -/* pos 03a1: 511 */ 0xE5 /* 'e' -> */, -/* pos 03a2: 512 */ 0xBA /* ':' -> */, -/* pos 03a3: 513 */ 0x00, 0x3D /* - terminal marker 61 - */, -/* pos 03a5: 514 */ 0xF2 /* 'r' -> */, -/* pos 03a6: 515 */ 0xE9 /* 'i' -> */, -/* pos 03a7: 516 */ 0xFA /* 'z' -> */, -/* pos 03a8: 517 */ 0xE1 /* 'a' -> */, -/* pos 03a9: 518 */ 0xF4 /* 't' -> */, -/* pos 03aa: 519 */ 0xE9 /* 'i' -> */, -/* pos 03ab: 520 */ 0xEF /* 'o' -> */, -/* pos 03ac: 521 */ 0xEE /* 'n' -> */, -/* pos 03ad: 522 */ 0xBA /* ':' -> */, -/* pos 03ae: 523 */ 0x00, 0x3E /* - terminal marker 62 - */, -/* pos 03b0: 524 */ 0xE5 /* 'e' -> */, -/* pos 03b1: 525 */ 0xF3 /* 's' -> */, -/* pos 03b2: 526 */ 0xE8 /* 'h' -> */, -/* pos 03b3: 527 */ 0xBA /* ':' -> */, -/* pos 03b4: 528 */ 0x00, 0x3F /* - terminal marker 63 - */, -/* pos 03b6: 529 */ 0xF2 /* 'r' -> */, -/* pos 03b7: 530 */ 0xF9 /* 'y' -> */, -/* pos 03b8: 531 */ 0xAD /* '-' -> */, -/* pos 03b9: 532 */ 0xE1 /* 'a' -> */, -/* pos 03ba: 533 */ 0xE6 /* 'f' -> */, -/* pos 03bb: 534 */ 0xF4 /* 't' -> */, -/* pos 03bc: 535 */ 0xE5 /* 'e' -> */, -/* pos 03bd: 536 */ 0xF2 /* 'r' -> */, -/* pos 03be: 537 */ 0xBA /* ':' -> */, -/* pos 03bf: 538 */ 0x00, 0x40 /* - terminal marker 64 - */, -/* pos 03c1: 539 */ 0xF6 /* 'v' -> */, -/* pos 03c2: 540 */ 0xE5 /* 'e' -> */, -/* pos 03c3: 541 */ 0xF2 /* 'r' -> */, -/* pos 03c4: 542 */ 0xBA /* ':' -> */, -/* pos 03c5: 543 */ 0x00, 0x41 /* - terminal marker 65 - */, -/* pos 03c7: 544 */ 0xAD /* '-' -> */, -/* pos 03c8: 545 */ 0xE3 /* 'c' -> */, -/* pos 03c9: 546 */ 0xEF /* 'o' -> */, -/* pos 03ca: 547 */ 0xEF /* 'o' -> */, -/* pos 03cb: 548 */ 0xEB /* 'k' -> */, -/* pos 03cc: 549 */ 0xE9 /* 'i' -> */, -/* pos 03cd: 550 */ 0xE5 /* 'e' -> */, -/* pos 03ce: 551 */ 0xBA /* ':' -> */, -/* pos 03cf: 552 */ 0x00, 0x42 /* - terminal marker 66 - */, -/* pos 03d1: 553 */ 0xF2 /* 'r' -> */, -/* pos 03d2: 554 */ 0xE9 /* 'i' -> */, -/* pos 03d3: 555 */ 0xE3 /* 'c' -> */, -/* pos 03d4: 556 */ 0xF4 /* 't' -> */, -/* pos 03d5: 557 */ 0xAD /* '-' -> */, -/* pos 03d6: 558 */ 0xF4 /* 't' -> */, -/* pos 03d7: 559 */ 0xF2 /* 'r' -> */, -/* pos 03d8: 560 */ 0xE1 /* 'a' -> */, -/* pos 03d9: 561 */ 0xEE /* 'n' -> */, -/* pos 03da: 562 */ 0xF3 /* 's' -> */, -/* pos 03db: 563 */ 0xF0 /* 'p' -> */, -/* pos 03dc: 564 */ 0xEF /* 'o' -> */, -/* pos 03dd: 565 */ 0xF2 /* 'r' -> */, -/* pos 03de: 566 */ 0xF4 /* 't' -> */, -/* pos 03df: 567 */ 0xAD /* '-' -> */, -/* pos 03e0: 568 */ 0xF3 /* 's' -> */, -/* pos 03e1: 569 */ 0xE5 /* 'e' -> */, -/* pos 03e2: 570 */ 0xE3 /* 'c' -> */, -/* pos 03e3: 571 */ 0xF5 /* 'u' -> */, -/* pos 03e4: 572 */ 0xF2 /* 'r' -> */, -/* pos 03e5: 573 */ 0xE9 /* 'i' -> */, -/* pos 03e6: 574 */ 0xF4 /* 't' -> */, -/* pos 03e7: 575 */ 0xF9 /* 'y' -> */, -/* pos 03e8: 576 */ 0xBA /* ':' -> */, -/* pos 03e9: 577 */ 0x00, 0x43 /* - terminal marker 67 - */, -/* pos 03eb: 578 */ 0x72 /* 'r' */, 0x07, 0x00 /* (to 0x03F2 state 579) */, - 0x65 /* 'e' */, 0x87, 0x00 /* (to 0x0475 state 680) */, - 0x08, /* fail */ -/* pos 03f2: 579 */ 0xE1 /* 'a' -> */, -/* pos 03f3: 580 */ 0xEE /* 'n' -> */, -/* pos 03f4: 581 */ 0xF3 /* 's' -> */, -/* pos 03f5: 582 */ 0xE6 /* 'f' -> */, -/* pos 03f6: 583 */ 0xE5 /* 'e' -> */, -/* pos 03f7: 584 */ 0xF2 /* 'r' -> */, -/* pos 03f8: 585 */ 0xAD /* '-' -> */, -/* pos 03f9: 586 */ 0xE5 /* 'e' -> */, -/* pos 03fa: 587 */ 0xEE /* 'n' -> */, -/* pos 03fb: 588 */ 0xE3 /* 'c' -> */, -/* pos 03fc: 589 */ 0xEF /* 'o' -> */, -/* pos 03fd: 590 */ 0xE4 /* 'd' -> */, -/* pos 03fe: 591 */ 0xE9 /* 'i' -> */, -/* pos 03ff: 592 */ 0xEE /* 'n' -> */, -/* pos 0400: 593 */ 0xE7 /* 'g' -> */, -/* pos 0401: 594 */ 0xBA /* ':' -> */, -/* pos 0402: 595 */ 0x00, 0x44 /* - terminal marker 68 - */, -/* pos 0404: 596 */ 0xE5 /* 'e' -> */, -/* pos 0405: 597 */ 0xF2 /* 'r' -> */, -/* pos 0406: 598 */ 0xAD /* '-' -> */, -/* pos 0407: 599 */ 0xE1 /* 'a' -> */, -/* pos 0408: 600 */ 0xE7 /* 'g' -> */, -/* pos 0409: 601 */ 0xE5 /* 'e' -> */, -/* pos 040a: 602 */ 0xEE /* 'n' -> */, -/* pos 040b: 603 */ 0xF4 /* 't' -> */, -/* pos 040c: 604 */ 0xBA /* ':' -> */, -/* pos 040d: 605 */ 0x00, 0x45 /* - terminal marker 69 - */, -/* pos 040f: 606 */ 0x61 /* 'a' */, 0x07, 0x00 /* (to 0x0416 state 607) */, - 0x69 /* 'i' */, 0x09, 0x00 /* (to 0x041B state 611) */, - 0x08, /* fail */ -/* pos 0416: 607 */ 0xF2 /* 'r' -> */, -/* pos 0417: 608 */ 0xF9 /* 'y' -> */, -/* pos 0418: 609 */ 0xBA /* ':' -> */, -/* pos 0419: 610 */ 0x00, 0x46 /* - terminal marker 70 - */, -/* pos 041b: 611 */ 0xE1 /* 'a' -> */, -/* pos 041c: 612 */ 0xBA /* ':' -> */, -/* pos 041d: 613 */ 0x00, 0x47 /* - terminal marker 71 - */, -/* pos 041f: 614 */ 0xF7 /* 'w' -> */, -/* pos 0420: 615 */ 0xF7 /* 'w' -> */, -/* pos 0421: 616 */ 0xAD /* '-' -> */, -/* pos 0422: 617 */ 0xE1 /* 'a' -> */, -/* pos 0423: 618 */ 0xF5 /* 'u' -> */, -/* pos 0424: 619 */ 0xF4 /* 't' -> */, -/* pos 0425: 620 */ 0xE8 /* 'h' -> */, -/* pos 0426: 621 */ 0xE5 /* 'e' -> */, -/* pos 0427: 622 */ 0xEE /* 'n' -> */, -/* pos 0428: 623 */ 0xF4 /* 't' -> */, -/* pos 0429: 624 */ 0xE9 /* 'i' -> */, -/* pos 042a: 625 */ 0xE3 /* 'c' -> */, -/* pos 042b: 626 */ 0xE1 /* 'a' -> */, -/* pos 042c: 627 */ 0xF4 /* 't' -> */, -/* pos 042d: 628 */ 0xE5 /* 'e' -> */, -/* pos 042e: 629 */ 0xBA /* ':' -> */, -/* pos 042f: 630 */ 0x00, 0x48 /* - terminal marker 72 - */, -/* pos 0431: 631 */ 0xF4 /* 't' -> */, -/* pos 0432: 632 */ 0xE3 /* 'c' -> */, -/* pos 0433: 633 */ 0xE8 /* 'h' -> */, -/* pos 0434: 634 */ 0x00, 0x49 /* - terminal marker 73 - */, -/* pos 0436: 635 */ 0xF4 /* 't' -> */, -/* pos 0437: 636 */ 0x00, 0x4A /* - terminal marker 74 - */, -/* pos 0439: 637 */ 0xEC /* 'l' -> */, -/* pos 043a: 638 */ 0xE5 /* 'e' -> */, -/* pos 043b: 639 */ 0xF4 /* 't' -> */, -/* pos 043c: 640 */ 0xE5 /* 'e' -> */, -/* pos 043d: 641 */ 0x00, 0x4B /* - terminal marker 75 - */, -/* pos 043f: 642 */ 0xE9 /* 'i' -> */, -/* pos 0440: 643 */ 0xAD /* '-' -> */, -/* pos 0441: 644 */ 0xE1 /* 'a' -> */, -/* pos 0442: 645 */ 0xF2 /* 'r' -> */, -/* pos 0443: 646 */ 0xE7 /* 'g' -> */, -/* pos 0444: 647 */ 0xF3 /* 's' -> */, -/* pos 0445: 648 */ 0x00, 0x4C /* - terminal marker 76 - */, -/* pos 0447: 649 */ 0x00, 0x4D /* - terminal marker 77 - */, -/* pos 0449: 650 */ 0xAD /* '-' -> */, -/* pos 044a: 651 */ 0x72 /* 'r' */, 0x0A, 0x00 /* (to 0x0454 state 652) */, - 0x66 /* 'f' */, 0x13, 0x00 /* (to 0x0460 state 662) */, - 0x61 /* 'a' */, 0x3C, 0x00 /* (to 0x048C state 700) */, - 0x08, /* fail */ -/* pos 0454: 652 */ 0xE5 /* 'e' -> */, -/* pos 0455: 653 */ 0xE1 /* 'a' -> */, -/* pos 0456: 654 */ 0xEC /* 'l' -> */, -/* pos 0457: 655 */ 0xAD /* '-' -> */, -/* pos 0458: 656 */ 0xE9 /* 'i' -> */, -/* pos 0459: 657 */ 0xF0 /* 'p' -> */, -/* pos 045a: 658 */ 0xBA /* ':' -> */, -/* pos 045b: 659 */ 0x00, 0x4E /* - terminal marker 78 - */, -/* pos 045d: 660 */ 0xA0 /* ' ' -> */, -/* pos 045e: 661 */ 0x00, 0x4F /* - terminal marker 79 - */, -/* pos 0460: 662 */ 0xEF /* 'o' -> */, -/* pos 0461: 663 */ 0xF2 /* 'r' -> */, -/* pos 0462: 664 */ 0xF7 /* 'w' -> */, -/* pos 0463: 665 */ 0xE1 /* 'a' -> */, -/* pos 0464: 666 */ 0xF2 /* 'r' -> */, -/* pos 0465: 667 */ 0xE4 /* 'd' -> */, -/* pos 0466: 668 */ 0xE5 /* 'e' -> */, -/* pos 0467: 669 */ 0xE4 /* 'd' -> */, -/* pos 0468: 670 */ 0xAD /* '-' -> */, -/* pos 0469: 671 */ 0xE6 /* 'f' -> */, -/* pos 046a: 672 */ 0xEF /* 'o' -> */, -/* pos 046b: 673 */ 0xF2 /* 'r' -> */, -/* pos 046c: 674 */ 0x00, 0x50 /* - terminal marker 80 - */, -/* pos 046e: 675 */ 0x00, 0x51 /* - terminal marker 81 - */, -/* pos 0470: 676 */ 0xE1 /* 'a' -> */, -/* pos 0471: 677 */ 0xE4 /* 'd' -> */, -/* pos 0472: 678 */ 0xA0 /* ' ' -> */, -/* pos 0473: 679 */ 0x00, 0x52 /* - terminal marker 82 - */, -/* pos 0475: 680 */ 0xBA /* ':' -> */, -/* pos 0476: 681 */ 0x00, 0x53 /* - terminal marker 83 - */, -/* pos 0478: 682 */ 0xEC /* 'l' -> */, -/* pos 0479: 683 */ 0xE1 /* 'a' -> */, -/* pos 047a: 684 */ 0xF9 /* 'y' -> */, -/* pos 047b: 685 */ 0xAD /* '-' -> */, -/* pos 047c: 686 */ 0xEE /* 'n' -> */, -/* pos 047d: 687 */ 0xEF /* 'o' -> */, -/* pos 047e: 688 */ 0xEE /* 'n' -> */, -/* pos 047f: 689 */ 0xE3 /* 'c' -> */, -/* pos 0480: 690 */ 0xE5 /* 'e' -> */, -/* pos 0481: 691 */ 0xBA /* ':' -> */, -/* pos 0482: 692 */ 0x00, 0x54 /* - terminal marker 84 - */, -/* pos 0484: 693 */ 0xEF /* 'o' -> */, -/* pos 0485: 694 */ 0xF4 /* 't' -> */, -/* pos 0486: 695 */ 0xEF /* 'o' -> */, -/* pos 0487: 696 */ 0xE3 /* 'c' -> */, -/* pos 0488: 697 */ 0xEF /* 'o' -> */, -/* pos 0489: 698 */ 0xEC /* 'l' -> */, -/* pos 048a: 699 */ 0x00, 0x55 /* - terminal marker 85 - */, -/* pos 048c: 700 */ 0xF5 /* 'u' -> */, -/* pos 048d: 701 */ 0xF4 /* 't' -> */, -/* pos 048e: 702 */ 0xE8 /* 'h' -> */, -/* pos 048f: 703 */ 0xAD /* '-' -> */, -/* pos 0490: 704 */ 0xF4 /* 't' -> */, +/* pos 020f: 251 */ 0xE3 /* 'c' -> */, +/* pos 0210: 252 */ 0xE8 /* 'h' -> */, +/* pos 0211: 253 */ 0xBA /* ':' -> */, +/* pos 0212: 254 */ 0x00, 0x2C /* - terminal marker 44 - */, +/* pos 0214: 255 */ 0xE1 /* 'a' -> */, +/* pos 0215: 256 */ 0xEE /* 'n' -> */, +/* pos 0216: 257 */ 0xE7 /* 'g' -> */, +/* pos 0217: 258 */ 0xE5 /* 'e' -> */, +/* pos 0218: 259 */ 0xBA /* ':' -> */, +/* pos 0219: 260 */ 0x00, 0x2D /* - terminal marker 45 - */, +/* pos 021b: 261 */ 0xEE /* 'n' -> */, +/* pos 021c: 262 */ 0xED /* 'm' -> */, +/* pos 021d: 263 */ 0xEF /* 'o' -> */, +/* pos 021e: 264 */ 0xE4 /* 'd' -> */, +/* pos 021f: 265 */ 0xE9 /* 'i' -> */, +/* pos 0220: 266 */ 0xE6 /* 'f' -> */, +/* pos 0221: 267 */ 0xE9 /* 'i' -> */, +/* pos 0222: 268 */ 0xE5 /* 'e' -> */, +/* pos 0223: 269 */ 0xE4 /* 'd' -> */, +/* pos 0224: 270 */ 0xAD /* '-' -> */, +/* pos 0225: 271 */ 0xF3 /* 's' -> */, +/* pos 0226: 272 */ 0xE9 /* 'i' -> */, +/* pos 0227: 273 */ 0xEE /* 'n' -> */, +/* pos 0228: 274 */ 0xE3 /* 'c' -> */, +/* pos 0229: 275 */ 0xE5 /* 'e' -> */, +/* pos 022a: 276 */ 0xBA /* ':' -> */, +/* pos 022b: 277 */ 0x00, 0x2E /* - terminal marker 46 - */, +/* pos 022d: 278 */ 0x61 /* 'a' */, 0x0A, 0x00 /* (to 0x0237 state 279) */, + 0x69 /* 'i' */, 0x15, 0x00 /* (to 0x0245 state 292) */, + 0x6F /* 'o' */, 0x17, 0x00 /* (to 0x024A state 296) */, + 0x08, /* fail */ +/* pos 0237: 279 */ 0xF3 /* 's' -> */, +/* pos 0238: 280 */ 0xF4 /* 't' -> */, +/* pos 0239: 281 */ 0xAD /* '-' -> */, +/* pos 023a: 282 */ 0xED /* 'm' -> */, +/* pos 023b: 283 */ 0xEF /* 'o' -> */, +/* pos 023c: 284 */ 0xE4 /* 'd' -> */, +/* pos 023d: 285 */ 0xE9 /* 'i' -> */, +/* pos 023e: 286 */ 0xE6 /* 'f' -> */, +/* pos 023f: 287 */ 0xE9 /* 'i' -> */, +/* pos 0240: 288 */ 0xE5 /* 'e' -> */, +/* pos 0241: 289 */ 0xE4 /* 'd' -> */, +/* pos 0242: 290 */ 0xBA /* ':' -> */, +/* pos 0243: 291 */ 0x00, 0x2F /* - terminal marker 47 - */, +/* pos 0245: 292 */ 0xEE /* 'n' -> */, +/* pos 0246: 293 */ 0xEB /* 'k' -> */, +/* pos 0247: 294 */ 0xBA /* ':' -> */, +/* pos 0248: 295 */ 0x00, 0x30 /* - terminal marker 48 - */, +/* pos 024a: 296 */ 0xE3 /* 'c' -> */, +/* pos 024b: 297 */ 0xE1 /* 'a' -> */, +/* pos 024c: 298 */ 0xF4 /* 't' -> */, +/* pos 024d: 299 */ 0xE9 /* 'i' -> */, +/* pos 024e: 300 */ 0xEF /* 'o' -> */, +/* pos 024f: 301 */ 0xEE /* 'n' -> */, +/* pos 0250: 302 */ 0xBA /* ':' -> */, +/* pos 0251: 303 */ 0x00, 0x31 /* - terminal marker 49 - */, +/* pos 0253: 304 */ 0x66 /* 'f' */, 0x0A, 0x00 /* (to 0x025D state 305) */, + 0x74 /* 't' */, 0x14, 0x00 /* (to 0x026A state 311) */, + 0x70 /* 'p' */, 0x6F, 0x01 /* (to 0x03C8 state 578) */, + 0x08, /* fail */ +/* pos 025d: 305 */ 0x72 /* 'r' */, 0x07, 0x00 /* (to 0x0264 state 306) */, + 0x65 /* 'e' */, 0xB1, 0x00 /* (to 0x0311 state 430) */, + 0x08, /* fail */ +/* pos 0264: 306 */ 0xE5 /* 'e' -> */, +/* pos 0265: 307 */ 0xF3 /* 's' -> */, +/* pos 0266: 308 */ 0xE8 /* 'h' -> */, +/* pos 0267: 309 */ 0xBA /* ':' -> */, +/* pos 0268: 310 */ 0x00, 0x35 /* - terminal marker 53 - */, +/* pos 026a: 311 */ 0xF2 /* 'r' -> */, +/* pos 026b: 312 */ 0xF9 /* 'y' -> */, +/* pos 026c: 313 */ 0xAD /* '-' -> */, +/* pos 026d: 314 */ 0xE1 /* 'a' -> */, +/* pos 026e: 315 */ 0xE6 /* 'f' -> */, +/* pos 026f: 316 */ 0xF4 /* 't' -> */, +/* pos 0270: 317 */ 0xE5 /* 'e' -> */, +/* pos 0271: 318 */ 0xF2 /* 'r' -> */, +/* pos 0272: 319 */ 0xBA /* ':' -> */, +/* pos 0273: 320 */ 0x00, 0x36 /* - terminal marker 54 - */, +/* pos 0275: 321 */ 0x65 /* 'e' */, 0x07, 0x00 /* (to 0x027C state 322) */, + 0x74 /* 't' */, 0xED, 0x00 /* (to 0x0365 state 496) */, + 0x08, /* fail */ +/* pos 027c: 322 */ 0x72 /* 'r' */, 0x0A, 0x00 /* (to 0x0286 state 323) */, + 0x74 /* 't' */, 0x0D, 0x00 /* (to 0x028C state 328) */, + 0x63 /* 'c' */, 0x52, 0x01 /* (to 0x03D4 state 589) */, + 0x08, /* fail */ +/* pos 0286: 323 */ 0xF6 /* 'v' -> */, +/* pos 0287: 324 */ 0xE5 /* 'e' -> */, +/* pos 0288: 325 */ 0xF2 /* 'r' -> */, +/* pos 0289: 326 */ 0xBA /* ':' -> */, +/* pos 028a: 327 */ 0x00, 0x37 /* - terminal marker 55 - */, +/* pos 028c: 328 */ 0xAD /* '-' -> */, +/* pos 028d: 329 */ 0xE3 /* 'c' -> */, +/* pos 028e: 330 */ 0xEF /* 'o' -> */, +/* pos 028f: 331 */ 0xEF /* 'o' -> */, +/* pos 0290: 332 */ 0xEB /* 'k' -> */, +/* pos 0291: 333 */ 0xE9 /* 'i' -> */, +/* pos 0292: 334 */ 0xE5 /* 'e' -> */, +/* pos 0293: 335 */ 0xBA /* ':' -> */, +/* pos 0294: 336 */ 0x00, 0x38 /* - terminal marker 56 - */, +/* pos 0296: 337 */ 0x72 /* 'r' */, 0x07, 0x00 /* (to 0x029D state 338) */, + 0x65 /* 'e' */, 0x2C, 0x01 /* (to 0x03C5 state 576) */, + 0x08, /* fail */ +/* pos 029d: 338 */ 0xE1 /* 'a' -> */, +/* pos 029e: 339 */ 0xEE /* 'n' -> */, +/* pos 029f: 340 */ 0xF3 /* 's' -> */, +/* pos 02a0: 341 */ 0xE6 /* 'f' -> */, +/* pos 02a1: 342 */ 0xE5 /* 'e' -> */, +/* pos 02a2: 343 */ 0xF2 /* 'r' -> */, +/* pos 02a3: 344 */ 0xAD /* '-' -> */, +/* pos 02a4: 345 */ 0xE5 /* 'e' -> */, +/* pos 02a5: 346 */ 0xEE /* 'n' -> */, +/* pos 02a6: 347 */ 0xE3 /* 'c' -> */, +/* pos 02a7: 348 */ 0xEF /* 'o' -> */, +/* pos 02a8: 349 */ 0xE4 /* 'd' -> */, +/* pos 02a9: 350 */ 0xE9 /* 'i' -> */, +/* pos 02aa: 351 */ 0xEE /* 'n' -> */, +/* pos 02ab: 352 */ 0xE7 /* 'g' -> */, +/* pos 02ac: 353 */ 0xBA /* ':' -> */, +/* pos 02ad: 354 */ 0x00, 0x3A /* - terminal marker 58 - */, +/* pos 02af: 355 */ 0xE9 /* 'i' -> */, +/* pos 02b0: 356 */ 0xAD /* '-' -> */, +/* pos 02b1: 357 */ 0xE1 /* 'a' -> */, +/* pos 02b2: 358 */ 0xF2 /* 'r' -> */, +/* pos 02b3: 359 */ 0xE7 /* 'g' -> */, +/* pos 02b4: 360 */ 0xF3 /* 's' -> */, +/* pos 02b5: 361 */ 0x00, 0x42 /* - terminal marker 66 - */, +/* pos 02b7: 362 */ 0xA0 /* ' ' -> */, +/* pos 02b8: 363 */ 0x00, 0x45 /* - terminal marker 69 - */, +/* pos 02ba: 364 */ 0xAD /* '-' -> */, +/* pos 02bb: 365 */ 0x66 /* 'f' */, 0x0A, 0x00 /* (to 0x02C5 state 366) */, + 0x61 /* 'a' */, 0x1D, 0x00 /* (to 0x02DB state 385) */, + 0x72 /* 'r' */, 0xFB, 0x00 /* (to 0x03BC state 568) */, + 0x08, /* fail */ +/* pos 02c5: 366 */ 0xEF /* 'o' -> */, +/* pos 02c6: 367 */ 0xF2 /* 'r' -> */, +/* pos 02c7: 368 */ 0xF7 /* 'w' -> */, +/* pos 02c8: 369 */ 0xE1 /* 'a' -> */, +/* pos 02c9: 370 */ 0xF2 /* 'r' -> */, +/* pos 02ca: 371 */ 0xE4 /* 'd' -> */, +/* pos 02cb: 372 */ 0xE5 /* 'e' -> */, +/* pos 02cc: 373 */ 0xE4 /* 'd' -> */, +/* pos 02cd: 374 */ 0xAD /* '-' -> */, +/* pos 02ce: 375 */ 0xE6 /* 'f' -> */, +/* pos 02cf: 376 */ 0xEF /* 'o' -> */, +/* pos 02d0: 377 */ 0xF2 /* 'r' -> */, +/* pos 02d1: 378 */ 0xBA /* ':' -> */, +/* pos 02d2: 379 */ 0x00, 0x46 /* - terminal marker 70 - */, +/* pos 02d4: 380 */ 0x00, 0x47 /* - terminal marker 71 - */, +/* pos 02d6: 381 */ 0xE1 /* 'a' -> */, +/* pos 02d7: 382 */ 0xE4 /* 'd' -> */, +/* pos 02d8: 383 */ 0xA0 /* ' ' -> */, +/* pos 02d9: 384 */ 0x00, 0x48 /* - terminal marker 72 - */, +/* pos 02db: 385 */ 0xF5 /* 'u' -> */, +/* pos 02dc: 386 */ 0xF4 /* 't' -> */, +/* pos 02dd: 387 */ 0xE8 /* 'h' -> */, +/* pos 02de: 388 */ 0xAD /* '-' -> */, +/* pos 02df: 389 */ 0xF4 /* 't' -> */, +/* pos 02e0: 390 */ 0xEF /* 'o' -> */, +/* pos 02e1: 391 */ 0xEB /* 'k' -> */, +/* pos 02e2: 392 */ 0xE5 /* 'e' -> */, +/* pos 02e3: 393 */ 0xEE /* 'n' -> */, +/* pos 02e4: 394 */ 0xBA /* ':' -> */, +/* pos 02e5: 395 */ 0x00, 0x4C /* - terminal marker 76 - */, +/* pos 02e7: 396 */ 0xF4 /* 't' -> */, +/* pos 02e8: 397 */ 0xE9 /* 'i' -> */, +/* pos 02e9: 398 */ 0xEF /* 'o' -> */, +/* pos 02ea: 399 */ 0xEE /* 'n' -> */, +/* pos 02eb: 400 */ 0xF3 /* 's' -> */, +/* pos 02ec: 401 */ 0xA0 /* ' ' -> */, +/* pos 02ed: 402 */ 0x00, 0x02 /* - terminal marker 2 - */, +/* pos 02ef: 403 */ 0xF3 /* 's' -> */, +/* pos 02f0: 404 */ 0xAD /* '-' -> */, +/* pos 02f1: 405 */ 0xE3 /* 'c' -> */, +/* pos 02f2: 406 */ 0xEF /* 'o' -> */, +/* pos 02f3: 407 */ 0xEE /* 'n' -> */, +/* pos 02f4: 408 */ 0xF4 /* 't' -> */, +/* pos 02f5: 409 */ 0xF2 /* 'r' -> */, +/* pos 02f6: 410 */ 0xEF /* 'o' -> */, +/* pos 02f7: 411 */ 0xEC /* 'l' -> */, +/* pos 02f8: 412 */ 0xAD /* '-' -> */, +/* pos 02f9: 413 */ 0x72 /* 'r' */, 0x07, 0x00 /* (to 0x0300 state 414) */, + 0x61 /* 'a' */, 0x24, 0x00 /* (to 0x0320 state 443) */, + 0x08, /* fail */ +/* pos 0300: 414 */ 0xE5 /* 'e' -> */, +/* pos 0301: 415 */ 0xF1 /* 'q' -> */, +/* pos 0302: 416 */ 0xF5 /* 'u' -> */, +/* pos 0303: 417 */ 0xE5 /* 'e' -> */, +/* pos 0304: 418 */ 0xF3 /* 's' -> */, +/* pos 0305: 419 */ 0xF4 /* 't' -> */, +/* pos 0306: 420 */ 0xAD /* '-' -> */, +/* pos 0307: 421 */ 0xE8 /* 'h' -> */, +/* pos 0308: 422 */ 0xE5 /* 'e' -> */, +/* pos 0309: 423 */ 0xE1 /* 'a' -> */, +/* pos 030a: 424 */ 0xE4 /* 'd' -> */, +/* pos 030b: 425 */ 0xE5 /* 'e' -> */, +/* pos 030c: 426 */ 0xF2 /* 'r' -> */, +/* pos 030d: 427 */ 0xF3 /* 's' -> */, +/* pos 030e: 428 */ 0xBA /* ':' -> */, +/* pos 030f: 429 */ 0x00, 0x0B /* - terminal marker 11 - */, +/* pos 0311: 430 */ 0xF2 /* 'r' -> */, +/* pos 0312: 431 */ 0xE5 /* 'e' -> */, +/* pos 0313: 432 */ 0xF2 /* 'r' -> */, +/* pos 0314: 433 */ 0xBA /* ':' -> */, +/* pos 0315: 434 */ 0x00, 0x18 /* - terminal marker 24 - */, +/* pos 0317: 435 */ 0xE8 /* 'h' -> */, +/* pos 0318: 436 */ 0xE1 /* 'a' -> */, +/* pos 0319: 437 */ 0xF2 /* 'r' -> */, +/* pos 031a: 438 */ 0xF3 /* 's' -> */, +/* pos 031b: 439 */ 0xE5 /* 'e' -> */, +/* pos 031c: 440 */ 0xF4 /* 't' -> */, +/* pos 031d: 441 */ 0xBA /* ':' -> */, +/* pos 031e: 442 */ 0x00, 0x1E /* - terminal marker 30 - */, +/* pos 0320: 443 */ 0xEC /* 'l' -> */, +/* pos 0321: 444 */ 0xEC /* 'l' -> */, +/* pos 0322: 445 */ 0xEF /* 'o' -> */, +/* pos 0323: 446 */ 0xF7 /* 'w' -> */, +/* pos 0324: 447 */ 0xAD /* '-' -> */, +/* pos 0325: 448 */ 0xEF /* 'o' -> */, +/* pos 0326: 449 */ 0xF2 /* 'r' -> */, +/* pos 0327: 450 */ 0xE9 /* 'i' -> */, +/* pos 0328: 451 */ 0xE7 /* 'g' -> */, +/* pos 0329: 452 */ 0xE9 /* 'i' -> */, +/* pos 032a: 453 */ 0xEE /* 'n' -> */, +/* pos 032b: 454 */ 0xBA /* ':' -> */, +/* pos 032c: 455 */ 0x00, 0x20 /* - terminal marker 32 - */, +/* pos 032e: 456 */ 0xE1 /* 'a' -> */, +/* pos 032f: 457 */ 0xF8 /* 'x' -> */, +/* pos 0330: 458 */ 0xAD /* '-' -> */, +/* pos 0331: 459 */ 0xE6 /* 'f' -> */, +/* pos 0332: 460 */ 0xEF /* 'o' -> */, +/* pos 0333: 461 */ 0xF2 /* 'r' -> */, +/* pos 0334: 462 */ 0xF7 /* 'w' -> */, +/* pos 0335: 463 */ 0xE1 /* 'a' -> */, +/* pos 0336: 464 */ 0xF2 /* 'r' -> */, +/* pos 0337: 465 */ 0xE4 /* 'd' -> */, +/* pos 0338: 466 */ 0xF3 /* 's' -> */, +/* pos 0339: 467 */ 0xBA /* ':' -> */, +/* pos 033a: 468 */ 0x00, 0x32 /* - terminal marker 50 - */, +/* pos 033c: 469 */ 0xF8 /* 'x' -> */, +/* pos 033d: 470 */ 0xF9 /* 'y' -> */, +/* pos 033e: 471 */ 0x2D /* '-' */, 0x07, 0x00 /* (to 0x0345 state 472) */, + 0x20 /* ' ' */, 0x79, 0x00 /* (to 0x03BA state 567) */, + 0x08, /* fail */ +/* pos 0345: 472 */ 0xE1 /* 'a' -> */, +/* pos 0346: 473 */ 0xF5 /* 'u' -> */, +/* pos 0347: 474 */ 0xF4 /* 't' -> */, +/* pos 0348: 475 */ 0xE8 /* 'h' -> */, +/* pos 0349: 476 */ 0x65 /* 'e' */, 0x07, 0x00 /* (to 0x0350 state 477) */, + 0x6F /* 'o' */, 0x0E, 0x00 /* (to 0x035A state 486) */, + 0x08, /* fail */ +/* pos 0350: 477 */ 0xEE /* 'n' -> */, +/* pos 0351: 478 */ 0xF4 /* 't' -> */, +/* pos 0352: 479 */ 0xE9 /* 'i' -> */, +/* pos 0353: 480 */ 0xE3 /* 'c' -> */, +/* pos 0354: 481 */ 0xE1 /* 'a' -> */, +/* pos 0355: 482 */ 0xF4 /* 't' -> */, +/* pos 0356: 483 */ 0xE5 /* 'e' -> */, +/* pos 0357: 484 */ 0xBA /* ':' -> */, +/* pos 0358: 485 */ 0x00, 0x33 /* - terminal marker 51 - */, +/* pos 035a: 486 */ 0xF2 /* 'r' -> */, +/* pos 035b: 487 */ 0xE9 /* 'i' -> */, +/* pos 035c: 488 */ 0xFA /* 'z' -> */, +/* pos 035d: 489 */ 0xE1 /* 'a' -> */, +/* pos 035e: 490 */ 0xF4 /* 't' -> */, +/* pos 035f: 491 */ 0xE9 /* 'i' -> */, +/* pos 0360: 492 */ 0xEF /* 'o' -> */, +/* pos 0361: 493 */ 0xEE /* 'n' -> */, +/* pos 0362: 494 */ 0xBA /* ':' -> */, +/* pos 0363: 495 */ 0x00, 0x34 /* - terminal marker 52 - */, +/* pos 0365: 496 */ 0xF2 /* 'r' -> */, +/* pos 0366: 497 */ 0xE9 /* 'i' -> */, +/* pos 0367: 498 */ 0xE3 /* 'c' -> */, +/* pos 0368: 499 */ 0xF4 /* 't' -> */, +/* pos 0369: 500 */ 0xAD /* '-' -> */, +/* pos 036a: 501 */ 0xF4 /* 't' -> */, +/* pos 036b: 502 */ 0xF2 /* 'r' -> */, +/* pos 036c: 503 */ 0xE1 /* 'a' -> */, +/* pos 036d: 504 */ 0xEE /* 'n' -> */, +/* pos 036e: 505 */ 0xF3 /* 's' -> */, +/* pos 036f: 506 */ 0xF0 /* 'p' -> */, +/* pos 0370: 507 */ 0xEF /* 'o' -> */, +/* pos 0371: 508 */ 0xF2 /* 'r' -> */, +/* pos 0372: 509 */ 0xF4 /* 't' -> */, +/* pos 0373: 510 */ 0xAD /* '-' -> */, +/* pos 0374: 511 */ 0xF3 /* 's' -> */, +/* pos 0375: 512 */ 0xE5 /* 'e' -> */, +/* pos 0376: 513 */ 0xE3 /* 'c' -> */, +/* pos 0377: 514 */ 0xF5 /* 'u' -> */, +/* pos 0378: 515 */ 0xF2 /* 'r' -> */, +/* pos 0379: 516 */ 0xE9 /* 'i' -> */, +/* pos 037a: 517 */ 0xF4 /* 't' -> */, +/* pos 037b: 518 */ 0xF9 /* 'y' -> */, +/* pos 037c: 519 */ 0xBA /* ':' -> */, +/* pos 037d: 520 */ 0x00, 0x39 /* - terminal marker 57 - */, +/* pos 037f: 521 */ 0xE5 /* 'e' -> */, +/* pos 0380: 522 */ 0xF2 /* 'r' -> */, +/* pos 0381: 523 */ 0xAD /* '-' -> */, +/* pos 0382: 524 */ 0xE1 /* 'a' -> */, +/* pos 0383: 525 */ 0xE7 /* 'g' -> */, +/* pos 0384: 526 */ 0xE5 /* 'e' -> */, +/* pos 0385: 527 */ 0xEE /* 'n' -> */, +/* pos 0386: 528 */ 0xF4 /* 't' -> */, +/* pos 0387: 529 */ 0xBA /* ':' -> */, +/* pos 0388: 530 */ 0x00, 0x3B /* - terminal marker 59 - */, +/* pos 038a: 531 */ 0x61 /* 'a' */, 0x07, 0x00 /* (to 0x0391 state 532) */, + 0x69 /* 'i' */, 0x09, 0x00 /* (to 0x0396 state 536) */, + 0x08, /* fail */ +/* pos 0391: 532 */ 0xF2 /* 'r' -> */, +/* pos 0392: 533 */ 0xF9 /* 'y' -> */, +/* pos 0393: 534 */ 0xBA /* ':' -> */, +/* pos 0394: 535 */ 0x00, 0x3C /* - terminal marker 60 - */, +/* pos 0396: 536 */ 0xE1 /* 'a' -> */, +/* pos 0397: 537 */ 0xBA /* ':' -> */, +/* pos 0398: 538 */ 0x00, 0x3D /* - terminal marker 61 - */, +/* pos 039a: 539 */ 0xF7 /* 'w' -> */, +/* pos 039b: 540 */ 0xF7 /* 'w' -> */, +/* pos 039c: 541 */ 0xAD /* '-' -> */, +/* pos 039d: 542 */ 0xE1 /* 'a' -> */, +/* pos 039e: 543 */ 0xF5 /* 'u' -> */, +/* pos 039f: 544 */ 0xF4 /* 't' -> */, +/* pos 03a0: 545 */ 0xE8 /* 'h' -> */, +/* pos 03a1: 546 */ 0xE5 /* 'e' -> */, +/* pos 03a2: 547 */ 0xEE /* 'n' -> */, +/* pos 03a3: 548 */ 0xF4 /* 't' -> */, +/* pos 03a4: 549 */ 0xE9 /* 'i' -> */, +/* pos 03a5: 550 */ 0xE3 /* 'c' -> */, +/* pos 03a6: 551 */ 0xE1 /* 'a' -> */, +/* pos 03a7: 552 */ 0xF4 /* 't' -> */, +/* pos 03a8: 553 */ 0xE5 /* 'e' -> */, +/* pos 03a9: 554 */ 0xBA /* ':' -> */, +/* pos 03aa: 555 */ 0x00, 0x3E /* - terminal marker 62 - */, +/* pos 03ac: 556 */ 0xF4 /* 't' -> */, +/* pos 03ad: 557 */ 0xE3 /* 'c' -> */, +/* pos 03ae: 558 */ 0xE8 /* 'h' -> */, +/* pos 03af: 559 */ 0x00, 0x3F /* - terminal marker 63 - */, +/* pos 03b1: 560 */ 0xF4 /* 't' -> */, +/* pos 03b2: 561 */ 0x00, 0x40 /* - terminal marker 64 - */, +/* pos 03b4: 562 */ 0xEC /* 'l' -> */, +/* pos 03b5: 563 */ 0xE5 /* 'e' -> */, +/* pos 03b6: 564 */ 0xF4 /* 't' -> */, +/* pos 03b7: 565 */ 0xE5 /* 'e' -> */, +/* pos 03b8: 566 */ 0x00, 0x41 /* - terminal marker 65 - */, +/* pos 03ba: 567 */ 0x00, 0x43 /* - terminal marker 67 - */, +/* pos 03bc: 568 */ 0xE5 /* 'e' -> */, +/* pos 03bd: 569 */ 0xE1 /* 'a' -> */, +/* pos 03be: 570 */ 0xEC /* 'l' -> */, +/* pos 03bf: 571 */ 0xAD /* '-' -> */, +/* pos 03c0: 572 */ 0xE9 /* 'i' -> */, +/* pos 03c1: 573 */ 0xF0 /* 'p' -> */, +/* pos 03c2: 574 */ 0xBA /* ':' -> */, +/* pos 03c3: 575 */ 0x00, 0x44 /* - terminal marker 68 - */, +/* pos 03c5: 576 */ 0xBA /* ':' -> */, +/* pos 03c6: 577 */ 0x00, 0x49 /* - terminal marker 73 - */, +/* pos 03c8: 578 */ 0xEC /* 'l' -> */, +/* pos 03c9: 579 */ 0xE1 /* 'a' -> */, +/* pos 03ca: 580 */ 0xF9 /* 'y' -> */, +/* pos 03cb: 581 */ 0xAD /* '-' -> */, +/* pos 03cc: 582 */ 0xEE /* 'n' -> */, +/* pos 03cd: 583 */ 0xEF /* 'o' -> */, +/* pos 03ce: 584 */ 0xEE /* 'n' -> */, +/* pos 03cf: 585 */ 0xE3 /* 'c' -> */, +/* pos 03d0: 586 */ 0xE5 /* 'e' -> */, +/* pos 03d1: 587 */ 0xBA /* ':' -> */, +/* pos 03d2: 588 */ 0x00, 0x4A /* - terminal marker 74 - */, +/* pos 03d4: 589 */ 0xAD /* '-' -> */, +/* pos 03d5: 590 */ 0xF7 /* 'w' -> */, +/* pos 03d6: 591 */ 0xE5 /* 'e' -> */, +/* pos 03d7: 592 */ 0xE2 /* 'b' -> */, +/* pos 03d8: 593 */ 0xF3 /* 's' -> */, +/* pos 03d9: 594 */ 0xEF /* 'o' -> */, +/* pos 03da: 595 */ 0xE3 /* 'c' -> */, +/* pos 03db: 596 */ 0xEB /* 'k' -> */, +/* pos 03dc: 597 */ 0xE5 /* 'e' -> */, +/* pos 03dd: 598 */ 0xF4 /* 't' -> */, +/* pos 03de: 599 */ 0xAD /* '-' -> */, +/* pos 03df: 600 */ 0x64 /* 'd' */, 0x19, 0x00 /* (to 0x03F8 state 601) */, + 0x65 /* 'e' */, 0x1D, 0x00 /* (to 0x03FF state 607) */, + 0x6B /* 'k' */, 0x26, 0x00 /* (to 0x040B state 618) */, + 0x70 /* 'p' */, 0x35, 0x00 /* (to 0x041D state 625) */, + 0x61 /* 'a' */, 0x3C, 0x00 /* (to 0x0427 state 634) */, + 0x6E /* 'n' */, 0x41, 0x00 /* (to 0x042F state 641) */, + 0x76 /* 'v' */, 0x47, 0x00 /* (to 0x0438 state 648) */, + 0x6F /* 'o' */, 0x4D, 0x00 /* (to 0x0441 state 656) */, + 0x08, /* fail */ +/* pos 03f8: 601 */ 0xF2 /* 'r' -> */, +/* pos 03f9: 602 */ 0xE1 /* 'a' -> */, +/* pos 03fa: 603 */ 0xE6 /* 'f' -> */, +/* pos 03fb: 604 */ 0xF4 /* 't' -> */, +/* pos 03fc: 605 */ 0xBA /* ':' -> */, +/* pos 03fd: 606 */ 0x00, 0x07 /* - terminal marker 7 - */, +/* pos 03ff: 607 */ 0xF8 /* 'x' -> */, +/* pos 0400: 608 */ 0xF4 /* 't' -> */, +/* pos 0401: 609 */ 0xE5 /* 'e' -> */, +/* pos 0402: 610 */ 0xEE /* 'n' -> */, +/* pos 0403: 611 */ 0xF3 /* 's' -> */, +/* pos 0404: 612 */ 0xE9 /* 'i' -> */, +/* pos 0405: 613 */ 0xEF /* 'o' -> */, +/* pos 0406: 614 */ 0xEE /* 'n' -> */, +/* pos 0407: 615 */ 0xF3 /* 's' -> */, +/* pos 0408: 616 */ 0xBA /* ':' -> */, +/* pos 0409: 617 */ 0x00, 0x09 /* - terminal marker 9 - */, +/* pos 040b: 618 */ 0xE5 /* 'e' -> */, +/* pos 040c: 619 */ 0xF9 /* 'y' -> */, +/* pos 040d: 620 */ 0x31 /* '1' */, 0x0A, 0x00 /* (to 0x0417 state 621) */, + 0x32 /* '2' */, 0x0A, 0x00 /* (to 0x041A state 623) */, + 0x3A /* ':' */, 0x23, 0x00 /* (to 0x0436 state 647) */, + 0x08, /* fail */ +/* pos 0417: 621 */ 0xBA /* ':' -> */, +/* pos 0418: 622 */ 0x00, 0x0A /* - terminal marker 10 - */, +/* pos 041a: 623 */ 0xBA /* ':' -> */, +/* pos 041b: 624 */ 0x00, 0x0B /* - terminal marker 11 - */, +/* pos 041d: 625 */ 0xF2 /* 'r' -> */, +/* pos 041e: 626 */ 0xEF /* 'o' -> */, +/* pos 041f: 627 */ 0xF4 /* 't' -> */, +/* pos 0420: 628 */ 0xEF /* 'o' -> */, +/* pos 0421: 629 */ 0xE3 /* 'c' -> */, +/* pos 0422: 630 */ 0xEF /* 'o' -> */, +/* pos 0423: 631 */ 0xEC /* 'l' -> */, +/* pos 0424: 632 */ 0xBA /* ':' -> */, +/* pos 0425: 633 */ 0x00, 0x0C /* - terminal marker 12 - */, +/* pos 0427: 634 */ 0xE3 /* 'c' -> */, +/* pos 0428: 635 */ 0xE3 /* 'c' -> */, +/* pos 0429: 636 */ 0xE5 /* 'e' -> */, +/* pos 042a: 637 */ 0xF0 /* 'p' -> */, +/* pos 042b: 638 */ 0xF4 /* 't' -> */, +/* pos 042c: 639 */ 0xBA /* ':' -> */, +/* pos 042d: 640 */ 0x00, 0x0D /* - terminal marker 13 - */, +/* pos 042f: 641 */ 0xEF /* 'o' -> */, +/* pos 0430: 642 */ 0xEE /* 'n' -> */, +/* pos 0431: 643 */ 0xE3 /* 'c' -> */, +/* pos 0432: 644 */ 0xE5 /* 'e' -> */, +/* pos 0433: 645 */ 0xBA /* ':' -> */, +/* pos 0434: 646 */ 0x00, 0x0E /* - terminal marker 14 - */, +/* pos 0436: 647 */ 0x00, 0x1F /* - terminal marker 31 - */, +/* pos 0438: 648 */ 0xE5 /* 'e' -> */, +/* pos 0439: 649 */ 0xF2 /* 'r' -> */, +/* pos 043a: 650 */ 0xF3 /* 's' -> */, +/* pos 043b: 651 */ 0xE9 /* 'i' -> */, +/* pos 043c: 652 */ 0xEF /* 'o' -> */, +/* pos 043d: 653 */ 0xEE /* 'n' -> */, +/* pos 043e: 654 */ 0xBA /* ':' -> */, +/* pos 043f: 655 */ 0x00, 0x20 /* - terminal marker 32 - */, +/* pos 0441: 656 */ 0xF2 /* 'r' -> */, +/* pos 0442: 657 */ 0xE9 /* 'i' -> */, +/* pos 0443: 658 */ 0xE7 /* 'g' -> */, +/* pos 0444: 659 */ 0xE9 /* 'i' -> */, +/* pos 0445: 660 */ 0xEE /* 'n' -> */, +/* pos 0446: 661 */ 0xBA /* ':' -> */, +/* pos 0447: 662 */ 0x00, 0x21 /* - terminal marker 33 - */, +/* pos 0449: 663 */ 0xAD /* '-' -> */, +/* pos 044a: 664 */ 0xF3 /* 's' -> */, +/* pos 044b: 665 */ 0xE5 /* 'e' -> */, +/* pos 044c: 666 */ 0xF4 /* 't' -> */, +/* pos 044d: 667 */ 0xF4 /* 't' -> */, +/* pos 044e: 668 */ 0xE9 /* 'i' -> */, +/* pos 044f: 669 */ 0xEE /* 'n' -> */, +/* pos 0450: 670 */ 0xE7 /* 'g' -> */, +/* pos 0451: 671 */ 0xF3 /* 's' -> */, +/* pos 0452: 672 */ 0xBA /* ':' -> */, +/* pos 0453: 673 */ 0x00, 0x09 /* - terminal marker 9 - */, +/* pos 0455: 674 */ 0x61 /* 'a' */, 0x0D, 0x00 /* (to 0x0462 state 675) */, + 0x6D /* 'm' */, 0x14, 0x00 /* (to 0x046C state 684) */, + 0x70 /* 'p' */, 0x18, 0x00 /* (to 0x0473 state 690) */, + 0x73 /* 's' */, 0x20, 0x00 /* (to 0x047E state 694) */, + 0x08, /* fail */ +/* pos 0462: 675 */ 0xF5 /* 'u' -> */, +/* pos 0463: 676 */ 0xF4 /* 't' -> */, +/* pos 0464: 677 */ 0xE8 /* 'h' -> */, +/* pos 0465: 678 */ 0xEF /* 'o' -> */, +/* pos 0466: 679 */ 0xF2 /* 'r' -> */, +/* pos 0467: 680 */ 0xE9 /* 'i' -> */, +/* pos 0468: 681 */ 0xF4 /* 't' -> */, +/* pos 0469: 682 */ 0xF9 /* 'y' -> */, +/* pos 046a: 683 */ 0x00, 0x19 /* - terminal marker 25 - */, +/* pos 046c: 684 */ 0xE5 /* 'e' -> */, +/* pos 046d: 685 */ 0xF4 /* 't' -> */, +/* pos 046e: 686 */ 0xE8 /* 'h' -> */, +/* pos 046f: 687 */ 0xEF /* 'o' -> */, +/* pos 0470: 688 */ 0xE4 /* 'd' -> */, +/* pos 0471: 689 */ 0x00, 0x1A /* - terminal marker 26 - */, +/* pos 0473: 690 */ 0x61 /* 'a' */, 0x07, 0x00 /* (to 0x047A state 691) */, + 0x72 /* 'r' */, 0x1B, 0x00 /* (to 0x0491 state 705) */, + 0x08, /* fail */ +/* pos 047a: 691 */ 0xF4 /* 't' -> */, +/* pos 047b: 692 */ 0xE8 /* 'h' -> */, +/* pos 047c: 693 */ 0x00, 0x1B /* - terminal marker 27 - */, +/* pos 047e: 694 */ 0x63 /* 'c' */, 0x07, 0x00 /* (to 0x0485 state 695) */, + 0x74 /* 't' */, 0x0A, 0x00 /* (to 0x048B state 700) */, + 0x08, /* fail */ +/* pos 0485: 695 */ 0xE8 /* 'h' -> */, +/* pos 0486: 696 */ 0xE5 /* 'e' -> */, +/* pos 0487: 697 */ 0xED /* 'm' -> */, +/* pos 0488: 698 */ 0xE5 /* 'e' -> */, +/* pos 0489: 699 */ 0x00, 0x1C /* - terminal marker 28 - */, +/* pos 048b: 700 */ 0xE1 /* 'a' -> */, +/* pos 048c: 701 */ 0xF4 /* 't' -> */, +/* pos 048d: 702 */ 0xF5 /* 'u' -> */, +/* pos 048e: 703 */ 0xF3 /* 's' -> */, +/* pos 048f: 704 */ 0x00, 0x1D /* - terminal marker 29 - */, +/* pos 0491: 705 */ 0xEF /* 'o' -> */, +/* pos 0492: 706 */ 0xF4 /* 't' -> */, +/* pos 0493: 707 */ 0xEF /* 'o' -> */, +/* pos 0494: 708 */ 0xE3 /* 'c' -> */, +/* pos 0495: 709 */ 0xEF /* 'o' -> */, +/* pos 0496: 710 */ 0xEC /* 'l' -> */, +/* pos 0497: 711 */ 0x00, 0x4B /* - terminal marker 75 - */, +/* total size 1177 bytes */ +#endif + +#if !defined(LWS_HTTP_HEADERS_ALL) && !defined(LWS_WITH_HTTP_UNCOMMON_HEADERS) && defined(LWS_ROLE_WS) && defined(LWS_ROLE_H2) + /* 0: 0: get */ + /* 1: 1: post */ + /* 2: 3: host: */ + /* 3: 4: connection: */ + /* 4: 5: upgrade: */ + /* 5: 6: origin: */ + /* 6: 7: sec-websocket-draft: */ + /* 7: 8: + */ + /* 8: 9: sec-websocket-extensions: */ + /* 9: 10: sec-websocket-key1: */ + /* 10: 11: sec-websocket-key2: */ + /* 11: 12: sec-websocket-protocol: */ + /* 12: 13: sec-websocket-accept: */ + /* 13: 14: sec-websocket-nonce: */ + /* 14: 15: http/1.1 */ + /* 15: 16: http2-settings: */ + /* 16: 17: accept: */ + /* 17: 19: if-modified-since: */ + /* 18: 20: if-none-match: */ + /* 19: 21: accept-encoding: */ + /* 20: 22: accept-language: */ + /* 21: 23: pragma: */ + /* 22: 24: cache-control: */ + /* 23: 25: authorization: */ + /* 24: 26: cookie: */ + /* 25: 27: content-length: */ + /* 26: 28: content-type: */ + /* 27: 29: date: */ + /* 28: 30: range: */ + /* 29: 31: referer: */ + /* 30: 32: sec-websocket-key: */ + /* 31: 33: sec-websocket-version: */ + /* 32: 34: sec-websocket-origin: */ + /* 33: 35: :authority */ + /* 34: 36: :method */ + /* 35: 37: :path */ + /* 36: 38: :scheme */ + /* 37: 39: :status */ + /* 38: 40: accept-charset: */ + /* 39: 41: accept-ranges: */ + /* 40: 42: access-control-allow-origin: */ + /* 41: 43: age: */ + /* 42: 44: allow: */ + /* 43: 45: content-disposition: */ + /* 44: 46: content-encoding: */ + /* 45: 47: content-language: */ + /* 46: 48: content-location: */ + /* 47: 49: content-range: */ + /* 48: 50: etag: */ + /* 49: 51: expect: */ + /* 50: 52: expires: */ + /* 51: 53: from: */ + /* 52: 54: if-match: */ + /* 53: 55: if-range: */ + /* 54: 56: if-unmodified-since: */ + /* 55: 57: last-modified: */ + /* 56: 58: link: */ + /* 57: 59: location: */ + /* 58: 60: max-forwards: */ + /* 59: 61: proxy-authenticate: */ + /* 60: 62: proxy-authorization: */ + /* 61: 63: refresh: */ + /* 62: 64: retry-after: */ + /* 63: 65: server: */ + /* 64: 66: set-cookie: */ + /* 65: 67: strict-transport-security: */ + /* 66: 68: transfer-encoding: */ + /* 67: 69: user-agent: */ + /* 68: 70: vary: */ + /* 69: 71: via: */ + /* 70: 72: www-authenticate: */ + /* 71: 76: uri-args */ + /* 72: 79: http/1.0 */ + /* 73: 80: x-forwarded-for: */ + /* 74: 81: connect */ + /* 75: 82: head */ + /* 76: 83: te: */ + /* 77: 84: replay-nonce: */ + /* 78: 85: :protocol */ + /* 79: 86: x-auth-token: */ + /* 80: 87: */ +/* pos 0000: 0 */ 0x67 /* 'g' */, 0x40, 0x00 /* (to 0x0040 state 1) */, + 0x70 /* 'p' */, 0x42, 0x00 /* (to 0x0045 state 5) */, + 0x68 /* 'h' */, 0x51, 0x00 /* (to 0x0057 state 10) */, + 0x63 /* 'c' */, 0x5D, 0x00 /* (to 0x0066 state 15) */, + 0x75 /* 'u' */, 0x7E, 0x00 /* (to 0x008A state 26) */, + 0x6F /* 'o' */, 0x8D, 0x00 /* (to 0x009C state 34) */, + 0x0D /* '.' */, 0x98, 0x00 /* (to 0x00AA state 41) */, + 0x61 /* 'a' */, 0xAD, 0x00 /* (to 0x00C2 state 51) */, + 0x69 /* 'i' */, 0xCA, 0x00 /* (to 0x00E2 state 58) */, + 0x64 /* 'd' */, 0x73, 0x01 /* (to 0x018E state 160) */, + 0x72 /* 'r' */, 0x7C, 0x01 /* (to 0x019A state 165) */, + 0x65 /* 'e' */, 0xC8, 0x01 /* (to 0x01E9 state 229) */, + 0x66 /* 'f' */, 0xE4, 0x01 /* (to 0x0208 state 245) */, + 0x6C /* 'l' */, 0x06, 0x02 /* (to 0x022D state 278) */, + 0x73 /* 's' */, 0x4B, 0x02 /* (to 0x0275 state 321) */, + 0x74 /* 't' */, 0x69, 0x02 /* (to 0x0296 state 337) */, + 0x78 /* 'x' */, 0x8A, 0x02 /* (to 0x02BA state 364) */, + 0x6D /* 'm' */, 0xFB, 0x02 /* (to 0x032E state 456) */, + 0x76 /* 'v' */, 0x54, 0x03 /* (to 0x038A state 531) */, + 0x77 /* 'w' */, 0x61, 0x03 /* (to 0x039A state 539) */, + 0x3A /* ':' */, 0x19, 0x04 /* (to 0x0455 state 674) */, + 0x08, /* fail */ +/* pos 0040: 1 */ 0xE5 /* 'e' -> */, +/* pos 0041: 2 */ 0xF4 /* 't' -> */, +/* pos 0042: 3 */ 0xA0 /* ' ' -> */, +/* pos 0043: 4 */ 0x00, 0x00 /* - terminal marker 0 - */, +/* pos 0045: 5 */ 0x6F /* 'o' */, 0x0D, 0x00 /* (to 0x0052 state 6) */, + 0x72 /* 'r' */, 0xEC, 0x00 /* (to 0x0134 state 106) */, + 0x61 /* 'a' */, 0x61, 0x03 /* (to 0x03AC state 556) */, + 0x75 /* 'u' */, 0x63, 0x03 /* (to 0x03B1 state 560) */, + 0x08, /* fail */ +/* pos 0052: 6 */ 0xF3 /* 's' -> */, +/* pos 0053: 7 */ 0xF4 /* 't' -> */, +/* pos 0054: 8 */ 0xA0 /* ' ' -> */, +/* pos 0055: 9 */ 0x00, 0x01 /* - terminal marker 1 - */, +/* pos 0057: 10 */ 0x6F /* 'o' */, 0x0A, 0x00 /* (to 0x0061 state 11) */, + 0x74 /* 't' */, 0x53, 0x00 /* (to 0x00AD state 43) */, + 0x65 /* 'e' */, 0x79, 0x02 /* (to 0x02D6 state 381) */, + 0x08, /* fail */ +/* pos 0061: 11 */ 0xF3 /* 's' -> */, +/* pos 0062: 12 */ 0xF4 /* 't' -> */, +/* pos 0063: 13 */ 0xBA /* ':' -> */, +/* pos 0064: 14 */ 0x00, 0x02 /* - terminal marker 2 - */, +/* pos 0066: 15 */ 0x6F /* 'o' */, 0x07, 0x00 /* (to 0x006D state 16) */, + 0x61 /* 'a' */, 0xD8, 0x00 /* (to 0x0141 state 112) */, + 0x08, /* fail */ +/* pos 006d: 16 */ 0x6E /* 'n' */, 0x07, 0x00 /* (to 0x0074 state 17) */, + 0x6F /* 'o' */, 0xED, 0x00 /* (to 0x015D state 138) */, + 0x08, /* fail */ +/* pos 0074: 17 */ 0x6E /* 'n' */, 0x07, 0x00 /* (to 0x007B state 18) */, + 0x74 /* 't' */, 0xEC, 0x00 /* (to 0x0163 state 143) */, + 0x08, /* fail */ +/* pos 007b: 18 */ 0xE5 /* 'e' -> */, +/* pos 007c: 19 */ 0xE3 /* 'c' -> */, +/* pos 007d: 20 */ 0xF4 /* 't' -> */, +/* pos 007e: 21 */ 0x69 /* 'i' */, 0x07, 0x00 /* (to 0x0085 state 22) */, + 0x20 /* ' ' */, 0x53, 0x02 /* (to 0x02D4 state 380) */, + 0x08, /* fail */ +/* pos 0085: 22 */ 0xEF /* 'o' -> */, +/* pos 0086: 23 */ 0xEE /* 'n' -> */, +/* pos 0087: 24 */ 0xBA /* ':' -> */, +/* pos 0088: 25 */ 0x00, 0x03 /* - terminal marker 3 - */, +/* pos 008a: 26 */ 0x70 /* 'p' */, 0x0A, 0x00 /* (to 0x0094 state 27) */, + 0x72 /* 'r' */, 0x22, 0x02 /* (to 0x02AF state 355) */, + 0x73 /* 's' */, 0xEF, 0x02 /* (to 0x037F state 521) */, + 0x08, /* fail */ +/* pos 0094: 27 */ 0xE7 /* 'g' -> */, +/* pos 0095: 28 */ 0xF2 /* 'r' -> */, +/* pos 0096: 29 */ 0xE1 /* 'a' -> */, +/* pos 0097: 30 */ 0xE4 /* 'd' -> */, +/* pos 0098: 31 */ 0xE5 /* 'e' -> */, +/* pos 0099: 32 */ 0xBA /* ':' -> */, +/* pos 009a: 33 */ 0x00, 0x04 /* - terminal marker 4 - */, +/* pos 009c: 34 */ 0x72 /* 'r' */, 0x07, 0x00 /* (to 0x00A3 state 35) */, + 0x70 /* 'p' */, 0x48, 0x02 /* (to 0x02E7 state 396) */, + 0x08, /* fail */ +/* pos 00a3: 35 */ 0xE9 /* 'i' -> */, +/* pos 00a4: 36 */ 0xE7 /* 'g' -> */, +/* pos 00a5: 37 */ 0xE9 /* 'i' -> */, +/* pos 00a6: 38 */ 0xEE /* 'n' -> */, +/* pos 00a7: 39 */ 0xBA /* ':' -> */, +/* pos 00a8: 40 */ 0x00, 0x05 /* - terminal marker 5 - */, +/* pos 00aa: 41 */ 0x8A /* '.' -> */, +/* pos 00ab: 42 */ 0x00, 0x07 /* - terminal marker 7 - */, +/* pos 00ad: 43 */ 0xF4 /* 't' -> */, +/* pos 00ae: 44 */ 0xF0 /* 'p' -> */, +/* pos 00af: 45 */ 0x2F /* '/' */, 0x07, 0x00 /* (to 0x00B6 state 46) */, + 0x32 /* '2' */, 0x97, 0x03 /* (to 0x0449 state 663) */, + 0x08, /* fail */ +/* pos 00b6: 46 */ 0xB1 /* '1' -> */, +/* pos 00b7: 47 */ 0xAE /* '.' -> */, +/* pos 00b8: 48 */ 0x31 /* '1' */, 0x07, 0x00 /* (to 0x00BF state 49) */, + 0x30 /* '0' */, 0xFC, 0x01 /* (to 0x02B7 state 362) */, + 0x08, /* fail */ +/* pos 00bf: 49 */ 0xA0 /* ' ' -> */, +/* pos 00c0: 50 */ 0x00, 0x0E /* - terminal marker 14 - */, +/* pos 00c2: 51 */ 0x63 /* 'c' */, 0x0D, 0x00 /* (to 0x00CF state 52) */, + 0x75 /* 'u' */, 0x8A, 0x00 /* (to 0x014F state 125) */, + 0x67 /* 'g' */, 0xE7, 0x00 /* (to 0x01AF state 178) */, + 0x6C /* 'l' */, 0xE8, 0x00 /* (to 0x01B3 state 181) */, + 0x08, /* fail */ +/* pos 00cf: 52 */ 0xE3 /* 'c' -> */, +/* pos 00d0: 53 */ 0xE5 /* 'e' -> */, +/* pos 00d1: 54 */ 0x70 /* 'p' */, 0x07, 0x00 /* (to 0x00D8 state 55) */, + 0x73 /* 's' */, 0x1B, 0x02 /* (to 0x02EF state 403) */, + 0x08, /* fail */ +/* pos 00d8: 55 */ 0xF4 /* 't' -> */, +/* pos 00d9: 56 */ 0x3A /* ':' */, 0x07, 0x00 /* (to 0x00E0 state 57) */, + 0x2D /* '-' */, 0x37, 0x00 /* (to 0x0113 state 87) */, + 0x08, /* fail */ +/* pos 00e0: 57 */ 0x00, 0x10 /* - terminal marker 16 - */, +/* pos 00e2: 58 */ 0xE6 /* 'f' -> */, +/* pos 00e3: 59 */ 0xAD /* '-' -> */, +/* pos 00e4: 60 */ 0x6D /* 'm' */, 0x0D, 0x00 /* (to 0x00F1 state 61) */, + 0x6E /* 'n' */, 0x20, 0x00 /* (to 0x0107 state 76) */, + 0x72 /* 'r' */, 0x2A, 0x01 /* (to 0x0214 state 255) */, + 0x75 /* 'u' */, 0x2E, 0x01 /* (to 0x021B state 261) */, + 0x08, /* fail */ +/* pos 00f1: 61 */ 0x6F /* 'o' */, 0x07, 0x00 /* (to 0x00F8 state 62) */, + 0x61 /* 'a' */, 0x1A, 0x01 /* (to 0x020E state 250) */, + 0x08, /* fail */ +/* pos 00f8: 62 */ 0xE4 /* 'd' -> */, +/* pos 00f9: 63 */ 0xE9 /* 'i' -> */, +/* pos 00fa: 64 */ 0xE6 /* 'f' -> */, +/* pos 00fb: 65 */ 0xE9 /* 'i' -> */, +/* pos 00fc: 66 */ 0xE5 /* 'e' -> */, +/* pos 00fd: 67 */ 0xE4 /* 'd' -> */, +/* pos 00fe: 68 */ 0xAD /* '-' -> */, +/* pos 00ff: 69 */ 0xF3 /* 's' -> */, +/* pos 0100: 70 */ 0xE9 /* 'i' -> */, +/* pos 0101: 71 */ 0xEE /* 'n' -> */, +/* pos 0102: 72 */ 0xE3 /* 'c' -> */, +/* pos 0103: 73 */ 0xE5 /* 'e' -> */, +/* pos 0104: 74 */ 0xBA /* ':' -> */, +/* pos 0105: 75 */ 0x00, 0x11 /* - terminal marker 17 - */, +/* pos 0107: 76 */ 0xEF /* 'o' -> */, +/* pos 0108: 77 */ 0xEE /* 'n' -> */, +/* pos 0109: 78 */ 0xE5 /* 'e' -> */, +/* pos 010a: 79 */ 0xAD /* '-' -> */, +/* pos 010b: 80 */ 0xED /* 'm' -> */, +/* pos 010c: 81 */ 0xE1 /* 'a' -> */, +/* pos 010d: 82 */ 0xF4 /* 't' -> */, +/* pos 010e: 83 */ 0xE3 /* 'c' -> */, +/* pos 010f: 84 */ 0xE8 /* 'h' -> */, +/* pos 0110: 85 */ 0xBA /* ':' -> */, +/* pos 0111: 86 */ 0x00, 0x12 /* - terminal marker 18 - */, +/* pos 0113: 87 */ 0x65 /* 'e' */, 0x0D, 0x00 /* (to 0x0120 state 88) */, + 0x6C /* 'l' */, 0x14, 0x00 /* (to 0x012A state 97) */, + 0x72 /* 'r' */, 0x8E, 0x00 /* (to 0x01A7 state 171) */, + 0x63 /* 'c' */, 0xFB, 0x01 /* (to 0x0317 state 435) */, + 0x08, /* fail */ +/* pos 0120: 88 */ 0xEE /* 'n' -> */, +/* pos 0121: 89 */ 0xE3 /* 'c' -> */, +/* pos 0122: 90 */ 0xEF /* 'o' -> */, +/* pos 0123: 91 */ 0xE4 /* 'd' -> */, +/* pos 0124: 92 */ 0xE9 /* 'i' -> */, +/* pos 0125: 93 */ 0xEE /* 'n' -> */, +/* pos 0126: 94 */ 0xE7 /* 'g' -> */, +/* pos 0127: 95 */ 0xBA /* ':' -> */, +/* pos 0128: 96 */ 0x00, 0x13 /* - terminal marker 19 - */, +/* pos 012a: 97 */ 0xE1 /* 'a' -> */, +/* pos 012b: 98 */ 0xEE /* 'n' -> */, +/* pos 012c: 99 */ 0xE7 /* 'g' -> */, +/* pos 012d: 100 */ 0xF5 /* 'u' -> */, +/* pos 012e: 101 */ 0xE1 /* 'a' -> */, +/* pos 012f: 102 */ 0xE7 /* 'g' -> */, +/* pos 0130: 103 */ 0xE5 /* 'e' -> */, +/* pos 0131: 104 */ 0xBA /* ':' -> */, +/* pos 0132: 105 */ 0x00, 0x14 /* - terminal marker 20 - */, +/* pos 0134: 106 */ 0x61 /* 'a' */, 0x07, 0x00 /* (to 0x013B state 107) */, + 0x6F /* 'o' */, 0x05, 0x02 /* (to 0x033C state 469) */, + 0x08, /* fail */ +/* pos 013b: 107 */ 0xE7 /* 'g' -> */, +/* pos 013c: 108 */ 0xED /* 'm' -> */, +/* pos 013d: 109 */ 0xE1 /* 'a' -> */, +/* pos 013e: 110 */ 0xBA /* ':' -> */, +/* pos 013f: 111 */ 0x00, 0x15 /* - terminal marker 21 - */, +/* pos 0141: 112 */ 0xE3 /* 'c' -> */, +/* pos 0142: 113 */ 0xE8 /* 'h' -> */, +/* pos 0143: 114 */ 0xE5 /* 'e' -> */, +/* pos 0144: 115 */ 0xAD /* '-' -> */, +/* pos 0145: 116 */ 0xE3 /* 'c' -> */, +/* pos 0146: 117 */ 0xEF /* 'o' -> */, +/* pos 0147: 118 */ 0xEE /* 'n' -> */, +/* pos 0148: 119 */ 0xF4 /* 't' -> */, +/* pos 0149: 120 */ 0xF2 /* 'r' -> */, +/* pos 014a: 121 */ 0xEF /* 'o' -> */, +/* pos 014b: 122 */ 0xEC /* 'l' -> */, +/* pos 014c: 123 */ 0xBA /* ':' -> */, +/* pos 014d: 124 */ 0x00, 0x16 /* - terminal marker 22 - */, +/* pos 014f: 125 */ 0xF4 /* 't' -> */, +/* pos 0150: 126 */ 0xE8 /* 'h' -> */, +/* pos 0151: 127 */ 0xEF /* 'o' -> */, +/* pos 0152: 128 */ 0xF2 /* 'r' -> */, +/* pos 0153: 129 */ 0xE9 /* 'i' -> */, +/* pos 0154: 130 */ 0xFA /* 'z' -> */, +/* pos 0155: 131 */ 0xE1 /* 'a' -> */, +/* pos 0156: 132 */ 0xF4 /* 't' -> */, +/* pos 0157: 133 */ 0xE9 /* 'i' -> */, +/* pos 0158: 134 */ 0xEF /* 'o' -> */, +/* pos 0159: 135 */ 0xEE /* 'n' -> */, +/* pos 015a: 136 */ 0xBA /* ':' -> */, +/* pos 015b: 137 */ 0x00, 0x17 /* - terminal marker 23 - */, +/* pos 015d: 138 */ 0xEB /* 'k' -> */, +/* pos 015e: 139 */ 0xE9 /* 'i' -> */, +/* pos 015f: 140 */ 0xE5 /* 'e' -> */, +/* pos 0160: 141 */ 0xBA /* ':' -> */, +/* pos 0161: 142 */ 0x00, 0x18 /* - terminal marker 24 - */, +/* pos 0163: 143 */ 0xE5 /* 'e' -> */, +/* pos 0164: 144 */ 0xEE /* 'n' -> */, +/* pos 0165: 145 */ 0xF4 /* 't' -> */, +/* pos 0166: 146 */ 0xAD /* '-' -> */, +/* pos 0167: 147 */ 0x6C /* 'l' */, 0x10, 0x00 /* (to 0x0177 state 148) */, + 0x74 /* 't' */, 0x1E, 0x00 /* (to 0x0188 state 155) */, + 0x64 /* 'd' */, 0x4C, 0x00 /* (to 0x01B9 state 186) */, + 0x65 /* 'e' */, 0x56, 0x00 /* (to 0x01C6 state 198) */, + 0x72 /* 'r' */, 0x6F, 0x00 /* (to 0x01E2 state 223) */, + 0x08, /* fail */ +/* pos 0177: 148 */ 0x65 /* 'e' */, 0x0A, 0x00 /* (to 0x0181 state 149) */, + 0x61 /* 'a' */, 0x56, 0x00 /* (to 0x01D0 state 207) */, + 0x6F /* 'o' */, 0x5C, 0x00 /* (to 0x01D9 state 215) */, + 0x08, /* fail */ +/* pos 0181: 149 */ 0xEE /* 'n' -> */, +/* pos 0182: 150 */ 0xE7 /* 'g' -> */, +/* pos 0183: 151 */ 0xF4 /* 't' -> */, +/* pos 0184: 152 */ 0xE8 /* 'h' -> */, +/* pos 0185: 153 */ 0xBA /* ':' -> */, +/* pos 0186: 154 */ 0x00, 0x19 /* - terminal marker 25 - */, +/* pos 0188: 155 */ 0xF9 /* 'y' -> */, +/* pos 0189: 156 */ 0xF0 /* 'p' -> */, +/* pos 018a: 157 */ 0xE5 /* 'e' -> */, +/* pos 018b: 158 */ 0xBA /* ':' -> */, +/* pos 018c: 159 */ 0x00, 0x1A /* - terminal marker 26 - */, +/* pos 018e: 160 */ 0x61 /* 'a' */, 0x07, 0x00 /* (to 0x0195 state 161) */, + 0x65 /* 'e' */, 0x23, 0x02 /* (to 0x03B4 state 562) */, + 0x08, /* fail */ +/* pos 0195: 161 */ 0xF4 /* 't' -> */, +/* pos 0196: 162 */ 0xE5 /* 'e' -> */, +/* pos 0197: 163 */ 0xBA /* ':' -> */, +/* pos 0198: 164 */ 0x00, 0x1B /* - terminal marker 27 - */, +/* pos 019a: 165 */ 0x61 /* 'a' */, 0x07, 0x00 /* (to 0x01A1 state 166) */, + 0x65 /* 'e' */, 0xB6, 0x00 /* (to 0x0253 state 304) */, + 0x08, /* fail */ +/* pos 01a1: 166 */ 0xEE /* 'n' -> */, +/* pos 01a2: 167 */ 0xE7 /* 'g' -> */, +/* pos 01a3: 168 */ 0xE5 /* 'e' -> */, +/* pos 01a4: 169 */ 0xBA /* ':' -> */, +/* pos 01a5: 170 */ 0x00, 0x1C /* - terminal marker 28 - */, +/* pos 01a7: 171 */ 0xE1 /* 'a' -> */, +/* pos 01a8: 172 */ 0xEE /* 'n' -> */, +/* pos 01a9: 173 */ 0xE7 /* 'g' -> */, +/* pos 01aa: 174 */ 0xE5 /* 'e' -> */, +/* pos 01ab: 175 */ 0xF3 /* 's' -> */, +/* pos 01ac: 176 */ 0xBA /* ':' -> */, +/* pos 01ad: 177 */ 0x00, 0x27 /* - terminal marker 39 - */, +/* pos 01af: 178 */ 0xE5 /* 'e' -> */, +/* pos 01b0: 179 */ 0xBA /* ':' -> */, +/* pos 01b1: 180 */ 0x00, 0x29 /* - terminal marker 41 - */, +/* pos 01b3: 181 */ 0xEC /* 'l' -> */, +/* pos 01b4: 182 */ 0xEF /* 'o' -> */, +/* pos 01b5: 183 */ 0xF7 /* 'w' -> */, +/* pos 01b6: 184 */ 0xBA /* ':' -> */, +/* pos 01b7: 185 */ 0x00, 0x2A /* - terminal marker 42 - */, +/* pos 01b9: 186 */ 0xE9 /* 'i' -> */, +/* pos 01ba: 187 */ 0xF3 /* 's' -> */, +/* pos 01bb: 188 */ 0xF0 /* 'p' -> */, +/* pos 01bc: 189 */ 0xEF /* 'o' -> */, +/* pos 01bd: 190 */ 0xF3 /* 's' -> */, +/* pos 01be: 191 */ 0xE9 /* 'i' -> */, +/* pos 01bf: 192 */ 0xF4 /* 't' -> */, +/* pos 01c0: 193 */ 0xE9 /* 'i' -> */, +/* pos 01c1: 194 */ 0xEF /* 'o' -> */, +/* pos 01c2: 195 */ 0xEE /* 'n' -> */, +/* pos 01c3: 196 */ 0xBA /* ':' -> */, +/* pos 01c4: 197 */ 0x00, 0x2B /* - terminal marker 43 - */, +/* pos 01c6: 198 */ 0xEE /* 'n' -> */, +/* pos 01c7: 199 */ 0xE3 /* 'c' -> */, +/* pos 01c8: 200 */ 0xEF /* 'o' -> */, +/* pos 01c9: 201 */ 0xE4 /* 'd' -> */, +/* pos 01ca: 202 */ 0xE9 /* 'i' -> */, +/* pos 01cb: 203 */ 0xEE /* 'n' -> */, +/* pos 01cc: 204 */ 0xE7 /* 'g' -> */, +/* pos 01cd: 205 */ 0xBA /* ':' -> */, +/* pos 01ce: 206 */ 0x00, 0x2C /* - terminal marker 44 - */, +/* pos 01d0: 207 */ 0xEE /* 'n' -> */, +/* pos 01d1: 208 */ 0xE7 /* 'g' -> */, +/* pos 01d2: 209 */ 0xF5 /* 'u' -> */, +/* pos 01d3: 210 */ 0xE1 /* 'a' -> */, +/* pos 01d4: 211 */ 0xE7 /* 'g' -> */, +/* pos 01d5: 212 */ 0xE5 /* 'e' -> */, +/* pos 01d6: 213 */ 0xBA /* ':' -> */, +/* pos 01d7: 214 */ 0x00, 0x2D /* - terminal marker 45 - */, +/* pos 01d9: 215 */ 0xE3 /* 'c' -> */, +/* pos 01da: 216 */ 0xE1 /* 'a' -> */, +/* pos 01db: 217 */ 0xF4 /* 't' -> */, +/* pos 01dc: 218 */ 0xE9 /* 'i' -> */, +/* pos 01dd: 219 */ 0xEF /* 'o' -> */, +/* pos 01de: 220 */ 0xEE /* 'n' -> */, +/* pos 01df: 221 */ 0xBA /* ':' -> */, +/* pos 01e0: 222 */ 0x00, 0x2E /* - terminal marker 46 - */, +/* pos 01e2: 223 */ 0xE1 /* 'a' -> */, +/* pos 01e3: 224 */ 0xEE /* 'n' -> */, +/* pos 01e4: 225 */ 0xE7 /* 'g' -> */, +/* pos 01e5: 226 */ 0xE5 /* 'e' -> */, +/* pos 01e6: 227 */ 0xBA /* ':' -> */, +/* pos 01e7: 228 */ 0x00, 0x2F /* - terminal marker 47 - */, +/* pos 01e9: 229 */ 0x74 /* 't' */, 0x07, 0x00 /* (to 0x01F0 state 230) */, + 0x78 /* 'x' */, 0x09, 0x00 /* (to 0x01F5 state 234) */, + 0x08, /* fail */ +/* pos 01f0: 230 */ 0xE1 /* 'a' -> */, +/* pos 01f1: 231 */ 0xE7 /* 'g' -> */, +/* pos 01f2: 232 */ 0xBA /* ':' -> */, +/* pos 01f3: 233 */ 0x00, 0x30 /* - terminal marker 48 - */, +/* pos 01f5: 234 */ 0xF0 /* 'p' -> */, +/* pos 01f6: 235 */ 0x65 /* 'e' */, 0x07, 0x00 /* (to 0x01FD state 236) */, + 0x69 /* 'i' */, 0x09, 0x00 /* (to 0x0202 state 240) */, + 0x08, /* fail */ +/* pos 01fd: 236 */ 0xE3 /* 'c' -> */, +/* pos 01fe: 237 */ 0xF4 /* 't' -> */, +/* pos 01ff: 238 */ 0xBA /* ':' -> */, +/* pos 0200: 239 */ 0x00, 0x31 /* - terminal marker 49 - */, +/* pos 0202: 240 */ 0xF2 /* 'r' -> */, +/* pos 0203: 241 */ 0xE5 /* 'e' -> */, +/* pos 0204: 242 */ 0xF3 /* 's' -> */, +/* pos 0205: 243 */ 0xBA /* ':' -> */, +/* pos 0206: 244 */ 0x00, 0x32 /* - terminal marker 50 - */, +/* pos 0208: 245 */ 0xF2 /* 'r' -> */, +/* pos 0209: 246 */ 0xEF /* 'o' -> */, +/* pos 020a: 247 */ 0xED /* 'm' -> */, +/* pos 020b: 248 */ 0xBA /* ':' -> */, +/* pos 020c: 249 */ 0x00, 0x33 /* - terminal marker 51 - */, +/* pos 020e: 250 */ 0xF4 /* 't' -> */, +/* pos 020f: 251 */ 0xE3 /* 'c' -> */, +/* pos 0210: 252 */ 0xE8 /* 'h' -> */, +/* pos 0211: 253 */ 0xBA /* ':' -> */, +/* pos 0212: 254 */ 0x00, 0x34 /* - terminal marker 52 - */, +/* pos 0214: 255 */ 0xE1 /* 'a' -> */, +/* pos 0215: 256 */ 0xEE /* 'n' -> */, +/* pos 0216: 257 */ 0xE7 /* 'g' -> */, +/* pos 0217: 258 */ 0xE5 /* 'e' -> */, +/* pos 0218: 259 */ 0xBA /* ':' -> */, +/* pos 0219: 260 */ 0x00, 0x35 /* - terminal marker 53 - */, +/* pos 021b: 261 */ 0xEE /* 'n' -> */, +/* pos 021c: 262 */ 0xED /* 'm' -> */, +/* pos 021d: 263 */ 0xEF /* 'o' -> */, +/* pos 021e: 264 */ 0xE4 /* 'd' -> */, +/* pos 021f: 265 */ 0xE9 /* 'i' -> */, +/* pos 0220: 266 */ 0xE6 /* 'f' -> */, +/* pos 0221: 267 */ 0xE9 /* 'i' -> */, +/* pos 0222: 268 */ 0xE5 /* 'e' -> */, +/* pos 0223: 269 */ 0xE4 /* 'd' -> */, +/* pos 0224: 270 */ 0xAD /* '-' -> */, +/* pos 0225: 271 */ 0xF3 /* 's' -> */, +/* pos 0226: 272 */ 0xE9 /* 'i' -> */, +/* pos 0227: 273 */ 0xEE /* 'n' -> */, +/* pos 0228: 274 */ 0xE3 /* 'c' -> */, +/* pos 0229: 275 */ 0xE5 /* 'e' -> */, +/* pos 022a: 276 */ 0xBA /* ':' -> */, +/* pos 022b: 277 */ 0x00, 0x36 /* - terminal marker 54 - */, +/* pos 022d: 278 */ 0x61 /* 'a' */, 0x0A, 0x00 /* (to 0x0237 state 279) */, + 0x69 /* 'i' */, 0x15, 0x00 /* (to 0x0245 state 292) */, + 0x6F /* 'o' */, 0x17, 0x00 /* (to 0x024A state 296) */, + 0x08, /* fail */ +/* pos 0237: 279 */ 0xF3 /* 's' -> */, +/* pos 0238: 280 */ 0xF4 /* 't' -> */, +/* pos 0239: 281 */ 0xAD /* '-' -> */, +/* pos 023a: 282 */ 0xED /* 'm' -> */, +/* pos 023b: 283 */ 0xEF /* 'o' -> */, +/* pos 023c: 284 */ 0xE4 /* 'd' -> */, +/* pos 023d: 285 */ 0xE9 /* 'i' -> */, +/* pos 023e: 286 */ 0xE6 /* 'f' -> */, +/* pos 023f: 287 */ 0xE9 /* 'i' -> */, +/* pos 0240: 288 */ 0xE5 /* 'e' -> */, +/* pos 0241: 289 */ 0xE4 /* 'd' -> */, +/* pos 0242: 290 */ 0xBA /* ':' -> */, +/* pos 0243: 291 */ 0x00, 0x37 /* - terminal marker 55 - */, +/* pos 0245: 292 */ 0xEE /* 'n' -> */, +/* pos 0246: 293 */ 0xEB /* 'k' -> */, +/* pos 0247: 294 */ 0xBA /* ':' -> */, +/* pos 0248: 295 */ 0x00, 0x38 /* - terminal marker 56 - */, +/* pos 024a: 296 */ 0xE3 /* 'c' -> */, +/* pos 024b: 297 */ 0xE1 /* 'a' -> */, +/* pos 024c: 298 */ 0xF4 /* 't' -> */, +/* pos 024d: 299 */ 0xE9 /* 'i' -> */, +/* pos 024e: 300 */ 0xEF /* 'o' -> */, +/* pos 024f: 301 */ 0xEE /* 'n' -> */, +/* pos 0250: 302 */ 0xBA /* ':' -> */, +/* pos 0251: 303 */ 0x00, 0x39 /* - terminal marker 57 - */, +/* pos 0253: 304 */ 0x66 /* 'f' */, 0x0A, 0x00 /* (to 0x025D state 305) */, + 0x74 /* 't' */, 0x14, 0x00 /* (to 0x026A state 311) */, + 0x70 /* 'p' */, 0x6F, 0x01 /* (to 0x03C8 state 578) */, + 0x08, /* fail */ +/* pos 025d: 305 */ 0x72 /* 'r' */, 0x07, 0x00 /* (to 0x0264 state 306) */, + 0x65 /* 'e' */, 0xB1, 0x00 /* (to 0x0311 state 430) */, + 0x08, /* fail */ +/* pos 0264: 306 */ 0xE5 /* 'e' -> */, +/* pos 0265: 307 */ 0xF3 /* 's' -> */, +/* pos 0266: 308 */ 0xE8 /* 'h' -> */, +/* pos 0267: 309 */ 0xBA /* ':' -> */, +/* pos 0268: 310 */ 0x00, 0x3D /* - terminal marker 61 - */, +/* pos 026a: 311 */ 0xF2 /* 'r' -> */, +/* pos 026b: 312 */ 0xF9 /* 'y' -> */, +/* pos 026c: 313 */ 0xAD /* '-' -> */, +/* pos 026d: 314 */ 0xE1 /* 'a' -> */, +/* pos 026e: 315 */ 0xE6 /* 'f' -> */, +/* pos 026f: 316 */ 0xF4 /* 't' -> */, +/* pos 0270: 317 */ 0xE5 /* 'e' -> */, +/* pos 0271: 318 */ 0xF2 /* 'r' -> */, +/* pos 0272: 319 */ 0xBA /* ':' -> */, +/* pos 0273: 320 */ 0x00, 0x3E /* - terminal marker 62 - */, +/* pos 0275: 321 */ 0x65 /* 'e' */, 0x07, 0x00 /* (to 0x027C state 322) */, + 0x74 /* 't' */, 0xED, 0x00 /* (to 0x0365 state 496) */, + 0x08, /* fail */ +/* pos 027c: 322 */ 0x72 /* 'r' */, 0x0A, 0x00 /* (to 0x0286 state 323) */, + 0x74 /* 't' */, 0x0D, 0x00 /* (to 0x028C state 328) */, + 0x63 /* 'c' */, 0x52, 0x01 /* (to 0x03D4 state 589) */, + 0x08, /* fail */ +/* pos 0286: 323 */ 0xF6 /* 'v' -> */, +/* pos 0287: 324 */ 0xE5 /* 'e' -> */, +/* pos 0288: 325 */ 0xF2 /* 'r' -> */, +/* pos 0289: 326 */ 0xBA /* ':' -> */, +/* pos 028a: 327 */ 0x00, 0x3F /* - terminal marker 63 - */, +/* pos 028c: 328 */ 0xAD /* '-' -> */, +/* pos 028d: 329 */ 0xE3 /* 'c' -> */, +/* pos 028e: 330 */ 0xEF /* 'o' -> */, +/* pos 028f: 331 */ 0xEF /* 'o' -> */, +/* pos 0290: 332 */ 0xEB /* 'k' -> */, +/* pos 0291: 333 */ 0xE9 /* 'i' -> */, +/* pos 0292: 334 */ 0xE5 /* 'e' -> */, +/* pos 0293: 335 */ 0xBA /* ':' -> */, +/* pos 0294: 336 */ 0x00, 0x40 /* - terminal marker 64 - */, +/* pos 0296: 337 */ 0x72 /* 'r' */, 0x07, 0x00 /* (to 0x029D state 338) */, + 0x65 /* 'e' */, 0x2C, 0x01 /* (to 0x03C5 state 576) */, + 0x08, /* fail */ +/* pos 029d: 338 */ 0xE1 /* 'a' -> */, +/* pos 029e: 339 */ 0xEE /* 'n' -> */, +/* pos 029f: 340 */ 0xF3 /* 's' -> */, +/* pos 02a0: 341 */ 0xE6 /* 'f' -> */, +/* pos 02a1: 342 */ 0xE5 /* 'e' -> */, +/* pos 02a2: 343 */ 0xF2 /* 'r' -> */, +/* pos 02a3: 344 */ 0xAD /* '-' -> */, +/* pos 02a4: 345 */ 0xE5 /* 'e' -> */, +/* pos 02a5: 346 */ 0xEE /* 'n' -> */, +/* pos 02a6: 347 */ 0xE3 /* 'c' -> */, +/* pos 02a7: 348 */ 0xEF /* 'o' -> */, +/* pos 02a8: 349 */ 0xE4 /* 'd' -> */, +/* pos 02a9: 350 */ 0xE9 /* 'i' -> */, +/* pos 02aa: 351 */ 0xEE /* 'n' -> */, +/* pos 02ab: 352 */ 0xE7 /* 'g' -> */, +/* pos 02ac: 353 */ 0xBA /* ':' -> */, +/* pos 02ad: 354 */ 0x00, 0x42 /* - terminal marker 66 - */, +/* pos 02af: 355 */ 0xE9 /* 'i' -> */, +/* pos 02b0: 356 */ 0xAD /* '-' -> */, +/* pos 02b1: 357 */ 0xE1 /* 'a' -> */, +/* pos 02b2: 358 */ 0xF2 /* 'r' -> */, +/* pos 02b3: 359 */ 0xE7 /* 'g' -> */, +/* pos 02b4: 360 */ 0xF3 /* 's' -> */, +/* pos 02b5: 361 */ 0x00, 0x47 /* - terminal marker 71 - */, +/* pos 02b7: 362 */ 0xA0 /* ' ' -> */, +/* pos 02b8: 363 */ 0x00, 0x48 /* - terminal marker 72 - */, +/* pos 02ba: 364 */ 0xAD /* '-' -> */, +/* pos 02bb: 365 */ 0x66 /* 'f' */, 0x0A, 0x00 /* (to 0x02C5 state 366) */, + 0x61 /* 'a' */, 0x1D, 0x00 /* (to 0x02DB state 385) */, + 0x72 /* 'r' */, 0xFB, 0x00 /* (to 0x03BC state 568) */, + 0x08, /* fail */ +/* pos 02c5: 366 */ 0xEF /* 'o' -> */, +/* pos 02c6: 367 */ 0xF2 /* 'r' -> */, +/* pos 02c7: 368 */ 0xF7 /* 'w' -> */, +/* pos 02c8: 369 */ 0xE1 /* 'a' -> */, +/* pos 02c9: 370 */ 0xF2 /* 'r' -> */, +/* pos 02ca: 371 */ 0xE4 /* 'd' -> */, +/* pos 02cb: 372 */ 0xE5 /* 'e' -> */, +/* pos 02cc: 373 */ 0xE4 /* 'd' -> */, +/* pos 02cd: 374 */ 0xAD /* '-' -> */, +/* pos 02ce: 375 */ 0xE6 /* 'f' -> */, +/* pos 02cf: 376 */ 0xEF /* 'o' -> */, +/* pos 02d0: 377 */ 0xF2 /* 'r' -> */, +/* pos 02d1: 378 */ 0xBA /* ':' -> */, +/* pos 02d2: 379 */ 0x00, 0x49 /* - terminal marker 73 - */, +/* pos 02d4: 380 */ 0x00, 0x4A /* - terminal marker 74 - */, +/* pos 02d6: 381 */ 0xE1 /* 'a' -> */, +/* pos 02d7: 382 */ 0xE4 /* 'd' -> */, +/* pos 02d8: 383 */ 0xA0 /* ' ' -> */, +/* pos 02d9: 384 */ 0x00, 0x4B /* - terminal marker 75 - */, +/* pos 02db: 385 */ 0xF5 /* 'u' -> */, +/* pos 02dc: 386 */ 0xF4 /* 't' -> */, +/* pos 02dd: 387 */ 0xE8 /* 'h' -> */, +/* pos 02de: 388 */ 0xAD /* '-' -> */, +/* pos 02df: 389 */ 0xF4 /* 't' -> */, +/* pos 02e0: 390 */ 0xEF /* 'o' -> */, +/* pos 02e1: 391 */ 0xEB /* 'k' -> */, +/* pos 02e2: 392 */ 0xE5 /* 'e' -> */, +/* pos 02e3: 393 */ 0xEE /* 'n' -> */, +/* pos 02e4: 394 */ 0xBA /* ':' -> */, +/* pos 02e5: 395 */ 0x00, 0x4F /* - terminal marker 79 - */, +/* pos 02e7: 396 */ 0xF4 /* 't' -> */, +/* pos 02e8: 397 */ 0xE9 /* 'i' -> */, +/* pos 02e9: 398 */ 0xEF /* 'o' -> */, +/* pos 02ea: 399 */ 0xEE /* 'n' -> */, +/* pos 02eb: 400 */ 0xF3 /* 's' -> */, +/* pos 02ec: 401 */ 0xA0 /* ' ' -> */, +/* pos 02ed: 402 */ 0x00, 0x02 /* - terminal marker 2 - */, +/* pos 02ef: 403 */ 0xF3 /* 's' -> */, +/* pos 02f0: 404 */ 0xAD /* '-' -> */, +/* pos 02f1: 405 */ 0xE3 /* 'c' -> */, +/* pos 02f2: 406 */ 0xEF /* 'o' -> */, +/* pos 02f3: 407 */ 0xEE /* 'n' -> */, +/* pos 02f4: 408 */ 0xF4 /* 't' -> */, +/* pos 02f5: 409 */ 0xF2 /* 'r' -> */, +/* pos 02f6: 410 */ 0xEF /* 'o' -> */, +/* pos 02f7: 411 */ 0xEC /* 'l' -> */, +/* pos 02f8: 412 */ 0xAD /* '-' -> */, +/* pos 02f9: 413 */ 0x72 /* 'r' */, 0x07, 0x00 /* (to 0x0300 state 414) */, + 0x61 /* 'a' */, 0x24, 0x00 /* (to 0x0320 state 443) */, + 0x08, /* fail */ +/* pos 0300: 414 */ 0xE5 /* 'e' -> */, +/* pos 0301: 415 */ 0xF1 /* 'q' -> */, +/* pos 0302: 416 */ 0xF5 /* 'u' -> */, +/* pos 0303: 417 */ 0xE5 /* 'e' -> */, +/* pos 0304: 418 */ 0xF3 /* 's' -> */, +/* pos 0305: 419 */ 0xF4 /* 't' -> */, +/* pos 0306: 420 */ 0xAD /* '-' -> */, +/* pos 0307: 421 */ 0xE8 /* 'h' -> */, +/* pos 0308: 422 */ 0xE5 /* 'e' -> */, +/* pos 0309: 423 */ 0xE1 /* 'a' -> */, +/* pos 030a: 424 */ 0xE4 /* 'd' -> */, +/* pos 030b: 425 */ 0xE5 /* 'e' -> */, +/* pos 030c: 426 */ 0xF2 /* 'r' -> */, +/* pos 030d: 427 */ 0xF3 /* 's' -> */, +/* pos 030e: 428 */ 0xBA /* ':' -> */, +/* pos 030f: 429 */ 0x00, 0x0B /* - terminal marker 11 - */, +/* pos 0311: 430 */ 0xF2 /* 'r' -> */, +/* pos 0312: 431 */ 0xE5 /* 'e' -> */, +/* pos 0313: 432 */ 0xF2 /* 'r' -> */, +/* pos 0314: 433 */ 0xBA /* ':' -> */, +/* pos 0315: 434 */ 0x00, 0x1D /* - terminal marker 29 - */, +/* pos 0317: 435 */ 0xE8 /* 'h' -> */, +/* pos 0318: 436 */ 0xE1 /* 'a' -> */, +/* pos 0319: 437 */ 0xF2 /* 'r' -> */, +/* pos 031a: 438 */ 0xF3 /* 's' -> */, +/* pos 031b: 439 */ 0xE5 /* 'e' -> */, +/* pos 031c: 440 */ 0xF4 /* 't' -> */, +/* pos 031d: 441 */ 0xBA /* ':' -> */, +/* pos 031e: 442 */ 0x00, 0x26 /* - terminal marker 38 - */, +/* pos 0320: 443 */ 0xEC /* 'l' -> */, +/* pos 0321: 444 */ 0xEC /* 'l' -> */, +/* pos 0322: 445 */ 0xEF /* 'o' -> */, +/* pos 0323: 446 */ 0xF7 /* 'w' -> */, +/* pos 0324: 447 */ 0xAD /* '-' -> */, +/* pos 0325: 448 */ 0xEF /* 'o' -> */, +/* pos 0326: 449 */ 0xF2 /* 'r' -> */, +/* pos 0327: 450 */ 0xE9 /* 'i' -> */, +/* pos 0328: 451 */ 0xE7 /* 'g' -> */, +/* pos 0329: 452 */ 0xE9 /* 'i' -> */, +/* pos 032a: 453 */ 0xEE /* 'n' -> */, +/* pos 032b: 454 */ 0xBA /* ':' -> */, +/* pos 032c: 455 */ 0x00, 0x28 /* - terminal marker 40 - */, +/* pos 032e: 456 */ 0xE1 /* 'a' -> */, +/* pos 032f: 457 */ 0xF8 /* 'x' -> */, +/* pos 0330: 458 */ 0xAD /* '-' -> */, +/* pos 0331: 459 */ 0xE6 /* 'f' -> */, +/* pos 0332: 460 */ 0xEF /* 'o' -> */, +/* pos 0333: 461 */ 0xF2 /* 'r' -> */, +/* pos 0334: 462 */ 0xF7 /* 'w' -> */, +/* pos 0335: 463 */ 0xE1 /* 'a' -> */, +/* pos 0336: 464 */ 0xF2 /* 'r' -> */, +/* pos 0337: 465 */ 0xE4 /* 'd' -> */, +/* pos 0338: 466 */ 0xF3 /* 's' -> */, +/* pos 0339: 467 */ 0xBA /* ':' -> */, +/* pos 033a: 468 */ 0x00, 0x3A /* - terminal marker 58 - */, +/* pos 033c: 469 */ 0xF8 /* 'x' -> */, +/* pos 033d: 470 */ 0xF9 /* 'y' -> */, +/* pos 033e: 471 */ 0x2D /* '-' */, 0x07, 0x00 /* (to 0x0345 state 472) */, + 0x20 /* ' ' */, 0x79, 0x00 /* (to 0x03BA state 567) */, + 0x08, /* fail */ +/* pos 0345: 472 */ 0xE1 /* 'a' -> */, +/* pos 0346: 473 */ 0xF5 /* 'u' -> */, +/* pos 0347: 474 */ 0xF4 /* 't' -> */, +/* pos 0348: 475 */ 0xE8 /* 'h' -> */, +/* pos 0349: 476 */ 0x65 /* 'e' */, 0x07, 0x00 /* (to 0x0350 state 477) */, + 0x6F /* 'o' */, 0x0E, 0x00 /* (to 0x035A state 486) */, + 0x08, /* fail */ +/* pos 0350: 477 */ 0xEE /* 'n' -> */, +/* pos 0351: 478 */ 0xF4 /* 't' -> */, +/* pos 0352: 479 */ 0xE9 /* 'i' -> */, +/* pos 0353: 480 */ 0xE3 /* 'c' -> */, +/* pos 0354: 481 */ 0xE1 /* 'a' -> */, +/* pos 0355: 482 */ 0xF4 /* 't' -> */, +/* pos 0356: 483 */ 0xE5 /* 'e' -> */, +/* pos 0357: 484 */ 0xBA /* ':' -> */, +/* pos 0358: 485 */ 0x00, 0x3B /* - terminal marker 59 - */, +/* pos 035a: 486 */ 0xF2 /* 'r' -> */, +/* pos 035b: 487 */ 0xE9 /* 'i' -> */, +/* pos 035c: 488 */ 0xFA /* 'z' -> */, +/* pos 035d: 489 */ 0xE1 /* 'a' -> */, +/* pos 035e: 490 */ 0xF4 /* 't' -> */, +/* pos 035f: 491 */ 0xE9 /* 'i' -> */, +/* pos 0360: 492 */ 0xEF /* 'o' -> */, +/* pos 0361: 493 */ 0xEE /* 'n' -> */, +/* pos 0362: 494 */ 0xBA /* ':' -> */, +/* pos 0363: 495 */ 0x00, 0x3C /* - terminal marker 60 - */, +/* pos 0365: 496 */ 0xF2 /* 'r' -> */, +/* pos 0366: 497 */ 0xE9 /* 'i' -> */, +/* pos 0367: 498 */ 0xE3 /* 'c' -> */, +/* pos 0368: 499 */ 0xF4 /* 't' -> */, +/* pos 0369: 500 */ 0xAD /* '-' -> */, +/* pos 036a: 501 */ 0xF4 /* 't' -> */, +/* pos 036b: 502 */ 0xF2 /* 'r' -> */, +/* pos 036c: 503 */ 0xE1 /* 'a' -> */, +/* pos 036d: 504 */ 0xEE /* 'n' -> */, +/* pos 036e: 505 */ 0xF3 /* 's' -> */, +/* pos 036f: 506 */ 0xF0 /* 'p' -> */, +/* pos 0370: 507 */ 0xEF /* 'o' -> */, +/* pos 0371: 508 */ 0xF2 /* 'r' -> */, +/* pos 0372: 509 */ 0xF4 /* 't' -> */, +/* pos 0373: 510 */ 0xAD /* '-' -> */, +/* pos 0374: 511 */ 0xF3 /* 's' -> */, +/* pos 0375: 512 */ 0xE5 /* 'e' -> */, +/* pos 0376: 513 */ 0xE3 /* 'c' -> */, +/* pos 0377: 514 */ 0xF5 /* 'u' -> */, +/* pos 0378: 515 */ 0xF2 /* 'r' -> */, +/* pos 0379: 516 */ 0xE9 /* 'i' -> */, +/* pos 037a: 517 */ 0xF4 /* 't' -> */, +/* pos 037b: 518 */ 0xF9 /* 'y' -> */, +/* pos 037c: 519 */ 0xBA /* ':' -> */, +/* pos 037d: 520 */ 0x00, 0x41 /* - terminal marker 65 - */, +/* pos 037f: 521 */ 0xE5 /* 'e' -> */, +/* pos 0380: 522 */ 0xF2 /* 'r' -> */, +/* pos 0381: 523 */ 0xAD /* '-' -> */, +/* pos 0382: 524 */ 0xE1 /* 'a' -> */, +/* pos 0383: 525 */ 0xE7 /* 'g' -> */, +/* pos 0384: 526 */ 0xE5 /* 'e' -> */, +/* pos 0385: 527 */ 0xEE /* 'n' -> */, +/* pos 0386: 528 */ 0xF4 /* 't' -> */, +/* pos 0387: 529 */ 0xBA /* ':' -> */, +/* pos 0388: 530 */ 0x00, 0x43 /* - terminal marker 67 - */, +/* pos 038a: 531 */ 0x61 /* 'a' */, 0x07, 0x00 /* (to 0x0391 state 532) */, + 0x69 /* 'i' */, 0x09, 0x00 /* (to 0x0396 state 536) */, + 0x08, /* fail */ +/* pos 0391: 532 */ 0xF2 /* 'r' -> */, +/* pos 0392: 533 */ 0xF9 /* 'y' -> */, +/* pos 0393: 534 */ 0xBA /* ':' -> */, +/* pos 0394: 535 */ 0x00, 0x44 /* - terminal marker 68 - */, +/* pos 0396: 536 */ 0xE1 /* 'a' -> */, +/* pos 0397: 537 */ 0xBA /* ':' -> */, +/* pos 0398: 538 */ 0x00, 0x45 /* - terminal marker 69 - */, +/* pos 039a: 539 */ 0xF7 /* 'w' -> */, +/* pos 039b: 540 */ 0xF7 /* 'w' -> */, +/* pos 039c: 541 */ 0xAD /* '-' -> */, +/* pos 039d: 542 */ 0xE1 /* 'a' -> */, +/* pos 039e: 543 */ 0xF5 /* 'u' -> */, +/* pos 039f: 544 */ 0xF4 /* 't' -> */, +/* pos 03a0: 545 */ 0xE8 /* 'h' -> */, +/* pos 03a1: 546 */ 0xE5 /* 'e' -> */, +/* pos 03a2: 547 */ 0xEE /* 'n' -> */, +/* pos 03a3: 548 */ 0xF4 /* 't' -> */, +/* pos 03a4: 549 */ 0xE9 /* 'i' -> */, +/* pos 03a5: 550 */ 0xE3 /* 'c' -> */, +/* pos 03a6: 551 */ 0xE1 /* 'a' -> */, +/* pos 03a7: 552 */ 0xF4 /* 't' -> */, +/* pos 03a8: 553 */ 0xE5 /* 'e' -> */, +/* pos 03a9: 554 */ 0xBA /* ':' -> */, +/* pos 03aa: 555 */ 0x00, 0x46 /* - terminal marker 70 - */, +/* pos 03ac: 556 */ 0xF4 /* 't' -> */, +/* pos 03ad: 557 */ 0xE3 /* 'c' -> */, +/* pos 03ae: 558 */ 0xE8 /* 'h' -> */, +/* pos 03af: 559 */ 0x00, 0x3F /* - terminal marker 63 - */, +/* pos 03b1: 560 */ 0xF4 /* 't' -> */, +/* pos 03b2: 561 */ 0x00, 0x40 /* - terminal marker 64 - */, +/* pos 03b4: 562 */ 0xEC /* 'l' -> */, +/* pos 03b5: 563 */ 0xE5 /* 'e' -> */, +/* pos 03b6: 564 */ 0xF4 /* 't' -> */, +/* pos 03b7: 565 */ 0xE5 /* 'e' -> */, +/* pos 03b8: 566 */ 0x00, 0x41 /* - terminal marker 65 - */, +/* pos 03ba: 567 */ 0x00, 0x43 /* - terminal marker 67 - */, +/* pos 03bc: 568 */ 0xE5 /* 'e' -> */, +/* pos 03bd: 569 */ 0xE1 /* 'a' -> */, +/* pos 03be: 570 */ 0xEC /* 'l' -> */, +/* pos 03bf: 571 */ 0xAD /* '-' -> */, +/* pos 03c0: 572 */ 0xE9 /* 'i' -> */, +/* pos 03c1: 573 */ 0xF0 /* 'p' -> */, +/* pos 03c2: 574 */ 0xBA /* ':' -> */, +/* pos 03c3: 575 */ 0x00, 0x44 /* - terminal marker 68 - */, +/* pos 03c5: 576 */ 0xBA /* ':' -> */, +/* pos 03c6: 577 */ 0x00, 0x4C /* - terminal marker 76 - */, +/* pos 03c8: 578 */ 0xEC /* 'l' -> */, +/* pos 03c9: 579 */ 0xE1 /* 'a' -> */, +/* pos 03ca: 580 */ 0xF9 /* 'y' -> */, +/* pos 03cb: 581 */ 0xAD /* '-' -> */, +/* pos 03cc: 582 */ 0xEE /* 'n' -> */, +/* pos 03cd: 583 */ 0xEF /* 'o' -> */, +/* pos 03ce: 584 */ 0xEE /* 'n' -> */, +/* pos 03cf: 585 */ 0xE3 /* 'c' -> */, +/* pos 03d0: 586 */ 0xE5 /* 'e' -> */, +/* pos 03d1: 587 */ 0xBA /* ':' -> */, +/* pos 03d2: 588 */ 0x00, 0x4D /* - terminal marker 77 - */, +/* pos 03d4: 589 */ 0xAD /* '-' -> */, +/* pos 03d5: 590 */ 0xF7 /* 'w' -> */, +/* pos 03d6: 591 */ 0xE5 /* 'e' -> */, +/* pos 03d7: 592 */ 0xE2 /* 'b' -> */, +/* pos 03d8: 593 */ 0xF3 /* 's' -> */, +/* pos 03d9: 594 */ 0xEF /* 'o' -> */, +/* pos 03da: 595 */ 0xE3 /* 'c' -> */, +/* pos 03db: 596 */ 0xEB /* 'k' -> */, +/* pos 03dc: 597 */ 0xE5 /* 'e' -> */, +/* pos 03dd: 598 */ 0xF4 /* 't' -> */, +/* pos 03de: 599 */ 0xAD /* '-' -> */, +/* pos 03df: 600 */ 0x64 /* 'd' */, 0x19, 0x00 /* (to 0x03F8 state 601) */, + 0x65 /* 'e' */, 0x1D, 0x00 /* (to 0x03FF state 607) */, + 0x6B /* 'k' */, 0x26, 0x00 /* (to 0x040B state 618) */, + 0x70 /* 'p' */, 0x35, 0x00 /* (to 0x041D state 625) */, + 0x61 /* 'a' */, 0x3C, 0x00 /* (to 0x0427 state 634) */, + 0x6E /* 'n' */, 0x41, 0x00 /* (to 0x042F state 641) */, + 0x76 /* 'v' */, 0x47, 0x00 /* (to 0x0438 state 648) */, + 0x6F /* 'o' */, 0x4D, 0x00 /* (to 0x0441 state 656) */, + 0x08, /* fail */ +/* pos 03f8: 601 */ 0xF2 /* 'r' -> */, +/* pos 03f9: 602 */ 0xE1 /* 'a' -> */, +/* pos 03fa: 603 */ 0xE6 /* 'f' -> */, +/* pos 03fb: 604 */ 0xF4 /* 't' -> */, +/* pos 03fc: 605 */ 0xBA /* ':' -> */, +/* pos 03fd: 606 */ 0x00, 0x06 /* - terminal marker 6 - */, +/* pos 03ff: 607 */ 0xF8 /* 'x' -> */, +/* pos 0400: 608 */ 0xF4 /* 't' -> */, +/* pos 0401: 609 */ 0xE5 /* 'e' -> */, +/* pos 0402: 610 */ 0xEE /* 'n' -> */, +/* pos 0403: 611 */ 0xF3 /* 's' -> */, +/* pos 0404: 612 */ 0xE9 /* 'i' -> */, +/* pos 0405: 613 */ 0xEF /* 'o' -> */, +/* pos 0406: 614 */ 0xEE /* 'n' -> */, +/* pos 0407: 615 */ 0xF3 /* 's' -> */, +/* pos 0408: 616 */ 0xBA /* ':' -> */, +/* pos 0409: 617 */ 0x00, 0x08 /* - terminal marker 8 - */, +/* pos 040b: 618 */ 0xE5 /* 'e' -> */, +/* pos 040c: 619 */ 0xF9 /* 'y' -> */, +/* pos 040d: 620 */ 0x31 /* '1' */, 0x0A, 0x00 /* (to 0x0417 state 621) */, + 0x32 /* '2' */, 0x0A, 0x00 /* (to 0x041A state 623) */, + 0x3A /* ':' */, 0x23, 0x00 /* (to 0x0436 state 647) */, + 0x08, /* fail */ +/* pos 0417: 621 */ 0xBA /* ':' -> */, +/* pos 0418: 622 */ 0x00, 0x09 /* - terminal marker 9 - */, +/* pos 041a: 623 */ 0xBA /* ':' -> */, +/* pos 041b: 624 */ 0x00, 0x0A /* - terminal marker 10 - */, +/* pos 041d: 625 */ 0xF2 /* 'r' -> */, +/* pos 041e: 626 */ 0xEF /* 'o' -> */, +/* pos 041f: 627 */ 0xF4 /* 't' -> */, +/* pos 0420: 628 */ 0xEF /* 'o' -> */, +/* pos 0421: 629 */ 0xE3 /* 'c' -> */, +/* pos 0422: 630 */ 0xEF /* 'o' -> */, +/* pos 0423: 631 */ 0xEC /* 'l' -> */, +/* pos 0424: 632 */ 0xBA /* ':' -> */, +/* pos 0425: 633 */ 0x00, 0x0B /* - terminal marker 11 - */, +/* pos 0427: 634 */ 0xE3 /* 'c' -> */, +/* pos 0428: 635 */ 0xE3 /* 'c' -> */, +/* pos 0429: 636 */ 0xE5 /* 'e' -> */, +/* pos 042a: 637 */ 0xF0 /* 'p' -> */, +/* pos 042b: 638 */ 0xF4 /* 't' -> */, +/* pos 042c: 639 */ 0xBA /* ':' -> */, +/* pos 042d: 640 */ 0x00, 0x0C /* - terminal marker 12 - */, +/* pos 042f: 641 */ 0xEF /* 'o' -> */, +/* pos 0430: 642 */ 0xEE /* 'n' -> */, +/* pos 0431: 643 */ 0xE3 /* 'c' -> */, +/* pos 0432: 644 */ 0xE5 /* 'e' -> */, +/* pos 0433: 645 */ 0xBA /* ':' -> */, +/* pos 0434: 646 */ 0x00, 0x0D /* - terminal marker 13 - */, +/* pos 0436: 647 */ 0x00, 0x1E /* - terminal marker 30 - */, +/* pos 0438: 648 */ 0xE5 /* 'e' -> */, +/* pos 0439: 649 */ 0xF2 /* 'r' -> */, +/* pos 043a: 650 */ 0xF3 /* 's' -> */, +/* pos 043b: 651 */ 0xE9 /* 'i' -> */, +/* pos 043c: 652 */ 0xEF /* 'o' -> */, +/* pos 043d: 653 */ 0xEE /* 'n' -> */, +/* pos 043e: 654 */ 0xBA /* ':' -> */, +/* pos 043f: 655 */ 0x00, 0x1F /* - terminal marker 31 - */, +/* pos 0441: 656 */ 0xF2 /* 'r' -> */, +/* pos 0442: 657 */ 0xE9 /* 'i' -> */, +/* pos 0443: 658 */ 0xE7 /* 'g' -> */, +/* pos 0444: 659 */ 0xE9 /* 'i' -> */, +/* pos 0445: 660 */ 0xEE /* 'n' -> */, +/* pos 0446: 661 */ 0xBA /* ':' -> */, +/* pos 0447: 662 */ 0x00, 0x20 /* - terminal marker 32 - */, +/* pos 0449: 663 */ 0xAD /* '-' -> */, +/* pos 044a: 664 */ 0xF3 /* 's' -> */, +/* pos 044b: 665 */ 0xE5 /* 'e' -> */, +/* pos 044c: 666 */ 0xF4 /* 't' -> */, +/* pos 044d: 667 */ 0xF4 /* 't' -> */, +/* pos 044e: 668 */ 0xE9 /* 'i' -> */, +/* pos 044f: 669 */ 0xEE /* 'n' -> */, +/* pos 0450: 670 */ 0xE7 /* 'g' -> */, +/* pos 0451: 671 */ 0xF3 /* 's' -> */, +/* pos 0452: 672 */ 0xBA /* ':' -> */, +/* pos 0453: 673 */ 0x00, 0x0F /* - terminal marker 15 - */, +/* pos 0455: 674 */ 0x61 /* 'a' */, 0x0D, 0x00 /* (to 0x0462 state 675) */, + 0x6D /* 'm' */, 0x14, 0x00 /* (to 0x046C state 684) */, + 0x70 /* 'p' */, 0x18, 0x00 /* (to 0x0473 state 690) */, + 0x73 /* 's' */, 0x20, 0x00 /* (to 0x047E state 694) */, + 0x08, /* fail */ +/* pos 0462: 675 */ 0xF5 /* 'u' -> */, +/* pos 0463: 676 */ 0xF4 /* 't' -> */, +/* pos 0464: 677 */ 0xE8 /* 'h' -> */, +/* pos 0465: 678 */ 0xEF /* 'o' -> */, +/* pos 0466: 679 */ 0xF2 /* 'r' -> */, +/* pos 0467: 680 */ 0xE9 /* 'i' -> */, +/* pos 0468: 681 */ 0xF4 /* 't' -> */, +/* pos 0469: 682 */ 0xF9 /* 'y' -> */, +/* pos 046a: 683 */ 0x00, 0x21 /* - terminal marker 33 - */, +/* pos 046c: 684 */ 0xE5 /* 'e' -> */, +/* pos 046d: 685 */ 0xF4 /* 't' -> */, +/* pos 046e: 686 */ 0xE8 /* 'h' -> */, +/* pos 046f: 687 */ 0xEF /* 'o' -> */, +/* pos 0470: 688 */ 0xE4 /* 'd' -> */, +/* pos 0471: 689 */ 0x00, 0x22 /* - terminal marker 34 - */, +/* pos 0473: 690 */ 0x61 /* 'a' */, 0x07, 0x00 /* (to 0x047A state 691) */, + 0x72 /* 'r' */, 0x1B, 0x00 /* (to 0x0491 state 705) */, + 0x08, /* fail */ +/* pos 047a: 691 */ 0xF4 /* 't' -> */, +/* pos 047b: 692 */ 0xE8 /* 'h' -> */, +/* pos 047c: 693 */ 0x00, 0x23 /* - terminal marker 35 - */, +/* pos 047e: 694 */ 0x63 /* 'c' */, 0x07, 0x00 /* (to 0x0485 state 695) */, + 0x74 /* 't' */, 0x0A, 0x00 /* (to 0x048B state 700) */, + 0x08, /* fail */ +/* pos 0485: 695 */ 0xE8 /* 'h' -> */, +/* pos 0486: 696 */ 0xE5 /* 'e' -> */, +/* pos 0487: 697 */ 0xED /* 'm' -> */, +/* pos 0488: 698 */ 0xE5 /* 'e' -> */, +/* pos 0489: 699 */ 0x00, 0x24 /* - terminal marker 36 - */, +/* pos 048b: 700 */ 0xE1 /* 'a' -> */, +/* pos 048c: 701 */ 0xF4 /* 't' -> */, +/* pos 048d: 702 */ 0xF5 /* 'u' -> */, +/* pos 048e: 703 */ 0xF3 /* 's' -> */, +/* pos 048f: 704 */ 0x00, 0x25 /* - terminal marker 37 - */, +/* pos 0491: 705 */ 0xEF /* 'o' -> */, +/* pos 0492: 706 */ 0xF4 /* 't' -> */, +/* pos 0493: 707 */ 0xEF /* 'o' -> */, +/* pos 0494: 708 */ 0xE3 /* 'c' -> */, +/* pos 0495: 709 */ 0xEF /* 'o' -> */, +/* pos 0496: 710 */ 0xEC /* 'l' -> */, +/* pos 0497: 711 */ 0x00, 0x4E /* - terminal marker 78 - */, +/* total size 1177 bytes */ +#endif + +#if defined(LWS_HTTP_HEADERS_ALL) || (defined(LWS_WITH_HTTP_UNCOMMON_HEADERS) && defined(LWS_ROLE_WS) && defined(LWS_ROLE_H2)) + /* 0: 0: get */ + /* 1: 1: post */ + /* 2: 2: options */ + /* 3: 3: host: */ + /* 4: 4: connection: */ + /* 5: 5: upgrade: */ + /* 6: 6: origin: */ + /* 7: 7: sec-websocket-draft: */ + /* 8: 8: + */ + /* 9: 9: sec-websocket-extensions: */ + /* 10: 10: sec-websocket-key1: */ + /* 11: 11: sec-websocket-key2: */ + /* 12: 12: sec-websocket-protocol: */ + /* 13: 13: sec-websocket-accept: */ + /* 14: 14: sec-websocket-nonce: */ + /* 15: 15: http/1.1 */ + /* 16: 16: http2-settings: */ + /* 17: 17: accept: */ + /* 18: 18: access-control-request-headers: */ + /* 19: 19: if-modified-since: */ + /* 20: 20: if-none-match: */ + /* 21: 21: accept-encoding: */ + /* 22: 22: accept-language: */ + /* 23: 23: pragma: */ + /* 24: 24: cache-control: */ + /* 25: 25: authorization: */ + /* 26: 26: cookie: */ + /* 27: 27: content-length: */ + /* 28: 28: content-type: */ + /* 29: 29: date: */ + /* 30: 30: range: */ + /* 31: 31: referer: */ + /* 32: 32: sec-websocket-key: */ + /* 33: 33: sec-websocket-version: */ + /* 34: 34: sec-websocket-origin: */ + /* 35: 35: :authority */ + /* 36: 36: :method */ + /* 37: 37: :path */ + /* 38: 38: :scheme */ + /* 39: 39: :status */ + /* 40: 40: accept-charset: */ + /* 41: 41: accept-ranges: */ + /* 42: 42: access-control-allow-origin: */ + /* 43: 43: age: */ + /* 44: 44: allow: */ + /* 45: 45: content-disposition: */ + /* 46: 46: content-encoding: */ + /* 47: 47: content-language: */ + /* 48: 48: content-location: */ + /* 49: 49: content-range: */ + /* 50: 50: etag: */ + /* 51: 51: expect: */ + /* 52: 52: expires: */ + /* 53: 53: from: */ + /* 54: 54: if-match: */ + /* 55: 55: if-range: */ + /* 56: 56: if-unmodified-since: */ + /* 57: 57: last-modified: */ + /* 58: 58: link: */ + /* 59: 59: location: */ + /* 60: 60: max-forwards: */ + /* 61: 61: proxy-authenticate: */ + /* 62: 62: proxy-authorization: */ + /* 63: 63: refresh: */ + /* 64: 64: retry-after: */ + /* 65: 65: server: */ + /* 66: 66: set-cookie: */ + /* 67: 67: strict-transport-security: */ + /* 68: 68: transfer-encoding: */ + /* 69: 69: user-agent: */ + /* 70: 70: vary: */ + /* 71: 71: via: */ + /* 72: 72: www-authenticate: */ + /* 73: 73: patch */ + /* 74: 74: put */ + /* 75: 75: delete */ + /* 76: 76: uri-args */ + /* 77: 77: proxy */ + /* 78: 78: x-real-ip: */ + /* 79: 79: http/1.0 */ + /* 80: 80: x-forwarded-for: */ + /* 81: 81: connect */ + /* 82: 82: head */ + /* 83: 83: te: */ + /* 84: 84: replay-nonce: */ + /* 85: 85: :protocol */ + /* 86: 86: x-auth-token: */ + /* 87: 87: */ +/* pos 0000: 0 */ 0x67 /* 'g' */, 0x40, 0x00 /* (to 0x0040 state 1) */, + 0x70 /* 'p' */, 0x42, 0x00 /* (to 0x0045 state 5) */, + 0x68 /* 'h' */, 0x51, 0x00 /* (to 0x0057 state 10) */, + 0x63 /* 'c' */, 0x5D, 0x00 /* (to 0x0066 state 15) */, + 0x75 /* 'u' */, 0x7E, 0x00 /* (to 0x008A state 26) */, + 0x6F /* 'o' */, 0x8D, 0x00 /* (to 0x009C state 34) */, + 0x0D /* '.' */, 0x98, 0x00 /* (to 0x00AA state 41) */, + 0x61 /* 'a' */, 0xAD, 0x00 /* (to 0x00C2 state 51) */, + 0x69 /* 'i' */, 0xCA, 0x00 /* (to 0x00E2 state 58) */, + 0x64 /* 'd' */, 0x73, 0x01 /* (to 0x018E state 160) */, + 0x72 /* 'r' */, 0x7C, 0x01 /* (to 0x019A state 165) */, + 0x65 /* 'e' */, 0xC8, 0x01 /* (to 0x01E9 state 229) */, + 0x66 /* 'f' */, 0xE4, 0x01 /* (to 0x0208 state 245) */, + 0x6C /* 'l' */, 0x06, 0x02 /* (to 0x022D state 278) */, + 0x73 /* 's' */, 0x4B, 0x02 /* (to 0x0275 state 321) */, + 0x74 /* 't' */, 0x69, 0x02 /* (to 0x0296 state 337) */, + 0x78 /* 'x' */, 0x8A, 0x02 /* (to 0x02BA state 364) */, + 0x6D /* 'm' */, 0xFB, 0x02 /* (to 0x032E state 456) */, + 0x76 /* 'v' */, 0x54, 0x03 /* (to 0x038A state 531) */, + 0x77 /* 'w' */, 0x61, 0x03 /* (to 0x039A state 539) */, + 0x3A /* ':' */, 0x19, 0x04 /* (to 0x0455 state 674) */, + 0x08, /* fail */ +/* pos 0040: 1 */ 0xE5 /* 'e' -> */, +/* pos 0041: 2 */ 0xF4 /* 't' -> */, +/* pos 0042: 3 */ 0xA0 /* ' ' -> */, +/* pos 0043: 4 */ 0x00, 0x00 /* - terminal marker 0 - */, +/* pos 0045: 5 */ 0x6F /* 'o' */, 0x0D, 0x00 /* (to 0x0052 state 6) */, + 0x72 /* 'r' */, 0xEC, 0x00 /* (to 0x0134 state 106) */, + 0x61 /* 'a' */, 0x61, 0x03 /* (to 0x03AC state 556) */, + 0x75 /* 'u' */, 0x63, 0x03 /* (to 0x03B1 state 560) */, + 0x08, /* fail */ +/* pos 0052: 6 */ 0xF3 /* 's' -> */, +/* pos 0053: 7 */ 0xF4 /* 't' -> */, +/* pos 0054: 8 */ 0xA0 /* ' ' -> */, +/* pos 0055: 9 */ 0x00, 0x01 /* - terminal marker 1 - */, +/* pos 0057: 10 */ 0x6F /* 'o' */, 0x0A, 0x00 /* (to 0x0061 state 11) */, + 0x74 /* 't' */, 0x53, 0x00 /* (to 0x00AD state 43) */, + 0x65 /* 'e' */, 0x79, 0x02 /* (to 0x02D6 state 381) */, + 0x08, /* fail */ +/* pos 0061: 11 */ 0xF3 /* 's' -> */, +/* pos 0062: 12 */ 0xF4 /* 't' -> */, +/* pos 0063: 13 */ 0xBA /* ':' -> */, +/* pos 0064: 14 */ 0x00, 0x03 /* - terminal marker 3 - */, +/* pos 0066: 15 */ 0x6F /* 'o' */, 0x07, 0x00 /* (to 0x006D state 16) */, + 0x61 /* 'a' */, 0xD8, 0x00 /* (to 0x0141 state 112) */, + 0x08, /* fail */ +/* pos 006d: 16 */ 0x6E /* 'n' */, 0x07, 0x00 /* (to 0x0074 state 17) */, + 0x6F /* 'o' */, 0xED, 0x00 /* (to 0x015D state 138) */, + 0x08, /* fail */ +/* pos 0074: 17 */ 0x6E /* 'n' */, 0x07, 0x00 /* (to 0x007B state 18) */, + 0x74 /* 't' */, 0xEC, 0x00 /* (to 0x0163 state 143) */, + 0x08, /* fail */ +/* pos 007b: 18 */ 0xE5 /* 'e' -> */, +/* pos 007c: 19 */ 0xE3 /* 'c' -> */, +/* pos 007d: 20 */ 0xF4 /* 't' -> */, +/* pos 007e: 21 */ 0x69 /* 'i' */, 0x07, 0x00 /* (to 0x0085 state 22) */, + 0x20 /* ' ' */, 0x53, 0x02 /* (to 0x02D4 state 380) */, + 0x08, /* fail */ +/* pos 0085: 22 */ 0xEF /* 'o' -> */, +/* pos 0086: 23 */ 0xEE /* 'n' -> */, +/* pos 0087: 24 */ 0xBA /* ':' -> */, +/* pos 0088: 25 */ 0x00, 0x04 /* - terminal marker 4 - */, +/* pos 008a: 26 */ 0x70 /* 'p' */, 0x0A, 0x00 /* (to 0x0094 state 27) */, + 0x72 /* 'r' */, 0x22, 0x02 /* (to 0x02AF state 355) */, + 0x73 /* 's' */, 0xEF, 0x02 /* (to 0x037F state 521) */, + 0x08, /* fail */ +/* pos 0094: 27 */ 0xE7 /* 'g' -> */, +/* pos 0095: 28 */ 0xF2 /* 'r' -> */, +/* pos 0096: 29 */ 0xE1 /* 'a' -> */, +/* pos 0097: 30 */ 0xE4 /* 'd' -> */, +/* pos 0098: 31 */ 0xE5 /* 'e' -> */, +/* pos 0099: 32 */ 0xBA /* ':' -> */, +/* pos 009a: 33 */ 0x00, 0x05 /* - terminal marker 5 - */, +/* pos 009c: 34 */ 0x72 /* 'r' */, 0x07, 0x00 /* (to 0x00A3 state 35) */, + 0x70 /* 'p' */, 0x48, 0x02 /* (to 0x02E7 state 396) */, + 0x08, /* fail */ +/* pos 00a3: 35 */ 0xE9 /* 'i' -> */, +/* pos 00a4: 36 */ 0xE7 /* 'g' -> */, +/* pos 00a5: 37 */ 0xE9 /* 'i' -> */, +/* pos 00a6: 38 */ 0xEE /* 'n' -> */, +/* pos 00a7: 39 */ 0xBA /* ':' -> */, +/* pos 00a8: 40 */ 0x00, 0x06 /* - terminal marker 6 - */, +/* pos 00aa: 41 */ 0x8A /* '.' -> */, +/* pos 00ab: 42 */ 0x00, 0x08 /* - terminal marker 8 - */, +/* pos 00ad: 43 */ 0xF4 /* 't' -> */, +/* pos 00ae: 44 */ 0xF0 /* 'p' -> */, +/* pos 00af: 45 */ 0x2F /* '/' */, 0x07, 0x00 /* (to 0x00B6 state 46) */, + 0x32 /* '2' */, 0x97, 0x03 /* (to 0x0449 state 663) */, + 0x08, /* fail */ +/* pos 00b6: 46 */ 0xB1 /* '1' -> */, +/* pos 00b7: 47 */ 0xAE /* '.' -> */, +/* pos 00b8: 48 */ 0x31 /* '1' */, 0x07, 0x00 /* (to 0x00BF state 49) */, + 0x30 /* '0' */, 0xFC, 0x01 /* (to 0x02B7 state 362) */, + 0x08, /* fail */ +/* pos 00bf: 49 */ 0xA0 /* ' ' -> */, +/* pos 00c0: 50 */ 0x00, 0x0F /* - terminal marker 15 - */, +/* pos 00c2: 51 */ 0x63 /* 'c' */, 0x0D, 0x00 /* (to 0x00CF state 52) */, + 0x75 /* 'u' */, 0x8A, 0x00 /* (to 0x014F state 125) */, + 0x67 /* 'g' */, 0xE7, 0x00 /* (to 0x01AF state 178) */, + 0x6C /* 'l' */, 0xE8, 0x00 /* (to 0x01B3 state 181) */, + 0x08, /* fail */ +/* pos 00cf: 52 */ 0xE3 /* 'c' -> */, +/* pos 00d0: 53 */ 0xE5 /* 'e' -> */, +/* pos 00d1: 54 */ 0x70 /* 'p' */, 0x07, 0x00 /* (to 0x00D8 state 55) */, + 0x73 /* 's' */, 0x1B, 0x02 /* (to 0x02EF state 403) */, + 0x08, /* fail */ +/* pos 00d8: 55 */ 0xF4 /* 't' -> */, +/* pos 00d9: 56 */ 0x3A /* ':' */, 0x07, 0x00 /* (to 0x00E0 state 57) */, + 0x2D /* '-' */, 0x37, 0x00 /* (to 0x0113 state 87) */, + 0x08, /* fail */ +/* pos 00e0: 57 */ 0x00, 0x11 /* - terminal marker 17 - */, +/* pos 00e2: 58 */ 0xE6 /* 'f' -> */, +/* pos 00e3: 59 */ 0xAD /* '-' -> */, +/* pos 00e4: 60 */ 0x6D /* 'm' */, 0x0D, 0x00 /* (to 0x00F1 state 61) */, + 0x6E /* 'n' */, 0x20, 0x00 /* (to 0x0107 state 76) */, + 0x72 /* 'r' */, 0x2A, 0x01 /* (to 0x0214 state 255) */, + 0x75 /* 'u' */, 0x2E, 0x01 /* (to 0x021B state 261) */, + 0x08, /* fail */ +/* pos 00f1: 61 */ 0x6F /* 'o' */, 0x07, 0x00 /* (to 0x00F8 state 62) */, + 0x61 /* 'a' */, 0x1A, 0x01 /* (to 0x020E state 250) */, + 0x08, /* fail */ +/* pos 00f8: 62 */ 0xE4 /* 'd' -> */, +/* pos 00f9: 63 */ 0xE9 /* 'i' -> */, +/* pos 00fa: 64 */ 0xE6 /* 'f' -> */, +/* pos 00fb: 65 */ 0xE9 /* 'i' -> */, +/* pos 00fc: 66 */ 0xE5 /* 'e' -> */, +/* pos 00fd: 67 */ 0xE4 /* 'd' -> */, +/* pos 00fe: 68 */ 0xAD /* '-' -> */, +/* pos 00ff: 69 */ 0xF3 /* 's' -> */, +/* pos 0100: 70 */ 0xE9 /* 'i' -> */, +/* pos 0101: 71 */ 0xEE /* 'n' -> */, +/* pos 0102: 72 */ 0xE3 /* 'c' -> */, +/* pos 0103: 73 */ 0xE5 /* 'e' -> */, +/* pos 0104: 74 */ 0xBA /* ':' -> */, +/* pos 0105: 75 */ 0x00, 0x13 /* - terminal marker 19 - */, +/* pos 0107: 76 */ 0xEF /* 'o' -> */, +/* pos 0108: 77 */ 0xEE /* 'n' -> */, +/* pos 0109: 78 */ 0xE5 /* 'e' -> */, +/* pos 010a: 79 */ 0xAD /* '-' -> */, +/* pos 010b: 80 */ 0xED /* 'm' -> */, +/* pos 010c: 81 */ 0xE1 /* 'a' -> */, +/* pos 010d: 82 */ 0xF4 /* 't' -> */, +/* pos 010e: 83 */ 0xE3 /* 'c' -> */, +/* pos 010f: 84 */ 0xE8 /* 'h' -> */, +/* pos 0110: 85 */ 0xBA /* ':' -> */, +/* pos 0111: 86 */ 0x00, 0x14 /* - terminal marker 20 - */, +/* pos 0113: 87 */ 0x65 /* 'e' */, 0x0D, 0x00 /* (to 0x0120 state 88) */, + 0x6C /* 'l' */, 0x14, 0x00 /* (to 0x012A state 97) */, + 0x72 /* 'r' */, 0x8E, 0x00 /* (to 0x01A7 state 171) */, + 0x63 /* 'c' */, 0xFB, 0x01 /* (to 0x0317 state 435) */, + 0x08, /* fail */ +/* pos 0120: 88 */ 0xEE /* 'n' -> */, +/* pos 0121: 89 */ 0xE3 /* 'c' -> */, +/* pos 0122: 90 */ 0xEF /* 'o' -> */, +/* pos 0123: 91 */ 0xE4 /* 'd' -> */, +/* pos 0124: 92 */ 0xE9 /* 'i' -> */, +/* pos 0125: 93 */ 0xEE /* 'n' -> */, +/* pos 0126: 94 */ 0xE7 /* 'g' -> */, +/* pos 0127: 95 */ 0xBA /* ':' -> */, +/* pos 0128: 96 */ 0x00, 0x15 /* - terminal marker 21 - */, +/* pos 012a: 97 */ 0xE1 /* 'a' -> */, +/* pos 012b: 98 */ 0xEE /* 'n' -> */, +/* pos 012c: 99 */ 0xE7 /* 'g' -> */, +/* pos 012d: 100 */ 0xF5 /* 'u' -> */, +/* pos 012e: 101 */ 0xE1 /* 'a' -> */, +/* pos 012f: 102 */ 0xE7 /* 'g' -> */, +/* pos 0130: 103 */ 0xE5 /* 'e' -> */, +/* pos 0131: 104 */ 0xBA /* ':' -> */, +/* pos 0132: 105 */ 0x00, 0x16 /* - terminal marker 22 - */, +/* pos 0134: 106 */ 0x61 /* 'a' */, 0x07, 0x00 /* (to 0x013B state 107) */, + 0x6F /* 'o' */, 0x05, 0x02 /* (to 0x033C state 469) */, + 0x08, /* fail */ +/* pos 013b: 107 */ 0xE7 /* 'g' -> */, +/* pos 013c: 108 */ 0xED /* 'm' -> */, +/* pos 013d: 109 */ 0xE1 /* 'a' -> */, +/* pos 013e: 110 */ 0xBA /* ':' -> */, +/* pos 013f: 111 */ 0x00, 0x17 /* - terminal marker 23 - */, +/* pos 0141: 112 */ 0xE3 /* 'c' -> */, +/* pos 0142: 113 */ 0xE8 /* 'h' -> */, +/* pos 0143: 114 */ 0xE5 /* 'e' -> */, +/* pos 0144: 115 */ 0xAD /* '-' -> */, +/* pos 0145: 116 */ 0xE3 /* 'c' -> */, +/* pos 0146: 117 */ 0xEF /* 'o' -> */, +/* pos 0147: 118 */ 0xEE /* 'n' -> */, +/* pos 0148: 119 */ 0xF4 /* 't' -> */, +/* pos 0149: 120 */ 0xF2 /* 'r' -> */, +/* pos 014a: 121 */ 0xEF /* 'o' -> */, +/* pos 014b: 122 */ 0xEC /* 'l' -> */, +/* pos 014c: 123 */ 0xBA /* ':' -> */, +/* pos 014d: 124 */ 0x00, 0x18 /* - terminal marker 24 - */, +/* pos 014f: 125 */ 0xF4 /* 't' -> */, +/* pos 0150: 126 */ 0xE8 /* 'h' -> */, +/* pos 0151: 127 */ 0xEF /* 'o' -> */, +/* pos 0152: 128 */ 0xF2 /* 'r' -> */, +/* pos 0153: 129 */ 0xE9 /* 'i' -> */, +/* pos 0154: 130 */ 0xFA /* 'z' -> */, +/* pos 0155: 131 */ 0xE1 /* 'a' -> */, +/* pos 0156: 132 */ 0xF4 /* 't' -> */, +/* pos 0157: 133 */ 0xE9 /* 'i' -> */, +/* pos 0158: 134 */ 0xEF /* 'o' -> */, +/* pos 0159: 135 */ 0xEE /* 'n' -> */, +/* pos 015a: 136 */ 0xBA /* ':' -> */, +/* pos 015b: 137 */ 0x00, 0x19 /* - terminal marker 25 - */, +/* pos 015d: 138 */ 0xEB /* 'k' -> */, +/* pos 015e: 139 */ 0xE9 /* 'i' -> */, +/* pos 015f: 140 */ 0xE5 /* 'e' -> */, +/* pos 0160: 141 */ 0xBA /* ':' -> */, +/* pos 0161: 142 */ 0x00, 0x1A /* - terminal marker 26 - */, +/* pos 0163: 143 */ 0xE5 /* 'e' -> */, +/* pos 0164: 144 */ 0xEE /* 'n' -> */, +/* pos 0165: 145 */ 0xF4 /* 't' -> */, +/* pos 0166: 146 */ 0xAD /* '-' -> */, +/* pos 0167: 147 */ 0x6C /* 'l' */, 0x10, 0x00 /* (to 0x0177 state 148) */, + 0x74 /* 't' */, 0x1E, 0x00 /* (to 0x0188 state 155) */, + 0x64 /* 'd' */, 0x4C, 0x00 /* (to 0x01B9 state 186) */, + 0x65 /* 'e' */, 0x56, 0x00 /* (to 0x01C6 state 198) */, + 0x72 /* 'r' */, 0x6F, 0x00 /* (to 0x01E2 state 223) */, + 0x08, /* fail */ +/* pos 0177: 148 */ 0x65 /* 'e' */, 0x0A, 0x00 /* (to 0x0181 state 149) */, + 0x61 /* 'a' */, 0x56, 0x00 /* (to 0x01D0 state 207) */, + 0x6F /* 'o' */, 0x5C, 0x00 /* (to 0x01D9 state 215) */, + 0x08, /* fail */ +/* pos 0181: 149 */ 0xEE /* 'n' -> */, +/* pos 0182: 150 */ 0xE7 /* 'g' -> */, +/* pos 0183: 151 */ 0xF4 /* 't' -> */, +/* pos 0184: 152 */ 0xE8 /* 'h' -> */, +/* pos 0185: 153 */ 0xBA /* ':' -> */, +/* pos 0186: 154 */ 0x00, 0x1B /* - terminal marker 27 - */, +/* pos 0188: 155 */ 0xF9 /* 'y' -> */, +/* pos 0189: 156 */ 0xF0 /* 'p' -> */, +/* pos 018a: 157 */ 0xE5 /* 'e' -> */, +/* pos 018b: 158 */ 0xBA /* ':' -> */, +/* pos 018c: 159 */ 0x00, 0x1C /* - terminal marker 28 - */, +/* pos 018e: 160 */ 0x61 /* 'a' */, 0x07, 0x00 /* (to 0x0195 state 161) */, + 0x65 /* 'e' */, 0x23, 0x02 /* (to 0x03B4 state 562) */, + 0x08, /* fail */ +/* pos 0195: 161 */ 0xF4 /* 't' -> */, +/* pos 0196: 162 */ 0xE5 /* 'e' -> */, +/* pos 0197: 163 */ 0xBA /* ':' -> */, +/* pos 0198: 164 */ 0x00, 0x1D /* - terminal marker 29 - */, +/* pos 019a: 165 */ 0x61 /* 'a' */, 0x07, 0x00 /* (to 0x01A1 state 166) */, + 0x65 /* 'e' */, 0xB6, 0x00 /* (to 0x0253 state 304) */, + 0x08, /* fail */ +/* pos 01a1: 166 */ 0xEE /* 'n' -> */, +/* pos 01a2: 167 */ 0xE7 /* 'g' -> */, +/* pos 01a3: 168 */ 0xE5 /* 'e' -> */, +/* pos 01a4: 169 */ 0xBA /* ':' -> */, +/* pos 01a5: 170 */ 0x00, 0x1E /* - terminal marker 30 - */, +/* pos 01a7: 171 */ 0xE1 /* 'a' -> */, +/* pos 01a8: 172 */ 0xEE /* 'n' -> */, +/* pos 01a9: 173 */ 0xE7 /* 'g' -> */, +/* pos 01aa: 174 */ 0xE5 /* 'e' -> */, +/* pos 01ab: 175 */ 0xF3 /* 's' -> */, +/* pos 01ac: 176 */ 0xBA /* ':' -> */, +/* pos 01ad: 177 */ 0x00, 0x29 /* - terminal marker 41 - */, +/* pos 01af: 178 */ 0xE5 /* 'e' -> */, +/* pos 01b0: 179 */ 0xBA /* ':' -> */, +/* pos 01b1: 180 */ 0x00, 0x2B /* - terminal marker 43 - */, +/* pos 01b3: 181 */ 0xEC /* 'l' -> */, +/* pos 01b4: 182 */ 0xEF /* 'o' -> */, +/* pos 01b5: 183 */ 0xF7 /* 'w' -> */, +/* pos 01b6: 184 */ 0xBA /* ':' -> */, +/* pos 01b7: 185 */ 0x00, 0x2C /* - terminal marker 44 - */, +/* pos 01b9: 186 */ 0xE9 /* 'i' -> */, +/* pos 01ba: 187 */ 0xF3 /* 's' -> */, +/* pos 01bb: 188 */ 0xF0 /* 'p' -> */, +/* pos 01bc: 189 */ 0xEF /* 'o' -> */, +/* pos 01bd: 190 */ 0xF3 /* 's' -> */, +/* pos 01be: 191 */ 0xE9 /* 'i' -> */, +/* pos 01bf: 192 */ 0xF4 /* 't' -> */, +/* pos 01c0: 193 */ 0xE9 /* 'i' -> */, +/* pos 01c1: 194 */ 0xEF /* 'o' -> */, +/* pos 01c2: 195 */ 0xEE /* 'n' -> */, +/* pos 01c3: 196 */ 0xBA /* ':' -> */, +/* pos 01c4: 197 */ 0x00, 0x2D /* - terminal marker 45 - */, +/* pos 01c6: 198 */ 0xEE /* 'n' -> */, +/* pos 01c7: 199 */ 0xE3 /* 'c' -> */, +/* pos 01c8: 200 */ 0xEF /* 'o' -> */, +/* pos 01c9: 201 */ 0xE4 /* 'd' -> */, +/* pos 01ca: 202 */ 0xE9 /* 'i' -> */, +/* pos 01cb: 203 */ 0xEE /* 'n' -> */, +/* pos 01cc: 204 */ 0xE7 /* 'g' -> */, +/* pos 01cd: 205 */ 0xBA /* ':' -> */, +/* pos 01ce: 206 */ 0x00, 0x2E /* - terminal marker 46 - */, +/* pos 01d0: 207 */ 0xEE /* 'n' -> */, +/* pos 01d1: 208 */ 0xE7 /* 'g' -> */, +/* pos 01d2: 209 */ 0xF5 /* 'u' -> */, +/* pos 01d3: 210 */ 0xE1 /* 'a' -> */, +/* pos 01d4: 211 */ 0xE7 /* 'g' -> */, +/* pos 01d5: 212 */ 0xE5 /* 'e' -> */, +/* pos 01d6: 213 */ 0xBA /* ':' -> */, +/* pos 01d7: 214 */ 0x00, 0x2F /* - terminal marker 47 - */, +/* pos 01d9: 215 */ 0xE3 /* 'c' -> */, +/* pos 01da: 216 */ 0xE1 /* 'a' -> */, +/* pos 01db: 217 */ 0xF4 /* 't' -> */, +/* pos 01dc: 218 */ 0xE9 /* 'i' -> */, +/* pos 01dd: 219 */ 0xEF /* 'o' -> */, +/* pos 01de: 220 */ 0xEE /* 'n' -> */, +/* pos 01df: 221 */ 0xBA /* ':' -> */, +/* pos 01e0: 222 */ 0x00, 0x30 /* - terminal marker 48 - */, +/* pos 01e2: 223 */ 0xE1 /* 'a' -> */, +/* pos 01e3: 224 */ 0xEE /* 'n' -> */, +/* pos 01e4: 225 */ 0xE7 /* 'g' -> */, +/* pos 01e5: 226 */ 0xE5 /* 'e' -> */, +/* pos 01e6: 227 */ 0xBA /* ':' -> */, +/* pos 01e7: 228 */ 0x00, 0x31 /* - terminal marker 49 - */, +/* pos 01e9: 229 */ 0x74 /* 't' */, 0x07, 0x00 /* (to 0x01F0 state 230) */, + 0x78 /* 'x' */, 0x09, 0x00 /* (to 0x01F5 state 234) */, + 0x08, /* fail */ +/* pos 01f0: 230 */ 0xE1 /* 'a' -> */, +/* pos 01f1: 231 */ 0xE7 /* 'g' -> */, +/* pos 01f2: 232 */ 0xBA /* ':' -> */, +/* pos 01f3: 233 */ 0x00, 0x32 /* - terminal marker 50 - */, +/* pos 01f5: 234 */ 0xF0 /* 'p' -> */, +/* pos 01f6: 235 */ 0x65 /* 'e' */, 0x07, 0x00 /* (to 0x01FD state 236) */, + 0x69 /* 'i' */, 0x09, 0x00 /* (to 0x0202 state 240) */, + 0x08, /* fail */ +/* pos 01fd: 236 */ 0xE3 /* 'c' -> */, +/* pos 01fe: 237 */ 0xF4 /* 't' -> */, +/* pos 01ff: 238 */ 0xBA /* ':' -> */, +/* pos 0200: 239 */ 0x00, 0x33 /* - terminal marker 51 - */, +/* pos 0202: 240 */ 0xF2 /* 'r' -> */, +/* pos 0203: 241 */ 0xE5 /* 'e' -> */, +/* pos 0204: 242 */ 0xF3 /* 's' -> */, +/* pos 0205: 243 */ 0xBA /* ':' -> */, +/* pos 0206: 244 */ 0x00, 0x34 /* - terminal marker 52 - */, +/* pos 0208: 245 */ 0xF2 /* 'r' -> */, +/* pos 0209: 246 */ 0xEF /* 'o' -> */, +/* pos 020a: 247 */ 0xED /* 'm' -> */, +/* pos 020b: 248 */ 0xBA /* ':' -> */, +/* pos 020c: 249 */ 0x00, 0x35 /* - terminal marker 53 - */, +/* pos 020e: 250 */ 0xF4 /* 't' -> */, +/* pos 020f: 251 */ 0xE3 /* 'c' -> */, +/* pos 0210: 252 */ 0xE8 /* 'h' -> */, +/* pos 0211: 253 */ 0xBA /* ':' -> */, +/* pos 0212: 254 */ 0x00, 0x36 /* - terminal marker 54 - */, +/* pos 0214: 255 */ 0xE1 /* 'a' -> */, +/* pos 0215: 256 */ 0xEE /* 'n' -> */, +/* pos 0216: 257 */ 0xE7 /* 'g' -> */, +/* pos 0217: 258 */ 0xE5 /* 'e' -> */, +/* pos 0218: 259 */ 0xBA /* ':' -> */, +/* pos 0219: 260 */ 0x00, 0x37 /* - terminal marker 55 - */, +/* pos 021b: 261 */ 0xEE /* 'n' -> */, +/* pos 021c: 262 */ 0xED /* 'm' -> */, +/* pos 021d: 263 */ 0xEF /* 'o' -> */, +/* pos 021e: 264 */ 0xE4 /* 'd' -> */, +/* pos 021f: 265 */ 0xE9 /* 'i' -> */, +/* pos 0220: 266 */ 0xE6 /* 'f' -> */, +/* pos 0221: 267 */ 0xE9 /* 'i' -> */, +/* pos 0222: 268 */ 0xE5 /* 'e' -> */, +/* pos 0223: 269 */ 0xE4 /* 'd' -> */, +/* pos 0224: 270 */ 0xAD /* '-' -> */, +/* pos 0225: 271 */ 0xF3 /* 's' -> */, +/* pos 0226: 272 */ 0xE9 /* 'i' -> */, +/* pos 0227: 273 */ 0xEE /* 'n' -> */, +/* pos 0228: 274 */ 0xE3 /* 'c' -> */, +/* pos 0229: 275 */ 0xE5 /* 'e' -> */, +/* pos 022a: 276 */ 0xBA /* ':' -> */, +/* pos 022b: 277 */ 0x00, 0x38 /* - terminal marker 56 - */, +/* pos 022d: 278 */ 0x61 /* 'a' */, 0x0A, 0x00 /* (to 0x0237 state 279) */, + 0x69 /* 'i' */, 0x15, 0x00 /* (to 0x0245 state 292) */, + 0x6F /* 'o' */, 0x17, 0x00 /* (to 0x024A state 296) */, + 0x08, /* fail */ +/* pos 0237: 279 */ 0xF3 /* 's' -> */, +/* pos 0238: 280 */ 0xF4 /* 't' -> */, +/* pos 0239: 281 */ 0xAD /* '-' -> */, +/* pos 023a: 282 */ 0xED /* 'm' -> */, +/* pos 023b: 283 */ 0xEF /* 'o' -> */, +/* pos 023c: 284 */ 0xE4 /* 'd' -> */, +/* pos 023d: 285 */ 0xE9 /* 'i' -> */, +/* pos 023e: 286 */ 0xE6 /* 'f' -> */, +/* pos 023f: 287 */ 0xE9 /* 'i' -> */, +/* pos 0240: 288 */ 0xE5 /* 'e' -> */, +/* pos 0241: 289 */ 0xE4 /* 'd' -> */, +/* pos 0242: 290 */ 0xBA /* ':' -> */, +/* pos 0243: 291 */ 0x00, 0x39 /* - terminal marker 57 - */, +/* pos 0245: 292 */ 0xEE /* 'n' -> */, +/* pos 0246: 293 */ 0xEB /* 'k' -> */, +/* pos 0247: 294 */ 0xBA /* ':' -> */, +/* pos 0248: 295 */ 0x00, 0x3A /* - terminal marker 58 - */, +/* pos 024a: 296 */ 0xE3 /* 'c' -> */, +/* pos 024b: 297 */ 0xE1 /* 'a' -> */, +/* pos 024c: 298 */ 0xF4 /* 't' -> */, +/* pos 024d: 299 */ 0xE9 /* 'i' -> */, +/* pos 024e: 300 */ 0xEF /* 'o' -> */, +/* pos 024f: 301 */ 0xEE /* 'n' -> */, +/* pos 0250: 302 */ 0xBA /* ':' -> */, +/* pos 0251: 303 */ 0x00, 0x3B /* - terminal marker 59 - */, +/* pos 0253: 304 */ 0x66 /* 'f' */, 0x0A, 0x00 /* (to 0x025D state 305) */, + 0x74 /* 't' */, 0x14, 0x00 /* (to 0x026A state 311) */, + 0x70 /* 'p' */, 0x6F, 0x01 /* (to 0x03C8 state 578) */, + 0x08, /* fail */ +/* pos 025d: 305 */ 0x72 /* 'r' */, 0x07, 0x00 /* (to 0x0264 state 306) */, + 0x65 /* 'e' */, 0xB1, 0x00 /* (to 0x0311 state 430) */, + 0x08, /* fail */ +/* pos 0264: 306 */ 0xE5 /* 'e' -> */, +/* pos 0265: 307 */ 0xF3 /* 's' -> */, +/* pos 0266: 308 */ 0xE8 /* 'h' -> */, +/* pos 0267: 309 */ 0xBA /* ':' -> */, +/* pos 0268: 310 */ 0x00, 0x3F /* - terminal marker 63 - */, +/* pos 026a: 311 */ 0xF2 /* 'r' -> */, +/* pos 026b: 312 */ 0xF9 /* 'y' -> */, +/* pos 026c: 313 */ 0xAD /* '-' -> */, +/* pos 026d: 314 */ 0xE1 /* 'a' -> */, +/* pos 026e: 315 */ 0xE6 /* 'f' -> */, +/* pos 026f: 316 */ 0xF4 /* 't' -> */, +/* pos 0270: 317 */ 0xE5 /* 'e' -> */, +/* pos 0271: 318 */ 0xF2 /* 'r' -> */, +/* pos 0272: 319 */ 0xBA /* ':' -> */, +/* pos 0273: 320 */ 0x00, 0x40 /* - terminal marker 64 - */, +/* pos 0275: 321 */ 0x65 /* 'e' */, 0x07, 0x00 /* (to 0x027C state 322) */, + 0x74 /* 't' */, 0xED, 0x00 /* (to 0x0365 state 496) */, + 0x08, /* fail */ +/* pos 027c: 322 */ 0x72 /* 'r' */, 0x0A, 0x00 /* (to 0x0286 state 323) */, + 0x74 /* 't' */, 0x0D, 0x00 /* (to 0x028C state 328) */, + 0x63 /* 'c' */, 0x52, 0x01 /* (to 0x03D4 state 589) */, + 0x08, /* fail */ +/* pos 0286: 323 */ 0xF6 /* 'v' -> */, +/* pos 0287: 324 */ 0xE5 /* 'e' -> */, +/* pos 0288: 325 */ 0xF2 /* 'r' -> */, +/* pos 0289: 326 */ 0xBA /* ':' -> */, +/* pos 028a: 327 */ 0x00, 0x41 /* - terminal marker 65 - */, +/* pos 028c: 328 */ 0xAD /* '-' -> */, +/* pos 028d: 329 */ 0xE3 /* 'c' -> */, +/* pos 028e: 330 */ 0xEF /* 'o' -> */, +/* pos 028f: 331 */ 0xEF /* 'o' -> */, +/* pos 0290: 332 */ 0xEB /* 'k' -> */, +/* pos 0291: 333 */ 0xE9 /* 'i' -> */, +/* pos 0292: 334 */ 0xE5 /* 'e' -> */, +/* pos 0293: 335 */ 0xBA /* ':' -> */, +/* pos 0294: 336 */ 0x00, 0x42 /* - terminal marker 66 - */, +/* pos 0296: 337 */ 0x72 /* 'r' */, 0x07, 0x00 /* (to 0x029D state 338) */, + 0x65 /* 'e' */, 0x2C, 0x01 /* (to 0x03C5 state 576) */, + 0x08, /* fail */ +/* pos 029d: 338 */ 0xE1 /* 'a' -> */, +/* pos 029e: 339 */ 0xEE /* 'n' -> */, +/* pos 029f: 340 */ 0xF3 /* 's' -> */, +/* pos 02a0: 341 */ 0xE6 /* 'f' -> */, +/* pos 02a1: 342 */ 0xE5 /* 'e' -> */, +/* pos 02a2: 343 */ 0xF2 /* 'r' -> */, +/* pos 02a3: 344 */ 0xAD /* '-' -> */, +/* pos 02a4: 345 */ 0xE5 /* 'e' -> */, +/* pos 02a5: 346 */ 0xEE /* 'n' -> */, +/* pos 02a6: 347 */ 0xE3 /* 'c' -> */, +/* pos 02a7: 348 */ 0xEF /* 'o' -> */, +/* pos 02a8: 349 */ 0xE4 /* 'd' -> */, +/* pos 02a9: 350 */ 0xE9 /* 'i' -> */, +/* pos 02aa: 351 */ 0xEE /* 'n' -> */, +/* pos 02ab: 352 */ 0xE7 /* 'g' -> */, +/* pos 02ac: 353 */ 0xBA /* ':' -> */, +/* pos 02ad: 354 */ 0x00, 0x44 /* - terminal marker 68 - */, +/* pos 02af: 355 */ 0xE9 /* 'i' -> */, +/* pos 02b0: 356 */ 0xAD /* '-' -> */, +/* pos 02b1: 357 */ 0xE1 /* 'a' -> */, +/* pos 02b2: 358 */ 0xF2 /* 'r' -> */, +/* pos 02b3: 359 */ 0xE7 /* 'g' -> */, +/* pos 02b4: 360 */ 0xF3 /* 's' -> */, +/* pos 02b5: 361 */ 0x00, 0x4C /* - terminal marker 76 - */, +/* pos 02b7: 362 */ 0xA0 /* ' ' -> */, +/* pos 02b8: 363 */ 0x00, 0x4F /* - terminal marker 79 - */, +/* pos 02ba: 364 */ 0xAD /* '-' -> */, +/* pos 02bb: 365 */ 0x66 /* 'f' */, 0x0A, 0x00 /* (to 0x02C5 state 366) */, + 0x61 /* 'a' */, 0x1D, 0x00 /* (to 0x02DB state 385) */, + 0x72 /* 'r' */, 0xFB, 0x00 /* (to 0x03BC state 568) */, + 0x08, /* fail */ +/* pos 02c5: 366 */ 0xEF /* 'o' -> */, +/* pos 02c6: 367 */ 0xF2 /* 'r' -> */, +/* pos 02c7: 368 */ 0xF7 /* 'w' -> */, +/* pos 02c8: 369 */ 0xE1 /* 'a' -> */, +/* pos 02c9: 370 */ 0xF2 /* 'r' -> */, +/* pos 02ca: 371 */ 0xE4 /* 'd' -> */, +/* pos 02cb: 372 */ 0xE5 /* 'e' -> */, +/* pos 02cc: 373 */ 0xE4 /* 'd' -> */, +/* pos 02cd: 374 */ 0xAD /* '-' -> */, +/* pos 02ce: 375 */ 0xE6 /* 'f' -> */, +/* pos 02cf: 376 */ 0xEF /* 'o' -> */, +/* pos 02d0: 377 */ 0xF2 /* 'r' -> */, +/* pos 02d1: 378 */ 0xBA /* ':' -> */, +/* pos 02d2: 379 */ 0x00, 0x50 /* - terminal marker 80 - */, +/* pos 02d4: 380 */ 0x00, 0x51 /* - terminal marker 81 - */, +/* pos 02d6: 381 */ 0xE1 /* 'a' -> */, +/* pos 02d7: 382 */ 0xE4 /* 'd' -> */, +/* pos 02d8: 383 */ 0xA0 /* ' ' -> */, +/* pos 02d9: 384 */ 0x00, 0x52 /* - terminal marker 82 - */, +/* pos 02db: 385 */ 0xF5 /* 'u' -> */, +/* pos 02dc: 386 */ 0xF4 /* 't' -> */, +/* pos 02dd: 387 */ 0xE8 /* 'h' -> */, +/* pos 02de: 388 */ 0xAD /* '-' -> */, +/* pos 02df: 389 */ 0xF4 /* 't' -> */, +/* pos 02e0: 390 */ 0xEF /* 'o' -> */, +/* pos 02e1: 391 */ 0xEB /* 'k' -> */, +/* pos 02e2: 392 */ 0xE5 /* 'e' -> */, +/* pos 02e3: 393 */ 0xEE /* 'n' -> */, +/* pos 02e4: 394 */ 0xBA /* ':' -> */, +/* pos 02e5: 395 */ 0x00, 0x56 /* - terminal marker 86 - */, +/* pos 02e7: 396 */ 0xF4 /* 't' -> */, +/* pos 02e8: 397 */ 0xE9 /* 'i' -> */, +/* pos 02e9: 398 */ 0xEF /* 'o' -> */, +/* pos 02ea: 399 */ 0xEE /* 'n' -> */, +/* pos 02eb: 400 */ 0xF3 /* 's' -> */, +/* pos 02ec: 401 */ 0xA0 /* ' ' -> */, +/* pos 02ed: 402 */ 0x00, 0x02 /* - terminal marker 2 - */, +/* pos 02ef: 403 */ 0xF3 /* 's' -> */, +/* pos 02f0: 404 */ 0xAD /* '-' -> */, +/* pos 02f1: 405 */ 0xE3 /* 'c' -> */, +/* pos 02f2: 406 */ 0xEF /* 'o' -> */, +/* pos 02f3: 407 */ 0xEE /* 'n' -> */, +/* pos 02f4: 408 */ 0xF4 /* 't' -> */, +/* pos 02f5: 409 */ 0xF2 /* 'r' -> */, +/* pos 02f6: 410 */ 0xEF /* 'o' -> */, +/* pos 02f7: 411 */ 0xEC /* 'l' -> */, +/* pos 02f8: 412 */ 0xAD /* '-' -> */, +/* pos 02f9: 413 */ 0x72 /* 'r' */, 0x07, 0x00 /* (to 0x0300 state 414) */, + 0x61 /* 'a' */, 0x24, 0x00 /* (to 0x0320 state 443) */, + 0x08, /* fail */ +/* pos 0300: 414 */ 0xE5 /* 'e' -> */, +/* pos 0301: 415 */ 0xF1 /* 'q' -> */, +/* pos 0302: 416 */ 0xF5 /* 'u' -> */, +/* pos 0303: 417 */ 0xE5 /* 'e' -> */, +/* pos 0304: 418 */ 0xF3 /* 's' -> */, +/* pos 0305: 419 */ 0xF4 /* 't' -> */, +/* pos 0306: 420 */ 0xAD /* '-' -> */, +/* pos 0307: 421 */ 0xE8 /* 'h' -> */, +/* pos 0308: 422 */ 0xE5 /* 'e' -> */, +/* pos 0309: 423 */ 0xE1 /* 'a' -> */, +/* pos 030a: 424 */ 0xE4 /* 'd' -> */, +/* pos 030b: 425 */ 0xE5 /* 'e' -> */, +/* pos 030c: 426 */ 0xF2 /* 'r' -> */, +/* pos 030d: 427 */ 0xF3 /* 's' -> */, +/* pos 030e: 428 */ 0xBA /* ':' -> */, +/* pos 030f: 429 */ 0x00, 0x12 /* - terminal marker 18 - */, +/* pos 0311: 430 */ 0xF2 /* 'r' -> */, +/* pos 0312: 431 */ 0xE5 /* 'e' -> */, +/* pos 0313: 432 */ 0xF2 /* 'r' -> */, +/* pos 0314: 433 */ 0xBA /* ':' -> */, +/* pos 0315: 434 */ 0x00, 0x1F /* - terminal marker 31 - */, +/* pos 0317: 435 */ 0xE8 /* 'h' -> */, +/* pos 0318: 436 */ 0xE1 /* 'a' -> */, +/* pos 0319: 437 */ 0xF2 /* 'r' -> */, +/* pos 031a: 438 */ 0xF3 /* 's' -> */, +/* pos 031b: 439 */ 0xE5 /* 'e' -> */, +/* pos 031c: 440 */ 0xF4 /* 't' -> */, +/* pos 031d: 441 */ 0xBA /* ':' -> */, +/* pos 031e: 442 */ 0x00, 0x28 /* - terminal marker 40 - */, +/* pos 0320: 443 */ 0xEC /* 'l' -> */, +/* pos 0321: 444 */ 0xEC /* 'l' -> */, +/* pos 0322: 445 */ 0xEF /* 'o' -> */, +/* pos 0323: 446 */ 0xF7 /* 'w' -> */, +/* pos 0324: 447 */ 0xAD /* '-' -> */, +/* pos 0325: 448 */ 0xEF /* 'o' -> */, +/* pos 0326: 449 */ 0xF2 /* 'r' -> */, +/* pos 0327: 450 */ 0xE9 /* 'i' -> */, +/* pos 0328: 451 */ 0xE7 /* 'g' -> */, +/* pos 0329: 452 */ 0xE9 /* 'i' -> */, +/* pos 032a: 453 */ 0xEE /* 'n' -> */, +/* pos 032b: 454 */ 0xBA /* ':' -> */, +/* pos 032c: 455 */ 0x00, 0x2A /* - terminal marker 42 - */, +/* pos 032e: 456 */ 0xE1 /* 'a' -> */, +/* pos 032f: 457 */ 0xF8 /* 'x' -> */, +/* pos 0330: 458 */ 0xAD /* '-' -> */, +/* pos 0331: 459 */ 0xE6 /* 'f' -> */, +/* pos 0332: 460 */ 0xEF /* 'o' -> */, +/* pos 0333: 461 */ 0xF2 /* 'r' -> */, +/* pos 0334: 462 */ 0xF7 /* 'w' -> */, +/* pos 0335: 463 */ 0xE1 /* 'a' -> */, +/* pos 0336: 464 */ 0xF2 /* 'r' -> */, +/* pos 0337: 465 */ 0xE4 /* 'd' -> */, +/* pos 0338: 466 */ 0xF3 /* 's' -> */, +/* pos 0339: 467 */ 0xBA /* ':' -> */, +/* pos 033a: 468 */ 0x00, 0x3C /* - terminal marker 60 - */, +/* pos 033c: 469 */ 0xF8 /* 'x' -> */, +/* pos 033d: 470 */ 0xF9 /* 'y' -> */, +/* pos 033e: 471 */ 0x2D /* '-' */, 0x07, 0x00 /* (to 0x0345 state 472) */, + 0x20 /* ' ' */, 0x79, 0x00 /* (to 0x03BA state 567) */, + 0x08, /* fail */ +/* pos 0345: 472 */ 0xE1 /* 'a' -> */, +/* pos 0346: 473 */ 0xF5 /* 'u' -> */, +/* pos 0347: 474 */ 0xF4 /* 't' -> */, +/* pos 0348: 475 */ 0xE8 /* 'h' -> */, +/* pos 0349: 476 */ 0x65 /* 'e' */, 0x07, 0x00 /* (to 0x0350 state 477) */, + 0x6F /* 'o' */, 0x0E, 0x00 /* (to 0x035A state 486) */, + 0x08, /* fail */ +/* pos 0350: 477 */ 0xEE /* 'n' -> */, +/* pos 0351: 478 */ 0xF4 /* 't' -> */, +/* pos 0352: 479 */ 0xE9 /* 'i' -> */, +/* pos 0353: 480 */ 0xE3 /* 'c' -> */, +/* pos 0354: 481 */ 0xE1 /* 'a' -> */, +/* pos 0355: 482 */ 0xF4 /* 't' -> */, +/* pos 0356: 483 */ 0xE5 /* 'e' -> */, +/* pos 0357: 484 */ 0xBA /* ':' -> */, +/* pos 0358: 485 */ 0x00, 0x3D /* - terminal marker 61 - */, +/* pos 035a: 486 */ 0xF2 /* 'r' -> */, +/* pos 035b: 487 */ 0xE9 /* 'i' -> */, +/* pos 035c: 488 */ 0xFA /* 'z' -> */, +/* pos 035d: 489 */ 0xE1 /* 'a' -> */, +/* pos 035e: 490 */ 0xF4 /* 't' -> */, +/* pos 035f: 491 */ 0xE9 /* 'i' -> */, +/* pos 0360: 492 */ 0xEF /* 'o' -> */, +/* pos 0361: 493 */ 0xEE /* 'n' -> */, +/* pos 0362: 494 */ 0xBA /* ':' -> */, +/* pos 0363: 495 */ 0x00, 0x3E /* - terminal marker 62 - */, +/* pos 0365: 496 */ 0xF2 /* 'r' -> */, +/* pos 0366: 497 */ 0xE9 /* 'i' -> */, +/* pos 0367: 498 */ 0xE3 /* 'c' -> */, +/* pos 0368: 499 */ 0xF4 /* 't' -> */, +/* pos 0369: 500 */ 0xAD /* '-' -> */, +/* pos 036a: 501 */ 0xF4 /* 't' -> */, +/* pos 036b: 502 */ 0xF2 /* 'r' -> */, +/* pos 036c: 503 */ 0xE1 /* 'a' -> */, +/* pos 036d: 504 */ 0xEE /* 'n' -> */, +/* pos 036e: 505 */ 0xF3 /* 's' -> */, +/* pos 036f: 506 */ 0xF0 /* 'p' -> */, +/* pos 0370: 507 */ 0xEF /* 'o' -> */, +/* pos 0371: 508 */ 0xF2 /* 'r' -> */, +/* pos 0372: 509 */ 0xF4 /* 't' -> */, +/* pos 0373: 510 */ 0xAD /* '-' -> */, +/* pos 0374: 511 */ 0xF3 /* 's' -> */, +/* pos 0375: 512 */ 0xE5 /* 'e' -> */, +/* pos 0376: 513 */ 0xE3 /* 'c' -> */, +/* pos 0377: 514 */ 0xF5 /* 'u' -> */, +/* pos 0378: 515 */ 0xF2 /* 'r' -> */, +/* pos 0379: 516 */ 0xE9 /* 'i' -> */, +/* pos 037a: 517 */ 0xF4 /* 't' -> */, +/* pos 037b: 518 */ 0xF9 /* 'y' -> */, +/* pos 037c: 519 */ 0xBA /* ':' -> */, +/* pos 037d: 520 */ 0x00, 0x43 /* - terminal marker 67 - */, +/* pos 037f: 521 */ 0xE5 /* 'e' -> */, +/* pos 0380: 522 */ 0xF2 /* 'r' -> */, +/* pos 0381: 523 */ 0xAD /* '-' -> */, +/* pos 0382: 524 */ 0xE1 /* 'a' -> */, +/* pos 0383: 525 */ 0xE7 /* 'g' -> */, +/* pos 0384: 526 */ 0xE5 /* 'e' -> */, +/* pos 0385: 527 */ 0xEE /* 'n' -> */, +/* pos 0386: 528 */ 0xF4 /* 't' -> */, +/* pos 0387: 529 */ 0xBA /* ':' -> */, +/* pos 0388: 530 */ 0x00, 0x45 /* - terminal marker 69 - */, +/* pos 038a: 531 */ 0x61 /* 'a' */, 0x07, 0x00 /* (to 0x0391 state 532) */, + 0x69 /* 'i' */, 0x09, 0x00 /* (to 0x0396 state 536) */, + 0x08, /* fail */ +/* pos 0391: 532 */ 0xF2 /* 'r' -> */, +/* pos 0392: 533 */ 0xF9 /* 'y' -> */, +/* pos 0393: 534 */ 0xBA /* ':' -> */, +/* pos 0394: 535 */ 0x00, 0x46 /* - terminal marker 70 - */, +/* pos 0396: 536 */ 0xE1 /* 'a' -> */, +/* pos 0397: 537 */ 0xBA /* ':' -> */, +/* pos 0398: 538 */ 0x00, 0x47 /* - terminal marker 71 - */, +/* pos 039a: 539 */ 0xF7 /* 'w' -> */, +/* pos 039b: 540 */ 0xF7 /* 'w' -> */, +/* pos 039c: 541 */ 0xAD /* '-' -> */, +/* pos 039d: 542 */ 0xE1 /* 'a' -> */, +/* pos 039e: 543 */ 0xF5 /* 'u' -> */, +/* pos 039f: 544 */ 0xF4 /* 't' -> */, +/* pos 03a0: 545 */ 0xE8 /* 'h' -> */, +/* pos 03a1: 546 */ 0xE5 /* 'e' -> */, +/* pos 03a2: 547 */ 0xEE /* 'n' -> */, +/* pos 03a3: 548 */ 0xF4 /* 't' -> */, +/* pos 03a4: 549 */ 0xE9 /* 'i' -> */, +/* pos 03a5: 550 */ 0xE3 /* 'c' -> */, +/* pos 03a6: 551 */ 0xE1 /* 'a' -> */, +/* pos 03a7: 552 */ 0xF4 /* 't' -> */, +/* pos 03a8: 553 */ 0xE5 /* 'e' -> */, +/* pos 03a9: 554 */ 0xBA /* ':' -> */, +/* pos 03aa: 555 */ 0x00, 0x48 /* - terminal marker 72 - */, +/* pos 03ac: 556 */ 0xF4 /* 't' -> */, +/* pos 03ad: 557 */ 0xE3 /* 'c' -> */, +/* pos 03ae: 558 */ 0xE8 /* 'h' -> */, +/* pos 03af: 559 */ 0x00, 0x49 /* - terminal marker 73 - */, +/* pos 03b1: 560 */ 0xF4 /* 't' -> */, +/* pos 03b2: 561 */ 0x00, 0x4A /* - terminal marker 74 - */, +/* pos 03b4: 562 */ 0xEC /* 'l' -> */, +/* pos 03b5: 563 */ 0xE5 /* 'e' -> */, +/* pos 03b6: 564 */ 0xF4 /* 't' -> */, +/* pos 03b7: 565 */ 0xE5 /* 'e' -> */, +/* pos 03b8: 566 */ 0x00, 0x4B /* - terminal marker 75 - */, +/* pos 03ba: 567 */ 0x00, 0x4D /* - terminal marker 77 - */, +/* pos 03bc: 568 */ 0xE5 /* 'e' -> */, +/* pos 03bd: 569 */ 0xE1 /* 'a' -> */, +/* pos 03be: 570 */ 0xEC /* 'l' -> */, +/* pos 03bf: 571 */ 0xAD /* '-' -> */, +/* pos 03c0: 572 */ 0xE9 /* 'i' -> */, +/* pos 03c1: 573 */ 0xF0 /* 'p' -> */, +/* pos 03c2: 574 */ 0xBA /* ':' -> */, +/* pos 03c3: 575 */ 0x00, 0x4E /* - terminal marker 78 - */, +/* pos 03c5: 576 */ 0xBA /* ':' -> */, +/* pos 03c6: 577 */ 0x00, 0x53 /* - terminal marker 83 - */, +/* pos 03c8: 578 */ 0xEC /* 'l' -> */, +/* pos 03c9: 579 */ 0xE1 /* 'a' -> */, +/* pos 03ca: 580 */ 0xF9 /* 'y' -> */, +/* pos 03cb: 581 */ 0xAD /* '-' -> */, +/* pos 03cc: 582 */ 0xEE /* 'n' -> */, +/* pos 03cd: 583 */ 0xEF /* 'o' -> */, +/* pos 03ce: 584 */ 0xEE /* 'n' -> */, +/* pos 03cf: 585 */ 0xE3 /* 'c' -> */, +/* pos 03d0: 586 */ 0xE5 /* 'e' -> */, +/* pos 03d1: 587 */ 0xBA /* ':' -> */, +/* pos 03d2: 588 */ 0x00, 0x54 /* - terminal marker 84 - */, +/* pos 03d4: 589 */ 0xAD /* '-' -> */, +/* pos 03d5: 590 */ 0xF7 /* 'w' -> */, +/* pos 03d6: 591 */ 0xE5 /* 'e' -> */, +/* pos 03d7: 592 */ 0xE2 /* 'b' -> */, +/* pos 03d8: 593 */ 0xF3 /* 's' -> */, +/* pos 03d9: 594 */ 0xEF /* 'o' -> */, +/* pos 03da: 595 */ 0xE3 /* 'c' -> */, +/* pos 03db: 596 */ 0xEB /* 'k' -> */, +/* pos 03dc: 597 */ 0xE5 /* 'e' -> */, +/* pos 03dd: 598 */ 0xF4 /* 't' -> */, +/* pos 03de: 599 */ 0xAD /* '-' -> */, +/* pos 03df: 600 */ 0x64 /* 'd' */, 0x19, 0x00 /* (to 0x03F8 state 601) */, + 0x65 /* 'e' */, 0x1D, 0x00 /* (to 0x03FF state 607) */, + 0x6B /* 'k' */, 0x26, 0x00 /* (to 0x040B state 618) */, + 0x70 /* 'p' */, 0x35, 0x00 /* (to 0x041D state 625) */, + 0x61 /* 'a' */, 0x3C, 0x00 /* (to 0x0427 state 634) */, + 0x6E /* 'n' */, 0x41, 0x00 /* (to 0x042F state 641) */, + 0x76 /* 'v' */, 0x47, 0x00 /* (to 0x0438 state 648) */, + 0x6F /* 'o' */, 0x4D, 0x00 /* (to 0x0441 state 656) */, + 0x08, /* fail */ +/* pos 03f8: 601 */ 0xF2 /* 'r' -> */, +/* pos 03f9: 602 */ 0xE1 /* 'a' -> */, +/* pos 03fa: 603 */ 0xE6 /* 'f' -> */, +/* pos 03fb: 604 */ 0xF4 /* 't' -> */, +/* pos 03fc: 605 */ 0xBA /* ':' -> */, +/* pos 03fd: 606 */ 0x00, 0x07 /* - terminal marker 7 - */, +/* pos 03ff: 607 */ 0xF8 /* 'x' -> */, +/* pos 0400: 608 */ 0xF4 /* 't' -> */, +/* pos 0401: 609 */ 0xE5 /* 'e' -> */, +/* pos 0402: 610 */ 0xEE /* 'n' -> */, +/* pos 0403: 611 */ 0xF3 /* 's' -> */, +/* pos 0404: 612 */ 0xE9 /* 'i' -> */, +/* pos 0405: 613 */ 0xEF /* 'o' -> */, +/* pos 0406: 614 */ 0xEE /* 'n' -> */, +/* pos 0407: 615 */ 0xF3 /* 's' -> */, +/* pos 0408: 616 */ 0xBA /* ':' -> */, +/* pos 0409: 617 */ 0x00, 0x09 /* - terminal marker 9 - */, +/* pos 040b: 618 */ 0xE5 /* 'e' -> */, +/* pos 040c: 619 */ 0xF9 /* 'y' -> */, +/* pos 040d: 620 */ 0x31 /* '1' */, 0x0A, 0x00 /* (to 0x0417 state 621) */, + 0x32 /* '2' */, 0x0A, 0x00 /* (to 0x041A state 623) */, + 0x3A /* ':' */, 0x23, 0x00 /* (to 0x0436 state 647) */, + 0x08, /* fail */ +/* pos 0417: 621 */ 0xBA /* ':' -> */, +/* pos 0418: 622 */ 0x00, 0x0A /* - terminal marker 10 - */, +/* pos 041a: 623 */ 0xBA /* ':' -> */, +/* pos 041b: 624 */ 0x00, 0x0B /* - terminal marker 11 - */, +/* pos 041d: 625 */ 0xF2 /* 'r' -> */, +/* pos 041e: 626 */ 0xEF /* 'o' -> */, +/* pos 041f: 627 */ 0xF4 /* 't' -> */, +/* pos 0420: 628 */ 0xEF /* 'o' -> */, +/* pos 0421: 629 */ 0xE3 /* 'c' -> */, +/* pos 0422: 630 */ 0xEF /* 'o' -> */, +/* pos 0423: 631 */ 0xEC /* 'l' -> */, +/* pos 0424: 632 */ 0xBA /* ':' -> */, +/* pos 0425: 633 */ 0x00, 0x0C /* - terminal marker 12 - */, +/* pos 0427: 634 */ 0xE3 /* 'c' -> */, +/* pos 0428: 635 */ 0xE3 /* 'c' -> */, +/* pos 0429: 636 */ 0xE5 /* 'e' -> */, +/* pos 042a: 637 */ 0xF0 /* 'p' -> */, +/* pos 042b: 638 */ 0xF4 /* 't' -> */, +/* pos 042c: 639 */ 0xBA /* ':' -> */, +/* pos 042d: 640 */ 0x00, 0x0D /* - terminal marker 13 - */, +/* pos 042f: 641 */ 0xEF /* 'o' -> */, +/* pos 0430: 642 */ 0xEE /* 'n' -> */, +/* pos 0431: 643 */ 0xE3 /* 'c' -> */, +/* pos 0432: 644 */ 0xE5 /* 'e' -> */, +/* pos 0433: 645 */ 0xBA /* ':' -> */, +/* pos 0434: 646 */ 0x00, 0x0E /* - terminal marker 14 - */, +/* pos 0436: 647 */ 0x00, 0x20 /* - terminal marker 32 - */, +/* pos 0438: 648 */ 0xE5 /* 'e' -> */, +/* pos 0439: 649 */ 0xF2 /* 'r' -> */, +/* pos 043a: 650 */ 0xF3 /* 's' -> */, +/* pos 043b: 651 */ 0xE9 /* 'i' -> */, +/* pos 043c: 652 */ 0xEF /* 'o' -> */, +/* pos 043d: 653 */ 0xEE /* 'n' -> */, +/* pos 043e: 654 */ 0xBA /* ':' -> */, +/* pos 043f: 655 */ 0x00, 0x21 /* - terminal marker 33 - */, +/* pos 0441: 656 */ 0xF2 /* 'r' -> */, +/* pos 0442: 657 */ 0xE9 /* 'i' -> */, +/* pos 0443: 658 */ 0xE7 /* 'g' -> */, +/* pos 0444: 659 */ 0xE9 /* 'i' -> */, +/* pos 0445: 660 */ 0xEE /* 'n' -> */, +/* pos 0446: 661 */ 0xBA /* ':' -> */, +/* pos 0447: 662 */ 0x00, 0x22 /* - terminal marker 34 - */, +/* pos 0449: 663 */ 0xAD /* '-' -> */, +/* pos 044a: 664 */ 0xF3 /* 's' -> */, +/* pos 044b: 665 */ 0xE5 /* 'e' -> */, +/* pos 044c: 666 */ 0xF4 /* 't' -> */, +/* pos 044d: 667 */ 0xF4 /* 't' -> */, +/* pos 044e: 668 */ 0xE9 /* 'i' -> */, +/* pos 044f: 669 */ 0xEE /* 'n' -> */, +/* pos 0450: 670 */ 0xE7 /* 'g' -> */, +/* pos 0451: 671 */ 0xF3 /* 's' -> */, +/* pos 0452: 672 */ 0xBA /* ':' -> */, +/* pos 0453: 673 */ 0x00, 0x10 /* - terminal marker 16 - */, +/* pos 0455: 674 */ 0x61 /* 'a' */, 0x0D, 0x00 /* (to 0x0462 state 675) */, + 0x6D /* 'm' */, 0x14, 0x00 /* (to 0x046C state 684) */, + 0x70 /* 'p' */, 0x18, 0x00 /* (to 0x0473 state 690) */, + 0x73 /* 's' */, 0x20, 0x00 /* (to 0x047E state 694) */, + 0x08, /* fail */ +/* pos 0462: 675 */ 0xF5 /* 'u' -> */, +/* pos 0463: 676 */ 0xF4 /* 't' -> */, +/* pos 0464: 677 */ 0xE8 /* 'h' -> */, +/* pos 0465: 678 */ 0xEF /* 'o' -> */, +/* pos 0466: 679 */ 0xF2 /* 'r' -> */, +/* pos 0467: 680 */ 0xE9 /* 'i' -> */, +/* pos 0468: 681 */ 0xF4 /* 't' -> */, +/* pos 0469: 682 */ 0xF9 /* 'y' -> */, +/* pos 046a: 683 */ 0x00, 0x23 /* - terminal marker 35 - */, +/* pos 046c: 684 */ 0xE5 /* 'e' -> */, +/* pos 046d: 685 */ 0xF4 /* 't' -> */, +/* pos 046e: 686 */ 0xE8 /* 'h' -> */, +/* pos 046f: 687 */ 0xEF /* 'o' -> */, +/* pos 0470: 688 */ 0xE4 /* 'd' -> */, +/* pos 0471: 689 */ 0x00, 0x24 /* - terminal marker 36 - */, +/* pos 0473: 690 */ 0x61 /* 'a' */, 0x07, 0x00 /* (to 0x047A state 691) */, + 0x72 /* 'r' */, 0x1B, 0x00 /* (to 0x0491 state 705) */, + 0x08, /* fail */ +/* pos 047a: 691 */ 0xF4 /* 't' -> */, +/* pos 047b: 692 */ 0xE8 /* 'h' -> */, +/* pos 047c: 693 */ 0x00, 0x25 /* - terminal marker 37 - */, +/* pos 047e: 694 */ 0x63 /* 'c' */, 0x07, 0x00 /* (to 0x0485 state 695) */, + 0x74 /* 't' */, 0x0A, 0x00 /* (to 0x048B state 700) */, + 0x08, /* fail */ +/* pos 0485: 695 */ 0xE8 /* 'h' -> */, +/* pos 0486: 696 */ 0xE5 /* 'e' -> */, +/* pos 0487: 697 */ 0xED /* 'm' -> */, +/* pos 0488: 698 */ 0xE5 /* 'e' -> */, +/* pos 0489: 699 */ 0x00, 0x26 /* - terminal marker 38 - */, +/* pos 048b: 700 */ 0xE1 /* 'a' -> */, +/* pos 048c: 701 */ 0xF4 /* 't' -> */, +/* pos 048d: 702 */ 0xF5 /* 'u' -> */, +/* pos 048e: 703 */ 0xF3 /* 's' -> */, +/* pos 048f: 704 */ 0x00, 0x27 /* - terminal marker 39 - */, /* pos 0491: 705 */ 0xEF /* 'o' -> */, -/* pos 0492: 706 */ 0xEB /* 'k' -> */, -/* pos 0493: 707 */ 0xE5 /* 'e' -> */, -/* pos 0494: 708 */ 0xEE /* 'n' -> */, -/* pos 0495: 709 */ 0xBA /* ':' -> */, -/* pos 0496: 710 */ 0x00, 0x56 /* - terminal marker 86 - */, -/* total size 1176 bytes */ +/* pos 0492: 706 */ 0xF4 /* 't' -> */, +/* pos 0493: 707 */ 0xEF /* 'o' -> */, +/* pos 0494: 708 */ 0xE3 /* 'c' -> */, +/* pos 0495: 709 */ 0xEF /* 'o' -> */, +/* pos 0496: 710 */ 0xEC /* 'l' -> */, +/* pos 0497: 711 */ 0x00, 0x55 /* - terminal marker 85 - */, +/* total size 1177 bytes */ +#endif + + +/* +#if !defined(LWS_HTTP_HEADERS_ALL) && !defined(LWS_WITH_HTTP_UNCOMMON_HEADERS) && !defined(LWS_ROLE_WS) && !defined(LWS_ROLE_H2) +static uint8_t lws_header_implies_psuedoheader_map[] = { + 0x03,0x00,0x00,0x00,0x00,0x00,0x01,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, +}; +#endif +#if !defined(LWS_HTTP_HEADERS_ALL) && defined(LWS_WITH_HTTP_UNCOMMON_HEADERS) && !defined(LWS_ROLE_WS) && !defined(LWS_ROLE_H2) +static uint8_t lws_header_implies_psuedoheader_map[] = { + 0x07,0x00,0x00,0x00,0x00,0x00,0x00,0x0e,0x04,0x00,0x00,0x00,0x00,0x00,0x00,0x00, +}; +#endif +#if !defined(LWS_HTTP_HEADERS_ALL) && !defined(LWS_WITH_HTTP_UNCOMMON_HEADERS) && defined(LWS_ROLE_WS) && !defined(LWS_ROLE_H2) +static uint8_t lws_header_implies_psuedoheader_map[] = { + 0x03,0x00,0x00,0x00,0x00,0x00,0x00,0x04,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, +}; +#endif +#if !defined(LWS_HTTP_HEADERS_ALL) && defined(LWS_WITH_HTTP_UNCOMMON_HEADERS) && defined(LWS_ROLE_WS) && !defined(LWS_ROLE_H2) +static uint8_t lws_header_implies_psuedoheader_map[] = { + 0x07,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x38,0x10,0x00,0x00,0x00,0x00,0x00,0x00, +}; +#endif +#if !defined(LWS_HTTP_HEADERS_ALL) && !defined(LWS_WITH_HTTP_UNCOMMON_HEADERS) && !defined(LWS_ROLE_WS) && defined(LWS_ROLE_H2) +static uint8_t lws_header_implies_psuedoheader_map[] = { + 0x03,0x00,0x80,0x0f,0x00,0x00,0x00,0x00,0x02,0x00,0x00,0x00,0x00,0x00,0x00,0x00, +}; +#endif +#if !defined(LWS_HTTP_HEADERS_ALL) && defined(LWS_WITH_HTTP_UNCOMMON_HEADERS) && !defined(LWS_ROLE_WS) && defined(LWS_ROLE_H2) +static uint8_t lws_header_implies_psuedoheader_map[] = { + 0x07,0x00,0x00,0x3e,0x00,0x00,0x00,0x80,0x03,0x01,0x00,0x00,0x00,0x00,0x00,0x00, +}; +#endif +#if !defined(LWS_HTTP_HEADERS_ALL) && !defined(LWS_WITH_HTTP_UNCOMMON_HEADERS) && defined(LWS_ROLE_WS) && defined(LWS_ROLE_H2) +static uint8_t lws_header_implies_psuedoheader_map[] = { + 0x03,0x00,0x00,0x00,0x3e,0x00,0x00,0x00,0x00,0x08,0x00,0x00,0x00,0x00,0x00,0x00, +}; +#endif +#if defined(LWS_HTTP_HEADERS_ALL) || (defined(LWS_WITH_HTTP_UNCOMMON_HEADERS) && defined(LWS_ROLE_WS) && defined(LWS_ROLE_H2)) +static uint8_t lws_header_implies_psuedoheader_map[] = { + 0x07,0x00,0x00,0x00,0xf8,0x00,0x00,0x00,0x00,0x0e,0x04,0x00,0x00,0x00,0x00,0x00, +}; +#endif +*/ diff -Nru libwebsockets-3.2.1/lib/roles/http/lextable-strings.h libwebsockets-4.1.6/lib/roles/http/lextable-strings.h --- libwebsockets-3.2.1/lib/roles/http/lextable-strings.h 2019-12-18 14:45:31.000000000 +0000 +++ libwebsockets-4.1.6/lib/roles/http/lextable-strings.h 2020-12-01 17:40:26.000000000 +0000 @@ -3,14 +3,19 @@ static const char * const set[] = { "get ", "post ", +#if defined(LWS_WITH_HTTP_UNCOMMON_HEADERS) || defined(LWS_HTTP_HEADERS_ALL) "options ", +#endif "host:", "connection:", "upgrade:", "origin:", +#if defined(LWS_ROLE_WS) || defined(LWS_HTTP_HEADERS_ALL) "sec-websocket-draft:", +#endif "\x0d\x0a", +#if defined(LWS_ROLE_WS) || defined(LWS_HTTP_HEADERS_ALL) "sec-websocket-extensions:", "sec-websocket-key1:", "sec-websocket-key2:", @@ -18,11 +23,16 @@ "sec-websocket-accept:", "sec-websocket-nonce:", +#endif "http/1.1 ", +#if defined(LWS_ROLE_H2) || defined(LWS_HTTP_HEADERS_ALL) "http2-settings:", +#endif "accept:", +#if defined(LWS_WITH_HTTP_UNCOMMON_HEADERS) || defined(LWS_HTTP_HEADERS_ALL) "access-control-request-headers:", +#endif "if-modified-since:", "if-none-match:", "accept-encoding:", @@ -35,20 +45,28 @@ "content-type:", "date:", "range:", +#if defined(LWS_WITH_HTTP_UNCOMMON_HEADERS) || defined(LWS_ROLE_H2) || defined(LWS_HTTP_HEADERS_ALL) "referer:", +#endif +#if defined(LWS_ROLE_WS) || defined(LWS_HTTP_HEADERS_ALL) "sec-websocket-key:", "sec-websocket-version:", "sec-websocket-origin:", - +#endif +#if defined(LWS_ROLE_H2) || defined(LWS_HTTP_HEADERS_ALL) ":authority", ":method", ":path", ":scheme", ":status", - +#endif +#if defined(LWS_WITH_HTTP_UNCOMMON_HEADERS) || defined(LWS_ROLE_H2) || defined(LWS_HTTP_HEADERS_ALL) "accept-charset:", +#endif "accept-ranges:", +#if defined(LWS_WITH_HTTP_UNCOMMON_HEADERS) || defined(LWS_ROLE_H2) || defined(LWS_HTTP_HEADERS_ALL) "access-control-allow-origin:", +#endif "age:", "allow:", "content-disposition:", @@ -66,36 +84,49 @@ "last-modified:", "link:", "location:", +#if defined(LWS_WITH_HTTP_UNCOMMON_HEADERS) || defined(LWS_ROLE_H2) || defined(LWS_HTTP_HEADERS_ALL) "max-forwards:", "proxy-authenticate:", "proxy-authorization:", +#endif "refresh:", "retry-after:", "server:", "set-cookie:", +#if defined(LWS_WITH_HTTP_UNCOMMON_HEADERS) || defined(LWS_ROLE_H2) || defined(LWS_HTTP_HEADERS_ALL) "strict-transport-security:", +#endif "transfer-encoding:", +#if defined(LWS_WITH_HTTP_UNCOMMON_HEADERS) || defined(LWS_ROLE_H2) || defined(LWS_HTTP_HEADERS_ALL) "user-agent:", "vary:", "via:", "www-authenticate:", - +#endif +#if defined(LWS_WITH_HTTP_UNCOMMON_HEADERS) || defined(LWS_HTTP_HEADERS_ALL) "patch", "put", "delete", +#endif "uri-args", /* fake header used for uri-only storage */ +#if defined(LWS_WITH_HTTP_UNCOMMON_HEADERS) || defined(LWS_HTTP_HEADERS_ALL) "proxy ", "x-real-ip:", +#endif "http/1.0 ", - "x-forwarded-for", + "x-forwarded-for:", "connect ", "head ", +#if defined(LWS_WITH_HTTP_UNCOMMON_HEADERS) || defined(LWS_ROLE_H2) || defined(LWS_HTTP_HEADERS_ALL) "te:", /* http/2 wants it to reject it */ "replay-nonce:", /* ACME */ +#endif +#if defined(LWS_ROLE_H2) || defined(LWS_HTTP_HEADERS_ALL) ":protocol", /* defined in mcmanus-httpbis-h2-ws-02 */ +#endif "x-auth-token:", diff -Nru libwebsockets-3.2.1/lib/roles/http/minilex.c libwebsockets-4.1.6/lib/roles/http/minilex.c --- libwebsockets-3.2.1/lib/roles/http/minilex.c 2019-12-18 14:45:31.000000000 +0000 +++ libwebsockets-4.1.6/lib/roles/http/minilex.c 2020-12-01 17:40:26.000000000 +0000 @@ -3,21 +3,144 @@ * * High efficiency lexical state parser * - * Copyright (C)2011-2014 Andy Green + * Copyright (C)2011-2020 Andy Green * - * Licensed under LGPL2 + * Licensed under MIT * * Usage: gcc minilex.c -o minilex && ./minilex > lextable.h * * Run it twice to test parsing on the generated table on stderr + * + * Whoo this got a bit complicated by lws-buildtime deselection of some + * headers optionally. There are 3 x vars, UNCOMMON, WS, H2 so we make + * eight copies of the lextable selected by the appropriate #if defined() */ #include #include #include +/* get all the strings */ + +#define LWS_ROLE_WS 1 +#define LWS_WITH_HTTP_UNCOMMON_HEADERS 1 +#define LWS_ROLE_H2 1 + #include "lextable-strings.h" +#undef LWS_ROLE_WS +#undef LWS_WITH_HTTP_UNCOMMON_HEADERS +#undef LWS_ROLE_H2 + +/* bitfield for the 8 versions as to which strings exist... index layout + * + * b0 b1 b2 + * 0 = + * 1 = uncommon + * 2 = ws + * 3 = uncommon ws + * 4 = h2 + * 5 = uncommon h2 + * 6 = ws h2 + * 7 = uncommon ws h2 + */ + +unsigned char filter_array[] = { + 0xff, /* get */ + 0xff, /* post */ + 0xaa, /* options */ + 0xff, /* host */ + 0xff, /* connection */ + 0xff, /* upgrade */ + 0xff, /* origin */ + 0xcc, /* sec-ws-draft */ + 0xff, /* crlf */ + 0xcc, /* sec-ws-ext */ + 0xcc, /* sec-ws-key1 */ + 0xcc, /* sec-ws-key2 */ + 0xcc, /* sec-ws-protocol */ + 0xcc, /* sec-ws-accept */ + 0xcc, /* sec-ws-nonce */ + 0xff, /* http/1.1 */ + 0xf0, /* http2-settings */ + 0xff, /* accept */ + 0xaa, /* access-control-req-hdrs */ + 0xff, /* if-modified-since */ + 0xff, /* if-none-match */ + 0xff, /* accept-encoding */ + 0xff, /* accept-language */ + 0xff, /* pragma */ + 0xff, /* cache-control */ + 0xff, /* authorization */ + 0xff, /* cookie */ + 0xff, /* content-length */ + 0xff, /* content-type */ + 0xff, /* date */ + 0xff, /* range */ + 0xfa, /* referer */ + 0xcc, /* sec-ws-key */ + 0xcc, /* sec-ws-version */ + 0xcc, /* sec-sc-origin */ + 0xf0, /* authority */ + 0xf0, /* method */ + 0xf0, /* path */ + 0xf0, /* scheme */ + 0xf0, /* status */ + 0xfa, /* accept-charset */ + 0xff, /* accept-ranges */ + 0xfa, /* access-control-allow-origin */ + 0xff, /* age */ + 0xff, /* allow */ + 0xff, /* content-disposition */ + 0xff, /* content-encoding */ + 0xff, /* content-language */ + 0xff, /* content-location */ + 0xff, /* content-range */ + 0xff, /* etag */ + 0xff, /* expect */ + 0xff, /* expires */ + 0xff, /* from */ + 0xff, /* if-match */ + 0xff, /* if-range */ + 0xff, /* if-unmodified-since */ + 0xff, /* last-modified */ + 0xff, /* link */ + 0xff, /* location */ + 0xfa, /* max-forwards */ + 0xfa, /* proxy-authenticate */ + 0xfa, /* proxy-authorization */ + 0xff, /* refresh */ + 0xff, /* retry-after */ + 0xff, /* server */ + 0xff, /* set-cookie */ + 0xfa, /* strict-transport-security */ + 0xff, /* transfer-encoding */ + 0xfa, /* user-agent */ + 0xfa, /* vary */ + 0xfa, /* via */ + 0xfa, /* www-authenticate */ + 0xaa, /* patch */ + 0xaa, /* put */ + 0xaa, /* delete */ + 0xff, /* uri-args */ + 0xaa, /* proxy */ + 0xaa, /* x-real-ip */ + 0xff, /* http/1.0 */ + 0xff, /* x-forwarded-for */ + 0xff, /* connect */ + 0xff, /* head */ + 0xfa, /* te */ + 0xfa, /* replay-nonce */ + 0xf0, /* protocol */ + 0xff, /* x-auth-token */ + 0xff /* not matchable */ +}; + +static unsigned char lws_header_implies_psuedoheader_map[] = { + 0x07, 0x00, 0x00, 0x00, 0xf8, 0x00, 0x00, 0x00, 0x00 /* <-64 */, + 0x0e /* <- 72 */, 0x24 /* <- 80 */, 0, 0, 0, 0 +}; + /* * b7 = 0 = 1-byte seq * 0x08 = fail @@ -29,8 +152,42 @@ * no match: die, match go fwd 1 byte */ -unsigned char lextable[] = { - #include "lextable.h" +unsigned char lextable[][2000] = { + { + #include "lextable.h" + }, +#define LWS_WITH_HTTP_UNCOMMON_HEADERS + { + #include "lextable.h" + }, +#undef LWS_WITH_HTTP_UNCOMMON_HEADERS +#define LWS_ROLE_WS 1 + { + #include "lextable.h" + }, +#define LWS_WITH_HTTP_UNCOMMON_HEADERS + { + #include "lextable.h" + }, +#undef LWS_ROLE_WS +#undef LWS_WITH_HTTP_UNCOMMON_HEADERS +#define LWS_ROLE_H2 1 + { + #include "lextable.h" + }, +#define LWS_WITH_HTTP_UNCOMMON_HEADERS + { + #include "lextable.h" + }, +#undef LWS_WITH_HTTP_UNCOMMON_HEADERS +#define LWS_ROLE_WS 1 + { + #include "lextable.h" + }, +#define LWS_WITH_HTTP_UNCOMMON_HEADERS 1 + { + #include "lextable.h" + }, }; #define PARALLEL 30 @@ -44,29 +201,31 @@ int real_pos; }; +static unsigned char pseudomap[8][16]; + struct state state[1000]; int next = 1; #define FAIL_CHAR 0x08 -int lextable_decode(int pos, char c) +int lextable_decode(int version, int pos, char c) { while (1) { - if (lextable[pos] & (1 << 7)) { /* 1-byte, fail on mismatch */ - if ((lextable[pos] & 0x7f) != c) + if (lextable[version][pos] & (1 << 7)) { /* 1-byte, fail on mismatch */ + if ((lextable[version][pos] & 0x7f) != c) return -1; /* fall thru */ pos++; - if (lextable[pos] == FAIL_CHAR) + if (lextable[version][pos] == FAIL_CHAR) return -1; return pos; } else { /* b7 = 0, end or 3-byte */ - if (lextable[pos] < FAIL_CHAR) /* terminal marker */ + if (lextable[version][pos] < FAIL_CHAR) /* terminal marker */ return pos; - if (lextable[pos] == c) /* goto */ - return pos + (lextable[pos + 1]) + - (lextable[pos + 2] << 8); + if (lextable[version][pos] == c) /* goto */ + return pos + (lextable[version][pos + 1]) + + (lextable[version][pos + 2] << 8); /* fall thru goto */ pos += 3; /* continue */ @@ -74,34 +233,62 @@ } } -int main(void) +int issue(int version) { + const char *rset[200]; int n = 0; - int m = 0; + int m; int prev; - char c; int walk; int saw; int y; int j; int pos = 0; - while (n < sizeof(set) / sizeof(set[0])) { + int setmembers = 0; + + memset(rset, 0, sizeof(rset)); + + if (version == 7) + printf("#if defined(LWS_HTTP_HEADERS_ALL) || (%cdefined(LWS_WITH_HTTP_UNCOMMON_HEADERS) && " + "%cdefined(LWS_ROLE_WS) && " + "%cdefined(LWS_ROLE_H2))\n", version & 1 ? ' ' : '!', + version & 2 ? ' ' : '!', version & 4 ? ' ' : '!'); + else + printf("#if !defined(LWS_HTTP_HEADERS_ALL) && %cdefined(LWS_WITH_HTTP_UNCOMMON_HEADERS) && " + "%cdefined(LWS_ROLE_WS) && " + "%cdefined(LWS_ROLE_H2)\n", version & 1 ? ' ' : '!', + version & 2 ? ' ' : '!', version & 4 ? ' ' : '!'); + + /* + * let's create version's view of the set of strings + */ + + for (n = 0; n < sizeof(set) / sizeof(set[0]); n++) + if (filter_array[n] & (1 << version)) { + printf("\t/* %d: %d: %s */\n", setmembers, n, set[n]); + if (lws_header_implies_psuedoheader_map[n >> 3] & (1 << (n & 7))) + pseudomap[version][(setmembers >> 3)] |= 1 << (setmembers & 7); + rset[setmembers++] = set[n]; + } + + n = 0; + while (n < setmembers) { m = 0; walk = 0; prev = 0; - if (set[n][0] == '\0') { + if (rset[n][0] == '\0') { n++; continue; } - while (set[n][m]) { + while (rset[n][m]) { saw = 0; for (y = 0; y < state[walk].count; y++) - if (state[walk].c[y] == set[n][m]) { + if (state[walk].c[y] == rset[n][m]) { /* exists -- go forward */ walk = state[walk].state[y]; saw = 1; @@ -113,7 +300,7 @@ /* something we didn't see before */ - state[walk].c[state[walk].count] = set[n][m]; + state[walk].c[state[walk].count] = rset[n][m]; state[walk].state[state[walk].count] = next; state[walk].count++; @@ -232,29 +419,32 @@ fprintf(stdout, "/* total size %d bytes */\n", pos); + printf("#endif\n\n"); + /* * Try to parse every legal input string */ - for (n = 0; n < sizeof(set) / sizeof(set[0]); n++) { + for (n = 0; n < setmembers; n++) { walk = 0; m = 0; y = -1; - if (set[n][0] == '\0') + if (rset[n][0] == '\0') continue; - fprintf(stderr, " trying '%s'\n", set[n]); + fprintf(stderr, " trying %d '%s'\n", n, rset[n]); - while (set[n][m]) { - walk = lextable_decode(walk, set[n][m]); + while (rset[n][m]) { + walk = lextable_decode(version, walk, rset[n][m]); if (walk < 0) { fprintf(stderr, "failed\n"); return 3; } - if (lextable[walk] < FAIL_CHAR) { - y = (lextable[walk] << 8) + lextable[walk + 1]; + if (lextable[version][walk] < FAIL_CHAR) { + y = (lextable[version][walk] << 8) + + lextable[version][walk + 1]; break; } m++; @@ -270,3 +460,41 @@ return 0; } + +int main(void) +{ + int m, n; + + for (n = 0; n < 8; n++) { + issue(n); + } + + printf("\n/*\n"); + + for (n = 0; n < 8; n++) { + + if (n == 7) + printf("#if defined(LWS_HTTP_HEADERS_ALL) || (%cdefined(LWS_WITH_HTTP_UNCOMMON_HEADERS) && " + "%cdefined(LWS_ROLE_WS) && " + "%cdefined(LWS_ROLE_H2))\n", n & 1 ? ' ' : '!', + n & 2 ? ' ' : '!', n & 4 ? ' ' : '!'); + else + printf("#if !defined(LWS_HTTP_HEADERS_ALL) && %cdefined(LWS_WITH_HTTP_UNCOMMON_HEADERS) && " + "%cdefined(LWS_ROLE_WS) && " + "%cdefined(LWS_ROLE_H2)\n", n & 1 ? ' ' : '!', + n & 2 ? ' ' : '!', n & 4 ? ' ' : '!'); + + printf("static uint8_t lws_header_implies_psuedoheader_map[] = {\n\t"); + + for (m = 0; m < sizeof(pseudomap[n]); m++) + printf("0x%02x,", pseudomap[n][m]); + + printf("\n};\n"); + + printf("#endif\n"); + } + + printf("*/\n"); + + fprintf(stderr, "did all the variants\n"); +} diff -Nru libwebsockets-3.2.1/lib/roles/http/parsers.c libwebsockets-4.1.6/lib/roles/http/parsers.c --- libwebsockets-3.2.1/lib/roles/http/parsers.c 1970-01-01 00:00:00.000000000 +0000 +++ libwebsockets-4.1.6/lib/roles/http/parsers.c 2020-12-01 17:40:26.000000000 +0000 @@ -0,0 +1,1616 @@ +/* + * libwebsockets - small server side websockets and web server implementation + * + * Copyright (C) 2010 - 2019 Andy Green + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to + * deal in the Software without restriction, including without limitation the + * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or + * sell copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS + * IN THE SOFTWARE. + */ + +#include "private-lib-core.h" + +static const unsigned char lextable_h1[] = { + #include "lextable.h" +}; + +#define FAIL_CHAR 0x08 + +#if defined(LWS_WITH_CUSTOM_HEADERS) + +#define UHO_NLEN 0 +#define UHO_VLEN 2 +#define UHO_LL 4 +#define UHO_NAME 8 + +#endif + +static struct allocated_headers * +_lws_create_ah(struct lws_context_per_thread *pt, ah_data_idx_t data_size) +{ + struct allocated_headers *ah = lws_zalloc(sizeof(*ah), "ah struct"); + + if (!ah) + return NULL; + + ah->data = lws_malloc(data_size, "ah data"); + if (!ah->data) { + lws_free(ah); + + return NULL; + } + ah->next = pt->http.ah_list; + pt->http.ah_list = ah; + ah->data_length = data_size; + pt->http.ah_pool_length++; + + lwsl_info("%s: created ah %p (size %d): pool length %u\n", __func__, + ah, (int)data_size, (unsigned int)pt->http.ah_pool_length); + + return ah; +} + +int +_lws_destroy_ah(struct lws_context_per_thread *pt, struct allocated_headers *ah) +{ + lws_start_foreach_llp(struct allocated_headers **, a, pt->http.ah_list) { + if ((*a) == ah) { + *a = ah->next; + pt->http.ah_pool_length--; + lwsl_info("%s: freed ah %p : pool length %u\n", + __func__, ah, + (unsigned int)pt->http.ah_pool_length); + if (ah->data) + lws_free(ah->data); + lws_free(ah); + + return 0; + } + } lws_end_foreach_llp(a, next); + + return 1; +} + +void +_lws_header_table_reset(struct allocated_headers *ah) +{ + /* init the ah to reflect no headers or data have appeared yet */ + memset(ah->frag_index, 0, sizeof(ah->frag_index)); + memset(ah->frags, 0, sizeof(ah->frags)); + ah->nfrag = 0; + ah->pos = 0; + ah->http_response = 0; + ah->parser_state = WSI_TOKEN_NAME_PART; + ah->lextable_pos = 0; + ah->unk_pos = 0; +#if defined(LWS_WITH_CUSTOM_HEADERS) + ah->unk_ll_head = 0; + ah->unk_ll_tail = 0; +#endif +} + +// doesn't scrub the ah rxbuffer by default, parent must do if needed + +void +__lws_header_table_reset(struct lws *wsi, int autoservice) +{ + struct allocated_headers *ah = wsi->http.ah; + struct lws_context_per_thread *pt; + struct lws_pollfd *pfd; + + /* if we have the idea we're resetting 'our' ah, must be bound to one */ + assert(ah); + /* ah also concurs with ownership */ + assert(ah->wsi == wsi); + + _lws_header_table_reset(ah); + + /* since we will restart the ah, our new headers are not completed */ + wsi->hdr_parsing_completed = 0; + + /* while we hold the ah, keep a timeout on the wsi */ + __lws_set_timeout(wsi, PENDING_TIMEOUT_HOLDING_AH, + wsi->a.vhost->timeout_secs_ah_idle); + + time(&ah->assigned); + + if (wsi->position_in_fds_table != LWS_NO_FDS_POS && + lws_buflist_next_segment_len(&wsi->buflist, NULL) && + autoservice) { + lwsl_debug("%s: service on readbuf ah\n", __func__); + + pt = &wsi->a.context->pt[(int)wsi->tsi]; + /* + * Unlike a normal connect, we have the headers already + * (or the first part of them anyway) + */ + pfd = &pt->fds[wsi->position_in_fds_table]; + pfd->revents |= LWS_POLLIN; + lwsl_err("%s: calling service\n", __func__); + lws_service_fd_tsi(wsi->a.context, pfd, wsi->tsi); + } +} + +void +lws_header_table_reset(struct lws *wsi, int autoservice) +{ + struct lws_context_per_thread *pt = &wsi->a.context->pt[(int)wsi->tsi]; + + lws_pt_lock(pt, __func__); + + __lws_header_table_reset(wsi, autoservice); + + lws_pt_unlock(pt); +} + +static void +_lws_header_ensure_we_are_on_waiting_list(struct lws *wsi) +{ + struct lws_context_per_thread *pt = &wsi->a.context->pt[(int)wsi->tsi]; + struct lws_pollargs pa; + struct lws **pwsi = &pt->http.ah_wait_list; + + while (*pwsi) { + if (*pwsi == wsi) + return; + pwsi = &(*pwsi)->http.ah_wait_list; + } + + lwsl_info("%s: wsi: %p\n", __func__, wsi); + wsi->http.ah_wait_list = pt->http.ah_wait_list; + pt->http.ah_wait_list = wsi; + pt->http.ah_wait_list_length++; + + /* we cannot accept input then */ + + _lws_change_pollfd(wsi, LWS_POLLIN, 0, &pa); +} + +static int +__lws_remove_from_ah_waiting_list(struct lws *wsi) +{ + struct lws_context_per_thread *pt = &wsi->a.context->pt[(int)wsi->tsi]; + struct lws **pwsi =&pt->http.ah_wait_list; + + while (*pwsi) { + if (*pwsi == wsi) { + lwsl_info("%s: wsi %p\n", __func__, wsi); + /* point prev guy to our next */ + *pwsi = wsi->http.ah_wait_list; + /* we shouldn't point anywhere now */ + wsi->http.ah_wait_list = NULL; + pt->http.ah_wait_list_length--; + + return 1; + } + pwsi = &(*pwsi)->http.ah_wait_list; + } + + return 0; +} + +int LWS_WARN_UNUSED_RESULT +lws_header_table_attach(struct lws *wsi, int autoservice) +{ + struct lws_context *context = wsi->a.context; + struct lws_context_per_thread *pt = &context->pt[(int)wsi->tsi]; + struct lws_pollargs pa; + int n; + +#if defined(LWS_ROLE_MQTT) && defined(LWS_WITH_CLIENT) + if (lwsi_role_mqtt(wsi)) + goto connect_via_info2; +#endif + + lwsl_info("%s: wsi %p: ah %p (tsi %d, count = %d) in\n", __func__, + (void *)wsi, (void *)wsi->http.ah, wsi->tsi, + pt->http.ah_count_in_use); + + if (!lwsi_role_http(wsi)) { + lwsl_err("%s: bad role %s\n", __func__, wsi->role_ops->name); + assert(0); + return -1; + } + + lws_pt_lock(pt, __func__); + + /* if we are already bound to one, just clear it down */ + if (wsi->http.ah) { + lwsl_info("%s: cleardown\n", __func__); + goto reset; + } + + n = pt->http.ah_count_in_use == context->max_http_header_pool; +#if defined(LWS_WITH_PEER_LIMITS) + if (!n) { + n = lws_peer_confirm_ah_attach_ok(context, wsi->peer); + if (n) + lws_stats_bump(pt, LWSSTATS_C_PEER_LIMIT_AH_DENIED, 1); + } +#endif + if (n) { + /* + * Pool is either all busy, or we don't want to give this + * particular guy an ah right now... + * + * Make sure we are on the waiting list, and return that we + * weren't able to provide the ah + */ + _lws_header_ensure_we_are_on_waiting_list(wsi); + + goto bail; + } + + __lws_remove_from_ah_waiting_list(wsi); + + wsi->http.ah = _lws_create_ah(pt, context->max_http_header_data); + if (!wsi->http.ah) { /* we could not create an ah */ + _lws_header_ensure_we_are_on_waiting_list(wsi); + + goto bail; + } + + wsi->http.ah->in_use = 1; + wsi->http.ah->wsi = wsi; /* mark our owner */ + pt->http.ah_count_in_use++; + +#if defined(LWS_WITH_PEER_LIMITS) && (defined(LWS_ROLE_H1) || \ + defined(LWS_ROLE_H2)) + lws_context_lock(context, "ah attach"); /* <========================= */ + if (wsi->peer) + wsi->peer->http.count_ah++; + lws_context_unlock(context); /* ====================================> */ +#endif + + _lws_change_pollfd(wsi, 0, LWS_POLLIN, &pa); + + lwsl_info("%s: did attach wsi %p: ah %p: count %d (on exit)\n", __func__, + (void *)wsi, (void *)wsi->http.ah, pt->http.ah_count_in_use); + +reset: + __lws_header_table_reset(wsi, autoservice); + + lws_pt_unlock(pt); + +#if defined(LWS_WITH_CLIENT) +#if defined(LWS_ROLE_MQTT) +connect_via_info2: +#endif + if (lwsi_role_client(wsi) && lwsi_state(wsi) == LRS_UNCONNECTED) + if (!lws_http_client_connect_via_info2(wsi)) + /* our client connect has failed, the wsi + * has been closed + */ + return -1; +#endif + + return 0; + +bail: + lws_pt_unlock(pt); + + return 1; +} + +int __lws_header_table_detach(struct lws *wsi, int autoservice) +{ + struct lws_context *context = wsi->a.context; + struct allocated_headers *ah = wsi->http.ah; + struct lws_context_per_thread *pt = &context->pt[(int)wsi->tsi]; + struct lws_pollargs pa; + struct lws **pwsi, **pwsi_eligible; + time_t now; + + __lws_remove_from_ah_waiting_list(wsi); + + if (!ah) + return 0; + + lwsl_info("%s: wsi %p: ah %p (tsi=%d, count = %d)\n", __func__, + (void *)wsi, (void *)ah, wsi->tsi, + pt->http.ah_count_in_use); + + /* we did have an ah attached */ + time(&now); + if (ah->assigned && now - ah->assigned > 3) { + /* + * we're detaching the ah, but it was held an + * unreasonably long time + */ + lwsl_debug("%s: wsi %p: ah held %ds, role/state 0x%lx 0x%x," + "\n", __func__, wsi, (int)(now - ah->assigned), + (unsigned long)lwsi_role(wsi), lwsi_state(wsi)); + } + + ah->assigned = 0; + + /* if we think we're detaching one, there should be one in use */ + assert(pt->http.ah_count_in_use > 0); + /* and this specific one should have been in use */ + assert(ah->in_use); + memset(&wsi->http.ah, 0, sizeof(wsi->http.ah)); + +#if defined(LWS_WITH_PEER_LIMITS) + if (ah->wsi) + lws_peer_track_ah_detach(context, wsi->peer); +#endif + ah->wsi = NULL; /* no owner */ + wsi->http.ah = NULL; + + pwsi = &pt->http.ah_wait_list; + + /* oh there is nobody on the waiting list... leave the ah unattached */ + if (!*pwsi) + goto nobody_usable_waiting; + + /* + * at least one wsi on the same tsi is waiting, give it to oldest guy + * who is allowed to take it (if any) + */ + lwsl_info("pt wait list %p\n", *pwsi); + wsi = NULL; + pwsi_eligible = NULL; + + while (*pwsi) { +#if defined(LWS_WITH_PEER_LIMITS) + /* are we willing to give this guy an ah? */ + if (!lws_peer_confirm_ah_attach_ok(context, (*pwsi)->peer)) +#endif + { + wsi = *pwsi; + pwsi_eligible = pwsi; + } +#if defined(LWS_WITH_PEER_LIMITS) + else + if (!(*pwsi)->http.ah_wait_list) + lws_stats_bump(pt, + LWSSTATS_C_PEER_LIMIT_AH_DENIED, 1); +#endif + pwsi = &(*pwsi)->http.ah_wait_list; + } + + if (!wsi) /* everybody waiting already has too many ah... */ + goto nobody_usable_waiting; + + lwsl_info("%s: transferring ah to last eligible wsi in wait list " + "%p (wsistate 0x%lx)\n", __func__, wsi, + (unsigned long)wsi->wsistate); + + wsi->http.ah = ah; + ah->wsi = wsi; /* new owner */ + + __lws_header_table_reset(wsi, autoservice); +#if defined(LWS_WITH_PEER_LIMITS) && (defined(LWS_ROLE_H1) || \ + defined(LWS_ROLE_H2)) + lws_context_lock(context, "ah detach"); /* <========================= */ + if (wsi->peer) + wsi->peer->http.count_ah++; + lws_context_unlock(context); /* ====================================> */ +#endif + + /* clients acquire the ah and then insert themselves in fds table... */ + if (wsi->position_in_fds_table != LWS_NO_FDS_POS) { + lwsl_info("%s: Enabling %p POLLIN\n", __func__, wsi); + + /* he has been stuck waiting for an ah, but now his wait is + * over, let him progress */ + + _lws_change_pollfd(wsi, 0, LWS_POLLIN, &pa); + } + + /* point prev guy to next guy in list instead */ + *pwsi_eligible = wsi->http.ah_wait_list; + /* the guy who got one is out of the list */ + wsi->http.ah_wait_list = NULL; + pt->http.ah_wait_list_length--; + +#if defined(LWS_WITH_CLIENT) + if (lwsi_role_client(wsi) && lwsi_state(wsi) == LRS_UNCONNECTED) { + lws_pt_unlock(pt); + + if (!lws_http_client_connect_via_info2(wsi)) { + /* our client connect has failed, the wsi + * has been closed + */ + + return -1; + } + return 0; + } +#endif + + assert(!!pt->http.ah_wait_list_length == + !!(lws_intptr_t)pt->http.ah_wait_list); +bail: + lwsl_info("%s: wsi %p: ah %p (tsi=%d, count = %d)\n", __func__, + (void *)wsi, (void *)ah, pt->tid, pt->http.ah_count_in_use); + + return 0; + +nobody_usable_waiting: + lwsl_info("%s: nobody usable waiting\n", __func__); + _lws_destroy_ah(pt, ah); + pt->http.ah_count_in_use--; + + goto bail; +} + +int lws_header_table_detach(struct lws *wsi, int autoservice) +{ + struct lws_context *context = wsi->a.context; + struct lws_context_per_thread *pt = &context->pt[(int)wsi->tsi]; + int n; + + lws_pt_lock(pt, __func__); + n = __lws_header_table_detach(wsi, autoservice); + lws_pt_unlock(pt); + + return n; +} + +int +lws_hdr_fragment_length(struct lws *wsi, enum lws_token_indexes h, int frag_idx) +{ + int n; + + if (!wsi->http.ah) + return 0; + + n = wsi->http.ah->frag_index[h]; + if (!n) + return 0; + do { + if (!frag_idx) + return wsi->http.ah->frags[n].len; + n = wsi->http.ah->frags[n].nfrag; + } while (frag_idx-- && n); + + return 0; +} + +int lws_hdr_total_length(struct lws *wsi, enum lws_token_indexes h) +{ + int n; + int len = 0; + + if (!wsi->http.ah) + return 0; + + n = wsi->http.ah->frag_index[h]; + if (!n) + return 0; + do { + len += wsi->http.ah->frags[n].len; + n = wsi->http.ah->frags[n].nfrag; + + if (n && h != WSI_TOKEN_HTTP_COOKIE) + ++len; + + } while (n); + + return len; +} + +int lws_hdr_copy_fragment(struct lws *wsi, char *dst, int len, + enum lws_token_indexes h, int frag_idx) +{ + int n = 0; + int f; + + if (!wsi->http.ah) + return -1; + + f = wsi->http.ah->frag_index[h]; + + if (!f) + return -1; + + while (n < frag_idx) { + f = wsi->http.ah->frags[f].nfrag; + if (!f) + return -1; + n++; + } + + if (wsi->http.ah->frags[f].len >= len) + return -1; + + memcpy(dst, wsi->http.ah->data + wsi->http.ah->frags[f].offset, + wsi->http.ah->frags[f].len); + dst[wsi->http.ah->frags[f].len] = '\0'; + + return wsi->http.ah->frags[f].len; +} + +int lws_hdr_copy(struct lws *wsi, char *dst, int len, + enum lws_token_indexes h) +{ + int toklen = lws_hdr_total_length(wsi, h); + int n; + int comma; + + *dst = '\0'; + if (!toklen) + return 0; + + if (toklen >= len) + return -1; + + if (!wsi->http.ah) + return -1; + + n = wsi->http.ah->frag_index[h]; + if (!n) + return 0; + + do { + comma = (wsi->http.ah->frags[n].nfrag && + h != WSI_TOKEN_HTTP_COOKIE) ? 1 : 0; + + if (wsi->http.ah->frags[n].len + comma >= len) + return -1; + strncpy(dst, &wsi->http.ah->data[wsi->http.ah->frags[n].offset], + wsi->http.ah->frags[n].len); + dst += wsi->http.ah->frags[n].len; + len -= wsi->http.ah->frags[n].len; + n = wsi->http.ah->frags[n].nfrag; + + if (comma) + *dst++ = ','; + + } while (n); + *dst = '\0'; + + return toklen; +} + +#if defined(LWS_WITH_CUSTOM_HEADERS) +int +lws_hdr_custom_length(struct lws *wsi, const char *name, int nlen) +{ + ah_data_idx_t ll; + + if (!wsi->http.ah || wsi->mux_substream) + return -1; + + ll = wsi->http.ah->unk_ll_head; + while (ll) { + if (ll >= wsi->http.ah->data_length) + return -1; + if (nlen == lws_ser_ru16be( + (uint8_t *)&wsi->http.ah->data[ll + UHO_NLEN]) && + !strncmp(name, &wsi->http.ah->data[ll + UHO_NAME], nlen)) + return lws_ser_ru16be( + (uint8_t *)&wsi->http.ah->data[ll + UHO_VLEN]); + + ll = lws_ser_ru32be((uint8_t *)&wsi->http.ah->data[ll + UHO_LL]); + } + + return -1; +} + +int +lws_hdr_custom_copy(struct lws *wsi, char *dst, int len, const char *name, + int nlen) +{ + ah_data_idx_t ll; + int n; + + if (!wsi->http.ah || wsi->mux_substream) + return -1; + + *dst = '\0'; + + ll = wsi->http.ah->unk_ll_head; + while (ll) { + if (ll >= wsi->http.ah->data_length) + return -1; + if (nlen == lws_ser_ru16be( + (uint8_t *)&wsi->http.ah->data[ll + UHO_NLEN]) && + !strncmp(name, &wsi->http.ah->data[ll + UHO_NAME], nlen)) { + n = lws_ser_ru16be( + (uint8_t *)&wsi->http.ah->data[ll + UHO_VLEN]); + if (n + 1 > len) + return -1; + strncpy(dst, &wsi->http.ah->data[ll + UHO_NAME + nlen], n); + dst[n] = '\0'; + + return n; + } + ll = lws_ser_ru32be((uint8_t *)&wsi->http.ah->data[ll + UHO_LL]); + } + + return -1; +} +#endif + +char *lws_hdr_simple_ptr(struct lws *wsi, enum lws_token_indexes h) +{ + int n; + + if (!wsi->http.ah) + return NULL; + + n = wsi->http.ah->frag_index[h]; + if (!n) + return NULL; + + return wsi->http.ah->data + wsi->http.ah->frags[n].offset; +} + +static int LWS_WARN_UNUSED_RESULT +lws_pos_in_bounds(struct lws *wsi) +{ + if (!wsi->http.ah) + return -1; + + if (wsi->http.ah->pos < + (unsigned int)wsi->a.context->max_http_header_data) + return 0; + + if ((int)wsi->http.ah->pos >= wsi->a.context->max_http_header_data - 1) { + lwsl_err("Ran out of header data space\n"); + return 1; + } + + /* + * with these tests everywhere, it should never be able to exceed + * the limit, only meet it + */ + lwsl_err("%s: pos %ld, limit %ld\n", __func__, + (unsigned long)wsi->http.ah->pos, + (unsigned long)wsi->a.context->max_http_header_data); + assert(0); + + return 1; +} + +int LWS_WARN_UNUSED_RESULT +lws_hdr_simple_create(struct lws *wsi, enum lws_token_indexes h, const char *s) +{ + if (!*s) { + /* + * If we get an empty string, then remove any entry for the + * header + */ + wsi->http.ah->frag_index[h] = 0; + + return 0; + } + + wsi->http.ah->nfrag++; + if (wsi->http.ah->nfrag == LWS_ARRAY_SIZE(wsi->http.ah->frags)) { + lwsl_warn("More hdr frags than we can deal with, dropping\n"); + return -1; + } + + wsi->http.ah->frag_index[h] = wsi->http.ah->nfrag; + + wsi->http.ah->frags[wsi->http.ah->nfrag].offset = wsi->http.ah->pos; + wsi->http.ah->frags[wsi->http.ah->nfrag].len = 0; + wsi->http.ah->frags[wsi->http.ah->nfrag].nfrag = 0; + + do { + if (lws_pos_in_bounds(wsi)) + return -1; + + wsi->http.ah->data[wsi->http.ah->pos++] = *s; + if (*s) + wsi->http.ah->frags[wsi->http.ah->nfrag].len++; + } while (*s++); + + return 0; +} + +static int LWS_WARN_UNUSED_RESULT +issue_char(struct lws *wsi, unsigned char c) +{ + unsigned short frag_len; + + if (lws_pos_in_bounds(wsi)) + return -1; + + frag_len = wsi->http.ah->frags[wsi->http.ah->nfrag].len; + /* + * If we haven't hit the token limit, just copy the character into + * the header + */ + if (!wsi->http.ah->current_token_limit || + frag_len < wsi->http.ah->current_token_limit) { + wsi->http.ah->data[wsi->http.ah->pos++] = c; + if (c) + wsi->http.ah->frags[wsi->http.ah->nfrag].len++; + return 0; + } + + /* Insert a null character when we *hit* the limit: */ + if (frag_len == wsi->http.ah->current_token_limit) { + if (lws_pos_in_bounds(wsi)) + return -1; + + wsi->http.ah->data[wsi->http.ah->pos++] = '\0'; + lwsl_warn("header %li exceeds limit %ld\n", + (long)wsi->http.ah->parser_state, + (long)wsi->http.ah->current_token_limit); + } + + return 1; +} + +int +lws_parse_urldecode(struct lws *wsi, uint8_t *_c) +{ + struct allocated_headers *ah = wsi->http.ah; + unsigned int enc = 0; + uint8_t c = *_c; + + // lwsl_notice("ah->ups %d\n", ah->ups); + + /* + * PRIORITY 1 + * special URI processing... convert %xx + */ + switch (ah->ues) { + case URIES_IDLE: + if (c == '%') { + ah->ues = URIES_SEEN_PERCENT; + goto swallow; + } + break; + case URIES_SEEN_PERCENT: + if (char_to_hex(c) < 0) + /* illegal post-% char */ + goto forbid; + + ah->esc_stash = c; + ah->ues = URIES_SEEN_PERCENT_H1; + goto swallow; + + case URIES_SEEN_PERCENT_H1: + if (char_to_hex(c) < 0) + /* illegal post-% char */ + goto forbid; + + *_c = (char_to_hex(ah->esc_stash) << 4) | + char_to_hex(c); + c = *_c; + enc = 1; + ah->ues = URIES_IDLE; + break; + } + + /* + * PRIORITY 2 + * special URI processing... + * convert /.. or /... or /../ etc to / + * convert /./ to / + * convert // or /// etc to / + * leave /.dir or whatever alone + */ + + switch (ah->ups) { + case URIPS_IDLE: + if (!c) + return -1; + /* genuine delimiter */ + if ((c == '&' || c == ';') && !enc) { + if (issue_char(wsi, '\0') < 0) + return -1; + /* link to next fragment */ + ah->frags[ah->nfrag].nfrag = ah->nfrag + 1; + ah->nfrag++; + if (ah->nfrag >= LWS_ARRAY_SIZE(ah->frags)) + goto excessive; + /* start next fragment after the & */ + ah->post_literal_equal = 0; + ah->frags[ah->nfrag].offset = ++ah->pos; + ah->frags[ah->nfrag].len = 0; + ah->frags[ah->nfrag].nfrag = 0; + goto swallow; + } + /* uriencoded = in the name part, disallow */ + if (c == '=' && enc && + ah->frag_index[WSI_TOKEN_HTTP_URI_ARGS] && + !ah->post_literal_equal) { + c = '_'; + *_c =c; + } + + /* after the real =, we don't care how many = */ + if (c == '=' && !enc) + ah->post_literal_equal = 1; + + /* + to space */ + if (c == '+' && !enc) { + c = ' '; + *_c = c; + } + /* issue the first / always */ + if (c == '/' && !ah->frag_index[WSI_TOKEN_HTTP_URI_ARGS]) + ah->ups = URIPS_SEEN_SLASH; + break; + case URIPS_SEEN_SLASH: + /* swallow subsequent slashes */ + if (c == '/') + goto swallow; + /* track and swallow the first . after / */ + if (c == '.') { + ah->ups = URIPS_SEEN_SLASH_DOT; + goto swallow; + } + ah->ups = URIPS_IDLE; + break; + case URIPS_SEEN_SLASH_DOT: + /* swallow second . */ + if (c == '.') { + ah->ups = URIPS_SEEN_SLASH_DOT_DOT; + goto swallow; + } + /* change /./ to / */ + if (c == '/') { + ah->ups = URIPS_SEEN_SLASH; + goto swallow; + } + /* it was like /.dir ... regurgitate the . */ + ah->ups = URIPS_IDLE; + if (issue_char(wsi, '.') < 0) + return -1; + break; + + case URIPS_SEEN_SLASH_DOT_DOT: + + /* /../ or /..[End of URI] --> backup to last / */ + if (c == '/' || c == '?') { + /* + * back up one dir level if possible + * safe against header fragmentation because + * the method URI can only be in 1 fragment + */ + if (ah->frags[ah->nfrag].len > 2) { + ah->pos--; + ah->frags[ah->nfrag].len--; + do { + ah->pos--; + ah->frags[ah->nfrag].len--; + } while (ah->frags[ah->nfrag].len > 1 && + ah->data[ah->pos] != '/'); + } + ah->ups = URIPS_SEEN_SLASH; + if (ah->frags[ah->nfrag].len > 1) + break; + goto swallow; + } + + /* /..[^/] ... regurgitate and allow */ + + if (issue_char(wsi, '.') < 0) + return -1; + if (issue_char(wsi, '.') < 0) + return -1; + ah->ups = URIPS_IDLE; + break; + } + + if (c == '?' && !enc && + !ah->frag_index[WSI_TOKEN_HTTP_URI_ARGS]) { /* start of URI args */ + if (ah->ues != URIES_IDLE) + goto forbid; + + /* seal off uri header */ + if (issue_char(wsi, '\0') < 0) + return -1; + + /* move to using WSI_TOKEN_HTTP_URI_ARGS */ + ah->nfrag++; + if (ah->nfrag >= LWS_ARRAY_SIZE(ah->frags)) + goto excessive; + ah->frags[ah->nfrag].offset = ++ah->pos; + ah->frags[ah->nfrag].len = 0; + ah->frags[ah->nfrag].nfrag = 0; + + ah->post_literal_equal = 0; + ah->frag_index[WSI_TOKEN_HTTP_URI_ARGS] = ah->nfrag; + ah->ups = URIPS_IDLE; + goto swallow; + } + + return LPUR_CONTINUE; + +swallow: + return LPUR_SWALLOW; + +forbid: + return LPUR_FORBID; + +excessive: + return LPUR_EXCESSIVE; +} + +static const unsigned char methods[] = { + WSI_TOKEN_GET_URI, + WSI_TOKEN_POST_URI, +#if defined(LWS_WITH_HTTP_UNCOMMON_HEADERS) + WSI_TOKEN_OPTIONS_URI, + WSI_TOKEN_PUT_URI, + WSI_TOKEN_PATCH_URI, + WSI_TOKEN_DELETE_URI, +#endif + WSI_TOKEN_CONNECT, + WSI_TOKEN_HEAD_URI, +}; + +/* + * possible returns:, -1 fail, 0 ok or 2, transition to raw + */ + +lws_parser_return_t LWS_WARN_UNUSED_RESULT +lws_parse(struct lws *wsi, unsigned char *buf, int *len) +{ + struct allocated_headers *ah = wsi->http.ah; + struct lws_context *context = wsi->a.context; + unsigned int n, m; + unsigned char c; + int r, pos; + + assert(wsi->http.ah); + + do { + (*len)--; + c = *buf++; + + switch (ah->parser_state) { +#if defined(LWS_WITH_CUSTOM_HEADERS) + case WSI_TOKEN_UNKNOWN_VALUE_PART: + + if (c == '\r') + break; + if (c == '\n') { + lws_ser_wu16be((uint8_t *)&ah->data[ah->unk_pos + 2], + ah->pos - ah->unk_value_pos); + ah->parser_state = WSI_TOKEN_NAME_PART; + ah->unk_pos = 0; + ah->lextable_pos = 0; + break; + } + + /* trim leading whitespace */ + if (ah->pos != ah->unk_value_pos || + (c != ' ' && c != '\t')) { + + if (lws_pos_in_bounds(wsi)) + return LPR_FAIL; + + ah->data[ah->pos++] = c; + } + pos = ah->lextable_pos; + break; +#endif + default: + + lwsl_parser("WSI_TOK_(%d) '%c'\n", ah->parser_state, c); + + /* collect into malloc'd buffers */ + /* optional initial space swallow */ + if (!ah->frags[ah->frag_index[ah->parser_state]].len && + c == ' ') + break; + + for (m = 0; m < LWS_ARRAY_SIZE(methods); m++) + if (ah->parser_state == methods[m]) + break; + if (m == LWS_ARRAY_SIZE(methods)) + /* it was not any of the methods */ + goto check_eol; + + /* special URI processing... end at space */ + + if (c == ' ') { + /* enforce starting with / */ + if (!ah->frags[ah->nfrag].len) + if (issue_char(wsi, '/') < 0) + return LPR_FAIL; + + if (ah->ups == URIPS_SEEN_SLASH_DOT_DOT) { + /* + * back up one dir level if possible + * safe against header fragmentation + * because the method URI can only be + * in 1 fragment + */ + if (ah->frags[ah->nfrag].len > 2) { + ah->pos--; + ah->frags[ah->nfrag].len--; + do { + ah->pos--; + ah->frags[ah->nfrag].len--; + } while (ah->frags[ah->nfrag].len > 1 && + ah->data[ah->pos] != '/'); + } + } + + /* begin parsing HTTP version: */ + if (issue_char(wsi, '\0') < 0) + return LPR_FAIL; + ah->parser_state = WSI_TOKEN_HTTP; + goto start_fragment; + } + + r = lws_parse_urldecode(wsi, &c); + switch (r) { + case LPUR_CONTINUE: + break; + case LPUR_SWALLOW: + goto swallow; + case LPUR_FORBID: + goto forbid; + case LPUR_EXCESSIVE: + goto excessive; + default: + return LPR_FAIL; + } +check_eol: + /* bail at EOL */ + if (ah->parser_state != WSI_TOKEN_CHALLENGE && + (c == '\x0d' || c == '\x0a')) { + if (ah->ues != URIES_IDLE) + goto forbid; + + if (c == '\x0a') { + /* broken peer */ + ah->parser_state = WSI_TOKEN_NAME_PART; + ah->unk_pos = ah->lextable_pos = 0; + } else + ah->parser_state = WSI_TOKEN_SKIPPING_SAW_CR; + + c = '\0'; + lwsl_parser("*\n"); + } + + n = issue_char(wsi, c); + if ((int)n < 0) + return LPR_FAIL; + if (n > 0) + ah->parser_state = WSI_TOKEN_SKIPPING; + +swallow: + /* per-protocol end of headers management */ + + if (ah->parser_state == WSI_TOKEN_CHALLENGE) + goto set_parsing_complete; + break; + + /* collecting and checking a name part */ + case WSI_TOKEN_NAME_PART: + lwsl_parser("WSI_TOKEN_NAME_PART '%c' 0x%02X " + "(role=0x%lx) " + "wsi->lextable_pos=%d\n", c, c, + (unsigned long)lwsi_role(wsi), + ah->lextable_pos); + + if (!ah->unk_pos && c == '\x0a') + /* broken peer */ + goto set_parsing_complete; + + if (c >= 'A' && c <= 'Z') + c += 'a' - 'A'; + /* + * ...in case it's an unknown header, speculatively + * store it as the name comes in. If we recognize it as + * a known header, we'll snip this. + */ + + if (!wsi->mux_substream && !ah->unk_pos) { + ah->unk_pos = ah->pos; + +#if defined(LWS_WITH_CUSTOM_HEADERS) + /* + * Prepare new unknown header linked-list entry + * + * - 16-bit BE: name part length + * - 16-bit BE: value part length + * - 32-bit BE: data offset of next, or 0 + */ + for (n = 0; n < 8; n++) + if (!lws_pos_in_bounds(wsi)) + ah->data[ah->pos++] = 0; +#endif + } + + if (lws_pos_in_bounds(wsi)) + return LPR_FAIL; + + ah->data[ah->pos++] = c; + pos = ah->lextable_pos; + +#if defined(LWS_WITH_CUSTOM_HEADERS) + if (!wsi->mux_substream && pos < 0 && c == ':') { +#if defined(_DEBUG) + char dotstar[64]; + int uhlen; +#endif + + /* + * process unknown headers + * + * register us in the unknown hdr ll + */ + + if (!ah->unk_ll_head) + ah->unk_ll_head = ah->unk_pos; + + if (ah->unk_ll_tail) + lws_ser_wu32be( + (uint8_t *)&ah->data[ah->unk_ll_tail + UHO_LL], + ah->unk_pos); + + ah->unk_ll_tail = ah->unk_pos; + +#if defined(_DEBUG) + uhlen = ah->pos - (ah->unk_pos + UHO_NAME); + lws_strnncpy(dotstar, + &ah->data[ah->unk_pos + UHO_NAME], + uhlen, sizeof(dotstar)); + lwsl_debug("%s: unk header %d '%s'\n", + __func__, + ah->pos - (ah->unk_pos + UHO_NAME), + dotstar); +#endif + + /* set the unknown header name part length */ + + lws_ser_wu16be((uint8_t *)&ah->data[ah->unk_pos], + (ah->pos - ah->unk_pos) - UHO_NAME); + + ah->unk_value_pos = ah->pos; + + /* + * collect whatever's coming for the unknown header + * argument until the next CRLF + */ + ah->parser_state = WSI_TOKEN_UNKNOWN_VALUE_PART; + break; + } +#endif + if (pos < 0) + break; + + while (1) { + if (lextable_h1[pos] & (1 << 7)) { + /* 1-byte, fail on mismatch */ + if ((lextable_h1[pos] & 0x7f) != c) { +nope: + ah->lextable_pos = -1; + break; + } + /* fall thru */ + pos++; + if (lextable_h1[pos] == FAIL_CHAR) + goto nope; + + ah->lextable_pos = pos; + break; + } + + if (lextable_h1[pos] == FAIL_CHAR) + goto nope; + + /* b7 = 0, end or 3-byte */ + if (lextable_h1[pos] < FAIL_CHAR) { + if (!wsi->mux_substream) { + /* + * We hit a terminal marker, so + * we recognized this header... + * drop the speculative name + * part storage + */ + ah->pos = ah->unk_pos; + ah->unk_pos = 0; + } + + ah->lextable_pos = pos; + break; + } + + if (lextable_h1[pos] == c) { /* goto */ + ah->lextable_pos = pos + + (lextable_h1[pos + 1]) + + (lextable_h1[pos + 2] << 8); + break; + } + + /* fall thru goto */ + pos += 3; + /* continue */ + } + + /* + * If it's h1, server needs to be on the look out for + * unknown methods... + */ + if (ah->lextable_pos < 0 && lwsi_role_h1(wsi) && + lwsi_role_server(wsi)) { + /* + * this is not a header we know about... did + * we get a valid method (GET, POST etc) + * already, or is this the bogus method? + */ + for (m = 0; m < LWS_ARRAY_SIZE(methods); m++) + if (ah->frag_index[methods[m]]) { + /* + * already had the method + */ +#if !defined(LWS_WITH_CUSTOM_HEADERS) + ah->parser_state = WSI_TOKEN_SKIPPING; +#endif + if (wsi->mux_substream) + ah->parser_state = WSI_TOKEN_SKIPPING; + break; + } + + if (m != LWS_ARRAY_SIZE(methods)) { +#if defined(LWS_WITH_CUSTOM_HEADERS) + /* + * We have the method, this is just an + * unknown header then + */ + if (!wsi->mux_substream) + goto unknown_hdr; + else + break; +#else + break; +#endif + } + /* + * ...it's an unknown http method from a client + * in fact, it cannot be valid http. + * + * Are we set up to transition to another role + * in these cases? + */ + if (lws_check_opt(wsi->a.vhost->options, + LWS_SERVER_OPTION_FALLBACK_TO_APPLY_LISTEN_ACCEPT_CONFIG)) { + lwsl_notice("%s: http fail fallback\n", + __func__); + /* transition to other role */ + return LPR_DO_FALLBACK; + } + + lwsl_info("Unknown method - dropping\n"); + goto forbid; + } + if (ah->lextable_pos < 0) { + /* + * It's not a header that lws knows about... + */ +#if defined(LWS_WITH_CUSTOM_HEADERS) + if (!wsi->mux_substream) + goto unknown_hdr; +#endif + /* + * ...otherwise for a client, let him ignore + * unknown headers coming from the server + */ + ah->parser_state = WSI_TOKEN_SKIPPING; + break; + } + + if (lextable_h1[ah->lextable_pos] < FAIL_CHAR) { + /* terminal state */ + + n = ((unsigned int)lextable_h1[ah->lextable_pos] << 8) | + lextable_h1[ah->lextable_pos + 1]; + + lwsl_parser("known hdr %d\n", n); + for (m = 0; m < LWS_ARRAY_SIZE(methods); m++) + if (n == methods[m] && + ah->frag_index[methods[m]]) { + lwsl_warn("Duplicated method\n"); + return LPR_FAIL; + } + + if (!wsi->mux_substream) { + /* + * Whether we are collecting unknown names or not, + * if we matched an internal header we can dispense + * with the header name part we were keeping + */ + ah->pos = ah->unk_pos; + ah->unk_pos = 0; + } + +#if defined(LWS_ROLE_WS) + /* + * WSORIGIN is protocol equiv to ORIGIN, + * JWebSocket likes to send it, map to ORIGIN + */ + if (n == WSI_TOKEN_SWORIGIN) + n = WSI_TOKEN_ORIGIN; +#endif + + ah->parser_state = (enum lws_token_indexes) + (WSI_TOKEN_GET_URI + n); + ah->ups = URIPS_IDLE; + + if (context->token_limits) + ah->current_token_limit = context-> + token_limits->token_limit[ + ah->parser_state]; + else + ah->current_token_limit = + wsi->a.context->max_http_header_data; + + if (ah->parser_state == WSI_TOKEN_CHALLENGE) + goto set_parsing_complete; + + goto start_fragment; + } + break; + +#if defined(LWS_WITH_CUSTOM_HEADERS) +unknown_hdr: + //ah->parser_state = WSI_TOKEN_SKIPPING; + //break; + if (!wsi->mux_substream) + break; +#endif + +start_fragment: + ah->nfrag++; +excessive: + if (ah->nfrag == LWS_ARRAY_SIZE(ah->frags)) { + lwsl_warn("More hdr frags than we can deal with\n"); + return LPR_FAIL; + } + + ah->frags[ah->nfrag].offset = ah->pos; + ah->frags[ah->nfrag].len = 0; + ah->frags[ah->nfrag].nfrag = 0; + ah->frags[ah->nfrag].flags = 2; + + n = ah->frag_index[ah->parser_state]; + if (!n) { /* first fragment */ + ah->frag_index[ah->parser_state] = ah->nfrag; + ah->hdr_token_idx = ah->parser_state; + break; + } + /* continuation */ + while (ah->frags[n].nfrag) + n = ah->frags[n].nfrag; + ah->frags[n].nfrag = ah->nfrag; + + if (issue_char(wsi, ' ') < 0) + return LPR_FAIL; + break; + + /* skipping arg part of a name we didn't recognize */ + case WSI_TOKEN_SKIPPING: + lwsl_parser("WSI_TOKEN_SKIPPING '%c'\n", c); + + if (c == '\x0a') { + /* broken peer */ + ah->parser_state = WSI_TOKEN_NAME_PART; + ah->unk_pos = ah->lextable_pos = 0; + } + + if (c == '\x0d') + ah->parser_state = WSI_TOKEN_SKIPPING_SAW_CR; + break; + + case WSI_TOKEN_SKIPPING_SAW_CR: + lwsl_parser("WSI_TOKEN_SKIPPING_SAW_CR '%c'\n", c); + if (ah->ues != URIES_IDLE) + goto forbid; + if (c == '\x0a') { + ah->parser_state = WSI_TOKEN_NAME_PART; + ah->unk_pos = ah->lextable_pos = 0; + } else + ah->parser_state = WSI_TOKEN_SKIPPING; + break; + /* we're done, ignore anything else */ + + case WSI_PARSING_COMPLETE: + lwsl_parser("WSI_PARSING_COMPLETE '%c'\n", c); + break; + } + + } while (*len); + + return LPR_OK; + +set_parsing_complete: + if (ah->ues != URIES_IDLE) + goto forbid; + + if (lws_hdr_total_length(wsi, WSI_TOKEN_UPGRADE)) { +#if defined(LWS_ROLE_WS) + const char *pv = lws_hdr_simple_ptr(wsi, WSI_TOKEN_VERSION); + if (pv) + wsi->rx_frame_type = atoi(pv); + + lwsl_parser("v%02d hdrs done\n", wsi->rx_frame_type); +#endif + } + ah->parser_state = WSI_PARSING_COMPLETE; + wsi->hdr_parsing_completed = 1; + + return LPR_OK; + +forbid: + lwsl_info(" forbidding on uri sanitation\n"); +#if defined(LWS_WITH_SERVER) + lws_return_http_status(wsi, HTTP_STATUS_FORBIDDEN, NULL); +#endif + + return LPR_FORBIDDEN; +} + +int +lws_http_cookie_get(struct lws *wsi, const char *name, char *buf, + size_t *max_len) +{ + int n, bl = (int)strlen(name); + size_t max = *max_len; + char *p, *bo = buf; + + n = lws_hdr_total_length(wsi, WSI_TOKEN_HTTP_COOKIE); + lwsl_notice("%s: cookie hdr len %d\n", __func__, n); + if (n < bl + 1) + return 1; + + p = lws_hdr_simple_ptr(wsi, WSI_TOKEN_HTTP_COOKIE); + if (!p) + return 1; + + lwsl_hexdump_notice(p, n); + + p += bl; + n -= bl; + while (n-- > bl) { + if (*p == '=' && !memcmp(p - bl, name, bl)) { + p++; + while (*p != ';' && n-- && max) { + *buf++ = *p++; + max--; + } + if (!max) + return 2; + + *buf = '\0'; + *max_len = lws_ptr_diff(buf, bo); + + return 0; + } + p++; + } + + return 1; +} + +#if defined(LWS_WITH_JOSE) + +#define MAX_JWT_SIZE 1024 + +int +lws_jwt_get_http_cookie_validate_jwt(struct lws *wsi, + struct lws_jwt_sign_set_cookie *i, + char *out, size_t *out_len) +{ + char temp[MAX_JWT_SIZE * 2]; + size_t cml = *out_len; + const char *cp; + + /* first use out to hold the encoded JWT */ + + if (lws_http_cookie_get(wsi, i->cookie_name, out, out_len)) { + lwsl_notice("%s: cookie %s not provided\n", __func__, + i->cookie_name); + return 1; + } + + /* decode the JWT into temp */ + + if (lws_jwt_signed_validate(wsi->a.context, i->jwk, i->alg, out, + *out_len, temp, sizeof(temp), out, &cml)) { + lwsl_notice("%s: jwt validation failed\n", __func__); + return 1; + } + + /* + * Copy out the decoded JWT payload into out, overwriting the + * original encoded JWT taken from the cookie (that has long ago been + * translated into allocated buffers in the JOSE object) + */ + + if (lws_jwt_token_sanity(out, cml, i->iss, i->aud, i->csrf_in, + i->sub, sizeof(i->sub), + &i->expiry_unix_time)) { + lwsl_notice("%s: jwt sanity failed\n", __func__); + return 1; + } + + /* + * If he's interested in his private JSON part, point him to that in + * the args struct (it's pointing to the data in out + */ + + cp = lws_json_simple_find(out, cml, "\"ext\":", &i->extra_json_len); + if (cp) + i->extra_json = cp; + + if (cp) + lwsl_hexdump_notice(cp, i->extra_json_len); + else + lwsl_notice("%s: no ext JWT payload\n", __func__); + + return 0; +} + +int +lws_jwt_sign_token_set_http_cookie(struct lws *wsi, + const struct lws_jwt_sign_set_cookie *i, + uint8_t **p, uint8_t *end) +{ + char plain[MAX_JWT_SIZE + 1], temp[MAX_JWT_SIZE * 2], csrf[17]; + size_t pl = sizeof(plain); + unsigned long long ull; + int n; + + /* + * Create a 16-char random csrf token with the same lifetime as the JWT + */ + + lws_hex_random(wsi->a.context, csrf, sizeof(csrf)); + ull = lws_now_secs(); + if (lws_jwt_sign_compact(wsi->a.context, i->jwk, i->alg, plain, &pl, + temp, sizeof(temp), + "{\"iss\":\"%s\",\"aud\":\"%s\"," + "\"iat\":%llu,\"nbf\":%llu,\"exp\":%llu," + "\"csrf\":\"%s\",\"sub\":\"%s\"%s%s%s}", + i->iss, i->aud, ull, ull - 60, + ull + i->expiry_unix_time, + csrf, i->sub, + i->extra_json ? ",\"ext\":{" : "", + i->extra_json ? i->extra_json : "", + i->extra_json ? "}" : "")) { + lwsl_err("%s: failed to create JWT\n", __func__); + + return 1; + } + + /* + * There's no point the browser holding on to a JWT beyond the JWT's + * expiry time, so set it to be the same. + */ + + n = lws_snprintf(temp, sizeof(temp), "__Host-%s=%s;" + "HttpOnly;" + "Secure;" + "SameSite=strict;" + "Path=/;" + "Max-Age=%lu", + i->cookie_name, plain, i->expiry_unix_time); + + if (lws_add_http_header_by_token(wsi, WSI_TOKEN_HTTP_SET_COOKIE, + (uint8_t *)temp, n, p, end)) { + lwsl_err("%s: failed to add JWT cookie header\n", __func__); + return 1; + } + + return 0; +} +#endif diff -Nru libwebsockets-3.2.1/lib/roles/http/private.h libwebsockets-4.1.6/lib/roles/http/private.h --- libwebsockets-3.2.1/lib/roles/http/private.h 2019-12-18 14:45:31.000000000 +0000 +++ libwebsockets-4.1.6/lib/roles/http/private.h 1970-01-01 00:00:00.000000000 +0000 @@ -1,306 +0,0 @@ -/* - * libwebsockets - small server side websockets and web server implementation - * - * Copyright (C) 2010 - 2018 Andy Green - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation: - * version 2.1 of the License. - * - * This library is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with this library; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, - * MA 02110-1301 USA - * - * This is included from core/private.h if either H1 or H2 roles are - * enabled - */ - -#if defined(LWS_WITH_HUBBUB) - #include - #include - #endif - -#if defined(LWS_WITH_HTTP_STREAM_COMPRESSION) -#include "roles/http/compression/private.h" -#endif - -#define lwsi_role_http(wsi) (lwsi_role_h1(wsi) || lwsi_role_h2(wsi)) - -enum http_version { - HTTP_VERSION_1_0, - HTTP_VERSION_1_1, - HTTP_VERSION_2 -}; - -enum http_conn_type { - HTTP_CONNECTION_CLOSE, - HTTP_CONNECTION_KEEP_ALIVE -}; - -/* - * This is totally opaque to code using the library. It's exported as a - * forward-reference pointer-only declaration; the user can use the pointer with - * other APIs to get information out of it. - */ - -#if defined(LWS_WITH_ESP32) -typedef uint16_t ah_data_idx_t; -#else -typedef uint32_t ah_data_idx_t; -#endif - -struct lws_fragments { - ah_data_idx_t offset; - uint16_t len; - uint8_t nfrag; /* which ah->frag[] continues this content, or 0 */ - uint8_t flags; /* only http2 cares */ -}; - -#if defined(LWS_WITH_RANGES) -enum range_states { - LWSRS_NO_ACTIVE_RANGE, - LWSRS_BYTES_EQ, - LWSRS_FIRST, - LWSRS_STARTING, - LWSRS_ENDING, - LWSRS_COMPLETED, - LWSRS_SYNTAX, -}; - -struct lws_range_parsing { - unsigned long long start, end, extent, agg, budget; - const char buf[128]; - int pos; - enum range_states state; - char start_valid, end_valid, ctr, count_ranges, did_try, inside, send_ctr; -}; - -int -lws_ranges_init(struct lws *wsi, struct lws_range_parsing *rp, - unsigned long long extent); -int -lws_ranges_next(struct lws_range_parsing *rp); -void -lws_ranges_reset(struct lws_range_parsing *rp); -#endif - -/* - * these are assigned from a pool held in the context. - * Both client and server mode uses them for http header analysis - */ - -struct allocated_headers { - struct allocated_headers *next; /* linked list */ - struct lws *wsi; /* owner */ - char *data; /* prepared by context init to point to dedicated storage */ - ah_data_idx_t data_length; - /* - * the randomly ordered fragments, indexed by frag_index and - * lws_fragments->nfrag for continuation. - */ - struct lws_fragments frags[WSI_TOKEN_COUNT]; - time_t assigned; - /* - * for each recognized token, frag_index says which frag[] his data - * starts in (0 means the token did not appear) - * the actual header data gets dumped as it comes in, into data[] - */ - uint8_t frag_index[WSI_TOKEN_COUNT]; - -#ifndef LWS_NO_CLIENT - char initial_handshake_hash_base64[30]; -#endif - int hdr_token_idx; - - ah_data_idx_t pos; - ah_data_idx_t http_response; - ah_data_idx_t current_token_limit; - -#if defined(LWS_WITH_CUSTOM_HEADERS) - ah_data_idx_t unk_pos; /* to undo speculative unknown header */ - ah_data_idx_t unk_value_pos; - - ah_data_idx_t unk_ll_head; - ah_data_idx_t unk_ll_tail; -#endif - - int16_t lextable_pos; - - uint8_t in_use; - uint8_t nfrag; - char /*enum uri_path_states */ ups; - char /*enum uri_esc_states */ ues; - - char esc_stash; - char post_literal_equal; - uint8_t /* enum lws_token_indexes */ parser_state; -}; - - - -#if defined(LWS_WITH_HUBBUB) -struct lws_rewrite { - hubbub_parser *parser; - hubbub_parser_optparams params; - const char *from, *to; - int from_len, to_len; - unsigned char *p, *end; - struct lws *wsi; -}; -static LWS_INLINE int hstrcmp(hubbub_string *s, const char *p, int len) -{ - if ((int)s->len != len) - return 1; - - return strncmp((const char *)s->ptr, p, len); -} -typedef hubbub_error (*hubbub_callback_t)(const hubbub_token *token, void *pw); -LWS_EXTERN struct lws_rewrite * -lws_rewrite_create(struct lws *wsi, hubbub_callback_t cb, const char *from, const char *to); -LWS_EXTERN void -lws_rewrite_destroy(struct lws_rewrite *r); -LWS_EXTERN int -lws_rewrite_parse(struct lws_rewrite *r, const unsigned char *in, int in_len); -#endif - -struct lws_pt_role_http { - struct allocated_headers *ah_list; - struct lws *ah_wait_list; -#ifdef LWS_WITH_CGI - struct lws_cgi *cgi_list; -#endif - int ah_wait_list_length; - uint32_t ah_pool_length; - - int ah_count_in_use; -}; - -struct lws_peer_role_http { - uint32_t count_ah; - uint32_t total_ah; -}; - -struct lws_vhost_role_http { - char http_proxy_address[128]; - const struct lws_http_mount *mount_list; - const char *error_document_404; - unsigned int http_proxy_port; -}; - -#ifdef LWS_WITH_ACCESS_LOG -struct lws_access_log { - char *header_log; - char *user_agent; - char *referrer; - unsigned long sent; - int response; -}; -#endif - -#define LWS_HTTP_CHUNK_HDR_MAX_SIZE (6 + 2) /* 6 hex digits and then CRLF */ -#define LWS_HTTP_CHUNK_TRL_MAX_SIZE (2 + 5) /* CRLF, then maybe 0 CRLF CRLF */ - -struct _lws_http_mode_related { - struct lws *new_wsi_list; - - unsigned char *pending_return_headers; - size_t pending_return_headers_len; - size_t prh_content_length; - -#if defined(LWS_WITH_HTTP_PROXY) - struct lws_rewrite *rw; - struct lws_buflist *buflist_post_body; -#endif - struct allocated_headers *ah; - struct lws *ah_wait_list; - - lws_filepos_t filepos; - lws_filepos_t filelen; - lws_fop_fd_t fop_fd; - -#if defined(LWS_WITH_RANGES) - struct lws_range_parsing range; - char multipart_content_type[64]; -#endif - -#ifdef LWS_WITH_ACCESS_LOG - struct lws_access_log access_log; -#endif -#ifdef LWS_WITH_CGI - struct lws_cgi *cgi; /* wsi being cgi master have one of these */ -#endif -#if defined(LWS_WITH_HTTP_STREAM_COMPRESSION) - struct lws_compression_support *lcs; - lws_comp_ctx_t comp_ctx; - unsigned char comp_accept_mask; -#endif - - enum http_version request_version; - enum http_conn_type conn_type; - lws_filepos_t tx_content_length; - lws_filepos_t tx_content_remain; - lws_filepos_t rx_content_length; - lws_filepos_t rx_content_remain; - -#if defined(LWS_WITH_HTTP_PROXY) - unsigned int perform_rewrite:1; - unsigned int proxy_clientside:1; - unsigned int proxy_parent_chunked:1; -#endif - unsigned int deferred_transaction_completed:1; - unsigned int content_length_explicitly_zero:1; - unsigned int did_stream_close:1; -}; - - -#ifndef LWS_NO_CLIENT -enum lws_chunk_parser { - ELCP_HEX, - ELCP_CR, - ELCP_CONTENT, - ELCP_POST_CR, - ELCP_POST_LF, -}; -#endif - -enum lws_parse_urldecode_results { - LPUR_CONTINUE, - LPUR_SWALLOW, - LPUR_FORBID, - LPUR_EXCESSIVE, -}; - -enum lws_check_basic_auth_results { - LCBA_CONTINUE, - LCBA_FAILED_AUTH, - LCBA_END_TRANSACTION, -}; - -enum lws_check_basic_auth_results -lws_check_basic_auth(struct lws *wsi, const char *basic_auth_login_file); - -int -lws_unauthorised_basic_auth(struct lws *wsi); - -int -lws_read_h1(struct lws *wsi, unsigned char *buf, lws_filepos_t len); - -void -_lws_header_table_reset(struct allocated_headers *ah); - -LWS_EXTERN int -_lws_destroy_ah(struct lws_context_per_thread *pt, struct allocated_headers *ah); - -int -lws_http_proxy_start(struct lws *wsi, const struct lws_http_mount *hit, - char *uri_ptr, char ws); - -void -lws_sul_http_ah_lifecheck(lws_sorted_usec_list_t *sul); diff -Nru libwebsockets-3.2.1/lib/roles/http/private-lib-roles-http.h libwebsockets-4.1.6/lib/roles/http/private-lib-roles-http.h --- libwebsockets-3.2.1/lib/roles/http/private-lib-roles-http.h 1970-01-01 00:00:00.000000000 +0000 +++ libwebsockets-4.1.6/lib/roles/http/private-lib-roles-http.h 2020-12-01 17:40:26.000000000 +0000 @@ -0,0 +1,337 @@ + /* + * libwebsockets - small server side websockets and web server implementation + * + * Copyright (C) 2010 - 2019 Andy Green + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to + * deal in the Software without restriction, including without limitation the + * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or + * sell copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS + * IN THE SOFTWARE. + * + * This is included from private-lib-core.h if either H1 or H2 roles are + * enabled + */ + +#if defined(LWS_WITH_HUBBUB) + #include + #include + #endif + +#if defined(LWS_WITH_HTTP_STREAM_COMPRESSION) +#include "private-lib-roles-http-compression.h" +#endif + +#define lwsi_role_http(wsi) (lwsi_role_h1(wsi) || lwsi_role_h2(wsi)) + +enum http_version { + HTTP_VERSION_1_0, + HTTP_VERSION_1_1, + HTTP_VERSION_2 +}; + +enum http_conn_type { + HTTP_CONNECTION_CLOSE, + HTTP_CONNECTION_KEEP_ALIVE +}; + +/* + * This is totally opaque to code using the library. It's exported as a + * forward-reference pointer-only declaration; the user can use the pointer with + * other APIs to get information out of it. + */ + +#if defined(LWS_PLAT_FREERTOS) +typedef uint16_t ah_data_idx_t; +#else +typedef uint32_t ah_data_idx_t; +#endif + +struct lws_fragments { + ah_data_idx_t offset; + uint16_t len; + uint8_t nfrag; /* which ah->frag[] continues this content, or 0 */ + uint8_t flags; /* only http2 cares */ +}; + +#if defined(LWS_WITH_RANGES) +enum range_states { + LWSRS_NO_ACTIVE_RANGE, + LWSRS_BYTES_EQ, + LWSRS_FIRST, + LWSRS_STARTING, + LWSRS_ENDING, + LWSRS_COMPLETED, + LWSRS_SYNTAX, +}; + +struct lws_range_parsing { + unsigned long long start, end, extent, agg, budget; + const char buf[128]; + int pos; + enum range_states state; + char start_valid, end_valid, ctr, count_ranges, did_try, inside, send_ctr; +}; + +int +lws_ranges_init(struct lws *wsi, struct lws_range_parsing *rp, + unsigned long long extent); +int +lws_ranges_next(struct lws_range_parsing *rp); +void +lws_ranges_reset(struct lws_range_parsing *rp); +#endif + +/* + * these are assigned from a pool held in the context. + * Both client and server mode uses them for http header analysis + */ + +struct allocated_headers { + struct allocated_headers *next; /* linked list */ + struct lws *wsi; /* owner */ + char *data; /* prepared by context init to point to dedicated storage */ + ah_data_idx_t data_length; + /* + * the randomly ordered fragments, indexed by frag_index and + * lws_fragments->nfrag for continuation. + */ + struct lws_fragments frags[WSI_TOKEN_COUNT]; + time_t assigned; + /* + * for each recognized token, frag_index says which frag[] his data + * starts in (0 means the token did not appear) + * the actual header data gets dumped as it comes in, into data[] + */ + uint8_t frag_index[WSI_TOKEN_COUNT]; + +#if defined(LWS_WITH_CLIENT) + char initial_handshake_hash_base64[30]; +#endif + int hdr_token_idx; + + ah_data_idx_t pos; + ah_data_idx_t http_response; + ah_data_idx_t current_token_limit; + ah_data_idx_t unk_pos; /* to undo speculative unknown header */ + +#if defined(LWS_WITH_CUSTOM_HEADERS) + ah_data_idx_t unk_value_pos; + + ah_data_idx_t unk_ll_head; + ah_data_idx_t unk_ll_tail; +#endif + + int16_t lextable_pos; + + uint8_t in_use; + uint8_t nfrag; + char /*enum uri_path_states */ ups; + char /*enum uri_esc_states */ ues; + + char esc_stash; + char post_literal_equal; + uint8_t /* enum lws_token_indexes */ parser_state; +}; + + + +#if defined(LWS_WITH_HUBBUB) +struct lws_rewrite { + hubbub_parser *parser; + hubbub_parser_optparams params; + const char *from, *to; + int from_len, to_len; + unsigned char *p, *end; + struct lws *wsi; +}; +static LWS_INLINE int hstrcmp(hubbub_string *s, const char *p, int len) +{ + if ((int)s->len != len) + return 1; + + return strncmp((const char *)s->ptr, p, len); +} +typedef hubbub_error (*hubbub_callback_t)(const hubbub_token *token, void *pw); +LWS_EXTERN struct lws_rewrite * +lws_rewrite_create(struct lws *wsi, hubbub_callback_t cb, const char *from, const char *to); +LWS_EXTERN void +lws_rewrite_destroy(struct lws_rewrite *r); +LWS_EXTERN int +lws_rewrite_parse(struct lws_rewrite *r, const unsigned char *in, int in_len); +#endif + +struct lws_pt_role_http { + struct allocated_headers *ah_list; + struct lws *ah_wait_list; +#ifdef LWS_WITH_CGI + struct lws_cgi *cgi_list; +#endif + int ah_wait_list_length; + uint32_t ah_pool_length; + + int ah_count_in_use; +}; + +struct lws_peer_role_http { + uint32_t count_ah; + uint32_t total_ah; +}; + +struct lws_vhost_role_http { +#if defined(LWS_CLIENT_HTTP_PROXYING) + char http_proxy_address[128]; +#endif + const struct lws_http_mount *mount_list; + const char *error_document_404; +#if defined(LWS_CLIENT_HTTP_PROXYING) + unsigned int http_proxy_port; +#endif +}; + +#ifdef LWS_WITH_ACCESS_LOG +struct lws_access_log { + char *header_log; + char *user_agent; + char *referrer; + unsigned long sent; + int response; +}; +#endif + +#define LWS_HTTP_CHUNK_HDR_MAX_SIZE (6 + 2) /* 6 hex digits and then CRLF */ +#define LWS_HTTP_CHUNK_TRL_MAX_SIZE (2 + 5) /* CRLF, then maybe 0 CRLF CRLF */ + +struct _lws_http_mode_related { + struct lws *new_wsi_list; + + unsigned char *pending_return_headers; + size_t pending_return_headers_len; + size_t prh_content_length; + +#if defined(LWS_WITH_HTTP_PROXY) + struct lws_rewrite *rw; + struct lws_buflist *buflist_post_body; +#endif + struct allocated_headers *ah; + struct lws *ah_wait_list; + + unsigned long writeable_len; + +#if defined(LWS_WITH_FILE_OPS) + lws_filepos_t filepos; + lws_filepos_t filelen; + lws_fop_fd_t fop_fd; +#endif +#if defined(LWS_WITH_CLIENT) + char multipart_boundary[16]; +#endif +#if defined(LWS_WITH_RANGES) + struct lws_range_parsing range; + char multipart_content_type[64]; +#endif + +#ifdef LWS_WITH_ACCESS_LOG + struct lws_access_log access_log; +#endif +#ifdef LWS_WITH_CGI + struct lws_cgi *cgi; /* wsi being cgi master have one of these */ +#endif +#if defined(LWS_WITH_HTTP_STREAM_COMPRESSION) + struct lws_compression_support *lcs; + lws_comp_ctx_t comp_ctx; + unsigned char comp_accept_mask; +#endif + + enum http_version request_version; + enum http_conn_type conn_type; + lws_filepos_t tx_content_length; + lws_filepos_t tx_content_remain; + lws_filepos_t rx_content_length; + lws_filepos_t rx_content_remain; + +#if defined(LWS_WITH_HTTP_PROXY) + unsigned int perform_rewrite:1; + unsigned int proxy_clientside:1; + unsigned int proxy_parent_chunked:1; +#endif + unsigned int deferred_transaction_completed:1; + unsigned int content_length_explicitly_zero:1; + unsigned int content_length_given:1; + unsigned int did_stream_close:1; + unsigned int multipart:1; + unsigned int cgi_transaction_complete:1; + unsigned int multipart_issue_boundary:1; +}; + + +#if defined(LWS_WITH_CLIENT) +enum lws_chunk_parser { + ELCP_HEX, + ELCP_CR, + ELCP_CONTENT, + ELCP_POST_CR, + ELCP_POST_LF, + ELCP_TRAILER_CR, + ELCP_TRAILER_LF +}; +#endif + +enum lws_parse_urldecode_results { + LPUR_CONTINUE, + LPUR_SWALLOW, + LPUR_FORBID, + LPUR_EXCESSIVE, +}; + +enum lws_check_basic_auth_results { + LCBA_CONTINUE, + LCBA_FAILED_AUTH, + LCBA_END_TRANSACTION, +}; + +enum lws_check_basic_auth_results +lws_check_basic_auth(struct lws *wsi, const char *basic_auth_login_file, unsigned int auth_mode); + +int +lws_unauthorised_basic_auth(struct lws *wsi); + +int +lws_read_h1(struct lws *wsi, unsigned char *buf, lws_filepos_t len); + +void +_lws_header_table_reset(struct allocated_headers *ah); + +LWS_EXTERN int +_lws_destroy_ah(struct lws_context_per_thread *pt, struct allocated_headers *ah); + +int +lws_http_proxy_start(struct lws *wsi, const struct lws_http_mount *hit, + char *uri_ptr, char ws); + +void +lws_sul_http_ah_lifecheck(lws_sorted_usec_list_t *sul); + +uint8_t * +lws_http_multipart_headers(struct lws *wsi, uint8_t *p); + +enum { + CCTLS_RETURN_ERROR = -1, + CCTLS_RETURN_DONE = 0, + CCTLS_RETURN_RETRY = 1, +}; + +int +lws_client_create_tls(struct lws *wsi, const char **pcce, int do_c1); diff -Nru libwebsockets-3.2.1/lib/roles/http/server/access-log.c libwebsockets-4.1.6/lib/roles/http/server/access-log.c --- libwebsockets-3.2.1/lib/roles/http/server/access-log.c 2019-12-18 14:45:31.000000000 +0000 +++ libwebsockets-4.1.6/lib/roles/http/server/access-log.c 2020-12-01 17:40:26.000000000 +0000 @@ -1,25 +1,28 @@ /* - * libwebsockets - server access log handling + * libwebsockets - small server side websockets and web server implementation * - * Copyright (C) 2010-2017 Andy Green + * Copyright (C) 2010 - 2019 Andy Green * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation: - * version 2.1 of the License. - * - * This library is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with this library; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, - * MA 02110-1301 USA + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to + * deal in the Software without restriction, including without limitation the + * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or + * sell copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS + * IN THE SOFTWARE. */ -#include "core/private.h" +#include "private-lib-core.h" /* * Produce Apache-compatible log string for wsi, like this: @@ -41,21 +44,17 @@ lws_prepare_access_log_info(struct lws *wsi, char *uri_ptr, int uri_len, int meth) { char da[64], uri[256]; - const char *pa, *me; time_t t = time(NULL); + struct lws *nwsi; + const char *me; int l = 256, m; -#ifdef LWS_WITH_IPV6 - char ads[INET6_ADDRSTRLEN]; -#else - char ads[INET_ADDRSTRLEN]; -#endif struct tm *tmp; - if (!wsi->vhost) + if (!wsi->a.vhost) return; /* only worry about preparing it if we store it */ - if (wsi->vhost->log_fd == (int)LWS_INVALID_FILE) + if (wsi->a.vhost->log_fd == (int)LWS_INVALID_FILE) return; if (wsi->access_log_pending) @@ -71,14 +70,13 @@ else strcpy(da, "01/Jan/1970:00:00:00 +0000"); - pa = lws_get_peer_simple(wsi, ads, sizeof(ads)); - if (!pa) - pa = "(unknown)"; - - if (wsi->http2_substream) +#if defined(LWS_ROLE_H2) + if (wsi->mux_substream) me = lws_hdr_simple_ptr(wsi, WSI_TOKEN_HTTP_COLON_METHOD); else +#endif me = method_names[meth]; + if (!me) me = "(null)"; @@ -89,9 +87,12 @@ strncpy(uri, uri_ptr, m); uri[m] = '\0'; + nwsi = lws_get_network_wsi(wsi); + lws_snprintf(wsi->http.access_log.header_log, l, "%s - - [%s] \"%s %s %s\"", - pa, da, me, uri, hver[wsi->http.request_version]); + nwsi->simple_ip[0] ? nwsi->simple_ip : "unknown", da, me, uri, + hver[wsi->http.request_version]); //lwsl_notice("%s\n", wsi->http.access_log.header_log); @@ -140,10 +141,10 @@ *p1 = wsi->http.access_log.referrer; int l; - if (!wsi->vhost) + if (!wsi->a.vhost) return 0; - if (wsi->vhost->log_fd == (int)LWS_INVALID_FILE) + if (wsi->a.vhost->log_fd == (int)LWS_INVALID_FILE) return 0; if (!wsi->access_log_pending) @@ -175,7 +176,7 @@ ass[sizeof(ass) - 1] = '\0'; - if (write(wsi->vhost->log_fd, ass, l) != l) + if (write(wsi->a.vhost->log_fd, ass, l) != l) lwsl_err("Failed to write log\n"); if (wsi->http.access_log.header_log) { diff -Nru libwebsockets-3.2.1/lib/roles/http/server/fops-zip.c libwebsockets-4.1.6/lib/roles/http/server/fops-zip.c --- libwebsockets-3.2.1/lib/roles/http/server/fops-zip.c 2019-12-18 14:45:31.000000000 +0000 +++ libwebsockets-4.1.6/lib/roles/http/server/fops-zip.c 2020-12-01 17:40:26.000000000 +0000 @@ -30,28 +30,10 @@ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE * SOFTWARE. * - * - * lws rewrite: - * - * Copyright (C) 2017 Andy Green - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation: - * version 2.1 of the License. - * - * This library is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with this library; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, - * MA 02110-1301 USA + * Somewhat rewritten by AG */ -#include "core/private.h" +#include "private-lib-core.h" #if defined(LWS_WITH_MINIZ) #include @@ -162,6 +144,9 @@ LWS_FZ_ERR_SEEK_COMPRESSED, }; +#define eff_size(_priv) (_priv->hdr.method == ZIP_COMPRESSION_METHOD_STORE ? \ + _priv->hdr.uncomp_size : _priv->hdr.comp_size) + static uint16_t get_u16(void *p) { @@ -359,7 +344,7 @@ priv->zip_fop_fd = fops->LWS_FOP_OPEN(fops, rp, NULL, &local_flags); if (!priv->zip_fop_fd) { - lwsl_err("unable to open zip %s\n", rp); + lwsl_err("%s: unable to open zip %s\n", __func__, rp); goto bail1; } @@ -544,11 +529,8 @@ spin: if (!priv->inflate.avail_in) { rlen = sizeof(priv->rbuf); - if (rlen > priv->hdr.comp_size - - (cur - priv->content_start)) - rlen = priv->hdr.comp_size - - (priv->hdr.comp_size - - priv->content_start); + if (rlen > eff_size(priv) - (cur - priv->content_start)) + rlen = eff_size(priv) - (cur - priv->content_start); if (priv->zip_fop_fd->fops->LWS_FOP_READ( priv->zip_fop_fd, &ramount, priv->rbuf, @@ -650,14 +632,15 @@ lwsl_info("%s: store\n", __func__); - if (len > priv->hdr.uncomp_size - (cur - priv->content_start)) - len = priv->hdr.comp_size - (priv->hdr.comp_size - - priv->content_start); + if (len > eff_size(priv) - cur) + len = eff_size(priv) - cur; if (priv->zip_fop_fd->fops->LWS_FOP_READ(priv->zip_fop_fd, amount, buf, len)) return LWS_FZ_ERR_READ_CONTENT; + fd->pos += *amount; + return 0; } diff -Nru libwebsockets-3.2.1/lib/roles/http/server/lejp-conf.c libwebsockets-4.1.6/lib/roles/http/server/lejp-conf.c --- libwebsockets-3.2.1/lib/roles/http/server/lejp-conf.c 2019-12-18 14:45:31.000000000 +0000 +++ libwebsockets-4.1.6/lib/roles/http/server/lejp-conf.c 2020-12-01 17:40:26.000000000 +0000 @@ -1,25 +1,28 @@ /* - * libwebsockets web server application + * libwebsockets - small server side websockets and web server implementation * - * Copyright (C) 2010-2018 Andy Green + * Copyright (C) 2010 - 2019 Andy Green * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation: - * version 2.1 of the License. + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to + * deal in the Software without restriction, including without limitation the + * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or + * sell copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: * - * This library is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. * - * You should have received a copy of the GNU Lesser General Public - * License along with this library; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, - * MA 02110-1301 USA + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS + * IN THE SOFTWARE. */ -#include "core/private.h" +#include "private-lib-core.h" #ifndef _WIN32 /* this is needed for Travis CI */ @@ -37,11 +40,14 @@ "global.init-ssl", "global.server-string", "global.plugin-dir", - "global.ws-pingpong-secs", + "global.ws-pingpong-secs", /* deprecated */ "global.timeout-secs", "global.reject-service-keywords[].*", "global.reject-service-keywords[]", "global.default-alpn", + "global.ip-limit-ah", + "global.ip-limit-wsi", + "global.rlimit-nofile", }; enum lejp_global_paths { @@ -58,6 +64,9 @@ LWJPGP_REJECT_SERVICE_KEYWORDS_NAME, LWJPGP_REJECT_SERVICE_KEYWORDS, LWJPGP_DEFAULT_ALPN, + LWJPGP_IP_LIMIT_AH, + LWJPGP_IP_LIMIT_WSI, + LWJPGP_FD_LIMIT_PT, }; static const char * const paths_vhosts[] = { @@ -125,6 +134,7 @@ "vhosts[].allow-http-on-https", "vhosts[].disable-no-protocol-ws-upgrades", + "vhosts[].h2-half-closed-long-poll", }; enum lejp_vhost_paths { @@ -192,6 +202,7 @@ LEJPVP_FLAG_ALLOW_HTTP_ON_HTTPS, LEJPVP_FLAG_DISABLE_NO_PROTOCOL_WS_UPGRADES, + LEJPVP_FLAG_H2_HALF_CLOSED_LONG_POLL, }; #define MAX_PLUGIN_DIRS 10 @@ -247,7 +258,7 @@ } static void -set_reset_flag(unsigned int *p, const char *state, unsigned int flag) +set_reset_flag(uint64_t *p, const char *state, uint64_t flag) { if (arg_to_bool(state)) *p |= flag; @@ -305,7 +316,9 @@ a->info->options |= LWS_SERVER_OPTION_DO_SSL_GLOBAL_INIT; return 0; case LEJPGP_SERVER_STRING: +#if defined(LWS_WITH_SERVER) a->info->server_string = a->p; +#endif break; case LEJPGP_PLUGIN_DIR: if (a->count_plugin_dirs == MAX_PLUGIN_DIRS - 1) { @@ -315,17 +328,32 @@ a->plugin_dirs[a->count_plugin_dirs++] = a->p; break; - case LWJPGP_PINGPONG_SECS: - a->info->ws_ping_pong_interval = atoi(ctx->buf); + case LWJPGP_PINGPONG_SECS: /* deprecated */ return 0; case LWJPGP_TIMEOUT_SECS: a->info->timeout_secs = atoi(ctx->buf); return 0; +#if defined(LWS_WITH_TLS) case LWJPGP_DEFAULT_ALPN: a->info->alpn = a->p; break; +#endif + +#if defined(LWS_WITH_PEER_LIMITS) + case LWJPGP_IP_LIMIT_AH: + a->info->ip_limit_ah = atoi(ctx->buf); + return 0; + + case LWJPGP_IP_LIMIT_WSI: + a->info->ip_limit_wsi = atoi(ctx->buf); + return 0; +#endif + + case LWJPGP_FD_LIMIT_PT: + a->info->rlimit_nofile = atoi(ctx->buf); + return 0; default: return 0; @@ -355,7 +383,9 @@ if (reason == LEJPCB_OBJECT_START && ctx->path_match == LEJPVP + 1) { uint32_t i[4]; +#if defined(LWS_WITH_SERVER) const char *ss; +#endif /* set the defaults for this vhost */ a->reject_ws_with_no_protocol = 0; @@ -373,22 +403,27 @@ LWS_SERVER_OPTION_LIBEVENT | LWS_SERVER_OPTION_LIBEV ); +#if defined(LWS_WITH_SERVER) ss = a->info->server_string; - i[2] = a->info->ws_ping_pong_interval; +#endif i[3] = a->info->timeout_secs; memset(a->info, 0, sizeof(*a->info)); a->info->count_threads = i[0]; a->info->options = i[1]; +#if defined(LWS_WITH_SERVER) a->info->server_string = ss; - a->info->ws_ping_pong_interval = i[2]; +#endif a->info->timeout_secs = i[3]; a->info->protocols = a->protocols; a->info->pprotocols = a->pprotocols; +#if defined(LWS_ROLE_WS) a->info->extensions = a->extensions; +#endif #if defined(LWS_WITH_TLS) +#if defined(LWS_WITH_CLIENT) a->info->client_ssl_cipher_list = "ECDHE-ECDSA-AES256-GCM-SHA384:" "ECDHE-RSA-AES256-GCM-SHA384:" "DHE-RSA-AES256-GCM-SHA384:" @@ -403,6 +438,7 @@ "!AES256-GCM-SHA384:" "!AES256-SHA256"; #endif +#if defined(LWS_WITH_SERVER) a->info->ssl_cipher_list = "ECDHE-ECDSA-AES256-GCM-SHA384:" "ECDHE-RSA-AES256-GCM-SHA384:" "DHE-RSA-AES256-GCM-SHA384:" @@ -416,6 +452,8 @@ "!DHE-RSA-AES256-SHA256:" "!AES256-GCM-SHA384:" "!AES256-SHA256"; +#endif +#endif a->info->keepalive_timeout = 5; } @@ -501,7 +539,7 @@ vhost->default_protocol_index = 255; } -#if defined(LWS_WITH_TLS) +#if defined(LWS_WITH_TLS) && defined(LWS_WITH_CLIENT) if (a->enable_client_ssl) { const char *cert_filepath = a->info->client_ssl_cert_filepath; @@ -604,6 +642,7 @@ else a->info->options &= ~(LWS_SERVER_OPTION_STS); return 0; +#if defined(LWS_WITH_TLS) case LEJPVP_HOST_SSL_KEY: a->info->ssl_private_key_filepath = a->p; break; @@ -613,6 +652,7 @@ case LEJPVP_HOST_SSL_CA: a->info->ssl_ca_filepath = a->p; break; +#endif case LEJPVP_ACCESS_LOG: a->info->log_filepath = a->p; break; @@ -646,7 +686,9 @@ a->m.cache_intermediaries = arg_to_bool(ctx->buf);; return 0; case LEJPVP_MOUNT_BASIC_AUTH: +#if defined(LWS_WITH_HTTP_BASIC_AUTH) a->m.basic_auth_login_file = a->p; +#endif break; case LEJPVP_CGI_TIMEOUT: a->m.cgi_timeout = atoi(ctx->buf); @@ -655,23 +697,25 @@ a->info->keepalive_timeout = atoi(ctx->buf); return 0; #if defined(LWS_WITH_TLS) +#if defined(LWS_WITH_CLIENT) case LEJPVP_CLIENT_CIPHERS: a->info->client_ssl_cipher_list = a->p; break; + case LEJPVP_CLIENT_TLS13_CIPHERS: + a->info->client_tls_1_3_plus_cipher_list = a->p; + break; #endif + case LEJPVP_CIPHERS: a->info->ssl_cipher_list = a->p; break; case LEJPVP_TLS13_CIPHERS: a->info->tls1_3_plus_cipher_list = a->p; break; - case LEJPVP_CLIENT_TLS13_CIPHERS: - a->info->client_tls_1_3_plus_cipher_list = a->p; - break; - case LEJPVP_ECDH_CURVE: a->info->ecdh_curve = a->p; break; +#endif case LEJPVP_PMO: case LEJPVP_CGI_ENV: mp_cgienv = lwsws_align(a); @@ -741,7 +785,7 @@ case LEJPVP_ENABLE_CLIENT_SSL: a->enable_client_ssl = arg_to_bool(ctx->buf); return 0; -#if defined(LWS_WITH_TLS) +#if defined(LWS_WITH_TLS) && defined(LWS_WITH_CLIENT) case LEJPVP_CLIENT_SSL_KEY: a->info->client_ssl_private_key_filepath = a->p; break; @@ -789,6 +833,7 @@ a->info->error_document_404 = a->p; break; +#if defined(LWS_WITH_TLS) case LEJPVP_SSL_OPTION_SET: a->info->ssl_options_set |= atol(ctx->buf); return 0; @@ -796,16 +841,19 @@ a->info->ssl_options_clear |= atol(ctx->buf); return 0; +#if defined(LWS_WITH_CLIENT) case LEJPVP_SSL_CLIENT_OPTION_SET: a->info->ssl_client_options_set |= atol(ctx->buf); return 0; case LEJPVP_SSL_CLIENT_OPTION_CLEAR: a->info->ssl_client_options_clear |= atol(ctx->buf); return 0; +#endif case LEJPVP_ALPN: a->info->alpn = a->p; break; +#endif case LEJPVP_LISTEN_ACCEPT_ROLE: a->info->listen_accept_role = a->p; @@ -841,6 +889,11 @@ a->reject_ws_with_no_protocol = 1; return 0; + case LEJPVP_FLAG_H2_HALF_CLOSED_LONG_POLL: + set_reset_flag(&a->info->options, ctx->buf, + LWS_SERVER_OPTION_VH_H2_HALF_CLOSED_LONG_POLL); + return 0; + default: return 0; } @@ -892,7 +945,7 @@ if (!n) break; - m = (int)(signed char)lejp_parse(&ctx, buf, n); + m = lejp_parse(&ctx, buf, n); } while (m == LEJP_CONTINUE); close(fd); @@ -937,7 +990,9 @@ { struct lws_dir_args da; struct jpargs a; +#if defined(LWS_WITH_PLUGINS) const char * const *old = info->plugin_dirs; +#endif char dd[128]; memset(&a, 0, sizeof(a)); @@ -948,16 +1003,20 @@ a.valid = 0; lwsws_align(&a); +#if defined(LWS_WITH_PLUGINS) info->plugin_dirs = (void *)a.p; +#endif a.plugin_dirs = (void *)a.p; /* writeable version */ a.p += MAX_PLUGIN_DIRS * sizeof(void *); +#if defined(LWS_WITH_PLUGINS) /* copy any default paths */ while (old && *old) { a.plugin_dirs[a.count_plugin_dirs++] = *old; old++; } +#endif lws_snprintf(dd, sizeof(dd) - 1, "%s/conf", d); if (lwsws_get_config(&a, dd, paths_global, @@ -999,7 +1058,9 @@ a.context = context; a.protocols = info->protocols; a.pprotocols = info->pprotocols; +#if defined(LWS_ROLE_WS) a.extensions = info->extensions; +#endif lws_snprintf(dd, sizeof(dd) - 1, "%s/conf", d); if (lwsws_get_config(&a, dd, paths_vhosts, diff -Nru libwebsockets-3.2.1/lib/roles/http/server/lws-spa.c libwebsockets-4.1.6/lib/roles/http/server/lws-spa.c --- libwebsockets-3.2.1/lib/roles/http/server/lws-spa.c 2019-12-18 14:45:31.000000000 +0000 +++ libwebsockets-4.1.6/lib/roles/http/server/lws-spa.c 2020-12-01 17:40:26.000000000 +0000 @@ -1,25 +1,28 @@ /* - * libwebsockets - Stateful urldecode for POST + * libwebsockets - small server side websockets and web server implementation * - * Copyright (C) 2010-2019 Andy Green + * Copyright (C) 2010 - 2019 Andy Green * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation: - * version 2.1 of the License. + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to + * deal in the Software without restriction, including without limitation the + * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or + * sell copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: * - * This library is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. * - * You should have received a copy of the GNU Lesser General Public - * License along with this library; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, - * MA 02110-1301 USA + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS + * IN THE SOFTWARE. */ -#include "core/private.h" +#include "private-lib-core.h" #define LWS_MAX_ELEM_NAME 32 @@ -39,10 +42,13 @@ MT_COMPLETED, }; -static const char * const mp_hdr[] = { - "content-disposition: ", - "content-type: ", - "\x0d\x0a" +static struct mp_hdr { + const char * const hdr; + uint8_t hdr_len; +} mp_hdrs[] = { + { "content-disposition: ", 21 }, + { "content-type: ", 14 }, + { "\x0d\x0a", 2 } }; struct lws_spa; @@ -66,10 +72,12 @@ int mp; int sum; - unsigned int multipart_form_data:1; - unsigned int inside_quote:1; - unsigned int subname:1; - unsigned int boundary_real_crlf:1; + uint8_t matchable; + + uint8_t multipart_form_data:1; + uint8_t inside_quote:1; + uint8_t subname:1; + uint8_t boundary_real_crlf:1; enum urldecode_stateful state; @@ -118,7 +126,8 @@ /* multipart/form-data; * boundary=----WebKitFormBoundarycc7YgAPEIHvgE9Bf */ - if (!strncmp(buf, "multipart/form-data", 19)) { + if (!strncmp(buf, "multipart/form-data", 19) || + !strncmp(buf, "multipart/related", 17)) { s->multipart_form_data = 1; s->state = MT_LOOK_BOUND_IN; s->mp = 2; @@ -129,13 +138,14 @@ s->mime_boundary[m++] = '\x0a'; s->mime_boundary[m++] = '-'; s->mime_boundary[m++] = '-'; + if (*p == '\"') + p++; while (m < (int)sizeof(s->mime_boundary) - 1 && - *p && *p != ' ') + *p && *p != ' ' && *p != ';' && *p != '\"') s->mime_boundary[m++] = *p++; - s->mime_boundary[m] = '\0'; - lwsl_info("boundary '%s'\n", s->mime_boundary); + // lwsl_notice("boundary '%s'\n", s->mime_boundary); } } } @@ -147,8 +157,8 @@ lws_urldecode_s_process(struct lws_urldecode_stateful *s, const char *in, int len) { - int n, m, hit = 0; - char c, was_end = 0; + int n, hit; + char c; while (len--) { if (s->pos == s->out_len - s->mp - 1) { @@ -156,9 +166,9 @@ LWS_UFS_CONTENT)) return -1; - was_end = s->pos; s->pos = 0; } + switch (s->state) { /* states for url arg style */ @@ -183,7 +193,8 @@ continue; } if (s->pos >= (int)sizeof(s->name) - 1) { - lwsl_notice("Name too long\n"); + lwsl_hexdump_notice(s->name, s->pos); + lwsl_notice("Name too long...\n"); return -1; } s->name[s->pos++] = *in++; @@ -244,11 +255,10 @@ s->mp = 0; s->state = MT_IGNORE1; - if (s->pos || was_end) - if (s->output(s->data, s->name, + if (s->output(s->data, s->name, &s->out, s->pos, LWS_UFS_FINAL_CONTENT)) - return -1; + return -1; s->pos = 0; @@ -278,29 +288,52 @@ break; case MT_HNAME: - m = 0; c =*in; if (c >= 'A' && c <= 'Z') c += 'a' - 'A'; - for (n = 0; n < (int)LWS_ARRAY_SIZE(mp_hdr); n++) - if (c == mp_hdr[n][s->mp]) { - m++; + if (!s->mp) + /* initially, any of them might match */ + s->matchable = (1 << LWS_ARRAY_SIZE(mp_hdrs)) - 1; + + hit = -1; + for (n = 0; n < (int)LWS_ARRAY_SIZE(mp_hdrs); n++) { + + if (!(s->matchable & (1 << n))) + continue; + /* this guy is still in contention... */ + + if (s->mp >= mp_hdrs[n].hdr_len) { + /* he went past the end of it */ + s->matchable &= ~(1 << n); + continue; + } + + if (c != mp_hdrs[n].hdr[s->mp]) { + /* mismatched a char */ + s->matchable &= ~(1 << n); + continue; + } + + if (s->mp + 1 == mp_hdrs[n].hdr_len) { + /* we have a winner... */ hit = n; + break; } + } + in++; - if (!m) { - /* Unknown header - ignore it */ + if (hit == -1 && !s->matchable) { + /* We ruled them all out */ s->state = MT_IGNORE1; s->mp = 0; continue; } s->mp++; - if (m != 1) + if (hit < 0) continue; - if (mp_hdr[hit][s->mp]) - continue; + /* we matched the one in hit */ s->mp = 0; s->temp[0] = '\0'; @@ -565,7 +598,7 @@ goto bail5; } - lwsl_info("%s: Created SPA %p\n", __func__, spa); + // lwsl_notice("%s: Created SPA %p\n", __func__, spa); return spa; diff -Nru libwebsockets-3.2.1/lib/roles/http/server/parsers.c libwebsockets-4.1.6/lib/roles/http/server/parsers.c --- libwebsockets-3.2.1/lib/roles/http/server/parsers.c 2019-12-18 14:45:31.000000000 +0000 +++ libwebsockets-4.1.6/lib/roles/http/server/parsers.c 1970-01-01 00:00:00.000000000 +0000 @@ -1,1420 +0,0 @@ -/* - * libwebsockets - small server side websockets and web server implementation - * - * Copyright (C) 2010-2018 Andy Green - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation: - * version 2.1 of the License. - * - * This library is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with this library; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, - * MA 02110-1301 USA - */ - -#include "core/private.h" - -static const unsigned char lextable[] = { -#if defined(LWS_AMAZON_RTOS) || defined(LWS_AMAZON_LINUX) - #include "roles/http/lextable.h" -#else - #include "../lextable.h" -#endif -}; - -#define FAIL_CHAR 0x08 - -#if defined(LWS_WITH_CUSTOM_HEADERS) - -#define UHO_NLEN 0 -#define UHO_VLEN 2 -#define UHO_LL 4 -#define UHO_NAME 8 - -static uint16_t -lws_un16be_get(const void *_p) -{ - const uint8_t *p = _p; - - return ((uint16_t)p[0] << 8) | p[1]; -} - -static void -lws_un16be_set(void *_p, uint16_t v) -{ - uint8_t *p = _p; - - *p++ = (uint8_t)(v >> 8); - *p++ = (uint8_t)v; -} - -static uint32_t -lws_un32be_get(const void *_p) -{ - const uint8_t *p = _p; - - return (uint32_t)((p[0] << 24) | (p[1] << 16) | (p[2] << 8) | p[3]); -} - -static void -lws_un32be_set(void *_p, uint32_t v) -{ - uint8_t *p = _p; - - *p++ = (uint8_t)(v >> 24); - *p++ = (uint8_t)(v >> 16); - *p++ = (uint8_t)(v >> 8); - *p = (uint8_t)v; -} -#endif - -static struct allocated_headers * -_lws_create_ah(struct lws_context_per_thread *pt, ah_data_idx_t data_size) -{ - struct allocated_headers *ah = lws_zalloc(sizeof(*ah), "ah struct"); - - if (!ah) - return NULL; - - ah->data = lws_malloc(data_size, "ah data"); - if (!ah->data) { - lws_free(ah); - - return NULL; - } - ah->next = pt->http.ah_list; - pt->http.ah_list = ah; - ah->data_length = data_size; - pt->http.ah_pool_length++; - - lwsl_info("%s: created ah %p (size %d): pool length %ld\n", __func__, - ah, (int)data_size, (unsigned long)pt->http.ah_pool_length); - - return ah; -} - -int -_lws_destroy_ah(struct lws_context_per_thread *pt, struct allocated_headers *ah) -{ - lws_start_foreach_llp(struct allocated_headers **, a, pt->http.ah_list) { - if ((*a) == ah) { - *a = ah->next; - pt->http.ah_pool_length--; - lwsl_info("%s: freed ah %p : pool length %ld\n", - __func__, ah, - (unsigned long)pt->http.ah_pool_length); - if (ah->data) - lws_free(ah->data); - lws_free(ah); - - return 0; - } - } lws_end_foreach_llp(a, next); - - return 1; -} - -void -_lws_header_table_reset(struct allocated_headers *ah) -{ - /* init the ah to reflect no headers or data have appeared yet */ - memset(ah->frag_index, 0, sizeof(ah->frag_index)); - memset(ah->frags, 0, sizeof(ah->frags)); - ah->nfrag = 0; - ah->pos = 0; - ah->http_response = 0; - ah->parser_state = WSI_TOKEN_NAME_PART; - ah->lextable_pos = 0; -#if defined(LWS_WITH_CUSTOM_HEADERS) - ah->unk_pos = 0; - ah->unk_ll_head = 0; - ah->unk_ll_tail = 0; -#endif -} - -// doesn't scrub the ah rxbuffer by default, parent must do if needed - -void -__lws_header_table_reset(struct lws *wsi, int autoservice) -{ - struct allocated_headers *ah = wsi->http.ah; - struct lws_context_per_thread *pt; - struct lws_pollfd *pfd; - - /* if we have the idea we're resetting 'our' ah, must be bound to one */ - assert(ah); - /* ah also concurs with ownership */ - assert(ah->wsi == wsi); - - _lws_header_table_reset(ah); - - /* since we will restart the ah, our new headers are not completed */ - wsi->hdr_parsing_completed = 0; - - /* while we hold the ah, keep a timeout on the wsi */ - __lws_set_timeout(wsi, PENDING_TIMEOUT_HOLDING_AH, - wsi->vhost->timeout_secs_ah_idle); - - time(&ah->assigned); - - if (wsi->position_in_fds_table != LWS_NO_FDS_POS && - lws_buflist_next_segment_len(&wsi->buflist, NULL) && - autoservice) { - lwsl_debug("%s: service on readbuf ah\n", __func__); - - pt = &wsi->context->pt[(int)wsi->tsi]; - /* - * Unlike a normal connect, we have the headers already - * (or the first part of them anyway) - */ - pfd = &pt->fds[wsi->position_in_fds_table]; - pfd->revents |= LWS_POLLIN; - lwsl_err("%s: calling service\n", __func__); - lws_service_fd_tsi(wsi->context, pfd, wsi->tsi); - } -} - -void -lws_header_table_reset(struct lws *wsi, int autoservice) -{ - struct lws_context_per_thread *pt = &wsi->context->pt[(int)wsi->tsi]; - - lws_pt_lock(pt, __func__); - - __lws_header_table_reset(wsi, autoservice); - - lws_pt_unlock(pt); -} - -static void -_lws_header_ensure_we_are_on_waiting_list(struct lws *wsi) -{ - struct lws_context_per_thread *pt = &wsi->context->pt[(int)wsi->tsi]; - struct lws_pollargs pa; - struct lws **pwsi = &pt->http.ah_wait_list; - - while (*pwsi) { - if (*pwsi == wsi) - return; - pwsi = &(*pwsi)->http.ah_wait_list; - } - - lwsl_info("%s: wsi: %p\n", __func__, wsi); - wsi->http.ah_wait_list = pt->http.ah_wait_list; - pt->http.ah_wait_list = wsi; - pt->http.ah_wait_list_length++; - - /* we cannot accept input then */ - - _lws_change_pollfd(wsi, LWS_POLLIN, 0, &pa); -} - -static int -__lws_remove_from_ah_waiting_list(struct lws *wsi) -{ - struct lws_context_per_thread *pt = &wsi->context->pt[(int)wsi->tsi]; - struct lws **pwsi =&pt->http.ah_wait_list; - - while (*pwsi) { - if (*pwsi == wsi) { - lwsl_info("%s: wsi %p\n", __func__, wsi); - /* point prev guy to our next */ - *pwsi = wsi->http.ah_wait_list; - /* we shouldn't point anywhere now */ - wsi->http.ah_wait_list = NULL; - pt->http.ah_wait_list_length--; - - return 1; - } - pwsi = &(*pwsi)->http.ah_wait_list; - } - - return 0; -} - -int LWS_WARN_UNUSED_RESULT -lws_header_table_attach(struct lws *wsi, int autoservice) -{ - struct lws_context *context = wsi->context; - struct lws_context_per_thread *pt = &context->pt[(int)wsi->tsi]; - struct lws_pollargs pa; - int n; - - lwsl_info("%s: wsi %p: ah %p (tsi %d, count = %d) in\n", __func__, - (void *)wsi, (void *)wsi->http.ah, wsi->tsi, - pt->http.ah_count_in_use); - - if (!lwsi_role_http(wsi)) { - lwsl_err("%s: bad role %s\n", __func__, wsi->role_ops->name); - assert(0); - return -1; - } - - lws_pt_lock(pt, __func__); - - /* if we are already bound to one, just clear it down */ - if (wsi->http.ah) { - lwsl_info("%s: cleardown\n", __func__); - goto reset; - } - - n = pt->http.ah_count_in_use == context->max_http_header_pool; -#if defined(LWS_WITH_PEER_LIMITS) - if (!n) { - n = lws_peer_confirm_ah_attach_ok(context, wsi->peer); - if (n) - lws_stats_bump(pt, LWSSTATS_C_PEER_LIMIT_AH_DENIED, 1); - } -#endif - if (n) { - /* - * Pool is either all busy, or we don't want to give this - * particular guy an ah right now... - * - * Make sure we are on the waiting list, and return that we - * weren't able to provide the ah - */ - _lws_header_ensure_we_are_on_waiting_list(wsi); - - goto bail; - } - - __lws_remove_from_ah_waiting_list(wsi); - - wsi->http.ah = _lws_create_ah(pt, context->max_http_header_data); - if (!wsi->http.ah) { /* we could not create an ah */ - _lws_header_ensure_we_are_on_waiting_list(wsi); - - goto bail; - } - - wsi->http.ah->in_use = 1; - wsi->http.ah->wsi = wsi; /* mark our owner */ - pt->http.ah_count_in_use++; - -#if defined(LWS_WITH_PEER_LIMITS) && (defined(LWS_ROLE_H1) || \ - defined(LWS_ROLE_H2)) - lws_context_lock(context, "ah attach"); /* <========================= */ - if (wsi->peer) - wsi->peer->http.count_ah++; - lws_context_unlock(context); /* ====================================> */ -#endif - - _lws_change_pollfd(wsi, 0, LWS_POLLIN, &pa); - - lwsl_info("%s: did attach wsi %p: ah %p: count %d (on exit)\n", __func__, - (void *)wsi, (void *)wsi->http.ah, pt->http.ah_count_in_use); - -reset: - __lws_header_table_reset(wsi, autoservice); - - lws_pt_unlock(pt); - -#ifndef LWS_NO_CLIENT - if (lwsi_role_client(wsi) && lwsi_state(wsi) == LRS_UNCONNECTED) - if (!lws_http_client_connect_via_info2(wsi)) - /* our client connect has failed, the wsi - * has been closed - */ - return -1; -#endif - - return 0; - -bail: - lws_pt_unlock(pt); - - return 1; -} - -int __lws_header_table_detach(struct lws *wsi, int autoservice) -{ - struct lws_context *context = wsi->context; - struct allocated_headers *ah = wsi->http.ah; - struct lws_context_per_thread *pt = &context->pt[(int)wsi->tsi]; - struct lws_pollargs pa; - struct lws **pwsi, **pwsi_eligible; - time_t now; - - __lws_remove_from_ah_waiting_list(wsi); - - if (!ah) - return 0; - - lwsl_info("%s: wsi %p: ah %p (tsi=%d, count = %d)\n", __func__, - (void *)wsi, (void *)ah, wsi->tsi, - pt->http.ah_count_in_use); - - /* we did have an ah attached */ - time(&now); - if (ah->assigned && now - ah->assigned > 3) { - /* - * we're detaching the ah, but it was held an - * unreasonably long time - */ - lwsl_debug("%s: wsi %p: ah held %ds, role/state 0x%lx 0x%x," - "\n", __func__, wsi, (int)(now - ah->assigned), - (unsigned long)lwsi_role(wsi), lwsi_state(wsi)); - } - - ah->assigned = 0; - - /* if we think we're detaching one, there should be one in use */ - assert(pt->http.ah_count_in_use > 0); - /* and this specific one should have been in use */ - assert(ah->in_use); - memset(&wsi->http.ah, 0, sizeof(wsi->http.ah)); - -#if defined(LWS_WITH_PEER_LIMITS) - if (ah->wsi) - lws_peer_track_ah_detach(context, wsi->peer); -#endif - ah->wsi = NULL; /* no owner */ - - pwsi = &pt->http.ah_wait_list; - - /* oh there is nobody on the waiting list... leave the ah unattached */ - if (!*pwsi) - goto nobody_usable_waiting; - - /* - * at least one wsi on the same tsi is waiting, give it to oldest guy - * who is allowed to take it (if any) - */ - lwsl_info("pt wait list %p\n", *pwsi); - wsi = NULL; - pwsi_eligible = NULL; - - while (*pwsi) { -#if defined(LWS_WITH_PEER_LIMITS) - /* are we willing to give this guy an ah? */ - if (!lws_peer_confirm_ah_attach_ok(context, (*pwsi)->peer)) -#endif - { - wsi = *pwsi; - pwsi_eligible = pwsi; - } -#if defined(LWS_WITH_PEER_LIMITS) - else - if (!(*pwsi)->http.ah_wait_list) - lws_stats_bump(pt, - LWSSTATS_C_PEER_LIMIT_AH_DENIED, 1); -#endif - pwsi = &(*pwsi)->http.ah_wait_list; - } - - if (!wsi) /* everybody waiting already has too many ah... */ - goto nobody_usable_waiting; - - lwsl_info("%s: transferring ah to last eligible wsi in wait list " - "%p (wsistate 0x%lx)\n", __func__, wsi, - (unsigned long)wsi->wsistate); - - wsi->http.ah = ah; - ah->wsi = wsi; /* new owner */ - - __lws_header_table_reset(wsi, autoservice); -#if defined(LWS_WITH_PEER_LIMITS) && (defined(LWS_ROLE_H1) || \ - defined(LWS_ROLE_H2)) - lws_context_lock(context, "ah detach"); /* <========================= */ - if (wsi->peer) - wsi->peer->http.count_ah++; - lws_context_unlock(context); /* ====================================> */ -#endif - - /* clients acquire the ah and then insert themselves in fds table... */ - if (wsi->position_in_fds_table != LWS_NO_FDS_POS) { - lwsl_info("%s: Enabling %p POLLIN\n", __func__, wsi); - - /* he has been stuck waiting for an ah, but now his wait is - * over, let him progress */ - - _lws_change_pollfd(wsi, 0, LWS_POLLIN, &pa); - } - - /* point prev guy to next guy in list instead */ - *pwsi_eligible = wsi->http.ah_wait_list; - /* the guy who got one is out of the list */ - wsi->http.ah_wait_list = NULL; - pt->http.ah_wait_list_length--; - -#ifndef LWS_NO_CLIENT - if (lwsi_role_client(wsi) && lwsi_state(wsi) == LRS_UNCONNECTED) { - lws_pt_unlock(pt); - - if (!lws_http_client_connect_via_info2(wsi)) { - /* our client connect has failed, the wsi - * has been closed - */ - - return -1; - } - return 0; - } -#endif - - assert(!!pt->http.ah_wait_list_length == - !!(lws_intptr_t)pt->http.ah_wait_list); -bail: - lwsl_info("%s: wsi %p: ah %p (tsi=%d, count = %d)\n", __func__, - (void *)wsi, (void *)ah, pt->tid, pt->http.ah_count_in_use); - - return 0; - -nobody_usable_waiting: - lwsl_info("%s: nobody usable waiting\n", __func__); - _lws_destroy_ah(pt, ah); - pt->http.ah_count_in_use--; - - goto bail; -} - -int lws_header_table_detach(struct lws *wsi, int autoservice) -{ - struct lws_context *context = wsi->context; - struct lws_context_per_thread *pt = &context->pt[(int)wsi->tsi]; - int n; - - lws_pt_lock(pt, __func__); - n = __lws_header_table_detach(wsi, autoservice); - lws_pt_unlock(pt); - - return n; -} - -LWS_VISIBLE int -lws_hdr_fragment_length(struct lws *wsi, enum lws_token_indexes h, int frag_idx) -{ - int n; - - if (!wsi->http.ah) - return 0; - - n = wsi->http.ah->frag_index[h]; - if (!n) - return 0; - do { - if (!frag_idx) - return wsi->http.ah->frags[n].len; - n = wsi->http.ah->frags[n].nfrag; - } while (frag_idx-- && n); - - return 0; -} - -LWS_VISIBLE int lws_hdr_total_length(struct lws *wsi, enum lws_token_indexes h) -{ - int n; - int len = 0; - - if (!wsi->http.ah) - return 0; - - n = wsi->http.ah->frag_index[h]; - if (!n) - return 0; - do { - len += wsi->http.ah->frags[n].len; - n = wsi->http.ah->frags[n].nfrag; - - if (n && h != WSI_TOKEN_HTTP_COOKIE) - ++len; - - } while (n); - - return len; -} - -LWS_VISIBLE int lws_hdr_copy_fragment(struct lws *wsi, char *dst, int len, - enum lws_token_indexes h, int frag_idx) -{ - int n = 0; - int f; - - if (!wsi->http.ah) - return -1; - - f = wsi->http.ah->frag_index[h]; - - if (!f) - return -1; - - while (n < frag_idx) { - f = wsi->http.ah->frags[f].nfrag; - if (!f) - return -1; - n++; - } - - if (wsi->http.ah->frags[f].len >= len) - return -1; - - memcpy(dst, wsi->http.ah->data + wsi->http.ah->frags[f].offset, - wsi->http.ah->frags[f].len); - dst[wsi->http.ah->frags[f].len] = '\0'; - - return wsi->http.ah->frags[f].len; -} - -LWS_VISIBLE int lws_hdr_copy(struct lws *wsi, char *dst, int len, - enum lws_token_indexes h) -{ - int toklen = lws_hdr_total_length(wsi, h); - int n; - int comma; - - *dst = '\0'; - if (!toklen) - return 0; - - if (toklen >= len) - return -1; - - if (!wsi->http.ah) - return -1; - - n = wsi->http.ah->frag_index[h]; - if (!n) - return 0; - - do { - comma = (wsi->http.ah->frags[n].nfrag && - h != WSI_TOKEN_HTTP_COOKIE) ? 1 : 0; - - if (wsi->http.ah->frags[n].len + comma >= len) - return -1; - strncpy(dst, &wsi->http.ah->data[wsi->http.ah->frags[n].offset], - wsi->http.ah->frags[n].len); - dst += wsi->http.ah->frags[n].len; - len -= wsi->http.ah->frags[n].len; - n = wsi->http.ah->frags[n].nfrag; - - if (comma) - *dst++ = ','; - - } while (n); - *dst = '\0'; - - return toklen; -} - -#if defined(LWS_WITH_CUSTOM_HEADERS) -LWS_VISIBLE int -lws_hdr_custom_length(struct lws *wsi, const char *name, int nlen) -{ - ah_data_idx_t ll; - - if (!wsi->http.ah || wsi->http2_substream) - return -1; - - ll = wsi->http.ah->unk_ll_head; - while (ll) { - if (ll >= wsi->http.ah->data_length) - return -1; - if (nlen == lws_un16be_get(&wsi->http.ah->data[ll + UHO_NLEN]) && - !strncmp(name, &wsi->http.ah->data[ll + UHO_NAME], nlen)) - return lws_un16be_get(&wsi->http.ah->data[ll + UHO_VLEN]); - - ll = lws_un32be_get(&wsi->http.ah->data[ll + UHO_LL]); - } - - return -1; -} - -LWS_VISIBLE int -lws_hdr_custom_copy(struct lws *wsi, char *dst, int len, const char *name, - int nlen) -{ - ah_data_idx_t ll; - int n; - - if (!wsi->http.ah || wsi->http2_substream) - return -1; - - *dst = '\0'; - - ll = wsi->http.ah->unk_ll_head; - while (ll) { - if (ll >= wsi->http.ah->data_length) - return -1; - if (nlen == lws_un16be_get(&wsi->http.ah->data[ll + UHO_NLEN]) && - !strncmp(name, &wsi->http.ah->data[ll + UHO_NAME], nlen)) { - n = lws_un16be_get(&wsi->http.ah->data[ll + UHO_VLEN]); - if (n + 1 > len) - return -1; - strncpy(dst, &wsi->http.ah->data[ll + UHO_NAME + nlen], n); - dst[n] = '\0'; - - return n; - } - ll = lws_un32be_get(&wsi->http.ah->data[ll + UHO_LL]); - } - - return -1; -} -#endif - -char *lws_hdr_simple_ptr(struct lws *wsi, enum lws_token_indexes h) -{ - int n; - - if (!wsi->http.ah) - return NULL; - - n = wsi->http.ah->frag_index[h]; - if (!n) - return NULL; - - return wsi->http.ah->data + wsi->http.ah->frags[n].offset; -} - -static int LWS_WARN_UNUSED_RESULT -lws_pos_in_bounds(struct lws *wsi) -{ - if (!wsi->http.ah) - return -1; - - if (wsi->http.ah->pos < - (unsigned int)wsi->context->max_http_header_data) - return 0; - - if ((int)wsi->http.ah->pos == wsi->context->max_http_header_data) { - lwsl_err("Ran out of header data space\n"); - return 1; - } - - /* - * with these tests everywhere, it should never be able to exceed - * the limit, only meet it - */ - lwsl_err("%s: pos %ld, limit %ld\n", __func__, - (unsigned long)wsi->http.ah->pos, - (unsigned long)wsi->context->max_http_header_data); - assert(0); - - return 1; -} - -int LWS_WARN_UNUSED_RESULT -lws_hdr_simple_create(struct lws *wsi, enum lws_token_indexes h, const char *s) -{ - wsi->http.ah->nfrag++; - if (wsi->http.ah->nfrag == LWS_ARRAY_SIZE(wsi->http.ah->frags)) { - lwsl_warn("More hdr frags than we can deal with, dropping\n"); - return -1; - } - - wsi->http.ah->frag_index[h] = wsi->http.ah->nfrag; - - wsi->http.ah->frags[wsi->http.ah->nfrag].offset = wsi->http.ah->pos; - wsi->http.ah->frags[wsi->http.ah->nfrag].len = 0; - wsi->http.ah->frags[wsi->http.ah->nfrag].nfrag = 0; - - do { - if (lws_pos_in_bounds(wsi)) - return -1; - - wsi->http.ah->data[wsi->http.ah->pos++] = *s; - if (*s) - wsi->http.ah->frags[wsi->http.ah->nfrag].len++; - } while (*s++); - - return 0; -} - -static int LWS_WARN_UNUSED_RESULT -issue_char(struct lws *wsi, unsigned char c) -{ - unsigned short frag_len; - - if (lws_pos_in_bounds(wsi)) - return -1; - - frag_len = wsi->http.ah->frags[wsi->http.ah->nfrag].len; - /* - * If we haven't hit the token limit, just copy the character into - * the header - */ - if (!wsi->http.ah->current_token_limit || - frag_len < wsi->http.ah->current_token_limit) { - wsi->http.ah->data[wsi->http.ah->pos++] = c; - if (c) - wsi->http.ah->frags[wsi->http.ah->nfrag].len++; - return 0; - } - - /* Insert a null character when we *hit* the limit: */ - if (frag_len == wsi->http.ah->current_token_limit) { - if (lws_pos_in_bounds(wsi)) - return -1; - - wsi->http.ah->data[wsi->http.ah->pos++] = '\0'; - lwsl_warn("header %li exceeds limit %ld\n", - (long)wsi->http.ah->parser_state, - (long)wsi->http.ah->current_token_limit); - } - - return 1; -} - -int -lws_parse_urldecode(struct lws *wsi, uint8_t *_c) -{ - struct allocated_headers *ah = wsi->http.ah; - unsigned int enc = 0; - uint8_t c = *_c; - - // lwsl_notice("ah->ups %d\n", ah->ups); - - /* - * PRIORITY 1 - * special URI processing... convert %xx - */ - switch (ah->ues) { - case URIES_IDLE: - if (c == '%') { - ah->ues = URIES_SEEN_PERCENT; - goto swallow; - } - break; - case URIES_SEEN_PERCENT: - if (char_to_hex(c) < 0) - /* illegal post-% char */ - goto forbid; - - ah->esc_stash = c; - ah->ues = URIES_SEEN_PERCENT_H1; - goto swallow; - - case URIES_SEEN_PERCENT_H1: - if (char_to_hex(c) < 0) - /* illegal post-% char */ - goto forbid; - - *_c = (char_to_hex(ah->esc_stash) << 4) | - char_to_hex(c); - c = *_c; - enc = 1; - ah->ues = URIES_IDLE; - break; - } - - /* - * PRIORITY 2 - * special URI processing... - * convert /.. or /... or /../ etc to / - * convert /./ to / - * convert // or /// etc to / - * leave /.dir or whatever alone - */ - - switch (ah->ups) { - case URIPS_IDLE: - if (!c) - return -1; - /* genuine delimiter */ - if ((c == '&' || c == ';') && !enc) { - if (issue_char(wsi, '\0') < 0) - return -1; - /* link to next fragment */ - ah->frags[ah->nfrag].nfrag = ah->nfrag + 1; - ah->nfrag++; - if (ah->nfrag >= LWS_ARRAY_SIZE(ah->frags)) - goto excessive; - /* start next fragment after the & */ - ah->post_literal_equal = 0; - ah->frags[ah->nfrag].offset = ++ah->pos; - ah->frags[ah->nfrag].len = 0; - ah->frags[ah->nfrag].nfrag = 0; - goto swallow; - } - /* uriencoded = in the name part, disallow */ - if (c == '=' && enc && - ah->frag_index[WSI_TOKEN_HTTP_URI_ARGS] && - !ah->post_literal_equal) { - c = '_'; - *_c =c; - } - - /* after the real =, we don't care how many = */ - if (c == '=' && !enc) - ah->post_literal_equal = 1; - - /* + to space */ - if (c == '+' && !enc) { - c = ' '; - *_c = c; - } - /* issue the first / always */ - if (c == '/' && !ah->frag_index[WSI_TOKEN_HTTP_URI_ARGS]) - ah->ups = URIPS_SEEN_SLASH; - break; - case URIPS_SEEN_SLASH: - /* swallow subsequent slashes */ - if (c == '/') - goto swallow; - /* track and swallow the first . after / */ - if (c == '.') { - ah->ups = URIPS_SEEN_SLASH_DOT; - goto swallow; - } - ah->ups = URIPS_IDLE; - break; - case URIPS_SEEN_SLASH_DOT: - /* swallow second . */ - if (c == '.') { - ah->ups = URIPS_SEEN_SLASH_DOT_DOT; - goto swallow; - } - /* change /./ to / */ - if (c == '/') { - ah->ups = URIPS_SEEN_SLASH; - goto swallow; - } - /* it was like /.dir ... regurgitate the . */ - ah->ups = URIPS_IDLE; - if (issue_char(wsi, '.') < 0) - return -1; - break; - - case URIPS_SEEN_SLASH_DOT_DOT: - - /* /../ or /..[End of URI] --> backup to last / */ - if (c == '/' || c == '?') { - /* - * back up one dir level if possible - * safe against header fragmentation because - * the method URI can only be in 1 fragment - */ - if (ah->frags[ah->nfrag].len > 2) { - ah->pos--; - ah->frags[ah->nfrag].len--; - do { - ah->pos--; - ah->frags[ah->nfrag].len--; - } while (ah->frags[ah->nfrag].len > 1 && - ah->data[ah->pos] != '/'); - } - ah->ups = URIPS_SEEN_SLASH; - if (ah->frags[ah->nfrag].len > 1) - break; - goto swallow; - } - - /* /..[^/] ... regurgitate and allow */ - - if (issue_char(wsi, '.') < 0) - return -1; - if (issue_char(wsi, '.') < 0) - return -1; - ah->ups = URIPS_IDLE; - break; - } - - if (c == '?' && !enc && - !ah->frag_index[WSI_TOKEN_HTTP_URI_ARGS]) { /* start of URI args */ - if (ah->ues != URIES_IDLE) - goto forbid; - - /* seal off uri header */ - if (issue_char(wsi, '\0') < 0) - return -1; - - /* move to using WSI_TOKEN_HTTP_URI_ARGS */ - ah->nfrag++; - if (ah->nfrag >= LWS_ARRAY_SIZE(ah->frags)) - goto excessive; - ah->frags[ah->nfrag].offset = ++ah->pos; - ah->frags[ah->nfrag].len = 0; - ah->frags[ah->nfrag].nfrag = 0; - - ah->post_literal_equal = 0; - ah->frag_index[WSI_TOKEN_HTTP_URI_ARGS] = ah->nfrag; - ah->ups = URIPS_IDLE; - goto swallow; - } - - return LPUR_CONTINUE; - -swallow: - return LPUR_SWALLOW; - -forbid: - return LPUR_FORBID; - -excessive: - return LPUR_EXCESSIVE; -} - -static const unsigned char methods[] = { - WSI_TOKEN_GET_URI, - WSI_TOKEN_POST_URI, - WSI_TOKEN_OPTIONS_URI, - WSI_TOKEN_PUT_URI, - WSI_TOKEN_PATCH_URI, - WSI_TOKEN_DELETE_URI, - WSI_TOKEN_CONNECT, - WSI_TOKEN_HEAD_URI, -}; - -/* - * possible returns:, -1 fail, 0 ok or 2, transition to raw - */ - -int LWS_WARN_UNUSED_RESULT -lws_parse(struct lws *wsi, unsigned char *buf, int *len) -{ - struct allocated_headers *ah = wsi->http.ah; - struct lws_context *context = wsi->context; - unsigned int n, m; - unsigned char c; - int r, pos; - - assert(wsi->http.ah); - - do { - (*len)--; - c = *buf++; - - switch (ah->parser_state) { -#if defined(LWS_WITH_CUSTOM_HEADERS) - case WSI_TOKEN_UNKNOWN_VALUE_PART: - - if (c == '\r') - break; - if (c == '\n') { - lws_un16be_set(&ah->data[ah->unk_pos + 2], - ah->pos - ah->unk_value_pos); - ah->parser_state = WSI_TOKEN_NAME_PART; - ah->unk_pos = 0; - ah->lextable_pos = 0; - break; - } - - /* trim leading whitespace */ - if (ah->pos != ah->unk_value_pos || - (c != ' ' && c != '\t')) { - - if (lws_pos_in_bounds(wsi)) - return -1; - - ah->data[ah->pos++] = c; - } - pos = ah->lextable_pos; - break; -#endif - default: - - lwsl_parser("WSI_TOK_(%d) '%c'\n", ah->parser_state, c); - - /* collect into malloc'd buffers */ - /* optional initial space swallow */ - if (!ah->frags[ah->frag_index[ah->parser_state]].len && - c == ' ') - break; - - for (m = 0; m < LWS_ARRAY_SIZE(methods); m++) - if (ah->parser_state == methods[m]) - break; - if (m == LWS_ARRAY_SIZE(methods)) - /* it was not any of the methods */ - goto check_eol; - - /* special URI processing... end at space */ - - if (c == ' ') { - /* enforce starting with / */ - if (!ah->frags[ah->nfrag].len) - if (issue_char(wsi, '/') < 0) - return -1; - - if (ah->ups == URIPS_SEEN_SLASH_DOT_DOT) { - /* - * back up one dir level if possible - * safe against header fragmentation - * because the method URI can only be - * in 1 fragment - */ - if (ah->frags[ah->nfrag].len > 2) { - ah->pos--; - ah->frags[ah->nfrag].len--; - do { - ah->pos--; - ah->frags[ah->nfrag].len--; - } while (ah->frags[ah->nfrag].len > 1 && - ah->data[ah->pos] != '/'); - } - } - - /* begin parsing HTTP version: */ - if (issue_char(wsi, '\0') < 0) - return -1; - ah->parser_state = WSI_TOKEN_HTTP; - goto start_fragment; - } - - r = lws_parse_urldecode(wsi, &c); - switch (r) { - case LPUR_CONTINUE: - break; - case LPUR_SWALLOW: - goto swallow; - case LPUR_FORBID: - goto forbid; - case LPUR_EXCESSIVE: - goto excessive; - default: - return LPR_FAIL; - } -check_eol: - /* bail at EOL */ - if (ah->parser_state != WSI_TOKEN_CHALLENGE && - c == '\x0d') { - if (ah->ues != URIES_IDLE) - goto forbid; - - c = '\0'; - ah->parser_state = WSI_TOKEN_SKIPPING_SAW_CR; - lwsl_parser("*\n"); - } - - n = issue_char(wsi, c); - if ((int)n < 0) - return LPR_FAIL; - if (n > 0) - ah->parser_state = WSI_TOKEN_SKIPPING; - -swallow: - /* per-protocol end of headers management */ - - if (ah->parser_state == WSI_TOKEN_CHALLENGE) - goto set_parsing_complete; - break; - - /* collecting and checking a name part */ - case WSI_TOKEN_NAME_PART: - lwsl_parser("WSI_TOKEN_NAME_PART '%c' 0x%02X " - "(role=0x%lx) " - "wsi->lextable_pos=%d\n", c, c, - (unsigned long)lwsi_role(wsi), - ah->lextable_pos); - - if (c >= 'A' && c <= 'Z') - c += 'a' - 'A'; - -#if defined(LWS_WITH_CUSTOM_HEADERS) - /* - * ...in case it's an unknown header, speculatively - * store it as the name comes in. If we recognize it as - * a known header, we'll snip this. - */ - - if (!ah->unk_pos) { - ah->unk_pos = ah->pos; - /* - * Prepare new unknown header linked-list entry - * - * - 16-bit BE: name part length - * - 16-bit BE: value part length - * - 32-bit BE: data offset of next, or 0 - */ - for (n = 0; n < 8; n++) - if (!lws_pos_in_bounds(wsi)) - ah->data[ah->pos++] = 0; - } -#endif - - if (lws_pos_in_bounds(wsi)) - return -1; - - ah->data[ah->pos++] = c; - pos = ah->lextable_pos; - -#if defined(LWS_WITH_CUSTOM_HEADERS) - if (pos < 0 && c == ':') { - /* - * process unknown headers - * - * register us in the unknown hdr ll - */ - - if (!ah->unk_ll_head) - ah->unk_ll_head = ah->unk_pos; - - if (ah->unk_ll_tail) - lws_un32be_set(&ah->data[ah->unk_ll_tail + UHO_LL], - ah->unk_pos); - - ah->unk_ll_tail = ah->unk_pos; - - lwsl_debug("%s: unk header %d '%.*s'\n", - __func__, - ah->pos - (ah->unk_pos + UHO_NAME), - ah->pos - (ah->unk_pos + UHO_NAME), - &ah->data[ah->unk_pos + UHO_NAME]); - - /* set the unknown header name part length */ - - lws_un16be_set(&ah->data[ah->unk_pos], - (ah->pos - ah->unk_pos) - UHO_NAME); - - ah->unk_value_pos = ah->pos; - - /* - * collect whatever's coming for the unknown header - * argument until the next CRLF - */ - ah->parser_state = WSI_TOKEN_UNKNOWN_VALUE_PART; - break; - } -#endif - if (pos < 0) - break; - - while (1) { - if (lextable[pos] & (1 << 7)) { - /* 1-byte, fail on mismatch */ - if ((lextable[pos] & 0x7f) != c) { -nope: - ah->lextable_pos = -1; - break; - } - /* fall thru */ - pos++; - if (lextable[pos] == FAIL_CHAR) - goto nope; - - ah->lextable_pos = pos; - break; - } - - if (lextable[pos] == FAIL_CHAR) - goto nope; - - /* b7 = 0, end or 3-byte */ - if (lextable[pos] < FAIL_CHAR) { -#if defined(LWS_WITH_CUSTOM_HEADERS) - /* - * We hit a terminal marker, so we - * recognized this header... drop the - * speculative name part storage - */ - ah->pos = ah->unk_pos; - ah->unk_pos = 0; -#endif - ah->lextable_pos = pos; - break; - } - - if (lextable[pos] == c) { /* goto */ - ah->lextable_pos = pos + - (lextable[pos + 1]) + - (lextable[pos + 2] << 8); - break; - } - - /* fall thru goto */ - pos += 3; - /* continue */ - } - - /* - * If it's h1, server needs to be on the look out for - * unknown methods... - */ - if (ah->lextable_pos < 0 && lwsi_role_h1(wsi) && - lwsi_role_server(wsi)) { - /* - * this is not a header we know about... did - * we get a valid method (GET, POST etc) - * already, or is this the bogus method? - */ - for (m = 0; m < LWS_ARRAY_SIZE(methods); m++) - if (ah->frag_index[methods[m]]) { - /* - * already had the method - */ -#if !defined(LWS_WITH_CUSTOM_HEADERS) - ah->parser_state = WSI_TOKEN_SKIPPING; -#endif - break; - } - - if (m != LWS_ARRAY_SIZE(methods)) -#if defined(LWS_WITH_CUSTOM_HEADERS) - /* - * We have the method, this is just an - * unknown header then - */ - goto unknown_hdr; -#else - break; -#endif - /* - * ...it's an unknown http method from a client - * in fact, it cannot be valid http. - * - * Are we set up to transition to another role - * in these cases? - */ - if (lws_check_opt(wsi->vhost->options, - LWS_SERVER_OPTION_FALLBACK_TO_APPLY_LISTEN_ACCEPT_CONFIG)) { - lwsl_notice("%s: http fail fallback\n", - __func__); - /* transition to other role */ - return LPR_DO_FALLBACK; - } - - lwsl_info("Unknown method - dropping\n"); - goto forbid; - } - if (ah->lextable_pos < 0) { -#if defined(LWS_WITH_CUSTOM_HEADERS) - goto unknown_hdr; -#else - /* - * ...otherwise for a client, let him ignore - * unknown headers coming from the server - */ - ah->parser_state = WSI_TOKEN_SKIPPING; - break; -#endif - } - - if (lextable[ah->lextable_pos] < FAIL_CHAR) { - /* terminal state */ - - n = ((unsigned int)lextable[ah->lextable_pos] << 8) | - lextable[ah->lextable_pos + 1]; - - lwsl_parser("known hdr %d\n", n); - for (m = 0; m < LWS_ARRAY_SIZE(methods); m++) - if (n == methods[m] && - ah->frag_index[methods[m]]) { - lwsl_warn("Duplicated method\n"); - return LPR_FAIL; - } - - /* - * WSORIGIN is protocol equiv to ORIGIN, - * JWebSocket likes to send it, map to ORIGIN - */ - if (n == WSI_TOKEN_SWORIGIN) - n = WSI_TOKEN_ORIGIN; - - ah->parser_state = (enum lws_token_indexes) - (WSI_TOKEN_GET_URI + n); - ah->ups = URIPS_IDLE; - - if (context->token_limits) - ah->current_token_limit = context-> - token_limits->token_limit[ - ah->parser_state]; - else - ah->current_token_limit = - wsi->context->max_http_header_data; - - if (ah->parser_state == WSI_TOKEN_CHALLENGE) - goto set_parsing_complete; - - goto start_fragment; - } - break; - -#if defined(LWS_WITH_CUSTOM_HEADERS) -unknown_hdr: - //ah->parser_state = WSI_TOKEN_SKIPPING; - //break; - break; -#endif - -start_fragment: - ah->nfrag++; -excessive: - if (ah->nfrag == LWS_ARRAY_SIZE(ah->frags)) { - lwsl_warn("More hdr frags than we can deal with\n"); - return LPR_FAIL; - } - - ah->frags[ah->nfrag].offset = ah->pos; - ah->frags[ah->nfrag].len = 0; - ah->frags[ah->nfrag].nfrag = 0; - ah->frags[ah->nfrag].flags = 2; - - n = ah->frag_index[ah->parser_state]; - if (!n) { /* first fragment */ - ah->frag_index[ah->parser_state] = ah->nfrag; - ah->hdr_token_idx = ah->parser_state; - break; - } - /* continuation */ - while (ah->frags[n].nfrag) - n = ah->frags[n].nfrag; - ah->frags[n].nfrag = ah->nfrag; - - if (issue_char(wsi, ' ') < 0) - return LPR_FAIL; - break; - - /* skipping arg part of a name we didn't recognize */ - case WSI_TOKEN_SKIPPING: - lwsl_parser("WSI_TOKEN_SKIPPING '%c'\n", c); - - if (c == '\x0d') - ah->parser_state = WSI_TOKEN_SKIPPING_SAW_CR; - break; - - case WSI_TOKEN_SKIPPING_SAW_CR: - lwsl_parser("WSI_TOKEN_SKIPPING_SAW_CR '%c'\n", c); - if (ah->ues != URIES_IDLE) - goto forbid; - if (c == '\x0a') { - ah->parser_state = WSI_TOKEN_NAME_PART; -#if defined(LWS_WITH_CUSTOM_HEADERS) - ah->unk_pos = 0; -#endif - ah->lextable_pos = 0; - } else - ah->parser_state = WSI_TOKEN_SKIPPING; - break; - /* we're done, ignore anything else */ - - case WSI_PARSING_COMPLETE: - lwsl_parser("WSI_PARSING_COMPLETE '%c'\n", c); - break; - } - - } while (*len); - - return LPR_OK; - -set_parsing_complete: - if (ah->ues != URIES_IDLE) - goto forbid; - - if (lws_hdr_total_length(wsi, WSI_TOKEN_UPGRADE)) { - if (lws_hdr_total_length(wsi, WSI_TOKEN_VERSION)) - wsi->rx_frame_type = /* temp for ws version index */ - atoi(lws_hdr_simple_ptr(wsi, WSI_TOKEN_VERSION)); - - lwsl_parser("v%02d hdrs done\n", wsi->rx_frame_type); - } - ah->parser_state = WSI_PARSING_COMPLETE; - wsi->hdr_parsing_completed = 1; - - return LPR_OK; - -forbid: - lwsl_notice(" forbidding on uri sanitation\n"); - lws_return_http_status(wsi, HTTP_STATUS_FORBIDDEN, NULL); - - return LPR_FORBIDDEN; -} - diff -Nru libwebsockets-3.2.1/lib/roles/http/server/ranges.c libwebsockets-4.1.6/lib/roles/http/server/ranges.c --- libwebsockets-3.2.1/lib/roles/http/server/ranges.c 2019-12-18 14:45:31.000000000 +0000 +++ libwebsockets-4.1.6/lib/roles/http/server/ranges.c 2020-12-01 17:40:26.000000000 +0000 @@ -1,27 +1,28 @@ /* * libwebsockets - small server side websockets and web server implementation * - * RFC7233 ranges parser + * Copyright (C) 2010 - 2019 Andy Green * - * Copyright (C) 2016 Andy Green + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to + * deal in the Software without restriction, including without limitation the + * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or + * sell copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation: - * version 2.1 of the License. + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. * - * This library is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with this library; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, - * MA 02110-1301 USA + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS + * IN THE SOFTWARE. */ -#include "core/private.h" +#include "private-lib-core.h" /* * RFC7233 examples diff -Nru libwebsockets-3.2.1/lib/roles/http/server/rewrite.c libwebsockets-4.1.6/lib/roles/http/server/rewrite.c --- libwebsockets-3.2.1/lib/roles/http/server/rewrite.c 2019-12-18 14:45:31.000000000 +0000 +++ libwebsockets-4.1.6/lib/roles/http/server/rewrite.c 2020-12-01 17:40:26.000000000 +0000 @@ -1,8 +1,8 @@ -#include "core/private.h" +#include "private-lib-core.h" #if defined(LWS_WITH_HUBBUB) -LWS_EXTERN struct lws_rewrite * +struct lws_rewrite * lws_rewrite_create(struct lws *wsi, hubbub_callback_t cb, const char *from, const char *to) { @@ -35,7 +35,7 @@ return r; } -LWS_EXTERN int +int lws_rewrite_parse(struct lws_rewrite *r, const unsigned char *in, int in_len) { @@ -45,7 +45,7 @@ return 0; } -LWS_EXTERN void +void lws_rewrite_destroy(struct lws_rewrite *r) { hubbub_parser_destroy(r->parser); diff -Nru libwebsockets-3.2.1/lib/roles/http/server/server.c libwebsockets-4.1.6/lib/roles/http/server/server.c --- libwebsockets-3.2.1/lib/roles/http/server/server.c 2019-12-18 14:45:31.000000000 +0000 +++ libwebsockets-4.1.6/lib/roles/http/server/server.c 2020-12-01 17:40:26.000000000 +0000 @@ -1,34 +1,43 @@ /* * libwebsockets - small server side websockets and web server implementation * - * Copyright (C) 2010-2018 Andy Green + * Copyright (C) 2010 - 2019 Andy Green * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation: - * version 2.1 of the License. + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to + * deal in the Software without restriction, including without limitation the + * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or + * sell copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: * - * This library is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. * - * You should have received a copy of the GNU Lesser General Public - * License along with this library; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, - * MA 02110-1301 USA + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS + * IN THE SOFTWARE. */ -#include "core/private.h" +#include "private-lib-core.h" const char * const method_names[] = { - "GET", "POST", "OPTIONS", "PUT", "PATCH", "DELETE", "CONNECT", "HEAD", + "GET", "POST", +#if defined(LWS_WITH_HTTP_UNCOMMON_HEADERS) + "OPTIONS", "PUT", "PATCH", "DELETE", +#endif + "CONNECT", "HEAD", #ifdef LWS_WITH_HTTP2 ":path", #endif }; +#if defined(LWS_WITH_FILE_OPS) static const char * const intermediates[] = { "private", "public" }; +#endif /* * return 0: all done @@ -38,11 +47,12 @@ * REQUIRES CONTEXT LOCK HELD */ -#ifndef LWS_NO_SERVER +#if defined(LWS_WITH_SERVER) int _lws_vhost_init_server(const struct lws_context_creation_info *info, struct lws_vhost *vhost) { + struct lws_context_per_thread *pt; int n, opt = 1, limit = 1; lws_sockfd_type sockfd; struct lws_vhost *vh; @@ -132,7 +142,8 @@ vhost->name, vhost->iface, vhost->listen_port); else return -1; - return (info->options & LWS_SERVER_OPTION_FAIL_UPON_UNABLE_TO_BIND) == LWS_SERVER_OPTION_FAIL_UPON_UNABLE_TO_BIND? + return (info->options & LWS_SERVER_OPTION_FAIL_UPON_UNABLE_TO_BIND) == + LWS_SERVER_OPTION_FAIL_UPON_UNABLE_TO_BIND? -1 : 1; case LWS_ITOSA_NOT_USABLE: /* can't add it */ @@ -141,7 +152,8 @@ vhost->name, vhost->iface, vhost->listen_port); else return -1; - return (info->options & LWS_SERVER_OPTION_FAIL_UPON_UNABLE_TO_BIND) == LWS_SERVER_OPTION_FAIL_UPON_UNABLE_TO_BIND? + return (info->options & LWS_SERVER_OPTION_FAIL_UPON_UNABLE_TO_BIND) == + LWS_SERVER_OPTION_FAIL_UPON_UNABLE_TO_BIND? -1 : 1; } } @@ -179,7 +191,7 @@ lwsl_err("ERROR opening socket\n"); return 1; } -#if !defined(LWS_WITH_ESP32) +#if !defined(LWS_PLAT_FREERTOS) #if (defined(WIN32) || defined(_WIN32)) && defined(SO_EXCLUSIVEADDRUSE) /* * only accept that we are the only listener on the port @@ -240,7 +252,8 @@ #endif lws_plat_set_socket_options(vhost, sockfd, 0); - is = lws_socket_bind(vhost, sockfd, vhost->listen_port, vhost->iface, 1); + is = lws_socket_bind(vhost, sockfd, vhost->listen_port, + vhost->iface, 1); if (is == LWS_ITOSA_BUSY) { /* treat as fatal */ compatible_close(sockfd); @@ -259,10 +272,21 @@ goto deal; } - wsi = lws_zalloc(sizeof(struct lws), "listen wsi"); - if (wsi == NULL) { - lwsl_err("Out of mem\n"); - goto bail; + { + size_t s = sizeof(struct lws); + +#if defined(LWS_WITH_EVENT_LIBS) + s += vhost->context->event_loop_ops->evlib_size_wsi; +#endif + + wsi = lws_zalloc(s, "listen wsi"); + if (wsi == NULL) { + lwsl_err("Out of mem\n"); + goto bail; + } +#if defined(LWS_WITH_EVENT_LIBS) + wsi->evlib_wsi = (uint8_t *)wsi + sizeof(*wsi); +#endif } #ifdef LWS_WITH_UNIX_SOCK @@ -275,24 +299,29 @@ lwsl_debug("%s: lws_socket_bind says %d\n", __func__, is); } - wsi->context = vhost->context; + wsi->a.context = vhost->context; wsi->desc.sockfd = sockfd; lws_role_transition(wsi, 0, LRS_UNCONNECTED, &role_ops_listen); - wsi->protocol = vhost->protocols; + wsi->a.protocol = vhost->protocols; wsi->tsi = m; lws_vhost_bind_wsi(vhost, wsi); wsi->listener = 1; - if (wsi->context->event_loop_ops->init_vhost_listen_wsi) - wsi->context->event_loop_ops->init_vhost_listen_wsi(wsi); + if (wsi->a.context->event_loop_ops->init_vhost_listen_wsi) + wsi->a.context->event_loop_ops->init_vhost_listen_wsi(wsi); + + pt = &vhost->context->pt[m]; + lws_pt_lock(pt, __func__); if (__insert_wsi_socket_into_fds(vhost->context, wsi)) { lwsl_notice("inserting wsi socket into fds failed\n"); + lws_pt_unlock(pt); goto bail; } vhost->context->count_wsi_allocated++; vhost->lserv_wsi = wsi; + lws_pt_unlock(pt); n = listen(wsi->desc.sockfd, LWS_SOMAXCONN); if (n < 0) { @@ -304,7 +333,8 @@ } } /* for each thread able to independently listen */ - if (!lws_check_opt(vhost->context->options, LWS_SERVER_OPTION_EXPLICIT_VHOSTS)) { + if (!lws_check_opt(vhost->context->options, + LWS_SERVER_OPTION_EXPLICIT_VHOSTS)) { #ifdef LWS_WITH_UNIX_SOCK if (LWS_UNIX_SOCK_ENABLED(vhost)) lwsl_info(" Listening on \"%s\"\n", vhost->iface); @@ -410,7 +440,7 @@ { ".json", "application/json" }, }; -LWS_VISIBLE LWS_EXTERN const char * +const char * lws_get_mimetype(const char *file, const struct lws_http_mount *m) { const struct lws_protocol_vhost_options *pvo; @@ -428,7 +458,8 @@ len = strlen(pvo->name); if (n > len && !strcasecmp(&file[n - len], pvo->name)) { - lwsl_info("%s: match to user mimetype: %s\n", __func__, pvo->value); + lwsl_info("%s: match to user mimetype: %s\n", __func__, + pvo->value); return pvo->value; } } @@ -439,20 +470,23 @@ len = strlen(mt->extension); if (n > len && !strcasecmp(&file[n - len], mt->extension)) { - lwsl_info("%s: match to server mimetype: %s\n", __func__, mt->mimetype); + lwsl_info("%s: match to server mimetype: %s\n", __func__, + mt->mimetype); return mt->mimetype; } } /* fallback to '*' if defined */ if (fallback_mimetype) { - lwsl_info("%s: match to any mimetype: %s\n", __func__, fallback_mimetype); + lwsl_info("%s: match to any mimetype: %s\n", __func__, + fallback_mimetype); return fallback_mimetype; } return NULL; } +#if defined(LWS_WITH_FILE_OPS) static lws_fop_flags_t lws_vfs_prepare_flags(struct lws *wsi) { @@ -470,7 +504,6 @@ return f; } -#if !defined(LWS_AMAZON_RTOS) static int lws_http_serve(struct lws *wsi, char *uri, const char *origin, const struct lws_http_mount *m) @@ -492,18 +525,18 @@ char path[256], sym[2048]; unsigned char *p = (unsigned char *)sym + 32 + LWS_PRE, *start = p; unsigned char *end = p + sizeof(sym) - 32 - LWS_PRE; -#if !defined(WIN32) && !defined(LWS_WITH_ESP32) +#if !defined(WIN32) && !defined(LWS_PLAT_FREERTOS) size_t len; #endif int n; wsi->handling_404 = 0; - if (!wsi->vhost) + if (!wsi->a.vhost) return -1; #if defined(LWS_ROLE_H1) || defined(LWS_ROLE_H2) - if (wsi->vhost->http.error_document_404 && - !strcmp(uri, wsi->vhost->http.error_document_404)) + if (wsi->a.vhost->http.error_document_404 && + !strcmp(uri, wsi->a.vhost->http.error_document_404)) wsi->handling_404 = 1; #endif @@ -515,12 +548,12 @@ do { spin++; - fops = lws_vfs_select_fops(wsi->context->fops, path, &vpath); + fops = lws_vfs_select_fops(wsi->a.context->fops, path, &vpath); if (wsi->http.fop_fd) lws_vfs_file_close(&wsi->http.fop_fd); - wsi->http.fop_fd = fops->LWS_FOP_OPEN(wsi->context->fops, + wsi->http.fop_fd = fops->LWS_FOP_OPEN(wsi->a.context->fops, path, vpath, &fflags); if (!wsi->http.fop_fd) { lwsl_info("%s: Unable to open '%s': errno %d\n", @@ -532,7 +565,7 @@ /* if it can't be statted, don't try */ if (fflags & LWS_FOP_FLAG_VIRTUAL) break; -#if defined(LWS_WITH_ESP32) +#if defined(LWS_PLAT_FREERTOS) break; #endif #if !defined(WIN32) @@ -557,7 +590,7 @@ wsi->http.fop_fd->mod_time = (uint32_t)st.st_mtime; fflags |= LWS_FOP_FLAG_MOD_TIME_VALID; -#if !defined(WIN32) && !defined(LWS_WITH_ESP32) +#if !defined(WIN32) && !defined(LWS_PLAT_FREERTOS) if ((S_IFMT & st.st_mode) == S_IFLNK) { len = readlink(path, sym, sizeof(sym) - 1); if (len) { @@ -571,8 +604,8 @@ #endif if ((S_IFMT & st.st_mode) == S_IFDIR) { lwsl_debug("default filename append to dir\n"); - lws_snprintf(path, sizeof(path) - 1, "%s/%s/index.html", - origin, uri); + lws_snprintf(path, sizeof(path) - 1, "%s/%s/%s", + origin, uri, m->def ? m->def : "index.html"); } } while ((S_IFMT & st.st_mode) != S_IFREG && spin < 5); @@ -692,19 +725,19 @@ if (n > (int)strlen(pvo->name) && !strcmp(&path[n - strlen(pvo->name)], pvo->name)) { wsi->interpreting = 1; - if (!wsi->http2_substream) + if (!wsi->mux_substream) wsi->sending_chunked = 1; wsi->protocol_interpret_idx = (char)( - lws_vhost_name_to_protocol(wsi->vhost, + lws_vhost_name_to_protocol(wsi->a.vhost, pvo->value) - &lws_get_vhost(wsi)->protocols[0]); lwsl_debug("want %s interpreted by %s (pcol is %s)\n", path, - wsi->vhost->protocols[ + wsi->a.vhost->protocols[ (int)wsi->protocol_interpret_idx].name, - wsi->protocol->name); - if (lws_bind_protocol(wsi, &wsi->vhost->protocols[ + wsi->a.protocol->name); + if (lws_bind_protocol(wsi, &wsi->a.vhost->protocols[ (int)wsi->protocol_interpret_idx], __func__)) return -1; @@ -725,7 +758,7 @@ if (m->protocol) { const struct lws_protocols *pp = lws_vhost_name_to_protocol( - wsi->vhost, m->protocol); + wsi->a.vhost, m->protocol); if (lws_bind_protocol(wsi, pp, __func__)) return -1; @@ -759,7 +792,7 @@ const struct lws_http_mount *hm, *hit = NULL; int best = 0; - hm = wsi->vhost->http.mount_list; + hm = wsi->a.vhost->http.mount_list; while (hm) { if (uri_len >= hm->mountpoint_len && !strncmp(uri_ptr, hm->mountpoint, hm->mountpoint_len) && @@ -772,9 +805,11 @@ lws_hdr_total_length(wsi, WSI_TOKEN_GET_URI) || lws_hdr_total_length(wsi, WSI_TOKEN_POST_URI) || lws_hdr_total_length(wsi, WSI_TOKEN_HEAD_URI) || - (wsi->http2_substream && +#if defined(LWS_ROLE_H2) + (wsi->mux_substream && lws_hdr_total_length(wsi, WSI_TOKEN_HTTP_COLON_PATH)) || +#endif hm->protocol) && hm->mountpoint_len > best)) { best = hm->mountpoint_len; @@ -788,7 +823,7 @@ } #endif -#if !defined(LWS_WITH_ESP32) +#if defined(LWS_WITH_HTTP_BASIC_AUTH) && !defined(LWS_PLAT_FREERTOS) && defined(LWS_WITH_FILE_OPS) static int lws_find_string_in_file(const char *filename, const char *string, int stringlen) { @@ -834,10 +869,12 @@ } #endif +#if defined(LWS_WITH_HTTP_BASIC_AUTH) + int lws_unauthorised_basic_auth(struct lws *wsi) { - struct lws_context_per_thread *pt = &wsi->context->pt[(int)wsi->tsi]; + struct lws_context_per_thread *pt = &wsi->a.context->pt[(int)wsi->tsi]; unsigned char *start = pt->serv_buf + LWS_PRE, *p = start, *end = p + 2048; char buf[64]; @@ -869,6 +906,8 @@ } +#endif + int lws_clean_url(char *p) { if (p[0] == 'h' && p[1] == 't' && p[2] == 't' && p[3] == 'p') { @@ -900,10 +939,12 @@ static const unsigned char methods[] = { WSI_TOKEN_GET_URI, WSI_TOKEN_POST_URI, +#if defined(LWS_WITH_HTTP_UNCOMMON_HEADERS) WSI_TOKEN_OPTIONS_URI, WSI_TOKEN_PUT_URI, WSI_TOKEN_PATCH_URI, WSI_TOKEN_DELETE_URI, +#endif WSI_TOKEN_CONNECT, WSI_TOKEN_HEAD_URI, #ifdef LWS_WITH_HTTP2 @@ -925,8 +966,12 @@ } if (count != 1 && - !((wsi->http2_substream || wsi->h2_stream_carries_ws) && - lws_hdr_total_length(wsi, WSI_TOKEN_HTTP_COLON_PATH))) { + !((wsi->mux_substream || wsi->h2_stream_carries_ws) +#if defined(LWS_ROLE_H2) + && + lws_hdr_total_length(wsi, WSI_TOKEN_HTTP_COLON_PATH) +#endif + )) { lwsl_warn("multiple methods?\n"); return -1; } @@ -941,13 +986,17 @@ return -1; } +#if defined(LWS_WITH_HTTP_BASIC_AUTH) + enum lws_check_basic_auth_results -lws_check_basic_auth(struct lws *wsi, const char *basic_auth_login_file) +lws_check_basic_auth(struct lws *wsi, const char *basic_auth_login_file, + unsigned int auth_mode) { +#if defined(LWS_WITH_FILE_OPS) char b64[160], plain[(sizeof(b64) * 3) / 4], *pcolon; - int m, ml, fi; + int m, ml, fi, bar; - if (!basic_auth_login_file) + if (!basic_auth_login_file && auth_mode == LWSAUTHM_DEFAULT) return LCBA_CONTINUE; /* Did he send auth? */ @@ -990,8 +1039,23 @@ lwsl_err("basic auth format broken\n"); return LCBA_END_TRANSACTION; } - if (!lws_find_string_in_file(basic_auth_login_file, plain, m)) { - lwsl_err("basic auth lookup failed\n"); + + switch (auth_mode) { + case LWSAUTHM_DEFAULT: + if (lws_find_string_in_file(basic_auth_login_file, plain, m)) + break; + lwsl_err("%s: basic auth lookup failed\n", __func__); + return LCBA_FAILED_AUTH; + + case LWSAUTHM_BASIC_AUTH_CALLBACK: + bar = wsi->a.protocol->callback(wsi, + LWS_CALLBACK_VERIFY_BASIC_AUTHORIZATION, + wsi->user_space, plain, m); + if (!bar) + return LCBA_FAILED_AUTH; + break; + default: + /* Invalid auth mode so lets fail all authentication attempts */ return LCBA_FAILED_AUTH; } @@ -1009,8 +1073,13 @@ lws_hdr_simple_ptr(wsi, WSI_TOKEN_HTTP_AUTHORIZATION)); return LCBA_CONTINUE; +#else + return LCBA_FAILED_AUTH; +#endif } +#endif + #if defined(LWS_WITH_HTTP_PROXY) /* * Set up an onward http proxy connection according to the mount this @@ -1026,6 +1095,7 @@ struct lws *cwsi; int n, na; +#if defined(LWS_ROLE_WS) if (ws) /* * Neither our inbound ws upgrade request side, nor our onward @@ -1042,7 +1112,7 @@ * the .local_protocol_name. */ lws_bind_protocol(wsi, &lws_ws_proxy, __func__); - +#endif memset(&i, 0, sizeof(i)); i.context = lws_get_context(wsi); @@ -1095,7 +1165,12 @@ lws_clean_url(rpath); na = lws_hdr_total_length(wsi, WSI_TOKEN_HTTP_URI_ARGS); if (na) { - char *p = rpath + n; + char *p; + + if (!n) /* don't start with the ?... use the first / if so */ + n++; + + p = rpath + n; if (na >= (int)sizeof(rpath) - n - 2) { lwsl_info("%s: query string %d longer " @@ -1124,10 +1199,13 @@ * host */ i.host = NULL; +#if defined(LWS_ROLE_H2) n = lws_hdr_total_length(wsi, WSI_TOKEN_HTTP_COLON_AUTHORITY); if (n > 0) i.host = lws_hdr_simple_ptr(wsi, WSI_TOKEN_HTTP_COLON_AUTHORITY); - else { + else +#endif + { n = lws_hdr_total_length(wsi, WSI_TOKEN_HOST); if (n > 0) { i.host = lws_hdr_simple_ptr(wsi, WSI_TOKEN_HOST); @@ -1147,7 +1225,8 @@ #if defined(LWS_WITH_HTTP2) || ( lws_hdr_simple_ptr(wsi, WSI_TOKEN_HTTP_COLON_METHOD) && - !strcmp(lws_hdr_simple_ptr(wsi, WSI_TOKEN_HTTP_COLON_METHOD), "post") + !strcmp(lws_hdr_simple_ptr(wsi, + WSI_TOKEN_HTTP_COLON_METHOD), "post") ) #endif ) @@ -1158,7 +1237,7 @@ if (i.host) lws_snprintf(host, sizeof(host), "%s:%u", i.host, - wsi->vhost->listen_port); + wsi->a.vhost->listen_port); else lws_snprintf(host, sizeof(host), "%s:%d", i.address, i.port); @@ -1167,9 +1246,11 @@ i.alpn = "http/1.1"; i.parent_wsi = wsi; i.pwsi = &cwsi; +#if defined(LWS_ROLE_WS) i.protocol = lws_hdr_simple_ptr(wsi, WSI_TOKEN_PROTOCOL); if (ws) i.local_protocol_name = "lws-ws-proxy"; +#endif // i.uri_replace_from = hit->origin; // i.uri_replace_to = hit->mountpoint; @@ -1204,7 +1285,8 @@ wsi->proxied_ws_parent = 1; cwsi->h1_ws_proxied = 1; if (i.protocol) { - lwsl_debug("%s: (requesting '%s')\n", __func__, i.protocol); + lwsl_debug("%s: (requesting '%s')\n", + __func__, i.protocol); } } @@ -1212,24 +1294,116 @@ } #endif + static const char * const oprot[] = { "http://", "https://" }; + +static int +lws_http_redirect_hit(struct lws_context_per_thread *pt, struct lws *wsi, + const struct lws_http_mount *hit, char *uri_ptr, + int uri_len, int *h) +{ + char *s; + int n; + + *h = 0; + s = uri_ptr + hit->mountpoint_len; + + /* + * if we have a mountpoint like https://xxx.com/yyy + * there is an implied / at the end for our purposes since + * we can only mount on a "directory". + * + * But if we just go with that, the browser cannot understand + * that he is actually looking down one "directory level", so + * even though we give him /yyy/abc.html he acts like the + * current directory level is /. So relative urls like "x.png" + * wrongly look outside the mountpoint. + * + * Therefore if we didn't come in on a url with an explicit + * / at the end, we must redirect to add it so the browser + * understands he is one "directory level" down. + */ + if ((hit->mountpoint_len > 1 || + (hit->origin_protocol == LWSMPRO_REDIR_HTTP || + hit->origin_protocol == LWSMPRO_REDIR_HTTPS)) && + (*s != '/' || + (hit->origin_protocol == LWSMPRO_REDIR_HTTP || + hit->origin_protocol == LWSMPRO_REDIR_HTTPS)) && + (hit->origin_protocol != LWSMPRO_CGI && + hit->origin_protocol != LWSMPRO_CALLBACK)) { + unsigned char *start = pt->serv_buf + LWS_PRE, *p = start, + *end = p + wsi->a.context->pt_serv_buf_size - + LWS_PRE - 512; + + *h = 1; + + lwsl_info("Doing 301 '%s' org %s\n", s, hit->origin); + + /* > at start indicates deal with by redirect */ + if (hit->origin_protocol == LWSMPRO_REDIR_HTTP || + hit->origin_protocol == LWSMPRO_REDIR_HTTPS) + n = lws_snprintf((char *)end, 256, "%s%s", + oprot[hit->origin_protocol & 1], + hit->origin); + else { + if (!lws_hdr_total_length(wsi, WSI_TOKEN_HOST)) { +#if defined(LWS_ROLE_H2) + if (!lws_hdr_total_length(wsi, + WSI_TOKEN_HTTP_COLON_AUTHORITY)) +#endif + goto bail_nuke_ah; +#if defined(LWS_ROLE_H2) + n = lws_snprintf((char *)end, 256, + "%s%s%s/", oprot[!!lws_is_ssl(wsi)], + lws_hdr_simple_ptr(wsi, + WSI_TOKEN_HTTP_COLON_AUTHORITY), + uri_ptr); +#else + ; +#endif + } else + n = lws_snprintf((char *)end, 256, + "%s%s%s/", oprot[!!lws_is_ssl(wsi)], + lws_hdr_simple_ptr(wsi, WSI_TOKEN_HOST), + uri_ptr); + } + + lws_clean_url((char *)end); + n = lws_http_redirect(wsi, HTTP_STATUS_MOVED_PERMANENTLY, + end, n, &p, end); + if ((int)n < 0) + goto bail_nuke_ah; + + return lws_http_transaction_completed(wsi); + } + + return 0; + +bail_nuke_ah: + lws_header_table_detach(wsi, 1); + + return 1; +} + int lws_http_action(struct lws *wsi) { - struct lws_context_per_thread *pt = &wsi->context->pt[(int)wsi->tsi]; + struct lws_context_per_thread *pt = &wsi->a.context->pt[(int)wsi->tsi]; + int uri_len = 0, meth, m, http_version_len, ha; const struct lws_http_mount *hit = NULL; enum http_version request_version; struct lws_process_html_args args; enum http_conn_type conn_type; char content_length_str[32]; char http_version_str[12]; - char *uri_ptr = NULL, *s; - int uri_len = 0, meth, m; char http_conn_str[25]; - int http_version_len; + char *uri_ptr = NULL; +#if defined(LWS_WITH_FILE_OPS) + char *s; +#endif unsigned int n; meth = lws_http_get_uri_and_method(wsi, &uri_ptr, &uri_len); @@ -1264,9 +1438,13 @@ wsi->http.rx_content_length = 0; wsi->http.content_length_explicitly_zero = 0; - if (lws_hdr_total_length(wsi, WSI_TOKEN_POST_URI) || + if (lws_hdr_total_length(wsi, WSI_TOKEN_POST_URI) +#if defined(LWS_WITH_HTTP_UNCOMMON_HEADERS) + || lws_hdr_total_length(wsi, WSI_TOKEN_PATCH_URI) || - lws_hdr_total_length(wsi, WSI_TOKEN_PUT_URI)) + lws_hdr_total_length(wsi, WSI_TOKEN_PUT_URI) +#endif + ) wsi->http.rx_content_length = 100 * 1024 * 1024; if (lws_hdr_total_length(wsi, WSI_TOKEN_HTTP_CONTENT_LENGTH) && @@ -1281,7 +1459,7 @@ } } - if (wsi->http2_substream) { + if (wsi->mux_substream) { wsi->http.request_version = HTTP_VERSION_2; } else { /* http_version? Default to 1.0, override with token: */ @@ -1318,7 +1496,7 @@ wsi->http.conn_type = conn_type; } - n = wsi->protocol->callback(wsi, LWS_CALLBACK_FILTER_HTTP_CONNECTION, + n = wsi->a.protocol->callback(wsi, LWS_CALLBACK_FILTER_HTTP_CONNECTION, wsi->user_space, uri_ptr, uri_len); if (n) { lwsl_info("LWS_CALLBACK_HTTP closing\n"); @@ -1329,8 +1507,9 @@ * if there is content supposed to be coming, * put a timeout on it having arrived */ - lws_set_timeout(wsi, PENDING_TIMEOUT_HTTP_CONTENT, - wsi->context->timeout_secs); + if (!wsi->mux_stream_immortal) + lws_set_timeout(wsi, PENDING_TIMEOUT_HTTP_CONTENT, + wsi->a.context->timeout_secs); #ifdef LWS_WITH_TLS if (wsi->tls.redirect_to_https) { /* @@ -1339,12 +1518,15 @@ * URI from the host: header and ignore the path part */ unsigned char *start = pt->serv_buf + LWS_PRE, *p = start, - *end = p + wsi->context->pt_serv_buf_size - LWS_PRE; + *end = p + wsi->a.context->pt_serv_buf_size - LWS_PRE; n = lws_hdr_total_length(wsi, WSI_TOKEN_HOST); if (!n || n > 128) goto bail_nuke_ah; + if (!lws_hdr_simple_ptr(wsi, WSI_TOKEN_HOST)) + goto bail_nuke_ah; + p += lws_snprintf((char *)p, lws_ptr_diff(end, p), "https://"); memcpy(p, lws_hdr_simple_ptr(wsi, WSI_TOKEN_HOST), n); p += n; @@ -1374,84 +1556,31 @@ lwsl_info("no hit\n"); - if (lws_bind_protocol(wsi, &wsi->vhost->protocols[0], + if (lws_bind_protocol(wsi, &wsi->a.vhost->protocols[0], "no mount hit")) return 1; lwsi_set_state(wsi, LRS_DOING_TRANSACTION); - m = wsi->protocol->callback(wsi, LWS_CALLBACK_HTTP, + m = wsi->a.protocol->callback(wsi, LWS_CALLBACK_HTTP, wsi->user_space, uri_ptr, uri_len); goto after; } +#if defined(LWS_WITH_FILE_OPS) s = uri_ptr + hit->mountpoint_len; +#endif + n = lws_http_redirect_hit(pt, wsi, hit, uri_ptr, uri_len, &ha); + if (ha) + return n; - /* - * if we have a mountpoint like https://xxx.com/yyy - * there is an implied / at the end for our purposes since - * we can only mount on a "directory". - * - * But if we just go with that, the browser cannot understand - * that he is actually looking down one "directory level", so - * even though we give him /yyy/abc.html he acts like the - * current directory level is /. So relative urls like "x.png" - * wrongly look outside the mountpoint. - * - * Therefore if we didn't come in on a url with an explicit - * / at the end, we must redirect to add it so the browser - * understands he is one "directory level" down. - */ - if ((hit->mountpoint_len > 1 || - (hit->origin_protocol == LWSMPRO_REDIR_HTTP || - hit->origin_protocol == LWSMPRO_REDIR_HTTPS)) && - (*s != '/' || - (hit->origin_protocol == LWSMPRO_REDIR_HTTP || - hit->origin_protocol == LWSMPRO_REDIR_HTTPS)) && - (hit->origin_protocol != LWSMPRO_CGI && - hit->origin_protocol != LWSMPRO_CALLBACK)) { - unsigned char *start = pt->serv_buf + LWS_PRE, *p = start, - *end = p + wsi->context->pt_serv_buf_size - - LWS_PRE - 512; - - lwsl_info("Doing 301 '%s' org %s\n", s, hit->origin); - - /* > at start indicates deal with by redirect */ - if (hit->origin_protocol == LWSMPRO_REDIR_HTTP || - hit->origin_protocol == LWSMPRO_REDIR_HTTPS) - n = lws_snprintf((char *)end, 256, "%s%s", - oprot[hit->origin_protocol & 1], - hit->origin); - else { - if (!lws_hdr_total_length(wsi, WSI_TOKEN_HOST)) { - if (!lws_hdr_total_length(wsi, - WSI_TOKEN_HTTP_COLON_AUTHORITY)) - goto bail_nuke_ah; - n = lws_snprintf((char *)end, 256, - "%s%s%s/", oprot[!!lws_is_ssl(wsi)], - lws_hdr_simple_ptr(wsi, - WSI_TOKEN_HTTP_COLON_AUTHORITY), - uri_ptr); - } else - n = lws_snprintf((char *)end, 256, - "%s%s%s/", oprot[!!lws_is_ssl(wsi)], - lws_hdr_simple_ptr(wsi, WSI_TOKEN_HOST), - uri_ptr); - } - - lws_clean_url((char *)end); - n = lws_http_redirect(wsi, HTTP_STATUS_MOVED_PERMANENTLY, - end, n, &p, end); - if ((int)n < 0) - goto bail_nuke_ah; - - return lws_http_transaction_completed(wsi); - } +#if defined(LWS_WITH_HTTP_BASIC_AUTH) /* basic auth? */ - switch(lws_check_basic_auth(wsi, hit->basic_auth_login_file)) { + switch (lws_check_basic_auth(wsi, hit->basic_auth_login_file, + hit->auth_mask & AUTH_MODE_MASK)) { case LCBA_CONTINUE: break; case LCBA_FAILED_AUTH: @@ -1460,6 +1589,7 @@ lws_return_http_status(wsi, HTTP_STATUS_FORBIDDEN, NULL); return lws_http_transaction_completed(wsi); } +#endif #if defined(LWS_WITH_HTTP_PROXY) /* @@ -1494,9 +1624,8 @@ if (hit->protocol) name = hit->protocol; - pp = lws_vhost_name_to_protocol(wsi->vhost, name); + pp = lws_vhost_name_to_protocol(wsi->a.vhost, name); if (!pp) { - n = -1; lwsl_err("Unable to find plugin '%s'\n", hit->origin); return 1; @@ -1505,16 +1634,16 @@ if (lws_bind_protocol(wsi, pp, "http action CALLBACK bind")) return 1; - lwsl_notice("%s: %s, checking access rights for mask 0x%x\n", + lwsl_debug("%s: %s, checking access rights for mask 0x%x\n", __func__, hit->origin, hit->auth_mask); args.p = uri_ptr; args.len = uri_len; - args.max_len = hit->auth_mask; + args.max_len = hit->auth_mask & ~AUTH_MODE_MASK; args.final = 0; /* used to signal callback dealt with it */ args.chunked = 0; - n = wsi->protocol->callback(wsi, + n = wsi->a.protocol->callback(wsi, LWS_CALLBACK_CHECK_ACCESS_RIGHTS, wsi->user_space, &args, 0); if (n) { @@ -1525,13 +1654,13 @@ if (args.final) /* callback completely handled it well */ return 0; - if (hit->cgienv && wsi->protocol->callback(wsi, + if (hit->cgienv && wsi->a.protocol->callback(wsi, LWS_CALLBACK_HTTP_PMO, wsi->user_space, (void *)hit->cgienv, 0)) return 1; if (lws_hdr_total_length(wsi, WSI_TOKEN_POST_URI)) { - m = wsi->protocol->callback(wsi, LWS_CALLBACK_HTTP, + m = wsi->a.protocol->callback(wsi, LWS_CALLBACK_HTTP, wsi->user_space, uri_ptr + hit->mountpoint_len, uri_len - hit->mountpoint_len); @@ -1565,31 +1694,38 @@ } #endif - n = uri_len - lws_ptr_diff(s, uri_ptr); // (int)strlen(s); +#if defined(LWS_WITH_FILE_OPS) + n = uri_len - lws_ptr_diff(s, uri_ptr); if (s[0] == '\0' || (n == 1 && s[n - 1] == '/')) s = (char *)hit->def; if (!s) s = "index.html"; +#endif wsi->cache_secs = hit->cache_max_age; wsi->cache_reuse = hit->cache_reusable; wsi->cache_revalidate = hit->cache_revalidate; wsi->cache_intermediaries = hit->cache_intermediaries; +#if defined(LWS_WITH_FILE_OPS) m = 1; -#if !defined(LWS_AMAZON_RTOS) if (hit->origin_protocol == LWSMPRO_FILE) m = lws_http_serve(wsi, s, hit->origin, hit); -#endif - if (m > 0) { + if (m > 0) +#endif + { /* * lws_return_http_status(wsi, HTTP_STATUS_NOT_FOUND, NULL); */ if (hit->protocol) { const struct lws_protocols *pp = lws_vhost_name_to_protocol( - wsi->vhost, hit->protocol); + wsi->a.vhost, hit->protocol); + + /* coverity */ + if (!pp) + return 1; lwsi_set_state(wsi, LRS_DOING_TRANSACTION); @@ -1601,7 +1737,7 @@ uri_ptr + hit->mountpoint_len, uri_len - hit->mountpoint_len); } else - m = wsi->protocol->callback(wsi, LWS_CALLBACK_HTTP, + m = wsi->a.protocol->callback(wsi, LWS_CALLBACK_HTTP, wsi->user_space, uri_ptr, uri_len); } @@ -1623,76 +1759,72 @@ * In any case, return 0 and let lws_read decide how to * proceed based on state */ - if (lwsi_state(wsi) != LRS_ISSUING_FILE) { - /* Prepare to read body if we have a content length: */ - lwsl_debug("wsi->http.rx_content_length %lld %d %d\n", - (long long)wsi->http.rx_content_length, - wsi->upgraded_to_http2, wsi->http2_substream); + if (lwsi_state(wsi) == LRS_ISSUING_FILE) + return 0; - if (wsi->http.content_length_explicitly_zero && - lws_hdr_total_length(wsi, WSI_TOKEN_POST_URI)) { + /* Prepare to read body if we have a content length: */ + lwsl_debug("wsi->http.rx_content_length %lld %d %d\n", + (long long)wsi->http.rx_content_length, + wsi->upgraded_to_http2, wsi->mux_substream); - /* - * POST with an explicit content-length of zero - * - * If we don't give the user code the empty HTTP_BODY - * callback, he may become confused to hear the - * HTTP_BODY_COMPLETION (due to, eg, instantiation of - * lws_spa never happened). - * - * HTTP_BODY_COMPLETION is responsible for sending the - * result status code and result body if any, and - * do the transaction complete processing. - */ - if (wsi->protocol->callback(wsi, - LWS_CALLBACK_HTTP_BODY, - wsi->user_space, NULL, 0)) - return 1; - if (wsi->protocol->callback(wsi, - LWS_CALLBACK_HTTP_BODY_COMPLETION, - wsi->user_space, NULL, 0)) - return 1; + if (wsi->http.content_length_explicitly_zero && + lws_hdr_total_length(wsi, WSI_TOKEN_POST_URI)) { - return 0; - } + /* + * POST with an explicit content-length of zero + * + * If we don't give the user code the empty HTTP_BODY callback, + * he may become confused to hear the HTTP_BODY_COMPLETION (due + * to, eg, instantiation of lws_spa never happened). + * + * HTTP_BODY_COMPLETION is responsible for sending the result + * status code and result body if any, and to do the transaction + * complete processing. + */ + if (wsi->a.protocol->callback(wsi, LWS_CALLBACK_HTTP_BODY, + wsi->user_space, NULL, 0)) + return 1; + if (wsi->a.protocol->callback(wsi, LWS_CALLBACK_HTTP_BODY_COMPLETION, + wsi->user_space, NULL, 0)) + return 1; - if (wsi->http.rx_content_length > 0) { + return 0; + } - if (lwsi_state(wsi) != LRS_DISCARD_BODY) { - lwsi_set_state(wsi, LRS_BODY); - lwsl_info("%s: %p: LRS_BODY state set (0x%x)\n", - __func__, wsi, wsi->wsistate); - } - wsi->http.rx_content_remain = - wsi->http.rx_content_length; + if (wsi->http.rx_content_length <= 0) + return 0; - /* - * At this point we have transitioned from deferred - * action to expecting BODY on the stream wsi, if it's - * in a bundle like h2. So if the stream wsi has its - * own buflist, we need to deal with that first. - */ + if (lwsi_state(wsi) != LRS_DISCARD_BODY) { + lwsi_set_state(wsi, LRS_BODY); + lwsl_info("%s: %p: LRS_BODY state set (0x%x)\n", __func__, wsi, + (int)wsi->wsistate); + } + wsi->http.rx_content_remain = wsi->http.rx_content_length; - while (1) { - struct lws_tokens ebuf; - int m; - - ebuf.len = (int)lws_buflist_next_segment_len( - &wsi->buflist, - &ebuf.token); - if (!ebuf.len) - break; - lwsl_debug("%s: consuming %d\n", __func__, - (int)ebuf.len); - m = lws_read_h1(wsi, ebuf.token, - ebuf.len); - if (m < 0) - return -1; + /* + * At this point we have transitioned from deferred + * action to expecting BODY on the stream wsi, if it's + * in a bundle like h2. So if the stream wsi has its + * own buflist, we need to deal with that first. + */ - if (lws_buflist_aware_consume(wsi, &ebuf, m, 1)) - return -1; - } - } + while (1) { + struct lws_tokens ebuf; + int m; + + ebuf.len = (int)lws_buflist_next_segment_len(&wsi->buflist, + &ebuf.token); + if (!ebuf.len) + break; + + lwsl_debug("%s: consuming %d\n", __func__, (int)ebuf.len); + m = lws_read_h1(wsi, ebuf.token, ebuf.len); + if (m < 0) + return -1; + + if (lws_buflist_aware_finished_consuming(wsi, &ebuf, m, 1, + __func__)) + return -1; } return 0; @@ -1708,8 +1840,8 @@ { struct lws_tokenize ts; lws_tokenize_elem e; + int port = 80, n; char buf[128]; - int port = 80; /* * this vhost wants us to validate what the @@ -1730,19 +1862,20 @@ lws_tokenize_init(&ts, buf, LWS_TOKENIZE_F_DOT_NONTERM /* server.com */| LWS_TOKENIZE_F_NO_FLOATS /* 1.server.com */| LWS_TOKENIZE_F_MINUS_NONTERM /* a-b.com */); - ts.len = lws_hdr_copy(wsi, buf, sizeof(buf) - 1, WSI_TOKEN_HOST); - if (ts.len <= 0) { + n = lws_hdr_copy(wsi, buf, sizeof(buf) - 1, WSI_TOKEN_HOST); + if (n <= 0) { lwsl_info("%s: missing or oversize host header\n", __func__); return 1; } + ts.len = n; if (lws_tokenize(&ts) != LWS_TOKZE_TOKEN) goto bad_format; - if (strncmp(ts.token, wsi->vhost->name, ts.token_len)) { + if (strncmp(ts.token, wsi->a.vhost->name, ts.token_len)) { buf[(ts.token - buf) + ts.token_len] = '\0'; lwsl_info("%s: '%s' in host hdr but vhost name %s\n", - __func__, ts.token, wsi->vhost->name); + __func__, ts.token, wsi->a.vhost->name); return 1; } @@ -1756,9 +1889,9 @@ if (e != LWS_TOKZE_ENDED) goto bad_format; - if (wsi->vhost->listen_port != port) { + if (wsi->a.vhost->listen_port != port) { lwsl_info("%s: host port %d mismatches vhost port %d\n", - __func__, port, wsi->vhost->listen_port); + __func__, port, wsi->a.vhost->listen_port); return 1; } @@ -1772,23 +1905,23 @@ return 1; } -#if !defined(LWS_NO_SERVER) +#if defined(LWS_WITH_SERVER) int lws_http_to_fallback(struct lws *wsi, unsigned char *obuf, size_t olen) { const struct lws_role_ops *role = &role_ops_raw_skt; const struct lws_protocols *p1, *protocol = - &wsi->vhost->protocols[wsi->vhost->raw_protocol_index]; + &wsi->a.vhost->protocols[wsi->a.vhost->raw_protocol_index]; char ipbuf[64]; int n; - if (wsi->vhost->listen_accept_role && - lws_role_by_name(wsi->vhost->listen_accept_role)) - role = lws_role_by_name(wsi->vhost->listen_accept_role); - - if (wsi->vhost->listen_accept_protocol) { - p1 = lws_vhost_name_to_protocol(wsi->vhost, - wsi->vhost->listen_accept_protocol); + if (wsi->a.vhost->listen_accept_role && + lws_role_by_name(wsi->a.vhost->listen_accept_role)) + role = lws_role_by_name(wsi->a.vhost->listen_accept_role); + + if (wsi->a.vhost->listen_accept_protocol) { + p1 = lws_vhost_name_to_protocol(wsi->a.vhost, + wsi->a.vhost->listen_accept_protocol); if (p1) protocol = p1; } @@ -1801,8 +1934,8 @@ lws_set_timeout(wsi, NO_PENDING_TIMEOUT, 0); n = LWS_CALLBACK_SERVER_NEW_CLIENT_INSTANTIATED; - if (wsi->role_ops->adoption_cb[lwsi_role_server(wsi)]) - n = wsi->role_ops->adoption_cb[lwsi_role_server(wsi)]; + if (wsi->role_ops->adoption_cb[1]) + n = wsi->role_ops->adoption_cb[1]; ipbuf[0] = '\0'; #if !defined(LWS_PLAT_OPTEE) @@ -1810,16 +1943,17 @@ #endif lwsl_notice("%s: vh %s, peer: %s, role %s, " - "protocol %s, cb %d, ah %p\n", __func__, wsi->vhost->name, - ipbuf, role->name, protocol->name, n, wsi->http.ah); + "protocol %s, cb %d, ah %p\n", __func__, wsi->a.vhost->name, + ipbuf, role ? role->name : "null", protocol->name, n, + wsi->http.ah); - if ((wsi->protocol->callback)(wsi, n, wsi->user_space, NULL, 0)) + if ((wsi->a.protocol->callback)(wsi, n, wsi->user_space, NULL, 0)) return 1; n = LWS_CALLBACK_RAW_RX; if (wsi->role_ops->rx_cb[lwsi_role_server(wsi)]) n = wsi->role_ops->rx_cb[lwsi_role_server(wsi)]; - if (wsi->protocol->callback(wsi, n, wsi->user_space, obuf, olen)) + if (wsi->a.protocol->callback(wsi, n, wsi->user_space, obuf, olen)) return 1; return 0; @@ -1829,6 +1963,7 @@ lws_handshake_server(struct lws *wsi, unsigned char **buf, size_t len) { struct lws_context *context = lws_get_context(wsi); + struct lws_context_per_thread *pt = &context->pt[(int)wsi->tsi]; #if defined(LWS_WITH_HTTP2) struct allocated_headers *ah; #endif @@ -1852,7 +1987,7 @@ while (len) { if (!lwsi_role_server(wsi) || !lwsi_role_http(wsi)) { lwsl_err("%s: bad wsi role 0x%x\n", __func__, - lwsi_role(wsi)); + (int)lwsi_role(wsi)); goto bail_nuke_ah; } @@ -1890,6 +2025,10 @@ goto bail_nuke_ah; } + /* coverity... */ + if (!wsi->http.ah) + goto bail_nuke_ah; + if (wsi->http.ah->parser_state != WSI_PARSING_COMPLETE) continue; @@ -1897,10 +2036,10 @@ /* select vhost */ - if (wsi->vhost->listen_port && + if (wsi->a.vhost->listen_port && lws_hdr_total_length(wsi, WSI_TOKEN_HOST)) { struct lws_vhost *vhost = lws_select_vhost( - context, wsi->vhost->listen_port, + context, wsi->a.vhost->listen_port, lws_hdr_simple_ptr(wsi, WSI_TOKEN_HOST)); if (vhost) @@ -1909,18 +2048,22 @@ lwsl_info("no host\n"); if (!lwsi_role_h2(wsi) || !lwsi_role_server(wsi)) { - wsi->vhost->conn_stats.h1_trans++; +#if defined(LWS_WITH_SERVER_STATUS) + wsi->a.vhost->conn_stats.h1_trans++; +#endif if (!wsi->conn_stat_done) { - wsi->vhost->conn_stats.h1_conn++; +#if defined(LWS_WITH_SERVER_STATUS) + wsi->a.vhost->conn_stats.h1_conn++; +#endif wsi->conn_stat_done = 1; } } /* check for unwelcome guests */ - - if (wsi->context->reject_service_keywords) { +#if defined(LWS_WITH_HTTP_UNCOMMON_HEADERS) + if (wsi->a.context->reject_service_keywords) { const struct lws_protocol_vhost_options *rej = - wsi->context->reject_service_keywords; + wsi->a.context->reject_service_keywords; char ua[384], *msg = NULL; if (lws_hdr_copy(wsi, ua, sizeof(ua) - 1, @@ -1950,7 +2093,9 @@ /* wsi close will do the log */ #endif - wsi->vhost->conn_stats.rejected++; +#if defined(LWS_WITH_SERVER_STATUS) + wsi->a.vhost->conn_stats.rejected++; +#endif /* * We don't want anything from * this rejected guy. Follow @@ -1961,11 +2106,36 @@ } } } +#endif + /* + * So he may have come to us requesting one or another kind + * of upgrade from http... but we may want to redirect him at + * http level. In that case, we need to check the redirect + * situation even though he's not actually wanting http and + * prioritize returning that if there is one. + */ + + { + const struct lws_http_mount *hit = NULL; + int uri_len = 0, ha, n; + char *uri_ptr = NULL; + + n = lws_http_get_uri_and_method(wsi, &uri_ptr, &uri_len); + if (n >= 0) { + hit = lws_find_mount(wsi, uri_ptr, uri_len); + if (hit) { + n = lws_http_redirect_hit(pt, wsi, hit, uri_ptr, + uri_len, &ha); + if (ha) + return n; + } + } + } + if (lws_hdr_total_length(wsi, WSI_TOKEN_CONNECT)) { lwsl_info("Changing to RAW mode\n"); - m = 0; goto raw_transition; } @@ -1987,7 +2157,7 @@ goto bail_nuke_ah; } - n = user_callback_handle_rxflow(wsi->protocol->callback, + n = user_callback_handle_rxflow(wsi->a.protocol->callback, wsi, LWS_CALLBACK_HTTP_CONFIRM_UPGRADE, wsi->user_space, (char *)up, 0); @@ -2009,21 +2179,25 @@ /* callback said 0, it was allowed */ - if (wsi->vhost->options & + if (wsi->a.vhost->options & LWS_SERVER_OPTION_VHOST_UPG_STRICT_HOST_CHECK && lws_confirm_host_header(wsi)) goto bail_nuke_ah; if (!strcasecmp(up, "websocket")) { #if defined(LWS_ROLE_WS) - wsi->vhost->conn_stats.ws_upg++; +#if defined(LWS_WITH_SERVER_STATUS) + wsi->a.vhost->conn_stats.ws_upg++; +#endif lwsl_info("Upgrade to ws\n"); goto upgrade_ws; #endif } #if defined(LWS_WITH_HTTP2) if (!strcasecmp(up, "h2c")) { - wsi->vhost->conn_stats.h2_upg++; +#if defined(LWS_WITH_SERVER_STATUS) + wsi->a.vhost->conn_stats.h2_upg++; +#endif lwsl_info("Upgrade to h2c\n"); goto upgrade_h2c; } @@ -2035,7 +2209,9 @@ lwsl_info("%s: %p: No upgrade\n", __func__, wsi); lwsi_set_state(wsi, LRS_ESTABLISHED); +#if defined(LWS_WITH_FILE_OPS) wsi->http.fop_fd = NULL; +#endif #if defined(LWS_WITH_HTTP_STREAM_COMPRESSION) lws_http_compression_validate(wsi); @@ -2077,8 +2253,7 @@ wsi->http.ah = ah; if (!wsi->h2.h2n) { - wsi->h2.h2n = lws_zalloc(sizeof(*wsi->h2.h2n), - "h2n"); + wsi->h2.h2n = lws_zalloc(sizeof(*wsi->h2.h2n), "h2n"); if (!wsi->h2.h2n) return 1; } @@ -2087,9 +2262,9 @@ /* HTTP2 union */ - lws_h2_settings(wsi, &wsi->h2.h2n->set, (unsigned char *)tbuf, n); + lws_h2_settings(wsi, &wsi->h2.h2n->peer_set, (uint8_t *)tbuf, n); - lws_hpack_dynamic_size(wsi, wsi->h2.h2n->set.s[ + lws_hpack_dynamic_size(wsi, wsi->h2.h2n->peer_set.s[ H2SET_HEADER_TABLE_SIZE]); strcpy(tbuf, "HTTP/1.1 101 Switching Protocols\x0d\x0a" @@ -2123,10 +2298,13 @@ } #endif -LWS_VISIBLE int LWS_WARN_UNUSED_RESULT +int LWS_WARN_UNUSED_RESULT lws_http_transaction_completed(struct lws *wsi) { - int n = NO_PENDING_TIMEOUT; + int n; + + if (wsi->http.cgi_transaction_complete) + return 0; if (lws_has_buffered_out(wsi) #if defined(LWS_WITH_HTTP_STREAM_COMPRESSION) @@ -2178,7 +2356,11 @@ #endif lws_access_log(wsi); - if (!wsi->hdr_parsing_completed) { + if (!wsi->hdr_parsing_completed +#if defined(LWS_WITH_CGI) + && !wsi->http.cgi +#endif + ) { char peer[64]; #if !defined(LWS_PLAT_OPTEE) @@ -2187,13 +2369,26 @@ peer[0] = '\0'; #endif peer[sizeof(peer) - 1] = '\0'; - lwsl_notice("%s: (from %s) ignoring, ah parsing incomplete\n", + lwsl_info("%s: (from %s) ignoring, ah parsing incomplete\n", __func__, peer); return 0; } +#if defined(LWS_WITH_CGI) + if (wsi->http.cgi) { + lwsl_debug("%s: cleaning cgi\n", __func__); + wsi->http.cgi_transaction_complete = 1; + lws_cgi_remove_and_kill(wsi); + lws_spawn_piped_destroy(&wsi->http.cgi->lsp); + lws_sul_cancel(&wsi->http.cgi->sul_grace); + + lws_free_set_NULL(wsi->http.cgi); + wsi->http.cgi_transaction_complete = 0; + } +#endif + /* if we can't go back to accept new headers, drop the connection */ - if (wsi->http2_substream) + if (wsi->mux_substream) return 1; if (wsi->seen_zero_length_recv) @@ -2204,7 +2399,7 @@ return 1; } - if (lws_bind_protocol(wsi, &wsi->vhost->protocols[0], __func__)) + if (lws_bind_protocol(wsi, &wsi->a.vhost->protocols[0], __func__)) return 1; /* @@ -2213,8 +2408,8 @@ * until we can verify POLLOUT. The part of this that confirms POLLOUT * with no partials is in lws_server_socket_service() below. */ - lwsl_debug("%s: %p: setting DEF_ACT from 0x%x\n", __func__, - wsi, wsi->wsistate); + lwsl_debug("%s: %p: setting DEF_ACT from 0x%x: %p\n", __func__, + wsi, (int)wsi->wsistate, wsi->buflist); lwsi_set_state(wsi, LRS_DEFERRING_ACTION); wsi->http.tx_content_length = 0; wsi->http.tx_content_remain = 0; @@ -2223,16 +2418,16 @@ #ifdef LWS_WITH_ACCESS_LOG wsi->http.access_log.sent = 0; #endif - #if defined(LWS_WITH_FILE_OPS) && (defined(LWS_ROLE_H1) || defined(LWS_ROLE_H2)) - if (lwsi_role_http(wsi) && lwsi_role_server(wsi) && - wsi->http.fop_fd != NULL) - lws_vfs_file_close(&wsi->http.fop_fd); + if (lwsi_role_http(wsi) && lwsi_role_server(wsi) && + wsi->http.fop_fd != NULL) + lws_vfs_file_close(&wsi->http.fop_fd); #endif - if (wsi->vhost->keepalive_timeout) + n = NO_PENDING_TIMEOUT; + if (wsi->a.vhost->keepalive_timeout) n = PENDING_TIMEOUT_HTTP_KEEPALIVE_IDLE; - lws_set_timeout(wsi, n, wsi->vhost->keepalive_timeout); + lws_set_timeout(wsi, n, wsi->a.vhost->keepalive_timeout); /* * We already know we are on http1.1 / keepalive and the next thing @@ -2247,7 +2442,7 @@ * reset the existing header table and keep it. */ if (wsi->http.ah) { - // lws_buflist_describe(&wsi->buflist, wsi); + // lws_buflist_describe(&wsi->buflist, wsi, __func__); if (!lws_buflist_next_segment_len(&wsi->buflist, NULL)) { lwsl_debug("%s: %p: nothing in buflist, detaching ah\n", __func__, wsi); @@ -2259,10 +2454,10 @@ * SSL is scarce, drop this connection without waiting */ - if (wsi->vhost->tls.use_ssl && - wsi->context->simultaneous_ssl_restriction && - wsi->context->simultaneous_ssl == - wsi->context->simultaneous_ssl_restriction) { + if (wsi->a.vhost->tls.use_ssl && + wsi->a.context->simultaneous_ssl_restriction && + wsi->a.context->simultaneous_ssl == + wsi->a.context->simultaneous_ssl_restriction) { lwsl_info("%s: simultaneous_ssl_restriction\n", __func__); return 1; @@ -2279,7 +2474,7 @@ * open. */ lws_set_timeout(wsi, PENDING_TIMEOUT_HOLDING_AH, - wsi->vhost->keepalive_timeout); + wsi->a.vhost->keepalive_timeout); } /* If we're (re)starting on headers, need other implied init */ if (wsi->http.ah) @@ -2292,14 +2487,14 @@ lwsl_debug("acquired ah\n"); lwsl_debug("%s: %p: keep-alive await new transaction (state 0x%x)\n", - __func__, wsi, wsi->wsistate); + __func__, wsi, (int)wsi->wsistate); lws_callback_on_writable(wsi); return 0; } -#if !defined(LWS_AMAZON_RTOS) -LWS_VISIBLE int +#if defined(LWS_WITH_FILE_OPS) +int lws_serve_http_file(struct lws *wsi, const char *file, const char *content_type, const char *other_headers, int other_headers_len) { @@ -2332,9 +2527,9 @@ * If wsi->http.fop_fd is already set, the caller already opened it */ if (!wsi->http.fop_fd) { - fops = lws_vfs_select_fops(wsi->context->fops, file, &vpath); + fops = lws_vfs_select_fops(wsi->a.context->fops, file, &vpath); fflags |= lws_vfs_prepare_flags(wsi); - wsi->http.fop_fd = fops->LWS_FOP_OPEN(wsi->context->fops, + wsi->http.fop_fd = fops->LWS_FOP_OPEN(wsi->a.context->fops, file, vpath, &fflags); if (!wsi->http.fop_fd) { lwsl_info("%s: Unable to open: '%s': errno %d\n", @@ -2342,7 +2537,7 @@ if (lws_return_http_status(wsi, HTTP_STATUS_NOT_FOUND, NULL)) return -1; - return !wsi->http2_substream; + return !wsi->mux_substream; } } @@ -2486,7 +2681,7 @@ goto bail; #endif - if (!wsi->http2_substream) { + if (!wsi->mux_substream) { /* for http/1.1 ... */ if (!wsi->sending_chunked #if defined(LWS_WITH_HTTP_STREAM_COMPRESSION) @@ -2600,9 +2795,11 @@ } #endif -LWS_VISIBLE int lws_serve_http_file_fragment(struct lws *wsi) +#if defined(LWS_WITH_FILE_OPS) + +int lws_serve_http_file_fragment(struct lws *wsi) { - struct lws_context *context = wsi->context; + struct lws_context *context = wsi->a.context; struct lws_context_per_thread *pt = &context->pt[(int)wsi->tsi]; struct lws_process_html_args args; lws_filepos_t amount, poss; @@ -2612,7 +2809,7 @@ #endif int n, m; - lwsl_debug("wsi->http2_substream %d\n", wsi->http2_substream); + lwsl_debug("wsi->mux_substream %d\n", wsi->mux_substream); do { @@ -2651,10 +2848,7 @@ goto all_sent; n = 0; - - pstart = pt->serv_buf + LWS_H2_FRAME_HEADER_LENGTH; - - p = pstart; + p = pstart = pt->serv_buf + LWS_H2_FRAME_HEADER_LENGTH; #if defined(LWS_WITH_RANGES) if (wsi->http.range.count_ranges && !wsi->http.range.inside) { @@ -2699,27 +2893,33 @@ poss = wsi->http.tx_content_remain; /* - * if there is a hint about how much we will do well to send at + * If there is a hint about how much we will do well to send at * one time, restrict ourselves to only trying to send that. */ - if (wsi->protocol->tx_packet_size && - poss > wsi->protocol->tx_packet_size) - poss = wsi->protocol->tx_packet_size; + if (wsi->a.protocol->tx_packet_size && + poss > wsi->a.protocol->tx_packet_size) + poss = wsi->a.protocol->tx_packet_size; if (wsi->role_ops->tx_credit) { - lws_filepos_t txc = wsi->role_ops->tx_credit(wsi); + lws_filepos_t txc = + wsi->role_ops->tx_credit(wsi, LWSTXCR_US_TO_PEER, 0); if (!txc) { - lwsl_info("%s: came here with no tx credit\n", - __func__); + /* + * We shouldn't've been able to get the + * WRITEABLE if we are skint + */ + lwsl_notice("%s: %p: no tx credit\n", __func__, + wsi); + return 0; } if (txc < poss) poss = txc; /* - * consumption of the actual payload amount sent will be - * handled when the role data frame is sent + * Tracking consumption of the actual payload amount + * will be handled when the role data frame is sent... */ } @@ -2738,6 +2938,7 @@ poss -= 10 + 128; } + amount = 0; if (lws_vfs_file_read(wsi->http.fop_fd, &amount, p, poss) < 0) goto file_had_it; /* caller will close */ @@ -2760,7 +2961,7 @@ wsi->http.filelen; args.chunked = wsi->sending_chunked; if (user_callback_handle_rxflow( - wsi->vhost->protocols[ + wsi->a.vhost->protocols[ (int)wsi->protocol_interpret_idx].callback, wsi, LWS_CALLBACK_PROCESS_HTML, wsi->user_space, &args, 0) < 0) @@ -2832,8 +3033,8 @@ lwsl_debug("file completed\n"); - if (wsi->protocol->callback && - user_callback_handle_rxflow(wsi->protocol->callback, + if (wsi->a.protocol->callback && + user_callback_handle_rxflow(wsi->a.protocol->callback, wsi, LWS_CALLBACK_HTTP_FILE_COMPLETION, wsi->user_space, NULL, 0) < 0) { /* @@ -2850,7 +3051,7 @@ * state, not the root connection at the * network level */ - if (wsi->http2_substream) + if (wsi->mux_substream) return 1; else return -1; @@ -2875,18 +3076,22 @@ return -1; } -#ifndef LWS_NO_SERVER -LWS_VISIBLE void +#endif + +#if defined(LWS_WITH_SERVER) +void lws_server_get_canonical_hostname(struct lws_context *context, const struct lws_context_creation_info *info) { if (lws_check_opt(info->options, LWS_SERVER_OPTION_SKIP_SERVER_CANONICAL_NAME)) return; -#if !defined(LWS_WITH_ESP32) +#if !defined(LWS_PLAT_FREERTOS) /* find canonical hostname */ - gethostname((char *)context->canonical_hostname, - sizeof(context->canonical_hostname) - 1); + if (gethostname((char *)context->canonical_hostname, + sizeof(context->canonical_hostname) - 1)) + lws_strncpy((char *)context->canonical_hostname, "unknown", + sizeof(context->canonical_hostname)); lwsl_info(" canonical_hostname = %s\n", context->canonical_hostname); #else @@ -2895,7 +3100,7 @@ } #endif -LWS_VISIBLE LWS_EXTERN int +int lws_chunked_html_process(struct lws_process_html_args *args, struct lws_process_html_state *s) { diff -Nru libwebsockets-3.2.1/lib/roles/listen/CMakeLists.txt libwebsockets-4.1.6/lib/roles/listen/CMakeLists.txt --- libwebsockets-3.2.1/lib/roles/listen/CMakeLists.txt 1970-01-01 00:00:00.000000000 +0000 +++ libwebsockets-4.1.6/lib/roles/listen/CMakeLists.txt 2020-12-01 17:40:26.000000000 +0000 @@ -0,0 +1,42 @@ +# +# libwebsockets - small server side websockets and web server implementation +# +# Copyright (C) 2010 - 2020 Andy Green +# +# Permission is hereby granted, free of charge, to any person obtaining a copy +# of this software and associated documentation files (the "Software"), to +# deal in the Software without restriction, including without limitation the +# rights to use, copy, modify, merge, publish, distribute, sublicense, and/or +# sell copies of the Software, and to permit persons to whom the Software is +# furnished to do so, subject to the following conditions: +# +# The above copyright notice and this permission notice shall be included in +# all copies or substantial portions of the Software. +# +# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING +# FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS +# IN THE SOFTWARE. +# +# The strategy is to only export to PARENT_SCOPE +# +# - changes to LIB_LIST +# - changes to SOURCES +# - includes via include_directories +# +# and keep everything else private + +include_directories(.) + +list(APPEND SOURCES + roles/listen/ops-listen.c) + +# +# Keep explicit parent scope exports at end +# + +exports_to_parent_scope() + diff -Nru libwebsockets-3.2.1/lib/roles/listen/ops-listen.c libwebsockets-4.1.6/lib/roles/listen/ops-listen.c --- libwebsockets-3.2.1/lib/roles/listen/ops-listen.c 2019-12-18 14:45:31.000000000 +0000 +++ libwebsockets-4.1.6/lib/roles/listen/ops-listen.c 2020-12-01 17:40:26.000000000 +0000 @@ -1,39 +1,42 @@ /* * libwebsockets - small server side websockets and web server implementation * - * Copyright (C) 2010-2018 Andy Green + * Copyright (C) 2010 - 2019 Andy Green * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation: - * version 2.1 of the License. + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to + * deal in the Software without restriction, including without limitation the + * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or + * sell copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: * - * This library is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. * - * You should have received a copy of the GNU Lesser General Public - * License along with this library; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, - * MA 02110-1301 USA + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS + * IN THE SOFTWARE. */ -#include +#include static int rops_handle_POLLIN_listen(struct lws_context_per_thread *pt, struct lws *wsi, struct lws_pollfd *pollfd) { - struct lws_context *context = wsi->context; - lws_sockfd_type accept_fd = LWS_SOCK_INVALID; + struct lws_context *context = wsi->a.context; + struct lws_filter_network_conn_args filt; lws_sock_file_fd_type fd; - struct sockaddr_storage cli_addr; - socklen_t clilen; + + memset(&filt, 0, sizeof(filt)); /* if our vhost is going down, ignore it */ - if (wsi->vhost->being_destroyed) + if (wsi->a.vhost->being_destroyed) return LWS_HPI_RET_HANDLED; /* pollin means a client has connected to us then @@ -56,7 +59,7 @@ * another vhost may also have had POLLIN on his * listener this round and used it up already */ - if (wsi->vhost->tls.use_ssl && + if (wsi->a.vhost->tls.use_ssl && context->simultaneous_ssl_restriction && context->simultaneous_ssl == context->simultaneous_ssl_restriction) @@ -69,8 +72,7 @@ #endif /* listen socket got an unencrypted connection... */ - clilen = sizeof(cli_addr); - lws_latency_pre(context, wsi); + filt.clilen = sizeof(filt.cli_addr); /* * We cannot identify the peer who is in the listen @@ -79,39 +81,41 @@ * block the connect queue for other legit peers. */ - accept_fd = accept((int)pollfd->fd, - (struct sockaddr *)&cli_addr, &clilen); - lws_latency(context, wsi, "listener accept", - (int)accept_fd, accept_fd != LWS_SOCK_INVALID); - if (accept_fd == LWS_SOCK_INVALID) { + filt.accept_fd = accept((int)pollfd->fd, + (struct sockaddr *)&filt.cli_addr, + &filt.clilen); + if (filt.accept_fd == LWS_SOCK_INVALID) { if (LWS_ERRNO == LWS_EAGAIN || LWS_ERRNO == LWS_EWOULDBLOCK) { break; } - lwsl_err("accept: %s\n", strerror(LWS_ERRNO)); + lwsl_err("accept: errno %d\n", LWS_ERRNO); + return LWS_HPI_RET_HANDLED; } if (context->being_destroyed) { - compatible_close(accept_fd); + compatible_close(filt.accept_fd); + return LWS_HPI_RET_PLEASE_CLOSE_ME; } - lws_plat_set_socket_options(wsi->vhost, accept_fd, 0); + lws_plat_set_socket_options(wsi->a.vhost, filt.accept_fd, 0); #if defined(LWS_WITH_IPV6) lwsl_debug("accepted new conn port %u on fd=%d\n", - ((cli_addr.ss_family == AF_INET6) ? - ntohs(((struct sockaddr_in6 *) &cli_addr)->sin6_port) : - ntohs(((struct sockaddr_in *) &cli_addr)->sin_port)), - accept_fd); + ((filt.cli_addr.ss_family == AF_INET6) ? + ntohs(((struct sockaddr_in6 *) &filt.cli_addr)->sin6_port) : + ntohs(((struct sockaddr_in *) &filt.cli_addr)->sin_port)), + filt.accept_fd); #else { struct sockaddr_in sain; - memcpy(&sain, &cli_addr, sizeof(sain)); + + memcpy(&sain, &filt.cli_addr, sizeof(sain)); lwsl_debug("accepted new conn port %u on fd=%d\n", ntohs(sain.sin_port), - accept_fd); + filt.accept_fd); } #endif @@ -121,35 +125,36 @@ * protocol selected yet so we issue this to * protocols[0] */ - if ((wsi->vhost->protocols[0].callback)(wsi, + if ((wsi->a.vhost->protocols[0].callback)(wsi, LWS_CALLBACK_FILTER_NETWORK_CONNECTION, - NULL, - (void *)(lws_intptr_t)accept_fd, 0)) { + (void *)&filt, + (void *)(lws_intptr_t)filt.accept_fd, 0)) { lwsl_debug("Callback denied net connection\n"); - compatible_close(accept_fd); - return LWS_HPI_RET_PLEASE_CLOSE_ME; + compatible_close(filt.accept_fd); + return LWS_HPI_RET_HANDLED; } - if (!(wsi->vhost->options & + if (!(wsi->a.vhost->options & LWS_SERVER_OPTION_ADOPT_APPLY_LISTEN_ACCEPT_CONFIG)) opts |= LWS_ADOPT_HTTP; #if defined(LWS_WITH_TLS) - if (!wsi->vhost->tls.use_ssl) + if (!wsi->a.vhost->tls.use_ssl) #endif opts &= ~LWS_ADOPT_ALLOW_SSL; - fd.sockfd = accept_fd; - cwsi = lws_adopt_descriptor_vhost(wsi->vhost, opts, fd, - NULL, NULL); + fd.sockfd = filt.accept_fd; + cwsi = lws_adopt_descriptor_vhost(wsi->a.vhost, opts, fd, + wsi->a.vhost->listen_accept_protocol, NULL); if (!cwsi) { - lwsl_err("%s: lws_adopt_descriptor_vhost failed\n", - __func__); + lwsl_info("%s: vh %s: adopt failed\n", __func__, + wsi->a.vhost->name); + /* already closed cleanly as necessary */ return LWS_HPI_RET_WSI_ALREADY_DIED; } /* - if (lws_server_socket_service_ssl(cwsi, accept_fd)) { + if (lws_server_socket_service_ssl(cwsi, accept_fd, 1)) { lws_close_free_wsi(cwsi, LWS_CLOSE_STATUS_NOSTATUS, "listen svc fail"); return LWS_HPI_RET_WSI_ALREADY_DIED; @@ -172,14 +177,13 @@ return LWS_HP_RET_USER_SERVICE; } -struct lws_role_ops role_ops_listen = { +const struct lws_role_ops role_ops_listen = { /* role name */ "listen", /* alpn id */ NULL, /* check_upgrades */ NULL, - /* init_context */ NULL, + /* pt_init_destroy */ NULL, /* init_vhost */ NULL, /* destroy_vhost */ NULL, - /* periodic_checks */ NULL, /* service_flag_pending */ NULL, /* handle_POLLIN */ rops_handle_POLLIN_listen, /* handle_POLLOUT */ rops_handle_POLLOUT_listen, @@ -195,6 +199,7 @@ /* destroy_role */ NULL, /* adoption_bind */ NULL, /* client_bind */ NULL, + /* issue_keepalive */ NULL, /* adoption_cb clnt, srv */ { 0, 0 }, /* rx_cb clnt, srv */ { 0, 0 }, /* writeable cb clnt, srv */ { 0, 0 }, diff -Nru libwebsockets-3.2.1/lib/roles/mqtt/client/client-mqtt.c libwebsockets-4.1.6/lib/roles/mqtt/client/client-mqtt.c --- libwebsockets-3.2.1/lib/roles/mqtt/client/client-mqtt.c 1970-01-01 00:00:00.000000000 +0000 +++ libwebsockets-4.1.6/lib/roles/mqtt/client/client-mqtt.c 2020-12-01 17:40:26.000000000 +0000 @@ -0,0 +1,396 @@ +/* + * libwebsockets - small server side websockets and web server implementation + * + * Copyright (C) 2010 - 2020 Andy Green + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to + * deal in the Software without restriction, including without limitation the + * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or + * sell copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS + * IN THE SOFTWARE. + */ + +/* + * You can leave buf NULL, if so it will be allocated on the heap once the + * actual length is known. nf should be 0, it will be set at allocation time. + * + * Or you can ensure no allocation and use an external buffer by setting buf + * and lim. But buf must be in the ep context somehow, since it may have to + * survive returns to the event loop unchanged. Set nf to 0 in this case. + * + * Or you can set buf to an externally allocated buffer, in which case you may + * set nf so it will be freed when the string is "freed". + */ + +#include "private-lib-core.h" +/* #include "lws-mqtt.h" */ +/* 3.1.3.1-5: MUST allow... that contain only the characters... */ + +static const uint8_t *code = (const uint8_t *) + "0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ"; + +static int +lws_mqtt_generate_id(struct lws* wsi, lws_mqtt_str_t **ms, const char *client_id) +{ + struct lws_context *context = wsi->a.context; + uint16_t ran[24]; /* 16-bit so wrap bias from %62 diluted by ~1000 */ + size_t n, len; + uint8_t *buf; + + if (client_id) + len = strlen(client_id); + else + len = 23; + + if (len > 23) /* 3.1.3.1-5: Server MUST... between 1 and 23 chars... */ + return 1; + + *ms = lws_mqtt_str_create((uint16_t)(len + 1)); + if (!*ms) + return 1; + + buf = lws_mqtt_str_next(*ms, NULL); + + if (client_id) { + lws_strnncpy((char *)buf, client_id, len, len + 1); + lwsl_notice("%s: User space provided a client ID '%s'\n", + __func__, (const char *)buf); + } else { + lwsl_notice("%s: generating random client id\n", __func__); + n = len * sizeof(ran[0]); + if (lws_get_random(context, ran, n) != n) { + lws_mqtt_str_free(ms); + + return 1; + } + + for (n = 0; n < len; n++) + buf[n] = code[ran[n] % 62]; + buf[len] = '\0'; + } + + if (lws_mqtt_str_advance(*ms, (uint16_t)len)) { + lws_mqtt_str_free(ms); + + return 1; + } + + return 0; +} + +int +lws_read_mqtt(struct lws *wsi, unsigned char *buf, lws_filepos_t len) +{ + lws_mqttc_t *c = &wsi->mqtt->client; + + return _lws_mqtt_rx_parser(wsi, &c->par, buf, len); +} + +int +lws_create_client_mqtt_object(const struct lws_client_connect_info *i, + struct lws *wsi) +{ + lws_mqttc_t *c; + const lws_mqtt_client_connect_param_t *cp = i->mqtt_cp; + + /* allocate the ws struct for the wsi */ + wsi->mqtt = lws_zalloc(sizeof(*wsi->mqtt), "client mqtt struct"); + if (!wsi->mqtt) + goto oom; + + wsi->mqtt->wsi = wsi; + c = &wsi->mqtt->client; + + if (lws_mqtt_generate_id(wsi, &c->id, cp->client_id)) { + lwsl_err("%s: Error generating client ID\n", __func__); + return 1; + } + lwsl_info("%s: using client id '%.*s'\n", __func__, c->id->len, + (const char *)c->id->buf); + + if (cp->clean_start || !cp->client_id[0]) + c->conn_flags = LMQCFT_CLEAN_START; + + c->keep_alive_secs = cp->keep_alive; + + if (cp->will_param.topic && + *cp->will_param.topic) { + c->will.topic = lws_mqtt_str_create_cstr_dup( + cp->will_param.topic, 0); + if (!c->will.topic) + goto oom1; + c->conn_flags |= LMQCFT_WILL_FLAG; + if (cp->will_param.message) { + c->will.message = lws_mqtt_str_create_cstr_dup( + cp->will_param.message, 0); + if (!c->will.message) + goto oom2; + } + c->conn_flags |= (cp->will_param.qos << 3) & LMQCFT_WILL_QOS_MASK; + c->conn_flags |= (!!cp->will_param.retain) * LMQCFT_WILL_RETAIN; + } + + if (cp->username && + *cp->username) { + c->username = lws_mqtt_str_create_cstr_dup(cp->username, 0); + if (!c->username) + goto oom3; + c->conn_flags |= LMQCFT_USERNAME; + if (cp->password) { + c->password = + lws_mqtt_str_create_cstr_dup(cp->password, 0); + if (!c->password) + goto oom4; + c->conn_flags |= LMQCFT_PASSWORD; + } + } + + return 0; +oom4: + lws_mqtt_str_free(&c->username); +oom3: + lws_mqtt_str_free(&c->will.message); +oom2: + lws_mqtt_str_free(&c->will.topic); +oom1: + lws_mqtt_str_free(&c->id); +oom: + lwsl_err("%s: OOM!\n", __func__); + return 1; +} + +int +lws_mqtt_client_socket_service(struct lws *wsi, struct lws_pollfd *pollfd, + struct lws *wsi_conn) +{ + struct lws_context *context = wsi->a.context; + struct lws_context_per_thread *pt = &context->pt[(int)wsi->tsi]; + int n = 0, m = 0; + struct lws_tokens ebuf; + int buffered = 0; + char pending = 0; +#if defined(LWS_WITH_TLS) + char erbuf[128]; +#endif + const char *cce = NULL; + + switch (lwsi_state(wsi)) { +#if defined(LWS_WITH_SOCKS5) + /* SOCKS Greeting Reply */ + case LRS_WAITING_SOCKS_GREETING_REPLY: + case LRS_WAITING_SOCKS_AUTH_REPLY: + case LRS_WAITING_SOCKS_CONNECT_REPLY: + + switch (lws_socks5c_handle_state(wsi, pollfd, &cce)) { + case LW5CHS_RET_RET0: + return 0; + case LW5CHS_RET_BAIL3: + goto bail3; + case LW5CHS_RET_STARTHS: + + /* + * Now we got the socks5 connection, we need to go down + * the tls path on it if that's what we want + */ + + if (!(wsi->tls.use_ssl & LCCSCF_USE_SSL)) + goto start_ws_handshake; + + switch (lws_client_create_tls(wsi, &cce, 0)) { + case 0: + break; + case 1: + return 0; + default: + goto bail3; + } + + break; + + default: + break; + } + break; +#endif + case LRS_WAITING_DNS: + /* + * we are under PENDING_TIMEOUT_SENT_CLIENT_HANDSHAKE + * timeout protection set in client-handshake.c + */ + if (!lws_client_connect_2_dnsreq(wsi)) { + /* closed */ + lwsl_client("closed\n"); + return -1; + } + + /* either still pending connection, or changed mode */ + return 0; + + case LRS_WAITING_CONNECT: + + /* + * we are under PENDING_TIMEOUT_SENT_CLIENT_HANDSHAKE + * timeout protection set in client-handshake.c + */ + if (pollfd->revents & LWS_POLLOUT) + lws_client_connect_3_connect(wsi, NULL, NULL, 0, NULL); + break; + +#if defined(LWS_WITH_TLS) + case LRS_WAITING_SSL: + + if (wsi->tls.use_ssl & LCCSCF_USE_SSL) { + n = lws_ssl_client_connect2(wsi, erbuf, sizeof(erbuf)); + if (!n) + return 0; + if (n < 0) { + cce = erbuf; + goto bail3; + } + } else + wsi->tls.ssl = NULL; +#endif /* LWS_WITH_TLS */ + +#if defined(LWS_WITH_DETAILED_LATENCY) + if (context->detailed_latency_cb) { + wsi->detlat.type = LDLT_TLS_NEG_CLIENT; + wsi->detlat.latencies[LAT_DUR_PROXY_CLIENT_REQ_TO_WRITE] = + lws_now_usecs() - + wsi->detlat.earliest_write_req_pre_write; + wsi->detlat.latencies[LAT_DUR_USERCB] = 0; + lws_det_lat_cb(wsi->a.context, &wsi->detlat); + } +#endif +#if 0 + if (wsi->client_h2_alpn) { + /* + * We connected to the server and set up tls, and + * negotiated "h2". + * + * So this is it, we are an h2 master client connection + * now, not an h1 client connection. + */ +#if defined(LWS_WITH_TLS) + lws_tls_server_conn_alpn(wsi); +#endif + + /* send the H2 preface to legitimize the connection */ + if (lws_h2_issue_preface(wsi)) { + cce = "error sending h2 preface"; + goto bail3; + } + + break; + } +#endif + + /* fallthru */ + +#if defined(LWS_WITH_SOCKS5) +start_ws_handshake: +#endif + lwsi_set_state(wsi, LRS_MQTTC_IDLE); + lws_set_timeout(wsi, PENDING_TIMEOUT_AWAITING_CLIENT_HS_SEND, + context->timeout_secs); + + /* fallthru */ + + case LRS_MQTTC_IDLE: + /* + * we should be ready to send out MQTT CONNECT + */ + lwsl_info("%s: wsi %p: Transport established, send out CONNECT\n", + __func__, wsi); + if (lws_change_pollfd(wsi, LWS_POLLOUT, 0)) + return -1; + if (!lws_mqtt_client_send_connect(wsi)) { + lwsl_err("%s: Unable to send MQTT CONNECT\n", __func__); + return -1; + } + if (lws_change_pollfd(wsi, 0, LWS_POLLIN)) + return -1; + + lwsi_set_state(wsi, LRS_MQTTC_AWAIT_CONNACK); + return 0; + + case LRS_ESTABLISHED: + case LRS_MQTTC_AWAIT_CONNACK: + buffered = 0; + ebuf.token = pt->serv_buf; + ebuf.len = wsi->a.context->pt_serv_buf_size; + + if ((unsigned int)ebuf.len > wsi->a.context->pt_serv_buf_size) + ebuf.len = wsi->a.context->pt_serv_buf_size; + + if ((int)pending > ebuf.len) + pending = ebuf.len; + + ebuf.len = lws_ssl_capable_read(wsi, ebuf.token, + pending ? (int)pending : + ebuf.len); + switch (ebuf.len) { + case 0: + lwsl_info("%s: zero length read\n", + __func__); + goto fail; + case LWS_SSL_CAPABLE_MORE_SERVICE: + lwsl_info("SSL Capable more service\n"); + return 0; + case LWS_SSL_CAPABLE_ERROR: + lwsl_info("%s: LWS_SSL_CAPABLE_ERROR\n", + __func__); + goto fail; + } + + if (ebuf.len < 0) + n = -1; + else + n = lws_read_mqtt(wsi, ebuf.token, ebuf.len); + if (n < 0) { + lwsl_err("%s: Parsing packet failed\n", __func__); + goto fail; + } + + m = ebuf.len - n; + // lws_buflist_describe(&wsi->buflist, wsi, __func__); + lwsl_debug("%s: consuming %d / %d\n", __func__, n, ebuf.len); + if (lws_buflist_aware_finished_consuming(wsi, &ebuf, m, + buffered, + __func__)) + return -1; + + return 0; + +#if defined(LWS_WITH_TLS) || defined(LWS_WITH_SOCKS5) +bail3: +#endif + lwsl_info("closing conn at LWS_CONNMODE...SERVER_REPLY\n"); + if (cce) + lwsl_info("reason: %s\n", cce); + lws_inform_client_conn_fail(wsi, (void *)cce, strlen(cce)); + + lws_close_free_wsi(wsi, LWS_CLOSE_STATUS_NOSTATUS, "cbail3"); + return -1; + + default: + break; + } + + return 0; +fail: + lws_close_free_wsi(wsi, LWS_CLOSE_STATUS_NOSTATUS, "mqtt svc fail"); + + return LWS_HPI_RET_WSI_ALREADY_DIED; +} diff -Nru libwebsockets-3.2.1/lib/roles/mqtt/client/client-mqtt-handshake.c libwebsockets-4.1.6/lib/roles/mqtt/client/client-mqtt-handshake.c --- libwebsockets-3.2.1/lib/roles/mqtt/client/client-mqtt-handshake.c 1970-01-01 00:00:00.000000000 +0000 +++ libwebsockets-4.1.6/lib/roles/mqtt/client/client-mqtt-handshake.c 2020-12-01 17:40:26.000000000 +0000 @@ -0,0 +1,182 @@ +/* + * libwebsockets - small server side websockets and web server implementation + * + * Copyright (C) 2010 - 2020 Andy Green + * Sakthi Kannan + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to + * deal in the Software without restriction, including without limitation the + * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or + * sell copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS + * IN THE SOFTWARE. + */ + +#include + +#define MQTT_CONNECT_MSG_BASE_LEN (12) + +struct lws * +lws_mqtt_client_send_connect(struct lws *wsi) +{ + /* static int */ + /* lws_mqttc_abs_writeable(lws_abs_protocol_inst_t *api, size_t budget) */ + const lws_mqttc_t *c = &wsi->mqtt->client; + uint8_t b[256 + LWS_PRE], *start = b + LWS_PRE, *p = start, + len = MQTT_CONNECT_MSG_BASE_LEN; + + switch (lwsi_state(wsi)) { + case LRS_MQTTC_IDLE: + /* + * Transport connected - this is our chance to do the + * protocol connect action. + */ + + /* 1. Fixed Headers */ + if (lws_mqtt_fill_fixed_header(p++, LMQCP_CTOS_CONNECT, 0, 0, 0)) { + lwsl_err("%s: Failled to fill fixed header\n", __func__); + return NULL; + } + + /* + * 2. Remaining length - Add the lengths of client ID, + * username and password and their length fields if + * the respective flags are set. + */ + len += c->id->len; + if (c->conn_flags & LMQCFT_USERNAME && c->username) { + len += c->username->len + 2; + if (c->conn_flags & LMQCFT_PASSWORD) + len += (c->password ? c->password->len : 0) + 2; + } + if (c->conn_flags & LMQCFT_WILL_FLAG && c->will.topic) { + len += c->will.topic->len + 2; + len += (c->will.message ? c->will.message->len : 0) + 2; + } + p += lws_mqtt_vbi_encode(len, p); + + /* + * 3. Variable Header - Protocol name & level, Connect + * flags and keep alive time (in secs). + */ + lws_ser_wu16be(p, 4); /* Length of protocol name */ + p += 2; + *p++ = 'M'; + *p++ = 'Q'; + *p++ = 'T'; + *p++ = 'T'; + *p++ = MQTT_VER_3_1_1; + *p++ = c->conn_flags; + lws_ser_wu16be(p, c->keep_alive_secs); + p += 2; + + /* + * 4. Payload - Client ID, Will topic & message, + * Username & password. + */ + if (lws_mqtt_str_is_not_empty(c->id)) { + lws_ser_wu16be(p, c->id->len); + p += 2; + memcpy(p, c->id->buf, c->id->len); + p += c->id->len; + } else { + /* + * If the Client supplies a zero-byte + * ClientId, the Client MUST also set + * CleanSession to 1 [MQTT-3.1.3-7]. + */ + if (!(c->conn_flags & LMQCFT_CLEAN_START)) { + lwsl_err("%s: Empty client ID needs a clean start\n", + __func__); + return NULL; + } + *p++ = 0; + } + + if ((c->conn_flags & ~LMQCFT_CLEAN_START) == 0) { + *p++ = 0; /* no properties */ + break; + } + if (c->conn_flags & LMQCFT_WILL_FLAG) { + if (lws_mqtt_str_is_not_empty(c->will.topic)) { + lws_ser_wu16be(p, c->will.topic->len); + p += 2; + memcpy(p, c->will.topic->buf, c->will.topic->len); + p += c->will.topic->len; + if (lws_mqtt_str_is_not_empty(c->will.message)) { + lws_ser_wu16be(p, c->will.topic->len); + p += 2; + memcpy(p, c->will.message->buf, + c->will.message->len); + p += c->will.message->len; + } else { + lws_ser_wu16be(p, 0); + p += 2; + } + } else { + lwsl_err("%s: Missing Will Topic\n", __func__); + return NULL; + } + } + if (c->conn_flags & LMQCFT_USERNAME) { + /* + * Detailed sanity check on the username and + * password strings. + */ + if (lws_mqtt_str_is_not_empty(c->username)) { + lws_ser_wu16be(p, c->username->len); + p += 2; + memcpy(p, c->username->buf, c->username->len); + p += c->username->len; + } else { + lwsl_err("%s: Empty / missing Username!\n", + __func__); + return NULL; + } + if (c->conn_flags & LMQCFT_PASSWORD) { + if (lws_mqtt_str_is_not_empty(c->password)) { + lws_ser_wu16be(p, c->password->len); + p += 2; + memcpy(p, c->password->buf, + c->password->len); + p += c->password->len; + } else { + lws_ser_wu16be(p, 0); + p += 2; + } + } + } else if (c->conn_flags & LMQCFT_PASSWORD) { + lwsl_err("%s: Unsupported - Password without username\n", + __func__); + return NULL; + } + break; + default: + lwsl_err("%s: unexpected state %d\n", __func__, lwsi_state(wsi)); + + return NULL; + } + + /* + * Perform the actual write + */ + if (lws_write(wsi, (unsigned char *)&b[LWS_PRE], lws_ptr_diff(p, start), + LWS_WRITE_BINARY) != lws_ptr_diff(p, start)) { + lwsl_notice("%s: write failed\n", __func__); + + return NULL; + } + + return wsi; +} diff -Nru libwebsockets-3.2.1/lib/roles/mqtt/CMakeLists.txt libwebsockets-4.1.6/lib/roles/mqtt/CMakeLists.txt --- libwebsockets-3.2.1/lib/roles/mqtt/CMakeLists.txt 1970-01-01 00:00:00.000000000 +0000 +++ libwebsockets-4.1.6/lib/roles/mqtt/CMakeLists.txt 2020-12-01 17:40:26.000000000 +0000 @@ -0,0 +1,48 @@ +# +# libwebsockets - small server side websockets and web server implementation +# +# Copyright (C) 2010 - 2020 Andy Green +# +# Permission is hereby granted, free of charge, to any person obtaining a copy +# of this software and associated documentation files (the "Software"), to +# deal in the Software without restriction, including without limitation the +# rights to use, copy, modify, merge, publish, distribute, sublicense, and/or +# sell copies of the Software, and to permit persons to whom the Software is +# furnished to do so, subject to the following conditions: +# +# The above copyright notice and this permission notice shall be included in +# all copies or substantial portions of the Software. +# +# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING +# FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS +# IN THE SOFTWARE. +# +# The strategy is to only export to PARENT_SCOPE +# +# - changes to LIB_LIST +# - changes to SOURCES +# - includes via include_directories +# +# and keep everything else private + +include_directories(.) + +if (LWS_WITH_CLIENT) + list(APPEND SOURCES + roles/mqtt/mqtt.c + roles/mqtt/ops-mqtt.c + roles/mqtt/primitives.c + roles/mqtt/client/client-mqtt.c + roles/mqtt/client/client-mqtt-handshake.c + ) +endif() + +# +# Keep explicit parent scope exports at end +# + +exports_to_parent_scope() diff -Nru libwebsockets-3.2.1/lib/roles/mqtt/mqtt.c libwebsockets-4.1.6/lib/roles/mqtt/mqtt.c --- libwebsockets-3.2.1/lib/roles/mqtt/mqtt.c 1970-01-01 00:00:00.000000000 +0000 +++ libwebsockets-4.1.6/lib/roles/mqtt/mqtt.c 2020-12-01 17:40:26.000000000 +0000 @@ -0,0 +1,2125 @@ +/* + * libwebsockets - small server side websockets and web server implementation + * + * Copyright (C) 2010 - 2020 Andy Green + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to + * deal in the Software without restriction, including without limitation the + * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or + * sell copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS + * IN THE SOFTWARE. + * + * MQTT v5 + * + * http://docs.oasis-open.org/mqtt/mqtt/v5.0/mqtt-v5.0.html + * + * Control Packet structure + * + * - Always: 2+ byte: Fixed Hdr + * - Required in some: variable: Variable Hdr + [(CONNECT)Will Props] + Props + * - Required in some: variable: Payload + * + * For CONNECT, the props if present MUST be in the order [MQTT-3.1.3-1] + * + * - Client Identifier + * - Will Properties + * - Will Topic + * - Will Payload + * - User Name + * - Password + */ + +#include "private-lib-core.h" +#include +#include +#include + +typedef enum { + LMQPRS_AWAITING_CONNECT, + +} lws_mqtt_protocol_server_connstate_t; + +const char * const reason_names_g1[] = { + "Success / Normal disconnection / QoS0", + "QoS1", + "QoS2", + "Disconnect Will", + "No matching subscriber", + "No subscription existed", + "Continue authentication", + "Re-authenticate" +}; + +const char * const reason_names_g2[] = { + "Unspecified error", + "Malformed packet", + "Protocol error", + "Implementation specific error", + "Unsupported protocol", + "Client ID invalid", + "Bad credentials", + "Not Authorized", + "Server Unavailable", + "Server Busy", + "Banned", + "Server Shutting Down", + "Bad Authentication Method", + "Keepalive Timeout", + "Session taken over", + "Topic Filter Invalid", + "Packet ID in use", + "Packet ID not found", + "Max RX Exceeded", + "Topic Alias Invalid", + "Packet too large", + "Ratelimit", + "Quota Exceeded", + "Administrative Action", + "Payload format invalid", + "Retain not supported", + "QoS not supported", + "Use another server", + "Server Moved", + "Shared subscriptions not supported", + "Connection rate exceeded", + "Maximum Connect Time", + "Subscription IDs not supported", + "Wildcard subscriptions not supported" +}; + +#define LMQCP_WILL_PROPERTIES 0 + +/* For each property, a bitmap describing which commands it is valid for */ + +static const uint16_t property_valid[] = { + [LMQPROP_PAYLOAD_FORMAT_INDICATOR] = (1 << LMQCP_PUBLISH) | + (1 << LMQCP_WILL_PROPERTIES), + [LMQPROP_MESSAGE_EXPIRY_INTERVAL] = (1 << LMQCP_PUBLISH) | + (1 << LMQCP_WILL_PROPERTIES), + [LMQPROP_CONTENT_TYPE] = (1 << LMQCP_PUBLISH) | + (1 << LMQCP_WILL_PROPERTIES), + [LMQPROP_RESPONSE_TOPIC] = (1 << LMQCP_PUBLISH) | + (1 << LMQCP_WILL_PROPERTIES), + [LMQPROP_CORRELATION_DATA] = (1 << LMQCP_PUBLISH) | + (1 << LMQCP_WILL_PROPERTIES), + [LMQPROP_SUBSCRIPTION_IDENTIFIER] = (1 << LMQCP_PUBLISH) | + (1 << LMQCP_CTOS_SUBSCRIBE), + [LMQPROP_SESSION_EXPIRY_INTERVAL] = (1 << LMQCP_CTOS_CONNECT) | + (1 << LMQCP_STOC_CONNACK) | + (1 << LMQCP_DISCONNECT), + [LMQPROP_ASSIGNED_CLIENT_IDENTIFIER] = (1 << LMQCP_STOC_CONNACK), + [LMQPROP_SERVER_KEEP_ALIVE] = (1 << LMQCP_STOC_CONNACK), + [LMQPROP_AUTHENTICATION_METHOD] = (1 << LMQCP_CTOS_CONNECT) | + (1 << LMQCP_STOC_CONNACK) | + (1 << LMQCP_AUTH), + [LMQPROP_AUTHENTICATION_DATA] = (1 << LMQCP_CTOS_CONNECT) | + (1 << LMQCP_STOC_CONNACK) | + (1 << LMQCP_AUTH), + [LMQPROP_REQUEST_PROBLEM_INFORMATION] = (1 << LMQCP_CTOS_CONNECT), + [LMQPROP_WILL_DELAY_INTERVAL] = (1 << LMQCP_WILL_PROPERTIES), + [LMQPROP_REQUEST_RESPONSE_INFORMATION] = (1 << LMQCP_CTOS_CONNECT), + [LMQPROP_RESPONSE_INFORMATION] = (1 << LMQCP_STOC_CONNACK), + [LMQPROP_SERVER_REFERENCE] = (1 << LMQCP_STOC_CONNACK) | + (1 << LMQCP_DISCONNECT), + [LMQPROP_REASON_STRING] = (1 << LMQCP_STOC_CONNACK) | + (1 << LMQCP_PUBACK) | + (1 << LMQCP_PUBREC) | + (1 << LMQCP_PUBREL) | + (1 << LMQCP_PUBCOMP) | + (1 << LMQCP_STOC_SUBACK) | + (1 << LMQCP_STOC_UNSUBACK) | + (1 << LMQCP_DISCONNECT) | + (1 << LMQCP_AUTH), + [LMQPROP_RECEIVE_MAXIMUM] = (1 << LMQCP_CTOS_CONNECT) | + (1 << LMQCP_STOC_CONNACK), + [LMQPROP_TOPIC_ALIAS_MAXIMUM] = (1 << LMQCP_CTOS_CONNECT) | + (1 << LMQCP_STOC_CONNACK), + [LMQPROP_TOPIC_ALIAS] = (1 << LMQCP_PUBLISH), + [LMQPROP_MAXIMUM_QOS] = (1 << LMQCP_STOC_CONNACK), + [LMQPROP_RETAIN_AVAILABLE] = (1 << LMQCP_STOC_CONNACK), + [LMQPROP_USER_PROPERTY] = (1 << LMQCP_CTOS_CONNECT) | + (1 << LMQCP_STOC_CONNACK) | + (1 << LMQCP_PUBLISH) | + (1 << LMQCP_WILL_PROPERTIES) | + (1 << LMQCP_PUBACK) | + (1 << LMQCP_PUBREC) | + (1 << LMQCP_PUBREL) | + (1 << LMQCP_PUBCOMP) | + (1 << LMQCP_CTOS_SUBSCRIBE) | + (1 << LMQCP_STOC_SUBACK) | + (1 << LMQCP_CTOS_UNSUBSCRIBE) | + (1 << LMQCP_STOC_UNSUBACK) | + (1 << LMQCP_DISCONNECT) | + (1 << LMQCP_AUTH), + [LMQPROP_MAXIMUM_PACKET_SIZE] = (1 << LMQCP_CTOS_CONNECT) | + (1 << LMQCP_STOC_CONNACK), + [LMQPROP_WILDCARD_SUBSCRIPTION_AVAIL] = (1 << LMQCP_STOC_CONNACK), + [LMQPROP_SUBSCRIPTION_IDENTIFIER_AVAIL] = (1 << LMQCP_STOC_CONNACK), + [LMQPROP_SHARED_SUBSCRIPTION_AVAIL] = (1 << LMQCP_STOC_CONNACK) +}; + + +/* + * For each command index, maps flags, id, qos and payload legality + * notice in most cases PUBLISH requires further processing + */ +static const uint8_t map_flags[] = { + [LMQCP_RESERVED] = 0x00, + [LMQCP_CTOS_CONNECT] = LMQCP_LUT_FLAG_RESERVED_FLAGS | + LMQCP_LUT_FLAG_PAYLOAD | + LMQCP_LUT_FLAG_PACKET_ID_NONE | 0x00, + [LMQCP_STOC_CONNACK] = LMQCP_LUT_FLAG_RESERVED_FLAGS | + LMQCP_LUT_FLAG_PACKET_ID_NONE | 0x00, + [LMQCP_PUBLISH] = LMQCP_LUT_FLAG_PAYLOAD | /* option */ + LMQCP_LUT_FLAG_PACKET_ID_QOS12 | 0x00, + [LMQCP_PUBACK] = LMQCP_LUT_FLAG_RESERVED_FLAGS | + LMQCP_LUT_FLAG_PACKET_ID_HAS | 0x00, + [LMQCP_PUBREC] = LMQCP_LUT_FLAG_RESERVED_FLAGS | + LMQCP_LUT_FLAG_PACKET_ID_HAS | 0x00, + [LMQCP_PUBREL] = LMQCP_LUT_FLAG_RESERVED_FLAGS | + LMQCP_LUT_FLAG_PACKET_ID_HAS | 0x02, + [LMQCP_PUBCOMP] = LMQCP_LUT_FLAG_RESERVED_FLAGS | + LMQCP_LUT_FLAG_PACKET_ID_HAS | 0x00, + [LMQCP_CTOS_SUBSCRIBE] = LMQCP_LUT_FLAG_RESERVED_FLAGS | + LMQCP_LUT_FLAG_PAYLOAD | + LMQCP_LUT_FLAG_PACKET_ID_HAS | 0x02, + [LMQCP_STOC_SUBACK] = LMQCP_LUT_FLAG_RESERVED_FLAGS | + LMQCP_LUT_FLAG_PAYLOAD | + LMQCP_LUT_FLAG_PACKET_ID_HAS | 0x00, + [LMQCP_CTOS_UNSUBSCRIBE] = LMQCP_LUT_FLAG_RESERVED_FLAGS | + LMQCP_LUT_FLAG_PAYLOAD | + LMQCP_LUT_FLAG_PACKET_ID_HAS | 0x02, + [LMQCP_STOC_UNSUBACK] = LMQCP_LUT_FLAG_RESERVED_FLAGS | + LMQCP_LUT_FLAG_PAYLOAD | + LMQCP_LUT_FLAG_PACKET_ID_NONE | 0x00, + [LMQCP_CTOS_PINGREQ] = LMQCP_LUT_FLAG_RESERVED_FLAGS | + LMQCP_LUT_FLAG_PACKET_ID_NONE | 0x00, + [LMQCP_STOC_PINGRESP] = LMQCP_LUT_FLAG_RESERVED_FLAGS | + LMQCP_LUT_FLAG_PACKET_ID_NONE | 0x00, + [LMQCP_DISCONNECT] = LMQCP_LUT_FLAG_RESERVED_FLAGS | + LMQCP_LUT_FLAG_PACKET_ID_NONE | 0x00, + [LMQCP_AUTH] = LMQCP_LUT_FLAG_RESERVED_FLAGS | + LMQCP_LUT_FLAG_PACKET_ID_NONE | 0x00, +}; + +void +lws_mqttc_state_transition(lws_mqttc_t *c, lwsgs_mqtt_states_t s) +{ + lwsl_debug("%s: ep %p: state %d -> %d\n", __func__, c, c->estate, s); + c->estate = s; +} + +static int +lws_mqtt_pconsume(lws_mqtt_parser_t *par, int consumed) +{ + par->consumed += consumed; + + if (par->consumed > par->props_len) + return -1; + + /* more properties coming */ + + if (par->consumed < par->props_len) { + par->state = LMQCPP_PROP_ID_VBI; + return 0; + } + + /* properties finished: are we headed for payload or idle? */ + + if ((map_flags[ctl_pkt_type(par)] & LMQCP_LUT_FLAG_PAYLOAD) && + /* A PUBLISH packet MUST NOT contain a Packet Identifier if + * its QoS value is set to 0 [MQTT-2.2.1-2]. */ + (ctl_pkt_type(par) != LMQCP_PUBLISH || + (par->packet_type_flags & 6))) { + par->state = LMQCPP_PAYLOAD; + return 0; + } + + par->state = LMQCPP_IDLE; + + return 0; +} + +static int +lws_mqtt_set_client_established(struct lws *wsi) +{ + lws_role_transition(wsi, LWSIFR_CLIENT, LRS_ESTABLISHED, + &role_ops_mqtt); + + if (user_callback_handle_rxflow(wsi->a.protocol->callback, + wsi, LWS_CALLBACK_MQTT_CLIENT_ESTABLISHED, + wsi->user_space, NULL, 0) < 0) { + lwsl_err("%s: MQTT_ESTABLISHED failed\n", __func__); + + return -1; + } + /* + * If we made a new connection and got the ACK, our connection is + * definitely working in both directions at the moment + */ + lws_validity_confirmed(wsi); + + /* clear connection timeout */ + lws_set_timeout(wsi, NO_PENDING_TIMEOUT, 0); + + return 0; +} + +lws_mqtt_subs_t * +lws_mqtt_find_sub(struct _lws_mqtt_related *mqtt, const char *topic) +{ + lws_mqtt_subs_t *s = mqtt->subs_head; + + while (s) { + if (!strcmp((const char *)s->topic, topic)) + return s; + s = s->next; + } + + return NULL; +} + +static lws_mqtt_subs_t * +lws_mqtt_create_sub(struct _lws_mqtt_related *mqtt, const char *topic) +{ + lws_mqtt_subs_t *mysub; + + mysub = lws_malloc(sizeof(*mysub) + strlen(topic) + 1, "sub"); + if (!mysub) + return NULL; + + mysub->next = mqtt->subs_head; + mqtt->subs_head = mysub; + memcpy(mysub->topic, topic, strlen(topic) + 1); + mysub->ref_count = 1; + + lwsl_info("%s: Created mysub %p for wsi->mqtt %p\n", + __func__, mysub, mqtt); + + return mysub; +} + +static int +lws_mqtt_client_remove_subs(struct _lws_mqtt_related *mqtt) +{ + lws_mqtt_subs_t *s = mqtt->subs_head; + lws_mqtt_subs_t *temp = NULL; + + + lwsl_info("%s: Called to remove subs from wsi->mqtt %p\n", + __func__, mqtt); + + while (s && s->next) { + if (s->next->ref_count == 0) + break; + s = s->next; + } + + if (s && s->next) { + temp = s->next; + lwsl_info("%s: Removing sub %p from wsi->mqtt %p\n", + __func__, temp, mqtt); + s->next = temp->next; + lws_free(temp); + return 0; + } + return 1; +} + +int +_lws_mqtt_rx_parser(struct lws *wsi, lws_mqtt_parser_t *par, + const uint8_t *buf, size_t len) +{ + struct lws *w; + int n; + + if (par->flag_pending_send_reason_close) + return 0; + + /* + * Stateful, fragmentation-immune parser + * + * Notice that len can always be 1 if under attack, even over tls if + * the server is compromised or malicious. + */ + + while (len) { + lwsl_debug("%s: %d, len = %d\n", __func__, par->state, (int)len); + switch (par->state) { + case LMQCPP_IDLE: + par->packet_type_flags = *buf++; + len--; + +#if defined(LWS_WITH_CLIENT) + /* + * The case where we sent the connect, but we received + * something else before any CONNACK + */ + if (lwsi_state(wsi) == LRS_MQTTC_AWAIT_CONNACK && + par->packet_type_flags >> 4 != LMQCP_STOC_CONNACK) { + lwsl_notice("%s: server sent non-CONNACK\n", + __func__); + goto send_protocol_error_and_close; + } +#endif /* LWS_WITH_CLIENT */ + + n = map_flags[par->packet_type_flags >> 4]; + /* + * Where a flag bit is marked as “Reserved”, it is + * reserved for future use and MUST be set to the value + * listed [MQTT-2.1.3-1]. + */ + if ((n & LMQCP_LUT_FLAG_RESERVED_FLAGS) && + ((par->packet_type_flags & 0x0f) != (n & 0x0f))) { + lwsl_notice("%s: wsi %p: bad flags, 0x%02x mask 0x%02x (len %d)\n", + __func__, wsi, par->packet_type_flags, n, (int)len + 1); + lwsl_hexdump_err(buf - 1, len + 1); + goto send_protocol_error_and_close; + } + + lwsl_debug("%s: received pkt type 0x%x / flags 0x%x\n", + __func__, par->packet_type_flags >> 4, + par->packet_type_flags & 0xf); + + /* allows us to know if a property that can only be + * given once, appears twice */ + memset(par->props_seen, 0, sizeof(par->props_seen)); + par->state = par->packet_type_flags & 0xf0; + break; + + case LMQCPP_CONNECT_PACKET: + lwsl_debug("%s: received CONNECT pkt\n", __func__); + par->state = LMQCPP_CONNECT_REMAINING_LEN_VBI; + lws_mqtt_vbi_init(&par->vbit); + break; + + case LMQCPP_CONNECT_REMAINING_LEN_VBI: + switch (lws_mqtt_vbi_r(&par->vbit, &buf, &len)) { + case LMSPR_NEED_MORE: + break; + case LMSPR_COMPLETED: + par->cpkt_remlen = par->vbit.value; + n = map_flags[ctl_pkt_type(par)]; + lws_mqtt_str_init(&par->s_temp, par->temp, + sizeof(par->temp), 0); + par->state = LMQCPP_CONNECT_VH_PNAME; + break; + default: + lwsl_notice("%s: bad vbi\n", __func__); + goto send_protocol_error_and_close; + } + break; + + case LMQCPP_CONNECT_VH_PNAME: + switch (lws_mqtt_str_parse(&par->s_temp, &buf, &len)) { + case LMSPR_NEED_MORE: + break; + case LMSPR_COMPLETED: + if (par->s_temp.len != 4 || + memcmp(par->s_temp.buf, "MQTT", + par->s_temp.len)) { + lwsl_notice("%s: protocol name: %.*s\n", + __func__, par->s_temp.len, + par->s_temp.buf); + goto send_unsupp_connack_and_close; + } + par->state = LMQCPP_CONNECT_VH_PVERSION; + break; + default: + lwsl_notice("%s: bad protocol name\n", __func__); + goto send_protocol_error_and_close; + } + break; + + case LMQCPP_CONNECT_VH_PVERSION: + par->conn_protocol_version = *buf++; + len--; + if (par->conn_protocol_version != 5) { + lwsl_info("%s: unsupported MQTT version %d\n", + __func__, par->conn_protocol_version); + goto send_unsupp_connack_and_close; + } + par->state = LMQCPP_CONNECT_VH_FLAGS; + break; + + case LMQCPP_CONNECT_VH_FLAGS: + par->cpkt_flags = *buf++; + len--; + if (par->cpkt_flags & 1) { + /* + * The Server MUST validate that the reserved + * flag in the CONNECT packet is set to 0 + * [MQTT-3.1.2-3]. + */ + par->reason = LMQCP_REASON_MALFORMED_PACKET; + goto send_reason_and_close; + } + /* + * conn_flags specifies the Will Properties that should + * appear in the payload section + */ + lws_mqtt_2byte_init(&par->vbit); + par->state = LMQCPP_CONNECT_VH_KEEPALIVE; + break; + + case LMQCPP_CONNECT_VH_KEEPALIVE: + switch (lws_mqtt_vbi_r(&par->vbit, &buf, &len)) { + case LMSPR_NEED_MORE: + break; + case LMSPR_COMPLETED: + par->keepalive = (uint16_t)par->vbit.value; + lws_mqtt_vbi_init(&par->vbit); + par->state = LMQCPP_CONNECT_VH_PROPERTIES_VBI_LEN; + break; + default: + lwsl_notice("%s: ka bad vbi\n", __func__); + goto send_protocol_error_and_close; + } + break; + + case LMQCPP_PINGRESP_ZERO: + len--; + /* second byte of PINGRESP must be zero */ + if (*buf++) + goto send_protocol_error_and_close; + goto cmd_completion; + + case LMQCPP_CONNECT_VH_PROPERTIES_VBI_LEN: + switch (lws_mqtt_vbi_r(&par->vbit, &buf, &len)) { + case LMSPR_NEED_MORE: + break; + case LMSPR_COMPLETED: + /* reset consumption counter */ + par->consumed = 0; + par->props_len = par->vbit.value; + lws_mqtt_vbi_init(&par->vbit); + par->state = LMQCPP_PROP_ID_VBI; + break; + default: + lwsl_notice("%s: connpr bad vbi\n", __func__); + goto send_protocol_error_and_close; + } + break; + + case LMQCPP_PUBLISH_PACKET: + if (lwsi_role_client(wsi) && wsi->mqtt->inside_subscribe) { + lwsl_notice("%s: Topic rx before subscribing\n", + __func__); + goto send_protocol_error_and_close; + } + lwsl_info("%s: received PUBLISH pkt\n", __func__); + par->state = LMQCPP_PUBLISH_REMAINING_LEN_VBI; + lws_mqtt_vbi_init(&par->vbit); + break; + case LMQCPP_PUBLISH_REMAINING_LEN_VBI: + switch (lws_mqtt_vbi_r(&par->vbit, &buf, &len)) { + case LMSPR_NEED_MORE: + break; + case LMSPR_COMPLETED: + par->cpkt_remlen = par->vbit.value; + lwsl_debug("%s: PUBLISH pkt len = %d\n", + __func__, (int)par->cpkt_remlen); + /* Move on to PUBLISH's variable header */ + par->state = LMQCPP_PUBLISH_VH_TOPIC; + break; + default: + lwsl_notice("%s: pubrem bad vbi\n", __func__); + goto send_protocol_error_and_close; + } + break; + + case LMQCPP_PUBLISH_VH_TOPIC: + { + lws_mqtt_publish_param_t *pub = NULL; + + if (len < 2) { + lwsl_notice("%s: topic too short\n", __func__); + return -1; + } + + /* Topic len */ + par->n = lws_ser_ru16be(buf); + buf += 2; + len -= 2; + + if (len < par->n) {/* the way this is written... */ + lwsl_notice("%s: len breakage\n", __func__); + return -1; + } + + /* Invalid topic len */ + if (par->n == 0) { + lwsl_notice("%s: zero topic len\n", __func__); + par->reason = LMQCP_REASON_MALFORMED_PACKET; + goto send_reason_and_close; + } + lwsl_debug("%s: PUBLISH topic len %d\n", + __func__, (int)par->n); + assert(!wsi->mqtt->rx_cpkt_param); + wsi->mqtt->rx_cpkt_param = lws_zalloc( + sizeof(lws_mqtt_publish_param_t), "rx pub param"); + if (!wsi->mqtt->rx_cpkt_param) + goto oom; + pub = (lws_mqtt_publish_param_t *)wsi->mqtt->rx_cpkt_param; + + pub->topic_len = par->n; + + /* Topic Name */ + pub->topic = (char *)lws_zalloc((size_t)pub->topic_len + 1, + "rx publish topic"); + if (!pub->topic) + goto oom; + lws_strncpy(pub->topic, (const char *)buf, + (size_t)pub->topic_len + 1); + buf += pub->topic_len; + len -= pub->topic_len; + + /* Extract QoS Level from Fixed Header Flags */ + pub->qos = (lws_mqtt_qos_levels_t) + ((par->packet_type_flags >> 1) & 0x3); + + pub->payload_pos = 0; + + pub->payload_len = par->cpkt_remlen - + (2 + pub->topic_len + ((pub->qos) ? 2 : 0)); + + switch (pub->qos) { + case QOS0: + par->state = LMQCPP_PAYLOAD; + if (pub->payload_len == 0) + goto cmd_completion; + + break; + case QOS1: + case QOS2: + par->state = LMQCPP_PUBLISH_VH_PKT_ID; + break; + default: + par->reason = LMQCP_REASON_MALFORMED_PACKET; + lws_free_set_NULL(pub->topic); + lws_free_set_NULL(wsi->mqtt->rx_cpkt_param); + goto send_reason_and_close; + } + break; + } + case LMQCPP_PUBLISH_VH_PKT_ID: + { + lws_mqtt_publish_param_t *pub = + (lws_mqtt_publish_param_t *)wsi->mqtt->rx_cpkt_param; + + if (len < 2) { + lwsl_notice("%s: len breakage 2\n", __func__); + return -1; + } + + par->cpkt_id = lws_ser_ru16be(buf); + buf += 2; + len -= 2; + wsi->mqtt->ack_pkt_id = par->cpkt_id; + lwsl_debug("%s: Packet ID %d\n", + __func__, (int)par->cpkt_id); + par->state = LMQCPP_PAYLOAD; + pub->payload_pos = 0; + pub->payload_len = par->cpkt_remlen - + (2 + pub->topic_len + ((pub->qos) ? 2 : 0)); + if (pub->payload_len == 0) + goto cmd_completion; + + break; + } + case LMQCPP_PAYLOAD: + { + lws_mqtt_publish_param_t *pub = + (lws_mqtt_publish_param_t *)wsi->mqtt->rx_cpkt_param; + if (pub == NULL) { + lwsl_err("%s: Uninitialized pub_param\n", + __func__); + goto send_protocol_error_and_close; + } + + pub->payload = buf; + goto cmd_completion; + } + + case LMQCPP_CONNACK_PACKET: + if (!lwsi_role_client(wsi)) { + lwsl_err("%s: CONNACK is only Server to Client", + __func__); + goto send_unsupp_connack_and_close; + } + + lwsl_debug("%s: received CONNACK pkt\n", __func__); + lws_mqtt_vbi_init(&par->vbit); + switch (lws_mqtt_vbi_r(&par->vbit, &buf, &len)) { + case LMSPR_NEED_MORE: + break; + case LMSPR_COMPLETED: + par->cpkt_remlen = par->vbit.value; + lwsl_debug("%s: CONNACK pkt len = %d\n", + __func__, (int)par->cpkt_remlen); + if (par->cpkt_remlen != 2) + goto send_protocol_error_and_close; + + par->state = LMQCPP_CONNACK_VH_FLAGS; + break; + default: + lwsl_notice("%s: connack bad vbi\n", __func__); + goto send_protocol_error_and_close; + } + break; + + case LMQCPP_CONNACK_VH_FLAGS: + { + lws_mqttc_t *c = &wsi->mqtt->client; + par->cpkt_flags = *buf++; + len--; + + if (par->cpkt_flags & ~LMQCFT_SESSION_PRESENT) { + /* + * Byte 1 is the "Connect Acknowledge + * Flags". Bits 7-1 are reserved and + * MUST be set to 0. + */ + par->reason = LMQCP_REASON_MALFORMED_PACKET; + goto send_reason_and_close; + } + /* + * If the Server accepts a connection with + * CleanSession set to 1, the Server MUST set + * Session Present to 0 in the CONNACK packet + * in addition to setting a zero return code + * in the CONNACK packet [MQTT-3.2.2-1]. If + * the Server accepts a connection with + * CleanSession set to 0, the value set in + * Session Present depends on whether the + * Server already has stored Session state for + * the supplied client ID. If the Server has + * stored Session state, it MUST set + * SessionPresent to 1 in the CONNACK packet + * [MQTT-3.2.2-2]. If the Server does not have + * stored Session state, it MUST set Session + * Present to 0 in the CONNACK packet. This is + * in addition to setting a zero return code + * in the CONNACK packet [MQTT-3.2.2-3]. + */ + if ((c->conn_flags & LMQCFT_CLEAN_START) && + (par->cpkt_flags & LMQCFT_SESSION_PRESENT)) + goto send_protocol_error_and_close; + + wsi->mqtt->session_resumed = (par->cpkt_flags & + LMQCFT_SESSION_PRESENT); + + /* Move on to Connect Return Code */ + par->state = LMQCPP_CONNACK_VH_RETURN_CODE; + break; + } + case LMQCPP_CONNACK_VH_RETURN_CODE: + par->conn_rc = *buf++; + len--; + /* + * If a server sends a CONNACK packet containing a + * non-zero return code it MUST then close the Network + * Connection [MQTT-3.2.2-5] + */ + switch (par->conn_rc) { + case 0: + goto cmd_completion; + case 1: + case 2: + case 3: + case 4: + case 5: + par->reason = LMQCP_REASON_UNSUPPORTED_PROTOCOL + + par->conn_rc - 1; + goto send_reason_and_close; + default: + lwsl_notice("%s: bad connack retcode\n", __func__); + goto send_protocol_error_and_close; + } + break; + + /* SUBACK */ + case LMQCPP_SUBACK_PACKET: + if (!lwsi_role_client(wsi)) { + lwsl_err("%s: SUBACK is only Server to Client", + __func__); + goto send_unsupp_connack_and_close; + } + + lwsl_debug("%s: received SUBACK pkt\n", __func__); + lws_mqtt_vbi_init(&par->vbit); + switch (lws_mqtt_vbi_r(&par->vbit, &buf, &len)) { + case LMSPR_NEED_MORE: + break; + case LMSPR_COMPLETED: + par->cpkt_remlen = par->vbit.value; + lwsl_debug("%s: SUBACK pkt len = %d\n", + __func__, (int)par->cpkt_remlen); + if (par->cpkt_remlen <= 2) + goto send_protocol_error_and_close; + par->state = LMQCPP_SUBACK_VH_PKT_ID; + break; + default: + lwsl_notice("%s: suback bad vbi\n", __func__); + goto send_protocol_error_and_close; + } + break; + + case LMQCPP_SUBACK_VH_PKT_ID: + + if (len < 2) { + lwsl_notice("%s: len breakage 4\n", __func__); + return -1; + } + + par->cpkt_id = lws_ser_ru16be(buf); + wsi->mqtt->ack_pkt_id = par->cpkt_id; + buf += 2; + len -= 2; + par->cpkt_remlen -= 2; + par->n = 0; + par->state = LMQCPP_SUBACK_PAYLOAD; + *par->temp = 0; + break; + + case LMQCPP_SUBACK_PAYLOAD: + { + lws_mqtt_qos_levels_t qos = (lws_mqtt_qos_levels_t)*buf++; + + len--; + switch (qos) { + case QOS0: + case QOS1: + case QOS2: + break; + case FAILURE_QOS_LEVEL: + goto send_protocol_error_and_close; + + default: + par->reason = LMQCP_REASON_MALFORMED_PACKET; + goto send_reason_and_close; + } + + if (++(par->n) == par->cpkt_remlen) { + par->n = 0; + goto cmd_completion; + } + + break; + } + + /* UNSUBACK */ + case LMQCPP_UNSUBACK_PACKET: + if (!lwsi_role_client(wsi)) { + lwsl_err("%s: UNSUBACK is only Server to Client", + __func__); + goto send_unsupp_connack_and_close; + } + + lwsl_debug("%s: received UNSUBACK pkt\n", __func__); + lws_mqtt_vbi_init(&par->vbit); + switch (lws_mqtt_vbi_r(&par->vbit, &buf, &len)) { + case LMSPR_NEED_MORE: + break; + case LMSPR_COMPLETED: + par->cpkt_remlen = par->vbit.value; + lwsl_debug("%s: UNSUBACK pkt len = %d\n", + __func__, (int)par->cpkt_remlen); + if (par->cpkt_remlen < 2) + goto send_protocol_error_and_close; + par->state = LMQCPP_UNSUBACK_VH_PKT_ID; + break; + default: + lwsl_notice("%s: unsuback bad vbi\n", __func__); + goto send_protocol_error_and_close; + } + break; + + case LMQCPP_UNSUBACK_VH_PKT_ID: + + if (len < 2) { + lwsl_notice("%s: len breakage 3\n", __func__); + return -1; + } + + par->cpkt_id = lws_ser_ru16be(buf); + wsi->mqtt->ack_pkt_id = par->cpkt_id; + buf += 2; + len -= 2; + par->cpkt_remlen -= 2; + par->n = 0; + + goto cmd_completion; + + case LMQCPP_PUBACK_PACKET: + lws_mqtt_vbi_init(&par->vbit); + switch (lws_mqtt_vbi_r(&par->vbit, &buf, &len)) { + case LMSPR_NEED_MORE: + break; + case LMSPR_COMPLETED: + par->cpkt_remlen = par->vbit.value; + lwsl_info("%s: PUBACK pkt len = %d\n", __func__, + (int)par->cpkt_remlen); + /* + * must be 4 or more, with special case that 2 + * means success with no reason code or props + */ + if (par->cpkt_remlen <= 1 || + par->cpkt_remlen == 3) + goto send_protocol_error_and_close; + + par->state = LMQCPP_PUBACK_VH_PKT_ID; + par->fixed_seen[2] = par->fixed_seen[3] = 0; + par->fixed = 0; + par->n = 0; + break; + default: + lwsl_notice("%s: puback bad vbi\n", __func__); + goto send_protocol_error_and_close; + } + break; + + case LMQCPP_PUBACK_VH_PKT_ID: + /* + * There are 3 fixed bytes and then a VBI for the + * property section length + */ + par->fixed_seen[par->fixed++] = *buf++; + if (len < par->cpkt_remlen - par->n) { + lwsl_notice("%s: len breakage 4\n", __func__); + return -1; + } + len--; + par->n++; + if (par->fixed == 2) + par->cpkt_id = lws_ser_ru16be(par->fixed_seen); + + if (par->fixed == 3) { + lws_mqtt_vbi_init(&par->vbit); + par->props_consumed = 0; + par->state = LMQCPP_PUBACK_PROPERTIES_LEN_VBI; + } + /* length of 2 is truncated packet and we completed it */ + if (par->cpkt_remlen == par->fixed) + goto cmd_completion; + break; + + case LMQCPP_PUBACK_PROPERTIES_LEN_VBI: + switch (lws_mqtt_vbi_r(&par->vbit, &buf, &len)) { + case LMSPR_NEED_MORE: + break; + case LMSPR_COMPLETED: + par->props_len = par->vbit.value; + lwsl_info("%s: PUBACK props len = %d\n", + __func__, (int)par->cpkt_remlen); + /* + * If there are no properties, this is a + * command completion event in itself + */ + if (!par->props_len) + goto cmd_completion; + + /* + * Otherwise consume the properties before + * completing the command + */ + lws_mqtt_vbi_init(&par->vbit); + par->state = LMQCPP_PUBACK_VH_PKT_ID; + break; + default: + lwsl_notice("%s: puback pr bad vbi\n", __func__); + goto send_protocol_error_and_close; + } + break; + + case LMQCPP_EAT_PROPERTIES_AND_COMPLETE: + /* + * TODO: stash the props + */ + par->props_consumed++; + len--; + buf++; + if (par->props_len != par->props_consumed) + break; + +cmd_completion: + /* + * We come here when we understood we just processed + * the last byte of a command packet, regardless of the + * packet type + */ + par->state = LMQCPP_IDLE; + + switch (par->packet_type_flags >> 4) { + case LMQCP_STOC_CONNACK: + lwsl_info("%s: cmd_completion: CONNACK\n", + __func__); + + /* + * Getting the CONNACK means we are the first, + * the nwsi, and we succeeded to create a new + * network connection ourselves. + * + * Since others may join us sharing the nwsi, + * and we may close while they still want to use + * it, our wsi lifecycle alone can no longer + * define the lifecycle of the nwsi... it means + * we need to do a "magic trick" and instead of + * being both the nwsi and act like a child + * stream, create a new wsi to take over the + * nwsi duties and turn our wsi into a child of + * the nwsi with its own lifecycle. + * + * The nwsi gets a mostly empty wsi->nwsi used + * to track already-subscribed topics globally + * for the connection. + */ + + /* we were under SENT_CLIENT_HANDSHAKE timeout */ + lws_set_timeout(wsi, 0, 0); + + w = lws_create_new_server_wsi(wsi->a.vhost, + wsi->tsi); + if (!w) { + lwsl_notice("%s: sid 1 migrate failed\n", + __func__); + return -1; + } + + wsi->mux.highest_sid = 1; + lws_wsi_mux_insert(w, wsi, wsi->mux.highest_sid++); + + wsi->mux_substream = 1; + w->mux_substream = 1; + w->client_mux_substream = 1; + wsi->client_mux_migrated = 1; + wsi->told_user_closed = 1; /* don't tell nwsi closed */ + + lwsi_set_state(w, LRS_ESTABLISHED); + lwsi_set_state(wsi, LRS_ESTABLISHED); + lwsi_set_role(w, lwsi_role(wsi)); + +#if defined(LWS_WITH_CLIENT) + w->flags = wsi->flags; +#endif + + w->mqtt = wsi->mqtt; + wsi->mqtt = lws_zalloc(sizeof(*wsi->mqtt), "nwsi mqtt"); + if (!wsi->mqtt) + return -1; + w->mqtt->wsi = w; + w->a.protocol = wsi->a.protocol; + if (w->user_space && + !w->user_space_externally_allocated) + lws_free_set_NULL(w->user_space); + w->user_space = wsi->user_space; + wsi->user_space = NULL; + w->user_space_externally_allocated = + wsi->user_space_externally_allocated; + if (lws_ensure_user_space(w)) + goto bail1; + w->a.opaque_user_data = wsi->a.opaque_user_data; + wsi->a.opaque_user_data = NULL; + w->stash = wsi->stash; + wsi->stash = NULL; + + lws_mux_mark_immortal(w); + + lwsl_notice("%s: migrated nwsi %p to sid 1 %p\n", + __func__, wsi, w); + + #if defined(LWS_WITH_SERVER_STATUS) + wsi->a.vhost->conn_stats.h2_subs++; + #endif + + /* + * It was the last thing we were waiting for + * before we can be fully ESTABLISHED + */ + if (lws_mqtt_set_client_established(w)) { + lwsl_notice("%s: set EST fail\n", __func__); + return -1; + } + + /* get the ball rolling */ + lws_validity_confirmed(wsi); + + /* well, add the queued guys as children */ + lws_wsi_mux_apply_queue(wsi); + break; + +bail1: + /* undo the insert */ + wsi->mux.child_list = w->mux.sibling_list; + wsi->mux.child_count--; + + w->a.context->count_wsi_allocated--; + + if (w->user_space) + lws_free_set_NULL(w->user_space); + w->a.vhost->protocols[0].callback(w, + LWS_CALLBACK_WSI_DESTROY, + NULL, NULL, 0); + lws_vhost_unbind_wsi(w); + lws_free(w); + + return 0; + + case LMQCP_PUBACK: + lwsl_info("%s: cmd_completion: PUBACK\n", + __func__); + + /* + * Figure out which child asked for this + */ + + n = 0; + lws_start_foreach_ll(struct lws *, w, + wsi->mux.child_list) { + if (w->mqtt->unacked_publish && + w->mqtt->ack_pkt_id == par->cpkt_id) { + char requested_close = 0; + + w->mqtt->unacked_publish = 0; + if (user_callback_handle_rxflow( + w->a.protocol->callback, + w, LWS_CALLBACK_MQTT_ACK, + w->user_space, NULL, 0) < 0) { + lwsl_info("%s: MQTT_ACK requests close\n", + __func__); + requested_close = 1; + } + n = 1; + + /* + * We got an assertive PUBACK, + * no need for ACK timeout wait + * any more + */ + lws_sul_cancel(&w->mqtt->sul_qos1_puback_wait); + + if (requested_close) { + __lws_close_free_wsi(w, + 0, "ack cb"); + break; + } + + break; + } + } lws_end_foreach_ll(w, mux.sibling_list); + + if (!n) { + lwsl_err("%s: unsolicited PUBACK\n", + __func__); + return -1; + } + + /* + * If we published something and it was acked, + * our connection is definitely working in both + * directions at the moment. + */ + lws_validity_confirmed(wsi); + break; + + case LMQCP_STOC_PINGRESP: + lwsl_info("%s: cmd_completion: PINGRESP\n", + __func__); + /* + * If we asked for a PINGRESP and it came, + * our connection is definitely working in both + * directions at the moment. + */ + lws_validity_confirmed(wsi); + break; + + case LMQCP_STOC_SUBACK: + lwsl_info("%s: cmd_completion: SUBACK\n", + __func__); + + /* + * Figure out which child asked for this + */ + + n = 0; + lws_start_foreach_ll(struct lws *, w, + wsi->mux.child_list) { + if (w->mqtt->inside_subscribe && + w->mqtt->ack_pkt_id == par->cpkt_id) { + w->mqtt->inside_subscribe = 0; + if (user_callback_handle_rxflow( + w->a.protocol->callback, + w, LWS_CALLBACK_MQTT_SUBSCRIBED, + w->user_space, NULL, 0) < 0) { + lwsl_err("%s: MQTT_SUBSCRIBE failed\n", + __func__); + return -1; + } + n = 1; + break; + } + } lws_end_foreach_ll(w, mux.sibling_list); + + if (!n) { + lwsl_err("%s: unsolicited SUBACK\n", + __func__); + return -1; + } + + /* + * If we subscribed to something and SUBACK came, + * our connection is definitely working in both + * directions at the moment. + */ + lws_validity_confirmed(wsi); + + break; + + case LMQCP_STOC_UNSUBACK: + { + char requested_close = 0; + lwsl_info("%s: cmd_completion: UNSUBACK\n", + __func__); + /* + * Figure out which child asked for this + */ + n = 0; + lws_start_foreach_ll(struct lws *, w, + wsi->mux.child_list) { + if (w->mqtt->inside_unsubscribe && + w->mqtt->ack_pkt_id == par->cpkt_id) { + struct lws *nwsi = lws_get_network_wsi(w); + + /* + * No more subscribers left, + * remove the topic from nwsi + */ + lws_mqtt_client_remove_subs(nwsi->mqtt); + + w->mqtt->inside_unsubscribe = 0; + if (user_callback_handle_rxflow( + w->a.protocol->callback, + w, LWS_CALLBACK_MQTT_UNSUBSCRIBED, + w->user_space, NULL, 0) < 0) { + lwsl_info("%s: MQTT_UNSUBACK requests close\n", + __func__); + requested_close = 1; + } + n = 1; + + if (requested_close) { + __lws_close_free_wsi(w, + 0, "unsub ack cb"); + break; + } + break; + } + } lws_end_foreach_ll(w, mux.sibling_list); + + if (!n) { + lwsl_err("%s: unsolicited UNSUBACK\n", + __func__); + return -1; + } + + + /* + * If we unsubscribed to something and + * UNSUBACK came, our connection is + * definitely working in both + * directions at the moment. + */ + lws_validity_confirmed(wsi); + + break; + } + case LMQCP_PUBLISH: + { + lws_mqtt_publish_param_t *pub = + (lws_mqtt_publish_param_t *) + wsi->mqtt->rx_cpkt_param; + size_t chunk; + + if (pub == NULL) { + lwsl_notice("%s: no pub\n", __func__); + return -1; + } + + /* + * RX PUBLISH is delivered to any children that + * registered for the related topic + */ + + n = wsi->role_ops->rx_cb[lwsi_role_server(wsi)]; + + chunk = pub->payload_len - pub->payload_pos; + if (chunk > len) + chunk = len; + + lws_start_foreach_ll(struct lws *, w, + wsi->mux.child_list) { + if (lws_mqtt_find_sub(w->mqtt, + pub->topic)) + if (w->a.protocol->callback( + w, n, + w->user_space, + (void *)pub, + chunk)) + return 1; + } lws_end_foreach_ll(w, mux.sibling_list); + + + pub->payload_pos += (uint32_t)chunk; + len -= chunk; + buf += chunk; + + lwsl_debug("%s: post pos %d, plen %d, len %d\n", + __func__, (int)pub->payload_pos, + (int)pub->payload_len, (int)len); + + if (pub->payload_pos != pub->payload_len) { + /* + * More chunks of the payload pending, + * blocking this connection from doing + * anything else + */ + par->state = LMQCPP_PAYLOAD; + break; + } + + /* For QOS>0, send out PUBACK */ + if (pub->qos) { + wsi->mqtt->send_puback = 1; + lws_callback_on_writable(wsi); + } + + par->payload_consumed = 0; + lws_free_set_NULL(pub->topic); + lws_free_set_NULL(wsi->mqtt->rx_cpkt_param); + + break; + } + default: + break; + } + + break; + + + case LMQCPP_PROP_ID_VBI: + switch (lws_mqtt_vbi_r(&par->vbit, &buf, &len)) { + case LMSPR_NEED_MORE: + break; + case LMSPR_COMPLETED: + par->consumed += par->vbit.consumed; + if (par->vbit.value > + LWS_ARRAY_SIZE(property_valid)) { + lwsl_notice("%s: undef prop id 0x%x\n", + __func__, (int)par->vbit.value); + goto send_protocol_error_and_close; + } + if (!(property_valid[par->vbit.value] & + (1 << ctl_pkt_type(par)))) { + lwsl_notice("%s: prop id 0x%x invalid for" + " control pkt %d\n", __func__, + (int)par->vbit.value, + ctl_pkt_type(par)); + goto send_protocol_error_and_close; + } + par->prop_id = par->vbit.value; + par->flag_prop_multi = + par->props_seen[par->prop_id >> 3] & + (1 << (par->prop_id & 7)); + par->props_seen[par->prop_id >> 3] |= + (1 << (par->prop_id & 7)); + /* + * even if it's not a vbi property arg, + * .consumed of this will be zero the first time + */ + lws_mqtt_vbi_init(&par->vbit); + /* + * if it's a string, next state must set the + * destination and size limit itself. But + * resetting it generically here lets it use + * lws_mqtt_str_first() to understand it's the + * first time around. + */ + lws_mqtt_str_init(&par->s_temp, NULL, 0, 0); + + /* property arg state enums are so encoded */ + par->state = 0x100 | par->vbit.value; + break; + default: + lwsl_notice("%s: prop id bad vbi\n", __func__); + goto send_protocol_error_and_close; + } + break; + + /* + * All possible property payloads... restricting which ones + * can appear in which control packets is already done above + * in LMQCPP_PROP_ID_VBI + */ + + case LMQCPP_PROP_REQUEST_PROBLEM_INFO_1BYTE: + case LMQCPP_PROP_REQUEST_REPSONSE_INFO_1BYTE: + case LMQCPP_PROP_MAXIMUM_QOS_1BYTE: + case LMQCPP_PROP_RETAIN_AVAILABLE_1BYTE: + case LMQCPP_PROP_WILDCARD_SUBSCRIPTION_AVAILABLE_1BYTE: + case LMQCPP_PROP_SUBSCRIPTION_IDENTIFIER_AVAILABLE_1BYTE: + case LMQCPP_PROP_SHARED_SUBSCRIPTION_AVAILABLE_1BYTE: + case LMQCPP_PROP_PAYLOAD_FORMAT_INDICATOR_1BYTE: /* 3.3.2.3.2 */ + if (par->flag_prop_multi) + goto singular_prop_seen_twice; + par->payload_format = *buf++; + len--; + if (lws_mqtt_pconsume(par, 1)) + goto send_protocol_error_and_close; + break; + + case LMQCPP_PROP_MAXIMUM_PACKET_SIZE_4BYTE: + case LMQCPP_PROP_WILL_DELAY_INTERVAL_4BYTE: + case LMQCPP_PROP_SESSION_EXPIRY_INTERVAL_4BYTE: + case LMQCPP_PROP_MSG_EXPIRY_INTERVAL_4BYTE: + if (par->flag_prop_multi) + goto singular_prop_seen_twice; + + if (lws_mqtt_mb_first(&par->vbit)) + lws_mqtt_4byte_init(&par->vbit); + + switch (lws_mqtt_mb_parse(&par->vbit, &buf, &len)) { + case LMSPR_NEED_MORE: + break; + case LMSPR_COMPLETED: + if (lws_mqtt_pconsume(par, par->vbit.consumed)) + goto send_protocol_error_and_close; + break; + default: + goto send_protocol_error_and_close; + } + break; + + case LMQCPP_PROP_SERVER_KEEPALIVE_2BYTE: + case LMQCPP_PROP_RECEIVE_MAXIMUM_2BYTE: + case LMQCPP_PROP_TOPIC_MAXIMUM_2BYTE: + case LMQCPP_PROP_TOPIC_ALIAS_2BYTE: + if (par->flag_prop_multi) + goto singular_prop_seen_twice; + + if (lws_mqtt_mb_first(&par->vbit)) + lws_mqtt_2byte_init(&par->vbit); + + switch (lws_mqtt_mb_parse(&par->vbit, &buf, &len)) { + case LMSPR_NEED_MORE: + break; + case LMSPR_COMPLETED: + if (lws_mqtt_pconsume(par, par->vbit.consumed)) + goto send_protocol_error_and_close; + break; + default: + goto send_protocol_error_and_close; + } + break; + + case LMQCPP_PROP_ASSIGNED_CLIENTID_UTF8S: + case LMQCPP_PROP_AUTH_METHOD_UTF8S: + case LMQCPP_PROP_USER_PROPERTY_NAME_UTF8S: + case LMQCPP_PROP_USER_PROPERTY_VALUE_UTF8S: + case LMQCPP_PROP_RESPONSE_INFO_UTF8S: + case LMQCPP_PROP_SERVER_REFERENCE_UTF8S: + case LMQCPP_PROP_REASON_STRING_UTF8S: + case LMQCPP_PROP_RESPONSE_TOPIC_UTF8S: + case LMQCPP_PROP_CONTENT_TYPE_UTF8S: + if (par->flag_prop_multi) + goto singular_prop_seen_twice; + + if (lws_mqtt_str_first(&par->s_temp)) + lws_mqtt_str_init(&par->s_temp, par->temp, + sizeof(par->temp), 0); + + switch (lws_mqtt_str_parse(&par->s_temp, &buf, &len)) { + case LMSPR_NEED_MORE: + break; + case LMSPR_COMPLETED: + if (lws_mqtt_pconsume(par, par->s_temp.len)) + goto send_protocol_error_and_close; + break; + + default: + lwsl_info("%s: bad protocol name\n", __func__); + goto send_protocol_error_and_close; + } + break; + + case LMQCPP_PROP_SUBSCRIPTION_ID_VBI: + + case LMQCPP_PROP_CORRELATION_BINDATA: + case LMQCPP_PROP_AUTH_DATA_BINDATA: + + /* TODO */ + lwsl_err("%s: Unimplemented packet state 0x%x\n", + __func__, par->state); + return -1; + } + } + + return 0; + +oom: + lwsl_err("%s: OOM!\n", __func__); + goto send_protocol_error_and_close; + +singular_prop_seen_twice: + lwsl_info("%s: property appears twice\n", __func__); + +send_protocol_error_and_close: + lwsl_notice("%s: peac\n", __func__); + par->reason = LMQCP_REASON_PROTOCOL_ERROR; + +send_reason_and_close: + lwsl_notice("%s: srac\n", __func__); + par->flag_pending_send_reason_close = 1; + goto ask; + +send_unsupp_connack_and_close: + lwsl_notice("%s: unsupac\n", __func__); + par->reason = LMQCP_REASON_UNSUPPORTED_PROTOCOL; + par->flag_pending_send_connack_close = 1; + +ask: + /* Should we ask for clients? */ + lws_callback_on_writable(wsi); + + return -1; +} + +int +lws_mqtt_fill_fixed_header(uint8_t *p, lws_mqtt_control_packet_t ctrl_pkt_type, + uint8_t dup, lws_mqtt_qos_levels_t qos, + uint8_t retain) +{ + lws_mqtt_fixed_hdr_t hdr; + + hdr.bits = 0; + hdr.flags.ctrl_pkt_type = (uint8_t) ctrl_pkt_type; + + switch(ctrl_pkt_type) { + case LMQCP_PUBLISH: + hdr.flags.dup = !!dup; + /* + * A PUBLISH Packet MUST NOT have both QoS bits set to + * 1. If a Server or Client receives a PUBLISH Packet + * which has both QoS bits set to 1 it MUST close the + * Network Connection [MQTT-3.3.1-4]. + */ + if (qos >= RESERVED_QOS_LEVEL) { + lwsl_err("%s: Unsupport QoS level 0x%x\n", + __func__, qos); + return -1; + } + hdr.flags.qos = (uint8_t)qos; + hdr.flags.retain = !!retain; + break; + + case LMQCP_CTOS_CONNECT: + case LMQCP_STOC_CONNACK: + case LMQCP_PUBACK: + case LMQCP_PUBREC: + case LMQCP_PUBCOMP: + case LMQCP_STOC_SUBACK: + case LMQCP_STOC_UNSUBACK: + case LMQCP_CTOS_PINGREQ: + case LMQCP_STOC_PINGRESP: + case LMQCP_DISCONNECT: + case LMQCP_AUTH: + hdr.bits &= 0xf0; + break; + + /* + * Bits 3,2,1 and 0 of the fixed header of the PUBREL, + * SUBSCRIBE, UNSUBSCRIBE Control Packets are reserved and + * MUST be set to 0,0,1 and 0 respectively. The Server MUST + * treat any other value as malformed and close the Network + * Connection [MQTT-3.6.1-1], [MQTT-3.8.1-1], [MQTT-3.10.1-1]. + */ + case LMQCP_PUBREL: + case LMQCP_CTOS_SUBSCRIBE: + case LMQCP_CTOS_UNSUBSCRIBE: + hdr.bits |= 0x02; + break; + + default: + return -1; + } + + *p = hdr.bits; + + return 0; +} + +/* + * This fires if the wsi did a PUBLISH under QoS1, but no PUBACK came before + * the timeout period + */ + +static void +lws_mqtt_publish_resend(struct lws_sorted_usec_list *sul) +{ + struct _lws_mqtt_related *mqtt = lws_container_of(sul, + struct _lws_mqtt_related, sul_qos1_puback_wait); + + lwsl_notice("%s: wsi %p\n", __func__, mqtt->wsi); + + if (mqtt->wsi->a.protocol->callback(mqtt->wsi, LWS_CALLBACK_MQTT_RESEND, + mqtt->wsi->user_space, NULL, 0)) + lws_set_timeout(mqtt->wsi, 1, LWS_TO_KILL_ASYNC); +} + +int +lws_mqtt_client_send_publish(struct lws *wsi, lws_mqtt_publish_param_t *pub, + const void *buf, uint32_t len, int is_complete) +{ + struct lws_context_per_thread *pt = &wsi->a.context->pt[(int)wsi->tsi]; + uint8_t *b = (uint8_t *)pt->serv_buf, *start, *p; + struct lws *nwsi = lws_get_network_wsi(wsi); + lws_mqtt_str_t mqtt_vh_payload; + uint32_t vh_len, rem_len; + + assert(pub->topic); + + lwsl_debug("%s: len = %d, is_complete = %d\n", + __func__, (int)len, (int)is_complete); + + if (lwsi_state(wsi) != LRS_ESTABLISHED) { + lwsl_err("%s: wsi %p: unknown state 0x%x\n", __func__, wsi, + lwsi_state(wsi)); + assert(0); + return 1; + } + + if (wsi->mqtt->inside_payload) { + /* + * Headers are filled, we are sending + * the payload - a buffer with LWS_PRE + * in front it. + */ + start = (uint8_t *)buf; + p = start + len; + if (is_complete) + wsi->mqtt->inside_payload = 0; + goto do_write; + } + + start = b + LWS_PRE; + p = start; + /* + * Fill headers and the first chunk of the + * payload (if any) + */ + if (lws_mqtt_fill_fixed_header(p++, LMQCP_PUBLISH, + 0, pub->qos, 0)) { + lwsl_err("%s: Failed to fill fixed header\n", __func__); + return 1; + } + + /* + * Topic len field + Topic len + Packet ID + * (for QOS>0) + Payload len + */ + vh_len = 2 + pub->topic_len + ((pub->qos) ? 2 : 0); + rem_len = vh_len + pub->payload_len; + lwsl_debug("%s: Remaining len = %d\n", __func__, (int) rem_len); + + /* Will the chunk of payload fit? */ + if ((vh_len + len) >= + (wsi->a.context->pt_serv_buf_size - LWS_PRE)) { + lwsl_err("%s: Payload is too big\n", __func__); + return 1; + } + + p += lws_mqtt_vbi_encode(rem_len, p); + + /* Topic's Len */ + lws_ser_wu16be(p, pub->topic_len); + p += 2; + + /* + * Init lws_mqtt_str for "MQTT Variable + * Headers + payload" (only the supplied + * chuncked payload) + */ + lws_mqtt_str_init(&mqtt_vh_payload, (uint8_t *)p, + (pub->topic_len + ((pub->qos) ? 2 : 0) + len), + 0); + + p = lws_mqtt_str_next(&mqtt_vh_payload, NULL); + lws_strncpy((char *)p, pub->topic, (size_t)pub->topic_len+1); + if (lws_mqtt_str_advance(&mqtt_vh_payload, pub->topic_len)) { + lwsl_err("%s: a\n", __func__); + return 1; + } + + /* Packet ID */ + if (pub->qos != QOS0) { + p = lws_mqtt_str_next(&mqtt_vh_payload, NULL); + wsi->mqtt->ack_pkt_id = pub->packet_id = ++nwsi->mqtt->pkt_id; + lwsl_debug("%s: pkt_id = %d\n", __func__, + (int)wsi->mqtt->ack_pkt_id); + lws_ser_wu16be(p, pub->packet_id); + if (lws_mqtt_str_advance(&mqtt_vh_payload, 2)) { + lwsl_err("%s: b\n", __func__); + return 1; + } + } + /* + * A non-empty Payload is expected and a chunk + * is present + */ + if (pub->payload_len && len) { + p = lws_mqtt_str_next(&mqtt_vh_payload, NULL); + memcpy(p, buf, len); + if (lws_mqtt_str_advance(&mqtt_vh_payload, len)) + return 1; + p = lws_mqtt_str_next(&mqtt_vh_payload, NULL); + } + + if (!is_complete) + nwsi->mqtt->inside_payload = wsi->mqtt->inside_payload = 1; + +do_write: + + // lwsl_hexdump_err(start, lws_ptr_diff(p, start)); + + if (lws_write(nwsi, start, lws_ptr_diff(p, start), LWS_WRITE_BINARY) != + lws_ptr_diff(p, start)) { + lwsl_err("%s: write failed\n", __func__); + return 1; + } + + if (!is_complete) { + /* still some more chunks to come... */ + lws_callback_on_writable(wsi); + + return 0; + } + + wsi->mqtt->inside_payload = nwsi->mqtt->inside_payload = 0; + + if (pub->qos != QOS0) + wsi->mqtt->unacked_publish = 1; + + /* this was the last part of the publish message */ + + if (pub->qos == QOS0) { + /* + * There won't be any real PUBACK, act like we got one + * so the user callback logic is the same for QoS0 or + * QoS1 + */ + if (wsi->a.protocol->callback(wsi, LWS_CALLBACK_MQTT_ACK, + wsi->user_space, NULL, 0)) { + lwsl_err("%s: ACK callback exited\n", __func__); + return 1; + } + + return 0; + } + + /* For QoS1, if no PUBACK coming after 3s, we must RETRY the publish */ + + wsi->mqtt->sul_qos1_puback_wait.cb = lws_mqtt_publish_resend; + __lws_sul_insert_us(&pt->pt_sul_owner[wsi->conn_validity_wakesuspend], + &wsi->mqtt->sul_qos1_puback_wait, + 3 * LWS_USEC_PER_SEC); + + return 0; +} + +int +lws_mqtt_client_send_subcribe(struct lws *wsi, lws_mqtt_subscribe_param_t *sub) +{ + struct lws_context_per_thread *pt = &wsi->a.context->pt[(int)wsi->tsi]; + uint8_t *b = (uint8_t *)pt->serv_buf + LWS_PRE, *start = b, *p = start; + struct lws *nwsi = lws_get_network_wsi(wsi); + lws_mqtt_str_t mqtt_vh_payload; + uint8_t exists[8], extant; + lws_mqtt_subs_t *mysub; + uint32_t rem_len; +#if defined(_DEBUG) + uint32_t tops; +#endif + uint32_t n; + + assert(sub->num_topics); + assert(sub->num_topics < sizeof(exists)); + + switch (lwsi_state(wsi)) { + case LRS_ESTABLISHED: /* Protocol connection established */ + if (lws_mqtt_fill_fixed_header(p++, LMQCP_CTOS_SUBSCRIBE, + 0, 0, 0)) { + lwsl_err("%s: Failed to fill fixed header\n", __func__); + return 1; + } + + /* + * The stream wants to subscribe to one or more topic, but + * the shared nwsi may already be subscribed to some or all of + * them from interactions with other streams. For those cases, + * we filter them from the list the child wants until we just + * have ones that are new to the nwsi. If nothing left, we just + * synthesize the callback to the child as if SUBACK had come + * and we're done, otherwise just ask the server for topics that + * are new to the wsi. + */ + + extant = 0; + memset(&exists, 0, sizeof(exists)); + for (n = 0; n < sub->num_topics; n++) { + lwsl_info("%s: Subscribing to topic[%d] = \"%s\"\n", + __func__, (int)n, sub->topic[n].name); + + mysub = lws_mqtt_find_sub(nwsi->mqtt, sub->topic[n].name); + if (mysub && mysub->ref_count) { + mysub->ref_count++; /* another stream using it */ + exists[n] = 1; + extant++; + } + + /* + * Attach the topic we're subscribing to, to wsi->mqtt + */ + if (!lws_mqtt_create_sub(wsi->mqtt, sub->topic[n].name)) { + lwsl_err("%s: create sub fail\n", __func__); + return 1; + } + } + + if (extant == sub->num_topics) { + /* + * It turns out there's nothing to do here, the nwsi has + * already subscribed to all the topics this stream + * wanted. Just tell it it can have them. + */ + lwsl_notice("%s: all topics already subscribed\n", __func__); + if (user_callback_handle_rxflow( + wsi->a.protocol->callback, + wsi, LWS_CALLBACK_MQTT_SUBSCRIBED, + wsi->user_space, NULL, 0) < 0) { + lwsl_err("%s: MQTT_SUBSCRIBE failed\n", + __func__); + return -1; + } + + return 0; + } + +#if defined(_DEBUG) + /* + * zero or more of the topics already existed, but not all, + * so we must go to the server with a filtered list of the + * new ones only + */ + + tops = sub->num_topics - extant; +#endif + + /* + * Pid + (Topic len field + Topic len + Req. QoS) x Num of Topics + */ + rem_len = 2; + for (n = 0; n < sub->num_topics; n++) + if (!exists[n]) + rem_len += (2 + (uint32_t)strlen(sub->topic[n].name) + (uint32_t)1); + + wsi->mqtt->sub_size = rem_len; + +#if defined(_DEBUG) + lwsl_debug("%s: Number of topics = %d, Remaining len = %d\n", + __func__, (int)tops, (int)rem_len); +#endif + + p += lws_mqtt_vbi_encode(rem_len, p); + + if ((rem_len + lws_ptr_diff(p, start)) >= + wsi->a.context->pt_serv_buf_size) { + lwsl_err("%s: Payload is too big\n", __func__); + return 1; + } + + /* Init lws_mqtt_str */ + lws_mqtt_str_init(&mqtt_vh_payload, (uint8_t *)p, rem_len, 0); + p = lws_mqtt_str_next(&mqtt_vh_payload, NULL); + + /* Packet ID */ + wsi->mqtt->ack_pkt_id = ++nwsi->mqtt->pkt_id; + lwsl_debug("%s: pkt_id = %d\n", __func__, + (int)wsi->mqtt->ack_pkt_id); + lws_ser_wu16be(p, wsi->mqtt->ack_pkt_id); + + if (lws_mqtt_str_advance(&mqtt_vh_payload, 2)) + return 1; + + p = lws_mqtt_str_next(&mqtt_vh_payload, NULL); + + for (n = 0; n < sub->num_topics; n++) { + lwsl_info("%s: topics[%d] = %s\n", __func__, + (int)n, sub->topic[n].name); + + /* if the nwsi already has it, don't ask server for it */ + if (exists[n]) { + lwsl_info("%s: topics[%d] \"%s\" exists in nwsi\n", + __func__, (int)n, sub->topic[n].name); + continue; + } + + /* + * Attach the topic we're subscribing to, to nwsi->mqtt + * so we know the nwsi itself has a subscription to it + */ + + if (!lws_mqtt_create_sub(nwsi->mqtt, sub->topic[n].name)) + return 1; + + /* Topic's Len */ + lws_ser_wu16be(p, (uint16_t)strlen(sub->topic[n].name)); + if (lws_mqtt_str_advance(&mqtt_vh_payload, 2)) + return 1; + p = lws_mqtt_str_next(&mqtt_vh_payload, NULL); + + /* Topic Name */ + lws_strncpy((char *)p, sub->topic[n].name, + strlen(sub->topic[n].name) + 1); + if (lws_mqtt_str_advance(&mqtt_vh_payload, + (int)strlen(sub->topic[n].name))) + return 1; + p = lws_mqtt_str_next(&mqtt_vh_payload, NULL); + + /* QoS */ + *p = sub->topic[n].qos; + if (lws_mqtt_str_advance(&mqtt_vh_payload, 1)) + return 1; + p = lws_mqtt_str_next(&mqtt_vh_payload, NULL); + } + break; + + default: + return 1; + } + + if (lws_write(nwsi, start, lws_ptr_diff(p, start), LWS_WRITE_BINARY) != + lws_ptr_diff(p, start)) + return 1; + + wsi->mqtt->inside_subscribe = 1; + + return 0; +} + +int +lws_mqtt_client_send_unsubcribe(struct lws *wsi, + const lws_mqtt_subscribe_param_t *unsub) +{ + struct lws_context_per_thread *pt = &wsi->a.context->pt[(int)wsi->tsi]; + uint8_t *b = (uint8_t *)pt->serv_buf + LWS_PRE, *start = b, *p = start; + struct lws *nwsi = lws_get_network_wsi(wsi); + lws_mqtt_str_t mqtt_vh_payload; + uint8_t send_unsub[8], orphaned; + uint32_t rem_len, n; + lws_mqtt_subs_t *mysub; +#if defined(_DEBUG) + uint32_t tops; +#endif + + lwsl_info("%s: Enter\n", __func__); + + switch (lwsi_state(wsi)) { + case LRS_ESTABLISHED: /* Protocol connection established */ + orphaned = 0; + memset(&send_unsub, 0, sizeof(send_unsub)); + for (n = 0; n < unsub->num_topics; n++) { + mysub = lws_mqtt_find_sub(nwsi->mqtt, + unsub->topic[n].name); + assert(mysub); + + if (mysub && --mysub->ref_count == 0) { + lwsl_notice("%s: Need to send UNSUB\n", __func__); + send_unsub[n] = 1; + orphaned++; + } + } + + if (!orphaned) { + /* + * The nwsi still has other subscribers bound to the + * topics. + * + * So, don't send UNSUB to server, and just fake the + * UNSUB ACK event for the guy going away. + */ + lwsl_notice("%s: unsubscribed!\n", __func__); + if (user_callback_handle_rxflow( + wsi->a.protocol->callback, + wsi, LWS_CALLBACK_MQTT_UNSUBSCRIBED, + wsi->user_space, NULL, 0) < 0) { + /* + * We can't directly close here, because the + * caller still has the wsi. Inform the + * caller that we want to close + */ + + return 1; + } + + return 0; + } +#if defined(_DEBUG) + /* + * one or more of the topics needs to be unsubscribed + * from, so we must go to the server with a filtered + * list of the new ones only + */ + + tops = orphaned; +#endif + + if (lws_mqtt_fill_fixed_header(p++, LMQCP_CTOS_UNSUBSCRIBE, + 0, 0, 0)) { + lwsl_err("%s: Failed to fill fixed header\n", __func__); + return 1; + } + + /* + * Pid + (Topic len field + Topic len) x Num of Topics + */ + rem_len = 2; + for (n = 0; n < unsub->num_topics; n++) + if (send_unsub[n]) + rem_len += (2 + (uint32_t)strlen(unsub->topic[n].name)); + + wsi->mqtt->sub_size = rem_len; + + lwsl_debug("%s: Number of topics = %d, Remaining len = %d\n", + __func__, (int)tops, (int)rem_len); + + p += lws_mqtt_vbi_encode(rem_len, p); + + if ((rem_len + lws_ptr_diff(p, start)) >= + wsi->a.context->pt_serv_buf_size) { + lwsl_err("%s: Payload is too big\n", __func__); + return 1; + } + + /* Init lws_mqtt_str */ + lws_mqtt_str_init(&mqtt_vh_payload, (uint8_t *)p, rem_len, 0); + p = lws_mqtt_str_next(&mqtt_vh_payload, NULL); + + /* Packet ID */ + wsi->mqtt->ack_pkt_id = ++nwsi->mqtt->pkt_id; + lwsl_debug("%s: pkt_id = %d\n", __func__, + (int)wsi->mqtt->ack_pkt_id); + lws_ser_wu16be(p, wsi->mqtt->ack_pkt_id); + + if (lws_mqtt_str_advance(&mqtt_vh_payload, 2)) + return 1; + + p = lws_mqtt_str_next(&mqtt_vh_payload, NULL); + + for (n = 0; n < unsub->num_topics; n++) { + lwsl_info("%s: topics[%d] = %s\n", __func__, + (int)n, unsub->topic[n].name); + + /* + * Subscriber still bound to it, don't UBSUB + * from the server + */ + if (!send_unsub[n]) + continue; + + /* Topic's Len */ + lws_ser_wu16be(p, (uint16_t)strlen(unsub->topic[n].name)); + if (lws_mqtt_str_advance(&mqtt_vh_payload, 2)) + return 1; + p = lws_mqtt_str_next(&mqtt_vh_payload, NULL); + + /* Topic Name */ + lws_strncpy((char *)p, unsub->topic[n].name, + strlen(unsub->topic[n].name) + 1); + if (lws_mqtt_str_advance(&mqtt_vh_payload, + (int)strlen(unsub->topic[n].name))) + return 1; + p = lws_mqtt_str_next(&mqtt_vh_payload, NULL); + } + break; + + default: + return 1; + } + + if (lws_write(nwsi, start, lws_ptr_diff(p, start), LWS_WRITE_BINARY) != + lws_ptr_diff(p, start)) + return 1; + + wsi->mqtt->inside_unsubscribe = 1; + + return 0; +} + +/* + * This is called when child streams bind to an already-existing and compatible + * MQTT stream + */ + +struct lws * +lws_wsi_mqtt_adopt(struct lws *parent_wsi, struct lws *wsi) +{ + /* no more children allowed by parent? */ + + if (parent_wsi->mux.child_count + 1 > LWS_MQTT_MAX_CHILDREN) { + lwsl_err("%s: reached concurrent stream limit\n", __func__); + return NULL; + } + +#if defined(LWS_WITH_CLIENT) + wsi->client_mux_substream = 1; +#endif + + lws_wsi_mux_insert(wsi, parent_wsi, wsi->mux.my_sid); + + if (lws_ensure_user_space(wsi)) + goto bail1; + + lws_mqtt_set_client_established(wsi); + lws_callback_on_writable(wsi); + +#if defined(LWS_WITH_SERVER_STATUS) + wsi->a.vhost->conn_stats.mqtt_subs++; +#endif + + return wsi; + +bail1: + /* undo the insert */ + parent_wsi->mux.child_list = wsi->mux.sibling_list; + parent_wsi->mux.child_count--; + + if (wsi->user_space) + lws_free_set_NULL(wsi->user_space); + + wsi->a.protocol->callback(wsi, LWS_CALLBACK_WSI_DESTROY, NULL, NULL, 0); + lws_free(wsi); + + return NULL; +} + diff -Nru libwebsockets-3.2.1/lib/roles/mqtt/ops-mqtt.c libwebsockets-4.1.6/lib/roles/mqtt/ops-mqtt.c --- libwebsockets-3.2.1/lib/roles/mqtt/ops-mqtt.c 1970-01-01 00:00:00.000000000 +0000 +++ libwebsockets-4.1.6/lib/roles/mqtt/ops-mqtt.c 2020-12-01 17:40:26.000000000 +0000 @@ -0,0 +1,601 @@ +/* + * libwebsockets - small server side websockets and web server implementation + * + * Copyright (C) 2010 - 2020 Andy Green + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to + * deal in the Software without restriction, including without limitation the + * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or + * sell copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS + * IN THE SOFTWARE. + */ + +#include "private-lib-core.h" + +static int +rops_handle_POLLIN_mqtt(struct lws_context_per_thread *pt, struct lws *wsi, + struct lws_pollfd *pollfd) +{ + unsigned int pending = 0; + struct lws_tokens ebuf; + int n = 0; + char buffered = 0; + + lwsl_debug("%s: wsistate 0x%x, %s pollout %d\n", __func__, + (unsigned int)wsi->wsistate, wsi->a.protocol->name, + pollfd->revents); + + /* + * After the CONNACK and nwsi establishment, the first logical + * stream is migrated out of the nwsi to be child sid 1, and the + * nwsi no longer has a wsi->mqtt of its own. + * + * RX events on the nwsi must be converted to events seen or not + * seen by one or more child streams. + * + * SUBACK - reflected to child stream that asked for it + * PUBACK - routed to child that did the related publish + */ + + ebuf.token = NULL; + ebuf.len = 0; + + if (lwsi_state(wsi) != LRS_ESTABLISHED) { +#if defined(LWS_WITH_CLIENT) + + if (lwsi_state(wsi) == LRS_WAITING_SSL && + ((pollfd->revents & LWS_POLLOUT)) && + lws_change_pollfd(wsi, LWS_POLLOUT, 0)) { + lwsl_info("failed at set pollfd\n"); + return LWS_HPI_RET_PLEASE_CLOSE_ME; + } + + if ((pollfd->revents & LWS_POLLOUT) && + lws_handle_POLLOUT_event(wsi, pollfd)) { + lwsl_debug("POLLOUT event closed it\n"); + return LWS_HPI_RET_PLEASE_CLOSE_ME; + } + + n = lws_mqtt_client_socket_service(wsi, pollfd, NULL); + if (n) + return LWS_HPI_RET_WSI_ALREADY_DIED; +#endif + return LWS_HPI_RET_HANDLED; + } + + /* 1: something requested a callback when it was OK to write */ + + if ((pollfd->revents & LWS_POLLOUT) && + lwsi_state_can_handle_POLLOUT(wsi) && + lws_handle_POLLOUT_event(wsi, pollfd)) { + if (lwsi_state(wsi) == LRS_RETURNED_CLOSE) + lwsi_set_state(wsi, LRS_FLUSHING_BEFORE_CLOSE); + + return LWS_HPI_RET_PLEASE_CLOSE_ME; + } + + /* 3: buflist needs to be drained + */ +read: + // lws_buflist_describe(&wsi->buflist, wsi, __func__); + ebuf.len = (int)lws_buflist_next_segment_len(&wsi->buflist, &ebuf.token); + if (ebuf.len) { + lwsl_info("draining buflist (len %d)\n", ebuf.len); + buffered = 1; + goto drain; + } + + if (!(pollfd->revents & pollfd->events & LWS_POLLIN)) + return LWS_HPI_RET_HANDLED; + + /* if (lws_is_flowcontrolled(wsi)) { */ + /* lwsl_info("%s: %p should be rxflow (bm 0x%x)..\n", */ + /* __func__, wsi, wsi->rxflow_bitmap); */ + /* return LWS_HPI_RET_HANDLED; */ + /* } */ + + if (!(lwsi_role_client(wsi) && lwsi_state(wsi) != LRS_ESTABLISHED)) { + /* + * In case we are going to react to this rx by scheduling + * writes, we need to restrict the amount of rx to the size + * the protocol reported for rx buffer. + * + * Otherwise we get a situation we have to absorb possibly a + * lot of reads before we get a chance to drain them by writing + * them, eg, with echo type tests in autobahn. + */ + + buffered = 0; + ebuf.token = pt->serv_buf; + ebuf.len = wsi->a.context->pt_serv_buf_size; + + if ((unsigned int)ebuf.len > wsi->a.context->pt_serv_buf_size) + ebuf.len = wsi->a.context->pt_serv_buf_size; + + if ((int)pending > ebuf.len) + pending = ebuf.len; + + ebuf.len = lws_ssl_capable_read(wsi, ebuf.token, + pending ? (int)pending : + ebuf.len); + switch (ebuf.len) { + case 0: + lwsl_info("%s: zero length read\n", + __func__); + return LWS_HPI_RET_PLEASE_CLOSE_ME; + case LWS_SSL_CAPABLE_MORE_SERVICE: + lwsl_info("SSL Capable more service\n"); + return LWS_HPI_RET_HANDLED; + case LWS_SSL_CAPABLE_ERROR: + lwsl_info("%s: LWS_SSL_CAPABLE_ERROR\n", + __func__); + return LWS_HPI_RET_PLEASE_CLOSE_ME; + } + + /* + * coverity thinks ssl_capable_read() may read over + * 2GB. Dissuade it... + */ + ebuf.len &= 0x7fffffff; + } + +drain: + /* service incoming data */ + //lws_buflist_describe(&wsi->buflist, wsi, __func__); + if (ebuf.len) { + n = lws_read_mqtt(wsi, ebuf.token, ebuf.len); + if (n < 0) { + lwsl_notice("%s: lws_read_mqtt returned %d\n", + __func__, n); + /* we closed wsi */ + goto fail; + } + // lws_buflist_describe(&wsi->buflist, wsi, __func__); + lwsl_debug("%s: consuming %d / %d\n", __func__, n, ebuf.len); + if (lws_buflist_aware_finished_consuming(wsi, &ebuf, ebuf.len, + buffered, __func__)) + return LWS_HPI_RET_PLEASE_CLOSE_ME; + } + + ebuf.token = NULL; + ebuf.len = 0; + + pending = lws_ssl_pending(wsi); + if (pending) { + pending = pending > wsi->a.context->pt_serv_buf_size ? + wsi->a.context->pt_serv_buf_size : pending; + goto read; + } + + if (buffered && /* were draining, now nothing left */ + !lws_buflist_next_segment_len(&wsi->buflist, NULL)) { + lwsl_info("%s: %p flow buf: drained\n", __func__, wsi); + /* having drained the rxflow buffer, can rearm POLLIN */ +#if !defined(LWS_WITH_SERVER) + n = +#endif + __lws_rx_flow_control(wsi); + /* n ignored, needed for NO_SERVER case */ + } + + /* n = 0 */ + return LWS_HPI_RET_HANDLED; + +fail: + lwsl_err("%s: Failed, bailing\n", __func__); + lws_close_free_wsi(wsi, LWS_CLOSE_STATUS_NOSTATUS, "mqtt svc fail"); + + return LWS_HPI_RET_WSI_ALREADY_DIED; +} + +#if 0 /* defined(LWS_WITH_SERVER) */ + +static int +rops_adoption_bind_mqtt(struct lws *wsi, int type, const char *vh_prot_name) +{ + /* no http but socket... must be mqtt */ + if ((type & LWS_ADOPT_HTTP) || !(type & LWS_ADOPT_SOCKET) || + (type & _LWS_ADOPT_FINISH)) + return 0; /* no match */ + + lws_role_transition(wsi, 0, (type & LWS_ADOPT_ALLOW_SSL) ? LRS_SSL_INIT : + LRS_ESTABLISHED, &role_ops_mqtt); + + if (vh_prot_name) + lws_bind_protocol(wsi, wsi->a.protocol, __func__); + else + /* this is the only time he will transition */ + lws_bind_protocol(wsi, + &wsi->a.vhost->protocols[wsi->a.vhost->mqtt_protocol_index], + __func__); + + return 1; /* bound */ +} +#endif + +static int +rops_client_bind_mqtt(struct lws *wsi, const struct lws_client_connect_info *i) +{ + lwsl_debug("%s: i = %p\n", __func__, i); + if (!i) { + + /* finalize */ + + if (!wsi->user_space && wsi->stash->cis[CIS_METHOD]) + if (lws_ensure_user_space(wsi)) + return 1; + + if (!wsi->stash->cis[CIS_METHOD] && !wsi->stash->cis[CIS_ALPN]) + wsi->stash->cis[CIS_ALPN] = "x-amzn-mqtt-ca"; + + /* if we went on the ah waiting list, it's ok, we can + * wait. + * + * When we do get the ah, now or later, he will end up + * at lws_http_client_connect_via_info2(). + */ +#if defined(LWS_WITH_CLIENT) + if (lws_header_table_attach(wsi, 0) < 0) + /* + * if we failed here, the connection is already closed + * and freed. + */ + return -1; +#else + if (lws_header_table_attach(wsi, 0)) + return 0; +#endif + return 0; + } + + /* if a recognized mqtt method, bind to it */ + if (strcmp(i->method, "MQTT")) + return 0; /* no match */ + + if (lws_create_client_mqtt_object(i, wsi)) + return 1; + + lws_role_transition(wsi, LWSIFR_CLIENT, LRS_UNCONNECTED, + &role_ops_mqtt); + return 1; /* matched */ +} + +static int +rops_handle_POLLOUT_mqtt(struct lws *wsi) +{ + struct lws **wsi2; + + lwsl_debug("%s\n", __func__); + +#if defined(LWS_WITH_CLIENT) + if (wsi->mqtt && wsi->mqtt->send_pingreq && !wsi->mqtt->inside_payload) { + uint8_t buf[LWS_PRE + 2]; + + /* + * We are swallowing this POLLOUT in order to send a PINGREQ + * autonomously + */ + + wsi->mqtt->send_pingreq = 0; + + lwsl_notice("%s: issuing PINGREQ\n", __func__); + + buf[LWS_PRE] = LMQCP_CTOS_PINGREQ << 4; + buf[LWS_PRE + 1] = 0; + + if (lws_write(wsi, (uint8_t *)&buf[LWS_PRE], 2, + LWS_WRITE_BINARY) != 2) + return LWS_HP_RET_BAIL_DIE; + + return LWS_HP_RET_BAIL_OK; + } +#endif + + wsi = lws_get_network_wsi(wsi); + + wsi->mux.requested_POLLOUT = 0; + + wsi2 = &wsi->mux.child_list; + if (!*wsi2) { + lwsl_debug("%s: no children\n", __func__); + return LWS_HP_RET_DROP_POLLOUT; + } + + lws_wsi_mux_dump_waiting_children(wsi); + + do { + struct lws *w, **wa; + + wa = &(*wsi2)->mux.sibling_list; + if (!(*wsi2)->mux.requested_POLLOUT) + goto next_child; + + if (!lwsi_state_can_handle_POLLOUT(wsi)) + goto next_child; + + /* + * If the nwsi is in the middle of a frame, we can only + * continue to send that + */ + + if (wsi->mqtt->inside_payload && !(*wsi2)->mqtt->inside_payload) + goto next_child; + + /* + * we're going to do writable callback for this child. + * move him to be the last child + */ + w = lws_wsi_mux_move_child_to_tail(wsi2); + if (!w) { + wa = &wsi->mux.child_list; + goto next_child; + } + + lwsl_debug("%s: child %p (wsistate 0x%x)\n", __func__, w, + (unsigned int)w->wsistate); + + if (lwsi_state(wsi) == LRS_ESTABLISHED && + !wsi->mqtt->inside_payload && + wsi->mqtt->send_puback) { + uint8_t buf[LWS_PRE + 4]; + lwsl_notice("%s: issuing PUBACK for pkt id: %d\n", + __func__, wsi->mqtt->ack_pkt_id); + + /* Fixed header */ + buf[LWS_PRE] = LMQCP_PUBACK << 4; + /* Remaining len = 2 */ + buf[LWS_PRE + 1] = 2; + /* Packet ID */ + lws_ser_wu16be(&buf[LWS_PRE + 2], wsi->mqtt->ack_pkt_id); + + if (lws_write(wsi, (uint8_t *)&buf[LWS_PRE], 4, + LWS_WRITE_BINARY) != 4) + return LWS_HP_RET_BAIL_DIE; + + wsi->mqtt->send_puback = 0; + w->mux.requested_POLLOUT = 1; + + wa = &wsi->mux.child_list; + goto next_child; + } + + if (lws_callback_as_writeable(w)) { + lwsl_notice("%s: Closing child %p\n", __func__, w); + lws_close_free_wsi(w, LWS_CLOSE_STATUS_NOSTATUS, + "mqtt pollout handle"); + wa = &wsi->mux.child_list; + } + +next_child: + wsi2 = wa; + } while (wsi2 && *wsi2 && !lws_send_pipe_choked(wsi)); + + // lws_wsi_mux_dump_waiting_children(wsi); + + if (lws_wsi_mux_action_pending_writeable_reqs(wsi)) + return LWS_HP_RET_BAIL_DIE; + + return LWS_HP_RET_BAIL_OK; +} + +#if defined(LWS_WITH_CLIENT) +static int +rops_issue_keepalive_mqtt(struct lws *wsi, int isvalid) +{ + struct lws *nwsi = lws_get_network_wsi(wsi); + + if (isvalid) { + _lws_validity_confirmed_role(nwsi); + + return 0; + } + + nwsi->mqtt->send_pingreq = 1; + lws_callback_on_writable(nwsi); + + return 0; +} +#endif + +static int +rops_close_role_mqtt(struct lws_context_per_thread *pt, struct lws *wsi) +{ + struct lws *nwsi = lws_get_network_wsi(wsi); + lws_mqtt_subs_t *s, *s1, *mysub; + lws_mqttc_t *c; + + if (!wsi->mqtt) + return 0; + + c = &wsi->mqtt->client; + + lws_sul_cancel(&wsi->mqtt->sul_qos1_puback_wait); + + lws_mqtt_str_free(&c->username); + lws_mqtt_str_free(&c->password); + lws_mqtt_str_free(&c->will.message); + lws_mqtt_str_free(&c->will.topic); + lws_mqtt_str_free(&c->id); + + /* clean up any subscription allocations */ + + s = wsi->mqtt->subs_head; + wsi->mqtt->subs_head = NULL; + while (s) { + s1 = s->next; + /* + * Account for children no longer using nwsi subscription + */ + mysub = lws_mqtt_find_sub(nwsi->mqtt, (const char *)&s[1]); +// assert(mysub); /* if child subscribed, nwsi must feel the same */ + if (mysub) { + assert(mysub->ref_count); + mysub->ref_count--; + } + lws_free(s); + s = s1; + } + + lws_mqtt_publish_param_t *pub = + (lws_mqtt_publish_param_t *) + wsi->mqtt->rx_cpkt_param; + + if (pub) + lws_free_set_NULL(pub->topic); + + lws_free_set_NULL(wsi->mqtt->rx_cpkt_param); + + lws_free_set_NULL(wsi->mqtt); + + return 0; +} + +static int +rops_callback_on_writable_mqtt(struct lws *wsi) +{ +#if defined(LWS_WITH_CLIENT) + struct lws *network_wsi; +#endif + int already; + + lwsl_debug("%s: %p (wsistate 0x%x)\n", __func__, wsi, (unsigned int)wsi->wsistate); + + if (wsi->mux.requested_POLLOUT +#if defined(LWS_WITH_CLIENT) + && !wsi->client_h2_alpn +#endif + ) { + lwsl_debug("already pending writable\n"); + return 1; + } +#if 0 + /* is this for DATA or for control messages? */ + if (wsi->upgraded_to_http2 && !wsi->h2.h2n->pps && + !lws_h2_tx_cr_get(wsi)) { + /* + * other side is not able to cope with us sending DATA + * anything so no matter if we have POLLOUT on our side if it's + * DATA we want to send. + * + * Delay waiting for our POLLOUT until peer indicates he has + * space for more using tx window command in http2 layer + */ + lwsl_notice("%s: %p: skint (%d)\n", __func__, wsi, + wsi->h2.tx_cr); + wsi->h2.skint = 1; + return 0; + } + + wsi->h2.skint = 0; +#endif +#if defined(LWS_WITH_CLIENT) + network_wsi = lws_get_network_wsi(wsi); +#endif + already = lws_wsi_mux_mark_parents_needing_writeable(wsi); + + /* for network action, act only on the network wsi */ + + if (already +#if defined(LWS_WITH_CLIENT) + && !network_wsi->client_mux_substream +#endif + ) + return 1; + + return 0; +} + +static int +rops_close_kill_connection_mqtt(struct lws *wsi, enum lws_close_status reason) +{ + lwsl_info(" wsi: %p, his parent %p: child list %p, siblings:\n", wsi, + wsi->mux.parent_wsi, wsi->mux.child_list); + //lws_wsi_mux_dump_children(wsi); + + if (wsi->mux_substream +#if defined(LWS_WITH_CLIENT) + || wsi->client_mux_substream +#endif + ) { + lwsl_info("closing %p: parent %p: first child %p\n", wsi, + wsi->mux.parent_wsi, wsi->mux.child_list); + + if (wsi->mux.child_list && lwsl_visible(LLL_INFO)) { + lwsl_info(" parent %p: closing children: list:\n", wsi); + lws_wsi_mux_dump_children(wsi); + } + + lws_wsi_mux_close_children(wsi, reason); + } + + if (( +#if defined(LWS_WITH_CLIENT) + wsi->client_mux_substream || +#endif + wsi->mux_substream) && + wsi->mux.parent_wsi) { + lws_wsi_mux_sibling_disconnect(wsi); + } + + return 0; +} + + +struct lws_role_ops role_ops_mqtt = { + /* role name */ "mqtt", + /* alpn id */ "x-amzn-mqtt-ca", /* "mqtt/3.1.1" */ + /* check_upgrades */ NULL, + /* pt_init_destroy */ NULL, + /* init_vhost */ NULL, + /* destroy_vhost */ NULL, + /* service_flag_pending */ NULL, + .handle_POLLIN = rops_handle_POLLIN_mqtt, + .handle_POLLOUT = rops_handle_POLLOUT_mqtt, + /* perform_user_POLLOUT */ NULL, + /* callback_on_writable */ rops_callback_on_writable_mqtt, + /* tx_credit */ NULL, + .write_role_protocol = NULL, + /* encapsulation_parent */ NULL, + /* alpn_negotiated */ NULL, + /* close_via_role_protocol */ NULL, + .close_role = rops_close_role_mqtt, + .close_kill_connection = rops_close_kill_connection_mqtt, + /* destroy_role */ NULL, +#if 0 /* defined(LWS_WITH_SERVER) */ + /* adoption_bind */ rops_adoption_bind_mqtt, +#else + NULL, +#endif +#if defined(LWS_WITH_CLIENT) + .client_bind = rops_client_bind_mqtt, + .issue_keepalive = rops_issue_keepalive_mqtt, +#else + .client_bind = NULL, + .issue_keepalive = NULL, +#endif + .adoption_cb = { LWS_CALLBACK_MQTT_NEW_CLIENT_INSTANTIATED, + LWS_CALLBACK_MQTT_NEW_CLIENT_INSTANTIATED }, + .rx_cb = { LWS_CALLBACK_MQTT_CLIENT_RX, + LWS_CALLBACK_MQTT_CLIENT_RX }, + .writeable_cb = { LWS_CALLBACK_MQTT_CLIENT_WRITEABLE, + LWS_CALLBACK_MQTT_CLIENT_WRITEABLE }, + .close_cb = { LWS_CALLBACK_MQTT_CLIENT_CLOSED, + LWS_CALLBACK_MQTT_CLIENT_CLOSED }, + .protocol_bind_cb = { LWS_CALLBACK_MQTT_IDLE, + LWS_CALLBACK_MQTT_IDLE }, + .protocol_unbind_cb = { LWS_CALLBACK_MQTT_DROP_PROTOCOL, + LWS_CALLBACK_MQTT_DROP_PROTOCOL }, + .file_handle = 0, +}; diff -Nru libwebsockets-3.2.1/lib/roles/mqtt/primitives.c libwebsockets-4.1.6/lib/roles/mqtt/primitives.c --- libwebsockets-3.2.1/lib/roles/mqtt/primitives.c 1970-01-01 00:00:00.000000000 +0000 +++ libwebsockets-4.1.6/lib/roles/mqtt/primitives.c 2020-12-01 17:40:26.000000000 +0000 @@ -0,0 +1,324 @@ +/* + * libwebsockets - small server side websockets and web server implementation + * + * Copyright (C) 2010 - 2020 Andy Green + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to + * deal in the Software without restriction, including without limitation the + * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or + * sell copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS + * IN THE SOFTWARE. + * + * MQTT v5 + * + * http://docs.oasis-open.org/mqtt/mqtt/v5.0/mqtt-v5.0.html + */ + +#include "private-lib-core.h" + +#include +#include +#include + + +/* + * Encode is done into a buffer of at least 4 bytes space. + * + * Returns -1 for error, or number of bytes used + */ + +int +lws_mqtt_vbi_encode(uint32_t value, void *buf) +{ + uint8_t *p = (uint8_t *)buf, b; + + if (value > 0xfffffff) { + assert(0); + return -1; + } + + do { + b = value & 0x7f; + value >>= 7; + if (value) + *p++ = (0x80 | b); + else + *p++ = b; + } while (value); + + return lws_ptr_diff(p, (uint8_t *)buf); +} + +void +lws_mqtt_vbi_init(lws_mqtt_vbi *vbi) +{ + vbi->value = 0; + vbi->consumed = 0; + vbi->budget = 4; +} + +void +lws_mqtt_2byte_init(lws_mqtt_vbi *vbi) +{ + vbi->value = 0; + vbi->consumed = 0; + vbi->budget = 2; +} + +void +lws_mqtt_4byte_init(lws_mqtt_vbi *vbi) +{ + vbi->value = 0; + vbi->consumed = 0; + vbi->budget = 4; +} + +lws_mqtt_stateful_primitive_return_t +lws_mqtt_vbi_r(lws_mqtt_vbi *vbi, const uint8_t **in, size_t *len) +{ + uint8_t multiplier = 0; + if (!vbi->budget) { + lwsl_info("%s: bad vbi\n", __func__); + + return LMSPR_FAILED_ALREADY_COMPLETED; + } + + while (*len && vbi->budget--) { + uint8_t u = *((*in)++); + + (*len)--; + vbi->consumed++; + vbi->value += (u & 0x7f) << multiplier; + multiplier += 7; + if (!(u & 0x80)) + return LMSPR_COMPLETED; /* finished */ + } + + if (!vbi->budget) { /* should have ended on b7 = 0 and exited then... */ + lwsl_info("%s: bad vbi\n", __func__); + + return LMSPR_FAILED_FORMAT; + } + + return LMSPR_NEED_MORE; +} + +lws_mqtt_stateful_primitive_return_t +lws_mqtt_mb_parse(lws_mqtt_vbi *vbi, const uint8_t **in, size_t *len) +{ + if (!vbi->budget) + return LMSPR_FAILED_ALREADY_COMPLETED; + + while (*len && vbi->budget--) { + vbi->value = (vbi->value << 8) | *((*in)++); + (*len)--; + vbi->consumed++; + } + + return vbi->budget ? LMSPR_NEED_MORE : LMSPR_COMPLETED; +} + +/* + * You can leave buf NULL, if so it will be allocated on the heap once the + * actual length is known. nf should be 0, it will be set at allocation time. + * + * Or you can ensure no allocation and use an external buffer by setting buf + * and lim. But buf must be in the ep context somehow, since it may have to + * survive returns to the event loop unchanged. Set nf to 0 in this case. + * + * Or you can set buf to an externally allocated buffer, in which case you may + * set nf so it will be freed when the string is "freed". + */ + +void +lws_mqtt_str_init(lws_mqtt_str_t *s, uint8_t *buf, uint16_t lim, char nf) +{ + s->len = 0; /* at COMPLETED, consumed count is s->len + 2 */ + s->pos = 0; + s->buf = buf; + s->limit = lim; + s->len_valid = 0; + s->needs_freeing = nf; +} + +lws_mqtt_str_t * +lws_mqtt_str_create(uint16_t lim) +{ + lws_mqtt_str_t *s = lws_malloc(sizeof(*s) + lim + 1, __func__); + + if (!s) + return NULL; + + s->len = 0; + s->pos = 0; + s->buf = (uint8_t *)&s[1]; + s->limit = lim; + s->len_valid = 0; + s->needs_freeing = 1; + + return s; +} + +lws_mqtt_str_t * +lws_mqtt_str_create_init(uint8_t *buf, uint16_t len, uint16_t lim) +{ + lws_mqtt_str_t *s; + + if (!lim) + lim = len; + + s = lws_mqtt_str_create(lim); + + if (!s) + return NULL; + + memcpy(s->buf, buf, len); + s->len = len; + s->len_valid = 1; + s->pos = len; + + return s; +} + + +lws_mqtt_str_t * +lws_mqtt_str_create_cstr_dup(const char *buf, uint16_t lim) +{ + size_t len = strlen(buf); + + if (!lim) + lim = (uint16_t)len; + + return lws_mqtt_str_create_init((uint8_t *)buf, (uint16_t)len, lim); +} + +uint8_t * +lws_mqtt_str_next(lws_mqtt_str_t *s, uint16_t *budget) +{ + if (budget) + *budget = s->limit - s->pos; + + return &s->buf[s->pos]; +} + +int +lws_mqtt_str_advance(lws_mqtt_str_t *s, int n) +{ + if (n > s->limit - s->pos) { + lwsl_err("%s: attempted overflow %d vs %d\n", __func__, + n, s->limit - s->pos); + return 1; + } + + s->pos += n; + s->len += n; + + return 0; +} + +void +lws_mqtt_str_free(lws_mqtt_str_t **ps) +{ + lws_mqtt_str_t *s = *ps; + + if (!s || !s->needs_freeing) + return; + + /* buf may be independently allocated or allocated along with the + * lws_mqtt_str_t at the end... if so the whole lws_mqtt_str_t is freed. + */ + + if (s->buf != (uint8_t *)&s[1]) + lws_free_set_NULL(s->buf); + else + lws_free_set_NULL(*ps); +} + +/* + * Parses and allocates for lws_mqtt_str_t in a fragmentation-immune, but + * efficient for bulk data way. + * + * Returns: LMSPR_NEED_MORE if needs more data, + * LMSPR_COMPLETED if complete, <0 for error + * + * *len is reduced by, and *in is advanced by, the amount of data actually used, + * except in error case + * + * lws_mqtt_str_free() must be called after calling this successfully + * or not. + */ +lws_mqtt_stateful_primitive_return_t +lws_mqtt_str_parse(lws_mqtt_str_t *s, const uint8_t **in, size_t *len) +{ + const uint8_t *oin = *in; + + /* handle the length + allocation if needed */ + while (*len && !s->len_valid && s->pos < 2) { + s->len = (s->len << 8) | *((*in)++); + (*len)--; + oin = *in; + if (++s->pos == 2) { + if (s->len > s->limit) + return LMSPR_FAILED_OVERSIZE; + + s->pos = 0; + s->len_valid = 1; + + if (!s->len) /* do not need to allocate */ + return LMSPR_COMPLETED; + + if (!s->buf) { + s->buf = lws_malloc(s->len, __func__); + if (!s->buf) + return LMSPR_FAILED_OOM; + + s->needs_freeing = 1; + } + } + } + + /* handle copying bulk data into allocation */ + if (s->len_valid && *len) { + uint16_t span = s->len - s->pos; + + if (span > *len) + span = (uint16_t)*len; + + memcpy(s->buf + s->pos, *in, span); + *in += span; + s->pos += span; + } + + *len -= *in - oin; + + return s->buf && s->pos == s->len ? LMSPR_COMPLETED : LMSPR_NEED_MORE; +} + +int +lws_mqtt_bindata_cmp(const lws_mqtt_str_t *bd1, + const lws_mqtt_str_t *bd2) +{ + if (bd1->len != bd2->len) + return 1; + + if (!!bd1->buf != !!bd2->buf) + return 1; + + if (!bd1->buf && !bd2->buf) + return 0; + + return memcmp(bd1->buf, bd2->buf, bd1->len); +} + diff -Nru libwebsockets-3.2.1/lib/roles/mqtt/private-lib-roles-mqtt.h libwebsockets-4.1.6/lib/roles/mqtt/private-lib-roles-mqtt.h --- libwebsockets-3.2.1/lib/roles/mqtt/private-lib-roles-mqtt.h 1970-01-01 00:00:00.000000000 +0000 +++ libwebsockets-4.1.6/lib/roles/mqtt/private-lib-roles-mqtt.h 2020-12-01 17:40:26.000000000 +0000 @@ -0,0 +1,396 @@ +/* + * libwebsockets - small server side websockets and web server implementation + * + * Copyright (C) 2010 - 2020 Andy Green + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to + * deal in the Software without restriction, including without limitation the + * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or + * sell copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS + * IN THE SOFTWARE. + */ + +#ifndef _PRIVATE_LIB_ROLES_MQTT +#define _PRIVATE_LIB_ROLES_MQTT 1 + +extern struct lws_role_ops role_ops_mqtt; + +#define lwsi_role_mqtt(wsi) (wsi->role_ops == &role_ops_mqtt) + +#define LWS_MQTT_MAX_CHILDREN 8 /* max child streams on same parent */ + +#define LMQCP_LUT_FLAG_RESERVED_FLAGS 0x10 +#define LMQCP_LUT_FLAG_PACKET_ID_NONE 0x00 +#define LMQCP_LUT_FLAG_PACKET_ID_HAS 0x20 +#define LMQCP_LUT_FLAG_PACKET_ID_QOS12 0x40 +#define LMQCP_LUT_FLAG_PACKET_ID_MASK 0x60 +#define LMQCP_LUT_FLAG_PAYLOAD 0x80 /* payload req (publish = opt)*/ + +#define lws_mqtt_str_is_not_empty(s) ( ((s)) && \ + ((s))->len && \ + ((s))->buf && \ + *((s))->buf ) + +#define LWS_MQTT_RESPONSE_TIMEOUT (3 * LWS_US_PER_SEC) +#define LWS_MQTT_RETRY_CEILING (60 * LWS_US_PER_SEC) + +typedef enum { + LMSPR_COMPLETED = 0, + LMSPR_NEED_MORE = 1, + + LMSPR_FAILED_OOM = -1, + LMSPR_FAILED_OVERSIZE = -2, + LMSPR_FAILED_FORMAT = -3, + LMSPR_FAILED_ALREADY_COMPLETED = -4, +} lws_mqtt_stateful_primitive_return_t; + +typedef struct { + uint32_t value; + char budget; + char consumed; +} lws_mqtt_vbi; + +/* works for vbi, 2-byte and 4-byte fixed length */ +static inline int +lws_mqtt_mb_first(lws_mqtt_vbi *vbi) { return !vbi->consumed; } + +int +lws_mqtt_vbi_encode(uint32_t value, void *buf); + +/* + * Decode is done statefully on an arbitrary amount of input data (which may + * be one byte). It's like this so it can continue seamlessly if a buffer ends + * partway through the primitive, and the api matches the bulk binary data case. + * + * VBI decode: + * + * Initialize the lws_mqtt_vbi state by calling lws_mqtt_vbi_init() on it, then + * feed lws_mqtt_vbi_r() bytes to decode. + * + * Returns <0 for error, LMSPR_COMPLETED if done (vbi->value is valid), or + * LMSPR_NEED_MORE if more calls to lws_mqtt_vbi_r() with subsequent bytes + * needed. + * + * *in and *len are updated accordingly. + * + * 2-byte and 4-byte decode: + * + * Initialize the lws_mqtt_vbi state by calling lws_mqtt_2byte_init() or + * lws_mqtt_4byte_init() on it, then feed lws_mqtt_mb_parse() bytes + * to decode. + * + * Returns <0 for error, LMSPR_COMPLETED if done (vbi->value is valid), or + * LMSPR_NEED_MORE if more calls to lws_mqtt_mb_parse() with subsequent + * bytes needed. + * + * *in and *len are updated accordingly. + */ + +void +lws_mqtt_vbi_init(lws_mqtt_vbi *vbi); + +void +lws_mqtt_2byte_init(lws_mqtt_vbi *vbi); + +void +lws_mqtt_4byte_init(lws_mqtt_vbi *vbi); + +lws_mqtt_stateful_primitive_return_t +lws_mqtt_vbi_r(lws_mqtt_vbi *vbi, const uint8_t **in, size_t *len); + +lws_mqtt_stateful_primitive_return_t +lws_mqtt_mb_parse(lws_mqtt_vbi *vbi, const uint8_t **in, size_t *len); + +struct lws_mqtt_str_st { + uint8_t *buf; + uint16_t len; + + uint16_t limit; /* it's cheaper to add the state here than + * the pointer to point to it elsewhere */ + uint16_t pos; + char len_valid; + char needs_freeing; +}; + +static inline int +lws_mqtt_str_first(struct lws_mqtt_str_st *s) { return !s->buf && !s->pos; } + + +lws_mqtt_stateful_primitive_return_t +lws_mqtt_str_parse(struct lws_mqtt_str_st *bd, const uint8_t **in, size_t *len); + +typedef enum { + LMQCPP_IDLE, + + /* receive packet type part of fixed header took us out of idle... */ + LMQCPP_CONNECT_PACKET = LMQCP_CTOS_CONNECT << 4, + LMQCPP_CONNECT_REMAINING_LEN_VBI, + LMQCPP_CONNECT_VH_PNAME, + LMQCPP_CONNECT_VH_PVERSION, + LMQCPP_CONNECT_VH_FLAGS, + LMQCPP_CONNECT_VH_KEEPALIVE, + LMQCPP_CONNECT_VH_PROPERTIES_VBI_LEN, + + LMQCPP_CONNACK_PACKET = LMQCP_STOC_CONNACK << 4, + LMQCPP_CONNACK_VH_FLAGS, + LMQCPP_CONNACK_VH_RETURN_CODE, + + LMQCPP_PUBLISH_PACKET = LMQCP_PUBLISH << 4, + LMQCPP_PUBLISH_REMAINING_LEN_VBI, + LMQCPP_PUBLISH_VH_TOPIC, + LMQCPP_PUBLISH_VH_PKT_ID, + + LMQCPP_PUBACK_PACKET = LMQCP_PUBACK << 4, + LMQCPP_PUBACK_VH_PKT_ID, + LMQCPP_PUBACK_PROPERTIES_LEN_VBI, + + LMQCPP_SUBACK_PACKET = LMQCP_STOC_SUBACK << 4, + LMQCPP_SUBACK_VH_PKT_ID, + LMQCPP_SUBACK_PAYLOAD, + + LMQCPP_UNSUBACK_PACKET = LMQCP_STOC_UNSUBACK << 4, + LMQCPP_UNSUBACK_VH_PKT_ID, + + LMQCPP_PINGRESP_ZERO = LMQCP_STOC_PINGRESP << 4, + + LMQCPP_PAYLOAD, + + LMQCPP_EAT_PROPERTIES_AND_COMPLETE, + + LMQCPP_PROP_ID_VBI, + + /* all possible property payloads */ + + /* 3.3.2.3.2 */ + LMQCPP_PROP_PAYLOAD_FORMAT_INDICATOR_1BYTE = 0x101, + + LMQCPP_PROP_MSG_EXPIRY_INTERVAL_4BYTE = 0x102, + + LMQCPP_PROP_CONTENT_TYPE_UTF8S = 0x103, + + LMQCPP_PROP_RESPONSE_TOPIC_UTF8S = 0x108, + + LMQCPP_PROP_CORRELATION_BINDATA = 0x109, + + LMQCPP_PROP_SUBSCRIPTION_ID_VBI = 0x10b, + + LMQCPP_PROP_SESSION_EXPIRY_INTERVAL_4BYTE = 0x111, + + LMQCPP_PROP_ASSIGNED_CLIENTID_UTF8S = 0x112, + + LMQCPP_PROP_SERVER_KEEPALIVE_2BYTE = 0x113, + + LMQCPP_PROP_AUTH_METHOD_UTF8S = 0x115, + + LMQCPP_PROP_AUTH_DATA_BINDATA = 0x116, + + LMQCPP_PROP_REQUEST_PROBLEM_INFO_1BYTE = 0x117, + + LMQCPP_PROP_WILL_DELAY_INTERVAL_4BYTE = 0x118, + + LMQCPP_PROP_REQUEST_REPSONSE_INFO_1BYTE = 0x119, + + LMQCPP_PROP_RESPONSE_INFO_UTF8S = 0x11a, + + LMQCPP_PROP_SERVER_REFERENCE_UTF8S = 0x11c, + + LMQCPP_PROP_REASON_STRING_UTF8S = 0x11f, + + LMQCPP_PROP_RECEIVE_MAXIMUM_2BYTE = 0x121, + + LMQCPP_PROP_TOPIC_MAXIMUM_2BYTE = 0x122, + + LMQCPP_PROP_TOPIC_ALIAS_2BYTE = 0x123, + + LMQCPP_PROP_MAXIMUM_QOS_1BYTE = 0x124, + + LMQCPP_PROP_RETAIN_AVAILABLE_1BYTE = 0x125, + + LMQCPP_PROP_USER_PROPERTY_NAME_UTF8S = 0x126, + LMQCPP_PROP_USER_PROPERTY_VALUE_UTF8S = 0x226, + + LMQCPP_PROP_MAXIMUM_PACKET_SIZE_4BYTE = 0x127, + + LMQCPP_PROP_WILDCARD_SUBSCRIPTION_AVAILABLE_1BYTE = 0x128, + + LMQCPP_PROP_SUBSCRIPTION_IDENTIFIER_AVAILABLE_1BYTE = 0x129, + + LMQCPP_PROP_SHARED_SUBSCRIPTION_AVAILABLE_1BYTE = 0x12a, + +} lws_mqtt_packet_parse_state_t; + +/* + * the states an MQTT connection can be in + */ + +typedef enum { + LGSMQTT_UNKNOWN, + LGSMQTT_IDLE, + LGSMQTT_TRANSPORT_CONNECTED, + + LGSMQTT_SENT_CONNECT, + LGSMQTT_ESTABLISHED, + + LGSMQTT_SENT_SUBSCRIBE, + LGSMQTT_SUBSCRIBED, + +} lwsgs_mqtt_states_t; + +typedef struct lws_mqtt_parser_st { + /* struct lws_mqtt_str_st s_content_type; */ + lws_mqtt_packet_parse_state_t state; + lws_mqtt_vbi vbit; + + lws_mqtt_reason_t reason; + + lws_mqtt_str_t s_temp; + + uint8_t fixed_seen[4]; + uint8_t props_seen[8]; + + uint8_t cpkt_flags; + uint32_t cpkt_remlen; + + uint32_t props_len; + uint32_t consumed; + uint32_t prop_id; + uint32_t props_consumed; + uint32_t payload_consumed; + + uint16_t keepalive; + uint16_t cpkt_id; + uint32_t n; + + uint8_t temp[32]; + uint8_t conn_rc; + uint8_t payload_format; + uint8_t packet_type_flags; + uint8_t conn_protocol_version; + uint8_t fixed; + + uint8_t flag_pending_send_connack_close:1; + uint8_t flag_pending_send_reason_close:1; + uint8_t flag_prop_multi:1; + uint8_t flag_server:1; + +} lws_mqtt_parser_t; + +typedef struct lws_mqtt_subs { + struct lws_mqtt_subs *next; + + uint8_t ref_count; /* number of children referencing */ + + /* subscription name + NUL overallocated here */ + char topic[]; +} lws_mqtt_subs_t; + +typedef struct lws_mqtts { + lws_mqtt_parser_t par; + lwsgs_mqtt_states_t estate; + struct lws_dll2 active_session_list_head; + struct lws_dll2 limbo_session_list_head; +} lws_mqtts_t; + +typedef struct lws_mqttc { + lws_mqtt_parser_t par; + lwsgs_mqtt_states_t estate; + struct lws_mqtt_str_st *id; + struct lws_mqtt_str_st *username; + struct lws_mqtt_str_st *password; + struct { + struct lws_mqtt_str_st *topic; + struct lws_mqtt_str_st *message; + lws_mqtt_qos_levels_t qos; + uint8_t retain; + } will; + uint16_t keep_alive_secs; + uint8_t conn_flags; +} lws_mqttc_t; + +struct _lws_mqtt_related { + lws_mqttc_t client; + lws_sorted_usec_list_t sul_qos1_puback_wait; /* QoS1 puback wait TO */ + struct lws *wsi; /**< so sul can use lws_container_of */ + lws_mqtt_subs_t *subs_head; /**< Linked-list of heap-allocated subscription objects */ + void *rx_cpkt_param; + uint16_t pkt_id; + uint16_t ack_pkt_id; + uint16_t sub_size; + +#if defined(LWS_WITH_CLIENT) + uint8_t send_pingreq:1; + uint8_t session_resumed:1; +#endif + uint8_t inside_payload:1; + uint8_t inside_subscribe:1; + uint8_t inside_unsubscribe:1; + uint8_t send_puback:1; + uint8_t unacked_publish:1; + + uint8_t done_subscribe:1; +}; + +/* + * New sessions are created by starting CONNECT. If the ClientID sent + * by the client matches a different, extant session, then the + * existing one is taken over and the new one created for duration of + * CONNECT processing is destroyed. + * + * On the server side, bearing in mind multiple simultaneous, + * fragmented CONNECTs may be interleaved ongoing, all state and + * parsing temps for a session must live in the session object. + */ + +struct lws_mqtt_endpoint_st; + +typedef struct lws_mqtts_session_st { + struct lws_dll2 session_list; + +} lws_mqtts_session_t; + +#define ctl_pkt_type(x) (x->packet_type_flags >> 4) + + +void +lws_mqttc_state_transition(lws_mqttc_t *ep, lwsgs_mqtt_states_t s); + +int +_lws_mqtt_rx_parser(struct lws *wsi, lws_mqtt_parser_t *par, + const uint8_t *buf, size_t len); + +int +lws_mqtt_client_socket_service(struct lws *wsi, struct lws_pollfd *pollfd, + struct lws *wsi_conn); + +int +lws_create_client_mqtt_object(const struct lws_client_connect_info *i, + struct lws *wsi); + +struct lws * +lws_mqtt_client_send_connect(struct lws *wsi); + +int +lws_mqtt_fill_fixed_header(uint8_t *p, lws_mqtt_control_packet_t ctrl_pkt_type, + uint8_t dup, lws_mqtt_qos_levels_t qos, + uint8_t retain); + +struct lws * +lws_wsi_mqtt_adopt(struct lws *parent_wsi, struct lws *wsi); + +lws_mqtt_subs_t * +lws_mqtt_find_sub(struct _lws_mqtt_related *mqtt, const char *topic); + +#endif /* _PRIVATE_LIB_ROLES_MQTT */ + diff -Nru libwebsockets-3.2.1/lib/roles/pipe/ops-pipe.c libwebsockets-4.1.6/lib/roles/pipe/ops-pipe.c --- libwebsockets-3.2.1/lib/roles/pipe/ops-pipe.c 2019-12-18 14:45:31.000000000 +0000 +++ libwebsockets-4.1.6/lib/roles/pipe/ops-pipe.c 2020-12-01 17:40:26.000000000 +0000 @@ -1,31 +1,44 @@ /* * libwebsockets - small server side websockets and web server implementation * - * Copyright (C) 2010-2018 Andy Green + * Copyright (C) 2010 - 2019 Andy Green * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation: - * version 2.1 of the License. + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to + * deal in the Software without restriction, including without limitation the + * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or + * sell copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: * - * This library is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. * - * You should have received a copy of the GNU Lesser General Public - * License along with this library; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, - * MA 02110-1301 USA + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS + * IN THE SOFTWARE. */ -#include +#include static int rops_handle_POLLIN_pipe(struct lws_context_per_thread *pt, struct lws *wsi, struct lws_pollfd *pollfd) { -#if !defined(WIN32) && !defined(_WIN32) +#if defined(LWS_HAVE_EVENTFD) + eventfd_t value; + int n; + + n = eventfd_read(wsi->desc.sockfd, &value); + if (n < 0) { + lwsl_notice("%s: eventfd read %d bailed errno %d\n", __func__, + wsi->desc.sockfd, LWS_ERRNO); + return LWS_HPI_RET_PLEASE_CLOSE_ME; + } +#elif !defined(WIN32) && !defined(_WIN32) char s[100]; int n; @@ -65,14 +78,13 @@ return LWS_HPI_RET_HANDLED; } -struct lws_role_ops role_ops_pipe = { +const struct lws_role_ops role_ops_pipe = { /* role name */ "pipe", /* alpn id */ NULL, /* check_upgrades */ NULL, - /* init_context */ NULL, + /* pt_init_destroy */ NULL, /* init_vhost */ NULL, /* destroy_vhost */ NULL, - /* periodic_checks */ NULL, /* service_flag_pending */ NULL, /* handle_POLLIN */ rops_handle_POLLIN_pipe, /* handle_POLLOUT */ NULL, @@ -88,6 +100,7 @@ /* destroy_role */ NULL, /* adoption_bind */ NULL, /* client_bind */ NULL, + /* issue_keepalive */ NULL, /* adoption_cb clnt, srv */ { 0, 0 }, /* rx_cb clnt, srv */ { 0, 0 }, /* writeable cb clnt, srv */ { 0, 0 }, diff -Nru libwebsockets-3.2.1/lib/roles/private.h libwebsockets-4.1.6/lib/roles/private.h --- libwebsockets-3.2.1/lib/roles/private.h 2019-12-18 14:45:31.000000000 +0000 +++ libwebsockets-4.1.6/lib/roles/private.h 1970-01-01 00:00:00.000000000 +0000 @@ -1,335 +0,0 @@ -/* - * libwebsockets - small server side websockets and web server implementation - * - * Copyright (C) 2010 - 2018 Andy Green - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation: - * version 2.1 of the License. - * - * This library is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with this library; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, - * MA 02110-1301 USA - * - * This is included from core/private.h - */ - -typedef uint32_t lws_wsi_state_t; - -/* - * The wsi->role_ops pointer decides almost everything about what role the wsi - * will play, h2, raw, ws, etc. - * - * However there are a few additional flags needed that vary, such as if the - * role is a client or server side, if it has that concept. And the connection - * fulfilling the role, has a separate dynamic state. - * - * 31 16 15 0 - * [ role flags ] [ state ] - * - * The role flags part is generally invariant for the lifetime of the wsi, - * although it can change if the connection role itself does, eg, if the - * connection upgrades from H1 -> WS1 the role flags may be changed at that - * point. - * - * The state part reflects the dynamic connection state, and the states are - * reused between roles. - * - * None of the internal role or state representations are made available outside - * of lws internals. Even for lws internals, if you add stuff here, please keep - * the constants inside this header only by adding necessary helpers here and - * use the helpers in the actual code. This is to ease any future refactors. - * - * Notice LWSIFR_ENCAP means we have a parent wsi that actually carries our - * data as a stream inside a different protocol. - */ - -#define _RS 16 - -#define LWSIFR_CLIENT (0x1000 << _RS) /* client side */ -#define LWSIFR_SERVER (0x2000 << _RS) /* server side */ - -#define LWSIFR_P_ENCAP_H2 (0x0100 << _RS) /* we are encapsulated by h2 */ - -enum lwsi_role { - LWSI_ROLE_MASK = (0xffff << _RS), - LWSI_ROLE_ENCAP_MASK = (0x0f00 << _RS), -}; - -#define lwsi_role(wsi) (wsi->wsistate & LWSI_ROLE_MASK) -#if !defined (_DEBUG) -#define lwsi_set_role(wsi, role) wsi->wsistate = \ - (wsi->wsistate & (~LWSI_ROLE_MASK)) | role -#else -void lwsi_set_role(struct lws *wsi, lws_wsi_state_t role); -#endif - -#define lwsi_role_client(wsi) (!!(wsi->wsistate & LWSIFR_CLIENT)) -#define lwsi_role_server(wsi) (!!(wsi->wsistate & LWSIFR_SERVER)) -#define lwsi_role_h2_ENCAPSULATION(wsi) \ - ((wsi->wsistate & LWSI_ROLE_ENCAP_MASK) == LWSIFR_P_ENCAP_H2) - -/* Pollout wants a callback in this state */ -#define LWSIFS_POCB (0x100) -/* Before any protocol connection was established */ -#define LWSIFS_NOT_EST (0x200) - -enum lwsi_state { - - /* Phase 1: pre-transport */ - - LRS_UNCONNECTED = LWSIFS_NOT_EST | 0, - LRS_WAITING_CONNECT = LWSIFS_NOT_EST | 1, - - /* Phase 2: establishing intermediaries on top of transport */ - - LRS_WAITING_PROXY_REPLY = LWSIFS_NOT_EST | 2, - LRS_WAITING_SSL = LWSIFS_NOT_EST | 3, - LRS_WAITING_SOCKS_GREETING_REPLY = LWSIFS_NOT_EST | 4, - LRS_WAITING_SOCKS_CONNECT_REPLY = LWSIFS_NOT_EST | 5, - LRS_WAITING_SOCKS_AUTH_REPLY = LWSIFS_NOT_EST | 6, - - /* Phase 3: establishing tls tunnel */ - - LRS_SSL_INIT = LWSIFS_NOT_EST | 7, - LRS_SSL_ACK_PENDING = LWSIFS_NOT_EST | 8, - LRS_PRE_WS_SERVING_ACCEPT = LWSIFS_NOT_EST | 9, - - /* Phase 4: connected */ - - LRS_WAITING_SERVER_REPLY = LWSIFS_NOT_EST | 10, - LRS_H2_AWAIT_PREFACE = LWSIFS_NOT_EST | 11, - LRS_H2_AWAIT_SETTINGS = LWSIFS_NOT_EST | - LWSIFS_POCB | 12, - - /* Phase 5: protocol logically established */ - - LRS_H2_CLIENT_SEND_SETTINGS = LWSIFS_POCB | 13, - LRS_H2_WAITING_TO_SEND_HEADERS = LWSIFS_POCB | 14, - LRS_DEFERRING_ACTION = LWSIFS_POCB | 15, - LRS_IDLING = 16, - LRS_H1C_ISSUE_HANDSHAKE = 17, - LRS_H1C_ISSUE_HANDSHAKE2 = 18, - LRS_ISSUE_HTTP_BODY = 19, - LRS_ISSUING_FILE = 20, - LRS_HEADERS = 21, - LRS_BODY = 22, - LRS_DISCARD_BODY = 31, - LRS_ESTABLISHED = LWSIFS_POCB | 23, - /* we are established, but we have embarked on serving a single - * transaction. Other transaction input may be pending, but we will - * not service it while we are busy dealing with the current - * transaction. - * - * When we complete the current transaction, we would reset our state - * back to ESTABLISHED and start to process the next transaction. - */ - LRS_DOING_TRANSACTION = LWSIFS_POCB | 24, - - /* Phase 6: finishing */ - - LRS_WAITING_TO_SEND_CLOSE = LWSIFS_POCB | 25, - LRS_RETURNED_CLOSE = LWSIFS_POCB | 26, - LRS_AWAITING_CLOSE_ACK = LWSIFS_POCB | 27, - LRS_FLUSHING_BEFORE_CLOSE = LWSIFS_POCB | 28, - LRS_SHUTDOWN = 29, - - /* Phase 7: dead */ - - LRS_DEAD_SOCKET = 30, - - LRS_MASK = 0xffff -}; - -#define lwsi_state(wsi) ((enum lwsi_state)(wsi->wsistate & LRS_MASK)) -#define lwsi_state_PRE_CLOSE(wsi) \ - ((enum lwsi_state)(wsi->wsistate_pre_close & LRS_MASK)) -#define lwsi_state_est(wsi) (!(wsi->wsistate & LWSIFS_NOT_EST)) -#define lwsi_state_est_PRE_CLOSE(wsi) \ - (!(wsi->wsistate_pre_close & LWSIFS_NOT_EST)) -#define lwsi_state_can_handle_POLLOUT(wsi) (wsi->wsistate & LWSIFS_POCB) -#if !defined (_DEBUG) -#define lwsi_set_state(wsi, lrs) wsi->wsistate = \ - (wsi->wsistate & (~LRS_MASK)) | lrs -#else -void lwsi_set_state(struct lws *wsi, lws_wsi_state_t lrs); -#endif - -#define _LWS_ADOPT_FINISH (1 << 24) - -/* - * internal role-specific ops - */ -struct lws_context_per_thread; -struct lws_role_ops { - const char *name; - const char *alpn; - /* - * After http headers have parsed, this is the last chance for a role - * to upgrade the connection to something else using the headers. - * ws-over-h2 is upgraded from h2 like this. - */ - int (*check_upgrades)(struct lws *wsi); - /* role-specific context init during context creation */ - int (*init_context)(struct lws_context *context, - const struct lws_context_creation_info *info); - /* role-specific per-vhost init during vhost creation */ - int (*init_vhost)(struct lws_vhost *vh, - const struct lws_context_creation_info *info); - /* role-specific per-vhost destructor during vhost destroy */ - int (*destroy_vhost)(struct lws_vhost *vh); - /* generic 1Hz callback for the role itself */ - int (*periodic_checks)(struct lws_context *context, int tsi, - time_t now); - /* chance for the role to force POLLIN without network activity */ - int (*service_flag_pending)(struct lws_context *context, int tsi); - /* an fd using this role has POLLIN signalled */ - int (*handle_POLLIN)(struct lws_context_per_thread *pt, struct lws *wsi, - struct lws_pollfd *pollfd); - /* an fd using the role wanted a POLLOUT callback and now has it */ - int (*handle_POLLOUT)(struct lws *wsi); - /* perform user pollout */ - int (*perform_user_POLLOUT)(struct lws *wsi); - /* do effective callback on writeable */ - int (*callback_on_writable)(struct lws *wsi); - /* connection-specific tx credit in bytes */ - lws_fileofs_t (*tx_credit)(struct lws *wsi); - /* role-specific write formatting */ - int (*write_role_protocol)(struct lws *wsi, unsigned char *buf, - size_t len, enum lws_write_protocol *wp); - - /* get encapsulation parent */ - struct lws * (*encapsulation_parent)(struct lws *wsi); - - /* role-specific destructor */ - int (*alpn_negotiated)(struct lws *wsi, const char *alpn); - - /* chance for the role to handle close in the protocol */ - int (*close_via_role_protocol)(struct lws *wsi, - enum lws_close_status reason); - /* role-specific close processing */ - int (*close_role)(struct lws_context_per_thread *pt, struct lws *wsi); - /* role-specific connection close processing */ - int (*close_kill_connection)(struct lws *wsi, - enum lws_close_status reason); - /* role-specific destructor */ - int (*destroy_role)(struct lws *wsi); - - /* role-specific socket-adopt */ - int (*adoption_bind)(struct lws *wsi, int type, const char *prot); - /* role-specific client-bind: - * ret 1 = bound, 0 = not bound, -1 = fail out - * i may be NULL, indicating client_bind is being called after - * a successful bind earlier, to finalize the binding. In that - * case ret 0 = OK, 1 = fail, wsi needs freeing, -1 = fail, wsi freed */ - int (*client_bind)(struct lws *wsi, - const struct lws_client_connect_info *i); - - /* - * the callback reasons for adoption for client, server - * (just client applies if no concept of client or server) - */ - uint16_t adoption_cb[2]; - /* - * the callback reasons for adoption for client, server - * (just client applies if no concept of client or server) - */ - uint16_t rx_cb[2]; - /* - * the callback reasons for WRITEABLE for client, server - * (just client applies if no concept of client or server) - */ - uint16_t writeable_cb[2]; - /* - * the callback reasons for CLOSE for client, server - * (just client applies if no concept of client or server) - */ - uint16_t close_cb[2]; - /* - * the callback reasons for protocol bind for client, server - * (just client applies if no concept of client or server) - */ - uint16_t protocol_bind_cb[2]; - /* - * the callback reasons for protocol unbind for client, server - * (just client applies if no concept of client or server) - */ - uint16_t protocol_unbind_cb[2]; - - unsigned int file_handle:1; /* role operates on files not sockets */ -}; - -/* core roles */ -extern struct lws_role_ops role_ops_raw_skt, role_ops_raw_file, role_ops_listen, - role_ops_pipe; - -/* bring in role private declarations */ - -#if defined(LWS_ROLE_H1) || defined(LWS_ROLE_H2) - #include "roles/http/private.h" -#else - #define lwsi_role_http(wsi) (0) -#endif - -#if defined(LWS_ROLE_H1) - #include "roles/h1/private.h" -#else - #define lwsi_role_h1(wsi) (0) -#endif - -#if defined(LWS_ROLE_H2) - #include "roles/h2/private.h" -#else - #define lwsi_role_h2(wsi) (0) -#endif - -#if defined(LWS_ROLE_WS) - #include "roles/ws/private.h" -#else - #define lwsi_role_ws(wsi) (0) -#endif - -#if defined(LWS_ROLE_CGI) - #include "roles/cgi/private.h" -#else - #define lwsi_role_cgi(wsi) (0) -#endif - -#if defined(LWS_ROLE_DBUS) - #include "roles/dbus/private.h" -#else - #define lwsi_role_dbus(wsi) (0) -#endif - -#if defined(LWS_ROLE_RAW_PROXY) - #include "roles/raw-proxy/private.h" -#else - #define lwsi_role_raw_proxy(wsi) (0) -#endif - -enum { - LWS_HP_RET_BAIL_OK, - LWS_HP_RET_BAIL_DIE, - LWS_HP_RET_USER_SERVICE, - - LWS_HPI_RET_WSI_ALREADY_DIED, /* we closed it */ - LWS_HPI_RET_HANDLED, /* no probs */ - LWS_HPI_RET_PLEASE_CLOSE_ME, /* close it for us */ - - LWS_UPG_RET_DONE, - LWS_UPG_RET_CONTINUE, - LWS_UPG_RET_BAIL -}; - -int -lws_role_call_adoption_bind(struct lws *wsi, int type, const char *prot); - -struct lws * -lws_client_connect_3(struct lws *wsi, struct lws *wsi_piggyback, ssize_t plen); diff -Nru libwebsockets-3.2.1/lib/roles/private-lib-roles.h libwebsockets-4.1.6/lib/roles/private-lib-roles.h --- libwebsockets-3.2.1/lib/roles/private-lib-roles.h 1970-01-01 00:00:00.000000000 +0000 +++ libwebsockets-4.1.6/lib/roles/private-lib-roles.h 2020-12-01 17:40:26.000000000 +0000 @@ -0,0 +1,354 @@ +/* + * libwebsockets - small server side websockets and web server implementation + * + * Copyright (C) 2010 - 2019 Andy Green + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to + * deal in the Software without restriction, including without limitation the + * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or + * sell copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS + * IN THE SOFTWARE. + */ + +typedef uint32_t lws_wsi_state_t; + +/* + * The wsi->role_ops pointer decides almost everything about what role the wsi + * will play, h2, raw, ws, etc. + * + * However there are a few additional flags needed that vary, such as if the + * role is a client or server side, if it has that concept. And the connection + * fulfilling the role, has a separate dynamic state. + * + * 31 16 15 0 + * [ role flags ] [ state ] + * + * The role flags part is generally invariant for the lifetime of the wsi, + * although it can change if the connection role itself does, eg, if the + * connection upgrades from H1 -> WS1 the role flags may be changed at that + * point. + * + * The state part reflects the dynamic connection state, and the states are + * reused between roles. + * + * None of the internal role or state representations are made available outside + * of lws internals. Even for lws internals, if you add stuff here, please keep + * the constants inside this header only by adding necessary helpers here and + * use the helpers in the actual code. This is to ease any future refactors. + * + * Notice LWSIFR_ENCAP means we have a parent wsi that actually carries our + * data as a stream inside a different protocol. + */ + +#define _RS 16 + +#define LWSIFR_CLIENT (0x1000 << _RS) /* client side */ +#define LWSIFR_SERVER (0x2000 << _RS) /* server side */ + +#define LWSIFR_P_ENCAP_H2 (0x0100 << _RS) /* we are encapsulated by h2 */ + +enum lwsi_role { + LWSI_ROLE_MASK = (0xffff << _RS), + LWSI_ROLE_ENCAP_MASK = (0x0f00 << _RS), +}; + +#define lwsi_role(wsi) (wsi->wsistate & LWSI_ROLE_MASK) +#if !defined (_DEBUG) +#define lwsi_set_role(wsi, role) wsi->wsistate = \ + (wsi->wsistate & (~LWSI_ROLE_MASK)) | role +#else +void lwsi_set_role(struct lws *wsi, lws_wsi_state_t role); +#endif + +#define lwsi_role_client(wsi) (!!(wsi->wsistate & LWSIFR_CLIENT)) +#define lwsi_role_server(wsi) (!!(wsi->wsistate & LWSIFR_SERVER)) +#define lwsi_role_h2_ENCAPSULATION(wsi) \ + ((wsi->wsistate & LWSI_ROLE_ENCAP_MASK) == LWSIFR_P_ENCAP_H2) + +/* Pollout wants a callback in this state */ +#define LWSIFS_POCB (0x100) +/* Before any protocol connection was established */ +#define LWSIFS_NOT_EST (0x200) + +enum lwsi_state { + + /* Phase 1: pre-transport */ + + LRS_UNCONNECTED = LWSIFS_NOT_EST | 0, + LRS_WAITING_DNS = LWSIFS_NOT_EST | 1, + LRS_WAITING_CONNECT = LWSIFS_NOT_EST | 2, + + /* Phase 2: establishing intermediaries on top of transport */ + + LRS_WAITING_PROXY_REPLY = LWSIFS_NOT_EST | 3, + LRS_WAITING_SSL = LWSIFS_NOT_EST | 4, + LRS_WAITING_SOCKS_GREETING_REPLY = LWSIFS_NOT_EST | 5, + LRS_WAITING_SOCKS_CONNECT_REPLY = LWSIFS_NOT_EST | 6, + LRS_WAITING_SOCKS_AUTH_REPLY = LWSIFS_NOT_EST | 7, + + /* Phase 3: establishing tls tunnel */ + + LRS_SSL_INIT = LWSIFS_NOT_EST | 8, + LRS_SSL_ACK_PENDING = LWSIFS_NOT_EST | 9, + LRS_PRE_WS_SERVING_ACCEPT = LWSIFS_NOT_EST | 10, + + /* Phase 4: connected */ + + LRS_WAITING_SERVER_REPLY = LWSIFS_NOT_EST | 11, + LRS_H2_AWAIT_PREFACE = LWSIFS_NOT_EST | 12, + LRS_H2_AWAIT_SETTINGS = LWSIFS_NOT_EST | + LWSIFS_POCB | 13, + LRS_MQTTC_IDLE = LWSIFS_POCB | 33, + LRS_MQTTC_AWAIT_CONNACK = 34, + + /* Phase 5: protocol logically established */ + + LRS_H2_CLIENT_SEND_SETTINGS = LWSIFS_POCB | 14, + LRS_H2_WAITING_TO_SEND_HEADERS = LWSIFS_POCB | 15, + LRS_DEFERRING_ACTION = LWSIFS_POCB | 16, + LRS_IDLING = 17, + LRS_H1C_ISSUE_HANDSHAKE = 18, + LRS_H1C_ISSUE_HANDSHAKE2 = 19, + LRS_ISSUE_HTTP_BODY = 20, + LRS_ISSUING_FILE = 21, + LRS_HEADERS = 22, + LRS_BODY = 23, + LRS_DISCARD_BODY = 24, + LRS_ESTABLISHED = LWSIFS_POCB | 25, + + /* we are established, but we have embarked on serving a single + * transaction. Other transaction input may be pending, but we will + * not service it while we are busy dealing with the current + * transaction. + * + * When we complete the current transaction, we would reset our state + * back to ESTABLISHED and start to process the next transaction. + */ + LRS_DOING_TRANSACTION = LWSIFS_POCB | 26, + + /* Phase 6: finishing */ + + LRS_WAITING_TO_SEND_CLOSE = LWSIFS_POCB | 27, + LRS_RETURNED_CLOSE = LWSIFS_POCB | 28, + LRS_AWAITING_CLOSE_ACK = LWSIFS_POCB | 29, + LRS_FLUSHING_BEFORE_CLOSE = LWSIFS_POCB | 30, + LRS_SHUTDOWN = 31, + + /* Phase 7: dead */ + + LRS_DEAD_SOCKET = 32, + + LRS_MASK = 0xffff +}; + +#define lwsi_state(wsi) ((enum lwsi_state)(wsi->wsistate & LRS_MASK)) +#define lwsi_state_PRE_CLOSE(wsi) \ + ((enum lwsi_state)(wsi->wsistate_pre_close & LRS_MASK)) +#define lwsi_state_est(wsi) (!(wsi->wsistate & LWSIFS_NOT_EST)) +#define lwsi_state_est_PRE_CLOSE(wsi) \ + (!(wsi->wsistate_pre_close & LWSIFS_NOT_EST)) +#define lwsi_state_can_handle_POLLOUT(wsi) (wsi->wsistate & LWSIFS_POCB) +#if !defined (_DEBUG) +#define lwsi_set_state(wsi, lrs) wsi->wsistate = \ + (wsi->wsistate & (~LRS_MASK)) | lrs +#else +void lwsi_set_state(struct lws *wsi, lws_wsi_state_t lrs); +#endif + +#define _LWS_ADOPT_FINISH (1 << 24) + +/* + * internal role-specific ops + */ +struct lws_context_per_thread; +struct lws_role_ops { + const char *name; + const char *alpn; + /* + * After http headers have parsed, this is the last chance for a role + * to upgrade the connection to something else using the headers. + * ws-over-h2 is upgraded from h2 like this. + */ + int (*check_upgrades)(struct lws *wsi); + /* role-specific context init during context creation */ + int (*pt_init_destroy)(struct lws_context *context, + const struct lws_context_creation_info *info, + struct lws_context_per_thread *pt, int destroy); + /* role-specific per-vhost init during vhost creation */ + int (*init_vhost)(struct lws_vhost *vh, + const struct lws_context_creation_info *info); + /* role-specific per-vhost destructor during vhost destroy */ + int (*destroy_vhost)(struct lws_vhost *vh); + /* chance for the role to force POLLIN without network activity */ + int (*service_flag_pending)(struct lws_context *context, int tsi); + /* an fd using this role has POLLIN signalled */ + int (*handle_POLLIN)(struct lws_context_per_thread *pt, struct lws *wsi, + struct lws_pollfd *pollfd); + /* an fd using the role wanted a POLLOUT callback and now has it */ + int (*handle_POLLOUT)(struct lws *wsi); + /* perform user pollout */ + int (*perform_user_POLLOUT)(struct lws *wsi); + /* do effective callback on writeable */ + int (*callback_on_writable)(struct lws *wsi); + /* connection-specific tx credit in bytes */ + int (*tx_credit)(struct lws *wsi, char peer_to_us, int add); + /* role-specific write formatting */ + int (*write_role_protocol)(struct lws *wsi, unsigned char *buf, + size_t len, enum lws_write_protocol *wp); + + /* get encapsulation parent */ + struct lws * (*encapsulation_parent)(struct lws *wsi); + + /* role-specific destructor */ + int (*alpn_negotiated)(struct lws *wsi, const char *alpn); + + /* chance for the role to handle close in the protocol */ + int (*close_via_role_protocol)(struct lws *wsi, + enum lws_close_status reason); + /* role-specific close processing */ + int (*close_role)(struct lws_context_per_thread *pt, struct lws *wsi); + /* role-specific connection close processing */ + int (*close_kill_connection)(struct lws *wsi, + enum lws_close_status reason); + /* role-specific destructor */ + int (*destroy_role)(struct lws *wsi); + + /* role-specific socket-adopt */ + int (*adoption_bind)(struct lws *wsi, int type, const char *prot); + /* role-specific client-bind: + * ret 1 = bound, 0 = not bound, -1 = fail out + * i may be NULL, indicating client_bind is being called after + * a successful bind earlier, to finalize the binding. In that + * case ret 0 = OK, 1 = fail, wsi needs freeing, -1 = fail, wsi freed */ + int (*client_bind)(struct lws *wsi, + const struct lws_client_connect_info *i); + /* isvalid = 0: request a role-specific keepalive (PING etc) + * = 1: reset any related validity timer */ + int (*issue_keepalive)(struct lws *wsi, int isvalid); + + /* + * the callback reasons for adoption for client, server + * (just client applies if no concept of client or server) + */ + uint16_t adoption_cb[2]; + /* + * the callback reasons for adoption for client, server + * (just client applies if no concept of client or server) + */ + uint16_t rx_cb[2]; + /* + * the callback reasons for WRITEABLE for client, server + * (just client applies if no concept of client or server) + */ + uint16_t writeable_cb[2]; + /* + * the callback reasons for CLOSE for client, server + * (just client applies if no concept of client or server) + */ + uint16_t close_cb[2]; + /* + * the callback reasons for protocol bind for client, server + * (just client applies if no concept of client or server) + */ + uint16_t protocol_bind_cb[2]; + /* + * the callback reasons for protocol unbind for client, server + * (just client applies if no concept of client or server) + */ + uint16_t protocol_unbind_cb[2]; + + unsigned int file_handle:1; /* role operates on files not sockets */ +}; + +/* core roles */ +extern const struct lws_role_ops role_ops_raw_skt, role_ops_raw_file, + role_ops_listen, role_ops_pipe; + +/* bring in role private declarations */ + +#if defined(LWS_ROLE_H1) || defined(LWS_ROLE_H2) + #include "private-lib-roles-http.h" +#else + #define lwsi_role_http(wsi) (0) +#endif + +#if defined(LWS_ROLE_H1) + #include "private-lib-roles-h1.h" +#else + #define lwsi_role_h1(wsi) (0) +#endif + +#if defined(LWS_ROLE_H2) + #include "private-lib-roles-h2.h" +#else + #define lwsi_role_h2(wsi) (0) +#endif + +#if defined(LWS_ROLE_WS) + #include "private-lib-roles-ws.h" +#else + #define lwsi_role_ws(wsi) (0) +#endif + +#if defined(LWS_ROLE_CGI) + #include "private-lib-roles-cgi.h" +#else + #define lwsi_role_cgi(wsi) (0) +#endif + +#if defined(LWS_ROLE_DBUS) + #include "private-lib-roles-dbus.h" +#else + #define lwsi_role_dbus(wsi) (0) +#endif + +#if defined(LWS_ROLE_RAW_PROXY) + #include "private-lib-roles-raw-proxy.h" +#else + #define lwsi_role_raw_proxy(wsi) (0) +#endif + +#if defined(LWS_ROLE_MQTT) + #include "mqtt/private-lib-roles-mqtt.h" +#else + #define lwsi_role_mqtt(wsi) (0) +#endif + +enum { + LWS_HP_RET_BAIL_OK, + LWS_HP_RET_BAIL_DIE, + LWS_HP_RET_USER_SERVICE, + LWS_HP_RET_DROP_POLLOUT, + + LWS_HPI_RET_WSI_ALREADY_DIED, /* we closed it */ + LWS_HPI_RET_HANDLED, /* no probs */ + LWS_HPI_RET_PLEASE_CLOSE_ME, /* close it for us */ + + LWS_UPG_RET_DONE, + LWS_UPG_RET_CONTINUE, + LWS_UPG_RET_BAIL +}; + +#define LWS_CONNECT_COMPLETION_GOOD (-99) + +int +lws_role_call_adoption_bind(struct lws *wsi, int type, const char *prot); + +struct lws * +lws_client_connect_4_established(struct lws *wsi, struct lws *wsi_piggyback, ssize_t plen); + +struct lws * +lws_client_connect_3_connect(struct lws *wsi, const char *ads, + const struct addrinfo *result, int n, void *opaque); diff -Nru libwebsockets-3.2.1/lib/roles/raw-file/CMakeLists.txt libwebsockets-4.1.6/lib/roles/raw-file/CMakeLists.txt --- libwebsockets-3.2.1/lib/roles/raw-file/CMakeLists.txt 1970-01-01 00:00:00.000000000 +0000 +++ libwebsockets-4.1.6/lib/roles/raw-file/CMakeLists.txt 2020-12-01 17:40:26.000000000 +0000 @@ -0,0 +1,40 @@ +# +# libwebsockets - small server side websockets and web server implementation +# +# Copyright (C) 2010 - 2020 Andy Green +# +# Permission is hereby granted, free of charge, to any person obtaining a copy +# of this software and associated documentation files (the "Software"), to +# deal in the Software without restriction, including without limitation the +# rights to use, copy, modify, merge, publish, distribute, sublicense, and/or +# sell copies of the Software, and to permit persons to whom the Software is +# furnished to do so, subject to the following conditions: +# +# The above copyright notice and this permission notice shall be included in +# all copies or substantial portions of the Software. +# +# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING +# FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS +# IN THE SOFTWARE. +# +# The strategy is to only export to PARENT_SCOPE +# +# - changes to LIB_LIST +# - changes to SOURCES +# - includes via include_directories +# +# and keep everything else private + +include_directories(.) + +list(APPEND SOURCES roles/raw-file/ops-raw-file.c) + +# +# Keep explicit parent scope exports at end +# + +exports_to_parent_scope() \ No newline at end of file diff -Nru libwebsockets-3.2.1/lib/roles/raw-file/ops-raw-file.c libwebsockets-4.1.6/lib/roles/raw-file/ops-raw-file.c --- libwebsockets-3.2.1/lib/roles/raw-file/ops-raw-file.c 2019-12-18 14:45:31.000000000 +0000 +++ libwebsockets-4.1.6/lib/roles/raw-file/ops-raw-file.c 2020-12-01 17:40:26.000000000 +0000 @@ -1,25 +1,28 @@ /* * libwebsockets - small server side websockets and web server implementation * - * Copyright (C) 2010-2018 Andy Green + * Copyright (C) 2010 - 2019 Andy Green * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation: - * version 2.1 of the License. + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to + * deal in the Software without restriction, including without limitation the + * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or + * sell copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: * - * This library is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. * - * You should have received a copy of the GNU Lesser General Public - * License along with this library; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, - * MA 02110-1301 USA + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS + * IN THE SOFTWARE. */ -#include +#include static int rops_handle_POLLIN_raw_file(struct lws_context_per_thread *pt, struct lws *wsi, @@ -38,7 +41,7 @@ } if (pollfd->revents & LWS_POLLIN) { - if (user_callback_handle_rxflow(wsi->protocol->callback, + if (user_callback_handle_rxflow(wsi->a.protocol->callback, wsi, LWS_CALLBACK_RAW_RX_FILE, wsi->user_space, NULL, 0)) { lwsl_debug("raw rx callback closed it\n"); @@ -47,12 +50,12 @@ } if (pollfd->revents & LWS_POLLHUP) - return LWS_HPI_RET_PLEASE_CLOSE_ME; + if (!(pollfd->revents & LWS_POLLIN)) + return LWS_HPI_RET_PLEASE_CLOSE_ME; return LWS_HPI_RET_HANDLED; } -//#if !defined(LWS_NO_SERVER) static int rops_adoption_bind_raw_file(struct lws *wsi, int type, const char *vh_prot_name) { @@ -64,26 +67,24 @@ lws_role_transition(wsi, 0, LRS_ESTABLISHED, &role_ops_raw_file); if (!vh_prot_name) { - if (wsi->vhost->default_protocol_index >= - wsi->vhost->count_protocols) + if (wsi->a.vhost->default_protocol_index >= + wsi->a.vhost->count_protocols) return 0; - wsi->protocol = &wsi->vhost->protocols[ - wsi->vhost->default_protocol_index]; + wsi->a.protocol = &wsi->a.vhost->protocols[ + wsi->a.vhost->default_protocol_index]; } return 1; /* bound */ } -//#endif -struct lws_role_ops role_ops_raw_file = { +const struct lws_role_ops role_ops_raw_file = { /* role name */ "raw-file", /* alpn id */ NULL, /* check_upgrades */ NULL, - /* init_context */ NULL, + /* pt_init_destroy */ NULL, /* init_vhost */ NULL, /* destroy_vhost */ NULL, - /* periodic_checks */ NULL, /* service_flag_pending */ NULL, /* handle_POLLIN */ rops_handle_POLLIN_raw_file, /* handle_POLLOUT */ NULL, @@ -97,12 +98,9 @@ /* close_role */ NULL, /* close_kill_connection */ NULL, /* destroy_role */ NULL, -//#if !defined(LWS_NO_SERVER) /* adoption_bind */ rops_adoption_bind_raw_file, -//#else -// NULL, -//#endif /* client_bind */ NULL, + /* issue_keepalive */ NULL, /* adoption_cb clnt, srv */ { LWS_CALLBACK_RAW_ADOPT_FILE, LWS_CALLBACK_RAW_ADOPT_FILE }, /* rx_cb clnt, srv */ { LWS_CALLBACK_RAW_RX_FILE, diff -Nru libwebsockets-3.2.1/lib/roles/raw-proxy/CMakeLists.txt libwebsockets-4.1.6/lib/roles/raw-proxy/CMakeLists.txt --- libwebsockets-3.2.1/lib/roles/raw-proxy/CMakeLists.txt 1970-01-01 00:00:00.000000000 +0000 +++ libwebsockets-4.1.6/lib/roles/raw-proxy/CMakeLists.txt 2020-12-01 17:40:26.000000000 +0000 @@ -0,0 +1,42 @@ +# +# libwebsockets - small server side websockets and web server implementation +# +# Copyright (C) 2010 - 2020 Andy Green +# +# Permission is hereby granted, free of charge, to any person obtaining a copy +# of this software and associated documentation files (the "Software"), to +# deal in the Software without restriction, including without limitation the +# rights to use, copy, modify, merge, publish, distribute, sublicense, and/or +# sell copies of the Software, and to permit persons to whom the Software is +# furnished to do so, subject to the following conditions: +# +# The above copyright notice and this permission notice shall be included in +# all copies or substantial portions of the Software. +# +# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING +# FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS +# IN THE SOFTWARE. +# +# The strategy is to only export to PARENT_SCOPE +# +# - changes to LIB_LIST +# - changes to SOURCES +# - includes via include_directories +# +# and keep everything else private + +include_directories(.) + +list(APPEND SOURCES + roles/raw-proxy/ops-raw-proxy.c) + +# +# Keep explicit parent scope exports at end +# + +exports_to_parent_scope() + diff -Nru libwebsockets-3.2.1/lib/roles/raw-proxy/ops-raw-proxy.c libwebsockets-4.1.6/lib/roles/raw-proxy/ops-raw-proxy.c --- libwebsockets-3.2.1/lib/roles/raw-proxy/ops-raw-proxy.c 2019-12-18 14:45:31.000000000 +0000 +++ libwebsockets-4.1.6/lib/roles/raw-proxy/ops-raw-proxy.c 2020-12-01 17:40:26.000000000 +0000 @@ -1,25 +1,28 @@ /* * libwebsockets - small server side websockets and web server implementation * - * Copyright (C) 2010-2018 Andy Green + * Copyright (C) 2010 - 2019 Andy Green * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation: - * version 2.1 of the License. + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to + * deal in the Software without restriction, including without limitation the + * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or + * sell copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: * - * This library is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. * - * You should have received a copy of the GNU Lesser General Public - * License along with this library; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, - * MA 02110-1301 USA + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS + * IN THE SOFTWARE. */ -#include +#include static int rops_handle_POLLIN_raw_proxy(struct lws_context_per_thread *pt, struct lws *wsi, @@ -51,7 +54,12 @@ !(wsi->favoured_pollin && (pollfd->revents & pollfd->events & LWS_POLLOUT))) { - buffered = lws_buflist_aware_read(pt, wsi, &ebuf); + ebuf.token = NULL; + ebuf.len = 0; + buffered = lws_buflist_aware_read(pt, wsi, &ebuf, 1, __func__); + if (buffered < 0) + goto fail; + switch (ebuf.len) { case 0: lwsl_info("%s: read 0 len\n", __func__); @@ -72,7 +80,7 @@ case LWS_SSL_CAPABLE_MORE_SERVICE: goto try_pollout; } - n = user_callback_handle_rxflow(wsi->protocol->callback, + n = user_callback_handle_rxflow(wsi->a.protocol->callback, wsi, lwsi_role_client(wsi) ? LWS_CALLBACK_RAW_PROXY_CLI_RX : LWS_CALLBACK_RAW_PROXY_SRV_RX, @@ -83,7 +91,8 @@ goto fail; } - if (lws_buflist_aware_consume(wsi, &ebuf, ebuf.len, buffered)) + if (lws_buflist_aware_finished_consuming(wsi, &ebuf, ebuf.len, + buffered, __func__)) return LWS_HPI_RET_PLEASE_CLOSE_ME; } else if (wsi->favoured_pollin && @@ -101,8 +110,8 @@ return LWS_HPI_RET_PLEASE_CLOSE_ME; } -#if !defined(LWS_NO_CLIENT) - if (lws_client_socket_service(wsi, pollfd, NULL)) +#if defined(LWS_WITH_CLIENT) + if (lws_client_socket_service(wsi, pollfd)) return LWS_HPI_RET_WSI_ALREADY_DIED; #endif @@ -123,22 +132,24 @@ (!(type & LWS_ADOPT_FLAG_RAW_PROXY)) || (type & _LWS_ADOPT_FINISH)) return 0; /* no match */ +#if defined(LWS_WITH_UDP) if (type & LWS_ADOPT_FLAG_UDP) /* * these can be >128 bytes, so just alloc for UDP */ wsi->udp = lws_malloc(sizeof(*wsi->udp), "udp struct"); +#endif lws_role_transition(wsi, LWSIFR_SERVER, (type & LWS_ADOPT_ALLOW_SSL) ? LRS_SSL_INIT : LRS_ESTABLISHED, &role_ops_raw_proxy); if (vh_prot_name) - lws_bind_protocol(wsi, wsi->protocol, __func__); + lws_bind_protocol(wsi, wsi->a.protocol, __func__); else /* this is the only time he will transition */ lws_bind_protocol(wsi, - &wsi->vhost->protocols[wsi->vhost->raw_protocol_index], + &wsi->a.vhost->protocols[wsi->a.vhost->raw_protocol_index], __func__); return 1; /* bound */ @@ -152,7 +163,7 @@ /* finalize */ - if (!wsi->user_space && wsi->stash->method) + if (!wsi->user_space && wsi->stash->cis[CIS_METHOD]) if (lws_ensure_user_space(wsi)) return 1; @@ -161,8 +172,9 @@ /* we are a fallback if nothing else matched */ -// lws_role_transition(wsi, LWSIFR_CLIENT, LRS_UNCONNECTED, -// &role_ops_raw_proxy); + if (i->local_protocol_name && !strcmp(i->local_protocol_name, "raw-proxy")) + lws_role_transition(wsi, LWSIFR_CLIENT, LRS_UNCONNECTED, + &role_ops_raw_proxy); return 0; } @@ -179,14 +191,13 @@ return LWS_HP_RET_BAIL_OK; } -struct lws_role_ops role_ops_raw_proxy = { +const struct lws_role_ops role_ops_raw_proxy = { /* role name */ "raw-proxy", /* alpn id */ NULL, /* check_upgrades */ NULL, - /* init_context */ NULL, + /* pt_init_destroy */ NULL, /* init_vhost */ NULL, /* destroy_vhost */ NULL, - /* periodic_checks */ NULL, /* service_flag_pending */ NULL, /* handle_POLLIN */ rops_handle_POLLIN_raw_proxy, /* handle_POLLOUT */ rops_handle_POLLOUT_raw_proxy, @@ -202,6 +213,7 @@ /* destroy_role */ NULL, /* adoption_bind */ rops_adoption_bind_raw_proxy, /* client_bind */ rops_client_bind_raw_proxy, + /* issue_keepalive */ NULL, /* adoption_cb clnt, srv */ { LWS_CALLBACK_RAW_PROXY_CLI_ADOPT, LWS_CALLBACK_RAW_PROXY_SRV_ADOPT }, /* rx_cb clnt, srv */ { LWS_CALLBACK_RAW_PROXY_CLI_RX, diff -Nru libwebsockets-3.2.1/lib/roles/raw-proxy/private.h libwebsockets-4.1.6/lib/roles/raw-proxy/private.h --- libwebsockets-3.2.1/lib/roles/raw-proxy/private.h 2019-12-18 14:45:31.000000000 +0000 +++ libwebsockets-4.1.6/lib/roles/raw-proxy/private.h 1970-01-01 00:00:00.000000000 +0000 @@ -1,41 +0,0 @@ -/* - * libwebsockets - small server side websockets and web server implementation - * - * Copyright (C) 2010 - 2018 Andy Green - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation: - * version 2.1 of the License. - * - * This library is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with this library; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, - * MA 02110-1301 USA - * - * This is included from core/private.h if LWS_ROLE_RAW_PROXY - */ - -extern struct lws_role_ops role_ops_raw_proxy; - -#define lwsi_role_raw_proxy(wsi) (wsi->role_ops == &role_ops_raw_proxy) - -#if 0 -struct lws_vhost_role_ws { - const struct lws_extension *extensions; -}; - -struct lws_pt_role_ws { - struct lws *rx_draining_ext_list; - struct lws *tx_draining_ext_list; -}; - -struct _lws_raw_proxy_related { - struct lws *wsi_onward; -}; -#endif diff -Nru libwebsockets-3.2.1/lib/roles/raw-proxy/private-lib-roles-raw-proxy.h libwebsockets-4.1.6/lib/roles/raw-proxy/private-lib-roles-raw-proxy.h --- libwebsockets-3.2.1/lib/roles/raw-proxy/private-lib-roles-raw-proxy.h 1970-01-01 00:00:00.000000000 +0000 +++ libwebsockets-4.1.6/lib/roles/raw-proxy/private-lib-roles-raw-proxy.h 2020-12-01 17:40:26.000000000 +0000 @@ -0,0 +1,44 @@ + /* + * libwebsockets - small server side websockets and web server implementation + * + * Copyright (C) 2010 - 2019 Andy Green + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to + * deal in the Software without restriction, including without limitation the + * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or + * sell copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS + * IN THE SOFTWARE. + * + * This is included from private-lib-core.h if LWS_ROLE_RAW_PROXY + */ + +extern const struct lws_role_ops role_ops_raw_proxy; + +#define lwsi_role_raw_proxy(wsi) (wsi->role_ops == &role_ops_raw_proxy) + +#if 0 +struct lws_vhost_role_ws { + const struct lws_extension *extensions; +}; + +struct lws_pt_role_ws { + struct lws *rx_draining_ext_list; + struct lws *tx_draining_ext_list; +}; + +struct _lws_raw_proxy_related { + struct lws *wsi_onward; +}; +#endif diff -Nru libwebsockets-3.2.1/lib/roles/raw-skt/CMakeLists.txt libwebsockets-4.1.6/lib/roles/raw-skt/CMakeLists.txt --- libwebsockets-3.2.1/lib/roles/raw-skt/CMakeLists.txt 1970-01-01 00:00:00.000000000 +0000 +++ libwebsockets-4.1.6/lib/roles/raw-skt/CMakeLists.txt 2020-12-01 17:40:26.000000000 +0000 @@ -0,0 +1,46 @@ +# +# libwebsockets - small server side websockets and web server implementation +# +# Copyright (C) 2010 - 2020 Andy Green +# +# Permission is hereby granted, free of charge, to any person obtaining a copy +# of this software and associated documentation files (the "Software"), to +# deal in the Software without restriction, including without limitation the +# rights to use, copy, modify, merge, publish, distribute, sublicense, and/or +# sell copies of the Software, and to permit persons to whom the Software is +# furnished to do so, subject to the following conditions: +# +# The above copyright notice and this permission notice shall be included in +# all copies or substantial portions of the Software. +# +# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING +# FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS +# IN THE SOFTWARE. +# +# The strategy is to only export to PARENT_SCOPE +# +# - changes to LIB_LIST +# - changes to SOURCES +# - includes via include_directories +# +# and keep everything else private + +include_directories(.) + +list(APPEND SOURCES + roles/raw-skt/ops-raw-skt.c) + +if (LWS_WITH_ABSTRACT) + list(APPEND SOURCES + abstract/transports/raw-skt.c) +endif() + +# +# Keep explicit parent scope exports at end +# + +exports_to_parent_scope() diff -Nru libwebsockets-3.2.1/lib/roles/raw-skt/ops-raw-skt.c libwebsockets-4.1.6/lib/roles/raw-skt/ops-raw-skt.c --- libwebsockets-3.2.1/lib/roles/raw-skt/ops-raw-skt.c 2019-12-18 14:45:31.000000000 +0000 +++ libwebsockets-4.1.6/lib/roles/raw-skt/ops-raw-skt.c 2020-12-01 17:40:26.000000000 +0000 @@ -1,32 +1,38 @@ /* * libwebsockets - small server side websockets and web server implementation * - * Copyright (C) 2010-2018 Andy Green + * Copyright (C) 2010 - 2020 Andy Green * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation: - * version 2.1 of the License. + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to + * deal in the Software without restriction, including without limitation the + * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or + * sell copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: * - * This library is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. * - * You should have received a copy of the GNU Lesser General Public - * License along with this library; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, - * MA 02110-1301 USA + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS + * IN THE SOFTWARE. */ -#include +#include static int rops_handle_POLLIN_raw_skt(struct lws_context_per_thread *pt, struct lws *wsi, struct lws_pollfd *pollfd) { +#if defined(LWS_WITH_SOCKS5) + const char *cce = NULL; +#endif struct lws_tokens ebuf; - int n, buffered; + int n = 0, buffered = 0; /* pending truncated sends have uber priority */ @@ -46,15 +52,16 @@ } -#if !defined(LWS_NO_SERVER) +#if defined(LWS_WITH_SERVER) if (!lwsi_role_client(wsi) && lwsi_state(wsi) != LRS_ESTABLISHED) { lwsl_debug("%s: %p: wsistate 0x%x\n", __func__, wsi, - wsi->wsistate); + (int)wsi->wsistate); if (lwsi_state(wsi) != LRS_SSL_INIT) if (lws_server_socket_service_ssl(wsi, - LWS_SOCK_INVALID)) + LWS_SOCK_INVALID, + !!(pollfd->revents & pollfd->events & LWS_POLLIN))) return LWS_HPI_RET_PLEASE_CLOSE_ME; return LWS_HPI_RET_HANDLED; @@ -62,58 +69,128 @@ #endif if ((pollfd->revents & pollfd->events & LWS_POLLIN) && - /* any tunnel has to have been established... */ - lwsi_state(wsi) != LRS_SSL_ACK_PENDING && !(wsi->favoured_pollin && (pollfd->revents & pollfd->events & LWS_POLLOUT))) { - buffered = lws_buflist_aware_read(pt, wsi, &ebuf); - switch (ebuf.len) { - case 0: - lwsl_info("%s: read 0 len\n", __func__); - wsi->seen_zero_length_recv = 1; - if (lws_change_pollfd(wsi, LWS_POLLIN, 0)) + lwsl_debug("%s: POLLIN: wsi %p, state 0x%x\n", __func__, + wsi, lwsi_state(wsi)); + + switch (lwsi_state(wsi)) { + + /* any tunnel has to have been established... */ + case LRS_SSL_ACK_PENDING: + goto nope; + /* we are actually connected */ + case LRS_WAITING_CONNECT: + goto nope; + +#if defined(LWS_WITH_SOCKS5) + + /* SOCKS Greeting Reply */ + case LRS_WAITING_SOCKS_GREETING_REPLY: + case LRS_WAITING_SOCKS_AUTH_REPLY: + case LRS_WAITING_SOCKS_CONNECT_REPLY: + + switch (lws_socks5c_handle_state(wsi, pollfd, &cce)) { + case LW5CHS_RET_RET0: + goto nope; + case LW5CHS_RET_BAIL3: + lws_inform_client_conn_fail(wsi, (void *)cce, strlen(cce)); + goto fail; + case LW5CHS_RET_STARTHS: + lwsi_set_state(wsi, LRS_ESTABLISHED); + lws_client_connect_4_established(wsi, NULL, 0); + + /* + * Now we got the socks5 connection, we need to + * go down the tls path on it now if that's what + * we want + */ + goto post_rx; + + default: + break; + } + goto post_rx; +#endif + default: + ebuf.token = NULL; + ebuf.len = 0; + + buffered = lws_buflist_aware_read(pt, wsi, &ebuf, 1, __func__); + switch (ebuf.len) { + case 0: + lwsl_info("%s: read 0 len\n", __func__); + wsi->seen_zero_length_recv = 1; + if (lws_change_pollfd(wsi, LWS_POLLIN, 0)) + goto fail; + + /* + * we need to go to fail here, since it's the only + * chance we get to understand that the socket has + * closed + */ + // goto try_pollout; goto fail; - /* - * we need to go to fail here, since it's the only - * chance we get to understand that the socket has - * closed - */ - // goto try_pollout; - goto fail; + case LWS_SSL_CAPABLE_ERROR: + goto fail; + case LWS_SSL_CAPABLE_MORE_SERVICE: + goto try_pollout; + } + +#if defined(LWS_WITH_UDP) + if (wsi->a.context->udp_loss_sim_rx_pc) { + uint16_t u16; + /* + * We should randomly drop some of these + */ + + if (lws_get_random(wsi->a.context, &u16, 2) == 2 && + ((u16 * 100) / 0xffff) <= + wsi->a.context->udp_loss_sim_rx_pc) { + lwsl_warn("%s: dropping udp rx\n", __func__); + /* pretend it was handled */ + n = ebuf.len; + goto post_rx; + } + } +#endif - case LWS_SSL_CAPABLE_ERROR: - goto fail; - case LWS_SSL_CAPABLE_MORE_SERVICE: - goto try_pollout; - } + n = user_callback_handle_rxflow(wsi->a.protocol->callback, + wsi, LWS_CALLBACK_RAW_RX, + wsi->user_space, ebuf.token, + ebuf.len); +#if defined(LWS_WITH_UDP) || defined(LWS_WITH_SOCKS5) +post_rx: +#endif + if (n < 0) { + lwsl_info("LWS_CALLBACK_RAW_RX_fail\n"); + goto fail; + } - n = user_callback_handle_rxflow(wsi->protocol->callback, - wsi, LWS_CALLBACK_RAW_RX, - wsi->user_space, ebuf.token, - ebuf.len); - if (n < 0) { - lwsl_info("LWS_CALLBACK_RAW_RX_fail\n"); - goto fail; - } + if (lws_buflist_aware_finished_consuming(wsi, &ebuf, ebuf.len, + buffered, __func__)) + return LWS_HPI_RET_PLEASE_CLOSE_ME; - if (lws_buflist_aware_consume(wsi, &ebuf, ebuf.len, buffered)) - return LWS_HPI_RET_PLEASE_CLOSE_ME; - } else - if (wsi->favoured_pollin && - (pollfd->revents & pollfd->events & LWS_POLLOUT)) - /* we balanced the last favouring of pollin */ - wsi->favoured_pollin = 0; + goto try_pollout; + } + } +nope: + if (wsi->favoured_pollin && + (pollfd->revents & pollfd->events & LWS_POLLOUT)) + /* we balanced the last favouring of pollin */ + wsi->favoured_pollin = 0; try_pollout: if (!(pollfd->revents & LWS_POLLOUT)) return LWS_HPI_RET_HANDLED; -#if !defined(LWS_WITHOUT_CLIENT) - if (lwsi_state(wsi) == LRS_WAITING_CONNECT) - lws_client_connect_3(wsi, NULL, 0); +#if defined(LWS_WITH_CLIENT) + if (lwsi_state(wsi) == LRS_WAITING_CONNECT && + !lws_client_connect_3_connect(wsi, NULL, NULL, 0, NULL)) + return LWS_HPI_RET_WSI_ALREADY_DIED; #endif /* one shot */ @@ -137,7 +214,7 @@ wsi->active_writable_req_us = 0; } #endif - n = user_callback_handle_rxflow(wsi->protocol->callback, + n = user_callback_handle_rxflow(wsi->a.protocol->callback, wsi, LWS_CALLBACK_RAW_WRITEABLE, wsi->user_space, NULL, 0); if (n < 0) { @@ -153,7 +230,7 @@ return LWS_HPI_RET_WSI_ALREADY_DIED; } -#if !defined(LWS_NO_SERVER) +#if defined(LWS_WITH_SERVER) static int rops_adoption_bind_raw_skt(struct lws *wsi, int type, const char *vh_prot_name) { @@ -162,7 +239,7 @@ (type & _LWS_ADOPT_FINISH)) return 0; /* no match */ -#if !defined(LWS_WITH_ESP32) && !defined(LWS_PLAT_OPTEE) +#if defined(LWS_WITH_UDP) if (type & LWS_ADOPT_FLAG_UDP) /* * these can be >128 bytes, so just alloc for UDP @@ -174,18 +251,18 @@ LRS_ESTABLISHED, &role_ops_raw_skt); if (vh_prot_name) - lws_bind_protocol(wsi, wsi->protocol, __func__); + lws_bind_protocol(wsi, wsi->a.protocol, __func__); else /* this is the only time he will transition */ lws_bind_protocol(wsi, - &wsi->vhost->protocols[wsi->vhost->raw_protocol_index], + &wsi->a.vhost->protocols[wsi->a.vhost->raw_protocol_index], __func__); return 1; /* bound */ } #endif -#if !defined(LWS_NO_CLIENT) +#if defined(LWS_WITH_CLIENT) static int rops_client_bind_raw_skt(struct lws *wsi, const struct lws_client_connect_info *i) @@ -194,7 +271,7 @@ /* finalize */ - if (!wsi->user_space && wsi->stash->method) + if (!wsi->user_space && wsi->stash->cis[CIS_METHOD]) if (lws_ensure_user_space(wsi)) return 1; @@ -203,21 +280,22 @@ /* we are a fallback if nothing else matched */ - lws_role_transition(wsi, LWSIFR_CLIENT, LRS_UNCONNECTED, + if (!i->local_protocol_name || + strcmp(i->local_protocol_name, "raw-proxy")) + lws_role_transition(wsi, LWSIFR_CLIENT, LRS_UNCONNECTED, &role_ops_raw_skt); return 1; /* matched */ } #endif -struct lws_role_ops role_ops_raw_skt = { +const struct lws_role_ops role_ops_raw_skt = { /* role name */ "raw-skt", /* alpn id */ NULL, /* check_upgrades */ NULL, - /* init_context */ NULL, + /* pt_init_destroy */ NULL, /* init_vhost */ NULL, /* destroy_vhost */ NULL, - /* periodic_checks */ NULL, /* service_flag_pending */ NULL, /* handle_POLLIN */ rops_handle_POLLIN_raw_skt, /* handle_POLLOUT */ NULL, @@ -231,16 +309,17 @@ /* close_role */ NULL, /* close_kill_connection */ NULL, /* destroy_role */ NULL, -#if !defined(LWS_NO_SERVER) +#if defined(LWS_WITH_SERVER) /* adoption_bind */ rops_adoption_bind_raw_skt, #else NULL, #endif -#if !defined(LWS_NO_CLIENT) +#if defined(LWS_WITH_CLIENT) /* client_bind */ rops_client_bind_raw_skt, #else NULL, #endif + /* issue_keepalive */ NULL, /* adoption_cb clnt, srv */ { LWS_CALLBACK_RAW_CONNECTED, LWS_CALLBACK_RAW_ADOPT }, /* rx_cb clnt, srv */ { LWS_CALLBACK_RAW_RX, diff -Nru libwebsockets-3.2.1/lib/roles/README.md libwebsockets-4.1.6/lib/roles/README.md --- libwebsockets-3.2.1/lib/roles/README.md 2019-12-18 14:45:31.000000000 +0000 +++ libwebsockets-4.1.6/lib/roles/README.md 2020-12-01 17:40:26.000000000 +0000 @@ -54,7 +54,7 @@ ### Role ops struct -The role is defined by `struct lws_role_ops` in `lib/roles/private.h`, +The role is defined by `struct lws_role_ops` in `lib/roles/private-lib-roles.h`, each role instantiates one of these and fills in the appropriate ops callbacks to perform its job. By convention that lives in `./lib/roles/**role name**/ops-**role_name**.c`. @@ -64,15 +64,15 @@ Truly private declarations for the role can go in the role directory as you like. However when the declarations must be accessible to other things in lws build, eg, the role adds members to `struct lws` when enabled, they should be in the role -directory in a file `private.h`. +directory in a file `private-lib-roles-myrole.h`. -Search for "bring in role private declarations" in `./lib/roles/private.h +Search for "bring in role private declarations" in `./lib/roles/private-lib-roles.h and add your private role file there following the style used for the other roles, eg, ``` #if defined(LWS_ROLE_WS) - #include "roles/ws/private.h" + #include "roles/ws/private-lib-roles-ws.h" #else #define lwsi_role_ws(wsi) (0) #endif diff -Nru libwebsockets-3.2.1/lib/roles/ws/client-parser-ws.c libwebsockets-4.1.6/lib/roles/ws/client-parser-ws.c --- libwebsockets-3.2.1/lib/roles/ws/client-parser-ws.c 2019-12-18 14:45:31.000000000 +0000 +++ libwebsockets-4.1.6/lib/roles/ws/client-parser-ws.c 2020-12-01 17:40:26.000000000 +0000 @@ -1,25 +1,28 @@ /* * libwebsockets - small server side websockets and web server implementation * - * Copyright (C) 2010-2018 Andy Green + * Copyright (C) 2010 - 2019 Andy Green * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation: - * version 2.1 of the License. + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to + * deal in the Software without restriction, including without limitation the + * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or + * sell copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: * - * This library is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. * - * You should have received a copy of the GNU Lesser General Public - * License along with this library; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, - * MA 02110-1301 USA + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS + * IN THE SOFTWARE. */ -#include "core/private.h" +#include "private-lib-core.h" /* * parsers.c: lws_ws_rx_sm() needs to be roughly kept in @@ -28,7 +31,6 @@ int lws_ws_client_rx_sm(struct lws *wsi, unsigned char c) { - struct lws_context_per_thread *pt = &wsi->context->pt[(int)wsi->tsi]; int callback_action = LWS_CALLBACK_CLIENT_RECEIVE; struct lws_ext_pm_deflate_rx_ebufs pmdrx; unsigned short close_code; @@ -80,7 +82,7 @@ #endif wsi->ws->continuation_possible = 1; wsi->ws->check_utf8 = lws_check_opt( - wsi->context->options, + wsi->a.context->options, LWS_SERVER_OPTION_VALIDATE_UTF8); wsi->ws->utf8 = 0; wsi->ws->first_fragment = 1; @@ -360,12 +362,12 @@ * if there's no protocol max frame size given, we are * supposed to default to context->pt_serv_buf_size */ - if (!wsi->protocol->rx_buffer_size && - wsi->ws->rx_ubuf_head != wsi->context->pt_serv_buf_size) + if (!wsi->a.protocol->rx_buffer_size && + wsi->ws->rx_ubuf_head != wsi->a.context->pt_serv_buf_size) break; - if (wsi->protocol->rx_buffer_size && - wsi->ws->rx_ubuf_head != wsi->protocol->rx_buffer_size) + if (wsi->a.protocol->rx_buffer_size && + wsi->ws->rx_ubuf_head != wsi->a.protocol->rx_buffer_size) break; /* spill because we filled our rx buffer */ @@ -384,7 +386,7 @@ switch (wsi->ws->opcode) { case LWSWSOPC_CLOSE: pp = &wsi->ws->rx_ubuf[LWS_PRE]; - if (lws_check_opt(wsi->context->options, + if (lws_check_opt(wsi->a.context->options, LWS_SERVER_OPTION_VALIDATE_UTF8) && wsi->ws->rx_ubuf_head > 2 && lws_check_utf8(&wsi->ws->utf8, pp + 2, @@ -402,7 +404,7 @@ } lwsl_parser("client sees server close len = %d\n", - wsi->ws->rx_ubuf_head); + (int)wsi->ws->rx_ubuf_head); if (wsi->ws->rx_ubuf_head >= 2) { close_code = (pp[0] << 8) | pp[1]; if (close_code < 1000 || @@ -420,7 +422,7 @@ } } if (user_callback_handle_rxflow( - wsi->protocol->callback, wsi, + wsi->a.protocol->callback, wsi, LWS_CALLBACK_WS_PEER_INITIATED_CLOSE, wsi->user_space, pp, wsi->ws->rx_ubuf_head)) @@ -444,7 +446,7 @@ case LWSWSOPC_PING: lwsl_info("received %d byte ping, sending pong\n", - wsi->ws->rx_ubuf_head); + (int)wsi->ws->rx_ubuf_head); /* he set a close reason on this guy, ignore PING */ if (wsi->ws->close_in_ping_buffer_len) @@ -485,20 +487,7 @@ lwsl_hexdump(&wsi->ws->rx_ubuf[LWS_PRE], wsi->ws->rx_ubuf_head); - if (wsi->ws->await_pong) { - lws_set_timeout(wsi, NO_PENDING_TIMEOUT, 0); - wsi->ws->await_pong = 0; - - /* - * prepare to send the ping again if nothing - * sent to countermand it - */ - - __lws_sul_insert(&pt->pt_sul_owner, - &wsi->sul_ping, - (lws_usec_t)wsi->context->ws_ping_pong_interval * - LWS_USEC_PER_SEC); - } + lws_validity_confirmed(wsi); /* issue it */ callback_action = LWS_CALLBACK_CLIENT_RECEIVE_PONG; break; @@ -541,7 +530,7 @@ pmdrx.eb_out = pmdrx.eb_in; lwsl_debug("%s: starting disbursal of %d deframed rx\n", - __func__, wsi->ws->rx_ubuf_head); + __func__, (int)wsi->ws->rx_ubuf_head); #if !defined(LWS_WITHOUT_EXTENSIONS) drain_extension: @@ -565,6 +554,7 @@ return -1; } if (n == PMDR_DID_NOTHING) + /* ie, not PMDR_NOTHING_WE_SHOULD_DO */ break; #endif lwsl_ext("%s: post inflate ebuf in len %d / out len %d\n", @@ -630,7 +620,7 @@ pmdrx.eb_out.token[pmdrx.eb_out.len] = '\0'; - if (!wsi->protocol->callback) + if (!wsi->a.protocol->callback) goto already_done; if (callback_action == LWS_CALLBACK_CLIENT_RECEIVE_PONG) @@ -662,7 +652,7 @@ ) pmdrx.eb_in.len -= pmdrx.eb_out.len; - m = wsi->protocol->callback(wsi, + m = wsi->a.protocol->callback(wsi, (enum lws_callback_reasons)callback_action, wsi->user_space, pmdrx.eb_out.token, pmdrx.eb_out.len); @@ -670,8 +660,8 @@ wsi->ws->first_fragment = 0; lwsl_debug("%s: bulk ws rx: inp used %d, output %d\n", - __func__, wsi->ws->rx_ubuf_head, - pmdrx.eb_out.len); + __func__, (int)wsi->ws->rx_ubuf_head, + (int)pmdrx.eb_out.len); /* if user code wants to close, let caller know */ if (m) diff -Nru libwebsockets-3.2.1/lib/roles/ws/client-ws.c libwebsockets-4.1.6/lib/roles/ws/client-ws.c --- libwebsockets-3.2.1/lib/roles/ws/client-ws.c 2019-12-18 14:45:31.000000000 +0000 +++ libwebsockets-4.1.6/lib/roles/ws/client-ws.c 2020-12-01 17:40:26.000000000 +0000 @@ -1,25 +1,28 @@ /* * libwebsockets - small server side websockets and web server implementation * - * Copyright (C) 2010-2018 Andy Green + * Copyright (C) 2010 - 2019 Andy Green * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation: - * version 2.1 of the License. + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to + * deal in the Software without restriction, including without limitation the + * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or + * sell copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: * - * This library is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. * - * You should have received a copy of the GNU Lesser General Public - * License along with this library; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, - * MA 02110-1301 USA + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS + * IN THE SOFTWARE. */ -#include +#include /* * In-place str to lower case @@ -62,7 +65,7 @@ return 0; } -#if !defined(LWS_NO_CLIENT) +#if defined(LWS_WITH_CLIENT) int lws_ws_handshake_client(struct lws *wsi, unsigned char **buf, size_t len) { @@ -128,7 +131,7 @@ */ if (lws_ws_client_rx_sm(wsi, *(*buf)++)) { - lwsl_notice("%s: client_rx_sm exited, DROPPING %d\n", + lwsl_info("%s: client_rx_sm exited, DROPPING %d\n", __func__, (int)len); return -1; } @@ -153,13 +156,13 @@ /* * create the random key */ - n = lws_get_random(wsi->context, hash, 16); - if (n != 16) { + if (lws_get_random(wsi->a.context, hash, 16) != 16) { lwsl_err("Unable to read from random dev %s\n", SYSTEM_RANDOM_FILEPATH); return NULL; } + /* coverity[tainted_scalar] */ lws_b64_encode_string(hash, 16, key_b64, sizeof(key_b64)); p += sprintf(p, "Upgrade: websocket\x0d\x0a" @@ -176,10 +179,10 @@ /* tell the server what extensions we could support */ #if !defined(LWS_WITHOUT_EXTENSIONS) - ext = wsi->vhost->ws.extensions; + ext = wsi->a.vhost->ws.extensions; while (ext && ext->callback) { - n = wsi->vhost->protocols[0].callback(wsi, + n = wsi->a.vhost->protocols[0].callback(wsi, LWS_CALLBACK_CLIENT_CONFIRM_EXTENSION_SUPPORTED, wsi->user_space, (char *)ext->name, 0); @@ -231,14 +234,14 @@ int lws_client_ws_upgrade(struct lws *wsi, const char **cce) { - struct lws_context_per_thread *pt = &wsi->context->pt[(int)wsi->tsi]; - struct lws_context *context = wsi->context; + struct lws_context *context = wsi->a.context; struct lws_tokenize ts; int n, len, okay = 0; lws_tokenize_elem e; char *p, buf[64]; const char *pc; #if !defined(LWS_WITHOUT_EXTENSIONS) + struct lws_context_per_thread *pt = &wsi->a.context->pt[(int)wsi->tsi]; char *sb = (char *)&pt->serv_buf[0]; const struct lws_ext_options *opts; const struct lws_extension *ext; @@ -248,7 +251,12 @@ char ignore; #endif - if (wsi->client_h2_substream) {/* !!! client ws-over-h2 not there yet */ +#if defined(LWS_WITH_DETAILED_LATENCY) + wsi->detlat.earliest_write_req = 0; + wsi->detlat.earliest_write_req_pre_write = 0; +#endif + + if (wsi->client_mux_substream) {/* !!! client ws-over-h2 not there yet */ lwsl_warn("%s: client ws-over-h2 upgrade not supported yet\n", __func__); *cce = "HS: h2 / ws upgrade unsupported"; @@ -295,9 +303,10 @@ lws_tokenize_init(&ts, buf, LWS_TOKENIZE_F_COMMA_SEP_LIST | LWS_TOKENIZE_F_MINUS_NONTERM); - ts.len = lws_hdr_copy(wsi, buf, sizeof(buf) - 1, WSI_TOKEN_CONNECTION); - if (ts.len <= 0) /* won't fit, or absent */ + n = lws_hdr_copy(wsi, buf, sizeof(buf) - 1, WSI_TOKEN_CONNECTION); + if (n <= 0) /* won't fit, or absent */ goto bad_conn_format; + ts.len = n; do { e = lws_tokenize(&ts); @@ -340,15 +349,15 @@ * default to first protocol */ - if (wsi->protocol) { - p = (char *)wsi->protocol->name; + if (wsi->a.protocol) { + p = (char *)wsi->a.protocol->name; goto identify_protocol; } /* no choice but to use the default protocol */ n = 0; - wsi->protocol = &wsi->vhost->protocols[0]; + wsi->a.protocol = &wsi->a.vhost->protocols[0]; goto check_extensions; } @@ -386,18 +395,18 @@ n = 0; /* keep client connection pre-bound protocol */ if (!lwsi_role_client(wsi)) - wsi->protocol = NULL; + wsi->a.protocol = NULL; - while (wsi->vhost->protocols[n].callback) { - if (!wsi->protocol && - strcmp(p, wsi->vhost->protocols[n].name) == 0) { - wsi->protocol = &wsi->vhost->protocols[n]; + while (n < wsi->a.vhost->count_protocols) { + if (!wsi->a.protocol && + strcmp(p, wsi->a.vhost->protocols[n].name) == 0) { + wsi->a.protocol = &wsi->a.vhost->protocols[n]; break; } n++; } - if (!wsi->vhost->protocols[n].callback) { /* no match */ + if (n == wsi->a.vhost->count_protocols) { /* no match */ /* if server, that's already fatal */ if (!lwsi_role_client(wsi)) { lwsl_info("%s: fail protocol %s\n", __func__, p); @@ -408,19 +417,19 @@ /* for client, find the index of our pre-bound protocol */ n = 0; - while (wsi->vhost->protocols[n].callback) { - if (wsi->protocol && strcmp(wsi->protocol->name, - wsi->vhost->protocols[n].name) == 0) { - wsi->protocol = &wsi->vhost->protocols[n]; + while (wsi->a.vhost->protocols[n].callback) { + if (wsi->a.protocol && strcmp(wsi->a.protocol->name, + wsi->a.vhost->protocols[n].name) == 0) { + wsi->a.protocol = &wsi->a.vhost->protocols[n]; break; } n++; } - if (!wsi->vhost->protocols[n].callback) { - if (wsi->protocol) + if (!wsi->a.vhost->protocols[n].callback) { + if (wsi->a.protocol) lwsl_err("Failed to match protocol %s\n", - wsi->protocol->name); + wsi->a.protocol->name); else lwsl_err("No protocol on client\n"); *cce = "ws protocol no match"; @@ -428,7 +437,7 @@ } } - lwsl_debug("Selected protocol %s\n", wsi->protocol->name); + lwsl_debug("Selected protocol %s\n", wsi->a.protocol->name); check_extensions: /* @@ -498,7 +507,7 @@ lwsl_notice("checking client ext %s\n", ext_name); n = 0; - ext = wsi->vhost->ws.extensions; + ext = wsi->a.vhost->ws.extensions; while (ext && ext->callback) { if (strcmp(ext_name, ext->name)) { ext++; @@ -530,7 +539,7 @@ * wants to */ ext_name[0] = '\0'; - if (user_callback_handle_rxflow(wsi->protocol->callback, + if (user_callback_handle_rxflow(wsi->a.protocol->callback, wsi, LWS_CALLBACK_WS_EXT_DEFAULTS, (char *)ext->name, ext_name, sizeof(ext_name))) { @@ -614,7 +623,7 @@ * we seem to be good to go, give client last chance to check * headers and OK it */ - if (wsi->protocol->callback(wsi, + if (wsi->a.protocol->callback(wsi, LWS_CALLBACK_CLIENT_FILTER_PRE_ESTABLISH, wsi->user_space, NULL, 0)) { *cce = "HS: Rejected by filter cb"; @@ -627,15 +636,8 @@ /* free up his parsing allocations */ lws_header_table_detach(wsi, 0); - lws_role_transition(wsi, LWSIFR_CLIENT, LRS_ESTABLISHED, - &role_ops_ws); - - if (wsi->context->ws_ping_pong_interval && !wsi->http2_substream ) { - wsi->sul_ping.cb = lws_sul_wsping_cb; - __lws_sul_insert(&pt->pt_sul_owner, &wsi->sul_ping, - (lws_usec_t)wsi->context->ws_ping_pong_interval * - LWS_USEC_PER_SEC); - } + lws_role_transition(wsi, LWSIFR_CLIENT, LRS_ESTABLISHED, &role_ops_ws); + lws_validity_confirmed(wsi); wsi->rxflow_change_to = LWS_RXFLOW_ALLOW; @@ -644,7 +646,7 @@ * size mentioned in the protocol definition. If 0 there, then * use a big default for compatibility */ - n = (int)wsi->protocol->rx_buffer_size; + n = (int)wsi->a.protocol->rx_buffer_size; if (!n) n = context->pt_serv_buf_size; n += LWS_PRE; @@ -656,22 +658,12 @@ goto bail2; } wsi->ws->rx_ubuf_alloc = n; - lwsl_info("Allocating client RX buffer %d\n", n); - -#if !defined(LWS_WITH_ESP32) - if (setsockopt(wsi->desc.sockfd, SOL_SOCKET, SO_SNDBUF, - (const char *)&n, sizeof n)) { - lwsl_warn("Failed to set SNDBUF to %d", n); - *cce = "HS: SO_SNDBUF failed"; - goto bail3; - } -#endif - lwsl_debug("handshake OK for protocol %s\n", wsi->protocol->name); + lwsl_debug("handshake OK for protocol %s\n", wsi->a.protocol->name); /* call him back to inform him he is up */ - if (wsi->protocol->callback(wsi, LWS_CALLBACK_CLIENT_ESTABLISHED, + if (wsi->a.protocol->callback(wsi, LWS_CALLBACK_CLIENT_ESTABLISHED, wsi->user_space, NULL, 0)) { *cce = "HS: Rejected at CLIENT_ESTABLISHED"; goto bail3; diff -Nru libwebsockets-3.2.1/lib/roles/ws/CMakeLists.txt libwebsockets-4.1.6/lib/roles/ws/CMakeLists.txt --- libwebsockets-3.2.1/lib/roles/ws/CMakeLists.txt 1970-01-01 00:00:00.000000000 +0000 +++ libwebsockets-4.1.6/lib/roles/ws/CMakeLists.txt 2020-12-01 17:40:26.000000000 +0000 @@ -0,0 +1,61 @@ +# +# libwebsockets - small server side websockets and web server implementation +# +# Copyright (C) 2010 - 2020 Andy Green +# +# Permission is hereby granted, free of charge, to any person obtaining a copy +# of this software and associated documentation files (the "Software"), to +# deal in the Software without restriction, including without limitation the +# rights to use, copy, modify, merge, publish, distribute, sublicense, and/or +# sell copies of the Software, and to permit persons to whom the Software is +# furnished to do so, subject to the following conditions: +# +# The above copyright notice and this permission notice shall be included in +# all copies or substantial portions of the Software. +# +# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING +# FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS +# IN THE SOFTWARE. +# +# The strategy is to only export to PARENT_SCOPE +# +# - changes to LIB_LIST +# - changes to SOURCES +# - includes via include_directories +# +# and keep everything else private + +include_directories(.) + +list(APPEND SOURCES + roles/ws/ops-ws.c) + +if (NOT LWS_WITHOUT_CLIENT) + list(APPEND SOURCES + roles/ws/client-ws.c + roles/ws/client-parser-ws.c) +endif() + +if (NOT LWS_WITHOUT_SERVER) + list(APPEND SOURCES + roles/ws/server-ws.c) +endif() + +if (NOT LWS_WITHOUT_EXTENSIONS) + list(APPEND HDR_PRIVATE + roles/ws/ext/extension-permessage-deflate.h) + list(APPEND SOURCES + roles/ws/ext/extension.c + roles/ws/ext/extension-permessage-deflate.c) +endif() + +# +# Keep explicit parent scope exports at end +# + +exports_to_parent_scope() + diff -Nru libwebsockets-3.2.1/lib/roles/ws/ext/extension.c libwebsockets-4.1.6/lib/roles/ws/ext/extension.c --- libwebsockets-3.2.1/lib/roles/ws/ext/extension.c 2019-12-18 14:45:31.000000000 +0000 +++ libwebsockets-4.1.6/lib/roles/ws/ext/extension.c 2020-12-01 17:40:26.000000000 +0000 @@ -1,8 +1,32 @@ -#include "core/private.h" +/* + * libwebsockets - small server side websockets and web server implementation + * + * Copyright (C) 2010 - 2019 Andy Green + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to + * deal in the Software without restriction, including without limitation the + * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or + * sell copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS + * IN THE SOFTWARE. + */ + +#include "private-lib-core.h" #include "extension-permessage-deflate.h" -LWS_VISIBLE void +void lws_context_init_extensions(const struct lws_context_creation_info *info, struct lws_context *context) { @@ -17,7 +41,7 @@ LEAPS_SEEK_ARG_TERM }; -LWS_VISIBLE int +int lws_ext_parse_options(const struct lws_extension *ext, struct lws *wsi, void *ext_user, const struct lws_ext_options *opts, const char *in, int len) @@ -196,10 +220,10 @@ int n = 0, m, handled = 0; const struct lws_extension *ext; - if (!wsi || !wsi->vhost || !wsi->ws) + if (!wsi || !wsi->a.vhost || !wsi->ws) return 0; - ext = wsi->vhost->ws.extensions; + ext = wsi->a.vhost->ws.extensions; while (ext && ext->callback && !handled) { m = ext->callback(context, ext, wsi, reason, @@ -309,7 +333,7 @@ lws_any_extension_handled(struct lws *wsi, enum lws_extension_callback_reasons r, void *v, size_t len) { - struct lws_context *context = wsi->context; + struct lws_context *context = wsi->a.context; int n, handled = 0; if (!wsi->ws) @@ -352,7 +376,7 @@ oa.start = opt_val; oa.len = 0; - return wsi->ws->active_extensions[idx]->callback(wsi->context, + return wsi->ws->active_extensions[idx]->callback(wsi->a.context, wsi->ws->active_extensions[idx], wsi, LWS_EXT_CB_NAMED_OPTION_SET, wsi->ws->act_ext_user[idx], &oa, 0); diff -Nru libwebsockets-3.2.1/lib/roles/ws/ext/extension-permessage-deflate.c libwebsockets-4.1.6/lib/roles/ws/ext/extension-permessage-deflate.c --- libwebsockets-3.2.1/lib/roles/ws/ext/extension-permessage-deflate.c 2019-12-18 14:45:31.000000000 +0000 +++ libwebsockets-4.1.6/lib/roles/ws/ext/extension-permessage-deflate.c 2020-12-01 17:40:26.000000000 +0000 @@ -1,25 +1,28 @@ /* - * ./lib/extension-permessage-deflate.c + * libwebsockets - small server side websockets and web server implementation * - * Copyright (C) 2016 - 2018 Andy Green + * Copyright (C) 2010 - 2019 Andy Green * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation: - * version 2.1 of the License. + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to + * deal in the Software without restriction, including without limitation the + * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or + * sell copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: * - * This library is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. * - * You should have received a copy of the GNU Lesser General Public - * License along with this library; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, - * MA 02110-1301 USA + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS + * IN THE SOFTWARE. */ -#include "core/private.h" +#include "private-lib-core.h" #include "extension-permessage-deflate.h" #include #include @@ -49,9 +52,9 @@ /* cap the RX buf at the nearest power of 2 to protocol rx buf */ - n = wsi->context->pt_serv_buf_size; - if (wsi->protocol->rx_buffer_size) - n = (int)wsi->protocol->rx_buffer_size; + n = wsi->a.context->pt_serv_buf_size; + if (wsi->a.protocol->rx_buffer_size) + n = (int)wsi->a.protocol->rx_buffer_size; extra = 7; while (n >= 1 << (extra + 1)) @@ -127,13 +130,13 @@ case LWS_EXT_CB_CONSTRUCT: n = context->pt_serv_buf_size; - if (wsi->protocol->rx_buffer_size) - n = (int)wsi->protocol->rx_buffer_size; + if (wsi->a.protocol->rx_buffer_size) + n = (int)wsi->a.protocol->rx_buffer_size; if (n < 128) { lwsl_info(" permessage-deflate requires the protocol " "(%s) to have an RX buffer >= 128\n", - wsi->protocol->name); + wsi->a.protocol->name); return -1; } @@ -183,13 +186,26 @@ case LWS_EXT_CB_PAYLOAD_RX: + /* + * ie, we are INFLATING + */ lwsl_ext(" %s: LWS_EXT_CB_PAYLOAD_RX: in %d, existing in %d\n", __func__, pmdrx->eb_in.len, priv->rx.avail_in); - /* if this frame is not marked as compressed, we ignore it */ + /* + * If this frame is not marked as compressed, + * there is nothing we should do with it + */ if (!(wsi->ws->rsv_first_msg & 0x40) || (wsi->ws->opcode & 8)) - return PMDR_DID_NOTHING; + /* + * This is a bit different than DID_NOTHING... we have + * identified using ext-private bits in the packet, or + * by it being a control fragment that we SHOULD not do + * anything to it, parent should continue as if we + * processed it + */ + return PMDR_NOTHING_WE_SHOULD_DO; /* * we shouldn't come back in here if we already applied the @@ -201,9 +217,8 @@ pmdrx->eb_out.len = 0; lwsl_ext("%s: LWS_EXT_CB_PAYLOAD_RX: in %d, " - "existing avail in %d, pkt fin: %d\n", __func__, - pmdrx->eb_in.len, priv->rx.avail_in, - wsi->ws->final); + "existing avail in %d, pkt fin: %d\n", __func__, + pmdrx->eb_in.len, priv->rx.avail_in, wsi->ws->final); /* if needed, initialize the inflator */ @@ -247,14 +262,12 @@ pmdrx->eb_out.token = priv->rx.next_out; priv->rx.avail_out = 1 << priv->args[PMD_RX_BUF_PWR2]; - pen = penbits = 0; - deflatePending(&priv->rx, &pen, &penbits); - pen |= penbits; - /* so... if... * * - he has no remaining input content for this message, and + * * - and this is the final fragment, and + * * - we used everything that could be drained on the input side * * ...then put back the 00 00 FF FF the sender stripped as our @@ -276,7 +289,7 @@ * him right now, bail without having done anything */ - if (!priv->rx.avail_in && !pen) + if (!priv->rx.avail_in) return PMDR_DID_NOTHING; n = inflate(&priv->rx, was_fin ? Z_SYNC_FLUSH : Z_NO_FLUSH); @@ -300,25 +313,18 @@ (pmdrx->eb_in.len - priv->rx.avail_in); pmdrx->eb_in.len = priv->rx.avail_in; - pen = penbits = 0; - deflatePending(&priv->rx, &pen, &penbits); - pen |= penbits; - - lwsl_debug("%s: %d %d %d %d %d %d\n", __func__, + lwsl_debug("%s: %d %d %d %d %d\n", __func__, priv->rx.avail_in, wsi->ws->final, (int)wsi->ws->rx_packet_length, was_fin, - wsi->ws->pmd_trailer_application, - pen); + wsi->ws->pmd_trailer_application); if (!priv->rx.avail_in && wsi->ws->final && !wsi->ws->rx_packet_length && !was_fin && - wsi->ws->pmd_trailer_application && - !pen - ) { + wsi->ws->pmd_trailer_application) { lwsl_ext("%s: RX trailer apply 2\n", __func__); /* we overallocated just for this situation where @@ -331,7 +337,7 @@ priv->rx.avail_in = sizeof(trail); n = inflate(&priv->rx, Z_SYNC_FLUSH); lwsl_ext("RX trailer infl ret %d, avi %d, avo %d\n", - n, priv->rx.avail_in, priv->rx.avail_out); + n, priv->rx.avail_in, priv->rx.avail_out); switch (n) { case Z_NEED_DICT: case Z_STREAM_ERROR: @@ -343,10 +349,6 @@ } assert(priv->rx.avail_out); - - pen = penbits = 0; - deflatePending(&priv->rx, &pen, &penbits); - pen |= penbits; } pmdrx->eb_out.len = lws_ptr_diff(priv->rx.next_out, @@ -358,7 +360,7 @@ __func__, pmdrx->eb_out.len, priv->rx.avail_in, (unsigned long)priv->count_rx_between_fin); - if (was_fin && !pen) { + if (was_fin) { lwsl_ext("%s: was_fin\n", __func__); priv->count_rx_between_fin = 0; if (priv->args[PMD_SERVER_NO_CONTEXT_TAKEOVER]) { @@ -370,20 +372,24 @@ return PMDR_EMPTY_FINAL; } - if (pen || priv->rx.avail_in) + if (priv->rx.avail_in) return PMDR_HAS_PENDING; return PMDR_EMPTY_NONFINAL; case LWS_EXT_CB_PAYLOAD_TX: - /* initialize us if needed */ + /* + * ie, we are DEFLATING + * + * initialize us if needed + */ if (!priv->tx_init) { n = deflateInit2(&priv->tx, priv->args[PMD_COMP_LEVEL], Z_DEFLATED, -priv->args[PMD_SERVER_MAX_WINDOW_BITS + - (wsi->vhost->listen_port <= 0)], + (wsi->a.vhost->listen_port <= 0)], priv->args[PMD_MEM_LEVEL], Z_DEFAULT_STRATEGY); if (n != Z_OK) { diff -Nru libwebsockets-3.2.1/lib/roles/ws/ext/extension-permessage-deflate.h libwebsockets-4.1.6/lib/roles/ws/ext/extension-permessage-deflate.h --- libwebsockets-3.2.1/lib/roles/ws/ext/extension-permessage-deflate.h 2019-12-18 14:45:31.000000000 +0000 +++ libwebsockets-4.1.6/lib/roles/ws/ext/extension-permessage-deflate.h 2020-12-01 17:40:26.000000000 +0000 @@ -1,3 +1,26 @@ +/* + * libwebsockets - small server side websockets and web server implementation + * + * Copyright (C) 2010 - 2019 Andy Green + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to + * deal in the Software without restriction, including without limitation the + * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or + * sell copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS + * IN THE SOFTWARE. + */ #if defined(LWS_WITH_MINIZ) #include diff -Nru libwebsockets-3.2.1/lib/roles/ws/ops-ws.c libwebsockets-4.1.6/lib/roles/ws/ops-ws.c --- libwebsockets-3.2.1/lib/roles/ws/ops-ws.c 2019-12-18 14:45:31.000000000 +0000 +++ libwebsockets-4.1.6/lib/roles/ws/ops-ws.c 2020-12-01 17:40:26.000000000 +0000 @@ -1,25 +1,28 @@ /* * libwebsockets - small server side websockets and web server implementation * - * Copyright (C) 2010-2018 Andy Green + * Copyright (C) 2010 - 2019 Andy Green * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation: - * version 2.1 of the License. + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to + * deal in the Software without restriction, including without limitation the + * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or + * sell copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: * - * This library is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. * - * You should have received a copy of the GNU Lesser General Public - * License along with this library; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, - * MA 02110-1301 USA + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS + * IN THE SOFTWARE. */ -#include +#include #define LWS_CPYAPP(ptr, str) { strcpy(ptr, str); ptr += strlen(str); } @@ -31,7 +34,6 @@ int lws_ws_rx_sm(struct lws *wsi, char already_processed, unsigned char c) { - struct lws_context_per_thread *pt = &wsi->context->pt[(int)wsi->tsi]; int callback_action = LWS_CALLBACK_RECEIVE; struct lws_ext_pm_deflate_rx_ebufs pmdrx; unsigned short close_code; @@ -154,7 +156,7 @@ switch (wsi->ws->opcode) { case LWSWSOPC_TEXT_FRAME: wsi->ws->check_utf8 = lws_check_opt( - wsi->context->options, + wsi->a.context->options, LWS_SERVER_OPTION_VALIDATE_UTF8); /* fallthru */ case LWSWSOPC_BINARY_FRAME: @@ -420,12 +422,12 @@ * if there's no protocol max frame size given, we are * supposed to default to context->pt_serv_buf_size */ - if (!wsi->protocol->rx_buffer_size && - wsi->ws->rx_ubuf_head != wsi->context->pt_serv_buf_size) + if (!wsi->a.protocol->rx_buffer_size && + wsi->ws->rx_ubuf_head != wsi->a.context->pt_serv_buf_size) break; - if (wsi->protocol->rx_buffer_size && - wsi->ws->rx_ubuf_head != wsi->protocol->rx_buffer_size) + if (wsi->a.protocol->rx_buffer_size && + wsi->ws->rx_ubuf_head != wsi->a.protocol->rx_buffer_size) break; /* spill because we filled our rx buffer */ @@ -435,7 +437,7 @@ * layer? If so service it and hide it from the user callback */ - lwsl_parser("spill on %s\n", wsi->protocol->name); + lwsl_parser("spill on %s\n", wsi->a.protocol->name); switch (wsi->ws->opcode) { case LWSWSOPC_CLOSE: @@ -446,7 +448,7 @@ wsi->ws->peer_has_sent_close = 1; pp = &wsi->ws->rx_ubuf[LWS_PRE]; - if (lws_check_opt(wsi->context->options, + if (lws_check_opt(wsi->a.context->options, LWS_SERVER_OPTION_VALIDATE_UTF8) && wsi->ws->rx_ubuf_head > 2 && lws_check_utf8(&wsi->ws->utf8, pp + 2, @@ -496,7 +498,7 @@ } if (user_callback_handle_rxflow( - wsi->protocol->callback, wsi, + wsi->a.protocol->callback, wsi, LWS_CALLBACK_WS_PEER_INITIATED_CLOSE, wsi->user_space, &wsi->ws->rx_ubuf[LWS_PRE], @@ -511,7 +513,7 @@ case LWSWSOPC_PING: lwsl_info("received %d byte ping, sending pong\n", - wsi->ws->rx_ubuf_head); + (int)wsi->ws->rx_ubuf_head); if (wsi->ws->ping_pending_flag) { /* @@ -547,22 +549,7 @@ lwsl_hexdump(&wsi->ws->rx_ubuf[LWS_PRE], wsi->ws->rx_ubuf_head); - if (wsi->ws->await_pong) { - lwsl_info("received expected PONG on wsi %p\n", - wsi); - lws_set_timeout(wsi, NO_PENDING_TIMEOUT, 0); - wsi->ws->await_pong = 0; - - /* - * prepare to send the ping again if nothing - * sent to countermand it - */ - - __lws_sul_insert(&pt->pt_sul_owner, - &wsi->sul_ping, - (lws_usec_t)wsi->context->ws_ping_pong_interval * - LWS_USEC_PER_SEC); - } + lws_validity_confirmed(wsi); /* issue it */ callback_action = LWS_CALLBACK_RECEIVE_PONG; @@ -646,6 +633,7 @@ return -1; } if (n == PMDR_DID_NOTHING) + /* ie, not PMDR_NOTHING_WE_SHOULD_DO */ break; #endif lwsl_debug("%s: post ext ret %d, ebuf in %d / out %d\n", @@ -704,7 +692,8 @@ /* if pmd not enabled, in == out */ - if (n == PMDR_DID_NOTHING + if (n == PMDR_DID_NOTHING || + n == PMDR_NOTHING_WE_SHOULD_DO #if !defined(LWS_WITHOUT_EXTENSIONS) || n == PMDR_UNKNOWN @@ -719,14 +708,14 @@ if (pmdrx.eb_out.len) pmdrx.eb_out.token[pmdrx.eb_out.len] = '\0'; - if (wsi->protocol->callback && + if (wsi->a.protocol->callback && !(already_processed & ALREADY_PROCESSED_NO_CB)) { if (callback_action == LWS_CALLBACK_RECEIVE_PONG) lwsl_info("Doing pong callback\n"); ret = user_callback_handle_rxflow( - wsi->protocol->callback, wsi, + wsi->a.protocol->callback, wsi, (enum lws_callback_reasons) callback_action, wsi->user_space, @@ -762,13 +751,13 @@ } -LWS_VISIBLE size_t +size_t lws_remaining_packet_payload(struct lws *wsi) { return wsi->ws->rx_packet_length; } -LWS_VISIBLE int lws_frame_is_binary(struct lws *wsi) +int lws_frame_is_binary(struct lws *wsi) { return wsi->ws->frame_is_binary; } @@ -777,7 +766,7 @@ lws_add_wsi_to_draining_ext_list(struct lws *wsi) { #if !defined(LWS_WITHOUT_EXTENSIONS) - struct lws_context_per_thread *pt = &wsi->context->pt[(int)wsi->tsi]; + struct lws_context_per_thread *pt = &wsi->a.context->pt[(int)wsi->tsi]; if (wsi->ws->rx_draining_ext) return; @@ -794,7 +783,7 @@ lws_remove_wsi_from_draining_ext_list(struct lws *wsi) { #if !defined(LWS_WITHOUT_EXTENSIONS) - struct lws_context_per_thread *pt = &wsi->context->pt[(int)wsi->tsi]; + struct lws_context_per_thread *pt = &wsi->a.context->pt[(int)wsi->tsi]; struct lws **w = &pt->ws.rx_draining_ext_list; if (!wsi->ws->rx_draining_ext) @@ -820,13 +809,13 @@ static int lws_0405_frame_mask_generate(struct lws *wsi) { - int n; + size_t n; /* fetch the per-frame nonce */ n = lws_get_random(lws_get_context(wsi), wsi->ws->mask, 4); if (n != 4) { lwsl_parser("Unable to read from random device %s %d\n", - SYSTEM_RANDOM_FILEPATH, n); + SYSTEM_RANDOM_FILEPATH, (int)n); return 1; } @@ -836,64 +825,22 @@ return 0; } -void -lws_sul_wsping_cb(lws_sorted_usec_list_t *sul) -{ - struct lws *wsi = lws_container_of(sul, struct lws, sul_ping); - - if (!wsi->ws) - return; - - /* - * The sul_ping timer came up... either it's time to send a PING - * (!wsi->ws->send_check_ping), or we didn't get the PONG in time - * (wsi->ws->send_check_ping) - */ - - if (!wsi->ws->send_check_ping) { - lwsl_info("%s: req pp on wsi %p\n", __func__, wsi); - - wsi->ws->send_check_ping = 1; - lws_set_timeout(wsi, PENDING_TIMEOUT_WS_PONG_CHECK_SEND_PING, - wsi->context->timeout_secs); - lws_callback_on_writable(wsi); - - return; - } - - if (wsi->ws->await_pong) { - /* it didn't return the PONG in time */ - - lwsl_info("%s: wsi %p: failed to send PONG\n", __func__, wsi); - __lws_close_free_wsi(wsi, LWS_CLOSE_STATUS_NOSTATUS, - "PONG timeout"); - } -} - int lws_server_init_wsi_for_ws(struct lws *wsi) { - struct lws_context_per_thread *pt = &wsi->context->pt[(int)wsi->tsi]; int n; lwsi_set_state(wsi, LRS_ESTABLISHED); - if (wsi->context->ws_ping_pong_interval && !wsi->http2_substream ) { - wsi->sul_ping.cb = lws_sul_wsping_cb; - __lws_sul_insert(&pt->pt_sul_owner, &wsi->sul_ping, - (lws_usec_t)wsi->context->ws_ping_pong_interval * - LWS_USEC_PER_SEC); - } - /* * create the frame buffer for this connection according to the * size mentioned in the protocol definition. If 0 there, use * a big default for compatibility */ - n = (int)wsi->protocol->rx_buffer_size; + n = (int)wsi->a.protocol->rx_buffer_size; if (!n) - n = wsi->context->pt_serv_buf_size; + n = wsi->a.context->pt_serv_buf_size; n += LWS_PRE; wsi->ws->rx_ubuf = lws_malloc(n + 4 /* 0x0000ffff zlib */, "rx_ubuf"); if (!wsi->ws->rx_ubuf) { @@ -901,21 +848,11 @@ return 1; } wsi->ws->rx_ubuf_alloc = n; - lwsl_debug("Allocating RX buffer %d\n", n); - -#if !defined(LWS_WITH_ESP32) - if (!wsi->h2_stream_carries_ws) - if (setsockopt(wsi->desc.sockfd, SOL_SOCKET, SO_SNDBUF, - (const char *)&n, sizeof n)) { - lwsl_warn("Failed to set SNDBUF to %d", n); - return 1; - } -#endif /* notify user code that we're ready to roll */ - if (wsi->protocol->callback) - if (wsi->protocol->callback(wsi, LWS_CALLBACK_ESTABLISHED, + if (wsi->a.protocol->callback) + if (wsi->a.protocol->callback(wsi, LWS_CALLBACK_ESTABLISHED, wsi->user_space, #ifdef LWS_WITH_TLS wsi->tls.ssl, @@ -925,6 +862,7 @@ wsi->h2_stream_carries_ws)) return 1; + lws_validity_confirmed(wsi); lwsl_debug("ws established\n"); return 0; @@ -932,7 +870,7 @@ -LWS_VISIBLE int +int lws_is_final_fragment(struct lws *wsi) { #if !defined(LWS_WITHOUT_EXTENSIONS) @@ -946,31 +884,31 @@ #endif } -LWS_VISIBLE int +int lws_is_first_fragment(struct lws *wsi) { return wsi->ws->first_fragment; } -LWS_VISIBLE unsigned char +unsigned char lws_get_reserved_bits(struct lws *wsi) { return wsi->ws->rsv; } -LWS_VISIBLE LWS_EXTERN int +int lws_get_close_length(struct lws *wsi) { return wsi->ws->close_in_ping_buffer_len; } -LWS_VISIBLE LWS_EXTERN unsigned char * +unsigned char * lws_get_close_payload(struct lws *wsi) { return &wsi->ws->ping_payload_buf[LWS_PRE]; } -LWS_VISIBLE LWS_EXTERN void +void lws_close_reason(struct lws *wsi, enum lws_close_status status, unsigned char *buf, size_t len) { @@ -1018,7 +956,7 @@ return LWS_HPI_RET_PLEASE_CLOSE_ME; } - // lwsl_notice("%s: %s\n", __func__, wsi->protocol->name); + // lwsl_notice("%s: %s\n", __func__, wsi->a.protocol->name); //lwsl_info("%s: wsistate 0x%x, pollout %d\n", __func__, // wsi->wsistate, pollfd->revents & LWS_POLLOUT); @@ -1036,14 +974,14 @@ ebuf.len = 0; if (lwsi_state(wsi) == LRS_WAITING_CONNECT) { -#if !defined(LWS_NO_CLIENT) +#if defined(LWS_WITH_CLIENT) if ((pollfd->revents & LWS_POLLOUT) && lws_handle_POLLOUT_event(wsi, pollfd)) { lwsl_debug("POLLOUT event closed it\n"); return LWS_HPI_RET_PLEASE_CLOSE_ME; } - n = lws_client_socket_service(wsi, pollfd, NULL); + n = lws_client_socket_service(wsi, pollfd); if (n) return LWS_HPI_RET_WSI_ALREADY_DIED; #endif @@ -1106,7 +1044,7 @@ return LWS_HPI_RET_HANDLED; #if defined(LWS_WITH_HTTP2) - if (wsi->http2_substream || wsi->upgraded_to_http2) { + if (wsi->mux_substream || wsi->upgraded_to_http2) { wsi1 = lws_get_network_wsi(wsi); if (wsi1 && lws_has_buffered_out(wsi1)) /* We cannot deal with any kind of new RX @@ -1125,7 +1063,7 @@ if (wsi->ws->rx_draining_ext) { lwsl_debug("%s: RX EXT DRAINING: Service\n", __func__); -#ifndef LWS_NO_CLIENT +#if defined(LWS_WITH_CLIENT) if (lwsi_role_client(wsi)) { n = lws_ws_client_rx_sm(wsi, 0); if (n < 0) @@ -1150,7 +1088,7 @@ /* 3: buflist needs to be drained */ read: - //lws_buflist_describe(&wsi->buflist, wsi); + //lws_buflist_describe(&wsi->buflist, wsi, __func__); ebuf.len = (int)lws_buflist_next_segment_len(&wsi->buflist, &ebuf.token); if (ebuf.len) { @@ -1187,10 +1125,10 @@ if (lwsi_role_ws(wsi)) ebuf.len = wsi->ws->rx_ubuf_alloc; else - ebuf.len = wsi->context->pt_serv_buf_size; + ebuf.len = wsi->a.context->pt_serv_buf_size; - if ((unsigned int)ebuf.len > wsi->context->pt_serv_buf_size) - ebuf.len = wsi->context->pt_serv_buf_size; + if ((unsigned int)ebuf.len > wsi->a.context->pt_serv_buf_size) + ebuf.len = wsi->a.context->pt_serv_buf_size; if ((int)pending > ebuf.len) pending = ebuf.len; @@ -1236,7 +1174,7 @@ do { /* service incoming data */ - //lws_buflist_describe(&wsi->buflist, wsi); + //lws_buflist_describe(&wsi->buflist, wsi, __func__); if (ebuf.len) { #if defined(LWS_ROLE_H2) if (lwsi_role_h2(wsi) && lwsi_state(wsi) != LRS_BODY && @@ -1250,12 +1188,12 @@ if (n < 0) { /* we closed wsi */ - n = 0; return LWS_HPI_RET_WSI_ALREADY_DIED; } - //lws_buflist_describe(&wsi->buflist, wsi); + //lws_buflist_describe(&wsi->buflist, wsi, __func__); //lwsl_notice("%s: consuming %d / %d\n", __func__, n, ebuf.len); - if (lws_buflist_aware_consume(wsi, &ebuf, n, buffered)) + if (lws_buflist_aware_finished_consuming(wsi, &ebuf, n, + buffered, __func__)) return LWS_HPI_RET_PLEASE_CLOSE_ME; } @@ -1264,7 +1202,7 @@ } while (m); if (wsi->http.ah -#if !defined(LWS_NO_CLIENT) +#if defined(LWS_WITH_CLIENT) && !wsi->client_h2_alpn #endif ) { @@ -1273,13 +1211,20 @@ } pending = lws_ssl_pending(wsi); + +#if defined(LWS_WITH_CLIENT) + if (!pending && (wsi->flags & LCCSCF_PRIORITIZE_READS) && + lws_buflist_total_len(&wsi->buflist)) + pending = 9999999; +#endif + if (pending) { if (lws_is_ws_with_ext(wsi)) pending = pending > wsi->ws->rx_ubuf_alloc ? wsi->ws->rx_ubuf_alloc : pending; else - pending = pending > wsi->context->pt_serv_buf_size ? - wsi->context->pt_serv_buf_size : pending; + pending = pending > wsi->a.context->pt_serv_buf_size ? + wsi->a.context->pt_serv_buf_size : pending; goto read; } @@ -1287,7 +1232,7 @@ !lws_buflist_next_segment_len(&wsi->buflist, NULL)) { lwsl_info("%s: %p flow buf: drained\n", __func__, wsi); /* having drained the rxflow buffer, can rearm POLLIN */ -#ifdef LWS_NO_SERVER +#if !defined(LWS_WITH_SERVER) n = #endif __lws_rx_flow_control(wsi); @@ -1301,7 +1246,6 @@ int rops_handle_POLLOUT_ws(struct lws *wsi) { - struct lws_context_per_thread *pt = &wsi->context->pt[(int)wsi->tsi]; int write_type = LWS_WRITE_PONG; #if !defined(LWS_WITHOUT_EXTENSIONS) struct lws_ext_pm_deflate_rx_ebufs pmdrx; @@ -1311,7 +1255,7 @@ #if !defined(LWS_WITHOUT_EXTENSIONS) lwsl_debug("%s: %s: wsi->ws->tx_draining_ext %d\n", __func__, - wsi->protocol->name, wsi->ws->tx_draining_ext); + wsi->a.protocol->name, wsi->ws->tx_draining_ext); #endif /* Priority 3: pending control packets (pong or close) @@ -1379,24 +1323,17 @@ } if (!wsi->socket_is_permanently_unusable && - wsi->ws->send_check_ping && wsi->context->ws_ping_pong_interval) { + wsi->ws->send_check_ping) { lwsl_info("%s: issuing ping on wsi %p: %s %s h2: %d\n", __func__, wsi, - wsi->role_ops->name, wsi->protocol->name, - wsi->http2_substream); + wsi->role_ops->name, wsi->a.protocol->name, + wsi->mux_substream); wsi->ws->send_check_ping = 0; - wsi->ws->await_pong = 1; n = lws_write(wsi, &wsi->ws->ping_payload_buf[LWS_PRE], 0, LWS_WRITE_PING); if (n < 0) return LWS_HP_RET_BAIL_DIE; - /* give it a few seconds to respond with the PONG */ - - __lws_sul_insert(&pt->pt_sul_owner, &wsi->sul_ping, - (lws_usec_t)wsi->context->timeout_secs * - LWS_USEC_PER_SEC); - return LWS_HP_RET_BAIL_OK; } @@ -1438,8 +1375,11 @@ */ ret = 1; - if (wsi->role_ops == &role_ops_raw_skt || - wsi->role_ops == &role_ops_raw_file) + if (wsi->role_ops == &role_ops_raw_skt +#if defined(LWS_ROLE_RAW_FILE) + || wsi->role_ops == &role_ops_raw_file +#endif + ) ret = 0; while (ret == 1) { @@ -1633,8 +1573,8 @@ rops_write_role_protocol_ws(struct lws *wsi, unsigned char *buf, size_t len, enum lws_write_protocol *wp) { - struct lws_context_per_thread *pt = &wsi->context->pt[(int)wsi->tsi]; #if !defined(LWS_WITHOUT_EXTENSIONS) + struct lws_context_per_thread *pt = &wsi->a.context->pt[(int)wsi->tsi]; enum lws_write_protocol wpt; #endif struct lws_ext_pm_deflate_rx_ebufs pmdrx; @@ -1681,13 +1621,7 @@ // assert(0); } #endif - /* reset the ping wait */ - if (wsi->context->ws_ping_pong_interval) { - wsi->sul_ping.cb = lws_sul_wsping_cb; - __lws_sul_insert(&pt->pt_sul_owner, &wsi->sul_ping, - (lws_usec_t)wsi->context->ws_ping_pong_interval * - LWS_USEC_PER_SEC); - } + if (((*wp) & 0x1f) == LWS_WRITE_HTTP || ((*wp) & 0x1f) == LWS_WRITE_HTTP_FINAL || ((*wp) & 0x1f) == LWS_WRITE_HTTP_HEADERS_CONTINUATION || @@ -1979,10 +1913,9 @@ static int rops_close_kill_connection_ws(struct lws *wsi, enum lws_close_status reason) { - lws_dll2_remove(&wsi->sul_ping.list); /* deal with ws encapsulation in h2 */ #if defined(LWS_WITH_HTTP2) - if (wsi->http2_substream && wsi->h2_stream_carries_ws) + if (wsi->mux_substream && wsi->h2_stream_carries_ws) return role_ops_h2.close_kill_connection(wsi, reason); return 0; @@ -2013,7 +1946,7 @@ { #if !defined(LWS_WITHOUT_EXTENSIONS) #ifdef LWS_WITH_PLUGINS - struct lws_plugin *plugin = vh->context->plugin_list; + struct lws_plugin *plugin; int m; if (vh->context->plugin_extension_count) { @@ -2036,11 +1969,14 @@ sizeof(struct lws_extension) * m); plugin = vh->context->plugin_list; while (plugin) { + const lws_plugin_protocol_t *plpr = + (const lws_plugin_protocol_t *)plugin->hdr; + memcpy((struct lws_extension *)&vh->ws.extensions[m], - plugin->caps.extensions, + plpr->extensions, sizeof(struct lws_extension) * - plugin->caps.count_extensions); - m += plugin->caps.count_extensions; + plpr->count_extensions); + m += plpr->count_extensions; plugin = plugin->list; } } else @@ -2086,14 +2022,41 @@ return 0; } -struct lws_role_ops role_ops_ws = { +static int +rops_issue_keepalive_ws(struct lws *wsi, int isvalid) +{ + uint64_t us; + +#if defined(LWS_WITH_HTTP2) + if (lwsi_role_h2_ENCAPSULATION(wsi)) { + /* we know then that it has an h2 parent */ + struct lws *enc = role_ops_h2.encapsulation_parent(wsi); + + assert(enc); + if (enc->role_ops->issue_keepalive(enc, isvalid)) + return 1; + } +#endif + + if (isvalid) + _lws_validity_confirmed_role(wsi); + else { + us = lws_now_usecs(); + memcpy(&wsi->ws->ping_payload_buf[LWS_PRE], &us, 8); + wsi->ws->send_check_ping = 1; + lws_callback_on_writable(wsi); + } + + return 0; +} + +const struct lws_role_ops role_ops_ws = { /* role name */ "ws", /* alpn id */ NULL, /* check_upgrades */ NULL, - /* init_context */ NULL, + /* pt_init_destroy */ NULL, /* init_vhost */ rops_init_vhost_ws, /* destroy_vhost */ rops_destroy_vhost_ws, - /* periodic_checks */ NULL, /* service_flag_pending */ rops_service_flag_pending_ws, /* handle_POLLIN */ rops_handle_POLLIN_ws, /* handle_POLLOUT */ rops_handle_POLLOUT_ws, @@ -2109,6 +2072,7 @@ /* destroy_role */ rops_destroy_role_ws, /* adoption_bind */ NULL, /* client_bind */ NULL, + /* issue_keepalive */ rops_issue_keepalive_ws, /* adoption_cb clnt, srv */ { LWS_CALLBACK_SERVER_NEW_CLIENT_INSTANTIATED, LWS_CALLBACK_SERVER_NEW_CLIENT_INSTANTIATED }, /* rx_cb clnt, srv */ { LWS_CALLBACK_CLIENT_RECEIVE, diff -Nru libwebsockets-3.2.1/lib/roles/ws/private.h libwebsockets-4.1.6/lib/roles/ws/private.h --- libwebsockets-3.2.1/lib/roles/ws/private.h 2019-12-18 14:45:31.000000000 +0000 +++ libwebsockets-4.1.6/lib/roles/ws/private.h 1970-01-01 00:00:00.000000000 +0000 @@ -1,191 +0,0 @@ -/* - * libwebsockets - small server side websockets and web server implementation - * - * Copyright (C) 2010 - 2018 Andy Green - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation: - * version 2.1 of the License. - * - * This library is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with this library; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, - * MA 02110-1301 USA - * - * This is included from core/private.h if LWS_ROLE_WS - */ - -extern struct lws_role_ops role_ops_ws; - -#define lwsi_role_ws(wsi) (wsi->role_ops == &role_ops_ws) - -enum lws_rx_parse_state { - LWS_RXPS_NEW, - - LWS_RXPS_04_mask_1, - LWS_RXPS_04_mask_2, - LWS_RXPS_04_mask_3, - - LWS_RXPS_04_FRAME_HDR_1, - LWS_RXPS_04_FRAME_HDR_LEN, - LWS_RXPS_04_FRAME_HDR_LEN16_2, - LWS_RXPS_04_FRAME_HDR_LEN16_1, - LWS_RXPS_04_FRAME_HDR_LEN64_8, - LWS_RXPS_04_FRAME_HDR_LEN64_7, - LWS_RXPS_04_FRAME_HDR_LEN64_6, - LWS_RXPS_04_FRAME_HDR_LEN64_5, - LWS_RXPS_04_FRAME_HDR_LEN64_4, - LWS_RXPS_04_FRAME_HDR_LEN64_3, - LWS_RXPS_04_FRAME_HDR_LEN64_2, - LWS_RXPS_04_FRAME_HDR_LEN64_1, - - LWS_RXPS_07_COLLECT_FRAME_KEY_1, - LWS_RXPS_07_COLLECT_FRAME_KEY_2, - LWS_RXPS_07_COLLECT_FRAME_KEY_3, - LWS_RXPS_07_COLLECT_FRAME_KEY_4, - - LWS_RXPS_WS_FRAME_PAYLOAD -}; - -enum lws_websocket_opcodes_07 { - LWSWSOPC_CONTINUATION = 0, - LWSWSOPC_TEXT_FRAME = 1, - LWSWSOPC_BINARY_FRAME = 2, - - LWSWSOPC_NOSPEC__MUX = 7, - - /* control extensions 8+ */ - - LWSWSOPC_CLOSE = 8, - LWSWSOPC_PING = 9, - LWSWSOPC_PONG = 0xa, -}; - -/* this is not usable directly by user code any more, lws_close_reason() */ -#define LWS_WRITE_CLOSE 4 - -#define ALREADY_PROCESSED_IGNORE_CHAR 1 -#define ALREADY_PROCESSED_NO_CB 2 - -#if !defined(LWS_WITHOUT_EXTENSIONS) -struct lws_vhost_role_ws { - const struct lws_extension *extensions; -}; - -struct lws_pt_role_ws { - struct lws *rx_draining_ext_list; - struct lws *tx_draining_ext_list; -}; -#endif - -struct _lws_websocket_related { - unsigned char *rx_ubuf; -#if !defined(LWS_WITHOUT_EXTENSIONS) - const struct lws_extension *active_extensions[LWS_MAX_EXTENSIONS_ACTIVE]; - void *act_ext_user[LWS_MAX_EXTENSIONS_ACTIVE]; - struct lws *rx_draining_ext_list; - struct lws *tx_draining_ext_list; -#endif - -#if defined(LWS_WITH_HTTP_PROXY) - struct lws_dll2_owner proxy_owner; - char actual_protocol[16]; - size_t proxy_buffered; -#endif - - /* Also used for close content... control opcode == < 128 */ - uint8_t ping_payload_buf[128 - 3 + LWS_PRE]; - uint8_t mask[4]; - - size_t rx_packet_length; - uint32_t rx_ubuf_head; - uint32_t rx_ubuf_alloc; - - uint8_t ping_payload_len; - uint8_t mask_idx; - uint8_t opcode; - uint8_t rsv; - uint8_t rsv_first_msg; - /* zero if no info, or length including 2-byte close code */ - uint8_t close_in_ping_buffer_len; - uint8_t utf8; - uint8_t stashed_write_type; - uint8_t tx_draining_stashed_wp; - uint8_t ietf_spec_revision; - - unsigned int final:1; - unsigned int frame_is_binary:1; - unsigned int all_zero_nonce:1; - unsigned int this_frame_masked:1; - unsigned int inside_frame:1; /* next write will be more of frame */ - unsigned int clean_buffer:1; /* buffer not rewritten by extension */ - unsigned int payload_is_close:1; /* process as PONG, but it is close */ - unsigned int ping_pending_flag:1; - unsigned int continuation_possible:1; - unsigned int owed_a_fin:1; - unsigned int check_utf8:1; - unsigned int defeat_check_utf8:1; - unsigned int stashed_write_pending:1; - unsigned int send_check_ping:1; - unsigned int first_fragment:1; - unsigned int peer_has_sent_close:1; - unsigned int await_pong; -#if !defined(LWS_WITHOUT_EXTENSIONS) - unsigned int extension_data_pending:1; - unsigned int rx_draining_ext:1; - unsigned int tx_draining_ext:1; - unsigned int pmd_trailer_application:1; - - uint8_t count_act_ext; -#endif -}; - -/* - * we need to separately track what's happening with both compressed rx in - * and with inflated rx out that will be passed to the user code - */ - -struct lws_ext_pm_deflate_rx_ebufs { - struct lws_tokens eb_in; - struct lws_tokens eb_out; -}; - -int -lws_ws_handshake_client(struct lws *wsi, unsigned char **buf, size_t len); - -#if !defined(LWS_WITHOUT_EXTENSIONS) -LWS_VISIBLE void -lws_context_init_extensions(const struct lws_context_creation_info *info, - struct lws_context *context); -LWS_EXTERN int -lws_any_extension_handled(struct lws *wsi, enum lws_extension_callback_reasons r, - void *v, size_t len); - -LWS_EXTERN int -lws_ext_cb_active(struct lws *wsi, int reason, void *buf, int len); -LWS_EXTERN int -lws_ext_cb_all_exts(struct lws_context *context, struct lws *wsi, int reason, - void *arg, int len); -#endif - -int -handshake_0405(struct lws_context *context, struct lws *wsi); -int -lws_process_ws_upgrade(struct lws *wsi); - -int -lws_process_ws_upgrade2(struct lws *wsi); - -extern const struct lws_protocols lws_ws_proxy; - -int -lws_server_init_wsi_for_ws(struct lws *wsi); - -void -lws_sul_wsping_cb(lws_sorted_usec_list_t *sul); diff -Nru libwebsockets-3.2.1/lib/roles/ws/private-lib-roles-ws.h libwebsockets-4.1.6/lib/roles/ws/private-lib-roles-ws.h --- libwebsockets-3.2.1/lib/roles/ws/private-lib-roles-ws.h 1970-01-01 00:00:00.000000000 +0000 +++ libwebsockets-4.1.6/lib/roles/ws/private-lib-roles-ws.h 2020-12-01 17:40:26.000000000 +0000 @@ -0,0 +1,195 @@ + /* + * libwebsockets - small server side websockets and web server implementation + * + * Copyright (C) 2010 - 2019 Andy Green + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to + * deal in the Software without restriction, including without limitation the + * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or + * sell copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS + * IN THE SOFTWARE. + * + * This is included from private-lib-core.h if LWS_ROLE_WS + */ + +extern const struct lws_role_ops role_ops_ws; + +#define lwsi_role_ws(wsi) (wsi->role_ops == &role_ops_ws) + +enum lws_rx_parse_state { + LWS_RXPS_NEW, + + LWS_RXPS_04_mask_1, + LWS_RXPS_04_mask_2, + LWS_RXPS_04_mask_3, + + LWS_RXPS_04_FRAME_HDR_1, + LWS_RXPS_04_FRAME_HDR_LEN, + LWS_RXPS_04_FRAME_HDR_LEN16_2, + LWS_RXPS_04_FRAME_HDR_LEN16_1, + LWS_RXPS_04_FRAME_HDR_LEN64_8, + LWS_RXPS_04_FRAME_HDR_LEN64_7, + LWS_RXPS_04_FRAME_HDR_LEN64_6, + LWS_RXPS_04_FRAME_HDR_LEN64_5, + LWS_RXPS_04_FRAME_HDR_LEN64_4, + LWS_RXPS_04_FRAME_HDR_LEN64_3, + LWS_RXPS_04_FRAME_HDR_LEN64_2, + LWS_RXPS_04_FRAME_HDR_LEN64_1, + + LWS_RXPS_07_COLLECT_FRAME_KEY_1, + LWS_RXPS_07_COLLECT_FRAME_KEY_2, + LWS_RXPS_07_COLLECT_FRAME_KEY_3, + LWS_RXPS_07_COLLECT_FRAME_KEY_4, + + LWS_RXPS_WS_FRAME_PAYLOAD +}; + +enum lws_websocket_opcodes_07 { + LWSWSOPC_CONTINUATION = 0, + LWSWSOPC_TEXT_FRAME = 1, + LWSWSOPC_BINARY_FRAME = 2, + + LWSWSOPC_NOSPEC__MUX = 7, + + /* control extensions 8+ */ + + LWSWSOPC_CLOSE = 8, + LWSWSOPC_PING = 9, + LWSWSOPC_PONG = 0xa, +}; + +/* this is not usable directly by user code any more, lws_close_reason() */ +#define LWS_WRITE_CLOSE 4 + +#define ALREADY_PROCESSED_IGNORE_CHAR 1 +#define ALREADY_PROCESSED_NO_CB 2 + +#if !defined(LWS_WITHOUT_EXTENSIONS) +struct lws_vhost_role_ws { + const struct lws_extension *extensions; +}; + +struct lws_pt_role_ws { + struct lws *rx_draining_ext_list; + struct lws *tx_draining_ext_list; +}; +#endif + +struct _lws_websocket_related { + unsigned char *rx_ubuf; +#if !defined(LWS_WITHOUT_EXTENSIONS) + const struct lws_extension *active_extensions[LWS_MAX_EXTENSIONS_ACTIVE]; + void *act_ext_user[LWS_MAX_EXTENSIONS_ACTIVE]; + struct lws *rx_draining_ext_list; + struct lws *tx_draining_ext_list; +#endif + +#if defined(LWS_WITH_HTTP_PROXY) + struct lws_dll2_owner proxy_owner; + char actual_protocol[16]; + size_t proxy_buffered; +#endif + + /* Also used for close content... control opcode == < 128 */ + uint8_t ping_payload_buf[128 - 3 + LWS_PRE]; + + unsigned int final:1; + unsigned int frame_is_binary:1; + unsigned int all_zero_nonce:1; + unsigned int this_frame_masked:1; + unsigned int inside_frame:1; /* next write will be more of frame */ + unsigned int clean_buffer:1; /* buffer not rewritten by extension */ + unsigned int payload_is_close:1; /* process as PONG, but it is close */ + unsigned int ping_pending_flag:1; + unsigned int continuation_possible:1; + unsigned int owed_a_fin:1; + unsigned int check_utf8:1; + unsigned int defeat_check_utf8:1; + unsigned int stashed_write_pending:1; + unsigned int send_check_ping:1; + unsigned int first_fragment:1; + unsigned int peer_has_sent_close:1; +#if !defined(LWS_WITHOUT_EXTENSIONS) + unsigned int extension_data_pending:1; + unsigned int rx_draining_ext:1; + unsigned int tx_draining_ext:1; + unsigned int pmd_trailer_application:1; +#endif + + uint8_t mask[4]; + + size_t rx_packet_length; + uint32_t rx_ubuf_head; + uint32_t rx_ubuf_alloc; + + uint8_t ping_payload_len; + uint8_t mask_idx; + uint8_t opcode; + uint8_t rsv; + uint8_t rsv_first_msg; + /* zero if no info, or length including 2-byte close code */ + uint8_t close_in_ping_buffer_len; + uint8_t utf8; + uint8_t stashed_write_type; + uint8_t tx_draining_stashed_wp; + uint8_t ietf_spec_revision; +#if !defined(LWS_WITHOUT_EXTENSIONS) + uint8_t count_act_ext; +#endif +}; + +/* + * we need to separately track what's happening with both compressed rx in + * and with inflated rx out that will be passed to the user code + */ + +struct lws_ext_pm_deflate_rx_ebufs { + struct lws_tokens eb_in; + struct lws_tokens eb_out; +}; + +int +lws_ws_handshake_client(struct lws *wsi, unsigned char **buf, size_t len); + +#if !defined(LWS_WITHOUT_EXTENSIONS) +LWS_VISIBLE void +lws_context_init_extensions(const struct lws_context_creation_info *info, + struct lws_context *context); +LWS_EXTERN int +lws_any_extension_handled(struct lws *wsi, enum lws_extension_callback_reasons r, + void *v, size_t len); + +LWS_EXTERN int +lws_ext_cb_active(struct lws *wsi, int reason, void *buf, int len); +LWS_EXTERN int +lws_ext_cb_all_exts(struct lws_context *context, struct lws *wsi, int reason, + void *arg, int len); +#endif + +int +handshake_0405(struct lws_context *context, struct lws *wsi); +int +lws_process_ws_upgrade(struct lws *wsi); + +int +lws_process_ws_upgrade2(struct lws *wsi); + +extern const struct lws_protocols lws_ws_proxy; + +int +lws_server_init_wsi_for_ws(struct lws *wsi); + +void +lws_sul_wsping_cb(lws_sorted_usec_list_t *sul); diff -Nru libwebsockets-3.2.1/lib/roles/ws/server-ws.c libwebsockets-4.1.6/lib/roles/ws/server-ws.c --- libwebsockets-3.2.1/lib/roles/ws/server-ws.c 2019-12-18 14:45:31.000000000 +0000 +++ libwebsockets-4.1.6/lib/roles/ws/server-ws.c 2020-12-01 17:40:26.000000000 +0000 @@ -1,25 +1,28 @@ /* * libwebsockets - small server side websockets and web server implementation * - * Copyright (C) 2010-2018 Andy Green + * Copyright (C) 2010 - 2019 Andy Green * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation: - * version 2.1 of the License. + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to + * deal in the Software without restriction, including without limitation the + * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or + * sell copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: * - * This library is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. * - * You should have received a copy of the GNU Lesser General Public - * License along with this library; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, - * MA 02110-1301 USA + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS + * IN THE SOFTWARE. */ -#include +#include #define LWS_CPYAPP(ptr, str) { strcpy(ptr, str); ptr += strlen(str); } @@ -27,7 +30,7 @@ static int lws_extension_server_handshake(struct lws *wsi, char **p, int budget) { - struct lws_context *context = wsi->context; + struct lws_context *context = wsi->a.context; struct lws_context_per_thread *pt = &context->pt[(int)wsi->tsi]; char ext_name[64], *args, *end = (*p) + budget - 1; const struct lws_ext_options *opts, *po; @@ -109,7 +112,7 @@ /* check a client's extension against our support */ - ext = wsi->vhost->ws.extensions; + ext = wsi->a.vhost->ws.extensions; while (ext && ext->callback) { @@ -132,7 +135,7 @@ * ask user code if it's OK to apply it on this * particular connection + protocol */ - m = (wsi->protocol->callback)(wsi, + m = (wsi->a.protocol->callback)(wsi, LWS_CALLBACK_CONFIRM_EXTENSION_OKAY, wsi->user_space, ext_name, 0); @@ -251,10 +254,12 @@ int lws_process_ws_upgrade2(struct lws *wsi) { - struct lws_context_per_thread *pt = &wsi->context->pt[(int)wsi->tsi]; + struct lws_context_per_thread *pt = &wsi->a.context->pt[(int)wsi->tsi]; +#if defined(LWS_WITH_HTTP_BASIC_AUTH) const struct lws_protocol_vhost_options *pvos = NULL; const char *ws_prot_basic_auth = NULL; + /* * Allow basic auth a look-in now we bound the wsi to the protocol. * @@ -263,12 +268,13 @@ * section, as a pvo. */ - pvos = lws_vhost_protocol_options(wsi->vhost, wsi->protocol->name); + pvos = lws_vhost_protocol_options(wsi->a.vhost, wsi->a.protocol->name); if (pvos && pvos->options && !lws_pvo_get_str((void *)pvos->options, "basic-auth", &ws_prot_basic_auth)) { lwsl_info("%s: ws upgrade requires basic auth\n", __func__); - switch(lws_check_basic_auth(wsi, ws_prot_basic_auth)) { + switch (lws_check_basic_auth(wsi, ws_prot_basic_auth, LWSAUTHM_DEFAULT + /* no callback based auth here */)) { case LCBA_CONTINUE: break; case LCBA_FAILED_AUTH: @@ -278,6 +284,7 @@ return lws_http_transaction_completed(wsi); } } +#endif /* * We are upgrading to ws, so http/1.1 + h2 and keepalive + pipelined @@ -290,10 +297,37 @@ lws_pt_lock(pt, __func__); - if (!wsi->h2_stream_carries_ws) + /* + * Switch roles if we're upgrading away from http + */ + + if (!wsi->h2_stream_carries_ws) { lws_role_transition(wsi, LWSIFR_SERVER, LRS_ESTABLISHED, &role_ops_ws); +#if defined(LWS_WITH_SECURE_STREAMS) && defined(LWS_WITH_SERVER) + + /* + * If we're a SS server object, we have to switch to ss-ws + * protocol handler too + */ + if (wsi->a.vhost->ss_handle) { + lwsl_info("%s: Server SS %p switching to ws protocol\n", + __func__, wsi->a.vhost->ss_handle); + wsi->a.protocol = &protocol_secstream_ws; + + /* + * inform the SS user code that this has done a one-way + * upgrade to some other protocol... it will likely + * want to treat subsequent payloads differently + */ + + (void)lws_ss_event_helper(wsi->a.vhost->ss_handle, + LWSSSCS_SERVER_UPGRADE); + } +#endif + } + lws_pt_unlock(pt); /* allocate the ws struct for the wsi */ @@ -318,7 +352,7 @@ * Give the user code a chance to study the request and * have the opportunity to deny it */ - if ((wsi->protocol->callback)(wsi, + if ((wsi->a.protocol->callback)(wsi, LWS_CALLBACK_FILTER_PROTOCOL_CONNECTION, wsi->user_space, lws_hdr_simple_ptr(wsi, WSI_TOKEN_PROTOCOL), 0)) { @@ -348,11 +382,19 @@ lws_role_transition(wsi, LWSIFR_SERVER | LWSIFR_P_ENCAP_H2, LRS_ESTABLISHED, &role_ops_ws); + + /* + * There should be no validity checking since we + * are encapsulated in something else with its own + * validity checking + */ + + lws_sul_cancel(&wsi->sul_validity); } else #endif { lwsl_parser("lws_parse calling handshake_04\n"); - if (handshake_0405(wsi->context, wsi)) { + if (handshake_0405(wsi->a.context, wsi)) { lwsl_notice("hs0405 has failed the connection\n"); return 1; } @@ -360,22 +402,28 @@ break; } - lws_server_init_wsi_for_ws(wsi); + if (lws_server_init_wsi_for_ws(wsi)) { + lwsl_notice("%s: user ESTABLISHED failed connection\n", __func__); + return 1; + } lwsl_parser("accepted v%02d connection\n", wsi->ws->ietf_spec_revision); #if defined(LWS_WITH_ACCESS_LOG) { - char *uptr = NULL, combo[128]; - int l, meth = lws_http_get_uri_and_method(wsi, &uptr, &l); + char *uptr = "unknown method", combo[128], dotstar[64]; + int l = 14, meth = lws_http_get_uri_and_method(wsi, &uptr, &l); if (wsi->h2_stream_carries_ws) wsi->http.request_version = HTTP_VERSION_2; wsi->http.access_log.response = 101; - l = lws_snprintf(combo, sizeof(combo), "%.*s (%s)", l, uptr, - wsi->protocol->name); + lws_strnncpy(dotstar, uptr, l, sizeof(dotstar)); + l = lws_snprintf(combo, sizeof(combo), "%s (%s)", dotstar, + wsi->a.protocol->name); + if (meth < 0) + meth = 0; lws_prepare_access_log_info(wsi, combo, l, meth); lws_access_log(wsi); } @@ -394,8 +442,9 @@ char buf[128], name[64]; struct lws_tokenize ts; lws_tokenize_elem e; + int n; - if (!wsi->protocol) + if (!wsi->a.protocol) lwsl_err("NULL protocol at lws_read\n"); /* @@ -406,17 +455,17 @@ */ #if defined(LWS_WITH_HTTP2) - if (!wsi->http2_substream) { + if (!wsi->mux_substream) { #endif lws_tokenize_init(&ts, buf, LWS_TOKENIZE_F_COMMA_SEP_LIST | LWS_TOKENIZE_F_DOT_NONTERM | LWS_TOKENIZE_F_RFC7230_DELIMS | LWS_TOKENIZE_F_MINUS_NONTERM); - ts.len = lws_hdr_copy(wsi, buf, sizeof(buf) - 1, - WSI_TOKEN_CONNECTION); - if (ts.len <= 0) + n = lws_hdr_copy(wsi, buf, sizeof(buf) - 1, WSI_TOKEN_CONNECTION); + if (n <= 0) goto bad_conn_format; + ts.len = n; do { e = lws_tokenize(&ts); @@ -451,7 +500,9 @@ meth = lws_http_get_uri_and_method(wsi, &uri_ptr, &uri_len); hit = lws_find_mount(wsi, uri_ptr, uri_len); - if (hit && (meth == 0 || meth == 8) && + if (hit && (meth == LWSHUMETH_GET || + meth == LWSHUMETH_CONNECT || + meth == LWSHUMETH_COLON_PATH) && (hit->origin_protocol == LWSMPRO_HTTPS || hit->origin_protocol == LWSMPRO_HTTP)) /* @@ -478,13 +529,14 @@ LWS_TOKENIZE_F_MINUS_NONTERM | LWS_TOKENIZE_F_DOT_NONTERM | LWS_TOKENIZE_F_RFC7230_DELIMS); - ts.len = lws_hdr_copy(wsi, buf, sizeof(buf) - 1, WSI_TOKEN_PROTOCOL); - if (ts.len < 0) { + n = lws_hdr_copy(wsi, buf, sizeof(buf) - 1, WSI_TOKEN_PROTOCOL); + if (n < 0) { lwsl_err("%s: protocol list too long\n", __func__); return 1; } + ts.len = n; if (!ts.len) { - int n = wsi->vhost->default_protocol_index; + int n = wsi->a.vhost->default_protocol_index; /* * Some clients only have one protocol and do not send the * protocol list header... allow it and match to the vhost's @@ -495,7 +547,7 @@ * these "no protocol" ws connections to be rejected. */ - if (n >= wsi->vhost->count_protocols) { + if (n >= wsi->a.vhost->count_protocols) { lwsl_notice("%s: rejecting ws upg with no protocol\n", __func__); @@ -504,12 +556,39 @@ lwsl_info("%s: defaulting to prot handler %d\n", __func__, n); - lws_bind_protocol(wsi, &wsi->vhost->protocols[n], + lws_bind_protocol(wsi, &wsi->a.vhost->protocols[n], "ws upgrade default pcol"); goto alloc_ws; } +#if defined(LWS_WITH_SECURE_STREAMS) && defined(LWS_WITH_SERVER) + if (wsi->a.vhost->ss_handle) { + lws_ss_handle_t *sssh = wsi->a.vhost->ss_handle; + + /* + * At the moment, once we see it's a ss ws server, whatever + * he asked for we bind him to the ss-ws protocol handler. + * + * In the response subprotocol header, we need to name + * + * sssh->policy->u.http.u.ws.subprotocol + * + * though... + */ + + if (sssh->policy->u.http.u.ws.subprotocol) { + pcol = lws_vhost_name_to_protocol(wsi->a.vhost, + "lws-secstream-ws"); + if (pcol) { + lws_bind_protocol(wsi, pcol, "ss ws upg pcol"); + + goto alloc_ws; + } + } + } +#endif + /* otherwise go through the user-provided protocol list */ do { @@ -523,7 +602,7 @@ return 1; } lwsl_debug("checking %s\n", name); - pcol = lws_vhost_name_to_protocol(wsi->vhost, name); + pcol = lws_vhost_name_to_protocol(wsi->a.vhost, name); if (pcol) { /* if we know it, bind to it and stop looking */ lws_bind_protocol(wsi, pcol, "ws upg pcol"); @@ -617,15 +696,36 @@ * - one came in, and ... */ if (lws_hdr_total_length(wsi, WSI_TOKEN_PROTOCOL) && /* - it is not an empty string */ - wsi->protocol->name && - wsi->protocol->name[0]) { - const char *prot = wsi->protocol->name; + wsi->a.protocol->name && + wsi->a.protocol->name[0]) { + const char *prot = wsi->a.protocol->name; #if defined(LWS_WITH_HTTP_PROXY) if (wsi->proxied_ws_parent && wsi->child_list) prot = wsi->child_list->ws->actual_protocol; #endif +#if defined(LWS_WITH_SECURE_STREAMS) && defined(LWS_WITH_SERVER) + { + lws_ss_handle_t *sssh = wsi->a.vhost->ss_handle; + + /* + * At the moment, once we see it's a ss ws server, whatever + * he asked for we bind him to the ss-ws protocol handler. + * + * In the response subprotocol header, we need to name + * + * sssh->policy->u.http.u.ws.subprotocol + * + * though... + */ + + if (sssh && sssh->policy && + sssh->policy->u.http.u.ws.subprotocol) + prot = sssh->policy->u.http.u.ws.subprotocol; + } +#endif + LWS_CPYAPP(p, "\x0d\x0aSec-WebSocket-Protocol: "); p += lws_snprintf(p, 128, "%s", prot); } @@ -645,7 +745,7 @@ args.p = p; args.max_len = lws_ptr_diff((char *)pt->serv_buf + context->pt_serv_buf_size, p); - if (user_callback_handle_rxflow(wsi->protocol->callback, wsi, + if (user_callback_handle_rxflow(wsi->a.protocol->callback, wsi, LWS_CALLBACK_ADD_HEADERS, wsi->user_space, &args, 0)) goto bail; @@ -682,7 +782,7 @@ const struct lws_http_mount *hit = lws_find_mount(wsi, uri_ptr, uri_len); if (hit && hit->cgienv && - wsi->protocol->callback(wsi, LWS_CALLBACK_HTTP_PMO, + wsi->a.protocol->callback(wsi, LWS_CALLBACK_HTTP_PMO, wsi->user_space, (void *)hit->cgienv, 0)) return 1; } @@ -724,10 +824,10 @@ if (!wsi->ws->count_act_ext) #endif { - if (wsi->protocol->rx_buffer_size) - avail = (int)wsi->protocol->rx_buffer_size; + if (wsi->a.protocol->rx_buffer_size) + avail = (int)wsi->a.protocol->rx_buffer_size; else - avail = wsi->context->pt_serv_buf_size; + avail = wsi->a.context->pt_serv_buf_size; } /* do not consume more than we should */ @@ -814,12 +914,12 @@ old_packet_length && /* we gave the inflator new input */ !wsi->ws->rx_packet_length && /* raw ws packet payload all gone */ wsi->ws->final && /* the raw ws packet is a FIN guy */ - wsi->protocol->callback && + wsi->a.protocol->callback && !wsi->wsistate_pre_close) { lwsl_ext("%s: issuing zero length FIN pkt\n", __func__); - if (user_callback_handle_rxflow(wsi->protocol->callback, wsi, + if (user_callback_handle_rxflow(wsi->a.protocol->callback, wsi, LWS_CALLBACK_RECEIVE, wsi->user_space, NULL, 0)) return -1; @@ -866,8 +966,8 @@ } } - if (wsi->protocol->callback && !wsi->wsistate_pre_close) - if (user_callback_handle_rxflow(wsi->protocol->callback, wsi, + if (wsi->a.protocol->callback && !wsi->wsistate_pre_close) + if (user_callback_handle_rxflow(wsi->a.protocol->callback, wsi, LWS_CALLBACK_RECEIVE, wsi->user_space, pmdrx.eb_out.token, @@ -920,7 +1020,6 @@ * We dealt with it by trimming the existing * rxflow cache HEAD to account for what we used. * - * indicate we didn't use anything to the caller * so he doesn't do any consumed processing */ lwsl_info("%s: trimming inside rxflow cache\n", diff -Nru libwebsockets-3.2.1/lib/secure-streams/CMakeLists.txt libwebsockets-4.1.6/lib/secure-streams/CMakeLists.txt --- libwebsockets-3.2.1/lib/secure-streams/CMakeLists.txt 1970-01-01 00:00:00.000000000 +0000 +++ libwebsockets-4.1.6/lib/secure-streams/CMakeLists.txt 2020-12-01 17:40:26.000000000 +0000 @@ -0,0 +1,133 @@ +# +# libwebsockets - small server side websockets and web server implementation +# +# Copyright (C) 2010 - 2020 Andy Green +# +# Permission is hereby granted, free of charge, to any person obtaining a copy +# of this software and associated documentation files (the "Software"), to +# deal in the Software without restriction, including without limitation the +# rights to use, copy, modify, merge, publish, distribute, sublicense, and/or +# sell copies of the Software, and to permit persons to whom the Software is +# furnished to do so, subject to the following conditions: +# +# The above copyright notice and this permission notice shall be included in +# all copies or substantial portions of the Software. +# +# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING +# FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS +# IN THE SOFTWARE. +# + +include_directories(.) + +if (LWS_WITH_CLIENT) + list(APPEND SOURCES + secure-streams/secure-streams.c + secure-streams/policy-common.c + secure-streams/system/captive-portal-detect/captive-portal-detect.c + secure-streams/protocols/ss-raw.c + ) + if (NOT LWS_WITH_SECURE_STREAMS_STATIC_POLICY_ONLY) + list(APPEND SOURCES + secure-streams/policy-json.c + secure-streams/system/fetch-policy/fetch-policy.c + ) + endif() + if (LWS_ROLE_H1) + list(APPEND SOURCES + secure-streams/protocols/ss-h1.c + ) + endif() + if (LWS_ROLE_H2) + list(APPEND SOURCES + secure-streams/protocols/ss-h2.c + ) + endif() + if (LWS_ROLE_WS) + list(APPEND SOURCES + secure-streams/protocols/ss-ws.c + ) + endif() + if (LWS_ROLE_MQTT) + list(APPEND SOURCES + secure-streams/protocols/ss-mqtt.c + ) + endif() + + if (LWS_WITH_SECURE_STREAMS_PROXY_API) + list(APPEND SOURCES + secure-streams/secure-streams-serialize.c + secure-streams/secure-streams-client.c + ) + endif() + + if (LWS_WITH_SECURE_STREAMS_PROXY_API) + list(APPEND SOURCES + secure-streams/secure-streams-process.c + ) + endif() + + if (LWS_WITH_SECURE_STREAMS_SYS_AUTH_API_AMAZON_COM AND + LWS_WITH_SYS_STATE) + list(APPEND SOURCES + secure-streams/system/auth-api.amazon.com/auth.c + ) + endif() + + + # + # Helper function for adding a secure stream plugin + # + macro(create_ss_plugin NAME S2 S3 S4 S5 S6) + + set(SSP_SRCS) + set(SSP_PUBLIC_HDR) + set(SSP_HDR) + + if ("${S2}" STREQUAL "") + else() + list(APPEND SSP_SRCS plugins/${NAME}/${S2}) + endif() + if ("${S3}" STREQUAL "") + else() + list(APPEND SSP_SRCS plugins/${NAME}/${S3}) + endif() + if ("${S4}" STREQUAL "") + else() + list(APPEND SSP_SRCS plugins/${NAME}/${S4}) + endif() + if ("${S5}" STREQUAL "") + else() + list(APPEND SSP_SRCS plugins/${NAME}/${S5}) + endif() + if ("${S6}" STREQUAL "") + else() + list(APPEND SSP_SRCS plugins/${NAME}/${S6}) + endif() + + source_group("Headers Private" FILES ${SSP_HDR}) + source_group("Sources" FILES ${SSP_SRCS}) + + add_library( ${NAME} STATIC + ${SSP_HDR} ${SSP_PUBLIC_HDR} ${SSP_SRCS} ) + + target_include_directories(${NAME} PRIVATE "${LWS_LIB_INCLUDES}" ${LWS_LIB_BUILD_INC_PATHS}) + + if (NOT LWS_PLAT_FREERTOS) + add_dependencies(${NAME} websockets_shared) + endif() + list(APPEND SS_PLUGINS_LIST ${NAME}) + endmacro() + + # create_ss_plugin(ssp-h1url "h1url.c" "" "" "" "") +endif() + +# +# Keep explicit parent scope exports at end +# + +exports_to_parent_scope() diff -Nru libwebsockets-3.2.1/lib/secure-streams/plugins/ssp-h1url/h1url.c libwebsockets-4.1.6/lib/secure-streams/plugins/ssp-h1url/h1url.c --- libwebsockets-3.2.1/lib/secure-streams/plugins/ssp-h1url/h1url.c 1970-01-01 00:00:00.000000000 +0000 +++ libwebsockets-4.1.6/lib/secure-streams/plugins/ssp-h1url/h1url.c 2020-12-01 17:40:26.000000000 +0000 @@ -0,0 +1,40 @@ +/* + * ssp-h1url plugin + * + * Written in 2010-2020 by Andy Green + * + * This file is made available under the Creative Commons CC0 1.0 + * Universal Public Domain Dedication. + * + * CC0 so it can be used as a template for your own secure streams plugins + * licensed how you like. + */ + +#include + +static int +ssp_h1url_create(struct lws_ss_handle *ss, void *info, plugin_auth_status_cb status) +{ + return 0; +} + +static int +ssp_h1url_destroy(struct lws_ss_handle *ss) +{ + return 0; +} + +static int +ssp_h1url_munge(struct lws_ss_handle *ss, char *path, size_t path_len) +{ + return 0; +} + +/* this is the only exported symbol */ +const lws_ss_plugin_t ssp_h1url = { + .name = "h1url", + .alloc = 0, + .create = ssp_h1url_create, + .destroy = ssp_h1url_destroy, + .munge = ssp_h1url_munge +}; diff -Nru libwebsockets-3.2.1/lib/secure-streams/policy-common.c libwebsockets-4.1.6/lib/secure-streams/policy-common.c --- libwebsockets-3.2.1/lib/secure-streams/policy-common.c 1970-01-01 00:00:00.000000000 +0000 +++ libwebsockets-4.1.6/lib/secure-streams/policy-common.c 2020-12-01 17:40:26.000000000 +0000 @@ -0,0 +1,388 @@ +/* + * libwebsockets - small server side websockets and web server implementation + * + * Copyright (C) 2019 - 2020 Andy Green + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to + * deal in the Software without restriction, including without limitation the + * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or + * sell copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS + * IN THE SOFTWARE. + * + * This file contains the stuff related to secure streams policy, it's always + * built if LWS_WITH_SECURE_STREAMS enabled. + */ + +#include + +#if defined(LWS_WITH_SYS_SMD) +const lws_ss_policy_t pol_smd = { + .flags = 0, /* have to set something for windows */ +}; +#endif + +const lws_ss_policy_t * +lws_ss_policy_lookup(const struct lws_context *context, const char *streamtype) +{ + const lws_ss_policy_t *p = context->pss_policies; + + if (!streamtype) + return NULL; + +#if defined(LWS_WITH_SYS_SMD) + if (!strcmp(streamtype, LWS_SMD_STREAMTYPENAME)) + return &pol_smd; +#endif + + while (p) { + if (!strcmp(p->streamtype, streamtype)) + return p; + p = p->next; + } + + return NULL; +} + +int +lws_ss_set_metadata(struct lws_ss_handle *h, const char *name, + const void *value, size_t len) +{ + lws_ss_metadata_t *omd = lws_ss_policy_metadata(h->policy, name); + + if (!omd) { + lwsl_info("%s: unknown metadata %s\n", __func__, name); + return 1; + } + + h->metadata[omd->length].name = name; + h->metadata[omd->length].value = (void *)value; + h->metadata[omd->length].length = len; + + return 0; +} + +lws_ss_metadata_t * +lws_ss_get_handle_metadata(struct lws_ss_handle *h, const char *name) +{ + lws_ss_metadata_t *omd = lws_ss_policy_metadata(h->policy, name); + + if (!omd) + return NULL; + + return &h->metadata[omd->length]; +} + +lws_ss_metadata_t * +lws_ss_policy_metadata(const lws_ss_policy_t *p, const char *name) +{ + lws_ss_metadata_t *pmd = p->metadata; + + while (pmd) { + if (pmd->name && !strcmp(name, pmd->name)) + return pmd; + pmd = pmd->next; + } + + return NULL; +} + +lws_ss_metadata_t * +lws_ss_policy_metadata_index(const lws_ss_policy_t *p, size_t index) +{ + lws_ss_metadata_t *pmd = p->metadata; + + while (pmd) { + if (pmd->length == index) + return pmd; + pmd = pmd->next; + } + + return NULL; +} + +#if !defined(LWS_WITH_SECURE_STREAMS_STATIC_POLICY_ONLY) +static int +fe_lws_ss_destroy(struct lws_dll2 *d, void *user) +{ + lws_ss_handle_t *h = lws_container_of(d, lws_ss_handle_t, list); + + lws_ss_destroy(&h); + + return 0; +} +#endif + +/* + * Dynamic policy: we want to one-time create the vhost for the policy and the + * trust store behind it. + * + * Static policy: We want to make use of a trust store / vhost from the policy and add to its + * ss-refcount. + */ + +struct lws_vhost * +lws_ss_policy_ref_trust_store(struct lws_context *context, + const lws_ss_policy_t *pol, char doref) +{ + struct lws_context_creation_info i; + struct lws_vhost *v; + int n; + + memset(&i, 0, sizeof(i)); + + if (!pol->trust.store) { + v = lws_get_vhost_by_name(context, "_ss_default"); + if (!v) { + /* corner case... there's no trust store used */ + i.options = context->options; + i.vhost_name = "_ss_default"; + i.port = CONTEXT_PORT_NO_LISTEN; + v = lws_create_vhost(context, &i); + if (!v) { + lwsl_err("%s: failed to create vhost %s\n", + __func__, i.vhost_name); + + return NULL; + } + } + + goto accepted; + } + v = lws_get_vhost_by_name(context, pol->trust.store->name); + if (v) { + lwsl_debug("%s: vh already exists\n", __func__); + goto accepted; + } + + i.options = context->options; + i.vhost_name = pol->trust.store->name; + lwsl_debug("%s: %s\n", __func__, i.vhost_name); +#if defined(LWS_WITH_TLS) && defined(LWS_WITH_CLIENT) + i.client_ssl_ca_mem = pol->trust.store->ssx509[0]->ca_der; + i.client_ssl_ca_mem_len = (unsigned int) + pol->trust.store->ssx509[0]->ca_der_len; +#endif + i.port = CONTEXT_PORT_NO_LISTEN; + lwsl_info("%s: %s trust store initial '%s'\n", __func__, + i.vhost_name, pol->trust.store->ssx509[0]->vhost_name); + + v = lws_create_vhost(context, &i); + if (!v) { + lwsl_err("%s: failed to create vhost %s\n", + __func__, i.vhost_name); + return NULL; + } else + v->from_ss_policy = 1; + + for (n = 1; v && n < pol->trust.store->count; n++) { + lwsl_info("%s: add '%s' to trust store\n", __func__, + pol->trust.store->ssx509[n]->vhost_name); +#if defined(LWS_WITH_TLS) + if (lws_tls_client_vhost_extra_cert_mem(v, + pol->trust.store->ssx509[n]->ca_der, + pol->trust.store->ssx509[n]->ca_der_len)) { + lwsl_err("%s: add extra cert failed\n", + __func__); + return NULL; + } +#endif + } + +accepted: +#if defined(LWS_WITH_SECURE_STREAMS_STATIC_POLICY_ONLY) + if (doref) + v->ss_refcount++; +#endif + + return v; +} + +#if defined(LWS_WITH_SECURE_STREAMS_STATIC_POLICY_ONLY) +int +lws_ss_policy_unref_trust_store(struct lws_context *context, + const lws_ss_policy_t *pol) +{ + struct lws_vhost *v; + const char *name = "_ss_default"; + + if (pol->trust.store) + name = pol->trust.store->name; + + v = lws_get_vhost_by_name(context, name); + if (!v || !v->from_ss_policy) + return 0; + + assert(v->ss_refcount); + + v->ss_refcount--; + if (!v->ss_refcount) { + lwsl_notice("%s: destroying vh %s\n", __func__, name); + lws_vhost_destroy(v); + } + + return 1; +} +#endif + +int +lws_ss_policy_set(struct lws_context *context, const char *name) +{ + int ret = 0; + +#if !defined(LWS_WITH_SECURE_STREAMS_STATIC_POLICY_ONLY) + struct policy_cb_args *args = (struct policy_cb_args *)context->pol_args; + const lws_ss_policy_t *pol; + struct lws_vhost *v; + lws_ss_x509_t *x; + char buf[16]; + int m; + + /* + * Parsing seems to have succeeded, and we're going to use the new + * policy that's laid out in args->ac + */ + + lejp_destruct(&args->jctx); + + if (context->ac_policy) { + int n; + + /* + * any existing ss created with the old policy have to go away + * now, since they point to the shortly-to-be-destroyed old + * policy + */ + + for (n = 0; n < context->count_threads; n++) { + struct lws_context_per_thread *pt = &context->pt[n]; + + lws_dll2_foreach_safe(&pt->ss_owner, NULL, fe_lws_ss_destroy); + } + + /* + * So this is a bit fun-filled, we already had a policy in + * force, perhaps it was the default policy that's just good for + * fetching the real policy, and we're doing that now. + * + * We can destroy all the policy-related direct allocations + * easily because they're cleanly in a single lwsac... + */ + lwsac_free(&context->ac_policy); + + /* + * ...but when we did the trust stores, we created vhosts for + * each. We need to destroy those now too, and recreate new + * ones from the new policy, perhaps with different X.509s. + */ + + v = context->vhost_list; + while (v) { + if (v->from_ss_policy) { + struct lws_vhost *vh = v->vhost_next; + lwsl_debug("%s: destroying vh %p\n", __func__, v); + lws_vhost_destroy(v); + v = vh; + continue; + } + v = v->vhost_next; + } + + lws_check_deferred_free(context, 0, 1); + } + + context->pss_policies = args->heads[LTY_POLICY].p; + context->ac_policy = args->ac; + + lws_humanize(buf, sizeof(buf), lwsac_total_alloc(args->ac), + humanize_schema_si_bytes); + if (lwsac_total_alloc(args->ac)) + m = (int)((lwsac_total_overhead(args->ac) * 100) / + lwsac_total_alloc(args->ac)); + else + m = 0; + + (void)m; + lwsl_info("%s: %s, pad %d%c: %s\n", __func__, buf, m, '%', name); + + /* Create vhosts for each type of trust store */ + + /* + * We get called from context creation... instantiates + * vhosts with client tls contexts set up for each unique CA. + * + * We create the vhosts by walking streamtype list and create vhosts + * using trust store name if it's a client connection that doesn't + * already exist. + */ + + pol = context->pss_policies; + while (pol) { + if (!(pol->flags & LWSSSPOLF_SERVER)) { + v = lws_ss_policy_ref_trust_store(context, pol, + 0 /* no refcount inc */); + if (!v) + ret = 1; + } + + pol = pol->next; + } + +#if defined(LWS_WITH_SOCKS5) + + /* + * ... we need to go through every vhost updating its understanding of + * which socks5 proxy to use... + */ + + v = context->vhost_list; + while (v) { + lws_set_socks(v, args->socks5_proxy); + v = v->vhost_next; + } + if (context->vhost_system) + lws_set_socks(context->vhost_system, args->socks5_proxy); + + if (args->socks5_proxy) + lwsl_notice("%s: global socks5 proxy: %s\n", __func__, + args->socks5_proxy); +#endif + + /* + * For dynamic policy case, now we processed the x.509 CAs, we can free + * all of our originals. For static policy, they're in .rodata, nothing + * to free. + */ + + x = args->heads[LTY_X509].x; + while (x) { + /* + * Free all the client DER buffers now they have been parsed + * into tls library X.509 objects + */ + if (!x->keep) { /* used for server */ + lws_free((void *)x->ca_der); + x->ca_der = NULL; + } + + x = x->next; + } + + /* and we can discard the parsing args object now, invalidating args */ + + lws_free_set_NULL(context->pol_args); +#endif + + return ret; +} diff -Nru libwebsockets-3.2.1/lib/secure-streams/policy-json.c libwebsockets-4.1.6/lib/secure-streams/policy-json.c --- libwebsockets-3.2.1/lib/secure-streams/policy-json.c 1970-01-01 00:00:00.000000000 +0000 +++ libwebsockets-4.1.6/lib/secure-streams/policy-json.c 2020-12-01 17:40:26.000000000 +0000 @@ -0,0 +1,896 @@ +/* + * libwebsockets - small server side websockets and web server implementation + * + * Copyright (C) 2019 - 2020 Andy Green + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to + * deal in the Software without restriction, including without limitation the + * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or + * sell copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS + * IN THE SOFTWARE. + * + * This file contains the stuff related to JSON-provided policy, it's not built + * if LWS_WITH_SECURE_STREAMS_STATIC_POLICY_ONLY enabled. + */ + +#include + +static const char * const lejp_tokens_policy[] = { + "release", + "product", + "schema-version", + "via-socks5", + "retry[].*.backoff", + "retry[].*.conceal", + "retry[].*.jitterpc", + "retry[].*.svalidping", + "retry[].*.svalidhup", + "retry[].*", + "certs[].*", + "trust_stores[].name", + "trust_stores[].stack", + "s[].*.endpoint", + "s[].*.via-socks5", + "s[].*.protocol", + "s[].*.port", + "s[].*.plugins", + "s[].*.tls", + "s[].*.client_cert", + "s[].*.opportunistic", + "s[].*.nailed_up", + "s[].*.allow_redirects", + "s[].*.urgent_tx", + "s[].*.urgent_rx", + "s[].*.long_poll", + "s[].*.retry", + "s[].*.timeout_ms", + "s[].*.tls_trust_store", + "s[].*.metadata", + "s[].*.metadata[].*", + + "s[].*.http_auth_header", + "s[].*.http_dsn_header", + "s[].*.http_fwv_header", + "s[].*.http_devtype_header", + + "s[].*.http_auth_preamble", + + "s[].*.http_no_content_length", + "s[].*.rideshare", /* streamtype name this rides shotgun with */ + "s[].*.payload_fmt", + "s[].*.http_method", + "s[].*.http_url", + "s[].*.nghttp2_quirk_end_stream", + "s[].*.h2q_oflow_txcr", + "s[].*.http_multipart_name", + "s[].*.http_multipart_filename", + "s[].*.http_mime_content_type", + "s[].*.http_www_form_urlencoded", + "s[].*.http_expect", + "s[].*.http_fail_redirect", + "s[].*.http_multipart_ss_in", + "s[].*.ws_subprotocol", + "s[].*.ws_binary", + "s[].*.local_sink", + "s[].*.server", + "s[].*.server_cert", + "s[].*.server_key", + "s[].*.mqtt_topic", + "s[].*.mqtt_subscribe", + "s[].*.mqtt_qos", + "s[].*.mqtt_keep_alive", + "s[].*.mqtt_clean_start", + "s[].*.mqtt_will_topic", + "s[].*.mqtt_will_message", + "s[].*.mqtt_will_qos", + "s[].*.mqtt_will_retain", + "s[].*.swake_validity", + "s[].*", +}; + +typedef enum { + LSSPPT_RELEASE, + LSSPPT_PRODUCT, + LSSPPT_SCHEMA_VERSION, + LSSPPT_VIA_SOCKS5, + LSSPPT_BACKOFF, + LSSPPT_CONCEAL, + LSSPPT_JITTERPC, + LSSPPT_VALIDPING_S, + LSSPPT_VALIDHUP_S, + LSSPPT_RETRY, + LSSPPT_CERTS, + LSSPPT_TRUST_STORES_NAME, + LSSPPT_TRUST_STORES_STACK, + LSSPPT_ENDPOINT, + LSSPPT_VH_VIA_SOCKS5, + LSSPPT_PROTOCOL, + LSSPPT_PORT, + LSSPPT_PLUGINS, + LSSPPT_TLS, + LSSPPT_TLS_CLIENT_CERT, + LSSPPT_OPPORTUNISTIC, + LSSPPT_NAILED_UP, + LSSPPT_ALLOW_REDIRECTS, + LSSPPT_URGENT_TX, + LSSPPT_URGENT_RX, + LSSPPT_LONG_POLL, + LSSPPT_RETRYPTR, + LSSPPT_DEFAULT_TIMEOUT_MS, + LSSPPT_TRUST, + LSSPPT_METADATA, + LSSPPT_METADATA_ITEM, + + LSSPPT_HTTP_AUTH_HEADER, + LSSPPT_HTTP_DSN_HEADER, + LSSPPT_HTTP_FWV_HEADER, + LSSPPT_HTTP_TYPE_HEADER, + + LSSPPT_HTTP_AUTH_PREAMBLE, + LSSPPT_HTTP_NO_CONTENT_LENGTH, + LSSPPT_RIDESHARE, + LSSPPT_PAYLOAD_FORMAT, + LSSPPT_HTTP_METHOD, + LSSPPT_HTTP_URL, + LSSPPT_NGHTTP2_QUIRK_END_STREAM, + LSSPPT_H2_QUIRK_OVERFLOWS_TXCR, + LSSPPT_HTTP_MULTIPART_NAME, + LSSPPT_HTTP_MULTIPART_FILENAME, + LSSPPT_HTTP_MULTIPART_CONTENT_TYPE, + LSSPPT_HTTP_WWW_FORM_URLENCODED, + LSSPPT_HTTP_EXPECT, + LSSPPT_HTTP_FAIL_REDIRECT, + LSSPPT_HTTP_MULTIPART_SS_IN, + LSSPPT_WS_SUBPROTOCOL, + LSSPPT_WS_BINARY, + LSSPPT_LOCAL_SINK, + LSSPPT_SERVER, + LSSPPT_SERVER_CERT, + LSSPPT_SERVER_KEY, + LSSPPT_MQTT_TOPIC, + LSSPPT_MQTT_SUBSCRIBE, + LSSPPT_MQTT_QOS, + LSSPPT_MQTT_KEEPALIVE, + LSSPPT_MQTT_CLEAN_START, + LSSPPT_MQTT_WILL_TOPIC, + LSSPPT_MQTT_WILL_MESSAGE, + LSSPPT_MQTT_WILL_QOS, + LSSPPT_MQTT_WILL_RETAIN, + LSSPPT_SWAKE_VALIDITY, + LSSPPT_STREAMTYPES, + +} policy_token_t; + +#define POL_AC_INITIAL 2048 +#define POL_AC_GRAIN 800 +#define MAX_CERT_TEMP 3072 /* used to discover actual cert size for realloc */ + +static uint8_t sizes[] = { + sizeof(backoff_t), + sizeof(lws_ss_x509_t), + sizeof(lws_ss_trust_store_t), + sizeof(lws_ss_policy_t), +}; + +static const char *protonames[] = { + "h1", /* LWSSSP_H1 */ + "h2", /* LWSSSP_H2 */ + "ws", /* LWSSSP_WS */ + "mqtt", /* LWSSSP_MQTT */ + "raw", /* LWSSSP_RAW */ +}; + +static signed char +lws_ss_policy_parser_cb(struct lejp_ctx *ctx, char reason) +{ + struct policy_cb_args *a = (struct policy_cb_args *)ctx->user; +#if defined(LWS_WITH_SSPLUGINS) + const lws_ss_plugin_t **pin; +#endif + char **pp, dotstar[32], *q; + lws_ss_trust_store_t *ts; + lws_ss_metadata_t *pmd; + lws_ss_x509_t *x, **py; + lws_ss_policy_t *p2; + lws_retry_bo_t *b; + size_t inl, outl; + uint8_t *extant; + backoff_t *bot; + int n = -1; + + lwsl_debug("%s: %d %d %s\n", __func__, reason, ctx->path_match - 1, + ctx->path); + + switch (ctx->path_match - 1) { + case LSSPPT_RETRY: + n = LTY_BACKOFF; + break; + case LSSPPT_CERTS: + n = LTY_X509; + break; + case LSSPPT_TRUST_STORES_NAME: + case LSSPPT_TRUST_STORES_STACK: + n = LTY_TRUSTSTORE; + break; + case LSSPPT_STREAMTYPES: + n = LTY_POLICY; + break; + } + + if (reason == LEJPCB_ARRAY_START && + (ctx->path_match - 1 == LSSPPT_PLUGINS || + ctx->path_match - 1 == LSSPPT_METADATA)) + a->count = 0; + + if (reason == LEJPCB_ARRAY_END && + ctx->path_match - 1 == LSSPPT_TRUST_STORES_STACK && !a->count) { + lwsl_err("%s: at least one cert required in trust store\n", + __func__); + goto oom; + } + + if (reason == LEJPCB_OBJECT_END && a->p) { + /* + * Allocate a just-the-right-size buf for the cert DER now + * we decoded it into the a->p temp buffer and know the exact + * size. + * + * The struct *x is in the lwsac... the ca_der it points to + * is individually allocated from the heap + */ + a->curr[LTY_X509].x->ca_der = lws_malloc(a->count, "ssx509"); + if (!a->curr[LTY_X509].x->ca_der) + goto oom; + memcpy((uint8_t *)a->curr[LTY_X509].x->ca_der, a->p, a->count); + a->curr[LTY_X509].x->ca_der_len = a->count; + + /* + * ... and then we can free the temp buffer + */ + lws_free_set_NULL(a->p); + + return 0; + } + + if (reason == LEJPCB_PAIR_NAME && n != -1 && n != LTY_TRUSTSTORE) { + + p2 = NULL; + if (n == LTY_POLICY) { + /* + * We want to allow for the possibility of overlays... + * eg, we come later with a JSON snippet that overrides + * select streamtype members of a streamtype that was + * already defined + */ + p2 = (lws_ss_policy_t *)a->context->pss_policies; + + while (p2) { + if (!strncmp(p2->streamtype, + ctx->path + ctx->st[ctx->sp].p, + ctx->path_match_len - + ctx->st[ctx->sp].p)) { + lwsl_info("%s: overriding s[] %s\n", + __func__, p2->streamtype); + break; + } + + p2 = p2->next; + } + } + + /* + * We do the pointers always as .b union member, all of the + * participating structs begin with .next and .name the same + */ + if (p2) /* we may be overriding existing streamtype... */ + a->curr[n].b = (backoff_t *)p2; + else + a->curr[n].b = lwsac_use_zero(&a->ac, sizes[n], POL_AC_GRAIN); + if (!a->curr[n].b) + goto oom; + + if (n == LTY_X509) { + a->p = lws_malloc(MAX_CERT_TEMP, "cert temp"); + if (!a->p) + goto oom; + memset(&a->b64, 0, sizeof(a->b64)); + } + + a->count = 0; + if (!p2) { + a->curr[n].b->next = a->heads[n].b; + a->heads[n].b = a->curr[n].b; + pp = (char **)&a->curr[n].b->name; + + goto string1; + } + + return 0; /* overriding */ + } + + if (!(reason & LEJP_FLAG_CB_IS_VALUE) || !ctx->path_match) + return 0; + + switch (ctx->path_match - 1) { + + /* strings */ + + case LSSPPT_RELEASE: + break; + + case LSSPPT_PRODUCT: + break; + + case LSSPPT_SCHEMA_VERSION: + break; + + case LSSPPT_VIA_SOCKS5: + /* the global / default proxy */ + pp = (char **)&a->socks5_proxy; + goto string2; + + case LSSPPT_BACKOFF: + b = &a->curr[LTY_BACKOFF].b->r; + if (b->retry_ms_table_count == 8) { + lwsl_err("%s: > 8 backoff levels\n", __func__); + return 1; + } + if (!b->retry_ms_table_count) { + b->retry_ms_table = (uint32_t *)lwsac_use_zero(&a->ac, + sizeof(uint32_t) * 8, POL_AC_GRAIN); + if (!b->retry_ms_table) + goto oom; + } + + ((uint32_t *)b->retry_ms_table) + [b->retry_ms_table_count++] = atoi(ctx->buf); + break; + + case LSSPPT_CONCEAL: + a->curr[LTY_BACKOFF].b->r.conceal_count = atoi(ctx->buf); + break; + + case LSSPPT_JITTERPC: + a->curr[LTY_BACKOFF].b->r.jitter_percent = atoi(ctx->buf); + break; + + case LSSPPT_VALIDPING_S: + a->curr[LTY_BACKOFF].b->r.secs_since_valid_ping = atoi(ctx->buf); + break; + + case LSSPPT_VALIDHUP_S: + a->curr[LTY_BACKOFF].b->r.secs_since_valid_hangup = atoi(ctx->buf); + break; + + case LSSPPT_CERTS: + if (a->count + ctx->npos >= MAX_CERT_TEMP) { + lwsl_err("%s: cert too big\n", __func__); + goto oom; + } + inl = ctx->npos; + outl = MAX_CERT_TEMP - a->count; + + lws_b64_decode_stateful(&a->b64, ctx->buf, &inl, + a->p + a->count, &outl, + reason == LEJPCB_VAL_STR_END); + a->count += (int)outl; + if (inl != ctx->npos) { + lwsl_err("%s: b64 decode fail\n", __func__); + goto oom; + } + break; + + case LSSPPT_TRUST_STORES_NAME: + /* + * We do the pointers always as .b, all of the participating + * structs begin with .next and .name + */ + a->curr[LTY_TRUSTSTORE].b = lwsac_use_zero(&a->ac, + sizes[LTY_TRUSTSTORE], POL_AC_GRAIN); + if (!a->curr[LTY_TRUSTSTORE].b) + goto oom; + + a->count = 0; + a->curr[LTY_TRUSTSTORE].b->next = a->heads[LTY_TRUSTSTORE].b; + a->heads[LTY_TRUSTSTORE].b = a->curr[LTY_TRUSTSTORE].b; + pp = (char **)&a->curr[LTY_TRUSTSTORE].b->name; + + goto string2; + + case LSSPPT_TRUST_STORES_STACK: + if (a->count >= (int)LWS_ARRAY_SIZE( + a->curr[LTY_TRUSTSTORE].t->ssx509)) { + lwsl_err("%s: trust store too big\n", __func__); + goto oom; + } + lwsl_debug("%s: trust stores stack %.*s\n", __func__, + ctx->npos, ctx->buf); + x = a->heads[LTY_X509].x; + while (x) { + if (!strncmp(x->vhost_name, ctx->buf, ctx->npos)) { + a->curr[LTY_TRUSTSTORE].t->ssx509[a->count++] = x; + a->curr[LTY_TRUSTSTORE].t->count++; + + return 0; + } + x = x->next; + } + lws_strnncpy(dotstar, ctx->buf, ctx->npos, sizeof(dotstar)); + lwsl_err("%s: unknown trust store entry %s\n", __func__, + dotstar); + goto oom; + + case LSSPPT_SERVER_CERT: + case LSSPPT_SERVER_KEY: + + /* iterate through the certs */ + + py = &a->heads[LTY_X509].x; + x = a->heads[LTY_X509].x; + while (x) { + if (!strncmp(x->vhost_name, ctx->buf, ctx->npos) && + !x->vhost_name[ctx->npos]) { + if ((ctx->path_match - 1) == LSSPPT_SERVER_CERT) + a->curr[LTY_POLICY].p->trust.server.cert = x; + else + a->curr[LTY_POLICY].p->trust.server.key = x; + /* + * Certs that are for servers need to stick + * around in DER form, so the vhost can be + * instantiated when the server is brought up + */ + x->keep = 1; + lwsl_notice("%s: server '%s' keep %d %p\n", + __func__, x->vhost_name, + ctx->path_match - 1, x); + + /* + * Server DER we need to move it to another + * list just for destroying it when the context + * is destroyed... snip us out of the live + * X.509 list + */ + + *py = x->next; + + /* + * ... and instead put us on the list of things + * to keep hold of for context destruction + */ + + x->next = a->context->server_der_list; + a->context->server_der_list = x; + + return 0; + } + py = &x->next; + x = x->next; + } + lws_strnncpy(dotstar, ctx->buf, ctx->npos, sizeof(dotstar)); + lwsl_err("%s: unknown cert / key %s\n", __func__, dotstar); + goto oom; + + case LSSPPT_ENDPOINT: + pp = (char **)&a->curr[LTY_POLICY].p->endpoint; + goto string2; + + case LSSPPT_VH_VIA_SOCKS5: + pp = (char **)&a->curr[LTY_POLICY].p->socks5_proxy; + goto string2; + + case LSSPPT_PORT: + a->curr[LTY_POLICY].p->port = atoi(ctx->buf); + break; + + case LSSPPT_HTTP_METHOD: + pp = (char **)&a->curr[LTY_POLICY].p->u.http.method; + goto string2; + + case LSSPPT_HTTP_URL: + pp = (char **)&a->curr[LTY_POLICY].p->u.http.url; + goto string2; + + case LSSPPT_RIDESHARE: + pp = (char **)&a->curr[LTY_POLICY].p->rideshare_streamtype; + goto string2; + + case LSSPPT_PAYLOAD_FORMAT: + pp = (char **)&a->curr[LTY_POLICY].p->payload_fmt; + goto string2; + + case LSSPPT_PLUGINS: +#if defined(LWS_WITH_SSPLUGINS) + pin = a->context->pss_plugins; + if (a->count == + (int)LWS_ARRAY_SIZE(a->curr[LTY_POLICY].p->plugins)) { + lwsl_err("%s: too many plugins\n", __func__); + + goto oom; + } + if (!pin) + break; + while (*pin) { + if (!strncmp((*pin)->name, ctx->buf, ctx->npos)) { + a->curr[LTY_POLICY].p->plugins[a->count++] = *pin; + return 0; + } + pin++; + } + lwsl_err("%s: unknown plugin\n", __func__); + goto oom; +#else + break; +#endif + + case LSSPPT_TLS: + if (reason == LEJPCB_VAL_TRUE) + a->curr[LTY_POLICY].p->flags |= LWSSSPOLF_TLS; + break; + + case LSSPPT_TLS_CLIENT_CERT: + a->curr[LTY_POLICY].p->client_cert = atoi(ctx->buf) + 1; + break; + + case LSSPPT_HTTP_EXPECT: + a->curr[LTY_POLICY].p->u.http.resp_expect = atoi(ctx->buf); + break; + + case LSSPPT_DEFAULT_TIMEOUT_MS: + a->curr[LTY_POLICY].p->timeout_ms = atoi(ctx->buf); + break; + + case LSSPPT_OPPORTUNISTIC: + if (reason == LEJPCB_VAL_TRUE) + a->curr[LTY_POLICY].p->flags |= LWSSSPOLF_OPPORTUNISTIC; + break; + case LSSPPT_NAILED_UP: + if (reason == LEJPCB_VAL_TRUE) + a->curr[LTY_POLICY].p->flags |= LWSSSPOLF_NAILED_UP; + break; + case LSSPPT_URGENT_TX: + if (reason == LEJPCB_VAL_TRUE) + a->curr[LTY_POLICY].p->flags |= LWSSSPOLF_URGENT_TX; + break; + case LSSPPT_URGENT_RX: + if (reason == LEJPCB_VAL_TRUE) + a->curr[LTY_POLICY].p->flags |= LWSSSPOLF_URGENT_RX; + break; + case LSSPPT_LONG_POLL: + if (reason == LEJPCB_VAL_TRUE) + a->curr[LTY_POLICY].p->flags |= LWSSSPOLF_LONG_POLL; + break; + case LSSPPT_HTTP_WWW_FORM_URLENCODED: + if (reason == LEJPCB_VAL_TRUE) + a->curr[LTY_POLICY].p->flags |= + LWSSSPOLF_HTTP_X_WWW_FORM_URLENCODED; + break; + case LSSPPT_SWAKE_VALIDITY: + if (reason == LEJPCB_VAL_TRUE) + a->curr[LTY_POLICY].p->flags |= + LWSSSPOLF_WAKE_SUSPEND__VALIDITY; + break; + case LSSPPT_ALLOW_REDIRECTS: + if (reason == LEJPCB_VAL_TRUE) + a->curr[LTY_POLICY].p->flags |= + LWSSSPOLF_ALLOW_REDIRECTS; + break; + case LSSPPT_HTTP_MULTIPART_SS_IN: + if (reason == LEJPCB_VAL_TRUE) + a->curr[LTY_POLICY].p->flags |= + LWSSSPOLF_HTTP_MULTIPART_IN; + return 0; + + case LSSPPT_RETRYPTR: + bot = a->heads[LTY_BACKOFF].b; + while (bot) { + if (!strncmp(ctx->buf, bot->name, ctx->npos)) { + a->curr[LTY_POLICY].p->retry_bo = &bot->r; + + return 0; + } + bot = bot->next; + } + lwsl_err("%s: unknown backoff scheme\n", __func__); + + return -1; + + case LSSPPT_TRUST: + ts = a->heads[LTY_TRUSTSTORE].t; + while (ts) { + if (!strncmp(ctx->buf, ts->name, ctx->npos)) { + a->curr[LTY_POLICY].p->trust.store = ts; + return 0; + } + ts = ts->next; + } + lws_strnncpy(dotstar, ctx->buf, ctx->npos, sizeof(dotstar)); + lwsl_err("%s: unknown trust store name %s\n", __func__, + dotstar); + + return -1; + + case LSSPPT_METADATA: + break; + + case LSSPPT_METADATA_ITEM: + pmd = a->curr[LTY_POLICY].p->metadata; + a->curr[LTY_POLICY].p->metadata = lwsac_use_zero(&a->ac, + sizeof(lws_ss_metadata_t) + ctx->npos + + (ctx->path_match_len - ctx->st[ctx->sp - 2].p + 1) + 2, + POL_AC_GRAIN); + a->curr[LTY_POLICY].p->metadata->next = pmd; + + q = (char *)a->curr[LTY_POLICY].p->metadata + + sizeof(lws_ss_metadata_t); + a->curr[LTY_POLICY].p->metadata->name = q; + memcpy(q, ctx->path + ctx->st[ctx->sp - 2].p + 1, + ctx->path_match_len - ctx->st[ctx->sp - 2].p); + + q += ctx->path_match_len - ctx->st[ctx->sp - 2].p; + a->curr[LTY_POLICY].p->metadata->value = q; + memcpy(q, ctx->buf, ctx->npos); + + a->curr[LTY_POLICY].p->metadata->length = /* the index in handle->metadata */ + a->curr[LTY_POLICY].p->metadata_count++; + break; + +#if defined(LWS_ROLE_H1) || defined(LWS_ROLE_H2) + case LSSPPT_HTTP_AUTH_HEADER: + case LSSPPT_HTTP_DSN_HEADER: + case LSSPPT_HTTP_FWV_HEADER: + case LSSPPT_HTTP_TYPE_HEADER: + pp = (char **)&a->curr[LTY_POLICY].p->u.http.blob_header[ + (ctx->path_match - 1) - LSSPPT_HTTP_AUTH_HEADER]; + goto string2; + + case LSSPPT_HTTP_AUTH_PREAMBLE: + pp = (char **)&a->curr[LTY_POLICY].p->u.http.auth_preamble; + goto string2; + + case LSSPPT_HTTP_NO_CONTENT_LENGTH: + if (reason == LEJPCB_VAL_TRUE) + a->curr[LTY_POLICY].p->flags |= + LWSSSPOLF_HTTP_NO_CONTENT_LENGTH; + break; + + case LSSPPT_NGHTTP2_QUIRK_END_STREAM: + if (reason == LEJPCB_VAL_TRUE) + a->curr[LTY_POLICY].p->flags |= + LWSSSPOLF_QUIRK_NGHTTP2_END_STREAM; + break; + case LSSPPT_H2_QUIRK_OVERFLOWS_TXCR: + if (reason == LEJPCB_VAL_TRUE) + a->curr[LTY_POLICY].p->flags |= + LWSSSPOLF_H2_QUIRK_OVERFLOWS_TXCR; + break; + case LSSPPT_HTTP_MULTIPART_NAME: + a->curr[LTY_POLICY].p->flags |= LWSSSPOLF_HTTP_MULTIPART; + pp = (char **)&a->curr[LTY_POLICY].p->u.http.multipart_name; + goto string2; + case LSSPPT_HTTP_MULTIPART_FILENAME: + a->curr[LTY_POLICY].p->flags |= LWSSSPOLF_HTTP_MULTIPART; + pp = (char **)&a->curr[LTY_POLICY].p->u.http.multipart_filename; + goto string2; + case LSSPPT_HTTP_MULTIPART_CONTENT_TYPE: + a->curr[LTY_POLICY].p->flags |= LWSSSPOLF_HTTP_MULTIPART; + pp = (char **)&a->curr[LTY_POLICY].p->u.http.multipart_content_type; + goto string2; + + case LSSPPT_HTTP_FAIL_REDIRECT: + a->curr[LTY_POLICY].p->u.http.fail_redirect = + reason == LEJPCB_VAL_TRUE; + break; +#endif + +#if defined(LWS_ROLE_WS) + + case LSSPPT_WS_SUBPROTOCOL: + pp = (char **)&a->curr[LTY_POLICY].p->u.http.u.ws.subprotocol; + goto string2; + + case LSSPPT_WS_BINARY: + a->curr[LTY_POLICY].p->u.http.u.ws.binary = + reason == LEJPCB_VAL_TRUE; + break; +#endif + + case LSSPPT_LOCAL_SINK: + if (reason == LEJPCB_VAL_TRUE) + a->curr[LTY_POLICY].p->flags |= LWSSSPOLF_LOCAL_SINK; + break; + + case LSSPPT_SERVER: + if (reason == LEJPCB_VAL_TRUE) + a->curr[LTY_POLICY].p->flags |= LWSSSPOLF_SERVER; + break; + +#if defined(LWS_ROLE_MQTT) + case LSSPPT_MQTT_TOPIC: + pp = (char **)&a->curr[LTY_POLICY].p->u.mqtt.topic; + goto string2; + + case LSSPPT_MQTT_SUBSCRIBE: + pp = (char **)&a->curr[LTY_POLICY].p->u.mqtt.subscribe; + goto string2; + + case LSSPPT_MQTT_QOS: + a->curr[LTY_POLICY].p->u.mqtt.qos = atoi(ctx->buf); + break; + + case LSSPPT_MQTT_KEEPALIVE: + a->curr[LTY_POLICY].p->u.mqtt.keep_alive = atoi(ctx->buf); + break; + + case LSSPPT_MQTT_CLEAN_START: + a->curr[LTY_POLICY].p->u.mqtt.clean_start = + reason == LEJPCB_VAL_TRUE; + break; + case LSSPPT_MQTT_WILL_TOPIC: + pp = (char **)&a->curr[LTY_POLICY].p->u.mqtt.will_topic; + goto string2; + + case LSSPPT_MQTT_WILL_MESSAGE: + pp = (char **)&a->curr[LTY_POLICY].p->u.mqtt.will_message; + goto string2; + + case LSSPPT_MQTT_WILL_QOS: + a->curr[LTY_POLICY].p->u.mqtt.will_qos = atoi(ctx->buf); + break; + case LSSPPT_MQTT_WILL_RETAIN: + a->curr[LTY_POLICY].p->u.mqtt.will_retain = + reason == LEJPCB_VAL_TRUE; + break; +#endif + + case LSSPPT_PROTOCOL: + a->curr[LTY_POLICY].p->protocol = 0xff; + for (n = 0; n < (int)LWS_ARRAY_SIZE(protonames); n++) + if (strlen(protonames[n]) == ctx->npos && + !strncmp(ctx->buf, protonames[n], ctx->npos)) + a->curr[LTY_POLICY].p->protocol = (uint8_t)n; + + if (a->curr[LTY_POLICY].p->protocol != 0xff) + break; + lws_strnncpy(dotstar, ctx->buf, ctx->npos, sizeof(dotstar)); + lwsl_err("%s: unknown protocol name %s\n", __func__, dotstar); + return -1; + + default: + break; + } + + return 0; + +string2: + /* + * If we can do const string folding, reuse the existing string rather + * than make a new entry + */ + extant = lwsac_scan_extant(a->ac, (uint8_t *)ctx->buf, ctx->npos, 1); + if (extant) { + *pp = (char *)extant; + + return 0; + } + *pp = lwsac_use_backfill(&a->ac, ctx->npos + 1, POL_AC_GRAIN); + if (!*pp) + goto oom; + memcpy(*pp, ctx->buf, ctx->npos); + (*pp)[ctx->npos] = '\0'; + + return 0; + +string1: + n = ctx->st[ctx->sp].p; + *pp = lwsac_use_backfill(&a->ac, ctx->path_match_len + 1 - n, + POL_AC_GRAIN); + if (!*pp) + goto oom; + memcpy(*pp, ctx->path + n, ctx->path_match_len - n); + (*pp)[ctx->path_match_len - n] = '\0'; + + return 0; + +oom: + lwsl_err("%s: OOM\n", __func__); + lws_free_set_NULL(a->p); + lwsac_free(&a->ac); + + return -1; +} + +int +lws_ss_policy_parse_begin(struct lws_context *context, int overlay) +{ + struct policy_cb_args *args; + char *p; + + args = lws_zalloc(sizeof(struct policy_cb_args), __func__); + if (!args) { + lwsl_err("%s: OOM\n", __func__); + + return 1; + } + if (overlay) + /* continue to use the existing lwsac */ + args->ac = context->ac_policy; + else + /* we don't want to see any old policy */ + context->pss_policies = NULL; + + context->pol_args = args; + args->context = context; + p = lwsac_use(&args->ac, 1, POL_AC_INITIAL); + if (!p) { + lwsl_err("%s: OOM\n", __func__); + lws_free_set_NULL(context->pol_args); + + return -1; + } + *p = 0; + lejp_construct(&args->jctx, lws_ss_policy_parser_cb, args, + lejp_tokens_policy, LWS_ARRAY_SIZE(lejp_tokens_policy)); + + return 0; +} + +int +lws_ss_policy_parse_abandon(struct lws_context *context) +{ + struct policy_cb_args *args = (struct policy_cb_args *)context->pol_args; + + lejp_destruct(&args->jctx); + lwsac_free(&args->ac); + lws_free_set_NULL(context->pol_args); + + return 0; +} + +int +lws_ss_policy_parse(struct lws_context *context, const uint8_t *buf, size_t len) +{ + struct policy_cb_args *args = (struct policy_cb_args *)context->pol_args; + int m; + + m = lejp_parse(&args->jctx, buf, (int)len); + if (m == LEJP_CONTINUE || m >= 0) + return m; + + lwsl_err("%s: parse failed line %u: %d: %s\n", __func__, + (unsigned int)args->jctx.line, m, lejp_error_to_string(m)); + lws_ss_policy_parse_abandon(context); + assert(0); + + return m; +} + +int +lws_ss_policy_overlay(struct lws_context *context, const char *overlay) +{ + lws_ss_policy_parse_begin(context, 1); + return lws_ss_policy_parse(context, (const uint8_t *)overlay, + strlen(overlay)); +} + +const lws_ss_policy_t * +lws_ss_policy_get(struct lws_context *context) +{ + struct policy_cb_args *args = (struct policy_cb_args *)context->pol_args; + + if (!args) + return NULL; + + return args->heads[LTY_POLICY].p; +} diff -Nru libwebsockets-3.2.1/lib/secure-streams/private-lib-secure-streams.h libwebsockets-4.1.6/lib/secure-streams/private-lib-secure-streams.h --- libwebsockets-3.2.1/lib/secure-streams/private-lib-secure-streams.h 1970-01-01 00:00:00.000000000 +0000 +++ libwebsockets-4.1.6/lib/secure-streams/private-lib-secure-streams.h 2020-12-01 17:40:26.000000000 +0000 @@ -0,0 +1,460 @@ +/* + * libwebsockets - small server side websockets and web server implementation + * + * Copyright (C) 2019 - 2020 Andy Green + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to + * deal in the Software without restriction, including without limitation the + * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or + * sell copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS + * IN THE SOFTWARE. + */ + +/* + * Secure Stream state + */ + +typedef enum { + SSSEQ_IDLE, + SSSEQ_TRY_CONNECT, + SSSEQ_TRY_CONNECT_NAUTH, + SSSEQ_TRY_CONNECT_SAUTH, + SSSEQ_RECONNECT_WAIT, + SSSEQ_DO_RETRY, + SSSEQ_CONNECTED, +} lws_ss_seq_state_t; + + +/** + * lws_ss_handle_t: publicly-opaque secure stream object implementation + */ + +typedef struct lws_ss_handle { + lws_ss_info_t info; /**< copy of stream creation info */ + struct lws_dll2 list; /**< pt lists active ss */ + struct lws_dll2 to_list; /**< pt lists ss with pending to-s */ + + struct lws_dll2_owner src_list; /**< sink's list of bound sources */ + + struct lws_context *context; /**< lws context we are created on */ + const lws_ss_policy_t *policy; /**< system policy for stream */ + + struct lws_sequencer *seq; /**< owning sequencer if any */ + struct lws *wsi; /**< the stream wsi if any */ + +#if defined(LWS_WITH_SSPLUGINS) + void *nauthi; /**< the nauth plugin instance data */ + void *sauthi; /**< the sauth plugin instance data */ +#endif + + lws_ss_metadata_t *metadata; + const lws_ss_policy_t *rideshare; + + //struct lws_ss_handle *h_sink; /**< sink we are bound to, or NULL */ + //void *sink_obj;/**< sink's private object representing us */ + + lws_sorted_usec_list_t sul_timeout; + lws_sorted_usec_list_t sul; + lws_ss_tx_ordinal_t txord; + + /* protocol-specific connection helpers */ + + union { + + /* ...for http-related protocols... */ + + struct { + + /* common to all http-related protocols */ + + /* incoming multipart parsing */ + + char boundary[24]; /* --boundary from headers */ + uint8_t boundary_len; /* length of --boundary */ + uint8_t boundary_seq; /* current match amount */ + uint8_t boundary_dashes; /* check for -- after */ + uint8_t boundary_post; /* swallow post CRLF */ + + uint8_t som:1; /* SOM has been sent */ + uint8_t any:1; /* any content has been sent */ + + + uint8_t good_respcode:1; /* 200 type response code */ + + union { + struct { /* LWSSSP_H1 */ +#if defined(WIN32) + uint8_t dummy; +#endif + } h1; + struct { /* LWSSSP_H2 */ +#if defined(WIN32) + uint8_t dummy; +#endif + } h2; + struct { /* LWSSSP_WS */ +#if defined(WIN32) + uint8_t dummy; +#endif + } ws; + } u; + } http; + + /* details for non-http related protocols... */ +#if defined(LWS_ROLE_MQTT) + struct { + lws_mqtt_topic_elem_t topic_qos; + lws_mqtt_topic_elem_t sub_top; + lws_mqtt_subscribe_param_t sub_info; + /* allocation that must be destroyed with conn */ + void *heap_baggage; + const char *subscribe_to; + size_t subscribe_to_len; + } mqtt; +#endif +#if defined(LWS_WITH_SYS_SMD) + struct { + struct lws_smd_peer *smd_peer; + lws_sorted_usec_list_t sul_write; + } smd; +#endif + } u; + + unsigned long writeable_len; + + lws_ss_constate_t connstate;/**< public connection state */ + lws_ss_seq_state_t seqstate; /**< private connection state */ + +#if defined(LWS_WITH_SERVER) + int txn_resp; +#endif + + uint16_t retry; /**< retry / backoff tracking */ + int16_t temp16; + + uint8_t tsi; /**< service thread idx, usually 0 */ + uint8_t subseq; /**< emulate SOM tracking */ + uint8_t txn_ok; /**< 1 = transaction was OK */ + + uint8_t txn_resp_set:1; /**< user code set one */ + uint8_t txn_resp_pending:1; /**< we have yet to send */ + uint8_t hanging_som:1; + uint8_t inside_msg:1; + uint8_t being_serialized:1; /* we are not the consumer */ + uint8_t destroying:1; +} lws_ss_handle_t; + +/* connection helper that doesn't need to hang around after connection starts */ + +union lws_ss_contemp { +#if defined(LWS_ROLE_MQTT) + lws_mqtt_client_connect_param_t ccp; +#else +#if defined(WIN32) + uint8_t dummy; +#endif +#endif +}; + +/* + * When allocating the opaque handle, we overallocate for: + * + * 1) policy->nauth_plugin->alloc (.nauthi) if any + * 2) policy->sauth_plugin->alloc (.sauthi) if any + * 3) copy of creation info stream type pointed to by info.streamtype... this + * may be arbitrarily long and since it may be coming from socket ipc and be + * temporary at creation time, we need a place for the copy to stay in scope + * 4) copy of info->streamtype contents + */ + + +/* the user object allocation is immediately after the ss object allocation */ +#define ss_to_userobj(ss) ((void *)&(ss)[1]) + +/* + * serialization parser state + */ + +enum { + KIND_C_TO_P, + KIND_SS_TO_P, +}; + +struct lws_ss_serialization_parser { + char streamtype[32]; + char rideshare[32]; + char metadata_name[32]; + + uint64_t ust_pwait; + + lws_ss_metadata_t *ssmd; + + int ps; + int ctr; + + uint32_t usd_phandling; + uint32_t flags; + int32_t temp32; + + int32_t txcr_out; + int32_t txcr_in; + uint16_t rem; + + uint8_t type; + uint8_t frag1; + uint8_t slen; + uint8_t rsl_pos; + uint8_t rsl_idx; +}; + +/* + * Unlike locally-fulfilled SS, SSS doesn't have to hold metadata on client side + * but pass it through to the proxy. The client side doesn't know the real + * metadata names that are available in the policy (since it's hardcoded in code + * no point passing them back to the client from the policy). Because of that, + * it doesn't know how many to allocate when we create the sspc_handle either. + * + * So we use a linked-list of changed-but-not-yet-proxied metadata allocated + * on the heap and items removed as they are proxied out. Anything on the list + * is sent to the proxy before any requested tx is handled. + * + * This is also used to queue tx credit changes + */ + +typedef struct lws_sspc_metadata { + lws_dll2_t list; + char name[32]; /* empty string, then actually TCXR */ + size_t len; + int tx_cr_adjust; + + /* the value of length .len is overallocated after this */ +} lws_sspc_metadata_t; + +/* state of the upstream proxy onward connection */ + +enum { + LWSSSPC_ONW_NONE, + LWSSSPC_ONW_REQ, + LWSSSPC_ONW_ONGOING, + LWSSSPC_ONW_CONN, +}; + +typedef struct lws_sspc_handle { + char rideshare_list[128]; + lws_ss_info_t ssi; + lws_sorted_usec_list_t sul_retry; + + struct lws_ss_serialization_parser parser; + + lws_dll2_owner_t metadata_owner; + + struct lws_dll2 client_list; + struct lws_tx_credit txc; + + struct lws *cwsi; + + struct lws_dsh *dsh; + struct lws_context *context; + + lws_usec_t us_earliest_write_req; + + unsigned long writeable_len; + + lws_ss_conn_states_t state; + + uint32_t timeout_ms; + uint32_t ord; + + int16_t temp16; + + uint8_t rideshare_ofs[4]; + uint8_t rsidx; + + uint8_t conn_req_state:2; + uint8_t destroying:1; + uint8_t non_wsi:1; + uint8_t ignore_txc:1; + uint8_t pending_timeout_update:1; + uint8_t pending_writeable_len:1; + uint8_t creating_cb_done:1; +} lws_sspc_handle_t; + +typedef struct backoffs { + struct backoffs *next; + const char *name; + lws_retry_bo_t r; +} backoff_t; + +union u { + backoff_t *b; + lws_ss_x509_t *x; + lws_ss_trust_store_t *t; + lws_ss_policy_t *p; +}; + +enum { + LTY_BACKOFF, + LTY_X509, + LTY_TRUSTSTORE, + LTY_POLICY, + + _LTY_COUNT /* always last */ +}; + + +struct policy_cb_args { + struct lejp_ctx jctx; + struct lws_context *context; + struct lwsac *ac; + + const char *socks5_proxy; + + struct lws_b64state b64; + + union u heads[_LTY_COUNT]; + union u curr[_LTY_COUNT]; + + uint8_t *p; + + int count; +}; + +#if defined(LWS_WITH_SYS_SMD) +extern const lws_ss_policy_t pol_smd; +#endif + + +/* + * returns one of + * + * LWSSSSRET_OK + * LWSSSSRET_DISCONNECT_ME + * LWSSSSRET_DESTROY_ME + */ +int +lws_ss_deserialize_parse(struct lws_ss_serialization_parser *par, + struct lws_context *context, + struct lws_dsh *dsh, const uint8_t *cp, size_t len, + lws_ss_conn_states_t *state, void *parconn, + lws_ss_handle_t **pss, lws_ss_info_t *ssi, char client); +int +lws_ss_serialize_rx_payload(struct lws_dsh *dsh, const uint8_t *buf, + size_t len, int flags, const char *rsp); +int +lws_ss_deserialize_tx_payload(struct lws_dsh *dsh, struct lws *wsi, + lws_ss_tx_ordinal_t ord, uint8_t *buf, + size_t *len, int *flags); +int +lws_ss_serialize_state(struct lws_dsh *dsh, lws_ss_constate_t state, + lws_ss_tx_ordinal_t ack); + +void +lws_ss_serialize_state_transition(lws_ss_conn_states_t *state, int new_state); + +const lws_ss_policy_t * +lws_ss_policy_lookup(const struct lws_context *context, const char *streamtype); + +/* can be used as a cb from lws_dll2_foreach_safe() to destroy ss */ +int +lws_ss_destroy_dll(struct lws_dll2 *d, void *user); + +int +lws_sspc_destroy_dll(struct lws_dll2 *d, void *user); + +int +lws_ss_policy_set(struct lws_context *context, const char *name); + +int +lws_ss_sys_fetch_policy(struct lws_context *context); + +lws_ss_state_return_t +lws_ss_event_helper(lws_ss_handle_t *h, lws_ss_constate_t cs); + +lws_ss_state_return_t +lws_ss_backoff(lws_ss_handle_t *h); + +int +_lws_ss_handle_state_ret(lws_ss_state_return_t r, struct lws *wsi, + lws_ss_handle_t **ph); + +int +lws_ss_set_timeout_us(lws_ss_handle_t *h, lws_usec_t us); + +void +ss_proxy_onward_txcr(void *userobj, int bump); + +int +lws_ss_serialize_txcr(struct lws_dsh *dsh, int txcr); + +int +lws_ss_sys_auth_api_amazon_com(struct lws_context *context); + +lws_ss_metadata_t * +lws_ss_get_handle_metadata(struct lws_ss_handle *h, const char *name); +lws_ss_metadata_t * +lws_ss_policy_metadata_index(const lws_ss_policy_t *p, size_t index); + +lws_ss_metadata_t * +lws_ss_policy_metadata(const lws_ss_policy_t *p, const char *name); + +int +lws_ss_exp_cb_metadata(void *priv, const char *name, char *out, size_t *pos, + size_t olen, size_t *exp_ofs); + +int +_lws_ss_client_connect(lws_ss_handle_t *h, int is_retry); + +struct lws_vhost * +lws_ss_policy_ref_trust_store(struct lws_context *context, + const lws_ss_policy_t *pol, char doref); + +#if defined(LWS_WITH_SECURE_STREAMS_STATIC_POLICY_ONLY) +int +lws_ss_policy_unref_trust_store(struct lws_context *context, + const lws_ss_policy_t *pol); +#endif + +int +lws_ss_sys_cpd(struct lws_context *cx); + +typedef int (* const secstream_protocol_connect_munge_t)(lws_ss_handle_t *h, + char *buf, size_t len, struct lws_client_connect_info *i, + union lws_ss_contemp *ct); + +typedef int (* const secstream_protocol_add_txcr_t)(lws_ss_handle_t *h, int add); + +typedef int (* const secstream_protocol_get_txcr_t)(lws_ss_handle_t *h); + +struct ss_pcols { + const char *name; + const char *alpn; + const struct lws_protocols *protocol; + secstream_protocol_connect_munge_t munge; + secstream_protocol_add_txcr_t tx_cr_add; + secstream_protocol_get_txcr_t tx_cr_est; +}; + +extern const struct ss_pcols ss_pcol_h1; +extern const struct ss_pcols ss_pcol_h2; +extern const struct ss_pcols ss_pcol_ws; +extern const struct ss_pcols ss_pcol_mqtt; +extern const struct ss_pcols ss_pcol_raw; + +extern const struct lws_protocols protocol_secstream_h1; +extern const struct lws_protocols protocol_secstream_h2; +extern const struct lws_protocols protocol_secstream_ws; +extern const struct lws_protocols protocol_secstream_mqtt; +extern const struct lws_protocols protocol_secstream_raw; + diff -Nru libwebsockets-3.2.1/lib/secure-streams/protocols/README.md libwebsockets-4.1.6/lib/secure-streams/protocols/README.md --- libwebsockets-3.2.1/lib/secure-streams/protocols/README.md 1970-01-01 00:00:00.000000000 +0000 +++ libwebsockets-4.1.6/lib/secure-streams/protocols/README.md 2020-12-01 17:40:26.000000000 +0000 @@ -0,0 +1,38 @@ +# Lws Protocol bindings for Secure Streams + +This directory contains the code wiring up normal lws protocols +to Secure Streams. + +## The lws_protocols callback + +This is the normal lws struct lws_protocols callback that handles events and +traffic on the lws protocol being supported. + +The various events and traffic are converted into calls using the Secure +Streams api, and Secure Streams events. + +## The connect_munge helper + +Different protocols have different semantics in the arguments to the client +connect function, this protocol-specific helper is called to munge the +connect_info struct to match the details of the protocol selected. + +The `ss->policy->aux` string is used to hold protocol-specific information +passed in the from the policy, eg, the URL path or websockets subprotocol +name. + +## The (library-private) ss_pcols export + +Each protocol binding exports two things to other parts of lws (they +are not exported to user code) + + - a struct lws_protocols, including a pointer to the callback + + - a struct ss_pcols describing how secure_streams should use, including + a pointer to the related connect_munge helper. + +In ./lib/core-net/vhost.c, enabled protocols are added to vhost protcols +lists so they may be used. And in ./lib/secure-streams/secure-streams.c, +enabled struct ss_pcols are listed and checked for matches when the user +creates a new Secure Stream. + diff -Nru libwebsockets-3.2.1/lib/secure-streams/protocols/ss-h1.c libwebsockets-4.1.6/lib/secure-streams/protocols/ss-h1.c --- libwebsockets-3.2.1/lib/secure-streams/protocols/ss-h1.c 1970-01-01 00:00:00.000000000 +0000 +++ libwebsockets-4.1.6/lib/secure-streams/protocols/ss-h1.c 2020-12-01 17:40:26.000000000 +0000 @@ -0,0 +1,779 @@ +/* + * libwebsockets - small server side websockets and web server implementation + * + * Copyright (C) 2019 - 2020 Andy Green + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to + * deal in the Software without restriction, including without limitation the + * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or + * sell copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS + * IN THE SOFTWARE. + * + * This is the glue that wires up h1 to Secure Streams. + */ + +#include + +#if !defined(LWS_PLAT_FREERTOS) || defined(LWS_ROLE_H2) +#define LWS_WITH_SS_RIDESHARE +#endif + +#if defined(LWS_WITH_SS_RIDESHARE) +static int +ss_http_multipart_parser(lws_ss_handle_t *h, void *in, size_t len) +{ + uint8_t *q = (uint8_t *)in; + int pending_issue = 0, n = 0; + + /* let's stick it in the boundary state machine first */ + while (n < (int)len) { + if (h->u.http.boundary_seq != h->u.http.boundary_len) { + if (q[n] == h->u.http.boundary[h->u.http.boundary_seq]) + h->u.http.boundary_seq++; + else { + h->u.http.boundary_seq = 0; + h->u.http.boundary_dashes = 0; + h->u.http.boundary_post = 0; + } + goto around; + } + + /* + * We already matched the boundary string, now we're + * looking if there's a -- afterwards + */ + if (h->u.http.boundary_dashes < 2) { + if (q[n] == '-') { + h->u.http.boundary_dashes++; + goto around; + } + /* there was no final -- ... */ + } + + if (h->u.http.boundary_dashes == 2) { + /* + * It's an EOM boundary: issue pending + multipart EOP + */ + lwsl_debug("%s: seen EOP, n %d pi %d\n", + __func__, n, pending_issue); + /* + * It's possible we already started the decode before + * the end of the last packet. Then there is no + * remainder to send. + */ + if (n >= pending_issue + h->u.http.boundary_len + + (h->u.http.any ? 2 : 0) + 1) + h->info.rx(ss_to_userobj(h), + &q[pending_issue], + n - pending_issue - + h->u.http.boundary_len - 1 - + (h->u.http.any ? 2 : 0) /* crlf */, + (!h->u.http.som ? LWSSS_FLAG_SOM : 0) | + LWSSS_FLAG_EOM | LWSSS_FLAG_RELATED_END); + + /* + * Peer may not END_STREAM us + */ + return 0; + //return -1; + } + + /* how about --boundaryCRLF */ + + if (h->u.http.boundary_post < 2) { + if ((!h->u.http.boundary_post && q[n] == '\x0d') || + (h->u.http.boundary_post && q[n] == '\x0a')) { + h->u.http.boundary_post++; + goto around; + } + /* there was no final CRLF ... it's wrong */ + + return -1; + } + if (h->u.http.boundary_post != 2) + goto around; + + /* + * We have a starting "--boundaryCRLF" or intermediate + * "CRLF--boundaryCRLF" boundary + */ + lwsl_debug("%s: b_post = 2 (pi %d)\n", __func__, pending_issue); + h->u.http.boundary_seq = 0; + h->u.http.boundary_post = 0; + + if (n >= pending_issue && (h->u.http.any || !h->u.http.som)) { + /* Intermediate... do the EOM */ + lwsl_debug("%s: seen interm EOP n %d pi %d\n", __func__, + n, pending_issue); + /* + * It's possible we already started the decode before + * the end of the last packet. Then there is no + * remainder to send. + */ + if (n >= pending_issue + h->u.http.boundary_len + + (h->u.http.any ? 2 : 0)) + h->info.rx(ss_to_userobj(h), &q[pending_issue], + n - pending_issue - + h->u.http.boundary_len - + (h->u.http.any ? 2 /* crlf */ : 0), + (!h->u.http.som ? LWSSS_FLAG_SOM : 0) | + LWSSS_FLAG_EOM); + } + + /* Next message starts after this boundary */ + + pending_issue = n; + h->u.http.som = 0; + +around: + n++; + } + + if (pending_issue != n) { + h->info.rx(ss_to_userobj(h), &q[pending_issue], n - pending_issue, + (!h->u.http.som ? LWSSS_FLAG_SOM : 0)); + h->u.http.any = 1; + h->u.http.som = 1; + } + + return 0; +} +#endif + +static int +lws_apply_metadata(lws_ss_handle_t *h, struct lws *wsi, uint8_t *buf, + uint8_t **pp, uint8_t *end) +{ + int m; + + for (m = 0; m < h->policy->metadata_count; m++) { + lws_ss_metadata_t *polmd; + + /* has to have a header string listed */ + if (!h->metadata[m].value) + continue; + + polmd = lws_ss_policy_metadata_index(h->policy, m); + + assert(polmd); + if (!polmd) + return -1; + + /* has to have a value */ + if (polmd->value && ((uint8_t *)polmd->value)[0]) { + if (lws_add_http_header_by_name(wsi, + polmd->value, + h->metadata[m].value, + (int)h->metadata[m].length, pp, end)) + return -1; + } + } + + /* + * Content-length on POST / PUT if we have the length information + */ + + if (h->policy->u.http.method && ( + (!strcmp(h->policy->u.http.method, "POST") || + !strcmp(h->policy->u.http.method, "PUT"))) && + wsi->http.writeable_len) { + if (!(h->policy->flags & + LWSSSPOLF_HTTP_NO_CONTENT_LENGTH)) { + int n = lws_snprintf((char *)buf, 20, "%u", + (unsigned int)wsi->http.writeable_len); + if (lws_add_http_header_by_token(wsi, + WSI_TOKEN_HTTP_CONTENT_LENGTH, + buf, n, pp, end)) + return -1; + } + lws_client_http_body_pending(wsi, 1); + } + + return 0; +} + +static const uint8_t blob_idx[] = { + LWS_SYSBLOB_TYPE_AUTH, + LWS_SYSBLOB_TYPE_DEVICE_SERIAL, + LWS_SYSBLOB_TYPE_DEVICE_FW_VERSION, + LWS_SYSBLOB_TYPE_DEVICE_TYPE, +}; + +int +secstream_h1(struct lws *wsi, enum lws_callback_reasons reason, void *user, + void *in, size_t len) +{ + lws_ss_handle_t *h = (lws_ss_handle_t *)lws_get_opaque_user_data(wsi); + uint8_t buf[LWS_PRE + 1520], *p = &buf[LWS_PRE], +#if defined(LWS_WITH_SERVER) + *start = p, +#endif + *end = &buf[sizeof(buf) - 1]; + lws_ss_state_return_t r; + int f = 0, m, status; + char conceal_eom = 0; + size_t buflen; + + switch (reason) { + + case LWS_CALLBACK_CLIENT_CONNECTION_ERROR: + if (!h) + break; + assert(h->policy); + lwsl_info("%s: h: %p, %s CLIENT_CONNECTION_ERROR: %s\n", __func__, + h, h->policy->streamtype, in ? (char *)in : "(null)"); + /* already disconnected, no action for DISCONNECT_ME */ + r = lws_ss_event_helper(h, LWSSSCS_UNREACHABLE); + if (r) + return _lws_ss_handle_state_ret(r, wsi, &h); + + h->wsi = NULL; + r = lws_ss_backoff(h); + if (r != LWSSSSRET_OK) + return _lws_ss_handle_state_ret(r, wsi, &h); + break; + + case LWS_CALLBACK_CLIENT_HTTP_REDIRECT: + if (h->policy->u.http.fail_redirect) + lws_system_cpd_set(lws_get_context(wsi), + LWS_CPD_CAPTIVE_PORTAL); + /* unless it's explicitly allowed, reject to follow it */ + return !(h->policy->flags & LWSSSPOLF_ALLOW_REDIRECTS); + + case LWS_CALLBACK_CLOSED_HTTP: /* server */ + case LWS_CALLBACK_CLOSED_CLIENT_HTTP: + if (!h) + break; + + lws_sul_cancel(&h->sul_timeout); + lwsl_info("%s: h: %p, %s LWS_CALLBACK_CLOSED_CLIENT_HTTP\n", + __func__, h, + h->policy ? h->policy->streamtype : "no policy"); + h->wsi = NULL; + + if (h->policy && !(h->policy->flags & LWSSSPOLF_OPPORTUNISTIC) && +#if defined(LWS_WITH_SERVER) + !(h->info.flags & LWSSSINFLAGS_ACCEPTED) && /* not server */ +#endif + !h->txn_ok && !wsi->a.context->being_destroyed) { + r = lws_ss_backoff(h); + if (r != LWSSSSRET_OK) + return _lws_ss_handle_state_ret(r, wsi, &h); + break; + } else + h->seqstate = SSSEQ_IDLE; + /* already disconnected, no action for DISCONNECT_ME */ + r = lws_ss_event_helper(h, LWSSSCS_DISCONNECTED); + if (r != LWSSSSRET_OK) + return _lws_ss_handle_state_ret(r, wsi, &h); + break; + + + case LWS_CALLBACK_ESTABLISHED_CLIENT_HTTP: + status = lws_http_client_http_response(wsi); + lwsl_info("%s: LWS_CALLBACK_ESTABLISHED_CLIENT_HTTP: %d\n", __func__, status); + // if (!status) + /* it's just telling use we connected / joined the nwsi */ + // break; + + if (h->policy->u.http.resp_expect) + h->u.http.good_respcode = + status == h->policy->u.http.resp_expect; + else + h->u.http.good_respcode = (status >= 200 && status < 300); + // lwsl_err("%s: good resp %d %d\n", __func__, status, h->u.http.good_respcode); + + if (h->u.http.good_respcode) + lwsl_info("%s: Connected streamtype %s, %d\n", __func__, + h->policy->streamtype, status); + else + if (h->u.http.good_respcode) + lwsl_warn("%s: Connected streamtype %s, BAD %d\n", + __func__, h->policy->streamtype, + status); + + h->hanging_som = 0; + + h->retry = 0; + h->seqstate = SSSEQ_CONNECTED; + lws_sul_cancel(&h->sul); + + r = lws_ss_event_helper(h, LWSSSCS_CONNECTED); + if (r != LWSSSSRET_OK) + return _lws_ss_handle_state_ret(r, wsi, &h); + + /* + * Since it's an http transaction we initiated... this is + * proof of connection validity + */ + lws_validity_confirmed(wsi); + +#if defined(LWS_WITH_SS_RIDESHARE) + + /* + * There are two ways we might want to deal with multipart, + * one is pass it through raw (although the user code needs + * a helping hand for learning the boundary), and the other + * is to deframe it and provide basically submessages in the + * different parts. + */ + + if (lws_hdr_copy(wsi, (char *)buf, sizeof(buf), + WSI_TOKEN_HTTP_CONTENT_TYPE) > 0 && + /* multipart/form-data; + * boundary=----WebKitFormBoundarycc7YgAPEIHvgE9Bf */ + + (!strncmp((char *)buf, "multipart/form-data", 19) || + !strncmp((char *)buf, "multipart/related", 17))) { + struct lws_tokenize ts; + lws_tokenize_elem e; + + // puts((const char *)buf); + + memset(&ts, 0, sizeof(ts)); + ts.start = (char *)buf; + ts.len = strlen(ts.start); + ts.flags = LWS_TOKENIZE_F_RFC7230_DELIMS | + LWS_TOKENIZE_F_SLASH_NONTERM | + LWS_TOKENIZE_F_MINUS_NONTERM; + + h->u.http.boundary[0] = '\0'; + do { + e = lws_tokenize(&ts); + if (e == LWS_TOKZE_TOKEN_NAME_EQUALS && + !strncmp(ts.token, "boundary", 8) && + ts.token_len == 8) { + e = lws_tokenize(&ts); + if (e != LWS_TOKZE_TOKEN) + goto malformed; + h->u.http.boundary[0] = '\x0d'; + h->u.http.boundary[1] = '\x0a'; + h->u.http.boundary[2] = '-'; + h->u.http.boundary[3] = '-'; + lws_strnncpy(h->u.http.boundary + 4, + ts.token, ts.token_len, + sizeof(h->u.http.boundary) - 4); + h->u.http.boundary_len = + (uint8_t)(ts.token_len + 4); + h->u.http.boundary_seq = 2; + h->u.http.boundary_dashes = 0; + } + } while (e > 0); + lwsl_info("%s: multipart boundary '%s' len %d\n", __func__, + h->u.http.boundary, h->u.http.boundary_len); + + /* inform the ss that a related message group begins */ + + if ((h->policy->flags & LWSSSPOLF_HTTP_MULTIPART_IN) && + h->u.http.boundary[0]) + h->info.rx(ss_to_userobj(h), NULL, 0, + LWSSS_FLAG_RELATED_START); + + // lws_header_table_detach(wsi, 0); + } + break; +malformed: + lwsl_notice("%s: malformed multipart header\n", __func__); + return -1; +#else + break; +#endif + + case LWS_CALLBACK_CLIENT_APPEND_HANDSHAKE_HEADER: + if (h->writeable_len) + wsi->http.writeable_len = h->writeable_len; + + { + uint8_t **p = (uint8_t **)in, *end = (*p) + len, + *oin = *(uint8_t **)in; + + /* + * blob-based headers + */ + + for (m = 0; m < _LWSSS_HBI_COUNT; m++) { + lws_system_blob_t *ab; + int o = 0, n; + + if (!h->policy->u.http.blob_header[m]) + continue; + + if (m == LWSSS_HBI_AUTH && + h->policy->u.http.auth_preamble) + o = lws_snprintf((char *)buf, sizeof(buf), "%s", + h->policy->u.http.auth_preamble); + + if (o > (int)sizeof(buf) - 2) + return -1; + + ab = lws_system_get_blob(wsi->a.context, blob_idx[m], 0); + if (!ab) + return -1; + + buflen = sizeof(buf) - o - 2; + n = lws_system_blob_get(ab, buf + o, &buflen, 0); + if (n < 0) + return -1; + + buf[o + buflen] = '\0'; + lwsl_debug("%s: adding blob %d: %s\n", __func__, m, buf); + + if (lws_add_http_header_by_name(wsi, + (uint8_t *)h->policy->u.http.blob_header[m], + buf, (int)(buflen + o), p, end)) + return -1; + } + + /* + * metadata-based headers + */ + + if (lws_apply_metadata(h, wsi, buf, p, end)) + return -1; + + (void)oin; + // if (*p != oin) + // lwsl_hexdump_notice(oin, lws_ptr_diff(*p, oin)); + + } + + /* + * So when proxied, for POST we have to synthesize a CONNECTED + * state, so it can request a writeable and deliver the POST + * body + */ + if ((h->policy->protocol == LWSSSP_H1 || + h->policy->protocol == LWSSSP_H2) && + h->being_serialized && ( + !strcmp(h->policy->u.http.method, "PUT") || + !strcmp(h->policy->u.http.method, "POST"))) { + r = lws_ss_event_helper(h, LWSSSCS_CONNECTED); + if (r) + return _lws_ss_handle_state_ret(r, wsi, &h); + } + + break; + + /* chunks of chunked content, with header removed */ + case LWS_CALLBACK_HTTP_BODY: + case LWS_CALLBACK_RECEIVE_CLIENT_HTTP_READ: + lwsl_debug("%s: RECEIVE_CLIENT_HTTP_READ: read %d\n", + __func__, (int)len); + if (!h || !h->info.rx) + return 0; + +#if defined(LWS_WITH_SS_RIDESHARE) + if ((h->policy->flags & LWSSSPOLF_HTTP_MULTIPART_IN) && + h->u.http.boundary[0]) + return ss_http_multipart_parser(h, in, len); +#endif + + if (!h->subseq) { + f |= LWSSS_FLAG_SOM; + h->hanging_som = 1; + h->subseq = 1; + } + + // lwsl_notice("%s: HTTP_READ: client side sent len %d fl 0x%x\n", + // __func__, (int)len, (int)f); + + r = h->info.rx(ss_to_userobj(h), (const uint8_t *)in, len, f); + if (r != LWSSSSRET_OK) + return _lws_ss_handle_state_ret(r, wsi, &h); + + return 0; /* don't passthru */ + + /* uninterpreted http content */ + case LWS_CALLBACK_RECEIVE_CLIENT_HTTP: + { + char *px = (char *)buf + LWS_PRE; /* guarantees LWS_PRE */ + int lenx = sizeof(buf) - LWS_PRE; + + m = lws_http_client_read(wsi, &px, &lenx); + if (m < 0) + return m; + } + lws_set_timeout(wsi, 99, 30); + + return 0; /* don't passthru */ + + case LWS_CALLBACK_COMPLETED_CLIENT_HTTP: + lwsl_debug("%s: LWS_CALLBACK_COMPLETED_CLIENT_HTTP\n", __func__); + if (h->hanging_som) + h->info.rx(ss_to_userobj(h), NULL, 0, LWSSS_FLAG_EOM); + + wsi->http.writeable_len = h->writeable_len = 0; + lws_sul_cancel(&h->sul_timeout); + + h->txn_ok = 1; + + r = lws_ss_event_helper(h, h->u.http.good_respcode ? + LWSSSCS_QOS_ACK_REMOTE : + LWSSSCS_QOS_NACK_REMOTE); + if (r != LWSSSSRET_OK) + return _lws_ss_handle_state_ret(r, wsi, &h); + + lws_cancel_service(lws_get_context(wsi)); /* abort poll wait */ + break; + + case LWS_CALLBACK_HTTP_WRITEABLE: + case LWS_CALLBACK_CLIENT_HTTP_WRITEABLE: + //lwsl_info("%s: wsi %p, par %p, HTTP_WRITEABLE\n", __func__, + // wsi, wsi->mux.parent_wsi); + if (!h || !h->info.tx) { + lwsl_notice("%s: no handle / tx %p\n", __func__, h); + return 0; + } + +#if defined(LWS_WITH_SERVER) + if (h->txn_resp_pending) { + /* + * If we're going to start sending something, we need to + * to take care of the http response header for it first + */ + h->txn_resp_pending = 0; + + if (lws_add_http_common_headers(wsi, + h->txn_resp_set ? + (h->txn_resp ? h->txn_resp : 200) : + HTTP_STATUS_NOT_FOUND, + NULL, h->wsi->http.writeable_len, + &p, end)) + return 1; + + /* + * metadata-based headers + */ + + if (lws_apply_metadata(h, wsi, buf, &p, end)) + return -1; + + if (lws_finalize_write_http_header(wsi, start, &p, end)) + return 1; + + /* write the body separately */ + lws_callback_on_writable(wsi); + + return 0; + } +#endif + + if ( +#if defined(LWS_WITH_SERVER) + !(h->info.flags & LWSSSINFLAGS_ACCEPTED) && /* not accepted */ +#endif + !h->rideshare) + + h->rideshare = h->policy; + +#if defined(LWS_WITH_SS_RIDESHARE) + if ( +#if defined(LWS_WITH_SERVER) + !(h->info.flags & LWSSSINFLAGS_ACCEPTED) && /* not accepted */ +#endif + !h->inside_msg && h->rideshare->u.http.multipart_name) + lws_client_http_multipart(wsi, + h->rideshare->u.http.multipart_name, + h->rideshare->u.http.multipart_filename, + h->rideshare->u.http.multipart_content_type, + (char **)&p, (char *)end); + + buflen = lws_ptr_diff(end, p); + if (h->policy->u.http.multipart_name) + buflen -= 24; /* allow space for end of multipart */ +#else + buflen = lws_ptr_diff(end, p); +#endif + r = h->info.tx(ss_to_userobj(h), h->txord++, p, &buflen, &f); + if (r == LWSSSSRET_TX_DONT_SEND) + return 0; + if (r < 0) + return _lws_ss_handle_state_ret(r, wsi, &h); + + // lwsl_notice("%s: WRITEABLE: user tx says len %d fl 0x%x\n", + // __func__, (int)buflen, (int)f); + + p += buflen; + + if (f & LWSSS_FLAG_EOM) { +#if defined(LWS_WITH_SERVER) + if (!(h->info.flags & LWSSSINFLAGS_ACCEPTED)) { +#endif + conceal_eom = 1; + /* end of rideshares */ + if (!h->rideshare->rideshare_streamtype) { + lws_client_http_body_pending(wsi, 0); +#if defined(LWS_WITH_SS_RIDESHARE) + if (h->rideshare->u.http.multipart_name) + lws_client_http_multipart(wsi, NULL, NULL, NULL, + (char **)&p, (char *)end); + conceal_eom = 0; +#endif + } else { + h->rideshare = lws_ss_policy_lookup(wsi->a.context, + h->rideshare->rideshare_streamtype); + lws_callback_on_writable(wsi); + } +#if defined(LWS_WITH_SERVER) + } +#endif + + h->inside_msg = 0; + } else { + /* otherwise we can spin with zero length writes */ + if (!f && !lws_ptr_diff(p, buf + LWS_PRE)) + break; + h->inside_msg = 1; + lws_callback_on_writable(wsi); + } + + lwsl_info("%s: lws_write %d %d\n", __func__, + lws_ptr_diff(p, buf + LWS_PRE), f); + + if (lws_write(wsi, buf + LWS_PRE, lws_ptr_diff(p, buf + LWS_PRE), + (!conceal_eom && (f & LWSSS_FLAG_EOM)) ? + LWS_WRITE_HTTP_FINAL : LWS_WRITE_HTTP) != + (int)lws_ptr_diff(p, buf + LWS_PRE)) { + lwsl_err("%s: write failed\n", __func__); + return -1; + } + +#if defined(LWS_WITH_SERVER) + if (!(h->info.flags & LWSSSINFLAGS_ACCEPTED) && + (f & LWSSS_FLAG_EOM) && + lws_http_transaction_completed(wsi)) + return -1; +#else + lws_set_timeout(wsi, 0, 0); +#endif + break; + +#if defined(LWS_WITH_SERVER) + case LWS_CALLBACK_HTTP: + + lwsl_notice("%s: LWS_CALLBACK_HTTP\n", __func__); + { + + h->txn_resp_set = 0; + h->txn_resp_pending = 1; + h->writeable_len = 0; + +#if defined(LWS_ROLE_H2) + m = lws_hdr_total_length(wsi, WSI_TOKEN_HTTP_COLON_METHOD); + if (m) { + lws_ss_set_metadata(h, "method", + lws_hdr_simple_ptr(wsi, + WSI_TOKEN_HTTP_COLON_METHOD), m); + m = lws_hdr_total_length(wsi, WSI_TOKEN_HTTP_COLON_PATH); + lws_ss_set_metadata(h, "path", + lws_hdr_simple_ptr(wsi, + WSI_TOKEN_HTTP_COLON_PATH), m); + } else +#endif + { + m = lws_hdr_total_length(wsi, WSI_TOKEN_GET_URI); + if (m) { + lws_ss_set_metadata(h, "path", + lws_hdr_simple_ptr(wsi, + WSI_TOKEN_GET_URI), m); + lws_ss_set_metadata(h, "method", "GET", 3); + } else { + m = lws_hdr_total_length(wsi, WSI_TOKEN_POST_URI); + if (m) { + lws_ss_set_metadata(h, "path", + lws_hdr_simple_ptr(wsi, + WSI_TOKEN_POST_URI), m); + lws_ss_set_metadata(h, "method", "POST", 4); + } + } + } + } + + r = lws_ss_event_helper(h, LWSSSCS_SERVER_TXN); + if (r) + return _lws_ss_handle_state_ret(r, wsi, &h); + return 0; +#endif + + default: + break; + } + + return lws_callback_http_dummy(wsi, reason, user, in, len); +} + +const struct lws_protocols protocol_secstream_h1 = { + "lws-secstream-h1", + secstream_h1, + 0, + 0, +}; + +/* + * Munge connect info according to protocol-specific considerations... this + * usually means interpreting aux in a protocol-specific way and using the + * pieces at connection setup time, eg, http url pieces. + * + * len bytes of buf can be used for things with scope until after the actual + * connect. + */ + +static int +secstream_connect_munge_h1(lws_ss_handle_t *h, char *buf, size_t len, + struct lws_client_connect_info *i, + union lws_ss_contemp *ct) +{ + const char *pbasis = h->policy->u.http.url; + size_t used_in, used_out; + lws_strexp_t exp; + + /* i.path on entry is used to override the policy urlpath if not "" */ + + if (i->path[0]) + pbasis = i->path; + + if (!pbasis) + return 0; + +#if defined(LWS_WITH_SS_RIDESHARE) + if (h->policy->flags & LWSSSPOLF_HTTP_MULTIPART) + i->ssl_connection |= LCCSCF_HTTP_MULTIPART_MIME; + + if (h->policy->flags & LWSSSPOLF_HTTP_X_WWW_FORM_URLENCODED) + i->ssl_connection |= LCCSCF_HTTP_X_WWW_FORM_URLENCODED; +#endif + + /* protocol aux is the path part */ + + i->path = buf; + buf[0] = '/'; + + lws_strexp_init(&exp, (void *)h, lws_ss_exp_cb_metadata, buf + 1, len - 1); + + if (lws_strexp_expand(&exp, pbasis, strlen(pbasis), + &used_in, &used_out) != LSTRX_DONE) + return 1; + + return 0; +} + + +const struct ss_pcols ss_pcol_h1 = { + "h1", + "http/1.1", + &protocol_secstream_h1, + secstream_connect_munge_h1, + NULL +}; diff -Nru libwebsockets-3.2.1/lib/secure-streams/protocols/ss-h2.c libwebsockets-4.1.6/lib/secure-streams/protocols/ss-h2.c --- libwebsockets-3.2.1/lib/secure-streams/protocols/ss-h2.c 1970-01-01 00:00:00.000000000 +0000 +++ libwebsockets-4.1.6/lib/secure-streams/protocols/ss-h2.c 2020-12-01 17:40:26.000000000 +0000 @@ -0,0 +1,201 @@ +/* + * libwebsockets - small server side websockets and web server implementation + * + * Copyright (C) 2019 - 2020 Andy Green + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to + * deal in the Software without restriction, including without limitation the + * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or + * sell copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS + * IN THE SOFTWARE. + */ + +#include + +extern int +secstream_h1(struct lws *wsi, enum lws_callback_reasons reason, void *user, + void *in, size_t len); + +static int +secstream_h2(struct lws *wsi, enum lws_callback_reasons reason, void *user, + void *in, size_t len) +{ + lws_ss_handle_t *h = (lws_ss_handle_t *)lws_get_opaque_user_data(wsi); + lws_ss_state_return_t r; + int n; + + switch (reason) { + + case LWS_CALLBACK_ESTABLISHED_CLIENT_HTTP: + +#if defined(LWS_WITH_SECURE_STREAMS_PROXY_API) + if (h->being_serialized) { + /* + * We are the proxy-side SS for a remote client... we + * need to inform the client about the initial tx credit + * to write to it that the remote h2 server set up + */ + lwsl_info("%s: reporting initial tx cr from server %d\n", + __func__, wsi->txc.tx_cr); + ss_proxy_onward_txcr((void *)&h[1], wsi->txc.tx_cr); + } +#endif + + n = secstream_h1(wsi, reason, user, in, len); + + if (!n && (h->policy->flags & LWSSSPOLF_LONG_POLL)) { + lwsl_notice("%s: h2 client %p entering LONG_POLL\n", + __func__, wsi); + lws_h2_client_stream_long_poll_rxonly(wsi); + } + return n; + + case LWS_CALLBACK_COMPLETED_CLIENT_HTTP: + // lwsl_err("%s: h2 COMPLETED_CLIENT_HTTP\n", __func__); + r = h->info.rx(ss_to_userobj(h), NULL, 0, LWSSS_FLAG_EOM); + /* decouple the fates of the wsi and the ss */ + h->wsi = NULL; + h->txn_ok = 1; + lws_cancel_service(lws_get_context(wsi)); /* abort poll wait */ + if (r != LWSSSSRET_OK) + return _lws_ss_handle_state_ret(r, wsi, &h); + break; + + case LWS_CALLBACK_WSI_TX_CREDIT_GET: + /* + * The peer has sent us additional tx credit... + */ + lwsl_info("%s: LWS_CALLBACK_WSI_TX_CREDIT_GET: %d\n", + __func__, (int32_t)len); + +#if defined(LWS_WITH_SECURE_STREAMS_PROXY_API) + if (h->being_serialized) + /* we are the proxy-side SS for a remote client */ + ss_proxy_onward_txcr((void *)&h[1], (int)len); +#endif + break; + + default: + break; + } + + return secstream_h1(wsi, reason, user, in, len); +} + +const struct lws_protocols protocol_secstream_h2 = { + "lws-secstream-h2", + secstream_h2, + 0, + 0, +}; + +/* + * Munge connect info according to protocol-specific considerations... this + * usually means interpreting aux in a protocol-specific way and using the + * pieces at connection setup time, eg, http url pieces. + * + * len bytes of buf can be used for things with scope until after the actual + * connect. + */ + +int +secstream_connect_munge_h2(lws_ss_handle_t *h, char *buf, size_t len, + struct lws_client_connect_info *i, + union lws_ss_contemp *ct) +{ + const char *pbasis = h->policy->u.http.url; + size_t used_in, used_out; + lws_strexp_t exp; + + /* i.path on entry is used to override the policy urlpath if not "" */ + + if (i->path[0]) + pbasis = i->path; + + if (h->policy->flags & LWSSSPOLF_QUIRK_NGHTTP2_END_STREAM) + i->ssl_connection |= LCCSCF_H2_QUIRK_NGHTTP2_END_STREAM; + + if (h->policy->flags & LWSSSPOLF_H2_QUIRK_OVERFLOWS_TXCR) + i->ssl_connection |= LCCSCF_H2_QUIRK_OVERFLOWS_TXCR; + + if (h->policy->flags & LWSSSPOLF_HTTP_MULTIPART) + i->ssl_connection |= LCCSCF_HTTP_MULTIPART_MIME; + + if (h->policy->flags & LWSSSPOLF_HTTP_X_WWW_FORM_URLENCODED) + i->ssl_connection |= LCCSCF_HTTP_X_WWW_FORM_URLENCODED; + + i->ssl_connection |= LCCSCF_PIPELINE; + + i->alpn = "h2"; + + /* initial peer tx credit */ + + if (h->info.manual_initial_tx_credit) { + i->ssl_connection |= LCCSCF_H2_MANUAL_RXFLOW; + i->manual_initial_tx_credit = h->info.manual_initial_tx_credit; + lwsl_info("%s: initial txcr %d\n", __func__, + i->manual_initial_tx_credit); + } + + if (!pbasis) + return 0; + + /* protocol aux is the path part */ + + i->path = buf; + buf[0] = '/'; + + lws_strexp_init(&exp, (void *)h, lws_ss_exp_cb_metadata, buf + 1, len - 1); + + if (lws_strexp_expand(&exp, pbasis, strlen(pbasis), + &used_in, &used_out) != LSTRX_DONE) + return 1; + + return 0; +} + +static int +secstream_tx_credit_add_h2(lws_ss_handle_t *h, int add) +{ + lwsl_info("%s: h %p: add %d\n", __func__, h, add); + if (h->wsi) + return lws_h2_update_peer_txcredit(h->wsi, LWS_H2_STREAM_SID, add); + + return 0; +} + +static int +secstream_tx_credit_est_h2(lws_ss_handle_t *h) +{ + if (h->wsi) { + lwsl_info("%s: h %p: est %d\n", __func__, h, + lws_h2_get_peer_txcredit_estimate(h->wsi)); + + return lws_h2_get_peer_txcredit_estimate(h->wsi); + } + + lwsl_info("%s: h %p: Unknown (0)\n", __func__, h); + + return 0; +} + +const struct ss_pcols ss_pcol_h2 = { + "h2", + NULL, + &protocol_secstream_h2, + secstream_connect_munge_h2, + secstream_tx_credit_add_h2, + secstream_tx_credit_est_h2 +}; diff -Nru libwebsockets-3.2.1/lib/secure-streams/protocols/ss-mqtt.c libwebsockets-4.1.6/lib/secure-streams/protocols/ss-mqtt.c --- libwebsockets-3.2.1/lib/secure-streams/protocols/ss-mqtt.c 1970-01-01 00:00:00.000000000 +0000 +++ libwebsockets-4.1.6/lib/secure-streams/protocols/ss-mqtt.c 2020-12-01 17:40:26.000000000 +0000 @@ -0,0 +1,349 @@ +/* + * libwebsockets - small server side websockets and web server implementation + * + * Copyright (C) 2019 - 2020 Andy Green + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to + * deal in the Software without restriction, including without limitation the + * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or + * sell copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS + * IN THE SOFTWARE. + */ + +#include + +static int +secstream_mqtt(struct lws *wsi, enum lws_callback_reasons reason, void *user, + void *in, size_t len) +{ + lws_ss_handle_t *h = (lws_ss_handle_t *)lws_get_opaque_user_data(wsi); + lws_mqtt_publish_param_t mqpp, *pmqpp; + uint8_t buf[LWS_PRE + 1400]; + lws_ss_state_return_t r; + size_t buflen; + int f = 0; + + switch (reason) { + + /* because we are protocols[0] ... */ + case LWS_CALLBACK_CLIENT_CONNECTION_ERROR: + lwsl_info("%s: CLIENT_CONNECTION_ERROR: %s\n", __func__, + in ? (char *)in : "(null)"); + if (!h) + break; + r = lws_ss_event_helper(h, LWSSSCS_UNREACHABLE); + h->wsi = NULL; + + if (h->u.mqtt.heap_baggage) { + lws_free(h->u.mqtt.heap_baggage); + h->u.mqtt.heap_baggage = NULL; + } + + if (r == LWSSSSRET_DESTROY_ME) + return _lws_ss_handle_state_ret(r, wsi, &h); + + r = lws_ss_backoff(h); + if (r != LWSSSSRET_OK) + return _lws_ss_handle_state_ret(r, wsi, &h); + + break; + + case LWS_CALLBACK_MQTT_CLIENT_CLOSED: + if (!h) + break; + lws_sul_cancel(&h->sul_timeout); + r= lws_ss_event_helper(h, LWSSSCS_DISCONNECTED); + if (h->wsi) + lws_set_opaque_user_data(h->wsi, NULL); + h->wsi = NULL; + + if (h->u.mqtt.heap_baggage) { + lws_free(h->u.mqtt.heap_baggage); + h->u.mqtt.heap_baggage = NULL; + } + + if (r) + return _lws_ss_handle_state_ret(r, wsi, &h); + + if (h->policy && !(h->policy->flags & LWSSSPOLF_OPPORTUNISTIC) && + !h->txn_ok && !wsi->a.context->being_destroyed) { + r = lws_ss_backoff(h); + if (r != LWSSSSRET_OK) + return _lws_ss_handle_state_ret(r, wsi, &h); + } + break; + + case LWS_CALLBACK_MQTT_CLIENT_ESTABLISHED: + /* + * Make sure the handle wsi points to the stream wsi not the + * original nwsi, in the case it was migrated + */ + h->wsi = wsi; + h->retry = 0; + h->seqstate = SSSEQ_CONNECTED; + lws_sul_cancel(&h->sul); + r = lws_ss_event_helper(h, LWSSSCS_CONNECTED); + if (r != LWSSSSRET_OK) + return _lws_ss_handle_state_ret(r, wsi, &h); + if (h->policy->u.mqtt.topic) + lws_callback_on_writable(wsi); + break; + + case LWS_CALLBACK_MQTT_CLIENT_RX: + // lwsl_user("LWS_CALLBACK_CLIENT_RECEIVE: read %d\n", (int)len); + if (!h || !h->info.rx) + return 0; + + pmqpp = (lws_mqtt_publish_param_t *)in; + + f = 0; + if (!pmqpp->payload_pos) + f |= LWSSS_FLAG_SOM; + if (pmqpp->payload_pos + len == pmqpp->payload_len) + f |= LWSSS_FLAG_EOM; + + h->subseq = 1; + + r = h->info.rx(ss_to_userobj(h), (const uint8_t *)pmqpp->payload, + len, f); + if (r != LWSSSSRET_OK) + return _lws_ss_handle_state_ret(r, wsi, &h); + + return 0; /* don't passthru */ + + case LWS_CALLBACK_MQTT_SUBSCRIBED: + wsi->mqtt->done_subscribe = 1; + lws_callback_on_writable(wsi); + break; + + case LWS_CALLBACK_MQTT_ACK: + lws_sul_cancel(&h->sul_timeout); + r = lws_ss_event_helper(h, LWSSSCS_QOS_ACK_REMOTE); + if (r != LWSSSSRET_OK) + return _lws_ss_handle_state_ret(r, wsi, &h); + break; + + case LWS_CALLBACK_MQTT_CLIENT_WRITEABLE: + if (!h || !h->info.tx) + return 0; + lwsl_notice("%s: ss %p: WRITEABLE\n", __func__, h); + + if (h->seqstate != SSSEQ_CONNECTED) { + lwsl_warn("%s: seqstate %d\n", __func__, h->seqstate); + break; + } + + if (h->policy->u.mqtt.subscribe && + !wsi->mqtt->done_subscribe) { + + /* + * The policy says to subscribe to something, and we + * haven't done it yet. Do it using the pre-prepared + * string-substituted version of the policy string. + */ + + lwsl_notice("%s: subscribing %s\n", __func__, + h->u.mqtt.subscribe_to); + + memset(&h->u.mqtt.sub_top, 0, sizeof(h->u.mqtt.sub_top)); + h->u.mqtt.sub_top.name = h->u.mqtt.subscribe_to; + h->u.mqtt.sub_top.qos = h->policy->u.mqtt.qos; + memset(&h->u.mqtt.sub_info, 0, sizeof(h->u.mqtt.sub_info)); + h->u.mqtt.sub_info.num_topics = 1; + h->u.mqtt.sub_info.topic = &h->u.mqtt.sub_top; + + if (lws_mqtt_client_send_subcribe(wsi, &h->u.mqtt.sub_info)) { + lwsl_notice("%s: unable to subscribe", __func__); + return -1; + } + + return 0; + } + + + buflen = sizeof(buf) - LWS_PRE; + r = h->info.tx(ss_to_userobj(h), h->txord++, buf + LWS_PRE, + &buflen, &f); + if (r == LWSSSSRET_TX_DONT_SEND) + return 0; + + if (r < 0) + return _lws_ss_handle_state_ret(r, wsi, &h); + + memset(&mqpp, 0, sizeof(mqpp)); + /* this is the string-substituted h->policy->u.mqtt.topic */ + mqpp.topic = (char *)h->u.mqtt.topic_qos.name; + mqpp.topic_len = strlen(mqpp.topic); + mqpp.packet_id = h->txord - 1; + mqpp.payload = buf + LWS_PRE; + if (h->writeable_len) + mqpp.payload_len = h->writeable_len; + else + mqpp.payload_len = buflen; + + lwsl_notice("%s: payload len %d\n", __func__, + (int)mqpp.payload_len); + + mqpp.qos = h->policy->u.mqtt.qos; + + if (lws_mqtt_client_send_publish(wsi, &mqpp, + (const char *)buf + LWS_PRE, buflen, + f & LWSSS_FLAG_EOM)) { + lwsl_notice("%s: failed to publish\n", __func__); + + return -1; + } + + return 0; + + default: + break; + } + + return lws_callback_http_dummy(wsi, reason, user, in, len); +} + +const struct lws_protocols protocol_secstream_mqtt = { + "lws-secstream-mqtt", + secstream_mqtt, + 0, + 0, +}; +/* + * Munge connect info according to protocol-specific considerations... this + * usually means interpreting aux in a protocol-specific way and using the + * pieces at connection setup time, eg, http url pieces. + * + * len bytes of buf can be used for things with scope until after the actual + * connect. + * + * For ws, protocol aux is ; + */ + +enum { + SSCMM_STRSUB_WILL_TOPIC, + SSCMM_STRSUB_WILL_MESSAGE, + SSCMM_STRSUB_SUBSCRIBE, + SSCMM_STRSUB_TOPIC +}; + +static int +secstream_connect_munge_mqtt(lws_ss_handle_t *h, char *buf, size_t len, + struct lws_client_connect_info *i, + union lws_ss_contemp *ct) +{ + const char *sources[4] = { + /* we're going to string-substitute these before use */ + h->policy->u.mqtt.will_topic, + h->policy->u.mqtt.will_message, + h->policy->u.mqtt.subscribe, + h->policy->u.mqtt.topic + }; + size_t used_in, olen[4] = { 0, 0, 0, 0 }, tot = 0; + lws_strexp_t exp; + char *p, *ps[4]; + int n; + + memset(&ct->ccp, 0, sizeof(ct->ccp)); + + ct->ccp.client_id = "lwsMqttClient"; + ct->ccp.keep_alive = h->policy->u.mqtt.keep_alive; + ct->ccp.clean_start = h->policy->u.mqtt.clean_start; + ct->ccp.will_param.qos = h->policy->u.mqtt.will_qos; + ct->ccp.will_param.retain = h->policy->u.mqtt.will_retain; + h->u.mqtt.topic_qos.qos = h->policy->u.mqtt.qos; + + /* + * We're going to string-substitute several of these parameters, which + * have unknown, possibly large size. And, as their usage is deferred + * inside the asynchronous lifetime of the MQTT connection, they need + * to live on the heap. + * + * Notice these allocations at h->u.mqtt.heap_baggage belong to the + * underlying MQTT stream lifetime, not the logical SS lifetime, and + * are destroyed if present at connection error or close of the + * underlying connection. + * + * + * First, compute the length of each without producing strsubst output, + * and keep a running total. + */ + + for (n = 0; n < (int)LWS_ARRAY_SIZE(sources); n++) { + lws_strexp_init(&exp, (void *)h, lws_ss_exp_cb_metadata, + NULL, (size_t)-1); + if (lws_strexp_expand(&exp, sources[n], strlen(sources[n]), + &used_in, &olen[n]) != LSTRX_DONE) { + lwsl_err("%s: failed to subsitute %s\n", __func__, + sources[n]); + return 1; + } + tot += olen[n] + 1; + } + + /* + * Then, allocate enough space on the heap for the total of the + * substituted results + */ + + h->u.mqtt.heap_baggage = lws_malloc(tot, __func__); + if (!h->u.mqtt.heap_baggage) + return 1; + + /* + * Finally, issue the subsitutions one after the other into the single + * allocated result buffer and prepare pointers into them + */ + + p = h->u.mqtt.heap_baggage; + for (n = 0; n < (int)LWS_ARRAY_SIZE(sources); n++) { + lws_strexp_init(&exp, (void *)h, lws_ss_exp_cb_metadata, + p, (size_t)-1); + ps[n] = p; + if (lws_strexp_expand(&exp, sources[n], strlen(sources[n]), + &used_in, &olen[n]) != LSTRX_DONE) + return 1; + + p += olen[n] + 1; + } + + /* + * Point the guys who want the substituted content at the substituted + * strings + */ + + ct->ccp.will_param.topic = ps[SSCMM_STRSUB_WILL_TOPIC]; + ct->ccp.will_param.message = ps[SSCMM_STRSUB_WILL_MESSAGE]; + h->u.mqtt.subscribe_to = ps[SSCMM_STRSUB_SUBSCRIBE]; + h->u.mqtt.subscribe_to_len = olen[SSCMM_STRSUB_SUBSCRIBE]; + h->u.mqtt.topic_qos.name = ps[SSCMM_STRSUB_TOPIC]; + + i->method = "MQTT"; + i->mqtt_cp = &ct->ccp; + + i->alpn = "x-amzn-mqtt-ca"; + + /* share connections where possible */ + i->ssl_connection |= LCCSCF_PIPELINE; + + return 0; +} + +const struct ss_pcols ss_pcol_mqtt = { + "MQTT", + "x-amzn-mqtt-ca", //"mqtt/3.1.1", + &protocol_secstream_mqtt, + secstream_connect_munge_mqtt +}; diff -Nru libwebsockets-3.2.1/lib/secure-streams/protocols/ss-raw.c libwebsockets-4.1.6/lib/secure-streams/protocols/ss-raw.c --- libwebsockets-3.2.1/lib/secure-streams/protocols/ss-raw.c 1970-01-01 00:00:00.000000000 +0000 +++ libwebsockets-4.1.6/lib/secure-streams/protocols/ss-raw.c 2020-12-01 17:40:26.000000000 +0000 @@ -0,0 +1,166 @@ +/* + * libwebsockets - small server side websockets and web server implementation + * + * Copyright (C) 2019 - 2020 Andy Green + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to + * deal in the Software without restriction, including without limitation the + * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or + * sell copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS + * IN THE SOFTWARE. + * + * This is the glue that wires up raw-socket to Secure Streams. + */ + +#include + +int +secstream_raw(struct lws *wsi, enum lws_callback_reasons reason, void *user, + void *in, size_t len) +{ + lws_ss_handle_t *h = (lws_ss_handle_t *)lws_get_opaque_user_data(wsi); + uint8_t buf[LWS_PRE + 1520], *p = &buf[LWS_PRE], + *end = &buf[sizeof(buf) - 1]; + lws_ss_state_return_t r; + size_t buflen; + int f = 0; + + switch (reason) { + + case LWS_CALLBACK_CLIENT_CONNECTION_ERROR: + assert(h); + assert(h->policy); + lwsl_info("%s: h: %p, %s CLIENT_CONNECTION_ERROR: %s\n", __func__, + h, h->policy->streamtype, in ? (char *)in : "(null)"); + r = lws_ss_event_helper(h, LWSSSCS_UNREACHABLE); + if (r == LWSSSSRET_DESTROY_ME) + return _lws_ss_handle_state_ret(r, wsi, &h); + h->wsi = NULL; + r = lws_ss_backoff(h); + if (r != LWSSSSRET_OK) + return _lws_ss_handle_state_ret(r, wsi, &h); + break; + + case LWS_CALLBACK_RAW_CLOSE: + if (!h) + break; + lws_sul_cancel(&h->sul_timeout); + lwsl_info("%s: h: %p, %s LWS_CALLBACK_CLOSED_CLIENT_HTTP\n", + __func__, h, + h->policy ? h->policy->streamtype : "no policy"); + h->wsi = NULL; + if (h->policy && !(h->policy->flags & LWSSSPOLF_OPPORTUNISTIC) && +#if defined(LWS_WITH_SERVER) + !(h->info.flags & LWSSSINFLAGS_ACCEPTED) && /* not server */ +#endif + !h->txn_ok && !wsi->a.context->being_destroyed) { + r = lws_ss_backoff(h); + if (r != LWSSSSRET_OK) + return _lws_ss_handle_state_ret(r, wsi, &h); + break; + } + /* wsi is going down anyway */ + r = lws_ss_event_helper(h, LWSSSCS_DISCONNECTED); + if (r == LWSSSSRET_DESTROY_ME) + return _lws_ss_handle_state_ret(r, wsi, &h); + break; + + case LWS_CALLBACK_RAW_CONNECTED: + lwsl_info("%s: RAW_CONNECTED\n", __func__); + + h->retry = 0; + h->seqstate = SSSEQ_CONNECTED; + lws_sul_cancel(&h->sul); + r = lws_ss_event_helper(h, LWSSSCS_CONNECTED); + if (r != LWSSSSRET_OK) + return _lws_ss_handle_state_ret(r, wsi, &h); + + lws_validity_confirmed(wsi); + break; + + case LWS_CALLBACK_RAW_ADOPT: + lwsl_info("%s: RAW_ADOPT\n", __func__); + break; + + /* chunks of chunked content, with header removed */ + case LWS_CALLBACK_RAW_RX: + if (!h || !h->info.rx) + return 0; + + r = h->info.rx(ss_to_userobj(h), (const uint8_t *)in, len, 0); + if (r != LWSSSSRET_OK) + return _lws_ss_handle_state_ret(r, wsi, &h); + + return 0; /* don't passthru */ + + case LWS_CALLBACK_RAW_WRITEABLE: + lwsl_info("%s: RAW_WRITEABLE\n", __func__); + if (!h || !h->info.tx) + return 0; + + buflen = lws_ptr_diff(end, p); + r = h->info.tx(ss_to_userobj(h), h->txord++, p, &buflen, &f); + if (r == LWSSSSRET_TX_DONT_SEND) + return 0; + if (r < 0) + return _lws_ss_handle_state_ret(r, wsi, &h); + + /* + * flags are ignored with raw, there are no protocol payload + * boundaries, just an arbitrarily-fragmented bytestream + */ + + p += buflen; + if (lws_write(wsi, buf + LWS_PRE, lws_ptr_diff(p, buf + LWS_PRE), + LWS_WRITE_HTTP) != (int)lws_ptr_diff(p, buf + LWS_PRE)) { + lwsl_err("%s: write failed\n", __func__); + return -1; + } + + lws_set_timeout(wsi, 0, 0); + break; + + default: + break; + } + + return 0; +} + +static int +secstream_connect_munge_raw(lws_ss_handle_t *h, char *buf, size_t len, + struct lws_client_connect_info *i, + union lws_ss_contemp *ct) +{ + i->method = "RAW"; + + return 0; +} + + +const struct lws_protocols protocol_secstream_raw = { + "lws-secstream-raw", + secstream_raw, + 0, + 0, +}; + +const struct ss_pcols ss_pcol_raw = { + "raw", + "", + &protocol_secstream_raw, + secstream_connect_munge_raw, + NULL +}; diff -Nru libwebsockets-3.2.1/lib/secure-streams/protocols/ss-ws.c libwebsockets-4.1.6/lib/secure-streams/protocols/ss-ws.c --- libwebsockets-3.2.1/lib/secure-streams/protocols/ss-ws.c 1970-01-01 00:00:00.000000000 +0000 +++ libwebsockets-4.1.6/lib/secure-streams/protocols/ss-ws.c 2020-12-01 17:40:26.000000000 +0000 @@ -0,0 +1,209 @@ +/* + * libwebsockets - small server side websockets and web server implementation + * + * Copyright (C) 2019 - 2020 Andy Green + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to + * deal in the Software without restriction, including without limitation the + * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or + * sell copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS + * IN THE SOFTWARE. + */ + +#include + +static int +secstream_ws(struct lws *wsi, enum lws_callback_reasons reason, void *user, + void *in, size_t len) +{ + lws_ss_handle_t *h = (lws_ss_handle_t *)lws_get_opaque_user_data(wsi); + uint8_t buf[LWS_PRE + 1400]; + lws_ss_state_return_t r; + int f = 0, f1, n; + size_t buflen; + + switch (reason) { + + /* because we are protocols[0] ... */ + case LWS_CALLBACK_CLIENT_CONNECTION_ERROR: + lwsl_info("%s: CLIENT_CONNECTION_ERROR: %s\n", __func__, + in ? (char *)in : "(null)"); + if (!h) + break; + r = lws_ss_event_helper(h, LWSSSCS_UNREACHABLE); + if (r == LWSSSSRET_DESTROY_ME) + return _lws_ss_handle_state_ret(r, wsi, &h); + + h->wsi = NULL; + r = lws_ss_backoff(h); + if (r != LWSSSSRET_OK) + return _lws_ss_handle_state_ret(r, wsi, &h); + break; + + case LWS_CALLBACK_CLOSED: /* server */ + case LWS_CALLBACK_CLIENT_CLOSED: + if (!h) + break; + lws_sul_cancel(&h->sul_timeout); + r = lws_ss_event_helper(h, LWSSSCS_DISCONNECTED); + if (r == LWSSSSRET_DESTROY_ME) + return _lws_ss_handle_state_ret(r, wsi, &h); + + if (h->wsi) + lws_set_opaque_user_data(h->wsi, NULL); + h->wsi = NULL; + + if (reason == LWS_CALLBACK_CLIENT_CLOSED) { + if (h->policy && + !(h->policy->flags & LWSSSPOLF_OPPORTUNISTIC) && +#if defined(LWS_WITH_SERVER) + !(h->info.flags & LWSSSINFLAGS_ACCEPTED) && /* not server */ +#endif + !h->txn_ok && !wsi->a.context->being_destroyed) { + r = lws_ss_backoff(h); + if (r != LWSSSSRET_OK) + return _lws_ss_handle_state_ret(r, wsi, &h); + break; + } + } + break; + + case LWS_CALLBACK_ESTABLISHED: + case LWS_CALLBACK_CLIENT_ESTABLISHED: + h->retry = 0; + h->seqstate = SSSEQ_CONNECTED; + lws_sul_cancel(&h->sul); + r = lws_ss_event_helper(h, LWSSSCS_CONNECTED); + if (r != LWSSSSRET_OK) + return _lws_ss_handle_state_ret(r, wsi, &h); + break; + + case LWS_CALLBACK_RECEIVE: + case LWS_CALLBACK_CLIENT_RECEIVE: + // lwsl_user("LWS_CALLBACK_CLIENT_RECEIVE: read %d\n", (int)len); + if (!h || !h->info.rx) + return 0; + if (lws_is_first_fragment(wsi)) + f |= LWSSS_FLAG_SOM; + if (lws_is_final_fragment(wsi)) + f |= LWSSS_FLAG_EOM; + // lws_frame_is_binary(wsi); + + h->subseq = 1; + + r = h->info.rx(ss_to_userobj(h), (const uint8_t *)in, len, f); + if (r != LWSSSSRET_OK) + return _lws_ss_handle_state_ret(r, wsi, &h); + + return 0; /* don't passthru */ + + case LWS_CALLBACK_SERVER_WRITEABLE: + case LWS_CALLBACK_CLIENT_WRITEABLE: + // lwsl_notice("%s: ss %p: WRITEABLE\n", __func__, h); + if (!h || !h->info.tx) + return 0; + + if (h->seqstate != SSSEQ_CONNECTED) { + lwsl_warn("%s: seqstate %d\n", __func__, h->seqstate); + break; + } + + buflen = sizeof(buf) - LWS_PRE; + r = h->info.tx(ss_to_userobj(h), h->txord++, buf + LWS_PRE, + &buflen, &f); + if (r == LWSSSSRET_TX_DONT_SEND) + return 0; + if (r != LWSSSSRET_OK) + return _lws_ss_handle_state_ret(r, wsi, &h); + + f1 = lws_write_ws_flags(h->policy->u.http.u.ws.binary ? + LWS_WRITE_BINARY : LWS_WRITE_TEXT, + !!(f & LWSSS_FLAG_SOM), + !!(f & LWSSS_FLAG_EOM)); + + n = lws_write(wsi, buf + LWS_PRE, buflen, f1); + if (n < (int)buflen) { + lwsl_info("%s: write failed %d %d\n", __func__, + n, (int)buflen); + + return -1; + } + + return 0; + + default: + break; + } + + return lws_callback_http_dummy(wsi, reason, user, in, len); +} + +const struct lws_protocols protocol_secstream_ws = { + "lws-secstream-ws", + secstream_ws, + 0, + 0, +}; +/* + * Munge connect info according to protocol-specific considerations... this + * usually means interpreting aux in a protocol-specific way and using the + * pieces at connection setup time, eg, http url pieces. + * + * len bytes of buf can be used for things with scope until after the actual + * connect. + * + * For ws, protocol aux is ; + */ + +static int +secstream_connect_munge_ws(lws_ss_handle_t *h, char *buf, size_t len, + struct lws_client_connect_info *i, + union lws_ss_contemp *ct) +{ + const char *pbasis = h->policy->u.http.url; + size_t used_in, used_out; + lws_strexp_t exp; + + lwsl_notice("%s\n", __func__); + + /* i.path on entry is used to override the policy urlpath if not "" */ + + if (i->path[0]) + pbasis = i->path; + + if (!pbasis) + return 0; + + /* protocol aux is the path part ; ws subprotocol name */ + + i->path = buf; + buf[0] = '/'; + + lws_strexp_init(&exp, (void *)h, lws_ss_exp_cb_metadata, buf + 1, len - 1); + + if (lws_strexp_expand(&exp, pbasis, strlen(pbasis), + &used_in, &used_out) != LSTRX_DONE) + return 1; + + i->protocol = h->policy->u.http.u.ws.subprotocol; + + lwsl_notice("%s: url %s, ws subprotocol %s\n", __func__, buf, i->protocol); + + return 0; +} + +const struct ss_pcols ss_pcol_ws = { + "ws", "http/1.1", &protocol_secstream_ws, secstream_connect_munge_ws +}; diff -Nru libwebsockets-3.2.1/lib/secure-streams/README.md libwebsockets-4.1.6/lib/secure-streams/README.md --- libwebsockets-3.2.1/lib/secure-streams/README.md 1970-01-01 00:00:00.000000000 +0000 +++ libwebsockets-4.1.6/lib/secure-streams/README.md 2020-12-01 17:40:26.000000000 +0000 @@ -0,0 +1,730 @@ +# Secure Streams + +Secure Streams is a networking api that strictly separates payload from any +metadata. That includes the client endpoint address for the connection, the tls +trust chain and even the protocol used to connect to the endpoint. + +The user api just receives and transmits payload, and receives advisory +connection state information. + +The details about how the connections for different types of secure stream should +be made are held in JSON "policy database" initially passed in to the context +creation, but able to be updated from a remote copy. + +Both client and server networking can be handled using Secure Streams APIS. + +![overview](../doc-assets/ss-operation-modes.png) + +## Secure Streams CLIENT State lifecycle + +![overview](../doc-assets/ss-state-flow.png) + +Secure Streams are created using `lws_ss_create()`, after that they may acquire +underlying connections, and lose them, but the lifecycle of the Secure Stream +itself is not directly related to any underlying connection. + +Once created, Secure Streams may attempt connections, these may fail and once +the number of failures exceeds the count of attempts to conceal in the retry / +backoff policy, the stream reaches `LWSSSCS_ALL_RETRIES_FAILED`. The stream becomes +idle again until another explicit connection attempt is given. + +Once connected, the user code can use `lws_ss_request_tx()` to ask for a slot +to write to the peer, when this if forthcoming the tx handler can send a message. +If the underlying protocol gives indications of transaction success, such as, +eg, a 200 for http, or an ACK from MQTT, the stream state is called back with +an `LWSSSCS_QOS_ACK_REMOTE` or `LWSSSCS_QOS_NACK_REMOTE`. + +## SS Callback return handling + +SS state(), rx() and tx() can indicate with their return code some common +situations that should be handled by the caller. + +Constant|Scope|Meaning +---|---|--- +LWSSSSRET_TX_DONT_SEND|tx|This opportunity to send something was passed on +LWSSSSRET_OK|state, rx, tx|No error, continue doing what we're doing +LWSSSSRET_DISCONNECT_ME|state, rx|assertively disconnect from peer +LWSSSSRET_DESTROY_ME|state, rx|Caller should now destroy the stream itself +LWSSSSRET_SS_HANDLE_DESTROYED|state|Something handled a request to destroy the stream + +Destruction of the stream we're calling back on inside the callback is tricky, +it's preferable to return `LWSSSSRET_DESTROY_ME` if it is required, and let the +caller handle it. But in some cases, helpers called from the callbacks may +destroy the handle themselves, in that case the handler should return +`LWSSSSRET_SS_HANDLE_DESTROYED` indicating that the handle is already destroyed. + +## Secure Streams SERVER State lifecycle + +![overview](../doc-assets/ss-state-flow-server.png) + +You can also run servers defined using Secure Streams, the main difference is +that the user code must assertively create a secure stream of the server type +in order to create the vhost and listening socket. When this stream is +destroyed, the vhost is destroyed and the listen socket closed, otherwise it +does not perform any rx or tx, it just represents the server lifecycle. + +When client connections randomly arrive at the listen socket, new Secure Stream +objects are created along with accept sockets to represent each client +connection. As they represent the incoming connection, their lifecycle is the +same as that of the underlying connection. There is no retry concept since as +with eg, http servers, the clients may typically not be routable for new +connections initiated by the server. + +Since connections at socket level are already established, new connections are +immediately taken through CREATING, CONNECTING, CONNECTED states for +consistency. + +Some underlying protocols like http are "transactional", the server receives +a logical request and must reply with a logical response. The additional +state `LWSSSCS_SERVER_TXN` provides a point where the user code can set +transaction metadata before or in place of sending any payload. It's also +possible to defer this until any rx related to the transaction was received, +but commonly with http requests, there is no rx / body. Configuring the +response there may look like + +``` + /* + * We do want to ack the transaction... + */ + lws_ss_server_ack(m->ss, 0); + /* + * ... it's going to be text/html... + */ + lws_ss_set_metadata(m->ss, "mime", "text/html", 9); + /* + * ...it's going to be 128 byte (and request tx) + */ + lws_ss_request_tx_len(m->ss, 128); +``` + +Otherwise the general api usage is very similar to client usage. + +## Convention for rx and tx callback return + +Function|Return|Meaning +---|---|--- +tx|`LWSSSSRET_OK`|Send the amount of `buf` stored in `*len` +tx|`LWSSSSRET_TX_DONT_SEND`|Do not send anything +tx|`LWSSSSRET_DISCONNECT_ME`|Close the current connection +tx|`LWSSSSRET_DESTROY_ME`|Destroy the Secure Stream +rx|>=0|accepted +rx|<0|Close the current connection + +# JSON Policy Database + +Example JSON policy... formatting is shown for clarity but whitespace can be +omitted in the actual policy. + +Ordering is not critical in itself, but forward references are not allowed, +things must be defined before they are allowed to be referenced later in the +JSON. + + +``` +{ + "release": "01234567", + "product": "myproduct", + "schema-version": 1, + "retry": [{ + "default": { + "backoff": [1000, 2000, 3000, 5000, 10000], + "conceal": 5, + "jitterpc": 20 + } + }], + "certs": [{ + "isrg_root_x1": "MIIFazCCA1OgAw...AnX5iItreGCc=" + }, { + "LEX3_isrg_root_x1": "MIIFjTCCA3WgAwIB...WEsikxqEt" + }], + "trust_stores": [{ + "le_via_isrg": ["isrg_root_x1", "LEX3_isrg_root_x1"] + }], + "s": [{ + "mintest": { + "endpoint": "warmcat.com", + "port": 4443, + "protocol": "h1get", + "aux": "index.html", + "plugins": [], + "tls": true, + "opportunistic": true, + "retry": "default", + "tls_trust_store": "le_via_isrg" + } + }] +} +``` + +### `Release` + +Identifies the policy version + +### `Product` + +Identifies the product the policy should apply to + +### `Schema-version` + +The minimum version of the policy parser required to parse this policy + +### `via-socks5` + +Optional redirect for Secure Streams client traffic through a socks5 +proxy given in the format `address:port`, eg, `127.0.0.1:12345`. + +### `retry` + +A list of backoff schemes referred to in the policy + +### `backoff` + +An array of ms delays for each retry in turn + +### `conceal` + +The number of retries to conceal from higher layers before giving errors. If +this is larger than the number of times in the backoff array, then the last time +is used for the extra delays + +### `jitterpc` + +Percentage of the delay times mentioned in the backoff array that may be +randomly added to the figure from the array. For example with an array entry of +1000ms, and jitterpc of 20%, actual delays will be chosen randomly from 1000ms +through 1200ms. This is to stop retry storms triggered by a single event like +an outage becoming synchronized into a DoS. + +### `certs` + +Certificates needed for validation should be listed here each with a name. The +format is base64 DER, which is the same as the part of PEM that is inside the +start and end lines. + +### `trust_stores` + +Chains of certificates given in the `certs` section may be named and described +inside the `trust_stores` section. Each entry in `trust_stores` is created as +a vhost + tls context with the given name. Stream types can later be associated +with one of these to enforce validity checking of the remote server. + +Entries should be named using "name" and the stack array defined using "stack" + +### `s` + +These are an array of policies for the supported stream type names. + +### `server` + +**SERVER ONLY**: if set to `true`, the policy describes a secure streams +server. + +### `endpoint` + +**CLIENT**: The DNS address the secure stream should connect to. + +This may contain string symbols which will be replaced with the +corresponding streamtype metadata value at runtime. Eg, if the +streamtype lists a metadata name "region", it's then possible to +define the endpoint as, eg, `${region}.mysite.com`, and before +attempting the connection setting the stream's metadata item +"region" to the desired value, eg, "uk". + +If the endpoint string begins with `+`, then it's understood to +mean a connection to a Unix Domain Socket, for Linux `+@` means +the following Unix Domain Socket is in the Linux Abstract +Namespace and doesn't have a filesystem footprint. This is only +supported on unix-type and windows platforms and when lws was +configured with `-DLWS_UNIX_SOCK=1` + +**SERVER**: If given, the network interface name or IP address the listen socket +should bind to. + +### `port` + +**CLIENT**: The port number as an integer on the endpoint to connect to + +**SERVER**: The port number the server will listen on + +### `protocol` + +**CLIENT**: The wire protocol to connect to the endpoint with. Currently +supported streamtypes are + +|Wire protocol|Description| +|---|---| +|h1|http/1| +|h2|http/2| +|ws|http/1 Websockets| +|mqtt|mqtt 3.1.1| +|raw|| + +Raw protocol is a bit different than the others in that there is no protocol framing, +whatever is received on the connection is passed to the user rx callback and whatever +the tx callback provides is issued on to the connection. Because tcp can be +arbitrarily fragmented by any intermediary, such streams have to be regarded as an +ordered bytestream that may be fragmented at any byte without any meaning in terms +of message boundaries, for that reason SOM and EOM are ignored with raw. + +### `allow_redirects` + +By default redirects are not followed, if you wish a streamtype to observe them, eg, +because that's how it responds to a POST, set `"allow_redirects": true` + +### `tls` + +Set to `true` to enforce the stream travelling in a tls tunnel + +### `client cert` + +Set if the stream needs to authenticate itself using a tls client certificate. +Set to the certificate index counting from 0+. The certificates are managed +using lws_sytstem blobs. + +### `opportunistic` + +Set to `true` if the connection may be left dropped except when in use + +### `nailed_up` + +Set to `true` to have lws retry if the connection carrying this stream should +ever drop. + +### `retry` + +The name of the policy described in the `retry` section to apply to this +connection for retry + backoff + +### `timeout_ms` + +Optional timeout associated with streams of this streamtype. + +If user code applies the `lws_ss_start_timeout()` api on a stream with a +timeout of LWSSS_TIMEOUT_FROM_POLICY, the `timeout_ms` entry given in the +policy is applied. + +### `tls_trust_store` + +The name of the trust store described in the `trust_stores` section to apply +to validate the remote server cert. + +### `server_cert` + +**SERVER ONLY**: subject to change... the name of the x.509 cert that is the +server's tls certificate + +### `server_key` + +**SERVER ONLY**: subject to change... the name of the x.509 cert that is the +server's tls key + +### `swake_validity` + +Set to `true` if this streamtype is important enough for the functioning of the +device that its locally-initiated periodic connection validity checks of the +interval described in the associated retry / backoff selection, are important +enough to wake the whole system from low power suspend so they happen on +schedule. + +## http transport + +### `http_method` + +HTTP method to use with http-related protocols, like GET or POST. +Not required for ws. + +### `http_expect` + +Optionally indicates that success for HTTP transactions using this +streamtype is different than the default 200 - 299. + +Eg, you may choose to set this to 204 for Captive Portal Detect usage +if that's what you expect the server to reply with to indicate +success. In that case, anything other than 204 will be treated as a +connection failure. + +### `http_fail_redirect` + +Set to `true` if you want to fail the connection on meeting an +http redirect. This is needed to, eg, detect Captive Portals +correctly. Normally, if on https, you would want the default behaviour +of following the redirect. + +### `http_url` + +Url path to use with http-related protocols + +The URL path can include metatadata like this + +"/mypath?whatever=${metadataname}" + +${metadataname} will be replaced by the current value of the +same metadata name. The metadata names must be listed in the +"metadata": [ ] section. + +### `http_auth_header` + +The name of the header that takes the auth token, with a trailing ':', eg + +``` + "http_auth_header": "authorization:" +``` + +### `http_dsn_header` + +The name of the header that takes the dsn token, with a trailing ':', eg + +``` + "http_dsn_header": "x-dsn:" +``` + +### `http_fwv_header` + +The name of the header that takes the firmware version token, with a trailing ':', eg + +``` + "http_fwv_header": "x-fw-version:" +``` + +### `http_devtype_header` + +The name of the header that takes the device type token, with a trailing ':', eg + +``` + "http_devtype_header": "x-device-type:" +``` + +### `http_auth_preamble` + +An optional string that precedes the auth token, eg + +``` + "http_auth_preamble": "bearer " +``` + +### `auth_hexify` + +Convert the auth token to hex ('A' -> "41") before transporting. Not necessary if the +auth token is already in printable string format suitable for transport. Needed if the +auth token is a chunk of 8-bit binary. + +### `nghttp2_quirk_end_stream` + +Set this to `true` if the peer server has the quirk it won't send a response until we have +sent an `END_STREAM`, even though we have sent headers with `END_HEADERS`. + +### `h2q_oflow_txcr` + +Set this to `true` if the peer server has the quirk it sends an maximum initial tx credit +of 0x7fffffff and then later increments it illegally. + +### `http_multipart_ss_in` + +Indicates that SS should parse any incoming multipart mime on this stream + +### `http_multipart_name` + +Indicates this stream goes out using multipart mime, and provides the name part of the +multipart header + +### `http_multipart_filename` + +Indicates this stream goes out using multipart mime, and provides the filename part of the +multipart header + +### `http_multipart_content_type` + +The `content-type` to mark up the multipart mime section with if present + +### `http_www_form_urlencoded` + +Indicate the data is sent in `x-www-form-urlencoded` form + +### `rideshare` + +For special cases where one logically separate stream travels with another when using this +protocol. Eg, a single multipart mime transaction carries content from two or more streams. + +## ws transport + +### `ws_subprotocol` + +** CLIENT **: Name of the ws subprotocol to request from the server + +** SERVER **: Name of the subprotocol we will accept + +### `ws_binary` + +Use if the ws messages are binary + +## MQTT transport + +### `mqtt_topic` + +Set the topic this streamtype uses for writes + +### `mqtt_subscribe` + +Set the topic this streamtype subscribes to + +### `mqtt qos` + +Set the QOS level for this streamtype + +### `mqtt_keep_alive` + +16-bit number representing MQTT keep alive for the stream. + +This is applied at connection time... where different streams may bind to the +same underlying MQTT connection, all the streams should have an identical +setting for this. + +### `mqtt_clean_start` + +Set to true if the connection should use MQTT's "clean start" feature. + +This is applied at connection time... where different streams may bind to the +same underlying MQTT connection, all the streams should have an identical +setting for this. + +### `mqtt_will_topic` + +Set the topic of the connection's will message, if any (there is none by default). + +This is applied at connection time... where different streams may bind to the +same underlying MQTT connection, all the streams should have an identical +setting for this. + +### `mqtt_will_message` + +Set the content of the connect's will message, if any (there is none by default). + +This is applied at connection time... where different streams may bind to the +same underlying MQTT connection, all the streams should have an identical +setting for this. + +### `mqtt_will_qos` + +Set the QoS of the will message, if any (there is none by default). + +This is applied at connection time... where different streams may bind to the +same underlying MQTT connection, all the streams should have an identical +setting for this. + +### `mqtt_will_retain` + +Set to true if the connection should use MQTT's "will retain" feature, if there +is a will message (there is none by default). + +This is applied at connection time... where different streams may bind to the +same underlying MQTT connection, all the streams should have an identical +setting for this. + +## Loading and using updated remote policy + +If the default, hardcoded policy includes a streamtype `fetch_policy`, +during startup when lws_system reaches the POLICY state, lws will use +a Secure Stream of type `fetch_policy` to download, parse and update +the policy to use it. + +The secure-streams-proxy minimal example shows how this is done and +fetches its real policy from warmcat.com at startup using the built-in +one. + +## Applying streamtype policy overlays + +This is intended for modifying policies at runtime for testing, eg, to +force error paths to be taken. After the main policy is processed, you +may parse additional, usually smaller policy fragments on top of it. + +Where streamtype names in the new fragment already exist in the current +parsed policy, the settings in the fragment are applied over the parsed +policy, overriding settings. There's a simple api to enable this by +giving it the override JSON in one string + +``` +int +lws_ss_policy_overlay(struct lws_context *context, const char *overlay); +``` + +but there are also other apis available that can statefully process +larger overlay fragments if needed. + +An example overlay fragment looks like this + +``` + { "s": [{ "captive_portal_detect": { + "endpoint": "google.com", + "http_url": "/", + "port": 80 + }}]} +``` + +ie the overlay fragment completely follows the structure of the main policy, +just misses out anything it doesn't override. + +Currently ONLY streamtypes may be overridden. + +You can see an example of this in use in `minimal-secure-streams` example +where `--force-portal` and `--force-no-internet` options cause the captive +portal detect streamtype to be overridden to force the requested kind of +outcome. + +## Captive Portal Detection + +If the policy contains a streamtype `captive_portal_detect` then the +type of transaction described there is automatically performed after +acquiring a DHCP address to try to determine the captive portal +situation. + +``` + "captive_portal_detect": { + "endpoint": "connectivitycheck.android.com", + "port": 80, + "protocol": "h1", + "http_method": "GET", + "http_url": "generate_204", + "opportunistic": true, + "http_expect": 204, + "http_fail_redirect": true + } +``` + +## Stream serialization and proxying + +By default Secure Streams expects to make the outgoing connection described in +the policy in the same process / thread, this suits the case where all the +participating clients are in the same statically-linked image. + +In this case the `lws_ss_` apis are fulfilled locally by secure-streams.c and +policy.c for policy lookups. + +However it also supports serialization, where the SS api can be streamed over +another transport such as a Unix Domain Socket connection. This suits the case +where the clients are actually in different processes in, eg, Linux or Android. + +In those cases, you run a proxy process (minimal-secure-streams-proxy) that +listens on a Unix Domain Socket and is connected to by one or more other +processes that pass their SS API activity to the proxy for fulfilment (or +onward proxying). + +Each Secure Stream that is created then in turn creates a private Unix Domain +Socket connection to the proxy for each stream. + +In this case the proxy uses secure-streams.c and policy.c as before to fulfil +the inbound proxy streams, but uses secure-streams-serialize.c to serialize and +deserialize the proxied SS API activity. The proxy clients define +LWS_SS_USE_SSPC either very early in their sources before the includes, or on +the compiler commandline... this causes the lws_ss_ apis to be replaced at +preprocessor time with lws_sspc_ equivalents. These serialize the api action +and pass it to the proxy over a Unix Domain Socket for fulfilment, the results +and state changes etc are streamed over the Unix Domain Socket and presented to +the application exactly the same as if it was being fulfilled locally. + +To demonstrate this, some minimal examples, eg, minimal-secure-streams and +mimimal-secure-streams-avs build themselves both ways, once with direct SS API +fulfilment and once with Unix Domain Socket proxying and -client appended on the +executable name. To test the -client variants, run minimal-secure-streams-proxy +on the same machine. + +## Complicated scenarios with secure streams proxy + +As mentioned above, Secure Streams has two modes, by default the application +directly parses the policy and makes the outgoing connections itself. +However when configured at cmake with + +``` +-DLWS_WITH_SOCKS5=1 -DLWS_WITH_SECURE_STREAMS=1 -DLWS_WITH_SECURE_STREAMS_PROXY_API=1 -DLWS_WITH_MINIMAL_EXAMPLES=1 +``` + +and define `LWS_SS_USE_SSPC` when building the application, applications forward +their network requests to a local or remote SS proxy for fulfilment... and only +the SS proxy has the system policy. By default, the SS proxy is on the local +machine and is connected to via a Unix Domain Socket, but tcp links are also +possible. (Note the proxied traffic is not encrypyed by default.) + +Using the configuration above, the example SS applications are built two ways, +once for direct connection fulfilment (eg, `./bin/lws-minimal-secure-streams`), +and once with `LWS_SS_USE_SSPC` also defined so it connects via an SS proxy, +(eg, `./bin/lws-minimal-secure-streams-client`). + +## Testing an example scenario with SS Proxy and socks5 proxy + +``` + [ SS application ] --- tcp --- [ socks 5 proxy ] --- tcp --- [ SS proxy ] --- internet +``` + +In this scenario, everything is on localhost, the socks5 proxy listens on :1337 and +the SS proxy listens on :1234. The SS application connects to the socks5 +proxy to get to the SS proxy, which then goes out to the internet + +### 1 Start the SS proxy + +Tell it to listen on lo interface on port 1234 + +``` +$ ./bin/lws-minimal-secure-streams-proxy -p 1234 -i lo +``` + +### 2 Start the SOCKS5 proxy + +``` +$ ssh -D 1337 -N -v localhost +``` + +The -v makes connections to the proxy visible in the terminal for testing + +### 3 Run the SS application + +The application is told to make all connections via the socks5 proxy at +127.0.0.1:1337, and to fulfil its SS connections via an SS proxy, binding +connections to 127.0.0.1 (ipv4 lo interface, -1), to 127.0.0.1:1234 (-a/-p). + +``` +socks_proxy=127.0.0.1:1337 ./bin/lws-minimal-secure-streams-client -p 1234 -i 127.0.0.1 -a 127.0.0.1 +``` + +You can confirm this goes through the ssh socks5 proxy to get to the SS proxy +and fulfil the connection. + +## Using static policies + +If one of your targets is too constrained to make use of dynamic JSON policies, but +using SS and the policies is attractive for wider reasons, you can use a static policy +built into the firmware for the constrained target. + +The secure-streams example "policy2c" (which runs on the build machine, not the device) + +https://libwebsockets.org/git/libwebsockets/tree/minimal-examples/secure-streams/minimal-secure-streams-policy2c + +accepts a normal JSON policy on stdin, and emits a C code representation that can be +included directly in the firmware. + +https://libwebsockets.org/git/libwebsockets/tree/minimal-examples/secure-streams/minimal-secure-streams-staticpolicy/static-policy.h + +Using this technique it's possible to standardize on maintaining JSON policies across a +range of devices with different contraints, and use the C conversion of the policy on devices +that are too small. + +The Cmake option `LWS_WITH_SECURE_STREAMS_STATIC_POLICY_ONLY` should be enabled to use this +mode, it will not build the JSON parser (and the option for LEJP can also be disabled if +you're not otherwise using it, saving an additional couple of KB). + +Notice policy2c example tool must be built with `LWS_ROLE_H1`, `LWS_ROLE_H2`, `LWS_ROLE_WS` +and `LWS_ROLE_MQTT` enabled so it can handle any kind of policy. + +## HTTP and ws serving + +All ws servers start out as http servers... for that reason ws serving is +handled as part of http serving, if you give the `ws_subprotocol` entry to the +streamtype additionally, the server will also accept upgrades to ws. + +To help the user code understand if the upgrade occurred, there's a special +state `LWSSSCS_SERVER_UPGRADE`, so subsequent rx and tx can be understood to +have come from the upgraded protocol. To allow separation of rx and tx +handling between http and ws, there's a ss api `lws_ss_change_handlers()` +which allows dynamically setting SS handlers. + +Since the http and ws upgrade identity is encapsulated in one streamtype, the +user object for the server streamtype should contain related user data for both +http and ws underlying protocol identity. diff -Nru libwebsockets-3.2.1/lib/secure-streams/secure-streams.c libwebsockets-4.1.6/lib/secure-streams/secure-streams.c --- libwebsockets-3.2.1/lib/secure-streams/secure-streams.c 1970-01-01 00:00:00.000000000 +0000 +++ libwebsockets-4.1.6/lib/secure-streams/secure-streams.c 2020-12-01 17:40:26.000000000 +0000 @@ -0,0 +1,1080 @@ +/* + * libwebsockets - small server side websockets and web server implementation + * + * Copyright (C) 2019 - 2020 Andy Green + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to + * deal in the Software without restriction, including without limitation the + * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or + * sell copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS + * IN THE SOFTWARE. + */ + +#include + +static const struct ss_pcols *ss_pcols[] = { +#if defined(LWS_ROLE_H1) + &ss_pcol_h1, /* LWSSSP_H1 */ +#else + NULL, +#endif +#if defined(LWS_ROLE_H2) + &ss_pcol_h2, /* LWSSSP_H2 */ +#else + NULL, +#endif +#if defined(LWS_ROLE_WS) + &ss_pcol_ws, /* LWSSSP_WS */ +#else + NULL, +#endif +#if defined(LWS_ROLE_MQTT) + &ss_pcol_mqtt, /* LWSSSP_MQTT */ +#else + NULL, +#endif + &ss_pcol_raw, /* LWSSSP_RAW */ + NULL, +}; + +static const char *state_names[] = { + "LWSSSCS_CREATING", + "LWSSSCS_DISCONNECTED", + "LWSSSCS_UNREACHABLE", + "LWSSSCS_AUTH_FAILED", + "LWSSSCS_CONNECTED", + "LWSSSCS_CONNECTING", + "LWSSSCS_DESTROYING", + "LWSSSCS_POLL", + "LWSSSCS_ALL_RETRIES_FAILED", + "LWSSSCS_QOS_ACK_REMOTE", + "LWSSSCS_QOS_NACK_REMOTE", + "LWSSSCS_QOS_ACK_LOCAL", + "LWSSSCS_QOS_NACK_LOCAL", + "LWSSSCS_TIMEOUT", + "LWSSSCS_SERVER_TXN", + "LWSSSCS_SERVER_UPGRADE", +}; + +const char * +lws_ss_state_name(int state) +{ + if (state >= (int)LWS_ARRAY_SIZE(state_names)) + return "unknown"; + + return state_names[state]; +} + +lws_ss_state_return_t +lws_ss_event_helper(lws_ss_handle_t *h, lws_ss_constate_t cs) +{ + lws_ss_state_return_t r; + + if (!h) + return LWSSSSRET_OK; + +#if defined(LWS_WITH_SEQUENCER) + /* + * A parent sequencer for the ss is optional, if we have one, keep it + * informed of state changes on the ss connection + */ + if (h->seq && cs != LWSSSCS_DESTROYING) + lws_seq_queue_event(h->seq, LWSSEQ_SS_STATE_BASE + cs, + (void *)h, NULL); +#endif + + if (h->info.state) { + r = h->info.state(ss_to_userobj(h), NULL, cs, 0); +#if defined(LWS_WITH_SERVER) + if ((h->info.flags & LWSSSINFLAGS_ACCEPTED) && + cs == LWSSSCS_DISCONNECTED) + r = LWSSSSRET_DESTROY_ME; +#endif + return r; + } + + return LWSSSSRET_OK; +} + +int +_lws_ss_handle_state_ret(lws_ss_state_return_t r, struct lws *wsi, + lws_ss_handle_t **ph) +{ + if (r == LWSSSSRET_DESTROY_ME) { + if (wsi) + lws_set_opaque_user_data(wsi, NULL); + (*ph)->wsi = NULL; + lws_ss_destroy(ph); + } + + return -1; /* close connection */ +} + +static void +lws_ss_timeout_sul_check_cb(lws_sorted_usec_list_t *sul) +{ + lws_ss_handle_t *h = lws_container_of(sul, lws_ss_handle_t, sul); + + lwsl_notice("%s: retrying ss h %p (%s) after backoff\n", __func__, h, + h->policy->streamtype); + /* we want to retry... */ + h->seqstate = SSSEQ_DO_RETRY; + + lws_ss_request_tx(h); +} + +int +lws_ss_exp_cb_metadata(void *priv, const char *name, char *out, size_t *pos, + size_t olen, size_t *exp_ofs) +{ + lws_ss_handle_t *h = (lws_ss_handle_t *)priv; + const char *replace = NULL; + size_t total, budget; + lws_ss_metadata_t *md = lws_ss_policy_metadata(h->policy, name); + + if (!md) { + lwsl_err("%s: Unknown metadata %s\n", __func__, name); + + return LSTRX_FATAL_NAME_UNKNOWN; + } + + lwsl_info("%s %s %d\n", __func__, name, (int)md->length); + + replace = h->metadata[md->length].value; + total = h->metadata[md->length].length; + // lwsl_hexdump_err(replace, total); + + budget = olen - *pos; + total -= *exp_ofs; + if (total < budget) + budget = total; + + if (out) + memcpy(out + *pos, replace + (*exp_ofs), budget); + *exp_ofs += budget; + *pos += budget; + + if (budget == total) + return LSTRX_DONE; + + return LSTRX_FILLED_OUT; +} + +int +lws_ss_set_timeout_us(lws_ss_handle_t *h, lws_usec_t us) +{ + struct lws_context_per_thread *pt = &h->context->pt[h->tsi]; + + h->sul.cb = lws_ss_timeout_sul_check_cb; + __lws_sul_insert_us(&pt->pt_sul_owner[ + !!(h->policy->flags & LWSSSPOLF_WAKE_SUSPEND__VALIDITY)], + &h->sul, us); + + return 0; +} + +lws_ss_state_return_t +lws_ss_backoff(lws_ss_handle_t *h) +{ + uint64_t ms; + char conceal; + + if (h->seqstate == SSSEQ_RECONNECT_WAIT) + return LWSSSSRET_OK; + + /* figure out what we should do about another retry */ + + lwsl_info("%s: ss %p: retry backoff after failure\n", __func__, h); + ms = lws_retry_get_delay_ms(h->context, h->policy->retry_bo, + &h->retry, &conceal); + if (!conceal) { + lwsl_info("%s: ss %p: abandon conn attempt \n",__func__, h); + h->seqstate = SSSEQ_IDLE; + + return lws_ss_event_helper(h, LWSSSCS_ALL_RETRIES_FAILED); + } + + h->seqstate = SSSEQ_RECONNECT_WAIT; + lws_ss_set_timeout_us(h, ms * LWS_US_PER_MS); + + lwsl_info("%s: ss %p: retry wait %"PRIu64"ms\n", __func__, h, ms); + + return LWSSSSRET_OK; +} + +#if defined(LWS_WITH_SYS_SMD) + +/* + * Local SMD <-> SS + * + * We pass received messages through to the SS handler synchronously, using the + * lws service thread context. + * + * After the SS is created and registered, still nothing is going to come here + * until the peer sends us his rx_class_mask and we update his registration with + * it, because from SS creation his rx_class_mask defaults to 0. + */ + +static int +lws_smd_ss_cb(void *opaque, lws_smd_class_t _class, + lws_usec_t timestamp, void *buf, size_t len) +{ + lws_ss_handle_t *h = (lws_ss_handle_t *)opaque; + uint8_t *p = (uint8_t *)buf - LWS_SMD_SS_RX_HEADER_LEN; + + /* + * When configured with SS enabled, lws over-allocates + * LWS_SMD_SS_RX_HEADER_LEN bytes behind the payload of the queued + * message, for prepending serialized class and timestamp data in-band + * with the payload. + */ + + lws_ser_wu64be(p, _class); + lws_ser_wu64be(p + 8, timestamp); + + if (h->info.rx) + h->info.rx((void *)&h[1], p, len + LWS_SMD_SS_RX_HEADER_LEN, + LWSSS_FLAG_SOM | LWSSS_FLAG_EOM); + + return 0; +} + +static void +lws_ss_smd_tx_cb(lws_sorted_usec_list_t *sul) +{ + lws_ss_handle_t *h = lws_container_of(sul, lws_ss_handle_t, u.smd.sul_write); + uint8_t buf[LWS_SMD_SS_RX_HEADER_LEN + LWS_SMD_MAX_PAYLOAD], *p; + size_t len = sizeof(buf); + lws_smd_class_t _class; + int flags = 0, n; + + if (!h->info.tx) + return; + + n = h->info.tx(&h[1], h->txord++, buf, &len, &flags); + if (n) + /* nonzero return means don't want to send anything */ + return; + + // lwsl_notice("%s: (SS %p bound to _lws_smd creates message) tx len %d\n", __func__, h, (int)len); + // lwsl_hexdump_notice(buf, len); + + assert(len >= LWS_SMD_SS_RX_HEADER_LEN); + _class = (lws_smd_class_t)lws_ser_ru64be(buf); + p = lws_smd_msg_alloc(h->context, _class, len - LWS_SMD_SS_RX_HEADER_LEN); + if (!p) { + // this can be rejected if nobody listening for this class + //lwsl_notice("%s: failed to alloc\n", __func__); + return; + } + + memcpy(p, buf + LWS_SMD_SS_RX_HEADER_LEN, len - LWS_SMD_SS_RX_HEADER_LEN); + if (lws_smd_msg_send(h->context, p)) { + lwsl_notice("%s: failed to queue\n", __func__); + return; + } +} + +#endif + +int +_lws_ss_client_connect(lws_ss_handle_t *h, int is_retry) +{ + const char *prot, *_prot, *ipath, *_ipath, *ads, *_ads; + struct lws_client_connect_info i; + const struct ss_pcols *ssp; + size_t used_in, used_out; + union lws_ss_contemp ct; + char path[1024], ep[96]; + lws_ss_state_return_t r; + int port, _port, tls; + lws_strexp_t exp; + + if (!h->policy) { + lwsl_err("%s: ss with no policy\n", __func__); + + return -1; + } + + /* + * We are already bound to a sink? + */ + +// if (h->h_sink) +// return 0; + + if (!is_retry) + h->retry = 0; + +#if defined(LWS_WITH_SYS_SMD) + if (h->policy == &pol_smd) { + + if (h->u.smd.smd_peer) + return 0; + + // lwsl_notice("%s: received connect for _lws_smd, registering for class mask 0x%x\n", + // __func__, h->info.manual_initial_tx_credit); + + h->u.smd.smd_peer = lws_smd_register(h->context, h, + (h->info.flags & LWSSSINFLAGS_PROXIED) ? + LWSSMDREG_FLAG_PROXIED_SS : 0, + h->info.manual_initial_tx_credit, + lws_smd_ss_cb); + if (!h->u.smd.smd_peer) + return -1; + + if (lws_ss_event_helper(h, LWSSSCS_CONNECTING)) + return -1; + // lwsl_err("%s: registered SS SMD\n", __func__); + if (lws_ss_event_helper(h, LWSSSCS_CONNECTED)) + return -1; + return 0; + } +#endif + + /* + * We're going to substitute ${metadata} in the endpoint at connection- + * time, so this can be set dynamically... + */ + + lws_strexp_init(&exp, (void *)h, lws_ss_exp_cb_metadata, ep, sizeof(ep)); + + if (lws_strexp_expand(&exp, h->policy->endpoint, + strlen(h->policy->endpoint), + &used_in, &used_out) != LSTRX_DONE) { + lwsl_err("%s: address strexp failed\n", __func__); + + return -1; + } + + /* + * ... in some cases, we might want the user to be able to override + * some policy settings by what he provided in there. For example, + * if he set the endpoint to "https://myendpoint.com:4443/mypath" it + * might be quite convenient to override the policy to follow the info + * that was given for at least server, port and the url path. + */ + + _port = port = h->policy->port; + _prot = prot = NULL; + _ipath = ipath = ""; + _ads = ads = ep; + + if (strchr(ep, ':') && + !lws_parse_uri(ep, &_prot, &_ads, &_port, &_ipath)) { + lwsl_debug("%s: using uri parse results '%s' '%s' %d '%s'\n", + __func__, _prot, _ads, _port, _ipath); + prot = _prot; + ads = _ads; + port = _port; + ipath = _ipath; + } + + memset(&i, 0, sizeof i); /* otherwise uninitialized garbage */ + i.context = h->context; + tls = !!(h->policy->flags & LWSSSPOLF_TLS); + + if (prot && (!strcmp(prot, "http") || !strcmp(prot, "ws") || + !strcmp(prot, "mqtt"))) + tls = 0; + + if (tls) { + lwsl_info("%s: using tls\n", __func__); + i.ssl_connection = LCCSCF_USE_SSL; + + if (!h->policy->trust.store) + lwsl_info("%s: using platform trust store\n", __func__); + else { + + i.vhost = lws_get_vhost_by_name(h->context, + h->policy->trust.store->name); + if (!i.vhost) { + lwsl_err("%s: missing vh for policy %s\n", + __func__, + h->policy->trust.store->name); + + return -1; + } + } + } + + if (h->policy->flags & LWSSSPOLF_WAKE_SUSPEND__VALIDITY) + i.ssl_connection |= LCCSCF_WAKE_SUSPEND__VALIDITY; + + i.address = ads; + i.port = port; + i.host = i.address; + i.origin = i.address; + i.opaque_user_data = h; + i.seq = h->seq; + i.retry_and_idle_policy = h->policy->retry_bo; + i.sys_tls_client_cert = h->policy->client_cert; + + i.path = ipath; + /* if this is not "", munge should use it instead of policy + * url path + */ + + ssp = ss_pcols[(int)h->policy->protocol]; + if (!ssp) { + lwsl_err("%s: unsupported protocol\n", __func__); + + return -1; + } + i.alpn = ssp->alpn; + + /* + * For http, we can get the method from the http object, override in + * the protocol-specific munge callback below if not http + */ + i.method = h->policy->u.http.method; + i.protocol = ssp->protocol->name; /* lws protocol name */ + i.local_protocol_name = i.protocol; + + if (ssp->munge) /* eg, raw doesn't use; endpoint strexp already done */ + ssp->munge(h, path, sizeof(path), &i, &ct); + + i.pwsi = &h->wsi; + +#if defined(LWS_WITH_SSPLUGINS) + if (h->policy->plugins[0] && h->policy->plugins[0]->munge) + h->policy->plugins[0]->munge(h, path, sizeof(path)); +#endif + + lwsl_info("%s: connecting %s, '%s' '%s' %s\n", __func__, i.method, + i.alpn, i.address, i.path); + + h->txn_ok = 0; + r = lws_ss_event_helper(h, LWSSSCS_CONNECTING); + if (r) + return r; + + if (!lws_client_connect_via_info(&i)) { + r = lws_ss_event_helper(h, LWSSSCS_UNREACHABLE); + if (r) + return r; + + r = lws_ss_backoff(h); + if (r) + return r; + + return 1; + } + + return 0; +} + +int +lws_ss_client_connect(lws_ss_handle_t *h) +{ + return _lws_ss_client_connect(h, 0); +} + +/* + * Public API + */ + +/* + * Create either a stream or a sink + */ + +int +lws_ss_create(struct lws_context *context, int tsi, const lws_ss_info_t *ssi, + void *opaque_user_data, lws_ss_handle_t **ppss, + struct lws_sequencer *seq_owner, const char **ppayload_fmt) +{ + struct lws_context_per_thread *pt = &context->pt[tsi]; + const lws_ss_policy_t *pol; + lws_ss_metadata_t *smd; + lws_ss_handle_t *h; + size_t size; + void **v; + char *p; + int n; + + pol = lws_ss_policy_lookup(context, ssi->streamtype); + if (!pol) { + lwsl_info("%s: unknown stream type %s\n", __func__, + ssi->streamtype); + return 1; + } + + if (ssi->flags & LWSSSINFLAGS_REGISTER_SINK) { + /* + * This can register a secure streams sink as well as normal + * secure streams connections. If that's what's happening, + * confirm the policy agrees that this streamtype should be + * directed to a sink. + */ + if (!(pol->flags & LWSSSPOLF_LOCAL_SINK)) { + /* + * Caller wanted to create a sink for this streamtype, + * but the policy does not agree the streamtype should + * be routed to a local sink. + */ + lwsl_err("%s: %s policy does not allow local sink\n", + __func__, ssi->streamtype); + + return 1; + } + } else { + + if (!(pol->flags & LWSSSPOLF_LOCAL_SINK)) { + + } +// lws_dll2_foreach_safe(&pt->ss_owner, NULL, lws_ss_destroy_dll); + } + + /* + * We overallocate and point to things in the overallocation... + * + * 1) the user_alloc from the stream info + * 2) network auth plugin instantiation data + * 3) stream auth plugin instantiation data + * 4) as many metadata pointer structs as the policy tells + * 5) the streamtype name (length is not aligned) + * + * ... when we come to destroy it, just one free to do. + */ + + size = sizeof(*h) + ssi->user_alloc + strlen(ssi->streamtype) + 1; +#if defined(LWS_WITH_SSPLUGINS) + if (pol->plugins[0]) + size += pol->plugins[0]->alloc; + if (pol->plugins[1]) + size += pol->plugins[1]->alloc; +#endif + size += pol->metadata_count * sizeof(lws_ss_metadata_t); + + h = lws_zalloc(size, __func__); + if (!h) + return 2; + + h->info = *ssi; + h->policy = pol; + h->context = context; + h->tsi = tsi; + h->seq = seq_owner; + + /* start of overallocated area */ + p = (char *)&h[1]; + + /* set the handle pointer in the user data struct */ + v = (void **)(p + ssi->handle_offset); + *v = h; + + /* set the opaque user data in the user data struct */ + v = (void **)(p + ssi->opaque_user_data_offset); + *v = opaque_user_data; + + p += ssi->user_alloc; + +#if defined(LWS_WITH_SSPLUGINS) + if (pol->plugins[0]) { + h->nauthi = p; + p += pol->plugins[0]->alloc; + } + if (pol->plugins[1]) { + h->sauthi = p; + p += pol->plugins[1]->alloc; + } +#endif + + if (pol->metadata_count) { + h->metadata = (lws_ss_metadata_t *)p; + p += pol->metadata_count * sizeof(lws_ss_metadata_t); + + lwsl_info("%s: %s metadata count %d\n", __func__, + pol->streamtype, pol->metadata_count); + } + + smd = pol->metadata; + for (n = 0; n < pol->metadata_count; n++) { + h->metadata[n].name = smd->name; + if (n + 1 == pol->metadata_count) + h->metadata[n].next = NULL; + else + h->metadata[n].next = &h->metadata[n + 1]; + smd = smd->next; + } + + memcpy(p, ssi->streamtype, strlen(ssi->streamtype) + 1); + /* don't mark accepted ss as being the server */ + if (ssi->flags & LWSSSINFLAGS_SERVER) + h->info.flags &= ~LWSSSINFLAGS_SERVER; + h->info.streamtype = p; + + lws_pt_lock(pt, __func__); + lws_dll2_add_head(&h->list, &pt->ss_owner); + lws_pt_unlock(pt); + + if (ppss) + *ppss = h; + + if (ppayload_fmt) + *ppayload_fmt = pol->payload_fmt; + + if (ssi->flags & LWSSSINFLAGS_SERVER) + /* + * return early for accepted connection flow + */ + return 0; + +#if defined(LWS_WITH_SYS_SMD) + /* + * For a local Secure Streams connection + */ + if (!(ssi->flags & LWSSSINFLAGS_PROXIED) && + pol == &pol_smd) { + lws_ss_state_return_t r; + /* + * So he has asked to be wired up to SMD over a SS link. + * Register him as an smd participant in his own right. + * + * Just for this case, ssi->manual_initial_tx_credit is used + * to set the rx class mask (this is part of the SS serialization + * format as well) + */ + h->u.smd.smd_peer = lws_smd_register(context, h, 0, + ssi->manual_initial_tx_credit, + lws_smd_ss_cb); + if (!h->u.smd.smd_peer) + goto late_bail; + lwsl_info("%s: registered SS SMD\n", __func__); + r = lws_ss_event_helper(h, LWSSSCS_CONNECTING); + if (r) + return r; + r = lws_ss_event_helper(h, LWSSSCS_CONNECTED); + if (r) + return r; + } +#endif + +#if defined(LWS_WITH_SERVER) + if (h->policy->flags & LWSSSPOLF_SERVER) { + const struct lws_protocols *pprot[3], **ppp = &pprot[0]; + struct lws_context_creation_info i; + struct lws_vhost *vho; + + lwsl_info("%s: creating server\n", __func__); + + /* + * This streamtype represents a server, we're being asked to + * instantiate a corresponding vhost for it + */ + + memset(&i, 0, sizeof i); + + i.iface = h->policy->endpoint; + i.vhost_name = h->policy->streamtype; + i.port = h->policy->port; + + if (!ss_pcols[h->policy->protocol]) { + lwsl_err("%s: unsupp protocol", __func__); + goto late_bail; + } + + *ppp++ = ss_pcols[h->policy->protocol]->protocol; +#if defined(LWS_ROLE_WS) + if (h->policy->u.http.u.ws.subprotocol) + /* + * He names a ws subprotocol, ie, we want to support + * ss-ws protocol in this vhost + */ + *ppp++ = &protocol_secstream_ws; +#endif + *ppp = NULL; + i.pprotocols = pprot; + +#if defined(LWS_WITH_TLS) + if (h->policy->flags & LWSSSPOLF_TLS) { + i.options |= LWS_SERVER_OPTION_DO_SSL_GLOBAL_INIT; + i.server_ssl_cert_mem = + h->policy->trust.server.cert->ca_der; + i.server_ssl_cert_mem_len = (unsigned int) + h->policy->trust.server.cert->ca_der_len; + i.server_ssl_private_key_mem = + h->policy->trust.server.key->ca_der; + i.server_ssl_private_key_mem_len = (unsigned int) + h->policy->trust.server.key->ca_der_len; + } +#endif + + vho = lws_create_vhost(context, &i); + if (!vho) { + lwsl_err("%s: failed to create vh", __func__); + goto late_bail; + } + + /* + * Mark this vhost as having to apply ss server semantics to + * any incoming accepted connection + */ + vho->ss_handle = h; + + lwsl_notice("%s: created server %s\n", __func__, + h->policy->streamtype); + + return 0; + } +#endif + +#if defined(LWS_WITH_SECURE_STREAMS_STATIC_POLICY_ONLY) + + /* + * For static policy case, dynamically ref / instantiate the related + * trust store and vhost. We do it by logical ss rather than connection + * because we don't want to expose the latency of creating the x.509 + * trust store at the first connection. + * + * But it might be given the tls linkup takes time anyway, it can move + * to the ss connect code instead. + */ + + if (!lws_ss_policy_ref_trust_store(context, h->policy, 1 /* do the ref */)) { + lwsl_err("%s: unable to get vhost / trust store\n", __func__); + goto late_bail; + } +#endif + + if (lws_ss_event_helper(h, LWSSSCS_CREATING)) { +late_bail: + lws_pt_lock(pt, __func__); + lws_dll2_remove(&h->list); + lws_pt_unlock(pt); + lws_free(h); + + return 1; + } + + if (!(ssi->flags & LWSSSINFLAGS_REGISTER_SINK) && + ((h->policy->flags & LWSSSPOLF_NAILED_UP) +#if defined(LWS_WITH_SYS_SMD) + || ((h->policy == &pol_smd) //&& + //(ssi->flags & LWSSSINFLAGS_PROXIED)) + ) +#endif + )) + if (_lws_ss_client_connect(h, 0)) { + if (lws_ss_backoff(h)) + /* has been destroyed */ + return 1; + } + + return 0; +} + +void * +lws_ss_to_user_object(struct lws_ss_handle *h) +{ + return (void *)&h[1]; +} + +void +lws_ss_destroy(lws_ss_handle_t **ppss) +{ + struct lws_context_per_thread *pt; + lws_ss_handle_t *h = *ppss; + lws_ss_metadata_t *pmd; + + if (!h) + return; + + if (h->destroying) { + lwsl_info("%s: reentrant destroy\n", __func__); + return; + } + h->destroying = 1; + + if (h->wsi) { + /* + * Don't let the wsi point to us any more, + * we (the ss object bound to the wsi) are going away now + */ + lws_set_opaque_user_data(h->wsi, NULL); + lws_set_timeout(h->wsi, 1, LWS_TO_KILL_SYNC); + } + + /* + * if we bound an smd registration to the SS, unregister it + */ + +#if defined(LWS_WITH_SYS_SMD) + if (h->policy == &pol_smd && h->u.smd.smd_peer) { + lws_smd_unregister(h->u.smd.smd_peer); + h->u.smd.smd_peer = NULL; + } +#endif + + pt = &h->context->pt[h->tsi]; + + lws_pt_lock(pt, __func__); + *ppss = NULL; + lws_dll2_remove(&h->list); + lws_dll2_remove(&h->to_list); + lws_sul_cancel(&h->sul_timeout); + + (void)lws_ss_event_helper(h, LWSSSCS_DESTROYING); + lws_pt_unlock(pt); + + /* in proxy case, metadata value on heap may need cleaning up */ + + pmd = h->metadata; + while (pmd) { + lwsl_info("%s: pmd %p\n", __func__, pmd); + if (pmd->value_on_lws_heap) + lws_free_set_NULL(pmd->value); + pmd = pmd->next; + } + + lws_sul_cancel(&h->sul); + +#if defined(LWS_WITH_SECURE_STREAMS_STATIC_POLICY_ONLY) + + /* + * For static policy case, dynamically ref / instantiate the related + * trust store and vhost. We do it by logical ss rather than connection + * because we don't want to expose the latency of creating the x.509 + * trust store at the first connection. + * + * But it might be given the tls linkup takes time anyway, it can move + * to the ss connect code instead. + */ + + + lws_ss_policy_unref_trust_store(h->context, h->policy); +#endif + +#if defined(LWS_WITH_SERVER) + if (h->policy->flags & LWSSSPOLF_SERVER) { + struct lws_vhost *v = lws_get_vhost_by_name(h->context, + h->policy->streamtype); + + /* + * For server, the policy describes a vhost that implements the + * server, when we take down the ss, we take down the related + * vhost (if it got that far) + */ + if (v) + lws_vhost_destroy(v); + } +#endif + + /* confirm no sul left scheduled in handle or user allocation object */ + lws_sul_debug_zombies(h->context, h, sizeof(*h) + h->info.user_alloc, + __func__); + + lws_free_set_NULL(h); +} + +#if defined(LWS_WITH_SERVER) +void +lws_ss_server_ack(struct lws_ss_handle *h, int nack) +{ + h->txn_resp = nack; + h->txn_resp_set = 1; +} +#endif + +lws_ss_state_return_t +lws_ss_request_tx(lws_ss_handle_t *h) +{ + lws_ss_state_return_t r; + + // lwsl_notice("%s: h %p, wsi %p\n", __func__, h, h->wsi); + + if (h->wsi) { + lws_callback_on_writable(h->wsi); + + return LWSSSSRET_OK; + } + + if (h->policy->flags & LWSSSPOLF_SERVER) + return LWSSSSRET_OK; + + /* + * there's currently no wsi / connection associated with the ss handle + */ + +#if defined(LWS_WITH_SYS_SMD) + if (h->policy == &pol_smd) { + /* + * He's an _lws_smd... and no wsi... since we're just going + * to queue it, we could call his tx() right here, but rather + * than surprise him let's set a sul to do it next time around + * the event loop + */ + + lws_sul_schedule(h->context, 0, &h->u.smd.sul_write, + lws_ss_smd_tx_cb, 1); + + return LWSSSSRET_OK; + } +#endif + + if (h->seqstate != SSSEQ_IDLE && + h->seqstate != SSSEQ_DO_RETRY) + return LWSSSSRET_OK; + + h->seqstate = SSSEQ_TRY_CONNECT; + r = lws_ss_event_helper(h, LWSSSCS_POLL); + if (r) + return r; + + /* + * Retries operate via lws_ss_request_tx(), explicitly ask for a + * reconnection to clear the retry limit + */ + r = _lws_ss_client_connect(h, 1); + if (r == LWSSSSRET_DESTROY_ME) + return r; + + if (r) + return lws_ss_backoff(h); + + return LWSSSSRET_OK; +} + +lws_ss_state_return_t +lws_ss_request_tx_len(lws_ss_handle_t *h, unsigned long len) +{ + if (h->wsi && + (h->policy->protocol == LWSSSP_H1 || + h->policy->protocol == LWSSSP_H2 || + h->policy->protocol == LWSSSP_WS)) + h->wsi->http.writeable_len = len; + else + h->writeable_len = len; + + return lws_ss_request_tx(h); +} + +/* + * private helpers + */ + +/* used on context destroy when iterating listed lws_ss on a pt */ + +int +lws_ss_destroy_dll(struct lws_dll2 *d, void *user) +{ + lws_ss_handle_t *h = lws_container_of(d, lws_ss_handle_t, list); + + lws_ss_destroy(&h); + + return 0; +} + +struct lws_sequencer * +lws_ss_get_sequencer(lws_ss_handle_t *h) +{ + return h->seq; +} + +struct lws_context * +lws_ss_get_context(struct lws_ss_handle *h) +{ + return h->context; +} + +const char * +lws_ss_rideshare(struct lws_ss_handle *h) +{ + if (!h->rideshare) + return h->policy->streamtype; + + return h->rideshare->streamtype; +} + +int +lws_ss_add_peer_tx_credit(struct lws_ss_handle *h, int32_t bump) +{ + const struct ss_pcols *ssp; + + ssp = ss_pcols[(int)h->policy->protocol]; + + if (h->wsi && ssp && ssp->tx_cr_add) + return ssp->tx_cr_add(h, bump); + + return 0; +} + +int +lws_ss_get_est_peer_tx_credit(struct lws_ss_handle *h) +{ + const struct ss_pcols *ssp; + + ssp = ss_pcols[(int)h->policy->protocol]; + + if (h->wsi && ssp && ssp->tx_cr_add) + return ssp->tx_cr_est(h); + + return 0; +} + +/* + * protocol-independent handler for ss timeout + */ + +static void +lws_ss_to_cb(lws_sorted_usec_list_t *sul) +{ + lws_ss_handle_t *h = lws_container_of(sul, lws_ss_handle_t, sul_timeout); + lws_ss_state_return_t r; + + lwsl_info("%s: ss %p timeout fired\n", __func__, h); + + r = lws_ss_event_helper(h, LWSSSCS_TIMEOUT); + if (r == LWSSSSRET_DESTROY_ME) { + if (h->wsi) + lws_set_timeout(h->wsi, 1, LWS_TO_KILL_ASYNC); + _lws_ss_handle_state_ret(r, NULL, &h); + } +} + +void +lws_ss_start_timeout(struct lws_ss_handle *h, unsigned int timeout_ms) +{ + if (!timeout_ms && !h->policy->timeout_ms) + return; + + lws_sul_schedule(h->context, 0, &h->sul_timeout, lws_ss_to_cb, + (timeout_ms ? timeout_ms : h->policy->timeout_ms) * + LWS_US_PER_MS); +} + +void +lws_ss_cancel_timeout(struct lws_ss_handle *h) +{ + lws_sul_cancel(&h->sul_timeout); +} + +void +lws_ss_change_handlers(struct lws_ss_handle *h, + lws_ss_state_return_t (*rx)(void *userobj, const uint8_t *buf, + size_t len, int flags), + lws_ss_state_return_t (*tx)(void *userobj, lws_ss_tx_ordinal_t ord, + uint8_t *buf, size_t *len, int *flags), + lws_ss_state_return_t (*state)(void *userobj, void *h_src /* ss handle type */, + lws_ss_constate_t state, + lws_ss_tx_ordinal_t ack)) +{ + if (rx) + h->info.rx = rx; + if (tx) + h->info.tx = tx; + if (state) + h->info.state = state; +} diff -Nru libwebsockets-3.2.1/lib/secure-streams/secure-streams-client.c libwebsockets-4.1.6/lib/secure-streams/secure-streams-client.c --- libwebsockets-3.2.1/lib/secure-streams/secure-streams-client.c 1970-01-01 00:00:00.000000000 +0000 +++ libwebsockets-4.1.6/lib/secure-streams/secure-streams-client.c 2020-12-01 17:40:26.000000000 +0000 @@ -0,0 +1,773 @@ +/* + * lws-minimal-secure-streams-client + * + * Written in 2010-2020 by Andy Green + * + * This file is made available under the Creative Commons CC0 1.0 + * Universal Public Domain Dedication. + * + * + * This client does not perform any INET networking... instead it opens a unix + * domain socket on a proxy that is listening for it, and that creates the + * actual secure stream connection. + * + * We are able to use the usual secure streams api in the client process, with + * payloads and connection state information proxied over the unix domain + * socket and fulfilled in the proxy process. + * + * The public client helper pieces are built as part of lws + */ +#include + +static void +lws_sspc_sul_retry_cb(lws_sorted_usec_list_t *sul) +{ + lws_sspc_handle_t *h = lws_container_of(sul, lws_sspc_handle_t, sul_retry); + static struct lws_client_connect_info i; + + /* + * We may have started up before the system proxy, so be prepared with + * a sul to retry at 1Hz + */ + + memset(&i, 0, sizeof i); + i.context = h->context; + if (h->context->ss_proxy_port) { /* tcp */ + i.address = h->context->ss_proxy_address; + i.port = h->context->ss_proxy_port; + i.iface = h->context->ss_proxy_bind; + } else { + if (h->context->ss_proxy_bind) + i.address = h->context->ss_proxy_bind; + else + i.address = "+@proxy.ss.lws"; + } + i.host = i.address; + i.origin = i.address; + i.method = "RAW"; + i.protocol = lws_sspc_protocols[0].name; + i.local_protocol_name = lws_sspc_protocols[0].name; + i.path = ""; + i.pwsi = &h->cwsi; + i.opaque_user_data = (void *)h; + + if (!lws_client_connect_via_info(&i)) { + lws_sul_schedule(h->context, 0, &h->sul_retry, + lws_sspc_sul_retry_cb, LWS_US_PER_SEC); + + return; + } + + lwsl_notice("%s: sspc ss wsi %p\n", __func__, h->cwsi); +} + +static int +lws_sspc_serialize_metadata(lws_sspc_metadata_t *md, uint8_t *p, uint8_t *end) +{ + int n, txc; + + if (md->name[0] == '\0') { + + lwsl_info("%s: sending tx credit update %d\n", __func__, + md->tx_cr_adjust); + + p[0] = LWSSS_SER_TXPRE_TXCR_UPDATE; + lws_ser_wu16be(&p[1], 4); + lws_ser_wu32be(&p[3], md->tx_cr_adjust); + + n = 7; + + } else { + + lwsl_info("%s: sending metadata\n", __func__); + + p[0] = LWSSS_SER_TXPRE_METADATA; + txc = strlen(md->name); + n = txc + 1 + md->len; + if (n > 0xffff) + /* we can't serialize this metadata in 16b length */ + return -1; + if (n > lws_ptr_diff(end, &p[4])) + /* we don't have space for this metadata */ + return -1; + lws_ser_wu16be(&p[1], n); + p[3] = txc; + memcpy(&p[4], md->name, txc); + memcpy(&p[4 + txc], &md[1], md->len); + n = 4 + txc + md->len; + } + + lws_dll2_remove(&md->list); + lws_free(md); + + return n; +} + +static int +callback_sspc_client(struct lws *wsi, enum lws_callback_reasons reason, + void *user, void *in, size_t len) +{ + lws_sspc_handle_t *h = (lws_sspc_handle_t *)lws_get_opaque_user_data(wsi); + uint8_t s[32], pkt[LWS_PRE + 2048], *p = pkt + LWS_PRE, + *end = p + sizeof(pkt) - LWS_PRE; + void *m = (void *)((uint8_t *)&h[1]); + const uint8_t *cp; + lws_usec_t us; + int flags, n; + + switch (reason) { + case LWS_CALLBACK_PROTOCOL_INIT: + break; + + case LWS_CALLBACK_PROTOCOL_DESTROY: + break; + + case LWS_CALLBACK_CLIENT_CONNECTION_ERROR: + lwsl_warn("%s: CONNECTION_ERROR\n", __func__); + lws_set_opaque_user_data(wsi, NULL); + h->cwsi = NULL; + lws_sul_schedule(h->context, 0, &h->sul_retry, + lws_sspc_sul_retry_cb, LWS_US_PER_SEC); + break; + + case LWS_CALLBACK_RAW_CONNECTED: + if (!h) + return -1; + lwsl_info("%s: CONNECTED (%s)\n", __func__, h->ssi.streamtype); + + h->state = LPCSCLI_SENDING_INITIAL_TX; + h->dsh = lws_dsh_create(NULL, (LWS_PRE + LWS_SS_MTU) * 160, 1); + if (!h->dsh) + return -1; + + lws_set_timeout(wsi, PENDING_TIMEOUT_AWAITING_CLIENT_HS_SEND, 3); + lws_callback_on_writable(wsi); + break; + + case LWS_CALLBACK_RAW_CLOSE: + /* + * our ss proxy Unix Domain socket has closed... + */ + lwsl_notice("%s: LWS_CALLBACK_RAW_CLOSE: proxy conn down\n", + __func__); + if (h) { + h->cwsi = NULL; + /* + * schedule a reconnect in 1s + */ + lws_sul_schedule(h->context, 0, &h->sul_retry, + lws_sspc_sul_retry_cb, LWS_US_PER_SEC); + } + break; + + case LWS_CALLBACK_RAW_RX: + /* + * ie, the proxy has sent us something + */ + lwsl_info("%s: RAW_RX: rx %d\n", __func__, (int)len); + + if (!h || !h->cwsi) { + lwsl_err("%s: rx with bad conn state\n", __func__); + + return -1; + } + + n = lws_ss_deserialize_parse(&h->parser, lws_get_context(wsi), + h->dsh, in, len, &h->state, h, + (lws_ss_handle_t **)m, &h->ssi, 1); + switch (n) { + case LWSSSSRET_OK: + break; + case LWSSSSRET_DISCONNECT_ME: + return -1; + case LWSSSSRET_DESTROY_ME: + lws_set_opaque_user_data(wsi, NULL); + lws_sspc_destroy(&h); + return -1; + } + + if (h->state == LPCSCLI_LOCAL_CONNECTED || + h->state == LPCSCLI_ONWARD_CONNECT) + lws_set_timeout(wsi, 0, 0); + + break; + + case LWS_CALLBACK_RAW_WRITEABLE: + + /* + * We can transmit something to the proxy... + */ + + if (!h) + break; + + lwsl_debug("%s: WRITEABLE %p: (%s) state %d\n", __func__, wsi, + h->ssi.streamtype, h->state); + + /* + * Management of ss timeout can happen any time and doesn't + * depend on wsi existence or state + */ + + n = 0; + cp = s; + + if (h->pending_timeout_update) { + s[0] = LWSSS_SER_TXPRE_TIMEOUT_UPDATE; + s[1] = 0; + s[2] = 4; + /* + * 0: use policy timeout value + * 0xffffffff: cancel the timeout + */ + lws_ser_wu32be(&s[3], h->timeout_ms); + /* in case anything else to write */ + lws_callback_on_writable(h->cwsi); + h->pending_timeout_update = 0; + n = 7; + goto do_write; + } + + s[1] = 0; + /* + * This is the state of the link that connects us to the onward + * proxy + */ + switch (h->state) { + case LPCSCLI_SENDING_INITIAL_TX: + /* + * We are negotating the opening of a particular + * streamtype + */ + n = strlen(h->ssi.streamtype) + 4; + + s[0] = LWSSS_SER_TXPRE_STREAMTYPE; + lws_ser_wu16be(&s[1], n); + lws_ser_wu32be(&s[3], h->txc.peer_tx_cr_est); + //h->txcr_out = txc; + lws_strncpy((char *)&s[7], h->ssi.streamtype, sizeof(s) - 7); + n += 3; + h->state = LPCSCLI_WAITING_CREATE_RESULT; + break; + + case LPCSCLI_LOCAL_CONNECTED: + + // lwsl_notice("%s: LPCSCLI_LOCAL_CONNECTED\n", __func__); + + /* + * Do we need to prioritize sending any metadata + * changes? + */ + + if (h->metadata_owner.count) { + lws_sspc_metadata_t *md = lws_container_of( + lws_dll2_get_tail(&h->metadata_owner), + lws_sspc_metadata_t, list); + + cp = p; + n = lws_sspc_serialize_metadata(md, p, end); + if (n < 0) + goto metadata_hangup; + + lwsl_debug("%s: (local_conn) metadata\n", __func__); + + goto req_write_and_issue; + } + + if (h->pending_writeable_len) { + lwsl_debug("%s: (local_conn) PAYLOAD_LENGTH_HINT %u\n", + __func__, (unsigned int)h->writeable_len); + s[0] = LWSSS_SER_TXPRE_PAYLOAD_LENGTH_HINT; + lws_ser_wu16be(&s[1], 4); + lws_ser_wu32be(&s[3], h->writeable_len); + h->pending_writeable_len = 0; + n = 7; + goto req_write_and_issue; + } + + if (h->conn_req_state >= LWSSSPC_ONW_ONGOING) { + lwsl_info("%s: conn_req_state %d\n", __func__, + h->conn_req_state); + break; + } + + lwsl_info("%s: (local_conn) onward connect\n", __func__); + + h->conn_req_state = LWSSSPC_ONW_ONGOING; + + s[0] = LWSSS_SER_TXPRE_ONWARD_CONNECT; + s[1] = 0; + s[2] = 0; + n = 3; + break; + + case LPCSCLI_OPERATIONAL: + + lwsl_notice("%s: LPCSCLI_OPERATIONAL\n", __func__); + + /* + * + * - Do we need to prioritize sending any metadata + * changes? (includes txcr updates) + * + * - Do we need to forward a hint about the payload + * length? + */ + + if (h->metadata_owner.count) { + lws_sspc_metadata_t *md = lws_container_of( + lws_dll2_get_tail(&h->metadata_owner), + lws_sspc_metadata_t, list); + + cp = p; + n = lws_sspc_serialize_metadata(md, p, end); + if (n < 0) + goto metadata_hangup; + + goto req_write_and_issue; + } + + if (h->pending_writeable_len) { + lwsl_info("%s: PAYLOAD_LENGTH_HINT %u\n", + __func__, (unsigned int)h->writeable_len); + s[0] = LWSSS_SER_TXPRE_PAYLOAD_LENGTH_HINT; + lws_ser_wu16be(&s[1], 4); + lws_ser_wu32be(&s[3], h->writeable_len); + h->pending_writeable_len = 0; + n = 7; + goto req_write_and_issue; + } + + /* we can't write anything if we don't have credit */ + if (!h->ignore_txc && h->txc.tx_cr <= 0) { + lwsl_info("%s: WRITEABLE / OPERATIONAL:" + " lack credit (%d)\n", __func__, + h->txc.tx_cr); + // break; + } + + len = sizeof(pkt) - LWS_PRE - 19; + flags = 0; + n = h->ssi.tx(m, h->ord++, pkt + LWS_PRE + 19, &len, + &flags); + if (n == LWSSSSRET_TX_DONT_SEND) { + n = 0; + break; + } + + h->txc.tx_cr -= len; + + cp = p; + n = len + 19; + us = lws_now_usecs(); + p[0] = LWSSS_SER_TXPRE_TX_PAYLOAD; + lws_ser_wu16be(&p[1], len + 19 - 3); + lws_ser_wu32be(&p[3], flags); + /* time spent here waiting to send this */ + lws_ser_wu32be(&p[7], us - h->us_earliest_write_req); + /* ust that the client write happened */ + lws_ser_wu64be(&p[11], us); + h->us_earliest_write_req = 0; + + if (flags & LWSSS_FLAG_EOM) + if (h->rsidx + 1 < (int)LWS_ARRAY_SIZE(h->rideshare_ofs) && + h->rideshare_ofs[h->rsidx + 1]) + h->rsidx++; + + break; + default: + break; + } + +do_write_nz: + + if (!n) + break; + +do_write: + n = lws_write(wsi, (uint8_t *)cp, n, LWS_WRITE_RAW); + if (n < 0) { + lwsl_notice("%s: WRITEABLE: %d\n", __func__, n); + + goto hangup; + } + break; + + default: + break; + } + + return lws_callback_http_dummy(wsi, reason, user, in, len); + +metadata_hangup: + lwsl_err("%s: metadata too large\n", __func__); + +hangup: + lwsl_warn("hangup\n"); + /* hang up on him */ + return -1; + +req_write_and_issue: + /* in case anything else to write */ + lws_callback_on_writable(h->cwsi); + goto do_write_nz; +} + +const struct lws_protocols lws_sspc_protocols[] = { + { + "ssproxy-protocol", + callback_sspc_client, + 0, + 2048, 2048, NULL, 0 + }, + { NULL, NULL, 0, 0, 0, NULL, 0 } +}; + +int +lws_sspc_create(struct lws_context *context, int tsi, const lws_ss_info_t *ssi, + void *opaque_user_data, lws_sspc_handle_t **ppss, + struct lws_sequencer *seq_owner, const char **ppayload_fmt) +{ + lws_sspc_handle_t *h; + uint8_t *ua; + char *p; + + lwsl_notice("%s: streamtype %s\n", __func__, ssi->streamtype); + + /* allocate the handle (including ssi), the user alloc, + * and the streamname */ + + h = malloc(sizeof(lws_sspc_handle_t) + ssi->user_alloc + + strlen(ssi->streamtype) + 1); + if (!h) + return 1; + memset(h, 0, sizeof(*h)); + memcpy(&h->ssi, ssi, sizeof(*ssi)); + ua = (uint8_t *)&h[1]; + memset(ua, 0, ssi->user_alloc); + p = (char *)ua + ssi->user_alloc; + memcpy(p, ssi->streamtype, strlen(ssi->streamtype) + 1); + h->ssi.streamtype = (const char *)p; + h->context = context; + + if (!ssi->manual_initial_tx_credit) + h->txc.peer_tx_cr_est = 500000000; + else + h->txc.peer_tx_cr_est = ssi->manual_initial_tx_credit; + + if (!strcmp(ssi->streamtype, "_lws_smd")) + h->ignore_txc = 1; + + lws_dll2_add_head(&h->client_list, &context->pt[tsi].ss_client_owner); + + /* fill in the things the real api does for the caller */ + + *((void **)(ua + ssi->opaque_user_data_offset)) = opaque_user_data; + *((void **)(ua + ssi->handle_offset)) = h; + + if (ppss) + *ppss = h; + + /* try the actual connect */ + + lws_sspc_sul_retry_cb(&h->sul_retry); + + return 0; +} + +/* used on context destroy when iterating listed lws_ss on a pt */ + +int +lws_sspc_destroy_dll(struct lws_dll2 *d, void *user) +{ + lws_sspc_handle_t *h = lws_container_of(d, lws_sspc_handle_t, client_list); + + lws_sspc_destroy(&h); + + return 0; +} + + +void +lws_sspc_destroy(lws_sspc_handle_t **ph) +{ + lws_sspc_handle_t *h; + void *m; + + lwsl_debug("%s\n", __func__); + + if (!*ph) + return; + + h = *ph; + m = (void *)((uint8_t *)&h[1]); + + if (h->destroying) + return; + + h->destroying = 1; + + lws_sul_cancel(&h->sul_retry); + lws_dll2_remove(&h->client_list); + + if (h->dsh) + lws_dsh_destroy(&h->dsh); + if (h->cwsi) + h->cwsi = NULL; + + /* clean out any pending metadata changes that didn't make it */ + + lws_start_foreach_dll_safe(struct lws_dll2 *, d, d1, + lws_dll2_get_head(&(*ph)->metadata_owner)) { + lws_sspc_metadata_t *md = + lws_container_of(d, lws_sspc_metadata_t, list); + + lws_dll2_remove(&md->list); + lws_free(md); + + } lws_end_foreach_dll_safe(d, d1); + + h->ssi.state(m, NULL, LWSSSCS_DESTROYING, 0); + *ph = NULL; + free(h); +} + +lws_ss_state_return_t +lws_sspc_request_tx(lws_sspc_handle_t *h) +{ + if (!h || !h->cwsi) + return LWSSSSRET_OK; + + if (!h->us_earliest_write_req) + h->us_earliest_write_req = lws_now_usecs(); + + if (h->state == LPCSCLI_LOCAL_CONNECTED && + h->conn_req_state == LWSSSPC_ONW_NONE) + h->conn_req_state = LWSSSPC_ONW_REQ; + + lws_callback_on_writable(h->cwsi); + + return LWSSSSRET_OK; +} + +/* + * Currently we fulfil the writeable part locally by just enabling POLLOUT on + * the UDS link, without serialization footprint, which is reasonable as far as + * it goes. + * + * But for the ..._len() variant, the expected payload length hint we are being + * told is something that must be serialized to the onward peer, since either + * that guy or someone upstream of him is the guy who will compose the framing + * with it that actually goes out. + * + * This information is needed at the upstream guy before we have sent any + * payload, eg, for http POST, he has to prepare the content-length in the + * headers, before any payload. So we have to issue a serialization of the + * length at this point. + */ + +lws_ss_state_return_t +lws_sspc_request_tx_len(lws_sspc_handle_t *h, unsigned long len) +{ + /* + * for client conns, they cannot even complete creation of the handle + * without the onwared connection to the proxy, it's not legal to start + * using it until it's operation and has the onward connection (and has + * called CREATED state) + */ + + if (!h) + return LWSSSSRET_OK; + + lwsl_notice("%s: setting h %p writeable_len %u\n", __func__, h, + (unsigned int)len); + h->writeable_len = len; + h->pending_writeable_len = 1; + + if (!h->us_earliest_write_req) + h->us_earliest_write_req = lws_now_usecs(); + + if (h->state == LPCSCLI_LOCAL_CONNECTED && + h->conn_req_state == LWSSSPC_ONW_NONE) + h->conn_req_state = LWSSSPC_ONW_REQ; + + /* + * We're going to use this up with serializing h->writeable_len... that + * will request again. + */ + + lws_callback_on_writable(h->cwsi); + + return LWSSSSRET_OK; +} + +int +lws_sspc_client_connect(lws_sspc_handle_t *h) +{ + if (!h || h->state == LPCSCLI_OPERATIONAL) + return 0; + + assert(h->state == LPCSCLI_LOCAL_CONNECTED); + if (h->state == LPCSCLI_LOCAL_CONNECTED && + h->conn_req_state == LWSSSPC_ONW_NONE) + h->conn_req_state = LWSSSPC_ONW_REQ; + if (h->cwsi) + lws_callback_on_writable(h->cwsi); + + return 0; +} + +struct lws_context * +lws_sspc_get_context(struct lws_sspc_handle *h) +{ + return h->context; +} + +const char * +lws_sspc_rideshare(struct lws_sspc_handle *h) +{ + /* + * ...the serialized RX rideshare name if any... + */ + + if (h->parser.rideshare[0]) { + lwsl_info("%s: parser %s\n", __func__, h->parser.rideshare); + return h->parser.rideshare; + } + + /* + * The tx rideshare index + */ + + if (h->rideshare_list[0]) { + lwsl_info("%s: tx list %s\n", __func__, + &h->rideshare_list[h->rideshare_ofs[h->rsidx]]); + return &h->rideshare_list[h->rideshare_ofs[h->rsidx]]; + } + + /* + * ... otherwise default to our stream type name + */ + + lwsl_info("%s: def %s\n", __func__, h->ssi.streamtype); + + return h->ssi.streamtype; +} + +static int +_lws_sspc_set_metadata(struct lws_sspc_handle *h, const char *name, + const void *value, size_t len, int tx_cr_adjust) +{ + lws_sspc_metadata_t *md; + + /* + * Are we replacing a pending metadata of the same name? It's not + * efficient to do this but user code can do what it likes... let's + * optimize away the old one. + * + * Tx credit adjust always has name "" + */ + + lws_start_foreach_dll_safe(struct lws_dll2 *, d, d1, + lws_dll2_get_head(&h->metadata_owner)) { + md = lws_container_of(d, lws_sspc_metadata_t, list); + + if (!strcmp(name, md->name)) { + lws_dll2_remove(&md->list); + lws_free(md); + break; + } + + } lws_end_foreach_dll_safe(d, d1); + + /* + * We have to stash the metadata and pass it to the proxy + */ + + md = lws_malloc(sizeof(*md) + len, "set metadata"); + if (!md) { + lwsl_err("%s: OOM\n", __func__); + + return 1; + } + + memset(md, 0, sizeof(*md)); + + md->tx_cr_adjust = tx_cr_adjust; + h->txc.peer_tx_cr_est += tx_cr_adjust; + + lws_strncpy(md->name, name, sizeof(md->name)); + md->len = len; + if (len) + memcpy(&md[1], value, len); + + lws_dll2_add_tail(&md->list, &h->metadata_owner); + + if (len) { + lwsl_info("%s: set metadata %s\n", __func__, name); + lwsl_hexdump_info(value, len); + } else + lwsl_info("%s: serializing tx cr adj %d\n", __func__, + (int)tx_cr_adjust); + + if (h->cwsi) + lws_callback_on_writable(h->cwsi); + + return 0; +} + +int +lws_sspc_set_metadata(struct lws_sspc_handle *h, const char *name, + const void *value, size_t len) +{ + return _lws_sspc_set_metadata(h, name, value, len, 0); +} + +int +lws_sspc_add_peer_tx_credit(struct lws_sspc_handle *h, int32_t bump) +{ + lwsl_notice("%s: %d\n", __func__, bump); + return _lws_sspc_set_metadata(h, "", NULL, 0, (int)bump); +} + +int +lws_sspc_get_est_peer_tx_credit(struct lws_sspc_handle *h) +{ + return h->txc.peer_tx_cr_est; +} + +void +lws_sspc_start_timeout(struct lws_sspc_handle *h, unsigned int timeout_ms) +{ + h->timeout_ms = (uint32_t)timeout_ms; + h->pending_timeout_update = 1; + lws_callback_on_writable(h->cwsi); +} + +void +lws_sspc_cancel_timeout(struct lws_sspc_handle *h) +{ + lws_sspc_start_timeout(h, (unsigned int)-1); +} + +void * +lws_sspc_to_user_object(struct lws_sspc_handle *h) +{ + return (void *)&h[1]; +} + +void +lws_sspc_change_handlers(struct lws_sspc_handle *h, + lws_ss_state_return_t (*rx)(void *userobj, const uint8_t *buf, size_t len, int flags), + lws_ss_state_return_t (*tx)(void *userobj, lws_ss_tx_ordinal_t ord, uint8_t *buf, + size_t *len, int *flags), + lws_ss_state_return_t (*state)(void *userobj, void *h_src /* ss handle type */, + lws_ss_constate_t state, lws_ss_tx_ordinal_t ack)) +{ + if (rx) + h->ssi.rx = rx; + if (tx) + h->ssi.tx = tx; + if (state) + h->ssi.state = state; +} diff -Nru libwebsockets-3.2.1/lib/secure-streams/secure-streams-process.c libwebsockets-4.1.6/lib/secure-streams/secure-streams-process.c --- libwebsockets-3.2.1/lib/secure-streams/secure-streams-process.c 1970-01-01 00:00:00.000000000 +0000 +++ libwebsockets-4.1.6/lib/secure-streams/secure-streams-process.c 2020-12-01 17:40:26.000000000 +0000 @@ -0,0 +1,563 @@ +/* + * libwebsockets - small server side websockets and web server implementation + * + * Copyright (C) 2019 - 2020 Andy Green + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to + * deal in the Software without restriction, including without limitation the + * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or + * sell copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS + * IN THE SOFTWARE. + * + * + * When the user code is in a different process, a non-tls unix domain socket + * proxy is used to asynchronusly transfer buffers in each direction via the + * network stack, without explicit IPC + * + * user_process{ [user code] | shim | socket-}------ lws_process{ lws } + * + * Lws exposes a listening unix domain socket in this case, the user processes + * connect to it and pass just info.streamtype in an initial tx packet. All + * packets are prepended by a 1-byte type field when used in this mode. See + * lws-secure-streams.h for documentation and definitions. + * + * Proxying in either direction can face the situation it cannot send the onward + * packet immediately and is subject to separating the write request from the + * write action. To make the best use of memory, a single preallocated buffer + * stashes pending packets in all four directions (c->p, p->c, p->ss, ss->p). + * This allows it to adapt to different traffic patterns without wasted areas + * dedicated to traffic that isn't coming in a particular application. + * + * A shim is provided to monitor the process' unix domain socket and regenerate + * the secure sockets api there with callbacks happening in the process thread + * context. + * + * This file implements the listening unix domain socket proxy... this code is + * only going to run on a Linux-class device with its implications about memory + * availability. + */ + +#include + +/* + * Because both sides of the connection share the conn, we allocate it + * during accepted adoption, and both sides point to it. + * + * The last one of the accepted side and the onward side to close frees it. + */ + +struct conn { + struct lws_ss_serialization_parser parser; + + lws_dsh_t *dsh; /* unified buffer for both sides */ + struct lws *wsi; /* the client side */ + lws_ss_handle_t *ss; /* the onward, ss side */ + + lws_ss_conn_states_t state; +}; + +struct raw_pss { + struct conn *conn; +}; + +/* + * Proxy - onward secure-stream handler + */ + +typedef struct ss_proxy_onward { + lws_ss_handle_t *ss; + struct conn *conn; +} ss_proxy_t; + + +/* secure streams payload interface */ + +static lws_ss_state_return_t +ss_proxy_onward_rx(void *userobj, const uint8_t *buf, size_t len, int flags) +{ + ss_proxy_t *m = (ss_proxy_t *)userobj; + const char *rsp = NULL; + int n; + + // lwsl_notice("%s: len %d\n", __func__, (int)len); + + /* + * The onward secure stream connection has received something. + */ + + if (m->ss->rideshare != m->ss->policy && m->ss->rideshare) { + rsp = m->ss->rideshare->streamtype; + flags |= LWSSS_FLAG_RIDESHARE; + } + + n = lws_ss_serialize_rx_payload(m->conn->dsh, buf, len, flags, rsp); + if (n) + return n; + + if (m->conn->wsi) /* if possible, request client conn write */ + lws_callback_on_writable(m->conn->wsi); + + return 0; +} + +/* + * we are transmitting buffered payload originally from the client on to the ss + */ + +static lws_ss_state_return_t +ss_proxy_onward_tx(void *userobj, lws_ss_tx_ordinal_t ord, uint8_t *buf, + size_t *len, int *flags) +{ + ss_proxy_t *m = (ss_proxy_t *)userobj; + void *p; + size_t si; + + if (!m->conn->ss || m->conn->state != LPCSPROX_OPERATIONAL) { + lwsl_notice("%s: ss not ready\n", __func__); + *len = 0; + + return 1; + } + + /* + * The onward secure stream says that we could send something to it + * (by putting it in buf, and setting *len and *flags) + */ + + if (lws_ss_deserialize_tx_payload(m->conn->dsh, m->ss->wsi, + ord, buf, len, flags)) + return 1; + + if (!lws_dsh_get_head(m->conn->dsh, KIND_C_TO_P, (void **)&p, &si)) + lws_ss_request_tx(m->conn->ss); + + if (!*len && !*flags) + return 1; /* we don't actually want to send anything */ + + lwsl_info("%s: onward tx %d fl 0x%x\n", __func__, (int)*len, *flags); + +#if 0 + { + int ff = open("/tmp/z", O_RDWR | O_CREAT | O_APPEND, 0666); + if (ff == -1) + lwsl_err("%s: errno %d\n", __func__, errno); + write(ff, buf, *len); + close(ff); + } +#endif + + return 0; +} + +static lws_ss_state_return_t +ss_proxy_onward_state(void *userobj, void *sh, + lws_ss_constate_t state, lws_ss_tx_ordinal_t ack) +{ + ss_proxy_t *m = (ss_proxy_t *)userobj; + + switch (state) { + case LWSSSCS_CREATING: + break; + + case LWSSSCS_DESTROYING: + if (!m->conn) + break; + if (!m->conn->wsi) { + /* + * Our onward secure stream is closing and our client + * connection has already gone away... destroy the conn. + */ + lwsl_info("%s: Destroying conn\n", __func__); + lws_dsh_destroy(&m->conn->dsh); + free(m->conn); + m->conn = NULL; + return 0; + } else + lwsl_info("%s: ss DESTROYING, wsi up\n", __func__); + break; + + default: + break; + } + if (!m->conn) { + lwsl_warn("%s: dropping state due to conn not up\n", __func__); + + return 0; + } + + lws_ss_serialize_state(m->conn->dsh, state, ack); + + if (m->conn->wsi) /* if possible, request client conn write */ + lws_callback_on_writable(m->conn->wsi); + + return 0; +} + +void +ss_proxy_onward_txcr(void *userobj, int bump) +{ + ss_proxy_t *m = (ss_proxy_t *)userobj; + + if (!m->conn) + return; + + lws_ss_serialize_txcr(m->conn->dsh, bump); + + if (m->conn->wsi) /* if possible, request client conn write */ + lws_callback_on_writable(m->conn->wsi); +} + +/* + * Client - Proxy connection on unix domain socket + */ + +static int +callback_ss_proxy(struct lws *wsi, enum lws_callback_reasons reason, + void *user, void *in, size_t len) +{ + struct lws_context_per_thread *pt = &wsi->a.context->pt[(int)wsi->tsi]; + struct raw_pss *pss = (struct raw_pss *)user; + const lws_ss_policy_t *rsp; + struct conn *conn = NULL; + lws_ss_info_t ssi; + const uint8_t *cp; +#if defined(LWS_WITH_DETAILED_LATENCY) + lws_usec_t us; +#endif + char s[128]; + uint8_t *p; + size_t si; + char pay; + int n; + + if (pss) + conn = pss->conn; + + switch (reason) { + case LWS_CALLBACK_PROTOCOL_INIT: + break; + + case LWS_CALLBACK_PROTOCOL_DESTROY: + break; + + /* callbacks related to raw socket descriptor "accepted side" */ + + case LWS_CALLBACK_RAW_ADOPT: + lwsl_info("LWS_CALLBACK_RAW_ADOPT\n"); + if (!pss) + return -1; + pss->conn = malloc(sizeof(struct conn)); + if (!pss->conn) + return -1; + memset(pss->conn, 0, sizeof(*pss->conn)); + + pss->conn->dsh = lws_dsh_create(&pt->ss_dsh_owner, + LWS_SS_MTU * 160, 2); + if (!pss->conn->dsh) { + free(pss->conn); + + return -1; + } + + pss->conn->wsi = wsi; + pss->conn->state = LPCSPROX_WAIT_INITIAL_TX; + + /* + * Client is expected to follow the unix domain socket + * acceptance up rapidly with an initial tx containing the + * streamtype name. We can't create the stream until then. + */ + lws_set_timeout(wsi, + PENDING_TIMEOUT_AWAITING_CLIENT_HS_SEND, 3); + break; + + case LWS_CALLBACK_RAW_CLOSE: + lwsl_info("LWS_CALLBACK_RAW_CLOSE:\n"); + + if (!conn) + break; + + /* + * the client unix domain socket connection (wsi / conn->wsi) + * has closed... eg, client has exited or otherwise has + * definitively finished with the proxying and onward connection + * + * But right now, the SS and possibly the SS onward wsi are + * still live... + */ + + if (conn->ss) { + struct lws *cw = conn->ss->wsi; + /* + * The onward connection is around + */ + lwsl_info("%s: destroying ss.h=%p, ss.wsi=%p\n", + __func__, conn->ss, conn->ss->wsi); + /* sever relationship with ss about to be deleted */ + lws_set_opaque_user_data(wsi, NULL); + if (wsi != cw) + /* + * The wsi doing the onward connection can no + * longer relate to the conn... otherwise when + * he gets callbacks he wants to bind to + * the ss we are about to delete + */ + lws_wsi_close(cw, LWS_TO_KILL_ASYNC); + conn->wsi = NULL; + + + lws_ss_destroy(&conn->ss); + /* conn may have gone */ + break; + } + + if (conn->state == LPCSPROX_DESTROYED || !conn->ss) { + /* + * There's no onward secure stream and our client + * connection is closing. Destroy the conn. + */ + lws_dsh_destroy(&conn->dsh); + free(conn); + pss->conn = NULL; + } else + lwsl_debug("%s: CLOSE; ss=%p\n", __func__, conn->ss); + + break; + + case LWS_CALLBACK_RAW_RX: + /* + * ie, the proxy is receiving something from a client + */ + lwsl_info("%s: RX: rx %d\n", __func__, (int)len); + + if (!conn || !conn->wsi) { + lwsl_err("%s: rx with bad conn state\n", __func__); + + return -1; + } + + // lwsl_hexdump_info(in, len); + + if (conn->state == LPCSPROX_WAIT_INITIAL_TX) { + memset(&ssi, 0, sizeof(ssi)); + ssi.user_alloc = sizeof(ss_proxy_t); + ssi.handle_offset = offsetof(ss_proxy_t, ss); + ssi.opaque_user_data_offset = + offsetof(ss_proxy_t, conn); + ssi.rx = ss_proxy_onward_rx; + ssi.tx = ss_proxy_onward_tx; + } + ssi.state = ss_proxy_onward_state; + ssi.flags = 0; + + n = lws_ss_deserialize_parse(&conn->parser, + lws_get_context(wsi), conn->dsh, in, len, + &conn->state, conn, &conn->ss, &ssi, 0); + switch (n) { + case LWSSSSRET_OK: + break; + case LWSSSSRET_DISCONNECT_ME: + return -1; + case LWSSSSRET_DESTROY_ME: + if (conn->ss) + lws_ss_destroy(&conn->ss); + return -1; + } + + if (conn->state == LPCSPROX_REPORTING_FAIL || + conn->state == LPCSPROX_REPORTING_OK) + lws_callback_on_writable(conn->wsi); + + break; + + case LWS_CALLBACK_RAW_WRITEABLE: + // lwsl_notice("LWS_CALLBACK_RAW_PROXY_SRV_WRITEABLE\n"); + + /* + * We can transmit something back to the client from the dsh + * of stuff we received on its behalf from the ss + */ + + if (!conn || !conn->wsi) + break; + + n = 0; + pay = 0; + s[3] = 0; + cp = (const uint8_t *)s; + switch (conn->state) { + case LPCSPROX_REPORTING_FAIL: + s[3] = 1; + /* fallthru */ + case LPCSPROX_REPORTING_OK: + s[0] = LWSSS_SER_RXPRE_CREATE_RESULT; + s[1] = 0; + s[2] = 1; + + n = 4; + + /* + * If there's rideshare sequencing, it's added after the + * first 4 bytes or the create result, comma-separated + */ + + if (conn->ss) { + rsp = conn->ss->policy; + + while (rsp) { + if (n != 4 && n < (int)sizeof(s) - 2) + s[n++] = ','; + n += lws_snprintf(&s[n], sizeof(s) - n, + "%s", rsp->streamtype); + rsp = lws_ss_policy_lookup(wsi->a.context, + rsp->rideshare_streamtype); + } + } + s[2] = n - 3; + conn->state = LPCSPROX_OPERATIONAL; + lws_set_timeout(wsi, 0, 0); + break; + case LPCSPROX_OPERATIONAL: + if (lws_dsh_get_head(conn->dsh, KIND_SS_TO_P, + (void **)&p, &si)) + break; + cp = p; + +#if defined(LWS_WITH_DETAILED_LATENCY) + if (cp[0] == LWSSS_SER_RXPRE_RX_PAYLOAD && + wsi->a.context->detailed_latency_cb) { + + /* + * we're fulfilling rx that came in on ss + * by sending it back out to the client on + * the Unix Domain Socket + * + * + 7 u32 write will compute latency here... + * + 11 u32 ust we received from ss + * + * lws_write will report it and fill in + * LAT_DUR_PROXY_CLIENT_REQ_TO_WRITE + */ + + us = lws_now_usecs(); + lws_ser_wu32be(&p[7], us - + lws_ser_ru64be(&p[11])); + lws_ser_wu64be(&p[11], us); + + wsi->detlat.acc_size = + wsi->detlat.req_size = si - 19; + /* time proxy held it */ + wsi->detlat.latencies[ + LAT_DUR_PROXY_RX_TO_ONWARD_TX] = + lws_ser_ru32be(&p[7]); + } +#endif + + pay = 1; + n = (int)si; + break; + default: + break; + } +again: + if (!n) + break; + + n = lws_write(wsi, (uint8_t *)cp, n, LWS_WRITE_RAW); + if (n < 0) { + lwsl_info("%s: WRITEABLE: %d\n", __func__, n); + + goto hangup; + } + + switch (conn->state) { + case LPCSPROX_REPORTING_FAIL: + goto hangup; + case LPCSPROX_OPERATIONAL: + if (pay) + lws_dsh_free((void **)&p); + if (!lws_dsh_get_head(conn->dsh, KIND_SS_TO_P, + (void **)&p, &si)) { + if (!lws_send_pipe_choked(wsi)) { + cp = p; + pay = 1; + n = (int)si; + goto again; + } + lws_callback_on_writable(wsi); + } + break; + default: + break; + } + break; + + default: + break; + } + + return lws_callback_http_dummy(wsi, reason, user, in, len); + +hangup: + //lws_ss_destroy(&conn->ss); + //conn->state = LPCSPROX_DESTROYED; + + /* hang up on him */ + return -1; +} + +static const struct lws_protocols protocols[] = { + { + "ssproxy-protocol", + callback_ss_proxy, + sizeof(struct raw_pss), + 2048, 2048, NULL, 0 + }, + { NULL, NULL, 0, 0, 0, NULL, 0 } +}; + +/* + * called from create_context() + */ + +int +lws_ss_proxy_create(struct lws_context *context, const char *bind, int port) +{ + struct lws_context_creation_info info; + + memset(&info, 0, sizeof(info)); + + info.vhost_name = "ssproxy"; + info.options = LWS_SERVER_OPTION_ADOPT_APPLY_LISTEN_ACCEPT_CONFIG; + info.port = port; + if (!port) { + if (!bind) + bind = "@proxy.ss.lws"; + info.options |= LWS_SERVER_OPTION_UNIX_SOCK; + } + info.iface = bind; + info.unix_socket_perms = "root:root"; + info.listen_accept_role = "raw-skt"; + info.listen_accept_protocol = "ssproxy-protocol"; + info.protocols = protocols; + + if (!lws_create_vhost(context, &info)) { + lwsl_err("%s: Failed to create ss proxy vhost\n", __func__); + + return 1; + } + + return 0; +} diff -Nru libwebsockets-3.2.1/lib/secure-streams/secure-streams-serialize.c libwebsockets-4.1.6/lib/secure-streams/secure-streams-serialize.c --- libwebsockets-3.2.1/lib/secure-streams/secure-streams-serialize.c 1970-01-01 00:00:00.000000000 +0000 +++ libwebsockets-4.1.6/lib/secure-streams/secure-streams-serialize.c 2020-12-01 17:40:26.000000000 +0000 @@ -0,0 +1,1232 @@ +/* + * libwebsockets - small server side websockets and web server implementation + * + * Copyright (C) 2019 - 2020 Andy Green + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to + * deal in the Software without restriction, including without limitation the + * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or + * sell copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS + * IN THE SOFTWARE. + * + * + * In the case Secure Streams protocol needs to pass through a buffer, + * or a streamed connection, the protocol metadata must be serialized. This + * file provides internal apis to perform the serialization and deserialization + * in and out of an lws_dsh fifo-type buffer. + */ + +#include + +typedef enum { + RPAR_TYPE, + RPAR_LEN_MSB, + RPAR_LEN_LSB, + + RPAR_FLAG_B3, + RPAR_FLAG_B2, + RPAR_FLAG_B1, + RPAR_FLAG_B0, + + RPAR_LATA3, + RPAR_LATA2, + RPAR_LATA1, + RPAR_LATA0, + + RPAR_LATB7, + RPAR_LATB6, + RPAR_LATB5, + RPAR_LATB4, + RPAR_LATB3, + RPAR_LATB2, + RPAR_LATB1, + RPAR_LATB0, + + RPAR_RIDESHARE_LEN, + RPAR_RIDESHARE, + + RPAR_RESULT_CREATION_RIDESHARE, + + RPAR_METADATA_NAMELEN, + RPAR_METADATA_NAME, + RPAR_METADATA_VALUE, + + RPAR_PAYLOAD, + + RPAR_RX_TXCR_UPDATE, + + RPAR_STREAMTYPE, + RPAR_INITTXC0, + + RPAR_TXCR0, + + RPAR_TIMEOUT0, + + RPAR_PAYLEN0, + + RPAR_RESULT_CREATION, + + RPAR_STATEINDEX, + RPAR_ORD3, + RPAR_ORD2, + RPAR_ORD1, + RPAR_ORD0, +} rx_parser_t; + +#if defined(_DEBUG) +static const char *sn[] = { + "unset", + + "LPCSPROX_WAIT_INITIAL_TX", + "LPCSPROX_REPORTING_FAIL", + "LPCSPROX_REPORTING_OK", + "LPCSPROX_OPERATIONAL", + "LPCSPROX_DESTROYED", + + "LPCSCLI_SENDING_INITIAL_TX", + "LPCSCLI_WAITING_CREATE_RESULT", + "LPCSCLI_LOCAL_CONNECTED", + "LPCSCLI_ONWARD_CONNECT", + "LPCSCLI_OPERATIONAL", +}; +#endif + +void +lws_ss_serialize_state_transition(lws_ss_conn_states_t *state, int new_state) +{ +#if defined(_DEBUG) + lwsl_info("%s: %s -> %s\n", __func__, sn[*state], sn[new_state]); +#endif + *state = new_state; +} + + +/* + * event loop received something and is queueing it for the foreign side of + * the dsh to consume later as serialized rx + */ + +int +lws_ss_serialize_rx_payload(struct lws_dsh *dsh, const uint8_t *buf, + size_t len, int flags, const char *rsp) +{ + lws_usec_t us = lws_now_usecs(); + uint8_t pre[128]; + int est = 19, l = 0; + + if (flags & LWSSS_FLAG_RIDESHARE) { + /* + * We should have the rideshare name if we have been told it's + * on a non-default rideshare + */ + assert(rsp); + if (!rsp) + return 1; + l = strlen(rsp); + est += 1 + l; + } else + assert(!rsp); + + // lwsl_user("%s: len %d, flags: %d\n", __func__, (int)len, flags); + // lwsl_hexdump_info(buf, len); + + pre[0] = LWSSS_SER_RXPRE_RX_PAYLOAD; + lws_ser_wu16be(&pre[1], len + est - 3); + lws_ser_wu32be(&pre[3], flags); + lws_ser_wu32be(&pre[7], 0); /* write will compute latency here... */ + lws_ser_wu64be(&pre[11], us); /* ... and set this to the write time */ + + /* + * If we are on a non-default rideshare, append the non-default name to + * the headers of the payload part, 1-byte length first + */ + + if (flags & LWSSS_FLAG_RIDESHARE) { + pre[19] = (uint8_t)l; + memcpy(&pre[20], rsp, l); + } + + if (lws_dsh_alloc_tail(dsh, KIND_SS_TO_P, pre, est, buf, len)) { + lwsl_err("%s: unable to alloc in dsh 1\n", __func__); + + return 1; + } + + return 0; +} + +/* + * event loop is consuming dsh-buffered, already-serialized tx from the + * foreign side + */ + +int +lws_ss_deserialize_tx_payload(struct lws_dsh *dsh, struct lws *wsi, + lws_ss_tx_ordinal_t ord, uint8_t *buf, + size_t *len, int *flags) +{ + uint8_t *p; + size_t si; + + if (lws_dsh_get_head(dsh, KIND_C_TO_P, (void **)&p, &si)) { + *len = 0; + return 0; + } + + /* + * The packet in the dsh has a proxying serialization header, process + * and strip it so we just forward the payload + */ + + if (*len <= si - 23 || si < 23) { + /* + * What comes out of the dsh needs to fit in the tx buffer... + * we have arrangements at the proxy rx of the client UDS to + * chop chunks larger than 1380 into seuqential lumps of 1380 + */ + lwsl_err("%s: *len = %d, si = %d\n", __func__, (int)*len, (int)si); + assert(0); + return 1; + } + if (p[0] != LWSSS_SER_TXPRE_TX_PAYLOAD) { + assert(0); + return 1; + } + + *len = lws_ser_ru16be(&p[1]) - (23 - 3); + if (*len != si - 23) { + /* + * We cannot accept any length that doesn't reflect the actual + * length of what came in from the dsh, either something nasty + * happened with truncation or we are being attacked + */ + assert(0); + + return 1; + } + + memcpy(buf, p + 23, si - 23); + + *flags = lws_ser_ru32be(&p[3]); + +#if defined(LWS_WITH_DETAILED_LATENCY) + if (wsi && wsi->a.context->detailed_latency_cb) { + /* + * use the proxied latency information to compute the client + * and our delays, and apply to wsi. + * + * + 7 u32 us held at client before written + * +11 u32 us taken for transit to proxy + * +15 u64 ustime when proxy got packet from client + */ + lws_usec_t us = lws_now_usecs(); + + wsi->detlat.acc_size = wsi->detlat.req_size = si - 23; + wsi->detlat.latencies[LAT_DUR_PROXY_CLIENT_REQ_TO_WRITE] = + lws_ser_ru32be(&p[7]); + wsi->detlat.latencies[LAT_DUR_PROXY_CLIENT_WRITE_TO_PROXY_RX] = + lws_ser_ru32be(&p[11]); + wsi->detlat.latencies[LAT_DUR_PROXY_RX_TO_ONWARD_TX] = + us - lws_ser_ru64be(&p[15]); + + wsi->detlat.latencies[LAT_DUR_USERCB] = 0; + } +#endif + + // lwsl_user("%s: len %d, flags: %d\n", __func__, (int)*len, *flags); + // lwsl_hexdump_info(buf, *len); + + lws_dsh_free((void **)&p); + + return 0; +} + +/* + * event loop side is issuing state, serialize and put it in the dbuf for + * the foreign side to consume later + */ + +int +lws_ss_serialize_state(struct lws_dsh *dsh, lws_ss_constate_t state, + lws_ss_tx_ordinal_t ack) +{ + uint8_t pre[12]; + int n = 4; + + lwsl_info("%s: %s, ord 0x%x\n", __func__, lws_ss_state_name(state), + (unsigned int)ack); + + pre[0] = LWSSS_SER_RXPRE_CONNSTATE; + pre[1] = 0; + + if (state > 255) { + pre[2] = 8; + lws_ser_wu32be(&pre[3], state); + n = 7; + } else { + pre[2] = 5; + pre[3] = (uint8_t)state; + } + + lws_ser_wu32be(&pre[n], ack); + + if (lws_dsh_alloc_tail(dsh, KIND_SS_TO_P, pre, n + 4, NULL, 0)) { + lwsl_err("%s: unable to alloc in dsh 2\n", __func__); + + return 1; + } + + return 0; +} + +/* + * event loop side was told about remote peer tx credit window update, serialize + * and put it in the dbuf for the foreign side to consume later + */ + +int +lws_ss_serialize_txcr(struct lws_dsh *dsh, int txcr) +{ + uint8_t pre[7]; + + lwsl_info("%s: %d\n", __func__, txcr); + + pre[0] = LWSSS_SER_RXPRE_TXCR_UPDATE; + pre[1] = 0; + pre[2] = 4; + lws_ser_wu32be(&pre[3], txcr); + + if (lws_dsh_alloc_tail(dsh, KIND_SS_TO_P, pre, 7, NULL, 0)) { + lwsl_err("%s: unable to alloc in dsh 2\n", __func__); + + return 1; + } + + return 0; +} + +/* + * event loop side is consuming serialized data from the client via dsh, parse + * it using a bytewise parser for the serialization header(s)... + * it's possibly coalesced + * + * client: pss is pointing to the start of userdata. We can use + * pss_to_sspc_h(_pss, _ssi) to convert that to a pointer to the sspc + * handle + * + * proxy: pss is pointing to &conn->ss, a pointer to the ss handle + * + * Returns one of + * + * LWSSSSRET_OK + * LWSSSSRET_DISCONNECT_ME + * LWSSSSRET_DESTROY_ME + */ + +/* convert userdata ptr _pss to handle pointer, allowing for any layout in + * userdata */ +#define client_pss_to_sspc_h(_pss, _ssi) (*((lws_sspc_handle_t **) \ + ((uint8_t *)_pss) + _ssi->handle_offset)) +/* client pss to sspc userdata */ +#define client_pss_to_userdata(_pss) ((void *)_pss) +/* proxy convert pss to ss handle */ +#define proxy_pss_to_ss_h(_pss) (*_pss) + +/* convert userdata ptr _pss to handle pointer, allowing for any layout in + * userdata */ +#define client_pss_to_sspc_h(_pss, _ssi) (*((lws_sspc_handle_t **) \ + ((uint8_t *)_pss) + _ssi->handle_offset)) +/* client pss to sspc userdata */ +#define client_pss_to_userdata(_pss) ((void *)_pss) +/* proxy convert pss to ss handle */ +#define proxy_pss_to_ss_h(_pss) (*_pss) + +int +lws_ss_deserialize_parse(struct lws_ss_serialization_parser *par, + struct lws_context *context, + struct lws_dsh *dsh, const uint8_t *cp, size_t len, + lws_ss_conn_states_t *state, void *parconn, + lws_ss_handle_t **pss, lws_ss_info_t *ssi, char client) +{ + lws_ss_metadata_t *pm; + lws_sspc_handle_t *h; + uint8_t pre[23]; + lws_usec_t us; + uint32_t flags; + uint8_t *p; + int n; + + while (len--) { + switch (par->ps) { + case RPAR_TYPE: + par->type = *cp++; + par->ps++; + break; + + case RPAR_LEN_MSB: /* this is remaining frame length */ + par->rem = (*cp++) << 8; + par->ps++; + break; + + case RPAR_LEN_LSB: + par->rem |= *cp++; + switch (par->type) { + + /* event loop side */ + + case LWSSS_SER_TXPRE_TX_PAYLOAD: + if (client) + goto hangup; + if (*state != LPCSPROX_OPERATIONAL) + goto hangup; + + par->ps = RPAR_FLAG_B3; + break; + + case LWSSS_SER_TXPRE_DESTROYING: + if (client) + goto hangup; + par->ps = RPAR_TYPE; + lwsl_notice("%s: DESTROYING\n", __func__); + goto hangup; + + case LWSSS_SER_TXPRE_ONWARD_CONNECT: + if (client) + goto hangup; + if (*state != LPCSPROX_OPERATIONAL) + goto hangup; + par->ps = RPAR_TYPE; + lwsl_notice("%s: LWSSS_SER_TXPRE_ONWARD_CONNECT\n", __func__); + if (proxy_pss_to_ss_h(pss) && + !proxy_pss_to_ss_h(pss)->wsi) + _lws_ss_client_connect( + proxy_pss_to_ss_h(pss), 0); + break; + + case LWSSS_SER_TXPRE_STREAMTYPE: + if (client) + goto hangup; + if (*state != LPCSPROX_WAIT_INITIAL_TX) + goto hangup; + if (par->rem < 4) + goto hangup; + par->ctr = 0; + par->ps = RPAR_INITTXC0; + break; + + case LWSSS_SER_TXPRE_METADATA: + if (client) + goto hangup; + if (par->rem < 3) + goto hangup; + par->ctr = 0; + par->ps = RPAR_METADATA_NAMELEN; + break; + + case LWSSS_SER_TXPRE_TXCR_UPDATE: + par->ps = RPAR_TXCR0; + par->ctr = 0; + break; + + case LWSSS_SER_TXPRE_TIMEOUT_UPDATE: + if (client) + goto hangup; + if (par->rem != 4) + goto hangup; + par->ps = RPAR_TIMEOUT0; + par->ctr = 0; + break; + + case LWSSS_SER_TXPRE_PAYLOAD_LENGTH_HINT: + if (client) + goto hangup; + if (par->rem != 4) + goto hangup; + par->ps = RPAR_PAYLEN0; + par->ctr = 0; + break; + + /* client side */ + + case LWSSS_SER_RXPRE_RX_PAYLOAD: + if (!client) + goto hangup; + if (*state != LPCSCLI_OPERATIONAL && + *state != LPCSCLI_LOCAL_CONNECTED) + goto hangup; + + par->rideshare[0] = '\0'; + par->ps = RPAR_FLAG_B3; + break; + + case LWSSS_SER_RXPRE_CREATE_RESULT: + if (!client) + goto hangup; + if (*state != LPCSCLI_WAITING_CREATE_RESULT) + goto hangup; + + if (par->rem < 1) + goto hangup; + + par->ps = RPAR_RESULT_CREATION; + break; + + case LWSSS_SER_RXPRE_CONNSTATE: + if (!client) + goto hangup; + if (*state != LPCSCLI_LOCAL_CONNECTED && + *state != LPCSCLI_OPERATIONAL) + goto hangup; + + if (par->rem < 5 || par->rem > 8) + goto hangup; + + par->ps = RPAR_STATEINDEX; + par->ctr = 0; + break; + + case LWSSS_SER_RXPRE_TXCR_UPDATE: + par->ctr = 0; + par->ps = RPAR_RX_TXCR_UPDATE; + break; + + default: + lwsl_notice("%s: bad type 0x%x\n", __func__, + par->type); + goto hangup; + } + break; + + case RPAR_FLAG_B3: + case RPAR_FLAG_B2: + case RPAR_FLAG_B1: + case RPAR_FLAG_B0: + par->flags <<= 8; + par->flags |= *cp++; + par->ps++; + if (!par->rem--) + goto hangup; + break; + + case RPAR_LATA3: + case RPAR_LATA2: + case RPAR_LATA1: + case RPAR_LATA0: + par->usd_phandling <<= 8; + par->usd_phandling |= *cp++; + par->ps++; + if (!par->rem--) + goto hangup; + break; + + case RPAR_LATB7: + case RPAR_LATB6: + case RPAR_LATB5: + case RPAR_LATB4: + case RPAR_LATB3: + case RPAR_LATB2: + case RPAR_LATB1: + case RPAR_LATB0: + par->ust_pwait <<= 8; + par->ust_pwait |= *cp++; + par->ps++; + par->frag1 = 1; + if (!par->rem--) + goto hangup; + + if (par->ps == RPAR_RIDESHARE_LEN && + !(par->flags & LWSSS_FLAG_RIDESHARE)) + par->ps = RPAR_PAYLOAD; + + if (par->rem) + break; + + /* fallthru - handle 0-length payload */ + + if (!(par->flags & LWSSS_FLAG_RIDESHARE)) + goto payload_ff; + goto hangup; + + /* + * Inbound rideshare info is provided on the RX packet + * itself + */ + + case RPAR_RIDESHARE_LEN: + par->slen = *cp++; + par->ctr = 0; + par->ps++; + if (par->rem-- < par->slen) + goto hangup; + break; + + case RPAR_RIDESHARE: + par->rideshare[par->ctr++] = *cp++; + if (!par->rem--) + goto hangup; + if (par->ctr != par->slen) + break; + par->ps = RPAR_PAYLOAD; + if (par->rem) + break; + + /* fallthru - handle 0-length payload */ + + case RPAR_PAYLOAD: +payload_ff: + n = (int)len + 1; + if (n > par->rem) + n = par->rem; + /* + * We get called with a serialized buffer of a size + * chosen by the client. We can only create dsh entries + * with up to 1380 payload, to guarantee we can emit + * them on the onward connection atomically. + * + * If 1380 isn't enough to cover what was handed to us, + * we'll stop at 1380 and go around again and create + * more dsh entries for the rest, with their own + * headers. + */ + + if (n > 1380) + n = 1380; + + /* + * Since we're in the business of fragmenting client + * serialized payloads at 1380, we have to deal with + * refragmenting the SOM / EOM flags that covered the + * whole client serialized packet, so they apply to + * each dsh entry we split it into correctly + */ + + flags = par->flags & LWSSS_FLAG_RELATED_START; + if (par->frag1) + /* + * Only set the first time we came to this + * state after deserialization of the header + */ + flags |= par->flags & + (LWSSS_FLAG_SOM | LWSSS_FLAG_POLL); + + if (par->rem == n) + /* + * We are going to complete the advertised + * payload length from the client on this dsh, + * so give him the EOM type flags if any + */ + flags |= par->flags & (LWSSS_FLAG_EOM | + LWSSS_FLAG_RELATED_END); + + par->frag1 = 0; + us = lws_now_usecs(); + + if (!client) { + /* + * Proxy - we received some serialized tx from + * the client. + * + * The header for buffering private to the + * proxy is 23 bytes vs 19, so we can hold the + * current time when it was buffered + * additionally + */ + + lwsl_info("%s: C2P RX: len %d\n", __func__, + (int)n); + + p = pre; + pre[0] = LWSSS_SER_TXPRE_TX_PAYLOAD; + lws_ser_wu16be(&p[1], n + 23 - 3); + lws_ser_wu32be(&p[3], flags); + /* us held at client before written */ + lws_ser_wu32be(&p[7], par->usd_phandling); + /* us taken for transit to proxy */ + lws_ser_wu32be(&p[11], us - par->ust_pwait); + /* time used later to find proxy hold time */ + lws_ser_wu64be(&p[15], us); + + if (lws_dsh_alloc_tail(dsh, KIND_C_TO_P, pre, + 23, cp, n)) { + lwsl_err("%s: unable to alloc in dsh 3\n", + __func__); + + return LWSSSSRET_DISCONNECT_ME; + } + + if (proxy_pss_to_ss_h(pss)) + lws_ss_request_tx( + proxy_pss_to_ss_h(pss)); + } else { + + /* + * Client receives some RX from proxy + * + * Pass whatever payload we have to ss user + */ + + lwsl_info("%s: P2C RX: len %d\n", __func__, + (int)n); + + h = lws_container_of(par, lws_sspc_handle_t, + parser); + h->txc.peer_tx_cr_est -= n; + + if (client_pss_to_sspc_h(pss, ssi)) { + /* we still have an sspc handle */ + int ret = ssi->rx(client_pss_to_userdata(pss), + (uint8_t *)cp, n, flags); + switch (ret) { + case LWSSSSRET_OK: + break; + case LWSSSSRET_DISCONNECT_ME: + goto hangup; + case LWSSSSRET_DESTROY_ME: + return LWSSSSRET_DESTROY_ME; + } + } + +#if defined(LWS_WITH_DETAILED_LATENCY) + if (lws_det_lat_active(context)) { + lws_detlat_t d; + + d.type = LDLT_READ; + d.acc_size = d.req_size = n; + d.latencies[LAT_DUR_USERCB] = + lws_now_usecs() - us; + d.latencies[LAT_DUR_PROXY_CLIENT_REQ_TO_WRITE] = + par->usd_phandling; + d.latencies[LAT_DUR_PROXY_CLIENT_WRITE_TO_PROXY_RX] = + us - par->ust_pwait; + + lws_det_lat_cb(context, &d); + } +#endif + } + + if (n) { + cp += n; + par->rem -= n; + len = (len + 1) - n; + /* + * if we didn't consume it all, we'll come + * around again and produce more dsh entries up + * to 1380 each until it is gone + */ + } + if (!par->rem) + par->ps = RPAR_TYPE; + break; + + case RPAR_RX_TXCR_UPDATE: + if (!--par->rem && par->ctr != 3) + goto hangup; + + par->temp32 = (par->temp32 << 8) | *cp++; + if (++par->ctr < 4) + break; + + /* + * Proxy is telling us remote endpoint is allowing us + * par->temp32 more bytes tx credit to write to it + */ + + h = lws_container_of(par, lws_sspc_handle_t, parser); + h->txc.tx_cr += par->temp32; + lwsl_info("%s: RX_PEER_TXCR: %d\n", __func__, par->temp32); + lws_sspc_request_tx(h); /* in case something waiting */ + par->ctr = 0; + par->ps = RPAR_TYPE; + break; + + case RPAR_INITTXC0: + if (!--par->rem) + goto hangup; + + par->temp32 = (par->temp32 << 8) | *cp++; + if (++par->ctr < 4) + break; + + par->txcr_out = par->temp32; + par->ctr = 0; + par->ps = RPAR_STREAMTYPE; + break; + + /* + * These are the client adjusting our / the remote peer ability + * to send back to him. He's sending a signed u32 BE + */ + + case RPAR_TXCR0: + + par->temp32 = (par->temp32 << 8) | *cp++; + if (++par->ctr < 4) { + if (!--par->rem) + goto hangup; + break; + } + + if (--par->rem) + goto hangup; + + if (!client) { + /* + * We're the proxy, being told by the client + * that it wants to allow more tx from the peer + * on the onward connection towards it. + */ +#if defined(LWS_ROLE_H2) || defined(LWS_ROLE_MQTT) + if (proxy_pss_to_ss_h(pss) && + proxy_pss_to_ss_h(pss)->wsi) { + lws_wsi_tx_credit( + proxy_pss_to_ss_h(pss)->wsi, + LWSTXCR_PEER_TO_US, + par->temp32); + lwsl_notice("%s: proxy RX_PEER_TXCR: +%d (est %d)\n", + __func__, par->temp32, + proxy_pss_to_ss_h(pss)->wsi-> + txc.peer_tx_cr_est); + lws_ss_request_tx(proxy_pss_to_ss_h(pss)); + } else +#endif + lwsl_info("%s: dropping TXCR\n", __func__); + } else { + /* + * We're the client, being told by the proxy + * about tx credit being given to us from the + * remote peer, allowing the client to write to + * it. + */ + h = lws_container_of(par, lws_sspc_handle_t, + parser); + h->txc.tx_cr += par->temp32; + lwsl_info("%s: client RX_PEER_TXCR: %d\n", + __func__, par->temp32); + lws_sspc_request_tx(h); /* in case something waiting */ + } + par->ps = RPAR_TYPE; + break; + + case RPAR_TIMEOUT0: + + par->temp32 = (par->temp32 << 8) | *cp++; + if (++par->ctr < 4) { + if (!--par->rem) + goto hangup; + break; + } + + if (--par->rem) + goto hangup; + + /* + * Proxy... + * + * *pss may have gone away asynchronously inbetweentimes + */ + + if (proxy_pss_to_ss_h(pss)) { + + if ((unsigned int)par->temp32 == 0xffffffff) { + lwsl_notice("%s: cancel ss timeout\n", + __func__); + lws_ss_cancel_timeout( + proxy_pss_to_ss_h(pss)); + } else { + + if (!par->temp32) + par->temp32 = + proxy_pss_to_ss_h(pss)-> + policy->timeout_ms; + + lwsl_notice("%s: set ss timeout for +%ums\n", + __func__, par->temp32); + + lws_ss_start_timeout( + proxy_pss_to_ss_h(pss), + par->temp32); + } + } + + par->ps = RPAR_TYPE; + break; + + case RPAR_PAYLEN0: + /* + * It's the length from lws_ss_request_tx_len() being + * passed up to the proxy + */ + par->temp32 = (par->temp32 << 8) | *cp++; + if (++par->ctr < 4) { + if (!--par->rem) + goto hangup; + break; + } + + if (--par->rem) + goto hangup; + + lwsl_notice("%s: set payload len %u\n", __func__, + par->temp32); + + if (proxy_pss_to_ss_h(pss)) + lws_ss_request_tx_len(proxy_pss_to_ss_h(pss), + par->temp32); + + par->ps = RPAR_TYPE; + break; + + case RPAR_METADATA_NAMELEN: + if (!--par->rem) + goto hangup; + par->slen = *cp++; + if (par->slen >= sizeof(par->metadata_name) - 1) + goto hangup; + par->ctr = 0; + par->ps++; + break; + + case RPAR_METADATA_NAME: + if (!--par->rem) + goto hangup; + par->metadata_name[par->ctr++] = *cp++; + if (par->ctr != par->slen) + break; + par->metadata_name[par->ctr] = '\0'; + par->ps = RPAR_METADATA_VALUE; + + /* only proxy side can receive these */ + + if (!proxy_pss_to_ss_h(pss)) + goto hangup; + + /* + * This is the policy's metadata list for the given + * name + */ + pm = lws_ss_policy_metadata(proxy_pss_to_ss_h(pss)->policy, + par->metadata_name); + if (!pm) { + lwsl_err("%s: metadata %s not in proxy policy\n", + __func__, par->metadata_name); + + goto hangup; + } + + par->ssmd = &proxy_pss_to_ss_h(pss)->metadata[pm->length]; + + if (par->ssmd->value_on_lws_heap) + lws_free_set_NULL(par->ssmd->value); + par->ssmd->value_on_lws_heap = 0; + + par->ssmd->value = lws_malloc(par->rem + 1, "metadata"); + if (!par->ssmd->value) { + lwsl_err("%s: OOM mdv\n", __func__); + goto hangup; + } + par->ssmd->length = par->rem; + /* mark it as needing cleanup */ + par->ssmd->value_on_lws_heap = 1; + par->ctr = 0; + break; + + case RPAR_METADATA_VALUE: + ((uint8_t *)(par->ssmd->value))[par->ctr++] = *cp++; + if (--par->rem) + break; + + /* we think we got all the value */ + lwsl_info("%s: RPAR_METADATA_VALUE for %s (len %d)\n", + __func__, par->ssmd->name, + (int)par->ssmd->length); + lwsl_hexdump_info(par->ssmd->value, par->ssmd->length); + par->ps = RPAR_TYPE; + break; + + case RPAR_STREAMTYPE: + + /* only the proxy can get these */ + + if (client) + goto hangup; + if (par->ctr == sizeof(par->streamtype) - 1) + goto hangup; + + /* + * We can only expect to get this if we ourselves are + * in the state that we're waiting for it. If it comes + * later it's a protocol error. + */ + + if (*state != LPCSPROX_WAIT_INITIAL_TX) + goto hangup; + + /* + * We're the proxy, creating an SS on behalf of a + * client + */ + + par->streamtype[par->ctr++] = *cp++; + if (--par->rem) + break; + + par->ps = RPAR_TYPE; + par->streamtype[par->ctr] = '\0'; + lwsl_notice("%s: creating proxied ss '%s', txcr %d\n", + __func__, par->streamtype, par->txcr_out); + + ssi->streamtype = par->streamtype; + if (par->txcr_out) // !!! + ssi->manual_initial_tx_credit = par->txcr_out; + + /* + * Even for a synthetic SS proxing action like _lws_smd, + * we create an actual SS in the proxy representing the + * connection + */ + + ssi->flags |= LWSSSINFLAGS_PROXIED; + if (lws_ss_create(context, 0, ssi, parconn, pss, + NULL, NULL)) { + /* + * We're unable to create the onward secure + * stream he asked for... schedule a chance to + * inform him + */ + lwsl_err("%s: create '%s' fail\n", + __func__, par->streamtype); + *state = LPCSPROX_REPORTING_FAIL; + } else { + lwsl_debug("%s: create '%s' OK\n", + __func__, par->streamtype); + *state = LPCSPROX_REPORTING_OK; + } + + if (*pss) { + (*pss)->being_serialized = 1; +#if defined(LWS_WITH_SYS_SMD) + if ((*pss)->policy != &pol_smd) + /* + * In SMD case we overloaded the + * initial credit to be the class mask + */ +#endif + { + lwsl_info("%s: Created SS initial credit %d\n", + __func__, par->txcr_out); + + (*pss)->info.manual_initial_tx_credit = par->txcr_out; + } + } + + /* parent needs to schedule write on client conn */ + break; + + /* clientside states */ + + case RPAR_RESULT_CREATION: + if (*cp++) { + lwsl_err("%s: stream creation failed\n", + __func__); + goto hangup; + } + + /* + * Client + */ + + lws_ss_serialize_state_transition(state, + LPCSCLI_LOCAL_CONNECTED); + h = lws_container_of(par, lws_sspc_handle_t, parser); + + /* + * This is telling us that the streamtype could be (and + * was) created at the proxy. It's not telling us that + * the onward peer connection could be connected. + * + * We'll get a proxied state() coming later that informs + * us about the situation with that. + * + * However at this point, we should choose to inform + * the client that his stream was created... we will + * later get a proxied CREATING state from the peer + * but we should do it now and suppress the later one. + * + * The reason is he may set metadata in CREATING, and + * we will try to do writeables to sync the stream to + * master and ultimately bring up the onward connection now + * now we are in LOCAL_CONNECTED. We need to do the + * CREATING now so we'll know the metadata to sync. + */ + + h->creating_cb_done = 1; + + n = ssi->state(client_pss_to_userdata(pss), + NULL, LWSSSCS_CREATING, 0); + switch (n) { + case LWSSSSRET_OK: + break; + case LWSSSSRET_DISCONNECT_ME: + goto hangup; + case LWSSSSRET_DESTROY_ME: + return LWSSSSRET_DESTROY_ME; + } + + if (h->cwsi) + lws_callback_on_writable(h->cwsi); + + par->rsl_pos = 0; + par->rsl_idx = 0; + + memset(&h->rideshare_ofs[0], 0, sizeof(h->rideshare_ofs[0])); + h->rideshare_list[0] = '\0'; + h->rsidx = 0; + + if (!--par->rem) + par->ps = RPAR_TYPE; + else { + par->ps = RPAR_RESULT_CREATION_RIDESHARE; + if (par->rem >= sizeof(h->rideshare_list)) + goto hangup; + } + break; + + case RPAR_RESULT_CREATION_RIDESHARE: + h = lws_container_of(par, lws_sspc_handle_t, parser); + if (*cp == ',') { + cp++; + h->rideshare_list[par->rsl_pos++] = '\0'; + if (par->rsl_idx == LWS_ARRAY_SIZE(h->rideshare_ofs)) + goto hangup; + h->rideshare_ofs[++par->rsl_idx] = par->rsl_pos; + } else + h->rideshare_list[par->rsl_pos++] = *cp++; + if (!--par->rem) + par->ps = RPAR_TYPE; + break; + + case RPAR_STATEINDEX: + par->ctr = (par->ctr << 8) | (*cp++); + if (--par->rem == 4) + par->ps = RPAR_ORD3; + break; + + case RPAR_ORD3: + par->flags = (*cp++) << 24; + par->ps++; + break; + + case RPAR_ORD2: + par->flags |= (*cp++) << 16; + par->ps++; + break; + + case RPAR_ORD1: + par->flags |= (*cp++) << 8; + par->ps++; + break; + + case RPAR_ORD0: + par->flags |= *cp++; + par->ps++; + par->ps = RPAR_TYPE; + + /* + * Client received a proxied state change + */ + + if (!client_pss_to_sspc_h(pss, ssi)) + /* + * Since we're being informed we need to have + * a stream to inform. Assume whatever set this + * to NULL has started to close it. + */ + break; + + switch (par->ctr) { + case LWSSSCS_DISCONNECTED: + case LWSSSCS_UNREACHABLE: + case LWSSSCS_AUTH_FAILED: + lws_ss_serialize_state_transition(state, + LPCSCLI_LOCAL_CONNECTED); + client_pss_to_sspc_h(pss, ssi)->conn_req_state = + LWSSSPC_ONW_NONE; + break; + case LWSSSCS_CONNECTED: + lwsl_info("%s: CONNECTED %s\n", __func__, + ssi->streamtype); + if (*state == LPCSCLI_OPERATIONAL) + /* + * Don't allow to see connected more + * than once for one connection + */ + goto swallow; + lws_ss_serialize_state_transition(state, + LPCSCLI_OPERATIONAL); + + client_pss_to_sspc_h(pss, ssi)->conn_req_state = + LWSSSPC_ONW_CONN; + break; + case LWSSSCS_TIMEOUT: + break; + default: + break; + } + + if (par->ctr < 0) + goto hangup; + +#if defined(_DEBUG) + lwsl_info("%s: forwarding proxied state %s\n", + __func__, lws_ss_state_name(par->ctr)); +#endif + + if (par->ctr == LWSSSCS_CREATING) { + if (h->creating_cb_done) + /* + * We have told him he's CREATING when + * we heard we had linked up to the + * proxy, so suppress the remote + * CREATING so that he only sees it once + */ + break; + + h->creating_cb_done = 1; + } + + n = ssi->state(client_pss_to_userdata(pss), + NULL, par->ctr, par->flags); + switch (n) { + case LWSSSSRET_OK: + break; + case LWSSSSRET_DISCONNECT_ME: + goto hangup; + case LWSSSSRET_DESTROY_ME: + return LWSSSSRET_DESTROY_ME; + } + +swallow: + break; + + default: + goto hangup; + } + } + + return LWSSSSRET_OK; + +hangup: + return LWSSSSRET_DISCONNECT_ME; +} diff -Nru libwebsockets-3.2.1/lib/secure-streams/system/auth-api.amazon.com/auth.c libwebsockets-4.1.6/lib/secure-streams/system/auth-api.amazon.com/auth.c --- libwebsockets-3.2.1/lib/secure-streams/system/auth-api.amazon.com/auth.c 1970-01-01 00:00:00.000000000 +0000 +++ libwebsockets-4.1.6/lib/secure-streams/system/auth-api.amazon.com/auth.c 2020-12-01 17:40:26.000000000 +0000 @@ -0,0 +1,285 @@ +/* + * LWA auth support for Secure Streams + * + * libwebsockets - small server side websockets and web server implementation + * + * Copyright (C) 2019 - 2020 Andy Green + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to + * deal in the Software without restriction, including without limitation the + * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or + * sell copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS + * IN THE SOFTWARE. + */ + +#include + +typedef struct ss_api_amazon_auth { + struct lws_ss_handle *ss; + void *opaque_data; + /* ... application specific state ... */ + struct lejp_ctx jctx; + size_t pos; + int expires_secs; +} ss_api_amazon_auth_t; + +static const char * const lejp_tokens_lwa[] = { + "access_token", + "expires_in", +}; + +typedef enum { + LSSPPT_ACCESS_TOKEN, + LSSPPT_EXPIRES_IN, +} lejp_tokens_t; + +enum { + AUTH_IDX_LWA, + AUTH_IDX_ROOT, +}; + +static void +lws_ss_sys_auth_api_amazon_com_kick(lws_sorted_usec_list_t *sul) +{ + struct lws_context *context = lws_container_of(sul, struct lws_context, + sul_api_amazon_com_kick); + + lws_state_transition_steps(&context->mgr_system, + LWS_SYSTATE_OPERATIONAL); +} + +static void +lws_ss_sys_auth_api_amazon_com_renew(lws_sorted_usec_list_t *sul) +{ + struct lws_context *context = lws_container_of(sul, struct lws_context, + sul_api_amazon_com); + + lws_ss_sys_auth_api_amazon_com(context); +} + +static signed char +auth_api_amazon_com_parser_cb(struct lejp_ctx *ctx, char reason) +{ + ss_api_amazon_auth_t *m = (ss_api_amazon_auth_t *)ctx->user; + struct lws_context *context = (struct lws_context *)m->opaque_data; + lws_system_blob_t *blob; + + if (!(reason & LEJP_FLAG_CB_IS_VALUE) || !ctx->path_match) + return 0; + + switch (ctx->path_match - 1) { + case LSSPPT_ACCESS_TOKEN: + if (!ctx->npos) + break; + + blob = lws_system_get_blob(context, LWS_SYSBLOB_TYPE_AUTH, + AUTH_IDX_LWA); + if (!blob) + return -1; + + if (lws_system_blob_heap_append(blob, + (const uint8_t *)ctx->buf, + ctx->npos)) { + lwsl_err("%s: unable to store auth token\n", __func__); + + return -1; + } + break; + case LSSPPT_EXPIRES_IN: + m->expires_secs = atoi(ctx->buf); + lws_sul_schedule(context, 0, &context->sul_api_amazon_com, + lws_ss_sys_auth_api_amazon_com_renew, + (uint64_t)m->expires_secs * LWS_US_PER_SEC); + break; + } + + return 0; +} + +/* secure streams payload interface */ + +static lws_ss_state_return_t +ss_api_amazon_auth_rx(void *userobj, const uint8_t *buf, size_t len, int flags) +{ + ss_api_amazon_auth_t *m = (ss_api_amazon_auth_t *)userobj; + struct lws_context *context = (struct lws_context *)m->opaque_data; + lws_system_blob_t *ab; + size_t total; + int n; + + ab = lws_system_get_blob(context, LWS_SYSBLOB_TYPE_AUTH, AUTH_IDX_LWA); + /* coverity */ + if (!ab) + return -1; + + if (buf) { + if (flags & LWSSS_FLAG_SOM) { + lejp_construct(&m->jctx, auth_api_amazon_com_parser_cb, + m, lejp_tokens_lwa, + LWS_ARRAY_SIZE(lejp_tokens_lwa)); + lws_system_blob_heap_empty(ab); + } + + n = lejp_parse(&m->jctx, buf, (int)len); + if (n < 0) { + lejp_destruct(&m->jctx); + lws_system_blob_destroy( + lws_system_get_blob(context, + LWS_SYSBLOB_TYPE_AUTH, + AUTH_IDX_LWA)); + + return -1; + } + } + if (!(flags & LWSSS_FLAG_EOM)) + return 0; + + /* we should have the auth token now */ + + total = lws_system_blob_get_size(ab); + lwsl_notice("%s: acquired %u-byte api.amazon.com auth token, exp %ds\n", + __func__, (unsigned int)total, m->expires_secs); + + lejp_destruct(&m->jctx); + + /* we move the system state at auth connection close */ + + return 0; +} + +static lws_ss_state_return_t +ss_api_amazon_auth_tx(void *userobj, lws_ss_tx_ordinal_t ord, uint8_t *buf, + size_t *len, int *flags) +{ + ss_api_amazon_auth_t *m = (ss_api_amazon_auth_t *)userobj; + struct lws_context *context = (struct lws_context *)m->opaque_data; + lws_system_blob_t *ab; + size_t total; + int n; + + /* + * We send out auth slot AUTH_IDX_ROOT, it's the LWA user / device + * identity token + */ + + ab = lws_system_get_blob(context, LWS_SYSBLOB_TYPE_AUTH, AUTH_IDX_ROOT); + if (!ab) + return LWSSSSRET_DESTROY_ME; + + total = lws_system_blob_get_size(ab); + + n = lws_system_blob_get(ab, buf, len, m->pos); + if (n < 0) + return 1; + + if (!m->pos) + *flags |= LWSSS_FLAG_SOM; + + m->pos += *len; + + if (m->pos == total) { + *flags |= LWSSS_FLAG_EOM; + m->pos = 0; /* for next time */ + } + + return 0; +} + +static lws_ss_state_return_t +ss_api_amazon_auth_state(void *userobj, void *sh, lws_ss_constate_t state, + lws_ss_tx_ordinal_t ack) +{ + ss_api_amazon_auth_t *m = (ss_api_amazon_auth_t *)userobj; + struct lws_context *context = (struct lws_context *)m->opaque_data; + lws_system_blob_t *ab; + size_t s; + + lwsl_info("%s: %s, ord 0x%x\n", __func__, lws_ss_state_name(state), + (unsigned int)ack); + + ab = lws_system_get_blob(context, LWS_SYSBLOB_TYPE_AUTH, AUTH_IDX_ROOT); + /* coverity */ + if (!ab) + return LWSSSSRET_DESTROY_ME; + + switch (state) { + case LWSSSCS_CREATING: + lws_ss_set_metadata(m->ss, "ctype", "application/json", 16); + /* fallthru */ + case LWSSSCS_CONNECTING: + s = lws_system_blob_get_size(ab); + if (!s) + lwsl_debug("%s: no auth blob\n", __func__); + lws_ss_request_tx_len(m->ss, (unsigned long)s); + m->pos = 0; + break; + + case LWSSSCS_DISCONNECTED: + /* + * We defer moving the system state forward until we have + * closed our connection + tls for the auth action... this is + * because on small systems, we need that memory recovered + * before we can make another connection subsequently. + * + * At this point, we're ultimately being called from within + * the wsi close process, the tls tunnel is not freed yet. + * Use a sul to actually do it next time around the event loop + * when the close process for the auth wsi has completed and + * the related tls is already freed. + */ + s = lws_system_blob_get_size(ab); + + if (s && context->mgr_system.state != LWS_SYSTATE_OPERATIONAL) + lws_sul_schedule(context, 0, + &context->sul_api_amazon_com_kick, + lws_ss_sys_auth_api_amazon_com_kick, 1); + + context->hss_auth = NULL; + return LWSSSSRET_DESTROY_ME; + + default: + break; + } + + return 0; +} + +int +lws_ss_sys_auth_api_amazon_com(struct lws_context *context) +{ + lws_ss_info_t ssi; + + if (context->hss_auth) /* already exists */ + return 0; + + /* We're making an outgoing secure stream ourselves */ + + memset(&ssi, 0, sizeof(ssi)); + ssi.handle_offset = offsetof(ss_api_amazon_auth_t, ss); + ssi.opaque_user_data_offset = offsetof(ss_api_amazon_auth_t, opaque_data); + ssi.rx = ss_api_amazon_auth_rx; + ssi.tx = ss_api_amazon_auth_tx; + ssi.state = ss_api_amazon_auth_state; + ssi.user_alloc = sizeof(ss_api_amazon_auth_t); + ssi.streamtype = "api_amazon_com_auth"; + + if (lws_ss_create(context, 0, &ssi, context, &context->hss_auth, + NULL, NULL)) { + lwsl_info("%s: Create LWA auth ss failed (policy?)\n", __func__); + return 1; + } + + return 0; +} diff -Nru libwebsockets-3.2.1/lib/secure-streams/system/captive-portal-detect/captive-portal-detect.c libwebsockets-4.1.6/lib/secure-streams/system/captive-portal-detect/captive-portal-detect.c --- libwebsockets-3.2.1/lib/secure-streams/system/captive-portal-detect/captive-portal-detect.c 1970-01-01 00:00:00.000000000 +0000 +++ libwebsockets-4.1.6/lib/secure-streams/system/captive-portal-detect/captive-portal-detect.c 2020-12-01 17:40:26.000000000 +0000 @@ -0,0 +1,89 @@ +/* + * Captive portal detect for Secure Streams + * + * libwebsockets - small server side websockets and web server implementation + * + * Copyright (C) 2019 - 2020 Andy Green + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to + * deal in the Software without restriction, including without limitation the + * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or + * sell copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS + * IN THE SOFTWARE. + */ + +#include + +typedef struct ss_cpd { + struct lws_ss_handle *ss; + void *opaque_data; + /* ... application specific state ... */ + + lws_sorted_usec_list_t sul; +} ss_cpd_t; + +static lws_ss_state_return_t +ss_cpd_state(void *userobj, void *sh, lws_ss_constate_t state, + lws_ss_tx_ordinal_t ack) +{ + ss_cpd_t *m = (ss_cpd_t *)userobj; + struct lws_context *cx = (struct lws_context *)m->opaque_data; + + lwsl_info("%s: %s, ord 0x%x\n", __func__, lws_ss_state_name(state), + (unsigned int)ack); + + switch (state) { + case LWSSSCS_CREATING: + lws_ss_request_tx(m->ss); + break; + case LWSSSCS_QOS_ACK_REMOTE: + lws_system_cpd_set(cx, LWS_CPD_INTERNET_OK); + return LWSSSSRET_DESTROY_ME; + + case LWSSSCS_ALL_RETRIES_FAILED: + case LWSSSCS_DISCONNECTED: + /* + * First result reported sticks... if nothing else, this will + * cover the situation we didn't connect to anything + */ + lws_system_cpd_set(cx, LWS_CPD_NO_INTERNET); + return LWSSSSRET_DESTROY_ME; + + default: + break; + } + + return LWSSSSRET_OK; +} + +static const lws_ss_info_t ssi_cpd = { + .handle_offset = offsetof(ss_cpd_t, ss), + .opaque_user_data_offset = offsetof(ss_cpd_t, opaque_data), + .state = ss_cpd_state, + .user_alloc = sizeof(ss_cpd_t), + .streamtype = "captive_portal_detect", +}; + +int +lws_ss_sys_cpd(struct lws_context *cx) +{ + if (lws_ss_create(cx, 0, &ssi_cpd, cx, NULL, NULL, NULL)) { + lwsl_info("%s: Create stream failed (policy?)\n", __func__); + + return 1; + } + + return 0; +} diff -Nru libwebsockets-3.2.1/lib/secure-streams/system/fetch-policy/fetch-policy.c libwebsockets-4.1.6/lib/secure-streams/system/fetch-policy/fetch-policy.c --- libwebsockets-3.2.1/lib/secure-streams/system/fetch-policy/fetch-policy.c 1970-01-01 00:00:00.000000000 +0000 +++ libwebsockets-4.1.6/lib/secure-streams/system/fetch-policy/fetch-policy.c 2020-12-01 17:40:26.000000000 +0000 @@ -0,0 +1,163 @@ +/* + * Policy fetching for Secure Streams + * + * libwebsockets - small server side websockets and web server implementation + * + * Copyright (C) 2019 - 2020 Andy Green + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to + * deal in the Software without restriction, including without limitation the + * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or + * sell copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS + * IN THE SOFTWARE. + */ + +#include + +typedef struct ss_fetch_policy { + struct lws_ss_handle *ss; + void *opaque_data; + /* ... application specific state ... */ + + lws_sorted_usec_list_t sul; + + uint8_t partway; +} ss_fetch_policy_t; + +/* secure streams payload interface */ + +static lws_ss_state_return_t +ss_fetch_policy_rx(void *userobj, const uint8_t *buf, size_t len, int flags) +{ + ss_fetch_policy_t *m = (ss_fetch_policy_t *)userobj; + struct lws_context *context = (struct lws_context *)m->opaque_data; + + if (flags & LWSSS_FLAG_SOM) { + if (lws_ss_policy_parse_begin(context, 0)) + return LWSSSSRET_OK; + m->partway = 1; + } + + if (len && lws_ss_policy_parse(context, buf, len) < 0) + return LWSSSSRET_OK; + + if (flags & LWSSS_FLAG_EOM) + m->partway = 2; + + return 0; +} + +static lws_ss_state_return_t +ss_fetch_policy_tx(void *userobj, lws_ss_tx_ordinal_t ord, uint8_t *buf, + size_t *len, int *flags) +{ + return 1; +} + +static void +policy_set(lws_sorted_usec_list_t *sul) +{ + ss_fetch_policy_t *m = lws_container_of(sul, ss_fetch_policy_t, sul); + struct lws_context *context = (struct lws_context *)m->opaque_data; + + /* + * We get called if the policy parse was successful, just after the + * ss connection close that was using the vhost from the old policy + */ + + lws_ss_destroy(&m->ss); + + if (lws_ss_policy_set(context, "updated")) + lwsl_err("%s: policy set failed\n", __func__); + else { + context->policy_updated = 1; +#if defined(LWS_WITH_SYS_STATE) + lws_state_transition_steps(&context->mgr_system, + LWS_SYSTATE_OPERATIONAL); +#endif + } +} + +static lws_ss_state_return_t +ss_fetch_policy_state(void *userobj, void *sh, lws_ss_constate_t state, + lws_ss_tx_ordinal_t ack) +{ + ss_fetch_policy_t *m = (ss_fetch_policy_t *)userobj; + struct lws_context *context = (struct lws_context *)m->opaque_data; + + lwsl_info("%s: %s, ord 0x%x\n", __func__, lws_ss_state_name(state), + (unsigned int)ack); + + switch (state) { + case LWSSSCS_CREATING: + lws_ss_request_tx(m->ss); + break; + case LWSSSCS_CONNECTING: + break; + + case LWSSSCS_DISCONNECTED: + lwsl_info("%s: DISCONNECTED\n", __func__); + switch (m->partway) { + case 1: + lws_ss_policy_parse_abandon(context); + break; + + case 2: + lws_sul_schedule(context, 0, &m->sul, policy_set, 1); + break; + } + m->partway = 0; + break; + + default: + break; + } + + return 0; +} + +int +lws_ss_sys_fetch_policy(struct lws_context *context) +{ + lws_ss_info_t ssi; + + if (context->hss_fetch_policy) /* already exists */ + return 0; + + /* We're making an outgoing secure stream ourselves */ + + memset(&ssi, 0, sizeof(ssi)); + ssi.handle_offset = offsetof(ss_fetch_policy_t, ss); + ssi.opaque_user_data_offset = offsetof(ss_fetch_policy_t, opaque_data); + ssi.rx = ss_fetch_policy_rx; + ssi.tx = ss_fetch_policy_tx; + ssi.state = ss_fetch_policy_state; + ssi.user_alloc = sizeof(ss_fetch_policy_t); + ssi.streamtype = "fetch_policy"; + + if (lws_ss_create(context, 0, &ssi, context, &context->hss_fetch_policy, + NULL, NULL)) { + /* + * If there's no fetch_policy streamtype, it can just be we're + * running on a proxied client with no policy of its own, + * it's OK. + */ + lwsl_info("%s: Create LWA auth ss failed (policy?)\n", __func__); + + return 1; + } + + return 0; +} diff -Nru libwebsockets-3.2.1/lib/system/async-dns/async-dns.c libwebsockets-4.1.6/lib/system/async-dns/async-dns.c --- libwebsockets-3.2.1/lib/system/async-dns/async-dns.c 1970-01-01 00:00:00.000000000 +0000 +++ libwebsockets-4.1.6/lib/system/async-dns/async-dns.c 2020-12-01 17:40:26.000000000 +0000 @@ -0,0 +1,763 @@ +/* + * libwebsockets - small server side websockets and web server implementation + * + * Copyright (C) 2010 - 2020 Andy Green + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to + * deal in the Software without restriction, including without limitation the + * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or + * sell copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS + * IN THE SOFTWARE. + */ + +#include "private-lib-core.h" +#include "private-lib-async-dns.h" + +static const uint32_t botable[] = { 500, 1000, 1250, 5000 + /* in case everything just dog slow */ }; +static const lws_retry_bo_t retry_policy = { + botable, LWS_ARRAY_SIZE(botable), LWS_ARRAY_SIZE(botable), + /* don't conceal after the last table entry */ 0, 0, 20 }; + +void +lws_adns_q_destroy(lws_adns_q_t *q) +{ + lws_dll2_remove(&q->sul.list); + lws_dll2_remove(&q->list); + lws_free(q); +} + +lws_adns_q_t * +lws_adns_get_query(lws_async_dns_t *dns, adns_query_type_t qtype, + lws_dll2_owner_t *owner, uint16_t tid, const char *name) +{ + lws_start_foreach_dll_safe(struct lws_dll2 *, d, d1, + lws_dll2_get_head(owner)) { + lws_adns_q_t *q = lws_container_of(d, lws_adns_q_t, list); + + if (!name && (tid & 0xfffe) == (q->tid & 0xfffe)) + return q; + + if (name && q->qtype == ((tid & 1) ? LWS_ADNS_RECORD_AAAA : + LWS_ADNS_RECORD_A) && + !strcasecmp(name, (const char *)&q[1])) { + if (owner == &dns->cached) { + /* Keep sorted by LRU: move to the head */ + lws_dll2_remove(&q->list); + lws_dll2_add_head(&q->list, &dns->cached); + } + + return q; + } + } lws_end_foreach_dll_safe(d, d1); + + return NULL; +} + +void +lws_async_dns_drop_server(struct lws_context *context) +{ + context->async_dns.dns_server_set = 0; + lws_set_timeout(context->async_dns.wsi, 1, LWS_TO_KILL_ASYNC); + context->async_dns.wsi = NULL; +} + +int +lws_async_dns_complete(lws_adns_q_t *q, lws_adns_cache_t *c) +{ + + lws_start_foreach_dll_safe(struct lws_dll2 *, d, d1, + lws_dll2_get_head(&q->wsi_adns)) { + struct lws *w = lws_container_of(d, struct lws, adns); + + lws_dll2_remove(d); + if (c && c->results) { + lwsl_debug("%s: q: %p, c: %p, refcount %d -> %d\n", + __func__, q, c, c->refcount, c->refcount + 1); + c->refcount++; + } + lws_set_timeout(w, NO_PENDING_TIMEOUT, 0); + /* + * This may decide to close / delete w + */ + if (w->adns_cb(w, (const char *)&q[1], c ? c->results : NULL, 0, + q->opaque) == NULL) + lwsl_notice("%s: failed\n", __func__); + // lws_close_free_wsi(w, LWS_CLOSE_STATUS_NOSTATUS, + // "adopt udp2 fail"); + + } lws_end_foreach_dll_safe(d, d1); + + if (q->standalone_cb) { + if (c && c->results) { + lwsl_debug("%s: q: %p, c: %p, refcount %d -> %d\n", + __func__, q, c, c->refcount, c->refcount + 1); + c->refcount++; + } + + q->standalone_cb(NULL, (const char *)&q[1], + c ? c->results : NULL, 0, q->opaque); + } + + return 0; +} + +static void +lws_async_dns_sul_cb_retry(struct lws_sorted_usec_list *sul) +{ + lws_adns_q_t *q = lws_container_of(sul, lws_adns_q_t, sul); + + // lwsl_notice("%s\n", __func__); + + lws_callback_on_writable(q->dns->wsi); +} + +static void +lws_async_dns_writeable(struct lws *wsi, lws_adns_q_t *q) +{ + uint8_t pkt[LWS_PRE + DNS_PACKET_LEN], *e = &pkt[sizeof(pkt)], *p, *pl; + int m, n, which; + const char *name; + + // lwsl_notice("%s: %p\n", __func__, q); + + /* + * UDP is not reliable, it can be locally dropped, or dropped + * by any intermediary or the remote peer. So even though we + * will do the write in a moment, we schedule another request + * for rewrite according to the wsi retry policy. + * + * If the result came before, we'll cancel it as part of the + * wsi close. + * + * If we have already reached the end of our concealed retries + * in the policy, just close without another write. + */ + if (lws_dll2_is_detached(&q->sul.list) && + lws_retry_sul_schedule_retry_wsi(wsi, &q->sul, + lws_async_dns_sul_cb_retry, &q->retry)) { + /* we have reached the end of our concealed retries */ + lwsl_notice("%s: failing query\n", __func__); + /* + * our policy is to force reloading the dns server info + * if our connection ever timed out, in case it or the + * routing state changed + */ + + lws_async_dns_drop_server(q->context); + goto qfail; + } + + name = (const char *)&q[1]; + + p = &pkt[LWS_PRE]; + memset(p, 0, DHO_SIZEOF); + +#if defined(LWS_WITH_IPV6) + if (!q->responded) { + /* must pick between ipv6 and ipv4 */ + which = q->sent[0] >= q->sent[1]; + q->sent[which]++; + q->asked = 3; /* want results for 4 & 6 before done */ + } else + which = q->responded & 1; +#else + which = 0; + q->asked = 1; +#endif + + /* we hack b0 of the tid to be 0 = A, 1 = AAAA */ + + lws_ser_wu16be(&p[DHO_TID], +#if defined(LWS_WITH_IPV6) + which ? q->tid | 1 : +#endif + q->tid); + lws_ser_wu16be(&p[DHO_FLAGS], (1 << 8)); + lws_ser_wu16be(&p[DHO_NQUERIES], 1); + + p += DHO_SIZEOF; + + /* start of label-formatted qname */ + + pl = p++; + + do { + if (*name == '.' || !*name) { + *pl = lws_ptr_diff(p, pl + 1); + pl = p; + *p++ = 0; /* also serves as terminal length */ + if (!*name++) + break; + } else + *p++ = *name++; + } while (p + 6 < e); + + if (p + 6 >= e) { + assert(0); + lwsl_err("%s: name too big\n", __func__); + goto qfail; + } + + lws_ser_wu16be(p, which ? LWS_ADNS_RECORD_AAAA : + LWS_ADNS_RECORD_A); + p += 2; + + lws_ser_wu16be(p, 1); /* IN class */ + p += 2; + + assert(p < pkt + sizeof(pkt) - LWS_PRE); + n = lws_ptr_diff(p, pkt + LWS_PRE); + m = lws_write(wsi, pkt + LWS_PRE, n, 0); + if (m != n) { + lwsl_notice("%s: dns write failed %d %d errno %d\n", __func__, + m, n, errno); + goto qfail; + } + +#if defined(LWS_WITH_IPV6) + if (!q->responded && q->sent[0] != q->sent[1]) + lws_callback_on_writable(wsi); +#endif + + /* if we did anything, check one more time */ + lws_callback_on_writable(wsi); + + return; + +qfail: + lwsl_warn("%s: failing query doing NULL completion\n", __func__); + /* + * in ipv6 case, we made a cache entry for the first response but + * evidently the second response didn't come in time, purge the + * incomplete cache entry + */ + if (q->firstcache) + lws_adns_cache_destroy(q->firstcache); + lws_async_dns_complete(q, NULL); + lws_adns_q_destroy(q); +} + +static int +callback_async_dns(struct lws *wsi, enum lws_callback_reasons reason, + void *user, void *in, size_t len) +{ + struct lws_async_dns *dns = &(lws_get_context(wsi)->async_dns); + + switch (reason) { + + /* callbacks related to raw socket descriptor */ + + case LWS_CALLBACK_RAW_ADOPT: + // lwsl_user("LWS_CALLBACK_RAW_ADOPT\n"); + break; + + case LWS_CALLBACK_RAW_CLOSE: + // lwsl_user("LWS_CALLBACK_RAW_CLOSE\n"); + break; + + case LWS_CALLBACK_RAW_RX: + // lwsl_user("LWS_CALLBACK_RAW_RX (%d)\n", (int)len); + // lwsl_hexdump_level(LLL_NOTICE, in, len); + lws_adns_parse_udp(dns, in, len); + break; + + case LWS_CALLBACK_RAW_WRITEABLE: + // lwsl_notice("%s: WRITABLE\n", __func__); + + lws_start_foreach_dll_safe(struct lws_dll2 *, d, d1, + dns->waiting.head) { + lws_adns_q_t *q = lws_container_of(d, lws_adns_q_t, + list); + + if (lws_dll2_is_detached(&q->sul.list) && + (!q->asked || q->responded != q->asked)) + lws_async_dns_writeable(wsi, q); + } lws_end_foreach_dll_safe(d, d1); + break; + + default: + break; + } + + return 0; +} + +struct lws_protocols lws_async_dns_protocol = { + "lws-async-dns", callback_async_dns, 0, 0 +}; + +int +lws_async_dns_init(struct lws_context *context) +{ + lws_async_dns_t *dns = &context->async_dns; + char ads[48]; + int n; + + if (!context->vhost_list) { /* coverity... system vhost always present */ + lwsl_err("%s: no system vhost\n", __func__); + return 1; + } + + memset(&dns->sa46, 0, sizeof(dns->sa46)); + +#if defined(LWS_WITH_SYS_DHCP_CLIENT) + if (lws_dhcpc_status(context, &dns->sa46)) + goto ok; +#endif + + n = lws_plat_asyncdns_init(context, &dns->sa46); + if (n < 0) { + lwsl_warn("%s: no valid dns server, retry\n", __func__); + + return 1; + } + + if (n != LADNS_CONF_SERVER_CHANGED) + return 0; + +#if defined(LWS_WITH_SYS_DHCP_CLIENT) +ok: +#endif + dns->sa46.sa4.sin_port = htons(53); + lws_write_numeric_address((uint8_t *)&dns->sa46.sa4.sin_addr.s_addr, 4, + ads, sizeof(ads)); + + context->async_dns.wsi = lws_create_adopt_udp(context->vhost_list, ads, + 53, 0, lws_async_dns_protocol.name, NULL, + NULL, NULL, &retry_policy); + if (!dns->wsi) { + lwsl_err("%s: foreign socket adoption failed\n", __func__); + return 1; + } + + dns->dns_server_set = 1; + + return 0; +} + +lws_adns_cache_t * +lws_adns_get_cache(lws_async_dns_t *dns, const char *name) +{ + lws_adns_cache_t *c; + const char *cn; + + lws_start_foreach_dll_safe(struct lws_dll2 *, d, d1, + lws_dll2_get_head(&dns->cached)) { + c = lws_container_of(d, lws_adns_cache_t, list); + cn = (const char *)&c[1]; + + if (name && !c->incomplete && !strcasecmp(name, cn)) { + /* Keep sorted by LRU: move to the head */ + lws_dll2_remove(&c->list); + lws_dll2_add_head(&c->list, &dns->cached); + + return c; + } + } lws_end_foreach_dll_safe(d, d1); + + return NULL; +} + +void +lws_adns_cache_destroy(lws_adns_cache_t *c) +{ + lws_dll2_remove(&c->sul.list); + lws_dll2_remove(&c->list); + if (c->chain) + lws_free(c->chain); + lws_free(c); +} + +static int +cache_clean(struct lws_dll2 *d, void *user) +{ + lws_adns_cache_destroy(lws_container_of(d, lws_adns_cache_t, list)); + + return 0; +} + +void +sul_cb_expire(struct lws_sorted_usec_list *sul) +{ + lws_adns_cache_t *c = lws_container_of(sul, lws_adns_cache_t, sul); + + lws_adns_cache_destroy(c); +} + +void +lws_async_dns_freeaddrinfo(const struct addrinfo **pai) +{ + lws_adns_cache_t *c; + + if (!*pai) + return; + + /* + * First query may have been empty... if second has something, we + * fixed up the first result to point to second... but it means + * looking backwards from ai, which is c->result, which is the second + * packet's results, doesn't get us to the firstcache pointer. + * + * Adjust c to the firstcache in this case. + */ + + c = &((lws_adns_cache_t *)(*pai))[-1]; + if (c->firstcache) + c = c->firstcache; + + lwsl_debug("%s: c %p, %s, refcount %d -> %d\n", __func__, c, + (c->results && c->results->ai_canonname) ? + c->results->ai_canonname : "none", + c->refcount, c->refcount - 1); + + assert(c->refcount > 0); + c->refcount--; + *pai = NULL; +} + +void +lws_async_dns_trim_cache(lws_async_dns_t *dns) +{ + lws_adns_cache_t *c1; + + if (dns->cached.count + 1< MAX_CACHE_ENTRIES) + return; + + c1 = lws_container_of(lws_dll2_get_tail(&dns->cached), + lws_adns_cache_t, list); + if (c1->refcount) + lwsl_notice("%s: wsi %p: refcount %d on purge\n", + __func__, c1, c1->refcount); + else + lws_adns_cache_destroy(c1); +} + + +static int +clean(struct lws_dll2 *d, void *user) +{ + lws_adns_q_destroy(lws_container_of(d, lws_adns_q_t, list)); + + return 0; +} + +void +lws_async_dns_deinit(lws_async_dns_t *dns) +{ + lws_dll2_foreach_safe(&dns->waiting, NULL, clean); + lws_dll2_foreach_safe(&dns->cached, NULL, cache_clean); +} + + +static int +cancel(struct lws_dll2 *d, void *user) +{ + lws_adns_q_t *q = lws_container_of(d, lws_adns_q_t, list); + + lws_start_foreach_dll_safe(struct lws_dll2 *, d3, d4, + lws_dll2_get_head(&q->wsi_adns)) { + struct lws *w = lws_container_of(d3, struct lws, adns); + + if (user == w) { + lws_dll2_remove(d3); + if (!q->wsi_adns.count) + lws_adns_q_destroy(q); + return 1; + } + } lws_end_foreach_dll_safe(d3, d4); + + return 0; +} + +void +lws_async_dns_cancel(struct lws *wsi) +{ + lws_async_dns_t *dns = &wsi->a.context->async_dns; + + lws_dll2_foreach_safe(&dns->waiting, wsi, cancel); +} + + +static int +check_tid(struct lws_dll2 *d, void *user) +{ + lws_adns_q_t *q = lws_container_of(d, lws_adns_q_t, list); + + return q->tid == (uint16_t)(intptr_t)user; +} + +int +lws_async_dns_get_new_tid(struct lws_context *context, lws_adns_q_t *q) +{ + lws_async_dns_t *dns = &context->async_dns; + int budget = 10; + + /* + * Make the TID unpredictable, but must be unique amongst ongoing ones + */ + do { + uint16_t tid; + + if (lws_get_random(context, &tid, 2) != 2) + return -1; + + if (lws_dll2_foreach_safe(&dns->waiting, + (void *)(intptr_t)tid, check_tid)) + continue; + + q->tid = tid; + + return 0; + + } while (budget--); + + lwsl_err("%s: unable to get unique tid\n", __func__); + + return -1; +} + +struct temp_q { + lws_adns_q_t tq; + char name[48]; +}; + +lws_async_dns_retcode_t +lws_async_dns_query(struct lws_context *context, int tsi, const char *name, + adns_query_type_t qtype, lws_async_dns_cb_t cb, + struct lws *wsi, void *opaque) +{ + lws_async_dns_t *dns = &context->async_dns; + size_t nlen = strlen(name); + lws_sockaddr46 *sa46; + lws_adns_cache_t *c; + struct addrinfo *ai; + struct temp_q tmq; + lws_adns_q_t *q; + uint8_t ads[16]; + char *p; + int m; + +#if !defined(LWS_WITH_IPV6) + if (qtype == LWS_ADNS_RECORD_AAAA) { + lwsl_err("%s: ipv6 not enabled\n", __func__); + goto failed; + } +#endif + + if (nlen >= DNS_MAX - 1) + goto failed; + + /* + * we magically know 'localhost' and 'localhost6' if IPv6, this is a + * sort of canned /etc/hosts + */ + + if (!strcmp(name, "localhost")) + name = "127.0.0.1"; + +#if defined(LWS_WITH_IPV6) + if (!strcmp(name, "localhost6")) + name = "::1"; +#endif + + if (wsi) { + if (!lws_dll2_is_detached(&wsi->adns)) { + lwsl_err("%s: wsi %p already bound to query %p\n", + __func__, wsi, wsi->adns.owner); + goto failed; + } + wsi->adns_cb = cb; + } + + /* there's a done, cached query we can just reuse? */ + + c = lws_adns_get_cache(dns, name); + if (c) { + lwsl_err("%s: using cached, c->results %p\n", __func__, c->results); + m = c->results ? LADNS_RET_FOUND : LADNS_RET_FAILED; + if (c->results) + c->refcount++; + if (cb(wsi, name, c->results, m, opaque) == NULL) + return LADNS_RET_FAILED_WSI_CLOSED; + + return m; + } + + /* + * It's a 1.2.3.4 type IP address already? We don't need a dns + * server set up to be able to create an addrinfo result for that. + * + * Create it as a cached object so it follows the refcount lifecycle + * of any other result + */ + + m = lws_parse_numeric_address(name, ads, sizeof(ads)); + if (m == 4 +#if defined(LWS_WITH_IPV6) + || m == 16 +#endif + ) { + lws_async_dns_trim_cache(dns); + + c = lws_zalloc(sizeof(lws_adns_cache_t) + + sizeof(struct addrinfo) + + sizeof(lws_sockaddr46) + nlen + 1, "adns-numip"); + if (!c) + goto failed; + + ai = (struct addrinfo *)&c[1]; + sa46 = (lws_sockaddr46 *)&ai[1]; + + ai->ai_socktype = SOCK_STREAM; + memcpy(&sa46[1], name, nlen + 1); + ai->ai_canonname = (char *)&sa46[1]; + + c->results = ai; + memset(&tmq.tq, 0, sizeof(tmq.tq)); + tmq.tq.opaque = opaque; + if (wsi) { + wsi->adns_cb = cb; + lws_dll2_add_head(&wsi->adns, &tmq.tq.wsi_adns); + } else + tmq.tq.standalone_cb = cb; + lws_strncpy(tmq.name, name, sizeof(tmq.name)); + + lws_dll2_add_head(&c->list, &dns->cached); + lws_sul_schedule(context, 0, &c->sul, sul_cb_expire, + lws_now_usecs() + (3600ll * LWS_US_PER_SEC)); + } + + if (m == 4) { + ai->ai_family = sa46->sa4.sin_family = AF_INET; + ai->ai_addrlen = sizeof(sa46->sa4); + ai->ai_addr = (struct sockaddr *)&sa46->sa4; + memcpy(&sa46->sa4.sin_addr, ads, m); + + lws_async_dns_complete(&tmq.tq, c); + + return LADNS_RET_FOUND; + } + +#if defined(LWS_WITH_IPV6) + if (m == 16) { + ai->ai_family = sa46->sa6.sin6_family = AF_INET6; + ai->ai_addrlen = sizeof(sa46->sa6); + ai->ai_addr = (struct sockaddr *)&sa46->sa6; + memcpy(&sa46->sa6.sin6_addr, ads, m); + + lws_async_dns_complete(&tmq.tq, c); + + return LADNS_RET_FOUND; + } +#endif + + /* + * to try anything else we need a remote server configured... + */ + + if (!context->async_dns.dns_server_set && + lws_async_dns_init(context)) { + lwsl_notice("%s: init failed\n", __func__); + goto failed; + } + + /* there's an ongoing query we can share the result of */ + + q = lws_adns_get_query(dns, qtype, &dns->waiting, 0, name); + if (q) { + lwsl_debug("%s: dns piggybacking: %d:%s\n", __func__, + qtype, name); + if (wsi) + lws_dll2_add_head(&wsi->adns, &q->wsi_adns); + + return LADNS_RET_CONTINUING; + } + + /* + * Allocate new query / queries... this is a bit complicated because + * multiple queries in one packet are not supported peoperly in DNS + * itself, and there's no reliable other way to get both ipv6 and ipv4 + * (AAAA and A) responses in one hit. + * + * If we don't support ipv6, it's simple, we just ask for A and that's + * it. But if we do support ipv6, we need to ask twice, once for A + * and in a separate query, again for AAAA. + * + * For ipv6, A / ipv4 is routable over ipv6. So we always ask for A + * first and then if ipv6, AAAA separately. + * + * Allocate for DNS_MAX, because we may recurse and alter what we're + * looking for. + * + * 0 sizeof(*q) sizeof(*q) + DNS_MAX + * [lws_adns_q_t][ name (DNS_MAX reserved) ] [ name \0 ] + */ + + q = (lws_adns_q_t *)lws_malloc(sizeof(*q) + DNS_MAX + nlen + 1, + __func__); + if (!q) + goto failed; + memset(q, 0, sizeof(*q)); + + if (wsi) + lws_dll2_add_head(&wsi->adns, &q->wsi_adns); + + q->qtype = (uint16_t)qtype; + + if (lws_async_dns_get_new_tid(context, q)) + goto failed; + + q->tid &= 0xfffe; + q->context = context; + q->tsi = tsi; + q->opaque = opaque; + q->dns = dns; + + if (!wsi) + q->standalone_cb = cb; + + /* schedule a retry according to the retry policy on the wsi */ + if (lws_retry_sul_schedule_retry_wsi(dns->wsi, &q->sul, + lws_async_dns_sul_cb_retry, &q->retry)) + goto failed; + + /* + * We may rewrite the copy at +sizeof(*q) for CNAME recursion. Keep + * a second copy at + sizeof(*q) + DNS_MAX so we can create the cache + * entry for the original name, not the last CNAME we met. + */ + + p = (char *)&q[1]; + while (nlen--) { + *p++ = tolower(*name++); + p[DNS_MAX - 1] = p[-1]; + } + *p = '\0'; + p[DNS_MAX] = '\0'; + + lws_callback_on_writable(dns->wsi); + + lws_dll2_add_head(&q->list, &dns->waiting); + + lwsl_debug("%s: created new query\n", __func__); + + return LADNS_RET_CONTINUING; + +failed: + cb(wsi, NULL, NULL, LADNS_RET_FAILED, opaque); + + return LADNS_RET_FAILED; +} diff -Nru libwebsockets-3.2.1/lib/system/async-dns/async-dns-parse.c libwebsockets-4.1.6/lib/system/async-dns/async-dns-parse.c --- libwebsockets-3.2.1/lib/system/async-dns/async-dns-parse.c 1970-01-01 00:00:00.000000000 +0000 +++ libwebsockets-4.1.6/lib/system/async-dns/async-dns-parse.c 2020-12-01 17:40:26.000000000 +0000 @@ -0,0 +1,700 @@ +/* + * libwebsockets - small server side websockets and web server implementation + * + * Copyright (C) 2010 - 2019 Andy Green + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to + * deal in the Software without restriction, including without limitation the + * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or + * sell copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS + * IN THE SOFTWARE. + */ + +#include "private-lib-core.h" +#include "private-lib-async-dns.h" + + +/* updates *dest, returns chars used from ls directly, else -1 for fail */ + +static int +lws_adns_parse_label(const uint8_t *pkt, int len, const uint8_t *ls, int budget, + char **dest, int dl) +{ + const uint8_t *e = pkt + len, *ols = ls; + char pointer = 0, first = 1; + uint8_t ll; + int n; + + if (budget < 1) + return 0; + + /* caller must catch end of labels */ + assert(*ls); + +again1: + if (ls >= e) + return -1; + + if (((*ls) & 0xc0) == 0xc0) { + if (budget < 2) + return -1; + /* pointer into message pkt to name to actually use */ + n = lws_ser_ru16be(ls) & 0x3fff; + if (n >= len) { + lwsl_notice("%s: illegal name pointer\n", __func__); + + return -1; + } + + /* dereference the label pointer */ + ls = pkt + n; + + /* are we being fuzzed or messed with? */ + if (((*ls) & 0xc0) == 0xc0) { + /* ... pointer to pointer is unreasonable */ + lwsl_notice("%s: label ptr to ptr invalid\n", __func__); + + return -1; + } + pointer = 1; + } + + if (ls >= e) + return -1; + + ll = *ls++; + if (ls + ll + 1 > e) { + lwsl_notice("%s: label len invalid, %d vs %d\n", __func__, + lws_ptr_diff((ls + ll + 1), pkt), lws_ptr_diff(e, pkt)); + + return -1; + } + if (ll > budget) { + lwsl_notice("%s: label too long %d vs %d\n", __func__, ll, budget); + + return -1; + } + + if (ll + 2 > dl) { + lwsl_notice("%s: qname too large\n", __func__); + + return -1; + } + + /* copy the label content into place */ + + memcpy(*dest, ls, ll); + (*dest)[ll] = '.'; + (*dest)[ll + 1] = '\0'; + *dest += ll + 1; + ls += ll; + + if (pointer) { + if (*ls) + goto again1; + + /* + * special fun rule... if whole qname was a pointer label, + * it has no 00 terminator afterwards + */ + if (first) + return 2; /* we just took the 16-bit pointer */ + + return 3; + } + + first = 0; + + if (*ls) + goto again1; + + ls++; + + return lws_ptr_diff(ls, ols); +} + +typedef int (*lws_async_dns_find_t)(const char *name, void *opaque, + uint32_t ttl, adns_query_type_t type, + const uint8_t *payload); + +/* locally query the response packet */ + +struct label_stack { + char name[DNS_MAX]; + int enl; + const uint8_t *p; +}; + +/* + * Walk the response packet, calling back to the user-provided callback for each + * A (and AAAA if LWS_IPV6=1) record with a matching name found in there. + * + * Able to recurse using an explicit non-CPU stack to resolve CNAME usages + * + * Return -1: unexpectedly failed + * 0: found + * 1: didn't find anything matching + */ + +static int +lws_adns_iterate(lws_adns_q_t *q, const uint8_t *pkt, int len, + const char *expname, lws_async_dns_find_t cb, void *opaque) +{ + const uint8_t *e = pkt + len, *p, *pay; + struct label_stack stack[4]; + int n = 0, stp = 0, ansc, m; + uint16_t rrtype, rrpaylen; + char *sp, inq; + uint32_t ttl; + + lws_strncpy(stack[0].name, expname, sizeof(stack[0].name)); + stack[0].enl = (int)strlen(expname); + +start: + ansc = lws_ser_ru16be(pkt + DHO_NANSWERS); + p = pkt + DHO_SIZEOF; + inq = 1; + + /* + * The response also includes the query... and we have to parse it + * so we can understand we reached the response... there's a QNAME + * made up of labels and then 2 x 16-bit fields, for query type and + * query class + */ + + + while (p + 14 < e && (inq || ansc)) { + + if (!inq && !stp) + ansc--; + + /* + * First is the name the query applies to... two main + * formats can appear here, one is a pointer to + * elsewhere in the message, the other separately + * provides len / data for each dotted "label", so for + * "warmcat.com" warmcat and com are given each with a + * prepended length byte. Any of those may be a pointer + * to somewhere else in the packet :-/ + * + * Paranoia is appropriate since the name length must be + * parsed out before the rest of the RR can be used and + * we can be attacked with absolutely any crafted + * content easily via UDP. + * + * So parse the name and additionally confirm it matches + * what the query the TID belongs to actually asked for. + */ + + sp = stack[0].name; + + /* while we have more labels */ + + n = lws_adns_parse_label(pkt, len, p, len, &sp, + sizeof(stack[0].name) - + lws_ptr_diff(sp, stack[0].name)); + /* includes case name won't fit */ + if (n < 0) + return -1; + + p += n; + + if (p + (inq ? 5 : 14) > e) + return -1; + + /* + * p is now just after the decoded RR name, pointing at: type + * + * We sent class = 1 = IN query... response must match + */ + + if (lws_ser_ru16be(&p[2]) != 1) { + lwsl_err("%s: non-IN response 0x%x\n", __func__, + lws_ser_ru16be(&p[2])); + + return -1; + } + + if (inq) { + lwsl_debug("%s: reached end of inq\n", __func__); + inq = 0; + p += 4; + continue; + } + + /* carefully validate the claimed RR payload length */ + + rrpaylen = lws_ser_ru16be(&p[8]); + if (p + 10 + rrpaylen > e) { /* it may be == e */ + lwsl_notice("%s: invalid RR data length\n", __func__); + + return -1; + } + + ttl = lws_ser_ru32be(&p[4]); + rrtype = lws_ser_ru16be(&p[0]); + p += 10; /* point to the payload */ + pay = p; + + /* + * Compare the RR names, allowing for the decoded labelname + * to have an extra '.' at the end. + */ + + n = lws_ptr_diff(sp, stack[0].name); + if (stack[0].name[n - 1] == '.') + n--; + + m = stack[stp].enl; + if (stack[stp].name[m - 1] == '.') + m--; + + if (n < 1 || n != m || + strncmp(stack[0].name, stack[stp].name, n)) { + lwsl_notice("%s: skipping %s vs %s\n", __func__, + stack[0].name, stack[stp].name); + goto skip; + } + + /* + * It's something we could be interested in... + * + * We can skip RRs we don't understand. But we need to deal + * with at least these and their payloads: + * + * A: 4: ipv4 address + * AAAA: 16: ipv6 address (if asked for AAAA) + * CNAME: ?: labelized name + * + * If we hit a CNAME we need to try to dereference it with + * stuff that is in the same response packet and judge it + * from that, without losing our place here. CNAMEs may + * point to CNAMEs to whatever depth we're willing to handle. + */ + + switch (rrtype) { + + case LWS_ADNS_RECORD_AAAA: + if (rrpaylen != 16) { + lwsl_err("%s: unexpected rrpaylen\n", __func__); + return -1; + } +#if defined(LWS_WITH_IPV6) + goto do_cb; +#else + break; +#endif + + case LWS_ADNS_RECORD_A: + if (rrpaylen != 4) { + lwsl_err("%s: unexpected rrpaylen4\n", __func__); + + return -1; + } +#if defined(LWS_WITH_IPV6) +do_cb: +#endif + cb(stack[0].name, opaque, ttl, rrtype, p); + break; + + case LWS_ADNS_RECORD_CNAME: + /* + * The name the CNAME refers to MAY itself be + * included elsewhere in the response packet. + * + * So switch tack, stack where to resume from and + * search for the decoded CNAME label name definition + * instead. + * + * First decode the CNAME label payload into the next + * stack level buffer for it. + */ + + if (++stp == (int)LWS_ARRAY_SIZE(stack)) { + lwsl_notice("%s: CNAMEs too deep\n", __func__); + + return -1; + } + sp = stack[stp].name; + /* get the cname alias */ + n = lws_adns_parse_label(pkt, len, p, rrpaylen, &sp, + sizeof(stack[stp].name) - + lws_ptr_diff(sp, stack[stp].name)); + /* includes case name won't fit */ + if (n < 0) + return -1; + + p += n; + + if (p + 14 > e) + return -1; +#if 0 + /* it should have exactly reached rrpaylen if only one + * CNAME, else somewhere in the middle */ + + if (p != pay + rrpaylen) { + lwsl_err("%s: cname name bad len %d\n", __func__, rrpaylen); + + return -1; + } +#endif + lwsl_notice("%s: recursing looking for %s\n", __func__, stack[stp].name); + + lwsl_info("%s: recursing looking for %s\n", __func__, + stack[stp].name); + + stack[stp].enl = lws_ptr_diff(sp, stack[stp].name); + /* when we unstack, resume from here */ + stack[stp].p = pay + rrpaylen; + goto start; + + default: + break; + } + +skip: + p += rrpaylen; + } + + if (!stp) + return 1; /* we didn't find anything, but we didn't error */ + + lwsl_info("%s: '%s' -> CNAME '%s' resolution not provided, recursing\n", + __func__, ((const char *)&q[1]) + DNS_MAX, + stack[stp].name); + + /* + * This implies there wasn't any usable definition for the + * CNAME in the end, eg, only AAAA when we needed an A. + * + * It's also legit if the DNS just returns the CNAME, and that server + * did not directly know the next step in resolution of the CNAME, so + * instead of putting the resolution elsewhere in the response, has + * told us just the CNAME and left it to us to find out its resolution + * separately. + * + * Reset this request to be for the CNAME, and restart the request + * action with a new tid. + */ + + if (lws_async_dns_get_new_tid(q->context, q)) + return -1; + + q->tid &= 0xfffe; + q->asked = q->responded = 0; +#if defined(LWS_WITH_IPV6) + q->sent[1] = 0; +#endif + q->sent[0] = 0; + q->recursion++; + if (q->recursion == DNS_RECURSION_LIMIT) { + lwsl_err("%s: recursion overflow\n", __func__); + + return -1; + } + + if (q->firstcache) + lws_adns_cache_destroy(q->firstcache); + q->firstcache = NULL; + + /* overwrite the query name with the CNAME */ + + n = 0; + { + char *cp = (char *)&q[1]; + + while (stack[stp].name[n]) + *cp++ = tolower(stack[stp].name[n++]); + /* trim the following . if any */ + if (n && cp[-1] == '.') + cp--; + *cp = '\0'; + } + + lws_callback_on_writable(q->dns->wsi); + + return 2; +} + +int +lws_async_dns_estimate(const char *name, void *opaque, uint32_t ttl, + adns_query_type_t type, const uint8_t *payload) +{ + size_t *est = (size_t *)opaque, my; + + my = sizeof(struct addrinfo); + if (type == LWS_ADNS_RECORD_AAAA) + my += sizeof(struct sockaddr_in6); + else + my += sizeof(struct sockaddr_in); + + *est += my; + + return 0; +} + +struct adstore { + const char *name; + struct addrinfo *pos; + struct addrinfo *prev; + int ctr; + uint32_t smallest_ttl; + uint8_t flags; +}; + +/* + * Callback for each A or AAAA record, creating getaddrinfo-compatible results + * into the preallocated exact-sized storage. + */ +int +lws_async_dns_store(const char *name, void *opaque, uint32_t ttl, + adns_query_type_t type, const uint8_t *payload) +{ + struct adstore *adst = (struct adstore *)opaque; +#if defined(_DEBUG) + char buf[48]; +#endif + size_t i; + + if (ttl < adst->smallest_ttl || !adst->ctr) + adst->smallest_ttl = ttl; + + if (adst->prev) + adst->prev->ai_next = adst->pos; + adst->prev = adst->pos; + + adst->pos->ai_flags = 0; + adst->pos->ai_family = type == LWS_ADNS_RECORD_AAAA ? + AF_INET6 : AF_INET; + adst->pos->ai_socktype = SOCK_STREAM; + adst->pos->ai_protocol = IPPROTO_UDP; /* no meaning */ + adst->pos->ai_addrlen = type == LWS_ADNS_RECORD_AAAA ? + sizeof(struct sockaddr_in6) : + sizeof(struct sockaddr_in); + adst->pos->ai_canonname = (char *)adst->name; + adst->pos->ai_addr = (struct sockaddr *)&adst->pos[1]; + adst->pos->ai_next = NULL; + +#if defined(LWS_WITH_IPV6) + if (type == LWS_ADNS_RECORD_AAAA) { + struct sockaddr_in6 *in6 = (struct sockaddr_in6 *)&adst->pos[1]; + + i = sizeof(*in6); + memset(in6, 0, i); + in6->sin6_family = adst->pos->ai_family; + memcpy(in6->sin6_addr.s6_addr, payload, 16); + adst->flags |= 2; + } else +#endif + { + struct sockaddr_in *in = (struct sockaddr_in *)&adst->pos[1]; + + i = sizeof(*in); + memset(in, 0, i); + in->sin_family = adst->pos->ai_family; + memcpy(&in->sin_addr.s_addr, payload, 4); + adst->flags |= 1; + } + + adst->pos = (struct addrinfo *)((uint8_t *)adst->pos + + sizeof(struct addrinfo) + i); + +#if defined(_DEBUG) + if (lws_write_numeric_address(payload, + type == LWS_ADNS_RECORD_AAAA ? 16 : 4, + buf, sizeof(buf)) > 0) + lwsl_info("%s: %d: %s: %s\n", __func__, adst->ctr, + adst->name, buf); +#endif + adst->ctr++; + + return 0; +} + +/* + * We want to parse out all A or AAAA records + */ + +void +lws_adns_parse_udp(lws_async_dns_t *dns, const uint8_t *pkt, size_t len) +{ + const char *nm, *nmcname; + lws_adns_cache_t *c; + struct adstore adst; + lws_adns_q_t *q; + int n, ncname; + size_t est; + + // lwsl_hexdump_notice(pkt, len); + + /* we have to at least have the header */ + + if (len < DHO_SIZEOF) + return; + + /* we asked with one query, so anything else is bogus */ + + if (lws_ser_ru16be(pkt + DHO_NQUERIES) != 1) + return; + + /* match both A and AAAA queries if any */ + + q = lws_adns_get_query(dns, 0, &dns->waiting, + lws_ser_ru16be(pkt + DHO_TID), NULL); + if (!q) { + lwsl_notice("%s: dropping unknown query tid 0x%x\n", + __func__, lws_ser_ru16be(pkt + DHO_TID)); + + return; + } + + /* we can get dups... drop any that have already happened */ + + n = 1 << (lws_ser_ru16be(pkt + DHO_TID) & 1); + if (q->responded & n) { + lwsl_notice("%s: dup\n", __func__); + goto fail_out; + } + + q->responded |= n; + + /* we want to confirm the results against what we last requested... */ + + nmcname = ((const char *)&q[1]); + + /* + * First walk the packet figuring out the allocation needed for all + * the results. Produce the following layout at c + * + * lws_adns_cache_t: new cache object + * [struct addrinfo + struct sockaddr_in or _in6]: for each A or AAAA + * char []: copy of resolved name + */ + + ncname = (int)strlen(nmcname) + 1; + + est = sizeof(lws_adns_cache_t) + ncname; + if (lws_ser_ru16be(pkt + DHO_NANSWERS)) { + int ir = lws_adns_iterate(q, pkt, (int)len, nmcname, + lws_async_dns_estimate, &est); + if (ir < 0) + goto fail_out; + + if (ir == 2) /* CNAME recursive resolution */ + return; + } + + /* but we want to create the cache entry against the original request */ + + nm = ((const char *)&q[1]) + DNS_MAX; + n = (int)strlen(nm) + 1; + + lwsl_info("%s: create cache entry for %s, %zu\n", __func__, nm, + est - sizeof(lws_adns_cache_t)); + c = lws_malloc(est, "async-dns-entry"); + if (!c) { + lwsl_err("%s: OOM %zu\n", __func__, est); + goto fail_out; + } + memset(c, 0, sizeof(*c)); + + /* place it at end, no need to care about alignment padding */ + adst.name = ((const char *)c) + est - n; + memcpy((char *)adst.name, nm, n); + + /* + * Then walk the packet again, placing the objects we accounted for + * the first time into the result allocation after the cache object + * and copy of the name + */ + + adst.pos = (struct addrinfo *)&c[1]; + adst.prev = NULL; + adst.ctr = 0; + adst.smallest_ttl = 3600; + adst.flags = 0; + + /* + * smallest_ttl applies as it is to empty results (NXDOMAIN), or is + * set to the minimum ttl seen in all the results. + */ + + if (lws_ser_ru16be(pkt + DHO_NANSWERS) && + lws_adns_iterate(q, pkt, (int)len, nmcname, lws_async_dns_store, &adst) < 0) { + lws_free(c); + goto fail_out; + } + + if (lws_ser_ru16be(pkt + DHO_NANSWERS)) { + c->results = (struct addrinfo *)&c[1]; + if (q->last) /* chain the second one on */ + *q->last = c->results; + else /* first one had no results, set first guy's c->results */ + if (q->firstcache) + q->firstcache->results = c->results; + } + + if (adst.prev) /* so we know where to continue the addrinfo list */ + /* can be NULL if first resp empty */ + q->last = &adst.prev->ai_next; + + if (q->firstcache) { /* also need to free chain when we free this guy */ + q->firstcache->chain = c; + c->firstcache = q->firstcache; + } else { + + q->firstcache = c; + c->incomplete = q->responded != q->asked; + + /* + * Only register the first one into the cache... + * Trim the oldest cache entry if necessary + */ + + lws_async_dns_trim_cache(dns); + + /* + * cache the first results object... if a second one comes, + * we won't directly register it but will chain it on to this + * first one and continue to addinfo ai_next linked list from + * the first into the second + */ + + c->flags = adst.flags; + lws_dll2_add_head(&c->list, &dns->cached); + lws_sul_schedule(q->context, 0, &c->sul, sul_cb_expire, + lws_now_usecs() + + (adst.smallest_ttl * LWS_US_PER_SEC)); + } + + if (q->responded != q->asked) + return; + + /* + * Now we captured everything into the new object, return the + * addrinfo results, if any, to all interested wsi, if any... + */ + + c->incomplete = 0; + lws_async_dns_complete(q, q->firstcache); + + /* + * the query is completely finished with + */ + +fail_out: + lws_adns_q_destroy(q); +} + diff -Nru libwebsockets-3.2.1/lib/system/async-dns/private-lib-async-dns.h libwebsockets-4.1.6/lib/system/async-dns/private-lib-async-dns.h --- libwebsockets-3.2.1/lib/system/async-dns/private-lib-async-dns.h 1970-01-01 00:00:00.000000000 +0000 +++ libwebsockets-4.1.6/lib/system/async-dns/private-lib-async-dns.h 2020-12-01 17:40:26.000000000 +0000 @@ -0,0 +1,124 @@ +/* + * libwebsockets - small server side websockets and web server implementation + * + * Copyright (C) 2010 - 2019 Andy Green + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to + * deal in the Software without restriction, including without limitation the + * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or + * sell copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS + * IN THE SOFTWARE. + */ + + +#define DNS_MAX 96 /* Maximum host name */ +#define DNS_RECURSION_LIMIT 3 +#define DNS_PACKET_LEN 1400 /* Buffer size for DNS packet */ +#define MAX_CACHE_ENTRIES 10 /* Dont cache more than that */ +#define DNS_QUERY_TIMEOUT 30 /* Query timeout, seconds */ + +/* + * ... when we completed a query then the query object is destroyed and a + * cache object below is created with the results in getaddrinfo format + * appended to the allocation + */ + +typedef struct lws_adns_cache { + lws_sorted_usec_list_t sul; /* for cache TTL management */ + lws_dll2_t list; + + struct lws_adns_cache *firstcache; + struct lws_adns_cache *chain; + struct addrinfo *results; + uint8_t flags; /* b0 = has ipv4, b1 = has ipv6 */ + char refcount; + char incomplete; + /* name, and then result struct addrinfos overallocated here */ +} lws_adns_cache_t; + +/* + * these objects are used while a query is ongoing... + */ + +typedef struct { + lws_sorted_usec_list_t sul; /* per-query write retry timer */ + lws_dll2_t list; + + lws_dll2_owner_t wsi_adns; + lws_async_dns_cb_t standalone_cb; /* if not associated to wsi */ + struct lws_context *context; + void *opaque; + struct addrinfo **last; + lws_async_dns_t *dns; + + lws_adns_cache_t *firstcache; + + lws_async_dns_retcode_t ret; + uint16_t tid; + uint16_t qtype; + uint16_t retry; + uint8_t tsi; + +#if defined(LWS_WITH_IPV6) + uint8_t sent[2]; +#else + uint8_t sent[1]; +#endif + uint8_t asked; + uint8_t responded; + + uint8_t recursion; + + /* name overallocated here */ +} lws_adns_q_t; + +enum { + DHO_TID, + DHO_FLAGS = 2, + DHO_NQUERIES = 4, + DHO_NANSWERS = 6, + DHO_NAUTH = 8, + DHO_NOTHER = 10, + + DHO_SIZEOF = 12 /* last */ +}; + +void +lws_adns_q_destroy(lws_adns_q_t *q); + +void +sul_cb_expire(struct lws_sorted_usec_list *sul); + +void +lws_adns_cache_destroy(lws_adns_cache_t *c); + +int +lws_async_dns_complete(lws_adns_q_t *q, lws_adns_cache_t *c); + +lws_adns_cache_t * +lws_adns_get_cache(lws_async_dns_t *dns, const char *name); + +void +lws_adns_parse_udp(lws_async_dns_t *dns, const uint8_t *pkt, size_t len); + +lws_adns_q_t * +lws_adns_get_query(lws_async_dns_t *dns, adns_query_type_t qtype, + lws_dll2_owner_t *owner, uint16_t tid, const char *name); + +void +lws_async_dns_trim_cache(lws_async_dns_t *dns); + +int +lws_async_dns_get_new_tid(struct lws_context *context, lws_adns_q_t *q); diff -Nru libwebsockets-3.2.1/lib/system/CMakeLists.txt libwebsockets-4.1.6/lib/system/CMakeLists.txt --- libwebsockets-3.2.1/lib/system/CMakeLists.txt 1970-01-01 00:00:00.000000000 +0000 +++ libwebsockets-4.1.6/lib/system/CMakeLists.txt 2020-12-01 17:40:26.000000000 +0000 @@ -0,0 +1,65 @@ +# +# libwebsockets - small server side websockets and web server implementation +# +# Copyright (C) 2010 - 2020 Andy Green +# +# Permission is hereby granted, free of charge, to any person obtaining a copy +# of this software and associated documentation files (the "Software"), to +# deal in the Software without restriction, including without limitation the +# rights to use, copy, modify, merge, publish, distribute, sublicense, and/or +# sell copies of the Software, and to permit persons to whom the Software is +# furnished to do so, subject to the following conditions: +# +# The above copyright notice and this permission notice shall be included in +# all copies or substantial portions of the Software. +# +# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING +# FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS +# IN THE SOFTWARE. +# +# The strategy is to only export to PARENT_SCOPE +# +# - changes to LIB_LIST +# - changes to SOURCES +# - includes via include_directories +# +# and keep everything else private + +include_directories(./async-dns) + +list(APPEND SOURCES + system/system.c) + +if (LWS_WITH_NETWORK) + + if (LWS_WITH_SYS_ASYNC_DNS) + list(APPEND SOURCES + system/async-dns/async-dns.c + system/async-dns/async-dns-parse.c) + endif() + + if (LWS_WITH_SYS_NTPCLIENT) + list(APPEND SOURCES + system/ntpclient/ntpclient.c) + endif() + + if (LWS_WITH_SYS_DHCP_CLIENT) + list(APPEND SOURCES + system/dhcpclient/dhcpclient.c) + endif() + + if (LWS_WITH_SYS_SMD) + add_subdir_include_dirs(smd) + endif() + +endif() + +# +# Keep explicit parent scope exports at end +# + +exports_to_parent_scope() diff -Nru libwebsockets-3.2.1/lib/system/dhcpclient/dhcpclient.c libwebsockets-4.1.6/lib/system/dhcpclient/dhcpclient.c --- libwebsockets-3.2.1/lib/system/dhcpclient/dhcpclient.c 1970-01-01 00:00:00.000000000 +0000 +++ libwebsockets-4.1.6/lib/system/dhcpclient/dhcpclient.c 2020-12-01 17:40:26.000000000 +0000 @@ -0,0 +1,752 @@ + /* + * libwebsockets - small server side websockets and web server implementation + * + * Copyright (C) 2010 - 2020 Andy Green + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to + * deal in the Software without restriction, including without limitation the + * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or + * sell copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS + * IN THE SOFTWARE. + */ + +#include "private-lib-core.h" +#include "private-lib-system-dhcpclient.h" + +typedef enum { + LDHC_INIT_REBOOT, + LDHC_REBOOTING, /* jitterwait */ + LDHC_INIT, /* issue DHCPDISCOVER */ + LDHC_SELECTING, + LDHC_REQUESTING, + LDHC_REBINDING, + LDHC_BOUND, + LDHC_RENEWING +} lws_dhcpc_state_t; + +enum { + LWSDHCPDISCOVER = 1, + LWSDHCPOFFER, + LWSDHCPREQUEST, + LWSDHCPDECLINE, + LWSDHCPACK, + LWSDHCPNACK, + LWSDHCPRELEASE, + + IPV4_PROPOSED = 0, + IPV4_SERVER, + IPV4_ROUTER, + IPV4_SUBNET_MASK, + IPV4_BROADCAST, + IPV4_TIME_SERVER, + IPV4_DNS_SRV_1, + IPV4_DNS_SRV_2, + IPV4_DNS_SRV_3, + IPV4_DNS_SRV_4, + IPV4_LEASE_SECS, + IPV4_REBINDING_SECS, + IPV4_RENEWAL_SECS, + + _IPV4_COUNT, + + LWSDHCPOPT_PAD = 0, + LWSDHCPOPT_SUBNET_MASK = 1, + LWSDHCPOPT_TIME_OFFSET = 2, + LWSDHCPOPT_ROUTER = 3, + LWSDHCPOPT_TIME_SERVER = 4, + LWSDHCPOPT_NAME_SERVER = 5, + LWSDHCPOPT_DNSERVER = 6, + LWSDHCPOPT_LOG_SERVER = 7, + LWSDHCPOPT_COOKIE_SERVER = 8, + LWSDHCPOPT_LPR_SERVER = 9, + LWSDHCPOPT_IMPRESS_SERVER = 10, + LWSDHCPOPT_RESLOC_SERVER = 11, + LWSDHCPOPT_HOST_NAME = 12, + LWSDHCPOPT_BOOTFILE_SIZE = 13, + LWSDHCPOPT_MERIT_DUMP_FILE = 14, + LWSDHCPOPT_DOMAIN_NAME = 15, + LWSDHCPOPT_SWAP_SERVER = 16, + LWSDHCPOPT_ROOT_PATH = 17, + LWSDHCPOPT_EXTENSIONS_PATH = 18, + LWSDHCPOPT_BROADCAST_ADS = 28, + + LWSDHCPOPT_REQUESTED_ADS = 50, + LWSDHCPOPT_LEASE_TIME = 51, + LWSDHCPOPT_OPTION_OVERLOAD = 52, + LWSDHCPOPT_MESSAGE_TYPE = 53, + LWSDHCPOPT_SERVER_ID = 54, + LWSDHCPOPT_PARAM_REQ_LIST = 55, + LWSDHCPOPT_MESSAGE = 56, + LWSDHCPOPT_MAX_DHCP_MSG_SIZE = 57, + LWSDHCPOPT_RENEWAL_TIME = 58, /* AKA T1 */ + LWSDHCPOPT_REBINDING_TIME = 59, /* AKA T2 */ + LWSDHCPOPT_VENDOR_CLASS_ID = 60, + LWSDHCPOPT_CLIENT_ID = 61, + + LWSDHCPOPT_END_OPTIONS = 255 +}; + +typedef struct lws_dhcpc_req { + lws_dll2_t list; + char domain[64]; + struct lws_context *context; + lws_sorted_usec_list_t sul_conn; + lws_sorted_usec_list_t sul_write; + dhcpc_cb_t cb; /* cb on completion / failure */ + void *opaque; /* ignored by lws, give to cb */ + + /* these are separated so we can close the bcast one asynchronously */ + struct lws *wsi_raw; /* for broadcast */ + lws_dhcpc_state_t state; + + uint32_t ipv4[_IPV4_COUNT]; + + uint16_t retry_count_conn; + uint16_t retry_count_write; + uint8_t mac[6]; + uint8_t xid[4]; + uint8_t af; /* address family */ +} lws_dhcpc_req_t; +/* interface name is overallocated here */ + +static const uint32_t botable2[] = { 1500, 1750, 5000 /* in case dog slow */ }; +static const lws_retry_bo_t bo2 = { + botable2, LWS_ARRAY_SIZE(botable2), LWS_RETRY_CONCEAL_ALWAYS, 0, 0, 20 }; + +static const uint8_t rawdisc[] = { + 0x45, 0x00, 0, 0, 0, 0, 0x40, 0, 0x2e, IPPROTO_UDP, + 0, 0, 0, 0, 0, 0, 0xff, 0xff, 0xff, 0xff, + 0, 68, 0, 67, 0, 0, 0, 0 +}; + +#define LDHC_OP_BOOTREQUEST 1 +#define LDHC_OP_BOOTREPLY 2 + +/* + * IPv4... max total 576 + * + * 0 1 2 3 + * 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 + * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ + * | op (1) | htype (1) | hlen (1) | hops (1) | + * +---------------+---------------+---------------+---------------+ + * | +04 xid (4) | + * +-------------------------------+-------------------------------+ + * | +08 secs (2) | +0a flags (2) | + * +-------------------------------+-------------------------------+ + * | +0C ciaddr (4) client IP | + * +---------------------------------------------------------------+ + * | +10 yiaddr (4) your IP | + * +---------------------------------------------------------------+ + * | +14 siaddr (4) server IP | + * +---------------------------------------------------------------+ + * | +18 giaddr (4) gateway IP | + * +---------------------------------------------------------------+ + * | | + * | +1C chaddr (16) client HWADDR | + * +---------------------------------------------------------------+ + * | | + * | +2C sname (64) | + * +---------------------------------------------------------------+ + * | | + * | +6C file (128) | + * +---------------------------------------------------------------+ + * | | + * | +EC options (variable) | + * +---------------------------------------------------------------+ + */ + +#if defined(_DEBUG) +static const char *dhcp_entry_names[] = { + "proposed ip", + "dhcp server", + "router", + "subnet mask", + "broadcast", + "time server", + "dns1", + "dns2", + "dns3", + "dns4", + "lease secs", + "rebinding secs", + "renewal secs", +}; +#endif + +static void +lws_dhcpc_retry_conn(struct lws_sorted_usec_list *sul) +{ + lws_dhcpc_req_t *r = lws_container_of(sul, lws_dhcpc_req_t, sul_conn); + + if (r->wsi_raw || !lws_dll2_is_detached(&r->sul_conn.list)) + return; + + /* create the UDP socket aimed at the server */ + + r->retry_count_write = 0; + r->wsi_raw = lws_create_adopt_udp(r->context->vhost_system, "0.0.0.0", + 68, LWS_CAUDP_PF_PACKET | + LWS_CAUDP_BROADCAST, + "lws-dhcpclient", (const char *)&r[1], + NULL, NULL, &bo2); + lwsl_debug("%s: created wsi_raw: %p\n", __func__, r->wsi_raw); + if (!r->wsi_raw) { + lwsl_err("%s: unable to create udp skt\n", __func__); + + lws_retry_sul_schedule(r->context, 0, &r->sul_conn, &bo2, + lws_dhcpc_retry_conn, + &r->retry_count_conn); + + return; + } + + /* force the network if up */ + lws_plat_if_up((const char *)&r[1], r->wsi_raw->desc.sockfd, 0); + lws_plat_if_up((const char *)&r[1], r->wsi_raw->desc.sockfd, 1); + + r->wsi_raw->user_space = r; + r->wsi_raw->user_space_externally_allocated = 1; + + lws_get_random(r->wsi_raw->a.context, r->xid, 4); +} + +static void +lws_dhcpc_retry_write(struct lws_sorted_usec_list *sul) +{ + lws_dhcpc_req_t *r = lws_container_of(sul, lws_dhcpc_req_t, sul_write); + + lwsl_debug("%s\n", __func__); + + if (r && r->wsi_raw) + lws_callback_on_writable(r->wsi_raw); +} + +static int +lws_dhcpc_prep(uint8_t *start, int bufsiz, lws_dhcpc_req_t *r, int op) +{ + uint8_t *p = start; + + memset(start, 0, bufsiz); + + *p++ = 1; + *p++ = 1; + *p++ = 6; /* sizeof ethernet MAC */ + + memcpy(p + 1, r->xid, 4); + +// p[7] = 0x80; /* broadcast flag */ + + p += 0x1c - 3; + + if (lws_plat_ifname_to_hwaddr(r->wsi_raw->desc.sockfd, + (const char *)&r[1], r->mac, 6) < 0) + return -1; + + memcpy(p, r->mac, 6); + + p += 16 + 64 + 128; + + *p++ = 0x63; /* RFC2132 Magic Cookie indicates start of options */ + *p++ = 0x82; + *p++ = 0x53; + *p++ = 0x63; + + *p++ = LWSDHCPOPT_MESSAGE_TYPE; + *p++ = 1; /* length */ + *p++ = op; + + switch (op) { + case LWSDHCPDISCOVER: + *p++ = LWSDHCPOPT_PARAM_REQ_LIST; + *p++ = 4; /* length */ + *p++ = 1; /* subnet mask */ + *p++ = 3; /* router */ + *p++ = 15; /* domain name */ + *p++ = 6; /* DNServer */ + break; + case LWSDHCPREQUEST: + *p++ = LWSDHCPOPT_REQUESTED_ADS; + *p++ = 4; /* length */ + lws_ser_wu32be(p, r->ipv4[IPV4_PROPOSED]); + p += 4; + *p++ = LWSDHCPOPT_SERVER_ID; + *p++ = 4; /* length */ + lws_ser_wu32be(p, r->ipv4[IPV4_SERVER]); + p += 4; + break; + } + + *p++ = LWSDHCPOPT_END_OPTIONS; + + return lws_ptr_diff(p, start); +} + +static int +callback_dhcpc(struct lws *wsi, enum lws_callback_reasons reason, void *user, + void *in, size_t len) +{ + lws_dhcpc_req_t *r = (lws_dhcpc_req_t *)user; + uint8_t pkt[LWS_PRE + 576], *p = pkt + LWS_PRE, *end; + int n, m; + + switch (reason) { + + case LWS_CALLBACK_RAW_ADOPT: + lwsl_debug("%s: LWS_CALLBACK_RAW_ADOPT\n", __func__); + lws_callback_on_writable(wsi); + break; + + case LWS_CALLBACK_CLIENT_CONNECTION_ERROR: + lwsl_err("%s: udp conn failed\n", __func__); + + /* fallthru */ + case LWS_CALLBACK_RAW_CLOSE: + lwsl_debug("%s: LWS_CALLBACK_RAW_CLOSE\n", __func__); + if (!r) + break; + r->wsi_raw = NULL; + lws_sul_cancel(&r->sul_write); + if (r->state != LDHC_BOUND) { + r->state = LDHC_INIT; + lws_retry_sul_schedule(r->context, 0, &r->sul_conn, + &bo2, lws_dhcpc_retry_conn, + &r->retry_count_conn); + } + break; + + case LWS_CALLBACK_RAW_RX: + + switch (r->state) { + case LDHC_INIT: /* expect DHCPOFFER */ + case LDHC_REQUESTING: /* expect DHCPACK */ + /* + * We should check carefully if we like what we were + * sent... anything can spam us with crafted replies + */ + if (len < 0x100) + break; + + p = (uint8_t *)in + 28; /* skip to UDP payload */ + if (p[0] != 2 || p[1] != 1 || p[2] != 6) + break; + + if (memcmp(&p[4], r->xid, 4)) /* must be our xid */ + break; + + if (memcmp(&p[0x1c], r->mac, 6)) /* our netif mac? */ + break; + + /* the DHCP magic cookie must be in place */ + if (lws_ser_ru32be(&p[0xec]) != 0x63825363) + break; + + r->ipv4[IPV4_PROPOSED] = lws_ser_ru32be(&p[0x10]); + r->ipv4[IPV4_SERVER] = lws_ser_ru32be(&p[0x14]); + + /* it looks legit so far... look at the options */ + + end = (uint8_t *)in + len; + p += 0xec + 4; + while (p < end) { + uint8_t c = *p++; + uint8_t l = 0; + + if (c && c != 0xff) { + /* pad 0 and EOT 0xff have no length */ + l = *p++; + if (!l) { + lwsl_err("%s: zero length\n", + __func__); + goto broken; + } + if (p + l > end) { + /* ...nice try... */ + lwsl_err("%s: bad len\n", + __func__); + goto broken; + } + } + + if (c == 0xff) /* end of options */ + break; + + m = 0; + switch (c) { + case LWSDHCPOPT_SUBNET_MASK: + n = IPV4_SUBNET_MASK; + goto get_ipv4; + + case LWSDHCPOPT_ROUTER: + n = IPV4_ROUTER; + goto get_ipv4; + + case LWSDHCPOPT_TIME_SERVER: + n = IPV4_TIME_SERVER; + goto get_ipv4; + + case LWSDHCPOPT_BROADCAST_ADS: + n = IPV4_BROADCAST; + goto get_ipv4; + + case LWSDHCPOPT_LEASE_TIME: + n = IPV4_LEASE_SECS; + goto get_ipv4; + + case LWSDHCPOPT_RENEWAL_TIME: /* AKA T1 */ + n = IPV4_RENEWAL_SECS; + goto get_ipv4; + + case LWSDHCPOPT_REBINDING_TIME: /* AKA T2 */ + n = IPV4_REBINDING_SECS; + goto get_ipv4; + + case LWSDHCPOPT_DNSERVER: + if (l & 3) + break; + m = IPV4_DNS_SRV_1; + while (l && m - IPV4_DNS_SRV_1 < 4) { + r->ipv4[m++] = lws_ser_ru32be(p); + l -= 4; + p += 4; + } + break; + case LWSDHCPOPT_DOMAIN_NAME: + m = l; + if (m > (int)sizeof(r->domain) - 1) + m = sizeof(r->domain) - 1; + memcpy(r->domain, p, m); + r->domain[m] = '\0'; + break; + + case LWSDHCPOPT_MESSAGE_TYPE: + /* + * Confirm this is the right message + * for the state of the negotiation + */ + if (r->state == LDHC_INIT && + *p != LWSDHCPOFFER) + goto broken; + if (r->state == LDHC_REQUESTING && + *p != LWSDHCPACK) + goto broken; + break; + + default: + break; + } + + p += l; + continue; +get_ipv4: + if (l >= 4) + r->ipv4[n] = lws_ser_ru32be(p); + p += l; + continue; +broken: + memset(r->ipv4, 0, sizeof(r->ipv4)); + break; + } + +#if defined(_DEBUG) + /* dump what we have parsed out */ + + for (n = 0; n < (int)LWS_ARRAY_SIZE(dhcp_entry_names); + n++) + if (n >= IPV4_LEASE_SECS) + lwsl_info("%s: %s: %ds\n", __func__, + dhcp_entry_names[n], + r->ipv4[n]); + else { + m = ntohl(r->ipv4[n]); + lws_write_numeric_address((uint8_t *)&m, + 4,(char *)pkt, 20); + lwsl_info("%s: %s: %s\n", __func__, + dhcp_entry_names[n], + pkt); + } +#endif + + /* + * Having seen everything in there... do we really feel + * we could use it? Everything critical is there? + */ + + if (!r->ipv4[IPV4_PROPOSED] || + !r->ipv4[IPV4_SERVER] || + !r->ipv4[IPV4_ROUTER] || + !r->ipv4[IPV4_SUBNET_MASK] || + !r->ipv4[IPV4_LEASE_SECS] || + !r->ipv4[IPV4_DNS_SRV_1]) { + memset(r->ipv4, 0, sizeof(r->ipv4)); + break; + } + + /* + * Network layout has to be internally consistent... + * DHCP server has to be reachable by broadcast and + * default route has to be on same subnet + */ + + if ((r->ipv4[IPV4_PROPOSED] & r->ipv4[IPV4_SUBNET_MASK]) != + (r->ipv4[IPV4_SERVER] & r->ipv4[IPV4_SUBNET_MASK])) + break; + + if ((r->ipv4[IPV4_PROPOSED] & r->ipv4[IPV4_SUBNET_MASK]) != + (r->ipv4[IPV4_ROUTER] & r->ipv4[IPV4_SUBNET_MASK])) + break; + + if (r->state == LDHC_INIT) { + lwsl_info("%s: moving to REQ\n", __func__); + r->state = LDHC_REQUESTING; + lws_callback_on_writable(r->wsi_raw); + break; + } + + /* + * that's it... commit to the configuration + */ + + /* set up our network interface as offered */ + + if (lws_plat_ifconfig_ip((const char *)&r[1], + r->wsi_raw->desc.sockfd, + (uint8_t *)&r->ipv4[IPV4_PROPOSED], + (uint8_t *)&r->ipv4[IPV4_SUBNET_MASK], + (uint8_t *)&r->ipv4[IPV4_ROUTER])) { + /* + * Problem setting the IP... maybe something + * transient like racing with NetworkManager? + * Since the sul retries are still around it + * will retry + */ + return -1; + } + + /* clear timeouts related to the broadcast socket */ + + lws_sul_cancel(&r->sul_write); + lws_sul_cancel(&r->sul_conn); + + lwsl_notice("%s: DHCP configured %s\n", __func__, + (const char *)&r[1]); + r->state = LDHC_BOUND; + + lws_state_transition_steps(&wsi->a.context->mgr_system, + LWS_SYSTATE_OPERATIONAL); + + r->cb(r->opaque, r->af, + (uint8_t *)&r->ipv4[IPV4_PROPOSED], 4); + + r->wsi_raw = NULL; + return -1; /* close the broadcast wsi */ + default: + break; + } + + break; + + case LWS_CALLBACK_RAW_WRITEABLE: + + if (!r) + break; + + /* + * UDP is not reliable, it can be locally dropped, or dropped + * by any intermediary or the remote peer. So even though we + * will do the write in a moment, we schedule another request + * for rewrite according to the wsi retry policy. + * + * If the result came before, we'll cancel it in the close flow. + * + * If we have already reached the end of our concealed retries + * in the policy, just close without another write. + */ + if (lws_dll2_is_detached(&r->sul_write.list) && + lws_retry_sul_schedule_retry_wsi(wsi, &r->sul_write, + lws_dhcpc_retry_write, + &r->retry_count_write)) { + /* we have reached the end of our concealed retries */ + lwsl_warn("%s: concealed retries done, failing\n", + __func__); + goto retry_conn; + } + + switch (r->state) { + case LDHC_INIT: + n = LWSDHCPDISCOVER; + goto bcast; + + case LDHC_REQUESTING: + n = LWSDHCPREQUEST; + + /* fallthru */ +bcast: + n = lws_dhcpc_prep(p + 28, sizeof(pkt) - LWS_PRE - 28, + r, n); + if (n < 0) { + lwsl_err("%s: failed to prep\n", __func__); + break; + } + + m = lws_plat_rawudp_broadcast(p, rawdisc, + LWS_ARRAY_SIZE(rawdisc), + n + 28, + r->wsi_raw->desc.sockfd, + (const char *)&r[1]); + if (m < 0) + lwsl_err("%s: Failed to write dhcp client req: " + "%d %d, errno %d\n", __func__, + n, m, LWS_ERRNO); + break; + default: + break; + } + + return 0; + +retry_conn: + lws_retry_sul_schedule(wsi->a.context, 0, &r->sul_conn, &bo2, + lws_dhcpc_retry_conn, + &r->retry_count_conn); + + return -1; + + default: + break; + } + + return 0; +} + +struct lws_protocols lws_system_protocol_dhcpc = + { "lws-dhcpclient", callback_dhcpc, 0, 128, }; + +static void +lws_dhcpc_destroy(lws_dhcpc_req_t **pr) +{ + lws_dhcpc_req_t *r = *pr; + + lws_sul_cancel(&r->sul_conn); + lws_sul_cancel(&r->sul_write); + if (r->wsi_raw) + lws_set_timeout(r->wsi_raw, 1, LWS_TO_KILL_ASYNC); + + lws_dll2_remove(&r->list); + + lws_free_set_NULL(r); +} + +int +lws_dhcpc_status(struct lws_context *context, lws_sockaddr46 *sa46) +{ + lws_dhcpc_req_t *r; + + lws_start_foreach_dll(struct lws_dll2 *, p, context->dhcpc_owner.head) { + r = (lws_dhcpc_req_t *)p; + + if (r->state == LDHC_BOUND) { + if (sa46) { + memset(sa46, 0, sizeof(*sa46)); + sa46->sa4.sin_family = AF_INET; + sa46->sa4.sin_addr.s_addr = + r->ipv4[IPV4_DNS_SRV_1]; + } + return 1; + } + + } lws_end_foreach_dll(p); + + return 0; +} + +static lws_dhcpc_req_t * +lws_dhcpc_find(struct lws_context *context, const char *iface, int af) +{ + lws_dhcpc_req_t *r; + + /* see if we are already looking after this af / iface combination */ + + lws_start_foreach_dll(struct lws_dll2 *, p, context->dhcpc_owner.head) { + r = (lws_dhcpc_req_t *)p; + + if (!strcmp((const char *)&r[1], iface) && af == r->af) + return r; /* yes... */ + + } lws_end_foreach_dll(p); + + return NULL; +} + +/* + * Create a persistent dhcp client entry for network interface "iface" and AF + * type "af" + */ + +int +lws_dhcpc_request(struct lws_context *context, const char *iface, int af, + dhcpc_cb_t cb, void *opaque) +{ + lws_dhcpc_req_t *r = lws_dhcpc_find(context, iface, af); + int n; + + /* see if we are already looking after this af / iface combination */ + + if (r) + return 0; + + /* nope... let's create a request object as he asks */ + + n = strlen(iface); + r = lws_zalloc(sizeof(*r) + n + 1, __func__); + if (!r) + return 1; + + memcpy(&r[1], iface, n + 1); + r->af = af; + r->cb = cb; + r->opaque = opaque; + r->context = context; + r->state = LDHC_INIT; + + lws_dll2_add_head(&r->list, &context->dhcpc_owner); /* add him to list */ + + lws_dhcpc_retry_conn(&r->sul_conn); + + return 0; +} + +/* + * Destroy every DHCP client object related to interface "iface" + */ + +static int +_remove_if(struct lws_dll2 *d, void *opaque) +{ + lws_dhcpc_req_t *r = lws_container_of(d, lws_dhcpc_req_t, list); + + if (!opaque || !strcmp((const char *)&r[1], (const char *)opaque)) + lws_dhcpc_destroy(&r); + + return 0; +} + +int +lws_dhcpc_remove(struct lws_context *context, const char *iface) +{ + lws_dll2_foreach_safe(&context->dhcpc_owner, (void *)iface, _remove_if); + + return 0; +} diff -Nru libwebsockets-3.2.1/lib/system/dhcpclient/private-lib-system-dhcpclient.h libwebsockets-4.1.6/lib/system/dhcpclient/private-lib-system-dhcpclient.h --- libwebsockets-3.2.1/lib/system/dhcpclient/private-lib-system-dhcpclient.h 1970-01-01 00:00:00.000000000 +0000 +++ libwebsockets-4.1.6/lib/system/dhcpclient/private-lib-system-dhcpclient.h 2020-12-01 17:40:26.000000000 +0000 @@ -0,0 +1,25 @@ + /* + * libwebsockets - small server side websockets and web server implementation + * + * Copyright (C) 2010 - 2019 Andy Green + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to + * deal in the Software without restriction, including without limitation the + * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or + * sell copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS + * IN THE SOFTWARE. + */ + + diff -Nru libwebsockets-3.2.1/lib/system/ntpclient/ntpclient.c libwebsockets-4.1.6/lib/system/ntpclient/ntpclient.c --- libwebsockets-3.2.1/lib/system/ntpclient/ntpclient.c 1970-01-01 00:00:00.000000000 +0000 +++ libwebsockets-4.1.6/lib/system/ntpclient/ntpclient.c 2020-12-01 17:40:26.000000000 +0000 @@ -0,0 +1,310 @@ + /* + * libwebsockets - small server side websockets and web server implementation + * + * Copyright (C) 2010 - 2020 Andy Green + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to + * deal in the Software without restriction, including without limitation the + * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or + * sell copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS + * IN THE SOFTWARE. + */ + +#include "private-lib-core.h" + +#define LWSNTPC_LI_NONE 0 +#define LWSNTPC_VN_3 3 +#define LWSNTPC_MODE_CLIENT 3 + +struct vhd_ntpc { + struct lws_context *context; + struct lws_vhost *vhost; + const struct lws_protocols *protocol; + lws_sorted_usec_list_t sul_conn; + lws_sorted_usec_list_t sul_write; /* track write retries */ + const char *ntp_server_ads; + struct lws *wsi_udp; + uint16_t retry_count_conn; + uint16_t retry_count_write; + + char set_time; +}; + +/* + * Without a valid ntp we won't be able to do anything requiring client tls. + * + * We have our own outer backoff scheme that just keeps retrying dns lookup + * and the transaction forever. + */ + +static const uint32_t botable[] = + { 300, 500, 650, 800, 800, 900, 1000, 1100, 1500 }; +static const lws_retry_bo_t bo = { + botable, LWS_ARRAY_SIZE(botable), LWS_RETRY_CONCEAL_ALWAYS, 0, 0, 20 }; + +/* + * Once we resolved the remote server (implying we should have network), + * we use a different policy on the wsi itself that gives it a few tries before + * failing the wsi and using to outer retry policy to get dns to a different + * server in the pool and try fresh + */ + +static const uint32_t botable2[] = { 1000, 1250, 5000 /* in case dog slow */ }; +static const lws_retry_bo_t bo2 = { + botable2, LWS_ARRAY_SIZE(botable2), LWS_ARRAY_SIZE(botable2), + /* don't conceal after the last table entry */ 0, 0, 20 }; + +static void +lws_ntpc_retry_conn(struct lws_sorted_usec_list *sul) +{ + struct vhd_ntpc *v = lws_container_of(sul, struct vhd_ntpc, sul_conn); + + lwsl_debug("%s: wsi_udp: %p\n", __func__, v->wsi_udp); + + if (v->wsi_udp || !lws_dll2_is_detached(&v->sul_conn.list)) + return; + + /* create the UDP socket aimed at the server */ + + lwsl_debug("%s: server %s\n", __func__, v->ntp_server_ads); + + v->retry_count_write = 0; + v->wsi_udp = lws_create_adopt_udp(v->vhost, v->ntp_server_ads, 123, 0, + v->protocol->name, NULL, NULL, NULL, + &bo2); + lwsl_debug("%s: created wsi_udp: %p\n", __func__, v->wsi_udp); + if (!v->wsi_udp) { + lwsl_err("%s: unable to create udp skt\n", __func__); + + lws_retry_sul_schedule(v->context, 0, &v->sul_conn, &bo, + lws_ntpc_retry_conn, &v->retry_count_conn); + } +} + +static void +lws_ntpc_retry_write(struct lws_sorted_usec_list *sul) +{ + struct vhd_ntpc *v = lws_container_of(sul, struct vhd_ntpc, sul_write); + + lwsl_debug("%s\n", __func__); + + if (v && v->wsi_udp) + lws_callback_on_writable(v->wsi_udp); +} + +static int +callback_ntpc(struct lws *wsi, enum lws_callback_reasons reason, void *user, + void *in, size_t len) +{ + struct vhd_ntpc *v = (struct vhd_ntpc *) + lws_protocol_vh_priv_get(lws_get_vhost(wsi), + lws_get_protocol(wsi)); + uint8_t pkt[LWS_PRE + 48]; + struct timeval t1; + int64_t delta_us; + uint64_t ns; + + switch (reason) { + + case LWS_CALLBACK_PROTOCOL_INIT: /* per vhost */ + if (v) + break; + + lwsl_debug("%s: LWS_CALLBACK_PROTOCOL_INIT:\n", __func__); + lws_protocol_vh_priv_zalloc(wsi->a.vhost, wsi->a.protocol, + sizeof(*v)); + v = (struct vhd_ntpc *)lws_protocol_vh_priv_get(wsi->a.vhost, + wsi->a.protocol); + v->context = lws_get_context(wsi); + v->vhost = lws_get_vhost(wsi); + v->protocol = lws_get_protocol(wsi); + + v->context->ntpclient_priv = v; + + if (!lws_system_get_ops(wsi->a.context) || + !lws_system_get_ops(wsi->a.context)->set_clock) { +#if !defined(LWS_ESP_PLATFORM) + lwsl_err("%s: set up system ops for set_clock\n", + __func__); +#endif + + // return -1; + } + + /* register our lws_system notifier */ + + v->ntp_server_ads = "pool.ntp.org"; + lws_plat_ntpclient_config(v->context); + lws_system_blob_get_single_ptr(lws_system_get_blob( + v->context, LWS_SYSBLOB_TYPE_NTP_SERVER, 0), + (const uint8_t **)&v->ntp_server_ads); + if (!v->ntp_server_ads || v->ntp_server_ads[0] == '\0') + v->ntp_server_ads = "pool.ntp.org"; + + lwsl_info("%s: using ntp server %s\n", __func__, + v->ntp_server_ads); + break; + + case LWS_CALLBACK_PROTOCOL_DESTROY: /* per vhost */ + if (!v) + break; + if (v->wsi_udp) + lws_set_timeout(v->wsi_udp, 1, LWS_TO_KILL_ASYNC); + v->wsi_udp = NULL; + goto cancel_conn_timer; + + /* callbacks related to raw socket descriptor */ + + case LWS_CALLBACK_RAW_ADOPT: + lwsl_debug("%s: LWS_CALLBACK_RAW_ADOPT\n", __func__); + lws_callback_on_writable(wsi); + break; + + case LWS_CALLBACK_CLIENT_CONNECTION_ERROR: + lwsl_info("%s: CONNECTION_ERROR\n", __func__); + goto do_close; + + case LWS_CALLBACK_RAW_CLOSE: + lwsl_debug("%s: LWS_CALLBACK_RAW_CLOSE\n", __func__); +do_close: + v->wsi_udp = NULL; + + /* cancel any pending write retry */ + lws_sul_cancel(&v->sul_write); + + if (v->set_time) + goto cancel_conn_timer; + + lws_retry_sul_schedule(v->context, 0, &v->sul_conn, &bo, + lws_ntpc_retry_conn, + &v->retry_count_conn); + break; + + case LWS_CALLBACK_RAW_RX: + + if (len != 48) + return 0; /* ignore it */ + + /* + * First get the seconds, corrected for the ntp epoch of 1900 + * vs the unix epoch of 1970. Then shift the seconds up by 1bn + * and add in the ns + */ + + ns = lws_ser_ru32be(((uint8_t *)in) + 40) - 2208988800; + ns = (ns * 1000000000) + lws_ser_ru32be(((uint8_t *)in) + 44); + + /* + * Compute the step + */ + + gettimeofday(&t1, NULL); + + delta_us = (ns / 1000) - + ((t1.tv_sec * LWS_US_PER_SEC) + t1.tv_usec); + + lwsl_notice("%s: Unix time: %llu, step: %lldus\n", __func__, + (unsigned long long)ns / 1000000000, + (long long)delta_us); + +#if defined(LWS_PLAT_FREERTOS) + { + struct timeval t; + + t.tv_sec = (unsigned long long)ns / 1000000000; + t.tv_usec = (ns % 1000000000) / 1000; + + lws_sul_nonmonotonic_adjust(wsi->a.context, delta_us); + + settimeofday(&t, NULL); + } +#endif + if (lws_system_get_ops(wsi->a.context) && + lws_system_get_ops(wsi->a.context)->set_clock) + lws_system_get_ops(wsi->a.context)->set_clock(ns / 1000); + + v->set_time = 1; + lws_state_transition_steps(&wsi->a.context->mgr_system, + LWS_SYSTATE_OPERATIONAL); + + /* close the wsi */ + return -1; + + case LWS_CALLBACK_RAW_WRITEABLE: + + /* + * UDP is not reliable, it can be locally dropped, or dropped + * by any intermediary or the remote peer. So even though we + * will do the write in a moment, we schedule another request + * for rewrite according to the wsi retry policy. + * + * If the result came before, we'll cancel it in the close flow. + * + * If we have already reached the end of our concealed retries + * in the policy, just close without another write. + */ + if (lws_dll2_is_detached(&v->sul_write.list) && + lws_retry_sul_schedule_retry_wsi(wsi, &v->sul_write, + lws_ntpc_retry_write, + &v->retry_count_write)) { + /* we have reached the end of our concealed retries */ + lwsl_warn("%s: concealed retries done, failing\n", __func__); + goto retry_conn; + } + + memset(pkt + LWS_PRE, 0, sizeof(pkt) - LWS_PRE); + pkt[LWS_PRE] = (LWSNTPC_LI_NONE << 6) | + (LWSNTPC_VN_3 << 3) | + (LWSNTPC_MODE_CLIENT << 0); + + if (lws_write(wsi, pkt + LWS_PRE, sizeof(pkt) - LWS_PRE, 0) == + sizeof(pkt) - LWS_PRE) + break; + + lwsl_err("%s: Failed to write ntp client req\n", __func__); + +retry_conn: + lws_retry_sul_schedule(wsi->a.context, 0, &v->sul_conn, &bo, + lws_ntpc_retry_conn, + &v->retry_count_conn); + + return -1; + + default: + break; + } + + return 0; + + +cancel_conn_timer: + lws_sul_cancel(&v->sul_conn); + + return 0; +} + +void +lws_ntpc_trigger(struct lws_context *ctx) +{ + struct vhd_ntpc *v = (struct vhd_ntpc *)ctx->ntpclient_priv; + + lwsl_notice("%s\n", __func__); + v->retry_count_conn = 0; + lws_ntpc_retry_conn(&v->sul_conn); +} + +struct lws_protocols lws_system_protocol_ntpc = + { "lws-ntpclient", callback_ntpc, 0, 128, }; + diff -Nru libwebsockets-3.2.1/lib/system/README.md libwebsockets-4.1.6/lib/system/README.md --- libwebsockets-3.2.1/lib/system/README.md 1970-01-01 00:00:00.000000000 +0000 +++ libwebsockets-4.1.6/lib/system/README.md 2020-12-01 17:40:26.000000000 +0000 @@ -0,0 +1,68 @@ +# LWS System Helpers + +Lws now has a little collection of helper utilities for common network-based +functions necessary for normal device operation, eg, async DNS, ntpclient +(necessary for tls validation), and DHCP client. + +## Conventions + +If any system helper is enabled for build, lws creates an additional vhost +"system" at Context Creation time. Wsi that are created for the system +features are bound to this. In the context object, this is available as +`.vhost_system`. + +# Attaching to an existing context from other threads + +To simplify the case different pieces of code want to attach to a single +lws_context at runtime, from different thread contexts, lws_system has an api +via an lws_system operation function pointer where the other threads can use +platform-specific locking to request callbacks to their own code from the +lws event loop thread context safely. + +For convenience, the callback can be delayed until the system has entered or +passed a specified system state, eg, LWS_SYSTATE_OPERATIONAL so the code will +only get called back after the network, ntpclient and auth have been done. +Additionally an opaque pointer can be passed to the callback when it is called +from the lws event loop context. + +## Implementing the system-specific locking + +`lws_system_ops_t` struct has a member `.attach` + +``` + int (*attach)(struct lws_context *context, int tsi, lws_attach_cb_t *cb, + lws_system_states_t state, void *opaque, + struct lws_attach_item **get); +``` + +This should be defined in user code as setting locking, then passing the +arguments through to a non-threadsafe helper + +``` +int +__lws_system_attach(struct lws_context *context, int tsi, lws_attach_cb_t *cb, + lws_system_states_t state, void *opaque, + struct lws_attach_item **get); +``` + +that does the actual attach work. When it returns, the locking should be +unlocked and the return passed back. + +## Attaching the callback request + +User code should call the lws_system_ops_t `.attach` function like + +``` + lws_system_get_ops(context)->attach(...); +``` + +The callback function which will be called from the lws event loop context +should look like this + +``` +void my_callback(struct lws_context *context, int tsi, void *opaque); +``` + +with the callback function name passed into the (*attach)() call above. When +the callback happens, the opaque user pointer set at the (*attach)() call is +passed back to it as an argument. diff -Nru libwebsockets-3.2.1/lib/system/smd/CMakeLists.txt libwebsockets-4.1.6/lib/system/smd/CMakeLists.txt --- libwebsockets-3.2.1/lib/system/smd/CMakeLists.txt 1970-01-01 00:00:00.000000000 +0000 +++ libwebsockets-4.1.6/lib/system/smd/CMakeLists.txt 2020-12-01 17:40:26.000000000 +0000 @@ -0,0 +1,8 @@ +include_directories(.) + +list(APPEND SOURCES + system/smd/smd.c +) + +exports_to_parent_scope() + diff -Nru libwebsockets-3.2.1/lib/system/smd/private-lib-system-smd.h libwebsockets-4.1.6/lib/system/smd/private-lib-system-smd.h --- libwebsockets-3.2.1/lib/system/smd/private-lib-system-smd.h 1970-01-01 00:00:00.000000000 +0000 +++ libwebsockets-4.1.6/lib/system/smd/private-lib-system-smd.h 2020-12-01 17:40:26.000000000 +0000 @@ -0,0 +1,114 @@ +/* + * lws System Message Distribution + * + * Copyright (C) 2019 - 2020 Andy Green + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to + * deal in the Software without restriction, including without limitation the + * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or + * sell copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS + * IN THE SOFTWARE. + */ + +/* + * Number of seconds registered peers must remain as zombies to handle in-flight + * older messages correctly + */ +#if !defined(LWS_SMD_INFLIGHT_GRACE_SECS) +#define LWS_SMD_INFLIGHT_GRACE_SECS (2) +#endif +#if !defined(LWS_SMD_MAX_QUEUE_DEPTH) +#define LWS_SMD_MAX_QUEUE_DEPTH (12) +#endif + +#if defined(LWS_WITH_SECURE_STREAMS) +#define LWS_SMD_SS_RX_HEADER_LEN_EFF (LWS_SMD_SS_RX_HEADER_LEN) +#else +#define LWS_SMD_SS_RX_HEADER_LEN_EFF (0) +#endif + +typedef struct lws_smd_msg { + lws_dll2_t list; + + lws_usec_t timestamp; + lws_smd_class_t _class; + + uint16_t length; + uint16_t refcount; + + /* message itself is over-allocated after this */ +} lws_smd_msg_t; + +/* + * The peer's relationship to the lws instance doing the distribution + */ + +typedef enum { + LSMDT_SAME_PROCESS, /* we call him back ourselves */ + LSMDT_SECURE_STREAMS_LOCAL, /* we call him back ourselves */ + LSMDT_SECURE_STREAMS_PROXIED, /* we ask to write and wait */ +} lws_smd_type_t; + +typedef struct lws_smd_peer { + lws_dll2_t list; + + lws_usec_t timestamp_joined; + lws_usec_t timestamp_left; + +#if defined(LWS_WITH_SECURE_STREAMS) + lws_ss_handle_t *ss_handle; /* LSMDT_SECURE_STREAMS */ +#endif + + lws_smd_notification_cb_t cb; /* LSMDT_ */ + void *opaque; + + /* NULL, or next message we will handle */ + lws_smd_msg_t *tail; + + lws_smd_class_t _class_filter; + lws_smd_type_t type; +} lws_smd_peer_t; + +/* + * Manages message distribution + * + * There is one of these in the lws_context, but the distribution action also + * gets involved in delivering to pt event loops individually for SMP case + */ + +typedef struct lws_smd { + lws_dll2_owner_t owner_messages; /* lws_smd_msg_t */ + lws_mutex_t lock_messages; + lws_dll2_owner_t owner_peers; /* lws_smd_peer_t */ + lws_mutex_t lock_peers; + + /* union of peer class filters, suppress creation of msg classes not set */ + lws_smd_class_t _class_filter; + + lws_sorted_usec_list_t sul_tail_stale; + + char delivering; +} lws_smd_t; + +/* check if this tsi has pending messages to deliver */ + +int +lws_smd_message_pending(struct lws_context *ctx); + +int +lws_smd_msg_distribute(struct lws_context *ctx); + +int +_lws_smd_destroy(struct lws_context *ctx); diff -Nru libwebsockets-3.2.1/lib/system/smd/README.md libwebsockets-4.1.6/lib/system/smd/README.md --- libwebsockets-3.2.1/lib/system/smd/README.md 1970-01-01 00:00:00.000000000 +0000 +++ libwebsockets-4.1.6/lib/system/smd/README.md 2020-12-01 17:40:26.000000000 +0000 @@ -0,0 +1,223 @@ +# LWS System Message Distribution + +## Overview + +Independent pieces of a system may need to become aware of events and state +changes in the other pieces quickly, along with the new state if it is small. +These messages are local to inside a system, although they may be triggered by +events outside of it. Examples include keypresses, or networking state changes. +Individual OSes and frameworks typically have their own fragmented apis for +message-passing, but the lws apis operate the same across any platforms +including, eg, Windows and RTOS and allow crossplatform code to be written once. + +Message payloads are short, less than 384 bytes, below system limits for atomic +pipe or UDS datagrams and consistent with heap usage on smaller systems, but +large enough to carry JSON usefully. Messages are typically low duty cycle. + +Messages may be sent by any registered participant, they are allocated on heap +in a linked-list, and delivered no sooner than next time around the event loop. +This retains the ability to handle multiple event queuing in one event loop trip +while guaranteeing message handling is nonrecursive. Messages are passed to all +other registered participants before being destroyed. + +`lws_smd` apis allow publication and subscription of message objects between +participants that are in a single process and are informed by callback from lws +service thread context, and, via Secure Streams proxying as the IPC method, also +between those in different processes. Registering as a participant and sending +messages are threadsafe APIs. + +## Message Class + +Message class is a bitfield messages use to indicate their general type, eg, +network status, or UI event like a keypress. Participants set a bitmask to +filter what kind of messages they care about, classes that are 0 in the peer's +filter are never delivered to the peer. A message usually indicates it is a +single class, but it's possible to set multiple class bits and match on any. If +so, care must be taken the payload can be parsed by readers expecting any of the +indicated classes, eg, by using JSON. + +`lws_smd` tracks a global union mask for all participants' class mask. Requests +to allocate a message of a class that no participant listens for are rejected, +not at distribution-time but at message allocation-time, so no heap or cpu is +wasted on things that are not currently interesting; but such messages start to +appear as soon as a participant appears that wants them. The message generation +action should be bypassed without error in the case lws_smd_msg_alloc() +returns NULL. + +## Messaging guarantees + +Sent messages are delivered to all registered participants whose class mask +indicates they want it, including the sender. The send apis are threadsafe. + +Locally-delivered message delivery callbacks occur from lws event loop thread +context 0 (the only one in the default case LWS_MAX_SMP = 1). Clients in +different processes receive callbacks from the thread context of their UDS +networking thread. + +The message payload may be destroyed immediately when you return from the +callback, you can't store references to it or expect it to be there later. + +Messages are timestamped with a systemwide monotonic timestamp. When +participants are on the lws event loop, messages are delivered in-order. When +participants are on different threads, delivery order depends on platform lock +acquisition. External process participants are connected by the Unix Domain +Socket capability of Secure Streams, and may be delivered out-of-order; +receivers that care must consult the message creation timestamps. + +## Message Refcounting + +To avoid keeping a list of the length of the number of participants for each +message, a refcount is used in the message, computed at the time the message +arrived considering the number of active participants that indicated a desire to +receive messages of that class. + +Since peers may detach / close their link asynchronously, the logical peer +objects at the distributor defer destroying themselves until there is no more +possibility of messages arriving timestamped with the period they were active. +A grace period (default 2s) is used to ensure departing peers correctly account +for message refcounts before being destroyed. + +## Message creation + +Messages may contain arbitrary text or binary data depending on the class. JSON +is recommended since lws_smd messages are small and low duty cycle but have +open-ended content: JSON is maintainable, extensible, debuggable and self- +documenting and avoids, eg, fragile dependencies on header versions shared +between teams. To simplify issuing JSON, a threadsafe api to create and send +messages in one step using format strings is provided: + +``` +int +lws_smd_msg_printf(struct lws_context *ctx, lws_smd_class_t _class, + const char *format, ...); +``` + +## Secure Streams `lws_smd` streamtype + +When built with LWS_WITH_SECURE_STREAMS, lws_smd exposes a built-in streamtype +`_lws_smd` which user Secure Streams may use to interoperate with lws_smd using +SS payload semantics. + +When using `_lws_smd`, the SS info struct member `manual_initial_tx_credit` +provided by the user when creating the Secure Stream is overloaded to be used as +the RX class mask for the SMD connection associated with the Secure Stream. + +Both RX and TX payloads have a 16-byte binary header before the actual payload. +For TX, although the header is 16-bytes, only the first 64-bit class bitfield +needs setting, the timestamp is fetched and added by lws. + + - MSB-first 64-bit class bitfield (currently only 32 least-sig in use) + - MSB-First Order 64-bit us-resolution timestamp + +## Well-known message schema + +Class|Schema +---|--- +LWSSMDCL_INTERACTION|lws_button events +LWSSMDCL_NETWORK|captive portal detection requests and results +LWSSMDCL_SYSTEM_STATE|lws_system state progression + +### User interaction Button events + +Class: `LWSSMDCL_INTERACTION` + +Produced by lws_button when a user interacts with a defined button. + +Click-related events are produced alongside up and down related events, the +participant can choose which to attend to according to the meaning of the +interaction. + +Both kinds of event go through sophisticated filtering before being issued, see +`./lib/drivers/button/README.md` for details. + +#### SMD Button interaction event + +Schema: +``` +{ + "type": "button", + "src": "/", + "event": "" +} +``` + +For example, `{"type":"button","src":"bc/user","event":"doubleclick"}` + +Event name|Meaning +---|--- +down|The button passes a filter for being down, useful for duration-based response +up|The button has come up, useful for duration-based response +click|The button activity resulted in a classification as a single-click +longclick|The button activity resulted in a classification as a long-click +doubleclick|The button activity resulted in a classification as a double-click + +### Captive Portal Detection + +Class: `LWSSMDCL_NETWORK` + +Actively detects if the network can reach the internet or if it is +intercepted by a captive portal. The detection steps are programmable +via the Secure Streams Policy for a streamtype `captive_portal_detect`, eg + +``` + "captive_portal_detect": { + "endpoint": "connectivitycheck.android.com", + "http_url": "generate_204", + "port": 80, + "protocol": "h1", + "http_method": "GET", + "opportunistic": true, + "http_expect": 204, + "http_fail_redirect": true + } +``` + +#### SMD Report Result + +Schema: `{"type": "cpd", "result":""}` + +result|meaning +---|--- +OK|Internet is reachable +Captive|Internet is behind a captive portal +No internet|There is no connectivity + +#### SMD Request re-detection + +Schema: `{"trigger": "cpdcheck"}` + +### lws_system state progression + +Class: `LWSSMDCL_SYSTEM_STATE` + +Lws system state changes are forwarded to lws_smd messages so participants not +on the lws event loop directly can be aware of progress. Code registering a +lws_system notifier callback, on the main lws loop, can synchronously veto state +changes and hook proposed state changes, lws_smd events are asynchronous +notifications of state changes after they were decided only... however they are +available over the whole system. + +It's not possible to make validated TLS connections until the system has +acquired the date as well as acquired an IP on a non-captive portal connection, +for that reason user code will usually be dependent on the system reaching +"OPERATIONAL" state if lws is responsible for managing the boot process. + +#### System state event + +Schema: `{"state":""}"` + +State|Meaning +---|--- +CONTEXT_CREATED|We're creating the lws_context +INITIALIZED|Initial vhosts and protocols initialized +IFACE_COLDPLUG|Network interfaces discovered +DHCP|DHCP acquired +CPD_PRE_TIME|Captive portal detect hook before we have system time +TIME_VALID|Ntpclient has run +CPD_POST_TIME|Captive portal detect hook after system time (tls-based check) +POLICY_VALID|The system policy has been acquired and parsed +REGISTERED|This device is registered with an authority +AUTH1|We acquired auth1 from the authority using our registration info +AUTH2|We acquired auth2 from the authority using our registration info +OPERATIONAL|We are active and able to make authenticated tls connections +POLICY_INVALID|The policy is being changed diff -Nru libwebsockets-3.2.1/lib/system/smd/smd.c libwebsockets-4.1.6/lib/system/smd/smd.c --- libwebsockets-3.2.1/lib/system/smd/smd.c 1970-01-01 00:00:00.000000000 +0000 +++ libwebsockets-4.1.6/lib/system/smd/smd.c 2020-12-01 17:40:26.000000000 +0000 @@ -0,0 +1,524 @@ +/* + * lws System Message Distribution + * + * Copyright (C) 2019 - 2020 Andy Green + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to + * deal in the Software without restriction, including without limitation the + * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or + * sell copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS + * IN THE SOFTWARE. + */ + +#include "private-lib-core.h" +#include + +void * +lws_smd_msg_alloc(struct lws_context *ctx, lws_smd_class_t _class, size_t len) +{ + lws_smd_msg_t *msg; + + /* only allow it if someone wants to consume this class of event */ + + if (!(ctx->smd._class_filter & _class)) { + lwsl_info("%s: rejecting class 0x%x as no participant wants it\n", __func__, + (unsigned int)_class); + return NULL; + } + + assert(len <= LWS_SMD_MAX_PAYLOAD); + + + /* + * If SS configured, over-allocate LWS_SMD_SS_RX_HEADER_LEN behind + * payload, ie, msg_t (gap LWS_SMD_SS_RX_HEADER_LEN) payload + */ + msg = lws_malloc(sizeof(*msg) + LWS_SMD_SS_RX_HEADER_LEN_EFF + len, + __func__); + if (!msg) + return NULL; + + memset(msg, 0, sizeof(*msg)); + msg->timestamp = lws_now_usecs(); + msg->length = (uint16_t)len; + msg->_class = _class; + + return ((uint8_t *)&msg[1]) + LWS_SMD_SS_RX_HEADER_LEN_EFF; +} + +void +lws_smd_msg_free(void **ppay) +{ + lws_smd_msg_t *msg = (lws_smd_msg_t *)(((uint8_t *)*ppay) - + LWS_SMD_SS_RX_HEADER_LEN_EFF - sizeof(*msg)); + + /* if SS configured, actual alloc is LWS_SMD_SS_RX_HEADER_LEN behind */ + lws_free(msg); + *ppay = NULL; +} + +/* + * Figure out what to set the initial refcount for the message to + */ + +static int +_lws_smd_msg_assess_peers_interested(lws_smd_t *smd, lws_smd_msg_t *msg) +{ + struct lws_context *ctx = lws_container_of(smd, struct lws_context, smd); + int interested = 0; + + lws_start_foreach_dll(struct lws_dll2 *, p, ctx->smd.owner_peers.head) { + lws_smd_peer_t *pr = lws_container_of(p, lws_smd_peer_t, list); + + /* + * In order to optimize the tail managment into a refcount, + * we have to account exactly for when peers arrived and + * departed (including deferring the logical peer destruction + * until no message pending he may have contributed to the + * refcount of) + */ + + if (pr->timestamp_joined <= msg->timestamp && + (!pr->timestamp_left || /* if zombie, only contribute to + * refcount if msg from before we + * left */ + pr->timestamp_left >= msg->timestamp) && + (msg->_class & pr->_class_filter)) + /* + * This peer wants to consume it + */ + interested++; + + } lws_end_foreach_dll(p); + + return interested; +} + +static int +_lws_smd_class_mask_union(lws_smd_t *smd) +{ + uint32_t mask = 0; + + lws_start_foreach_dll_safe(struct lws_dll2 *, p, p1, + smd->owner_peers.head) { + lws_smd_peer_t *pr = lws_container_of(p, lws_smd_peer_t, list); + + /* may destroy pr if zombie */ + mask |= pr->_class_filter; + + } lws_end_foreach_dll_safe(p, p1); + + smd->_class_filter = mask; + + return 0; +} + +int +lws_smd_msg_send(struct lws_context *ctx, void *pay) +{ + lws_smd_msg_t *msg = (lws_smd_msg_t *)(((uint8_t *)pay) - + LWS_SMD_SS_RX_HEADER_LEN_EFF - sizeof(*msg)); + + if (ctx->smd.owner_messages.count >= LWS_SMD_MAX_QUEUE_DEPTH) + /* reject the message due to max queue depth reached */ + return 1; + + if (!ctx->smd.delivering) + lws_mutex_lock(ctx->smd.lock_peers); /* +++++++++++++++ peers */ + + msg->refcount = _lws_smd_msg_assess_peers_interested(&ctx->smd, msg); + + lws_mutex_lock(ctx->smd.lock_messages); /* +++++++++++++++++ messages */ + lws_dll2_add_tail(&msg->list, &ctx->smd.owner_messages); + lws_mutex_unlock(ctx->smd.lock_messages); /* --------------- messages */ + + /* + * Any peer with no active tail needs to check our class to see if we + * should become his tail + */ + + lws_start_foreach_dll(struct lws_dll2 *, p, ctx->smd.owner_peers.head) { + lws_smd_peer_t *pr = lws_container_of(p, lws_smd_peer_t, list); + + if (!pr->tail && (pr->_class_filter & msg->_class)) + pr->tail = msg; + + } lws_end_foreach_dll(p); + + if (!ctx->smd.delivering) + lws_mutex_unlock(ctx->smd.lock_peers); /* ------------- peers */ + + /* we may be happening from another thread context */ + lws_cancel_service(ctx); + + return 0; +} + +int +lws_smd_msg_printf(struct lws_context *ctx, lws_smd_class_t _class, + const char *format, ...) +{ + lws_smd_msg_t *msg; + va_list ap; + void *p; + int n; + + if (!(ctx->smd._class_filter & _class)) + /* + * There's nobody interested in messages of this class atm. + * Don't bother generating it, and act like all is well. + */ + return 0; + + va_start(ap, format); + n = vsnprintf(NULL, 0, format, ap); + va_end(ap); + if (n > LWS_SMD_MAX_PAYLOAD) + /* too large to send */ + return 1; + + p = lws_smd_msg_alloc(ctx, _class, (size_t)n + 2); + if (!p) + return 1; + msg = (lws_smd_msg_t *)(((uint8_t *)p) - LWS_SMD_SS_RX_HEADER_LEN_EFF - + sizeof(*msg)); + msg->length = (uint16_t)n; + va_start(ap, format); + vsnprintf((char*)p, n + 2, format, ap); + va_end(ap); + + /* + * locks taken and released in here + */ + + if (lws_smd_msg_send(ctx, p)) { + lws_smd_msg_free(&p); + return 1; + } + + return 0; +} + + +static void +_lws_smd_peer_finalize_destroy(lws_smd_peer_t *pr) +{ + lws_dll2_remove(&pr->list); + lws_free(pr); +} + +/* + * Peers that deregister may need to hang around as zombies, so they account + * for refcounts on messages they already contributed to. Because older + * messages may be in flight over UDS links, we have to stick around and make + * sure all cases have their refcount handled correctly. + */ + +static void +_lws_smd_peer_zombify(lws_smd_peer_t *pr) +{ + lws_smd_t *smd = lws_container_of(pr->list.owner, lws_smd_t, + owner_peers); + + /* update the class mask union to reflect this peer no longer active */ + _lws_smd_class_mask_union(smd); + + pr->timestamp_left = lws_now_usecs(); +} + +static lws_smd_msg_t * +_lws_smd_msg_next_matching_filter(lws_dll2_t *tail, lws_smd_class_t filter) +{ + lws_smd_msg_t *msg; + + do { + tail = tail->next; + if (!tail) + return NULL; + + msg = lws_container_of(tail, lws_smd_msg_t, list); + if (msg->_class & filter) + return msg; + } while (1); + + return NULL; +} + +/* + * Note: May destroy zombie peers when it sees grace period has expired. + * + * Delivers only one message to the peer and advances the tail, or sets to NULL + * if no more filtered queued messages. Returns nonzero if tail non-NULL. + * + * For Proxied SS, only asks for writeable and does not advance or change the + * tail. + * + * This is done so if multiple messages queued, we don't get a situation where + * one participant gets them all spammed, then the next etc. Instead they are + * delivered round-robin. + */ + +static int +_lws_smd_msg_deliver_peer(struct lws_context *ctx, lws_smd_peer_t *pr) +{ + lws_smd_msg_t *msg; + + if (!pr->tail) + return 0; + + msg = lws_container_of(pr->tail, lws_smd_msg_t, list); + + /* + * Check if zombie peer and the message predates our leaving + */ + + if (pr->timestamp_left && + msg->timestamp > pr->timestamp_left) { + /* + * We do not need to modify message refcount, if it was + * generated after we became a zombie, and so we + * definitely did not contribute to its refcount... + * + * ...have we waited out the grace period? + */ + + if (lws_now_usecs() - pr->timestamp_left > + LWS_SMD_INFLIGHT_GRACE_SECS * LWS_US_PER_SEC) + /* + * ... ok, it's time for the zombie to abandon + * its attachment to the Earth and rejoin the + * cosmic mandela + */ + _lws_smd_peer_finalize_destroy(pr); + + /* ... either way, nothing further to do for this guy */ + + return 0; + } + + if (!pr->timestamp_left) { + + /* + * Peer is not a zombie... deliver the tail + */ +#if 0 + if (pr->type == LSMDT_SECURE_STREAMS_PROXIED) { +#if defined(LWS_WITH_SECURE_STREAMS) + if (pr->ss_handle) + lws_ss_request_tx(pr->ss_handle); +#endif + return 0; + } +#endif + + pr->cb(pr->opaque, msg->_class, msg->timestamp, + ((uint8_t *)&msg[1]) + + LWS_SMD_SS_RX_HEADER_LEN_EFF, + (size_t)msg->length); + } + + assert(msg->refcount); + + /* + * If there is one, move forward to the next queued + * message that meets our filters + */ + pr->tail = _lws_smd_msg_next_matching_filter( + &pr->tail->list, pr->_class_filter); + + if (!--msg->refcount) { + /* + * We have fully delivered the message now, it + * can be unlinked and destroyed + */ + lws_dll2_remove(&msg->list); + lws_free(msg); + } + + /* + * Wait out the grace period even if no live messages + * for a zombie peer... there may be some in flight + */ + + return !!pr->tail; +} + +/* + * Called when the event loop could deliver messages synchronously, eg, on + * entry to idle + */ + +int +lws_smd_msg_distribute(struct lws_context *ctx) +{ + char more; + + /* commonly, no messages and nothing to do... */ + + if (!ctx->smd.owner_messages.count) + return 0; + + ctx->smd.delivering = 1; + + do { + more = 0; + lws_mutex_lock(ctx->smd.lock_peers); /* +++++++++++++++ peers */ + + lws_start_foreach_dll_safe(struct lws_dll2 *, p, p1, + ctx->smd.owner_peers.head) { + lws_smd_peer_t *pr = lws_container_of(p, lws_smd_peer_t, list); + + /* may destroy pr if zombie, hence _safe iterator */ + more |= _lws_smd_msg_deliver_peer(ctx, pr); + + } lws_end_foreach_dll_safe(p, p1); + + lws_mutex_unlock(ctx->smd.lock_peers); /* ------------- peers */ + } while (more); + + ctx->smd.delivering = 0; + + return 0; +} + +struct lws_smd_peer * +lws_smd_register(struct lws_context *ctx, void *opaque, int flags, + lws_smd_class_t _class_filter, lws_smd_notification_cb_t cb) +{ + lws_smd_peer_t *pr = lws_zalloc(sizeof(*pr), __func__); + + if (!pr) + return NULL; + + pr->cb = cb; + pr->opaque = opaque; + pr->_class_filter = _class_filter; + pr->timestamp_joined = lws_now_usecs(); + + /* + * Figure out the type of peer from the situation... + */ + +#if 0 +#if defined(LWS_WITH_SECURE_STREAMS) + if (!ctx->smd.listen_vh) { + /* + * The guy who is regsitering is actually a SS proxy link + * between a client and SMD + */ + } else +#endif +#endif + pr->type = LSMDT_SAME_PROCESS; + + if (!ctx->smd.delivering) + lws_mutex_lock(ctx->smd.lock_peers); /* +++++++++++++++ peers */ + lws_dll2_add_tail(&pr->list, &ctx->smd.owner_peers); + + /* update the global class mask union to account for new peer mask */ + _lws_smd_class_mask_union(&ctx->smd); + if (!ctx->smd.delivering) + lws_mutex_unlock(ctx->smd.lock_peers); /* ------------- peers */ + + lwsl_debug("%s: registered\n", __func__); + + return pr; +} + +void +lws_smd_unregister(struct lws_smd_peer *pr) +{ + lws_smd_t *smd = lws_container_of(pr->list.owner, lws_smd_t, owner_peers); + + lws_mutex_lock(smd->lock_peers); /* +++++++++++++++++++++++++++ peers */ + _lws_smd_peer_zombify(pr); + lws_mutex_unlock(smd->lock_peers); /* ------------------------- peers */ +} + +int +lws_smd_message_pending(struct lws_context *ctx) +{ + int ret = 1; + + /* + * First cheaply check the common case no messages pending, so there's + * definitely nothing for this tsi or anything else + */ + + if (!ctx->smd.owner_messages.count) + return 0; + + /* + * Walk the peer list + */ + + lws_mutex_lock(ctx->smd.lock_peers); /* +++++++++++++++++++++++ peers */ + lws_start_foreach_dll(struct lws_dll2 *, p, ctx->smd.owner_peers.head) { + lws_smd_peer_t *pr = lws_container_of(p, lws_smd_peer_t, list); + + if (pr->tail && pr->type == LSMDT_SAME_PROCESS) + goto bail; + + } lws_end_foreach_dll(p); + + /* + * There's no message pending that we need to handle + */ + + ret = 0; + +bail: + lws_mutex_unlock(ctx->smd.lock_peers); /* --------------------- peers */ + + return ret; +} + +int +_lws_smd_destroy(struct lws_context *ctx) +{ + /* stop any message creation */ + + ctx->smd._class_filter = 0; + + /* + * Walk the message list, destroying them + */ + + lws_start_foreach_dll_safe(struct lws_dll2 *, p, p1, + ctx->smd.owner_messages.head) { + lws_smd_msg_t *msg = lws_container_of(p, lws_smd_msg_t, list); + + lws_free(msg); + + } lws_end_foreach_dll_safe(p, p1); + + lws_mutex_destroy(ctx->smd.lock_messages); + + /* + * Walk the peer list, destroying them + */ + + lws_start_foreach_dll_safe(struct lws_dll2 *, p, p1, + ctx->smd.owner_peers.head) { + lws_smd_peer_t *pr = lws_container_of(p, lws_smd_peer_t, list); + + _lws_smd_peer_finalize_destroy(pr); + + } lws_end_foreach_dll_safe(p, p1); + + lws_mutex_destroy(ctx->smd.lock_peers); + + return 0; +} diff -Nru libwebsockets-3.2.1/lib/system/system.c libwebsockets-4.1.6/lib/system/system.c --- libwebsockets-3.2.1/lib/system/system.c 1970-01-01 00:00:00.000000000 +0000 +++ libwebsockets-4.1.6/lib/system/system.c 2020-12-01 17:40:26.000000000 +0000 @@ -0,0 +1,265 @@ +/* + * libwebsockets - small server side websockets and web server implementation + * + * Copyright (C) 2010 - 2019 Andy Green + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to + * deal in the Software without restriction, including without limitation the + * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or + * sell copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS + * IN THE SOFTWARE. + */ + +#include + +/* + * It's either a buflist (.is_direct = 0) or + * a direct pointer + len (.is_direct = 1) + */ + +const lws_system_ops_t * +lws_system_get_ops(struct lws_context *context) +{ + return context->system_ops; +} + + +void +lws_system_blob_direct_set(lws_system_blob_t *b, const uint8_t *ptr, size_t len) +{ + b->is_direct = 1; + b->u.direct.ptr = ptr; + b->u.direct.len = len; +} + +void +lws_system_blob_heap_empty(lws_system_blob_t *b) +{ + b->is_direct = 0; + lws_buflist_destroy_all_segments(&b->u.bl); +} + +int +lws_system_blob_heap_append(lws_system_blob_t *b, const uint8_t *buf, size_t len) +{ + assert(!b->is_direct); + + lwsl_debug("%s: blob %p\n", __func__, b); + + if (lws_buflist_append_segment(&b->u.bl, buf, len) < 0) + return -1; + + return 0; +} + +size_t +lws_system_blob_get_size(lws_system_blob_t *b) +{ + if (b->is_direct) + return b->u.direct.len; + + return lws_buflist_total_len(&b->u.bl); +} + +int +lws_system_blob_get(lws_system_blob_t *b, uint8_t *buf, size_t *len, size_t ofs) +{ + int n; + + if (b->is_direct) { + + assert(b->u.direct.ptr); + + if (ofs >= b->u.direct.len) { + *len = 0; + return 1; + } + + if (*len > b->u.direct.len - ofs) + *len = b->u.direct.len - ofs; + + memcpy(buf, b->u.direct.ptr + ofs, *len); + + return 0; + } + + n = lws_buflist_linear_copy(&b->u.bl, ofs, buf, *len); + if (n < 0) + return -2; + + *len = n; + + return 0; +} + +int +lws_system_blob_get_single_ptr(lws_system_blob_t *b, const uint8_t **ptr) +{ + if (b->is_direct) { + *ptr = b->u.direct.ptr; + return 0; + } + + if (!b->u.bl) + return -1; + + if (b->u.bl->next) + return -1; /* multipart buflist, no single pointer to it all */ + + *ptr = (const uint8_t *)&b->u.bl[1]; + + return 0; +} + +void +lws_system_blob_destroy(lws_system_blob_t *b) +{ + if (!b) + return; + // lwsl_info("%s: blob %p\n", __func__, b); + if (!b->is_direct) + lws_buflist_destroy_all_segments(&b->u.bl); +} + +lws_system_blob_t * +lws_system_get_blob(struct lws_context *context, lws_system_blob_item_t type, + int idx) +{ + if (idx < 0 || + idx >= (int)LWS_ARRAY_SIZE(context->system_blobs)) + return NULL; + + return &context->system_blobs[type + idx]; +} + +#if defined(LWS_WITH_NETWORK) + +/* + * Caller must protect the whole call with system-specific locking + */ + +int +__lws_system_attach(struct lws_context *context, int tsi, lws_attach_cb_t cb, + lws_system_states_t state, void *opaque, + struct lws_attach_item **get) +{ + struct lws_context_per_thread *pt = &context->pt[tsi]; + struct lws_attach_item *item; + + if (!get) { + /* + * allocate and add to the head of the pt's attach list + */ + + item = lws_zalloc(sizeof(*item), __func__); + if (!item) + return 1; + + item->cb = cb; + item->opaque = opaque; + item->state = state; + + lws_dll2_add_head(&item->list, &pt->attach_owner); + + lws_cancel_service(context); + + return 0; + } + + *get = NULL; +#if defined(LWS_WITH_SYS_STATE) + if (!pt->attach_owner.count) + return 0; + + /* + * If any, return the first guy whose state requirement matches + */ + + lws_start_foreach_dll(struct lws_dll2 *, d, + lws_dll2_get_head(&pt->attach_owner)) { + item = lws_container_of(d, lws_attach_item_t, list); + + if (pt->context->mgr_system.state >= (int)item->state) { + *get = item; + lws_dll2_remove(d); + + /* + * We detached it, but the caller now has the + * responsibility to lws_free() *get. + */ + + return 0; + } + } lws_end_foreach_dll(d); +#endif + + /* nobody ready to go... leave *get as NULL and return cleanly */ + + return 0; +} + +int +lws_system_do_attach(struct lws_context_per_thread *pt) +{ + /* + * If nothing to do, we just return immediately + */ + + while (pt->attach_owner.count) { + + struct lws_attach_item *item; + + /* + * If anybody used the attach apis, there must be an + * implementation of the (*attach) lws_system op function + */ + + assert(pt->context->system_ops->attach); + if (!pt->context->system_ops->attach) { + lwsl_err("%s: define (*attach)\n", __func__); + return 1; + } + + /* + * System locking is applied only around this next call, while + * we detach and get a pointer to the tail attach item. We + * become responsible to free what we have detached. + */ + + if (pt->context->system_ops->attach(pt->context, pt->tid, NULL, + 0, NULL, &item)) { + lwsl_err("%s: attach problem\n", __func__); + return 1; + } + + if (!item) + /* there's nothing more to do at the moment */ + return 0; + + /* + * Do the callback from the lws event loop thread + */ + + item->cb(pt->context, pt->tid, item->opaque); + + /* it's done, destroy the item */ + + lws_free(item); + } + + return 0; +} + +#endif diff -Nru libwebsockets-3.2.1/lib/tls/CMakeLists.txt libwebsockets-4.1.6/lib/tls/CMakeLists.txt --- libwebsockets-3.2.1/lib/tls/CMakeLists.txt 1970-01-01 00:00:00.000000000 +0000 +++ libwebsockets-4.1.6/lib/tls/CMakeLists.txt 2020-12-01 17:40:26.000000000 +0000 @@ -0,0 +1,482 @@ +# +# libwebsockets - small server side websockets and web server implementation +# +# Copyright (C) 2010 - 2020 Andy Green +# +# Permission is hereby granted, free of charge, to any person obtaining a copy +# of this software and associated documentation files (the "Software"), to +# deal in the Software without restriction, including without limitation the +# rights to use, copy, modify, merge, publish, distribute, sublicense, and/or +# sell copies of the Software, and to permit persons to whom the Software is +# furnished to do so, subject to the following conditions: +# +# The above copyright notice and this permission notice shall be included in +# all copies or substantial portions of the Software. +# +# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING +# FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS +# IN THE SOFTWARE. +# +# +# This converts everything about the tls support into +# +# - entries on SOURCES (modifications set back in PARENT_SCOPE) +# - entries on LIB_LIST (modifications set back in PARENT_SCOPE) +# - include_directories() +# - Api build-time discovery results set in PARENT_SCOPE +# +# Everything else is handled privately here. + +include_directories(.) + +# Allow the user to use the old CyaSSL options/library in stead of wolfSSL +if (LWS_WITH_CYASSL AND LWS_WITH_WOLFSSL) + message(FATAL_ERROR "LWS_WITH_CYASSL and LWS_WITH_WOLFSSL are mutually exclusive!") +endif() + +if (LWS_WITH_CYASSL) + # Copy CyaSSL options to the wolfSSL options + set(LWS_WITH_WOLFSSL ${LWS_WITH_CYASSL} CACHE BOOL "Use wolfSSL/CyaSSL instead of OpenSSL" FORCE PARENT_SCOPE) + set(LWS_WOLFSSL_LIBRARIES ${LWS_CYASSL_LIBRARIES} CACHE PATH "Path to wolfSSL/CyaSSL libraries" FORCE PARENT_SCOPE) + set(LWS_WOLFSSL_INCLUDE_DIRS ${LWS_CYASSL_INCLUDE_DIRS} CACHE PATH "Path to wolfSSL/CyaSSL header files" FORCE PARENT_SCOPE) +endif() + +set(LWS_OPENSSL_LIBRARIES CACHE PATH "Path to the OpenSSL library" ) +set(LWS_OPENSSL_INCLUDE_DIRS CACHE PATH "Path to the OpenSSL include directory" ) +set(LWS_WOLFSSL_LIBRARIES CACHE PATH "Path to the wolfSSL library" ) +set(LWS_WOLFSSL_INCLUDE_DIRS CACHE PATH "Path to the wolfSSL include directory" ) + + +if (LWS_WITH_BORINGSSL) + # boringssl deprecated EVP_PKEY + set (LWS_WITH_GENHASH OFF PARENT_SCOPE) +endif() + +if (LWS_WITH_SSL AND NOT LWS_WITH_WOLFSSL AND NOT LWS_WITH_MBEDTLS) + if ("${LWS_OPENSSL_LIBRARIES}" STREQUAL "" OR "${LWS_OPENSSL_INCLUDE_DIRS}" STREQUAL "") + else() + if (NOT LWS_PLAT_FREERTOS) + set(OPENSSL_LIBRARIES ${LWS_OPENSSL_LIBRARIES}) + endif() + set(OPENSSL_INCLUDE_DIRS ${LWS_OPENSSL_INCLUDE_DIRS}) + set(OPENSSL_FOUND 1) + endif() +endif() + +if (LWS_WITH_SSL AND LWS_WITH_WOLFSSL) + if ("${LWS_WOLFSSL_LIBRARIES}" STREQUAL "" OR "${LWS_WOLFSSL_INCLUDE_DIRS}" STREQUAL "") + if (NOT WOLFSSL_FOUND) + if (LWS_WITH_CYASSL) + message(FATAL_ERROR "You must set LWS_CYASSL_LIBRARIES and LWS_CYASSL_INCLUDE_DIRS when LWS_WITH_CYASSL is turned on.") + else() + message(FATAL_ERROR "You must set LWS_WOLFSSL_LIBRARIES and LWS_WOLFSSL_INCLUDE_DIRS when LWS_WITH_WOLFSSL is turned on.") + endif() + endif() + else() + set(WOLFSSL_LIBRARIES ${LWS_WOLFSSL_LIBRARIES}) + set(WOLFSSL_INCLUDE_DIRS ${LWS_WOLFSSL_INCLUDE_DIRS}) + set(WOLFSSL_FOUND 1) + endif() + set(USE_WOLFSSL 1) + set(USE_WOLFSSL 1 PARENT_SCOPE) + set(LWS_WITH_TLS 1 PARENT_SCOPE) + if (LWS_WITH_CYASSL) + set(USE_OLD_CYASSL 1) + endif() +endif() + +if (LWS_SSL_CLIENT_USE_OS_CA_CERTS) + set(LWS_SSL_CLIENT_USE_OS_CA_CERTS 1 PARENT_SCOPE) +endif() + +if (LWS_WITH_MBEDTLS) + add_subdirectory(mbedtls) + include_directories(${_CMAKE_INC_LIST}) +endif() + +# The base dir where the test-apps look for the SSL certs. +set(LWS_OPENSSL_CLIENT_CERTS ../share CACHE PATH "Server SSL certificate directory") +if (WIN32) + set(LWS_OPENSSL_CLIENT_CERTS . CACHE PATH "Client SSL certificate directory" PARENT_SCOPE) +else() + set(LWS_OPENSSL_CLIENT_CERTS /etc/pki/tls/certs/ CACHE PATH "Client SSL certificate directory") +endif() + +if (LWS_WITH_SSL) + list(APPEND SOURCES + tls/tls.c) + if (LWS_WITH_NETWORK) + list(APPEND SOURCES + tls/tls-network.c) + endif() + + if (LWS_WITH_MBEDTLS) + list(APPEND SOURCES + tls/mbedtls/mbedtls-tls.c + tls/mbedtls/mbedtls-x509.c) + if (LWS_WITH_NETWORK) + list(APPEND SOURCES + tls/mbedtls/mbedtls-ssl.c) + endif() + if (LWS_WITH_GENCRYPTO) + list(APPEND SOURCES + tls/mbedtls/lws-genhash.c + tls/mbedtls/lws-genrsa.c + tls/mbedtls/lws-genaes.c + tls/lws-genec-common.c + tls/mbedtls/lws-genec.c + tls/mbedtls/lws-gencrypto.c) + endif() + else() + list(APPEND SOURCES + tls/openssl/openssl-tls.c + tls/openssl/openssl-x509.c) + if (LWS_WITH_NETWORK) + list(APPEND SOURCES + tls/openssl/openssl-ssl.c) + endif() + if (LWS_WITH_GENCRYPTO) + list(APPEND SOURCES + tls/openssl/lws-genhash.c + tls/openssl/lws-genrsa.c + tls/openssl/lws-genaes.c + tls/lws-genec-common.c + tls/openssl/lws-genec.c + tls/openssl/lws-gencrypto.c) + endif() + endif() + + if (NOT LWS_WITHOUT_SERVER) + list(APPEND SOURCES + tls/tls-server.c) + if (LWS_WITH_MBEDTLS) + list(APPEND SOURCES + tls/mbedtls/mbedtls-server.c) + else() + list(APPEND SOURCES + tls/openssl/openssl-server.c) + endif() + endif() + if (NOT LWS_WITHOUT_CLIENT) + list(APPEND SOURCES + tls/tls-client.c) + if (LWS_WITH_MBEDTLS) + list(APPEND SOURCES + tls/mbedtls/mbedtls-client.c) + else() + list(APPEND SOURCES + tls/openssl/openssl-client.c) + endif() + + endif() +endif() + +set(SOURCES ${SOURCES} PARENT_SCOPE) + +# +# OpenSSL +# +if (LWS_WITH_SSL) + message("Compiling with SSL support") + set(chose_ssl 0) + if (LWS_WITH_WOLFSSL) + # Use wolfSSL as OpenSSL replacement. + # TODO: Add a find_package command for this also. + message("wolfSSL include dir: ${WOLFSSL_INCLUDE_DIRS}") + message("wolfSSL libraries: ${WOLFSSL_LIBRARIES}") + + # Additional to the root directory we need to include + # the wolfssl/ subdirectory which contains the OpenSSL + # compatibility layer headers. + + if (LWS_WITH_CYASSL) + foreach(inc ${WOLFSSL_INCLUDE_DIRS}) + set(OPENSSL_INCLUDE_DIRS ${OPENSSL_INCLUDE_DIRS} ${inc} ${inc}/cyassl) + include_directories("${inc}" "${inc}/cyassl") + endforeach() + else() + foreach(inc ${WOLFSSL_INCLUDE_DIRS}) + set(OPENSSL_INCLUDE_DIRS ${OPENSSL_INCLUDE_DIRS} ${inc} ${inc}/wolfssl) + include_directories("${inc}" "${inc}/wolfssl") + endforeach() + endif() + set(CMAKE_REQUIRED_INCLUDES ${CMAKE_REQUIRED_INCLUDES} ${OPENSSL_INCLUDE_DIRS}) + set(CMAKE_REQUIRED_INCLUDES ${CMAKE_REQUIRED_INCLUDES} PARENT_SCOPE) + set(OPENSSL_INCLUDE_DIRS ${OPENSSL_INCLUDE_DIRS} PARENT_SCOPE) + set(VARIA wolfSSL_) + + list(INSERT LIB_LIST 0 "${WOLFSSL_LIBRARIES}") + message("LIB_LIST ${LIB_LIST}") + set(chose_ssl 1) + endif() + + if (LWS_WITH_MBEDTLS AND DEFINED MBEDTLS_INCLUDE_DIRS AND DEFINED MBEDTLS_LIBRARIES) + message("MBEDTLS include dir: ${MBEDTLS_INCLUDE_DIRS}") + message("MBEDTLS libraries: ${MBEDTLS_LIBRARIES}") + + foreach(inc ${MBEDTLS_INCLUDE_DIRS}) + include_directories("${inc}" "${inc}/mbedtls") + endforeach() + + list(INSERT LIB_LIST 0 "${MBEDTLS_LIBRARIES}") + endif() + + if (LWS_WITH_MBEDTLS) + set(chose_ssl 1) + endif() + + if (NOT chose_ssl) + if (NOT OPENSSL_FOUND AND NOT LWS_WITH_BORINGSSL) + # TODO: Add support for STATIC also. + if (NOT LWS_PLAT_FREERTOS) + find_package(PkgConfig QUIET) + pkg_check_modules(PC_OPENSSL openssl QUIET) + find_package(OpenSSL REQUIRED) + list(APPEND OPENSSL_LIBRARIES ${PC_OPENSSL_LIBRARIES}) + set(OPENSSL_LIBRARIES ${OPENSSL_LIBRARIES} PARENT_SCOPE) + endif() + set(OPENSSL_INCLUDE_DIRS "${OPENSSL_INCLUDE_DIR}") + endif() + + message("OpenSSL include dir: ${OPENSSL_INCLUDE_DIRS}") + if (NOT LWS_PLAT_FREERTOS) + message("OpenSSL libraries: ${OPENSSL_LIBRARIES}") + endif() + + if (OPENSSL_INCLUDE_DIRS) + include_directories("${OPENSSL_INCLUDE_DIRS}") + if (NOT LWS_PLAT_FREERTOS) + list(INSERT LIB_LIST 0 ${OPENSSL_LIBRARIES}) + endif() + + if (NOT LWS_WITH_MBEDTLS) + # older (0.98) Openssl lacks this + set(CMAKE_REQUIRED_INCLUDES ${CMAKE_REQUIRED_INCLUDES} ${OPENSSL_INCLUDE_DIRS} PARENT_SCOPE) + check_include_file(openssl/ecdh.h LWS_HAVE_OPENSSL_ECDH_H) + + if (LWS_SSL_SERVER_WITH_ECDH_CERT AND NOT LWS_HAVE_OPENSSL_ECDH_H) + message(FATAL_ERROR "Missing openssl/ecdh.h, so cannot use LWS_SSL_SERVER_WITH_ECDH_CERT") + endif() + else() + unset(LWS_HAVE_OPENSSL_ECDH_H PARENT_SCOPE) + endif(NOT LWS_WITH_MBEDTLS) + endif() + endif() + +endif(LWS_WITH_SSL) + +if (DEFINED OPENSSL_INCLUDE_DIRS) + set(CMAKE_REQUIRED_INCLUDES ${OPENSSL_INCLUDE_DIRS}) +endif() +if (DEFINED LIB_LIST) + set(CMAKE_REQUIRED_LIBRARIES ${LIB_LIST}) +endif() +if (UNIX AND NOT (${CMAKE_SYSTEM_NAME} MATCHES "QNX")) + set(CMAKE_REQUIRED_LIBRARIES ${CMAKE_REQUIRED_LIBRARIES} dl) +endif() +if ((CMAKE_COMPILER_IS_GNUCC OR CMAKE_COMPILER_IS_GNUCXX) AND NOT (${CMAKE_SYSTEM_NAME} MATCHES "QNX")) + set(CMAKE_REQUIRED_LIBRARIES ${CMAKE_REQUIRED_LIBRARIES} pthread) +endif() + +if (NOT VARIA) + set(VARIA "") +endif() + +CHECK_FUNCTION_EXISTS(${VARIA}SSL_CTX_set1_param LWS_HAVE_SSL_CTX_set1_param PARENT_SCOPE) +CHECK_FUNCTION_EXISTS(${VARIA}SSL_set_info_callback LWS_HAVE_SSL_SET_INFO_CALLBACK PARENT_SCOPE) +CHECK_FUNCTION_EXISTS(${VARIA}X509_VERIFY_PARAM_set1_host LWS_HAVE_X509_VERIFY_PARAM_set1_host PARENT_SCOPE) +CHECK_FUNCTION_EXISTS(${VARIA}RSA_set0_key LWS_HAVE_RSA_SET0_KEY PARENT_SCOPE) +CHECK_FUNCTION_EXISTS(${VARIA}X509_get_key_usage LWS_HAVE_X509_get_key_usage PARENT_SCOPE) +CHECK_FUNCTION_EXISTS(${VARIA}EVP_PKEY_new_raw_private_key LWS_HAVE_SSL_CTX_EVP_PKEY_new_raw_private_key PARENT_SCOPE) +CHECK_FUNCTION_EXISTS(${VARIA}SSL_CTX_get0_certificate LWS_HAVE_SSL_CTX_get0_certificate PARENT_SCOPE) +CHECK_FUNCTION_EXISTS(${VARIA}SSL_get0_alpn_selected LWS_HAVE_SSL_get0_alpn_selected PARENT_SCOPE) +CHECK_FUNCTION_EXISTS(${VARIA}SSL_set_alpn_protos LWS_HAVE_SSL_set_alpn_protos PARENT_SCOPE) +CHECK_FUNCTION_EXISTS(${VARIA}EVP_aes_128_cfb8 LWS_HAVE_EVP_aes_128_cfb8 PARENT_SCOPE) +CHECK_FUNCTION_EXISTS(${VARIA}EVP_aes_128_cfb128 LWS_HAVE_EVP_aes_128_cfb128 PARENT_SCOPE) +CHECK_FUNCTION_EXISTS(${VARIA}EVP_aes_192_cfb8 LWS_HAVE_EVP_aes_192_cfb8 PARENT_SCOPE) +CHECK_FUNCTION_EXISTS(${VARIA}EVP_aes_192_cfb128 LWS_HAVE_EVP_aes_192_cfb128 PARENT_SCOPE) +CHECK_FUNCTION_EXISTS(${VARIA}EVP_aes_256_cfb8 LWS_HAVE_EVP_aes_256_cfb8 PARENT_SCOPE) +CHECK_FUNCTION_EXISTS(${VARIA}EVP_aes_256_cfb128 LWS_HAVE_EVP_aes_256_cfb128 PARENT_SCOPE) +CHECK_FUNCTION_EXISTS(${VARIA}EVP_aes_128_xts LWS_HAVE_EVP_aes_128_xts PARENT_SCOPE) +CHECK_FUNCTION_EXISTS(${VARIA}RSA_verify_pss_mgf1 LWS_HAVE_RSA_verify_pss_mgf1 PARENT_SCOPE) +CHECK_FUNCTION_EXISTS(${VARIA}HMAC_CTX_new LWS_HAVE_HMAC_CTX_new PARENT_SCOPE) +CHECK_FUNCTION_EXISTS(${VARIA}SSL_CTX_set_ciphersuites LWS_HAVE_SSL_CTX_set_ciphersuites PARENT_SCOPE) +CHECK_FUNCTION_EXISTS(${VARIA}EVP_PKEY_new_raw_private_key LWS_HAVE_EVP_PKEY_new_raw_private_key PARENT_SCOPE) + +if (LWS_WITH_SSL AND NOT LWS_WITH_MBEDTLS) + # we don't want to confuse what's in or out of the wrapper with + # what's in an openssl also installed on the build host +CHECK_C_SOURCE_COMPILES("#include \nint main(void) { STACK_OF(X509) *c = NULL; SSL_CTX *ctx = NULL; return (int)SSL_CTX_get_extra_chain_certs_only(ctx, &c); }\n" LWS_HAVE_SSL_EXTRA_CHAIN_CERTS) +CHECK_C_SOURCE_COMPILES("#include \nint main(void) { EVP_MD_CTX *md_ctx = NULL; EVP_MD_CTX_free(md_ctx); return 0; }\n" LWS_HAVE_EVP_MD_CTX_free) +set(LWS_HAVE_SSL_EXTRA_CHAIN_CERTS ${LWS_HAVE_SSL_EXTRA_CHAIN_CERTS} PARENT_SCOPE) +set(LWS_HAVE_EVP_MD_CTX_free ${LWS_HAVE_EVP_MD_CTX_free} PARENT_SCOPE) +CHECK_FUNCTION_EXISTS(${VARIA}ECDSA_SIG_set0 LWS_HAVE_ECDSA_SIG_set0 PARENT_SCOPE) +CHECK_FUNCTION_EXISTS(${VARIA}BN_bn2binpad LWS_HAVE_BN_bn2binpad PARENT_SCOPE) +CHECK_FUNCTION_EXISTS(${VARIA}EVP_aes_128_wrap LWS_HAVE_EVP_aes_128_wrap PARENT_SCOPE) +CHECK_FUNCTION_EXISTS(${VARIA}EC_POINT_get_affine_coordinates LWS_HAVE_EC_POINT_get_affine_coordinates PARENT_SCOPE) +CHECK_FUNCTION_EXISTS(${VARIA}SSL_CTX_load_verify_file LWS_HAVE_SSL_CTX_load_verify_file PARENT_SCOPE) +CHECK_FUNCTION_EXISTS(${VARIA}SSL_CTX_load_verify_dir LWS_HAVE_SSL_CTX_load_verify_dir PARENT_SCOPE) +endif() + +if (LWS_WITH_MBEDTLS) + set(LWS_HAVE_TLS_CLIENT_METHOD 1 PARENT_SCOPE) + if (NOT LWS_PLAT_FREERTOS) + # not supported in esp-idf openssl wrapper yet, but is in our version + set(LWS_HAVE_X509_VERIFY_PARAM_set1_host 1 PARENT_SCOPE) + endif() + + CHECK_FUNCTION_EXISTS(mbedtls_ssl_conf_alpn_protocols LWS_HAVE_mbedtls_ssl_conf_alpn_protocols PARENT_SCOPE) + CHECK_FUNCTION_EXISTS(mbedtls_ssl_get_alpn_protocol LWS_HAVE_mbedtls_ssl_get_alpn_protocol PARENT_SCOPE) + CHECK_FUNCTION_EXISTS(mbedtls_ssl_conf_sni LWS_HAVE_mbedtls_ssl_conf_sni PARENT_SCOPE) + CHECK_FUNCTION_EXISTS(mbedtls_ssl_set_hs_ca_chain LWS_HAVE_mbedtls_ssl_set_hs_ca_chain PARENT_SCOPE) + CHECK_FUNCTION_EXISTS(mbedtls_ssl_set_hs_own_cert LWS_HAVE_mbedtls_ssl_set_hs_own_cert PARENT_SCOPE) + CHECK_FUNCTION_EXISTS(mbedtls_ssl_set_hs_authmode LWS_HAVE_mbedtls_ssl_set_hs_authmode PARENT_SCOPE) + CHECK_FUNCTION_EXISTS(mbedtls_net_init LWS_HAVE_mbedtls_net_init PARENT_SCOPE) + CHECK_FUNCTION_EXISTS(mbedtls_md_setup LWS_HAVE_mbedtls_md_setup PARENT_SCOPE) # not on xenial 2.2 + CHECK_FUNCTION_EXISTS(mbedtls_rsa_complete LWS_HAVE_mbedtls_rsa_complete PARENT_SCOPE) # not on xenial 2.2 + CHECK_FUNCTION_EXISTS(mbedtls_internal_aes_encrypt LWS_HAVE_mbedtls_internal_aes_encrypt PARENT_SCOPE) # not on xenial 2.2 +else() +CHECK_FUNCTION_EXISTS(${VARIA}TLS_client_method LWS_HAVE_TLS_CLIENT_METHOD PARENT_SCOPE) +CHECK_FUNCTION_EXISTS(${VARIA}TLSv1_2_client_method LWS_HAVE_TLSV1_2_CLIENT_METHOD PARENT_SCOPE) +endif() + +# Generate self-signed SSL certs for the test-server. + +if (LWS_WITH_SSL AND NOT LWS_WITH_WOLFSSL) + message("Searching for OpenSSL executable and dlls") + find_package(OpenSSLbins) + if (DEFINED OPENSSL_EXECUTABLE) + message("OpenSSL executable: ${OPENSSL_EXECUTABLE}") + + if (OPENSSL_EXECUTABLE MATCHES "^$") + set(OPENSSL_EXECUTABLE openssl) + endif() + endif() + if (NOT DEFINED OPENSSL_EXECUTABLE) + set(OPENSSL_EXECUTABLE openssl) + endif() + +endif() + +set(GENCERTS 0) + +if (LWS_WITH_SSL AND OPENSSL_EXECUTABLE AND NOT LWS_WITHOUT_TEST_SERVER AND NOT LWS_WITHOUT_SERVER AND NOT LWS_WITHOUT_TESTAPPS) + set(GENCERTS 1) +endif() +if (LWS_PLAT_FREERTOS AND LWS_WITH_SSL) + set(GENCERTS 1) +endif() +message(" GENCERTS = ${GENCERTS}") +if (GENCERTS) + message("Generating SSL Certificates for the test-server...") + + set(TEST_SERVER_SSL_KEY "${PROJECT_BINARY_DIR}/libwebsockets-test-server.key.pem") + set(TEST_SERVER_SSL_CERT "${PROJECT_BINARY_DIR}/libwebsockets-test-server.pem") + + if (WIN32) + if (MINGW) + message("cmd = \"${OPENSSL_EXECUTABLE}\" req -new -newkey rsa:2048 -days 10000 -nodes -x509 -subj \"/C=GB/ST=Erewhon/L=All around/O=libwebsockets-test/CN=localhost\" -keyout \"${TEST_SERVER_SSL_KEY}\" -out \"${TEST_SERVER_SSL_CERT}\"") + execute_process( + COMMAND "${OPENSSL_EXECUTABLE}" req -new -newkey rsa:2048 -days 10000 -nodes -x509 -subj "/C=GB/ST=Erewhon/L=All around/O=libwebsockets-test/CN=localhost" -keyout "${TEST_SERVER_SSL_KEY}" -out "${TEST_SERVER_SSL_CERT}" + RESULT_VARIABLE OPENSSL_RETURN_CODE) + else() + file(WRITE "${PROJECT_BINARY_DIR}/openssl_input.txt" + "GB\n" + "Erewhon\n" + "All around\n" + "libwebsockets-test\n" + "localhost\n" + "none@invalid.org\n\n" + ) + + # The "type" command is a bit picky with paths. + file(TO_NATIVE_PATH "${PROJECT_BINARY_DIR}/openssl_input.txt" OPENSSL_INPUT_WIN_PATH) + message("OPENSSL_INPUT_WIN_PATH = ${OPENSSL_INPUT_WIN_PATH}") + message("cmd = \"${OPENSSL_EXECUTABLE}\" req -new -newkey rsa:2048 -days 10000 -nodes -x509 -keyout \"${TEST_SERVER_SSL_KEY}\" -out \"${TEST_SERVER_SSL_CERT}\"") + + execute_process( + COMMAND cmd /c type "${OPENSSL_INPUT_WIN_PATH}" + COMMAND "${OPENSSL_EXECUTABLE}" req -new -newkey rsa:2048 -days 10000 -nodes -x509 -keyout "${TEST_SERVER_SSL_KEY}" -out "${TEST_SERVER_SSL_CERT}" + RESULT_VARIABLE OPENSSL_RETURN_CODE + OUTPUT_QUIET ERROR_QUIET) + + message("\n") + endif() + + if (OPENSSL_RETURN_CODE) + message(WARNING "!!! Failed to generate SSL certificate for Test Server using cmd.exe !!!:\nOpenSSL return code = ${OPENSSL_RETURN_CODE}") + else() + message("SUCCSESFULLY generated SSL certificate") + endif() + else() + # Unix. + execute_process( + COMMAND printf "GB\\nErewhon\\nAll around\\nlibwebsockets-test\\n\\nlocalhost\\nnone@invalid.org\\n" + COMMAND "${OPENSSL_EXECUTABLE}" + req -new -newkey rsa:2048 -days 10000 -nodes -x509 -keyout "${TEST_SERVER_SSL_KEY}" -out "${TEST_SERVER_SSL_CERT}" + RESULT_VARIABLE OPENSSL_RETURN_CODE + # OUTPUT_QUIET ERROR_QUIET + ) + + if (OPENSSL_RETURN_CODE) + message(WARNING "!!! Failed to generate SSL certificate for Test Server!!!:\nOpenSSL return code = ${OPENSSL_RETURN_CODE}") + else() + message("SUCCESSFULLY generated SSL certificate") + endif() + endif() + + list(APPEND TEST_SERVER_DATA + "${TEST_SERVER_SSL_KEY}" + "${TEST_SERVER_SSL_CERT}") +endif() + +# +# Copy OpenSSL dlls to the output directory on Windows. +# (Otherwise we'll get an error when trying to run) +# +if (MSVC AND LWS_WITH_SSL AND NOT LWS_WITH_WOLFSSL) + if(OPENSSL_BIN_FOUND) + message("OpenSSL dlls found:") + message(" Libeay: ${LIBEAY_BIN}") + message(" SSLeay: ${SSLEAY_BIN}") + + foreach(TARGET_BIN ${TEST_APP_LIST}) + add_custom_command(TARGET ${TARGET_BIN} + POST_BUILD + COMMAND "${CMAKE_COMMAND}" -E copy "${LIBEAY_BIN}" "$" VERBATIM) + add_custom_command(TARGET ${TARGET_BIN} + POST_BUILD + COMMAND "${CMAKE_COMMAND}" -E copy "${SSLEAY_BIN}" "$" VERBATIM) + + # + # Win32: if we are using libuv, also need to copy it in the output dir + # + if (MSVC AND LWS_WITH_LIBUV) + STRING(REPLACE ".lib" ".dll" LIBUV_BIN ${LIBUV_LIBRARIES}) + add_custom_command(TARGET ${TARGET_BIN} + POST_BUILD + COMMAND "${CMAKE_COMMAND}" -E copy "${LIBUV_BIN}" "$" VERBATIM) + endif() + endforeach() + endif() +endif() + +if (LWS_WITH_TLS AND (LWS_WITH_JOSE OR LWS_WITH_GENCRYPTO)) + list(APPEND SOURCES + tls/lws-gencrypto-common.c) +endif() + +# +# Keep explicit parent scope exports at end +# + +exports_to_parent_scope() +set(LWS_HAVE_MBEDTLS_NET_SOCKETS ${LWS_HAVE_MBEDTLS_NET_SOCKETS} PARENT_SCOPE) +set(TEST_SERVER_SSL_KEY "${TEST_SERVER_SSL_KEY}" PARENT_SCOPE) +set(TEST_SERVER_SSL_CERT "${TEST_SERVER_SSL_CERT}" PARENT_SCOPE) +set(TEST_SERVER_DATA ${TEST_SERVER_DATA} PARENT_SCOPE) + diff -Nru libwebsockets-3.2.1/lib/tls/lws-gencrypto-common.c libwebsockets-4.1.6/lib/tls/lws-gencrypto-common.c --- libwebsockets-3.2.1/lib/tls/lws-gencrypto-common.c 2019-12-18 14:45:31.000000000 +0000 +++ libwebsockets-4.1.6/lib/tls/lws-gencrypto-common.c 2020-12-01 17:40:26.000000000 +0000 @@ -1,24 +1,28 @@ /* - * libwebsockets - generic crypto hiding the backend - common parts + * libwebsockets - small server side websockets and web server implementation * - * Copyright (C) 2017 - 2018 Andy Green + * Copyright (C) 2010 - 2019 Andy Green * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation: - * version 2.1 of the License. + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to + * deal in the Software without restriction, including without limitation the + * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or + * sell copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: * - * This library is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. * - * You should have received a copy of the GNU Lesser General Public - * License along with this library; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, - * MA 02110-1301 USA + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS + * IN THE SOFTWARE. */ -#include "core/private.h" + +#include "private-lib-core.h" /* * These came from RFC7518 (JSON Web Algorithms) Section 3 @@ -234,6 +238,8 @@ "PS512", NULL, 2048, 4096, 0 }, #endif + /* list terminator */ + { 0, 0, 0, 0, NULL, NULL, 0, 0, 0} }; /* @@ -566,7 +572,7 @@ { 0, 0, 0, 0, NULL, NULL, 0, 0, 0 } /* sentinel */ }; -LWS_VISIBLE int +int lws_gencrypto_jws_alg_to_definition(const char *alg, const struct lws_jose_jwe_alg **jose) { @@ -584,7 +590,7 @@ return 1; } -LWS_VISIBLE int +int lws_gencrypto_jwe_alg_to_definition(const char *alg, const struct lws_jose_jwe_alg **jose) { @@ -602,7 +608,7 @@ return 1; } -LWS_VISIBLE int +int lws_gencrypto_jwe_enc_to_definition(const char *enc, const struct lws_jose_jwe_alg **jose) { @@ -682,3 +688,8 @@ if (el[n].buf) lws_free_set_NULL(el[n].buf); } + +size_t lws_gencrypto_padded_length(size_t pad_block_size, size_t len) +{ + return (len / pad_block_size + 1) * pad_block_size; +} diff -Nru libwebsockets-3.2.1/lib/tls/lws-genec-common.c libwebsockets-4.1.6/lib/tls/lws-genec-common.c --- libwebsockets-3.2.1/lib/tls/lws-genec-common.c 2019-12-18 14:45:31.000000000 +0000 +++ libwebsockets-4.1.6/lib/tls/lws-genec-common.c 2020-12-01 17:40:26.000000000 +0000 @@ -1,27 +1,30 @@ -/* - * libwebsockets - generic EC api hiding the backend - common parts + /* + * libwebsockets - small server side websockets and web server implementation * - * Copyright (C) 2017 - 2019 Andy Green + * Copyright (C) 2010 - 2019 Andy Green * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation: - * version 2.1 of the License. + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to + * deal in the Software without restriction, including without limitation the + * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or + * sell copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: * - * This library is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. * - * You should have received a copy of the GNU Lesser General Public - * License along with this library; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, - * MA 02110-1301 USA + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS + * IN THE SOFTWARE. * * lws_genec provides an EC abstraction api in lws that works the * same whether you are using openssl or mbedtls crypto functions underneath. */ -#include "core/private.h" +#include "private-lib-core.h" const struct lws_ec_curves * lws_genec_curve(const struct lws_ec_curves *table, const char *name) @@ -65,7 +68,7 @@ } lwsl_info("match curve %s\n", lws_ec_curves[n].name); - len = strlen(lws_ec_curves[n].name); + len = (int)strlen(lws_ec_curves[n].name); jwk->e[LWS_GENCRYPTO_EC_KEYEL_CRV].len = len; jwk->e[LWS_GENCRYPTO_EC_KEYEL_CRV].buf = lws_malloc(len + 1, "cert crv"); @@ -95,7 +98,7 @@ return -1; } -LWS_VISIBLE void +void lws_genec_destroy_elements(struct lws_gencrypto_keyelem *el) { int n; @@ -107,7 +110,7 @@ static const char *enames[] = { "crv", "x", "d", "y" }; -LWS_VISIBLE int +int lws_genec_dump(struct lws_gencrypto_keyelem *el) { int n; diff -Nru libwebsockets-3.2.1/lib/tls/mbedtls/CMakeLists.txt libwebsockets-4.1.6/lib/tls/mbedtls/CMakeLists.txt --- libwebsockets-3.2.1/lib/tls/mbedtls/CMakeLists.txt 1970-01-01 00:00:00.000000000 +0000 +++ libwebsockets-4.1.6/lib/tls/mbedtls/CMakeLists.txt 2020-12-01 17:40:26.000000000 +0000 @@ -0,0 +1,130 @@ +# +# libwebsockets - small server side websockets and web server implementation +# +# Copyright (C) 2010 - 2020 Andy Green +# +# Permission is hereby granted, free of charge, to any person obtaining a copy +# of this software and associated documentation files (the "Software"), to +# deal in the Software without restriction, including without limitation the +# rights to use, copy, modify, merge, publish, distribute, sublicense, and/or +# sell copies of the Software, and to permit persons to whom the Software is +# furnished to do so, subject to the following conditions: +# +# The above copyright notice and this permission notice shall be included in +# all copies or substantial portions of the Software. +# +# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING +# FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS +# IN THE SOFTWARE. +# +# The strategy is to only export to PARENT_SCOPE +# +# - changes to LIB_LIST +# - changes to SOURCES +# - includes via include_directories +# +# and keep everything else private + +include_directories(wrapper/include wrapper/include/internal) + + set(LWS_WITH_SSL ON) + + include_directories(wrapper/include) + include_directories(wrapper/include/platform) + include_directories(wrapper/include/internal) + include_directories(wrapper/include/openssl) + + if (LWS_WITH_NETWORK) + list(APPEND HDR_PRIVATE + tls/mbedtls/wrapper/include/internal/ssl3.h + tls/mbedtls/wrapper/include/internal/ssl_cert.h + tls/mbedtls/wrapper/include/internal/ssl_code.h + tls/mbedtls/wrapper/include/internal/ssl_dbg.h + tls/mbedtls/wrapper/include/internal/ssl_lib.h + tls/mbedtls/wrapper/include/internal/ssl_methods.h + tls/mbedtls/wrapper/include/internal/ssl_pkey.h + tls/mbedtls/wrapper/include/internal/ssl_stack.h + tls/mbedtls/wrapper/include/internal/ssl_types.h + tls/mbedtls/wrapper/include/internal/ssl_x509.h + tls/mbedtls/wrapper/include/internal/tls1.h + tls/mbedtls/wrapper/include/internal/x509_vfy.h) + + list(APPEND HDR_PRIVATE + tls/mbedtls/wrapper/include/openssl/ssl.h) + + list(APPEND HDR_PRIVATE + tls/mbedtls/wrapper/include/platform/ssl_pm.h + tls/mbedtls/wrapper/include/platform/ssl_port.h) + + list(APPEND SOURCES + tls/mbedtls/wrapper/library/ssl_cert.c + tls/mbedtls/wrapper/library/ssl_lib.c + tls/mbedtls/wrapper/library/ssl_methods.c + tls/mbedtls/wrapper/library/ssl_pkey.c + tls/mbedtls/wrapper/library/ssl_stack.c + tls/mbedtls/wrapper/library/ssl_x509.c) + + list(APPEND SOURCES + tls/mbedtls/wrapper/platform/ssl_pm.c + tls/mbedtls/wrapper/platform/ssl_port.c) + endif() + + set(_WANT_MBT 0) + if (NOT LWS_PLAT_FREERTOS) + if (NOT DEFINED LWS_MBEDTLS_LIBRARIES) + set(_WANT_MBT 1) + endif() + if (NOT DEFINED LWS_MBEDTLS_INCLUDE_DIRS) + set(_WANT_MBT 1) + endif() + endif() + + if (_WANT_MBT) + + find_path(LWS_MBEDTLS_INCLUDE_DIRS mbedtls/ssl.h) + + find_library(MBEDTLS_LIBRARY mbedtls) + find_library(MBEDX509_LIBRARY mbedx509) + find_library(MBEDCRYPTO_LIBRARY mbedcrypto) + + set(LWS_MBEDTLS_LIBRARIES "${MBEDTLS_LIBRARY}" "${MBEDX509_LIBRARY}" "${MBEDCRYPTO_LIBRARY}") + + include(FindPackageHandleStandardArgs) + find_package_handle_standard_args(MBEDTLS DEFAULT_MSG + LWS_MBEDTLS_INCLUDE_DIRS MBEDTLS_LIBRARY MBEDX509_LIBRARY MBEDCRYPTO_LIBRARY) + + mark_as_advanced(LWS_MBEDTLS_INCLUDE_DIRS MBEDTLS_LIBRARY MBEDX509_LIBRARY MBEDCRYPTO_LIBRARY) + + if ("${LWS_MBEDTLS_LIBRARIES}" STREQUAL "" OR "${LWS_MBEDTLS_INCLUDE_DIRS}" STREQUAL "") + message(FATAL_ERROR "You must set LWS_MBEDTLS_LIBRARIES and LWS_MBEDTLS_INCLUDE_DIRS when LWS_WITH_MBEDTLS is turned on.") + endif() + endif() + if (LWS_MBEDTLS_LIBRARIES) + set(MBEDTLS_LIBRARIES ${LWS_MBEDTLS_LIBRARIES}) + endif() + if (LWS_MBEDTLS_INCLUDE_DIRS) + set(MBEDTLS_INCLUDE_DIRS ${LWS_MBEDTLS_INCLUDE_DIRS}) + endif() + set(USE_MBEDTLS 1 PARENT_SCOPE) + if (DEFINED MBEDTLS_INCLUDE_DIRS) + include_directories(${MBEDTLS_INCLUDE_DIRS}) + endif() + + if (DEFINED MBEDTLS_LIBRARIES) + list(APPEND LIB_LIST ${MBEDTLS_LIBRARIES}) + endif() + +# old mbedtls has everything in mbedtls/net.h + +CHECK_C_SOURCE_COMPILES("#include \nint main(void) { return 0;}\n" LWS_HAVE_MBEDTLS_NET_SOCKETS) + +# +# Keep explicit parent scope exports at end +# + +exports_to_parent_scope() +set(LWS_HAVE_MBEDTLS_NET_SOCKETS ${LWS_HAVE_MBEDTLS_NET_SOCKETS} PARENT_SCOPE) diff -Nru libwebsockets-3.2.1/lib/tls/mbedtls/lws-genaes.c libwebsockets-4.1.6/lib/tls/mbedtls/lws-genaes.c --- libwebsockets-3.2.1/lib/tls/mbedtls/lws-genaes.c 2019-12-18 14:45:31.000000000 +0000 +++ libwebsockets-4.1.6/lib/tls/mbedtls/lws-genaes.c 2020-12-01 17:40:26.000000000 +0000 @@ -1,32 +1,51 @@ -/* - * libwebsockets - generic AES api hiding the backend + /* + * libwebsockets - small server side websockets and web server implementation * - * Copyright (C) 2017 - 2018 Andy Green + * Copyright (C) 2010 - 2019 Andy Green * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation: - * version 2.1 of the License. + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to + * deal in the Software without restriction, including without limitation the + * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or + * sell copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: * - * This library is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. * - * You should have received a copy of the GNU Lesser General Public - * License along with this library; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, - * MA 02110-1301 USA + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS + * IN THE SOFTWARE. * * lws_genaes provides an abstraction api for AES in lws that works the * same whether you are using openssl or mbedtls hash functions underneath. */ -#include "core/private.h" -#include "../../jose/private.h" +#include "private-lib-core.h" +#if defined(LWS_WITH_JOSE) +#include "private-lib-jose.h" +#endif static int operation_map[] = { MBEDTLS_AES_ENCRYPT, MBEDTLS_AES_DECRYPT }; -LWS_VISIBLE int +static unsigned int +_write_pkcs7_pad(uint8_t *p, int len) +{ + unsigned int n = 0, padlen = LWS_AES_CBC_BLOCKLEN * (len / + LWS_AES_CBC_BLOCKLEN + 1) - len; + + p += len; + + while (n++ < padlen) + *p++ = (uint8_t)padlen; + + return padlen; +} + +int lws_genaes_create(struct lws_genaes_ctx *ctx, enum enum_aes_operation op, enum enum_aes_modes mode, struct lws_gencrypto_keyelem *el, enum enum_aes_padding padding, void *engine) @@ -37,6 +56,7 @@ ctx->k = el; ctx->op = operation_map[op]; ctx->underway = 0; + ctx->padding = padding == LWS_GAESP_WITH_PADDING; switch (ctx->mode) { case LWS_GAESM_XTS: @@ -108,10 +128,10 @@ return n; } -LWS_VISIBLE int +int lws_genaes_destroy(struct lws_genaes_ctx *ctx, unsigned char *tag, size_t tlen) { - int n = 0; + int n; if (ctx->mode == LWS_GAESM_GCM) { n = mbedtls_gcm_finish(&ctx->u.ctx_gcm, tag, tlen); @@ -143,6 +163,7 @@ return 0; } +#if defined(LWS_HAVE_mbedtls_internal_aes_encrypt) static int lws_genaes_rfc3394_wrap(int wrap, int cek_bits, const uint8_t *kek, int kek_bits, const uint8_t *in, uint8_t *out) @@ -253,8 +274,9 @@ return ret; } +#endif -LWS_VISIBLE int +int lws_genaes_crypt(struct lws_genaes_ctx *ctx, const uint8_t *in, size_t len, uint8_t *out, uint8_t *iv_or_nonce_ctr_or_data_unit_16, uint8_t *stream_block_16, size_t *nc_or_iv_off, int taglen) @@ -264,6 +286,7 @@ switch (ctx->mode) { case LWS_GAESM_KW: +#if defined(LWS_HAVE_mbedtls_internal_aes_encrypt) /* a key of length ctx->k->len is wrapped by a 128-bit KEK */ n = lws_genaes_rfc3394_wrap(ctx->op == MBEDTLS_AES_ENCRYPT, ctx->op == MBEDTLS_AES_ENCRYPT ? len * 8 : @@ -271,10 +294,39 @@ ctx->k->len * 8, in, out); break; +#else + lwsl_err("%s: your mbedtls is too old\n", __func__); + return -1; +#endif case LWS_GAESM_CBC: memcpy(iv, iv_or_nonce_ctr_or_data_unit_16, 16); - n = mbedtls_aes_crypt_cbc(&ctx->u.ctx, ctx->op, len, iv, - in, out); + + /* + * If encrypting, we do the PKCS#7 padding. + * During decryption, the caller will need to unpad. + */ + if (ctx->padding && ctx->op == MBEDTLS_AES_ENCRYPT) { + /* + * Since we don't want to burden the caller with + * the over-allocation at the end of the input, + * we have to allocate a temp with space for it + */ + uint8_t *padin = (uint8_t *)lws_malloc( + lws_gencrypto_padded_length(LWS_AES_CBC_BLOCKLEN, len), + __func__); + + if (!padin) + return -1; + + memcpy(padin, in, len); + len += _write_pkcs7_pad((uint8_t *)padin, len); + n = mbedtls_aes_crypt_cbc(&ctx->u.ctx, ctx->op, len, iv, + padin, out); + lws_free(padin); + } else + n = mbedtls_aes_crypt_cbc(&ctx->u.ctx, ctx->op, len, iv, + in, out); + break; case LWS_GAESM_CFB128: diff -Nru libwebsockets-3.2.1/lib/tls/mbedtls/lws-gencrypto.c libwebsockets-4.1.6/lib/tls/mbedtls/lws-gencrypto.c --- libwebsockets-3.2.1/lib/tls/mbedtls/lws-gencrypto.c 2019-12-18 14:45:31.000000000 +0000 +++ libwebsockets-4.1.6/lib/tls/mbedtls/lws-gencrypto.c 2020-12-01 17:40:26.000000000 +0000 @@ -1,28 +1,31 @@ -/* - * libwebsockets - generic crypto api hiding the backend + /* + * libwebsockets - small server side websockets and web server implementation * - * Copyright (C) 2017 - 2018 Andy Green + * Copyright (C) 2010 - 2019 Andy Green * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation: - * version 2.1 of the License. + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to + * deal in the Software without restriction, including without limitation the + * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or + * sell copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: * - * This library is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. * - * You should have received a copy of the GNU Lesser General Public - * License along with this library; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, - * MA 02110-1301 USA + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS + * IN THE SOFTWARE. * * lws-gencrypto openssl-specific common code */ -#include "core/private.h" -#include "tls/mbedtls/private.h" +#include "private-lib-core.h" +#include "private-lib-tls-mbedtls.h" mbedtls_md_type_t lws_gencrypto_mbedtls_hash_to_MD_TYPE(enum lws_genhash_types hash_type) diff -Nru libwebsockets-3.2.1/lib/tls/mbedtls/lws-genec.c libwebsockets-4.1.6/lib/tls/mbedtls/lws-genec.c --- libwebsockets-3.2.1/lib/tls/mbedtls/lws-genec.c 2019-12-18 14:45:31.000000000 +0000 +++ libwebsockets-4.1.6/lib/tls/mbedtls/lws-genec.c 2020-12-01 17:40:26.000000000 +0000 @@ -1,28 +1,31 @@ -/* - * libwebsockets - generic EC api hiding the backend - mbedtls implementation + /* + * libwebsockets - small server side websockets and web server implementation * - * Copyright (C) 2017 - 2018 Andy Green + * Copyright (C) 2010 - 2019 Andy Green * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation: - * version 2.1 of the License. + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to + * deal in the Software without restriction, including without limitation the + * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or + * sell copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: * - * This library is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. * - * You should have received a copy of the GNU Lesser General Public - * License along with this library; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, - * MA 02110-1301 USA + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS + * IN THE SOFTWARE. * * lws_genec provides an EC abstraction api in lws that works the * same whether you are using openssl or mbedtls crypto functions underneath. */ -#include "core/private.h" -#include "tls/mbedtls/private.h" +#include "private-lib-core.h" +#include "private-lib-tls-mbedtls.h" const struct lws_ec_curves lws_ec_curves[] = { /* @@ -135,7 +138,7 @@ return ret; } -LWS_VISIBLE int +int lws_genecdh_create(struct lws_genec_ctx *ctx, struct lws_context *context, const struct lws_ec_curves *curve_table) { @@ -154,7 +157,7 @@ return 0; } -LWS_VISIBLE int +int lws_genecdsa_create(struct lws_genec_ctx *ctx, struct lws_context *context, const struct lws_ec_curves *curve_table) { @@ -174,7 +177,7 @@ } -LWS_VISIBLE int +int lws_genecdh_set_key(struct lws_genec_ctx *ctx, struct lws_gencrypto_keyelem *el, enum enum_lws_dh_side side) { @@ -184,7 +187,7 @@ return lws_genec_keypair_import(ctx, side, el); } -LWS_VISIBLE int +int lws_genecdsa_set_key(struct lws_genec_ctx *ctx, struct lws_gencrypto_keyelem *el) { @@ -194,7 +197,7 @@ return lws_genec_keypair_import(ctx, 0, el); } -LWS_VISIBLE void +void lws_genec_destroy(struct lws_genec_ctx *ctx) { switch (ctx->genec_alg) { @@ -217,7 +220,7 @@ } } -LWS_VISIBLE int +int lws_genecdh_new_keypair(struct lws_genec_ctx *ctx, enum enum_lws_dh_side side, const char *curve_name, struct lws_gencrypto_keyelem *el) @@ -301,7 +304,7 @@ return -1; } -LWS_VISIBLE int +int lws_genecdsa_new_keypair(struct lws_genec_ctx *ctx, const char *curve_name, struct lws_gencrypto_keyelem *el) { @@ -374,7 +377,7 @@ return -1; } -LWS_VISIBLE LWS_EXTERN int +int lws_genecdsa_hash_sign_jws(struct lws_genec_ctx *ctx, const uint8_t *in, enum lws_genhash_types hash_type, int keybits, uint8_t *sig, size_t sig_len) @@ -436,7 +439,7 @@ return -3; } -LWS_VISIBLE LWS_EXTERN int +int lws_genecdsa_hash_sig_verify_jws(struct lws_genec_ctx *ctx, const uint8_t *in, enum lws_genhash_types hash_type, int keybits, const uint8_t *sig, size_t sig_len) diff -Nru libwebsockets-3.2.1/lib/tls/mbedtls/lws-genhash.c libwebsockets-4.1.6/lib/tls/mbedtls/lws-genhash.c --- libwebsockets-3.2.1/lib/tls/mbedtls/lws-genhash.c 2019-12-18 14:45:31.000000000 +0000 +++ libwebsockets-4.1.6/lib/tls/mbedtls/lws-genhash.c 2020-12-01 17:40:26.000000000 +0000 @@ -1,22 +1,25 @@ -/* - * libwebsockets - generic hash and HMAC api hiding the backend + /* + * libwebsockets - small server side websockets and web server implementation * - * Copyright (C) 2017 Andy Green + * Copyright (C) 2010 - 2019 Andy Green * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation: - * version 2.1 of the License. + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to + * deal in the Software without restriction, including without limitation the + * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or + * sell copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: * - * This library is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. * - * You should have received a copy of the GNU Lesser General Public - * License along with this library; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, - * MA 02110-1301 USA + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS + * IN THE SOFTWARE. * * lws_genhash provides a hash / hmac abstraction api in lws that works the * same whether you are using openssl or mbedtls hash functions underneath. @@ -25,10 +28,120 @@ #include #if (MBEDTLS_VERSION_NUMBER >= 0x02070000) -#define MBA(fn) fn##_ret + +/* + * We have the _ret variants available, check the return codes on everything + */ + +int +lws_genhash_init(struct lws_genhash_ctx *ctx, enum lws_genhash_types type) +{ + ctx->type = type; + + switch (ctx->type) { + case LWS_GENHASH_TYPE_MD5: + mbedtls_md5_init(&ctx->u.md5); + if (mbedtls_md5_starts_ret(&ctx->u.md5)) + return 1; + break; + case LWS_GENHASH_TYPE_SHA1: + mbedtls_sha1_init(&ctx->u.sha1); + if (mbedtls_sha1_starts_ret(&ctx->u.sha1)) + return 1; + break; + case LWS_GENHASH_TYPE_SHA256: + mbedtls_sha256_init(&ctx->u.sha256); + if (mbedtls_sha256_starts_ret(&ctx->u.sha256, 0)) + return 1; + break; + case LWS_GENHASH_TYPE_SHA384: + mbedtls_sha512_init(&ctx->u.sha512); + if (mbedtls_sha512_starts_ret(&ctx->u.sha512, 1 /* is384 */)) + return 1; + break; + case LWS_GENHASH_TYPE_SHA512: + mbedtls_sha512_init(&ctx->u.sha512); + if (mbedtls_sha512_starts_ret(&ctx->u.sha512, 0)) + return 1; + break; + default: + return 1; + } + + return 0; +} + +int +lws_genhash_update(struct lws_genhash_ctx *ctx, const void *in, size_t len) +{ + if (!len) + return 0; + + switch (ctx->type) { + case LWS_GENHASH_TYPE_MD5: + if (mbedtls_md5_update_ret(&ctx->u.md5, in, len)) + return 1; + break; + case LWS_GENHASH_TYPE_SHA1: + if (mbedtls_sha1_update_ret(&ctx->u.sha1, in, len)) + return 1; + break; + case LWS_GENHASH_TYPE_SHA256: + if (mbedtls_sha256_update_ret(&ctx->u.sha256, in, len)) + return 1; + break; + case LWS_GENHASH_TYPE_SHA384: + if (mbedtls_sha512_update_ret(&ctx->u.sha512, in, len)) + return 1; + break; + case LWS_GENHASH_TYPE_SHA512: + if (mbedtls_sha512_update_ret(&ctx->u.sha512, in, len)) + return 1; + break; + } + + return 0; +} + +int +lws_genhash_destroy(struct lws_genhash_ctx *ctx, void *result) +{ + switch (ctx->type) { + case LWS_GENHASH_TYPE_MD5: + if (mbedtls_md5_finish_ret(&ctx->u.md5, result)) + return 1; + mbedtls_md5_free(&ctx->u.md5); + break; + case LWS_GENHASH_TYPE_SHA1: + if (mbedtls_sha1_finish_ret(&ctx->u.sha1, result)) + return 1; + mbedtls_sha1_free(&ctx->u.sha1); + break; + case LWS_GENHASH_TYPE_SHA256: + if (mbedtls_sha256_finish_ret(&ctx->u.sha256, result)) + return 1; + mbedtls_sha256_free(&ctx->u.sha256); + break; + case LWS_GENHASH_TYPE_SHA384: + if (mbedtls_sha512_finish_ret(&ctx->u.sha512, result)) + return 1; + mbedtls_sha512_free(&ctx->u.sha512); + break; + case LWS_GENHASH_TYPE_SHA512: + if (mbedtls_sha512_finish_ret(&ctx->u.sha512, result)) + return 1; + mbedtls_sha512_free(&ctx->u.sha512); + break; + } + + return 0; +} + #else -#define MBA(fn) fn -#endif + +/* + * mbedtls is too old to have the _ret variants + */ int lws_genhash_init(struct lws_genhash_ctx *ctx, enum lws_genhash_types type) @@ -38,23 +151,23 @@ switch (ctx->type) { case LWS_GENHASH_TYPE_MD5: mbedtls_md5_init(&ctx->u.md5); - MBA(mbedtls_md5_starts)(&ctx->u.md5); + mbedtls_md5_starts(&ctx->u.md5); break; case LWS_GENHASH_TYPE_SHA1: mbedtls_sha1_init(&ctx->u.sha1); - MBA(mbedtls_sha1_starts)(&ctx->u.sha1); + mbedtls_sha1_starts(&ctx->u.sha1); break; case LWS_GENHASH_TYPE_SHA256: mbedtls_sha256_init(&ctx->u.sha256); - MBA(mbedtls_sha256_starts)(&ctx->u.sha256, 0); + mbedtls_sha256_starts(&ctx->u.sha256, 0); break; case LWS_GENHASH_TYPE_SHA384: mbedtls_sha512_init(&ctx->u.sha512); - MBA(mbedtls_sha512_starts)(&ctx->u.sha512, 1 /* is384 */); + mbedtls_sha512_starts(&ctx->u.sha512, 1 /* is384 */); break; case LWS_GENHASH_TYPE_SHA512: mbedtls_sha512_init(&ctx->u.sha512); - MBA(mbedtls_sha512_starts)(&ctx->u.sha512, 0); + mbedtls_sha512_starts(&ctx->u.sha512, 0); break; default: return 1; @@ -71,19 +184,19 @@ switch (ctx->type) { case LWS_GENHASH_TYPE_MD5: - MBA(mbedtls_md5_update)(&ctx->u.md5, in, len); + mbedtls_md5_update(&ctx->u.md5, in, len); break; case LWS_GENHASH_TYPE_SHA1: - MBA(mbedtls_sha1_update)(&ctx->u.sha1, in, len); + mbedtls_sha1_update(&ctx->u.sha1, in, len); break; case LWS_GENHASH_TYPE_SHA256: - MBA(mbedtls_sha256_update)(&ctx->u.sha256, in, len); + mbedtls_sha256_update(&ctx->u.sha256, in, len); break; case LWS_GENHASH_TYPE_SHA384: - MBA(mbedtls_sha512_update)(&ctx->u.sha512, in, len); + mbedtls_sha512_update(&ctx->u.sha512, in, len); break; case LWS_GENHASH_TYPE_SHA512: - MBA(mbedtls_sha512_update)(&ctx->u.sha512, in, len); + mbedtls_sha512_update(&ctx->u.sha512, in, len); break; } @@ -95,23 +208,23 @@ { switch (ctx->type) { case LWS_GENHASH_TYPE_MD5: - MBA(mbedtls_md5_finish)(&ctx->u.md5, result); + mbedtls_md5_finish(&ctx->u.md5, result); mbedtls_md5_free(&ctx->u.md5); break; case LWS_GENHASH_TYPE_SHA1: - MBA(mbedtls_sha1_finish)(&ctx->u.sha1, result); + mbedtls_sha1_finish(&ctx->u.sha1, result); mbedtls_sha1_free(&ctx->u.sha1); break; case LWS_GENHASH_TYPE_SHA256: - MBA(mbedtls_sha256_finish)(&ctx->u.sha256, result); + mbedtls_sha256_finish(&ctx->u.sha256, result); mbedtls_sha256_free(&ctx->u.sha256); break; case LWS_GENHASH_TYPE_SHA384: - MBA(mbedtls_sha512_finish)(&ctx->u.sha512, result); + mbedtls_sha512_finish(&ctx->u.sha512, result); mbedtls_sha512_free(&ctx->u.sha512); break; case LWS_GENHASH_TYPE_SHA512: - MBA(mbedtls_sha512_finish)(&ctx->u.sha512, result); + mbedtls_sha512_finish(&ctx->u.sha512, result); mbedtls_sha512_free(&ctx->u.sha512); break; } @@ -119,6 +232,8 @@ return 0; } +#endif + int lws_genhmac_init(struct lws_genhmac_ctx *ctx, enum lws_genhmac_types type, const uint8_t *key, size_t key_len) @@ -145,8 +260,13 @@ if (!ctx->hmac) return -1; +#if !defined(LWS_HAVE_mbedtls_md_setup) if (mbedtls_md_init_ctx(&ctx->ctx, ctx->hmac)) return -1; +#else + if (mbedtls_md_setup(&ctx->ctx, ctx->hmac, 1)) + return -1; +#endif if (mbedtls_md_hmac_starts(&ctx->ctx, key, key_len)) { mbedtls_md_free(&ctx->ctx); diff -Nru libwebsockets-3.2.1/lib/tls/mbedtls/lws-genrsa.c libwebsockets-4.1.6/lib/tls/mbedtls/lws-genrsa.c --- libwebsockets-3.2.1/lib/tls/mbedtls/lws-genrsa.c 2019-12-18 14:45:31.000000000 +0000 +++ libwebsockets-4.1.6/lib/tls/mbedtls/lws-genrsa.c 2020-12-01 17:40:26.000000000 +0000 @@ -1,31 +1,34 @@ -/* - * libwebsockets - generic RSA api hiding the backend + /* + * libwebsockets - small server side websockets and web server implementation * - * Copyright (C) 2017 - 2018 Andy Green + * Copyright (C) 2010 - 2019 Andy Green * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation: - * version 2.1 of the License. + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to + * deal in the Software without restriction, including without limitation the + * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or + * sell copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: * - * This library is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. * - * You should have received a copy of the GNU Lesser General Public - * License along with this library; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, - * MA 02110-1301 USA + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS + * IN THE SOFTWARE. * * lws_genrsa provides an RSA abstraction api in lws that works the * same whether you are using openssl or mbedtls crypto functions underneath. */ -#include "core/private.h" -#include "tls/mbedtls/private.h" +#include "private-lib-core.h" +#include "private-lib-tls-mbedtls.h" #include -LWS_VISIBLE void +void lws_genrsa_destroy_elements(struct lws_gencrypto_keyelem *el) { int n; @@ -37,7 +40,7 @@ static int mode_map[] = { MBEDTLS_RSA_PKCS_V15, MBEDTLS_RSA_PKCS_V21 }; -LWS_VISIBLE int +int lws_genrsa_create(struct lws_genrsa_ctx *ctx, struct lws_gencrypto_keyelem *el, struct lws_context *context, enum enum_genrsa_mode mode, enum lws_genhash_types oaep_hashid) @@ -82,8 +85,13 @@ if ( el[LWS_GENCRYPTO_RSA_KEYEL_D].len && !el[LWS_GENCRYPTO_RSA_KEYEL_P].len && !el[LWS_GENCRYPTO_RSA_KEYEL_Q].len) { +#if defined(LWS_HAVE_mbedtls_rsa_complete) if (mbedtls_rsa_complete(ctx->ctx)) { lwsl_notice("mbedtls_rsa_complete failed\n"); +#else + { + lwsl_notice("%s: you have to provide P and Q\n", __func__); +#endif lws_free_set_NULL(ctx->ctx); return -1; @@ -106,7 +114,7 @@ return -1; } -LWS_VISIBLE int +int lws_genrsa_new_keypair(struct lws_context *context, struct lws_genrsa_ctx *ctx, enum enum_genrsa_mode mode, struct lws_gencrypto_keyelem *el, int bits) @@ -164,7 +172,7 @@ return -1; } -LWS_VISIBLE int +int lws_genrsa_public_decrypt(struct lws_genrsa_ctx *ctx, const uint8_t *in, size_t in_len, uint8_t *out, size_t out_max) { @@ -173,7 +181,9 @@ ctx->ctx->len = in_len; +#if defined(LWS_HAVE_mbedtls_rsa_complete) mbedtls_rsa_complete(ctx->ctx); +#endif switch(ctx->mode) { case LGRSAM_PKCS1_1_5: @@ -202,7 +212,7 @@ return olen; } -LWS_VISIBLE int +int lws_genrsa_private_decrypt(struct lws_genrsa_ctx *ctx, const uint8_t *in, size_t in_len, uint8_t *out, size_t out_max) { @@ -211,7 +221,9 @@ ctx->ctx->len = in_len; +#if defined(LWS_HAVE_mbedtls_rsa_complete) mbedtls_rsa_complete(ctx->ctx); +#endif switch(ctx->mode) { case LGRSAM_PKCS1_1_5: @@ -240,13 +252,15 @@ return olen; } -LWS_VISIBLE int +int lws_genrsa_public_encrypt(struct lws_genrsa_ctx *ctx, const uint8_t *in, size_t in_len, uint8_t *out) { int n; +#if defined(LWS_HAVE_mbedtls_rsa_complete) mbedtls_rsa_complete(ctx->ctx); +#endif switch(ctx->mode) { case LGRSAM_PKCS1_1_5: @@ -275,13 +289,15 @@ return mbedtls_mpi_size(&ctx->ctx->N); } -LWS_VISIBLE int +int lws_genrsa_private_encrypt(struct lws_genrsa_ctx *ctx, const uint8_t *in, size_t in_len, uint8_t *out) { int n; +#if defined(LWS_HAVE_mbedtls_rsa_complete) mbedtls_rsa_complete(ctx->ctx); +#endif switch(ctx->mode) { case LGRSAM_PKCS1_1_5: @@ -310,7 +326,7 @@ return mbedtls_mpi_size(&ctx->ctx->N); } -LWS_VISIBLE int +int lws_genrsa_hash_sig_verify(struct lws_genrsa_ctx *ctx, const uint8_t *in, enum lws_genhash_types hash_type, const uint8_t *sig, size_t sig_len) @@ -320,7 +336,9 @@ if (h < 0) return -1; +#if defined(LWS_HAVE_mbedtls_rsa_complete) mbedtls_rsa_complete(ctx->ctx); +#endif switch(ctx->mode) { case LGRSAM_PKCS1_1_5: @@ -345,7 +363,7 @@ return n; } -LWS_VISIBLE int +int lws_genrsa_hash_sign(struct lws_genrsa_ctx *ctx, const uint8_t *in, enum lws_genhash_types hash_type, uint8_t *sig, size_t sig_len) @@ -355,7 +373,9 @@ if (h < 0) return -1; +#if defined(LWS_HAVE_mbedtls_rsa_complete) mbedtls_rsa_complete(ctx->ctx); +#endif /* * The "sig" buffer must be as large as the size of ctx->N @@ -388,7 +408,7 @@ return ctx->ctx->len; } -LWS_VISIBLE int +int lws_genrsa_render_pkey_asn1(struct lws_genrsa_ctx *ctx, int _private, uint8_t *pkey_asn1, size_t pkey_asn1_len) { @@ -468,7 +488,7 @@ return n; } -LWS_VISIBLE void +void lws_genrsa_destroy(struct lws_genrsa_ctx *ctx) { if (!ctx->ctx) diff -Nru libwebsockets-3.2.1/lib/tls/mbedtls/mbedtls-client.c libwebsockets-4.1.6/lib/tls/mbedtls/mbedtls-client.c --- libwebsockets-3.2.1/lib/tls/mbedtls/mbedtls-client.c 2019-12-18 14:45:31.000000000 +0000 +++ libwebsockets-4.1.6/lib/tls/mbedtls/mbedtls-client.c 2020-12-01 17:40:26.000000000 +0000 @@ -1,25 +1,28 @@ /* - * libwebsockets - mbedtls-specific client TLS code + * libwebsockets - small server side websockets and web server implementation * - * Copyright (C) 2010-2017 Andy Green + * Copyright (C) 2010 - 2020 Andy Green * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation: - * version 2.1 of the License. + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to + * deal in the Software without restriction, including without limitation the + * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or + * sell copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: * - * This library is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. * - * You should have received a copy of the GNU Lesser General Public - * License along with this library; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, - * MA 02110-1301 USA + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS + * IN THE SOFTWARE. */ -#include "core/private.h" +#include "private-lib-core.h" static int OpenSSL_client_verify_callback(int preverify_ok, X509_STORE_CTX *x509_ctx) @@ -31,15 +34,18 @@ lws_ssl_client_bio_create(struct lws *wsi) { char hostname[128], *p; - const char *alpn_comma = wsi->context->tls.alpn_default; + const char *alpn_comma = wsi->a.context->tls.alpn_default; struct alpn_ctx protos; - if (lws_hdr_copy(wsi, hostname, sizeof(hostname), - _WSI_TOKEN_CLIENT_HOST) <= 0) { - lwsl_err("%s: Unable to get hostname\n", __func__); + if (wsi->stash) + lws_strncpy(hostname, wsi->stash->cis[CIS_HOST], sizeof(hostname)); + else + if (lws_hdr_copy(wsi, hostname, sizeof(hostname), + _WSI_TOKEN_CLIENT_HOST) <= 0) { + lwsl_err("%s: Unable to get hostname\n", __func__); - return -1; - } + return -1; + } /* * remove any :port part on the hostname... necessary for network @@ -54,13 +60,13 @@ p++; } - wsi->tls.ssl = SSL_new(wsi->vhost->tls.ssl_client_ctx); + wsi->tls.ssl = SSL_new(wsi->a.vhost->tls.ssl_client_ctx); if (!wsi->tls.ssl) { lwsl_info("%s: SSL_new() failed\n", __func__); return -1; } - if (wsi->vhost->tls.ssl_info_event_mask) + if (wsi->a.vhost->tls.ssl_info_event_mask) SSL_set_info_callback(wsi->tls.ssl, lws_ssl_info_callback); if (!(wsi->tls.use_ssl & LCCSCF_SKIP_SERVER_CERT_HOSTNAME_CHECK)) { @@ -71,12 +77,17 @@ X509_VERIFY_PARAM_set1_host(param, hostname, 0); } - if (wsi->vhost->tls.alpn) - alpn_comma = wsi->vhost->tls.alpn; + if (wsi->a.vhost->tls.alpn) + alpn_comma = wsi->a.vhost->tls.alpn; - if (lws_hdr_copy(wsi, hostname, sizeof(hostname), - _WSI_TOKEN_CLIENT_ALPN) > 0) - alpn_comma = hostname; + if (wsi->stash) { + lws_strncpy(hostname, wsi->stash->cis[CIS_HOST], sizeof(hostname)); + alpn_comma = wsi->stash->cis[CIS_ALPN]; + } else { + if (lws_hdr_copy(wsi, hostname, sizeof(hostname), + _WSI_TOKEN_CLIENT_ALPN) > 0) + alpn_comma = hostname; + } lwsl_info("%s: %p: client conn sending ALPN list '%s'\n", __func__, wsi, alpn_comma); @@ -96,7 +107,77 @@ SSL_set_fd(wsi->tls.ssl, wsi->desc.sockfd); + if (wsi->sys_tls_client_cert) { + lws_system_blob_t *b = lws_system_get_blob(wsi->a.context, + LWS_SYSBLOB_TYPE_CLIENT_CERT_DER, + wsi->sys_tls_client_cert - 1); + const uint8_t *pem_data = NULL; + uint8_t *data = NULL; + lws_filepos_t flen; + size_t size; + int err = 0; + + if (!b) + goto no_client_cert; + + /* + * Set up the per-connection client cert + */ + + size = lws_system_blob_get_size(b); + if (!size) + goto no_client_cert; + + if (lws_system_blob_get_single_ptr(b, &pem_data)) + goto no_client_cert; + + if (lws_tls_alloc_pem_to_der_file(wsi->a.context, NULL, + (const char *)pem_data, size, + &data, &flen)) + goto no_client_cert; + size = (size_t) flen; + + err = SSL_use_certificate_ASN1(wsi->tls.ssl, data, size); + lws_free_set_NULL(data); + if (err != 1) + goto no_client_cert; + + b = lws_system_get_blob(wsi->a.context, + LWS_SYSBLOB_TYPE_CLIENT_KEY_DER, + wsi->sys_tls_client_cert - 1); + if (!b) + goto no_client_cert; + size = lws_system_blob_get_size(b); + if (!size) + goto no_client_cert; + + if (lws_system_blob_get_single_ptr(b, &pem_data)) + goto no_client_cert; + + if (lws_tls_alloc_pem_to_der_file(wsi->a.context, NULL, + (const char *)pem_data, size, + &data, &flen)) + goto no_client_cert; + size = (size_t) flen; + + err = SSL_use_PrivateKey_ASN1(0, wsi->tls.ssl, data, size); + lws_free_set_NULL(data); + if (err != 1) + goto no_client_cert; + + /* no wrapper api for check key */ + + lwsl_notice("%s: set system client cert %u\n", __func__, + wsi->sys_tls_client_cert - 1); + } + return 0; + +no_client_cert: + lwsl_err("%s: unable to set up system client cert %d\n", __func__, + wsi->sys_tls_client_cert - 1); + + return 1; } int ERR_get_error(void) @@ -105,7 +186,7 @@ } enum lws_ssl_capable_status -lws_tls_client_connect(struct lws *wsi) +lws_tls_client_connect(struct lws *wsi, char *errbuf, int elen) { int m, n = SSL_connect(wsi->tls.ssl); const unsigned char *prot; @@ -129,6 +210,8 @@ if (!n) /* we don't know what he wants, but he says to retry */ return LWS_SSL_CAPABLE_MORE_SERVICE; + lws_snprintf(errbuf, elen, "mbedtls connect %d %d %d", n, m, errno); + return LWS_SSL_CAPABLE_ERROR; } @@ -137,7 +220,7 @@ { int n; X509 *peer = SSL_get_peer_certificate(wsi->tls.ssl); - struct lws_context_per_thread *pt = &wsi->context->pt[(int)wsi->tsi]; + struct lws_context_per_thread *pt = &wsi->a.context->pt[(int)wsi->tsi]; char *sb = (char *)&pt->serv_buf[0]; if (!peer) { @@ -149,9 +232,6 @@ lwsl_info("peer provided cert\n"); n = SSL_get_verify_result(wsi->tls.ssl); - lws_latency(wsi->context, wsi, - "SSL_get_verify_result LWS_CONNMODE..HANDSHAKE", n, n > 0); - lwsl_debug("get_verify says %d\n", n); if (n == X509_V_OK) @@ -177,8 +257,8 @@ return 0; } lws_snprintf(ebuf, ebuf_len, - "server's cert didn't look good, X509_V_ERR = %d: %s\n", - n, ERR_error_string(n, sb)); + "server's cert didn't look good, (use_ssl 0x%x) X509_V_ERR = %d: %s\n", + (unsigned int)wsi->tls.use_ssl, n, ERR_error_string(n, sb)); lwsl_info("%s\n", ebuf); lws_tls_err_describe_clear(); @@ -195,7 +275,10 @@ const char *cert_filepath, const void *cert_mem, unsigned int cert_mem_len, - const char *private_key_filepath) + const char *private_key_filepath, + const void *key_mem, + unsigned int key_mem_len + ) { X509 *d2i_X509(X509 **cert, const unsigned char *buffer, long len); SSL_METHOD *method = (SSL_METHOD *)TLS_client_method(); @@ -286,13 +369,13 @@ lwsl_notice("Loaded client cert %s\n", cert_filepath); #endif } else if (cert_mem && cert_mem_len) { - // lwsl_hexdump_notice(cert_mem, cert_mem_len - 1); + /* lwsl_hexdump_notice(cert_mem, cert_mem_len - 1); */ SSL_CTX_use_PrivateKey_ASN1(0, vh->tls.ssl_client_ctx, cert_mem, cert_mem_len - 1); n = SSL_CTX_use_certificate_ASN1(vh->tls.ssl_client_ctx, cert_mem_len, cert_mem); if (n < 1) { - lwsl_err("%s: problem interpreting client cert\n", + lwsl_err("%s: (mbedtls) problem interpreting client cert\n", __func__); lws_tls_err_describe_clear(); return 1; @@ -303,3 +386,16 @@ return 0; } + +int +lws_tls_client_vhost_extra_cert_mem(struct lws_vhost *vh, + const uint8_t *der, size_t der_len) +{ + if (SSL_CTX_add_client_CA_ASN1(vh->tls.ssl_client_ctx, der_len, der) != 1) { + lwsl_err("%s: failed\n", __func__); + return 1; + } + + return 0; +} + diff -Nru libwebsockets-3.2.1/lib/tls/mbedtls/mbedtls-server.c libwebsockets-4.1.6/lib/tls/mbedtls/mbedtls-server.c --- libwebsockets-3.2.1/lib/tls/mbedtls/mbedtls-server.c 2019-12-18 14:45:31.000000000 +0000 +++ libwebsockets-4.1.6/lib/tls/mbedtls/mbedtls-server.c 2020-12-01 17:40:26.000000000 +0000 @@ -1,26 +1,30 @@ /* - * libwebsockets - mbedTLS-specific server functions + * libwebsockets - small server side websockets and web server implementation * - * Copyright (C) 2010-2017 Andy Green + * Copyright (C) 2010 - 2019 Andy Green * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation: - * version 2.1 of the License. + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to + * deal in the Software without restriction, including without limitation the + * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or + * sell copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: * - * This library is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. * - * You should have received a copy of the GNU Lesser General Public - * License along with this library; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, - * MA 02110-1301 USA + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS + * IN THE SOFTWARE. */ -#include "core/private.h" +#include "private-lib-core.h" #include +#include int lws_tls_server_client_cert_verify_config(struct lws_vhost *vh) @@ -149,9 +153,6 @@ */ cert = NULL; private_key = NULL; - - if (!mem_cert) - return 1; } if (lws_tls_alloc_pem_to_der_file(vhost->context, cert, mem_cert, mem_cert_len, &p, &flen)) { @@ -183,14 +184,6 @@ return 1; } - if (!private_key && !mem_privkey && vhost->protocols[0].callback(wsi, - LWS_CALLBACK_OPENSSL_CONTEXT_REQUIRES_PRIVATE_KEY, - vhost->tls.ssl_ctx, NULL, 0)) { - lwsl_err("ssl private key not set\n"); - - return 1; - } - vhost->tls.skipped_certs = 0; return 0; @@ -261,7 +254,7 @@ lws_tls_server_new_nonblocking(struct lws *wsi, lws_sockfd_type accept_fd) { errno = 0; - wsi->tls.ssl = SSL_new(wsi->vhost->tls.ssl_ctx); + wsi->tls.ssl = SSL_new(wsi->a.vhost->tls.ssl_ctx); if (wsi->tls.ssl == NULL) { lwsl_err("SSL_new failed: errno %d\n", errno); @@ -271,10 +264,10 @@ SSL_set_fd(wsi->tls.ssl, accept_fd); - if (wsi->vhost->tls.ssl_info_event_mask) + if (wsi->a.vhost->tls.ssl_info_event_mask) SSL_set_info_callback(wsi->tls.ssl, lws_ssl_info_callback); - SSL_set_sni_callback(wsi->tls.ssl, lws_mbedtls_sni_cb, wsi->context); + SSL_set_sni_callback(wsi->tls.ssl, lws_mbedtls_sni_cb, wsi->a.context); return 0; } @@ -299,9 +292,11 @@ int m, n; n = SSL_accept(wsi->tls.ssl); + + wsi->skip_fallback = 1; if (n == 1) { - if (strstr(wsi->vhost->name, ".invalid")) { + if (strstr(wsi->a.vhost->name, ".invalid")) { lwsl_notice("%s: vhost has .invalid, " "rejecting accept\n", __func__); @@ -320,13 +315,18 @@ } m = SSL_get_error(wsi->tls.ssl, n); - lwsl_debug("%s: %p: accept SSL_get_error %d errno %d\n", __func__, + lwsl_notice("%s: %p: accept SSL_get_error %d errno %d\n", __func__, wsi, m, errno); // mbedtls wrapper only if (m == SSL_ERROR_SYSCALL && errno == 11) return LWS_SSL_CAPABLE_MORE_SERVICE_READ; +#if defined(__APPLE__) + if (m == SSL_ERROR_SYSCALL && errno == 35) + return LWS_SSL_CAPABLE_MORE_SERVICE_READ; +#endif + #if defined(WIN32) if (m == SSL_ERROR_SYSCALL && errno == 0) return LWS_SSL_CAPABLE_MORE_SERVICE_READ; @@ -459,14 +459,14 @@ #define SAN_A_LENGTH 78 -LWS_VISIBLE int +int lws_tls_acme_sni_cert_create(struct lws_vhost *vhost, const char *san_a, const char *san_b) { int buflen = 0x560; uint8_t *buf = lws_malloc(buflen, "tmp cert buf"), *p = buf, *pkey_asn1; struct lws_genrsa_ctx ctx; - struct lws_gencrypto_keyelem el; + struct lws_gencrypto_keyelem el[LWS_GENCRYPTO_RSA_KEYEL_COUNT]; uint8_t digest[32]; struct lws_genhash_ctx hash_ctx; int pkey_asn1_len = 3 * 1024; @@ -475,9 +475,10 @@ if (!buf) return 1; - n = lws_genrsa_new_keypair(vhost->context, &ctx, &el, keybits); + n = lws_genrsa_new_keypair(vhost->context, &ctx, LGRSAM_PKCS1_1_5, + &el[0], keybits); if (n < 0) { - lws_genrsa_destroy_elements(&el); + lws_genrsa_destroy_elements(&el[0]); goto bail1; } @@ -511,8 +512,8 @@ /* we need to drop 1 + (keybits / 8) bytes of n in here, 00 + key */ *p++ = 0x00; - memcpy(p, el.e[LWS_GENCRYPTO_RSA_KEYEL_N].buf, el.e[LWS_GENCRYPTO_RSA_KEYEL_N].len); - p += el.e[LWS_GENCRYPTO_RSA_KEYEL_N].len; + memcpy(p, el[LWS_GENCRYPTO_RSA_KEYEL_N].buf, el[LWS_GENCRYPTO_RSA_KEYEL_N].len); + p += el[LWS_GENCRYPTO_RSA_KEYEL_N].len; memcpy(p, ss_cert_san_leadin, sizeof(ss_cert_san_leadin)); p += sizeof(ss_cert_san_leadin); @@ -581,7 +582,7 @@ } lws_genrsa_destroy(&ctx); - lws_genrsa_destroy_elements(&el); + lws_genrsa_destroy_elements(&el[0]); lws_free(buf); @@ -589,7 +590,7 @@ bail2: lws_genrsa_destroy(&ctx); - lws_genrsa_destroy_elements(&el); + lws_genrsa_destroy_elements(&el[0]); bail1: lws_free(buf); @@ -617,7 +618,7 @@ * CSR is output formatted as b64url(DER) * Private key is output as a PEM in memory */ -LWS_VISIBLE LWS_EXTERN int +int lws_tls_acme_sni_csr_create(struct lws_context *context, const char *elements[], uint8_t *dcsr, size_t csr_len, char **privkey_pem, size_t *privkey_len) diff -Nru libwebsockets-3.2.1/lib/tls/mbedtls/mbedtls-ssl.c libwebsockets-4.1.6/lib/tls/mbedtls/mbedtls-ssl.c --- libwebsockets-3.2.1/lib/tls/mbedtls/mbedtls-ssl.c 1970-01-01 00:00:00.000000000 +0000 +++ libwebsockets-4.1.6/lib/tls/mbedtls/mbedtls-ssl.c 2020-12-01 17:40:26.000000000 +0000 @@ -0,0 +1,343 @@ +/* + * libwebsockets - small server side websockets and web server implementation + * + * Copyright (C) 2010 - 2019 Andy Green + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to + * deal in the Software without restriction, including without limitation the + * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or + * sell copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS + * IN THE SOFTWARE. + */ + +#include "private-lib-core.h" +#include "private-lib-tls-mbedtls.h" + +void +lws_ssl_destroy(struct lws_vhost *vhost) +{ + if (!lws_check_opt(vhost->context->options, + LWS_SERVER_OPTION_DO_SSL_GLOBAL_INIT)) + return; + + if (vhost->tls.ssl_ctx) + SSL_CTX_free(vhost->tls.ssl_ctx); + if (!vhost->tls.user_supplied_ssl_ctx && vhost->tls.ssl_client_ctx) + SSL_CTX_free(vhost->tls.ssl_client_ctx); + + if (vhost->tls.x509_client_CA) + X509_free(vhost->tls.x509_client_CA); +} + +int +lws_ssl_capable_read(struct lws *wsi, unsigned char *buf, int len) +{ + struct lws_context *context = wsi->a.context; + struct lws_context_per_thread *pt = &context->pt[(int)wsi->tsi]; + int n = 0, m; + + if (!wsi->tls.ssl) + return lws_ssl_capable_read_no_ssl(wsi, buf, len); + + lws_stats_bump(pt, LWSSTATS_C_API_READ, 1); + + errno = 0; + n = SSL_read(wsi->tls.ssl, buf, len); +#if defined(LWS_PLAT_FREERTOS) + if (!n && errno == LWS_ENOTCONN) { + lwsl_debug("%p: SSL_read ENOTCONN\n", wsi); + return LWS_SSL_CAPABLE_ERROR; + } +#endif +#if defined(LWS_WITH_STATS) + if (!wsi->seen_rx && wsi->accept_start_us) { + lws_stats_bump(pt, LWSSTATS_US_SSL_RX_DELAY_AVG, + lws_now_usecs() - wsi->accept_start_us); + lws_stats_bump(pt, LWSSTATS_C_SSL_CONNS_HAD_RX, 1); + wsi->seen_rx = 1; + } +#endif + + + lwsl_debug("%p: SSL_read says %d\n", wsi, n); + /* manpage: returning 0 means connection shut down */ + if (!n) { + wsi->socket_is_permanently_unusable = 1; + + return LWS_SSL_CAPABLE_ERROR; + } + + if (n < 0) { + m = SSL_get_error(wsi->tls.ssl, n); + lwsl_debug("%p: ssl err %d errno %d\n", wsi, m, errno); + if (errno == LWS_ENOTCONN) { + /* If the socket isn't connected anymore, bail out. */ + wsi->socket_is_permanently_unusable = 1; + return LWS_SSL_CAPABLE_ERROR; + } + if (m == SSL_ERROR_ZERO_RETURN || + m == SSL_ERROR_SYSCALL) + return LWS_SSL_CAPABLE_ERROR; + + if (m == SSL_ERROR_WANT_READ || SSL_want_read(wsi->tls.ssl)) { + lwsl_debug("%s: WANT_READ\n", __func__); + lwsl_debug("%p: LWS_SSL_CAPABLE_MORE_SERVICE\n", wsi); + return LWS_SSL_CAPABLE_MORE_SERVICE; + } + if (m == SSL_ERROR_WANT_WRITE || SSL_want_write(wsi->tls.ssl)) { + lwsl_debug("%s: WANT_WRITE\n", __func__); + lwsl_debug("%p: LWS_SSL_CAPABLE_MORE_SERVICE\n", wsi); + return LWS_SSL_CAPABLE_MORE_SERVICE; + } + wsi->socket_is_permanently_unusable = 1; + + return LWS_SSL_CAPABLE_ERROR; + } + +#if 0 + /* + * If using mbedtls type tls library, this is the earliest point for all + * paths to dump what was received as decrypted data from the tls tunnel + */ + lwsl_notice("%s: len %d\n", __func__, n); + lwsl_hexdump_notice(buf, n); +#endif + + lws_stats_bump(pt, LWSSTATS_B_READ, n); + +#if defined(LWS_WITH_SERVER_STATUS) + if (wsi->a.vhost) + wsi->a.vhost->conn_stats.rx += n; +#endif +#if defined(LWS_WITH_DETAILED_LATENCY) + if (context->detailed_latency_cb) { + wsi->detlat.req_size = len; + wsi->detlat.acc_size = n; + wsi->detlat.type = LDLT_READ; + wsi->detlat.latencies[LAT_DUR_PROXY_RX_TO_ONWARD_TX] = + lws_now_usecs() - pt->ust_left_poll; + wsi->detlat.latencies[LAT_DUR_USERCB] = 0; + lws_det_lat_cb(wsi->a.context, &wsi->detlat); + } +#endif + /* + * if it was our buffer that limited what we read, + * check if SSL has additional data pending inside SSL buffers. + * + * Because these won't signal at the network layer with POLLIN + * and if we don't realize, this data will sit there forever + */ + if (n != len) + goto bail; + if (!wsi->tls.ssl) + goto bail; + + if (SSL_pending(wsi->tls.ssl)) { + if (lws_dll2_is_detached(&wsi->tls.dll_pending_tls)) + lws_dll2_add_head(&wsi->tls.dll_pending_tls, + &pt->tls.dll_pending_tls_owner); + } else + __lws_ssl_remove_wsi_from_buffered_list(wsi); + + return n; +bail: + lws_ssl_remove_wsi_from_buffered_list(wsi); + + return n; +} + +int +lws_ssl_pending(struct lws *wsi) +{ + if (!wsi->tls.ssl) + return 0; + + return SSL_pending(wsi->tls.ssl); +} + +int +lws_ssl_capable_write(struct lws *wsi, unsigned char *buf, int len) +{ + int n, m; + +#if 0 + /* + * If using mbedtls type tls library, this is the last point for all + * paths before sending data into the tls tunnel, where you can dump it + * and see what is being sent. + */ + lwsl_notice("%s: len %d\n", __func__, len); + lwsl_hexdump_notice(buf, len); +#endif + + if (!wsi->tls.ssl) + return lws_ssl_capable_write_no_ssl(wsi, buf, len); + + n = SSL_write(wsi->tls.ssl, buf, len); + if (n > 0) + return n; + + m = SSL_get_error(wsi->tls.ssl, n); + if (m != SSL_ERROR_SYSCALL) { + if (m == SSL_ERROR_WANT_READ || SSL_want_read(wsi->tls.ssl)) { + lwsl_notice("%s: want read\n", __func__); + + return LWS_SSL_CAPABLE_MORE_SERVICE; + } + + if (m == SSL_ERROR_WANT_WRITE || SSL_want_write(wsi->tls.ssl)) { + lws_set_blocking_send(wsi); + lwsl_debug("%s: want write\n", __func__); + + return LWS_SSL_CAPABLE_MORE_SERVICE; + } + } + + lwsl_debug("%s failed: %d\n",__func__, m); + wsi->socket_is_permanently_unusable = 1; + + return LWS_SSL_CAPABLE_ERROR; +} + +int openssl_SSL_CTX_private_data_index; + +void +lws_ssl_info_callback(const SSL *ssl, int where, int ret) +{ + struct lws *wsi; + struct lws_context *context; + struct lws_ssl_info si; + + context = (struct lws_context *)SSL_CTX_get_ex_data( + SSL_get_SSL_CTX(ssl), + openssl_SSL_CTX_private_data_index); + if (!context) + return; + wsi = wsi_from_fd(context, SSL_get_fd(ssl)); + if (!wsi) + return; + + if (!(where & wsi->a.vhost->tls.ssl_info_event_mask)) + return; + + si.where = where; + si.ret = ret; + + if (user_callback_handle_rxflow(wsi->a.protocol->callback, + wsi, LWS_CALLBACK_SSL_INFO, + wsi->user_space, &si, 0)) + lws_set_timeout(wsi, PENDING_TIMEOUT_KILLED_BY_SSL_INFO, -1); +} + + +int +lws_ssl_close(struct lws *wsi) +{ + lws_sockfd_type n; + + if (!wsi->tls.ssl) + return 0; /* not handled */ + +#if defined (LWS_HAVE_SSL_SET_INFO_CALLBACK) + /* kill ssl callbacks, becausse we will remove the fd from the + * table linking it to the wsi + */ + if (wsi->a.vhost->tls.ssl_info_event_mask) + SSL_set_info_callback(wsi->tls.ssl, NULL); +#endif + + n = SSL_get_fd(wsi->tls.ssl); + if (!wsi->socket_is_permanently_unusable) + SSL_shutdown(wsi->tls.ssl); + compatible_close(n); + SSL_free(wsi->tls.ssl); + wsi->tls.ssl = NULL; + + lws_tls_restrict_return(wsi->a.context); + + return 1; /* handled */ +} + +void +lws_ssl_SSL_CTX_destroy(struct lws_vhost *vhost) +{ + if (vhost->tls.ssl_ctx) + SSL_CTX_free(vhost->tls.ssl_ctx); + + if (!vhost->tls.user_supplied_ssl_ctx && vhost->tls.ssl_client_ctx) + SSL_CTX_free(vhost->tls.ssl_client_ctx); +#if defined(LWS_WITH_ACME) + lws_tls_acme_sni_cert_destroy(vhost); +#endif +} + +void +lws_ssl_context_destroy(struct lws_context *context) +{ +} + +lws_tls_ctx * +lws_tls_ctx_from_wsi(struct lws *wsi) +{ + if (!wsi->tls.ssl) + return NULL; + + return SSL_get_SSL_CTX(wsi->tls.ssl); +} + +enum lws_ssl_capable_status +__lws_tls_shutdown(struct lws *wsi) +{ + int n = SSL_shutdown(wsi->tls.ssl); + + lwsl_debug("SSL_shutdown=%d for fd %d\n", n, wsi->desc.sockfd); + + switch (n) { + case 1: /* successful completion */ + (void)shutdown(wsi->desc.sockfd, SHUT_WR); + return LWS_SSL_CAPABLE_DONE; + + case 0: /* needs a retry */ + __lws_change_pollfd(wsi, 0, LWS_POLLIN); + return LWS_SSL_CAPABLE_MORE_SERVICE; + + default: /* fatal error, or WANT */ + n = SSL_get_error(wsi->tls.ssl, n); + if (n != SSL_ERROR_SYSCALL && n != SSL_ERROR_SSL) { + if (SSL_want_read(wsi->tls.ssl)) { + lwsl_debug("(wants read)\n"); + __lws_change_pollfd(wsi, 0, LWS_POLLIN); + return LWS_SSL_CAPABLE_MORE_SERVICE_READ; + } + if (SSL_want_write(wsi->tls.ssl)) { + lwsl_debug("(wants write)\n"); + __lws_change_pollfd(wsi, 0, LWS_POLLOUT); + return LWS_SSL_CAPABLE_MORE_SERVICE_WRITE; + } + } + return LWS_SSL_CAPABLE_ERROR; + } +} + + +static int +tops_fake_POLLIN_for_buffered_mbedtls(struct lws_context_per_thread *pt) +{ + return lws_tls_fake_POLLIN_for_buffered(pt); +} + +const struct lws_tls_ops tls_ops_mbedtls = { + /* fake_POLLIN_for_buffered */ tops_fake_POLLIN_for_buffered_mbedtls, +}; diff -Nru libwebsockets-3.2.1/lib/tls/mbedtls/mbedtls-tls.c libwebsockets-4.1.6/lib/tls/mbedtls/mbedtls-tls.c --- libwebsockets-3.2.1/lib/tls/mbedtls/mbedtls-tls.c 1970-01-01 00:00:00.000000000 +0000 +++ libwebsockets-4.1.6/lib/tls/mbedtls/mbedtls-tls.c 2020-12-01 17:40:26.000000000 +0000 @@ -0,0 +1,49 @@ +/* + * libwebsockets - small server side websockets and web server implementation + * + * Copyright (C) 2010 - 2019 Andy Green + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to + * deal in the Software without restriction, including without limitation the + * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or + * sell copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS + * IN THE SOFTWARE. + */ + +#include "private-lib-core.h" +#include "private-lib-tls-mbedtls.h" + +void +lws_tls_err_describe_clear(void) +{ +} + +int +lws_context_init_ssl_library(const struct lws_context_creation_info *info) +{ + lwsl_info(" Compiled with MbedTLS support\n"); + + if (!lws_check_opt(info->options, LWS_SERVER_OPTION_DO_SSL_GLOBAL_INIT)) + lwsl_info(" SSL disabled: no " + "LWS_SERVER_OPTION_DO_SSL_GLOBAL_INIT\n"); + + return 0; +} + +void +lws_context_deinit_ssl_library(struct lws_context *context) +{ + +} diff -Nru libwebsockets-3.2.1/lib/tls/mbedtls/mbedtls-x509.c libwebsockets-4.1.6/lib/tls/mbedtls/mbedtls-x509.c --- libwebsockets-3.2.1/lib/tls/mbedtls/mbedtls-x509.c 1970-01-01 00:00:00.000000000 +0000 +++ libwebsockets-4.1.6/lib/tls/mbedtls/mbedtls-x509.c 2020-12-01 17:40:26.000000000 +0000 @@ -0,0 +1,435 @@ +/* + * libwebsockets - small server side websockets and web server implementation + * + * Copyright (C) 2010 - 2019 Andy Green + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to + * deal in the Software without restriction, including without limitation the + * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or + * sell copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS + * IN THE SOFTWARE. + */ + +#include "private-lib-core.h" +#include "private-lib-tls-mbedtls.h" +#include + +#if defined(LWS_PLAT_OPTEE) || defined(OPTEE_DEV_KIT) +struct tm { +int tm_sec; // seconds [0,61] +int tm_min; // minutes [0,59] +int tm_hour; // hour [0,23] +int tm_mday; // day of month [1,31] +int tm_mon; // month of year [0,11] +int tm_year; // years since 1900 +int tm_wday; // day of week [0,6] (Sunday = 0) +int tm_yday; // day of year [0,365] +int tm_isdst; // daylight savings flag +}; +time_t mktime(struct tm *t) +{ + return (time_t)0; +} +#endif + +static time_t +lws_tls_mbedtls_time_to_unix(mbedtls_x509_time *xtime) +{ + struct tm t; + + if (!xtime || !xtime->year || xtime->year < 0) + return (time_t)(long long)-1; + + memset(&t, 0, sizeof(t)); + + t.tm_year = xtime->year - 1900; + t.tm_mon = xtime->mon - 1; /* mbedtls months are 1+, tm are 0+ */ + t.tm_mday = xtime->day - 1; /* mbedtls days are 1+, tm are 0+ */ + t.tm_hour = xtime->hour; + t.tm_min = xtime->min; + t.tm_sec = xtime->sec; + t.tm_isdst = -1; + + return mktime(&t); +} + +static int +lws_tls_mbedtls_get_x509_name(mbedtls_x509_name *name, + union lws_tls_cert_info_results *buf, size_t len) +{ + while (name) { + if (MBEDTLS_OID_CMP(MBEDTLS_OID_AT_CN, &name->oid)) { + name = name->next; + continue; + } + + if (len - 1 < name->val.len) + return -1; + + memcpy(&buf->ns.name[0], name->val.p, name->val.len); + buf->ns.name[name->val.len] = '\0'; + buf->ns.len = name->val.len; + + return 0; + } + + return -1; +} + +static int +lws_tls_mbedtls_cert_info(mbedtls_x509_crt *x509, enum lws_tls_cert_info type, + union lws_tls_cert_info_results *buf, size_t len) +{ + if (!x509) + return -1; + + switch (type) { + case LWS_TLS_CERT_INFO_VALIDITY_FROM: + buf->time = lws_tls_mbedtls_time_to_unix(&x509->valid_from); + if (buf->time == (time_t)(long long)-1) + return -1; + break; + + case LWS_TLS_CERT_INFO_VALIDITY_TO: + buf->time = lws_tls_mbedtls_time_to_unix(&x509->valid_to); + if (buf->time == (time_t)(long long)-1) + return -1; + break; + + case LWS_TLS_CERT_INFO_COMMON_NAME: + return lws_tls_mbedtls_get_x509_name(&x509->subject, buf, len); + + case LWS_TLS_CERT_INFO_ISSUER_NAME: + return lws_tls_mbedtls_get_x509_name(&x509->issuer, buf, len); + + case LWS_TLS_CERT_INFO_USAGE: + buf->usage = x509->key_usage; + break; + + case LWS_TLS_CERT_INFO_OPAQUE_PUBLIC_KEY: + { + char *p = buf->ns.name; + size_t r = len, u; + + switch (mbedtls_pk_get_type(&x509->pk)) { + case MBEDTLS_PK_RSA: + { + mbedtls_rsa_context *rsa = mbedtls_pk_rsa(x509->pk); + + if (mbedtls_mpi_write_string(&rsa->N, 16, p, r, &u)) + return -1; + r -= u; + p += u; + if (mbedtls_mpi_write_string(&rsa->E, 16, p, r, &u)) + return -1; + + p += u; + buf->ns.len = lws_ptr_diff(p, buf->ns.name); + break; + } + case MBEDTLS_PK_ECKEY: + { + mbedtls_ecp_keypair *ecp = mbedtls_pk_ec(x509->pk); + + if (mbedtls_mpi_write_string(&ecp->Q.X, 16, p, r, &u)) + return -1; + r -= u; + p += u; + if (mbedtls_mpi_write_string(&ecp->Q.Y, 16, p, r, &u)) + return -1; + r -= u; + p += u; + if (mbedtls_mpi_write_string(&ecp->Q.Z, 16, p, r, &u)) + return -1; + p += u; + buf->ns.len = lws_ptr_diff(p, buf->ns.name); + break; + } + default: + lwsl_notice("%s: x509 has unsupported pubkey type %d\n", + __func__, + mbedtls_pk_get_type(&x509->pk)); + + return -1; + } + break; + } + + default: + return -1; + } + + return 0; +} + +#if defined(LWS_WITH_NETWORK) +int +lws_tls_vhost_cert_info(struct lws_vhost *vhost, enum lws_tls_cert_info type, + union lws_tls_cert_info_results *buf, size_t len) +{ + mbedtls_x509_crt *x509; + + x509 = ssl_ctx_get_mbedtls_x509_crt(vhost->tls.ssl_ctx); + + return lws_tls_mbedtls_cert_info(x509, type, buf, len); +} + +int +lws_tls_peer_cert_info(struct lws *wsi, enum lws_tls_cert_info type, + union lws_tls_cert_info_results *buf, size_t len) +{ + mbedtls_x509_crt *x509; + + wsi = lws_get_network_wsi(wsi); + + x509 = ssl_get_peer_mbedtls_x509_crt(wsi->tls.ssl); + + if (!x509) + return -1; + + switch (type) { + case LWS_TLS_CERT_INFO_VERIFIED: + buf->verified = SSL_get_verify_result(wsi->tls.ssl) == X509_V_OK; + return 0; + default: + return lws_tls_mbedtls_cert_info(x509, type, buf, len); + } + + return -1; +} +#endif + +int +lws_x509_info(struct lws_x509_cert *x509, enum lws_tls_cert_info type, + union lws_tls_cert_info_results *buf, size_t len) +{ + return lws_tls_mbedtls_cert_info(&x509->cert, type, buf, len); +} + +int +lws_x509_create(struct lws_x509_cert **x509) +{ + *x509 = lws_malloc(sizeof(**x509), __func__); + + return !(*x509); +} + +/* + * Parse one DER-encoded or one or more concatenated PEM-encoded certificates + * and add them to the chained list. + */ + +int +lws_x509_parse_from_pem(struct lws_x509_cert *x509, const void *pem, size_t len) +{ + int ret; + + mbedtls_x509_crt_init(&x509->cert); + + ret = mbedtls_x509_crt_parse(&x509->cert, pem, len); + if (ret) { + if (ret > 0) + mbedtls_x509_crt_free(&x509->cert); + lwsl_err("%s: unable to parse PEM cert: -0x%x\n", + __func__, -ret); + + return -1; + } + + return 0; +} + +int +lws_x509_verify(struct lws_x509_cert *x509, struct lws_x509_cert *trusted, + const char *common_name) +{ + uint32_t flags = 0; + int ret; + + ret = mbedtls_x509_crt_verify_with_profile(&x509->cert, &trusted->cert, + NULL, + &mbedtls_x509_crt_profile_next, + common_name, &flags, NULL, + NULL); + + if (ret) { + lwsl_err("%s: unable to parse PEM cert: -0x%x\n", + __func__, -ret); + + return -1; + } + + return 0; +} + +#if defined(LWS_WITH_JOSE) + +int +lws_x509_public_to_jwk(struct lws_jwk *jwk, struct lws_x509_cert *x509, + const char *curves, int rsa_min_bits) +{ + int kt = mbedtls_pk_get_type(&x509->cert.pk), n, count = 0, ret = -1; + mbedtls_rsa_context *rsactx; + mbedtls_ecp_keypair *ecpctx; + mbedtls_mpi *mpi[LWS_GENCRYPTO_RSA_KEYEL_COUNT]; + + memset(jwk, 0, sizeof(*jwk)); + + switch (kt) { + case MBEDTLS_PK_RSA: + lwsl_notice("%s: RSA key\n", __func__); + jwk->kty = LWS_GENCRYPTO_KTY_RSA; + rsactx = mbedtls_pk_rsa(x509->cert.pk); + + mpi[LWS_GENCRYPTO_RSA_KEYEL_E] = &rsactx->E; + mpi[LWS_GENCRYPTO_RSA_KEYEL_N] = &rsactx->N; + mpi[LWS_GENCRYPTO_RSA_KEYEL_D] = &rsactx->D; + mpi[LWS_GENCRYPTO_RSA_KEYEL_P] = &rsactx->P; + mpi[LWS_GENCRYPTO_RSA_KEYEL_Q] = &rsactx->Q; + mpi[LWS_GENCRYPTO_RSA_KEYEL_DP] = &rsactx->DP; + mpi[LWS_GENCRYPTO_RSA_KEYEL_DQ] = &rsactx->DQ; + mpi[LWS_GENCRYPTO_RSA_KEYEL_QI] = &rsactx->QP; + + count = LWS_GENCRYPTO_RSA_KEYEL_COUNT; + n = LWS_GENCRYPTO_RSA_KEYEL_E; + break; + + case MBEDTLS_PK_ECKEY: + lwsl_notice("%s: EC key\n", __func__); + jwk->kty = LWS_GENCRYPTO_KTY_EC; + ecpctx = mbedtls_pk_ec(x509->cert.pk); + mpi[LWS_GENCRYPTO_EC_KEYEL_X] = &ecpctx->Q.X; + mpi[LWS_GENCRYPTO_EC_KEYEL_D] = &ecpctx->d; + mpi[LWS_GENCRYPTO_EC_KEYEL_Y] = &ecpctx->Q.Y; + + if (lws_genec_confirm_curve_allowed_by_tls_id(curves, + ecpctx->grp.id, jwk)) + /* already logged */ + goto bail; + + count = LWS_GENCRYPTO_EC_KEYEL_COUNT; + n = LWS_GENCRYPTO_EC_KEYEL_X; + break; + default: + lwsl_err("%s: key type %d not supported\n", __func__, kt); + + return -1; + } + + for (; n < count; n++) { + if (!mbedtls_mpi_size(mpi[n])) + continue; + + jwk->e[n].buf = lws_malloc(mbedtls_mpi_size(mpi[n]), "certjwk"); + if (!jwk->e[n].buf) + goto bail; + jwk->e[n].len = mbedtls_mpi_size(mpi[n]); + mbedtls_mpi_write_binary(mpi[n], jwk->e[n].buf, jwk->e[n].len); + } + + ret = 0; + +bail: + /* jwk destroy will clean up partials */ + if (ret) + lws_jwk_destroy(jwk); + + return ret; +} + +int +lws_x509_jwk_privkey_pem(struct lws_jwk *jwk, void *pem, size_t len, + const char *passphrase) +{ + mbedtls_rsa_context *rsactx; + mbedtls_ecp_keypair *ecpctx; + mbedtls_pk_context pk; + mbedtls_mpi *mpi[LWS_GENCRYPTO_RSA_KEYEL_COUNT]; + int n, ret = -1, count = 0; + + mbedtls_pk_init(&pk); + + n = 0; + if (passphrase) + n = strlen(passphrase); + n = mbedtls_pk_parse_key(&pk, pem, len, (uint8_t *)passphrase, n); + if (n) { + lwsl_err("%s: parse PEM key failed: -0x%x\n", __func__, -n); + + return -1; + } + + /* the incoming private key type */ + switch (mbedtls_pk_get_type(&pk)) { + case MBEDTLS_PK_RSA: + if (jwk->kty != LWS_GENCRYPTO_KTY_RSA) { + lwsl_err("%s: RSA privkey, non-RSA jwk\n", __func__); + goto bail; + } + rsactx = mbedtls_pk_rsa(pk); + mpi[LWS_GENCRYPTO_RSA_KEYEL_D] = &rsactx->D; + mpi[LWS_GENCRYPTO_RSA_KEYEL_P] = &rsactx->P; + mpi[LWS_GENCRYPTO_RSA_KEYEL_Q] = &rsactx->Q; + n = LWS_GENCRYPTO_RSA_KEYEL_D; + count = LWS_GENCRYPTO_RSA_KEYEL_Q + 1; + break; + case MBEDTLS_PK_ECKEY: + if (jwk->kty != LWS_GENCRYPTO_KTY_EC) { + lwsl_err("%s: EC privkey, non-EC jwk\n", __func__); + goto bail; + } + ecpctx = mbedtls_pk_ec(pk); + mpi[LWS_GENCRYPTO_EC_KEYEL_D] = &ecpctx->d; + n = LWS_GENCRYPTO_EC_KEYEL_D; + count = n + 1; + break; + default: + lwsl_err("%s: unusable key type %d\n", __func__, + mbedtls_pk_get_type(&pk)); + goto bail; + } + + for (; n < count; n++) { + if (!mbedtls_mpi_size(mpi[n])) { + lwsl_err("%s: empty privkey\n", __func__); + goto bail; + } + + jwk->e[n].buf = lws_malloc(mbedtls_mpi_size(mpi[n]), "certjwk"); + if (!jwk->e[n].buf) + goto bail; + jwk->e[n].len = mbedtls_mpi_size(mpi[n]); + mbedtls_mpi_write_binary(mpi[n], jwk->e[n].buf, jwk->e[n].len); + } + + ret = 0; + +bail: + mbedtls_pk_free(&pk); + + return ret; +} +#endif + +void +lws_x509_destroy(struct lws_x509_cert **x509) +{ + if (!*x509) + return; + + mbedtls_x509_crt_free(&(*x509)->cert); + + lws_free_set_NULL(*x509); +} diff -Nru libwebsockets-3.2.1/lib/tls/mbedtls/private.h libwebsockets-4.1.6/lib/tls/mbedtls/private.h --- libwebsockets-3.2.1/lib/tls/mbedtls/private.h 2019-12-18 14:45:31.000000000 +0000 +++ libwebsockets-4.1.6/lib/tls/mbedtls/private.h 1970-01-01 00:00:00.000000000 +0000 @@ -1,34 +0,0 @@ -/* - * libwebsockets - small server side websockets and web server implementation - * - * Copyright (C) 2010 - 2018 Andy Green - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation: - * version 2.1 of the License. - * - * This library is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with this library; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, - * MA 02110-1301 USA - * - * gencrypto mbedtls-specific helper declarations - */ - -#include - -struct lws_x509_cert { - mbedtls_x509_crt cert; /* has a .next for linked-list / chain */ -}; - -mbedtls_md_type_t -lws_gencrypto_mbedtls_hash_to_MD_TYPE(enum lws_genhash_types hash_type); - -int -lws_gencrypto_mbedtls_rngf(void *context, unsigned char *buf, size_t len); diff -Nru libwebsockets-3.2.1/lib/tls/mbedtls/private-lib-tls-mbedtls.h libwebsockets-4.1.6/lib/tls/mbedtls/private-lib-tls-mbedtls.h --- libwebsockets-3.2.1/lib/tls/mbedtls/private-lib-tls-mbedtls.h 1970-01-01 00:00:00.000000000 +0000 +++ libwebsockets-4.1.6/lib/tls/mbedtls/private-lib-tls-mbedtls.h 2020-12-01 17:40:26.000000000 +0000 @@ -0,0 +1,38 @@ + /* + * libwebsockets - small server side websockets and web server implementation + * + * Copyright (C) 2010 - 2019 Andy Green + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to + * deal in the Software without restriction, including without limitation the + * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or + * sell copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS + * IN THE SOFTWARE. + * + * gencrypto mbedtls-specific helper declarations + */ + +#include +#include + +struct lws_x509_cert { + mbedtls_x509_crt cert; /* has a .next for linked-list / chain */ +}; + +mbedtls_md_type_t +lws_gencrypto_mbedtls_hash_to_MD_TYPE(enum lws_genhash_types hash_type); + +int +lws_gencrypto_mbedtls_rngf(void *context, unsigned char *buf, size_t len); diff -Nru libwebsockets-3.2.1/lib/tls/mbedtls/ssl.c libwebsockets-4.1.6/lib/tls/mbedtls/ssl.c --- libwebsockets-3.2.1/lib/tls/mbedtls/ssl.c 2019-12-18 14:45:31.000000000 +0000 +++ libwebsockets-4.1.6/lib/tls/mbedtls/ssl.c 1970-01-01 00:00:00.000000000 +0000 @@ -1,317 +0,0 @@ -/* - * libwebsockets - mbedTLS-specific lws apis - * - * Copyright (C) 2010 - 2019 Andy Green - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation: - * version 2.1 of the License. - * - * This library is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with this library; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, - * MA 02110-1301 USA - */ - -#include "core/private.h" -#include "tls/mbedtls/private.h" - - -LWS_VISIBLE void -lws_ssl_destroy(struct lws_vhost *vhost) -{ - if (!lws_check_opt(vhost->context->options, - LWS_SERVER_OPTION_DO_SSL_GLOBAL_INIT)) - return; - - if (vhost->tls.ssl_ctx) - SSL_CTX_free(vhost->tls.ssl_ctx); - if (!vhost->tls.user_supplied_ssl_ctx && vhost->tls.ssl_client_ctx) - SSL_CTX_free(vhost->tls.ssl_client_ctx); - - if (vhost->tls.x509_client_CA) - X509_free(vhost->tls.x509_client_CA); -} - -LWS_VISIBLE int -lws_ssl_capable_read(struct lws *wsi, unsigned char *buf, int len) -{ - struct lws_context *context = wsi->context; - struct lws_context_per_thread *pt = &context->pt[(int)wsi->tsi]; - int n = 0, m; - - if (!wsi->tls.ssl) - return lws_ssl_capable_read_no_ssl(wsi, buf, len); - - lws_stats_bump(pt, LWSSTATS_C_API_READ, 1); - - errno = 0; - n = SSL_read(wsi->tls.ssl, buf, len); -#if defined(LWS_WITH_ESP32) - if (!n && errno == LWS_ENOTCONN) { - lwsl_debug("%p: SSL_read ENOTCONN\n", wsi); - return LWS_SSL_CAPABLE_ERROR; - } -#endif -#if defined(LWS_WITH_STATS) - if (!wsi->seen_rx && wsi->accept_start_us) { - lws_stats_bump(pt, LWSSTATS_US_SSL_RX_DELAY_AVG, - lws_now_usecs() - wsi->accept_start_us); - lws_stats_bump(pt, LWSSTATS_C_SSL_CONNS_HAD_RX, 1); - wsi->seen_rx = 1; - } -#endif - - - lwsl_debug("%p: SSL_read says %d\n", wsi, n); - /* manpage: returning 0 means connection shut down */ - if (!n) { - wsi->socket_is_permanently_unusable = 1; - - return LWS_SSL_CAPABLE_ERROR; - } - - if (n < 0) { - m = SSL_get_error(wsi->tls.ssl, n); - lwsl_debug("%p: ssl err %d errno %d\n", wsi, m, errno); - if (errno == LWS_ENOTCONN) { - /* If the socket isn't connected anymore, bail out. */ - wsi->socket_is_permanently_unusable = 1; - return LWS_SSL_CAPABLE_ERROR; - } - if (m == SSL_ERROR_ZERO_RETURN || - m == SSL_ERROR_SYSCALL) - return LWS_SSL_CAPABLE_ERROR; - - if (m == SSL_ERROR_WANT_READ || SSL_want_read(wsi->tls.ssl)) { - lwsl_debug("%s: WANT_READ\n", __func__); - lwsl_debug("%p: LWS_SSL_CAPABLE_MORE_SERVICE\n", wsi); - return LWS_SSL_CAPABLE_MORE_SERVICE; - } - if (m == SSL_ERROR_WANT_WRITE || SSL_want_write(wsi->tls.ssl)) { - lwsl_debug("%s: WANT_WRITE\n", __func__); - lwsl_debug("%p: LWS_SSL_CAPABLE_MORE_SERVICE\n", wsi); - return LWS_SSL_CAPABLE_MORE_SERVICE; - } - wsi->socket_is_permanently_unusable = 1; - - return LWS_SSL_CAPABLE_ERROR; - } - - lws_stats_bump(pt, LWSSTATS_B_READ, n); - - if (wsi->vhost) - wsi->vhost->conn_stats.rx += n; - - /* - * if it was our buffer that limited what we read, - * check if SSL has additional data pending inside SSL buffers. - * - * Because these won't signal at the network layer with POLLIN - * and if we don't realize, this data will sit there forever - */ - if (n != len) - goto bail; - if (!wsi->tls.ssl) - goto bail; - - if (SSL_pending(wsi->tls.ssl) && - lws_dll2_is_detached(&wsi->tls.dll_pending_tls)) - lws_dll2_add_head(&wsi->tls.dll_pending_tls, - &pt->tls.dll_pending_tls_owner); - - return n; -bail: - lws_ssl_remove_wsi_from_buffered_list(wsi); - - return n; -} - -LWS_VISIBLE int -lws_ssl_pending(struct lws *wsi) -{ - if (!wsi->tls.ssl) - return 0; - - return SSL_pending(wsi->tls.ssl); -} - -LWS_VISIBLE int -lws_ssl_capable_write(struct lws *wsi, unsigned char *buf, int len) -{ - int n, m; - - if (!wsi->tls.ssl) - return lws_ssl_capable_write_no_ssl(wsi, buf, len); - - n = SSL_write(wsi->tls.ssl, buf, len); - if (n > 0) - return n; - - m = SSL_get_error(wsi->tls.ssl, n); - if (m != SSL_ERROR_SYSCALL) { - if (m == SSL_ERROR_WANT_READ || SSL_want_read(wsi->tls.ssl)) { - lwsl_notice("%s: want read\n", __func__); - - return LWS_SSL_CAPABLE_MORE_SERVICE; - } - - if (m == SSL_ERROR_WANT_WRITE || SSL_want_write(wsi->tls.ssl)) { - lws_set_blocking_send(wsi); - lwsl_debug("%s: want write\n", __func__); - - return LWS_SSL_CAPABLE_MORE_SERVICE; - } - } - - lwsl_debug("%s failed: %d\n",__func__, m); - wsi->socket_is_permanently_unusable = 1; - - return LWS_SSL_CAPABLE_ERROR; -} - -int openssl_SSL_CTX_private_data_index; - -void -lws_ssl_info_callback(const SSL *ssl, int where, int ret) -{ - struct lws *wsi; - struct lws_context *context; - struct lws_ssl_info si; - - context = (struct lws_context *)SSL_CTX_get_ex_data( - SSL_get_SSL_CTX(ssl), - openssl_SSL_CTX_private_data_index); - if (!context) - return; - wsi = wsi_from_fd(context, SSL_get_fd(ssl)); - if (!wsi) - return; - - if (!(where & wsi->vhost->tls.ssl_info_event_mask)) - return; - - si.where = where; - si.ret = ret; - - if (user_callback_handle_rxflow(wsi->protocol->callback, - wsi, LWS_CALLBACK_SSL_INFO, - wsi->user_space, &si, 0)) - lws_set_timeout(wsi, PENDING_TIMEOUT_KILLED_BY_SSL_INFO, -1); -} - - -LWS_VISIBLE int -lws_ssl_close(struct lws *wsi) -{ - lws_sockfd_type n; - - if (!wsi->tls.ssl) - return 0; /* not handled */ - -#if defined (LWS_HAVE_SSL_SET_INFO_CALLBACK) - /* kill ssl callbacks, becausse we will remove the fd from the - * table linking it to the wsi - */ - if (wsi->vhost->tls.ssl_info_event_mask) - SSL_set_info_callback(wsi->tls.ssl, NULL); -#endif - - n = SSL_get_fd(wsi->tls.ssl); - if (!wsi->socket_is_permanently_unusable) - SSL_shutdown(wsi->tls.ssl); - compatible_close(n); - SSL_free(wsi->tls.ssl); - wsi->tls.ssl = NULL; - - if (!lwsi_role_client(wsi) && - wsi->context->simultaneous_ssl_restriction && - wsi->context->simultaneous_ssl-- == - wsi->context->simultaneous_ssl_restriction) - /* we made space and can do an accept */ - lws_gate_accepts(wsi->context, 1); - -#if defined(LWS_WITH_STATS) - wsi->context->updated = 1; -#endif - - return 1; /* handled */ -} - -void -lws_ssl_SSL_CTX_destroy(struct lws_vhost *vhost) -{ - if (vhost->tls.ssl_ctx) - SSL_CTX_free(vhost->tls.ssl_ctx); - - if (!vhost->tls.user_supplied_ssl_ctx && vhost->tls.ssl_client_ctx) - SSL_CTX_free(vhost->tls.ssl_client_ctx); -#if defined(LWS_WITH_ACME) - lws_tls_acme_sni_cert_destroy(vhost); -#endif -} - -void -lws_ssl_context_destroy(struct lws_context *context) -{ -} - -lws_tls_ctx * -lws_tls_ctx_from_wsi(struct lws *wsi) -{ - if (!wsi->tls.ssl) - return NULL; - - return SSL_get_SSL_CTX(wsi->tls.ssl); -} - -enum lws_ssl_capable_status -__lws_tls_shutdown(struct lws *wsi) -{ - int n = SSL_shutdown(wsi->tls.ssl); - - lwsl_debug("SSL_shutdown=%d for fd %d\n", n, wsi->desc.sockfd); - - switch (n) { - case 1: /* successful completion */ - n = shutdown(wsi->desc.sockfd, SHUT_WR); - return LWS_SSL_CAPABLE_DONE; - - case 0: /* needs a retry */ - __lws_change_pollfd(wsi, 0, LWS_POLLIN); - return LWS_SSL_CAPABLE_MORE_SERVICE; - - default: /* fatal error, or WANT */ - n = SSL_get_error(wsi->tls.ssl, n); - if (n != SSL_ERROR_SYSCALL && n != SSL_ERROR_SSL) { - if (SSL_want_read(wsi->tls.ssl)) { - lwsl_debug("(wants read)\n"); - __lws_change_pollfd(wsi, 0, LWS_POLLIN); - return LWS_SSL_CAPABLE_MORE_SERVICE_READ; - } - if (SSL_want_write(wsi->tls.ssl)) { - lwsl_debug("(wants write)\n"); - __lws_change_pollfd(wsi, 0, LWS_POLLOUT); - return LWS_SSL_CAPABLE_MORE_SERVICE_WRITE; - } - } - return LWS_SSL_CAPABLE_ERROR; - } -} - - -static int -tops_fake_POLLIN_for_buffered_mbedtls(struct lws_context_per_thread *pt) -{ - return lws_tls_fake_POLLIN_for_buffered(pt); -} - -const struct lws_tls_ops tls_ops_mbedtls = { - /* fake_POLLIN_for_buffered */ tops_fake_POLLIN_for_buffered_mbedtls, -}; diff -Nru libwebsockets-3.2.1/lib/tls/mbedtls/tls.c libwebsockets-4.1.6/lib/tls/mbedtls/tls.c --- libwebsockets-3.2.1/lib/tls/mbedtls/tls.c 2019-12-18 14:45:31.000000000 +0000 +++ libwebsockets-4.1.6/lib/tls/mbedtls/tls.c 1970-01-01 00:00:00.000000000 +0000 @@ -1,46 +0,0 @@ -/* - * libwebsockets - mbedTLS-specific lws apis - * - * Copyright (C) 2010 - 2019 Andy Green - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation: - * version 2.1 of the License. - * - * This library is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with this library; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, - * MA 02110-1301 USA - */ - -#include "core/private.h" -#include "tls/mbedtls/private.h" - -void -lws_tls_err_describe_clear(void) -{ -} - -int -lws_context_init_ssl_library(const struct lws_context_creation_info *info) -{ - lwsl_info(" Compiled with MbedTLS support\n"); - - if (!lws_check_opt(info->options, LWS_SERVER_OPTION_DO_SSL_GLOBAL_INIT)) - lwsl_info(" SSL disabled: no " - "LWS_SERVER_OPTION_DO_SSL_GLOBAL_INIT\n"); - - return 0; -} - -void -lws_context_deinit_ssl_library(struct lws_context *context) -{ - -} diff -Nru libwebsockets-3.2.1/lib/tls/mbedtls/wrapper/include/internal/ssl_dbg.h libwebsockets-4.1.6/lib/tls/mbedtls/wrapper/include/internal/ssl_dbg.h --- libwebsockets-3.2.1/lib/tls/mbedtls/wrapper/include/internal/ssl_dbg.h 2019-12-18 14:45:31.000000000 +0000 +++ libwebsockets-4.1.6/lib/tls/mbedtls/wrapper/include/internal/ssl_dbg.h 2020-12-01 17:40:26.000000000 +0000 @@ -15,7 +15,7 @@ #ifndef _SSL_DEBUG_H_ #define _SSL_DEBUG_H_ -#include "platform/ssl_port.h" +#include "ssl_port.h" #ifdef __cplusplus extern "C" { diff -Nru libwebsockets-3.2.1/lib/tls/mbedtls/wrapper/include/internal/ssl_types.h libwebsockets-4.1.6/lib/tls/mbedtls/wrapper/include/internal/ssl_types.h --- libwebsockets-3.2.1/lib/tls/mbedtls/wrapper/include/internal/ssl_types.h 2019-12-18 14:45:31.000000000 +0000 +++ libwebsockets-4.1.6/lib/tls/mbedtls/wrapper/include/internal/ssl_types.h 2020-12-01 17:40:26.000000000 +0000 @@ -19,9 +19,9 @@ extern "C" { #endif -//#include "core/private.h" +//#include "private-lib-core.h" #include -#if defined(LWS_WITH_ESP32) +#if defined(LWS_PLAT_FREERTOS) /* AMAZON RTOS has its own setting via MTK_MBEDTLS_CONFIG_FILE */ #if !defined(LWS_AMAZON_RTOS) #undef MBEDTLS_CONFIG_FILE diff -Nru libwebsockets-3.2.1/lib/tls/mbedtls/wrapper/include/internal/ssl_x509.h libwebsockets-4.1.6/lib/tls/mbedtls/wrapper/include/internal/ssl_x509.h --- libwebsockets-3.2.1/lib/tls/mbedtls/wrapper/include/internal/ssl_x509.h 2019-12-18 14:45:31.000000000 +0000 +++ libwebsockets-4.1.6/lib/tls/mbedtls/wrapper/include/internal/ssl_x509.h 2020-12-01 17:40:26.000000000 +0000 @@ -99,7 +99,8 @@ * 1 : OK * */ -int SSL_use_certificate_ASN1(SSL *ssl, int len, const unsigned char *d); + +int SSL_use_certificate_ASN1(SSL *ssl, const unsigned char *d, int len); const char *X509_verify_cert_error_string(long n); diff -Nru libwebsockets-3.2.1/lib/tls/mbedtls/wrapper/include/openssl/ssl.h libwebsockets-4.1.6/lib/tls/mbedtls/wrapper/include/openssl/ssl.h --- libwebsockets-3.2.1/lib/tls/mbedtls/wrapper/include/openssl/ssl.h 2019-12-18 14:45:31.000000000 +0000 +++ libwebsockets-4.1.6/lib/tls/mbedtls/wrapper/include/openssl/ssl.h 2020-12-01 17:40:26.000000000 +0000 @@ -20,8 +20,8 @@ #endif #include -#include "internal/ssl_x509.h" -#include "internal/ssl_pkey.h" +#include "ssl_x509.h" +#include "ssl_pkey.h" /* { diff -Nru libwebsockets-3.2.1/lib/tls/mbedtls/wrapper/library/ssl_lib.c libwebsockets-4.1.6/lib/tls/mbedtls/wrapper/library/ssl_lib.c --- libwebsockets-3.2.1/lib/tls/mbedtls/wrapper/library/ssl_lib.c 2019-12-18 14:45:31.000000000 +0000 +++ libwebsockets-4.1.6/lib/tls/mbedtls/wrapper/library/ssl_lib.c 2020-12-01 17:40:26.000000000 +0000 @@ -19,7 +19,7 @@ #include "ssl_dbg.h" #include "ssl_port.h" -#include "core/private.h" +#include "private-lib-core.h" char * lws_strncpy(char *dest, const char *src, size_t size); @@ -805,220 +805,6 @@ } /** - * @brief get alert description string - */ -const char* SSL_alert_desc_string(int value) -{ - const char *str; - - switch (value & 0xff) - { - case SSL3_AD_CLOSE_NOTIFY: - str = "CN"; - break; - case SSL3_AD_UNEXPECTED_MESSAGE: - str = "UM"; - break; - case SSL3_AD_BAD_RECORD_MAC: - str = "BM"; - break; - case SSL3_AD_DECOMPRESSION_FAILURE: - str = "DF"; - break; - case SSL3_AD_HANDSHAKE_FAILURE: - str = "HF"; - break; - case SSL3_AD_NO_CERTIFICATE: - str = "NC"; - break; - case SSL3_AD_BAD_CERTIFICATE: - str = "BC"; - break; - case SSL3_AD_UNSUPPORTED_CERTIFICATE: - str = "UC"; - break; - case SSL3_AD_CERTIFICATE_REVOKED: - str = "CR"; - break; - case SSL3_AD_CERTIFICATE_EXPIRED: - str = "CE"; - break; - case SSL3_AD_CERTIFICATE_UNKNOWN: - str = "CU"; - break; - case SSL3_AD_ILLEGAL_PARAMETER: - str = "IP"; - break; - case TLS1_AD_DECRYPTION_FAILED: - str = "DC"; - break; - case TLS1_AD_RECORD_OVERFLOW: - str = "RO"; - break; - case TLS1_AD_UNKNOWN_CA: - str = "CA"; - break; - case TLS1_AD_ACCESS_DENIED: - str = "AD"; - break; - case TLS1_AD_DECODE_ERROR: - str = "DE"; - break; - case TLS1_AD_DECRYPT_ERROR: - str = "CY"; - break; - case TLS1_AD_EXPORT_RESTRICTION: - str = "ER"; - break; - case TLS1_AD_PROTOCOL_VERSION: - str = "PV"; - break; - case TLS1_AD_INSUFFICIENT_SECURITY: - str = "IS"; - break; - case TLS1_AD_INTERNAL_ERROR: - str = "IE"; - break; - case TLS1_AD_USER_CANCELLED: - str = "US"; - break; - case TLS1_AD_NO_RENEGOTIATION: - str = "NR"; - break; - case TLS1_AD_UNSUPPORTED_EXTENSION: - str = "UE"; - break; - case TLS1_AD_CERTIFICATE_UNOBTAINABLE: - str = "CO"; - break; - case TLS1_AD_UNRECOGNIZED_NAME: - str = "UN"; - break; - case TLS1_AD_BAD_CERTIFICATE_STATUS_RESPONSE: - str = "BR"; - break; - case TLS1_AD_BAD_CERTIFICATE_HASH_VALUE: - str = "BH"; - break; - case TLS1_AD_UNKNOWN_PSK_IDENTITY: - str = "UP"; - break; - default: - str = "UK"; - break; - } - - return str; -} - -/** - * @brief get alert description long string - */ -const char* SSL_alert_desc_string_long(int value) -{ - const char *str; - - switch (value & 0xff) - { - case SSL3_AD_CLOSE_NOTIFY: - str = "close notify"; - break; - case SSL3_AD_UNEXPECTED_MESSAGE: - str = "unexpected_message"; - break; - case SSL3_AD_BAD_RECORD_MAC: - str = "bad record mac"; - break; - case SSL3_AD_DECOMPRESSION_FAILURE: - str = "decompression failure"; - break; - case SSL3_AD_HANDSHAKE_FAILURE: - str = "handshake failure"; - break; - case SSL3_AD_NO_CERTIFICATE: - str = "no certificate"; - break; - case SSL3_AD_BAD_CERTIFICATE: - str = "bad certificate"; - break; - case SSL3_AD_UNSUPPORTED_CERTIFICATE: - str = "unsupported certificate"; - break; - case SSL3_AD_CERTIFICATE_REVOKED: - str = "certificate revoked"; - break; - case SSL3_AD_CERTIFICATE_EXPIRED: - str = "certificate expired"; - break; - case SSL3_AD_CERTIFICATE_UNKNOWN: - str = "certificate unknown"; - break; - case SSL3_AD_ILLEGAL_PARAMETER: - str = "illegal parameter"; - break; - case TLS1_AD_DECRYPTION_FAILED: - str = "decryption failed"; - break; - case TLS1_AD_RECORD_OVERFLOW: - str = "record overflow"; - break; - case TLS1_AD_UNKNOWN_CA: - str = "unknown CA"; - break; - case TLS1_AD_ACCESS_DENIED: - str = "access denied"; - break; - case TLS1_AD_DECODE_ERROR: - str = "decode error"; - break; - case TLS1_AD_DECRYPT_ERROR: - str = "decrypt error"; - break; - case TLS1_AD_EXPORT_RESTRICTION: - str = "export restriction"; - break; - case TLS1_AD_PROTOCOL_VERSION: - str = "protocol version"; - break; - case TLS1_AD_INSUFFICIENT_SECURITY: - str = "insufficient security"; - break; - case TLS1_AD_INTERNAL_ERROR: - str = "internal error"; - break; - case TLS1_AD_USER_CANCELLED: - str = "user canceled"; - break; - case TLS1_AD_NO_RENEGOTIATION: - str = "no renegotiation"; - break; - case TLS1_AD_UNSUPPORTED_EXTENSION: - str = "unsupported extension"; - break; - case TLS1_AD_CERTIFICATE_UNOBTAINABLE: - str = "certificate unobtainable"; - break; - case TLS1_AD_UNRECOGNIZED_NAME: - str = "unrecognized name"; - break; - case TLS1_AD_BAD_CERTIFICATE_STATUS_RESPONSE: - str = "bad certificate status response"; - break; - case TLS1_AD_BAD_CERTIFICATE_HASH_VALUE: - str = "bad certificate hash value"; - break; - case TLS1_AD_UNKNOWN_PSK_IDENTITY: - str = "unknown PSK identity"; - break; - default: - str = "unknown"; - break; - } - - return str; -} - -/** * @brief get alert type string */ const char *SSL_alert_type_string(int value) @@ -1042,306 +828,6 @@ } /** - * @brief get alert type long string - */ -const char *SSL_alert_type_string_long(int value) -{ - const char *str; - - switch (value >> 8) - { - case SSL3_AL_WARNING: - str = "warning"; - break; - case SSL3_AL_FATAL: - str = "fatal"; - break; - default: - str = "unknown"; - break; - } - - return str; -} - -/** - * @brief get the state string where SSL is reading - */ -const char *SSL_rstate_string(SSL *ssl) -{ - const char *str; - - SSL_ASSERT2(ssl); - - switch (ssl->rlayer.rstate) - { - case SSL_ST_READ_HEADER: - str = "RH"; - break; - case SSL_ST_READ_BODY: - str = "RB"; - break; - case SSL_ST_READ_DONE: - str = "RD"; - break; - default: - str = "unknown"; - break; - } - - return str; -} - -/** - * @brief get the statement long string where SSL is reading - */ -const char *SSL_rstate_string_long(SSL *ssl) -{ - const char *str = "unknown"; - - SSL_ASSERT2(ssl); - - switch (ssl->rlayer.rstate) - { - case SSL_ST_READ_HEADER: - str = "read header"; - break; - case SSL_ST_READ_BODY: - str = "read body"; - break; - case SSL_ST_READ_DONE: - str = "read done"; - break; - default: - break; - } - - return str; -} - -/** - * @brief get SSL statement string - */ -char *SSL_state_string(const SSL *ssl) -{ - char *str = "UNKWN "; - - SSL_ASSERT2(ssl); - - if (ossl_statem_in_error(ssl)) - str = "SSLERR"; - else - { - switch (SSL_get_state(ssl)) - { - case TLS_ST_BEFORE: - str = "PINIT "; - break; - case TLS_ST_OK: - str = "SSLOK "; - break; - case TLS_ST_CW_CLNT_HELLO: - str = "TWCH"; - break; - case TLS_ST_CR_SRVR_HELLO: - str = "TRSH"; - break; - case TLS_ST_CR_CERT: - str = "TRSC"; - break; - case TLS_ST_CR_KEY_EXCH: - str = "TRSKE"; - break; - case TLS_ST_CR_CERT_REQ: - str = "TRCR"; - break; - case TLS_ST_CR_SRVR_DONE: - str = "TRSD"; - break; - case TLS_ST_CW_CERT: - str = "TWCC"; - break; - case TLS_ST_CW_KEY_EXCH: - str = "TWCKE"; - break; - case TLS_ST_CW_CERT_VRFY: - str = "TWCV"; - break; - case TLS_ST_SW_CHANGE: - case TLS_ST_CW_CHANGE: - str = "TWCCS"; - break; - case TLS_ST_SW_FINISHED: - case TLS_ST_CW_FINISHED: - str = "TWFIN"; - break; - case TLS_ST_SR_CHANGE: - case TLS_ST_CR_CHANGE: - str = "TRCCS"; - break; - case TLS_ST_SR_FINISHED: - case TLS_ST_CR_FINISHED: - str = "TRFIN"; - break; - case TLS_ST_SW_HELLO_REQ: - str = "TWHR"; - break; - case TLS_ST_SR_CLNT_HELLO: - str = "TRCH"; - break; - case TLS_ST_SW_SRVR_HELLO: - str = "TWSH"; - break; - case TLS_ST_SW_CERT: - str = "TWSC"; - break; - case TLS_ST_SW_KEY_EXCH: - str = "TWSKE"; - break; - case TLS_ST_SW_CERT_REQ: - str = "TWCR"; - break; - case TLS_ST_SW_SRVR_DONE: - str = "TWSD"; - break; - case TLS_ST_SR_CERT: - str = "TRCC"; - break; - case TLS_ST_SR_KEY_EXCH: - str = "TRCKE"; - break; - case TLS_ST_SR_CERT_VRFY: - str = "TRCV"; - break; - case DTLS_ST_CR_HELLO_VERIFY_REQUEST: - str = "DRCHV"; - break; - case DTLS_ST_SW_HELLO_VERIFY_REQUEST: - str = "DWCHV"; - break; - default: - break; - } - } - - return str; -} - -/** - * @brief get SSL statement long string - */ -char *SSL_state_string_long(const SSL *ssl) -{ - char *str = "UNKWN "; - - SSL_ASSERT2(ssl); - - if (ossl_statem_in_error(ssl)) - str = "SSLERR"; - else - { - switch (SSL_get_state(ssl)) - { - case TLS_ST_BEFORE: - str = "before SSL initialization"; - break; - case TLS_ST_OK: - str = "SSL negotiation finished successfully"; - break; - case TLS_ST_CW_CLNT_HELLO: - str = "SSLv3/TLS write client hello"; - break; - case TLS_ST_CR_SRVR_HELLO: - str = "SSLv3/TLS read server hello"; - break; - case TLS_ST_CR_CERT: - str = "SSLv3/TLS read server certificate"; - break; - case TLS_ST_CR_KEY_EXCH: - str = "SSLv3/TLS read server key exchange"; - break; - case TLS_ST_CR_CERT_REQ: - str = "SSLv3/TLS read server certificate request"; - break; - case TLS_ST_CR_SESSION_TICKET: - str = "SSLv3/TLS read server session ticket"; - break; - case TLS_ST_CR_SRVR_DONE: - str = "SSLv3/TLS read server done"; - break; - case TLS_ST_CW_CERT: - str = "SSLv3/TLS write client certificate"; - break; - case TLS_ST_CW_KEY_EXCH: - str = "SSLv3/TLS write client key exchange"; - break; - case TLS_ST_CW_CERT_VRFY: - str = "SSLv3/TLS write certificate verify"; - break; - case TLS_ST_CW_CHANGE: - case TLS_ST_SW_CHANGE: - str = "SSLv3/TLS write change cipher spec"; - break; - case TLS_ST_CW_FINISHED: - case TLS_ST_SW_FINISHED: - str = "SSLv3/TLS write finished"; - break; - case TLS_ST_CR_CHANGE: - case TLS_ST_SR_CHANGE: - str = "SSLv3/TLS read change cipher spec"; - break; - case TLS_ST_CR_FINISHED: - case TLS_ST_SR_FINISHED: - str = "SSLv3/TLS read finished"; - break; - case TLS_ST_SR_CLNT_HELLO: - str = "SSLv3/TLS read client hello"; - break; - case TLS_ST_SW_HELLO_REQ: - str = "SSLv3/TLS write hello request"; - break; - case TLS_ST_SW_SRVR_HELLO: - str = "SSLv3/TLS write server hello"; - break; - case TLS_ST_SW_CERT: - str = "SSLv3/TLS write certificate"; - break; - case TLS_ST_SW_KEY_EXCH: - str = "SSLv3/TLS write key exchange"; - break; - case TLS_ST_SW_CERT_REQ: - str = "SSLv3/TLS write certificate request"; - break; - case TLS_ST_SW_SESSION_TICKET: - str = "SSLv3/TLS write session ticket"; - break; - case TLS_ST_SW_SRVR_DONE: - str = "SSLv3/TLS write server done"; - break; - case TLS_ST_SR_CERT: - str = "SSLv3/TLS read client certificate"; - break; - case TLS_ST_SR_KEY_EXCH: - str = "SSLv3/TLS read client key exchange"; - break; - case TLS_ST_SR_CERT_VRFY: - str = "SSLv3/TLS read certificate verify"; - break; - case DTLS_ST_CR_HELLO_VERIFY_REQUEST: - str = "DTLS1 read hello verify request"; - break; - case DTLS_ST_SW_HELLO_VERIFY_REQUEST: - str = "DTLS1 write hello verify request"; - break; - default: - break; - } - } - - return str; -} - -/** * @brief set the SSL context read buffer length */ void SSL_CTX_set_default_read_buffer_len(SSL_CTX *ctx, size_t len) @@ -1660,21 +1146,22 @@ /* find out how many entries he gave us */ - len = *p++; - while (p - ac->data < ac->len) { - if (len--) { - p++; - continue; - } - count++; + if (ac->len) { len = *p++; - if (!len) - break; + if (len) + count++; + while (p - ac->data < ac->len) { + if (len--) { + p++; + continue; + } + len = *p++; + if (!len) + break; + count++; + } } - if (!len) - count++; - if (!count) return; diff -Nru libwebsockets-3.2.1/lib/tls/mbedtls/wrapper/library/ssl_methods.c libwebsockets-4.1.6/lib/tls/mbedtls/wrapper/library/ssl_methods.c --- libwebsockets-3.2.1/lib/tls/mbedtls/wrapper/library/ssl_methods.c 2019-12-18 14:45:31.000000000 +0000 +++ libwebsockets-4.1.6/lib/tls/mbedtls/wrapper/library/ssl_methods.c 2020-12-01 17:40:26.000000000 +0000 @@ -34,24 +34,28 @@ IMPLEMENT_TLS_METHOD(TLS1_2_VERSION, 0, TLS_method_func, TLSv1_2_client_method); +#if 0 IMPLEMENT_TLS_METHOD(TLS1_1_VERSION, 0, TLS_method_func, TLSv1_1_client_method); IMPLEMENT_TLS_METHOD(TLS1_VERSION, 0, TLS_method_func, TLSv1_client_method); IMPLEMENT_SSL_METHOD(SSL3_VERSION, 0, TLS_method_func, SSLv3_client_method); +#endif /** * TLS or SSL server method collection */ IMPLEMENT_TLS_METHOD(TLS_ANY_VERSION, 1, TLS_method_func, TLS_server_method); -IMPLEMENT_TLS_METHOD(TLS1_1_VERSION, 1, TLS_method_func, TLSv1_1_server_method); - IMPLEMENT_TLS_METHOD(TLS1_2_VERSION, 1, TLS_method_func, TLSv1_2_server_method); +#if 0 +IMPLEMENT_TLS_METHOD(TLS1_1_VERSION, 1, TLS_method_func, TLSv1_1_server_method); + IMPLEMENT_TLS_METHOD(TLS1_VERSION, 0, TLS_method_func, TLSv1_server_method); IMPLEMENT_SSL_METHOD(SSL3_VERSION, 1, TLS_method_func, SSLv3_server_method); +#endif /** * TLS or SSL method collection @@ -60,11 +64,13 @@ IMPLEMENT_SSL_METHOD(TLS1_2_VERSION, -1, TLS_method_func, TLSv1_2_method); +#if 0 IMPLEMENT_SSL_METHOD(TLS1_1_VERSION, -1, TLS_method_func, TLSv1_1_method); IMPLEMENT_SSL_METHOD(TLS1_VERSION, -1, TLS_method_func, TLSv1_method); IMPLEMENT_SSL_METHOD(SSL3_VERSION, -1, TLS_method_func, SSLv3_method); +#endif /** * @brief get X509 object method diff -Nru libwebsockets-3.2.1/lib/tls/mbedtls/wrapper/library/ssl_x509.c libwebsockets-4.1.6/lib/tls/mbedtls/wrapper/library/ssl_x509.c --- libwebsockets-3.2.1/lib/tls/mbedtls/wrapper/library/ssl_x509.c 2019-12-18 14:45:31.000000000 +0000 +++ libwebsockets-4.1.6/lib/tls/mbedtls/wrapper/library/ssl_x509.c 2020-12-01 17:40:26.000000000 +0000 @@ -286,8 +286,7 @@ /** * @brief load certification into the SSL */ -int SSL_use_certificate_ASN1(SSL *ssl, int len, - const unsigned char *d) +int SSL_use_certificate_ASN1(SSL *ssl, const unsigned char *d, int len) { int ret; X509 *x; diff -Nru libwebsockets-3.2.1/lib/tls/mbedtls/wrapper/platform/ssl_pm.c libwebsockets-4.1.6/lib/tls/mbedtls/wrapper/platform/ssl_pm.c --- libwebsockets-3.2.1/lib/tls/mbedtls/wrapper/platform/ssl_pm.c 2019-12-18 14:45:31.000000000 +0000 +++ libwebsockets-4.1.6/lib/tls/mbedtls/wrapper/platform/ssl_pm.c 2020-12-01 17:40:26.000000000 +0000 @@ -18,14 +18,18 @@ /* mbedtls include */ #include "mbedtls/platform.h" +#if defined(LWS_HAVE_MBEDTLS_NET_SOCKETS) #include "mbedtls/net_sockets.h" +#else +#include "mbedtls/net.h" +#endif #include "mbedtls/debug.h" #include "mbedtls/entropy.h" #include "mbedtls/ctr_drbg.h" #include "mbedtls/error.h" #include "mbedtls/certs.h" -#include "core/private.h" +#include "private-lib-core.h" #define X509_INFO_STRING_LENGTH 8192 @@ -63,6 +67,7 @@ unsigned int max_content_len; + /*********************************************************************************************/ /************************************ SSL arch interface *************************************/ @@ -181,7 +186,9 @@ goto mbedtls_err2; } - mbedtls_ssl_set_bio(&ssl_pm->ssl, &ssl_pm->fd, mbedtls_net_send, mbedtls_net_recv, NULL); + mbedtls_ssl_set_bio(&ssl_pm->ssl, &ssl_pm->fd, + lws_plat_mbedtls_net_send, + lws_plat_mbedtls_net_recv, NULL); ssl->ssl_pm = ssl_pm; @@ -544,6 +551,7 @@ int x509_pm_show_info(X509 *x) { +#if 0 int ret; char *buf; mbedtls_x509_crt *x509_crt; @@ -583,6 +591,9 @@ ssl_mem_free(buf); no_mem: return -1; +#else + return 0; +#endif } int x509_pm_new(X509 *x, X509 *m_x) diff -Nru libwebsockets-3.2.1/lib/tls/mbedtls/x509.c libwebsockets-4.1.6/lib/tls/mbedtls/x509.c --- libwebsockets-3.2.1/lib/tls/mbedtls/x509.c 2019-12-18 14:45:31.000000000 +0000 +++ libwebsockets-4.1.6/lib/tls/mbedtls/x509.c 1970-01-01 00:00:00.000000000 +0000 @@ -1,431 +0,0 @@ -/* - * libwebsockets - mbedTLS-specific lws apis - * - * Copyright (C) 2010-2019 Andy Green - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation: - * version 2.1 of the License. - * - * This library is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with this library; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, - * MA 02110-1301 USA - */ - -#include "core/private.h" -#include "tls/mbedtls/private.h" -#include - -#if defined(LWS_PLAT_OPTEE) || defined(OPTEE_DEV_KIT) -struct tm { -int tm_sec; // seconds [0,61] -int tm_min; // minutes [0,59] -int tm_hour; // hour [0,23] -int tm_mday; // day of month [1,31] -int tm_mon; // month of year [0,11] -int tm_year; // years since 1900 -int tm_wday; // day of week [0,6] (Sunday = 0) -int tm_yday; // day of year [0,365] -int tm_isdst; // daylight savings flag -}; -time_t mktime(struct tm *t) -{ - return (time_t)0; -} -#endif - -static time_t -lws_tls_mbedtls_time_to_unix(mbedtls_x509_time *xtime) -{ - struct tm t; - - if (!xtime || !xtime->year || xtime->year < 0) - return (time_t)(long long)-1; - - memset(&t, 0, sizeof(t)); - - t.tm_year = xtime->year - 1900; - t.tm_mon = xtime->mon - 1; /* mbedtls months are 1+, tm are 0+ */ - t.tm_mday = xtime->day - 1; /* mbedtls days are 1+, tm are 0+ */ - t.tm_hour = xtime->hour; - t.tm_min = xtime->min; - t.tm_sec = xtime->sec; - t.tm_isdst = -1; - - return mktime(&t); -} - -static int -lws_tls_mbedtls_get_x509_name(mbedtls_x509_name *name, - union lws_tls_cert_info_results *buf, size_t len) -{ - while (name) { - if (MBEDTLS_OID_CMP(MBEDTLS_OID_AT_CN, &name->oid)) { - name = name->next; - continue; - } - - if (len - 1 < name->val.len) - return -1; - - memcpy(&buf->ns.name[0], name->val.p, name->val.len); - buf->ns.name[name->val.len] = '\0'; - buf->ns.len = name->val.len; - - return 0; - } - - return -1; -} - -static int -lws_tls_mbedtls_cert_info(mbedtls_x509_crt *x509, enum lws_tls_cert_info type, - union lws_tls_cert_info_results *buf, size_t len) -{ - if (!x509) - return -1; - - switch (type) { - case LWS_TLS_CERT_INFO_VALIDITY_FROM: - buf->time = lws_tls_mbedtls_time_to_unix(&x509->valid_from); - if (buf->time == (time_t)(long long)-1) - return -1; - break; - - case LWS_TLS_CERT_INFO_VALIDITY_TO: - buf->time = lws_tls_mbedtls_time_to_unix(&x509->valid_to); - if (buf->time == (time_t)(long long)-1) - return -1; - break; - - case LWS_TLS_CERT_INFO_COMMON_NAME: - return lws_tls_mbedtls_get_x509_name(&x509->subject, buf, len); - - case LWS_TLS_CERT_INFO_ISSUER_NAME: - return lws_tls_mbedtls_get_x509_name(&x509->issuer, buf, len); - - case LWS_TLS_CERT_INFO_USAGE: - buf->usage = x509->key_usage; - break; - - case LWS_TLS_CERT_INFO_OPAQUE_PUBLIC_KEY: - { - char *p = buf->ns.name; - size_t r = len, u; - - switch (mbedtls_pk_get_type(&x509->pk)) { - case MBEDTLS_PK_RSA: - { - mbedtls_rsa_context *rsa = mbedtls_pk_rsa(x509->pk); - - if (mbedtls_mpi_write_string(&rsa->N, 16, p, r, &u)) - return -1; - r -= u; - p += u; - if (mbedtls_mpi_write_string(&rsa->E, 16, p, r, &u)) - return -1; - - p += u; - buf->ns.len = lws_ptr_diff(p, buf->ns.name); - break; - } - case MBEDTLS_PK_ECKEY: - { - mbedtls_ecp_keypair *ecp = mbedtls_pk_ec(x509->pk); - - if (mbedtls_mpi_write_string(&ecp->Q.X, 16, p, r, &u)) - return -1; - r -= u; - p += u; - if (mbedtls_mpi_write_string(&ecp->Q.Y, 16, p, r, &u)) - return -1; - r -= u; - p += u; - if (mbedtls_mpi_write_string(&ecp->Q.Z, 16, p, r, &u)) - return -1; - p += u; - buf->ns.len = lws_ptr_diff(p, buf->ns.name); - break; - } - default: - lwsl_notice("%s: x509 has unsupported pubkey type %d\n", - __func__, - mbedtls_pk_get_type(&x509->pk)); - - return -1; - } - break; - } - - default: - return -1; - } - - return 0; -} - -#if defined(LWS_WITH_NETWORK) -int -lws_tls_vhost_cert_info(struct lws_vhost *vhost, enum lws_tls_cert_info type, - union lws_tls_cert_info_results *buf, size_t len) -{ - mbedtls_x509_crt *x509; - - x509 = ssl_ctx_get_mbedtls_x509_crt(vhost->tls.ssl_ctx); - - return lws_tls_mbedtls_cert_info(x509, type, buf, len); -} - -int -lws_tls_peer_cert_info(struct lws *wsi, enum lws_tls_cert_info type, - union lws_tls_cert_info_results *buf, size_t len) -{ - mbedtls_x509_crt *x509; - - wsi = lws_get_network_wsi(wsi); - - x509 = ssl_get_peer_mbedtls_x509_crt(wsi->tls.ssl); - - if (!x509) - return -1; - - switch (type) { - case LWS_TLS_CERT_INFO_VERIFIED: - buf->verified = SSL_get_verify_result(wsi->tls.ssl) == X509_V_OK; - return 0; - default: - return lws_tls_mbedtls_cert_info(x509, type, buf, len); - } - - return -1; -} -#endif - -int -lws_x509_info(struct lws_x509_cert *x509, enum lws_tls_cert_info type, - union lws_tls_cert_info_results *buf, size_t len) -{ - return lws_tls_mbedtls_cert_info(&x509->cert, type, buf, len); -} - -int -lws_x509_create(struct lws_x509_cert **x509) -{ - *x509 = lws_malloc(sizeof(**x509), __func__); - - return !(*x509); -} - -/* - * Parse one DER-encoded or one or more concatenated PEM-encoded certificates - * and add them to the chained list. - */ - -int -lws_x509_parse_from_pem(struct lws_x509_cert *x509, const void *pem, size_t len) -{ - int ret; - - mbedtls_x509_crt_init(&x509->cert); - - ret = mbedtls_x509_crt_parse(&x509->cert, pem, len); - if (ret) { - mbedtls_x509_crt_free(&x509->cert); - lwsl_err("%s: unable to parse PEM cert: -0x%x\n", - __func__, -ret); - - return -1; - } - - return 0; -} - -int -lws_x509_verify(struct lws_x509_cert *x509, struct lws_x509_cert *trusted, - const char *common_name) -{ - uint32_t flags = 0; - int ret; - - ret = mbedtls_x509_crt_verify_with_profile(&x509->cert, &trusted->cert, - NULL, - &mbedtls_x509_crt_profile_next, - common_name, &flags, NULL, - NULL); - - if (ret) { - lwsl_err("%s: unable to parse PEM cert: -0x%x\n", - __func__, -ret); - - return -1; - } - - return 0; -} - -#if defined(LWS_WITH_JOSE) - -int -lws_x509_public_to_jwk(struct lws_jwk *jwk, struct lws_x509_cert *x509, - const char *curves, int rsa_min_bits) -{ - int kt = mbedtls_pk_get_type(&x509->cert.pk), n, count = 0, ret = -1; - mbedtls_rsa_context *rsactx; - mbedtls_ecp_keypair *ecpctx; - mbedtls_mpi *mpi[LWS_GENCRYPTO_RSA_KEYEL_COUNT]; - - memset(jwk, 0, sizeof(*jwk)); - - switch (kt) { - case MBEDTLS_PK_RSA: - lwsl_notice("%s: RSA key\n", __func__); - jwk->kty = LWS_GENCRYPTO_KTY_RSA; - rsactx = mbedtls_pk_rsa(x509->cert.pk); - - mpi[LWS_GENCRYPTO_RSA_KEYEL_E] = &rsactx->E; - mpi[LWS_GENCRYPTO_RSA_KEYEL_N] = &rsactx->N; - mpi[LWS_GENCRYPTO_RSA_KEYEL_D] = &rsactx->D; - mpi[LWS_GENCRYPTO_RSA_KEYEL_P] = &rsactx->P; - mpi[LWS_GENCRYPTO_RSA_KEYEL_Q] = &rsactx->Q; - mpi[LWS_GENCRYPTO_RSA_KEYEL_DP] = &rsactx->DP; - mpi[LWS_GENCRYPTO_RSA_KEYEL_DQ] = &rsactx->DQ; - mpi[LWS_GENCRYPTO_RSA_KEYEL_QI] = &rsactx->QP; - - count = LWS_GENCRYPTO_RSA_KEYEL_COUNT; - n = LWS_GENCRYPTO_RSA_KEYEL_E; - break; - - case MBEDTLS_PK_ECKEY: - lwsl_notice("%s: EC key\n", __func__); - jwk->kty = LWS_GENCRYPTO_KTY_EC; - ecpctx = mbedtls_pk_ec(x509->cert.pk); - mpi[LWS_GENCRYPTO_EC_KEYEL_X] = &ecpctx->Q.X; - mpi[LWS_GENCRYPTO_EC_KEYEL_D] = &ecpctx->d; - mpi[LWS_GENCRYPTO_EC_KEYEL_Y] = &ecpctx->Q.Y; - - if (lws_genec_confirm_curve_allowed_by_tls_id(curves, - ecpctx->grp.id, jwk)) - /* already logged */ - goto bail; - - count = LWS_GENCRYPTO_EC_KEYEL_COUNT; - n = LWS_GENCRYPTO_EC_KEYEL_X; - break; - default: - lwsl_err("%s: key type %d not supported\n", __func__, kt); - - return -1; - } - - for (; n < count; n++) { - if (!mbedtls_mpi_size(mpi[n])) - continue; - - jwk->e[n].buf = lws_malloc(mbedtls_mpi_size(mpi[n]), "certjwk"); - if (!jwk->e[n].buf) - goto bail; - jwk->e[n].len = mbedtls_mpi_size(mpi[n]); - mbedtls_mpi_write_binary(mpi[n], jwk->e[n].buf, jwk->e[n].len); - } - - ret = 0; - -bail: - /* jwk destroy will clean up partials */ - if (ret) - lws_jwk_destroy(jwk); - - return ret; -} - -int -lws_x509_jwk_privkey_pem(struct lws_jwk *jwk, void *pem, size_t len, - const char *passphrase) -{ - mbedtls_rsa_context *rsactx; - mbedtls_ecp_keypair *ecpctx; - mbedtls_pk_context pk; - mbedtls_mpi *mpi[LWS_GENCRYPTO_RSA_KEYEL_COUNT]; - int n, ret = -1, count = 0; - - mbedtls_pk_init(&pk); - - n = 0; - if (passphrase) - n = strlen(passphrase); - n = mbedtls_pk_parse_key(&pk, pem, len, (uint8_t *)passphrase, n); - if (n) { - lwsl_err("%s: parse PEM key failed: -0x%x\n", __func__, -n); - - return -1; - } - - /* the incoming private key type */ - switch (mbedtls_pk_get_type(&pk)) { - case MBEDTLS_PK_RSA: - if (jwk->kty != LWS_GENCRYPTO_KTY_RSA) { - lwsl_err("%s: RSA privkey, non-RSA jwk\n", __func__); - goto bail; - } - rsactx = mbedtls_pk_rsa(pk); - mpi[LWS_GENCRYPTO_RSA_KEYEL_D] = &rsactx->D; - mpi[LWS_GENCRYPTO_RSA_KEYEL_P] = &rsactx->P; - mpi[LWS_GENCRYPTO_RSA_KEYEL_Q] = &rsactx->Q; - n = LWS_GENCRYPTO_RSA_KEYEL_D; - count = LWS_GENCRYPTO_RSA_KEYEL_Q + 1; - break; - case MBEDTLS_PK_ECKEY: - if (jwk->kty != LWS_GENCRYPTO_KTY_EC) { - lwsl_err("%s: EC privkey, non-EC jwk\n", __func__); - goto bail; - } - ecpctx = mbedtls_pk_ec(pk); - mpi[LWS_GENCRYPTO_EC_KEYEL_D] = &ecpctx->d; - n = LWS_GENCRYPTO_EC_KEYEL_D; - count = n + 1; - break; - default: - lwsl_err("%s: unusable key type %d\n", __func__, - mbedtls_pk_get_type(&pk)); - goto bail; - } - - for (; n < count; n++) { - if (!mbedtls_mpi_size(mpi[n])) { - lwsl_err("%s: empty privkey\n", __func__); - goto bail; - } - - jwk->e[n].buf = lws_malloc(mbedtls_mpi_size(mpi[n]), "certjwk"); - if (!jwk->e[n].buf) - goto bail; - jwk->e[n].len = mbedtls_mpi_size(mpi[n]); - mbedtls_mpi_write_binary(mpi[n], jwk->e[n].buf, jwk->e[n].len); - } - - ret = 0; - -bail: - mbedtls_pk_free(&pk); - - return ret; -} -#endif - -void -lws_x509_destroy(struct lws_x509_cert **x509) -{ - if (!*x509) - return; - - mbedtls_x509_crt_free(&(*x509)->cert); - - lws_free_set_NULL(*x509); -} diff -Nru libwebsockets-3.2.1/lib/tls/openssl/lws-genaes.c libwebsockets-4.1.6/lib/tls/openssl/lws-genaes.c --- libwebsockets-3.2.1/lib/tls/openssl/lws-genaes.c 2019-12-18 14:45:31.000000000 +0000 +++ libwebsockets-4.1.6/lib/tls/openssl/lws-genaes.c 2020-12-01 17:40:26.000000000 +0000 @@ -1,35 +1,40 @@ -/* - * libwebsockets - generic AES api hiding the backend + /* + * libwebsockets - small server side websockets and web server implementation * - * Copyright (C) 2017 - 2018 Andy Green + * Copyright (C) 2010 - 2019 Andy Green * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation: - * version 2.1 of the License. + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to + * deal in the Software without restriction, including without limitation the + * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or + * sell copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: * - * This library is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. * - * You should have received a copy of the GNU Lesser General Public - * License along with this library; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, - * MA 02110-1301 USA + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS + * IN THE SOFTWARE. * * lws_genaes provides an AES abstraction api in lws that works the * same whether you are using openssl or mbedtls hash functions underneath. */ -#include "core/private.h" -#include "../../jose/private.h" +#include "private-lib-core.h" +#if defined(LWS_WITH_JOSE) +#include "private-lib-jose.h" +#endif /* * Care: many openssl apis return 1 for success. These are translated to the * lws convention of 0 for success. */ -LWS_VISIBLE int +int lws_genaes_create(struct lws_genaes_ctx *ctx, enum enum_aes_operation op, enum enum_aes_modes mode, struct lws_gencrypto_keyelem *el, enum enum_aes_padding padding, void *engine) @@ -231,11 +236,11 @@ return -1; } -LWS_VISIBLE int +int lws_genaes_destroy(struct lws_genaes_ctx *ctx, unsigned char *tag, size_t tlen) { - int outl = 0, n = 0; uint8_t buf[256]; + int outl = sizeof(buf), n = 0; if (!ctx->ctx) return 0; @@ -258,7 +263,11 @@ n = 1; } } + if (ctx->mode == LWS_GAESM_CBC) + memcpy(tag, buf, outl); + break; + case LWS_GAESO_DEC: if (EVP_DecryptFinal_ex(ctx->ctx, buf, &outl) != 1) { lwsl_err("%s: dec final failed\n", __func__); @@ -279,7 +288,7 @@ return n; } -LWS_VISIBLE int +int lws_genaes_crypt(struct lws_genaes_ctx *ctx, const uint8_t *in, size_t len, uint8_t *out, uint8_t *iv_or_nonce_ctr_or_data_unit_16, @@ -293,7 +302,7 @@ if (ctx->mode == LWS_GAESM_GCM) { n = EVP_CIPHER_CTX_ctrl(ctx->ctx, EVP_CTRL_GCM_SET_IVLEN, - *nc_or_iv_off, NULL); + (int)*nc_or_iv_off, NULL); if (n != 1) { lwsl_err("%s: SET_IVLEN failed\n", __func__); return -1; @@ -337,10 +346,10 @@ switch (ctx->op) { case LWS_GAESO_ENC: - n = EVP_EncryptUpdate(ctx->ctx, NULL, &olen, in, len); + n = EVP_EncryptUpdate(ctx->ctx, NULL, &olen, in, (int)len); break; case LWS_GAESO_DEC: - n = EVP_DecryptUpdate(ctx->ctx, NULL, &olen, in, len); + n = EVP_DecryptUpdate(ctx->ctx, NULL, &olen, in, (int)len); break; default: return -1; @@ -357,10 +366,10 @@ switch (ctx->op) { case LWS_GAESO_ENC: - n = EVP_EncryptUpdate(ctx->ctx, out, &outl, in, len); + n = EVP_EncryptUpdate(ctx->ctx, out, &outl, in, (int)len); break; case LWS_GAESO_DEC: - n = EVP_DecryptUpdate(ctx->ctx, out, &outl, in, len); + n = EVP_DecryptUpdate(ctx->ctx, out, &outl, in, (int)len); break; default: return -1; diff -Nru libwebsockets-3.2.1/lib/tls/openssl/lws-gencrypto.c libwebsockets-4.1.6/lib/tls/openssl/lws-gencrypto.c --- libwebsockets-3.2.1/lib/tls/openssl/lws-gencrypto.c 2019-12-18 14:45:31.000000000 +0000 +++ libwebsockets-4.1.6/lib/tls/openssl/lws-gencrypto.c 2020-12-01 17:40:26.000000000 +0000 @@ -1,28 +1,31 @@ -/* - * libwebsockets - generic crypto api hiding the backend + /* + * libwebsockets - small server side websockets and web server implementation * - * Copyright (C) 2017 - 2018 Andy Green + * Copyright (C) 2010 - 2019 Andy Green * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation: - * version 2.1 of the License. + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to + * deal in the Software without restriction, including without limitation the + * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or + * sell copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: * - * This library is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. * - * You should have received a copy of the GNU Lesser General Public - * License along with this library; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, - * MA 02110-1301 USA + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS + * IN THE SOFTWARE. * * lws-gencrypto openssl-specific common code */ -#include "core/private.h" -#include "tls/openssl/private.h" +#include "private-lib-core.h" +#include "private-lib-tls-openssl.h" /* * Care: many openssl apis return 1 for success. These are translated to the diff -Nru libwebsockets-3.2.1/lib/tls/openssl/lws-genec.c libwebsockets-4.1.6/lib/tls/openssl/lws-genec.c --- libwebsockets-3.2.1/lib/tls/openssl/lws-genec.c 2019-12-18 14:45:31.000000000 +0000 +++ libwebsockets-4.1.6/lib/tls/openssl/lws-genec.c 2020-12-01 17:40:26.000000000 +0000 @@ -1,28 +1,31 @@ -/* - * libwebsockets - generic EC api hiding the backend - openssl implementation + /* + * libwebsockets - small server side websockets and web server implementation * - * Copyright (C) 2017 - 2018 Andy Green + * Copyright (C) 2010 - 2019 Andy Green * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation: - * version 2.1 of the License. + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to + * deal in the Software without restriction, including without limitation the + * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or + * sell copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: * - * This library is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. * - * You should have received a copy of the GNU Lesser General Public - * License along with this library; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, - * MA 02110-1301 USA + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS + * IN THE SOFTWARE. * * lws_genec provides an EC abstraction api in lws that works the * same whether you are using openssl or mbedtls crypto functions underneath. */ -#include "core/private.h" -#include "tls/openssl/private.h" +#include "private-lib-core.h" +#include "private-lib-tls-openssl.h" /* * Care: many openssl apis return 1 for success. These are translated to the @@ -223,7 +226,7 @@ return -9; } -LWS_VISIBLE int +int lws_genecdh_create(struct lws_genec_ctx *ctx, struct lws_context *context, const struct lws_ec_curves *curve_table) { @@ -236,7 +239,7 @@ return 0; } -LWS_VISIBLE int +int lws_genecdsa_create(struct lws_genec_ctx *ctx, struct lws_context *context, const struct lws_ec_curves *curve_table) { @@ -249,7 +252,7 @@ return 0; } -LWS_VISIBLE int +int lws_genecdh_set_key(struct lws_genec_ctx *ctx, struct lws_gencrypto_keyelem *el, enum enum_lws_dh_side side) { @@ -259,7 +262,7 @@ return lws_genec_keypair_import(ctx, ctx->curve_table, &ctx->ctx[side], el); } -LWS_VISIBLE int +int lws_genecdsa_set_key(struct lws_genec_ctx *ctx, struct lws_gencrypto_keyelem *el) { @@ -283,7 +286,7 @@ *pctx = NULL; } -LWS_VISIBLE void +void lws_genec_destroy(struct lws_genec_ctx *ctx) { if (ctx->ctx[0]) @@ -363,7 +366,7 @@ goto bail2; } - el[LWS_GENCRYPTO_EC_KEYEL_CRV].len = strlen(curve_name) + 1; + el[LWS_GENCRYPTO_EC_KEYEL_CRV].len = (uint32_t)strlen(curve_name) + 1; el[LWS_GENCRYPTO_EC_KEYEL_CRV].buf = lws_malloc(el[LWS_GENCRYPTO_EC_KEYEL_CRV].len, "ec"); if (!el[LWS_GENCRYPTO_EC_KEYEL_CRV].buf) { @@ -400,7 +403,7 @@ return ret; } -LWS_VISIBLE int +int lws_genecdh_new_keypair(struct lws_genec_ctx *ctx, enum enum_lws_dh_side side, const char *curve_name, struct lws_gencrypto_keyelem *el) @@ -411,7 +414,7 @@ return lws_genec_new_keypair(ctx, side, curve_name, el); } -LWS_VISIBLE int +int lws_genecdsa_new_keypair(struct lws_genec_ctx *ctx, const char *curve_name, struct lws_gencrypto_keyelem *el) { @@ -422,7 +425,7 @@ } #if 0 -LWS_VISIBLE LWS_EXTERN int +int lws_genecdsa_hash_sign(struct lws_genec_ctx *ctx, const uint8_t *in, enum lws_genhash_types hash_type, uint8_t *sig, size_t sig_len) @@ -468,7 +471,7 @@ } #endif -LWS_VISIBLE LWS_EXTERN int +int lws_genecdsa_hash_sign_jws(struct lws_genec_ctx *ctx, const uint8_t *in, enum lws_genhash_types hash_type, int keybits, uint8_t *sig, size_t sig_len) @@ -513,7 +516,7 @@ * 4. The resulting 64-octet sequence is the JWS Signature value. */ - ecdsasig = ECDSA_do_sign(in, lws_genhash_size(hash_type), eckey); + ecdsasig = ECDSA_do_sign(in, (int)lws_genhash_size(hash_type), eckey); EC_KEY_free(eckey); if (!ecdsasig) { lwsl_notice("%s: ECDSA_do_sign fail\n", __func__); @@ -550,13 +553,13 @@ /* in is the JWS Signing Input hash */ -LWS_VISIBLE LWS_EXTERN int +int lws_genecdsa_hash_sig_verify_jws(struct lws_genec_ctx *ctx, const uint8_t *in, enum lws_genhash_types hash_type, int keybits, const uint8_t *sig, size_t sig_len) { int ret = -1, n, keybytes = lws_gencrypto_bits_to_bytes(keybits), - hlen = lws_genhash_size(hash_type); + hlen = (int)lws_genhash_size(hash_type); ECDSA_SIG *ecsig = ECDSA_SIG_new(); BIGNUM *r = NULL, *s = NULL; EC_KEY *eckey; diff -Nru libwebsockets-3.2.1/lib/tls/openssl/lws-genhash.c libwebsockets-4.1.6/lib/tls/openssl/lws-genhash.c --- libwebsockets-3.2.1/lib/tls/openssl/lws-genhash.c 2019-12-18 14:45:31.000000000 +0000 +++ libwebsockets-4.1.6/lib/tls/openssl/lws-genhash.c 2020-12-01 17:40:26.000000000 +0000 @@ -1,22 +1,25 @@ -/* - * libwebsockets - generic hash and HMAC api hiding the backend + /* + * libwebsockets - small server side websockets and web server implementation * - * Copyright (C) 2017 Andy Green + * Copyright (C) 2010 - 2019 Andy Green * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation: - * version 2.1 of the License. + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to + * deal in the Software without restriction, including without limitation the + * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or + * sell copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: * - * This library is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. * - * You should have received a copy of the GNU Lesser General Public - * License along with this library; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, - * MA 02110-1301 USA + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS + * IN THE SOFTWARE. * * lws_genhash provides a hash / hmac abstraction api in lws that works the * same whether you are using openssl or mbedtls hash functions underneath. @@ -90,6 +93,78 @@ return ret; } +#if defined(LWS_HAVE_EVP_PKEY_new_raw_private_key) + +int +lws_genhmac_init(struct lws_genhmac_ctx *ctx, enum lws_genhmac_types type, + const uint8_t *key, size_t key_len) +{ + ctx->ctx = EVP_MD_CTX_create(); + if (!ctx->ctx) + return -1; + + ctx->evp_type = 0; + ctx->type = type; + + switch (type) { + case LWS_GENHMAC_TYPE_SHA256: + ctx->evp_type = EVP_sha256(); + break; + case LWS_GENHMAC_TYPE_SHA384: + ctx->evp_type = EVP_sha384(); + break; + case LWS_GENHMAC_TYPE_SHA512: + ctx->evp_type = EVP_sha512(); + break; + default: + lwsl_err("%s: unknown HMAC type %d\n", __func__, type); + goto bail; + } + + ctx->key = EVP_PKEY_new_raw_private_key(EVP_PKEY_HMAC, NULL, key, key_len); + if (!ctx->key) + goto bail; + + if (EVP_DigestSignInit(ctx->ctx, NULL, ctx->evp_type, NULL, ctx->key) != 1) + goto bail1; + + return 0; + +bail1: + EVP_PKEY_free(ctx->key); +bail: + EVP_MD_CTX_free(ctx->ctx); + + return -1; +} + +int +lws_genhmac_update(struct lws_genhmac_ctx *ctx, const void *in, size_t len) +{ + + if (EVP_DigestSignUpdate(ctx->ctx, in, len) != 1) + return -1; + + return 0; +} + +int +lws_genhmac_destroy(struct lws_genhmac_ctx *ctx, void *result) +{ + size_t size = (size_t)lws_genhmac_size(ctx->type); + int n; + + n = EVP_DigestSignFinal(ctx->ctx, result, &size); + EVP_MD_CTX_free(ctx->ctx); + EVP_PKEY_free(ctx->key); + + if (n != 1) + return -1; + + return 0; +} + +#else int lws_genhmac_init(struct lws_genhmac_ctx *ctx, enum lws_genhmac_types type, @@ -103,7 +178,8 @@ HMAC_CTX_init(&ctx->ctx); #endif - ctx->evp_type = 0; /* coverity unable to see we set this or fail */ + ctx->evp_type = 0; + ctx->type = type; switch (type) { case LWS_GENHMAC_TYPE_SHA256: @@ -121,9 +197,9 @@ } #if defined(LWS_HAVE_HMAC_CTX_new) - if (HMAC_Init_ex(ctx->ctx, key, key_len, ctx->evp_type, NULL) != 1) + if (HMAC_Init_ex(ctx->ctx, key, (int)key_len, ctx->evp_type, NULL) != 1) #else - if (HMAC_Init_ex(&ctx->ctx, key, key_len, ctx->evp_type, NULL) != 1) + if (HMAC_Init_ex(&ctx->ctx, key, (int)key_len, ctx->evp_type, NULL) != 1) #endif goto bail; @@ -153,7 +229,7 @@ int lws_genhmac_destroy(struct lws_genhmac_ctx *ctx, void *result) { - unsigned int size = lws_genhmac_size(ctx->type); + unsigned int size = (unsigned int)lws_genhmac_size(ctx->type); #if defined(LWS_HAVE_HMAC_CTX_new) int n = HMAC_Final(ctx->ctx, result, &size); @@ -168,3 +244,5 @@ return 0; } + +#endif diff -Nru libwebsockets-3.2.1/lib/tls/openssl/lws-genrsa.c libwebsockets-4.1.6/lib/tls/openssl/lws-genrsa.c --- libwebsockets-3.2.1/lib/tls/openssl/lws-genrsa.c 2019-12-18 14:45:31.000000000 +0000 +++ libwebsockets-4.1.6/lib/tls/openssl/lws-genrsa.c 2020-12-01 17:40:26.000000000 +0000 @@ -1,35 +1,38 @@ -/* - * libwebsockets - generic RSA api hiding the backend + /* + * libwebsockets - small server side websockets and web server implementation * - * Copyright (C) 2017 - 2018 Andy Green + * Copyright (C) 2010 - 2019 Andy Green * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation: - * version 2.1 of the License. + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to + * deal in the Software without restriction, including without limitation the + * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or + * sell copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: * - * This library is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. * - * You should have received a copy of the GNU Lesser General Public - * License along with this library; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, - * MA 02110-1301 USA + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS + * IN THE SOFTWARE. * * lws_genrsa provides an RSA abstraction api in lws that works the * same whether you are using openssl or mbedtls crypto functions underneath. */ -#include "core/private.h" -#include "tls/openssl/private.h" +#include "private-lib-core.h" +#include "private-lib-tls-openssl.h" /* * Care: many openssl apis return 1 for success. These are translated to the * lws convention of 0 for success. */ -LWS_VISIBLE void +void lws_genrsa_destroy_elements(struct lws_gencrypto_keyelem *el) { lws_gencrypto_destroy_elements(el, LWS_GENCRYPTO_RSA_KEYEL_COUNT); @@ -73,7 +76,7 @@ return 1; } -LWS_VISIBLE int +int lws_genrsa_create(struct lws_genrsa_ctx *ctx, struct lws_gencrypto_keyelem *el, struct lws_context *context, enum enum_genrsa_mode mode, enum lws_genhash_types oaep_hashid) @@ -143,7 +146,7 @@ return 1; } -LWS_VISIBLE int +int lws_genrsa_new_keypair(struct lws_context *context, struct lws_genrsa_ctx *ctx, enum enum_genrsa_mode mode, struct lws_gencrypto_keyelem *el, int bits) @@ -217,7 +220,7 @@ * based padding modes */ -LWS_VISIBLE int +int lws_genrsa_public_encrypt(struct lws_genrsa_ctx *ctx, const uint8_t *in, size_t in_len, uint8_t *out) { @@ -232,7 +235,7 @@ return n; } -LWS_VISIBLE int +int lws_genrsa_private_encrypt(struct lws_genrsa_ctx *ctx, const uint8_t *in, size_t in_len, uint8_t *out) { @@ -247,7 +250,7 @@ return n; } -LWS_VISIBLE int +int lws_genrsa_public_decrypt(struct lws_genrsa_ctx *ctx, const uint8_t *in, size_t in_len, uint8_t *out, size_t out_max) { @@ -261,7 +264,7 @@ return n; } -LWS_VISIBLE int +int lws_genrsa_private_decrypt(struct lws_genrsa_ctx *ctx, const uint8_t *in, size_t in_len, uint8_t *out, size_t out_max) { @@ -276,7 +279,7 @@ return n; } -LWS_VISIBLE int +int lws_genrsa_hash_sig_verify(struct lws_genrsa_ctx *ctx, const uint8_t *in, enum lws_genhash_types hash_type, const uint8_t *sig, size_t sig_len) @@ -319,7 +322,7 @@ return 0; } -LWS_VISIBLE int +int lws_genrsa_hash_sign(struct lws_genrsa_ctx *ctx, const uint8_t *in, enum lws_genhash_types hash_type, uint8_t *sig, size_t sig_len) @@ -392,7 +395,7 @@ return -1; } -LWS_VISIBLE void +void lws_genrsa_destroy(struct lws_genrsa_ctx *ctx) { if (!ctx->ctx) diff -Nru libwebsockets-3.2.1/lib/tls/openssl/openssl-client.c libwebsockets-4.1.6/lib/tls/openssl/openssl-client.c --- libwebsockets-3.2.1/lib/tls/openssl/openssl-client.c 2019-12-18 14:45:31.000000000 +0000 +++ libwebsockets-4.1.6/lib/tls/openssl/openssl-client.c 2020-12-01 17:40:26.000000000 +0000 @@ -1,27 +1,36 @@ /* - * libwebsockets - openSSL-specific client tls code + * libwebsockets - small server side websockets and web server implementation * - * Copyright (C) 2010-2017 Andy Green + * Copyright (C) 2010 - 2019 Andy Green * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation: - * version 2.1 of the License. + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to + * deal in the Software without restriction, including without limitation the + * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or + * sell copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: * - * This library is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. * - * You should have received a copy of the GNU Lesser General Public - * License along with this library; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, - * MA 02110-1301 USA + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS + * IN THE SOFTWARE. */ -#include "core/private.h" +#include "lws_config.h" +#ifdef LWS_HAVE_X509_VERIFY_PARAM_set1_host +/* Before glibc 2.10, strnlen required _GNU_SOURCE */ +#define _GNU_SOURCE +#endif +#include -#include "tls/openssl/private.h" +#include "private-lib-core.h" +#include "private-lib-tls-openssl.h" /* * Care: many openssl apis return 1 for success. These are translated to the @@ -97,7 +106,7 @@ return 0; } - n = lws_get_context_protocol(wsi->context, 0).callback(wsi, + n = lws_get_context_protocol(wsi->a.context, 0).callback(wsi, LWS_CALLBACK_OPENSSL_PERFORM_SERVER_CERT_VERIFICATION, x509_ctx, ssl, preverify_ok); @@ -135,18 +144,26 @@ #if defined(LWS_HAVE_SSL_set_alpn_protos) && \ defined(LWS_HAVE_SSL_get0_alpn_selected) uint8_t openssl_alpn[40]; - const char *alpn_comma = wsi->context->tls.alpn_default; + const char *alpn_comma = wsi->a.context->tls.alpn_default; int n; #endif + if (wsi->stash) { + lws_strncpy(hostname, wsi->stash->cis[CIS_HOST], sizeof(hostname)); +#if defined(LWS_HAVE_SSL_set_alpn_protos) && \ + defined(LWS_HAVE_SSL_get0_alpn_selected) + alpn_comma = wsi->stash->cis[CIS_ALPN]; +#endif + } else { #if defined(LWS_ROLE_H1) || defined(LWS_ROLE_H2) - if (lws_hdr_copy(wsi, hostname, sizeof(hostname), - _WSI_TOKEN_CLIENT_HOST) <= 0) + if (lws_hdr_copy(wsi, hostname, sizeof(hostname), + _WSI_TOKEN_CLIENT_HOST) <= 0) #endif - { - lwsl_err("%s: Unable to get hostname\n", __func__); + { + lwsl_err("%s: Unable to get hostname\n", __func__); - return -1; + return -1; + } } /* @@ -162,7 +179,7 @@ p++; } - wsi->tls.ssl = SSL_new(wsi->vhost->tls.ssl_client_ctx); + wsi->tls.ssl = SSL_new(wsi->a.vhost->tls.ssl_client_ctx); if (!wsi->tls.ssl) { lwsl_err("SSL_new failed: %s\n", ERR_error_string(lws_ssl_get_error(wsi, 0), NULL)); @@ -171,20 +188,32 @@ } #if defined (LWS_HAVE_SSL_SET_INFO_CALLBACK) - if (wsi->vhost->tls.ssl_info_event_mask) + if (wsi->a.vhost->tls.ssl_info_event_mask) SSL_set_info_callback(wsi->tls.ssl, lws_ssl_info_callback); #endif -#if defined LWS_HAVE_X509_VERIFY_PARAM_set1_host +#if defined(LWS_HAVE_X509_VERIFY_PARAM_set1_host) if (!(wsi->tls.use_ssl & LCCSCF_SKIP_SERVER_CERT_HOSTNAME_CHECK)) { +#if !defined(USE_WOLFSSL) + X509_VERIFY_PARAM *param = SSL_get0_param(wsi->tls.ssl); /* Enable automatic hostname checks */ X509_VERIFY_PARAM_set_hostflags(param, X509_CHECK_FLAG_NO_PARTIAL_WILDCARDS); - // Handle the case where the hostname is an IP address. + /* Handle the case where the hostname is an IP address */ if (!X509_VERIFY_PARAM_set1_ip_asc(param, hostname)) - X509_VERIFY_PARAM_set1_host(param, hostname, 0); + X509_VERIFY_PARAM_set1_host(param, hostname, + strnlen(hostname, sizeof(hostname))); +#endif + + } +#else + if (!(wsi->tls.use_ssl & LCCSCF_SKIP_SERVER_CERT_HOSTNAME_CHECK)) { + lwsl_err("%s: your tls lib is too old to have " + "X509_VERIFY_PARAM_set1_host, failing all client tls\n", + __func__); + return -1; } #endif @@ -230,15 +259,15 @@ * Otherwise the connect will simply fail with error code -155 */ #ifdef USE_OLD_CYASSL - if (wsi->tls.use_ssl == 2) + if (wsi->tls.use_ssl & LCCSCF_ALLOW_SELFSIGNED) CyaSSL_set_verify(wsi->tls.ssl, SSL_VERIFY_NONE, NULL); #else - if (wsi->tls.use_ssl == 2) + if (wsi->tls.use_ssl & LCCSCF_ALLOW_SELFSIGNED) wolfSSL_set_verify(wsi->tls.ssl, SSL_VERIFY_NONE, NULL); #endif #endif /* USE_WOLFSSL */ - wsi->tls.client_bio = BIO_new_socket((int)(long long)wsi->desc.sockfd, + wsi->tls.client_bio = BIO_new_socket((int)(lws_intptr_t)wsi->desc.sockfd, BIO_NOCLOSE); SSL_set_bio(wsi->tls.ssl, wsi->tls.client_bio, wsi->tls.client_bio); @@ -254,15 +283,17 @@ #if defined(LWS_HAVE_SSL_set_alpn_protos) && \ defined(LWS_HAVE_SSL_get0_alpn_selected) - if (wsi->vhost->tls.alpn) - alpn_comma = wsi->vhost->tls.alpn; + if (wsi->a.vhost->tls.alpn) + alpn_comma = wsi->a.vhost->tls.alpn; + if (wsi->stash) + alpn_comma = wsi->stash->cis[CIS_ALPN]; #if defined(LWS_ROLE_H1) || defined(LWS_ROLE_H2) if (lws_hdr_copy(wsi, hostname, sizeof(hostname), _WSI_TOKEN_CLIENT_ALPN) > 0) alpn_comma = hostname; #endif - lwsl_info("client conn using alpn list '%s'\n", alpn_comma); + lwsl_info("%s client conn using alpn list '%s'\n", wsi->role_ops->name, alpn_comma); n = lws_alpn_comma_to_openssl(alpn_comma, openssl_alpn, sizeof(openssl_alpn) - 1); @@ -273,11 +304,87 @@ SSL_set_ex_data(wsi->tls.ssl, openssl_websocket_private_data_index, wsi); + if (wsi->sys_tls_client_cert) { + lws_system_blob_t *b = lws_system_get_blob(wsi->a.context, + LWS_SYSBLOB_TYPE_CLIENT_CERT_DER, + wsi->sys_tls_client_cert - 1); + const uint8_t *data; + size_t size; + + if (!b) + goto no_client_cert; + + /* + * Set up the per-connection client cert + */ + + size = lws_system_blob_get_size(b); + if (!size) + goto no_client_cert; + + if (lws_system_blob_get_single_ptr(b, &data)) + goto no_client_cert; + + if (SSL_use_certificate_ASN1(wsi->tls.ssl, +#if defined(USE_WOLFSSL) + (unsigned char *) +#endif + data, (int)size) != 1) { + lwsl_err("%s: use_certificate failed\n", __func__); + lws_tls_err_describe_clear(); + goto no_client_cert; + } + + b = lws_system_get_blob(wsi->a.context, + LWS_SYSBLOB_TYPE_CLIENT_KEY_DER, + wsi->sys_tls_client_cert - 1); + if (!b) + goto no_client_cert; + + size = lws_system_blob_get_size(b); + if (!size) + goto no_client_cert; + + if (lws_system_blob_get_single_ptr(b, &data)) + goto no_client_cert; + + if (SSL_use_PrivateKey_ASN1(EVP_PKEY_RSA, wsi->tls.ssl, +#if defined(USE_WOLFSSL) + (unsigned char *) +#endif + + data, (int)size) != 1 && + SSL_use_PrivateKey_ASN1(EVP_PKEY_EC, wsi->tls.ssl, +#if defined(USE_WOLFSSL) + (unsigned char *) +#endif + data, (int)size) != 1) { + lwsl_err("%s: use_privkey failed\n", __func__); + lws_tls_err_describe_clear(); + goto no_client_cert; + } + + if (SSL_check_private_key(wsi->tls.ssl) != 1) { + lwsl_err("Private SSL key doesn't match cert\n"); + lws_tls_err_describe_clear(); + return 1; + } + + lwsl_notice("%s: set system client cert %u\n", __func__, + wsi->sys_tls_client_cert - 1); + } + return 0; + +no_client_cert: + lwsl_err("%s: unable to set up system client cert %d\n", __func__, + wsi->sys_tls_client_cert - 1); + + return 1; } enum lws_ssl_capable_status -lws_tls_client_connect(struct lws *wsi) +lws_tls_client_connect(struct lws *wsi, char *errbuf, int elen) { #if defined(LWS_HAVE_SSL_set_alpn_protos) && \ defined(LWS_HAVE_SSL_get0_alpn_selected) @@ -285,12 +392,40 @@ char a[32]; unsigned int len; #endif - int m, n; + int m, n, en; errno = 0; ERR_clear_error(); n = SSL_connect(wsi->tls.ssl); - if (n == 1) { + en = errno; + + m = lws_ssl_get_error(wsi, n); + + if (m == SSL_ERROR_SYSCALL +#if defined(WIN32) + && en +#endif + ) { +#if defined(WIN32) || (_LWS_ENABLED_LOGS & LLL_INFO) + lwsl_info("%s: n %d, m %d, errno %d\n", __func__, n, m, en); +#endif + lws_snprintf(errbuf, elen, "connect SYSCALL %d", en); + return LWS_SSL_CAPABLE_ERROR; + } + + if (m == SSL_ERROR_SSL) { + n = lws_snprintf(errbuf, elen, "connect SSL err %d: ", m); + ERR_error_string_n(m, errbuf + n, elen - n); + return LWS_SSL_CAPABLE_ERROR; + } + + if (m == SSL_ERROR_WANT_READ || SSL_want_read(wsi->tls.ssl)) + return LWS_SSL_CAPABLE_MORE_SERVICE_READ; + + if (m == SSL_ERROR_WANT_WRITE || SSL_want_write(wsi->tls.ssl)) + return LWS_SSL_CAPABLE_MORE_SERVICE_WRITE; + + if (n == 1 || m == SSL_ERROR_SYSCALL) { #if defined(LWS_HAVE_SSL_set_alpn_protos) && \ defined(LWS_HAVE_SSL_get0_alpn_selected) SSL_get0_alpn_selected(wsi->tls.ssl, &prot, &len); @@ -307,20 +442,11 @@ return LWS_SSL_CAPABLE_DONE; } - m = lws_ssl_get_error(wsi, n); - - if (m == SSL_ERROR_SYSCALL) - return LWS_SSL_CAPABLE_ERROR; - - if (m == SSL_ERROR_WANT_READ || SSL_want_read(wsi->tls.ssl)) - return LWS_SSL_CAPABLE_MORE_SERVICE_READ; - - if (m == SSL_ERROR_WANT_WRITE || SSL_want_write(wsi->tls.ssl)) - return LWS_SSL_CAPABLE_MORE_SERVICE_WRITE; - if (!n) /* we don't know what he wants, but he says to retry */ return LWS_SSL_CAPABLE_MORE_SERVICE; + lws_snprintf(errbuf, elen, "connect unk %d", m); + return LWS_SSL_CAPABLE_ERROR; } @@ -328,17 +454,14 @@ lws_tls_client_confirm_peer_cert(struct lws *wsi, char *ebuf, int ebuf_len) { #if !defined(USE_WOLFSSL) - struct lws_context_per_thread *pt = &wsi->context->pt[(int)wsi->tsi]; + struct lws_context_per_thread *pt = &wsi->a.context->pt[(int)wsi->tsi]; char *p = (char *)&pt->serv_buf[0]; char *sb = p; int n; - lws_latency_pre(wsi->context, wsi); errno = 0; ERR_clear_error(); n = SSL_get_verify_result(wsi->tls.ssl); - lws_latency(wsi->context, wsi, - "SSL_get_verify_result LWS_CONNMODE..HANDSHAKE", n, n > 0); lwsl_debug("get_verify says %d\n", n); @@ -377,6 +500,36 @@ } int +lws_tls_client_vhost_extra_cert_mem(struct lws_vhost *vh, + const uint8_t *der, size_t der_len) +{ + X509_STORE *st; + X509 *x = d2i_X509(NULL, &der, (long)der_len); + int n; + + if (!x) { + lwsl_err("%s: Failed to load DER\n", __func__); + lws_tls_err_describe_clear(); + return 1; + } + + st = SSL_CTX_get_cert_store(vh->tls.ssl_client_ctx); + if (!st) { + lwsl_err("%s: failed to get cert store\n", __func__); + X509_free(x); + return 1; + } + + n = X509_STORE_add_cert(st, x); + if (n != 1) + lwsl_err("%s: failed to add cert\n", __func__); + + X509_free(x); + + return n != 1; +} + +int lws_tls_client_create_vhost_context(struct lws_vhost *vh, const struct lws_context_creation_info *info, const char *cipher_list, @@ -386,10 +539,12 @@ const char *cert_filepath, const void *cert_mem, unsigned int cert_mem_len, - const char *private_key_filepath) + const char *private_key_filepath, + const void *key_mem, + unsigned int key_mem_len + ) { struct lws_tls_client_reuse *tcr; - const unsigned char *ca_mem_ptr; X509_STORE *x509_store; unsigned long error; SSL_METHOD *method; @@ -578,15 +733,25 @@ /* openssl init for cert verification (for client sockets) */ if (!ca_filepath && (!ca_mem || !ca_mem_len)) { +#if defined(LWS_HAVE_SSL_CTX_load_verify_dir) + if (!SSL_CTX_load_verify_dir( + vh->tls.ssl_client_ctx, LWS_OPENSSL_CLIENT_CERTS)) +#else if (!SSL_CTX_load_verify_locations( vh->tls.ssl_client_ctx, NULL, LWS_OPENSSL_CLIENT_CERTS)) +#endif lwsl_err("Unable to load SSL Client certs from %s " "(set by LWS_OPENSSL_CLIENT_CERTS) -- " "client ssl isn't going to work\n", LWS_OPENSSL_CLIENT_CERTS); } else if (ca_filepath) { +#if defined(LWS_HAVE_SSL_CTX_load_verify_file) + if (!SSL_CTX_load_verify_file( + vh->tls.ssl_client_ctx, ca_filepath)) { +#else if (!SSL_CTX_load_verify_locations( vh->tls.ssl_client_ctx, ca_filepath, NULL)) { +#endif lwsl_err( "Unable to load SSL Client certs " "file from %s -- client ssl isn't " @@ -596,23 +761,43 @@ else lwsl_info("loaded ssl_ca_filepath\n"); } else { - ca_mem_ptr = (const unsigned char*)ca_mem; - client_CA = d2i_X509(NULL, &ca_mem_ptr, ca_mem_len); - x509_store = X509_STORE_new(); - if (!client_CA || !X509_STORE_add_cert(x509_store, client_CA)) { - X509_STORE_free(x509_store); - lwsl_err("Unable to load SSL Client certs from " - "ssl_ca_mem -- client ssl isn't going to " - "work\n"); + + lws_filepos_t amount = 0; + const uint8_t *up; + uint8_t *up1; + + if (lws_tls_alloc_pem_to_der_file(vh->context, NULL, ca_mem, + ca_mem_len, &up1, &amount)) { + lwsl_err("%s: Unable to decode x.509 mem\n", __func__); + lwsl_hexdump_notice(ca_mem, ca_mem_len); + return 1; + } + + up = up1; + client_CA = d2i_X509(NULL, &up, (long)amount); + if (!client_CA) { + lwsl_err("%s: d2i_X509 failed\n", __func__); + lwsl_hexdump_notice(up1, (size_t)amount); lws_tls_err_describe_clear(); } else { - /* it doesn't increment x509_store ref counter */ - SSL_CTX_set_cert_store(vh->tls.ssl_client_ctx, - x509_store); - lwsl_info("loaded ssl_ca_mem\n"); + x509_store = X509_STORE_new(); + if (!X509_STORE_add_cert(x509_store, client_CA)) { + X509_STORE_free(x509_store); + lwsl_err("Unable to load SSL Client certs from " + "ssl_ca_mem -- client ssl isn't going to " + "work\n"); + lws_tls_err_describe_clear(); + } else { + /* it doesn't increment x509_store ref counter */ + SSL_CTX_set_cert_store(vh->tls.ssl_client_ctx, + x509_store); + lwsl_info("loaded ssl_ca_mem\n"); + } } if (client_CA) X509_free(client_CA); + lws_free(up1); + // lws_tls_client_vhost_extra_cert_mem(vh, ca_mem, ca_mem_len); } /* @@ -621,6 +806,7 @@ */ /* support for client-side certificate authentication */ + if (cert_filepath) { if (lws_tls_use_any_upgrade_check_extant(cert_filepath) != LWS_TLS_EXTANT_YES && @@ -638,18 +824,33 @@ return 1; } lwsl_notice("Loaded client cert %s\n", cert_filepath); + } else if (cert_mem && cert_mem_len) { - n = SSL_CTX_use_certificate_ASN1(vh->tls.ssl_client_ctx, - cert_mem_len, cert_mem); + lws_filepos_t flen; + uint8_t *p; + + if (lws_tls_alloc_pem_to_der_file(vh->context, NULL, cert_mem, + cert_mem_len, &p, &flen)) { + lwsl_err("%s: couldn't read cert file\n", __func__); + + return 1; + } + + n = SSL_CTX_use_certificate_ASN1(vh->tls.ssl_client_ctx, (int)flen, p); + if (n < 1) { - lwsl_err("%s: problem interpreting client cert\n", - __func__); + lwsl_err("%s: problem interpreting client cert\n", __func__); lws_tls_err_describe_clear(); - return 1; } + + lws_free_set_NULL(p); + + if (n != 1) + return 1; + } if (private_key_filepath) { - lwsl_notice("%s: doing private key filepath\n", __func__); + lwsl_info("%s: using private key filepath\n", __func__); lws_ssl_bind_passphrase(vh->tls.ssl_client_ctx, 1, info); /* set the private key from KeyFile */ if (SSL_CTX_use_PrivateKey_file(vh->tls.ssl_client_ctx, @@ -659,7 +860,7 @@ lws_tls_err_describe_clear(); return 1; } - lwsl_notice("Loaded client cert private key %s\n", + lwsl_info("Loaded client cert private key %s\n", private_key_filepath); /* verify private key */ @@ -668,6 +869,35 @@ return 1; } } + else if (key_mem && key_mem_len) { + + lws_filepos_t flen; + uint8_t *p; + + if (lws_tls_alloc_pem_to_der_file(vh->context, NULL, key_mem, + key_mem_len, &p, &flen)) { + lwsl_err("%s: couldn't use mem cert\n", __func__); + + return 1; + } + + n = SSL_CTX_use_PrivateKey_ASN1(EVP_PKEY_RSA, vh->tls.ssl_client_ctx, p, + (long)(lws_intptr_t)flen); + if (n != 1) + n = SSL_CTX_use_PrivateKey_ASN1(EVP_PKEY_EC, + vh->tls.ssl_client_ctx, p, + (long)(lws_intptr_t)flen); + + lws_free_set_NULL(p); + + if (n != 1) { + lwsl_err("%s: unable to use key_mem\n", __func__); + + return 1; + } + } return 0; } + + diff -Nru libwebsockets-3.2.1/lib/tls/openssl/openssl-server.c libwebsockets-4.1.6/lib/tls/openssl/openssl-server.c --- libwebsockets-3.2.1/lib/tls/openssl/openssl-server.c 2019-12-18 14:45:31.000000000 +0000 +++ libwebsockets-4.1.6/lib/tls/openssl/openssl-server.c 2020-12-01 17:40:26.000000000 +0000 @@ -1,25 +1,28 @@ /* - * libwebsockets - OpenSSL-specific server functions + * libwebsockets - small server side websockets and web server implementation * - * Copyright (C) 2010-2018 Andy Green + * Copyright (C) 2010 - 2019 Andy Green * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation: - * version 2.1 of the License. + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to + * deal in the Software without restriction, including without limitation the + * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or + * sell copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: * - * This library is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. * - * You should have received a copy of the GNU Lesser General Public - * License along with this library; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, - * MA 02110-1301 USA + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS + * IN THE SOFTWARE. */ -#include "core/private.h" +#include "private-lib-core.h" /* * Care: many openssl apis return 1 for success. These are translated to the @@ -56,7 +59,7 @@ else lwsl_info("%s: couldn't get client cert CN\n", __func__); - n = wsi->vhost->protocols[0].callback(wsi, + n = wsi->a.vhost->protocols[0].callback(wsi, LWS_CALLBACK_OPENSSL_PERFORM_CLIENT_CERT_VERIFICATION, x509_ctx, ssl, preverify_ok); @@ -166,12 +169,11 @@ unsigned long error; lws_filepos_t flen; uint8_t *p; +#if OPENSSL_VERSION_NUMBER >= 0x10100000L int ret; - +#endif int n = lws_tls_generic_cert_checks(vhost, cert, private_key), m; - (void)ret; - if (!cert && !private_key) n = LWS_TLS_EXTANT_ALTERNATIVE; @@ -517,8 +519,13 @@ #endif if (info->ssl_ca_filepath && +#if defined(LWS_HAVE_SSL_CTX_load_verify_file) + !SSL_CTX_load_verify_file(vhost->tls.ssl_ctx, + info->ssl_ca_filepath)) { +#else !SSL_CTX_load_verify_locations(vhost->tls.ssl_ctx, info->ssl_ca_filepath, NULL)) { +#endif lwsl_err("%s: SSL_CTX_load_verify_locations unhappy\n", __func__); } @@ -558,7 +565,7 @@ errno = 0; ERR_clear_error(); - wsi->tls.ssl = SSL_new(wsi->vhost->tls.ssl_ctx); + wsi->tls.ssl = SSL_new(wsi->a.vhost->tls.ssl_ctx); if (wsi->tls.ssl == NULL) { lwsl_err("SSL_new failed: %d (errno %d)\n", lws_ssl_get_error(wsi, 0), errno); @@ -568,7 +575,7 @@ } SSL_set_ex_data(wsi->tls.ssl, openssl_websocket_private_data_index, wsi); - SSL_set_fd(wsi->tls.ssl, (int)(long long)accept_fd); + SSL_set_fd(wsi->tls.ssl, (int)(lws_intptr_t)accept_fd); #ifdef USE_WOLFSSL #ifdef USE_OLD_CYASSL @@ -593,7 +600,7 @@ #endif #if defined (LWS_HAVE_SSL_SET_INFO_CALLBACK) - if (wsi->vhost->tls.ssl_info_event_mask) + if (wsi->a.vhost->tls.ssl_info_event_mask) SSL_set_info_callback(wsi->tls.ssl, lws_ssl_info_callback); #endif @@ -612,7 +619,7 @@ enum lws_ssl_capable_status lws_tls_server_accept(struct lws *wsi) { - struct lws_context_per_thread *pt = &wsi->context->pt[(int)wsi->tsi]; + struct lws_context_per_thread *pt = &wsi->a.context->pt[(int)wsi->tsi]; union lws_tls_cert_info_results ir; int m, n; @@ -620,6 +627,8 @@ ERR_clear_error(); n = SSL_accept(wsi->tls.ssl); + wsi->skip_fallback = 1; + if (n == 1) { n = lws_tls_peer_cert_info(wsi, LWS_TLS_CERT_INFO_COMMON_NAME, &ir, sizeof(ir.ns.name)); @@ -708,7 +717,7 @@ RSA *rsa; }; -LWS_VISIBLE LWS_EXTERN int +int lws_tls_acme_sni_cert_create(struct lws_vhost *vhost, const char *san_a, const char *san_b) { @@ -865,10 +874,11 @@ NID_localityName, /* LWS_TLS_REQ_ELEMENT_LOCALITY */ NID_organizationName, /* LWS_TLS_REQ_ELEMENT_ORGANIZATION */ NID_commonName, /* LWS_TLS_REQ_ELEMENT_COMMON_NAME */ - NID_organizationalUnitName, /* LWS_TLS_REQ_ELEMENT_EMAIL */ + NID_subject_alt_name, /* LWS_TLS_REQ_ELEMENT_SUBJECT_ALT_NAME */ + NID_pkcs9_emailAddress, /* LWS_TLS_REQ_ELEMENT_EMAIL */ }; -LWS_VISIBLE LWS_EXTERN int +int lws_tls_acme_sni_csr_create(struct lws_context *context, const char *elements[], uint8_t *csr, size_t csr_len, char **privkey_pem, size_t *privkey_len) @@ -903,15 +913,45 @@ goto bail2; for (n = 0; n < LWS_TLS_REQ_ELEMENT_COUNT; n++) - if (lws_tls_openssl_add_nid(subj, nid_list[n], elements[n])) { - lwsl_notice("%s: failed to add element %d\n", __func__, - n); + if (elements[n] && + lws_tls_openssl_add_nid(subj, nid_list[n], + elements[n])) { + lwsl_notice("%s: failed to add element %d\n", + __func__, n); goto bail3; } if (X509_REQ_set_subject_name(req, subj) != 1) goto bail3; + if (elements[LWS_TLS_REQ_ELEMENT_SUBJECT_ALT_NAME]) { + STACK_OF(X509_EXTENSION) *exts; + X509_EXTENSION *ext; + char san[256]; + + exts = sk_X509_EXTENSION_new_null(); + if (!exts) + goto bail3; + + lws_snprintf(san, sizeof(san), "DNS:%s,DNS:%s", + elements[LWS_TLS_REQ_ELEMENT_COMMON_NAME], + elements[LWS_TLS_REQ_ELEMENT_SUBJECT_ALT_NAME]); + + ext = X509V3_EXT_conf_nid(NULL, NULL, NID_subject_alt_name, + san); + if (!ext) { + sk_X509_EXTENSION_pop_free(exts, X509_EXTENSION_free); + goto bail3; + } + sk_X509_EXTENSION_push(exts, ext); + + if (!X509_REQ_add_extensions(req, exts)) { + sk_X509_EXTENSION_pop_free(exts, X509_EXTENSION_free); + goto bail3; + } + sk_X509_EXTENSION_pop_free(exts, X509_EXTENSION_free); + } + if (!X509_REQ_sign(req, pkey, EVP_sha256())) goto bail3; diff -Nru libwebsockets-3.2.1/lib/tls/openssl/openssl-ssl.c libwebsockets-4.1.6/lib/tls/openssl/openssl-ssl.c --- libwebsockets-3.2.1/lib/tls/openssl/openssl-ssl.c 1970-01-01 00:00:00.000000000 +0000 +++ libwebsockets-4.1.6/lib/tls/openssl/openssl-ssl.c 2020-12-01 17:40:26.000000000 +0000 @@ -0,0 +1,574 @@ +/* + * libwebsockets - small server side websockets and web server implementation + * + * Copyright (C) 2010 - 2019 Andy Green + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to + * deal in the Software without restriction, including without limitation the + * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or + * sell copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS + * IN THE SOFTWARE. + */ + +#include "private-lib-core.h" +#include "private-lib-tls-openssl.h" +#include + +int openssl_websocket_private_data_index, + openssl_SSL_CTX_private_data_index; + +/* + * Care: many openssl apis return 1 for success. These are translated to the + * lws convention of 0 for success. + */ + +int lws_openssl_describe_cipher(struct lws *wsi) +{ +#if !defined(LWS_WITH_NO_LOGS) && !defined(USE_WOLFSSL) + int np = -1; + SSL *s = wsi->tls.ssl; + + SSL_get_cipher_bits(s, &np); + lwsl_info("%s: wsi %p: %s, %s, %d bits, %s\n", __func__, wsi, + SSL_get_cipher_name(s), SSL_get_cipher(s), np, + SSL_get_cipher_version(s)); +#endif + + return 0; +} + +int lws_ssl_get_error(struct lws *wsi, int n) +{ + int m; + + if (!wsi->tls.ssl) + return 99; + + m = SSL_get_error(wsi->tls.ssl, n); + lwsl_debug("%s: %p %d -> %d (errno %d)\n", __func__, wsi->tls.ssl, n, m, + errno); + if (m == SSL_ERROR_SSL) + lws_tls_err_describe_clear(); + + // assert (errno != 9); + + return m; +} + +#if defined(LWS_WITH_SERVER) +static int +lws_context_init_ssl_pem_passwd_cb(char *buf, int size, int rwflag, + void *userdata) +{ + struct lws_context_creation_info * info = + (struct lws_context_creation_info *)userdata; + + strncpy(buf, info->ssl_private_key_password, size); + buf[size - 1] = '\0'; + + return (int)strlen(buf); +} +#endif + +#if defined(LWS_WITH_CLIENT) +static int +lws_context_init_ssl_pem_passwd_client_cb(char *buf, int size, int rwflag, + void *userdata) +{ + struct lws_context_creation_info * info = + (struct lws_context_creation_info *)userdata; + const char *p = info->ssl_private_key_password; + + if (info->client_ssl_private_key_password) + p = info->client_ssl_private_key_password; + + strncpy(buf, p, size); + buf[size - 1] = '\0'; + + return (int)strlen(buf); +} +#endif + +void +lws_ssl_bind_passphrase(SSL_CTX *ssl_ctx, int is_client, + const struct lws_context_creation_info *info) +{ + if ( +#if defined(LWS_WITH_SERVER) + !info->ssl_private_key_password +#endif +#if defined(LWS_WITH_SERVER) && defined(LWS_WITH_CLIENT) + && +#endif +#if defined(LWS_WITH_CLIENT) + !info->client_ssl_private_key_password +#endif + ) + return; + /* + * password provided, set ssl callback and user data + * for checking password which will be trigered during + * SSL_CTX_use_PrivateKey_file function + */ + SSL_CTX_set_default_passwd_cb_userdata(ssl_ctx, (void *)info); + SSL_CTX_set_default_passwd_cb(ssl_ctx, is_client ? +#if defined(LWS_WITH_CLIENT) + lws_context_init_ssl_pem_passwd_client_cb: +#else + NULL: +#endif +#if defined(LWS_WITH_SERVER) + lws_context_init_ssl_pem_passwd_cb +#else + NULL +#endif + ); +} + +#if defined(LWS_WITH_CLIENT) +static void +lws_ssl_destroy_client_ctx(struct lws_vhost *vhost) +{ + struct lws_tls_client_reuse *tcr; + + if (vhost->tls.user_supplied_ssl_ctx || !vhost->tls.ssl_client_ctx) + return; + + tcr = SSL_CTX_get_ex_data(vhost->tls.ssl_client_ctx, + openssl_SSL_CTX_private_data_index); + + if (!tcr || --tcr->refcount) + return; + + SSL_CTX_free(vhost->tls.ssl_client_ctx); + vhost->tls.ssl_client_ctx = NULL; + + vhost->context->tls.count_client_contexts--; + + lws_dll2_remove(&tcr->cc_list); + lws_free(tcr); +} +#endif +void +lws_ssl_destroy(struct lws_vhost *vhost) +{ + if (!lws_check_opt(vhost->context->options, + LWS_SERVER_OPTION_DO_SSL_GLOBAL_INIT)) + return; + + if (vhost->tls.ssl_ctx) + SSL_CTX_free(vhost->tls.ssl_ctx); +#if defined(LWS_WITH_CLIENT) + lws_ssl_destroy_client_ctx(vhost); +#endif + +// after 1.1.0 no need +#if (OPENSSL_VERSION_NUMBER < 0x10100000) +// <= 1.0.1f = old api, 1.0.1g+ = new api +#if (OPENSSL_VERSION_NUMBER <= 0x1000106f) || defined(USE_WOLFSSL) + ERR_remove_state(0); +#else +#if OPENSSL_VERSION_NUMBER >= 0x1010005f && \ + !defined(LIBRESSL_VERSION_NUMBER) && \ + !defined(OPENSSL_IS_BORINGSSL) + ERR_remove_thread_state(); +#else + ERR_remove_thread_state(NULL); +#endif +#endif + /* not needed after 1.1.0 */ +#if (OPENSSL_VERSION_NUMBER >= 0x10002000) && \ + (OPENSSL_VERSION_NUMBER <= 0x10100000) + SSL_COMP_free_compression_methods(); +#endif + ERR_free_strings(); + EVP_cleanup(); + CRYPTO_cleanup_all_ex_data(); +#endif +} + +int +lws_ssl_capable_read(struct lws *wsi, unsigned char *buf, int len) +{ + struct lws_context *context = wsi->a.context; + struct lws_context_per_thread *pt = &context->pt[(int)wsi->tsi]; + int n = 0, m; + + if (!wsi->tls.ssl) + return lws_ssl_capable_read_no_ssl(wsi, buf, len); + + lws_stats_bump(pt, LWSSTATS_C_API_READ, 1); + + errno = 0; + ERR_clear_error(); + n = SSL_read(wsi->tls.ssl, buf, len); +#if defined(LWS_PLAT_FREERTOS) + if (!n && errno == LWS_ENOTCONN) { + lwsl_debug("%p: SSL_read ENOTCONN\n", wsi); + return LWS_SSL_CAPABLE_ERROR; + } +#endif +#if defined(LWS_WITH_STATS) + if (!wsi->seen_rx && wsi->accept_start_us) { + lws_stats_bump(pt, LWSSTATS_US_SSL_RX_DELAY_AVG, + lws_now_usecs() - + wsi->accept_start_us); + lws_stats_bump(pt, LWSSTATS_C_SSL_CONNS_HAD_RX, 1); + wsi->seen_rx = 1; + } +#endif + + + lwsl_debug("%p: SSL_read says %d\n", wsi, n); + /* manpage: returning 0 means connection shut down + * + * 2018-09-10: https://github.com/openssl/openssl/issues/1903 + * + * So, in summary, if you get a 0 or -1 return from SSL_read() / + * SSL_write(), you should call SSL_get_error(): + * + * - If you get back SSL_ERROR_RETURN_ZERO then you know the connection + * has been cleanly shutdown by the peer. To fully close the + * connection you may choose to call SSL_shutdown() to send a + * close_notify back. + * + * - If you get back SSL_ERROR_SSL then some kind of internal or + * protocol error has occurred. More details will be on the SSL error + * queue. You can also call SSL_get_shutdown(). If this indicates a + * state of SSL_RECEIVED_SHUTDOWN then you know a fatal alert has + * been received from the peer (if it had been a close_notify then + * SSL_get_error() would have returned SSL_ERROR_RETURN_ZERO). + * SSL_ERROR_SSL is considered fatal - you should not call + * SSL_shutdown() in this case. + * + * - If you get back SSL_ERROR_SYSCALL then some kind of fatal (i.e. + * non-retryable) error has occurred in a system call. + */ + if (n <= 0) { + m = lws_ssl_get_error(wsi, n); + lwsl_debug("%p: ssl err %d errno %d\n", wsi, m, errno); + if (m == SSL_ERROR_ZERO_RETURN) /* cleanly shut down */ + return LWS_SSL_CAPABLE_ERROR; + + /* hm not retryable.. could be 0 size pkt or error */ + + if (m == SSL_ERROR_SSL || m == SSL_ERROR_SYSCALL || + errno == LWS_ENOTCONN) { + + /* unclean, eg closed conn */ + + wsi->socket_is_permanently_unusable = 1; + + return LWS_SSL_CAPABLE_ERROR; + } + + /* retryable? */ + + if (SSL_want_read(wsi->tls.ssl)) { + lwsl_debug("%s: WANT_READ\n", __func__); + lwsl_debug("%p: LWS_SSL_CAPABLE_MORE_SERVICE\n", wsi); + return LWS_SSL_CAPABLE_MORE_SERVICE; + } + if (SSL_want_write(wsi->tls.ssl)) { + lwsl_debug("%s: WANT_WRITE\n", __func__); + lwsl_debug("%p: LWS_SSL_CAPABLE_MORE_SERVICE\n", wsi); + return LWS_SSL_CAPABLE_MORE_SERVICE; + } + + /* keep on trucking it seems */ + } + +#if 0 + /* + * If using openssl type tls library, this is the earliest point for all + * paths to dump what was received as decrypted data from the tls tunnel + */ + lwsl_notice("%s: len %d\n", __func__, n); + lwsl_hexdump_notice(buf, n); +#endif + + lws_stats_bump(pt, LWSSTATS_B_READ, n); + +#if defined(LWS_WITH_SERVER_STATUS) + if (wsi->a.vhost) + wsi->a.vhost->conn_stats.rx += n; +#endif + +#if defined(LWS_WITH_DETAILED_LATENCY) + if (context->detailed_latency_cb) { + wsi->detlat.req_size = len; + wsi->detlat.acc_size = n; + wsi->detlat.type = LDLT_READ; + wsi->detlat.latencies[LAT_DUR_PROXY_RX_TO_ONWARD_TX] = + lws_now_usecs() - pt->ust_left_poll; + wsi->detlat.latencies[LAT_DUR_USERCB] = 0; + lws_det_lat_cb(wsi->a.context, &wsi->detlat); + } +#endif + + /* + * if it was our buffer that limited what we read, + * check if SSL has additional data pending inside SSL buffers. + * + * Because these won't signal at the network layer with POLLIN + * and if we don't realize, this data will sit there forever + */ + if (n != len) + goto bail; + if (!wsi->tls.ssl) + goto bail; + + if (SSL_pending(wsi->tls.ssl)) { + if (lws_dll2_is_detached(&wsi->tls.dll_pending_tls)) + lws_dll2_add_head(&wsi->tls.dll_pending_tls, + &pt->tls.dll_pending_tls_owner); + } else + __lws_ssl_remove_wsi_from_buffered_list(wsi); + + return n; +bail: + lws_ssl_remove_wsi_from_buffered_list(wsi); + + return n; +} + +int +lws_ssl_pending(struct lws *wsi) +{ + if (!wsi->tls.ssl) + return 0; + + return SSL_pending(wsi->tls.ssl); +} + +int +lws_ssl_capable_write(struct lws *wsi, unsigned char *buf, int len) +{ + int n, m; + +#if 0 + /* + * If using OpenSSL type tls library, this is the last point for all + * paths before sending data into the tls tunnel, where you can dump it + * and see what is being sent. + */ + lwsl_notice("%s: len %d\n", __func__, len); + lwsl_hexdump_notice(buf, len); +#endif + + if (!wsi->tls.ssl) + return lws_ssl_capable_write_no_ssl(wsi, buf, len); + + errno = 0; + ERR_clear_error(); + n = SSL_write(wsi->tls.ssl, buf, len); + if (n > 0) + return n; + + m = lws_ssl_get_error(wsi, n); + if (m != SSL_ERROR_SYSCALL) { + if (m == SSL_ERROR_WANT_READ || SSL_want_read(wsi->tls.ssl)) { + lwsl_notice("%s: want read\n", __func__); + + return LWS_SSL_CAPABLE_MORE_SERVICE; + } + + if (m == SSL_ERROR_WANT_WRITE || SSL_want_write(wsi->tls.ssl)) { + lws_set_blocking_send(wsi); + + lwsl_debug("%s: want write\n", __func__); + + return LWS_SSL_CAPABLE_MORE_SERVICE; + } + } + + lwsl_debug("%s failed: %s\n",__func__, ERR_error_string(m, NULL)); + lws_tls_err_describe_clear(); + + wsi->socket_is_permanently_unusable = 1; + + return LWS_SSL_CAPABLE_ERROR; +} + +void +lws_ssl_info_callback(const SSL *ssl, int where, int ret) +{ + struct lws *wsi; + struct lws_context *context; + struct lws_ssl_info si; + int fd; + +#ifndef USE_WOLFSSL + context = (struct lws_context *)SSL_CTX_get_ex_data( + SSL_get_SSL_CTX(ssl), + openssl_SSL_CTX_private_data_index); +#else + context = (struct lws_context *)SSL_CTX_get_ex_data( + SSL_get_SSL_CTX((SSL*) ssl), + openssl_SSL_CTX_private_data_index); +#endif + if (!context) + return; + + fd = SSL_get_fd(ssl); + if (fd < 0 || (fd - lws_plat_socket_offset()) < 0) + return; + + wsi = wsi_from_fd(context, fd); + if (!wsi) + return; + + if (!(where & wsi->a.vhost->tls.ssl_info_event_mask)) + return; + + si.where = where; + si.ret = ret; + + if (user_callback_handle_rxflow(wsi->a.protocol->callback, + wsi, LWS_CALLBACK_SSL_INFO, + wsi->user_space, &si, 0)) + lws_set_timeout(wsi, PENDING_TIMEOUT_KILLED_BY_SSL_INFO, -1); +} + + +int +lws_ssl_close(struct lws *wsi) +{ + lws_sockfd_type n; + + if (!wsi->tls.ssl) + return 0; /* not handled */ + +#if defined (LWS_HAVE_SSL_SET_INFO_CALLBACK) + /* kill ssl callbacks, because we will remove the fd from the + * table linking it to the wsi + */ + if (wsi->a.vhost->tls.ssl_info_event_mask) + SSL_set_info_callback(wsi->tls.ssl, NULL); +#endif + + n = SSL_get_fd(wsi->tls.ssl); + if (!wsi->socket_is_permanently_unusable) + SSL_shutdown(wsi->tls.ssl); + compatible_close(n); + SSL_free(wsi->tls.ssl); + wsi->tls.ssl = NULL; + + lws_tls_restrict_return(wsi->a.context); + + // lwsl_notice("%s: ssl restr %d, simul %d\n", __func__, + // wsi->a.context->simultaneous_ssl_restriction, + // wsi->a.context->simultaneous_ssl); + + return 1; /* handled */ +} + +void +lws_ssl_SSL_CTX_destroy(struct lws_vhost *vhost) +{ + if (vhost->tls.ssl_ctx) + SSL_CTX_free(vhost->tls.ssl_ctx); + +#if defined(LWS_WITH_CLIENT) + lws_ssl_destroy_client_ctx(vhost); +#endif + +#if defined(LWS_WITH_ACME) + lws_tls_acme_sni_cert_destroy(vhost); +#endif +} + +void +lws_ssl_context_destroy(struct lws_context *context) +{ +// after 1.1.0 no need +#if (OPENSSL_VERSION_NUMBER < 0x10100000) +// <= 1.0.1f = old api, 1.0.1g+ = new api +#if (OPENSSL_VERSION_NUMBER <= 0x1000106f) || defined(USE_WOLFSSL) + ERR_remove_state(0); +#else +#if OPENSSL_VERSION_NUMBER >= 0x1010005f && \ + !defined(LIBRESSL_VERSION_NUMBER) && \ + !defined(OPENSSL_IS_BORINGSSL) + ERR_remove_thread_state(); +#else + ERR_remove_thread_state(NULL); +#endif +#endif + // after 1.1.0 no need +#if (OPENSSL_VERSION_NUMBER >= 0x10002000) && (OPENSSL_VERSION_NUMBER <= 0x10100000) + SSL_COMP_free_compression_methods(); +#endif + ERR_free_strings(); + EVP_cleanup(); + CRYPTO_cleanup_all_ex_data(); +#endif +} + +lws_tls_ctx * +lws_tls_ctx_from_wsi(struct lws *wsi) +{ + if (!wsi->tls.ssl) + return NULL; + + return SSL_get_SSL_CTX(wsi->tls.ssl); +} + +enum lws_ssl_capable_status +__lws_tls_shutdown(struct lws *wsi) +{ + int n; + + errno = 0; + ERR_clear_error(); + n = SSL_shutdown(wsi->tls.ssl); + lwsl_debug("SSL_shutdown=%d for fd %d\n", n, wsi->desc.sockfd); + switch (n) { + case 1: /* successful completion */ + n = shutdown(wsi->desc.sockfd, SHUT_WR); + return LWS_SSL_CAPABLE_DONE; + + case 0: /* needs a retry */ + __lws_change_pollfd(wsi, 0, LWS_POLLIN); + return LWS_SSL_CAPABLE_MORE_SERVICE; + + default: /* fatal error, or WANT */ + n = SSL_get_error(wsi->tls.ssl, n); + if (n != SSL_ERROR_SYSCALL && n != SSL_ERROR_SSL) { + if (SSL_want_read(wsi->tls.ssl)) { + lwsl_debug("(wants read)\n"); + __lws_change_pollfd(wsi, 0, LWS_POLLIN); + return LWS_SSL_CAPABLE_MORE_SERVICE_READ; + } + if (SSL_want_write(wsi->tls.ssl)) { + lwsl_debug("(wants write)\n"); + __lws_change_pollfd(wsi, 0, LWS_POLLOUT); + return LWS_SSL_CAPABLE_MORE_SERVICE_WRITE; + } + } + return LWS_SSL_CAPABLE_ERROR; + } +} + + +static int +tops_fake_POLLIN_for_buffered_openssl(struct lws_context_per_thread *pt) +{ + return lws_tls_fake_POLLIN_for_buffered(pt); +} + +const struct lws_tls_ops tls_ops_openssl = { + /* fake_POLLIN_for_buffered */ tops_fake_POLLIN_for_buffered_openssl, +}; diff -Nru libwebsockets-3.2.1/lib/tls/openssl/openssl-tls.c libwebsockets-4.1.6/lib/tls/openssl/openssl-tls.c --- libwebsockets-3.2.1/lib/tls/openssl/openssl-tls.c 1970-01-01 00:00:00.000000000 +0000 +++ libwebsockets-4.1.6/lib/tls/openssl/openssl-tls.c 2020-12-01 17:40:26.000000000 +0000 @@ -0,0 +1,196 @@ +/* + * libwebsockets - small server side websockets and web server implementation + * + * Copyright (C) 2010 - 2019 Andy Green + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to + * deal in the Software without restriction, including without limitation the + * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or + * sell copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS + * IN THE SOFTWARE. + */ + +#include "private-lib-core.h" +#include "private-lib-tls-openssl.h" + +extern int openssl_websocket_private_data_index, +openssl_SSL_CTX_private_data_index; + +char* lws_ssl_get_error_string(int status, int ret, char *buf, size_t len) { + switch (status) { + case SSL_ERROR_NONE: + return lws_strncpy(buf, "SSL_ERROR_NONE", len); + case SSL_ERROR_ZERO_RETURN: + return lws_strncpy(buf, "SSL_ERROR_ZERO_RETURN", len); + case SSL_ERROR_WANT_READ: + return lws_strncpy(buf, "SSL_ERROR_WANT_READ", len); + case SSL_ERROR_WANT_WRITE: + return lws_strncpy(buf, "SSL_ERROR_WANT_WRITE", len); + case SSL_ERROR_WANT_CONNECT: + return lws_strncpy(buf, "SSL_ERROR_WANT_CONNECT", len); + case SSL_ERROR_WANT_ACCEPT: + return lws_strncpy(buf, "SSL_ERROR_WANT_ACCEPT", len); + case SSL_ERROR_WANT_X509_LOOKUP: + return lws_strncpy(buf, "SSL_ERROR_WANT_X509_LOOKUP", len); + case SSL_ERROR_SYSCALL: + switch (ret) { + case 0: + lws_snprintf(buf, len, "SSL_ERROR_SYSCALL: EOF"); + return buf; + case -1: +#ifndef LWS_PLAT_OPTEE + lws_snprintf(buf, len, "SSL_ERROR_SYSCALL: %s", + strerror(errno)); +#else + lws_snprintf(buf, len, "SSL_ERROR_SYSCALL: %d", errno); +#endif + return buf; + default: + return strncpy(buf, "SSL_ERROR_SYSCALL", len); + } + case SSL_ERROR_SSL: + return "SSL_ERROR_SSL"; + default: + return "SSL_ERROR_UNKNOWN"; + } +} + +void +lws_tls_err_describe_clear(void) +{ + char buf[160]; + unsigned long l; + + do { + l = ERR_get_error(); + if (!l) + break; + + ERR_error_string_n(l, buf, sizeof(buf)); + lwsl_info(" openssl error: %s\n", buf); + } while (l); + lwsl_info("\n"); +} + +#if LWS_MAX_SMP != 1 + +static pthread_mutex_t *openssl_mutexes; + +static void +lws_openssl_lock_callback(int mode, int type, const char *file, int line) +{ + (void)file; + (void)line; + + if (mode & CRYPTO_LOCK) + pthread_mutex_lock(&openssl_mutexes[type]); + else + pthread_mutex_unlock(&openssl_mutexes[type]); +} + +static unsigned long +lws_openssl_thread_id(void) +{ + return (unsigned long)pthread_self(); +} +#endif + + +int +lws_context_init_ssl_library(const struct lws_context_creation_info *info) +{ +#ifdef USE_WOLFSSL +#ifdef USE_OLD_CYASSL + lwsl_info(" Compiled with CyaSSL support\n"); +#else + lwsl_info(" Compiled with wolfSSL support\n"); +#endif +#else +#if defined(LWS_WITH_BORINGSSL) + lwsl_info(" Compiled with BoringSSL support\n"); +#else + lwsl_info(" Compiled with OpenSSL support\n"); +#endif +#endif + if (!lws_check_opt(info->options, LWS_SERVER_OPTION_DO_SSL_GLOBAL_INIT)) { + lwsl_info(" SSL disabled: no " + "LWS_SERVER_OPTION_DO_SSL_GLOBAL_INIT\n"); + return 0; + } + + /* basic openssl init */ + + lwsl_info("Doing SSL library init\n"); + +#if OPENSSL_VERSION_NUMBER < 0x10100000L + SSL_library_init(); + OpenSSL_add_all_algorithms(); + SSL_load_error_strings(); +#else + OPENSSL_init_ssl(OPENSSL_INIT_LOAD_SSL_STRINGS, NULL); +#endif +#if defined(LWS_WITH_NETWORK) + openssl_websocket_private_data_index = + SSL_get_ex_new_index(0, "lws", NULL, NULL, NULL); + + openssl_SSL_CTX_private_data_index = SSL_CTX_get_ex_new_index(0, + NULL, NULL, NULL, NULL); +#endif + +#if LWS_MAX_SMP != 1 + { + int n; + + openssl_mutexes = (pthread_mutex_t *) + OPENSSL_malloc(CRYPTO_num_locks() * + sizeof(openssl_mutexes[0])); + + for (n = 0; n < CRYPTO_num_locks(); n++) + pthread_mutex_init(&openssl_mutexes[n], NULL); + + /* + * These "functions" disappeared in later OpenSSL which is + * already threadsafe. + */ + + (void)lws_openssl_thread_id; + (void)lws_openssl_lock_callback; + + CRYPTO_set_id_callback(lws_openssl_thread_id); + CRYPTO_set_locking_callback(lws_openssl_lock_callback); + } +#endif + + return 0; +} + +void +lws_context_deinit_ssl_library(struct lws_context *context) +{ +#if LWS_MAX_SMP != 1 + int n; + + if (!lws_check_opt(context->options, + LWS_SERVER_OPTION_DO_SSL_GLOBAL_INIT)) + return; + + CRYPTO_set_locking_callback(NULL); + + for (n = 0; n < CRYPTO_num_locks(); n++) + pthread_mutex_destroy(&openssl_mutexes[n]); + + OPENSSL_free(openssl_mutexes); +#endif +} diff -Nru libwebsockets-3.2.1/lib/tls/openssl/openssl-x509.c libwebsockets-4.1.6/lib/tls/openssl/openssl-x509.c --- libwebsockets-3.2.1/lib/tls/openssl/openssl-x509.c 1970-01-01 00:00:00.000000000 +0000 +++ libwebsockets-4.1.6/lib/tls/openssl/openssl-x509.c 2020-12-01 17:40:26.000000000 +0000 @@ -0,0 +1,668 @@ +/* + * libwebsockets - small server side websockets and web server implementation + * + * Copyright (C) 2010 - 2019 Andy Green + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to + * deal in the Software without restriction, including without limitation the + * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or + * sell copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS + * IN THE SOFTWARE. + */ + +#define WIN32_LEAN_AND_MEAN +#include "private-lib-core.h" +#include "private-lib-tls-openssl.h" + +#if !defined(LWS_PLAT_OPTEE) +static int +dec(char c) +{ + return c - '0'; +} +#endif + +static time_t +lws_tls_openssl_asn1time_to_unix(ASN1_TIME *as) +{ +#if !defined(LWS_PLAT_OPTEE) + + const char *p = (const char *)as->data; + struct tm t; + + /* [YY]YYMMDDHHMMSSZ */ + + memset(&t, 0, sizeof(t)); + + if (strlen(p) == 13) { + t.tm_year = (dec(p[0]) * 10) + dec(p[1]) + 100; + p += 2; + } else { + t.tm_year = (dec(p[0]) * 1000) + (dec(p[1]) * 100) + + (dec(p[2]) * 10) + dec(p[3]); + p += 4; + } + t.tm_mon = (dec(p[0]) * 10) + dec(p[1]) - 1; + p += 2; + t.tm_mday = (dec(p[0]) * 10) + dec(p[1]) - 1; + p += 2; + t.tm_hour = (dec(p[0]) * 10) + dec(p[1]); + p += 2; + t.tm_min = (dec(p[0]) * 10) + dec(p[1]); + p += 2; + t.tm_sec = (dec(p[0]) * 10) + dec(p[1]); + t.tm_isdst = 0; + + return mktime(&t); +#else + return (time_t)-1; +#endif +} + +int +lws_tls_openssl_cert_info(X509 *x509, enum lws_tls_cert_info type, + union lws_tls_cert_info_results *buf, size_t len) +{ + X509_NAME *xn; +#if !defined(LWS_PLAT_OPTEE) + char *p; +#endif + + if (!x509) + return -1; + +#if OPENSSL_VERSION_NUMBER >= 0x10100000L && !defined(X509_get_notBefore) +#define X509_get_notBefore(x) X509_getm_notBefore(x) +#define X509_get_notAfter(x) X509_getm_notAfter(x) +#endif + + switch (type) { + case LWS_TLS_CERT_INFO_VALIDITY_FROM: + buf->time = lws_tls_openssl_asn1time_to_unix( + X509_get_notBefore(x509)); + if (buf->time == (time_t)-1) + return -1; + break; + + case LWS_TLS_CERT_INFO_VALIDITY_TO: + buf->time = lws_tls_openssl_asn1time_to_unix( + X509_get_notAfter(x509)); + if (buf->time == (time_t)-1) + return -1; + break; + + case LWS_TLS_CERT_INFO_COMMON_NAME: +#if defined(LWS_PLAT_OPTEE) + return -1; +#else + xn = X509_get_subject_name(x509); + if (!xn) + return -1; + X509_NAME_oneline(xn, buf->ns.name, (int)len - 2); + p = strstr(buf->ns.name, "/CN="); + if (p) + memmove(buf->ns.name, p + 4, strlen(p + 4) + 1); + buf->ns.len = (int)strlen(buf->ns.name); + return 0; +#endif + case LWS_TLS_CERT_INFO_ISSUER_NAME: + xn = X509_get_issuer_name(x509); + if (!xn) + return -1; + X509_NAME_oneline(xn, buf->ns.name, (int)len - 1); + buf->ns.len = (int)strlen(buf->ns.name); + return 0; + + case LWS_TLS_CERT_INFO_USAGE: +#if defined(LWS_HAVE_X509_get_key_usage) + buf->usage = X509_get_key_usage(x509); + break; +#else + return -1; +#endif + + case LWS_TLS_CERT_INFO_OPAQUE_PUBLIC_KEY: + { +#ifndef USE_WOLFSSL + size_t klen = i2d_X509_PUBKEY(X509_get_X509_PUBKEY(x509), NULL); + uint8_t *tmp, *ptmp; + + if (!klen || klen > len) + return -1; + + tmp = (uint8_t *)OPENSSL_malloc(klen); + if (!tmp) + return -1; + + ptmp = tmp; + if (i2d_X509_PUBKEY( + X509_get_X509_PUBKEY(x509), &ptmp) != (int)klen || + !ptmp || lws_ptr_diff(ptmp, tmp) != (int)klen) { + lwsl_info("%s: cert public key extraction failed\n", + __func__); + if (ptmp) + OPENSSL_free(tmp); + + return -1; + } + + buf->ns.len = (int)klen; + memcpy(buf->ns.name, tmp, klen); + OPENSSL_free(tmp); +#endif + return 0; + } + default: + return -1; + } + + return 0; +} + +int +lws_x509_info(struct lws_x509_cert *x509, enum lws_tls_cert_info type, + union lws_tls_cert_info_results *buf, size_t len) +{ + return lws_tls_openssl_cert_info(x509->cert, type, buf, len); +} + +#if defined(LWS_WITH_NETWORK) +int +lws_tls_vhost_cert_info(struct lws_vhost *vhost, enum lws_tls_cert_info type, + union lws_tls_cert_info_results *buf, size_t len) +{ +#if defined(LWS_HAVE_SSL_CTX_get0_certificate) + X509 *x509 = SSL_CTX_get0_certificate(vhost->tls.ssl_ctx); + + return lws_tls_openssl_cert_info(x509, type, buf, len); +#else + lwsl_notice("openssl is too old to support %s\n", __func__); + + return -1; +#endif +} + + + +int +lws_tls_peer_cert_info(struct lws *wsi, enum lws_tls_cert_info type, + union lws_tls_cert_info_results *buf, size_t len) +{ + int rc = 0; + X509 *x509; + + wsi = lws_get_network_wsi(wsi); + + x509 = SSL_get_peer_certificate(wsi->tls.ssl); + + if (!x509) { + lwsl_debug("no peer cert\n"); + + return -1; + } + + switch (type) { + case LWS_TLS_CERT_INFO_VERIFIED: + buf->verified = SSL_get_verify_result(wsi->tls.ssl) == + X509_V_OK; + break; + default: + rc = lws_tls_openssl_cert_info(x509, type, buf, len); + } + + X509_free(x509); + + return rc; +} +#endif + +int +lws_x509_create(struct lws_x509_cert **x509) +{ + *x509 = lws_malloc(sizeof(**x509), __func__); + if (*x509) + (*x509)->cert = NULL; + + return !(*x509); +} + +int +lws_x509_parse_from_pem(struct lws_x509_cert *x509, const void *pem, size_t len) +{ + BIO* bio = BIO_new(BIO_s_mem()); + + BIO_write(bio, pem, (int)len); + x509->cert = PEM_read_bio_X509(bio, NULL, NULL, NULL); + BIO_free(bio); + if (!x509->cert) { + lwsl_err("%s: unable to parse PEM cert\n", __func__); + lws_tls_err_describe_clear(); + + return -1; + } + + return 0; +} + +int +lws_x509_verify(struct lws_x509_cert *x509, struct lws_x509_cert *trusted, + const char *common_name) +{ + char c[32], *p; + int ret; + + if (common_name) { + X509_NAME *xn = X509_get_subject_name(x509->cert); + if (!xn) + return -1; + X509_NAME_oneline(xn, c, (int)sizeof(c) - 2); + p = strstr(c, "/CN="); + if (p) + p = p + 4; + else + p = c; + + if (strcmp(p, common_name)) { + lwsl_err("%s: common name mismatch\n", __func__); + return -1; + } + } + + ret = X509_check_issued(trusted->cert, x509->cert); + if (ret != X509_V_OK) { + lwsl_err("%s: unable to verify cert relationship\n", __func__); + lws_tls_err_describe_clear(); + + return -1; + } + + return 0; +} + +#if defined(LWS_WITH_JOSE) +int +lws_x509_public_to_jwk(struct lws_jwk *jwk, struct lws_x509_cert *x509, + const char *curves, int rsa_min_bits) +{ + int id, n, ret = -1, count; + ASN1_OBJECT *obj = NULL; + const EC_POINT *ecpoint; + const EC_GROUP *ecgroup; + EC_KEY *ecpub = NULL; + X509_PUBKEY *pubkey; + RSA *rsapub = NULL; + BIGNUM *mpi[4]; + EVP_PKEY *pkey; + + memset(jwk, 0, sizeof(*jwk)); + + pubkey = X509_get_X509_PUBKEY(x509->cert); + if (!pubkey) { + lwsl_err("%s: missing pubkey alg in cert\n", __func__); + + goto bail; + } + + if (X509_PUBKEY_get0_param(&obj, NULL, NULL, NULL, pubkey) != 1) { + lwsl_err("%s: missing pubkey alg in cert\n", __func__); + + goto bail; + } + + id = OBJ_obj2nid(obj); + if (id == NID_undef) { + lwsl_err("%s: missing pubkey alg in cert\n", __func__); + + goto bail; + } + + lwsl_debug("%s: key type %d \"%s\"\n", __func__, id, OBJ_nid2ln(id)); + + pkey = X509_get_pubkey(x509->cert); + if (!pkey) { + lwsl_notice("%s: unable to extract pubkey", __func__); + + goto bail; + } + + switch (id) { + case NID_X9_62_id_ecPublicKey: + lwsl_debug("%s: EC key\n", __func__); + jwk->kty = LWS_GENCRYPTO_KTY_EC; + + if (!curves) { + lwsl_err("%s: ec curves not allowed\n", __func__); + + goto bail1; + } + + ecpub = EVP_PKEY_get1_EC_KEY(pkey); + if (!ecpub) { + lwsl_notice("%s: missing EC pubkey\n", __func__); + + goto bail1; + } + + ecpoint = EC_KEY_get0_public_key(ecpub); + if (!ecpoint) { + lwsl_err("%s: EC_KEY_get0_public_key failed\n", __func__); + goto bail2; + } + + ecgroup = EC_KEY_get0_group(ecpub); + if (!ecgroup) { + lwsl_err("%s: EC_KEY_get0_group failed\n", __func__); + goto bail2; + } + + /* validate the curve against ones we allow */ + + if (lws_genec_confirm_curve_allowed_by_tls_id(curves, + EC_GROUP_get_curve_name(ecgroup), jwk)) + /* already logged */ + goto bail2; + + mpi[LWS_GENCRYPTO_EC_KEYEL_CRV] = NULL; + mpi[LWS_GENCRYPTO_EC_KEYEL_X] = BN_new(); /* X */ + mpi[LWS_GENCRYPTO_EC_KEYEL_D] = NULL; + mpi[LWS_GENCRYPTO_EC_KEYEL_Y] = BN_new(); /* Y */ + +#if defined(LWS_HAVE_EC_POINT_get_affine_coordinates) + if (EC_POINT_get_affine_coordinates(ecgroup, ecpoint, +#else + if (EC_POINT_get_affine_coordinates_GFp(ecgroup, ecpoint, +#endif + mpi[LWS_GENCRYPTO_EC_KEYEL_X], + mpi[LWS_GENCRYPTO_EC_KEYEL_Y], + NULL) != 1) { + BN_clear_free(mpi[LWS_GENCRYPTO_EC_KEYEL_X]); + BN_clear_free(mpi[LWS_GENCRYPTO_EC_KEYEL_Y]); + lwsl_err("%s: EC_POINT_get_aff failed\n", __func__); + goto bail2; + } + count = LWS_GENCRYPTO_EC_KEYEL_COUNT; + n = LWS_GENCRYPTO_EC_KEYEL_X; + break; + + case NID_rsaEncryption: + lwsl_debug("%s: rsa key\n", __func__); + jwk->kty = LWS_GENCRYPTO_KTY_RSA; + + rsapub = EVP_PKEY_get1_RSA(pkey); + if (!rsapub) { + lwsl_notice("%s: missing RSA pubkey\n", __func__); + + goto bail1; + } + + if ((size_t)RSA_size(rsapub) * 8 < (size_t)rsa_min_bits) { + lwsl_err("%s: key bits %d less than minimum %d\n", + __func__, RSA_size(rsapub) * 8, rsa_min_bits); + + goto bail2; + } + +#if defined(LWS_HAVE_RSA_SET0_KEY) + /* we don't need d... but the api wants to write it */ + RSA_get0_key(rsapub, + (const BIGNUM **)&mpi[LWS_GENCRYPTO_RSA_KEYEL_N], + (const BIGNUM **)&mpi[LWS_GENCRYPTO_RSA_KEYEL_E], + (const BIGNUM **)&mpi[LWS_GENCRYPTO_RSA_KEYEL_D]); +#else + mpi[LWS_GENCRYPTO_RSA_KEYEL_E] = rsapub->e; + mpi[LWS_GENCRYPTO_RSA_KEYEL_N] = rsapub->n; + mpi[LWS_GENCRYPTO_RSA_KEYEL_D] = NULL; +#endif + count = LWS_GENCRYPTO_RSA_KEYEL_D; + n = LWS_GENCRYPTO_RSA_KEYEL_E; + break; + default: + lwsl_err("%s: unknown NID\n", __func__); + goto bail2; + } + + for (; n < count; n++) { + if (!mpi[n]) + continue; + jwk->e[n].len = BN_num_bytes(mpi[n]); + jwk->e[n].buf = lws_malloc(jwk->e[n].len, "certkeyimp"); + if (!jwk->e[n].buf) { + if (id == NID_X9_62_id_ecPublicKey) { + BN_clear_free(mpi[LWS_GENCRYPTO_EC_KEYEL_X]); + BN_clear_free(mpi[LWS_GENCRYPTO_EC_KEYEL_Y]); + } + goto bail2; + } + BN_bn2bin(mpi[n], jwk->e[n].buf); + } + + if (id == NID_X9_62_id_ecPublicKey) { + BN_clear_free(mpi[LWS_GENCRYPTO_EC_KEYEL_X]); + BN_clear_free(mpi[LWS_GENCRYPTO_EC_KEYEL_Y]); + } + + ret = 0; + +bail2: + if (id == NID_X9_62_id_ecPublicKey) + EC_KEY_free(ecpub); + else + RSA_free(rsapub); + +bail1: + EVP_PKEY_free(pkey); +bail: + /* jwk destroy will clean any partial state */ + if (ret) + lws_jwk_destroy(jwk); + + return ret; +} + +static int +lws_x509_jwk_privkey_pem_pp_cb(char *buf, int size, int rwflag, void *u) +{ + const char *pp = (const char *)u; + int n = (int)strlen(pp); + + if (n > size - 1) + return -1; + + memcpy(buf, pp, n + 1); + + return n; +} + +int +lws_x509_jwk_privkey_pem(struct lws_jwk *jwk, void *pem, size_t len, + const char *passphrase) +{ + BIO* bio = BIO_new(BIO_s_mem()); + BIGNUM *mpi, *dummy[6]; + EVP_PKEY *pkey = NULL; + EC_KEY *ecpriv = NULL; + RSA *rsapriv = NULL; + const BIGNUM *cmpi; + int n, m, ret = -1; + + BIO_write(bio, pem, (int)len); + PEM_read_bio_PrivateKey(bio, &pkey, lws_x509_jwk_privkey_pem_pp_cb, + (void *)passphrase); + BIO_free(bio); + lws_explicit_bzero((void *)pem, len); + if (!pkey) { + lwsl_err("%s: unable to parse PEM privkey\n", __func__); + lws_tls_err_describe_clear(); + + return -1; + } + + /* confirm the key type matches the existing jwk situation */ + + switch (jwk->kty) { + case LWS_GENCRYPTO_KTY_EC: + if (EVP_PKEY_type(EVP_PKEY_id(pkey)) != EVP_PKEY_EC) { + lwsl_err("%s: jwk is EC but privkey isn't\n", __func__); + + goto bail; + } + ecpriv = EVP_PKEY_get1_EC_KEY(pkey); + if (!ecpriv) { + lwsl_notice("%s: missing EC key\n", __func__); + + goto bail; + } + + cmpi = EC_KEY_get0_private_key(ecpriv); + + /* quick size check first */ + + n = BN_num_bytes(cmpi); + if (jwk->e[LWS_GENCRYPTO_EC_KEYEL_Y].len != (uint32_t)n) { + lwsl_err("%s: jwk key size doesn't match\n", __func__); + + goto bail1; + } + + /* TODO.. check public curve / group + point */ + + jwk->e[LWS_GENCRYPTO_EC_KEYEL_D].len = n; + jwk->e[LWS_GENCRYPTO_EC_KEYEL_D].buf = lws_malloc(n, "ec"); + if (!jwk->e[LWS_GENCRYPTO_EC_KEYEL_D].buf) + goto bail1; + + m = BN_bn2binpad(cmpi, jwk->e[LWS_GENCRYPTO_EC_KEYEL_D].buf, + jwk->e[LWS_GENCRYPTO_EC_KEYEL_D].len); + if ((unsigned int)m != (unsigned int)BN_num_bytes(cmpi)) + goto bail1; + + break; + + case LWS_GENCRYPTO_KTY_RSA: + if (EVP_PKEY_type(EVP_PKEY_id(pkey)) != EVP_PKEY_RSA) { + lwsl_err("%s: RSA jwk, non-RSA privkey\n", __func__); + + goto bail; + } + rsapriv = EVP_PKEY_get1_RSA(pkey); + if (!rsapriv) { + lwsl_notice("%s: missing RSA key\n", __func__); + + goto bail; + } + +#if defined(LWS_HAVE_RSA_SET0_KEY) + RSA_get0_key(rsapriv, (const BIGNUM **)&dummy[0], /* n */ + (const BIGNUM **)&dummy[1], /* e */ + (const BIGNUM **)&mpi); /* d */ + RSA_get0_factors(rsapriv, (const BIGNUM **)&dummy[4], /* p */ + (const BIGNUM **)&dummy[5]); /* q */ +#else + dummy[0] = rsapriv->n; + dummy[1] = rsapriv->e; + dummy[4] = rsapriv->p; + dummy[5] = rsapriv->q; + mpi = rsapriv->d; +#endif + + /* quick size check first */ + + n = BN_num_bytes(mpi); + if (jwk->e[LWS_GENCRYPTO_RSA_KEYEL_N].len != (uint32_t)n) { + lwsl_err("%s: jwk key size doesn't match\n", __func__); + + goto bail1; + } + + /* then check that n & e match what we got from the cert */ + + dummy[2] = BN_bin2bn(jwk->e[LWS_GENCRYPTO_RSA_KEYEL_N].buf, + jwk->e[LWS_GENCRYPTO_RSA_KEYEL_N].len, + NULL); + dummy[3] = BN_bin2bn(jwk->e[LWS_GENCRYPTO_RSA_KEYEL_E].buf, + jwk->e[LWS_GENCRYPTO_RSA_KEYEL_E].len, + NULL); + + m = BN_cmp(dummy[2], dummy[0]) | BN_cmp(dummy[3], dummy[1]); + BN_clear_free(dummy[2]); + BN_clear_free(dummy[3]); + if (m) { + lwsl_err("%s: privkey doesn't match jwk pubkey\n", + __func__); + + goto bail1; + } + + /* accept d from the PEM privkey into the JWK */ + + jwk->e[LWS_GENCRYPTO_RSA_KEYEL_D].len = n; + jwk->e[LWS_GENCRYPTO_RSA_KEYEL_D].buf = lws_malloc(n, "privjk"); + if (!jwk->e[LWS_GENCRYPTO_RSA_KEYEL_D].buf) + goto bail1; + + BN_bn2bin(mpi, jwk->e[LWS_GENCRYPTO_RSA_KEYEL_D].buf); + + /* accept p and q from the PEM privkey into the JWK */ + + jwk->e[LWS_GENCRYPTO_RSA_KEYEL_P].len = BN_num_bytes(dummy[4]); + jwk->e[LWS_GENCRYPTO_RSA_KEYEL_P].buf = lws_malloc(n, "privjk"); + if (!jwk->e[LWS_GENCRYPTO_RSA_KEYEL_P].buf) { + lws_free_set_NULL(jwk->e[LWS_GENCRYPTO_RSA_KEYEL_D].buf); + goto bail1; + } + BN_bn2bin(dummy[4], jwk->e[LWS_GENCRYPTO_RSA_KEYEL_P].buf); + + jwk->e[LWS_GENCRYPTO_RSA_KEYEL_Q].len = BN_num_bytes(dummy[5]); + jwk->e[LWS_GENCRYPTO_RSA_KEYEL_Q].buf = lws_malloc(n, "privjk"); + if (!jwk->e[LWS_GENCRYPTO_RSA_KEYEL_Q].buf) { + lws_free_set_NULL(jwk->e[LWS_GENCRYPTO_RSA_KEYEL_D].buf); + lws_free_set_NULL(jwk->e[LWS_GENCRYPTO_RSA_KEYEL_P].buf); + goto bail1; + } + BN_bn2bin(dummy[5], jwk->e[LWS_GENCRYPTO_RSA_KEYEL_Q].buf); + break; + default: + lwsl_err("%s: JWK has unknown kty %d\n", __func__, jwk->kty); + return -1; + } + + ret = 0; + +bail1: + if (jwk->kty == LWS_GENCRYPTO_KTY_EC) + EC_KEY_free(ecpriv); + else + RSA_free(rsapriv); + +bail: + EVP_PKEY_free(pkey); + + return ret; +} +#endif + +void +lws_x509_destroy(struct lws_x509_cert **x509) +{ + if (!*x509) + return; + + if ((*x509)->cert) { + X509_free((*x509)->cert); + (*x509)->cert = NULL; + } + + lws_free_set_NULL(*x509); +} diff -Nru libwebsockets-3.2.1/lib/tls/openssl/private.h libwebsockets-4.1.6/lib/tls/openssl/private.h --- libwebsockets-3.2.1/lib/tls/openssl/private.h 2019-12-18 14:45:31.000000000 +0000 +++ libwebsockets-4.1.6/lib/tls/openssl/private.h 1970-01-01 00:00:00.000000000 +0000 @@ -1,53 +0,0 @@ -/* - * libwebsockets - small server side websockets and web server implementation - * - * Copyright (C) 2010 - 2019 Andy Green - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation: - * version 2.1 of the License. - * - * This library is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with this library; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, - * MA 02110-1301 USA - * - * gencrypto openssl-specific helper declarations - */ - -/* - * one of these per different client context - * cc_owner is in lws_context.lws_context_tls - */ - -struct lws_tls_client_reuse { - lws_tls_ctx *ssl_client_ctx; - uint8_t hash[32]; - struct lws_dll2 cc_list; - int refcount; - int index; -}; - -typedef int (*next_proto_cb)(SSL *, const unsigned char **out, - unsigned char *outlen, const unsigned char *in, - unsigned int inlen, void *arg); - -struct lws_x509_cert { - X509 *cert; /* X509 is opaque, this has to be a pointer */ -}; - -int -lws_gencrypto_openssl_hash_to_NID(enum lws_genhash_types hash_type); - -const EVP_MD * -lws_gencrypto_openssl_hash_to_EVP_MD(enum lws_genhash_types hash_type); - -#if !defined(LWS_HAVE_BN_bn2binpad) -int BN_bn2binpad(const BIGNUM *a, unsigned char *to, int tolen); -#endif diff -Nru libwebsockets-3.2.1/lib/tls/openssl/private-lib-tls-openssl.h libwebsockets-4.1.6/lib/tls/openssl/private-lib-tls-openssl.h --- libwebsockets-3.2.1/lib/tls/openssl/private-lib-tls-openssl.h 1970-01-01 00:00:00.000000000 +0000 +++ libwebsockets-4.1.6/lib/tls/openssl/private-lib-tls-openssl.h 2020-12-01 17:40:26.000000000 +0000 @@ -0,0 +1,62 @@ + /* + * libwebsockets - small server side websockets and web server implementation + * + * Copyright (C) 2010 - 2019 Andy Green + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to + * deal in the Software without restriction, including without limitation the + * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or + * sell copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS + * IN THE SOFTWARE. + * + * gencrypto openssl-specific helper declarations + */ + +#if !defined(__LWS_PRIVATE_LIB_TLS_OPENSSL_H__) +#define __LWS_PRIVATE_LIB_TLS_OPENSSL_H__ + +/* + * one of these per different client context + * cc_owner is in lws_context.lws_context_tls + */ + +struct lws_tls_client_reuse { + lws_tls_ctx *ssl_client_ctx; + uint8_t hash[32]; + struct lws_dll2 cc_list; + int refcount; + int index; +}; + +typedef int (*next_proto_cb)(SSL *, const unsigned char **out, + unsigned char *outlen, const unsigned char *in, + unsigned int inlen, void *arg); + +struct lws_x509_cert { + X509 *cert; /* X509 is opaque, this has to be a pointer */ +}; + +int +lws_gencrypto_openssl_hash_to_NID(enum lws_genhash_types hash_type); + +const EVP_MD * +lws_gencrypto_openssl_hash_to_EVP_MD(enum lws_genhash_types hash_type); + +#if !defined(LWS_HAVE_BN_bn2binpad) +int BN_bn2binpad(const BIGNUM *a, unsigned char *to, int tolen); +#endif + +#endif + diff -Nru libwebsockets-3.2.1/lib/tls/openssl/ssl.c libwebsockets-4.1.6/lib/tls/openssl/ssl.c --- libwebsockets-3.2.1/lib/tls/openssl/ssl.c 2019-12-18 14:45:31.000000000 +0000 +++ libwebsockets-4.1.6/lib/tls/openssl/ssl.c 1970-01-01 00:00:00.000000000 +0000 @@ -1,510 +0,0 @@ -/* - * libwebsockets - small server side websockets and web server implementation - * - * Copyright (C) 2010-2018 Andy Green - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation: - * version 2.1 of the License. - * - * This library is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with this library; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, - * MA 02110-1301 USA - */ - -#include "core/private.h" -#include "tls/openssl/private.h" -#include - -int openssl_websocket_private_data_index, - openssl_SSL_CTX_private_data_index; - -/* - * Care: many openssl apis return 1 for success. These are translated to the - * lws convention of 0 for success. - */ - -int lws_openssl_describe_cipher(struct lws *wsi) -{ -#if !defined(LWS_WITH_NO_LOGS) - int np = -1; - SSL *s = wsi->tls.ssl; - - SSL_get_cipher_bits(s, &np); - lwsl_info("%s: wsi %p: %s, %s, %d bits, %s\n", __func__, wsi, - SSL_get_cipher_name(s), SSL_get_cipher(s), np, - SSL_get_cipher_version(s)); -#endif - - return 0; -} - -int lws_ssl_get_error(struct lws *wsi, int n) -{ - int m; - - if (!wsi->tls.ssl) - return 99; - - m = SSL_get_error(wsi->tls.ssl, n); - lwsl_debug("%s: %p %d -> %d (errno %d)\n", __func__, wsi->tls.ssl, n, m, - errno); - - return m; -} - -static int -lws_context_init_ssl_pem_passwd_cb(char *buf, int size, int rwflag, - void *userdata) -{ - struct lws_context_creation_info * info = - (struct lws_context_creation_info *)userdata; - - strncpy(buf, info->ssl_private_key_password, size); - buf[size - 1] = '\0'; - - return (int)strlen(buf); -} - -static int -lws_context_init_ssl_pem_passwd_client_cb(char *buf, int size, int rwflag, - void *userdata) -{ - struct lws_context_creation_info * info = - (struct lws_context_creation_info *)userdata; - const char *p = info->ssl_private_key_password; - - if (info->client_ssl_private_key_password) - p = info->client_ssl_private_key_password; - - strncpy(buf, p, size); - buf[size - 1] = '\0'; - - return (int)strlen(buf); -} - -void -lws_ssl_bind_passphrase(SSL_CTX *ssl_ctx, int is_client, - const struct lws_context_creation_info *info) -{ - if (!info->ssl_private_key_password && - !info->client_ssl_private_key_password) - return; - /* - * password provided, set ssl callback and user data - * for checking password which will be trigered during - * SSL_CTX_use_PrivateKey_file function - */ - SSL_CTX_set_default_passwd_cb_userdata(ssl_ctx, (void *)info); - SSL_CTX_set_default_passwd_cb(ssl_ctx, is_client ? - lws_context_init_ssl_pem_passwd_client_cb: - lws_context_init_ssl_pem_passwd_cb); -} - -static void -lws_ssl_destroy_client_ctx(struct lws_vhost *vhost) -{ - struct lws_tls_client_reuse *tcr; - - if (vhost->tls.user_supplied_ssl_ctx || !vhost->tls.ssl_client_ctx) - return; - - tcr = SSL_CTX_get_ex_data(vhost->tls.ssl_client_ctx, - openssl_SSL_CTX_private_data_index); - - if (!tcr || --tcr->refcount) - return; - - SSL_CTX_free(vhost->tls.ssl_client_ctx); - vhost->tls.ssl_client_ctx = NULL; - - vhost->context->tls.count_client_contexts--; - - lws_dll2_remove(&tcr->cc_list); - lws_free(tcr); -} - -LWS_VISIBLE void -lws_ssl_destroy(struct lws_vhost *vhost) -{ - if (!lws_check_opt(vhost->context->options, - LWS_SERVER_OPTION_DO_SSL_GLOBAL_INIT)) - return; - - if (vhost->tls.ssl_ctx) - SSL_CTX_free(vhost->tls.ssl_ctx); - - lws_ssl_destroy_client_ctx(vhost); - -// after 1.1.0 no need -#if (OPENSSL_VERSION_NUMBER < 0x10100000) -// <= 1.0.1f = old api, 1.0.1g+ = new api -#if (OPENSSL_VERSION_NUMBER <= 0x1000106f) || defined(USE_WOLFSSL) - ERR_remove_state(0); -#else -#if OPENSSL_VERSION_NUMBER >= 0x1010005f && \ - !defined(LIBRESSL_VERSION_NUMBER) && \ - !defined(OPENSSL_IS_BORINGSSL) - ERR_remove_thread_state(); -#else - ERR_remove_thread_state(NULL); -#endif -#endif - /* not needed after 1.1.0 */ -#if (OPENSSL_VERSION_NUMBER >= 0x10002000) && \ - (OPENSSL_VERSION_NUMBER <= 0x10100000) - SSL_COMP_free_compression_methods(); -#endif - ERR_free_strings(); - EVP_cleanup(); - CRYPTO_cleanup_all_ex_data(); -#endif -} - -LWS_VISIBLE int -lws_ssl_capable_read(struct lws *wsi, unsigned char *buf, int len) -{ - struct lws_context *context = wsi->context; - struct lws_context_per_thread *pt = &context->pt[(int)wsi->tsi]; - int n = 0, m; - - if (!wsi->tls.ssl) - return lws_ssl_capable_read_no_ssl(wsi, buf, len); - - lws_stats_bump(pt, LWSSTATS_C_API_READ, 1); - - errno = 0; - ERR_clear_error(); - n = SSL_read(wsi->tls.ssl, buf, len); -#if defined(LWS_WITH_ESP32) - if (!n && errno == LWS_ENOTCONN) { - lwsl_debug("%p: SSL_read ENOTCONN\n", wsi); - return LWS_SSL_CAPABLE_ERROR; - } -#endif -#if defined(LWS_WITH_STATS) - if (!wsi->seen_rx && wsi->accept_start_us) { - lws_stats_bump(pt, LWSSTATS_US_SSL_RX_DELAY_AVG, - lws_now_usecs() - - wsi->accept_start_us); - lws_stats_bump(pt, LWSSTATS_C_SSL_CONNS_HAD_RX, 1); - wsi->seen_rx = 1; - } -#endif - - - lwsl_debug("%p: SSL_read says %d\n", wsi, n); - /* manpage: returning 0 means connection shut down - * - * 2018-09-10: https://github.com/openssl/openssl/issues/1903 - * - * So, in summary, if you get a 0 or -1 return from SSL_read() / - * SSL_write(), you should call SSL_get_error(): - * - * - If you get back SSL_ERROR_RETURN_ZERO then you know the connection - * has been cleanly shutdown by the peer. To fully close the - * connection you may choose to call SSL_shutdown() to send a - * close_notify back. - * - * - If you get back SSL_ERROR_SSL then some kind of internal or - * protocol error has occurred. More details will be on the SSL error - * queue. You can also call SSL_get_shutdown(). If this indicates a - * state of SSL_RECEIVED_SHUTDOWN then you know a fatal alert has - * been received from the peer (if it had been a close_notify then - * SSL_get_error() would have returned SSL_ERROR_RETURN_ZERO). - * SSL_ERROR_SSL is considered fatal - you should not call - * SSL_shutdown() in this case. - * - * - If you get back SSL_ERROR_SYSCALL then some kind of fatal (i.e. - * non-retryable) error has occurred in a system call. - */ - if (n <= 0) { - m = lws_ssl_get_error(wsi, n); - lwsl_debug("%p: ssl err %d errno %d\n", wsi, m, errno); - if (m == SSL_ERROR_ZERO_RETURN) /* cleanly shut down */ - return LWS_SSL_CAPABLE_ERROR; - - /* hm not retryable.. could be 0 size pkt or error */ - - if (m == SSL_ERROR_SSL || m == SSL_ERROR_SYSCALL || - errno == LWS_ENOTCONN) { - - /* unclean, eg closed conn */ - - wsi->socket_is_permanently_unusable = 1; - - return LWS_SSL_CAPABLE_ERROR; - } - - /* retryable? */ - - if (SSL_want_read(wsi->tls.ssl)) { - lwsl_debug("%s: WANT_READ\n", __func__); - lwsl_debug("%p: LWS_SSL_CAPABLE_MORE_SERVICE\n", wsi); - return LWS_SSL_CAPABLE_MORE_SERVICE; - } - if (SSL_want_write(wsi->tls.ssl)) { - lwsl_debug("%s: WANT_WRITE\n", __func__); - lwsl_debug("%p: LWS_SSL_CAPABLE_MORE_SERVICE\n", wsi); - return LWS_SSL_CAPABLE_MORE_SERVICE; - } - - /* keep on trucking it seems */ - } - - lws_stats_bump(pt, LWSSTATS_B_READ, n); - - if (wsi->vhost) - wsi->vhost->conn_stats.rx += n; - - // lwsl_hexdump_err(buf, n); - - /* - * if it was our buffer that limited what we read, - * check if SSL has additional data pending inside SSL buffers. - * - * Because these won't signal at the network layer with POLLIN - * and if we don't realize, this data will sit there forever - */ - if (n != len) - goto bail; - if (!wsi->tls.ssl) - goto bail; - - if (SSL_pending(wsi->tls.ssl) && - lws_dll2_is_detached(&wsi->tls.dll_pending_tls)) - lws_dll2_add_head(&wsi->tls.dll_pending_tls, - &pt->tls.dll_pending_tls_owner); - - return n; -bail: - lws_ssl_remove_wsi_from_buffered_list(wsi); - - return n; -} - -LWS_VISIBLE int -lws_ssl_pending(struct lws *wsi) -{ - if (!wsi->tls.ssl) - return 0; - - return SSL_pending(wsi->tls.ssl); -} - -LWS_VISIBLE int -lws_ssl_capable_write(struct lws *wsi, unsigned char *buf, int len) -{ - int n, m; - - if (!wsi->tls.ssl) - return lws_ssl_capable_write_no_ssl(wsi, buf, len); - - errno = 0; - ERR_clear_error(); - n = SSL_write(wsi->tls.ssl, buf, len); - if (n > 0) - return n; - - m = lws_ssl_get_error(wsi, n); - if (m != SSL_ERROR_SYSCALL) { - if (m == SSL_ERROR_WANT_READ || SSL_want_read(wsi->tls.ssl)) { - lwsl_notice("%s: want read\n", __func__); - - return LWS_SSL_CAPABLE_MORE_SERVICE; - } - - if (m == SSL_ERROR_WANT_WRITE || SSL_want_write(wsi->tls.ssl)) { - lws_set_blocking_send(wsi); - - lwsl_debug("%s: want write\n", __func__); - - return LWS_SSL_CAPABLE_MORE_SERVICE; - } - } - - lwsl_debug("%s failed: %s\n",__func__, ERR_error_string(m, NULL)); - lws_tls_err_describe_clear(); - - wsi->socket_is_permanently_unusable = 1; - - return LWS_SSL_CAPABLE_ERROR; -} - -void -lws_ssl_info_callback(const SSL *ssl, int where, int ret) -{ - struct lws *wsi; - struct lws_context *context; - struct lws_ssl_info si; - -#ifndef USE_WOLFSSL - context = (struct lws_context *)SSL_CTX_get_ex_data( - SSL_get_SSL_CTX(ssl), - openssl_SSL_CTX_private_data_index); -#else - context = (struct lws_context *)SSL_CTX_get_ex_data( - SSL_get_SSL_CTX((SSL*) ssl), - openssl_SSL_CTX_private_data_index); -#endif - if (!context) - return; - wsi = wsi_from_fd(context, SSL_get_fd(ssl)); - if (!wsi) - return; - - if (!(where & wsi->vhost->tls.ssl_info_event_mask)) - return; - - si.where = where; - si.ret = ret; - - if (user_callback_handle_rxflow(wsi->protocol->callback, - wsi, LWS_CALLBACK_SSL_INFO, - wsi->user_space, &si, 0)) - lws_set_timeout(wsi, PENDING_TIMEOUT_KILLED_BY_SSL_INFO, -1); -} - - -LWS_VISIBLE int -lws_ssl_close(struct lws *wsi) -{ - lws_sockfd_type n; - - if (!wsi->tls.ssl) - return 0; /* not handled */ - -#if defined (LWS_HAVE_SSL_SET_INFO_CALLBACK) - /* kill ssl callbacks, because we will remove the fd from the - * table linking it to the wsi - */ - if (wsi->vhost->tls.ssl_info_event_mask) - SSL_set_info_callback(wsi->tls.ssl, NULL); -#endif - - n = SSL_get_fd(wsi->tls.ssl); - if (!wsi->socket_is_permanently_unusable) - SSL_shutdown(wsi->tls.ssl); - compatible_close(n); - SSL_free(wsi->tls.ssl); - wsi->tls.ssl = NULL; - - if (wsi->context->simultaneous_ssl_restriction && - wsi->context->simultaneous_ssl-- == - wsi->context->simultaneous_ssl_restriction) - /* we made space and can do an accept */ - lws_gate_accepts(wsi->context, 1); - - // lwsl_notice("%s: ssl restr %d, simul %d\n", __func__, - // wsi->context->simultaneous_ssl_restriction, - // wsi->context->simultaneous_ssl); - -#if defined(LWS_WITH_STATS) - wsi->context->updated = 1; -#endif - - return 1; /* handled */ -} - -void -lws_ssl_SSL_CTX_destroy(struct lws_vhost *vhost) -{ - if (vhost->tls.ssl_ctx) - SSL_CTX_free(vhost->tls.ssl_ctx); - - lws_ssl_destroy_client_ctx(vhost); - -#if defined(LWS_WITH_ACME) - lws_tls_acme_sni_cert_destroy(vhost); -#endif -} - -void -lws_ssl_context_destroy(struct lws_context *context) -{ -// after 1.1.0 no need -#if (OPENSSL_VERSION_NUMBER < 0x10100000) -// <= 1.0.1f = old api, 1.0.1g+ = new api -#if (OPENSSL_VERSION_NUMBER <= 0x1000106f) || defined(USE_WOLFSSL) - ERR_remove_state(0); -#else -#if OPENSSL_VERSION_NUMBER >= 0x1010005f && \ - !defined(LIBRESSL_VERSION_NUMBER) && \ - !defined(OPENSSL_IS_BORINGSSL) - ERR_remove_thread_state(); -#else - ERR_remove_thread_state(NULL); -#endif -#endif - // after 1.1.0 no need -#if (OPENSSL_VERSION_NUMBER >= 0x10002000) && (OPENSSL_VERSION_NUMBER <= 0x10100000) - SSL_COMP_free_compression_methods(); -#endif - ERR_free_strings(); - EVP_cleanup(); - CRYPTO_cleanup_all_ex_data(); -#endif -} - -lws_tls_ctx * -lws_tls_ctx_from_wsi(struct lws *wsi) -{ - if (!wsi->tls.ssl) - return NULL; - - return SSL_get_SSL_CTX(wsi->tls.ssl); -} - -enum lws_ssl_capable_status -__lws_tls_shutdown(struct lws *wsi) -{ - int n; - - errno = 0; - ERR_clear_error(); - n = SSL_shutdown(wsi->tls.ssl); - lwsl_debug("SSL_shutdown=%d for fd %d\n", n, wsi->desc.sockfd); - switch (n) { - case 1: /* successful completion */ - n = shutdown(wsi->desc.sockfd, SHUT_WR); - return LWS_SSL_CAPABLE_DONE; - - case 0: /* needs a retry */ - __lws_change_pollfd(wsi, 0, LWS_POLLIN); - return LWS_SSL_CAPABLE_MORE_SERVICE; - - default: /* fatal error, or WANT */ - n = SSL_get_error(wsi->tls.ssl, n); - if (n != SSL_ERROR_SYSCALL && n != SSL_ERROR_SSL) { - if (SSL_want_read(wsi->tls.ssl)) { - lwsl_debug("(wants read)\n"); - __lws_change_pollfd(wsi, 0, LWS_POLLIN); - return LWS_SSL_CAPABLE_MORE_SERVICE_READ; - } - if (SSL_want_write(wsi->tls.ssl)) { - lwsl_debug("(wants write)\n"); - __lws_change_pollfd(wsi, 0, LWS_POLLOUT); - return LWS_SSL_CAPABLE_MORE_SERVICE_WRITE; - } - } - return LWS_SSL_CAPABLE_ERROR; - } -} - - -static int -tops_fake_POLLIN_for_buffered_openssl(struct lws_context_per_thread *pt) -{ - return lws_tls_fake_POLLIN_for_buffered(pt); -} - -const struct lws_tls_ops tls_ops_openssl = { - /* fake_POLLIN_for_buffered */ tops_fake_POLLIN_for_buffered_openssl, -}; diff -Nru libwebsockets-3.2.1/lib/tls/openssl/tls.c libwebsockets-4.1.6/lib/tls/openssl/tls.c --- libwebsockets-3.2.1/lib/tls/openssl/tls.c 2019-12-18 14:45:31.000000000 +0000 +++ libwebsockets-4.1.6/lib/tls/openssl/tls.c 1970-01-01 00:00:00.000000000 +0000 @@ -1,193 +0,0 @@ -/* - * libwebsockets - small server side websockets and web server implementation - * - * Copyright (C) 2010-2018 Andy Green - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation: - * version 2.1 of the License. - * - * This library is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with this library; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, - * MA 02110-1301 USA - */ - -#include "core/private.h" -#include "tls/openssl/private.h" - -extern int openssl_websocket_private_data_index, -openssl_SSL_CTX_private_data_index; - -char* lws_ssl_get_error_string(int status, int ret, char *buf, size_t len) { - switch (status) { - case SSL_ERROR_NONE: - return lws_strncpy(buf, "SSL_ERROR_NONE", len); - case SSL_ERROR_ZERO_RETURN: - return lws_strncpy(buf, "SSL_ERROR_ZERO_RETURN", len); - case SSL_ERROR_WANT_READ: - return lws_strncpy(buf, "SSL_ERROR_WANT_READ", len); - case SSL_ERROR_WANT_WRITE: - return lws_strncpy(buf, "SSL_ERROR_WANT_WRITE", len); - case SSL_ERROR_WANT_CONNECT: - return lws_strncpy(buf, "SSL_ERROR_WANT_CONNECT", len); - case SSL_ERROR_WANT_ACCEPT: - return lws_strncpy(buf, "SSL_ERROR_WANT_ACCEPT", len); - case SSL_ERROR_WANT_X509_LOOKUP: - return lws_strncpy(buf, "SSL_ERROR_WANT_X509_LOOKUP", len); - case SSL_ERROR_SYSCALL: - switch (ret) { - case 0: - lws_snprintf(buf, len, "SSL_ERROR_SYSCALL: EOF"); - return buf; - case -1: -#ifndef LWS_PLAT_OPTEE - lws_snprintf(buf, len, "SSL_ERROR_SYSCALL: %s", - strerror(errno)); -#else - lws_snprintf(buf, len, "SSL_ERROR_SYSCALL: %d", errno); -#endif - return buf; - default: - return strncpy(buf, "SSL_ERROR_SYSCALL", len); - } - case SSL_ERROR_SSL: - return "SSL_ERROR_SSL"; - default: - return "SSL_ERROR_UNKNOWN"; - } -} - -void -lws_tls_err_describe_clear(void) -{ - char buf[160]; - unsigned long l; - - do { - l = ERR_get_error(); - if (!l) - break; - - ERR_error_string_n(l, buf, sizeof(buf)); - lwsl_info(" openssl error: %s\n", buf); - } while (l); - lwsl_info("\n"); -} - -#if LWS_MAX_SMP != 1 - -static pthread_mutex_t *openssl_mutexes; - -static void -lws_openssl_lock_callback(int mode, int type, const char *file, int line) -{ - (void)file; - (void)line; - - if (mode & CRYPTO_LOCK) - pthread_mutex_lock(&openssl_mutexes[type]); - else - pthread_mutex_unlock(&openssl_mutexes[type]); -} - -static unsigned long -lws_openssl_thread_id(void) -{ - return (unsigned long)pthread_self(); -} -#endif - - -int -lws_context_init_ssl_library(const struct lws_context_creation_info *info) -{ -#ifdef USE_WOLFSSL -#ifdef USE_OLD_CYASSL - lwsl_info(" Compiled with CyaSSL support\n"); -#else - lwsl_info(" Compiled with wolfSSL support\n"); -#endif -#else -#if defined(LWS_WITH_BORINGSSL) - lwsl_info(" Compiled with BoringSSL support\n"); -#else - lwsl_info(" Compiled with OpenSSL support\n"); -#endif -#endif - if (!lws_check_opt(info->options, LWS_SERVER_OPTION_DO_SSL_GLOBAL_INIT)) { - lwsl_info(" SSL disabled: no " - "LWS_SERVER_OPTION_DO_SSL_GLOBAL_INIT\n"); - return 0; - } - - /* basic openssl init */ - - lwsl_info("Doing SSL library init\n"); - -#if OPENSSL_VERSION_NUMBER < 0x10100000L - SSL_library_init(); - OpenSSL_add_all_algorithms(); - SSL_load_error_strings(); -#else - OPENSSL_init_ssl(OPENSSL_INIT_LOAD_SSL_STRINGS, NULL); -#endif -#if defined(LWS_WITH_NETWORK) - openssl_websocket_private_data_index = - SSL_get_ex_new_index(0, "lws", NULL, NULL, NULL); - - openssl_SSL_CTX_private_data_index = SSL_CTX_get_ex_new_index(0, - NULL, NULL, NULL, NULL); -#endif - -#if LWS_MAX_SMP != 1 - { - int n; - - openssl_mutexes = (pthread_mutex_t *) - OPENSSL_malloc(CRYPTO_num_locks() * - sizeof(openssl_mutexes[0])); - - for (n = 0; n < CRYPTO_num_locks(); n++) - pthread_mutex_init(&openssl_mutexes[n], NULL); - - /* - * These "functions" disappeared in later OpenSSL which is - * already threadsafe. - */ - - (void)lws_openssl_thread_id; - (void)lws_openssl_lock_callback; - - CRYPTO_set_id_callback(lws_openssl_thread_id); - CRYPTO_set_locking_callback(lws_openssl_lock_callback); - } -#endif - - return 0; -} - -void -lws_context_deinit_ssl_library(struct lws_context *context) -{ -#if LWS_MAX_SMP != 1 - int n; - - if (!lws_check_opt(context->options, - LWS_SERVER_OPTION_DO_SSL_GLOBAL_INIT)) - return; - - CRYPTO_set_locking_callback(NULL); - - for (n = 0; n < CRYPTO_num_locks(); n++) - pthread_mutex_destroy(&openssl_mutexes[n]); - - OPENSSL_free(openssl_mutexes); -#endif -} diff -Nru libwebsockets-3.2.1/lib/tls/openssl/x509.c libwebsockets-4.1.6/lib/tls/openssl/x509.c --- libwebsockets-3.2.1/lib/tls/openssl/x509.c 2019-12-18 14:45:31.000000000 +0000 +++ libwebsockets-4.1.6/lib/tls/openssl/x509.c 1970-01-01 00:00:00.000000000 +0000 @@ -1,664 +0,0 @@ -/* - * libwebsockets - OpenSSL-specific lws apis - * - * Copyright (C) 2010 - 2019 Andy Green - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation: - * version 2.1 of the License. - * - * This library is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with this library; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, - * MA 02110-1301 USA - */ - -#include "core/private.h" -#include "tls/openssl/private.h" - -#if !defined(LWS_PLAT_OPTEE) -static int -dec(char c) -{ - return c - '0'; -} -#endif - -static time_t -lws_tls_openssl_asn1time_to_unix(ASN1_TIME *as) -{ -#if !defined(LWS_PLAT_OPTEE) - - const char *p = (const char *)as->data; - struct tm t; - - /* [YY]YYMMDDHHMMSSZ */ - - memset(&t, 0, sizeof(t)); - - if (strlen(p) == 13) { - t.tm_year = (dec(p[0]) * 10) + dec(p[1]) + 100; - p += 2; - } else { - t.tm_year = (dec(p[0]) * 1000) + (dec(p[1]) * 100) + - (dec(p[2]) * 10) + dec(p[3]); - p += 4; - } - t.tm_mon = (dec(p[0]) * 10) + dec(p[1]) - 1; - p += 2; - t.tm_mday = (dec(p[0]) * 10) + dec(p[1]) - 1; - p += 2; - t.tm_hour = (dec(p[0]) * 10) + dec(p[1]); - p += 2; - t.tm_min = (dec(p[0]) * 10) + dec(p[1]); - p += 2; - t.tm_sec = (dec(p[0]) * 10) + dec(p[1]); - t.tm_isdst = 0; - - return mktime(&t); -#else - return (time_t)-1; -#endif -} - -int -lws_tls_openssl_cert_info(X509 *x509, enum lws_tls_cert_info type, - union lws_tls_cert_info_results *buf, size_t len) -{ - X509_NAME *xn; -#if !defined(LWS_PLAT_OPTEE) - char *p; -#endif - - if (!x509) - return -1; - -#if OPENSSL_VERSION_NUMBER >= 0x10100000L && !defined(X509_get_notBefore) -#define X509_get_notBefore(x) X509_getm_notBefore(x) -#define X509_get_notAfter(x) X509_getm_notAfter(x) -#endif - - switch (type) { - case LWS_TLS_CERT_INFO_VALIDITY_FROM: - buf->time = lws_tls_openssl_asn1time_to_unix( - X509_get_notBefore(x509)); - if (buf->time == (time_t)-1) - return -1; - break; - - case LWS_TLS_CERT_INFO_VALIDITY_TO: - buf->time = lws_tls_openssl_asn1time_to_unix( - X509_get_notAfter(x509)); - if (buf->time == (time_t)-1) - return -1; - break; - - case LWS_TLS_CERT_INFO_COMMON_NAME: -#if defined(LWS_PLAT_OPTEE) - return -1; -#else - xn = X509_get_subject_name(x509); - if (!xn) - return -1; - X509_NAME_oneline(xn, buf->ns.name, (int)len - 2); - p = strstr(buf->ns.name, "/CN="); - if (p) - memmove(buf->ns.name, p + 4, strlen(p + 4) + 1); - buf->ns.len = (int)strlen(buf->ns.name); - return 0; -#endif - case LWS_TLS_CERT_INFO_ISSUER_NAME: - xn = X509_get_issuer_name(x509); - if (!xn) - return -1; - X509_NAME_oneline(xn, buf->ns.name, (int)len - 1); - buf->ns.len = (int)strlen(buf->ns.name); - return 0; - - case LWS_TLS_CERT_INFO_USAGE: -#if defined(LWS_HAVE_X509_get_key_usage) - buf->usage = X509_get_key_usage(x509); - break; -#else - return -1; -#endif - - case LWS_TLS_CERT_INFO_OPAQUE_PUBLIC_KEY: - { -#ifndef USE_WOLFSSL - size_t klen = i2d_X509_PUBKEY(X509_get_X509_PUBKEY(x509), NULL); - uint8_t *tmp, *ptmp; - - if (!klen || klen > len) - return -1; - - tmp = (uint8_t *)OPENSSL_malloc(klen); - if (!tmp) - return -1; - - ptmp = tmp; - if (i2d_X509_PUBKEY( - X509_get_X509_PUBKEY(x509), &ptmp) != (int)klen || - !ptmp || lws_ptr_diff(ptmp, tmp) != (int)klen) { - lwsl_info("%s: cert public key extraction failed\n", - __func__); - if (ptmp) - OPENSSL_free(tmp); - - return -1; - } - - buf->ns.len = (int)klen; - memcpy(buf->ns.name, tmp, klen); - OPENSSL_free(tmp); -#endif - return 0; - } - default: - return -1; - } - - return 0; -} - -int -lws_x509_info(struct lws_x509_cert *x509, enum lws_tls_cert_info type, - union lws_tls_cert_info_results *buf, size_t len) -{ - return lws_tls_openssl_cert_info(x509->cert, type, buf, len); -} - -#if defined(LWS_WITH_NETWORK) -int -lws_tls_vhost_cert_info(struct lws_vhost *vhost, enum lws_tls_cert_info type, - union lws_tls_cert_info_results *buf, size_t len) -{ -#if defined(LWS_HAVE_SSL_CTX_get0_certificate) - X509 *x509 = SSL_CTX_get0_certificate(vhost->tls.ssl_ctx); - - return lws_tls_openssl_cert_info(x509, type, buf, len); -#else - lwsl_notice("openssl is too old to support %s\n", __func__); - - return -1; -#endif -} - - - -int -lws_tls_peer_cert_info(struct lws *wsi, enum lws_tls_cert_info type, - union lws_tls_cert_info_results *buf, size_t len) -{ - int rc = 0; - X509 *x509; - - wsi = lws_get_network_wsi(wsi); - - x509 = SSL_get_peer_certificate(wsi->tls.ssl); - - if (!x509) { - lwsl_debug("no peer cert\n"); - - return -1; - } - - switch (type) { - case LWS_TLS_CERT_INFO_VERIFIED: - buf->verified = SSL_get_verify_result(wsi->tls.ssl) == - X509_V_OK; - break; - default: - rc = lws_tls_openssl_cert_info(x509, type, buf, len); - } - - X509_free(x509); - - return rc; -} -#endif - -int -lws_x509_create(struct lws_x509_cert **x509) -{ - *x509 = lws_malloc(sizeof(**x509), __func__); - if (*x509) - (*x509)->cert = NULL; - - return !(*x509); -} - -int -lws_x509_parse_from_pem(struct lws_x509_cert *x509, const void *pem, size_t len) -{ - BIO* bio = BIO_new(BIO_s_mem()); - - BIO_write(bio, pem, (int)len); - x509->cert = PEM_read_bio_X509(bio, NULL, NULL, NULL); - BIO_free(bio); - if (!x509->cert) { - lwsl_err("%s: unable to parse PEM cert\n", __func__); - lws_tls_err_describe_clear(); - - return -1; - } - - return 0; -} - -int -lws_x509_verify(struct lws_x509_cert *x509, struct lws_x509_cert *trusted, - const char *common_name) -{ - char c[32], *p; - int ret; - - if (common_name) { - X509_NAME *xn = X509_get_subject_name(x509->cert); - if (!xn) - return -1; - X509_NAME_oneline(xn, c, (int)sizeof(c) - 2); - p = strstr(c, "/CN="); - if (p) - p = p + 4; - else - p = c; - - if (strcmp(p, common_name)) { - lwsl_err("%s: common name mismatch\n", __func__); - return -1; - } - } - - ret = X509_check_issued(trusted->cert, x509->cert); - if (ret != X509_V_OK) { - lwsl_err("%s: unable to verify cert relationship\n", __func__); - lws_tls_err_describe_clear(); - - return -1; - } - - return 0; -} - -#if defined(LWS_WITH_JOSE) -int -lws_x509_public_to_jwk(struct lws_jwk *jwk, struct lws_x509_cert *x509, - const char *curves, int rsa_min_bits) -{ - int id, n, ret = -1, count; - ASN1_OBJECT *obj = NULL; - const EC_POINT *ecpoint; - const EC_GROUP *ecgroup; - EC_KEY *ecpub = NULL; - X509_PUBKEY *pubkey; - RSA *rsapub = NULL; - BIGNUM *mpi[4]; - EVP_PKEY *pkey; - - memset(jwk, 0, sizeof(*jwk)); - - pubkey = X509_get_X509_PUBKEY(x509->cert); - if (!pubkey) { - lwsl_err("%s: missing pubkey alg in cert\n", __func__); - - goto bail; - } - - if (X509_PUBKEY_get0_param(&obj, NULL, NULL, NULL, pubkey) != 1) { - lwsl_err("%s: missing pubkey alg in cert\n", __func__); - - goto bail; - } - - id = OBJ_obj2nid(obj); - if (id == NID_undef) { - lwsl_err("%s: missing pubkey alg in cert\n", __func__); - - goto bail; - } - - lwsl_debug("%s: key type %d \"%s\"\n", __func__, id, OBJ_nid2ln(id)); - - pkey = X509_get_pubkey(x509->cert); - if (!pkey) { - lwsl_notice("%s: unable to extract pubkey", __func__); - - goto bail; - } - - switch (id) { - case NID_X9_62_id_ecPublicKey: - lwsl_debug("%s: EC key\n", __func__); - jwk->kty = LWS_GENCRYPTO_KTY_EC; - - if (!curves) { - lwsl_err("%s: ec curves not allowed\n", __func__); - - goto bail1; - } - - ecpub = EVP_PKEY_get1_EC_KEY(pkey); - if (!ecpub) { - lwsl_notice("%s: missing EC pubkey\n", __func__); - - goto bail1; - } - - ecpoint = EC_KEY_get0_public_key(ecpub); - if (!ecpoint) { - lwsl_err("%s: EC_KEY_get0_public_key failed\n", __func__); - goto bail2; - } - - ecgroup = EC_KEY_get0_group(ecpub); - if (!ecgroup) { - lwsl_err("%s: EC_KEY_get0_group failed\n", __func__); - goto bail2; - } - - /* validate the curve against ones we allow */ - - if (lws_genec_confirm_curve_allowed_by_tls_id(curves, - EC_GROUP_get_curve_name(ecgroup), jwk)) - /* already logged */ - goto bail2; - - mpi[LWS_GENCRYPTO_EC_KEYEL_CRV] = NULL; - mpi[LWS_GENCRYPTO_EC_KEYEL_X] = BN_new(); /* X */ - mpi[LWS_GENCRYPTO_EC_KEYEL_D] = NULL; - mpi[LWS_GENCRYPTO_EC_KEYEL_Y] = BN_new(); /* Y */ - -#if defined(LWS_HAVE_EC_POINT_get_affine_coordinates) - if (EC_POINT_get_affine_coordinates(ecgroup, ecpoint, -#else - if (EC_POINT_get_affine_coordinates_GFp(ecgroup, ecpoint, -#endif - mpi[LWS_GENCRYPTO_EC_KEYEL_X], - mpi[LWS_GENCRYPTO_EC_KEYEL_Y], - NULL) != 1) { - BN_clear_free(mpi[LWS_GENCRYPTO_EC_KEYEL_X]); - BN_clear_free(mpi[LWS_GENCRYPTO_EC_KEYEL_Y]); - lwsl_err("%s: EC_POINT_get_aff failed\n", __func__); - goto bail2; - } - count = LWS_GENCRYPTO_EC_KEYEL_COUNT; - n = LWS_GENCRYPTO_EC_KEYEL_X; - break; - - case NID_rsaEncryption: - lwsl_debug("%s: rsa key\n", __func__); - jwk->kty = LWS_GENCRYPTO_KTY_RSA; - - rsapub = EVP_PKEY_get1_RSA(pkey); - if (!rsapub) { - lwsl_notice("%s: missing RSA pubkey\n", __func__); - - goto bail1; - } - - if ((size_t)RSA_size(rsapub) * 8 < (size_t)rsa_min_bits) { - lwsl_err("%s: key bits %d less than minimum %d\n", - __func__, RSA_size(rsapub) * 8, rsa_min_bits); - - goto bail2; - } - -#if defined(LWS_HAVE_RSA_SET0_KEY) - /* we don't need d... but the api wants to write it */ - RSA_get0_key(rsapub, - (const BIGNUM **)&mpi[LWS_GENCRYPTO_RSA_KEYEL_N], - (const BIGNUM **)&mpi[LWS_GENCRYPTO_RSA_KEYEL_E], - (const BIGNUM **)&mpi[LWS_GENCRYPTO_RSA_KEYEL_D]); -#else - mpi[LWS_GENCRYPTO_RSA_KEYEL_E] = rsapub->e; - mpi[LWS_GENCRYPTO_RSA_KEYEL_N] = rsapub->n; - mpi[LWS_GENCRYPTO_RSA_KEYEL_D] = NULL; -#endif - count = LWS_GENCRYPTO_RSA_KEYEL_D; - n = LWS_GENCRYPTO_RSA_KEYEL_E; - break; - default: - lwsl_err("%s: unknown NID\n", __func__); - goto bail2; - } - - for (; n < count; n++) { - if (!mpi[n]) - continue; - jwk->e[n].len = BN_num_bytes(mpi[n]); - jwk->e[n].buf = lws_malloc(jwk->e[n].len, "certkeyimp"); - if (!jwk->e[n].buf) { - if (id == NID_X9_62_id_ecPublicKey) { - BN_clear_free(mpi[LWS_GENCRYPTO_EC_KEYEL_X]); - BN_clear_free(mpi[LWS_GENCRYPTO_EC_KEYEL_Y]); - } - goto bail2; - } - BN_bn2bin(mpi[n], jwk->e[n].buf); - } - - if (id == NID_X9_62_id_ecPublicKey) { - BN_clear_free(mpi[LWS_GENCRYPTO_EC_KEYEL_X]); - BN_clear_free(mpi[LWS_GENCRYPTO_EC_KEYEL_Y]); - } - - ret = 0; - -bail2: - if (id == NID_X9_62_id_ecPublicKey) - EC_KEY_free(ecpub); - else - RSA_free(rsapub); - -bail1: - EVP_PKEY_free(pkey); -bail: - /* jwk destroy will clean any partial state */ - if (ret) - lws_jwk_destroy(jwk); - - return ret; -} - -static int -lws_x509_jwk_privkey_pem_pp_cb(char *buf, int size, int rwflag, void *u) -{ - const char *pp = (const char *)u; - int n = strlen(pp); - - if (n > size - 1) - return -1; - - memcpy(buf, pp, n + 1); - - return n; -} - -int -lws_x509_jwk_privkey_pem(struct lws_jwk *jwk, void *pem, size_t len, - const char *passphrase) -{ - BIO* bio = BIO_new(BIO_s_mem()); - BIGNUM *mpi, *dummy[6]; - EVP_PKEY *pkey = NULL; - EC_KEY *ecpriv = NULL; - RSA *rsapriv = NULL; - const BIGNUM *cmpi; - int n, m, ret = -1; - - BIO_write(bio, pem, (int)len); - PEM_read_bio_PrivateKey(bio, &pkey, lws_x509_jwk_privkey_pem_pp_cb, - (void *)passphrase); - BIO_free(bio); - lws_explicit_bzero((void *)pem, len); - if (!pkey) { - lwsl_err("%s: unable to parse PEM privkey\n", __func__); - lws_tls_err_describe_clear(); - - return -1; - } - - /* confirm the key type matches the existing jwk situation */ - - switch (jwk->kty) { - case LWS_GENCRYPTO_KTY_EC: - if (EVP_PKEY_type(EVP_PKEY_id(pkey)) != EVP_PKEY_EC) { - lwsl_err("%s: jwk is EC but privkey isn't\n", __func__); - - goto bail; - } - ecpriv = EVP_PKEY_get1_EC_KEY(pkey); - if (!ecpriv) { - lwsl_notice("%s: missing EC key\n", __func__); - - goto bail; - } - - cmpi = EC_KEY_get0_private_key(ecpriv); - - /* quick size check first */ - - n = BN_num_bytes(cmpi); - if (jwk->e[LWS_GENCRYPTO_EC_KEYEL_Y].len != (uint32_t)n) { - lwsl_err("%s: jwk key size doesn't match\n", __func__); - - goto bail1; - } - - /* TODO.. check public curve / group + point */ - - jwk->e[LWS_GENCRYPTO_EC_KEYEL_D].len = n; - jwk->e[LWS_GENCRYPTO_EC_KEYEL_D].buf = lws_malloc(n, "ec"); - if (!jwk->e[LWS_GENCRYPTO_EC_KEYEL_D].buf) - goto bail1; - - m = BN_bn2binpad(cmpi, jwk->e[LWS_GENCRYPTO_EC_KEYEL_D].buf, - jwk->e[LWS_GENCRYPTO_EC_KEYEL_D].len); - if ((unsigned int)m != (unsigned int)BN_num_bytes(cmpi)) - goto bail1; - - break; - - case LWS_GENCRYPTO_KTY_RSA: - if (EVP_PKEY_type(EVP_PKEY_id(pkey)) != EVP_PKEY_RSA) { - lwsl_err("%s: RSA jwk, non-RSA privkey\n", __func__); - - goto bail; - } - rsapriv = EVP_PKEY_get1_RSA(pkey); - if (!rsapriv) { - lwsl_notice("%s: missing RSA key\n", __func__); - - goto bail; - } - -#if defined(LWS_HAVE_RSA_SET0_KEY) - RSA_get0_key(rsapriv, (const BIGNUM **)&dummy[0], /* n */ - (const BIGNUM **)&dummy[1], /* e */ - (const BIGNUM **)&mpi); /* d */ - RSA_get0_factors(rsapriv, (const BIGNUM **)&dummy[4], /* p */ - (const BIGNUM **)&dummy[5]); /* q */ -#else - dummy[0] = rsapriv->n; - dummy[1] = rsapriv->e; - dummy[4] = rsapriv->p; - dummy[5] = rsapriv->q; - mpi = rsapriv->d; -#endif - - /* quick size check first */ - - n = BN_num_bytes(mpi); - if (jwk->e[LWS_GENCRYPTO_RSA_KEYEL_N].len != (uint32_t)n) { - lwsl_err("%s: jwk key size doesn't match\n", __func__); - - goto bail1; - } - - /* then check that n & e match what we got from the cert */ - - dummy[2] = BN_bin2bn(jwk->e[LWS_GENCRYPTO_RSA_KEYEL_N].buf, - jwk->e[LWS_GENCRYPTO_RSA_KEYEL_N].len, - NULL); - dummy[3] = BN_bin2bn(jwk->e[LWS_GENCRYPTO_RSA_KEYEL_E].buf, - jwk->e[LWS_GENCRYPTO_RSA_KEYEL_E].len, - NULL); - - m = BN_cmp(dummy[2], dummy[0]) | BN_cmp(dummy[3], dummy[1]); - BN_clear_free(dummy[2]); - BN_clear_free(dummy[3]); - if (m) { - lwsl_err("%s: privkey doesn't match jwk pubkey\n", - __func__); - - goto bail1; - } - - /* accept d from the PEM privkey into the JWK */ - - jwk->e[LWS_GENCRYPTO_RSA_KEYEL_D].len = n; - jwk->e[LWS_GENCRYPTO_RSA_KEYEL_D].buf = lws_malloc(n, "privjk"); - if (!jwk->e[LWS_GENCRYPTO_RSA_KEYEL_D].buf) - goto bail1; - - BN_bn2bin(mpi, jwk->e[LWS_GENCRYPTO_RSA_KEYEL_D].buf); - - /* accept p and q from the PEM privkey into the JWK */ - - jwk->e[LWS_GENCRYPTO_RSA_KEYEL_P].len = BN_num_bytes(dummy[4]); - jwk->e[LWS_GENCRYPTO_RSA_KEYEL_P].buf = lws_malloc(n, "privjk"); - if (!jwk->e[LWS_GENCRYPTO_RSA_KEYEL_P].buf) { - lws_free_set_NULL(jwk->e[LWS_GENCRYPTO_RSA_KEYEL_D].buf); - goto bail1; - } - BN_bn2bin(dummy[4], jwk->e[LWS_GENCRYPTO_RSA_KEYEL_P].buf); - - jwk->e[LWS_GENCRYPTO_RSA_KEYEL_Q].len = BN_num_bytes(dummy[5]); - jwk->e[LWS_GENCRYPTO_RSA_KEYEL_Q].buf = lws_malloc(n, "privjk"); - if (!jwk->e[LWS_GENCRYPTO_RSA_KEYEL_Q].buf) { - lws_free_set_NULL(jwk->e[LWS_GENCRYPTO_RSA_KEYEL_D].buf); - lws_free_set_NULL(jwk->e[LWS_GENCRYPTO_RSA_KEYEL_P].buf); - goto bail1; - } - BN_bn2bin(dummy[5], jwk->e[LWS_GENCRYPTO_RSA_KEYEL_Q].buf); - break; - default: - lwsl_err("%s: JWK has unknown kty %d\n", __func__, jwk->kty); - return -1; - } - - ret = 0; - -bail1: - if (jwk->kty == LWS_GENCRYPTO_KTY_EC) - EC_KEY_free(ecpriv); - else - RSA_free(rsapriv); - -bail: - EVP_PKEY_free(pkey); - - return ret; -} -#endif - -void -lws_x509_destroy(struct lws_x509_cert **x509) -{ - if (!*x509) - return; - - if ((*x509)->cert) { - X509_free((*x509)->cert); - (*x509)->cert = NULL; - } - - lws_free_set_NULL(*x509); -} diff -Nru libwebsockets-3.2.1/lib/tls/private.h libwebsockets-4.1.6/lib/tls/private.h --- libwebsockets-3.2.1/lib/tls/private.h 2019-12-18 14:45:31.000000000 +0000 +++ libwebsockets-4.1.6/lib/tls/private.h 1970-01-01 00:00:00.000000000 +0000 @@ -1,182 +0,0 @@ -/* - * libwebsockets - small server side websockets and web server implementation - * - * Copyright (C) 2010 - 2019 Andy Green - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation: - * version 2.1 of the License. - * - * This library is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with this library; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, - * MA 02110-1301 USA - * - * This is included from core/private.h if LWS_WITH_TLS - */ - -#if !defined(__LWS_TLS_PRIVATE_H__) -#define __LWS_TLS_PRIVATE_H__ - - -#if defined(LWS_WITH_TLS) - -#if defined(USE_WOLFSSL) - #if defined(USE_OLD_CYASSL) - #if defined(_WIN32) - #include - #include - #else - #include - #endif - #include - #include - #else - #if defined(_WIN32) - #include - #include - #else - #include - #endif - #include - #include - #define OPENSSL_NO_TLSEXT - #endif /* not USE_OLD_CYASSL */ -#else /* WOLFSSL */ - #if defined(LWS_WITH_ESP32) - #define OPENSSL_NO_TLSEXT - #if !defined(LWS_AMAZON_RTOS) - /* AMAZON RTOS has its own setting via MTK_MBEDTLS_CONFIG_FILE */ - #undef MBEDTLS_CONFIG_FILE - #define MBEDTLS_CONFIG_FILE - #endif - #include - #include - #include - #include - #include "tls/mbedtls/wrapper/include/openssl/ssl.h" /* wrapper !!!! */ - #else /* not esp32 */ - #if defined(LWS_WITH_MBEDTLS) - #include - #include - #include - #include - #include - #include - #include - #include "tls/mbedtls/wrapper/include/openssl/ssl.h" /* wrapper !!!! */ - #else - #include - #include - #include - #include - #include - #include - #include - #include - #ifdef LWS_HAVE_OPENSSL_ECDH_H - #include - #endif - #if !defined(LWS_HAVE_EVP_MD_CTX_free) - #define EVP_MD_CTX_free EVP_MD_CTX_destroy - #endif - #include - #endif /* not mbedtls */ - #if defined(OPENSSL_VERSION_NUMBER) - #if (OPENSSL_VERSION_NUMBER < 0x0009080afL) -/* - * later openssl defines this to negate the presence of tlsext... but it was - * only introduced at 0.9.8j. Earlier versions don't know it exists so don't - * define it... making it look like the feature exists... - */ - #define OPENSSL_NO_TLSEXT - #endif - #endif - #endif /* not ESP32 */ -#endif /* not USE_WOLFSSL */ - -#endif /* LWS_WITH_TLS */ - -enum lws_tls_extant { - LWS_TLS_EXTANT_NO, - LWS_TLS_EXTANT_YES, - LWS_TLS_EXTANT_ALTERNATIVE -}; - - -#if defined(LWS_WITH_TLS) - -typedef SSL lws_tls_conn; -typedef SSL_CTX lws_tls_ctx; -typedef BIO lws_tls_bio; -typedef X509 lws_tls_x509; - -#if defined(LWS_WITH_NETWORK) -#include "tls/private-network.h" -#endif - -LWS_EXTERN int -lws_context_init_ssl_library(const struct lws_context_creation_info *info); -LWS_EXTERN void -lws_context_deinit_ssl_library(struct lws_context *context); -#define LWS_SSL_ENABLED(vh) (vh && vh->tls.use_ssl) - -extern const struct lws_tls_ops tls_ops_openssl, tls_ops_mbedtls; - -struct lws_ec_valid_curves { - int id; - const char *jwa_name; /* list terminates with NULL jwa_name */ -}; - -LWS_EXTERN enum lws_tls_extant -lws_tls_use_any_upgrade_check_extant(const char *name); -LWS_EXTERN int openssl_websocket_private_data_index; - - -LWS_EXTERN void -lws_tls_err_describe_clear(void); - -LWS_EXTERN int -lws_tls_openssl_cert_info(X509 *x509, enum lws_tls_cert_info type, - union lws_tls_cert_info_results *buf, size_t len); -LWS_EXTERN int -lws_tls_check_all_cert_lifetimes(struct lws_context *context); - -LWS_EXTERN int -lws_tls_alloc_pem_to_der_file(struct lws_context *context, const char *filename, - const char *inbuf, lws_filepos_t inlen, - uint8_t **buf, lws_filepos_t *amount); -LWS_EXTERN char * -lws_ssl_get_error_string(int status, int ret, char *buf, size_t len); - -int -lws_gencrypto_bits_to_bytes(int bits); - -void -lws_gencrypto_destroy_elements(struct lws_gencrypto_keyelem *el, int m); - -/* genec */ - -struct lws_gencrypto_keyelem; -struct lws_ec_curves; - -LWS_EXTERN const struct lws_ec_curves lws_ec_curves[4]; -const struct lws_ec_curves * -lws_genec_curve(const struct lws_ec_curves *table, const char *name); -LWS_VISIBLE void -lws_genec_destroy_elements(struct lws_gencrypto_keyelem *el); -int -lws_gencrypto_mbedtls_rngf(void *context, unsigned char *buf, size_t len); - -int -lws_genec_confirm_curve_allowed_by_tls_id(const char *allowed, int id, - struct lws_jwk *jwk); - -#endif -#endif diff -Nru libwebsockets-3.2.1/lib/tls/private-lib-tls.h libwebsockets-4.1.6/lib/tls/private-lib-tls.h --- libwebsockets-3.2.1/lib/tls/private-lib-tls.h 1970-01-01 00:00:00.000000000 +0000 +++ libwebsockets-4.1.6/lib/tls/private-lib-tls.h 2020-12-01 17:40:26.000000000 +0000 @@ -0,0 +1,201 @@ + /* + * libwebsockets - small server side websockets and web server implementation + * + * Copyright (C) 2010 - 2019 Andy Green + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to + * deal in the Software without restriction, including without limitation the + * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or + * sell copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS + * IN THE SOFTWARE. + * + * This is included from private-lib-core.h if LWS_WITH_TLS + */ + +#if !defined(__LWS_TLS_PRIVATE_H__) +#define __LWS_TLS_PRIVATE_H__ + + +#if defined(LWS_WITH_TLS) + +#if defined(USE_WOLFSSL) + #if defined(USE_OLD_CYASSL) + #if defined(_WIN32) + #include + #include + #else + #include + #endif + #include + #include + #else + #if defined(_WIN32) + #include + #include + #else + #include + #endif + #include + #include + #define OPENSSL_NO_TLSEXT + #endif /* not USE_OLD_CYASSL */ +#else /* WOLFSSL */ + #if defined(LWS_PLAT_FREERTOS) + #define OPENSSL_NO_TLSEXT + #if !defined(LWS_AMAZON_RTOS) + /* AMAZON RTOS has its own setting via MTK_MBEDTLS_CONFIG_FILE */ + #undef MBEDTLS_CONFIG_FILE + #define MBEDTLS_CONFIG_FILE + #endif + #include + #include + #include + #include + #include "ssl.h" /* wrapper !!!! */ + #else /* not esp32 */ + #if defined(LWS_WITH_MBEDTLS) + #include + #include + #include + #include + #include + #include + #include + #if defined(LWS_AMAZON_LINUX) + #include "ssl.h" /* wrapper !!!! */ + #else + #include "openssl/ssl.h" /* wrapper !!!! */ + #endif + #else + #include + #include + #include + #include + #include + #include + #include + #include + #ifdef LWS_HAVE_OPENSSL_ECDH_H + #include + #endif + #if !defined(LWS_HAVE_EVP_MD_CTX_free) && !defined(USE_WOLFSSL) + #define EVP_MD_CTX_free EVP_MD_CTX_destroy + #endif + #include + #endif /* not mbedtls */ + #if defined(OPENSSL_VERSION_NUMBER) + #if (OPENSSL_VERSION_NUMBER < 0x0009080afL) +/* + * later openssl defines this to negate the presence of tlsext... but it was + * only introduced at 0.9.8j. Earlier versions don't know it exists so don't + * define it... making it look like the feature exists... + */ + #define OPENSSL_NO_TLSEXT + #endif + #endif + #endif /* not ESP32 */ +#endif /* not USE_WOLFSSL */ + +#endif /* LWS_WITH_TLS */ + +enum lws_tls_extant { + LWS_TLS_EXTANT_NO, + LWS_TLS_EXTANT_YES, + LWS_TLS_EXTANT_ALTERNATIVE +}; + + +#if defined(LWS_WITH_TLS) + +int +lws_tls_restrict_borrow(struct lws_context *context); + +void +lws_tls_restrict_return(struct lws_context *context); + +typedef SSL lws_tls_conn; +typedef SSL_CTX lws_tls_ctx; +typedef BIO lws_tls_bio; +typedef X509 lws_tls_x509; + +#if defined(LWS_WITH_NETWORK) +#include "private-network.h" +#endif + +LWS_EXTERN int +lws_context_init_ssl_library(const struct lws_context_creation_info *info); +LWS_EXTERN void +lws_context_deinit_ssl_library(struct lws_context *context); +#define LWS_SSL_ENABLED(vh) (vh && vh->tls.use_ssl) + +extern const struct lws_tls_ops tls_ops_openssl, tls_ops_mbedtls; + +struct lws_ec_valid_curves { + int id; + const char *jwa_name; /* list terminates with NULL jwa_name */ +}; + +LWS_EXTERN enum lws_tls_extant +lws_tls_use_any_upgrade_check_extant(const char *name); +LWS_EXTERN int openssl_websocket_private_data_index; + + +LWS_EXTERN void +lws_tls_err_describe_clear(void); + +LWS_EXTERN int +lws_tls_openssl_cert_info(X509 *x509, enum lws_tls_cert_info type, + union lws_tls_cert_info_results *buf, size_t len); +LWS_EXTERN int +lws_tls_check_all_cert_lifetimes(struct lws_context *context); + +LWS_EXTERN int +lws_tls_alloc_pem_to_der_file(struct lws_context *context, const char *filename, + const char *inbuf, lws_filepos_t inlen, + uint8_t **buf, lws_filepos_t *amount); +LWS_EXTERN char * +lws_ssl_get_error_string(int status, int ret, char *buf, size_t len); + +int +lws_gencrypto_bits_to_bytes(int bits); + +void +lws_gencrypto_destroy_elements(struct lws_gencrypto_keyelem *el, int m); + +/* genec */ + +struct lws_gencrypto_keyelem; +struct lws_ec_curves; + +LWS_EXTERN const struct lws_ec_curves lws_ec_curves[4]; +const struct lws_ec_curves * +lws_genec_curve(const struct lws_ec_curves *table, const char *name); +LWS_VISIBLE void +lws_genec_destroy_elements(struct lws_gencrypto_keyelem *el); +int +lws_gencrypto_mbedtls_rngf(void *context, unsigned char *buf, size_t len); + +int +lws_genec_confirm_curve_allowed_by_tls_id(const char *allowed, int id, + struct lws_jwk *jwk); + + +#else /* ! WITH_TLS */ + +#define lws_tls_restrict_borrow(xxx) (0) +#define lws_tls_restrict_return(xxx) + +#endif +#endif diff -Nru libwebsockets-3.2.1/lib/tls/private-network.h libwebsockets-4.1.6/lib/tls/private-network.h --- libwebsockets-3.2.1/lib/tls/private-network.h 2019-12-18 14:45:31.000000000 +0000 +++ libwebsockets-4.1.6/lib/tls/private-network.h 2020-12-01 17:40:26.000000000 +0000 @@ -1,24 +1,27 @@ -/* + /* * libwebsockets - small server side websockets and web server implementation * * Copyright (C) 2010 - 2019 Andy Green * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation: - * version 2.1 of the License. + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to + * deal in the Software without restriction, including without limitation the + * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or + * sell copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: * - * This library is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. * - * You should have received a copy of the GNU Lesser General Public - * License along with this library; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, - * MA 02110-1301 USA + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS + * IN THE SOFTWARE. * - * This is included from core/private.h if LWS_WITH_TLS + * This is included from private-lib-core.h if LWS_WITH_TLS */ struct lws_context_per_thread; @@ -84,7 +87,8 @@ LWS_EXTERN int LWS_WARN_UNUSED_RESULT lws_ssl_pending(struct lws *wsi); LWS_EXTERN int LWS_WARN_UNUSED_RESULT -lws_server_socket_service_ssl(struct lws *new_wsi, lws_sockfd_type accept_fd); +lws_server_socket_service_ssl(struct lws *new_wsi, lws_sockfd_type accept_fd, + char is_pollin); LWS_EXTERN int lws_ssl_close(struct lws *wsi); LWS_EXTERN void @@ -98,7 +102,7 @@ LWS_EXTERN int lws_ssl_client_bio_create(struct lws *wsi); LWS_EXTERN int -lws_ssl_client_connect1(struct lws *wsi); +lws_ssl_client_connect1(struct lws *wsi, char *errbuf, int len); LWS_EXTERN int lws_ssl_client_connect2(struct lws *wsi, char *errbuf, int len); LWS_EXTERN int @@ -118,7 +122,7 @@ LWS_EXTERN enum lws_tls_extant lws_tls_generic_cert_checks(struct lws_vhost *vhost, const char *cert, const char *private_key); -#if !defined(LWS_NO_SERVER) +#if defined(LWS_WITH_SERVER) LWS_EXTERN int lws_context_init_server_ssl(const struct lws_context_creation_info *info, struct lws_vhost *vhost); @@ -154,7 +158,7 @@ __lws_tls_shutdown(struct lws *wsi); LWS_EXTERN enum lws_ssl_capable_status -lws_tls_client_connect(struct lws *wsi); +lws_tls_client_connect(struct lws *wsi, char *errbuf, int len); LWS_EXTERN int lws_tls_client_confirm_peer_cert(struct lws *wsi, char *ebuf, int ebuf_len); LWS_EXTERN int @@ -167,7 +171,10 @@ const char *cert_filepath, const void *cert_mem, unsigned int cert_mem_len, - const char *private_key_filepath); + const char *private_key_filepath, + const void *key_mem, + unsigned int key_mem_len); + LWS_EXTERN lws_tls_ctx * lws_tls_ctx_from_wsi(struct lws *wsi); @@ -183,8 +190,3 @@ int lws_tls_fake_POLLIN_for_buffered(struct lws_context_per_thread *pt); - - - - - diff -Nru libwebsockets-3.2.1/lib/tls/tls.c libwebsockets-4.1.6/lib/tls/tls.c --- libwebsockets-3.2.1/lib/tls/tls.c 2019-12-18 14:45:31.000000000 +0000 +++ libwebsockets-4.1.6/lib/tls/tls.c 2020-12-01 17:40:26.000000000 +0000 @@ -3,27 +3,146 @@ * * Copyright (C) 2010 - 2019 Andy Green * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation: - * version 2.1 of the License. - * - * This library is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with this library; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, - * MA 02110-1301 USA + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to + * deal in the Software without restriction, including without limitation the + * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or + * sell copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS + * IN THE SOFTWARE. */ -#include "core/private.h" -#include "tls/private.h" +#include "private-lib-core.h" +#include "private-lib-tls.h" + +#if defined(LWS_WITH_NETWORK) +#if defined(LWS_WITH_MBEDTLS) || (defined(OPENSSL_VERSION_NUMBER) && \ + OPENSSL_VERSION_NUMBER >= 0x10002000L) +static int +alpn_cb(SSL *s, const unsigned char **out, unsigned char *outlen, + const unsigned char *in, unsigned int inlen, void *arg) +{ +#if !defined(LWS_WITH_MBEDTLS) + struct alpn_ctx *alpn_ctx = (struct alpn_ctx *)arg; + + if (SSL_select_next_proto((unsigned char **)out, outlen, alpn_ctx->data, + alpn_ctx->len, in, inlen) != + OPENSSL_NPN_NEGOTIATED) + return SSL_TLSEXT_ERR_NOACK; +#endif + + return SSL_TLSEXT_ERR_OK; +} +#endif + +int +lws_tls_restrict_borrow(struct lws_context *context) +{ + if (!context->simultaneous_ssl_restriction) + return 0; + + if (context->simultaneous_ssl >= context->simultaneous_ssl_restriction) { + lwsl_notice("%s: tls connection limit %d\n", __func__, + context->simultaneous_ssl); + return 1; + } + + if (++context->simultaneous_ssl == context->simultaneous_ssl_restriction) + /* that was the last allowed SSL connection */ + lws_gate_accepts(context, 0); + + lwsl_info("%s: %d -> %d\n", __func__, + context->simultaneous_ssl - 1, + context->simultaneous_ssl); + + return 0; +} + +void +lws_tls_restrict_return(struct lws_context *context) +{ + if (context->simultaneous_ssl_restriction) { + if (context->simultaneous_ssl-- == + context->simultaneous_ssl_restriction) + /* we made space and can do an accept */ + lws_gate_accepts(context, 1); + lwsl_info("%s: %d -> %d\n", __func__, + context->simultaneous_ssl + 1, + context->simultaneous_ssl); + } +} + +void +lws_context_init_alpn(struct lws_vhost *vhost) +{ +#if defined(LWS_WITH_MBEDTLS) || (defined(OPENSSL_VERSION_NUMBER) && \ + OPENSSL_VERSION_NUMBER >= 0x10002000L) + const char *alpn_comma = vhost->context->tls.alpn_default; + + if (vhost->tls.alpn) + alpn_comma = vhost->tls.alpn; + + lwsl_info(" Server '%s' advertising ALPN: %s\n", + vhost->name, alpn_comma); + vhost->tls.alpn_ctx.len = lws_alpn_comma_to_openssl(alpn_comma, + vhost->tls.alpn_ctx.data, + sizeof(vhost->tls.alpn_ctx.data) - 1); + + SSL_CTX_set_alpn_select_cb(vhost->tls.ssl_ctx, alpn_cb, + &vhost->tls.alpn_ctx); +#else + lwsl_err( + " HTTP2 / ALPN configured but not supported by OpenSSL 0x%lx\n", + OPENSSL_VERSION_NUMBER); +#endif // OPENSSL_VERSION_NUMBER >= 0x10002000L +} + +int +lws_tls_server_conn_alpn(struct lws *wsi) +{ +#if defined(LWS_WITH_MBEDTLS) || (defined(OPENSSL_VERSION_NUMBER) && \ + OPENSSL_VERSION_NUMBER >= 0x10002000L) + const unsigned char *name = NULL; + char cstr[10]; + unsigned len; + + if (!wsi->tls.ssl) + return 0; + + SSL_get0_alpn_selected(wsi->tls.ssl, &name, &len); + if (!len) { + lwsl_info("no ALPN upgrade\n"); + return 0; + } + + if (len > sizeof(cstr) - 1) + len = sizeof(cstr) - 1; + + memcpy(cstr, name, len); + cstr[len] = '\0'; + + lwsl_info("negotiated '%s' using ALPN\n", cstr); + wsi->tls.use_ssl |= LCCSCF_USE_SSL; + + return lws_role_call_alpn_negotiated(wsi, (const char *)cstr); +#endif // OPENSSL_VERSION_NUMBER >= 0x10002000L + + return 0; +} +#endif #if !defined(LWS_PLAT_OPTEE) && !defined(OPTEE_DEV_KIT) -#if defined(LWS_WITH_ESP32) && !defined(LWS_AMAZON_RTOS) +#if defined(LWS_PLAT_FREERTOS) && !defined(LWS_AMAZON_RTOS) int alloc_file(struct lws_context *context, const char *filename, uint8_t **buf, lws_filepos_t *amount) { @@ -147,11 +266,11 @@ /* take it as being already DER */ - pem = lws_malloc(inlen, "alloc_der"); + pem = lws_malloc((size_t)inlen, "alloc_der"); if (!pem) return 1; - memcpy(pem, inbuf, inlen); + memcpy(pem, inbuf, (size_t)inlen); *buf = pem; *amount = inlen; @@ -163,7 +282,7 @@ if (!filename) { /* we don't know if it's in const memory... alloc the output */ - pem = lws_malloc((inlen * 3) / 4, "alloc_der"); + pem = lws_malloc(((size_t)inlen * 3) / 4, "alloc_der"); if (!pem) { lwsl_err("a\n"); return 1; @@ -226,7 +345,7 @@ #endif -#if !defined(LWS_WITH_ESP32) && !defined(LWS_PLAT_OPTEE) && !defined(OPTEE_DEV_KIT) +#if !defined(LWS_PLAT_FREERTOS) && !defined(LWS_PLAT_OPTEE) && !defined(OPTEE_DEV_KIT) static int @@ -275,15 +394,15 @@ * 4) LWS_TLS_EXTANT_YES: The certs are present with the correct name and we * have the rights to read them. */ -#if !defined(LWS_AMAZON_RTOS) + enum lws_tls_extant lws_tls_use_any_upgrade_check_extant(const char *name) { -#if !defined(LWS_PLAT_OPTEE) +#if !defined(LWS_PLAT_OPTEE) && !defined(LWS_AMAZON_RTOS) int n; -#if !defined(LWS_WITH_ESP32) +#if !defined(LWS_PLAT_FREERTOS) char buf[256]; lws_snprintf(buf, sizeof(buf) - 1, "%s.upd", name); @@ -332,5 +451,3 @@ #endif return LWS_TLS_EXTANT_YES; } -#endif - diff -Nru libwebsockets-3.2.1/lib/tls/tls-client.c libwebsockets-4.1.6/lib/tls/tls-client.c --- libwebsockets-3.2.1/lib/tls/tls-client.c 2019-12-18 14:45:31.000000000 +0000 +++ libwebsockets-4.1.6/lib/tls/tls-client.c 2020-12-01 17:40:26.000000000 +0000 @@ -1,36 +1,35 @@ /* - * libwebsockets - client-related ssl code independent of backend + * libwebsockets - small server side websockets and web server implementation * - * Copyright (C) 2010-2018 Andy Green + * Copyright (C) 2010 - 2019 Andy Green * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation: - * version 2.1 of the License. + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to + * deal in the Software without restriction, including without limitation the + * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or + * sell copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: * - * This library is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. * - * You should have received a copy of the GNU Lesser General Public - * License along with this library; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, - * MA 02110-1301 USA + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS + * IN THE SOFTWARE. */ -#include "core/private.h" +#include "private-lib-core.h" int -lws_ssl_client_connect1(struct lws *wsi) +lws_ssl_client_connect1(struct lws *wsi, char *errbuf, int len) { - struct lws_context *context = wsi->context; - int n = 0; - - lws_latency_pre(context, wsi); - n = lws_tls_client_connect(wsi); - lws_latency(context, wsi, "SSL_connect hs", n, n > 0); + int n; + n = lws_tls_client_connect(wsi, errbuf, len); switch (n) { case LWS_SSL_CAPABLE_ERROR: return -1; @@ -51,19 +50,15 @@ int lws_ssl_client_connect2(struct lws *wsi, char *errbuf, int len) { - int n = 0; + int n; if (lwsi_state(wsi) == LRS_WAITING_SSL) { - lws_latency_pre(wsi->context, wsi); - - n = lws_tls_client_connect(wsi); + n = lws_tls_client_connect(wsi, errbuf, len); lwsl_debug("%s: SSL_connect says %d\n", __func__, n); - lws_latency(wsi->context, wsi, - "SSL_connect LRS_WAITING_SSL", n, n > 0); switch (n) { case LWS_SSL_CAPABLE_ERROR: - lws_snprintf(errbuf, len, "client connect failed"); + // lws_snprintf(errbuf, len, "client connect failed"); return -1; case LWS_SSL_CAPABLE_DONE: break; /* connected */ @@ -92,7 +87,9 @@ const char *cert_filepath = info->ssl_cert_filepath; const char *ca_filepath = info->ssl_ca_filepath; const char *cipher_list = info->ssl_cipher_list; - struct lws wsi; + lws_fakewsi_def_plwsa(&vhost->context->pt[0]); + + lws_fakewsi_prep_plwsa_ctx(vhost->context); if (vhost->options & LWS_SERVER_OPTION_ADOPT_APPLY_LISTEN_ACCEPT_CONFIG) return 0; @@ -123,6 +120,7 @@ if (vhost->tls.ssl_client_ctx) return 0; +#if !defined(LWS_WITH_MBEDTLS) if (info->provided_client_ssl_ctx) { /* use the provided OpenSSL context if given one */ vhost->tls.ssl_client_ctx = info->provided_client_ssl_ctx; @@ -131,6 +129,7 @@ return 0; } +#endif if (lws_tls_client_create_vhost_context(vhost, info, cipher_list, ca_filepath, @@ -139,7 +138,10 @@ cert_filepath, info->client_ssl_cert_mem, info->client_ssl_cert_mem_len, - private_key_filepath)) + private_key_filepath, + info->client_ssl_key_mem, + info->client_ssl_key_mem_len + )) return 1; lwsl_info("created client ssl context for %s\n", vhost->name); @@ -148,13 +150,13 @@ * give him a fake wsi with context set, so he can use * lws_get_context() in the callback */ - memset(&wsi, 0, sizeof(wsi)); - wsi.vhost = vhost; /* not a real bound wsi */ - wsi.context = vhost->context; - vhost->protocols[0].callback(&wsi, + plwsa->vhost = vhost; /* not a real bound wsi */ + + vhost->protocols[0].callback((struct lws *)plwsa, LWS_CALLBACK_OPENSSL_LOAD_EXTRA_CLIENT_VERIFY_CERTS, vhost->tls.ssl_client_ctx, NULL, 0); return 0; } + diff -Nru libwebsockets-3.2.1/lib/tls/tls-network.c libwebsockets-4.1.6/lib/tls/tls-network.c --- libwebsockets-3.2.1/lib/tls/tls-network.c 2019-12-18 14:45:31.000000000 +0000 +++ libwebsockets-4.1.6/lib/tls/tls-network.c 2020-12-01 17:40:26.000000000 +0000 @@ -3,23 +3,26 @@ * * Copyright (C) 2010 - 2019 Andy Green * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation: - * version 2.1 of the License. + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to + * deal in the Software without restriction, including without limitation the + * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or + * sell copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: * - * This library is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. * - * You should have received a copy of the GNU Lesser General Public - * License along with this library; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, - * MA 02110-1301 USA + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS + * IN THE SOFTWARE. */ -#include "core/private.h" +#include "private-lib-core.h" /* * fakes POLLIN on all tls guys with buffered rx @@ -37,9 +40,12 @@ struct lws *wsi = lws_container_of(p, struct lws, tls.dll_pending_tls); - pt->fds[wsi->position_in_fds_table].revents |= - pt->fds[wsi->position_in_fds_table].events & LWS_POLLIN; - ret |= pt->fds[wsi->position_in_fds_table].revents & LWS_POLLIN; + if (wsi->position_in_fds_table >= 0) { + + pt->fds[wsi->position_in_fds_table].revents |= + pt->fds[wsi->position_in_fds_table].events & LWS_POLLIN; + ret |= pt->fds[wsi->position_in_fds_table].revents & LWS_POLLIN; + } } lws_end_foreach_dll_safe(p, p1); @@ -55,14 +61,14 @@ void lws_ssl_remove_wsi_from_buffered_list(struct lws *wsi) { - struct lws_context_per_thread *pt = &wsi->context->pt[(int)wsi->tsi]; + struct lws_context_per_thread *pt = &wsi->a.context->pt[(int)wsi->tsi]; lws_pt_lock(pt, __func__); __lws_ssl_remove_wsi_from_buffered_list(wsi); lws_pt_unlock(pt); } - +#if defined(LWS_WITH_SERVER) int lws_tls_check_cert_lifetime(struct lws_vhost *v) { @@ -110,7 +116,6 @@ return 0; } - /* * LWS_TLS_EXTANT_NO : skip adding the cert * LWS_TLS_EXTANT_YES : use the cert and private key paths normally @@ -158,12 +163,11 @@ return LWS_TLS_EXTANT_YES; } -#if !defined(LWS_NO_SERVER) /* * update the cert for every vhost using the given path */ -LWS_VISIBLE int +int lws_tls_cert_updated(struct lws_context *context, const char *certpath, const char *keypath, const char *mem_cert, size_t len_mem_cert, @@ -171,10 +175,10 @@ { struct lws wsi; - wsi.context = context; + wsi.a.context = context; lws_start_foreach_ll(struct lws_vhost *, v, context->vhost_list) { - wsi.vhost = v; /* not a real bound wsi */ + wsi.a.vhost = v; /* not a real bound wsi */ if (v->tls.alloc_cert_path && v->tls.key_path && !strcmp(v->tls.alloc_cert_path, certpath) && !strcmp(v->tls.key_path, keypath)) { @@ -222,7 +226,10 @@ { uint8_t *oos = os, *plen = NULL; - while (*comma && len > 1) { + if (!comma) + return 0; + + while (*comma && len > 2) { if (!plen && *comma == ' ') { comma++; continue; @@ -245,6 +252,8 @@ if (plen) *plen = lws_ptr_diff(os, plen + 1); + *os = 0; + return lws_ptr_diff(os, oos); } diff -Nru libwebsockets-3.2.1/lib/tls/tls-server.c libwebsockets-4.1.6/lib/tls/tls-server.c --- libwebsockets-3.2.1/lib/tls/tls-server.c 2019-12-18 14:45:31.000000000 +0000 +++ libwebsockets-4.1.6/lib/tls/tls-server.c 2020-12-01 17:40:26.000000000 +0000 @@ -1,104 +1,30 @@ /* * libwebsockets - small server side websockets and web server implementation * - * Copyright (C) 2010-2018 Andy Green + * Copyright (C) 2010 - 2019 Andy Green * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation: - * version 2.1 of the License. + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to + * deal in the Software without restriction, including without limitation the + * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or + * sell copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: * - * This library is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. * - * You should have received a copy of the GNU Lesser General Public - * License along with this library; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, - * MA 02110-1301 USA + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS + * IN THE SOFTWARE. */ -#include "core/private.h" +#include "private-lib-core.h" -#if defined(LWS_WITH_MBEDTLS) || (defined(OPENSSL_VERSION_NUMBER) && \ - OPENSSL_VERSION_NUMBER >= 0x10002000L) -static int -alpn_cb(SSL *s, const unsigned char **out, unsigned char *outlen, - const unsigned char *in, unsigned int inlen, void *arg) -{ -#if !defined(LWS_WITH_MBEDTLS) - struct alpn_ctx *alpn_ctx = (struct alpn_ctx *)arg; - - if (SSL_select_next_proto((unsigned char **)out, outlen, alpn_ctx->data, - alpn_ctx->len, in, inlen) != - OPENSSL_NPN_NEGOTIATED) - return SSL_TLSEXT_ERR_NOACK; -#endif - - return SSL_TLSEXT_ERR_OK; -} -#endif - -void -lws_context_init_alpn(struct lws_vhost *vhost) -{ -#if defined(LWS_WITH_MBEDTLS) || (defined(OPENSSL_VERSION_NUMBER) && \ - OPENSSL_VERSION_NUMBER >= 0x10002000L) - const char *alpn_comma = vhost->context->tls.alpn_default; - - if (vhost->tls.alpn) - alpn_comma = vhost->tls.alpn; - - lwsl_info(" Server '%s' advertising ALPN: %s\n", - vhost->name, alpn_comma); - vhost->tls.alpn_ctx.len = lws_alpn_comma_to_openssl(alpn_comma, - vhost->tls.alpn_ctx.data, - sizeof(vhost->tls.alpn_ctx.data) - 1); - - SSL_CTX_set_alpn_select_cb(vhost->tls.ssl_ctx, alpn_cb, - &vhost->tls.alpn_ctx); -#else - lwsl_err( - " HTTP2 / ALPN configured but not supported by OpenSSL 0x%lx\n", - OPENSSL_VERSION_NUMBER); -#endif // OPENSSL_VERSION_NUMBER >= 0x10002000L -} - -int -lws_tls_server_conn_alpn(struct lws *wsi) -{ -#if defined(LWS_WITH_MBEDTLS) || (defined(OPENSSL_VERSION_NUMBER) && \ - OPENSSL_VERSION_NUMBER >= 0x10002000L) - const unsigned char *name = NULL; - char cstr[10]; - unsigned len; - - if (!wsi->tls.ssl) - return 0; - - SSL_get0_alpn_selected(wsi->tls.ssl, &name, &len); - if (!len) { - lwsl_info("no ALPN upgrade\n"); - return 0; - } - - if (len > sizeof(cstr) - 1) - len = sizeof(cstr) - 1; - - memcpy(cstr, name, len); - cstr[len] = '\0'; - - lwsl_info("negotiated '%s' using ALPN\n", cstr); - wsi->tls.use_ssl |= LCCSCF_USE_SSL; - - return lws_role_call_alpn_negotiated(wsi, (const char *)cstr); -#endif // OPENSSL_VERSION_NUMBER >= 0x10002000L - - return 0; -} - -#if !defined(LWS_NO_SERVER) +#if defined(LWS_WITH_SERVER) static void lws_sul_tls_cb(lws_sorted_usec_list_t *sul) @@ -108,16 +34,19 @@ lws_tls_check_all_cert_lifetimes(pt->context); - __lws_sul_insert(&pt->pt_sul_owner, &pt->sul_tls, - (lws_usec_t)24 * 3600 * LWS_US_PER_SEC); + __lws_sul_insert_us(&pt->pt_sul_owner[LWSSULLI_MISS_IF_SUSPENDED], + &pt->sul_tls, + (lws_usec_t)24 * 3600 * LWS_US_PER_SEC); } -LWS_VISIBLE int +int lws_context_init_server_ssl(const struct lws_context_creation_info *info, struct lws_vhost *vhost) { struct lws_context *context = vhost->context; - struct lws wsi; + lws_fakewsi_def_plwsa(&vhost->context->pt[0]); + + lws_fakewsi_prep_plwsa_ctx(vhost->context); if (!lws_check_opt(info->options, LWS_SERVER_OPTION_DO_SSL_GLOBAL_INIT)) { @@ -146,19 +75,15 @@ lwsl_notice(" SSL ciphers: '%s'\n", info->ssl_cipher_list); - if (vhost->tls.use_ssl) - lwsl_notice(" Using SSL mode\n"); - else - lwsl_notice(" Using non-SSL mode\n"); + lwsl_notice(" Vhost '%s' using %sTLS mode\n", + vhost->name, vhost->tls.use_ssl ? "" : "non-"); } /* * give him a fake wsi with context + vhost set, so he can use * lws_get_context() in the callback */ - memset(&wsi, 0, sizeof(wsi)); - wsi.vhost = vhost; /* not a real bound wsi */ - wsi.context = context; + plwsa->vhost = vhost; /* not a real bound wsi */ /* * as a server, if we are requiring clients to identify themselves @@ -174,12 +99,12 @@ * allowing it to verify incoming client certs */ if (vhost->tls.use_ssl) { - if (lws_tls_server_vhost_backend_init(info, vhost, &wsi)) + if (lws_tls_server_vhost_backend_init(info, vhost, (struct lws *)plwsa)) return -1; lws_tls_server_client_cert_verify_config(vhost); - if (vhost->protocols[0].callback(&wsi, + if (vhost->protocols[0].callback((struct lws *)plwsa, LWS_CALLBACK_OPENSSL_LOAD_EXTRA_SERVER_VERIFY_CERTS, vhost->tls.ssl_ctx, vhost, 0)) return -1; @@ -191,25 +116,23 @@ /* check certs once a day */ context->pt[0].sul_tls.cb = lws_sul_tls_cb; - __lws_sul_insert(&context->pt[0].pt_sul_owner, &context->pt[0].sul_tls, - (lws_usec_t)24 * 3600 * LWS_US_PER_SEC); + __lws_sul_insert_us(&context->pt[0].pt_sul_owner[LWSSULLI_MISS_IF_SUSPENDED], + &context->pt[0].sul_tls, + (lws_usec_t)24 * 3600 * LWS_US_PER_SEC); return 0; } #endif -LWS_VISIBLE int -lws_server_socket_service_ssl(struct lws *wsi, lws_sockfd_type accept_fd) +int +lws_server_socket_service_ssl(struct lws *wsi, lws_sockfd_type accept_fd, char from_pollin) { - struct lws_context *context = wsi->context; + struct lws_context *context = wsi->a.context; struct lws_context_per_thread *pt = &context->pt[(int)wsi->tsi]; struct lws_vhost *vh; - char buf[256]; int n; - (void)buf; - - if (!LWS_SSL_ENABLED(wsi->vhost)) + if (!LWS_SSL_ENABLED(wsi->a.vhost)) return 0; switch (lwsi_state(wsi)) { @@ -219,25 +142,20 @@ lwsl_err("%s: leaking ssl\n", __func__); if (accept_fd == LWS_SOCK_INVALID) assert(0); - if (context->simultaneous_ssl_restriction && - context->simultaneous_ssl >= - context->simultaneous_ssl_restriction) { - lwsl_notice("unable to deal with SSL connection\n"); + + if (lws_tls_restrict_borrow(context)) { + lwsl_err("%s: failed on ssl restriction\n", __func__); return 1; } if (lws_tls_server_new_nonblocking(wsi, accept_fd)) { + lwsl_err("%s: failed on lws_tls_server_new_nonblocking\n", __func__); if (accept_fd != LWS_SOCK_INVALID) compatible_close(accept_fd); + lws_tls_restrict_return(context); goto fail; } - if (context->simultaneous_ssl_restriction && - ++context->simultaneous_ssl == - context->simultaneous_ssl_restriction) - /* that was the last allowed SSL connection */ - lws_gate_accepts(context, 0); - #if defined(LWS_WITH_STATS) context->updated = 1; #endif @@ -269,13 +187,14 @@ goto fail; } - lws_latency_pre(context, wsi); - - if (wsi->vhost->tls.allow_non_ssl_on_ssl_port) { + if (wsi->a.vhost->tls.allow_non_ssl_on_ssl_port && !wsi->skip_fallback) { + /* + * We came here by POLLIN, so there is supposed to be + * something to read... + */ n = recv(wsi->desc.sockfd, (char *)pt->serv_buf, context->pt_serv_buf_size, MSG_PEEK); - /* * We have LWS_SERVER_OPTION_ALLOW_NON_SSL_ON_SSL_PORT.. * this just means don't hang up on him because of no @@ -321,7 +240,7 @@ */ wsi->tls.ssl = NULL; - if (lws_check_opt(wsi->vhost->options, + if (lws_check_opt(wsi->a.vhost->options, LWS_SERVER_OPTION_REDIRECT_HTTP_TO_HTTPS)) { lwsl_info("%s: redirecting from http " "to https\n", __func__); @@ -329,7 +248,7 @@ goto notls_accepted; } - if (lws_check_opt(wsi->vhost->options, + if (lws_check_opt(wsi->a.vhost->options, LWS_SERVER_OPTION_ALLOW_HTTP_ON_HTTPS_LISTENER)) { lwsl_info("%s: allowing unencrypted " "http service on tls port\n", @@ -337,7 +256,7 @@ goto notls_accepted; } - if (lws_check_opt(wsi->vhost->options, + if (lws_check_opt(wsi->a.vhost->options, LWS_SERVER_OPTION_FALLBACK_TO_APPLY_LISTEN_ACCEPT_CONFIG)) { if (lws_http_to_fallback(wsi, NULL, 0)) goto fail; @@ -348,18 +267,37 @@ lwsl_notice("%s: client did not send a valid " "tls hello (default vhost %s)\n", - __func__, wsi->vhost->name); + __func__, wsi->a.vhost->name); goto fail; } if (!n) { /* - * connection is gone, fail out + * POLLIN but nothing to read is supposed to + * mean the connection is gone, we should + * fail out... + * + */ + lwsl_debug("%s: PEEKed 0 (from_pollin %d)\n", + __func__, from_pollin); + if (!from_pollin) + /* + * If this wasn't actually info from a + * pollin let it go around again until + * either data came or we still get told + * zero length peek AND POLLIN + */ + goto punt; + + /* + * treat as remote closed */ - lwsl_debug("PEEKed 0\n"); + goto fail; } if (n < 0 && (LWS_ERRNO == LWS_EAGAIN || LWS_ERRNO == LWS_EWOULDBLOCK)) { + +punt: /* * well, we get no way to know ssl or not * so go around again waiting for something @@ -367,7 +305,7 @@ * connection. */ if (lws_change_pollfd(wsi, 0, LWS_POLLIN)) { - lwsl_info("%s: change_pollfd failed\n", + lwsl_err("%s: change_pollfd failed\n", __func__); return -1; } @@ -387,16 +325,14 @@ errno = 0; lws_stats_bump(pt, LWSSTATS_C_SSL_ACCEPT_SPIN, 1); n = lws_tls_server_accept(wsi); - lws_latency(context, wsi, - "SSL_accept LRS_SSL_ACK_PENDING\n", n, n == 1); lwsl_info("SSL_accept says %d\n", n); switch (n) { case LWS_SSL_CAPABLE_DONE: break; case LWS_SSL_CAPABLE_ERROR: lws_stats_bump(pt, LWSSTATS_C_SSL_CONNECTIONS_FAILED, 1); - lwsl_info("SSL_accept failed socket %u: %d\n", - wsi->desc.sockfd, n); + lwsl_info("%s: SSL_accept failed socket %u: %d\n", + __func__, wsi->desc.sockfd, n); wsi->socket_is_permanently_unusable = 1; goto fail; @@ -413,6 +349,16 @@ wsi->accept_start_us); wsi->accept_start_us = lws_now_usecs(); #endif +#if defined(LWS_WITH_DETAILED_LATENCY) + if (context->detailed_latency_cb) { + wsi->detlat.type = LDLT_TLS_NEG_SERVER; + wsi->detlat.latencies[LAT_DUR_PROXY_RX_TO_ONWARD_TX] = + lws_now_usecs() - + wsi->detlat.earliest_write_req_pre_write; + wsi->detlat.latencies[LAT_DUR_USERCB] = 0; + lws_det_lat_cb(wsi->a.context, &wsi->detlat); + } +#endif /* adapt our vhost to match the SNI SSL_CTX that was chosen */ vh = context->vhost_list; @@ -431,8 +377,10 @@ context->timeout_secs); lwsi_set_state(wsi, LRS_ESTABLISHED); - if (lws_tls_server_conn_alpn(wsi)) + if (lws_tls_server_conn_alpn(wsi)) { + lwsl_warn("%s: fail on alpn\n", __func__); goto fail; + } lwsl_debug("accepted new SSL conn\n"); break; diff -Nru libwebsockets-3.2.1/libwebsockets.dox libwebsockets-4.1.6/libwebsockets.dox --- libwebsockets-3.2.1/libwebsockets.dox 2019-12-18 14:45:31.000000000 +0000 +++ libwebsockets-4.1.6/libwebsockets.dox 2020-12-01 17:40:26.000000000 +0000 @@ -103,39 +103,62 @@ #--------------------------------------------------------------------------- INPUT = include/libwebsockets.h \ include/libwebsockets/lws-adopt.h \ + include/libwebsockets/lws-async-dns.h \ + include/libwebsockets/lws-bb-i2c.h \ + include/libwebsockets/lws-bb-spi.h \ + include/libwebsockets/lws-button.h \ include/libwebsockets/lws-callbacks.h \ include/libwebsockets/lws-cgi.h \ include/libwebsockets/lws-client.h \ include/libwebsockets/lws-context-vhost.h \ include/libwebsockets/lws-dbus.h \ + include/libwebsockets/lws-detailed-latency.h \ include/libwebsockets/lws-diskcache.h \ + include/libwebsockets/lws-display.h \ + include/libwebsockets/lws-dll2.h \ include/libwebsockets/lws-dsh.h \ include/libwebsockets/lws-esp32.h \ + include/libwebsockets/lws-eventlib-exports.h \ + include/libwebsockets/lws-freertos.h \ include/libwebsockets/lws-fts.h \ include/libwebsockets/lws-genaes.h \ include/libwebsockets/lws-gencrypto.h \ include/libwebsockets/lws-genec.h \ include/libwebsockets/lws-genhash.h \ include/libwebsockets/lws-genrsa.h \ + include/libwebsockets/lws-gpio.h \ include/libwebsockets/lws-http.h \ + include/libwebsockets/lws-i2c.h \ + include/libwebsockets/lws-ili9341-spi.h \ include/libwebsockets/lws-jose.h \ include/libwebsockets/lws-jwe.h \ include/libwebsockets/lws-jwk.h \ include/libwebsockets/lws-jws.h \ + include/libwebsockets/lws-led.h \ include/libwebsockets/lws-lejp.h \ include/libwebsockets/lws-logs.h \ include/libwebsockets/lws-lwsac.h \ include/libwebsockets/lws-misc.h \ + include/libwebsockets/lws-mqtt.h \ + include/libwebsockets/lws-netdev.h \ include/libwebsockets/lws-network-helper.h \ - include/libwebsockets/lws-plugin-generic-sessions.h \ include/libwebsockets/lws-protocols-plugins.h \ include/libwebsockets/lws-purify.h \ + include/libwebsockets/lws-pwm.h \ include/libwebsockets/lws-retry.h \ include/libwebsockets/lws-ring.h \ + include/libwebsockets/lws-secure-streams-client.h \ + include/libwebsockets/lws-secure-streams.h \ + include/libwebsockets/lws-secure-streams-policy.h \ include/libwebsockets/lws-sequencer.h \ include/libwebsockets/lws-service.h \ + include/libwebsockets/lws-settings.h \ include/libwebsockets/lws-sha1-base64.h \ + include/libwebsockets/lws-smd.h \ include/libwebsockets/lws-spa.h \ + include/libwebsockets/lws-spi.h \ + include/libwebsockets/lws-ssd1306-i2c.h \ + include/libwebsockets/lws-state.h \ include/libwebsockets/lws-stats.h \ include/libwebsockets/lws-struct.h \ include/libwebsockets/lws-system.h \ @@ -152,22 +175,25 @@ include/libwebsockets/lws-x509.h \ plugins/ssh-base/include/lws-plugin-ssh.h \ ./READMEs/mainpage.md \ + ./READMEs/README.async-dns.md \ ./READMEs/README.build.md \ ./READMEs/README.ci.md \ ./READMEs/README.coding.md \ ./READMEs/README.content-security-policy.md \ ./READMEs/README.contributing.md \ ./READMEs/README.crypto-apis.md \ + ./READMEs/README.detailed-latency.md \ ./READMEs/README.esp32.md \ ./READMEs/README.generic-sessions.md \ ./READMEs/README.generic-table.md \ + ./READMEs/README.h2-long-poll.md \ ./READMEs/README.http-fallback.md \ ./READMEs/README.lws_dll.md \ ./READMEs/README.lws_sequencer.md \ ./READMEs/README.lws_struct.md \ ./READMEs/README.lws_sul.md \ ./READMEs/README.lwsws.md \ - ./READMEs/README.plugin-sshd-base.md \ + ./READMEs/README-plugin-sshd-base.md \ ./READMEs/README.plugin-acme.md \ ./READMEs/README.porting.md \ ./READMEs/README.problems.md \ diff -Nru libwebsockets-3.2.1/LICENSE libwebsockets-4.1.6/LICENSE --- libwebsockets-3.2.1/LICENSE 2019-12-18 14:45:31.000000000 +0000 +++ libwebsockets-4.1.6/LICENSE 2020-12-01 17:40:26.000000000 +0000 @@ -1,556 +1,56 @@ -Libwebsockets and included programs are provided under the terms of the GNU -Library General Public License (LGPL) 2.1, with the following exceptions: +Libwebsockets and included programs are provided under the terms of the +MIT license shown below, with the exception that some sources are under +a similar permissive license like BSD, or are explicitly CC0 / public +domain to remove any obstacles from basing differently-licensed code on +them. + +Original liberal license retained: + + - lib/misc/sha-1.c - 3-clause BSD license retained, link to original + - win32port/zlib - ZLIB license (see zlib.h) + - lib/tls/mbedtls/wrapper - Apache 2.0 (only built if linked against mbedtls) + - lib/misc/base64-decode.c - already MIT + +Relicensed to MIT: + + - lib/misc/daemonize.c - relicensed from Public Domain to MIT, + link to original Public Domain version + - lib/plat/windows/windows-resolv.c - relicensed from "Beerware v42" to MIT -1) Any reference, whether in these modifications or in the GNU -Library General Public License 2.1, to this License, these terms, the -GNU Lesser Public License, GNU Library General Public License, LGPL, or -any similar reference shall refer to the GNU Library General Public -License 2.1 as modified by these paragraphs 1) through 4). - -2) Static linking of programs with the libwebsockets library does not -constitute a derivative work and does not require the author to provide -source code for the program, use the shared libwebsockets libraries, or -link their program against a user-supplied version of libwebsockets. - -If you link the program to a modified version of libwebsockets, then the -changes to libwebsockets must be provided under the terms of the LGPL in -sections 1, 2, and 4. - -3) You do not have to provide a copy of the libwebsockets license with -programs that are linked to the libwebsockets library, nor do you have to -identify the libwebsockets license in your program or documentation as -required by section 6 of the LGPL. - -However, programs must still identify their use of libwebsockets. The -following example statement can be included in user documentation to -satisfy this requirement: - -"[program] is based in part on the work of the libwebsockets project -(https://libwebsockets.org)" - -4) Some sources included have their own, more liberal licenses, or options -to get original sources with the liberal terms. - -Original liberal license retained - - - lib/misc/sha-1.c - 3-clause BSD license retained, link to original - - win32port/zlib - ZLIB license (see zlib.h) - - lib/tls/mbedtls/wrapper - Apache 2.0 (only built if linked against mbedtls) - -Relicensed to libwebsocket license - - - lib/misc/base64-decode.c - relicensed to LGPL2.1+SLE, link to original - - lib/misc/daemonize.c - relicensed from Public Domain to LGPL2.1+SLE, - link to original Public Domain version - -Public Domain (CC-zero) to simplify reuse +Public Domain (CC-zero) to simplify reuse: - test-apps/*.c - test-apps/*.h - minimal-examples/* - lwsws/* ------- end of exceptions - - GNU LESSER GENERAL PUBLIC LICENSE - Version 2.1, February 1999 - - Copyright (C) 1991, 1999 Free Software Foundation, Inc. - 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA - Everyone is permitted to copy and distribute verbatim copies - of this license document, but changing it is not allowed. - -[This is the first released version of the Lesser GPL. It also counts - as the successor of the GNU Library Public License, version 2, hence - the version number 2.1.] - - Preamble - - The licenses for most software are designed to take away your -freedom to share and change it. By contrast, the GNU General Public -Licenses are intended to guarantee your freedom to share and change -free software--to make sure the software is free for all its users. - - This license, the Lesser General Public License, applies to some -specially designated software packages--typically libraries--of the -Free Software Foundation and other authors who decide to use it. You -can use it too, but we suggest you first think carefully about whether -this license or the ordinary General Public License is the better -strategy to use in any particular case, based on the explanations below. - - When we speak of free software, we are referring to freedom of use, -not price. Our General Public Licenses are designed to make sure that -you have the freedom to distribute copies of free software (and charge -for this service if you wish); that you receive source code or can get -it if you want it; that you can change the software and use pieces of -it in new free programs; and that you are informed that you can do -these things. - - To protect your rights, we need to make restrictions that forbid -distributors to deny you these rights or to ask you to surrender these -rights. These restrictions translate to certain responsibilities for -you if you distribute copies of the library or if you modify it. - - For example, if you distribute copies of the library, whether gratis -or for a fee, you must give the recipients all the rights that we gave -you. You must make sure that they, too, receive or can get the source -code. If you link other code with the library, you must provide -complete object files to the recipients, so that they can relink them -with the library after making changes to the library and recompiling -it. And you must show them these terms so they know their rights. - - We protect your rights with a two-step method: (1) we copyright the -library, and (2) we offer you this license, which gives you legal -permission to copy, distribute and/or modify the library. - - To protect each distributor, we want to make it very clear that -there is no warranty for the free library. Also, if the library is -modified by someone else and passed on, the recipients should know -that what they have is not the original version, so that the original -author's reputation will not be affected by problems that might be -introduced by others. - - Finally, software patents pose a constant threat to the existence of -any free program. We wish to make sure that a company cannot -effectively restrict the users of a free program by obtaining a -restrictive license from a patent holder. Therefore, we insist that -any patent license obtained for a version of the library must be -consistent with the full freedom of use specified in this license. - - Most GNU software, including some libraries, is covered by the -ordinary GNU General Public License. This license, the GNU Lesser -General Public License, applies to certain designated libraries, and -is quite different from the ordinary General Public License. We use -this license for certain libraries in order to permit linking those -libraries into non-free programs. - - When a program is linked with a library, whether statically or using -a shared library, the combination of the two is legally speaking a -combined work, a derivative of the original library. The ordinary -General Public License therefore permits such linking only if the -entire combination fits its criteria of freedom. The Lesser General -Public License permits more lax criteria for linking other code with -the library. - - We call this license the "Lesser" General Public License because it -does Less to protect the user's freedom than the ordinary General -Public License. It also provides other free software developers Less -of an advantage over competing non-free programs. These disadvantages -are the reason we use the ordinary General Public License for many -libraries. However, the Lesser license provides advantages in certain -special circumstances. - - For example, on rare occasions, there may be a special need to -encourage the widest possible use of a certain library, so that it becomes -a de-facto standard. To achieve this, non-free programs must be -allowed to use the library. A more frequent case is that a free -library does the same job as widely used non-free libraries. In this -case, there is little to gain by limiting the free library to free -software only, so we use the Lesser General Public License. - - In other cases, permission to use a particular library in non-free -programs enables a greater number of people to use a large body of -free software. For example, permission to use the GNU C Library in -non-free programs enables many more people to use the whole GNU -operating system, as well as its variant, the GNU/Linux operating -system. - - Although the Lesser General Public License is Less protective of the -users' freedom, it does ensure that the user of a program that is -linked with the Library has the freedom and the wherewithal to run -that program using a modified version of the Library. - - The precise terms and conditions for copying, distribution and -modification follow. Pay close attention to the difference between a -"work based on the library" and a "work that uses the library". The -former contains code derived from the library, whereas the latter must -be combined with the library in order to run. - - GNU LESSER GENERAL PUBLIC LICENSE - TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION - - 0. This License Agreement applies to any software library or other -program which contains a notice placed by the copyright holder or -other authorized party saying it may be distributed under the terms of -this Lesser General Public License (also called "this License"). -Each licensee is addressed as "you". - - A "library" means a collection of software functions and/or data -prepared so as to be conveniently linked with application programs -(which use some of those functions and data) to form executables. - - The "Library", below, refers to any such software library or work -which has been distributed under these terms. A "work based on the -Library" means either the Library or any derivative work under -copyright law: that is to say, a work containing the Library or a -portion of it, either verbatim or with modifications and/or translated -straightforwardly into another language. (Hereinafter, translation is -included without limitation in the term "modification".) - - "Source code" for a work means the preferred form of the work for -making modifications to it. For a library, complete source code means -all the source code for all modules it contains, plus any associated -interface definition files, plus the scripts used to control compilation -and installation of the library. - - Activities other than copying, distribution and modification are not -covered by this License; they are outside its scope. The act of -running a program using the Library is not restricted, and output from -such a program is covered only if its contents constitute a work based -on the Library (independent of the use of the Library in a tool for -writing it). Whether that is true depends on what the Library does -and what the program that uses the Library does. - - 1. You may copy and distribute verbatim copies of the Library's -complete source code as you receive it, in any medium, provided that -you conspicuously and appropriately publish on each copy an -appropriate copyright notice and disclaimer of warranty; keep intact -all the notices that refer to this License and to the absence of any -warranty; and distribute a copy of this License along with the -Library. - - You may charge a fee for the physical act of transferring a copy, -and you may at your option offer warranty protection in exchange for a -fee. - - 2. You may modify your copy or copies of the Library or any portion -of it, thus forming a work based on the Library, and copy and -distribute such modifications or work under the terms of Section 1 -above, provided that you also meet all of these conditions: - - a) The modified work must itself be a software library. - - b) You must cause the files modified to carry prominent notices - stating that you changed the files and the date of any change. - - c) You must cause the whole of the work to be licensed at no - charge to all third parties under the terms of this License. - - d) If a facility in the modified Library refers to a function or a - table of data to be supplied by an application program that uses - the facility, other than as an argument passed when the facility - is invoked, then you must make a good faith effort to ensure that, - in the event an application does not supply such function or - table, the facility still operates, and performs whatever part of - its purpose remains meaningful. - - (For example, a function in a library to compute square roots has - a purpose that is entirely well-defined independent of the - application. Therefore, Subsection 2d requires that any - application-supplied function or table used by this function must - be optional: if the application does not supply it, the square - root function must still compute square roots.) - -These requirements apply to the modified work as a whole. If -identifiable sections of that work are not derived from the Library, -and can be reasonably considered independent and separate works in -themselves, then this License, and its terms, do not apply to those -sections when you distribute them as separate works. But when you -distribute the same sections as part of a whole which is a work based -on the Library, the distribution of the whole must be on the terms of -this License, whose permissions for other licensees extend to the -entire whole, and thus to each and every part regardless of who wrote -it. - -Thus, it is not the intent of this section to claim rights or contest -your rights to work written entirely by you; rather, the intent is to -exercise the right to control the distribution of derivative or -collective works based on the Library. - -In addition, mere aggregation of another work not based on the Library -with the Library (or with a work based on the Library) on a volume of -a storage or distribution medium does not bring the other work under -the scope of this License. - - 3. You may opt to apply the terms of the ordinary GNU General Public -License instead of this License to a given copy of the Library. To do -this, you must alter all the notices that refer to this License, so -that they refer to the ordinary GNU General Public License, version 2, -instead of to this License. (If a newer version than version 2 of the -ordinary GNU General Public License has appeared, then you can specify -that version instead if you wish.) Do not make any other change in -these notices. - - Once this change is made in a given copy, it is irreversible for -that copy, so the ordinary GNU General Public License applies to all -subsequent copies and derivative works made from that copy. - - This option is useful when you wish to copy part of the code of -the Library into a program that is not a library. - - 4. You may copy and distribute the Library (or a portion or -derivative of it, under Section 2) in object code or executable form -under the terms of Sections 1 and 2 above provided that you accompany -it with the complete corresponding machine-readable source code, which -must be distributed under the terms of Sections 1 and 2 above on a -medium customarily used for software interchange. - - If distribution of object code is made by offering access to copy -from a designated place, then offering equivalent access to copy the -source code from the same place satisfies the requirement to -distribute the source code, even though third parties are not -compelled to copy the source along with the object code. - - 5. A program that contains no derivative of any portion of the -Library, but is designed to work with the Library by being compiled or -linked with it, is called a "work that uses the Library". Such a -work, in isolation, is not a derivative work of the Library, and -therefore falls outside the scope of this License. - - However, linking a "work that uses the Library" with the Library -creates an executable that is a derivative of the Library (because it -contains portions of the Library), rather than a "work that uses the -library". The executable is therefore covered by this License. -Section 6 states terms for distribution of such executables. - - When a "work that uses the Library" uses material from a header file -that is part of the Library, the object code for the work may be a -derivative work of the Library even though the source code is not. -Whether this is true is especially significant if the work can be -linked without the Library, or if the work is itself a library. The -threshold for this to be true is not precisely defined by law. - - If such an object file uses only numerical parameters, data -structure layouts and accessors, and small macros and small inline -functions (ten lines or less in length), then the use of the object -file is unrestricted, regardless of whether it is legally a derivative -work. (Executables containing this object code plus portions of the -Library will still fall under Section 6.) - - Otherwise, if the work is a derivative of the Library, you may -distribute the object code for the work under the terms of Section 6. -Any executables containing that work also fall under Section 6, -whether or not they are linked directly with the Library itself. - - 6. As an exception to the Sections above, you may also combine or -link a "work that uses the Library" with the Library to produce a -work containing portions of the Library, and distribute that work -under terms of your choice, provided that the terms permit -modification of the work for the customer's own use and reverse -engineering for debugging such modifications. - - You must give prominent notice with each copy of the work that the -Library is used in it and that the Library and its use are covered by -this License. You must supply a copy of this License. If the work -during execution displays copyright notices, you must include the -copyright notice for the Library among them, as well as a reference -directing the user to the copy of this License. Also, you must do one -of these things: - - a) Accompany the work with the complete corresponding - machine-readable source code for the Library including whatever - changes were used in the work (which must be distributed under - Sections 1 and 2 above); and, if the work is an executable linked - with the Library, with the complete machine-readable "work that - uses the Library", as object code and/or source code, so that the - user can modify the Library and then relink to produce a modified - executable containing the modified Library. (It is understood - that the user who changes the contents of definitions files in the - Library will not necessarily be able to recompile the application - to use the modified definitions.) - - b) Use a suitable shared library mechanism for linking with the - Library. A suitable mechanism is one that (1) uses at run time a - copy of the library already present on the user's computer system, - rather than copying library functions into the executable, and (2) - will operate properly with a modified version of the library, if - the user installs one, as long as the modified version is - interface-compatible with the version that the work was made with. - - c) Accompany the work with a written offer, valid for at - least three years, to give the same user the materials - specified in Subsection 6a, above, for a charge no more - than the cost of performing this distribution. - - d) If distribution of the work is made by offering access to copy - from a designated place, offer equivalent access to copy the above - specified materials from the same place. - - e) Verify that the user has already received a copy of these - materials or that you have already sent this user a copy. - - For an executable, the required form of the "work that uses the -Library" must include any data and utility programs needed for -reproducing the executable from it. However, as a special exception, -the materials to be distributed need not include anything that is -normally distributed (in either source or binary form) with the major -components (compiler, kernel, and so on) of the operating system on -which the executable runs, unless that component itself accompanies -the executable. - - It may happen that this requirement contradicts the license -restrictions of other proprietary libraries that do not normally -accompany the operating system. Such a contradiction means you cannot -use both them and the Library together in an executable that you -distribute. - - 7. You may place library facilities that are a work based on the -Library side-by-side in a single library together with other library -facilities not covered by this License, and distribute such a combined -library, provided that the separate distribution of the work based on -the Library and of the other library facilities is otherwise -permitted, and provided that you do these two things: - - a) Accompany the combined library with a copy of the same work - based on the Library, uncombined with any other library - facilities. This must be distributed under the terms of the - Sections above. - - b) Give prominent notice with the combined library of the fact - that part of it is a work based on the Library, and explaining - where to find the accompanying uncombined form of the same work. - - 8. You may not copy, modify, sublicense, link with, or distribute -the Library except as expressly provided under this License. Any -attempt otherwise to copy, modify, sublicense, link with, or -distribute the Library is void, and will automatically terminate your -rights under this License. However, parties who have received copies, -or rights, from you under this License will not have their licenses -terminated so long as such parties remain in full compliance. - - 9. You are not required to accept this License, since you have not -signed it. However, nothing else grants you permission to modify or -distribute the Library or its derivative works. These actions are -prohibited by law if you do not accept this License. Therefore, by -modifying or distributing the Library (or any work based on the -Library), you indicate your acceptance of this License to do so, and -all its terms and conditions for copying, distributing or modifying -the Library or works based on it. - - 10. Each time you redistribute the Library (or any work based on the -Library), the recipient automatically receives a license from the -original licensor to copy, distribute, link with or modify the Library -subject to these terms and conditions. You may not impose any further -restrictions on the recipients' exercise of the rights granted herein. -You are not responsible for enforcing compliance by third parties with -this License. - - 11. If, as a consequence of a court judgment or allegation of patent -infringement or for any other reason (not limited to patent issues), -conditions are imposed on you (whether by court order, agreement or -otherwise) that contradict the conditions of this License, they do not -excuse you from the conditions of this License. If you cannot -distribute so as to satisfy simultaneously your obligations under this -License and any other pertinent obligations, then as a consequence you -may not distribute the Library at all. For example, if a patent -license would not permit royalty-free redistribution of the Library by -all those who receive copies directly or indirectly through you, then -the only way you could satisfy both it and this License would be to -refrain entirely from distribution of the Library. - -If any portion of this section is held invalid or unenforceable under any -particular circumstance, the balance of the section is intended to apply, -and the section as a whole is intended to apply in other circumstances. - -It is not the purpose of this section to induce you to infringe any -patents or other property right claims or to contest validity of any -such claims; this section has the sole purpose of protecting the -integrity of the free software distribution system which is -implemented by public license practices. Many people have made -generous contributions to the wide range of software distributed -through that system in reliance on consistent application of that -system; it is up to the author/donor to decide if he or she is willing -to distribute software through any other system and a licensee cannot -impose that choice. - -This section is intended to make thoroughly clear what is believed to -be a consequence of the rest of this License. - - 12. If the distribution and/or use of the Library is restricted in -certain countries either by patents or by copyrighted interfaces, the -original copyright holder who places the Library under this License may add -an explicit geographical distribution limitation excluding those countries, -so that distribution is permitted only in or among countries not thus -excluded. In such case, this License incorporates the limitation as if -written in the body of this License. - - 13. The Free Software Foundation may publish revised and/or new -versions of the Lesser General Public License from time to time. -Such new versions will be similar in spirit to the present version, -but may differ in detail to address new problems or concerns. - -Each version is given a distinguishing version number. If the Library -specifies a version number of this License which applies to it and -"any later version", you have the option of following the terms and -conditions either of that version or of any later version published by -the Free Software Foundation. If the Library does not specify a -license version number, you may choose any version ever published by -the Free Software Foundation. - - 14. If you wish to incorporate parts of the Library into other free -programs whose distribution conditions are incompatible with these, -write to the author to ask for permission. For software which is -copyrighted by the Free Software Foundation, write to the Free -Software Foundation; we sometimes make exceptions for this. Our -decision will be guided by the two goals of preserving the free status -of all derivatives of our free software and of promoting the sharing -and reuse of software generally. - - NO WARRANTY - - 15. BECAUSE THE LIBRARY IS LICENSED FREE OF CHARGE, THERE IS NO -WARRANTY FOR THE LIBRARY, TO THE EXTENT PERMITTED BY APPLICABLE LAW. -EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR -OTHER PARTIES PROVIDE THE LIBRARY "AS IS" WITHOUT WARRANTY OF ANY -KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE -IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR -PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE -LIBRARY IS WITH YOU. SHOULD THE LIBRARY PROVE DEFECTIVE, YOU ASSUME -THE COST OF ALL NECESSARY SERVICING, REPAIR OR CORRECTION. - - 16. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN -WRITING WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY -AND/OR REDISTRIBUTE THE LIBRARY AS PERMITTED ABOVE, BE LIABLE TO YOU -FOR DAMAGES, INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR -CONSEQUENTIAL DAMAGES ARISING OUT OF THE USE OR INABILITY TO USE THE -LIBRARY (INCLUDING BUT NOT LIMITED TO LOSS OF DATA OR DATA BEING -RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD PARTIES OR A -FAILURE OF THE LIBRARY TO OPERATE WITH ANY OTHER SOFTWARE), EVEN IF -SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH -DAMAGES. - - END OF TERMS AND CONDITIONS - - How to Apply These Terms to Your New Libraries - - If you develop a new library, and you want it to be of the greatest -possible use to the public, we recommend making it free software that -everyone can redistribute and change. You can do so by permitting -redistribution under these terms (or, alternatively, under the terms of the -ordinary General Public License). - - To apply these terms, attach the following notices to the library. It is -safest to attach them to the start of each source file to most effectively -convey the exclusion of warranty; and each file should have at least the -"copyright" line and a pointer to where the full notice is found. - - - Copyright (C) - - This library is free software; you can redistribute it and/or - modify it under the terms of the GNU Lesser General Public - License as published by the Free Software Foundation; either - version 2.1 of the License, or (at your option) any later version. - - This library is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - Lesser General Public License for more details. - - You should have received a copy of the GNU Lesser General Public - License along with this library; if not, write to the Free Software - Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA - -Also add information on how to contact you by electronic and paper mail. - -You should also get your employer (if you work as a programmer) or your -school, if any, to sign a "copyright disclaimer" for the library, if -necessary. Here is a sample; alter the names: - - Yoyodyne, Inc., hereby disclaims all copyright interest in the - library `Frob' (a library for tweaking knobs) written by James Random Hacker. - - , 1 April 1990 - Ty Coon, President of Vice +Although libwebsockets is available under a permissive license, it does not +change the reality of dealing with large lumps of external code... if your +copy diverges it is guaranteed to contain security problems after a while +and can be very painful to pick backports (especially since historically, +we are very hot on cleaning and refactoring the codebase). The least +painful and lowest risk way remains sending your changes and fixes upstream +to us so you can easily use later releases and fixes. + +MIT License applied to libwebsockets: + +https://opensource.org/licenses/MIT + + Permission is hereby granted, free of charge, to any person obtaining a copy + of this software and associated documentation files (the "Software"), to + deal in the Software without restriction, including without limitation the + rights to use, copy, modify, merge, publish, distribute, sublicense, and/or + sell copies of the Software, and to permit persons to whom the Software is + furnished to do so, subject to the following conditions: + + The above copyright notice and this permission notice shall be included in + all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS + IN THE SOFTWARE. -That's all there is to it! diff -Nru libwebsockets-3.2.1/lwsws/CMakeLists.txt libwebsockets-4.1.6/lwsws/CMakeLists.txt --- libwebsockets-3.2.1/lwsws/CMakeLists.txt 1970-01-01 00:00:00.000000000 +0000 +++ libwebsockets-4.1.6/lwsws/CMakeLists.txt 2020-12-01 17:40:26.000000000 +0000 @@ -0,0 +1,66 @@ +# +# libwebsockets - small server side websockets and web server implementation +# +# Copyright (C) 2010 - 2020 Andy Green +# +# Permission is hereby granted, free of charge, to any person obtaining a copy +# of this software and associated documentation files (the "Software"), to +# deal in the Software without restriction, including without limitation the +# rights to use, copy, modify, merge, publish, distribute, sublicense, and/or +# sell copies of the Software, and to permit persons to whom the Software is +# furnished to do so, subject to the following conditions: +# +# The above copyright notice and this permission notice shall be included in +# all copies or substantial portions of the Software. +# +# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING +# FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS +# IN THE SOFTWARE. +# + +if (LWS_WITH_LWSWS) + list(APPEND LWSWS_SRCS + "main.c" + ) + + if (WIN32) + list(APPEND LWSWS_SRCS + ${WIN32_HELPERS_PATH}/getopt.c + ${WIN32_HELPERS_PATH}/getopt_long.c + ${WIN32_HELPERS_PATH}/gettimeofday.c + ) + + list(APPEND LWSWS_HDR + ${WIN32_HELPERS_PATH}/getopt.h + ${WIN32_HELPERS_PATH}/gettimeofday.h + ) + endif(WIN32) + + source_group("Headers Private" FILES ${LWSWS_HDR}) + source_group("Sources" FILES ${LWSWS_SRCS}) + add_executable("lwsws" ${LWSWS_SRCS} ${LWSWS_HDR}) + + if (LWS_WITH_SHARED) + target_link_libraries("lwsws" websockets_shared ${LIB_LIST_AT_END}) + add_dependencies("lwsws" websockets_shared) + else() + target_link_libraries("lwsws" websockets ${LIB_LIST_AT_END}) + add_dependencies("lwsws" websockets) + endif() + target_include_directories("lwsws" PRIVATE "${LWS_LIB_INCLUDES}" ${LWS_LIB_BUILD_INC_PATHS}) + + # Set test app specific defines. + set_property(TARGET "lwsws" + PROPERTY COMPILE_DEFINITIONS + INSTALL_DATADIR="${CMAKE_INSTALL_PREFIX}/share" + ) + + install(TARGETS lwsws + RUNTIME DESTINATION "${LWS_INSTALL_BIN_DIR}" COMPONENT lwsws ) +endif (LWS_WITH_LWSWS) + + diff -Nru libwebsockets-3.2.1/lwsws/main.c libwebsockets-4.1.6/lwsws/main.c --- libwebsockets-3.2.1/lwsws/main.c 2019-12-18 14:45:31.000000000 +0000 +++ libwebsockets-4.1.6/lwsws/main.c 2020-12-01 17:40:26.000000000 +0000 @@ -1,7 +1,7 @@ /* * libwebsockets web server application * - * Written in 2010-2019 by Andy Green + * Written in 2010-2020 by Andy Green * * This file is made available under the Creative Commons CC0 1.0 * Universal Public Domain Dedication. @@ -51,8 +51,13 @@ #include +#if defined(LWS_HAVE_MALLOC_TRIM) +#include +#endif + static struct lws_context *context; -static char config_dir[128]; +static lws_sorted_usec_list_t sul_lwsws; +static char config_dir[128], default_plugin_path = 1; static int opts = 0, do_reload = 1; static uv_loop_t loop; static uv_signal_t signal_outer[2]; @@ -72,16 +77,19 @@ { NULL, NULL, NULL /* terminator */ } }; +#if defined(LWS_WITH_PLUGINS) static const char * const plugin_dirs[] = { INSTALL_DATADIR"/libwebsockets-test-server/plugins/", NULL }; +#endif #if defined(LWS_HAS_GETOPT_LONG) || defined(WIN32) static struct option options[] = { { "help", no_argument, NULL, 'h' }, { "debug", required_argument, NULL, 'd' }, { "configdir", required_argument, NULL, 'c' }, + { "no-default-plugins", no_argument, NULL, 'n' }, { NULL, 0, 0, 0 } }; #endif @@ -111,6 +119,18 @@ lws_context_destroy(context); } +static void +lwsws_min(lws_sorted_usec_list_t *sul) +{ + lwsl_debug("%s\n", __func__); + +#if defined(LWS_HAVE_MALLOC_TRIM) + malloc_trim(4 * 1024); +#endif + + lws_sul_schedule(context, 0, &sul_lwsws, lwsws_min, 60 * LWS_US_PER_SEC); +} + static int context_creation(void) { @@ -133,7 +153,10 @@ LWS_SERVER_OPTION_EXPLICIT_VHOSTS | LWS_SERVER_OPTION_LIBUV; - info.plugin_dirs = plugin_dirs; +#if defined(LWS_WITH_PLUGINS) + if (default_plugin_path) + info.plugin_dirs = plugin_dirs; +#endif lwsl_notice("Using config dir: \"%s\"\n", config_dir); /* @@ -162,6 +185,8 @@ if (lwsws_get_config_vhosts(context, &info, config_dir, &cs, &cs_len)) return 1; + lws_sul_schedule(context, 0, &sul_lwsws, lwsws_min, 60 * LWS_US_PER_SEC); + return 0; init_failed: @@ -221,9 +246,9 @@ strcpy(config_dir, "/etc/lwsws"); while (n >= 0) { #if defined(LWS_HAS_GETOPT_LONG) || defined(WIN32) - n = getopt_long(argc, argv, "hd:c:", options, NULL); + n = getopt_long(argc, argv, "hd:c:n", options, NULL); #else - n = getopt(argc, argv, "hd:c:"); + n = getopt(argc, argv, "hd:c:n"); #endif if (n < 0) continue; @@ -231,12 +256,16 @@ case 'd': debug_level = atoi(optarg); break; + case 'n': + default_plugin_path = 0; + break; case 'c': lws_strncpy(config_dir, optarg, sizeof(config_dir)); break; case 'h': fprintf(stderr, "Usage: lwsws [-c ] " - "[-d ] [--help]\n"); + "[-d ] [--help] " + "[-n]\n"); exit(1); } } @@ -252,7 +281,7 @@ signal(SIGHUP, reload_handler); signal(SIGINT, reload_handler); - fprintf(stderr, "Root process is %u\n", getpid()); + fprintf(stderr, "Root process is %u\n", (unsigned int)getpid()); while (1) { if (do_reload) { @@ -287,8 +316,8 @@ lws_set_log_level(debug_level, lwsl_emit_stderr_notimestamp); - lwsl_notice("lwsws libwebsockets web server - license CC0 + LGPL2.1\n"); - lwsl_notice("(C) Copyright 2010-2018 Andy Green \n"); + lwsl_notice("lwsws libwebsockets web server - license CC0 + MIT\n"); + lwsl_notice("(C) Copyright 2010-2020 Andy Green \n"); #if (UV_VERSION_MAJOR > 0) // Travis... uv_loop_init(&loop); @@ -315,6 +344,9 @@ uv_close((uv_handle_t *)&signal_outer[n], NULL); } + /* cancel the per-minute sul */ + lws_sul_cancel(&sul_lwsws); + lws_context_destroy(context); (void)budget; #if (UV_VERSION_MAJOR > 0) // Travis... diff -Nru libwebsockets-3.2.1/minimal-examples/abstract/protocols/smtp-client/CMakeLists.txt libwebsockets-4.1.6/minimal-examples/abstract/protocols/smtp-client/CMakeLists.txt --- libwebsockets-3.2.1/minimal-examples/abstract/protocols/smtp-client/CMakeLists.txt 2019-12-18 14:45:31.000000000 +0000 +++ libwebsockets-4.1.6/minimal-examples/abstract/protocols/smtp-client/CMakeLists.txt 2020-12-01 17:40:26.000000000 +0000 @@ -1,66 +1,13 @@ +project(lws-api-test-smtp_client C) cmake_minimum_required(VERSION 2.8) +find_package(libwebsockets CONFIG REQUIRED) +list(APPEND CMAKE_MODULE_PATH ${LWS_CMAKE_DIR}) include(CheckCSourceCompiles) +include(LwsCheckRequirements) set(SAMP lws-api-test-smtp_client) set(SRCS main.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_WITH_SMTP 1 requirements) @@ -68,9 +15,9 @@ add_executable(${SAMP} ${SRCS}) if (websockets_shared) - target_link_libraries(${SAMP} websockets_shared) + target_link_libraries(${SAMP} websockets_shared ${LIBWEBSOCKETS_DEP_LIBS}) add_dependencies(${SAMP} websockets_shared) else() - target_link_libraries(${SAMP} websockets) + target_link_libraries(${SAMP} websockets ${LIBWEBSOCKETS_DEP_LIBS}) endif() endif() diff -Nru libwebsockets-3.2.1/minimal-examples/abstract/protocols/smtp-client/main.c libwebsockets-4.1.6/minimal-examples/abstract/protocols/smtp-client/main.c --- libwebsockets-3.2.1/minimal-examples/abstract/protocols/smtp-client/main.c 2019-12-18 14:45:31.000000000 +0000 +++ libwebsockets-4.1.6/minimal-examples/abstract/protocols/smtp-client/main.c 2020-12-01 17:40:26.000000000 +0000 @@ -21,12 +21,14 @@ } static int -email_sent_or_failed(struct lws_smtp_email *email, void *buf, size_t len) +done_cb(struct lws_smtp_email *email, void *buf, size_t len) { /* you could examine email->data here */ - if (buf) - lwsl_notice("%s: %.*s\n", __func__, (int)len, (const char *)buf); - else + if (buf) { + char dotstar[96]; + lws_strnncpy(dotstar, (const char *)buf, len, sizeof(dotstar)); + lwsl_notice("%s: %s\n", __func__, dotstar); + } else lwsl_notice("%s:\n", __func__); /* destroy any allocations in email */ @@ -39,39 +41,16 @@ return 0; } -/* - * We're going to bind to the raw-skt transport, so tell that what we want it - * to connect to - */ - -static const lws_token_map_t smtp_raw_skt_transport_tokens[] = { - { - .u = { .value = "127.0.0.1" }, - .name_index = LTMI_PEER_V_DNS_ADDRESS, - }, { - .u = { .lvalue = 25 }, - .name_index = LTMI_PEER_LV_PORT, - }, { - } -}; - -static const lws_token_map_t smtp_protocol_tokens[] = { - { - .u = { .value = "lws-test-client" }, - .name_index = LTMI_PSMTP_V_HELO, - }, { - } -}; - - int main(int argc, const char **argv) { int n = 1, logs = LLL_USER | LLL_ERR | LLL_WARN | LLL_NOTICE; struct lws_context_creation_info info; + lws_smtp_sequencer_args_t ss_args; struct lws_context *context; - lws_abs_t abs, *instance; - lws_smtp_email_t email; + lws_smtp_sequencer_t *sseq; + lws_smtp_email_t *email; struct lws_vhost *vh; + char payload[2048]; const char *p; /* the normal lws init */ @@ -107,56 +86,30 @@ goto bail1; } - /* - * create an smtp client that's hooked up to real sockets - */ - - memset(&abs, 0, sizeof(abs)); - abs.vh = vh; - - /* select the protocol and bind its tokens */ - - abs.ap = lws_abs_protocol_get_by_name("smtp"); - if (!abs.ap) - goto bail1; - abs.ap_tokens = smtp_protocol_tokens; - - /* select the transport and bind its tokens */ - - abs.at = lws_abs_transport_get_by_name("raw_skt"); - if (!abs.at) - goto bail1; - abs.at_tokens = smtp_raw_skt_transport_tokens; - - instance = lws_abs_bind_and_create_instance(&abs); - if (!instance) { - lwsl_err("%s: failed to create SMTP client\n", __func__); + memset(&ss_args, 0, sizeof(ss_args)); + ss_args.helo = "lws-abs-smtp-test"; + ss_args.vhost = vh; + + sseq = lws_smtp_sequencer_create(&ss_args); + if (!sseq) { + lwsl_err("%s: smtp sequencer create failed\n", __func__); goto bail1; } /* attach an email to it */ - memset(&email, 0, sizeof(email)); - email.data = NULL /* email specific user data */; - email.email_from = "andy@warmcat.com"; - email.email_to = recip; - email.payload = malloc(2048); - if (!email.payload) { - goto bail1; - } - - lws_snprintf((char *)email.payload, 2048, + n = lws_snprintf(payload, sizeof(payload), "From: noreply@example.com\n" "To: %s\n" "Subject: Test email for lws smtp-client\n" "\n" "Hello this was an api test for lws smtp-client\n" "\r\n.\r\n", recip); - email.done = email_sent_or_failed; - if (lws_smtp_client_add_email(instance, &email)) { + if (lws_smtpc_add_email(sseq, payload, n, "testserver", + "andy@warmcat.com", recip, NULL, done_cb)) { lwsl_err("%s: failed to add email\n", __func__); - goto bail; + goto bail1; } /* the usual lws event loop */ @@ -164,8 +117,6 @@ while (n >= 0 && !interrupted) n = lws_service(context, 0); -bail: - bail1: lwsl_user("Completed: %s\n", result ? "FAIL" : "PASS"); diff -Nru libwebsockets-3.2.1/minimal-examples/api-tests/api-test-async-dns/CMakeLists.txt libwebsockets-4.1.6/minimal-examples/api-tests/api-test-async-dns/CMakeLists.txt --- libwebsockets-3.2.1/minimal-examples/api-tests/api-test-async-dns/CMakeLists.txt 1970-01-01 00:00:00.000000000 +0000 +++ libwebsockets-4.1.6/minimal-examples/api-tests/api-test-async-dns/CMakeLists.txt 2020-12-01 17:40:26.000000000 +0000 @@ -0,0 +1,30 @@ +project(lws-api-test-async-dns C) +cmake_minimum_required(VERSION 2.8) +find_package(libwebsockets CONFIG REQUIRED) +list(APPEND CMAKE_MODULE_PATH ${LWS_CMAKE_DIR}) +include(CheckCSourceCompiles) +include(LwsCheckRequirements) + +set(SAMP lws-api-test-async-dns) +set(SRCS main.c) + +set(requirements 1) +require_lws_config(LWS_ROLE_H1 1 requirements) +require_lws_config(LWS_WITH_CLIENT 1 requirements) +require_lws_config(LWS_WITH_SYS_ASYNC_DNS 1 requirements) + +if (requirements) + add_executable(${SAMP} ${SRCS}) + add_test(NAME api-test-async-dns COMMAND lws-api-test-async-dns) + set_tests_properties(api-test-async-dns + PROPERTIES + WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}/minimal-examples/api-tests/api-test-async-dns + TIMEOUT 60) + + if (websockets_shared) + target_link_libraries(${SAMP} websockets_shared ${LIBWEBSOCKETS_DEP_LIBS}) + add_dependencies(${SAMP} websockets_shared) + else() + target_link_libraries(${SAMP} websockets ${LIBWEBSOCKETS_DEP_LIBS}) + endif() +endif() diff -Nru libwebsockets-3.2.1/minimal-examples/api-tests/api-test-async-dns/main.c libwebsockets-4.1.6/minimal-examples/api-tests/api-test-async-dns/main.c --- libwebsockets-3.2.1/minimal-examples/api-tests/api-test-async-dns/main.c 1970-01-01 00:00:00.000000000 +0000 +++ libwebsockets-4.1.6/minimal-examples/api-tests/api-test-async-dns/main.c 2020-12-01 17:40:26.000000000 +0000 @@ -0,0 +1,315 @@ +/* + * lws-api-test-async-dns + * + * Written in 2019 by Andy Green + * + * This file is made available under the Creative Commons CC0 1.0 + * Universal Public Domain Dedication. + * + * This api test confirms various kinds of async dns apis + */ + +#include +#include + +static int interrupted, dtest, ok, fail, _exp = 26; +struct lws_context *context; + +/* + * These are used to test the apis to parse and print ipv4 / ipv6 literal + * address strings for various cases. + * + * Expected error cases are not used to test the ip data -> string api. + */ + +static const struct ipparser_tests { + const char *test; + int rlen; + const char *emit_test; + int emit_len; + uint8_t b[16]; +} ipt[] = { + { "2001:db8:85a3:0:0:8a2e:370:7334", 16, + "2001:db8:85a3::8a2e:370:7334", 28, + { 0x20, 0x01, 0x0d, 0xb8, 0x85, 0xa3, 0x00, 0x00, + 0x00, 0x00, 0x8a, 0x2e, 0x03, 0x70, 0x73, 0x34 } }, + + { "2001:db8:85a3::8a2e:370:7334", 16, + "2001:db8:85a3::8a2e:370:7334", 28, + { 0x20, 0x01, 0x0d, 0xb8, 0x85, 0xa3, 0x00, 0x00, + 0x00, 0x00, 0x8a, 0x2e, 0x03, 0x70, 0x73, 0x34 } }, + + { "::1", 16, "::1", 3, + { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1 } }, + + { "::", 16, "::", 2, + { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 } }, + + { "::ffff:192.0.2.128", 16, "::ffff:192.0.2.128", 18, + { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0xff, 0xff, 0xc0, 0x00, 0x02, 0x80 } }, + + { "cats", -1, "", 0, + { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1 } }, + + { "onevalid.bogus.warmcat.com", -1, "", 0, + { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1 } }, + + { "1.cat.dog.com", -1, "", 0, + { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1 } }, + + { ":::1", -8, "", 0, + { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1 } }, + + { "0:0::0:1", 16, "::1", 3, + { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1 } }, + + { "1.2.3.4", 4, "1.2.3.4", 7, { 1, 2, 3, 4 } }, +}; + +static const struct async_dns_tests { + const char *dns_name; + int recordtype; + int addrlen; + uint8_t ads[16]; +} adt[] = { + { "warmcat.com", LWS_ADNS_RECORD_A, 4, + { 46, 105, 127, 147, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, } }, + { "libwebsockets.org", LWS_ADNS_RECORD_A, 4, + { 46, 105, 127, 147, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, } }, + { "doesntexist", LWS_ADNS_RECORD_A, 0, + { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, } }, + { "localhost", LWS_ADNS_RECORD_A, 4, + { 127, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, } }, + { "ipv4only.warmcat.com", LWS_ADNS_RECORD_A, 4, + { 46, 105, 127, 147, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, } }, + { "onevalid.bogus.warmcat.com", LWS_ADNS_RECORD_A, 4, + { 46, 105, 127, 147, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, } }, +#if defined(LWS_WITH_IPV6) + { "warmcat.com", LWS_ADNS_RECORD_AAAA, 16, /* check ipv6 */ + { 0x20, 0x01, 0x41, 0xd0, 0x00, 0x02, 0xee, 0x93, + 0, 0, 0, 0, 0, 0, 0, 0, } }, + { "ipv6only.warmcat.com", LWS_ADNS_RECORD_AAAA, 16, /* check ipv6 */ + { 0x20, 0x01, 0x41, 0xd0, 0x00, 0x02, 0xee, 0x93, + 0, 0, 0, 0, 0, 0, 0, 0, } }, +#endif +}; + +static lws_sorted_usec_list_t sul; + +struct lws * +cb1(struct lws *wsi_unused, const char *ads, const struct addrinfo *a, int n, + void *opaque); + +static void +next_test_cb(lws_sorted_usec_list_t *sul) +{ + int m; + + lwsl_notice("%s: querying %s\n", __func__, adt[dtest].dns_name); + + m = lws_async_dns_query(context, 0, + adt[dtest].dns_name, + adt[dtest].recordtype, cb1, NULL, + context); + if (m != LADNS_RET_CONTINUING && m != LADNS_RET_FOUND) { + lwsl_err("%s: adns 1 failed: %d\n", __func__, m); + interrupted = 1; + } +} + + +struct lws * +cb1(struct lws *wsi_unused, const char *ads, const struct addrinfo *a, int n, + void *opaque) +{ + const struct addrinfo *ac = a; + int ctr = 0, alen; + uint8_t *addr; + char buf[64]; + + dtest++; + + if (!ac) + lwsl_warn("%s: no results\n", __func__); + + /* dump the results */ + + while (ac) { + if (ac->ai_family == AF_INET) { + addr = (uint8_t *)&(((struct sockaddr_in *) + ac->ai_addr)->sin_addr.s_addr); + alen = 4; + } else { + addr = (uint8_t *)&(((struct sockaddr_in6 *) + ac->ai_addr)->sin6_addr.s6_addr); + alen = 16; + } + strcpy(buf, "unknown"); + lws_write_numeric_address(addr, alen, buf, sizeof(buf)); + + lwsl_warn("%s: %d: %s %d %s\n", __func__, ctr++, ads, alen, buf); + + ac = ac->ai_next; + } + + ac = a; + while (ac) { + if (ac->ai_family == AF_INET) { + addr = (uint8_t *)&(((struct sockaddr_in *) + ac->ai_addr)->sin_addr.s_addr); + alen = 4; + } else { +#if defined(LWS_WITH_IPV6) + addr = (uint8_t *)&(((struct sockaddr_in6 *) + ac->ai_addr)->sin6_addr.s6_addr); + alen = 16; +#else + goto again; +#endif + } + if (alen == adt[dtest - 1].addrlen && + !memcmp(adt[dtest - 1].ads, addr, alen)) { + ok++; + goto next; + } +#if !defined(LWS_WITH_IPV6) +again: +#endif + ac = ac->ai_next; + } + + /* testing for NXDOMAIN? */ + + if (!a && !adt[dtest - 1].addrlen) { + ok++; + goto next; + } + + lwsl_err("%s: dns test %d: no match\n", __func__, dtest); + fail++; + +next: + lws_async_dns_freeaddrinfo(&a); + if (dtest == (int)LWS_ARRAY_SIZE(adt)) + interrupted = 1; + else + lws_sul_schedule(context, 0, &sul, next_test_cb, 1); + + return NULL; +} + + +void sigint_handler(int sig) +{ + interrupted = 1; +} + +int +main(int argc, const char **argv) +{ + int n = 1, logs = LLL_USER | LLL_ERR | LLL_WARN | LLL_NOTICE; + struct lws_context_creation_info info; + const char *p; + + /* the normal lws init */ + + signal(SIGINT, sigint_handler); + + if ((p = lws_cmdline_option(argc, argv, "-d"))) + logs = atoi(p); + + lws_set_log_level(logs, NULL); + lwsl_user("LWS API selftest: Async DNS\n"); + + memset(&info, 0, sizeof info); /* otherwise uninitialized garbage */ + info.port = CONTEXT_PORT_NO_LISTEN; + info.options = LWS_SERVER_OPTION_DO_SSL_GLOBAL_INIT; + + context = lws_create_context(&info); + if (!context) { + lwsl_err("lws init failed\n"); + return 1; + } + + + /* ip address parser tests */ + + for (n = 0; n < (int)LWS_ARRAY_SIZE(ipt); n++) { + uint8_t u[16]; + int m = lws_parse_numeric_address(ipt[n].test, u, sizeof(u)); + + if (m != ipt[n].rlen) { + lwsl_err("%s: fail %s ret %d\n", + __func__, ipt[n].test, m); + fail++; + continue; + } + + if (m > 0) { + if (memcmp(ipt[n].b, u, m)) { + lwsl_err("%s: fail %s compare\n", __func__, + ipt[n].test); + lwsl_hexdump_notice(u, m); + fail++; + continue; + } + } + ok++; + } + + /* ip address formatter tests */ + + for (n = 0; n < (int)LWS_ARRAY_SIZE(ipt); n++) { + char buf[64]; + int m; + + /* don't attempt to reverse the ones that are meant to fail */ + if (ipt[n].rlen < 0) + continue; + + m = lws_write_numeric_address(ipt[n].b, ipt[n].rlen, buf, + sizeof(buf)); + if (m != ipt[n].emit_len) { + lwsl_err("%s: fail %s ret %d\n", + __func__, ipt[n].emit_test, m); + fail++; + continue; + } + + if (m > 0) { + if (strcmp(ipt[n].emit_test, buf)) { + lwsl_err("%s: fail %s compare\n", __func__, + ipt[n].test); + lwsl_hexdump_notice(buf, m); + fail++; + continue; + } + } + ok++; + } + +#if !defined(LWS_WITH_IPV6) + _exp -= 2; +#endif + + /* kick off the async dns tests */ + + lws_sul_schedule(context, 0, &sul, next_test_cb, 1); + + /* the usual lws event loop */ + + n = 1; + while (n >= 0 && !interrupted) + n = lws_service(context, 0); + + lws_context_destroy(context); + + if (fail || ok != _exp) + lwsl_user("Completed: PASS: %d / %d, FAIL: %d\n", ok, _exp, + fail); + else + lwsl_user("Completed: ALL PASS: %d / %d\n", ok, _exp); + + return !(ok == _exp && !fail); +} diff -Nru libwebsockets-3.2.1/minimal-examples/api-tests/api-test-dhcpc/CMakeLists.txt libwebsockets-4.1.6/minimal-examples/api-tests/api-test-dhcpc/CMakeLists.txt --- libwebsockets-3.2.1/minimal-examples/api-tests/api-test-dhcpc/CMakeLists.txt 1970-01-01 00:00:00.000000000 +0000 +++ libwebsockets-4.1.6/minimal-examples/api-tests/api-test-dhcpc/CMakeLists.txt 2020-12-01 17:40:26.000000000 +0000 @@ -0,0 +1,23 @@ +project(lws-api-test-dhcpc C) +cmake_minimum_required(VERSION 2.8) +find_package(libwebsockets CONFIG REQUIRED) +list(APPEND CMAKE_MODULE_PATH ${LWS_CMAKE_DIR}) +include(CheckCSourceCompiles) +include(LwsCheckRequirements) + +set(SAMP lws-api-test-dhcpc) +set(SRCS main.c) + +set(requirements 1) +require_lws_config(LWS_WITH_SYS_DHCP_CLIENT 1 requirements) + +if (requirements) + add_executable(${SAMP} ${SRCS}) + + if (websockets_shared) + target_link_libraries(${SAMP} websockets_shared ${LIBWEBSOCKETS_DEP_LIBS}) + add_dependencies(${SAMP} websockets_shared) + else() + target_link_libraries(${SAMP} websockets ${LIBWEBSOCKETS_DEP_LIBS}) + endif() +endif() diff -Nru libwebsockets-3.2.1/minimal-examples/api-tests/api-test-dhcpc/main.c libwebsockets-4.1.6/minimal-examples/api-tests/api-test-dhcpc/main.c --- libwebsockets-3.2.1/minimal-examples/api-tests/api-test-dhcpc/main.c 1970-01-01 00:00:00.000000000 +0000 +++ libwebsockets-4.1.6/minimal-examples/api-tests/api-test-dhcpc/main.c 2020-12-01 17:40:26.000000000 +0000 @@ -0,0 +1,79 @@ +/* + * lws-api-test-dhcpc + * + * Written in 2019 by Andy Green + * + * This file is made available under the Creative Commons CC0 1.0 + * Universal Public Domain Dedication. + */ + +#include +#include + +static int interrupted, ok, fail, exp = 1; +struct lws_context *context; +const char *nif; + +static int +lws_dhcpc_cb(void *opaque, int af, uint8_t *ip, int ip_len) +{ + lwsl_user("%s: dhcp set OK\n", __func__); + ok = 1; + interrupted = 1; + return 0; +} + +void sigint_handler(int sig) +{ + interrupted = 1; +} + +int +main(int argc, const char **argv) +{ + struct lws_context_creation_info info; + const char *p; + int n = 1; + + signal(SIGINT, sigint_handler); + + memset(&info, 0, sizeof info); /* otherwise uninitialized garbage */ + lws_cmdline_option_handle_builtin(argc, argv, &info); + lwsl_user("LWS API selftest: DHCP Client\n"); + + info.port = CONTEXT_PORT_NO_LISTEN; + info.options = LWS_SERVER_OPTION_DO_SSL_GLOBAL_INIT; + + if ((p = lws_cmdline_option(argc, argv, "-i"))) + nif = p; + + context = lws_create_context(&info); + if (!context) { + lwsl_err("lws init failed\n"); + return 1; + } + + if (nif) { + lwsl_user("%s: requesting DHCP for %s\n", __func__, nif); + lws_dhcpc_request(context, nif, AF_INET, lws_dhcpc_cb, NULL); + } else { + lwsl_err("%s: use -i to select if\n", __func__); + interrupted = 1; + } + + /* the usual lws event loop */ + + n = 1; + while (n >= 0 && !interrupted) + n = lws_service(context, 0); + + lws_context_destroy(context); + + if (fail || ok != exp) + lwsl_user("Completed: PASS: %d / %d, FAIL: %d\n", ok, exp, + fail); + else + lwsl_user("Completed: ALL PASS: %d / %d\n", ok, exp); + + return !(ok == exp && !fail); +} diff -Nru libwebsockets-3.2.1/minimal-examples/api-tests/api-test-dhcpc/README.md libwebsockets-4.1.6/minimal-examples/api-tests/api-test-dhcpc/README.md --- libwebsockets-3.2.1/minimal-examples/api-tests/api-test-dhcpc/README.md 1970-01-01 00:00:00.000000000 +0000 +++ libwebsockets-4.1.6/minimal-examples/api-tests/api-test-dhcpc/README.md 2020-12-01 17:40:26.000000000 +0000 @@ -0,0 +1,27 @@ +# api test dhcpc + +The application confirms it can set DHCP on the given interface + +## build + +``` + $ cmake . && make +``` + +## usage + +Commandline option|Meaning +---|--- +-d |Debug verbosity in decimal, eg, -d15 +-i |Network interface name to set by DHCP, eg, eth0 or wlo1 + +``` + $ ./lws-api-test-dhcpc -i wlo1 +[2019/10/06 14:56:41:7683] U: LWS API selftest: Async DNS +[2019/10/06 14:56:42:4461] U: main: requesting DHCP for wlo1 +[2019/10/06 14:56:42:5207] N: callback_dhcpc: DHCP configured wlo1 +[2019/10/06 14:56:42:5246] U: lws_dhcpc_cb: dhcp set OK +[2019/10/06 14:56:42:5999] U: Completed: ALL PASS: 1 / 1 +``` + + diff -Nru libwebsockets-3.2.1/minimal-examples/api-tests/api-test-fts/CMakeLists.txt libwebsockets-4.1.6/minimal-examples/api-tests/api-test-fts/CMakeLists.txt --- libwebsockets-3.2.1/minimal-examples/api-tests/api-test-fts/CMakeLists.txt 2019-12-18 14:45:31.000000000 +0000 +++ libwebsockets-4.1.6/minimal-examples/api-tests/api-test-fts/CMakeLists.txt 2020-12-01 17:40:26.000000000 +0000 @@ -1,66 +1,13 @@ +project(lws-api-test-fts C) cmake_minimum_required(VERSION 2.8) +find_package(libwebsockets CONFIG REQUIRED) +list(APPEND CMAKE_MODULE_PATH ${LWS_CMAKE_DIR}) include(CheckCSourceCompiles) +include(LwsCheckRequirements) set(SAMP lws-api-test-fts) set(SRCS main.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_WITH_FTS 1 requirements) @@ -68,9 +15,9 @@ add_executable(${SAMP} ${SRCS}) if (websockets_shared) - target_link_libraries(${SAMP} websockets_shared) + target_link_libraries(${SAMP} websockets_shared ${LIBWEBSOCKETS_DEP_LIBS}) add_dependencies(${SAMP} websockets_shared) else() - target_link_libraries(${SAMP} websockets) + target_link_libraries(${SAMP} websockets ${LIBWEBSOCKETS_DEP_LIBS}) endif() endif() diff -Nru libwebsockets-3.2.1/minimal-examples/api-tests/api-test-fts/selftest.sh libwebsockets-4.1.6/minimal-examples/api-tests/api-test-fts/selftest.sh --- libwebsockets-3.2.1/minimal-examples/api-tests/api-test-fts/selftest.sh 2019-12-18 14:45:31.000000000 +0000 +++ libwebsockets-4.1.6/minimal-examples/api-tests/api-test-fts/selftest.sh 1970-01-01 00:00:00.000000000 +0000 @@ -1,58 +0,0 @@ -#!/bin/bash -# -# $1: path to minimal example binaries... -# if lws is built with -DLWS_WITH_MINIMAL_EXAMPLES=1 -# that will be ./bin from your build dir -# -# $2: path for logs and results. The results will go -# in a subdir named after the directory this script -# is in -# -# $3: offset for test index count -# -# $4: total test count -# -# $5: path to ./minimal-examples dir in lws -# -# Test return code 0: OK, 254: timed out, other: error indication - -. $5/selftests-library.sh - -COUNT_TESTS=4 - -FAILS=0 - -# -# let's make an index with just Dorian first -# -dotest $1 $2 apitest -c -i /tmp/lws-fts-dorian.index \ - "../minimal-examples/api-tests/api-test-fts/the-picture-of-dorian-gray.txt" - -# and let's hear about autocompletes for "b" - -dotest $1 $2 apitest -i /tmp/lws-fts-dorian.index b -cat $2/api-test-fts/apitest.log | cut -d' ' -f5- > /tmp/fts1 -diff -urN /tmp/fts1 "../minimal-examples/api-tests/api-test-fts/canned-1.txt" -if [ $? -ne 0 ] ; then - echo "Test 1 failed" - FAILS=$(( $FAILS + 1 )) -fi - -# -# let's make an index with Dorian + Les Mis in French (ie, UTF-8) as well -# -dotest $1 $2 apitest -c -i /tmp/lws-fts-both.index \ - "../minimal-examples/api-tests/api-test-fts/the-picture-of-dorian-gray.txt" \ - "../minimal-examples/api-tests/api-test-fts/les-mis-utf8.txt" - -# and let's hear about "help", which appears in both - -dotest $1 $2 apitest -i /tmp/lws-fts-both.index -f -l help -cat $2/api-test-fts/apitest.log | cut -d' ' -f5- > /tmp/fts2 -diff -urN /tmp/fts2 "../minimal-examples/api-tests/api-test-fts/canned-2.txt" -if [ $? -ne 0 ] ; then - echo "Test 1 failed" - FAILS=$(( $FAILS + 1 )) -fi - -exit $FAILS diff -Nru libwebsockets-3.2.1/minimal-examples/api-tests/api-test-gencrypto/CMakeLists.txt libwebsockets-4.1.6/minimal-examples/api-tests/api-test-gencrypto/CMakeLists.txt --- libwebsockets-3.2.1/minimal-examples/api-tests/api-test-gencrypto/CMakeLists.txt 2019-12-18 14:45:31.000000000 +0000 +++ libwebsockets-4.1.6/minimal-examples/api-tests/api-test-gencrypto/CMakeLists.txt 2020-12-01 17:40:26.000000000 +0000 @@ -1,66 +1,13 @@ +project(lws-api-test-gencrypto C) cmake_minimum_required(VERSION 2.8) +find_package(libwebsockets CONFIG REQUIRED) +list(APPEND CMAKE_MODULE_PATH ${LWS_CMAKE_DIR}) include(CheckCSourceCompiles) +include(LwsCheckRequirements) set(SAMP lws-api-test-gencrypto) set(SRCS main.c lws-genaes.c lws-genec.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_WITH_GENCRYPTO 1 requirements) require_lws_config(LWS_WITH_JOSE 1 requirements) @@ -69,12 +16,13 @@ if (requirements) add_executable(${SAMP} ${SRCS}) + add_test(NAME api-test-gencrypto COMMAND lws-api-test-gencrypto) if (websockets_shared) - target_link_libraries(${SAMP} websockets_shared) + target_link_libraries(${SAMP} websockets_shared ${LIBWEBSOCKETS_DEP_LIBS}) add_dependencies(${SAMP} websockets_shared) else() - target_link_libraries(${SAMP} websockets) + target_link_libraries(${SAMP} websockets ${LIBWEBSOCKETS_DEP_LIBS}) endif() endif() diff -Nru libwebsockets-3.2.1/minimal-examples/api-tests/api-test-gencrypto/selftest.sh libwebsockets-4.1.6/minimal-examples/api-tests/api-test-gencrypto/selftest.sh --- libwebsockets-3.2.1/minimal-examples/api-tests/api-test-gencrypto/selftest.sh 2019-12-18 14:45:31.000000000 +0000 +++ libwebsockets-4.1.6/minimal-examples/api-tests/api-test-gencrypto/selftest.sh 1970-01-01 00:00:00.000000000 +0000 @@ -1,24 +0,0 @@ -#!/bin/bash -# -# $1: path to minimal example binaries... -# if lws is built with -DLWS_WITH_MINIMAL_EXAMPLES=1 -# that will be ./bin from your build dir -# -# $2: path for logs and results. The results will go -# in a subdir named after the directory this script -# is in -# -# $3: offset for test index count -# -# $4: total test count -# -# $5: path to ./minimal-examples dir in lws -# -# Test return code 0: OK, 254: timed out, other: error indication - -. $5/selftests-library.sh - -COUNT_TESTS=1 - -dotest $1 $2 apiselftest -exit $FAILS diff -Nru libwebsockets-3.2.1/minimal-examples/api-tests/api-test-jose/CMakeLists.txt libwebsockets-4.1.6/minimal-examples/api-tests/api-test-jose/CMakeLists.txt --- libwebsockets-3.2.1/minimal-examples/api-tests/api-test-jose/CMakeLists.txt 2019-12-18 14:45:31.000000000 +0000 +++ libwebsockets-4.1.6/minimal-examples/api-tests/api-test-jose/CMakeLists.txt 2020-12-01 17:40:26.000000000 +0000 @@ -1,66 +1,13 @@ +project(lws-api-test-jose C) cmake_minimum_required(VERSION 2.8) +find_package(libwebsockets CONFIG REQUIRED) +list(APPEND CMAKE_MODULE_PATH ${LWS_CMAKE_DIR}) include(CheckCSourceCompiles) +include(LwsCheckRequirements) set(SAMP lws-api-test-jose) set(SRCS main.c jwk.c jws.c jwe.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_WITH_JOSE 1 requirements) @@ -68,10 +15,14 @@ add_executable(${SAMP} ${SRCS}) + if (NOT (LWS_WITH_MBEDTLS AND NOT LWS_HAVE_mbedtls_internal_aes_encrypt)) + add_test(NAME api-test-jose COMMAND lws-api-test-jose) + endif() + if (websockets_shared) - target_link_libraries(${SAMP} websockets_shared) + target_link_libraries(${SAMP} websockets_shared ${LIBWEBSOCKETS_DEP_LIBS}) add_dependencies(${SAMP} websockets_shared) else() - target_link_libraries(${SAMP} websockets) + target_link_libraries(${SAMP} websockets ${LIBWEBSOCKETS_DEP_LIBS}) endif() endif() diff -Nru libwebsockets-3.2.1/minimal-examples/api-tests/api-test-jose/jwe.c libwebsockets-4.1.6/minimal-examples/api-tests/api-test-jose/jwe.c --- libwebsockets-3.2.1/minimal-examples/api-tests/api-test-jose/jwe.c 2019-12-18 14:45:31.000000000 +0000 +++ libwebsockets-4.1.6/minimal-examples/api-tests/api-test-jose/jwe.c 2020-12-01 17:40:26.000000000 +0000 @@ -82,7 +82,7 @@ } /* converts a compact serialization to jws b64 + decoded maps */ - if (lws_jws_compact_decode(ex_a1_compact, strlen(ex_a1_compact), + if (lws_jws_compact_decode(ex_a1_compact, (int)strlen(ex_a1_compact), &jwe.jws.map, &jwe.jws.map_b64, temp, &temp_len) != 5) { lwsl_err("%s: lws_jws_compact_decode failed\n", __func__); @@ -100,7 +100,7 @@ /* allowing for trailing padding, confirm the plaintext */ if (jwe.jws.map.len[LJWE_CTXT] < strlen(ex_a1_ptext) || lws_timingsafe_bcmp(jwe.jws.map.buf[LJWE_CTXT], ex_a1_ptext, - strlen(ex_a1_ptext))) { + (uint32_t)strlen(ex_a1_ptext))) { lwsl_err("%s: plaintext AES decrypt wrong\n", __func__); lwsl_hexdump_notice(ex_a1_ptext, strlen(ex_a1_ptext)); lwsl_hexdump_notice(jwe.jws.map.buf[LJWE_CTXT], @@ -185,7 +185,7 @@ temp_len = sizeof(temp); /* converts a compact serialization to jws b64 + decoded maps */ - if (lws_jws_compact_decode(compact, strlen(compact), &jwe.jws.map, + if (lws_jws_compact_decode(compact, (int)strlen(compact), &jwe.jws.map, &jwe.jws.map_b64, temp, &temp_len) != 5) { lwsl_err("%s: lws_jws_compact_decode failed\n", __func__); goto bail; @@ -299,7 +299,7 @@ /* converts a compact serialization to jws b64 + decoded maps */ if (lws_jws_compact_decode((const char *)ex_a2_compact, - strlen((char *)ex_a2_compact), + (int)strlen((char *)ex_a2_compact), &jwe.jws.map, &jwe.jws.map_b64, (char *)temp, &temp_len) != 5) { lwsl_err("%s: lws_jws_compact_decode failed\n", __func__); @@ -509,7 +509,9 @@ if (lws_jws_dup_element(&jwe.jws.map, LJWE_CTXT, lws_concat_temp(temp, temp_len), &temp_len, - ra_ptext_1024, sizeof(ra_ptext_1024), 0)) { + ra_ptext_1024, sizeof(ra_ptext_1024), + lws_gencrypto_padded_length(LWS_AES_CBC_BLOCKLEN, + sizeof(ra_ptext_1024)))) { lwsl_notice("%s: Not enough temp space for ptext\n", __func__); goto bail; } @@ -525,7 +527,7 @@ } jwe.jws.map.buf[LJWE_JOSE] = rsa256a128_jose; - jwe.jws.map.len[LJWE_JOSE] = strlen(rsa256a128_jose); + jwe.jws.map.len[LJWE_JOSE] = (uint32_t)strlen(rsa256a128_jose); n = lws_jwe_parse_jose(&jwe.jose, jwe.jws.map.buf[LJWE_JOSE], jwe.jws.map.len[LJWE_JOSE], @@ -632,12 +634,14 @@ /* * dup the plaintext into the ciphertext element, it will be - * encrypted in-place to a ciphertext of the same length + * encrypted in-place to a ciphertext of the same length + padding */ if (lws_jws_dup_element(&jwe.jws.map, LJWE_CTXT, lws_concat_temp(temp, temp_len), &temp_len, - ra_ptext_1024, sizeof(ra_ptext_1024), 0)) { + ra_ptext_1024, sizeof(ra_ptext_1024), + lws_gencrypto_padded_length(LWS_AES_CBC_BLOCKLEN, + sizeof(ra_ptext_1024)))) { lwsl_notice("%s: Not enough temp space for ptext\n", __func__); goto bail; } @@ -653,7 +657,7 @@ } jwe.jws.map.buf[LJWE_JOSE] = rsa256a192_jose; - jwe.jws.map.len[LJWE_JOSE] = strlen(rsa256a192_jose); + jwe.jws.map.len[LJWE_JOSE] = (uint32_t)strlen(rsa256a192_jose); n = lws_jwe_parse_jose(&jwe.jose, jwe.jws.map.buf[LJWE_JOSE], jwe.jws.map.len[LJWE_JOSE], @@ -762,12 +766,14 @@ /* * dup the plaintext into the ciphertext element, it will be - * encrypted in-place to a ciphertext of the same length + * encrypted in-place to a ciphertext of the same length + padding */ if (lws_jws_dup_element(&jwe.jws.map, LJWE_CTXT, lws_concat_temp(temp, temp_len), &temp_len, - ra_ptext_1024, sizeof(ra_ptext_1024), 0)) { + ra_ptext_1024, sizeof(ra_ptext_1024), + lws_gencrypto_padded_length(LWS_AES_CBC_BLOCKLEN, + sizeof(ra_ptext_1024)))) { lwsl_notice("%s: Not enough temp space for ptext\n", __func__); goto bail; } @@ -783,9 +789,10 @@ } jwe.jws.map.buf[LJWE_JOSE] = rsa256a256_jose; - jwe.jws.map.len[LJWE_JOSE] = strlen(rsa256a256_jose); + jwe.jws.map.len[LJWE_JOSE] = (int)strlen(rsa256a256_jose); - n = lws_jwe_parse_jose(&jwe.jose, rsa256a256_jose, strlen(rsa256a256_jose), + n = lws_jwe_parse_jose(&jwe.jose, rsa256a256_jose, + (int)strlen(rsa256a256_jose), lws_concat_temp(temp, temp_len), &temp_len); if (n < 0) { lwsl_err("%s: JOSE parse failed\n", __func__); @@ -1005,38 +1012,33 @@ */ static char *jwe_compact_rsa_cbc_openssl = - "eyAiYWxnIjoiUlNBMV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icEIMKW7sWLbcE_cDGqkHZcMGTOQKRiLp-xwyEu89oDGAcGBYpmC_f" + "iQ2qyFfe6tQK_5nPZbtW2mudiYZ-d0YIURSTp58S_n6w3wLDUEcuZtv-nhCaFVy8oUbAztkBIK6pu" + "VamKhHVLkCtOGIdNJYbLKAedhK1lQVPbrvfcSDPPkhxSx9AjKqhKA3ZPMA_UXQb6p9c33tgi_MdZX" + "-jRGXwGKWBCrv4UjttFLV-a5U7NgxQIIjwfAoutXtYardFw2d5nTJRqBrw06PSqaLzQi616_b-U0g" + "6bWxrFObIWrKODkGfQcXPXIQxW_4Vh6gR2GaHSi_A_5SGH0zsBtYxisbKXLK2HiZJOXBew4-am6c0" + "R1jBh7QtOWpwrYWt0d_xxrWtKezeEp3FkrFkwWCgY9dT1uV8tKUuxeeGqshkrXifT4axttpkbi-qA" + "eG_C6J-H29CPqScclD-A5LIg7k-KmA9hsWrXttAvoCSawNj1tv9JHq0jgP1yZytDW1DkWdCBY0au5" + "4." + "qqYQEaGx-lUHoO43fOXvKQ" ; @@ -1057,7 +1059,7 @@ /* converts a compact serialization to jws b64 + decoded maps */ if (lws_jws_compact_decode((const char *)jwe_compact_rsa_cbc_openssl, - strlen((char *)jwe_compact_rsa_cbc_openssl), + (int)strlen((char *)jwe_compact_rsa_cbc_openssl), &jwe.jws.map, &jwe.jws.map_b64, temp, &temp_len) != 5) { lwsl_err("%s: lws_jws_compact_decode failed\n", __func__); @@ -1102,7 +1104,33 @@ static char *jwe_compact_rsa_cbc_mbedtls = - "eyAiYWxnIjoiUlNBMV81IiwiZW5jIjoiQTEyOENCQy1IUzI1NiJ9.oBqKJ06UJs2oryPLWZKyI8743GC0geUt_xaKLMaPtApp__swG2w0IhNtmkIBKA9LeeGyiCWKpGGzOlQUR5YSxrT99PnincHXw_pkCprOvi4j3oxThJ2pFRx-CBc9ZgPJ3Kje1QifOueT3vQt_65iiyXmqyc5PDxzuV0L_KtrA_jEsm2m1JVBMOX--qzXjYyqx_dc87d43TX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x1zZSsetp3NEjT4DUrfmp_E_CTXhOEP0AgzpQ4Ukx5bFN3gm5gyBZw1E8" + "q20Hs01OBcMJ9wenLEQVMvO_IEIkRNBMWEgoZ148As14LNOgdh1UBrF6W4pAUjYvA3WG" + "Zp7uG9ooDB1RF2aaeBqoLJflqIegsvsfaNNBDJ-U6i_jLG1FSlttEhJVdXll0gMSYlXD" + "O3BBil4eiUPfiksfOmsbwoIxc-3yPTivU3DPM.O_IaktJRbdV66zfhD0LQmw" ; static int @@ -1122,7 +1150,7 @@ /* converts a compact serialization to jws b64 + decoded maps */ if (lws_jws_compact_decode((const char *)jwe_compact_rsa_cbc_mbedtls, - strlen((char *)jwe_compact_rsa_cbc_mbedtls), + (int)strlen((char *)jwe_compact_rsa_cbc_mbedtls), &jwe.jws.map, &jwe.jws.map_b64, temp, &temp_len) != 5) { lwsl_err("%s: lws_jws_compact_decode failed\n", __func__); @@ -1213,7 +1241,7 @@ /* converts a compact serialization to jws b64 + decoded maps */ if (lws_jws_compact_decode((const char *)ex_a3_compact, - strlen((char *)ex_a3_compact), + (int)strlen((char *)ex_a3_compact), &jwe.jws.map, &jwe.jws.map_b64, temp, &temp_len) != 5) { lwsl_err("%s: lws_jws_compact_decode failed\n", __func__); @@ -1622,7 +1650,7 @@ * See test_jwe_a3 above for a more normal usage pattern. */ - if (lws_jwe_parse_jose(&jwe.jose, ex_jwa_c_jose, strlen(ex_jwa_c_jose), + if (lws_jwe_parse_jose(&jwe.jose, ex_jwa_c_jose, (int)strlen(ex_jwa_c_jose), temp, &temp_len) < 0) { lwsl_err("%s: JOSE parse failed\n", __func__); @@ -1770,7 +1798,7 @@ jose_hdr, strlen(jose_hdr), 0)) goto bail; - if (lws_jwe_parse_jose(&jwe.jose, jose_hdr, strlen(jose_hdr), + if (lws_jwe_parse_jose(&jwe.jose, jose_hdr, (int)strlen(jose_hdr), temp, &temp_len) < 0) { lwsl_err("%s: JOSE parse failed\n", __func__); @@ -1787,13 +1815,15 @@ /* * dup the plaintext into the ciphertext element, it will be - * encrypted in-place to a ciphertext of the same length + * encrypted in-place to a ciphertext of the same length + padding */ if (lws_jws_dup_element(&jwe.jws.map, LJWE_CTXT, lws_concat_temp(temp, temp_len), &temp_len, ecdhes_t1_plaintext, - strlen(ecdhes_t1_plaintext), 0)) { + strlen(ecdhes_t1_plaintext), + lws_gencrypto_padded_length(LWS_AES_CBC_BLOCKLEN, + strlen(ecdhes_t1_plaintext)))) { lwsl_notice("%s: Not enough temp space for ptext\n", __func__); goto bail; } @@ -1844,7 +1874,7 @@ } /* converts a compact serialization to jws b64 + decoded maps */ - if (lws_jws_compact_decode(compact, strlen(compact), &jwe.jws.map, + if (lws_jws_compact_decode(compact, (int)strlen(compact), &jwe.jws.map, &jwe.jws.map_b64, temp, &temp_len) != 5) { lwsl_err("%s: lws_jws_compact_decode failed\n", __func__); goto bail; @@ -1873,24 +1903,58 @@ /* AES Key Wrap and AES_XXX_CBC_HMAC_SHA_YYY variations * - * These were created by, eg - * - * echo -n "plaintext0123456" | \ - * ./lws-crypto-jwe -e "A192KW A256CBC-HS512" -k aes192.key + * These were created using the node-jose node.js package */ - -/* "Live long and prosper." */ static const char *akw_ptext = "plaintext0123456", - *akw_ct_128_128 = "eyJhbGciOiJBMTI4S1ciLCAiZW5jIjoiQTEyOENCQy1IUzI1NiJ9.zbTfhhWePf1UrCRDxJD_-8eAQr2AoWAL51_nNOv0L4nV3P0e4_9ARA.qWehIhy4j4_gh_h5MF9ZEw.GD40YH6NeNOEkhhxC9ryZA.PEuU6V3rhYXeoxENrAzDgw", - *akw_ct_128_192 = "eyJhbGciOiJBMTI4S1ciLCAiZW5jIjoiQTE5MkNCQy1IUzM4NCJ9.zpkr45xH_kSJ5eTBv5dGo5PN_A6YdC4JoJSOw3_VTqcOeAYyCkCAXeGWugqIVLzMzBKgtXdabO8.O28MVhkgfketu5sxQK4Ffw.j25N7luxh251kQwpAoYURQ.Pm_NOj0KZzUq2fV9ARpHxT3Iach9feLK", - *akw_ct_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U81U0tHbDA3UXhIdk9YMzVqS2FJbzA2NXVLdWRubVZFZVpJYy" + "J9.SpizfgtzQLJCCnYnUmNfiMMTyL8iIDi8OyUDrO00KJtfwJdNAcs-NuYQkLKx6PlDJ" + "IGjucT4-IuA8k_Oc752kq1BzTHMZ-Mo.go-e8xpQoCmLD5RBQw7ruA.WqkEdM6T1_z5F" + "C-8eGQfGjos7cHPy1ecZk1Ep-TYgXo.bZVHhIpe2PbjguQlK_afkYDlVmEtRAe3LUJUX" + "4STOtU", *akw_key_128 = "{\"k\":\"JjVJVh8JsXvKf9qgHHWWBA\",\"kty\":\"oct\"}", *akw_key_192 = "{\"k\":\"BYF6urCMDRMKFXXRxXrDSVtW71AUZghj\",\"kty\":\"oct\"}", *akw_key_256 = "{\"k\":\"cSHyZXGEfnlgKud21cM6tAxRyXnK6xbWRTsyLUegTMk\",\"kty\":\"oct\"}" @@ -1912,7 +1976,7 @@ } /* converts a compact serialization to jws b64 + decoded maps */ - if (lws_jws_compact_decode(ciphertext, strlen(ciphertext), + if (lws_jws_compact_decode(ciphertext, (int)strlen(ciphertext), &jwe.jws.map, &jwe.jws.map_b64, temp, &temp_len) != 5) { lwsl_err("%s: lws_jws_compact_decode failed\n", __func__); @@ -1929,7 +1993,7 @@ /* allowing for trailing padding, confirm the plaintext */ if (jwe.jws.map.len[LJWE_CTXT] < strlen(akw_ptext) || lws_timingsafe_bcmp(jwe.jws.map.buf[LJWE_CTXT], akw_ptext, - strlen(akw_ptext))) { + (int)strlen(akw_ptext))) { lwsl_err("%s: plaintext AES decrypt wrong\n", __func__); lwsl_hexdump_notice(akw_ptext, strlen(akw_ptext)); lwsl_hexdump_notice(jwe.jws.map.buf[LJWE_CTXT], @@ -1984,12 +2048,14 @@ /* * dup the plaintext into the ciphertext element, it will be - * encrypted in-place to a ciphertext of the same length + * encrypted in-place to a ciphertext of the same length + padding */ if (lws_jws_dup_element(&jwe.jws.map, LJWE_CTXT, lws_concat_temp(temp, temp_len), &temp_len, - akw_ptext, strlen(akw_ptext), 0)) { + akw_ptext, strlen(akw_ptext), + lws_gencrypto_padded_length(LWS_AES_CBC_BLOCKLEN, + strlen(akw_ptext)))) { lwsl_notice("%s: Not enough temp space for ptext\n", __func__); goto bail; } @@ -2076,7 +2142,7 @@ lws_jwe_init(&jwe, context); - if (lws_jwe_parse_jose(&jwe.jose, complete, strlen(complete), + if (lws_jwe_parse_jose(&jwe.jose, complete, (int)strlen(complete), temp, &temp_len) < 0) { lwsl_err("%s: JOSE parse failed\n", __func__); @@ -2134,29 +2200,29 @@ n |= test_jwe_a2(context); n |= test_jwe_ra_ptext_1024(context, (char *)lws_jwe_ex_a2_jwk_json, - strlen((char *)lws_jwe_ex_a2_jwk_json)); + (int)strlen((char *)lws_jwe_ex_a2_jwk_json)); n |= test_jwe_r256a192_ptext(context, (char *)lws_jwe_ex_a2_jwk_json, - strlen((char *)lws_jwe_ex_a2_jwk_json)); + (int)strlen((char *)lws_jwe_ex_a2_jwk_json)); n |= test_jwe_r256a256_ptext(context, (char *)lws_jwe_ex_a2_jwk_json, - strlen((char *)lws_jwe_ex_a2_jwk_json)); + (int)strlen((char *)lws_jwe_ex_a2_jwk_json)); n |= test_jwe_ra_ptext_1024(context, (char *)rsa_key_2048, - strlen((char *)rsa_key_2048)); + (int)strlen((char *)rsa_key_2048)); n |= test_jwe_r256a192_ptext(context, (char *)rsa_key_2048, - strlen((char *)rsa_key_2048)); + (int)strlen((char *)rsa_key_2048)); n |= test_jwe_r256a256_ptext(context, (char *)rsa_key_2048, - strlen((char *)rsa_key_2048)); + (int)strlen((char *)rsa_key_2048)); n |= test_jwe_ra_ptext_1024(context, (char *)rsa_key_4096, - strlen((char *)rsa_key_4096)); + (int)strlen((char *)rsa_key_4096)); n |= test_jwe_r256a192_ptext(context, (char *)rsa_key_4096, - strlen((char *)rsa_key_4096)); + (int)strlen((char *)rsa_key_4096)); n |= test_jwe_r256a256_ptext(context, (char *)rsa_key_4096, - strlen((char *)rsa_key_4096)); + (int)strlen((char *)rsa_key_4096)); n |= test_jwe_ra_ptext_1024(context, (char *)rsa_key_4096_no_optional, - strlen((char *)rsa_key_4096_no_optional)); + (int)strlen((char *)rsa_key_4096_no_optional)); n |= test_jwe_r256a192_ptext(context, (char *)rsa_key_4096_no_optional, - strlen((char *)rsa_key_4096_no_optional)); + (int)strlen((char *)rsa_key_4096_no_optional)); n |= test_jwe_r256a256_ptext(context, (char *)rsa_key_4096_no_optional, - strlen((char *)rsa_key_4096_no_optional)); + (int)strlen((char *)rsa_key_4096_no_optional)); /* AESKW decrypt all variations */ diff -Nru libwebsockets-3.2.1/minimal-examples/api-tests/api-test-jose/jws.c libwebsockets-4.1.6/minimal-examples/api-tests/api-test-jose/jws.c --- libwebsockets-3.2.1/minimal-examples/api-tests/api-test-jose/jws.c 2019-12-18 14:45:31.000000000 +0000 +++ libwebsockets-4.1.6/minimal-examples/api-tests/api-test-jose/jws.c 2020-12-01 17:40:26.000000000 +0000 @@ -46,7 +46,7 @@ /* A.5 Unsecured JSON "none" RFC7515 worked example */ /* decode the b64.b64[.b64] compact serialization blocks */ - n = lws_jws_compact_decode(none_cser, strlen(none_cser), &map, NULL, + n = lws_jws_compact_decode(none_cser, (int)strlen(none_cser), &map, NULL, temp, &temp_len); if (n != 2) { lwsl_err("%s: concat_map failed\n", __func__); @@ -131,8 +131,8 @@ /* parse the JOSE header */ - if (lws_jws_parse_jose(&jose, test1, strlen(test1), temp, &temp_len) < 0 || - !jose.alg) { + if (lws_jws_parse_jose(&jose, test1, (int)strlen(test1), temp, + &temp_len) < 0 || !jose.alg) { lwsl_err("%s: JOSE parse failed\n", __func__); goto bail; } @@ -314,7 +314,7 @@ goto bail; } - if (lws_jws_b64_compact_map(rfc7515_rsa_a1, strlen(rfc7515_rsa_a1), + if (lws_jws_b64_compact_map(rfc7515_rsa_a1, (int)strlen(rfc7515_rsa_a1), &jws.map_b64) != 3) { lwsl_notice("%s: lws_jws_b64_compact_map failed\n", __func__); goto bail; @@ -323,7 +323,7 @@ /* 2.3: generate our own signature for a copy of the test packet */ in = lws_concat_temp(temp, temp_len); - l = strlen(rfc7515_rsa_a1); + l = (int)strlen(rfc7515_rsa_a1); if (temp_len < l + 1) goto bail; memcpy(in, rfc7515_rsa_a1, l + 1); @@ -421,7 +421,7 @@ lws_jose_init(&jose); /* decode the b64.b64[.b64] compact serialization blocks */ - if (lws_jws_compact_decode(es256_cser, strlen(es256_cser), + if (lws_jws_compact_decode(es256_cser, (int)strlen(es256_cser), &jws.map, &jws.map_b64, temp, &temp_len) != 3) { lwsl_err("%s: concat_map failed\n", __func__); @@ -481,7 +481,7 @@ /* A.3 "ES256" RFC7515 worked example - sign */ - l = strlen(es256_cser); + l = (int)strlen(es256_cser); if (temp_len < l + 1) goto bail1; p = lws_concat_temp(temp, temp_len); @@ -582,7 +582,7 @@ lws_jose_init(&jose); /* decode the b64.b64[.b64] compact serialization blocks */ - if (lws_jws_compact_decode(es512_cser, strlen(es512_cser), + if (lws_jws_compact_decode(es512_cser, (int)strlen(es512_cser), &jws.map, &jws.map_b64, temp, &temp_len) != 3) { lwsl_err("%s: concat_map failed\n", __func__); @@ -642,7 +642,7 @@ /* A.3 "es512" RFC7515 worked example - sign */ - l = strlen(es512_cser); + l = (int)strlen(es512_cser); if (temp_len < l) goto bail1; p = lws_concat_temp(temp, temp_len); @@ -685,6 +685,43 @@ goto bail1; } + /* jwt test */ + + { + unsigned long long ull = lws_now_secs(); + char buf[8192]; + size_t cml = 2048, cml2 = 2048; + + if (lws_jwt_sign_compact(context, &jwk, "ES512", + (char *)buf, &cml2, + (char *)buf + 2048, 4096, + "{\"iss\":\"warmcat.com\",\"aud\":" + "\"https://libwebsockets.org/sai\"," + "\"iat\":%llu," + "\"nbf\":%llu," + "\"exp\":%llu," + "\"sub\":\"manage\"}", ull, + ull - 60, ull + (30 * 24 * 3600) + )) { + lwsl_err("%s: failed to create JWT\n", __func__); + goto bail1; + } + + lwsl_notice("%s: jwt test '%s'\n", __func__, buf); + + if (lws_jwt_signed_validate(context, &jwk, "ES512", + (const char *)buf, cml2, + (char *)buf + 2048, 2048, + (char *)buf + 4096, &cml)) { + lwsl_err("%s: failed to parse JWT\n", __func__); + + goto bail1; + } + + lwsl_notice("%s: jwt valid, payload '%s'\n", + __func__, buf + 4096); + } + /* end */ ret = 0; diff -Nru libwebsockets-3.2.1/minimal-examples/api-tests/api-test-jose/selftest.sh libwebsockets-4.1.6/minimal-examples/api-tests/api-test-jose/selftest.sh --- libwebsockets-3.2.1/minimal-examples/api-tests/api-test-jose/selftest.sh 2019-12-18 14:45:31.000000000 +0000 +++ libwebsockets-4.1.6/minimal-examples/api-tests/api-test-jose/selftest.sh 1970-01-01 00:00:00.000000000 +0000 @@ -1,24 +0,0 @@ -#!/bin/bash -# -# $1: path to minimal example binaries... -# if lws is built with -DLWS_WITH_MINIMAL_EXAMPLES=1 -# that will be ./bin from your build dir -# -# $2: path for logs and results. The results will go -# in a subdir named after the directory this script -# is in -# -# $3: offset for test index count -# -# $4: total test count -# -# $5: path to ./minimal-examples dir in lws -# -# Test return code 0: OK, 254: timed out, other: error indication - -. $5/selftests-library.sh - -COUNT_TESTS=1 - -dotest $1 $2 apiselftest -exit $FAILS diff -Nru libwebsockets-3.2.1/minimal-examples/api-tests/api-test-lejp/CMakeLists.txt libwebsockets-4.1.6/minimal-examples/api-tests/api-test-lejp/CMakeLists.txt --- libwebsockets-3.2.1/minimal-examples/api-tests/api-test-lejp/CMakeLists.txt 1970-01-01 00:00:00.000000000 +0000 +++ libwebsockets-4.1.6/minimal-examples/api-tests/api-test-lejp/CMakeLists.txt 2020-12-01 17:40:26.000000000 +0000 @@ -0,0 +1,22 @@ +project(lws-api-test-lejp C) +cmake_minimum_required(VERSION 2.8) +find_package(libwebsockets CONFIG REQUIRED) +list(APPEND CMAKE_MODULE_PATH ${LWS_CMAKE_DIR}) +include(CheckCSourceCompiles) +include(LwsCheckRequirements) + +set(requirements 1) +require_lws_config(LWS_WITH_LEJP 1 requirements) + +if (requirements) + + add_executable(${PROJECT_NAME} main.c) + add_test(NAME api-test-lejp COMMAND lws-api-test-lejp) + + if (websockets_shared) + target_link_libraries(${PROJECT_NAME} websockets_shared ${LIBWEBSOCKETS_DEP_LIBS}) + add_dependencies(${PROJECT_NAME} websockets_shared) + else() + target_link_libraries(${PROJECT_NAME} websockets ${LIBWEBSOCKETS_DEP_LIBS}) + endif() +endif() diff -Nru libwebsockets-3.2.1/minimal-examples/api-tests/api-test-lejp/main.c libwebsockets-4.1.6/minimal-examples/api-tests/api-test-lejp/main.c --- libwebsockets-3.2.1/minimal-examples/api-tests/api-test-lejp/main.c 1970-01-01 00:00:00.000000000 +0000 +++ libwebsockets-4.1.6/minimal-examples/api-tests/api-test-lejp/main.c 2020-12-01 17:40:26.000000000 +0000 @@ -0,0 +1,219 @@ +/* + * lws-api-test-lejp + * + * Written in 2010-2020 by Andy Green + * + * This file is made available under the Creative Commons CC0 1.0 + * Universal Public Domain Dedication. + * + * sanity tests for lejp + */ + +#include + +/* + * in this example, the JSON is for one "builder" object, which may specify + * a child list "targets" of zero or more "target" objects. + */ + +static const char * const json_tests[] = { + "{" /* test 1 */ + "\"schema\":\"com-warmcat-sai-builder\"," + + "\"hostname\":\"learn\"," + "\"nspawn_timeout\":1800," + "\"targets\":[" + "{" + "\"name\":\"target1\"," + "\"someflag\":true" + "}," + "{" + "\"name\":\"target2\"," + "\"someflag\":false" + "}" + "]" + "}", + "{" /* test 2 */ + "\"schema\":\"com-warmcat-sai-builder\"," + + "\"hostname\":\"learn\"," + "\"targets\":[" + "{" + "\"name\":\"target1\"" + "}," + "{" + "\"name\":\"target2\"" + "}," + "{" + "\"name\":\"target3\"" + "}" + "]" + "}", "{" /* test 3 */ + "\"schema\":\"com-warmcat-sai-builder\"," + + "\"hostname\":\"learn\"," + "\"nspawn_timeout\":1800," + "\"targets\":[" + "{" + "\"name\":\"target1\"," + "\"unrecognized\":\"xyz\"," + "\"child\": {" + "\"somename\": \"abc\"," + "\"junk\": { \"x\": \"y\" }" + "}" + "}," + "{" + "\"name\":\"target2\"" + "}" + "]" + "}", + "{" /* test 4 */ + "\"schema\":\"com-warmcat-sai-builder\"," + + "\"hostname\":\"learn\"," + "\"nspawn_timeout\":1800" + "}", + "{" /* test 5 */ + "\"schema\":\"com-warmcat-sai-builder\"" + "}", + "{" /* test 6 ... check huge strings into smaller fixed char array */ + "\"schema\":\"com-warmcat-sai-builder\"," + "\"hostname\":\"" + "PYvtan6kqppjnS0KpYTCaiOLsJkc7XecAr1kcE0aCIciewYB+JcLG82mO1Vb1mJtjDwUjBxy2I6A" + "zefzoWUWmqZbsv4MXR55j9bKlyz1liiSX63iO0x6JAwACMtE2MkgcLwR86TSWAD9D1QKIWqg5RJ/" + "CRuVsW0DKAUMD52ql4JmPFuJpJgTq28z6PhYNzN3yI3bmQt6bzhA+A/xAsFzSBnb3MHYWzGMprr5" + "3FAP1ISo5Ec9i+2ehV40sG6Q470sH3PGQZ0YRPO7Sh/SyrSQ/scONmxRc3AcXl7X/CSs417ii+CV" + "8sq3ZgcxKNB7tNfN7idNx3upZ00G2BZy9jSy03cLKKLNaNUt0TQsxXbH55uDHzSEeZWvxJgT6zB1" + "NoMhdC02w+oXim94M6z6COCnqT3rgkGk8PHMry9Bkh4yVpRmzIRfMmln/lEhdZgxky2+g5hhlSIG" + "JYDCrdynD9kCfvfy6KGOpNIi1X+mhbbWn4lnL9ZKihL/RrfOV+oV4R26IDq+KqUiJBENeo8/GXkG" + "LUH/87iPyzXKEMavr6fkrK0vTGto8yEYxmOyaVz8phG5rwf4jJgmYNoMbGo8gWvhqO7UAGy2g7MW" + "v+B/t1eZZ+1euLsNrWAsFJiFbQKgdFfQT3RjB14iU8knlQ8usoy+pXssY2ddGJGVcGC21oZvstK9" + "eu1eRZftda/wP+N5unT1Hw7kCoVzqxHieiYt47EGIOaaQ7XjZDK6qPN6O/grHnvJZm2vBkxuXgsY" + "VkRQ7AuTWIecphqFsq7Wbc1YNbMW47SVU5zMD0WaCqbaaI0t4uIzRvPlD8cpiiTzFTrEHlIBTf8/" + "uZjjEGGLhJR1jPqA9D1Ej3ChV+ye6F9JTUMlozRMsGuF8U4btDzH5xdnmvRS4Ar6LKEtAXGkj2yu" + "yJln+v4RIWj2xOGPJovOqiXwi0FyM61f8U8gj0OiNA2/QlvrqQVDF7sMXgjvaE7iQt5vMETteZlx" + "+z3f+jTFM/aon511W4+ZkRD+6AHwucvM9BEC\"" + "}", + "{" /* test 7 ... check huge strings into char * */ + "\"schema\":\"com-warmcat-sai-builder\"," + "\"targets\":[" + "{" + "\"name\":\"" + "PYvtan6kqppjnS0KpYTCaiOLsJkc7XecAr1kcE0aCIciewYB+JcLG82mO1Vb1mJtjDwUjBxy2I6A" + "zefzoWUWmqZbsv4MXR55j9bKlyz1liiSX63iO0x6JAwACMtE2MkgcLwR86TSWAD9D1QKIWqg5RJ/" + "CRuVsW0DKAUMD52ql4JmPFuJpJgTq28z6PhYNzN3yI3bmQt6bzhA+A/xAsFzSBnb3MHYWzGMprr5" + "3FAP1ISo5Ec9i+2ehV40sG6Q470sH3PGQZ0YRPO7Sh/SyrSQ/scONmxRc3AcXl7X/CSs417ii+CV" + "8sq3ZgcxKNB7tNfN7idNx3upZ00G2BZy9jSy03cLKKLNaNUt0TQsxXbH55uDHzSEeZWvxJgT6zB1" + "NoMhdC02w+oXim94M6z6COCnqT3rgkGk8PHMry9Bkh4yVpRmzIRfMmln/lEhdZgxky2+g5hhlSIG" + "JYDCrdynD9kCfvfy6KGOpNIi1X+mhbbWn4lnL9ZKihL/RrfOV+oV4R26IDq+KqUiJBENeo8/GXkG" + "LUH/87iPyzXKEMavr6fkrK0vTGto8yEYxmOyaVz8phG5rwf4jJgmYNoMbGo8gWvhqO7UAGy2g7MW" + "v+B/t1eZZ+1euLsNrWAsFJiFbQKgdFfQT3RjB14iU8knlQ8usoy+pXssY2ddGJGVcGC21oZvstK9" + "eu1eRZftda/wP+N5unT1Hw7kCoVzqxHieiYt47EGIOaaQ7XjZDK6qPN6O/grHnvJZm2vBkxuXgsY" + "VkRQ7AuTWIecphqFsq7Wbc1YNbMW47SVU5zMD0WaCqbaaI0t4uIzRvPlD8cpiiTzFTrEHlIBTf8/" + "uZjjEGGLhJR1jPqA9D1Ej3ChV+ye6F9JTUMlozRMsGuF8U4btDzH5xdnmvRS4Ar6LKEtAXGkj2yu" + "yJln+v4RIWj2xOGPJovOqiXwi0FyM61f8U8gj0OiNA2/QlvrqQVDF7sMXgjvaE7iQt5vMETteZlx" + "+z3f+jTFM/aon511W4+ZkRD+6AHwucvM9BEC\"}]}" + "}", + "{" /* test 8 the "other" schema */ + "\"schema\":\"com-warmcat-sai-logs\"," + "\"task_uuid\":\"97fc90052506af8b3eb43b87aaa6fb76feab32bc128ede479a8a6b961e801f06\"," + "\"timestamp\": 170366786103,\"channel\":3, \"len\":20, " + "\"log\": \"PnNhaWI+IE5TU1RBVEVfSU5JVAo=\"}\x0a" + "ntu-xenial-amd64\"},{\"name\":\"linux-ubuntu-bionic-amd64\"},{\"name\":\"linux-fedora-32-x86_64\"}]}\",", + + "{" /* test 9, empty object */ + "\"a\":123,\"b\":{}" + "}", + + "{" /* SHOULD_FAIL: test 10, missing open */ + "\"a\":123,\"b\":}" + "}" +}; + +static const char * const tok[] = { + "something", +}; + +static signed char +test_cb(struct lejp_ctx *ctx, char reason) +{ + lwsl_info("%s: ctx->path %s, buf %s\n", __func__, ctx->path, ctx->buf); + return 0; +} + +/* authz JSON parsing */ + + +int main(int argc, const char **argv) +{ + int n, m, e = 0, logs = LLL_USER | LLL_ERR | LLL_WARN | LLL_NOTICE; + struct lejp_ctx ctx; + const char *p; + + if ((p = lws_cmdline_option(argc, argv, "-d"))) + logs = atoi(p); + + lws_set_log_level(logs, NULL); + lwsl_user("LWS API selftest: lws_struct JSON\n"); + + for (m = 0; m < (int)LWS_ARRAY_SIZE(json_tests); m++) { + + lwsl_info("%s: ++++++++++++++++ test %d\n", __func__, m + 1); + + lejp_construct(&ctx, test_cb, NULL, tok, LWS_ARRAY_SIZE(tok)); + + lwsl_hexdump_info(json_tests[m], strlen(json_tests[m])); + + if (m == 7) + n = lejp_parse(&ctx, (uint8_t *)json_tests[m], + 0xc8); + else + n = lejp_parse(&ctx, (uint8_t *)json_tests[m], + (int)strlen(json_tests[m])); + + lwsl_info("n = %d\n", n); + if (n < 0 && m != 9) { + lwsl_err("%s: test %d: JSON decode failed '%s'\n", + __func__, m + 1, lejp_error_to_string(n)); + e++; + } + if (n >= 0 && m == 9) { + lwsl_err("%s: test %d: JSON decode should have failed '%s'\n", + __func__, m + 1, lejp_error_to_string(n)); + e++; + } + } + + { + const char *cs; + size_t cslen; + cs = lws_json_simple_find("{\"blah\":123,\"ext\":{\"authorized\":1}}", 35, + "\"ext\":", &cslen); + if (!cs) { + lwsl_err("%s: simple_find failed\n", __func__); + e++; + } else { + if (lws_json_simple_strcmp(cs, cslen, + "\"authorized\":", "1")) + e++; + } + cs = lws_json_simple_find("{\"blah\":123,\"auth_user\":\"andy@warmcat.com\",\"thing\":\"yeah\"}", 57, + "\"auth_user\":", &cslen); + if (cslen != 16) { + lwsl_err("%s: wrong string len %d isolated\n", __func__, (int)cslen); + e++; + } + } + + if (e) + goto bail; + + lwsl_user("Completed: PASS\n"); + + return 0; + +bail: + lwsl_user("Completed: FAIL\n"); + + return 1; +} diff -Nru libwebsockets-3.2.1/minimal-examples/api-tests/api-test-lwsac/CMakeLists.txt libwebsockets-4.1.6/minimal-examples/api-tests/api-test-lwsac/CMakeLists.txt --- libwebsockets-3.2.1/minimal-examples/api-tests/api-test-lwsac/CMakeLists.txt 2019-12-18 14:45:31.000000000 +0000 +++ libwebsockets-4.1.6/minimal-examples/api-tests/api-test-lwsac/CMakeLists.txt 2020-12-01 17:40:26.000000000 +0000 @@ -1,73 +1,19 @@ +project(lws-api-test-lwsac C) cmake_minimum_required(VERSION 2.8) +find_package(libwebsockets CONFIG REQUIRED) +list(APPEND CMAKE_MODULE_PATH ${LWS_CMAKE_DIR}) include(CheckCSourceCompiles) +include(LwsCheckRequirements) set(SAMP lws-api-test-lwsac) set(SRCS main.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) +add_executable(${SAMP} ${SRCS}) +add_test(NAME api-test-lwsac COMMAND lws-api-test-lwsac) - 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() - - - - 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() +if (websockets_shared) + target_link_libraries(${SAMP} websockets_shared ${LIBWEBSOCKETS_DEP_LIBS}) + add_dependencies(${SAMP} websockets_shared) +else() + target_link_libraries(${SAMP} websockets ${LIBWEBSOCKETS_DEP_LIBS}) +endif() diff -Nru libwebsockets-3.2.1/minimal-examples/api-tests/api-test-lwsac/selftest.sh libwebsockets-4.1.6/minimal-examples/api-tests/api-test-lwsac/selftest.sh --- libwebsockets-3.2.1/minimal-examples/api-tests/api-test-lwsac/selftest.sh 2019-12-18 14:45:31.000000000 +0000 +++ libwebsockets-4.1.6/minimal-examples/api-tests/api-test-lwsac/selftest.sh 1970-01-01 00:00:00.000000000 +0000 @@ -1,24 +0,0 @@ -#!/bin/bash -# -# $1: path to minimal example binaries... -# if lws is built with -DLWS_WITH_MINIMAL_EXAMPLES=1 -# that will be ./bin from your build dir -# -# $2: path for logs and results. The results will go -# in a subdir named after the directory this script -# is in -# -# $3: offset for test index count -# -# $4: total test count -# -# $5: path to ./minimal-examples dir in lws -# -# Test return code 0: OK, 254: timed out, other: error indication - -. $5/selftests-library.sh - -COUNT_TESTS=1 - -dotest $1 $2 apiselftest -exit $FAILS diff -Nru libwebsockets-3.2.1/minimal-examples/api-tests/api-test-lws_dsh/CMakeLists.txt libwebsockets-4.1.6/minimal-examples/api-tests/api-test-lws_dsh/CMakeLists.txt --- libwebsockets-3.2.1/minimal-examples/api-tests/api-test-lws_dsh/CMakeLists.txt 2019-12-18 14:45:31.000000000 +0000 +++ libwebsockets-4.1.6/minimal-examples/api-tests/api-test-lws_dsh/CMakeLists.txt 2020-12-01 17:40:26.000000000 +0000 @@ -1,66 +1,13 @@ +project(lws-api-test-lws_dsh C) cmake_minimum_required(VERSION 2.8) +find_package(libwebsockets CONFIG REQUIRED) +list(APPEND CMAKE_MODULE_PATH ${LWS_CMAKE_DIR}) include(CheckCSourceCompiles) +include(LwsCheckRequirements) set(SAMP lws-api-test-lws_dsh) set(SRCS main.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_WITH_NETWORK 1 requirements) require_lws_config(LWS_WITH_LWS_DSH 1 requirements) @@ -68,11 +15,12 @@ if (requirements) add_executable(${SAMP} ${SRCS}) + add_test(NAME api-test-lws_dsh COMMAND lws-api-test-lws_dsh) if (websockets_shared) - target_link_libraries(${SAMP} websockets_shared) + target_link_libraries(${SAMP} websockets_shared ${LIBWEBSOCKETS_DEP_LIBS}) add_dependencies(${SAMP} websockets_shared) else() - target_link_libraries(${SAMP} websockets) + target_link_libraries(${SAMP} websockets ${LIBWEBSOCKETS_DEP_LIBS}) endif() endif() diff -Nru libwebsockets-3.2.1/minimal-examples/api-tests/api-test-lws_dsh/main.c libwebsockets-4.1.6/minimal-examples/api-tests/api-test-lws_dsh/main.c --- libwebsockets-3.2.1/minimal-examples/api-tests/api-test-lws_dsh/main.c 2019-12-18 14:45:31.000000000 +0000 +++ libwebsockets-4.1.6/minimal-examples/api-tests/api-test-lws_dsh/main.c 2020-12-01 17:40:26.000000000 +0000 @@ -12,7 +12,7 @@ int test1(void) { - lws_dsh_t *dsh; + struct lws_dsh *dsh; size_t size; void *a1; @@ -94,7 +94,7 @@ int test2(void) { - lws_dsh_t *dsh, *dsh2; + struct lws_dsh *dsh, *dsh2; lws_dll2_owner_t owner; uint8_t blob[4096]; @@ -114,7 +114,7 @@ } dsh2 = lws_dsh_create(&owner, 4096, 2); - if (!dsh) { + if (!dsh2) { lwsl_err("%s: Failed to create dsh2\n", __func__); goto bail; @@ -173,7 +173,7 @@ int test3(void) { - lws_dsh_t *dsh, *dsh2; + struct lws_dsh *dsh, *dsh2; lws_dll2_owner_t owner; uint8_t blob[4096]; @@ -193,7 +193,7 @@ } dsh2 = lws_dsh_create(&owner, 4096, 2); - if (!dsh) { + if (!dsh2) { lwsl_err("%s: Failed to create dsh2\n", __func__); goto bail; @@ -245,7 +245,7 @@ test4(void) { uint8_t blob[4096]; - lws_dsh_t *dsh; + struct lws_dsh *dsh; size_t size; void *a1; diff -Nru libwebsockets-3.2.1/minimal-examples/api-tests/api-test-lws_dsh/selftest.sh libwebsockets-4.1.6/minimal-examples/api-tests/api-test-lws_dsh/selftest.sh --- libwebsockets-3.2.1/minimal-examples/api-tests/api-test-lws_dsh/selftest.sh 2019-12-18 14:45:31.000000000 +0000 +++ libwebsockets-4.1.6/minimal-examples/api-tests/api-test-lws_dsh/selftest.sh 1970-01-01 00:00:00.000000000 +0000 @@ -1,24 +0,0 @@ -#!/bin/bash -# -# $1: path to minimal example binaries... -# if lws is built with -DLWS_WITH_MINIMAL_EXAMPLES=1 -# that will be ./bin from your build dir -# -# $2: path for logs and results. The results will go -# in a subdir named after the directory this script -# is in -# -# $3: offset for test index count -# -# $4: total test count -# -# $5: path to ./minimal-examples dir in lws -# -# Test return code 0: OK, 254: timed out, other: error indication - -. $5/selftests-library.sh - -COUNT_TESTS=1 - -dotest $1 $2 apiselftest -exit $FAILS diff -Nru libwebsockets-3.2.1/minimal-examples/api-tests/api-test-lws_sequencer/CMakeLists.txt libwebsockets-4.1.6/minimal-examples/api-tests/api-test-lws_sequencer/CMakeLists.txt --- libwebsockets-3.2.1/minimal-examples/api-tests/api-test-lws_sequencer/CMakeLists.txt 2019-12-18 14:45:31.000000000 +0000 +++ libwebsockets-4.1.6/minimal-examples/api-tests/api-test-lws_sequencer/CMakeLists.txt 2020-12-01 17:40:26.000000000 +0000 @@ -1,78 +1,25 @@ +project(lws-api-test-lws_sequencer C) cmake_minimum_required(VERSION 2.8) +find_package(libwebsockets CONFIG REQUIRED) +list(APPEND CMAKE_MODULE_PATH ${LWS_CMAKE_DIR}) include(CheckCSourceCompiles) +include(LwsCheckRequirements) set(SAMP lws-api-test-lws_sequencer) set(SRCS main.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_ROLE_H1 1 requirements) -require_lws_config(LWS_WITHOUT_CLIENT 0 requirements) +require_lws_config(LWS_WITH_CLIENT 1 requirements) require_lws_config(LWS_WITH_SEQUENCER 1 requirements) if (requirements) add_executable(${SAMP} ${SRCS}) if (websockets_shared) - target_link_libraries(${SAMP} websockets_shared) + target_link_libraries(${SAMP} websockets_shared ${LIBWEBSOCKETS_DEP_LIBS}) add_dependencies(${SAMP} websockets_shared) else() - target_link_libraries(${SAMP} websockets) + target_link_libraries(${SAMP} websockets ${LIBWEBSOCKETS_DEP_LIBS}) endif() endif() diff -Nru libwebsockets-3.2.1/minimal-examples/api-tests/api-test-lws_sequencer/libwebsockets.org.cer libwebsockets-4.1.6/minimal-examples/api-tests/api-test-lws_sequencer/libwebsockets.org.cer --- libwebsockets-3.2.1/minimal-examples/api-tests/api-test-lws_sequencer/libwebsockets.org.cer 2019-12-18 14:45:31.000000000 +0000 +++ libwebsockets-4.1.6/minimal-examples/api-tests/api-test-lws_sequencer/libwebsockets.org.cer 2020-12-01 17:40:26.000000000 +0000 @@ -56,3 +56,24 @@ PfZ+G6Z6h7mjem0Y+iWlkYcV4PIWL1iwBi8saCbGS5jN2p8M+X+Q7UNKEkROb3N6 KOqkqm57TH2H3eDJAkSnh6/DNFu0Qg== -----END CERTIFICATE----- + -----BEGIN CERTIFICATE----- +MIIDSjCCAjKgAwIBAgIQRK+wgNajJ7qJMDmGLvhAazANBgkqhkiG9w0BAQUFADA/ +MSQwIgYDVQQKExtEaWdpdGFsIFNpZ25hdHVyZSBUcnVzdCBDby4xFzAVBgNVBAMT +DkRTVCBSb290IENBIFgzMB4XDTAwMDkzMDIxMTIxOVoXDTIxMDkzMDE0MDExNVow +PzEkMCIGA1UEChMbRGlnaXRhbCBTaWduYXR1cmUgVHJ1c3QgQ28uMRcwFQYDVQQD +Ew5EU1QgUm9vdCBDQSBYMzCCASIwDQYJKoZIhvcNAQEBBQADggEPADCCAQoCggEB +AN+v6ZdQCINXtMxiZfaQguzH0yxrMMpb7NnDfcdAwRgUi+DoM3ZJKuM/IUmTrE4O +rz5Iy2Xu/NMhD2XSKtkyj4zl93ewEnu1lcCJo6m67XMuegwGMoOifooUMM0RoOEq +OLl5CjH9UL2AZd+3UWODyOKIYepLYYHsUmu5ouJLGiifSKOeDNoJjj4XLh7dIN9b +xiqKqy69cK3FCxolkHRyxXtqqzTWMIn/5WgTe1QLyNau7Fqckh49ZLOMxt+/yUFw +7BZy1SbsOFU5Q9D8/RhcQPGX69Wam40dutolucbY38EVAjqr2m7xPi71XAicPNaD +aeQQmxkqtilX4+U9m5/wAl0CAwEAAaNCMEAwDwYDVR0TAQH/BAUwAwEB/zAOBgNV +HQ8BAf8EBAMCAQYwHQYDVR0OBBYEFMSnsaR7LHH62+FLkHX/xBVghYkQMA0GCSqG +SIb3DQEBBQUAA4IBAQCjGiybFwBcqR7uKGY3Or+Dxz9LwwmglSBd49lZRNI+DT69 +ikugdB/OEIKcdBodfpga3csTS7MgROSR6cz8faXbauX+5v3gTt23ADq1cEmv8uXr +AvHRAosZy5Q6XkjEGB5YGV8eAlrwDPGxrancWYaLbumR9YbK+rlmM6pZW87ipxZz +R8srzJmwN0jP41ZL9c8PDHIyh8bwRLtTcm1D9SZImlJnt1ir/md2cXjbDaJWFBM5 +JDGFoqgCWjBH4d1QB7wCCZAA62RjYJsWvIjJEubSfZGL+T0yjWW06XyxV3bqxbYo +Ob8VZRzI9neWagqNdwvYkQsEjgfbKbYK7p2CNTUQ +-----END CERTIFICATE----- + diff -Nru libwebsockets-3.2.1/minimal-examples/api-tests/api-test-lws_sequencer/main.c libwebsockets-4.1.6/minimal-examples/api-tests/api-test-lws_sequencer/main.c --- libwebsockets-3.2.1/minimal-examples/api-tests/api-test-lws_sequencer/main.c 2019-12-18 14:45:31.000000000 +0000 +++ libwebsockets-4.1.6/minimal-examples/api-tests/api-test-lws_sequencer/main.c 2020-12-01 17:40:26.000000000 +0000 @@ -324,7 +324,7 @@ int n = 1, logs = LLL_USER | LLL_ERR | LLL_WARN | LLL_NOTICE; struct lws_context_creation_info info; struct lws_context *context; - lws_seq_t *seq; + struct lws_sequencer *seq; struct lws_vhost *vh; lws_seq_info_t i; struct myseq *s; @@ -346,7 +346,7 @@ LWS_SERVER_OPTION_EXPLICIT_VHOSTS; info.protocols = protocols; -#if defined(LWS_WITH_MBEDTLS) +#if defined(LWS_WITH_MBEDTLS) || defined(USE_WOLFSSL) /* * OpenSSL uses the system trust store. mbedTLS has to be told which * CA to trust explicitly. diff -Nru libwebsockets-3.2.1/minimal-examples/api-tests/api-test-lws_smd/CMakeLists.txt libwebsockets-4.1.6/minimal-examples/api-tests/api-test-lws_smd/CMakeLists.txt --- libwebsockets-3.2.1/minimal-examples/api-tests/api-test-lws_smd/CMakeLists.txt 1970-01-01 00:00:00.000000000 +0000 +++ libwebsockets-4.1.6/minimal-examples/api-tests/api-test-lws_smd/CMakeLists.txt 2020-12-01 17:40:26.000000000 +0000 @@ -0,0 +1,27 @@ +project(lws-api-test-lws_smd C) +cmake_minimum_required(VERSION 2.8) +find_package(libwebsockets CONFIG REQUIRED) +list(APPEND CMAKE_MODULE_PATH ${LWS_CMAKE_DIR}) +include(CheckCSourceCompiles) +include(LwsCheckRequirements) + +set(requirements 1) +require_pthreads(requirements) +require_lws_config(LWS_WITH_SYS_SMD 1 requirements) + +if (requirements) + add_executable(${PROJECT_NAME} main.c) + add_test(NAME api-test-lws_smd COMMAND lws-api-test-lws_smd -d1039) + set_tests_properties(api-test-lws_smd + PROPERTIES + RUN_SERIAL TRUE + WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}/minimal-examples/api-tests/api-test-lws_smd + TIMEOUT 60) + + if (websockets_shared) + target_link_libraries(${PROJECT_NAME} websockets_shared ${PTHREAD_LIB} ${LIBWEBSOCKETS_DEP_LIBS}) + add_dependencies(${PROJECT_NAME} websockets_shared) + else() + target_link_libraries(${PROJECT_NAME} websockets ${PTHREAD_LIB} ${LIBWEBSOCKETS_DEP_LIBS}) + endif() +endif() diff -Nru libwebsockets-3.2.1/minimal-examples/api-tests/api-test-lws_smd/main.c libwebsockets-4.1.6/minimal-examples/api-tests/api-test-lws_smd/main.c --- libwebsockets-3.2.1/minimal-examples/api-tests/api-test-lws_smd/main.c 1970-01-01 00:00:00.000000000 +0000 +++ libwebsockets-4.1.6/minimal-examples/api-tests/api-test-lws_smd/main.c 2020-12-01 17:40:26.000000000 +0000 @@ -0,0 +1,202 @@ +/* + * lws-api-test-lws_smd + * + * Written in 2020 by Andy Green + * + * This file is made available under the Creative Commons CC0 1.0 + * Universal Public Domain Dedication. + * + * This api test confirms lws_smd System Message Distribution + */ + +#include +#define HAVE_STRUCT_TIMESPEC +#include +#include + +static int interrupted, ok, fail, _exp = 111; +static lws_sorted_usec_list_t sul; +struct lws_context *context; +static pthread_t thread_spam; + +static void +timeout_cb(lws_sorted_usec_list_t *sul) +{ + /* We should have completed the test before this fires */ + interrupted = 1; + lws_cancel_service(context); +} + +static int +smd_cb1int(void *opaque, lws_smd_class_t _class, lws_usec_t timestamp, + void *buf, size_t len) +{ +#if 0 + lwsl_notice("%s: ts %llu, len %d\n", __func__, + (unsigned long long)timestamp, (int)len); + lwsl_hexdump_notice(buf, len); +#endif + ok++; + + return 0; +} + +static int +smd_cb2int(void *opaque, lws_smd_class_t _class, lws_usec_t timestamp, + void *buf, size_t len) +{ +#if 0 + lwsl_notice("%s: ts %llu, len %d\n", __func__, + (unsigned long long)timestamp, (int)len); + lwsl_hexdump_notice(buf, len); +#endif + ok++; + + return 0; +} + +static void * +_thread_spam(void *d) +{ + int n; + + n = 0; + while (n++ < 100) { + + if (lws_smd_msg_printf(context, LWSSMDCL_SYSTEM_STATE, + "{\"s\":\"state\",\"msg\":%d}", + (unsigned int)n)) { + lwsl_info("%s: send failed\n", __func__); + n--; + } +#if defined(WIN32) + Sleep(3); +#else + usleep(3000); +#endif + } +#if !defined(WIN32) + pthread_exit(NULL); +#endif + + return NULL; +} + +void sigint_handler(int sig) +{ + interrupted = 1; +} + +static int +system_notify_cb(lws_state_manager_t *mgr, lws_state_notify_link_t *link, + int current, int target) +{ + // struct lws_context *context = mgr->parent; + + if (current != LWS_SYSTATE_OPERATIONAL || target != LWS_SYSTATE_OPERATIONAL) + return 0; + + lwsl_info("%s: operational\n", __func__); + + /* + * spawn the test thread, it's going to spam 100 messages at 20ms + * intervals... check we got everything + */ + + if (pthread_create(&thread_spam, NULL, _thread_spam, NULL)) + lwsl_err("%s: failed to create the spamming thread\n", __func__); + + return 0; +} + +int +main(int argc, const char **argv) +{ + lws_state_notify_link_t notifier = { {0}, system_notify_cb, "app" }; + lws_state_notify_link_t *na[] = { ¬ifier, NULL }; + int logs = LLL_USER | LLL_ERR | LLL_WARN | LLL_NOTICE; + struct lws_context_creation_info info; + const char *p; + void *retval; + + /* the normal lws init */ + + signal(SIGINT, sigint_handler); + + if ((p = lws_cmdline_option(argc, argv, "-d"))) + logs = atoi(p); + + lws_set_log_level(logs, NULL); + lwsl_user("LWS API selftest: lws_smd\n"); + + memset(&info, 0, sizeof info); /* otherwise uninitialized garbage */ + info.port = CONTEXT_PORT_NO_LISTEN; + info.options = LWS_SERVER_OPTION_DO_SSL_GLOBAL_INIT; + info.register_notifier_list = na; + + context = lws_create_context(&info); + if (!context) { + lwsl_err("lws init failed\n"); + return 1; + } + + lws_sul_schedule(context, 0, &sul, timeout_cb, 5 * LWS_US_PER_SEC); + + /* register a messaging participant to hear INTERACTION class */ + + if (!lws_smd_register(context, NULL, 0, LWSSMDCL_INTERACTION, + smd_cb1int)) { + lwsl_err("%s: smd register 1 failed\n", __func__); + goto bail; + } + + /* register a messaging participant to hear SYSTEM_STATE class */ + + if (!lws_smd_register(context, NULL, 0, LWSSMDCL_SYSTEM_STATE, + smd_cb2int)) { + lwsl_err("%s: smd register 2 failed\n", __func__); + goto bail; + } + + + /* generate an INTERACTION class message */ + + if (lws_smd_msg_printf(context, LWSSMDCL_INTERACTION, + "{\"s\":\"interaction\"}")) { + lwsl_err("%s: problem sending smd\n", __func__); + goto bail; + } + + /* generate a SYSTEM_STATE class message */ + + if (lws_smd_msg_printf(context, LWSSMDCL_SYSTEM_STATE, + "{\"s\":\"state\"}")) { + lwsl_err("%s: problem sending smd\n", __func__); + goto bail; + } + + /* no participant listens for this class, so it should be skipped */ + + if (lws_smd_msg_printf(context, LWSSMDCL_NETWORK, "{\"s\":\"network\"}")) { + lwsl_err("%s: problem sending smd\n", __func__); + goto bail; + } + + /* the usual lws event loop */ + + while (!interrupted && lws_service(context, 0) >= 0) + ; + + pthread_join(thread_spam, &retval); + +bail: + lws_context_destroy(context); + + if (fail || ok >= _exp) + lwsl_user("Completed: PASS: %d / %d, FAIL: %d\n", ok, _exp, + fail); + else + lwsl_user("Completed: ALL PASS: %d / %d\n", ok, _exp); + + return !(ok >= _exp && !fail); +} diff -Nru libwebsockets-3.2.1/minimal-examples/api-tests/api-test-lws_struct-json/CMakeLists.txt libwebsockets-4.1.6/minimal-examples/api-tests/api-test-lws_struct-json/CMakeLists.txt --- libwebsockets-3.2.1/minimal-examples/api-tests/api-test-lws_struct-json/CMakeLists.txt 2019-12-18 14:45:31.000000000 +0000 +++ libwebsockets-4.1.6/minimal-examples/api-tests/api-test-lws_struct-json/CMakeLists.txt 2020-12-01 17:40:26.000000000 +0000 @@ -1,77 +1,25 @@ +project(lws-api-test-lws_struct-json C) cmake_minimum_required(VERSION 2.8) +find_package(libwebsockets CONFIG REQUIRED) +list(APPEND CMAKE_MODULE_PATH ${LWS_CMAKE_DIR}) include(CheckCSourceCompiles) +include(LwsCheckRequirements) set(SAMP lws-api-test-lws_struct-json) -set(SRCS main.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(SRCS main.c test2.c) set(requirements 1) require_lws_config(LWS_WITH_STRUCT_JSON 1 requirements) if (requirements) + add_executable(${SAMP} ${SRCS}) + add_test(NAME api-test-lws_struct-json COMMAND lws-api-test-lws_struct-json) if (websockets_shared) - target_link_libraries(${SAMP} websockets_shared) + target_link_libraries(${SAMP} websockets_shared ${LIBWEBSOCKETS_DEP_LIBS}) add_dependencies(${SAMP} websockets_shared) else() - target_link_libraries(${SAMP} websockets) + target_link_libraries(${SAMP} websockets ${LIBWEBSOCKETS_DEP_LIBS}) endif() endif() - diff -Nru libwebsockets-3.2.1/minimal-examples/api-tests/api-test-lws_struct-json/main.c libwebsockets-4.1.6/minimal-examples/api-tests/api-test-lws_struct-json/main.c --- libwebsockets-3.2.1/minimal-examples/api-tests/api-test-lws_struct-json/main.c 2019-12-18 14:45:31.000000000 +0000 +++ libwebsockets-4.1.6/minimal-examples/api-tests/api-test-lws_struct-json/main.c 2020-12-01 17:40:26.000000000 +0000 @@ -1,7 +1,7 @@ /* * lws-api-test-lws_struct-json * - * Written in 2010-2019 by Andy Green + * Written in 2010-2020 by Andy Green * * This file is made available under the Creative Commons CC0 1.0 * Universal Public Domain Dedication. @@ -16,6 +16,147 @@ #include +typedef struct { + lws_dll2_t list; + + struct gpiod_line *line; + + const char *name; + const char *wire; + + int chip_idx; + int offset; + int safe; +} sai_jig_gpio_t; + +typedef struct { + lws_dll2_t list; + sai_jig_gpio_t *gpio; /* null = wait ms */ + const char *gpio_name; + int value; +} sai_jig_seq_item_t; + +typedef struct { + lws_dll2_t list; + lws_dll2_owner_t seq_owner; + const char *name; +} sai_jig_sequence_t; + +typedef struct { + lws_dll2_t list; + lws_dll2_owner_t gpio_owner; + lws_dll2_owner_t seq_owner; + + lws_sorted_usec_list_t sul; /* next step in ongoing seq */ + sai_jig_seq_item_t *current; /* next seq step */ + + const char *name; + + struct lws *wsi; +} sai_jig_target_t; + +typedef struct { + lws_dll2_owner_t target_owner; + struct gpiod_chip *chip[16]; + struct lwsac *ac_conf; + int port; + const char *iface; + struct lws_context *ctx; +} sai_jig_t; + +/* + * We read the JSON config using lws_struct... instrument the related structures + */ + +static const lws_struct_map_t lsm_sai_jig_gpio[] = { + LSM_UNSIGNED (sai_jig_gpio_t, chip_idx, "chip_idx"), + LSM_UNSIGNED (sai_jig_gpio_t, offset, "offset"), + LSM_UNSIGNED (sai_jig_gpio_t, safe, "safe"), + LSM_STRING_PTR (sai_jig_gpio_t, name, "name"), + LSM_STRING_PTR (sai_jig_gpio_t, wire, "wire"), +}; + +static const lws_struct_map_t lsm_sai_jig_seq_item[] = { + LSM_STRING_PTR (sai_jig_seq_item_t, gpio_name, "gpio_name"), + LSM_UNSIGNED (sai_jig_seq_item_t, value, "value"), +}; + +static const lws_struct_map_t lsm_sai_jig_sequence[] = { + LSM_STRING_PTR (sai_jig_sequence_t, name, "name"), + LSM_LIST (sai_jig_sequence_t, seq_owner, + sai_jig_seq_item_t, list, + NULL, lsm_sai_jig_seq_item, "seq"), +}; + +static const lws_struct_map_t lsm_sai_jig_target[] = { + LSM_STRING_PTR (sai_jig_target_t, name, "name"), + LSM_LIST (sai_jig_target_t, gpio_owner, sai_jig_gpio_t, list, + NULL, lsm_sai_jig_gpio, "gpios"), + LSM_LIST (sai_jig_target_t, seq_owner, sai_jig_sequence_t, list, + NULL, lsm_sai_jig_sequence, "sequences"), +}; + +static const lws_struct_map_t lsm_sai_jig[] = { + LSM_STRING_PTR (sai_jig_t, iface, "iface"), + LSM_UNSIGNED (sai_jig_t, port, "port"), + LSM_LIST (sai_jig_t, target_owner, sai_jig_target_t, list, + NULL, lsm_sai_jig_target, "targets"), +}; + +static const lws_struct_map_t lsm_jig_schema[] = { + LSM_SCHEMA (sai_jig_t, NULL, lsm_sai_jig, "sai-jig"), +}; + +static const char * const jig_conf = +"{" + "\"schema\": \"sai-jig\"," + "\"port\": 44000," + "\"targets\": [" + "{" + "\"name\": \"linkit-7697-1\"," + "\"gpios\": [" + "{" + "\"chip_index\": 0," + "\"name\": \"nReset\"," + "\"offset\": 17," + "\"wire\": \"RST\"," + "\"safe\": 0" + "}, {" + "\"name\": \"usr\"," + "\"chip_index\": 0," + "\"offset\": 22," + "\"wire\": \"P6\"," + "\"safe\": 0" + "}" + "], \"sequences\": [" + "{" + "\"name\": \"reset\"," + "\"seq\": [" + "{ \"gpio_name\": \"nReset\", \"value\": 0 }," + "{ \"gpio_name\": \"usr\", \"value\": 0 }," + "{ \"value\": 300 }," + "{ \"gpio_name\": \"nReset\", \"value\": 1 }" + "]" + "}, {" + "\"name\": \"flash\"," + "\"seq\": [" + "{ \"gpio_name\": \"nReset\", \"value\": 0 }," + "{ \"gpio_name\": \"usr\", \"value\": 1 }," + "{ \"value\": 300 }," + "{ \"gpio_name\": \"nReset\", \"value\": 1 }," + "{ \"value\": 100 }," + "{ \"gpio_name\": \"usr\", \"value\": 0 }" + "]" + "}" + "]" + "}" + "]" +"}"; + + + +extern int test2(void); + /* * in this example, the JSON is for one "builder" object, which may specify * a child list "targets" of zero or more "target" objects. @@ -119,6 +260,10 @@ "yJln+v4RIWj2xOGPJovOqiXwi0FyM61f8U8gj0OiNA2/QlvrqQVDF7sMXgjvaE7iQt5vMETteZlx" "+z3f+jTFM/aon511W4+ZkRD+6AHwucvM9BEC\"}]}" "}", + "{" /* test 8 the "other" schema */ + "\"schema\":\"com-warmcat-sai-other\"," + "\"name\":\"somename\"" + "}", }; /* @@ -170,7 +315,8 @@ "V+ye6F9JTUMlozRMsGuF8U4btDzH5xdnmvRS4Ar6LKEtAXGkj2yuyJln+v4R" "IWj2xOGPJovOqiXwi0FyM61f8U8gj0OiNA2/QlvrqQVDF7sMXgjvaE7iQt5v" "METteZlx+z3f+jTFM/aon511W4+ZkRD+6AHwucvM9BEC\"" - ",\"someflag\":false}]}" + ",\"someflag\":false}]}", + "{\"schema\":\"com-warmcat-sai-other\",\"name\":\"somename\"}" }; /* @@ -210,6 +356,8 @@ NULL, lsm_child, "child"), }; +/* the first kind of struct / schema we can receive */ + /* builder object */ typedef struct sai_builder { @@ -227,22 +375,125 @@ NULL, lsm_target, "targets"), }; -/* Schema table +/* + * the second kind of struct / schema we can receive + */ + +typedef struct sai_other { + char name[32]; +} sai_other_t; + +static const lws_struct_map_t lsm_other[] = { + LSM_CARRAY (sai_other_t, name, "name"), +}; + +/* + * meta composed pointers test + * + * We serialize a struct that consists of members that point to other objects, + * we expect this kind of thing + * + * { + * "schema": "meta", + * "t": { ... }, + * "e": { ...} + * } + */ + +typedef struct meta { + sai_target_t *t; + sai_builder_t *b; +} meta_t; + +static const lws_struct_map_t lsm_meta[] = { + LSM_CHILD_PTR (meta_t, t, sai_target_t, NULL, lsm_target, "t"), + LSM_CHILD_PTR (meta_t, b, sai_child_t, NULL, lsm_builder, "e"), +}; + +static const lws_struct_map_t lsm_schema_meta[] = { + LSM_SCHEMA (meta_t, NULL, lsm_meta, "meta.schema"), +}; + +/* + * Schema table * * Before we can understand the serialization top level format, we must read * the schema, use the table below to create the right toplevel object for the * schema name, and select the correct map tables to interpret the rest of the * serialization. * - * Therefore the schema tables below are the starting point for the - * JSON deserialization. + * In this example there are two completely separate structs / schemas possible + * to receive, and we disambiguate and create the correct one using the schema + * JSON node. + * + * Therefore the schema table below is the starting point for the JSON + * deserialization. */ static const lws_struct_map_t lsm_schema_map[] = { LSM_SCHEMA (sai_builder_t, NULL, lsm_builder, "com-warmcat-sai-builder"), + LSM_SCHEMA (sai_other_t, NULL, + lsm_other, "com-warmcat-sai-other"), }; +typedef struct sai_cancel { + char task_uuid[65]; +} sai_cancel_t; + +const lws_struct_map_t lsm_task_cancel[] = { + LSM_CARRAY (sai_cancel_t, task_uuid, "uuid"), +}; + +static const lws_struct_map_t t2_map[] = { + LSM_SCHEMA (sai_cancel_t, NULL, lsm_task_cancel, + "com.warmcat.sai.taskinfo"), + LSM_SCHEMA (sai_cancel_t, NULL, lsm_task_cancel, + "com.warmcat.sai.eventinfo"), + LSM_SCHEMA (sai_cancel_t, NULL, lsm_task_cancel, + /* shares struct */ "com.warmcat.sai.taskreset"), + LSM_SCHEMA (sai_cancel_t, NULL, lsm_task_cancel, + /* shares struct */ "com.warmcat.sai.eventreset"), + LSM_SCHEMA (sai_cancel_t, NULL, lsm_task_cancel, + /* shares struct */ "com.warmcat.sai.eventdelete"), + LSM_SCHEMA (sai_cancel_t, NULL, lsm_task_cancel, + "com.warmcat.sai.taskcan"), +}; + +static const char *t2 = + "{\"schema\":\"com.warmcat.sai.taskcan\"," + "\"uuid\": \"071ab46ab4296e5de674c628fec17c55088254679f7714ad991f8c4873dca\"}\x01\x02\xff\xff\xff\xff"; + +typedef struct xlws_wifi_creds { + lws_dll2_t list; + char ssid[33]; + char passphrase[64]; + int alg; + char bssid[6]; +} xlws_wifi_creds_t; + +typedef struct xlws_netdevs { + lws_dll2_owner_t owner_creds; +} xlws_netdevs_t; + +static const lws_struct_map_t lsm_wifi_creds[] = { + LSM_CARRAY (xlws_wifi_creds_t, ssid, "ssid"), + LSM_CARRAY (xlws_wifi_creds_t, passphrase, "passphrase"), + LSM_UNSIGNED (xlws_wifi_creds_t, alg, "alg"), + LSM_STRING_PTR (xlws_wifi_creds_t, bssid, "bssid"), +}; + +static const lws_struct_map_t lsm_netdev_credentials[] = { + LSM_LIST (xlws_netdevs_t, owner_creds, xlws_wifi_creds_t, list, + NULL, lsm_wifi_creds, "credentials"), +}; + +static const lws_struct_map_t lsm_netdev_schema[] = { + LSM_SCHEMA (xlws_netdevs_t, NULL, lsm_netdev_credentials, + "com.warmcat.sai.taskinfo"), +}; + + static int show_target(struct lws_dll2 *d, void *user) { @@ -268,8 +519,11 @@ #endif struct lejp_ctx ctx; lws_struct_args_t a; - sai_builder_t *b; + sai_builder_t *b, mb; + sai_target_t mt; + sai_other_t *o; const char *p; + meta_t meta; if ((p = lws_cmdline_option(argc, argv, "-d"))) logs = atoi(p); @@ -289,8 +543,8 @@ a.ac_block_size = 512; lws_struct_json_init_parse(&ctx, NULL, &a); - n = (int)(signed char)lejp_parse(&ctx, (uint8_t *)json_tests[m], - strlen(json_tests[m])); + n = lejp_parse(&ctx, (uint8_t *)json_tests[m], + (int)strlen(json_tests[m])); if (n < 0) { lwsl_err("%s: notification JSON decode failed '%s'\n", __func__, lejp_error_to_string(n)); @@ -299,27 +553,58 @@ } lwsac_info(a.ac); - b = a.dest; - if (!b) { - lwsl_err("%s: didn't produce any output\n", __func__); - e++; - goto done; - } + if (m + 1 != 8) { + b = a.dest; + if (!b) { + lwsl_err("%s: didn't produce any output\n", __func__); + e++; + goto done; + } + + if (a.top_schema_index) { + lwsl_err("%s: wrong top_schema_index\n", __func__); + e++; + goto done; + } + + lwsl_notice("builder.hostname = '%s', timeout = %d, targets (%d)\n", + b->hostname, b->nspawn_timeout, + b->targets.count); + + lws_dll2_foreach_safe(&b->targets, NULL, show_target); + } else { + o = a.dest; + if (!o) { + lwsl_err("%s: didn't produce any output\n", __func__); + e++; + goto done; + } - lwsl_notice("builder.hostname = '%s', timeout = %d, targets (%d)\n", - b->hostname, b->nspawn_timeout, - b->targets.count); + if (a.top_schema_index != 1) { + lwsl_err("%s: wrong top_schema_index\n", __func__); + e++; + goto done; + } - lws_dll2_foreach_safe(&b->targets, NULL, show_target); + lwsl_notice("other.name = '%s'\n", o->name); + } /* 2. serialize the structs into JSON and confirm */ lwsl_notice("%s: .... strarting serialization of test %d\n", __func__, m + 1); - ser = lws_struct_json_serialize_create(lsm_schema_map, + + if (m + 1 != 8) { + ser = lws_struct_json_serialize_create(lsm_schema_map, LWS_ARRAY_SIZE(lsm_schema_map), 0//LSSERJ_FLAG_PRETTY , b); + } else { + ser = lws_struct_json_serialize_create(&lsm_schema_map[1], + 1, + 0//LSSERJ_FLAG_PRETTY + , o); + } if (!ser) { lwsl_err("%s: unable to init serialization\n", __func__); goto bail; @@ -328,12 +613,11 @@ do { n = lws_struct_json_serialize(ser, buf, sizeof(buf), &written); - lwsl_notice("ser says %d\n", n); switch (n) { - case LSJS_RESULT_CONTINUE: case LSJS_RESULT_FINISH: puts((const char *)buf); break; + case LSJS_RESULT_CONTINUE: case LSJS_RESULT_ERROR: goto bail; } @@ -343,6 +627,7 @@ lwsl_err("%s: test %d: expected %s\n", __func__, m + 1, json_expected[m]); e++; + goto done; } lws_struct_json_serialize_destroy(&ser); @@ -354,11 +639,163 @@ if (e) goto bail; + /* ad-hoc tests */ + + memset(&meta, 0, sizeof(meta)); + memset(&mb, 0, sizeof(mb)); + memset(&mt, 0, sizeof(mt)); + + meta.t = &mt; + meta.b = &mb; + + meta.t->name = "mytargetname"; + lws_strncpy(meta.b->hostname, "myhostname", sizeof(meta.b->hostname)); + ser = lws_struct_json_serialize_create(lsm_schema_meta, 1, 0, + &meta); + if (!ser) { + lwsl_err("%s: failed to create json\n", __func__); + + + } + do { + n = lws_struct_json_serialize(ser, buf, sizeof(buf), &written); + switch (n) { + case LSJS_RESULT_CONTINUE: + case LSJS_RESULT_FINISH: + puts((const char *)buf); + if (strcmp((const char *)buf, + "{\"schema\":\"meta.schema\"," + "\"t\":{\"name\":\"mytargetname\"," + "\"someflag\":false}," + "\"e\":{\"hostname\":\"myhostname\"," + "\"nspawn_timeout\":0}}")) { + lwsl_err("%s: meta test fail\n", __func__); + goto bail; + } + break; + case LSJS_RESULT_ERROR: + goto bail; + } + } while(n == LSJS_RESULT_CONTINUE); + + lws_struct_json_serialize_destroy(&ser); + + lwsl_notice("Test set 2\n"); + + memset(&a, 0, sizeof(a)); + a.map_st[0] = t2_map; + a.map_entries_st[0] = LWS_ARRAY_SIZE(t2_map); + a.ac_block_size = 128; + + lws_struct_json_init_parse(&ctx, NULL, &a); + m = lejp_parse(&ctx, (uint8_t *)t2, (int)strlen(t2)); + if (m < 0 || !a.dest) { + lwsl_notice("%s: notification JSON decode failed '%s'\n", + __func__, lejp_error_to_string(m)); + goto bail; + } + + lwsl_notice("Test set 2: %d: %s\n", m, + ((sai_cancel_t *)a.dest)->task_uuid); + + lwsac_free(&a.ac); + + if (test2()) + goto bail; + + { + lws_struct_serialize_t *js; + xlws_wifi_creds_t creds; + xlws_netdevs_t netdevs; + unsigned char *buf; + size_t w; + int n; + + memset(&creds, 0, sizeof(creds)); + memset(&netdevs, 0, sizeof(netdevs)); + + lws_strncpy(creds.ssid, "xxx", sizeof(creds.ssid)); + lws_strncpy(creds.passphrase, "yyy", sizeof(creds.passphrase)); + lws_dll2_add_tail(&creds.list, &netdevs.owner_creds); + + buf = malloc(2048); /* length should be computed */ + + js = lws_struct_json_serialize_create(lsm_netdev_schema, + LWS_ARRAY_SIZE(lsm_netdev_schema), 0, &netdevs); + if (!js) + goto bail; + + n = lws_struct_json_serialize(js, buf, 2048, &w); + lws_struct_json_serialize_destroy(&js); + if (n != LSJS_RESULT_FINISH) + goto bail; + if (strcmp("{\"schema\":\"com.warmcat.sai.taskinfo\",\"credentials\":[{\"ssid\":\"xxx\",\"passphrase\":\"yyy\",\"alg\":0}]}", (const char *)buf)) { + puts((const char *)buf); + goto bail; + } + free(buf); + } + + { + struct x { lws_dll2_t list; const char *sz; }; + struct x x1, x2, *xp; + lws_dll2_owner_t o; + + lws_dll2_owner_clear(&o); + memset(&x1, 0, sizeof(x1)); + memset(&x2, 0, sizeof(x2)); + + x1.sz = "nope"; + x2.sz = "yes"; + + lws_dll2_add_tail(&x1.list, &o); + lws_dll2_add_tail(&x2.list, &o); + + xp = lws_dll2_search_sz_pl(&o, "yes", 3, struct x, list, sz); + if (xp != &x2) { + lwsl_err("%s: 1 xp %p\n", __func__, xp); + goto bail; + } + xp = lws_dll2_search_sz_pl(&o, "nope", 4, struct x, list, sz); + if (xp != &x1) { + lwsl_err("%s: 2 xp %p\n", __func__, xp); + goto bail; + } + xp = lws_dll2_search_sz_pl(&o, "wrong", 4, struct x, list, sz); + if (xp) { + lwsl_err("%s: 3 xp %p\n", __func__, xp); + goto bail; + } + } + + { + lws_struct_args_t a; + struct lejp_ctx ctx; + int m; + + memset(&a, 0, sizeof(a)); + a.map_st[0] = lsm_jig_schema; + a.map_entries_st[0] = LWS_ARRAY_SIZE(lsm_jig_schema); + a.ac_block_size = 512; + + lws_struct_json_init_parse(&ctx, NULL, &a); + + m = lejp_parse(&ctx, (uint8_t *)jig_conf, (int)strlen(jig_conf)); + + if (m < 0 || !a.dest) { + lwsl_err("%s: line %d: JSON decode failed '%s'\n", + __func__, ctx.line, lejp_error_to_string(m)); + goto bail; + } + } + lwsl_user("Completed: PASS\n"); return 0; bail: +if (test2()) + return 1; lwsl_user("Completed: FAIL\n"); return 1; diff -Nru libwebsockets-3.2.1/minimal-examples/api-tests/api-test-lws_struct-json/README.md libwebsockets-4.1.6/minimal-examples/api-tests/api-test-lws_struct-json/README.md --- libwebsockets-3.2.1/minimal-examples/api-tests/api-test-lws_struct-json/README.md 2019-12-18 14:45:31.000000000 +0000 +++ libwebsockets-4.1.6/minimal-examples/api-tests/api-test-lws_struct-json/README.md 2020-12-01 17:40:26.000000000 +0000 @@ -17,40 +17,92 @@ ``` $ ./lws-api-test-lws_struct-json -[2019/03/30 22:09:09:2529] USER: LWS API selftest: lws_struct JSON -[2019/03/30 22:09:09:2625] NOTICE: main: ++++++++++++++++ test 1 -[2019/03/30 22:09:09:2812] NOTICE: builder.hostname = 'learn', timeout = 1800, targets (2) -[2019/03/30 22:09:09:2822] NOTICE: target.name 'target1' (target 0x543a830) -[2019/03/30 22:09:09:2824] NOTICE: target.name 'target2' (target 0x543a860) -[2019/03/30 22:09:09:2826] NOTICE: main: .... strarting serialization of test 1 -[2019/03/30 22:09:09:2899] NOTICE: ser says 1 -{"schema":"com-warmcat-sai-builder","hostname":"learn","nspawn_timeout":1800,"targets":[{"name":"target1"},{"name":"target2"}]} -[2019/03/30 22:09:09:2929] NOTICE: main: ++++++++++++++++ test 2 -[2019/03/30 22:09:09:2932] NOTICE: builder.hostname = 'learn', timeout = 0, targets (3) -[2019/03/30 22:09:09:2932] NOTICE: target.name 'target1' (target 0x543b060) -[2019/03/30 22:09:09:2933] NOTICE: target.name 'target2' (target 0x543b090) -[2019/03/30 22:09:09:2933] NOTICE: target.name 'target3' (target 0x543b0c0) -[2019/03/30 22:09:09:2934] NOTICE: main: .... strarting serialization of test 2 -[2019/03/30 22:09:09:2935] NOTICE: ser says 1 -{"schema":"com-warmcat-sai-builder","hostname":"learn","nspawn_timeout":0,"targets":[{"name":"target1"},{"name":"target2"},{"name":"target3"}]} -[2019/03/30 22:09:09:2940] NOTICE: main: ++++++++++++++++ test 3 -[2019/03/30 22:09:09:2959] NOTICE: builder.hostname = 'learn', timeout = 1800, targets (2) -[2019/03/30 22:09:09:2960] NOTICE: target.name 'target1' (target 0x543b450) -[2019/03/30 22:09:09:2961] NOTICE: child 0x543b480, target.child.somename 'abc' -[2019/03/30 22:09:09:2961] NOTICE: target.name 'target2' (target 0x543b490) -[2019/03/30 22:09:09:2962] NOTICE: main: .... strarting serialization of test 3 -[2019/03/30 22:09:09:2969] NOTICE: ser says 1 -{"schema":"com-warmcat-sai-builder","hostname":"learn","nspawn_timeout":1800,"targets":[{"name":"target1","child":{"somename":"abc"}},{"name":"target2"}]} -[2019/03/30 22:09:09:2970] NOTICE: main: ++++++++++++++++ test 4 -[2019/03/30 22:09:09:2971] NOTICE: builder.hostname = 'learn', timeout = 1800, targets (0) -[2019/03/30 22:09:09:2971] NOTICE: main: .... strarting serialization of test 4 -[2019/03/30 22:09:09:2973] NOTICE: ser says 1 +[2020/05/21 16:36:57:0808] U: LWS API selftest: lws_struct JSON +[2020/05/21 16:36:57:1188] N: main: ++++++++++++++++ test 1 +[2020/05/21 16:36:57:1291] N: lws_struct_schema_only_lejp_cb: child map ofs_clist 0 +[2020/05/21 16:36:57:1387] N: lws_struct_default_lejp_cb: created 'targets' object size 48 +[2020/05/21 16:36:57:1429] N: lws_struct_default_lejp_cb: created 'targets' object size 48 +[2020/05/21 16:36:57:1467] N: builder.hostname = 'learn', timeout = 1800, targets (2) +[2020/05/21 16:36:57:1490] N: target.name 'target1' (target 0x509fe30) +[2020/05/21 16:36:57:1495] N: target.name 'target2' (target 0x509fe68) +[2020/05/21 16:36:57:1500] N: main: .... strarting serialization of test 1 +{"schema":"com-warmcat-sai-builder","hostname":"learn","nspawn_timeout":1800,"targets":[{"name":"target1","someflag":true},{"name":"target2","someflag":false}]} +[2020/05/21 16:36:57:1648] N: main: ++++++++++++++++ test 2 +[2020/05/21 16:36:57:1649] N: lws_struct_schema_only_lejp_cb: child map ofs_clist 0 +[2020/05/21 16:36:57:1650] N: lws_struct_default_lejp_cb: created 'targets' object size 48 +[2020/05/21 16:36:57:1651] N: lws_struct_default_lejp_cb: created 'targets' object size 48 +[2020/05/21 16:36:57:1652] N: lws_struct_default_lejp_cb: created 'targets' object size 48 +[2020/05/21 16:36:57:1653] N: builder.hostname = 'learn', timeout = 0, targets (3) +[2020/05/21 16:36:57:1653] N: target.name 'target1' (target 0x50a0660) +[2020/05/21 16:36:57:1654] N: target.name 'target2' (target 0x50a0698) +[2020/05/21 16:36:57:1655] N: target.name 'target3' (target 0x50a06d0) +[2020/05/21 16:36:57:1655] N: main: .... strarting serialization of test 2 +{"schema":"com-warmcat-sai-builder","hostname":"learn","nspawn_timeout":0,"targets":[{"name":"target1","someflag":false},{"name":"target2","someflag":false},{"name":"target3","someflag":false}]} +[2020/05/21 16:36:57:1662] N: main: ++++++++++++++++ test 3 +[2020/05/21 16:36:57:1663] N: lws_struct_schema_only_lejp_cb: child map ofs_clist 0 +[2020/05/21 16:36:57:1664] N: lws_struct_default_lejp_cb: created 'targets' object size 48 +[2020/05/21 16:36:57:1671] N: lws_struct_default_lejp_cb: created 'child' object size 8 +[2020/05/21 16:36:57:1685] N: lws_struct_default_lejp_cb: created 'targets' object size 48 +[2020/05/21 16:36:57:1685] N: builder.hostname = 'learn', timeout = 1800, targets (2) +[2020/05/21 16:36:57:1686] N: target.name 'target1' (target 0x50a0a50) +[2020/05/21 16:36:57:1687] N: child 0x50a0a88, target.child.somename 'abc' +[2020/05/21 16:36:57:1688] N: target.name 'target2' (target 0x50a0a98) +[2020/05/21 16:36:57:1688] N: main: .... strarting serialization of test 3 +{"schema":"com-warmcat-sai-builder","hostname":"learn","nspawn_timeout":1800,"targets":[{"name":"target1","someflag":false,"child":{"somename":"abc"}},{"name":"target2","someflag":false}]} +[2020/05/21 16:36:57:1697] N: main: ++++++++++++++++ test 4 +[2020/05/21 16:36:57:1698] N: lws_struct_schema_only_lejp_cb: child map ofs_clist 0 +[2020/05/21 16:36:57:1699] N: builder.hostname = 'learn', timeout = 1800, targets (0) +[2020/05/21 16:36:57:1699] N: main: .... strarting serialization of test 4 {"schema":"com-warmcat-sai-builder","hostname":"learn","nspawn_timeout":1800} -[2019/03/30 22:09:09:2974] NOTICE: main: ++++++++++++++++ test 5 -[2019/03/30 22:09:09:2978] NOTICE: builder.hostname = '', timeout = 0, targets (0) -[2019/03/30 22:09:09:2979] NOTICE: main: .... strarting serialization of test 5 -[2019/03/30 22:09:09:2980] NOTICE: ser says 1 +[2020/05/21 16:36:57:1701] N: main: ++++++++++++++++ test 5 +[2020/05/21 16:36:57:1702] N: lws_struct_schema_only_lejp_cb: child map ofs_clist 0 +[2020/05/21 16:36:57:1707] N: builder.hostname = '', timeout = 0, targets (0) +[2020/05/21 16:36:57:1708] N: main: .... strarting serialization of test 5 {"schema":"com-warmcat-sai-builder","hostname":"","nspawn_timeout":0} -[2019/03/30 22:09:09:2982] USER: Completed: PASS +[2020/05/21 16:36:57:1709] N: main: ++++++++++++++++ test 6 +[2020/05/21 16:36:57:1710] N: lws_struct_schema_only_lejp_cb: child map ofs_clist 0 +[2020/05/21 16:36:57:1730] N: builder.hostname = 'PYvtan6kqppjnS0KpYTCaiOLsJkc7Xe', timeout = 0, targets (0) +[2020/05/21 16:36:57:1731] N: main: .... strarting serialization of test 6 +{"schema":"com-warmcat-sai-builder","hostname":"PYvtan6kqppjnS0KpYTCaiOLsJkc7Xe","nspawn_timeout":0} +[2020/05/21 16:36:57:1732] N: main: ++++++++++++++++ test 7 +[2020/05/21 16:36:57:1732] N: lws_struct_schema_only_lejp_cb: child map ofs_clist 0 +[2020/05/21 16:36:57:1733] N: lws_struct_default_lejp_cb: created 'targets' object size 48 +[2020/05/21 16:36:57:1739] N: builder.hostname = '', timeout = 0, targets (1) +[2020/05/21 16:36:57:1751] N: target.name 'PYvtan6kqppjnS0KpYTCaiOLsJkc7XecAr1kcE0aCIciewYB+JcLG82mO1Vb1mJtjDwUjBxy2I6AzefzoWUWmqZbsv4MXR55j9bKlyz1liiSX63iO0x6JAwACMtE2MkgcLwR86TSWAD9D1QKIWqg5RJ/CRuVsW0DKAUMD52ql4JmPFuJpJgTq28z6PhYNzN3yI3bmQt6bzhA+A/xAsFzSBnb3MHYWzGMprr53FAP1ISo5Ec9i+2ehV40sG6Q470sH3PGQZ0YRPO7Sh/SyrSQ/scONmxRc3AcXl7X/CSs417ii+CV8sq3ZgcxKNB7tNfN7idNx3upZ00G2BZy9jSy03cLKKLNaNUt0TQsxXbH55uDHzSEeZWvxJgT6zB1NoMhdC02w+oXim94M6z6COCnqT3rgkGk8PHMry9Bkh4yVpRmzIRfMmln/lEhdZgxky2+g5hhlSIGJYDCrdynD9kCfvfy6KGOpNIi1X+mhbbWn4lnL9ZKihL/RrfOV+oV4R26IDq+KqUiJBENeo8/GXkGLUH/87iPyzXKEMavr6fkrK0vTGto8yEYxmOyaVz8phG5rwf4jJgmYNoMbGo8gWvhqO7UAGy2g7MWv+B/t1eZZ+1euLsNrWAsFJiFbQKgdFfQT3RjB14iU8knlQ8usoy+pXssY2ddGJGVcGC21oZvstK9eu1eRZftda/wP+N5unT1Hw7kCoVzqxHieiYt47EGIOaaQ7XjZDK6qPN6O/grHnvJZm2vBkxuXgsYVkRQ7AuTWIecphqFsq7Wbc1YNbMW47SVU5zMD0WaCqbaaI0t4uIzRvPlD8cpiiTzFTrEHlIBTf8/uZjjEGGLhJR1jPqA9D1Ej3ChV+ye6F9JTUMlozRMsGuF8U4btDzH5xdnmvRS4Ar6LKEtAXGkj2yuyJln+v4RIWj2xOGPJovOqiXwi0FyM61f8U8gj0OiNA2/QlvrqQVDF7sMXgjvaE7iQt5vMETteZlx+z3f+jTFM/aon5... +[2020/05/21 16:36:57:1752] N: main: .... strarting serialization of test 7 +{"schema":"com-warmcat-sai-builder","hostname":"","nspawn_timeout":0,"targets":[{"name":"PYvtan6kqppjnS0KpYTCaiOLsJkc7XecAr1kcE0aCIciewYB+JcLG82mO1Vb1mJtjDwUjBxy2I6AzefzoWUWmqZbsv4MXR55j9bKlyz1liiSX63iO0x6JAwACMtE2MkgcLwR86TSWAD9D1QKIWqg5RJ/CRuVsW0DKAUMD52ql4JmPFuJpJgTq28z6PhYNzN3yI3bmQt6bzhA+A/xAsFzSBnb3MHYWzGMprr53FAP1ISo5Ec9i+2ehV40sG6Q470sH3PGQZ0YRPO7Sh/SyrSQ/scONmxRc3AcXl7X/CSs417ii+CV8sq3ZgcxKNB7tNfN7idNx3upZ00G2BZy9jSy03cLKKLNaNUt0TQsxXbH55uDHzSEeZWvxJgT6zB1NoMhdC02w+oXim94M6z6COCnqT3rgkGk8PHMry9Bkh4yVpRmzIRfMmln/lEhdZgxky2+g5hhlSIGJYDCrdynD9kCfvfy6KGOpNIi1X+mhbbWn4lnL9ZKihL/RrfOV+oV4R26IDq+KqUiJBENeo8/GXkGLUH/87iPyzXKEMavr6fkrK0vTGto8yEYxmOyaVz8phG5rwf4jJgmYNoMbGo8gWvhqO7UAGy2g7MWv+B/t1eZZ+1euLsNrWAsFJiFbQKgdFfQT3RjB14iU8knlQ8usoy+pXssY2ddGJGVcGC21oZvstK9eu1eRZftda/wP+N5unT1Hw7kCoVzqxHieiYt47EGIOaaQ7XjZDK6qPN6O/grHnvJZm2vBkxuXgsYVkRQ7AuTWIecphqFsq7Wbc1YNbMW47SVU5zMD0WaCqbaaI0t4uIzRvPlD8cpiiTzFTrEHlIBTf8/uZjjEGGLhJR1jPqA9D1Ej3ChV+ye6F9JTUMlozRMsGuF8U4btDzH5xdnmvRS4Ar6LKEtAXGkj2yuyJln+v4RIWj2xOGPJovOqiXwi0FyM61f8U8gj0OiNA2/QlvrqQVDF7sMXgjvaE7iQt5vMETteZlx+z3f+jTFM/aon511W4+ZkRD+6AHwucvM9BEC","someflag":false}]} +[2020/05/21 16:36:57:1756] N: main: ++++++++++++++++ test 8 +[2020/05/21 16:36:57:1758] N: lws_struct_schema_only_lejp_cb: child map ofs_clist 0 +[2020/05/21 16:36:57:1761] N: other.name = 'somename' +[2020/05/21 16:36:57:1763] N: main: .... strarting serialization of test 8 +{"schema":"com-warmcat-sai-other","name":"somename"} +{"schema":"meta.schema","t":{"name":"mytargetname","someflag":false},"e":{"hostname":"myhostname","nspawn_timeout":0}} +[2020/05/21 16:36:57:1785] N: Test set 2 +[2020/05/21 16:36:57:1791] N: lws_struct_schema_only_lejp_cb: child map ofs_clist 0 +[2020/05/21 16:36:57:1795] N: Test set 2: 6: 071ab46ab4296e5de674c628fec17c55088254679f7714ad991f8c4873dca +[2020/05/21 16:36:57:1801] N: test2: start +[2020/05/21 16:36:57:1811] N: lws_struct_schema_only_lejp_cb: child map ofs_clist 0 +[2020/05/21 16:36:57:1815] N: lws_struct_default_lejp_cb: created 'config' object size 80 +[2020/05/21 16:36:57:1819] N: lws_struct_default_lejp_cb: created 'creds' object size 16 +[2020/05/21 16:36:57:1833] N: lws_struct_default_lejp_cb: created 'config' object size 80 +[2020/05/21 16:36:57:1834] N: lws_struct_default_lejp_cb: created 'creds' object size 16 +[2020/05/21 16:36:57:1837] N: test2: lejp_parse 0 +[2020/05/21 16:36:57:1841] N: t2_configs_dump: number of configs: 2 +[2020/05/21 16:36:57:1844] N: t2_config_dump: id1 '(null)' +[2020/05/21 16:36:57:1846] N: t2_config_dump: arg1 'val1' +[2020/05/21 16:36:57:1848] N: t2_config_dump: ssid '"nw2"' +[2020/05/21 16:36:57:1850] N: t2_config_dump: freq 0 +[2020/05/21 16:36:57:1852] N: t2_config_dump: arg2 0 +[2020/05/21 16:36:57:1854] N: t2_config_dump: priority 1 +[2020/05/21 16:36:57:1856] N: t2_config_dump: key1: "xxxxxxxxx", key2: (null) +[2020/05/21 16:36:57:1857] N: t2_config_dump: id1 '(null)' +[2020/05/21 16:36:57:1858] N: t2_config_dump: arg1 'val2' +[2020/05/21 16:36:57:1858] N: t2_config_dump: ssid '"nw1"' +[2020/05/21 16:36:57:1859] N: t2_config_dump: freq 11 +[2020/05/21 16:36:57:1859] N: t2_config_dump: arg2 1420887242594 +[2020/05/21 16:36:57:1860] N: t2_config_dump: priority 3 +[2020/05/21 16:36:57:1860] N: t2_config_dump: key1: "xxxxxxxxxxxxx", key2: (null) +{"config":[{"creds":{"key1":"\u0022xxxxxxxxx\u0022"},"arg1":"val1","ssid":"\u0022nw2\u0022","frequency":0,"arg2":0,"priority":1},{"creds":{"key1":"\u0022xxxxxxxxxxxxx\u0022"},"arg1":"val2","ssid":"\u0022nw1\u0022","frequency":11,"arg2":1420887242594,"priority":3}]} +[2020/05/21 16:36:57:1880] U: Completed: PASS ``` diff -Nru libwebsockets-3.2.1/minimal-examples/api-tests/api-test-lws_struct-json/selftest.sh libwebsockets-4.1.6/minimal-examples/api-tests/api-test-lws_struct-json/selftest.sh --- libwebsockets-3.2.1/minimal-examples/api-tests/api-test-lws_struct-json/selftest.sh 2019-12-18 14:45:31.000000000 +0000 +++ libwebsockets-4.1.6/minimal-examples/api-tests/api-test-lws_struct-json/selftest.sh 1970-01-01 00:00:00.000000000 +0000 @@ -1,24 +0,0 @@ -#!/bin/bash -# -# $1: path to minimal example binaries... -# if lws is built with -DLWS_WITH_MINIMAL_EXAMPLES=1 -# that will be ./bin from your build dir -# -# $2: path for logs and results. The results will go -# in a subdir named after the directory this script -# is in -# -# $3: offset for test index count -# -# $4: total test count -# -# $5: path to ./minimal-examples dir in lws -# -# Test return code 0: OK, 254: timed out, other: error indication - -. $5/selftests-library.sh - -COUNT_TESTS=1 - -dotest $1 $2 apiselftest -exit $FAILS diff -Nru libwebsockets-3.2.1/minimal-examples/api-tests/api-test-lws_struct-json/test2.c libwebsockets-4.1.6/minimal-examples/api-tests/api-test-lws_struct-json/test2.c --- libwebsockets-3.2.1/minimal-examples/api-tests/api-test-lws_struct-json/test2.c 1970-01-01 00:00:00.000000000 +0000 +++ libwebsockets-4.1.6/minimal-examples/api-tests/api-test-lws_struct-json/test2.c 2020-12-01 17:40:26.000000000 +0000 @@ -0,0 +1,242 @@ +/* + * lws-api-test-lws_struct-json + * + * Written in 2010-2020 by Andy Green + * + * This file is made available under the Creative Commons CC0 1.0 + * Universal Public Domain Dedication. + * + * lws_struct apis are used to serialize and deserialize your C structs and + * linked-lists in a standardized way that's very modest on memory but + * convenient and easy to maintain. + * + * This second test file shows a worked example for how to express a schema + * and both consume JSON -> struct and struct -> JSON for it. + */ + +#include + +static const char * const test2_json = +"{" + "\"config\":[" + "{" + "\"id1\":" "null," + "\"creds\":{" + "\"key1\":" "\"\\\"xxxxxxxxx\\\"\"," + "\"key2\":" "null" + "}," + "\"frequency\":" "0," + "\"arg1\":" "\"val1\"," + "\"arg2\":" "0," + "\"priority\":" "1," + "\"ssid\":" "\"\\\"nw2\\\"\"" + "}, {" + "\"id2\":" "null," + "\"creds\": {" + "\"key1\":" "\"\\\"xxxxxxxxxxxxx\\\"\"," + "\"key2\":" "null" + "}," + "\"frequency\":" "11," + "\"arg1\":" "\"val2\"," +#if defined(_WIN32) + "\"arg2\":" "2147483647," +#else + "\"arg2\":" "1420887242594," +#endif + "\"priority\":" "3," + "\"ssid\":" "\"\\\"nw1\\\"\"" + "}" + "]" +"}"; + +static const char * const test2_json_expected = + "{\"config\":[{\"creds\":{\"key1\":\"\\u0022xxxxxxxxx\\u0022\"}," + "\"arg1\":\"val1\",\"ssid\":\"\\u0022nw2\\u0022\"," + "\"frequency\":0,\"arg2\":0,\"priority\":1}," + "{\"creds\":{\"key1\":\"\\u0022xxxxxxxxxxxxx\\u0022\"}," + "\"arg1\":\"val2\",\"ssid\":\"\\u0022nw1\\u0022\"," +#if defined(_WIN32) + "\"frequency\":11,\"arg2\":2147483647,\"priority\":3}]}" +#else + "\"frequency\":11,\"arg2\":1420887242594,\"priority\":3}]}" +#endif +; + +/* + * level 3: Credentials object + */ + +typedef struct t2_cred { + const char *key1; + const char *key2; +} t2_cred_t; + +static const lws_struct_map_t lsm_t2_cred[] = { + LSM_STRING_PTR (t2_cred_t, key1, "key1"), + LSM_STRING_PTR (t2_cred_t, key2, "key2"), +}; + +/* + * level 2: Configuration object, containing a child credentials object + */ + +typedef struct t2_config { + lws_dll2_t list; + t2_cred_t *creds; + const char *id1; + const char *arg1; + const char *ssid; + unsigned int frequency; + unsigned long arg2; + unsigned int priority; +} t2_config_t; + +static const lws_struct_map_t lsm_t2_config[] = { + LSM_CHILD_PTR (t2_config_t, + creds, /* the child pointer member */ + t2_cred_t, /* the child type */ + NULL, lsm_t2_cred, /* map object for item type */ + "creds"), /* outer json object name */ + LSM_STRING_PTR (t2_config_t, id1, "id1"), + LSM_STRING_PTR (t2_config_t, arg1, "arg1"), + LSM_STRING_PTR (t2_config_t, ssid, "ssid"), + + LSM_UNSIGNED (t2_config_t, frequency, "frequency"), + LSM_UNSIGNED (t2_config_t, arg2, "arg2"), + LSM_UNSIGNED (t2_config_t, priority, "priority"), +}; + +/* + * level 1: list-of-configurations object + */ + +typedef struct t2_configs { + lws_dll2_owner_t configs; +} t2_configs_t; + +static const lws_struct_map_t lsm_t2_configs[] = { + LSM_LIST (t2_configs_t, configs, /* the list owner type/member */ + t2_config_t, list, /* the list item type/member */ + NULL, lsm_t2_config, /* map object for item type */ + "config"), /* outer json object name */ +}; + +/* + * For parsing, this lists the kind of object we expect to parse so the struct + * can be allocated polymorphically. + * + * Lws uses an explicit "schema" member so the type is known unambiguously. If + * in the incoming JSON the first member is not "schema", it will scan the + * maps listed here and instantiate the first object that has a member of that + * name. + */ + +static const lws_struct_map_t lsm_schema[] = { + LSM_SCHEMA (t2_configs_t, NULL, lsm_t2_configs, "t2"), + /* other schemata that might need parsing... */ +}; + + + +static int +t2_config_dump(struct lws_dll2 *d, void *user) +{ + t2_config_t *c = lws_container_of(d, t2_config_t, list); + + lwsl_notice("%s: id1 '%s'\n", __func__, c->id1); + lwsl_notice("%s: arg1 '%s'\n", __func__, c->arg1); + lwsl_notice("%s: ssid '%s'\n", __func__, c->ssid); + + lwsl_notice("%s: freq %d\n", __func__, c->frequency); + lwsl_notice("%s: arg2 %lu\n", __func__, c->arg2); + lwsl_notice("%s: priority %d\n", __func__, c->priority); + + lwsl_notice("%s: key1: %s, key2: %s\n", __func__, + c->creds->key1, c->creds->key2); + + return 0; +} + +static int +t2_configs_dump(t2_configs_t *t2cs) +{ + lwsl_notice("%s: number of configs: %d\n", __func__, + t2cs->configs.count); + + lws_dll2_foreach_safe(&t2cs->configs, NULL, t2_config_dump); + + return 0; +} + + +int +test2(void) +{ + lws_struct_serialize_t *ser; + struct lejp_ctx ctx; + lws_struct_args_t a; + t2_configs_t *top; + uint8_t buf[4096]; + size_t written; + int n, bad = 1; + + lwsl_notice("%s: start \n", __func__); + + memset(&a, 0, sizeof(a)); + a.map_st[0] = lsm_schema; + a.map_entries_st[0] = LWS_ARRAY_SIZE(lsm_schema); + a.ac_block_size = 512; + lws_struct_json_init_parse(&ctx, NULL, &a); + + n = lejp_parse(&ctx, (uint8_t *)test2_json, (int)strlen(test2_json)); + lwsl_notice("%s: lejp_parse %d\n", __func__, n); + if (n < 0) { + lwsl_err("%s: test2 JSON decode failed '%s'\n", + __func__, lejp_error_to_string(n)); + goto bail; + } + lwsac_info(a.ac); + + top = (t2_configs_t *)a.dest; /* the top level object */ + + if (!top) { + lwsl_err("%s: no top level object\n", __func__); + goto bail; + } + t2_configs_dump(top); + + /* 2. Let's reserialize the top level object and see what comes out */ + + ser = lws_struct_json_serialize_create(&lsm_schema[0], 1, + LSSERJ_FLAG_OMIT_SCHEMA, top); + if (!ser) { + lwsl_err("%s: unable to init serialization\n", __func__); + goto bail; + } + + do { + n = lws_struct_json_serialize(ser, buf, sizeof(buf), &written); + switch (n) { + case LSJS_RESULT_FINISH: + puts((const char *)buf); + break; + case LSJS_RESULT_CONTINUE: + case LSJS_RESULT_ERROR: + goto bail; + } + } while (n == LSJS_RESULT_CONTINUE); + + if (strcmp(test2_json_expected, (char *)buf)) { + lwsl_err("%s: expected %s\n", __func__, test2_json_expected); + goto bail; + } + + lws_struct_json_serialize_destroy(&ser); + + bad = 0; + +bail: + lwsac_free(&a.ac); + + return bad; +} diff -Nru libwebsockets-3.2.1/minimal-examples/api-tests/api-test-lws_struct_sqlite/CMakeLists.txt libwebsockets-4.1.6/minimal-examples/api-tests/api-test-lws_struct_sqlite/CMakeLists.txt --- libwebsockets-3.2.1/minimal-examples/api-tests/api-test-lws_struct_sqlite/CMakeLists.txt 1970-01-01 00:00:00.000000000 +0000 +++ libwebsockets-4.1.6/minimal-examples/api-tests/api-test-lws_struct_sqlite/CMakeLists.txt 2020-12-01 17:40:26.000000000 +0000 @@ -0,0 +1,25 @@ +project(lws-api-test-lws_struct-sqlite C) +cmake_minimum_required(VERSION 2.8) +find_package(libwebsockets CONFIG REQUIRED) +list(APPEND CMAKE_MODULE_PATH ${LWS_CMAKE_DIR}) +include(CheckCSourceCompiles) +include(LwsCheckRequirements) + +set(SAMP lws-api-test-lws_struct-sqlite) +set(SRCS main.c) + +set(requirements 1) +require_lws_config(LWS_WITH_STRUCT_SQLITE3 1 requirements) + +if (requirements) + + add_executable(${SAMP} ${SRCS}) + add_test(NAME api-test-lws_struct_sqlite COMMAND lws-api-test-lws_struct-sqlite) + + if (websockets_shared) + target_link_libraries(${SAMP} websockets_shared sqlite3 ${LIBWEBSOCKETS_DEP_LIBS}) + add_dependencies(${SAMP} websockets_shared) + else() + target_link_libraries(${SAMP} websockets sqlite3 ${LIBWEBSOCKETS_DEP_LIBS}) + endif() +endif() diff -Nru libwebsockets-3.2.1/minimal-examples/api-tests/api-test-lws_struct_sqlite/main.c libwebsockets-4.1.6/minimal-examples/api-tests/api-test-lws_struct_sqlite/main.c --- libwebsockets-3.2.1/minimal-examples/api-tests/api-test-lws_struct_sqlite/main.c 1970-01-01 00:00:00.000000000 +0000 +++ libwebsockets-4.1.6/minimal-examples/api-tests/api-test-lws_struct_sqlite/main.c 2020-12-01 17:40:26.000000000 +0000 @@ -0,0 +1,202 @@ +/* + * lws-api-test-lws_struct-sqlite + * + * Written in 2010-2020 by Andy Green + * + * This file is made available under the Creative Commons CC0 1.0 + * Universal Public Domain Dedication. + * + * lws_struct apis are used to serialize and deserialize your C structs and + * linked-lists in a standardized way that's very modest on memory but + * convenient and easy to maintain. + * + * The API test shows how to serialize and deserialize a struct with a linked- + * list of child structs in JSON using lws_struct APIs. + */ + +#include + +typedef struct teststruct { + lws_dll2_t list; /* not directly serialized */ + + char str1[32]; + const char *str2; + uint8_t u8; + uint16_t u16; + uint32_t u32; + uint64_t u64; + int32_t s32; +} teststruct_t; + +/* + * These are the members that we will serialize and deserialize, not every + * member in the struct (eg, the dll2 list member) + */ + +static const lws_struct_map_t lsm_teststruct[] = { + LSM_CARRAY (teststruct_t, str1, "str1"), + LSM_STRING_PTR (teststruct_t, str2, "str2"), + LSM_UNSIGNED (teststruct_t, u8, "u8"), + LSM_UNSIGNED (teststruct_t, u16, "u16"), + LSM_UNSIGNED (teststruct_t, u32, "u32"), + LSM_UNSIGNED (teststruct_t, u64, "u64"), + LSM_SIGNED (teststruct_t, s32, "s32"), +}; + +static const lws_struct_map_t lsm_schema_apitest[] = { + LSM_SCHEMA_DLL2 (teststruct_t, list, NULL, lsm_teststruct, "apitest") +}; + +static const char *test_string = + "No one would have believed in the last years of the nineteenth " + "century that this world was being watched keenly and closely by " + "intelligences greater than man's and yet as mortal as his own; that as " + "men busied themselves about their various concerns they were " + "scrutinised and studied, perhaps almost as narrowly as a man with a " + "microscope might scrutinise the transient creatures that swarm and " + "multiply in a drop of water. With infinite complacency men went to " + "and fro over this globe about their little affairs, serene in their " + "assurance of their empire over matter. It is possible that the " + "infusoria under the microscope do the same. No one gave a thought to " + "the older worlds of space as sources of human danger, or thought of " + "them only to dismiss the idea of life upon them as impossible or " + "improbable. It is curious to recall some of the mental habits of " + "those departed days. At most terrestrial men fancied there might be " + "other men upon Mars, perhaps inferior to themselves and ready to " + "welcome a missionary enterprise. Yet across the gulf of space, minds " + "that are to our minds as ours are to those of the beasts that perish, " + "intellects vast and cool and unsympathetic, regarded this earth with " + "envious eyes, and slowly and surely drew their plans against us. And " + "early in the twentieth century came the great disillusionment. "; + +int main(int argc, const char **argv) +{ + int e = 0, logs = LLL_USER | LLL_ERR | LLL_WARN | LLL_NOTICE; + struct lws_context_creation_info info; + struct lws_context *context; + struct lwsac *ac = NULL; + lws_dll2_owner_t resown; + teststruct_t ts, *pts; + const char *p; + sqlite3 *db; + + if ((p = lws_cmdline_option(argc, argv, "-d"))) + logs = atoi(p); + + lws_set_log_level(logs, NULL); + lwsl_user("LWS API selftest: lws_struct SQLite\n"); + + memset(&info, 0, sizeof info); /* otherwise uninitialized garbage */ + info.port = CONTEXT_PORT_NO_LISTEN; + context = lws_create_context(&info); + if (!context) { + lwsl_err("lws init failed\n"); + return 1; + } + + + unlink("_lws_apitest.sq3"); + + if (lws_struct_sq3_open(context, "_lws_apitest.sq3", 1, &db)) { + lwsl_err("%s: failed to open table\n", __func__); + goto bail; + } + + /* 1. populate the struct */ + + memset(&ts, 0, sizeof(ts)); + + lws_strncpy(ts.str1, "hello", sizeof(ts.str1)); + ts.str2 = test_string; + ts.u8 = 1; + ts.u16 = 512, + ts.u32 = 0x55aa1234; /* 1437209140, */ + ts.u64 = 0x34abcdef01ull; + ts.s32 = -1; + + /* add our struct to the dll2 owner list */ + + lws_dll2_owner_clear(&resown); + lws_dll2_add_head(&ts.list, &resown); + + /* gratuitously create the table */ + + if (lws_struct_sq3_create_table(db, lsm_schema_apitest)) { + lwsl_err("%s: Create table failed\n", __func__); + e++; + goto done; + } + + /* serialize the items on the dll2 owner */ + + if (lws_struct_sq3_serialize(db, lsm_schema_apitest, &resown, 0)) { + lwsl_err("%s: Serialize failed\n", __func__); + e++; + goto done; + } + + /* resown should be cleared by deserialize, ac is already NULL */ + + lws_dll2_owner_clear(&resown); /* make sure old resown data is gone */ + + if (lws_struct_sq3_deserialize(db, NULL, NULL, lsm_schema_apitest, + &resown, &ac, 0, 1)) { + lwsl_err("%s: Deserialize failed\n", __func__); + e++; + goto done; + } + + /* we should have 1 entry in resown now (created into the ac) */ + + if (resown.count != 1) { + lwsl_err("%s: Expected 1 result got %d\n", __func__, + resown.count); + e++; + goto done; + } + + /* + * Convert the pointer to the embedded lws_dll2 into a pointer + * to the actual struct with the correct type + */ + + pts = lws_container_of(lws_dll2_get_head(&resown), + teststruct_t, list); + + if (strcmp(pts->str1, "hello") || + strcmp(pts->str2, test_string) || + pts->u8 != 1 || + pts->u16 != 512 || + pts->u32 != 0x55aa1234 || + pts->u64 != 0x34abcdef01ull || + pts->s32 != -1) { + lwsl_err("%s: unexpected deser values: %s\n", __func__, pts->str1); + lwsl_err("%s: %s\n", __func__, pts->str2); + lwsl_err("%s: %u %u %u 0x%llx %d\n", __func__, pts->u8, pts->u16, + pts->u32, (unsigned long long)pts->u64, pts->s32); + + e++; + goto done; + } + +done: + lwsac_free(&ac); + lws_struct_sq3_close(&db); + + + if (e) + goto bail; + + lws_context_destroy(context); + + lwsl_user("Completed: PASS\n"); + + return 0; + +bail: + lws_context_destroy(context); + + lwsl_user("Completed: FAIL\n"); + + return 1; +} diff -Nru libwebsockets-3.2.1/minimal-examples/api-tests/api-test-lws_struct_sqlite/README.md libwebsockets-4.1.6/minimal-examples/api-tests/api-test-lws_struct_sqlite/README.md --- libwebsockets-3.2.1/minimal-examples/api-tests/api-test-lws_struct_sqlite/README.md 1970-01-01 00:00:00.000000000 +0000 +++ libwebsockets-4.1.6/minimal-examples/api-tests/api-test-lws_struct_sqlite/README.md 2020-12-01 17:40:26.000000000 +0000 @@ -0,0 +1,25 @@ +# lws api test lws_struct SQLITE + +Demonstrates how to use and performs selftests for lws_struct +SQLITE serialization and deserialization + +## build + +``` + $ cmake . && make +``` + +## usage + +Commandline option|Meaning +---|--- +-d |Debug verbosity in decimal, eg, -d15 + +``` + $ ./lws-api-test-lws_struct-sqlite +[2020/02/22 09:55:05:4335] U: LWS API selftest: lws_struct SQLite +[2020/02/22 09:55:05:5579] N: lws_struct_sq3_open: created _lws_apitest.sq3 owned by 0:0 mode 0600 +[2020/02/22 09:55:05:9206] U: Completed: PASS + +``` + diff -Nru libwebsockets-3.2.1/minimal-examples/api-tests/api-test-lws_tokenize/CMakeLists.txt libwebsockets-4.1.6/minimal-examples/api-tests/api-test-lws_tokenize/CMakeLists.txt --- libwebsockets-3.2.1/minimal-examples/api-tests/api-test-lws_tokenize/CMakeLists.txt 2019-12-18 14:45:31.000000000 +0000 +++ libwebsockets-4.1.6/minimal-examples/api-tests/api-test-lws_tokenize/CMakeLists.txt 2020-12-01 17:40:26.000000000 +0000 @@ -1,73 +1,19 @@ +project(lws-api-test-lws_tokenize C) cmake_minimum_required(VERSION 2.8) +find_package(libwebsockets CONFIG REQUIRED) +list(APPEND CMAKE_MODULE_PATH ${LWS_CMAKE_DIR}) include(CheckCSourceCompiles) +include(LwsCheckRequirements) set(SAMP lws-api-test-lws_tokenize) set(SRCS main.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() - - - add_executable(${SAMP} ${SRCS}) + add_test(NAME api-test-lws_tokenize COMMAND lws-api-test-lws_tokenize) if (websockets_shared) - target_link_libraries(${SAMP} websockets_shared) + target_link_libraries(${SAMP} websockets_shared ${LIBWEBSOCKETS_DEP_LIBS}) add_dependencies(${SAMP} websockets_shared) else() - target_link_libraries(${SAMP} websockets) + target_link_libraries(${SAMP} websockets ${LIBWEBSOCKETS_DEP_LIBS}) endif() diff -Nru libwebsockets-3.2.1/minimal-examples/api-tests/api-test-lws_tokenize/main.c libwebsockets-4.1.6/minimal-examples/api-tests/api-test-lws_tokenize/main.c --- libwebsockets-3.2.1/minimal-examples/api-tests/api-test-lws_tokenize/main.c 2019-12-18 14:45:31.000000000 +0000 +++ libwebsockets-4.1.6/minimal-examples/api-tests/api-test-lws_tokenize/main.c 2020-12-01 17:40:26.000000000 +0000 @@ -20,7 +20,7 @@ struct expected { lws_tokenize_elem e; const char *value; - int len; + size_t len; }; struct tests { @@ -169,8 +169,11 @@ { LWS_TOKZE_TOKEN_NAME_EQUALS, "a", 1 }, { LWS_TOKZE_TOKEN, "5", 1 }, { LWS_TOKZE_ENDED, "", 0 }, + }, + expected17[] = { + { LWS_TOKZE_TOKEN, "hello", 5 }, + { LWS_TOKZE_ENDED, "", 0 }, } - ; struct tests tests[] = { @@ -247,6 +250,10 @@ "a=5", expected16, LWS_ARRAY_SIZE(expected16), LWS_TOKENIZE_F_NO_INTEGERS }, + { + "# comment1\r\nhello #comment2\r\n#comment3", expected17, + LWS_ARRAY_SIZE(expected17), LWS_TOKENIZE_F_HASH_COMMENT + } }; /* @@ -270,6 +277,41 @@ "LWS_TOKZE_QUOTED_STRING", }; + +int +exp_cb1(void *priv, const char *name, char *out, size_t *pos, size_t olen, + size_t *exp_ofs) +{ + const char *replace = NULL; + size_t total, budget; + + if (!strcmp(name, "test")) { + replace = "replacement_string"; + total = strlen(replace); + goto expand; + } + + return LSTRX_FATAL_NAME_UNKNOWN; + +expand: + budget = olen - *pos; + total -= *exp_ofs; + if (total < budget) + budget = total; + + if (out) + memcpy(out + *pos, replace + (*exp_ofs), budget); + *exp_ofs += budget; + *pos += budget; + + if (budget == total) + return LSTRX_DONE; + + return LSTRX_FILLED_OUT; +} + +static const char *exp_inp1 = "this-is-a-${test}-for-strexp"; + int main(int argc, const char **argv) { struct lws_tokenize ts; @@ -283,6 +325,7 @@ /* | LLL_EXT */ /* | LLL_CLIENT */ /* | LLL_LATENCY */ /* | LLL_DEBUG */; int fail = 0, ok = 0, flags = 0; + char dotstar[512]; if ((p = lws_cmdline_option(argc, argv, "-d"))) logs = atoi(p); @@ -293,12 +336,162 @@ if ((p = lws_cmdline_option(argc, argv, "-f"))) flags = atoi(p); + /* lws_strexp */ + + { + size_t in_len, used_in, used_out; + lws_strexp_t exp; + char obuf[128]; + const char *p; + + obuf[0] = '\0'; + lws_strexp_init(&exp, NULL, exp_cb1, obuf, sizeof(obuf)); + n = lws_strexp_expand(&exp, exp_inp1, 28, &used_in, &used_out); + if (n != LSTRX_DONE || used_in != 28 || + strcmp(obuf, "this-is-a-replacement_string-for-strexp")) { + lwsl_notice("%s: obuf %s\n", __func__, obuf); + lwsl_err("%s: lws_strexp test 1 failed: %d\n", __func__, n); + + return 1; + } + + /* as above, but don't generate output, just find the length */ + + lws_strexp_init(&exp, NULL, exp_cb1, NULL, (size_t)-1); + n = lws_strexp_expand(&exp, exp_inp1, 28, &used_in, &used_out); + if (n != LSTRX_DONE || used_in != 28 || used_out != 39) { + lwsl_err("%s: lws_strexp test 2 failed: %d, used_out: %d\n", + __func__, n, (int)used_out); + + return 1; + } + + p = exp_inp1; + in_len = strlen(p); + memset(obuf, 0, sizeof(obuf)); + lws_strexp_init(&exp, NULL, exp_cb1, obuf, 16); + n = lws_strexp_expand(&exp, p, in_len, &used_in, &used_out); + if (n != LSTRX_FILLED_OUT || used_in != 16 || used_out != 16) { + lwsl_err("a\n"); + return 1; + } + + p += used_in; + in_len -= used_in; + + memset(obuf, 0, sizeof(obuf)); + lws_strexp_reset_out(&exp, obuf, 16); + + n = lws_strexp_expand(&exp, p, in_len, &used_in, &used_out); + if (n != LSTRX_FILLED_OUT || used_in != 5 || used_out != 16) { + lwsl_err("b: n %d, used_in %d, used_out %d\n", n, + (int)used_in, (int)used_out); + return 2; + } + + p += used_in; + in_len -= used_in; + + memset(obuf, 0, sizeof(obuf)); + lws_strexp_reset_out(&exp, obuf, 16); + + n = lws_strexp_expand(&exp, p, in_len, &used_in, &used_out); + if (n != LSTRX_DONE || used_in != 7 || used_out != 7) { + lwsl_err("c: n %d, used_in %d, used_out %d\n", n, (int)used_in, (int)used_out); + return 2; + } + } + + /* sanity check lws_strnncpy() */ + + lws_strnncpy(dotstar, "12345678", 4, sizeof(dotstar)); + if (strcmp(dotstar, "1234")) { + lwsl_err("%s: lws_strnncpy check failed\n", __func__); + + return 1; + } + lws_strnncpy(dotstar, "12345678", 8, 6); + if (strcmp(dotstar, "12345")) { + lwsl_err("%s: lws_strnncpy check failed\n", __func__); + + return 1; + } + + /* sanity check lws_nstrstr() */ + + { + static const char *t1 = "abc123456"; + const char *mcp; + + mcp = lws_nstrstr(t1, strlen(t1), "abc", 3); + if (mcp != t1) { + lwsl_err("%s: lws_nstrstr 1 failed\n", __func__); + return 1; + } + mcp = lws_nstrstr(t1, strlen(t1), "def", 3); + if (mcp != NULL) { + lwsl_err("%s: lws_nstrstr 2 failed\n", __func__); + return 1; + } + mcp = lws_nstrstr(t1, strlen(t1), "456", 3); + if (mcp != t1 + 6) { + lwsl_err("%s: lws_nstrstr 3 failed: %p\n", __func__, mcp); + return 1; + } + mcp = lws_nstrstr(t1, strlen(t1), "1", 1); + if (mcp != t1 + 3) { + lwsl_err("%s: lws_nstrstr 4 failed\n", __func__); + return 1; + } + mcp = lws_nstrstr(t1, strlen(t1), "abc1234567", 10); + if (mcp != NULL) { + lwsl_err("%s: lws_nstrstr 5 failed\n", __func__); + return 1; + } + } + + /* sanity check lws_json_simple_find() */ + + { + static const char *t1 = "{\"myname1\":true," + "\"myname2\":\"string\", " + "\"myname3\": 123}"; + size_t alen; + const char *mcp; + + mcp = lws_json_simple_find(t1, strlen(t1), "\"myname1\":", &alen); + if (mcp != t1 + 11 || alen != 4) { + lwsl_err("%s: lws_json_simple_find 1 failed: (%d) %s\n", + __func__, (int)alen, mcp); + return 1; + } + + mcp = lws_json_simple_find(t1, strlen(t1), "\"myname2\":", &alen); + if (mcp != t1 + 27 || alen != 6) { + lwsl_err("%s: lws_json_simple_find 2 failed\n", __func__); + return 1; + } + + mcp = lws_json_simple_find(t1, strlen(t1), "\"myname3\":", &alen); + if (mcp != t1 + 47 || alen != 3) { + lwsl_err("%s: lws_json_simple_find 3 failed\n", __func__); + return 1; + } + + mcp = lws_json_simple_find(t1, strlen(t1), "\"nope\":", &alen); + if (mcp != NULL) { + lwsl_err("%s: lws_json_simple_find 4 failed\n", __func__); + return 1; + } + } + p = lws_cmdline_option(argc, argv, "-s"); for (n = 0; n < (int)LWS_ARRAY_SIZE(tests); n++) { int m = 0, in_fail = fail; struct expected *exp = tests[n].exp; + memset(&ts, 0, sizeof(ts)); ts.start = tests[n].string; ts.len = strlen(ts.start); ts.flags = tests[n].flags; @@ -306,9 +499,10 @@ do { e = lws_tokenize(&ts); - lwsl_info("{ %s, \"%.*s\", %d }\n", - element_names[e + LWS_TOKZE_ERRS], - (int)ts.token_len, ts.token, + lws_strnncpy(dotstar, ts.token, ts.token_len, + sizeof(dotstar)); + lwsl_info("{ %s, \"%s\", %d }\n", + element_names[e + LWS_TOKZE_ERRS], dotstar, (int)ts.token_len); if (m == (int)tests[n].count) { @@ -328,8 +522,11 @@ if (e > 0 && (ts.token_len != exp->len || memcmp(exp->value, ts.token, exp->len))) { - lwsl_notice("fail token mismatch %d %d %.*s\n", - ts.token_len, exp->len, ts.token_len, ts.token); + lws_strnncpy(dotstar, ts.token, ts.token_len, + sizeof(dotstar)); + lwsl_notice("fail token mismatch %d %d %s\n", + (int)ts.token_len, (int)exp->len, + dotstar); fail++; break; } @@ -391,17 +588,18 @@ do { e = lws_tokenize(&ts); - printf("\t\t{ %s, \"%.*s\", %d },\n", + lws_strnncpy(dotstar, ts.token, ts.token_len, + sizeof(dotstar)); + + printf("\t\t{ %s, \"%s\", %d },\n", element_names[e + LWS_TOKZE_ERRS], - (int)ts.token_len, - ts.token, (int)ts.token_len); + dotstar, (int)ts.token_len); } while (e > 0); printf("\t}\n"); } - lwsl_user("Completed: PASS: %d, FAIL: %d\n", ok, fail); return !(ok && !fail); diff -Nru libwebsockets-3.2.1/minimal-examples/api-tests/api-test-lws_tokenize/selftest.sh libwebsockets-4.1.6/minimal-examples/api-tests/api-test-lws_tokenize/selftest.sh --- libwebsockets-3.2.1/minimal-examples/api-tests/api-test-lws_tokenize/selftest.sh 2019-12-18 14:45:31.000000000 +0000 +++ libwebsockets-4.1.6/minimal-examples/api-tests/api-test-lws_tokenize/selftest.sh 1970-01-01 00:00:00.000000000 +0000 @@ -1,24 +0,0 @@ -#!/bin/bash -# -# $1: path to minimal example binaries... -# if lws is built with -DLWS_WITH_MINIMAL_EXAMPLES=1 -# that will be ./bin from your build dir -# -# $2: path for logs and results. The results will go -# in a subdir named after the directory this script -# is in -# -# $3: offset for test index count -# -# $4: total test count -# -# $5: path to ./minimal-examples dir in lws -# -# Test return code 0: OK, 254: timed out, other: error indication - -. $5/selftests-library.sh - -COUNT_TESTS=1 - -dotest $1 $2 apiselftest -exit $FAILS diff -Nru libwebsockets-3.2.1/minimal-examples/api-tests/api-test-secure-streams/CMakeLists.txt libwebsockets-4.1.6/minimal-examples/api-tests/api-test-secure-streams/CMakeLists.txt --- libwebsockets-3.2.1/minimal-examples/api-tests/api-test-secure-streams/CMakeLists.txt 1970-01-01 00:00:00.000000000 +0000 +++ libwebsockets-4.1.6/minimal-examples/api-tests/api-test-secure-streams/CMakeLists.txt 2020-12-01 17:40:26.000000000 +0000 @@ -0,0 +1,31 @@ +project(lws-api-test-secure-streams C) +cmake_minimum_required(VERSION 2.8) +include(CheckCSourceCompiles) +include(LwsCheckRequirements) + +set(requirements 1) +require_lws_config(LWS_WITH_SECURE_STREAMS 1 requirements) +require_lws_config(LWS_WITH_TLS 1 requirements) +require_lws_config(LWS_WITH_SYS_STATE 1 requirements) +require_lws_config(LWS_WITH_SECURE_STREAMS_STATIC_POLICY_ONLY 0 requirements) + +if (requirements) + + add_executable(${PROJECT_NAME} main.c) + + if (LWS_CTEST_INTERNET_AVAILABLE) + add_test(NAME api-test-secure-streams COMMAND ${PROJECT_NAME}) + set_tests_properties(api-test-secure-streams + PROPERTIES + WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}/minimal-examples/api-tests/api-test-secure-streams + TIMEOUT 20) + endif() + + if (websockets_shared) + target_link_libraries(${PROJECT_NAME} websockets_shared ${LIBWEBSOCKETS_DEP_LIBS}) + add_dependencies(${PROJECT_NAME} websockets_shared) + else() + target_link_libraries(${PROJECT_NAME} websockets ${LIBWEBSOCKETS_DEP_LIBS}) + endif() + +endif() diff -Nru libwebsockets-3.2.1/minimal-examples/api-tests/api-test-secure-streams/main.c libwebsockets-4.1.6/minimal-examples/api-tests/api-test-secure-streams/main.c --- libwebsockets-3.2.1/minimal-examples/api-tests/api-test-secure-streams/main.c 1970-01-01 00:00:00.000000000 +0000 +++ libwebsockets-4.1.6/minimal-examples/api-tests/api-test-secure-streams/main.c 2020-12-01 17:40:26.000000000 +0000 @@ -0,0 +1,384 @@ +/* + * lws-api-test-secure-streams + * + * Written in 2010-2020 by Andy Green + * + * This file is made available under the Creative Commons CC0 1.0 + * Universal Public Domain Dedication. + * + * Let's exercise some basic SS / h1 functionality against httpbin.org + */ + +#include +#include +#include + +static int interrupted, bad = 1; +static lws_state_notify_link_t nl; +static struct lws_context *context; + +static const char * const default_ss_policy = + "{" + "\"release\":" "\"01234567\"," + "\"product\":" "\"myproduct\"," + "\"schema-version\":" "1," +#if defined(VIA_LOCALHOST_SOCKS) + "\"via-socks5\":" "\"127.0.0.1:1080\"," +#endif + + "\"retry\": [" /* named backoff / retry strategies */ + "{\"default\": {" + "\"backoff\": [" "1000," + "2000," + "3000," + "5000," + "10000" + "]," + "\"conceal\":" "5," + "\"jitterpc\":" "20," + "\"svalidping\":" "30," + "\"svalidhup\":" "35" + "}}" + "]," + "\"certs\": [" /* named individual certificates in BASE64 DER */ + /* + * Let's Encrypt certs for warmcat.com / libwebsockets.org + * + * We fetch the real policy from there using SS and switch to + * using that. + */ + + "{\"amz_root_ca1\": \"" + "MIIDQTCCAimgAwIBAgITBmyfz5m/jAo54vB4ikPmljZbyjANBgkqhkiG9w0BAQsF" + "ADA5MQswCQYDVQQGEwJVUzEPMA0GA1UEChMGQW1hem9uMRkwFwYDVQQDExBBbWF6" + "b24gUm9vdCBDQSAxMB4XDTE1MDUyNjAwMDAwMFoXDTM4MDExNzAwMDAwMFowOTEL" + "MAkGA1UEBhMCVVMxDzANBgNVBAoTBkFtYXpvbjEZMBcGA1UEAxMQQW1hem9uIFJv" + "b3QgQ0EgMTCCASIwDQYJKoZIhvcNAQEBBQADggEPADCCAQoCggEBALJ4gHHKeNXj" + "ca9HgFB0fW7Y14h29Jlo91ghYPl0hAEvrAIthtOgQ3pOsqTQNroBvo3bSMgHFzZM" + "9O6II8c+6zf1tRn4SWiw3te5djgdYZ6k/oI2peVKVuRF4fn9tBb6dNqcmzU5L/qw" + "IFAGbHrQgLKm+a/sRxmPUDgH3KKHOVj4utWp+UhnMJbulHheb4mjUcAwhmahRWa6" + "VOujw5H5SNz/0egwLX0tdHA114gk957EWW67c4cX8jJGKLhD+rcdqsq08p8kDi1L" + "93FcXmn/6pUCyziKrlA4b9v7LWIbxcceVOF34GfID5yHI9Y/QCB/IIDEgEw+OyQm" + "jgSubJrIqg0CAwEAAaNCMEAwDwYDVR0TAQH/BAUwAwEB/zAOBgNVHQ8BAf8EBAMC" + "AYYwHQYDVR0OBBYEFIQYzIU07LwMlJQuCFmcx7IQTgoIMA0GCSqGSIb3DQEBCwUA" + "A4IBAQCY8jdaQZChGsV2USggNiMOruYou6r4lK5IpDB/G/wkjUu0yKGX9rbxenDI" + "U5PMCCjjmCXPI6T53iHTfIUJrU6adTrCC2qJeHZERxhlbI1Bjjt/msv0tadQ1wUs" + "N+gDS63pYaACbvXy8MWy7Vu33PqUXHeeE6V/Uq2V8viTO96LXFvKWlJbYK8U90vv" + "o/ufQJVtMVT8QtPHRh8jrdkPSHCa2XV4cdFyQzR1bldZwgJcJmApzyMZFo6IQ6XU" + "5MsI+yMRQ+hDKXJioaldXgjUkK642M4UwtBV8ob2xJNDd2ZhwLnoQdeXeGADbkpy" + "rqXRfboQnoZsG4q5WTP468SQvvG5" + "\"}" + "]," + "\"trust_stores\": [" /* named cert chains */ + "{" + "\"name\": \"amz\"," + "\"stack\": [" + "\"amz_root_ca1\"" + "]" + "}" + "]," + "\"s\": [" + /* + * "fetch_policy" decides from where the real policy + * will be fetched, if present. Otherwise the initial + * policy is treated as the whole, hardcoded, policy. + */ + "{\"httpbin_get\": {" + "\"endpoint\":" "\"httpbin.org\"," + "\"port\":" "443," + "\"protocol\":" "\"h1\"," + "\"http_method\":" "\"GET\"," + "\"http_url\":" "\"/get\"," + "\"tls\":" "true," + "\"opportunistic\":" "true," + "\"retry\":" "\"default\"," + "\"tls_trust_store\":" "\"amz\"" + "}}," + "{\"httpbin_get404\": {" + "\"endpoint\":" "\"httpbin.org\"," + "\"port\":" "443," + "\"protocol\":" "\"h1\"," + "\"http_method\":" "\"GET\"," + "\"http_url\":" "\"/status/404\"," + "\"tls\":" "true," + "\"opportunistic\":" "true," + "\"retry\":" "\"default\"," + "\"tls_trust_store\":" "\"amz\"" + "}}," + "{\"httpbin_post\": {" + "\"endpoint\":" "\"httpbin.org\"," + "\"port\":" "443," + "\"protocol\":" "\"h1\"," + "\"http_method\":" "\"POST\"," + "\"http_url\":" "\"/post\"," + "\"tls\":" "true," + "\"opportunistic\":" "true," + "\"retry\":" "\"default\"," + "\"tls_trust_store\":" "\"amz\"" + "}}" + "}" + "]}" +; + +typedef struct atss { + const lws_ss_info_t *ssi; + size_t send; + char expect_nack; +} atss_t; + +static const atss_t *next_test; + +typedef struct myss { + struct lws_ss_handle *ss; + void *opaque_data; + /* ... application specific state ... */ + lws_sorted_usec_list_t sul; + size_t payload; + size_t sent; + char seen_eom; + char ended_well; +} myss_t; + +/* secure streams payload interface */ + +static int +myss_rx(void *userobj, const uint8_t *buf, size_t len, int flags) +{ + myss_t *m = (myss_t *)userobj; + + lwsl_hexdump_info(buf, len); + + m->payload += len; + + if (!(flags & LWSSS_FLAG_EOM)) + m->seen_eom = 1; + + return 0; +} + +static int +myss_tx_get(void *userobj, lws_ss_tx_ordinal_t ord, uint8_t *buf, size_t *len, + int *flags) +{ + return 1; /* nothing to send */ +} + +static int +myss_tx_post(void *userobj, lws_ss_tx_ordinal_t ord, uint8_t *buf, size_t *len, + int *flags) +{ + myss_t *m = (myss_t *)userobj; + size_t budget = (next_test->send - m->sent); + + if (!budget) + return 1; + + if (*len < budget) + budget = *len; + + if (!m->sent) + *flags |= LWSSS_FLAG_SOM; + + memset(buf, 0x55, budget); + *len = budget; + m->sent += budget; + if (m->sent != next_test->send) + lws_ss_request_tx(m->ss); + else + *flags |= LWSSS_FLAG_EOM; + + return 0; +} + +static int +myss_state(void *userobj, void *sh, lws_ss_constate_t state, + lws_ss_tx_ordinal_t ack) +{ + myss_t *m = (myss_t *)userobj; + + lwsl_notice("%s: %s, ord 0x%x\n", __func__, lws_ss_state_name(state), + (unsigned int)ack); + + switch (state) { + case LWSSSCS_CREATING: + lws_ss_client_connect(m->ss); + if (next_test->send) + lws_ss_request_tx_len(m->ss, (unsigned long)next_test->send); + break; + case LWSSSCS_ALL_RETRIES_FAILED: + lwsl_notice("%s: Connection failed\n", __func__); + interrupted = 1; + break; + case LWSSSCS_QOS_NACK_REMOTE: + if (next_test->expect_nack) + goto happy; + lwsl_notice("%s: remote NACK\n", __func__); + interrupted = 1; + break; + case LWSSSCS_QOS_ACK_REMOTE: + /* + * To be satisfied, we want to see the ACK_REMOTE indicating + * that the transaction went through; that we had the payload + * EOM; and that we saw at least 200 + posted bytes response + */ + + if (!m->seen_eom || m->payload < 200 + next_test->send) { + lwsl_warn("%s: ACK_REMOTE but eom %d, payload %d\n", + __func__, m->seen_eom, (int)m->payload); + interrupted = 1; + return -1; + } + +happy: + /* when we disconnect, we can go happily */ + m->ended_well = 1; + + if (!(++next_test)->ssi) { + lwsl_notice("%s: completed all tests\n", __func__); + bad = 0; + interrupted = 1; + break; + } + if (lws_ss_create(context, 0, next_test->ssi, + NULL, NULL, NULL, NULL)) { + lwsl_err("%s: failed to create secure stream\n", + __func__); + return -1; + } + break; + + case LWSSSCS_DISCONNECTED: + if (!m->ended_well) { + lwsl_warn("%s: DISCONNECTED without good end\n", + __func__); + interrupted = 1; + } + break; + default: + break; + } + + return 0; +} + +static const lws_ss_info_t ssi_get = { + .handle_offset = offsetof(myss_t, ss), + .opaque_user_data_offset = offsetof(myss_t, opaque_data), + .rx = myss_rx, + .tx = myss_tx_get, + .state = myss_state, + .user_alloc = sizeof(myss_t), + .streamtype = "httpbin_get" +}, ssi_get404 = { + .handle_offset = offsetof(myss_t, ss), + .opaque_user_data_offset = offsetof(myss_t, opaque_data), + .rx = myss_rx, + .tx = myss_tx_get, + .state = myss_state, + .user_alloc = sizeof(myss_t), + .streamtype = "httpbin_get404" +}, ssi_post = { + .handle_offset = offsetof(myss_t, ss), + .opaque_user_data_offset = offsetof(myss_t, opaque_data), + .rx = myss_rx, + .tx = myss_tx_post, + .state = myss_state, + .user_alloc = sizeof(myss_t), + .streamtype = "httpbin_post" +}; + +static const atss_t test_list[] = { + { .ssi = &ssi_get }, + { .ssi = &ssi_get404, .expect_nack = 1 }, + { .ssi = &ssi_post, .send = 4096 }, + { .ssi = NULL } +}; + + +static int +app_system_state_nf(lws_state_manager_t *mgr, lws_state_notify_link_t *link, + int current, int target) +{ + struct lws_context *context = lws_system_context_from_system_mgr(mgr); + + /* + * For the things we care about, let's notice if we are trying to get + * past them when we haven't solved them yet, and make the system + * state wait while we trigger the dependent action. + */ + switch (target) { + + case LWS_SYSTATE_OPERATIONAL: + if (current == LWS_SYSTATE_OPERATIONAL) { + + next_test = &test_list[0]; + + if (lws_ss_create(context, 0, next_test->ssi, + NULL, NULL, NULL, NULL)) { + lwsl_err("%s: failed to create secure stream\n", + __func__); + return -1; + } + } + break; + } + + return 0; +} + +static lws_state_notify_link_t * const app_notifier_list[] = { + &nl, NULL +}; + +static void +sigint_handler(int sig) +{ + interrupted = 1; +} + +int main(int argc, const char **argv) +{ + struct lws_context_creation_info info; + int n = 0; + + signal(SIGINT, sigint_handler); + + memset(&info, 0, sizeof info); + lws_cmdline_option_handle_builtin(argc, argv, &info); + + lwsl_user("LWS secure streams test client [-d]\n"); + + /* these options are mutually exclusive if given */ + + info.fd_limit_per_thread = 1 + 6 + 1; + info.port = CONTEXT_PORT_NO_LISTEN; + info.pss_policies_json = default_ss_policy; + info.options = LWS_SERVER_OPTION_EXPLICIT_VHOSTS | + LWS_SERVER_OPTION_DO_SSL_GLOBAL_INIT | + LWS_SERVER_OPTION_H2_JUST_FIX_WINDOW_UPDATE_OVERFLOW; + + /* integrate us with lws system state management when context created */ + + nl.name = "app"; + nl.notify_cb = app_system_state_nf; + info.register_notifier_list = app_notifier_list; + + /* create the context */ + + context = lws_create_context(&info); + if (!context) { + lwsl_err("lws init failed\n"); + return 1; + } + + /* the event loop */ + + while (n >= 0 && !interrupted) + n = lws_service(context, 0); + + lws_context_destroy(context); + + lwsl_user("Completed: %s\n", bad ? "failed" : "OK"); + + return bad; +} diff -Nru libwebsockets-3.2.1/minimal-examples/api-tests/api-test-secure-streams/README.md libwebsockets-4.1.6/minimal-examples/api-tests/api-test-secure-streams/README.md --- libwebsockets-3.2.1/minimal-examples/api-tests/api-test-secure-streams/README.md 1970-01-01 00:00:00.000000000 +0000 +++ libwebsockets-4.1.6/minimal-examples/api-tests/api-test-secure-streams/README.md 2020-12-01 17:40:26.000000000 +0000 @@ -0,0 +1,21 @@ +# lws api test Secure Streams + +Performs some tests against httpbin.org server +to check Secure Streams client performance + +## build + +``` + $ cmake . && make +``` + +## usage + +Commandline option|Meaning +---|--- +-d |Debug verbosity in decimal, eg, -d15 + +``` + $ ./lws-api-test-secure-streams +``` + diff -Nru libwebsockets-3.2.1/minimal-examples/api-tests/api-test-smtp_client/CMakeLists.txt libwebsockets-4.1.6/minimal-examples/api-tests/api-test-smtp_client/CMakeLists.txt --- libwebsockets-3.2.1/minimal-examples/api-tests/api-test-smtp_client/CMakeLists.txt 2019-12-18 14:45:31.000000000 +0000 +++ libwebsockets-4.1.6/minimal-examples/api-tests/api-test-smtp_client/CMakeLists.txt 2020-12-01 17:40:26.000000000 +0000 @@ -1,66 +1,13 @@ +project(lws-unit-tests-smtp-client C) cmake_minimum_required(VERSION 2.8) +find_package(libwebsockets CONFIG REQUIRED) +list(APPEND CMAKE_MODULE_PATH ${LWS_CMAKE_DIR}) include(CheckCSourceCompiles) +include(LwsCheckRequirements) set(SAMP lws-unit-tests-smtp-client) set(SRCS main.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_WITH_SMTP 1 requirements) @@ -68,9 +15,9 @@ add_executable(${SAMP} ${SRCS}) if (websockets_shared) - target_link_libraries(${SAMP} websockets_shared) + target_link_libraries(${SAMP} websockets_shared ${LIBWEBSOCKETS_DEP_LIBS}) add_dependencies(${SAMP} websockets_shared) else() - target_link_libraries(${SAMP} websockets) + target_link_libraries(${SAMP} websockets ${LIBWEBSOCKETS_DEP_LIBS}) endif() endif() diff -Nru libwebsockets-3.2.1/minimal-examples/api-tests/api-test-smtp_client/main.c libwebsockets-4.1.6/minimal-examples/api-tests/api-test-smtp_client/main.c --- libwebsockets-3.2.1/minimal-examples/api-tests/api-test-smtp_client/main.c 2019-12-18 14:45:31.000000000 +0000 +++ libwebsockets-4.1.6/minimal-examples/api-tests/api-test-smtp_client/main.c 2020-12-01 17:40:26.000000000 +0000 @@ -55,7 +55,7 @@ "\r\n.\r\n", "andy@warmcat.com"); email->done = email_sent_or_failed; - if (lws_smtp_client_add_email(instance, email)) { + if (lws_smtpc_add_email(instance, email)) { lwsl_err("%s: failed to add email\n", __func__); return 1; } @@ -163,7 +163,7 @@ * set the HELO our SMTP client will use */ -static const lws_token_map_t smtp_protocol_tokens[] = { +static const lws_token_map_t smtp_ap_tokens[] = { { .u = { .value = "lws-test-client" }, .name_index = LTMI_PSMTP_V_HELO, @@ -183,8 +183,8 @@ struct lws_context_creation_info info; lws_test_sequencer_args_t args; struct lws_context *context; + lws_abs_t *abs = NULL; struct lws_vhost *vh; - lws_abs_t abs, *instance; const char *p; /* the normal lws init */ @@ -213,32 +213,16 @@ goto bail1; } - /* create the smtp client */ + /* create the abs used to create connections */ - memset(&abs, 0, sizeof(abs)); - abs.vh = vh; - - /* select the protocol and bind its tokens */ - - abs.ap = lws_abs_protocol_get_by_name("smtp"); - if (!abs.ap) - goto bail1; - - abs.ap_tokens = smtp_protocol_tokens; - - /* select the transport and bind its tokens */ - - abs.at = lws_abs_transport_get_by_name("unit_test"); - if (!abs.at) - goto bail1; - - instance = lws_abs_bind_and_create_instance(&abs); - if (!instance) + abs = lws_abstract_alloc(vh, NULL, "smtp.unit_test", + &smtp_ap_tokens[0], NULL); + if (!abs) goto bail1; /* configure the test sequencer */ - args.abs = &abs; + args.abs = abs; args.tests = tests; args.results = results; args.results_max = LWS_ARRAY_SIZE(results); @@ -271,5 +255,7 @@ lws_context_destroy(context); + lws_abstract_free(&abs); + return !count_tests || count_passes != count_tests; } diff -Nru libwebsockets-3.2.1/minimal-examples/client-server/minimal-ws-proxy/CMakeLists.txt libwebsockets-4.1.6/minimal-examples/client-server/minimal-ws-proxy/CMakeLists.txt --- libwebsockets-3.2.1/minimal-examples/client-server/minimal-ws-proxy/CMakeLists.txt 2019-12-18 14:45:31.000000000 +0000 +++ libwebsockets-4.1.6/minimal-examples/client-server/minimal-ws-proxy/CMakeLists.txt 2020-12-01 17:40:26.000000000 +0000 @@ -1,79 +1,25 @@ +project(lws-minimal-ws-proxy C) cmake_minimum_required(VERSION 2.8) +find_package(libwebsockets CONFIG REQUIRED) +list(APPEND CMAKE_MODULE_PATH ${LWS_CMAKE_DIR}) include(CheckCSourceCompiles) +include(LwsCheckRequirements) set(SAMP lws-minimal-ws-proxy) set(SRCS minimal-ws-proxy.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_ROLE_WS 1 requirements) -require_lws_config(LWS_WITHOUT_CLIENT 0 requirements) -require_lws_config(LWS_WITHOUT_SERVER 0 requirements) +require_lws_config(LWS_WITH_CLIENT 1 requirements) +require_lws_config(LWS_WITH_SERVER 1 requirements) if (requirements) add_executable(${SAMP} ${SRCS}) if (websockets_shared) - target_link_libraries(${SAMP} websockets_shared) + target_link_libraries(${SAMP} websockets_shared ${LIBWEBSOCKETS_DEP_LIBS}) add_dependencies(${SAMP} websockets_shared) else() - target_link_libraries(${SAMP} websockets) + target_link_libraries(${SAMP} websockets ${LIBWEBSOCKETS_DEP_LIBS}) endif() endif() \ No newline at end of file diff -Nru libwebsockets-3.2.1/minimal-examples/client-server/minimal-ws-proxy/mount-origin/example.js libwebsockets-4.1.6/minimal-examples/client-server/minimal-ws-proxy/mount-origin/example.js --- libwebsockets-3.2.1/minimal-examples/client-server/minimal-ws-proxy/mount-origin/example.js 2019-12-18 14:45:31.000000000 +0000 +++ libwebsockets-4.1.6/minimal-examples/client-server/minimal-ws-proxy/mount-origin/example.js 2020-12-01 17:40:26.000000000 +0000 @@ -28,15 +28,12 @@ function new_ws(urlpath, protocol) { - if (typeof MozWebSocket != "undefined") - return new MozWebSocket(urlpath, protocol); - return new WebSocket(urlpath, protocol); } document.addEventListener("DOMContentLoaded", function() { - ws = new_ws(get_appropriate_ws_url(""), "lws-minimal-proxy"); + var ws = new_ws(get_appropriate_ws_url(""), "lws-minimal-proxy"); try { ws.onopen = function() { document.getElementById("r").disabled = 0; diff -Nru libwebsockets-3.2.1/minimal-examples/client-server/minimal-ws-proxy/mount-origin/libwebsockets.org-logo.svg libwebsockets-4.1.6/minimal-examples/client-server/minimal-ws-proxy/mount-origin/libwebsockets.org-logo.svg --- libwebsockets-3.2.1/minimal-examples/client-server/minimal-ws-proxy/mount-origin/libwebsockets.org-logo.svg 2019-12-18 14:45:31.000000000 +0000 +++ libwebsockets-4.1.6/minimal-examples/client-server/minimal-ws-proxy/mount-origin/libwebsockets.org-logo.svg 2020-12-01 17:40:26.000000000 +0000 @@ -1,120 +1,66 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + + +image/svg+xml + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff -Nru libwebsockets-3.2.1/minimal-examples/client-server/minimal-ws-proxy/protocol_lws_minimal.c libwebsockets-4.1.6/minimal-examples/client-server/minimal-ws-proxy/protocol_lws_minimal.c --- libwebsockets-3.2.1/minimal-examples/client-server/minimal-ws-proxy/protocol_lws_minimal.c 2019-12-18 14:45:31.000000000 +0000 +++ libwebsockets-4.1.6/minimal-examples/client-server/minimal-ws-proxy/protocol_lws_minimal.c 2020-12-01 17:40:26.000000000 +0000 @@ -41,6 +41,8 @@ struct lws_vhost *vhost; const struct lws_protocols *protocol; + lws_sorted_usec_list_t sul; + struct per_session_data__minimal *pss_list; /* linked-list of live pss*/ struct lws_ring *ring; /* ringbuffer holding unsent messages */ @@ -60,9 +62,12 @@ msg->len = 0; } -static int -connect_client(struct per_vhost_data__minimal *vhd) +static void +sul_connect_attempt(struct lws_sorted_usec_list *sul) { + struct per_vhost_data__minimal *vhd = + lws_container_of(sul, struct per_vhost_data__minimal, sul); + vhd->i.context = vhd->context; vhd->i.port = 443; vhd->i.address = "libwebsockets.org"; @@ -75,7 +80,9 @@ vhd->i.local_protocol_name = "lws-minimal-proxy"; vhd->i.pwsi = &vhd->client_wsi; - return !lws_client_connect_via_info(&vhd->i); + if (!lws_client_connect_via_info(&vhd->i)) + lws_sul_schedule(vhd->context, 0, &vhd->sul, + sul_connect_attempt, 10 * LWS_US_PER_SEC); } static int @@ -109,14 +116,12 @@ if (!vhd->ring) return 1; - if (connect_client(vhd)) - lws_timed_callback_vh_protocol(vhd->vhost, - vhd->protocol, - LWS_CALLBACK_USER, 1); + sul_connect_attempt(&vhd->sul); break; case LWS_CALLBACK_PROTOCOL_DESTROY: lws_ring_destroy(vhd->ring); + lws_sul_cancel(&vhd->sul); break; /* --- serving callbacks --- */ @@ -169,8 +174,8 @@ lwsl_err("CLIENT_CONNECTION_ERROR: %s\n", in ? (char *)in : "(null)"); vhd->client_wsi = NULL; - lws_timed_callback_vh_protocol(vhd->vhost, vhd->protocol, - LWS_CALLBACK_USER, 1); + lws_sul_schedule(vhd->context, 0, &vhd->sul, + sul_connect_attempt, LWS_US_PER_SEC); break; case LWS_CALLBACK_CLIENT_ESTABLISHED: @@ -214,18 +219,8 @@ case LWS_CALLBACK_CLIENT_CLOSED: vhd->client_wsi = NULL; - lws_timed_callback_vh_protocol(vhd->vhost, vhd->protocol, - LWS_CALLBACK_USER, 1); - break; - - /* rate-limited client connect retries */ - - case LWS_CALLBACK_USER: - lwsl_notice("%s: LWS_CALLBACK_USER\n", __func__); - if (connect_client(vhd)) - lws_timed_callback_vh_protocol(vhd->vhost, - vhd->protocol, - LWS_CALLBACK_USER, 1); + lws_sul_schedule(vhd->context, 0, &vhd->sul, + sul_connect_attempt, LWS_US_PER_SEC); break; default: @@ -243,37 +238,3 @@ 128, \ 0, NULL, 0 \ } - - -#if !defined (LWS_PLUGIN_STATIC) - -/* boilerplate needed if we are built as a dynamic plugin */ - -static const struct lws_protocols protocols[] = { - LWS_PLUGIN_PROTOCOL_MINIMAL -}; - -LWS_EXTERN LWS_VISIBLE int -init_protocol_minimal(struct lws_context *context, - struct lws_plugin_capability *c) -{ - if (c->api_magic != LWS_PLUGIN_API_MAGIC) { - lwsl_err("Plugin API %d, library API %d", LWS_PLUGIN_API_MAGIC, - c->api_magic); - return 1; - } - - c->protocols = protocols; - c->count_protocols = LWS_ARRAY_SIZE(protocols); - c->extensions = NULL; - c->count_extensions = 0; - - return 0; -} - -LWS_EXTERN LWS_VISIBLE int -destroy_protocol_minimal(struct lws_context *context) -{ - return 0; -} -#endif diff -Nru libwebsockets-3.2.1/minimal-examples/CMakeLists.txt libwebsockets-4.1.6/minimal-examples/CMakeLists.txt --- libwebsockets-3.2.1/minimal-examples/CMakeLists.txt 1970-01-01 00:00:00.000000000 +0000 +++ libwebsockets-4.1.6/minimal-examples/CMakeLists.txt 2020-12-01 17:40:26.000000000 +0000 @@ -0,0 +1,50 @@ +# +# libwebsockets - small server side websockets and web server implementation +# +# Copyright (C) 2010 - 2020 Andy Green +# +# Permission is hereby granted, free of charge, to any person obtaining a copy +# of this software and associated documentation files (the "Software"), to +# deal in the Software without restriction, including without limitation the +# rights to use, copy, modify, merge, publish, distribute, sublicense, and/or +# sell copies of the Software, and to permit persons to whom the Software is +# furnished to do so, subject to the following conditions: +# +# The above copyright notice and this permission notice shall be included in +# all copies or substantial portions of the Software. +# +# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING +# FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS +# IN THE SOFTWARE. + +MACRO(SUBDIRLIST result curdir) + FILE(GLOB children RELATIVE ${curdir} ${curdir}/*) + SET(dirlist "") + + FOREACH(child ${children}) + IF (IS_DIRECTORY ${curdir}/${child}) + LIST(APPEND dirlist ${child}) + ENDIF() + ENDFOREACH() + + SET(${result} ${dirlist}) +ENDMACRO() + +include_directories(${LWS_LIB_BUILD_INC_PATHS}) +link_libraries(${LIB_LIST_AT_END}) + +SUBDIRLIST(SUBDIRS "${PROJECT_SOURCE_DIR}/minimal-examples") +FOREACH(subdir ${SUBDIRS}) + + SUBDIRLIST(SUBDIRS2 "${PROJECT_SOURCE_DIR}/minimal-examples/${subdir}") + FOREACH(subdir2 ${SUBDIRS2}) + if (EXISTS "${PROJECT_SOURCE_DIR}/minimal-examples/${subdir}/${subdir2}/CMakeLists.txt") + message("Processing ${PROJECT_SOURCE_DIR}/minimal-examples/${subdir}/${subdir2}") + add_subdirectory("${PROJECT_SOURCE_DIR}/minimal-examples/${subdir}/${subdir2}") + endif() + ENDFOREACH() +ENDFOREACH() diff -Nru libwebsockets-3.2.1/minimal-examples/crypto/minimal-crypto-jwe/CMakeLists.txt libwebsockets-4.1.6/minimal-examples/crypto/minimal-crypto-jwe/CMakeLists.txt --- libwebsockets-3.2.1/minimal-examples/crypto/minimal-crypto-jwe/CMakeLists.txt 2019-12-18 14:45:31.000000000 +0000 +++ libwebsockets-4.1.6/minimal-examples/crypto/minimal-crypto-jwe/CMakeLists.txt 2020-12-01 17:40:26.000000000 +0000 @@ -1,77 +1,23 @@ +project(lws-crypto-jwe C) cmake_minimum_required(VERSION 2.8) +find_package(libwebsockets CONFIG REQUIRED) +list(APPEND CMAKE_MODULE_PATH ${LWS_CMAKE_DIR}) include(CheckCSourceCompiles) +include(LwsCheckRequirements) set(SAMP lws-crypto-jwe) set(SRCS main.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_WITH_JOSE 1 requirements) if (requirements) - add_executable(${SAMP} ${SRCS}) if (websockets_shared) - target_link_libraries(${SAMP} websockets_shared) + target_link_libraries(${SAMP} websockets_shared ${LIBWEBSOCKETS_DEP_LIBS}) add_dependencies(${SAMP} websockets_shared) else() - target_link_libraries(${SAMP} websockets) + target_link_libraries(${SAMP} websockets ${LIBWEBSOCKETS_DEP_LIBS}) endif() endif() diff -Nru libwebsockets-3.2.1/minimal-examples/crypto/minimal-crypto-jwe/main.c libwebsockets-4.1.6/minimal-examples/crypto/minimal-crypto-jwe/main.c --- libwebsockets-3.2.1/minimal-examples/crypto/minimal-crypto-jwe/main.c 2019-12-18 14:45:31.000000000 +0000 +++ libwebsockets-4.1.6/minimal-examples/crypto/minimal-crypto-jwe/main.c 2020-12-01 17:40:26.000000000 +0000 @@ -153,7 +153,10 @@ lwsl_err("Problem reading from stdin\n"); return 1; } - temp_len -= n; + + /* account for padding as well */ + + temp_len -= (int)lws_gencrypto_padded_length(LWS_AES_CBC_BLOCKLEN, n); /* grab the key */ @@ -216,7 +219,11 @@ if (lws_cmdline_option(argc, argv, "-c")) format_c(compact); else - if (write(1, compact, strlen(compact)) < 0) { + if (write(1, compact, +#if defined(WIN32) + (unsigned int) +#endif + strlen(compact)) < 0) { lwsl_err("Write stdout failed\n"); goto bail1; } diff -Nru libwebsockets-3.2.1/minimal-examples/crypto/minimal-crypto-jwk/CMakeLists.txt libwebsockets-4.1.6/minimal-examples/crypto/minimal-crypto-jwk/CMakeLists.txt --- libwebsockets-3.2.1/minimal-examples/crypto/minimal-crypto-jwk/CMakeLists.txt 2019-12-18 14:45:31.000000000 +0000 +++ libwebsockets-4.1.6/minimal-examples/crypto/minimal-crypto-jwk/CMakeLists.txt 2020-12-01 17:40:26.000000000 +0000 @@ -1,77 +1,23 @@ +project(lws-crypto-jwk C) cmake_minimum_required(VERSION 2.8) +find_package(libwebsockets CONFIG REQUIRED) +list(APPEND CMAKE_MODULE_PATH ${LWS_CMAKE_DIR}) include(CheckCSourceCompiles) +include(LwsCheckRequirements) set(SAMP lws-crypto-jwk) set(SRCS main.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_WITH_JOSE 1 requirements) if (requirements) - add_executable(${SAMP} ${SRCS}) if (websockets_shared) - target_link_libraries(${SAMP} websockets_shared) + target_link_libraries(${SAMP} websockets_shared ${LIBWEBSOCKETS_DEP_LIBS}) add_dependencies(${SAMP} websockets_shared) else() - target_link_libraries(${SAMP} websockets) + target_link_libraries(${SAMP} websockets ${LIBWEBSOCKETS_DEP_LIBS}) endif() endif() diff -Nru libwebsockets-3.2.1/minimal-examples/crypto/minimal-crypto-jwk/main.c libwebsockets-4.1.6/minimal-examples/crypto/minimal-crypto-jwk/main.c --- libwebsockets-3.2.1/minimal-examples/crypto/minimal-crypto-jwk/main.c 2019-12-18 14:45:31.000000000 +0000 +++ libwebsockets-4.1.6/minimal-examples/crypto/minimal-crypto-jwk/main.c 2020-12-01 17:40:26.000000000 +0000 @@ -123,16 +123,16 @@ } if ((p = lws_cmdline_option(argc, argv, "--kid"))) - lws_jwk_strdup_meta(&jwk, JWK_META_KID, p, strlen(p)); + lws_jwk_strdup_meta(&jwk, JWK_META_KID, p, (int)strlen(p)); if ((p = lws_cmdline_option(argc, argv, "--use"))) - lws_jwk_strdup_meta(&jwk, JWK_META_USE, p, strlen(p)); + lws_jwk_strdup_meta(&jwk, JWK_META_USE, p, (int)strlen(p)); if ((p = lws_cmdline_option(argc, argv, "--alg"))) - lws_jwk_strdup_meta(&jwk, JWK_META_ALG, p, strlen(p)); + lws_jwk_strdup_meta(&jwk, JWK_META_ALG, p, (int)strlen(p)); if ((p = lws_cmdline_option(argc, argv, "--key-ops"))) - lws_jwk_strdup_meta(&jwk, JWK_META_KEY_OPS, p, strlen(p)); + lws_jwk_strdup_meta(&jwk, JWK_META_KEY_OPS, p, (int)strlen(p)); if ((p = lws_cmdline_option(argc, argv, "--public")) && kty != LWS_GENCRYPTO_KTY_OCT) { @@ -156,7 +156,11 @@ if (lws_cmdline_option(argc, argv, "-c")) format_c(fd, key); else { - if (write(fd, key, strlen(key)) < 0) { + if (write(fd, key, +#if defined(WIN32) + (unsigned int) +#endif + strlen(key)) < 0) { lwsl_err("Write public failed\n"); return 1; } @@ -167,7 +171,7 @@ /* private version */ - if (lws_jwk_export(&jwk, 1, key, &vl) < 0) { + if (lws_jwk_export(&jwk, LWSJWKF_EXPORT_PRIVATE, key, &vl) < 0) { lwsl_err("lws_jwk_export failed\n"); return 1; @@ -177,7 +181,11 @@ if (format_c(1, key) < 0) return 1; } else - if (write(1, key, strlen(key)) < 0) { + if (write(1, key, +#if defined(WIN32) + (unsigned int) +#endif + strlen(key)) < 0) { lwsl_err("Write stdout failed\n"); return 1; } diff -Nru libwebsockets-3.2.1/minimal-examples/crypto/minimal-crypto-jws/CMakeLists.txt libwebsockets-4.1.6/minimal-examples/crypto/minimal-crypto-jws/CMakeLists.txt --- libwebsockets-3.2.1/minimal-examples/crypto/minimal-crypto-jws/CMakeLists.txt 2019-12-18 14:45:31.000000000 +0000 +++ libwebsockets-4.1.6/minimal-examples/crypto/minimal-crypto-jws/CMakeLists.txt 2020-12-01 17:40:26.000000000 +0000 @@ -1,66 +1,13 @@ +project(lws-crypto-jws C) cmake_minimum_required(VERSION 2.8) +find_package(libwebsockets CONFIG REQUIRED) +list(APPEND CMAKE_MODULE_PATH ${LWS_CMAKE_DIR}) include(CheckCSourceCompiles) +include(LwsCheckRequirements) set(SAMP lws-crypto-jws) set(SRCS main.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_WITH_JOSE 1 requirements) @@ -69,9 +16,9 @@ add_executable(${SAMP} ${SRCS}) if (websockets_shared) - target_link_libraries(${SAMP} websockets_shared) + target_link_libraries(${SAMP} websockets_shared ${LIBWEBSOCKETS_DEP_LIBS}) add_dependencies(${SAMP} websockets_shared) else() - target_link_libraries(${SAMP} websockets) + target_link_libraries(${SAMP} websockets ${LIBWEBSOCKETS_DEP_LIBS}) endif() endif() diff -Nru libwebsockets-3.2.1/minimal-examples/crypto/minimal-crypto-jws/main.c libwebsockets-4.1.6/minimal-examples/crypto/minimal-crypto-jws/main.c --- libwebsockets-3.2.1/minimal-examples/crypto/minimal-crypto-jws/main.c 2019-12-18 14:45:31.000000000 +0000 +++ libwebsockets-4.1.6/minimal-examples/crypto/minimal-crypto-jws/main.c 2020-12-01 17:40:26.000000000 +0000 @@ -152,7 +152,11 @@ /* dump the compact JWS representation on stdout */ - if (write(1, compact, strlen(compact)) < 0) { + if (write(1, compact, +#if defined(WIN32) + (unsigned int) +#endif + strlen(compact)) < 0) { lwsl_err("Write stdout failed\n"); goto bail1; } diff -Nru libwebsockets-3.2.1/minimal-examples/crypto/minimal-crypto-x509/CMakeLists.txt libwebsockets-4.1.6/minimal-examples/crypto/minimal-crypto-x509/CMakeLists.txt --- libwebsockets-3.2.1/minimal-examples/crypto/minimal-crypto-x509/CMakeLists.txt 2019-12-18 14:45:31.000000000 +0000 +++ libwebsockets-4.1.6/minimal-examples/crypto/minimal-crypto-x509/CMakeLists.txt 2020-12-01 17:40:26.000000000 +0000 @@ -1,66 +1,13 @@ +project(lws-crypto-x509 C) cmake_minimum_required(VERSION 2.8) +find_package(libwebsockets CONFIG REQUIRED) +list(APPEND CMAKE_MODULE_PATH ${LWS_CMAKE_DIR}) include(CheckCSourceCompiles) +include(LwsCheckRequirements) set(SAMP lws-crypto-x509) set(SRCS main.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_WITH_JOSE 1 requirements) @@ -69,9 +16,9 @@ add_executable(${SAMP} ${SRCS}) if (websockets_shared) - target_link_libraries(${SAMP} websockets_shared) + target_link_libraries(${SAMP} websockets_shared ${LIBWEBSOCKETS_DEP_LIBS}) add_dependencies(${SAMP} websockets_shared) else() - target_link_libraries(${SAMP} websockets) + target_link_libraries(${SAMP} websockets ${LIBWEBSOCKETS_DEP_LIBS}) endif() endif() diff -Nru libwebsockets-3.2.1/minimal-examples/crypto/minimal-crypto-x509/main.c libwebsockets-4.1.6/minimal-examples/crypto/minimal-crypto-x509/main.c --- libwebsockets-3.2.1/minimal-examples/crypto/minimal-crypto-x509/main.c 2019-12-18 14:45:31.000000000 +0000 +++ libwebsockets-4.1.6/minimal-examples/crypto/minimal-crypto-x509/main.c 2020-12-01 17:40:26.000000000 +0000 @@ -126,7 +126,7 @@ } if ((p = lws_cmdline_option(argc, argv, "--alg"))) - lws_jwk_strdup_meta(&jwk, JWK_META_ALG, p, strlen(p)); + lws_jwk_strdup_meta(&jwk, JWK_META_ALG, p, (int)strlen(p)); lwsl_info("JWK version of trusted cert:\n"); lws_jwk_dump(&jwk); @@ -143,7 +143,7 @@ lwsl_info("JWK version of cert:\n"); if ((p = lws_cmdline_option(argc, argv, "--alg"))) - lws_jwk_strdup_meta(&jwk, JWK_META_ALG, p, strlen(p)); + lws_jwk_strdup_meta(&jwk, JWK_META_ALG, p, (int)strlen(p)); lws_jwk_dump(&jwk); /* only print public if he doesn't provide private */ @@ -172,13 +172,13 @@ } if ((p = lws_cmdline_option(argc, argv, "--alg"))) - lws_jwk_strdup_meta(&jwk, JWK_META_ALG, p, strlen(p)); + lws_jwk_strdup_meta(&jwk, JWK_META_ALG, p, (int)strlen(p)); lwsl_info("JWK version of cert + privkey:\n"); lws_jwk_dump(&jwk); lwsl_notice("Issuing Cert + Private JWK on stdout\n"); n = sizeof(pembuf); - if (lws_jwk_export(&jwk, 1, pembuf, &n)) + if (lws_jwk_export(&jwk, LWSJWKF_EXPORT_PRIVATE, pembuf, &n)) puts(pembuf); } diff -Nru libwebsockets-3.2.1/minimal-examples/dbus-client/minimal-dbus-client/CMakeLists.txt libwebsockets-4.1.6/minimal-examples/dbus-client/minimal-dbus-client/CMakeLists.txt --- libwebsockets-3.2.1/minimal-examples/dbus-client/minimal-dbus-client/CMakeLists.txt 2019-12-18 14:45:31.000000000 +0000 +++ libwebsockets-4.1.6/minimal-examples/dbus-client/minimal-dbus-client/CMakeLists.txt 2020-12-01 17:40:26.000000000 +0000 @@ -1,120 +1,34 @@ +project(lws-minimal-dbus-client C) cmake_minimum_required(VERSION 2.8) +find_package(libwebsockets CONFIG REQUIRED) +list(APPEND CMAKE_MODULE_PATH ${LWS_CMAKE_DIR}) include(CheckCSourceCompiles) include(CheckLibraryExists) +include(LwsCheckRequirements) set(SAMP lws-minimal-dbus-client) set(SRCS minimal-dbus-client.c) -if (NOT LWS_WITH_MINIMAL_EXAMPLES) - CHECK_LIBRARY_EXISTS(dbus-1 dbus_connection_set_watch_functions "" LWS_HAVE_LIBDBUS) - if (NOT LWS_HAVE_LIBDBUS) - message(FATAL_ERROR "Install dbus-devel, or libdbus-1-dev etc") - endif() - - if (NOT LWS_DBUS_LIB) - set(LWS_DBUS_LIB "dbus-1") - endif() - - if (NOT LWS_DBUS_INCLUDE1) - # look in fedora and debian / ubuntu place - if (EXISTS "/usr/include/dbus-1.0") - set(LWS_DBUS_INCLUDE1 "/usr/include/dbus-1.0") - else() - message(FATAL_ERROR "Set LWS_DBUS_INCLUDE1 to /usr/include/dbus-1.0 or wherever the main dbus includes are") - endif() - endif() - - if (NOT LWS_DBUS_INCLUDE2) - # look in fedora... debian / ubuntu has the ARCH in the path... - if (EXISTS "/usr/lib64/dbus-1.0/include") - set(LWS_DBUS_INCLUDE2 "/usr/lib64/dbus-1.0/include") - else() - message(FATAL_ERROR "Set LWS_DBUS_INCLUDE2 to /usr/lib/ARCH-linux-gnu/dbus-1.0/include or wherever dbus-arch-deps.h is on your system") - endif() - endif() - - set(CMAKE_REQUIRED_INCLUDES ${CMAKE_REQUIRED_INCLUDES};${LWS_DBUS_INCLUDE1};${LWS_DBUS_INCLUDE2}) - - if (NOT LWS_DBUS_INCLUDE1 OR NOT LWS_DBUS_INCLUDE2) - message(FATAL_ERROR "To build with libdbus, LWS_DBUS_INCLUDE1/2 must be given. See lib/roles/dbus/README.md") - endif() - -endif() - -# 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_ROLE_DBUS 1 requirements) -require_lws_config(LWS_WITHOUT_CLIENT 0 requirements) +require_lws_config(LWS_WITH_CLIENT 1 requirements) -if (requirements) +if (NOT MSVC AND NOT WIN32 AND requirements) add_executable(${SAMP} ${SRCS}) - + + if (NOT LWS_PLAT_FREERTOS) + find_package(PkgConfig QUIET) + pkg_check_modules(PC_DBUS1 dbus-1 QUIET) + list(APPEND LWS_DBUS_INCLUDE1 ${PC_DBUS1_INCLUDE_DIRS}) + list(APPEND LWS_DBUS_LIB "${PC_DBUS1_LIBRARIES};dl") + endif() + include_directories("${LWS_DBUS_INCLUDE1}") - include_directories("${LWS_DBUS_INCLUDE2}") - list(APPEND LIB_LIST dbus-1) if (websockets_shared) - target_link_libraries(${SAMP} websockets_shared) + target_link_libraries(${SAMP} websockets_shared ${LIBWEBSOCKETS_DEP_LIBS}) add_dependencies(${SAMP} websockets_shared ${LWS_DBUS_LIB}) else() - target_link_libraries(${SAMP} websockets ${LWS_DBUS_LIB}) + target_link_libraries(${SAMP} websockets ${LWS_DBUS_LIB} ${LIBWEBSOCKETS_DEP_LIBS}) endif() endif() diff -Nru libwebsockets-3.2.1/minimal-examples/dbus-client/minimal-dbus-ws-proxy-testclient/CMakeLists.txt libwebsockets-4.1.6/minimal-examples/dbus-client/minimal-dbus-ws-proxy-testclient/CMakeLists.txt --- libwebsockets-3.2.1/minimal-examples/dbus-client/minimal-dbus-ws-proxy-testclient/CMakeLists.txt 2019-12-18 14:45:31.000000000 +0000 +++ libwebsockets-4.1.6/minimal-examples/dbus-client/minimal-dbus-ws-proxy-testclient/CMakeLists.txt 2020-12-01 17:40:26.000000000 +0000 @@ -1,120 +1,31 @@ +project(lws-minimal-dbus-ws-proxy-testclient C) cmake_minimum_required(VERSION 2.8) +find_package(libwebsockets CONFIG REQUIRED) +list(APPEND CMAKE_MODULE_PATH ${LWS_CMAKE_DIR}) include(CheckCSourceCompiles) include(CheckLibraryExists) +include(LwsCheckRequirements) -set(SAMP lws-minimal-dbus-ws-proxy-testclient) -set(SRCS minimal-dbus-ws-proxy-testclient.c) - -if (NOT LWS_WITH_MINIMAL_EXAMPLES) - CHECK_LIBRARY_EXISTS(dbus-1 dbus_connection_set_watch_functions "" LWS_HAVE_LIBDBUS) - if (NOT LWS_HAVE_LIBDBUS) - message(FATAL_ERROR "Install dbus-devel, or libdbus-1-dev etc") - endif() - - if (NOT LWS_DBUS_LIB) - set(LWS_DBUS_LIB "dbus-1") - endif() - - if (NOT LWS_DBUS_INCLUDE1) - # look in fedora and debian / ubuntu place - if (EXISTS "/usr/include/dbus-1.0") - set(LWS_DBUS_INCLUDE1 "/usr/include/dbus-1.0") - else() - message(FATAL_ERROR "Set LWS_DBUS_INCLUDE1 to /usr/include/dbus-1.0 or wherever the main dbus includes are") - endif() - endif() - - if (NOT LWS_DBUS_INCLUDE2) - # look in fedora... debian / ubuntu has the ARCH in the path... - if (EXISTS "/usr/lib64/dbus-1.0/include") - set(LWS_DBUS_INCLUDE2 "/usr/lib64/dbus-1.0/include") - else() - message(FATAL_ERROR "Set LWS_DBUS_INCLUDE2 to /usr/lib/ARCH-linux-gnu/dbus-1.0/include or wherever dbus-arch-deps.h is on your system") - endif() - endif() - - set(CMAKE_REQUIRED_INCLUDES ${CMAKE_REQUIRED_INCLUDES};${LWS_DBUS_INCLUDE1};${LWS_DBUS_INCLUDE2}) - - if (NOT LWS_DBUS_INCLUDE1 OR NOT LWS_DBUS_INCLUDE2) - message(FATAL_ERROR "To build with libdbus, LWS_DBUS_INCLUDE1/2 must be given. See lib/roles/dbus/README.md") - endif() - -endif() - -# 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() +set(requirements 1) +require_lws_config(LWS_ROLE_DBUS 1 requirements) +require_lws_config(LWS_WITH_CLIENT 1 requirements) - 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() +if (NOT MSVC AND NOT WIN32 AND requirements) + add_executable(${PROJECT_NAME} minimal-dbus-ws-proxy-testclient.c) + if (NOT LWS_PLAT_FREERTOS) + find_package(PkgConfig QUIET) + pkg_check_modules(PC_DBUS1 dbus-1 QUIET) + list(APPEND LWS_DBUS_INCLUDE1 ${PC_DBUS1_INCLUDE_DIRS}) + list(APPEND LWS_DBUS_LIB "${PC_DBUS1_LIBRARIES};dl") endif() -ENDMACRO() - -set(requirements 1) -require_lws_config(LWS_ROLE_DBUS 1 requirements) -require_lws_config(LWS_WITHOUT_CLIENT 0 requirements) - -if (requirements) - add_executable(${SAMP} ${SRCS}) - include_directories("${LWS_DBUS_INCLUDE1}") - include_directories("${LWS_DBUS_INCLUDE2}") - list(APPEND LIB_LIST dbus-1) - + message("project ${PROJECT_NAME}") if (websockets_shared) - target_link_libraries(${SAMP} websockets_shared) - add_dependencies(${SAMP} websockets_shared ${LWS_DBUS_LIB}) + target_link_libraries(${PROJECT_NAME} websockets_shared ${LIBWEBSOCKETS_DEP_LIBS}) + add_dependencies(${PROJECT_NAME} websockets_shared ${LWS_DBUS_LIB}) else() - target_link_libraries(${SAMP} websockets ${LWS_DBUS_LIB}) + target_link_libraries(${PROJECT_NAME} websockets ${LWS_DBUS_LIB} ${LIBWEBSOCKETS_DEP_LIBS}) endif() endif() diff -Nru libwebsockets-3.2.1/minimal-examples/dbus-client/minimal-dbus-ws-proxy-testclient/minimal-dbus-ws-proxy-testclient.c libwebsockets-4.1.6/minimal-examples/dbus-client/minimal-dbus-ws-proxy-testclient/minimal-dbus-ws-proxy-testclient.c --- libwebsockets-3.2.1/minimal-examples/dbus-client/minimal-dbus-ws-proxy-testclient/minimal-dbus-ws-proxy-testclient.c 2019-12-18 14:45:31.000000000 +0000 +++ libwebsockets-4.1.6/minimal-examples/dbus-client/minimal-dbus-ws-proxy-testclient/minimal-dbus-ws-proxy-testclient.c 2020-12-01 17:40:26.000000000 +0000 @@ -43,6 +43,8 @@ struct lws_dbus_ctx_wsproxy_client { struct lws_dbus_ctx ctx; + lws_sorted_usec_list_t sul; + enum lws_dbus_client_state state; }; @@ -309,83 +311,56 @@ return ret; } -/* - * Stub lws protocol, just so we can get synchronous timers conveniently. - * - * Set up a 1Hz timer and if our connection state is suitable, use that - * to write mirror protocol drawing packets to the proxied ws connection - */ - -static int -callback_just_timer(struct lws *wsi, enum lws_callback_reasons reason, - void *user, void *in, size_t len) +static void +sul_timer(struct lws_sorted_usec_list *sul) { char payload[64]; const char *ws_pkt = payload; DBusMessage *msg; - switch (reason) { - case LWS_CALLBACK_PROTOCOL_INIT: - case LWS_CALLBACK_USER: - lwsl_info("%s: LWS_CALLBACK_USER\n", __func__); - - if (!dbus_ctx || dbus_ctx->state != LDCS_CONN_ONWARD) - goto again; - - if (autoexit_budget > 0) { - if (!--autoexit_budget) { - lwsl_notice("reached autoexit budget\n"); - interrupted = 1; - break; - } - } + if (!dbus_ctx || dbus_ctx->state != LDCS_CONN_ONWARD) + goto again; - msg = dbus_message_new_method_call(THIS_BUSNAME, THIS_OBJECT, - THIS_INTERFACE, "Send"); - if (!msg) - break; - - lws_snprintf(payload, sizeof(payload), "d #%06X %d %d %d %d;", - rand() & 0xffffff, rand() % 480, rand() % 300, - rand() % 480, rand() % 300); - - if (!dbus_message_append_args(msg, DBUS_TYPE_STRING, &ws_pkt, - DBUS_TYPE_INVALID)) { - dbus_message_unref(msg); - break; + if (autoexit_budget > 0) { + if (!--autoexit_budget) { + lwsl_notice("reached autoexit budget\n"); + interrupted = 1; + return; } + } - if (!dbus_connection_send_with_reply(dbus_ctx->ctx.conn, msg, - &dbus_ctx->ctx.pc, - DBUS_TIMEOUT_USE_DEFAULT)) { - lwsl_err("%s: unable to send\n", __func__); - dbus_message_unref(msg); - break; - } + msg = dbus_message_new_method_call(THIS_BUSNAME, THIS_OBJECT, + THIS_INTERFACE, "Send"); + if (!msg) + goto again; - dbus_message_unref(msg); - dbus_pending_call_set_notify(dbus_ctx->ctx.pc, - pending_call_notify, - &dbus_ctx->ctx, NULL); - count_tx++; + lws_snprintf(payload, sizeof(payload), "d #%06X %d %d %d %d;", + rand() & 0xffffff, rand() % 480, rand() % 300, + rand() % 480, rand() % 300); -again: - lws_timed_callback_vh_protocol(lws_get_vhost(wsi), - lws_get_protocol(wsi), - LWS_CALLBACK_USER, 2); - break; - default: - break; + if (!dbus_message_append_args(msg, DBUS_TYPE_STRING, &ws_pkt, + DBUS_TYPE_INVALID)) { + dbus_message_unref(msg); + goto again; } - return 0; -} + if (!dbus_connection_send_with_reply(dbus_ctx->ctx.conn, msg, + &dbus_ctx->ctx.pc, + DBUS_TIMEOUT_USE_DEFAULT)) { + lwsl_err("%s: unable to send\n", __func__); + dbus_message_unref(msg); + goto again; + } -static struct lws_protocols protocols[] = { - { "_just_timer", callback_just_timer, 0, 10, 0, NULL, 0 }, - { } -}; + dbus_message_unref(msg); + dbus_pending_call_set_notify(dbus_ctx->ctx.pc, + pending_call_notify, + &dbus_ctx->ctx, NULL); + count_tx++; +again: + lws_sul_schedule(context, 0, &dbus_ctx->sul, sul_timer, 2 * LWS_US_PER_SEC); +} int main(int argc, const char **argv) { @@ -413,7 +388,6 @@ memset(&info, 0, sizeof info); /* otherwise uninitialized garbage */ info.options = LWS_SERVER_OPTION_EXPLICIT_VHOSTS; - info.protocols = protocols; context = lws_create_context(&info); if (!context) { lwsl_err("lws init failed\n"); @@ -431,6 +405,9 @@ if (!dbus_ctx) goto bail1; + lws_sul_schedule(context, 0, &dbus_ctx->sul, sul_timer, LWS_US_PER_SEC); + + if (remote_method_call(dbus_ctx)) goto bail2; diff -Nru libwebsockets-3.2.1/minimal-examples/dbus-server/minimal-dbus-server/CMakeLists.txt libwebsockets-4.1.6/minimal-examples/dbus-server/minimal-dbus-server/CMakeLists.txt --- libwebsockets-3.2.1/minimal-examples/dbus-server/minimal-dbus-server/CMakeLists.txt 2019-12-18 14:45:31.000000000 +0000 +++ libwebsockets-4.1.6/minimal-examples/dbus-server/minimal-dbus-server/CMakeLists.txt 2020-12-01 17:40:26.000000000 +0000 @@ -1,120 +1,34 @@ +project(lws-minimal-dbus-server C) cmake_minimum_required(VERSION 2.8) +find_package(libwebsockets CONFIG REQUIRED) +list(APPEND CMAKE_MODULE_PATH ${LWS_CMAKE_DIR}) include(CheckCSourceCompiles) include(CheckLibraryExists) +include(LwsCheckRequirements) set(SAMP lws-minimal-dbus-server) set(SRCS main.c) -if (NOT LWS_WITH_MINIMAL_EXAMPLES) - CHECK_LIBRARY_EXISTS(dbus-1 dbus_connection_set_watch_functions "" LWS_HAVE_LIBDBUS) - if (NOT LWS_HAVE_LIBDBUS) - message(FATAL_ERROR "Install dbus-devel, or libdbus-1-dev etc") - endif() - - if (NOT LWS_DBUS_LIB) - set(LWS_DBUS_LIB "dbus-1") - endif() - - if (NOT LWS_DBUS_INCLUDE1) - # look in fedora and debian / ubuntu place - if (EXISTS "/usr/include/dbus-1.0") - set(LWS_DBUS_INCLUDE1 "/usr/include/dbus-1.0") - else() - message(FATAL_ERROR "Set LWS_DBUS_INCLUDE1 to /usr/include/dbus-1.0 or wherever the main dbus includes are") - endif() - endif() - - if (NOT LWS_DBUS_INCLUDE2) - # look in fedora... debian / ubuntu has the ARCH in the path... - if (EXISTS "/usr/lib64/dbus-1.0/include") - set(LWS_DBUS_INCLUDE2 "/usr/lib64/dbus-1.0/include") - else() - message(FATAL_ERROR "Set LWS_DBUS_INCLUDE2 to /usr/lib/ARCH-linux-gnu/dbus-1.0/include or wherever dbus-arch-deps.h is on your system") - endif() - endif() - - set(CMAKE_REQUIRED_INCLUDES ${CMAKE_REQUIRED_INCLUDES};${LWS_DBUS_INCLUDE1};${LWS_DBUS_INCLUDE2}) - - if (NOT LWS_DBUS_INCLUDE1 OR NOT LWS_DBUS_INCLUDE2) - message(FATAL_ERROR "To build with libdbus, LWS_DBUS_INCLUDE1/2 must be given. See lib/roles/dbus/README.md") - endif() - -endif() - -# 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_ROLE_DBUS 1 requirements) -require_lws_config(LWS_WITHOUT_SERVER 0 requirements) +require_lws_config(LWS_WITH_SERVER 1 requirements) -if (requirements) +if (NOT MSVC AND NOT WIN32 AND requirements) add_executable(${SAMP} ${SRCS}) - + + if (NOT LWS_PLAT_FREERTOS) + find_package(PkgConfig QUIET) + pkg_check_modules(PC_DBUS1 dbus-1 QUIET) + list(APPEND LWS_DBUS_INCLUDE1 ${PC_DBUS1_INCLUDE_DIRS}) + list(APPEND LWS_DBUS_LIB "${PC_DBUS1_LIBRARIES};dl") + endif() + include_directories("${LWS_DBUS_INCLUDE1}") - include_directories("${LWS_DBUS_INCLUDE2}") - list(APPEND LIB_LIST dbus-1) if (websockets_shared) - target_link_libraries(${SAMP} websockets_shared) + target_link_libraries(${SAMP} websockets_shared ${LIBWEBSOCKETS_DEP_LIBS}) add_dependencies(${SAMP} websockets_shared ${LWS_DBUS_LIB}) else() - target_link_libraries(${SAMP} websockets ${LWS_DBUS_LIB}) + target_link_libraries(${SAMP} websockets ${LWS_DBUS_LIB} ${LIBWEBSOCKETS_DEP_LIBS}) endif() endif() diff -Nru libwebsockets-3.2.1/minimal-examples/dbus-server/minimal-dbus-ws-proxy/CMakeLists.txt libwebsockets-4.1.6/minimal-examples/dbus-server/minimal-dbus-ws-proxy/CMakeLists.txt --- libwebsockets-3.2.1/minimal-examples/dbus-server/minimal-dbus-ws-proxy/CMakeLists.txt 2019-12-18 14:45:31.000000000 +0000 +++ libwebsockets-4.1.6/minimal-examples/dbus-server/minimal-dbus-ws-proxy/CMakeLists.txt 2020-12-01 17:40:26.000000000 +0000 @@ -1,122 +1,36 @@ +project(lws-minimal-dbus-ws-proxy C) cmake_minimum_required(VERSION 2.8) +find_package(libwebsockets CONFIG REQUIRED) +list(APPEND CMAKE_MODULE_PATH ${LWS_CMAKE_DIR}) include(CheckCSourceCompiles) include(CheckLibraryExists) +include(LwsCheckRequirements) set(SAMP lws-minimal-dbus-ws-proxy) set(SRCS main.c) -if (NOT LWS_WITH_MINIMAL_EXAMPLES) - CHECK_LIBRARY_EXISTS(dbus-1 dbus_connection_set_watch_functions "" LWS_HAVE_LIBDBUS) - if (NOT LWS_HAVE_LIBDBUS) - message(FATAL_ERROR "Install dbus-devel, or libdbus-1-dev etc") - endif() - - if (NOT LWS_DBUS_LIB) - set(LWS_DBUS_LIB "dbus-1") - endif() - - if (NOT LWS_DBUS_INCLUDE1) - # look in fedora and debian / ubuntu place - if (EXISTS "/usr/include/dbus-1.0") - set(LWS_DBUS_INCLUDE1 "/usr/include/dbus-1.0") - else() - message(FATAL_ERROR "Set LWS_DBUS_INCLUDE1 to /usr/include/dbus-1.0 or wherever the main dbus includes are") - endif() - endif() - - if (NOT LWS_DBUS_INCLUDE2) - # look in fedora... debian / ubuntu has the ARCH in the path... - if (EXISTS "/usr/lib64/dbus-1.0/include") - set(LWS_DBUS_INCLUDE2 "/usr/lib64/dbus-1.0/include") - else() - message(FATAL_ERROR "Set LWS_DBUS_INCLUDE2 to /usr/lib/ARCH-linux-gnu/dbus-1.0/include or wherever dbus-arch-deps.h is on your system") - endif() - endif() - - set(CMAKE_REQUIRED_INCLUDES ${CMAKE_REQUIRED_INCLUDES};${LWS_DBUS_INCLUDE1};${LWS_DBUS_INCLUDE2}) - - if (NOT LWS_DBUS_INCLUDE1 OR NOT LWS_DBUS_INCLUDE2) - message(FATAL_ERROR "To build with libdbus, LWS_DBUS_INCLUDE1/2 must be given. See lib/roles/dbus/README.md") - endif() - -endif() - -# 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_ROLE_DBUS 1 requirements) require_lws_config(LWS_ROLE_WS 1 requirements) -require_lws_config(LWS_WITHOUT_SERVER 0 requirements) -require_lws_config(LWS_WITHOUT_CLIENT 0 requirements) +require_lws_config(LWS_WITH_SERVER 1 requirements) +require_lws_config(LWS_WITH_CLIENT 1 requirements) -if (requirements) +if (NOT MSVC AND NOT WIN32 AND requirements) add_executable(${SAMP} ${SRCS}) + if (NOT LWS_PLAT_FREERTOS) + find_package(PkgConfig QUIET) + pkg_check_modules(PC_DBUS1 dbus-1 QUIET) + list(APPEND LWS_DBUS_INCLUDE1 ${PC_DBUS1_INCLUDE_DIRS}) + list(APPEND LWS_DBUS_LIB "${PC_DBUS1_LIBRARIES};dl") + endif() + include_directories("${LWS_DBUS_INCLUDE1}") - include_directories("${LWS_DBUS_INCLUDE2}") - list(APPEND LIB_LIST dbus-1) if (websockets_shared) - target_link_libraries(${SAMP} websockets_shared) + target_link_libraries(${SAMP} websockets_shared ${LIBWEBSOCKETS_DEP_LIBS}) add_dependencies(${SAMP} websockets_shared ${LWS_DBUS_LIB}) else() - target_link_libraries(${SAMP} websockets ${LWS_DBUS_LIB}) + target_link_libraries(${SAMP} websockets ${LWS_DBUS_LIB} ${LIBWEBSOCKETS_DEP_LIBS}) endif() endif() diff -Nru libwebsockets-3.2.1/minimal-examples/dbus-server/minimal-dbus-ws-proxy/main.c libwebsockets-4.1.6/minimal-examples/dbus-server/minimal-dbus-ws-proxy/main.c --- libwebsockets-3.2.1/minimal-examples/dbus-server/minimal-dbus-ws-proxy/main.c 2019-12-18 14:45:31.000000000 +0000 +++ libwebsockets-4.1.6/minimal-examples/dbus-server/minimal-dbus-ws-proxy/main.c 2020-12-01 17:40:26.000000000 +0000 @@ -79,7 +79,6 @@ info.options = LWS_SERVER_OPTION_DO_SSL_GLOBAL_INIT | LWS_SERVER_OPTION_HTTP_HEADERS_SECURITY_BEST_PRACTICES_ENFORCE; info.port = CONTEXT_PORT_NO_LISTEN; - info.ws_ping_pong_interval = 30; info.protocols = protocols; info.pvo = &pvo; diff -Nru libwebsockets-3.2.1/minimal-examples/dbus-server/minimal-dbus-ws-proxy/protocol_lws_minimal_dbus_ws_proxy.c libwebsockets-4.1.6/minimal-examples/dbus-server/minimal-dbus-ws-proxy/protocol_lws_minimal_dbus_ws_proxy.c --- libwebsockets-3.2.1/minimal-examples/dbus-server/minimal-dbus-ws-proxy/protocol_lws_minimal_dbus_ws_proxy.c 2019-12-18 14:45:31.000000000 +0000 +++ libwebsockets-4.1.6/minimal-examples/dbus-server/minimal-dbus-ws-proxy/protocol_lws_minimal_dbus_ws_proxy.c 2020-12-01 17:40:26.000000000 +0000 @@ -793,36 +793,3 @@ 1024, \ 0, NULL, 0 \ } - -#if !defined (LWS_PLUGIN_STATIC) - -/* boilerplate needed if we are built as a dynamic plugin */ - -static const struct lws_protocols protocols[] = { - LWS_PLUGIN_PROTOCOL_MINIMAL_DBUS_WSPROXY -}; - -LWS_EXTERN LWS_VISIBLE int -init_protocol_minimal_dbus_wsproxy(struct lws_context *context, - struct lws_plugin_capability *c) -{ - if (c->api_magic != LWS_PLUGIN_API_MAGIC) { - lwsl_err("Plugin API %d, library API %d", LWS_PLUGIN_API_MAGIC, - c->api_magic); - return 1; - } - - c->protocols = protocols; - c->count_protocols = LWS_ARRAY_SIZE(protocols); - c->extensions = NULL; - c->count_extensions = 0; - - return 0; -} - -LWS_EXTERN LWS_VISIBLE int -destroy_protocol_minimal_dbus_wsproxy(struct lws_context *context) -{ - return 0; -} -#endif diff -Nru libwebsockets-3.2.1/minimal-examples/embedded/esp32/esp-heltec-wb32/banded-img.h libwebsockets-4.1.6/minimal-examples/embedded/esp32/esp-heltec-wb32/banded-img.h --- libwebsockets-3.2.1/minimal-examples/embedded/esp32/esp-heltec-wb32/banded-img.h 1970-01-01 00:00:00.000000000 +0000 +++ libwebsockets-4.1.6/minimal-examples/embedded/esp32/esp-heltec-wb32/banded-img.h 2020-12-01 17:40:26.000000000 +0000 @@ -0,0 +1,64 @@ +0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, +0x00, 0x00, 0xE0, 0x40, 0x20, 0x20, 0x20, 0x20, 0x00, 0x40, 0xE0, 0x00, 0x80, 0xE0, 0x20, 0x20, +0x20, 0xE0, 0x00, 0x00, 0x00, 0xE0, 0xE0, 0x00, 0x00, 0xE0, 0xE0, 0x00, 0x00, 0x80, 0x40, 0x20, +0x20, 0x20, 0x60, 0x80, 0x00, 0xE0, 0x40, 0x20, 0x20, 0x60, 0xC0, 0x00, 0x80, 0x40, 0x20, 0x20, +0x20, 0x60, 0x80, 0x00, 0xC0, 0x60, 0x20, 0x20, 0x20, 0xC0, 0x00, 0x80, 0xC0, 0x20, 0x20, 0x20, +0x40, 0xC0, 0x00, 0xE0, 0x00, 0x80, 0x80, 0x60, 0x00, 0x80, 0xC0, 0x20, 0x20, 0x20, 0x60, 0x80, +0x00, 0x00, 0x40, 0x60, 0x20, 0x00, 0xC0, 0x40, 0x20, 0x20, 0x20, 0xC0, 0x40, 0x00, 0x00, 0x00, +0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, +0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, +0x00, 0x00, 0x7F, 0x04, 0x00, 0x00, 0x00, 0x00, 0x00, 0x04, 0x6F, 0x00, 0x34, 0x2F, 0x08, 0x08, +0x08, 0x0D, 0x07, 0x00, 0x0F, 0x00, 0x01, 0x0E, 0x0E, 0x01, 0x00, 0x0F, 0x08, 0x02, 0x0F, 0x09, +0x09, 0x19, 0x0F, 0x02, 0x00, 0x7F, 0x19, 0x08, 0x18, 0x08, 0x07, 0x01, 0x00, 0x0E, 0x09, 0x0B, +0x09, 0x0D, 0x04, 0x00, 0x07, 0x08, 0x08, 0x08, 0x08, 0x0F, 0x00, 0x03, 0x0E, 0x08, 0x18, 0x08, +0x0C, 0x04, 0x00, 0x7F, 0x02, 0x07, 0x08, 0x08, 0x00, 0x05, 0x0F, 0x0A, 0x11, 0x09, 0x0D, 0x06, +0x00, 0x08, 0x3F, 0x19, 0x08, 0x00, 0x06, 0x0A, 0x09, 0x09, 0x09, 0x0D, 0x00, 0x00, 0x00, 0x00, +0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, +0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, +0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, +0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x80, 0xE0, 0xF0, 0xF0, 0xF0, 0xF0, 0xE0, 0xC0, 0x80, 0x00, +0x00, 0x00, 0x00, 0x00, 0xC0, 0xE0, 0xF0, 0xF0, 0xF0, 0xF0, 0xE0, 0xC0, 0x00, 0x00, 0x00, 0xC0, +0xE0, 0xE0, 0xF0, 0xF0, 0xE0, 0xE0, 0xC0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x80, 0xE0, 0xE0, +0xF0, 0xF0, 0xE0, 0xE0, 0xC0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, +0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, +0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, +0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, +0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, +0x00, 0x00, 0x00, 0x80, 0xC0, 0xC0, 0xC1, 0x87, 0x8F, 0x0F, 0x0F, 0x0F, 0x07, 0x07, 0x00, 0x00, +0x00, 0x80, 0x80, 0xC0, 0x83, 0x87, 0x0F, 0x0F, 0x0F, 0x0F, 0x07, 0x83, 0x80, 0x80, 0x80, 0x83, +0x07, 0x0F, 0x1F, 0x0F, 0x0F, 0x0F, 0x83, 0x80, 0x80, 0x80, 0x00, 0x00, 0x00, 0x03, 0x07, 0x0F, +0x0F, 0x0F, 0x0F, 0x8F, 0x87, 0x80, 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, +0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, +0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, +0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, +0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, +0x00, 0xFE, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFE, 0x00, 0x00, 0x00, 0x00, 0x00, 0xFE, +0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0x10, 0x00, 0xBC, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, +0xFF, 0xF8, 0x00, 0x28, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFC, 0x00, 0x00, 0x00, 0x00, +0x00, 0xF8, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFE, 0xDC, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, +0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, +0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, +0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, +0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, +0x00, 0xBF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0x00, 0x00, 0x00, 0x00, 0x00, 0x1F, +0x3F, 0x7F, 0x7F, 0x7F, 0x7F, 0x3F, 0x3F, 0x00, 0x00, 0x1F, 0x3F, 0x7F, 0x7F, 0xFF, 0x7F, 0x7F, +0x3F, 0x0E, 0x00, 0x05, 0x3F, 0x7F, 0x7F, 0xFF, 0x7F, 0x7F, 0x7F, 0x1F, 0x00, 0x00, 0x00, 0x00, +0x00, 0x0E, 0x3F, 0x7F, 0xFF, 0xFF, 0x7F, 0x7F, 0x3F, 0x0B, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, +0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, +0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, +0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, +0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, +0x00, 0x3B, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0x3F, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, +0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, +0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, +0x00, 0x00, 0x00, 0x00, 0x00, 0x60, 0xF8, 0xF8, 0xFC, 0xFC, 0xFC, 0xFC, 0xF8, 0x20, 0x00, 0x00, +0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, +0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, +0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, +0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, +0x00, 0x00, 0x00, 0x03, 0x03, 0x03, 0x03, 0x03, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, +0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, +0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, +0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x01, 0x03, 0x03, 0x03, 0x03, 0x01, 0x00, 0x00, 0x00, +0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, +0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, diff -Nru libwebsockets-3.2.1/minimal-examples/embedded/esp32/esp-heltec-wb32/CMakeLists.txt libwebsockets-4.1.6/minimal-examples/embedded/esp32/esp-heltec-wb32/CMakeLists.txt --- libwebsockets-3.2.1/minimal-examples/embedded/esp32/esp-heltec-wb32/CMakeLists.txt 1970-01-01 00:00:00.000000000 +0000 +++ libwebsockets-4.1.6/minimal-examples/embedded/esp32/esp-heltec-wb32/CMakeLists.txt 2020-12-01 17:40:26.000000000 +0000 @@ -0,0 +1,35 @@ +cmake_minimum_required(VERSION 3.5) + +if (ESP_PLATFORM) + include($ENV{IDF_PATH}/tools/cmake/project.cmake) + project(lws-minimal-esp32 C) + enable_testing() + + target_link_libraries(lws-minimal-esp32.elf websockets) + + option(LWS_WITH_DRIVERS "With generic drivers for gpio, i2c, display etc" ON) + set(LWS_WITH_DRIVERS ON) + option(LWS_WITH_SECURE_STREAMS "With secure streams" ON) + set(LWS_WITH_SECURE_STREAMS ON) + option(LWS_WITH_SECURE_STREAMS_STATIC_POLICY_ONLY "static ssp" OFF) + set(LWS_WITH_SECURE_STREAMS_STATIC_POLICY_ONLY OFF) + option(LWS_WITH_LWSAC "With lwsac" ON) + set(LWS_WITH_LWSAC ON) + option(LWS_WITH_STRUCT_JSON "With lws_struct JSON" ON) + set(LWS_WITH_STRUCT_JSON ON) + option(LWS_WITH_SYS_NTPCLIENT "With ntpclient" ON) + set(LWS_WITH_SYS_NTPCLIENT ON) + + add_subdirectory(libwebsockets) + + add_test(NAME flashing COMMAND idf.py flash) + set_tests_properties(flashing PROPERTIES + WORKING_DIRECTORY ${CMAKE_SOURCE_DIR} + TIMEOUT 120) + + add_test(NAME boot COMMAND /usr/local/bin/sai-expect) + set_tests_properties(boot PROPERTIES + DEPENDS flashing + TIMEOUT 60) + +endif() diff -Nru libwebsockets-3.2.1/minimal-examples/embedded/esp32/esp-heltec-wb32/main/CMakeLists.txt libwebsockets-4.1.6/minimal-examples/embedded/esp32/esp-heltec-wb32/main/CMakeLists.txt --- libwebsockets-3.2.1/minimal-examples/embedded/esp32/esp-heltec-wb32/main/CMakeLists.txt 1970-01-01 00:00:00.000000000 +0000 +++ libwebsockets-4.1.6/minimal-examples/embedded/esp32/esp-heltec-wb32/main/CMakeLists.txt 2020-12-01 17:40:26.000000000 +0000 @@ -0,0 +1,6 @@ +idf_component_register(SRCS + lws-minimal-esp32.c devices.c + INCLUDE_DIRS "../libwebsockets/include;${IDF_PATH}/components/spi_flash/include;${IDF_PATH}/components/nvs_flash/include;${IDF_PATH}/components/mdns/include") + +target_link_libraries(${COMPONENT_LIB} websockets) +include_directories(../build/libwebsockets) diff -Nru libwebsockets-3.2.1/minimal-examples/embedded/esp32/esp-heltec-wb32/main/devices.c libwebsockets-4.1.6/minimal-examples/embedded/esp32/esp-heltec-wb32/main/devices.c --- libwebsockets-3.2.1/minimal-examples/embedded/esp32/esp-heltec-wb32/main/devices.c 1970-01-01 00:00:00.000000000 +0000 +++ libwebsockets-4.1.6/minimal-examples/embedded/esp32/esp-heltec-wb32/main/devices.c 2020-12-01 17:40:26.000000000 +0000 @@ -0,0 +1,207 @@ +/* + * devices for ESP32 Heltec WB32 + * + * Written in 2010-2020 by Andy Green + * + * This file is made available under the Creative Commons CC0 1.0 + * Universal Public Domain Dedication. + */ + +#define LWIP_PROVIDE_ERRNO 1 +#define _ESP_PLATFORM_ERRNO_H_ + +#include +#include "sdkconfig.h" +#include "freertos/FreeRTOS.h" +#include "freertos/task.h" + +#include + +#include + +struct lws_led_state *lls; +lws_display_state_t lds; +struct lws_button_state *bcs; +lws_netdev_instance_wifi_t *wnd; + +/* + * Hook up bitbang i2c, display driver and display + */ + +static void +esp32_i2c_delay(void) +{ + ets_delay_us(1); +} + +static const lws_bb_i2c_t li2c = { + .bb_ops = lws_bb_i2c_ops, + .scl = GPIO_NUM_15, + .sda = GPIO_NUM_4, + .gpio = &lws_gpio_plat, + .delay = esp32_i2c_delay +}; + +/* + * Button controller + */ + +static const lws_button_map_t bcm[] = { + { + .gpio = GPIO_NUM_0, + .smd_interaction_name = "user" + }, +}; + +static const lws_button_controller_t bc = { + .smd_bc_name = "bc", + .gpio_ops = &lws_gpio_plat, + .button_map = &bcm[0], + .active_state_bitmap = 0, + .count_buttons = LWS_ARRAY_SIZE(bcm), +}; + +/* + * pwm controller + */ + +static const lws_pwm_map_t pwm_map[] = { + { .gpio = GPIO_NUM_25, .index = 0, .active_level = 1 } +}; + +static const lws_pwm_ops_t pwm_ops = { + lws_pwm_plat_ops, + .pwm_map = &pwm_map[0], + .count_pwm_map = LWS_ARRAY_SIZE(pwm_map) +}; + +static const lws_display_ssd1306_t disp = { + .disp = { + lws_display_ssd1306_ops, + .w = 128, + .h = 64 + }, + .i2c = (lws_i2c_ops_t *)&li2c, + .gpio = &lws_gpio_plat, + .reset_gpio = GPIO_NUM_16, + .i2c7_address = SSD1306_I2C7_ADS1 +}; + +/* + * led controller + */ + +static const lws_led_gpio_map_t lgm[] = { + { + .name = "alert", + .gpio = GPIO_NUM_25, + .pwm_ops = &pwm_ops, /* managed by pwm */ + .active_level = 1, + }, +}; + +static const lws_led_gpio_controller_t lgc = { + .led_ops = lws_led_gpio_ops, + .gpio_ops = &lws_gpio_plat, + .led_map = &lgm[0], + .count_leds = LWS_ARRAY_SIZE(lgm) +}; + +/* + * Settings stored in platform nv + */ + +static const lws_settings_ops_t sett = { + lws_settings_ops_plat +}; + +/* + * Wifi + */ + +static const lws_netdev_ops_t wifi_ops = { + lws_netdev_wifi_plat_ops +}; + +int +init_plat_devices(struct lws_context *ctx) +{ + lws_settings_instance_t *si; + lws_netdevs_t *netdevs = lws_netdevs_from_ctx(ctx); + + si = lws_settings_init(&sett, (void *)"nvs"); + if (!si) { + lwsl_err("%s: failed to create settings instance\n", __func__); + return 1; + } + netdevs->si = si; + +#if 0 + /* + * This is a temp hack to bootstrap the settings to contain the test + * AP ssid and passphrase for one time, so the settings can be stored + * while there's no UI atm + */ + { + lws_wifi_creds_t creds; + + memset(&creds, 0, sizeof(creds)); + + lws_strncpy(creds.ssid, "xxx", sizeof(creds.ssid)); + lws_strncpy(creds.passphrase, "yyy", sizeof(creds.passphrase)); + lws_dll2_add_tail(&creds.list, &netdevs->owner_creds); + + if (lws_netdev_credentials_settings_set(netdevs)) { + lwsl_err("%s: failed to write bootstrap creds\n", + __func__); + return 1; + } + } +#endif + + /* create the wifi network device and configure it */ + + wnd = (lws_netdev_instance_wifi_t *) + wifi_ops.create(ctx, &wifi_ops, "wl0", NULL); + if (!wnd) { + lwsl_err("%s: failed to create wifi object\n", __func__); + return 1; + } + + wnd->flags |= LNDIW_MODE_STA; + + if (wifi_ops.configure(&wnd->inst, NULL)) { + lwsl_err("%s: failed to configure wifi object\n", __func__); + return 1; + } + + wifi_ops.up(&wnd->inst); + + lls = lgc.led_ops.create(&lgc.led_ops); + if (!lls) { + lwsl_err("%s: could not create led\n", __func__); + return 1; + } + + /* pwm init must go after the led controller init */ + + pwm_ops.init(&pwm_ops); + + bcs = lws_button_controller_create(ctx, &bc); + if (!bcs) { + lwsl_err("%s: could not create buttons\n", __func__); + return 1; + } + + /* + * Show the lws logo on the display + */ + + lws_display_state_init(&lds, ctx, 10000, 20000, lls, &disp.disp); + + lws_button_enable(bcs, 0, lws_button_get_bit(bcs, "user")); + lws_led_transition(lls, "alert", &lws_pwmseq_static_off, + &lws_pwmseq_static_on); + + return 0; +} diff -Nru libwebsockets-3.2.1/minimal-examples/embedded/esp32/esp-heltec-wb32/main/lws-minimal-esp32.c libwebsockets-4.1.6/minimal-examples/embedded/esp32/esp-heltec-wb32/main/lws-minimal-esp32.c --- libwebsockets-3.2.1/minimal-examples/embedded/esp32/esp-heltec-wb32/main/lws-minimal-esp32.c 1970-01-01 00:00:00.000000000 +0000 +++ libwebsockets-4.1.6/minimal-examples/embedded/esp32/esp-heltec-wb32/main/lws-minimal-esp32.c 2020-12-01 17:40:26.000000000 +0000 @@ -0,0 +1,213 @@ +/* + * lws-minimal-esp32 + * + * Written in 2010-2020 by Andy Green + * + * This file is made available under the Creative Commons CC0 1.0 + * Universal Public Domain Dedication. + * + * Based on espressif Public Domain sample + */ + +#define LWIP_PROVIDE_ERRNO 1 +#define _ESP_PLATFORM_ERRNO_H_ + +#include +#include "sdkconfig.h" +#include "freertos/FreeRTOS.h" +#include "freertos/task.h" + +#include + +#include + +struct lws_context *context; +extern struct lws_led_state *lls; +extern lws_display_state_t lds; +extern lws_netdev_instance_wifi_t *wnd; + +extern int init_plat_devices(struct lws_context *); + +static const uint8_t img[] = { +#include "../banded-img.h" +}; + +#include "policy.h" + +static uint8_t flip; + +typedef struct myss { + struct lws_ss_handle *ss; + void *opaque_data; + /* ... application specific state ... */ + + size_t amount; + +} myss_t; + +static int +myss_rx(void *userobj, const uint8_t *buf, size_t len, int flags) +{ + myss_t *m = (myss_t *)userobj; + + lwsl_user("%s: len %d, flags: %d\n", __func__, (int)len, flags); +// lwsl_hexdump_info(buf, len); + m->amount += len; + + if (flags & LWSSS_FLAG_EOM) { + + /* + * If we received the whole message, for our example it means + * we are done. + */ + + lwsl_notice("%s: received %u bytes\n", __func__, + (unsigned int)m->amount); + + /* + * In CI, we use sai-expect to look for this + * string for success + */ + + lwsl_notice("Completed: PASS\n"); + } + + return 0; +} + +static int +myss_state(void *userobj, void *sh, lws_ss_constate_t state, + lws_ss_tx_ordinal_t ack) +{ + myss_t *m = (myss_t *)userobj; + + lwsl_user("%s: %s, ord 0x%x\n", __func__, lws_ss_state_name(state), + (unsigned int)ack); + + switch (state) { + case LWSSSCS_CREATING: + lws_ss_client_connect(m->ss); + break; + default: + break; + } + + return 0; +} + +static const lws_ss_info_t ssi = { + .handle_offset = offsetof(myss_t, ss), + .opaque_user_data_offset = offsetof(myss_t, opaque_data), + .rx = myss_rx, + .state = myss_state, + .user_alloc = sizeof(myss_t), + .streamtype = "test_stream", +}; + +static const lws_led_sequence_def_t *seqs[] = { + &lws_pwmseq_static_on, + &lws_pwmseq_static_off, + &lws_pwmseq_sine_endless_slow, + &lws_pwmseq_sine_endless_fast, +}; + +static int +smd_cb(void *opaque, lws_smd_class_t _class, lws_usec_t timestamp, void *buf, + size_t len) +{ + + if (!lws_json_simple_strcmp(buf, len, "\"src\":", "bc/user") && + !lws_json_simple_strcmp(buf, len, "\"event\":", "click")) { + lws_led_transition(lls, "alert", seqs[flip & 3], + &lws_pwmseq_linear_wipe); + flip++; + } + + lwsl_hexdump_notice(buf, len); + + if ((_class & LWSSMDCL_SYSTEM_STATE) && + !lws_json_simple_strcmp(buf, len, "\"state\":", "OPERATIONAL")) { + + /* create the secure stream */ + + lwsl_notice("%s: creating test secure stream\n", __func__); + + if (lws_ss_create(context, 0, &ssi, NULL, NULL, NULL, NULL)) { + lwsl_err("%s: failed to create secure stream\n", + __func__); + return -1; + } + } + + if (_class & LWSSMDCL_INTERACTION) + /* + * Any kind of user interaction brings the display back up and + * resets the dimming / blanking timers + */ + lws_display_state_active(&lds); + + return 0; +} + +void +app_main(void) +{ + struct lws_context_creation_info *info; + + lws_set_log_level(1024 | 15, NULL); + + lws_netdev_plat_init(); + lws_netdev_plat_wifi_init(); + + info = malloc(sizeof(*info)); + if (!info) + goto spin; + + memset(info, 0, sizeof(*info)); + + lwsl_notice("LWS test for Heltec WB32 ESP32 board\n"); + + info->pss_policies_json = ss_policy; + info->options = LWS_SERVER_OPTION_EXPLICIT_VHOSTS | + LWS_SERVER_OPTION_DO_SSL_GLOBAL_INIT; + info->port = CONTEXT_PORT_NO_LISTEN; + info->early_smd_cb = smd_cb; + info->early_smd_class_filter = LWSSMDCL_INTERACTION | + LWSSMDCL_SYSTEM_STATE | + LWSSMDCL_NETWORK; + + context = lws_create_context(info); + if (!context) { + lwsl_err("lws init failed\n"); + return; + } + + /* + * We don't need this after context creation... things it pointed to + * still need to exist though since the context copied the pointers. + */ + + free(info); + + /* devices and init are in devices.c */ + + if (init_plat_devices(context)) + goto spin; + + /* put the logo on the OLED display */ + + lds.disp->blit(lds.disp, img, 0, 0, 128, 64); + lws_display_state_active(&lds); + + /* the lws event loop */ + + do { + taskYIELD(); + } while (lws_service(context, 0) >= 0); + + +spin: + vTaskDelay(10); + taskYIELD(); + goto spin; +} diff -Nru libwebsockets-3.2.1/minimal-examples/embedded/esp32/esp-heltec-wb32/main/policy.h libwebsockets-4.1.6/minimal-examples/embedded/esp32/esp-heltec-wb32/main/policy.h --- libwebsockets-3.2.1/minimal-examples/embedded/esp32/esp-heltec-wb32/main/policy.h 1970-01-01 00:00:00.000000000 +0000 +++ libwebsockets-4.1.6/minimal-examples/embedded/esp32/esp-heltec-wb32/main/policy.h 2020-12-01 17:40:26.000000000 +0000 @@ -0,0 +1,134 @@ + +static const char * const ss_policy = + "{" + "\"release\":" "\"01234567\"," + "\"product\":" "\"myproduct\"," + "\"schema-version\":" "1," + + "\"retry\": [" /* named backoff / retry strategies */ + "{\"default\": {" + "\"backoff\": [" "1000," + "2000," + "3000," + "5000," + "10000" + "]," + "\"conceal\":" "25," + "\"jitterpc\":" "20," + "\"svalidping\":" "30," + "\"svalidhup\":" "35" + "}}" + "]," + "\"certs\": [" /* named individual certificates in BASE64 DER */ + /* + * Let's Encrypt certs for warmcat.com / libwebsockets.org + * + * We fetch the real policy from there using SS and switch to + * using that. + */ + "{\"isrg_root_x1\": \"" /* ISRG ROOT X1 */ + "MIIFazCCA1OgAwIBAgIRAIIQz7DSQONZRGPgu2OCiwAwDQYJKoZIhvcNAQELBQAw" + "TzELMAkGA1UEBhMCVVMxKTAnBgNVBAoTIEludGVybmV0IFNlY3VyaXR5IFJlc2Vh" + "cmNoIEdyb3VwMRUwEwYDVQQDEwxJU1JHIFJvb3QgWDEwHhcNMTUwNjA0MTEwNDM4" + "WhcNMzUwNjA0MTEwNDM4WjBPMQswCQYDVQQGEwJVUzEpMCcGA1UEChMgSW50ZXJu" + "ZXQgU2VjdXJpdHkgUmVzZWFyY2ggR3JvdXAxFTATBgNVBAMTDElTUkcgUm9vdCBY" + "MTCCAiIwDQYJKoZIhvcNAQEBBQADggIPADCCAgoCggIBAK3oJHP0FDfzm54rVygc" + "h77ct984kIxuPOZXoHj3dcKi/vVqbvYATyjb3miGbESTtrFj/RQSa78f0uoxmyF+" + "0TM8ukj13Xnfs7j/EvEhmkvBioZxaUpmZmyPfjxwv60pIgbz5MDmgK7iS4+3mX6U" + "A5/TR5d8mUgjU+g4rk8Kb4Mu0UlXjIB0ttov0DiNewNwIRt18jA8+o+u3dpjq+sW" + "T8KOEUt+zwvo/7V3LvSye0rgTBIlDHCNAymg4VMk7BPZ7hm/ELNKjD+Jo2FR3qyH" + "B5T0Y3HsL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M3kxl5e+IZwhYAyO0OTg3/fs8HqGTNKd9BqoUwSRBzp06JMg5b" + "rUCGwbCUDI0mxadJ3Bz4WxR6fyNpBK2yAinWEsikxqEt" + "\"}" + "]," + "\"trust_stores\": [" /* named cert chains */ + "{" + "\"name\": \"le_via_isrg\"," + "\"stack\": [" + "\"isrg_root_x1\"," + "\"LEX3_isrg_root_x1\"" + "]" + "}" + "]," + "\"s\": [" + + "{\"test_stream\": {" + "\"endpoint\":" "\"warmcat.com\"," + "\"port\":" "443," + "\"protocol\":" "\"h2\"," + "\"http_method\":" "\"GET\"," + "\"http_url\":" "\"index.html\"," + "\"tls\":" "true," + "\"opportunistic\":" "true," + "\"retry\":" "\"default\"," + "\"tls_trust_store\":" "\"le_via_isrg\"" + "}},{" + /* + * "captive_portal_detect" describes + * what to do in order to check if the path to + * the Internet is being interrupted by a + * captive portal. + */ + "\"captive_portal_detect\": {" + "\"endpoint\":" "\"connectivitycheck.android.com\"," + "\"http_url\":" "\"generate_204\"," + "\"port\":" "80," + "\"protocol\":" "\"h1\"," + "\"http_method\":" "\"GET\"," + "\"opportunistic\":" "true," + "\"http_expect\":" "204," + "\"http_fail_redirect\": true" + "}}" + "]}" +; + + diff -Nru libwebsockets-3.2.1/minimal-examples/embedded/esp32/esp-heltec-wb32/partitions.csv libwebsockets-4.1.6/minimal-examples/embedded/esp32/esp-heltec-wb32/partitions.csv --- libwebsockets-3.2.1/minimal-examples/embedded/esp32/esp-heltec-wb32/partitions.csv 1970-01-01 00:00:00.000000000 +0000 +++ libwebsockets-4.1.6/minimal-examples/embedded/esp32/esp-heltec-wb32/partitions.csv 2020-12-01 17:40:26.000000000 +0000 @@ -0,0 +1,5 @@ +# ESP-IDF Partition Table +# Name, Type, SubType, Offset, Size, Flags +nvs, data, nvs, 0x9000, 0x6000, +phy_init, data, phy, 0xf000, 0x1000, +factory, app, factory, 0x10000, 2M, Binary files /tmp/tmp2l8bmswe/3lv7Sxvgkv/libwebsockets-3.2.1/minimal-examples/embedded/esp32/esp-heltec-wb32/scan/output.bmp and /tmp/tmp2l8bmswe/LwTwoWz49Q/libwebsockets-4.1.6/minimal-examples/embedded/esp32/esp-heltec-wb32/scan/output.bmp differ diff -Nru libwebsockets-3.2.1/minimal-examples/embedded/esp32/esp-heltec-wb32/scan/pic.h libwebsockets-4.1.6/minimal-examples/embedded/esp32/esp-heltec-wb32/scan/pic.h --- libwebsockets-3.2.1/minimal-examples/embedded/esp32/esp-heltec-wb32/scan/pic.h 1970-01-01 00:00:00.000000000 +0000 +++ libwebsockets-4.1.6/minimal-examples/embedded/esp32/esp-heltec-wb32/scan/pic.h 2020-12-01 17:40:26.000000000 +0000 @@ -0,0 +1,64 @@ +0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, +0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, +0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, +0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, +0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, +0x00, 0x00, 0x2f, 0x27, 0xc6, 0x61, 0xe5, 0xc3, 0xc7, 0x87, 0x11, 0x1e, 0x18, 0xe0, 0x00, 0x00, +0x00, 0x00, 0x30, 0x64, 0x46, 0x62, 0x26, 0x64, 0x4c, 0x48, 0xd1, 0x22, 0x33, 0x18, 0x00, 0x00, +0x00, 0x00, 0x20, 0x2c, 0x46, 0x64, 0x14, 0x28, 0x28, 0x58, 0x56, 0x61, 0x02, 0x10, 0x00, 0x00, +0x00, 0x00, 0x20, 0x24, 0x6a, 0x53, 0xe6, 0x33, 0xc8, 0x50, 0x14, 0x6e, 0x30, 0xf0, 0x00, 0x00, +0x00, 0x00, 0x20, 0x24, 0x29, 0x96, 0x34, 0x25, 0x08, 0x58, 0x1c, 0x31, 0x23, 0x00, 0x00, 0x00, +0x00, 0x00, 0x30, 0x6c, 0x69, 0x92, 0x24, 0x24, 0x68, 0x48, 0xd4, 0x63, 0x22, 0x10, 0x00, 0x00, +0x00, 0x00, 0x20, 0x27, 0xc9, 0x9b, 0xe7, 0xc7, 0xc7, 0xcf, 0x93, 0x36, 0x79, 0xf0, 0x00, 0x00, +0x00, 0x00, 0x20, 0x08, 0x00, 0x00, 0x46, 0x80, 0x00, 0x02, 0x10, 0x08, 0x30, 0x00, 0x00, 0x00, +0x00, 0x00, 0x20, 0x2c, 0x00, 0x00, 0x04, 0x00, 0x00, 0x00, 0x10, 0x00, 0x20, 0x00, 0x00, 0x00, +0x00, 0x00, 0x20, 0x20, 0x00, 0x00, 0x04, 0x00, 0x00, 0x00, 0x10, 0x00, 0x00, 0x00, 0x00, 0x00, +0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, +0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, +0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, +0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, +0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, +0x00, 0x00, 0x00, 0x00, 0x00, 0xf0, 0x03, 0xc0, 0x30, 0x00, 0xc0, 0x00, 0x00, 0x00, 0x00, 0x00, +0x00, 0x00, 0x00, 0x00, 0x01, 0xf8, 0x07, 0xe0, 0xfc, 0x03, 0xf0, 0x00, 0x00, 0x00, 0x00, 0x00, +0x00, 0x00, 0x00, 0x00, 0x01, 0xfc, 0x0f, 0xf1, 0xfe, 0x03, 0xf8, 0x00, 0x00, 0x00, 0x00, 0x00, +0x00, 0x00, 0x00, 0x00, 0x03, 0xfe, 0x0f, 0xf1, 0xfe, 0x07, 0xf8, 0x00, 0x00, 0x00, 0x00, 0x00, +0x00, 0x00, 0x00, 0x00, 0x03, 0xfc, 0x0f, 0xf1, 0xfe, 0x07, 0xf8, 0x00, 0x00, 0x00, 0x00, 0x00, +0x00, 0x00, 0x00, 0x00, 0x01, 0xfc, 0x0f, 0xf1, 0xfe, 0x07, 0xf8, 0x00, 0x00, 0x00, 0x00, 0x00, +0x00, 0x00, 0x00, 0x00, 0x01, 0xfc, 0x07, 0xe0, 0xfc, 0x03, 0xf8, 0x00, 0x00, 0x00, 0x00, 0x00, +0x00, 0x00, 0x00, 0x00, 0x00, 0xf0, 0x03, 0xc0, 0x7c, 0x01, 0xf0, 0x00, 0x00, 0x00, 0x00, 0x00, +0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x20, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, +0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, +0x00, 0x00, 0x00, 0x00, 0x0e, 0x00, 0x10, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, +0x00, 0x00, 0x00, 0x00, 0x1f, 0x80, 0x7c, 0x1f, 0x03, 0xc0, 0x1e, 0x00, 0x00, 0x00, 0x00, 0x00, +0x00, 0x00, 0x00, 0x00, 0x3f, 0x80, 0xfe, 0x3f, 0x8f, 0xe0, 0x3f, 0x00, 0x00, 0x00, 0x00, 0x00, +0x00, 0x00, 0x00, 0x00, 0x7f, 0xc1, 0xfe, 0x3f, 0x8f, 0xe0, 0x3f, 0x80, 0x00, 0x00, 0x00, 0x00, +0x00, 0x00, 0x00, 0x00, 0x7f, 0xc1, 0xfe, 0x7f, 0x8f, 0xf0, 0x3f, 0xc0, 0x00, 0x00, 0x00, 0x00, +0x00, 0x00, 0x00, 0x00, 0x7f, 0xc1, 0xfe, 0x7f, 0xdf, 0xf0, 0x7f, 0xc0, 0x00, 0x00, 0x00, 0x00, +0x00, 0x00, 0x00, 0x00, 0x7f, 0xc1, 0xff, 0x7f, 0xcf, 0xf0, 0x7f, 0xc0, 0x00, 0x00, 0x00, 0x00, +0x00, 0x00, 0x00, 0x00, 0x7f, 0xc1, 0xfe, 0x7f, 0xdf, 0xf0, 0x7f, 0x80, 0x00, 0x00, 0x00, 0x00, +0x00, 0x00, 0x00, 0x00, 0x7f, 0xc1, 0xfe, 0x3f, 0xcf, 0xf0, 0x7f, 0xc0, 0x00, 0x00, 0x00, 0x00, +0x00, 0x00, 0x00, 0x00, 0x7f, 0xc1, 0xfe, 0x7f, 0xcf, 0xf0, 0x7f, 0xc0, 0x00, 0x00, 0x00, 0x00, +0x00, 0x00, 0x00, 0x00, 0x7f, 0xc1, 0xfe, 0x7f, 0x9f, 0xf0, 0x3f, 0xc0, 0x00, 0x00, 0x00, 0x00, +0x00, 0x00, 0x00, 0x00, 0x7f, 0xc1, 0xfe, 0x7f, 0xcf, 0xf0, 0x7f, 0xc0, 0x00, 0x00, 0x00, 0x00, +0x00, 0x00, 0x00, 0x00, 0x7f, 0xc1, 0xfe, 0x7f, 0xdf, 0xf0, 0x7f, 0x80, 0x00, 0x00, 0x00, 0x00, +0x00, 0x00, 0x00, 0x00, 0x7f, 0xc1, 0xfe, 0x7f, 0xcf, 0xf0, 0x7f, 0xc0, 0x00, 0x00, 0x00, 0x00, +0x00, 0x00, 0x00, 0x00, 0x7f, 0xc1, 0xfe, 0x7f, 0x8f, 0xf0, 0x3f, 0x80, 0x00, 0x00, 0x00, 0x00, +0x00, 0x00, 0x00, 0x00, 0x7f, 0xc0, 0xfe, 0x3f, 0x8f, 0xe0, 0x3f, 0x80, 0x00, 0x00, 0x00, 0x00, +0x00, 0x00, 0x00, 0x00, 0x3f, 0xc0, 0x78, 0x1f, 0x07, 0xe0, 0x1f, 0x00, 0x00, 0x00, 0x00, 0x00, +0x00, 0x00, 0x00, 0x00, 0x7f, 0xc0, 0x00, 0x04, 0x01, 0x00, 0x0c, 0x00, 0x00, 0x00, 0x00, 0x00, +0x00, 0x00, 0x00, 0x00, 0x7f, 0xc0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, +0x00, 0x00, 0x00, 0x00, 0x7f, 0xc0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, +0x00, 0x00, 0x00, 0x00, 0x3f, 0xc0, 0x00, 0x00, 0x00, 0x00, 0x00, 0xf0, 0x00, 0x00, 0x00, 0x00, +0x00, 0x00, 0x00, 0x00, 0x7f, 0xc0, 0x00, 0x00, 0x00, 0x00, 0x03, 0xf8, 0x00, 0x00, 0x00, 0x00, +0x00, 0x00, 0x00, 0x00, 0x7f, 0xc0, 0x00, 0x00, 0x00, 0x00, 0x03, 0xf8, 0x00, 0x00, 0x00, 0x00, +0x00, 0x00, 0x00, 0x00, 0x7f, 0xc0, 0x00, 0x00, 0x00, 0x00, 0x07, 0xfc, 0x00, 0x00, 0x00, 0x00, +0x00, 0x00, 0x00, 0x00, 0x3f, 0x80, 0x00, 0x00, 0x00, 0x00, 0x07, 0xf8, 0x00, 0x00, 0x00, 0x00, +0x00, 0x00, 0x00, 0x00, 0x3f, 0x80, 0x00, 0x00, 0x00, 0x00, 0x03, 0xf8, 0x00, 0x00, 0x00, 0x00, +0x00, 0x00, 0x00, 0x00, 0x1f, 0x80, 0x00, 0x00, 0x00, 0x00, 0x03, 0xf8, 0x00, 0x00, 0x00, 0x00, +0x00, 0x00, 0x00, 0x00, 0x1f, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xf0, 0x00, 0x00, 0x00, 0x00, +0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, +0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, +0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, +0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, +0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, +0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, diff -Nru libwebsockets-3.2.1/minimal-examples/embedded/esp32/esp-heltec-wb32/scan/pic.h.1 libwebsockets-4.1.6/minimal-examples/embedded/esp32/esp-heltec-wb32/scan/pic.h.1 --- libwebsockets-3.2.1/minimal-examples/embedded/esp32/esp-heltec-wb32/scan/pic.h.1 1970-01-01 00:00:00.000000000 +0000 +++ libwebsockets-4.1.6/minimal-examples/embedded/esp32/esp-heltec-wb32/scan/pic.h.1 2020-12-01 17:40:26.000000000 +0000 @@ -0,0 +1,64 @@ +0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 +0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 +0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 +0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 +0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 +0x00, 0x00, 0x2f, 0x27, 0xc6, 0x61, 0xe5, 0xc3, 0xc7, 0x87, 0x11, 0x1e, 0x18, 0xe0, 0x00, 0x00 +0x00, 0x00, 0x30, 0x64, 0x46, 0x62, 0x26, 0x64, 0x4c, 0x48, 0xd1, 0x22, 0x33, 0x18, 0x00, 0x00 +0x00, 0x00, 0x20, 0x2c, 0x46, 0x64, 0x14, 0x28, 0x28, 0x58, 0x56, 0x61, 0x02, 0x10, 0x00, 0x00 +0x00, 0x00, 0x20, 0x24, 0x6a, 0x53, 0xe6, 0x33, 0xc8, 0x50, 0x14, 0x6e, 0x30, 0xf0, 0x00, 0x00 +0x00, 0x00, 0x20, 0x24, 0x29, 0x96, 0x34, 0x25, 0x08, 0x58, 0x1c, 0x31, 0x23, 0x00, 0x00, 0x00 +0x00, 0x00, 0x30, 0x6c, 0x69, 0x92, 0x24, 0x24, 0x68, 0x48, 0xd4, 0x63, 0x22, 0x10, 0x00, 0x00 +0x00, 0x00, 0x20, 0x27, 0xc9, 0x9b, 0xe7, 0xc7, 0xc7, 0xcf, 0x93, 0x36, 0x79, 0xf0, 0x00, 0x00 +0x00, 0x00, 0x20, 0x08, 0x00, 0x00, 0x46, 0x80, 0x00, 0x02, 0x10, 0x08, 0x30, 0x00, 0x00, 0x00 +0x00, 0x00, 0x20, 0x2c, 0x00, 0x00, 0x04, 0x00, 0x00, 0x00, 0x10, 0x00, 0x20, 0x00, 0x00, 0x00 +0x00, 0x00, 0x20, 0x20, 0x00, 0x00, 0x04, 0x00, 0x00, 0x00, 0x10, 0x00, 0x00, 0x00, 0x00, 0x00 +0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 +0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 +0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 +0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 +0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 +0x00, 0x00, 0x00, 0x00, 0x00, 0xf0, 0x03, 0xc0, 0x30, 0x00, 0xc0, 0x00, 0x00, 0x00, 0x00, 0x00 +0x00, 0x00, 0x00, 0x00, 0x01, 0xf8, 0x07, 0xe0, 0xfc, 0x03, 0xf0, 0x00, 0x00, 0x00, 0x00, 0x00 +0x00, 0x00, 0x00, 0x00, 0x01, 0xfc, 0x0f, 0xf1, 0xfe, 0x03, 0xf8, 0x00, 0x00, 0x00, 0x00, 0x00 +0x00, 0x00, 0x00, 0x00, 0x03, 0xfe, 0x0f, 0xf1, 0xfe, 0x07, 0xf8, 0x00, 0x00, 0x00, 0x00, 0x00 +0x00, 0x00, 0x00, 0x00, 0x03, 0xfc, 0x0f, 0xf1, 0xfe, 0x07, 0xf8, 0x00, 0x00, 0x00, 0x00, 0x00 +0x00, 0x00, 0x00, 0x00, 0x01, 0xfc, 0x0f, 0xf1, 0xfe, 0x07, 0xf8, 0x00, 0x00, 0x00, 0x00, 0x00 +0x00, 0x00, 0x00, 0x00, 0x01, 0xfc, 0x07, 0xe0, 0xfc, 0x03, 0xf8, 0x00, 0x00, 0x00, 0x00, 0x00 +0x00, 0x00, 0x00, 0x00, 0x00, 0xf0, 0x03, 0xc0, 0x7c, 0x01, 0xf0, 0x00, 0x00, 0x00, 0x00, 0x00 +0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x20, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 +0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 +0x00, 0x00, 0x00, 0x00, 0x0e, 0x00, 0x10, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 +0x00, 0x00, 0x00, 0x00, 0x1f, 0x80, 0x7c, 0x1f, 0x03, 0xc0, 0x1e, 0x00, 0x00, 0x00, 0x00, 0x00 +0x00, 0x00, 0x00, 0x00, 0x3f, 0x80, 0xfe, 0x3f, 0x8f, 0xe0, 0x3f, 0x00, 0x00, 0x00, 0x00, 0x00 +0x00, 0x00, 0x00, 0x00, 0x7f, 0xc1, 0xfe, 0x3f, 0x8f, 0xe0, 0x3f, 0x80, 0x00, 0x00, 0x00, 0x00 +0x00, 0x00, 0x00, 0x00, 0x7f, 0xc1, 0xfe, 0x7f, 0x8f, 0xf0, 0x3f, 0xc0, 0x00, 0x00, 0x00, 0x00 +0x00, 0x00, 0x00, 0x00, 0x7f, 0xc1, 0xfe, 0x7f, 0xdf, 0xf0, 0x7f, 0xc0, 0x00, 0x00, 0x00, 0x00 +0x00, 0x00, 0x00, 0x00, 0x7f, 0xc1, 0xff, 0x7f, 0xcf, 0xf0, 0x7f, 0xc0, 0x00, 0x00, 0x00, 0x00 +0x00, 0x00, 0x00, 0x00, 0x7f, 0xc1, 0xfe, 0x7f, 0xdf, 0xf0, 0x7f, 0x80, 0x00, 0x00, 0x00, 0x00 +0x00, 0x00, 0x00, 0x00, 0x7f, 0xc1, 0xfe, 0x3f, 0xcf, 0xf0, 0x7f, 0xc0, 0x00, 0x00, 0x00, 0x00 +0x00, 0x00, 0x00, 0x00, 0x7f, 0xc1, 0xfe, 0x7f, 0xcf, 0xf0, 0x7f, 0xc0, 0x00, 0x00, 0x00, 0x00 +0x00, 0x00, 0x00, 0x00, 0x7f, 0xc1, 0xfe, 0x7f, 0x9f, 0xf0, 0x3f, 0xc0, 0x00, 0x00, 0x00, 0x00 +0x00, 0x00, 0x00, 0x00, 0x7f, 0xc1, 0xfe, 0x7f, 0xcf, 0xf0, 0x7f, 0xc0, 0x00, 0x00, 0x00, 0x00 +0x00, 0x00, 0x00, 0x00, 0x7f, 0xc1, 0xfe, 0x7f, 0xdf, 0xf0, 0x7f, 0x80, 0x00, 0x00, 0x00, 0x00 +0x00, 0x00, 0x00, 0x00, 0x7f, 0xc1, 0xfe, 0x7f, 0xcf, 0xf0, 0x7f, 0xc0, 0x00, 0x00, 0x00, 0x00 +0x00, 0x00, 0x00, 0x00, 0x7f, 0xc1, 0xfe, 0x7f, 0x8f, 0xf0, 0x3f, 0x80, 0x00, 0x00, 0x00, 0x00 +0x00, 0x00, 0x00, 0x00, 0x7f, 0xc0, 0xfe, 0x3f, 0x8f, 0xe0, 0x3f, 0x80, 0x00, 0x00, 0x00, 0x00 +0x00, 0x00, 0x00, 0x00, 0x3f, 0xc0, 0x78, 0x1f, 0x07, 0xe0, 0x1f, 0x00, 0x00, 0x00, 0x00, 0x00 +0x00, 0x00, 0x00, 0x00, 0x7f, 0xc0, 0x00, 0x04, 0x01, 0x00, 0x0c, 0x00, 0x00, 0x00, 0x00, 0x00 +0x00, 0x00, 0x00, 0x00, 0x7f, 0xc0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 +0x00, 0x00, 0x00, 0x00, 0x7f, 0xc0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 +0x00, 0x00, 0x00, 0x00, 0x3f, 0xc0, 0x00, 0x00, 0x00, 0x00, 0x00, 0xf0, 0x00, 0x00, 0x00, 0x00 +0x00, 0x00, 0x00, 0x00, 0x7f, 0xc0, 0x00, 0x00, 0x00, 0x00, 0x03, 0xf8, 0x00, 0x00, 0x00, 0x00 +0x00, 0x00, 0x00, 0x00, 0x7f, 0xc0, 0x00, 0x00, 0x00, 0x00, 0x03, 0xf8, 0x00, 0x00, 0x00, 0x00 +0x00, 0x00, 0x00, 0x00, 0x7f, 0xc0, 0x00, 0x00, 0x00, 0x00, 0x07, 0xfc, 0x00, 0x00, 0x00, 0x00 +0x00, 0x00, 0x00, 0x00, 0x3f, 0x80, 0x00, 0x00, 0x00, 0x00, 0x07, 0xf8, 0x00, 0x00, 0x00, 0x00 +0x00, 0x00, 0x00, 0x00, 0x3f, 0x80, 0x00, 0x00, 0x00, 0x00, 0x03, 0xf8, 0x00, 0x00, 0x00, 0x00 +0x00, 0x00, 0x00, 0x00, 0x1f, 0x80, 0x00, 0x00, 0x00, 0x00, 0x03, 0xf8, 0x00, 0x00, 0x00, 0x00 +0x00, 0x00, 0x00, 0x00, 0x1f, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xf0, 0x00, 0x00, 0x00, 0x00 +0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 +0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 +0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 +0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 +0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 +0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 Binary files /tmp/tmp2l8bmswe/3lv7Sxvgkv/libwebsockets-3.2.1/minimal-examples/embedded/esp32/esp-heltec-wb32/scan/scan and /tmp/tmp2l8bmswe/LwTwoWz49Q/libwebsockets-4.1.6/minimal-examples/embedded/esp32/esp-heltec-wb32/scan/scan differ diff -Nru libwebsockets-3.2.1/minimal-examples/embedded/esp32/esp-heltec-wb32/scan/scan.c libwebsockets-4.1.6/minimal-examples/embedded/esp32/esp-heltec-wb32/scan/scan.c --- libwebsockets-3.2.1/minimal-examples/embedded/esp32/esp-heltec-wb32/scan/scan.c 1970-01-01 00:00:00.000000000 +0000 +++ libwebsockets-4.1.6/minimal-examples/embedded/esp32/esp-heltec-wb32/scan/scan.c 2020-12-01 17:40:26.000000000 +0000 @@ -0,0 +1,70 @@ +#include +#include +#include +#include +/* + * The bitmap mapping for the framebuffer is from top left to right, a strip of 8 vertical + * bits from each byte, so there is a block of 128 x 8 px on a stride of 128 bytes. + * + * The 8 bits from the first byte in the fb are the leftmost vertical strip of 8, then the + * next byte is the 8 pixels one to the right, until the 127th byte if the vertical strip + * of 8 on the rhs. + * + * +----------------------------------+ + * |0 | + * |1 | + * |2 | + * |3 | + * |4 | + * |5 | + * |6 | + * |7 | + * + * In this way the fb is more like (8 x vertical (128 x 8)) + * + */ + + +static const uint8_t scan[] = { + +#include "pic.h" +}; + +/* + * input byte 0 is like ABCDEFGH, one bit per horizontal pixel for one line + * on an hstride of 16 bytes + * + * output byte 0 = b0 = byte 0 b0, b1 = byte16 b0, b2 = byte24 b0 etc + * + * px(0,0) --> byte0 b0 + * px(0,1) --> byte0 b1 + */ + +int +main(void) +{ + const uint8_t *p = scan; + uint8_t r[1024]; + int x, y, t = 0; + + memset(&r, 0, sizeof(r)); + + while (t < 1024) { + + for (x = 0; x < 128; x++) { + for (y = 0; y < 8; y++) { + if (p[t + (16 * y) + (x / 8)] & (1 << (7 - (x & 7)))) + r[t + x] |= 1 << y; + } + } + + t += 128; + } + + for (x = 0; x < 1024; x++) { + printf("0x%02X, ", r[x]); + if ((x & 0xf) == 0xf) + printf("\n"); + } +} + diff -Nru libwebsockets-3.2.1/minimal-examples/embedded/esp32/esp-heltec-wb32/scan/scan.sh libwebsockets-4.1.6/minimal-examples/embedded/esp32/esp-heltec-wb32/scan/scan.sh --- libwebsockets-3.2.1/minimal-examples/embedded/esp32/esp-heltec-wb32/scan/scan.sh 1970-01-01 00:00:00.000000000 +0000 +++ libwebsockets-4.1.6/minimal-examples/embedded/esp32/esp-heltec-wb32/scan/scan.sh 2020-12-01 17:40:26.000000000 +0000 @@ -0,0 +1,8 @@ +#!/bin/bash + +convert -size 128x64 /tmp/128x64.png -monochrome output.bmp +dd if=output.bmp bs=1 skip=130 | hexdump -Cv | tr -s ' ' | cut -d' ' -f2-17 | grep ' ' | sed "s/^/0x/g" | sed "s/\ /,\ 0x/g" > pic.h.1 +cat pic.h.1 | sed "s/\$/,/g" > pic.h + +gcc -o scan scan.c && ./scan > ../banded-img.h + diff -Nru libwebsockets-3.2.1/minimal-examples/embedded/esp32/esp-heltec-wb32/sdkconfig libwebsockets-4.1.6/minimal-examples/embedded/esp32/esp-heltec-wb32/sdkconfig --- libwebsockets-3.2.1/minimal-examples/embedded/esp32/esp-heltec-wb32/sdkconfig 1970-01-01 00:00:00.000000000 +0000 +++ libwebsockets-4.1.6/minimal-examples/embedded/esp32/esp-heltec-wb32/sdkconfig 2020-12-01 17:40:26.000000000 +0000 @@ -0,0 +1,1152 @@ +# +# Automatically generated file. DO NOT EDIT. +# Espressif IoT Development Framework (ESP-IDF) Project Configuration +# +CONFIG_IDF_CMAKE=y +CONFIG_IDF_TARGET="esp32" +CONFIG_IDF_TARGET_ESP32=y +CONFIG_IDF_FIRMWARE_CHIP_ID=0x0000 + +# +# SDK tool configuration +# +CONFIG_SDK_TOOLPREFIX="xtensa-esp32-elf-" +# CONFIG_SDK_TOOLCHAIN_SUPPORTS_TIME_WIDE_64_BITS is not set +# end of SDK tool configuration + +# +# Build type +# +CONFIG_APP_BUILD_TYPE_APP_2NDBOOT=y +# CONFIG_APP_BUILD_TYPE_ELF_RAM is not set +CONFIG_APP_BUILD_GENERATE_BINARIES=y +CONFIG_APP_BUILD_BOOTLOADER=y +CONFIG_APP_BUILD_USE_FLASH_SECTIONS=y +# end of Build type + +# +# Application manager +# +CONFIG_APP_COMPILE_TIME_DATE=y +# CONFIG_APP_EXCLUDE_PROJECT_VER_VAR is not set +# CONFIG_APP_EXCLUDE_PROJECT_NAME_VAR is not set +# CONFIG_APP_PROJECT_VER_FROM_CONFIG is not set +CONFIG_APP_RETRIEVE_LEN_ELF_SHA=16 +# end of Application manager + +# +# Bootloader config +# +CONFIG_BOOTLOADER_COMPILER_OPTIMIZATION_SIZE=y +# CONFIG_BOOTLOADER_COMPILER_OPTIMIZATION_DEBUG is not set +# CONFIG_BOOTLOADER_COMPILER_OPTIMIZATION_PERF is not set +# CONFIG_BOOTLOADER_COMPILER_OPTIMIZATION_NONE is not set +# CONFIG_BOOTLOADER_LOG_LEVEL_NONE is not set +# CONFIG_BOOTLOADER_LOG_LEVEL_ERROR is not set +# CONFIG_BOOTLOADER_LOG_LEVEL_WARN is not set +CONFIG_BOOTLOADER_LOG_LEVEL_INFO=y +# CONFIG_BOOTLOADER_LOG_LEVEL_DEBUG is not set +# CONFIG_BOOTLOADER_LOG_LEVEL_VERBOSE is not set +CONFIG_BOOTLOADER_LOG_LEVEL=3 +# CONFIG_BOOTLOADER_VDDSDIO_BOOST_1_8V is not set +CONFIG_BOOTLOADER_VDDSDIO_BOOST_1_9V=y +# CONFIG_BOOTLOADER_FACTORY_RESET is not set +# CONFIG_BOOTLOADER_APP_TEST is not set +CONFIG_BOOTLOADER_WDT_ENABLE=y +# CONFIG_BOOTLOADER_WDT_DISABLE_IN_USER_CODE is not set +CONFIG_BOOTLOADER_WDT_TIME_MS=9000 +# CONFIG_BOOTLOADER_APP_ROLLBACK_ENABLE is not set +# CONFIG_BOOTLOADER_SKIP_VALIDATE_IN_DEEP_SLEEP is not set +CONFIG_BOOTLOADER_RESERVE_RTC_SIZE=0 +# CONFIG_BOOTLOADER_CUSTOM_RESERVE_RTC is not set +# end of Bootloader config + +# +# Security features +# +# CONFIG_SECURE_SIGNED_APPS_NO_SECURE_BOOT is not set +# CONFIG_SECURE_BOOT is not set +# CONFIG_SECURE_FLASH_ENC_ENABLED is not set +# end of Security features + +# +# Serial flasher config +# +CONFIG_ESPTOOLPY_BAUD_OTHER_VAL=115200 +# CONFIG_ESPTOOLPY_FLASHMODE_QIO is not set +# CONFIG_ESPTOOLPY_FLASHMODE_QOUT is not set +CONFIG_ESPTOOLPY_FLASHMODE_DIO=y +# CONFIG_ESPTOOLPY_FLASHMODE_DOUT is not set +CONFIG_ESPTOOLPY_FLASHMODE="dio" +# CONFIG_ESPTOOLPY_FLASHFREQ_80M is not set +# CONFIG_ESPTOOLPY_FLASHFREQ_40M is not set +CONFIG_ESPTOOLPY_FLASHFREQ_26M=y +# CONFIG_ESPTOOLPY_FLASHFREQ_20M is not set +CONFIG_ESPTOOLPY_FLASHFREQ="26m" +# CONFIG_ESPTOOLPY_FLASHSIZE_1MB is not set +# CONFIG_ESPTOOLPY_FLASHSIZE_2MB=y +CONFIG_ESPTOOLPY_FLASHSIZE_4MB=y +# CONFIG_ESPTOOLPY_FLASHSIZE_8MB is not set +# CONFIG_ESPTOOLPY_FLASHSIZE_16MB is not set +CONFIG_ESPTOOLPY_FLASHSIZE="4MB" +CONFIG_ESPTOOLPY_FLASHSIZE_DETECT=y +CONFIG_ESPTOOLPY_BEFORE_RESET=y +# CONFIG_ESPTOOLPY_BEFORE_NORESET is not set +CONFIG_ESPTOOLPY_BEFORE="default_reset" +CONFIG_ESPTOOLPY_AFTER_RESET=y +# CONFIG_ESPTOOLPY_AFTER_NORESET is not set +CONFIG_ESPTOOLPY_AFTER="hard_reset" +# CONFIG_ESPTOOLPY_MONITOR_BAUD_9600B is not set +# CONFIG_ESPTOOLPY_MONITOR_BAUD_57600B is not set +CONFIG_ESPTOOLPY_MONITOR_BAUD_115200B=y +# CONFIG_ESPTOOLPY_MONITOR_BAUD_230400B is not set +# CONFIG_ESPTOOLPY_MONITOR_BAUD_921600B is not set +# CONFIG_ESPTOOLPY_MONITOR_BAUD_2MB is not set +# CONFIG_ESPTOOLPY_MONITOR_BAUD_OTHER is not set +CONFIG_ESPTOOLPY_MONITOR_BAUD_OTHER_VAL=115200 +CONFIG_ESPTOOLPY_MONITOR_BAUD=115200 +# end of Serial flasher config + +# +# Partition Table +# +# CONFIG_PARTITION_TABLE_SINGLE_APP is not set +# CONFIG_PARTITION_TABLE_TWO_OTA is not set +CONFIG_PARTITION_TABLE_CUSTOM=y +CONFIG_PARTITION_TABLE_CUSTOM_FILENAME="partitions.csv" +CONFIG_PARTITION_TABLE_FILENAME="partitions_singleapp.csv" +CONFIG_PARTITION_TABLE_OFFSET=0x8000 +CONFIG_PARTITION_TABLE_MD5=y +# end of Partition Table + +# +# Compiler options +# +CONFIG_COMPILER_OPTIMIZATION_DEFAULT=y +# CONFIG_COMPILER_OPTIMIZATION_SIZE is not set +# CONFIG_COMPILER_OPTIMIZATION_PERF is not set +# CONFIG_COMPILER_OPTIMIZATION_NONE is not set +CONFIG_COMPILER_OPTIMIZATION_ASSERTIONS_ENABLE=y +# CONFIG_COMPILER_OPTIMIZATION_ASSERTIONS_SILENT is not set +# CONFIG_COMPILER_OPTIMIZATION_ASSERTIONS_DISABLE is not set +# CONFIG_COMPILER_CXX_EXCEPTIONS is not set +# CONFIG_COMPILER_CXX_RTTI is not set +CONFIG_COMPILER_STACK_CHECK_MODE_NONE=y +# CONFIG_COMPILER_STACK_CHECK_MODE_NORM is not set +# CONFIG_COMPILER_STACK_CHECK_MODE_STRONG is not set +# CONFIG_COMPILER_STACK_CHECK_MODE_ALL is not set +# CONFIG_COMPILER_WARN_WRITE_STRINGS is not set +# CONFIG_COMPILER_DISABLE_GCC8_WARNINGS is not set +# end of Compiler options + +# +# Component config +# + +# +# Application Level Tracing +# +# CONFIG_APPTRACE_DEST_TRAX is not set +CONFIG_APPTRACE_DEST_NONE=y +CONFIG_APPTRACE_LOCK_ENABLE=y +# end of Application Level Tracing + +# +# Bluetooth +# +# CONFIG_BT_ENABLED is not set +CONFIG_BTDM_CTRL_BR_EDR_SCO_DATA_PATH_EFF=0 +CONFIG_BTDM_CTRL_BLE_MAX_CONN_EFF=0 +CONFIG_BTDM_CTRL_BR_EDR_MAX_ACL_CONN_EFF=0 +CONFIG_BTDM_CTRL_BR_EDR_MAX_SYNC_CONN_EFF=0 +CONFIG_BTDM_CTRL_PINNED_TO_CORE=0 +CONFIG_BTDM_BLE_SLEEP_CLOCK_ACCURACY_INDEX_EFF=1 +CONFIG_BT_RESERVE_DRAM=0 +# end of Bluetooth + +# +# CoAP Configuration +# +CONFIG_COAP_MBEDTLS_PSK=y +# CONFIG_COAP_MBEDTLS_PKI is not set +# CONFIG_COAP_MBEDTLS_DEBUG is not set +CONFIG_COAP_LOG_DEFAULT_LEVEL=0 +# end of CoAP Configuration + +# +# Driver configurations +# + +# +# ADC configuration +# +# CONFIG_ADC_FORCE_XPD_FSM is not set +CONFIG_ADC_DISABLE_DAC=y +# end of ADC configuration + +# +# SPI configuration +# +# CONFIG_SPI_MASTER_IN_IRAM is not set +CONFIG_SPI_MASTER_ISR_IN_IRAM=y +# CONFIG_SPI_SLAVE_IN_IRAM is not set +CONFIG_SPI_SLAVE_ISR_IN_IRAM=y +# end of SPI configuration + +# +# UART configuration +# +# CONFIG_UART_ISR_IN_IRAM is not set +# end of UART configuration + +# +# RTCIO configuration +# +# CONFIG_RTCIO_SUPPORT_RTC_GPIO_DESC is not set +# end of RTCIO configuration +# end of Driver configurations + +# +# eFuse Bit Manager +# +# CONFIG_EFUSE_CUSTOM_TABLE is not set +# CONFIG_EFUSE_VIRTUAL is not set +# CONFIG_EFUSE_CODE_SCHEME_COMPAT_NONE is not set +CONFIG_EFUSE_CODE_SCHEME_COMPAT_3_4=y +# CONFIG_EFUSE_CODE_SCHEME_COMPAT_REPEAT is not set +CONFIG_EFUSE_MAX_BLK_LEN=192 +# end of eFuse Bit Manager + +# +# ESP-TLS +# +CONFIG_ESP_TLS_USING_MBEDTLS=y +# CONFIG_ESP_TLS_USE_SECURE_ELEMENT is not set +# CONFIG_ESP_TLS_SERVER is not set +# CONFIG_ESP_TLS_PSK_VERIFICATION is not set +# end of ESP-TLS + +# +# ESP32-specific +# +CONFIG_ESP32_REV_MIN_0=y +# CONFIG_ESP32_REV_MIN_1 is not set +# CONFIG_ESP32_REV_MIN_2 is not set +# CONFIG_ESP32_REV_MIN_3 is not set +CONFIG_ESP32_REV_MIN=0 +CONFIG_ESP32_DPORT_WORKAROUND=y +# CONFIG_ESP32_DEFAULT_CPU_FREQ_80 is not set +CONFIG_ESP32_DEFAULT_CPU_FREQ_160=y +# CONFIG_ESP32_DEFAULT_CPU_FREQ_240 is not set +CONFIG_ESP32_DEFAULT_CPU_FREQ_MHZ=160 +# CONFIG_ESP32_SPIRAM_SUPPORT is not set +# CONFIG_ESP32_TRAX is not set +CONFIG_ESP32_TRACEMEM_RESERVE_DRAM=0x0 +# CONFIG_ESP32_UNIVERSAL_MAC_ADDRESSES_TWO is not set +CONFIG_ESP32_UNIVERSAL_MAC_ADDRESSES_FOUR=y +CONFIG_ESP32_UNIVERSAL_MAC_ADDRESSES=4 +# CONFIG_ESP32_ULP_COPROC_ENABLED is not set +CONFIG_ESP32_ULP_COPROC_RESERVE_MEM=0 +CONFIG_ESP32_DEBUG_OCDAWARE=y +CONFIG_ESP32_BROWNOUT_DET=y +CONFIG_ESP32_BROWNOUT_DET_LVL_SEL_0=y +# CONFIG_ESP32_BROWNOUT_DET_LVL_SEL_1 is not set +# CONFIG_ESP32_BROWNOUT_DET_LVL_SEL_2 is not set +# CONFIG_ESP32_BROWNOUT_DET_LVL_SEL_3 is not set +# CONFIG_ESP32_BROWNOUT_DET_LVL_SEL_4 is not set +# CONFIG_ESP32_BROWNOUT_DET_LVL_SEL_5 is not set +# CONFIG_ESP32_BROWNOUT_DET_LVL_SEL_6 is not set +# CONFIG_ESP32_BROWNOUT_DET_LVL_SEL_7 is not set +CONFIG_ESP32_BROWNOUT_DET_LVL=0 +CONFIG_ESP32_REDUCE_PHY_TX_POWER=y +CONFIG_ESP32_TIME_SYSCALL_USE_RTC_FRC1=y +# CONFIG_ESP32_TIME_SYSCALL_USE_RTC is not set +# CONFIG_ESP32_TIME_SYSCALL_USE_FRC1 is not set +# CONFIG_ESP32_TIME_SYSCALL_USE_NONE is not set +CONFIG_ESP32_RTC_CLK_SRC_INT_RC=y +# CONFIG_ESP32_RTC_CLK_SRC_EXT_CRYS is not set +# CONFIG_ESP32_RTC_CLK_SRC_EXT_OSC is not set +# CONFIG_ESP32_RTC_CLK_SRC_INT_8MD256 is not set +CONFIG_ESP32_RTC_CLK_CAL_CYCLES=1024 +CONFIG_ESP32_DEEP_SLEEP_WAKEUP_DELAY=2000 +# CONFIG_ESP32_XTAL_FREQ_40 is not set +CONFIG_ESP32_XTAL_FREQ_26=y +# CONFIG_ESP32_XTAL_FREQ_AUTO is not set +CONFIG_ESP32_XTAL_FREQ=26 +# CONFIG_ESP32_DISABLE_BASIC_ROM_CONSOLE is not set +# CONFIG_ESP32_NO_BLOBS is not set +# CONFIG_ESP32_COMPATIBLE_PRE_V2_1_BOOTLOADERS is not set +# CONFIG_ESP32_USE_FIXED_STATIC_RAM_SIZE is not set +CONFIG_ESP32_DPORT_DIS_INTERRUPT_LVL=5 +# end of ESP32-specific + +# +# Power Management +# +# CONFIG_PM_ENABLE is not set +# end of Power Management + +# +# ADC-Calibration +# +CONFIG_ADC_CAL_EFUSE_TP_ENABLE=y +CONFIG_ADC_CAL_EFUSE_VREF_ENABLE=y +CONFIG_ADC_CAL_LUT_ENABLE=y +# end of ADC-Calibration + +# +# Common ESP-related +# +CONFIG_ESP_ERR_TO_NAME_LOOKUP=y +CONFIG_ESP_SYSTEM_EVENT_QUEUE_SIZE=32 +CONFIG_ESP_SYSTEM_EVENT_TASK_STACK_SIZE=4304 +CONFIG_ESP_MAIN_TASK_STACK_SIZE=6584 +CONFIG_ESP_IPC_TASK_STACK_SIZE=3024 +CONFIG_ESP_IPC_USES_CALLERS_PRIORITY=y +CONFIG_ESP_MINIMAL_SHARED_STACK_SIZE=2048 +CONFIG_ESP_CONSOLE_UART_DEFAULT=y +# CONFIG_ESP_CONSOLE_UART_CUSTOM is not set +# CONFIG_ESP_CONSOLE_UART_NONE is not set +CONFIG_ESP_CONSOLE_UART_NUM=0 +CONFIG_ESP_CONSOLE_UART_TX_GPIO=1 +CONFIG_ESP_CONSOLE_UART_RX_GPIO=3 +CONFIG_ESP_CONSOLE_UART_BAUDRATE=115200 +CONFIG_ESP_INT_WDT=y +CONFIG_ESP_INT_WDT_TIMEOUT_MS=300 +CONFIG_ESP_INT_WDT_CHECK_CPU1=y +CONFIG_ESP_TASK_WDT=y +# CONFIG_ESP_TASK_WDT_PANIC is not set +CONFIG_ESP_TASK_WDT_TIMEOUT_S=5 +CONFIG_ESP_TASK_WDT_CHECK_IDLE_TASK_CPU0=y +CONFIG_ESP_TASK_WDT_CHECK_IDLE_TASK_CPU1=y +# CONFIG_ESP_PANIC_HANDLER_IRAM is not set +CONFIG_ESP_MAC_ADDR_UNIVERSE_WIFI_STA=y +CONFIG_ESP_MAC_ADDR_UNIVERSE_WIFI_AP=y +CONFIG_ESP_MAC_ADDR_UNIVERSE_BT=y +CONFIG_ESP_MAC_ADDR_UNIVERSE_ETH=y +# end of Common ESP-related + +# +# Ethernet +# +CONFIG_ETH_ENABLED=y +CONFIG_ETH_USE_ESP32_EMAC=y +CONFIG_ETH_PHY_INTERFACE_RMII=y +# CONFIG_ETH_PHY_INTERFACE_MII is not set +CONFIG_ETH_RMII_CLK_INPUT=y +# CONFIG_ETH_RMII_CLK_OUTPUT is not set +CONFIG_ETH_RMII_CLK_IN_GPIO=0 +CONFIG_ETH_DMA_BUFFER_SIZE=512 +CONFIG_ETH_DMA_RX_BUFFER_NUM=10 +CONFIG_ETH_DMA_TX_BUFFER_NUM=10 +CONFIG_ETH_USE_SPI_ETHERNET=y +# CONFIG_ETH_SPI_ETHERNET_DM9051 is not set +# CONFIG_ETH_USE_OPENETH is not set +# end of Ethernet + +# +# Event Loop Library +# +# CONFIG_ESP_EVENT_LOOP_PROFILING is not set +CONFIG_ESP_EVENT_POST_FROM_ISR=y +CONFIG_ESP_EVENT_POST_FROM_IRAM_ISR=y +# end of Event Loop Library + +# +# GDB Stub +# +# end of GDB Stub + +# +# ESP HTTP client +# +CONFIG_ESP_HTTP_CLIENT_ENABLE_HTTPS=y +# CONFIG_ESP_HTTP_CLIENT_ENABLE_BASIC_AUTH is not set +# end of ESP HTTP client + +# +# HTTP Server +# +CONFIG_HTTPD_MAX_REQ_HDR_LEN=512 +CONFIG_HTTPD_MAX_URI_LEN=512 +CONFIG_HTTPD_ERR_RESP_NO_DELAY=y +CONFIG_HTTPD_PURGE_BUF_LEN=32 +# CONFIG_HTTPD_LOG_PURGE_DATA is not set +# CONFIG_HTTPD_WS_SUPPORT is not set +# end of HTTP Server + +# +# ESP HTTPS OTA +# +# CONFIG_OTA_ALLOW_HTTP is not set +# end of ESP HTTPS OTA + +# +# ESP HTTPS server +# +# CONFIG_ESP_HTTPS_SERVER_ENABLE is not set +# end of ESP HTTPS server + +# +# ESP NETIF Adapter +# +CONFIG_ESP_NETIF_IP_LOST_TIMER_INTERVAL=120 +CONFIG_ESP_NETIF_TCPIP_LWIP=y +# CONFIG_ESP_NETIF_LOOPBACK is not set +CONFIG_ESP_NETIF_TCPIP_ADAPTER_COMPATIBLE_LAYER=y +# end of ESP NETIF Adapter + +# +# ESP System Settings +# +# CONFIG_ESP_SYSTEM_PANIC_PRINT_HALT is not set +CONFIG_ESP_SYSTEM_PANIC_PRINT_REBOOT=y +# CONFIG_ESP_SYSTEM_PANIC_SILENT_REBOOT is not set +# CONFIG_ESP_SYSTEM_PANIC_GDBSTUB is not set +# end of ESP System Settings + +# +# High resolution timer (esp_timer) +# +# CONFIG_ESP_TIMER_PROFILING is not set +CONFIG_ESP_TIMER_TASK_STACK_SIZE=6584 +# CONFIG_ESP_TIMER_IMPL_FRC2 is not set +CONFIG_ESP_TIMER_IMPL_TG0_LAC=y +# end of High resolution timer (esp_timer) + +# +# Wi-Fi +# +CONFIG_ESP32_WIFI_STATIC_RX_BUFFER_NUM=10 +CONFIG_ESP32_WIFI_DYNAMIC_RX_BUFFER_NUM=32 +# CONFIG_ESP32_WIFI_STATIC_TX_BUFFER is not set +CONFIG_ESP32_WIFI_DYNAMIC_TX_BUFFER=y +CONFIG_ESP32_WIFI_TX_BUFFER_TYPE=1 +CONFIG_ESP32_WIFI_DYNAMIC_TX_BUFFER_NUM=32 +# CONFIG_ESP32_WIFI_CSI_ENABLED is not set +CONFIG_ESP32_WIFI_AMPDU_TX_ENABLED=y +CONFIG_ESP32_WIFI_TX_BA_WIN=6 +CONFIG_ESP32_WIFI_AMPDU_RX_ENABLED=y +CONFIG_ESP32_WIFI_RX_BA_WIN=6 +CONFIG_ESP32_WIFI_NVS_ENABLED=y +CONFIG_ESP32_WIFI_TASK_PINNED_TO_CORE_0=y +# CONFIG_ESP32_WIFI_TASK_PINNED_TO_CORE_1 is not set +CONFIG_ESP32_WIFI_SOFTAP_BEACON_MAX_LEN=752 +CONFIG_ESP32_WIFI_MGMT_SBUF_NUM=32 +# CONFIG_ESP32_WIFI_DEBUG_LOG_ENABLE is not set +CONFIG_ESP32_WIFI_IRAM_OPT=y +CONFIG_ESP32_WIFI_RX_IRAM_OPT=y +CONFIG_ESP32_WIFI_ENABLE_WPA3_SAE=y +# end of Wi-Fi + +# +# PHY +# +CONFIG_ESP32_PHY_CALIBRATION_AND_DATA_STORAGE=y +# CONFIG_ESP32_PHY_INIT_DATA_IN_PARTITION is not set +CONFIG_ESP32_PHY_MAX_WIFI_TX_POWER=20 +CONFIG_ESP32_PHY_MAX_TX_POWER=20 +# end of PHY + +# +# Core dump +# +# CONFIG_ESP32_ENABLE_COREDUMP_TO_FLASH is not set +# CONFIG_ESP32_ENABLE_COREDUMP_TO_UART is not set +CONFIG_ESP32_ENABLE_COREDUMP_TO_NONE=y +# end of Core dump + +# +# FAT Filesystem support +# +# CONFIG_FATFS_CODEPAGE_DYNAMIC is not set +CONFIG_FATFS_CODEPAGE_437=y +# CONFIG_FATFS_CODEPAGE_720 is not set +# CONFIG_FATFS_CODEPAGE_737 is not set +# CONFIG_FATFS_CODEPAGE_771 is not set +# CONFIG_FATFS_CODEPAGE_775 is not set +# CONFIG_FATFS_CODEPAGE_850 is not set +# CONFIG_FATFS_CODEPAGE_852 is not set +# CONFIG_FATFS_CODEPAGE_855 is not set +# CONFIG_FATFS_CODEPAGE_857 is not set +# CONFIG_FATFS_CODEPAGE_860 is not set +# CONFIG_FATFS_CODEPAGE_861 is not set +# CONFIG_FATFS_CODEPAGE_862 is not set +# CONFIG_FATFS_CODEPAGE_863 is not set +# CONFIG_FATFS_CODEPAGE_864 is not set +# CONFIG_FATFS_CODEPAGE_865 is not set +# CONFIG_FATFS_CODEPAGE_866 is not set +# CONFIG_FATFS_CODEPAGE_869 is not set +# CONFIG_FATFS_CODEPAGE_932 is not set +# CONFIG_FATFS_CODEPAGE_936 is not set +# CONFIG_FATFS_CODEPAGE_949 is not set +# CONFIG_FATFS_CODEPAGE_950 is not set +CONFIG_FATFS_CODEPAGE=437 +CONFIG_FATFS_LFN_NONE=y +# CONFIG_FATFS_LFN_HEAP is not set +# CONFIG_FATFS_LFN_STACK is not set +CONFIG_FATFS_FS_LOCK=0 +CONFIG_FATFS_TIMEOUT_MS=10000 +CONFIG_FATFS_PER_FILE_CACHE=y +# end of FAT Filesystem support + +# +# Modbus configuration +# +CONFIG_FMB_COMM_MODE_RTU_EN=y +CONFIG_FMB_COMM_MODE_ASCII_EN=y +CONFIG_FMB_MASTER_TIMEOUT_MS_RESPOND=150 +CONFIG_FMB_MASTER_DELAY_MS_CONVERT=200 +CONFIG_FMB_QUEUE_LENGTH=20 +CONFIG_FMB_SERIAL_TASK_STACK_SIZE=2048 +CONFIG_FMB_SERIAL_BUF_SIZE=256 +CONFIG_FMB_SERIAL_ASCII_BITS_PER_SYMB=8 +CONFIG_FMB_SERIAL_ASCII_TIMEOUT_RESPOND_MS=1000 +CONFIG_FMB_SERIAL_TASK_PRIO=10 +# CONFIG_FMB_CONTROLLER_SLAVE_ID_SUPPORT is not set +CONFIG_FMB_CONTROLLER_NOTIFY_TIMEOUT=20 +CONFIG_FMB_CONTROLLER_NOTIFY_QUEUE_SIZE=20 +CONFIG_FMB_CONTROLLER_STACK_SIZE=4096 +CONFIG_FMB_EVENT_QUEUE_TIMEOUT=20 +CONFIG_FMB_TIMER_PORT_ENABLED=y +CONFIG_FMB_TIMER_GROUP=0 +CONFIG_FMB_TIMER_INDEX=0 +# CONFIG_FMB_TIMER_ISR_IN_IRAM is not set +# end of Modbus configuration + +# +# FreeRTOS +# +# CONFIG_FREERTOS_UNICORE is not set +CONFIG_FREERTOS_NO_AFFINITY=0x7FFFFFFF +CONFIG_FREERTOS_CORETIMER_0=y +# CONFIG_FREERTOS_CORETIMER_1 is not set +CONFIG_FREERTOS_HZ=100 +CONFIG_FREERTOS_ASSERT_ON_UNTESTED_FUNCTION=y +# CONFIG_FREERTOS_CHECK_STACKOVERFLOW_NONE is not set +# CONFIG_FREERTOS_CHECK_STACKOVERFLOW_PTRVAL is not set +CONFIG_FREERTOS_CHECK_STACKOVERFLOW_CANARY=y +# CONFIG_FREERTOS_WATCHPOINT_END_OF_STACK is not set +CONFIG_FREERTOS_INTERRUPT_BACKTRACE=y +CONFIG_FREERTOS_THREAD_LOCAL_STORAGE_POINTERS=1 +CONFIG_FREERTOS_ASSERT_FAIL_ABORT=y +# CONFIG_FREERTOS_ASSERT_FAIL_PRINT_CONTINUE is not set +# CONFIG_FREERTOS_ASSERT_DISABLE is not set +CONFIG_FREERTOS_IDLE_TASK_STACKSIZE=1536 +CONFIG_FREERTOS_ISR_STACKSIZE=1536 +# CONFIG_FREERTOS_LEGACY_HOOKS is not set +CONFIG_FREERTOS_MAX_TASK_NAME_LEN=16 +# CONFIG_FREERTOS_SUPPORT_STATIC_ALLOCATION is not set +CONFIG_FREERTOS_TIMER_TASK_PRIORITY=1 +CONFIG_FREERTOS_TIMER_TASK_STACK_DEPTH=5048 +CONFIG_FREERTOS_TIMER_QUEUE_LENGTH=10 +CONFIG_FREERTOS_QUEUE_REGISTRY_SIZE=0 +# CONFIG_FREERTOS_USE_TRACE_FACILITY is not set +# CONFIG_FREERTOS_GENERATE_RUN_TIME_STATS is not set +CONFIG_FREERTOS_TASK_FUNCTION_WRAPPER=y +CONFIG_FREERTOS_CHECK_MUTEX_GIVEN_BY_OWNER=y +# CONFIG_FREERTOS_CHECK_PORT_CRITICAL_COMPLIANCE is not set +CONFIG_FREERTOS_DEBUG_OCDAWARE=y +# CONFIG_FREERTOS_FPU_IN_ISR is not set +# end of FreeRTOS + +# +# Heap memory debugging +# +CONFIG_HEAP_POISONING_DISABLED=y +# CONFIG_HEAP_POISONING_LIGHT is not set +# CONFIG_HEAP_POISONING_COMPREHENSIVE is not set +CONFIG_HEAP_TRACING_OFF=y +# CONFIG_HEAP_TRACING_STANDALONE is not set +# CONFIG_HEAP_TRACING_TOHOST is not set +# CONFIG_HEAP_ABORT_WHEN_ALLOCATION_FAILS is not set +# end of Heap memory debugging + +# +# jsmn +# +# CONFIG_JSMN_PARENT_LINKS is not set +# CONFIG_JSMN_STRICT is not set +# end of jsmn + +# +# libsodium +# +# end of libsodium + +# +# Log output +# +# CONFIG_LOG_DEFAULT_LEVEL_NONE is not set +# CONFIG_LOG_DEFAULT_LEVEL_ERROR is not set +# CONFIG_LOG_DEFAULT_LEVEL_WARN is not set +CONFIG_LOG_DEFAULT_LEVEL_INFO=y +# CONFIG_LOG_DEFAULT_LEVEL_DEBUG is not set +# CONFIG_LOG_DEFAULT_LEVEL_VERBOSE is not set +CONFIG_LOG_DEFAULT_LEVEL=3 +CONFIG_LOG_COLORS=y +CONFIG_LOG_TIMESTAMP_SOURCE_RTOS=y +# CONFIG_LOG_TIMESTAMP_SOURCE_SYSTEM is not set +# end of Log output + +# +# LWIP +# +CONFIG_LWIP_LOCAL_HOSTNAME="espressif" +CONFIG_LWIP_DNS_SUPPORT_MDNS_QUERIES=y +# CONFIG_LWIP_L2_TO_L3_COPY is not set +# CONFIG_LWIP_IRAM_OPTIMIZATION is not set +CONFIG_LWIP_TIMERS_ONDEMAND=y +CONFIG_LWIP_MAX_SOCKETS=10 +# CONFIG_LWIP_USE_ONLY_LWIP_SELECT is not set +CONFIG_LWIP_SO_REUSE=y +CONFIG_LWIP_SO_REUSE_RXTOALL=y +# CONFIG_LWIP_SO_RCVBUF is not set +# CONFIG_LWIP_NETBUF_RECVINFO is not set +CONFIG_LWIP_IP_FRAG=y +# CONFIG_LWIP_IP_REASSEMBLY is not set +# CONFIG_LWIP_IP_FORWARD is not set +# CONFIG_LWIP_STATS is not set +# CONFIG_LWIP_ETHARP_TRUST_IP_MAC is not set +CONFIG_LWIP_ESP_GRATUITOUS_ARP=y +CONFIG_LWIP_GARP_TMR_INTERVAL=60 +CONFIG_LWIP_TCPIP_RECVMBOX_SIZE=32 +CONFIG_LWIP_DHCP_DOES_ARP_CHECK=y +# CONFIG_LWIP_DHCP_RESTORE_LAST_IP is not set + +# +# DHCP server +# +CONFIG_LWIP_DHCPS_LEASE_UNIT=60 +CONFIG_LWIP_DHCPS_MAX_STATION_NUM=8 +# end of DHCP server + +# CONFIG_LWIP_AUTOIP is not set +# CONFIG_LWIP_IPV6_AUTOCONFIG is not set +CONFIG_LWIP_NETIF_LOOPBACK=y +CONFIG_LWIP_LOOPBACK_MAX_PBUFS=8 + +# +# TCP +# +CONFIG_LWIP_MAX_ACTIVE_TCP=16 +CONFIG_LWIP_MAX_LISTENING_TCP=16 +CONFIG_LWIP_TCP_MAXRTX=12 +CONFIG_LWIP_TCP_SYNMAXRTX=6 +CONFIG_LWIP_TCP_MSS=1440 +CONFIG_LWIP_TCP_TMR_INTERVAL=250 +CONFIG_LWIP_TCP_MSL=60000 +CONFIG_LWIP_TCP_SND_BUF_DEFAULT=5744 +CONFIG_LWIP_TCP_WND_DEFAULT=5744 +CONFIG_LWIP_TCP_RECVMBOX_SIZE=6 +CONFIG_LWIP_TCP_QUEUE_OOSEQ=y +# CONFIG_LWIP_TCP_SACK_OUT is not set +# CONFIG_LWIP_TCP_KEEP_CONNECTION_WHEN_IP_CHANGES is not set +CONFIG_LWIP_TCP_OVERSIZE_MSS=y +# CONFIG_LWIP_TCP_OVERSIZE_QUARTER_MSS is not set +# CONFIG_LWIP_TCP_OVERSIZE_DISABLE is not set +# end of TCP + +# +# UDP +# +CONFIG_LWIP_MAX_UDP_PCBS=16 +CONFIG_LWIP_UDP_RECVMBOX_SIZE=6 +# end of UDP + +CONFIG_LWIP_TCPIP_TASK_STACK_SIZE=3072 +CONFIG_LWIP_TCPIP_TASK_AFFINITY_NO_AFFINITY=y +# CONFIG_LWIP_TCPIP_TASK_AFFINITY_CPU0 is not set +# CONFIG_LWIP_TCPIP_TASK_AFFINITY_CPU1 is not set +CONFIG_LWIP_TCPIP_TASK_AFFINITY=0x7FFFFFFF +# CONFIG_LWIP_PPP_SUPPORT is not set + +# +# ICMP +# +# CONFIG_LWIP_MULTICAST_PING is not set +# CONFIG_LWIP_BROADCAST_PING is not set +# end of ICMP + +# +# LWIP RAW API +# +CONFIG_LWIP_MAX_RAW_PCBS=16 +# end of LWIP RAW API + +# +# SNTP +# +CONFIG_LWIP_DHCP_MAX_NTP_SERVERS=1 +CONFIG_LWIP_SNTP_UPDATE_DELAY=3600000 +# end of SNTP + +CONFIG_LWIP_ESP_LWIP_ASSERT=y +# end of LWIP + +# +# mbedTLS +# +CONFIG_MBEDTLS_INTERNAL_MEM_ALLOC=y +# CONFIG_MBEDTLS_DEFAULT_MEM_ALLOC is not set +# CONFIG_MBEDTLS_CUSTOM_MEM_ALLOC is not set +CONFIG_MBEDTLS_ASYMMETRIC_CONTENT_LEN=y +CONFIG_MBEDTLS_SSL_IN_CONTENT_LEN=16384 +CONFIG_MBEDTLS_SSL_OUT_CONTENT_LEN=4096 +# CONFIG_MBEDTLS_DYNAMIC_BUFFER is not set +# CONFIG_MBEDTLS_DEBUG is not set + +# +# Certificate Bundle +# +CONFIG_MBEDTLS_CERTIFICATE_BUNDLE=y +CONFIG_MBEDTLS_CERTIFICATE_BUNDLE_DEFAULT_FULL=y +# CONFIG_MBEDTLS_CERTIFICATE_BUNDLE_DEFAULT_CMN is not set +# CONFIG_MBEDTLS_CERTIFICATE_BUNDLE_DEFAULT_NONE is not set +# CONFIG_MBEDTLS_CUSTOM_CERTIFICATE_BUNDLE is not set +# end of Certificate Bundle + +# CONFIG_MBEDTLS_ECP_RESTARTABLE is not set +# CONFIG_MBEDTLS_CMAC_C is not set +CONFIG_MBEDTLS_HARDWARE_AES=y +CONFIG_MBEDTLS_HARDWARE_MPI=y +CONFIG_MBEDTLS_HARDWARE_SHA=y +# CONFIG_MBEDTLS_ATCA_HW_ECDSA_SIGN is not set +# CONFIG_MBEDTLS_ATCA_HW_ECDSA_VERIFY is not set +CONFIG_MBEDTLS_HAVE_TIME=y +# CONFIG_MBEDTLS_HAVE_TIME_DATE is not set +CONFIG_MBEDTLS_ECDSA_DETERMINISTIC=y +CONFIG_MBEDTLS_SHA512_C=y +CONFIG_MBEDTLS_TLS_SERVER_AND_CLIENT=y +# CONFIG_MBEDTLS_TLS_SERVER_ONLY is not set +# CONFIG_MBEDTLS_TLS_CLIENT_ONLY is not set +# CONFIG_MBEDTLS_TLS_DISABLED is not set +CONFIG_MBEDTLS_TLS_SERVER=y +CONFIG_MBEDTLS_TLS_CLIENT=y +CONFIG_MBEDTLS_TLS_ENABLED=y + +# +# TLS Key Exchange Methods +# +# CONFIG_MBEDTLS_PSK_MODES is not set +CONFIG_MBEDTLS_KEY_EXCHANGE_RSA=y +CONFIG_MBEDTLS_KEY_EXCHANGE_DHE_RSA=y +CONFIG_MBEDTLS_KEY_EXCHANGE_ELLIPTIC_CURVE=y +CONFIG_MBEDTLS_KEY_EXCHANGE_ECDHE_RSA=y +CONFIG_MBEDTLS_KEY_EXCHANGE_ECDHE_ECDSA=y +CONFIG_MBEDTLS_KEY_EXCHANGE_ECDH_ECDSA=y +CONFIG_MBEDTLS_KEY_EXCHANGE_ECDH_RSA=y +# end of TLS Key Exchange Methods + +CONFIG_MBEDTLS_SSL_RENEGOTIATION=y +# CONFIG_MBEDTLS_SSL_PROTO_SSL3 is not set +CONFIG_MBEDTLS_SSL_PROTO_TLS1=y +CONFIG_MBEDTLS_SSL_PROTO_TLS1_1=y +CONFIG_MBEDTLS_SSL_PROTO_TLS1_2=y +# CONFIG_MBEDTLS_SSL_PROTO_DTLS is not set +CONFIG_MBEDTLS_SSL_ALPN=y +CONFIG_MBEDTLS_CLIENT_SSL_SESSION_TICKETS=y +CONFIG_MBEDTLS_SERVER_SSL_SESSION_TICKETS=y + +# +# Symmetric Ciphers +# +CONFIG_MBEDTLS_AES_C=y +# CONFIG_MBEDTLS_CAMELLIA_C is not set +# CONFIG_MBEDTLS_DES_C is not set +CONFIG_MBEDTLS_RC4_DISABLED=y +# CONFIG_MBEDTLS_RC4_ENABLED_NO_DEFAULT is not set +# CONFIG_MBEDTLS_RC4_ENABLED is not set +# CONFIG_MBEDTLS_BLOWFISH_C is not set +# CONFIG_MBEDTLS_XTEA_C is not set +CONFIG_MBEDTLS_CCM_C=y +CONFIG_MBEDTLS_GCM_C=y +# end of Symmetric Ciphers + +# CONFIG_MBEDTLS_RIPEMD160_C is not set + +# +# Certificates +# +CONFIG_MBEDTLS_PEM_PARSE_C=y +CONFIG_MBEDTLS_PEM_WRITE_C=y +CONFIG_MBEDTLS_X509_CRL_PARSE_C=y +CONFIG_MBEDTLS_X509_CSR_PARSE_C=y +# end of Certificates + +CONFIG_MBEDTLS_ECP_C=y +CONFIG_MBEDTLS_ECDH_C=y +CONFIG_MBEDTLS_ECDSA_C=y +# CONFIG_MBEDTLS_ECJPAKE_C is not set +CONFIG_MBEDTLS_ECP_DP_SECP192R1_ENABLED=y +CONFIG_MBEDTLS_ECP_DP_SECP224R1_ENABLED=y +CONFIG_MBEDTLS_ECP_DP_SECP256R1_ENABLED=y +CONFIG_MBEDTLS_ECP_DP_SECP384R1_ENABLED=y +CONFIG_MBEDTLS_ECP_DP_SECP521R1_ENABLED=y +CONFIG_MBEDTLS_ECP_DP_SECP192K1_ENABLED=y +CONFIG_MBEDTLS_ECP_DP_SECP224K1_ENABLED=y +CONFIG_MBEDTLS_ECP_DP_SECP256K1_ENABLED=y +CONFIG_MBEDTLS_ECP_DP_BP256R1_ENABLED=y +CONFIG_MBEDTLS_ECP_DP_BP384R1_ENABLED=y +CONFIG_MBEDTLS_ECP_DP_BP512R1_ENABLED=y +CONFIG_MBEDTLS_ECP_DP_CURVE25519_ENABLED=y +CONFIG_MBEDTLS_ECP_NIST_OPTIM=y +# CONFIG_MBEDTLS_POLY1305_C is not set +# CONFIG_MBEDTLS_CHACHA20_C is not set +# CONFIG_MBEDTLS_HKDF_C is not set +# CONFIG_MBEDTLS_THREADING_C is not set +# CONFIG_MBEDTLS_SECURITY_RISKS is not set +# end of mbedTLS + +# +# mDNS +# +CONFIG_MDNS_MAX_SERVICES=10 +CONFIG_MDNS_TASK_PRIORITY=1 +CONFIG_MDNS_TASK_STACK_SIZE=4096 +# CONFIG_MDNS_TASK_AFFINITY_NO_AFFINITY is not set +CONFIG_MDNS_TASK_AFFINITY_CPU0=y +# CONFIG_MDNS_TASK_AFFINITY_CPU1 is not set +CONFIG_MDNS_TASK_AFFINITY=0x0 +CONFIG_MDNS_SERVICE_ADD_TIMEOUT_MS=2000 +CONFIG_MDNS_TIMER_PERIOD_MS=100 +# end of mDNS + +# +# ESP-MQTT Configurations +# +CONFIG_MQTT_PROTOCOL_311=y +CONFIG_MQTT_TRANSPORT_SSL=y +CONFIG_MQTT_TRANSPORT_WEBSOCKET=y +CONFIG_MQTT_TRANSPORT_WEBSOCKET_SECURE=y +# CONFIG_MQTT_USE_CUSTOM_CONFIG is not set +# CONFIG_MQTT_TASK_CORE_SELECTION_ENABLED is not set +# CONFIG_MQTT_CUSTOM_OUTBOX is not set +# end of ESP-MQTT Configurations + +# +# Newlib +# +CONFIG_NEWLIB_STDOUT_LINE_ENDING_CRLF=y +# CONFIG_NEWLIB_STDOUT_LINE_ENDING_LF is not set +# CONFIG_NEWLIB_STDOUT_LINE_ENDING_CR is not set +# CONFIG_NEWLIB_STDIN_LINE_ENDING_CRLF is not set +# CONFIG_NEWLIB_STDIN_LINE_ENDING_LF is not set +CONFIG_NEWLIB_STDIN_LINE_ENDING_CR=y +# CONFIG_NEWLIB_NANO_FORMAT is not set +# end of Newlib + +# +# NVS +# +# end of NVS + +# +# OpenSSL +# +# CONFIG_OPENSSL_DEBUG is not set +# CONFIG_OPENSSL_ASSERT_DO_NOTHING is not set +CONFIG_OPENSSL_ASSERT_EXIT=y +# end of OpenSSL + +# +# PThreads +# +CONFIG_PTHREAD_TASK_PRIO_DEFAULT=5 +CONFIG_PTHREAD_TASK_STACK_SIZE_DEFAULT=3072 +CONFIG_PTHREAD_STACK_MIN=768 +CONFIG_PTHREAD_DEFAULT_CORE_NO_AFFINITY=y +# CONFIG_PTHREAD_DEFAULT_CORE_0 is not set +# CONFIG_PTHREAD_DEFAULT_CORE_1 is not set +CONFIG_PTHREAD_TASK_CORE_DEFAULT=-1 +CONFIG_PTHREAD_TASK_NAME_DEFAULT="pthread" +# end of PThreads + +# +# SPI Flash driver +# +# CONFIG_SPI_FLASH_VERIFY_WRITE is not set +# CONFIG_SPI_FLASH_ENABLE_COUNTERS is not set +CONFIG_SPI_FLASH_ROM_DRIVER_PATCH=y +CONFIG_SPI_FLASH_DANGEROUS_WRITE_ABORTS=y +# CONFIG_SPI_FLASH_DANGEROUS_WRITE_FAILS is not set +# CONFIG_SPI_FLASH_DANGEROUS_WRITE_ALLOWED is not set +# CONFIG_SPI_FLASH_USE_LEGACY_IMPL is not set +# CONFIG_SPI_FLASH_SHARE_SPI1_BUS is not set +# CONFIG_SPI_FLASH_BYPASS_BLOCK_ERASE is not set +CONFIG_SPI_FLASH_YIELD_DURING_ERASE=y +CONFIG_SPI_FLASH_ERASE_YIELD_DURATION_MS=20 +CONFIG_SPI_FLASH_ERASE_YIELD_TICKS=1 + +# +# Auto-detect flash chips +# +CONFIG_SPI_FLASH_SUPPORT_ISSI_CHIP=y +CONFIG_SPI_FLASH_SUPPORT_MXIC_CHIP=y +CONFIG_SPI_FLASH_SUPPORT_GD_CHIP=y +# end of Auto-detect flash chips +# end of SPI Flash driver + +# +# SPIFFS Configuration +# +CONFIG_SPIFFS_MAX_PARTITIONS=3 + +# +# SPIFFS Cache Configuration +# +CONFIG_SPIFFS_CACHE=y +CONFIG_SPIFFS_CACHE_WR=y +# CONFIG_SPIFFS_CACHE_STATS is not set +# end of SPIFFS Cache Configuration + +CONFIG_SPIFFS_PAGE_CHECK=y +CONFIG_SPIFFS_GC_MAX_RUNS=10 +# CONFIG_SPIFFS_GC_STATS is not set +CONFIG_SPIFFS_PAGE_SIZE=256 +CONFIG_SPIFFS_OBJ_NAME_LEN=32 +# CONFIG_SPIFFS_FOLLOW_SYMLINKS is not set +CONFIG_SPIFFS_USE_MAGIC=y +CONFIG_SPIFFS_USE_MAGIC_LENGTH=y +CONFIG_SPIFFS_META_LENGTH=4 +CONFIG_SPIFFS_USE_MTIME=y + +# +# Debug Configuration +# +# CONFIG_SPIFFS_DBG is not set +# CONFIG_SPIFFS_API_DBG is not set +# CONFIG_SPIFFS_GC_DBG is not set +# CONFIG_SPIFFS_CACHE_DBG is not set +# CONFIG_SPIFFS_CHECK_DBG is not set +# CONFIG_SPIFFS_TEST_VISUALISATION is not set +# end of Debug Configuration +# end of SPIFFS Configuration + +# +# TinyUSB +# + +# +# Descriptor configuration +# +CONFIG_USB_DESC_CUSTOM_VID=0x1234 +CONFIG_USB_DESC_CUSTOM_PID=0x5678 +# end of Descriptor configuration +# end of TinyUSB + +# +# Unity unit testing library +# +CONFIG_UNITY_ENABLE_FLOAT=y +CONFIG_UNITY_ENABLE_DOUBLE=y +# CONFIG_UNITY_ENABLE_COLOR is not set +CONFIG_UNITY_ENABLE_IDF_TEST_RUNNER=y +# CONFIG_UNITY_ENABLE_FIXTURE is not set +# CONFIG_UNITY_ENABLE_BACKTRACE_ON_FAIL is not set +# end of Unity unit testing library + +# +# Virtual file system +# +CONFIG_VFS_SUPPORT_IO=y +CONFIG_VFS_SUPPORT_DIR=y +CONFIG_VFS_SUPPORT_SELECT=y +CONFIG_VFS_SUPPRESS_SELECT_DEBUG_OUTPUT=y +CONFIG_VFS_SUPPORT_TERMIOS=y + +# +# Host File System I/O (Semihosting) +# +CONFIG_VFS_SEMIHOSTFS_MAX_MOUNT_POINTS=1 +CONFIG_VFS_SEMIHOSTFS_HOST_PATH_MAX_LEN=128 +# end of Host File System I/O (Semihosting) +# end of Virtual file system + +# +# Wear Levelling +# +# CONFIG_WL_SECTOR_SIZE_512 is not set +CONFIG_WL_SECTOR_SIZE_4096=y +CONFIG_WL_SECTOR_SIZE=4096 +# end of Wear Levelling + +# +# Wi-Fi Provisioning Manager +# +CONFIG_WIFI_PROV_SCAN_MAX_ENTRIES=16 +CONFIG_WIFI_PROV_AUTOSTOP_TIMEOUT=30 +# end of Wi-Fi Provisioning Manager + +# +# Supplicant +# +CONFIG_WPA_MBEDTLS_CRYPTO=y +# CONFIG_WPA_DEBUG_PRINT is not set +# CONFIG_WPA_TESTING_OPTIONS is not set +# CONFIG_WPA_TLS_V12 is not set +# CONFIG_WPA_WPS_WARS is not set +# end of Supplicant +# end of Component config + +# +# Compatibility options +# +# CONFIG_LEGACY_INCLUDE_COMMON_HEADERS is not set +# end of Compatibility options + +# Deprecated options for backward compatibility +CONFIG_TOOLPREFIX="xtensa-esp32-elf-" +# CONFIG_LOG_BOOTLOADER_LEVEL_NONE is not set +# CONFIG_LOG_BOOTLOADER_LEVEL_ERROR is not set +# CONFIG_LOG_BOOTLOADER_LEVEL_WARN is not set +CONFIG_LOG_BOOTLOADER_LEVEL_INFO=y +# CONFIG_LOG_BOOTLOADER_LEVEL_DEBUG is not set +# CONFIG_LOG_BOOTLOADER_LEVEL_VERBOSE is not set +CONFIG_LOG_BOOTLOADER_LEVEL=3 +# CONFIG_APP_ROLLBACK_ENABLE is not set +# CONFIG_FLASH_ENCRYPTION_ENABLED is not set +# CONFIG_FLASHMODE_QIO is not set +# CONFIG_FLASHMODE_QOUT is not set +CONFIG_FLASHMODE_DIO=y +# CONFIG_FLASHMODE_DOUT is not set +# CONFIG_MONITOR_BAUD_9600B is not set +# CONFIG_MONITOR_BAUD_57600B is not set +CONFIG_MONITOR_BAUD_115200B=y +# CONFIG_MONITOR_BAUD_230400B is not set +# CONFIG_MONITOR_BAUD_921600B is not set +# CONFIG_MONITOR_BAUD_2MB is not set +# CONFIG_MONITOR_BAUD_OTHER is not set +CONFIG_MONITOR_BAUD_OTHER_VAL=115200 +CONFIG_MONITOR_BAUD=115200 +CONFIG_COMPILER_OPTIMIZATION_LEVEL_DEBUG=y +# CONFIG_COMPILER_OPTIMIZATION_LEVEL_RELEASE is not set +CONFIG_OPTIMIZATION_ASSERTIONS_ENABLED=y +# CONFIG_OPTIMIZATION_ASSERTIONS_SILENT is not set +# CONFIG_OPTIMIZATION_ASSERTIONS_DISABLED is not set +# CONFIG_CXX_EXCEPTIONS is not set +CONFIG_STACK_CHECK_NONE=y +# CONFIG_STACK_CHECK_NORM is not set +# CONFIG_STACK_CHECK_STRONG is not set +# CONFIG_STACK_CHECK_ALL is not set +# CONFIG_WARN_WRITE_STRINGS is not set +# CONFIG_DISABLE_GCC8_WARNINGS is not set +# CONFIG_ESP32_APPTRACE_DEST_TRAX is not set +CONFIG_ESP32_APPTRACE_DEST_NONE=y +CONFIG_ESP32_APPTRACE_LOCK_ENABLE=y +CONFIG_BTDM_CONTROLLER_BLE_MAX_CONN_EFF=0 +CONFIG_BTDM_CONTROLLER_BR_EDR_MAX_ACL_CONN_EFF=0 +CONFIG_BTDM_CONTROLLER_BR_EDR_MAX_SYNC_CONN_EFF=0 +CONFIG_BTDM_CONTROLLER_PINNED_TO_CORE=0 +CONFIG_ADC2_DISABLE_DAC=y +# CONFIG_SPIRAM_SUPPORT is not set +CONFIG_TRACEMEM_RESERVE_DRAM=0x0 +# CONFIG_TWO_UNIVERSAL_MAC_ADDRESS is not set +CONFIG_FOUR_UNIVERSAL_MAC_ADDRESS=y +CONFIG_NUMBER_OF_UNIVERSAL_MAC_ADDRESS=4 +# CONFIG_ULP_COPROC_ENABLED is not set +CONFIG_ULP_COPROC_RESERVE_MEM=0 +CONFIG_BROWNOUT_DET=y +CONFIG_BROWNOUT_DET_LVL_SEL_0=y +# CONFIG_BROWNOUT_DET_LVL_SEL_1 is not set +# CONFIG_BROWNOUT_DET_LVL_SEL_2 is not set +# CONFIG_BROWNOUT_DET_LVL_SEL_3 is not set +# CONFIG_BROWNOUT_DET_LVL_SEL_4 is not set +# CONFIG_BROWNOUT_DET_LVL_SEL_5 is not set +# CONFIG_BROWNOUT_DET_LVL_SEL_6 is not set +# CONFIG_BROWNOUT_DET_LVL_SEL_7 is not set +CONFIG_BROWNOUT_DET_LVL=0 +CONFIG_REDUCE_PHY_TX_POWER=y +CONFIG_ESP32_RTC_CLOCK_SOURCE_INTERNAL_RC=y +# CONFIG_ESP32_RTC_CLOCK_SOURCE_EXTERNAL_CRYSTAL is not set +# CONFIG_ESP32_RTC_CLOCK_SOURCE_EXTERNAL_OSC is not set +# CONFIG_ESP32_RTC_CLOCK_SOURCE_INTERNAL_8MD256 is not set +# CONFIG_DISABLE_BASIC_ROM_CONSOLE is not set +# CONFIG_NO_BLOBS is not set +# CONFIG_COMPATIBLE_PRE_V2_1_BOOTLOADERS is not set +CONFIG_SYSTEM_EVENT_QUEUE_SIZE=32 +CONFIG_SYSTEM_EVENT_TASK_STACK_SIZE=4304 +CONFIG_MAIN_TASK_STACK_SIZE=6584 +CONFIG_IPC_TASK_STACK_SIZE=3024 +CONFIG_CONSOLE_UART_DEFAULT=y +# CONFIG_CONSOLE_UART_CUSTOM is not set +# CONFIG_CONSOLE_UART_NONE is not set +CONFIG_CONSOLE_UART_NUM=0 +CONFIG_CONSOLE_UART_TX_GPIO=1 +CONFIG_CONSOLE_UART_RX_GPIO=3 +CONFIG_CONSOLE_UART_BAUDRATE=115200 +CONFIG_INT_WDT=y +CONFIG_INT_WDT_TIMEOUT_MS=300 +CONFIG_INT_WDT_CHECK_CPU1=y +CONFIG_TASK_WDT=y +# CONFIG_TASK_WDT_PANIC is not set +CONFIG_TASK_WDT_TIMEOUT_S=5 +CONFIG_TASK_WDT_CHECK_IDLE_TASK_CPU0=y +CONFIG_TASK_WDT_CHECK_IDLE_TASK_CPU1=y +# CONFIG_EVENT_LOOP_PROFILING is not set +CONFIG_POST_EVENTS_FROM_ISR=y +CONFIG_POST_EVENTS_FROM_IRAM_ISR=y +# CONFIG_ESP32S2_PANIC_PRINT_HALT is not set +CONFIG_ESP32S2_PANIC_PRINT_REBOOT=y +# CONFIG_ESP32S2_PANIC_SILENT_REBOOT is not set +# CONFIG_ESP32S2_PANIC_GDBSTUB is not set +CONFIG_TIMER_TASK_STACK_SIZE=6584 +CONFIG_MB_MASTER_TIMEOUT_MS_RESPOND=150 +CONFIG_MB_MASTER_DELAY_MS_CONVERT=200 +CONFIG_MB_QUEUE_LENGTH=20 +CONFIG_MB_SERIAL_TASK_STACK_SIZE=2048 +CONFIG_MB_SERIAL_BUF_SIZE=256 +CONFIG_MB_SERIAL_TASK_PRIO=10 +# CONFIG_MB_CONTROLLER_SLAVE_ID_SUPPORT is not set +CONFIG_MB_CONTROLLER_NOTIFY_TIMEOUT=20 +CONFIG_MB_CONTROLLER_NOTIFY_QUEUE_SIZE=20 +CONFIG_MB_CONTROLLER_STACK_SIZE=4096 +CONFIG_MB_EVENT_QUEUE_TIMEOUT=20 +CONFIG_MB_TIMER_PORT_ENABLED=y +CONFIG_MB_TIMER_GROUP=0 +CONFIG_MB_TIMER_INDEX=0 +# CONFIG_SUPPORT_STATIC_ALLOCATION is not set +CONFIG_TIMER_TASK_PRIORITY=1 +CONFIG_TIMER_TASK_STACK_DEPTH=5048 +CONFIG_TIMER_QUEUE_LENGTH=10 +# CONFIG_L2_TO_L3_COPY is not set +# CONFIG_USE_ONLY_LWIP_SELECT is not set +CONFIG_ESP_GRATUITOUS_ARP=y +CONFIG_GARP_TMR_INTERVAL=60 +CONFIG_TCPIP_RECVMBOX_SIZE=32 +CONFIG_TCP_MAXRTX=12 +CONFIG_TCP_SYNMAXRTX=6 +CONFIG_TCP_MSS=1440 +CONFIG_TCP_MSL=60000 +CONFIG_TCP_SND_BUF_DEFAULT=5744 +CONFIG_TCP_WND_DEFAULT=5744 +CONFIG_TCP_RECVMBOX_SIZE=6 +CONFIG_TCP_QUEUE_OOSEQ=y +# CONFIG_ESP_TCP_KEEP_CONNECTION_WHEN_IP_CHANGES is not set +CONFIG_TCP_OVERSIZE_MSS=y +# CONFIG_TCP_OVERSIZE_QUARTER_MSS is not set +# CONFIG_TCP_OVERSIZE_DISABLE is not set +CONFIG_UDP_RECVMBOX_SIZE=6 +CONFIG_TCPIP_TASK_STACK_SIZE=3072 +CONFIG_TCPIP_TASK_AFFINITY_NO_AFFINITY=y +# CONFIG_TCPIP_TASK_AFFINITY_CPU0 is not set +# CONFIG_TCPIP_TASK_AFFINITY_CPU1 is not set +CONFIG_TCPIP_TASK_AFFINITY=0x7FFFFFFF +# CONFIG_PPP_SUPPORT is not set +CONFIG_ESP32_PTHREAD_TASK_PRIO_DEFAULT=5 +CONFIG_ESP32_PTHREAD_TASK_STACK_SIZE_DEFAULT=3072 +CONFIG_ESP32_PTHREAD_STACK_MIN=768 +CONFIG_ESP32_DEFAULT_PTHREAD_CORE_NO_AFFINITY=y +# CONFIG_ESP32_DEFAULT_PTHREAD_CORE_0 is not set +# CONFIG_ESP32_DEFAULT_PTHREAD_CORE_1 is not set +CONFIG_ESP32_PTHREAD_TASK_CORE_DEFAULT=-1 +CONFIG_ESP32_PTHREAD_TASK_NAME_DEFAULT="pthread" +CONFIG_SPI_FLASH_WRITING_DANGEROUS_REGIONS_ABORTS=y +# CONFIG_SPI_FLASH_WRITING_DANGEROUS_REGIONS_FAILS is not set +# CONFIG_SPI_FLASH_WRITING_DANGEROUS_REGIONS_ALLOWED is not set +CONFIG_SUPPRESS_SELECT_DEBUG_OUTPUT=y +CONFIG_SUPPORT_TERMIOS=y +CONFIG_SEMIHOSTFS_MAX_MOUNT_POINTS=1 +CONFIG_SEMIHOSTFS_HOST_PATH_MAX_LEN=128 +# End of deprecated options + diff -Nru libwebsockets-3.2.1/minimal-examples/embedded/esp32/esp-heltec-wb32/sdkconfig.h libwebsockets-4.1.6/minimal-examples/embedded/esp32/esp-heltec-wb32/sdkconfig.h --- libwebsockets-3.2.1/minimal-examples/embedded/esp32/esp-heltec-wb32/sdkconfig.h 1970-01-01 00:00:00.000000000 +0000 +++ libwebsockets-4.1.6/minimal-examples/embedded/esp32/esp-heltec-wb32/sdkconfig.h 2020-12-01 17:40:26.000000000 +0000 @@ -0,0 +1,426 @@ +/* + * Automatically generated file. DO NOT EDIT. + * Espressif IoT Development Framework (ESP-IDF) Configuration Header + */ +#pragma once +#define CONFIG_IDF_CMAKE 1 +#define CONFIG_IDF_TARGET "esp32" +#define CONFIG_IDF_TARGET_ESP32 1 +#define CONFIG_IDF_FIRMWARE_CHIP_ID 0x0000 +#define CONFIG_SDK_TOOLPREFIX "xtensa-esp32-elf-" +#define CONFIG_APP_BUILD_TYPE_APP_2NDBOOT 1 +#define CONFIG_APP_BUILD_GENERATE_BINARIES 1 +#define CONFIG_APP_BUILD_BOOTLOADER 1 +#define CONFIG_APP_BUILD_USE_FLASH_SECTIONS 1 +#define CONFIG_APP_COMPILE_TIME_DATE 1 +#define CONFIG_APP_RETRIEVE_LEN_ELF_SHA 16 +#define CONFIG_BOOTLOADER_COMPILER_OPTIMIZATION_SIZE 1 +#define CONFIG_BOOTLOADER_LOG_LEVEL_INFO 1 +#define CONFIG_BOOTLOADER_LOG_LEVEL 3 +#define CONFIG_BOOTLOADER_VDDSDIO_BOOST_1_9V 1 +#define CONFIG_BOOTLOADER_WDT_ENABLE 1 +#define CONFIG_BOOTLOADER_WDT_TIME_MS 9000 +#define CONFIG_BOOTLOADER_RESERVE_RTC_SIZE 0x0 +#define CONFIG_ESPTOOLPY_BAUD_OTHER_VAL 115200 +#define CONFIG_ESPTOOLPY_FLASHMODE_DIO 1 +#define CONFIG_ESPTOOLPY_FLASHMODE "dio" +#define CONFIG_ESPTOOLPY_FLASHFREQ_26M 1 +#define CONFIG_ESPTOOLPY_FLASHFREQ "26m" +#define CONFIG_ESPTOOLPY_FLASHSIZE_2MB 1 +#define CONFIG_ESPTOOLPY_FLASHSIZE "2MB" +#define CONFIG_ESPTOOLPY_FLASHSIZE_DETECT 1 +#define CONFIG_ESPTOOLPY_BEFORE_RESET 1 +#define CONFIG_ESPTOOLPY_BEFORE "default_reset" +#define CONFIG_ESPTOOLPY_AFTER_RESET 1 +#define CONFIG_ESPTOOLPY_AFTER "hard_reset" +#define CONFIG_ESPTOOLPY_MONITOR_BAUD_115200B 1 +#define CONFIG_ESPTOOLPY_MONITOR_BAUD_OTHER_VAL 115200 +#define CONFIG_ESPTOOLPY_MONITOR_BAUD 115200 +#define CONFIG_PARTITION_TABLE_CUSTOM 1 +#define CONFIG_PARTITION_TABLE_CUSTOM_FILENAME "partitions.csv" +#define CONFIG_PARTITION_TABLE_FILENAME "partitions_singleapp.csv" +#define CONFIG_PARTITION_TABLE_OFFSET 0x8000 +#define CONFIG_PARTITION_TABLE_MD5 1 +#define CONFIG_COMPILER_OPTIMIZATION_DEFAULT 1 +#define CONFIG_COMPILER_OPTIMIZATION_ASSERTIONS_ENABLE 1 +#define CONFIG_COMPILER_STACK_CHECK_MODE_NONE 1 +#define CONFIG_APPTRACE_DEST_NONE 1 +#define CONFIG_APPTRACE_LOCK_ENABLE 1 +#define CONFIG_BTDM_CTRL_BR_EDR_SCO_DATA_PATH_EFF 0 +#define CONFIG_BTDM_CTRL_BLE_MAX_CONN_EFF 0 +#define CONFIG_BTDM_CTRL_BR_EDR_MAX_ACL_CONN_EFF 0 +#define CONFIG_BTDM_CTRL_BR_EDR_MAX_SYNC_CONN_EFF 0 +#define CONFIG_BTDM_CTRL_PINNED_TO_CORE 0 +#define CONFIG_BTDM_BLE_SLEEP_CLOCK_ACCURACY_INDEX_EFF 1 +#define CONFIG_BT_RESERVE_DRAM 0x0 +#define CONFIG_COAP_MBEDTLS_PSK 1 +#define CONFIG_COAP_LOG_DEFAULT_LEVEL 0 +#define CONFIG_ADC_DISABLE_DAC 1 +#define CONFIG_SPI_MASTER_ISR_IN_IRAM 1 +#define CONFIG_SPI_SLAVE_ISR_IN_IRAM 1 +#define CONFIG_EFUSE_CODE_SCHEME_COMPAT_3_4 1 +#define CONFIG_EFUSE_MAX_BLK_LEN 192 +#define CONFIG_ESP_TLS_USING_MBEDTLS 1 +#define CONFIG_ESP32_REV_MIN_0 1 +#define CONFIG_ESP32_REV_MIN 0 +#define CONFIG_ESP32_DPORT_WORKAROUND 1 +#define CONFIG_ESP32_DEFAULT_CPU_FREQ_160 1 +#define CONFIG_ESP32_DEFAULT_CPU_FREQ_MHZ 160 +#define CONFIG_ESP32_TRACEMEM_RESERVE_DRAM 0x0 +#define CONFIG_ESP32_UNIVERSAL_MAC_ADDRESSES_FOUR 1 +#define CONFIG_ESP32_UNIVERSAL_MAC_ADDRESSES 4 +#define CONFIG_ESP32_ULP_COPROC_RESERVE_MEM 0 +#define CONFIG_ESP32_DEBUG_OCDAWARE 1 +#define CONFIG_ESP32_BROWNOUT_DET 1 +#define CONFIG_ESP32_BROWNOUT_DET_LVL_SEL_0 1 +#define CONFIG_ESP32_BROWNOUT_DET_LVL 0 +#define CONFIG_ESP32_REDUCE_PHY_TX_POWER 1 +#define CONFIG_ESP32_TIME_SYSCALL_USE_RTC_FRC1 1 +#define CONFIG_ESP32_RTC_CLK_SRC_INT_RC 1 +#define CONFIG_ESP32_RTC_CLK_CAL_CYCLES 1024 +#define CONFIG_ESP32_DEEP_SLEEP_WAKEUP_DELAY 2000 +#define CONFIG_ESP32_XTAL_FREQ_26 1 +#define CONFIG_ESP32_XTAL_FREQ 26 +#define CONFIG_ESP32_DPORT_DIS_INTERRUPT_LVL 5 +#define CONFIG_ADC_CAL_EFUSE_TP_ENABLE 1 +#define CONFIG_ADC_CAL_EFUSE_VREF_ENABLE 1 +#define CONFIG_ADC_CAL_LUT_ENABLE 1 +#define CONFIG_ESP_ERR_TO_NAME_LOOKUP 1 +#define CONFIG_ESP_SYSTEM_EVENT_QUEUE_SIZE 32 +#define CONFIG_ESP_SYSTEM_EVENT_TASK_STACK_SIZE 2304 +#define CONFIG_ESP_MAIN_TASK_STACK_SIZE 6584 +#define CONFIG_ESP_IPC_TASK_STACK_SIZE 1024 +#define CONFIG_ESP_IPC_USES_CALLERS_PRIORITY 1 +#define CONFIG_ESP_MINIMAL_SHARED_STACK_SIZE 2048 +#define CONFIG_ESP_CONSOLE_UART_DEFAULT 1 +#define CONFIG_ESP_CONSOLE_UART_NUM 0 +#define CONFIG_ESP_CONSOLE_UART_TX_GPIO 1 +#define CONFIG_ESP_CONSOLE_UART_RX_GPIO 3 +#define CONFIG_ESP_CONSOLE_UART_BAUDRATE 115200 +#define CONFIG_ESP_INT_WDT 1 +#define CONFIG_ESP_INT_WDT_TIMEOUT_MS 300 +#define CONFIG_ESP_INT_WDT_CHECK_CPU1 1 +#define CONFIG_ESP_TASK_WDT 1 +#define CONFIG_ESP_TASK_WDT_TIMEOUT_S 5 +#define CONFIG_ESP_TASK_WDT_CHECK_IDLE_TASK_CPU0 1 +#define CONFIG_ESP_TASK_WDT_CHECK_IDLE_TASK_CPU1 1 +#define CONFIG_ESP_MAC_ADDR_UNIVERSE_WIFI_STA 1 +#define CONFIG_ESP_MAC_ADDR_UNIVERSE_WIFI_AP 1 +#define CONFIG_ESP_MAC_ADDR_UNIVERSE_BT 1 +#define CONFIG_ESP_MAC_ADDR_UNIVERSE_ETH 1 +#define CONFIG_ETH_ENABLED 1 +#define CONFIG_ETH_USE_ESP32_EMAC 1 +#define CONFIG_ETH_PHY_INTERFACE_RMII 1 +#define CONFIG_ETH_RMII_CLK_INPUT 1 +#define CONFIG_ETH_RMII_CLK_IN_GPIO 0 +#define CONFIG_ETH_DMA_BUFFER_SIZE 512 +#define CONFIG_ETH_DMA_RX_BUFFER_NUM 10 +#define CONFIG_ETH_DMA_TX_BUFFER_NUM 10 +#define CONFIG_ETH_USE_SPI_ETHERNET 1 +#define CONFIG_ESP_EVENT_POST_FROM_ISR 1 +#define CONFIG_ESP_EVENT_POST_FROM_IRAM_ISR 1 +#define CONFIG_ESP_HTTP_CLIENT_ENABLE_HTTPS 1 +#define CONFIG_HTTPD_MAX_REQ_HDR_LEN 512 +#define CONFIG_HTTPD_MAX_URI_LEN 512 +#define CONFIG_HTTPD_ERR_RESP_NO_DELAY 1 +#define CONFIG_HTTPD_PURGE_BUF_LEN 32 +#define CONFIG_ESP_NETIF_IP_LOST_TIMER_INTERVAL 120 +#define CONFIG_ESP_NETIF_TCPIP_LWIP 1 +#define CONFIG_ESP_NETIF_TCPIP_ADAPTER_COMPATIBLE_LAYER 1 +#define CONFIG_ESP_SYSTEM_PANIC_PRINT_REBOOT 1 +#define CONFIG_ESP_TIMER_TASK_STACK_SIZE 3584 +#define CONFIG_ESP_TIMER_IMPL_TG0_LAC 1 +#define CONFIG_ESP32_WIFI_STATIC_RX_BUFFER_NUM 10 +#define CONFIG_ESP32_WIFI_DYNAMIC_RX_BUFFER_NUM 32 +#define CONFIG_ESP32_WIFI_DYNAMIC_TX_BUFFER 1 +#define CONFIG_ESP32_WIFI_TX_BUFFER_TYPE 1 +#define CONFIG_ESP32_WIFI_DYNAMIC_TX_BUFFER_NUM 32 +#define CONFIG_ESP32_WIFI_AMPDU_TX_ENABLED 1 +#define CONFIG_ESP32_WIFI_TX_BA_WIN 6 +#define CONFIG_ESP32_WIFI_AMPDU_RX_ENABLED 1 +#define CONFIG_ESP32_WIFI_RX_BA_WIN 6 +#define CONFIG_ESP32_WIFI_NVS_ENABLED 1 +#define CONFIG_ESP32_WIFI_TASK_PINNED_TO_CORE_0 1 +#define CONFIG_ESP32_WIFI_SOFTAP_BEACON_MAX_LEN 752 +#define CONFIG_ESP32_WIFI_MGMT_SBUF_NUM 32 +#define CONFIG_ESP32_WIFI_IRAM_OPT 1 +#define CONFIG_ESP32_WIFI_RX_IRAM_OPT 1 +#define CONFIG_ESP32_WIFI_ENABLE_WPA3_SAE 1 +#define CONFIG_ESP32_PHY_CALIBRATION_AND_DATA_STORAGE 1 +#define CONFIG_ESP32_PHY_MAX_WIFI_TX_POWER 20 +#define CONFIG_ESP32_PHY_MAX_TX_POWER 20 +#define CONFIG_ESP32_ENABLE_COREDUMP_TO_NONE 1 +#define CONFIG_FATFS_CODEPAGE_437 1 +#define CONFIG_FATFS_CODEPAGE 437 +#define CONFIG_FATFS_LFN_NONE 1 +#define CONFIG_FATFS_FS_LOCK 0 +#define CONFIG_FATFS_TIMEOUT_MS 10000 +#define CONFIG_FATFS_PER_FILE_CACHE 1 +#define CONFIG_FMB_COMM_MODE_RTU_EN 1 +#define CONFIG_FMB_COMM_MODE_ASCII_EN 1 +#define CONFIG_FMB_MASTER_TIMEOUT_MS_RESPOND 150 +#define CONFIG_FMB_MASTER_DELAY_MS_CONVERT 200 +#define CONFIG_FMB_QUEUE_LENGTH 20 +#define CONFIG_FMB_SERIAL_TASK_STACK_SIZE 2048 +#define CONFIG_FMB_SERIAL_BUF_SIZE 256 +#define CONFIG_FMB_SERIAL_ASCII_BITS_PER_SYMB 8 +#define CONFIG_FMB_SERIAL_ASCII_TIMEOUT_RESPOND_MS 1000 +#define CONFIG_FMB_SERIAL_TASK_PRIO 10 +#define CONFIG_FMB_CONTROLLER_NOTIFY_TIMEOUT 20 +#define CONFIG_FMB_CONTROLLER_NOTIFY_QUEUE_SIZE 20 +#define CONFIG_FMB_CONTROLLER_STACK_SIZE 4096 +#define CONFIG_FMB_EVENT_QUEUE_TIMEOUT 20 +#define CONFIG_FMB_TIMER_PORT_ENABLED 1 +#define CONFIG_FMB_TIMER_GROUP 0 +#define CONFIG_FMB_TIMER_INDEX 0 +#define CONFIG_FREERTOS_NO_AFFINITY 0x7FFFFFFF +#define CONFIG_FREERTOS_CORETIMER_0 1 +#define CONFIG_FREERTOS_HZ 100 +#define CONFIG_FREERTOS_ASSERT_ON_UNTESTED_FUNCTION 1 +#define CONFIG_FREERTOS_CHECK_STACKOVERFLOW_CANARY 1 +#define CONFIG_FREERTOS_INTERRUPT_BACKTRACE 1 +#define CONFIG_FREERTOS_THREAD_LOCAL_STORAGE_POINTERS 1 +#define CONFIG_FREERTOS_ASSERT_FAIL_ABORT 1 +#define CONFIG_FREERTOS_IDLE_TASK_STACKSIZE 1536 +#define CONFIG_FREERTOS_ISR_STACKSIZE 1536 +#define CONFIG_FREERTOS_MAX_TASK_NAME_LEN 16 +#define CONFIG_FREERTOS_TIMER_TASK_PRIORITY 1 +#define CONFIG_FREERTOS_TIMER_TASK_STACK_DEPTH 2048 +#define CONFIG_FREERTOS_TIMER_QUEUE_LENGTH 10 +#define CONFIG_FREERTOS_QUEUE_REGISTRY_SIZE 0 +#define CONFIG_FREERTOS_TASK_FUNCTION_WRAPPER 1 +#define CONFIG_FREERTOS_CHECK_MUTEX_GIVEN_BY_OWNER 1 +#define CONFIG_FREERTOS_DEBUG_OCDAWARE 1 +#define CONFIG_HEAP_POISONING_DISABLED 1 +#define CONFIG_HEAP_TRACING_OFF 1 +#define CONFIG_LOG_DEFAULT_LEVEL_INFO 1 +#define CONFIG_LOG_DEFAULT_LEVEL 3 +#define CONFIG_LOG_COLORS 1 +#define CONFIG_LOG_TIMESTAMP_SOURCE_RTOS 1 +#define CONFIG_LWIP_LOCAL_HOSTNAME "espressif" +#define CONFIG_LWIP_DNS_SUPPORT_MDNS_QUERIES 1 +#define CONFIG_LWIP_TIMERS_ONDEMAND 1 +#define CONFIG_LWIP_MAX_SOCKETS 10 +#define CONFIG_LWIP_SO_REUSE 1 +#define CONFIG_LWIP_SO_REUSE_RXTOALL 1 +#define CONFIG_LWIP_IP_FRAG 1 +#define CONFIG_LWIP_ESP_GRATUITOUS_ARP 1 +#define CONFIG_LWIP_GARP_TMR_INTERVAL 60 +#define CONFIG_LWIP_TCPIP_RECVMBOX_SIZE 32 +#define CONFIG_LWIP_DHCP_DOES_ARP_CHECK 1 +#define CONFIG_LWIP_DHCPS_LEASE_UNIT 60 +#define CONFIG_LWIP_DHCPS_MAX_STATION_NUM 8 +#define CONFIG_LWIP_NETIF_LOOPBACK 1 +#define CONFIG_LWIP_LOOPBACK_MAX_PBUFS 8 +#define CONFIG_LWIP_MAX_ACTIVE_TCP 16 +#define CONFIG_LWIP_MAX_LISTENING_TCP 16 +#define CONFIG_LWIP_TCP_MAXRTX 12 +#define CONFIG_LWIP_TCP_SYNMAXRTX 6 +#define CONFIG_LWIP_TCP_MSS 1440 +#define CONFIG_LWIP_TCP_TMR_INTERVAL 250 +#define CONFIG_LWIP_TCP_MSL 60000 +#define CONFIG_LWIP_TCP_SND_BUF_DEFAULT 5744 +#define CONFIG_LWIP_TCP_WND_DEFAULT 5744 +#define CONFIG_LWIP_TCP_RECVMBOX_SIZE 6 +#define CONFIG_LWIP_TCP_QUEUE_OOSEQ 1 +#define CONFIG_LWIP_TCP_OVERSIZE_MSS 1 +#define CONFIG_LWIP_MAX_UDP_PCBS 16 +#define CONFIG_LWIP_UDP_RECVMBOX_SIZE 6 +#define CONFIG_LWIP_TCPIP_TASK_STACK_SIZE 3072 +#define CONFIG_LWIP_TCPIP_TASK_AFFINITY_NO_AFFINITY 1 +#define CONFIG_LWIP_TCPIP_TASK_AFFINITY 0x7FFFFFFF +#define CONFIG_LWIP_MAX_RAW_PCBS 16 +#define CONFIG_LWIP_DHCP_MAX_NTP_SERVERS 1 +#define CONFIG_LWIP_SNTP_UPDATE_DELAY 3600000 +#define CONFIG_LWIP_ESP_LWIP_ASSERT 1 +#define CONFIG_MBEDTLS_INTERNAL_MEM_ALLOC 1 +#define CONFIG_MBEDTLS_ASYMMETRIC_CONTENT_LEN 1 +#define CONFIG_MBEDTLS_SSL_IN_CONTENT_LEN 16384 +#define CONFIG_MBEDTLS_SSL_OUT_CONTENT_LEN 4096 +#define CONFIG_MBEDTLS_CERTIFICATE_BUNDLE 1 +#define CONFIG_MBEDTLS_CERTIFICATE_BUNDLE_DEFAULT_FULL 1 +#define CONFIG_MBEDTLS_HARDWARE_AES 1 +#define CONFIG_MBEDTLS_HARDWARE_MPI 1 +#define CONFIG_MBEDTLS_HARDWARE_SHA 1 +#define CONFIG_MBEDTLS_HAVE_TIME 1 +#define CONFIG_MBEDTLS_TLS_SERVER_AND_CLIENT 1 +#define CONFIG_MBEDTLS_TLS_SERVER 1 +#define CONFIG_MBEDTLS_TLS_CLIENT 1 +#define CONFIG_MBEDTLS_TLS_ENABLED 1 +#define CONFIG_MBEDTLS_PSK_MODES 1 +#define CONFIG_MBEDTLS_KEY_EXCHANGE_PSK 1 +#define CONFIG_MBEDTLS_KEY_EXCHANGE_DHE_PSK 1 +#define CONFIG_MBEDTLS_KEY_EXCHANGE_ECDHE_PSK 1 +#define CONFIG_MBEDTLS_KEY_EXCHANGE_RSA_PSK 1 +#define CONFIG_MBEDTLS_KEY_EXCHANGE_RSA 1 +#define CONFIG_MBEDTLS_KEY_EXCHANGE_DHE_RSA 1 +#define CONFIG_MBEDTLS_KEY_EXCHANGE_ELLIPTIC_CURVE 1 +#define CONFIG_MBEDTLS_KEY_EXCHANGE_ECDHE_RSA 1 +#define CONFIG_MBEDTLS_KEY_EXCHANGE_ECDHE_ECDSA 1 +#define CONFIG_MBEDTLS_KEY_EXCHANGE_ECDH_ECDSA 1 +#define CONFIG_MBEDTLS_KEY_EXCHANGE_ECDH_RSA 1 +#define CONFIG_MBEDTLS_SSL_RENEGOTIATION 1 +#define CONFIG_MBEDTLS_SSL_PROTO_TLS1 1 +#define CONFIG_MBEDTLS_SSL_PROTO_TLS1_1 1 +#define CONFIG_MBEDTLS_SSL_PROTO_TLS1_2 1 +#define CONFIG_MBEDTLS_SSL_PROTO_DTLS 1 +#define CONFIG_MBEDTLS_SSL_ALPN 1 +#define CONFIG_MBEDTLS_CLIENT_SSL_SESSION_TICKETS 1 +#define CONFIG_MBEDTLS_SERVER_SSL_SESSION_TICKETS 1 +#define CONFIG_MBEDTLS_AES_C 1 +#define CONFIG_MBEDTLS_RC4_DISABLED 1 +#define CONFIG_MBEDTLS_CCM_C 1 +#define CONFIG_MBEDTLS_GCM_C 1 +#define CONFIG_MBEDTLS_PEM_PARSE_C 1 +#define CONFIG_MBEDTLS_PEM_WRITE_C 1 +#define CONFIG_MBEDTLS_X509_CRL_PARSE_C 1 +#define CONFIG_MBEDTLS_X509_CSR_PARSE_C 1 +#define CONFIG_MBEDTLS_ECP_C 1 +#define CONFIG_MBEDTLS_ECDH_C 1 +#define CONFIG_MBEDTLS_ECDSA_C 1 +#define CONFIG_MBEDTLS_ECP_DP_SECP192R1_ENABLED 1 +#define CONFIG_MBEDTLS_ECP_DP_SECP224R1_ENABLED 1 +#define CONFIG_MBEDTLS_ECP_DP_SECP256R1_ENABLED 1 +#define CONFIG_MBEDTLS_ECP_DP_SECP384R1_ENABLED 1 +#define CONFIG_MBEDTLS_ECP_DP_SECP521R1_ENABLED 1 +#define CONFIG_MBEDTLS_ECP_DP_SECP192K1_ENABLED 1 +#define CONFIG_MBEDTLS_ECP_DP_SECP224K1_ENABLED 1 +#define CONFIG_MBEDTLS_ECP_DP_SECP256K1_ENABLED 1 +#define CONFIG_MBEDTLS_ECP_DP_BP256R1_ENABLED 1 +#define CONFIG_MBEDTLS_ECP_DP_BP384R1_ENABLED 1 +#define CONFIG_MBEDTLS_ECP_DP_BP512R1_ENABLED 1 +#define CONFIG_MBEDTLS_ECP_DP_CURVE25519_ENABLED 1 +#define CONFIG_MBEDTLS_ECP_NIST_OPTIM 1 +#define CONFIG_MDNS_MAX_SERVICES 10 +#define CONFIG_MDNS_TASK_PRIORITY 1 +#define CONFIG_MDNS_TASK_AFFINITY_CPU0 1 +#define CONFIG_MDNS_TASK_AFFINITY 0x0 +#define CONFIG_MDNS_SERVICE_ADD_TIMEOUT_MS 2000 +#define CONFIG_MDNS_TIMER_PERIOD_MS 100 +#define CONFIG_MQTT_PROTOCOL_311 1 +#define CONFIG_MQTT_TRANSPORT_SSL 1 +#define CONFIG_MQTT_TRANSPORT_WEBSOCKET 1 +#define CONFIG_MQTT_TRANSPORT_WEBSOCKET_SECURE 1 +#define CONFIG_NEWLIB_STDOUT_LINE_ENDING_CRLF 1 +#define CONFIG_NEWLIB_STDIN_LINE_ENDING_CR 1 +#define CONFIG_OPENSSL_ASSERT_EXIT 1 +#define CONFIG_PTHREAD_TASK_PRIO_DEFAULT 5 +#define CONFIG_PTHREAD_TASK_STACK_SIZE_DEFAULT 3072 +#define CONFIG_PTHREAD_STACK_MIN 768 +#define CONFIG_PTHREAD_DEFAULT_CORE_NO_AFFINITY 1 +#define CONFIG_PTHREAD_TASK_CORE_DEFAULT -1 +#define CONFIG_PTHREAD_TASK_NAME_DEFAULT "pthread" +#define CONFIG_SPI_FLASH_ROM_DRIVER_PATCH 1 +#define CONFIG_SPI_FLASH_DANGEROUS_WRITE_ABORTS 1 +#define CONFIG_SPI_FLASH_YIELD_DURING_ERASE 1 +#define CONFIG_SPI_FLASH_ERASE_YIELD_DURATION_MS 20 +#define CONFIG_SPI_FLASH_ERASE_YIELD_TICKS 1 +#define CONFIG_SPI_FLASH_SUPPORT_ISSI_CHIP 1 +#define CONFIG_SPI_FLASH_SUPPORT_MXIC_CHIP 1 +#define CONFIG_SPI_FLASH_SUPPORT_GD_CHIP 1 +#define CONFIG_SPIFFS_MAX_PARTITIONS 3 +#define CONFIG_SPIFFS_CACHE 1 +#define CONFIG_SPIFFS_CACHE_WR 1 +#define CONFIG_SPIFFS_PAGE_CHECK 1 +#define CONFIG_SPIFFS_GC_MAX_RUNS 10 +#define CONFIG_SPIFFS_PAGE_SIZE 256 +#define CONFIG_SPIFFS_OBJ_NAME_LEN 32 +#define CONFIG_SPIFFS_USE_MAGIC 1 +#define CONFIG_SPIFFS_USE_MAGIC_LENGTH 1 +#define CONFIG_SPIFFS_META_LENGTH 4 +#define CONFIG_SPIFFS_USE_MTIME 1 +#define CONFIG_USB_DESC_CUSTOM_VID 0x1234 +#define CONFIG_USB_DESC_CUSTOM_PID 0x5678 +#define CONFIG_UNITY_ENABLE_FLOAT 1 +#define CONFIG_UNITY_ENABLE_DOUBLE 1 +#define CONFIG_UNITY_ENABLE_IDF_TEST_RUNNER 1 +#define CONFIG_VFS_SUPPORT_IO 1 +#define CONFIG_VFS_SUPPORT_DIR 1 +#define CONFIG_VFS_SUPPORT_SELECT 1 +#define CONFIG_VFS_SUPPRESS_SELECT_DEBUG_OUTPUT 1 +#define CONFIG_VFS_SUPPORT_TERMIOS 1 +#define CONFIG_VFS_SEMIHOSTFS_MAX_MOUNT_POINTS 1 +#define CONFIG_VFS_SEMIHOSTFS_HOST_PATH_MAX_LEN 128 +#define CONFIG_WL_SECTOR_SIZE_4096 1 +#define CONFIG_WL_SECTOR_SIZE 4096 +#define CONFIG_WIFI_PROV_SCAN_MAX_ENTRIES 16 +#define CONFIG_WIFI_PROV_AUTOSTOP_TIMEOUT 30 +#define CONFIG_WPA_MBEDTLS_CRYPTO 1 + +/* List of deprecated options */ +#define CONFIG_ADC2_DISABLE_DAC CONFIG_ADC_DISABLE_DAC +#define CONFIG_BROWNOUT_DET CONFIG_ESP32_BROWNOUT_DET +#define CONFIG_BROWNOUT_DET_LVL_SEL_0 CONFIG_ESP32_BROWNOUT_DET_LVL_SEL_0 +#define CONFIG_COMPILER_OPTIMIZATION_LEVEL_DEBUG CONFIG_COMPILER_OPTIMIZATION_DEFAULT +#define CONFIG_CONSOLE_UART_BAUDRATE CONFIG_ESP_CONSOLE_UART_BAUDRATE +#define CONFIG_CONSOLE_UART_DEFAULT CONFIG_ESP_CONSOLE_UART_DEFAULT +#define CONFIG_CONSOLE_UART_RX_GPIO CONFIG_ESP_CONSOLE_UART_RX_GPIO +#define CONFIG_CONSOLE_UART_TX_GPIO CONFIG_ESP_CONSOLE_UART_TX_GPIO +#define CONFIG_ESP32S2_PANIC_PRINT_REBOOT CONFIG_ESP_SYSTEM_PANIC_PRINT_REBOOT +#define CONFIG_ESP32_APPTRACE_DEST_NONE CONFIG_APPTRACE_DEST_NONE +#define CONFIG_ESP32_DEFAULT_PTHREAD_CORE_NO_AFFINITY CONFIG_PTHREAD_DEFAULT_CORE_NO_AFFINITY +#define CONFIG_ESP32_PANIC_PRINT_REBOOT CONFIG_ESP_SYSTEM_PANIC_PRINT_REBOOT +#define CONFIG_ESP32_PTHREAD_STACK_MIN CONFIG_PTHREAD_STACK_MIN +#define CONFIG_ESP32_PTHREAD_TASK_NAME_DEFAULT CONFIG_PTHREAD_TASK_NAME_DEFAULT +#define CONFIG_ESP32_PTHREAD_TASK_PRIO_DEFAULT CONFIG_PTHREAD_TASK_PRIO_DEFAULT +#define CONFIG_ESP32_PTHREAD_TASK_STACK_SIZE_DEFAULT CONFIG_PTHREAD_TASK_STACK_SIZE_DEFAULT +#define CONFIG_ESP32_RTC_CLOCK_SOURCE_INTERNAL_RC CONFIG_ESP32_RTC_CLK_SRC_INT_RC +#define CONFIG_ESP_GRATUITOUS_ARP CONFIG_LWIP_ESP_GRATUITOUS_ARP +#define CONFIG_FLASHMODE_DIO CONFIG_ESPTOOLPY_FLASHMODE_DIO +#define CONFIG_FOUR_UNIVERSAL_MAC_ADDRESS CONFIG_ESP32_UNIVERSAL_MAC_ADDRESSES_FOUR +#define CONFIG_GARP_TMR_INTERVAL CONFIG_LWIP_GARP_TMR_INTERVAL +#define CONFIG_INT_WDT CONFIG_ESP_INT_WDT +#define CONFIG_INT_WDT_CHECK_CPU1 CONFIG_ESP_INT_WDT_CHECK_CPU1 +#define CONFIG_INT_WDT_TIMEOUT_MS CONFIG_ESP_INT_WDT_TIMEOUT_MS +#define CONFIG_IPC_TASK_STACK_SIZE CONFIG_ESP_IPC_TASK_STACK_SIZE +#define CONFIG_LOG_BOOTLOADER_LEVEL_INFO CONFIG_BOOTLOADER_LOG_LEVEL_INFO +#define CONFIG_MAIN_TASK_STACK_SIZE CONFIG_ESP_MAIN_TASK_STACK_SIZE +#define CONFIG_MB_CONTROLLER_NOTIFY_QUEUE_SIZE CONFIG_FMB_CONTROLLER_NOTIFY_QUEUE_SIZE +#define CONFIG_MB_CONTROLLER_NOTIFY_TIMEOUT CONFIG_FMB_CONTROLLER_NOTIFY_TIMEOUT +#define CONFIG_MB_CONTROLLER_STACK_SIZE CONFIG_FMB_CONTROLLER_STACK_SIZE +#define CONFIG_MB_EVENT_QUEUE_TIMEOUT CONFIG_FMB_EVENT_QUEUE_TIMEOUT +#define CONFIG_MB_MASTER_DELAY_MS_CONVERT CONFIG_FMB_MASTER_DELAY_MS_CONVERT +#define CONFIG_MB_MASTER_TIMEOUT_MS_RESPOND CONFIG_FMB_MASTER_TIMEOUT_MS_RESPOND +#define CONFIG_MB_QUEUE_LENGTH CONFIG_FMB_QUEUE_LENGTH +#define CONFIG_MB_SERIAL_BUF_SIZE CONFIG_FMB_SERIAL_BUF_SIZE +#define CONFIG_MB_SERIAL_TASK_PRIO CONFIG_FMB_SERIAL_TASK_PRIO +#define CONFIG_MB_SERIAL_TASK_STACK_SIZE CONFIG_FMB_SERIAL_TASK_STACK_SIZE +#define CONFIG_MB_TIMER_GROUP CONFIG_FMB_TIMER_GROUP +#define CONFIG_MB_TIMER_INDEX CONFIG_FMB_TIMER_INDEX +#define CONFIG_MB_TIMER_PORT_ENABLED CONFIG_FMB_TIMER_PORT_ENABLED +#define CONFIG_MONITOR_BAUD_115200B CONFIG_ESPTOOLPY_MONITOR_BAUD_115200B +#define CONFIG_OPTIMIZATION_ASSERTIONS_ENABLED CONFIG_COMPILER_OPTIMIZATION_ASSERTIONS_ENABLE +#define CONFIG_OPTIMIZATION_LEVEL_DEBUG CONFIG_COMPILER_OPTIMIZATION_DEFAULT +#define CONFIG_POST_EVENTS_FROM_IRAM_ISR CONFIG_ESP_EVENT_POST_FROM_IRAM_ISR +#define CONFIG_POST_EVENTS_FROM_ISR CONFIG_ESP_EVENT_POST_FROM_ISR +#define CONFIG_REDUCE_PHY_TX_POWER CONFIG_ESP32_REDUCE_PHY_TX_POWER +#define CONFIG_SEMIHOSTFS_HOST_PATH_MAX_LEN CONFIG_VFS_SEMIHOSTFS_HOST_PATH_MAX_LEN +#define CONFIG_SEMIHOSTFS_MAX_MOUNT_POINTS CONFIG_VFS_SEMIHOSTFS_MAX_MOUNT_POINTS +#define CONFIG_SPI_FLASH_WRITING_DANGEROUS_REGIONS_ABORTS CONFIG_SPI_FLASH_DANGEROUS_WRITE_ABORTS +#define CONFIG_STACK_CHECK_NONE CONFIG_COMPILER_STACK_CHECK_MODE_NONE +#define CONFIG_SUPPORT_TERMIOS CONFIG_VFS_SUPPORT_TERMIOS +#define CONFIG_SUPPRESS_SELECT_DEBUG_OUTPUT CONFIG_VFS_SUPPRESS_SELECT_DEBUG_OUTPUT +#define CONFIG_SYSTEM_EVENT_QUEUE_SIZE CONFIG_ESP_SYSTEM_EVENT_QUEUE_SIZE +#define CONFIG_SYSTEM_EVENT_TASK_STACK_SIZE CONFIG_ESP_SYSTEM_EVENT_TASK_STACK_SIZE +#define CONFIG_TASK_WDT CONFIG_ESP_TASK_WDT +#define CONFIG_TASK_WDT_CHECK_IDLE_TASK_CPU0 CONFIG_ESP_TASK_WDT_CHECK_IDLE_TASK_CPU0 +#define CONFIG_TASK_WDT_CHECK_IDLE_TASK_CPU1 CONFIG_ESP_TASK_WDT_CHECK_IDLE_TASK_CPU1 +#define CONFIG_TASK_WDT_TIMEOUT_S CONFIG_ESP_TASK_WDT_TIMEOUT_S +#define CONFIG_TCPIP_RECVMBOX_SIZE CONFIG_LWIP_TCPIP_RECVMBOX_SIZE +#define CONFIG_TCPIP_TASK_AFFINITY_NO_AFFINITY CONFIG_LWIP_TCPIP_TASK_AFFINITY_NO_AFFINITY +#define CONFIG_TCPIP_TASK_STACK_SIZE CONFIG_LWIP_TCPIP_TASK_STACK_SIZE +#define CONFIG_TCP_MAXRTX CONFIG_LWIP_TCP_MAXRTX +#define CONFIG_TCP_MSL CONFIG_LWIP_TCP_MSL +#define CONFIG_TCP_MSS CONFIG_LWIP_TCP_MSS +#define CONFIG_TCP_OVERSIZE_MSS CONFIG_LWIP_TCP_OVERSIZE_MSS +#define CONFIG_TCP_QUEUE_OOSEQ CONFIG_LWIP_TCP_QUEUE_OOSEQ +#define CONFIG_TCP_RECVMBOX_SIZE CONFIG_LWIP_TCP_RECVMBOX_SIZE +#define CONFIG_TCP_SND_BUF_DEFAULT CONFIG_LWIP_TCP_SND_BUF_DEFAULT +#define CONFIG_TCP_SYNMAXRTX CONFIG_LWIP_TCP_SYNMAXRTX +#define CONFIG_TCP_WND_DEFAULT CONFIG_LWIP_TCP_WND_DEFAULT +#define CONFIG_TIMER_QUEUE_LENGTH CONFIG_FREERTOS_TIMER_QUEUE_LENGTH +#define CONFIG_TIMER_TASK_PRIORITY CONFIG_FREERTOS_TIMER_TASK_PRIORITY +#define CONFIG_TIMER_TASK_STACK_DEPTH CONFIG_FREERTOS_TIMER_TASK_STACK_DEPTH +#define CONFIG_TIMER_TASK_STACK_SIZE CONFIG_ESP_TIMER_TASK_STACK_SIZE +#define CONFIG_TOOLPREFIX CONFIG_SDK_TOOLPREFIX +#define CONFIG_UDP_RECVMBOX_SIZE CONFIG_LWIP_UDP_RECVMBOX_SIZE diff -Nru libwebsockets-3.2.1/minimal-examples/embedded/esp32/esp-wrover-kit/CMakeLists.txt libwebsockets-4.1.6/minimal-examples/embedded/esp32/esp-wrover-kit/CMakeLists.txt --- libwebsockets-3.2.1/minimal-examples/embedded/esp32/esp-wrover-kit/CMakeLists.txt 1970-01-01 00:00:00.000000000 +0000 +++ libwebsockets-4.1.6/minimal-examples/embedded/esp32/esp-wrover-kit/CMakeLists.txt 2020-12-01 17:40:26.000000000 +0000 @@ -0,0 +1,33 @@ +cmake_minimum_required(VERSION 3.5) + +if (ESP_PLATFORM) + include($ENV{IDF_PATH}/tools/cmake/project.cmake) + project(lws-minimal-esp32 C) + enable_testing() + + target_link_libraries(lws-minimal-esp32.elf websockets) + + option(LWS_WITH_DRIVERS "With generic drivers for gpio, i2c, display etc" ON) + set(LWS_WITH_DRIVERS ON) + option(LWS_WITH_SECURE_STREAMS "With secure streams" ON) + set(LWS_WITH_SECURE_STREAMS ON) + option(LWS_WITH_LWSAC "With lwsac" ON) + set(LWS_WITH_LWSAC ON) + option(LWS_WITH_STRUCT_JSON "With lws_struct JSON" ON) + set(LWS_WITH_STRUCT_JSON ON) + option(LWS_WITH_SYS_NTPCLIENT "With ntpclient" ON) + set(LWS_WITH_SYS_NTPCLIENT ON) + + add_subdirectory(libwebsockets) + + add_test(NAME flashing COMMAND idf.py flash) + set_tests_properties(flashing PROPERTIES + WORKING_DIRECTORY ${CMAKE_SOURCE_DIR} + TIMEOUT 120) + + add_test(NAME boot COMMAND /usr/local/bin/sai-expect) + set_tests_properties(boot PROPERTIES + DEPENDS flashing + TIMEOUT 60) + +endif() diff -Nru libwebsockets-3.2.1/minimal-examples/embedded/esp32/esp-wrover-kit/main/cat-565.h libwebsockets-4.1.6/minimal-examples/embedded/esp32/esp-wrover-kit/main/cat-565.h --- libwebsockets-3.2.1/minimal-examples/embedded/esp32/esp-wrover-kit/main/cat-565.h 1970-01-01 00:00:00.000000000 +0000 +++ libwebsockets-4.1.6/minimal-examples/embedded/esp32/esp-wrover-kit/main/cat-565.h 2020-12-01 17:40:26.000000000 +0000 @@ -0,0 +1,19200 @@ +0x62, 0xEB, 0x5A, 0xAA, 0x52, 0x8A, 0x52, 0x69, +0x5A, 0xAA, 0x62, 0xEB, 0x73, 0x0C, 0x72, 0xEB, +0x52, 0x08, 0x31, 0x24, 0x4A, 0x08, 0x4A, 0x07, +0x41, 0xE7, 0x39, 0xC6, 0x39, 0xC6, 0x31, 0x85, +0x29, 0x44, 0x21, 0x24, 0x31, 0x85, 0x41, 0xE7, +0x41, 0xE7, 0x39, 0x85, 0x41, 0xA6, 0x39, 0x45, +0x31, 0x24, 0x29, 0x04, 0x20, 0xC3, 0x28, 0xC3, +0x28, 0xC2, 0x28, 0xC2, 0x31, 0x04, 0x49, 0xA6, +0x5A, 0x27, 0x62, 0x48, 0x62, 0x48, 0x52, 0x27, +0x39, 0x86, 0x20, 0xE3, 0x29, 0x24, 0x41, 0xE8, +0x39, 0xA6, 0x4A, 0x48, 0x4A, 0x49, 0x39, 0xC7, +0x31, 0x65, 0x29, 0x24, 0x6B, 0x2C, 0x4A, 0x29, +0x52, 0x69, 0x84, 0x10, 0x63, 0x0B, 0x52, 0x6A, +0x62, 0xEB, 0x4A, 0x08, 0x6B, 0x0C, 0x6B, 0x2C, +0x5A, 0xAB, 0x39, 0xC7, 0x31, 0x86, 0x73, 0xAF, +0xDE, 0xFD, 0xDE, 0xDC, 0xBD, 0xF8, 0x94, 0x92, +0x4A, 0x28, 0x29, 0x44, 0x39, 0xE6, 0x4A, 0x48, +0x6B, 0x2C, 0x52, 0x8A, 0x73, 0x6D,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0xD4, +0xC5, 0xB3, 0xC5, 0xB3, 0xBD, 0x73, 0xB5, 0x73, +0xA4, 0xF1, 0xA4, 0xF2, 0x94, 0x70, 0xA4, 0xF1, +0xA4, 0xF2, 0x94, 0x90, 0x94, 0x71, 0x8C, 0x70, +0x9C, 0xD2, 0xA5, 0x13, 0xA4, 0xF3, 0x8C, 0x50, +0x8C, 0x50, 0x8C, 0x30, 0x7B, 0xCF, 0x6B, 0x4D, +0x4A, 0x6A, 0x29, 0x66, 0x21, 0x25, 0x21, 0x04, +0x18, 0xE4, 0x18, 0xE4, 0x29, 0x66, 0x4A, 0x6A, +0x6B, 0x6E, 0x8C, 0x51, 0xA4, 0xF4, 0xA5, 0x14, +0xA5, 0x35, 0xA5, 0x14, 0x9C, 0xD3, 0x8C, 0x51, +0x7B, 0xEF, 0x7B, 0xAE, 0x84, 0x10, 0x84, 0x10, +0x6B, 0x2C, 0x7B, 0xAE, 0x84, 0x10, 0x84, 0x32, +0x7C, 0x12, 0x73, 0xD1, 0x7C, 0x12, 0x8C, 0x94, +0x94, 0xD5, 0x8C, 0xB5, 0x94, 0xD5, 0x94, 0xD5, +0x94, 0xD5, 0x94, 0xF5, 0x8C, 0xD5, 0x94, 0xD5, +0x95, 0x16, 0x94, 0xD5, 0x84, 0x73, 0x84, 0x32, +0x84, 0x32, 0x73, 0xD0, 0x7B, 0xD0, 0x84, 0x31, +0x7B, 0xF0, 0x73, 0xAF, 0x73, 0x8F, 0x6B, 0x4E, +0x4A, 0x28, 0x42, 0x07, 0x4A, 0x07, 0x41, 0xE7, +0x4A, 0x08, 0x41, 0xE7, 0x73, 0x4C, 0x7B, 0x4C, +0x31, 0x45, 0x29, 0x03, 0x41, 0xE6, 0x39, 0xA6, +0x39, 0xA6, 0x31, 0x85, 0x39, 0xC6, 0x42, 0x07, +0x39, 0xE7, 0x29, 0x64, 0x31, 0x85, 0x21, 0x03, +0x29, 0x04, 0x31, 0x65, 0x42, 0x07, 0x29, 0x24, +0x31, 0x45,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, 0xAD, 0x76, 0xA5, 0x56, 0x9C, 0xF5, +0x8C, 0x93, 0x84, 0x32, 0x7C, 0x12, 0x7B, 0xF1, +0x73, 0xB0, 0x73, 0xD1, 0x7C, 0x12, 0x84, 0x53, +0x8C, 0x94, 0x84, 0x73, 0x7C, 0x12, 0x73, 0xB0, +0x6B, 0x8F, 0x5A, 0xED, 0x52, 0xCC, 0x52, 0xAC, +0x4A, 0x6B, 0x39, 0xE8, 0x31, 0xA7, 0x29, 0x87, +0x31, 0x65, 0x39, 0xA5, 0x39, 0xA5, 0x39, 0x85, +0x31, 0x85, 0x31, 0x65, 0x94, 0x51, 0xD6, 0x38, +0x83, 0xAE, 0x29, 0x44, 0x31, 0x65, 0x31, 0x65, +0x31, 0x85, 0x31, 0x85, 0x31, 0xA6, 0x39, 0xA6, +0x39, 0xA6, 0x21, 0x03, 0x21, 0x24, 0x21, 0x24, +0x73, 0xAE, 0xAD, 0x55, 0xAD, 0x75, 0xA5, 0x14, +0x8C, 0x51, 0x42, 0x07, 0x41, 0xC7, 0x62, 0x8A, +0x8B, 0x4C, 0x93, 0x6C, 0x9B, 0xAD, 0x72, 0x68, +0x82, 0xEA, 0xC4, 0xD0, 0xBC, 0x70, 0x93, 0x6C, +0x9C, 0x0F, 0xA4, 0x51, 0x6A, 0xCA, 0x20, 0xC2, +0x18, 0xC3, 0x18, 0xC3, 0x18, 0xE3, 0x18, 0xE3, +0x18, 0xC3, 0x29, 0x65, 0x42, 0x07, 0x29, 0x24, +0x29, 0x24, 0x4A, 0x69, 0x5A, 0xCA, 0x42, 0x07, +0x42, 0x08, 0x41, 0xE7, 0x39, 0xC6, 0x31, 0xA6, +0x31, 0xA6, 0x39, 0xA6, 0x8C, 0x72, 0xE7, 0x1D, +0xD6, 0x9B, 0xC6, 0x19, 0x7B, 0xD0, 0x31, 0x86, +0x42, 0x07, 0x4A, 0x48, 0x4A, 0x69, 0x4A, 0x28, +0x63, 0x0B, 0x31, 0x65, 0x31, 0xA6, 0x52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0xC5, 0x92, 0xD6, 0x14, 0xD6, 0x14, 0xDE, 0x34, +0xD6, 0x14, 0xC5, 0x93, 0xB5, 0x10, 0xAC, 0xF1, +0xB5, 0x32, 0xCD, 0xF5, 0xBD, 0xB4, 0xD6, 0x57, +0xD6, 0x78, 0xBD, 0xB5, 0xAD, 0x53, 0x7B, 0xCE, +0x84, 0x2F, 0xA4, 0xF3, 0xAD, 0x54, 0x94, 0x91, +0x83, 0xEF, 0x8C, 0x50, 0x94, 0x91, 0x9C, 0xB2, +0x8C, 0x50, 0x7B, 0xEF, 0x73, 0x6D, 0x5A, 0xEB, +0x31, 0x86, 0x21, 0x05, 0x18, 0xE4, 0x18, 0xE4, +0x21, 0x05, 0x29, 0x46, 0x29, 0x87, 0x3A, 0x08, +0x63, 0x0D, 0x84, 0x31, 0x73, 0x8F, 0x63, 0x4D, +0x6B, 0x6E, 0x73, 0xAF, 0x73, 0x8F, 0x73, 0x8F, +0x73, 0x6E, 0x73, 0x8E, 0x6B, 0x4D, 0x73, 0xAF, +0x9C, 0xD4, 0x9D, 0x15, 0x9D, 0x15, 0x9C, 0xF5, +0x9C, 0xF4, 0x9C, 0xF4, 0x9D, 0x15, 0x9D, 0x15, +0x9C, 0xD5, 0x9D, 0x15, 0xA5, 0x56, 0xAD, 0x97, +0xB5, 0xB8, 0xB5, 0xD9, 0xB5, 0xB8, 0xA5, 0x56, +0x94, 0xD4, 0x84, 0x53, 0x84, 0x32, 0x7B, 0xF1, +0x52, 0xAA, 0x52, 0xCB, 0x52, 0xCA, 0x4A, 0x49, +0x29, 0x24, 0x31, 0x86, 0x7B, 0xCE, 0xCD, 0xF7, +0xA4, 0x71, 0x39, 0x85, 0x21, 0x04, 0x39, 0xC6, +0x29, 0x65, 0x21, 0x24, 0x29, 0x44, 0x39, 0xC6, +0x4A, 0x48, 0x31, 0xA6, 0x31, 0x86, 0x4A, 0x48, +0x7B, 0xAE, 0x9C, 0xB2, 0x94, 0x71, 0x9C, 0xB2, +0x6B, 0x0B, 0x29, 0x03, 0x29, 0x44, 0x62, 0x89, +0x93, 0x6C, 0x83, 0x0A, 0x93, 0x4B, 0x83, 0x0A, +0x41, 0x64, 0x62, 0x89, 0x6A, 0x89, 0x52, 0x48, +0x62, 0xCA, 0x41, 0xE7, 0x5A, 0xCA, 0x4A, 0x28, +0x21, 0x24, 0x29, 0x65, 0x21, 0x24, 0x21, 0x24, +0x21, 0x24, 0x18, 0xC3, 0x18, 0xE3, 0x29, 0x45, +0x21, 0x04, 0x29, 0x44, 0x39, 0xE7, 0x39, 0xC6, +0x39, 0xC6, 0x31, 0xA6, 0x31, 0x85, 0x29, 0x85, +0x31, 0x85, 0x31, 0xC6, 0xB5, 0xD7, 0xE7, 0x5E, +0xD6, 0xBC, 0xB5, 0x77, 0x5A, 0xCB, 0x52, 0x8A, +0x42, 0x28, 0x31, 0x85, 0x42, 0x07, 0x39, 0xE7, +0x5A, 0xEB, 0x39, 0xC7, 0x31, 0x86, 0x39, 0xE7, +0x42, 0x28, 0x63, 0x0C, 0x62, 0xCB, 0x7B, 0xAE, +0xA4, 0xB2, 0xA4, 0xB2, 0xBD, 0x75, 0xDE, 0x79, +0xC5, 0xF7, 0x7B, 0x8D, 0x8C, 0x50, 0xBD, 0xB6, +0x4A, 0x28, 0x84, 0x0E, 0xCE, 0x36, 0xD6, 0x97, +0xD6, 0x56, 0x94, 0x70, 0x73, 0x8D, 0x8C, 0x70, +0x94, 0xB1, 0x94, 0x90, 0xAD, 0x11, 0x7B, 0x6B, +0xA4, 0xD0, 0xA4, 0xF0, 0x94, 0x6F, 0x94, 0x4E, +0x8C, 0x0D, 0x8C, 0x0D, 0x83, 0xCC, 0x8C, 0x2D, +0x94, 0x8F, 0x9C, 0x8F, 0x8C, 0x0C, 0x8C, 0x0D, +0x94, 0x6E, 0x94, 0x2D, 0xAC, 0xF0, 0x94, 0x0D, +0x94, 0x4E, 0xAD, 0x11, 0x9C, 0xD0, 0x94, 0x6F, +0x8C, 0x0D, 0xA5, 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x73, 0xAF, 0x6B, 0x4E, +0x63, 0x0C, 0x6B, 0x6E, 0x84, 0x31, 0x7B, 0xCF, +0x6B, 0x2C, 0x83, 0xCF, 0x9C, 0xD3, 0x94, 0x93, +0x94, 0x93, 0x9C, 0xD4, 0xA5, 0x15, 0x9C, 0xF5, +0x94, 0xD4, 0x9C, 0xF4, 0xA5, 0x36, 0xAD, 0x77, +0xB5, 0xB8, 0xB5, 0xB8, 0xAD, 0x77, 0x9D, 0x15, +0xAD, 0x96, 0xAD, 0x96, 0xAD, 0x76, 0xA5, 0x55, +0x8C, 0x72, 0x7C, 0x10, 0x73, 0x4D, 0xCD, 0xD6, +0x8B, 0xAE, 0x62, 0xEB, 0x5A, 0xEB, 0x73, 0xAE, +0x73, 0x8D, 0x73, 0x6D, 0x7B, 0xAE, 0x84, 0x2F, +0x8C, 0x30, 0x84, 0x0F, 0x6B, 0x4C, 0x73, 0x8D, +0x39, 0xA6, 0x31, 0x65, 0x62, 0xCA, 0x5A, 0x69, +0x52, 0x69, 0x39, 0xC7, 0x5A, 0xAA, 0x72, 0xEB, +0x8B, 0x4C, 0x82, 0xEA, 0x82, 0xEA, 0x8B, 0x0B, +0x62, 0x68, 0x83, 0xAD, 0x8B, 0xCD, 0x94, 0x0E, +0x8B, 0xED, 0x7B, 0x8D, 0x8C, 0x2F, 0x83, 0xEE, +0x62, 0xEB, 0x4A, 0x69, 0x31, 0xA6, 0x21, 0x03, +0x29, 0x44, 0x29, 0x45, 0x21, 0x24, 0x29, 0x65, +0x21, 0x24, 0x21, 0x03, 0x29, 0x44, 0x29, 0x64, +0x29, 0x44, 0x29, 0x65, 0x29, 0x44, 0x29, 0x24, +0x29, 0x44, 0x63, 0x0C, 0xE7, 0x3D, 0xDE, 0xDC, +0xAD, 0x35, 0x9C, 0xB3, 0xA5, 0x14, 0x7B, 0xEF, +0x39, 0xA6, 0x21, 0x24, 0x4A, 0x48, 0x41, 0xE7, +0x4A, 0x28, 0x31, 0xA6, 0x42, 0x08,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x52, 0x69, 0x62, 0xEB, 0x5A, 0xCA, +0x39, 0xE7, 0x29, 0x44, 0x39, 0xC7, 0x39, 0xE7, +0x29, 0x65, 0x42, 0x28, 0x4A, 0x48, 0x52, 0x69, +0x63, 0x2C, 0x8C, 0x50, 0x8C, 0x50, 0x8C, 0x71, +0x8C, 0x51, 0x9D, 0x15, 0xA5, 0x35, 0xAD, 0x56, +0xAD, 0x35, 0xBD, 0xB6, 0xCE, 0x17, 0xC5, 0xD7, +0xC6, 0x38, 0xAD, 0x35, 0x8C, 0x71, 0x9C, 0x6F, +0xA4, 0xAF, 0x94, 0x0C, 0xA4, 0x8E, 0xA4, 0x8E, +0x9C, 0x6D, 0x9C, 0x4D, 0x9C, 0x6D, 0xA4, 0x8E, +0xB4, 0xF0, 0xBD, 0x51, 0xBD, 0x50, 0xC5, 0x92, +0xC5, 0xD4, 0xC5, 0xD4, 0xC5, 0xD4, 0xB5, 0x52, +0xBD, 0x72, 0xC5, 0xD4, 0xC5, 0xD5, 0xBD, 0x94, +0xBD, 0xB4, 0xB5, 0x73, 0xAD, 0x32, 0xAD, 0x12, +0xAC, 0xF1, 0xAD, 0x11, 0xA4, 0xD1, 0xA4, 0xF1, +0xA4, 0xD0, 0xA4, 0xB0, 0xA4, 0xB0, 0x9C, 0x90, +0x9C, 0x6F, 0x8C, 0x2F, 0x62, 0xEB, 0x29, 0x46, +0x31, 0x87, 0x31, 0x87, 0x39, 0xA7, 0x29, 0x45, +0x21, 0x04, 0x21, 0x04, 0x21, 0x05, 0x21, 0x05, +0x21, 0x25, 0x29, 0x25, 0x21, 0x25, 0x20, 0xE4, +0x18, 0xE4, 0x18, 0xE4, 0x18, 0xE4, 0x18, 0xE4, +0x18, 0xE4, 0x18, 0xE4, 0x21, 0x05, 0x21, 0x05, +0x21, 0x05, 0x29, 0x26, 0x31, 0x66, 0x42, 0x08, +0x6B, 0x2B, 0x8C, 0x2E, 0x84, 0x0D, 0x9C, 0xB0, +0xB5, 0x73, 0xAD, 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0x94, 0x90, 0x94, 0x70, +0x8C, 0x70, 0x8C, 0x4F, 0x83, 0xCE, 0x7B, 0xCE, +0x7B, 0xCE, 0x73, 0x8C, 0x73, 0x8C, 0x7B, 0xCD, +0x7B, 0xEE, 0x63, 0x2B, 0x63, 0x0B, 0x42, 0x07, +0x42, 0x07, 0x4A, 0x28, 0x42, 0x07, 0x42, 0x28, +0x52, 0xAA, 0x5A, 0xEB, 0x63, 0x0C, 0x8C, 0x71, +0x94, 0xB3, 0x94, 0x92, 0x73, 0xAF, 0x63, 0x0C, +0x84, 0x10, 0x52, 0x6A, 0x63, 0x0D, 0xB5, 0xB7, +0xD6, 0xBB, 0xCE, 0x59, 0xC6, 0x18, 0xBD, 0x95, +0x83, 0xED, 0x9C, 0xB0, 0xAD, 0x52, 0xA4, 0xD1, +0x8C, 0x4E, 0x94, 0x4E, 0x94, 0x6E, 0x8C, 0x2E, +0x8C, 0x0E, 0x83, 0xED, 0xAD, 0x31, 0xB5, 0x52, +0xB5, 0x32, 0x94, 0x2E, 0x8C, 0x0D, 0xA4, 0xF1, +0x8C, 0x2E, 0x83, 0xED, 0x83, 0xED, 0x94, 0x4E, +0x9C, 0x8F, 0x8C, 0x2E, 0x9C, 0x6F, 0x94, 0x4E, +0x8C, 0x2E, 0x7B, 0x8C, 0x83, 0xAD, 0x83, 0xCC, +0x7B, 0xAC, 0x7B, 0xAC, 0x83, 0xAC, 0x83, 0xED, +0x94, 0x6F, 0x8C, 0x0E, 0x83, 0xEE, 0x52, 0x69, +0x21, 0x25, 0x29, 0x46, 0x29, 0x46, 0x29, 0x25, +0x21, 0x05, 0x18, 0xE4, 0x18, 0xE4, 0x21, 0x05, +0x18, 0xE4, 0x18, 0xC4, 0x18, 0xE4, 0x18, 0xE4, +0x18, 0xE4, 0x18, 0xC4, 0x18, 0xC4, 0x18, 0xE4, +0x18, 0xC4, 0x18, 0xE4, 0x21, 0x05, 0x21, 0x05, +0x21, 0x05, 0x18, 0xE4, 0x4A, 0x49, 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4, 0x18, 0xC3, 0x18, 0xC4, 0x18, 0xC3, +0x10, 0xA4, 0x10, 0xA3, 0x18, 0xA3, 0x18, 0xC4, +0x18, 0xC4, 0x10, 0xA4, 0x10, 0xA3, 0x29, 0x45, +0x42, 0x08, 0x21, 0x05, 0x21, 0x05, 0x21, 0x04, +0x20, 0xE4, 0x18, 0xC4, 0x18, 0xC3, 0x20, 0xE4, +0x29, 0x45, 0x31, 0x87, 0x42, 0x08, 0x52, 0x8A, +0x7B, 0xAE, 0x94, 0x50, 0x9C, 0xB1, 0x83, 0xEE, +0x8B, 0xEE, 0x83, 0xEE, 0x7B, 0xAD, 0x7B, 0xAD, +0x73, 0x8D, 0x83, 0xEE, 0x94, 0x50, 0x94, 0x90, +0x94, 0x50, 0x7B, 0xCE, 0x73, 0x6D, 0x6B, 0x4D, +0x63, 0x0C, 0x5A, 0xCB, 0x5A, 0xAA, 0x62, 0xEB, +0x7B, 0x8D, 0x73, 0x4C, 0x7B, 0x6C, 0x94, 0x2F, +0x9C, 0xB0, 0xAD, 0x12, 0xB5, 0x33, 0xB5, 0x33, +0xB5, 0x33, 0xB5, 0x33, 0xAD, 0x32, 0xB5, 0x53, +0xB5, 0x53, 0xAD, 0x12, 0xAD, 0x32, 0xA4, 0xF1, +0xA4, 0xD1, 0xB5, 0x73, 0xBD, 0x73, 0xBD, 0x94, +0xBD, 0x94, 0xC5, 0xB4, 0xB5, 0x32, 0xBD, 0x94, +0xA4, 0xD1, 0x83, 0xEE, 0x8C, 0x0E, 0x83, 0xED, +0x83, 0xED, 0x8C, 0x0E, 0x8C, 0x0E, 0x83, 0xEE, +0x8B, 0xEE, 0x94, 0x6F, 0xA4, 0xB1, 0x94, 0x6F, +0x8C, 0x0E, 0x7B, 0xCC, 0x83, 0xAC, 0x83, 0xCD, +0x94, 0x0F, 0x9C, 0x6F, 0x94, 0x4F, 0x94, 0x4F, +0x83, 0xED, 0x94, 0x4F, 0x7B, 0x8C, 0x7B, 0x8C, +0xAD, 0x32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A5, 0x35, 0xBD, 0xD7, +0x84, 0x11, 0x7B, 0xD0, 0xA5, 0x35, 0xBD, 0xF8, +0x94, 0x93, 0x73, 0x6D, 0xBD, 0x95, 0x9C, 0x71, +0xB5, 0x35, 0x9C, 0xB2, 0x9C, 0xF3, 0x5A, 0xCB, +0x94, 0x70, 0x8C, 0x4E, 0x9C, 0xB0, 0xBD, 0x94, +0xB5, 0x32, 0x8B, 0xEE, 0xA4, 0xF1, 0xAC, 0xF0, +0xB5, 0x52, 0xBD, 0x72, 0xBD, 0x93, 0xB5, 0x31, +0xBD, 0x72, 0xB5, 0x51, 0xB5, 0x52, 0xBD, 0x72, +0xBD, 0x93, 0xB5, 0x32, 0xB5, 0x52, 0xB5, 0x73, +0xAD, 0x11, 0x9C, 0xB0, 0xA5, 0x12, 0xAD, 0x32, +0xA4, 0xB0, 0x94, 0x4F, 0x83, 0xCD, 0x6B, 0x2B, +0x21, 0x04, 0x18, 0xC4, 0x10, 0xA3, 0x18, 0xC4, +0x18, 0xE4, 0x10, 0xC3, 0x10, 0xA3, 0x10, 0xC3, +0x10, 0xC4, 0x10, 0xC4, 0x10, 0xC4, 0x10, 0xC4, +0x10, 0xA3, 0x10, 0xA3, 0x10, 0xA3, 0x10, 0xC4, +0x10, 0xC4, 0x30, 0xE5, 0x71, 0x87, 0xA1, 0xE9, +0xA2, 0x8A, 0x31, 0x04, 0x20, 0xE5, 0x21, 0x05, +0x20, 0xE4, 0x18, 0xC3, 0x10, 0xA3, 0x10, 0xA3, +0x18, 0xA3, 0x18, 0xC4, 0x18, 0xC4, 0x18, 0xC3, +0x18, 0xC4, 0x21, 0x04, 0x29, 0x45, 0x29, 0x66, +0x29, 0x66, 0x31, 0x67, 0x31, 0x87, 0x39, 0xA7, +0x41, 0xE8, 0x4A, 0x29, 0x52, 0x6A, 0x52, 0x8B, +0x4A, 0x4A, 0x4A, 0x09, 0x41, 0xE8, 0x39, 0xC8, +0x39, 0x87, 0x39, 0x87, 0x31, 0x66, 0x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, 0x10, 0xA3, +0x10, 0xA3, 0x10, 0xC4, 0x10, 0xC4, 0x10, 0xC4, +0x10, 0xC4, 0x10, 0xC4, 0x18, 0xE4, 0x10, 0xC4, +0x10, 0xC4, 0x18, 0xC4, 0x18, 0xE4, 0x18, 0xE4, +0x18, 0xA3, 0x49, 0x26, 0x79, 0x47, 0xAA, 0x4A, +0x79, 0xA8, 0x28, 0xE4, 0x18, 0xC4, 0x10, 0xA3, +0x10, 0xA3, 0x10, 0xA3, 0x10, 0xA3, 0x18, 0xC3, +0x18, 0xC4, 0x18, 0xC4, 0x18, 0xC4, 0x18, 0xC4, +0x18, 0xE4, 0x20, 0xE5, 0x21, 0x05, 0x21, 0x25, +0x29, 0x46, 0x29, 0x66, 0x31, 0x87, 0x39, 0xA7, +0x39, 0xC8, 0x39, 0xC8, 0x39, 0xE8, 0x4A, 0x09, +0x42, 0x09, 0x41, 0xC8, 0x39, 0xC8, 0x31, 0x87, +0x31, 0x87, 0x31, 0x87, 0x29, 0x66, 0x29, 0x46, +0x29, 0x46, 0x29, 0x46, 0x29, 0x66, 0x31, 0x87, +0x39, 0xA7, 0x39, 0xC8, 0x42, 0x29, 0x4A, 0x4A, +0x4A, 0x2A, 0x4A, 0x4A, 0x52, 0x8B, 0x63, 0x2D, +0x83, 0xEF, 0x9C, 0xD2, 0xB5, 0x74, 0xB5, 0x94, +0xB5, 0xB5, 0xAD, 0x53, 0x94, 0x70, 0x94, 0x6F, +0xBD, 0xB4, 0xCD, 0xF4, 0xBD, 0x92, 0xC5, 0xF4, +0xB5, 0x52, 0xB5, 0x73, 0xAD, 0x53, 0xBD, 0xB4, +0xB5, 0x73, 0xB5, 0x73, 0xAD, 0x51, 0xBD, 0x92, +0xBD, 0x72, 0xB5, 0x51, 0xB5, 0x93, 0xAD, 0x32, +0xC6, 0x16, 0xBD, 0xD5, 0xBD, 0xF5, 0xB5, 0x73, +0x9C, 0xD0, 0xCD, 0xF4, 0xCE, 0x35, 0xCE, 0x15, +0xA4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 0x10, 0x94, 0xB3, 0xD6, 0x7A, 0xA5, 0x35, +0x8C, 0x51, 0x8C, 0x52, 0x9C, 0xF4, 0x8C, 0x52, +0x7B, 0xAF, 0x84, 0x10, 0xC5, 0xD7, 0x62, 0xCB, +0x62, 0xEC, 0x84, 0x10, 0x9C, 0xD3, 0xAD, 0x34, +0xA4, 0xD2, 0xAC, 0xD0, 0xA4, 0xB0, 0xB5, 0x53, +0xB5, 0x73, 0xC5, 0xB4, 0xC5, 0xD5, 0xC5, 0xD5, +0xC5, 0xB4, 0xBD, 0x94, 0xB5, 0x52, 0xB5, 0x53, +0xC5, 0xD5, 0xC5, 0xB4, 0xC5, 0xB4, 0xBD, 0x93, +0xBD, 0x94, 0xC5, 0xB4, 0xBD, 0x94, 0xBD, 0x94, +0xB5, 0x53, 0xB5, 0x32, 0xAD, 0x12, 0xAD, 0x32, +0xAD, 0x12, 0xAD, 0x53, 0x9C, 0x90, 0x41, 0xE7, +0x20, 0xE4, 0x18, 0xC4, 0x10, 0xA3, 0x10, 0xA3, +0x10, 0xC3, 0x10, 0xC3, 0x10, 0xC4, 0x10, 0xA3, +0x10, 0xC4, 0x18, 0xC4, 0x10, 0xC4, 0x18, 0xC4, +0x18, 0xC4, 0x18, 0xE4, 0x21, 0x05, 0x18, 0xE4, +0x20, 0xA3, 0x61, 0x87, 0x71, 0x26, 0x89, 0xE9, +0x30, 0x83, 0x20, 0xC4, 0x18, 0xC3, 0x10, 0xA3, +0x10, 0xA3, 0x18, 0xA3, 0x10, 0xA3, 0x10, 0xA3, +0x10, 0xA3, 0x10, 0xA3, 0x18, 0xC4, 0x18, 0xE4, +0x18, 0xE4, 0x21, 0x05, 0x21, 0x05, 0x29, 0x25, +0x29, 0x46, 0x29, 0x66, 0x31, 0x87, 0x31, 0xA7, +0x39, 0xC8, 0x39, 0xC8, 0x31, 0xA7, 0x39, 0xA8, +0x39, 0xC8, 0x39, 0xC8, 0x31, 0x87, 0x31, 0x87, +0x31, 0x66, 0x29, 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 0x18, 0xC4, 0x18, 0xC3, 0x10, 0xA3, +0x10, 0xA3, 0x10, 0xA3, 0x10, 0xA3, 0x10, 0xC3, +0x10, 0xC4, 0x10, 0xC3, 0x10, 0xA3, 0x10, 0xA3, +0x10, 0xA3, 0x10, 0xA3, 0x10, 0xC4, 0x10, 0xA3, +0x38, 0xE4, 0x71, 0x46, 0x89, 0xA8, 0x61, 0x46, +0x20, 0xA3, 0x18, 0xC4, 0x10, 0xA3, 0x10, 0xA3, +0x18, 0xA3, 0x10, 0xA3, 0x10, 0xA3, 0x10, 0xA3, +0x18, 0xA3, 0x18, 0xC4, 0x18, 0xC4, 0x18, 0xC4, +0x18, 0xE4, 0x21, 0x05, 0x21, 0x05, 0x21, 0x25, +0x21, 0x05, 0x21, 0x25, 0x21, 0x25, 0x29, 0x46, +0x31, 0xA7, 0x39, 0xC8, 0x39, 0xC8, 0x31, 0x87, +0x31, 0x87, 0x31, 0x87, 0x31, 0x66, 0x29, 0x46, +0x31, 0x66, 0x31, 0x87, 0x31, 0x66, 0x29, 0x66, +0x29, 0x46, 0x29, 0x46, 0x29, 0x46, 0x29, 0x46, +0x21, 0x25, 0x21, 0x05, 0x29, 0x46, 0x31, 0x87, +0x39, 0xC8, 0x39, 0xC8, 0x41, 0xE9, 0x4A, 0x29, +0x52, 0x8B, 0x52, 0x8B, 0x52, 0x8B, 0x5A, 0xCC, +0x73, 0x8E, 0x94, 0x91, 0x94, 0x91, 0x94, 0x90, +0xBD, 0x73, 0xC5, 0xF4, 0xBD, 0x92, 0xC5, 0xD4, +0xBD, 0xD4, 0xBD, 0xB4, 0xBD, 0xB4, 0xBD, 0xD4, +0xC6, 0x16, 0xBD, 0xB4, 0xB5, 0x93, 0xC5, 0xB3, +0xC5, 0xD3, 0xC5, 0xF4, 0xB5, 0x93, 0xB5, 0x73, +0xC5, 0xF5, 0xC5, 0xF5, 0xB5, 0x94, 0xBD, 0xB4, +0xB5, 0x52, 0xC5, 0xD4, 0xCE, 0x35, 0xB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44, 0x39, 0xE7, +0x7B, 0xCF, 0xB5, 0x96, 0xAD, 0x55, 0x9C, 0xD4, +0x73, 0x8F, 0x52, 0xAB, 0x63, 0x2D, 0x73, 0x6E, +0x73, 0x6E, 0x73, 0x6E, 0xB5, 0x96, 0xBD, 0x96, +0x7B, 0xAE, 0x62, 0xEB, 0x39, 0xA6, 0x62, 0xEB, +0x9C, 0x91, 0xB5, 0x52, 0xA4, 0xB0, 0xC5, 0xB3, +0xC5, 0xD3, 0xC5, 0xB3, 0xB5, 0x52, 0x9C, 0x90, +0xB5, 0x52, 0xC5, 0xB3, 0xC5, 0xD3, 0xCD, 0xD3, +0xDE, 0x75, 0xC5, 0xB3, 0xBD, 0x72, 0xBD, 0x92, +0xD6, 0x14, 0xC5, 0x93, 0xA4, 0xB0, 0xA4, 0xF0, +0xAC, 0xF0, 0x9C, 0x8F, 0x9C, 0x6F, 0xBD, 0x73, +0xB5, 0x53, 0xAD, 0x12, 0x7B, 0xAD, 0x29, 0x45, +0x21, 0x04, 0x18, 0xE4, 0x18, 0xC4, 0x10, 0xA3, +0x10, 0xA3, 0x08, 0x83, 0x10, 0xA3, 0x18, 0xC4, +0x10, 0xC3, 0x10, 0xC3, 0x10, 0xC3, 0x10, 0xA3, +0x10, 0xA3, 0x10, 0xA3, 0x10, 0xA3, 0x20, 0x83, +0x61, 0x26, 0x81, 0x67, 0x91, 0xE9, 0x38, 0xA3, +0x18, 0xA3, 0x18, 0xA3, 0x18, 0xA3, 0x18, 0xA3, +0x18, 0xA3, 0x10, 0xA3, 0x18, 0xA3, 0x18, 0xA3, +0x18, 0xA3, 0x18, 0xC3, 0x18, 0xC3, 0x18, 0xE4, +0x20, 0xE4, 0x21, 0x05, 0x21, 0x05, 0x21, 0x25, +0x29, 0x25, 0x29, 0x46, 0x29, 0x46, 0x31, 0x66, +0x31, 0x87, 0x39, 0xA7, 0x31, 0xA7, 0x31, 0x87, +0x31, 0x66, 0x29, 0x25, 0x21, 0x25, 0x21, 0x05, +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0xE4, 0x21, 0x05, 0x18, 0xE4, 0x10, 0xA3, +0x10, 0xC3, 0x18, 0xE4, 0x19, 0x04, 0x18, 0xE4, +0x10, 0xA3, 0x10, 0xC3, 0x10, 0xC4, 0x10, 0xA3, +0x10, 0xA3, 0x10, 0x83, 0x10, 0xA3, 0x40, 0xE4, +0x79, 0x46, 0x91, 0x87, 0x69, 0x46, 0x20, 0xA3, +0x18, 0xC4, 0x18, 0xA3, 0x18, 0xA3, 0x18, 0xC3, +0x18, 0xA3, 0x18, 0xA3, 0x18, 0xC4, 0x18, 0xC4, +0x18, 0xC4, 0x18, 0xA3, 0x18, 0xC3, 0x18, 0xC4, +0x21, 0x05, 0x21, 0x05, 0x21, 0x05, 0x21, 0x05, +0x21, 0x25, 0x21, 0x05, 0x21, 0x05, 0x21, 0x25, +0x29, 0x46, 0x29, 0x25, 0x21, 0x25, 0x29, 0x25, +0x29, 0x66, 0x29, 0x46, 0x21, 0x25, 0x21, 0x05, +0x20, 0xE4, 0x21, 0x05, 0x29, 0x46, 0x29, 0x46, +0x21, 0x25, 0x21, 0x25, 0x21, 0x05, 0x18, 0xE4, +0x21, 0x25, 0x29, 0x25, 0x29, 0x46, 0x29, 0x46, +0x29, 0x46, 0x29, 0x46, 0x31, 0x67, 0x31, 0xA7, +0x39, 0xA7, 0x39, 0xC8, 0x41, 0xE9, 0x42, 0x09, +0x4A, 0x2A, 0x4A, 0x4A, 0x4A, 0x4A, 0x52, 0x8A, +0x6B, 0x0C, 0x8C, 0x2F, 0x9C, 0xB0, 0xA4, 0xF1, +0xA4, 0xF1, 0xA4, 0xF1, 0x9C, 0xD0, 0xAD, 0x12, +0xBD, 0xD4, 0xBD, 0xD4, 0xCE, 0x35, 0xD6, 0x96, +0xD6, 0x96, 0xD6, 0x76, 0xBD, 0xB4, 0xC5, 0xF5, +0xC6, 0x16, 0xC6, 0x16, 0xBD, 0xD4, 0xBD, 0xB4, +0xB5, 0x52, 0xCE, 0x35, 0xDE, 0x96, 0xBD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0x65, +0x5A, 0xEC, 0xCE, 0x59, 0xAD, 0x76, 0x8C, 0x52, +0x52, 0x8A, 0x42, 0x08, 0x52, 0xAA, 0x5A, 0xEB, +0x63, 0x2C, 0x5A, 0xEC, 0x52, 0x8A, 0x4A, 0x49, +0x52, 0x69, 0x6B, 0x2D, 0xA4, 0xF3, 0x7B, 0x8E, +0x73, 0x4D, 0x9C, 0x71, 0xCE, 0x16, 0xC5, 0xD4, +0xBD, 0x92, 0xC5, 0xB2, 0xC5, 0xD3, 0xA4, 0xD0, +0xB5, 0x31, 0xC5, 0x92, 0xB5, 0x0F, 0xC5, 0x92, +0xD6, 0x34, 0xC5, 0xB2, 0xC5, 0x92, 0xBD, 0x51, +0xC5, 0x92, 0xB5, 0x10, 0xAC, 0xD0, 0xBD, 0x72, +0xCD, 0xB3, 0xBD, 0x71, 0x9C, 0xAF, 0x9C, 0xB0, +0xA4, 0xF1, 0xA4, 0xD1, 0x6B, 0x4C, 0x29, 0x25, +0x20, 0xE4, 0x18, 0xE4, 0x18, 0xE4, 0x18, 0xE4, +0x19, 0x05, 0x19, 0x04, 0x10, 0xC4, 0x10, 0xA3, +0x10, 0xA3, 0x10, 0xC3, 0x10, 0xC4, 0x10, 0xA3, +0x10, 0xA3, 0x18, 0xC3, 0x18, 0xA3, 0x59, 0x46, +0x89, 0x67, 0x89, 0x67, 0x38, 0xC3, 0x18, 0xA3, +0x18, 0xC4, 0x18, 0xC4, 0x18, 0xC4, 0x18, 0xC4, +0x18, 0xA3, 0x18, 0xA3, 0x18, 0xA3, 0x18, 0xC4, +0x18, 0xA3, 0x18, 0xC3, 0x18, 0xC4, 0x18, 0xE4, +0x20, 0xE4, 0x21, 0x05, 0x20, 0xE4, 0x21, 0x05, +0x21, 0x05, 0x21, 0x05, 0x21, 0x05, 0x21, 0x05, +0x21, 0x25, 0x21, 0x25, 0x21, 0x05, 0x21, 0x25, +0x29, 0x25, 0x29, 0x46, 0x21, 0x25, 0x21, 0x05, +0x18, 0xE4, 0x21, 0x05, 0x21, 0x25, 0x29, 0x26, +0x29, 0x25, 0x21, 0x05, 0x21, 0x05, 0x18, 0xE4, +0x21, 0x05, 0x21, 0x05, 0x21, 0x25, 0x21, 0x25, +0x21, 0x05, 0x21, 0x25, 0x29, 0x46, 0x31, 0xA7, +0x39, 0xC8, 0x31, 0xA7, 0x39, 0xA8, 0x39, 0xC8, +0x41, 0xE9, 0x42, 0x09, 0x42, 0x2A, 0x4A, 0x2A, +0x42, 0x29, 0x4A, 0x29, 0x63, 0x0C, 0x94, 0x50, +0xAD, 0x12, 0xB5, 0x53, 0xB5, 0x53, 0xAC, 0xF1, +0xA4, 0xB0, 0x9C, 0x6F, 0x94, 0x2E, 0x8B, 0xED, +0x83, 0xED, 0x83, 0xCD, 0x83, 0xCD, 0x84, 0x0E, +0x9C, 0x70, 0x94, 0x6F, 0x83, 0xEE, 0x9C, 0xB0, +0xA4, 0xD0, 0xB5, 0x32, 0xAD, 0x11, 0x94, 0x6E, +0xA4, 0xD0, 0x9C, 0x8F, 0x9C, 0x90, 0xA4, 0xF1, +0xA4, 0xD1, 0xAD, 0x31, 0xA4, 0xD0, 0xA4, 0xD0, +0xA4, 0xD0, 0xAD, 0x11, 0xB5, 0x52, 0xB5, 0x52, +0xB5, 0x52, 0xB5, 0x52, 0xAD, 0x12, 0x9C, 0x8F, +0xBD, 0x93, 0xC5, 0xD3, 0xA4, 0xD0, 0xB5, 0x73, +0x9C, 0x8F, 0x73, 0x8C, 0x73, 0x8D, 0x62, 0xEB, +0x5A, 0xEB, 0x84, 0x10, 0xBD, 0xB6, 0x9C, 0xF3, +0x73, 0x6E, 0x4A, 0x49, 0x63, 0x2D, 0x4A, 0x49, +0x39, 0xC7, 0x39, 0xA7, 0xAD, 0x55, 0xAD, 0x34, +0x83, 0xCF, 0xAD, 0x33, 0xCE, 0x15, 0xCE, 0x35, +0xC6, 0x14, 0xBD, 0xD3, 0xC6, 0x14, 0xC6, 0x14, +0x74, 0xA9, 0x6C, 0x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A7, +0x18, 0xE4, 0x18, 0xE4, 0x18, 0xE4, 0x18, 0xC4, +0x18, 0xE4, 0x10, 0xC4, 0x18, 0xE4, 0x18, 0xC4, +0x10, 0xA3, 0x10, 0xA3, 0x10, 0xC4, 0x10, 0xC3, +0x10, 0xA3, 0x10, 0xC4, 0x28, 0xC4, 0x71, 0x46, +0x89, 0x67, 0x69, 0x25, 0x20, 0x62, 0x18, 0xC4, +0x18, 0xC4, 0x18, 0xC4, 0x18, 0xC4, 0x10, 0xA3, +0x10, 0xA3, 0x10, 0xA3, 0x18, 0xA3, 0x18, 0xC4, +0x18, 0xC4, 0x18, 0xC4, 0x18, 0xE4, 0x20, 0xE4, +0x20, 0xE4, 0x21, 0x05, 0x21, 0x05, 0x21, 0x05, +0x21, 0x05, 0x21, 0x05, 0x21, 0x05, 0x21, 0x05, +0x21, 0x05, 0x21, 0x05, 0x21, 0x05, 0x18, 0xE4, +0x21, 0x05, 0x29, 0x46, 0x29, 0x46, 0x21, 0x25, +0x18, 0xC4, 0x10, 0xA3, 0x18, 0xC4, 0x18, 0xE4, +0x20, 0xE4, 0x20, 0xE4, 0x21, 0x05, 0x18, 0xE4, +0x18, 0xE4, 0x21, 0x05, 0x21, 0x05, 0x21, 0x05, +0x20, 0xE4, 0x18, 0xE4, 0x21, 0x25, 0x31, 0x67, +0x31, 0xA7, 0x31, 0x87, 0x31, 0x87, 0x31, 0xA8, +0x39, 0xC8, 0x39, 0xE9, 0x42, 0x09, 0x42, 0x09, +0x4A, 0x2A, 0x42, 0x2A, 0x4A, 0x2A, 0x52, 0x8B, +0x7B, 0x8E, 0xA4, 0xD2, 0xAC, 0xF2, 0xB5, 0x53, +0xAD, 0x12, 0xA4, 0xD1, 0xAC, 0xF1, 0xAC, 0xF1, +0xA4, 0xB0, 0xAC, 0xF2, 0xAC, 0xF1, 0xAD, 0x12, +0xAC, 0xF1, 0xAD, 0x12, 0xB5, 0x12, 0xB5, 0x12, +0xB5, 0x32, 0xB5, 0x32, 0x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0x4E, 0x63, 0x0A, 0x8C, 0x2F, +0xB5, 0x75, 0xBD, 0xF7, 0xB5, 0x76, 0x8C, 0x72, +0x39, 0xC7, 0x39, 0xE7, 0x31, 0xA6, 0x39, 0xC6, +0x4A, 0x69, 0x52, 0x8A, 0x63, 0x0C, 0x63, 0x0C, +0x63, 0x0C, 0x52, 0xAB, 0x6B, 0x4D, 0x83, 0xF0, +0x42, 0x08, 0x73, 0x8E, 0x94, 0x51, 0x94, 0x51, +0xC5, 0xB6, 0xB5, 0x32, 0x9C, 0x8F, 0xA4, 0xB0, +0xAD, 0x11, 0xC5, 0x92, 0xC5, 0x71, 0xC5, 0xB2, +0xCD, 0xD3, 0xCD, 0xB2, 0xCD, 0xF3, 0xD6, 0x35, +0xD6, 0x14, 0xD5, 0xF3, 0xCD, 0xB3, 0xBD, 0x51, +0xC5, 0x92, 0xBD, 0x52, 0xAD, 0x11, 0xB5, 0x52, +0xBD, 0x92, 0xB5, 0x31, 0x8C, 0x2F, 0x52, 0x8A, +0x21, 0x05, 0x18, 0xE4, 0x18, 0xC4, 0x19, 0x04, +0x18, 0xE4, 0x19, 0x04, 0x19, 0x05, 0x18, 0xC4, +0x10, 0x83, 0x10, 0xA3, 0x18, 0xE4, 0x10, 0xC4, +0x18, 0xC4, 0x18, 0xC4, 0x38, 0xE4, 0x69, 0x25, +0x71, 0x25, 0x40, 0xE4, 0x18, 0xA3, 0x18, 0xC4, +0x18, 0xC4, 0x18, 0xC4, 0x10, 0xA3, 0x10, 0xA3, +0x10, 0xA3, 0x10, 0xA3, 0x10, 0xA3, 0x10, 0xA3, +0x18, 0xA3, 0x18, 0xC3, 0x18, 0xC4, 0x21, 0x04, +0x21, 0x05, 0x21, 0x05, 0x21, 0x05, 0x21, 0x05, +0x21, 0x05, 0x21, 0x05, 0x21, 0x05, 0x21, 0x05, +0x21, 0x05, 0x21, 0x25, 0x21, 0x05, 0x18, 0xE4, +0x18, 0xC4, 0x20, 0xE4, 0x21, 0x25, 0x21, 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x83, 0xEE, +0x39, 0xC7, 0x18, 0xE4, 0x18, 0xE4, 0x18, 0xE4, +0x18, 0xE4, 0x18, 0xE4, 0x18, 0xE4, 0x10, 0xC3, +0x10, 0xA3, 0x18, 0xE4, 0x18, 0xC4, 0x10, 0xA3, +0x10, 0xA3, 0x18, 0xC4, 0x41, 0x05, 0x61, 0x25, +0x59, 0x04, 0x30, 0xC3, 0x20, 0xC4, 0x18, 0xE4, +0x18, 0xE4, 0x18, 0xC4, 0x10, 0xA3, 0x10, 0x83, +0x10, 0xA3, 0x10, 0xA3, 0x10, 0xA3, 0x10, 0xA3, +0x10, 0xA3, 0x18, 0xC3, 0x18, 0xC4, 0x21, 0x05, +0x21, 0x05, 0x21, 0x05, 0x21, 0x05, 0x21, 0x05, +0x21, 0x05, 0x21, 0x05, 0x21, 0x05, 0x21, 0x05, +0x21, 0x05, 0x21, 0x05, 0x21, 0x05, 0x18, 0xE4, +0x18, 0xA3, 0x18, 0xE4, 0x21, 0x05, 0x21, 0x05, +0x21, 0x05, 0x21, 0x05, 0x21, 0x05, 0x18, 0xE4, +0x18, 0xC4, 0x18, 0xC4, 0x18, 0xC4, 0x18, 0xE4, +0x18, 0xE4, 0x18, 0xE4, 0x21, 0x25, 0x21, 0x05, +0x20, 0xE4, 0x18, 0xE4, 0x18, 0xE4, 0x21, 0x25, +0x31, 0x87, 0x31, 0x87, 0x29, 0x46, 0x29, 0x46, +0x29, 0x67, 0x31, 0x67, 0x31, 0x87, 0x39, 0xA8, +0x39, 0xC8, 0x41, 0xE9, 0x42, 0x09, 0x4A, 0x2A, +0x42, 0x09, 0x42, 0x09, 0x4A, 0x6A, 0x63, 0x0C, +0x7B, 0xAE, 0x94, 0x4F, 0x94, 0x2F, 0x9C, 0x90, +0x94, 0x70, 0x83, 0xCE, 0x94, 0x4F, 0x8C, 0x0E, +0x83, 0xCD, 0x83, 0xEE, 0x73, 0x4B, 0x6B, 0x2B, +0x6B, 0x2B, 0x6A, 0xEA, 0x5A, 0x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0x6F, 0x8B, 0xED, +0xBD, 0xD6, 0xAD, 0x76, 0xA5, 0x14, 0x7B, 0xAF, +0x39, 0xC7, 0x29, 0x44, 0x31, 0xA6, 0x42, 0x08, +0x39, 0xC7, 0x39, 0xE7, 0x5A, 0xCB, 0x4A, 0x69, +0x52, 0x89, 0x52, 0xAA, 0x5A, 0xEC, 0x6B, 0x4E, +0x73, 0x6E, 0xCE, 0x39, 0xCE, 0x59, 0x6B, 0x2D, +0x62, 0xEC, 0x7B, 0x8D, 0xAD, 0x33, 0x9C, 0x6F, +0xAD, 0x12, 0x9C, 0x6F, 0x8C, 0x0D, 0x94, 0x2D, +0x94, 0x2D, 0x8B, 0xED, 0x8B, 0xED, 0x94, 0x2D, +0x94, 0x2D, 0x9C, 0x6E, 0xA4, 0xAF, 0xA4, 0xAF, +0xAC, 0xF0, 0xA4, 0xD0, 0xAC, 0xF0, 0xAC, 0xF0, +0xBD, 0x72, 0xBD, 0x72, 0xAD, 0x11, 0x9C, 0xB1, +0x52, 0x8A, 0x29, 0x25, 0x19, 0x04, 0x21, 0x04, +0x21, 0x05, 0x18, 0xE4, 0x18, 0xC3, 0x18, 0xC3, +0x18, 0xE5, 0x18, 0xE4, 0x10, 0x83, 0x10, 0xA3, +0x10, 0xA3, 0x18, 0xC4, 0x41, 0x05, 0x58, 0xE4, +0x48, 0xE4, 0x30, 0xE4, 0x20, 0xE4, 0x21, 0x04, +0x21, 0x05, 0x18, 0xC4, 0x10, 0xA3, 0x10, 0xA3, +0x10, 0xA3, 0x10, 0xA3, 0x10, 0xA3, 0x10, 0xA3, +0x10, 0xA3, 0x18, 0xA3, 0x18, 0xC4, 0x18, 0xE4, +0x20, 0xE4, 0x20, 0xE5, 0x20, 0xE4, 0x21, 0x05, +0x21, 0x05, 0x21, 0x05, 0x21, 0x05, 0x21, 0x05, +0x21, 0x05, 0x18, 0xE4, 0x18, 0xC4, 0x18, 0xC4, +0x18, 0xE4, 0x18, 0xE4, 0x18, 0xE4, 0x20, 0xE4, +0x18, 0xE4, 0x18, 0xE4, 0x21, 0x25, 0x21, 0x05, +0x18, 0xE4, 0x18, 0xE4, 0x18, 0xE4, 0x20, 0xE4, +0x18, 0xE4, 0x18, 0xE4, 0x21, 0x05, 0x21, 0x05, +0x21, 0x05, 0x21, 0x05, 0x18, 0xE4, 0x18, 0xE4, +0x21, 0x25, 0x29, 0x66, 0x29, 0x46, 0x29, 0x46, +0x29, 0x46, 0x29, 0x46, 0x29, 0x67, 0x31, 0x87, +0x31, 0x87, 0x31, 0xA8, 0x41, 0xE9, 0x42, 0x0A, +0x42, 0x2A, 0x42, 0x09, 0x42, 0x09, 0x4A, 0x4A, +0x5A, 0xAB, 0x7B, 0x8E, 0x94, 0x2F, 0x94, 0x4F, +0x94, 0x4F, 0xA4, 0x90, 0x9C, 0x70, 0x9C, 0x70, +0x94, 0x0E, 0xA4, 0xB0, 0x94, 0x2E, 0x7B, 0x8C, +0x94, 0x0E, 0x94, 0x0F, 0x73, 0x2B, 0x73, 0x4C, +0x8B, 0xEE, 0x8C, 0x2F, 0x83, 0xCD, 0x83, 0xAD, +0x83, 0xCD, 0x8C, 0x2E, 0xAC, 0xF1, 0xB5, 0x12, +0xB5, 0x31, 0xA4, 0x8F, 0xA4, 0x8F, 0xAC, 0xF0, +0xBD, 0x51, 0xC5, 0x72, 0x9C, 0x6E, 0x94, 0x2E, +0xA4, 0xD0, 0xAC, 0xF1, 0xB5, 0x32, 0xAC, 0xF0, +0x9C, 0x4E, 0x94, 0x0D, 0x94, 0x2E, 0x94, 0x4E, +0x94, 0x2F, 0x8C, 0x0F, 0x5A, 0xCB, 0x62, 0xEC, +0x39, 0xA7, 0x39, 0xE8, 0x7B, 0xCF, 0x7B, 0xCF, +0x84, 0x10, 0x5A, 0xCB, 0x6B, 0x2D, 0x83, 0xCF, +0x73, 0x4D, 0x8B, 0xCF, 0x9C, 0x71, 0x83, 0xCE, +0xA4, 0xD2, 0xAD, 0x13, 0xA4, 0xD2, 0xBD, 0x52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EB, 0x39, 0xC7, 0x29, 0x45, 0x21, 0x05, +0x18, 0xE4, 0x18, 0xC4, 0x10, 0xC3, 0x18, 0xC4, +0x18, 0xC4, 0x10, 0xA3, 0x10, 0xA3, 0x10, 0xA3, +0x10, 0xA3, 0x18, 0xC4, 0x41, 0x05, 0x50, 0xE4, +0x40, 0xC4, 0x28, 0xE4, 0x20, 0xE4, 0x21, 0x25, +0x18, 0xE4, 0x10, 0xA3, 0x10, 0xA3, 0x10, 0xA3, +0x10, 0xA3, 0x10, 0xA3, 0x10, 0xA3, 0x10, 0xA3, +0x10, 0xA3, 0x18, 0xC4, 0x18, 0xC4, 0x20, 0xE4, +0x21, 0x04, 0x20, 0xE4, 0x18, 0xE4, 0x18, 0xC4, +0x18, 0xE4, 0x18, 0xE4, 0x18, 0xE4, 0x18, 0xC4, +0x18, 0xE4, 0x18, 0xE4, 0x18, 0xC4, 0x18, 0xC4, +0x18, 0xC4, 0x18, 0xC4, 0x18, 0xE4, 0x18, 0xE4, +0x18, 0xC4, 0x18, 0xC4, 0x21, 0x05, 0x21, 0x25, +0x21, 0x05, 0x18, 0xC4, 0x18, 0xC4, 0x18, 0xE4, +0x20, 0xE4, 0x18, 0xE4, 0x18, 0xE4, 0x21, 0x05, +0x21, 0x05, 0x21, 0x05, 0x18, 0xE4, 0x21, 0x05, +0x21, 0x05, 0x21, 0x05, 0x21, 0x25, 0x29, 0x46, +0x29, 0x46, 0x21, 0x26, 0x29, 0x26, 0x29, 0x47, +0x29, 0x67, 0x31, 0x67, 0x39, 0xA8, 0x39, 0xE9, +0x42, 0x09, 0x42, 0x09, 0x42, 0x09, 0x3A, 0x09, +0x42, 0x4A, 0x52, 0x8B, 0x6B, 0x2C, 0x9C, 0x90, +0x9C, 0xB0, 0x9C, 0x4F, 0x9C, 0x4F, 0x6B, 0x0A, +0x62, 0xC9, 0x9C, 0x6F, 0xA4, 0x90, 0x8B, 0xED, +0x94, 0x2F, 0x9C, 0x70, 0x9C, 0x70, 0x7B,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, 0x38, 0xA5, 0x35, 0xA5, 0x14, 0x6B, 0x6D, +0x31, 0x86, 0x31, 0x86, 0x21, 0x24, 0x18, 0xE3, +0x31, 0x86, 0x4A, 0x48, 0x4A, 0x49, 0x31, 0x86, +0x39, 0xE7, 0x4A, 0x48, 0x4A, 0x69, 0x52, 0x8A, +0x5A, 0xEB, 0x62, 0xEC, 0x73, 0x4D, 0x94, 0x51, +0xCE, 0x18, 0x8C, 0x10, 0x6B, 0x0C, 0x8C, 0x0F, +0x9C, 0x50, 0xAC, 0xF2, 0xAD, 0x12, 0xAC, 0xF1, +0xA4, 0xF1, 0xAC, 0xF1, 0xAC, 0xF1, 0xAC, 0xF1, +0x9C, 0x90, 0xA4, 0xD0, 0xB5, 0x32, 0xAD, 0x11, +0xAC, 0xF1, 0xAC, 0xF1, 0xA4, 0xD1, 0xA4, 0xD1, +0xAD, 0x12, 0xB5, 0x53, 0xBD, 0xB4, 0xAD, 0x12, +0x94, 0x4F, 0x52, 0x89, 0x4A, 0x69, 0x39, 0xE7, +0x21, 0x25, 0x10, 0xA3, 0x10, 0xA3, 0x10, 0xA3, +0x10, 0xA4, 0x18, 0xC4, 0x10, 0xA3, 0x10, 0xA3, +0x10, 0xA3, 0x20, 0xE4, 0x41, 0x05, 0x49, 0x05, +0x38, 0xC4, 0x28, 0xE4, 0x21, 0x05, 0x21, 0x05, +0x18, 0xC4, 0x10, 0xA3, 0x10, 0xA3, 0x10, 0xA3, +0x10, 0xA3, 0x10, 0xA3, 0x10, 0xA3, 0x10, 0xA3, +0x10, 0xA3, 0x10, 0xA3, 0x18, 0xC4, 0x18, 0xC4, +0x18, 0xC3, 0x18, 0xA3, 0x18, 0xA3, 0x18, 0xC4, +0x18, 0xC4, 0x18, 0xE4, 0x18, 0xE4, 0x18, 0xC4, +0x18, 0xC4, 0x18, 0xC4, 0x10, 0xA3, 0x10, 0x83, +0x10, 0x83, 0x10, 0xA3, 0x18, 0xC4, 0x18, 0xE4, +0x18, 0xE4, 0x18, 0xC4, 0x18, 0xE4, 0x21, 0x05, +0x21, 0x05, 0x18, 0xE4, 0x18, 0xE4, 0x21, 0x05, +0x21, 0x05, 0x18, 0xE4, 0x18, 0xC4, 0x20, 0xE4, +0x21, 0x25, 0x21, 0x05, 0x18, 0xC4, 0x20, 0xE4, +0x29, 0x25, 0x29, 0x46, 0x21, 0x05, 0x21, 0x05, +0x29, 0x46, 0x21, 0x26, 0x21, 0x05, 0x29, 0x46, +0x29, 0x67, 0x31, 0x67, 0x31, 0x87, 0x31, 0xA8, +0x39, 0xE9, 0x42, 0x09, 0x42, 0x09, 0x42, 0x09, +0x39, 0xE8, 0x42, 0x09, 0x52, 0xAB, 0x5A, 0xEB, +0x94, 0x70, 0x9C, 0x90, 0x9C, 0x8F, 0x73, 0x6C, +0x7B, 0xAD, 0x94, 0x2F, 0xA4, 0xD1, 0xA4, 0xF1, +0xAD, 0x12, 0xA4, 0xD1, 0xAD, 0x12, 0x9C, 0x90, +0xA4, 0xD1, 0xA4, 0xF1, 0xAC, 0xF1, 0x9C, 0x90, +0x9C, 0xB0, 0x94, 0x6F, 0xA4, 0xB0, 0xAC, 0xF1, +0xB5, 0x31, 0xAC, 0xF0, 0xB5, 0x32, 0xBD, 0x52, +0xBD, 0x72, 0xBD, 0x72, 0xB5, 0x11, 0x94, 0x4E, +0x9C, 0x8F, 0xB5, 0x32, 0xBD, 0x73, 0xBD, 0x73, +0xBD, 0x73, 0xB5, 0x32, 0x83, 0xCC, 0x8C, 0x0D, +0x94, 0x2E, 0x94, 0x4F, 0x83, 0xCE, 0x42, 0x28, +0x63, 0x0C, 0x39, 0xC7, 0x73, 0x6E, 0x52, 0x8A, +0x5A, 0xCB, 0x4A, 0x6A, 0x73, 0x8E, 0x73, 0x8E, +0x73, 0x4D, 0x7B, 0x6D, 0x8B, 0xCF, 0xA4, 0x91, +0xCE, 0x17, 0xCE, 0x17, 0xA4, 0xD1, 0xC5, 0xB3, +0x5B, 0x8A, 0x8D, 0x0E, 0x6C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EE, 0x6B, 0x2C, +0x31, 0xA6, 0x21, 0x04, 0x19, 0x04, 0x18, 0xA3, +0x18, 0xC4, 0x18, 0xC4, 0x18, 0xE4, 0x29, 0x45, +0x18, 0xC3, 0x20, 0xE4, 0x39, 0x04, 0x49, 0x25, +0x30, 0xE4, 0x20, 0xE4, 0x20, 0xE4, 0x18, 0xE4, +0x18, 0xC3, 0x10, 0xA3, 0x10, 0xA3, 0x10, 0xA3, +0x18, 0xC4, 0x10, 0xA3, 0x10, 0xA3, 0x10, 0xA3, +0x10, 0xA3, 0x10, 0xA3, 0x10, 0xA3, 0x10, 0xA3, +0x10, 0xA3, 0x18, 0xA3, 0x18, 0xC4, 0x18, 0xC4, +0x18, 0xC4, 0x18, 0xC4, 0x18, 0xC4, 0x18, 0xC4, +0x18, 0xC4, 0x18, 0xE4, 0x18, 0xC4, 0x10, 0x83, +0x10, 0x83, 0x10, 0x83, 0x10, 0xA3, 0x18, 0xE4, +0x18, 0xC4, 0x18, 0xC4, 0x18, 0xE4, 0x18, 0xA3, +0x18, 0xC4, 0x18, 0xC4, 0x20, 0xE4, 0x21, 0x05, +0x21, 0x05, 0x21, 0x05, 0x18, 0xE4, 0x18, 0xE4, +0x21, 0x25, 0x21, 0x05, 0x18, 0xE4, 0x18, 0xE5, +0x21, 0x25, 0x29, 0x66, 0x29, 0x46, 0x21, 0x05, +0x21, 0x25, 0x21, 0x26, 0x21, 0x05, 0x21, 0x26, +0x29, 0x46, 0x21, 0x26, 0x21, 0x05, 0x29, 0x67, +0x31, 0x87, 0x39, 0xC8, 0x39, 0xE9, 0x41, 0xE9, +0x39, 0xC8, 0x31, 0xA8, 0x39, 0xE9, 0x4A, 0x6A, +0x5A, 0xCB, 0x83, 0xEF, 0x9C, 0x6F, 0x83, 0xCD, +0x9C, 0x4F, 0x94, 0x2F, 0x94, 0x2E, 0x8B, 0xED, +0xAC, 0xF1, 0xB5, 0x32, 0xAC, 0xF1, 0xA4, 0xD1, +0xA4, 0xF1, 0xA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0xF4, 0x9C, 0xD2, +0x8C, 0x71, 0x73, 0xAE, 0x29, 0x24, 0x31, 0x86, +0x21, 0x24, 0x18, 0xE3, 0x39, 0xC7, 0x4A, 0x48, +0x31, 0xA6, 0x31, 0x86, 0x41, 0xE7, 0x52, 0x8A, +0x52, 0xAA, 0x63, 0x0C, 0x73, 0x6D, 0x4A, 0x49, +0x29, 0x45, 0x41, 0xE8, 0x5A, 0xAA, 0x8C, 0x10, +0xA4, 0xB2, 0x94, 0x0F, 0xB5, 0x53, 0xEE, 0xF8, +0xDE, 0x96, 0xD6, 0x76, 0xDE, 0x96, 0xDE, 0x96, +0xB5, 0x32, 0xBD, 0x73, 0xD6, 0x56, 0xD6, 0x35, +0xD6, 0x55, 0xCE, 0x35, 0xC5, 0xF5, 0xBD, 0xD4, +0xA4, 0xF1, 0xA4, 0xD1, 0xBD, 0x73, 0x94, 0x4F, +0x94, 0x2E, 0x94, 0x2E, 0x9C, 0x4F, 0x94, 0x2E, +0x6B, 0x0B, 0x52, 0x69, 0x4A, 0x28, 0x41, 0xE7, +0x41, 0xE7, 0x52, 0x89, 0x7B, 0xAD, 0x83, 0xCE, +0x39, 0xA6, 0x31, 0x66, 0x39, 0x25, 0x41, 0x25, +0x28, 0xE4, 0x20, 0xE4, 0x18, 0xE4, 0x18, 0xC4, +0x10, 0xA3, 0x10, 0xA3, 0x10, 0xA3, 0x10, 0xA3, +0x18, 0xC4, 0x10, 0xA3, 0x10, 0x83, 0x10, 0xA3, +0x10, 0xA3, 0x10, 0xA3, 0x10, 0xA3, 0x10, 0xA3, +0x10, 0xA3, 0x18, 0xC4, 0x18, 0xC4, 0x10, 0xA3, +0x10, 0xA3, 0x10, 0xA3, 0x10, 0xA3, 0x10, 0xA3, +0x18, 0xC4, 0x18, 0xC4, 0x10, 0xA3, 0x10, 0xA3, +0x10, 0xA3, 0x10, 0xA3, 0x10, 0xA3, 0x10, 0xA3, +0x10, 0xA3, 0x18, 0xC4, 0x21, 0x05, 0x21, 0x25, +0x18, 0xC4, 0x10, 0xA3, 0x18, 0xC4, 0x18, 0xE4, +0x21, 0x05, 0x21, 0x05, 0x18, 0xE4, 0x18, 0xC4, +0x21, 0x05, 0x21, 0x25, 0x21, 0x05, 0x21, 0x05, +0x21, 0x05, 0x29, 0x46, 0x29, 0x46, 0x21, 0x05, +0x21, 0x05, 0x21, 0x25, 0x21, 0x25, 0x21, 0x26, +0x29, 0x46, 0x29, 0x46, 0x21, 0x05, 0x21, 0x26, +0x29, 0x67, 0x31, 0xA8, 0x31, 0xA8, 0x31, 0xA8, +0x39, 0xC8, 0x31, 0xA8, 0x39, 0xC9, 0x3A, 0x09, +0x42, 0x4A, 0x52, 0x6A, 0x6A, 0xEB, 0x73, 0x4C, +0x7B, 0x6C, 0x6B, 0x0A, 0x6A, 0xEA, 0x6B, 0x0A, +0x73, 0x4B, 0x83, 0xAD, 0x8B, 0xED, 0x7B, 0x8C, +0x8C, 0x0E, 0x9C, 0x6F, 0x6B, 0x0A, 0x6B, 0x0A, +0x9C, 0xB1, 0x8C, 0x0E, 0xA4, 0xD1, 0xB5, 0x32, +0xB5, 0x31, 0xB5, 0x31, 0xBD, 0x93, 0xBD, 0x72, +0xBD, 0x72, 0xC5, 0xB3, 0xAD, 0x11, 0xAC, 0xF1, +0x9C, 0x8F, 0xA4, 0xD0, 0xAD, 0x32, 0xAC, 0xF1, +0xBD, 0xB4, 0xAD, 0x32, 0x8C, 0x2E, 0x9C, 0x90, +0xAC, 0xD1, 0xA4, 0xD1, 0x9C, 0xB0, 0x7B, 0xAD, +0x4A, 0x49, 0x29, 0x45, 0x41, 0xE8, 0x62, 0xEC, +0x39, 0xC7, 0x29, 0x45, 0x21, 0x04, 0x31, 0x66, +0x39, 0xC7, 0x6B, 0x0C, 0x73, 0x0C, 0x83, 0xAE, +0x8B, 0xEF, 0x94, 0x30, 0x83, 0x8E, 0x52, 0x49, +0xAD, 0xF4, 0x95, 0x31, 0x4B, 0x45, 0x74, 0xC7, +0x74, 0xA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x9C, 0x90, 0x94, 0x2E, 0x94, 0x4F, +0xA4, 0xD1, 0xB5, 0x53, 0xC5, 0x93, 0xBD, 0x53, +0x94, 0x2F, 0x7B, 0x8D, 0x73, 0x2C, 0x49, 0xE7, +0x29, 0x05, 0x21, 0x04, 0x21, 0x04, 0x18, 0xC4, +0x18, 0xA3, 0x18, 0xC4, 0x18, 0xC3, 0x10, 0x83, +0x10, 0xA3, 0x10, 0x83, 0x10, 0x83, 0x10, 0xA3, +0x10, 0xA3, 0x10, 0xA3, 0x10, 0xA3, 0x10, 0xA3, +0x10, 0xA3, 0x10, 0xA3, 0x10, 0xA3, 0x10, 0xA3, +0x10, 0xA3, 0x10, 0xA3, 0x10, 0xA3, 0x18, 0xC4, +0x10, 0xA3, 0x10, 0xA3, 0x10, 0xA3, 0x10, 0x83, +0x10, 0xA3, 0x18, 0xE4, 0x18, 0xC4, 0x18, 0xC4, +0x10, 0xA3, 0x10, 0xA3, 0x18, 0xC4, 0x21, 0x05, +0x21, 0x05, 0x18, 0xC4, 0x10, 0xA3, 0x18, 0xA3, +0x18, 0xE4, 0x21, 0x05, 0x21, 0x05, 0x18, 0xC4, +0x18, 0xC4, 0x18, 0xE4, 0x21, 0x25, 0x21, 0x25, +0x18, 0xE5, 0x21, 0x26, 0x29, 0x46, 0x21, 0x05, +0x18, 0xE4, 0x21, 0x05, 0x21, 0x25, 0x29, 0x46, +0x21, 0x25, 0x21, 0x25, 0x21, 0x05, 0x21, 0x05, +0x21, 0x26, 0x29, 0x67, 0x31, 0x87, 0x31, 0xA8, +0x39, 0xC8, 0x39, 0xC8, 0x31, 0xA8, 0x31, 0xA8, +0x39, 0xE9, 0x42, 0x2A, 0x4A, 0x4A, 0x63, 0x0C, +0x83, 0xCE, 0x83, 0xCE, 0x83, 0xAD, 0x83, 0xAD, +0x7B, 0x8D, 0x7B, 0x8C, 0x7B, 0x8C, 0x73, 0x2B, +0x6B, 0x2B, 0x6B, 0x0A, 0x6B, 0x2B, 0x73, 0x2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x18, 0xE4, 0x18, 0xC4, 0x18, 0xC4, 0x18, 0xE4, +0x18, 0xE4, 0x20, 0xE4, 0x21, 0x05, 0x18, 0xE4, +0x10, 0xA3, 0x18, 0xE4, 0x21, 0x05, 0x21, 0x26, +0x21, 0x05, 0x21, 0x05, 0x21, 0x26, 0x29, 0x46, +0x18, 0xE5, 0x18, 0xC4, 0x18, 0xE5, 0x21, 0x05, +0x21, 0x05, 0x21, 0x05, 0x18, 0xE5, 0x21, 0x05, +0x18, 0xE5, 0x21, 0x05, 0x29, 0x46, 0x31, 0x87, +0x31, 0x87, 0x31, 0x87, 0x31, 0xA8, 0x31, 0xA7, +0x31, 0xA8, 0x42, 0x09, 0x42, 0x2A, 0x4A, 0x49, +0x6B, 0x2C, 0xA4, 0xD2, 0xA4, 0xD1, 0xAD, 0x12, +0xAC, 0xF1, 0xAC, 0xF2, 0xA4, 0xD1, 0xA4, 0xB0, +0xA4, 0xB0, 0x9C, 0x70, 0x94, 0x4F, 0x94, 0x4F, +0x9C, 0x70, 0x9C, 0x90, 0xA4, 0xB0, 0xA4, 0xD0, +0xA4, 0xD1, 0xAC, 0xF1, 0xAC, 0xF1, 0xAC, 0xF1, +0xAC, 0xF1, 0xAC, 0xF1, 0xAC, 0xD0, 0xA4, 0xB0, +0x9C, 0x90, 0x94, 0x6F, 0x9C, 0x90, 0x9C, 0x6F, +0x9C, 0x8F, 0x8C, 0x0E, 0x8B, 0xED, 0x83, 0xCD, +0x8C, 0x0E, 0x8B, 0xEE, 0x83, 0xAC, 0xA4, 0xD1, +0x73, 0xAD, 0x31, 0xA6, 0x5A, 0xCB, 0x5A, 0xCB, +0x42, 0x08, 0x5A, 0xCB, 0x6B, 0x0C, 0x52, 0x49, +0x39, 0xA6, 0x41, 0xC7, 0x4A, 0x07, 0x62, 0xAA, +0x4A, 0x08, 0x7B, 0x6C, 0x94, 0x30, 0x5A, 0xAA, +0xA5, 0xF3, 0x7C, 0x8C, 0x6C, 0x28, 0x6C, 0x48, +0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93, 0xC5, 0xB3, 0xCD, 0xD4, 0xD5, 0xF5, +0xD5, 0xF5, 0xD5, 0xF4, 0xD5, 0xF4, 0xC5, 0x93, +0xC5, 0x73, 0xC5, 0x73, 0xAC, 0xF1, 0x73, 0x4C, +0x29, 0x45, 0x21, 0x25, 0x18, 0xE4, 0x10, 0xA3, +0x10, 0xA3, 0x18, 0xC4, 0x18, 0xC4, 0x10, 0xA3, +0x10, 0xA3, 0x10, 0xA3, 0x10, 0xA3, 0x10, 0xA3, +0x10, 0x83, 0x10, 0xA3, 0x10, 0xA3, 0x10, 0xA3, +0x10, 0xA3, 0x10, 0xA3, 0x10, 0xA3, 0x10, 0xA3, +0x10, 0xA3, 0x10, 0xA3, 0x10, 0xA3, 0x10, 0xA3, +0x10, 0xA3, 0x10, 0xA3, 0x10, 0xA3, 0x10, 0xA3, +0x10, 0xA3, 0x18, 0xE4, 0x18, 0xE4, 0x18, 0xE4, +0x18, 0xC4, 0x18, 0xC4, 0x18, 0xC4, 0x10, 0xA3, +0x18, 0xC4, 0x18, 0xC4, 0x18, 0xC4, 0x18, 0xE4, +0x18, 0xE4, 0x18, 0xE4, 0x18, 0xE4, 0x18, 0xE4, +0x10, 0xA4, 0x18, 0xE5, 0x29, 0x46, 0x21, 0x26, +0x21, 0x25, 0x21, 0x05, 0x21, 0x05, 0x21, 0x05, +0x18, 0xE5, 0x18, 0xE4, 0x18, 0xE5, 0x21, 0x05, +0x21, 0x05, 0x21, 0x05, 0x18, 0xE5, 0x18, 0xE4, +0x18, 0xE5, 0x18, 0xE5, 0x21, 0x26, 0x29, 0x67, +0x31, 0x87, 0x31, 0xA8, 0x29, 0x87, 0x29, 0x87, +0x29, 0x67, 0x31, 0xA8, 0x42, 0x2A, 0x4A, 0x6B, +0x4A, 0x8B, 0x6B, 0x4C, 0x8C, 0x2F, 0x83, 0xED, +0x83, 0xED, 0x6B, 0x2B, 0x7B, 0x8C, 0x94, 0x4F, +0xA4, 0xB0, 0xC5, 0xB3, 0xC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 0xC4, 0x18, 0xC4, 0x10, 0xA3, 0x18, 0xC4, +0x18, 0xC4, 0x18, 0xC4, 0x18, 0xC4, 0x18, 0xC4, +0x18, 0xC3, 0x18, 0xE4, 0x29, 0x46, 0x21, 0x25, +0x21, 0x25, 0x21, 0x25, 0x21, 0x05, 0x18, 0xE4, +0x18, 0xE4, 0x18, 0xC4, 0x18, 0xE4, 0x21, 0x05, +0x21, 0x05, 0x18, 0xC4, 0x18, 0xE4, 0x18, 0xE4, +0x18, 0xE5, 0x18, 0xE5, 0x18, 0xE5, 0x21, 0x46, +0x29, 0x67, 0x31, 0x87, 0x31, 0xA8, 0x31, 0xC8, +0x31, 0x87, 0x29, 0x67, 0x31, 0xC8, 0x42, 0x4A, +0x4A, 0x8B, 0x52, 0x8B, 0x6B, 0x6D, 0x94, 0x70, +0x94, 0x4F, 0x62, 0xEA, 0x8C, 0x4F, 0xBD, 0x53, +0xC5, 0x92, 0xD5, 0xF3, 0xE6, 0x96, 0xE6, 0x96, +0xE6, 0x96, 0xE6, 0x96, 0xE6, 0x96, 0xDE, 0x76, +0xDE, 0x55, 0xDE, 0x55, 0xDE, 0x55, 0xCD, 0xF4, +0xA4, 0xB0, 0x94, 0x4E, 0xB5, 0x52, 0xBD, 0x72, +0xCD, 0xD4, 0xDE, 0x56, 0xE6, 0x96, 0xDE, 0x56, +0xD6, 0x15, 0xDE, 0x76, 0xD6, 0x36, 0xAC, 0xF1, +0x94, 0x6F, 0xB5, 0x32, 0xA4, 0xB0, 0x9C, 0xB0, +0x83, 0xCE, 0x52, 0x69, 0x18, 0xE3, 0x31, 0x86, +0x39, 0xA7, 0x31, 0x86, 0x5A, 0xEB, 0x84, 0x10, +0x42, 0x08, 0x4A, 0x08, 0x62, 0xAA, 0x62, 0x8A, +0x49, 0xE7, 0x83, 0x8D, 0x83, 0xAD, 0x83, 0xAE, +0x8D, 0x4F, 0xBE, 0x95, 0xBE, 0x54, 0x6C, 0x09, +0x64, 0x07, 0x64, 0x07, 0x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, 0xB5, 0x32, 0xBD, 0x72, 0xC5, 0x93, +0xC5, 0xB4, 0xCD, 0xF5, 0xBD, 0x93, 0x8C, 0x0E, +0x4A, 0x07, 0x29, 0x45, 0x21, 0x04, 0x18, 0xE4, +0x18, 0xE4, 0x18, 0xE4, 0x18, 0xE4, 0x18, 0xC3, +0x10, 0xA3, 0x18, 0xC4, 0x10, 0xA3, 0x10, 0x83, +0x10, 0xA3, 0x10, 0xA3, 0x10, 0xA3, 0x10, 0xA3, +0x10, 0xA3, 0x10, 0xA3, 0x10, 0xA3, 0x10, 0xA3, +0x10, 0xA3, 0x10, 0xA3, 0x10, 0xA3, 0x10, 0xA3, +0x10, 0xA3, 0x10, 0xA3, 0x10, 0xA3, 0x10, 0xA3, +0x10, 0xA3, 0x18, 0xC4, 0x18, 0xC4, 0x21, 0x25, +0x21, 0x05, 0x21, 0x05, 0x18, 0xC4, 0x10, 0xA3, +0x18, 0xC4, 0x18, 0xE4, 0x10, 0xA3, 0x18, 0xC4, +0x18, 0xC4, 0x18, 0xC4, 0x18, 0xC4, 0x18, 0xC4, +0x18, 0xC4, 0x18, 0xC4, 0x21, 0x25, 0x21, 0x25, +0x21, 0x05, 0x21, 0x25, 0x18, 0xE4, 0x18, 0xE4, +0x18, 0xE4, 0x18, 0xC4, 0x10, 0xA3, 0x18, 0xC4, +0x18, 0xE4, 0x18, 0xC4, 0x18, 0xC4, 0x18, 0xE4, +0x21, 0x05, 0x21, 0x25, 0x21, 0x26, 0x21, 0x46, +0x29, 0x67, 0x21, 0x26, 0x29, 0x67, 0x31, 0xC8, +0x31, 0xC8, 0x31, 0x87, 0x29, 0x67, 0x31, 0xA8, +0x42, 0x0A, 0x4A, 0x4A, 0x4A, 0x6A, 0x73, 0xAE, +0x94, 0x90, 0x6B, 0x4C, 0xA4, 0xF1, 0xC5, 0x93, +0xDE, 0x55, 0xDE, 0x14, 0xE6, 0x96, 0xEE, 0xB6, +0xEE, 0x96, 0xEE, 0xB6, 0xEE, 0xB7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xD6, 0x14, 0xC5, 0x92, 0xBD, 0x51, +0xBD, 0x72, 0xBD, 0x72, 0xC5, 0xB3, 0xAD, 0x12, +0x4A, 0x07, 0x41, 0xE7, 0x6A, 0xEB, 0x73, 0x0B, +0x5A, 0x69, 0x62, 0xCB, 0x9C, 0x71, 0xC5, 0xD6, +0xC5, 0xB6, 0x5A, 0x8A, 0x73, 0x2C, 0x7B, 0x8D, +0x73, 0x2C, 0x9C, 0x70, 0x94, 0x0F, 0x9C, 0x50, +0xBD, 0x94, 0xBD, 0x94, 0xB5, 0x53, 0xBD, 0x94, +0xBD, 0x94, 0xAD, 0x32, 0xBD, 0xB4, 0xC5, 0xB5, +0xBD, 0x94, 0xC5, 0xF5, 0xCD, 0xF5, 0xCD, 0xF5, +0xC5, 0xD5, 0xC5, 0xB5, 0xBD, 0x94, 0xB5, 0x73, +0xB5, 0x32, 0xAD, 0x11, 0xA4, 0xD1, 0xA4, 0xD1, +0xAC, 0xF2, 0xA4, 0xF2, 0xA4, 0xD1, 0x9C, 0x90, +0x94, 0x6F, 0x8C, 0x0E, 0x83, 0xCD, 0x83, 0xAD, +0x52, 0x48, 0x29, 0x45, 0x21, 0x05, 0x21, 0x05, +0x21, 0x05, 0x18, 0xE4, 0x18, 0xC3, 0x18, 0xC4, +0x18, 0xC4, 0x18, 0xC4, 0x10, 0xA3, 0x10, 0xA3, +0x10, 0xA3, 0x10, 0x83, 0x10, 0xA3, 0x10, 0xA3, +0x10, 0xA3, 0x10, 0xA3, 0x10, 0xA3, 0x10, 0xA3, +0x10, 0xA3, 0x10, 0xA3, 0x10, 0xA3, 0x10, 0xA3, +0x10, 0xA3, 0x18, 0xC4, 0x10, 0xA3, 0x10, 0xA3, +0x10, 0xA3, 0x10, 0xA3, 0x18, 0xE4, 0x21, 0x25, +0x18, 0xE4, 0x18, 0xC4, 0x10, 0xA3, 0x18, 0xC4, +0x18, 0xE4, 0x18, 0xE4, 0x10, 0xA3, 0x10, 0xA3, +0x10, 0xA3, 0x10, 0xA3, 0x18, 0xC4, 0x18, 0xC4, +0x18, 0xC4, 0x18, 0xC4, 0x21, 0x05, 0x21, 0x25, +0x18, 0xE5, 0x21, 0x05, 0x18, 0xE4, 0x18, 0xC4, +0x18, 0xC4, 0x18, 0xE4, 0x18, 0xC4, 0x18, 0xC4, +0x10, 0xA3, 0x18, 0xC4, 0x18, 0xC4, 0x18, 0xE5, +0x21, 0x05, 0x21, 0x26, 0x21, 0x46, 0x29, 0x46, +0x29, 0x46, 0x21, 0x26, 0x21, 0x26, 0x29, 0x67, +0x31, 0xA8, 0x31, 0xA8, 0x29, 0x87, 0x29, 0x67, +0x39, 0xC8, 0x42, 0x29, 0x42, 0x2A, 0x4A, 0x8B, +0x84, 0x0F, 0x7B, 0xCE, 0xA4, 0xF1, 0xC5, 0xD4, +0xD6, 0x14, 0xDE, 0x14, 0xE6, 0x75, 0xEE, 0xB6, +0xEE, 0xB6, 0xEE, 0x96, 0xEE, 0xB6, 0xE6, 0x96, +0xDE, 0x54, 0xD6, 0x13, 0xD5, 0xF3, 0xCD, 0xD3, +0xDE, 0x35, 0xDE, 0x76, 0xBD, 0x93, 0xE6, 0xB8, +0xDE, 0x97, 0xDE, 0x76, 0xD6, 0x35, 0xD6, 0x14, +0xD6, 0x34, 0xD5, 0xF4, 0xDE, 0x76, 0xA4, 0xD0, +0xBD, 0x94, 0xBD, 0x93, 0xBD, 0x93, 0xC5, 0xB4, +0xB5, 0x73, 0x9C, 0xD1, 0x7B, 0xCE, 0x29, 0x66, +0x10, 0xA3, 0x18, 0xE4, 0x39, 0xC7, 0xB5, 0x97, +0xBD, 0xB7, 0x73, 0x4D, 0x6A, 0xCB, 0x83, 0xAE, +0x52, 0x08, 0x7B, 0x6D, 0x6A, 0xEA, 0x8C, 0x0F, +0x4B, 0x44, 0x53, 0xA6, 0x7C, 0xCC, 0x95, 0x6F, +0x6C, 0x48, 0x64, 0x06, 0x64, 0x07, 0x53, 0x45, +0x64, 0x27, 0x74, 0xA7, 0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0xB5, 0x53, +0xBD, 0x94, 0xBD, 0x74, 0xBD, 0x94, 0xA4, 0x90, +0x4A, 0x08, 0x29, 0x45, 0x21, 0x05, 0x21, 0x05, +0x21, 0x05, 0x18, 0xC4, 0x10, 0xA3, 0x10, 0xA3, +0x10, 0xA3, 0x10, 0xA3, 0x10, 0x83, 0x10, 0x83, +0x10, 0xA3, 0x10, 0xA3, 0x10, 0xA3, 0x18, 0xC4, +0x10, 0xA3, 0x18, 0xC4, 0x10, 0xA3, 0x10, 0xA3, +0x10, 0xA3, 0x10, 0xA3, 0x10, 0xA3, 0x10, 0xA3, +0x10, 0xA3, 0x10, 0x83, 0x10, 0xA3, 0x10, 0xA3, +0x10, 0xA3, 0x10, 0xC4, 0x18, 0xE4, 0x21, 0x25, +0x18, 0xE4, 0x10, 0xA4, 0x18, 0xC4, 0x18, 0xE4, +0x18, 0xE4, 0x18, 0xC4, 0x10, 0xA4, 0x10, 0xA3, +0x10, 0xC3, 0x10, 0xA3, 0x10, 0xA3, 0x10, 0xA3, +0x18, 0xC4, 0x18, 0xC4, 0x18, 0xE4, 0x21, 0x05, +0x18, 0xE4, 0x18, 0xE5, 0x18, 0xE4, 0x10, 0xC4, +0x18, 0xC4, 0x18, 0xE4, 0x18, 0xE4, 0x10, 0xA3, +0x10, 0xA3, 0x10, 0xA4, 0x10, 0xC4, 0x18, 0xE4, +0x19, 0x05, 0x21, 0x25, 0x21, 0x26, 0x21, 0x26, +0x21, 0x46, 0x29, 0x46, 0x21, 0x26, 0x21, 0x26, +0x29, 0x46, 0x29, 0x87, 0x31, 0x88, 0x29, 0x67, +0x31, 0x87, 0x39, 0xE9, 0x42, 0x2A, 0x4A, 0x4A, +0x5A, 0xEC, 0x7B, 0xAE, 0xA4, 0xF2, 0xC5, 0xD4, +0xDE, 0x35, 0xD5, 0xD3, 0xE6, 0x75, 0xE6, 0x96, +0xEE, 0x96, 0xEE, 0x96, 0xEE, 0xB6, 0xE6, 0x75, +0xE6, 0x75, 0xD6,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0xB5, 0x31, 0xAD, 0x11, 0xBD, 0x92, 0x83, 0xCD, +0x73, 0x4C, 0x6B, 0x0B, 0x42, 0x07, 0x41, 0xE7, +0x42, 0x07, 0x41, 0xE7, 0x5A, 0xAA, 0x7B, 0x6C, +0x83, 0xCE, 0x73, 0x4C, 0x52, 0x49, 0x49, 0xE7, +0x6B, 0x0C, 0x6A, 0xEB, 0x83, 0xAE, 0x94, 0x50, +0xB5, 0x33, 0x94, 0x2F, 0x83, 0xCE, 0x5A, 0x89, +0x6B, 0x2B, 0x83, 0xAD, 0x62, 0xEA, 0x4A, 0x48, +0x52, 0x49, 0x52, 0x68, 0x5A, 0xA9, 0x6B, 0x2B, +0x7B, 0x8C, 0x9C, 0x90, 0x9C, 0x4F, 0xAD, 0x12, +0xAD, 0x12, 0xAC, 0xF1, 0xB5, 0x53, 0xAD, 0x11, +0xBD, 0x73, 0xBD, 0x73, 0xBD, 0x93, 0xB5, 0x52, +0xBD, 0x52, 0xBD, 0x73, 0xCD, 0xD4, 0xA4, 0x90, +0x41, 0xC7, 0x29, 0x45, 0x21, 0x25, 0x21, 0x25, +0x21, 0x04, 0x10, 0xA3, 0x10, 0xA3, 0x10, 0xA3, +0x10, 0xA3, 0x10, 0x83, 0x10, 0x83, 0x10, 0x83, +0x10, 0x83, 0x10, 0xA3, 0x10, 0xA3, 0x10, 0xA3, +0x10, 0xA3, 0x10, 0xA3, 0x10, 0xA3, 0x10, 0xA3, +0x10, 0xA3, 0x10, 0xA3, 0x10, 0xA3, 0x10, 0xA3, +0x10, 0xA3, 0x10, 0x83, 0x10, 0x83, 0x10, 0xA3, +0x10, 0xA3, 0x18, 0xC4, 0x18, 0xE4, 0x21, 0x25, +0x18, 0xE4, 0x10, 0xC3, 0x18, 0xE4, 0x18, 0xC4, +0x18, 0xC4, 0x18, 0xC4, 0x10, 0xC4, 0x18, 0xC4, +0x18, 0xC4, 0x10, 0xC4, 0x10, 0xC4, 0x10, 0xC3, +0x10, 0xC4, 0x10, 0xC4, 0x18, 0xC4, 0x18, 0xE4, +0x18, 0xC4, 0x10, 0xC4, 0x10, 0xC4, 0x10, 0xC3, +0x10, 0xC4, 0x10, 0xC4, 0x10, 0xC4, 0x10, 0xC4, +0x10, 0xA3, 0x10, 0xA4, 0x10, 0xC4, 0x10, 0xC4, +0x19, 0x05, 0x21, 0x05, 0x21, 0x26, 0x21, 0x26, +0x21, 0x26, 0x21, 0x46, 0x21, 0x26, 0x21, 0x26, +0x21, 0x26, 0x21, 0x46, 0x29, 0x87, 0x31, 0x88, +0x29, 0x67, 0x31, 0xA8, 0x39, 0xE9, 0x42, 0x4A, +0x42, 0x4A, 0x63, 0x0C, 0xA4, 0xD1, 0xC5, 0xB3, +0xE6, 0x96, 0xDE, 0x14, 0xDE, 0x55, 0xE6, 0x96, +0xEE, 0x96, 0xEE, 0x96, 0xEE, 0x96, 0xE6, 0x75, +0xE6, 0x75, 0xCD, 0xF3, 0xCD, 0xB3, 0xCD, 0xD3, +0xDE, 0x55, 0xCD, 0xF4, 0xD6, 0x36, 0xE6, 0xB7, +0xDE, 0x77, 0xDE, 0x56, 0xD6, 0x35, 0xCD, 0xF4, +0xCD, 0xD4, 0xE6, 0x96, 0xC5, 0x93, 0xB5, 0x12, +0xBD, 0x73, 0xCD, 0xF5, 0xC5, 0xD4, 0xC5, 0xF4, +0xBD, 0x93, 0xAD, 0x53, 0xCE, 0x36, 0xBD, 0xD5, +0x31, 0x86, 0x18, 0xA3, 0x5A, 0xAB, 0xA4, 0xF3, +0xAD, 0x55, 0xBD, 0xD7, 0x4A, 0x69, 0x4A, 0x28, +0x31, 0x65, 0x52, 0x28, 0x8B, 0xAD, 0xB5, 0x12, +0x5B, 0xE6, 0x64, 0x47, 0x7C, 0xEA, 0x74, 0xA9, +0x5B, 0xE5, 0x6C, 0x28, 0x84, 0xCB, 0x6B, 0xEA, +0x3A, 0x64, 0x4A, 0xE5, 0x63, 0xC7, 0x7C, 0x89, +0x6C, 0x06, 0x8C, 0xED, 0x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 0x4F, +0x41, 0xC7, 0x29, 0x25, 0x18, 0xE4, 0x21, 0x25, +0x18, 0xE4, 0x10, 0xA3, 0x18, 0xC3, 0x10, 0xA3, +0x10, 0xA3, 0x10, 0x83, 0x10, 0x83, 0x10, 0xA3, +0x10, 0xA3, 0x10, 0xA3, 0x10, 0xA3, 0x10, 0xA3, +0x10, 0x83, 0x10, 0x83, 0x10, 0xA3, 0x10, 0xA3, +0x10, 0xA3, 0x18, 0xC4, 0x18, 0xC4, 0x10, 0xA3, +0x10, 0xA3, 0x10, 0xA3, 0x10, 0xA3, 0x10, 0x83, +0x10, 0xA3, 0x10, 0xA3, 0x18, 0xE4, 0x21, 0x25, +0x18, 0xC3, 0x18, 0xE4, 0x21, 0x05, 0x18, 0xE4, +0x18, 0xE4, 0x18, 0xC4, 0x18, 0xE4, 0x18, 0xE4, +0x19, 0x05, 0x10, 0xC4, 0x10, 0xC4, 0x10, 0xC4, +0x18, 0xC4, 0x10, 0xA3, 0x10, 0xC3, 0x10, 0xC3, +0x10, 0xC3, 0x10, 0xA3, 0x10, 0xC3, 0x10, 0xA3, +0x10, 0xA3, 0x10, 0xA3, 0x10, 0xA3, 0x10, 0xA3, +0x10, 0xA3, 0x10, 0xA3, 0x10, 0xA4, 0x18, 0xC4, +0x21, 0x05, 0x21, 0x05, 0x21, 0x26, 0x21, 0x26, +0x21, 0x05, 0x21, 0x26, 0x29, 0x46, 0x21, 0x26, +0x29, 0x46, 0x29, 0x67, 0x29, 0x67, 0x31, 0xA8, +0x31, 0x87, 0x29, 0x87, 0x31, 0xC8, 0x39, 0xE9, +0x42, 0x2A, 0x4A, 0x4A, 0x8C, 0x0F, 0xAC, 0xF1, +0xBD, 0x52, 0xDE, 0x56, 0xEE, 0xD7, 0xF6, 0xF7, +0xF6, 0xF7, 0xF6, 0xF7, 0xEE, 0xD7, 0xEE, 0xD6, +0xEE, 0xD6, 0xE6, 0x96, 0xDE, 0x35, 0xDE, 0x75, +0xE6, 0x96, 0xCD, 0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6, 0x34, 0xDE, 0x55, +0xD5, 0xF3, 0xCD, 0xF3, 0xDE, 0x55, 0xB5, 0x12, +0x4A, 0x27, 0x42, 0x07, 0x4A, 0x28, 0x83, 0xCE, +0x83, 0xEF, 0x8B, 0xEF, 0xC5, 0x95, 0x94, 0x2F, +0x49, 0xE8, 0x41, 0xA7, 0x73, 0x4D, 0x73, 0x2C, +0x83, 0xCE, 0x9C, 0x91, 0xAC, 0xF3, 0x83, 0xCE, +0x7B, 0xAD, 0x6B, 0x2C, 0x73, 0x6D, 0x94, 0x70, +0xA4, 0xD1, 0xBD, 0x93, 0xBD, 0x93, 0xAD, 0x32, +0xB5, 0x32, 0xAD, 0x31, 0xB5, 0x52, 0xC5, 0xB3, +0xC5, 0xB3, 0xAC, 0xF1, 0xBD, 0x73, 0xAD, 0x12, +0xBD, 0x93, 0xC5, 0xB3, 0xCE, 0x14, 0xC5, 0x93, +0xC5, 0x93, 0xCD, 0xD4, 0xC5, 0xD4, 0x9C, 0x6F, +0x41, 0xC7, 0x21, 0x04, 0x18, 0xE4, 0x29, 0x25, +0x18, 0xE4, 0x18, 0xC4, 0x18, 0xC3, 0x10, 0xA3, +0x10, 0xA3, 0x10, 0x83, 0x10, 0x83, 0x10, 0xA3, +0x10, 0x83, 0x10, 0x83, 0x10, 0xA3, 0x10, 0x83, +0x10, 0x83, 0x10, 0x83, 0x10, 0xA3, 0x10, 0xA3, +0x10, 0xA3, 0x10, 0xA3, 0x10, 0xA3, 0x10, 0xA3, +0x10, 0xA3, 0x10, 0xA3, 0x10, 0xA3, 0x08, 0x83, +0x10, 0x83, 0x08, 0x83, 0x19, 0x04, 0x21, 0x05, +0x18, 0xC4, 0x21, 0x05, 0x21, 0x05, 0x18, 0xE4, +0x18, 0xE4, 0x18, 0xE4, 0x21, 0x05, 0x18, 0xE4, +0x21, 0x25, 0x10, 0xC4, 0x10, 0xC4, 0x10, 0xC4, +0x18, 0xC4, 0x10, 0xC4, 0x18, 0xC4, 0x18, 0xC4, +0x10, 0xA4, 0x10, 0xA3, 0x10, 0xA3, 0x10, 0xA3, +0x10, 0xA3, 0x10, 0xA3, 0x10, 0xA3, 0x10, 0xA3, +0x10, 0xA3, 0x10, 0xA3, 0x10, 0xA4, 0x18, 0xE4, +0x21, 0x25, 0x21, 0x05, 0x21, 0x26, 0x21, 0x26, +0x21, 0x26, 0x21, 0x46, 0x29, 0x46, 0x29, 0x47, +0x21, 0x46, 0x29, 0x67, 0x29, 0x67, 0x29, 0x87, +0x29, 0x87, 0x29, 0x87, 0x29, 0x87, 0x39, 0xC8, +0x42, 0x2A, 0x4A, 0x4A, 0x52, 0xAA, 0xAD, 0x32, +0xBD, 0x93, 0xAC, 0xD0, 0xAC, 0xD0, 0xAC, 0xD0, +0xAC, 0xF0, 0xB4, 0xF0, 0xB5, 0x10, 0xB5, 0x10, +0xB5, 0x10, 0xB4, 0xF0, 0xB5, 0x31, 0xB5, 0x31, +0xAD, 0x31, 0xBD, 0x73, 0xDE, 0x56, 0xDE, 0x76, +0xDE, 0x76, 0xDE, 0x76, 0xD6, 0x35, 0xD6, 0x15, +0xCD, 0xF4, 0xDE, 0x76, 0xC5, 0x93, 0x9C, 0x6F, +0xBD, 0x93, 0xBD, 0xB4, 0xBD, 0x93, 0xC5, 0xD4, +0xB5, 0x73, 0xA4, 0xD1, 0xCE, 0x16, 0xCE, 0x16, +0x63, 0x2B, 0x29, 0x65, 0x10, 0xA3, 0x31, 0x65, +0x39, 0xE6, 0x29, 0x24, 0x39, 0x86, 0x52, 0x48, +0x49, 0xE7, 0x41, 0xE7, 0x52, 0x07, 0x83, 0x6D, +0xAD, 0xF4, 0x63, 0xEB, 0x43, 0x42, 0x4B, 0xA2, +0x3A, 0xC2, 0x4B, 0x06, 0x84, 0xAC, 0x7C, 0x6C, +0xAD, 0x91, 0x6B, 0x89, 0x3A, 0x44, 0x5B, 0x87, +0x4B, 0x05, 0x8C, 0xAE, 0xAD, 0xB2, 0x94, 0xEE, +0x9D, 0x0F, 0x9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 0xE4, 0x21, 0x04, 0x21, 0x25, +0x21, 0x04, 0x18, 0xC4, 0x10, 0xA3, 0x18, 0xC4, +0x18, 0xC4, 0x10, 0xA3, 0x10, 0x83, 0x10, 0xA3, +0x10, 0x83, 0x08, 0x83, 0x10, 0x83, 0x10, 0x83, +0x10, 0x83, 0x10, 0x83, 0x10, 0x83, 0x10, 0xA3, +0x10, 0xA3, 0x10, 0xA3, 0x10, 0xA3, 0x10, 0xA3, +0x10, 0xA3, 0x10, 0xA3, 0x10, 0x83, 0x08, 0x83, +0x08, 0x83, 0x10, 0xC3, 0x21, 0x05, 0x21, 0x05, +0x18, 0xC3, 0x21, 0x05, 0x21, 0x25, 0x18, 0xE4, +0x18, 0xE4, 0x18, 0xE4, 0x21, 0x05, 0x18, 0xE4, +0x21, 0x05, 0x10, 0xC4, 0x10, 0xC4, 0x18, 0xE4, +0x18, 0xC4, 0x10, 0xC4, 0x10, 0xC4, 0x10, 0xC4, +0x10, 0xA3, 0x10, 0xA3, 0x10, 0xA3, 0x10, 0xA3, +0x10, 0x83, 0x10, 0x83, 0x10, 0xA4, 0x10, 0xA3, +0x10, 0xA3, 0x10, 0xA3, 0x18, 0xE4, 0x19, 0x05, +0x21, 0x05, 0x21, 0x26, 0x21, 0x26, 0x21, 0x26, +0x21, 0x26, 0x21, 0x46, 0x29, 0x46, 0x29, 0x46, +0x29, 0x67, 0x29, 0x46, 0x29, 0x67, 0x29, 0x67, +0x29, 0x67, 0x29, 0x46, 0x29, 0x67, 0x29, 0x87, +0x3A, 0x09, 0x42, 0x29, 0x42, 0x09, 0x63, 0x2C, +0xB5, 0x53, 0xAC, 0xF1, 0xBD, 0x94, 0xA4, 0xD0, +0xA4, 0xD0, 0xA4, 0xD0, 0xAC, 0xD1, 0xAC, 0xF1, +0xAD, 0x11, 0xAD, 0x11, 0xB5, 0x12, 0xB5, 0x53, +0xB5, 0x32, 0xAD, 0x12, 0xAC, 0xF1, 0xAD, 0x11, +0xAC, 0xF1, 0xAC,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 0xDE, 0x34, 0xCD, 0xB2, +0xBD, 0x71, 0xB5, 0x10, 0x8C, 0x0E, 0x5A, 0xAA, +0x83, 0xAE, 0x94, 0x30, 0x6A, 0xEB, 0x5A, 0x8A, +0x4A, 0x08, 0x52, 0x49, 0x39, 0x86, 0x6B, 0x0B, +0x5A, 0x69, 0x73, 0x6D, 0xCE, 0x17, 0x83, 0x8D, +0x8B, 0xEF, 0xBD, 0x95, 0xA4, 0xF1, 0xBD, 0x73, +0xD5, 0xF4, 0xC5, 0x92, 0xBD, 0x51, 0xCD, 0xD3, +0xC5, 0x72, 0xAD, 0x11, 0x7B, 0x8B, 0x7B, 0x8C, +0xC5, 0xB4, 0xAD, 0x11, 0xC5, 0xB4, 0xAD, 0x12, +0xB5, 0x52, 0xBD, 0x72, 0xC5, 0xB3, 0xBD, 0x92, +0xBD, 0x72, 0xBD, 0x31, 0xC5, 0x72, 0x9C, 0x6F, +0x62, 0xA9, 0x39, 0xA7, 0x29, 0x46, 0x21, 0x05, +0x21, 0x05, 0x18, 0xC4, 0x18, 0xE4, 0x18, 0xC3, +0x10, 0xA3, 0x10, 0xA3, 0x10, 0xA3, 0x10, 0xA3, +0x08, 0x83, 0x08, 0x83, 0x08, 0x83, 0x08, 0x83, +0x10, 0x83, 0x08, 0x83, 0x08, 0x83, 0x08, 0x83, +0x10, 0x83, 0x10, 0xA3, 0x10, 0xA3, 0x10, 0xA3, +0x10, 0xA3, 0x10, 0xA3, 0x10, 0x83, 0x08, 0x83, +0x10, 0xA3, 0x10, 0xC3, 0x19, 0x05, 0x18, 0xE4, +0x18, 0xC4, 0x21, 0x25, 0x19, 0x05, 0x18, 0xE4, +0x19, 0x04, 0x18, 0xE4, 0x21, 0x05, 0x18, 0xE4, +0x19, 0x05, 0x10, 0xA3, 0x10, 0xC4, 0x10, 0xC4, +0x10, 0xC4, 0x10, 0xC3, 0x18, 0xC4, 0x10, 0xC4, +0x10, 0xA3, 0x10, 0xA3, 0x10, 0xA3, 0x10, 0xA3, +0x10, 0xA3, 0x10, 0xA3, 0x10, 0xC3, 0x10, 0xA3, +0x10, 0xA3, 0x18, 0xE4, 0x18, 0xE4, 0x19, 0x05, +0x19, 0x05, 0x19, 0x05, 0x21, 0x05, 0x21, 0x26, +0x21, 0x26, 0x21, 0x46, 0x21, 0x46, 0x29, 0x46, +0x29, 0x67, 0x29, 0x46, 0x29, 0x67, 0x29, 0x67, +0x29, 0x67, 0x21, 0x26, 0x29, 0x46, 0x29, 0x87, +0x39, 0xC8, 0x42, 0x09, 0x3A, 0x09, 0x39, 0xE8, +0x8C, 0x30, 0xBD, 0xB4, 0xC5, 0xF5, 0x94, 0x70, +0x8C, 0x0E, 0x9C, 0xB0, 0x8C, 0x2E, 0xAD, 0x12, +0xA4, 0xD1, 0xC5, 0xF5, 0xBD, 0xD5, 0xBD, 0xB5, +0xB5, 0x54, 0xAD, 0x33, 0xA4, 0xF2, 0xAD, 0x12, +0xB5, 0x73, 0xAD, 0x12, 0x9C, 0xB0, 0x94, 0x70, +0x94, 0x70, 0x94, 0x4F, 0x8C, 0x0E, 0x83, 0xEE, +0x94, 0x2F, 0x94, 0x6F, 0x9C, 0x90, 0x9C, 0x90, +0x9C, 0x90, 0xA4, 0xF1, 0xA4, 0xD1, 0x9C, 0x6F, +0xA4, 0xF1, 0x73, 0x8C, 0x20, 0xE4, 0x18, 0xA3, +0x31, 0x65, 0x31, 0x65, 0x39, 0x85, 0x39, 0xA6, +0x4A, 0x07, 0x39, 0xA6, 0x4A, 0x07, 0x8B, 0xCE, +0x7C, 0x8D, 0x63, 0xCA, 0x84, 0xAE, 0x5B, 0x88, +0x43, 0x04, 0x53, 0x66, 0x8D, 0x0D, 0x6B, 0xE9, +0x52, 0xC6, 0x4A, 0x65, 0x4A, 0x85, 0x94, 0xEE, +0xAD, 0xB1, 0x8C, 0xAE, 0x73, 0xEB, 0xAD, 0x71, +0xB5, 0x92, 0x9C, 0xCE, 0xA4, 0xEF, 0xCE, 0x55, +0xCE, 0x14,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 0xE4, 0x18, 0xC4, 0x10, 0xA3, +0x10, 0xA3, 0x18, 0xC3, 0x10, 0xA3, 0x10, 0xA3, +0x10, 0x83, 0x10, 0x83, 0x08, 0x83, 0x08, 0x83, +0x08, 0x83, 0x08, 0x83, 0x08, 0x83, 0x08, 0x83, +0x08, 0x83, 0x08, 0x83, 0x08, 0x83, 0x10, 0xA3, +0x10, 0xA3, 0x10, 0xA3, 0x10, 0xA3, 0x10, 0x83, +0x10, 0xA3, 0x10, 0xA3, 0x19, 0x05, 0x18, 0xE4, +0x18, 0xC4, 0x21, 0x25, 0x18, 0xE4, 0x18, 0xE4, +0x10, 0xC3, 0x18, 0xE4, 0x18, 0xE4, 0x10, 0xC4, +0x18, 0xE4, 0x10, 0xA3, 0x10, 0xA3, 0x10, 0xC3, +0x10, 0xA3, 0x10, 0xC3, 0x10, 0xC3, 0x10, 0xA3, +0x10, 0xA3, 0x10, 0xA3, 0x10, 0x83, 0x10, 0xA3, +0x10, 0xA3, 0x18, 0xC4, 0x18, 0xE4, 0x10, 0xC4, +0x18, 0xE4, 0x19, 0x05, 0x19, 0x05, 0x18, 0xE4, +0x19, 0x05, 0x18, 0xE5, 0x21, 0x05, 0x21, 0x46, +0x21, 0x46, 0x29, 0x46, 0x21, 0x46, 0x21, 0x46, +0x29, 0x46, 0x29, 0x67, 0x29, 0x67, 0x29, 0x67, +0x29, 0x67, 0x29, 0x46, 0x29, 0x46, 0x29, 0x67, +0x31, 0xC8, 0x3A, 0x09, 0x39, 0xE9, 0x31, 0xC8, +0x39, 0xC8, 0x94, 0x71, 0xCE, 0x16, 0x94, 0x90, +0x94, 0x4F, 0xA4, 0xD1, 0xA4, 0xD0, 0xB5, 0x53, +0xAD, 0x53, 0xCE, 0x77, 0xC6, 0x37, 0xC5, 0xF6, +0xC6, 0x17, 0xBD, 0xF6, 0xAD, 0x53, 0x9C, 0xB1, +0xAD, 0x33, 0xA5, 0x12, 0x8C, 0x50, 0x8C, 0x50, +0x9C, 0x91, 0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, 0x52, 0x6B, 0x0A, 0x62, 0xEA, +0x4A, 0x28, 0x41, 0xE7, 0x29, 0x44, 0x31, 0x86, +0x41, 0xC7, 0x4A, 0x08, 0x52, 0x49, 0x5A, 0x89, +0x94, 0x30, 0x62, 0xCB, 0x5A, 0x69, 0x7B, 0x8E, +0x7B, 0x8E, 0x83, 0x8E, 0xB5, 0x13, 0xCE, 0x16, +0xAD, 0x12, 0x9C, 0x90, 0x9C, 0x6F, 0x94, 0x2E, +0xA4, 0xAF, 0xAD, 0x11, 0xBD, 0x53, 0xB5, 0x32, +0xAC, 0xF0, 0x94, 0x2E, 0xBD, 0x74, 0xA4, 0xB0, +0x9C, 0x6F, 0x9C, 0x4E, 0x9C, 0x4E, 0x9C, 0x6E, +0xA4, 0xAF, 0xAC, 0xD0, 0xAC, 0xD0, 0xA4, 0xB0, +0xAC, 0xF1, 0x94, 0x0E, 0x5A, 0x69, 0x31, 0x66, +0x21, 0x25, 0x21, 0x25, 0x18, 0xC4, 0x10, 0xA3, +0x10, 0xA3, 0x10, 0xA3, 0x10, 0xA3, 0x10, 0xA3, +0x10, 0x83, 0x08, 0x83, 0x08, 0x83, 0x10, 0x83, +0x10, 0x83, 0x10, 0x83, 0x10, 0x83, 0x08, 0x83, +0x08, 0x83, 0x08, 0x82, 0x08, 0x83, 0x08, 0x83, +0x10, 0xA3, 0x10, 0xA3, 0x10, 0xA3, 0x10, 0xA3, +0x10, 0xA3, 0x10, 0xA3, 0x19, 0x04, 0x18, 0xC4, +0x18, 0xE4, 0x21, 0x25, 0x18, 0xE4, 0x18, 0xC4, +0x10, 0xC3, 0x18, 0xE4, 0x18, 0xE4, 0x18, 0xC4, +0x18, 0xE4, 0x10, 0xA3, 0x10, 0xA3, 0x10, 0xA3, +0x10, 0xA3, 0x10, 0xC3, 0x10, 0xC3, 0x10, 0xA3, +0x10, 0x83, 0x10, 0x83, 0x10, 0x83, 0x10, 0xA3, +0x10, 0xA3, 0x18, 0xE4, 0x18, 0xE4, 0x19, 0x05, +0x19, 0x05, 0x21, 0x05, 0x21, 0x05, 0x19, 0x05, +0x18, 0xE5, 0x18, 0xE5, 0x21, 0x26, 0x21, 0x46, +0x21, 0x46, 0x29, 0x46, 0x21, 0x46, 0x21, 0x46, +0x29, 0x46, 0x29, 0x46, 0x21, 0x46, 0x29, 0x46, +0x21, 0x46, 0x21, 0x46, 0x29, 0x46, 0x29, 0x46, +0x29, 0x87, 0x39, 0xE9, 0x39, 0xE9, 0x39, 0xE9, +0x31, 0x87, 0x39, 0xE8, 0x8C, 0x50, 0x9C, 0xF1, +0x94, 0x6F, 0x9C, 0x90, 0x9C, 0xB0, 0xB5, 0x53, +0xB5, 0x53, 0xCE, 0x57, 0xC6, 0x37, 0xBD, 0xB5, +0xB5, 0xB5, 0xBD, 0xB5, 0xA5, 0x12, 0x84, 0x2F, +0x8C, 0x91, 0x8C, 0x50, 0x7B, 0xEE, 0x8C, 0x50, +0x94, 0x91, 0x9C, 0xF2, 0xA5, 0x13, 0xA5, 0x33, +0xBD, 0xB5, 0xA5, 0x12, 0x9C, 0x91, 0xA4, 0xF2, +0x9C, 0xB0, 0x94, 0x90, 0xA4, 0xF1, 0xA4, 0xF1, +0xC5, 0xB4, 0xD6, 0x56, 0x52, 0x89, 0x18, 0xE4, +0x10, 0x82, 0x29, 0x44, 0x39, 0x85, 0x39, 0xA6, +0x52, 0x48, 0x6A, 0xEA, 0x5A, 0x89, 0x7B, 0x8D, +0x95, 0x70, 0x9D, 0x91, 0x74, 0x6D, 0x5B, 0xC9, +0x6C, 0x49, 0x53, 0x66, 0x53, 0x46, 0x6C, 0x08, +0x6B, 0xE9, 0x5B, 0x27, 0x8C, 0x6C, 0x8C, 0x4C, +0x84, 0x0B, 0x73, 0xCB, 0x74, 0x0B, 0x6B, 0xEB, +0x7C, 0x4D, 0xBE, 0x34, 0xA5, 0x10, 0xA5, 0x10, +0xB5, 0x71, 0xBD, 0xB3, 0xB5, 0x52, 0xB5, 0x52, +0xBD, 0xD4, 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0x10, 0xA3, +0x10, 0xA3, 0x10, 0xA3, 0x10, 0xA3, 0x10, 0xA3, +0x10, 0xA3, 0x10, 0xA3, 0x10, 0x83, 0x10, 0x83, +0x10, 0x83, 0x10, 0x83, 0x08, 0x83, 0x08, 0x83, +0x10, 0x83, 0x10, 0x83, 0x10, 0xA3, 0x10, 0x83, +0x10, 0x83, 0x10, 0xC4, 0x18, 0xE4, 0x10, 0xA3, +0x18, 0xE4, 0x19, 0x05, 0x18, 0xE4, 0x18, 0xE4, +0x10, 0xC4, 0x18, 0xE4, 0x18, 0xE4, 0x18, 0xE4, +0x18, 0xC4, 0x10, 0xC3, 0x10, 0xC4, 0x10, 0xA3, +0x10, 0xA3, 0x10, 0xC3, 0x10, 0xC4, 0x10, 0xA3, +0x10, 0x83, 0x08, 0x83, 0x08, 0x83, 0x10, 0xA3, +0x10, 0xA3, 0x18, 0xC4, 0x18, 0xE4, 0x19, 0x05, +0x19, 0x05, 0x19, 0x05, 0x21, 0x05, 0x19, 0x05, +0x19, 0x05, 0x19, 0x05, 0x21, 0x46, 0x21, 0x26, +0x21, 0x46, 0x21, 0x46, 0x21, 0x46, 0x21, 0x46, +0x29, 0x46, 0x21, 0x46, 0x21, 0x26, 0x21, 0x46, +0x21, 0x46, 0x21, 0x46, 0x21, 0x46, 0x29, 0x46, +0x29, 0x67, 0x31, 0xA8, 0x39, 0xE9, 0x39, 0xE9, +0x39, 0xC8, 0x29, 0x87, 0x42, 0x28, 0x83, 0xEF, +0x94, 0x4F, 0x9C, 0xB0, 0x8C, 0x2F, 0xB5, 0x53, +0xB5, 0x53, 0xD6, 0x98, 0xCE, 0x57, 0xBD, 0xB5, +0xAD, 0x74, 0xB5, 0x74, 0x9C, 0xF2, 0x84, 0x30, +0x8C, 0x91, 0x84, 0x2F, 0x7B, 0xEE, 0x7B, 0xEF, +0x94, 0x71, 0xA5, 0x13, 0xA4, 0xF2, 0x94, 0x90, +0xB5, 0x94, 0xA5, 0x13, 0x8C, 0x50, 0x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, 0x5A, 0x89, 0x52, 0x69, +0x41, 0xC7, 0x5A, 0xAA, 0x39, 0xA6, 0x39, 0xA7, +0x6B, 0x2D, 0xAD, 0x14, 0xCD, 0xF7, 0xAD, 0x13, +0xC5, 0xD6, 0x83, 0xCD, 0x94, 0x4F, 0x94, 0x6F, +0xBD, 0x73, 0xB5, 0x52, 0xB5, 0x53, 0xBD, 0xB4, +0xBD, 0x94, 0xA4, 0xD0, 0xA4, 0xF1, 0xA4, 0xB0, +0x8C, 0x0D, 0xAD, 0x32, 0xA4, 0xD1, 0xA4, 0xD0, +0xAC, 0xF1, 0xA4, 0xB0, 0xA4, 0xD1, 0xA4, 0xB0, +0xC5, 0xD4, 0xC5, 0xB4, 0x9C, 0x6F, 0x73, 0x2B, +0x41, 0xE7, 0x29, 0x45, 0x21, 0x04, 0x21, 0x25, +0x18, 0xC4, 0x10, 0x83, 0x10, 0xA3, 0x10, 0xA3, +0x10, 0xC4, 0x10, 0xA3, 0x10, 0xA3, 0x10, 0xA3, +0x10, 0xA3, 0x10, 0xA3, 0x10, 0xA3, 0x10, 0xA3, +0x10, 0xA3, 0x10, 0x83, 0x10, 0x83, 0x08, 0x83, +0x08, 0x83, 0x08, 0x83, 0x08, 0x83, 0x08, 0x83, +0x10, 0xA3, 0x10, 0xC3, 0x10, 0xA3, 0x10, 0xC4, +0x18, 0xE4, 0x18, 0xE4, 0x18, 0xE4, 0x18, 0xC4, +0x10, 0xC3, 0x18, 0xE4, 0x18, 0xE4, 0x18, 0xE4, +0x18, 0xE4, 0x18, 0xE4, 0x10, 0xC4, 0x10, 0xC3, +0x10, 0xA3, 0x10, 0xA3, 0x10, 0xC4, 0x10, 0xC4, +0x10, 0xA3, 0x08, 0x83, 0x08, 0x83, 0x10, 0xA3, +0x10, 0xC3, 0x10, 0xC4, 0x18, 0xE4, 0x18, 0xE4, +0x19, 0x05, 0x18, 0xE5, 0x21, 0x05, 0x21, 0x05, +0x19, 0x05, 0x21, 0x26, 0x29, 0x46, 0x21, 0x26, +0x21, 0x46, 0x21, 0x46, 0x21, 0x26, 0x21, 0x46, +0x21, 0x46, 0x21, 0x46, 0x21, 0x26, 0x21, 0x26, +0x21, 0x26, 0x21, 0x46, 0x29, 0x46, 0x29, 0x46, +0x29, 0x46, 0x29, 0x87, 0x39, 0xE9, 0x39, 0xC8, +0x39, 0xC8, 0x29, 0x87, 0x29, 0x67, 0x52, 0x6A, +0xA4, 0xF2, 0xBD, 0xB4, 0x8C, 0x0E, 0xB5, 0x53, +0xAD, 0x53, 0xCE, 0x57, 0xC6, 0x37, 0xC6, 0x37, +0xC6, 0x16, 0xC5, 0xF6, 0xAD, 0x54, 0x94, 0xB2, +0x94, 0xD2, 0x94, 0x91, 0x84, 0x30, 0x8C, 0x50, +0xA5, 0x13, 0xB5, 0x94, 0x8C, 0x4F, 0x7B, 0xCE, +0xAD, 0x54, 0x94, 0x91, 0x8C, 0x70, 0xB5, 0x94, +0x9C, 0xD1, 0x94, 0xB1, 0x9C, 0xB1, 0xA4, 0xF2, +0xCE, 0x15, 0xD6, 0x54, 0xD6, 0x56, 0x39, 0xA6, +0x18, 0xE3, 0x10, 0x82, 0x31, 0x65, 0x41, 0xE7, +0x4A, 0x28, 0x5A, 0xA9, 0x6A, 0xEB, 0x5A, 0x89, +0x7C, 0x6D, 0x74, 0x4D, 0x74, 0x4D, 0x63, 0xEA, +0x64, 0x0A, 0x5B, 0xA7, 0x4B, 0x44, 0x64, 0x07, +0x4B, 0x24, 0x84, 0xCC, 0x74, 0x4B, 0x53, 0x08, +0x84, 0xAD, 0x6C, 0x28, 0x74, 0x67, 0x95, 0x4D, +0x8C, 0x8D, 0x7B, 0xCC, 0x7B, 0x8B, 0x73, 0x2A, +0x83, 0xCC, 0x8C, 0x0D, 0xAD, 0x31, 0xCD, 0xD4, +0xA4, 0xAF, 0xA4, 0xAF, 0x9C, 0x4E, 0xB5, 0x31, +0xAC, 0xF0, 0xAC, 0xCF, 0x9C, 0x6E, 0x9C, 0x8E, +0x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0x83, 0x10, 0xA3, +0x10, 0xA3, 0x10, 0xA3, 0x10, 0x83, 0x08, 0x83, +0x08, 0x83, 0x08, 0x83, 0x08, 0x83, 0x10, 0x83, +0x10, 0x83, 0x10, 0xA3, 0x10, 0xA3, 0x10, 0xC4, +0x18, 0xE4, 0x18, 0xE4, 0x18, 0xE4, 0x18, 0xC4, +0x10, 0xA3, 0x18, 0xE4, 0x19, 0x04, 0x18, 0xE4, +0x19, 0x04, 0x10, 0xC4, 0x10, 0xC4, 0x10, 0xA3, +0x10, 0xC3, 0x10, 0xA3, 0x18, 0xE4, 0x10, 0xA3, +0x10, 0xA3, 0x10, 0x83, 0x10, 0xA3, 0x10, 0xA3, +0x10, 0xC3, 0x10, 0xC4, 0x18, 0xE4, 0x18, 0xE4, +0x19, 0x05, 0x21, 0x05, 0x21, 0x05, 0x21, 0x05, +0x21, 0x05, 0x21, 0x26, 0x21, 0x46, 0x21, 0x26, +0x21, 0x26, 0x29, 0x46, 0x21, 0x26, 0x21, 0x26, +0x21, 0x26, 0x21, 0x26, 0x21, 0x26, 0x21, 0x26, +0x21, 0x26, 0x21, 0x26, 0x29, 0x46, 0x29, 0x67, +0x21, 0x46, 0x29, 0x67, 0x31, 0xC8, 0x31, 0xC8, +0x31, 0xA8, 0x31, 0xA8, 0x31, 0x87, 0x31, 0x87, +0x6B, 0x4C, 0xBD, 0xB4, 0x94, 0x4E, 0xB5, 0x53, +0xB5, 0x94, 0xD6, 0x98, 0xD6, 0x98, 0xCE, 0x78, +0xCE, 0x57, 0xC6, 0x36, 0xBD, 0xB5, 0xA5, 0x33, +0xAD, 0x74, 0xA5, 0x34, 0xA5, 0x34, 0xB5, 0x95, +0xC6, 0x16, 0xAD, 0x74, 0x73, 0xAD, 0x9C, 0xF2, +0xAD, 0x74, 0xA5, 0x13, 0x9C, 0xD2, 0xBD, 0xB5, +0xAD, 0x53, 0x9C, 0xB1, 0x9C, 0xB1, 0xA4, 0xF2, +0xD6, 0x56, 0xDE, 0x75,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 0x29, 0x44, +0x29, 0x64, 0x42, 0x07, 0x83, 0xEF, 0x9C, 0x92, +0x7B, 0x6D, 0xA4, 0xD2, 0xCE, 0x16, 0xA4, 0xD1, +0xBD, 0x73, 0xC5, 0xD4, 0xCE, 0x15, 0xCE, 0x36, +0xC5, 0xD4, 0xB5, 0x53, 0x94, 0x6F, 0x8C, 0x2E, +0x9C, 0x90, 0xC5, 0xB4, 0xB5, 0x73, 0xC5, 0xF5, +0xBD, 0x93, 0xA4, 0xB0, 0xAD, 0x32, 0x8C, 0x2E, +0xA4, 0xD1, 0xB5, 0x52, 0xC5, 0xD4, 0xBD, 0x73, +0xC5, 0xD4, 0xB5, 0x32, 0xAC, 0xD1, 0xBD, 0x73, +0x7B, 0x8C, 0x52, 0x69, 0x29, 0x25, 0x18, 0xE4, +0x10, 0xC3, 0x10, 0xA3, 0x10, 0xC3, 0x10, 0xC3, +0x10, 0xA3, 0x10, 0xA3, 0x10, 0x83, 0x10, 0xA3, +0x10, 0xA3, 0x10, 0xA3, 0x10, 0xA3, 0x10, 0x83, +0x10, 0x83, 0x08, 0x83, 0x08, 0x83, 0x08, 0x83, +0x08, 0x83, 0x10, 0x83, 0x10, 0xA3, 0x10, 0xC4, +0x10, 0xC4, 0x18, 0xE4, 0x18, 0xE4, 0x18, 0xC4, +0x10, 0x83, 0x18, 0xE4, 0x19, 0x05, 0x18, 0xE4, +0x19, 0x04, 0x18, 0xC4, 0x10, 0xC3, 0x10, 0xA3, +0x10, 0xC3, 0x10, 0xA3, 0x10, 0xC4, 0x10, 0xC3, +0x10, 0xA3, 0x10, 0xA3, 0x10, 0xA3, 0x10, 0xA3, +0x10, 0xC4, 0x18, 0xE4, 0x18, 0xE4, 0x21, 0x25, +0x21, 0x05, 0x21, 0x05, 0x19, 0x05, 0x19, 0x05, +0x21, 0x05, 0x21, 0x05, 0x21, 0x26, 0x21, 0x05, +0x21, 0x05, 0x21, 0x05, 0x21, 0x05, 0x21, 0x26, +0x21, 0x26, 0x21, 0x46, 0x21, 0x26, 0x21, 0x26, +0x21, 0x26, 0x21, 0x26, 0x21, 0x46, 0x29, 0x46, +0x29, 0x46, 0x21, 0x46, 0x31, 0x87, 0x39, 0xE9, +0x31, 0xA8, 0x31, 0xA7, 0x39, 0xC8, 0x31, 0x87, +0x39, 0xA7, 0x7B, 0xAE, 0x9C, 0x90, 0xB5, 0x53, +0xB5, 0x73, 0xC6, 0x16, 0xAD, 0x53, 0xBD, 0xB5, +0xBD, 0xB4, 0xBD, 0xB4, 0xB5, 0x94, 0xB5, 0x94, +0xB5, 0x74, 0xA5, 0x13, 0xAD, 0x33, 0xA5, 0x13, +0xAD, 0x33, 0x9C, 0xD1, 0x84, 0x0E, 0xA4, 0xF2, +0xB5, 0x74, 0xAD, 0x53, 0xA5, 0x13, 0xBD, 0xB5, +0xCE, 0x37, 0xB5, 0x74, 0xA4, 0xF1, 0xAD, 0x12, +0xCE, 0x15, 0xE6, 0xB6, 0xD6, 0x35, 0x7B, 0xAD, +0x39, 0xC7, 0x18, 0xC3, 0x10, 0x82, 0x31, 0x66, +0x42, 0x07, 0x4A, 0x07, 0x6B, 0x2B, 0x4A, 0x27, +0x64, 0x29, 0x5B, 0xE8, 0x2A, 0x43, 0x42, 0xE8, +0x74, 0x6C, 0x63, 0xE8, 0x4B, 0x44, 0x4B, 0x64, +0x6C, 0x28, 0x6C, 0x29, 0x4B, 0x65, 0x64, 0x27, +0x6C, 0x68, 0x7C, 0xCB, 0x9D, 0xAF, 0xA5, 0x70, +0xA5, 0x11, 0x9C, 0xF1, 0xA5, 0x33, 0xB5, 0x94, +0x9C, 0xD1, 0x94, 0x90, 0x8C, 0x4F, 0x8C, 0x6F, +0x94, 0x90, 0x9C, 0xD1, 0x9C, 0xAF, 0xB5, 0x10, +0xB5, 0x10, 0xC5, 0xD4, 0xAD, 0x53, 0xB5, 0x94, +0xAD, 0x53, 0xA5, 0x12, 0xA5, 0x12, 0xA4, 0xF1, +0x9C, 0xD0, 0x9C, 0xB0,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x08, 0x82, 0x08, 0x83, 0x08, 0x83, +0x10, 0x83, 0x08, 0x83, 0x10, 0x83, 0x10, 0xA3, +0x10, 0xC4, 0x10, 0xC4, 0x18, 0xE4, 0x10, 0xC3, +0x08, 0x83, 0x10, 0xC3, 0x18, 0xE4, 0x18, 0xE4, +0x18, 0xE4, 0x10, 0xC4, 0x10, 0xA3, 0x10, 0xA3, +0x10, 0xC4, 0x10, 0xA3, 0x10, 0xC3, 0x10, 0xA3, +0x10, 0xA3, 0x10, 0xA3, 0x10, 0xA3, 0x10, 0xA3, +0x18, 0xE4, 0x18, 0xE4, 0x19, 0x05, 0x21, 0x26, +0x21, 0x05, 0x19, 0x05, 0x19, 0x05, 0x19, 0x05, +0x21, 0x05, 0x21, 0x05, 0x21, 0x05, 0x21, 0x26, +0x19, 0x05, 0x19, 0x05, 0x19, 0x05, 0x19, 0x05, +0x21, 0x05, 0x21, 0x26, 0x21, 0x26, 0x21, 0x26, +0x21, 0x26, 0x21, 0x26, 0x21, 0x26, 0x21, 0x46, +0x21, 0x46, 0x21, 0x46, 0x29, 0x46, 0x39, 0xC8, +0x31, 0xA8, 0x29, 0x67, 0x39, 0xC8, 0x39, 0xE9, +0x31, 0x87, 0x4A, 0x4A, 0x73, 0x6D, 0x94, 0x70, +0x9C, 0xB0, 0x9C, 0xB0, 0x9C, 0xB0, 0x94, 0x6F, +0x8C, 0x2E, 0x8C, 0x0E, 0x84, 0x0E, 0x84, 0x0E, +0x8C, 0x2F, 0x8C, 0x0E, 0x83, 0xEE, 0x83, 0xCD, +0x73, 0x6C, 0x73, 0x6C, 0x7B, 0x8C, 0x7B, 0xAD, +0x94, 0x4F, 0x83, 0xEE, 0x84, 0x0E, 0x84, 0x0E, +0x94, 0x70, 0x84, 0x0E, 0x8C, 0x2F, 0x9C, 0xB0, +0xA4, 0x90, 0xCD, 0xD4, 0xD6, 0x55, 0x9C, 0xB0, +0x4A, 0x48, 0x21, 0x04, 0x18, 0xA3, 0x18, 0xC3, +0x41, 0xC7, 0x4A, 0x28, 0x73, 0x4C, 0x62, 0xCA, +0x64, 0x07, 0x64, 0x48, 0x53, 0x87, 0x3A, 0xA5, +0x5B, 0xA9, 0x53, 0x87, 0x6C, 0x28, 0x53, 0x85, +0x6C, 0x28, 0x42, 0xE4, 0x43, 0x44, 0x74, 0xAA, +0xA5, 0xF1, 0xC6, 0xF7, 0xA5, 0x71, 0x8C, 0xCF, +0x8C, 0xAF, 0x9C, 0xF0, 0xA5, 0x53, 0xB5, 0xD4, +0xB5, 0xB4, 0xA5, 0x53, 0x94, 0x90, 0x9C, 0xF2, +0xA5, 0x12, 0xB5, 0x94, 0xA4, 0xAF, 0xAC, 0xF0, +0xBD, 0x72, 0xD6, 0x56, 0xCE, 0x15, 0xE6, 0xF9, +0xD6, 0x97, 0xCE, 0x36, 0xB5, 0x74, 0xAD, 0x73, +0xAD, 0x53, 0xAD, 0x32, 0xAD, 0x32, 0xB5, 0x53, +0xAD, 0x53, 0xB5, 0x94, 0xB5, 0x94, 0xC5, 0xF5, +0xDE, 0xB7, 0xE6, 0xD8, 0xD6, 0x77, 0xCE, 0x58, +0xF7, 0x9D, 0xCE, 0x38, 0x4A, 0x48, 0x42, 0x07, +0x18, 0xC3, 0x08, 0x82, 0x08, 0x62, 0x08, 0x82, +0x08, 0x82, 0x08, 0x82, 0x08, 0x82, 0x10, 0xA3, +0x21, 0x25, 0x21, 0x66, 0x21, 0x47, 0x21, 0x67, +0x29, 0x88, 0x29, 0x88, 0x29, 0x87, 0x63, 0x2D, +0x52, 0x8A, 0x63, 0x0A, 0x8C, 0x4E, 0xA4, 0xB0, +0x94, 0x2D, 0x8C, 0x0C, 0xB5, 0x10, 0xC5, 0x71, +0xAC, 0xAE, 0x7B, 0x6A, 0x94, 0x4D, 0x94, 0x0C, +0x9C, 0x6E, 0x9C, 0x4E, 0x8B, 0xEC, 0x94, 0x2D, +0xAC, 0xCF, 0xB5, 0x10, 0xAC, 0xCF, 0xAC, 0xEF, +0xAC, 0x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 0x48, +0x73, 0x6C, 0xA4, 0xD1, 0xCE, 0x15, 0xCE, 0x16, +0xAD, 0x32, 0x9C, 0xB0, 0x94, 0x2E, 0x9C, 0x8F, +0x83, 0xEC, 0x73, 0x6A, 0xA4, 0xD0, 0xCE, 0x15, +0xC5, 0xF5, 0xBD, 0x93, 0xB5, 0x93, 0x9C, 0xB0, +0xB5, 0x52, 0xC5, 0xF4, 0xD6, 0x36, 0xCD, 0xF4, +0xD6, 0x15, 0xCD, 0xF4, 0xCD, 0xD3, 0xC5, 0x93, +0xB5, 0x52, 0xB5, 0x32, 0xAC, 0xF1, 0x8C, 0x0E, +0x73, 0x2C, 0x62, 0xEB, 0x52, 0x69, 0x31, 0x66, +0x20, 0xE4, 0x10, 0xA3, 0x10, 0xA3, 0x10, 0xA3, +0x10, 0xC4, 0x10, 0xC3, 0x10, 0xA3, 0x10, 0xA3, +0x10, 0x83, 0x08, 0x83, 0x08, 0x83, 0x08, 0x83, +0x08, 0x83, 0x08, 0x83, 0x08, 0x83, 0x10, 0xA3, +0x10, 0xA3, 0x10, 0xC3, 0x10, 0xC4, 0x10, 0xA3, +0x10, 0x83, 0x10, 0xA3, 0x10, 0xC4, 0x18, 0xC4, +0x18, 0xE4, 0x10, 0xC4, 0x10, 0xC3, 0x10, 0xC3, +0x10, 0xC4, 0x10, 0xA3, 0x10, 0xC4, 0x10, 0xC3, +0x10, 0xA3, 0x10, 0xA3, 0x10, 0xA3, 0x10, 0xA3, +0x18, 0xC4, 0x19, 0x04, 0x19, 0x05, 0x19, 0x05, +0x18, 0xE4, 0x18, 0xE5, 0x21, 0x05, 0x21, 0x05, +0x19, 0x05, 0x21, 0x05, 0x21, 0x05, 0x21, 0x05, +0x19, 0x05, 0x19, 0x05, 0x21, 0x05, 0x21, 0x05, +0x19, 0x05, 0x21, 0x05, 0x21, 0x26, 0x21, 0x26, +0x21, 0x26, 0x21, 0x26, 0x21, 0x26, 0x21, 0x26, +0x21, 0x26, 0x21, 0x26, 0x21, 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, 0xA4, 0x8E, 0xAC, 0xCF, +0xAC, 0xCF, 0xC5, 0x71, 0xBD, 0x31, 0xC5, 0x71, +0xCD, 0x92, 0xC5, 0x71, 0xBD, 0x51, 0xB5, 0x31, +0xAC, 0xD0, 0xA4, 0xAF, 0xB5, 0x11, 0xD6, 0x15, +0xBD, 0x72, 0xAC, 0xB0, 0x83, 0x8B, 0x8B, 0xED, +0xC5, 0xB4, 0x8C, 0x2E, 0x9C, 0xB0, 0x8C, 0x2E, +0x8C, 0x2F, 0x8C, 0x4F, 0xAD, 0x52, 0xA5, 0x12, +0xA5, 0x12, 0xAD, 0x32, 0xAD, 0x53, 0x6B, 0x4C, +0x41, 0xE7, 0x42, 0x07, 0x42, 0x07, 0x42, 0x07, +0x42, 0x28, 0x29, 0x65, 0x31, 0x85, 0x31, 0x85, +0x39, 0xC6, 0x41, 0xE7, 0x42, 0x28, 0x29, 0x45, +0x31, 0x65, 0x62, 0xCA, 0x8B, 0xEE, 0xB5, 0x74, +0xC5, 0xD5, 0xBD, 0xB4, 0x9C, 0xB0, 0x94, 0x4E, +0x9C, 0x8F, 0x9C, 0xB0, 0xB5, 0x53, 0xD6, 0x57, +0xCE, 0x56, 0xC5, 0xD4, 0xC5, 0xF5, 0xAD, 0x32, +0xAD, 0x52, 0xC5, 0xB4, 0xD6, 0x36, 0xD6, 0x35, +0xD6, 0x15, 0xD6, 0x15, 0xCD, 0xD4, 0xB5, 0x11, +0xB5, 0x52, 0xB5, 0x52, 0xBD, 0xB4, 0xBD, 0x93, +0xAC, 0xF1, 0xAC, 0xF1, 0xAC, 0xF1, 0x7B, 0xAD, +0x52, 0x69, 0x21, 0x04, 0x18, 0xC4, 0x10, 0xC3, +0x18, 0xC4, 0x10, 0xC3, 0x10, 0xA3, 0x10, 0xA3, +0x10, 0x83, 0x08, 0x83, 0x08, 0x83, 0x08, 0x83, +0x08, 0x83, 0x08, 0x83, 0x08, 0x83, 0x08, 0x83, +0x08, 0x83, 0x10, 0xA3, 0x10, 0xC4, 0x10, 0xC3, +0x10, 0xA3, 0x10, 0xA3, 0x10, 0xC3, 0x10, 0xC4, +0x10, 0xC4, 0x10, 0xC4, 0x10, 0xC3, 0x10, 0xC4, +0x10, 0xC3, 0x10, 0xA3, 0x10, 0xC4, 0x10, 0xC3, +0x10, 0xA3, 0x10, 0xA3, 0x10, 0xC4, 0x10, 0xC4, +0x10, 0xC4, 0x18, 0xE4, 0x18, 0xE5, 0x19, 0x05, +0x18, 0xE5, 0x19, 0x05, 0x19, 0x05, 0x19, 0x05, +0x18, 0xE5, 0x19, 0x05, 0x18, 0xE5, 0x18, 0xE5, +0x18, 0xE5, 0x18, 0xE5, 0x18, 0xE5, 0x21, 0x05, +0x21, 0x05, 0x21, 0x05, 0x21, 0x05, 0x21, 0x26, +0x21, 0x26, 0x21, 0x46, 0x29, 0x46, 0x29, 0x46, +0x21, 0x46, 0x21, 0x46, 0x21, 0x46, 0x29, 0x67, +0x29, 0x67, 0x21, 0x26, 0x29, 0x67, 0x31, 0x87, +0x29, 0x66, 0x21, 0x46, 0x39, 0xC9, 0x52, 0x8B, +0x63, 0x0C, 0xAD, 0x53, 0xD6, 0x77, 0xB5, 0x94, +0xB5, 0x73, 0xCE, 0x36, 0xCE, 0x36, 0xCE, 0x36, +0xC5, 0xF5, 0xBD, 0xD4, 0xBD, 0x94, 0xBD, 0xB4, +0xD6, 0x56, 0xB5, 0x53, 0xB5, 0x73, 0xBD, 0x94, +0xBD, 0xB4, 0xA4, 0xD1, 0xB5, 0x73, 0xB5, 0x32, +0xB5, 0x73, 0xAD, 0x12, 0xAD, 0x12, 0xAD, 0x11, +0xAD, 0x12, 0xB5, 0x53, 0xAD, 0x12, 0xB5, 0x73, +0x6B, 0x2C, 0x29, 0x46, 0x18, 0xC3, 0x10, 0xA2, +0x21, 0x04, 0x4A, 0x08, 0x5A, 0xA9, 0x62, 0xEA, +0x74, 0x8A, 0x53, 0xA6, 0x5B, 0xE7, 0x53, 0xA8, +0x3A, 0xC5, 0x43, 0x05, 0x43, 0x04, 0x53, 0x65, +0x43, 0x24, 0x7C, 0xEB, 0x53, 0xC6, 0x4B, 0x44, +0x6C, 0x29, 0x8D, 0x0E, 0x6B, 0xEA, 0x5B, 0x67, +0xAD, 0xF2, 0xBE, 0x76, 0xA5, 0x53, 0x84, 0x0F, +0x94, 0xB1, 0x94, 0xB1, 0x8C, 0x71, 0x9C, 0xD2, +0x9C, 0xF2, 0xA5, 0x13, 0x94, 0x90, 0x9C, 0xB0, +0xA4, 0xF1, 0xA4, 0xF2, 0x94, 0xB1, 0x94, 0x91, +0x8C, 0x50, 0x84, 0x0F, 0x7B, 0xEF, 0x7B, 0xCF, +0x73, 0x8E, 0x6B, 0x4D, 0x63, 0x2E, 0x63, 0x2E, +0x63, 0x2E, 0x63, 0x2E, 0x6B, 0x4E, 0x63, 0x0E, +0x52, 0xAC, 0x4A, 0x6B, 0x42, 0x2A, 0x41, 0xE9, +0x39, 0xC8, 0x29, 0x67, 0x29, 0x46, 0x21, 0x04, +0x18, 0xE4, 0x18, 0xE4, 0x10, 0xC3, 0x10, 0xA3, +0x10, 0xA3, 0x10, 0xA3, 0x10, 0xA3, 0x08, 0x83, +0x08, 0x83, 0x21, 0x25, 0x29, 0x46, 0x31, 0xC8, +0x31, 0xA8, 0x29, 0x67, 0x21, 0x46, 0x21, 0x46, +0x4A, 0x6B, 0xBE, 0x18, 0xDE, 0xFC, 0x94, 0xB2, +0x94, 0x50, 0xBD, 0xB4, 0xBD, 0x71, 0xC5, 0x92, +0xB5, 0x31, 0xC5, 0xD4, 0xC6, 0x16, 0xC5, 0xF5, +0xB5, 0x73, 0xBD, 0xB4, 0xC6, 0x16, 0xCE, 0x36, +0xC5, 0xF5, 0xB5, 0x94, 0xBD, 0x94, 0xC6, 0x16, +0xB5, 0x73, 0xBD, 0xB4, 0xBD, 0xB4, 0xBD, 0xD4, +0xB5, 0x73, 0xAD, 0x52, 0xB5, 0x94, 0xAD, 0x32, +0xAD, 0x32, 0xB5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0xD6, 0x56, 0xD6, 0x56, 0xCE, 0x56, +0xCE, 0x35, 0xCE, 0x15, 0xBD, 0xB4, 0xAD, 0x32, +0xC5, 0xD4, 0xCE, 0x15, 0xD6, 0x56, 0xD6, 0x76, +0xD6, 0x35, 0xD6, 0x15, 0xC5, 0xB3, 0x94, 0x0D, +0xBD, 0x73, 0xBD, 0x72, 0xA4, 0xD0, 0xC5, 0xD4, +0xC5, 0xB4, 0xC5, 0xB4, 0xC5, 0xB3, 0xCD, 0xD4, +0x94, 0x2F, 0x6B, 0x0B, 0x52, 0x89, 0x18, 0xE4, +0x18, 0xC4, 0x10, 0xC3, 0x10, 0xA3, 0x10, 0xA3, +0x10, 0xA3, 0x08, 0x83, 0x08, 0x83, 0x08, 0x83, +0x08, 0x83, 0x08, 0x83, 0x08, 0x83, 0x08, 0x83, +0x08, 0x83, 0x10, 0x83, 0x10, 0xA3, 0x10, 0xC4, +0x10, 0xA3, 0x10, 0xA3, 0x10, 0xC3, 0x10, 0xC4, +0x10, 0xC4, 0x18, 0xC4, 0x10, 0xC4, 0x10, 0xC3, +0x10, 0xA3, 0x10, 0xA3, 0x10, 0xA3, 0x10, 0xA3, +0x10, 0xC3, 0x10, 0xC4, 0x18, 0xE4, 0x18, 0xE4, +0x18, 0xC4, 0x18, 0xC4, 0x18, 0xE4, 0x19, 0x05, +0x18, 0xC4, 0x18, 0xE4, 0x18, 0xE5, 0x18, 0xE5, +0x18, 0xE5, 0x18, 0xE5, 0x18, 0xE5, 0x18, 0xE4, +0x18, 0xE4, 0x18, 0xE4, 0x18, 0xE5, 0x21, 0x05, +0x19, 0x05, 0x19, 0x05, 0x19, 0x05, 0x19, 0x05, +0x21, 0x25, 0x21, 0x26, 0x21, 0x46, 0x29, 0x66, +0x21, 0x46, 0x29, 0x67, 0x29, 0x46, 0x29, 0x46, +0x21, 0x46, 0x19, 0x05, 0x21, 0x05, 0x21, 0x26, +0x21, 0x46, 0x19, 0x05, 0x29, 0x66, 0x39, 0xE8, +0x4A, 0x6A, 0x6B, 0x4D, 0x94, 0x90, 0x94, 0x70, +0xD6, 0x77, 0xDE, 0xB8, 0xCE, 0x56, 0xD6, 0x97, +0xD6, 0x77, 0xD6, 0x57, 0xCE, 0x36, 0xD6, 0x56, +0xD6, 0x77, 0xD6, 0x56, 0xD6, 0x76, 0xD6, 0x97, +0xD6, 0x77, 0x9C, 0x90, 0x8C, 0x0E, 0xAD, 0x32, +0xC5, 0xF5, 0xBD, 0x93, 0xB5, 0x73, 0xBD, 0xB4, +0xB5, 0x73, 0xAD, 0x32, 0xB5, 0x73, 0xBD, 0x93, +0x9C, 0xB1, 0x31, 0xA6, 0x18, 0xC4, 0x10, 0xA3, +0x18, 0xC3, 0x4A, 0x49, 0x4A, 0x28, 0x4A, 0x28, +0x64, 0x28, 0x5B, 0xE8, 0x4B, 0x45, 0x4B, 0x46, +0x3A, 0xE5, 0x43, 0x25, 0x3A, 0xE3, 0x3A, 0xE3, +0x3A, 0xE4, 0x5B, 0xC7, 0x3A, 0xC3, 0x43, 0x24, +0x53, 0x85, 0x5B, 0x86, 0x5B, 0x87, 0x84, 0x8C, +0xA5, 0x71, 0xA5, 0x52, 0x94, 0xB0, 0x31, 0x86, +0x39, 0xC8, 0x39, 0xE8, 0x3A, 0x09, 0x42, 0x09, +0x42, 0x29, 0x42, 0x4A, 0x4A, 0x4A, 0x4A, 0x6B, +0x52, 0x8B, 0x4A, 0x8B, 0x4A, 0x8B, 0x52, 0xAB, +0x52, 0xAC, 0x5B, 0x0D, 0x63, 0x2E, 0x63, 0x2D, +0x63, 0x4E, 0x73, 0xB0, 0x73, 0x90, 0x73, 0x90, +0x73, 0x8F, 0x6B, 0x4E, 0x6B, 0x4E, 0x6B, 0x4E, +0x73, 0x8E, 0x6B, 0x4D, 0x4A, 0x6B, 0x52, 0xAB, +0x42, 0x09, 0x21, 0x26, 0x18, 0xE4, 0x19, 0x04, +0x18, 0xC4, 0x10, 0xC3, 0x10, 0xA3, 0x10, 0xA3, +0x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 0x10, 0xC4, 0x10, 0xA3, +0x10, 0xC3, 0x10, 0xC3, 0x10, 0xC4, 0x18, 0xC4, +0x18, 0xC4, 0x10, 0xC3, 0x18, 0xE4, 0x18, 0xE4, +0x18, 0xE4, 0x18, 0xE4, 0x18, 0xE4, 0x19, 0x05, +0x18, 0xE4, 0x18, 0xE4, 0x18, 0xE4, 0x18, 0xE4, +0x18, 0xE4, 0x18, 0xE4, 0x18, 0xE4, 0x18, 0xE4, +0x18, 0xE4, 0x18, 0xE4, 0x18, 0xE4, 0x19, 0x05, +0x21, 0x05, 0x21, 0x05, 0x21, 0x05, 0x19, 0x05, +0x19, 0x05, 0x21, 0x05, 0x21, 0x26, 0x29, 0x67, +0x21, 0x46, 0x29, 0x67, 0x29, 0x67, 0x21, 0x46, +0x21, 0x05, 0x19, 0x05, 0x18, 0xE5, 0x18, 0xE5, +0x21, 0x26, 0x19, 0x05, 0x21, 0x26, 0x31, 0x87, +0x39, 0xC8, 0x52, 0x8A, 0x7B, 0xAE, 0x94, 0x91, +0xD6, 0x78, 0xDE, 0xD8, 0xD6, 0x97, 0xD6, 0x77, +0xD6, 0x97, 0xD6, 0x97, 0xDE, 0xB8, 0xDE, 0xB7, +0xD6, 0x56, 0xCE, 0x56, 0xD6, 0x76, 0xDE, 0xB7, +0xCE, 0x35, 0x9C, 0xB0, 0xAD, 0x32, 0xBD, 0xD4, +0xCE, 0x15, 0xBD, 0x93, 0xBD, 0x93, 0xBD, 0x93, +0xBD, 0x93, 0xB5, 0x73, 0xB5, 0x52, 0xBD, 0x93, +0xBD, 0xD4, 0x5A, 0xA9, 0x21, 0x04, 0x18, 0xA3, +0x10, 0x82, 0x41, 0xE7, 0x4A, 0x28, 0x41, 0xE7, +0x53, 0x86, 0x53, 0x86, 0x43, 0x05, 0x42, 0xE5, +0x4B, 0x67, 0x43, 0x05, 0x5B, 0xC7, 0x53, 0x86, +0x4B, 0x86, 0x4B, 0x86, 0x53, 0x85, 0x5B, 0xC7, +0x63, 0x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, 0xF5, +0xCD, 0xF5, 0xC5, 0xB4, 0xBD, 0xB4, 0xBD, 0xB3, +0xC5, 0xB4, 0xC5, 0xB4, 0xCD, 0xD4, 0xCD, 0xD5, +0xCD, 0xF5, 0xCD, 0xD4, 0xC5, 0xB4, 0xC5, 0xB3, +0xB5, 0x32, 0xB5, 0x32, 0xBD, 0x32, 0xB5, 0x11, +0xAC, 0xF0, 0xAC, 0xF1, 0x41, 0xC6, 0x10, 0xC3, +0x10, 0xA3, 0x18, 0xE4, 0x18, 0xE4, 0x18, 0xC4, +0x10, 0xA3, 0x10, 0x83, 0x08, 0x83, 0x08, 0x83, +0x08, 0x83, 0x08, 0x83, 0x08, 0x83, 0x08, 0x82, +0x08, 0x82, 0x08, 0x82, 0x08, 0x83, 0x10, 0xA3, +0x10, 0xA3, 0x10, 0xA3, 0x18, 0xC4, 0x18, 0xE4, +0x18, 0xE4, 0x18, 0xE4, 0x10, 0xC4, 0x10, 0xA3, +0x10, 0xC4, 0x10, 0xC4, 0x18, 0xE4, 0x18, 0xE4, +0x18, 0xC4, 0x10, 0xC4, 0x18, 0xE4, 0x18, 0xE4, +0x18, 0xE4, 0x18, 0xE4, 0x18, 0xE4, 0x19, 0x04, +0x18, 0xE4, 0x18, 0xE4, 0x18, 0xE4, 0x18, 0xE4, +0x18, 0xE4, 0x18, 0xE4, 0x19, 0x04, 0x18, 0xE4, +0x18, 0xE4, 0x18, 0xE4, 0x18, 0xE4, 0x19, 0x05, +0x21, 0x05, 0x21, 0x05, 0x21, 0x05, 0x21, 0x26, +0x19, 0x05, 0x21, 0x05, 0x21, 0x46, 0x29, 0x67, +0x21, 0x26, 0x29, 0x46, 0x29, 0x67, 0x21, 0x26, +0x18, 0xE5, 0x18, 0xE4, 0x10, 0xC3, 0x18, 0xC4, +0x21, 0x25, 0x21, 0x26, 0x21, 0x26, 0x29, 0x67, +0x31, 0xA8, 0x52, 0x8B, 0x94, 0xB2, 0xBD, 0xB5, +0x8C, 0x2F, 0xC5, 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D, +0x7B, 0xCD, 0x6B, 0x4B, 0x7B, 0xAD, 0x8C, 0x2E, +0x8C, 0x2E, 0x73, 0x4B, 0x73, 0x8C, 0xAD, 0x32, +0xAD, 0x32, 0xBD, 0x94, 0xCE, 0x15, 0xCD, 0xF5, +0xC5, 0xF5, 0xB5, 0x74, 0xAD, 0x12, 0xAD, 0x32, +0xC5, 0xD5, 0x94, 0x4F, 0x31, 0x65, 0x4A, 0x68, +0x39, 0xC6, 0x39, 0xC6, 0x52, 0x89, 0x5A, 0xEB, +0x42, 0x28, 0x52, 0x89, 0x39, 0xE7, 0x52, 0xAA, +0x84, 0x30, 0xCE, 0x79, 0x9C, 0xB3, 0x73, 0x0C, +0x8B, 0xCE, 0x94, 0x2F, 0x9C, 0x50, 0x9C, 0x90, +0x8C, 0x2E, 0x9C, 0x8F, 0x9C, 0x90, 0x9C, 0x90, +0xAD, 0x12, 0xA4, 0xF1, 0xA4, 0xD0, 0x8B, 0xED, +0xAD, 0x32, 0xB5, 0x33, 0xB5, 0x32, 0x9C, 0xAF, +0x94, 0x4E, 0x8C, 0x2E, 0x94, 0x6F, 0x94, 0x6F, +0x9C, 0x4F, 0x9C, 0x6F, 0xAC, 0xF0, 0xB5, 0x31, +0xAC, 0xF1, 0xBD, 0x73, 0xBD, 0x73, 0xD6, 0x15, +0xCD, 0xD4, 0x9C, 0x90, 0x39, 0x85, 0x18, 0xC3, +0x10, 0xC3, 0x10, 0xC3, 0x18, 0xC4, 0x19, 0x05, +0x18, 0xE4, 0x10, 0x83, 0x10, 0x83, 0x08, 0x83, +0x08, 0x83, 0x08, 0x83, 0x08, 0x83, 0x08, 0x83, +0x10, 0x83, 0x10, 0x83, 0x08, 0x83, 0x10, 0xA3, +0x10, 0xA3, 0x10, 0xA3, 0x10, 0xA3, 0x18, 0xE4, +0x19, 0x04, 0x18, 0xE4, 0x10, 0xC4, 0x10, 0xC3, +0x10, 0xC4, 0x10, 0xC4, 0x18, 0xE4, 0x10, 0xC4, +0x18, 0xE4, 0x18, 0xC4, 0x10, 0xA3, 0x18, 0xE4, +0x18, 0xE4, 0x18, 0xE4, 0x18, 0xE4, 0x18, 0xE4, +0x18, 0xE4, 0x19, 0x05, 0x18, 0xE4, 0x18, 0xE4, +0x18, 0xE4, 0x18, 0xE4, 0x19, 0x04, 0x19, 0x05, +0x18, 0xE4, 0x18, 0xC4, 0x18, 0xE4, 0x18, 0xE4, +0x19, 0x05, 0x21, 0x26, 0x21, 0x25, 0x21, 0x26, +0x19, 0x05, 0x21, 0x25, 0x21, 0x26, 0x21, 0x46, +0x21, 0x26, 0x21, 0x46, 0x21, 0x26, 0x21, 0x05, +0x18, 0xE4, 0x18, 0xC4, 0x10, 0xA4, 0x18, 0xE4, +0x21, 0x05, 0x21, 0x26, 0x21, 0x26, 0x21, 0x46, +0x31, 0x87, 0x4A, 0x4A, 0xA5, 0x34, 0xB5, 0x95, +0x8C, 0x2F, 0xDE, 0xB9, 0xDE, 0xB8, 0xDE, 0x97, +0xE6, 0xF9, 0xBD, 0xB4, 0xC6, 0x15, 0xD6, 0x97, +0xD6, 0x77, 0xD6, 0x77, 0xD6, 0x76, 0xD6, 0x76, +0xD6, 0x96, 0xBD, 0xB4, 0xAD, 0x32, 0xB5, 0x52, +0xCE, 0x36, 0xC5, 0xF4, 0xC5, 0xF4, 0xCE, 0x15, +0xCE, 0x15, 0xBD, 0x93, 0xCE, 0x35, 0xCE, 0x14, +0xC5, 0xF4, 0xA4, 0xF1, 0x5A, 0xCB, 0x20, 0xE4, +0x18, 0xC3, 0x21, 0x04, 0x4A, 0x28, 0x41, 0xC6, +0x74, 0x8B, 0x74, 0x69, 0x74, 0x6A, 0x64, 0x08, +0x53, 0xA6, 0x64, 0x28, 0x4B, 0x45, 0x4B, 0x45, +0x32, 0x62, 0x63, 0xC9, 0x74, 0x2B, 0x53, 0x28, +0x52, 0xE8, 0x6B, 0xAB, 0x53, 0x07, 0x4A, 0xE6, +0x6B, 0xAA, 0x73, 0x89, 0x9C, 0x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F, +0x9C, 0x8F, 0x9C, 0x8F, 0xAD, 0x32, 0xA4, 0xF1, +0xA4, 0xF1, 0xA4, 0xD0, 0xA4, 0xD0, 0xA5, 0x10, +0x9C, 0xAF, 0xC5, 0xB4, 0xB5, 0x32, 0xC5, 0x93, +0xBD, 0x93, 0x9C, 0x6F, 0x39, 0x86, 0x18, 0xC3, +0x10, 0xA3, 0x10, 0xA3, 0x18, 0xC3, 0x21, 0x25, +0x18, 0xE4, 0x10, 0xA3, 0x10, 0xA3, 0x08, 0x83, +0x10, 0x83, 0x10, 0x83, 0x10, 0x83, 0x08, 0x83, +0x10, 0x83, 0x08, 0x83, 0x10, 0xA3, 0x10, 0xC4, +0x18, 0xC4, 0x10, 0xA3, 0x10, 0x83, 0x10, 0xA3, +0x18, 0xE4, 0x18, 0xC4, 0x10, 0xC4, 0x10, 0xC4, +0x10, 0xC4, 0x10, 0xC4, 0x18, 0xE4, 0x10, 0xC4, +0x18, 0xE4, 0x18, 0xE4, 0x10, 0xA3, 0x18, 0xC4, +0x18, 0xE4, 0x18, 0xC4, 0x18, 0xC4, 0x18, 0xE4, +0x18, 0xE4, 0x18, 0xE4, 0x18, 0xE4, 0x19, 0x04, +0x18, 0xE4, 0x18, 0xE4, 0x18, 0xE4, 0x19, 0x05, +0x18, 0xE4, 0x18, 0xC4, 0x10, 0xC4, 0x18, 0xC4, +0x18, 0xE4, 0x21, 0x05, 0x21, 0x25, 0x19, 0x05, +0x19, 0x05, 0x21, 0x05, 0x21, 0x26, 0x21, 0x26, +0x21, 0x26, 0x21, 0x46, 0x21, 0x26, 0x18, 0xE5, +0x18, 0xE4, 0x18, 0xE4, 0x18, 0xE5, 0x19, 0x05, +0x21, 0x25, 0x21, 0x26, 0x21, 0x26, 0x21, 0x26, +0x29, 0x87, 0x31, 0xA8, 0x94, 0xB2, 0xA5, 0x12, +0x8C, 0x2F, 0xE6, 0xFA, 0xD6, 0x97, 0xDE, 0xD8, +0xDE, 0xB8, 0x83, 0xCE, 0x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, 0xC4, +0x18, 0xE4, 0x18, 0xC4, 0x18, 0xC4, 0x18, 0xE4, +0x18, 0xE4, 0x18, 0xE4, 0x19, 0x05, 0x21, 0x05, +0x19, 0x05, 0x18, 0xE4, 0x19, 0x05, 0x19, 0x05, +0x19, 0x05, 0x18, 0xE4, 0x10, 0xC4, 0x10, 0xC4, +0x10, 0xC4, 0x19, 0x05, 0x21, 0x05, 0x18, 0xE5, +0x18, 0xC4, 0x19, 0x05, 0x21, 0x05, 0x18, 0xE5, +0x19, 0x05, 0x21, 0x26, 0x21, 0x25, 0x18, 0xE4, +0x18, 0xE5, 0x18, 0xE5, 0x19, 0x05, 0x19, 0x05, +0x21, 0x05, 0x21, 0x26, 0x21, 0x26, 0x21, 0x46, +0x31, 0x87, 0x31, 0x87, 0x5A, 0xCB, 0x9C, 0xD2, +0xBD, 0x94, 0xD6, 0x77, 0xD6, 0x77, 0xD6, 0x98, +0xD6, 0x78, 0x8C, 0x30, 0xE7, 0x1A, 0xDE, 0xD8, +0xD6, 0x77, 0xCE, 0x15, 0xC5, 0xF4, 0xDE, 0x96, +0xE6, 0xF8, 0xAD, 0x11, 0xA4, 0xB0, 0xDE, 0x96, +0xE6, 0xB6, 0xDE, 0x96, 0xD6, 0x55, 0xDE, 0x76, +0xD6, 0x75, 0xC5, 0xD3, 0xD6, 0x35, 0xD6, 0x55, +0xCE, 0x14, 0xD6, 0x35, 0xDE, 0xB7, 0x83, 0xEE, +0x20, 0xE4, 0x10, 0xA3, 0x29, 0x24, 0x41, 0xE7, +0x53, 0x69, 0x5B, 0x89, 0x74, 0x2B, 0x63, 0xA9, +0x42, 0xC4, 0x42, 0xA3, 0x3A, 0x64, 0x3A, 0x85, +0x5B, 0x69, 0x5B, 0x29, 0x3A, 0x66, 0x42, 0xA7, +0x9D, 0x52, 0x74, 0x0C, 0x3A, 0xA3, 0x4B, 0x64, +0x53, 0xA4, 0x6C, 0x26, 0x9D, 0x8C, 0xBE, 0x30, +0xBD, 0xD2, 0xC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 0x8C, 0x2E, 0x94, 0x90, 0x8C, 0x4E, +0x94, 0x6F, 0x94, 0x6F, 0x9C, 0xB0, 0x9C, 0xB0, +0x9C, 0xB0, 0xBD, 0x73, 0xB5, 0x52, 0xCD, 0xF5, +0xC5, 0xD4, 0xB5, 0x33, 0x4A, 0x08, 0x18, 0xA3, +0x10, 0x83, 0x10, 0x83, 0x18, 0xC4, 0x21, 0x45, +0x19, 0x04, 0x10, 0xC3, 0x10, 0xA3, 0x10, 0xA3, +0x10, 0xA3, 0x10, 0xA3, 0x08, 0x83, 0x08, 0x83, +0x21, 0x05, 0x73, 0xAE, 0x94, 0x91, 0x9C, 0xB1, +0x9C, 0xD1, 0x8C, 0x2F, 0x63, 0x0B, 0x6B, 0x4C, +0x4A, 0x48, 0x19, 0x04, 0x10, 0xC3, 0x18, 0xC4, +0x18, 0xC4, 0x18, 0xC4, 0x10, 0xC4, 0x10, 0xC4, +0x10, 0xC4, 0x18, 0xE4, 0x18, 0xC4, 0x18, 0xC4, +0x18, 0xE4, 0x18, 0xE4, 0x18, 0xE4, 0x18, 0xE4, +0x18, 0xE4, 0x18, 0xE4, 0x18, 0xE5, 0x19, 0x05, +0x19, 0x05, 0x18, 0xE5, 0x18, 0xE5, 0x19, 0x05, +0x19, 0x05, 0x19, 0x05, 0x19, 0x05, 0x19, 0x05, +0x18, 0xE5, 0x18, 0xE5, 0x21, 0x05, 0x18, 0xE5, +0x18, 0xC4, 0x18, 0xE5, 0x18, 0xE5, 0x18, 0xC4, +0x10, 0xC4, 0x19, 0x05, 0x19, 0x05, 0x18, 0xE4, +0x19, 0x05, 0x19, 0x05, 0x18, 0xE5, 0x21, 0x05, +0x19, 0x05, 0x21, 0x05, 0x21, 0x05, 0x29, 0x46, +0x31, 0xA8, 0x29, 0x87, 0x39, 0xE8, 0x73, 0x6D, +0x94, 0x70, 0x9C, 0x90, 0x9C, 0x90, 0x9C, 0xB1, +0x9C, 0x90, 0x8C, 0x2F, 0x9C, 0x90, 0x9C,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4, +0x18, 0xC4, 0x18, 0xE4, 0x18, 0xE4, 0x18, 0xE5, +0x18, 0xE4, 0x18, 0xE4, 0x18, 0xE4, 0x19, 0x04, +0x19, 0x05, 0x18, 0xE4, 0x18, 0xE4, 0x18, 0xE5, +0x18, 0xE5, 0x19, 0x05, 0x19, 0x05, 0x19, 0x05, +0x21, 0x25, 0x21, 0x05, 0x19, 0x05, 0x19, 0x05, +0x18, 0xE5, 0x18, 0xE5, 0x18, 0xE5, 0x18, 0xE4, +0x10, 0xA4, 0x10, 0xC4, 0x18, 0xE4, 0x18, 0xC4, +0x18, 0xE5, 0x19, 0x05, 0x19, 0x05, 0x21, 0x25, +0x19, 0x05, 0x19, 0x05, 0x19, 0x05, 0x29, 0x46, +0x31, 0xA8, 0x29, 0x66, 0x31, 0x87, 0x5A, 0xCC, +0x94, 0x50, 0xCE, 0x16, 0xCD, 0xF5, 0xD6, 0x15, +0xCD, 0xF5, 0xC5, 0xB4, 0xBD, 0x73, 0xB5, 0x53, +0xC5, 0xB4, 0x94, 0x4F, 0xA4, 0xB0, 0xA4, 0xB0, +0x94, 0x4E, 0x9C, 0x8F, 0xB5, 0x32, 0x9C, 0x8F, +0xAC, 0xF1, 0xC5, 0x92, 0xC5, 0x93, 0xA4, 0xB0, +0xA4, 0xB0, 0xA4, 0xD0, 0x9C, 0x8F, 0x9C, 0x8F, +0x94, 0x2E, 0x9C, 0x8F, 0xA4, 0xD0, 0xA5, 0x11, +0x9C, 0xB0, 0x63, 0x2B, 0x18, 0xA2, 0x39, 0xA6, +0x8D, 0x10, 0x8C, 0xEF, 0x63, 0xCA, 0x53, 0x48, +0x53, 0x27, 0x5B, 0x67, 0x53, 0x06, 0x42, 0xC6, +0x63, 0xC9, 0x7C, 0x8D, 0xAD, 0xD3, 0x8C, 0xD0, +0xB5, 0xB4, 0x84, 0x6C, 0x43, 0x03, 0x4B, 0x63, +0x6C, 0x27, 0x84, 0x89, 0x94, 0xAC, 0xA5, 0x0F, +0x94, 0x8E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xAD, 0x73, 0xBD, 0xD5, 0xB5, 0x94, +0xB5, 0x73, 0xAD, 0x32, 0xB5, 0x73, 0xBD, 0xB4, +0xA4, 0xF1, 0xBD, 0x94, 0xB5, 0x53, 0xDE, 0x97, +0xCE, 0x36, 0xC5, 0xF5, 0x62, 0xEA, 0x18, 0xC3, +0x10, 0x83, 0x10, 0x83, 0x10, 0xC3, 0x29, 0x66, +0x21, 0x25, 0x18, 0xE4, 0x18, 0xE4, 0x18, 0xC3, +0x10, 0xA3, 0x10, 0x83, 0x10, 0xA3, 0x5A, 0xAA, +0xBD, 0xB4, 0xC5, 0xF5, 0xC5, 0xD5, 0xC5, 0xD4, +0xBD, 0xB4, 0xA4, 0xF1, 0xAD, 0x32, 0xC6, 0x15, +0xC5, 0xF5, 0xA4, 0xF2, 0x29, 0x65, 0x18, 0xC4, +0x18, 0xE4, 0x18, 0xC4, 0x10, 0xC4, 0x10, 0xC4, +0x10, 0xC4, 0x10, 0xC3, 0x10, 0xC4, 0x18, 0xC4, +0x18, 0xE4, 0x18, 0xE4, 0x19, 0x05, 0x19, 0x05, +0x19, 0x05, 0x18, 0xE4, 0x18, 0xE4, 0x18, 0xE4, +0x18, 0xE4, 0x18, 0xE4, 0x18, 0xE4, 0x18, 0xC4, +0x18, 0xE4, 0x19, 0x05, 0x19, 0x05, 0x18, 0xE5, +0x18, 0xE5, 0x19, 0x05, 0x19, 0x05, 0x21, 0x05, +0x21, 0x05, 0x21, 0x05, 0x19, 0x05, 0x18, 0xE4, +0x10, 0xC4, 0x10, 0xC4, 0x10, 0xC4, 0x18, 0xC4, +0x18, 0xE5, 0x21, 0x05, 0x19, 0x05, 0x21, 0x26, +0x19, 0x05, 0x19, 0x05, 0x21, 0x26, 0x29, 0x46, +0x31, 0xA8, 0x29, 0x46, 0x21, 0x25, 0x42, 0x29, +0x7B, 0xAE, 0xCD, 0xF5, 0xD6, 0x35, 0xD5, 0xF5, +0xD5, 0xF4, 0xD6, 0x14, 0xC5, 0xB3, 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10, 0xC4, 0x10, 0xC4, +0x18, 0xE4, 0x18, 0xE4, 0x18, 0xE5, 0x19, 0x05, +0x19, 0x05, 0x19, 0x05, 0x19, 0x05, 0x18, 0xE5, +0x18, 0xE4, 0x18, 0xE4, 0x18, 0xE4, 0x18, 0xC4, +0x18, 0xC4, 0x18, 0xE4, 0x19, 0x05, 0x18, 0xE4, +0x18, 0xE4, 0x18, 0xE4, 0x18, 0xE4, 0x19, 0x05, +0x19, 0x05, 0x18, 0xE5, 0x19, 0x05, 0x18, 0xE4, +0x18, 0xC4, 0x10, 0xA4, 0x10, 0xA3, 0x18, 0xE4, +0x19, 0x05, 0x21, 0x26, 0x18, 0xE5, 0x21, 0x05, +0x19, 0x05, 0x19, 0x05, 0x29, 0x46, 0x29, 0x46, +0x31, 0x87, 0x29, 0x67, 0x21, 0x46, 0x31, 0x87, +0x5A, 0xCC, 0xB5, 0x32, 0xE6, 0x76, 0xDE, 0x35, +0xDE, 0x35, 0xDE, 0x35, 0xD6, 0x14, 0xDE, 0x35, +0xDE, 0x35, 0xBD, 0x52, 0xC5, 0xB3, 0xCD, 0xD4, +0xCD, 0xB3, 0xD5, 0xF3, 0xCD, 0xB3, 0xD5, 0xD3, +0xDE, 0x14, 0xDE, 0x34, 0xDE, 0x34, 0xA4, 0x8F, +0xAC, 0xF1, 0xB5, 0x73, 0xBD, 0xB4, 0xBD, 0xD5, +0xBD, 0xB4, 0xB5, 0x73, 0xB5, 0x53, 0xAD, 0x32, +0xAD, 0x32, 0x8C, 0x4F, 0x21, 0x04, 0x10, 0xA2, +0x3A, 0x85, 0x53, 0x88, 0x4B, 0x07, 0x4A, 0xE7, +0x4A, 0xE7, 0x4A, 0x86, 0x5B, 0x08, 0x5B, 0x28, +0x74, 0x0B, 0x7C, 0x6D, 0x8C, 0xAE, 0xA5, 0x30, +0x5B, 0x28, 0x8C, 0xCD, 0x8C, 0xED, 0xC6, 0xD6, +0xD7, 0x39, 0xAD, 0x93, 0x94, 0x8D, 0xAD,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A4, 0xB0, 0xA4, 0xD0, 0x94, 0x6F, +0xA4, 0xB0, 0x9C, 0xB0, 0x9C, 0x90, 0x9C, 0xD0, +0xAD, 0x32, 0xB5, 0x73, 0xAD, 0x11, 0xC5, 0xF5, +0xCE, 0x36, 0xCE, 0x15, 0x6B, 0x2B, 0x18, 0xA3, +0x10, 0x83, 0x10, 0x83, 0x18, 0xC3, 0x29, 0x86, +0x19, 0x04, 0x19, 0x05, 0x18, 0xE4, 0x18, 0xE4, +0x10, 0xC3, 0x18, 0xC3, 0x41, 0xE7, 0xAD, 0x53, +0xCE, 0x35, 0xD6, 0x76, 0xD6, 0x56, 0xCE, 0x36, +0xBD, 0xB3, 0xB5, 0x52, 0xAD, 0x11, 0xCE, 0x35, +0xB5, 0x73, 0xD6, 0x56, 0xBD, 0x94, 0x5A, 0xCA, +0x18, 0xE4, 0x10, 0xC4, 0x18, 0xE4, 0x18, 0xC4, +0x18, 0xE4, 0x18, 0xE4, 0x18, 0xE4, 0x18, 0xE4, +0x19, 0x05, 0x18, 0xE4, 0x18, 0xE5, 0x18, 0xE4, +0x19, 0x05, 0x19, 0x05, 0x19, 0x05, 0x19, 0x05, +0x19, 0x05, 0x19, 0x05, 0x19, 0x05, 0x18, 0xE4, +0x10, 0xC4, 0x18, 0xE4, 0x18, 0xE5, 0x18, 0xE5, +0x18, 0xE4, 0x18, 0xE4, 0x18, 0xE4, 0x19, 0x04, +0x18, 0xE4, 0x18, 0xE4, 0x18, 0xE4, 0x18, 0xC4, +0x10, 0xA3, 0x10, 0xA3, 0x10, 0xA3, 0x18, 0xE4, +0x19, 0x05, 0x21, 0x05, 0x18, 0xE5, 0x19, 0x05, +0x19, 0x05, 0x21, 0x05, 0x29, 0x46, 0x29, 0x46, +0x31, 0x87, 0x29, 0x87, 0x29, 0x87, 0x21, 0x46, +0x4A, 0x4A, 0x7B, 0xAE, 0xE6, 0x97, 0xEE, 0xD7, +0xE6, 0x96, 0xE6, 0x75, 0xE6, 0x75, 0xE6,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0x04, +0x19, 0x05, 0x19, 0x05, 0x19, 0x05, 0x18, 0xE5, +0x18, 0xE4, 0x18, 0xE5, 0x19, 0x05, 0x19, 0x05, +0x19, 0x05, 0x19, 0x05, 0x19, 0x05, 0x18, 0xE4, +0x10, 0xC4, 0x18, 0xE4, 0x18, 0xE4, 0x18, 0xE4, +0x19, 0x05, 0x18, 0xE5, 0x18, 0xE5, 0x19, 0x05, +0x18, 0xE5, 0x10, 0xA3, 0x10, 0xC4, 0x10, 0xA4, +0x10, 0x83, 0x08, 0x83, 0x10, 0xA4, 0x18, 0xE4, +0x18, 0xE5, 0x19, 0x05, 0x19, 0x05, 0x21, 0x05, +0x19, 0x05, 0x19, 0x05, 0x21, 0x26, 0x29, 0x46, +0x31, 0x87, 0x31, 0x87, 0x31, 0xA8, 0x31, 0xC8, +0x39, 0xE8, 0x4A, 0x4A, 0x8C, 0x30, 0xD6, 0x56, +0xEE, 0xD7, 0xEE, 0xD6, 0xE6, 0x95, 0xEE, 0x96, +0xE6, 0x55, 0xDE, 0x55, 0xCD, 0xF3, 0xDE, 0x54, +0xEE, 0x95, 0xEE, 0x95, 0xEE, 0xB6, 0xEE, 0x96, +0xE6, 0x75, 0xE6, 0x55, 0xDE, 0x14, 0xAC, 0xD0, +0xA4, 0xF1, 0xB5, 0x73, 0xC5, 0xD4, 0xBD, 0xB4, +0xCE, 0x16, 0xB5, 0x73, 0xB5, 0x73, 0xB5, 0x73, +0xB5, 0x74, 0xC5, 0xD4, 0xCE, 0x57, 0x5A, 0xAA, +0x95, 0x31, 0x5B, 0x2A, 0x29, 0x83, 0x52, 0xE9, +0x5B, 0x2A, 0x5B, 0x2A, 0x63, 0x4A, 0x6B, 0xCC, +0x6B, 0xAC, 0x6B, 0xAB, 0x42, 0x67, 0x7B, 0xED, +0x63, 0x49, 0x4B, 0x07, 0x53, 0x08, 0x4A, 0xA8, +0x52, 0xE9, 0x7B, 0xED, 0x84, 0x0D, 0x8C, 0x2E, +0x9C, 0x8F, 0x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0xBD, 0x94, 0xB5, 0x32, 0xC5, 0xB4, +0xCD, 0xF5, 0xDE, 0x97, 0xCD, 0xF5, 0xCE, 0x15, +0xC5, 0xD4, 0xBD, 0x53, 0xB5, 0x32, 0xAD, 0x32, +0xAD, 0x11, 0xAC, 0xF1, 0x41, 0xA6, 0x18, 0xA3, +0x10, 0x83, 0x10, 0x82, 0x19, 0x04, 0x31, 0xA7, +0x21, 0x04, 0x18, 0xE4, 0x18, 0xC4, 0x18, 0xC3, +0x18, 0xE4, 0x39, 0xA7, 0xA4, 0xF2, 0xAD, 0x32, +0xB5, 0x11, 0xAD, 0x11, 0xAC, 0xF0, 0xAC, 0xF0, +0xAC, 0xF0, 0xAD, 0x10, 0xAD, 0x11, 0xAC, 0xF1, +0xA4, 0xD0, 0xA4, 0xD0, 0xAC, 0xF0, 0xB5, 0x11, +0x62, 0xCA, 0x21, 0x05, 0x18, 0xE4, 0x18, 0xE4, +0x18, 0xE4, 0x19, 0x04, 0x19, 0x05, 0x19, 0x05, +0x19, 0x04, 0x19, 0x05, 0x19, 0x05, 0x19, 0x05, +0x19, 0x05, 0x19, 0x04, 0x19, 0x05, 0x19, 0x05, +0x19, 0x04, 0x18, 0xE4, 0x19, 0x04, 0x18, 0xE4, +0x18, 0xC4, 0x18, 0xC4, 0x18, 0xE4, 0x18, 0xE4, +0x19, 0x05, 0x18, 0xE4, 0x18, 0xE4, 0x18, 0xE4, +0x18, 0xE4, 0x10, 0xC4, 0x10, 0xC4, 0x10, 0xA4, +0x10, 0x83, 0x08, 0x83, 0x10, 0xC4, 0x18, 0xE4, +0x19, 0x05, 0x21, 0x25, 0x21, 0x05, 0x21, 0x26, +0x18, 0xE5, 0x19, 0x05, 0x21, 0x46, 0x29, 0x66, +0x31, 0xA7, 0x31, 0xA8, 0x31, 0xC8, 0x39, 0xE9, +0x31, 0xA8, 0x31, 0xC8, 0x4A, 0x2A, 0x7B, 0x8D, +0xB5, 0x32, 0xDE, 0x35, 0xE6, 0x75, 0xE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 0x05, +0x18, 0xE4, 0x19, 0x04, 0x18, 0xE4, 0x19, 0x05, +0x19, 0x04, 0x18, 0xE4, 0x19, 0x04, 0x19, 0x05, +0x19, 0x05, 0x19, 0x05, 0x19, 0x04, 0x10, 0xC4, +0x10, 0xC4, 0x10, 0xA3, 0x18, 0xE4, 0x18, 0xE4, +0x18, 0xE4, 0x18, 0xC4, 0x18, 0xC4, 0x10, 0xC4, +0x10, 0xC4, 0x10, 0xC4, 0x10, 0xA3, 0x10, 0xA3, +0x08, 0x83, 0x08, 0x83, 0x10, 0xC4, 0x18, 0xE4, +0x19, 0x05, 0x21, 0x05, 0x18, 0xE5, 0x21, 0x26, +0x18, 0xE5, 0x21, 0x06, 0x29, 0x46, 0x31, 0x87, +0x31, 0xA8, 0x31, 0xA8, 0x31, 0xC8, 0x39, 0xC8, +0x29, 0x67, 0x31, 0xC8, 0x42, 0x0A, 0x4A, 0x6A, +0x63, 0x0C, 0xAC, 0xF1, 0xDE, 0x54, 0xEE, 0x95, +0xE6, 0x95, 0xE6, 0x75, 0xE6, 0x75, 0xE6, 0x75, +0xE6, 0x75, 0xE6, 0x54, 0xEE, 0x95, 0xEE, 0xB6, +0xEE, 0x95, 0xEE, 0x95, 0xCD, 0x93, 0xB5, 0x11, +0xA4, 0xF1, 0xAD, 0x12, 0xBD, 0x94, 0xAD, 0x32, +0xBD, 0xB4, 0xAD, 0x53, 0xB5, 0x53, 0xB5, 0x73, +0xBD, 0xB4, 0xB5, 0x93, 0xC5, 0xF5, 0xBD, 0xB4, +0x32, 0x06, 0x21, 0x62, 0x29, 0xC4, 0x42, 0x67, +0x4A, 0xC9, 0x73, 0xED, 0x7C, 0x0E, 0x7C, 0x0E, +0x7C, 0x2E, 0x73, 0xAC, 0x3A, 0x25, 0x6B, 0xCC, +0x7C, 0x4E, 0x95, 0x11, 0x94, 0xF2, 0x73, 0xCE, +0x5B, 0x0B, 0x84, 0x2F, 0x8C, 0x90, 0xA5, 0x33, +0xC6, 0x16, 0x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8C, 0x0F, 0xB5, 0x54, +0xAD, 0x13, 0xAD, 0x13, 0xB5, 0x53, 0xAD, 0x32, +0xAD, 0x32, 0xA4, 0xB0, 0x8C, 0x0D, 0x94, 0x4E, +0x8C, 0x0E, 0x4A, 0x07, 0x31, 0x65, 0x21, 0x04, +0x18, 0xE4, 0x18, 0xE4, 0x18, 0xE4, 0x21, 0x25, +0x18, 0xE4, 0x18, 0xC3, 0x18, 0xE4, 0x18, 0xC3, +0x31, 0xA6, 0x8C, 0x2F, 0xB5, 0x32, 0xB5, 0x31, +0xCD, 0xF4, 0xC5, 0xB3, 0xB5, 0x32, 0xB5, 0x52, +0xAC, 0xF1, 0xA4, 0x8F, 0x83, 0xAC, 0x9C, 0x6E, +0xA4, 0xAF, 0xB5, 0x31, 0xBD, 0x52, 0xBD, 0x51, +0xAD, 0x11, 0x7B, 0x8D, 0x29, 0x45, 0x18, 0xE4, +0x18, 0xE4, 0x18, 0xE4, 0x19, 0x04, 0x19, 0x05, +0x21, 0x25, 0x21, 0x25, 0x18, 0xE4, 0x18, 0xE4, +0x19, 0x04, 0x18, 0xE4, 0x18, 0xC4, 0x18, 0xE4, +0x19, 0x05, 0x19, 0x05, 0x18, 0xE4, 0x18, 0xE4, +0x18, 0xE4, 0x10, 0xA3, 0x10, 0xA3, 0x18, 0xE4, +0x10, 0xC4, 0x10, 0xC4, 0x18, 0xC4, 0x10, 0xC4, +0x10, 0xA3, 0x10, 0xA3, 0x10, 0xA3, 0x10, 0x83, +0x08, 0x83, 0x10, 0x83, 0x10, 0xC4, 0x18, 0xE4, +0x18, 0xE5, 0x19, 0x05, 0x18, 0xE5, 0x21, 0x26, +0x18, 0xE5, 0x21, 0x46, 0x29, 0x47, 0x31, 0xA8, +0x31, 0x88, 0x31, 0x87, 0x31, 0xA8, 0x31, 0xA8, +0x31, 0xA8, 0x42, 0x2A, 0x42, 0x09, 0x42, 0x09, +0x4A, 0x4A, 0x73, 0x6D, 0xA4, 0x90, 0xA4, 0x8F, +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, 0x8C, 0x2F, 0x84, 0x0E, 0x8C, 0x2F, +0x73, 0xAC, 0x84, 0x0E, 0x9C, 0xD1, 0x84, 0x0E, +0x73, 0x6B, 0x94, 0x6F, 0x7B, 0xCD, 0x94, 0x90, +0x9C, 0xD1, 0xA5, 0x12, 0x8C, 0x2F, 0x94, 0x4F, +0x8C, 0x2F, 0x8C, 0x4F, 0x8C, 0x4F, 0x73, 0x8D, +0x8C, 0x2F, 0xB5, 0x52, 0xB5, 0x53, 0xAD, 0x32, +0xAD, 0x31, 0x94, 0x6F, 0x9C, 0x90, 0x94, 0x6F, +0x63, 0x0A, 0x4A, 0x28, 0x42, 0x07, 0x6B, 0x2B, +0x5A, 0xAA, 0x4A, 0x28, 0x41, 0xE7, 0x62, 0xCA, +0x83, 0xAE, 0x8B, 0xCF, 0x73, 0x0C, 0x6A, 0xEB, +0x83, 0xCF, 0x83, 0xCE, 0x9C, 0x92, 0x7B, 0x6D, +0x94, 0x50, 0x83, 0xCE, 0x94, 0x30, 0x9C, 0x71, +0x94, 0x30, 0x8B, 0xEE, 0x94, 0x30, 0x83, 0xCE, +0x94, 0x2F, 0x39, 0xA6, 0x18, 0xC3, 0x18, 0xA2, +0x18, 0xE3, 0x41, 0xE7, 0x31, 0x66, 0x20, 0xE4, +0x10, 0xC3, 0x10, 0x83, 0x10, 0xA3, 0x18, 0xE4, +0x18, 0xC4, 0x18, 0xC3, 0x18, 0xE4, 0x21, 0x04, +0x94, 0x70, 0xB5, 0x73, 0xAD, 0x11, 0xB5, 0x32, +0xBD, 0x93, 0xBD, 0x93, 0xBD, 0xB3, 0xBD, 0xB3, +0xC5, 0xB3, 0xC5, 0xD4, 0xAC, 0xD0, 0xBD, 0x73, +0xC5, 0xD4, 0xC5, 0x93, 0xBD, 0x52, 0xBD, 0x93, +0xB5, 0x72, 0x94, 0x4F, 0x5A, 0x8A, 0x18, 0xE4, +0x18, 0xE4, 0x18, 0xE4, 0x19, 0x04, 0x19, 0x05, +0x21, 0x05, 0x21, 0x25, 0x18, 0xE4, 0x18, 0xE4, +0x19, 0x04, 0x19, 0x04, 0x18, 0xC4, 0x18, 0xE4, +0x18, 0xE4, 0x21, 0x05, 0x19, 0x05, 0x19, 0x05, +0x18, 0xE4, 0x10, 0xC3, 0x10, 0xA3, 0x10, 0xC4, +0x10, 0xC4, 0x10, 0xC3, 0x10, 0xC4, 0x10, 0xC3, +0x10, 0x83, 0x08, 0x83, 0x08, 0x83, 0x08, 0x83, +0x08, 0x83, 0x10, 0xA3, 0x18, 0xC4, 0x18, 0xE4, +0x18, 0xE4, 0x19, 0x05, 0x19, 0x05, 0x21, 0x26, +0x21, 0x26, 0x21, 0x46, 0x29, 0x46, 0x29, 0x87, +0x21, 0x46, 0x29, 0x67, 0x29, 0x87, 0x31, 0x87, +0x39, 0xE9, 0x3A, 0x09, 0x39, 0xC8, 0x31, 0xC8, +0x42, 0x09, 0x52, 0xCC, 0x84, 0x0F, 0xB5, 0x32, +0xB5, 0x52, 0xB5, 0x52, 0xB5, 0x32, 0xB5, 0x32, +0xB5, 0x12, 0xAC, 0xF1, 0xAC, 0xF1, 0xB5, 0x11, +0xAD, 0x11, 0xA4, 0xB0, 0xAD, 0x32, 0xBD, 0x93, +0xB5, 0x32, 0xA4, 0xF1, 0xA4, 0xD1, 0x9C, 0x90, +0x9C, 0x90, 0x94, 0x6F, 0x8C, 0x2E, 0x94, 0x4F, +0x8C, 0x2E, 0x8C, 0x0E, 0x83, 0xED, 0x83, 0xED, +0x8C, 0xB0, 0x94, 0xB1, 0x6B, 0x6C, 0x8C, 0xB0, +0x7C, 0x2F, 0x94, 0xB1, 0xB5, 0xF6, 0xAD, 0x94, +0x9C, 0xD1, 0x52, 0x87, 0x42, 0x26, 0x63, 0x8B, +0x74, 0x2E, 0x84, 0x90, 0x8C, 0xB0, 0x84, 0x50, +0x84, 0x2F, 0x9C, 0xF2, 0xAD, 0x74, 0xAD, 0x74, +0xC6, 0x57, 0xB5, 0xB5, 0xAD, 0x74, 0x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0x8D, 0x52, 0x49, 0x4A, 0x07, +0x6B, 0x0B, 0x73, 0x4D, 0x83, 0xEF, 0x62, 0xEB, +0x29, 0x24, 0x31, 0x86, 0x21, 0x04, 0x18, 0xC3, +0x10, 0xA3, 0x10, 0x83, 0x10, 0x83, 0x10, 0xA3, +0x18, 0xE4, 0x18, 0xC3, 0x18, 0xE4, 0x29, 0x65, +0xAD, 0x53, 0xC5, 0xD4, 0xAC, 0xF1, 0xBD, 0x73, +0xC5, 0xD4, 0xC5, 0xB3, 0xC5, 0xD4, 0xCD, 0xF4, +0xCD, 0xF4, 0xCD, 0xD4, 0xBD, 0x73, 0xCD, 0xF4, +0xD6, 0x36, 0xCE, 0x15, 0xCD, 0xF5, 0xCD, 0xF5, +0xCE, 0x15, 0xB5, 0x32, 0x83, 0xEE, 0x29, 0x65, +0x18, 0xE4, 0x18, 0xE4, 0x19, 0x04, 0x18, 0xE4, +0x18, 0xE4, 0x21, 0x05, 0x18, 0xE4, 0x18, 0xE4, +0x19, 0x04, 0x19, 0x05, 0x18, 0xE4, 0x18, 0xE4, +0x18, 0xE4, 0x18, 0xE4, 0x19, 0x04, 0x18, 0xE5, +0x18, 0xE4, 0x10, 0xA3, 0x10, 0xA3, 0x10, 0xA3, +0x10, 0xA3, 0x10, 0xA4, 0x10, 0xA3, 0x10, 0xA3, +0x08, 0x83, 0x08, 0x83, 0x08, 0x83, 0x08, 0x83, +0x10, 0x83, 0x10, 0xA3, 0x10, 0xC4, 0x10, 0xC4, +0x18, 0xE4, 0x19, 0x05, 0x19, 0x05, 0x21, 0x26, +0x21, 0x26, 0x21, 0x26, 0x21, 0x46, 0x21, 0x26, +0x18, 0xE5, 0x29, 0x46, 0x29, 0x67, 0x29, 0x87, +0x31, 0xC8, 0x39, 0xC9, 0x39, 0xC8, 0x39, 0xE9, +0x42, 0x2A, 0x3A, 0x09, 0x42, 0x49, 0xA4, 0xF2, +0xCE, 0x16, 0xBD, 0x73, 0xBD, 0x93, 0xA4, 0xB0,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0x05, 0x18, 0xE4, 0x18, 0xE4, +0x19, 0x04, 0x18, 0xC4, 0x18, 0xE4, 0x18, 0xE4, +0x18, 0xE4, 0x10, 0xC3, 0x10, 0xA3, 0x10, 0xA3, +0x10, 0xA3, 0x10, 0xA3, 0x08, 0x83, 0x08, 0x83, +0x08, 0x83, 0x10, 0x83, 0x08, 0x83, 0x08, 0x83, +0x08, 0x83, 0x10, 0xA3, 0x10, 0xC4, 0x10, 0xC4, +0x18, 0xE4, 0x19, 0x05, 0x21, 0x05, 0x21, 0x26, +0x21, 0x26, 0x21, 0x26, 0x21, 0x26, 0x19, 0x05, +0x21, 0x26, 0x21, 0x26, 0x21, 0x46, 0x29, 0x67, +0x31, 0x87, 0x39, 0xC8, 0x39, 0xE9, 0x39, 0xE9, +0x31, 0xA8, 0x31, 0x88, 0x31, 0x87, 0x6B, 0x4C, +0xC5, 0xD5, 0xC5, 0xB4, 0xBD, 0x94, 0xA4, 0xF1, +0xA4, 0xB0, 0xB5, 0x32, 0xBD, 0x72, 0xBD, 0x93, +0xD6, 0x36, 0xD6, 0x56, 0xAD, 0x32, 0x9C, 0x8F, +0xA4, 0xB0, 0xBD, 0x93, 0xCD, 0xF4, 0xBD, 0x93, +0x94, 0x6F, 0x8C, 0x0E, 0x8B, 0xED, 0xBD, 0x93, +0xBD, 0x92, 0xB5, 0x11, 0xB5, 0x31, 0xAD, 0x11, +0xBD, 0xF5, 0xBD, 0xD5, 0x73, 0x8C, 0x6B, 0x4B, +0x52, 0xC8, 0x7C, 0x4E, 0x5B, 0x29, 0x7B, 0xEC, +0x9C, 0xD1, 0xAD, 0x73, 0xA5, 0x52, 0x84, 0x2D, +0x84, 0x2C, 0x7B, 0xEB, 0x84, 0x0D, 0x94, 0xB0, +0x8C, 0x6F, 0x94, 0x90, 0x9C, 0xB0, 0xAD, 0x32, +0xB5, 0x93, 0xB5, 0x94, 0xA4, 0xF2, 0x9C, 0x8F, +0xAC, 0xCF, 0x9C, 0x8F, 0x94, 0x6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xAA, 0x5A, 0xAA, 0x6B, 0x2C, +0x7B, 0xCF, 0x8C, 0x10, 0x83, 0xAF, 0x52, 0x69, +0x4A, 0x28, 0x5A, 0x8A, 0x63, 0x0B, 0x73, 0x8D, +0x7B, 0xAE, 0x8C, 0x30, 0x52, 0x69, 0x52, 0x69, +0x41, 0xE7, 0x29, 0x03, 0x31, 0x85, 0x4A, 0x28, +0x39, 0xA6, 0x5A, 0xAA, 0x7B, 0x8E, 0x52, 0x69, +0x52, 0x89, 0x62, 0xC9, 0x73, 0x4B, 0x8C, 0x0D, +0xAD, 0x11, 0xB5, 0x32, 0xBD, 0x52, 0xBD, 0x72, +0xCD, 0xD4, 0xC5, 0xD3, 0xC5, 0x92, 0xDE, 0x55, +0xD6, 0x35, 0xD6, 0x35, 0xD6, 0x35, 0x9C, 0x8F, +0xB5, 0x53, 0xB5, 0x53, 0xB5, 0x33, 0xB5, 0x33, +0xAD, 0x12, 0xB5, 0x52, 0xBD, 0x73, 0xC5, 0x93, +0xBD, 0x53, 0xB5, 0x32, 0xB5, 0x53, 0xB5, 0x53, +0xBD, 0x53, 0xBD, 0x73, 0xBD, 0x73, 0xBD, 0x73, +0xBD, 0x93, 0xBD, 0x53, 0xB5, 0x32, 0xBD, 0x73, +0xBD, 0x94, 0xC5, 0xB4, 0xCD, 0xD5, 0xBD, 0x73, +0xB5, 0x31, 0xAC, 0xF1, 0xAC, 0xF0, 0xB5, 0x31, +0xB5, 0x52, 0xA4, 0x90, 0x7B, 0x6C, 0x31, 0x65, +0x42, 0x07, 0x31, 0x85, 0x29, 0x44, 0x29, 0x45, +0x4A, 0x49, 0x4A, 0x8A, 0x3A, 0x08, 0x52, 0xAA, +0x94, 0x72, 0x9C, 0x92, 0x94, 0x92, 0x8C, 0x51, +0x52, 0x49, 0x52, 0x49, 0x5A, 0x8A, 0x52, 0x28, +0x52, 0x28, 0x8B, 0xEF, 0x62, 0xCB, 0x83, 0xCE, +0x7B, 0x8E, 0x62, 0xAB, 0x7B, 0x6D, 0x94, 0x30, +0x8C, 0x30, 0x83, 0xAE, 0x39, 0x87, 0x18, 0xC4, +0x18, 0xE4, 0x19, 0x04, 0x18, 0xC3, 0x10, 0xA3, +0x10, 0xA3, 0x10, 0xC3, 0x21, 0x24, 0x94, 0x70, +0xD6, 0x56, 0xCD, 0xF4, 0xAC, 0xD0, 0xC5, 0x93, +0xD6, 0x14, 0xD6, 0x14, 0xE6, 0x76, 0xDE, 0x76, +0xDE, 0x75, 0xDE, 0x35, 0xCD, 0xD3, 0xCD, 0xB4, +0xC5, 0x93, 0xBD, 0x72, 0xC5, 0x93, 0xC5, 0xD3, +0xA4, 0xAF, 0xD6, 0x35, 0xCD, 0xF5, 0xAD, 0x12, +0x7B, 0xAD, 0x31, 0x86, 0x18, 0xE4, 0x18, 0xE4, +0x18, 0xE4, 0x18, 0xE4, 0x10, 0xC4, 0x18, 0xC4, +0x18, 0xE4, 0x19, 0x04, 0x18, 0xE4, 0x18, 0xE4, +0x18, 0xE4, 0x10, 0xC4, 0x10, 0xC4, 0x18, 0xE4, +0x18, 0xE4, 0x10, 0xC4, 0x10, 0xA3, 0x10, 0xA3, +0x10, 0xA3, 0x10, 0xA3, 0x08, 0x83, 0x10, 0x83, +0x10, 0x83, 0x10, 0x83, 0x10, 0x83, 0x10, 0x83, +0x08, 0x83, 0x10, 0xA3, 0x10, 0xA3, 0x10, 0xA4, +0x18, 0xE4, 0x19, 0x05, 0x21, 0x26, 0x21, 0x26, +0x21, 0x26, 0x21, 0x26, 0x21, 0x05, 0x19, 0x05, +0x21, 0x05, 0x21, 0x26, 0x21, 0x26, 0x21, 0x26, +0x29, 0x67, 0x39, 0xC8, 0x31, 0xC8, 0x39, 0xE9, +0x31, 0xA8, 0x4A, 0x6B, 0x4A, 0x4A, 0x4A, 0x29, +0x7B, 0xAD, 0xB5, 0x32, 0xBD, 0x73, 0xAD, 0x32, +0xA4, 0xF1, 0xAD, 0x11, 0xB5, 0x12, 0xD6, 0x35, +0xDE, 0x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6, 0x55, 0xD6, 0x56, 0xDE, 0x76, +0xD6, 0x35, 0xCD, 0xF4, 0xBD, 0x73, 0xB5, 0x32, +0xB5, 0x32, 0xB5, 0x32, 0xAC, 0xF0, 0x9C, 0x6F, +0x8C, 0x0D, 0xAD, 0x11, 0xB5, 0x11, 0xAD, 0x11, +0xBD, 0x73, 0xBD, 0x73, 0xAD, 0x11, 0xB5, 0x32, +0xB5, 0x32, 0x52, 0x48, 0x39, 0x86, 0x52, 0x68, +0xAD, 0x32, 0x73, 0x6C, 0x31, 0x85, 0x29, 0x44, +0x29, 0x45, 0x31, 0xA6, 0x31, 0x85, 0x31, 0xA6, +0x42, 0x07, 0x4A, 0x29, 0x7B, 0xAF, 0xB5, 0x96, +0x9C, 0xB2, 0x7B, 0xAE, 0x6B, 0x0C, 0x62, 0xAB, +0x49, 0xE7, 0x7B, 0x6E, 0x7B, 0xAE, 0x8C, 0x30, +0x6B, 0x0C, 0x7B, 0xAE, 0x9C, 0x71, 0x9C, 0x70, +0x8B, 0xEF, 0x94, 0x10, 0x73, 0x4D, 0x31, 0x66, +0x18, 0xA3, 0x18, 0xC4, 0x18, 0xE4, 0x18, 0xE4, +0x18, 0xE4, 0x18, 0xE4, 0x4A, 0x49, 0x8C, 0x0F, +0xBD, 0x93, 0xB5, 0x11, 0xB5, 0x11, 0xCD, 0xF4, +0xE6, 0x96, 0xE6, 0x76, 0xDE, 0x76, 0xE6, 0x96, +0xE6, 0x96, 0xB5, 0x11, 0xA4, 0x6F, 0x8B, 0xED, +0x8B, 0xCD, 0x94, 0x2E, 0x9C, 0x90, 0x94, 0x2E, +0x73, 0x6B, 0xBD, 0xB4, 0xE6, 0xB8, 0xDE, 0x76, +0xBD, 0x93, 0x73, 0x4C, 0x31, 0xA7, 0x18, 0xC4, +0x18, 0xE4, 0x10, 0xE4, 0x10, 0xC4, 0x10, 0xC4, +0x10, 0xC4, 0x18, 0xE4, 0x18, 0xE4, 0x18, 0xE4, +0x18, 0xE4, 0x18, 0xC4, 0x10, 0xA3, 0x18, 0xE4, +0x18, 0xC4, 0x10, 0xC4, 0x10, 0xA4, 0x10, 0xA3, +0x10, 0xA3, 0x10, 0xA3, 0x10, 0x83, 0x10, 0xA3, +0x10, 0xA3, 0x10, 0x83, 0x10, 0x83, 0x08, 0x83, +0x10, 0x83, 0x10, 0xA3, 0x10, 0xA3, 0x10, 0xC3, +0x18, 0xE4, 0x21, 0x25, 0x21, 0x26, 0x21, 0x26, +0x21, 0x26, 0x19, 0x05, 0x19, 0x05, 0x19, 0x05, +0x21, 0x05, 0x21, 0x46, 0x21, 0x26, 0x19, 0x05, +0x29, 0x46, 0x31, 0xA8, 0x31, 0xA8, 0x31, 0xA8, +0x39, 0xE9, 0x3A, 0x09, 0x39, 0xE9, 0x39, 0xA8, +0x41, 0xE8, 0x73, 0x6C, 0x9C, 0x90, 0xAD, 0x32, +0x9C, 0x90, 0xA4, 0xD1, 0xAC, 0xF1, 0xC5, 0xD4, +0xCD, 0xD4, 0xD6, 0x14, 0xD6, 0x35, 0xCD, 0xD4, +0xCD, 0xD4, 0xD6, 0x35, 0xCE, 0x14, 0xCD, 0xF4, +0xCD, 0xF5, 0xD6, 0x36, 0xC5, 0x93, 0xE6, 0xB7, +0xE6, 0x95, 0xE6, 0x95, 0xE6, 0x95, 0xE6, 0xB6, +0x73, 0x8D, 0x8C, 0x0F, 0x84, 0x0E, 0x94, 0x4E, +0x94, 0x6E, 0x83, 0xED, 0x8C, 0x6E, 0x94, 0x8F, +0x8C, 0x4F, 0x84, 0x0D, 0x8C, 0x2E, 0x9C, 0xD0, +0xA4, 0xF0, 0xA4, 0xCF, 0xA4, 0xEF, 0xA4, 0xCF, +0xAC, 0xCF, 0xAC, 0xCF, 0xAC, 0xCF, 0x94, 0x4D, +0xA4, 0x8E, 0x94, 0x0C, 0x8B, 0xCB, 0x94, 0x2C, +0xA4, 0x6E, 0xA4, 0x8E, 0xAC, 0xAE, 0xA4, 0x8E, +0xB4, 0xF0, 0xBD, 0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, 0x2C, 0x6B, 0x2C, 0x52, 0x69, 0x4A, 0x08, +0x5A, 0xAA, 0x52, 0x69, 0x63, 0x0B, 0x52, 0x89, +0x5A, 0xAA, 0x5A, 0xCA, 0x52, 0x89, 0x5A, 0xAA, +0x4A, 0x28, 0x39, 0xA6, 0x39, 0xC6, 0x21, 0x24, +0x21, 0x04, 0x6B, 0x4D, 0x63, 0x0B, 0x6B, 0x4C, +0x83, 0xEF, 0x84, 0x0F, 0x94, 0x70, 0x9C, 0xD1, +0xA5, 0x13, 0xAD, 0x53, 0xA5, 0x32, 0x94, 0x90, +0x94, 0x70, 0x94, 0x90, 0x8C, 0x4F, 0x94, 0x70, +0xA4, 0xF2, 0x94, 0x90, 0xA4, 0xF2, 0xB5, 0x53, +0xC5, 0xF5, 0xCE, 0x16, 0xA4, 0xD1, 0xB5, 0x32, +0xDE, 0x76, 0xDE, 0x96, 0xE6, 0x96, 0xE6, 0x96, +0xD6, 0x35, 0xDE, 0x75, 0xE6, 0xB7, 0xC5, 0xB3, +0xBD, 0x72, 0xD6, 0x35, 0xDE, 0x55, 0xD6, 0x35, +0xD6, 0x35, 0xCD, 0xF5, 0xC5, 0xD4, 0xBD, 0x93, +0xAC, 0xF1, 0xB5, 0x52, 0xAC, 0xF0, 0xA4, 0x6F, +0xCD, 0xF4, 0xDE, 0x55, 0xCD, 0xF4, 0xAC, 0xD0, +0xC5, 0xD5, 0xA4, 0xD1, 0x9C, 0xB1, 0x8C, 0x4F, +0xA5, 0x11, 0xA4, 0xD1, 0x8C, 0x2E, 0x52, 0xA9, +0x31, 0xA6, 0x31, 0x85, 0x29, 0x44, 0x29, 0x44, +0x29, 0x65, 0x39, 0xC7, 0x52, 0x8A, 0x63, 0x2C, +0x9D, 0x14, 0xCE, 0x59, 0xB5, 0x96, 0x7B, 0x8E, +0x52, 0x49, 0x83, 0xCE, 0x62, 0xCA, 0x52, 0x29, +0x41, 0xE7, 0x73, 0x6D, 0xA4, 0x91, 0x94, 0x0F, +0x83, 0x8D, 0x8C, 0x0F, 0x83, 0xCE, 0x6B, 0x0C, +0x39, 0x86, 0x21, 0x25, 0x18, 0xE4, 0x18, 0xE4, +0x21, 0x04, 0x5A, 0xAA, 0x9C, 0x91, 0x9C, 0x90, +0xA4, 0xB0, 0xAC, 0xF1, 0xB5, 0x11, 0xAC, 0xF0, +0xAC, 0xD0, 0xA4, 0xAF, 0x9C, 0x4E, 0x9C, 0x4E, +0xA4, 0x8F, 0x94, 0x0D, 0x83, 0xAD, 0x83, 0x8C, +0x7B, 0x4C, 0x6A, 0xEA, 0x5A, 0xA9, 0x5A, 0x89, +0x73, 0x2C, 0xB5, 0x32, 0xA4, 0xD0, 0x94, 0x2E, +0x83, 0xED, 0x83, 0xCD, 0x73, 0x4C, 0x39, 0xC7, +0x18, 0xE4, 0x10, 0xC4, 0x10, 0xC4, 0x10, 0xC4, +0x10, 0xC3, 0x10, 0xC3, 0x10, 0xC3, 0x10, 0xC4, +0x18, 0xC4, 0x18, 0xE4, 0x10, 0xC4, 0x10, 0xC4, +0x10, 0xC4, 0x10, 0xC4, 0x10, 0xA3, 0x10, 0xA3, +0x10, 0xA3, 0x10, 0xA3, 0x10, 0xA3, 0x10, 0xA3, +0x10, 0x83, 0x10, 0x83, 0x10, 0x83, 0x10, 0x83, +0x08, 0x83, 0x10, 0x83, 0x10, 0xA3, 0x10, 0xC4, +0x21, 0x05, 0x29, 0x46, 0x29, 0x66, 0x21, 0x26, +0x19, 0x05, 0x19, 0x05, 0x19, 0x05, 0x18, 0xE5, +0x21, 0x26, 0x29, 0x46, 0x21, 0x26, 0x21, 0x26, +0x29, 0x67, 0x29, 0x87, 0x29, 0x87, 0x29, 0x67, +0x29, 0x67, 0x29, 0x67, 0x29, 0x67, 0x31, 0xA7, +0x42, 0x09, 0x5A, 0xCB, 0x73, 0x6D, 0xA4, 0xD1, +0x94, 0x6F, 0xA4, 0xB0, 0x9C, 0xB0, 0xB5, 0x73, +0xBD, 0x93, 0xC5, 0xB3, 0x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xC4, 0x18, 0xE4, 0x10, 0xC4, +0x10, 0xC4, 0x10, 0xC4, 0x10, 0xC4, 0x10, 0xA3, +0x10, 0xA3, 0x10, 0xA3, 0x10, 0xA3, 0x10, 0xA3, +0x10, 0x83, 0x10, 0x83, 0x10, 0xA3, 0x08, 0x83, +0x08, 0x83, 0x10, 0x83, 0x10, 0xA3, 0x10, 0xC4, +0x21, 0x05, 0x29, 0x66, 0x31, 0xA7, 0x29, 0x67, +0x21, 0x26, 0x18, 0xE5, 0x18, 0xE5, 0x18, 0xE5, +0x21, 0x26, 0x21, 0x26, 0x21, 0x26, 0x21, 0x46, +0x29, 0x46, 0x29, 0x67, 0x21, 0x26, 0x21, 0x26, +0x21, 0x26, 0x21, 0x26, 0x29, 0x67, 0x31, 0xA8, +0x42, 0x4A, 0x5A, 0xEC, 0x5A, 0xCB, 0x73, 0xAD, +0x9C, 0x90, 0x9C, 0xB0, 0x94, 0x6F, 0xB5, 0x53, +0xB5, 0x72, 0xB5, 0x52, 0xB5, 0x52, 0xB5, 0x52, +0xBD, 0x92, 0xD6, 0x55, 0xCD, 0xF4, 0xBD, 0x52, +0xB5, 0x32, 0xB5, 0x73, 0xCE, 0x15, 0xE6, 0xD7, +0xD6, 0x14, 0xD6, 0x14, 0xD6, 0x14, 0xD6, 0x34, +0x6B, 0x6C, 0x7B, 0xCE, 0x7B, 0xEF, 0xDE, 0xFB, +0xDE, 0x99, 0xAD, 0x2F, 0x94, 0x6C, 0xAD, 0x31, +0xC5, 0xF5, 0xCE, 0x37, 0xAD, 0x12, 0xAD, 0x32, +0xA4, 0xF1, 0x9C, 0xB0, 0xA4, 0xD0, 0xB5, 0x30, +0xAC, 0xEF, 0xAC, 0xCE, 0xBD, 0x92, 0xE6, 0x97, +0xC5, 0xD4, 0xBD, 0x93, 0xBD, 0x93, 0xBD, 0x93, +0xBD, 0x93, 0xBD, 0x93, 0xB5, 0x52, 0xB5, 0x32, +0xB5, 0x52, 0xB5, 0x32, 0xAD, 0x11,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x8B, 0xAE, 0x83, 0x8D, 0x93, 0xEF, +0x72, 0xEB, 0x73, 0x2C, 0x9C, 0x30, 0x83, 0x8E, +0x83, 0xCE, 0xA4, 0xD2, 0x6B, 0x0B, 0x73, 0x6C, +0x9C, 0x90, 0xB5, 0x52, 0xB5, 0x72, 0xAD, 0x11, +0x8B, 0xEC, 0x94, 0x2E, 0x9C, 0x6E, 0x9C, 0x8F, +0xA4, 0xD0, 0xAC, 0xD0, 0xBD, 0x73, 0xD6, 0x15, +0xB5, 0x11, 0xC5, 0xB3, 0xC5, 0xB3, 0xBD, 0x72, +0xAC, 0xF0, 0xAD, 0x11, 0xB5, 0x11, 0xAC, 0xF1, +0xC5, 0xB4, 0xB5, 0x32, 0xAD, 0x11, 0x7B, 0xAC, +0x29, 0x86, 0x10, 0xC3, 0x10, 0xA3, 0x10, 0xA3, +0x10, 0xA3, 0x10, 0xA3, 0x10, 0xA3, 0x10, 0xC3, +0x10, 0xC4, 0x18, 0xC4, 0x18, 0xE4, 0x10, 0xC4, +0x10, 0xC4, 0x10, 0xC4, 0x10, 0xC4, 0x10, 0xA3, +0x10, 0xA3, 0x10, 0xA3, 0x10, 0xA3, 0x10, 0xA3, +0x10, 0x83, 0x08, 0x83, 0x08, 0x83, 0x10, 0x83, +0x08, 0x83, 0x10, 0x83, 0x10, 0xA3, 0x10, 0xC4, +0x21, 0x05, 0x29, 0x66, 0x39, 0xE8, 0x39, 0xC7, +0x29, 0x67, 0x21, 0x05, 0x18, 0xE5, 0x19, 0x05, +0x21, 0x26, 0x21, 0x26, 0x21, 0x46, 0x21, 0x26, +0x21, 0x46, 0x21, 0x46, 0x21, 0x26, 0x21, 0x26, +0x21, 0x26, 0x29, 0x46, 0x29, 0x87, 0x31, 0xC8, +0x42, 0x2A, 0x42, 0x29, 0x39, 0xA8, 0x4A, 0x29, +0x94, 0x70, 0xA4, 0xD1, 0x9C, 0xB0, 0xAD, 0x32, +0xB5, 0x32, 0xB5, 0x52, 0xAD, 0x12, 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F, 0xC5, 0xB3, 0xDE, 0x95, 0xE6, 0x96, +0xE6, 0x96, 0xDE, 0x95, 0xDE, 0x34, 0xD6, 0x14, +0xE6, 0x96, 0xC5, 0x71, 0xC5, 0x91, 0xDE, 0x34, +0xDE, 0x54, 0xD6, 0x34, 0xBD, 0x72, 0xB5, 0x53, +0xB5, 0x73, 0xC6, 0x15, 0xBD, 0xD4, 0xBD, 0xD4, +0xC5, 0xF5, 0xB5, 0x53, 0xBD, 0xD5, 0xAD, 0x53, +0xBD, 0xB4, 0xBD, 0xD4, 0xAD, 0x32, 0x94, 0x90, +0x6B, 0x2C, 0x31, 0x85, 0x29, 0x44, 0x21, 0x44, +0x21, 0x03, 0x21, 0x03, 0x21, 0x24, 0x29, 0x44, +0x21, 0x44, 0x29, 0x65, 0x31, 0x65, 0x52, 0x49, +0x62, 0xAA, 0x7B, 0x8D, 0x7B, 0x8D, 0x73, 0x2C, +0x73, 0x2C, 0x7B, 0x6D, 0x83, 0x8D, 0x94, 0x0F, +0x83, 0x8D, 0x83, 0x8D, 0x94, 0x0F, 0x83, 0xAE, +0x94, 0x50, 0xA4, 0xB2, 0x9C, 0x71, 0x94, 0x0F, +0x6B, 0x2B, 0x73, 0x4B, 0x9C, 0x90, 0xBD, 0x93, +0xB5, 0x52, 0xAD, 0x31, 0xAD, 0x31, 0xB5, 0x31, +0xB5, 0x31, 0xB5, 0x52, 0xCD, 0xD4, 0xD6, 0x56, +0xB5, 0x11, 0xAC, 0xF0, 0xA4, 0xD0, 0x8C, 0x0D, +0xAC, 0xF1, 0xC5, 0x93, 0xB5, 0x12, 0x83, 0xED, +0x9C, 0x70, 0x8C, 0x0E, 0x7B, 0xAC, 0x42, 0x07, +0x18, 0xE3, 0x10, 0xA3, 0x10, 0xA3, 0x10, 0xA3, +0x10, 0xA3, 0x10, 0xA3, 0x10, 0xA3, 0x10, 0xC3, +0x10, 0xC4, 0x10, 0xC4, 0x10, 0xC4, 0x10, 0xC4, +0x10, 0xC4, 0x10, 0xC3, 0x10, 0xA3, 0x10, 0xA3, +0x10, 0xA3, 0x10, 0xA3, 0x10, 0xA3, 0x10, 0xA3, +0x10, 0xA3, 0x10, 0xA3, 0x10, 0xA3, 0x10, 0xA3, +0x10, 0xA3, 0x10, 0x83, 0x10, 0xA3, 0x18, 0xE4, +0x19, 0x05, 0x29, 0x66, 0x42, 0x29, 0x52, 0x8A, +0x41, 0xE8, 0x29, 0x46, 0x21, 0x25, 0x19, 0x05, +0x21, 0x26, 0x21, 0x26, 0x21, 0x46, 0x21, 0x26, +0x21, 0x46, 0x21, 0x46, 0x21, 0x26, 0x21, 0x26, +0x21, 0x46, 0x29, 0x67, 0x29, 0x87, 0x31, 0xA8, +0x31, 0xA7, 0x29, 0x66, 0x29, 0x46, 0x39, 0xC8, +0x73, 0x4D, 0x94, 0x4F, 0x83, 0xEE, 0x7B, 0xAD, +0x83, 0xCD, 0x83, 0xED, 0x7B, 0xAD, 0x7B, 0xAD, +0x8B, 0xEE, 0x94, 0x4F, 0x94, 0x2F, 0x94, 0x4F, +0x94, 0x6F, 0x9C, 0x90, 0xB5, 0x32, 0xAD, 0x12, +0xAC, 0xF1, 0xAD, 0x11, 0xB5, 0x52, 0xB5, 0x73, +0x52, 0xAA, 0x6B, 0x4C, 0x8C, 0x50, 0xAD, 0x35, +0x73, 0x8E, 0x9C, 0x91, 0xC5, 0xF6, 0xBD, 0x94, +0xC5, 0xD5, 0xB5, 0x54, 0x62, 0xEB, 0x73, 0x8C, +0xA5, 0x32, 0xA4, 0xF1, 0x9C, 0xB0, 0xA4, 0xAF, +0xBD, 0x51, 0xAC, 0xAE, 0xA4, 0x8E, 0xD6, 0x36, +0xD6, 0x15, 0xD6, 0x35, 0xCE, 0x15, 0xCE, 0x15, +0xD6, 0x35, 0xD6, 0x35, 0xCE, 0x15, 0xCE, 0x15, +0xD6, 0x56, 0xD6, 0x56, 0xCE, 0x36, 0xD6, 0x77, +0xCE, 0x15, 0xC5, 0xF4, 0xC5, 0xD4, 0xC5, 0xF4, +0xCE, 0x15, 0xCE, 0x15, 0xC5, 0xB3, 0xD6, 0x35, +0xD6, 0x35, 0xAC, 0xAE, 0x94, 0x2D, 0xA4, 0xF0, +0xA4, 0xF0, 0xAD, 0x11, 0x9C, 0xB0, 0xA5, 0x11, +0xBD, 0xB3, 0xBD, 0xB3, 0xBD, 0xB3, 0xBD, 0xB3, +0xC5, 0xD4, 0xBD, 0xB3, 0xAD, 0x11, 0x52, 0x89, +0x52, 0x69, 0x4A, 0x28, 0x52, 0xCA, 0x5B, 0x0B, +0x4A, 0x49, 0x7B, 0xEF, 0x63, 0x0C, 0x73, 0xAF, +0xAD, 0x75, 0xA5, 0x14, 0x94, 0xB3, 0x8C, 0x72, +0x84, 0x10, 0x8C, 0x72, 0xA5, 0x35, 0x84, 0x10, +0x52, 0x8A, 0x31, 0xA7, 0x6B, 0x4D, 0xAD, 0x33, +0xAD, 0x33, 0x94, 0x6F, 0x7B, 0xAD, 0x62, 0xEA, +0x83, 0xCD, 0x8C, 0x2E, 0x6B, 0x4A, 0x83, 0xED, +0x8C, 0x0E, 0x84, 0x0D, 0x83, 0xCD, 0xB5, 0x31, +0xBD, 0x50, 0xAC, 0xEF, 0xCD, 0xD2, 0xD5, 0xF3, +0xD6, 0x13, 0xCD, 0xB2, 0xC5, 0x92, 0xCD, 0xB2, +0xCD, 0xB2, 0xD5, 0xB2, 0xCD, 0xB2, 0xC5, 0x70, +0xC5, 0x70, 0xC5, 0x71, 0xCD, 0xB2, 0xD5, 0xD2, +0xCD, 0xB2, 0xC5, 0x71, 0xCD, 0xF4, 0x83, 0xCD, +0x31, 0x65, 0x31, 0x44, 0x29, 0x44, 0x29, 0x24, +0x29, 0x24, 0x29, 0x23, 0x21, 0x03, 0x29, 0x44, +0x39, 0xA6, 0x42, 0x07, 0x29, 0x44, 0x31, 0x85, +0x4A, 0x48, 0x4A, 0x48, 0x52, 0x69, 0x41, 0xE7, +0x39, 0xE6, 0x31, 0x65, 0x29, 0x44, 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x9C, 0x50, 0x8B, 0xEF, +0x7B, 0x6D, 0x83, 0xAE, 0xB4, 0xF3, 0xB5, 0x13, +0xAC, 0xF2, 0x62, 0xAA, 0x62, 0xCA, 0x7B, 0x6D, +0xAC, 0xF1, 0xB5, 0x32, 0xBD, 0x93, 0xB5, 0x52, +0xB5, 0x31, 0xCE, 0x15, 0xDE, 0x56, 0xD6, 0x56, +0xCD, 0xF5, 0xCE, 0x15, 0xCD, 0xF5, 0xBD, 0x93, +0xC5, 0xD4, 0xC5, 0xB4, 0xC5, 0x94, 0xBD, 0xB4, +0x9C, 0x90, 0x62, 0xA9, 0x31, 0x65, 0x18, 0xC3, +0x10, 0xA3, 0x10, 0xA3, 0x10, 0xA3, 0x10, 0xA3, +0x10, 0x83, 0x08, 0x83, 0x08, 0x83, 0x10, 0x83, +0x10, 0xA3, 0x10, 0xA3, 0x10, 0xC3, 0x10, 0xC3, +0x10, 0xC3, 0x10, 0xC4, 0x10, 0xA3, 0x10, 0xA3, +0x10, 0xA3, 0x10, 0xA3, 0x10, 0xA3, 0x10, 0xA3, +0x10, 0xA3, 0x10, 0xA3, 0x10, 0xC3, 0x10, 0xA3, +0x10, 0xA3, 0x10, 0xA3, 0x10, 0xA3, 0x18, 0xE4, +0x21, 0x05, 0x31, 0x87, 0x73, 0x4D, 0x8C, 0x30, +0x62, 0xEB, 0x42, 0x08, 0x31, 0xA7, 0x21, 0x26, +0x21, 0x26, 0x21, 0x26, 0x21, 0x26, 0x21, 0x26, +0x21, 0x26, 0x21, 0x26, 0x21, 0x26, 0x21, 0x26, +0x29, 0x67, 0x29, 0x46, 0x29, 0x67, 0x29, 0x67, +0x21, 0x26, 0x21, 0x26, 0x29, 0x67, 0x39, 0xC8, +0x52, 0x49, 0x83, 0xEF, 0xBD, 0xB4, 0xC5, 0xF5, +0xBD, 0x74, 0xB5, 0x33, 0xAD, 0x33, 0xB5, 0x53, +0xB5, 0x53, 0xAD, 0x33, 0xAD, 0x32, 0xAD, 0x12, +0xA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0xEE, 0xD7, 0xEE, 0x96, 0xE6, 0x75, +0xCD, 0xB2, 0xDE, 0x34, 0xDE, 0x14, 0xE6, 0x54, +0xDE, 0x54, 0xCD, 0xB2, 0xA4, 0x8E, 0xBD, 0x93, +0xC5, 0xD4, 0xAD, 0x32, 0xBD, 0xD4, 0xB5, 0xB4, +0xC6, 0x15, 0xC6, 0x15, 0xBD, 0xD5, 0xBD, 0xB4, +0xB5, 0x93, 0xBD, 0xB4, 0xB5, 0x73, 0xAD, 0x11, +0xBD, 0x52, 0xDE, 0x35, 0xE6, 0x76, 0xBD, 0x93, +0x94, 0x2F, 0x41, 0xE7, 0x29, 0x44, 0x29, 0x44, +0x21, 0x24, 0x39, 0xC6, 0x7B, 0xEE, 0x8C, 0x0F, +0x8C, 0x10, 0x4A, 0x28, 0x52, 0x49, 0x41, 0xE7, +0x73, 0x4C, 0x83, 0xCF, 0x73, 0x4C, 0x72, 0xEA, +0x83, 0x8D, 0x93, 0xCE, 0x94, 0x0F, 0x94, 0x0F, +0x6A, 0xCB, 0x62, 0xAA, 0x8B, 0xEF, 0xB5, 0x33, +0xC5, 0x95, 0x7B, 0x6D, 0x6A, 0xCB, 0x5A, 0x89, +0x83, 0xAD, 0xA4, 0xB0, 0xC5, 0xD4, 0xBD, 0xB3, +0xBD, 0x72, 0xDE, 0x76, 0xDE, 0x77, 0x94, 0x2F, +0x41, 0xE7, 0x41, 0xE7, 0x4A, 0x07, 0x52, 0x69, +0x94, 0x70, 0xA4, 0xD1, 0x7B, 0x8C, 0x52, 0x89, +0x31, 0x45, 0x18, 0xC3, 0x10, 0xA3, 0x10, 0xA3, +0x10, 0xA3, 0x10, 0xA3, 0x10, 0xA3, 0x10, 0x83, +0x08, 0x83, 0x08, 0x83, 0x08, 0x83, 0x08, 0x83, +0x10, 0x83, 0x10, 0xA3, 0x10, 0xA3, 0x10, 0xA3, +0x10, 0xC4, 0x10, 0xA3, 0x10, 0x83, 0x10, 0xA3, +0x10, 0xA3, 0x10, 0xA3, 0x10, 0xA3, 0x10, 0xA3, +0x10, 0xA3, 0x10, 0xA3, 0x10, 0xA3, 0x10, 0xA3, +0x10, 0xA3, 0x10, 0xA3, 0x10, 0xA3, 0x10, 0xC4, +0x19, 0x04, 0x31, 0x66, 0x5A, 0xAA, 0x9C, 0xB1, +0xA4, 0xD1, 0x73, 0x4C, 0x5A, 0xAB, 0x31, 0x87, +0x21, 0x26, 0x21, 0x26, 0x21, 0x26, 0x21, 0x26, +0x21, 0x26, 0x21, 0x26, 0x21, 0x26, 0x29, 0x67, +0x29, 0x87, 0x21, 0x46, 0x21, 0x46, 0x21, 0x05, +0x18, 0xE5, 0x21, 0x05, 0x29, 0x67, 0x31, 0x87, +0x39, 0xC7, 0x5A, 0xAA, 0x94, 0x4F, 0xCD, 0xF5, +0xDE, 0x56, 0xCD, 0xD4, 0x9C, 0x90, 0x94, 0x6F, +0x94, 0x4F, 0x8C, 0x2F, 0x94, 0x70, 0x94, 0x6F, +0x8C, 0x2E, 0x94, 0x4F, 0x9C, 0xD1, 0xAD, 0x33, +0xAD, 0x33, 0xA4, 0xF2, 0xA4, 0xF1, 0x9C, 0xD1, +0x3A, 0x07, 0x42, 0x06, 0x42, 0x27, 0x62, 0xEB, +0x84, 0x10, 0x52, 0xAA, 0x73, 0xAF, 0xC5, 0xD7, +0x9C, 0x71, 0x9C, 0x71, 0x9C, 0x71, 0x8C, 0x0D, +0xAD, 0x32, 0xB5, 0x93, 0x83, 0xED, 0x8B, 0xEC, +0xAC, 0xCF, 0xA4, 0x6D, 0x94, 0x2D, 0x9C, 0x8F, +0xA4, 0xB0, 0xA4, 0xB0, 0x9C, 0x6F, 0xA4, 0xF1, +0x94, 0x4E, 0x9C, 0x90, 0xA4, 0xF1, 0xAD, 0x12, +0x9C, 0x90, 0x9C, 0x90, 0xA4, 0xF1, 0xAD, 0x11, +0x7B, 0x8C, 0x83, 0xAC, 0x8C, 0x0E, 0xAD, 0x11, +0xBD, 0x93, 0xCD, 0xF5, 0xCE, 0x15, 0xBD, 0x72, +0xC5, 0xB2, 0xAC, 0xCF, 0x8B, 0xEC, 0xA5, 0x11, +0xAD, 0x11, 0xB5, 0x93, 0xBD, 0x93, 0xCE, 0x15, +0xCE, 0x35, 0xC5, 0xF4, 0xD6, 0x55, 0xC5, 0xF4, +0xBD, 0xB3, 0xB5, 0x73, 0xBD, 0x73, 0xBD, 0x93, +0x7B, 0x8C, 0x63, 0x0B, 0x6B, 0x2B, 0x4A, 0x28, +0x52, 0x89, 0x73, 0x8E, 0x5A, 0xEC, 0x73, 0xAE, +0x7B, 0xEF, 0x8C, 0x72, 0xAD, 0x55, 0x83, 0xF0, +0x73, 0x8E, 0xB5, 0x96, 0xAD, 0x76, 0x84, 0x10, +0x84, 0x10, 0x62, 0xEC, 0x39, 0xE7, 0x6B, 0x6D, +0xAD, 0x34, 0xB5, 0x75, 0xC5, 0xF6, 0xAD, 0x33, +0xA5, 0x33, 0xC6, 0x16, 0xCE, 0x36, 0xC6, 0x16, +0xC6, 0x15, 0xCE, 0x36, 0xC5, 0xF5, 0xCE, 0x15, +0xC5, 0x72, 0xB5, 0x0F, 0xEE, 0xB6, 0xD5, 0xD2, +0xE6, 0x54, 0xE6, 0x54, 0xEE, 0x75, 0xEE, 0xD6, +0xEE, 0xD6, 0xEE, 0xB5, 0xCD, 0x91, 0xD6, 0x14, +0xCD, 0xD3, 0xBD, 0x72, 0xC5, 0x71, 0xDE, 0x14, +0xC5, 0x91, 0xAC, 0xEF, 0xC5, 0xB3, 0xA4, 0xF0, +0x83, 0xED, 0x94, 0x2E, 0xA4, 0xF0, 0xA4, 0xF0, +0x9C, 0x90, 0x73, 0x6C, 0x73, 0x6C, 0x63, 0x0B, +0x62, 0xEB, 0x42, 0x07, 0x29, 0x44, 0x29, 0x24, +0x21, 0x03, 0x21, 0x03, 0x20, 0xE3, 0x29, 0x44, +0x39, 0xA6, 0x29, 0x64, 0x29, 0x24, 0x29, 0x64, +0x39, 0xA6, 0x42, 0x07, 0x39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+0x5A, 0x69, 0x7B, 0xAE, 0x62, 0x8A, 0x73, 0x2C, +0x8B, 0xCF, 0x83, 0xAE, 0x83, 0xAE, 0x8C, 0x0F, +0x73, 0x2B, 0x6A, 0xEA, 0x83, 0x8D, 0x94, 0x2E, +0xB5, 0x52, 0xEE, 0xD8, 0xBD, 0x94, 0x42, 0x08, +0x18, 0xC4, 0x10, 0xA3, 0x10, 0x82, 0x10, 0x83, +0x18, 0xE4, 0x29, 0x25, 0x20, 0xE4, 0x20, 0xE4, +0x18, 0xC3, 0x18, 0xA3, 0x10, 0xA3, 0x10, 0xA3, +0x10, 0xA3, 0x10, 0x83, 0x08, 0x83, 0x10, 0x83, +0x08, 0x83, 0x08, 0x83, 0x10, 0x83, 0x10, 0x83, +0x10, 0x83, 0x10, 0x83, 0x10, 0x83, 0x10, 0xA3, +0x10, 0xA3, 0x10, 0x83, 0x10, 0xA3, 0x10, 0xA3, +0x10, 0xA3, 0x10, 0xA3, 0x10, 0xA3, 0x10, 0xA3, +0x10, 0xC4, 0x10, 0xC4, 0x10, 0xA3, 0x10, 0xA3, +0x10, 0xA3, 0x10, 0xA3, 0x10, 0xA3, 0x10, 0xC4, +0x19, 0x04, 0x29, 0x46, 0x39, 0xC7, 0x84, 0x0E, +0xBD, 0xD4, 0x8B, 0xEE, 0x6B, 0x2C, 0x39, 0xC7, +0x29, 0x46, 0x21, 0x26, 0x21, 0x05, 0x21, 0x05, +0x21, 0x05, 0x21, 0x26, 0x21, 0x26, 0x29, 0x87, +0x21, 0x26, 0x21, 0x26, 0x21, 0x26, 0x21, 0x05, +0x21, 0x05, 0x18, 0xE5, 0x19, 0x05, 0x31, 0x67, +0x39, 0xE8, 0x4A, 0x49, 0x5A, 0xAA, 0xAC, 0xF1, +0xF7, 0x19, 0xCD, 0xF4, 0xAD, 0x12, 0x8C, 0x0E, +0x9C, 0xB0, 0x94, 0x90, 0xA4, 0xF1, 0xA4, 0xD1, +0x94, 0x70, 0x94, 0x70, 0xAD, 0x12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C5, 0x72, 0xC5, 0x73, 0xBD, 0x52, 0xA4, 0xB0, +0xAC, 0xF1, 0xAC, 0xF1, 0xB5, 0x12, 0xB5, 0x32, +0xAD, 0x31, 0xA4, 0xD0, 0xA4, 0xF0, 0xAD, 0x11, +0xAD, 0x11, 0xB5, 0x73, 0xB5, 0x52, 0xAD, 0x11, +0xAC, 0xF1, 0xAC, 0xF1, 0xAD, 0x11, 0xAD, 0x32, +0xAD, 0x11, 0xA4, 0xD0, 0x9C, 0x6F, 0x94, 0x4F, +0x94, 0x4F, 0x9C, 0x6F, 0x94, 0x2E, 0x7B, 0xAC, +0x41, 0xE7, 0x4A, 0x69, 0x7B, 0xEF, 0x8C, 0x30, +0x84, 0x10, 0x39, 0xC7, 0x8C, 0x71, 0x8C, 0x51, +0x9C, 0xB2, 0x9C, 0xD3, 0x83, 0xCF, 0x8C, 0x10, +0x83, 0xCE, 0x73, 0x6C, 0x6B, 0x0C, 0x5A, 0x8A, +0x62, 0xCB, 0x83, 0xCE, 0x7B, 0xAE, 0x73, 0x2C, +0x62, 0xCA, 0x9C, 0x50, 0x9C, 0x71, 0x8B, 0xEF, +0x94, 0x30, 0x73, 0x2C, 0x6A, 0xCB, 0x7B, 0x4C, +0x6B, 0x0B, 0xB5, 0x32, 0x7B, 0x8D, 0x20, 0xE4, +0x10, 0x83, 0x10, 0xA2, 0x10, 0xA3, 0x10, 0x83, +0x10, 0x83, 0x10, 0xA3, 0x10, 0xA3, 0x10, 0xA3, +0x10, 0xA3, 0x10, 0xA3, 0x10, 0xA3, 0x10, 0x83, +0x10, 0xA3, 0x10, 0x83, 0x08, 0x83, 0x10, 0x83, +0x10, 0x83, 0x10, 0x83, 0x10, 0xA3, 0x10, 0xA3, +0x10, 0x83, 0x10, 0xA3, 0x18, 0xC4, 0x10, 0xA3, +0x10, 0x83, 0x08, 0x83, 0x10, 0xA3, 0x10, 0xA3, +0x10, 0xA3, 0x10, 0xA3, 0x10, 0xA3, 0x10, 0x83, +0x10, 0x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0x69, 0x6B, 0x0C, 0x7B, 0x8E, +0x8B, 0xEF, 0x83, 0xAD, 0x7B, 0x4C, 0x93, 0xEF, +0x8B, 0xEF, 0xB5, 0x13, 0xA4, 0xB2, 0x7B, 0x6D, +0x6A, 0xEB, 0x83, 0xAF, 0x41, 0xE7, 0x18, 0xC4, +0x18, 0xE4, 0x18, 0xC3, 0x10, 0xA3, 0x10, 0x83, +0x10, 0x83, 0x10, 0x82, 0x10, 0x83, 0x10, 0x83, +0x10, 0xA3, 0x10, 0x83, 0x10, 0x83, 0x10, 0xA3, +0x10, 0xA3, 0x10, 0xA3, 0x10, 0xA3, 0x10, 0xC3, +0x18, 0xC4, 0x10, 0xA3, 0x18, 0xC3, 0x18, 0xE4, +0x31, 0x86, 0x4A, 0x69, 0x29, 0x65, 0x10, 0x83, +0x08, 0x83, 0x10, 0xA3, 0x10, 0xA3, 0x10, 0xA3, +0x10, 0xA3, 0x10, 0xA3, 0x10, 0xA3, 0x10, 0xA3, +0x10, 0xA3, 0x10, 0xA3, 0x10, 0xA3, 0x10, 0xA3, +0x10, 0xA3, 0x10, 0xA3, 0x10, 0xA3, 0x10, 0x83, +0x10, 0xA3, 0x18, 0xE4, 0x21, 0x04, 0x41, 0xC7, +0x83, 0xCE, 0xA4, 0xB1, 0x8C, 0x2F, 0x7B, 0xAE, +0x52, 0xAA, 0x31, 0x86, 0x21, 0x25, 0x21, 0x05, +0x19, 0x05, 0x18, 0xE5, 0x21, 0x25, 0x21, 0x46, +0x18, 0xE5, 0x18, 0xE5, 0x18, 0xE5, 0x18, 0xE4, +0x21, 0x25, 0x29, 0x46, 0x29, 0x66, 0x29, 0x66, +0x21, 0x46, 0x21, 0x25, 0x29, 0x66, 0x4A, 0x28, +0xBD, 0x94, 0xC5, 0xD4, 0xB5, 0x53, 0x9C, 0xB1, +0xAD, 0x32, 0xAD, 0x32, 0xBD, 0xB4, 0xA4, 0xD1, +0xA4, 0xF2, 0xA4, 0xF1, 0xBD, 0xB4, 0xAD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0xD0, 0xBD, 0x94, 0x94, 0x4F, 0x84, 0x0E, +0x8C, 0x2F, 0x94, 0x8F, 0xA4, 0xD0, 0xAD, 0x11, +0x94, 0x2E, 0x9C, 0xB0, 0xBD, 0x93, 0xA4, 0xF0, +0x9C, 0xAF, 0x94, 0x4E, 0x9C, 0xB0, 0xB5, 0x52, +0xA4, 0xF1, 0xA4, 0xD0, 0xBD, 0xB4, 0xB5, 0x72, +0xA4, 0xB0, 0xA4, 0xD0, 0xA4, 0xD0, 0xA4, 0xB0, +0xA4, 0xD0, 0xAD, 0x11, 0xB5, 0x53, 0xCE, 0x15, +0xBD, 0x94, 0xA4, 0xF2, 0x94, 0x70, 0x84, 0x0F, +0x6B, 0x2C, 0x4A, 0x48, 0x4A, 0x48, 0x4A, 0x28, +0x31, 0x85, 0x29, 0x45, 0x29, 0x44, 0x39, 0xE7, +0x52, 0xAA, 0x6B, 0x4D, 0x73, 0x8E, 0x7B, 0xAE, +0x9C, 0xD2, 0x8C, 0x30, 0x63, 0x0C, 0x62, 0xAA, +0x7B, 0x6D, 0x62, 0xCA, 0x6A, 0xEB, 0x83, 0x8D, +0x94, 0x0F, 0xB5, 0x13, 0xB5, 0x13, 0x6B, 0x0B, +0x5A, 0x8A, 0x5A, 0x69, 0x49, 0xE8, 0x18, 0xC4, +0x21, 0x25, 0x21, 0x45, 0x10, 0xA3, 0x10, 0x82, +0x10, 0xA3, 0x10, 0x83, 0x10, 0x82, 0x10, 0x82, +0x10, 0x83, 0x10, 0x83, 0x10, 0x83, 0x10, 0xA3, +0x10, 0xC3, 0x18, 0xC4, 0x18, 0xE4, 0x18, 0xE4, +0x18, 0xE4, 0x18, 0xE4, 0x4A, 0x28, 0x8C, 0x50, +0x94, 0x70, 0x9C, 0x90, 0x73, 0x6C, 0x31, 0xA6, +0x10, 0xA3, 0x10, 0xA3, 0x10, 0xA3, 0x10, 0xA3, +0x10, 0xA3, 0x10, 0xA3, 0x10, 0xA3, 0x10, 0xA3, +0x10, 0xA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0x7B, 0xEF, 0xA5, 0x13, 0x94, 0x71, +0x73, 0x4D, 0x73, 0x2C, 0x73, 0x2C, 0x7B, 0x4C, +0x83, 0x6D, 0x8B, 0xEF, 0xA4, 0x91, 0x52, 0x28, +0x31, 0x65, 0x52, 0x28, 0x4A, 0x28, 0x39, 0x87, +0x18, 0xC3, 0x19, 0x04, 0x21, 0x05, 0x18, 0xC3, +0x18, 0xC4, 0x10, 0xC3, 0x10, 0x83, 0x10, 0xA3, +0x10, 0xA3, 0x10, 0xA3, 0x10, 0xC3, 0x10, 0xC3, +0x10, 0xA3, 0x18, 0xC3, 0x18, 0xE4, 0x21, 0x04, +0x52, 0x69, 0x7B, 0xAD, 0x9C, 0x70, 0xA4, 0xB0, +0x9C, 0x90, 0xAC, 0xF2, 0xAC, 0xF2, 0x83, 0xEE, +0x41, 0xE7, 0x10, 0xC3, 0x10, 0xA3, 0x10, 0xA3, +0x10, 0xA3, 0x10, 0xA3, 0x10, 0xA3, 0x10, 0xA3, +0x10, 0xA3, 0x10, 0xA3, 0x10, 0x83, 0x10, 0xA3, +0x10, 0xA3, 0x10, 0xA3, 0x10, 0xA3, 0x10, 0xA3, +0x10, 0xA3, 0x10, 0xA3, 0x10, 0xA3, 0x18, 0xC3, +0x29, 0x46, 0x5A, 0xAA, 0x94, 0x6F, 0xAD, 0x12, +0x73, 0x6C, 0x5A, 0xCB, 0x42, 0x29, 0x29, 0x66, +0x21, 0x25, 0x19, 0x05, 0x19, 0x05, 0x19, 0x05, +0x18, 0xE4, 0x18, 0xE4, 0x21, 0x26, 0x29, 0x67, +0x21, 0x25, 0x19, 0x05, 0x21, 0x05, 0x19, 0x05, +0x21, 0x05, 0x29, 0x46, 0x31, 0x87, 0x39, 0xC7, +0x52, 0x8A, 0x9C, 0xB1, 0xAD, 0x12, 0x9C, 0xB0, +0x9C, 0xB0, 0xA5, 0x12, 0xAD, 0x12, 0xA4, 0xF1, +0xAD, 0x53, 0xAD, 0x53, 0xAD, 0x32, 0xB5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0xA3, 0x10, 0xA3, +0x10, 0xA3, 0x10, 0xA3, 0x10, 0x83, 0x10, 0xA3, +0x10, 0xA3, 0x10, 0xA3, 0x10, 0xA3, 0x10, 0xA3, +0x10, 0x83, 0x10, 0x83, 0x10, 0xA3, 0x10, 0xA3, +0x18, 0xC4, 0x29, 0x45, 0x83, 0xEE, 0xAC, 0xF1, +0xA4, 0xB0, 0x94, 0x2F, 0x6B, 0x2C, 0x42, 0x08, +0x29, 0x46, 0x21, 0x25, 0x19, 0x04, 0x18, 0xE4, +0x18, 0xE4, 0x18, 0xE5, 0x21, 0x46, 0x21, 0x25, +0x19, 0x05, 0x19, 0x05, 0x19, 0x05, 0x19, 0x05, +0x21, 0x25, 0x29, 0x46, 0x29, 0x46, 0x29, 0x66, +0x41, 0xE8, 0x83, 0xEF, 0xA4, 0xB1, 0x9C, 0xB1, +0xA4, 0xF2, 0x9C, 0xB1, 0xA4, 0xF1, 0x9C, 0xB1, +0x9C, 0xD1, 0xB5, 0x94, 0x9C, 0xB0, 0xBD, 0x93, +0xB5, 0x93, 0xAD, 0x53, 0x9C, 0xB1, 0x9C, 0xD1, +0x94, 0xD1, 0x8C, 0x6F, 0xA5, 0x11, 0xA5, 0x11, +0xA5, 0x31, 0xAD, 0x52, 0xB5, 0x92, 0xB5, 0x92, +0xB5, 0x93, 0x52, 0xC8, 0x31, 0xA5, 0x31, 0xA6, +0x39, 0xE7, 0x42, 0x07, 0x4A, 0x48, 0x83, 0xEF, +0x73, 0x6D, 0x73, 0x6D, 0x6B, 0x2D, 0xC6, 0x18, +0xE6, 0xFB, 0x94, 0x2F, 0xA4, 0xB0, 0xC5, 0xD4, +0xB5, 0x52, 0xBD, 0xB4, 0xBD, 0xB5, 0xB5, 0x74, +0xAD, 0x53, 0xAD, 0x53, 0x9C, 0xD2, 0xA5, 0x33, +0xB5, 0x74, 0xAD, 0x73, 0xAD, 0x33, 0xAD, 0x33, +0xAD, 0x53, 0xAD, 0x53, 0xAD, 0x53, 0xAD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0x83, 0xCE, 0x42, 0x07, +0x31, 0x85, 0x29, 0x65, 0x29, 0x45, 0x29, 0x65, +0x52, 0x8A, 0x8C, 0x51, 0x94, 0x71, 0x8C, 0x0F, +0x5A, 0x89, 0x5A, 0x8A, 0x62, 0xAA, 0x94, 0x30, +0xAC, 0xF3, 0x73, 0x2C, 0x4A, 0x08, 0x49, 0xE7, +0x6A, 0xCA, 0x5A, 0x69, 0x31, 0x86, 0x10, 0xA3, +0x18, 0xC3, 0x10, 0xA3, 0x21, 0x04, 0x52, 0xAA, +0x4A, 0x29, 0x42, 0x29, 0x52, 0xAA, 0x94, 0x91, +0x9C, 0xB1, 0x94, 0x70, 0xA4, 0xD1, 0xBD, 0x94, +0xAC, 0xF1, 0x94, 0x6F, 0xAC, 0xF0, 0xB5, 0x52, +0xB5, 0x52, 0x9C, 0xB0, 0x9C, 0x8F, 0x94, 0x4E, +0x9C, 0x90, 0x83, 0xCE, 0x31, 0x86, 0x18, 0xE4, +0x10, 0xC3, 0x10, 0xA3, 0x10, 0xA3, 0x10, 0x83, +0x10, 0x83, 0x10, 0xA3, 0x10, 0xA3, 0x10, 0xA3, +0x10, 0xA3, 0x10, 0xA3, 0x10, 0xA3, 0x10, 0xA3, +0x10, 0xA3, 0x10, 0x83, 0x10, 0xA3, 0x08, 0x82, +0x10, 0xA3, 0x29, 0x24, 0x8C, 0x0F, 0xB5, 0x52, +0xBD, 0x73, 0xB5, 0x32, 0x94, 0x6F, 0x63, 0x0A, +0x39, 0xC7, 0x29, 0x66, 0x21, 0x05, 0x18, 0xE4, +0x19, 0x04, 0x19, 0x05, 0x21, 0x25, 0x19, 0x05, +0x18, 0xE4, 0x18, 0xE4, 0x19, 0x05, 0x21, 0x25, +0x21, 0x25, 0x21, 0x45, 0x21, 0x45, 0x29, 0x66, +0x31, 0x87, 0x73, 0x4C, 0xB5, 0x33, 0xBD, 0x94, +0xB5, 0x53, 0xAD, 0x32, 0xAD, 0x12, 0xA4, 0xD1, +0x9C, 0xB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10, 0xA3, 0x10, 0x83, 0x10, 0x83, +0x10, 0x83, 0x10, 0x83, 0x10, 0xA3, 0x10, 0x83, +0x10, 0x83, 0x10, 0xA3, 0x10, 0xA3, 0x10, 0x83, +0x10, 0x83, 0x10, 0x83, 0x10, 0x83, 0x10, 0x83, +0x10, 0xA3, 0x21, 0x04, 0x83, 0xCE, 0xD6, 0x15, +0xD5, 0xF4, 0xC5, 0x72, 0xBD, 0x72, 0x9C, 0x8F, +0x73, 0x4C, 0x41, 0xE7, 0x29, 0x45, 0x21, 0x05, +0x19, 0x04, 0x19, 0x04, 0x19, 0x05, 0x19, 0x04, +0x18, 0xE4, 0x18, 0xE4, 0x21, 0x25, 0x21, 0x25, +0x21, 0x25, 0x21, 0x25, 0x21, 0x25, 0x29, 0x46, +0x39, 0xC7, 0x6B, 0x2C, 0x9C, 0x90, 0xA4, 0xD1, +0x9C, 0xB0, 0x94, 0x4F, 0x9C, 0x90, 0x9C, 0x90, +0x9C, 0xB0, 0xA4, 0xD0, 0xA4, 0xD0, 0xA4, 0xF1, +0xB5, 0x52, 0xAD, 0x12, 0xAD, 0x32, 0xB5, 0x52, +0x95, 0x32, 0x63, 0xCA, 0x8C, 0xEF, 0xAD, 0x72, +0xAD, 0x52, 0xA5, 0x31, 0xA5, 0x6F, 0x8C, 0xCA, +0x7C, 0x68, 0xAD, 0xAD, 0xB5, 0xB1, 0xAD, 0x31, +0x52, 0xA8, 0x31, 0x85, 0x42, 0x28, 0x5A, 0xCA, +0x4A, 0x28, 0x5A, 0xEB, 0x84, 0x10, 0xAD, 0x75, +0xA5, 0x34, 0xBE, 0x18, 0xEF, 0x7D, 0xDE, 0xB9, +0xB5, 0x94, 0xC5, 0xF5, 0xBD, 0xF6, 0xC5, 0xF6, +0xBD, 0xD5, 0x9C, 0xB1, 0x94, 0x70, 0xBD, 0xB5, +0xB5, 0xB5, 0xB5, 0xB4, 0xB5, 0x94, 0xB5, 0x73, +0xB5, 0x74, 0xB5, 0x94, 0xAD, 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D6, 0x76, +0xDE, 0x97, 0xCE, 0x15, 0x94, 0x6F, 0x4A, 0x27, +0x31, 0x85, 0x29, 0x65, 0x31, 0x85, 0x4A, 0x49, +0x83, 0xCF, 0x62, 0xEB, 0x52, 0x69, 0x4A, 0x28, +0x4A, 0x28, 0x5A, 0x69, 0x62, 0x8A, 0x4A, 0x07, +0x52, 0x28, 0x52, 0x07, 0x62, 0x89, 0x83, 0x8D, +0x62, 0x8A, 0x4A, 0x08, 0x4A, 0x29, 0x52, 0x69, +0x83, 0xCF, 0xCE, 0x57, 0xDE, 0xD8, 0xDE, 0x97, +0xE6, 0xD8, 0xBD, 0x73, 0xA4, 0xD1, 0xB5, 0x32, +0xE6, 0xF8, 0xE6, 0xD7, 0xDE, 0x97, 0xE6, 0xB7, +0xDE, 0x75, 0xDE, 0x75, 0xDE, 0x75, 0xDE, 0x96, +0xDE, 0x76, 0xDE, 0x55, 0xD6, 0x15, 0xBD, 0x73, +0x83, 0xCD, 0x39, 0xA6, 0x31, 0x65, 0x18, 0xE4, +0x10, 0xA3, 0x10, 0xA3, 0x10, 0x83, 0x08, 0x83, +0x08, 0x83, 0x10, 0xA3, 0x10, 0xA3, 0x10, 0xA3, +0x10, 0x83, 0x10, 0x83, 0x10, 0x83, 0x10, 0xA3, +0x10, 0xA3, 0x18, 0xC3, 0xA4, 0xD2, 0xE6, 0x76, +0xDE, 0x34, 0xD5, 0xF4, 0xD6, 0x14, 0xBD, 0x72, +0x8C, 0x2E, 0x62, 0xEA, 0x31, 0x86, 0x29, 0x45, +0x21, 0x25, 0x21, 0x25, 0x21, 0x25, 0x19, 0x05, +0x18, 0xE4, 0x19, 0x04, 0x21, 0x25, 0x19, 0x05, +0x19, 0x05, 0x19, 0x05, 0x21, 0x05, 0x21, 0x46, +0x39, 0xE8, 0x7B, 0x8D, 0x8C, 0x0E, 0x8C, 0x0E, +0x9C, 0x6F, 0x94, 0x4F, 0x94, 0x6F, 0x9C, 0x8F, +0x9C, 0xB0, 0x94, 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 0xA4, 0xB1, 0xAD, 0x12, 0x4A, 0x28, +0x10, 0xC3, 0x10, 0x83, 0x08, 0x83, 0x10, 0x82, +0x10, 0x83, 0x08, 0x83, 0x08, 0x83, 0x08, 0x82, +0x08, 0x82, 0x10, 0xA3, 0x10, 0x83, 0x10, 0xA3, +0x18, 0xE4, 0x21, 0x04, 0xBD, 0x94, 0xE6, 0xB7, +0xDE, 0x34, 0xD5, 0xF3, 0xC5, 0xB2, 0xBD, 0x52, +0xA4, 0xD0, 0x83, 0xAC, 0x41, 0xE7, 0x39, 0xC6, +0x29, 0x66, 0x21, 0x46, 0x21, 0x25, 0x19, 0x04, +0x18, 0xE4, 0x21, 0x05, 0x21, 0x05, 0x19, 0x05, +0x19, 0x04, 0x19, 0x04, 0x21, 0x05, 0x29, 0x66, +0x4A, 0x49, 0x8C, 0x50, 0x94, 0x6F, 0x8B, 0xED, +0xB5, 0x32, 0xB5, 0x32, 0xB5, 0x32, 0xA4, 0xD0, +0x94, 0x6F, 0x8C, 0x0E, 0x8C, 0x2E, 0xA4, 0xF1, +0xB5, 0x53, 0xAD, 0x12, 0xB5, 0x52, 0xBD, 0x73, +0x64, 0x29, 0x64, 0x49, 0x8D, 0x4E, 0xBE, 0x75, +0x94, 0xCF, 0x74, 0x09, 0x74, 0x86, 0x6C, 0x64, +0x6C, 0x64, 0x8D, 0x09, 0x8C, 0x8B, 0x9C, 0xAD, +0xAD, 0x50, 0xB5, 0x50, 0x8C, 0x0C, 0x4A, 0x67, +0x39, 0xC6, 0x4A, 0x48, 0x52, 0xCA, 0x63, 0x0C, +0x8C, 0x92, 0xA5, 0x35, 0xBD, 0xF8, 0xBD, 0xD7, +0xDE, 0xFB, 0x9C, 0xD2, 0xA4, 0xF2, 0x94, 0x2E, +0x9C, 0x6E, 0x9C, 0x6E, 0x9C, 0x6E, 0x94, 0x4E, +0x8C, 0x0C, 0x94, 0x2D, 0x9C, 0x6E, 0x94, 0x2D, +0x83, 0xEC, 0x83, 0xCC, 0x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 0xDE, 0x55, 0xD6, 0x35, +0xDE, 0x55, 0xD6, 0x15, 0xD5, 0xF4, 0xC5, 0xB3, +0xC5, 0xB3, 0xB5, 0x52, 0x6B, 0x0A, 0x31, 0x65, +0x29, 0x45, 0x31, 0x85, 0x52, 0x8A, 0x94, 0x71, +0x94, 0x71, 0x73, 0x2D, 0x52, 0x69, 0x52, 0x29, +0x52, 0x28, 0x73, 0x2C, 0x73, 0x0C, 0x5A, 0x48, +0x73, 0x0B, 0x73, 0x0C, 0x94, 0x10, 0x73, 0x4C, +0x6B, 0x0B, 0xA4, 0xB2, 0xBD, 0x95, 0xA4, 0xD1, +0xDE, 0x98, 0xBD, 0x73, 0xB5, 0x32, 0xBD, 0x73, +0xD6, 0x56, 0xDE, 0x75, 0xDE, 0x96, 0xE6, 0x96, +0xDE, 0x54, 0xE6, 0x75, 0xEE, 0xB6, 0xE6, 0x95, +0xE6, 0x75, 0xE6, 0x95, 0xE6, 0x95, 0xD6, 0x14, +0xDE, 0x35, 0xDE, 0x76, 0xE6, 0x97, 0x8B, 0xED, +0x4A, 0x28, 0x20, 0xE4, 0x10, 0x83, 0x08, 0x63, +0x10, 0x83, 0x10, 0x83, 0x08, 0x82, 0x08, 0x82, +0x08, 0x82, 0x10, 0x83, 0x10, 0xA3, 0x18, 0xC3, +0x18, 0xE4, 0x39, 0xA6, 0xD6, 0x56, 0xD6, 0x14, +0xD6, 0x13, 0xD6, 0x14, 0xDE, 0x75, 0xD6, 0x34, +0xC5, 0x93, 0x9C, 0x4E, 0x73, 0x4B, 0x62, 0xEA, +0x42, 0x07, 0x31, 0x86, 0x29, 0x46, 0x29, 0x25, +0x21, 0x05, 0x21, 0x05, 0x21, 0x04, 0x19, 0x04, +0x18, 0xE4, 0x18, 0xE4, 0x21, 0x25, 0x31, 0xA7, +0x73, 0x8D, 0xA4, 0xF1, 0x83, 0xCC, 0x6B, 0x0A, +0xAD, 0x12, 0xAD, 0x32, 0xAD, 0x32, 0xBD, 0x93, +0xB5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, 0x54, 0xDE, 0x34, +0xEE, 0xB6, 0xF6, 0xF7, 0xEE, 0xD7, 0xBD, 0x72, +0x9C, 0x6F, 0x6B, 0x0B, 0x31, 0x65, 0x10, 0x83, +0x10, 0xA3, 0x10, 0x83, 0x08, 0x82, 0x08, 0x82, +0x08, 0x82, 0x10, 0x83, 0x10, 0x83, 0x18, 0xC4, +0x18, 0xE4, 0x73, 0x8C, 0xE6, 0xF8, 0xD6, 0x13, +0xDE, 0x54, 0xDE, 0x54, 0xDE, 0x54, 0xDE, 0x54, +0xCE, 0x14, 0xB5, 0x52, 0xA4, 0xD0, 0x83, 0xED, +0x62, 0xEA, 0x39, 0xE7, 0x39, 0xE7, 0x39, 0xC7, +0x29, 0x46, 0x21, 0x25, 0x21, 0x04, 0x21, 0x04, +0x18, 0xE4, 0x21, 0x05, 0x29, 0x66, 0x52, 0x6A, +0xBD, 0xB5, 0xCE, 0x35, 0x94, 0x6F, 0x62, 0xC9, +0xAD, 0x12, 0xCE, 0x15, 0xC5, 0xF5, 0xCE, 0x15, +0xCE, 0x15, 0xC5, 0xD4, 0xBD, 0x94, 0xBD, 0x94, +0xC5, 0xD5, 0xCE, 0x15, 0xD6, 0x35, 0xD6, 0x35, +0x53, 0xC6, 0x64, 0x67, 0x5B, 0xC7, 0x53, 0x66, +0x74, 0x8C, 0x7C, 0xAC, 0x74, 0x69, 0x5B, 0xE5, +0xA6, 0x30, 0x95, 0x6F, 0x94, 0xEE, 0xA5, 0x0F, +0xB5, 0x92, 0xAD, 0x51, 0xA4, 0xF0, 0xB5, 0x50, +0xAD, 0x10, 0x62, 0xE9, 0x42, 0x07, 0x3A, 0x07, +0x4A, 0x89, 0x6B, 0x6D, 0x8C, 0x71, 0xAD, 0x76, +0x84, 0x11, 0x94, 0x72, 0xBD, 0xD7, 0x84, 0x30, +0x52, 0x68, 0x83, 0xED, 0x9C, 0x8F, 0x8C, 0x0C, +0x94, 0x4D, 0x9C, 0x6E, 0xA4, 0xAE, 0xB5, 0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, 0x32, 0xB5, 0x12, 0xB5, 0x12, 0xB5, 0x12, +0xAC, 0xF2, 0xAD, 0x12, 0xB5, 0x53, 0xB5, 0x12, +0xAC, 0xF1, 0xA4, 0xD1, 0xAC, 0xF1, 0xAD, 0x11, +0xAD, 0x11, 0xAD, 0x11, 0x94, 0x4F, 0x39, 0xA6, +0x10, 0x82, 0x10, 0x82, 0x10, 0x82, 0x10, 0x82, +0x10, 0x82, 0x10, 0x82, 0x10, 0xC3, 0x18, 0xC3, +0x31, 0xA7, 0x94, 0x70, 0xA4, 0xD0, 0xAD, 0x11, +0xB5, 0x31, 0xBD, 0x92, 0xBD, 0x92, 0xBD, 0x72, +0xBD, 0x72, 0xAD, 0x11, 0xAD, 0x11, 0xAD, 0x11, +0xA4, 0xF1, 0x8C, 0x2E, 0x83, 0xED, 0x6B, 0x0B, +0x52, 0x89, 0x42, 0x08, 0x31, 0xA7, 0x31, 0x86, +0x39, 0xA7, 0x4A, 0x69, 0x7B, 0xCE, 0x9C, 0xD1, +0xBD, 0xD4, 0xB5, 0x52, 0xBD, 0xB4, 0x94, 0x4F, +0x83, 0xED, 0xDE, 0x97, 0xD6, 0x77, 0xD6, 0x56, +0xD6, 0x56, 0xD6, 0x57, 0xD6, 0x77, 0xD6, 0x77, +0xBD, 0xB4, 0xB5, 0x73, 0xBD, 0x93, 0xBD, 0x73, +0x32, 0xA3, 0x6C, 0x4A, 0x9D, 0xD2, 0x9D, 0xB2, +0x74, 0x4C, 0x7C, 0x8C, 0x7C, 0xAB, 0x7C, 0x8A, +0x6C, 0x49, 0x74, 0x6A, 0x8D, 0x0C, 0x84, 0xA9, +0x84, 0xCA, 0x8C, 0xAC, 0x8C, 0x6C, 0xA4, 0xCE, +0xC5, 0xD3, 0xC6, 0x15, 0xC5, 0xF5, 0x7B, 0xCE, +0x39, 0xE6, 0x39, 0xE6, 0x42, 0x48, 0x5A, 0xEB, +0x84, 0x31, 0x84, 0x10, 0x94, 0x92, 0x73, 0x6D, +0x7B,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, 0x4E, +0xAD, 0x32, 0xBD, 0x93, 0xA4, 0xF1, 0xA4, 0x90, +0xA4, 0xD0, 0x9C, 0x8F, 0xA4, 0xAF, 0xA4, 0xD0, +0xA4, 0xD0, 0xAD, 0x11, 0xB5, 0x52, 0xBD, 0x73, +0xBD, 0x72, 0xBD, 0x72, 0xB5, 0x52, 0xB5, 0x31, +0xB5, 0x31, 0xB5, 0x31, 0x9C, 0x8F, 0x8B, 0xED, +0x8B, 0xCC, 0x94, 0x2D, 0xAC, 0xF0, 0xA4, 0xD0, +0x83, 0xED, 0x52, 0x67, 0x29, 0x65, 0x29, 0x45, +0x39, 0x85, 0x41, 0xC7, 0x4A, 0x69, 0x7B, 0xCF, +0x9C, 0xF3, 0x94, 0x71, 0x41, 0xE8, 0x5A, 0x8A, +0x73, 0x0B, 0x94, 0x30, 0x8B, 0xEF, 0x5A, 0xAA, +0x4A, 0x49, 0x52, 0x49, 0x4A, 0x28, 0x73, 0x6D, +0x94, 0x50, 0x8C, 0x0E, 0xB5, 0x32, 0xAC, 0xF1, +0xCD, 0xF5, 0xBD, 0x93, 0xB5, 0x12, 0xB5, 0x52, +0xBD, 0x73, 0xBD, 0x52, 0xBD, 0x94, 0xBD, 0x73, +0xB5, 0x52, 0xAD, 0x32, 0xBD, 0x73, 0xB5, 0x73, +0xB5, 0x73, 0xB5, 0x53, 0xAD, 0x33, 0x4A, 0x48, +0x18, 0xA3, 0x10, 0x82, 0x10, 0x82, 0x10, 0x82, +0x10, 0x82, 0x10, 0xA3, 0x18, 0xE4, 0x18, 0xE4, +0x63, 0x2C, 0xB5, 0x53, 0xAC, 0xF1, 0xB5, 0x32, +0xB5, 0x73, 0xAD, 0x32, 0xAD, 0x32, 0xB5, 0x52, +0xB5, 0x73, 0xB5, 0x73, 0xB5, 0x73, 0xB5, 0x52, +0xAD, 0x32, 0xA4, 0xD1, 0x94, 0x4F, 0x8B, 0xEE, +0x73, 0x6C, 0x63, 0x0B, 0x52, 0x89, 0x52, 0x89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D, 0x31, +0xB5, 0x10, 0xBD, 0x31, 0xBD, 0x72, 0xBD, 0x52, +0xC5, 0x93, 0xC5, 0x92, 0xAD, 0x10, 0xAC, 0xF0, +0x62, 0xC9, 0x31, 0xA6, 0x42, 0x07, 0x73, 0x8D, +0x83, 0xEF, 0x52, 0x49, 0x29, 0x24, 0x5A, 0x69, +0x83, 0xAE, 0x83, 0x8E, 0x94, 0x51, 0x83, 0xEF, +0x73, 0x6E, 0x6B, 0x4D, 0xA4, 0xF4, 0xD6, 0x79, +0x8C, 0x31, 0x41, 0xE8, 0x5A, 0xCB, 0x8C, 0x31, +0xB5, 0x76, 0xDE, 0xBA, 0xE6, 0xFB, 0xE6, 0xFC, +0xD6, 0x59, 0xF7, 0x5C, 0xDE, 0x37, 0xA4, 0x6F, +0x94, 0x0D, 0xA4, 0xB0, 0x8C, 0x0F, 0x6B, 0x4C, +0x84, 0x10, 0x94, 0x92, 0xC6, 0x18, 0xC5, 0xF7, +0x5A, 0xCA, 0x39, 0xC6, 0x39, 0xE6, 0x39, 0xC6, +0x42, 0x07, 0x39, 0xC6, 0x39, 0xC6, 0x42, 0x07, +0x42, 0x08, 0x42, 0x29, 0x4A, 0x49, 0x5A, 0xCB, +0x63, 0x2D, 0x52, 0x8A, 0x39, 0xE8, 0x31, 0x86, +0x39, 0xE7, 0x5A, 0xCB, 0x84, 0x10, 0xAD, 0x34, +0xB5, 0x53, 0xA4, 0xD1, 0xA5, 0x12, 0xCE, 0x15, +0xDE, 0x97, 0xA4, 0xF0, 0xBD, 0x93, 0xC5, 0xB4, +0xBD, 0x73, 0x9C, 0xB0, 0xB5, 0x52, 0xB5, 0x52, +0xBD, 0x73, 0xB5, 0x52, 0xB5, 0x52, 0xAC, 0xF1, +0xBD, 0x94, 0xBD, 0xB4, 0xBD, 0x73, 0xB5, 0x52, +0xAD, 0x32, 0xA4, 0xD0, 0xB5, 0x32, 0xB5, 0x52, +0xB5, 0x52, 0xBD, 0x93, 0xBD, 0xB4, 0xB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0xA5, 0x11, 0x83, 0xEE, 0x7B, 0x8C, 0x7B, 0xAD, +0x83, 0xCD, 0x83, 0xEE, 0x83, 0xAD, 0x6B, 0x0B, +0x4A, 0x08, 0x41, 0xE7, 0x31, 0x65, 0x42, 0x27, +0x42, 0x07, 0x41, 0xE7, 0x31, 0x86, 0x31, 0xA6, +0x4A, 0x69, 0x52, 0x89, 0x5B, 0x0A, 0x42, 0xA7, +0x42, 0xC7, 0x53, 0x28, 0x42, 0xC6, 0x53, 0x88, +0x6C, 0x4B, 0x4B, 0x07, 0x95, 0x6F, 0x9D, 0xD0, +0x95, 0x90, 0x95, 0xB0, 0x7C, 0xEC, 0x74, 0xCA, +0x74, 0xAA, 0x21, 0xC3, 0x19, 0x43, 0x32, 0x05, +0x11, 0x02, 0x63, 0xAB, 0x95, 0x70, 0x8D, 0x2F, +0x43, 0x06, 0x19, 0xA1, 0x32, 0x83, 0x4B, 0x85, +0x5C, 0x46, 0x54, 0x04, 0x4B, 0xA4, 0x4B, 0x85, +0x7B, 0xEF, 0x73, 0x8D, 0x73, 0x8D, 0x7B, 0xEE, +0x84, 0x0F, 0x8C, 0x4F, 0xC5, 0xF5, 0xD6, 0x35, +0xD6, 0x14, 0xD6, 0x34, 0xDE, 0x55, 0xDE, 0x76, +0xCE, 0x15, 0x9C, 0x4E, 0x93, 0xCC, 0x93, 0xCC, +0xA4, 0x6E, 0xDE, 0x55, 0xE6, 0x76, 0xDE, 0x76, +0xD6, 0x14, 0xDE, 0x55, 0xDE, 0x55, 0xDE, 0x55, +0xDE, 0x75, 0xDE, 0x75, 0xE6, 0xB6, 0xDE, 0x55, +0xDE, 0x55, 0xD6, 0x14, 0xDE, 0x76, 0xDE, 0x76, +0xE6, 0x96, 0xE6, 0xB7, 0xE6, 0xB7, 0xE6, 0x76, +0xBD, 0x31, 0xC5, 0x71, 0xD5, 0xB3, 0xD5, 0xD3, +0xD5, 0xD4, 0xC5, 0x72, 0xC5, 0x51, 0xD5, 0x72, +0xDD, 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xD4, 0xB5, 0x94, 0xAD, 0x32, 0xAD, 0x32, +0xBD, 0xB4, 0xCE, 0x15, 0xD6, 0x35, 0xCD, 0xF4, +0xBD, 0x72, 0xB5, 0x11, 0xB5, 0x52, 0xAC, 0xF1, +0xB5, 0x32, 0xBD, 0x53, 0xBD, 0x53, 0xBD, 0x73, +0xB5, 0x32, 0xBD, 0x73, 0xC5, 0xB4, 0xC5, 0xD5, +0xAD, 0x32, 0xA4, 0xD1, 0xA4, 0xF1, 0xCD, 0xB4, +0xC5, 0x93, 0xDE, 0x56, 0xD6, 0x57, 0xD6, 0x57, +0xD6, 0x37, 0xCE, 0x16, 0xCE, 0x37, 0xCE, 0x58, +0xCE, 0x58, 0xCE, 0x59, 0xC6, 0x38, 0xBD, 0xD7, +0xAD, 0x55, 0xA5, 0x14, 0x8C, 0x30, 0x7B, 0xAE, +0x8C, 0x10, 0x9C, 0xB2, 0xAD, 0x33, 0xB5, 0x74, +0xB5, 0x53, 0xB5, 0x53, 0xAD, 0x53, 0xAD, 0x32, +0xA5, 0x12, 0xB5, 0x53, 0xAD, 0x53, 0xAD, 0x53, +0xB5, 0x74, 0xB5, 0x53, 0xAD, 0x33, 0xAD, 0x12, +0xA4, 0xD2, 0x94, 0x70, 0x83, 0xEF, 0x4A, 0x08, +0x94, 0x30, 0x9C, 0xB1, 0x83, 0xEF, 0x84, 0x10, +0x94, 0x71, 0x7C, 0x0E, 0x73, 0xEC, 0x5B, 0xEA, +0x6C, 0x6B, 0x53, 0xA8, 0x32, 0x44, 0x43, 0x06, +0x42, 0xC6, 0x42, 0xE6, 0x6C, 0x6A, 0x85, 0x2D, +0x8D, 0x8F, 0x95, 0xAF, 0x85, 0x2D, 0x85, 0x2C, +0x85, 0x4D, 0x3A, 0xA5, 0x42, 0x66, 0x31, 0xE5, +0x10, 0xC2, 0x19, 0x43, 0x5B, 0x8A, 0x9D, 0x70, +0x5B, 0x89, 0x32, 0x44, 0x22, 0x02, 0x32, 0xC3, +0x53, 0xC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, 0x9C, 0x8D, +0xA5, 0x2F, 0xB5, 0xD1, 0xB5, 0xF1, 0xB5, 0xF1, +0xA5, 0x70, 0x7C, 0x0C, 0x42, 0x26, 0x29, 0x64, +0x31, 0x86, 0x29, 0x44, 0x31, 0xA6, 0x39, 0xE7, +0x4A, 0x69, 0x73, 0x8E, 0x94, 0xB3, 0x94, 0x72, +0x8C, 0x51, 0xAD, 0x35, 0xA5, 0x15, 0x84, 0x10, +0x9C, 0xB3, 0x8C, 0x31, 0x6B, 0x4D, 0x8C, 0x51, +0x94, 0x71, 0xAD, 0x55, 0x6B, 0x6D, 0x63, 0x2C, +0x63, 0x4C, 0x63, 0x2C, 0x5A, 0xCA, 0x52, 0xAA, +0x6B, 0x4D, 0x7B, 0xCE, 0x84, 0x30, 0x8C, 0x50, +0x73, 0xAE, 0x84, 0x30, 0x84, 0x30, 0x8C, 0x50, +0x7B, 0xEF, 0x73, 0xAE, 0x84, 0x0F, 0x84, 0x0F, +0x84, 0x0E, 0x7B, 0xAD, 0x9C, 0xB1, 0xB5, 0x52, +0xBD, 0xB4, 0xAD, 0x53, 0xA5, 0x32, 0xD6, 0x77, +0xCE, 0x15, 0xBD, 0x94, 0xB5, 0x74, 0xB5, 0x74, +0x84, 0x0F, 0x94, 0x71, 0x73, 0x8D, 0x39, 0xE7, +0x31, 0x65, 0x29, 0x44, 0x29, 0x44, 0x31, 0xA5, +0x52, 0x88, 0x39, 0xE6, 0x31, 0x85, 0x31, 0xA6, +0x3A, 0x07, 0x52, 0xCA, 0x63, 0x2C, 0x5A, 0xEB, +0x52, 0xAA, 0x4A, 0x69, 0x63, 0x0C, 0x6B, 0x6E, +0x84, 0x11, 0x9C, 0xD4, 0xBD, 0xF8, 0x9C, 0xD3, +0x9C, 0xB3, 0x6B, 0x4D, 0x63, 0x0C, 0xA4, 0xD3, +0x6B, 0x4D, 0x6B, 0x2D, 0x83, 0xF0, 0xAD, 0x35, +0xC5, 0xF8, 0x8C, 0x31, 0x73, 0x6E, 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62, 0xCA, 0x52, 0x69, 0x39, 0xA6, 0x29, 0x44, +0x29, 0x04, 0x39, 0xA6, 0x73, 0x6D, 0x5A, 0xAA, +0x29, 0x44, 0x29, 0x64, 0x5A, 0xCA, 0x9C, 0xB0, +0xAD, 0x53, 0xB5, 0x53, 0xBD, 0x74, 0xBD, 0x94, +0xBD, 0x94, 0xB5, 0x53, 0xB5, 0x33, 0xB5, 0x53, +0xB5, 0x53, 0x94, 0xAF, 0x4B, 0x08, 0x53, 0x89, +0x32, 0x85, 0x22, 0x24, 0x2A, 0x65, 0x53, 0xAA, +0x8D, 0x70, 0x53, 0xC9, 0x43, 0x26, 0x2A, 0x64, +0x53, 0xC9, 0x74, 0xED, 0x7C, 0xED, 0x8D, 0x6F, +0xA5, 0xF2, 0x9D, 0xD2, 0x85, 0x2E, 0x3A, 0x85, +0x19, 0x22, 0x10, 0xE2, 0x21, 0x63, 0x63, 0xE9, +0x63, 0x6E, 0x8C, 0x71, 0x73, 0x6C, 0x8C, 0x4E, +0x94, 0x6F, 0xA5, 0x11, 0xAD, 0x32, 0x9C, 0xD0, +0xB5, 0x93, 0xB5, 0x93, 0xBD, 0xB4, 0xB5, 0x73, +0xBD, 0xB4, 0xBD, 0xD4, 0xC5, 0xF4, 0xC5, 0xF4, +0xC5, 0xF4, 0xBD, 0xF4, 0xE7, 0x1B, 0xF7, 0xBE, +0xA5, 0x34, 0x08, 0x41, 0x00, 0x00, 0x00, 0x00, +0x4A, 0x49, 0xF7, 0x9E, 0xEF, 0x3C, 0xD6, 0x57, +0xB5, 0x93, 0xB5, 0x72, 0xBD, 0x93, 0xB5, 0x72, +0xC5, 0xD4, 0xBD, 0xD4, 0xC5, 0xF4, 0xBD, 0xB4, +0xB5, 0x93, 0xA4, 0xF0, 0xAD, 0x52, 0xB5, 0x72, +0xBD, 0xB4, 0xB5, 0x93, 0xB5, 0x93, 0xB5, 0x93, +0xB5, 0x93, 0xBD, 0x93, 0xB5, 0x72, 0xB5, 0x10, +0xA4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 0x5C, 0xD6, 0xDA, 0x22, 0x03, 0x22, 0x23, +0x22, 0x03, 0x2A, 0x24, 0x43, 0x27, 0x53, 0xC8, +0x53, 0xA8, 0x53, 0xA8, 0x64, 0x4B, 0x5B, 0xEA, +0x43, 0x28, 0x19, 0xC3, 0x21, 0xE4, 0x19, 0xC3, +0x19, 0xC3, 0x32, 0x84, 0x3A, 0xA5, 0x32, 0x85, +0x11, 0x82, 0x22, 0x04, 0x11, 0x42, 0x10, 0xC1, +0x52, 0x89, 0x52, 0x88, 0x62, 0xE9, 0x6B, 0x09, +0x73, 0x4A, 0x7B, 0xCC, 0x8C, 0x0C, 0x9C, 0x6E, +0xA4, 0xF0, 0xAD, 0x31, 0xAD, 0x30, 0xB5, 0x30, +0xB5, 0x51, 0x9C, 0x4E, 0x9C, 0x4E, 0xA4, 0xCF, +0xA4, 0xAF, 0x9C, 0xAF, 0xF7, 0x9D, 0x9C, 0xD3, +0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, +0x00, 0x00, 0x10, 0xA2, 0xFF, 0xDF, 0xF7, 0x7D, +0xEF, 0x5C, 0xFF, 0xDE, 0x6B, 0x4D, 0x00, 0x00, +0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x42, 0x08, +0xFF, 0xFF, 0xFF, 0xFF, 0x31, 0x86, 0x00, 0x00, +0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x52, 0xAA, +0xFF, 0xFF, 0xE7, 0x3C, 0x08, 0x41, 0x00, 0x00, +0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x8C, 0x50, +0xFF, 0xDE, 0xE6, 0xFB, 0xFF, 0x9D, 0xFF, 0xDF, +0x63, 0x2C, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, +0x00, 0x00, 0x08, 0x61, 0xF7, 0x9E, 0xE7, 0x3C, +0xAD, 0xD4, 0xDF, 0x38, 0xAD, 0x71, 0x8C, 0x8D, +0xBE, 0x34, 0xCE, 0x34, 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x9C, 0x8F, 0x8C, 0x0D, +0x94, 0x2D, 0x94, 0x2E, 0xF7, 0x7D, 0x84, 0x30, +0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, +0x00, 0x00, 0x08, 0x41, 0xFF, 0xFF, 0xFF, 0xBE, +0xF7, 0xBE, 0xFF, 0xFF, 0x18, 0xC3, 0x00, 0x00, +0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, +0xEF, 0x7D, 0xEF, 0x5D, 0x00, 0x00, 0x00, 0x00, +0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x08, 0x61, +0xFF, 0xFF, 0xA5, 0x14, 0x00, 0x00, 0x00, 0x00, +0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x39, 0xE7, +0xFF, 0xFF, 0xF7, 0x7D, 0xFF, 0xBE, 0xFF, 0xFF, +0x21, 0x24, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, +0x00, 0x00, 0x00, 0x00, 0xBD, 0xD7, 0xEF, 0x7D, +0xAD, 0xD3, 0xD7, 0x17, 0x9D, 0x0F, 0xB5, 0xD3, +0xC6, 0x54, 0xC6, 0x34, 0xC6, 0x14, 0xC5, 0xF4, +0xCE, 0x14, 0xCE, 0x55, 0xCE, 0x34, 0xCE, 0x34, +0xFF, 0xFF, 0xA5, 0x34, 0x00, 0x00, 0xCE, 0x79, +0xF7, 0x9D, 0xDE, 0xD9, 0xF7, 0x9D, 0xDE, 0xDB, +0x29, 0x65, 0xB5, 0xB6, 0xF7, 0xBE, 0xDE, 0xB9, +0xF7, 0x9E, 0x9C, 0xF3, 0x00, 0x00, 0xDE, 0xFB, +0xAD, 0x55, 0x42, 0x28, 0x18, 0xC3, 0x00, 0x00, +0x10, 0xA2, 0x39, 0xE7, 0x9C, 0xD3, 0xFF, 0xDF, +0xEF, 0x7D, 0xE7, 0x1C, 0xFF, 0xDF, 0x6B, 0x6D, +0x4A, 0x49, 0xFF, 0xDE, 0xDF, 0x1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7, 0x9E, 0x00, 0x00, +0x8C, 0x51, 0xF7, 0x9E, 0xBD, 0x96, 0xBD, 0x96, +0xDE, 0xDB, 0xF7, 0xBE, 0xB5, 0xB6, 0x31, 0x86, +0x63, 0x0C, 0xF7, 0xBE, 0xEF, 0x7D, 0xE7, 0x3C, +0xEF, 0x7D, 0xFF, 0xDF, 0xBD, 0xF7, 0x5A, 0xCB, +0x18, 0xE3, 0x08, 0x41, 0x08, 0x41, 0x21, 0x04, +0x63, 0x0C, 0xCE, 0x59, 0xFF, 0xDF, 0xE7, 0x3C, +0xD6, 0xBA, 0xF7, 0x9E, 0x73, 0x8E, 0x31, 0x86, +0x31, 0x86, 0x10, 0xA2, 0x00, 0x00, 0x21, 0x04, +0x21, 0x04, 0x21, 0x04, 0x73, 0xAE, 0xF7, 0xBE, +0xDE, 0xBA, 0xEF, 0x3C, 0xF7, 0xBE, 0xD6, 0x9A, +0x63, 0x0C, 0x29, 0x45, 0x10, 0x82, 0x00, 0x00, +0x08, 0x61, 0x29, 0x65, 0x73, 0xAE, 0xDE, 0xFB, +0xEF, 0x5D, 0xBD, 0xD7, 0x6B, 0x4D, 0x31, 0x86, +0x29, 0x45, 0x29, 0x24, 0x5A, 0xCA, 0x62, 0xEB, +0x52, 0xAB, 0x73, 0xAE, 0xBD, 0xF7, 0xEF, 0x7D, +0xE7, 0x3C, 0x7B, 0xCF, 0x31, 0x86, 0x10, 0xA2, +0x00, 0x00, 0x08, 0x61, 0x21, 0x24, 0x63, 0x0C, +0xCE, 0x79, 0xFF, 0xDE, 0xE7, 0x3B, 0xCE, 0x37, +0xEF, 0x5C, 0xEF, 0x5C, 0x21, 0x24, 0xB5, 0x96, +0xB5, 0x96, 0x39, 0xC7, 0x08, 0x41, 0x00, 0x00, +0x52, 0x8A, 0xFF, 0xDF, 0xF7, 0x7C, 0xF7, 0x9D, +0xF7, 0xBE, 0x94, 0xB2, 0x42, 0x08, 0x18, 0xE3, +0x08, 0x41, 0x00, 0x20, 0x18, 0xC3, 0x31, 0xA6, +0x84, 0x10, 0xC6, 0x18, 0x10, 0x82, 0x00, 0x00, +0x9C, 0xF3, 0xEF, 0x5D, 0x3A, 0xE5, 0x3B, 0x06, +0x64, 0x0B, 0x85, 0x0F, 0x5B, 0xCA, 0x43, 0x07, +0xA5, 0xD2, 0x53, 0x88, 0x74, 0xAD, 0x43, 0x07, +0x19, 0xA3, 0x19, 0xA3, 0x21, 0xC3, 0x19, 0xA3, +0x19, 0xA3, 0x19, 0xA2, 0x32, 0x64, 0x32, 0x85, +0x19, 0xA3, 0x21, 0xC3, 0x2A, 0x25, 0x32, 0x66, +0x73, 0x4C, 0x83, 0xCD, 0x6B, 0x0A, 0x83, 0xED, +0xAC, 0xF1, 0xAC, 0xD0, 0xAC, 0xD0, 0x9C, 0x8F, +0x9C, 0x6F, 0x94, 0x4E, 0x8B, 0xED, 0x8C, 0x0D, +0xA4, 0xD0, 0xBD, 0x73, 0xB5, 0x32, 0xA4, 0xB0, +0xA4, 0xD0, 0xAC, 0xD0, 0xF7, 0x9D, 0x5A, 0xEB, +0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, +0x00, 0x00, 0x00, 0x00, 0xFF, 0xFF, 0xFF, 0xDE, +0xF7, 0xBE, 0xFF, 0xFF, 0x00, 0x00, 0x00, 0x00, +0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, +0xC6, 0x38, 0xDE, 0xDB, 0x00, 0x00, 0x00, 0x00, +0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, +0xF7, 0x9E, 0x84, 0x30, 0x00, 0x00, 0x00, 0x00, +0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x10, 0x82, +0xFF, 0xDF, 0xEF, 0x7C, 0xFF, 0xBE, 0xFF, 0xFF, +0x08, 0x41, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, +0x00, 0x00, 0x00, 0x00, 0xA5, 0x14, 0xEF, 0x7D, +0xB6, 0x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0xD6, 0xBA, 0xE7, 0x1C, 0x94, 0x92, 0x42, 0x07, +0x21, 0x04, 0x21, 0x04, 0x21, 0x24, 0x29, 0x65, +0x62, 0xEB, 0xBD, 0xD6, 0xF7, 0x9D, 0xCE, 0x79, +0x10, 0x82, 0x08, 0x61, 0x63, 0x0C, 0x8C, 0x71, +0x9C, 0xD3, 0x94, 0xB2, 0x73, 0x8E, 0x21, 0x04, +0x00, 0x00, 0x9C, 0xF3, 0xF7, 0xBE, 0xEF, 0x5B, +0xFF, 0xDD, 0xE7, 0x3C, 0x00, 0x00, 0x42, 0x08, +0x00, 0x20, 0x52, 0x8A, 0x94, 0x92, 0x9C, 0xD3, +0xBD, 0xD7, 0xFF, 0xFF, 0xFF, 0xDE, 0xFF, 0xDF, +0x4A, 0x49, 0x00, 0x00, 0x4A, 0x49, 0x8C, 0x71, +0x9C, 0xF3, 0x9C, 0xF3, 0x84, 0x30, 0x5A, 0xEB, +0x08, 0x41, 0x00, 0x00, 0x5A, 0xCB, 0xDE, 0xFB, +0xFF, 0xDF, 0xE7, 0x3C, 0x43, 0x26, 0x64, 0x6C, +0x85, 0x30, 0x9D, 0xB3, 0x85, 0x10, 0x7C, 0x8D, +0xA5, 0xB2, 0x2A, 0x04, 0x53, 0x69, 0x2A, 0x24, +0x11, 0x62, 0x19, 0xC4, 0x2A, 0x05, 0x21, 0xC3, +0x21, 0xC3, 0x43, 0x07, 0x19, 0xA2, 0x3A, 0x85, +0x22, 0x03, 0x3A, 0xC6, 0x42, 0xE6, 0x32, 0x24, +0x9C, 0x4F, 0x94, 0x2E, 0x6A, 0xEA, 0xA4, 0xF1, +0xC5, 0xB3, 0xC5, 0xB4, 0xBD, 0x93, 0xBD, 0x52, +0xB5, 0x32, 0x94, 0x4F, 0x8C, 0x2E, 0x8C, 0x0D, +0x83, 0xED, 0x83, 0xCD, 0x7B, 0xAC, 0x73, 0x4B, +0x73, 0x4B, 0x73, 0x6B, 0xEF, 0x7D, 0x63, 0x2C, +0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, +0x00, 0x00, 0x00, 0x00, 0xFF, 0xFF, 0xF7, 0xBE, +0xF7, 0x9E, 0xFF, 0xFF, 0x00, 0x00, 0x00, 0x00, +0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, +0xCE, 0x59, 0xDE, 0xFB, 0x00, 0x00, 0x00, 0x00, +0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, +0xF7, 0x9E, 0xA5, 0x14, 0x00, 0x00, 0x00, 0x00, +0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x21, 0x24, +0xFF, 0xDE, 0xE7, 0x1B, 0xEF, 0x5C, 0xFF, 0xDE, +0x18, 0xC3, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, +0x00, 0x00, 0x00, 0x00, 0xAD, 0x75, 0xEF, 0x7D, +0xB6, 0x55, 0xBE, 0xB5, 0xBE, 0x94, 0xA5, 0x91, +0x8C, 0x8D, 0xAD, 0x90, 0x7C, 0x88, 0x8D, 0x09, +0x8D, 0x08, 0x8C, 0xEA, 0x94, 0xEC, 0xAD, 0x4F, +0xFF, 0xFF, 0xA5, 0x34, 0x00, 0x00, 0xCE, 0x79, +0xF7, 0x9D, 0xDE, 0xD9, 0xF7, 0x9D, 0xD6, 0x9A, +0x00, 0x00, 0xA5, 0x34, 0xF7, 0xBE, 0xDE, 0xB9, +0xFF, 0xBE, 0x9C, 0xF3, 0x00, 0x00, 0x00, 0x00, +0xB5, 0x96, 0xFF, 0xDF, 0xF7, 0xBE, 0xF7, 0x9D, +0xF7, 0xBE, 0xFF, 0xDF, 0x84, 0x10, 0x00, 0x00, +0xAD, 0x55, 0xFF, 0xFF, 0xFF, 0xFF, 0xCE, 0x79, +0x00, 0x00, 0xA5, 0x14, 0xEF, 0x9D, 0xC6, 0x55, +0xCE, 0x76, 0xEF, 0x9D, 0xBD, 0xF7, 0x00, 0x00, +0x7B, 0xEF, 0x00, 0x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0xFF, 0xDF, +0xDE, 0xDB, 0x08, 0x61, 0x73, 0x8E, 0xFF, 0xDF, +0xEF, 0x5C, 0xC6, 0x78, 0x6C, 0x6B, 0x8D, 0x50, +0x95, 0x72, 0xA6, 0x15, 0x95, 0x72, 0x53, 0x29, +0x53, 0x49, 0x29, 0xE4, 0x21, 0xC3, 0x19, 0xA2, +0x11, 0x42, 0x21, 0xC4, 0x32, 0x66, 0x21, 0xC4, +0x09, 0x01, 0x19, 0xA3, 0x11, 0x42, 0x21, 0xE4, +0x32, 0x85, 0x5B, 0xE9, 0x43, 0x46, 0x3A, 0xA5, +0x9C, 0x70, 0x8B, 0xED, 0x6B, 0x0A, 0xAD, 0x11, +0xBD, 0xB3, 0xCD, 0xF4, 0xCD, 0xF5, 0xCE, 0x15, +0xDE, 0x77, 0xD6, 0x36, 0xCD, 0xF5, 0xD6, 0x56, +0xD6, 0x77, 0xBD, 0xB4, 0xAD, 0x32, 0xAD, 0x11, +0xA4, 0xD0, 0x9C, 0x90, 0xF7, 0x9D, 0x6B, 0x4D, +0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, +0x00, 0x00, 0x00, 0x00, 0xFF, 0xFF, 0xF7, 0x9E, +0xEF, 0x7D, 0xFF, 0xDF, 0x00, 0x20, 0x00, 0x00, +0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, +0xCE, 0x59, 0xDE, 0xFB, 0x00, 0x00, 0x00, 0x00, +0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, +0xF7, 0x9E, 0xA5, 0x14, 0x00, 0x00, 0x00, 0x00, +0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x29, 0x65, +0xFF, 0xDE, 0xEF, 0x3B, 0xEF, 0x3B, 0xFF, 0xDE, +0x21, 0x04, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, +0x00, 0x00, 0x00, 0x00, 0xAD, 0x75, 0xEF, 0x7D, +0x9D, 0x72, 0xA5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 0x32, +0xE6, 0xD8, 0xDE, 0x77, 0xF7, 0xBE, 0x6B, 0x4D, +0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, +0x00, 0x00, 0x00, 0x00, 0xFF, 0xFF, 0xF7, 0x9E, +0xEF, 0x7D, 0xFF, 0xDF, 0x00, 0x20, 0x00, 0x00, +0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, +0xCE, 0x59, 0xDE, 0xFB, 0x00, 0x00, 0x00, 0x00, +0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, +0xF7, 0x9E, 0xA5, 0x14, 0x00, 0x00, 0x00, 0x00, +0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x29, 0x65, +0xFF, 0xDF, 0xF7, 0x9C, 0xF7, 0x9C, 0xFF, 0xDF, +0x21, 0x04, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, +0x00, 0x00, 0x00, 0x00, 0xAD, 0x75, 0xEF, 0x7D, +0xA5, 0xB3, 0x8C, 0xEE, 0x9D, 0x51, 0x84, 0x6E, +0x94, 0xAE, 0x9D, 0x0E, 0x74, 0x27, 0x74, 0x67, +0x6C, 0x26, 0x8C, 0xCA, 0xAD, 0x4E, 0xAD, 0x0F, +0xFF, 0xFF, 0xA5, 0x34, 0x00, 0x00, 0xCE, 0x79, +0xEF, 0x5C, 0xCE, 0x16, 0xEF, 0x3C, 0xD6, 0x9A, +0x00, 0x00, 0xA5, 0x34, 0xF7, 0x9D, 0xDE, 0xB9, +0xF7, 0x9D, 0x9C, 0xF3, 0x00, 0x00, 0xA5, 0x14, +0xF7, 0x9D, 0xC6, 0x36, 0xA5, 0x0F, 0x9C, 0x8E, +0xBD, 0xB4, 0xD6, 0x79, 0xF7, 0x9E, 0x63, 0x2C, +0x10, 0xA2, 0xFF, 0xFF, 0xFF, 0xDE, 0xFF, 0xDF, +0x52, 0xAA, 0x18, 0xE3, 0xFF, 0xDE, 0xE7, 0x1B, +0xD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D, 0xD6, 0x58, +0xDE, 0x77, 0xE6, 0xB8, 0xE6, 0xB8, 0xF7, 0x5C, +0xFF, 0xDF, 0x42, 0x28, 0x31, 0xA6, 0xF7, 0xBE, +0xC6, 0x77, 0x74, 0x8C, 0x53, 0xE8, 0x85, 0x4F, +0x95, 0x71, 0x53, 0x8A, 0x21, 0xE3, 0x19, 0xA3, +0x22, 0x04, 0x21, 0xE3, 0x21, 0xE3, 0x19, 0xA2, +0x11, 0x62, 0x11, 0x62, 0x21, 0xC3, 0x19, 0xA3, +0x21, 0xC3, 0x11, 0x41, 0x4B, 0x28, 0x5C, 0x0A, +0x5C, 0x0A, 0x4B, 0xA8, 0x5C, 0x09, 0x6C, 0x8C, +0xA4, 0xB0, 0x83, 0xAC, 0x73, 0x6B, 0xBD, 0x93, +0xAC, 0xF0, 0xA4, 0xF0, 0xA5, 0x10, 0xAD, 0x31, +0xB5, 0x52, 0xBD, 0xB3, 0xB5, 0x72, 0xCE, 0x15, +0xC5, 0xD4, 0xC5, 0xD4, 0xB5, 0x52, 0xB5, 0x52, +0xD6, 0x76, 0xDE, 0x96, 0xFF, 0xBE, 0x6B, 0x4D, +0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, +0x00, 0x00, 0x00, 0x00, 0xFF, 0xFF, 0xF7, 0xBE, +0xF7, 0x9D, 0xFF, 0xFF, 0x00, 0x00, 0x00, 0x00, +0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, +0xCE, 0x59, 0xDE, 0xFB, 0x00, 0x00, 0x00, 0x00, +0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, +0xF7, 0x9E, 0x9C, 0xF3, 0x00, 0x00, 0x00, 0x00, +0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x21, 0x04, +0xFF, 0xFF, 0xF7, 0x9D, 0xF7, 0x9D, 0xFF, 0xFF, +0x10, 0xA2, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, +0x00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x31, 0xAD, 0x31, 0xC5, 0xF4, +0xBD, 0xD4, 0xBD, 0x93, 0xC6, 0x15, 0xC5, 0xF4, +0xD6, 0x76, 0xD6, 0x75, 0xFF, 0xBE, 0x63, 0x2C, +0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, +0x00, 0x00, 0x00, 0x00, 0xFF, 0xFF, 0xFF, 0xDE, +0xFF, 0xBE, 0xFF, 0xFF, 0x00, 0x00, 0x00, 0x00, +0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, +0xC6, 0x38, 0xDE, 0xDB, 0x00, 0x00, 0x00, 0x00, +0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, +0xF7, 0x9E, 0x7B, 0xEF, 0x00, 0x00, 0x00, 0x00, +0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x10, 0x82, +0xFF, 0xFF, 0xFF, 0xBD, 0xFF, 0xBD, 0xFF, 0xFF, +0x08, 0x41, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, +0x00, 0x00, 0x00, 0x00, 0x94, 0xB2, 0xFF, 0xDE, +0xCE, 0x76, 0xC6, 0x14, 0xC5, 0xF4, 0xAD, 0x72, +0x8C, 0x8E, 0xBD, 0xF3, 0xE7, 0x17, 0xD6, 0x75, +0xA4, 0xCE, 0xAC, 0xEF, 0xBD, 0xB2, 0xCD, 0xF3, +0xFF, 0xFF, 0xA5, 0x34, 0x00, 0x00, 0xCE, 0x79, +0xF7, 0x9D, 0xDE, 0x98, 0xEF, 0x7D, 0xD6, 0x9A, +0x00, 0x00, 0xA5, 0x34, 0xF7, 0x9E, 0xDE, 0xB9, +0xF7, 0x9D, 0x9C, 0xF3, 0x00, 0x00, 0xD6, 0x9A, +0xEF, 0x5C, 0xCE, 0x35, 0xDE, 0x77, 0xAD, 0x12, +0x5A, 0xCA, 0xC5, 0xF6, 0xF7, 0x9D, 0x8C, 0x71, +0x00, 0x00, 0xEF, 0x7D, 0xF7,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A2, 0x18, 0xC3, 0x84, 0x30, 0xC6, 0x18, +0xD6, 0x9A, 0xD6, 0xBA, 0xC6, 0x38, 0x9C, 0xD3, +0x29, 0x65, 0x08, 0x41, 0xCE, 0x79, 0xE7, 0x3C, +0x95, 0x11, 0x53, 0xA7, 0x3B, 0x44, 0x3B, 0x05, +0x3A, 0xC6, 0x22, 0x24, 0x19, 0xC2, 0x11, 0x61, +0x19, 0xC3, 0x22, 0x03, 0x21, 0xE3, 0x21, 0xE3, +0x21, 0xE3, 0x22, 0x04, 0x2A, 0x25, 0x21, 0xE4, +0x11, 0x42, 0x21, 0xA3, 0x53, 0x68, 0x3A, 0xC5, +0x3B, 0x06, 0x74, 0xCD, 0x85, 0x4F, 0x85, 0x0F, +0x8B, 0xEE, 0x73, 0x2A, 0x73, 0x4B, 0xA4, 0xF0, +0xAD, 0x10, 0xB5, 0x31, 0xB5, 0x31, 0xAC, 0xF0, +0xB5, 0x32, 0xAD, 0x11, 0xB5, 0x73, 0xB5, 0x72, +0xA4, 0xF0, 0x83, 0xCC, 0xBD, 0xB4, 0xE6, 0xD8, +0xDE, 0xB7, 0xDE, 0x96, 0xF7, 0xBE, 0x94, 0xB2, +0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, +0x00, 0x00, 0x10, 0x82, 0xFF, 0xFF, 0xFF, 0xFF, +0xFF, 0xDF, 0xFF, 0xFF, 0x10, 0x82, 0x00, 0x00, +0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, +0xD6, 0xBA, 0xEF, 0x7D, 0x00, 0x00, 0x00, 0x00, +0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x08, 0x61, +0xFF, 0xFF, 0xB5, 0xB6, 0x00, 0x00, 0x00, 0x00, +0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x42, 0x28, +0xFF, 0xFF, 0xF7, 0x9D, 0xFF, 0xBE, 0xFF, 0xFF, +0x39, 0xC7, 0x00, 0x00, 0x00, 0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F7, 0x9E, +0xAD, 0x55, 0x7B, 0xCF, 0x52, 0xAA, 0x31, 0x86, +0x08, 0x61, 0x00, 0x00, 0x00, 0x00, 0x31, 0x86, +0xCE, 0x79, 0xF7, 0xBE, 0xD6, 0x98, 0xB5, 0x94, +0xAD, 0x12, 0x8C, 0x2E, 0x9C, 0xAF, 0xC6, 0x13, +0xC6, 0x16, 0xF7, 0x7D, 0x73, 0xAE, 0x08, 0x41, +0xFF, 0xDF, 0xDE, 0xFA, 0xC6, 0x95, 0x95, 0x0E, +0x8C, 0xEC, 0xAE, 0x2B, 0xAE, 0x0B, 0xD7, 0x17, +0xFF, 0xFE, 0x42, 0x28, 0x39, 0xC7, 0xFF, 0xFF, +0xFF, 0xFF, 0xE7, 0x3C, 0x00, 0x00, 0x9C, 0xD3, +0xF7, 0x9E, 0xC6, 0x36, 0xBD, 0xB3, 0xDE, 0xD7, +0xEF, 0x59, 0xEF, 0x5C, 0xE7, 0x3C, 0x21, 0x04, +0x4A, 0x49, 0x5A, 0xCB, 0x08, 0x41, 0x00, 0x00, +0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, +0x39, 0xC7, 0xC6, 0x18, 0xEF, 0x9D, 0xBE, 0x37, +0x6C, 0x0C, 0x64, 0x0A, 0x64, 0x09, 0x74, 0x8C, +0x74, 0x6D, 0x19, 0xE3, 0x11, 0x82, 0x09, 0x01, +0x19, 0xA2, 0x22, 0x03, 0x21, 0xE3, 0x19, 0xC2, +0x11, 0x82, 0x21, 0xC3, 0x19, 0xC3, 0x19, 0x83, +0x09, 0x02, 0x11, 0x42, 0x42, 0xE7, 0x21, 0xE3, +0x3A, 0xC6, 0x74, 0xAC, 0x85, 0x2F, 0x8D, 0x70, +0x5A, 0x89, 0x6B, 0x0A, 0x73, 0x4B, 0x7B, 0x8B, +0x7B, 0x8A, 0x83, 0xAB, 0x83, 0xAB, 0x83, 0xAB, +0x83, 0xCC, 0x94, 0x4E, 0x83, 0xCC, 0x83, 0xCC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, 0xC6, 0x78, +0xF7, 0x9D, 0xCE, 0x79, 0x42, 0x08, 0x00, 0x00, +0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, +0x08, 0x41, 0x73, 0x8E, 0xF7, 0xBE, 0xEF, 0x5C, +0xC6, 0x57, 0xEF, 0x9D, 0xFF, 0xFF, 0x08, 0x41, +0x84, 0x30, 0x94, 0x92, 0x08, 0x61, 0x00, 0x00, +0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x10, 0xA2, +0x9C, 0xF3, 0xF7, 0xBE, 0xD6, 0xBA, 0x94, 0xD1, +0xBE, 0x55, 0xDF, 0x1B, 0xF7, 0xDE, 0x84, 0x30, +0x10, 0xA2, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, +0x00, 0x00, 0x00, 0x00, 0x00, 0x20, 0x52, 0xAA, +0xE7, 0x3C, 0xEF, 0xBD, 0xCE, 0xD7, 0xA5, 0xB2, +0xD6, 0xFA, 0xF7, 0xDE, 0x9D, 0x13, 0x21, 0x04, +0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, +0x00, 0x00, 0x10, 0xA2, 0x84, 0x10, 0xF7, 0xBE, +0xEF, 0x9C, 0xCF, 0x17, 0xC6, 0xF5, 0xDF, 0x5A, +0xF7, 0xDE, 0xC6, 0x18, 0x31, 0xA6, 0x00, 0x00, +0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, +0x08, 0x41, 0x6B, 0x4D, 0xEF, 0x9D, 0xDE, 0xFB, +0xB5, 0xB6, 0xDE, 0xDB, 0xEF, 0x7D, 0x00, 0x00, +0x8C, 0x51, 0xEF, 0x7D, 0xAD, 0x55, 0x94, 0xB3, +0xC6, 0x38, 0xEF, 0x7D, 0xEF, 0x5D, 0x31, 0xA6, +0x00, 0x20, 0xAD, 0x55, 0xFF, 0xDF, 0xFF, 0xDF, +0xFF, 0xFF, 0xEF, 0x7D, 0x63, 0x0C, 0x00, 0x20, +0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, +0x00, 0x00, 0x4A, 0x49, 0xDE, 0xDB, 0xE7, 0x3D, +0xD6, 0x9A, 0xC6, 0x18, 0xA5, 0x35, 0x94, 0x92, +0xD6, 0x9A, 0xF7, 0x9E, 0x63, 0x0C, 0x00, 0x00, +0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xCE, 0x79, +0xF7, 0xBE, 0xF7, 0x9E, 0xEF, 0x7D, 0x73, 0x8E, +0x08, 0x41, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, +0x00, 0x00, 0x00, 0x00, 0x08, 0x41, 0x6B, 0x6D, +0xF7, 0x9E, 0xEF, 0x5C, 0xD6, 0x79, 0xEF, 0x3C, +0xFF, 0xDF, 0x08, 0x61, 0x00, 0x00, 0xEF, 0x7D, +0xEF, 0x3C, 0xCE, 0x58, 0xE7, 0x1B, 0xFF, 0xBE, +0xA5, 0x34, 0x21, 0x04, 0x00, 0x00, 0x00, 0x00, +0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x10, 0xA2, +0x7B, 0xEF, 0xF7, 0xBE, 0xF7, 0x9D, 0xDE, 0xB9, +0xEF, 0x5C, 0xE7, 0x3C, 0x00, 0x00, 0x9C, 0xD3, +0xEF, 0x7D, 0xBE, 0x33, 0xCE, 0xB2, 0x9C, 0xEE, +0xD6, 0xB7, 0xFF, 0xBE, 0x63, 0x2C, 0x39, 0xC7, +0xFF, 0xFF, 0xF7, 0x9D, 0xEF, 0x3B, 0xE7, 0x1A, +0xDF, 0x19, 0xDF, 0x1A, 0xE7, 0x3C, 0xEF, 0x5D, +0xF7, 0x9E, 0xFF, 0xFF, 0x42, 0x28, 0x39, 0xC7, +0xFF, 0xDE, 0xC6, 0x37, 0x32, 0x64, 0x42, 0xE6, +0x32, 0x64, 0x32, 0x85, 0x3A, 0xA5, 0x2A, 0x24, +0x21, 0xE3, 0x21, 0xE3, 0x19, 0xA2, 0x22, 0x03, +0x32, 0xA5, 0x32, 0x64, 0x2A, 0x24, 0x21, 0xE3, +0x53, 0x69, 0x6C, 0x6C, 0x64, 0x2B, 0x84, 0xEF, +0x32, 0xA6, 0x19, 0xE2, 0x19, 0xE2, 0x19, 0xC2, +0x94, 0x91, 0xAD, 0x12, 0xB5, 0x52, 0xB5, 0x52, +0xBD, 0x93, 0xBD, 0x93, 0xBD, 0x94, 0xCE, 0x36, +0xCD, 0xF5, 0xC5, 0xD4, 0xC5, 0xD4, 0xD6, 0x35, +0x94, 0x2D, 0xCE, 0x15, 0xD6, 0x56, 0xD6, 0x56, +0xD6, 0x56, 0xD6, 0x56, 0xD6, 0x36, 0xD6, 0x36, +0xD6, 0x56, 0xDE, 0xB9, 0xF7, 0xBE, 0x94, 0xB2, +0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, +0x00, 0x00, 0xA5, 0x34, 0xFF, 0xBE, 0xEF, 0x1A, +0xF7, 0x7D, 0xEF, 0x5D, 0x00, 0x00, 0x00, 0x00, +0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x42, 0x28, +0xFF, 0xFF, 0xFF, 0xFF, 0x4A, 0x49, 0x00, 0x00, +0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, +0xDE, 0xDB, 0xEF, 0x7C, 0xD6, 0xB8, 0xEF, 0x3B, +0xF7, 0x9E, 0x00, 0x20, 0x00, 0x00, 0x00, 0x00, +0x00, 0x00, 0x00, 0x00, 0x29, 0x45, 0xFF, 0xBE, +0xDE, 0xD9, 0x8C, 0x6E, 0x84, 0xED, 0x95, 0x6E, +0x7C, 0xAC, 0x53, 0x88, 0x6C, 0x09, 0x9D, 0x6E, +0x5B, 0x28, 0x94, 0xCE, 0xA5, 0x2F, 0x94, 0xAE, +0x7B, 0xEC, 0x73, 0x6B, 0x73, 0x6B, 0x7B, 0xAC, +0xFF, 0xFF, 0xEF, 0x7D, 0xD6, 0x9A, 0xF7, 0x9E, +0xE7, 0x1C, 0xCE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xCE, 0x79, +0x9C, 0xD3, 0x39, 0xE7, 0x00, 0x00, 0xAD, 0x75, +0xEF, 0x5C, 0x9D, 0x13, 0x32, 0x85, 0x32, 0x65, +0x32, 0x85, 0x19, 0xA3, 0x11, 0x41, 0x19, 0xC3, +0x2A, 0x24, 0x21, 0xC3, 0x19, 0xA2, 0x32, 0x85, +0x4B, 0x07, 0x3A, 0xC5, 0x2A, 0x64, 0x21, 0xE2, +0x32, 0x84, 0x4B, 0xA8, 0x7C, 0xEE, 0x8D, 0x50, +0x32, 0x85, 0x2A, 0x23, 0x22, 0x23, 0x21, 0xE2, +0x6B, 0x2A, 0x83, 0xAC, 0x94, 0x4D, 0x9C, 0x8E, +0xAD, 0x10, 0xBD, 0x72, 0xC5, 0xD4, 0xCD, 0xF4, +0xD6, 0x55, 0xDE, 0x76, 0xDE, 0x97, 0xCD, 0xF4, +0x9C, 0x4D, 0xCD, 0xD3, 0xDE, 0x76, 0xE6, 0x97, +0xE6, 0xB7, 0xE6, 0xB7, 0xDE, 0x76, 0xDE, 0x76, +0xDE, 0x56, 0xEE, 0xF9, 0xF7, 0xBE, 0xAD, 0x75, +0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, +0x00, 0x00, 0xC6, 0x18, 0xFF, 0xBE, 0xDE, 0xB9, +0xF7, 0x7C, 0xFF, 0xDE, 0x18, 0xC3, 0x00, 0x00, +0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x6B, 0x6D, +0xFF, 0xFF, 0xFF, 0xFF, 0x84, 0x10, 0x00, 0x00, +0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x18, 0xE3, +0xF7, 0xBE, 0xF7, 0x9D, 0xEF, 0x3A, 0xF7, 0x7C, +0xFF, 0xDE, 0x39, 0xE7, 0x00, 0x00, 0x00, 0x00, +0x00, 0x00, 0x00, 0x00, 0x6B, 0x6D, 0xF7, 0xBE, +0xDE, 0xD8, 0xAD, 0xB1, 0x8C, 0xED, 0x53, 0x68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x8D, 0x7C, 0x2A, 0x7C, 0xA9, +0x53, 0xC4, 0x64, 0x46, 0x64, 0x26, 0x85, 0x29, +0x6C, 0x88, 0x32, 0x63, 0x21, 0xE2, 0x4B, 0x66, +0x74, 0xCA, 0x74, 0xC9, 0x74, 0xC9, 0x95, 0xAD, +0x95, 0x8C, 0x95, 0xAC, 0x7D, 0x09, 0x4B, 0x84, +0x32, 0x63, 0x43, 0x05, 0x3A, 0x84, 0x3A, 0xC5, +0x43, 0x05, 0x4B, 0x27, 0x11, 0x21, 0x11, 0x02, +0x11, 0x01, 0x2A, 0x24, 0x42, 0xC6, 0xAE, 0x11, +0x84, 0xCC, 0x4A, 0xE7, 0x74, 0x4C, 0x8D, 0x2E, +0x8D, 0x4D, 0x7C, 0xCB, 0x5B, 0xE7, 0x64, 0x49, +0x64, 0x48, 0x4B, 0xC4, 0x74, 0xE9, 0x9E, 0x0E, +0xAE, 0x71, 0xAE, 0x50, 0x9D, 0xCE, 0x7D, 0x0A, +0x6C, 0x88, 0x95, 0x4A, 0xBE, 0x8F, 0xA5, 0xEF, +0xC7, 0x14, 0xBE, 0xF4, 0xB6, 0x71, 0x53, 0xC5, +0x54, 0x03, 0x64, 0x63, 0x7C, 0xC7, 0xB6, 0x30, +0x84, 0x6D, 0x63, 0x0C, 0x9C, 0xD3, 0x9C, 0xF4, +0xBD, 0xF8, 0x8C, 0x31, 0x7B, 0x8E, 0x8B, 0xCF, +0xA4, 0xB3, 0xB5, 0x55, 0x8C, 0x51, 0x8C, 0x30, +0xAD, 0x94, 0xA5, 0x54, 0xA5, 0x34, 0x9C, 0xF4, +0x8C, 0x92, 0x52, 0xCB, 0x39, 0xC7, 0x31, 0x65, +0x21, 0x44, 0x29, 0x44, 0x31, 0x85, 0x31, 0x86, +0x52, 0x89, 0x5A, 0xCA, 0x29, 0x45, 0x21, 0x04, +0x31, 0x65, 0x52, 0x8A, 0x62, 0xEB, 0x5A, 0xAB, +0x39, 0xA6, 0x52, 0x8A, 0x6B,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0x74, 0x6C, 0x8D, 0x0F, +0xA5, 0x51, 0x94, 0xCF, 0xAD, 0x31, 0xA4, 0xAE, +0x94, 0x2D, 0xA4, 0xF1, 0xAD, 0x52, 0xB5, 0x53, +0xBD, 0x94, 0xB5, 0x74, 0xAD, 0x33, 0x7B, 0xED, +0x8C, 0x8F, 0x63, 0x6B, 0xA5, 0x53, 0xBD, 0xF5, +0xA5, 0x72, 0x7C, 0x8E, 0x63, 0xEC, 0x53, 0x48, +0x6B, 0xEA, 0x8C, 0xCE, 0xA5, 0x71, 0xAD, 0xD2, +0xA5, 0x90, 0x95, 0x0D, 0x84, 0xAB, 0xAD, 0xEF, +0x9D, 0x8D, 0x64, 0x07, 0x8D, 0x2B, 0x95, 0x2B, +0x7C, 0x8F, 0xCE, 0xD9, 0x84, 0x2F, 0x9D, 0x31, +0xB6, 0x53, 0xA5, 0xF1, 0x5B, 0xE7, 0x5B, 0xC6, +0x85, 0x0B, 0x4B, 0x63, 0x43, 0x03, 0x4A, 0xE6, +0x84, 0x2D, 0x94, 0x6D, 0x9D, 0x0E, 0x74, 0x48, +0x5B, 0xE5, 0x4B, 0x83, 0x7D, 0x09, 0x8D, 0x6A, +0x6C, 0x88, 0x11, 0x60, 0x21, 0xA3, 0x2A, 0x44, +0x3A, 0xC5, 0x2A, 0x23, 0x19, 0xA1, 0x6C, 0x49, +0xAE, 0x4F, 0x85, 0x29, 0x5C, 0x03, 0x74, 0x88, +0x95, 0x4C, 0x63, 0xC8, 0x74, 0x4A, 0x53, 0x67, +0x74, 0x6B, 0x53, 0x47, 0x21, 0x62, 0x19, 0x22, +0x11, 0x01, 0x53, 0x08, 0xA5, 0xAF, 0xBE, 0x91, +0x84, 0x8C, 0x7C, 0x2D, 0x95, 0x10, 0x74, 0x6C, +0x3A, 0x84, 0x22, 0x02, 0x74, 0x8B, 0x85, 0x4D, +0x6C, 0x89, 0x64, 0x66, 0x85, 0x4B, 0xA6, 0x30, +0xAE, 0x51, 0x7D, 0x0B, 0x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, 0xAD, 0xB5, 0xD2, +0xAD, 0x92, 0xA5, 0x30, 0x63, 0x89, 0x74, 0x2B, +0x8D, 0x0E, 0x8D, 0x2E, 0x85, 0x0D, 0x85, 0x0D, +0x6B, 0xEA, 0x63, 0x68, 0x84, 0x8A, 0x84, 0xA9, +0x84, 0xA9, 0x95, 0x2C, 0x9D, 0x6E, 0xAD, 0x90, +0xAD, 0x91, 0x8C, 0x2D, 0x83, 0xEC, 0xC6, 0x35, +0xAD, 0xF3, 0x7C, 0xCC, 0x85, 0x0C, 0x8D, 0x2E, +0x95, 0x6F, 0x7C, 0xAC, 0x5B, 0xE9, 0x42, 0xE6, +0x4B, 0x26, 0x4B, 0x67, 0x53, 0xA8, 0x4B, 0x69, +0x84, 0xCF, 0xA5, 0xB2, 0x9D, 0x30, 0x9D, 0x10, +0x7C, 0x0E, 0x94, 0xF3, 0x9D, 0x54, 0x95, 0x70, +0x84, 0xEA, 0x64, 0x26, 0x5C, 0x06, 0x7D, 0x0A, +0x6C, 0x88, 0x64, 0x47, 0x4B, 0x84, 0x32, 0xE2, +0x3A, 0xE2, 0x6C, 0x48, 0x7C, 0xAB, 0x9D, 0xD0, +0xA6, 0x31, 0x9D, 0xD0, 0x9D, 0xCF, 0x9D, 0xEE, +0x85, 0x6B, 0x74, 0xE8, 0x64, 0x87, 0x74, 0xC9, +0xA6, 0x2F, 0x5C, 0x07, 0x43, 0x24, 0x43, 0x04, +0x5B, 0xE7, 0x6C, 0x49, 0x19, 0x61, 0x19, 0xA2, +0x95, 0x8F, 0xAE, 0x50, 0xAE, 0x51, 0xAE, 0x50, +0xAE, 0x71, 0x8D, 0x4C, 0x53, 0x05, 0x42, 0x85, +0x6B, 0xA9, 0x29, 0x62, 0x4A, 0x46, 0x6B, 0x69, +0x5B, 0x27, 0x3A, 0x85, 0x2A, 0x04, 0x2A, 0x04, +0x32, 0x45, 0x21, 0xC4, 0x19, 0x83, 0x3A, 0x86, +0x4B, 0x87, 0x53, 0xC7, 0x6C,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, 0x64, 0x46, +0x4B, 0xA3, 0x43, 0x63, 0x32, 0xE2, 0x5C, 0x27, +0x53, 0xE5, 0x85, 0x2B, 0x8D, 0x4D, 0x9D, 0xF0, +0xA6, 0x11, 0xA6, 0x11, 0xA6, 0x31, 0x7C, 0xEA, +0x7D, 0x2A, 0x74, 0xE9, 0x74, 0xC9, 0x9D, 0xCE, +0x95, 0xAE, 0x74, 0xAA, 0x7D, 0x0B, 0x64, 0x28, +0x85, 0x4C, 0x64, 0x09, 0x19, 0x61, 0x21, 0xA3, +0x42, 0xE6, 0x3A, 0xA4, 0x42, 0xE5, 0x6C, 0x2A, +0xA6, 0x0F, 0x9D, 0xCE, 0x63, 0xE7, 0x4B, 0x25, +0x84, 0xCB, 0x42, 0xC5, 0x31, 0xE3, 0x4A, 0xC6, +0x29, 0xC2, 0x42, 0xA6, 0x32, 0x44, 0x2A, 0x04, +0x3A, 0xA7, 0x32, 0x66, 0x32, 0x45, 0x43, 0x07, +0x53, 0xA8, 0x2A, 0x63, 0x43, 0x05, 0x32, 0x85, +0x2A, 0x24, 0x3A, 0xA5, 0x22, 0x42, 0x22, 0x22, +0x22, 0x22, 0x2A, 0x83, 0x43, 0x25, 0x4B, 0xA6, +0x64, 0x69, 0x74, 0xCA, 0xAE, 0x50, 0x64, 0x47, +0x43, 0x44, 0x2A, 0xA2, 0x2A, 0x62, 0x2A, 0x43, +0x7C, 0xED, 0xAE, 0x93, 0x9D, 0xF1, 0xAE, 0x52, +0x84, 0xED, 0x7C, 0xAB, 0x95, 0x4D, 0x95, 0x6D, +0x95, 0x8E, 0xC7, 0x15, 0xA5, 0xD0, 0x8C, 0xCD, +0x73, 0x6B, 0x5A, 0x48, 0x49, 0xE7, 0x8B, 0xAE, +0xAC, 0xB1, 0x83, 0xAE, 0x5A, 0x8A, 0x52, 0x8A, +0x7B, 0xCE, 0x73, 0x8E, 0x9C, 0xD3, 0xD6, 0x99, +0xD6, 0xBA, 0xBD, 0xD7, 0x84, 0x0F, 0x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 0x25, 0x53, 0xC5, +0x85, 0x4B, 0x6C, 0x47, 0x95, 0x8E, 0x7C, 0xAC, +0xA5, 0xF0, 0xB6, 0x32, 0x8D, 0x0D, 0x6C, 0x47, +0x64, 0x46, 0x5C, 0x05, 0x64, 0x48, 0x8D, 0x8D, +0x9E, 0x10, 0x8D, 0x8E, 0x6C, 0x89, 0x74, 0xE9, +0x85, 0x4B, 0x85, 0x4C, 0x9D, 0xEF, 0xA6, 0x31, +0x95, 0xAE, 0x9D, 0xCF, 0x9D, 0xCF, 0x5B, 0xC7, +0x3A, 0xE5, 0x19, 0xA2, 0x21, 0xA3, 0x21, 0xC3, +0x19, 0xA3, 0x32, 0x65, 0x3A, 0xC6, 0x2A, 0x24, +0x21, 0xE2, 0x53, 0xA6, 0x43, 0x44, 0x43, 0x24, +0x5B, 0xE7, 0x43, 0x04, 0x3A, 0xC3, 0x5C, 0x07, +0x6C, 0x68, 0x4B, 0x46, 0x2A, 0x03, 0x32, 0x65, +0x43, 0x08, 0x53, 0x49, 0x4B, 0x48, 0x4B, 0x47, +0x4B, 0x67, 0x43, 0x46, 0x3B, 0x25, 0x3B, 0x05, +0x4B, 0x67, 0x4B, 0x67, 0x3A, 0xC5, 0x2A, 0x43, +0x3A, 0xC5, 0x22, 0x02, 0x22, 0x22, 0x6C, 0xAA, +0x6C, 0xA9, 0x85, 0x4D, 0x9D, 0xF0, 0x74, 0xCA, +0x7D, 0x0A, 0x5C, 0x07, 0x4B, 0x85, 0x43, 0x65, +0x32, 0xE4, 0x3A, 0xE5, 0x64, 0x2A, 0x85, 0x4E, +0x64, 0x49, 0x53, 0x67, 0x8D, 0x6E, 0x8D, 0x8F, +0xBE, 0xD4, 0x95, 0x6F, 0x8D, 0x0D, 0x7C, 0x0A, +0x73, 0x6A, 0x52, 0x46, 0x49, 0xE7, 0x72, 0xEA, +0xA4, 0x0D, 0x72, 0xEA, 0x83, 0xAD, 0x4A, 0x48, +0x62, 0xEB, 0x52, 0x6A, 0x62, 0x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 0x8D, 0x67, +0xCF, 0x32, 0x95, 0xAD, 0x85, 0x26, 0x9D, 0xC5, +0x9D, 0xC4, 0x8D, 0x62, 0x95, 0x83, 0xA6, 0x08, +0xAE, 0x6E, 0xB6, 0x50, 0xBE, 0x8F, 0xA5, 0xE9, +0x9D, 0xEB, 0xA5, 0xF1, 0xBE, 0x37, 0xC6, 0x38, +0xA5, 0x55, 0x63, 0x2C, 0x4A, 0xE6, 0x85, 0x28, +0x75, 0x05, 0x64, 0x85, 0x32, 0xE1, 0x2A, 0x61, +0x3A, 0xE4, 0x53, 0x86, 0x19, 0xC1, 0x32, 0x64, +0x53, 0x89, 0x5B, 0x8A, 0x32, 0x45, 0x19, 0x82, +0x42, 0xE5, 0x21, 0xE2, 0x2A, 0x23, 0x2A, 0x23, +0x21, 0xE3, 0x42, 0xE6, 0x5B, 0xE9, 0x5C, 0x09, +0x4B, 0x87, 0x4B, 0x87, 0x4B, 0x87, 0x43, 0x47, +0x43, 0x47, 0x43, 0x26, 0x32, 0xA5, 0x43, 0x08, +0x7B, 0xAD, 0x73, 0x6C, 0x63, 0x0B, 0x73, 0x6C, +0x7B, 0xCD, 0x94, 0x4F, 0x9C, 0x90, 0x94, 0x4F, +0x83, 0xCD, 0x83, 0xCD, 0x84, 0x0D, 0x7B, 0xCD, +0x73, 0x8B, 0x94, 0x2D, 0x94, 0x0D, 0x94, 0x2D, +0x94, 0x4E, 0x8C, 0x4E, 0x83, 0xED, 0x9C, 0x90, +0xA4, 0xF1, 0xB5, 0x73, 0xBD, 0xB3, 0xCD, 0xF4, +0xCD, 0xF4, 0xC5, 0xB2, 0xD6, 0x14, 0xCD, 0xD3, +0xBD, 0x92, 0xBD, 0x93, 0xC5, 0xF4, 0xCD, 0xF4, +0xD6, 0x35, 0xD6, 0x35, 0xDE, 0x55, 0xDE, 0x55, +0xDE, 0x55, 0xA4, 0xAF, 0xBD, 0x72, 0xCD, 0xF4, +0xA4, 0x8E, 0xAC, 0xF0, 0xB5, 0x10,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, 0x53, 0xE4, 0x64, 0x27, 0x74, 0x29, +0x9D, 0x4E, 0x74, 0x69, 0x84, 0xCB, 0x6B, 0xEA, +0x84, 0xAF, 0xAD, 0xB2, 0x9D, 0x71, 0x74, 0x4B, +0x3B, 0x23, 0x4B, 0xA5, 0x64, 0x47, 0x2A, 0x81, +0x19, 0xE1, 0x22, 0x02, 0x3A, 0xE4, 0x64, 0x68, +0x95, 0xAD, 0xA6, 0x10, 0xAE, 0x51, 0x9D, 0xF0, +0x53, 0x88, 0x19, 0xC2, 0x22, 0x03, 0x2A, 0x44, +0x53, 0xA8, 0x43, 0x06, 0x3A, 0xE5, 0x32, 0xA4, +0x53, 0x87, 0x63, 0xE9, 0x43, 0x05, 0x43, 0x26, +0x2A, 0x42, 0x53, 0xC7, 0x5C, 0x26, 0x4B, 0x64, +0x64, 0x27, 0x7C, 0xEA, 0x6C, 0x69, 0x43, 0x45, +0x6C, 0xA9, 0x42, 0xE5, 0x19, 0xA2, 0x32, 0x65, +0x3A, 0xC5, 0x43, 0x06, 0x53, 0xA9, 0x9D, 0xF1, +0x8D, 0x6F, 0x85, 0x2D, 0x85, 0x4E, 0x8D, 0x8F, +0x9E, 0x11, 0x53, 0x88, 0x4B, 0x66, 0x5B, 0xE8, +0x3A, 0xE4, 0x2A, 0x23, 0x3A, 0xA4, 0x64, 0x69, +0x95, 0xCF, 0x95, 0xAF, 0xA6, 0x31, 0x7D, 0x0C, +0x7C, 0xEB, 0x4B, 0xA6, 0x95, 0xAE, 0x6C, 0x68, +0x5C, 0x47, 0x6C, 0xA9, 0x7D, 0x0B, 0x85, 0x6C, +0x8D, 0x8D, 0x95, 0x8D, 0x6C, 0x8A, 0x8D, 0x4E, +0xAE, 0x52, 0x6C, 0x4A, 0x6C, 0x49, 0x95, 0x6D, +0x63, 0x68, 0x5B, 0x47, 0x63, 0x68, 0x83, 0x69, +0x83, 0x09, 0x6A, 0xA8, 0x62, 0x89, 0x83, 0xCF, +0x94, 0x91, 0x9C, 0xB2, 0x94, 0x92, 0x8C, 0x30, +0x83, 0xEF, 0x9C, 0xB2, 0xA4, 0xD3, 0xBD, 0xB6, +0xBD, 0xB6, 0xAD, 0x34, 0xAD, 0x14, 0xCE, 0x38, +0xD6, 0x99, 0x9C, 0x92, 0x83, 0xAF, 0x5A, 0xAB, +0x20, 0xE4, 0x31, 0x65, 0x5A, 0x8A, 0x73, 0x6D, +0x73, 0x6D, 0x83, 0xAE, 0x73, 0x2C, 0x6B, 0x0C, +0x94, 0x72, 0xD6, 0x58, 0xDE, 0x79, 0xA4, 0xD3, +0xAD, 0x14, 0xAD, 0x55, 0xB5, 0x76, 0xB5, 0x96, +0xD6, 0x9A, 0xDE, 0xBB, 0x9C, 0xD3, 0x73, 0x8E, +0x73, 0x8E, 0x94, 0x71, 0x8C, 0x30, 0x73, 0x8D, +0x63, 0x4B, 0x84, 0xAD, 0x8D, 0x4D, 0x9D, 0xCC, +0x74, 0xC5, 0x74, 0xC2, 0x85, 0x44, 0x9D, 0xE9, +0xB6, 0x71, 0xCF, 0x35, 0x95, 0xAE, 0x95, 0xA8, +0x8D, 0x64, 0x7D, 0x00, 0x85, 0x42, 0x9D, 0xC7, +0xA6, 0x0B, 0xAE, 0x4D, 0xB6, 0x6D, 0xAE, 0x49, +0x95, 0x88, 0xAD, 0xD1, 0xC6, 0x58, 0xC6, 0x38, +0x9D, 0x14, 0x42, 0x49, 0x5B, 0x68, 0x85, 0x48, +0x74, 0xE5, 0x53, 0xE3, 0x32, 0xC1, 0x2A, 0x61, +0x74, 0x8A, 0x85, 0x4B, 0x2A, 0x41, 0x3A, 0xA4, +0x7C, 0xCD, 0xAE, 0x12, 0x5B, 0xAA, 0x21, 0xC3, +0x74, 0x8A, 0x53, 0x66, 0x4B, 0x46, 0x53, 0x68, +0x64, 0x0A, 0x5B, 0xE9, 0x43, 0x46, 0x32, 0xC4, +0x2A, 0x83, 0x2A, 0x63, 0x4B, 0x67, 0x4B, 0x87, +0x53, 0xE8, 0x4B, 0x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22, 0x03, +0x22, 0x22, 0x2A, 0x43, 0x64, 0x2A, 0x95, 0x90, +0x95, 0xB0, 0x9D, 0xF1, 0xA6, 0x12, 0xA6, 0x52, +0x74, 0x8C, 0x32, 0x85, 0x4B, 0x47, 0x5C, 0x09, +0x4B, 0x46, 0x3A, 0x84, 0x3A, 0xA5, 0x5B, 0xE7, +0x74, 0xCB, 0x95, 0xAF, 0xA6, 0x31, 0x7D, 0x0C, +0x8D, 0x6E, 0x64, 0x49, 0xBE, 0xF3, 0x8D, 0x6C, +0x5C, 0x47, 0x53, 0xE6, 0x43, 0x64, 0x3B, 0x44, +0x8D, 0x4C, 0x9D, 0xCE, 0x9D, 0xCD, 0x85, 0x2B, +0x85, 0x2C, 0x6C, 0x89, 0x95, 0x8C, 0x95, 0x8D, +0x8C, 0xCC, 0x6B, 0xE8, 0x5B, 0x86, 0x73, 0xA7, +0x7B, 0x28, 0x52, 0x07, 0x73, 0x2C, 0x83, 0xEF, +0x94, 0x71, 0x94, 0x50, 0x94, 0x71, 0x8C, 0x0F, +0x8C, 0x30, 0xA4, 0xF3, 0x8C, 0x10, 0x9C, 0xB3, +0x9C, 0x92, 0x94, 0x51, 0xA4, 0xD3, 0xB5, 0x75, +0xC5, 0xF7, 0xAD, 0x55, 0xD6, 0x58, 0xBD, 0xB6, +0x73, 0x8E, 0x4A, 0x08, 0x41, 0xC7, 0x62, 0xEB, +0x62, 0xCA, 0x83, 0xCF, 0x73, 0x2C, 0x52, 0x69, +0xA4, 0xD3, 0xD6, 0x58, 0xCD, 0xF7, 0xAD, 0x14, +0x7B, 0xCF, 0xAD, 0x55, 0xB5, 0x96, 0xDE, 0xBB, +0xDE, 0xBB, 0xB5, 0x96, 0x6B, 0x4D, 0x94, 0x93, +0xAD, 0x35, 0x7B, 0xCF, 0x6B, 0x2C, 0xAD, 0x34, +0x84, 0x2F, 0x63, 0x8A, 0x84, 0xED, 0x85, 0x2B, +0x85, 0x27, 0x7C, 0xE4, 0x95, 0xA7, 0x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B, 0xE6, 0x3A, 0xE2, 0x53, 0x87, 0x5B, 0xC8, +0x6C, 0x6A, 0x63, 0xE7, 0x43, 0x25, 0x53, 0x28, +0x9D, 0x53, 0xBE, 0x77, 0xBE, 0x77, 0x7C, 0xAE, +0x64, 0x49, 0x43, 0x64, 0x2A, 0x81, 0x19, 0xE1, +0x53, 0x67, 0x42, 0xC5, 0x2A, 0x23, 0x2A, 0x23, +0x32, 0x63, 0x4B, 0x67, 0x32, 0x44, 0x11, 0x21, +0x11, 0x41, 0x19, 0x82, 0x2A, 0x44, 0x43, 0x06, +0x74, 0xAA, 0x74, 0xCA, 0x6C, 0x89, 0x64, 0x28, +0x7C, 0xCB, 0x74, 0xAA, 0x53, 0xC6, 0x53, 0xE6, +0x5B, 0xE7, 0x4B, 0x85, 0x53, 0xA6, 0x5C, 0x26, +0x53, 0xE6, 0x32, 0x82, 0x2A, 0x03, 0x19, 0x82, +0x21, 0xE3, 0x21, 0xA2, 0x3A, 0xA5, 0x3A, 0xA5, +0x19, 0xE1, 0x32, 0xA4, 0x6C, 0x8A, 0x8D, 0x6F, +0xA6, 0x32, 0xAE, 0x53, 0x95, 0xD0, 0x7C, 0xCD, +0x2A, 0x64, 0x32, 0x85, 0x43, 0x26, 0x5B, 0xC8, +0x5C, 0x09, 0x53, 0xA7, 0x74, 0xCB, 0x74, 0xEA, +0x7D, 0x0C, 0x95, 0xD0, 0xA6, 0x31, 0x74, 0xCB, +0x53, 0xC8, 0x7C, 0xCB, 0xAE, 0x70, 0xA6, 0x2F, +0x95, 0xCE, 0x85, 0x4B, 0x7D, 0x0B, 0x53, 0xE6, +0x95, 0x8D, 0xA6, 0x0F, 0x95, 0x8C, 0x95, 0xAC, +0x8D, 0x4C, 0x7D, 0x0A, 0x7C, 0xE9, 0x4B, 0x24, +0x31, 0xA2, 0x42, 0x24, 0x5B, 0x66, 0x74, 0x68, +0x84, 0x2A, 0x8C, 0x0F, 0x9C, 0x92, 0x8C, 0x10, +0x9C, 0xB2, 0xA4, 0xD3, 0xA4, 0xF3, 0x8C, 0x30, +0x83, 0xEF, 0xCE, 0x38, 0xA5, 0x13, 0x62, 0xCB, +0x73, 0x8E, 0x9C, 0x92, 0x8C, 0x51, 0x84, 0x10, +0x94, 0x92, 0xB5, 0x75, 0xD6, 0x79, 0xAD, 0x55, +0xC6, 0x18, 0xBD, 0x96, 0x8C, 0x31, 0x7B, 0xAE, +0x52, 0x49, 0x73, 0x2C, 0x7B, 0xAE, 0x7B, 0xAE, +0xAD, 0x34, 0xD6, 0x38, 0xD6, 0x58, 0xBD, 0x96, +0x94, 0x51, 0x9C, 0xB3, 0xDE, 0xBB, 0xD6, 0x7A, +0xAD, 0x76, 0x73, 0xAF, 0x6B, 0x4D, 0x84, 0x10, +0x94, 0x71, 0x8C, 0x51, 0x7B, 0xCF, 0xA4, 0xF3, +0x7B, 0xEF, 0x5B, 0x0B, 0xA5, 0x92, 0x84, 0xED, +0x85, 0x09, 0x8D, 0x48, 0x95, 0xCA, 0x9D, 0xEB, +0x95, 0x8A, 0x9D, 0xCD, 0xA6, 0x10, 0x9E, 0x0D, +0x7D, 0x26, 0x64, 0x60, 0x6C, 0xC2, 0x8D, 0x46, +0x9E, 0x09, 0x95, 0xA6, 0x95, 0xA4, 0xA6, 0x26, +0x8D, 0x48, 0xA5, 0x92, 0xCE, 0x79, 0xBE, 0x38, +0x84, 0x31, 0x3A, 0x06, 0x84, 0xED, 0x85, 0x29, +0x74, 0xC6, 0x5C, 0x25, 0x32, 0xC1, 0x53, 0xA6, +0x95, 0xCC, 0x85, 0x47, 0x74, 0xE6, 0x32, 0x82, +0x84, 0xED, 0xB6, 0x94, 0x53, 0x69, 0x63, 0xA8, +0x9D, 0xAC, 0x53, 0x65, 0x42, 0xE5, 0x2A, 0x63, +0x22, 0x23, 0x3A, 0xA5, 0x3A, 0xC5, 0x43, 0x27, +0x43, 0x46, 0x3A, 0xC4, 0x3B, 0x05, 0x53, 0xC7, +0x64, 0x29, 0x3A, 0xC4, 0x09, 0x00, 0x21, 0xE4, diff -Nru libwebsockets-3.2.1/minimal-examples/embedded/esp32/esp-wrover-kit/main/CMakeLists.txt libwebsockets-4.1.6/minimal-examples/embedded/esp32/esp-wrover-kit/main/CMakeLists.txt --- libwebsockets-3.2.1/minimal-examples/embedded/esp32/esp-wrover-kit/main/CMakeLists.txt 1970-01-01 00:00:00.000000000 +0000 +++ libwebsockets-4.1.6/minimal-examples/embedded/esp32/esp-wrover-kit/main/CMakeLists.txt 2020-12-01 17:40:26.000000000 +0000 @@ -0,0 +1,7 @@ +idf_component_register(SRCS + lws-minimal-esp32.c + devices.c + INCLUDE_DIRS "../libwebsockets/include;${IDF_PATH}/components/spi_flash/include;${IDF_PATH}/components/nvs_flash/include;${IDF_PATH}/components/mdns/include") + +target_link_libraries(${COMPONENT_LIB} websockets) +include_directories(../build/libwebsockets) diff -Nru libwebsockets-3.2.1/minimal-examples/embedded/esp32/esp-wrover-kit/main/devices.c libwebsockets-4.1.6/minimal-examples/embedded/esp32/esp-wrover-kit/main/devices.c --- libwebsockets-3.2.1/minimal-examples/embedded/esp32/esp-wrover-kit/main/devices.c 1970-01-01 00:00:00.000000000 +0000 +++ libwebsockets-4.1.6/minimal-examples/embedded/esp32/esp-wrover-kit/main/devices.c 2020-12-01 17:40:26.000000000 +0000 @@ -0,0 +1,272 @@ +/* + * devices for ESP WROVER KIT + * + * Written in 2010-2020 by Andy Green + * + * This file is made available under the Creative Commons CC0 1.0 + * Universal Public Domain Dedication. + */ + +#define LWIP_PROVIDE_ERRNO 1 +#define _ESP_PLATFORM_ERRNO_H_ + +#include +#include "sdkconfig.h" +#include "freertos/FreeRTOS.h" +#include "freertos/task.h" + +#include + +#include + +struct lws_led_state *lls; +lws_display_state_t lds; +struct lws_button_state *bcs; +lws_netdev_instance_wifi_t *wnd; + +/* + * Button controller + * + * On the WROVER KIT, it's a bit overloaded... the two buttons are reset and + * gpio0, gpio is also used for one of the RGB LEDs channels control so it's not + * really usable as a general user button. + * + * Instead we use GPIO 14 (available on J1) for a button with the other side + * of the switch connected to 0V. + */ + +static const lws_button_map_t bcm[] = { + { + .gpio = GPIO_NUM_14, + .smd_interaction_name = "user" + }, +}; + +static const lws_button_controller_t bc = { + .smd_bc_name = "bc", + .gpio_ops = &lws_gpio_plat, + .button_map = &bcm[0], + .active_state_bitmap = 0, + .count_buttons = LWS_ARRAY_SIZE(bcm), +}; + +/* + * pwm controller + */ + +static const lws_pwm_map_t pwm_map[] = { + { .gpio = GPIO_NUM_2, .index = 0, .active_level = 1 }, + { .gpio = GPIO_NUM_0, .index = 1, .active_level = 1 }, + { .gpio = GPIO_NUM_4, .index = 2, .active_level = 1 }, + { .gpio = GPIO_NUM_5, .index = 3, .active_level = 0 } +}; + +static const lws_pwm_ops_t pwm_ops = { + lws_pwm_plat_ops, + .pwm_map = &pwm_map[0], + .count_pwm_map = LWS_ARRAY_SIZE(pwm_map) +}; + +/* + * led controller + */ + +static const lws_led_gpio_map_t lgm[] = { + { + .name = "red", + .gpio = GPIO_NUM_2, + .pwm_ops = &pwm_ops, /* managed by pwm */ + .active_level = 1, + }, + { + .name = "green", + .gpio = GPIO_NUM_0, + .pwm_ops = &pwm_ops, /* managed by pwm */ + .active_level = 1, + }, + { + .name = "blue", + .gpio = GPIO_NUM_4, + .pwm_ops = &pwm_ops, /* managed by pwm */ + .active_level = 1, + }, + { + .name = "backlight", + .gpio = GPIO_NUM_5, + .pwm_ops = &pwm_ops, /* managed by pwm */ + .active_level = 0, + /* + * The wrover kit uses a 2 NPN in series to drive the backlight + * which means if the GPIO provides no current, the backlight is + * full-on. This causes a white flash during boot... they mark + * the first stage with "Modify In ESP-WROVER-KIT!" on the + * schematics but on Kit v4.1, it's still like that. + */ + }, +}; + +static const lws_led_gpio_controller_t lgc = { + .led_ops = lws_led_gpio_ops, + .gpio_ops = &lws_gpio_plat, + .led_map = &lgm[0], + .count_leds = LWS_ARRAY_SIZE(lgm) +}; + +/* + * Bitbang SPI configuration for display + */ + +static const lws_bb_spi_t lbspi = { + .bb_ops = { + lws_bb_spi_ops, + .bus_mode = LWS_SPI_BUSMODE_CLK_IDLE_LOW_SAMP_RISING + }, + .gpio = &lws_gpio_plat, + .clk = GPIO_NUM_19, + .ncs = { GPIO_NUM_22 }, + .ncmd = { GPIO_NUM_21 }, + .mosi = GPIO_NUM_23, + .miso = GPIO_NUM_25, + .flags = LWSBBSPI_FLAG_USE_NCS0 | + LWSBBSPI_FLAG_USE_NCMD0 +}; + +/* + * SPI display + */ + +static const lws_display_ili9341_t disp = { + .disp = { + lws_display_ili9341_ops, + .bl_pwm_ops = &pwm_ops, + .bl_active = &lws_pwmseq_static_on, + .bl_dim = &lws_pwmseq_static_half, + .bl_transition = &lws_pwmseq_linear_wipe, + .bl_index = 3, + .w = 320, + .h = 240, + .latency_wake_ms = 150, + }, + .spi = (lws_spi_ops_t *)&lbspi, + .gpio = &lws_gpio_plat, + .reset_gpio = GPIO_NUM_18, + .spi_index = 0 +}; + +/* + * Settings stored in platform nv + */ + +static const lws_settings_ops_t sett = { + lws_settings_ops_plat +}; + +/* + * Wifi + */ + +static const lws_netdev_ops_t wifi_ops = { + lws_netdev_wifi_plat_ops +}; + +int +init_plat_devices(struct lws_context *ctx) +{ + lws_settings_instance_t *si; + lws_netdevs_t *netdevs = lws_netdevs_from_ctx(ctx); + + si = lws_settings_init(&sett, (void *)"nvs"); + if (!si) { + lwsl_err("%s: failed to create settings instance\n", __func__); + return 1; + } + netdevs->si = si; + +#if 0 + /* + * This is a temp hack to bootstrap the settings to contain the test + * AP ssid and passphrase for one time, so the settings can be stored + * while there's no UI atm + */ + { + lws_wifi_creds_t creds; + + memset(&creds, 0, sizeof(creds)); + + lws_strncpy(creds.ssid, "xxx", sizeof(creds.ssid)); + lws_strncpy(creds.passphrase, "yyy", sizeof(creds.passphrase)); + lws_dll2_add_tail(&creds.list, &netdevs->owner_creds); + + if (lws_netdev_credentials_settings_set(netdevs)) { + lwsl_err("%s: failed to write bootstrap creds\n", + __func__); + return 1; + } + } +#endif + +// if (lws_netdev_instance_wifi_settings_get(si, "netdev.wl0", &niw, &ac)) { +// lwsl_err("%s: unable to fetch wl0 settings\n", __func__); +// return 1; +// } + + /* create the wifi network device and configure it */ + + wnd = (lws_netdev_instance_wifi_t *) + wifi_ops.create(ctx, &wifi_ops, "wl0", NULL); + if (!wnd) { + lwsl_err("%s: failed to create wifi object\n", __func__); + return 1; + } + + wnd->flags |= LNDIW_MODE_STA; + + if (wifi_ops.configure(&wnd->inst, NULL)) { + lwsl_err("%s: failed to configure wifi object\n", __func__); + return 1; + } + + wifi_ops.up(&wnd->inst); + + /* bring up the led controller */ + + lls = lgc.led_ops.create(&lgc.led_ops); + if (!lls) { + lwsl_err("%s: could not create led\n", __func__); + return 1; + } + + /* pwm init must go after the led controller init */ + + pwm_ops.init(&pwm_ops); + + /* ... and the button controller */ + + bcs = lws_button_controller_create(ctx, &bc); + if (!bcs) { + lwsl_err("%s: could not create buttons\n", __func__); + return 1; + } + + lws_button_enable(bcs, 0, lws_button_get_bit(bcs, "user")); + + /* ... bring up spi bb and the display */ + + lbspi.bb_ops.init(&lbspi.bb_ops); + lws_display_state_init(&lds, ctx, 30000, 10000, lls, &disp.disp); + + /* + * Make the RGB LED do something using sequenced PWM... pressing the + * GPIO14 button with single-presses advances the blue channel between + * different sequences + */ + + lws_led_transition(lls, "blue", &lws_pwmseq_sine_endless_fast, + &lws_pwmseq_linear_wipe); + lws_led_transition(lls, "green", &lws_pwmseq_sine_endless_slow, + &lws_pwmseq_linear_wipe); + lws_led_transition(lls, "red", &lws_pwmseq_sine_endless_slow, + &lws_pwmseq_linear_wipe); + + return 0; +} diff -Nru libwebsockets-3.2.1/minimal-examples/embedded/esp32/esp-wrover-kit/main/lws-minimal-esp32.c libwebsockets-4.1.6/minimal-examples/embedded/esp32/esp-wrover-kit/main/lws-minimal-esp32.c --- libwebsockets-3.2.1/minimal-examples/embedded/esp32/esp-wrover-kit/main/lws-minimal-esp32.c 1970-01-01 00:00:00.000000000 +0000 +++ libwebsockets-4.1.6/minimal-examples/embedded/esp32/esp-wrover-kit/main/lws-minimal-esp32.c 2020-12-01 17:40:26.000000000 +0000 @@ -0,0 +1,249 @@ +/* + * lws-minimal-esp32 + * + * Written in 2010-2020 by Andy Green + * + * This file is made available under the Creative Commons CC0 1.0 + * Universal Public Domain Dedication. + * + * Configured for ESP32 WROVER KIT + * + * What should be notable about this is there are no esp-idf apis used here or + * any related files, despite we are running on top of stock esp-idf. + */ + +#define LWIP_PROVIDE_ERRNO 1 +#define _ESP_PLATFORM_ERRNO_H_ + +#include +#include "sdkconfig.h" +#include "freertos/FreeRTOS.h" +#include "freertos/task.h" + +#include + +#include + +struct lws_context *context; +extern struct lws_led_state *lls; +extern lws_display_state_t lds; +extern struct lws_button_state *bcs; +extern lws_netdev_instance_wifi_t *wnd; + +lws_sorted_usec_list_t sul_pass; + +extern int init_plat_devices(struct lws_context *); + +static const uint8_t logo[] = { +#include "cat-565.h" +}; + +#if defined(LWS_WITH_SECURE_STREAMS_STATIC_POLICY_ONLY) +#include "static-policy.h" +#else +#include "policy.h" +#endif + +static uint8_t flip; + + +typedef struct myss { + struct lws_ss_handle *ss; + void *opaque_data; + /* ... application specific state ... */ + + size_t amount; + +} myss_t; + +/* + * When we're actually happy we passed, we schedule the actual pass + * string to happen a few seconds later, so we can observe what the + * code did after the pass. + */ + +static void +completion_sul_cb(lws_sorted_usec_list_t *sul) +{ + /* + * In CI, we use sai-expect to look for this + * string for success + */ + + lwsl_notice("Completed: PASS\n"); +} + +static int +myss_rx(void *userobj, const uint8_t *buf, size_t len, int flags) +{ + myss_t *m = (myss_t *)userobj; + + lwsl_user("%s: len %d, flags: %d\n", __func__, (int)len, flags); +// lwsl_hexdump_info(buf, len); + m->amount += len; + + if (flags & LWSSS_FLAG_EOM) { + + /* + * If we received the whole message, for our example it means + * we are done. + * + * Howevere we want to record what happened after we received + * the last bit so we can see anything unexpected coming. So + * wait a couple of seconds before sending the PASS magic. + */ + + lwsl_notice("%s: received %u bytes, passing in 10s\n", + __func__, (unsigned int)m->amount); + + lws_sul_schedule(context, 0, &sul_pass, completion_sul_cb, + 10 * LWS_US_PER_SEC); + + return LWSSSSRET_DESTROY_ME; + } + + return 0; +} + +static int +myss_state(void *userobj, void *sh, lws_ss_constate_t state, + lws_ss_tx_ordinal_t ack) +{ + myss_t *m = (myss_t *)userobj; + + lwsl_user("%s: %s, ord 0x%x\n", __func__, lws_ss_state_name(state), + (unsigned int)ack); + + switch (state) { + case LWSSSCS_CREATING: + lws_ss_client_connect(m->ss); + break; + default: + break; + } + + return 0; +} + +static const lws_ss_info_t ssi = { + .handle_offset = offsetof(myss_t, ss), + .opaque_user_data_offset = offsetof(myss_t, opaque_data), + .rx = myss_rx, + .state = myss_state, + .user_alloc = sizeof(myss_t), + .streamtype = "test_stream", +}; + +static const lws_led_sequence_def_t *seqs[] = { + &lws_pwmseq_static_on, + &lws_pwmseq_static_off, + &lws_pwmseq_sine_endless_slow, + &lws_pwmseq_sine_endless_fast, +}; + +static int +smd_cb(void *opaque, lws_smd_class_t _class, lws_usec_t timestamp, void *buf, + size_t len) +{ + + if (!lws_json_simple_strcmp(buf, len, "\"src\":", "bc/user") && + !lws_json_simple_strcmp(buf, len, "\"event\":", "click")) { + lws_led_transition(lls, "blue", seqs[flip & 3], + &lws_pwmseq_linear_wipe); + flip++; + } + + lwsl_hexdump_notice(buf, len); + + if ((_class & LWSSMDCL_SYSTEM_STATE) && + !lws_json_simple_strcmp(buf, len, "\"state\":", "OPERATIONAL")) { + + /* create the secure stream */ + + lwsl_notice("%s: creating test secure stream\n", __func__); + + if (lws_ss_create(context, 0, &ssi, NULL, NULL, NULL, NULL)) { + lwsl_err("%s: failed to create secure stream\n", + __func__); + return -1; + } + } + + if (_class & LWSSMDCL_INTERACTION) + /* + * Any kind of user interaction brings the display back up and + * resets the dimming / blanking timers + */ + lws_display_state_active(&lds); + + return 0; +} + +void +app_main(void) +{ + struct lws_context_creation_info *info; + + lws_set_log_level(1024 | 15, NULL); + + lws_netdev_plat_init(); + lws_netdev_plat_wifi_init(); + + info = malloc(sizeof(*info)); + if (!info) + goto spin; + + memset(info, 0, sizeof(*info)); + + lwsl_notice("LWS test for Espressif ESP32 WROVER KIT\n"); + +#if !defined(LWS_WITH_SECURE_STREAMS_STATIC_POLICY_ONLY) + info->pss_policies_json = ss_policy; +#else + info->pss_policies = &_ss_static_policy_entry; +#endif + info->options = LWS_SERVER_OPTION_EXPLICIT_VHOSTS | + LWS_SERVER_OPTION_DO_SSL_GLOBAL_INIT; + info->port = CONTEXT_PORT_NO_LISTEN; + info->early_smd_cb = smd_cb; + info->early_smd_class_filter = LWSSMDCL_INTERACTION | + LWSSMDCL_SYSTEM_STATE | + LWSSMDCL_NETWORK; + + context = lws_create_context(info); + if (!context) { + lwsl_err("lws init failed\n"); + goto spin; + } + + /* + * We don't need this after context creation... things it pointed to + * still need to exist though since the context copied the pointers. + */ + + free(info); + + /* devices and init are in devices.c */ + + if (init_plat_devices(context)) + goto spin; + + /* put the cat picture up there and enable the backlight */ + + lds.disp->blit(lds.disp, logo, 0, 0, 320, 240); + lws_display_state_active(&lds); + + /* the lws event loop */ + + do { + taskYIELD(); + } while (lws_service(context, 0) >= 0); + + lwsl_notice("%s: exited event loop\n", __func__); + + +spin: + vTaskDelay(10); + taskYIELD(); + goto spin; +} diff -Nru libwebsockets-3.2.1/minimal-examples/embedded/esp32/esp-wrover-kit/main/policy.h libwebsockets-4.1.6/minimal-examples/embedded/esp32/esp-wrover-kit/main/policy.h --- libwebsockets-3.2.1/minimal-examples/embedded/esp32/esp-wrover-kit/main/policy.h 1970-01-01 00:00:00.000000000 +0000 +++ libwebsockets-4.1.6/minimal-examples/embedded/esp32/esp-wrover-kit/main/policy.h 2020-12-01 17:40:26.000000000 +0000 @@ -0,0 +1,131 @@ + +static const char * const ss_policy = + "{" + "\"release\":" "\"01234567\"," + "\"product\":" "\"myproduct\"," + "\"schema-version\":" "1," + + "\"retry\": [" /* named backoff / retry strategies */ + "{\"default\": {" + "\"backoff\": [" "1000," + "2000," + "3000," + "5000," + "10000" + "]," + "\"conceal\":" "25," + "\"jitterpc\":" "20," + "\"svalidping\":" "30," + "\"svalidhup\":" "35" + "}}" + "]," + "\"certs\": [" /* named individual certificates in BASE64 DER */ + /* + * Let's Encrypt certs for warmcat.com / libwebsockets.org + */ + "{\"isrg_root_x1\": \"" /* ISRG ROOT X1 */ + "MIIFazCCA1OgAwIBAgIRAIIQz7DSQONZRGPgu2OCiwAwDQYJKoZIhvcNAQELBQAw" + "TzELMAkGA1UEBhMCVVMxKTAnBgNVBAoTIEludGVybmV0IFNlY3VyaXR5IFJlc2Vh" + "cmNoIEdyb3VwMRUwEwYDVQQDEwxJU1JHIFJvb3QgWDEwHhcNMTUwNjA0MTEwNDM4" + "WhcNMzUwNjA0MTEwNDM4WjBPMQswCQYDVQQGEwJVUzEpMCcGA1UEChMgSW50ZXJu" + "ZXQgU2VjdXJpdHkgUmVzZWFyY2ggR3JvdXAxFTATBgNVBAMTDElTUkcgUm9vdCBY" + "MTCCAiIwDQYJKoZIhvcNAQEBBQADggIPADCCAgoCggIBAK3oJHP0FDfzm54rVygc" + "h77ct984kIxuPOZXoHj3dcKi/vVqbvYATyjb3miGbESTtrFj/RQSa78f0uoxmyF+" + "0TM8ukj13Xnfs7j/EvEhmkvBioZxaUpmZmyPfjxwv60pIgbz5MDmgK7iS4+3mX6U" + "A5/TR5d8mUgjU+g4rk8Kb4Mu0UlXjIB0ttov0DiNewNwIRt18jA8+o+u3dpjq+sW" + "T8KOEUt+zwvo/7V3LvSye0rgTBIlDHCNAymg4VMk7BPZ7hm/ELNKjD+Jo2FR3qyH" + "B5T0Y3HsLuJvW5iB4YlcNHlsdu87kGJ55tukmi8mxdAQ4Q7e2RCOFvu396j3x+UC" + "B5iPNgiV5+I3lg02dZ77DnKxHZu8A/lJBdiB3QW0KtZB6awBdpUKD9jf1b0SHzUv" + "KBds0pjBqAlkd25HN7rOrFleaJ1/ctaJ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gNVHR8ELDAqMCigJqAkhiJodHRwOi8vY3Js" + "LnJvb3QteDEubGV0c2VuY3J5cHQub3JnMHIGCCsGAQUFBwEBBGYwZDAwBggrBgEF" + "BQcwAYYkaHR0cDovL29jc3Aucm9vdC14MS5sZXRzZW5jcnlwdC5vcmcvMDAGCCsG" + "AQUFBzAChiRodHRwOi8vY2VydC5yb290LXgxLmxldHNlbmNyeXB0Lm9yZy8wHwYD" + "VR0jBBgwFoAUebRZ5nu25eQBc4AIiMgaWPbpm24wDQYJKoZIhvcNAQELBQADggIB" + "ABnPdSA0LTqmRf/Q1eaM2jLonG4bQdEnqOJQ8nCqxOeTRrToEKtwT++36gTSlBGx" + "A/5dut82jJQ2jxN8RI8L9QFXrWi4xXnA2EqA10yjHiR6H9cj6MFiOnb5In1eWsRM" + "UM2v3e9tNsCAgBukPHAg1lQh07rvFKm/Bz9BCjaxorALINUfZ9DD64j2igLIxle2" + "DPxW8dI/F2loHMjXZjqG8RkqZUdoxtID5+90FgsGIfkMpqgRS05f4zPbCEHqCXl1" + "eO5HyELTgcVlLXXQDgAWnRzut1hFJeczY1tjQQno6f6s+nMydLN26WuU4s3UYvOu" + "OsUxRlJu7TSRHqDC3lSE5XggVkzdaPkuKGQbGpny+01/47hfXXNB7HntWNZ6N2Vw" + "p7G6OfY+YQrZwIaQmhrIqJZuigsrbe3W+gdn5ykE9+Ky0VgVUsfxo52mwFYs1JKY" + "2PGDuWx8M6DlS6qQkvHaRUo0FMd8TsSlbF0/v965qGFKhSDeQoMpYnwcmQilRh/0" + "ayLThlHLN81gSkJjVrPI0Y8xCVPB4twb1PFUd2fPM3sA1tJ83sZ5v8vgFv2yofKR" + "PB0t6JzUA81mSqM3kxl5e+IZwhYAyO0OTg3/fs8HqGTNKd9BqoUwSRBzp06JMg5b" + "rUCGwbCUDI0mxadJ3Bz4WxR6fyNpBK2yAinWEsikxqEt" + "\"}" + "]," + "\"trust_stores\": [" /* named cert chains */ + "{" + "\"name\": \"le_via_isrg\"," + "\"stack\": [" + "\"isrg_root_x1\"," + "\"LEX3_isrg_root_x1\"" + "]" + "}" + "]," + "\"s\": [" + + "{\"test_stream\": {" + "\"endpoint\":" "\"warmcat.com\"," + "\"port\":" "443," + "\"protocol\":" "\"h2\"," + "\"http_method\":" "\"GET\"," + "\"http_url\":" "\"index.html\"," + "\"tls\":" "true," + "\"opportunistic\":" "true," + "\"retry\":" "\"default\"," + "\"tls_trust_store\":" "\"le_via_isrg\"" + "}},{" + /* + * "captive_portal_detect" describes + * what to do in order to check if the path to + * the Internet is being interrupted by a + * captive portal. + */ + "\"captive_portal_detect\": {" + "\"endpoint\":" "\"connectivitycheck.android.com\"," + "\"http_url\":" "\"generate_204\"," + "\"port\":" "80," + "\"protocol\":" "\"h1\"," + "\"http_method\":" "\"GET\"," + "\"opportunistic\":" "true," + "\"http_expect\":" "204," + "\"http_fail_redirect\": true" + "}}" + "]}" +; + + diff -Nru libwebsockets-3.2.1/minimal-examples/embedded/esp32/esp-wrover-kit/main/static-policy.h libwebsockets-4.1.6/minimal-examples/embedded/esp32/esp-wrover-kit/main/static-policy.h --- libwebsockets-3.2.1/minimal-examples/embedded/esp32/esp-wrover-kit/main/static-policy.h 1970-01-01 00:00:00.000000000 +0000 +++ libwebsockets-4.1.6/minimal-examples/embedded/esp32/esp-wrover-kit/main/static-policy.h 2020-12-01 17:40:26.000000000 +0000 @@ -0,0 +1,488 @@ +/* + * Autogenerated from the following JSON policy + */ + +#if 0 + { + "release": "01234567", + "product": "myproduct", + "schema-version": 1, + + "retry": [ + {"default": { + "backoff": [ 1000, + 2000, + 3000, + 5000, + 10000 + ], + "conceal": 25, + "jitterpc": 20, + "svalidping": 30, + "svalidhup": 35 + }} + ], + "certs": [ + {"isrg_root_x1": + "MIIFazCCA1OgAwIBAgIRAIIQz7DSQONZRGPgu2OCiwAwDQYJKoZIhvcNAQELBQAwTzELMAkGA1UEBhMCVVMxKTAnBgNVBAoTIEludGVybmV0IFNlY3VyaXR5IFJlc2Vhcm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HqCXl1eO5HyELTgcVlLXXQDgAWnRzut1hFJeczY1tjQQno6f6s+nMydLN26WuU4s3UYvOuOsUxRlJu7TSRHqDC3lSE5XggVkzdaPkuKGQbGpny+01/47hfXXNB7HntWNZ6N2Vwp7G6OfY+YQrZwIaQmhrIqJZuigsrbe3W+gdn5ykE9+Ky0VgVUsfxo52mwFYs1JKY2PGDuWx8M6DlS6qQkvHaRUo0FMd8TsSlbF0/v965qGFKhSDeQoMpYnwcmQilRh/0ayLThlHLN81gSkJjVrPI0Y8xCVPB4twb1PFUd2fPM3sA1tJ83sZ5v8vgFv2yofKRPB0t6JzUA81mSqM3kxl5e+IZwhYAyO0OTg3/fs8HqGTNKd9BqoUwSRBzp06JMg5brUCGwbCUDI0mxadJ3Bz4WxR6fyNpBK2yAinWEsikxqEt"} + ], + "trust_stores": [ + { + "name": "le_via_isrg", + "stack": [ + "isrg_root_x1", + "LEX3_isrg_root_x1" + ] + } + ], + "s": [ + + {"test_stream": { + "endpoint": "warmcat.com", + "port": 443, + "protocol": "h2", + "http_method": "GET", + "http_url": "index.html", + "tls": true, + "opportunistic": true, + "retry": "default", + "tls_trust_store": "le_via_isrg" + }},{ + "captive_portal_detect": { + "endpoint": "connectivitycheck.android.com", + "http_url": "generate_204", + "port": 80, + "protocol": "h1", + "http_method": "GET", + "opportunistic": true, + "http_expect": 204, + "http_fail_redirect": true + }} + ]} + + + Original JSON size: 4903 +#endif + +static const uint32_t _rbo_bo_0[] = { + 1000, 2000, 3000, 5000, 10000, +}; +static const lws_retry_bo_t _rbo_0 = { + .retry_ms_table = _rbo_bo_0, + .retry_ms_table_count = 5, + .conceal_count = 25, + .secs_since_valid_ping = 30, + .secs_since_valid_hangup = 35, + .jitter_percent = 20, +}; +static const uint8_t _ss_der_isrg_root_x1[] = { + /* 0x 0 */ 0x30, 0x82, 0x05, 0x6B, 0x30, 0x82, 0x03, 0x53, + /* 0x 8 */ 0xA0, 0x03, 0x02, 0x01, 0x02, 0x02, 0x11, 0x00, + /* 0x 10 */ 0x82, 0x10, 0xCF, 0xB0, 0xD2, 0x40, 0xE3, 0x59, + /* 0x 18 */ 0x44, 0x63, 0xE0, 0xBB, 0x63, 0x82, 0x8B, 0x00, + /* 0x 20 */ 0x30, 0x0D, 0x06, 0x09, 0x2A, 0x86, 0x48, 0x86, + /* 0x 28 */ 0xF7, 0x0D, 0x01, 0x01, 0x0B, 0x05, 0x00, 0x30, + /* 0x 30 */ 0x4F, 0x31, 0x0B, 0x30, 0x09, 0x06, 0x03, 0x55, + /* 0x 38 */ 0x04, 0x06, 0x13, 0x02, 0x55, 0x53, 0x31, 0x29, + /* 0x 40 */ 0x30, 0x27, 0x06, 0x03, 0x55, 0x04, 0x0A, 0x13, + /* 0x 48 */ 0x20, 0x49, 0x6E, 0x74, 0x65, 0x72, 0x6E, 0x65, + /* 0x 50 */ 0x74, 0x20, 0x53, 0x65, 0x63, 0x75, 0x72, 0x69, + /* 0x 58 */ 0x74, 0x79, 0x20, 0x52, 0x65, 0x73, 0x65, 0x61, + /* 0x 60 */ 0x72, 0x63, 0x68, 0x20, 0x47, 0x72, 0x6F, 0x75, + /* 0x 68 */ 0x70, 0x31, 0x15, 0x30, 0x13, 0x06, 0x03, 0x55, + /* 0x 70 */ 0x04, 0x03, 0x13, 0x0C, 0x49, 0x53, 0x52, 0x47, + /* 0x 78 */ 0x20, 0x52, 0x6F, 0x6F, 0x74, 0x20, 0x58, 0x31, + /* 0x 80 */ 0x30, 0x1E, 0x17, 0x0D, 0x31, 0x35, 0x30, 0x36, + /* 0x 88 */ 0x30, 0x34, 0x31, 0x31, 0x30, 0x34, 0x33, 0x38, + /* 0x 90 */ 0x5A, 0x17, 0x0D, 0x33, 0x35, 0x30, 0x36, 0x30, + /* 0x 98 */ 0x34, 0x31, 0x31, 0x30, 0x34, 0x33, 0x38, 0x5A, + /* 0x a0 */ 0x30, 0x4F, 0x31, 0x0B, 0x30, 0x09, 0x06, 0x03, + /* 0x a8 */ 0x55, 0x04, 0x06, 0x13, 0x02, 0x55, 0x53, 0x31, + /* 0x b0 */ 0x29, 0x30, 0x27, 0x06, 0x03, 0x55, 0x04, 0x0A, + /* 0x b8 */ 0x13, 0x20, 0x49, 0x6E, 0x74, 0x65, 0x72, 0x6E, + /* 0x c0 */ 0x65, 0x74, 0x20, 0x53, 0x65, 0x63, 0x75, 0x72, + /* 0x c8 */ 0x69, 0x74, 0x79, 0x20, 0x52, 0x65, 0x73, 0x65, + /* 0x d0 */ 0x61, 0x72, 0x63, 0x68, 0x20, 0x47, 0x72, 0x6F, + /* 0x d8 */ 0x75, 0x70, 0x31, 0x15, 0x30, 0x13, 0x06, 0x03, + /* 0x e0 */ 0x55, 0x04, 0x03, 0x13, 0x0C, 0x49, 0x53, 0x52, + /* 0x e8 */ 0x47, 0x20, 0x52, 0x6F, 0x6F, 0x74, 0x20, 0x58, + /* 0x f0 */ 0x31, 0x30, 0x82, 0x02, 0x22, 0x30, 0x0D, 0x06, + /* 0x f8 */ 0x09, 0x2A, 0x86, 0x48, 0x86, 0xF7, 0x0D, 0x01, + /* 0x100 */ 0x01, 0x01, 0x05, 0x00, 0x03, 0x82, 0x02, 0x0F, + /* 0x108 */ 0x00, 0x30, 0x82, 0x02, 0x0A, 0x02, 0x82, 0x02, + /* 0x110 */ 0x01, 0x00, 0xAD, 0xE8, 0x24, 0x73, 0xF4, 0x14, + /* 0x118 */ 0x37, 0xF3, 0x9B, 0x9E, 0x2B, 0x57, 0x28, 0x1C, + /* 0x120 */ 0x87, 0xBE, 0xDC, 0xB7, 0xDF, 0x38, 0x90, 0x8C, + /* 0x128 */ 0x6E, 0x3C, 0xE6, 0x57, 0xA0, 0x78, 0xF7, 0x75, + /* 0x130 */ 0xC2, 0xA2, 0xFE, 0xF5, 0x6A, 0x6E, 0xF6, 0x00, + /* 0x138 */ 0x4F, 0x28, 0xDB, 0xDE, 0x68, 0x86, 0x6C, 0x44, + /* 0x140 */ 0x93, 0xB6, 0xB1, 0x63, 0xFD, 0x14, 0x12, 0x6B, + /* 0x148 */ 0xBF, 0x1F, 0xD2, 0xEA, 0x31, 0x9B, 0x21, 0x7E, + /* 0x150 */ 0xD1, 0x33, 0x3C, 0xBA, 0x48, 0xF5, 0xDD, 0x79, + /* 0x158 */ 0xDF, 0xB3, 0xB8, 0xFF, 0x12, 0xF1, 0x21, 0x9A, + /* 0x160 */ 0x4B, 0xC1, 0x8A, 0x86, 0x71, 0x69, 0x4A, 0x66, + /* 0x168 */ 0x66, 0x6C, 0x8F, 0x7E, 0x3C, 0x70, 0xBF, 0xAD, + /* 0x170 */ 0x29, 0x22, 0x06, 0xF3, 0xE4, 0xC0, 0xE6, 0x80, + /* 0x178 */ 0xAE, 0xE2, 0x4B, 0x8F, 0xB7, 0x99, 0x7E, 0x94, + /* 0x180 */ 0x03, 0x9F, 0xD3, 0x47, 0x97, 0x7C, 0x99, 0x48, + /* 0x188 */ 0x23, 0x53, 0xE8, 0x38, 0xAE, 0x4F, 0x0A, 0x6F, + /* 0x190 */ 0x83, 0x2E, 0xD1, 0x49, 0x57, 0x8C, 0x80, 0x74, + /* 0x198 */ 0xB6, 0xDA, 0x2F, 0xD0, 0x38, 0x8D, 0x7B, 0x03, + /* 0x1a0 */ 0x70, 0x21, 0x1B, 0x75, 0xF2, 0x30, 0x3C, 0xFA, + /* 0x1a8 */ 0x8F, 0xAE, 0xDD, 0xDA, 0x63, 0xAB, 0xEB, 0x16, + /* 0x1b0 */ 0x4F, 0xC2, 0x8E, 0x11, 0x4B, 0x7E, 0xCF, 0x0B, + /* 0x1b8 */ 0xE8, 0xFF, 0xB5, 0x77, 0x2E, 0xF4, 0xB2, 0x7B, + /* 0x1c0 */ 0x4A, 0xE0, 0x4C, 0x12, 0x25, 0x0C, 0x70, 0x8D, + /* 0x1c8 */ 0x03, 0x29, 0xA0, 0xE1, 0x53, 0x24, 0xEC, 0x13, + /* 0x1d0 */ 0xD9, 0xEE, 0x19, 0xBF, 0x10, 0xB3, 0x4A, 0x8C, + /* 0x1d8 */ 0x3F, 0x89, 0xA3, 0x61, 0x51, 0xDE, 0xAC, 0x87, + /* 0x1e0 */ 0x07, 0x94, 0xF4, 0x63, 0x71, 0xEC, 0x2E, 0xE2, + /* 0x1e8 */ 0x6F, 0x5B, 0x98, 0x81, 0xE1, 0x89, 0x5C, 0x34, + /* 0x1f0 */ 0x79, 0x6C, 0x76, 0xEF, 0x3B, 0x90, 0x62, 0x79, + /* 0x1f8 */ 0xE6, 0xDB, 0xA4, 0x9A, 0x2F, 0x26, 0xC5, 0xD0, + /* 0x200 */ 0x10, 0xE1, 0x0E, 0xDE, 0xD9, 0x10, 0x8E, 0x16, + /* 0x208 */ 0xFB, 0xB7, 0xF7, 0xA8, 0xF7, 0xC7, 0xE5, 0x02, + /* 0x210 */ 0x07, 0x98, 0x8F, 0x36, 0x08, 0x95, 0xE7, 0xE2, + /* 0x218 */ 0x37, 0x96, 0x0D, 0x36, 0x75, 0x9E, 0xFB, 0x0E, + /* 0x220 */ 0x72, 0xB1, 0x1D, 0x9B, 0xBC, 0x03, 0xF9, 0x49, + /* 0x228 */ 0x05, 0xD8, 0x81, 0xDD, 0x05, 0xB4, 0x2A, 0xD6, + /* 0x230 */ 0x41, 0xE9, 0xAC, 0x01, 0x76, 0x95, 0x0A, 0x0F, + /* 0x238 */ 0xD8, 0xDF, 0xD5, 0xBD, 0x12, 0x1F, 0x35, 0x2F, + /* 0x240 */ 0x28, 0x17, 0x6C, 0xD2, 0x98, 0xC1, 0xA8, 0x09, + /* 0x248 */ 0x64, 0x77, 0x6E, 0x47, 0x37, 0xBA, 0xCE, 0xAC, + /* 0x250 */ 0x59, 0x5E, 0x68, 0x9D, 0x7F, 0x72, 0xD6, 0x89, + /* 0x258 */ 0xC5, 0x06, 0x41, 0x29, 0x3E, 0x59, 0x3E, 0xDD, + /* 0x260 */ 0x26, 0xF5, 0x24, 0xC9, 0x11, 0xA7, 0x5A, 0xA3, + /* 0x268 */ 0x4C, 0x40, 0x1F, 0x46, 0xA1, 0x99, 0xB5, 0xA7, + /* 0x270 */ 0x3A, 0x51, 0x6E, 0x86, 0x3B, 0x9E, 0x7D, 0x72, + /* 0x278 */ 0xA7, 0x12, 0x05, 0x78, 0x59, 0xED, 0x3E, 0x51, + /* 0x280 */ 0x78, 0x15, 0x0B, 0x03, 0x8F, 0x8D, 0xD0, 0x2F, + /* 0x288 */ 0x05, 0xB2, 0x3E, 0x7B, 0x4A, 0x1C, 0x4B, 0x73, + /* 0x290 */ 0x05, 0x12, 0xFC, 0xC6, 0xEA, 0xE0, 0x50, 0x13, + /* 0x298 */ 0x7C, 0x43, 0x93, 0x74, 0xB3, 0xCA, 0x74, 0xE7, + /* 0x2a0 */ 0x8E, 0x1F, 0x01, 0x08, 0xD0, 0x30, 0xD4, 0x5B, + /* 0x2a8 */ 0x71, 0x36, 0xB4, 0x07, 0xBA, 0xC1, 0x30, 0x30, + /* 0x2b0 */ 0x5C, 0x48, 0xB7, 0x82, 0x3B, 0x98, 0xA6, 0x7D, + /* 0x2b8 */ 0x60, 0x8A, 0xA2, 0xA3, 0x29, 0x82, 0xCC, 0xBA, + /* 0x2c0 */ 0xBD, 0x83, 0x04, 0x1B, 0xA2, 0x83, 0x03, 0x41, + /* 0x2c8 */ 0xA1, 0xD6, 0x05, 0xF1, 0x1B, 0xC2, 0xB6, 0xF0, + /* 0x2d0 */ 0xA8, 0x7C, 0x86, 0x3B, 0x46, 0xA8, 0x48, 0x2A, + /* 0x2d8 */ 0x88, 0xDC, 0x76, 0x9A, 0x76, 0xBF, 0x1F, 0x6A, + /* 0x2e0 */ 0xA5, 0x3D, 0x19, 0x8F, 0xEB, 0x38, 0xF3, 0x64, + /* 0x2e8 */ 0xDE, 0xC8, 0x2B, 0x0D, 0x0A, 0x28, 0xFF, 0xF7, + /* 0x2f0 */ 0xDB, 0xE2, 0x15, 0x42, 0xD4, 0x22, 0xD0, 0x27, + /* 0x2f8 */ 0x5D, 0xE1, 0x79, 0xFE, 0x18, 0xE7, 0x70, 0x88, + /* 0x300 */ 0xAD, 0x4E, 0xE6, 0xD9, 0x8B, 0x3A, 0xC6, 0xDD, + /* 0x308 */ 0x27, 0x51, 0x6E, 0xFF, 0xBC, 0x64, 0xF5, 0x33, + /* 0x310 */ 0x43, 0x4F, 0x02, 0x03, 0x01, 0x00, 0x01, 0xA3, + /* 0x318 */ 0x42, 0x30, 0x40, 0x30, 0x0E, 0x06, 0x03, 0x55, + /* 0x320 */ 0x1D, 0x0F, 0x01, 0x01, 0xFF, 0x04, 0x04, 0x03, + /* 0x328 */ 0x02, 0x01, 0x06, 0x30, 0x0F, 0x06, 0x03, 0x55, + /* 0x330 */ 0x1D, 0x13, 0x01, 0x01, 0xFF, 0x04, 0x05, 0x30, + /* 0x338 */ 0x03, 0x01, 0x01, 0xFF, 0x30, 0x1D, 0x06, 0x03, + /* 0x340 */ 0x55, 0x1D, 0x0E, 0x04, 0x16, 0x04, 0x14, 0x79, + /* 0x348 */ 0xB4, 0x59, 0xE6, 0x7B, 0xB6, 0xE5, 0xE4, 0x01, + /* 0x350 */ 0x73, 0x80, 0x08, 0x88, 0xC8, 0x1A, 0x58, 0xF6, + /* 0x358 */ 0xE9, 0x9B, 0x6E, 0x30, 0x0D, 0x06, 0x09, 0x2A, + /* 0x360 */ 0x86, 0x48, 0x86, 0xF7, 0x0D, 0x01, 0x01, 0x0B, + /* 0x368 */ 0x05, 0x00, 0x03, 0x82, 0x02, 0x01, 0x00, 0x55, + /* 0x370 */ 0x1F, 0x58, 0xA9, 0xBC, 0xB2, 0xA8, 0x50, 0xD0, + /* 0x378 */ 0x0C, 0xB1, 0xD8, 0x1A, 0x69, 0x20, 0x27, 0x29, + /* 0x380 */ 0x08, 0xAC, 0x61, 0x75, 0x5C, 0x8A, 0x6E, 0xF8, + /* 0x388 */ 0x82, 0xE5, 0x69, 0x2F, 0xD5, 0xF6, 0x56, 0x4B, + /* 0x390 */ 0xB9, 0xB8, 0x73, 0x10, 0x59, 0xD3, 0x21, 0x97, + /* 0x398 */ 0x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0x55, 0x98, 0x1D, 0xBE, 0x29, 0x86, + /* 0x430 */ 0x8C, 0x22, 0x9B, 0x9E, 0xE2, 0x6B, 0x3B, 0x57, + /* 0x438 */ 0x3A, 0x82, 0x70, 0x4D, 0xDC, 0x09, 0xC7, 0x89, + /* 0x440 */ 0xCB, 0x0A, 0x07, 0x4D, 0x6C, 0xE8, 0x5D, 0x8E, + /* 0x448 */ 0xC9, 0xEF, 0xCE, 0xAB, 0xC7, 0xBB, 0xB5, 0x2B, + /* 0x450 */ 0x4E, 0x45, 0xD6, 0x4A, 0xD0, 0x26, 0xCC, 0xE5, + /* 0x458 */ 0x72, 0xCA, 0x08, 0x6A, 0xA5, 0x95, 0xE3, 0x15, + /* 0x460 */ 0xA1, 0xF7, 0xA4, 0xED, 0xC9, 0x2C, 0x5F, 0xA5, + /* 0x468 */ 0xFB, 0xFF, 0xAC, 0x28, 0x02, 0x2E, 0xBE, 0xD7, + /* 0x470 */ 0x7B, 0xBB, 0xE3, 0x71, 0x7B, 0x90, 0x16, 0xD3, + /* 0x478 */ 0x07, 0x5E, 0x46, 0x53, 0x7C, 0x37, 0x07, 0x42, + /* 0x480 */ 0x8C, 0xD3, 0xC4, 0x96, 0x9C, 0xD5, 0x99, 0xB5, + /* 0x488 */ 0x2A, 0xE0, 0x95, 0x1A, 0x80, 0x48, 0xAE, 0x4C, + /* 0x490 */ 0x39, 0x07, 0xCE, 0xCC, 0x47, 0xA4, 0x52, 0x95, + /* 0x498 */ 0x2B, 0xBA, 0xB8, 0xFB, 0xAD, 0xD2, 0x33, 0x53, + /* 0x4a0 */ 0x7D, 0xE5, 0x1D, 0x4D, 0x6D, 0xD5, 0xA1, 0xB1, + /* 0x4a8 */ 0xC7, 0x42, 0x6F, 0xE6, 0x40, 0x27, 0x35, 0x5C, + /* 0x4b0 */ 0xA3, 0x28, 0xB7, 0x07, 0x8D, 0xE7, 0x8D, 0x33, + /* 0x4b8 */ 0x90, 0xE7, 0x23, 0x9F, 0xFB, 0x50, 0x9C, 0x79, + /* 0x4c0 */ 0x6C, 0x46, 0xD5, 0xB4, 0x15, 0xB3, 0x96, 0x6E, + /* 0x4c8 */ 0x7E, 0x9B, 0x0C, 0x96, 0x3A, 0xB8, 0x52, 0x2D, + /* 0x4d0 */ 0x3F, 0xD6, 0x5B, 0xE1, 0xFB, 0x08, 0xC2, 0x84, + /* 0x4d8 */ 0xFE, 0x24, 0xA8, 0xA3, 0x89, 0xDA, 0xAC, 0x6A, + /* 0x4e0 */ 0xE1, 0x18, 0x2A, 0xB1, 0xA8, 0x43, 0x61, 0x5B, + /* 0x4e8 */ 0xD3, 0x1F, 0xDC, 0x3B, 0x8D, 0x76, 0xF2, 0x2D, + /* 0x4f0 */ 0xE8, 0x8D, 0x75, 0xDF, 0x17, 0x33, 0x6C, 0x3D, + /* 0x4f8 */ 0x53, 0xFB, 0x7B, 0xCB, 0x41, 0x5F, 0xFF, 0xDC, + /* 0x500 */ 0xA2, 0xD0, 0x61, 0x38, 0xE1, 0x96, 0xB8, 0xAC, + /* 0x508 */ 0x5D, 0x8B, 0x37, 0xD7, 0x75, 0xD5, 0x33, 0xC0, + /* 0x510 */ 0x99, 0x11, 0xAE, 0x9D, 0x41, 0xC1, 0x72, 0x75, + /* 0x518 */ 0x84, 0xBE, 0x02, 0x41, 0x42, 0x5F, 0x67, 0x24, + /* 0x520 */ 0x48, 0x94, 0xD1, 0x9B, 0x27, 0xBE, 0x07, 0x3F, + /* 0x528 */ 0xB9, 0xB8, 0x4F, 0x81, 0x74, 0x51, 0xE1, 0x7A, + /* 0x530 */ 0xB7, 0xED, 0x9D, 0x23, 0xE2, 0xBE, 0xE0, 0xD5, + /* 0x538 */ 0x28, 0x04, 0x13, 0x3C, 0x31, 0x03, 0x9E, 0xDD, + /* 0x540 */ 0x7A, 0x6C, 0x8F, 0xC6, 0x07, 0x18, 0xC6, 0x7F, + /* 0x548 */ 0xDE, 0x47, 0x8E, 0x3F, 0x28, 0x9E, 0x04, 0x06, + /* 0x550 */ 0xCF, 0xA5, 0x54, 0x34, 0x77, 0xBD, 0xEC, 0x89, + /* 0x558 */ 0x9B, 0xE9, 0x17, 0x43, 0xDF, 0x5B, 0xDB, 0x5F, + /* 0x560 */ 0xFE, 0x8E, 0x1E, 0x57, 0xA2, 0xCD, 0x40, 0x9D, + /* 0x568 */ 0x7E, 0x62, 0x22, 0xDA, 0xDE, 0x18, 0x27, +}; +static const lws_ss_x509_t _ss_x509_isrg_root_x1 = { + .vhost_name = "isrg_root_x1", + .ca_der = _ss_der_isrg_root_x1, + .ca_der_len = 1391, +}; +static const uint8_t _ss_der_LEX3_isrg_root_x1[] = { + /* 0x 0 */ 0x30, 0x82, 0x05, 0x8D, 0x30, 0x82, 0x03, 0x75, + /* 0x 8 */ 0xA0, 0x03, 0x02, 0x01, 0x02, 0x02, 0x11, 0x00, + /* 0x 10 */ 0xD3, 0xB1, 0x72, 0x26, 0x34, 0x23, 0x32, 0xDC, + /* 0x 18 */ 0xF4, 0x05, 0x28, 0x51, 0x2A, 0xEC, 0x9C, 0x6A, + /* 0x 20 */ 0x30, 0x0D, 0x06, 0x09, 0x2A, 0x86, 0x48, 0x86, + /* 0x 28 */ 0xF7, 0x0D, 0x01, 0x01, 0x0B, 0x05, 0x00, 0x30, + /* 0x 30 */ 0x4F, 0x31, 0x0B, 0x30, 0x09, 0x06, 0x03, 0x55, + /* 0x 38 */ 0x04, 0x06, 0x13, 0x02, 0x55, 0x53, 0x31, 0x29, + /* 0x 40 */ 0x30, 0x27, 0x06, 0x03, 0x55, 0x04, 0x0A, 0x13, + /* 0x 48 */ 0x20, 0x49, 0x6E, 0x74, 0x65, 0x72, 0x6E, 0x65, + /* 0x 50 */ 0x74, 0x20, 0x53, 0x65, 0x63, 0x75, 0x72, 0x69, + /* 0x 58 */ 0x74, 0x79, 0x20, 0x52, 0x65, 0x73, 0x65, 0x61, + /* 0x 60 */ 0x72, 0x63, 0x68, 0x20, 0x47, 0x72, 0x6F, 0x75, + /* 0x 68 */ 0x70, 0x31, 0x15, 0x30, 0x13, 0x06, 0x03, 0x55, + /* 0x 70 */ 0x04, 0x03, 0x13, 0x0C, 0x49, 0x53, 0x52, 0x47, + /* 0x 78 */ 0x20, 0x52, 0x6F, 0x6F, 0x74, 0x20, 0x58, 0x31, + /* 0x 80 */ 0x30, 0x1E, 0x17, 0x0D, 0x31, 0x36, 0x31, 0x30, + /* 0x 88 */ 0x30, 0x36, 0x31, 0x35, 0x34, 0x33, 0x35, 0x35, + /* 0x 90 */ 0x5A, 0x17, 0x0D, 0x32, 0x31, 0x31, 0x30, 0x30, + /* 0x 98 */ 0x36, 0x31, 0x35, 0x34, 0x33, 0x35, 0x35, 0x5A, + /* 0x a0 */ 0x30, 0x4A, 0x31, 0x0B, 0x30, 0x09, 0x06, 0x03, + /* 0x a8 */ 0x55, 0x04, 0x06, 0x13, 0x02, 0x55, 0x53, 0x31, + /* 0x b0 */ 0x16, 0x30, 0x14, 0x06, 0x03, 0x55, 0x04, 0x0A, + /* 0x b8 */ 0x13, 0x0D, 0x4C, 0x65, 0x74, 0x27, 0x73, 0x20, + /* 0x c0 */ 0x45, 0x6E, 0x63, 0x72, 0x79, 0x70, 0x74, 0x31, + /* 0x c8 */ 0x23, 0x30, 0x21, 0x06, 0x03, 0x55, 0x04, 0x03, + /* 0x d0 */ 0x13, 0x1A, 0x4C, 0x65, 0x74, 0x27, 0x73, 0x20, + /* 0x d8 */ 0x45, 0x6E, 0x63, 0x72, 0x79, 0x70, 0x74, 0x20, + /* 0x e0 */ 0x41, 0x75, 0x74, 0x68, 0x6F, 0x72, 0x69, 0x74, + /* 0x e8 */ 0x79, 0x20, 0x58, 0x33, 0x30, 0x82, 0x01, 0x22, + /* 0x f0 */ 0x30, 0x0D, 0x06, 0x09, 0x2A, 0x86, 0x48, 0x86, + /* 0x f8 */ 0xF7, 0x0D, 0x01, 0x01, 0x01, 0x05, 0x00, 0x03, + /* 0x100 */ 0x82, 0x01, 0x0F, 0x00, 0x30, 0x82, 0x01, 0x0A, + /* 0x108 */ 0x02, 0x82, 0x01, 0x01, 0x00, 0x9C, 0xD3, 0x0C, + /* 0x110 */ 0xF0, 0x5A, 0xE5, 0x2E, 0x47, 0xB7, 0x72, 0x5D, + /* 0x118 */ 0x37, 0x83, 0xB3, 0x68, 0x63, 0x30, 0xEA, 0xD7, + /* 0x120 */ 0x35, 0x26, 0x19, 0x25, 0xE1, 0xBD, 0xBE, 0x35, + /* 0x128 */ 0xF1, 0x70, 0x92, 0x2F, 0xB7, 0xB8, 0x4B, 0x41, + /* 0x130 */ 0x05, 0xAB, 0xA9, 0x9E, 0x35, 0x08, 0x58, 0xEC, + /* 0x138 */ 0xB1, 0x2A, 0xC4, 0x68, 0x87, 0x0B, 0xA3, 0xE3, + /* 0x140 */ 0x75, 0xE4, 0xE6, 0xF3, 0xA7, 0x62, 0x71, 0xBA, + /* 0x148 */ 0x79, 0x81, 0x60, 0x1F, 0xD7, 0x91, 0x9A, 0x9F, + /* 0x150 */ 0xF3, 0xD0, 0x78, 0x67, 0x71, 0xC8, 0x69, 0x0E, + /* 0x158 */ 0x95, 0x91, 0xCF, 0xFE, 0xE6, 0x99, 0xE9, 0x60, + /* 0x160 */ 0x3C, 0x48, 0xCC, 0x7E, 0xCA, 0x4D, 0x77, 0x12, + /* 0x168 */ 0x24, 0x9D, 0x47, 0x1B, 0x5A, 0xEB, 0xB9, 0xEC, + /* 0x170 */ 0x1E, 0x37, 0x00, 0x1C, 0x9C, 0xAC, 0x7B, 0xA7, + /* 0x178 */ 0x05, 0xEA, 0xCE, 0x4A, 0xEB, 0xBD, 0x41, 0xE5, + /* 0x180 */ 0x36, 0x98, 0xB9, 0xCB, 0xFD, 0x6D, 0x3C, 0x96, + /* 0x188 */ 0x68, 0xDF, 0x23, 0x2A, 0x42, 0x90, 0x0C, 0x86, + /* 0x190 */ 0x74, 0x67, 0xC8, 0x7F, 0xA5, 0x9A, 0xB8, 0x52, + /* 0x198 */ 0x61, 0x14, 0x13, 0x3F, 0x65, 0xE9, 0x82, 0x87, + /* 0x1a0 */ 0xCB, 0xDB, 0xFA, 0x0E, 0x56, 0xF6, 0x86, 0x89, + /* 0x1a8 */ 0xF3, 0x85, 0x3F, 0x97, 0x86, 0xAF, 0xB0, 0xDC, + /* 0x1b0 */ 0x1A, 0xEF, 0x6B, 0x0D, 0x95, 0x16, 0x7D, 0xC4, + /* 0x1b8 */ 0x2B, 0xA0, 0x65, 0xB2, 0x99, 0x04, 0x36, 0x75, + /* 0x1c0 */ 0x80, 0x6B, 0xAC, 0x4A, 0xF3, 0x1B, 0x90, 0x49, + /* 0x1c8 */ 0x78, 0x2F, 0xA2, 0x96, 0x4F, 0x2A, 0x20, 0x25, + /* 0x1d0 */ 0x29, 0x04, 0xC6, 0x74, 0xC0, 0xD0, 0x31, 0xCD, + /* 0x1d8 */ 0x8F, 0x31, 0x38, 0x95, 0x16, 0xBA, 0xA8, 0x33, + /* 0x1e0 */ 0xB8, 0x43, 0xF1, 0xB1, 0x1F, 0xC3, 0x30, 0x7F, + /* 0x1e8 */ 0xA2, 0x79, 0x31, 0x13, 0x3D, 0x2D, 0x36, 0xF8, + /* 0x1f0 */ 0xE3, 0xFC, 0xF2, 0x33, 0x6A, 0xB9, 0x39, 0x31, + /* 0x1f8 */ 0xC5, 0xAF, 0xC4, 0x8D, 0x0D, 0x1D, 0x64, 0x16, + /* 0x200 */ 0x33, 0xAA, 0xFA, 0x84, 0x29, 0xB6, 0xD4, 0x0B, + /* 0x208 */ 0xC0, 0xD8, 0x7D, 0xC3, 0x93, 0x02, 0x03, 0x01, + /* 0x210 */ 0x00, 0x01, 0xA3, 0x82, 0x01, 0x67, 0x30, 0x82, + /* 0x218 */ 0x01, 0x63, 0x30, 0x0E, 0x06, 0x03, 0x55, 0x1D, + /* 0x220 */ 0x0F, 0x01, 0x01, 0xFF, 0x04, 0x04, 0x03, 0x02, + /* 0x228 */ 0x01, 0x86, 0x30, 0x12, 0x06, 0x03, 0x55, 0x1D, + /* 0x230 */ 0x13, 0x01, 0x01, 0xFF, 0x04, 0x08, 0x30, 0x06, + /* 0x238 */ 0x01, 0x01, 0xFF, 0x02, 0x01, 0x00, 0x30, 0x54, + /* 0x240 */ 0x06, 0x03, 0x55, 0x1D, 0x20, 0x04, 0x4D, 0x30, + /* 0x248 */ 0x4B, 0x30, 0x08, 0x06, 0x06, 0x67, 0x81, 0x0C, + /* 0x250 */ 0x01, 0x02, 0x01, 0x30, 0x3F, 0x06, 0x0B, 0x2B, + /* 0x258 */ 0x06, 0x01, 0x04, 0x01, 0x82, 0xDF, 0x13, 0x01, + /* 0x260 */ 0x01, 0x01, 0x30, 0x30, 0x30, 0x2E, 0x06, 0x08, + /* 0x268 */ 0x2B, 0x06, 0x01, 0x05, 0x05, 0x07, 0x02, 0x01, + /* 0x270 */ 0x16, 0x22, 0x68, 0x74, 0x74, 0x70, 0x3A, 0x2F, + /* 0x278 */ 0x2F, 0x63, 0x70, 0x73, 0x2E, 0x72, 0x6F, 0x6F, + /* 0x280 */ 0x74, 0x2D, 0x78, 0x31, 0x2E, 0x6C, 0x65, 0x74, + /* 0x288 */ 0x73, 0x65, 0x6E, 0x63, 0x72, 0x79, 0x70, 0x74, + /* 0x290 */ 0x2E, 0x6F, 0x72, 0x67, 0x30, 0x1D, 0x06, 0x03, + /* 0x298 */ 0x55, 0x1D, 0x0E, 0x04, 0x16, 0x04, 0x14, 0xA8, + /* 0x2a0 */ 0x4A, 0x6A, 0x63, 0x04, 0x7D, 0xDD, 0xBA, 0xE6, + /* 0x2a8 */ 0xD1, 0x39, 0xB7, 0xA6, 0x45, 0x65, 0xEF, 0xF3, + /* 0x2b0 */ 0xA8, 0xEC, 0xA1, 0x30, 0x33, 0x06, 0x03, 0x55, + /* 0x2b8 */ 0x1D, 0x1F, 0x04, 0x2C, 0x30, 0x2A, 0x30, 0x28, + /* 0x2c0 */ 0xA0, 0x26, 0xA0, 0x24, 0x86, 0x22, 0x68, 0x74, + /* 0x2c8 */ 0x74, 0x70, 0x3A, 0x2F, 0x2F, 0x63, 0x72, 0x6C, + /* 0x2d0 */ 0x2E, 0x72, 0x6F, 0x6F, 0x74, 0x2D, 0x78, 0x31, + /* 0x2d8 */ 0x2E, 0x6C, 0x65, 0x74, 0x73, 0x65, 0x6E, 0x63, + /* 0x2e0 */ 0x72, 0x79, 0x70, 0x74, 0x2E, 0x6F, 0x72, 0x67, + /* 0x2e8 */ 0x30, 0x72, 0x06, 0x08, 0x2B, 0x06, 0x01, 0x05, + /* 0x2f0 */ 0x05, 0x07, 0x01, 0x01, 0x04, 0x66, 0x30, 0x64, + /* 0x2f8 */ 0x30, 0x30, 0x06, 0x08, 0x2B, 0x06, 0x01, 0x05, + /* 0x300 */ 0x05, 0x07, 0x30, 0x01, 0x86, 0x24, 0x68, 0x74, + /* 0x308 */ 0x74, 0x70, 0x3A, 0x2F, 0x2F, 0x6F, 0x63, 0x73, + /* 0x310 */ 0x70, 0x2E, 0x72, 0x6F, 0x6F, 0x74, 0x2D, 0x78, + /* 0x318 */ 0x31, 0x2E, 0x6C, 0x65, 0x74, 0x73, 0x65, 0x6E, + /* 0x320 */ 0x63, 0x72, 0x79, 0x70, 0x74, 0x2E, 0x6F, 0x72, + /* 0x328 */ 0x67, 0x2F, 0x30, 0x30, 0x06, 0x08, 0x2B, 0x06, + /* 0x330 */ 0x01, 0x05, 0x05, 0x07, 0x30, 0x02, 0x86, 0x24, + /* 0x338 */ 0x68, 0x74, 0x74, 0x70, 0x3A, 0x2F, 0x2F, 0x63, + /* 0x340 */ 0x65, 0x72, 0x74, 0x2E, 0x72, 0x6F, 0x6F, 0x74, + /* 0x348 */ 0x2D, 0x78, 0x31, 0x2E, 0x6C, 0x65, 0x74, 0x73, + /* 0x350 */ 0x65, 0x6E, 0x63, 0x72, 0x79, 0x70, 0x74, 0x2E, + /* 0x358 */ 0x6F, 0x72, 0x67, 0x2F, 0x30, 0x1F, 0x06, 0x03, + /* 0x360 */ 0x55, 0x1D, 0x23, 0x04, 0x18, 0x30, 0x16, 0x80, + /* 0x368 */ 0x14, 0x79, 0xB4, 0x59, 0xE6, 0x7B, 0xB6, 0xE5, + /* 0x370 */ 0xE4, 0x01, 0x73, 0x80, 0x08, 0x88, 0xC8, 0x1A, + /* 0x378 */ 0x58, 0xF6, 0xE9, 0x9B, 0x6E, 0x30, 0x0D, 0x06, + /* 0x380 */ 0x09, 0x2A, 0x86, 0x48, 0x86, 0xF7, 0x0D, 0x01, + /* 0x388 */ 0x01, 0x0B, 0x05, 0x00, 0x03, 0x82, 0x02, 0x01, + /* 0x390 */ 0x00, 0x19, 0xCF, 0x75, 0x20, 0x34, 0x2D, 0x3A, + /* 0x398 */ 0xA6, 0x45, 0xFF, 0xD0, 0xD5, 0xE6, 0x8C, 0xDA, + /* 0x3a0 */ 0x32, 0xE8, 0x9C, 0x6E, 0x1B, 0x41, 0xD1, 0x27, + /* 0x3a8 */ 0xA8, 0xE2, 0x50, 0xF2, 0x70, 0xAA, 0xC4, 0xE7, + /* 0x3b0 */ 0x93, 0x46, 0xB4, 0xE8, 0x10, 0xAB, 0x70, 0x4F, + /* 0x3b8 */ 0xEF, 0xB7, 0xEA, 0x04, 0xD2, 0x94, 0x11, 0xB1, + /* 0x3c0 */ 0x03, 0xFE, 0x5D, 0xBA, 0xDF, 0x36, 0x8C, 0x94, + /* 0x3c8 */ 0x36, 0x8F, 0x13, 0x7C, 0x44, 0x8F, 0x0B, 0xF5, + /* 0x3d0 */ 0x01, 0x57, 0xAD, 0x68, 0xB8, 0xC5, 0x79, 0xC0, + /* 0x3d8 */ 0xD8, 0x4A, 0x80, 0xD7, 0x4C, 0xA3, 0x1E, 0x24, + /* 0x3e0 */ 0x7A, 0x1F, 0xD7, 0x23, 0xE8, 0xC1, 0x62, 0x3A, + /* 0x3e8 */ 0x76, 0xF9, 0x22, 0x7D, 0x5E, 0x5A, 0xC4, 0x4C, + /* 0x3f0 */ 0x50, 0xCD, 0xAF, 0xDD, 0xEF, 0x6D, 0x36, 0xC0, + /* 0x3f8 */ 0x80, 0x80, 0x1B, 0xA4, 0x3C, 0x70, 0x20, 0xD6, + /* 0x400 */ 0x54, 0x21, 0xD3, 0xBA, 0xEF, 0x14, 0xA9, 0xBF, + /* 0x408 */ 0x07, 0x3F, 0x41, 0x0A, 0x36, 0xB1, 0xA2, 0xB0, + /* 0x410 */ 0x0B, 0x20, 0xD5, 0x1F, 0x67, 0xD0, 0xC3, 0xEB, + /* 0x418 */ 0x88, 0xF6, 0x8A, 0x02, 0xC8, 0xC6, 0x57, 0xB6, + /* 0x420 */ 0x0C, 0xFC, 0x56, 0xF1, 0xD2, 0x3F, 0x17, 0x69, + /* 0x428 */ 0x68, 0x1C, 0xC8, 0xD7, 0x66, 0x3A, 0x86, 0xF1, + /* 0x430 */ 0x19, 0x2A, 0x65, 0x47, 0x68, 0xC6, 0xD2, 0x03, + /* 0x438 */ 0xE7, 0xEF, 0x74, 0x16, 0x0B, 0x06, 0x21, 0xF9, + /* 0x440 */ 0x0C, 0xA6, 0xA8, 0x11, 0x4B, 0x4E, 0x5F, 0xE3, + /* 0x448 */ 0x33, 0xDB, 0x08, 0x41, 0xEA, 0x09, 0x79, 0x75, + /* 0x450 */ 0x78, 0xEE, 0x47, 0xC8, 0x42, 0xD3, 0x81, 0xC5, + /* 0x458 */ 0x65, 0x2D, 0x75, 0xD0, 0x0E, 0x00, 0x16, 0x9D, + /* 0x460 */ 0x1C, 0xEE, 0xB7, 0x58, 0x45, 0x25, 0xE7, 0x33, + /* 0x468 */ 0x63, 0x5B, 0x63, 0x41, 0x09, 0xE8, 0xE9, 0xFE, + /* 0x470 */ 0xAC, 0xFA, 0x73, 0x32, 0x74, 0xB3, 0x76, 0xE9, + /* 0x478 */ 0x6B, 0x94, 0xE2, 0xCD, 0xD4, 0x62, 0xF3, 0xAE, + /* 0x480 */ 0x3A, 0xC5, 0x31, 0x46, 0x52, 0x6E, 0xED, 0x34, + /* 0x488 */ 0x91, 0x1E, 0xA0, 0xC2, 0xDE, 0x54, 0x84, 0xE5, + /* 0x490 */ 0x78, 0x20, 0x56, 0x4C, 0xDD, 0x68, 0xF9, 0x2E, + /* 0x498 */ 0x28, 0x64, 0x1B, 0x1A, 0x99, 0xF2, 0xFB, 0x4D, + /* 0x4a0 */ 0x7F, 0xE3, 0xB8, 0x5F, 0x5D, 0x73, 0x41, 0xEC, + /* 0x4a8 */ 0x79, 0xED, 0x58, 0xD6, 0x7A, 0x37, 0x65, 0x70, + /* 0x4b0 */ 0xA7, 0xB1, 0xBA, 0x39, 0xF6, 0x3E, 0x61, 0x0A, + /* 0x4b8 */ 0xD9, 0xC0, 0x86, 0x90, 0x9A, 0x1A, 0xC8, 0xA8, + /* 0x4c0 */ 0x96, 0x6E, 0x8A, 0x0B, 0x2B, 0x6D, 0xED, 0xD6, + /* 0x4c8 */ 0xFA, 0x07, 0x67, 0xE7, 0x29, 0x04, 0xF7, 0xE2, + /* 0x4d0 */ 0xB2, 0xD1, 0x58, 0x15, 0x52, 0xC7, 0xF1, 0xA3, + /* 0x4d8 */ 0x9D, 0xA6, 0xC0, 0x56, 0x2C, 0xD4, 0x92, 0x98, + /* 0x4e0 */ 0xD8, 0xF1, 0x83, 0xB9, 0x6C, 0x7C, 0x33, 0xA0, + /* 0x4e8 */ 0xE5, 0x4B, 0xAA, 0x90, 0x92, 0xF1, 0xDA, 0x45, + /* 0x4f0 */ 0x4A, 0x34, 0x14, 0xC7, 0x7C, 0x4E, 0xC4, 0xA5, + /* 0x4f8 */ 0x6C, 0x5D, 0x3F, 0xBF, 0xDE, 0xB9, 0xA8, 0x61, + /* 0x500 */ 0x4A, 0x85, 0x20, 0xDE, 0x42, 0x83, 0x29, 0x62, + /* 0x508 */ 0x7C, 0x1C, 0x99, 0x08, 0xA5, 0x46, 0x1F, 0xF4, + /* 0x510 */ 0x6B, 0x22, 0xD3, 0x86, 0x51, 0xCB, 0x37, 0xCD, + /* 0x518 */ 0x60, 0x4A, 0x42, 0x63, 0x56, 0xB3, 0xC8, 0xD1, + /* 0x520 */ 0x8F, 0x31, 0x09, 0x53, 0xC1, 0xE2, 0xDC, 0x1B, + /* 0x528 */ 0xD4, 0xF1, 0x54, 0x77, 0x67, 0xCF, 0x33, 0x7B, + /* 0x530 */ 0x00, 0xD6, 0xD2, 0x7C, 0xDE, 0xC6, 0x79, 0xBF, + /* 0x538 */ 0xCB, 0xE0, 0x16, 0xFD, 0xB2, 0xA1, 0xF2, 0x91, + /* 0x540 */ 0x3C, 0x1D, 0x2D, 0xE8, 0x9C, 0xD4, 0x03, 0xCD, + /* 0x548 */ 0x66, 0x4A, 0xA3, 0x37, 0x93, 0x19, 0x79, 0x7B, + /* 0x550 */ 0xE2, 0x19, 0xC2, 0x16, 0x00, 0xC8, 0xED, 0x0E, + /* 0x558 */ 0x4E, 0x0D, 0xFF, 0x7E, 0xCF, 0x07, 0xA8, 0x64, + /* 0x560 */ 0xCD, 0x29, 0xDF, 0x41, 0xAA, 0x85, 0x30, 0x49, + /* 0x568 */ 0x10, 0x73, 0xA7, 0x4E, 0x89, 0x32, 0x0E, 0x5B, + /* 0x570 */ 0xAD, 0x40, 0x86, 0xC1, 0xB0, 0x94, 0x0C, 0x8D, + /* 0x578 */ 0x26, 0xC5, 0xA7, 0x49, 0xDC, 0x1C, 0xF8, 0x5B, + /* 0x580 */ 0x14, 0x7A, 0x7F, 0x23, 0x69, 0x04, 0xAD, 0xB2, + /* 0x588 */ 0x02, 0x29, 0xD6, 0x12, 0xC8, 0xA4, 0xC6, 0xA1, + /* 0x590 */ 0x2D, +}; +static const lws_ss_x509_t _ss_x509_LEX3_isrg_root_x1 = { + .vhost_name = "LEX3_isrg_root_x1", + .ca_der = _ss_der_LEX3_isrg_root_x1, + .ca_der_len = 1425, +}; +static const lws_ss_trust_store_t _ss_ts_le_via_isrg = { + .name = "le_via_isrg", + .ssx509 = { + &_ss_x509_LEX3_isrg_root_x1, + &_ss_x509_isrg_root_x1, + } +}; + +static const lws_ss_policy_t _ssp_captive_portal_detect = { + .streamtype = "captive_portal_detect", + .endpoint = "connectivitycheck.android.com", + .u = { + .http = { + .method = "GET", + .url = "generate_204", + .resp_expect = 204, + .fail_redirect = 1, + } + }, + .flags = 0x1, + .port = 80, + .protocol = 0, +}, +_ssp_test_stream = { + .next = (void *)&_ssp_captive_portal_detect, + .streamtype = "test_stream", + .endpoint = "warmcat.com", + .u = { + .http = { + .method = "GET", + .url = "index.html", + } + }, + .retry_bo = &_rbo_0, + .flags = 0x11, + .port = 443, + .protocol = 1, + .trust = {.store = &_ss_ts_le_via_isrg}, +}; +#define _ss_static_policy_entry _ssp_test_stream +/* estimated footprint 3412 (when sizeof void * = 8) */ diff -Nru libwebsockets-3.2.1/minimal-examples/embedded/esp32/esp-wrover-kit/partitions.csv libwebsockets-4.1.6/minimal-examples/embedded/esp32/esp-wrover-kit/partitions.csv --- libwebsockets-3.2.1/minimal-examples/embedded/esp32/esp-wrover-kit/partitions.csv 1970-01-01 00:00:00.000000000 +0000 +++ libwebsockets-4.1.6/minimal-examples/embedded/esp32/esp-wrover-kit/partitions.csv 2020-12-01 17:40:26.000000000 +0000 @@ -0,0 +1,5 @@ +# ESP-IDF Partition Table +# Name, Type, SubType, Offset, Size, Flags +nvs, data, nvs, 0x9000, 0x6000, +phy_init, data, phy, 0xf000, 0x1000, +factory, app, factory, 0x10000, 2M, diff -Nru libwebsockets-3.2.1/minimal-examples/embedded/esp32/esp-wrover-kit/rgb565/rgb565.c libwebsockets-4.1.6/minimal-examples/embedded/esp32/esp-wrover-kit/rgb565/rgb565.c --- libwebsockets-3.2.1/minimal-examples/embedded/esp32/esp-wrover-kit/rgb565/rgb565.c 1970-01-01 00:00:00.000000000 +0000 +++ libwebsockets-4.1.6/minimal-examples/embedded/esp32/esp-wrover-kit/rgb565/rgb565.c 2020-12-01 17:40:26.000000000 +0000 @@ -0,0 +1,26 @@ +/* + * gcc /tmp/q.c && convert cat-565.png -depth 8 rgb:- | ./a.out > cat-565.h + */ + +#include + +int main() +{ + int r, g, b, w, m = 0; + + while (1) { + r = getchar(); + g = getchar(); + b = getchar(); + + if (r == EOF || g == EOF || b == EOF) + return r == EOF; + + w = (b >> 3) | ((g >> 2) << 5) | ((r >> 3) << 11); + printf("0x%02X, 0x%02X, ", (w >> 8) & 0xFF, w & 0xFF); + + if (((++m) & 3) == 0) + printf("\n"); + } +} + diff -Nru libwebsockets-3.2.1/minimal-examples/embedded/esp32/esp-wrover-kit/sdkconfig libwebsockets-4.1.6/minimal-examples/embedded/esp32/esp-wrover-kit/sdkconfig --- libwebsockets-3.2.1/minimal-examples/embedded/esp32/esp-wrover-kit/sdkconfig 1970-01-01 00:00:00.000000000 +0000 +++ libwebsockets-4.1.6/minimal-examples/embedded/esp32/esp-wrover-kit/sdkconfig 2020-12-01 17:40:26.000000000 +0000 @@ -0,0 +1,1151 @@ +# +# Automatically generated file. DO NOT EDIT. +# Espressif IoT Development Framework (ESP-IDF) Project Configuration +# +CONFIG_IDF_CMAKE=y +CONFIG_IDF_TARGET="esp32" +CONFIG_IDF_TARGET_ESP32=y +CONFIG_IDF_FIRMWARE_CHIP_ID=0x0000 + +# +# SDK tool configuration +# +CONFIG_SDK_TOOLPREFIX="xtensa-esp32-elf-" +# CONFIG_SDK_TOOLCHAIN_SUPPORTS_TIME_WIDE_64_BITS is not set +# end of SDK tool configuration + +# +# Build type +# +CONFIG_APP_BUILD_TYPE_APP_2NDBOOT=y +# CONFIG_APP_BUILD_TYPE_ELF_RAM is not set +CONFIG_APP_BUILD_GENERATE_BINARIES=y +CONFIG_APP_BUILD_BOOTLOADER=y +CONFIG_APP_BUILD_USE_FLASH_SECTIONS=y +# end of Build type + +# +# Application manager +# +CONFIG_APP_COMPILE_TIME_DATE=y +# CONFIG_APP_EXCLUDE_PROJECT_VER_VAR is not set +# CONFIG_APP_EXCLUDE_PROJECT_NAME_VAR is not set +# CONFIG_APP_PROJECT_VER_FROM_CONFIG is not set +CONFIG_APP_RETRIEVE_LEN_ELF_SHA=16 +# end of Application manager + +# +# Bootloader config +# +CONFIG_BOOTLOADER_COMPILER_OPTIMIZATION_SIZE=y +# CONFIG_BOOTLOADER_COMPILER_OPTIMIZATION_DEBUG is not set +# CONFIG_BOOTLOADER_COMPILER_OPTIMIZATION_PERF is not set +# CONFIG_BOOTLOADER_COMPILER_OPTIMIZATION_NONE is not set +# CONFIG_BOOTLOADER_LOG_LEVEL_NONE is not set +# CONFIG_BOOTLOADER_LOG_LEVEL_ERROR is not set +# CONFIG_BOOTLOADER_LOG_LEVEL_WARN is not set +CONFIG_BOOTLOADER_LOG_LEVEL_INFO=y +# CONFIG_BOOTLOADER_LOG_LEVEL_DEBUG is not set +# CONFIG_BOOTLOADER_LOG_LEVEL_VERBOSE is not set +CONFIG_BOOTLOADER_LOG_LEVEL=3 +# CONFIG_BOOTLOADER_VDDSDIO_BOOST_1_8V is not set +CONFIG_BOOTLOADER_VDDSDIO_BOOST_1_9V=y +# CONFIG_BOOTLOADER_FACTORY_RESET is not set +# CONFIG_BOOTLOADER_APP_TEST is not set +CONFIG_BOOTLOADER_WDT_ENABLE=y +# CONFIG_BOOTLOADER_WDT_DISABLE_IN_USER_CODE is not set +CONFIG_BOOTLOADER_WDT_TIME_MS=9000 +# CONFIG_BOOTLOADER_APP_ROLLBACK_ENABLE is not set +# CONFIG_BOOTLOADER_SKIP_VALIDATE_IN_DEEP_SLEEP is not set +CONFIG_BOOTLOADER_RESERVE_RTC_SIZE=0 +# CONFIG_BOOTLOADER_CUSTOM_RESERVE_RTC is not set +# end of Bootloader config + +# +# Security features +# +# CONFIG_SECURE_SIGNED_APPS_NO_SECURE_BOOT is not set +# CONFIG_SECURE_BOOT is not set +# CONFIG_SECURE_FLASH_ENC_ENABLED is not set +# end of Security features + +# +# Serial flasher config +# +CONFIG_ESPTOOLPY_BAUD_OTHER_VAL=115200 +# CONFIG_ESPTOOLPY_FLASHMODE_QIO is not set +# CONFIG_ESPTOOLPY_FLASHMODE_QOUT is not set +CONFIG_ESPTOOLPY_FLASHMODE_DIO=y +# CONFIG_ESPTOOLPY_FLASHMODE_DOUT is not set +CONFIG_ESPTOOLPY_FLASHMODE="dio" +# CONFIG_ESPTOOLPY_FLASHFREQ_80M is not set +CONFIG_ESPTOOLPY_FLASHFREQ_40M=y +# CONFIG_ESPTOOLPY_FLASHFREQ_26M is not set +# CONFIG_ESPTOOLPY_FLASHFREQ_20M is not set +CONFIG_ESPTOOLPY_FLASHFREQ="40m" +# CONFIG_ESPTOOLPY_FLASHSIZE_1MB is not set +# CONFIG_ESPTOOLPY_FLASHSIZE_2MB is not set +CONFIG_ESPTOOLPY_FLASHSIZE_4MB=y +# CONFIG_ESPTOOLPY_FLASHSIZE_8MB is not set +# CONFIG_ESPTOOLPY_FLASHSIZE_16MB is not set +CONFIG_ESPTOOLPY_FLASHSIZE="4MB" +CONFIG_ESPTOOLPY_FLASHSIZE_DETECT=y +CONFIG_ESPTOOLPY_BEFORE_RESET=y +# CONFIG_ESPTOOLPY_BEFORE_NORESET is not set +CONFIG_ESPTOOLPY_BEFORE="default_reset" +CONFIG_ESPTOOLPY_AFTER_RESET=y +# CONFIG_ESPTOOLPY_AFTER_NORESET is not set +CONFIG_ESPTOOLPY_AFTER="hard_reset" +# CONFIG_ESPTOOLPY_MONITOR_BAUD_9600B is not set +# CONFIG_ESPTOOLPY_MONITOR_BAUD_57600B is not set +CONFIG_ESPTOOLPY_MONITOR_BAUD_115200B=y +# CONFIG_ESPTOOLPY_MONITOR_BAUD_230400B is not set +# CONFIG_ESPTOOLPY_MONITOR_BAUD_921600B is not set +# CONFIG_ESPTOOLPY_MONITOR_BAUD_2MB is not set +# CONFIG_ESPTOOLPY_MONITOR_BAUD_OTHER is not set +CONFIG_ESPTOOLPY_MONITOR_BAUD_OTHER_VAL=115200 +CONFIG_ESPTOOLPY_MONITOR_BAUD=115200 +# end of Serial flasher config + +# +# Partition Table +# +# CONFIG_PARTITION_TABLE_SINGLE_APP is not set +# CONFIG_PARTITION_TABLE_TWO_OTA is not set +CONFIG_PARTITION_TABLE_CUSTOM=y +CONFIG_PARTITION_TABLE_CUSTOM_FILENAME="partitions.csv" +CONFIG_PARTITION_TABLE_FILENAME="partitions.csv" +CONFIG_PARTITION_TABLE_OFFSET=0x8000 +CONFIG_PARTITION_TABLE_MD5=y +# end of Partition Table + +# +# Compiler options +# +CONFIG_COMPILER_OPTIMIZATION_DEFAULT=y +# CONFIG_COMPILER_OPTIMIZATION_SIZE is not set +# CONFIG_COMPILER_OPTIMIZATION_PERF is not set +# CONFIG_COMPILER_OPTIMIZATION_NONE is not set +CONFIG_COMPILER_OPTIMIZATION_ASSERTIONS_ENABLE=y +# CONFIG_COMPILER_OPTIMIZATION_ASSERTIONS_SILENT is not set +# CONFIG_COMPILER_OPTIMIZATION_ASSERTIONS_DISABLE is not set +# CONFIG_COMPILER_CXX_EXCEPTIONS is not set +# CONFIG_COMPILER_CXX_RTTI is not set +CONFIG_COMPILER_STACK_CHECK_MODE_NONE=y +# CONFIG_COMPILER_STACK_CHECK_MODE_NORM is not set +# CONFIG_COMPILER_STACK_CHECK_MODE_STRONG is not set +# CONFIG_COMPILER_STACK_CHECK_MODE_ALL is not set +# CONFIG_COMPILER_WARN_WRITE_STRINGS is not set +# CONFIG_COMPILER_DISABLE_GCC8_WARNINGS is not set +# end of Compiler options + +# +# Component config +# + +# +# Application Level Tracing +# +# CONFIG_APPTRACE_DEST_TRAX is not set +CONFIG_APPTRACE_DEST_NONE=y +CONFIG_APPTRACE_LOCK_ENABLE=y +# end of Application Level Tracing + +# +# Bluetooth +# +# CONFIG_BT_ENABLED is not set +CONFIG_BTDM_CTRL_BR_EDR_SCO_DATA_PATH_EFF=0 +CONFIG_BTDM_CTRL_BLE_MAX_CONN_EFF=0 +CONFIG_BTDM_CTRL_BR_EDR_MAX_ACL_CONN_EFF=0 +CONFIG_BTDM_CTRL_BR_EDR_MAX_SYNC_CONN_EFF=0 +CONFIG_BTDM_CTRL_PINNED_TO_CORE=0 +CONFIG_BTDM_BLE_SLEEP_CLOCK_ACCURACY_INDEX_EFF=1 +CONFIG_BT_RESERVE_DRAM=0 +# end of Bluetooth + +# +# CoAP Configuration +# +CONFIG_COAP_MBEDTLS_PSK=y +# CONFIG_COAP_MBEDTLS_PKI is not set +# CONFIG_COAP_MBEDTLS_DEBUG is not set +CONFIG_COAP_LOG_DEFAULT_LEVEL=0 +# end of CoAP Configuration + +# +# Driver configurations +# + +# +# ADC configuration +# +# CONFIG_ADC_FORCE_XPD_FSM is not set +CONFIG_ADC_DISABLE_DAC=y +# end of ADC configuration + +# +# SPI configuration +# +# CONFIG_SPI_MASTER_IN_IRAM is not set +CONFIG_SPI_MASTER_ISR_IN_IRAM=y +# CONFIG_SPI_SLAVE_IN_IRAM is not set +CONFIG_SPI_SLAVE_ISR_IN_IRAM=y +# end of SPI configuration + +# +# UART configuration +# +# CONFIG_UART_ISR_IN_IRAM is not set +# end of UART configuration + +# +# RTCIO configuration +# +# CONFIG_RTCIO_SUPPORT_RTC_GPIO_DESC is not set +# end of RTCIO configuration +# end of Driver configurations + +# +# eFuse Bit Manager +# +# CONFIG_EFUSE_CUSTOM_TABLE is not set +# CONFIG_EFUSE_VIRTUAL is not set +# CONFIG_EFUSE_CODE_SCHEME_COMPAT_NONE is not set +CONFIG_EFUSE_CODE_SCHEME_COMPAT_3_4=y +# CONFIG_EFUSE_CODE_SCHEME_COMPAT_REPEAT is not set +CONFIG_EFUSE_MAX_BLK_LEN=192 +# end of eFuse Bit Manager + +# +# ESP-TLS +# +CONFIG_ESP_TLS_USING_MBEDTLS=y +# CONFIG_ESP_TLS_USE_SECURE_ELEMENT is not set +# CONFIG_ESP_TLS_SERVER is not set +# CONFIG_ESP_TLS_PSK_VERIFICATION is not set +# end of ESP-TLS + +# +# ESP32-specific +# +CONFIG_ESP32_REV_MIN_0=y +# CONFIG_ESP32_REV_MIN_1 is not set +# CONFIG_ESP32_REV_MIN_2 is not set +# CONFIG_ESP32_REV_MIN_3 is not set +CONFIG_ESP32_REV_MIN=0 +CONFIG_ESP32_DPORT_WORKAROUND=y +# CONFIG_ESP32_DEFAULT_CPU_FREQ_80 is not set +CONFIG_ESP32_DEFAULT_CPU_FREQ_160=y +# CONFIG_ESP32_DEFAULT_CPU_FREQ_240 is not set +CONFIG_ESP32_DEFAULT_CPU_FREQ_MHZ=160 +# CONFIG_ESP32_SPIRAM_SUPPORT is not set +# CONFIG_ESP32_TRAX is not set +CONFIG_ESP32_TRACEMEM_RESERVE_DRAM=0x0 +# CONFIG_ESP32_UNIVERSAL_MAC_ADDRESSES_TWO is not set +CONFIG_ESP32_UNIVERSAL_MAC_ADDRESSES_FOUR=y +CONFIG_ESP32_UNIVERSAL_MAC_ADDRESSES=4 +# CONFIG_ESP32_ULP_COPROC_ENABLED is not set +CONFIG_ESP32_ULP_COPROC_RESERVE_MEM=0 +CONFIG_ESP32_DEBUG_OCDAWARE=y +CONFIG_ESP32_BROWNOUT_DET=y +CONFIG_ESP32_BROWNOUT_DET_LVL_SEL_0=y +# CONFIG_ESP32_BROWNOUT_DET_LVL_SEL_1 is not set +# CONFIG_ESP32_BROWNOUT_DET_LVL_SEL_2 is not set +# CONFIG_ESP32_BROWNOUT_DET_LVL_SEL_3 is not set +# CONFIG_ESP32_BROWNOUT_DET_LVL_SEL_4 is not set +# CONFIG_ESP32_BROWNOUT_DET_LVL_SEL_5 is not set +# CONFIG_ESP32_BROWNOUT_DET_LVL_SEL_6 is not set +# CONFIG_ESP32_BROWNOUT_DET_LVL_SEL_7 is not set +CONFIG_ESP32_BROWNOUT_DET_LVL=0 +CONFIG_ESP32_REDUCE_PHY_TX_POWER=y +CONFIG_ESP32_TIME_SYSCALL_USE_RTC_FRC1=y +# CONFIG_ESP32_TIME_SYSCALL_USE_RTC is not set +# CONFIG_ESP32_TIME_SYSCALL_USE_FRC1 is not set +# CONFIG_ESP32_TIME_SYSCALL_USE_NONE is not set +CONFIG_ESP32_RTC_CLK_SRC_INT_RC=y +# CONFIG_ESP32_RTC_CLK_SRC_EXT_CRYS is not set +# CONFIG_ESP32_RTC_CLK_SRC_EXT_OSC is not set +# CONFIG_ESP32_RTC_CLK_SRC_INT_8MD256 is not set +CONFIG_ESP32_RTC_CLK_CAL_CYCLES=1024 +CONFIG_ESP32_DEEP_SLEEP_WAKEUP_DELAY=2000 +CONFIG_ESP32_XTAL_FREQ_40=y +# CONFIG_ESP32_XTAL_FREQ_26 is not set +# CONFIG_ESP32_XTAL_FREQ_AUTO is not set +CONFIG_ESP32_XTAL_FREQ=40 +# CONFIG_ESP32_DISABLE_BASIC_ROM_CONSOLE is not set +# CONFIG_ESP32_NO_BLOBS is not set +# CONFIG_ESP32_COMPATIBLE_PRE_V2_1_BOOTLOADERS is not set +# CONFIG_ESP32_USE_FIXED_STATIC_RAM_SIZE is not set +CONFIG_ESP32_DPORT_DIS_INTERRUPT_LVL=5 +# end of ESP32-specific + +# +# Power Management +# +# CONFIG_PM_ENABLE is not set +# end of Power Management + +# +# ADC-Calibration +# +CONFIG_ADC_CAL_EFUSE_TP_ENABLE=y +CONFIG_ADC_CAL_EFUSE_VREF_ENABLE=y +CONFIG_ADC_CAL_LUT_ENABLE=y +# end of ADC-Calibration + +# +# Common ESP-related +# +CONFIG_ESP_ERR_TO_NAME_LOOKUP=y +CONFIG_ESP_SYSTEM_EVENT_QUEUE_SIZE=32 +CONFIG_ESP_SYSTEM_EVENT_TASK_STACK_SIZE=2304 +CONFIG_ESP_MAIN_TASK_STACK_SIZE=6584 +CONFIG_ESP_IPC_TASK_STACK_SIZE=1024 +CONFIG_ESP_IPC_USES_CALLERS_PRIORITY=y +CONFIG_ESP_MINIMAL_SHARED_STACK_SIZE=2048 +CONFIG_ESP_CONSOLE_UART_DEFAULT=y +# CONFIG_ESP_CONSOLE_UART_CUSTOM is not set +# CONFIG_ESP_CONSOLE_UART_NONE is not set +CONFIG_ESP_CONSOLE_UART_NUM=0 +CONFIG_ESP_CONSOLE_UART_TX_GPIO=1 +CONFIG_ESP_CONSOLE_UART_RX_GPIO=3 +CONFIG_ESP_CONSOLE_UART_BAUDRATE=115200 +CONFIG_ESP_INT_WDT=y +CONFIG_ESP_INT_WDT_TIMEOUT_MS=300 +CONFIG_ESP_INT_WDT_CHECK_CPU1=y +CONFIG_ESP_TASK_WDT=y +# CONFIG_ESP_TASK_WDT_PANIC is not set +CONFIG_ESP_TASK_WDT_TIMEOUT_S=5 +CONFIG_ESP_TASK_WDT_CHECK_IDLE_TASK_CPU0=y +CONFIG_ESP_TASK_WDT_CHECK_IDLE_TASK_CPU1=y +# CONFIG_ESP_PANIC_HANDLER_IRAM is not set +CONFIG_ESP_MAC_ADDR_UNIVERSE_WIFI_STA=y +CONFIG_ESP_MAC_ADDR_UNIVERSE_WIFI_AP=y +CONFIG_ESP_MAC_ADDR_UNIVERSE_BT=y +CONFIG_ESP_MAC_ADDR_UNIVERSE_ETH=y +# end of Common ESP-related + +# +# Ethernet +# +CONFIG_ETH_ENABLED=y +CONFIG_ETH_USE_ESP32_EMAC=y +CONFIG_ETH_PHY_INTERFACE_RMII=y +# CONFIG_ETH_PHY_INTERFACE_MII is not set +CONFIG_ETH_RMII_CLK_INPUT=y +# CONFIG_ETH_RMII_CLK_OUTPUT is not set +CONFIG_ETH_RMII_CLK_IN_GPIO=0 +CONFIG_ETH_DMA_BUFFER_SIZE=512 +CONFIG_ETH_DMA_RX_BUFFER_NUM=10 +CONFIG_ETH_DMA_TX_BUFFER_NUM=10 +CONFIG_ETH_USE_SPI_ETHERNET=y +# CONFIG_ETH_SPI_ETHERNET_DM9051 is not set +# CONFIG_ETH_USE_OPENETH is not set +# end of Ethernet + +# +# Event Loop Library +# +# CONFIG_ESP_EVENT_LOOP_PROFILING is not set +CONFIG_ESP_EVENT_POST_FROM_ISR=y +CONFIG_ESP_EVENT_POST_FROM_IRAM_ISR=y +# end of Event Loop Library + +# +# GDB Stub +# +# end of GDB Stub + +# +# ESP HTTP client +# +CONFIG_ESP_HTTP_CLIENT_ENABLE_HTTPS=y +# CONFIG_ESP_HTTP_CLIENT_ENABLE_BASIC_AUTH is not set +# end of ESP HTTP client + +# +# HTTP Server +# +CONFIG_HTTPD_MAX_REQ_HDR_LEN=512 +CONFIG_HTTPD_MAX_URI_LEN=512 +CONFIG_HTTPD_ERR_RESP_NO_DELAY=y +CONFIG_HTTPD_PURGE_BUF_LEN=32 +# CONFIG_HTTPD_LOG_PURGE_DATA is not set +# CONFIG_HTTPD_WS_SUPPORT is not set +# end of HTTP Server + +# +# ESP HTTPS OTA +# +# CONFIG_OTA_ALLOW_HTTP is not set +# end of ESP HTTPS OTA + +# +# ESP HTTPS server +# +# CONFIG_ESP_HTTPS_SERVER_ENABLE is not set +# end of ESP HTTPS server + +# +# ESP NETIF Adapter +# +CONFIG_ESP_NETIF_IP_LOST_TIMER_INTERVAL=120 +CONFIG_ESP_NETIF_TCPIP_LWIP=y +# CONFIG_ESP_NETIF_LOOPBACK is not set +CONFIG_ESP_NETIF_TCPIP_ADAPTER_COMPATIBLE_LAYER=y +# end of ESP NETIF Adapter + +# +# ESP System Settings +# +# CONFIG_ESP_SYSTEM_PANIC_PRINT_HALT is not set +CONFIG_ESP_SYSTEM_PANIC_PRINT_REBOOT=y +# CONFIG_ESP_SYSTEM_PANIC_SILENT_REBOOT is not set +# CONFIG_ESP_SYSTEM_PANIC_GDBSTUB is not set +# end of ESP System Settings + +# +# High resolution timer (esp_timer) +# +# CONFIG_ESP_TIMER_PROFILING is not set +CONFIG_ESP_TIMER_TASK_STACK_SIZE=6584 +# CONFIG_ESP_TIMER_IMPL_FRC2 is not set +CONFIG_ESP_TIMER_IMPL_TG0_LAC=y +# end of High resolution timer (esp_timer) + +# +# Wi-Fi +# +CONFIG_ESP32_WIFI_STATIC_RX_BUFFER_NUM=10 +CONFIG_ESP32_WIFI_DYNAMIC_RX_BUFFER_NUM=32 +# CONFIG_ESP32_WIFI_STATIC_TX_BUFFER is not set +CONFIG_ESP32_WIFI_DYNAMIC_TX_BUFFER=y +CONFIG_ESP32_WIFI_TX_BUFFER_TYPE=1 +CONFIG_ESP32_WIFI_DYNAMIC_TX_BUFFER_NUM=32 +# CONFIG_ESP32_WIFI_CSI_ENABLED is not set +CONFIG_ESP32_WIFI_AMPDU_TX_ENABLED=y +CONFIG_ESP32_WIFI_TX_BA_WIN=6 +CONFIG_ESP32_WIFI_AMPDU_RX_ENABLED=y +CONFIG_ESP32_WIFI_RX_BA_WIN=6 +CONFIG_ESP32_WIFI_NVS_ENABLED=y +CONFIG_ESP32_WIFI_TASK_PINNED_TO_CORE_0=y +# CONFIG_ESP32_WIFI_TASK_PINNED_TO_CORE_1 is not set +CONFIG_ESP32_WIFI_SOFTAP_BEACON_MAX_LEN=752 +CONFIG_ESP32_WIFI_MGMT_SBUF_NUM=32 +# CONFIG_ESP32_WIFI_DEBUG_LOG_ENABLE is not set +CONFIG_ESP32_WIFI_IRAM_OPT=y +CONFIG_ESP32_WIFI_RX_IRAM_OPT=y +CONFIG_ESP32_WIFI_ENABLE_WPA3_SAE=y +# end of Wi-Fi + +# +# PHY +# +CONFIG_ESP32_PHY_CALIBRATION_AND_DATA_STORAGE=y +# CONFIG_ESP32_PHY_INIT_DATA_IN_PARTITION is not set +CONFIG_ESP32_PHY_MAX_WIFI_TX_POWER=20 +CONFIG_ESP32_PHY_MAX_TX_POWER=20 +# end of PHY + +# +# Core dump +# +# CONFIG_ESP32_ENABLE_COREDUMP_TO_FLASH is not set +# CONFIG_ESP32_ENABLE_COREDUMP_TO_UART is not set +CONFIG_ESP32_ENABLE_COREDUMP_TO_NONE=y +# end of Core dump + +# +# FAT Filesystem support +# +# CONFIG_FATFS_CODEPAGE_DYNAMIC is not set +CONFIG_FATFS_CODEPAGE_437=y +# CONFIG_FATFS_CODEPAGE_720 is not set +# CONFIG_FATFS_CODEPAGE_737 is not set +# CONFIG_FATFS_CODEPAGE_771 is not set +# CONFIG_FATFS_CODEPAGE_775 is not set +# CONFIG_FATFS_CODEPAGE_850 is not set +# CONFIG_FATFS_CODEPAGE_852 is not set +# CONFIG_FATFS_CODEPAGE_855 is not set +# CONFIG_FATFS_CODEPAGE_857 is not set +# CONFIG_FATFS_CODEPAGE_860 is not set +# CONFIG_FATFS_CODEPAGE_861 is not set +# CONFIG_FATFS_CODEPAGE_862 is not set +# CONFIG_FATFS_CODEPAGE_863 is not set +# CONFIG_FATFS_CODEPAGE_864 is not set +# CONFIG_FATFS_CODEPAGE_865 is not set +# CONFIG_FATFS_CODEPAGE_866 is not set +# CONFIG_FATFS_CODEPAGE_869 is not set +# CONFIG_FATFS_CODEPAGE_932 is not set +# CONFIG_FATFS_CODEPAGE_936 is not set +# CONFIG_FATFS_CODEPAGE_949 is not set +# CONFIG_FATFS_CODEPAGE_950 is not set +CONFIG_FATFS_CODEPAGE=437 +CONFIG_FATFS_LFN_NONE=y +# CONFIG_FATFS_LFN_HEAP is not set +# CONFIG_FATFS_LFN_STACK is not set +CONFIG_FATFS_FS_LOCK=0 +CONFIG_FATFS_TIMEOUT_MS=10000 +CONFIG_FATFS_PER_FILE_CACHE=y +# end of FAT Filesystem support + +# +# Modbus configuration +# +CONFIG_FMB_COMM_MODE_RTU_EN=y +CONFIG_FMB_COMM_MODE_ASCII_EN=y +CONFIG_FMB_MASTER_TIMEOUT_MS_RESPOND=150 +CONFIG_FMB_MASTER_DELAY_MS_CONVERT=200 +CONFIG_FMB_QUEUE_LENGTH=20 +CONFIG_FMB_SERIAL_TASK_STACK_SIZE=2048 +CONFIG_FMB_SERIAL_BUF_SIZE=256 +CONFIG_FMB_SERIAL_ASCII_BITS_PER_SYMB=8 +CONFIG_FMB_SERIAL_ASCII_TIMEOUT_RESPOND_MS=1000 +CONFIG_FMB_SERIAL_TASK_PRIO=10 +# CONFIG_FMB_CONTROLLER_SLAVE_ID_SUPPORT is not set +CONFIG_FMB_CONTROLLER_NOTIFY_TIMEOUT=20 +CONFIG_FMB_CONTROLLER_NOTIFY_QUEUE_SIZE=20 +CONFIG_FMB_CONTROLLER_STACK_SIZE=4096 +CONFIG_FMB_EVENT_QUEUE_TIMEOUT=20 +CONFIG_FMB_TIMER_PORT_ENABLED=y +CONFIG_FMB_TIMER_GROUP=0 +CONFIG_FMB_TIMER_INDEX=0 +# CONFIG_FMB_TIMER_ISR_IN_IRAM is not set +# end of Modbus configuration + +# +# FreeRTOS +# +# CONFIG_FREERTOS_UNICORE is not set +CONFIG_FREERTOS_NO_AFFINITY=0x7FFFFFFF +CONFIG_FREERTOS_CORETIMER_0=y +# CONFIG_FREERTOS_CORETIMER_1 is not set +CONFIG_FREERTOS_HZ=100 +CONFIG_FREERTOS_ASSERT_ON_UNTESTED_FUNCTION=y +# CONFIG_FREERTOS_CHECK_STACKOVERFLOW_NONE is not set +# CONFIG_FREERTOS_CHECK_STACKOVERFLOW_PTRVAL is not set +CONFIG_FREERTOS_CHECK_STACKOVERFLOW_CANARY=y +# CONFIG_FREERTOS_WATCHPOINT_END_OF_STACK is not set +CONFIG_FREERTOS_INTERRUPT_BACKTRACE=y +CONFIG_FREERTOS_THREAD_LOCAL_STORAGE_POINTERS=1 +CONFIG_FREERTOS_ASSERT_FAIL_ABORT=y +# CONFIG_FREERTOS_ASSERT_FAIL_PRINT_CONTINUE is not set +# CONFIG_FREERTOS_ASSERT_DISABLE is not set +CONFIG_FREERTOS_IDLE_TASK_STACKSIZE=1536 +CONFIG_FREERTOS_ISR_STACKSIZE=1536 +# CONFIG_FREERTOS_LEGACY_HOOKS is not set +CONFIG_FREERTOS_MAX_TASK_NAME_LEN=16 +# CONFIG_FREERTOS_SUPPORT_STATIC_ALLOCATION is not set +CONFIG_FREERTOS_TIMER_TASK_PRIORITY=1 +CONFIG_FREERTOS_TIMER_TASK_STACK_DEPTH=6048 +CONFIG_FREERTOS_TIMER_QUEUE_LENGTH=10 +CONFIG_FREERTOS_QUEUE_REGISTRY_SIZE=0 +# CONFIG_FREERTOS_USE_TRACE_FACILITY is not set +# CONFIG_FREERTOS_GENERATE_RUN_TIME_STATS is not set +CONFIG_FREERTOS_TASK_FUNCTION_WRAPPER=y +CONFIG_FREERTOS_CHECK_MUTEX_GIVEN_BY_OWNER=y +# CONFIG_FREERTOS_CHECK_PORT_CRITICAL_COMPLIANCE is not set +CONFIG_FREERTOS_DEBUG_OCDAWARE=y +# CONFIG_FREERTOS_FPU_IN_ISR is not set +# end of FreeRTOS + +# +# Heap memory debugging +# +CONFIG_HEAP_POISONING_DISABLED=y +# CONFIG_HEAP_POISONING_LIGHT is not set +# CONFIG_HEAP_POISONING_COMPREHENSIVE is not set +CONFIG_HEAP_TRACING_OFF=y +# CONFIG_HEAP_TRACING_STANDALONE is not set +# CONFIG_HEAP_TRACING_TOHOST is not set +# CONFIG_HEAP_ABORT_WHEN_ALLOCATION_FAILS is not set +# end of Heap memory debugging + +# +# jsmn +# +# CONFIG_JSMN_PARENT_LINKS is not set +# CONFIG_JSMN_STRICT is not set +# end of jsmn + +# +# libsodium +# +# end of libsodium + +# +# Log output +# +# CONFIG_LOG_DEFAULT_LEVEL_NONE is not set +# CONFIG_LOG_DEFAULT_LEVEL_ERROR is not set +# CONFIG_LOG_DEFAULT_LEVEL_WARN is not set +CONFIG_LOG_DEFAULT_LEVEL_INFO=y +# CONFIG_LOG_DEFAULT_LEVEL_DEBUG is not set +# CONFIG_LOG_DEFAULT_LEVEL_VERBOSE is not set +CONFIG_LOG_DEFAULT_LEVEL=3 +CONFIG_LOG_COLORS=y +CONFIG_LOG_TIMESTAMP_SOURCE_RTOS=y +# CONFIG_LOG_TIMESTAMP_SOURCE_SYSTEM is not set +# end of Log output + +# +# LWIP +# +CONFIG_LWIP_LOCAL_HOSTNAME="espressif" +CONFIG_LWIP_DNS_SUPPORT_MDNS_QUERIES=y +# CONFIG_LWIP_L2_TO_L3_COPY is not set +# CONFIG_LWIP_IRAM_OPTIMIZATION is not set +CONFIG_LWIP_TIMERS_ONDEMAND=y +CONFIG_LWIP_MAX_SOCKETS=10 +# CONFIG_LWIP_USE_ONLY_LWIP_SELECT is not set +CONFIG_LWIP_SO_REUSE=y +CONFIG_LWIP_SO_REUSE_RXTOALL=y +# CONFIG_LWIP_SO_RCVBUF is not set +# CONFIG_LWIP_NETBUF_RECVINFO is not set +CONFIG_LWIP_IP_FRAG=y +# CONFIG_LWIP_IP_REASSEMBLY is not set +# CONFIG_LWIP_IP_FORWARD is not set +# CONFIG_LWIP_STATS is not set +# CONFIG_LWIP_ETHARP_TRUST_IP_MAC is not set +CONFIG_LWIP_ESP_GRATUITOUS_ARP=y +CONFIG_LWIP_GARP_TMR_INTERVAL=60 +CONFIG_LWIP_TCPIP_RECVMBOX_SIZE=32 +CONFIG_LWIP_DHCP_DOES_ARP_CHECK=y +# CONFIG_LWIP_DHCP_RESTORE_LAST_IP is not set + +# +# DHCP server +# +CONFIG_LWIP_DHCPS_LEASE_UNIT=60 +CONFIG_LWIP_DHCPS_MAX_STATION_NUM=8 +# end of DHCP server + +# CONFIG_LWIP_AUTOIP is not set +# CONFIG_LWIP_IPV6_AUTOCONFIG is not set +CONFIG_LWIP_NETIF_LOOPBACK=y +CONFIG_LWIP_LOOPBACK_MAX_PBUFS=8 + +# +# TCP +# +CONFIG_LWIP_MAX_ACTIVE_TCP=16 +CONFIG_LWIP_MAX_LISTENING_TCP=16 +CONFIG_LWIP_TCP_MAXRTX=12 +CONFIG_LWIP_TCP_SYNMAXRTX=6 +CONFIG_LWIP_TCP_MSS=1440 +CONFIG_LWIP_TCP_TMR_INTERVAL=250 +CONFIG_LWIP_TCP_MSL=60000 +CONFIG_LWIP_TCP_SND_BUF_DEFAULT=5744 +CONFIG_LWIP_TCP_WND_DEFAULT=5744 +CONFIG_LWIP_TCP_RECVMBOX_SIZE=6 +CONFIG_LWIP_TCP_QUEUE_OOSEQ=y +# CONFIG_LWIP_TCP_SACK_OUT is not set +# CONFIG_LWIP_TCP_KEEP_CONNECTION_WHEN_IP_CHANGES is not set +CONFIG_LWIP_TCP_OVERSIZE_MSS=y +# CONFIG_LWIP_TCP_OVERSIZE_QUARTER_MSS is not set +# CONFIG_LWIP_TCP_OVERSIZE_DISABLE is not set +# end of TCP + +# +# UDP +# +CONFIG_LWIP_MAX_UDP_PCBS=16 +CONFIG_LWIP_UDP_RECVMBOX_SIZE=6 +# end of UDP + +CONFIG_LWIP_TCPIP_TASK_STACK_SIZE=3072 +CONFIG_LWIP_TCPIP_TASK_AFFINITY_NO_AFFINITY=y +# CONFIG_LWIP_TCPIP_TASK_AFFINITY_CPU0 is not set +# CONFIG_LWIP_TCPIP_TASK_AFFINITY_CPU1 is not set +CONFIG_LWIP_TCPIP_TASK_AFFINITY=0x7FFFFFFF +# CONFIG_LWIP_PPP_SUPPORT is not set + +# +# ICMP +# +# CONFIG_LWIP_MULTICAST_PING is not set +# CONFIG_LWIP_BROADCAST_PING is not set +# end of ICMP + +# +# LWIP RAW API +# +CONFIG_LWIP_MAX_RAW_PCBS=16 +# end of LWIP RAW API + +# +# SNTP +# +CONFIG_LWIP_DHCP_MAX_NTP_SERVERS=1 +CONFIG_LWIP_SNTP_UPDATE_DELAY=3600000 +# end of SNTP + +CONFIG_LWIP_ESP_LWIP_ASSERT=y +# end of LWIP + +# +# mbedTLS +# +CONFIG_MBEDTLS_INTERNAL_MEM_ALLOC=y +# CONFIG_MBEDTLS_DEFAULT_MEM_ALLOC is not set +# CONFIG_MBEDTLS_CUSTOM_MEM_ALLOC is not set +CONFIG_MBEDTLS_ASYMMETRIC_CONTENT_LEN=y +CONFIG_MBEDTLS_SSL_IN_CONTENT_LEN=16384 +CONFIG_MBEDTLS_SSL_OUT_CONTENT_LEN=4096 +# CONFIG_MBEDTLS_DYNAMIC_BUFFER is not set +# CONFIG_MBEDTLS_DEBUG is not set + +# +# Certificate Bundle +# +CONFIG_MBEDTLS_CERTIFICATE_BUNDLE=y +CONFIG_MBEDTLS_CERTIFICATE_BUNDLE_DEFAULT_FULL=y +# CONFIG_MBEDTLS_CERTIFICATE_BUNDLE_DEFAULT_CMN is not set +# CONFIG_MBEDTLS_CERTIFICATE_BUNDLE_DEFAULT_NONE is not set +# CONFIG_MBEDTLS_CUSTOM_CERTIFICATE_BUNDLE is not set +# end of Certificate Bundle + +# CONFIG_MBEDTLS_ECP_RESTARTABLE is not set +# CONFIG_MBEDTLS_CMAC_C is not set +CONFIG_MBEDTLS_HARDWARE_AES=y +CONFIG_MBEDTLS_HARDWARE_MPI=y +CONFIG_MBEDTLS_HARDWARE_SHA=y +# CONFIG_MBEDTLS_ATCA_HW_ECDSA_SIGN is not set +# CONFIG_MBEDTLS_ATCA_HW_ECDSA_VERIFY is not set +CONFIG_MBEDTLS_HAVE_TIME=y +# CONFIG_MBEDTLS_HAVE_TIME_DATE is not set +CONFIG_MBEDTLS_ECDSA_DETERMINISTIC=y +CONFIG_MBEDTLS_SHA512_C=y +CONFIG_MBEDTLS_TLS_SERVER_AND_CLIENT=y +# CONFIG_MBEDTLS_TLS_SERVER_ONLY is not set +# CONFIG_MBEDTLS_TLS_CLIENT_ONLY is not set +# CONFIG_MBEDTLS_TLS_DISABLED is not set +CONFIG_MBEDTLS_TLS_SERVER=y +CONFIG_MBEDTLS_TLS_CLIENT=y +CONFIG_MBEDTLS_TLS_ENABLED=y + +# +# TLS Key Exchange Methods +# +# CONFIG_MBEDTLS_PSK_MODES is not set +CONFIG_MBEDTLS_KEY_EXCHANGE_RSA=y +CONFIG_MBEDTLS_KEY_EXCHANGE_DHE_RSA=y +CONFIG_MBEDTLS_KEY_EXCHANGE_ELLIPTIC_CURVE=y +CONFIG_MBEDTLS_KEY_EXCHANGE_ECDHE_RSA=y +CONFIG_MBEDTLS_KEY_EXCHANGE_ECDHE_ECDSA=y +CONFIG_MBEDTLS_KEY_EXCHANGE_ECDH_ECDSA=y +CONFIG_MBEDTLS_KEY_EXCHANGE_ECDH_RSA=y +# end of TLS Key Exchange Methods + +CONFIG_MBEDTLS_SSL_RENEGOTIATION=y +# CONFIG_MBEDTLS_SSL_PROTO_SSL3 is not set +CONFIG_MBEDTLS_SSL_PROTO_TLS1=y +CONFIG_MBEDTLS_SSL_PROTO_TLS1_1=y +CONFIG_MBEDTLS_SSL_PROTO_TLS1_2=y +# CONFIG_MBEDTLS_SSL_PROTO_DTLS is not set +CONFIG_MBEDTLS_SSL_ALPN=y +CONFIG_MBEDTLS_CLIENT_SSL_SESSION_TICKETS=y +CONFIG_MBEDTLS_SERVER_SSL_SESSION_TICKETS=y + +# +# Symmetric Ciphers +# +CONFIG_MBEDTLS_AES_C=y +# CONFIG_MBEDTLS_CAMELLIA_C is not set +# CONFIG_MBEDTLS_DES_C is not set +CONFIG_MBEDTLS_RC4_DISABLED=y +# CONFIG_MBEDTLS_RC4_ENABLED_NO_DEFAULT is not set +# CONFIG_MBEDTLS_RC4_ENABLED is not set +# CONFIG_MBEDTLS_BLOWFISH_C is not set +# CONFIG_MBEDTLS_XTEA_C is not set +CONFIG_MBEDTLS_CCM_C=y +CONFIG_MBEDTLS_GCM_C=y +# end of Symmetric Ciphers + +# CONFIG_MBEDTLS_RIPEMD160_C is not set + +# +# Certificates +# +CONFIG_MBEDTLS_PEM_PARSE_C=y +CONFIG_MBEDTLS_PEM_WRITE_C=y +CONFIG_MBEDTLS_X509_CRL_PARSE_C=y +CONFIG_MBEDTLS_X509_CSR_PARSE_C=y +# end of Certificates + +CONFIG_MBEDTLS_ECP_C=y +CONFIG_MBEDTLS_ECDH_C=y +CONFIG_MBEDTLS_ECDSA_C=y +# CONFIG_MBEDTLS_ECJPAKE_C is not set +CONFIG_MBEDTLS_ECP_DP_SECP192R1_ENABLED=y +CONFIG_MBEDTLS_ECP_DP_SECP224R1_ENABLED=y +CONFIG_MBEDTLS_ECP_DP_SECP256R1_ENABLED=y +CONFIG_MBEDTLS_ECP_DP_SECP384R1_ENABLED=y +CONFIG_MBEDTLS_ECP_DP_SECP521R1_ENABLED=y +CONFIG_MBEDTLS_ECP_DP_SECP192K1_ENABLED=y +CONFIG_MBEDTLS_ECP_DP_SECP224K1_ENABLED=y +CONFIG_MBEDTLS_ECP_DP_SECP256K1_ENABLED=y +CONFIG_MBEDTLS_ECP_DP_BP256R1_ENABLED=y +CONFIG_MBEDTLS_ECP_DP_BP384R1_ENABLED=y +CONFIG_MBEDTLS_ECP_DP_BP512R1_ENABLED=y +CONFIG_MBEDTLS_ECP_DP_CURVE25519_ENABLED=y +CONFIG_MBEDTLS_ECP_NIST_OPTIM=y +# CONFIG_MBEDTLS_POLY1305_C is not set +# CONFIG_MBEDTLS_CHACHA20_C is not set +# CONFIG_MBEDTLS_HKDF_C is not set +# CONFIG_MBEDTLS_THREADING_C is not set +# CONFIG_MBEDTLS_SECURITY_RISKS is not set +# end of mbedTLS + +# +# mDNS +# +CONFIG_MDNS_MAX_SERVICES=10 +CONFIG_MDNS_TASK_PRIORITY=1 +CONFIG_MDNS_TASK_STACK_SIZE=4096 +# CONFIG_MDNS_TASK_AFFINITY_NO_AFFINITY is not set +CONFIG_MDNS_TASK_AFFINITY_CPU0=y +# CONFIG_MDNS_TASK_AFFINITY_CPU1 is not set +CONFIG_MDNS_TASK_AFFINITY=0x0 +CONFIG_MDNS_SERVICE_ADD_TIMEOUT_MS=2000 +CONFIG_MDNS_TIMER_PERIOD_MS=100 +# end of mDNS + +# +# ESP-MQTT Configurations +# +CONFIG_MQTT_PROTOCOL_311=y +CONFIG_MQTT_TRANSPORT_SSL=y +CONFIG_MQTT_TRANSPORT_WEBSOCKET=y +CONFIG_MQTT_TRANSPORT_WEBSOCKET_SECURE=y +# CONFIG_MQTT_USE_CUSTOM_CONFIG is not set +# CONFIG_MQTT_TASK_CORE_SELECTION_ENABLED is not set +# CONFIG_MQTT_CUSTOM_OUTBOX is not set +# end of ESP-MQTT Configurations + +# +# Newlib +# +CONFIG_NEWLIB_STDOUT_LINE_ENDING_CRLF=y +# CONFIG_NEWLIB_STDOUT_LINE_ENDING_LF is not set +# CONFIG_NEWLIB_STDOUT_LINE_ENDING_CR is not set +# CONFIG_NEWLIB_STDIN_LINE_ENDING_CRLF is not set +# CONFIG_NEWLIB_STDIN_LINE_ENDING_LF is not set +CONFIG_NEWLIB_STDIN_LINE_ENDING_CR=y +# CONFIG_NEWLIB_NANO_FORMAT is not set +# end of Newlib + +# +# NVS +# +# end of NVS + +# +# OpenSSL +# +# CONFIG_OPENSSL_DEBUG is not set +# CONFIG_OPENSSL_ASSERT_DO_NOTHING is not set +CONFIG_OPENSSL_ASSERT_EXIT=y +# end of OpenSSL + +# +# PThreads +# +CONFIG_PTHREAD_TASK_PRIO_DEFAULT=5 +CONFIG_PTHREAD_TASK_STACK_SIZE_DEFAULT=3072 +CONFIG_PTHREAD_STACK_MIN=768 +CONFIG_PTHREAD_DEFAULT_CORE_NO_AFFINITY=y +# CONFIG_PTHREAD_DEFAULT_CORE_0 is not set +# CONFIG_PTHREAD_DEFAULT_CORE_1 is not set +CONFIG_PTHREAD_TASK_CORE_DEFAULT=-1 +CONFIG_PTHREAD_TASK_NAME_DEFAULT="pthread" +# end of PThreads + +# +# SPI Flash driver +# +# CONFIG_SPI_FLASH_VERIFY_WRITE is not set +# CONFIG_SPI_FLASH_ENABLE_COUNTERS is not set +CONFIG_SPI_FLASH_ROM_DRIVER_PATCH=y +CONFIG_SPI_FLASH_DANGEROUS_WRITE_ABORTS=y +# CONFIG_SPI_FLASH_DANGEROUS_WRITE_FAILS is not set +# CONFIG_SPI_FLASH_DANGEROUS_WRITE_ALLOWED is not set +# CONFIG_SPI_FLASH_USE_LEGACY_IMPL is not set +# CONFIG_SPI_FLASH_SHARE_SPI1_BUS is not set +# CONFIG_SPI_FLASH_BYPASS_BLOCK_ERASE is not set +CONFIG_SPI_FLASH_YIELD_DURING_ERASE=y +CONFIG_SPI_FLASH_ERASE_YIELD_DURATION_MS=20 +CONFIG_SPI_FLASH_ERASE_YIELD_TICKS=1 + +# +# Auto-detect flash chips +# +CONFIG_SPI_FLASH_SUPPORT_ISSI_CHIP=y +CONFIG_SPI_FLASH_SUPPORT_MXIC_CHIP=y +CONFIG_SPI_FLASH_SUPPORT_GD_CHIP=y +# end of Auto-detect flash chips +# end of SPI Flash driver + +# +# SPIFFS Configuration +# +CONFIG_SPIFFS_MAX_PARTITIONS=3 + +# +# SPIFFS Cache Configuration +# +CONFIG_SPIFFS_CACHE=y +CONFIG_SPIFFS_CACHE_WR=y +# CONFIG_SPIFFS_CACHE_STATS is not set +# end of SPIFFS Cache Configuration + +CONFIG_SPIFFS_PAGE_CHECK=y +CONFIG_SPIFFS_GC_MAX_RUNS=10 +# CONFIG_SPIFFS_GC_STATS is not set +CONFIG_SPIFFS_PAGE_SIZE=256 +CONFIG_SPIFFS_OBJ_NAME_LEN=32 +# CONFIG_SPIFFS_FOLLOW_SYMLINKS is not set +CONFIG_SPIFFS_USE_MAGIC=y +CONFIG_SPIFFS_USE_MAGIC_LENGTH=y +CONFIG_SPIFFS_META_LENGTH=4 +CONFIG_SPIFFS_USE_MTIME=y + +# +# Debug Configuration +# +# CONFIG_SPIFFS_DBG is not set +# CONFIG_SPIFFS_API_DBG is not set +# CONFIG_SPIFFS_GC_DBG is not set +# CONFIG_SPIFFS_CACHE_DBG is not set +# CONFIG_SPIFFS_CHECK_DBG is not set +# CONFIG_SPIFFS_TEST_VISUALISATION is not set +# end of Debug Configuration +# end of SPIFFS Configuration + +# +# TinyUSB +# + +# +# Descriptor configuration +# +CONFIG_USB_DESC_CUSTOM_VID=0x1234 +CONFIG_USB_DESC_CUSTOM_PID=0x5678 +# end of Descriptor configuration +# end of TinyUSB + +# +# Unity unit testing library +# +CONFIG_UNITY_ENABLE_FLOAT=y +CONFIG_UNITY_ENABLE_DOUBLE=y +# CONFIG_UNITY_ENABLE_COLOR is not set +CONFIG_UNITY_ENABLE_IDF_TEST_RUNNER=y +# CONFIG_UNITY_ENABLE_FIXTURE is not set +# CONFIG_UNITY_ENABLE_BACKTRACE_ON_FAIL is not set +# end of Unity unit testing library + +# +# Virtual file system +# +CONFIG_VFS_SUPPORT_IO=y +CONFIG_VFS_SUPPORT_DIR=y +CONFIG_VFS_SUPPORT_SELECT=y +CONFIG_VFS_SUPPRESS_SELECT_DEBUG_OUTPUT=y +CONFIG_VFS_SUPPORT_TERMIOS=y + +# +# Host File System I/O (Semihosting) +# +CONFIG_VFS_SEMIHOSTFS_MAX_MOUNT_POINTS=1 +CONFIG_VFS_SEMIHOSTFS_HOST_PATH_MAX_LEN=128 +# end of Host File System I/O (Semihosting) +# end of Virtual file system + +# +# Wear Levelling +# +# CONFIG_WL_SECTOR_SIZE_512 is not set +CONFIG_WL_SECTOR_SIZE_4096=y +CONFIG_WL_SECTOR_SIZE=4096 +# end of Wear Levelling + +# +# Wi-Fi Provisioning Manager +# +CONFIG_WIFI_PROV_SCAN_MAX_ENTRIES=16 +CONFIG_WIFI_PROV_AUTOSTOP_TIMEOUT=30 +# end of Wi-Fi Provisioning Manager + +# +# Supplicant +# +CONFIG_WPA_MBEDTLS_CRYPTO=y +# CONFIG_WPA_DEBUG_PRINT is not set +# CONFIG_WPA_TESTING_OPTIONS is not set +# CONFIG_WPA_TLS_V12 is not set +# CONFIG_WPA_WPS_WARS is not set +# end of Supplicant +# end of Component config + +# +# Compatibility options +# +# CONFIG_LEGACY_INCLUDE_COMMON_HEADERS is not set +# end of Compatibility options + +# Deprecated options for backward compatibility +CONFIG_TOOLPREFIX="xtensa-esp32-elf-" +# CONFIG_LOG_BOOTLOADER_LEVEL_NONE is not set +# CONFIG_LOG_BOOTLOADER_LEVEL_ERROR is not set +# CONFIG_LOG_BOOTLOADER_LEVEL_WARN is not set +CONFIG_LOG_BOOTLOADER_LEVEL_INFO=y +# CONFIG_LOG_BOOTLOADER_LEVEL_DEBUG is not set +# CONFIG_LOG_BOOTLOADER_LEVEL_VERBOSE is not set +CONFIG_LOG_BOOTLOADER_LEVEL=3 +# CONFIG_APP_ROLLBACK_ENABLE is not set +# CONFIG_FLASH_ENCRYPTION_ENABLED is not set +# CONFIG_FLASHMODE_QIO is not set +# CONFIG_FLASHMODE_QOUT is not set +CONFIG_FLASHMODE_DIO=y +# CONFIG_FLASHMODE_DOUT is not set +# CONFIG_MONITOR_BAUD_9600B is not set +# CONFIG_MONITOR_BAUD_57600B is not set +CONFIG_MONITOR_BAUD_115200B=y +# CONFIG_MONITOR_BAUD_230400B is not set +# CONFIG_MONITOR_BAUD_921600B is not set +# CONFIG_MONITOR_BAUD_2MB is not set +# CONFIG_MONITOR_BAUD_OTHER is not set +CONFIG_MONITOR_BAUD_OTHER_VAL=115200 +CONFIG_MONITOR_BAUD=115200 +CONFIG_COMPILER_OPTIMIZATION_LEVEL_DEBUG=y +# CONFIG_COMPILER_OPTIMIZATION_LEVEL_RELEASE is not set +CONFIG_OPTIMIZATION_ASSERTIONS_ENABLED=y +# CONFIG_OPTIMIZATION_ASSERTIONS_SILENT is not set +# CONFIG_OPTIMIZATION_ASSERTIONS_DISABLED is not set +# CONFIG_CXX_EXCEPTIONS is not set +CONFIG_STACK_CHECK_NONE=y +# CONFIG_STACK_CHECK_NORM is not set +# CONFIG_STACK_CHECK_STRONG is not set +# CONFIG_STACK_CHECK_ALL is not set +# CONFIG_WARN_WRITE_STRINGS is not set +# CONFIG_DISABLE_GCC8_WARNINGS is not set +# CONFIG_ESP32_APPTRACE_DEST_TRAX is not set +CONFIG_ESP32_APPTRACE_DEST_NONE=y +CONFIG_ESP32_APPTRACE_LOCK_ENABLE=y +CONFIG_BTDM_CONTROLLER_BLE_MAX_CONN_EFF=0 +CONFIG_BTDM_CONTROLLER_BR_EDR_MAX_ACL_CONN_EFF=0 +CONFIG_BTDM_CONTROLLER_BR_EDR_MAX_SYNC_CONN_EFF=0 +CONFIG_BTDM_CONTROLLER_PINNED_TO_CORE=0 +CONFIG_ADC2_DISABLE_DAC=y +# CONFIG_SPIRAM_SUPPORT is not set +CONFIG_TRACEMEM_RESERVE_DRAM=0x0 +# CONFIG_TWO_UNIVERSAL_MAC_ADDRESS is not set +CONFIG_FOUR_UNIVERSAL_MAC_ADDRESS=y +CONFIG_NUMBER_OF_UNIVERSAL_MAC_ADDRESS=4 +# CONFIG_ULP_COPROC_ENABLED is not set +CONFIG_ULP_COPROC_RESERVE_MEM=0 +CONFIG_BROWNOUT_DET=y +CONFIG_BROWNOUT_DET_LVL_SEL_0=y +# CONFIG_BROWNOUT_DET_LVL_SEL_1 is not set +# CONFIG_BROWNOUT_DET_LVL_SEL_2 is not set +# CONFIG_BROWNOUT_DET_LVL_SEL_3 is not set +# CONFIG_BROWNOUT_DET_LVL_SEL_4 is not set +# CONFIG_BROWNOUT_DET_LVL_SEL_5 is not set +# CONFIG_BROWNOUT_DET_LVL_SEL_6 is not set +# CONFIG_BROWNOUT_DET_LVL_SEL_7 is not set +CONFIG_BROWNOUT_DET_LVL=0 +CONFIG_REDUCE_PHY_TX_POWER=y +CONFIG_ESP32_RTC_CLOCK_SOURCE_INTERNAL_RC=y +# CONFIG_ESP32_RTC_CLOCK_SOURCE_EXTERNAL_CRYSTAL is not set +# CONFIG_ESP32_RTC_CLOCK_SOURCE_EXTERNAL_OSC is not set +# CONFIG_ESP32_RTC_CLOCK_SOURCE_INTERNAL_8MD256 is not set +# CONFIG_DISABLE_BASIC_ROM_CONSOLE is not set +# CONFIG_NO_BLOBS is not set +# CONFIG_COMPATIBLE_PRE_V2_1_BOOTLOADERS is not set +CONFIG_SYSTEM_EVENT_QUEUE_SIZE=32 +CONFIG_SYSTEM_EVENT_TASK_STACK_SIZE=2304 +CONFIG_MAIN_TASK_STACK_SIZE=3584 +CONFIG_IPC_TASK_STACK_SIZE=1024 +CONFIG_CONSOLE_UART_DEFAULT=y +# CONFIG_CONSOLE_UART_CUSTOM is not set +# CONFIG_CONSOLE_UART_NONE is not set +CONFIG_CONSOLE_UART_NUM=0 +CONFIG_CONSOLE_UART_TX_GPIO=1 +CONFIG_CONSOLE_UART_RX_GPIO=3 +CONFIG_CONSOLE_UART_BAUDRATE=115200 +CONFIG_INT_WDT=y +CONFIG_INT_WDT_TIMEOUT_MS=300 +CONFIG_INT_WDT_CHECK_CPU1=y +CONFIG_TASK_WDT=y +# CONFIG_TASK_WDT_PANIC is not set +CONFIG_TASK_WDT_TIMEOUT_S=5 +CONFIG_TASK_WDT_CHECK_IDLE_TASK_CPU0=y +CONFIG_TASK_WDT_CHECK_IDLE_TASK_CPU1=y +# CONFIG_EVENT_LOOP_PROFILING is not set +CONFIG_POST_EVENTS_FROM_ISR=y +CONFIG_POST_EVENTS_FROM_IRAM_ISR=y +# CONFIG_ESP32S2_PANIC_PRINT_HALT is not set +CONFIG_ESP32S2_PANIC_PRINT_REBOOT=y +# CONFIG_ESP32S2_PANIC_SILENT_REBOOT is not set +# CONFIG_ESP32S2_PANIC_GDBSTUB is not set +CONFIG_TIMER_TASK_STACK_SIZE=6584 +CONFIG_MB_MASTER_TIMEOUT_MS_RESPOND=150 +CONFIG_MB_MASTER_DELAY_MS_CONVERT=200 +CONFIG_MB_QUEUE_LENGTH=20 +CONFIG_MB_SERIAL_TASK_STACK_SIZE=2048 +CONFIG_MB_SERIAL_BUF_SIZE=256 +CONFIG_MB_SERIAL_TASK_PRIO=10 +# CONFIG_MB_CONTROLLER_SLAVE_ID_SUPPORT is not set +CONFIG_MB_CONTROLLER_NOTIFY_TIMEOUT=20 +CONFIG_MB_CONTROLLER_NOTIFY_QUEUE_SIZE=20 +CONFIG_MB_CONTROLLER_STACK_SIZE=4096 +CONFIG_MB_EVENT_QUEUE_TIMEOUT=20 +CONFIG_MB_TIMER_PORT_ENABLED=y +CONFIG_MB_TIMER_GROUP=0 +CONFIG_MB_TIMER_INDEX=0 +# CONFIG_SUPPORT_STATIC_ALLOCATION is not set +CONFIG_TIMER_TASK_PRIORITY=1 +CONFIG_TIMER_TASK_STACK_DEPTH=6048 +CONFIG_TIMER_QUEUE_LENGTH=10 +# CONFIG_L2_TO_L3_COPY is not set +# CONFIG_USE_ONLY_LWIP_SELECT is not set +CONFIG_ESP_GRATUITOUS_ARP=y +CONFIG_GARP_TMR_INTERVAL=60 +CONFIG_TCPIP_RECVMBOX_SIZE=32 +CONFIG_TCP_MAXRTX=12 +CONFIG_TCP_SYNMAXRTX=6 +CONFIG_TCP_MSS=1440 +CONFIG_TCP_MSL=60000 +CONFIG_TCP_SND_BUF_DEFAULT=5744 +CONFIG_TCP_WND_DEFAULT=5744 +CONFIG_TCP_RECVMBOX_SIZE=6 +CONFIG_TCP_QUEUE_OOSEQ=y +# CONFIG_ESP_TCP_KEEP_CONNECTION_WHEN_IP_CHANGES is not set +CONFIG_TCP_OVERSIZE_MSS=y +# CONFIG_TCP_OVERSIZE_QUARTER_MSS is not set +# CONFIG_TCP_OVERSIZE_DISABLE is not set +CONFIG_UDP_RECVMBOX_SIZE=6 +CONFIG_TCPIP_TASK_STACK_SIZE=3072 +CONFIG_TCPIP_TASK_AFFINITY_NO_AFFINITY=y +# CONFIG_TCPIP_TASK_AFFINITY_CPU0 is not set +# CONFIG_TCPIP_TASK_AFFINITY_CPU1 is not set +CONFIG_TCPIP_TASK_AFFINITY=0x7FFFFFFF +# CONFIG_PPP_SUPPORT is not set +CONFIG_ESP32_PTHREAD_TASK_PRIO_DEFAULT=5 +CONFIG_ESP32_PTHREAD_TASK_STACK_SIZE_DEFAULT=3072 +CONFIG_ESP32_PTHREAD_STACK_MIN=768 +CONFIG_ESP32_DEFAULT_PTHREAD_CORE_NO_AFFINITY=y +# CONFIG_ESP32_DEFAULT_PTHREAD_CORE_0 is not set +# CONFIG_ESP32_DEFAULT_PTHREAD_CORE_1 is not set +CONFIG_ESP32_PTHREAD_TASK_CORE_DEFAULT=-1 +CONFIG_ESP32_PTHREAD_TASK_NAME_DEFAULT="pthread" +CONFIG_SPI_FLASH_WRITING_DANGEROUS_REGIONS_ABORTS=y +# CONFIG_SPI_FLASH_WRITING_DANGEROUS_REGIONS_FAILS is not set +# CONFIG_SPI_FLASH_WRITING_DANGEROUS_REGIONS_ALLOWED is not set +CONFIG_SUPPRESS_SELECT_DEBUG_OUTPUT=y +CONFIG_SUPPORT_TERMIOS=y +CONFIG_SEMIHOSTFS_MAX_MOUNT_POINTS=1 +CONFIG_SEMIHOSTFS_HOST_PATH_MAX_LEN=128 +# End of deprecated options diff -Nru libwebsockets-3.2.1/minimal-examples/embedded/esp32/esp-wrover-kit/sdkconfig.h libwebsockets-4.1.6/minimal-examples/embedded/esp32/esp-wrover-kit/sdkconfig.h --- libwebsockets-3.2.1/minimal-examples/embedded/esp32/esp-wrover-kit/sdkconfig.h 1970-01-01 00:00:00.000000000 +0000 +++ libwebsockets-4.1.6/minimal-examples/embedded/esp32/esp-wrover-kit/sdkconfig.h 2020-12-01 17:40:26.000000000 +0000 @@ -0,0 +1,426 @@ +/* + * Automatically generated file. DO NOT EDIT. + * Espressif IoT Development Framework (ESP-IDF) Configuration Header + */ +#pragma once +#define CONFIG_IDF_CMAKE 1 +#define CONFIG_IDF_TARGET "esp32" +#define CONFIG_IDF_TARGET_ESP32 1 +#define CONFIG_IDF_FIRMWARE_CHIP_ID 0x0000 +#define CONFIG_SDK_TOOLPREFIX "xtensa-esp32-elf-" +#define CONFIG_APP_BUILD_TYPE_APP_2NDBOOT 1 +#define CONFIG_APP_BUILD_GENERATE_BINARIES 1 +#define CONFIG_APP_BUILD_BOOTLOADER 1 +#define CONFIG_APP_BUILD_USE_FLASH_SECTIONS 1 +#define CONFIG_APP_COMPILE_TIME_DATE 1 +#define CONFIG_APP_RETRIEVE_LEN_ELF_SHA 16 +#define CONFIG_BOOTLOADER_COMPILER_OPTIMIZATION_SIZE 1 +#define CONFIG_BOOTLOADER_LOG_LEVEL_INFO 1 +#define CONFIG_BOOTLOADER_LOG_LEVEL 3 +#define CONFIG_BOOTLOADER_VDDSDIO_BOOST_1_9V 1 +#define CONFIG_BOOTLOADER_WDT_ENABLE 1 +#define CONFIG_BOOTLOADER_WDT_TIME_MS 9000 +#define CONFIG_BOOTLOADER_RESERVE_RTC_SIZE 0x0 +#define CONFIG_ESPTOOLPY_BAUD_OTHER_VAL 115200 +#define CONFIG_ESPTOOLPY_FLASHMODE_DIO 1 +#define CONFIG_ESPTOOLPY_FLASHMODE "dio" +#define CONFIG_ESPTOOLPY_FLASHFREQ_40M 1 +#define CONFIG_ESPTOOLPY_FLASHFREQ "40m" +#define CONFIG_ESPTOOLPY_FLASHSIZE_4MB 1 +#define CONFIG_ESPTOOLPY_FLASHSIZE "4MB" +#define CONFIG_ESPTOOLPY_FLASHSIZE_DETECT 1 +#define CONFIG_ESPTOOLPY_BEFORE_RESET 1 +#define CONFIG_ESPTOOLPY_BEFORE "default_reset" +#define CONFIG_ESPTOOLPY_AFTER_RESET 1 +#define CONFIG_ESPTOOLPY_AFTER "hard_reset" +#define CONFIG_ESPTOOLPY_MONITOR_BAUD_115200B 1 +#define CONFIG_ESPTOOLPY_MONITOR_BAUD_OTHER_VAL 115200 +#define CONFIG_ESPTOOLPY_MONITOR_BAUD 115200 +#define CONFIG_PARTITION_TABLE_SINGLE_APP 1 +#define CONFIG_PARTITION_TABLE_CUSTOM_FILENAME "partitions.csv" +#define CONFIG_PARTITION_TABLE_FILENAME "partitions_singleapp.csv" +#define CONFIG_PARTITION_TABLE_OFFSET 0x8000 +#define CONFIG_PARTITION_TABLE_MD5 1 +#define CONFIG_COMPILER_OPTIMIZATION_DEFAULT 1 +#define CONFIG_COMPILER_OPTIMIZATION_ASSERTIONS_ENABLE 1 +#define CONFIG_COMPILER_STACK_CHECK_MODE_NONE 1 +#define CONFIG_APPTRACE_DEST_NONE 1 +#define CONFIG_APPTRACE_LOCK_ENABLE 1 +#define CONFIG_BTDM_CTRL_BR_EDR_SCO_DATA_PATH_EFF 0 +#define CONFIG_BTDM_CTRL_BLE_MAX_CONN_EFF 0 +#define CONFIG_BTDM_CTRL_BR_EDR_MAX_ACL_CONN_EFF 0 +#define CONFIG_BTDM_CTRL_BR_EDR_MAX_SYNC_CONN_EFF 0 +#define CONFIG_BTDM_CTRL_PINNED_TO_CORE 0 +#define CONFIG_BTDM_BLE_SLEEP_CLOCK_ACCURACY_INDEX_EFF 1 +#define CONFIG_BT_RESERVE_DRAM 0x0 +#define CONFIG_COAP_MBEDTLS_PSK 1 +#define CONFIG_COAP_LOG_DEFAULT_LEVEL 0 +#define CONFIG_ADC_DISABLE_DAC 1 +#define CONFIG_SPI_MASTER_ISR_IN_IRAM 1 +#define CONFIG_SPI_SLAVE_ISR_IN_IRAM 1 +#define CONFIG_EFUSE_CODE_SCHEME_COMPAT_3_4 1 +#define CONFIG_EFUSE_MAX_BLK_LEN 192 +#define CONFIG_ESP_TLS_USING_MBEDTLS 1 +#define CONFIG_ESP32_REV_MIN_0 1 +#define CONFIG_ESP32_REV_MIN 0 +#define CONFIG_ESP32_DPORT_WORKAROUND 1 +#define CONFIG_ESP32_DEFAULT_CPU_FREQ_160 1 +#define CONFIG_ESP32_DEFAULT_CPU_FREQ_MHZ 160 +#define CONFIG_ESP32_TRACEMEM_RESERVE_DRAM 0x0 +#define CONFIG_ESP32_UNIVERSAL_MAC_ADDRESSES_FOUR 1 +#define CONFIG_ESP32_UNIVERSAL_MAC_ADDRESSES 4 +#define CONFIG_ESP32_ULP_COPROC_RESERVE_MEM 0 +#define CONFIG_ESP32_DEBUG_OCDAWARE 1 +#define CONFIG_ESP32_BROWNOUT_DET 1 +#define CONFIG_ESP32_BROWNOUT_DET_LVL_SEL_0 1 +#define CONFIG_ESP32_BROWNOUT_DET_LVL 0 +#define CONFIG_ESP32_REDUCE_PHY_TX_POWER 1 +#define CONFIG_ESP32_TIME_SYSCALL_USE_RTC_FRC1 1 +#define CONFIG_ESP32_RTC_CLK_SRC_INT_RC 1 +#define CONFIG_ESP32_RTC_CLK_CAL_CYCLES 1024 +#define CONFIG_ESP32_DEEP_SLEEP_WAKEUP_DELAY 2000 +#define CONFIG_ESP32_XTAL_FREQ_40 1 +#define CONFIG_ESP32_XTAL_FREQ 40 +#define CONFIG_ESP32_DPORT_DIS_INTERRUPT_LVL 5 +#define CONFIG_ADC_CAL_EFUSE_TP_ENABLE 1 +#define CONFIG_ADC_CAL_EFUSE_VREF_ENABLE 1 +#define CONFIG_ADC_CAL_LUT_ENABLE 1 +#define CONFIG_ESP_ERR_TO_NAME_LOOKUP 1 +#define CONFIG_ESP_SYSTEM_EVENT_QUEUE_SIZE 32 +#define CONFIG_ESP_SYSTEM_EVENT_TASK_STACK_SIZE 2304 +#define CONFIG_ESP_MAIN_TASK_STACK_SIZE 6584 +#define CONFIG_ESP_IPC_TASK_STACK_SIZE 1024 +#define CONFIG_ESP_IPC_USES_CALLERS_PRIORITY 1 +#define CONFIG_ESP_MINIMAL_SHARED_STACK_SIZE 2048 +#define CONFIG_ESP_CONSOLE_UART_DEFAULT 1 +#define CONFIG_ESP_CONSOLE_UART_NUM 0 +#define CONFIG_ESP_CONSOLE_UART_TX_GPIO 1 +#define CONFIG_ESP_CONSOLE_UART_RX_GPIO 3 +#define CONFIG_ESP_CONSOLE_UART_BAUDRATE 115200 +#define CONFIG_ESP_INT_WDT 1 +#define CONFIG_ESP_INT_WDT_TIMEOUT_MS 300 +#define CONFIG_ESP_INT_WDT_CHECK_CPU1 1 +#define CONFIG_ESP_TASK_WDT 1 +#define CONFIG_ESP_TASK_WDT_TIMEOUT_S 5 +#define CONFIG_ESP_TASK_WDT_CHECK_IDLE_TASK_CPU0 1 +#define CONFIG_ESP_TASK_WDT_CHECK_IDLE_TASK_CPU1 1 +#define CONFIG_ESP_MAC_ADDR_UNIVERSE_WIFI_STA 1 +#define CONFIG_ESP_MAC_ADDR_UNIVERSE_WIFI_AP 1 +#define CONFIG_ESP_MAC_ADDR_UNIVERSE_BT 1 +#define CONFIG_ESP_MAC_ADDR_UNIVERSE_ETH 1 +#define CONFIG_ETH_ENABLED 1 +#define CONFIG_ETH_USE_ESP32_EMAC 1 +#define CONFIG_ETH_PHY_INTERFACE_RMII 1 +#define CONFIG_ETH_RMII_CLK_INPUT 1 +#define CONFIG_ETH_RMII_CLK_IN_GPIO 0 +#define CONFIG_ETH_DMA_BUFFER_SIZE 512 +#define CONFIG_ETH_DMA_RX_BUFFER_NUM 10 +#define CONFIG_ETH_DMA_TX_BUFFER_NUM 10 +#define CONFIG_ETH_USE_SPI_ETHERNET 1 +#define CONFIG_ESP_EVENT_POST_FROM_ISR 1 +#define CONFIG_ESP_EVENT_POST_FROM_IRAM_ISR 1 +#define CONFIG_ESP_HTTP_CLIENT_ENABLE_HTTPS 1 +#define CONFIG_HTTPD_MAX_REQ_HDR_LEN 512 +#define CONFIG_HTTPD_MAX_URI_LEN 512 +#define CONFIG_HTTPD_ERR_RESP_NO_DELAY 1 +#define CONFIG_HTTPD_PURGE_BUF_LEN 32 +#define CONFIG_ESP_NETIF_IP_LOST_TIMER_INTERVAL 120 +#define CONFIG_ESP_NETIF_TCPIP_LWIP 1 +#define CONFIG_ESP_NETIF_TCPIP_ADAPTER_COMPATIBLE_LAYER 1 +#define CONFIG_ESP_SYSTEM_PANIC_PRINT_REBOOT 1 +#define CONFIG_ESP_TIMER_TASK_STACK_SIZE 6584 +#define CONFIG_ESP_TIMER_IMPL_TG0_LAC 1 +#define CONFIG_ESP32_WIFI_STATIC_RX_BUFFER_NUM 10 +#define CONFIG_ESP32_WIFI_DYNAMIC_RX_BUFFER_NUM 32 +#define CONFIG_ESP32_WIFI_DYNAMIC_TX_BUFFER 1 +#define CONFIG_ESP32_WIFI_TX_BUFFER_TYPE 1 +#define CONFIG_ESP32_WIFI_DYNAMIC_TX_BUFFER_NUM 32 +#define CONFIG_ESP32_WIFI_AMPDU_TX_ENABLED 1 +#define CONFIG_ESP32_WIFI_TX_BA_WIN 6 +#define CONFIG_ESP32_WIFI_AMPDU_RX_ENABLED 1 +#define CONFIG_ESP32_WIFI_RX_BA_WIN 6 +#define CONFIG_ESP32_WIFI_NVS_ENABLED 1 +#define CONFIG_ESP32_WIFI_TASK_PINNED_TO_CORE_0 1 +#define CONFIG_ESP32_WIFI_SOFTAP_BEACON_MAX_LEN 752 +#define CONFIG_ESP32_WIFI_MGMT_SBUF_NUM 32 +#define CONFIG_ESP32_WIFI_IRAM_OPT 1 +#define CONFIG_ESP32_WIFI_RX_IRAM_OPT 1 +#define CONFIG_ESP32_WIFI_ENABLE_WPA3_SAE 1 +#define CONFIG_ESP32_PHY_CALIBRATION_AND_DATA_STORAGE 1 +#define CONFIG_ESP32_PHY_MAX_WIFI_TX_POWER 20 +#define CONFIG_ESP32_PHY_MAX_TX_POWER 20 +#define CONFIG_ESP32_ENABLE_COREDUMP_TO_NONE 1 +#define CONFIG_FATFS_CODEPAGE_437 1 +#define CONFIG_FATFS_CODEPAGE 437 +#define CONFIG_FATFS_LFN_NONE 1 +#define CONFIG_FATFS_FS_LOCK 0 +#define CONFIG_FATFS_TIMEOUT_MS 10000 +#define CONFIG_FATFS_PER_FILE_CACHE 1 +#define CONFIG_FMB_COMM_MODE_RTU_EN 1 +#define CONFIG_FMB_COMM_MODE_ASCII_EN 1 +#define CONFIG_FMB_MASTER_TIMEOUT_MS_RESPOND 150 +#define CONFIG_FMB_MASTER_DELAY_MS_CONVERT 200 +#define CONFIG_FMB_QUEUE_LENGTH 20 +#define CONFIG_FMB_SERIAL_TASK_STACK_SIZE 2048 +#define CONFIG_FMB_SERIAL_BUF_SIZE 256 +#define CONFIG_FMB_SERIAL_ASCII_BITS_PER_SYMB 8 +#define CONFIG_FMB_SERIAL_ASCII_TIMEOUT_RESPOND_MS 1000 +#define CONFIG_FMB_SERIAL_TASK_PRIO 10 +#define CONFIG_FMB_CONTROLLER_NOTIFY_TIMEOUT 20 +#define CONFIG_FMB_CONTROLLER_NOTIFY_QUEUE_SIZE 20 +#define CONFIG_FMB_CONTROLLER_STACK_SIZE 4096 +#define CONFIG_FMB_EVENT_QUEUE_TIMEOUT 20 +#define CONFIG_FMB_TIMER_PORT_ENABLED 1 +#define CONFIG_FMB_TIMER_GROUP 0 +#define CONFIG_FMB_TIMER_INDEX 0 +#define CONFIG_FREERTOS_NO_AFFINITY 0x7FFFFFFF +#define CONFIG_FREERTOS_CORETIMER_0 1 +#define CONFIG_FREERTOS_HZ 100 +#define CONFIG_FREERTOS_ASSERT_ON_UNTESTED_FUNCTION 1 +#define CONFIG_FREERTOS_CHECK_STACKOVERFLOW_CANARY 1 +#define CONFIG_FREERTOS_INTERRUPT_BACKTRACE 1 +#define CONFIG_FREERTOS_THREAD_LOCAL_STORAGE_POINTERS 1 +#define CONFIG_FREERTOS_ASSERT_FAIL_ABORT 1 +#define CONFIG_FREERTOS_IDLE_TASK_STACKSIZE 1536 +#define CONFIG_FREERTOS_ISR_STACKSIZE 1536 +#define CONFIG_FREERTOS_MAX_TASK_NAME_LEN 16 +#define CONFIG_FREERTOS_TIMER_TASK_PRIORITY 1 +#define CONFIG_FREERTOS_TIMER_TASK_STACK_DEPTH 6048 +#define CONFIG_FREERTOS_TIMER_QUEUE_LENGTH 10 +#define CONFIG_FREERTOS_QUEUE_REGISTRY_SIZE 0 +#define CONFIG_FREERTOS_TASK_FUNCTION_WRAPPER 1 +#define CONFIG_FREERTOS_CHECK_MUTEX_GIVEN_BY_OWNER 1 +#define CONFIG_FREERTOS_DEBUG_OCDAWARE 1 +#define CONFIG_HEAP_POISONING_DISABLED 1 +#define CONFIG_HEAP_TRACING_OFF 1 +#define CONFIG_LOG_DEFAULT_LEVEL_INFO 1 +#define CONFIG_LOG_DEFAULT_LEVEL 3 +#define CONFIG_LOG_COLORS 1 +#define CONFIG_LOG_TIMESTAMP_SOURCE_RTOS 1 +#define CONFIG_LWIP_LOCAL_HOSTNAME "espressif" +#define CONFIG_LWIP_DNS_SUPPORT_MDNS_QUERIES 1 +#define CONFIG_LWIP_TIMERS_ONDEMAND 1 +#define CONFIG_LWIP_MAX_SOCKETS 10 +#define CONFIG_LWIP_SO_REUSE 1 +#define CONFIG_LWIP_SO_REUSE_RXTOALL 1 +#define CONFIG_LWIP_IP_FRAG 1 +#define CONFIG_LWIP_ESP_GRATUITOUS_ARP 1 +#define CONFIG_LWIP_GARP_TMR_INTERVAL 60 +#define CONFIG_LWIP_TCPIP_RECVMBOX_SIZE 32 +#define CONFIG_LWIP_DHCP_DOES_ARP_CHECK 1 +#define CONFIG_LWIP_DHCPS_LEASE_UNIT 60 +#define CONFIG_LWIP_DHCPS_MAX_STATION_NUM 8 +#define CONFIG_LWIP_NETIF_LOOPBACK 1 +#define CONFIG_LWIP_LOOPBACK_MAX_PBUFS 8 +#define CONFIG_LWIP_MAX_ACTIVE_TCP 16 +#define CONFIG_LWIP_MAX_LISTENING_TCP 16 +#define CONFIG_LWIP_TCP_MAXRTX 12 +#define CONFIG_LWIP_TCP_SYNMAXRTX 6 +#define CONFIG_LWIP_TCP_MSS 1440 +#define CONFIG_LWIP_TCP_TMR_INTERVAL 250 +#define CONFIG_LWIP_TCP_MSL 60000 +#define CONFIG_LWIP_TCP_SND_BUF_DEFAULT 5744 +#define CONFIG_LWIP_TCP_WND_DEFAULT 5744 +#define CONFIG_LWIP_TCP_RECVMBOX_SIZE 6 +#define CONFIG_LWIP_TCP_QUEUE_OOSEQ 1 +#define CONFIG_LWIP_TCP_OVERSIZE_MSS 1 +#define CONFIG_LWIP_MAX_UDP_PCBS 16 +#define CONFIG_LWIP_UDP_RECVMBOX_SIZE 6 +#define CONFIG_LWIP_TCPIP_TASK_STACK_SIZE 3072 +#define CONFIG_LWIP_TCPIP_TASK_AFFINITY_NO_AFFINITY 1 +#define CONFIG_LWIP_TCPIP_TASK_AFFINITY 0x7FFFFFFF +#define CONFIG_LWIP_MAX_RAW_PCBS 16 +#define CONFIG_LWIP_DHCP_MAX_NTP_SERVERS 1 +#define CONFIG_LWIP_SNTP_UPDATE_DELAY 3600000 +#define CONFIG_LWIP_ESP_LWIP_ASSERT 1 +#define CONFIG_MBEDTLS_INTERNAL_MEM_ALLOC 1 +#define CONFIG_MBEDTLS_ASYMMETRIC_CONTENT_LEN 1 +#define CONFIG_MBEDTLS_SSL_IN_CONTENT_LEN 16384 +#define CONFIG_MBEDTLS_SSL_OUT_CONTENT_LEN 4096 +#define CONFIG_MBEDTLS_CERTIFICATE_BUNDLE 1 +#define CONFIG_MBEDTLS_CERTIFICATE_BUNDLE_DEFAULT_FULL 1 +#define CONFIG_MBEDTLS_HARDWARE_AES 1 +#define CONFIG_MBEDTLS_HARDWARE_MPI 1 +#define CONFIG_MBEDTLS_HARDWARE_SHA 1 +#define CONFIG_MBEDTLS_HAVE_TIME 1 +#define CONFIG_MBEDTLS_TLS_SERVER_AND_CLIENT 1 +#define CONFIG_MBEDTLS_TLS_SERVER 1 +#define CONFIG_MBEDTLS_TLS_CLIENT 1 +#define CONFIG_MBEDTLS_TLS_ENABLED 1 +#define CONFIG_MBEDTLS_PSK_MODES 1 +#define CONFIG_MBEDTLS_KEY_EXCHANGE_PSK 1 +#define CONFIG_MBEDTLS_KEY_EXCHANGE_DHE_PSK 1 +#define CONFIG_MBEDTLS_KEY_EXCHANGE_ECDHE_PSK 1 +#define CONFIG_MBEDTLS_KEY_EXCHANGE_RSA_PSK 1 +#define CONFIG_MBEDTLS_KEY_EXCHANGE_RSA 1 +#define CONFIG_MBEDTLS_KEY_EXCHANGE_DHE_RSA 1 +#define CONFIG_MBEDTLS_KEY_EXCHANGE_ELLIPTIC_CURVE 1 +#define CONFIG_MBEDTLS_KEY_EXCHANGE_ECDHE_RSA 1 +#define CONFIG_MBEDTLS_KEY_EXCHANGE_ECDHE_ECDSA 1 +#define CONFIG_MBEDTLS_KEY_EXCHANGE_ECDH_ECDSA 1 +#define CONFIG_MBEDTLS_KEY_EXCHANGE_ECDH_RSA 1 +#define CONFIG_MBEDTLS_SSL_RENEGOTIATION 1 +#define CONFIG_MBEDTLS_SSL_PROTO_TLS1 1 +#define CONFIG_MBEDTLS_SSL_PROTO_TLS1_1 1 +#define CONFIG_MBEDTLS_SSL_PROTO_TLS1_2 1 +#define CONFIG_MBEDTLS_SSL_PROTO_DTLS 1 +#define CONFIG_MBEDTLS_SSL_ALPN 1 +#define CONFIG_MBEDTLS_CLIENT_SSL_SESSION_TICKETS 1 +#define CONFIG_MBEDTLS_SERVER_SSL_SESSION_TICKETS 1 +#define CONFIG_MBEDTLS_AES_C 1 +#define CONFIG_MBEDTLS_RC4_DISABLED 1 +#define CONFIG_MBEDTLS_CCM_C 1 +#define CONFIG_MBEDTLS_GCM_C 1 +#define CONFIG_MBEDTLS_PEM_PARSE_C 1 +#define CONFIG_MBEDTLS_PEM_WRITE_C 1 +#define CONFIG_MBEDTLS_X509_CRL_PARSE_C 1 +#define CONFIG_MBEDTLS_X509_CSR_PARSE_C 1 +#define CONFIG_MBEDTLS_ECP_C 1 +#define CONFIG_MBEDTLS_ECDH_C 1 +#define CONFIG_MBEDTLS_ECDSA_C 1 +#define CONFIG_MBEDTLS_ECP_DP_SECP192R1_ENABLED 1 +#define CONFIG_MBEDTLS_ECP_DP_SECP224R1_ENABLED 1 +#define CONFIG_MBEDTLS_ECP_DP_SECP256R1_ENABLED 1 +#define CONFIG_MBEDTLS_ECP_DP_SECP384R1_ENABLED 1 +#define CONFIG_MBEDTLS_ECP_DP_SECP521R1_ENABLED 1 +#define CONFIG_MBEDTLS_ECP_DP_SECP192K1_ENABLED 1 +#define CONFIG_MBEDTLS_ECP_DP_SECP224K1_ENABLED 1 +#define CONFIG_MBEDTLS_ECP_DP_SECP256K1_ENABLED 1 +#define CONFIG_MBEDTLS_ECP_DP_BP256R1_ENABLED 1 +#define CONFIG_MBEDTLS_ECP_DP_BP384R1_ENABLED 1 +#define CONFIG_MBEDTLS_ECP_DP_BP512R1_ENABLED 1 +#define CONFIG_MBEDTLS_ECP_DP_CURVE25519_ENABLED 1 +#define CONFIG_MBEDTLS_ECP_NIST_OPTIM 1 +#define CONFIG_MDNS_MAX_SERVICES 10 +#define CONFIG_MDNS_TASK_PRIORITY 1 +#define CONFIG_MDNS_TASK_AFFINITY_CPU0 1 +#define CONFIG_MDNS_TASK_AFFINITY 0x0 +#define CONFIG_MDNS_SERVICE_ADD_TIMEOUT_MS 2000 +#define CONFIG_MDNS_TIMER_PERIOD_MS 100 +#define CONFIG_MQTT_PROTOCOL_311 1 +#define CONFIG_MQTT_TRANSPORT_SSL 1 +#define CONFIG_MQTT_TRANSPORT_WEBSOCKET 1 +#define CONFIG_MQTT_TRANSPORT_WEBSOCKET_SECURE 1 +#define CONFIG_NEWLIB_STDOUT_LINE_ENDING_CRLF 1 +#define CONFIG_NEWLIB_STDIN_LINE_ENDING_CR 1 +#define CONFIG_OPENSSL_ASSERT_EXIT 1 +#define CONFIG_PTHREAD_TASK_PRIO_DEFAULT 5 +#define CONFIG_PTHREAD_TASK_STACK_SIZE_DEFAULT 3072 +#define CONFIG_PTHREAD_STACK_MIN 768 +#define CONFIG_PTHREAD_DEFAULT_CORE_NO_AFFINITY 1 +#define CONFIG_PTHREAD_TASK_CORE_DEFAULT -1 +#define CONFIG_PTHREAD_TASK_NAME_DEFAULT "pthread" +#define CONFIG_SPI_FLASH_ROM_DRIVER_PATCH 1 +#define CONFIG_SPI_FLASH_DANGEROUS_WRITE_ABORTS 1 +#define CONFIG_SPI_FLASH_YIELD_DURING_ERASE 1 +#define CONFIG_SPI_FLASH_ERASE_YIELD_DURATION_MS 20 +#define CONFIG_SPI_FLASH_ERASE_YIELD_TICKS 1 +#define CONFIG_SPI_FLASH_SUPPORT_ISSI_CHIP 1 +#define CONFIG_SPI_FLASH_SUPPORT_MXIC_CHIP 1 +#define CONFIG_SPI_FLASH_SUPPORT_GD_CHIP 1 +#define CONFIG_SPIFFS_MAX_PARTITIONS 3 +#define CONFIG_SPIFFS_CACHE 1 +#define CONFIG_SPIFFS_CACHE_WR 1 +#define CONFIG_SPIFFS_PAGE_CHECK 1 +#define CONFIG_SPIFFS_GC_MAX_RUNS 10 +#define CONFIG_SPIFFS_PAGE_SIZE 256 +#define CONFIG_SPIFFS_OBJ_NAME_LEN 32 +#define CONFIG_SPIFFS_USE_MAGIC 1 +#define CONFIG_SPIFFS_USE_MAGIC_LENGTH 1 +#define CONFIG_SPIFFS_META_LENGTH 4 +#define CONFIG_SPIFFS_USE_MTIME 1 +#define CONFIG_USB_DESC_CUSTOM_VID 0x1234 +#define CONFIG_USB_DESC_CUSTOM_PID 0x5678 +#define CONFIG_UNITY_ENABLE_FLOAT 1 +#define CONFIG_UNITY_ENABLE_DOUBLE 1 +#define CONFIG_UNITY_ENABLE_IDF_TEST_RUNNER 1 +#define CONFIG_VFS_SUPPORT_IO 1 +#define CONFIG_VFS_SUPPORT_DIR 1 +#define CONFIG_VFS_SUPPORT_SELECT 1 +#define CONFIG_VFS_SUPPRESS_SELECT_DEBUG_OUTPUT 1 +#define CONFIG_VFS_SUPPORT_TERMIOS 1 +#define CONFIG_VFS_SEMIHOSTFS_MAX_MOUNT_POINTS 1 +#define CONFIG_VFS_SEMIHOSTFS_HOST_PATH_MAX_LEN 128 +#define CONFIG_WL_SECTOR_SIZE_4096 1 +#define CONFIG_WL_SECTOR_SIZE 4096 +#define CONFIG_WIFI_PROV_SCAN_MAX_ENTRIES 16 +#define CONFIG_WIFI_PROV_AUTOSTOP_TIMEOUT 30 +#define CONFIG_WPA_MBEDTLS_CRYPTO 1 + +/* List of deprecated options */ +#define CONFIG_ADC2_DISABLE_DAC CONFIG_ADC_DISABLE_DAC +#define CONFIG_BROWNOUT_DET CONFIG_ESP32_BROWNOUT_DET +#define CONFIG_BROWNOUT_DET_LVL_SEL_0 CONFIG_ESP32_BROWNOUT_DET_LVL_SEL_0 +#define CONFIG_COMPILER_OPTIMIZATION_LEVEL_DEBUG CONFIG_COMPILER_OPTIMIZATION_DEFAULT +#define CONFIG_CONSOLE_UART_BAUDRATE CONFIG_ESP_CONSOLE_UART_BAUDRATE +#define CONFIG_CONSOLE_UART_DEFAULT CONFIG_ESP_CONSOLE_UART_DEFAULT +#define CONFIG_CONSOLE_UART_RX_GPIO CONFIG_ESP_CONSOLE_UART_RX_GPIO +#define CONFIG_CONSOLE_UART_TX_GPIO CONFIG_ESP_CONSOLE_UART_TX_GPIO +#define CONFIG_ESP32S2_PANIC_PRINT_REBOOT CONFIG_ESP_SYSTEM_PANIC_PRINT_REBOOT +#define CONFIG_ESP32_APPTRACE_DEST_NONE CONFIG_APPTRACE_DEST_NONE +#define CONFIG_ESP32_DEFAULT_PTHREAD_CORE_NO_AFFINITY CONFIG_PTHREAD_DEFAULT_CORE_NO_AFFINITY +#define CONFIG_ESP32_PANIC_PRINT_REBOOT CONFIG_ESP_SYSTEM_PANIC_PRINT_REBOOT +#define CONFIG_ESP32_PTHREAD_STACK_MIN CONFIG_PTHREAD_STACK_MIN +#define CONFIG_ESP32_PTHREAD_TASK_NAME_DEFAULT CONFIG_PTHREAD_TASK_NAME_DEFAULT +#define CONFIG_ESP32_PTHREAD_TASK_PRIO_DEFAULT CONFIG_PTHREAD_TASK_PRIO_DEFAULT +#define CONFIG_ESP32_PTHREAD_TASK_STACK_SIZE_DEFAULT CONFIG_PTHREAD_TASK_STACK_SIZE_DEFAULT +#define CONFIG_ESP32_RTC_CLOCK_SOURCE_INTERNAL_RC CONFIG_ESP32_RTC_CLK_SRC_INT_RC +#define CONFIG_ESP_GRATUITOUS_ARP CONFIG_LWIP_ESP_GRATUITOUS_ARP +#define CONFIG_FLASHMODE_DIO CONFIG_ESPTOOLPY_FLASHMODE_DIO +#define CONFIG_FOUR_UNIVERSAL_MAC_ADDRESS CONFIG_ESP32_UNIVERSAL_MAC_ADDRESSES_FOUR +#define CONFIG_GARP_TMR_INTERVAL CONFIG_LWIP_GARP_TMR_INTERVAL +#define CONFIG_INT_WDT CONFIG_ESP_INT_WDT +#define CONFIG_INT_WDT_CHECK_CPU1 CONFIG_ESP_INT_WDT_CHECK_CPU1 +#define CONFIG_INT_WDT_TIMEOUT_MS CONFIG_ESP_INT_WDT_TIMEOUT_MS +#define CONFIG_IPC_TASK_STACK_SIZE CONFIG_ESP_IPC_TASK_STACK_SIZE +#define CONFIG_LOG_BOOTLOADER_LEVEL_INFO CONFIG_BOOTLOADER_LOG_LEVEL_INFO +#define CONFIG_MAIN_TASK_STACK_SIZE CONFIG_ESP_MAIN_TASK_STACK_SIZE +#define CONFIG_MB_CONTROLLER_NOTIFY_QUEUE_SIZE CONFIG_FMB_CONTROLLER_NOTIFY_QUEUE_SIZE +#define CONFIG_MB_CONTROLLER_NOTIFY_TIMEOUT CONFIG_FMB_CONTROLLER_NOTIFY_TIMEOUT +#define CONFIG_MB_CONTROLLER_STACK_SIZE CONFIG_FMB_CONTROLLER_STACK_SIZE +#define CONFIG_MB_EVENT_QUEUE_TIMEOUT CONFIG_FMB_EVENT_QUEUE_TIMEOUT +#define CONFIG_MB_MASTER_DELAY_MS_CONVERT CONFIG_FMB_MASTER_DELAY_MS_CONVERT +#define CONFIG_MB_MASTER_TIMEOUT_MS_RESPOND CONFIG_FMB_MASTER_TIMEOUT_MS_RESPOND +#define CONFIG_MB_QUEUE_LENGTH CONFIG_FMB_QUEUE_LENGTH +#define CONFIG_MB_SERIAL_BUF_SIZE CONFIG_FMB_SERIAL_BUF_SIZE +#define CONFIG_MB_SERIAL_TASK_PRIO CONFIG_FMB_SERIAL_TASK_PRIO +#define CONFIG_MB_SERIAL_TASK_STACK_SIZE CONFIG_FMB_SERIAL_TASK_STACK_SIZE +#define CONFIG_MB_TIMER_GROUP CONFIG_FMB_TIMER_GROUP +#define CONFIG_MB_TIMER_INDEX CONFIG_FMB_TIMER_INDEX +#define CONFIG_MB_TIMER_PORT_ENABLED CONFIG_FMB_TIMER_PORT_ENABLED +#define CONFIG_MONITOR_BAUD_115200B CONFIG_ESPTOOLPY_MONITOR_BAUD_115200B +#define CONFIG_OPTIMIZATION_ASSERTIONS_ENABLED CONFIG_COMPILER_OPTIMIZATION_ASSERTIONS_ENABLE +#define CONFIG_OPTIMIZATION_LEVEL_DEBUG CONFIG_COMPILER_OPTIMIZATION_DEFAULT +#define CONFIG_POST_EVENTS_FROM_IRAM_ISR CONFIG_ESP_EVENT_POST_FROM_IRAM_ISR +#define CONFIG_POST_EVENTS_FROM_ISR CONFIG_ESP_EVENT_POST_FROM_ISR +#define CONFIG_REDUCE_PHY_TX_POWER CONFIG_ESP32_REDUCE_PHY_TX_POWER +#define CONFIG_SEMIHOSTFS_HOST_PATH_MAX_LEN CONFIG_VFS_SEMIHOSTFS_HOST_PATH_MAX_LEN +#define CONFIG_SEMIHOSTFS_MAX_MOUNT_POINTS CONFIG_VFS_SEMIHOSTFS_MAX_MOUNT_POINTS +#define CONFIG_SPI_FLASH_WRITING_DANGEROUS_REGIONS_ABORTS CONFIG_SPI_FLASH_DANGEROUS_WRITE_ABORTS +#define CONFIG_STACK_CHECK_NONE CONFIG_COMPILER_STACK_CHECK_MODE_NONE +#define CONFIG_SUPPORT_TERMIOS CONFIG_VFS_SUPPORT_TERMIOS +#define CONFIG_SUPPRESS_SELECT_DEBUG_OUTPUT CONFIG_VFS_SUPPRESS_SELECT_DEBUG_OUTPUT +#define CONFIG_SYSTEM_EVENT_QUEUE_SIZE CONFIG_ESP_SYSTEM_EVENT_QUEUE_SIZE +#define CONFIG_SYSTEM_EVENT_TASK_STACK_SIZE CONFIG_ESP_SYSTEM_EVENT_TASK_STACK_SIZE +#define CONFIG_TASK_WDT CONFIG_ESP_TASK_WDT +#define CONFIG_TASK_WDT_CHECK_IDLE_TASK_CPU0 CONFIG_ESP_TASK_WDT_CHECK_IDLE_TASK_CPU0 +#define CONFIG_TASK_WDT_CHECK_IDLE_TASK_CPU1 CONFIG_ESP_TASK_WDT_CHECK_IDLE_TASK_CPU1 +#define CONFIG_TASK_WDT_TIMEOUT_S CONFIG_ESP_TASK_WDT_TIMEOUT_S +#define CONFIG_TCPIP_RECVMBOX_SIZE CONFIG_LWIP_TCPIP_RECVMBOX_SIZE +#define CONFIG_TCPIP_TASK_AFFINITY_NO_AFFINITY CONFIG_LWIP_TCPIP_TASK_AFFINITY_NO_AFFINITY +#define CONFIG_TCPIP_TASK_STACK_SIZE CONFIG_LWIP_TCPIP_TASK_STACK_SIZE +#define CONFIG_TCP_MAXRTX CONFIG_LWIP_TCP_MAXRTX +#define CONFIG_TCP_MSL CONFIG_LWIP_TCP_MSL +#define CONFIG_TCP_MSS CONFIG_LWIP_TCP_MSS +#define CONFIG_TCP_OVERSIZE_MSS CONFIG_LWIP_TCP_OVERSIZE_MSS +#define CONFIG_TCP_QUEUE_OOSEQ CONFIG_LWIP_TCP_QUEUE_OOSEQ +#define CONFIG_TCP_RECVMBOX_SIZE CONFIG_LWIP_TCP_RECVMBOX_SIZE +#define CONFIG_TCP_SND_BUF_DEFAULT CONFIG_LWIP_TCP_SND_BUF_DEFAULT +#define CONFIG_TCP_SYNMAXRTX CONFIG_LWIP_TCP_SYNMAXRTX +#define CONFIG_TCP_WND_DEFAULT CONFIG_LWIP_TCP_WND_DEFAULT +#define CONFIG_TIMER_QUEUE_LENGTH CONFIG_FREERTOS_TIMER_QUEUE_LENGTH +#define CONFIG_TIMER_TASK_PRIORITY CONFIG_FREERTOS_TIMER_TASK_PRIORITY +#define CONFIG_TIMER_TASK_STACK_DEPTH CONFIG_FREERTOS_TIMER_TASK_STACK_DEPTH +#define CONFIG_TIMER_TASK_STACK_SIZE CONFIG_ESP_TIMER_TASK_STACK_SIZE +#define CONFIG_TOOLPREFIX CONFIG_SDK_TOOLPREFIX +#define CONFIG_UDP_RECVMBOX_SIZE CONFIG_LWIP_UDP_RECVMBOX_SIZE diff -Nru libwebsockets-3.2.1/minimal-examples/gtk/minimal-gtk/CMakeLists.txt libwebsockets-4.1.6/minimal-examples/gtk/minimal-gtk/CMakeLists.txt --- libwebsockets-3.2.1/minimal-examples/gtk/minimal-gtk/CMakeLists.txt 1970-01-01 00:00:00.000000000 +0000 +++ libwebsockets-4.1.6/minimal-examples/gtk/minimal-gtk/CMakeLists.txt 2020-12-01 17:40:26.000000000 +0000 @@ -0,0 +1,47 @@ +project(lws-minimal-gtk C) +cmake_minimum_required(VERSION 2.8) +find_package(libwebsockets CONFIG REQUIRED) +list(APPEND CMAKE_MODULE_PATH ${LWS_CMAKE_DIR}) +include(CheckCSourceCompiles) +include(LwsCheckRequirements) + +set(SAMP lws-minimal-gtk) +set(SRCS main.c) + +set(requirements 1) +require_lws_config(LWS_ROLE_H1 1 requirements) +require_lws_config(LWS_WITH_SERVER 1 requirements) +require_lws_config(LWS_WITH_GLIB 1 requirements) +require_lws_config(LWS_WITH_GTK 1 requirements) + +if (requirements) + +# gtk pieces + + include (FindPkgConfig) + + set(LWS_GTK_INCLUDE_DIRS CACHE PATH "Path to the gtk include directory") + set(LWS_GTK_LIBRARIES CACHE PATH "Path to the gtk library") + PKG_SEARCH_MODULE(LWS_GTK2 gtk+-3.0) + if (LWS_GTK2_FOUND) + list(APPEND LWS_GTK_INCLUDE_DIRS "${LWS_GTK2_INCLUDE_DIRS}") + list(APPEND LWS_GTK_LIBRARIES "${LWS_GTK2_LIBRARIES}") + endif() + message("gtk include dir: ${LWS_GTK_INCLUDE_DIRS}") + message("gtk libraries: ${LWS_GTK_LIBRARIES}") + include_directories("${LWS_GTK_INCLUDE_DIRS}") + set(extralibs ${extralibs} ${LWS_GTK_LIBRARIES}) + + + + message("Extra libs: ${extralibs}") + + add_executable(${SAMP} ${SRCS}) + + if (websockets_shared) + target_link_libraries(${SAMP} websockets_shared ${extralibs} ${LIBWEBSOCKETS_DEP_LIBS}) + add_dependencies(${SAMP} websockets_shared) + else() + target_link_libraries(${SAMP} websockets ${extralibs} ${LIBWEBSOCKETS_DEP_LIBS}) + endif() +endif() diff -Nru libwebsockets-3.2.1/minimal-examples/gtk/minimal-gtk/main.c libwebsockets-4.1.6/minimal-examples/gtk/minimal-gtk/main.c --- libwebsockets-3.2.1/minimal-examples/gtk/minimal-gtk/main.c 1970-01-01 00:00:00.000000000 +0000 +++ libwebsockets-4.1.6/minimal-examples/gtk/minimal-gtk/main.c 2020-12-01 17:40:26.000000000 +0000 @@ -0,0 +1,210 @@ +#include +#include + +static int status = 0; + +static void +print_hello(GtkWidget *widget, gpointer data) +{ + g_print("Hello World\n"); +} + +static void +activate(GtkApplication *app, gpointer user_data) +{ + GtkWidget *window; + GtkWidget *button, *bbox; + + window = gtk_application_window_new(app); + gtk_window_set_title(GTK_WINDOW(window), "mywindow"); + gtk_window_set_default_size(GTK_WINDOW(window), 200, 200); + + bbox = gtk_button_box_new(GTK_ORIENTATION_HORIZONTAL); + gtk_container_add(GTK_CONTAINER(window), bbox); + + button = gtk_button_new_with_label("Hello World"); + g_signal_connect(button, "clicked", G_CALLBACK(print_hello), NULL); + g_signal_connect_swapped(button, "clicked", + G_CALLBACK(gtk_widget_destroy), window); + gtk_container_add(GTK_CONTAINER(bbox), button); + + gtk_widget_show_all(window); +} + +static int +system_notify_cb(lws_state_manager_t *mgr, lws_state_notify_link_t *link, + int current, int target) +{ + struct lws_context *context = mgr->parent; + struct lws_client_connect_info i; + + if (current != LWS_SYSTATE_OPERATIONAL || + target != LWS_SYSTATE_OPERATIONAL) + return 0; + + lwsl_notice("%s: operational\n", __func__); + + memset(&i, 0, sizeof i); /* otherwise uninitialized garbage */ + i.context = context; + i.ssl_connection = LCCSCF_USE_SSL | LCCSCF_H2_QUIRK_OVERFLOWS_TXCR | + LCCSCF_H2_QUIRK_NGHTTP2_END_STREAM; + i.port = 443; + i.address = "warmcat.com"; + i.path = "/"; + i.host = i.address; + i.origin = i.address; + i.method = "GET"; + + i.protocol = "http"; + + return !lws_client_connect_via_info(&i); +} + +static int +callback_http(struct lws *wsi, enum lws_callback_reasons reason, + void *user, void *in, size_t len) +{ + switch (reason) { + + /* because we are protocols[0] ... */ + case LWS_CALLBACK_CLIENT_CONNECTION_ERROR: + lwsl_err("CLIENT_CONNECTION_ERROR: %s\n", + in ? (char *)in : "(null)"); + break; + + case LWS_CALLBACK_ESTABLISHED_CLIENT_HTTP: + { + char buf[128]; + + lws_get_peer_simple(wsi, buf, sizeof(buf)); + status = lws_http_client_http_response(wsi); + + lwsl_user("Connected to %s, http response: %d\n", + buf, status); + } + break; + + /* chunks of chunked content, with header removed */ + case LWS_CALLBACK_RECEIVE_CLIENT_HTTP_READ: + lwsl_user("RECEIVE_CLIENT_HTTP_READ: read %d\n", (int)len); + return 0; /* don't passthru */ + + /* uninterpreted http content */ + case LWS_CALLBACK_RECEIVE_CLIENT_HTTP: + { + char buffer[1024 + LWS_PRE]; + char *px = buffer + LWS_PRE; + int lenx = sizeof(buffer) - LWS_PRE; + + if (lws_http_client_read(wsi, &px, &lenx) < 0) + return -1; + } + return 0; /* don't passthru */ + + case LWS_CALLBACK_COMPLETED_CLIENT_HTTP: + lwsl_user("LWS_CALLBACK_COMPLETED_CLIENT_HTTP\n"); + lws_cancel_service(lws_get_context(wsi)); /* abort poll wait */ + break; + + case LWS_CALLBACK_CLOSED_CLIENT_HTTP: + lws_cancel_service(lws_get_context(wsi)); /* abort poll wait */ + break; + + default: + break; + } + + return lws_callback_http_dummy(wsi, reason, user, in, len); +} + +static const struct lws_protocols protocols[] = { + { + "http", + callback_http, + 0, + 0, + }, + { NULL, NULL, 0, 0 } +}; + +static gpointer +t1_main (gpointer user_data) +{ + 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; + struct lws_context *context; + void *foreign_loops[1]; + GMainLoop *ml; + + g_print("%s: started\n", __func__); + + g_main_context_push_thread_default(t1_mc); + + ml = g_main_loop_new(t1_mc, FALSE); + + /* attach our lws activities to the main loop of this thread */ + + lws_set_log_level(LLL_USER | LLL_ERR | LLL_WARN | LLL_NOTICE, NULL); + memset(&info, 0, sizeof info); + info.port = CONTEXT_PORT_NO_LISTEN; + info.options = LWS_SERVER_OPTION_DO_SSL_GLOBAL_INIT | + LWS_SERVER_OPTION_GLIB; + info.protocols = protocols; + foreign_loops[0] = (void *)ml; + info.foreign_loops = foreign_loops; + info.register_notifier_list = na; + +#if defined(LWS_WITH_MBEDTLS) || defined(USE_WOLFSSL) + /* + * OpenSSL uses the system trust store. mbedTLS has to be told which + * CA to trust explicitly. + */ + info.client_ssl_ca_filepath = "./warmcat.com.cer"; +#endif + + context = lws_create_context(&info); + if (!context) { + lwsl_err("lws init failed\n"); + return NULL; + } + + /* + * We created the lws_context and bound it to this thread's main loop, + * let's run the thread's main loop now... + */ + + g_main_loop_run(ml); + g_main_loop_unref(ml); + + g_main_context_pop_thread_default(t1_mc); + g_main_context_unref(t1_mc); + + g_print("%s: ending\n", __func__); + + lws_context_destroy(context); + + return NULL; +} + +int +main(int argc, char **argv) +{ + GMainContext *t1_mc = g_main_context_new(); + GtkApplication *app; + GThread *t1; + int status; + + t1 = g_thread_new ("t1", t1_main, g_main_context_ref (t1_mc)); + (void)t1; + + app = gtk_application_new("org.gtk.example", G_APPLICATION_FLAGS_NONE); + g_signal_connect(app, "activate", G_CALLBACK(activate), NULL); + + status = g_application_run(G_APPLICATION(app), argc, argv); + g_object_unref(app); + + return status; +} + diff -Nru libwebsockets-3.2.1/minimal-examples/gtk/minimal-gtk/README.md libwebsockets-4.1.6/minimal-examples/gtk/minimal-gtk/README.md --- libwebsockets-3.2.1/minimal-examples/gtk/minimal-gtk/README.md 1970-01-01 00:00:00.000000000 +0000 +++ libwebsockets-4.1.6/minimal-examples/gtk/minimal-gtk/README.md 2020-12-01 17:40:26.000000000 +0000 @@ -0,0 +1,32 @@ +# lws minimal http client gtk + +The application goes to https://warmcat.com and receives the page data, +from inside a gtk app using gtk / glib main loop directly. + +## build + +``` + $ cmake . && make +``` + +## usage + + +``` +$ +t1_main: started +[2020/02/08 18:04:07:6647] N: Loading client CA for verification ./warmcat.com.cer +[2020/02/08 18:04:07:7744] U: Connected to 46.105.127.147, http response: 200 +[2020/02/08 18:04:07:7762] U: RECEIVE_CLIENT_HTTP_READ: read 4087 +[2020/02/08 18:04:07:7762] U: RECEIVE_CLIENT_HTTP_READ: read 4096 +[2020/02/08 18:04:07:7928] U: RECEIVE_CLIENT_HTTP_READ: read 4087 +[2020/02/08 18:04:07:7929] U: RECEIVE_CLIENT_HTTP_READ: read 4096 +[2020/02/08 18:04:07:7956] U: RECEIVE_CLIENT_HTTP_READ: read 4087 +[2020/02/08 18:04:07:7956] U: RECEIVE_CLIENT_HTTP_READ: read 4096 +[2020/02/08 18:04:07:7956] U: RECEIVE_CLIENT_HTTP_READ: read 1971 +[2020/02/08 18:04:07:7956] U: LWS_CALLBACK_COMPLETED_CLIENT_HTTP +Hello World +$ +``` + + diff -Nru libwebsockets-3.2.1/minimal-examples/gtk/minimal-gtk/warmcat.com.cer libwebsockets-4.1.6/minimal-examples/gtk/minimal-gtk/warmcat.com.cer --- libwebsockets-3.2.1/minimal-examples/gtk/minimal-gtk/warmcat.com.cer 1970-01-01 00:00:00.000000000 +0000 +++ libwebsockets-4.1.6/minimal-examples/gtk/minimal-gtk/warmcat.com.cer 2020-12-01 17:40:26.000000000 +0000 @@ -0,0 +1,78 @@ +-----BEGIN CERTIFICATE----- +MIIFUDCCBDigAwIBAgISA4mJfIm3iCGbU9+o8YQa+4nUMA0GCSqGSIb3DQEBCwUA +MEoxCzAJBgNVBAYTAlVTMRYwFAYDVQQKEw1MZXQncyBFbmNyeXB0MSMwIQYDVQQD +ExpMZXQncyBFbmNyeXB0IEF1dGhvcml0eSBYMzAeFw0xOTA5MDcwNzA5MjNaFw0x +OTEyMDYwNzA5MjNaMBYxFDASBgNVBAMTC3dhcm1jYXQuY29tMIIBIjANBgkqhkiG +9w0BAQEFAAOCAQ8AMIIBCgKCAQEAwnEoH9JW3GvpadpxHGZPb5wv1Q6KfAIMWtdq +YCOfotFxaYULuzHVxmrTTgmEqJr+eBqUBkXKmGuRR/9UipOmTu5j02qFyWHotFdF +ZGyp//8z+Rle9Qt1nL68oNIZLDtWkybh5x00b1uo4eyEszXUaa0aLqKP3lH7Q4jI +aSVARZ8snrJR640Gp3ByudvNTYkGz469bpWzRC/8wSNtzzY02DvHs1GxQx9tMXw+ +BbtUxeP7lpYFKEFBjgZaIKLv+4g8ItJIuO7gMSzG2JfpQHxdhrlhxpx7dsaMUcyM +nnYXysNL5JG3KEMhkxbtdpCaEQ8jLSPbl/rnF/+mgce+lSjMuQIDAQABo4ICYjCC +Al4wDgYDVR0PAQH/BAQDAgWgMB0GA1UdJQQWMBQGCCsGAQUFBwMBBggrBgEFBQcD +AjAMBgNVHRMBAf8EAjAAMB0GA1UdDgQWBBSI9ai12zLFeNTEDHKI9Ghkqcpa2TAf +BgNVHSMEGDAWgBSoSmpjBH3duubRObemRWXv86jsoTBvBggrBgEFBQcBAQRjMGEw +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e1QLyNau7Fqckh49ZLOMxt+/yUFw +7BZy1SbsOFU5Q9D8/RhcQPGX69Wam40dutolucbY38EVAjqr2m7xPi71XAicPNaD +aeQQmxkqtilX4+U9m5/wAl0CAwEAAaNCMEAwDwYDVR0TAQH/BAUwAwEB/zAOBgNV +HQ8BAf8EBAMCAQYwHQYDVR0OBBYEFMSnsaR7LHH62+FLkHX/xBVghYkQMA0GCSqG +SIb3DQEBBQUAA4IBAQCjGiybFwBcqR7uKGY3Or+Dxz9LwwmglSBd49lZRNI+DT69 +ikugdB/OEIKcdBodfpga3csTS7MgROSR6cz8faXbauX+5v3gTt23ADq1cEmv8uXr +AvHRAosZy5Q6XkjEGB5YGV8eAlrwDPGxrancWYaLbumR9YbK+rlmM6pZW87ipxZz +R8srzJmwN0jP41ZL9c8PDHIyh8bwRLtTcm1D9SZImlJnt1ir/md2cXjbDaJWFBM5 +JDGFoqgCWjBH4d1QB7wCCZAA62RjYJsWvIjJEubSfZGL+T0yjWW06XyxV3bqxbYo +Ob8VZRzI9neWagqNdwvYkQsEjgfbKbYK7p2CNTUQ +-----END CERTIFICATE----- diff -Nru libwebsockets-3.2.1/minimal-examples/http-client/minimal-http-client/CMakeLists.txt libwebsockets-4.1.6/minimal-examples/http-client/minimal-http-client/CMakeLists.txt --- libwebsockets-3.2.1/minimal-examples/http-client/minimal-http-client/CMakeLists.txt 2019-12-18 14:45:31.000000000 +0000 +++ libwebsockets-4.1.6/minimal-examples/http-client/minimal-http-client/CMakeLists.txt 2020-12-01 17:40:26.000000000 +0000 @@ -1,79 +1,36 @@ +project(lws-minimal-http-client C) cmake_minimum_required(VERSION 2.8) +find_package(libwebsockets CONFIG REQUIRED) +list(APPEND CMAKE_MODULE_PATH ${LWS_CMAKE_DIR}) include(CheckCSourceCompiles) +include(LwsCheckRequirements) set(SAMP lws-minimal-http-client) set(SRCS minimal-http-client.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_ROLE_H1 1 requirements) -require_lws_config(LWS_WITHOUT_CLIENT 0 requirements) +require_lws_config(LWS_WITH_CLIENT 1 requirements) +require_lws_config(LWS_WITH_SYS_STATE 1 requirements) if (requirements) add_executable(${SAMP} ${SRCS}) + # if (LWS_CTEST_INTERNET_AVAILABLE) + # add_test(NAME http-client-warmcat COMMAND lws-minimal-http-client --ignore-sigterm) + # add_test(NAME http-client-warmcat-h1 COMMAND lws-minimal-http-client --ignore-sigterm --h1) + # set_tests_properties(http-client-warmcat + # http-client-warmcat-h1 + # PROPERTIES + # WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}/minimal-examples/http-client/minimal-http-client + # TIMEOUT 20) + # + #endif() + if (websockets_shared) - target_link_libraries(${SAMP} websockets_shared) + target_link_libraries(${SAMP} websockets_shared ${LIBWEBSOCKETS_DEP_LIBS}) add_dependencies(${SAMP} websockets_shared) else() - target_link_libraries(${SAMP} websockets) + target_link_libraries(${SAMP} websockets ${LIBWEBSOCKETS_DEP_LIBS}) endif() -endif() \ No newline at end of file +endif() diff -Nru libwebsockets-3.2.1/minimal-examples/http-client/minimal-http-client/minimal-http-client.c libwebsockets-4.1.6/minimal-examples/http-client/minimal-http-client/minimal-http-client.c --- libwebsockets-3.2.1/minimal-examples/http-client/minimal-http-client/minimal-http-client.c 2019-12-18 14:45:31.000000000 +0000 +++ libwebsockets-4.1.6/minimal-examples/http-client/minimal-http-client/minimal-http-client.c 2020-12-01 17:40:26.000000000 +0000 @@ -17,7 +17,16 @@ #include static int interrupted, bad = 1, status; +#if defined(LWS_WITH_HTTP2) +static int long_poll; +#endif static struct lws *client_wsi; +static const char *ba_user, *ba_password; + +static const lws_retry_bo_t retry = { + .secs_since_valid_ping = 3, + .secs_since_valid_hangup = 10, +}; static int callback_http(struct lws *wsi, enum lws_callback_reasons reason, @@ -29,17 +38,60 @@ case LWS_CALLBACK_CLIENT_CONNECTION_ERROR: lwsl_err("CLIENT_CONNECTION_ERROR: %s\n", in ? (char *)in : "(null)"); - client_wsi = NULL; + interrupted = 1; break; case LWS_CALLBACK_ESTABLISHED_CLIENT_HTTP: - status = lws_http_client_http_response(wsi); - lwsl_user("Connected with server response: %d\n", status); + { + char buf[128]; + + lws_get_peer_simple(wsi, buf, sizeof(buf)); + status = lws_http_client_http_response(wsi); + + lwsl_user("Connected to %s, http response: %d\n", + buf, status); + } +#if defined(LWS_WITH_HTTP2) + if (long_poll) { + lwsl_user("%s: Client entering long poll mode\n", __func__); + lws_h2_client_stream_long_poll_rxonly(wsi); + } +#endif + break; + +#if defined(LWS_WITH_HTTP_BASIC_AUTH) + + /* you only need this if you need to do Basic Auth */ + case LWS_CALLBACK_CLIENT_APPEND_HANDSHAKE_HEADER: + { + unsigned char **p = (unsigned char **)in, *end = (*p) + len; + char b[128]; + + if (!ba_user || !ba_password) + break; + + 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, (int)strlen(b), p, end)) + return -1; + break; + } +#endif /* chunks of chunked content, with header removed */ case LWS_CALLBACK_RECEIVE_CLIENT_HTTP_READ: lwsl_user("RECEIVE_CLIENT_HTTP_READ: read %d\n", (int)len); +#if defined(LWS_WITH_HTTP2) + if (long_poll) { + char dotstar[128]; + lws_strnncpy(dotstar, (const char *)in, len, + sizeof(dotstar)); + lwsl_notice("long poll rx: %d '%s'\n", (int)len, + dotstar); + } +#endif #if 0 /* enable to dump the html */ { const char *p = in; @@ -67,13 +119,13 @@ case LWS_CALLBACK_COMPLETED_CLIENT_HTTP: lwsl_user("LWS_CALLBACK_COMPLETED_CLIENT_HTTP\n"); - client_wsi = NULL; + interrupted = 1; bad = status != 200; lws_cancel_service(lws_get_context(wsi)); /* abort poll wait */ break; case LWS_CALLBACK_CLOSED_CLIENT_HTTP: - client_wsi = NULL; + interrupted = 1; bad = status != 200; lws_cancel_service(lws_get_context(wsi)); /* abort poll wait */ break; @@ -101,64 +153,39 @@ interrupted = 1; } -int main(int argc, const char **argv) +struct args { + int argc; + const char **argv; +}; + +static int +system_notify_cb(lws_state_manager_t *mgr, lws_state_notify_link_t *link, + int current, int target) { - struct lws_context_creation_info info; + struct lws_context *context = mgr->parent; struct lws_client_connect_info i; - struct lws_context *context; + struct args *a = lws_context_user(context); const char *p; - int n = 0, logs = LLL_USER | LLL_ERR | LLL_WARN | LLL_NOTICE - /* - * For LLL_ verbosity above NOTICE to be built into lws, - * lws must have been configured and built with - * -DCMAKE_BUILD_TYPE=DEBUG instead of =RELEASE - * - * | LLL_INFO | LLL_PARSER | LLL_HEADER | LLL_EXT | - * LLL_CLIENT | LLL_LATENCY | LLL_DEBUG - */ ; - signal(SIGINT, sigint_handler); + if (current != LWS_SYSTATE_OPERATIONAL || target != LWS_SYSTATE_OPERATIONAL) + return 0; - if ((p = lws_cmdline_option(argc, argv, "-d"))) - logs = atoi(p); - - lws_set_log_level(logs, NULL); - lwsl_user("LWS minimal http client [-d] [-l] [--h1]\n"); - - memset(&info, 0, sizeof info); /* otherwise uninitialized garbage */ - info.options = LWS_SERVER_OPTION_DO_SSL_GLOBAL_INIT; - info.port = CONTEXT_PORT_NO_LISTEN; /* we do not run any server */ - info.protocols = protocols; - - /* - * since we know this lws context is only ever going to be used with - * one client wsis / fds / sockets at a time, let lws know it doesn't - * have to use the default allocations for fd tables up to ulimit -n. - * It will just allocate for 1 internal and 1 (+ 1 http2 nwsi) that we - * will use. - */ - info.fd_limit_per_thread = 1 + 1 + 1; - -#if defined(LWS_WITH_MBEDTLS) - /* - * OpenSSL uses the system trust store. mbedTLS has to be told which - * CA to trust explicitly. - */ - info.client_ssl_ca_filepath = "./warmcat.com.cer"; -#endif - - context = lws_create_context(&info); - if (!context) { - lwsl_err("lws init failed\n"); - return 1; - } + lwsl_info("%s: operational\n", __func__); memset(&i, 0, sizeof i); /* otherwise uninitialized garbage */ i.context = context; - if (!lws_cmdline_option(argc, argv, "-n")) + if (!lws_cmdline_option(a->argc, a->argv, "-n")) { i.ssl_connection = LCCSCF_USE_SSL; +#if defined(LWS_WITH_HTTP2) + /* requires h2 */ + if (lws_cmdline_option(a->argc, a->argv, "--long-poll")) { + lwsl_user("%s: long poll mode\n", __func__); + long_poll = 1; + } +#endif + } - if (lws_cmdline_option(argc, argv, "-l")) { + if (lws_cmdline_option(a->argc, a->argv, "-l")) { i.port = 7681; i.address = "localhost"; i.ssl_connection |= LCCSCF_ALLOW_SELFSIGNED; @@ -167,37 +194,129 @@ i.address = "warmcat.com"; } - if (lws_cmdline_option(argc, argv, "--h1")) + if (lws_cmdline_option(a->argc, a->argv, "--nossl")) + i.ssl_connection = 0; + + i.ssl_connection |= LCCSCF_H2_QUIRK_OVERFLOWS_TXCR | + LCCSCF_H2_QUIRK_NGHTTP2_END_STREAM; + + i.alpn = "h2"; + if (lws_cmdline_option(a->argc, a->argv, "--h1")) i.alpn = "http/1.1"; - if ((p = lws_cmdline_option(argc, argv, "-p"))) + if (lws_cmdline_option(a->argc, a->argv, "--h2-prior-knowledge")) + i.ssl_connection |= LCCSCF_H2_PRIOR_KNOWLEDGE; + + if ((p = lws_cmdline_option(a->argc, a->argv, "-p"))) i.port = atoi(p); - if (lws_cmdline_option(argc, argv, "-j")) + if ((p = lws_cmdline_option(a->argc, a->argv, "--user"))) + ba_user = p; + if ((p = lws_cmdline_option(a->argc, a->argv, "--password"))) + ba_password = p; + + if (lws_cmdline_option(a->argc, a->argv, "-j")) i.ssl_connection |= LCCSCF_ALLOW_SELFSIGNED; - if (lws_cmdline_option(argc, argv, "-k")) + if (lws_cmdline_option(a->argc, a->argv, "-k")) i.ssl_connection |= LCCSCF_ALLOW_INSECURE; - if (lws_cmdline_option(argc, argv, "-m")) + if (lws_cmdline_option(a->argc, a->argv, "-m")) i.ssl_connection |= LCCSCF_SKIP_SERVER_CERT_HOSTNAME_CHECK; - if (lws_cmdline_option(argc, argv, "-e")) + if (lws_cmdline_option(a->argc, a->argv, "-e")) i.ssl_connection |= LCCSCF_ALLOW_EXPIRED; - if ((p = lws_cmdline_option(argc, argv, "--server"))) + if ((p = lws_cmdline_option(a->argc, a->argv, "-f"))) { + i.ssl_connection |= LCCSCF_H2_MANUAL_RXFLOW; + i.manual_initial_tx_credit = atoi(p); + lwsl_notice("%s: manual peer tx credit %d\n", __func__, + i.manual_initial_tx_credit); + } + + /* the default validity check is 5m / 5m10s... -v = 3s / 10s */ + + if (lws_cmdline_option(a->argc, a->argv, "-v")) + i.retry_and_idle_policy = &retry; + + if ((p = lws_cmdline_option(a->argc, a->argv, "--server"))) i.address = p; - i.path = "/"; + if ((p = lws_cmdline_option(a->argc, a->argv, "--path"))) + i.path = p; + else + i.path = "/"; + i.host = i.address; i.origin = i.address; i.method = "GET"; i.protocol = protocols[0].name; i.pwsi = &client_wsi; - lws_client_connect_via_info(&i); - while (n >= 0 && client_wsi && !interrupted) + return !lws_client_connect_via_info(&i); +} + +int main(int argc, const char **argv) +{ + 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; + struct args args; + int n = 0; + // uint8_t memcert[4096]; + + args.argc = argc; + args.argv = argv; + + signal(SIGINT, sigint_handler); + + memset(&info, 0, sizeof info); /* otherwise uninitialized garbage */ + lws_cmdline_option_handle_builtin(argc, argv, &info); + + lwsl_user("LWS minimal http client [-d] [-l] [--h1]\n"); + + info.options = LWS_SERVER_OPTION_DO_SSL_GLOBAL_INIT; + info.port = CONTEXT_PORT_NO_LISTEN; /* we do not run any server */ + info.protocols = protocols; + info.user = &args; + info.register_notifier_list = na; + info.connect_timeout_secs = 30; + + /* + * since we know this lws context is only ever going to be used with + * one client wsis / fds / sockets at a time, let lws know it doesn't + * have to use the default allocations for fd tables up to ulimit -n. + * It will just allocate for 1 internal and 1 (+ 1 http2 nwsi) that we + * will use. + */ + info.fd_limit_per_thread = 1 + 1 + 1; + +#if defined(LWS_WITH_MBEDTLS) || defined(USE_WOLFSSL) + /* + * OpenSSL uses the system trust store. mbedTLS has to be told which + * CA to trust explicitly. + */ + info.client_ssl_ca_filepath = "./warmcat.com.cer"; +#endif +#if 0 + n = open("./warmcat.com.cer", O_RDONLY); + if (n >= 0) { + info.client_ssl_ca_mem_len = read(n, memcert, sizeof(memcert)); + info.client_ssl_ca_mem = memcert; + close(n); + n = 0; + memcert[info.client_ssl_ca_mem_len++] = '\0'; + } +#endif + context = lws_create_context(&info); + if (!context) { + lwsl_err("lws init failed\n"); + return 1; + } + + while (n >= 0 && !interrupted) n = lws_service(context, 0); lws_context_destroy(context); diff -Nru libwebsockets-3.2.1/minimal-examples/http-client/minimal-http-client/README.md libwebsockets-4.1.6/minimal-examples/http-client/minimal-http-client/README.md --- libwebsockets-3.2.1/minimal-examples/http-client/minimal-http-client/README.md 2019-12-18 14:45:31.000000000 +0000 +++ libwebsockets-4.1.6/minimal-examples/http-client/minimal-http-client/README.md 2020-12-01 17:40:26.000000000 +0000 @@ -21,6 +21,10 @@ -j|Apply tls option LCCSCF_ALLOW_SELFSIGNED -m|Apply tls option LCCSCF_SKIP_SERVER_CERT_HOSTNAME_CHECK -e|Apply tls option LCCSCF_ALLOW_EXPIRED +-v|Connection validity use 3s / 10s instead of default 5m / 5m10s +--nossl| disable ssl connection +--user | Set Basic Auth username +--password | Set Basic Auth password ``` $ ./lws-minimal-http-client @@ -61,4 +65,12 @@ [2018/03/04 14:43:23:3042] USER: Completed ``` +You can also test the client Basic Auth support against the http-server/minimal-http-server-basicauth +example. In one console window run the server and in the other + +``` +$ lws-minimal-http-client -l --nossl --path /secret/index.html --user user --password password +``` + +The Basic Auth credentials for the test server are literally username "user" and password "password". diff -Nru libwebsockets-3.2.1/minimal-examples/http-client/minimal-http-client/selftest.sh libwebsockets-4.1.6/minimal-examples/http-client/minimal-http-client/selftest.sh --- libwebsockets-3.2.1/minimal-examples/http-client/minimal-http-client/selftest.sh 2019-12-18 14:45:31.000000000 +0000 +++ libwebsockets-4.1.6/minimal-examples/http-client/minimal-http-client/selftest.sh 1970-01-01 00:00:00.000000000 +0000 @@ -1,33 +0,0 @@ -#!/bin/bash -# -# $1: path to minimal example binaries... -# if lws is built with -DLWS_WITH_MINIMAL_EXAMPLES=1 -# that will be ./bin from your build dir -# -# $2: path for logs and results. The results will go -# in a subdir named after the directory this script -# is in -# -# $3: offset for test index count -# -# $4: total test count -# -# $5: path to ./minimal-examples dir in lws -# -# Test return code 0: OK, 254: timed out, other: error indication - -. $5/selftests-library.sh - -COUNT_TESTS=4 - -dotest $1 $2 warmcat -dotest $1 $2 warmcat-h1 --h1 - -spawn "" $5/http-server/minimal-http-server-tls $1/lws-minimal-http-server-tls -dotest $1 $2 localhost -l -spawn $SPID $5/http-server/minimal-http-server-tls $1/lws-minimal-http-server-tls -dotest $1 $2 localhost-h1 -l --h1 - -kill $SPID 2>/dev/null -wait $SPID 2>/dev/null -exit $FAILS diff -Nru libwebsockets-3.2.1/minimal-examples/http-client/minimal-http-client/warmcat.com.cer libwebsockets-4.1.6/minimal-examples/http-client/minimal-http-client/warmcat.com.cer --- libwebsockets-3.2.1/minimal-examples/http-client/minimal-http-client/warmcat.com.cer 2019-12-18 14:45:31.000000000 +0000 +++ libwebsockets-4.1.6/minimal-examples/http-client/minimal-http-client/warmcat.com.cer 2020-12-01 17:40:26.000000000 +0000 @@ -56,3 +56,23 @@ PfZ+G6Z6h7mjem0Y+iWlkYcV4PIWL1iwBi8saCbGS5jN2p8M+X+Q7UNKEkROb3N6 KOqkqm57TH2H3eDJAkSnh6/DNFu0Qg== -----END CERTIFICATE----- +-----BEGIN CERTIFICATE----- +MIIDSjCCAjKgAwIBAgIQRK+wgNajJ7qJMDmGLvhAazANBgkqhkiG9w0BAQUFADA/ +MSQwIgYDVQQKExtEaWdpdGFsIFNpZ25hdHVyZSBUcnVzdCBDby4xFzAVBgNVBAMT +DkRTVCBSb290IENBIFgzMB4XDTAwMDkzMDIxMTIxOVoXDTIxMDkzMDE0MDExNVow +PzEkMCIGA1UEChMbRGlnaXRhbCBTaWduYXR1cmUgVHJ1c3QgQ28uMRcwFQYDVQQD +Ew5EU1QgUm9vdCBDQSBYMzCCASIwDQYJKoZIhvcNAQEBBQADggEPADCCAQoCggEB +AN+v6ZdQCINXtMxiZfaQguzH0yxrMMpb7NnDfcdAwRgUi+DoM3ZJKuM/IUmTrE4O +rz5Iy2Xu/NMhD2XSKtkyj4zl93ewEnu1lcCJo6m67XMuegwGMoOifooUMM0RoOEq +OLl5CjH9UL2AZd+3UWODyOKIYepLYYHsUmu5ouJLGiifSKOeDNoJjj4XLh7dIN9b +xiqKqy69cK3FCxolkHRyxXtqqzTWMIn/5WgTe1QLyNau7Fqckh49ZLOMxt+/yUFw +7BZy1SbsOFU5Q9D8/RhcQPGX69Wam40dutolucbY38EVAjqr2m7xPi71XAicPNaD +aeQQmxkqtilX4+U9m5/wAl0CAwEAAaNCMEAwDwYDVR0TAQH/BAUwAwEB/zAOBgNV +HQ8BAf8EBAMCAQYwHQYDVR0OBBYEFMSnsaR7LHH62+FLkHX/xBVghYkQMA0GCSqG +SIb3DQEBBQUAA4IBAQCjGiybFwBcqR7uKGY3Or+Dxz9LwwmglSBd49lZRNI+DT69 +ikugdB/OEIKcdBodfpga3csTS7MgROSR6cz8faXbauX+5v3gTt23ADq1cEmv8uXr +AvHRAosZy5Q6XkjEGB5YGV8eAlrwDPGxrancWYaLbumR9YbK+rlmM6pZW87ipxZz +R8srzJmwN0jP41ZL9c8PDHIyh8bwRLtTcm1D9SZImlJnt1ir/md2cXjbDaJWFBM5 +JDGFoqgCWjBH4d1QB7wCCZAA62RjYJsWvIjJEubSfZGL+T0yjWW06XyxV3bqxbYo +Ob8VZRzI9neWagqNdwvYkQsEjgfbKbYK7p2CNTUQ +-----END CERTIFICATE----- diff -Nru libwebsockets-3.2.1/minimal-examples/http-client/minimal-http-client-attach/CMakeLists.txt libwebsockets-4.1.6/minimal-examples/http-client/minimal-http-client-attach/CMakeLists.txt --- libwebsockets-3.2.1/minimal-examples/http-client/minimal-http-client-attach/CMakeLists.txt 1970-01-01 00:00:00.000000000 +0000 +++ libwebsockets-4.1.6/minimal-examples/http-client/minimal-http-client-attach/CMakeLists.txt 2020-12-01 17:40:26.000000000 +0000 @@ -0,0 +1,26 @@ +project(lws-minimal-http-client-attach C) +cmake_minimum_required(VERSION 2.8) +find_package(libwebsockets CONFIG REQUIRED) +list(APPEND CMAKE_MODULE_PATH ${LWS_CMAKE_DIR}) +include(CheckIncludeFile) +include(CheckCSourceCompiles) +include(LwsCheckRequirements) + +set(SAMP lws-minimal-http-client-attach) +set(SRCS minimal-http-client-attach.c) + +set(requirements 1) +require_pthreads(requirements) +require_lws_config(LWS_ROLE_H1 1 requirements) +require_lws_config(LWS_WITH_CLIENT 1 requirements) + +if (requirements AND NOT WIN32) + add_executable(${SAMP} ${SRCS}) + + if (websockets_shared) + target_link_libraries(${SAMP} websockets_shared ${PTHREAD_LIB} ${LIBWEBSOCKETS_DEP_LIBS}) + add_dependencies(${SAMP} websockets_shared) + else() + target_link_libraries(${SAMP} websockets ${PTHREAD_LIB} ${LIBWEBSOCKETS_DEP_LIBS}) + endif() +endif() diff -Nru libwebsockets-3.2.1/minimal-examples/http-client/minimal-http-client-attach/minimal-http-client-attach.c libwebsockets-4.1.6/minimal-examples/http-client/minimal-http-client-attach/minimal-http-client-attach.c --- libwebsockets-3.2.1/minimal-examples/http-client/minimal-http-client-attach/minimal-http-client-attach.c 1970-01-01 00:00:00.000000000 +0000 +++ libwebsockets-4.1.6/minimal-examples/http-client/minimal-http-client-attach/minimal-http-client-attach.c 2020-12-01 17:40:26.000000000 +0000 @@ -0,0 +1,277 @@ +/* + * lws-minimal-http-client-attach + * + * Written in 2010-2019 by Andy Green + * + * This file is made available under the Creative Commons CC0 1.0 + * Universal Public Domain Dedication. + * + * This demonstrates how to use the lws_system (*attach) api to allow a + * different thread to arrange to join an existing lws event loop safely. The + * attached stuff does an http client GET from the lws event loop, even though + * it was originally requested from a different thread than the lws event loop. + */ + +#include +#include +#include +#if defined(WIN32) +#define HAVE_STRUCT_TIMESPEC +#if defined(pid_t) +#undef pid_t +#endif +#endif +#include + +static struct lws_context *context; +static pthread_t lws_thread; +static pthread_mutex_t lock; +static int interrupted, bad = 1, status; + +static int +callback_http(struct lws *wsi, enum lws_callback_reasons reason, + void *user, void *in, size_t len) +{ + switch (reason) { + + /* because we are protocols[0] ... */ + case LWS_CALLBACK_CLIENT_CONNECTION_ERROR: + lwsl_err("CLIENT_CONNECTION_ERROR: %s\n", + in ? (char *)in : "(null)"); + interrupted = 1; + break; + + case LWS_CALLBACK_ESTABLISHED_CLIENT_HTTP: + { + char buf[128]; + + lws_get_peer_simple(wsi, buf, sizeof(buf)); + status = lws_http_client_http_response(wsi); + + lwsl_user("Connected to %s, http response: %d\n", + buf, status); + } + break; + + /* chunks of chunked content, with header removed */ + case LWS_CALLBACK_RECEIVE_CLIENT_HTTP_READ: + lwsl_user("RECEIVE_CLIENT_HTTP_READ: read %d\n", (int)len); + +#if 0 /* enable to dump the html */ + { + const char *p = in; + + while (len--) + if (*p < 0x7f) + putchar(*p++); + else + putchar('.'); + } +#endif + return 0; /* don't passthru */ + + /* uninterpreted http content */ + case LWS_CALLBACK_RECEIVE_CLIENT_HTTP: + { + char buffer[1024 + LWS_PRE]; + char *px = buffer + LWS_PRE; + int lenx = sizeof(buffer) - LWS_PRE; + + if (lws_http_client_read(wsi, &px, &lenx) < 0) + return -1; + } + return 0; /* don't passthru */ + + case LWS_CALLBACK_COMPLETED_CLIENT_HTTP: + lwsl_user("LWS_CALLBACK_COMPLETED_CLIENT_HTTP\n"); + interrupted = 1; + bad = status != 200; + lws_cancel_service(lws_get_context(wsi)); /* abort poll wait */ + break; + + case LWS_CALLBACK_CLOSED_CLIENT_HTTP: + interrupted = 1; + bad = status != 200; + lws_cancel_service(lws_get_context(wsi)); /* abort poll wait */ + break; + + default: + break; + } + + return lws_callback_http_dummy(wsi, reason, user, in, len); +} + +static const struct lws_protocols protocols[] = { + { + "http", + callback_http, + 0, + 0, + }, + { NULL, NULL, 0, 0 } +}; + +void sigint_handler(int sig) +{ + interrupted = 1; +} + +static void +attach_callback(struct lws_context *context, int tsi, void *opaque) +{ + struct lws_client_connect_info i; + + /* + * Even though it was asked for from a different thread, we are called + * back by lws from the lws event loop thread context + * + * We can set up our operations on the lws event loop and return so + * they can happen asynchronously + */ + + memset(&i, 0, sizeof i); /* otherwise uninitialized garbage */ + i.context = context; + i.ssl_connection = LCCSCF_USE_SSL; + i.ssl_connection |= LCCSCF_H2_QUIRK_OVERFLOWS_TXCR | + LCCSCF_H2_QUIRK_NGHTTP2_END_STREAM; + i.port = 443; + i.address = "warmcat.com"; + i.path = "/"; + i.host = i.address; + i.origin = i.address; + i.method = "GET"; + + i.protocol = protocols[0].name; + + lws_client_connect_via_info(&i); +} + + +static int +lws_attach_with_pthreads_locking(struct lws_context *context, int tsi, + lws_attach_cb_t cb, lws_system_states_t state, + void *opaque, struct lws_attach_item **get) +{ + int n; + + pthread_mutex_lock(&lock); + /* + * We just provide system-specific locking around the lws non-threadsafe + * helper that adds and removes things from the pt list + */ + n = __lws_system_attach(context, tsi, cb, state, opaque, get); + pthread_mutex_unlock(&lock); + + return n; +} + + +lws_system_ops_t ops = { + .attach = lws_attach_with_pthreads_locking +}; + +/* + * We made this into a different thread to model it being run from completely + * different codebase that's all linked together + */ + +static void * +lws_create(void *d) +{ + struct lws_context_creation_info info; + + lwsl_user("%s: tid %p\n", __func__, (void *)pthread_self()); + + memset(&info, 0, sizeof info); /* otherwise uninitialized garbage */ + info.port = CONTEXT_PORT_NO_LISTEN; + info.options = LWS_SERVER_OPTION_DO_SSL_GLOBAL_INIT; + info.system_ops = &ops; + info.protocols = protocols; + + context = lws_create_context(&info); + if (!context) { + lwsl_err("lws init failed\n"); + goto bail; + } + + /* start the event loop */ + + while (!interrupted) + if (lws_service(context, 0)) + interrupted = 1; + + lws_context_destroy(context); + +bail: + pthread_exit(NULL); + + return NULL; +} + +int main(int argc, const char **argv) +{ + int n = 0, logs = LLL_USER | LLL_ERR | LLL_WARN | LLL_NOTICE; + const char *p; + void *retval; + + signal(SIGINT, sigint_handler); + + if ((p = lws_cmdline_option(argc, argv, "-d"))) + logs = atoi(p); + + lws_set_log_level(logs, NULL); + lwsl_user("LWS minimal http client attach\n"); + + pthread_mutex_init(&lock, NULL); + + /* + * The idea of the example is we're going to split the lws context and + * event loop off to be created from its own thread... this is like it + * was actually started by some completely different code... + */ + + if (pthread_create(&lws_thread, NULL, lws_create, NULL)) { + lwsl_err("thread creation failed\n"); + goto bail1; + } + + /* + * Now on the original / different thread representing a different + * codebase that wants to join this existing event loop, we'll ask to + * get a callback from the event loop context when the event loop + * thread is operational. We have to wait around a bit because we + * may run before the lws context was created. + */ + + while (!context && n++ < 30) + usleep(10000); + + if (!context) { + lwsl_err("%s: context didn't start\n", __func__); + goto bail; + } + + /* + * From our different, non event loop thread, ask for our attach + * callback to get called when lws system state is OPERATIONAL + */ + + lws_system_get_ops(context)->attach(context, 0, attach_callback, + LWS_SYSTATE_OPERATIONAL, + NULL, NULL); + + /* + * That's all we wanted to do with our thread. Just wait for the lws + * thread to exit as well. + */ + +bail: + pthread_join(lws_thread, &retval); +bail1: + pthread_mutex_destroy(&lock); + + lwsl_user("%s: finished\n", __func__); + + return 0; +} diff -Nru libwebsockets-3.2.1/minimal-examples/http-client/minimal-http-client-attach/README.md libwebsockets-4.1.6/minimal-examples/http-client/minimal-http-client-attach/README.md --- libwebsockets-3.2.1/minimal-examples/http-client/minimal-http-client-attach/README.md 1970-01-01 00:00:00.000000000 +0000 +++ libwebsockets-4.1.6/minimal-examples/http-client/minimal-http-client-attach/README.md 2020-12-01 17:40:26.000000000 +0000 @@ -0,0 +1,35 @@ +# lws minimal http client attach + +This demonstrates how other threads can reach out to an existing lws_context +and join its event loop cleanly and safely. + +## build + +``` + $ cmake . && make +``` + +Pthreads is required on your system. + +## usage + +``` + $ ./lws-minimal-http-client-attach +[2019/12/31 18:30:49:3495] U: main: main thread tid 0x503e1c0 +[2019/12/31 18:30:50:3584] U: LWS minimal http client attach +[2019/12/31 18:30:50:4002] U: lws_create: tid 0x5c41700 +[2019/12/31 18:30:50:5727] E: callback_ntpc: set up system ops for set_clock +[2019/12/31 18:30:50:2110] N: callback_ntpc: Unix time: 1577817053 +[2019/12/31 18:30:50:2136] U: attach_callback: called from tid 0x5c41700 +[2019/12/31 18:30:51:8733] U: Connected to 46.105.127.147, http response: 200 +[2019/12/31 18:30:51:8818] U: RECEIVE_CLIENT_HTTP_READ: read 4087 +[2019/12/31 18:30:51:8823] U: RECEIVE_CLIENT_HTTP_READ: read 4096 +[2019/12/31 18:30:51:8846] U: RECEIVE_CLIENT_HTTP_READ: read 4087 +[2019/12/31 18:30:51:8847] U: RECEIVE_CLIENT_HTTP_READ: read 4096 +[2019/12/31 18:30:51:8855] U: RECEIVE_CLIENT_HTTP_READ: read 4087 +[2019/12/31 18:30:51:8856] U: RECEIVE_CLIENT_HTTP_READ: read 4096 +[2019/12/31 18:30:51:8860] U: RECEIVE_CLIENT_HTTP_READ: read 1971 +[2019/12/31 18:30:51:8873] U: LWS_CALLBACK_COMPLETED_CLIENT_HTTP +[2019/12/31 18:30:51:9629] U: main: finished +``` + diff -Nru libwebsockets-3.2.1/minimal-examples/http-client/minimal-http-client-captive-portal/CMakeLists.txt libwebsockets-4.1.6/minimal-examples/http-client/minimal-http-client-captive-portal/CMakeLists.txt --- libwebsockets-3.2.1/minimal-examples/http-client/minimal-http-client-captive-portal/CMakeLists.txt 1970-01-01 00:00:00.000000000 +0000 +++ libwebsockets-4.1.6/minimal-examples/http-client/minimal-http-client-captive-portal/CMakeLists.txt 2020-12-01 17:40:26.000000000 +0000 @@ -0,0 +1,27 @@ +project(lws-minimal-http-client-captive-portal C) +cmake_minimum_required(VERSION 2.8) +find_package(libwebsockets CONFIG REQUIRED) +list(APPEND CMAKE_MODULE_PATH ${LWS_CMAKE_DIR}) +include(CheckIncludeFile) +include(CheckCSourceCompiles) +include(LwsCheckRequirements) + +set(SAMP lws-minimal-http-client-captive-portal) +set(SRCS minimal-http-client-captive-portal.c) + +set(requirements 1) +require_lws_config(LWS_ROLE_H1 1 requirements) +require_lws_config(LWS_WITH_TLS 1 requirements) +require_lws_config(LWS_WITH_CLIENT 1 requirements) +require_lws_config(LWS_WITH_SYS_STATE 1 requirements) + +if (NOT WIN32 AND requirements) + add_executable(${SAMP} ${SRCS}) + + if (websockets_shared) + target_link_libraries(${SAMP} websockets_shared pthread ${LIBWEBSOCKETS_DEP_LIBS}) + add_dependencies(${SAMP} websockets_shared) + else() + target_link_libraries(${SAMP} websockets pthread ${LIBWEBSOCKETS_DEP_LIBS}) + endif() +endif() diff -Nru libwebsockets-3.2.1/minimal-examples/http-client/minimal-http-client-captive-portal/minimal-http-client-captive-portal.c libwebsockets-4.1.6/minimal-examples/http-client/minimal-http-client-captive-portal/minimal-http-client-captive-portal.c --- libwebsockets-3.2.1/minimal-examples/http-client/minimal-http-client-captive-portal/minimal-http-client-captive-portal.c 1970-01-01 00:00:00.000000000 +0000 +++ libwebsockets-4.1.6/minimal-examples/http-client/minimal-http-client-captive-portal/minimal-http-client-captive-portal.c 2020-12-01 17:40:26.000000000 +0000 @@ -0,0 +1,321 @@ +/* + * lws-minimal-http-client-captive-portal + * + * Written in 2010-2020 by Andy Green + * + * This file is made available under the Creative Commons CC0 1.0 + * Universal Public Domain Dedication. + * + * This demonstrates how to use the lws_system captive portal detect integration + * + * We check for a captive portal by doing a GET from + * http://connectivitycheck.android.com/generate_204, if we really are going + * out on the Internet he'll return with a 204 response code and we will + * understand there's no captive portal. If we get something else, we take it + * there is a captive portal. + */ + +#include +#include +#include + +static struct lws_context *context; +static int interrupted, bad = 1, status; +static lws_state_notify_link_t nl; + +/* + * this is the user code http handler + */ + +static int +callback_http(struct lws *wsi, enum lws_callback_reasons reason, + void *user, void *in, size_t len) +{ + switch (reason) { + + /* because we are protocols[0] ... */ + case LWS_CALLBACK_CLIENT_CONNECTION_ERROR: + lwsl_err("CLIENT_CONNECTION_ERROR: %s\n", + in ? (char *)in : "(null)"); + interrupted = 1; + break; + + case LWS_CALLBACK_ESTABLISHED_CLIENT_HTTP: + { + char buf[128]; + + lws_get_peer_simple(wsi, buf, sizeof(buf)); + status = lws_http_client_http_response(wsi); + + lwsl_user("Connected to %s, http response: %d\n", + buf, status); + } + break; + + /* chunks of chunked content, with header removed */ + case LWS_CALLBACK_RECEIVE_CLIENT_HTTP_READ: + lwsl_user("RECEIVE_CLIENT_HTTP_READ: read %d\n", (int)len); + +#if 0 /* enable to dump the html */ + { + const char *p = in; + + while (len--) + if (*p < 0x7f) + putchar(*p++); + else + putchar('.'); + } +#endif + return 0; /* don't passthru */ + + /* uninterpreted http content */ + case LWS_CALLBACK_RECEIVE_CLIENT_HTTP: + { + char buffer[1024 + LWS_PRE]; + char *px = buffer + LWS_PRE; + int lenx = sizeof(buffer) - LWS_PRE; + + if (lws_http_client_read(wsi, &px, &lenx) < 0) + return -1; + } + return 0; /* don't passthru */ + + case LWS_CALLBACK_COMPLETED_CLIENT_HTTP: + lwsl_user("LWS_CALLBACK_COMPLETED_CLIENT_HTTP\n"); + interrupted = 1; + bad = status != 200; + lws_cancel_service(lws_get_context(wsi)); /* abort poll wait */ + break; + + case LWS_CALLBACK_CLOSED_CLIENT_HTTP: + interrupted = 1; + bad = status != 200; + lws_cancel_service(lws_get_context(wsi)); /* abort poll wait */ + break; + + default: + break; + } + + return lws_callback_http_dummy(wsi, reason, user, in, len); +} + +/* + * This is the platform's custom captive portal detection handler + */ + +static int +callback_cpd_http(struct lws *wsi, enum lws_callback_reasons reason, + void *user, void *in, size_t len) +{ + int resp; + + switch (reason) { + + case LWS_CALLBACK_ESTABLISHED_CLIENT_HTTP: + resp = lws_http_client_http_response(wsi); + if (!resp) + break; + lwsl_user("%s: established with resp %d\n", __func__, resp); + switch (resp) { + + case HTTP_STATUS_NO_CONTENT: + /* + * We got the 204 which is used to distinguish the real + * endpoint + */ + lws_system_cpd_set(lws_get_context(wsi), + LWS_CPD_INTERNET_OK); + return 0; + + /* also case HTTP_STATUS_OK: ... */ + default: + break; + } + + /* fallthru */ + + case LWS_CALLBACK_CLIENT_HTTP_REDIRECT: + lws_system_cpd_set(lws_get_context(wsi), LWS_CPD_CAPTIVE_PORTAL); + /* don't follow it, just report it */ + return 1; + + case LWS_CALLBACK_CLIENT_CONNECTION_ERROR: + case LWS_CALLBACK_CLOSED_CLIENT_HTTP: + /* only the first result counts */ + lws_system_cpd_set(lws_get_context(wsi), LWS_CPD_NO_INTERNET); + break; + + default: + break; + } + + return lws_callback_http_dummy(wsi, reason, user, in, len); +} + +static const struct lws_protocols protocols[] = { + { + "http", + callback_http, + 0, + 0, + }, { + "lws-cpd-http", + callback_cpd_http + }, + { NULL, NULL, 0, 0 } +}; + +void sigint_handler(int sig) +{ + interrupted = 1; +} + +/* + * This triggers our platform implementation of captive portal detection, the + * actual test can be whatever you need. + * + * In this example, we detect it using Android's + * + * http://connectivitycheck.android.com/generate_204 + * + * and seeing if we get an http 204 back. + */ + +static int +captive_portal_detect_request(struct lws_context *context) +{ + struct lws_client_connect_info i; + + memset(&i, 0, sizeof i); + i.context = context; + i.port = 80; + i.address = "connectivitycheck.android.com"; + i.path = "/generate_204"; + i.host = i.address; + i.origin = i.address; + i.method = "GET"; + + i.protocol = "lws-cpd-http"; + + return !lws_client_connect_via_info(&i); +} + + +lws_system_ops_t ops = { + .captive_portal_detect_request = captive_portal_detect_request +}; + + +static int +app_system_state_nf(lws_state_manager_t *mgr, lws_state_notify_link_t *link, + int current, int target) +{ + struct lws_context *cx = lws_system_context_from_system_mgr(mgr); + + switch (target) { + case LWS_SYSTATE_CPD_PRE_TIME: + if (lws_system_cpd_state_get(cx)) + return 0; /* allow it */ + + lwsl_info("%s: LWS_SYSTATE_CPD_PRE_TIME\n", __func__); + lws_system_cpd_start(cx); + /* we'll move the state on when we get a result */ + return 1; + + case LWS_SYSTATE_OPERATIONAL: + if (current == LWS_SYSTATE_OPERATIONAL) { + struct lws_client_connect_info i; + + lwsl_user("%s: OPERATIONAL, cpd %d\n", __func__, + lws_system_cpd_state_get(cx)); + + /* + * When we reach the OPERATIONAL lws_system state, we + * can do our main job knowing we have DHCP, ntpclient, + * captive portal testing done. + */ + + if (lws_system_cpd_state_get(cx) != LWS_CPD_INTERNET_OK) { + lwsl_warn("%s: There's no internet...\n", __func__); + interrupted = 1; + break; + } + + memset(&i, 0, sizeof i); + i.context = context; + i.ssl_connection = LCCSCF_USE_SSL; + i.ssl_connection |= LCCSCF_H2_QUIRK_OVERFLOWS_TXCR | + LCCSCF_H2_QUIRK_NGHTTP2_END_STREAM; + i.port = 443; + i.address = "warmcat.com"; + i.path = "/"; + i.host = i.address; + i.origin = i.address; + i.method = "GET"; + + i.protocol = protocols[0].name; + + lws_client_connect_via_info(&i); + break; + } + default: + break; + } + + return 0; +} + +static lws_state_notify_link_t * const app_notifier_list[] = { + &nl, NULL +}; + +/* + * We made this into a different thread to model it being run from completely + * different codebase that's all linked together + */ + + +int main(int argc, const char **argv) +{ + int logs = LLL_USER | LLL_ERR | LLL_WARN | LLL_NOTICE; + struct lws_context_creation_info info; + const char *p; + + signal(SIGINT, sigint_handler); + + if ((p = lws_cmdline_option(argc, argv, "-d"))) + logs = atoi(p); + + lws_set_log_level(logs, NULL); + lwsl_user("LWS minimal http client captive portal detect\n"); + + memset(&info, 0, sizeof info); + info.port = CONTEXT_PORT_NO_LISTEN; + info.options = LWS_SERVER_OPTION_DO_SSL_GLOBAL_INIT; + info.system_ops = &ops; + info.protocols = protocols; + + /* integrate us with lws system state management when context created */ + + nl.name = "app"; + nl.notify_cb = app_system_state_nf; + info.register_notifier_list = app_notifier_list; + + context = lws_create_context(&info); + if (!context) { + lwsl_err("lws init failed\n"); + return 1; + } + + while (!interrupted) + if (lws_service(context, 0)) + interrupted = 1; + + lws_context_destroy(context); + + lwsl_user("%s: finished %s\n", __func__, bad ? "FAIL": "OK"); + + return bad; +} diff -Nru libwebsockets-3.2.1/minimal-examples/http-client/minimal-http-client-captive-portal/README.md libwebsockets-4.1.6/minimal-examples/http-client/minimal-http-client-captive-portal/README.md --- libwebsockets-3.2.1/minimal-examples/http-client/minimal-http-client-captive-portal/README.md 1970-01-01 00:00:00.000000000 +0000 +++ libwebsockets-4.1.6/minimal-examples/http-client/minimal-http-client-captive-portal/README.md 2020-12-01 17:40:26.000000000 +0000 @@ -0,0 +1,45 @@ +# lws minimal http client captive portal detect + +This demonstrates how to perform captive portal detection integrated +with `lws_system` states. + +After reaching the `lws_system` DHCP state, the application tries to +connect through to `http://connectivitycheck.android.com/generate_204` +over http... if it succeeds, it will get a 204 response and set the +captive portal detection state to `LWS_CPD_INTERNET_OK` and perform +a GET from warmcat.com. + +If there is a problem detected, the captive portal detection state is +set accordingly and the app will respond by exiting without trying the +read from warmcat.com. + +The captive portal detection scheme is implemented in the user code +and can be modified according to the strategy that's desired for +captive portal detection. + +## build + +``` + $ cmake . && make +``` + +## usage + +``` +$ ./bin/lws-minimal-http-client-captive-portal +[2020/03/11 13:07:07:4519] U: LWS minimal http client captive portal detect +[2020/03/11 13:07:07:4519] N: lws_create_context: using ss proxy bind '(null)', port 0, ads '(null)' +[2020/03/11 13:07:07:5022] U: callback_cpd_http: established with resp 204 +[2020/03/11 13:07:07:5023] U: app_system_state_nf: OPERATIONAL, cpd 1 +[2020/03/11 13:07:07:5896] U: Connected to 46.105.127.147, http response: 200 +[2020/03/11 13:07:07:5931] U: RECEIVE_CLIENT_HTTP_READ: read 4087 +[2020/03/11 13:07:07:5931] U: RECEIVE_CLIENT_HTTP_READ: read 4096 +[2020/03/11 13:07:07:6092] U: RECEIVE_CLIENT_HTTP_READ: read 4087 +[2020/03/11 13:07:07:6092] U: RECEIVE_CLIENT_HTTP_READ: read 4096 +[2020/03/11 13:07:07:6112] U: RECEIVE_CLIENT_HTTP_READ: read 4087 +[2020/03/11 13:07:07:6113] U: RECEIVE_CLIENT_HTTP_READ: read 4096 +[2020/03/11 13:07:07:6113] U: RECEIVE_CLIENT_HTTP_READ: read 2657 +[2020/03/11 13:07:07:6113] U: LWS_CALLBACK_COMPLETED_CLIENT_HTTP +[2020/03/11 13:07:07:6119] U: main: finished OK +``` + diff -Nru libwebsockets-3.2.1/minimal-examples/http-client/minimal-http-client-certinfo/CMakeLists.txt libwebsockets-4.1.6/minimal-examples/http-client/minimal-http-client-certinfo/CMakeLists.txt --- libwebsockets-3.2.1/minimal-examples/http-client/minimal-http-client-certinfo/CMakeLists.txt 2019-12-18 14:45:31.000000000 +0000 +++ libwebsockets-4.1.6/minimal-examples/http-client/minimal-http-client-certinfo/CMakeLists.txt 2020-12-01 17:40:26.000000000 +0000 @@ -1,80 +1,25 @@ +project(lws-minimal-http-client-certinfo C) cmake_minimum_required(VERSION 2.8) +find_package(libwebsockets CONFIG REQUIRED) +list(APPEND CMAKE_MODULE_PATH ${LWS_CMAKE_DIR}) include(CheckCSourceCompiles) +include(LwsCheckRequirements) set(SAMP lws-minimal-http-client-certinfo) set(SRCS minimal-http-client-certinfo.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_ROLE_H1 1 requirements) -require_lws_config(LWS_WITHOUT_CLIENT 0 requirements) -require_lws_config(LWS_OPENSSL_SUPPORT 1 requirements) +require_lws_config(LWS_WITH_CLIENT 1 requirements) +require_lws_config(LWS_WITH_TLS 1 requirements) if (requirements) add_executable(${SAMP} ${SRCS}) if (websockets_shared) - target_link_libraries(${SAMP} websockets_shared) + target_link_libraries(${SAMP} websockets_shared ${LIBWEBSOCKETS_DEP_LIBS}) add_dependencies(${SAMP} websockets_shared) else() - target_link_libraries(${SAMP} websockets) + target_link_libraries(${SAMP} websockets ${LIBWEBSOCKETS_DEP_LIBS}) endif() endif() diff -Nru libwebsockets-3.2.1/minimal-examples/http-client/minimal-http-client-certinfo/minimal-http-client-certinfo.c libwebsockets-4.1.6/minimal-examples/http-client/minimal-http-client-certinfo/minimal-http-client-certinfo.c --- libwebsockets-3.2.1/minimal-examples/http-client/minimal-http-client-certinfo/minimal-http-client-certinfo.c 2019-12-18 14:45:31.000000000 +0000 +++ libwebsockets-4.1.6/minimal-examples/http-client/minimal-http-client-certinfo/minimal-http-client-certinfo.c 2020-12-01 17:40:26.000000000 +0000 @@ -167,7 +167,7 @@ */ info.fd_limit_per_thread = 1 + 1 + 1; -#if defined(LWS_WITH_MBEDTLS) +#if defined(LWS_WITH_MBEDTLS) || defined(USE_WOLFSSL) /* * OpenSSL uses the system trust store. mbedTLS has to be told which * CA to trust explicitly. diff -Nru libwebsockets-3.2.1/minimal-examples/http-client/minimal-http-client-certinfo/warmcat.com.cer libwebsockets-4.1.6/minimal-examples/http-client/minimal-http-client-certinfo/warmcat.com.cer --- libwebsockets-3.2.1/minimal-examples/http-client/minimal-http-client-certinfo/warmcat.com.cer 2019-12-18 14:45:31.000000000 +0000 +++ libwebsockets-4.1.6/minimal-examples/http-client/minimal-http-client-certinfo/warmcat.com.cer 2020-12-01 17:40:26.000000000 +0000 @@ -56,3 +56,23 @@ PfZ+G6Z6h7mjem0Y+iWlkYcV4PIWL1iwBi8saCbGS5jN2p8M+X+Q7UNKEkROb3N6 KOqkqm57TH2H3eDJAkSnh6/DNFu0Qg== -----END CERTIFICATE----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4d1QB7wCCZAA62RjYJsWvIjJEubSfZGL+T0yjWW06XyxV3bqxbYo +Ob8VZRzI9neWagqNdwvYkQsEjgfbKbYK7p2CNTUQ +-----END CERTIFICATE----- diff -Nru libwebsockets-3.2.1/minimal-examples/http-client/minimal-http-client-custom-headers/CMakeLists.txt libwebsockets-4.1.6/minimal-examples/http-client/minimal-http-client-custom-headers/CMakeLists.txt --- libwebsockets-3.2.1/minimal-examples/http-client/minimal-http-client-custom-headers/CMakeLists.txt 2019-12-18 14:45:31.000000000 +0000 +++ libwebsockets-4.1.6/minimal-examples/http-client/minimal-http-client-custom-headers/CMakeLists.txt 2020-12-01 17:40:26.000000000 +0000 @@ -1,79 +1,24 @@ +project(lws-minimal-http-client-custom-headers C) cmake_minimum_required(VERSION 2.8) +find_package(libwebsockets CONFIG REQUIRED) +list(APPEND CMAKE_MODULE_PATH ${LWS_CMAKE_DIR}) include(CheckCSourceCompiles) +include(LwsCheckRequirements) set(SAMP lws-minimal-http-client-custom-headers) set(SRCS minimal-http-client-custom-headers.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_ROLE_H1 1 requirements) -require_lws_config(LWS_WITHOUT_CLIENT 0 requirements) +require_lws_config(LWS_WITH_CLIENT 1 requirements) if (requirements) add_executable(${SAMP} ${SRCS}) if (websockets_shared) - target_link_libraries(${SAMP} websockets_shared) + target_link_libraries(${SAMP} websockets_shared ${LIBWEBSOCKETS_DEP_LIBS}) add_dependencies(${SAMP} websockets_shared) else() - target_link_libraries(${SAMP} websockets) + target_link_libraries(${SAMP} websockets ${LIBWEBSOCKETS_DEP_LIBS}) endif() endif() diff -Nru libwebsockets-3.2.1/minimal-examples/http-client/minimal-http-client-custom-headers/minimal-http-client-custom-headers.c libwebsockets-4.1.6/minimal-examples/http-client/minimal-http-client-custom-headers/minimal-http-client-custom-headers.c --- libwebsockets-3.2.1/minimal-examples/http-client/minimal-http-client-custom-headers/minimal-http-client-custom-headers.c 2019-12-18 14:45:31.000000000 +0000 +++ libwebsockets-4.1.6/minimal-examples/http-client/minimal-http-client-custom-headers/minimal-http-client-custom-headers.c 2020-12-01 17:40:26.000000000 +0000 @@ -177,7 +177,7 @@ */ info.fd_limit_per_thread = 1 + 1 + 1; -#if defined(LWS_WITH_MBEDTLS) +#if defined(LWS_WITH_MBEDTLS) || defined(USE_WOLFSSL) /* * OpenSSL uses the system trust store. mbedTLS has to be told which * CA to trust explicitly. diff -Nru libwebsockets-3.2.1/minimal-examples/http-client/minimal-http-client-custom-headers/warmcat.com.cer libwebsockets-4.1.6/minimal-examples/http-client/minimal-http-client-custom-headers/warmcat.com.cer --- libwebsockets-3.2.1/minimal-examples/http-client/minimal-http-client-custom-headers/warmcat.com.cer 2019-12-18 14:45:31.000000000 +0000 +++ libwebsockets-4.1.6/minimal-examples/http-client/minimal-http-client-custom-headers/warmcat.com.cer 2020-12-01 17:40:26.000000000 +0000 @@ -56,3 +56,23 @@ PfZ+G6Z6h7mjem0Y+iWlkYcV4PIWL1iwBi8saCbGS5jN2p8M+X+Q7UNKEkROb3N6 KOqkqm57TH2H3eDJAkSnh6/DNFu0Qg== -----END CERTIFICATE----- +-----BEGIN CERTIFICATE----- +MIIDSjCCAjKgAwIBAgIQRK+wgNajJ7qJMDmGLvhAazANBgkqhkiG9w0BAQUFADA/ +MSQwIgYDVQQKExtEaWdpdGFsIFNpZ25hdHVyZSBUcnVzdCBDby4xFzAVBgNVBAMT +DkRTVCBSb290IENBIFgzMB4XDTAwMDkzMDIxMTIxOVoXDTIxMDkzMDE0MDExNVow +PzEkMCIGA1UEChMbRGlnaXRhbCBTaWduYXR1cmUgVHJ1c3QgQ28uMRcwFQYDVQQD +Ew5EU1QgUm9vdCBDQSBYMzCCASIwDQYJKoZIhvcNAQEBBQADggEPADCCAQoCggEB +AN+v6ZdQCINXtMxiZfaQguzH0yxrMMpb7NnDfcdAwRgUi+DoM3ZJKuM/IUmTrE4O +rz5Iy2Xu/NMhD2XSKtkyj4zl93ewEnu1lcCJo6m67XMuegwGMoOifooUMM0RoOEq +OLl5CjH9UL2AZd+3UWODyOKIYepLYYHsUmu5ouJLGiifSKOeDNoJjj4XLh7dIN9b +xiqKqy69cK3FCxolkHRyxXtqqzTWMIn/5WgTe1QLyNau7Fqckh49ZLOMxt+/yUFw +7BZy1SbsOFU5Q9D8/RhcQPGX69Wam40dutolucbY38EVAjqr2m7xPi71XAicPNaD +aeQQmxkqtilX4+U9m5/wAl0CAwEAAaNCMEAwDwYDVR0TAQH/BAUwAwEB/zAOBgNV +HQ8BAf8EBAMCAQYwHQYDVR0OBBYEFMSnsaR7LHH62+FLkHX/xBVghYkQMA0GCSqG +SIb3DQEBBQUAA4IBAQCjGiybFwBcqR7uKGY3Or+Dxz9LwwmglSBd49lZRNI+DT69 +ikugdB/OEIKcdBodfpga3csTS7MgROSR6cz8faXbauX+5v3gTt23ADq1cEmv8uXr +AvHRAosZy5Q6XkjEGB5YGV8eAlrwDPGxrancWYaLbumR9YbK+rlmM6pZW87ipxZz +R8srzJmwN0jP41ZL9c8PDHIyh8bwRLtTcm1D9SZImlJnt1ir/md2cXjbDaJWFBM5 +JDGFoqgCWjBH4d1QB7wCCZAA62RjYJsWvIjJEubSfZGL+T0yjWW06XyxV3bqxbYo +Ob8VZRzI9neWagqNdwvYkQsEjgfbKbYK7p2CNTUQ +-----END CERTIFICATE----- diff -Nru libwebsockets-3.2.1/minimal-examples/http-client/minimal-http-client-h2-rxflow/CMakeLists.txt libwebsockets-4.1.6/minimal-examples/http-client/minimal-http-client-h2-rxflow/CMakeLists.txt --- libwebsockets-3.2.1/minimal-examples/http-client/minimal-http-client-h2-rxflow/CMakeLists.txt 1970-01-01 00:00:00.000000000 +0000 +++ libwebsockets-4.1.6/minimal-examples/http-client/minimal-http-client-h2-rxflow/CMakeLists.txt 2020-12-01 17:40:26.000000000 +0000 @@ -0,0 +1,34 @@ +project(lws-minimal-http-client-h2-rxflow C) +cmake_minimum_required(VERSION 2.8) +find_package(libwebsockets CONFIG REQUIRED) +list(APPEND CMAKE_MODULE_PATH ${LWS_CMAKE_DIR}) +include(CheckCSourceCompiles) +include(LwsCheckRequirements) + +set(SAMP lws-minimal-http-client-h2-rxflow) +set(SRCS minimal-http-client.c) + +set(requirements 1) +require_lws_config(LWS_ROLE_H2 1 requirements) +require_lws_config(LWS_WITH_CLIENT 1 requirements) +require_lws_config(LWS_WITH_SYS_STATE 1 requirements) + +if (requirements) + add_executable(${SAMP} ${SRCS}) + if (LWS_CTEST_INTERNET_AVAILABLE) + add_test(NAME http-client-h2-rxflow-warmcat COMMAND lws-minimal-http-client-h2-rxflow --ignore-sigterm) + add_test(NAME http-client-h2-rxflow-warmcat-h1 COMMAND lws-minimal-http-client-h2-rxflow --ignore-sigterm --h1) + set_tests_properties(http-client-h2-rxflow-warmcat + http-client-h2-rxflow-warmcat-h1 + PROPERTIES + WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}/minimal-examples/http-client/minimal-http-client-h2-rxflow + TIMEOUT 30) + endif() + + if (websockets_shared) + target_link_libraries(${SAMP} websockets_shared ${LIBWEBSOCKETS_DEP_LIBS}) + add_dependencies(${SAMP} websockets_shared) + else() + target_link_libraries(${SAMP} websockets ${LIBWEBSOCKETS_DEP_LIBS}) + endif() +endif() diff -Nru libwebsockets-3.2.1/minimal-examples/http-client/minimal-http-client-h2-rxflow/minimal-http-client.c libwebsockets-4.1.6/minimal-examples/http-client/minimal-http-client-h2-rxflow/minimal-http-client.c --- libwebsockets-3.2.1/minimal-examples/http-client/minimal-http-client-h2-rxflow/minimal-http-client.c 1970-01-01 00:00:00.000000000 +0000 +++ libwebsockets-4.1.6/minimal-examples/http-client/minimal-http-client-h2-rxflow/minimal-http-client.c 2020-12-01 17:40:26.000000000 +0000 @@ -0,0 +1,303 @@ +/* + * lws-minimal-http-client-h2-rxflow + * + * Written in 2010-2019 by Andy Green + * + * This file is made available under the Creative Commons CC0 1.0 + * Universal Public Domain Dedication. + * + * This demonstrates the a minimal http client using lws. + * + * It visits https://warmcat.com/ and receives the html page there. You + * can dump the page data by changing the #if 0 below. + */ + +#include +#include +#include + +static int interrupted, bad = 1, status, each = 1024; +static struct lws *client_wsi; + +static const lws_retry_bo_t retry = { + .secs_since_valid_ping = 3, + .secs_since_valid_hangup = 10, +}; + +struct pss { + lws_sorted_usec_list_t sul; + struct lws *wsi; +}; + +/* + * Once we're established, we ask the server for another 1KB every 250ms + * until we have it all. + */ + +static void +drain_cb(lws_sorted_usec_list_t *sul) +{ + struct pss *pss = lws_container_of(sul, struct pss, sul); + + lws_wsi_tx_credit(pss->wsi, LWSTXCR_PEER_TO_US, each); + + lws_sul_schedule(lws_get_context(pss->wsi), 0, &pss->sul, drain_cb, + 250 * LWS_US_PER_MS); +} + + +static int +callback_http(struct lws *wsi, enum lws_callback_reasons reason, + void *user, void *in, size_t len) +{ + struct pss *pss = (struct pss *)user; + + switch (reason) { + + /* because we are protocols[0] ... */ + case LWS_CALLBACK_CLIENT_CONNECTION_ERROR: + lwsl_err("CLIENT_CONNECTION_ERROR: %s\n", + in ? (char *)in : "(null)"); + interrupted = 1; + break; + + case LWS_CALLBACK_ESTABLISHED_CLIENT_HTTP: + { + char buf[128]; + + lws_get_peer_simple(wsi, buf, sizeof(buf)); + status = lws_http_client_http_response(wsi); + + lwsl_user("Connected to %s, http response: %d\n", + buf, status); + } + pss->wsi = wsi; + lws_sul_schedule(lws_get_context(wsi), 0, &pss->sul, drain_cb, + 250 * LWS_US_PER_MS); + break; + + /* chunks of chunked content, with header removed */ + case LWS_CALLBACK_RECEIVE_CLIENT_HTTP_READ: + lwsl_user("RECEIVE_CLIENT_HTTP_READ: read %d\n", (int)len); + +#if 0 /* enable to dump the html */ + { + const char *p = in; + + while (len--) + if (*p < 0x7f) + putchar(*p++); + else + putchar('.'); + } +#endif + return 0; /* don't passthru */ + + /* uninterpreted http content */ + case LWS_CALLBACK_RECEIVE_CLIENT_HTTP: + { + char buffer[1024 + LWS_PRE]; + char *px = buffer + LWS_PRE; + int lenx = sizeof(buffer) - LWS_PRE; + + if (lws_http_client_read(wsi, &px, &lenx) < 0) + return -1; + } + return 0; /* don't passthru */ + + case LWS_CALLBACK_COMPLETED_CLIENT_HTTP: + lwsl_user("LWS_CALLBACK_COMPLETED_CLIENT_HTTP\n"); + interrupted = 1; + bad = status != 200; + lws_cancel_service(lws_get_context(wsi)); /* abort poll wait */ + break; + + case LWS_CALLBACK_CLOSED_CLIENT_HTTP: + interrupted = 1; + bad = status != 200; + lws_sul_cancel(&pss->sul); + lws_cancel_service(lws_get_context(wsi)); /* abort poll wait */ + break; + + default: + break; + } + + return lws_callback_http_dummy(wsi, reason, user, in, len); +} + +static const struct lws_protocols protocols[] = { + { + "http", + callback_http, + sizeof(struct pss), + 0, + }, + { NULL, NULL, 0, 0 } +}; + +static void +sigint_handler(int sig) +{ + interrupted = 1; +} + +struct args { + int argc; + const char **argv; +}; + +static int +system_notify_cb(lws_state_manager_t *mgr, lws_state_notify_link_t *link, + int current, int target) +{ + struct lws_context *context = mgr->parent; + struct lws_client_connect_info i; + struct args *a = lws_context_user(context); + const char *p; + + if (current != LWS_SYSTATE_OPERATIONAL || target != LWS_SYSTATE_OPERATIONAL) + return 0; + + lwsl_info("%s: operational\n", __func__); + + memset(&i, 0, sizeof i); /* otherwise uninitialized garbage */ + i.context = context; + if (!lws_cmdline_option(a->argc, a->argv, "-n")) + i.ssl_connection = LCCSCF_USE_SSL; + + if (lws_cmdline_option(a->argc, a->argv, "-l")) { + i.port = 7681; + i.address = "localhost"; + i.ssl_connection |= LCCSCF_ALLOW_SELFSIGNED; + } else { + i.port = 443; + i.address = "warmcat.com"; + } + + if (lws_cmdline_option(a->argc, a->argv, "--nossl")) + i.ssl_connection = 0; + + i.ssl_connection |= LCCSCF_H2_QUIRK_OVERFLOWS_TXCR | + LCCSCF_H2_QUIRK_NGHTTP2_END_STREAM; + + i.alpn = "h2"; + if (lws_cmdline_option(a->argc, a->argv, "--h1")) + i.alpn = "http/1.1"; + + if ((p = lws_cmdline_option(a->argc, a->argv, "-p"))) + i.port = atoi(p); + + if (lws_cmdline_option(a->argc, a->argv, "-j")) + i.ssl_connection |= LCCSCF_ALLOW_SELFSIGNED; + + if (lws_cmdline_option(a->argc, a->argv, "-k")) + i.ssl_connection |= LCCSCF_ALLOW_INSECURE; + + if (lws_cmdline_option(a->argc, a->argv, "-m")) + i.ssl_connection |= LCCSCF_SKIP_SERVER_CERT_HOSTNAME_CHECK; + + if (lws_cmdline_option(a->argc, a->argv, "-e")) + i.ssl_connection |= LCCSCF_ALLOW_EXPIRED; + + if ((p = lws_cmdline_option(a->argc, a->argv, "-f"))) { + i.ssl_connection |= LCCSCF_H2_MANUAL_RXFLOW; + i.manual_initial_tx_credit = atoi(p); + lwsl_notice("%s: manual peer tx credit %d\n", __func__, + i.manual_initial_tx_credit); + } + + if ((p = lws_cmdline_option(a->argc, a->argv, "--each"))) + each = atoi(p); + + /* the default validity check is 5m / 5m10s... -v = 3s / 10s */ + + if (lws_cmdline_option(a->argc, a->argv, "-v")) + i.retry_and_idle_policy = &retry; + + if ((p = lws_cmdline_option(a->argc, a->argv, "--server"))) + i.address = p; + + if ((p = lws_cmdline_option(a->argc, a->argv, "--path"))) + i.path = p; + else + i.path = "/"; + + i.host = i.address; + i.origin = i.address; + i.method = "GET"; + + i.protocol = protocols[0].name; + i.pwsi = &client_wsi; + + return !lws_client_connect_via_info(&i); +} + +int main(int argc, const char **argv) +{ + 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; + struct args args; + int n = 0; + // uint8_t memcert[4096]; + + args.argc = argc; + args.argv = argv; + + signal(SIGINT, sigint_handler); + + memset(&info, 0, sizeof info); /* otherwise uninitialized garbage */ + lws_cmdline_option_handle_builtin(argc, argv, &info); + + lwsl_user("LWS minimal http client [-d] [-l] [--h1]\n"); + + info.options = LWS_SERVER_OPTION_DO_SSL_GLOBAL_INIT; + info.port = CONTEXT_PORT_NO_LISTEN; /* we do not run any server */ + info.protocols = protocols; + info.user = &args; + info.register_notifier_list = na; + info.timeout_secs = 10; + info.connect_timeout_secs = 30; + + /* + * since we know this lws context is only ever going to be used with + * one client wsis / fds / sockets at a time, let lws know it doesn't + * have to use the default allocations for fd tables up to ulimit -n. + * It will just allocate for 1 internal and 1 (+ 1 http2 nwsi) that we + * will use. + */ + info.fd_limit_per_thread = 1 + 1 + 1; + +#if defined(LWS_WITH_MBEDTLS) || defined(USE_WOLFSSL) + /* + * OpenSSL uses the system trust store. mbedTLS has to be told which + * CA to trust explicitly. + */ + info.client_ssl_ca_filepath = "./warmcat.com.cer"; +#endif +#if 0 + n = open("./warmcat.com.cer", O_RDONLY); + if (n >= 0) { + info.client_ssl_ca_mem_len = read(n, memcert, sizeof(memcert)); + info.client_ssl_ca_mem = memcert; + close(n); + n = 0; + memcert[info.client_ssl_ca_mem_len++] = '\0'; + } +#endif + context = lws_create_context(&info); + if (!context) { + lwsl_err("lws init failed\n"); + return 1; + } + + while (n >= 0 && !interrupted) + n = lws_service(context, 0); + + lws_context_destroy(context); + lwsl_user("Completed: %s\n", bad ? "failed" : "OK"); + + return bad; +} diff -Nru libwebsockets-3.2.1/minimal-examples/http-client/minimal-http-client-h2-rxflow/README.md libwebsockets-4.1.6/minimal-examples/http-client/minimal-http-client-h2-rxflow/README.md --- libwebsockets-3.2.1/minimal-examples/http-client/minimal-http-client-h2-rxflow/README.md 1970-01-01 00:00:00.000000000 +0000 +++ libwebsockets-4.1.6/minimal-examples/http-client/minimal-http-client-h2-rxflow/README.md 2020-12-01 17:40:26.000000000 +0000 @@ -0,0 +1,53 @@ +# lws minimal http client-h2-rxflow + +The application reads from a server with tightly controlled and rate-limited +receive flow control using h2 tx credit. + +## build + +``` + $ cmake . && make +``` + +## usage + +Commandline option|Meaning +---|--- +-d |Debug verbosity in decimal, eg, -d15 +-l| Connect to https://localhost:7681 and accept selfsigned cert +--server |set server name to connect to +--path |URL path to access on server +-k|Apply tls option LCCSCF_ALLOW_INSECURE +-j|Apply tls option LCCSCF_ALLOW_SELFSIGNED +-m|Apply tls option LCCSCF_SKIP_SERVER_CERT_HOSTNAME_CHECK +-e|Apply tls option LCCSCF_ALLOW_EXPIRED +-v|Connection validity use 3s / 10s instead of default 5m / 5m10s +--nossl| disable ssl connection +-f |Indicate we will manually manage tx credit and set a new connection-specific initial tx credit + +RX is constrained to 1024 bytes every 250ms + +``` + $ ./lws-minimal-http-client-h2-rxflow --server phys.org --path "/" -f 1024 +[2019/12/26 13:32:59:6801] U: LWS minimal http client [-d] [-l] [--h1] +[2019/12/26 13:33:00:5087] N: system_notify_cb: manual peer tx credit 1024 +[2019/12/26 13:33:01:7390] U: Connected to 72.251.236.55, http response: 200 +[2019/12/26 13:33:01:7441] U: RECEIVE_CLIENT_HTTP_READ: read 1024 +[2019/12/26 13:33:01:0855] U: RECEIVE_CLIENT_HTTP_READ: read 1024 +[2019/12/26 13:33:02:3367] U: RECEIVE_CLIENT_HTTP_READ: read 1024 +[2019/12/26 13:33:02:5858] U: RECEIVE_CLIENT_HTTP_READ: read 1024 +[2019/12/26 13:33:02:8384] U: RECEIVE_CLIENT_HTTP_READ: read 1024 +[2019/12/26 13:33:02:0886] U: RECEIVE_CLIENT_HTTP_READ: read 1024 +... +[2019/12/26 13:33:46:1152] U: RECEIVE_CLIENT_HTTP_READ: read 1024 +[2019/12/26 13:33:47:3650] U: RECEIVE_CLIENT_HTTP_READ: read 1024 +[2019/12/26 13:33:47:6150] U: RECEIVE_CLIENT_HTTP_READ: read 1024 +[2019/12/26 13:33:47:8666] U: RECEIVE_CLIENT_HTTP_READ: read 1024 +[2019/12/26 13:33:47:1154] U: RECEIVE_CLIENT_HTTP_READ: read 1024 +[2019/12/26 13:33:48:3656] U: RECEIVE_CLIENT_HTTP_READ: read 1024 +[2019/12/26 13:33:48:6157] U: RECEIVE_CLIENT_HTTP_READ: read 380 +[2019/12/26 13:33:48:6219] U: LWS_CALLBACK_COMPLETED_CLIENT_HTTP +[2019/12/26 13:33:48:7050] U: Completed: OK + +``` + diff -Nru libwebsockets-3.2.1/minimal-examples/http-client/minimal-http-client-h2-rxflow/warmcat.com.cer libwebsockets-4.1.6/minimal-examples/http-client/minimal-http-client-h2-rxflow/warmcat.com.cer --- libwebsockets-3.2.1/minimal-examples/http-client/minimal-http-client-h2-rxflow/warmcat.com.cer 1970-01-01 00:00:00.000000000 +0000 +++ libwebsockets-4.1.6/minimal-examples/http-client/minimal-http-client-h2-rxflow/warmcat.com.cer 2020-12-01 17:40:26.000000000 +0000 @@ -0,0 +1,78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aR7LHH62+FLkHX/xBVghYkQMA0GCSqG +SIb3DQEBBQUAA4IBAQCjGiybFwBcqR7uKGY3Or+Dxz9LwwmglSBd49lZRNI+DT69 +ikugdB/OEIKcdBodfpga3csTS7MgROSR6cz8faXbauX+5v3gTt23ADq1cEmv8uXr +AvHRAosZy5Q6XkjEGB5YGV8eAlrwDPGxrancWYaLbumR9YbK+rlmM6pZW87ipxZz +R8srzJmwN0jP41ZL9c8PDHIyh8bwRLtTcm1D9SZImlJnt1ir/md2cXjbDaJWFBM5 +JDGFoqgCWjBH4d1QB7wCCZAA62RjYJsWvIjJEubSfZGL+T0yjWW06XyxV3bqxbYo +Ob8VZRzI9neWagqNdwvYkQsEjgfbKbYK7p2CNTUQ +-----END CERTIFICATE----- diff -Nru libwebsockets-3.2.1/minimal-examples/http-client/minimal-http-client-hugeurl/CMakeLists.txt libwebsockets-4.1.6/minimal-examples/http-client/minimal-http-client-hugeurl/CMakeLists.txt --- libwebsockets-3.2.1/minimal-examples/http-client/minimal-http-client-hugeurl/CMakeLists.txt 2019-12-18 14:45:31.000000000 +0000 +++ libwebsockets-4.1.6/minimal-examples/http-client/minimal-http-client-hugeurl/CMakeLists.txt 2020-12-01 17:40:26.000000000 +0000 @@ -1,78 +1,35 @@ +project(lws-minimal-http-client-hugeurl C) cmake_minimum_required(VERSION 2.8) +find_package(libwebsockets CONFIG REQUIRED) +list(APPEND CMAKE_MODULE_PATH ${LWS_CMAKE_DIR}) include(CheckCSourceCompiles) +include(LwsCheckRequirements) set(SAMP lws-minimal-http-client-hugeurl) set(SRCS minimal-http-client-hugeurl.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_ROLE_H1 1 requirements) -require_lws_config(LWS_WITHOUT_CLIENT 0 requirements) +require_lws_config(LWS_WITH_CLIENT 1 requirements) if (requirements) add_executable(${SAMP} ${SRCS}) + if (LWS_CTEST_INTERNET_AVAILABLE) + add_test(NAME http-client-hugeurl-warmcat COMMAND lws-minimal-http-client-hugeurl --ignore-sigterm) + add_test(NAME http-client-hugeurl-warmcat-h1 COMMAND lws-minimal-http-client-hugeurl --ignore-sigterm --h1) + set_tests_properties(http-client-hugeurl-warmcat + http-client-hugeurl-warmcat-h1 + PROPERTIES + WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}/minimal-examples/http-client/minimal-http-client-hugeurl + TIMEOUT 20) + + endif() + if (websockets_shared) - target_link_libraries(${SAMP} websockets_shared) + target_link_libraries(${SAMP} websockets_shared ${LIBWEBSOCKETS_DEP_LIBS}) add_dependencies(${SAMP} websockets_shared) else() - target_link_libraries(${SAMP} websockets) + target_link_libraries(${SAMP} websockets ${LIBWEBSOCKETS_DEP_LIBS}) endif() endif() diff -Nru libwebsockets-3.2.1/minimal-examples/http-client/minimal-http-client-hugeurl/minimal-http-client-hugeurl.c libwebsockets-4.1.6/minimal-examples/http-client/minimal-http-client-hugeurl/minimal-http-client-hugeurl.c --- libwebsockets-3.2.1/minimal-examples/http-client/minimal-http-client-hugeurl/minimal-http-client-hugeurl.c 2019-12-18 14:45:31.000000000 +0000 +++ libwebsockets-4.1.6/minimal-examples/http-client/minimal-http-client-hugeurl/minimal-http-client-hugeurl.c 2020-12-01 17:40:26.000000000 +0000 @@ -149,26 +149,21 @@ struct lws_context_creation_info info; struct lws_client_connect_info i; struct lws_context *context; - const char *p; - int n = 0, logs = LLL_USER | LLL_ERR | LLL_WARN | LLL_NOTICE - /* for LLL_ verbosity above NOTICE to be built into lws, - * lws must have been configured and built with - * -DCMAKE_BUILD_TYPE=DEBUG instead of =RELEASE */ - /* | LLL_INFO */ /* | LLL_PARSER */ /* | LLL_HEADER */ - /* | LLL_EXT */ /* | LLL_CLIENT */ /* | LLL_LATENCY */ - /* | LLL_DEBUG */; - - if ((p = lws_cmdline_option(argc, argv, "-d"))) - logs = atoi(p); + int n = 0; signal(SIGINT, sigint_handler); - lws_set_log_level(logs, NULL); - lwsl_user("LWS minimal http client hugeurl [-d ] [-l] [--h1]\n"); memset(&info, 0, sizeof info); /* otherwise uninitialized garbage */ + lws_cmdline_option_handle_builtin(argc, argv, &info); + + lwsl_user("LWS minimal http client hugeurl [-d ] [-l] [--h1]\n"); + info.options = LWS_SERVER_OPTION_DO_SSL_GLOBAL_INIT; info.port = CONTEXT_PORT_NO_LISTEN; /* we do not run any server */ info.protocols = protocols; + info.pt_serv_buf_size = 8192; + info.timeout_secs = 10; + info.connect_timeout_secs = 30; /* * since we know this lws context is only ever going to be used with * one client wsis / fds / sockets at a time, let lws know it doesn't @@ -178,7 +173,7 @@ */ info.fd_limit_per_thread = 1 + 1 + 1; -#if defined(LWS_WITH_MBEDTLS) +#if defined(LWS_WITH_MBEDTLS) || defined(USE_WOLFSSL) /* * OpenSSL uses the system trust store. mbedTLS has to be told which * CA to trust explicitly. diff -Nru libwebsockets-3.2.1/minimal-examples/http-client/minimal-http-client-hugeurl/selftest.sh libwebsockets-4.1.6/minimal-examples/http-client/minimal-http-client-hugeurl/selftest.sh --- libwebsockets-3.2.1/minimal-examples/http-client/minimal-http-client-hugeurl/selftest.sh 2019-12-18 14:45:31.000000000 +0000 +++ libwebsockets-4.1.6/minimal-examples/http-client/minimal-http-client-hugeurl/selftest.sh 1970-01-01 00:00:00.000000000 +0000 @@ -1,47 +0,0 @@ -#!/bin/bash -# -# $1: path to minimal example binaries... -# if lws is built with -DLWS_WITH_MINIMAL_EXAMPLES=1 -# that will be ./bin from your build dir -# -# $2: path for logs and results. The results will go -# in a subdir named after the directory this script -# is in -# -# $3: offset for test index count -# -# $4: total test count -# -# $5: path to ./minimal-examples dir in lws -# -# Test return code 0: OK, 254: timed out, other: error indication - -. $5/selftests-library.sh - -COUNT_TESTS=6 - -dotest $1 $2 warmcat -dotest $1 $2 warmcat-h1 --h1 - -spawn "" $5/http-server/minimal-http-server-tls $1/lws-minimal-http-server-tls -dotest $1 $2 localhost -l -spawn $SPID $5/http-server/minimal-http-server-tls $1/lws-minimal-http-server-tls -dotest $1 $2 localhost-h1 -l --h1 -kill $SPID 2>/dev/null -wait $SPID 2>/dev/null - - -if [ -z "$TRAVIS_OS_NAME" ] ; then - SPID="" - spawn "" $5/http-server/minimal-http-server-eventlib $1/lws-minimal-http-server-eventlib --uv -s - dotest $1 $2 localhost-suv -l - spawn $SPID $5/http-server/minimal-http-server-eventlib $1/lws-minimal-http-server-eventlib --uv -s - dotest $1 $2 localhost-suv-h1 -l --h1 - - kill $SPID 2>/dev/null - wait $SPID 2>/dev/null -fi - -exit $FAILS - - diff -Nru libwebsockets-3.2.1/minimal-examples/http-client/minimal-http-client-hugeurl/warmcat.com.cer libwebsockets-4.1.6/minimal-examples/http-client/minimal-http-client-hugeurl/warmcat.com.cer --- libwebsockets-3.2.1/minimal-examples/http-client/minimal-http-client-hugeurl/warmcat.com.cer 2019-12-18 14:45:31.000000000 +0000 +++ libwebsockets-4.1.6/minimal-examples/http-client/minimal-http-client-hugeurl/warmcat.com.cer 2020-12-01 17:40:26.000000000 +0000 @@ -56,3 +56,23 @@ PfZ+G6Z6h7mjem0Y+iWlkYcV4PIWL1iwBi8saCbGS5jN2p8M+X+Q7UNKEkROb3N6 KOqkqm57TH2H3eDJAkSnh6/DNFu0Qg== -----END CERTIFICATE----- +-----BEGIN CERTIFICATE----- +MIIDSjCCAjKgAwIBAgIQRK+wgNajJ7qJMDmGLvhAazANBgkqhkiG9w0BAQUFADA/ +MSQwIgYDVQQKExtEaWdpdGFsIFNpZ25hdHVyZSBUcnVzdCBDby4xFzAVBgNVBAMT +DkRTVCBSb290IENBIFgzMB4XDTAwMDkzMDIxMTIxOVoXDTIxMDkzMDE0MDExNVow +PzEkMCIGA1UEChMbRGlnaXRhbCBTaWduYXR1cmUgVHJ1c3QgQ28uMRcwFQYDVQQD +Ew5EU1QgUm9vdCBDQSBYMzCCASIwDQYJKoZIhvcNAQEBBQADggEPADCCAQoCggEB +AN+v6ZdQCINXtMxiZfaQguzH0yxrMMpb7NnDfcdAwRgUi+DoM3ZJKuM/IUmTrE4O +rz5Iy2Xu/NMhD2XSKtkyj4zl93ewEnu1lcCJo6m67XMuegwGMoOifooUMM0RoOEq +OLl5CjH9UL2AZd+3UWODyOKIYepLYYHsUmu5ouJLGiifSKOeDNoJjj4XLh7dIN9b +xiqKqy69cK3FCxolkHRyxXtqqzTWMIn/5WgTe1QLyNau7Fqckh49ZLOMxt+/yUFw +7BZy1SbsOFU5Q9D8/RhcQPGX69Wam40dutolucbY38EVAjqr2m7xPi71XAicPNaD +aeQQmxkqtilX4+U9m5/wAl0CAwEAAaNCMEAwDwYDVR0TAQH/BAUwAwEB/zAOBgNV +HQ8BAf8EBAMCAQYwHQYDVR0OBBYEFMSnsaR7LHH62+FLkHX/xBVghYkQMA0GCSqG +SIb3DQEBBQUAA4IBAQCjGiybFwBcqR7uKGY3Or+Dxz9LwwmglSBd49lZRNI+DT69 +ikugdB/OEIKcdBodfpga3csTS7MgROSR6cz8faXbauX+5v3gTt23ADq1cEmv8uXr +AvHRAosZy5Q6XkjEGB5YGV8eAlrwDPGxrancWYaLbumR9YbK+rlmM6pZW87ipxZz +R8srzJmwN0jP41ZL9c8PDHIyh8bwRLtTcm1D9SZImlJnt1ir/md2cXjbDaJWFBM5 +JDGFoqgCWjBH4d1QB7wCCZAA62RjYJsWvIjJEubSfZGL+T0yjWW06XyxV3bqxbYo +Ob8VZRzI9neWagqNdwvYkQsEjgfbKbYK7p2CNTUQ +-----END CERTIFICATE----- diff -Nru libwebsockets-3.2.1/minimal-examples/http-client/minimal-http-client-multi/CMakeLists.txt libwebsockets-4.1.6/minimal-examples/http-client/minimal-http-client-multi/CMakeLists.txt --- libwebsockets-3.2.1/minimal-examples/http-client/minimal-http-client-multi/CMakeLists.txt 2019-12-18 14:45:31.000000000 +0000 +++ libwebsockets-4.1.6/minimal-examples/http-client/minimal-http-client-multi/CMakeLists.txt 2020-12-01 17:40:26.000000000 +0000 @@ -1,79 +1,174 @@ +project(lws-minimal-http-client-multi C) cmake_minimum_required(VERSION 2.8) +find_package(libwebsockets CONFIG REQUIRED) +list(APPEND CMAKE_MODULE_PATH ${LWS_CMAKE_DIR}) include(CheckCSourceCompiles) +include(LwsCheckRequirements) set(SAMP lws-minimal-http-client-multi) set(SRCS minimal-http-client-multi.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_ROLE_H1 1 requirements) -require_lws_config(LWS_WITHOUT_CLIENT 0 requirements) +require_lws_config(LWS_WITH_CLIENT 1 requirements) +require_lws_config(LWS_WITH_TLS 1 requirements) + if (requirements) add_executable(${SAMP} ${SRCS}) + + # + # instantiate the server per sai builder instance, they are running in the same + # machine context in parallel so they can tread on each other otherwise + # + set(PORT_HCM_SRV "7670") + if ("$ENV{SAI_INSTANCE_IDX}" STREQUAL "0") + set(PORT_HCM_SRV 7671) + endif() + if ("$ENV{SAI_INSTANCE_IDX}" STREQUAL "1") + set(PORT_HCM_SRV 7672) + endif() + if ("$ENV{SAI_INSTANCE_IDX}" STREQUAL "2") + set(PORT_HCM_SRV 7673) + endif() + if ("$ENV{SAI_INSTANCE_IDX}" STREQUAL "3") + set(PORT_HCM_SRV 7674) + endif() + + +# hack +if (NOT WIN32 AND LWS_WITH_SERVER) + + # + # Tests against built server running locally (needs daemonization...) + # + +if (WIN32) + add_test(NAME st_hcm_srv COMMAND cmd.exe /c start /b $ --port ${PORT_HCM_SRV}) + add_test(NAME ki_hcm_srv COMMAND taskkill /F /IM $ /T) + add_test(NAME st_hcmp_srv COMMAND cmd.exe /c start /b $ -s --port 1${PORT_HCM_SRV}) + add_test(NAME ki_hcmp_srv COMMAND taskkill /F /IM $ /T) +else() + add_test(NAME st_hcm_srv COMMAND + ${CMAKE_SOURCE_DIR}/scripts/ctest-background.sh + hcm_srv $ + --port ${PORT_HCM_SRV} --ignore-sigterm) + add_test(NAME ki_hcm_srv COMMAND + ${CMAKE_SOURCE_DIR}/scripts/ctest-background-kill.sh + hcm_srv $ + --port ${PORT_HCM_SRV}) + add_test(NAME st_hcmp_srv COMMAND + ${CMAKE_SOURCE_DIR}/scripts/ctest-background.sh + hcmp_srv $ -s + -r ${CMAKE_SOURCE_DIR}/destdir/usr/local/share/libwebsockets-test-server/ + --port 1${PORT_HCM_SRV} --ignore-sigterm) + add_test(NAME ki_hcmp_srv COMMAND + ${CMAKE_SOURCE_DIR}/scripts/ctest-background-kill.sh + hcmp_srv $ + --port 1${PORT_HCM_SRV}) +endif() + + set_tests_properties(st_hcm_srv PROPERTIES + WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}/minimal-examples/http-server/minimal-http-server-tls + FIXTURES_SETUP hcm_srv + TIMEOUT 800) + set_tests_properties(ki_hcm_srv PROPERTIES + FIXTURES_CLEANUP hcm_srv) + + set_tests_properties(st_hcmp_srv PROPERTIES + WORKING_DIRECTORY . + FIXTURES_SETUP hcmp_srv + TIMEOUT 800) + set_tests_properties(ki_hcmp_srv PROPERTIES + FIXTURES_CLEANUP hcmp_srv) + + # + # Tests against local server peer + # + + add_test(NAME http-client-multi COMMAND lws-minimal-http-client-multi + -l --port ${PORT_HCM_SRV}) + add_test(NAME http-client-multi-h1 COMMAND lws-minimal-http-client-multi + --h1 -l --port ${PORT_HCM_SRV}) + add_test(NAME http-client-multi-pipe COMMAND lws-minimal-http-client-multi + -p -l --port ${PORT_HCM_SRV}) + add_test(NAME http-client-multi-h1-pipe COMMAND lws-minimal-http-client-multi + --h1 -p -l --port ${PORT_HCM_SRV}) + add_test(NAME http-client-multi-stag COMMAND lws-minimal-http-client-multi + -s -l --port ${PORT_HCM_SRV}) + add_test(NAME http-client-multi-stag-h1 COMMAND lws-minimal-http-client-multi + --h1 -s -l --port ${PORT_HCM_SRV}) + add_test(NAME http-client-multi-stag-pipe COMMAND lws-minimal-http-client-multi + -p -s -l --port ${PORT_HCM_SRV}) + add_test(NAME http-client-multi-stag-h1-pipe COMMAND lws-minimal-http-client-multi + --h1 -p -s -l --port ${PORT_HCM_SRV}) + + # confirm that the pipelined mode really is doing it in one connection + add_test(NAME http-client-multi-restrict-pipe COMMAND lws-minimal-http-client-multi -d1151 --limit 1 -p -l --port ${PORT_HCM_SRV}) + add_test(NAME http-client-multi-restrict-h1-pipe COMMAND lws-minimal-http-client-multi -d1151 --limit 1 --h1 -p -l --port ${PORT_HCM_SRV}) + add_test(NAME http-client-multi-restrict-stag-pipe COMMAND lws-minimal-http-client-multi -d1151 --limit 1 -p -s -l --port ${PORT_HCM_SRV}) + add_test(NAME http-client-multi-restrict-stag-h1-pipe COMMAND lws-minimal-http-client-multi -d1151 --limit 1 --h1 -p -s -l --port ${PORT_HCM_SRV}) + # confirm that we do fail with a one connection limit and no pipelining + add_test(NAME http-client-multi-restrict-nopipe-fail COMMAND lws-minimal-http-client-multi --limit 1 -l --port ${PORT_HCM_SRV}) + set_property(TEST http-client-multi-restrict-nopipe-fail PROPERTY WILL_FAIL TRUE) + add_test(NAME http-client-multi-restrict-h1-nopipe-fail COMMAND lws-minimal-http-client-multi --limit 1 --h1 -l --port ${PORT_HCM_SRV}) + set_property(TEST http-client-multi-restrict-h1-nopipe-fail PROPERTY WILL_FAIL TRUE) + + set_tests_properties(http-client-multi-restrict-pipe + http-client-multi-restrict-h1-pipe + http-client-multi-restrict-stag-pipe + http-client-multi-restrict-stag-h1-pipe + http-client-multi-restrict-nopipe-fail + http-client-multi-restrict-h1-nopipe-fail + http-client-multi + http-client-multi-h1 + http-client-multi-pipe + http-client-multi-h1-pipe + http-client-multi-stag + http-client-multi-stag-h1 + http-client-multi-stag-pipe + http-client-multi-stag-h1-pipe + PROPERTIES + FIXTURES_REQUIRED "hcm_srv" + WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}/minimal-examples/http-client/minimal-http-client-multi + TIMEOUT 20) + + # POSTs against local http-server-form-post + add_test(NAME http-client-multi-post COMMAND lws-minimal-http-client-multi + --post -l --port 1${PORT_HCM_SRV}) + add_test(NAME http-client-multi-post-h1 COMMAND lws-minimal-http-client-multi + --post --h1 -l --port 1${PORT_HCM_SRV}) + add_test(NAME http-client-multi-post-pipe COMMAND lws-minimal-http-client-multi + --post -p -l --port 1${PORT_HCM_SRV}) + add_test(NAME http-client-multi-post-h1-pipe COMMAND lws-minimal-http-client-multi + --post --h1 -p -l --port 1${PORT_HCM_SRV}) + add_test(NAME http-client-multi-post-stag COMMAND lws-minimal-http-client-multi + --post -s -l -d1151 --port 1${PORT_HCM_SRV}) + add_test(NAME http-client-multi-post-stag-h1 COMMAND lws-minimal-http-client-multi + --post --h1 -d1151 -s -l --port 1${PORT_HCM_SRV}) + add_test(NAME http-client-multi-post-stag-pipe COMMAND lws-minimal-http-client-multi + --post -p -s -l --port 1${PORT_HCM_SRV}) + add_test(NAME http-client-multi-post-stag-h1-pipe COMMAND lws-minimal-http-client-multi + --post --h1 -p -s -l --port 1${PORT_HCM_SRV}) + set_tests_properties(http-client-multi-post + http-client-multi-post-h1 + http-client-multi-post-pipe + http-client-multi-post-h1-pipe + http-client-multi-post-stag + http-client-multi-post-stag-h1 + http-client-multi-post-stag-pipe + http-client-multi-post-stag-h1-pipe + PROPERTIES + FIXTURES_REQUIRED "hcmp_srv" + WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}/minimal-examples/http-client/minimal-http-client-multi + TIMEOUT 20) + +endif(NOT WIN32 AND LWS_WITH_SERVER) if (websockets_shared) - target_link_libraries(${SAMP} websockets_shared) + target_link_libraries(${SAMP} websockets_shared ${LIBWEBSOCKETS_DEP_LIBS}) add_dependencies(${SAMP} websockets_shared) else() - target_link_libraries(${SAMP} websockets) + target_link_libraries(${SAMP} websockets ${LIBWEBSOCKETS_DEP_LIBS}) endif() endif() diff -Nru libwebsockets-3.2.1/minimal-examples/http-client/minimal-http-client-multi/minimal-http-client-multi.c libwebsockets-4.1.6/minimal-examples/http-client/minimal-http-client-multi/minimal-http-client-multi.c --- libwebsockets-3.2.1/minimal-examples/http-client/minimal-http-client-multi/minimal-http-client-multi.c 2019-12-18 14:45:31.000000000 +0000 +++ libwebsockets-4.1.6/minimal-examples/http-client/minimal-http-client-multi/minimal-http-client-multi.c 2020-12-01 17:40:26.000000000 +0000 @@ -1,7 +1,7 @@ /* * lws-minimal-http-client-multi * - * Written in 2010-2019 by Andy Green + * Written in 2010-2020 by Andy Green * * This file is made available under the Creative Commons CC0 1.0 * Universal Public Domain Dedication. @@ -36,59 +36,65 @@ #define COUNT 8 -struct user { +struct cliuser { int index; }; -static int interrupted, completed, failed, numbered, stagger_idx; -static struct lws *client_wsi[COUNT]; -static struct user user[COUNT]; +static int completed, failed, numbered, stagger_idx, posting, count = COUNT; static lws_sorted_usec_list_t sul_stagger; static struct lws_client_connect_info i; -struct lws_context *context; +static struct lws *client_wsi[COUNT]; +static char urlpath[64], intr; +static struct lws_context *context; + +/* we only need this for tracking POST emit state */ + +struct pss { + char body_part; +}; static int callback_http(struct lws *wsi, enum lws_callback_reasons reason, void *user, void *in, size_t len) { - struct user *u = (struct user *)user; + char buf[LWS_PRE + 1024], *start = &buf[LWS_PRE], *p = start, + *end = &buf[sizeof(buf) - LWS_PRE - 1]; + int n, idx = (int)(intptr_t)lws_get_opaque_user_data(wsi); + struct pss *pss = (struct pss *)user; switch (reason) { case LWS_CALLBACK_ESTABLISHED_CLIENT_HTTP: - lwsl_user("LWS_CALLBACK_ESTABLISHED_CLIENT_HTTP: resp %u\n", - lws_http_client_http_response(wsi)); + lwsl_user("LWS_CALLBACK_ESTABLISHED_CLIENT_HTTP: idx: %d, resp %u\n", + idx, lws_http_client_http_response(wsi)); break; /* because we are protocols[0] ... */ case LWS_CALLBACK_CLIENT_CONNECTION_ERROR: lwsl_err("CLIENT_CONNECTION_ERROR: %s\n", in ? (char *)in : "(null)"); - client_wsi[u->index] = NULL; + client_wsi[idx] = NULL; failed++; - if (++completed == COUNT) { - lwsl_err("Done: failed: %d\n", failed); - interrupted = 1; - } - break; + goto finished; /* chunks of chunked content, with header removed */ case LWS_CALLBACK_RECEIVE_CLIENT_HTTP_READ: - lwsl_user("RECEIVE_CLIENT_HTTP_READ: conn %d: read %d\n", - u->index, (int)len); -#if 0 /* enable to dump the html */ - { - const char *p = in; - - while (len--) - if (*p < 0x7f) - putchar(*p++); - else - putchar('.'); - } -#endif + lwsl_user("RECEIVE_CLIENT_HTTP_READ: conn %d: read %d\n", idx, (int)len); + lwsl_hexdump_info(in, len); return 0; /* don't passthru */ + case LWS_CALLBACK_CLIENT_APPEND_HANDSHAKE_HEADER: + /* + * Tell lws we are going to send the body next... + */ + if (posting && !lws_http_is_redirected_to_get(wsi)) { + lwsl_user("%s: doing POST flow\n", __func__); + lws_client_http_body_pending(wsi, 1); + lws_callback_on_writable(wsi); + } else + lwsl_user("%s: doing GET flow\n", __func__); + break; + /* uninterpreted http content */ case LWS_CALLBACK_RECEIVE_CLIENT_HTTP: { @@ -103,33 +109,83 @@ case LWS_CALLBACK_COMPLETED_CLIENT_HTTP: lwsl_user("LWS_CALLBACK_COMPLETED_CLIENT_HTTP %p: idx %d\n", - wsi, u->index); - client_wsi[u->index] = NULL; - if (++completed == COUNT) { - if (!failed) - lwsl_user("Done: all OK\n"); - else - lwsl_err("Done: failed: %d\n", failed); - interrupted = 1; - /* so we exit immediately */ - lws_cancel_service(lws_get_context(wsi)); - } - break; + wsi, idx); + client_wsi[idx] = NULL; + goto finished; case LWS_CALLBACK_CLOSED_CLIENT_HTTP: - if (u && client_wsi[u->index]) { + lwsl_info("%s: closed: %p\n", __func__, client_wsi[idx]); + if (client_wsi[idx]) { /* * If it completed normally, it will have been set to * NULL then already. So we are dealing with an * abnormal, failing, close */ - client_wsi[u->index] = NULL; + client_wsi[idx] = NULL; failed++; - if (++completed == COUNT) { - lwsl_err("Done: failed: %d\n", failed); - interrupted = 1; - } + goto finished; + } + break; + + case LWS_CALLBACK_CLIENT_HTTP_WRITEABLE: + if (!posting) + break; + if (lws_http_is_redirected_to_get(wsi)) + break; + lwsl_info("LWS_CALLBACK_CLIENT_HTTP_WRITEABLE: %p, idx %d," + " part %d\n", wsi, idx, pss->body_part); + + n = LWS_WRITE_HTTP; + + /* + * For a small body like this, we could prepare it in memory and + * send it all at once. But to show how to handle, eg, + * arbitrary-sized file payloads, or huge form-data fields, the + * sending is done in multiple passes through the event loop. + */ + + switch (pss->body_part++) { + case 0: + if (lws_client_http_multipart(wsi, "text", NULL, NULL, + &p, end)) + return -1; + /* notice every usage of the boundary starts with -- */ + p += lws_snprintf(p, end - p, "my text field\xd\xa"); + break; + case 1: + if (lws_client_http_multipart(wsi, "file", "myfile.txt", + "text/plain", &p, end)) + return -1; + p += lws_snprintf(p, end - p, + "This is the contents of the " + "uploaded file.\xd\xa" + "\xd\xa"); + break; + case 2: + if (lws_client_http_multipart(wsi, NULL, NULL, NULL, + &p, end)) + return -1; + lws_client_http_body_pending(wsi, 0); + /* necessary to support H2, it means we will write no + * more on this stream */ + n = LWS_WRITE_HTTP_FINAL; + break; + + default: + /* + * We can get extra callbacks here, if nothing to do, + * then do nothing. + */ + return 0; } + + if (lws_write(wsi, (uint8_t *)start, lws_ptr_diff(p, start), n) + != lws_ptr_diff(p, start)) + return 1; + + if (n != LWS_WRITE_HTTP_FINAL) + lws_callback_on_writable(wsi); + break; default: @@ -137,17 +193,48 @@ } return lws_callback_http_dummy(wsi, reason, user, in, len); + +finished: + if (++completed == count) { + if (!failed) + lwsl_user("Done: all OK\n"); + else + lwsl_err("Done: failed: %d\n", failed); + intr = 1; + /* + * This is how we can exit the event loop even when it's an + * event library backing it... it will start and stage the + * destroy to happen after we exited this service for each pt + */ + lws_context_destroy(lws_get_context(wsi)); + } + + return 0; } static const struct lws_protocols protocols[] = { - { "http", callback_http, 0, 0, }, + { "http", callback_http, sizeof(struct pss), 0, }, { NULL, NULL, 0, 0 } }; static void +signal_cb(void *handle, int signum) +{ + switch (signum) { + case SIGTERM: + case SIGINT: + break; + default: + lwsl_err("%s: signal %d\n", __func__, signum); + break; + } + lws_context_destroy(context); +} + +static void sigint_handler(int sig) { - interrupted = 1; + signal_cb(NULL, sig); } #if defined(WIN32) @@ -191,17 +278,16 @@ lws_snprintf(path, sizeof(path), "/%d.png", m + 1); i->path = path; } else - i->path = "/"; + i->path = urlpath; i->pwsi = &client_wsi[m]; - user[m].index = m; - i->userdata = &user[m]; + i->opaque_user_data = (void *)(intptr_t)m; if (!lws_client_connect_via_info(i)) { failed++; - if (++completed == COUNT) { + if (++completed == count) { lwsl_user("Done: failed: %d\n", failed); - interrupted = 1; + lws_context_destroy(context); } } else lwsl_user("started connection %p: idx %d (%s)\n", @@ -220,11 +306,11 @@ */ lws_try_client_connection(&i, stagger_idx++); - if (stagger_idx == (int)LWS_ARRAY_SIZE(client_wsi)) + if (stagger_idx == count) return; next = 300 * LWS_US_PER_MS; - if (stagger_idx == (int)LWS_ARRAY_SIZE(client_wsi) - 1) + if (stagger_idx == count - 1) next += 700 * LWS_US_PER_MS; lws_sul_schedule(context, 0, &sul_stagger, stagger_cb, next); @@ -234,31 +320,37 @@ { struct lws_context_creation_info info; unsigned long long start; + int m, staggered = 0; const char *p; - int n = 0, m, staggered = 0, logs = - LLL_USER | LLL_ERR | LLL_WARN | LLL_NOTICE - /* for LLL_ verbosity above NOTICE to be built into lws, - * lws must have been configured and built with - * -DCMAKE_BUILD_TYPE=DEBUG instead of =RELEASE */ - /* | LLL_INFO */ /* | LLL_PARSER */ /* | LLL_HEADER */ - /* | LLL_EXT */ /* | LLL_CLIENT */ /* | LLL_LATENCY */ - /* | LLL_DEBUG */; - - signal(SIGINT, sigint_handler); + memset(&info, 0, sizeof info); /* otherwise uninitialized garbage */ memset(&i, 0, sizeof i); /* otherwise uninitialized garbage */ + lws_cmdline_option_handle_builtin(argc, argv, &info); + + info.signal_cb = signal_cb; + info.options = LWS_SERVER_OPTION_DO_SSL_GLOBAL_INIT; + + if (lws_cmdline_option(argc, argv, "--uv")) + info.options |= LWS_SERVER_OPTION_LIBUV; + else + if (lws_cmdline_option(argc, argv, "--event")) + info.options |= LWS_SERVER_OPTION_LIBEVENT; + else + if (lws_cmdline_option(argc, argv, "--ev")) + info.options |= LWS_SERVER_OPTION_LIBEV; + else + if (lws_cmdline_option(argc, argv, "--glib")) + info.options |= LWS_SERVER_OPTION_GLIB; + else + signal(SIGINT, sigint_handler); + staggered = !!lws_cmdline_option(argc, argv, "-s"); - if ((p = lws_cmdline_option(argc, argv, "-d"))) - logs = atoi(p); - lws_set_log_level(logs, NULL); lwsl_user("LWS minimal http client [-s (staggered)] [-p (pipeline)]\n"); lwsl_user(" [--h1 (http/1 only)] [-l (localhost)] [-d ]\n"); - lwsl_user(" [-n (numbered)]\n"); + lwsl_user(" [-n (numbered)] [--post]\n"); - memset(&info, 0, sizeof info); /* otherwise uninitialized garbage */ - info.options = LWS_SERVER_OPTION_DO_SSL_GLOBAL_INIT; info.port = CONTEXT_PORT_NO_LISTEN; /* we do not run any server */ info.protocols = protocols; /* @@ -270,7 +362,7 @@ */ info.fd_limit_per_thread = 1 + COUNT + 1; -#if defined(LWS_WITH_MBEDTLS) +#if defined(LWS_WITH_MBEDTLS) || defined(USE_WOLFSSL) /* * OpenSSL uses the system trust store. mbedTLS has to be told which * CA to trust explicitly. @@ -278,6 +370,14 @@ info.client_ssl_ca_filepath = "./warmcat.com.cer"; #endif + if ((p = lws_cmdline_option(argc, argv, "--limit"))) + info.simultaneous_ssl_restriction = atoi(p); + +#if defined(LWS_WITH_DETAILED_LATENCY) + info.detailed_latency_cb = lws_det_lat_plot_cb; + info.detailed_latency_filepath = "/tmp/lws-latency-results"; +#endif + context = lws_create_context(&info); if (!context) { lwsl_err("lws init failed\n"); @@ -285,7 +385,16 @@ } i.context = context; - i.ssl_connection = LCCSCF_USE_SSL; + i.ssl_connection = LCCSCF_USE_SSL | + LCCSCF_H2_QUIRK_OVERFLOWS_TXCR | + LCCSCF_H2_QUIRK_NGHTTP2_END_STREAM; + + if (lws_cmdline_option(argc, argv, "--post")) { + posting = 1; + i.method = "POST"; + i.ssl_connection |= LCCSCF_HTTP_MULTIPART_MIME; + } else + i.method = "GET"; /* enables h1 or h2 connection sharing */ if (lws_cmdline_option(argc, argv, "-p")) @@ -295,24 +404,42 @@ if (lws_cmdline_option(argc, argv, "--h1")) i.alpn = "http/1.1"; + strcpy(urlpath, "/"); + if (lws_cmdline_option(argc, argv, "-l")) { i.port = 7681; i.address = "localhost"; i.ssl_connection |= LCCSCF_ALLOW_SELFSIGNED; + if (posting) + strcpy(urlpath, "/formtest"); } else { i.port = 443; - i.address = "warmcat.com"; + i.address = "libwebsockets.org"; + if (posting) + strcpy(urlpath, "/testserver/formtest"); } + if (lws_cmdline_option(argc, argv, "--no-tls")) + i.ssl_connection &= ~(LCCSCF_USE_SSL); + if (lws_cmdline_option(argc, argv, "-n")) numbered = 1; + if ((p = lws_cmdline_option(argc, argv, "--server"))) + i.address = p; + if ((p = lws_cmdline_option(argc, argv, "--port"))) i.port = atoi(p); + if ((p = lws_cmdline_option(argc, argv, "--path"))) + lws_strncpy(urlpath, p, sizeof(urlpath)); + + if ((p = lws_cmdline_option(argc, argv, "-c"))) + if (atoi(p) <= COUNT && atoi(p)) + count = atoi(p); + i.host = i.address; i.origin = i.address; - i.method = "GET"; i.protocol = protocols[0].name; if (!staggered) @@ -320,7 +447,7 @@ * just pile on all the connections at once, testing the * pipeline queuing before the first is connected */ - for (m = 0; m < (int)LWS_ARRAY_SIZE(client_wsi); m++) + for (m = 0; m < count; m++) lws_try_client_connection(&i, m); else /* @@ -330,14 +457,13 @@ 100 * LWS_US_PER_MS); start = us(); - m = 0; - while (n >= 0 && !interrupted) - n = lws_service(context, 0); + while (!intr && !lws_service(context, 0)) + ; lwsl_user("Duration: %lldms\n", (us() - start) / 1000); lws_context_destroy(context); - lwsl_user("Exiting with %d\n", failed || completed != COUNT); + lwsl_user("Exiting with %d\n", failed || completed != count); - return failed || completed != COUNT; + return failed || completed != count; } diff -Nru libwebsockets-3.2.1/minimal-examples/http-client/minimal-http-client-multi/README.md libwebsockets-4.1.6/minimal-examples/http-client/minimal-http-client-multi/README.md --- libwebsockets-3.2.1/minimal-examples/http-client/minimal-http-client-multi/README.md 2019-12-18 14:45:31.000000000 +0000 +++ libwebsockets-4.1.6/minimal-examples/http-client/minimal-http-client-multi/README.md 2020-12-01 17:40:26.000000000 +0000 @@ -22,4 +22,9 @@ --h1|Force http/1 only -l|Connect to server on https://localhost:7681 instead of https://warmcat.com:443 -n|Read numbered files like /1.png, /2.png etc. Default is just read / - +--uv|Use libuv event loop if lws built for it +--event|Use libevent event loop if lws built for it +--ev|Use libev event loop if lws built for it +--post|POST to the server rather than GET +-c|Create n connections (n can be 1 .. 8) +--path |Force the URL path (should start with /) \ No newline at end of file diff -Nru libwebsockets-3.2.1/minimal-examples/http-client/minimal-http-client-multi/selftest.sh libwebsockets-4.1.6/minimal-examples/http-client/minimal-http-client-multi/selftest.sh --- libwebsockets-3.2.1/minimal-examples/http-client/minimal-http-client-multi/selftest.sh 2019-12-18 14:45:31.000000000 +0000 +++ libwebsockets-4.1.6/minimal-examples/http-client/minimal-http-client-multi/selftest.sh 1970-01-01 00:00:00.000000000 +0000 @@ -1,52 +0,0 @@ -#!/bin/bash -# -# $1: path to minimal example binaries... -# if lws is built with -DLWS_WITH_MINIMAL_EXAMPLES=1 -# that will be ./bin from your build dir -# -# $2: path for logs and results. The results will go -# in a subdir named after the directory this script -# is in -# -# $3: offset for test index count -# -# $4: total test count -# -# $5: path to ./minimal-examples dir in lws -# -# Test return code 0: OK, 254: timed out, other: error indication - -. $5/selftests-library.sh - -COUNT_TESTS=16 - -dotest $1 $2 warmcat -dotest $1 $2 warmcat-pipe -p -dotest $1 $2 warmcat-h1 --h1 -dotest $1 $2 warmcat-h1-pipe --h1 -p -dotest $1 $2 warmcat-stag -s -dotest $1 $2 warmcat-pipe-stag -p -s -dotest $1 $2 warmcat-h1-stag --h1 -s -dotest $1 $2 warmcat-h1-pipe-stag --h1 -p -s - -spawn "" $5/http-server/minimal-http-server-tls $1/lws-minimal-http-server-tls -dotest $1 $2 localhost -l -spawn $SPID $5/http-server/minimal-http-server-tls $1/lws-minimal-http-server-tls -dotest $1 $2 localhost-pipe -l -p -spawn $SPID $5/http-server/minimal-http-server-tls $1/lws-minimal-http-server-tls -dotest $1 $2 localhost-h1 -l --h1 -spawn $SPID $5/http-server/minimal-http-server-tls $1/lws-minimal-http-server-tls -dotest $1 $2 localhost-h1-pipe -l --h1 -p -spawn $SPID $5/http-server/minimal-http-server-tls $1/lws-minimal-http-server-tls -dotest $1 $2 localhost-stag -l -s -spawn $SPID $5/http-server/minimal-http-server-tls $1/lws-minimal-http-server-tls -dotest $1 $2 localhost-pipe-stag -l -p -s -spawn $SPID $5/http-server/minimal-http-server-tls $1/lws-minimal-http-server-tls -dotest $1 $2 localhost-h1-stag -l --h1 -s -spawn $SPID $5/http-server/minimal-http-server-tls $1/lws-minimal-http-server-tls -dotest $1 $2 localhost-h1-pipe-stag -l --h1 -p -s - -kill $SPID 2>/dev/null -wait $SPID 2>/dev/null -exit $FAILS - diff -Nru libwebsockets-3.2.1/minimal-examples/http-client/minimal-http-client-multi/warmcat.com.cer libwebsockets-4.1.6/minimal-examples/http-client/minimal-http-client-multi/warmcat.com.cer --- libwebsockets-3.2.1/minimal-examples/http-client/minimal-http-client-multi/warmcat.com.cer 2019-12-18 14:45:31.000000000 +0000 +++ libwebsockets-4.1.6/minimal-examples/http-client/minimal-http-client-multi/warmcat.com.cer 2020-12-01 17:40:26.000000000 +0000 @@ -56,3 +56,23 @@ PfZ+G6Z6h7mjem0Y+iWlkYcV4PIWL1iwBi8saCbGS5jN2p8M+X+Q7UNKEkROb3N6 KOqkqm57TH2H3eDJAkSnh6/DNFu0Qg== -----END CERTIFICATE----- +-----BEGIN CERTIFICATE----- +MIIDSjCCAjKgAwIBAgIQRK+wgNajJ7qJMDmGLvhAazANBgkqhkiG9w0BAQUFADA/ +MSQwIgYDVQQKExtEaWdpdGFsIFNpZ25hdHVyZSBUcnVzdCBDby4xFzAVBgNVBAMT +DkRTVCBSb290IENBIFgzMB4XDTAwMDkzMDIxMTIxOVoXDTIxMDkzMDE0MDExNVow +PzEkMCIGA1UEChMbRGlnaXRhbCBTaWduYXR1cmUgVHJ1c3QgQ28uMRcwFQYDVQQD +Ew5EU1QgUm9vdCBDQSBYMzCCASIwDQYJKoZIhvcNAQEBBQADggEPADCCAQoCggEB +AN+v6ZdQCINXtMxiZfaQguzH0yxrMMpb7NnDfcdAwRgUi+DoM3ZJKuM/IUmTrE4O +rz5Iy2Xu/NMhD2XSKtkyj4zl93ewEnu1lcCJo6m67XMuegwGMoOifooUMM0RoOEq +OLl5CjH9UL2AZd+3UWODyOKIYepLYYHsUmu5ouJLGiifSKOeDNoJjj4XLh7dIN9b +xiqKqy69cK3FCxolkHRyxXtqqzTWMIn/5WgTe1QLyNau7Fqckh49ZLOMxt+/yUFw +7BZy1SbsOFU5Q9D8/RhcQPGX69Wam40dutolucbY38EVAjqr2m7xPi71XAicPNaD +aeQQmxkqtilX4+U9m5/wAl0CAwEAAaNCMEAwDwYDVR0TAQH/BAUwAwEB/zAOBgNV +HQ8BAf8EBAMCAQYwHQYDVR0OBBYEFMSnsaR7LHH62+FLkHX/xBVghYkQMA0GCSqG +SIb3DQEBBQUAA4IBAQCjGiybFwBcqR7uKGY3Or+Dxz9LwwmglSBd49lZRNI+DT69 +ikugdB/OEIKcdBodfpga3csTS7MgROSR6cz8faXbauX+5v3gTt23ADq1cEmv8uXr +AvHRAosZy5Q6XkjEGB5YGV8eAlrwDPGxrancWYaLbumR9YbK+rlmM6pZW87ipxZz +R8srzJmwN0jP41ZL9c8PDHIyh8bwRLtTcm1D9SZImlJnt1ir/md2cXjbDaJWFBM5 +JDGFoqgCWjBH4d1QB7wCCZAA62RjYJsWvIjJEubSfZGL+T0yjWW06XyxV3bqxbYo +Ob8VZRzI9neWagqNdwvYkQsEjgfbKbYK7p2CNTUQ +-----END CERTIFICATE----- diff -Nru libwebsockets-3.2.1/minimal-examples/http-client/minimal-http-client-post/CMakeLists.txt libwebsockets-4.1.6/minimal-examples/http-client/minimal-http-client-post/CMakeLists.txt --- libwebsockets-3.2.1/minimal-examples/http-client/minimal-http-client-post/CMakeLists.txt 2019-12-18 14:45:31.000000000 +0000 +++ libwebsockets-4.1.6/minimal-examples/http-client/minimal-http-client-post/CMakeLists.txt 2020-12-01 17:40:26.000000000 +0000 @@ -1,78 +1,90 @@ +project(lws-minimal-http-client-post C) cmake_minimum_required(VERSION 2.8) +find_package(libwebsockets CONFIG REQUIRED) +list(APPEND CMAKE_MODULE_PATH ${LWS_CMAKE_DIR}) include(CheckCSourceCompiles) +include(LwsCheckRequirements) set(SAMP lws-minimal-http-client-post) set(SRCS minimal-http-client-post.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) +set(requirements 1) +require_lws_config(LWS_ROLE_H1 1 requirements) +require_lws_config(LWS_WITH_CLIENT 1 requirements) + +if (requirements) + add_executable(${SAMP} ${SRCS}) + + # + # instantiate the server per sai builder instance, they are running in the same + # machine context in parallel so they can tread on each other otherwise + # + set(PORT_HCP_SRV "7640") + if ("$ENV{SAI_INSTANCE_IDX}" STREQUAL "0") + set(PORT_HCP_SRV 7641) endif() - else() - set(rq 0) + if ("$ENV{SAI_INSTANCE_IDX}" STREQUAL "1") + set(PORT_HCP_SRV 7642) endif() - - if (${_val} EQUAL ${rq}) - set(SAME 1) - else() - set(SAME 0) + if ("$ENV{SAI_INSTANCE_IDX}" STREQUAL "2") + set(PORT_HCP_SRV 7643) 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() + if ("$ENV{SAI_INSTANCE_IDX}" STREQUAL "3") + set(PORT_HCP_SRV 7644) endif() -ENDMACRO() - + +# hack +if (NOT WIN32 AND LWS_WITH_SERVER) + + # + # Tests against built server running locally (needs daemonization...) + # + +if (WIN32) + add_test(NAME st_hcp_srv COMMAND cmd.exe /c start /b $ -s --port ${PORT_HCP_SRV}) + add_test(NAME ki_hcp_srv COMMAND taskkill /F /IM $ /T) +else() + add_test(NAME st_hcp_srv COMMAND + ${CMAKE_SOURCE_DIR}/scripts/ctest-background.sh + hcp_srv + $ + -r ${CMAKE_SOURCE_DIR}/destdir/usr/local/share/libwebsockets-test-server/ + -s --port ${PORT_HCP_SRV} --ignore-sigterm) + add_test(NAME ki_hcp_srv COMMAND + ${CMAKE_SOURCE_DIR}/scripts/ctest-background-kill.sh hcp_srv + $ --port ${PORT_HCP_SRV}) +endif() -set(requirements 1) -require_lws_config(LWS_ROLE_H1 1 requirements) -require_lws_config(LWS_WITHOUT_CLIENT 0 requirements) + set_tests_properties(st_hcp_srv PROPERTIES + WORKING_DIRECTORY . + FIXTURES_SETUP hcp_srv + TIMEOUT 800) + set_tests_properties(ki_hcp_srv PROPERTIES + FIXTURES_CLEANUP hcp_srv) + + add_test(NAME http-client-post COMMAND + lws-minimal-http-client-post -l --port ${PORT_HCP_SRV}) + add_test(NAME http-client-post-m COMMAND + lws-minimal-http-client-post -l -m --port ${PORT_HCP_SRV}) + add_test(NAME http-client-post-h1 COMMAND + lws-minimal-http-client-post -l --h1 --port ${PORT_HCP_SRV}) + add_test(NAME http-client-post-m-h1 COMMAND + lws-minimal-http-client-post -l -m --h1 --port ${PORT_HCP_SRV}) + set_tests_properties(http-client-post + http-client-post-m + http-client-post-h1 + http-client-post-m-h1 + PROPERTIES + FIXTURES_REQUIRED "hcp_srv" + WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}/minimal-examples/http-client/minimal-http-client-post + TIMEOUT 20) +endif() -if (requirements) - add_executable(${SAMP} ${SRCS}) if (websockets_shared) - target_link_libraries(${SAMP} websockets_shared) + target_link_libraries(${SAMP} websockets_shared ${LIBWEBSOCKETS_DEP_LIBS}) add_dependencies(${SAMP} websockets_shared) else() - target_link_libraries(${SAMP} websockets) + target_link_libraries(${SAMP} websockets ${LIBWEBSOCKETS_DEP_LIBS}) endif() endif() diff -Nru libwebsockets-3.2.1/minimal-examples/http-client/minimal-http-client-post/libwebsockets.org.cer libwebsockets-4.1.6/minimal-examples/http-client/minimal-http-client-post/libwebsockets.org.cer --- libwebsockets-3.2.1/minimal-examples/http-client/minimal-http-client-post/libwebsockets.org.cer 2019-12-18 14:45:31.000000000 +0000 +++ libwebsockets-4.1.6/minimal-examples/http-client/minimal-http-client-post/libwebsockets.org.cer 2020-12-01 17:40:26.000000000 +0000 @@ -56,3 +56,24 @@ PfZ+G6Z6h7mjem0Y+iWlkYcV4PIWL1iwBi8saCbGS5jN2p8M+X+Q7UNKEkROb3N6 KOqkqm57TH2H3eDJAkSnh6/DNFu0Qg== -----END CERTIFICATE----- + -----BEGIN CERTIFICATE----- +MIIDSjCCAjKgAwIBAgIQRK+wgNajJ7qJMDmGLvhAazANBgkqhkiG9w0BAQUFADA/ +MSQwIgYDVQQKExtEaWdpdGFsIFNpZ25hdHVyZSBUcnVzdCBDby4xFzAVBgNVBAMT +DkRTVCBSb290IENBIFgzMB4XDTAwMDkzMDIxMTIxOVoXDTIxMDkzMDE0MDExNVow +PzEkMCIGA1UEChMbRGlnaXRhbCBTaWduYXR1cmUgVHJ1c3QgQ28uMRcwFQYDVQQD +Ew5EU1QgUm9vdCBDQSBYMzCCASIwDQYJKoZIhvcNAQEBBQADggEPADCCAQoCggEB +AN+v6ZdQCINXtMxiZfaQguzH0yxrMMpb7NnDfcdAwRgUi+DoM3ZJKuM/IUmTrE4O +rz5Iy2Xu/NMhD2XSKtkyj4zl93ewEnu1lcCJo6m67XMuegwGMoOifooUMM0RoOEq +OLl5CjH9UL2AZd+3UWODyOKIYepLYYHsUmu5ouJLGiifSKOeDNoJjj4XLh7dIN9b +xiqKqy69cK3FCxolkHRyxXtqqzTWMIn/5WgTe1QLyNau7Fqckh49ZLOMxt+/yUFw +7BZy1SbsOFU5Q9D8/RhcQPGX69Wam40dutolucbY38EVAjqr2m7xPi71XAicPNaD +aeQQmxkqtilX4+U9m5/wAl0CAwEAAaNCMEAwDwYDVR0TAQH/BAUwAwEB/zAOBgNV +HQ8BAf8EBAMCAQYwHQYDVR0OBBYEFMSnsaR7LHH62+FLkHX/xBVghYkQMA0GCSqG +SIb3DQEBBQUAA4IBAQCjGiybFwBcqR7uKGY3Or+Dxz9LwwmglSBd49lZRNI+DT69 +ikugdB/OEIKcdBodfpga3csTS7MgROSR6cz8faXbauX+5v3gTt23ADq1cEmv8uXr +AvHRAosZy5Q6XkjEGB5YGV8eAlrwDPGxrancWYaLbumR9YbK+rlmM6pZW87ipxZz +R8srzJmwN0jP41ZL9c8PDHIyh8bwRLtTcm1D9SZImlJnt1ir/md2cXjbDaJWFBM5 +JDGFoqgCWjBH4d1QB7wCCZAA62RjYJsWvIjJEubSfZGL+T0yjWW06XyxV3bqxbYo +Ob8VZRzI9neWagqNdwvYkQsEjgfbKbYK7p2CNTUQ +-----END CERTIFICATE----- + diff -Nru libwebsockets-3.2.1/minimal-examples/http-client/minimal-http-client-post/minimal-http-client-post.c libwebsockets-4.1.6/minimal-examples/http-client/minimal-http-client-post/minimal-http-client-post.c --- libwebsockets-3.2.1/minimal-examples/http-client/minimal-http-client-post/minimal-http-client-post.c 2019-12-18 14:45:31.000000000 +0000 +++ libwebsockets-4.1.6/minimal-examples/http-client/minimal-http-client-post/minimal-http-client-post.c 2020-12-01 17:40:26.000000000 +0000 @@ -21,7 +21,6 @@ static struct lws *client_wsi[4]; struct pss { - char boundary[32]; char body_part; }; @@ -31,9 +30,7 @@ { struct pss *pss = (struct pss *)user; char buf[LWS_PRE + 1024], *start = &buf[LWS_PRE], *p = start, - *end = &buf[sizeof(buf) - 1]; - uint8_t **up, *uend; - uint32_t r; + *end = &buf[sizeof(buf) - LWS_PRE - 1]; int n; switch (reason) { @@ -96,36 +93,20 @@ /* ...callbacks related to generating the POST... */ case LWS_CALLBACK_CLIENT_APPEND_HANDSHAKE_HEADER: - lwsl_user("LWS_CALLBACK_CLIENT_APPEND_HANDSHAKE_HEADER\n"); - up = (uint8_t **)in; - uend = *up + len - 1; - - /* generate a random boundary string */ - - lws_get_random(lws_get_context(wsi), &r, sizeof(r)); - lws_snprintf(pss->boundary, sizeof(pss->boundary) - 1, - "---boundary-%08x", r); - - n = lws_snprintf(buf, sizeof(buf) - 1, - "multipart/form-data; boundary=%s", pss->boundary); - if (lws_add_http_header_by_token(wsi, - WSI_TOKEN_HTTP_CONTENT_TYPE, - (uint8_t *)buf, n, up, uend)) - return 1; /* - * Notice because we are sending multipart/form-data we can - * usually rely on the server to understand where the form - * payload ends without having to give it an overall - * content-length (which can be troublesome to compute ahead - * of generating the data to send). - * * Tell lws we are going to send the body next... */ - lws_client_http_body_pending(wsi, 1); - lws_callback_on_writable(wsi); + if (!lws_http_is_redirected_to_get(wsi)) { + lwsl_user("%s: doing POST flow\n", __func__); + lws_client_http_body_pending(wsi, 1); + lws_callback_on_writable(wsi); + } else + lwsl_user("%s: doing GET flow\n", __func__); break; case LWS_CALLBACK_CLIENT_HTTP_WRITEABLE: + if (lws_http_is_redirected_to_get(wsi)) + break; lwsl_user("LWS_CALLBACK_CLIENT_HTTP_WRITEABLE\n"); n = LWS_WRITE_HTTP; @@ -138,28 +119,25 @@ switch (pss->body_part++) { case 0: + if (lws_client_http_multipart(wsi, "text", NULL, NULL, + &p, end)) + return -1; /* notice every usage of the boundary starts with -- */ - p += lws_snprintf(p, end - p, "--%s\xd\xa" - "content-disposition: " - "form-data; name=\"text\"\xd\xa" - "\xd\xa" - "my text field" - "\xd\xa", pss->boundary); + p += lws_snprintf(p, end - p, "my text field\xd\xa"); break; case 1: + if (lws_client_http_multipart(wsi, "file", "myfile.txt", + "text/plain", &p, end)) + return -1; p += lws_snprintf(p, end - p, - "--%s\xd\xa" - "content-disposition: form-data; name=\"file\";" - "filename=\"myfile.txt\"\xd\xa" - "content-type: text/plain\xd\xa" - "\xd\xa" "This is the contents of the " "uploaded file.\xd\xa" - "\xd\xa", pss->boundary); + "\xd\xa"); break; case 2: - p += lws_snprintf(p, end - p, "--%s--\xd\xa", - pss->boundary); + if (lws_client_http_multipart(wsi, NULL, NULL, NULL, + &p, end)) + return -1; lws_client_http_body_pending(wsi, 0); /* necessary to support H2, it means we will write no * more on this stream */ @@ -212,28 +190,17 @@ struct lws_client_connect_info i; struct lws_context *context; const char *p; - int n = 0, logs = LLL_USER | LLL_ERR | LLL_WARN | LLL_NOTICE - /* - * For LLL_ verbosity above NOTICE to be built into lws, - * lws must have been configured and built with - * -DCMAKE_BUILD_TYPE=DEBUG instead of =RELEASE - * - * | LLL_INFO | LLL_PARSER | LLL_HEADER | LLL_EXT | - * LLL_CLIENT | LLL_LATENCY | LLL_DEBUG - */ ; + int n = 0; signal(SIGINT, sigint_handler); - if ((p = lws_cmdline_option(argc, argv, "-d"))) - logs = atoi(p); - - lws_set_log_level(logs, NULL); + memset(&info, 0, sizeof info); /* otherwise uninitialized garbage */ + lws_cmdline_option_handle_builtin(argc, argv, &info); lwsl_user("LWS minimal http client - POST [-d] [-l] [--h1]\n"); if (lws_cmdline_option(argc, argv, "-m")) count_clients = LWS_ARRAY_SIZE(client_wsi); - memset(&info, 0, sizeof info); /* otherwise uninitialized garbage */ info.options = LWS_SERVER_OPTION_DO_SSL_GLOBAL_INIT; info.port = CONTEXT_PORT_NO_LISTEN; /* we do not run any server */ info.protocols = protocols; @@ -246,7 +213,7 @@ */ info.fd_limit_per_thread = 1 + count_clients + 1; -#if defined(LWS_WITH_MBEDTLS) +#if defined(LWS_WITH_MBEDTLS) || defined(USE_WOLFSSL) /* * OpenSSL uses the system trust store. mbedTLS has to be told which * CA to trust explicitly. @@ -263,7 +230,7 @@ memset(&i, 0, sizeof i); /* otherwise uninitialized garbage */ i.context = context; - i.ssl_connection = LCCSCF_USE_SSL; + i.ssl_connection = LCCSCF_USE_SSL | LCCSCF_HTTP_MULTIPART_MIME; if (lws_cmdline_option(argc, argv, "-l")) { i.port = 7681; @@ -276,6 +243,12 @@ i.path = "/testserver/formtest"; } + if (lws_cmdline_option(argc, argv, "--form1")) + i.path = "/form1"; + + if ((p = lws_cmdline_option(argc, argv, "--port"))) + i.port = atoi(p); + i.host = i.address; i.origin = i.address; i.method = "POST"; @@ -288,6 +261,8 @@ for (n = 0; n < count_clients; n++) { i.pwsi = &client_wsi[n]; + lwsl_notice("%s: connecting to %s:%d\n", __func__, + i.address, i.port); if (!lws_client_connect_via_info(&i)) completed++; } diff -Nru libwebsockets-3.2.1/minimal-examples/http-client/minimal-http-client-post/selftest.sh libwebsockets-4.1.6/minimal-examples/http-client/minimal-http-client-post/selftest.sh --- libwebsockets-3.2.1/minimal-examples/http-client/minimal-http-client-post/selftest.sh 2019-12-18 14:45:31.000000000 +0000 +++ libwebsockets-4.1.6/minimal-examples/http-client/minimal-http-client-post/selftest.sh 1970-01-01 00:00:00.000000000 +0000 @@ -1,39 +0,0 @@ -#!/bin/bash -# -# $1: path to minimal example binaries... -# if lws is built with -DLWS_WITH_MINIMAL_EXAMPLES=1 -# that will be ./bin from your build dir -# -# $2: path for logs and results. The results will go -# in a subdir named after the directory this script -# is in -# -# $3: offset for test index count -# -# $4: total test count -# -# $5: path to ./minimal-examples dir in lws -# -# Test return code 0: OK, 254: timed out, other: error indication - -. $5/selftests-library.sh - -COUNT_TESTS=8 - -dotest $1 $2 warmcat -dotest $1 $2 warmcat-h1 --h1 -dotest $1 $2 warmcat-m -m -dotest $1 $2 warmcat-m-h1 -m --h1 - -spawn "" $5 $1/libwebsockets-test-server -s -dotest $1 $2 localhost -l -spawn $SPID $5 $1/libwebsockets-test-server -s -dotest $1 $2 localhost-h1 -l --h1 -spawn $SPID $5 $1/libwebsockets-test-server -s -dotest $1 $2 localhost-m -l -m -spawn $SPID $5 $1/libwebsockets-test-server -s -dotest $1 $2 localhost-m-h1 -l -m --h1 - -kill $SPID 2>/dev/null -wait $SPID 2>/dev/null -exit $FAILS diff -Nru libwebsockets-3.2.1/minimal-examples/http-server/minimal-http-server/CMakeLists.txt libwebsockets-4.1.6/minimal-examples/http-server/minimal-http-server/CMakeLists.txt --- libwebsockets-3.2.1/minimal-examples/http-server/minimal-http-server/CMakeLists.txt 2019-12-18 14:45:31.000000000 +0000 +++ libwebsockets-4.1.6/minimal-examples/http-server/minimal-http-server/CMakeLists.txt 2020-12-01 17:40:26.000000000 +0000 @@ -1,79 +1,24 @@ +project(lws-minimal-http-server C) cmake_minimum_required(VERSION 2.8) +find_package(libwebsockets CONFIG REQUIRED) +list(APPEND CMAKE_MODULE_PATH ${LWS_CMAKE_DIR}) include(CheckCSourceCompiles) +include(LwsCheckRequirements) set(SAMP lws-minimal-http-server) set(SRCS minimal-http-server.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_ROLE_H1 1 requirements) -require_lws_config(LWS_WITHOUT_SERVER 0 requirements) +require_lws_config(LWS_WITH_SERVER 1 requirements) if (requirements) add_executable(${SAMP} ${SRCS}) if (websockets_shared) - target_link_libraries(${SAMP} websockets_shared) + target_link_libraries(${SAMP} websockets_shared ${LIBWEBSOCKETS_DEP_LIBS}) add_dependencies(${SAMP} websockets_shared) else() - target_link_libraries(${SAMP} websockets) + target_link_libraries(${SAMP} websockets ${LIBWEBSOCKETS_DEP_LIBS}) endif() endif() \ No newline at end of file diff -Nru libwebsockets-3.2.1/minimal-examples/http-server/minimal-http-server/minimal-http-server.c libwebsockets-4.1.6/minimal-examples/http-server/minimal-http-server/minimal-http-server.c --- libwebsockets-3.2.1/minimal-examples/http-server/minimal-http-server/minimal-http-server.c 2019-12-18 14:45:31.000000000 +0000 +++ libwebsockets-4.1.6/minimal-examples/http-server/minimal-http-server/minimal-http-server.c 2020-12-01 17:40:26.000000000 +0000 @@ -72,6 +72,9 @@ info.options = LWS_SERVER_OPTION_HTTP_HEADERS_SECURITY_BEST_PRACTICES_ENFORCE; + if (lws_cmdline_option(argc, argv, "--h2-prior-knowledge")) + info.options |= LWS_SERVER_OPTION_H2_PRIOR_KNOWLEDGE; + context = lws_create_context(&info); if (!context) { lwsl_err("lws init failed\n"); diff -Nru libwebsockets-3.2.1/minimal-examples/http-server/minimal-http-server/mount-origin/libwebsockets.org-logo.svg libwebsockets-4.1.6/minimal-examples/http-server/minimal-http-server/mount-origin/libwebsockets.org-logo.svg --- libwebsockets-3.2.1/minimal-examples/http-server/minimal-http-server/mount-origin/libwebsockets.org-logo.svg 2019-12-18 14:45:31.000000000 +0000 +++ libwebsockets-4.1.6/minimal-examples/http-server/minimal-http-server/mount-origin/libwebsockets.org-logo.svg 2020-12-01 17:40:26.000000000 +0000 @@ -1,120 +1,66 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + + +image/svg+xml + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff -Nru libwebsockets-3.2.1/minimal-examples/http-server/minimal-http-server-basicauth/CMakeLists.txt libwebsockets-4.1.6/minimal-examples/http-server/minimal-http-server-basicauth/CMakeLists.txt --- libwebsockets-3.2.1/minimal-examples/http-server/minimal-http-server-basicauth/CMakeLists.txt 2019-12-18 14:45:31.000000000 +0000 +++ libwebsockets-4.1.6/minimal-examples/http-server/minimal-http-server-basicauth/CMakeLists.txt 2020-12-01 17:40:26.000000000 +0000 @@ -1,77 +1,25 @@ +project(lws-minimal-http-server-basicauth C) cmake_minimum_required(VERSION 2.8) +find_package(libwebsockets CONFIG REQUIRED) +list(APPEND CMAKE_MODULE_PATH ${LWS_CMAKE_DIR}) include(CheckCSourceCompiles) +include(LwsCheckRequirements) set(SAMP lws-minimal-http-server-basicauth) set(SRCS minimal-http-server-basicauth.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_ROLE_H1 1 requirements) -require_lws_config(LWS_WITHOUT_SERVER 0 requirements) +require_lws_config(LWS_WITH_SERVER 1 requirements) +require_lws_config(LWS_WITH_HTTP_BASIC_AUTH 1 requirements) if (requirements) add_executable(${SAMP} ${SRCS}) if (websockets_shared) - target_link_libraries(${SAMP} websockets_shared) + target_link_libraries(${SAMP} websockets_shared ${LIBWEBSOCKETS_DEP_LIBS}) add_dependencies(${SAMP} websockets_shared) else() - target_link_libraries(${SAMP} websockets) + target_link_libraries(${SAMP} websockets ${LIBWEBSOCKETS_DEP_LIBS}) endif() endif() diff -Nru libwebsockets-3.2.1/minimal-examples/http-server/minimal-http-server-basicauth/mount-origin/libwebsockets.org-logo.svg libwebsockets-4.1.6/minimal-examples/http-server/minimal-http-server-basicauth/mount-origin/libwebsockets.org-logo.svg --- libwebsockets-3.2.1/minimal-examples/http-server/minimal-http-server-basicauth/mount-origin/libwebsockets.org-logo.svg 2019-12-18 14:45:31.000000000 +0000 +++ libwebsockets-4.1.6/minimal-examples/http-server/minimal-http-server-basicauth/mount-origin/libwebsockets.org-logo.svg 2020-12-01 17:40:26.000000000 +0000 @@ -1,120 +1,66 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + + +image/svg+xml + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff -Nru libwebsockets-3.2.1/minimal-examples/http-server/minimal-http-server-basicauth/mount-secret-origin/libwebsockets.org-logo.svg libwebsockets-4.1.6/minimal-examples/http-server/minimal-http-server-basicauth/mount-secret-origin/libwebsockets.org-logo.svg --- libwebsockets-3.2.1/minimal-examples/http-server/minimal-http-server-basicauth/mount-secret-origin/libwebsockets.org-logo.svg 2019-12-18 14:45:31.000000000 +0000 +++ libwebsockets-4.1.6/minimal-examples/http-server/minimal-http-server-basicauth/mount-secret-origin/libwebsockets.org-logo.svg 2020-12-01 17:40:26.000000000 +0000 @@ -1,120 +1,66 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + + +image/svg+xml + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff -Nru libwebsockets-3.2.1/minimal-examples/http-server/minimal-http-server-cgi/CMakeLists.txt libwebsockets-4.1.6/minimal-examples/http-server/minimal-http-server-cgi/CMakeLists.txt --- libwebsockets-3.2.1/minimal-examples/http-server/minimal-http-server-cgi/CMakeLists.txt 1970-01-01 00:00:00.000000000 +0000 +++ libwebsockets-4.1.6/minimal-examples/http-server/minimal-http-server-cgi/CMakeLists.txt 2020-12-01 17:40:26.000000000 +0000 @@ -0,0 +1,25 @@ +project(lws-minimal-http-server-cgi C) +cmake_minimum_required(VERSION 2.8) +find_package(libwebsockets CONFIG REQUIRED) +list(APPEND CMAKE_MODULE_PATH ${LWS_CMAKE_DIR}) +include(CheckCSourceCompiles) +include(LwsCheckRequirements) + +set(SAMP lws-minimal-http-server-cgi) +set(SRCS minimal-http-server.c) + +set(requirements 1) +require_lws_config(LWS_ROLE_H1 1 requirements) +require_lws_config(LWS_WITH_CGI 1 requirements) +require_lws_config(LWS_WITHOUT_SERVER 0 requirements) + +if (requirements) + add_executable(${SAMP} ${SRCS}) + + if (websockets_shared) + target_link_libraries(${SAMP} websockets_shared ${LIBWEBSOCKETS_DEP_LIBS}) + add_dependencies(${SAMP} websockets_shared) + else() + target_link_libraries(${SAMP} websockets ${LIBWEBSOCKETS_DEP_LIBS}) + endif() +endif() diff -Nru libwebsockets-3.2.1/minimal-examples/http-server/minimal-http-server-cgi/minimal-http-server.c libwebsockets-4.1.6/minimal-examples/http-server/minimal-http-server-cgi/minimal-http-server.c --- libwebsockets-3.2.1/minimal-examples/http-server/minimal-http-server-cgi/minimal-http-server.c 1970-01-01 00:00:00.000000000 +0000 +++ libwebsockets-4.1.6/minimal-examples/http-server/minimal-http-server-cgi/minimal-http-server.c 2020-12-01 17:40:26.000000000 +0000 @@ -0,0 +1,105 @@ +/* + * lws-minimal-http-server-cgi + * + * Written in 2010-2020 by 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. + * + * 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 char cgi_script_fullpath[256]; + +static const struct lws_http_mount mount = { + /* .mount_next */ NULL, /* linked-list "next" */ + /* .mountpoint */ "/", /* mountpoint URL */ + /* .origin */ cgi_script_fullpath, /* cgi script */ + /* .def */ "/", /* 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_CGI, /* 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, const char **argv) +{ + struct lws_context_creation_info info; + struct lws_context *context; + const char *p; + int n = 0, logs = LLL_USER | LLL_ERR | LLL_WARN | LLL_NOTICE + /* for LLL_ verbosity above NOTICE to be built into lws, + * lws must have been configured and built with + * -DCMAKE_BUILD_TYPE=DEBUG instead of =RELEASE */ + /* | LLL_INFO */ /* | LLL_PARSER */ /* | LLL_HEADER */ + /* | LLL_EXT */ /* | LLL_CLIENT */ /* | LLL_LATENCY */ + /* | LLL_DEBUG */; + + signal(SIGINT, sigint_handler); + + if ((p = lws_cmdline_option(argc, argv, "-d"))) + logs = atoi(p); + + lws_set_log_level(logs, NULL); + lwsl_user("LWS minimal http server | visit http://localhost:7681\n"); + + { + char cwd[128]; + cwd[0] = '\0'; + getcwd(cwd, sizeof(cwd)); + + lws_snprintf(cgi_script_fullpath, sizeof(cgi_script_fullpath), + "%s/my-cgi-script.sh", cwd); + } + + 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_HTTP_HEADERS_SECURITY_BEST_PRACTICES_ENFORCE; + +#if defined(LWS_WITH_TLS) + if (lws_cmdline_option(argc, argv, "-s")) { + info.options |= LWS_SERVER_OPTION_DO_SSL_GLOBAL_INIT; + info.ssl_cert_filepath = "localhost-100y.cert"; + info.ssl_private_key_filepath = "localhost-100y.key"; + } +#endif + + 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 -Nru libwebsockets-3.2.1/minimal-examples/http-server/minimal-http-server-cgi/my-cgi-script.sh libwebsockets-4.1.6/minimal-examples/http-server/minimal-http-server-cgi/my-cgi-script.sh --- libwebsockets-3.2.1/minimal-examples/http-server/minimal-http-server-cgi/my-cgi-script.sh 1970-01-01 00:00:00.000000000 +0000 +++ libwebsockets-4.1.6/minimal-examples/http-server/minimal-http-server-cgi/my-cgi-script.sh 2020-12-01 17:40:26.000000000 +0000 @@ -0,0 +1,36 @@ +#!/bin/sh + +echo -e -n "content-type: text/html\x0d\x0a" +echo -e -n "transfer-encoding: chunked\x0d\x0a" +echo -e -n "\x0d\x0a" + +echo "" +echo "

lwstest script stdout

" +>&2 echo -n "lwstest script stderr: REQUEST_METHOD was $REQUEST_METHOD" + +echo "

REQUEST_METHOD=$REQUEST_METHOD

" + +if [ "$REQUEST_METHOD" = "POST" ] ; then + >&2 echo "lwstest script stderr: doing read" + echo "CONTENT_LENGTH=$CONTENT_LENGTH" + read -n $CONTENT_LENGTH line + >&2 echo "lwstest script stderr: done read $line" + + echo "read=\"$line\"" +else + echo "" + echo "" + cat /proc/meminfo | while read line ; do + A=`echo "$line" | cut -d: -f1` + B=`echo "$line" | tr -s ' ' | cut -d' ' -f2-` + echo -e "" + echo -e "" + done + echo "
/proc/meminfo
$A$B
" +fi + +echo "
done" +echo "" +sleep 0.5 +exit 0 + diff -Nru libwebsockets-3.2.1/minimal-examples/http-server/minimal-http-server-cgi/README.md libwebsockets-4.1.6/minimal-examples/http-server/minimal-http-server-cgi/README.md --- libwebsockets-3.2.1/minimal-examples/http-server/minimal-http-server-cgi/README.md 1970-01-01 00:00:00.000000000 +0000 +++ libwebsockets-4.1.6/minimal-examples/http-server/minimal-http-server-cgi/README.md 2020-12-01 17:40:26.000000000 +0000 @@ -0,0 +1,28 @@ +# lws minimal http server-cgi + +## build + +``` + $ cmake . && make +``` + +## usage + +This example runs a script ./my-cgi-script.sh when you vist / + +The script dumps some information from /proc on stdout, which +is proxied back to the browser, script output on stderr is +printed in the console. + +It's able to serve the script output over h1 using chunked encoding, +and over h2 having stripped the chunked encoding from the script +output. + +``` + $ ./lws-minimal-http-server-cgi +[2019/11/18 16:31:29:5481] U: LWS minimal http server | visit http://localhost:7681 +[2019/11/18 16:31:40:2176] N: CGI-stderr: lwstest script stderr: REQUEST_METHOD was GET +``` + +Visit http://localhost:7681 + diff -Nru libwebsockets-3.2.1/minimal-examples/http-server/minimal-http-server-custom-headers/CMakeLists.txt libwebsockets-4.1.6/minimal-examples/http-server/minimal-http-server-custom-headers/CMakeLists.txt --- libwebsockets-3.2.1/minimal-examples/http-server/minimal-http-server-custom-headers/CMakeLists.txt 2019-12-18 14:45:31.000000000 +0000 +++ libwebsockets-4.1.6/minimal-examples/http-server/minimal-http-server-custom-headers/CMakeLists.txt 2020-12-01 17:40:26.000000000 +0000 @@ -1,78 +1,25 @@ +project(lws-minimal-http-server-custom-headers C) cmake_minimum_required(VERSION 2.8) +find_package(libwebsockets CONFIG REQUIRED) +list(APPEND CMAKE_MODULE_PATH ${LWS_CMAKE_DIR}) include(CheckCSourceCompiles) +include(LwsCheckRequirements) set(SAMP lws-minimal-http-server-custom-headers) set(SRCS minimal-http-server-custom-headers.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_ROLE_H1 1 requirements) require_lws_config(LWS_WITH_CUSTOM_HEADERS 1 requirements) -require_lws_config(LWS_WITHOUT_SERVER 0 requirements) +require_lws_config(LWS_WITH_SERVER 1 requirements) if (requirements) add_executable(${SAMP} ${SRCS}) if (websockets_shared) - target_link_libraries(${SAMP} websockets_shared) + target_link_libraries(${SAMP} websockets_shared ${LIBWEBSOCKETS_DEP_LIBS}) add_dependencies(${SAMP} websockets_shared) else() - target_link_libraries(${SAMP} websockets) + target_link_libraries(${SAMP} websockets ${LIBWEBSOCKETS_DEP_LIBS}) endif() endif() diff -Nru libwebsockets-3.2.1/minimal-examples/http-server/minimal-http-server-custom-headers/minimal-http-server-custom-headers.c libwebsockets-4.1.6/minimal-examples/http-server/minimal-http-server-custom-headers/minimal-http-server-custom-headers.c --- libwebsockets-3.2.1/minimal-examples/http-server/minimal-http-server-custom-headers/minimal-http-server-custom-headers.c 2019-12-18 14:45:31.000000000 +0000 +++ libwebsockets-4.1.6/minimal-examples/http-server/minimal-http-server-custom-headers/minimal-http-server-custom-headers.c 2020-12-01 17:40:26.000000000 +0000 @@ -201,8 +201,10 @@ info.port = 7682; info.error_document_404 = "/404.html"; +#if defined(LWS_WITH_TLS) info.ssl_cert_filepath = "localhost-100y.cert"; info.ssl_private_key_filepath = "localhost-100y.key"; +#endif info.vhost_name = "https"; if (!lws_create_vhost(context, &info)) { diff -Nru libwebsockets-3.2.1/minimal-examples/http-server/minimal-http-server-custom-headers/mount-origin/libwebsockets.org-logo.svg libwebsockets-4.1.6/minimal-examples/http-server/minimal-http-server-custom-headers/mount-origin/libwebsockets.org-logo.svg --- libwebsockets-3.2.1/minimal-examples/http-server/minimal-http-server-custom-headers/mount-origin/libwebsockets.org-logo.svg 2019-12-18 14:45:31.000000000 +0000 +++ libwebsockets-4.1.6/minimal-examples/http-server/minimal-http-server-custom-headers/mount-origin/libwebsockets.org-logo.svg 2020-12-01 17:40:26.000000000 +0000 @@ -1,120 +1,66 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + + +image/svg+xml + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff -Nru libwebsockets-3.2.1/minimal-examples/http-server/minimal-http-server-deaddrop/CMakeLists.txt libwebsockets-4.1.6/minimal-examples/http-server/minimal-http-server-deaddrop/CMakeLists.txt --- libwebsockets-3.2.1/minimal-examples/http-server/minimal-http-server-deaddrop/CMakeLists.txt 2019-12-18 14:45:31.000000000 +0000 +++ libwebsockets-4.1.6/minimal-examples/http-server/minimal-http-server-deaddrop/CMakeLists.txt 2020-12-01 17:40:26.000000000 +0000 @@ -1,5 +1,9 @@ +project(lws-minimal-http-server-deaddrop C) cmake_minimum_required(VERSION 2.8) +find_package(libwebsockets CONFIG REQUIRED) +list(APPEND CMAKE_MODULE_PATH ${LWS_CMAKE_DIR}) include(CheckCSourceCompiles) +include(LwsCheckRequirements) set(SAMP lws-minimal-http-server-deaddrop) set(SRCS minimal-http-server-deaddrop.c) @@ -8,69 +12,13 @@ # to the lws plugins dir so it can pick up the plugin source. Eg, # cmake . -DLWS_PLUGINS_DIR=~/libwebsockets/plugins -# 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_ROLE_H1 1 requirements) require_lws_config(LWS_ROLE_WS 1 requirements) -require_lws_config(LWS_WITHOUT_SERVER 0 requirements) +require_lws_config(LWS_WITH_SERVER 1 requirements) +require_lws_config(LWS_WITH_HTTP_BASIC_AUTH 1 requirements) -if (requirements) +if (requirements AND UNIX) add_executable(${SAMP} ${SRCS}) if (LWS_PLUGINS_DIR) @@ -78,9 +26,9 @@ endif() if (websockets_shared) - target_link_libraries(${SAMP} websockets_shared) + target_link_libraries(${SAMP} websockets_shared ${LIBWEBSOCKETS_DEP_LIBS}) add_dependencies(${SAMP} websockets_shared) else() - target_link_libraries(${SAMP} websockets) + target_link_libraries(${SAMP} websockets ${LIBWEBSOCKETS_DEP_LIBS}) endif() endif() diff -Nru libwebsockets-3.2.1/minimal-examples/http-server/minimal-http-server-deaddrop/minimal-http-server-deaddrop.c libwebsockets-4.1.6/minimal-examples/http-server/minimal-http-server-deaddrop/minimal-http-server-deaddrop.c --- libwebsockets-3.2.1/minimal-examples/http-server/minimal-http-server-deaddrop/minimal-http-server-deaddrop.c 2019-12-18 14:45:31.000000000 +0000 +++ libwebsockets-4.1.6/minimal-examples/http-server/minimal-http-server-deaddrop/minimal-http-server-deaddrop.c 2020-12-01 17:40:26.000000000 +0000 @@ -153,8 +153,10 @@ info.error_document_404 = "/404.html"; info.options = LWS_SERVER_OPTION_DO_SSL_GLOBAL_INIT | LWS_SERVER_OPTION_HTTP_HEADERS_SECURITY_BEST_PRACTICES_ENFORCE; +#if defined(LWS_WITH_TLS) info.ssl_cert_filepath = "localhost-100y.cert"; info.ssl_private_key_filepath = "localhost-100y.key"; +#endif context = lws_create_context(&info); if (!context) { diff -Nru libwebsockets-3.2.1/minimal-examples/http-server/minimal-http-server-deaddrop/mount-origin/deaddrop.js libwebsockets-4.1.6/minimal-examples/http-server/minimal-http-server-deaddrop/mount-origin/deaddrop.js --- libwebsockets-3.2.1/minimal-examples/http-server/minimal-http-server-deaddrop/mount-origin/deaddrop.js 2019-12-18 14:45:31.000000000 +0000 +++ libwebsockets-4.1.6/minimal-examples/http-server/minimal-http-server-deaddrop/mount-origin/deaddrop.js 2020-12-01 17:40:26.000000000 +0000 @@ -74,7 +74,7 @@ } function clear_errors() { - var t = document.getElementById("ongoing"); + var n, t = document.getElementById("ongoing"); for (n = 0; n < t.rows.length; n++) if (t.rows[n].cells[0].classList.contains("err")) @@ -154,8 +154,7 @@ } function upl_button(e) { - var fi = document.getElementById("file"), - da = document.getElementById("da"); + var fi = document.getElementById("file"); clear_errors(); e.preventDefault(); @@ -211,9 +210,6 @@ function new_ws(urlpath, protocol) { - if (typeof MozWebSocket != "undefined") - return new MozWebSocket(urlpath, protocol); - return new WebSocket(urlpath, protocol); } diff -Nru libwebsockets-3.2.1/minimal-examples/http-server/minimal-http-server-deaddrop/mount-origin/libwebsockets.org-logo.svg libwebsockets-4.1.6/minimal-examples/http-server/minimal-http-server-deaddrop/mount-origin/libwebsockets.org-logo.svg --- libwebsockets-3.2.1/minimal-examples/http-server/minimal-http-server-deaddrop/mount-origin/libwebsockets.org-logo.svg 2019-12-18 14:45:31.000000000 +0000 +++ libwebsockets-4.1.6/minimal-examples/http-server/minimal-http-server-deaddrop/mount-origin/libwebsockets.org-logo.svg 2020-12-01 17:40:26.000000000 +0000 @@ -1,120 +1,66 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + + +image/svg+xml + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff -Nru libwebsockets-3.2.1/minimal-examples/http-server/minimal-http-server-dynamic/CMakeLists.txt libwebsockets-4.1.6/minimal-examples/http-server/minimal-http-server-dynamic/CMakeLists.txt --- libwebsockets-3.2.1/minimal-examples/http-server/minimal-http-server-dynamic/CMakeLists.txt 2019-12-18 14:45:31.000000000 +0000 +++ libwebsockets-4.1.6/minimal-examples/http-server/minimal-http-server-dynamic/CMakeLists.txt 2020-12-01 17:40:26.000000000 +0000 @@ -1,78 +1,24 @@ +project(lws-minimal-http-server-dynamic C) cmake_minimum_required(VERSION 2.8) +find_package(libwebsockets CONFIG REQUIRED) +list(APPEND CMAKE_MODULE_PATH ${LWS_CMAKE_DIR}) include(CheckCSourceCompiles) +include(LwsCheckRequirements) set(SAMP lws-minimal-http-server-dynamic) set(SRCS minimal-http-server-dynamic.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_ROLE_H1 1 requirements) -require_lws_config(LWS_WITHOUT_SERVER 0 requirements) +require_lws_config(LWS_WITH_SERVER 1 requirements) if (requirements) add_executable(${SAMP} ${SRCS}) if (websockets_shared) - target_link_libraries(${SAMP} websockets_shared) + target_link_libraries(${SAMP} websockets_shared ${LIBWEBSOCKETS_DEP_LIBS}) add_dependencies(${SAMP} websockets_shared) else() - target_link_libraries(${SAMP} websockets) + target_link_libraries(${SAMP} websockets ${LIBWEBSOCKETS_DEP_LIBS}) endif() endif() diff -Nru libwebsockets-3.2.1/minimal-examples/http-server/minimal-http-server-dynamic/minimal-http-server-dynamic.c libwebsockets-4.1.6/minimal-examples/http-server/minimal-http-server-dynamic/minimal-http-server-dynamic.c --- libwebsockets-3.2.1/minimal-examples/http-server/minimal-http-server-dynamic/minimal-http-server-dynamic.c 2019-12-18 14:45:31.000000000 +0000 +++ libwebsockets-4.1.6/minimal-examples/http-server/minimal-http-server-dynamic/minimal-http-server-dynamic.c 2020-12-01 17:40:26.000000000 +0000 @@ -49,8 +49,27 @@ switch (reason) { case LWS_CALLBACK_HTTP: - /* in contains the url part after our mountpoint /dyn, if any */ - lws_snprintf(pss->path, sizeof(pss->path), "%s", (const char *)in); + /* + * If you want to know the full url path used, you can get it + * like this + * + * n = lws_hdr_copy(wsi, buf, sizeof(buf), WSI_TOKEN_GET_URI); + * + * The base path is the first (n - strlen((const char *)in)) + * chars in buf. + */ + + /* + * In contains the url part after the place the mount was + * positioned at, eg, if positioned at "/dyn" and given + * "/dyn/mypath", in will contain /mypath + */ + lws_snprintf(pss->path, sizeof(pss->path), "%s", + (const char *)in); + + lws_get_peer_simple(wsi, (char *)buf, sizeof(buf)); + lwsl_notice("%s: HTTP: connection %s, path %s\n", __func__, + (const char *)buf, pss->path); /* * prepare and write http headers... with regards to content- @@ -175,10 +194,11 @@ return lws_callback_http_dummy(wsi, reason, user, in, len); } -static const struct lws_protocols protocol = +static const struct lws_protocols defprot = + { "defprot", lws_callback_http_dummy, 0, 0 }, protocol = { "http", callback_dynamic_http, sizeof(struct pss), 0 }; -static const struct lws_protocols *pprotocols[] = { &protocol, NULL }; +static const struct lws_protocols *pprotocols[] = { &defprot, &protocol, NULL }; /* override the default mount for /dyn in the URL space */ @@ -281,8 +301,10 @@ info.port = 7682; info.error_document_404 = "/404.html"; +#if defined(LWS_WITH_TLS) info.ssl_cert_filepath = "localhost-100y.cert"; info.ssl_private_key_filepath = "localhost-100y.key"; +#endif info.vhost_name = "localhost"; if (!lws_create_vhost(context, &info)) { diff -Nru libwebsockets-3.2.1/minimal-examples/http-server/minimal-http-server-dynamic/mount-origin/libwebsockets.org-logo.svg libwebsockets-4.1.6/minimal-examples/http-server/minimal-http-server-dynamic/mount-origin/libwebsockets.org-logo.svg --- libwebsockets-3.2.1/minimal-examples/http-server/minimal-http-server-dynamic/mount-origin/libwebsockets.org-logo.svg 2019-12-18 14:45:31.000000000 +0000 +++ libwebsockets-4.1.6/minimal-examples/http-server/minimal-http-server-dynamic/mount-origin/libwebsockets.org-logo.svg 2020-12-01 17:40:26.000000000 +0000 @@ -1,120 +1,66 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + + +image/svg+xml + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff -Nru libwebsockets-3.2.1/minimal-examples/http-server/minimal-http-server-eventlib/CMakeLists.txt libwebsockets-4.1.6/minimal-examples/http-server/minimal-http-server-eventlib/CMakeLists.txt --- libwebsockets-3.2.1/minimal-examples/http-server/minimal-http-server-eventlib/CMakeLists.txt 2019-12-18 14:45:31.000000000 +0000 +++ libwebsockets-4.1.6/minimal-examples/http-server/minimal-http-server-eventlib/CMakeLists.txt 2020-12-01 17:40:26.000000000 +0000 @@ -1,78 +1,24 @@ +project(lws-minimal-http-server-eventlib C) cmake_minimum_required(VERSION 2.8) +find_package(libwebsockets CONFIG REQUIRED) +list(APPEND CMAKE_MODULE_PATH ${LWS_CMAKE_DIR}) include(CheckCSourceCompiles) +include(LwsCheckRequirements) set(SAMP lws-minimal-http-server-eventlib) set(SRCS minimal-http-server-eventlib.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_ROLE_H1 1 requirements) -require_lws_config(LWS_WITHOUT_SERVER 0 requirements) +require_lws_config(LWS_WITH_SERVER 1 requirements) if (requirements) add_executable(${SAMP} ${SRCS}) if (websockets_shared) - target_link_libraries(${SAMP} websockets_shared) + target_link_libraries(${SAMP} websockets_shared ${LIBWEBSOCKETS_DEP_LIBS}) add_dependencies(${SAMP} websockets_shared) else() - target_link_libraries(${SAMP} websockets) + target_link_libraries(${SAMP} websockets ${LIBWEBSOCKETS_DEP_LIBS}) endif() endif() diff -Nru libwebsockets-3.2.1/minimal-examples/http-server/minimal-http-server-eventlib/minimal-http-server-eventlib.c libwebsockets-4.1.6/minimal-examples/http-server/minimal-http-server-eventlib/minimal-http-server-eventlib.c --- libwebsockets-3.2.1/minimal-examples/http-server/minimal-http-server-eventlib/minimal-http-server-eventlib.c 2019-12-18 14:45:31.000000000 +0000 +++ libwebsockets-4.1.6/minimal-examples/http-server/minimal-http-server-eventlib/minimal-http-server-eventlib.c 2020-12-01 17:40:26.000000000 +0000 @@ -86,11 +86,13 @@ info.options = LWS_SERVER_OPTION_HTTP_HEADERS_SECURITY_BEST_PRACTICES_ENFORCE; +#if defined(LWS_WITH_TLS) if (lws_cmdline_option(argc, argv, "-s")) { info.options |= LWS_SERVER_OPTION_DO_SSL_GLOBAL_INIT; info.ssl_cert_filepath = "localhost-100y.cert"; info.ssl_private_key_filepath = "localhost-100y.key"; } +#endif if (lws_cmdline_option(argc, argv, "--uv")) info.options |= LWS_SERVER_OPTION_LIBUV; @@ -101,7 +103,10 @@ if (lws_cmdline_option(argc, argv, "--ev")) info.options |= LWS_SERVER_OPTION_LIBEV; else - signal(SIGINT, sigint_handler); + if (lws_cmdline_option(argc, argv, "--glib")) + info.options |= LWS_SERVER_OPTION_GLIB; + else + signal(SIGINT, sigint_handler); context = lws_create_context(&info); if (!context) { diff -Nru libwebsockets-3.2.1/minimal-examples/http-server/minimal-http-server-eventlib/mount-origin/libwebsockets.org-logo.svg libwebsockets-4.1.6/minimal-examples/http-server/minimal-http-server-eventlib/mount-origin/libwebsockets.org-logo.svg --- libwebsockets-3.2.1/minimal-examples/http-server/minimal-http-server-eventlib/mount-origin/libwebsockets.org-logo.svg 2019-12-18 14:45:31.000000000 +0000 +++ libwebsockets-4.1.6/minimal-examples/http-server/minimal-http-server-eventlib/mount-origin/libwebsockets.org-logo.svg 2020-12-01 17:40:26.000000000 +0000 @@ -1,120 +1,66 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + + +image/svg+xml + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff -Nru libwebsockets-3.2.1/minimal-examples/http-server/minimal-http-server-eventlib-demos/CMakeLists.txt libwebsockets-4.1.6/minimal-examples/http-server/minimal-http-server-eventlib-demos/CMakeLists.txt --- libwebsockets-3.2.1/minimal-examples/http-server/minimal-http-server-eventlib-demos/CMakeLists.txt 2019-12-18 14:45:31.000000000 +0000 +++ libwebsockets-4.1.6/minimal-examples/http-server/minimal-http-server-eventlib-demos/CMakeLists.txt 2020-12-01 17:40:26.000000000 +0000 @@ -1,79 +1,25 @@ +project(lws-minimal-http-server-eventlib-demos C) cmake_minimum_required(VERSION 2.8) +find_package(libwebsockets CONFIG REQUIRED) +list(APPEND CMAKE_MODULE_PATH ${LWS_CMAKE_DIR}) include(CheckCSourceCompiles) +include(LwsCheckRequirements) set(SAMP lws-minimal-http-server-eventlib-demos) set(SRCS minimal-http-server-eventlib-demos.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_ROLE_H1 1 requirements) require_lws_config(LWS_ROLE_WS 1 requirements) -require_lws_config(LWS_WITHOUT_SERVER 0 requirements) +require_lws_config(LWS_WITH_SERVER 1 requirements) if (requirements) add_executable(${SAMP} ${SRCS}) if (websockets_shared) - target_link_libraries(${SAMP} websockets_shared) + target_link_libraries(${SAMP} websockets_shared ${LIBWEBSOCKETS_DEP_LIBS}) add_dependencies(${SAMP} websockets_shared) else() - target_link_libraries(${SAMP} websockets) + target_link_libraries(${SAMP} websockets ${LIBWEBSOCKETS_DEP_LIBS}) endif() endif() diff -Nru libwebsockets-3.2.1/minimal-examples/http-server/minimal-http-server-eventlib-demos/minimal-http-server-eventlib-demos.c libwebsockets-4.1.6/minimal-examples/http-server/minimal-http-server-eventlib-demos/minimal-http-server-eventlib-demos.c --- libwebsockets-3.2.1/minimal-examples/http-server/minimal-http-server-eventlib-demos/minimal-http-server-eventlib-demos.c 2019-12-18 14:45:31.000000000 +0000 +++ libwebsockets-4.1.6/minimal-examples/http-server/minimal-http-server-eventlib-demos/minimal-http-server-eventlib-demos.c 2020-12-01 17:40:26.000000000 +0000 @@ -41,10 +41,30 @@ * mount handlers for sections of the URL space */ -static const struct lws_http_mount mount_ziptest = { +static const struct lws_http_mount mount_ziptest_uncomm = { NULL, /* linked-list pointer to next*/ + "/uncommziptest", /* mountpoint in URL namespace on this vhost */ + "./mount-origin/candide-uncompressed.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 */ + 14, /* strlen("/ziptest"), ie length of the mountpoint */ + NULL, + + { NULL, NULL } // sentinel +}, mount_ziptest = { + (struct lws_http_mount *)&mount_ziptest_uncomm, /* linked-list pointer to next*/ "/ziptest", /* mountpoint in URL namespace on this vhost */ - "candide.zip", /* handler */ + "./mount-origin/candide.zip", /* handler */ NULL, /* default filename if none given */ NULL, NULL, @@ -61,9 +81,7 @@ NULL, { NULL, NULL } // sentinel -}; - -static const struct lws_http_mount mount_post = { +}, 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 */ @@ -83,10 +101,7 @@ NULL, { NULL, NULL } // sentinel -}; - - -static const struct lws_http_mount mount = { +}, mount = { /* .mount_next */ &mount_post, /* linked-list "next" */ /* .mountpoint */ "/", /* mountpoint URL */ /* .origin */ "./mount-origin", /* serve from dir */ @@ -157,8 +172,10 @@ if (lws_cmdline_option(argc, argv, "-s")) { info.options |= LWS_SERVER_OPTION_DO_SSL_GLOBAL_INIT; +#if defined(LWS_WITH_TLS) info.ssl_cert_filepath = "localhost-100y.cert"; info.ssl_private_key_filepath = "localhost-100y.key"; +#endif } if (lws_cmdline_option(argc, argv, "--uv")) @@ -170,7 +187,10 @@ if (lws_cmdline_option(argc, argv, "--ev")) info.options |= LWS_SERVER_OPTION_LIBEV; else - signal(SIGINT, sigint_handler); + if (lws_cmdline_option(argc, argv, "--glib")) + info.options |= LWS_SERVER_OPTION_GLIB; + else + signal(SIGINT, sigint_handler); context = lws_create_context(&info); if (!context) { Binary files /tmp/tmp2l8bmswe/3lv7Sxvgkv/libwebsockets-3.2.1/minimal-examples/http-server/minimal-http-server-eventlib-demos/mount-origin/candide-uncompressed.zip and /tmp/tmp2l8bmswe/LwTwoWz49Q/libwebsockets-4.1.6/minimal-examples/http-server/minimal-http-server-eventlib-demos/mount-origin/candide-uncompressed.zip differ diff -Nru libwebsockets-3.2.1/minimal-examples/http-server/minimal-http-server-eventlib-demos/mount-origin/libwebsockets.org-logo.svg libwebsockets-4.1.6/minimal-examples/http-server/minimal-http-server-eventlib-demos/mount-origin/libwebsockets.org-logo.svg --- libwebsockets-3.2.1/minimal-examples/http-server/minimal-http-server-eventlib-demos/mount-origin/libwebsockets.org-logo.svg 2019-12-18 14:45:31.000000000 +0000 +++ libwebsockets-4.1.6/minimal-examples/http-server/minimal-http-server-eventlib-demos/mount-origin/libwebsockets.org-logo.svg 2020-12-01 17:40:26.000000000 +0000 @@ -1,120 +1,66 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + + +image/svg+xml + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff -Nru libwebsockets-3.2.1/minimal-examples/http-server/minimal-http-server-eventlib-demos/mount-origin/lws-common.js libwebsockets-4.1.6/minimal-examples/http-server/minimal-http-server-eventlib-demos/mount-origin/lws-common.js --- libwebsockets-3.2.1/minimal-examples/http-server/minimal-http-server-eventlib-demos/mount-origin/lws-common.js 2019-12-18 14:45:31.000000000 +0000 +++ libwebsockets-4.1.6/minimal-examples/http-server/minimal-http-server-eventlib-demos/mount-origin/lws-common.js 2020-12-01 17:40:26.000000000 +0000 @@ -113,9 +113,6 @@ function new_ws(urlpath, protocol) { - if (typeof MozWebSocket != "undefined") - return new MozWebSocket(urlpath, protocol); - return new WebSocket(urlpath, protocol); } diff -Nru libwebsockets-3.2.1/minimal-examples/http-server/minimal-http-server-eventlib-foreign/CMakeLists.txt libwebsockets-4.1.6/minimal-examples/http-server/minimal-http-server-eventlib-foreign/CMakeLists.txt --- libwebsockets-3.2.1/minimal-examples/http-server/minimal-http-server-eventlib-foreign/CMakeLists.txt 2019-12-18 14:45:31.000000000 +0000 +++ libwebsockets-4.1.6/minimal-examples/http-server/minimal-http-server-eventlib-foreign/CMakeLists.txt 2020-12-01 17:40:26.000000000 +0000 @@ -1,87 +1,81 @@ +project(lws-minimal-http-server-eventlib-foreign C) cmake_minimum_required(VERSION 2.8) +find_package(libwebsockets CONFIG REQUIRED) +list(APPEND CMAKE_MODULE_PATH ${LWS_CMAKE_DIR}) +include(CheckIncludeFile) include(CheckCSourceCompiles) +include(LwsCheckRequirements) set(SAMP lws-minimal-http-server-eventlib-foreign) set(SRCS minimal-http-server-eventlib-foreign.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_pthreads(requirements) require_lws_config(LWS_ROLE_H1 1 requirements) -require_lws_config(LWS_WITHOUT_SERVER 0 requirements) +require_lws_config(LWS_WITH_SERVER 1 requirements) +require_lws_config(LWS_WITH_TLS 1 requirements) CHECK_C_SOURCE_COMPILES("#include \nint main(void) {\n#if defined(LWS_WITH_LIBUV)\n return 0;\n#else\n fail;\n#endif\n return 0;\n}\n" LWS_WITH_LIBUV) CHECK_C_SOURCE_COMPILES("#include \nint main(void) {\n#if defined(LWS_WITH_LIBEVENT)\n return 0;\n#else\n fail;\n#endif\n return 0;\n}\n" LWS_WITH_LIBEVENT) CHECK_C_SOURCE_COMPILES("#include \nint main(void) {\n#if defined(LWS_WITH_LIBEV)\n return 0;\n#else\n fail;\n#endif\n return 0;\n}\n" LWS_WITH_LIBEV) +CHECK_C_SOURCE_COMPILES("#include \nint main(void) {\n#if defined(LWS_WITH_GLIB)\n return 0;\n#else\n fail;\n#endif\n return 0;\n}\n" LWS_WITH_GLIB) + if (LWS_WITH_LIBUV) - set(extralibs ${extralibs} uv) + find_path(LIBUV_INCLUDE_DIRS NAMES uv.h) + find_library(LIBUV_LIBRARIES NAMES uv) + message("libuv include dir: ${LIBUV_INCLUDE_DIRS}") + message("libuv libraries: ${LIBUV_LIBRARIES}") + include_directories("${LIBUV_INCLUDE_DIRS}") + set(extralibs ${extralibs} ${LIBUV_LIBRARIES}) + list(APPEND SRCS libuv.c) endif() if (LWS_WITH_LIBEVENT) - set(extralibs ${extralibs} event) + find_path(LIBEVENT_INCLUDE_DIRS NAMES event2/event.h) + find_library(LIBEVENT_LIBRARIES NAMES event) + message("libevent include dir: ${LIBEVENT_INCLUDE_DIRS}") + message("libevent libraries: ${LIBEVENT_LIBRARIES}") + include_directories("${LIBEVENT_INCLUDE_DIRS}") + set(extralibs ${extralibs} ${LIBEVENT_LIBRARIES}) + list(APPEND SRCS libevent.c) endif() if (LWS_WITH_LIBEV) - set(extralibs ${extralibs} ev) + find_path(LIBEV_INCLUDE_DIRS NAMES ev.h) + find_library(LIBEV_LIBRARIES NAMES ev) + message("libev include dir: ${LIBEV_INCLUDE_DIRS}") + message("libev libraries: ${LIBEV_LIBRARIES}") + include_directories("${LIBEV_INCLUDE_DIRS}") + set(extralibs ${extralibs} ${LIBEV_LIBRARIES}) + list(APPEND SRCS libev.c) +endif() +if (LWS_WITH_GLIB) + set(LWS_GLIB_INCLUDE_DIRS CACHE PATH "Path to the glib include directory") + set(LWS_GLIB_LIBRARIES CACHE PATH "Path to the glib library") + include (FindPkgConfig) + if (NOT GLIB_FOUND) + find_path(GLIB_INCLUDE_DIRS NAMES glib-2.0/glib.h) + find_library(GLIB_LIBRARIES NAMES glib-2.0) + if(GLIB_INCLUDE_DIRS AND GLIB_LIBRARIES) + set(GLIB_FOUND 1) + endif() + if (GLIB_INCLUDE_DIRS) + set(GLIB_INCLUDE_DIRS "${GLIB_INCLUDE_DIRS}/glib-2.0") + endif() + endif() + PKG_SEARCH_MODULE(LWS_GLIB2 glib-2.0) + if (LWS_GLIB2_FOUND) + list(APPEND GLIB_INCLUDE_DIRS "${LWS_GLIB2_INCLUDE_DIRS}") + endif() + message("glib include dir: ${GLIB_INCLUDE_DIRS}") + message("glib libraries: ${GLIB_LIBRARIES}") + include_directories("${GLIB_INCLUDE_DIRS}") + set(extralibs ${extralibs} ${GLIB_LIBRARIES}) + list(APPEND SRCS glib.c) endif() message("Extra libs: ${extralibs}") -if (NOT LWS_WITH_LIBUV AND NOT LWS_WITH_LIBEVENT AND NOT LWS_WITH_LIBEV) +if (NOT LWS_WITH_LIBUV AND NOT LWS_WITH_LIBEVENT AND NOT LWS_WITH_LIBEV AND NOT LWS_WITH_GLIB) set(requirements 0) endif() @@ -89,9 +83,9 @@ add_executable(${SAMP} ${SRCS}) if (websockets_shared) - target_link_libraries(${SAMP} websockets_shared ${extralibs}) + target_link_libraries(${SAMP} websockets_shared ${extralibs} ${PTHREAD_LIB} ${LIBWEBSOCKETS_DEP_LIBS}) add_dependencies(${SAMP} websockets_shared) else() - target_link_libraries(${SAMP} websockets ${extralibs}) + target_link_libraries(${SAMP} websockets ${extralibs} ${PTHREAD_LIB} ${LIBWEBSOCKETS_DEP_LIBS}) endif() endif() diff -Nru libwebsockets-3.2.1/minimal-examples/http-server/minimal-http-server-eventlib-foreign/glib.c libwebsockets-4.1.6/minimal-examples/http-server/minimal-http-server-eventlib-foreign/glib.c --- libwebsockets-3.2.1/minimal-examples/http-server/minimal-http-server-eventlib-foreign/glib.c 1970-01-01 00:00:00.000000000 +0000 +++ libwebsockets-4.1.6/minimal-examples/http-server/minimal-http-server-eventlib-foreign/glib.c 2020-12-01 17:40:26.000000000 +0000 @@ -0,0 +1,92 @@ +/* + * lws-minimal-http-server-eventlib-foreign + * + * Written in 2010-2020 by Andy Green + * + * This file is made available under the Creative Commons CC0 1.0 + * Universal Public Domain Dedication. + * + * The glib specific code + */ + +#include + +#include +#include + +#include +#include + +#include "private.h" + +typedef struct lws_glib_tag { + GSource *gs; + guint tag; +} lws_glib_tag_t; + +#define lws_gs_valid(t) (t.gs) +#define lws_gs_destroy(t) if (lws_gs_valid(t)) { \ + g_source_remove(t.tag); \ + g_source_unref(t.gs); \ + t.gs = NULL; t.tag = 0; } + +static GMainLoop *loop_glib; +static lws_glib_tag_t timer_outer_glib, sighandler_glib; + +static int +timer_cb_glib(void *p) +{ + foreign_timer_service(loop_glib); + return 1; +} + +static void +signal_cb_glib(void *p) +{ + signal_cb(SIGINT); +} + +static void +foreign_event_loop_init_and_run_glib(void) +{ + /* we create and start our "foreign loop" */ + + loop_glib = g_main_loop_new(NULL, 0); + + sighandler_glib.gs = g_unix_signal_source_new(SIGINT); + g_source_set_callback(sighandler_glib.gs, G_SOURCE_FUNC(signal_cb_glib), + NULL, NULL); + sighandler_glib.tag = g_source_attach(sighandler_glib.gs, + g_main_loop_get_context(loop_glib)); + + timer_outer_glib.gs = g_timeout_source_new(1000); + g_source_set_callback(timer_outer_glib.gs, timer_cb_glib, NULL, NULL); + timer_outer_glib.tag = g_source_attach(timer_outer_glib.gs, + g_main_loop_get_context(loop_glib)); + + g_main_loop_run(loop_glib); +} + +static void +foreign_event_loop_stop_glib(void) +{ + g_main_loop_quit(loop_glib); +} + +static void +foreign_event_loop_cleanup_glib(void) +{ + /* cleanup the foreign loop assets */ + + lws_gs_destroy(sighandler_glib); + lws_gs_destroy(timer_outer_glib); + + g_main_loop_unref(loop_glib); + loop_glib = NULL; +} + +const struct ops ops_glib = { + foreign_event_loop_init_and_run_glib, + foreign_event_loop_stop_glib, + foreign_event_loop_cleanup_glib +}; diff -Nru libwebsockets-3.2.1/minimal-examples/http-server/minimal-http-server-eventlib-foreign/libev.c libwebsockets-4.1.6/minimal-examples/http-server/minimal-http-server-eventlib-foreign/libev.c --- libwebsockets-3.2.1/minimal-examples/http-server/minimal-http-server-eventlib-foreign/libev.c 1970-01-01 00:00:00.000000000 +0000 +++ libwebsockets-4.1.6/minimal-examples/http-server/minimal-http-server-eventlib-foreign/libev.c 2020-12-01 17:40:26.000000000 +0000 @@ -0,0 +1,76 @@ +/* + * lws-minimal-http-server-eventlib-foreign + * + * Written in 2010-2020 by Andy Green + * + * This file is made available under the Creative Commons CC0 1.0 + * Universal Public Domain Dedication. + * + * The libev specific code + */ + +#include + +#include + +#include +#include + +#include "private.h" + +static struct ev_loop *loop_ev; +static struct ev_timer timer_outer_ev; +static struct ev_signal sighandler_ev; + +static void +timer_cb_ev(struct ev_loop *loop, struct ev_timer *watcher, int revents) +{ + foreign_timer_service(loop_ev); +} + +static void +signal_cb_ev(struct ev_loop *loop, struct ev_signal *watcher, int revents) +{ + signal_cb(watcher->signum); +} + +static void +foreign_event_loop_init_and_run_libev(void) +{ + /* we create and start our "foreign loop" */ + + loop_ev = ev_loop_new(0); + + ev_signal_init(&sighandler_ev, signal_cb_ev, SIGINT); + ev_signal_start(loop_ev, &sighandler_ev); + + ev_timer_init(&timer_outer_ev, timer_cb_ev, 0, 1); + ev_timer_start(loop_ev, &timer_outer_ev); + + ev_run(loop_ev, 0); +} + +static void +foreign_event_loop_stop_libev(void) +{ + ev_break(loop_ev, EVBREAK_ALL); +} + +static void +foreign_event_loop_cleanup_libev(void) +{ + /* cleanup the foreign loop assets */ + + ev_timer_stop(loop_ev, &timer_outer_ev); + ev_signal_stop(loop_ev, &sighandler_ev); + + ev_run(loop_ev, 0); + ev_loop_destroy(loop_ev); +} + +const struct ops ops_libev = { + foreign_event_loop_init_and_run_libev, + foreign_event_loop_stop_libev, + foreign_event_loop_cleanup_libev +}; + diff -Nru libwebsockets-3.2.1/minimal-examples/http-server/minimal-http-server-eventlib-foreign/libevent.c libwebsockets-4.1.6/minimal-examples/http-server/minimal-http-server-eventlib-foreign/libevent.c --- libwebsockets-3.2.1/minimal-examples/http-server/minimal-http-server-eventlib-foreign/libevent.c 1970-01-01 00:00:00.000000000 +0000 +++ libwebsockets-4.1.6/minimal-examples/http-server/minimal-http-server-eventlib-foreign/libevent.c 2020-12-01 17:40:26.000000000 +0000 @@ -0,0 +1,84 @@ +/* + * lws-minimal-http-server-eventlib-foreign + * + * Written in 2010-2020 by Andy Green + * + * This file is made available under the Creative Commons CC0 1.0 + * Universal Public Domain Dedication. + * + * The libevent specific code + */ + +#include + +#include + +#include +#include + +#include "private.h" + +static struct event_base *loop_event; +static struct event *timer_outer_event; +static struct event *sighandler_event; + +static void +timer_cb_event(int fd, short event, void *arg) +{ + foreign_timer_service(loop_event); +} + +static void +signal_cb_event(int fd, short event, void *arg) +{ + signal_cb((int)(lws_intptr_t)arg); +} + +static void +foreign_event_loop_init_and_run_libevent(void) +{ + struct timeval tv; + + /* we create and start our "foreign loop" */ + + tv.tv_sec = 1; + tv.tv_usec = 0; + + loop_event = event_base_new(); + + sighandler_event = evsignal_new(loop_event, SIGINT, signal_cb_event, + (void*)SIGINT); + + timer_outer_event = event_new(loop_event, -1, EV_PERSIST, + timer_cb_event, NULL); + //evtimer_new(loop_event, timer_cb_event, NULL); + evtimer_add(timer_outer_event, &tv); + + event_base_loop(loop_event, 0); +} + +static void +foreign_event_loop_stop_libevent(void) +{ + event_base_loopexit(loop_event, NULL); +} + +static void +foreign_event_loop_cleanup_libevent(void) +{ + /* cleanup the foreign loop assets */ + + evtimer_del(timer_outer_event); + event_free(timer_outer_event); + evsignal_del(sighandler_event); + event_free(sighandler_event); + + event_base_loop(loop_event, 0); + event_base_free(loop_event); +} + +const struct ops ops_libevent = { + foreign_event_loop_init_and_run_libevent, + foreign_event_loop_stop_libevent, + foreign_event_loop_cleanup_libevent +}; diff -Nru libwebsockets-3.2.1/minimal-examples/http-server/minimal-http-server-eventlib-foreign/libuv.c libwebsockets-4.1.6/minimal-examples/http-server/minimal-http-server-eventlib-foreign/libuv.c --- libwebsockets-3.2.1/minimal-examples/http-server/minimal-http-server-eventlib-foreign/libuv.c 1970-01-01 00:00:00.000000000 +0000 +++ libwebsockets-4.1.6/minimal-examples/http-server/minimal-http-server-eventlib-foreign/libuv.c 2020-12-01 17:40:26.000000000 +0000 @@ -0,0 +1,91 @@ +/* + * lws-minimal-http-server-eventlib-foreign + * + * Written in 2010-2020 by Andy Green + * + * This file is made available under the Creative Commons CC0 1.0 + * Universal Public Domain Dedication. + * + * The libuv specific code + */ + +#include + +#include +#include + +#include +#ifdef LWS_HAVE_UV_VERSION_H +#include +#endif +#ifdef LWS_HAVE_NEW_UV_VERSION_H +#include +#endif + +#include "private.h" + +static uv_loop_t loop_uv; +static uv_timer_t timer_outer_uv; +static uv_signal_t sighandler_uv; + +static void +timer_cb_uv(uv_timer_t *t) +{ + foreign_timer_service(&loop_uv); +} + +static void +signal_cb_uv(uv_signal_t *watcher, int signum) +{ + signal_cb(signum); +} + +static void +foreign_event_loop_init_and_run_libuv(void) +{ + /* we create and start our "foreign loop" */ + +#if (UV_VERSION_MAJOR > 0) // Travis... + uv_loop_init(&loop_uv); +#endif + uv_signal_init(&loop_uv, &sighandler_uv); + uv_signal_start(&sighandler_uv, signal_cb_uv, SIGINT); + + uv_timer_init(&loop_uv, &timer_outer_uv); +#if (UV_VERSION_MAJOR > 0) // Travis... + uv_timer_start(&timer_outer_uv, timer_cb_uv, 0, 1000); +#else + (void)timer_cb_uv; +#endif + + uv_run(&loop_uv, UV_RUN_DEFAULT); +} + +static void +foreign_event_loop_stop_libuv(void) +{ + uv_stop(&loop_uv); +} + +static void +foreign_event_loop_cleanup_libuv(void) +{ + /* cleanup the foreign loop assets */ + + uv_timer_stop(&timer_outer_uv); + uv_close((uv_handle_t*)&timer_outer_uv, NULL); + uv_signal_stop(&sighandler_uv); + uv_close((uv_handle_t *)&sighandler_uv, NULL); + + uv_run(&loop_uv, UV_RUN_DEFAULT); +#if (UV_VERSION_MAJOR > 0) // Travis... + uv_loop_close(&loop_uv); +#endif +} + +const struct ops ops_libuv = { + foreign_event_loop_init_and_run_libuv, + foreign_event_loop_stop_libuv, + foreign_event_loop_cleanup_libuv +}; + diff -Nru libwebsockets-3.2.1/minimal-examples/http-server/minimal-http-server-eventlib-foreign/minimal-http-server-eventlib-foreign.c libwebsockets-4.1.6/minimal-examples/http-server/minimal-http-server-eventlib-foreign/minimal-http-server-eventlib-foreign.c --- libwebsockets-3.2.1/minimal-examples/http-server/minimal-http-server-eventlib-foreign/minimal-http-server-eventlib-foreign.c 2019-12-18 14:45:31.000000000 +0000 +++ libwebsockets-4.1.6/minimal-examples/http-server/minimal-http-server-eventlib-foreign/minimal-http-server-eventlib-foreign.c 2020-12-01 17:40:26.000000000 +0000 @@ -1,7 +1,7 @@ /* * lws-minimal-http-server-eventlib-foreign * - * Written in 2010-2019 by Andy Green + * Written in 2010-2020 by Andy Green * * This file is made available under the Creative Commons CC0 1.0 * Universal Public Domain Dedication. @@ -23,11 +23,12 @@ #include #include -struct lws_context_creation_info info; -static struct lws_context *context; -static int lifetime = 5, reported; +#include "private.h" -static void foreign_timer_service(void *foreign_loop); +static struct lws_context_creation_info info; +static const struct ops *ops = NULL; +struct lws_context *context; +int lifetime = 5, reported; enum { TEST_STATE_CREATE_LWS_CONTEXT, @@ -57,7 +58,7 @@ /* .basic_auth_login_file */ NULL, }; -static void +void signal_cb(int signum) { lwsl_notice("Signal %d caught, exiting...\n", signum); @@ -73,195 +74,9 @@ lws_context_destroy(context); } -/* - * The event-loop specific foreign loop code, one set for each event loop lib - * - * Only the code in this section is specific to the event library used. - */ - -#if defined(LWS_WITH_LIBUV) - -static uv_loop_t loop_uv; -static uv_timer_t timer_outer_uv; -static uv_signal_t sighandler_uv; - -static void -timer_cb_uv(uv_timer_t *t) -{ - foreign_timer_service(&loop_uv); -} - -static void -signal_cb_uv(uv_signal_t *watcher, int signum) -{ - signal_cb(signum); -} - -static void -foreign_event_loop_init_and_run_libuv(void) -{ - /* we create and start our "foreign loop" */ - -#if (UV_VERSION_MAJOR > 0) // Travis... - uv_loop_init(&loop_uv); -#endif - uv_signal_init(&loop_uv, &sighandler_uv); - uv_signal_start(&sighandler_uv, signal_cb_uv, SIGINT); - - uv_timer_init(&loop_uv, &timer_outer_uv); -#if (UV_VERSION_MAJOR > 0) // Travis... - uv_timer_start(&timer_outer_uv, timer_cb_uv, 0, 1000); -#else - (void)timer_cb_uv; -#endif - - uv_run(&loop_uv, UV_RUN_DEFAULT); -} - -static void -foreign_event_loop_stop_libuv(void) -{ - uv_stop(&loop_uv); -} - -static void -foreign_event_loop_cleanup_libuv(void) -{ - /* cleanup the foreign loop assets */ - - uv_timer_stop(&timer_outer_uv); - uv_close((uv_handle_t*)&timer_outer_uv, NULL); - uv_signal_stop(&sighandler_uv); - uv_close((uv_handle_t *)&sighandler_uv, NULL); - - uv_run(&loop_uv, UV_RUN_DEFAULT); -#if (UV_VERSION_MAJOR > 0) // Travis... - uv_loop_close(&loop_uv); -#endif -} - -#endif - -#if defined(LWS_WITH_LIBEVENT) - -static struct event_base *loop_event; -static struct event *timer_outer_event; -static struct event *sighandler_event; - -static void -timer_cb_event(int fd, short event, void *arg) -{ - foreign_timer_service(loop_event); -} - -static void -signal_cb_event(int fd, short event, void *arg) -{ - signal_cb((int)(lws_intptr_t)arg); -} - -static void -foreign_event_loop_init_and_run_libevent(void) -{ - struct timeval tv; - - /* we create and start our "foreign loop" */ - - tv.tv_sec = 1; - tv.tv_usec = 0; - - loop_event = event_base_new(); - - sighandler_event = evsignal_new(loop_event, SIGINT, signal_cb_event, - (void*)SIGINT); - - timer_outer_event = event_new(loop_event, -1, EV_PERSIST, - timer_cb_event, NULL); - //evtimer_new(loop_event, timer_cb_event, NULL); - evtimer_add(timer_outer_event, &tv); - - event_base_loop(loop_event, 0); -} - -static void -foreign_event_loop_stop_libevent(void) -{ - event_base_loopexit(loop_event, NULL); -} - -static void -foreign_event_loop_cleanup_libevent(void) -{ - /* cleanup the foreign loop assets */ - - evtimer_del(timer_outer_event); - event_free(timer_outer_event); - evsignal_del(sighandler_event); - event_free(sighandler_event); - - event_base_loop(loop_event, 0); - event_base_free(loop_event); -} - -#endif - -#if defined(LWS_WITH_LIBEV) - -static struct ev_loop *loop_ev; -static struct ev_timer timer_outer_ev; -static struct ev_signal sighandler_ev; - -static void -timer_cb_ev(struct ev_loop *loop, struct ev_timer *watcher, int revents) -{ - foreign_timer_service(loop_ev); -} - -static void -signal_cb_ev(struct ev_loop *loop, struct ev_signal *watcher, int revents) -{ - signal_cb(watcher->signum); -} - -static void -foreign_event_loop_init_and_run_libev(void) -{ - /* we create and start our "foreign loop" */ - - loop_ev = ev_loop_new(0); - - ev_signal_init(&sighandler_ev, signal_cb_ev, SIGINT); - ev_signal_start(loop_ev, &sighandler_ev); - - ev_timer_init(&timer_outer_ev, timer_cb_ev, 0, 1); - ev_timer_start(loop_ev, &timer_outer_ev); - - ev_run(loop_ev, 0); -} - -static void -foreign_event_loop_stop_libev(void) -{ - ev_break(loop_ev, EVBREAK_ALL); -} - -static void -foreign_event_loop_cleanup_libev(void) -{ - /* cleanup the foreign loop assets */ - - ev_timer_stop(loop_ev, &timer_outer_ev); - ev_signal_stop(loop_ev, &sighandler_ev); - - ev_run(loop_ev, UV_RUN_DEFAULT); - ev_loop_destroy(loop_ev); -} - -#endif - /* this is called at 1Hz using a foreign loop timer */ -static void +void foreign_timer_service(void *foreign_loop) { void *foreign_loops[1]; @@ -304,18 +119,7 @@ case TEST_STATE_EXIT: lwsl_user("Deciding to exit foreign loop too\n"); -#if defined(LWS_WITH_LIBUV) - if (info.options & LWS_SERVER_OPTION_LIBUV) - foreign_event_loop_stop_libuv(); -#endif -#if defined(LWS_WITH_LIBEVENT) - if (info.options & LWS_SERVER_OPTION_LIBEVENT) - foreign_event_loop_stop_libevent(); -#endif -#if defined(LWS_WITH_LIBEV) - if (info.options & LWS_SERVER_OPTION_LIBEV) - foreign_event_loop_stop_libev(); -#endif + ops->stop(); break; default: break; @@ -360,20 +164,45 @@ info.ssl_private_key_filepath = "localhost-100y.key"; } - if (lws_cmdline_option(argc, argv, "--uv")) + /* + * We configure lws to use the chosen event loop, and select the + * matching event-lib specific code for our demo operations + */ + +#if defined(LWS_WITH_LIBUV) + if (lws_cmdline_option(argc, argv, "--uv")) { info.options |= LWS_SERVER_OPTION_LIBUV; - else - if (lws_cmdline_option(argc, argv, "--event")) + ops = &ops_libuv; + lwsl_notice("%s: using libuv event loop\n", __func__); + } else +#endif +#if defined(LWS_WITH_LIBEVENT) + if (lws_cmdline_option(argc, argv, "--event")) { info.options |= LWS_SERVER_OPTION_LIBEVENT; - else - if (lws_cmdline_option(argc, argv, "--ev")) + ops = &ops_libevent; + lwsl_notice("%s: using libevent loop\n", __func__); + } else +#endif +#if defined(LWS_WITH_LIBEV) + if (lws_cmdline_option(argc, argv, "--ev")) { info.options |= LWS_SERVER_OPTION_LIBEV; - else { + ops = &ops_libev; + lwsl_notice("%s: using libev loop\n", __func__); + } else +#endif +#if defined(LWS_WITH_GLIB) + if (lws_cmdline_option(argc, argv, "--glib")) { + info.options |= LWS_SERVER_OPTION_GLIB; + ops = &ops_glib; + lwsl_notice("%s: using glib loop\n", __func__); + } else +#endif + { lwsl_err("This app only makes sense when used\n"); - lwsl_err(" with a foreign loop, --uv, --event, or --ev\n"); + lwsl_err(" with a foreign loop, --uv, --event, --glib, or --ev\n"); return 1; - } + } lwsl_user(" This app creates a foreign event loop with a timer +\n"); lwsl_user(" signalhandler, and performs a test in three phases:\n"); @@ -389,35 +218,13 @@ /* foreign loop specific startup and run */ -#if defined(LWS_WITH_LIBUV) - if (info.options & LWS_SERVER_OPTION_LIBUV) - foreign_event_loop_init_and_run_libuv(); -#endif -#if defined(LWS_WITH_LIBEVENT) - if (info.options & LWS_SERVER_OPTION_LIBEVENT) - foreign_event_loop_init_and_run_libevent(); -#endif -#if defined(LWS_WITH_LIBEV) - if (info.options & LWS_SERVER_OPTION_LIBEV) - foreign_event_loop_init_and_run_libev(); -#endif + ops->init_and_run(); lws_context_destroy(context); /* foreign loop specific cleanup and exit */ -#if defined(LWS_WITH_LIBUV) - if (info.options & LWS_SERVER_OPTION_LIBUV) - foreign_event_loop_cleanup_libuv(); -#endif -#if defined(LWS_WITH_LIBEVENT) - if (info.options & LWS_SERVER_OPTION_LIBEVENT) - foreign_event_loop_cleanup_libevent(); -#endif -#if defined(LWS_WITH_LIBEV) - if (info.options & LWS_SERVER_OPTION_LIBEV) - foreign_event_loop_cleanup_libev(); -#endif + ops->cleanup(); lwsl_user("%s: exiting...\n", __func__); diff -Nru libwebsockets-3.2.1/minimal-examples/http-server/minimal-http-server-eventlib-foreign/mount-origin/libwebsockets.org-logo.svg libwebsockets-4.1.6/minimal-examples/http-server/minimal-http-server-eventlib-foreign/mount-origin/libwebsockets.org-logo.svg --- libwebsockets-3.2.1/minimal-examples/http-server/minimal-http-server-eventlib-foreign/mount-origin/libwebsockets.org-logo.svg 2019-12-18 14:45:31.000000000 +0000 +++ libwebsockets-4.1.6/minimal-examples/http-server/minimal-http-server-eventlib-foreign/mount-origin/libwebsockets.org-logo.svg 2020-12-01 17:40:26.000000000 +0000 @@ -1,120 +1,66 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + + +image/svg+xml + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff -Nru libwebsockets-3.2.1/minimal-examples/http-server/minimal-http-server-eventlib-foreign/private.h libwebsockets-4.1.6/minimal-examples/http-server/minimal-http-server-eventlib-foreign/private.h --- libwebsockets-3.2.1/minimal-examples/http-server/minimal-http-server-eventlib-foreign/private.h 1970-01-01 00:00:00.000000000 +0000 +++ libwebsockets-4.1.6/minimal-examples/http-server/minimal-http-server-eventlib-foreign/private.h 2020-12-01 17:40:26.000000000 +0000 @@ -0,0 +1,15 @@ + + +struct ops { + void (*init_and_run)(void); + void (*stop)(void); + void (*cleanup)(void); +}; + +extern struct lws_context *context; +extern int lifetime, reported; + +void foreign_timer_service(void *foreign_loop); +void signal_cb(int signum); + +extern const struct ops ops_libuv, ops_libevent, ops_glib, ops_libev; diff -Nru libwebsockets-3.2.1/minimal-examples/http-server/minimal-http-server-eventlib-smp/CMakeLists.txt libwebsockets-4.1.6/minimal-examples/http-server/minimal-http-server-eventlib-smp/CMakeLists.txt --- libwebsockets-3.2.1/minimal-examples/http-server/minimal-http-server-eventlib-smp/CMakeLists.txt 2019-12-18 14:45:31.000000000 +0000 +++ libwebsockets-4.1.6/minimal-examples/http-server/minimal-http-server-eventlib-smp/CMakeLists.txt 2020-12-01 17:40:26.000000000 +0000 @@ -1,91 +1,26 @@ +project(lws-minimal-http-server-eventlib-smp C) cmake_minimum_required(VERSION 2.8) +find_package(libwebsockets CONFIG REQUIRED) +list(APPEND CMAKE_MODULE_PATH ${LWS_CMAKE_DIR}) include(CheckIncludeFile) include(CheckCSourceCompiles) +include(LwsCheckRequirements) set(SAMP lws-minimal-http-server-eventlib-smp) set(SRCS minimal-http-server-eventlib-smp.c) -MACRO(require_pthreads result) - CHECK_INCLUDE_FILE(pthread.h LWS_HAVE_PTHREAD_H) - if (NOT LWS_HAVE_PTHREAD_H) - if (LWS_WITH_MINIMAL_EXAMPLES) - set(result 0) - else() - message(FATAL_ERROR "threading support requires pthreads") - endif() - endif() -ENDMACRO() - -# 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_pthreads(requirements) require_lws_config(LWS_ROLE_H1 1 requirements) -require_lws_config(LWS_WITHOUT_SERVER 0 requirements) +require_lws_config(LWS_WITH_SERVER 1 requirements) if (requirements) add_executable(${SAMP} ${SRCS}) if (websockets_shared) - target_link_libraries(${SAMP} websockets_shared pthread) - add_dependencies(${SAMP} websockets_shared pthread) + target_link_libraries(${SAMP} websockets_shared ${PTHREAD_LIB} ${LIBWEBSOCKETS_DEP_LIBS}) + add_dependencies(${SAMP} websockets_shared ${PTHREAD_LIB}) else() - target_link_libraries(${SAMP} websockets pthread) + target_link_libraries(${SAMP} websockets ${PTHREAD_LIB} ${LIBWEBSOCKETS_DEP_LIBS}) endif() endif() diff -Nru libwebsockets-3.2.1/minimal-examples/http-server/minimal-http-server-eventlib-smp/minimal-http-server-eventlib-smp.c libwebsockets-4.1.6/minimal-examples/http-server/minimal-http-server-eventlib-smp/minimal-http-server-eventlib-smp.c --- libwebsockets-3.2.1/minimal-examples/http-server/minimal-http-server-eventlib-smp/minimal-http-server-eventlib-smp.c 2019-12-18 14:45:31.000000000 +0000 +++ libwebsockets-4.1.6/minimal-examples/http-server/minimal-http-server-eventlib-smp/minimal-http-server-eventlib-smp.c 2020-12-01 17:40:26.000000000 +0000 @@ -18,6 +18,13 @@ #include #include +#if defined(WIN32) +#define HAVE_STRUCT_TIMESPEC +#if defined(pid_t) +#undef pid_t +#endif +#endif + #include #define COUNT_THREADS 8 @@ -115,11 +122,13 @@ } else info.count_threads = COUNT_THREADS; +#if defined(LWS_WITH_TLS) if (lws_cmdline_option(argc, argv, "-s")) { info.options |= LWS_SERVER_OPTION_DO_SSL_GLOBAL_INIT; info.ssl_cert_filepath = "localhost-100y.cert"; info.ssl_private_key_filepath = "localhost-100y.key"; } +#endif if (lws_cmdline_option(argc, argv, "--uv")) info.options |= LWS_SERVER_OPTION_LIBUV; @@ -130,7 +139,10 @@ if (lws_cmdline_option(argc, argv, "--ev")) info.options |= LWS_SERVER_OPTION_LIBEV; else - signal(SIGINT, sigint_handler); + if (lws_cmdline_option(argc, argv, "--glib")) + info.options |= LWS_SERVER_OPTION_GLIB; + else + signal(SIGINT, sigint_handler); context = lws_create_context(&info); if (!context) { diff -Nru libwebsockets-3.2.1/minimal-examples/http-server/minimal-http-server-eventlib-smp/mount-origin/libwebsockets.org-logo.svg libwebsockets-4.1.6/minimal-examples/http-server/minimal-http-server-eventlib-smp/mount-origin/libwebsockets.org-logo.svg --- libwebsockets-3.2.1/minimal-examples/http-server/minimal-http-server-eventlib-smp/mount-origin/libwebsockets.org-logo.svg 2019-12-18 14:45:31.000000000 +0000 +++ libwebsockets-4.1.6/minimal-examples/http-server/minimal-http-server-eventlib-smp/mount-origin/libwebsockets.org-logo.svg 2020-12-01 17:40:26.000000000 +0000 @@ -1,120 +1,66 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + + +image/svg+xml + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff -Nru libwebsockets-3.2.1/minimal-examples/http-server/minimal-http-server-form-get/CMakeLists.txt libwebsockets-4.1.6/minimal-examples/http-server/minimal-http-server-form-get/CMakeLists.txt --- libwebsockets-3.2.1/minimal-examples/http-server/minimal-http-server-form-get/CMakeLists.txt 2019-12-18 14:45:31.000000000 +0000 +++ libwebsockets-4.1.6/minimal-examples/http-server/minimal-http-server-form-get/CMakeLists.txt 2020-12-01 17:40:26.000000000 +0000 @@ -1,77 +1,24 @@ +project(lws-minimal-http-server-form-get C) cmake_minimum_required(VERSION 2.8) +find_package(libwebsockets CONFIG REQUIRED) +list(APPEND CMAKE_MODULE_PATH ${LWS_CMAKE_DIR}) include(CheckCSourceCompiles) +include(LwsCheckRequirements) set(SAMP lws-minimal-http-server-form-get) set(SRCS minimal-http-server-form-get.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_ROLE_H1 1 requirements) -require_lws_config(LWS_WITHOUT_SERVER 0 requirements) +require_lws_config(LWS_WITH_SERVER 1 requirements) if (requirements) add_executable(${SAMP} ${SRCS}) if (websockets_shared) - target_link_libraries(${SAMP} websockets_shared) + target_link_libraries(${SAMP} websockets_shared ${LIBWEBSOCKETS_DEP_LIBS}) add_dependencies(${SAMP} websockets_shared) else() - target_link_libraries(${SAMP} websockets) + target_link_libraries(${SAMP} websockets ${LIBWEBSOCKETS_DEP_LIBS}) endif() endif() diff -Nru libwebsockets-3.2.1/minimal-examples/http-server/minimal-http-server-form-get/mount-origin/libwebsockets.org-logo.svg libwebsockets-4.1.6/minimal-examples/http-server/minimal-http-server-form-get/mount-origin/libwebsockets.org-logo.svg --- libwebsockets-3.2.1/minimal-examples/http-server/minimal-http-server-form-get/mount-origin/libwebsockets.org-logo.svg 2019-12-18 14:45:31.000000000 +0000 +++ libwebsockets-4.1.6/minimal-examples/http-server/minimal-http-server-form-get/mount-origin/libwebsockets.org-logo.svg 2020-12-01 17:40:26.000000000 +0000 @@ -1,120 +1,66 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + + +image/svg+xml + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff -Nru libwebsockets-3.2.1/minimal-examples/http-server/minimal-http-server-form-post/CMakeLists.txt libwebsockets-4.1.6/minimal-examples/http-server/minimal-http-server-form-post/CMakeLists.txt --- libwebsockets-3.2.1/minimal-examples/http-server/minimal-http-server-form-post/CMakeLists.txt 2019-12-18 14:45:31.000000000 +0000 +++ libwebsockets-4.1.6/minimal-examples/http-server/minimal-http-server-form-post/CMakeLists.txt 2020-12-01 17:40:26.000000000 +0000 @@ -1,77 +1,24 @@ +project(lws-minimal-http-server-form-post C) cmake_minimum_required(VERSION 2.8) +find_package(libwebsockets CONFIG REQUIRED) +list(APPEND CMAKE_MODULE_PATH ${LWS_CMAKE_DIR}) include(CheckCSourceCompiles) +include(LwsCheckRequirements) set(SAMP lws-minimal-http-server-form-post) set(SRCS minimal-http-server-form-post.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_ROLE_H1 1 requirements) -require_lws_config(LWS_WITHOUT_SERVER 0 requirements) +require_lws_config(LWS_WITH_SERVER 1 requirements) if (requirements) add_executable(${SAMP} ${SRCS}) if (websockets_shared) - target_link_libraries(${SAMP} websockets_shared) + target_link_libraries(${SAMP} websockets_shared ${LIBWEBSOCKETS_DEP_LIBS}) add_dependencies(${SAMP} websockets_shared) else() - target_link_libraries(${SAMP} websockets) + target_link_libraries(${SAMP} websockets ${LIBWEBSOCKETS_DEP_LIBS}) endif() endif() diff -Nru libwebsockets-3.2.1/minimal-examples/http-server/minimal-http-server-form-post/minimal-http-server-form-post.c libwebsockets-4.1.6/minimal-examples/http-server/minimal-http-server-form-post/minimal-http-server-form-post.c --- libwebsockets-3.2.1/minimal-examples/http-server/minimal-http-server-form-post/minimal-http-server-form-post.c 2019-12-18 14:45:31.000000000 +0000 +++ libwebsockets-4.1.6/minimal-examples/http-server/minimal-http-server-form-post/minimal-http-server-form-post.c 2020-12-01 17:40:26.000000000 +0000 @@ -24,7 +24,7 @@ struct lws_spa *spa; }; -static int interrupted; +static int interrupted, use303; static const char * const param_names[] = { "text1", @@ -81,6 +81,11 @@ return -1; break; + case LWS_CALLBACK_CLOSED_CLIENT_HTTP: + if (pss->spa && lws_spa_destroy(pss->spa)) + return -1; + break; + case LWS_CALLBACK_HTTP_BODY_COMPLETION: /* inform the spa no more payload data coming */ @@ -90,22 +95,27 @@ /* we just dump the decoded things to the log */ - for (n = 0; n < (int)LWS_ARRAY_SIZE(param_names); n++) { - if (!lws_spa_get_string(pss->spa, n)) - lwsl_user("%s: undefined\n", param_names[n]); - else - lwsl_user("%s: (len %d) '%s'\n", - param_names[n], - lws_spa_get_length(pss->spa, n), - lws_spa_get_string(pss->spa, n)); - } + if (pss->spa) + for (n = 0; n < (int)LWS_ARRAY_SIZE(param_names); n++) { + if (!lws_spa_get_string(pss->spa, n)) + lwsl_user("%s: undefined\n", param_names[n]); + else + lwsl_user("%s: (len %d) '%s'\n", + param_names[n], + lws_spa_get_length(pss->spa, n), + lws_spa_get_string(pss->spa, n)); + } + + if (pss->spa && lws_spa_destroy(pss->spa)) + return -1; /* * Our response is to redirect to a static page. We could * have generated a dynamic html page here instead. */ - if (lws_http_redirect(wsi, HTTP_STATUS_MOVED_PERMANENTLY, + if (lws_http_redirect(wsi, use303 ? HTTP_STATUS_SEE_OTHER : + HTTP_STATUS_MOVED_PERMANENTLY, (unsigned char *)"after-form1.html", 16, &p, end) < 0) return -1; @@ -185,12 +195,21 @@ info.mounts = &mount; info.options = LWS_SERVER_OPTION_HTTP_HEADERS_SECURITY_BEST_PRACTICES_ENFORCE; - +#if defined(LWS_WITH_TLS) if (lws_cmdline_option(argc, argv, "-s")) { info.options |= LWS_SERVER_OPTION_DO_SSL_GLOBAL_INIT; info.ssl_cert_filepath = "localhost-100y.cert"; info.ssl_private_key_filepath = "localhost-100y.key"; } +#endif + + if ((p = lws_cmdline_option(argc, argv, "--port"))) + info.port = atoi(p); + + if (lws_cmdline_option(argc, argv, "--303")) { + lwsl_user("%s: using 303 redirect\n", __func__); + use303 = 1; + } context = lws_create_context(&info); if (!context) { diff -Nru libwebsockets-3.2.1/minimal-examples/http-server/minimal-http-server-form-post/mount-origin/libwebsockets.org-logo.svg libwebsockets-4.1.6/minimal-examples/http-server/minimal-http-server-form-post/mount-origin/libwebsockets.org-logo.svg --- libwebsockets-3.2.1/minimal-examples/http-server/minimal-http-server-form-post/mount-origin/libwebsockets.org-logo.svg 2019-12-18 14:45:31.000000000 +0000 +++ libwebsockets-4.1.6/minimal-examples/http-server/minimal-http-server-form-post/mount-origin/libwebsockets.org-logo.svg 2020-12-01 17:40:26.000000000 +0000 @@ -1,120 +1,66 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + + +image/svg+xml + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff -Nru libwebsockets-3.2.1/minimal-examples/http-server/minimal-http-server-form-post-file/CMakeLists.txt libwebsockets-4.1.6/minimal-examples/http-server/minimal-http-server-form-post-file/CMakeLists.txt --- libwebsockets-3.2.1/minimal-examples/http-server/minimal-http-server-form-post-file/CMakeLists.txt 2019-12-18 14:45:31.000000000 +0000 +++ libwebsockets-4.1.6/minimal-examples/http-server/minimal-http-server-form-post-file/CMakeLists.txt 2020-12-01 17:40:26.000000000 +0000 @@ -1,77 +1,24 @@ +project(lws-minimal-http-server-form-post-file C) cmake_minimum_required(VERSION 2.8) +find_package(libwebsockets CONFIG REQUIRED) +list(APPEND CMAKE_MODULE_PATH ${LWS_CMAKE_DIR}) include(CheckCSourceCompiles) +include(LwsCheckRequirements) set(SAMP lws-minimal-http-server-form-post-file) set(SRCS minimal-http-server-form-post-file.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_ROLE_H1 1 requirements) -require_lws_config(LWS_WITHOUT_SERVER 0 requirements) +require_lws_config(LWS_WITH_SERVER 1 requirements) if (requirements) add_executable(${SAMP} ${SRCS}) if (websockets_shared) - target_link_libraries(${SAMP} websockets_shared) + target_link_libraries(${SAMP} websockets_shared ${LIBWEBSOCKETS_DEP_LIBS}) add_dependencies(${SAMP} websockets_shared) else() - target_link_libraries(${SAMP} websockets) + target_link_libraries(${SAMP} websockets ${LIBWEBSOCKETS_DEP_LIBS}) endif() endif() diff -Nru libwebsockets-3.2.1/minimal-examples/http-server/minimal-http-server-form-post-file/minimal-http-server-form-post-file.c libwebsockets-4.1.6/minimal-examples/http-server/minimal-http-server-form-post-file/minimal-http-server-form-post-file.c --- libwebsockets-3.2.1/minimal-examples/http-server/minimal-http-server-form-post-file/minimal-http-server-form-post-file.c 2019-12-18 14:45:31.000000000 +0000 +++ libwebsockets-4.1.6/minimal-examples/http-server/minimal-http-server-form-post-file/minimal-http-server-form-post-file.c 2020-12-01 17:40:26.000000000 +0000 @@ -15,7 +15,9 @@ #include #include #include +#if !defined(WIN32) #include +#endif #include #include #include diff -Nru libwebsockets-3.2.1/minimal-examples/http-server/minimal-http-server-form-post-file/mount-origin/libwebsockets.org-logo.svg libwebsockets-4.1.6/minimal-examples/http-server/minimal-http-server-form-post-file/mount-origin/libwebsockets.org-logo.svg --- libwebsockets-3.2.1/minimal-examples/http-server/minimal-http-server-form-post-file/mount-origin/libwebsockets.org-logo.svg 2019-12-18 14:45:31.000000000 +0000 +++ libwebsockets-4.1.6/minimal-examples/http-server/minimal-http-server-form-post-file/mount-origin/libwebsockets.org-logo.svg 2020-12-01 17:40:26.000000000 +0000 @@ -1,120 +1,66 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + + +image/svg+xml + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff -Nru libwebsockets-3.2.1/minimal-examples/http-server/minimal-http-server-form-post-lwsac/CMakeLists.txt libwebsockets-4.1.6/minimal-examples/http-server/minimal-http-server-form-post-lwsac/CMakeLists.txt --- libwebsockets-3.2.1/minimal-examples/http-server/minimal-http-server-form-post-lwsac/CMakeLists.txt 2019-12-18 14:45:31.000000000 +0000 +++ libwebsockets-4.1.6/minimal-examples/http-server/minimal-http-server-form-post-lwsac/CMakeLists.txt 2020-12-01 17:40:26.000000000 +0000 @@ -1,77 +1,24 @@ +project(lws-minimal-http-server-form-post-lwsac C) cmake_minimum_required(VERSION 2.8) +find_package(libwebsockets CONFIG REQUIRED) +list(APPEND CMAKE_MODULE_PATH ${LWS_CMAKE_DIR}) include(CheckCSourceCompiles) +include(LwsCheckRequirements) set(SAMP lws-minimal-http-server-form-post-lwsac) set(SRCS minimal-http-server-form-post.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_ROLE_H1 1 requirements) -require_lws_config(LWS_WITHOUT_SERVER 0 requirements) +require_lws_config(LWS_WITH_SERVER 1 requirements) if (requirements) add_executable(${SAMP} ${SRCS}) if (websockets_shared) - target_link_libraries(${SAMP} websockets_shared) + target_link_libraries(${SAMP} websockets_shared ${LIBWEBSOCKETS_DEP_LIBS}) add_dependencies(${SAMP} websockets_shared) else() - target_link_libraries(${SAMP} websockets) + target_link_libraries(${SAMP} websockets ${LIBWEBSOCKETS_DEP_LIBS}) endif() endif() diff -Nru libwebsockets-3.2.1/minimal-examples/http-server/minimal-http-server-form-post-lwsac/minimal-http-server-form-post.c libwebsockets-4.1.6/minimal-examples/http-server/minimal-http-server-form-post-lwsac/minimal-http-server-form-post.c --- libwebsockets-3.2.1/minimal-examples/http-server/minimal-http-server-form-post-lwsac/minimal-http-server-form-post.c 2019-12-18 14:45:31.000000000 +0000 +++ libwebsockets-4.1.6/minimal-examples/http-server/minimal-http-server-form-post-lwsac/minimal-http-server-form-post.c 2020-12-01 17:40:26.000000000 +0000 @@ -198,8 +198,10 @@ if (lws_cmdline_option(argc, argv, "-s")) { info.options |= LWS_SERVER_OPTION_DO_SSL_GLOBAL_INIT; +#if defined(LWS_WITH_TLS) info.ssl_cert_filepath = "localhost-100y.cert"; info.ssl_private_key_filepath = "localhost-100y.key"; +#endif } context = lws_create_context(&info); diff -Nru libwebsockets-3.2.1/minimal-examples/http-server/minimal-http-server-fulltext-search/CMakeLists.txt libwebsockets-4.1.6/minimal-examples/http-server/minimal-http-server-fulltext-search/CMakeLists.txt --- libwebsockets-3.2.1/minimal-examples/http-server/minimal-http-server-fulltext-search/CMakeLists.txt 2019-12-18 14:45:31.000000000 +0000 +++ libwebsockets-4.1.6/minimal-examples/http-server/minimal-http-server-fulltext-search/CMakeLists.txt 2020-12-01 17:40:26.000000000 +0000 @@ -1,82 +1,27 @@ +project(lws-minimal-http-server-fulltext-search C) cmake_minimum_required(VERSION 2.8) +find_package(libwebsockets CONFIG REQUIRED) +list(APPEND CMAKE_MODULE_PATH ${LWS_CMAKE_DIR}) include(CheckCSourceCompiles) +include(LwsCheckRequirements) set(SAMP lws-minimal-http-server-fulltext-search) set(SRCS minimal-http-server.c) include_directories(../../../plugins) -# 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_ROLE_H1 1 requirements) require_lws_config(LWS_WITH_FTS 1 requirements) -require_lws_config(LWS_WITHOUT_SERVER 0 requirements) +require_lws_config(LWS_WITH_SERVER 1 requirements) if (requirements) add_executable(${SAMP} ${SRCS}) if (websockets_shared) - target_link_libraries(${SAMP} websockets_shared) + target_link_libraries(${SAMP} websockets_shared ${LIBWEBSOCKETS_DEP_LIBS}) add_dependencies(${SAMP} websockets_shared) else() - target_link_libraries(${SAMP} websockets) + target_link_libraries(${SAMP} websockets ${LIBWEBSOCKETS_DEP_LIBS}) endif() endif() diff -Nru libwebsockets-3.2.1/minimal-examples/http-server/minimal-http-server-fulltext-search/mount-origin/libwebsockets.org-logo.svg libwebsockets-4.1.6/minimal-examples/http-server/minimal-http-server-fulltext-search/mount-origin/libwebsockets.org-logo.svg --- libwebsockets-3.2.1/minimal-examples/http-server/minimal-http-server-fulltext-search/mount-origin/libwebsockets.org-logo.svg 2019-12-18 14:45:31.000000000 +0000 +++ libwebsockets-4.1.6/minimal-examples/http-server/minimal-http-server-fulltext-search/mount-origin/libwebsockets.org-logo.svg 2020-12-01 17:40:26.000000000 +0000 @@ -1,120 +1,66 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + + +image/svg+xml + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff -Nru libwebsockets-3.2.1/minimal-examples/http-server/minimal-http-server-fulltext-search/mount-origin/lws-fts.js libwebsockets-4.1.6/minimal-examples/http-server/minimal-http-server-fulltext-search/mount-origin/lws-fts.js --- libwebsockets-3.2.1/minimal-examples/http-server/minimal-http-server-fulltext-search/mount-origin/lws-fts.js 2019-12-18 14:45:31.000000000 +0000 +++ libwebsockets-4.1.6/minimal-examples/http-server/minimal-http-server-fulltext-search/mount-origin/lws-fts.js 2020-12-01 17:40:26.000000000 +0000 @@ -1,21 +1,35 @@ /* lws-fts.js - JS supporting lws fulltext search * - * Copyright (C) 2018 Andy Green + * Copyright (C) 2010 - 2019 Andy Green * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation: - * version 2.1 of the License. + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to + * deal in the Software without restriction, including without limitation the + * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or + * sell copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS + * IN THE SOFTWARE. */ + (function() { var last_ac = ""; function san(s) { - s.replace("<", "!"); - s.replace("%", "!"); + s.replace(/"; @@ -115,7 +124,7 @@ xhr.setRequestHeader("cache-control", "max-age=0"); }; xhr.onload = function(e) { - var jj, n, s = "", x, lic = 0; + var jj, n, s = "", lic = 0; var inp = document.getElementById("lws_fts"); var ac = document.getElementById("acomplete"); @@ -208,4 +217,4 @@ }, false); -}()); \ No newline at end of file +}()); diff -Nru libwebsockets-3.2.1/minimal-examples/http-server/minimal-http-server-generic-sessions/CMakeLists.txt libwebsockets-4.1.6/minimal-examples/http-server/minimal-http-server-generic-sessions/CMakeLists.txt --- libwebsockets-3.2.1/minimal-examples/http-server/minimal-http-server-generic-sessions/CMakeLists.txt 2019-12-18 14:45:31.000000000 +0000 +++ libwebsockets-4.1.6/minimal-examples/http-server/minimal-http-server-generic-sessions/CMakeLists.txt 1970-01-01 00:00:00.000000000 +0000 @@ -1,82 +0,0 @@ -cmake_minimum_required(VERSION 2.8) -include(CheckCSourceCompiles) - -set(SAMP lws-minimal-http-server-generic-sessions) -set(SRCS minimal-http-server-generic-sessions.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_ROLE_H1 1 requirements) -require_lws_config(LWS_WITHOUT_SERVER 0 requirements) -require_lws_config(LWS_OPENSSL_SUPPORT 1 requirements) -require_lws_config(LWS_WITH_GENERIC_SESSIONS 1 requirements) -require_lws_config(LWS_WITH_LIBUV 1 requirements) -require_lws_config(LWS_WITH_PLUGINS 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 -Nru libwebsockets-3.2.1/minimal-examples/http-server/minimal-http-server-generic-sessions/localhost-100y.cert libwebsockets-4.1.6/minimal-examples/http-server/minimal-http-server-generic-sessions/localhost-100y.cert --- libwebsockets-3.2.1/minimal-examples/http-server/minimal-http-server-generic-sessions/localhost-100y.cert 2019-12-18 14:45:31.000000000 +0000 +++ libwebsockets-4.1.6/minimal-examples/http-server/minimal-http-server-generic-sessions/localhost-100y.cert 1970-01-01 00:00:00.000000000 +0000 @@ -1,34 +0,0 @@ ------BEGIN CERTIFICATE----- -MIIF5jCCA86gAwIBAgIJANq50IuwPFKgMA0GCSqGSIb3DQEBCwUAMIGGMQswCQYD -VQQGEwJHQjEQMA4GA1UECAwHRXJld2hvbjETMBEGA1UEBwwKQWxsIGFyb3VuZDEb -MBkGA1UECgwSbGlid2Vic29ja2V0cy10ZXN0MRIwE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EFgQU -9mYU23tW2zsomkKTAXarjr2vjuswHwYDVR0jBBgwFoAU9mYU23tW2zsomkKTAXar -jr2vjuswDwYDVR0TAQH/BAUwAwEB/zANBgkqhkiG9w0BAQsFAAOCAgEANjIBMrow -YNCbhAJdP7dhlhT2RUFRdeRUJD0IxrH/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 -Nru libwebsockets-3.2.1/minimal-examples/http-server/minimal-http-server-generic-sessions/localhost-100y.key libwebsockets-4.1.6/minimal-examples/http-server/minimal-http-server-generic-sessions/localhost-100y.key --- libwebsockets-3.2.1/minimal-examples/http-server/minimal-http-server-generic-sessions/localhost-100y.key 2019-12-18 14:45:31.000000000 +0000 +++ libwebsockets-4.1.6/minimal-examples/http-server/minimal-http-server-generic-sessions/localhost-100y.key 1970-01-01 00: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iGhhHesgRrs -fBrpEY1IATtPq1taBZZogRqI3rOkkPk= ------END PRIVATE KEY----- diff -Nru libwebsockets-3.2.1/minimal-examples/http-server/minimal-http-server-generic-sessions/minimal-http-server-generic-sessions.c libwebsockets-4.1.6/minimal-examples/http-server/minimal-http-server-generic-sessions/minimal-http-server-generic-sessions.c --- libwebsockets-3.2.1/minimal-examples/http-server/minimal-http-server-generic-sessions/minimal-http-server-generic-sessions.c 2019-12-18 14:45:31.000000000 +0000 +++ libwebsockets-4.1.6/minimal-examples/http-server/minimal-http-server-generic-sessions/minimal-http-server-generic-sessions.c 1970-01-01 00:00:00.000000000 +0000 @@ -1,202 +0,0 @@ -/* - * lws-minimal-http-server-generic-sessions - * - * Copyright (C) 2019 Andy Green - * - * This file is made available under the Creative Commons CC0 1.0 - * Universal Public Domain Dedication. - * - * This demonstrates setting up and using generic sessions - */ - -#include -#include -#include - -static int interrupted; -struct lws_context *context; - -static const struct lws_protocol_vhost_options - pvo_mm1 = { - NULL, NULL, "message-db", (void *)"/var/www/sessions/messageboard.sqlite3" -}, pvo_m1 = { - NULL, &pvo_mm1, "protocol-lws-messageboard", "" -}, - - pvo13 = { - NULL, NULL, "email-confirm-url-base", (void *)"https://localhost:7681/" -}, pvo12 = { - &pvo13, NULL, "urlroot", (void *)"https://127.0.0.1:7681/" -}, pvo11 = { - &pvo12, NULL, "email-contact-person", (void *)"andy@warmcat.com" -}, pvo10 = { - &pvo11, NULL, "email-helo", (void *)"warmcat.com" -}, pvo9 = { - &pvo10, NULL, "email-expire", (void *)"3600" -}, pvo8 = { - &pvo9, NULL, "email-smtp-ip", (void *)"127.0.0.1" -}, pvo7 = { - &pvo8, NULL, "email-from", (void *)"noreply@warmcat.com" -}, pvo6 = { - &pvo7, NULL, "confounder", (void *)"some kind of secret confounder" -}, pvo5 = { - &pvo6, NULL, "timeout-anon-idle-secs", (void *)"1200" -}, pvo4 = { - &pvo5, NULL, "timeout-idle-secs", (void *)"6000" -}, pvo3 = { - &pvo4, NULL, "session-db", (void *)"/var/www/sessions/lws.sqlite3" -}, pvo2 = { - &pvo3, NULL, "admin-password-sha256", - (void *)"25d08521d996bad92605f5a40fe71179dc968e70f669cb1db6190dcd53258200" /* pvo value */ -}, pvo1 = { - &pvo2, NULL, "admin-user", (void *)"admin" -}, pvo = { - &pvo_m1, &pvo1, "protocol-generic-sessions", "" -}, - - interpret1 = { - NULL, NULL, ".js", "protocol-lws-messageboard" -}, - - pvo_hsbph[] = {{ - NULL, NULL, "referrer-policy:", "no-referrer" -}, { - &pvo_hsbph[0], NULL, "x-xss-protection:", "1; mode=block" -}, { - &pvo_hsbph[1], NULL, "x-content-type-options:", "nosniff" -}, { - &pvo_hsbph[2], NULL, "content-security-policy:", - "default-src 'self'; " - "img-src https://www.gravatar.com 'self' data: ; " - "script-src 'self'; " - "font-src 'self'; " - "style-src 'self'; " - "connect-src 'self'; " - "frame-ancestors 'self'; " - "base-uri 'none'; " - "form-action 'self';" -}}; - - static const struct lws_http_mount mount2 = { - /* .mount_next */ NULL, /* linked-list "next" */ - /* .mountpoint */ "/needadmin", /* mountpoint URL */ - /* .origin */ "./mount-origin/needadmin", /* serve from dir */ - /* .def */ "index.html", /* default filename */ - /* .protocol */ "protocol-lws-messageboard", - /* .cgienv */ NULL, - /* .extra_mimetypes */ NULL, - /* .interpret */ &interpret1, - /* .cgi_timeout */ 0, - /* .cache_max_age */ 0, - /* .auth_mask */ 7, - /* .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, - }; - - static const struct lws_http_mount mount1 = { - /* .mount_next */ &mount2, /* linked-list "next" */ - /* .mountpoint */ "/needauth", /* mountpoint URL */ - /* .origin */ "./mount-origin/needauth", /* serve from dir */ - /* .def */ "index.html", /* default filename */ - /* .protocol */ "protocol-lws-messageboard", - /* .cgienv */ NULL, - /* .extra_mimetypes */ NULL, - /* .interpret */ &interpret1, - /* .cgi_timeout */ 0, - /* .cache_max_age */ 0, - /* .auth_mask */ 5, - /* .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, - }; - -static const struct lws_http_mount mount = { - /* .mount_next */ &mount1, /* linked-list "next" */ - /* .mountpoint */ "/", /* mountpoint URL */ - /* .origin */ "./mount-origin", /* serve from dir */ - /* .def */ "index.html", /* default filename */ - /* .protocol */ "protocol-lws-messageboard", - /* .cgienv */ NULL, - /* .extra_mimetypes */ NULL, - /* .interpret */ &interpret1, - /* .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) -{ - lws_context_destroy(context); - - interrupted = 1; -} - -int main(int argc, const char **argv) -{ - struct lws_context_creation_info info; - const char *p, *plugin_dirs[] = { - "/usr/local/share/libwebsockets-test-server/plugins", - NULL }; - int n = 0, logs = LLL_USER | LLL_ERR | LLL_WARN | LLL_NOTICE - /* for LLL_ verbosity above NOTICE to be built into lws, - * lws must have been configured and built with - * -DCMAKE_BUILD_TYPE=DEBUG instead of =RELEASE */ - /* | LLL_INFO */ /* | LLL_PARSER */ /* | LLL_HEADER */ - /* | LLL_EXT */ /* | LLL_CLIENT */ /* | LLL_LATENCY */ - /* | LLL_DEBUG */; - - if ((p = lws_cmdline_option(argc, argv, "-d"))) - logs = atoi(p); - - lws_set_log_level(logs, NULL); - lwsl_user("LWS minimal http server TLS | visit https://localhost:7681\n"); - - 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 | - LWS_SERVER_OPTION_EXPLICIT_VHOSTS; - info.ssl_cert_filepath = "localhost-100y.cert"; - info.ssl_private_key_filepath = "localhost-100y.key"; - info.plugin_dirs = plugin_dirs; - info.pvo = &pvo; - - if (lws_cmdline_option(argc, argv, "-h")) - info.options |= LWS_SERVER_OPTION_VHOST_UPG_STRICT_HOST_CHECK; - - context = lws_create_context(&info); - if (!context) { - lwsl_err("lws init failed\n"); - return 1; - } - - info.headers = &pvo_hsbph[3]; - - if (!lws_create_vhost(context, &info)) { - lwsl_err("lws init failed\n"); - return 1; - } - - while (n >= 0 && !interrupted) - n = lws_service(context, 0); - - lws_context_destroy(context); - - return 0; -} diff -Nru libwebsockets-3.2.1/minimal-examples/http-server/minimal-http-server-generic-sessions/mount-origin/404.html libwebsockets-4.1.6/minimal-examples/http-server/minimal-http-server-generic-sessions/mount-origin/404.html --- libwebsockets-3.2.1/minimal-examples/http-server/minimal-http-server-generic-sessions/mount-origin/404.html 2019-12-18 14:45:31.000000000 +0000 +++ libwebsockets-4.1.6/minimal-examples/http-server/minimal-http-server-generic-sessions/mount-origin/404.html 1970-01-01 00:00:00.000000000 +0000 @@ -1,11 +0,0 @@ - - - - -
- -

404

- Sorry, that file doesn't exist. - - - diff -Nru libwebsockets-3.2.1/minimal-examples/http-server/minimal-http-server-generic-sessions/mount-origin/admin-login.html libwebsockets-4.1.6/minimal-examples/http-server/minimal-http-server-generic-sessions/mount-origin/admin-login.html --- libwebsockets-3.2.1/minimal-examples/http-server/minimal-http-server-generic-sessions/mount-origin/admin-login.html 2019-12-18 14:45:31.000000000 +0000 +++ libwebsockets-4.1.6/minimal-examples/http-server/minimal-http-server-generic-sessions/mount-origin/admin-login.html 1970-01-01 00:00:00.000000000 +0000 @@ -1,5 +0,0 @@ - -This is an example destination that will appear after successful Admin login. - -This URL cannot be served if you're not logged in as admin. - diff -Nru libwebsockets-3.2.1/minimal-examples/http-server/minimal-http-server-generic-sessions/mount-origin/example.js libwebsockets-4.1.6/minimal-examples/http-server/minimal-http-server-generic-sessions/mount-origin/example.js --- libwebsockets-3.2.1/minimal-examples/http-server/minimal-http-server-generic-sessions/mount-origin/example.js 2019-12-18 14:45:31.000000000 +0000 +++ libwebsockets-4.1.6/minimal-examples/http-server/minimal-http-server-generic-sessions/mount-origin/example.js 1970-01-01 00:00:00.000000000 +0000 @@ -1,22 +0,0 @@ -document.addEventListener("DOMContentLoaded", function() { - - var transport_protocol = ""; - - if ( performance && performance.timing.nextHopProtocol ) { - transport_protocol = performance.timing.nextHopProtocol; - } else if ( window.chrome && window.chrome.loadTimes ) { - transport_protocol = window.chrome.loadTimes().connectionInfo; - } else { - - var p = performance.getEntriesByType("resource"); - for (var i=0; i < p.length; i++) { - var value = "nextHopProtocol" in p[i]; - if (value) - transport_protocol = p[i].nextHopProtocol; - } - } - - if (transport_protocol == "h2") - document.getElementById("transport").innerHTML = ""; - } -}, false); \ No newline at end of file diff -Nru libwebsockets-3.2.1/minimal-examples/http-server/minimal-http-server-generic-sessions/mount-origin/failed-login.html libwebsockets-4.1.6/minimal-examples/http-server/minimal-http-server-generic-sessions/mount-origin/failed-login.html --- libwebsockets-3.2.1/minimal-examples/http-server/minimal-http-server-generic-sessions/mount-origin/failed-login.html 2019-12-18 14:45:31.000000000 +0000 +++ libwebsockets-4.1.6/minimal-examples/http-server/minimal-http-server-generic-sessions/mount-origin/failed-login.html 1970-01-01 00:00:00.000000000 +0000 @@ -1,3 +0,0 @@ - -This is an example destination that will appear after a failed login - Binary files /tmp/tmp2l8bmswe/3lv7Sxvgkv/libwebsockets-3.2.1/minimal-examples/http-server/minimal-http-server-generic-sessions/mount-origin/favicon.ico and /tmp/tmp2l8bmswe/LwTwoWz49Q/libwebsockets-4.1.6/minimal-examples/http-server/minimal-http-server-generic-sessions/mount-origin/favicon.ico differ Binary files /tmp/tmp2l8bmswe/3lv7Sxvgkv/libwebsockets-3.2.1/minimal-examples/http-server/minimal-http-server-generic-sessions/mount-origin/http2.png and /tmp/tmp2l8bmswe/LwTwoWz49Q/libwebsockets-4.1.6/minimal-examples/http-server/minimal-http-server-generic-sessions/mount-origin/http2.png differ diff -Nru libwebsockets-3.2.1/minimal-examples/http-server/minimal-http-server-generic-sessions/mount-origin/index.html libwebsockets-4.1.6/minimal-examples/http-server/minimal-http-server-generic-sessions/mount-origin/index.html --- libwebsockets-3.2.1/minimal-examples/http-server/minimal-http-server-generic-sessions/mount-origin/index.html 2019-12-18 14:45:31.000000000 +0000 +++ libwebsockets-4.1.6/minimal-examples/http-server/minimal-http-server-generic-sessions/mount-origin/index.html 1970-01-01 00:00:00.000000000 +0000 @@ -1,57 +0,0 @@ - - - - - - - - - - - - - - - - - -
-
-
- -
- - This is a demo application for lws generic-sessions.

- It's a simple messageboard.

- What's interesting about it is there is no serverside scripting,
- instead client js makes a wss:// connection back to the server
- and then reacts to JSON from the ws protocol. Sessions stuff is
- handled by lws generic sessions, making the actual
- test application
very small.

- And because it's natively websocket, it's naturally connected
- for dynamic events and easy to maintain. -

- Register / Login at the top right to see and create new messages. -
- -
-
- New message
-
- -
-
-
-
- -
- -
-
- - - diff -Nru libwebsockets-3.2.1/minimal-examples/http-server/minimal-http-server-generic-sessions/mount-origin/libwebsockets.org-logo.svg libwebsockets-4.1.6/minimal-examples/http-server/minimal-http-server-generic-sessions/mount-origin/libwebsockets.org-logo.svg --- libwebsockets-3.2.1/minimal-examples/http-server/minimal-http-server-generic-sessions/mount-origin/libwebsockets.org-logo.svg 2019-12-18 14:45:31.000000000 +0000 +++ libwebsockets-4.1.6/minimal-examples/http-server/minimal-http-server-generic-sessions/mount-origin/libwebsockets.org-logo.svg 1970-01-01 00:00:00.000000000 +0000 @@ -1,120 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - diff -Nru libwebsockets-3.2.1/minimal-examples/http-server/minimal-http-server-generic-sessions/mount-origin/lws-common.js libwebsockets-4.1.6/minimal-examples/http-server/minimal-http-server-generic-sessions/mount-origin/lws-common.js --- libwebsockets-3.2.1/minimal-examples/http-server/minimal-http-server-generic-sessions/mount-origin/lws-common.js 2019-12-18 14:45:31.000000000 +0000 +++ libwebsockets-4.1.6/minimal-examples/http-server/minimal-http-server-generic-sessions/mount-origin/lws-common.js 1970-01-01 00:00:00.000000000 +0000 @@ -1,128 +0,0 @@ -/* - * This section around grayOut came from here: - * http://www.codingforums.com/archive/index.php/t-151720.html - * Assumed public domain - * - * Init like this in your main html script, this also reapplies the gray - * - * lws_gray_out(true,{'zindex':'499'}); - * - * To remove the gray - * - * lws_gray_out(false); - * - */ - -function gsize(ptype) -{ - var h = document.compatMode === "CSS1Compat" && - !window.opera ? - document.documentElement.clientHeight : - document.body.clientHeight; - var w = document.compatMode === "CSS1Compat" && - !window.opera ? - document.documentElement.clientWidth : - document.body.clientWidth; - var pageWidth, pageHeight, t; - - if (document.body && - (document.body.scrollWidth || document.body.scrollHeight)) { - t = document.body.scrollWidth; - pageWidth = (w > t) ? ("" + w + "px") : ("" + (t) + "px"); - t = document.body.scrollHeight; - pageHeight = (h > t) ? ("" + h + "px") : ("" + (t) + "px"); - } else if (document.body.offsetWidth) { - t = document.body.offsetWidth; - pageWidth = (w > t) ? ("" + w + "px") : ("" + (t) + "px"); - t = document.body.offsetHeight; - pageHeight =(h > t) ? ("" + h + "px") : ("" + (t) + "px"); - } else { - pageWidth = "100%"; - pageHeight = "100%"; - } - return (ptype === 1) ? pageWidth : pageHeight; -} - -function addEvent( obj, type, fn ) { - if ( obj.attachEvent ) { - obj["e" + type + fn] = fn; - obj[type+fn] = function() { obj["e" + type + fn]( window.event );}; - obj.attachEvent("on" + type, obj[type + fn]); - } else - obj.addEventListener(type, fn, false); -} - -function removeEvent( obj, type, fn ) { - if ( obj.detachEvent ) { - obj.detachEvent("on" + type, obj[type + fn]); - obj[type + fn] = null; - } else - obj.removeEventListener(type, fn, false); -} - -function lws_gray_out(vis, _options) { - - var options = _options || {}; - var zindex = options.zindex || 50; - var opacity = options.opacity || 70; - var opaque = (opacity / 100); - var bgcolor = options.bgcolor || "#000000"; - var dark = document.getElementById("darkenScreenObject"); - - if (!dark) { - var tbody = document.getElementsByTagName("body")[0]; - var tnode = document.createElement("div"); - tnode.style.position = "absolute"; - tnode.style.top = "0px"; - tnode.style.left = "0px"; - tnode.style.overflow = "hidden"; - tnode.style.display ="none"; - tnode.id = "darkenScreenObject"; - tbody.appendChild(tnode); - dark = document.getElementById("darkenScreenObject"); - } - if (vis) { - dark.style.opacity = opaque; - dark.style.MozOpacity = opaque; - // dark.style.filter ='alpha(opacity='+opacity+')'; - dark.style.zIndex = zindex; - dark.style.backgroundColor = bgcolor; - dark.style.width = gsize(1); - dark.style.height = gsize(0); - dark.style.display = "block"; - addEvent(window, "resize", - function() { - dark.style.height = gsize(0); - dark.style.width = gsize(1); - } - ); - } else { - dark.style.display = "none"; - removeEvent(window, "resize", - function() { - dark.style.height = gsize(0); - dark.style.width = gsize(1); - } - ); - } -} - -/* - * end of grayOut related stuff - */ - -function new_ws(urlpath, protocol) -{ - if (typeof MozWebSocket != "undefined") - return new MozWebSocket(urlpath, protocol); - - return new WebSocket(urlpath, protocol); -} - -function lws_san(s) -{ - if (s.search("<") !== -1) - return "invalid string"; - - return s; -} diff -Nru libwebsockets-3.2.1/minimal-examples/http-server/minimal-http-server-generic-sessions/mount-origin/lwsgs.css libwebsockets-4.1.6/minimal-examples/http-server/minimal-http-server-generic-sessions/mount-origin/lwsgs.css --- libwebsockets-3.2.1/minimal-examples/http-server/minimal-http-server-generic-sessions/mount-origin/lwsgs.css 2019-12-18 14:45:31.000000000 +0000 +++ libwebsockets-4.1.6/minimal-examples/http-server/minimal-http-server-generic-sessions/mount-origin/lwsgs.css 1970-01-01 00:00:00.000000000 +0000 @@ -1,144 +0,0 @@ -.body { font-size: 12px } -.gstitle { font-size: 18px } - -.group1 { - vertical-align:middle; - text-align:center; - background:#f0f0e0; - padding:12px; - border-radius:10px; -} -.group2 { - display:block; - vertical-align:middle; - font-size: 22px; - text-align:center; - margin:auto; - align:center; - background-color: rgba(255, 255, 255, 0.8); - padding:12px; - border-radius:10px; -} - -body { - background-color: rgba(205, 205, 205, 1); -} - -div.lwsgs { - z-index: 3; - text-align:right; - background-color: rgba(255, 255, 255, 0.8); -} - -table.lwsgs { - width:100%; - height:100%; - transition: max-height 2s; -} -table.c100 { - text-align:center; - width:100%; -} - -table.r { - vertical-align:top; - text-align:right; -} - -table.l { - vertical-align:top; - text-align:left; -} - -table.fixed { - table-layout: fixed; -} - -td.logo { - vertical-align:top; - text-align:left; - width:200px -} - -td.rlogo { - vertical-align:top; - text-align:right -} - -td.lwsgs { - vertical-align:top; - float:right; -} - -td.h99 { - height:99%; - vertical-align:middle; -} - -td.c { - margin:auto; - align:center -} - -td.tac { - text-align:center -} - -td.ava { - display:inline-block; - vertical-align:top; - word-wrap:break-word; -} - -iframe.hidden { - display:none; -} - -div.hidden { - display:none; -} - -div.hiddenr { - display:none; - text-align:right; -} - -input { - margin: 2px; - padding: 2px; -} - -input.em { - margin: 4px; - font-weight:bold; -} - -input.wide { - margin: 6px; - padding: 6px; -} - -input.hidden { - display: none; -} - -form.r { - text-align:right; -} - -span.bad { - color: red; -} - -span.small { - font-size:8pt; -} - -img.av { - width: 64px; - height: 64px; -} - -.green { - color: green; -} diff -Nru libwebsockets-3.2.1/minimal-examples/http-server/minimal-http-server-generic-sessions/mount-origin/lwsgs.js libwebsockets-4.1.6/minimal-examples/http-server/minimal-http-server-generic-sessions/mount-origin/lwsgs.js --- libwebsockets-3.2.1/minimal-examples/http-server/minimal-http-server-generic-sessions/mount-origin/lwsgs.js 2019-12-18 14:45:31.000000000 +0000 +++ libwebsockets-4.1.6/minimal-examples/http-server/minimal-http-server-generic-sessions/mount-origin/lwsgs.js 1970-01-01 00:00:00.000000000 +0000 @@ -1,637 +0,0 @@ - - -var lwsgs_user = "$lwsgs_user"; -var lwsgs_auth = "$lwsgs_auth"; -var lwsgs_email = "$lwsgs_email"; - -var lwsgs_html = '\ - \ -\ -
\ -
\ - \ - \ - \ - \ -
\ - \ -
\ - \ -
\ -\ - \ - \ - \ - \ - \ -'; - -/*-- this came from - -- https://raw.githubusercontent.com/blueimp/JavaScript-MD5/master/js/md5.min.js - -- under MIT license */ -!function(n){"use strict";function t(n,t){var r=(65535&n)+(65535&t),e=(n>>16)+(t>>16)+(r>>16);return e<<16|65535&r}function r(n,t){return n<>>32-t}function e(n,e,o,u,c,f){return t(r(t(t(e,n),t(u,f)),c),o)}function o(n,t,r,o,u,c,f){return e(t&r|~t&o,n,t,u,c,f)}function u(n,t,r,o,u,c,f){return e(t&o|r&~o,n,t,u,c,f)}function c(n,t,r,o,u,c,f){return e(t^r^o,n,t,u,c,f)}function f(n,t,r,o,u,c,f){return e(r^(t|~o),n,t,u,c,f)}function i(n,r){n[r>>5]|=128<>>9<<4)+14]=r;var e,i,a,h,d,l=1732584193,g=-271733879,v=-1732584194,m=271733878;for(e=0;e>5]>>>t%32&255);return r}function h(n){var t,r=[];for(r[(n.length>>2)-1]=void 0,t=0;t>5]|=(255&n.charCodeAt(t/8))<16&&(o=i(o,8*n.length)),r=0;16>r;r+=1)u[r]=909522486^o[r],c[r]=1549556828^o[r];return e=i(u.concat(h(t)),512+8*t.length),a(i(c.concat(e),640))}function g(n){var t,r,e="0123456789abcdef",o="";for(r=0;r>>4&15)+e.charAt(15&t);return o}function v(n){return unescape(encodeURIComponent(n))}function m(n){return d(v(n))}function p(n){return g(m(n))}function s(n,t){return l(v(n),v(t))}function C(n,t){return g(s(n,t))}function A(n,t,r){return t?r?s(t,n):C(t,n):r?m(n):p(n)}"function"==typeof define&&define.amd?define(function(){return A}):"object"==typeof module&&module.exports?module.exports=A:n.md5=A}(this); - -if (lwsgs_user.substring(0, 1) == "$") { - alert("lwsgs.js: lws generic sessions misconfigured and not providing vars"); -} -function lwsgs_san(s) -{ - if (s.search("<") != -1) - return "invalid string"; - - return s; -} - -function lwsgs_update() -{ - var en_login = 1, en_forgot = 1; - - if (document.getElementById('password').value.length && - document.getElementById('password').value.length < 8) - en_login = 0; - - if (!document.getElementById('username').value || - !document.getElementById('password').value) - en_login = 0; - - if (!document.getElementById('username').value || - document.getElementById('password').value) - en_forgot = 0; - - document.getElementById('login').disabled = !en_login; - document.getElementById('forgot').disabled = !en_forgot; - - if (lwsgs_user) - document.getElementById("curuser").innerHTML = lwsgs_san(lwsgs_user); - - if (lwsgs_user === "") - document.getElementById("dlogin").style.display = "inline"; - else - document.getElementById("dlogout").style.display = "inline"; - } - -function lwsgs_open_registration() -{ - document.getElementById("dadmin").style.display = "none"; - document.getElementById("dlogin").style.display = "none"; - document.getElementById("dlogout").style.display = "none"; - document.getElementById("dchange").style.display = "none"; - document.getElementById("dregister").style.display = "inline"; -} - -function lwsgs_cancel_registration() -{ - document.getElementById("dadmin").style.display = "none"; - document.getElementById("dregister").style.display = "none"; - document.getElementById("dchange").style.display = "none"; - - if (lwsgs_user === "") - document.getElementById("dlogin").style.display = "inline"; - else - document.getElementById("dlogout").style.display = "inline"; -} - -function lwsgs_select_change() -{ - document.getElementById("dlogin").style.display = "none"; - document.getElementById("dlogout").style.display = "none"; - document.getElementById("dregister").style.display = "none"; - if (lwsgs_auth & 2) { - document.getElementById("dadmin").style.display = "inline"; - document.getElementById("dchange").style.display = "none"; - } else { - document.getElementById("dadmin").style.display = "none"; - document.getElementById("dchange").style.display = "inline"; - } - - event.preventDefault() -} - -var lwsgs_user_check = '0'; -var lwsgs_email_check = '0'; - -function lwsgs_rupdate() -{ - var en_register = 1, en_forgot = 0; - - if (document.getElementById('rpassword').value == - document.getElementById('password2').value) { - if (document.getElementById('rpassword').value.length) - document.getElementById('match').innerHTML = - "\u2713"; - else - document.getElementById('match').innerHTML = ""; - document.getElementById('pw2').style = ""; - } else { - if (document.getElementById('password2').value || - document.getElementById('email').value) { // ie, he is filling in "register" path and cares - document.getElementById('match').innerHTML = - "\u2718 Passwords do not match"; - } else - document.getElementById('match').innerHTML = - "\u2718 Passwords do not match"; - - en_register = 0; - } - - if (document.getElementById('rpassword').value.length && - document.getElementById('rpassword').value.length < 8) { - en_register = 0; - document.getElementById('rpw1').innerHTML = "Need 8 chars"; - } else - if (document.getElementById('rpassword').value.length) - document.getElementById('rpw1').innerHTML = "\u2713"; - else - document.getElementById('rpw1').innerHTML = ""; - - if (!document.getElementById('rpassword').value || - !document.getElementById('password2').value || - !document.getElementById('rusername').value || - !document.getElementById('email').value || - lwsgs_email_check === '1'|| - lwsgs_user_check === '1') - en_register = 0; - - document.getElementById('register').disabled = !en_register; - document.getElementById('rpassword').disabled = lwsgs_user_check === '1'; - document.getElementById('password2').disabled = lwsgs_user_check === '1'; - document.getElementById('email').disabled = lwsgs_user_check === '1'; - - if (lwsgs_user_check === '0') { - var uc = document.getElementById('uchk'); - - if (uc) { - if (document.getElementById('rusername').value) - uc.innerHTML = "\u2713"; - else - uc.innerHTML = ""; - } - } else { - if (document.getElementById('uchk')) - ocument.getElementById('uchk').innerHTML = "\u2718 Already registered"; - en_forgot = 1; - } - - if (lwsgs_email_check === '0') { - var ec = document.getElementById('echk'); - - if (ec) { - if (document.getElementById('email').value) - ec.innerHTML = "\u2713"; - else - ec.innerHTML = ""; - } - } else { - if (document.getElementById('echk')) - document.getElementById('echk').innerHTML = "\u2718 Already registered"; - en_forgot = 1; - } - - if (en_forgot) - document.getElementById('rforgot').style.display = "inline"; - else - document.getElementById('rforgot').style.display = "none"; - - if (lwsgs_user_check === '1') - op = '0.5'; - else - op = '1.0'; - document.getElementById('rpassword').style.opacity = op; - document.getElementById('password2').style.opacity = op; - document.getElementById('email').style.opacity = op; - } - -function lwsgs_cupdate() -{ - var en_change = 1, en_forgot = 1, pwok = 1; - - if (lwsgs_auth & 8) { - document.getElementById('ccurpw').style.display = "none"; - document.getElementById('ccurpw_name').style.display = "none"; - } else { - if (!document.getElementById('ccurpw').value || - document.getElementById('ccurpw').value.length < 8) { - en_change = 0; - pwok = 0; - document.getElementById('cuchk').innerHTML = "\u2718"; - } else { - en_forgot = 0; - document.getElementById('cuchk').innerHTML = ""; - } - document.getElementById('ccurpw').style.display = "inline"; - document.getElementById('ccurpw_name').style.display = "inline"; - } - - if (document.getElementById('cpassword').value == - document.getElementById('cpassword2').value) { - if (document.getElementById('cpassword').value.length) - document.getElementById('cmatch').innerHTML = "\u2713"; - else - document.getElementById('cmatch').innerHTML = ""; - document.getElementById('pw2').style = ""; - } else { - if (document.getElementById('cpassword2').value //|| - //document.getElementById('cemail').value - ) { // ie, he is filling in "register" path and cares - document.getElementById('cmatch').innerHTML = - "\u2718 Passwords do not match"; - } else - document.getElementById('cmatch').innerHTML = "\u2718 Passwords do not match"; - - en_change = 0; - } - - if (document.getElementById('cpassword').value.length && - document.getElementById('cpassword').value.length < 8) { - en_change = 0; - document.getElementById('cpw1').innerHTML = "Need 8 chars"; - } else { - var cpw = document.getElementById('cpw1'); - - if (cpw) { - if (document.getElementById('cpassword').value.length) - cpw.innerHTML = "\u2713"; - else - cpw.innerHTML = ""; - } - } - - if (!document.getElementById('cpassword').value || - !document.getElementById('cpassword2').value || - pwok === 0) - en_change = 0; - - if (document.getElementById('showdel').checked) - document.getElementById('delete').style.display = "inline"; - else - document.getElementById('delete').style.display = "none"; - - document.getElementById('change').disabled = !en_change; - document.getElementById('cpassword').disabled = pwok === 0; - document.getElementById('cpassword2').disabled = pwok === 0; - document.getElementById('showdel').disabled = pwok === 0; - document.getElementById('delete').disabled = pwok === 0; - //document.getElementById('cemail').disabled = pwok === 0; - - /* - if (lwsgs_auth & 8) { - document.getElementById('cemail').style.display = "none"; - document.getElementById('cemail_name').style.display = "none"; - } else { - document.getElementById('cemail').style.display = "inline"; - document.getElementById('cemail_name').style.display = "inline"; - if (lwsgs_email_check === '0' && - document.getElementById('cemail').value != lwsgs_email) { - if (document.getElementById('cemail').value) - document.getElementById('cechk').innerHTML = "\u2713"; - else - document.getElementById('cechk').innerHTML = ""; - } else { - document.getElementById('cechk').innerHTML = "\u2718 Already registered"; - en_forgot = 1; - } - } */ - - if (lwsgs_auth & 8) - en_forgot = 0; - - if (en_forgot) - document.getElementById('cforgot').style.display = "inline"; - else - document.getElementById('cforgot').style.display = "none"; - - if (pwok === 0) - op = '0.5'; - else - op = '1.0'; - document.getElementById('cpassword').style.opacity = op; - document.getElementById('cpassword2').style.opacity = op; - // document.getElementById('cemail').style.opacity = op; - } - -function lwsgs_check_user() -{ - var xmlHttp = new XMLHttpRequest(); - xmlHttp.onreadystatechange = function() { - if (xmlHttp.readyState === 4 && xmlHttp.status === 200) { - lwsgs_user_check = xmlHttp.responseText; - lwsgs_rupdate(); - } - } - xmlHttp.open("GET", "lwsgs-check/username="+document.getElementById('rusername').value, true); - xmlHttp.send(null); -} - -function lwsgs_check_email(id) -{ - var xmlHttp = new XMLHttpRequest(); - xmlHttp.onreadystatechange = function() { - if (xmlHttp.readyState === 4 && xmlHttp.status === 200) { - lwsgs_email_check = xmlHttp.responseText; - lwsgs_rupdate(); - } - } - xmlHttp.open("GET", "lwsgs-check/email="+document.getElementById(id).value, true); - xmlHttp.send(null); -} - -function rupdate_user() -{ - lwsgs_rupdate(); - lwsgs_check_user(); -} - -function rupdate_email() -{ - lwsgs_rupdate(); - lwsgs_check_email('email'); -} - -function cupdate_email() -{ - lwsgs_cupdate(); - lwsgs_check_email('cemail'); -} - - -function lwsgs_initial() -{ - document.getElementById('lwsgs').innerHTML = lwsgs_html; - - if (lwsgs_user) { - document.getElementById("curuser").innerHTML = - "currently logged in as " + lwsgs_san(lwsgs_user) + "
"; - - document.getElementById("ccuruser").innerHTML = - "Login settings for " + - lwsgs_san(lwsgs_user) + "
"; - } - - document.getElementById('username').oninput = lwsgs_update; - document.getElementById('username').onchange = lwsgs_update; - document.getElementById('password').oninput = lwsgs_update; - document.getElementById('password').onchange = lwsgs_update; - document.getElementById('doreg').onclick = lwsgs_open_registration; - document.getElementById('clink').onclick = lwsgs_select_change; - document.getElementById('cancel').onclick =lwsgs_cancel_registration; - document.getElementById('cancel2').onclick =lwsgs_cancel_registration; - document.getElementById('rpassword').oninput = lwsgs_rupdate; - document.getElementById('password2').oninput = lwsgs_rupdate; - document.getElementById('rusername').oninput = rupdate_user; - document.getElementById('email').oninput = rupdate_email; - document.getElementById('ccurpw').oninput = lwsgs_cupdate; - document.getElementById('cpassword').oninput = lwsgs_cupdate; - document.getElementById('cpassword2').oninput = lwsgs_cupdate; - - document.getElementById('showdel').onchange = lwsgs_cupdate; - - if (lwsgs_email) - document.getElementById('grav').innerHTML = - ""; - //if (lwsgs_email) - //document.getElementById('cemail').placeholder = lwsgs_email; - document.getElementById('cusername').value = lwsgs_user; - lwsgs_update(); - lwsgs_cupdate(); -} - -window.addEventListener("load", function() { - lwsgs_initial(); - document.getElementById("nolog").style.display = !!lwsgs_user ? "none" : "inline-block"; - document.getElementById("logged").style.display = !lwsgs_user ? "none" : "inline-block"; - - document.getElementById("msg").onkeyup = mupd; - document.getElementById("msg").onchange = mupd; - - var ws; - - function mb_format(s) - { - var r = "", n, wos = 0; - - for (n = 0; n < s.length; n++) { - if (s[n] == ' ') - wos = 0; - else { - wos++; - if (wos === 40) { - wos = 0; - r = r + ' '; - } - } - if (s[n] == '<') { - r = r + "<"; - continue; - } - if (s[n] == '\n') { - r = r + "
"; - continue; - } - - r = r + s[n]; - } - - return r; - } - - function add_div(n, m) - { - var q = document.getElementById(n); - var d = new Date(m.time * 1000), s = d.toTimeString(), t; - - t = s.indexOf('('); - if (t) - s = s.substring(0, t); - - q.innerHTML = "
" + - "
" + - "" + lwsgs_san(m.username) + "
" + - "" + d.toDateString() + - "
" + s + "

" + - "IP: " + lwsgs_san(m.ip) + - "
" + - mb_format(m.content) + - "

" + q.innerHTML; - } - - function get_appropriate_ws_url() - { - var pcol; - var u = document.URL; - - if (u.substring(0, 5) == "https") { - pcol = "wss://"; - u = u.substr(8); - } else { - pcol = "ws://"; - if (u.substring(0, 4) == "http") - u = u.substr(7); - } - u = u.split('/'); - - return pcol + u[0] + "/xxx"; - } - - if (lwsgs_user) { - if (typeof MozWebSocket != "undefined") - ws = new MozWebSocket(get_appropriate_ws_url(), - "protocol-lws-messageboard"); - else - ws = new WebSocket(get_appropriate_ws_url(), - "protocol-lws-messageboard"); - - try { - ws.onopen = function() { - document.getElementById("debug").textContent = "ws opened"; - } - ws.onmessage =function got_packet(msg) { - add_div("messages", JSON.parse(msg.data)); - } - ws.onclose = function(){ - } - } catch(exception) { - alert('

Error' + exception); - } - } - - function mupd() - { - document.getElementById("send").disabled = !document.getElementById("msg").value; - } -}, false); Binary files /tmp/tmp2l8bmswe/3lv7Sxvgkv/libwebsockets-3.2.1/minimal-examples/http-server/minimal-http-server-generic-sessions/mount-origin/lwsgs-logo.png and /tmp/tmp2l8bmswe/LwTwoWz49Q/libwebsockets-4.1.6/minimal-examples/http-server/minimal-http-server-generic-sessions/mount-origin/lwsgs-logo.png differ diff -Nru libwebsockets-3.2.1/minimal-examples/http-server/minimal-http-server-generic-sessions/mount-origin/md5.min.js libwebsockets-4.1.6/minimal-examples/http-server/minimal-http-server-generic-sessions/mount-origin/md5.min.js --- libwebsockets-3.2.1/minimal-examples/http-server/minimal-http-server-generic-sessions/mount-origin/md5.min.js 2019-12-18 14:45:31.000000000 +0000 +++ libwebsockets-4.1.6/minimal-examples/http-server/minimal-http-server-generic-sessions/mount-origin/md5.min.js 1970-01-01 00:00:00.000000000 +0000 @@ -1,2 +0,0 @@ -!function(n){"use strict";function t(n,t){var r=(65535&n)+(65535&t),e=(n>>16)+(t>>16)+(r>>16);return e<<16|65535&r}function r(n,t){return n<>>32-t}function e(n,e,o,u,c,f){return t(r(t(t(e,n),t(u,f)),c),o)}function o(n,t,r,o,u,c,f){return e(t&r|~t&o,n,t,u,c,f)}function u(n,t,r,o,u,c,f){return e(t&o|r&~o,n,t,u,c,f)}function c(n,t,r,o,u,c,f){return e(t^r^o,n,t,u,c,f)}function f(n,t,r,o,u,c,f){return e(r^(t|~o),n,t,u,c,f)}function i(n,r){n[r>>5]|=128<>>9<<4)+14]=r;var e,i,a,h,d,l=1732584193,g=-271733879,v=-1732584194,m=271733878;for(e=0;e>5]>>>t%32&255);return r}function h(n){var t,r=[];for(r[(n.length>>2)-1]=void 0,t=0;t>5]|=(255&n.charCodeAt(t/8))<16&&(o=i(o,8*n.length)),r=0;16>r;r+=1)u[r]=909522486^o[r],c[r]=1549556828^o[r];return e=i(u.concat(h(t)),512+8*t.length),a(i(c.concat(e),640))}function g(n){var t,r,e="0123456789abcdef",o="";for(r=0;r>>4&15)+e.charAt(15&t);return o}function v(n){return unescape(encodeURIComponent(n))}function m(n){return d(v(n))}function p(n){return g(m(n))}function s(n,t){return l(v(n),v(t))}function C(n,t){return g(s(n,t))}function A(n,t,r){return t?r?s(t,n):C(t,n):r?m(n):p(n)}"function"==typeof define&&define.amd?define(function(){return A}):"object"==typeof module&&module.exports?module.exports=A:n.md5=A}(this); -//# sourceMappingURL=md5.min.js.map \ No newline at end of file diff -Nru libwebsockets-3.2.1/minimal-examples/http-server/minimal-http-server-generic-sessions/mount-origin/needadmin/admin-login.html libwebsockets-4.1.6/minimal-examples/http-server/minimal-http-server-generic-sessions/mount-origin/needadmin/admin-login.html --- libwebsockets-3.2.1/minimal-examples/http-server/minimal-http-server-generic-sessions/mount-origin/needadmin/admin-login.html 2019-12-18 14:45:31.000000000 +0000 +++ libwebsockets-4.1.6/minimal-examples/http-server/minimal-http-server-generic-sessions/mount-origin/needadmin/admin-login.html 1970-01-01 00:00:00.000000000 +0000 @@ -1,5 +0,0 @@ - -This is an example destination that will appear after successful Admin login. - -This URL cannot be served if you're not logged in as admin. - diff -Nru libwebsockets-3.2.1/minimal-examples/http-server/minimal-http-server-generic-sessions/mount-origin/needauth/successful-login.html libwebsockets-4.1.6/minimal-examples/http-server/minimal-http-server-generic-sessions/mount-origin/needauth/successful-login.html --- libwebsockets-3.2.1/minimal-examples/http-server/minimal-http-server-generic-sessions/mount-origin/needauth/successful-login.html 2019-12-18 14:45:31.000000000 +0000 +++ libwebsockets-4.1.6/minimal-examples/http-server/minimal-http-server-generic-sessions/mount-origin/needauth/successful-login.html 1970-01-01 00:00:00.000000000 +0000 @@ -1,4 +0,0 @@ - -This is an example destination that will appear after successful non-Admin login - - diff -Nru libwebsockets-3.2.1/minimal-examples/http-server/minimal-http-server-generic-sessions/mount-origin/post-forgot-fail.html libwebsockets-4.1.6/minimal-examples/http-server/minimal-http-server-generic-sessions/mount-origin/post-forgot-fail.html --- libwebsockets-3.2.1/minimal-examples/http-server/minimal-http-server-generic-sessions/mount-origin/post-forgot-fail.html 2019-12-18 14:45:31.000000000 +0000 +++ libwebsockets-4.1.6/minimal-examples/http-server/minimal-http-server-generic-sessions/mount-origin/post-forgot-fail.html 1970-01-01 00:00:00.000000000 +0000 @@ -1,5 +0,0 @@ - -Sorry, something went wrong. - -Click here to continue. - diff -Nru libwebsockets-3.2.1/minimal-examples/http-server/minimal-http-server-generic-sessions/mount-origin/post-forgot-ok.html libwebsockets-4.1.6/minimal-examples/http-server/minimal-http-server-generic-sessions/mount-origin/post-forgot-ok.html --- libwebsockets-3.2.1/minimal-examples/http-server/minimal-http-server-generic-sessions/mount-origin/post-forgot-ok.html 2019-12-18 14:45:31.000000000 +0000 +++ libwebsockets-4.1.6/minimal-examples/http-server/minimal-http-server-generic-sessions/mount-origin/post-forgot-ok.html 1970-01-01 00:00:00.000000000 +0000 @@ -1,6 +0,0 @@ - -This is a one-time password recovery login. - -Please click here and click your username at the top to reset your password. - - diff -Nru libwebsockets-3.2.1/minimal-examples/http-server/minimal-http-server-generic-sessions/mount-origin/post-register-fail.html libwebsockets-4.1.6/minimal-examples/http-server/minimal-http-server-generic-sessions/mount-origin/post-register-fail.html --- libwebsockets-3.2.1/minimal-examples/http-server/minimal-http-server-generic-sessions/mount-origin/post-register-fail.html 2019-12-18 14:45:31.000000000 +0000 +++ libwebsockets-4.1.6/minimal-examples/http-server/minimal-http-server-generic-sessions/mount-origin/post-register-fail.html 1970-01-01 00:00:00.000000000 +0000 @@ -1 +0,0 @@ -Registration failed, sorry diff -Nru libwebsockets-3.2.1/minimal-examples/http-server/minimal-http-server-generic-sessions/mount-origin/post-register-ok.html libwebsockets-4.1.6/minimal-examples/http-server/minimal-http-server-generic-sessions/mount-origin/post-register-ok.html --- libwebsockets-3.2.1/minimal-examples/http-server/minimal-http-server-generic-sessions/mount-origin/post-register-ok.html 2019-12-18 14:45:31.000000000 +0000 +++ libwebsockets-4.1.6/minimal-examples/http-server/minimal-http-server-generic-sessions/mount-origin/post-register-ok.html 1970-01-01 00:00:00.000000000 +0000 @@ -1,27 +0,0 @@ - - - - - - - - - - - - -
- -
- Your registration as is accepted,
- you will receive an email shortly with instructions
- to verify and enable the account for normal use.

- The link is only valid for an hour, after that if it has
- not been verified your account will be deleted. -
- - - - diff -Nru libwebsockets-3.2.1/minimal-examples/http-server/minimal-http-server-generic-sessions/mount-origin/post-verify-fail.html libwebsockets-4.1.6/minimal-examples/http-server/minimal-http-server-generic-sessions/mount-origin/post-verify-fail.html --- libwebsockets-3.2.1/minimal-examples/http-server/minimal-http-server-generic-sessions/mount-origin/post-verify-fail.html 2019-12-18 14:45:31.000000000 +0000 +++ libwebsockets-4.1.6/minimal-examples/http-server/minimal-http-server-generic-sessions/mount-origin/post-verify-fail.html 1970-01-01 00:00:00.000000000 +0000 @@ -1,20 +0,0 @@ - - - - - - - - - - - - -
- -
- Sorry, the link was invalid. -
- - - diff -Nru libwebsockets-3.2.1/minimal-examples/http-server/minimal-http-server-generic-sessions/mount-origin/post-verify-ok.html libwebsockets-4.1.6/minimal-examples/http-server/minimal-http-server-generic-sessions/mount-origin/post-verify-ok.html --- libwebsockets-3.2.1/minimal-examples/http-server/minimal-http-server-generic-sessions/mount-origin/post-verify-ok.html 2019-12-18 14:45:31.000000000 +0000 +++ libwebsockets-4.1.6/minimal-examples/http-server/minimal-http-server-generic-sessions/mount-origin/post-verify-ok.html 1970-01-01 00:00:00.000000000 +0000 @@ -1,25 +0,0 @@ - - - - - - - - - - - - -
- -
- Thanks for signing up, your registration as is verified.
-
- Click here to continue. -
- - - - Binary files /tmp/tmp2l8bmswe/3lv7Sxvgkv/libwebsockets-3.2.1/minimal-examples/http-server/minimal-http-server-generic-sessions/mount-origin/seats.jpg and /tmp/tmp2l8bmswe/LwTwoWz49Q/libwebsockets-4.1.6/minimal-examples/http-server/minimal-http-server-generic-sessions/mount-origin/seats.jpg differ diff -Nru libwebsockets-3.2.1/minimal-examples/http-server/minimal-http-server-generic-sessions/mount-origin/sent-forgot-fail.html libwebsockets-4.1.6/minimal-examples/http-server/minimal-http-server-generic-sessions/mount-origin/sent-forgot-fail.html --- libwebsockets-3.2.1/minimal-examples/http-server/minimal-http-server-generic-sessions/mount-origin/sent-forgot-fail.html 2019-12-18 14:45:31.000000000 +0000 +++ libwebsockets-4.1.6/minimal-examples/http-server/minimal-http-server-generic-sessions/mount-origin/sent-forgot-fail.html 1970-01-01 00:00:00.000000000 +0000 @@ -1,5 +0,0 @@ - -Sorry, something went wrong. - -Click here to continue. - diff -Nru libwebsockets-3.2.1/minimal-examples/http-server/minimal-http-server-generic-sessions/mount-origin/sent-forgot-ok.html libwebsockets-4.1.6/minimal-examples/http-server/minimal-http-server-generic-sessions/mount-origin/sent-forgot-ok.html --- libwebsockets-3.2.1/minimal-examples/http-server/minimal-http-server-generic-sessions/mount-origin/sent-forgot-ok.html 2019-12-18 14:45:31.000000000 +0000 +++ libwebsockets-4.1.6/minimal-examples/http-server/minimal-http-server-generic-sessions/mount-origin/sent-forgot-ok.html 1970-01-01 00:00:00.000000000 +0000 @@ -1,4 +0,0 @@ -An email has been sent to your registered address. - -Please follow the instructions to reset your password. - diff -Nru libwebsockets-3.2.1/minimal-examples/http-server/minimal-http-server-generic-sessions/mount-origin/strict-csp.svg libwebsockets-4.1.6/minimal-examples/http-server/minimal-http-server-generic-sessions/mount-origin/strict-csp.svg --- libwebsockets-3.2.1/minimal-examples/http-server/minimal-http-server-generic-sessions/mount-origin/strict-csp.svg 2019-12-18 14:45:31.000000000 +0000 +++ libwebsockets-4.1.6/minimal-examples/http-server/minimal-http-server-generic-sessions/mount-origin/strict-csp.svg 1970-01-01 00:00:00.000000000 +0000 @@ -1,53 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - diff -Nru libwebsockets-3.2.1/minimal-examples/http-server/minimal-http-server-generic-sessions/mount-origin/successful-login.html libwebsockets-4.1.6/minimal-examples/http-server/minimal-http-server-generic-sessions/mount-origin/successful-login.html --- libwebsockets-3.2.1/minimal-examples/http-server/minimal-http-server-generic-sessions/mount-origin/successful-login.html 2019-12-18 14:45:31.000000000 +0000 +++ libwebsockets-4.1.6/minimal-examples/http-server/minimal-http-server-generic-sessions/mount-origin/successful-login.html 1970-01-01 00:00:00.000000000 +0000 @@ -1,4 +0,0 @@ - -This is an example destination that will appear after successful non-Admin login - - diff -Nru libwebsockets-3.2.1/minimal-examples/http-server/minimal-http-server-generic-sessions/README.md libwebsockets-4.1.6/minimal-examples/http-server/minimal-http-server-generic-sessions/README.md --- libwebsockets-3.2.1/minimal-examples/http-server/minimal-http-server-generic-sessions/README.md 2019-12-18 14:45:31.000000000 +0000 +++ libwebsockets-4.1.6/minimal-examples/http-server/minimal-http-server-generic-sessions/README.md 1970-01-01 00:00:00.000000000 +0000 @@ -1,26 +0,0 @@ -# lws minimal http server with generic-sessions - -## 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 -``` - - diff -Nru libwebsockets-3.2.1/minimal-examples/http-server/minimal-http-server-h2-long-poll/CMakeLists.txt libwebsockets-4.1.6/minimal-examples/http-server/minimal-http-server-h2-long-poll/CMakeLists.txt --- libwebsockets-3.2.1/minimal-examples/http-server/minimal-http-server-h2-long-poll/CMakeLists.txt 1970-01-01 00:00:00.000000000 +0000 +++ libwebsockets-4.1.6/minimal-examples/http-server/minimal-http-server-h2-long-poll/CMakeLists.txt 2020-12-01 17:40:26.000000000 +0000 @@ -0,0 +1,25 @@ +project(lws-minimal-http-server-h2-long-poll C) +cmake_minimum_required(VERSION 2.8) +find_package(libwebsockets CONFIG REQUIRED) +list(APPEND CMAKE_MODULE_PATH ${LWS_CMAKE_DIR}) +include(CheckCSourceCompiles) +include(LwsCheckRequirements) + +set(SAMP lws-minimal-http-server-h2-long-poll) +set(SRCS minimal-http-server.c) + +set(requirements 1) +require_lws_config(LWS_ROLE_H1 1 requirements) +require_lws_config(LWS_WITH_SERVER 1 requirements) +require_lws_config(LWS_WITH_HTTP2 1 requirements) + +if (requirements) + add_executable(${SAMP} ${SRCS}) + + if (websockets_shared) + target_link_libraries(${SAMP} websockets_shared ${LIBWEBSOCKETS_DEP_LIBS}) + add_dependencies(${SAMP} websockets_shared) + else() + target_link_libraries(${SAMP} websockets ${LIBWEBSOCKETS_DEP_LIBS}) + endif() +endif() diff -Nru libwebsockets-3.2.1/minimal-examples/http-server/minimal-http-server-h2-long-poll/localhost-100y.cert libwebsockets-4.1.6/minimal-examples/http-server/minimal-http-server-h2-long-poll/localhost-100y.cert --- libwebsockets-3.2.1/minimal-examples/http-server/minimal-http-server-h2-long-poll/localhost-100y.cert 1970-01-01 00:00:00.000000000 +0000 +++ libwebsockets-4.1.6/minimal-examples/http-server/minimal-http-server-h2-long-poll/localhost-100y.cert 2020-12-01 17:40:26.000000000 +0000 @@ -0,0 +1,34 @@ +-----BEGIN CERTIFICATE----- +MIIF5jCCA86gAwIBAgIJANq50IuwPFKgMA0GCSqGSIb3DQEBCwUAMIGGMQswCQYD +VQQGEwJHQjEQMA4GA1UECAwHRXJld2hvbjETMBEGA1UEBwwKQWxsIGFyb3VuZDEb +MBkGA1UECgwSbGlid2Vic29ja2V0cy10ZXN0MRIwEAYDVQQDDAlsb2NhbGhvc3Qx +HzAdBgkqhkiG9w0BCQEWEG5vbmVAaW52YWxpZC5vcmcwIBcNMTgwMzIwMDQxNjA3 +WhgPMjExODAyMjQwNDE2MDdaMIGGMQswCQYDVQQGEwJHQjEQMA4GA1UECAwHRXJl +d2hvbjETMBEGA1UEBwwKQWxsIGFyb3VuZDEbMBkGA1UECgwSbGlid2Vic29ja2V0 +cy10ZXN0MRIwEAYDVQQDDAlsb2NhbGhvc3QxHzAdBgkqhkiG9w0BCQEWEG5vbmVA +aW52YWxpZC5vcmcwggIiMA0GCSqGSIb3DQEBAQUAA4ICDwAwggIKAoICAQCjYtuW +aICCY0tJPubxpIgIL+WWmz/fmK8IQr11Wtee6/IUyUlo5I602mq1qcLhT/kmpoR8 +Di3DAmHKnSWdPWtn1BtXLErLlUiHgZDrZWInmEBjKM1DZf+CvNGZ+EzPgBv5nTek +LWcfI5ZZtoGuIP1Dl/IkNDw8zFz4cpiMe/BFGemyxdHhLrKHSm8Eo+nT734tItnH +KT/m6DSU0xlZ13d6ehLRm7/+Nx47M3XMTRH5qKP/7TTE2s0U6+M0tsGI2zpRi+m6 +jzhNyMBTJ1u58qAe3ZW5/+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Wg6Gg +mnIZLRerQCu1Oozr87rOQqQakPkyt8BUSNK3K42j2qcfhAONdRl8Hq8Qs5pupy+s +8sdCGDlwR3JNCMv6u48OK87F4mcIxhkSefFJUFII25pCGN5WtE4p5l+9cnO1GrIX +e2Hl/7M0c/lbZ4FvXgARlex2rkgS0Ka06HE= +-----END CERTIFICATE----- diff -Nru libwebsockets-3.2.1/minimal-examples/http-server/minimal-http-server-h2-long-poll/localhost-100y.key libwebsockets-4.1.6/minimal-examples/http-server/minimal-http-server-h2-long-poll/localhost-100y.key --- libwebsockets-3.2.1/minimal-examples/http-server/minimal-http-server-h2-long-poll/localhost-100y.key 1970-01-01 00:00:00.000000000 +0000 +++ libwebsockets-4.1.6/minimal-examples/http-server/minimal-http-server-h2-long-poll/localhost-100y.key 2020-12-01 17:40:26.000000000 +0000 @@ -0,0 +1,52 @@ +-----BEGIN PRIVATE KEY----- +MIIJQwIBADANBgkqhkiG9w0BAQEFAASCCS0wggkpAgEAAoICAQCjYtuWaICCY0tJ +PubxpIgIL+WWmz/fmK8IQr11Wtee6/IUyUlo5I602mq1qcLhT/kmpoR8Di3DAmHK +nSWdPWtn1BtXLErLlUiHgZDrZWInmEBjKM1DZf+CvNGZ+EzPgBv5nTekLWcfI5ZZ +toGuIP1Dl/IkNDw8zFz4cpiMe/BFGemyxdHhLrKHSm8Eo+nT734tItnHKT/m6DSU +0xlZ13d6ehLRm7/+Nx47M3XMTRH5qKP/7TTE2s0U6+M0tsGI2zpRi+m6jzhNyMBT +J1u58qAe3ZW5/+YAiuZYAB6n5bhUp4oFuB5wYbcBywVR8ujInpF8buWQUjy5N8pS +Np7szdYsnLJpvAd0sibrNPjC0FQCNrpNjgJmIK3+mKk4kXX7ZTwefoAzTK4l2pHN +uC53QVc/EF++GBLAxmvCDq9ZpMIYi7OmzkkAKKC9Ue6Ef217LFQCFIBKIzv9cgi9 +fwPMLhrKleoVRNsecBsCP569WgJXhUnwf2lon4fEZr3+vRuc9shfqnV0nPN1IMSn +z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/L8ta+mUDy37K6vC34jh9vK9yrwF6X44ItRoOJafCaVfGI+175q/eWcqTX4q+I +G4tKls4sL4mgOJLq+ra50aYMxbcuommctPMXU6CrrYyQpPTHMNVDQy2ttFdsq9iK +TncCggEBAMmt/8yvPflS+xv3kg/ZBvR9JB1In2n3rUCYYD47ReKFqJ03Vmq5C9nY +56s9w7OUO8perBXlJYmKZQhO4293lvxZD2Iq4NcZbVSCMoHAUzhzY3brdgtSIxa2 +gGveGAezZ38qKIU26dkz7deECY4vrsRkwhpTW0LGVCpjcQoaKvymAoCmAs8V2oMr +Ziw1YQ9uOUoWwOqm1wZqmVcOXvPIS2gWAs3fQlWjH9hkcQTMsUaXQDOD0aqkSY3E +NqOvbCV1/oUpRi3076khCoAXI1bKSn/AvR3KDP14B5toHI/F5OTSEiGhhHesgRrs +fBrpEY1IATtPq1taBZZogRqI3rOkkPk= +-----END PRIVATE KEY----- diff -Nru libwebsockets-3.2.1/minimal-examples/http-server/minimal-http-server-h2-long-poll/minimal-http-server.c libwebsockets-4.1.6/minimal-examples/http-server/minimal-http-server-h2-long-poll/minimal-http-server.c --- libwebsockets-3.2.1/minimal-examples/http-server/minimal-http-server-h2-long-poll/minimal-http-server.c 1970-01-01 00:00:00.000000000 +0000 +++ libwebsockets-4.1.6/minimal-examples/http-server/minimal-http-server-h2-long-poll/minimal-http-server.c 2020-12-01 17:40:26.000000000 +0000 @@ -0,0 +1,158 @@ +/* + * lws-minimal-http-server-h2-long-poll + * + * Written in 2010-2019 by Andy Green + * + * This file is made available under the Creative Commons CC0 1.0 + * Universal Public Domain Dedication. + * + * This demonstrates an h2 server that supports "long poll" + * immortal client connections. For simplicity it doesn't serve + * any regular files, you can add a mount to do it if you want. + * + * The protocol keeps the long poll h2 stream open, and sends + * the time on the stream once per minute. Normally idle h2 + * connections are closed by default within 30s, so this demonstrates + * the stream and network connection are operating as "immortal" + * on both sides. + * + * See http-client/minimal-http-client-h2-long-poll for the + * client example that connects and transitions the stream to the + * immortal long poll mode. + */ + +#include +#include +#include + +static int interrupted; + +struct pss { + struct lws *wsi; + lws_sorted_usec_list_t sul; + char pending; +}; + +static const lws_retry_bo_t retry = { + .secs_since_valid_ping = 5, + .secs_since_valid_hangup = 10, +}; + +static void +sul_cb(lws_sorted_usec_list_t *sul) +{ + struct pss *pss = (struct pss *)lws_container_of(sul, struct pss, sul); + + pss->pending = 1; + lws_callback_on_writable(pss->wsi); + /* interval 1min... longer than any normal timeout */ + lws_sul_schedule(lws_get_context(pss->wsi), 0, &pss->sul, sul_cb, + 60 * LWS_US_PER_SEC); +} + +static int +callback_http(struct lws *wsi, enum lws_callback_reasons reason, void *user, + void *in, size_t len) +{ + struct pss * pss = (struct pss *)user; + uint8_t buf[LWS_PRE + LWS_RECOMMENDED_MIN_HEADER_SPACE], + *start = &buf[LWS_PRE], *p = start, + *end = p + sizeof(buf) - LWS_PRE; + int m, n; + + switch (reason) { + case LWS_CALLBACK_HTTP: + lwsl_user("%s: connect\n", __func__); + pss->wsi = wsi; + + if (lws_add_http_common_headers(wsi, HTTP_STATUS_OK, + "text/html", + LWS_ILLEGAL_HTTP_CONTENT_LEN, /* no content len */ + &p, end)) + return 1; + if (lws_finalize_write_http_header(wsi, start, &p, end)) + return 1; + + sul_cb(&pss->sul); + return 0; + + case LWS_CALLBACK_CLOSED_HTTP: + if (!pss) + break; + lws_sul_cancel(&pss->sul); + break; + + case LWS_CALLBACK_HTTP_WRITEABLE: + if (!pss->pending) + break; + n = lws_snprintf((char *)p, sizeof(buf) - LWS_PRE, "%llu", + (unsigned long long)lws_now_usecs()); + m = lws_write(wsi, p, n, LWS_WRITE_HTTP); + if (m < n) { + lwsl_err("ERROR %d writing to socket\n", n); + return -1; + } + break; + default: + break; + } + + return lws_callback_http_dummy(wsi, reason, user, in, len); +} + +static struct lws_protocols protocols[] = { + { "http", callback_http, sizeof(struct pss), 0 }, + { NULL, NULL, 0, 0 } /* terminator */ +}; + + +void sigint_handler(int sig) +{ + interrupted = 1; +} + +int main(int argc, const char **argv) +{ + struct lws_context_creation_info info; + struct lws_context *context; + const char *p; + int n = 0, logs = LLL_USER | LLL_ERR | LLL_WARN | LLL_NOTICE; + + signal(SIGINT, sigint_handler); + + if ((p = lws_cmdline_option(argc, argv, "-d"))) + logs = atoi(p); + + lws_set_log_level(logs, NULL); + lwsl_user("LWS minimal http server h2 long poll\n"); + + memset(&info, 0, sizeof info); /* otherwise uninitialized garbage */ + info.port = 7681; +#if defined(LWS_WITH_TLS) + info.ssl_cert_filepath = "localhost-100y.cert"; + info.ssl_private_key_filepath = "localhost-100y.key"; +#endif + info.protocols = protocols; + info.options = + LWS_SERVER_OPTION_DO_SSL_GLOBAL_INIT | + LWS_SERVER_OPTION_VH_H2_HALF_CLOSED_LONG_POLL | + LWS_SERVER_OPTION_HTTP_HEADERS_SECURITY_BEST_PRACTICES_ENFORCE; + + /* the default validity check is 5m / 5m10s... -v = 5s / 10s */ + + if (lws_cmdline_option(argc, argv, "-v")) + info.retry_and_idle_policy = &retry; + + context = lws_create_context(&info); + if (!context) { + lwsl_err("lws init failed\n"); + return 1; + } + + while (n >= 0 && !interrupted) + n = lws_service(context, 0); + + lws_context_destroy(context); + + return 0; +} diff -Nru libwebsockets-3.2.1/minimal-examples/http-server/minimal-http-server-h2-long-poll/README.md libwebsockets-4.1.6/minimal-examples/http-server/minimal-http-server-h2-long-poll/README.md --- libwebsockets-3.2.1/minimal-examples/http-server/minimal-http-server-h2-long-poll/README.md 1970-01-01 00:00:00.000000000 +0000 +++ libwebsockets-4.1.6/minimal-examples/http-server/minimal-http-server-h2-long-poll/README.md 2020-12-01 17:40:26.000000000 +0000 @@ -0,0 +1,25 @@ +# lws minimal http server + +## build + +``` + $ cmake . && make +``` +## Commandline Options + +Option|Meaning +---|--- +-d|Set logging verbosity +-s|Serve using TLS selfsigned cert (ie, connect to it with https://...) +-v|Connection validity use 3s / 10s instead of default 5m / 5m10s + +## usage + +``` + $ ./lws-minimal-http-server +[2018/03/04 09:30:02:7986] USER: LWS minimal http server | visit http://localhost:7681 +[2018/03/04 09:30:02:7986] NOTICE: Creating Vhost 'default' port 7681, 1 protocols, IPv6 on +``` + +Visit http://localhost:7681 + diff -Nru libwebsockets-3.2.1/minimal-examples/http-server/minimal-http-server-mimetypes/CMakeLists.txt libwebsockets-4.1.6/minimal-examples/http-server/minimal-http-server-mimetypes/CMakeLists.txt --- libwebsockets-3.2.1/minimal-examples/http-server/minimal-http-server-mimetypes/CMakeLists.txt 2019-12-18 14:45:31.000000000 +0000 +++ libwebsockets-4.1.6/minimal-examples/http-server/minimal-http-server-mimetypes/CMakeLists.txt 2020-12-01 17:40:26.000000000 +0000 @@ -1,79 +1,24 @@ +project(lws-minimal-http-server-mimetypes C) cmake_minimum_required(VERSION 2.8) +find_package(libwebsockets CONFIG REQUIRED) +list(APPEND CMAKE_MODULE_PATH ${LWS_CMAKE_DIR}) include(CheckCSourceCompiles) +include(LwsCheckRequirements) set(SAMP lws-minimal-http-server-mimetypes) set(SRCS minimal-http-server-mimetypes.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_ROLE_H1 1 requirements) -require_lws_config(LWS_WITHOUT_SERVER 0 requirements) +require_lws_config(LWS_WITH_SERVER 1 requirements) if (requirements) add_executable(${SAMP} ${SRCS}) if (websockets_shared) - target_link_libraries(${SAMP} websockets_shared) + target_link_libraries(${SAMP} websockets_shared ${LIBWEBSOCKETS_DEP_LIBS}) add_dependencies(${SAMP} websockets_shared) else() - target_link_libraries(${SAMP} websockets) + target_link_libraries(${SAMP} websockets ${LIBWEBSOCKETS_DEP_LIBS}) endif() endif() diff -Nru libwebsockets-3.2.1/minimal-examples/http-server/minimal-http-server-mimetypes/mount-origin/libwebsockets.org-logo.svg libwebsockets-4.1.6/minimal-examples/http-server/minimal-http-server-mimetypes/mount-origin/libwebsockets.org-logo.svg --- libwebsockets-3.2.1/minimal-examples/http-server/minimal-http-server-mimetypes/mount-origin/libwebsockets.org-logo.svg 2019-12-18 14:45:31.000000000 +0000 +++ libwebsockets-4.1.6/minimal-examples/http-server/minimal-http-server-mimetypes/mount-origin/libwebsockets.org-logo.svg 2020-12-01 17:40:26.000000000 +0000 @@ -1,120 +1,66 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + + +image/svg+xml + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff -Nru libwebsockets-3.2.1/minimal-examples/http-server/minimal-http-server-multivhost/CMakeLists.txt libwebsockets-4.1.6/minimal-examples/http-server/minimal-http-server-multivhost/CMakeLists.txt --- libwebsockets-3.2.1/minimal-examples/http-server/minimal-http-server-multivhost/CMakeLists.txt 2019-12-18 14:45:31.000000000 +0000 +++ libwebsockets-4.1.6/minimal-examples/http-server/minimal-http-server-multivhost/CMakeLists.txt 2020-12-01 17:40:26.000000000 +0000 @@ -1,77 +1,24 @@ +project(lws-minimal-http-server-multivhost C) cmake_minimum_required(VERSION 2.8) +find_package(libwebsockets CONFIG REQUIRED) +list(APPEND CMAKE_MODULE_PATH ${LWS_CMAKE_DIR}) include(CheckCSourceCompiles) +include(LwsCheckRequirements) set(SAMP lws-minimal-http-server-multivhost) set(SRCS minimal-http-server.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_ROLE_H1 1 requirements) -require_lws_config(LWS_WITHOUT_SERVER 0 requirements) +require_lws_config(LWS_WITH_SERVER 1 requirements) if (requirements) add_executable(${SAMP} ${SRCS}) if (websockets_shared) - target_link_libraries(${SAMP} websockets_shared) + target_link_libraries(${SAMP} websockets_shared ${LIBWEBSOCKETS_DEP_LIBS}) add_dependencies(${SAMP} websockets_shared) else() - target_link_libraries(${SAMP} websockets) + target_link_libraries(${SAMP} websockets ${LIBWEBSOCKETS_DEP_LIBS}) endif() endif() \ No newline at end of file diff -Nru libwebsockets-3.2.1/minimal-examples/http-server/minimal-http-server-multivhost/mount-origin-localhost1/libwebsockets.org-logo.svg libwebsockets-4.1.6/minimal-examples/http-server/minimal-http-server-multivhost/mount-origin-localhost1/libwebsockets.org-logo.svg --- libwebsockets-3.2.1/minimal-examples/http-server/minimal-http-server-multivhost/mount-origin-localhost1/libwebsockets.org-logo.svg 2019-12-18 14:45:31.000000000 +0000 +++ libwebsockets-4.1.6/minimal-examples/http-server/minimal-http-server-multivhost/mount-origin-localhost1/libwebsockets.org-logo.svg 2020-12-01 17:40:26.000000000 +0000 @@ -1,120 +1,66 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + + +image/svg+xml + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff -Nru libwebsockets-3.2.1/minimal-examples/http-server/minimal-http-server-multivhost/mount-origin-localhost2/libwebsockets.org-logo.svg libwebsockets-4.1.6/minimal-examples/http-server/minimal-http-server-multivhost/mount-origin-localhost2/libwebsockets.org-logo.svg --- libwebsockets-3.2.1/minimal-examples/http-server/minimal-http-server-multivhost/mount-origin-localhost2/libwebsockets.org-logo.svg 2019-12-18 14:45:31.000000000 +0000 +++ libwebsockets-4.1.6/minimal-examples/http-server/minimal-http-server-multivhost/mount-origin-localhost2/libwebsockets.org-logo.svg 2020-12-01 17:40:26.000000000 +0000 @@ -1,120 +1,66 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + + +image/svg+xml + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff -Nru libwebsockets-3.2.1/minimal-examples/http-server/minimal-http-server-multivhost/mount-origin-localhost3/libwebsockets.org-logo.svg libwebsockets-4.1.6/minimal-examples/http-server/minimal-http-server-multivhost/mount-origin-localhost3/libwebsockets.org-logo.svg --- libwebsockets-3.2.1/minimal-examples/http-server/minimal-http-server-multivhost/mount-origin-localhost3/libwebsockets.org-logo.svg 2019-12-18 14:45:31.000000000 +0000 +++ libwebsockets-4.1.6/minimal-examples/http-server/minimal-http-server-multivhost/mount-origin-localhost3/libwebsockets.org-logo.svg 2020-12-01 17:40:26.000000000 +0000 @@ -1,120 +1,66 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + + +image/svg+xml + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff -Nru libwebsockets-3.2.1/minimal-examples/http-server/minimal-http-server-proxy/CMakeLists.txt libwebsockets-4.1.6/minimal-examples/http-server/minimal-http-server-proxy/CMakeLists.txt --- libwebsockets-3.2.1/minimal-examples/http-server/minimal-http-server-proxy/CMakeLists.txt 2019-12-18 14:45:31.000000000 +0000 +++ libwebsockets-4.1.6/minimal-examples/http-server/minimal-http-server-proxy/CMakeLists.txt 2020-12-01 17:40:26.000000000 +0000 @@ -1,80 +1,26 @@ +project(lws-minimal-http-server-proxy C) cmake_minimum_required(VERSION 2.8) +find_package(libwebsockets CONFIG REQUIRED) +list(APPEND CMAKE_MODULE_PATH ${LWS_CMAKE_DIR}) include(CheckCSourceCompiles) +include(LwsCheckRequirements) set(SAMP lws-minimal-http-server-proxy) set(SRCS minimal-http-server-proxy.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_ROLE_H1 1 requirements) -require_lws_config(LWS_WITHOUT_SERVER 0 requirements) +require_lws_config(LWS_WITH_SERVER 1 requirements) require_lws_config(LWS_WITH_HTTP_PROXY 1 requirements) -require_lws_config(LWS_OPENSSL_SUPPORT 1 requirements) +require_lws_config(LWS_WITH_TLS 1 requirements) if (requirements) add_executable(${SAMP} ${SRCS}) if (websockets_shared) - target_link_libraries(${SAMP} websockets_shared) + target_link_libraries(${SAMP} websockets_shared ${LIBWEBSOCKETS_DEP_LIBS}) add_dependencies(${SAMP} websockets_shared) else() - target_link_libraries(${SAMP} websockets) + target_link_libraries(${SAMP} websockets ${LIBWEBSOCKETS_DEP_LIBS}) endif() endif() diff -Nru libwebsockets-3.2.1/minimal-examples/http-server/minimal-http-server-smp/CMakeLists.txt libwebsockets-4.1.6/minimal-examples/http-server/minimal-http-server-smp/CMakeLists.txt --- libwebsockets-3.2.1/minimal-examples/http-server/minimal-http-server-smp/CMakeLists.txt 2019-12-18 14:45:31.000000000 +0000 +++ libwebsockets-4.1.6/minimal-examples/http-server/minimal-http-server-smp/CMakeLists.txt 2020-12-01 17:40:26.000000000 +0000 @@ -1,91 +1,26 @@ +project(lws-minimal-http-server-smp C) cmake_minimum_required(VERSION 2.8) +find_package(libwebsockets CONFIG REQUIRED) +list(APPEND CMAKE_MODULE_PATH ${LWS_CMAKE_DIR}) include(CheckIncludeFile) include(CheckCSourceCompiles) +include(LwsCheckRequirements) set(SAMP lws-minimal-http-server-smp) set(SRCS minimal-http-server-smp.c) -MACRO(require_pthreads result) - CHECK_INCLUDE_FILE(pthread.h LWS_HAVE_PTHREAD_H) - if (NOT LWS_HAVE_PTHREAD_H) - if (LWS_WITH_MINIMAL_EXAMPLES) - set(result 0) - else() - message(FATAL_ERROR "threading support requires pthreads") - endif() - endif() -ENDMACRO() - -# 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_pthreads(requirements) require_lws_config(LWS_ROLE_H1 1 requirements) -require_lws_config(LWS_WITHOUT_SERVER 0 requirements) +require_lws_config(LWS_WITH_SERVER 1 requirements) if (requirements) add_executable(${SAMP} ${SRCS}) if (websockets_shared) - target_link_libraries(${SAMP} websockets_shared pthread) - add_dependencies(${SAMP} websockets_shared pthread) + target_link_libraries(${SAMP} websockets_shared ${PTHREAD_LIB} ${LIBWEBSOCKETS_DEP_LIBS}) + add_dependencies(${SAMP} websockets_shared) else() - target_link_libraries(${SAMP} websockets pthread) + target_link_libraries(${SAMP} websockets ${PTHREAD_LIB} ${LIBWEBSOCKETS_DEP_LIBS}) endif() endif() \ No newline at end of file diff -Nru libwebsockets-3.2.1/minimal-examples/http-server/minimal-http-server-smp/minimal-http-server-smp.c libwebsockets-4.1.6/minimal-examples/http-server/minimal-http-server-smp/minimal-http-server-smp.c --- libwebsockets-3.2.1/minimal-examples/http-server/minimal-http-server-smp/minimal-http-server-smp.c 2019-12-18 14:45:31.000000000 +0000 +++ libwebsockets-4.1.6/minimal-examples/http-server/minimal-http-server-smp/minimal-http-server-smp.c 2020-12-01 17:40:26.000000000 +0000 @@ -21,6 +21,12 @@ #include #include #include +#if defined(WIN32) +#define HAVE_STRUCT_TIMESPEC +#if defined(pid_t) +#undef pid_t +#endif +#endif #include #define COUNT_THREADS 8 @@ -100,11 +106,13 @@ } else info.count_threads = COUNT_THREADS; +#if defined(LWS_WITH_TLS) if (lws_cmdline_option(argc, argv, "-s")) { info.options = LWS_SERVER_OPTION_DO_SSL_GLOBAL_INIT | LWS_SERVER_OPTION_REQUIRE_VALID_OPENSSL_CLIENT_CERT; info.ssl_cert_filepath = "localhost-100y.cert"; info.ssl_private_key_filepath = "localhost-100y.key"; } +#endif context = lws_create_context(&info); if (!context) { diff -Nru libwebsockets-3.2.1/minimal-examples/http-server/minimal-http-server-smp/mount-origin/libwebsockets.org-logo.svg libwebsockets-4.1.6/minimal-examples/http-server/minimal-http-server-smp/mount-origin/libwebsockets.org-logo.svg --- libwebsockets-3.2.1/minimal-examples/http-server/minimal-http-server-smp/mount-origin/libwebsockets.org-logo.svg 2019-12-18 14:45:31.000000000 +0000 +++ libwebsockets-4.1.6/minimal-examples/http-server/minimal-http-server-smp/mount-origin/libwebsockets.org-logo.svg 2020-12-01 17:40:26.000000000 +0000 @@ -1,120 +1,66 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + + +image/svg+xml + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff -Nru libwebsockets-3.2.1/minimal-examples/http-server/minimal-http-server-sse/CMakeLists.txt libwebsockets-4.1.6/minimal-examples/http-server/minimal-http-server-sse/CMakeLists.txt --- libwebsockets-3.2.1/minimal-examples/http-server/minimal-http-server-sse/CMakeLists.txt 2019-12-18 14:45:31.000000000 +0000 +++ libwebsockets-4.1.6/minimal-examples/http-server/minimal-http-server-sse/CMakeLists.txt 2020-12-01 17:40:26.000000000 +0000 @@ -1,78 +1,25 @@ +project(lws-minimal-http-server-sse C) cmake_minimum_required(VERSION 2.8) +find_package(libwebsockets CONFIG REQUIRED) +list(APPEND CMAKE_MODULE_PATH ${LWS_CMAKE_DIR}) include(CheckCSourceCompiles) +include(LwsCheckRequirements) set(SAMP lws-minimal-http-server-sse) set(SRCS minimal-http-server-sse.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_pthreads(requirements) require_lws_config(LWS_ROLE_H1 1 requirements) -require_lws_config(LWS_WITHOUT_SERVER 0 requirements) +require_lws_config(LWS_WITH_SERVER 1 requirements) if (requirements) add_executable(${SAMP} ${SRCS}) if (websockets_shared) - target_link_libraries(${SAMP} websockets_shared) + target_link_libraries(${SAMP} websockets_shared ${PTHREAD_LIB} ${LIBWEBSOCKETS_DEP_LIBS}) add_dependencies(${SAMP} websockets_shared) else() - target_link_libraries(${SAMP} websockets) + target_link_libraries(${SAMP} websockets ${PTHREAD_LIB} ${LIBWEBSOCKETS_DEP_LIBS}) endif() endif() diff -Nru libwebsockets-3.2.1/minimal-examples/http-server/minimal-http-server-sse/minimal-http-server-sse.c libwebsockets-4.1.6/minimal-examples/http-server/minimal-http-server-sse/minimal-http-server-sse.c --- libwebsockets-3.2.1/minimal-examples/http-server/minimal-http-server-sse/minimal-http-server-sse.c 2019-12-18 14:45:31.000000000 +0000 +++ libwebsockets-4.1.6/minimal-examples/http-server/minimal-http-server-sse/minimal-http-server-sse.c 2020-12-01 17:40:26.000000000 +0000 @@ -19,6 +19,12 @@ #include #include #include +#if defined(WIN32) +#define HAVE_STRUCT_TIMESPEC +#if defined(pid_t) +#undef pid_t +#endif +#endif #include /* @@ -202,12 +208,15 @@ info.options = LWS_SERVER_OPTION_HTTP_HEADERS_SECURITY_BEST_PRACTICES_ENFORCE; info.port = 7681; + +#if defined(LWS_WITH_TLS) if (lws_cmdline_option(argc, argv, "-s")) { info.port = 443; info.options |= LWS_SERVER_OPTION_DO_SSL_GLOBAL_INIT; info.ssl_cert_filepath = "localhost-100y.cert"; info.ssl_private_key_filepath = "localhost-100y.key"; } +#endif context = lws_create_context(&info); if (!context) { diff -Nru libwebsockets-3.2.1/minimal-examples/http-server/minimal-http-server-sse/mount-origin/example.js libwebsockets-4.1.6/minimal-examples/http-server/minimal-http-server-sse/mount-origin/example.js --- libwebsockets-3.2.1/minimal-examples/http-server/minimal-http-server-sse/mount-origin/example.js 2019-12-18 14:45:31.000000000 +0000 +++ libwebsockets-4.1.6/minimal-examples/http-server/minimal-http-server-sse/mount-origin/example.js 2020-12-01 17:40:26.000000000 +0000 @@ -1,6 +1,6 @@ document.addEventListener("DOMContentLoaded", function() { -var head = 0, tail = 0, ring = new Array(); +var head = 0, tail = 0, ring = new Array(), es; es = new EventSource("/sse/sourcename"); try { diff -Nru libwebsockets-3.2.1/minimal-examples/http-server/minimal-http-server-sse/mount-origin/libwebsockets.org-logo.svg libwebsockets-4.1.6/minimal-examples/http-server/minimal-http-server-sse/mount-origin/libwebsockets.org-logo.svg --- libwebsockets-3.2.1/minimal-examples/http-server/minimal-http-server-sse/mount-origin/libwebsockets.org-logo.svg 2019-12-18 14:45:31.000000000 +0000 +++ libwebsockets-4.1.6/minimal-examples/http-server/minimal-http-server-sse/mount-origin/libwebsockets.org-logo.svg 2020-12-01 17:40:26.000000000 +0000 @@ -1,120 +1,66 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + + +image/svg+xml + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff -Nru libwebsockets-3.2.1/minimal-examples/http-server/minimal-http-server-sse-ring/CMakeLists.txt libwebsockets-4.1.6/minimal-examples/http-server/minimal-http-server-sse-ring/CMakeLists.txt --- libwebsockets-3.2.1/minimal-examples/http-server/minimal-http-server-sse-ring/CMakeLists.txt 2019-12-18 14:45:31.000000000 +0000 +++ libwebsockets-4.1.6/minimal-examples/http-server/minimal-http-server-sse-ring/CMakeLists.txt 2020-12-01 17:40:26.000000000 +0000 @@ -1,91 +1,24 @@ +project(lws-minimal-http-server-sse-ring C) cmake_minimum_required(VERSION 2.8) +find_package(libwebsockets CONFIG REQUIRED) include(CheckIncludeFile) include(CheckCSourceCompiles) set(SAMP lws-minimal-http-server-sse-ring) set(SRCS minimal-http-server-sse-ring.c) -MACRO(require_pthreads result) - CHECK_INCLUDE_FILE(pthread.h LWS_HAVE_PTHREAD_H) - if (NOT LWS_HAVE_PTHREAD_H) - if (LWS_WITH_MINIMAL_EXAMPLES) - set(result 0) - else() - message(FATAL_ERROR "threading support requires pthreads") - endif() - endif() -ENDMACRO() - -# 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_pthreads(requirements) require_lws_config(LWS_ROLE_H1 1 requirements) -require_lws_config(LWS_WITHOUT_SERVER 0 requirements) +require_lws_config(LWS_WITH_SERVER 1 requirements) if (requirements) add_executable(${SAMP} ${SRCS}) if (websockets_shared) - target_link_libraries(${SAMP} websockets_shared pthread) + target_link_libraries(${SAMP} websockets_shared ${PTHREAD_LIB} ${LIBWEBSOCKETS_DEP_LIBS}) add_dependencies(${SAMP} websockets_shared) else() - target_link_libraries(${SAMP} websockets pthread) + target_link_libraries(${SAMP} websockets ${PTHREAD_LIB} ${LIBWEBSOCKETS_DEP_LIBS}) endif() endif() diff -Nru libwebsockets-3.2.1/minimal-examples/http-server/minimal-http-server-sse-ring/minimal-http-server-sse-ring.c libwebsockets-4.1.6/minimal-examples/http-server/minimal-http-server-sse-ring/minimal-http-server-sse-ring.c --- libwebsockets-3.2.1/minimal-examples/http-server/minimal-http-server-sse-ring/minimal-http-server-sse-ring.c 2019-12-18 14:45:31.000000000 +0000 +++ libwebsockets-4.1.6/minimal-examples/http-server/minimal-http-server-sse-ring/minimal-http-server-sse-ring.c 2020-12-01 17:40:26.000000000 +0000 @@ -19,6 +19,12 @@ #include #include #include +#if defined(WIN32) +#define HAVE_STRUCT_TIMESPEC +#if defined(pid_t) +#undef pid_t +#endif +#endif #include #include @@ -86,7 +92,11 @@ { struct vhd *vhd = (struct vhd *)d; struct msg amsg; - int len = 128, index = 1, n; + int len = 128, index = 1, n, whoami = 0; + + for (n = 0; n < (int)LWS_ARRAY_SIZE(vhd->pthread_spam); n++) + if (pthread_equal(pthread_self(), vhd->pthread_spam[n])) + whoami = n + 1; do { /* don't generate output if nobody connected */ @@ -108,10 +118,9 @@ goto wait_unlock; } n = lws_snprintf((char *)amsg.payload, len, - "%s: tid: %p, msg: %d", __func__, - (void *)pthread_self(), index++); + "%s: tid: %d, msg: %d", __func__, whoami, index++); amsg.len = n; - n = lws_ring_insert(vhd->ring, &amsg, 1); + n = (int)lws_ring_insert(vhd->ring, &amsg, 1); if (n != 1) { __minimal_destroy_message(&amsg); lwsl_user("dropping!\n"); @@ -131,7 +140,7 @@ } while (!vhd->finished); - lwsl_notice("thread_spam %p exiting\n", (void *)pthread_self()); + lwsl_notice("thread_spam %d exiting\n", whoami); pthread_exit(NULL); @@ -186,8 +195,7 @@ init_fail: vhd->finished = 1; for (n = 0; n < (int)LWS_ARRAY_SIZE(vhd->pthread_spam); n++) - if (vhd->pthread_spam[n]) - pthread_join(vhd->pthread_spam[n], &retval); + pthread_join(vhd->pthread_spam[n], &retval); if (vhd->ring) lws_ring_destroy(vhd->ring); diff -Nru libwebsockets-3.2.1/minimal-examples/http-server/minimal-http-server-sse-ring/mount-origin/example.js libwebsockets-4.1.6/minimal-examples/http-server/minimal-http-server-sse-ring/mount-origin/example.js --- libwebsockets-3.2.1/minimal-examples/http-server/minimal-http-server-sse-ring/mount-origin/example.js 2019-12-18 14:45:31.000000000 +0000 +++ libwebsockets-4.1.6/minimal-examples/http-server/minimal-http-server-sse-ring/mount-origin/example.js 2020-12-01 17:40:26.000000000 +0000 @@ -1,6 +1,6 @@ document.addEventListener("DOMContentLoaded", function() { - var head = 0, tail = 0, ring = new Array(); + var head = 0, tail = 0, ring = new Array(), es; es = new EventSource("/sse/sourcename"); try { diff -Nru libwebsockets-3.2.1/minimal-examples/http-server/minimal-http-server-sse-ring/mount-origin/libwebsockets.org-logo.svg libwebsockets-4.1.6/minimal-examples/http-server/minimal-http-server-sse-ring/mount-origin/libwebsockets.org-logo.svg --- libwebsockets-3.2.1/minimal-examples/http-server/minimal-http-server-sse-ring/mount-origin/libwebsockets.org-logo.svg 2019-12-18 14:45:31.000000000 +0000 +++ libwebsockets-4.1.6/minimal-examples/http-server/minimal-http-server-sse-ring/mount-origin/libwebsockets.org-logo.svg 2020-12-01 17:40:26.000000000 +0000 @@ -1,120 +1,66 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + + +image/svg+xml + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff -Nru libwebsockets-3.2.1/minimal-examples/http-server/minimal-http-server-tls/CMakeLists.txt libwebsockets-4.1.6/minimal-examples/http-server/minimal-http-server-tls/CMakeLists.txt --- libwebsockets-3.2.1/minimal-examples/http-server/minimal-http-server-tls/CMakeLists.txt 2019-12-18 14:45:31.000000000 +0000 +++ libwebsockets-4.1.6/minimal-examples/http-server/minimal-http-server-tls/CMakeLists.txt 2020-12-01 17:40:26.000000000 +0000 @@ -1,79 +1,25 @@ +project(lws-minimal-http-server-tls C) cmake_minimum_required(VERSION 2.8) +find_package(libwebsockets CONFIG REQUIRED) +list(APPEND CMAKE_MODULE_PATH ${LWS_CMAKE_DIR}) include(CheckCSourceCompiles) +include(LwsCheckRequirements) 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_ROLE_H1 1 requirements) -require_lws_config(LWS_WITHOUT_SERVER 0 requirements) -require_lws_config(LWS_OPENSSL_SUPPORT 1 requirements) +require_lws_config(LWS_WITH_SERVER 1 requirements) +require_lws_config(LWS_WITH_TLS 1 requirements) if (requirements) add_executable(${SAMP} ${SRCS}) if (websockets_shared) - target_link_libraries(${SAMP} websockets_shared) + target_link_libraries(${SAMP} websockets_shared ${LIBWEBSOCKETS_DEP_LIBS}) add_dependencies(${SAMP} websockets_shared) else() - target_link_libraries(${SAMP} websockets) + target_link_libraries(${SAMP} websockets ${LIBWEBSOCKETS_DEP_LIBS}) endif() endif() diff -Nru libwebsockets-3.2.1/minimal-examples/http-server/minimal-http-server-tls/minimal-http-server-tls.c libwebsockets-4.1.6/minimal-examples/http-server/minimal-http-server-tls/minimal-http-server-tls.c --- libwebsockets-3.2.1/minimal-examples/http-server/minimal-http-server-tls/minimal-http-server-tls.c 2019-12-18 14:45:31.000000000 +0000 +++ libwebsockets-4.1.6/minimal-examples/http-server/minimal-http-server-tls/minimal-http-server-tls.c 2020-12-01 17:40:26.000000000 +0000 @@ -52,24 +52,17 @@ struct lws_context_creation_info info; struct lws_context *context; const char *p; - int n = 0, logs = LLL_USER | LLL_ERR | LLL_WARN | LLL_NOTICE - /* for LLL_ verbosity above NOTICE to be built into lws, - * lws must have been configured and built with - * -DCMAKE_BUILD_TYPE=DEBUG instead of =RELEASE */ - /* | LLL_INFO */ /* | LLL_PARSER */ /* | LLL_HEADER */ - /* | LLL_EXT */ /* | LLL_CLIENT */ /* | LLL_LATENCY */ - /* | LLL_DEBUG */; - - if ((p = lws_cmdline_option(argc, argv, "-d"))) - logs = atoi(p); - - lws_set_log_level(logs, NULL); - lwsl_user("LWS minimal http server TLS | visit https://localhost:7681\n"); + int n = 0; signal(SIGINT, sigint_handler); memset(&info, 0, sizeof info); /* otherwise uninitialized garbage */ + lws_cmdline_option_handle_builtin(argc, argv, &info); + lwsl_user("LWS minimal http server TLS | visit https://localhost:7681\n"); + info.port = 7681; + if ((p = lws_cmdline_option(argc, argv, "--port"))) + info.port = atoi(p); info.mounts = &mount; info.error_document_404 = "/404.html"; info.options = LWS_SERVER_OPTION_DO_SSL_GLOBAL_INIT | diff -Nru libwebsockets-3.2.1/minimal-examples/http-server/minimal-http-server-tls/mount-origin/example.js libwebsockets-4.1.6/minimal-examples/http-server/minimal-http-server-tls/mount-origin/example.js --- libwebsockets-3.2.1/minimal-examples/http-server/minimal-http-server-tls/mount-origin/example.js 2019-12-18 14:45:31.000000000 +0000 +++ libwebsockets-4.1.6/minimal-examples/http-server/minimal-http-server-tls/mount-origin/example.js 2020-12-01 17:40:26.000000000 +0000 @@ -16,7 +16,6 @@ } } - if (transport_protocol == "h2") + if (transport_protocol === "h2") document.getElementById("transport").innerHTML = ""; - } -}, false); \ No newline at end of file +}, false); diff -Nru libwebsockets-3.2.1/minimal-examples/http-server/minimal-http-server-tls/mount-origin/libwebsockets.org-logo.svg libwebsockets-4.1.6/minimal-examples/http-server/minimal-http-server-tls/mount-origin/libwebsockets.org-logo.svg --- libwebsockets-3.2.1/minimal-examples/http-server/minimal-http-server-tls/mount-origin/libwebsockets.org-logo.svg 2019-12-18 14:45:31.000000000 +0000 +++ libwebsockets-4.1.6/minimal-examples/http-server/minimal-http-server-tls/mount-origin/libwebsockets.org-logo.svg 2020-12-01 17:40:26.000000000 +0000 @@ -1,120 +1,66 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + + +image/svg+xml + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff -Nru libwebsockets-3.2.1/minimal-examples/http-server/minimal-http-server-tls-80/CMakeLists.txt libwebsockets-4.1.6/minimal-examples/http-server/minimal-http-server-tls-80/CMakeLists.txt --- libwebsockets-3.2.1/minimal-examples/http-server/minimal-http-server-tls-80/CMakeLists.txt 2019-12-18 14:45:31.000000000 +0000 +++ libwebsockets-4.1.6/minimal-examples/http-server/minimal-http-server-tls-80/CMakeLists.txt 2020-12-01 17:40:26.000000000 +0000 @@ -1,79 +1,25 @@ +project(lws-minimal-http-server-tls-80 C) cmake_minimum_required(VERSION 2.8) +find_package(libwebsockets CONFIG REQUIRED) +list(APPEND CMAKE_MODULE_PATH ${LWS_CMAKE_DIR}) include(CheckCSourceCompiles) +include(LwsCheckRequirements) set(SAMP lws-minimal-http-server-tls-80) set(SRCS minimal-http-server-tls-80.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_ROLE_H1 1 requirements) -require_lws_config(LWS_WITHOUT_SERVER 0 requirements) -require_lws_config(LWS_OPENSSL_SUPPORT 1 requirements) +require_lws_config(LWS_WITH_SERVER 1 requirements) +require_lws_config(LWS_WITH_TLS 1 requirements) if (requirements) add_executable(${SAMP} ${SRCS}) if (websockets_shared) - target_link_libraries(${SAMP} websockets_shared) + target_link_libraries(${SAMP} websockets_shared ${LIBWEBSOCKETS_DEP_LIBS}) add_dependencies(${SAMP} websockets_shared) else() - target_link_libraries(${SAMP} websockets) + target_link_libraries(${SAMP} websockets ${LIBWEBSOCKETS_DEP_LIBS}) endif() endif() diff -Nru libwebsockets-3.2.1/minimal-examples/http-server/minimal-http-server-tls-80/mount-origin/libwebsockets.org-logo.svg libwebsockets-4.1.6/minimal-examples/http-server/minimal-http-server-tls-80/mount-origin/libwebsockets.org-logo.svg --- libwebsockets-3.2.1/minimal-examples/http-server/minimal-http-server-tls-80/mount-origin/libwebsockets.org-logo.svg 2019-12-18 14:45:31.000000000 +0000 +++ libwebsockets-4.1.6/minimal-examples/http-server/minimal-http-server-tls-80/mount-origin/libwebsockets.org-logo.svg 2020-12-01 17:40:26.000000000 +0000 @@ -1,120 +1,66 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + + +image/svg+xml + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff -Nru libwebsockets-3.2.1/minimal-examples/http-server/minimal-http-server-tls-mem/CMakeLists.txt libwebsockets-4.1.6/minimal-examples/http-server/minimal-http-server-tls-mem/CMakeLists.txt --- libwebsockets-3.2.1/minimal-examples/http-server/minimal-http-server-tls-mem/CMakeLists.txt 2019-12-18 14:45:31.000000000 +0000 +++ libwebsockets-4.1.6/minimal-examples/http-server/minimal-http-server-tls-mem/CMakeLists.txt 2020-12-01 17:40:26.000000000 +0000 @@ -1,79 +1,25 @@ +project(lws-minimal-http-server-tls-mem C) cmake_minimum_required(VERSION 2.8) +find_package(libwebsockets CONFIG REQUIRED) +list(APPEND CMAKE_MODULE_PATH ${LWS_CMAKE_DIR}) include(CheckCSourceCompiles) +include(LwsCheckRequirements) set(SAMP lws-minimal-http-server-tls-mem) set(SRCS minimal-http-server-tls-mem.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_ROLE_H1 1 requirements) -require_lws_config(LWS_WITHOUT_SERVER 0 requirements) -require_lws_config(LWS_OPENSSL_SUPPORT 1 requirements) +require_lws_config(LWS_WITH_SERVER 1 requirements) +require_lws_config(LWS_WITH_TLS 1 requirements) if (requirements) add_executable(${SAMP} ${SRCS}) if (websockets_shared) - target_link_libraries(${SAMP} websockets_shared) + target_link_libraries(${SAMP} websockets_shared ${LIBWEBSOCKETS_DEP_LIBS}) add_dependencies(${SAMP} websockets_shared) else() - target_link_libraries(${SAMP} websockets) + target_link_libraries(${SAMP} websockets ${LIBWEBSOCKETS_DEP_LIBS}) endif() endif() diff -Nru libwebsockets-3.2.1/minimal-examples/http-server/minimal-http-server-tls-mem/minimal-http-server-tls-mem.c libwebsockets-4.1.6/minimal-examples/http-server/minimal-http-server-tls-mem/minimal-http-server-tls-mem.c --- libwebsockets-3.2.1/minimal-examples/http-server/minimal-http-server-tls-mem/minimal-http-server-tls-mem.c 2019-12-18 14:45:31.000000000 +0000 +++ libwebsockets-4.1.6/minimal-examples/http-server/minimal-http-server-tls-mem/minimal-http-server-tls-mem.c 2020-12-01 17:40:26.000000000 +0000 @@ -429,9 +429,9 @@ info.mounts = &mount; info.error_document_404 = "/404.html"; info.server_ssl_cert_mem = cert_pem; - info.server_ssl_cert_mem_len = strlen(cert_pem); + info.server_ssl_cert_mem_len = (unsigned int)strlen(cert_pem); info.server_ssl_private_key_mem = key_pem; - info.server_ssl_private_key_mem_len = strlen(key_pem); + info.server_ssl_private_key_mem_len = (unsigned int)strlen(key_pem); info.vhost_name = "first"; if (!lws_create_vhost(context, &info)) { @@ -443,9 +443,9 @@ info.mounts = &mount; info.error_document_404 = "/404.html"; info.server_ssl_cert_mem = cert_der; - info.server_ssl_cert_mem_len = sizeof(cert_der); + info.server_ssl_cert_mem_len = (unsigned int)sizeof(cert_der); info.server_ssl_private_key_mem = key_der; - info.server_ssl_private_key_mem_len = sizeof(key_der); + info.server_ssl_private_key_mem_len = (unsigned int)sizeof(key_der); info.vhost_name = "second"; if (!lws_create_vhost(context, &info)) { diff -Nru libwebsockets-3.2.1/minimal-examples/http-server/minimal-http-server-tls-mem/mount-origin/example.js libwebsockets-4.1.6/minimal-examples/http-server/minimal-http-server-tls-mem/mount-origin/example.js --- libwebsockets-3.2.1/minimal-examples/http-server/minimal-http-server-tls-mem/mount-origin/example.js 2019-12-18 14:45:31.000000000 +0000 +++ libwebsockets-4.1.6/minimal-examples/http-server/minimal-http-server-tls-mem/mount-origin/example.js 2020-12-01 17:40:26.000000000 +0000 @@ -16,7 +16,7 @@ } } - if (transport_protocol == "h2") + if (transport_protocol === "h2") document.getElementById("transport").innerHTML = ""; - } + }, false); \ No newline at end of file diff -Nru libwebsockets-3.2.1/minimal-examples/http-server/minimal-http-server-tls-mem/mount-origin/libwebsockets.org-logo.svg libwebsockets-4.1.6/minimal-examples/http-server/minimal-http-server-tls-mem/mount-origin/libwebsockets.org-logo.svg --- libwebsockets-3.2.1/minimal-examples/http-server/minimal-http-server-tls-mem/mount-origin/libwebsockets.org-logo.svg 2019-12-18 14:45:31.000000000 +0000 +++ libwebsockets-4.1.6/minimal-examples/http-server/minimal-http-server-tls-mem/mount-origin/libwebsockets.org-logo.svg 2020-12-01 17:40:26.000000000 +0000 @@ -1,120 +1,66 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + + +image/svg+xml + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff -Nru libwebsockets-3.2.1/minimal-examples/mqtt-client/minimal-mqtt-client/CMakeLists.txt libwebsockets-4.1.6/minimal-examples/mqtt-client/minimal-mqtt-client/CMakeLists.txt --- libwebsockets-3.2.1/minimal-examples/mqtt-client/minimal-mqtt-client/CMakeLists.txt 1970-01-01 00:00:00.000000000 +0000 +++ libwebsockets-4.1.6/minimal-examples/mqtt-client/minimal-mqtt-client/CMakeLists.txt 2020-12-01 17:40:26.000000000 +0000 @@ -0,0 +1,23 @@ +project(lws-minimal-mqtt-client C) +cmake_minimum_required(VERSION 2.8) +include(CheckCSourceCompiles) +include(LwsCheckRequirements) + +set(SAMP lws-minimal-mqtt-client) +set(SRCS minimal-mqtt-client.c) + +set(requirements 1) +require_lws_config(LWS_ROLE_MQTT 1 requirements) +require_lws_config(LWS_WITH_CLIENT 1 requirements) +require_lws_config(LWS_WITH_SYS_STATE 1 requirements) + +if (requirements) + add_executable(${SAMP} ${SRCS}) + + if (websockets_shared) + target_link_libraries(${SAMP} websockets_shared ${LIBWEBSOCKETS_DEP_LIBS}) + add_dependencies(${SAMP} websockets_shared) + else() + target_link_libraries(${SAMP} websockets ${LIBWEBSOCKETS_DEP_LIBS}) + endif() +endif() diff -Nru libwebsockets-3.2.1/minimal-examples/mqtt-client/minimal-mqtt-client/minimal-mqtt-client.c libwebsockets-4.1.6/minimal-examples/mqtt-client/minimal-mqtt-client/minimal-mqtt-client.c --- libwebsockets-3.2.1/minimal-examples/mqtt-client/minimal-mqtt-client/minimal-mqtt-client.c 1970-01-01 00:00:00.000000000 +0000 +++ libwebsockets-4.1.6/minimal-examples/mqtt-client/minimal-mqtt-client/minimal-mqtt-client.c 2020-12-01 17:40:26.000000000 +0000 @@ -0,0 +1,349 @@ +/* + * lws-minimal-mqtt-client + * + * Written in 2010-2020 by Andy Green + * Sakthi Kannan + * + * This file is made available under the Creative Commons CC0 1.0 + * Universal Public Domain Dedication. + */ + +#include +#include +#include +#if defined(WIN32) +#define HAVE_STRUCT_TIMESPEC +#if defined(pid_t) +#undef pid_t +#endif +#endif +#include +#include + +enum { + STATE_SUBSCRIBE, /* subscribe to the topic */ + STATE_PUBLISH_QOS0, /* Send the message in QoS0 */ + STATE_WAIT_ACK0, /* Wait for the synthetic "ack" */ + STATE_PUBLISH_QOS1, /* Send the message in QoS1 */ + STATE_WAIT_ACK1, /* Wait for the real ack (or timeout + retry) */ + + STATE_TEST_FINISH +}; + +static int interrupted, bad = 1, do_ssl; + +static const lws_retry_bo_t retry = { + .secs_since_valid_ping = 20, /* if idle, PINGREQ after secs */ + .secs_since_valid_hangup = 25, /* hangup if still idle secs */ +}; + +static const lws_mqtt_client_connect_param_t client_connect_param = { + .client_id = "lwsMqttClient", + .keep_alive = 60, + .clean_start = 1, + .will_param = { + .topic = "good/bye", + .message = "sign-off", + .qos = 0, + .retain = 0, + }, + .username = "lwsUser", + .password = "mySecretPassword", +}; + +static lws_mqtt_publish_param_t pub_param; + +static lws_mqtt_topic_elem_t topics[] = { + [0] = { .name = "test/topic0", .qos = QOS0 }, + [1] = { .name = "test/topic1", .qos = QOS1 }, +}; + +static lws_mqtt_subscribe_param_t sub_param = { + .topic = &topics[0], + .num_topics = LWS_ARRAY_SIZE(topics), +}; + +static const char * const test_string = + "No one would have believed in the last years of the nineteenth " + "century that this world was being watched keenly and closely by " + "intelligences greater than man's and yet as mortal as his own; that as " + "men busied themselves about their various concerns they were " + "scrutinised and studied, perhaps almost as narrowly as a man with a " + "microscope might scrutinise the transient creatures that swarm and " + "multiply in a drop of water. With infinite complacency men went to " + "and fro over this globe about their little affairs, serene in their " + "assurance of their empire over matter. It is possible that the " + "infusoria under the microscope do the same. No one gave a thought to " + "the older worlds of space as sources of human danger, or thought of " + "them only to dismiss the idea of life upon them as impossible or " + "improbable. It is curious to recall some of the mental habits of " + "those departed days. At most terrestrial men fancied there might be " + "other men upon Mars, perhaps inferior to themselves and ready to " + "welcome a missionary enterprise. Yet across the gulf of space, minds " + "that are to our minds as ours are to those of the beasts that perish, " + "intellects vast and cool and unsympathetic, regarded this earth with " + "envious eyes, and slowly and surely drew their plans against us. And " + "early in the twentieth century came the great disillusionment. "; + +/* this reflects the length of the string above */ +#define TEST_STRING_LEN 1337 + +struct pss { + int state; + size_t pos; + int retries; +}; + +static void +sigint_handler(int sig) +{ + interrupted = 1; +} + +static int +connect_client(struct lws_context *context) +{ + struct lws_client_connect_info i; + + memset(&i, 0, sizeof i); + + i.mqtt_cp = &client_connect_param; + i.address = "localhost"; + i.host = "localhost"; + i.protocol = "mqtt"; + i.context = context; + i.method = "MQTT"; + i.alpn = "mqtt"; + i.port = 1883; + + if (do_ssl) { + i.ssl_connection = LCCSCF_USE_SSL; + i.ssl_connection |= LCCSCF_ALLOW_SELFSIGNED; + i.port = 8883; + } + + if (!lws_client_connect_via_info(&i)) { + lwsl_err("%s: Client Connect Failed\n", __func__); + + return 1; + } + + return 0; +} + +static int +system_notify_cb(lws_state_manager_t *mgr, lws_state_notify_link_t *link, + int current, int target) +{ + struct lws_context *context = mgr->parent; + + if (current != LWS_SYSTATE_OPERATIONAL || + target != LWS_SYSTATE_OPERATIONAL) + return 0; + + /* + * We delay trying to do the client connection until + * the protocols have been initialized for each + * vhost... this happens after we have network and + * time so we can judge tls cert validity. + */ + + if (connect_client(context)) + interrupted = 1; + + return 0; + } + + +static int +callback_mqtt(struct lws *wsi, enum lws_callback_reasons reason, + void *user, void *in, size_t len) +{ + struct pss *pss = (struct pss *)user; + lws_mqtt_publish_param_t *pub; + size_t chunk; + + switch (reason) { + case LWS_CALLBACK_CLIENT_CONNECTION_ERROR: + lwsl_err("%s: CLIENT_CONNECTION_ERROR: %s\n", __func__, + in ? (char *)in : "(null)"); + interrupted = 1; + break; + + case LWS_CALLBACK_MQTT_CLIENT_CLOSED: + lwsl_user("%s: CLIENT_CLOSED\n", __func__); + interrupted = 1; + break; + + case LWS_CALLBACK_MQTT_CLIENT_ESTABLISHED: + lwsl_user("%s: MQTT_CLIENT_ESTABLISHED\n", __func__); + lws_callback_on_writable(wsi); + + return 0; + + case LWS_CALLBACK_MQTT_SUBSCRIBED: + lwsl_user("%s: MQTT_SUBSCRIBED\n", __func__); + break; + + case LWS_CALLBACK_MQTT_CLIENT_WRITEABLE: + /* + * Extra WRITEABLE may appear here other than ones we asked + * for, so we must consult our own state to decide if we want + * to make use of the opportunity + */ + + switch (pss->state) { + case STATE_SUBSCRIBE: + lwsl_user("%s: WRITEABLE: Subscribing\n", __func__); + + if (lws_mqtt_client_send_subcribe(wsi, &sub_param)) { + lwsl_notice("%s: subscribe failed\n", __func__); + + return -1; + } + pss->state++; + break; + + case STATE_PUBLISH_QOS0: + case STATE_PUBLISH_QOS1: + + lwsl_user("%s: WRITEABLE: Publish\n", __func__); + + pub_param.topic = "test/topic"; + pub_param.topic_len = (uint16_t)strlen(pub_param.topic); + pub_param.qos = pss->state == STATE_PUBLISH_QOS0 ? QOS0 : QOS1; + pub_param.payload_len = TEST_STRING_LEN; + + /* We send the message out 300 bytes or less at at time */ + + chunk = 300; + + if (chunk > TEST_STRING_LEN - pss->pos) + chunk = TEST_STRING_LEN - pss->pos; + + if (lws_mqtt_client_send_publish(wsi, &pub_param, + test_string + pss->pos, chunk, + (pss->pos + chunk == TEST_STRING_LEN))) + return -1; + + pss->pos += chunk; + + if (pss->pos == TEST_STRING_LEN) { + pss->pos = 0; + pss->state++; + } + break; + + default: + break; + } + + return 0; + + case LWS_CALLBACK_MQTT_ACK: + lwsl_user("%s: MQTT_ACK\n", __func__); + /* + * We can forget about the message we just sent, it's done. + * + * For our test, that's the indication we can close the wsi. + */ + + pss->state++; + if (pss->state != STATE_TEST_FINISH) + break; + + /* Oh we are done then */ + + bad = 0; + interrupted = 1; + lws_cancel_service(lws_get_context(wsi)); + break; + + case LWS_CALLBACK_MQTT_RESEND: + lwsl_user("%s: MQTT_RESEND\n", __func__); + /* + * We must resend the packet ID mentioned in len + */ + if (++pss->retries == 3) { + interrupted = 1; + break; + } + pss->state--; + pss->pos = 0; + break; + + case LWS_CALLBACK_MQTT_CLIENT_RX: + lwsl_user("%s: MQTT_CLIENT_RX\n", __func__); + + pub = (lws_mqtt_publish_param_t *)in; + assert(pub); + + lwsl_hexdump_notice(pub->topic, pub->topic_len); + lwsl_hexdump_notice(pub->payload, pub->payload_len); + + return 0; + + default: + break; + } + + return 0; +} + +static const struct lws_protocols protocols[] = { + { + .name = "mqtt", + .callback = callback_mqtt, + .per_session_data_size = sizeof(struct pss) + }, + { NULL, NULL, 0, 0 } +}; + +int main(int argc, const char **argv) +{ + lws_state_notify_link_t notifier = { {}, system_notify_cb, "app" }; + lws_state_notify_link_t *na[] = { ¬ifier, NULL }; + 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 */ + lws_cmdline_option_handle_builtin(argc, argv, &info); + + do_ssl = !!lws_cmdline_option(argc, argv, "-s"); + if (do_ssl) + info.options = LWS_SERVER_OPTION_DO_SSL_GLOBAL_INIT; + + lwsl_user("LWS minimal MQTT client %s [-d][-s]\n", + do_ssl ? "tls enabled": "unencrypted"); + + info.port = CONTEXT_PORT_NO_LISTEN; /* we do not run any server */ + info.protocols = protocols; + info.register_notifier_list = na; + info.fd_limit_per_thread = 1 + 1 + 1; + info.retry_and_idle_policy = &retry; + +#if defined(LWS_WITH_MBEDTLS) || defined(USE_WOLFSSL) + /* + * OpenSSL uses the system trust store. mbedTLS has to be told which + * CA to trust explicitly. + */ + info.client_ssl_ca_filepath = "./mosq-ca.crt"; +#endif + + context = lws_create_context(&info); + if (!context) { + lwsl_err("lws init failed\n"); + return 1; + } + + /* Event loop */ + while (n >= 0 && !interrupted) + n = lws_service(context, 0); + + lwsl_user("Completed: %s\n", bad ? "failed" : "OK"); + lws_context_destroy(context); + + return bad; +} diff -Nru libwebsockets-3.2.1/minimal-examples/mqtt-client/minimal-mqtt-client/mosq-ca.crt libwebsockets-4.1.6/minimal-examples/mqtt-client/minimal-mqtt-client/mosq-ca.crt --- libwebsockets-3.2.1/minimal-examples/mqtt-client/minimal-mqtt-client/mosq-ca.crt 1970-01-01 00:00:00.000000000 +0000 +++ libwebsockets-4.1.6/minimal-examples/mqtt-client/minimal-mqtt-client/mosq-ca.crt 2020-12-01 17:40:26.000000000 +0000 @@ -0,0 +1,22 @@ +-----BEGIN CERTIFICATE----- +MIIDjzCCAnegAwIBAgIUAVMnfaOq8yiLnvIB/obE689mulMwDQYJKoZIhvcNAQEL +BQAwVjELMAkGA1UEBhMCWFgxFTATBgNVBAcMDERlZmF1bHQgQ2l0eTEcMBoGA1UE +CgwTRGVmYXVsdCBDb21wYW55IEx0ZDESMBAGA1UEAwwJbG9jYWxob3N0MCAXDTE5 +MTEyMDA1NTYyNFoYDzIxMTkxMDI3MDU1NjI0WjBWMQswCQYDVQQGEwJYWDEVMBMG +A1UEBwwMRGVmYXVsdCBDaXR5MRwwGgYDVQQKDBNEZWZhdWx0IENvbXBhbnkgTHRk +MRIwEAYDVQQDDAlsb2NhbGhvc3QwggEiMA0GCSqGSIb3DQEBAQUAA4IBDwAwggEK +AoIBAQCyw+kBLg9lCGlBceil0lNqgh7fyguin8IFm5X60bfSJ/pV6i8dZZplVjE+ +g75iFEFBYyfn+6bOPdinfQ7Uu+l6t6y2HWbK6MkoypF/g7cdtUFy9s4cUX0467BZ +hMPJUc4UfnD+bYcXoguPJ6/OH84+Ayg6uvm5nJ32pDiXr6gMd5YljdXaJpCeeh4w +O2UBD1HffyPIklIPT59lxv2ZvKnZbE4UE1uaLLvTWiT+X+gA3i0Syxkq5RlZ61DE +3MyIYAUVSf3coNXCSdJ9wrOsGoP+X+T+aDjnFCCnqus3QX3JOHTKf4+tBoF65cNP +mnHXb5/ZQCcR9HMofacalMpjiGb7AgMBAAGjUzBRMB0GA1UdDgQWBBTl3poLE/22 +R4RXTMoXPHMlc3QRjzAfBgNVHSMEGDAWgBTl3poLE/22R4RXTMoXPHMlc3QRjzAP +BgNVHRMBAf8EBTADAQH/MA0GCSqGSIb3DQEBCwUAA4IBAQCwWVnNjKRH9CCBv3yT +Djah51q3NH3E+f1IcBZz2c5WbJHxEtP4QC57ou2x3hC7Cur9iOqIO57VW8vnFP2Y +bD9oHb46grsGhwuaSuA2AlFZ5EuUAe2cgEj5/3Ihd3HYsXN3rfRO1PVGN1iRG1sE +xAxENNm6nOS1Ht1Zy5YmMiSPzghcsTnpg44AqsmowbIED75EpumLwY2NbAl9/7JL +EJil3cxEZ8rl2DVWPU3hAwrOfhl/rkQTCcigyPvZvAqsJ9vYhZftrF6njUsqr5kL +KHENu5ySKPNk5gFR17WjWoqT6iEOZN25qyfFhBRzjpCX6zD1gx0sYcVryCnTH5Y4 +Drjh +-----END CERTIFICATE----- diff -Nru libwebsockets-3.2.1/minimal-examples/mqtt-client/minimal-mqtt-client/mosq-server.crt libwebsockets-4.1.6/minimal-examples/mqtt-client/minimal-mqtt-client/mosq-server.crt --- libwebsockets-3.2.1/minimal-examples/mqtt-client/minimal-mqtt-client/mosq-server.crt 1970-01-01 00:00:00.000000000 +0000 +++ libwebsockets-4.1.6/minimal-examples/mqtt-client/minimal-mqtt-client/mosq-server.crt 2020-12-01 17:40:26.000000000 +0000 @@ -0,0 +1,20 @@ +-----BEGIN CERTIFICATE----- +MIIDNTCCAh0CFFu5XIMrh5gPYnjTr8UrXA3UiWqHMA0GCSqGSIb3DQEBCwUAMFYx +CzAJBgNVBAYTAlhYMRUwEwYDVQQHDAxEZWZhdWx0IENpdHkxHDAaBgNVBAoME0Rl +ZmF1bHQgQ29tcGFueSBMdGQxEjAQBgNVBAMMCWxvY2FsaG9zdDAgFw0xOTExMjAw +NTU4NTdaGA8yMTE5MTAyNzA1NTg1N1owVjELMAkGA1UEBhMCWFgxFTATBgNVBAcM +DERlZmF1bHQgQ2l0eTEcMBoGA1UECgwTRGVmYXVsdCBDb21wYW55IEx0ZDESMBAG +A1UEAwwJbG9jYWxob3N0MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEA +tldZ5yGrBsLR/7G4b48pwQSSG6fp4egiZdeFV7SRNfbMzpuIDlFdZM9zdcoQQrTl +24aVIGwkvfsMD33Hb/D1WW+r8UFnq4CutigwXArXUxoFX6fa0rwEEjuxwG3f7+xm +vb6p/KXomyWcdAUmAvALaDXIUDEc3tH+Hxik5z36YjIqRjH16jhhs/6T8B3xAWuR +jnDknJWv36QruMIyPUqYYkl2zl4VXUKBgWZr31Opm08kb/FrWJ6lQ7912jZC8G2L +rtwZJB/1psBrX3Oj/Quj+BWHmzkosqVae2G5zAhphZ2NMrdSVfxdctNmakH8oTwf +hRas8DE2olW3whUkfKG2DQIDAQABMA0GCSqGSIb3DQEBCwUAA4IBAQAKEQ7LpPdU +XbJKushJ7wmuljQn3pmW9SjzFMlL9o59KLHWAmxzTDaAm6r3SGgHeSz3ZLwqtJ8I +7pCxQxI6V1ySMkWI1mfi4KPSavxBRaST4o8+YIKJt4c5aLB1seHoghx3Q/jXEGEB +9dFyLMK6u3EhYSletQNeMVGaeK1q/nVZdHNk4LXVIHsXnKlxyMnW3v18iaV3ZhVd +doAWMpnbY91AyCXjOmQrfQaHLL6n3r1Xk2L+cRO3nSor54UIXqIJxHZtj+ZYOy3Z +C5AkQ1yyTTOtEz9WB0Bk2O4ZfNgJO+1MbQSfL0m0YKpuaFnMHD9g5ufUlJGR2aMI +nw1F/oGZoNUl +-----END CERTIFICATE----- diff -Nru libwebsockets-3.2.1/minimal-examples/mqtt-client/minimal-mqtt-client/mosq-server.key libwebsockets-4.1.6/minimal-examples/mqtt-client/minimal-mqtt-client/mosq-server.key --- libwebsockets-3.2.1/minimal-examples/mqtt-client/minimal-mqtt-client/mosq-server.key 1970-01-01 00:00:00.000000000 +0000 +++ libwebsockets-4.1.6/minimal-examples/mqtt-client/minimal-mqtt-client/mosq-server.key 2020-12-01 17:40:26.000000000 +0000 @@ -0,0 +1,27 @@ +-----BEGIN RSA PRIVATE KEY----- +MIIEpQIBAAKCAQEAtldZ5yGrBsLR/7G4b48pwQSSG6fp4egiZdeFV7SRNfbMzpuI +DlFdZM9zdcoQQrTl24aVIGwkvfsMD33Hb/D1WW+r8UFnq4CutigwXArXUxoFX6fa +0rwEEjuxwG3f7+xmvb6p/KXomyWcdAUmAvALaDXIUDEc3tH+Hxik5z36YjIqRjH1 +6jhhs/6T8B3xAWuRjnDknJWv36QruMIyPUqYYkl2zl4VXUKBgWZr31Opm08kb/Fr +WJ6lQ7912jZC8G2LrtwZJB/1psBrX3Oj/Quj+BWHmzkosqVae2G5zAhphZ2NMrdS +VfxdctNmakH8oTwfhRas8DE2olW3whUkfKG2DQIDAQABAoIBACMctwc3CIQIx/+A +7Y8t9lBg3PHOZ89EsDsEQX0eHEhT+iRe9tgq+t0KxaUNAAyYYRrg056mtHyQ90WU +Zu87a0OJqYaPnbL82KfjHUzcGZK7FAXTgOPLqM0KCbSQc+rzjuVC7eDk4eHeYD5H +L4apSskKckRe8LxHm7PJPxf4a1q1EuMEfAyJhh7Tot0oVsG/wABGFUuJVJWXnec1 +0ukPowKh9bg7UyEecwyeYGzXqNqvbjhS3J0dBkjG5vfxuVHae2yIeXk6ZNsCw6tO +K8bklmsmbWAFR5SKpsNve8X/6nlclP0taDDZsz0KSbxJEd2DuRhFcdiRWEoryZVp +7DOORFECgYEA5sdsRjQoHaU85QZuM7ff6NpNT7kMIJbjHRdiauEBakLHs8yVLNEp +Vvg5fcZY4PumqPKyGEjUD6DenlLvb4OBGqzKGGhAJaLz9cpVoWWPz8y1NRBfPjlB +FQdB4GdtBQGXwnZoD9kXPjYHlk4nwZZ/Sitm2w6RibiIxE0adnwLhP8CgYEAykTE +5NZ88OGGf0RWUt54OxTl4fChAcvK93KkdlK9nbokXHs7VIl4QpKPFu1nuMDrkVI4 +fVYwRDcZUjyxqbpBSf/M6T/kuEsMWBYYGv5c9/U87y0UWHbphN0TSdML2DJp9BTy +uy4RleQovof2kOr6sOsKP8lhBGSlhXyJDKn1iPMCgYEAnpvc7HsYPxe7vGQpBV6Q +g0bV777seNF7EhlqSK6P/GodOpOWyxCN6vn6+ViC6U3Lgz4Z7NrQ9FTJ6+JwMSIe +byjmVNQBklxmcz02kRBuQJEe0XOJIgjTlBJC0moC4Xfwx3P9nTbE5LrZiBH6/O/k +WCNwM4nVuOOdC906HMiwWh0CgYEAqn3m3ODydXQTk2i9vqIpA9vsnVLf1Ay8a3El +sVqy26VQCugQrYQmay7wD6pS2Ec9CMQeO3+PtaAf5tKkCmWlrMNCLIWfu7v+jq0o +6m/nW1ZKY2xDDwJEeaqDHKIZBMYRyxxxMVd2mTq1IUynh6WZY9DqVbPf4/0WC/tZ +5ePIxAMCgYEAwwBNT2xjG1mWD4eANvKjQgrsxKFttmaXXCiixZJR+tsQc5bff5Yb +IgvvkIwLHoNpL2Nk7sEjS4sUtAKwzCtIMwvPnhQedICnOEteZ8NPfaFmPewcovcL +gv9k+mFActZ7H8i9FXLrZHyEzOXZaM/vY/mHbrlJSWnSDZsvnVzQv+o= +-----END RSA PRIVATE KEY----- diff -Nru libwebsockets-3.2.1/minimal-examples/mqtt-client/minimal-mqtt-client/README.md libwebsockets-4.1.6/minimal-examples/mqtt-client/minimal-mqtt-client/README.md --- libwebsockets-3.2.1/minimal-examples/mqtt-client/minimal-mqtt-client/README.md 1970-01-01 00:00:00.000000000 +0000 +++ libwebsockets-4.1.6/minimal-examples/mqtt-client/minimal-mqtt-client/README.md 2020-12-01 17:40:26.000000000 +0000 @@ -0,0 +1,51 @@ +# lws minimal MQTT client + +The application connects to a broker at localhost 1883 (unencrypted) or +8883 (tls) + +## build + +``` + $ cmake . && make +``` + +## usage + +Commandline option|Meaning +---|--- +-d |Debug verbosity in decimal, eg, -d15 +-s| Use tls and connect to port 8883 instead of 1883 + +Start mosquitto server locally + +``` +$ mosquitto +``` + +Run the example + +``` +[2020/01/31 10:40:23:7789] U: LWS minimal MQTT client unencrypted [-d][-s] +[2020/01/31 10:40:23:8539] N: lws_mqtt_generate_id: User space provided a client ID 'lwsMqttClient' +[2020/01/31 10:40:23:9893] N: _lws_mqtt_rx_parser: migrated nwsi 0x50febd0 to sid 1 0x5106820 +[2020/01/31 10:40:23:9899] U: callback_mqtt: MQTT_CLIENT_ESTABLISHED +[2020/01/31 10:40:23:9967] U: callback_mqtt: WRITEABLE: Subscribing +[2020/01/31 10:40:24:0068] U: callback_mqtt: MQTT_SUBSCRIBED +``` + +Send something to the test client + + +``` +mosquitto_pub -h 127.0.0.1 -p 1883 -t test/topic0 -m "hello" +``` + +Observe it received at the test client + +``` +[2020/01/31 10:40:27:1845] U: callback_mqtt: MQTT_CLIENT_RX +[2020/01/31 10:40:27:1870] N: +[2020/01/31 10:40:27:1945] N: 0000: 74 65 73 74 2F 74 6F 70 69 63 30 test/topic0 +[2020/01/31 10:40:27:1952] N: + +``` diff -Nru libwebsockets-3.2.1/minimal-examples/mqtt-client/minimal-mqtt-client-multi/CMakeLists.txt libwebsockets-4.1.6/minimal-examples/mqtt-client/minimal-mqtt-client-multi/CMakeLists.txt --- libwebsockets-3.2.1/minimal-examples/mqtt-client/minimal-mqtt-client-multi/CMakeLists.txt 1970-01-01 00:00:00.000000000 +0000 +++ libwebsockets-4.1.6/minimal-examples/mqtt-client/minimal-mqtt-client-multi/CMakeLists.txt 2020-12-01 17:40:26.000000000 +0000 @@ -0,0 +1,25 @@ +project(lws-minimal-mqtt-client-multi C) +cmake_minimum_required(VERSION 2.8) +find_package(libwebsockets CONFIG REQUIRED) +list(APPEND CMAKE_MODULE_PATH ${LWS_CMAKE_DIR}) +include(CheckCSourceCompiles) +include(LwsCheckRequirements) + +set(SAMP lws-minimal-mqtt-client-multi) +set(SRCS minimal-mqtt-client-multi.c) + +set(requirements 1) +require_lws_config(LWS_ROLE_MQTT 1 requirements) +require_lws_config(LWS_WITH_CLIENT 1 requirements) +require_lws_config(LWS_WITH_SYS_STATE 1 requirements) + +if (requirements) + add_executable(${SAMP} ${SRCS}) + + if (websockets_shared) + target_link_libraries(${SAMP} websockets_shared ${LIBWEBSOCKETS_DEP_LIBS}) + add_dependencies(${SAMP} websockets_shared) + else() + target_link_libraries(${SAMP} websockets ${LIBWEBSOCKETS_DEP_LIBS}) + endif() +endif() diff -Nru libwebsockets-3.2.1/minimal-examples/mqtt-client/minimal-mqtt-client-multi/minimal-mqtt-client-multi.c libwebsockets-4.1.6/minimal-examples/mqtt-client/minimal-mqtt-client-multi/minimal-mqtt-client-multi.c --- libwebsockets-3.2.1/minimal-examples/mqtt-client/minimal-mqtt-client-multi/minimal-mqtt-client-multi.c 1970-01-01 00:00:00.000000000 +0000 +++ libwebsockets-4.1.6/minimal-examples/mqtt-client/minimal-mqtt-client-multi/minimal-mqtt-client-multi.c 2020-12-01 17:40:26.000000000 +0000 @@ -0,0 +1,443 @@ +/* + * lws-minimal-mqtt-client + * + * Written in 2010-2020 by Andy Green + * Sakthi Kannan + * + * This file is made available under the Creative Commons CC0 1.0 + * Universal Public Domain Dedication. + */ + +#include +#include +#include +#if defined(WIN32) +#define HAVE_STRUCT_TIMESPEC +#if defined(pid_t) +#undef pid_t +#endif +#endif +#include +#include + +#define COUNT 8 + +struct test_item { + struct lws_context *context; + struct lws *wsi; + lws_sorted_usec_list_t sul; +} items[COUNT]; + +enum { + STATE_SUBSCRIBE, /* subscribe to the topic */ + STATE_WAIT_SUBACK, + STATE_PUBLISH_QOS0, /* Send the message in QoS0 */ + STATE_WAIT_ACK0, /* Wait for the synthetic "ack" */ + STATE_PUBLISH_QOS1, /* Send the message in QoS1 */ + STATE_WAIT_ACK1, /* Wait for the real ack (or timeout + retry) */ + STATE_UNSUBSCRIBE, + STATE_WAIT_UNSUBACK, + + STATE_TEST_FINISH +}; + +static int interrupted, do_ssl, pipeline, stagger_us = 5000, okay, + done, count = COUNT; + +static const lws_retry_bo_t retry = { + .secs_since_valid_ping = 20, /* if idle, PINGREQ after secs */ + .secs_since_valid_hangup = 25, /* hangup if still idle secs */ +}; + +static const lws_mqtt_client_connect_param_t client_connect_param = { + .client_id = NULL, + .keep_alive = 60, + .clean_start = 1, + .will_param = { + .topic = "good/bye", + .message = "sign-off", + .qos = 0, + .retain = 0, + }, + .username = "lwsUser", + .password = "mySecretPassword", +}; + +static lws_mqtt_topic_elem_t topics[] = { + [0] = { .name = "test/topic0", .qos = QOS0 }, + [1] = { .name = "test/topic1", .qos = QOS1 }, +}; + +static lws_mqtt_subscribe_param_t sub_param = { + .topic = &topics[0], + .num_topics = LWS_ARRAY_SIZE(topics), +}; + +static const char * const test_string = + "No one would have believed in the last years of the nineteenth " + "century that this world was being watched keenly and closely by " + "intelligences greater than man's and yet as mortal as his own; that as " + "men busied themselves about their various concerns they were " + "scrutinised and studied, perhaps almost as narrowly as a man with a " + "microscope might scrutinise the transient creatures that swarm and " + "multiply in a drop of water. With infinite complacency men went to " + "and fro over this globe about their little affairs, serene in their " + "assurance of their empire over matter. It is possible that the " + "infusoria under the microscope do the same. No one gave a thought to " + "the older worlds of space as sources of human danger, or thought of " + "them only to dismiss the idea of life upon them as impossible or " + "improbable. It is curious to recall some of the mental habits of " + "those departed days. At most terrestrial men fancied there might be " + "other men upon Mars, perhaps inferior to themselves and ready to " + "welcome a missionary enterprise. Yet across the gulf of space, minds " + "that are to our minds as ours are to those of the beasts that perish, " + "intellects vast and cool and unsympathetic, regarded this earth with " + "envious eyes, and slowly and surely drew their plans against us. And " + "early in the twentieth century came the great disillusionment. "; + +/* this reflects the length of the string above */ +#define TEST_STRING_LEN 1337 + +struct pss { + lws_mqtt_publish_param_t pub_param; + int state; + size_t pos; + int retries; +}; + +static void +sigint_handler(int sig) +{ + interrupted = 1; +} + +static int +connect_client(struct lws_context *context, struct test_item *item) +{ + struct lws_client_connect_info i; + + memset(&i, 0, sizeof i); + + i.mqtt_cp = &client_connect_param; + i.opaque_user_data = item; + i.protocol = "test-mqtt"; + i.address = "localhost"; + i.host = "localhost"; + i.pwsi = &item->wsi; + i.context = context; + i.method = "MQTT"; + i.alpn = "mqtt"; + i.port = 1883; + + if (do_ssl) { + i.ssl_connection = LCCSCF_USE_SSL; + i.ssl_connection |= LCCSCF_ALLOW_SELFSIGNED; + i.port = 8883; + } + + if (pipeline) + i.ssl_connection |= LCCSCF_PIPELINE; + + if (!lws_client_connect_via_info(&i)) { + lwsl_err("%s: Client Connect Failed\n", __func__); + + return 1; + } + + return 0; +} + +static void +start_conn(struct lws_sorted_usec_list *sul) +{ + struct test_item *item = lws_container_of(sul, struct test_item, sul); + + lwsl_notice("%s: item %d\n", __func__, (int)(item - &items[0])); + + if (connect_client(item->context, item)) + interrupted = 1; +} + + +static int +system_notify_cb(lws_state_manager_t *mgr, lws_state_notify_link_t *link, + int current, int target) +{ + struct lws_context *context = mgr->parent; + int n; + + if (current != LWS_SYSTATE_OPERATIONAL || + target != LWS_SYSTATE_OPERATIONAL) + return 0; + + /* + * We delay trying to do the client connection until the protocols have + * been initialized for each vhost... this happens after we have network + * and time so we can judge tls cert validity. + * + * Stagger the connection attempts so we get some joining before the + * first has connected and some afterwards + */ + + for (n = 0; n < count; n++) { + items[n].context = context; + lws_sul_schedule(context, 0, &items[n].sul, start_conn, + n * stagger_us); + } + + return 0; +} + + +static int +callback_mqtt(struct lws *wsi, enum lws_callback_reasons reason, + void *user, void *in, size_t len) +{ + struct test_item *item = (struct test_item *)lws_get_opaque_user_data(wsi); + struct pss *pss = (struct pss *)user; + lws_mqtt_publish_param_t *pub; + size_t chunk; + + switch (reason) { + case LWS_CALLBACK_CLIENT_CONNECTION_ERROR: + lwsl_err("%s: CLIENT_CONNECTION_ERROR: %s\n", __func__, + in ? (char *)in : "(null)"); + + if (++done == count) + goto finish_test; + break; + + case LWS_CALLBACK_MQTT_CLIENT_CLOSED: + lwsl_user("%s: item %d: CLIENT_CLOSED %p\n", __func__, (int)(item - &items[0]), wsi); + + if (++done == count) + goto finish_test; + break; + + case LWS_CALLBACK_MQTT_CLIENT_ESTABLISHED: + lwsl_user("%s: MQTT_CLIENT_ESTABLISHED: %p\n", __func__, wsi); + lws_callback_on_writable(wsi); + + return 0; + + case LWS_CALLBACK_MQTT_SUBSCRIBED: + lwsl_user("%s: MQTT_SUBSCRIBED\n", __func__); + + /* then we can get on with the actual test part */ + + pss->state++; + lws_callback_on_writable(wsi); + break; + + case LWS_CALLBACK_MQTT_UNSUBSCRIBED: + lwsl_user("%s: item %d: UNSUBSCRIBED: %p: Received unsuback\n", + __func__, (int)(item - &item[0]), wsi); + okay++; + + if (++pss->state == STATE_TEST_FINISH) { + lwsl_notice("%s: MQTT_UNSUBACK ending stream %d successfully(%d/%d)\n", + __func__, (int)(item - &items[0]), okay, count); + /* We are done, request to close */ + return -1; + } + break; + + case LWS_CALLBACK_MQTT_CLIENT_WRITEABLE: + + /* + * Extra WRITEABLE may appear here other than ones we asked + * for, so we must consult our own state to decide if we want + * to make use of the opportunity + */ + + switch (pss->state) { + case STATE_SUBSCRIBE: + lwsl_user("%s: item %d: WRITEABLE: %p: Subscribing\n", __func__, (int)(item - &items[0]), wsi); + + if (lws_mqtt_client_send_subcribe(wsi, &sub_param)) { + lwsl_notice("%s: subscribe failed\n", __func__); + + return -1; + } + pss->state++; + break; + + case STATE_PUBLISH_QOS0: + case STATE_PUBLISH_QOS1: + + lwsl_user("%s: item %d: WRITEABLE: %p: Publish\n", __func__, (int)(item - &items[0]), wsi); + + pss->pub_param.topic = pss->state == STATE_PUBLISH_QOS0 ? + "test/topic0" : "test/topic1"; + pss->pub_param.topic_len = (uint16_t)strlen(pss->pub_param.topic); + pss->pub_param.qos = + pss->state == STATE_PUBLISH_QOS0 ? QOS0 : QOS1; + pss->pub_param.payload_len = TEST_STRING_LEN; + + /* We send the message out 300 bytes or less at at time */ + + chunk = 300; + + if (chunk > TEST_STRING_LEN - pss->pos) + chunk = TEST_STRING_LEN - pss->pos; + + lwsl_notice("%s: sending %d at +%d\n", __func__, + (int)chunk, (int)pss->pos); + + if (lws_mqtt_client_send_publish(wsi, &pss->pub_param, + test_string + pss->pos, chunk, + (pss->pos + chunk == TEST_STRING_LEN))) { + lwsl_notice("%s: publish failed\n", __func__); + return -1; + } + + pss->pos += chunk; + + if (pss->pos == TEST_STRING_LEN) { + lwsl_debug("%s: sent message\n", __func__); + pss->pos = 0; + pss->state++; + } + break; + + case STATE_UNSUBSCRIBE: + lwsl_user("%s: item %d: UNSUBSCRIBE: %p: Send unsub\n", + __func__, (int)(item - &item[0]), wsi); + pss->state++; + if (lws_mqtt_client_send_unsubcribe(wsi, &sub_param)) { + lwsl_notice("%s: subscribe failed\n", __func__); + return -1; + } + break; + default: + break; + } + + return 0; + + case LWS_CALLBACK_MQTT_ACK: + lwsl_user("%s: item %d: MQTT_ACK (state %d)\n", __func__, (int)(item - &items[0]), pss->state); + /* + * We can forget about the message we just sent, it's done. + * + * For our test, that's the indication we can close the wsi. + */ + + pss->state++; + if (pss->state != STATE_TEST_FINISH) { + lws_callback_on_writable(wsi); + break; + } + + break; + + case LWS_CALLBACK_MQTT_RESEND: + lwsl_user("%s: MQTT_RESEND\n", __func__); + /* + * We must resend the packet ID mentioned in len + */ + if (++pss->retries == 3) { + lwsl_notice("%s: too many retries\n", __func__); + return 1; /* kill the connection */ + } + pss->state--; + pss->pos = 0; + break; + + case LWS_CALLBACK_MQTT_CLIENT_RX: + pub = (lws_mqtt_publish_param_t *)in; + assert(pub); + lwsl_user("%s: item %d: MQTT_CLIENT_RX (%s) pos %d/%d len %d\n", __func__, + (int)(item - &items[0]), pub->topic, (int)pub->payload_pos, + (int)pub->payload_len, (int)len); + + //lwsl_hexdump_info(pub->payload, len); + + return 0; + + default: + break; + } + + return 0; + +finish_test: + interrupted = 1; + lws_cancel_service(lws_get_context(wsi)); + + return 0; +} + +static const struct lws_protocols protocols[] = { + { + .name = "test-mqtt", + .callback = callback_mqtt, + .per_session_data_size = sizeof(struct pss) + }, + { NULL, NULL, 0, 0 } +}; + +int main(int argc, const char **argv) +{ + lws_state_notify_link_t notifier = { {}, system_notify_cb, "app" }; + lws_state_notify_link_t *na[] = { ¬ifier, NULL }; + struct lws_context_creation_info info; + struct lws_context *context; + const char *p; + int n = 0; + + signal(SIGINT, sigint_handler); + memset(&info, 0, sizeof info); /* otherwise uninitialized garbage */ + lws_cmdline_option_handle_builtin(argc, argv, &info); + + do_ssl = !!lws_cmdline_option(argc, argv, "-s"); + if (do_ssl) + info.options = LWS_SERVER_OPTION_DO_SSL_GLOBAL_INIT; + + if (lws_cmdline_option(argc, argv, "-p")) + pipeline = 1; + + if ((p = lws_cmdline_option(argc, argv, "-i"))) + stagger_us = atoi(p); + + if ((p = lws_cmdline_option(argc, argv, "-c"))) + count = atoi(p); + + if (count > COUNT) { + count = COUNT; + lwsl_err("%s: clipped count at max %d\n", __func__, count); + } + + lwsl_user("LWS minimal MQTT client %s [-d][-s]\n", + do_ssl ? "tls enabled": "unencrypted"); + + info.port = CONTEXT_PORT_NO_LISTEN; /* we do not run any server */ + info.protocols = protocols; + info.register_notifier_list = na; + info.fd_limit_per_thread = 1 + COUNT + 1; + info.retry_and_idle_policy = &retry; + +#if defined(LWS_WITH_MBEDTLS) || defined(USE_WOLFSSL) + /* + * OpenSSL uses the system trust store. mbedTLS has to be told which + * CA to trust explicitly. + */ + info.client_ssl_ca_filepath = "./mosq-ca.crt"; +#endif + + context = lws_create_context(&info); + if (!context) { + lwsl_err("lws init failed\n"); + return 1; + } + + /* Event loop */ + while (n >= 0 && !interrupted) + n = lws_service(context, 0); + + lwsl_user("%s: Completed: %d/%d ok, %s\n", __func__, okay, count, + okay != count ? "failed" : "OK"); + lws_context_destroy(context); + + return okay != count; +} diff -Nru libwebsockets-3.2.1/minimal-examples/mqtt-client/minimal-mqtt-client-multi/README.md libwebsockets-4.1.6/minimal-examples/mqtt-client/minimal-mqtt-client-multi/README.md --- libwebsockets-3.2.1/minimal-examples/mqtt-client/minimal-mqtt-client-multi/README.md 1970-01-01 00:00:00.000000000 +0000 +++ libwebsockets-4.1.6/minimal-examples/mqtt-client/minimal-mqtt-client-multi/README.md 2020-12-01 17:40:26.000000000 +0000 @@ -0,0 +1,24 @@ +# lws minimal MQTT client multi + +## build + +``` + $ cmake . && make +``` + +## usage + +The application goes to https://warmcat.com and receives the page data +same as minimal http client. + +However it does it for 8 client connections concurrently. + +## Commandline Options + +Option|Meaning +---|--- +-c |Count of simultaneous connections (default 8) +-s|Stagger the connections by 100ms, the last by 1s +-p|Use stream binding + + diff -Nru libwebsockets-3.2.1/minimal-examples/mqtt-client/minimal-mqtt-client-multi/selftest.sh.broken-on-travis libwebsockets-4.1.6/minimal-examples/mqtt-client/minimal-mqtt-client-multi/selftest.sh.broken-on-travis --- libwebsockets-3.2.1/minimal-examples/mqtt-client/minimal-mqtt-client-multi/selftest.sh.broken-on-travis 1970-01-01 00:00:00.000000000 +0000 +++ libwebsockets-4.1.6/minimal-examples/mqtt-client/minimal-mqtt-client-multi/selftest.sh.broken-on-travis 2020-12-01 17:40:26.000000000 +0000 @@ -0,0 +1,32 @@ +#!/bin/bash +# +# $1: path to minimal example binaries... +# if lws is built with -DLWS_WITH_MINIMAL_EXAMPLES=1 +# that will be ./bin from your build dir +# +# $2: path for logs and results. The results will go +# in a subdir named after the directory this script +# is in +# +# $3: offset for test index count +# +# $4: total test count +# +# $5: path to ./minimal-examples dir in lws +# +# Test return code 0: OK, 254: timed out, other: error indication + +. $5/selftests-library.sh + +COUNT_TESTS=1 + +#dotest $1 $2 warmcat + +Q=`which mosquitto` +spawn "" /tmp $Q -v +dotest $1 $2 -p-i100000 -p -i 100000 + +kill $SPID 2>/dev/null +wait $SPID 2>/dev/null +exit $FAILS + diff -Nru libwebsockets-3.2.1/minimal-examples/mqtt-client/minimal-mqtt-client-multi/warmcat.com.cer libwebsockets-4.1.6/minimal-examples/mqtt-client/minimal-mqtt-client-multi/warmcat.com.cer --- libwebsockets-3.2.1/minimal-examples/mqtt-client/minimal-mqtt-client-multi/warmcat.com.cer 1970-01-01 00:00:00.000000000 +0000 +++ libwebsockets-4.1.6/minimal-examples/mqtt-client/minimal-mqtt-client-multi/warmcat.com.cer 2020-12-01 17:40:26.000000000 +0000 @@ -0,0 +1,78 @@ +-----BEGIN CERTIFICATE----- +MIIFUDCCBDigAwIBAgISA4mJfIm3iCGbU9+o8YQa+4nUMA0GCSqGSIb3DQEBCwUA +MEoxCzAJBgNVBAYTAlVTMRYwFAYDVQQKEw1MZXQncyBFbmNyeXB0MSMwIQYDVQQD +ExpMZXQncyBFbmNyeXB0IEF1dGhvcml0eSBYMzAeFw0xOTA5MDcwNzA5MjNaFw0x +OTEyMDYwNzA5MjNaMBYxFDASBgNVBAMTC3dhcm1jYXQuY29tMIIBIjANBgkqhkiG +9w0BAQEFAAOCAQ8AMIIBCgKCAQEAwnEoH9JW3GvpadpxHGZPb5wv1Q6KfAIMWtdq +YCOfotFxaYULuzHVxmrTTgmEqJr+eBqUBkXKmGuRR/9UipOmTu5j02qFyWHotFdF +ZGyp//8z+Rle9Qt1nL68oNIZLDtWkybh5x00b1uo4eyEszXUaa0aLqKP3lH7Q4jI +aSVARZ8snrJR640Gp3ByudvNTYkGz469bpWzRC/8wSNtzzY02DvHs1GxQx9tMXw+ +BbtUxeP7lpYFKEFBjgZaIKLv+4g8ItJIuO7gMSzG2JfpQHxdhrlhxpx7dsaMUcyM +nnYXysNL5JG3KEMhkxbtdpCaEQ8jLSPbl/rnF/+mgce+lSjMuQIDAQABo4ICYjCC +Al4wDgYDVR0PAQH/BAQDAgWgMB0GA1UdJQQWMBQGCCsGAQUFBwMBBggrBgEFBQcD +AjAMBgNVHRMBAf8EAjAAMB0GA1UdDgQWBBSI9ai12zLFeNTEDHKI9Ghkqcpa2TAf +BgNVHSMEGDAWgBSoSmpjBH3duubRObemRWXv86jsoTBvBggrBgEFBQcBAQRjMGEw +LgYIKwYBBQUHMAGGImh0dHA6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UFw +7BZy1SbsOFU5Q9D8/RhcQPGX69Wam40dutolucbY38EVAjqr2m7xPi71XAicPNaD +aeQQmxkqtilX4+U9m5/wAl0CAwEAAaNCMEAwDwYDVR0TAQH/BAUwAwEB/zAOBgNV +HQ8BAf8EBAMCAQYwHQYDVR0OBBYEFMSnsaR7LHH62+FLkHX/xBVghYkQMA0GCSqG +SIb3DQEBBQUAA4IBAQCjGiybFwBcqR7uKGY3Or+Dxz9LwwmglSBd49lZRNI+DT69 +ikugdB/OEIKcdBodfpga3csTS7MgROSR6cz8faXbauX+5v3gTt23ADq1cEmv8uXr +AvHRAosZy5Q6XkjEGB5YGV8eAlrwDPGxrancWYaLbumR9YbK+rlmM6pZW87ipxZz +R8srzJmwN0jP41ZL9c8PDHIyh8bwRLtTcm1D9SZImlJnt1ir/md2cXjbDaJWFBM5 +JDGFoqgCWjBH4d1QB7wCCZAA62RjYJsWvIjJEubSfZGL+T0yjWW06XyxV3bqxbYo +Ob8VZRzI9neWagqNdwvYkQsEjgfbKbYK7p2CNTUQ +-----END CERTIFICATE----- diff -Nru libwebsockets-3.2.1/minimal-examples/mqtt-client/minimal-mqtt-client-multi/wget-log libwebsockets-4.1.6/minimal-examples/mqtt-client/minimal-mqtt-client-multi/wget-log --- libwebsockets-3.2.1/minimal-examples/mqtt-client/minimal-mqtt-client-multi/wget-log 1970-01-01 00:00:00.000000000 +0000 +++ libwebsockets-4.1.6/minimal-examples/mqtt-client/minimal-mqtt-client-multi/wget-log 2020-12-01 17:40:26.000000000 +0000 @@ -0,0 +1,11 @@ +--2018-11-25 07:54:30-- https://www.gravatar.com/avatar/c50933ca2aa61e0fe2c43d46bb6b59cb/?s=128 +Resolving www.gravatar.com (www.gravatar.com)... 192.0.73.2, 2a04:fa87:fffe::c000:4902 +Connecting to www.gravatar.com (www.gravatar.com)|192.0.73.2|:443... connected. +HTTP request sent, awaiting response... 200 OK +Length: 24761 (24K) [image/png] +Saving to: ‘/tmp/q’ + + /tmp/q 0%[ ] 0 --.-KB/s /tmp/q 100%[================================>] 24.18K --.-KB/s in 0.01s + +2018-11-25 07:54:31 (2.04 MB/s) - ‘/tmp/q’ saved [24761/24761] + diff -Nru libwebsockets-3.2.1/minimal-examples/mqtt-client/README.md libwebsockets-4.1.6/minimal-examples/mqtt-client/README.md --- libwebsockets-3.2.1/minimal-examples/mqtt-client/README.md 1970-01-01 00:00:00.000000000 +0000 +++ libwebsockets-4.1.6/minimal-examples/mqtt-client/README.md 2020-12-01 17:40:26.000000000 +0000 @@ -0,0 +1,4 @@ +|name|demonstrates| +---|--- +minimal-mqtt-client|Simple demo for mqtt client operation +minimal-mqtt-client-multi|Demonstrates automatic binding / muxing of independent connections to share a single tcp / tls connection diff -Nru libwebsockets-3.2.1/minimal-examples/raw/minimal-raw-adopt-tcp/CMakeLists.txt libwebsockets-4.1.6/minimal-examples/raw/minimal-raw-adopt-tcp/CMakeLists.txt --- libwebsockets-3.2.1/minimal-examples/raw/minimal-raw-adopt-tcp/CMakeLists.txt 2019-12-18 14:45:31.000000000 +0000 +++ libwebsockets-4.1.6/minimal-examples/raw/minimal-raw-adopt-tcp/CMakeLists.txt 2020-12-01 17:40:26.000000000 +0000 @@ -1,76 +1,23 @@ +project(lws-minimal-raw-adopt-tcp C) cmake_minimum_required(VERSION 2.8) +find_package(libwebsockets CONFIG REQUIRED) +list(APPEND CMAKE_MODULE_PATH ${LWS_CMAKE_DIR}) include(CheckCSourceCompiles) +include(LwsCheckRequirements) set(SAMP lws-minimal-raw-adopt-tcp) set(SRCS minimal-raw-adopt-tcp.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_WITH_SERVER 1 requirements) if (requirements) add_executable(${SAMP} ${SRCS}) if (websockets_shared) - target_link_libraries(${SAMP} websockets_shared) + target_link_libraries(${SAMP} websockets_shared ${LIBWEBSOCKETS_DEP_LIBS}) add_dependencies(${SAMP} websockets_shared) else() - target_link_libraries(${SAMP} websockets) + target_link_libraries(${SAMP} websockets ${LIBWEBSOCKETS_DEP_LIBS}) endif() endif() diff -Nru libwebsockets-3.2.1/minimal-examples/raw/minimal-raw-adopt-tcp/minimal-raw-adopt-tcp.c libwebsockets-4.1.6/minimal-examples/raw/minimal-raw-adopt-tcp/minimal-raw-adopt-tcp.c --- libwebsockets-3.2.1/minimal-examples/raw/minimal-raw-adopt-tcp/minimal-raw-adopt-tcp.c 2019-12-18 14:45:31.000000000 +0000 +++ libwebsockets-4.1.6/minimal-examples/raw/minimal-raw-adopt-tcp/minimal-raw-adopt-tcp.c 2020-12-01 17:40:26.000000000 +0000 @@ -31,7 +31,9 @@ #include #include #include +#if !defined(WIN32) #include +#endif #include static int diff -Nru libwebsockets-3.2.1/minimal-examples/raw/minimal-raw-adopt-udp/CMakeLists.txt libwebsockets-4.1.6/minimal-examples/raw/minimal-raw-adopt-udp/CMakeLists.txt --- libwebsockets-3.2.1/minimal-examples/raw/minimal-raw-adopt-udp/CMakeLists.txt 2019-12-18 14:45:31.000000000 +0000 +++ libwebsockets-4.1.6/minimal-examples/raw/minimal-raw-adopt-udp/CMakeLists.txt 2020-12-01 17:40:26.000000000 +0000 @@ -1,76 +1,26 @@ +project(lws-minimal-raw-adopt-udp C) cmake_minimum_required(VERSION 2.8) +find_package(libwebsockets CONFIG REQUIRED) +list(APPEND CMAKE_MODULE_PATH ${LWS_CMAKE_DIR}) include(CheckCSourceCompiles) +include(LwsCheckRequirements) set(SAMP lws-minimal-raw-adopt-udp) set(SRCS minimal-raw-adopt-udp.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_WITH_SERVER 1 requirements) +require_lws_config(LWS_WITH_CLIENT 1 requirements) +require_lws_config(LWS_WITH_UDP 1 requirements) + if (requirements) add_executable(${SAMP} ${SRCS}) if (websockets_shared) - target_link_libraries(${SAMP} websockets_shared) + target_link_libraries(${SAMP} websockets_shared ${LIBWEBSOCKETS_DEP_LIBS}) add_dependencies(${SAMP} websockets_shared) else() - target_link_libraries(${SAMP} websockets) + target_link_libraries(${SAMP} websockets ${LIBWEBSOCKETS_DEP_LIBS}) endif() endif() diff -Nru libwebsockets-3.2.1/minimal-examples/raw/minimal-raw-adopt-udp/minimal-raw-adopt-udp.c libwebsockets-4.1.6/minimal-examples/raw/minimal-raw-adopt-udp/minimal-raw-adopt-udp.c --- libwebsockets-3.2.1/minimal-examples/raw/minimal-raw-adopt-udp/minimal-raw-adopt-udp.c 2019-12-18 14:45:31.000000000 +0000 +++ libwebsockets-4.1.6/minimal-examples/raw/minimal-raw-adopt-udp/minimal-raw-adopt-udp.c 2020-12-01 17:40:26.000000000 +0000 @@ -28,7 +28,9 @@ #include #include #include +#if !defined(WIN32) #include +#endif #include static uint8_t sendbuf[4096]; @@ -40,7 +42,7 @@ void *user, void *in, size_t len) { ssize_t n; - int fd; + lws_sockfd_type fd; switch (reason) { @@ -84,8 +86,13 @@ break; fd = lws_get_socket_fd(wsi); +#if defined(WIN32) + if ((int)fd < 0) + break; +#else if (fd < 0) /* keep Coverity happy: actually it cannot be < 0 */ break; +#endif /* * We can write directly on the UDP socket, specifying @@ -102,7 +109,11 @@ #if defined(WIN32) (const char *) #endif - sendbuf, sendlen, 0, &udp.sa, udp.salen); + sendbuf, +#if defined(WIN32) + (int) +#endif + sendlen, 0, &udp.sa, (socklen_t)udp.salen); if (n < (ssize_t)len) lwsl_notice("%s: send returned %d\n", __func__, (int)n); break; @@ -169,8 +180,8 @@ /* * Create our own "foreign" UDP socket bound to 7681/udp */ - if (!lws_create_adopt_udp(vhost, 7681, LWS_CAUDP_BIND, - protocols[0].name, NULL)) { + if (!lws_create_adopt_udp(vhost, NULL, 7681, LWS_CAUDP_BIND, + protocols[0].name, NULL, NULL, NULL, NULL)) { lwsl_err("%s: foreign socket adoption failed\n", __func__); goto bail; } diff -Nru libwebsockets-3.2.1/minimal-examples/raw/minimal-raw-audio/audio.c libwebsockets-4.1.6/minimal-examples/raw/minimal-raw-audio/audio.c --- libwebsockets-3.2.1/minimal-examples/raw/minimal-raw-audio/audio.c 1970-01-01 00:00:00.000000000 +0000 +++ libwebsockets-4.1.6/minimal-examples/raw/minimal-raw-audio/audio.c 2020-12-01 17:40:26.000000000 +0000 @@ -0,0 +1,211 @@ +/* + * lws-minimal-raw-audio + * + * Written in 2010-2019 by Andy Green + * + * This file is made available under the Creative Commons CC0 1.0 + * Universal Public Domain Dedication. + * + * This demonstrates adopting and managing audio device file descriptors in the + * event loop. + */ + +#include +#include +#include +#include +#include +#include + +#include + +static unsigned int sample_rate = 16000; + +struct raw_vhd { + uint8_t simplebuf[32768 * 2]; + snd_pcm_t *pcm_capture; + snd_pcm_t *pcm_playback; + snd_pcm_hw_params_t *params; + snd_pcm_uframes_t frames; + int filefd; + int rpos; + int wpos; + int times; +}; + +static int +set_hw_params(struct lws_vhost *vh, snd_pcm_t **pcm, int type) +{ + unsigned int rate = sample_rate; + snd_pcm_hw_params_t *params; + lws_sock_file_fd_type u; + struct pollfd pfd; + struct lws *wsi1; + int n; + + n = snd_pcm_open(pcm, "default", type, SND_PCM_NONBLOCK); + if (n < 0) { + lwsl_err("%s: Can't open default for playback: %s\n", + __func__, snd_strerror(n)); + + return -1; + } + + if (snd_pcm_poll_descriptors(*pcm, &pfd, 1) != 1) { + lwsl_err("%s: failed to get playback desc\n", __func__); + return -1; + } + + u.filefd = (lws_filefd_type)(long long)pfd.fd; + wsi1 = lws_adopt_descriptor_vhost(vh, LWS_ADOPT_RAW_FILE_DESC, u, + "lws-audio-test", NULL); + if (!wsi1) { + lwsl_err("%s: Failed to adopt playback desc\n", __func__); + goto bail; + } + if (type == SND_PCM_STREAM_PLAYBACK) + lws_rx_flow_control(wsi1, 0); /* no POLLIN */ + + snd_pcm_hw_params_malloc(¶ms); + snd_pcm_hw_params_any(*pcm, params); + + n = snd_pcm_hw_params_set_access(*pcm, params, + SND_PCM_ACCESS_RW_INTERLEAVED); + if (n < 0) + goto bail1; + + n = snd_pcm_hw_params_set_format(*pcm, params, SND_PCM_FORMAT_S16_LE); + if (n < 0) + goto bail1; + + n = snd_pcm_hw_params_set_channels(*pcm, params, 1); + if (n < 0) + goto bail1; + + n = snd_pcm_hw_params_set_rate_near(*pcm, params, &rate, 0); + if (n < 0) + goto bail1; + + n = snd_pcm_hw_params(*pcm, params); + snd_pcm_hw_params_free(params); + if (n < 0) + goto bail; + + return 0; + +bail1: + snd_pcm_hw_params_free(params); +bail: + lwsl_err("%s: Set hw params failed: %s\n", __func__, snd_strerror(n)); + + return -1; +} + +static int +callback_raw_test(struct lws *wsi, enum lws_callback_reasons reason, + void *user, void *in, size_t len) +{ + struct raw_vhd *vhd = (struct raw_vhd *)lws_protocol_vh_priv_get( + lws_get_vhost(wsi), lws_get_protocol(wsi)); + int n; + + switch (reason) { + case LWS_CALLBACK_PROTOCOL_INIT: + vhd = lws_protocol_vh_priv_zalloc(lws_get_vhost(wsi), + lws_get_protocol(wsi), sizeof(struct raw_vhd)); + + if (set_hw_params(lws_get_vhost(wsi), &vhd->pcm_playback, + SND_PCM_STREAM_PLAYBACK)) { + lwsl_err("%s: Can't open default for playback\n", + __func__); + + return -1; + } + + if (set_hw_params(lws_get_vhost(wsi), &vhd->pcm_capture, + SND_PCM_STREAM_CAPTURE)) { + lwsl_err("%s: Can't open default for capture\n", + __func__); + + return -1; + } + break; + + case LWS_CALLBACK_PROTOCOL_DESTROY: + lwsl_notice("LWS_CALLBACK_PROTOCOL_DESTROY\n"); + if (vhd && vhd->pcm_playback) { + snd_pcm_drain(vhd->pcm_playback); + snd_pcm_close(vhd->pcm_playback); + vhd->pcm_playback = NULL; + } + if (vhd && vhd->pcm_capture) { + snd_pcm_close(vhd->pcm_capture); + vhd->pcm_capture = NULL; + } + break; + + case LWS_CALLBACK_RAW_RX_FILE: + if (vhd->times >= 6) { /* delay amount decided by this */ + n = snd_pcm_writei(vhd->pcm_playback, + &vhd->simplebuf[vhd->rpos], + ((vhd->wpos - vhd->rpos) & + (sizeof(vhd->simplebuf) - 1)) / 2); + vhd->rpos = (vhd->rpos + (n * 2)) & + (sizeof(vhd->simplebuf) - 1); + } + + n = snd_pcm_readi(vhd->pcm_capture, &vhd->simplebuf[vhd->wpos], + (sizeof(vhd->simplebuf) - vhd->wpos) / 2); + lwsl_notice("LWS_CALLBACK_RAW_RX_FILE: %d samples\n", n); + vhd->times++; + + vhd->wpos = (vhd->wpos + (n * 2)) & (sizeof(vhd->simplebuf) - 1); + break; + + default: + break; + } + + return 0; +} + +static struct lws_protocols protocols[] = { + { "lws-audio-test", callback_raw_test, 0, 0 }, + { NULL, NULL, 0, 0 } /* terminator */ +}; + +static int interrupted; + +void sigint_handler(int sig) +{ + interrupted = 1; +} + +int main(int argc, const char **argv) +{ + struct lws_context_creation_info info; + struct lws_context *context; + int n = 0; + + signal(SIGINT, sigint_handler); + memset(&info, 0, sizeof info); + lws_cmdline_option_handle_builtin(argc, argv, &info); + + lwsl_user("LWS minimal raw audio\n"); + + info.port = CONTEXT_PORT_NO_LISTEN_SERVER; + info.protocols = protocols; + + context = lws_create_context(&info); + if (!context) { + lwsl_err("lws init failed\n"); + return 1; + } + + while (n >= 0 && !interrupted) + n = lws_service(context, 0); + + lws_context_destroy(context); + + return 0; +} diff -Nru libwebsockets-3.2.1/minimal-examples/raw/minimal-raw-audio/CMakeLists.txt libwebsockets-4.1.6/minimal-examples/raw/minimal-raw-audio/CMakeLists.txt --- libwebsockets-3.2.1/minimal-examples/raw/minimal-raw-audio/CMakeLists.txt 1970-01-01 00:00:00.000000000 +0000 +++ libwebsockets-4.1.6/minimal-examples/raw/minimal-raw-audio/CMakeLists.txt 2020-12-01 17:40:26.000000000 +0000 @@ -0,0 +1,24 @@ +project(lws-minimal-raw-audio C) +cmake_minimum_required(VERSION 2.8) +find_package(libwebsockets CONFIG REQUIRED) +list(APPEND CMAKE_MODULE_PATH ${LWS_CMAKE_DIR}) +include(CheckCSourceCompiles) +include(LwsCheckRequirements) + +set(SAMP lws-minimal-raw-audio) +set(SRCS audio.c) + +set(requirements 1) +require_lws_config(LWS_WITH_ALSA 1 requirements) +require_lws_config(LWS_WITH_NETWORK 1 requirements) + +if (requirements) + add_executable(${SAMP} ${SRCS}) + + if (websockets_shared) + target_link_libraries(${SAMP} websockets_shared asound ${LIBWEBSOCKETS_DEP_LIBS}) + add_dependencies(${SAMP} websockets_shared) + else() + target_link_libraries(${SAMP} websockets asound ${LIBWEBSOCKETS_DEP_LIBS}) + endif() +endif() diff -Nru libwebsockets-3.2.1/minimal-examples/raw/minimal-raw-audio/README.md libwebsockets-4.1.6/minimal-examples/raw/minimal-raw-audio/README.md --- libwebsockets-3.2.1/minimal-examples/raw/minimal-raw-audio/README.md 1970-01-01 00:00:00.000000000 +0000 +++ libwebsockets-4.1.6/minimal-examples/raw/minimal-raw-audio/README.md 2020-12-01 17:40:26.000000000 +0000 @@ -0,0 +1,37 @@ +# lws minimal raw audio + +This demonstrates operating ALSA playback and capture using the lws event loop +via raw file descriptors. + +You need the lws cmake option `-DLWS_WITH_ALSA=1` + +This example opens the default ALSA playback and capture devices and pipes the +capture data into the playback with something over 1s delay via a ringbuffer. + +ALSA doesn't really lend itself to direct use with event loops... this example +uses the capture channel which does create POLLIN normally as the timesource +for the playback as well; they're both set to 16000Hz sample rate. + +## build + +``` + $ cmake . && make +``` + +## usage + +``` + $ ./lws-minimal-raw-audio +[2019/10/14 18:58:49:3288] U: LWS minimal raw audio +[2019/10/14 18:58:50:3438] N: LWS_CALLBACK_RAW_ADOPT_FILE +[2019/10/14 18:58:50:3455] N: LWS_CALLBACK_RAW_ADOPT_FILE +[2019/10/14 18:58:50:4764] N: LWS_CALLBACK_RAW_RX_FILE: 2062 samples +[2019/10/14 18:58:50:6132] N: LWS_CALLBACK_RAW_RX_FILE: 2205 samples +[2019/10/14 18:58:50:7592] N: LWS_CALLBACK_RAW_RX_FILE: 2328 samples +... +^C[2019/10/14 18:58:56:8460] N: LWS_CALLBACK_RAW_CLOSE_FILE +[2019/10/14 18:58:56:8461] N: LWS_CALLBACK_RAW_CLOSE_FILE +[2019/10/14 18:58:56:8461] N: LWS_CALLBACK_PROTOCOL_DESTROY +$ + +``` diff -Nru libwebsockets-3.2.1/minimal-examples/raw/minimal-raw-fallback-http-server/CMakeLists.txt libwebsockets-4.1.6/minimal-examples/raw/minimal-raw-fallback-http-server/CMakeLists.txt --- libwebsockets-3.2.1/minimal-examples/raw/minimal-raw-fallback-http-server/CMakeLists.txt 2019-12-18 14:45:31.000000000 +0000 +++ libwebsockets-4.1.6/minimal-examples/raw/minimal-raw-fallback-http-server/CMakeLists.txt 2020-12-01 17:40:26.000000000 +0000 @@ -1,79 +1,24 @@ +project(lws-minimal-raw-fallback-http-server C) cmake_minimum_required(VERSION 2.8) +find_package(libwebsockets CONFIG REQUIRED) +list(APPEND CMAKE_MODULE_PATH ${LWS_CMAKE_DIR}) include(CheckCSourceCompiles) +include(LwsCheckRequirements) set(SAMP lws-minimal-raw-fallback-http-server) set(SRCS minimal-raw-fallback-http-server.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_ROLE_H1 1 requirements) -require_lws_config(LWS_WITHOUT_SERVER 0 requirements) +require_lws_config(LWS_WITH_SERVER 1 requirements) if (requirements) add_executable(${SAMP} ${SRCS}) if (websockets_shared) - target_link_libraries(${SAMP} websockets_shared) + target_link_libraries(${SAMP} websockets_shared ${LIBWEBSOCKETS_DEP_LIBS}) add_dependencies(${SAMP} websockets_shared) else() - target_link_libraries(${SAMP} websockets) + target_link_libraries(${SAMP} websockets ${LIBWEBSOCKETS_DEP_LIBS}) endif() endif() diff -Nru libwebsockets-3.2.1/minimal-examples/raw/minimal-raw-fallback-http-server/minimal-raw-fallback-http-server.c libwebsockets-4.1.6/minimal-examples/raw/minimal-raw-fallback-http-server/minimal-raw-fallback-http-server.c --- libwebsockets-3.2.1/minimal-examples/raw/minimal-raw-fallback-http-server/minimal-raw-fallback-http-server.c 2019-12-18 14:45:31.000000000 +0000 +++ libwebsockets-4.1.6/minimal-examples/raw/minimal-raw-fallback-http-server/minimal-raw-fallback-http-server.c 2020-12-01 17:40:26.000000000 +0000 @@ -63,7 +63,7 @@ if (len > sizeof(pss->buf)) len = sizeof(pss->buf); memcpy(pss->buf, in, len); - pss->len = len; + pss->len = (int)len; lws_callback_on_writable(wsi); break; @@ -119,6 +119,7 @@ info.listen_accept_role = "raw-skt"; info.listen_accept_protocol = "raw-echo"; +#if defined(LWS_WITH_TLS) if (lws_cmdline_option(argc, argv, "-s")) { info.options |= LWS_SERVER_OPTION_DO_SSL_GLOBAL_INIT | LWS_SERVER_OPTION_ALLOW_NON_SSL_ON_SSL_PORT; @@ -131,6 +132,7 @@ if (lws_cmdline_option(argc, argv, "-h")) info.options |= LWS_SERVER_OPTION_ALLOW_HTTP_ON_HTTPS_LISTENER; } +#endif context = lws_create_context(&info); if (!context) { diff -Nru libwebsockets-3.2.1/minimal-examples/raw/minimal-raw-fallback-http-server/mount-origin/libwebsockets.org-logo.svg libwebsockets-4.1.6/minimal-examples/raw/minimal-raw-fallback-http-server/mount-origin/libwebsockets.org-logo.svg --- libwebsockets-3.2.1/minimal-examples/raw/minimal-raw-fallback-http-server/mount-origin/libwebsockets.org-logo.svg 2019-12-18 14:45:31.000000000 +0000 +++ libwebsockets-4.1.6/minimal-examples/raw/minimal-raw-fallback-http-server/mount-origin/libwebsockets.org-logo.svg 2020-12-01 17:40:26.000000000 +0000 @@ -1,120 +1,66 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + + +image/svg+xml + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff -Nru libwebsockets-3.2.1/minimal-examples/raw/minimal-raw-file/CMakeLists.txt libwebsockets-4.1.6/minimal-examples/raw/minimal-raw-file/CMakeLists.txt --- libwebsockets-3.2.1/minimal-examples/raw/minimal-raw-file/CMakeLists.txt 2019-12-18 14:45:31.000000000 +0000 +++ libwebsockets-4.1.6/minimal-examples/raw/minimal-raw-file/CMakeLists.txt 2020-12-01 17:40:26.000000000 +0000 @@ -1,77 +1,23 @@ +project(lws-minimal-raw-file C) cmake_minimum_required(VERSION 2.8) +find_package(libwebsockets CONFIG REQUIRED) +list(APPEND CMAKE_MODULE_PATH ${LWS_CMAKE_DIR}) include(CheckCSourceCompiles) +include(LwsCheckRequirements) set(SAMP lws-minimal-raw-file) set(SRCS minimal-raw-file.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_WITH_SERVER 1 requirements) if (requirements) add_executable(${SAMP} ${SRCS}) if (websockets_shared) - target_link_libraries(${SAMP} websockets_shared) + target_link_libraries(${SAMP} websockets_shared ${LIBWEBSOCKETS_DEP_LIBS}) add_dependencies(${SAMP} websockets_shared) else() - target_link_libraries(${SAMP} websockets) + target_link_libraries(${SAMP} websockets ${LIBWEBSOCKETS_DEP_LIBS}) endif() endif() \ No newline at end of file diff -Nru libwebsockets-3.2.1/minimal-examples/raw/minimal-raw-netcat/CMakeLists.txt libwebsockets-4.1.6/minimal-examples/raw/minimal-raw-netcat/CMakeLists.txt --- libwebsockets-3.2.1/minimal-examples/raw/minimal-raw-netcat/CMakeLists.txt 2019-12-18 14:45:31.000000000 +0000 +++ libwebsockets-4.1.6/minimal-examples/raw/minimal-raw-netcat/CMakeLists.txt 2020-12-01 17:40:26.000000000 +0000 @@ -1,76 +1,23 @@ +project(lws-minimal-raw-netcat C) cmake_minimum_required(VERSION 2.8) +find_package(libwebsockets CONFIG REQUIRED) +list(APPEND CMAKE_MODULE_PATH ${LWS_CMAKE_DIR}) include(CheckCSourceCompiles) +include(LwsCheckRequirements) set(SAMP lws-minimal-raw-netcat) set(SRCS minimal-raw-netcat.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_WITH_SERVER 1 requirements) if (requirements) add_executable(${SAMP} ${SRCS}) if (websockets_shared) - target_link_libraries(${SAMP} websockets_shared) + target_link_libraries(${SAMP} websockets_shared ${LIBWEBSOCKETS_DEP_LIBS}) add_dependencies(${SAMP} websockets_shared) else() - target_link_libraries(${SAMP} websockets) + target_link_libraries(${SAMP} websockets ${LIBWEBSOCKETS_DEP_LIBS}) endif() endif() diff -Nru libwebsockets-3.2.1/minimal-examples/raw/minimal-raw-netcat/minimal-raw-netcat.c libwebsockets-4.1.6/minimal-examples/raw/minimal-raw-netcat/minimal-raw-netcat.c --- libwebsockets-3.2.1/minimal-examples/raw/minimal-raw-netcat/minimal-raw-netcat.c 2019-12-18 14:45:31.000000000 +0000 +++ libwebsockets-4.1.6/minimal-examples/raw/minimal-raw-netcat/minimal-raw-netcat.c 2020-12-01 17:40:26.000000000 +0000 @@ -26,7 +26,9 @@ #include #include #include +#if !defined(WIN32) #include +#endif #include static struct lws *raw_wsi, *stdin_wsi; diff -Nru libwebsockets-3.2.1/minimal-examples/raw/minimal-raw-proxy/CMakeLists.txt libwebsockets-4.1.6/minimal-examples/raw/minimal-raw-proxy/CMakeLists.txt --- libwebsockets-3.2.1/minimal-examples/raw/minimal-raw-proxy/CMakeLists.txt 2019-12-18 14:45:31.000000000 +0000 +++ libwebsockets-4.1.6/minimal-examples/raw/minimal-raw-proxy/CMakeLists.txt 2020-12-01 17:40:26.000000000 +0000 @@ -1,5 +1,9 @@ +project(lws-minimal-raw-proxy C) cmake_minimum_required(VERSION 2.8) +find_package(libwebsockets CONFIG REQUIRED) +list(APPEND CMAKE_MODULE_PATH ${LWS_CMAKE_DIR}) include(CheckCSourceCompiles) +include(LwsCheckRequirements) set(SAMP lws-minimal-raw-proxy) set(SRCS minimal-raw-proxy.c) @@ -8,63 +12,6 @@ # to the lws plugins dir so it can pick up the plugin source. Eg, # cmake . -DLWS_PLUGINS_DIR=~/libwebsockets/plugins -# 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_ROLE_RAW_PROXY 1 requirements) @@ -76,9 +23,9 @@ endif() if (websockets_shared) - target_link_libraries(${SAMP} websockets_shared) + target_link_libraries(${SAMP} websockets_shared ${LIBWEBSOCKETS_DEP_LIBS}) add_dependencies(${SAMP} websockets_shared) else() - target_link_libraries(${SAMP} websockets) + target_link_libraries(${SAMP} websockets ${LIBWEBSOCKETS_DEP_LIBS}) endif() endif() diff -Nru libwebsockets-3.2.1/minimal-examples/raw/minimal-raw-proxy-fallback/CMakeLists.txt libwebsockets-4.1.6/minimal-examples/raw/minimal-raw-proxy-fallback/CMakeLists.txt --- libwebsockets-3.2.1/minimal-examples/raw/minimal-raw-proxy-fallback/CMakeLists.txt 2019-12-18 14:45:31.000000000 +0000 +++ libwebsockets-4.1.6/minimal-examples/raw/minimal-raw-proxy-fallback/CMakeLists.txt 2020-12-01 17:40:26.000000000 +0000 @@ -1,5 +1,9 @@ +project(lws-minimal-raw-proxy-fallback C) cmake_minimum_required(VERSION 2.8) +find_package(libwebsockets CONFIG REQUIRED) +list(APPEND CMAKE_MODULE_PATH ${LWS_CMAKE_DIR}) include(CheckCSourceCompiles) +include(LwsCheckRequirements) set(SAMP lws-minimal-raw-proxy-fallback) set(SRCS minimal-raw-proxy-fallback.c) @@ -8,63 +12,6 @@ # to the lws plugins dir so it can pick up the plugin source. Eg, # cmake . -DLWS_PLUGINS_DIR=~/libwebsockets/plugins -# 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_ROLE_RAW_PROXY 1 requirements) @@ -76,9 +23,9 @@ endif() if (websockets_shared) - target_link_libraries(${SAMP} websockets_shared) + target_link_libraries(${SAMP} websockets_shared ${LIBWEBSOCKETS_DEP_LIBS}) add_dependencies(${SAMP} websockets_shared) else() - target_link_libraries(${SAMP} websockets) + target_link_libraries(${SAMP} websockets ${LIBWEBSOCKETS_DEP_LIBS}) endif() endif() diff -Nru libwebsockets-3.2.1/minimal-examples/raw/minimal-raw-proxy-fallback/minimal-raw-proxy-fallback.c libwebsockets-4.1.6/minimal-examples/raw/minimal-raw-proxy-fallback/minimal-raw-proxy-fallback.c --- libwebsockets-3.2.1/minimal-examples/raw/minimal-raw-proxy-fallback/minimal-raw-proxy-fallback.c 2019-12-18 14:45:31.000000000 +0000 +++ libwebsockets-4.1.6/minimal-examples/raw/minimal-raw-proxy-fallback/minimal-raw-proxy-fallback.c 2020-12-01 17:40:26.000000000 +0000 @@ -106,6 +106,7 @@ info.listen_accept_role = "raw-proxy"; info.listen_accept_protocol = "raw-proxy"; +#if defined(LWS_WITH_TLS) if (lws_cmdline_option(argc, argv, "-s")) { info.options |= LWS_SERVER_OPTION_DO_SSL_GLOBAL_INIT | LWS_SERVER_OPTION_ALLOW_NON_SSL_ON_SSL_PORT; @@ -118,6 +119,7 @@ if (lws_cmdline_option(argc, argv, "-h")) info.options |= LWS_SERVER_OPTION_ALLOW_HTTP_ON_HTTPS_LISTENER; } +#endif context = lws_create_context(&info); if (!context) { diff -Nru libwebsockets-3.2.1/minimal-examples/raw/minimal-raw-proxy-fallback/mount-origin/libwebsockets.org-logo.svg libwebsockets-4.1.6/minimal-examples/raw/minimal-raw-proxy-fallback/mount-origin/libwebsockets.org-logo.svg --- libwebsockets-3.2.1/minimal-examples/raw/minimal-raw-proxy-fallback/mount-origin/libwebsockets.org-logo.svg 2019-12-18 14:45:31.000000000 +0000 +++ libwebsockets-4.1.6/minimal-examples/raw/minimal-raw-proxy-fallback/mount-origin/libwebsockets.org-logo.svg 2020-12-01 17:40:26.000000000 +0000 @@ -1,120 +1,66 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + + +image/svg+xml + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff -Nru libwebsockets-3.2.1/minimal-examples/raw/minimal-raw-serial/CMakeLists.txt libwebsockets-4.1.6/minimal-examples/raw/minimal-raw-serial/CMakeLists.txt --- libwebsockets-3.2.1/minimal-examples/raw/minimal-raw-serial/CMakeLists.txt 1970-01-01 00:00:00.000000000 +0000 +++ libwebsockets-4.1.6/minimal-examples/raw/minimal-raw-serial/CMakeLists.txt 2020-12-01 17:40:26.000000000 +0000 @@ -0,0 +1,23 @@ +project(lws-minimal-raw-serial C) +cmake_minimum_required(VERSION 2.8) +find_package(libwebsockets CONFIG REQUIRED) +list(APPEND CMAKE_MODULE_PATH ${LWS_CMAKE_DIR}) +include(CheckCSourceCompiles) +include(LwsCheckRequirements) + +set(SAMP lws-minimal-raw-serial) +set(SRCS minimal-raw-file.c) + +set(requirements 1) +require_lws_config(LWS_WITH_SERVER 1 requirements) + +if (requirements AND UNIX) + add_executable(${SAMP} ${SRCS}) + + if (websockets_shared) + target_link_libraries(${SAMP} websockets_shared ${LIBWEBSOCKETS_DEP_LIBS}) + add_dependencies(${SAMP} websockets_shared) + else() + target_link_libraries(${SAMP} websockets ${LIBWEBSOCKETS_DEP_LIBS}) + endif() +endif() diff -Nru libwebsockets-3.2.1/minimal-examples/raw/minimal-raw-serial/minimal-raw-file.c libwebsockets-4.1.6/minimal-examples/raw/minimal-raw-serial/minimal-raw-file.c --- libwebsockets-3.2.1/minimal-examples/raw/minimal-raw-serial/minimal-raw-file.c 1970-01-01 00:00:00.000000000 +0000 +++ libwebsockets-4.1.6/minimal-examples/raw/minimal-raw-serial/minimal-raw-file.c 2020-12-01 17:40:26.000000000 +0000 @@ -0,0 +1,231 @@ +/* + * lws-minimal-raw-file + * + * Written in 2010-2019 by Andy Green + * + * This file is made available under the Creative Commons CC0 1.0 + * Universal Public Domain Dedication. + * + * This demonstrates dealing with a serial port + */ + +#include +#include +#include +#include +#include +#include + +#include +#include + +#if defined(__linux__) +#include +#include +#endif + +struct raw_vhd { + lws_sorted_usec_list_t sul; + struct lws *wsi; + int filefd; +}; + +static char filepath[256]; + +static void +sul_cb(lws_sorted_usec_list_t *sul) +{ + struct raw_vhd *v = lws_container_of(sul, struct raw_vhd, sul); + + lws_callback_on_writable(v->wsi); + + lws_sul_schedule(lws_get_context(v->wsi), 0, &v->sul, sul_cb, + 2 * LWS_USEC_PER_SEC); +} + +static int +callback_raw_test(struct lws *wsi, enum lws_callback_reasons reason, + void *user, void *in, size_t len) +{ + struct raw_vhd *vhd = (struct raw_vhd *)lws_protocol_vh_priv_get( + lws_get_vhost(wsi), lws_get_protocol(wsi)); +#if defined(__linux__) + struct serial_struct s_s; +#endif + lws_sock_file_fd_type u; + struct termios tio; + uint8_t buf[1024]; + int n; + + switch (reason) { + case LWS_CALLBACK_PROTOCOL_INIT: + vhd = lws_protocol_vh_priv_zalloc(lws_get_vhost(wsi), + lws_get_protocol(wsi), sizeof(struct raw_vhd)); + vhd->filefd = lws_open(filepath, O_RDWR); + if (vhd->filefd == -1) { + lwsl_err("Unable to open %s\n", filepath); + + return 1; + } + + tcflush(vhd->filefd, TCIOFLUSH); + +#if defined(__linux__) + if (ioctl(vhd->filefd, TIOCGSERIAL, &s_s) == 0) { + s_s.closing_wait = ASYNC_CLOSING_WAIT_NONE; + ioctl(vhd->filefd, TIOCSSERIAL, &s_s); + } +#endif + + /* enforce suitable tty state */ + + memset(&tio, 0, sizeof tio); + if (tcgetattr(vhd->filefd, &tio)) { + close(vhd->filefd); + vhd->filefd = -1; + return -1; + } + + cfsetispeed(&tio, B115200); + cfsetospeed(&tio, B115200); + + tio.c_lflag &= ~(ISIG | ICANON | IEXTEN | ECHO | +#if defined(__linux__) + XCASE | +#endif + ECHOE | ECHOK | ECHONL | ECHOCTL | ECHOKE); + tio.c_iflag &= ~(INLCR | IGNBRK | IGNPAR | IGNCR | ICRNL | + IMAXBEL | IXON | IXOFF | IXANY +#if defined(__linux__) + | IUCLC +#endif + | 0xff); + tio.c_oflag = 0; + + tio.c_cc[VMIN] = 1; + tio.c_cc[VTIME] = 0; + tio.c_cc[VEOF] = 1; + tio.c_cflag &= ~( +#if defined(__linux__) + CBAUD | +#endif + CSIZE | CSTOPB | PARENB | CRTSCTS); + tio.c_cflag |= 0x1412 | CS8 | CREAD | CLOCAL; + + tcsetattr(vhd->filefd, TCSANOW, &tio); + + u.filefd = (lws_filefd_type)(long long)vhd->filefd; + if (!lws_adopt_descriptor_vhost(lws_get_vhost(wsi), + LWS_ADOPT_RAW_FILE_DESC, u, + "raw-test", NULL)) { + lwsl_err("Failed to adopt fifo descriptor\n"); + close(vhd->filefd); + vhd->filefd = -1; + + return 1; + } + + break; + + case LWS_CALLBACK_PROTOCOL_DESTROY: + if (vhd && vhd->filefd != -1) + close(vhd->filefd); + break; + + /* callbacks related to raw file descriptor */ + + case LWS_CALLBACK_RAW_ADOPT_FILE: + lwsl_notice("LWS_CALLBACK_RAW_ADOPT_FILE\n"); + vhd->wsi = wsi; + lws_sul_schedule(lws_get_context(wsi), 0, &vhd->sul, sul_cb, 1); + break; + + case LWS_CALLBACK_RAW_RX_FILE: + lwsl_notice("LWS_CALLBACK_RAW_RX_FILE\n"); + n = read(vhd->filefd, buf, sizeof(buf)); + if (n < 0) { + lwsl_err("Reading from %s failed\n", filepath); + + return 1; + } + lwsl_hexdump_level(LLL_NOTICE, buf, n); + break; + + case LWS_CALLBACK_RAW_CLOSE_FILE: + lwsl_notice("LWS_CALLBACK_RAW_CLOSE_FILE\n"); + lws_sul_cancel(&vhd->sul); + break; + + case LWS_CALLBACK_RAW_WRITEABLE_FILE: + lwsl_notice("LWS_CALLBACK_RAW_WRITEABLE_FILE\n"); + if (lws_write(wsi, (uint8_t *)"hello-this-is-written-every-couple-of-seconds\r\n", 47, LWS_WRITE_RAW) != 47) + return -1; + break; + + default: + break; + } + + return 0; +} + +static struct lws_protocols protocols[] = { + { "raw-test", callback_raw_test, 0, 0 }, + { NULL, NULL, 0, 0 } /* terminator */ +}; + +static int interrupted; + +void sigint_handler(int sig) +{ + interrupted = 1; +} + +int main(int argc, const char **argv) +{ + struct lws_context_creation_info info; + struct lws_context *context; + const char *p; + int n = 0, logs = LLL_USER | LLL_ERR | LLL_WARN | LLL_NOTICE + /* for LLL_ verbosity above NOTICE to be built into lws, + * lws must have been configured and built with + * -DCMAKE_BUILD_TYPE=DEBUG instead of =RELEASE */ + /* | LLL_INFO */ /* | LLL_PARSER */ /* | LLL_HEADER */ + /* | LLL_EXT */ /* | LLL_CLIENT */ /* | LLL_LATENCY */ + /* | LLL_DEBUG */; + + signal(SIGINT, sigint_handler); + + if ((p = lws_cmdline_option(argc, argv, "-d"))) + logs = atoi(p); + + lws_set_log_level(logs, NULL); + lwsl_user("LWS minimal raw serial\n"); + if (argc < 2) { + lwsl_user("Usage: %s " + " eg, /dev/ttyUSB0\n", argv[0]); + + return 1; + } + + signal(SIGINT, sigint_handler); + + memset(&info, 0, sizeof info); /* otherwise uninitialized garbage */ + info.port = CONTEXT_PORT_NO_LISTEN_SERVER; /* no listen socket for demo */ + info.protocols = protocols; + + lws_strncpy(filepath, argv[1], sizeof(filepath)); + + context = lws_create_context(&info); + if (!context) { + lwsl_err("lws init failed\n"); + return 1; + } + + while (n >= 0 && !interrupted) + n = lws_service(context, 0); + + lws_context_destroy(context); + + return 0; +} diff -Nru libwebsockets-3.2.1/minimal-examples/raw/minimal-raw-serial/README.md libwebsockets-4.1.6/minimal-examples/raw/minimal-raw-serial/README.md --- libwebsockets-3.2.1/minimal-examples/raw/minimal-raw-serial/README.md 1970-01-01 00:00:00.000000000 +0000 +++ libwebsockets-4.1.6/minimal-examples/raw/minimal-raw-serial/README.md 2020-12-01 17:40:26.000000000 +0000 @@ -0,0 +1,46 @@ +# lws minimal raw serial example + +This demonstrates adopting a file descriptor representing a serial device +into the event loop, printing a string on it every couple of seconds and +showing any serial that is received. + +The serial terminal is configured for 115200 8N1. + + +``` + $ ./lws-minimal-raw-serial +``` + + +## build + +``` + $ cmake . && make +``` + +## usage + +``` +[2019/12/08 16:30:53:4436] U: LWS minimal raw serial +[2019/12/08 16:30:53:5016] E: callback_ntpc: set up system ops for set_clock +[2019/12/08 16:30:54:8061] N: callback_ntpc: Unix time: 1575822654 +[2019/12/08 16:30:54:8253] N: LWS_CALLBACK_RAW_ADOPT_FILE +[2019/12/08 16:30:54:8364] N: callback_ntpc: LWS_CALLBACK_RAW_CLOSE +[2019/12/08 16:30:54:8456] N: LWS_CALLBACK_RAW_WRITEABLE_FILE +[2019/12/08 16:30:56:8455] N: LWS_CALLBACK_RAW_WRITEABLE_FILE +[2019/12/08 16:30:58:8460] N: LWS_CALLBACK_RAW_WRITEABLE_FILE +[2019/12/08 16:30:59:1570] N: LWS_CALLBACK_RAW_RX_FILE +[2019/12/08 16:30:59:1604] N: +[2019/12/08 16:30:59:1641] N: 0000: 62 b +[2019/12/08 16:30:59:1644] N: +[2019/12/08 16:31:00:8463] N: LWS_CALLBACK_RAW_WRITEABLE_FILE +[2019/12/08 16:31:01:6392] N: LWS_CALLBACK_RAW_RX_FILE +[2019/12/08 16:31:01:6397] N: +[2019/12/08 16:31:01:6407] N: 0000: 65 e +[2019/12/08 16:31:01:6411] N: +[2019/12/08 16:31:02:8463] N: LWS_CALLBACK_RAW_WRITEABLE_FILE +... . + +``` + +The remote serial connection will show the string sent every 2s. diff -Nru libwebsockets-3.2.1/minimal-examples/raw/minimal-raw-vhost/CMakeLists.txt libwebsockets-4.1.6/minimal-examples/raw/minimal-raw-vhost/CMakeLists.txt --- libwebsockets-3.2.1/minimal-examples/raw/minimal-raw-vhost/CMakeLists.txt 2019-12-18 14:45:31.000000000 +0000 +++ libwebsockets-4.1.6/minimal-examples/raw/minimal-raw-vhost/CMakeLists.txt 2020-12-01 17:40:26.000000000 +0000 @@ -1,76 +1,23 @@ +project(lws-minimal-raw-vhost C) cmake_minimum_required(VERSION 2.8) +find_package(libwebsockets CONFIG REQUIRED) +list(APPEND CMAKE_MODULE_PATH ${LWS_CMAKE_DIR}) include(CheckCSourceCompiles) +include(LwsCheckRequirements) set(SAMP lws-minimal-raw-vhost) set(SRCS minimal-raw-vhost.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_WITH_SERVER 1 requirements) if (requirements) add_executable(${SAMP} ${SRCS}) if (websockets_shared) - target_link_libraries(${SAMP} websockets_shared) + target_link_libraries(${SAMP} websockets_shared ${LIBWEBSOCKETS_DEP_LIBS}) add_dependencies(${SAMP} websockets_shared) else() - target_link_libraries(${SAMP} websockets) + target_link_libraries(${SAMP} websockets ${LIBWEBSOCKETS_DEP_LIBS}) endif() endif() diff -Nru libwebsockets-3.2.1/minimal-examples/raw/minimal-raw-vhost/minimal-raw-vhost.c libwebsockets-4.1.6/minimal-examples/raw/minimal-raw-vhost/minimal-raw-vhost.c --- libwebsockets-3.2.1/minimal-examples/raw/minimal-raw-vhost/minimal-raw-vhost.c 2019-12-18 14:45:31.000000000 +0000 +++ libwebsockets-4.1.6/minimal-examples/raw/minimal-raw-vhost/minimal-raw-vhost.c 2020-12-01 17:40:26.000000000 +0000 @@ -53,7 +53,7 @@ switch (reason) { case LWS_CALLBACK_PROTOCOL_INIT: - vhd = lws_protocol_vh_priv_zalloc(lws_get_vhost(wsi), + lws_protocol_vh_priv_zalloc(lws_get_vhost(wsi), lws_get_protocol(wsi), sizeof(struct raw_vhd)); break; @@ -75,7 +75,7 @@ case LWS_CALLBACK_RAW_RX: lwsl_user("LWS_CALLBACK_RAW_RX: %d\n", (int)len); - vhd->len = len; + vhd->len = (int)len; if (vhd->len > (int)sizeof(vhd->buf)) vhd->len = sizeof(vhd->buf); memcpy(vhd->buf, in, vhd->len); @@ -137,11 +137,13 @@ info.protocols = protocols; info.options = LWS_SERVER_OPTION_ONLY_RAW; /* vhost accepts RAW */ +#if defined(LWS_WITH_TLS) if (lws_cmdline_option(argc, argv, "-s")) { info.options |= LWS_SERVER_OPTION_DO_SSL_GLOBAL_INIT; info.ssl_cert_filepath = "localhost-100y.cert"; info.ssl_private_key_filepath = "localhost-100y.key"; } +#endif context = lws_create_context(&info); if (!context) { diff -Nru libwebsockets-3.2.1/minimal-examples/README.md libwebsockets-4.1.6/minimal-examples/README.md --- libwebsockets-3.2.1/minimal-examples/README.md 2019-12-18 14:45:31.000000000 +0000 +++ libwebsockets-4.1.6/minimal-examples/README.md 2020-12-01 17:40:26.000000000 +0000 @@ -6,6 +6,7 @@ http-client|Minimal examples providing an http client http-server|Minimal examples providing an http server raw|Minimal examples related to adopting raw file or socket descriptors into the event loop +secure-streams|Minimal examples related to the Secure Streams client api ws-client|Minimal examples providing a ws client ws-server|Minimal examples providing a ws server (and an http server) diff -Nru libwebsockets-3.2.1/minimal-examples/secure-streams/minimal-secure-streams/CMakeLists.txt libwebsockets-4.1.6/minimal-examples/secure-streams/minimal-secure-streams/CMakeLists.txt --- libwebsockets-3.2.1/minimal-examples/secure-streams/minimal-secure-streams/CMakeLists.txt 1970-01-01 00:00:00.000000000 +0000 +++ libwebsockets-4.1.6/minimal-examples/secure-streams/minimal-secure-streams/CMakeLists.txt 2020-12-01 17:40:26.000000000 +0000 @@ -0,0 +1,49 @@ +project(lws-minimal-secure-streams C) +cmake_minimum_required(VERSION 2.8) +find_package(libwebsockets CONFIG REQUIRED) +list(APPEND CMAKE_MODULE_PATH ${LWS_CMAKE_DIR}) +include(CheckCSourceCompiles) +include(LwsCheckRequirements) + +set(SAMP lws-minimal-secure-streams) + +set(requirements 1) +require_lws_config(LWS_ROLE_H1 1 requirements) +require_lws_config(LWS_WITHOUT_CLIENT 0 requirements) +require_lws_config(LWS_WITH_SECURE_STREAMS 1 requirements) +require_lws_config(LWS_WITH_SECURE_STREAMS_STATIC_POLICY_ONLY 0 requirements) +require_lws_config(LWS_WITH_SYS_STATE 1 requirements) + +if (requirements) + add_executable(${SAMP} minimal-secure-streams.c) + + if (LWS_CTEST_INTERNET_AVAILABLE) + add_test(NAME ss-warmcat COMMAND lws-minimal-secure-streams) + set_tests_properties(ss-warmcat + PROPERTIES + WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}/minimal-examples/secure-streams/minimal-secure-streams + TIMEOUT 20) + endif() + + if (websockets_shared) + target_link_libraries(${SAMP} websockets_shared ${LIBWEBSOCKETS_DEP_LIBS}) + add_dependencies(${SAMP} websockets_shared) + else() + target_link_libraries(${SAMP} websockets ${LIBWEBSOCKETS_DEP_LIBS}) + endif() + + CHECK_C_SOURCE_COMPILES("#include \nint main(void) {\ni#if defined(LWS_WITH_SECURE_STREAMS_PROXY_API)\n return 0;\n #else\n fail\n #endif\n return 0;\n}\n" HAS_LWS_WITH_SECURE_STREAMS_PROXY_API) + + if (HAS_LWS_WITH_SECURE_STREAMS_PROXY_API OR LWS_WITH_SECURE_STREAMS_PROXY_API) + add_compile_options(-DLWS_SS_USE_SSPC) + + add_executable(${SAMP}-client minimal-secure-streams.c) + if (websockets_shared) + target_link_libraries(${SAMP}-client websockets_shared ${LIBWEBSOCKETS_DEP_LIBS}) + add_dependencies(${SAMP}-client websockets_shared) + else() + target_link_libraries(${SAMP}-client websockets ${LIBWEBSOCKETS_DEP_LIBS}) + endif() + endif() + +endif() diff -Nru libwebsockets-3.2.1/minimal-examples/secure-streams/minimal-secure-streams/minimal-secure-streams.c libwebsockets-4.1.6/minimal-examples/secure-streams/minimal-secure-streams/minimal-secure-streams.c --- libwebsockets-3.2.1/minimal-examples/secure-streams/minimal-secure-streams/minimal-secure-streams.c 1970-01-01 00:00:00.000000000 +0000 +++ libwebsockets-4.1.6/minimal-examples/secure-streams/minimal-secure-streams/minimal-secure-streams.c 2020-12-01 17:40:26.000000000 +0000 @@ -0,0 +1,520 @@ +/* + * lws-minimal-secure-streams + * + * Written in 2010-2020 by Andy Green + * + * This file is made available under the Creative Commons CC0 1.0 + * Universal Public Domain Dedication. + * + * + * This demonstrates a minimal http client using secure streams api. + * + * It visits https://warmcat.com/ and receives the html page there. + * + * This example is built two different ways from the same source... one includes + * the policy everything needed to fulfil the stream directly. The other -client + * variant has no policy itself and some other minor init changes, and connects + * to the -proxy example to actually get the connection done. + * + * In the -client build case, the example does not even init the tls libraries + * since the proxy part will take care of all that. + */ + +#include +#include +#include + +/* + * uncomment to force network traffic through 127.0.0.1:1080 + * + * On your local machine, you can run a SOCKS5 proxy like this + * + * $ ssh -N -D 0.0.0.0:1080 localhost -v + * + * If enabled, this also fetches a remote policy that also + * specifies that all traffic should go through the remote + * proxy. + */ +// #define VIA_LOCALHOST_SOCKS + +static int interrupted, bad = 1, force_cpd_fail_portal, + force_cpd_fail_no_internet; +static unsigned int timeout_ms = 3000; +static lws_state_notify_link_t nl; + +/* + * If the -proxy app is fulfilling our connection, then we don't need to have + * the policy in the client. + * + * When we build with LWS_SS_USE_SSPC, the apis hook up to a proxy process over + * a Unix Domain Socket. To test that, you need to separately run the + * ./lws-minimal-secure-streams-proxy test app on the same machine. + */ + +#if !defined(LWS_SS_USE_SSPC) +static const char * const default_ss_policy = + "{" + "\"release\":" "\"01234567\"," + "\"product\":" "\"myproduct\"," + "\"schema-version\":" "1," +#if defined(VIA_LOCALHOST_SOCKS) + "\"via-socks5\":" "\"127.0.0.1:1080\"," +#endif + + "\"retry\": [" /* named backoff / retry strategies */ + "{\"default\": {" + "\"backoff\": [" "1000," + "2000," + "3000," + "5000," + "10000" + "]," + "\"conceal\":" "5," + "\"jitterpc\":" "20," + "\"svalidping\":" "30," + "\"svalidhup\":" "35" + "}}" + "]," + "\"certs\": [" /* named individual certificates in BASE64 DER */ + /* + * Let's Encrypt certs for warmcat.com / libwebsockets.org + * + * We fetch the real policy from there using SS and switch to + * using that. + */ + "{\"isrg_root_x1\": \"" /* ISRG ROOT X1 */ + "MIIFazCCA1OgAwIBAgIRAIIQz7DSQONZRGPgu2OCiwAwDQYJKoZIhvcNAQELBQAw" + "TzELMAkGA1UEBhMCVVMxKTAnBgNVBAoTIEludGVybmV0IFNlY3VyaXR5IFJlc2Vh" + "cmNoIEdyb3VwMRUwEwYDVQQDEwxJU1JHIFJvb3QgWDEwHhcNMTUwNjA0MTEwNDM4" + "WhcNMzUwNjA0MTEwNDM4WjBPMQswCQYDVQQGEwJVUzEpMCcGA1UEChMgSW50ZXJu" + "ZXQgU2VjdXJpdHkgUmVzZWFyY2ggR3JvdXAxFTATBgNVBAMTDElTUkcgUm9vdCBY" + "MTCCAiIwDQYJKoZIhvcNAQEBBQADggIPADCCAgoCggIBAK3oJHP0FDfzm54rVygc" + "h77ct984kIxuPOZXoHj3dcKi/vVqbvYATyjb3miGbESTtrFj/RQSa78f0uoxmyF+" + "0TM8ukj13Xnfs7j/EvEhmkvBioZxaUpmZmyPfjxwv60pIgbz5MDmgK7iS4+3mX6U" + "A5/TR5d8mUgjU+g4rk8Kb4Mu0UlXjIB0ttov0DiNew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KhSDeQoMpYnwcmQilRh/0" + "ayLThlHLN81gSkJjVrPI0Y8xCVPB4twb1PFUd2fPM3sA1tJ83sZ5v8vgFv2yofKR" + "PB0t6JzUA81mSqM3kxl5e+IZwhYAyO0OTg3/fs8HqGTNKd9BqoUwSRBzp06JMg5b" + "rUCGwbCUDI0mxadJ3Bz4WxR6fyNpBK2yAinWEsikxqEt" + "\"}" + "]," + "\"trust_stores\": [" /* named cert chains */ + "{" + "\"name\": \"le_via_isrg\"," + "\"stack\": [" + "\"isrg_root_x1\"," + "\"LEX3_isrg_root_x1\"" + "]" + "}" + "]," + "\"s\": [" + /* + * "fetch_policy" decides from where the real policy + * will be fetched, if present. Otherwise the initial + * policy is treated as the whole, hardcoded, policy. + */ + "{\"fetch_policy\": {" + "\"endpoint\":" "\"warmcat.com\"," + "\"port\":" "443," + "\"protocol\":" "\"h1\"," + "\"http_method\":" "\"GET\"," +#if defined(VIA_LOCALHOST_SOCKS) + "\"http_url\":" "\"policy/minimal-proxy-socks.json\"," +#else + "\"http_url\":" "\"policy/minimal-proxy.json\"," +#endif + "\"tls\":" "true," + "\"opportunistic\":" "true," + "\"retry\":" "\"default\"," + "\"tls_trust_store\":" "\"le_via_isrg\"" + "}},{" + /* + * "captive_portal_detect" describes + * what to do in order to check if the path to + * the Internet is being interrupted by a + * captive portal. If there's a larger policy + * fetched from elsewhere, it should also include + * this since it needs to be done at least after + * every DHCP acquisition + */ + "\"captive_portal_detect\": {" + "\"endpoint\": \"connectivitycheck.android.com\"," + "\"http_url\": \"generate_204\"," + "\"port\": 80," + "\"protocol\": \"h1\"," + "\"http_method\": \"GET\"," + "\"opportunistic\": true," + "\"http_expect\": 204," + "\"http_fail_redirect\": true" + "}}" + "]}" +; + +#endif + +typedef struct myss { + struct lws_ss_handle *ss; + void *opaque_data; + /* ... application specific state ... */ + lws_sorted_usec_list_t sul; +} myss_t; + +#if !defined(LWS_SS_USE_SSPC) + +static const char *canned_root_token_payload = + "grant_type=refresh_token" + "&refresh_token=Atzr|IwEBIJedGXjDqsU_vMxykqOMg" + "SHfYe3CPcedueWEMWSDMaDnEmiW8RlR1Kns7Cb4B-TOSnqp7ifVsY4BMY2B8tpHfO39XP" + "zfu9HapGjTR458IyHX44FE71pWJkGZ79uVBpljP4sazJuk8XS3Oe_yLnm_DIO6fU1nU3Y" + "0flYmsOiOAQE_gRk_pdlmEtHnpMA-9rLw3mkY5L89Ty9kUygBsiFaYatouROhbsTn8-jW" + "k1zZLUDpT6ICtBXSnrCIg0pUbZevPFhTwdXd6eX-u4rq0W-XaDvPWFO7au-iPb4Zk5eZE" + "iX6sissYrtNmuEXc2uHu7MnQO1hHCaTdIO2CANVumf-PHSD8xseamyh04sLV5JgFzY45S" + "KvKMajiUZuLkMokOx86rjC2Hdkx5DO7G-dbG1ufBDG-N79pFMSs7Ck5pc283IdLoJkCQc" + "AGvTX8o8I29QqkcGou-9TKhOJmpX8As94T61ok0UqqEKPJ7RhfQHHYdCtsdwxgvfVr9qI" + "xL_hDCcTho8opCVX-6QhJHl6SQFlTw13" + "&client_id=" + "amzn1.application-oa2-client.4823334c434b4190a2b5a42c07938a2d"; + +#endif + +/* secure streams payload interface */ + +static int +myss_rx(void *userobj, const uint8_t *buf, size_t len, int flags) +{ +// myss_t *m = (myss_t *)userobj; + + lwsl_user("%s: len %d, flags: %d\n", __func__, (int)len, flags); + lwsl_hexdump_info(buf, len); + + /* + * If we received the whole message, for our example it means + * we are done. + */ + if (flags & LWSSS_FLAG_EOM) { + bad = 0; + interrupted = 1; + } + + return 0; +} + +static int +myss_tx(void *userobj, lws_ss_tx_ordinal_t ord, uint8_t *buf, size_t *len, + int *flags) +{ + //myss_t *m = (myss_t *)userobj; + + /* in this example, we don't send stuff */ + + return LWSSSSRET_TX_DONT_SEND; +} + +static int +myss_state(void *userobj, void *sh, lws_ss_constate_t state, + lws_ss_tx_ordinal_t ack) +{ + myss_t *m = (myss_t *)userobj; + + lwsl_user("%s: %s, ord 0x%x\n", __func__, lws_ss_state_name(state), + (unsigned int)ack); + + switch (state) { + case LWSSSCS_CREATING: + lws_ss_start_timeout(m->ss, timeout_ms); + lws_ss_set_metadata(m->ss, "uptag", "myuptag123", 10); + lws_ss_set_metadata(m->ss, "ctype", "myctype", 7); + lws_ss_client_connect(m->ss); + break; + case LWSSSCS_ALL_RETRIES_FAILED: + /* if we're out of retries, we want to close the app and FAIL */ + interrupted = 1; + break; + case LWSSSCS_QOS_ACK_REMOTE: + lwsl_notice("%s: LWSSSCS_QOS_ACK_REMOTE\n", __func__); + break; + + case LWSSSCS_TIMEOUT: + lwsl_notice("%s: LWSSSCS_TIMEOUT\n", __func__); + break; + default: + break; + } + + return 0; +} + +static int +app_system_state_nf(lws_state_manager_t *mgr, lws_state_notify_link_t *link, + int current, int target) +{ + struct lws_context *context = lws_system_context_from_system_mgr(mgr); +#if !defined(LWS_SS_USE_SSPC) + + lws_system_blob_t *ab = lws_system_get_blob(context, + LWS_SYSBLOB_TYPE_AUTH, 1 /* AUTH_IDX_ROOT */); + size_t size; +#endif + + /* + * For the things we care about, let's notice if we are trying to get + * past them when we haven't solved them yet, and make the system + * state wait while we trigger the dependent action. + */ + switch (target) { + +#if !defined(LWS_SS_USE_SSPC) + + /* + * The proxy takes responsibility for this stuff if we get things + * done through that + */ + + case LWS_SYSTATE_INITIALIZED: /* overlay on the hardcoded policy */ + case LWS_SYSTATE_POLICY_VALID: /* overlay on the loaded policy */ + + if (target != current) + break; + + if (force_cpd_fail_portal) + + /* this makes it look like we're behind a captive portal + * because the overriden address does a redirect */ + + lws_ss_policy_overlay(context, + "{\"s\": [{\"captive_portal_detect\": {" + "\"endpoint\": \"google.com\"," + "\"http_url\": \"/\"," + "\"port\": 80" + "}}]}"); + + if (force_cpd_fail_no_internet) + + /* this looks like no internet, because the overridden + * port doesn't have anything that will connect to us */ + + lws_ss_policy_overlay(context, + "{\"s\": [{\"captive_portal_detect\": {" + "\"endpoint\": \"warmcat.com\"," + "\"http_url\": \"/\"," + "\"port\": 999" + "}}]}"); + break; + + case LWS_SYSTATE_REGISTERED: + size = lws_system_blob_get_size(ab); + if (size) + break; + + /* let's register our canned root token so auth can use it */ + lws_system_blob_direct_set(ab, + (const uint8_t *)canned_root_token_payload, + strlen(canned_root_token_payload)); + break; + +#endif + + case LWS_SYSTATE_OPERATIONAL: + if (current == LWS_SYSTATE_OPERATIONAL) { + lws_ss_info_t ssi; + + /* We're making an outgoing secure stream ourselves */ + + memset(&ssi, 0, sizeof(ssi)); + ssi.handle_offset = offsetof(myss_t, ss); + ssi.opaque_user_data_offset = offsetof(myss_t, + opaque_data); + ssi.rx = myss_rx; + ssi.tx = myss_tx; + ssi.state = myss_state; + ssi.user_alloc = sizeof(myss_t); + ssi.streamtype = "mintest"; + + if (lws_ss_create(context, 0, &ssi, NULL, NULL, + NULL, NULL)) { + lwsl_err("%s: failed to create secure stream\n", + __func__); + return -1; + } + } + break; + } + + return 0; +} + +static lws_state_notify_link_t * const app_notifier_list[] = { + &nl, NULL +}; + +static void +sigint_handler(int sig) +{ + interrupted = 1; +} + +int main(int argc, const char **argv) +{ + struct lws_context_creation_info info; + struct lws_context *context; + const char *p; + int n = 0; + + signal(SIGINT, sigint_handler); + + memset(&info, 0, sizeof info); + lws_cmdline_option_handle_builtin(argc, argv, &info); + + lwsl_user("LWS secure streams test client [-d]\n"); + + /* these options are mutually exclusive if given */ + + if (lws_cmdline_option(argc, argv, "--force-portal")) + force_cpd_fail_portal = 1; + + if (lws_cmdline_option(argc, argv, "--force-no-internet")) + force_cpd_fail_no_internet = 1; + + if ((p = lws_cmdline_option(argc, argv, "--timeout_ms"))) + timeout_ms = atoi(p); + + info.fd_limit_per_thread = 1 + 6 + 1; + info.port = CONTEXT_PORT_NO_LISTEN; +#if defined(LWS_SS_USE_SSPC) + info.protocols = lws_sspc_protocols; + { + const char *p; + + /* connect to ssproxy via UDS by default, else via + * tcp connection to this port */ + if ((p = lws_cmdline_option(argc, argv, "-p"))) + info.ss_proxy_port = atoi(p); + + /* UDS "proxy.ss.lws" in abstract namespace, else this socket + * path; when -p given this can specify the network interface + * to bind to */ + if ((p = lws_cmdline_option(argc, argv, "-i"))) + info.ss_proxy_bind = p; + + /* if -p given, -a specifies the proxy address to connect to */ + if ((p = lws_cmdline_option(argc, argv, "-a"))) + info.ss_proxy_address = p; + } +#else + info.pss_policies_json = default_ss_policy; + info.options = LWS_SERVER_OPTION_EXPLICIT_VHOSTS | + LWS_SERVER_OPTION_DO_SSL_GLOBAL_INIT; +#endif +#if defined(LWS_WITH_DETAILED_LATENCY) + info.detailed_latency_cb = lws_det_lat_plot_cb; + info.detailed_latency_filepath = "/tmp/lws-latency-ssproxy"; +#endif + + /* integrate us with lws system state management when context created */ + + nl.name = "app"; + nl.notify_cb = app_system_state_nf; + info.register_notifier_list = app_notifier_list; + + /* create the context */ + + context = lws_create_context(&info); + if (!context) { + lwsl_err("lws init failed\n"); + return 1; + } + +#if !defined(LWS_SS_USE_SSPC) + /* + * If we're being a proxied client, the proxy does all this + */ + + /* + * Set the related lws_system blobs + * + * ...direct_set() sets a pointer, so the thing pointed to has to have + * a suitable lifetime, eg, something that already exists on the heap or + * a const string in .rodata like this + */ + + lws_system_blob_direct_set(lws_system_get_blob(context, + LWS_SYSBLOB_TYPE_DEVICE_SERIAL, 0), + (const uint8_t *)"SN12345678", 10); + lws_system_blob_direct_set(lws_system_get_blob(context, + LWS_SYSBLOB_TYPE_DEVICE_FW_VERSION, 0), + (const uint8_t *)"v0.01", 5); + + /* + * ..._heap_append() appends to a buflist kind of arrangement on heap, + * just one block is fine, otherwise it will concatenate the fragments + * in the order they were appended (and take care of freeing them at + * context destroy time). ..._heap_empty() is also available to remove + * everything that was already allocated. + * + * Here we use _heap_append() just so it's tested as well as direct set. + */ + + lws_system_blob_heap_append(lws_system_get_blob(context, + LWS_SYSBLOB_TYPE_DEVICE_TYPE, 0), + (const uint8_t *)"spacerocket", 11); +#endif + + /* the event loop */ + + while (n >= 0 && !interrupted) + n = lws_service(context, 0); + + lws_context_destroy(context); + + lwsl_user("Completed: %s\n", bad ? "failed" : "OK"); + + return bad; +} diff -Nru libwebsockets-3.2.1/minimal-examples/secure-streams/minimal-secure-streams/README.md libwebsockets-4.1.6/minimal-examples/secure-streams/minimal-secure-streams/README.md --- libwebsockets-3.2.1/minimal-examples/secure-streams/minimal-secure-streams/README.md 1970-01-01 00:00:00.000000000 +0000 +++ libwebsockets-4.1.6/minimal-examples/secure-streams/minimal-secure-streams/README.md 2020-12-01 17:40:26.000000000 +0000 @@ -0,0 +1,66 @@ +# lws minimal secure streams + +The application goes to https://warmcat.com and reads index.html there. + +It does it using Secure Streams... the main code in minimal-secure-streams.c +just sets up the context and opens a secure stream of type "mintest". + +The handler for state changes and payloads for "mintest" is in ss-myss.c + +The information about how a "mintest" stream should connect and the +protocol it uses is kept separated in policy-database.c + +## build + +``` + $ cmake . && make +``` + +## usage + +Commandline option|Meaning +---|--- +-d |Debug verbosity in decimal, eg, -d15 +-f| Force connecting to the wrong endpoint to check backoff retry flow +-p| Run as proxy server for clients to connect to over unix domain socket +--force-portal|Force the SS Captive Portal Detection to feel it's behind a portal +--force-no-internet|Force the SS Captive Portal Detection to feel it can't reach the internet + +``` +[2019/08/12 07:16:11:0045] USR: LWS minimal secure streams [-d] [-f] +[2019/08/12 07:16:12:6102] USR: myss_state: LWSSSCS_CREATING, ord 0x0 +[2019/08/12 07:16:12:6107] USR: myss_state: LWSSSCS_POLL, ord 0x0 +[2019/08/12 07:16:12:6117] N: lws_ss_client_connect: connecting h1get warmcat.com / +[2019/08/12 07:16:12:6118] USR: myss_state: LWSSSCS_CONNECTING, ord 0x0 +[2019/08/12 07:16:13:4171] USR: myss_state: LWSSSCS_CONNECTED, ord 0x0 +[2019/08/12 07:16:13:4222] USR: myss_rx: len 1024, flags: 1 +[2019/08/12 07:16:13:4243] USR: myss_rx: len 1024, flags: 0 +[2019/08/12 07:16:13:4244] USR: myss_rx: len 1024, flags: 0 +[2019/08/12 07:16:13:4244] USR: myss_rx: len 1024, flags: 0 +[2019/08/12 07:16:13:4245] USR: myss_rx: len 1024, flags: 0 +[2019/08/12 07:16:13:4246] USR: myss_rx: len 1024, flags: 0 +[2019/08/12 07:16:13:4247] USR: myss_rx: len 1024, flags: 0 +[2019/08/12 07:16:13:4252] USR: myss_rx: len 1015, flags: 0 +[2019/08/12 07:16:13:4264] USR: myss_rx: len 1024, flags: 0 +[2019/08/12 07:16:13:4265] USR: myss_rx: len 1024, flags: 0 +[2019/08/12 07:16:13:4266] USR: myss_rx: len 1024, flags: 0 +[2019/08/12 07:16:13:4267] USR: myss_rx: len 1024, flags: 0 +[2019/08/12 07:16:13:4268] USR: myss_rx: len 1024, flags: 0 +[2019/08/12 07:16:13:4268] USR: myss_rx: len 1024, flags: 0 +[2019/08/12 07:16:13:4269] USR: myss_rx: len 1024, flags: 0 +[2019/08/12 07:16:13:4270] USR: myss_rx: len 1015, flags: 0 +[2019/08/12 07:16:13:4278] USR: myss_rx: len 1024, flags: 0 +[2019/08/12 07:16:13:4279] USR: myss_rx: len 1024, flags: 0 +[2019/08/12 07:16:13:4280] USR: myss_rx: len 1024, flags: 0 +[2019/08/12 07:16:13:4281] USR: myss_rx: len 1024, flags: 0 +[2019/08/12 07:16:13:4282] USR: myss_rx: len 1024, flags: 0 +[2019/08/12 07:16:13:4283] USR: myss_rx: len 1024, flags: 0 +[2019/08/12 07:16:13:4283] USR: myss_rx: len 1024, flags: 0 +[2019/08/12 07:16:13:4284] USR: myss_rx: len 1015, flags: 0 +[2019/08/12 07:16:13:4287] USR: myss_rx: len 1024, flags: 0 +[2019/08/12 07:16:13:4288] USR: myss_rx: len 947, flags: 0 +[2019/08/12 07:16:13:4293] USR: myss_rx: len 0, flags: 2 +[2019/08/12 07:16:13:4399] USR: myss_state: LWSSSCS_DISCONNECTED, ord 0x0 +[2019/08/12 07:16:13:4761] USR: myss_state: LWSSSCS_DESTROYING, ord 0x0 +[2019/08/12 07:16:13:4781] USR: Completed: OK +``` diff -Nru libwebsockets-3.2.1/minimal-examples/secure-streams/minimal-secure-streams-alexa/alexa.c libwebsockets-4.1.6/minimal-examples/secure-streams/minimal-secure-streams-alexa/alexa.c --- libwebsockets-3.2.1/minimal-examples/secure-streams/minimal-secure-streams-alexa/alexa.c 1970-01-01 00:00:00.000000000 +0000 +++ libwebsockets-4.1.6/minimal-examples/secure-streams/minimal-secure-streams-alexa/alexa.c 2020-12-01 17:40:26.000000000 +0000 @@ -0,0 +1,675 @@ +/* + * lws-minimal-secure-streams-alexa + * + * This file is made available under the Creative Commons CC0 1.0 + * Universal Public Domain Dedication. + */ + +#include +#include +#include +#include +#include +#include + +#include + +#include "private.h" + +struct lws_ss_handle *hss_avs_event, *hss_avs_sync; + +/* this is the type for the long poll event channel */ + +typedef struct ss_avs_event { + struct lws_ss_handle *ss; + void *opaque_data; + /* ... application specific state ... */ + + struct lejp_ctx jctx; +} ss_avs_event_t; + +enum { + LAMP3STATE_IDLE, + LAMP3STATE_SPOOLING, + LAMP3STATE_DRAINING, +}; + +/* this is the type for the utterance metadata (and audio rideshares) */ + +typedef struct ss_avs_metadata { + struct lws_ss_handle *ss; + void *opaque_data; + /* ... application specific state ... */ + + struct lws_buflist *dribble; /* next mp3 data while draining last */ + + struct lejp_ctx jctx; + size_t pos; + size_t mp3_in; + mpg123_handle *mh; + + lws_sorted_usec_list_t sul; + + uint8_t stash_eom[16]; + + uint8_t se_head; + uint8_t se_tail; + + char mp3_state; + char first_mp3; + uint8_t mp3_mime_match; + uint8_t seen; + uint8_t inside_mp3; + +} ss_avs_metadata_t; + +/* + * The remote server only seems to give us a budget of 10s to consume the + * results, after that it doesn't drop the stream, but doesn't send us anything + * further on it. + * + * This makes it impossible to optimize buffering for incoming mp3 since we + * have to go ahead and take it before the 10s is up. + */ + +#define MAX_MP3_IN_BUFFERING_BYTES 32768 + +/* + * Structure of JSON metadata for utterance handling + */ + +static const char *metadata = "{" + "\"event\": {" + "\"header\": {" + "\"namespace\": \"SpeechRecognizer\"," + "\"name\": \"Recognize\"," + "\"messageId\": \"message-123\"," + "\"dialogRequestId\": \"dialog-request-321\"" + "}," + "\"payload\": {" + "\"profile\":" "\"CLOSE_TALK\"," + "\"format\":" "\"AUDIO_L16_RATE_16000_CHANNELS_1\"" + "}" + "}" +"}"; + +/* + * avs metadata + */ + +static void +use_buffer_250ms(lws_sorted_usec_list_t *sul) +{ + ss_avs_metadata_t *m = lws_container_of(sul, ss_avs_metadata_t, sul); + struct lws_context *context = (struct lws_context *)m->opaque_data; + int est = lws_ss_get_est_peer_tx_credit(m->ss); + + lwsl_notice("%s: est txcr %d\n", __func__, est); + + if (est < MAX_MP3_IN_BUFFERING_BYTES - (MAX_MP3_IN_BUFFERING_BYTES / 4)) { + lwsl_notice(" adding %d\n", MAX_MP3_IN_BUFFERING_BYTES / 4); + lws_ss_add_peer_tx_credit(m->ss, MAX_MP3_IN_BUFFERING_BYTES / 4); + } + + lws_sul_schedule(context, 0, &m->sul, use_buffer_250ms, + 250 * LWS_US_PER_MS); +} + +static const char *mp3_mimetype = "application/octet-stream", + *match2 = "\x0d\x0a\x0d\x0a"; + +static int +ss_avs_mp3_open(ss_avs_metadata_t *m) +{ + int r; + + lwsl_notice("%s\n", __func__); + + m->first_mp3 = 1; + m->mh = mpg123_new(NULL, NULL); + if (!m->mh) { + lwsl_err("%s: unable to make new mp3\n", + __func__); + goto bail; + } + mpg123_format_none(m->mh); + r = mpg123_format(m->mh, 16000, MPG123_M_MONO, + MPG123_ENC_SIGNED_16); + if (r) { + lwsl_err("%s: mpg123 format failed %d\n", + __func__, r); + goto bail1; + } + r = mpg123_open_feed(m->mh); + if (r) { + lwsl_err("%s: mpg123 open feed failed %d\n", + __func__, r); + goto bail1; + } + + return 0; + +bail1: + mpg123_delete(m->mh); + m->mh = NULL; + +bail: + return 1; +} + +static int +ss_avs_metadata_rx(void *userobj, const uint8_t *buf, size_t len, int flags); + +/* + * This is called when the mp3 has drained it's input buffer and destroyed + * itself. + */ + +static int +drain_end_cb(void *v) +{ + ss_avs_metadata_t *m = (ss_avs_metadata_t *)v; + struct lws_context *context = (struct lws_context *)m->opaque_data; + int tot = 0; + + lwsl_err("%s\n", __func__); + + /* + * We have drained and destroyed the existing mp3 session. Is there + * a new one pending? + */ + + m->first_mp3 = 1; + m->mp3_state = LAMP3STATE_IDLE; + + if (lws_buflist_total_len(&m->dribble)) { + /* we started another one */ + + /* resume tx credit top up */ + lws_sul_schedule(context, 0, &m->sul, use_buffer_250ms, 1); + + if (ss_avs_mp3_open(m)) + return 1; + + m->mp3_state = LAMP3STATE_SPOOLING; + + /* + * Dump what we stashed from draining into the new mp3 + */ + + while (lws_buflist_total_len(&m->dribble)) { + size_t s; + uint8_t *u, t; + + s = lws_buflist_next_segment_len(&m->dribble, &u); + t = m->stash_eom[m->se_tail]; + lwsl_notice("%s: preload %d: %d\n", __func__, (int)s, t); + + mpg123_feed(m->mh, u, s); + lws_buflist_use_segment(&m->dribble, s); + if (m->first_mp3) { + play_mp3(m->mh, NULL, NULL); + m->first_mp3 = 0; + } + + tot += s; + + m->se_tail = (m->se_tail + 1) % sizeof(m->stash_eom); + if (t) { + lwsl_notice("%s: preloaded EOM\n", __func__); + + /* + * We stashed the whole of the message, we need + * to also do the EOM processing. We will come + * back here if there's another message in the + * stash. + */ + + m->mp3_state = LAMP3STATE_DRAINING; + if (m->mh) + play_mp3(NULL, drain_end_cb, m); + + lws_ss_add_peer_tx_credit(m->ss, tot); +#if 0 + /* + * Put a hold on bringing in any more data + */ + lws_sul_cancel(&m->sul); +#endif + /* destroy our copy of the handle */ + m->mh = NULL; + + break; + } + } + + lws_ss_add_peer_tx_credit(m->ss, tot); + } + + return 0; +} + +static int +ss_avs_metadata_rx(void *userobj, const uint8_t *buf, size_t len, int flags) +{ + ss_avs_metadata_t *m = (ss_avs_metadata_t *)userobj; + struct lws_context *context = (struct lws_context *)m->opaque_data; + int n = 0, hit = 0; + + lwsl_notice("%s: len %d, flags %d (est peer txcr %d)\n", __func__, + (int)len, flags, lws_ss_get_est_peer_tx_credit(m->ss)); + + // lwsl_hexdump_warn(buf, len); + + if ((flags & LWSSS_FLAG_SOM) && !m->mh && !m->seen) { + m->mp3_mime_match = 0; + m->seen = 0; + m->inside_mp3 = 0; + } + + if (!m->inside_mp3) { + /* + * Identify the part with the mp3 in, if any + */ + + while (n < (int)len - 24) { + if (!m->seen) { + if (buf[n] == mp3_mimetype[m->mp3_mime_match]) { + m->mp3_mime_match++; + if (m->mp3_mime_match == 24) { + m->mp3_mime_match = 0; + m->seen = 1; + n++; + continue; + } + } else + m->mp3_mime_match = 0; + } else { + if (buf[n] == match2[m->mp3_mime_match]) { + m->mp3_mime_match++; + if (m->mp3_mime_match == 4) { + m->seen = 0; + m->mp3_mime_match = 0; + hit = 1; + n++; + buf += n; + len -= n; + lwsl_notice("identified reply...\n"); + m->inside_mp3 = 1; + break; + } + } else + m->mp3_mime_match = 0; + } + + n++; + } + + if (!hit) { + lws_ss_add_peer_tx_credit(m->ss, len); + return 0; + } + } + + // lwsl_notice("%s: state %d\n", __func__, m->mp3_state); + + switch (m->mp3_state) { + case LAMP3STATE_IDLE: + + if (hit) { + + lws_ss_add_peer_tx_credit(m->ss, n); + + if (ss_avs_mp3_open(m)) + goto bail; + + lws_sul_schedule(context, 0, &m->sul, use_buffer_250ms, 1); + m->mp3_state = LAMP3STATE_SPOOLING; + break; + } + + lws_ss_add_peer_tx_credit(m->ss, len); + + if (!m->inside_mp3) + break; + + /* fallthru */ + + case LAMP3STATE_SPOOLING: + + if (m->dribble) + goto draining; + + if (len) { + /* + * We are shoving encoded mp3 into mpg123-allocated heap + * buffers... unfortunately mpg123 doesn't seem to + * expose where it is in its allocated input so we can + * track how much is stashed. Instead while in playback + * mode, we assume 64kbps mp3 encoding, ie, 8KB/s, and + * run a sul that allows an additional 2KB tx credit + * every 250ms, with 4KB initial credit. + */ + lwsl_notice("%s: SPOOL %d\n", __func__, (int)len); + mpg123_feed(m->mh, buf, len); + + if (m->first_mp3) { + lws_sul_schedule(context, 0, &m->sul, + use_buffer_250ms, 1); + // lws_ss_add_peer_tx_credit(m->ss, + // len + (MAX_MP3_IN_BUFFERING_BYTES / 2)); + play_mp3(m->mh, NULL, NULL); + } //else + // lws_ss_add_peer_tx_credit(m->ss, len); + m->first_mp3 = 0; + } + + if (flags & LWSSS_FLAG_EOM) { + /* + * This means one "message" / mime part with mp3 data + * has finished coming in. But there may be whole other + * parts with other mp3s following, with potentially + * different mp3 parameters. So we want to tell this + * one to drain and finish and destroy the current mp3 + * object before we go on. + * + * But not knowing the length of the current one, there + * will already be outstanding tx credit at the server, + * so it's going to spam us with the next part before we + * have the new mp3 sink for it. + */ + lwsl_notice("%s: EOM\n", __func__); + m->mp3_mime_match = 0; + m->seen = 0; + m->mp3_state = LAMP3STATE_DRAINING; + /* from input POV, we're no longer inside an mp3 */ + m->inside_mp3 = 0; + if (m->mh) + play_mp3(NULL, drain_end_cb, m); +#if 0 + /* + * Put a hold on bringing in any more data + */ + lws_sul_cancel(&m->sul); +#endif + /* destroy our copy of the handle */ + m->mh = NULL; + } + break; + + case LAMP3STATE_DRAINING: + +draining: + if (buf && len && m->inside_mp3) { + lwsl_notice("%s: DRAINING: stashing %d: %d %d %d\n", + __func__, (int)len, !!(flags & LWSSS_FLAG_EOM), + m->se_head, m->se_tail); + lwsl_hexdump_notice(buf, len); + if (lws_buflist_append_segment(&m->dribble, buf, len) < 0) + goto bail; + + m->stash_eom[m->se_head] = !!(flags & LWSSS_FLAG_EOM); + m->se_head = (m->se_head + 1) % sizeof(m->stash_eom); + lwsl_notice("%s: next head %d\n", __func__, m->se_head); + + lws_ss_add_peer_tx_credit(m->ss, len); + } + + if (flags & LWSSS_FLAG_EOM) { + if (!len && m->se_head != m->se_tail) { + /* 0-len EOM... retrospectively mark last stash */ + lwsl_notice("%s: retro EOM\n", __func__); + m->stash_eom[(m->se_head - 1) % sizeof(m->stash_eom)] = 1; + } + + lwsl_notice("%s: Draining EOM\n", __func__); + m->inside_mp3 = 0; + } + /* + * Don't provide any additional tx credit... we're just + * mopping up the overspill from the previous mp3 credit + */ + break; + } + + return 0; + +bail: + return -1; +} + +/* + * Because this is multipart mime in h2 currently, use a "rideshare" to handle + * first the native metadata on this secure stream, then the "rideshare" audio + * stream mentioned in the policy. + * + * Lws takes care of interleaving the multipart mime pieces since the policy + * calls for it. + */ + +static int +ss_avs_metadata_tx(void *userobj, lws_ss_tx_ordinal_t ord, uint8_t *buf, + size_t *len, int *flags) +{ + ss_avs_metadata_t *m = (ss_avs_metadata_t *)userobj; + size_t tot; + int n; + + // lwsl_notice("%s %d\n", __func__, (int)m->pos); + + if ((long)m->pos < 0) { + *len = 0; + lwsl_info("%s: skip\n", __func__); + return 1; + } + + if (!strcmp(lws_ss_rideshare(m->ss), "avs_audio")) { + + /* audio rideshare part */ + + if (!m->pos) + *flags |= LWSSS_FLAG_SOM; + + n = spool_capture(buf, *len); + if (n > 0) + *len = n; + else + *len = 0; + if (!n) { + lwsl_info("%s: trying to skip tx\n", __func__); + return 1; + } + + m->pos += *len; + + if (n < 0) { + *flags |= LWSSS_FLAG_EOM; + m->pos = (long)-1l; /* ban subsequent until new stream */ + } + + lwsl_notice("%s: tx audio %d\n", __func__, (int)*len); + +#if 0 + { + int ff = open("/tmp/z1", O_RDWR | O_CREAT | O_APPEND, 0666); + if (ff == -1) + lwsl_err("%s: errno %d\n", __func__, errno); + write(ff, buf, *len); + close(ff); + } +#endif + + return 0; + } + + /* metadata part */ + + tot = strlen(metadata); + + if (!m->pos) + *flags |= LWSSS_FLAG_SOM; + + if (*len > tot - m->pos) + *len = tot - m->pos; + + memcpy(buf, metadata + m->pos, *len); + + m->pos += *len; + + if (m->pos == tot) { + lwsl_notice("metadata done\n"); + *flags |= LWSSS_FLAG_EOM; + m->pos = 0; /* for next time */ + } + + return 0; +} + +static int +ss_avs_metadata_state(void *userobj, void *sh, + lws_ss_constate_t state, lws_ss_tx_ordinal_t ack) +{ + ss_avs_metadata_t *m = (ss_avs_metadata_t *)userobj; + struct lws_context *context = (struct lws_context *)m->opaque_data; + + lwsl_notice("%s: %p: %s, ord 0x%x\n", __func__, m->ss, + lws_ss_state_name(state), (unsigned int)ack); + + switch (state) { + case LWSSSCS_CREATING: + lws_ss_client_connect(m->ss); + break; + case LWSSSCS_CONNECTING: + m->pos = 0; + break; + case LWSSSCS_CONNECTED: + lwsl_info("%s: CONNECTED\n", __func__); + lws_ss_request_tx(m->ss); + break; + case LWSSSCS_DISCONNECTED: + lws_sul_cancel(&m->sul); + //if (m->mh) { + play_mp3(NULL, NULL, NULL); + m->mh = NULL; + //} + /* + * For this stream encapsulating an alexa exchange, dropping + * is the end of its life + */ + return 1; + + case LWSSSCS_DESTROYING: + lws_buflist_destroy_all_segments(&m->dribble); + break; + default: + break; + } + + return 0; +} + +/* + * avs event + */ + +static int +ss_avs_event_rx(void *userobj, const uint8_t *buf, size_t len, int flags) +{ + return 0; +} + +static int +ss_avs_event_tx(void *userobj, lws_ss_tx_ordinal_t ord, uint8_t *buf, + size_t *len, int *flags) +{ + return 1; /* don't transmit anything */ +} + +static int +ss_avs_event_state(void *userobj, void *sh, + lws_ss_constate_t state, lws_ss_tx_ordinal_t ack) +{ + lwsl_info("%s: %s, ord 0x%x\n", __func__, lws_ss_state_name(state), + (unsigned int)ack); + + switch (state) { + case LWSSSCS_CREATING: + mpg123_init(); + break; + case LWSSSCS_CONNECTING: + break; + case LWSSSCS_CONNECTED: + lwsl_user("Connected to Alexa... speak \"Alexa, ...\"\n"); + break; + case LWSSSCS_DISCONNECTED: + lwsl_user("Disconnected from Alexa\n"); + break; + case LWSSSCS_DESTROYING: + mpg123_exit(); + break; + default: + break; + } + + return 0; +} + +int +avs_query_start(struct lws_context *context) +{ + lws_ss_info_t ssi; + + lwsl_notice("%s:\n", __func__); + + memset(&ssi, 0, sizeof(ssi)); + ssi.handle_offset = offsetof(ss_avs_metadata_t, ss); + ssi.opaque_user_data_offset = offsetof(ss_avs_metadata_t, opaque_data); + ssi.rx = ss_avs_metadata_rx; + ssi.tx = ss_avs_metadata_tx; + ssi.state = ss_avs_metadata_state; + ssi.user_alloc = sizeof(ss_avs_metadata_t); + ssi.streamtype = "avs_metadata"; + + ssi.manual_initial_tx_credit = 8192; + + if (lws_ss_create(context, 0, &ssi, context, &hss_avs_sync, NULL, NULL)) { + lwsl_err("%s: failed to create avs metadata secstream\n", + __func__); + + return 1; + } + + lwsl_user("%s: created query stream %p\n", __func__, hss_avs_sync); + + return 0; +} + +int +avs_example_start(struct lws_context *context) +{ + lws_ss_info_t ssi; + + if (hss_avs_event) + return 0; + + lwsl_info("%s: Starting AVS stream\n", __func__); + + /* AVS wants us to establish the long poll event stream first */ + + memset(&ssi, 0, sizeof(ssi)); + ssi.handle_offset = offsetof(ss_avs_event_t, ss); + ssi.opaque_user_data_offset = offsetof(ss_avs_event_t, opaque_data); + ssi.rx = ss_avs_event_rx; + ssi.tx = ss_avs_event_tx; + ssi.state = ss_avs_event_state; + ssi.user_alloc = sizeof(ss_avs_event_t); + ssi.streamtype = "avs_event"; + + if (lws_ss_create(context, 0, &ssi, context, &hss_avs_event, NULL, NULL)) { + lwsl_err("%s: failed to create avs event secure stream\n", + __func__); + return 1; + } + + return 0; +} Binary files /tmp/tmp2l8bmswe/3lv7Sxvgkv/libwebsockets-3.2.1/minimal-examples/secure-streams/minimal-secure-streams-alexa/alexa_linux.ppn and /tmp/tmp2l8bmswe/LwTwoWz49Q/libwebsockets-4.1.6/minimal-examples/secure-streams/minimal-secure-streams-alexa/alexa_linux.ppn differ diff -Nru libwebsockets-3.2.1/minimal-examples/secure-streams/minimal-secure-streams-alexa/audio.c libwebsockets-4.1.6/minimal-examples/secure-streams/minimal-secure-streams-alexa/audio.c --- libwebsockets-3.2.1/minimal-examples/secure-streams/minimal-secure-streams-alexa/audio.c 1970-01-01 00:00:00.000000000 +0000 +++ libwebsockets-4.1.6/minimal-examples/secure-streams/minimal-secure-streams-alexa/audio.c 2020-12-01 17:40:26.000000000 +0000 @@ -0,0 +1,469 @@ +/* + * alsa audio handling + * + * Written in 2010-2020 by Andy Green + * + * This file is made available under the Creative Commons CC0 1.0 + * Universal Public Domain Dedication. + */ + +#include +#include +#include +#include +#include +#include + +#include +#include + +#include + +#include "private.h" + +extern struct lws_ss_handle *hss_avs_event, *hss_avs_sync; + +int +avs_query_start(struct lws_context *context); + +enum { + MODE_IDLE, + MODE_CAPTURING, + MODE_PLAYING +}; + +struct raw_vhd { + int16_t p[8 * 1024]; /* 500ms at 16kHz 16-bit PCM */ + pv_porcupine_object_t *porc; + snd_pcm_t *pcm_capture; + snd_pcm_t *pcm_playback; + snd_pcm_hw_params_t *params; + snd_pcm_uframes_t frames; + int16_t *porcbuf; + + mpg123_handle *mh; + + mp3_done_cb done_cb; + void *opaque; + + int mode; + int rate; + + int porc_spf; + int filefd; + int rpos; + int wpos; + int porcpos; + int npos; + int times; + int quietcount; + int anycount; + + int wplay; + int rplay; + + char last_wake_detect; + char destroy_mh_on_drain; +}; + +static struct raw_vhd *avhd; + +/* + * called from alexa.c to grab the next chunk of audio capture buffer + * for upload + */ + +int +spool_capture(uint8_t *buf, size_t len) +{ + int16_t *sam = (int16_t *)buf; + size_t s, os; + + if (avhd->mode != MODE_CAPTURING) + return -1; + + os = s = len / 2; + + while (s && avhd->wpos != avhd->npos) { + *sam++ = avhd->p[avhd->npos]; + avhd->npos = (avhd->npos + 1) % LWS_ARRAY_SIZE(avhd->p); + s--; + } + + lwsl_info("Copied %d samples (%d %d)\n", (int)(os - s), + avhd->wpos, avhd->npos); + + return (os - s) * 2; +} + +/* + * Called from alexa.c to control when the mp3 playback should begin and end + */ + +int +play_mp3(mpg123_handle *mh, mp3_done_cb cb, void *opaque) +{ + if (mh) { + avhd->mh = mh; + avhd->mode = MODE_PLAYING; + snd_pcm_prepare(avhd->pcm_playback); + + return 0; + } + + avhd->destroy_mh_on_drain = 1; + avhd->done_cb = cb; + avhd->opaque = opaque; + + return 0; +} + +/* + * Helper used to set alsa hwparams on both capture and playback channels + */ + +static int +set_hw_params(struct lws_vhost *vh, snd_pcm_t **pcm, int type) +{ + unsigned int rate = pv_sample_rate(); /* it's 16kHz */ + snd_pcm_hw_params_t *params; + lws_sock_file_fd_type u; + struct pollfd pfd; + struct lws *wsi1; + int n; + + n = snd_pcm_open(pcm, "default", type, SND_PCM_NONBLOCK); + if (n < 0) { + lwsl_err("%s: Can't open default for playback: %s\n", + __func__, snd_strerror(n)); + + return -1; + } + + if (snd_pcm_poll_descriptors(*pcm, &pfd, 1) != 1) { + lwsl_err("%s: failed to get playback desc\n", __func__); + return -1; + } + + u.filefd = (lws_filefd_type)(long long)pfd.fd; + wsi1 = lws_adopt_descriptor_vhost(vh, LWS_ADOPT_RAW_FILE_DESC, u, + "lws-audio-test", NULL); + if (!wsi1) { + lwsl_err("%s: Failed to adopt playback desc\n", __func__); + goto bail; + } + if (type == SND_PCM_STREAM_PLAYBACK) + lws_rx_flow_control(wsi1, 0); /* no POLLIN */ + + snd_pcm_hw_params_malloc(¶ms); + snd_pcm_hw_params_any(*pcm, params); + + n = snd_pcm_hw_params_set_access(*pcm, params, + SND_PCM_ACCESS_RW_INTERLEAVED); + if (n < 0) + goto bail1; + + n = snd_pcm_hw_params_set_format(*pcm, params, SND_PCM_FORMAT_S16_LE); + if (n < 0) + goto bail1; + + n = snd_pcm_hw_params_set_channels(*pcm, params, 1); + if (n < 0) + goto bail1; + + n = snd_pcm_hw_params_set_rate_near(*pcm, params, &rate, 0); + if (n < 0) + goto bail1; + + lwsl_notice("%s: %s rate %d\n", __func__, + type == SND_PCM_STREAM_PLAYBACK ? "Playback" : "Capture", rate); + + n = snd_pcm_hw_params(*pcm, params); + snd_pcm_hw_params_free(params); + if (n < 0) + goto bail; + + return 0; + +bail1: + snd_pcm_hw_params_free(params); +bail: + lwsl_err("%s: Set hw params failed: %s\n", __func__, snd_strerror(n)); + + return -1; +} + +/* + * The lws RAW file protocol handler that wraps ALSA. + * + * The timing is coming from ALSA capture channel... since they are both set to + * 16kHz, it's enough just to have the one. + */ + +static int +callback_audio(struct lws *wsi, enum lws_callback_reasons reason, void *user, + void *in, size_t len) +{ + struct raw_vhd *vhd = (struct raw_vhd *)lws_protocol_vh_priv_get( + lws_get_vhost(wsi), lws_get_protocol(wsi)); + uint16_t rands[50]; + int16_t temp[256]; + bool det; + long avg; + int n, s; + + switch (reason) { + case LWS_CALLBACK_PROTOCOL_INIT: + + if (avhd) /* just on one vhost */ + return 0; + + avhd = vhd = lws_protocol_vh_priv_zalloc(lws_get_vhost(wsi), + lws_get_protocol(wsi), sizeof(struct raw_vhd)); + + /* + * Set up the wakeword library + */ + + n = pv_porcupine_init("porcupine_params.pv", "alexa_linux.ppn", + 1.0, &vhd->porc); + if (n) { + lwsl_err("%s: porcupine init fail %d\n", __func__, n); + + return -1; + } + vhd->porc_spf = pv_porcupine_frame_length(); + vhd->porcbuf = malloc(vhd->porc_spf * 2); + lwsl_info("%s: %s porc frame length is %d samples\n", __func__, + lws_get_vhost_name(lws_get_vhost(wsi)), + vhd->porc_spf); + + vhd->rate = pv_sample_rate(); /* 16kHz */ + + /* set up alsa */ + + if (set_hw_params(lws_get_vhost(wsi), &vhd->pcm_playback, + SND_PCM_STREAM_PLAYBACK)) { + lwsl_err("%s: Can't open default for playback\n", + __func__); + + return -1; + } + + if (set_hw_params(lws_get_vhost(wsi), &vhd->pcm_capture, + SND_PCM_STREAM_CAPTURE)) { + lwsl_err("%s: Can't open default for capture\n", + __func__); + + return -1; + } + + snd_config_update_free_global(); + + break; + + case LWS_CALLBACK_PROTOCOL_DESTROY: + lwsl_info("%s: LWS_CALLBACK_PROTOCOL_DESTROY\n", __func__); + if (!vhd) + break; + + if (vhd->porcbuf) { + free(vhd->porcbuf); + vhd->porcbuf = NULL; + } + if (vhd->pcm_playback) { + snd_pcm_drop(vhd->pcm_playback); + snd_pcm_close(vhd->pcm_playback); + vhd->pcm_playback = NULL; + } + if (vhd->pcm_capture) { + snd_pcm_drop(vhd->pcm_capture); + snd_pcm_close(vhd->pcm_capture); + vhd->pcm_capture = NULL; + } + if (vhd->porc) { + pv_porcupine_delete(vhd->porc); + vhd->porc = NULL; + } + + /* avoid most of the valgrind mess from alsa */ + snd_config_update_free_global(); + + break; + + case LWS_CALLBACK_RAW_CLOSE_FILE: + lwsl_info("%s: closed\n", __func__); + break; + + case LWS_CALLBACK_RAW_RX_FILE: + /* we come here about every 250ms */ + + /* + * Playing back the mp3? + */ + if (vhd->mode == MODE_PLAYING && vhd->mh) { + size_t amt, try; + + do { + try = snd_pcm_avail(vhd->pcm_playback); + if (try > LWS_ARRAY_SIZE(vhd->p)) + try = LWS_ARRAY_SIZE(vhd->p); + + n = mpg123_read(vhd->mh, (uint8_t *)vhd->p, + try * 2, &amt); + lwsl_info("%s: PLAYING: mpg123 read %d, n %d\n", + __func__, (int)amt, n); + if (n == MPG123_NEW_FORMAT) { + snd_pcm_start(vhd->pcm_playback); + memset(vhd->p, 0, try); + snd_pcm_writei(vhd->pcm_playback, + vhd->p, try / 2); + snd_pcm_prepare(vhd->pcm_playback); + } + } while (n == MPG123_NEW_FORMAT); + + if (amt) { + n = snd_pcm_writei(vhd->pcm_playback, + vhd->p, amt / 2); + if (n < 0) + lwsl_notice("%s: snd_pcm_writei: %d %s\n", + __func__, n, snd_strerror(n)); + if (n == -EPIPE) { + lwsl_err("%s: did EPIPE prep\n", __func__); + snd_pcm_prepare(vhd->pcm_playback); + } + } else + if (vhd->destroy_mh_on_drain && + n != MPG123_NEW_FORMAT) { + snd_pcm_drain(vhd->pcm_playback); + vhd->destroy_mh_on_drain = 0; + lwsl_notice("%s: mp3 destroyed\n", + __func__); + mpg123_close(vhd->mh); + mpg123_delete(vhd->mh); + vhd->mh = NULL; + vhd->mode = MODE_IDLE; + + if (vhd->done_cb) + vhd->done_cb(vhd->opaque); + } + } + + /* + * Get the capture data + */ + + n = snd_pcm_readi(vhd->pcm_capture, temp, LWS_ARRAY_SIZE(temp)); + s = 0; + while (s < n) { + vhd->p[(vhd->wpos + s) % LWS_ARRAY_SIZE(vhd->p)] = temp[s]; + s++; + } + + if (vhd->mode == MODE_CAPTURING) { + + /* + * We are recording an utterance. + * + * Estimate the sound density in the frame by picking 50 + * samples at random and averaging the sampled + * [abs()^2] / 10000 to create a Figure of Merit. + * + * Speaking on my laptop gets us 1000 - 5000, silence + * is typ under 30. The wakeword tells us there was + * speech at the start, end the capture when there's + * ~750ms (12000 samples) under 125 FOM. + */ + +#define SILENCE_THRESH 125 + + avg = 0; + lws_get_random(lws_get_context(wsi), rands, sizeof(rands)); + for (s = 0; s < (int)LWS_ARRAY_SIZE(rands); s++) { + long q; + + q = temp[rands[s] % n]; + + avg += (q * q); + } + avg = (avg / (int)LWS_ARRAY_SIZE(rands)) / 10000; + + lwsl_notice("est audio energy: %ld %d\n", avg, vhd->mode); + + /* + * Only start looking for "silence" after 1.5s, in case + * he does a long pause after the wakeword + */ + + if (vhd->anycount < (3 *vhd->rate) / 2 && + avg < SILENCE_THRESH) { + vhd->quietcount += n; + /* then 500ms of "silence" does it for us */ + if (vhd->quietcount >= ((vhd->rate * 3) / 4)) { + lwsl_warn("%s: ended capture\n", __func__); + vhd->mode = MODE_IDLE; + vhd->quietcount = 0; + } + } + + /* if we're not "silent", reset the count */ + if (avg > SILENCE_THRESH * 2) + vhd->quietcount = 0; + + /* + * Since we are in capturing mode, we have something + * new to send now. + * + * We must send an extra one at the end so we can finish + * the tx. + */ + lws_ss_request_tx(hss_avs_sync); + } + + /* + * Just waiting for a wakeword + */ + + while (vhd->mode == MODE_IDLE) { + int m = 0, ppold = vhd->porcpos; + + s = (vhd->wpos - vhd->porcpos) % LWS_ARRAY_SIZE(vhd->p); + if (s < vhd->porc_spf) + goto eol; + + while (m < vhd->porc_spf) { + vhd->porcbuf[m++] = avhd->p[vhd->porcpos]; + vhd->porcpos = (vhd->porcpos + 1) % + LWS_ARRAY_SIZE(vhd->p); + } + + if (pv_porcupine_process(vhd->porc, vhd->porcbuf, &det)) + lwsl_err("%s: porc_process failed\n", __func__); + + if (!det && vhd->last_wake_detect && + vhd->mode == MODE_IDLE) { + lwsl_warn("************* Wakeword\n"); + if (!avs_query_start(lws_get_context(wsi))) { + vhd->mode = MODE_CAPTURING; + vhd->quietcount = 0; + vhd->last_wake_detect = det; + vhd->npos = ppold; + break; + } + } + vhd->last_wake_detect = det; + } + +eol: + vhd->wpos = (vhd->wpos + n) % LWS_ARRAY_SIZE(vhd->p); + break; + + default: + break; + } + + return 0; +} + +struct lws_protocols protocol_audio_test = + { "lws-audio-test", callback_audio, 0, 0 }; diff -Nru libwebsockets-3.2.1/minimal-examples/secure-streams/minimal-secure-streams-alexa/CMakeLists.txt libwebsockets-4.1.6/minimal-examples/secure-streams/minimal-secure-streams-alexa/CMakeLists.txt --- libwebsockets-3.2.1/minimal-examples/secure-streams/minimal-secure-streams-alexa/CMakeLists.txt 1970-01-01 00:00:00.000000000 +0000 +++ libwebsockets-4.1.6/minimal-examples/secure-streams/minimal-secure-streams-alexa/CMakeLists.txt 2020-12-01 17:40:26.000000000 +0000 @@ -0,0 +1,43 @@ +project(lws-minimal-secure-streams-alexa C) +cmake_minimum_required(VERSION 2.8) +find_package(libwebsockets CONFIG REQUIRED) +list(APPEND CMAKE_MODULE_PATH ${LWS_CMAKE_DIR}) +include(CheckCSourceCompiles) +include(LwsCheckRequirements) + +set(SAMP lws-minimal-secure-streams-alexa) +set(SRCS main.c alexa.c audio.c) + +set(requirements 1) +require_lws_config(LWS_ROLE_H1 1 requirements) +require_lws_config(LWS_WITHOUT_CLIENT 0 requirements) +require_lws_config(LWS_WITH_SECURE_STREAMS 1 requirements) +require_lws_config(LWS_WITH_SECURE_STREAMS_STATIC_POLICY_ONLY 0 requirements) +require_lws_config(LWS_WITH_ALSA 1 requirements) +require_lws_config(LWS_WITH_SYS_STATE 1 requirements) + +if (requirements) + add_executable(${SAMP} ${SRCS}) + + if (websockets_shared) + target_link_libraries(${SAMP} websockets_shared asound pv_porcupine mpg123 ${LIBWEBSOCKETS_DEP_LIBS}) + add_dependencies(${SAMP} websockets_shared) + else() + target_link_libraries(${SAMP} websockets asound pv_porcupine mpg123 ${LIBWEBSOCKETS_DEP_LIBS}) + endif() + + CHECK_C_SOURCE_COMPILES("#include \nint main(void) {\ni#if defined(LWS_WITH_SECURE_STREAMS_PROXY_API)\n return 0;\n #else\n fail\n #endif\n return 0;\n}\n" HAS_LWS_WITH_SECURE_STREAMS_PROXY_API) + + if (HAS_LWS_WITH_SECURE_STREAMS_PROXY_API OR LWS_WITH_SECURE_STREAMS_PROXY_API) + add_compile_options(-DLWS_SS_USE_SSPC) + + add_executable(${SAMP}-client ${SRCS}) + if (websockets_shared) + target_link_libraries(${SAMP}-client websockets_shared asound pv_porcupine mpg123 ${LIBWEBSOCKETS_DEP_LIBS}) + add_dependencies(${SAMP}-client websockets_shared) + else() + target_link_libraries(${SAMP}-client websockets asound pv_porcupine mpg123 ${LIBWEBSOCKETS_DEP_LIBS}) + endif() + endif() + +endif() diff -Nru libwebsockets-3.2.1/minimal-examples/secure-streams/minimal-secure-streams-alexa/main.c libwebsockets-4.1.6/minimal-examples/secure-streams/minimal-secure-streams-alexa/main.c --- libwebsockets-3.2.1/minimal-examples/secure-streams/minimal-secure-streams-alexa/main.c 1970-01-01 00:00:00.000000000 +0000 +++ libwebsockets-4.1.6/minimal-examples/secure-streams/minimal-secure-streams-alexa/main.c 2020-12-01 17:40:26.000000000 +0000 @@ -0,0 +1,420 @@ +/* + * lws-minimal-secure-streams-alexa + * + * This file is made available under the Creative Commons CC0 1.0 + * Universal Public Domain Dedication. + */ + +#include +#include +#include + +extern int +avs_example_start(struct lws_context *context); + +static int interrupted; +static lws_state_notify_link_t nl; + +#if !defined(LWS_SS_USE_SSPC) + +/* + * If not using the proxy, we need to bring our own policy + */ + +static const char * const default_ss_policy = + "{" + "\"release\":" "\"01234567\"," + "\"product\":" "\"myproduct\"," + "\"schema-version\":" "1," + "\"retry\": [" /* named backoff / retry strategies */ + "{\"default\": {" + "\"backoff\": [" "1000," + "2000," + "3000," + "5000," + "10000" + "]," + "\"conceal\":" "5," + "\"jitterpc\":" "20," + "\"svalidping\":" "60," + "\"svalidhup\":" "64" + "}}" + "]," + "\"certs\": [" /* named individual certificates in BASE64 DER */ + "{\"digicert_global_root_g2\": \"" /* api.amazon.com 2038-01 */ + "MIIDjjCCAnagAwIBAgIQAzrx5qcRqaC7KGSxHQn65TANBgkqhkiG9w0BAQsFADBh" + "MQswCQYDVQQGEwJVUzEVMBMGA1UEChMMRGlnaUNlcnQgSW5jMRkwFwYDVQQLExB3" + "d3cuZGlnaWNlcnQuY29tMSAwHgYDVQQDExdEaWdpQ2VydCBHbG9iYWwgUm9vdCBH" + "MjAeFw0xMzA4MDExMjAwMDBaFw0zODAxMTUxMjAwMDBaMGExCzAJBgNVBAYTAlVT" + "MRUwEwYDVQQKEwxEaWdpQ2VydCBJbmMxGTAXBgNVBAsTEHd3dy5kaWdpY2VydC5j" + "b20xIDAeBgNVBAMTF0RpZ2lDZXJ0IEdsb2JhbCBSb290IEcyMIIBIjANBgkqhkiG" + "9w0BAQEFAAOCAQ8AMIIBCgKCAQEAuzfNNNx7a8myaJCtSnX/RrohCgiN9RlUyfuI" + "2/Ou8jqJkTx65qsGGmvPrC3oXgkkRLpimn7Wo6h+4FR1IAWsULecYxpsMNzaHxmx" + "1x7e/dfgy5SDN67sH0NO3Xss0r0upS/kqbitOtSZpLYl6ZtrAGCSYP9PIUkY92eQ" + "q2EGnI/yuum06ZIya7XzV+hdG82MHauVBJVJ8zUtluNJbd134/tJS7SsVQepj5Wz" + "tCO7TG1F8PapspUwtP1MVYwnSlcUfIKdzXOS0xZKBgyMUNGPHgm+F6HmIcr9g+UQ" + "vIOlCsRnKPZzFBQ9RnbDhxSJITRNrw9FDKZJobq7nMWxM4MphQIDAQABo0IwQDAP" + "BgNVHRMBAf8EBTADAQH/MA4GA1UdDwEB/wQEAwIBhjAdBgNVHQ4EFgQUTiJUIBiV" + "5uNu5g/6+rkS7QYXjzkwDQYJKoZIhvcNAQELBQADggEBAGBnKJRvDkh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py" + "rqXRfboQnoZsG4q5WTP468SQvvG5" + "\"}," + "{\"starfield_services_root_ca\": \"" + "MIID7zCCAtegAwIBAgIBADANBgkqhkiG9w0BAQsFADCBmDELMAkGA1UEBhMCVVMx" + "EDAOBgNVBAgTB0FyaXpvbmExEzARBgNVBAcTClNjb3R0c2RhbGUxJTAjBgNVBAoT" + "HFN0YXJmaWVsZCBUZWNobm9sb2dpZXMsIEluYy4xOzA5BgNVBAMTMlN0YXJmaWVs" + "ZCBTZXJ2aWNlcyBSb290IENlcnRpZmljYXRlIEF1dGhvcml0eSAtIEcyMB4XDTA5" + "MDkwMTAwMDAwMFoXDTM3MTIzMTIzNTk1OVowgZgxCzAJBgNVBAYTAlVTMRAwDgYD" + "VQQIEwdBcml6b25hMRMwEQYDVQQHEwpTY290dHNkYWxlMSUwIwYDVQQKExxTdGFy" + "ZmllbGQgVGVjaG5vbG9naWVzLCBJbmMuMTswOQYDVQQDEzJTdGFyZmllbGQgU2Vy" + "dmljZXMgUm9vdCBDZXJ0aWZpY2F0ZSBBdXRob3JpdHkgLSBHMjCCASIwDQYJKoZI" + "hvcNAQEBBQADggEPADCCAQoCggEBANUMOsQq+U7i9b4Zl1+OiFOxHz/Lz58gE20p" + "OsgPfTz3a3Y4Y9k2YKibXlwAgLIvWX/2h/klQ4bnaRtSmpDhcePYLQ1Ob/bISdm2" + "8xpWriu2dBTrz/sm4xq6HZYuajtYlIlHVv8loJNwU4PahHQUw2eeBGg6345AWh1K" + "Ts9DkTvnVtYAcMtS7nt9rjrnvDH5RfbCYM8TWQIrgMw0R9+53pBlbQLPLJGmpufe" + "hRhJfGZOozptqbXuNC66DQO4M99H67FrjSXZm86B0UVGMpZwh94CDklDhbZsc7tk" + "6mFBrMnUVN+HL8cisibMn1lUaJ/8viovxFUcdUBgF4UCVTmLfwUCAwEAAaNCMEAw" + "DwYDVR0TAQH/BAUwAwEB/zAOBgNVHQ8BAf8EBAMCAQYwHQYDVR0OBBYEFJxfAN+q" + "Adcw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8MC5fvj13c7JdBmzDI1aa" + "K4UmkhynArPkPw2vCHmCuDY96pzTNbO8acr1zJ3o/WSNF4Azbl5KXZnJHoe0nRrA" + "1W4TNSNe35tfPe/W93bC6j67eA0cQmdrBNj41tpvi/JEoAGrAgEDo4HFMIHCMB0G" + "A1UdDgQWBBS/X7fRzt0fhvRbVazc1xDCDqmI5zCBkgYDVR0jBIGKMIGHgBS/X7fR" + "zt0fhvRbVazc1xDCDqmI56FspGowaDELMAkGA1UEBhMCVVMxJTAjBgNVBAoTHFN0" + "YXJmaWVsZCBUZWNobm9sb2dpZXMsIEluYy4xMjAwBgNVBAsTKVN0YXJmaWVsZCBD" + "bGFzcyAyIENlcnRpZmljYXRpb24gQXV0aG9yaXR5ggEAMAwGA1UdEwQFMAMBAf8w" + "DQYJKoZIhvcNAQEFBQADggEBAAWdP4id0ckaVaGsafPzWdqbAYcaT1epoXkJKtv3" + "L7IezMdeatiDh6GX70k1PncGQVhiv45YuApnP+yz3SFmH8lU+nLMPUxA2IGvd56D" + "eruix/U0F47ZEUD0/CwqTRV/p2JdLiXTAAsgGh1o+Re49L2L7ShZ3U0WixeDyLJl" + "xy16paq8U4Zt3VekyvggQQto8PT7dL5WXXp59fkdheMtlb71cZBDzI0fmgAKhynp" + "VSJYACPq4xJDKVtHCN2MQWplBqjlIapBtJUhlbl90TSrE9atvNziPTnNvT51cKEY" + "WQPJIrSPnNVeKtelttQKbfi3QBFGmh95DmK/D5fs4C8fF5Q=" + "\"}" + "]," + "\"trust_stores\": [" /* named cert chains */ + "{" /* chain for alexa.na.gateway.devices.a2z.com */ + "\"name\": \"avs_via_starfield\"," + "\"stack\": [" + "\"starfield_class_2_ca\"," + "\"starfield_services_root_ca\"" + "]" + "}," + "{" /* chain for api.amazon.com */ + "\"name\": \"api_amazon_com\"," + "\"stack\": [" + "\"digicert_global_ca_g2\"," + "\"digicert_global_root_g2\"" + "]" + "}" + "]," + "\"s\": [" /* the supported stream types */ + "{\"api_amazon_com_auth\": {" + "\"endpoint\":" "\"api.amazon.com\"," + "\"port\":" "443," + "\"protocol\":" "\"h1\"," + "\"http_method\":" "\"POST\"," + "\"http_url\":" "\"auth/o2/token\"," + "\"plugins\":" "[]," + "\"opportunistic\":" "true," + "\"tls\":" "true," + "\"h2q_oflow_txcr\":" "true," + "\"http_www_form_urlencoded\":" "true," + "\"http_no_content_length\":" "true," + "\"retry\":" "\"default\"," + "\"tls_trust_store\":" "\"api_amazon_com\"" + "}}," + /* + * long poll event listener + */ + "{\"avs_event\": {" + "\"endpoint\":" "\"alexa.na.gateway.devices.a2z.com\"," + "\"port\":" "443," + "\"protocol\":" "\"h2\"," + "\"http_method\":" "\"GET\"," + "\"http_url\":" "\"v20160207/directives\"," + "\"h2q_oflow_txcr\":" "true," + "\"http_auth_header\":" "\"authorization:\"," + "\"http_auth_preamble\":" "\"Bearer \"," + "\"http_multipart_ss_in\":" "true," + "\"nailed_up\":" "true," + "\"long_poll\":" "true," + "\"retry\":" "\"default\"," + "\"plugins\":" "[]," + "\"tls\":" "true," + "\"tls_trust_store\":" "\"avs_via_starfield\"" + "}}," + /* + * Utterance metadata and audio send and reply processing. + * + * "Rideshare" and http_multipart_mime means these both go out + * in one multipart http transaction. + */ + "{\"avs_metadata\": {" + "\"endpoint\":" "\"alexa.na.gateway.devices.a2z.com\"," + "\"port\":" "443," + "\"protocol\":" "\"h2\"," + "\"http_method\":" "\"POST\"," + "\"http_url\":" "\"v20160207/events\"," + "\"opportunistic\":" "true," + "\"h2q_oflow_txcr\":" "true," + "\"http_auth_header\":" "\"authorization:\"," + "\"http_auth_preamble\":" "\"Bearer \"," + "\"http_multipart_name\":" "\"metadata\"," + "\"http_mime_content_type\":" "\"application/json; charset=UTF-8\"," + "\"http_no_content_length\":" "true," + "\"http_multipart_ss_in\":" "true," + "\"rideshare\":" "\"avs_audio\"," + "\"retry\":" "\"default\"," + "\"plugins\":" "[]," + "\"tls\":" "true," + "\"tls_trust_store\":" "\"avs_via_starfield\"" + "}}," + "{\"avs_audio\": {" + "\"endpoint\":" "\"alexa.na.gateway.devices.a2z.com\"," + "\"port\":" "443," + "\"protocol\":" "\"h2\"," + "\"http_method\":" "\"POST\"," + "\"http_url\":" "\"v20160207/events\"," + "\"plugins\":" "[]," + "\"tls\":" "true," + "\"h2q_oflow_txcr\":" "true," + "\"http_auth_header\":" "\"authorization:\"," + "\"http_auth_preamble\":" "\"Bearer \"," + "\"http_multipart_ss_in\":" "true," + "\"http_multipart_name\":" "\"audio\"," + "\"http_mime_content_type\":" "\"application/octet-stream\"," + "\"http_no_content_length\":" "true," + "\"retry\":" "\"default\"," + "\"tls_trust_store\":" "\"avs_via_starfield\"" + "}}" + "]" + "}" +; + +#endif + +static const char *canned_root_token_payload = + "grant_type=refresh_token" + "&refresh_token=Atzr|IwEBIJedGXjDqsU_vMxykqOMg" + "SHfYe3CPcedueWEMWSDMaDnEmiW8RlR1Kns7Cb4B-TOSnqp7ifVsY4BMY2B8tpHfO39XP" + "zfu9HapGjTR458IyHX44FE71pWJkGZ79uVBpljP4sazJuk8XS3Oe_yLnm_DIO6fU1nU3Y" + "0flYmsOiOAQE_gRk_pdlmEtHnpMA-9rLw3mkY5L89Ty9kUygBsiFaYatouROhbsTn8-jW" + "k1zZLUDpT6ICtBXSnrCIg0pUbZevPFhTwdXd6eX-u4rq0W-XaDvPWFO7au-iPb4Zk5eZE" + "iX6sissYrtNmuEXc2uHu7MnQO1hHCaTdIO2CANVumf-PHSD8xseamyh04sLV5JgFzY45S" + "KvKMajiUZuLkMokOx86rjC2Hdkx5DO7G-dbG1ufBDG-N79pFMSs7Ck5pc283IdLoJkCQc" + "AGvTX8o8I29QqkcGou-9TKhOJmpX8As94T61ok0UqqEKPJ7RhfQHHYdCtsdwxgvfVr9qI" + "xL_hDCcTho8opCVX-6QhJHl6SQFlTw13" + "&client_id=" + "amzn1.application-oa2-client.4823334c434b4190a2b5a42c07938a2d"; + +/* + * Register the root token, and make the sticky AVS connection at the + * appropriate times during system startup + */ + +static int +app_system_state_nf(lws_state_manager_t *mgr, lws_state_notify_link_t *link, + int current, int target) +{ + struct lws_context *context = lws_system_context_from_system_mgr(mgr); + lws_system_blob_t *ab = lws_system_get_blob(context, + LWS_SYSBLOB_TYPE_AUTH, 1 /* AUTH_IDX_ROOT */); + size_t size; + + /* + * For the things we care about, let's notice if we are trying to get + * past them when we haven't solved them yet, and make the system + * state wait while we trigger the dependent action. + */ + switch (target) { + case LWS_SYSTATE_REGISTERED: + size = lws_system_blob_get_size(ab); + if (size) + break; + + /* let's register our canned root token so auth can use it */ + lws_system_blob_direct_set(ab, + (const uint8_t *)canned_root_token_payload, + strlen(canned_root_token_payload)); + break; + case LWS_SYSTATE_OPERATIONAL: + if (current == target) + avs_example_start(context); + break; + case LWS_SYSTATE_POLICY_INVALID: + /* + * This is a NOP since we used direct set... but in a real + * system this could easily change to be done on the heap, then + * this would be important + */ + lws_system_blob_destroy(lws_system_get_blob(context, + LWS_SYSBLOB_TYPE_AUTH, + 1 /* AUTH_IDX_ROOT */)); + break; + } + + return 0; +} + +static void +sigint_handler(int sig) +{ + interrupted = 1; +} + +static lws_state_notify_link_t * const app_notifier_list[] = { + &nl, NULL +}; + +extern struct lws_protocols protocol_audio_test; +static const struct lws_protocols *protocols[] = { + &protocol_audio_test, +#if defined(LWS_SS_USE_SSPC) + lws_sspc_protocols, +#endif + NULL +}; + +int main(int argc, const 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 */ + lws_cmdline_option_handle_builtin(argc, argv, &info); + + lwsl_user("LWS secure streams - Alexa voice test [-d]\n"); + + info.fd_limit_per_thread = 1 + 6 + 1; +#if !defined(LWS_SS_USE_SSPC) + info.options = LWS_SERVER_OPTION_EXPLICIT_VHOSTS | + LWS_SERVER_OPTION_DO_SSL_GLOBAL_INIT; + info.pss_policies_json = default_ss_policy; +#else + { + const char *p; + + /* connect to ssproxy via UDS by default, else via + * tcp connection to this port */ + if ((p = lws_cmdline_option(argc, argv, "-p"))) + info.ss_proxy_port = atoi(p); + + /* UDS "proxy.ss.lws" in abstract namespace, else this socket + * path; when -p given this can specify the network interface + * to bind to */ + if ((p = lws_cmdline_option(argc, argv, "-i"))) + info.ss_proxy_bind = p; + + /* if -p given, -a specifies the proxy address to connect to */ + if ((p = lws_cmdline_option(argc, argv, "-a"))) + info.ss_proxy_address = p; + } +#endif + info.port = CONTEXT_PORT_NO_LISTEN; + info.pprotocols = protocols; + +#if defined(LWS_WITH_DETAILED_LATENCY) + info.detailed_latency_cb = lws_det_lat_plot_cb; + info.detailed_latency_filepath = "/tmp/lws-latency-ssproxy"; +#endif + + /* integrate us with lws system state management when context created */ + nl.name = "app"; + nl.notify_cb = app_system_state_nf; + info.register_notifier_list = app_notifier_list; + + context = lws_create_context(&info); + if (!context) { + lwsl_err("lws init failed\n"); + return 1; + } + + /* create an explicit vhost so the sound protocol is initialized */ + + info.vhost_name = "asound"; + if (!lws_create_vhost(context, &info)) { + lwsl_err("lws init failed\n"); + goto bail; + } + + /* the event loop */ + + while (n >= 0 && !interrupted) + n = lws_service(context, 0); + +bail: + lws_context_destroy(context); + lwsl_user("Completed\n"); + + return 0; +} Binary files /tmp/tmp2l8bmswe/3lv7Sxvgkv/libwebsockets-3.2.1/minimal-examples/secure-streams/minimal-secure-streams-alexa/porcupine_params.pv and /tmp/tmp2l8bmswe/LwTwoWz49Q/libwebsockets-4.1.6/minimal-examples/secure-streams/minimal-secure-streams-alexa/porcupine_params.pv differ diff -Nru libwebsockets-3.2.1/minimal-examples/secure-streams/minimal-secure-streams-alexa/private.h libwebsockets-4.1.6/minimal-examples/secure-streams/minimal-secure-streams-alexa/private.h --- libwebsockets-3.2.1/minimal-examples/secure-streams/minimal-secure-streams-alexa/private.h 1970-01-01 00:00:00.000000000 +0000 +++ libwebsockets-4.1.6/minimal-examples/secure-streams/minimal-secure-streams-alexa/private.h 2020-12-01 17:40:26.000000000 +0000 @@ -0,0 +1,8 @@ +typedef int (*mp3_done_cb)(void *opaque); + +int +play_mp3(mpg123_handle *mh, mp3_done_cb cb, void *opaque); + + +int +spool_capture(uint8_t *buf, size_t len); diff -Nru libwebsockets-3.2.1/minimal-examples/secure-streams/minimal-secure-streams-alexa/README.md libwebsockets-4.1.6/minimal-examples/secure-streams/minimal-secure-streams-alexa/README.md --- libwebsockets-3.2.1/minimal-examples/secure-streams/minimal-secure-streams-alexa/README.md 1970-01-01 00:00:00.000000000 +0000 +++ libwebsockets-4.1.6/minimal-examples/secure-streams/minimal-secure-streams-alexa/README.md 2020-12-01 17:40:26.000000000 +0000 @@ -0,0 +1,77 @@ +# lws secure streams alexa + +This demonstrates AVS Alexa usage using secure streams. It connects to AVS, +uses your linux computer's microphone to wait for the 'alexa' wakeword, sends +the utterance to AVS and plays back the result. + +## build + +There are some special build considerations: + +1) Build lws with cmake options `-DLWS_WITH_ALSA=1 -DLWS_WITH_SECURE_STREAMS=1` + +2) Install distro build dependency packages: + + |Dependency|Ubuntu package|Fedora Package| + |---|---|---| + |libasound|libasound2-dev|alsa-lib-devel| + |mpg123|libmpg123-dev|mpg123-devel| + +3) Clone Picovoice Porcupine Apache-licensed demo version from here + + https://github.com/Picovoice/porcupine + + It provides binary libs for wakeword detection on various platforms. Copy + the headers and binary lib to your build context, eg, for native x86_64 + +``` + $ sudo cp ./include/* /usr/include + $ sudo cp ./lib/linux/x86_64/libpv_porcupine.* /usr/lib + $ sudo ldconfig +``` + + Enter the minimal example dir for secure-streams-alexa and make the sample + +``` + $ cd ./minimal-examples/secure-streams/minimal-secure-streams-alexa + $ cmake . + $ make +``` + +## usage + +``` + $ ./lws-minimal-secure-streams-alexa +[2019/10/16 16:22:01:1097] U: LWS secure streams - Alex voice test [-d] +[2019/10/16 16:22:01:1115] N: lws_create_context: creating Secure Streams policy +[2019/10/16 16:22:01:1115] N: lwsac_use: alloc 1532 for 1 +[2019/10/16 16:22:01:1119] N: lwsac_use: alloc 288 for 168 +[2019/10/16 16:22:01:1119] N: lws_ss_policy_set: policy lwsac size: 1.796KiB, pad 11% +[2019/10/16 16:22:02:4114] N: lws_ss_client_connect: connecting 0 api.amazon.com /auth/o2/token +[2019/10/16 16:22:02:8686] N: auth_api_amazon_com_parser_cb: expires in 3600 +[2019/10/16 16:22:02:8686] N: ss_api_amazon_auth_rx: acquired 656-byte api.amazon.com auth token +[2019/10/16 16:22:02:8754] N: lws_ss_client_connect: connecting 1 alexa.na.gateway.devices.a2z.com /v20160207/directives +[2019/10/16 16:22:02:3182] N: secstream_h2: h2 client entering LONG_POLL +[2019/10/16 16:22:02:3183] U: Connected to Alexa... speak "Alexa, ..." +[2019/10/16 16:22:06:9380] W: ************* Wakeword +[2019/10/16 16:22:06:9380] N: avs_query_start: +[2019/10/16 16:22:06:9381] N: lws_ss_client_connect: connecting 1 alexa.na.gateway.devices.a2z.com /v20160207/events +[2019/10/16 16:22:06:9381] N: lws_vhost_active_conns: just join h2 directly +[2019/10/16 16:22:06:9384] N: metadata done +[2019/10/16 16:22:06:1524] N: est: 42 1 +[2019/10/16 16:22:06:3723] N: est: 108 1 +[2019/10/16 16:22:07:5914] N: est: 352 1 +[2019/10/16 16:22:07:8112] N: est: 4284 1 +[2019/10/16 16:22:07:0300] N: est: 3369 1 +[2019/10/16 16:22:07:2325] N: est: 577 1 +[2019/10/16 16:22:08:4519] N: est: 9 1 +[2019/10/16 16:22:08:6716] N: est: 3 1 +[2019/10/16 16:22:08:6718] N: est: 11 1 +[2019/10/16 16:22:08:8915] N: est: 10 1 +[2019/10/16 16:22:08:8915] W: callback_audio: ended capture +[2019/10/16 16:22:09:0993] N: identified reply... +^C[2019/10/16 16:22:14:3067] U: Disconnected from Alexa +[2019/10/16 16:22:14:3123] U: Completed +$ + +``` diff -Nru libwebsockets-3.2.1/minimal-examples/secure-streams/minimal-secure-streams-avs/avs.c libwebsockets-4.1.6/minimal-examples/secure-streams/minimal-secure-streams-avs/avs.c --- libwebsockets-3.2.1/minimal-examples/secure-streams/minimal-secure-streams-avs/avs.c 1970-01-01 00:00:00.000000000 +0000 +++ libwebsockets-4.1.6/minimal-examples/secure-streams/minimal-secure-streams-avs/avs.c 2020-12-01 17:40:26.000000000 +0000 @@ -0,0 +1,430 @@ +/* + * lws-minimal-secure-streams-avs + * + * Written in 2019-2020 by Andy Green + * + * This file is made available under the Creative Commons CC0 1.0 + * Universal Public Domain Dedication. + * + * This sends a canned WAV and received (and discards) the mp3 response. + * However it rate-limits the response reception to manage a small ringbuffer + * using ss / h2 flow control apis, reflecting consumption at 64kbps and only + * and 8KB buffer, indtended to model optimizing rx buffering on mp3 playback + * on a constrained device. + */ + +#include +#include +#include +#include +#if !defined(WIN32) +#include +#endif +#include +#include + +extern int interrupted, bad; +static struct lws_ss_handle *hss_avs_event, *hss_avs_sync; +static uint8_t *wav; +static size_t wav_len; + +typedef struct ss_avs_event { + struct lws_ss_handle *ss; + void *opaque_data; + /* ... application specific state ... */ + struct lejp_ctx jctx; +} ss_avs_event_t; + +typedef struct ss_avs_metadata { + struct lws_ss_handle *ss; + void *opaque_data; + /* ... application specific state ... */ + struct lejp_ctx jctx; + size_t pos; + + /* + * We simulate a ringbuffer that is used up by a sul at 64Kbit/sec + * rate, and managed at the same rate using tx credit + */ + + lws_sorted_usec_list_t sul; + uint8_t buf[256 * 1024]; /* to test rate-limiting, set to 8 * 1024 */ + int head; + int tail; + + char filled; + +} ss_avs_metadata_t; + +static const char *metadata = "{" + "\"event\": {" + "\"header\": {" + "\"namespace\": \"SpeechRecognizer\"," + "\"name\": \"Recognize\"," + "\"messageId\": \"message-123\"," + "\"dialogRequestId\": \"dialog-request-321\"" + "}," + "\"payload\": {" + "\"profile\":" "\"CLOSE_TALK\"," + "\"format\":" "\"AUDIO_L16_RATE_16000_CHANNELS_1\"" + "}" + "}" +"}"; + +/* + * avs metadata + */ + +static void +use_buffer_50ms(lws_sorted_usec_list_t *sul) +{ + ss_avs_metadata_t *m = lws_container_of(sul, ss_avs_metadata_t, sul); + struct lws_context *context = (struct lws_context *)m->opaque_data; + size_t n; + int e; + + /* + * Use up 50ms-worth (8KB / 20) == 401 bytes of buffered data + */ + + /* remaining data in buffer */ + n = ((m->head - m->tail) % sizeof(m->buf)); + lwsl_info("%s: avail %d\n", __func__, (int)n); + + if (n < 401) + lwsl_err("%s: underrun\n", __func__); + + m->tail = (m->tail + 401) % sizeof(m->buf); + n = ((m->head - m->tail) % sizeof(m->buf)); + + e = lws_ss_get_est_peer_tx_credit(m->ss); + + lwsl_info("%s: avail after: %d, curr est %d\n", __func__, (int)n, e); + + if (n < (sizeof(m->buf) * 2) / 3 && e < (int)(sizeof(m->buf) - 1 - n)) { + lwsl_info("%s: requesting additional %d\n", __func__, + (int)(sizeof(m->buf) - 1 - e - n)); + lws_ss_add_peer_tx_credit(m->ss, (int32_t)(sizeof(m->buf) - 1 - e - n)); + } + + lws_sul_schedule(context, 0, &m->sul, use_buffer_50ms, + 50 * LWS_US_PER_MS); +} + +static int +ss_avs_metadata_rx(void *userobj, const uint8_t *buf, size_t len, int flags) +{ + ss_avs_metadata_t *m = (ss_avs_metadata_t *)userobj; + struct lws_context *context = (struct lws_context *)m->opaque_data; + size_t n, n1; + + lwsl_notice("%s: rideshare %s, len %d, flags 0x%x\n", __func__, + lws_ss_rideshare(m->ss), (int)len, flags); +#if 0 + lwsl_hexdump_warn(buf, len); +#endif + + n = sizeof(m->buf) - ((m->head - m->tail) % sizeof(m->buf)); + lwsl_info("%s: len %d, buf h %d, t %d, space %d\n", __func__, + (int)len, (int)m->head, (int)m->tail, (int)n); + lws_ss_get_est_peer_tx_credit(m->ss); + if (len > n) { + lwsl_err("%s: bad len: len %d, n %d\n", __func__, (int)len, (int)n); + assert(0); + + return 1; + } + + if (m->head < m->tail) /* |****h-------t**| */ + memcpy(&m->buf[m->head], buf, len); + else { /* |---t*****h-----| */ + n1 = sizeof(m->buf) - m->head; + if (len < n1) + n1 = len; + memcpy(&m->buf[m->head], buf, n1); + if (n1 != len) + memcpy(m->buf, buf, len - n1); + } + + m->head = (m->head + len) % sizeof(m->buf); + + lws_sul_schedule(context, 0, &m->sul, use_buffer_50ms, + 50 * LWS_US_PER_MS); + + return 0; +} + +static int +ss_avs_metadata_tx(void *userobj, lws_ss_tx_ordinal_t ord, uint8_t *buf, + size_t *len, int *flags) +{ + ss_avs_metadata_t *m = (ss_avs_metadata_t *)userobj; + //struct lws_context *context = (struct lws_context *)m->opaque_data; + size_t tot; + + if ((long)m->pos < 0) { + *len = 0; + lwsl_debug("%s: skip tx\n", __func__); + return 1; + } + +// lwsl_notice("%s: rideshare '%s'\n", __func__, lws_ss_rideshare(m->ss)); + + if (!strcmp(lws_ss_rideshare(m->ss), "avs_audio")) { + /* audio rideshare */ + + if (!m->pos) + *flags |= LWSSS_FLAG_SOM; + + if (*len > wav_len - m->pos) + *len = wav_len - m->pos; + + memcpy(buf, wav + m->pos, *len); + m->pos += *len; + + if (m->pos == wav_len) { + *flags |= LWSSS_FLAG_EOM; + lwsl_info("%s: tx done\n", __func__); + m->pos = (long)-1l; /* ban subsequent until new stream */ + } else + lws_ss_request_tx(m->ss); + + lwsl_hexdump_info(buf, *len); + + return 0; + } + + /* metadata part */ + + tot = strlen(metadata); + + if (!m->pos) + *flags |= LWSSS_FLAG_SOM; + + if (*len > tot - m->pos) + *len = tot - m->pos; + + memcpy(buf, metadata + m->pos, *len); + + m->pos += *len; + + if (m->pos == tot) { + *flags |= LWSSS_FLAG_EOM; + m->pos = 0; /* for next time */ + lws_ss_request_tx(m->ss); + } + + lwsl_hexdump_info(buf, *len); + + return 0; +} + +static int +ss_avs_metadata_state(void *userobj, void *sh, + lws_ss_constate_t state, lws_ss_tx_ordinal_t ack) +{ + + ss_avs_metadata_t *m = (ss_avs_metadata_t *)userobj; + // struct lws_context *context = (struct lws_context *)m->opaque_data; + + lwsl_user("%s: %s, ord 0x%x\n", __func__, lws_ss_state_name(state), + (unsigned int)ack); + + switch (state) { + case LWSSSCS_CREATING: + lwsl_user("%s: CREATING\n", __func__); + lws_ss_client_connect(m->ss); + m->pos = 0; + break; + case LWSSSCS_CONNECTING: + break; + case LWSSSCS_CONNECTED: + lws_ss_request_tx(m->ss); + break; + case LWSSSCS_ALL_RETRIES_FAILED: + /* for this demo app, we want to exit on fail to connect */ + case LWSSSCS_DISCONNECTED: + /* for this demo app, we want to exit after complete flow */ + lws_sul_cancel(&m->sul); + interrupted = 1; + break; + case LWSSSCS_DESTROYING: + lws_sul_cancel(&m->sul); + break; + default: + break; + } + + return 0; +} + +/* + * avs event + */ + +static int +ss_avs_event_rx(void *userobj, const uint8_t *buf, size_t len, int flags) +{ + ss_avs_event_t *m = (ss_avs_event_t *)userobj; + // struct lws_context *context = (struct lws_context *)m->opaque_data; + + lwsl_notice("%s: rideshare %s, len %d, flags 0x%x\n", __func__, + lws_ss_rideshare(m->ss), (int)len, flags); + +// lwsl_hexdump_warn(buf, len); + + bad = 0; /* for this demo, receiving something here == success */ + + return 0; +} + +static int +ss_avs_event_tx(void *userobj, lws_ss_tx_ordinal_t ord, uint8_t *buf, + size_t *len, int *flags) +{ + ss_avs_event_t *m = (ss_avs_event_t *)userobj; + lwsl_notice("%s: rideshare %s\n", __func__, lws_ss_rideshare(m->ss)); + + return 1; /* don't transmit anything */ +} + +static int +ss_avs_event_state(void *userobj, void *sh, + lws_ss_constate_t state, lws_ss_tx_ordinal_t ack) +{ + ss_avs_event_t *m = (ss_avs_event_t *)userobj; + struct lws_context *context = (struct lws_context *)m->opaque_data; + lws_ss_info_t ssi; + + lwsl_user("%s: %s, ord 0x%x\n", __func__, lws_ss_state_name(state), + (unsigned int)ack); + + switch (state) { + case LWSSSCS_CREATING: + case LWSSSCS_CONNECTING: + break; + case LWSSSCS_CONNECTED: + if (hss_avs_sync) + break; + + lwsl_notice("%s: starting the second avs stream\n", __func__); + + /* + * When we have established the event stream, we must POST + * on another stream within 10s + */ + + memset(&ssi, 0, sizeof(ssi)); + ssi.handle_offset = offsetof(ss_avs_metadata_t, ss); + ssi.opaque_user_data_offset = offsetof(ss_avs_metadata_t, + opaque_data); + ssi.rx = ss_avs_metadata_rx; + ssi.tx = ss_avs_metadata_tx; + ssi.state = ss_avs_metadata_state; + ssi.user_alloc = sizeof(ss_avs_metadata_t); + ssi.streamtype = "avs_metadata"; + + /* + * We want to allow the other side to fill our buffer, but no + * more. But it's a bit tricky when the payload is inside + * framing like multipart MIME and contains other parts + */ + + /* uncomment to test rate-limiting, doesn't work with AVS servers */ +// ssi.manual_initial_tx_credit = +// sizeof(((ss_avs_metadata_t *)0)->buf) / 2; + + if (lws_ss_create(context, 0, &ssi, context, &hss_avs_sync, + NULL, NULL)) { + lwsl_err("%s: failed to create avs metadata secstream\n", + __func__); + } + break; + case LWSSSCS_ALL_RETRIES_FAILED: + /* for this demo app, we want to exit on fail to connect */ + interrupted = 1; + break; + case LWSSSCS_DISCONNECTED: + break; + case LWSSSCS_DESTROYING: + lwsl_notice("%s: DESTROYING\n", __func__); + if (wav) { + free(wav); + wav = NULL; + } + break; + default: + break; + } + + return 0; +} + +int +avs_example_start(struct lws_context *context) +{ + lws_ss_info_t ssi; + struct stat stat; + int fd; + + if (hss_avs_event) + return 0; + + fd = open("./year.wav", O_RDONLY); + if (fd < 0) { + lwsl_err("%s: failed to open wav file\n", __func__); + + return 1; + } + if (fstat(fd, &stat) < 0) { + lwsl_err("%s: failed to stat wav file\n", __func__); + + goto bail; + } + + wav_len = stat.st_size; + wav = malloc(wav_len); + if (!wav) { + lwsl_err("%s: failed to alloc wav buffer", __func__); + + goto bail; + } + if (read(fd, wav, +#if defined(WIN32) + (unsigned int) +#endif + wav_len) != (int)wav_len) { + lwsl_err("%s: failed to read wav\n", __func__); + + goto bail; + } + close(fd); + + lwsl_user("%s: Starting AVS stream\n", __func__); + + /* AVS wants us to establish the long poll event stream first */ + + memset(&ssi, 0, sizeof(ssi)); + ssi.handle_offset = offsetof(ss_avs_event_t, ss); + ssi.opaque_user_data_offset = offsetof(ss_avs_event_t, opaque_data); + ssi.rx = ss_avs_event_rx; + ssi.tx = ss_avs_event_tx; + ssi.state = ss_avs_event_state; + ssi.user_alloc = sizeof(ss_avs_event_t); + ssi.streamtype = "avs_event"; + + if (lws_ss_create(context, 0, &ssi, context, &hss_avs_event, NULL, NULL)) { + lwsl_err("%s: failed to create avs event secure stream\n", + __func__); + free(wav); + wav = NULL; + return 1; + } + + return 0; + +bail: + close(fd); + + return 1; +} diff -Nru libwebsockets-3.2.1/minimal-examples/secure-streams/minimal-secure-streams-avs/CMakeLists.txt libwebsockets-4.1.6/minimal-examples/secure-streams/minimal-secure-streams-avs/CMakeLists.txt --- libwebsockets-3.2.1/minimal-examples/secure-streams/minimal-secure-streams-avs/CMakeLists.txt 1970-01-01 00:00:00.000000000 +0000 +++ libwebsockets-4.1.6/minimal-examples/secure-streams/minimal-secure-streams-avs/CMakeLists.txt 2020-12-01 17:40:26.000000000 +0000 @@ -0,0 +1,41 @@ +project(lws-minimal-secure-streams-avs C) +cmake_minimum_required(VERSION 2.8) +find_package(libwebsockets CONFIG REQUIRED) +list(APPEND CMAKE_MODULE_PATH ${LWS_CMAKE_DIR}) +include(CheckCSourceCompiles) +include(LwsCheckRequirements) + +set(SAMP lws-minimal-secure-streams-avs) + +set(requirements 1) +require_lws_config(LWS_ROLE_H1 1 requirements) +require_lws_config(LWS_WITHOUT_CLIENT 0 requirements) +require_lws_config(LWS_WITH_SECURE_STREAMS 1 requirements) +require_lws_config(LWS_WITH_SECURE_STREAMS_STATIC_POLICY_ONLY 0 requirements) +require_lws_config(LWS_WITH_SYS_STATE 1 requirements) + +if (requirements) + add_executable(${SAMP} main.c avs.c) + + if (websockets_shared) + target_link_libraries(${SAMP} websockets_shared ${LIBWEBSOCKETS_DEP_LIBS}) + add_dependencies(${SAMP} websockets_shared) + else() + target_link_libraries(${SAMP} websockets ${LIBWEBSOCKETS_DEP_LIBS}) + endif() + + CHECK_C_SOURCE_COMPILES("#include \nint main(void) {\ni#if defined(LWS_WITH_SECURE_STREAMS_PROXY_API)\n return 0;\n #else\n fail\n #endif\n return 0;\n}\n" HAS_LWS_WITH_SECURE_STREAMS_PROXY_API) + + if (HAS_LWS_WITH_SECURE_STREAMS_PROXY_API OR LWS_WITH_SECURE_STREAMS_PROXY_API) + add_compile_options(-DLWS_SS_USE_SSPC) + + add_executable(${SAMP}-client main-client.c avs.c) + if (websockets_shared) + target_link_libraries(${SAMP}-client websockets_shared ${LIBWEBSOCKETS_DEP_LIBS}) + add_dependencies(${SAMP}-client websockets_shared) + else() + target_link_libraries(${SAMP}-client websockets ${LIBWEBSOCKETS_DEP_LIBS}) + endif() + endif() + +endif() diff -Nru libwebsockets-3.2.1/minimal-examples/secure-streams/minimal-secure-streams-avs/main.c libwebsockets-4.1.6/minimal-examples/secure-streams/minimal-secure-streams-avs/main.c --- libwebsockets-3.2.1/minimal-examples/secure-streams/minimal-secure-streams-avs/main.c 1970-01-01 00:00:00.000000000 +0000 +++ libwebsockets-4.1.6/minimal-examples/secure-streams/minimal-secure-streams-avs/main.c 2020-12-01 17:40:26.000000000 +0000 @@ -0,0 +1,363 @@ +/* + * lws-minimal-secure-streams-avs + * + * Written in 2019-2020 by Andy Green + * + * This file is made available under the Creative Commons CC0 1.0 + * Universal Public Domain Dedication. + */ + +#include +#include +#include + +extern int +avs_example_start(struct lws_context *context); + +int interrupted, bad = 1; +static lws_state_notify_link_t nl; +static const char * const default_ss_policy = + "{" + "\"release\":" "\"01234567\"," + "\"product\":" "\"myproduct\"," + "\"schema-version\":" "1," +// "\"via-socks5\":" "\"127.0.0.1:1080\"," + "\"retry\": [" /* named backoff / retry strategies */ + "{\"default\": {" + "\"backoff\": [" "1000," + "2000," + "3000," + "5000," + "10000" + "]," + "\"conceal\":" "5," + "\"jitterpc\":" "20," + "\"svalidping\":" "60," + "\"svalidhup\":" "64" + "}}" + "]," + "\"certs\": [" /* named individual certificates in BASE64 DER */ + "{\"digicert_global_root_g2\": \"" /* api.amazon.com 2038-01 */ + "MIIDjjCCAnagAwIBAgIQAzrx5qc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KNhJ7jitralj41E6Vf8PlwUHBHQRFXGU7Aj64GxJUTFy8bJZ91" + "8rGOmaFvE7FBcf6IKshPECBV1/MUReXgRPTqh5Uykw7+U0b6LJ3/iyK5S9kJRaTe" + "pLiaWN0bfVKfjllDiIGknibVb63dDcY3fe0Dkhvld1927jyNxF1WW6LZZm6zNTfl" + "MrY=" + "\"}," + "{\"digicert_global_ca_g2\": \"" /* api.amazon.com 2028-08 */ + "MIIEizCCA3OgAwIBAgIQDI7gyQ1qiRWIBAYe4kH5rzANBgkqhkiG9w0BAQsFADBh" + "MQswCQYDVQQGEwJVUzEVMBMGA1UEChMMRGlnaUNlcnQgSW5jMRkwFwYDVQQLExB3" + "d3cuZGlnaWNlcnQuY29tMSAwHgYDVQQDExdEaWdpQ2VydCBHbG9iYWwgUm9vdCBH" + "MjAeFw0xMzA4MDExMjAwMDBaFw0yODA4MDExMjAwMDBaMEQxCzAJBgNVBAYTAlVT" + "MRUwEwYDVQQKEwxEaWdpQ2VydCBJbmMxHjAcBgNVBAMTFURpZ2lDZXJ0IEdsb2Jh" + "bCBDQSBHMjCCASIwDQYJKoZIhvcNAQEBBQADggEPADCCAQoCggEBANNIfL7zBYZd" + "W9UvhU5L4IatFaxhz1uvPmoKR/uadpFgC4przc/cV35gmAvkVNlW7SHMArZagV+X" + "au4CLyMnuG3UsOcGAngLH1ypmTb+u6wbBfpXzYEQQGfWMItYNdSWYb7QjHqXnxr5" + "IuYUL6nG6AEfq/gmD6yOTSwyOR2Bm40cZbIc22GoiS9g5+vCShjEbyrpEJIJ7RfR" + "ACvmfe8EiRROM6GyD5eHn7OgzS+8LOy4g2gxPR/VSpAQGQuBldYpdlH5NnbQtwl6" + "OErXb4y/E3w57bqukPyV93t4CTZedJMeJfD/1K2uaGvG/w/VNfFVbkhJ+Pi474j4" + "8V4Rd6rfArMCAwEAAaOCAVowggFWMBIGA1UdEwEB/wQIMAYBAf8CAQAwDgYDVR0P" + "AQH/BAQDAgGGMDQGCCsGAQUFBw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/I9vG+o1VTqkC50cRRj70/b17KSa7qWFiNyi2LSr2EIZkyXCn" + "0q23KXB56jzaYyWf/Wi3MOxw+3WKt21gZ7IeyLnp2KhvAotnDU0mV3HaIPzBSlCN" + "sSi6" + "\"}," + "{\"starfield_class_2_ca\": \"" + "MIIEDzCCAvegAwIBAgIBADANBgkqhkiG9w0BAQUFADBoMQswCQYDVQQGEwJVUzEl" + "MCMGA1UEChMcU3RhcmZpZWxkIFRlY2hub2xvZ2llcywgSW5jLjEyMDAGA1UECxMp" + "U3RhcmZpZWxkIENsYXNzIDIgQ2VydGlmaWNhdGlvbiBBdXRob3JpdHkwHhcNMDQw" + "NjI5MTczOTE2WhcNMzQwNjI5MTczOTE2WjBoMQswCQYDVQQGEwJVUzElMCMGA1UE" + "ChMcU3RhcmZpZWxkIFRlY2hub2xvZ2llcywgSW5jLjEyMDAGA1UECxMpU3RhcmZp" + "ZWxkIENsYXNzIDIgQ2VydGlmaWNhdGlvbiBBdXRob3JpdHkwggEgMA0GCSqGSIb3" + "DQEBAQUAA4IBDQAwggEIAoIBAQC3Msj+6XGmBIWtDBFk385N78gDGIc/oav7PKaf" + "8MOh2tTYbitTkPskpD6E8J7oX+zlJ0T1KKY/e97gKvDIr1MvnsoFAZMej2YcOadN" + "+lq2cwQlZut3f+dZxkqZJRRU6ybH838Z1TBwj6+wRir/resp7defqgSHo9T5iaU0" + "X9tDkYI22WY8sbi5gv2cOj4QyDvvBmVmepsZGD3/cVE8MC5fvj13c7JdBmzDI1aa" + "K4UmkhynArPkPw2vCHmCuDY96pzTNbO8acr1zJ3o/WSNF4Azbl5KXZnJHoe0nRrA" + "1W4TNSNe35tfPe/W93bC6j67eA0cQmdrBNj41tpvi/JEoAGrAgEDo4HFMIHCMB0G" + "A1UdDgQWBBS/X7fRzt0fhvRbVazc1xDCDqmI5zCBkgYDVR0jBIGKMIGHgBS/X7fR" + "zt0fhvRbVazc1xDCDqmI56FspGowaDELMAkGA1UEBhMCVVMxJTAjBgNVBAoTHFN0" + "YXJmaWVsZCBUZWNobm9sb2dpZXMsIEluYy4xMjAwBgNVBAsTKVN0YXJmaWVsZCBD" + "bGFzcyAyIENlcnRpZmljYXRpb24gQXV0aG9yaXR5ggEAMAwGA1UdEwQFMAMBAf8w" + "DQYJKoZIhvcNAQEFBQADggEBAAWdP4id0ckaVaGsafPzWdqbAYcaT1epoXkJKtv3" + "L7IezMdeatiDh6GX70k1PncGQVhiv45YuApnP+yz3SFmH8lU+nLMPUxA2IGvd56D" + "eruix/U0F47ZEUD0/CwqTRV/p2JdLiXTAAsgGh1o+Re49L2L7ShZ3U0WixeDyLJl" + "xy16paq8U4Zt3VekyvggQQto8PT7dL5WXXp59fkdheMtlb71cZBDzI0fmgAKhynp" + "VSJYACPq4xJDKVtHCN2MQWplBqjlIapBtJUhlbl90TSrE9atvNziPTnNvT51cKEY" + "WQPJIrSPnNVeKtelttQKbfi3QBFGmh95DmK/D5fs4C8fF5Q=" + "\"}" + "]," + "\"trust_stores\": [" /* named cert chains */ + "{" /* chain for alexa.na.gateway.devices.a2z.com */ + "\"name\": \"avs_via_starfield\"," + "\"stack\": [" + "\"starfield_class_2_ca\"," + "\"starfield_services_root_ca\"" + "]" + "}," + "{" /* chain for api.amazon.com */ + "\"name\": \"api_amazon_com\"," + "\"stack\": [" + "\"digicert_global_ca_g2\"," + "\"digicert_global_root_g2\"" + "]" + "}" + "]," + "\"s\": [" /* the supported stream types */ + "{\"api_amazon_com_auth\": {" + "\"endpoint\":" "\"api.amazon.com\"," + "\"port\":" "443," + "\"protocol\":" "\"h1\"," + "\"http_method\":" "\"POST\"," + "\"http_url\":" "\"auth/o2/token\"," + "\"plugins\":" "[]," + "\"opportunistic\":" "true," + "\"tls\":" "true," + "\"h2q_oflow_txcr\":" "true," + "\"http_www_form_urlencoded\":" "true," + "\"http_no_content_length\":" "true," + "\"retry\":" "\"default\"," + "\"tls_trust_store\":" "\"api_amazon_com\"" + "}}," + "{\"avs_event\": {" + "\"endpoint\":" "\"alexa.na.gateway.devices.a2z.com\"," + "\"port\":" "443," + "\"protocol\":" "\"h2\"," + "\"http_method\":" "\"GET\"," + "\"http_url\":" "\"v20160207/directives\"," + "\"h2q_oflow_txcr\":" "true," + "\"http_auth_header\":" "\"authorization:\"," + "\"http_auth_preamble\":" "\"Bearer \"," + "\"nailed_up\":" "true," + "\"long_poll\":" "true," + "\"retry\":" "\"default\"," + "\"plugins\":" "[]," + "\"tls\":" "true," + "\"tls_trust_store\":" "\"avs_via_starfield\"" + "}}," + "{\"avs_metadata\": {" + "\"endpoint\":" "\"alexa.na.gateway.devices.a2z.com\"," + "\"port\":" "443," + "\"protocol\":" "\"h2\"," + "\"http_method\":" "\"POST\"," + "\"http_url\":" "\"v20160207/events\"," + "\"http_no_content_length\":" "true," + "\"h2q_oflow_txcr\":" "true," + "\"http_auth_header\":" "\"authorization:\"," + "\"http_auth_preamble\":" "\"Bearer \"," + "\"http_multipart_name\":" "\"metadata\"," + "\"http_mime_content_type\":" "\"application/json; charset=UTF-8\"," +#if 1 + "\"http_multipart_ss_in\":" "true," +#endif + "\"rideshare\":" "\"avs_audio\"," + "\"retry\":" "\"default\"," + "\"plugins\":" "[]," + "\"tls\":" "true," + "\"tls_trust_store\":" "\"avs_via_starfield\"" + "}}," + "{\"avs_audio\": {" + "\"endpoint\":" "\"alexa.na.gateway.devices.a2z.com\"," + "\"port\":" "443," + "\"protocol\":" "\"h2\"," + "\"http_method\":" "\"POST\"," + "\"http_url\":" "\"v20160207/events\"," + "\"http_no_content_length\":" "true," + "\"plugins\":" "[]," + "\"tls\":" "true," + "\"h2q_oflow_txcr\":" "true," +#if 1 + "\"http_multipart_ss_in\":" "true," +#endif + "\"http_auth_header\":" "\"authorization:\"," + "\"http_auth_preamble\":" "\"Bearer \"," + "\"http_multipart_name\":" "\"audio\"," + "\"http_mime_content_type\":" "\"application/octet-stream\"," + "\"retry\":" "\"default\"," + "\"tls_trust_store\":" "\"avs_via_starfield\"" + "}}" + "]" + "}" +; + +static const char *canned_root_token_payload = + "grant_type=refresh_token" + "&refresh_token=Atzr|IwEBIJedGXjDqsU_vMxykqOMg" + "SHfYe3CPcedueWEMWSDMaDnEmiW8RlR1Kns7Cb4B-TOSnqp7ifVsY4BMY2B8tpHfO39XP" + "zfu9HapGjTR458IyHX44FE71pWJkGZ79uVBpljP4sazJuk8XS3Oe_yLnm_DIO6fU1nU3Y" + "0flYmsOiOAQE_gRk_pdlmEtHnpMA-9rLw3mkY5L89Ty9kUygBsiFaYatouROhbsTn8-jW" + "k1zZLUDpT6ICtBXSnrCIg0pUbZevPFhTwdXd6eX-u4rq0W-XaDvPWFO7au-iPb4Zk5eZE" + "iX6sissYrtNmuEXc2uHu7MnQO1hHCaTdIO2CANVumf-PHSD8xseamyh04sLV5JgFzY45S" + "KvKMajiUZuLkMokOx86rjC2Hdkx5DO7G-dbG1ufBDG-N79pFMSs7Ck5pc283IdLoJkCQc" + "AGvTX8o8I29QqkcGou-9TKhOJmpX8As94T61ok0UqqEKPJ7RhfQHHYdCtsdwxgvfVr9qI" + "xL_hDCcTho8opCVX-6QhJHl6SQFlTw13" + "&client_id=" + "amzn1.application-oa2-client.4823334c434b4190a2b5a42c07938a2d"; + +static int +app_system_state_nf(lws_state_manager_t *mgr, lws_state_notify_link_t *link, + int current, int target) +{ + struct lws_context *context = lws_system_context_from_system_mgr(mgr); + lws_system_blob_t *ab = lws_system_get_blob(context, + LWS_SYSBLOB_TYPE_AUTH, 1 /* AUTH_IDX_ROOT */); + size_t size; + + /* + * For the things we care about, let's notice if we are trying to get + * past them when we haven't solved them yet, and make the system + * state wait while we trigger the dependent action. + */ + switch (target) { + case LWS_SYSTATE_REGISTERED: + size = lws_system_blob_get_size(ab); + if (size) + break; + + /* let's register our canned root token so auth can use it */ + lws_system_blob_direct_set(ab, + (const uint8_t *)canned_root_token_payload, + strlen(canned_root_token_payload)); + break; + case LWS_SYSTATE_OPERATIONAL: + if (current == LWS_SYSTATE_OPERATIONAL) + avs_example_start(context); + break; + case LWS_SYSTATE_POLICY_INVALID: + /* + * This is a NOP since we used direct set... but in a real + * system this could easily change to be done on the heap, then + * this would be important + */ + lws_system_blob_destroy(lws_system_get_blob(context, + LWS_SYSBLOB_TYPE_AUTH, + 1 /* AUTH_IDX_ROOT */)); + break; + } + + return 0; +} + +static void +sigint_handler(int sig) +{ + interrupted = 1; +} + +static lws_state_notify_link_t * const app_notifier_list[] = { + &nl, NULL +}; + +int main(int argc, const 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 */ + lws_cmdline_option_handle_builtin(argc, argv, &info); + + lwsl_user("LWS secure streams - AVS test [-d]\n"); + + info.options = LWS_SERVER_OPTION_EXPLICIT_VHOSTS | + LWS_SERVER_OPTION_DO_SSL_GLOBAL_INIT; + info.fd_limit_per_thread = 1 + 6 + 1; + info.pss_policies_json = default_ss_policy; + info.port = CONTEXT_PORT_NO_LISTEN; + +#if defined(LWS_SS_USE_SSPC) + { + const char *p; + + /* connect to ssproxy via UDS by default, else via + * tcp connection to this port */ + if ((p = lws_cmdline_option(argc, argv, "-p"))) + info.ss_proxy_port = atoi(p); + + /* UDS "proxy.ss.lws" in abstract namespace, else this socket + * path; when -p given this can specify the network interface + * to bind to */ + if ((p = lws_cmdline_option(argc, argv, "-i"))) + info.ss_proxy_bind = p; + + /* if -p given, -a specifies the proxy address to connect to */ + if ((p = lws_cmdline_option(argc, argv, "-a"))) + info.ss_proxy_address = p; + } +#endif + +#if defined(LWS_WITH_DETAILED_LATENCY) + info.detailed_latency_cb = lws_det_lat_plot_cb; + info.detailed_latency_filepath = "/tmp/lws-latency-ssproxy"; +#endif + + /* integrate us with lws system state management when context created */ + nl.name = "app"; + nl.notify_cb = app_system_state_nf; + info.register_notifier_list = app_notifier_list; + + context = lws_create_context(&info); + if (!context) { + lwsl_err("lws init failed\n"); + return 1; + } + + /* the event loop */ + + while (n >= 0 && !interrupted) + n = lws_service(context, 0); + + lws_context_destroy(context); + lwsl_user("Completed: %s\n", bad ? "failed" : "OK"); + + return bad; +} diff -Nru libwebsockets-3.2.1/minimal-examples/secure-streams/minimal-secure-streams-avs/main-client.c libwebsockets-4.1.6/minimal-examples/secure-streams/minimal-secure-streams-avs/main-client.c --- libwebsockets-3.2.1/minimal-examples/secure-streams/minimal-secure-streams-avs/main-client.c 1970-01-01 00:00:00.000000000 +0000 +++ libwebsockets-4.1.6/minimal-examples/secure-streams/minimal-secure-streams-avs/main-client.c 2020-12-01 17:40:26.000000000 +0000 @@ -0,0 +1,128 @@ +/* + * lws-minimal-secure-streams-avs + * + * This file is made available under the Creative Commons CC0 1.0 + * Universal Public Domain Dedication. + */ + +#include +#include +#include + +extern int +avs_example_start(struct lws_context *context); + +int interrupted, bad = 1; +static lws_state_notify_link_t nl; + +static const char *canned_root_token_payload = + "grant_type=refresh_token" + "&refresh_token=Atzr|IwEBIJedGXjDqsU_vMxykqOMg" + "SHfYe3CPcedueWEMWSDMaDnEmiW8RlR1Kns7Cb4B-TOSnqp7ifVsY4BMY2B8tpHfO39XP" + "zfu9HapGjTR458IyHX44FE71pWJkGZ79uVBpljP4sazJuk8XS3Oe_yLnm_DIO6fU1nU3Y" + "0flYmsOiOAQE_gRk_pdlmEtHnpMA-9rLw3mkY5L89Ty9kUygBsiFaYatouROhbsTn8-jW" + "k1zZLUDpT6ICtBXSnrCIg0pUbZevPFhTwdXd6eX-u4rq0W-XaDvPWFO7au-iPb4Zk5eZE" + "iX6sissYrtNmuEXc2uHu7MnQO1hHCaTdIO2CANVumf-PHSD8xseamyh04sLV5JgFzY45S" + "KvKMajiUZuLkMokOx86rjC2Hdkx5DO7G-dbG1ufBDG-N79pFMSs7Ck5pc283IdLoJkCQc" + "AGvTX8o8I29QqkcGou-9TKhOJmpX8As94T61ok0UqqEKPJ7RhfQHHYdCtsdwxgvfVr9qI" + "xL_hDCcTho8opCVX-6QhJHl6SQFlTw13" + "&client_id=" + "amzn1.application-oa2-client.4823334c434b4190a2b5a42c07938a2d"; + +static int +app_system_state_nf(lws_state_manager_t *mgr, lws_state_notify_link_t *link, + int current, int target) +{ + struct lws_context *context = lws_system_context_from_system_mgr(mgr); + lws_system_blob_t *ab = lws_system_get_blob(context, + LWS_SYSBLOB_TYPE_AUTH, 1 /* AUTH_IDX_ROOT */); + size_t size; + + /* + * For the things we care about, let's notice if we are trying to get + * past them when we haven't solved them yet, and make the system + * state wait while we trigger the dependent action. + */ + switch (target) { + case LWS_SYSTATE_REGISTERED: + size = lws_system_blob_get_size(ab); + if (size) + break; + + /* let's register our canned root token so auth can use it */ + lws_system_blob_direct_set(ab, + (const uint8_t *)canned_root_token_payload, + strlen(canned_root_token_payload)); + break; + case LWS_SYSTATE_OPERATIONAL: + if (current == LWS_SYSTATE_OPERATIONAL) + avs_example_start(context); + break; + case LWS_SYSTATE_POLICY_INVALID: + /* + * This is a NOP since we used direct set... but in a real + * system this could easily change to be done on the heap, then + * this would be important + */ + lws_system_blob_destroy(lws_system_get_blob(context, + LWS_SYSBLOB_TYPE_AUTH, + 1 /* AUTH_IDX_ROOT */)); + break; + } + + return 0; +} + +static void +sigint_handler(int sig) +{ + interrupted = 1; +} + +static lws_state_notify_link_t * const app_notifier_list[] = { + &nl, NULL +}; + +int main(int argc, const 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 */ + lws_cmdline_option_handle_builtin(argc, argv, &info); + + lwsl_user("LWS secure streams - AVS test client [-d]\n"); + + info.options = LWS_SERVER_OPTION_DO_SSL_GLOBAL_INIT; + info.fd_limit_per_thread = 1 + 6 + 1; + info.protocols = lws_sspc_protocols; + info.port = CONTEXT_PORT_NO_LISTEN; + +#if defined(LWS_WITH_DETAILED_LATENCY) + info.detailed_latency_cb = lws_det_lat_plot_cb; + info.detailed_latency_filepath = "/tmp/lws-latency-ssproxy"; +#endif + + /* integrate us with lws system state management when context created */ + nl.name = "app"; + nl.notify_cb = app_system_state_nf; + info.register_notifier_list = app_notifier_list; + + context = lws_create_context(&info); + if (!context) { + lwsl_err("lws init failed\n"); + return 1; + } + + /* the event loop */ + + while (n >= 0 && !interrupted) + n = lws_service(context, 0); + + lws_context_destroy(context); + lwsl_user("Completed: %s\n", bad ? "failed" : "OK"); + + return bad; +} Binary files /tmp/tmp2l8bmswe/3lv7Sxvgkv/libwebsockets-3.2.1/minimal-examples/secure-streams/minimal-secure-streams-avs/year.wav and /tmp/tmp2l8bmswe/LwTwoWz49Q/libwebsockets-4.1.6/minimal-examples/secure-streams/minimal-secure-streams-avs/year.wav differ diff -Nru libwebsockets-3.2.1/minimal-examples/secure-streams/minimal-secure-streams-client-tx/CMakeLists.txt libwebsockets-4.1.6/minimal-examples/secure-streams/minimal-secure-streams-client-tx/CMakeLists.txt --- libwebsockets-3.2.1/minimal-examples/secure-streams/minimal-secure-streams-client-tx/CMakeLists.txt 1970-01-01 00:00:00.000000000 +0000 +++ libwebsockets-4.1.6/minimal-examples/secure-streams/minimal-secure-streams-client-tx/CMakeLists.txt 2020-12-01 17:40:26.000000000 +0000 @@ -0,0 +1,27 @@ +project(lws-minimal-secure-streams-client-tx C) +cmake_minimum_required(VERSION 2.8) +find_package(libwebsockets CONFIG REQUIRED) +list(APPEND CMAKE_MODULE_PATH ${LWS_CMAKE_DIR}) +include(CheckCSourceCompiles) +include(LwsCheckRequirements) + +set(SAMP lws-minimal-secure-streams-client-tx) +set(SRCS minimal-secure-streams-client-tx.c) + +set(requirements 1) +require_lws_config(LWS_ROLE_H1 1 requirements) +require_lws_config(LWS_WITHOUT_CLIENT 0 requirements) +require_lws_config(LWS_WITH_SECURE_STREAMS 1 requirements) +require_lws_config(LWS_WITH_SECURE_STREAMS_PROXY_API 1 requirements) + + +if (requirements) + add_executable(${SAMP} ${SRCS}) + + if (websockets_shared) + target_link_libraries(${SAMP} websockets_shared ${LIBWEBSOCKETS_DEP_LIBS}) + add_dependencies(${SAMP} websockets_shared) + else() + target_link_libraries(${SAMP} websockets ${LIBWEBSOCKETS_DEP_LIBS}) + endif() +endif() diff -Nru libwebsockets-3.2.1/minimal-examples/secure-streams/minimal-secure-streams-client-tx/minimal-secure-streams-client-tx.c libwebsockets-4.1.6/minimal-examples/secure-streams/minimal-secure-streams-client-tx/minimal-secure-streams-client-tx.c --- libwebsockets-3.2.1/minimal-examples/secure-streams/minimal-secure-streams-client-tx/minimal-secure-streams-client-tx.c 1970-01-01 00:00:00.000000000 +0000 +++ libwebsockets-4.1.6/minimal-examples/secure-streams/minimal-secure-streams-client-tx/minimal-secure-streams-client-tx.c 2020-12-01 17:40:26.000000000 +0000 @@ -0,0 +1,197 @@ +/* + * lws-minimal-secure-streams-tx + * + * Written in 2010-2020 by Andy Green + * + * This file is made available under the Creative Commons CC0 1.0 + * Universal Public Domain Dedication. + * + * + * This demonstrates tx from secure streams. + * + * It opens a stream and fires small 80-byte payloads on it at 50Hz (20ms) + */ + +#include +#include +#include + +#define PKT_SIZE 80 +#define RATE_US 50000 + +static int interrupted, bad = 1; + +typedef struct myss { + struct lws_sspc_handle *ss; + void *opaque_data; + /* ... application specific state ... */ + lws_sorted_usec_list_t sul; + + int count; + char due; +} myss_t; + +/* secure streams payload interface */ + +static int +myss_rx(void *userobj, const uint8_t *buf, size_t len, int flags) +{ +// myss_t *m = (myss_t *)userobj; + + //lwsl_user("%s: len %d, flags: %d\n", __func__, (int)len, flags); + //lwsl_hexdump_info(buf, len); + + return 0; +} + +static void +txcb(struct lws_sorted_usec_list *sul) +{ + myss_t *m = lws_container_of(sul, myss_t, sul); + + if (m->count == 1000) { + interrupted = 1; + return; + } + + m->due = 1; + lws_sspc_request_tx(m->ss); + + lws_sul_schedule(lws_sspc_get_context(m->ss), 0, &m->sul, txcb, RATE_US); + + +} + +static int +myss_tx(void *userobj, lws_ss_tx_ordinal_t ord, uint8_t *buf, size_t *len, + int *flags) +{ + myss_t *m = (myss_t *)userobj; + + if (!m->due) + return 0; + + m->due = 0; + + if (lws_get_random(lws_sspc_get_context(m->ss), buf, PKT_SIZE) != PKT_SIZE) + return 1; + + *len = PKT_SIZE; + *flags = 0; + if (!m->count) + *flags |= LWSSS_FLAG_SOM; + if (m->count == 999) { + *flags |= LWSSS_FLAG_EOM; + lwsl_user("%s: sent final packet\n", __func__); + bad = 0; + } + + m->count++; + + lws_sul_schedule(lws_sspc_get_context(m->ss), 0, &m->sul, txcb, RATE_US); + + // lwsl_user("%s: sending pkt %d\n", __func__, m->count); + + return 0; +} + +static int +myss_state(void *userobj, void *sh, lws_ss_constate_t state, + lws_ss_tx_ordinal_t ack) +{ + myss_t *m = (myss_t *)userobj; + struct lws_context *context = lws_sspc_get_context(m->ss); + + lwsl_user("%s: %s, ord 0x%x\n", __func__, lws_ss_state_name(state), + (unsigned int)ack); + + switch (state) { + case LWSSSCS_CREATING: + break; + case LWSSSCS_CONNECTED: + lws_sul_schedule(context, 0, &m->sul, txcb, RATE_US); + break; + case LWSSSCS_DISCONNECTED: + lws_sul_cancel(&m->sul); + break; + case LWSSSCS_ALL_RETRIES_FAILED: + /* if we're out of retries, we want to close the app and FAIL */ + interrupted = 1; + break; + default: + break; + } + + return 0; +} + +static void +sigint_handler(int sig) +{ + interrupted = 1; +} + +int main(int argc, const char **argv) +{ + int n = 0, logs = LLL_USER | LLL_ERR | LLL_WARN | LLL_NOTICE; + struct lws_context_creation_info info; + struct lws_context *context; + lws_ss_info_t ssi; + const char *p; + + signal(SIGINT, sigint_handler); + + if ((p = lws_cmdline_option(argc, argv, "-d"))) + logs = atoi(p); + + lws_set_log_level(logs, NULL); + lwsl_user("LWS secure streams client TX [-d]\n"); + + memset(&info, 0, sizeof info); /* otherwise uninitialized garbage */ + + info.options = //LWS_SERVER_OPTION_EXPLICIT_VHOSTS | + LWS_SERVER_OPTION_DO_SSL_GLOBAL_INIT; + info.fd_limit_per_thread = 1 + 6 + 1; + info.port = CONTEXT_PORT_NO_LISTEN; + info.protocols = lws_sspc_protocols; +#if defined(LWS_WITH_DETAILED_LATENCY) + info.detailed_latency_cb = lws_det_lat_plot_cb; + info.detailed_latency_filepath = "/tmp/lws-latency-ssclient"; +#endif + + context = lws_create_context(&info); + if (!context) { + lwsl_err("lws init failed\n"); + return 1; + } + + /* + * We're requesting a secure stream via proxy... where and how this + * connects are details managed by the proxy policy + */ + + memset(&ssi, 0, sizeof ssi); + ssi.handle_offset = offsetof(myss_t, ss); + ssi.opaque_user_data_offset = offsetof(myss_t, opaque_data); + ssi.rx = myss_rx; + ssi.tx = myss_tx; + ssi.state = myss_state; + ssi.user_alloc = sizeof(myss_t); + ssi.streamtype = "spam"; + + if (lws_sspc_create(context, 0, &ssi, NULL, NULL, NULL, NULL)) { + lwsl_err("%s: create secure stream failed\n", __func__); + goto bail; + } + + /* the event loop */ + + while (n >= 0 && !interrupted) + n = lws_service(context, 0); + +bail: + lws_context_destroy(context); + lwsl_user("Completed: %s\n", bad ? "failed" : "OK"); + + return bad; +} diff -Nru libwebsockets-3.2.1/minimal-examples/secure-streams/minimal-secure-streams-client-tx/README.md libwebsockets-4.1.6/minimal-examples/secure-streams/minimal-secure-streams-client-tx/README.md --- libwebsockets-3.2.1/minimal-examples/secure-streams/minimal-secure-streams-client-tx/README.md 1970-01-01 00:00:00.000000000 +0000 +++ libwebsockets-4.1.6/minimal-examples/secure-streams/minimal-secure-streams-client-tx/README.md 2020-12-01 17:40:26.000000000 +0000 @@ -0,0 +1,64 @@ +# lws minimal secure streams + +The application goes to https://warmcat.com and reads index.html there. + +It does it using Secure Streams... the main code in minimal-secure-streams.c +just sets up the context and opens a secure stream of type "mintest". + +The handler for state changes and payloads for "mintest" is in ss-myss.c + +The information about how a "mintest" stream should connect and the +protocol it uses is kept separated in policy-database.c + +## build + +``` + $ cmake . && make +``` + +## usage + +Commandline option|Meaning +---|--- +-d |Debug verbosity in decimal, eg, -d15 +-f| Force connecting to the wrong endpoint to check backoff retry flow +-p| Run as proxy server for clients to connect to over unix domain socket + +``` +[2019/08/12 07:16:11:0045] USR: LWS minimal secure streams [-d] [-f] +[2019/08/12 07:16:12:6102] USR: myss_state: LWSSSCS_CREATING, ord 0x0 +[2019/08/12 07:16:12:6107] USR: myss_state: LWSSSCS_POLL, ord 0x0 +[2019/08/12 07:16:12:6117] N: lws_ss_client_connect: connecting h1get warmcat.com / +[2019/08/12 07:16:12:6118] USR: myss_state: LWSSSCS_CONNECTING, ord 0x0 +[2019/08/12 07:16:13:4171] USR: myss_state: LWSSSCS_CONNECTED, ord 0x0 +[2019/08/12 07:16:13:4222] USR: myss_rx: len 1024, flags: 1 +[2019/08/12 07:16:13:4243] USR: myss_rx: len 1024, flags: 0 +[2019/08/12 07:16:13:4244] USR: myss_rx: len 1024, flags: 0 +[2019/08/12 07:16:13:4244] USR: myss_rx: len 1024, flags: 0 +[2019/08/12 07:16:13:4245] USR: myss_rx: len 1024, flags: 0 +[2019/08/12 07:16:13:4246] USR: myss_rx: len 1024, flags: 0 +[2019/08/12 07:16:13:4247] USR: myss_rx: len 1024, flags: 0 +[2019/08/12 07:16:13:4252] USR: myss_rx: len 1015, flags: 0 +[2019/08/12 07:16:13:4264] USR: myss_rx: len 1024, flags: 0 +[2019/08/12 07:16:13:4265] USR: myss_rx: len 1024, flags: 0 +[2019/08/12 07:16:13:4266] USR: myss_rx: len 1024, flags: 0 +[2019/08/12 07:16:13:4267] USR: myss_rx: len 1024, flags: 0 +[2019/08/12 07:16:13:4268] USR: myss_rx: len 1024, flags: 0 +[2019/08/12 07:16:13:4268] USR: myss_rx: len 1024, flags: 0 +[2019/08/12 07:16:13:4269] USR: myss_rx: len 1024, flags: 0 +[2019/08/12 07:16:13:4270] USR: myss_rx: len 1015, flags: 0 +[2019/08/12 07:16:13:4278] USR: myss_rx: len 1024, flags: 0 +[2019/08/12 07:16:13:4279] USR: myss_rx: len 1024, flags: 0 +[2019/08/12 07:16:13:4280] USR: myss_rx: len 1024, flags: 0 +[2019/08/12 07:16:13:4281] USR: myss_rx: len 1024, flags: 0 +[2019/08/12 07:16:13:4282] USR: myss_rx: len 1024, flags: 0 +[2019/08/12 07:16:13:4283] USR: myss_rx: len 1024, flags: 0 +[2019/08/12 07:16:13:4283] USR: myss_rx: len 1024, flags: 0 +[2019/08/12 07:16:13:4284] USR: myss_rx: len 1015, flags: 0 +[2019/08/12 07:16:13:4287] USR: myss_rx: len 1024, flags: 0 +[2019/08/12 07:16:13:4288] USR: myss_rx: len 947, flags: 0 +[2019/08/12 07:16:13:4293] USR: myss_rx: len 0, flags: 2 +[2019/08/12 07:16:13:4399] USR: myss_state: LWSSSCS_DISCONNECTED, ord 0x0 +[2019/08/12 07:16:13:4761] USR: myss_state: LWSSSCS_DESTROYING, ord 0x0 +[2019/08/12 07:16:13:4781] USR: Completed: OK +``` diff -Nru libwebsockets-3.2.1/minimal-examples/secure-streams/minimal-secure-streams-metadata/CMakeLists.txt libwebsockets-4.1.6/minimal-examples/secure-streams/minimal-secure-streams-metadata/CMakeLists.txt --- libwebsockets-3.2.1/minimal-examples/secure-streams/minimal-secure-streams-metadata/CMakeLists.txt 1970-01-01 00:00:00.000000000 +0000 +++ libwebsockets-4.1.6/minimal-examples/secure-streams/minimal-secure-streams-metadata/CMakeLists.txt 2020-12-01 17:40:26.000000000 +0000 @@ -0,0 +1,41 @@ +project(lws-minimal-secure-streams-metadata C) +cmake_minimum_required(VERSION 2.8) +find_package(libwebsockets CONFIG REQUIRED) +list(APPEND CMAKE_MODULE_PATH ${LWS_CMAKE_DIR}) +include(CheckCSourceCompiles) +include(LwsCheckRequirements) + +set(SAMP lws-minimal-secure-streams-metadata) + +set(requirements 1) +require_lws_config(LWS_ROLE_H1 1 requirements) +require_lws_config(LWS_WITHOUT_CLIENT 0 requirements) +require_lws_config(LWS_WITH_SECURE_STREAMS 1 requirements) +require_lws_config(LWS_WITH_SECURE_STREAMS_STATIC_POLICY_ONLY 0 requirements) +require_lws_config(LWS_WITH_SYS_STATE 1 requirements) + +if (requirements) + add_executable(${SAMP} minimal-secure-streams.c) + + if (websockets_shared) + target_link_libraries(${SAMP} websockets_shared ${LIBWEBSOCKETS_DEP_LIBS}) + add_dependencies(${SAMP} websockets_shared) + else() + target_link_libraries(${SAMP} websockets ${LIBWEBSOCKETS_DEP_LIBS}) + endif() + + CHECK_C_SOURCE_COMPILES("#include \nint main(void) {\ni#if defined(LWS_WITH_SECURE_STREAMS_PROXY_API)\n return 0;\n #else\n fail\n #endif\n return 0;\n}\n" HAS_LWS_WITH_SECURE_STREAMS_PROXY_API) + + if (HAS_LWS_WITH_SECURE_STREAMS_PROXY_API OR LWS_WITH_SECURE_STREAMS_PROXY_API) + add_compile_options(-DLWS_SS_USE_SSPC) + + add_executable(${SAMP}-client minimal-secure-streams.c) + if (websockets_shared) + target_link_libraries(${SAMP}-client websockets_shared ${LIBWEBSOCKETS_DEP_LIBS}) + add_dependencies(${SAMP}-client websockets_shared) + else() + target_link_libraries(${SAMP}-client websockets ${LIBWEBSOCKETS_DEP_LIBS}) + endif() + endif() + +endif() diff -Nru libwebsockets-3.2.1/minimal-examples/secure-streams/minimal-secure-streams-metadata/minimal-secure-streams.c libwebsockets-4.1.6/minimal-examples/secure-streams/minimal-secure-streams-metadata/minimal-secure-streams.c --- libwebsockets-3.2.1/minimal-examples/secure-streams/minimal-secure-streams-metadata/minimal-secure-streams.c 1970-01-01 00:00:00.000000000 +0000 +++ libwebsockets-4.1.6/minimal-examples/secure-streams/minimal-secure-streams-metadata/minimal-secure-streams.c 2020-12-01 17:40:26.000000000 +0000 @@ -0,0 +1,374 @@ +/* + * lws-minimal-secure-streams-metadata + * + * Written in 2010-2020 by Andy Green + * + * This file is made available under the Creative Commons CC0 1.0 + * Universal Public Domain Dedication. + * + * + * This demonstrates a minimal http client using secure streams api. + * + * It visits https://warmcat.com/ and receives the html page there. + * + * This example is built two different ways from the same source... one includes + * the policy everything needed to fulfil the stream directly. The other -client + * variant has no policy itself and some other minor init changes, and connects + * to the -proxy example to actually get the connection done. + * + * In the -client build case, the example does not even init the tls libraries + * since the proxy part will take care of all that. + */ + +#include +#include +#include + +/* + * uncomment to force network traffic through 127.0.0.1:1080 + * + * On your local machine, you can run a SOCKS5 proxy like this + * + * $ ssh -N -D 0.0.0.0:1080 localhost -v + * + * If enabled, this also fetches a remote policy that also + * specifies that all traffic should go through the remote + * proxy. + */ +// #define VIA_LOCALHOST_SOCKS + +static int interrupted, bad = 1, force_cpd_fail_portal, + force_cpd_fail_no_internet; +static lws_state_notify_link_t nl; +static const char *server_name_or_url = "warmcat.com"; + +/* + * If the -proxy app is fulfilling our connection, then we don't need to have + * the policy in the client. + * + * When we build with LWS_SS_USE_SSPC, the apis hook up to a proxy process over + * a Unix Domain Socket. To test that, you need to separately run the + * ./lws-minimal-secure-streams-proxy test app on the same machine. + */ + +#if !defined(LWS_SS_USE_SSPC) +static const char * const default_ss_policy = + "{" + "\"release\":" "\"01234567\"," + "\"product\":" "\"myproduct\"," + "\"schema-version\":" "1," +#if defined(VIA_LOCALHOST_SOCKS) + "\"via-socks5\":" "\"127.0.0.1:1080\"," +#endif + + "\"retry\": [" /* named backoff / retry strategies */ + "{\"default\": {" + "\"backoff\": [" "1000," + "2000," + "3000," + "5000," + "10000" + "]," + "\"conceal\":" "5," + "\"jitterpc\":" "20," + "\"svalidping\":" "30," + "\"svalidhup\":" "35" + "}}" + "]," + "\"certs\": [" /* named individual certificates in BASE64 DER */ + /* + * Let's Encrypt certs for warmcat.com / libwebsockets.org + * + * We fetch the real policy from there using SS and switch to + * using that. + */ + "{\"isrg_root_x1\": \"" /* ISRG ROOT X1 */ + "MIIFazCCA1OgAwIBAgIRAIIQz7DSQONZRGPgu2OCiwAwDQYJKoZIhvcNAQELBQAw" + "TzELMAkGA1UEBhMCVVMxKTAnBgNVBAoTIEludGVybmV0IFNlY3VyaXR5IFJlc2Vh" + "cmNoIEdyb3VwMRUwEwYDVQQDEwxJU1JHIFJvb3QgWDEwHhcNMTUwNjA0MTEwNDM4" + "WhcNMzUwNjA0MTEwNDM4WjBPMQsw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rvFKm/Bz9BCjaxorALINUfZ9DD64j2igLIxle2" + "DPxW8dI/F2loHMjXZjqG8RkqZUdoxtID5+90FgsGIfkMpqgRS05f4zPbCEHqCXl1" + "eO5HyELTgcVlLXXQDgAWnRzut1hFJeczY1tjQQno6f6s+nMydLN26WuU4s3UYvOu" + "OsUxRlJu7TSRHqDC3lSE5XggVkzdaPkuKGQbGpny+01/47hfXXNB7HntWNZ6N2Vw" + "p7G6OfY+YQrZwIaQmhrIqJZuigsrbe3W+gdn5ykE9+Ky0VgVUsfxo52mwFYs1JKY" + "2PGDuWx8M6DlS6qQkvHaRUo0FMd8TsSlbF0/v965qGFKhSDeQoMpYnwcmQilRh/0" + "ayLThlHLN81gSkJjVrPI0Y8xCVPB4twb1PFUd2fPM3sA1tJ83sZ5v8vgFv2yofKR" + "PB0t6JzUA81mSqM3kxl5e+IZwhYAyO0OTg3/fs8HqGTNKd9BqoUwSRBzp06JMg5b" + "rUCGwbCUDI0mxadJ3Bz4WxR6fyNpBK2yAinWEsikxqEt" + "\"}" + "]," + "\"trust_stores\": [" /* named cert chains */ + "{" + "\"name\": \"le_via_isrg\"," + "\"stack\": [" + "\"isrg_root_x1\"," + "\"LEX3_isrg_root_x1\"" + "]" + "}" + "]," + "\"s\": [" + "{\"mintest\": {" + "\"endpoint\":" "\"${servername}\"," + "\"port\":" "443," + "\"protocol\":" "\"h1\"," + "\"http_method\":" "\"GET\"," + "\"http_url\":" "\"\"," + "\"tls\":" "true," + "\"opportunistic\":" "true," + "\"retry\":" "\"default\"," + "\"tls_trust_store\":" "\"le_via_isrg\"," + "\"metadata\": [" + "{\"servername\": \"\"}" + "]" + "}}" + "]}" +; + +#endif + +typedef struct myss { + struct lws_ss_handle *ss; + void *opaque_data; + /* ... application specific state ... */ + lws_sorted_usec_list_t sul; +} myss_t; + +/* secure streams payload interface */ + +static int +myss_rx(void *userobj, const uint8_t *buf, size_t len, int flags) +{ +// myss_t *m = (myss_t *)userobj; + + lwsl_user("%s: len %d, flags: %d\n", __func__, (int)len, flags); + lwsl_hexdump_info(buf, len); + + /* + * If we received the whole message, for our example it means + * we are done. + */ + if (flags & LWSSS_FLAG_EOM) { + bad = 0; + interrupted = 1; + } + + return 0; +} + +static int +myss_tx(void *userobj, lws_ss_tx_ordinal_t ord, uint8_t *buf, size_t *len, + int *flags) +{ + //myss_t *m = (myss_t *)userobj; + + return 0; +} + +static int +myss_state(void *userobj, void *sh, lws_ss_constate_t state, + lws_ss_tx_ordinal_t ack) +{ + myss_t *m = (myss_t *)userobj; + + lwsl_user("%s: %s, ord 0x%x\n", __func__, lws_ss_state_name(state), + (unsigned int)ack); + + switch (state) { + case LWSSSCS_CREATING: + lwsl_notice("%s: CREATING: setting servername metadata to %s\n", + __func__, server_name_or_url); + lws_ss_set_metadata(m->ss, "servername", server_name_or_url, strlen(server_name_or_url)); + lws_ss_client_connect(m->ss); + break; + case LWSSSCS_ALL_RETRIES_FAILED: + /* if we're out of retries, we want to close the app and FAIL */ + interrupted = 1; + break; + case LWSSSCS_QOS_ACK_REMOTE: + lwsl_notice("%s: LWSSSCS_QOS_ACK_REMOTE\n", __func__); + break; + default: + break; + } + + return 0; +} + +static int +app_system_state_nf(lws_state_manager_t *mgr, lws_state_notify_link_t *link, + int current, int target) +{ + struct lws_context *context = lws_system_context_from_system_mgr(mgr); + + /* + * For the things we care about, let's notice if we are trying to get + * past them when we haven't solved them yet, and make the system + * state wait while we trigger the dependent action. + */ + switch (target) { + + case LWS_SYSTATE_OPERATIONAL: + if (current == LWS_SYSTATE_OPERATIONAL) { + lws_ss_info_t ssi; + + /* We're making an outgoing secure stream ourselves */ + + memset(&ssi, 0, sizeof(ssi)); + ssi.handle_offset = offsetof(myss_t, ss); + ssi.opaque_user_data_offset = offsetof(myss_t, + opaque_data); + ssi.rx = myss_rx; + ssi.tx = myss_tx; + ssi.state = myss_state; + ssi.user_alloc = sizeof(myss_t); + ssi.streamtype = "mintest"; + + if (lws_ss_create(context, 0, &ssi, NULL, NULL, + NULL, NULL)) { + lwsl_err("%s: failed to create secure stream\n", + __func__); + return -1; + } + } + break; + } + + return 0; +} + +static lws_state_notify_link_t * const app_notifier_list[] = { + &nl, NULL +}; + +static void +sigint_handler(int sig) +{ + interrupted = 1; +} + +int main(int argc, const char **argv) +{ + struct lws_context_creation_info info; + struct lws_context *context; + const char *p; + int n = 0; + + signal(SIGINT, sigint_handler); + + memset(&info, 0, sizeof info); + lws_cmdline_option_handle_builtin(argc, argv, &info); + + lwsl_user("LWS secure streams test client [-d]\n"); + + /* these options are mutually exclusive if given */ + + if (lws_cmdline_option(argc, argv, "--force-portal")) + force_cpd_fail_portal = 1; + + if (lws_cmdline_option(argc, argv, "--force-no-internet")) + force_cpd_fail_no_internet = 1; + + info.fd_limit_per_thread = 1 + 6 + 1; + info.port = CONTEXT_PORT_NO_LISTEN; + +#if defined(LWS_SS_USE_SSPC) + info.protocols = lws_sspc_protocols; + + /* connect to ssproxy via UDS by default, else via + * tcp connection to this port */ + if ((p = lws_cmdline_option(argc, argv, "-p"))) + info.ss_proxy_port = atoi(p); + + /* UDS "proxy.ss.lws" in abstract namespace, else this socket + * path; when -p given this can specify the network interface + * to bind to */ + if ((p = lws_cmdline_option(argc, argv, "-i"))) + info.ss_proxy_bind = p; + + /* if -p given, -a specifies the proxy address to connect to */ + if ((p = lws_cmdline_option(argc, argv, "-a"))) + info.ss_proxy_address = p; +#else + info.pss_policies_json = default_ss_policy; + info.options = LWS_SERVER_OPTION_EXPLICIT_VHOSTS | + LWS_SERVER_OPTION_DO_SSL_GLOBAL_INIT; +#endif + + if ((p = lws_cmdline_option(argc, argv, "-u"))) + server_name_or_url = p; + + /* integrate us with lws system state management when context created */ + + nl.name = "app"; + nl.notify_cb = app_system_state_nf; + info.register_notifier_list = app_notifier_list; + + /* create the context */ + + context = lws_create_context(&info); + if (!context) { + lwsl_err("lws init failed\n"); + return 1; + } + + + /* the event loop */ + + while (n >= 0 && !interrupted) + n = lws_service(context, 0); + + lws_context_destroy(context); + + lwsl_user("Completed: %s\n", bad ? "failed" : "OK"); + + return bad; +} diff -Nru libwebsockets-3.2.1/minimal-examples/secure-streams/minimal-secure-streams-metadata/README.md libwebsockets-4.1.6/minimal-examples/secure-streams/minimal-secure-streams-metadata/README.md --- libwebsockets-3.2.1/minimal-examples/secure-streams/minimal-secure-streams-metadata/README.md 1970-01-01 00:00:00.000000000 +0000 +++ libwebsockets-4.1.6/minimal-examples/secure-streams/minimal-secure-streams-metadata/README.md 2020-12-01 17:40:26.000000000 +0000 @@ -0,0 +1,66 @@ +# lws minimal secure streams + +The application goes to https://warmcat.com and reads index.html there. + +It does it using Secure Streams... the main code in minimal-secure-streams.c +just sets up the context and opens a secure stream of type "mintest". + +The handler for state changes and payloads for "mintest" is in ss-myss.c + +The information about how a "mintest" stream should connect and the +protocol it uses is kept separated in policy-database.c + +## build + +``` + $ cmake . && make +``` + +## usage + +Commandline option|Meaning +---|--- +-d |Debug verbosity in decimal, eg, -d15 +-f| Force connecting to the wrong endpoint to check backoff retry flow +-p| Run as proxy server for clients to connect to over unix domain socket +--force-portal|Force the SS Captive Portal Detection to feel it's behind a portal +--force-no-internet|Force the SS Captive Portal Detection to feel it can't reach the internet + +``` +[2019/08/12 07:16:11:0045] USR: LWS minimal secure streams [-d] [-f] +[2019/08/12 07:16:12:6102] USR: myss_state: LWSSSCS_CREATING, ord 0x0 +[2019/08/12 07:16:12:6107] USR: myss_state: LWSSSCS_POLL, ord 0x0 +[2019/08/12 07:16:12:6117] N: lws_ss_client_connect: connecting h1get warmcat.com / +[2019/08/12 07:16:12:6118] USR: myss_state: LWSSSCS_CONNECTING, ord 0x0 +[2019/08/12 07:16:13:4171] USR: myss_state: LWSSSCS_CONNECTED, ord 0x0 +[2019/08/12 07:16:13:4222] USR: myss_rx: len 1024, flags: 1 +[2019/08/12 07:16:13:4243] USR: myss_rx: len 1024, flags: 0 +[2019/08/12 07:16:13:4244] USR: myss_rx: len 1024, flags: 0 +[2019/08/12 07:16:13:4244] USR: myss_rx: len 1024, flags: 0 +[2019/08/12 07:16:13:4245] USR: myss_rx: len 1024, flags: 0 +[2019/08/12 07:16:13:4246] USR: myss_rx: len 1024, flags: 0 +[2019/08/12 07:16:13:4247] USR: myss_rx: len 1024, flags: 0 +[2019/08/12 07:16:13:4252] USR: myss_rx: len 1015, flags: 0 +[2019/08/12 07:16:13:4264] USR: myss_rx: len 1024, flags: 0 +[2019/08/12 07:16:13:4265] USR: myss_rx: len 1024, flags: 0 +[2019/08/12 07:16:13:4266] USR: myss_rx: len 1024, flags: 0 +[2019/08/12 07:16:13:4267] USR: myss_rx: len 1024, flags: 0 +[2019/08/12 07:16:13:4268] USR: myss_rx: len 1024, flags: 0 +[2019/08/12 07:16:13:4268] USR: myss_rx: len 1024, flags: 0 +[2019/08/12 07:16:13:4269] USR: myss_rx: len 1024, flags: 0 +[2019/08/12 07:16:13:4270] USR: myss_rx: len 1015, flags: 0 +[2019/08/12 07:16:13:4278] USR: myss_rx: len 1024, flags: 0 +[2019/08/12 07:16:13:4279] USR: myss_rx: len 1024, flags: 0 +[2019/08/12 07:16:13:4280] USR: myss_rx: len 1024, flags: 0 +[2019/08/12 07:16:13:4281] USR: myss_rx: len 1024, flags: 0 +[2019/08/12 07:16:13:4282] USR: myss_rx: len 1024, flags: 0 +[2019/08/12 07:16:13:4283] USR: myss_rx: len 1024, flags: 0 +[2019/08/12 07:16:13:4283] USR: myss_rx: len 1024, flags: 0 +[2019/08/12 07:16:13:4284] USR: myss_rx: len 1015, flags: 0 +[2019/08/12 07:16:13:4287] USR: myss_rx: len 1024, flags: 0 +[2019/08/12 07:16:13:4288] USR: myss_rx: len 947, flags: 0 +[2019/08/12 07:16:13:4293] USR: myss_rx: len 0, flags: 2 +[2019/08/12 07:16:13:4399] USR: myss_state: LWSSSCS_DISCONNECTED, ord 0x0 +[2019/08/12 07:16:13:4761] USR: myss_state: LWSSSCS_DESTROYING, ord 0x0 +[2019/08/12 07:16:13:4781] USR: Completed: OK +``` diff -Nru libwebsockets-3.2.1/minimal-examples/secure-streams/minimal-secure-streams-policy2c/CMakeLists.txt libwebsockets-4.1.6/minimal-examples/secure-streams/minimal-secure-streams-policy2c/CMakeLists.txt --- libwebsockets-3.2.1/minimal-examples/secure-streams/minimal-secure-streams-policy2c/CMakeLists.txt 1970-01-01 00:00:00.000000000 +0000 +++ libwebsockets-4.1.6/minimal-examples/secure-streams/minimal-secure-streams-policy2c/CMakeLists.txt 2020-12-01 17:40:26.000000000 +0000 @@ -0,0 +1,28 @@ +project(lws-minimal-secure-streams-policy2c C) +cmake_minimum_required(VERSION 2.8) +find_package(libwebsockets CONFIG REQUIRED) +list(APPEND CMAKE_MODULE_PATH ${LWS_CMAKE_DIR}) +include(CheckCSourceCompiles) +include(LwsCheckRequirements) + +set(SAMP lws-minimal-secure-streams-policy2c) + +set(requirements 1) +require_lws_config(LWS_ROLE_H1 1 requirements) +require_lws_config(LWS_ROLE_H2 1 requirements) +require_lws_config(LWS_ROLE_MQTT 1 requirements) +require_lws_config(LWS_WITHOUT_CLIENT 0 requirements) +require_lws_config(LWS_WITH_SECURE_STREAMS 1 requirements) +require_lws_config(LWS_WITH_SECURE_STREAMS_STATIC_POLICY_ONLY 0 requirements) + +if (requirements) + add_executable(${SAMP} minimal-secure-streams.c) + + if (websockets_shared) + target_link_libraries(${SAMP} websockets_shared ${LIBWEBSOCKETS_DEP_LIBS}) + add_dependencies(${SAMP} websockets_shared) + else() + target_link_libraries(${SAMP} websockets ${LIBWEBSOCKETS_DEP_LIBS}) + endif() + +endif() diff -Nru libwebsockets-3.2.1/minimal-examples/secure-streams/minimal-secure-streams-policy2c/minimal-secure-streams.c libwebsockets-4.1.6/minimal-examples/secure-streams/minimal-secure-streams-policy2c/minimal-secure-streams.c --- libwebsockets-3.2.1/minimal-examples/secure-streams/minimal-secure-streams-policy2c/minimal-secure-streams.c 1970-01-01 00:00:00.000000000 +0000 +++ libwebsockets-4.1.6/minimal-examples/secure-streams/minimal-secure-streams-policy2c/minimal-secure-streams.c 2020-12-01 17:40:26.000000000 +0000 @@ -0,0 +1,573 @@ +/* + * lws-minimal-secure-streams-policy2c + * + * Written in 2010-2020 by Andy Green + * + * This file is made available under the Creative Commons CC0 1.0 + * Universal Public Domain Dedication. + * + * + * This reads policy JSON on stdin and emits it as compileable + * C structs. + * + * It's useful if your platform is too space-constrained for a + * JSON policy and needs to build a static policy in C via + * LWS_WITH_SECURE_STREAMS_STATIC_POLICY_ONLY... this way you can + * still create and maintain the JSON policy but implement it directly + * as C structs in your code. + */ + +#include +#include +#include +#include +#include + +static int interrupted, bad = 1; + + +static void +sigint_handler(int sig) +{ + interrupted = 1; +} + +struct aggstr { + struct aggstr *next; + + const char *orig; + size_t offset; +}; + +static struct aggstr *rbomap, /* retry / backoff object map */ + *trustmap, /* trust store map */ + *certmap; /* x.509 cert map */ +static size_t last_offset; + + + +static const char * +purify_csymbol(const char *in, char *temp, size_t templen) +{ + const char *otemp = temp; + + assert (strlen(in) < templen); + + while (*in) { + if ((*in >= 'a' && *in <= 'z') || (*in >= 'A' && *in <= 'Z') || + (*in >= '0' && *in <= '9')) + *temp++ = *in; + else + *temp++ = '_'; + + in++; + } + + *temp = '\0'; + + return otemp; +} + +int main(int argc, const char **argv) +{ + const lws_ss_policy_t *pol, *lastpol = NULL; + struct lws_context_creation_info info; + size_t json_size = 0, est = 0; + struct lws_context *context; + char prev[128], curr[128]; + int unique_rbo = 0, m, n; + char buf[64], buf1[64]; + lws_ss_metadata_t *md; + struct aggstr *a, *a1; + + signal(SIGINT, sigint_handler); + + memset(&info, 0, sizeof info); + lws_cmdline_option_handle_builtin(argc, argv, &info); + + lwsl_user("LWS secure streams policy2c [-d]\n"); + + info.fd_limit_per_thread = 1 + 6 + 1; + info.port = CONTEXT_PORT_NO_LISTEN; + + info.options = LWS_SERVER_OPTION_EXPLICIT_VHOSTS | + LWS_SERVER_OPTION_DO_SSL_GLOBAL_INIT; + + /* create the context */ + + context = lws_create_context(&info); + if (!context) { + lwsl_err("lws init failed\n"); + return 1; + } + + lws_ss_policy_parse_begin(context, 0); + + printf("/*\n * Autogenerated from the following JSON policy\n */\n\n#if 0\n"); + + do { + int m, n = read(0, buf, sizeof(buf)); + + if (n < 1) + break; + + m = lws_ss_policy_parse(context, (uint8_t *)buf, (size_t)n); + + printf("%.*s", n, buf); + json_size += n; + + if (m < 0 && m != LEJP_CONTINUE) { + lwsl_err("%s: policy parse failed... lws has WITH_ROLEs" + "for what's in the JSON?\n", __func__); + goto bail; + } + } while (1); + + printf("\n\n Original JSON size: %zu\n#endif\n\n", json_size); + + lwsl_notice("%s: parsed JSON\n", __func__); + + /* + * Well, this is fun, isn't it... we have parsed the JSON into in-memory + * policy objects, and it has set the context policy pointer to the head + * of those but has not set the new policy (which would free the x.509). + * + * We want to walk the streamtype list first discovering unique objects + * and strings referenced there and emitting them compactly as C data, + * and then second to emit the streamtype linked-list referring to those + * objects. + * + * For const strings, we aggregate them and avoid generating extra + * pointers by encoding the reference as &_lws_ss_staticpol_str[xxx] + * where xxx is the fixed offset in the aggregated monster-string. When + * doing that, we keep a map of original pointers to offsets. + * + * Although we want to minimize memory used by the emitted C, we don't + * have to sweat memory during this conversion since it's happening on a + * PC + */ + + pol = lws_ss_policy_get(context); + + while (pol) { + + /* + * Walk the metadata list gathering strings and issuing the + * C struct + */ + + md = pol->metadata; + + if (md) { + int idx = 0; + + printf("\nstatic const lws_ss_metadata_t "); + + prev[0] = '\0'; + md = pol->metadata; + while (md) { + + est += sizeof(lws_ss_metadata_t); + + lws_snprintf(curr, sizeof(curr), "_md_%s_%s", + purify_csymbol(pol->streamtype, buf, + sizeof(buf)), + purify_csymbol(md->name, buf1, + sizeof(buf1))); + + printf("%s = {\n", curr); + if (prev[0]) + printf("\t.next = (void *)&%s, \n", prev); + + printf("\t.name = \"%s\",\n", (const char *)md->name); + if (md->value) + printf("\t.value = (void *)\"%s\",\n", (const char *)md->value); + + printf("\t.length = %d,\n", idx++); // md->length); + + printf("}"); + if (md->next) + printf(",\n"); + + lws_strncpy(prev, curr, sizeof(prev)); + + md = md->next; + } + + printf(";\n\n"); + } + + /* + * Create unique retry policies... have we seen this guy? + */ + + if (pol->retry_bo) { + a = rbomap; + while (a) { + if (a->orig == (const char *)pol->retry_bo) + break; + + a = a->next; + } + + if (!a) { + + /* We haven't seen it before and need to create it */ + + a = malloc(sizeof(*a)); + if (!a) + goto bail; + a->next = rbomap; + a->offset = unique_rbo++; + a->orig = (const char *)pol->retry_bo; + rbomap = a; + + printf("static const uint32_t _rbo_bo_%zu[] = {\n", + a->offset); + for (n = 0; n < pol->retry_bo->retry_ms_table_count; n++) + printf(" %u, ", (unsigned int) + pol->retry_bo->retry_ms_table[n]); + + est += sizeof(uint32_t) * + pol->retry_bo->retry_ms_table_count; + + printf("\n};\nstatic const " + "lws_retry_bo_t _rbo_%zu = {\n", a->offset); + + printf("\t.retry_ms_table = _rbo_bo_%zu,\n", + a->offset); + printf("\t.retry_ms_table_count = %u,\n", + pol->retry_bo->retry_ms_table_count); + printf("\t.conceal_count = %u,\n", + pol->retry_bo->conceal_count); + printf("\t.secs_since_valid_ping = %u,\n", + pol->retry_bo->secs_since_valid_ping); + printf("\t.secs_since_valid_hangup = %u,\n", + pol->retry_bo->secs_since_valid_hangup); + printf("\t.jitter_percent = %u,\n", + pol->retry_bo->jitter_percent); + printf("};\n"); + + est += sizeof(lws_retry_bo_t); + } + } + + /* + * How about his trust store, it's new to us? + */ + + if (pol->trust.store) { + a = trustmap; + while (a) { + if (a->orig == (const char *)pol->trust.store) + break; + + a = a->next; + } + + if (!a) { + + /* it's new to us... */ + + a = malloc(sizeof(*a)); + if (!a) + goto bail; + a->next = trustmap; + a->offset = 0; /* don't care, just track seen */ + a->orig = (const char *)pol->trust.store; + trustmap = a; + + /* + * Have a look through his x.509 stack... + * any that're new to us? + */ + + for (n = 0; n < pol->trust.store->count; n++) { + if (!pol->trust.store->ssx509[n]) + continue; + a1 = certmap; + while (a1) { + if (a1->orig == (const char *)pol->trust.store->ssx509[n]) + break; + a1 = a1->next; + } + + if (!a1) { + /* + * This x.509 cert is new to us... + * let's capture the DER + */ + + a1 = malloc(sizeof(*a1)); + if (!a1) + goto bail; + a1->next = certmap; + a1->offset = 0; /* don't care, just track seen */ + a1->orig = (const char *)pol->trust.store->ssx509[n]; + certmap = a1; + + printf("static const uint8_t _ss_der_%s[] = {\n", + purify_csymbol(pol->trust.store->ssx509[n]->vhost_name, + buf, sizeof(buf))); + + for (m = 0; m < (int)pol->trust.store->ssx509[n]->ca_der_len; m++) { + if ((m & 7) == 0) + printf("\t/* 0x%3x */ ", m); + + printf("0x%02X, ", pol->trust.store->ssx509[n]->ca_der[m]); + if ((m & 7) == 7) + printf("\n"); + } + + printf("\n};\nstatic const lws_ss_x509_t _ss_x509_%s = {\n", + purify_csymbol(pol->trust.store->ssx509[n]->vhost_name, + buf, sizeof(buf))); + printf("\t.vhost_name = \"%s\",\n", pol->trust.store->ssx509[n]->vhost_name); + printf("\t.ca_der = _ss_der_%s,\n", + purify_csymbol(pol->trust.store->ssx509[n]->vhost_name, + buf, sizeof(buf))); + printf("\t.ca_der_len = %zu,\n", pol->trust.store->ssx509[n]->ca_der_len); + printf("};\n"); + + est += sizeof(lws_ss_x509_t) + pol->trust.store->ssx509[n]->ca_der_len; + } + + } + + + printf("static const lws_ss_trust_store_t _ss_ts_%s = {\n", + purify_csymbol(pol->trust.store->name, + buf, sizeof(buf))); + + printf("\t.name = \"%s\",\n", pol->trust.store->name); + printf("\t.ssx509 = {\n"); + + for (n = pol->trust.store->count - 1; n >= 0 ; n--) + printf("\t\t&_ss_x509_%s,\n", + pol->trust.store->ssx509[n]->vhost_name); + + printf("\t}\n};\n"); + + est += sizeof(lws_ss_trust_store_t); + + } + } + + pol = pol->next; + } + + + + /* + * The streamtypes + */ + + pol = lws_ss_policy_get(context); + + printf("\nstatic const lws_ss_policy_t "); + prev[0] = '\0'; + + while (pol) { + + est += sizeof(*pol); + + lws_snprintf(curr, sizeof(curr), "_ssp_%s", + purify_csymbol(pol->streamtype, buf, sizeof(buf))); + printf("%s = {\n", curr); + + + if (prev[0]) + printf("\t.next = (void *)&%s,\n", prev); + + printf("\t.streamtype = \"%s\",\n", pol->streamtype); + if (pol->endpoint) + printf("\t.endpoint = \"%s\",\n", pol->endpoint); + if (pol->rideshare_streamtype) + printf("\t.rideshare_streamtype = \"%s\",\n", + pol->rideshare_streamtype); + if (pol->payload_fmt) + printf("\t.payload_fmt = \"%s\",\n", + pol->payload_fmt); + if (pol->socks5_proxy) + printf("\t.socks5_proxy = \"%s\",\n", + pol->socks5_proxy); + + { + lws_ss_metadata_t *nv = pol->metadata, *last = NULL; + + while (nv) { + last = nv; + nv = nv->next; + } + if (pol->metadata) + printf("\t.metadata = (void *)&_md_%s_%s,\n", + purify_csymbol(pol->streamtype, buf, sizeof(buf)), + purify_csymbol(last->name, buf1, sizeof(buf1))); + } + + + switch (pol->protocol) { + case LWSSSP_H1: + case LWSSSP_H2: + case LWSSSP_WS: + + printf("\t.u = {\n\t\t.http = {\n"); + + if (pol->u.http.method) + printf("\t\t\t.method = \"%s\",\n", + pol->u.http.method); + if (pol->u.http.url) + printf("\t\t\t.url = \"%s\",\n", + pol->u.http.url); + if (pol->u.http.multipart_name) + printf("\t\t\t.multipart_name = \"%s\",\n", + pol->u.http.multipart_name); + if (pol->u.http.multipart_filename) + printf("\t\t\t.multipart_filename = \"%s\",\n", + pol->u.http.multipart_filename); + if (pol->u.http.multipart_content_type) + printf("\t\t\t.multipart_content_type = \"%s\",\n", + pol->u.http.multipart_content_type); + if (pol->u.http.auth_preamble) + printf("\t\t\t.auth_preamble = \"%s\",\n", + pol->u.http.auth_preamble); + + if (pol->u.http.blob_header[0]) { + printf("\t\t\t.blob_header = {\n"); + for (n = 0; n < (int)LWS_ARRAY_SIZE(pol->u.http.blob_header); n++) + if (pol->u.http.blob_header[n]) + printf("\t\t\t\t\"%s\",\n", + pol->u.http.blob_header[n]); + + printf("\t\t\t},\n"); + } + + if (pol->protocol == LWSSSP_WS) { + printf("\t\t\t.u = {\n\t\t\t\t.ws = {\n"); + if (pol->u.http.u.ws.subprotocol) + printf("\t\t\t\t\t.subprotocol = \"%s\",\n", + pol->u.http.u.ws.subprotocol); + printf("\t\t\t\t\t.binary = %u\n", pol->u.http.u.ws.binary); + printf("\t\t\t\t}\n\t\t\t},\n"); + } + + if (pol->u.http.resp_expect) + printf("\t\t\t.resp_expect = %u,\n", pol->u.http.resp_expect); + if (pol->u.http.fail_redirect) + printf("\t\t\t.fail_redirect = %u,\n", pol->u.http.fail_redirect); + + printf("\t\t}\n\t},\n"); + + break; + case LWSSSP_MQTT: + + printf("\t.u = {\n\t\t.mqtt = {\n"); + + if (pol->u.mqtt.topic) + printf("\t\t\t.topic = \"%s\",\n", + pol->u.mqtt.topic); + if (pol->u.mqtt.subscribe) + printf("\t\t\t.subscribe = \"%s\",\n", + pol->u.mqtt.subscribe); + if (pol->u.mqtt.will_topic) + printf("\t\t\t.will_topic = \"%s\",\n", + pol->u.mqtt.will_topic); + if (pol->u.mqtt.will_message) + printf("\t\t\t.will_message = \"%s\",\n", + pol->u.mqtt.will_message); + + if (pol->u.mqtt.keep_alive) + printf("\t\t\t.keep_alive = %u,\n", + pol->u.mqtt.keep_alive); + if (pol->u.mqtt.qos) + printf("\t\t\t.qos = %u,\n", + pol->u.mqtt.qos); + if (pol->u.mqtt.clean_start) + printf("\t\t\t.clean_start = %u,\n", + pol->u.mqtt.clean_start); + if (pol->u.mqtt.will_qos) + printf("\t\t\t.will_qos = %u,\n", + pol->u.mqtt.will_qos); + if (pol->u.mqtt.will_retain) + printf("\t\t\t.will_retain = %u,\n", + pol->u.mqtt.will_retain); + + printf("\t\t}\n\t},\n"); + + break; + default: + lwsl_err("%s: unknown ss protocol index %d\n", __func__, + pol->protocol); + goto bail; + } + +#if 0 + const lws_ss_trust_store_t *trust_store; /**< CA certs needed for conn + validation, only set between policy parsing and vhost creation */ +#endif + + if (pol->retry_bo) { + a = rbomap; + while (a) { + if (a->orig == (const char *)pol->retry_bo) + break; + + a = a->next; + } + if (!a) + goto bail; + + printf("\t.retry_bo = &_rbo_%zu,\n", a->offset); + } + + if (pol->timeout_ms) + printf("\t.timeout_ms = %u,\n", pol->timeout_ms); + if (pol->flags) + printf("\t.flags = 0x%x,\n", pol->flags); + if (pol->port) + printf("\t.port = %u,\n", pol->port); + if (pol->metadata_count) + printf("\t.metadata_count = %u,\n", pol->metadata_count); + printf("\t.protocol = %u,\n", pol->protocol); + if (pol->client_cert) + printf("\t.client_cert = %u,\n", pol->client_cert); + + if (pol->trust.store) + printf("\t.trust = {.store = &_ss_ts_%s},\n", + purify_csymbol(pol->trust.store->name, + buf, sizeof(buf))); + + + printf("}"); + if (pol->next) + printf(",\n"); + + lws_strncpy(prev, curr, sizeof(prev)); + + lastpol = pol; + + pol = pol->next; + } + + printf(";\n"); + if (lastpol) + printf("#define _ss_static_policy_entry _ssp_%s\n", + purify_csymbol(lastpol->streamtype, buf, sizeof(buf))); + + est += last_offset; + + printf("/* estimated footprint %zu (when sizeof void * = %zu) */\n", + est, sizeof(void *)); + + lws_ss_policy_parse_abandon(context); + bad = 0; + +bail: + + + lws_context_destroy(context); + + lwsl_user("Completed: %s\n", bad ? "failed" : "OK"); + + return bad; +} diff -Nru libwebsockets-3.2.1/minimal-examples/secure-streams/minimal-secure-streams-policy2c/README.md libwebsockets-4.1.6/minimal-examples/secure-streams/minimal-secure-streams-policy2c/README.md --- libwebsockets-3.2.1/minimal-examples/secure-streams/minimal-secure-streams-policy2c/README.md 1970-01-01 00:00:00.000000000 +0000 +++ libwebsockets-4.1.6/minimal-examples/secure-streams/minimal-secure-streams-policy2c/README.md 2020-12-01 17:40:26.000000000 +0000 @@ -0,0 +1,49 @@ +# lws minimal secure streams policy2c + +This application parses a JSON policy passed on stdin and emits the +equivalent of it in C structs ready for compilation. + +This is useful in the case your platform doesn't use a dynamic JSON +policy and is space-constrained, you can still form and maintain the +policy in JSON, but with this utility convert it into compileable C. + +**Notice** this depends on LWS_ROLE_H1, LWS_ROLE_H2, LWS_ROLE_WS and +LWS_ROLE_MQTT build of lws, since it has to be able to work with any kind +of policy content. + +## build + +``` + $ cmake . && make +``` + +## usage + +Commandline option|Meaning +---|--- +-d |Debug verbosity in decimal, eg, -d15 + +``` +$ cat mypolicy.json | lws-minimal-secure-streams-policy2c + +(on stdout) + +static const uint32_t _rbo_bo_0[] = { + 1000, 2000, 3000, 5000, 10000, +}; +static const lws_retry_bo_t _rbo_0 = { + .retry_ms_table = _rbo_bo_0, + .retry_ms_table_count = 5, + .conceal_count = 5, + .secs_since_valid_ping = 30, + .secs_since_valid_hangup = 35, + .jitter_percent = 20, +}; +static const uint8_t _ss_der_amazon_root_ca_1[] = { + /* 0x 0 */ 0x30, 0x82, 0x03, 0x41, 0x30, 0x82, 0x02, 0x29, + /* 0x 8 */ 0xA0, 0x03, 0x02, 0x01, 0x02, 0x02, 0x13, 0x06, + /* 0x 10 */ 0x6C, 0x9F, 0xCF, 0x99, 0xBF, 0x8C, 0x0A, 0x39, + /* 0x 18 */ 0xE2, 0xF0, 0x78, 0x8A, 0x43, 0xE6, 0x96, 0x36, + /* 0x 20 */ 0x5B, 0xCA, 0x30, 0x0D, 0x06, 0x09, 0x2A, 0x86, +... +``` diff -Nru libwebsockets-3.2.1/minimal-examples/secure-streams/minimal-secure-streams-post/CMakeLists.txt libwebsockets-4.1.6/minimal-examples/secure-streams/minimal-secure-streams-post/CMakeLists.txt --- libwebsockets-3.2.1/minimal-examples/secure-streams/minimal-secure-streams-post/CMakeLists.txt 1970-01-01 00:00:00.000000000 +0000 +++ libwebsockets-4.1.6/minimal-examples/secure-streams/minimal-secure-streams-post/CMakeLists.txt 2020-12-01 17:40:26.000000000 +0000 @@ -0,0 +1,49 @@ +project(lws-minimal-secure-streams-post C) +cmake_minimum_required(VERSION 2.8) +find_package(libwebsockets CONFIG REQUIRED) +list(APPEND CMAKE_MODULE_PATH ${LWS_CMAKE_DIR}) +include(CheckCSourceCompiles) +include(LwsCheckRequirements) + +set(SAMP lws-minimal-secure-streams-post) + +set(requirements 1) +require_lws_config(LWS_ROLE_H1 1 requirements) +require_lws_config(LWS_WITHOUT_CLIENT 0 requirements) +require_lws_config(LWS_WITH_SECURE_STREAMS 1 requirements) +require_lws_config(LWS_WITH_SECURE_STREAMS_STATIC_POLICY_ONLY 0 requirements) +require_lws_config(LWS_WITH_SYS_STATE 1 requirements) + +if (requirements) + add_executable(${SAMP} minimal-secure-streams-post.c) + + if (LWS_CTEST_INTERNET_AVAILABLE) + add_test(NAME sspost-warmcat COMMAND lws-minimal-secure-streams-post) + set_tests_properties(sspost-warmcat + PROPERTIES + WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}/minimal-examples/secure-streams/minimal-secure-streams-post + TIMEOUT 20) + endif() + + if (websockets_shared) + target_link_libraries(${SAMP} websockets_shared ${LIBWEBSOCKETS_DEP_LIBS}) + add_dependencies(${SAMP} websockets_shared) + else() + target_link_libraries(${SAMP} websockets ${LIBWEBSOCKETS_DEP_LIBS}) + endif() + + CHECK_C_SOURCE_COMPILES("#include \nint main(void) {\ni#if defined(LWS_WITH_SECURE_STREAMS_PROXY_API)\n return 0;\n #else\n fail\n #endif\n return 0;\n}\n" HAS_LWS_WITH_SECURE_STREAMS_PROXY_API) + + if (HAS_LWS_WITH_SECURE_STREAMS_PROXY_API OR LWS_WITH_SECURE_STREAMS_PROXY_API) + add_compile_options(-DLWS_SS_USE_SSPC) + + add_executable(${SAMP}-client minimal-secure-streams-post.c) + if (websockets_shared) + target_link_libraries(${SAMP}-client websockets_shared ${LIBWEBSOCKETS_DEP_LIBS}) + add_dependencies(${SAMP}-client websockets_shared) + else() + target_link_libraries(${SAMP}-client websockets ${LIBWEBSOCKETS_DEP_LIBS}) + endif() + endif() + +endif() diff -Nru libwebsockets-3.2.1/minimal-examples/secure-streams/minimal-secure-streams-post/minimal-secure-streams-post.c libwebsockets-4.1.6/minimal-examples/secure-streams/minimal-secure-streams-post/minimal-secure-streams-post.c --- libwebsockets-3.2.1/minimal-examples/secure-streams/minimal-secure-streams-post/minimal-secure-streams-post.c 1970-01-01 00:00:00.000000000 +0000 +++ libwebsockets-4.1.6/minimal-examples/secure-streams/minimal-secure-streams-post/minimal-secure-streams-post.c 2020-12-01 17:40:26.000000000 +0000 @@ -0,0 +1,611 @@ +/* + * lws-minimal-secure-streams-post + * + * Written in 2010-2020 by Andy Green + * + * This file is made available under the Creative Commons CC0 1.0 + * Universal Public Domain Dedication. + * + * + * This demonstrates a minimal http client using secure streams api. + * + * It visits https://warmcat.com/ and receives the html page there. + * + * This example is built two different ways from the same source... one includes + * the policy everything needed to fulfil the stream directly. The other -client + * variant has no policy itself and some other minor init changes, and connects + * to the -proxy example to actually get the connection done. + * + * In the -client build case, the example does not even init the tls libraries + * since the proxy part will take care of all that. + */ + +#include +#include +#include +#include + +/* + * uncomment to force network traffic through 127.0.0.1:1080 + * + * On your local machine, you can run a SOCKS5 proxy like this + * + * $ ssh -N -D 0.0.0.0:1080 localhost -v + * + * If enabled, this also fetches a remote policy that also + * specifies that all traffic should go through the remote + * proxy. + */ +// #define VIA_LOCALHOST_SOCKS + +static int interrupted, bad = 1, force_cpd_fail_portal, + force_cpd_fail_no_internet; +static unsigned int timeout_ms = 3000; +static lws_state_notify_link_t nl; + +static const char * const postbody = + "--boundary\r\n" + "Content-Disposition: form-data; name=\"text\"\r\n" + "\r\n" + "value1\r\n" + "--boundary\r\n" + "Content-Disposition: form-data; " + "name=\"field2\"; filename=\"example.txt\"\r\n" + "\r\n" + "value2\r\n" + "00-0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef\r\n" + "01-0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef\r\n" + "02-0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef\r\n" + "03-0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef\r\n" + "04-0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef\r\n" + "05-0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef\r\n" + "06-0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef\r\n" + "07-0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef\r\n" + "08-0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef\r\n" + "09-0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef\r\n" + "0a-0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef\r\n" + "0b-0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef\r\n" + "0c-0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef\r\n" + "0d-0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef\r\n" + "0e-0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef\r\n" + "0f-0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef\r\n" + "10-0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef\r\n" + "11-0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef\r\n" + "12-0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef\r\n" + "13-0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef\r\n" + "14-0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef\r\n" + "15-0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef\r\n" + "16-0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef\r\n" + "17-0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef\r\n" + "18-0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef\r\n" + "19-0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef\r\n" + "1a-0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef\r\n" + "1b-0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef\r\n" + "1c-0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef\r\n" + "1d-0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef\r\n" + "1e-0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef\r\n" + "1f-0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef\r\n" + "20-0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef\r\n" + "21-0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef\r\n" + "22-0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef\r\n" + "23-0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef\r\n" + "24-0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef\r\n" + "25-0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef\r\n" + "26-0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef\r\n" + "27-0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef\r\n" + "28-0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef\r\n" + "29-0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef\r\n" + "2a-0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef\r\n" + "2b-0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef\r\n" + "2c-0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef\r\n" + "2d-0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef\r\n" + "2e-0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef\r\n" + "2f-0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef\r\n" + "30-0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef\r\n" + "31-0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef\r\n" + "32-0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef\r\n" + "33-0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef\r\n" + "34-0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef\r\n" + "35-0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef\r\n" + "36-0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef\r\n" + "37-0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef\r\n" + "38-0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef\r\n" + "39-0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef\r\n" + "3a-0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef\r\n" + "3b-0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef\r\n" + "3c-0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef\r\n" + "3d-0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef\r\n" + "3e-0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef\r\n" + "3f-0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef\r\n" + "40-0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef\r\n" + "41-0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef\r\n" + "42-0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef\r\n" + "43-0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef\r\n" + "44-0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef\r\n" + "45-0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef\r\n" + "46-0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef\r\n" + "47-0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef\r\n" + "48-0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef\r\n" + "49-0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef\r\n" + "4a-0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef\r\n" + "4b-0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef\r\n" + "4c-0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef\r\n" + "4d-0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef\r\n" + "4e-0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef\r\n" + "4f-0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef\r\n" + "--boundary--\r\n"; + +/* + * If the -proxy app is fulfilling our connection, then we don't need to have + * the policy in the client. + * + * When we build with LWS_SS_USE_SSPC, the apis hook up to a proxy process over + * a Unix Domain Socket. To test that, you need to separately run the + * ./lws-minimal-secure-streams-proxy test app on the same machine. + */ + +#if !defined(LWS_SS_USE_SSPC) +static const char * const default_ss_policy = + "{" + "\"release\":" "\"01234567\"," + "\"product\":" "\"myproduct\"," + "\"schema-version\":" "1," +#if defined(VIA_LOCALHOST_SOCKS) + "\"via-socks5\":" "\"127.0.0.1:1080\"," +#endif + + "\"retry\": [" /* named backoff / retry strategies */ + "{\"default\": {" + "\"backoff\": [" "1000," + "2000," + "3000," + "5000," + "10000" + "]," + "\"conceal\":" "5," + "\"jitterpc\":" "20," + "\"svalidping\":" "30," + "\"svalidhup\":" "35" + "}}" + "]," + "\"certs\": [" /* named individual certificates in BASE64 DER */ + /* + * Let's Encrypt certs for warmcat.com / libwebsockets.org + * + * We fetch the real policy from there using SS and switch to + * using that. + */ + "{\"isrg_root_x1\": \"" /* ISRG ROOT X1 */ + "MIIFazCCA1OgAwIBAgIRAIIQz7DSQONZRGPgu2OCiwAwDQYJKoZIhvcNAQELBQAw" + "TzELMAkGA1UEBhMCVVMxKTAnBgNVBAoTIEludGVybmV0IFNlY3VyaXR5IFJlc2Vh" + "cmNoIEdyb3VwMRUwEwYDVQQDEwxJU1JHIFJvb3QgWDEwHhcNMTUwNjA0MTEwNDM4" + "WhcNMzUwNjA0MTEwNDM4WjBPMQswCQYDVQQGEwJVUzEpMCcGA1UEChMgSW50ZXJu" + "ZXQgU2VjdXJpdHkgUmVzZWFyY2ggR3JvdXAxFTATBgNVBAMTDElTUkcgUm9vdCBY" + "MTCCAiIwDQYJKoZIhvcNAQEBBQADggIPADCCAgoCggIBAK3oJHP0FDfzm54rVygc" + "h77ct984kIxuPOZXoHj3dcKi/vVqbvYATyjb3miGbESTtrFj/RQSa78f0uoxmyF+" + "0TM8ukj13Xnfs7j/EvEhmkv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uigsrbe3W+gdn5ykE9+Ky0VgVUsfxo52mwFYs1JKY" + "2PGDuWx8M6DlS6qQkvHaRUo0FMd8TsSlbF0/v965qGFKhSDeQoMpYnwcmQilRh/0" + "ayLThlHLN81gSkJjVrPI0Y8xCVPB4twb1PFUd2fPM3sA1tJ83sZ5v8vgFv2yofKR" + "PB0t6JzUA81mSqM3kxl5e+IZwhYAyO0OTg3/fs8HqGTNKd9BqoUwSRBzp06JMg5b" + "rUCGwbCUDI0mxadJ3Bz4WxR6fyNpBK2yAinWEsikxqEt" + "\"}" + "]," + "\"trust_stores\": [" /* named cert chains */ + "{" + "\"name\": \"le_via_isrg\"," + "\"stack\": [" + "\"isrg_root_x1\"," + "\"LEX3_isrg_root_x1\"" + "]" + "}" + "]," + "\"s\": [" + /* + * "fetch_policy" decides from where the real policy + * will be fetched, if present. Otherwise the initial + * policy is treated as the whole, hardcoded, policy. + */ + "{\"fetch_policy\": {" + "\"endpoint\":" "\"warmcat.com\"," + "\"port\":" "443," + "\"protocol\":" "\"h1\"," + "\"http_method\":" "\"GET\"," +#if defined(VIA_LOCALHOST_SOCKS) + "\"http_url\":" "\"policy/minimal-proxy-socks.json\"," +#else + "\"http_url\":" "\"policy/minimal-proxy.json\"," +#endif + "\"tls\":" "true," + "\"opportunistic\":" "true," + "\"retry\":" "\"default\"," + "\"tls_trust_store\":" "\"le_via_isrg\"" + "}},{" + /* + * "captive_portal_detect" describes + * what to do in order to check if the path to + * the Internet is being interrupted by a + * captive portal. If there's a larger policy + * fetched from elsewhere, it should also include + * this since it needs to be done at least after + * every DHCP acquisition + */ + "\"captive_portal_detect\": {" + "\"endpoint\": \"connectivitycheck.android.com\"," + "\"http_url\": \"generate_204\"," + "\"port\": 80," + "\"protocol\": \"h1\"," + "\"http_method\": \"GET\"," + "\"opportunistic\": true," + "\"http_expect\": 204," + "\"http_fail_redirect\": true" + "}}" + "]}" +; + +#endif + +typedef struct myss { + struct lws_ss_handle *ss; + void *opaque_data; + /* ... application specific state ... */ + lws_sorted_usec_list_t sul; + + size_t pos; + size_t len; +} myss_t; + +#if !defined(LWS_SS_USE_SSPC) + +static const char *canned_root_token_payload = + "grant_type=refresh_token" + "&refresh_token=Atzr|IwEBIJedGXjDqsU_vMxykqOMg" + "SHfYe3CPcedueWEMWSDMaDnEmiW8RlR1Kns7Cb4B-TOSnqp7ifVsY4BMY2B8tpHfO39XP" + "zfu9HapGjTR458IyHX44FE71pWJkGZ79uVBpljP4sazJuk8XS3Oe_yLnm_DIO6fU1nU3Y" + "0flYmsOiOAQE_gRk_pdlmEtHnpMA-9rLw3mkY5L89Ty9kUygBsiFaYatouROhbsTn8-jW" + "k1zZLUDpT6ICtBXSnrCIg0pUbZevPFhTwdXd6eX-u4rq0W-XaDvPWFO7au-iPb4Zk5eZE" + "iX6sissYrtNmuEXc2uHu7MnQO1hHCaTdIO2CANVumf-PHSD8xseamyh04sLV5JgFzY45S" + "KvKMajiUZuLkMokOx86rjC2Hdkx5DO7G-dbG1ufBDG-N79pFMSs7Ck5pc283IdLoJkCQc" + "AGvTX8o8I29QqkcGou-9TKhOJmpX8As94T61ok0UqqEKPJ7RhfQHHYdCtsdwxgvfVr9qI" + "xL_hDCcTho8opCVX-6QhJHl6SQFlTw13" + "&client_id=" + "amzn1.application-oa2-client.4823334c434b4190a2b5a42c07938a2d"; + +#endif + +/* secure streams payload interface */ + +static int +myss_rx(void *userobj, const uint8_t *buf, size_t len, int flags) +{ +// myss_t *m = (myss_t *)userobj; + + lwsl_user("%s: len %d, flags: %d\n", __func__, (int)len, flags); + lwsl_hexdump_info(buf, len); + + /* + * If we received the whole message, for our example it means + * we are done. + */ + if (flags & LWSSS_FLAG_EOM) { + bad = 0; + interrupted = 1; + } + + return 0; +} + +static int +myss_tx(void *userobj, lws_ss_tx_ordinal_t ord, uint8_t *buf, size_t *len, + int *flags) +{ + myss_t *m = (myss_t *)userobj; + + if (m->pos == m->len) + return LWSSSSRET_TX_DONT_SEND; + + if (m->len - m->pos < *len) + *len = m->len - m->pos; + + *flags = 0; + if (!m->pos) + *flags |= LWSSS_FLAG_SOM; + + memcpy(buf, postbody + m->pos, *len); + + m->pos += *len; + if (m->pos == m->len) + *flags |= LWSSS_FLAG_EOM; + else + lws_ss_request_tx(m->ss); + + lwsl_notice("%s: write %d flags %d\n", __func__, (int)*len, (int)*flags); + + return 0; +} + +static int +myss_state(void *userobj, void *sh, lws_ss_constate_t state, + lws_ss_tx_ordinal_t ack) +{ + myss_t *m = (myss_t *)userobj; + + lwsl_user("%s: h %p, %s, ord 0x%x\n", __func__, m->ss, + lws_ss_state_name(state), (unsigned int)ack); + + switch (state) { + case LWSSSCS_CREATING: + + /* + * CREATING is only coming after we have asked the upstream + * proxy to create the stream and it has been allowed. + */ + + lws_ss_set_metadata(m->ss, "ctype", + "multipart/form-data;boundary=\"boundary\"", + 39); + + /* provide a hint about the payload size */ + m->pos = 0; + m->len = strlen(postbody); + lws_ss_request_tx_len(m->ss, (unsigned long)strlen(postbody)); + break; + case LWSSSCS_CONNECTED: + lws_ss_request_tx(m->ss); + break; + case LWSSSCS_ALL_RETRIES_FAILED: + /* if we're out of retries, we want to close the app and FAIL */ + interrupted = 1; + break; + case LWSSSCS_QOS_ACK_REMOTE: + lwsl_notice("%s: LWSSSCS_QOS_ACK_REMOTE\n", __func__); + break; + + case LWSSSCS_TIMEOUT: + lwsl_notice("%s: LWSSSCS_TIMEOUT\n", __func__); + break; + default: + break; + } + + return 0; +} + +static int +app_system_state_nf(lws_state_manager_t *mgr, lws_state_notify_link_t *link, + int current, int target) +{ + struct lws_context *context = lws_system_context_from_system_mgr(mgr); +#if !defined(LWS_SS_USE_SSPC) + + lws_system_blob_t *ab = lws_system_get_blob(context, + LWS_SYSBLOB_TYPE_AUTH, 1 /* AUTH_IDX_ROOT */); + size_t size; +#endif + + /* + * For the things we care about, let's notice if we are trying to get + * past them when we haven't solved them yet, and make the system + * state wait while we trigger the dependent action. + */ + switch (target) { + +#if !defined(LWS_SS_USE_SSPC) + + case LWS_SYSTATE_REGISTERED: + size = lws_system_blob_get_size(ab); + if (size) + break; + + /* let's register our canned root token so auth can use it */ + lws_system_blob_direct_set(ab, + (const uint8_t *)canned_root_token_payload, + strlen(canned_root_token_payload)); + break; + +#endif + + case LWS_SYSTATE_OPERATIONAL: + if (current == LWS_SYSTATE_OPERATIONAL) { + lws_ss_info_t ssi; + + /* We're making an outgoing secure stream ourselves */ + + memset(&ssi, 0, sizeof(ssi)); + ssi.handle_offset = offsetof(myss_t, ss); + ssi.opaque_user_data_offset = offsetof(myss_t, + opaque_data); + ssi.rx = myss_rx; + ssi.tx = myss_tx; + ssi.state = myss_state; + ssi.user_alloc = sizeof(myss_t); + ssi.streamtype = "minpost"; + + if (lws_ss_create(context, 0, &ssi, NULL, NULL, + NULL, NULL)) { + lwsl_err("%s: failed to create secure stream\n", + __func__); + return -1; + } + } + break; + } + + return 0; +} + +static lws_state_notify_link_t * const app_notifier_list[] = { + &nl, NULL +}; + +static void +sigint_handler(int sig) +{ + interrupted = 1; +} + +int main(int argc, const char **argv) +{ + struct lws_context_creation_info info; + struct lws_context *context; + const char *p; + int n = 0; + + signal(SIGINT, sigint_handler); + + memset(&info, 0, sizeof info); + lws_cmdline_option_handle_builtin(argc, argv, &info); + + lwsl_user("LWS secure streams test client [-d]\n"); + + /* these options are mutually exclusive if given */ + + if (lws_cmdline_option(argc, argv, "--force-portal")) + force_cpd_fail_portal = 1; + + if (lws_cmdline_option(argc, argv, "--force-no-internet")) + force_cpd_fail_no_internet = 1; + + if ((p = lws_cmdline_option(argc, argv, "--timeout_ms"))) + timeout_ms = atoi(p); + + info.fd_limit_per_thread = 1 + 6 + 1; + info.port = CONTEXT_PORT_NO_LISTEN; +#if defined(LWS_SS_USE_SSPC) + info.protocols = lws_sspc_protocols; + { + const char *p; + + /* connect to ssproxy via UDS by default, else via + * tcp connection to this port */ + if ((p = lws_cmdline_option(argc, argv, "-p"))) + info.ss_proxy_port = atoi(p); + + /* UDS "proxy.ss.lws" in abstract namespace, else this socket + * path; when -p given this can specify the network interface + * to bind to */ + if ((p = lws_cmdline_option(argc, argv, "-i"))) + info.ss_proxy_bind = p; + + /* if -p given, -a specifies the proxy address to connect to */ + if ((p = lws_cmdline_option(argc, argv, "-a"))) + info.ss_proxy_address = p; + } +#else + info.pss_policies_json = default_ss_policy; + info.options = LWS_SERVER_OPTION_EXPLICIT_VHOSTS | + LWS_SERVER_OPTION_DO_SSL_GLOBAL_INIT; +#endif +#if defined(LWS_WITH_DETAILED_LATENCY) + info.detailed_latency_cb = lws_det_lat_plot_cb; + info.detailed_latency_filepath = "/tmp/lws-latency-ssproxy"; +#endif + + /* integrate us with lws system state management when context created */ + + nl.name = "app"; + nl.notify_cb = app_system_state_nf; + info.register_notifier_list = app_notifier_list; + + /* create the context */ + + context = lws_create_context(&info); + if (!context) { + lwsl_err("lws init failed\n"); + return 1; + } + +#if !defined(LWS_SS_USE_SSPC) + /* + * If we're being a proxied client, the proxy does all this + */ + + /* + * Set the related lws_system blobs + * + * ...direct_set() sets a pointer, so the thing pointed to has to have + * a suitable lifetime, eg, something that already exists on the heap or + * a const string in .rodata like this + */ + + lws_system_blob_direct_set(lws_system_get_blob(context, + LWS_SYSBLOB_TYPE_DEVICE_SERIAL, 0), + (const uint8_t *)"SN12345678", 10); + lws_system_blob_direct_set(lws_system_get_blob(context, + LWS_SYSBLOB_TYPE_DEVICE_FW_VERSION, 0), + (const uint8_t *)"v0.01", 5); + + /* + * ..._heap_append() appends to a buflist kind of arrangement on heap, + * just one block is fine, otherwise it will concatenate the fragments + * in the order they were appended (and take care of freeing them at + * context destroy time). ..._heap_empty() is also available to remove + * everything that was already allocated. + * + * Here we use _heap_append() just so it's tested as well as direct set. + */ + + lws_system_blob_heap_append(lws_system_get_blob(context, + LWS_SYSBLOB_TYPE_DEVICE_TYPE, 0), + (const uint8_t *)"spacerocket", 11); +#endif + + /* the event loop */ + + while (n >= 0 && !interrupted) + n = lws_service(context, 0); + + lws_context_destroy(context); + + lwsl_user("Completed: %s\n", bad ? "failed" : "OK"); + + return bad; +} diff -Nru libwebsockets-3.2.1/minimal-examples/secure-streams/minimal-secure-streams-post/README.md libwebsockets-4.1.6/minimal-examples/secure-streams/minimal-secure-streams-post/README.md --- libwebsockets-3.2.1/minimal-examples/secure-streams/minimal-secure-streams-post/README.md 1970-01-01 00:00:00.000000000 +0000 +++ libwebsockets-4.1.6/minimal-examples/secure-streams/minimal-secure-streams-post/README.md 2020-12-01 17:40:26.000000000 +0000 @@ -0,0 +1,66 @@ +# lws minimal secure streams + +The application goes to https://warmcat.com and reads index.html there. + +It does it using Secure Streams... the main code in minimal-secure-streams.c +just sets up the context and opens a secure stream of type "mintest". + +The handler for state changes and payloads for "mintest" is in ss-myss.c + +The information about how a "mintest" stream should connect and the +protocol it uses is kept separated in policy-database.c + +## build + +``` + $ cmake . && make +``` + +## usage + +Commandline option|Meaning +---|--- +-d |Debug verbosity in decimal, eg, -d15 +-f| Force connecting to the wrong endpoint to check backoff retry flow +-p| Run as proxy server for clients to connect to over unix domain socket +--force-portal|Force the SS Captive Portal Detection to feel it's behind a portal +--force-no-internet|Force the SS Captive Portal Detection to feel it can't reach the internet + +``` +[2019/08/12 07:16:11:0045] USR: LWS minimal secure streams [-d] [-f] +[2019/08/12 07:16:12:6102] USR: myss_state: LWSSSCS_CREATING, ord 0x0 +[2019/08/12 07:16:12:6107] USR: myss_state: LWSSSCS_POLL, ord 0x0 +[2019/08/12 07:16:12:6117] N: lws_ss_client_connect: connecting h1get warmcat.com / +[2019/08/12 07:16:12:6118] USR: myss_state: LWSSSCS_CONNECTING, ord 0x0 +[2019/08/12 07:16:13:4171] USR: myss_state: LWSSSCS_CONNECTED, ord 0x0 +[2019/08/12 07:16:13:4222] USR: myss_rx: len 1024, flags: 1 +[2019/08/12 07:16:13:4243] USR: myss_rx: len 1024, flags: 0 +[2019/08/12 07:16:13:4244] USR: myss_rx: len 1024, flags: 0 +[2019/08/12 07:16:13:4244] USR: myss_rx: len 1024, flags: 0 +[2019/08/12 07:16:13:4245] USR: myss_rx: len 1024, flags: 0 +[2019/08/12 07:16:13:4246] USR: myss_rx: len 1024, flags: 0 +[2019/08/12 07:16:13:4247] USR: myss_rx: len 1024, flags: 0 +[2019/08/12 07:16:13:4252] USR: myss_rx: len 1015, flags: 0 +[2019/08/12 07:16:13:4264] USR: myss_rx: len 1024, flags: 0 +[2019/08/12 07:16:13:4265] USR: myss_rx: len 1024, flags: 0 +[2019/08/12 07:16:13:4266] USR: myss_rx: len 1024, flags: 0 +[2019/08/12 07:16:13:4267] USR: myss_rx: len 1024, flags: 0 +[2019/08/12 07:16:13:4268] USR: myss_rx: len 1024, flags: 0 +[2019/08/12 07:16:13:4268] USR: myss_rx: len 1024, flags: 0 +[2019/08/12 07:16:13:4269] USR: myss_rx: len 1024, flags: 0 +[2019/08/12 07:16:13:4270] USR: myss_rx: len 1015, flags: 0 +[2019/08/12 07:16:13:4278] USR: myss_rx: len 1024, flags: 0 +[2019/08/12 07:16:13:4279] USR: myss_rx: len 1024, flags: 0 +[2019/08/12 07:16:13:4280] USR: myss_rx: len 1024, flags: 0 +[2019/08/12 07:16:13:4281] USR: myss_rx: len 1024, flags: 0 +[2019/08/12 07:16:13:4282] USR: myss_rx: len 1024, flags: 0 +[2019/08/12 07:16:13:4283] USR: myss_rx: len 1024, flags: 0 +[2019/08/12 07:16:13:4283] USR: myss_rx: len 1024, flags: 0 +[2019/08/12 07:16:13:4284] USR: myss_rx: len 1015, flags: 0 +[2019/08/12 07:16:13:4287] USR: myss_rx: len 1024, flags: 0 +[2019/08/12 07:16:13:4288] USR: myss_rx: len 947, flags: 0 +[2019/08/12 07:16:13:4293] USR: myss_rx: len 0, flags: 2 +[2019/08/12 07:16:13:4399] USR: myss_state: LWSSSCS_DISCONNECTED, ord 0x0 +[2019/08/12 07:16:13:4761] USR: myss_state: LWSSSCS_DESTROYING, ord 0x0 +[2019/08/12 07:16:13:4781] USR: Completed: OK +``` diff -Nru libwebsockets-3.2.1/minimal-examples/secure-streams/minimal-secure-streams-proxy/CMakeLists.txt libwebsockets-4.1.6/minimal-examples/secure-streams/minimal-secure-streams-proxy/CMakeLists.txt --- libwebsockets-3.2.1/minimal-examples/secure-streams/minimal-secure-streams-proxy/CMakeLists.txt 1970-01-01 00:00:00.000000000 +0000 +++ libwebsockets-4.1.6/minimal-examples/secure-streams/minimal-secure-streams-proxy/CMakeLists.txt 2020-12-01 17:40:26.000000000 +0000 @@ -0,0 +1,28 @@ +project(lws-minimal-secure-streams-proxy C) +cmake_minimum_required(VERSION 2.8) +find_package(libwebsockets CONFIG REQUIRED) +list(APPEND CMAKE_MODULE_PATH ${LWS_CMAKE_DIR}) +include(CheckCSourceCompiles) +include(LwsCheckRequirements) + +set(SAMP lws-minimal-secure-streams-proxy) +set(SRCS main.c) + +set(requirements 1) +require_lws_config(LWS_ROLE_H1 1 requirements) +require_lws_config(LWS_WITHOUT_CLIENT 0 requirements) +require_lws_config(LWS_WITH_SECURE_STREAMS 1 requirements) +require_lws_config(LWS_WITH_SECURE_STREAMS_PROXY_API 1 requirements) +require_lws_config(LWS_WITH_SECURE_STREAMS_STATIC_POLICY_ONLY 0 requirements) +require_lws_config(LWS_WITH_SYS_STATE 1 requirements) + +if (requirements) + add_executable(${SAMP} ${SRCS}) + + if (websockets_shared) + target_link_libraries(${SAMP} websockets_shared ${LIBWEBSOCKETS_DEP_LIBS}) + add_dependencies(${SAMP} websockets_shared) + else() + target_link_libraries(${SAMP} websockets ${LIBWEBSOCKETS_DEP_LIBS}) + endif() +endif() diff -Nru libwebsockets-3.2.1/minimal-examples/secure-streams/minimal-secure-streams-proxy/main.c libwebsockets-4.1.6/minimal-examples/secure-streams/minimal-secure-streams-proxy/main.c --- libwebsockets-3.2.1/minimal-examples/secure-streams/minimal-secure-streams-proxy/main.c 1970-01-01 00:00:00.000000000 +0000 +++ libwebsockets-4.1.6/minimal-examples/secure-streams/minimal-secure-streams-proxy/main.c 2020-12-01 17:40:26.000000000 +0000 @@ -0,0 +1,295 @@ +/* + * lws-minimal-secure-streams-proxy + * + * Written in 2010-2020 by Andy Green + * + * This file is made available under the Creative Commons CC0 1.0 + * Universal Public Domain Dedication. + * + * + * This is the proxy part for examples built to use it to connect to... it has + * the policy and the core SS function, but it doesn't contain any of the user + * code "business logic"... that's in the clients. + * + * The proxy side has the policy and performs the onward connection proxying + * fulfilment. The clients state the streamtype name they want and ask for the + * client to do the connection part. + * + * Rideshare information is being parsed out at the proxy side; the SSS RX part + * also brings with it rideshare names. + * + * Metadata is passed back over SSS from the client in the TX messages for the + * proxy to use per the policy. + */ + +#include +#include +#include + +static int interrupted, bad = 1, port = 0 /* unix domain socket */; +static const char *ibind = NULL; /* default to unix domain skt "proxy.ss.lws" */ +static lws_state_notify_link_t nl; + +/* + * We just define enough policy so it can fetch the latest one securely + */ + +static const char * const default_ss_policy = + "{" + "\"release\":" "\"01234567\"," + "\"product\":" "\"myproduct\"," + "\"schema-version\":" "1," + "\"retry\": [" /* named backoff / retry strategies */ + "{\"default\": {" + "\"backoff\": [" "1000," + "2000," + "3000," + "5000," + "10000" + "]," + "\"conceal\":" "5," + "\"jitterpc\":" "20," + "\"svalidping\":" "30," + "\"svalidhup\":" "35" + "}}" + "]," + "\"certs\": [" /* named individual certificates in BASE64 DER */ + /* + * Let's Encrypt certs for warmcat.com / libwebsockets.org + * + * We fetch the real policy from there using SS and switch to + * using that. + */ + "{\"isrg_root_x1\": \"" /* ISRG ROOT X1 */ + "MIIFazCCA1OgAwIBAgIRAIIQz7DSQONZRGPgu2OCiwAwDQYJKoZIhvcNAQELBQAw" + "TzELMAkGA1UEBhMCVVMxKTAnBgNVBAoTIEludGVybmV0IFNlY3VyaXR5IFJlc2Vh" + "cmNoIEdyb3VwMRUwEwYDVQQDEwxJU1JHIFJvb3QgWDEwHhcNMTUwNjA0MTEwNDM4" + "WhcNMzUwNjA0MTEwNDM4WjBPMQswCQYDVQQGEwJVUzEpMCcGA1UEChMgSW50ZXJu" + "ZXQgU2VjdXJpd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ZjqG8RkqZUdoxtID5+90FgsGIfkMpqgRS05f4zPbCEHqCXl1" + "eO5HyELTgcVlLXXQDgAWnRzut1hFJeczY1tjQQno6f6s+nMydLN26WuU4s3UYvOu" + "OsUxRlJu7TSRHqDC3lSE5XggVkzdaPkuKGQbGpny+01/47hfXXNB7HntWNZ6N2Vw" + "p7G6OfY+YQrZwIaQmhrIqJZuigsrbe3W+gdn5ykE9+Ky0VgVUsfxo52mwFYs1JKY" + "2PGDuWx8M6DlS6qQkvHaRUo0FMd8TsSlbF0/v965qGFKhSDeQoMpYnwcmQilRh/0" + "ayLThlHLN81gSkJjVrPI0Y8xCVPB4twb1PFUd2fPM3sA1tJ83sZ5v8vgFv2yofKR" + "PB0t6JzUA81mSqM3kxl5e+IZwhYAyO0OTg3/fs8HqGTNKd9BqoUwSRBzp06JMg5b" + "rUCGwbCUDI0mxadJ3Bz4WxR6fyNpBK2yAinWEsikxqEt" + "\"}" + "]," + "\"trust_stores\": [" /* named cert chains */ + "{" + "\"name\": \"le_via_isrg\"," + "\"stack\": [" + "\"isrg_root_x1\"," + "\"LEX3_isrg_root_x1\"" + "]" + "}" + "]," + "\"s\": [{" + "\"captive_portal_detect\": {" + "\"endpoint\": \"connectivitycheck.android.com\"," + "\"http_url\": \"generate_204\"," + "\"port\": 80," + "\"protocol\": \"h1\"," + "\"http_method\": \"GET\"," + "\"opportunistic\": true," + "\"http_expect\": 204," + "\"http_fail_redirect\": true" + "}," + "\"fetch_policy\": {" + "\"endpoint\":" "\"warmcat.com\"," + "\"port\":" "443," + "\"protocol\":" "\"h1\"," + "\"http_method\":" "\"GET\"," + "\"http_url\":" "\"policy/minimal-proxy.json\"," + "\"tls\":" "true," + "\"opportunistic\":" "true," + "\"retry\":" "\"default\"," + "\"tls_trust_store\":" "\"le_via_isrg\"" + "}}" + "}" +; + +static const char *canned_root_token_payload = + "grant_type=refresh_token" + "&refresh_token=Atzr|IwEBIJedGXjDqsU_vMxykqOMg" + "SHfYe3CPcedueWEMWSDMaDnEmiW8RlR1Kns7Cb4B-TOSnqp7ifVsY4BMY2B8tpHfO39XP" + "zfu9HapGjTR458IyHX44FE71pWJkGZ79uVBpljP4sazJuk8XS3Oe_yLnm_DIO6fU1nU3Y" + "0flYmsOiOAQE_gRk_pdlmEtHnpMA-9rLw3mkY5L89Ty9kUygBsiFaYatouROhbsTn8-jW" + "k1zZLUDpT6ICtBXSnrCIg0pUbZevPFhTwdXd6eX-u4rq0W-XaDvPWFO7au-iPb4Zk5eZE" + "iX6sissYrtNmuEXc2uHu7MnQO1hHCaTdIO2CANVumf-PHSD8xseamyh04sLV5JgFzY45S" + "KvKMajiUZuLkMokOx86rjC2Hdkx5DO7G-dbG1ufBDG-N79pFMSs7Ck5pc283IdLoJkCQc" + "AGvTX8o8I29QqkcGou-9TKhOJmpX8As94T61ok0UqqEKPJ7RhfQHHYdCtsdwxgvfVr9qI" + "xL_hDCcTho8opCVX-6QhJHl6SQFlTw13" + "&client_id=" + "amzn1.application-oa2-client.4823334c434b4190a2b5a42c07938a2d"; + +static int +app_system_state_nf(lws_state_manager_t *mgr, lws_state_notify_link_t *link, + int current, int target) +{ + struct lws_context *context = lws_system_context_from_system_mgr(mgr); + lws_system_blob_t *ab = lws_system_get_blob(context, + LWS_SYSBLOB_TYPE_AUTH, 1 /* AUTH_IDX_ROOT */); + size_t size; + + /* + * For the things we care about, let's notice if we are trying to get + * past them when we haven't solved them yet, and make the system + * state wait while we trigger the dependent action. + */ + switch (target) { + case LWS_SYSTATE_REGISTERED: + size = lws_system_blob_get_size(ab); + if (size) + break; + + /* let's register our canned root token so auth can use it */ + lws_system_blob_direct_set(ab, + (const uint8_t *)canned_root_token_payload, + strlen(canned_root_token_payload)); + break; + case LWS_SYSTATE_OPERATIONAL: + if (current == LWS_SYSTATE_OPERATIONAL) + /* + * At this point we have DHCP, ntp, system auth token + * and we can reasonably create the proxy + */ + if (lws_ss_proxy_create(context, ibind, port)) { + lwsl_err("%s: failed to create ss proxy\n", + __func__); + return -1; + } + break; + case LWS_SYSTATE_POLICY_INVALID: + /* + * This is a NOP since we used direct set... but in a real + * system this could easily change to be done on the heap, then + * this would be important + */ + lws_system_blob_destroy(lws_system_get_blob(context, + LWS_SYSBLOB_TYPE_AUTH, + 1 /* AUTH_IDX_ROOT */)); + break; + } + + return 0; +} + +static lws_state_notify_link_t * const app_notifier_list[] = { + &nl, NULL +}; + +static void +sigint_handler(int sig) +{ + interrupted = 1; +} + +int main(int argc, const char **argv) +{ + int n = 0, logs = LLL_USER | LLL_ERR | LLL_WARN | LLL_NOTICE; + struct lws_context_creation_info info; + struct lws_context *context; + const char *p; + + signal(SIGINT, sigint_handler); + + if ((p = lws_cmdline_option(argc, argv, "-d"))) + logs = atoi(p); + + /* connect to ssproxy via UDS by default, else via tcp with this port */ + if ((p = lws_cmdline_option(argc, argv, "-p"))) + port = atoi(p); + + /* UDS "proxy.ss.lws" in abstract namespace, else this socket path; + * when -p given this can specify the network interface to bind to */ + if ((p = lws_cmdline_option(argc, argv, "-i"))) + ibind = p; + + lws_set_log_level(logs, NULL); + lwsl_user("LWS secure streams Proxy [-d]\n"); + + memset(&info, 0, sizeof info); /* otherwise uninitialized garbage */ + + info.options = LWS_SERVER_OPTION_EXPLICIT_VHOSTS | + LWS_SERVER_OPTION_DO_SSL_GLOBAL_INIT; + info.fd_limit_per_thread = 1 + 6 + 1; + info.pss_policies_json = default_ss_policy; + info.port = CONTEXT_PORT_NO_LISTEN; +#if defined(LWS_WITH_DETAILED_LATENCY) + info.detailed_latency_cb = lws_det_lat_plot_cb; + info.detailed_latency_filepath = "/tmp/lws-latency-ssproxy"; +#endif + + /* integrate us with lws system state management when context created */ + nl.name = "app"; + nl.notify_cb = app_system_state_nf; + info.register_notifier_list = app_notifier_list; + + context = lws_create_context(&info); + if (!context) { + lwsl_err("lws init failed\n"); + return 1; + } + + /* the event loop */ + + while (n >= 0 && !interrupted) + n = lws_service(context, 0); + + bad = 0; + + lws_context_destroy(context); + lwsl_user("Completed: %s\n", bad ? "failed" : "OK"); + + return bad; +} diff -Nru libwebsockets-3.2.1/minimal-examples/secure-streams/minimal-secure-streams-proxy/README.md libwebsockets-4.1.6/minimal-examples/secure-streams/minimal-secure-streams-proxy/README.md --- libwebsockets-3.2.1/minimal-examples/secure-streams/minimal-secure-streams-proxy/README.md 1970-01-01 00:00:00.000000000 +0000 +++ libwebsockets-4.1.6/minimal-examples/secure-streams/minimal-secure-streams-proxy/README.md 2020-12-01 17:40:26.000000000 +0000 @@ -0,0 +1,33 @@ +# lws minimal secure streams proxy + +Operates as a secure streams proxy, by default on a listening unix domain socket +"proxy.ss.lws" in the Linux abstract namespace. + +Give -p to have it listen on a specific tcp port instead. + +## build + +``` + $ cmake . && make +``` + +## usage + +Commandline option|Meaning +---|--- +-d |Debug verbosity in decimal, eg, -d15 +-f| Force connecting to the wrong endpoint to check backoff retry flow +-p |If not given, proxy listens on a Unix Domain Socket, if given listen on specified tcp port +-i |Optionally specify the UDS path (no -p) or network interface to bind to (if -p also given) + +``` +[2020/02/26 15:41:27:5768] U: LWS secure streams Proxy [-d] +[2020/02/26 15:41:27:5770] N: lws_ss_policy_set: 2.064KiB, pad 70%: hardcoded +[2020/02/26 15:41:27:5771] N: lws_tls_client_create_vhost_context: using mem client CA cert 1391 +[2020/02/26 15:41:27:8681] N: lws_ss_policy_set: 4.512KiB, pad 15%: updated +[2020/02/26 15:41:27:8682] N: lws_tls_client_create_vhost_context: using mem client CA cert 837 +[2020/02/26 15:41:27:8683] N: lws_tls_client_create_vhost_context: using mem client CA cert 1043 +[2020/02/26 15:41:27:8684] N: lws_tls_client_create_vhost_context: using mem client CA cert 1167 +[2020/02/26 15:41:27:8684] N: lws_tls_client_create_vhost_context: using mem client CA cert 1391 +[2020/02/26 15:41:28:4226] N: ss_api_amazon_auth_rx: acquired 567-byte api.amazon.com auth token, exp 3600s +``` diff -Nru libwebsockets-3.2.1/minimal-examples/secure-streams/minimal-secure-streams-seq/CMakeLists.txt libwebsockets-4.1.6/minimal-examples/secure-streams/minimal-secure-streams-seq/CMakeLists.txt --- libwebsockets-3.2.1/minimal-examples/secure-streams/minimal-secure-streams-seq/CMakeLists.txt 1970-01-01 00:00:00.000000000 +0000 +++ libwebsockets-4.1.6/minimal-examples/secure-streams/minimal-secure-streams-seq/CMakeLists.txt 2020-12-01 17:40:26.000000000 +0000 @@ -0,0 +1,27 @@ +project(lws-minimal-secure-streams-seq C) +cmake_minimum_required(VERSION 2.8) +find_package(libwebsockets CONFIG REQUIRED) +list(APPEND CMAKE_MODULE_PATH ${LWS_CMAKE_DIR}) +include(CheckCSourceCompiles) +include(LwsCheckRequirements) + +set(SAMP lws-minimal-secure-streams-seq) +set(SRCS minimal-secure-streams.c) + +set(requirements 1) +require_lws_config(LWS_ROLE_H1 1 requirements) +require_lws_config(LWS_WITHOUT_CLIENT 0 requirements) +require_lws_config(LWS_WITH_SEQUENCER 1 requirements) +require_lws_config(LWS_WITH_SECURE_STREAMS 1 requirements) +require_lws_config(LWS_WITH_SECURE_STREAMS_STATIC_POLICY_ONLY 0 requirements) + +if (requirements) + add_executable(${SAMP} ${SRCS}) + + if (websockets_shared) + target_link_libraries(${SAMP} websockets_shared ${LIBWEBSOCKETS_DEP_LIBS}) + add_dependencies(${SAMP} websockets_shared) + else() + target_link_libraries(${SAMP} websockets ${LIBWEBSOCKETS_DEP_LIBS}) + endif() +endif() diff -Nru libwebsockets-3.2.1/minimal-examples/secure-streams/minimal-secure-streams-seq/minimal-secure-streams.c libwebsockets-4.1.6/minimal-examples/secure-streams/minimal-secure-streams-seq/minimal-secure-streams.c --- libwebsockets-3.2.1/minimal-examples/secure-streams/minimal-secure-streams-seq/minimal-secure-streams.c 1970-01-01 00:00:00.000000000 +0000 +++ libwebsockets-4.1.6/minimal-examples/secure-streams/minimal-secure-streams-seq/minimal-secure-streams.c 2020-12-01 17:40:26.000000000 +0000 @@ -0,0 +1,443 @@ +/* + * lws-minimal-secure-streams-seq + * + * Written in 2010-2020 by Andy Green + * + * This file is made available under the Creative Commons CC0 1.0 + * Universal Public Domain Dedication. + * + * + * This demonstrates the a minimal http client using secure streams api. + * + * It visits https://warmcat.com/ and receives the html page there. + * + * This is the "secure streams" api equivalent of minimal-http-client... + * it shows how to use a sequencer to make it easy to build more complex + * schemes on top of this example. + * + * The layering looks like this + * + * lifetime + * + * ------ app ------ process + * ---- sequencer ---- process + * --- secure stream --- process + * ------- wsi ------- connection + * + * see minimal-secure-streams for a similar example without the sequencer. + */ + +#include +#include +#include + +static int interrupted, bad = 1, flag_conn_fail, flag_h1post; +static const char * const default_ss_policy = + "{" + "\"release\":" "\"01234567\"," + "\"product\":" "\"myproduct\"," + "\"schema-version\":" "1," + "\"retry\": [" /* named backoff / retry strategies */ + "{\"default\": {" + "\"backoff\": [" "1000," + "2000," + "3000," + "5000," + "10000" + "]," + "\"conceal\":" "5," + "\"jitterpc\":" "20," + "\"svalidping\":" "300," + "\"svalidhup\":" "310" + "}}" + "]," + "\"certs\": [" /* named individual certificates in BASE64 DER */ + /* + * Need to be in order from root cert... notice sometimes as + * with Let's Encrypt there are multiple possible validation + * paths, all the pieces for one validation path must be + * given, excluding the server cert itself. Let's Encrypt + * intermediate is signed by their ISRG Root CA but also is + * cross-signed by an IdenTrust intermediate that's widely + * deployed in browsers. We use the ISRG path because that + * way we can skip the extra IdenTrust root cert. + */ + "{\"isrg_root_x1\": \"" /* ISRG ROOT X1 */ + "MIIFazCCA1OgAwIBAgIRAIIQz7DSQONZRGPgu2OCiwAwDQYJKoZIhvcNAQELBQAw" + "TzELMAkGA1UEBhMCVVMxKTAnBgNVBAoTIEludGVybmV0IFNlY3VyaXR5IFJlc2Vh" + "cmNoIEdyb3VwMRUwEwYDVQQDEwxJU1JHIFJvb3QgWDEwHhcNMTUwNjA0MTEwNDM4" + "WhcNMzUwNjA0MTEwNDM4WjBPMQswCQYDVQQGEwJVUzEpMCcGA1UEChMgSW50ZXJu" + "ZXQgU2VjdXJpdHkgUmVzZWFyY2ggR3JvdXAxFTATBgN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RS05f4zPbCEHqCXl1" + "eO5HyELTgcVlLXXQDgAWnRzut1hFJeczY1tjQQno6f6s+nMydLN26WuU4s3UYvOu" + "OsUxRlJu7TSRHqDC3lSE5XggVkzdaPkuKGQbGpny+01/47hfXXNB7HntWNZ6N2Vw" + "p7G6OfY+YQrZwIaQmhrIqJZuigsrbe3W+gdn5ykE9+Ky0VgVUsfxo52mwFYs1JKY" + "2PGDuWx8M6DlS6qQkvHaRUo0FMd8TsSlbF0/v965qGFKhSDeQoMpYnwcmQilRh/0" + "ayLThlHLN81gSkJjVrPI0Y8xCVPB4twb1PFUd2fPM3sA1tJ83sZ5v8vgFv2yofKR" + "PB0t6JzUA81mSqM3kxl5e+IZwhYAyO0OTg3/fs8HqGTNKd9BqoUwSRBzp06JMg5b" + "rUCGwbCUDI0mxadJ3Bz4WxR6fyNpBK2yAinWEsikxqEt" + "\"}" + "]," + "\"trust_stores\": [" /* named cert chains */ + "{" + "\"name\": \"le_via_isrg\"," + "\"stack\": [" + "\"isrg_root_x1\"," + "\"LEX3_isrg_root_x1\"" + "]" + "}" + "]," + "\"s\": [" /* the supported stream types */ + "{\"mintest\": {" + "\"endpoint\":" "\"warmcat.com\"," + "\"port\":" "443," + "\"protocol\":" "\"h1\"," + "\"http_method\":" "\"GET\"," + "\"http_url\":" "\"index.html\"," + "\"plugins\":" "[]," + "\"tls\":" "true," + "\"opportunistic\":" "true," + "\"retry\":" "\"default\"," + "\"tls_trust_store\":" "\"le_via_isrg\"" + "}}," + "{\"mintest-fail\": {" + "\"endpoint\":" "\"warmcat.com\"," + "\"port\":" "22," + "\"protocol\":" "\"h1\"," + "\"http_method\":" "\"GET\"," + "\"http_url\":" "\"index.html\"," + "\"plugins\":" "[]," + "\"tls\":" "true," + "\"opportunistic\":" "true," + "\"retry\":" "\"default\"," + "\"tls_trust_store\":" "\"le_via_isrg\"" + "}}," + "{\"minpost\": {" + "\"endpoint\":" "\"warmcat.com\"," + "\"port\":" "443," + "\"protocol\":" "\"h1\"," + "\"http_method\":" "\"POST\"," + "\"http_url\":" "\"testserver/formtest\"," + "\"plugins\":" "[]," + "\"tls\":" "true," + "\"opportunistic\":" "true," + "\"retry\":" "\"default\"," + "\"tls_trust_store\":" "\"le_via_isrg\"" + "}}" + "]" + "}" +; + +typedef struct myss { + struct lws_ss_handle *ss; + void *opaque_data; + /* ... application specific state ... */ +} myss_t; + +/* secure streams payload interface */ + +static int +myss_rx(void *userobj, const uint8_t *buf, size_t len, int flags) +{ +// myss_t *m = (myss_t *)userobj; + + lwsl_user("%s: len %d, flags: %d\n", __func__, (int)len, flags); + lwsl_hexdump_info(buf, len); + + /* + * If we received the whole message, we let the sequencer know it + * was a success + */ + if (flags & LWSSS_FLAG_EOM) { + bad = 0; + interrupted = 1; + } + + return 0; +} + +static int +myss_tx(void *userobj, lws_ss_tx_ordinal_t ord, uint8_t *buf, size_t *len, + int *flags) +{ + // myss_t *m = (myss_t *)userobj; + + /* in this example, we don't send any payload */ + + return 0; +} + +static int +myss_state(void *userobj, void *sh, lws_ss_constate_t state, + lws_ss_tx_ordinal_t ack) +{ + myss_t *m = (myss_t *)userobj; + + lwsl_user("%s: %s, ord 0x%x\n", __func__, lws_ss_state_name(state), + (unsigned int)ack); + + switch (state) { + case LWSSSCS_CREATING: + lws_ss_request_tx(m->ss); + break; + case LWSSSCS_ALL_RETRIES_FAILED: + /* if we're out of retries, we want to close the app and FAIL */ + interrupted = 1; + break; + default: + break; + } + + return 0; +} + +typedef enum { + SEQ_IDLE, + SEQ_TRY_CONNECT, + SEQ_RECONNECT_WAIT, + SEQ_CONNECTED, +} myseq_state_t; + +typedef struct myseq { + struct lws_ss_handle *ss; + + myseq_state_t state; + int http_resp; + + uint16_t try; +} myseq_t; + +/* + * This defines the sequence of things the test app does. + */ + +static lws_seq_cb_return_t +min_sec_str_sequencer_cb(struct lws_sequencer *seq, void *user, int event, + void *v, void *a) +{ + struct myseq *s = (struct myseq *)user; + lws_ss_info_t ssi; + + switch ((int)event) { + + /* these messages are created just by virtue of being a sequencer */ + + case LWSSEQ_CREATED: /* our sequencer just got started */ + s->state = SEQ_IDLE; + lwsl_notice("%s: LWSSEQ_CREATED\n", __func__); + + /* We're making an outgoing secure stream ourselves */ + + memset(&ssi, 0, sizeof(ssi)); + ssi.handle_offset = offsetof(myss_t, ss); + ssi.opaque_user_data_offset = offsetof(myss_t, opaque_data); + ssi.rx = myss_rx; + ssi.tx = myss_tx; + ssi.state = myss_state; + ssi.user_alloc = sizeof(myss_t); + + /* requested to fail (to check backoff)? */ + if (flag_conn_fail) + ssi.streamtype = "mintest-fail"; + else + /* request to check h1 POST */ + if (flag_h1post) + ssi.streamtype = "minpost"; + else + /* default to h1 GET */ + ssi.streamtype = "mintest"; + + if (lws_ss_create(lws_seq_get_context(seq), 0, &ssi, NULL, + &s->ss, seq, NULL)) { + lwsl_err("%s: failed to create secure stream\n", + __func__); + + return LWSSEQ_RET_DESTROY; + } + break; + + case LWSSEQ_DESTROYED: + lwsl_notice("%s: LWSSEQ_DESTROYED\n", __func__); + break; + + case LWSSEQ_TIMED_OUT: /* current step timed out */ + if (s->state == SEQ_RECONNECT_WAIT) + lws_ss_request_tx(s->ss); + break; + + /* + * These messages are created because we have a secure stream that was + * bound to this sequencer at creation time. It copies its state + * events to us as its sequencer parent. v is the lws_ss_handle_t * + */ + + case LWSSEQ_SS_STATE_BASE + LWSSSCS_CREATING: + lwsl_info("%s: seq LWSSSCS_CREATING\n", __func__); + lws_ss_request_tx(s->ss); + break; + case LWSSEQ_SS_STATE_BASE + LWSSSCS_DISCONNECTED: + lwsl_info("%s: seq LWSSSCS_DISCONNECTED\n", __func__); + break; + case LWSSEQ_SS_STATE_BASE + LWSSSCS_UNREACHABLE: + lwsl_info("%s: seq LWSSSCS_UNREACHABLE\n", __func__); + break; + case LWSSEQ_SS_STATE_BASE + LWSSSCS_AUTH_FAILED: + lwsl_info("%s: seq LWSSSCS_AUTH_FAILED\n", __func__); + break; + case LWSSEQ_SS_STATE_BASE + LWSSSCS_CONNECTED: + lwsl_info("%s: seq LWSSSCS_CONNECTED\n", __func__); + break; + case LWSSEQ_SS_STATE_BASE + LWSSSCS_CONNECTING: + lwsl_info("%s: seq LWSSSCS_CONNECTING\n", __func__); + break; + case LWSSEQ_SS_STATE_BASE + LWSSSCS_DESTROYING: + lwsl_info("%s: seq LWSSSCS_DESTROYING\n", __func__); + break; + case LWSSEQ_SS_STATE_BASE + LWSSSCS_POLL: + /* somebody called lws_ss_poll() on the stream */ + lwsl_info("%s: seq LWSSSCS_POLL\n", __func__); + break; + case LWSSEQ_SS_STATE_BASE + LWSSSCS_ALL_RETRIES_FAILED: + lwsl_info("%s: seq LWSSSCS_ALL_RETRIES_FAILED\n", __func__); + interrupted = 1; + break; + case LWSSEQ_SS_STATE_BASE + LWSSSCS_QOS_ACK_REMOTE: + lwsl_info("%s: seq LWSSSCS_QOS_ACK_REMOTE\n", __func__); + break; + case LWSSEQ_SS_STATE_BASE + LWSSSCS_QOS_ACK_LOCAL: + lwsl_info("%s: seq LWSSSCS_QOS_ACK_LOCAL\n", __func__); + break; + + /* + * This is the message we send from the ss handler to inform the + * sequencer we had the payload properly + */ + + case LWSSEQ_USER_BASE: + bad = 0; + interrupted = 1; + break; + + default: + break; + } + + return LWSSEQ_RET_CONTINUE; +} + +static void +sigint_handler(int sig) +{ + interrupted = 1; +} + +int main(int argc, const char **argv) +{ + int n = 0, logs = LLL_USER | LLL_ERR | LLL_WARN | LLL_NOTICE; + struct lws_context_creation_info info; + struct lws_context *context; + lws_seq_info_t i; + const char *p; + myseq_t *ms; + + signal(SIGINT, sigint_handler); + + if ((p = lws_cmdline_option(argc, argv, "-d"))) + logs = atoi(p); + + lws_set_log_level(logs, NULL); + lwsl_user("LWS minimal secure streams [-d][-f][--h1post]\n"); + + flag_conn_fail = !!lws_cmdline_option(argc, argv, "-f"); + flag_h1post = !!lws_cmdline_option(argc, argv, "--h1post"); + + memset(&info, 0, sizeof info); /* otherwise uninitialized garbage */ + + info.options = LWS_SERVER_OPTION_EXPLICIT_VHOSTS | + LWS_SERVER_OPTION_DO_SSL_GLOBAL_INIT; + info.fd_limit_per_thread = 1 + 1 + 1; + info.pss_policies_json = default_ss_policy; + info.port = CONTEXT_PORT_NO_LISTEN; + + context = lws_create_context(&info); + if (!context) { + lwsl_err("lws init failed\n"); + return 1; + } + + /* + * Create the sequencer that performs the steps of the test action + * from inside the event loop. + */ + + memset(&i, 0, sizeof(i)); + i.context = context; + i.user_size = sizeof(myseq_t); + i.puser = (void **)&ms; + i.cb = min_sec_str_sequencer_cb; + i.name = "min-sec-stream-seq"; + + if (!lws_seq_create(&i)) { + lwsl_err("%s: failed to create sequencer\n", __func__); + goto bail; + } + + /* the event loop */ + + while (n >= 0 && !interrupted) + n = lws_service(context, 0); + +bail: + lws_context_destroy(context); + lwsl_user("Completed: %s\n", bad ? "failed" : "OK"); + + return bad; +} diff -Nru libwebsockets-3.2.1/minimal-examples/secure-streams/minimal-secure-streams-seq/README.md libwebsockets-4.1.6/minimal-examples/secure-streams/minimal-secure-streams-seq/README.md --- libwebsockets-3.2.1/minimal-examples/secure-streams/minimal-secure-streams-seq/README.md 1970-01-01 00:00:00.000000000 +0000 +++ libwebsockets-4.1.6/minimal-examples/secure-streams/minimal-secure-streams-seq/README.md 2020-12-01 17:40:26.000000000 +0000 @@ -0,0 +1,65 @@ +# lws minimal sequre streams seq + +The application goes to https://warmcat.com and reads index.html there. + +It does it using Secure Streams... the main code in minimal-secure-streams.c +just sets up the context and opens a secure stream of type "mintest". + +The handler for state changes and payloads for "mintest" is in ss-myss.c + +The information about how a "mintest" stream should connect and the +protocol it uses is kept separated in policy-database.c + +## build + +``` + $ cmake . && make +``` + +## usage + +Commandline option|Meaning +---|--- +-d |Debug verbosity in decimal, eg, -d15 +-f| Force connecting to the wrong endpoint to check backoff retry flow + +``` + $ ./lws-minimal-secure-streams-seq +[2018/03/04 14:43:20:8562] USER: LWS minimal http client +[2018/03/04 14:43:20:8571] NOTICE: Creating Vhost 'default' port -1, 1 protocols, IPv6 on +[2018/03/04 14:43:20:8616] NOTICE: created client ssl context for default +[2018/03/04 14:43:20:8617] NOTICE: lws_client_connect_2: 0x1814dc0: address warmcat.com +[2018/03/04 14:43:21:1496] NOTICE: lws_client_connect_2: 0x1814dc0: address warmcat.com +[2018/03/04 14:43:22:0154] NOTICE: lws_client_interpret_server_handshake: incoming content length 26520 +[2018/03/04 14:43:22:0154] NOTICE: lws_client_interpret_server_handshake: client connection up +[2018/03/04 14:43:22:0169] USER: RECEIVE_CLIENT_HTTP_READ: read 1024 +[2018/03/04 14:43:22:0169] USER: RECEIVE_CLIENT_HTTP_READ: read 1024 +[2018/03/04 14:43:22:0169] USER: RECEIVE_CLIENT_HTTP_READ: read 1024 +[2018/03/04 14:43:22:0169] USER: RECEIVE_CLIENT_HTTP_READ: read 1015 +[2018/03/04 14:43:22:0174] USER: RECEIVE_CLIENT_HTTP_READ: read 1024 +[2018/03/04 14:43:22:0174] USER: RECEIVE_CLIENT_HTTP_READ: read 1024 +[2018/03/04 14:43:22:0174] USER: RECEIVE_CLIENT_HTTP_READ: read 1024 +[2018/03/04 14:43:22:0174] USER: RECEIVE_CLIENT_HTTP_READ: read 1015 +[2018/03/04 14:43:22:0179] USER: RECEIVE_CLIENT_HTTP_READ: read 1024 +[2018/03/04 14:43:22:0179] USER: RECEIVE_CLIENT_HTTP_READ: read 1024 +[2018/03/04 14:43:22:0179] USER: RECEIVE_CLIENT_HTTP_READ: read 1024 +[2018/03/04 14:43:22:0179] USER: RECEIVE_CLIENT_HTTP_READ: read 1015 +[2018/03/04 14:43:22:3010] USER: RECEIVE_CLIENT_HTTP_READ: read 1024 +[2018/03/04 14:43:22:3010] USER: RECEIVE_CLIENT_HTTP_READ: read 1024 +[2018/03/04 14:43:22:3010] USER: RECEIVE_CLIENT_HTTP_READ: read 1024 +[2018/03/04 14:43:22:3010] USER: RECEIVE_CLIENT_HTTP_READ: read 1015 +[2018/03/04 14:43:22:3015] USER: RECEIVE_CLIENT_HTTP_READ: read 1024 +[2018/03/04 14:43:22:3015] USER: RECEIVE_CLIENT_HTTP_READ: read 1024 +[2018/03/04 14:43:22:3015] USER: RECEIVE_CLIENT_HTTP_READ: read 1024 +[2018/03/04 14:43:22:3015] USER: RECEIVE_CLIENT_HTTP_READ: read 1015 +[2018/03/04 14:43:22:3020] USER: RECEIVE_CLIENT_HTTP_READ: read 1024 +[2018/03/04 14:43:22:3020] USER: RECEIVE_CLIENT_HTTP_READ: read 1024 +[2018/03/04 14:43:22:3020] USER: RECEIVE_CLIENT_HTTP_READ: read 1024 +[2018/03/04 14:43:22:3020] USER: RECEIVE_CLIENT_HTTP_READ: read 1015 +[2018/03/04 14:43:22:3022] USER: RECEIVE_CLIENT_HTTP_READ: read 1024 +[2018/03/04 14:43:22:3022] USER: RECEIVE_CLIENT_HTTP_READ: read 974 +[2018/03/04 14:43:22:3022] NOTICE: lws_http_client_read: transaction completed says -1 +[2018/03/04 14:43:23:3042] USER: Completed +``` + + diff -Nru libwebsockets-3.2.1/minimal-examples/secure-streams/minimal-secure-streams-server/CMakeLists.txt libwebsockets-4.1.6/minimal-examples/secure-streams/minimal-secure-streams-server/CMakeLists.txt --- libwebsockets-3.2.1/minimal-examples/secure-streams/minimal-secure-streams-server/CMakeLists.txt 1970-01-01 00:00:00.000000000 +0000 +++ libwebsockets-4.1.6/minimal-examples/secure-streams/minimal-secure-streams-server/CMakeLists.txt 2020-12-01 17:40:26.000000000 +0000 @@ -0,0 +1,28 @@ +project(lws-minimal-secure-streams-server C) +cmake_minimum_required(VERSION 2.8) +find_package(libwebsockets CONFIG REQUIRED) +list(APPEND CMAKE_MODULE_PATH ${LWS_CMAKE_DIR}) +include(CheckCSourceCompiles) +include(LwsCheckRequirements) + +set(SAMP lws-minimal-secure-streams-server) +set(SRCS main.c ss-client.c ss-server.c) + +set(requirements 1) +require_lws_config(LWS_ROLE_H1 1 requirements) +require_lws_config(LWS_WITH_CLIENT 1 requirements) +require_lws_config(LWS_WITH_SERVER 1 requirements) +require_lws_config(LWS_WITH_SYS_SMD 1 requirements) +require_lws_config(LWS_WITH_SECURE_STREAMS 1 requirements) +require_lws_config(LWS_WITH_SECURE_STREAMS_STATIC_POLICY_ONLY 0 requirements) + +if (requirements) + add_executable(${SAMP} ${SRCS}) + + if (websockets_shared) + target_link_libraries(${SAMP} websockets_shared ${LIBWEBSOCKETS_DEP_LIBS}) + add_dependencies(${SAMP} websockets_shared) + else() + target_link_libraries(${SAMP} websockets ${LIBWEBSOCKETS_DEP_LIBS}) + endif() +endif() diff -Nru libwebsockets-3.2.1/minimal-examples/secure-streams/minimal-secure-streams-server/main.c libwebsockets-4.1.6/minimal-examples/secure-streams/minimal-secure-streams-server/main.c --- libwebsockets-3.2.1/minimal-examples/secure-streams/minimal-secure-streams-server/main.c 1970-01-01 00:00:00.000000000 +0000 +++ libwebsockets-4.1.6/minimal-examples/secure-streams/minimal-secure-streams-server/main.c 2020-12-01 17:40:26.000000000 +0000 @@ -0,0 +1,336 @@ +/* + * lws-minimal-secure-streams-server + * + * Written in 2010-2020 by Andy Green + * + * This file is made available under the Creative Commons CC0 1.0 + * Universal Public Domain Dedication. + */ + +#include +#include +#include + +extern const lws_ss_info_t ssi_client, ssi_server; + +static struct lws_context *context; +int interrupted, bad = 1, multipart; +static const char * const default_ss_policy = + "{" + "\"release\":" "\"01234567\"," + "\"product\":" "\"myproduct\"," + "\"schema-version\":" "1," + "\"retry\": [" /* named backoff / retry strategies */ + "{\"default\": {" + "\"backoff\": [" "1000," + "2000," + "3000," + "5000," + "10000" + "]," + "\"conceal\":" "5," + "\"jitterpc\":" "20," + "\"svalidping\":" "300," + "\"svalidhup\":" "310" + "}}" + "]," + "\"certs\": [" /* named individual certificates in BASE64 DER */ + /* + * Need to be in order from root cert... notice sometimes as + * with Let's Encrypt there are multiple possible validation + * paths, all the pieces for one validation path must be + * given, excluding the server cert itself. Let's Encrypt + * intermediate is signed by their ISRG Root CA but also is + * cross-signed by an IdenTrust intermediate that's widely + * deployed in browsers. We use the ISRG path because that + * way we can skip the extra IdenTrust root cert. + */ + "{\"isrg_root_x1\": \"" /* ISRG ROOT X1 */ + "MIIFazCCA1OgAwIBAgIRAIIQz7DSQONZRGPgu2OCiwAwDQYJKoZIhvcNAQELBQAw" + "TzELMAkGA1UEBhMCVVMxKTAnBgNVBAoTIEludGVybmV0IFNlY3VyaXR5IFJlc2Vh" + "cmNoIEdyb3VwMRUwEwYDVQQDEwxJU1JHIFJvb3QgWDEwHhcNMTUwNjA0MTEwNDM4" + "WhcNMzUwNjA0MTEwNDM4WjBPMQswCQYDVQQGEwJVUzEpMCcGA1UEChMgSW50ZXJu" + "ZXQgU2VjdXJpdHkgUmVzZWFyY2ggR3JvdXAxFTATBgNVBAMTDElTUkcgUm9vdCBY" + "MTCCAiIwDQYJKoZIhvcNAQEBBQADggIPADCCAgoCggIBAK3oJHP0FDfzm54rVygc" + "h77ct984kIxuPOZXoHj3dcKi/vVqbvYATyjb3miGbESTtrFj/RQSa78f0uoxmyF+" + "0TM8ukj13Xnfs7j/EvEhmkvBioZxaUpmZmyPfjxwv60pIgbz5MDmgK7iS4+3mX6U" + "A5/TR5d8mUgjU+g4rk8Kb4Mu0UlXjIB0ttov0DiNewNwIRt18jA8+o+u3dpjq+sW" + "T8KOEUt+zwvo/7V3LvSye0rgTBIlDHCNAymg4VMk7BPZ7hm/ELNKjD+Jo2FR3qyH" + "B5T0Y3HsLuJvW5iB4YlcNHlsdu87kGJ55tukmi8mxdAQ4Q7e2RCOFvu396j3x+UC" + "B5iPNgiV5+I3lg02dZ77DnKxHZu8A/lJBdiB3QW0KtZB6awBdpUKD9jf1b0SHzUv" + "KBds0pjBqAlkd25HN7rOrFleaJ1/ctaJxQZBKT5ZPt0m9STJEadao0xAH0ahmbWn" + "OlFuhjuefXKnEgV4We0+UXgVCwOPjdAvBbI+e0ocS3MFEvzG6uBQE3xDk3SzynTn" + "jh8BCNAw1FtxNrQHusEwMFxIt4I7mKZ9YIqioymCzLq9g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cnlwdC5vcmcvMDAGCCsG" + "AQUFBzAChiRodHRwOi8vY2VydC5yb290LXgxLmxldHNlbmNyeXB0Lm9yZy8wHwYD" + "VR0jBBgwFoAUebRZ5nu25eQBc4AIiMgaWPbpm24wDQYJKoZIhvcNAQELBQADggIB" + "ABnPdSA0LTqmRf/Q1eaM2jLonG4bQdEnqOJQ8nCqxOeTRrToEKtwT++36gTSlBGx" + "A/5dut82jJQ2jxN8RI8L9QFXrWi4xXnA2EqA10yjHiR6H9cj6MFiOnb5In1eWsRM" + "UM2v3e9tNsCAgBukPHAg1lQh07rvFKm/Bz9BCjaxorALINUfZ9DD64j2igLIxle2" + "DPxW8dI/F2loHMjXZjqG8RkqZUdoxtID5+90FgsGIfkMpqgRS05f4zPbCEHqCXl1" + "eO5HyELTgcVlLXXQDgAWnRzut1hFJeczY1tjQQno6f6s+nMydLN26WuU4s3UYvOu" + "OsUxRlJu7TSRHqDC3lSE5XggVkzdaPkuKGQbGpny+01/47hfXXNB7HntWNZ6N2Vw" + "p7G6OfY+YQrZwIaQmhrIqJZuigsrbe3W+gdn5ykE9+Ky0VgVUsfxo52mwFYs1JKY" + "2PGDuWx8M6DlS6qQkvHaRUo0FMd8TsSlbF0/v965qGFKhSDeQoMpYnwcmQilRh/0" + "ayLThlHLN81gSkJjVrPI0Y8xCVPB4twb1PFUd2fPM3sA1tJ83sZ5v8vgFv2yofKR" + "PB0t6JzUA81mSqM3kxl5e+IZwhYAyO0OTg3/fs8HqGTNKd9BqoUwSRBzp06JMg5b" + "rUCGwbCUDI0mxadJ3Bz4WxR6fyNpBK2yAinWEsikxqEt" + "\"}," + /* + * a selfsigned cert for localhost for 100 years + */ + "{\"self_localhost\": \"" + "MIIF5jCCA86gAwIBAgIJANq50IuwPFKgMA0GCSqGSIb3DQEBCwUAMIGGMQswCQYD" + "VQQGEwJHQjEQMA4GA1UECAwHRXJld2hvbjETMBEGA1UEBwwKQWxsIGFyb3VuZDEb" + "MBkGA1UECgwSbGlid2Vic29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T1Qelbs7Y27sxdEnNUth4kI+wIDAQABo1MwUTAdBgNVHQ4EFgQU" + "9mYU23tW2zsomkKTAXarjr2vjuswHwYDVR0jBBgwFoAU9mYU23tW2zsomkKTAXar" + "jr2vjuswDwYDVR0TAQH/BAUwAwEB/zANBgkqhkiG9w0BAQsFAAOCAgEANjIBMrow" + "YNCbhAJdP7dhlhT2RUFRdeRUJD0IxrH/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=" + "\"}," + /* + * the private key for above + */ + "{\"self_localhost_key\": \"" + "MIIJQwIBADANBgkqhkiG9w0BAQEFAASCCS0wggkpAgEAAoICAQCjYtuWaICCY0tJ" + "PubxpIgIL+WWmz/fmK8IQr11Wtee6/IUyUlo5I602mq1qcLhT/kmpoR8Di3DAmHK" + "nSWdPWtn1B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QPnHZsUiByqb743adkbTUjmxdJzjaVtxN7ZXwZvOVrY7I7fPWYnCE" + "fXCr4+IVpZI/ZHZWpGX6CGSgT6EOjCZ5IUufIvEpqVSmtF8MqfXO9o9uIYLokrWQ" + "x1dBl5UnuTLDqw8bChq7O5y6yfuWaOWvL7nxI8NvSsfj4y635gIa/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=" + "\"}" + "]," + "\"trust_stores\": [" /* named cert chains */ + "{" + "\"name\": \"le_via_isrg\"," + "\"stack\": [" + "\"isrg_root_x1\"," + "\"LEX3_isrg_root_x1\"" + "]" + "}" + "]," + "\"s\": [" + /* + * Client streamtypes + */ + + "{\"mintest\": {" + "\"endpoint\":" "\"warmcat.com\"," + "\"port\":" "443," + "\"protocol\":" "\"h2\"," + "\"http_method\":" "\"GET\"," + "\"http_url\":" "\"index.html\"," + "\"tls\":" "true," + "\"retry\":" "\"default\"," + "\"tls_trust_store\":" "\"le_via_isrg\"" + "}}," + + /* + * This streamtype represents an h2 server listening on :7681, + * using a 100-y self-signed tls cert + */ + + "{\"myserver\": {" + /* if given, "endpoint" is network if to bind to */ + "\"server\":" "true," + "\"port\":" "7681," + "\"protocol\":" "\"h1\"," + "\"metadata\": [{" + "\"mime\": \"Content-Type:\"," + "\"method\": \"\"," + "\"path\": \"\"" + "}]," + "\"tls\":" "true," + /* + * A ws server is an http server, if you give a + * ws_subprotocol here it's understood we also serve + * that ove ws or wss according to tls + */ + "\"ws_subprotocol\":" "\"mywsprotocol\"," + "\"server_cert\":" "\"self_localhost\"," + "\"server_key\":" "\"self_localhost_key\"" + "}}," + + "]" + "}" +; + +static int +smd_cb(void *opaque, lws_smd_class_t c, lws_usec_t ts, void *buf, size_t len) +{ + if ((c & LWSSMDCL_SYSTEM_STATE) && + !lws_json_simple_strcmp(buf, len, "\"state\":", "OPERATIONAL")) { + + /* create the secure streams */ + + lwsl_notice("%s: creating server stream\n", __func__); + + if (lws_ss_create(context, 0, &ssi_server, NULL, NULL, + NULL, NULL)) { + lwsl_err("%s: failed to create secure stream\n", + __func__); + return -1; + } +#if 0 + lwsl_notice("%s: creating client stream\n", __func__); + + if (lws_ss_create(context, 0, &ssi_client, NULL, NULL, + NULL, NULL)) { + lwsl_err("%s: failed to create secure stream\n", + __func__); + return -1; + } +#endif + } + + return 0; +} + +static void +sigint_handler(int sig) +{ + interrupted = 1; +} + +int main(int argc, const char **argv) +{ + struct lws_context_creation_info info; + int n = 0; + + signal(SIGINT, sigint_handler); + + memset(&info, 0, sizeof info); /* otherwise uninitialized garbage */ + lws_cmdline_option_handle_builtin(argc, argv, &info); + + if (lws_cmdline_option(argc, argv, "-m")) + multipart = 1; + + lwsl_user("LWS Secure Streams Server\n"); + + info.options = LWS_SERVER_OPTION_EXPLICIT_VHOSTS | + LWS_SERVER_OPTION_DO_SSL_GLOBAL_INIT; + info.fd_limit_per_thread = 1 + 6 + 1; + info.pss_policies_json = default_ss_policy; + info.port = CONTEXT_PORT_NO_LISTEN; + info.early_smd_cb = smd_cb; + info.early_smd_class_filter = LWSSMDCL_SYSTEM_STATE; + + context = lws_create_context(&info); + if (!context) { + lwsl_err("lws init failed\n"); + return 1; + } + + /* the event loop */ + + while (n >= 0 && !interrupted) + n = lws_service(context, 0); + + bad = 0; + + lws_context_destroy(context); + lwsl_user("Completed: %s\n", bad ? "failed" : "OK"); + + return bad; +} diff -Nru libwebsockets-3.2.1/minimal-examples/secure-streams/minimal-secure-streams-server/README.md libwebsockets-4.1.6/minimal-examples/secure-streams/minimal-secure-streams-server/README.md --- libwebsockets-3.2.1/minimal-examples/secure-streams/minimal-secure-streams-server/README.md 1970-01-01 00:00:00.000000000 +0000 +++ libwebsockets-4.1.6/minimal-examples/secure-streams/minimal-secure-streams-server/README.md 2020-12-01 17:40:26.000000000 +0000 @@ -0,0 +1,72 @@ +# lws minimal secure streams server + +The application sets up a tls + ws server on https://localhost:7681 + +It does it using Secure Streams... information about how the server should +operate is held in JSON policy in main.c + +Visiting the server in a modern browser will fetch some html + JS, the JS will +create a ws link back to the server and the server will spam an incrementing +number that is displayed in the browser every 100ms. + +The app also has a SS client that works, but it's disabled by default since +we're interested in server. + +## build + +``` + $ cmake . && make +``` + +## usage + +Commandline option|Meaning +---|--- +-d |Debug verbosity in decimal, eg, -d15 + +``` +[2020/07/27 10:51:04:8994] U: LWS Secure Streams Server +[2020/07/27 10:51:04:9440] N: LWS: 4.0.99-v4.0.0-245-ge6eb4417a, loglevel 1031 +[2020/07/27 10:51:04:9444] N: NET CLI SRV H1 H2 WS MQTT SS-JSON-POL SSPROX ASYNC_DNS IPv6-absent +[2020/07/27 10:51:05:1685] N: lws_adopt_descriptor_vhost2: wsi 0x5317d30, vhost system ss_handle (nil) +[2020/07/27 10:51:05:1753] N: lws_adopt_descriptor_vhost2: wsi 0x53182c0, vhost system ss_handle (nil) +[2020/07/27 10:51:05:2129] N: lws_ss_policy_parser_cb: server 'self_localhost' keep 52 0x5318cc0 +[2020/07/27 10:51:05:2134] N: lws_ss_policy_parser_cb: server 'self_localhost_key' keep 53 0x5318cf8 +[2020/07/27 10:51:05:2192] N: lws_ss_policy_ref_trust_store: le_via_isrg trust store initial 'isrg_root_x1' +[2020/07/27 10:51:05:7804] N: smd_cb: creating server stream +[2020/07/27 10:51:05:7851] N: Vhost 'myserver' using TLS mode +[2020/07/27 10:51:05:8660] N: SSL ECDH curve 'prime256v1' +[2020/07/27 10:51:06:1035] N: vhost myserver: cert expiry: 729599d +[2020/07/27 10:51:06:1039] N: lws_ss_create: created server myserver +[2020/07/27 10:51:11:8650] N: lws_adopt_descriptor_vhost2: wsi 0x5b046e0, vhost myserver ss_handle 0x56e2be0 +[2020/07/27 10:51:11:8672] U: myss_srv_state: 0x5b52f60 LWSSSCS_CREATING, ord 0x0 +[2020/07/27 10:51:11:8693] U: myss_srv_state: 0x5b52f60 LWSSSCS_CONNECTING, ord 0x0 +[2020/07/27 10:51:11:8696] U: myss_srv_state: 0x5b52f60 LWSSSCS_CONNECTED, ord 0x0 +[2020/07/27 10:51:11:9743] U: myss_srv_state: 0x5ba2bd0 LWSSSCS_CREATING, ord 0x0 +[2020/07/27 10:51:11:9747] U: myss_srv_state: 0x5ba2bd0 LWSSSCS_CONNECTING, ord 0x0 +[2020/07/27 10:51:11:9747] U: myss_srv_state: 0x5ba2bd0 LWSSSCS_CONNECTED, ord 0x0 +[2020/07/27 10:51:12:0192] U: myss_srv_state: 0x5bad0a0 LWSSSCS_CREATING, ord 0x0 +[2020/07/27 10:51:12:0193] U: myss_srv_state: 0x5bad0a0 LWSSSCS_CONNECTING, ord 0x0 +[2020/07/27 10:51:12:0194] U: myss_srv_state: 0x5bad0a0 LWSSSCS_CONNECTED, ord 0x0 +[2020/07/27 10:51:12:0306] N: secstream_h1: LWS_CALLBACK_HTTP +[2020/07/27 10:51:12:0329] U: myss_srv_state: 0x5bad0a0 LWSSSCS_SERVER_TXN, ord 0x0 +[2020/07/27 10:51:12:0481] N: lws_h2_ws_handshake: Server SS 0x5ba2bd0 .wsi 0x5ba27b0 switching to ws protocol +[2020/07/27 10:51:12:0484] U: myss_srv_state: 0x5ba2bd0 LWSSSCS_SERVER_UPGRADE, ord 0x0 +[2020/07/27 10:51:12:0541] U: myss_srv_state: 0x5ba2bd0 LWSSSCS_CONNECTED, ord 0x0 +[2020/07/27 10:51:12:1222] U: myss_srv_state: 0x5bd1100 LWSSSCS_CREATING, ord 0x0 +[2020/07/27 10:51:12:1222] U: myss_srv_state: 0x5bd1100 LWSSSCS_CONNECTING, ord 0x0 +[2020/07/27 10:51:12:1223] U: myss_srv_state: 0x5bd1100 LWSSSCS_CONNECTED, ord 0x0 +[2020/07/27 10:51:12:1242] N: lws_h2_ws_handshake: Server SS 0x5bd1100 .wsi 0x5bd0ce0 switching to ws protocol +[2020/07/27 10:51:12:1243] U: myss_srv_state: 0x5bd1100 LWSSSCS_SERVER_UPGRADE, ord 0x0 +[2020/07/27 10:51:12:1246] U: myss_srv_state: 0x5bd1100 LWSSSCS_CONNECTED, ord 0x0 +^C[2020/07/27 10:51:15:2809] U: myss_srv_state: 0x5bad0a0 LWSSSCS_DISCONNECTED, ord 0x0 +[2020/07/27 10:51:15:2838] U: myss_srv_state: 0x5bad0a0 LWSSSCS_DESTROYING, ord 0x0 +[2020/07/27 10:51:15:2938] U: myss_srv_state: 0x5ba2bd0 LWSSSCS_DISCONNECTED, ord 0x0 +[2020/07/27 10:51:15:2946] U: myss_srv_state: 0x5ba2bd0 LWSSSCS_DESTROYING, ord 0x0 +[2020/07/27 10:51:15:2952] U: myss_srv_state: 0x5bd1100 LWSSSCS_DISCONNECTED, ord 0x0 +[2020/07/27 10:51:15:2953] U: myss_srv_state: 0x5bd1100 LWSSSCS_DESTROYING, ord 0x0 +[2020/07/27 10:51:15:2960] U: myss_srv_state: 0x5b52f60 LWSSSCS_DISCONNECTED, ord 0x0 +[2020/07/27 10:51:15:2961] U: myss_srv_state: 0x5b52f60 LWSSSCS_DESTROYING, ord 0x0 +[2020/07/27 10:51:15:3042] U: myss_srv_state: 0x56e2be0 LWSSSCS_DESTROYING, ord 0x0 +[2020/07/27 10:51:15:3378] U: Completed: OK +``` diff -Nru libwebsockets-3.2.1/minimal-examples/secure-streams/minimal-secure-streams-server/ss-client.c libwebsockets-4.1.6/minimal-examples/secure-streams/minimal-secure-streams-server/ss-client.c --- libwebsockets-3.2.1/minimal-examples/secure-streams/minimal-secure-streams-server/ss-client.c 1970-01-01 00:00:00.000000000 +0000 +++ libwebsockets-4.1.6/minimal-examples/secure-streams/minimal-secure-streams-server/ss-client.c 2020-12-01 17:40:26.000000000 +0000 @@ -0,0 +1,86 @@ +/* + * lws-minimal-secure-streams-server + * + * Written in 2010-2020 by Andy Green + * + * This file is made available under the Creative Commons CC0 1.0 + * Universal Public Domain Dedication. + */ + +#include + +extern int interrupted, bad; + +typedef struct myss { + struct lws_ss_handle *ss; + void *opaque_data; + /* ... application specific state ... */ + lws_sorted_usec_list_t sul; + + int count; +} myss_t; + +/* secure streams payload interface */ + +static int +myss_rx(void *userobj, const uint8_t *buf, size_t len, int flags) +{ +// myss_t *m = (myss_t *)userobj; + + lwsl_user("%s: len %d, flags: %d\n", __func__, (int)len, flags); + lwsl_hexdump_info(buf, len); + + /* + * If we received the whole message, for our example it means + * we are done. + */ + if (flags & LWSSS_FLAG_EOM) { + bad = 0; + interrupted = 1; + } + + return 0; +} + +static int +myss_tx(void *userobj, lws_ss_tx_ordinal_t ord, uint8_t *buf, size_t *len, + int *flags) +{ + //myss_t *m = (myss_t *)userobj; + + return LWSSSSRET_TX_DONT_SEND; /* don't want to write */ +} + +static int +myss_state(void *userobj, void *sh, lws_ss_constate_t state, + lws_ss_tx_ordinal_t ack) +{ + myss_t *m = (myss_t *)userobj; + + lwsl_user("%s: %p %s, ord 0x%x\n", __func__, m->ss, + lws_ss_state_name(state), (unsigned int)ack); + + switch (state) { + case LWSSSCS_CREATING: + lws_ss_request_tx(m->ss); + break; + case LWSSSCS_ALL_RETRIES_FAILED: + /* if we're out of retries, we want to close the app and FAIL */ + interrupted = 1; + break; + default: + break; + } + + return 0; +} + +const lws_ss_info_t ssi_client = { + .handle_offset = offsetof(myss_t, ss), + .opaque_user_data_offset = offsetof(myss_t, opaque_data), + .streamtype = "mintest", + .rx = myss_rx, + .tx = myss_tx, + .state = myss_state, + .user_alloc = sizeof(myss_t), +}; diff -Nru libwebsockets-3.2.1/minimal-examples/secure-streams/minimal-secure-streams-server/ss-server.c libwebsockets-4.1.6/minimal-examples/secure-streams/minimal-secure-streams-server/ss-server.c --- libwebsockets-3.2.1/minimal-examples/secure-streams/minimal-secure-streams-server/ss-server.c 1970-01-01 00:00:00.000000000 +0000 +++ libwebsockets-4.1.6/minimal-examples/secure-streams/minimal-secure-streams-server/ss-server.c 2020-12-01 17:40:26.000000000 +0000 @@ -0,0 +1,235 @@ +/* + * lws-minimal-secure-streams-server + * + * Written in 2010-2020 by Andy Green + * + * This file is made available under the Creative Commons CC0 1.0 + * Universal Public Domain Dedication. + */ + +#include +#include + +extern int interrupted, bad, multipart; + +static const char *html = + /* normally we serve this... */ + "" + "Hello from the web server
" + "

" + "", + +*multipart_html = + /* + * If you use -m commandline switch we send this instead, as + * multipart/form-data + */ + "--aBoundaryString\r\n" + "Content-Disposition: form-data; name=\"myFile\"; filename=\"xxx.txt\"\r\n" + "Content-Type: text/plain\r\n" + "\r\n" + "The file contents\r\n" + "--aBoundaryString\r\n" + "Content-Disposition: form-data; name=\"myField\"\r\n" + "\r\n" + "(data)\r\n" + "--aBoundaryString--\r\n"; + + +typedef struct myss { + struct lws_ss_handle *ss; + void *opaque_data; + /* ... application specific state ... */ + + lws_sorted_usec_list_t sul; + int count; + char upgraded; + +} myss_srv_t; + +/* + * This is the Secure Streams Server RX and TX for HTTP(S) + */ + +static int +myss_srv_rx(void *userobj, const uint8_t *buf, size_t len, int flags) +{ +// myss_srv_t *m = (myss_srv_t *)userobj; + + lwsl_user("%s: len %d, flags: %d\n", __func__, (int)len, flags); + lwsl_hexdump_info(buf, len); + + /* + * If we received the whole message, for our example it means + * we are done. + */ + if (flags & LWSSS_FLAG_EOM) { + bad = 0; + interrupted = 1; + } + + return 0; +} + +static int +myss_srv_tx(void *userobj, lws_ss_tx_ordinal_t ord, uint8_t *buf, size_t *len, + int *flags) +{ + myss_srv_t *m = (myss_srv_t *)userobj; + const char *send = html; + + if (m->upgraded) + return LWSSSSRET_TX_DONT_SEND; + + if (multipart) + send = multipart_html; + + *flags = LWSSS_FLAG_SOM | LWSSS_FLAG_EOM; + + lws_strncpy((char *)buf, send, *len); + *len = strlen(send); + + return 0; +} + +/* + * This is the Secure Streams Server RX and TX for WS(S)... when we get a + * state that the underlying connection upgraded protocol, we switch the stream + * rx and tx handlers to here. + */ + +static int +myss_ws_rx(void *userobj, const uint8_t *buf, size_t len, int flags) +{ +// myss_srv_t *m = (myss_srv_t *)userobj; + + lwsl_user("%s: len %d, flags: %d\n", __func__, (int)len, flags); + lwsl_hexdump_info(buf, len); + + /* + * If we received the whole message, for our example it means + * we are done. + */ + if (flags & LWSSS_FLAG_EOM) { + bad = 0; + interrupted = 1; + } + + return 0; +} + +/* this is the callback that mediates sending the incrementing number */ + +static void +spam_sul_cb(struct lws_sorted_usec_list *sul) +{ + myss_srv_t *m = lws_container_of(sul, myss_srv_t, sul); + + lws_ss_request_tx(m->ss); + + lws_sul_schedule(lws_ss_get_context(m->ss), 0, &m->sul, spam_sul_cb, + 100 * LWS_US_PER_MS); +} + +static int +myss_ws_tx(void *userobj, lws_ss_tx_ordinal_t ord, uint8_t *buf, size_t *len, + int *flags) +{ + myss_srv_t *m = (myss_srv_t *)userobj; + + *flags = LWSSS_FLAG_SOM | LWSSS_FLAG_EOM; + + *len = lws_snprintf((char *)buf, *len, "hello from ws %d", m->count++); + + lws_sul_schedule(lws_ss_get_context(m->ss), 0, &m->sul, spam_sul_cb, + 100 * LWS_US_PER_MS); + + return 0; +} + +static int +myss_srv_state(void *userobj, void *sh, lws_ss_constate_t state, + lws_ss_tx_ordinal_t ack) +{ + myss_srv_t *m = (myss_srv_t *)userobj; + + lwsl_user("%s: %p %s, ord 0x%x\n", __func__, m->ss, + lws_ss_state_name(state), (unsigned int)ack); + + switch (state) { + case LWSSSCS_DISCONNECTED: + lws_sul_cancel(&m->sul); + break; + case LWSSSCS_CREATING: + lws_ss_request_tx(m->ss); + break; + case LWSSSCS_ALL_RETRIES_FAILED: + /* if we're out of retries, we want to close the app and FAIL */ + interrupted = 1; + break; + + case LWSSSCS_SERVER_TXN: + /* + * The underlying protocol started a transaction, let's + * describe how we want to complete it. We can defer this until + * later, eg, after we have consumed any rx that's coming with + * the client's transaction initiation phase, but in this + * example we know what we want to do already. + * + * We do want to ack the transaction... + */ + lws_ss_server_ack(m->ss, 0); + /* + * ... it's going to be either text/html or multipart ... + */ + if (multipart) + lws_ss_set_metadata(m->ss, "mime", + "multipart/form-data; boundary=aBoundaryString", 45); + else + lws_ss_set_metadata(m->ss, "mime", "text/html", 9); + /* + * ...it's going to be whatever size it is (and request tx) + */ + lws_ss_request_tx_len(m->ss, (unsigned long) + (multipart ? strlen(multipart_html) : + strlen(html))); + break; + + case LWSSSCS_SERVER_UPGRADE: + + /* + * This is sent when the underlying protocol has experienced + * an upgrade, eg, http->ws... it's a one-way upgrade on this + * stream, change the handlers to deal with the kind of + * messages we send on ws + */ + + m->upgraded = 1; + lws_ss_change_handlers(m->ss, myss_ws_rx, myss_ws_tx, NULL); + lws_ss_request_tx(m->ss); /* we want to start sending numbers */ + break; + default: + break; + } + + return 0; +} + +const lws_ss_info_t ssi_server = { + .handle_offset = offsetof(myss_srv_t, ss), + .opaque_user_data_offset = offsetof(myss_srv_t, opaque_data), + .streamtype = "myserver", + .rx = myss_srv_rx, + .tx = myss_srv_tx, + .state = myss_srv_state, + .user_alloc = sizeof(myss_srv_t), +}; diff -Nru libwebsockets-3.2.1/minimal-examples/secure-streams/minimal-secure-streams-server-raw/CMakeLists.txt libwebsockets-4.1.6/minimal-examples/secure-streams/minimal-secure-streams-server-raw/CMakeLists.txt --- libwebsockets-3.2.1/minimal-examples/secure-streams/minimal-secure-streams-server-raw/CMakeLists.txt 1970-01-01 00:00:00.000000000 +0000 +++ libwebsockets-4.1.6/minimal-examples/secure-streams/minimal-secure-streams-server-raw/CMakeLists.txt 2020-12-01 17:40:26.000000000 +0000 @@ -0,0 +1,27 @@ +project(lws-minimal-secure-streams-server-raw C) +cmake_minimum_required(VERSION 2.8) +find_package(libwebsockets CONFIG REQUIRED) +list(APPEND CMAKE_MODULE_PATH ${LWS_CMAKE_DIR}) +include(CheckCSourceCompiles) +include(LwsCheckRequirements) + +set(SAMP lws-minimal-secure-streams-server-raw) +set(SRCS main.c ss-server.c) + +set(requirements 1) +require_lws_config(LWS_ROLE_H1 1 requirements) +require_lws_config(LWS_WITH_SERVER 1 requirements) +require_lws_config(LWS_WITH_SYS_SMD 1 requirements) +require_lws_config(LWS_WITH_SECURE_STREAMS 1 requirements) +require_lws_config(LWS_WITH_SECURE_STREAMS_STATIC_POLICY_ONLY 0 requirements) + +if (requirements) + add_executable(${SAMP} ${SRCS}) + + if (websockets_shared) + target_link_libraries(${SAMP} websockets_shared ${LIBWEBSOCKETS_DEP_LIBS}) + add_dependencies(${SAMP} websockets_shared) + else() + target_link_libraries(${SAMP} websockets ${LIBWEBSOCKETS_DEP_LIBS}) + endif() +endif() diff -Nru libwebsockets-3.2.1/minimal-examples/secure-streams/minimal-secure-streams-server-raw/main.c libwebsockets-4.1.6/minimal-examples/secure-streams/minimal-secure-streams-server-raw/main.c --- libwebsockets-3.2.1/minimal-examples/secure-streams/minimal-secure-streams-server-raw/main.c 1970-01-01 00:00:00.000000000 +0000 +++ libwebsockets-4.1.6/minimal-examples/secure-streams/minimal-secure-streams-server-raw/main.c 2020-12-01 17:40:26.000000000 +0000 @@ -0,0 +1,104 @@ +/* + * lws-minimal-secure-streams-server + * + * Written in 2010-2020 by Andy Green + * + * This file is made available under the Creative Commons CC0 1.0 + * Universal Public Domain Dedication. + */ + +#include +#include +#include + +extern const lws_ss_info_t ssi_client, ssi_server; + +static struct lws_context *context; +int interrupted, bad = 1; +static const char * const default_ss_policy = + "{" + "\"release\":" "\"01234567\"," + "\"product\":" "\"myproduct\"," + "\"schema-version\":" "1," + "\"s\": [" + + /* + * This streamtype represents a raw server listening on :7681, + * without tls + */ + + "{\"myrawserver\": {" + /* if given, "endpoint" is network if to bind to */ + "\"server\":" "true," + "\"port\":" "7681," + "\"protocol\":" "\"raw\"" + "}}" + + "]" + "}" +; + +static int +smd_cb(void *opaque, lws_smd_class_t c, lws_usec_t ts, void *buf, size_t len) +{ + if ((c & LWSSMDCL_SYSTEM_STATE) && + !lws_json_simple_strcmp(buf, len, "\"state\":", "OPERATIONAL")) { + + /* create the secure streams */ + + lwsl_notice("%s: creating server stream\n", __func__); + + if (lws_ss_create(context, 0, &ssi_server, NULL, NULL, + NULL, NULL)) { + lwsl_err("%s: failed to create secure stream\n", + __func__); + return -1; + } + } + + return 0; +} + +static void +sigint_handler(int sig) +{ + interrupted = 1; +} + +int main(int argc, const char **argv) +{ + struct lws_context_creation_info info; + int n = 0; + + signal(SIGINT, sigint_handler); + + memset(&info, 0, sizeof info); /* otherwise uninitialized garbage */ + lws_cmdline_option_handle_builtin(argc, argv, &info); + lwsl_user("LWS Secure Streams Server Raw\n"); + + info.options = LWS_SERVER_OPTION_EXPLICIT_VHOSTS | + LWS_SERVER_OPTION_DO_SSL_GLOBAL_INIT; + info.fd_limit_per_thread = 1 + 6 + 1; + info.pss_policies_json = default_ss_policy; + info.port = CONTEXT_PORT_NO_LISTEN; + info.early_smd_cb = smd_cb; + info.early_smd_class_filter = LWSSMDCL_SYSTEM_STATE; + + context = lws_create_context(&info); + if (!context) { + lwsl_err("lws init failed\n"); + return 1; + } + + /* the event loop */ + + while (n >= 0 && !interrupted) + n = lws_service(context, 0); + + bad = 0; + + lws_context_destroy(context); + lwsl_user("Completed: %s\n", bad ? "failed" : "OK"); + + return bad; +} diff -Nru libwebsockets-3.2.1/minimal-examples/secure-streams/minimal-secure-streams-server-raw/README.md libwebsockets-4.1.6/minimal-examples/secure-streams/minimal-secure-streams-server-raw/README.md --- libwebsockets-3.2.1/minimal-examples/secure-streams/minimal-secure-streams-server-raw/README.md 1970-01-01 00:00:00.000000000 +0000 +++ libwebsockets-4.1.6/minimal-examples/secure-streams/minimal-secure-streams-server-raw/README.md 2020-12-01 17:40:26.000000000 +0000 @@ -0,0 +1,54 @@ +# lws minimal secure streams server raw + +The application sets up a raw tcp server on localhost:7681 + +It does it using Secure Streams... information about how the server should +operate is held in JSON policy in main.c + +Connecting to the server using `echo "hello" | nc --no-shutdown 127.0.0.1 7681` +will send "hello" which is hexdumped to console by the rx function, then +will receive an incrementing message at 100ms intervals. + +Note there are two incomaptible versions of netcat around, this is from Fedora's +nmap-ncat, the --no-shutdown is needed to stop it hanging up itself after it +has sent its stdin. + +## build + +``` + $ cmake . && make +``` + +## usage + +Commandline option|Meaning +---|--- +-d |Debug verbosity in decimal, eg, -d15 + +``` +[2020/07/28 10:25:54:6747] U: LWS Secure Streams Server Raw +[2020/07/28 10:25:54:7194] N: LWS: 4.0.99-v4.0.0-247-g58be599aa, loglevel 1031 +[2020/07/28 10:25:54:7198] N: NET CLI SRV H1 H2 WS MQTT SS-JSON-POL SSPROX ASYNC_DNS IPv6-absent +[2020/07/28 10:25:54:9376] N: lws_adopt_descriptor_vhost2: wsi 0x5317d30, vhost system ss_handle (nil) +[2020/07/28 10:25:54:9442] N: lws_adopt_descriptor_vhost2: wsi 0x53182c0, vhost system ss_handle (nil) +[2020/07/28 10:25:54:9920] N: smd_cb: creating server stream +[2020/07/28 10:25:54:9963] N: lws_ss_create: created server myrawserver +[2020/07/28 10:26:00:1065] N: secstream_raw: RAW_ADOPT +[2020/07/28 10:26:00:1068] N: lws_adopt_descriptor_vhost2: wsi 0x531a6b0, vhost myrawserver ss_handle 0x5319ac0 +[2020/07/28 10:26:00:1088] U: myss_raw_state: 0x531aad0 LWSSSCS_CREATING, ord 0x0 +[2020/07/28 10:26:00:1094] U: myss_raw_state: 0x531aad0 LWSSSCS_CONNECTING, ord 0x0 +[2020/07/28 10:26:00:1096] U: myss_raw_state: 0x531aad0 LWSSSCS_CONNECTED, ord 0x0 +[2020/07/28 10:26:00:1172] U: myss_raw_rx: len 6, flags: 0 +[2020/07/28 10:26:02:8516] U: myss_raw_state: 0x531aad0 LWSSSCS_DISCONNECTED, ord 0x0 +[2020/07/28 10:26:02:8545] U: myss_raw_state: 0x531aad0 LWSSSCS_DESTROYING, ord 0x0 +^C[2020/07/28 10:26:04:9608] U: myss_raw_state: 0x5319ac0 LWSSSCS_DESTROYING, ord 0x0 +[2020/07/28 10:26:04:9723] U: Completed: OK +``` + +``` +$ echo "hello" | nc --no-shutdown 127.0.0.1 7681 +hello from raw 0 +hello from raw 1 +hello from raw 2 +... +``` diff -Nru libwebsockets-3.2.1/minimal-examples/secure-streams/minimal-secure-streams-server-raw/ss-server.c libwebsockets-4.1.6/minimal-examples/secure-streams/minimal-secure-streams-server-raw/ss-server.c --- libwebsockets-3.2.1/minimal-examples/secure-streams/minimal-secure-streams-server-raw/ss-server.c 1970-01-01 00:00:00.000000000 +0000 +++ libwebsockets-4.1.6/minimal-examples/secure-streams/minimal-secure-streams-server-raw/ss-server.c 2020-12-01 17:40:26.000000000 +0000 @@ -0,0 +1,111 @@ +/* + * lws-minimal-secure-streams-server + * + * Written in 2010-2020 by Andy Green + * + * This file is made available under the Creative Commons CC0 1.0 + * Universal Public Domain Dedication. + */ + +#include +#include + +extern int interrupted, bad; + +typedef struct myss { + struct lws_ss_handle *ss; + void *opaque_data; + /* ... application specific state ... */ + + lws_sorted_usec_list_t sul; + int count; + char upgraded; + +} myss_srv_t; + +/* + * This is the Secure Streams Server RX and TX + */ + +static int +myss_raw_rx(void *userobj, const uint8_t *buf, size_t len, int flags) +{ +// myss_srv_t *m = (myss_srv_t *)userobj; + + lwsl_user("%s: len %d, flags: %d\n", __func__, (int)len, flags); + lwsl_hexdump_info(buf, len); + + /* + * If we received the whole message, for our example it means + * we are done. + */ + if (flags & LWSSS_FLAG_EOM) { + bad = 0; + interrupted = 1; + } + + return 0; +} + +/* this is the callback that mediates sending the incrementing number */ + +static void +spam_sul_cb(struct lws_sorted_usec_list *sul) +{ + myss_srv_t *m = lws_container_of(sul, myss_srv_t, sul); + + lws_ss_request_tx(m->ss); + + lws_sul_schedule(lws_ss_get_context(m->ss), 0, &m->sul, spam_sul_cb, + 100 * LWS_US_PER_MS); +} + +static int +myss_raw_tx(void *userobj, lws_ss_tx_ordinal_t ord, uint8_t *buf, size_t *len, + int *flags) +{ + myss_srv_t *m = (myss_srv_t *)userobj; + + *flags = LWSSS_FLAG_SOM | LWSSS_FLAG_EOM; + + *len = lws_snprintf((char *)buf, *len, "hello from raw %d\n", m->count++); + + lws_sul_schedule(lws_ss_get_context(m->ss), 0, &m->sul, spam_sul_cb, + 100 * LWS_US_PER_MS); + + return 0; +} + +static int +myss_raw_state(void *userobj, void *sh, lws_ss_constate_t state, + lws_ss_tx_ordinal_t ack) +{ + myss_srv_t *m = (myss_srv_t *)userobj; + + lwsl_user("%s: %p %s, ord 0x%x\n", __func__, m->ss, + lws_ss_state_name(state), (unsigned int)ack); + + switch (state) { + case LWSSSCS_DISCONNECTED: + lws_sul_cancel(&m->sul); + break; + case LWSSSCS_CONNECTED: + lws_ss_request_tx(m->ss); + break; + + default: + break; + } + + return 0; +} + +const lws_ss_info_t ssi_server = { + .handle_offset = offsetof(myss_srv_t, ss), + .opaque_user_data_offset = offsetof(myss_srv_t, opaque_data), + .streamtype = "myrawserver", + .rx = myss_raw_rx, + .tx = myss_raw_tx, + .state = myss_raw_state, + .user_alloc = sizeof(myss_srv_t), +}; diff -Nru libwebsockets-3.2.1/minimal-examples/secure-streams/minimal-secure-streams-smd/CMakeLists.txt libwebsockets-4.1.6/minimal-examples/secure-streams/minimal-secure-streams-smd/CMakeLists.txt --- libwebsockets-3.2.1/minimal-examples/secure-streams/minimal-secure-streams-smd/CMakeLists.txt 1970-01-01 00:00:00.000000000 +0000 +++ libwebsockets-4.1.6/minimal-examples/secure-streams/minimal-secure-streams-smd/CMakeLists.txt 2020-12-01 17:40:26.000000000 +0000 @@ -0,0 +1,48 @@ +project(lws-minimal-secure-streams-smd C) +cmake_minimum_required(VERSION 2.8) +find_package(libwebsockets CONFIG REQUIRED) +list(APPEND CMAKE_MODULE_PATH ${LWS_CMAKE_DIR}) +include(CheckCSourceCompiles) +include(LwsCheckRequirements) + +set(requirements 1) +require_lws_config(LWS_ROLE_H1 1 requirements) +require_lws_config(LWS_WITH_CLIENT 1 requirements) +require_lws_config(LWS_WITH_SECURE_STREAMS 1 requirements) +require_lws_config(LWS_WITH_SYS_SMD 1 requirements) +require_lws_config(LWS_WITH_SECURE_STREAMS_STATIC_POLICY_ONLY 0 requirements) +require_lws_config(LWS_WITH_SYS_STATE 1 requirements) + +if (requirements) + add_executable(${PROJECT_NAME} minimal-secure-streams-smd.c) + + if (LWS_CTEST_INTERNET_AVAILABLE) + add_test(NAME ss-smd COMMAND lws-minimal-secure-streams-smd) + set_tests_properties(ss-smd + PROPERTIES + WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}/minimal-examples/secure-streams/minimal-secure-streams-smd + TIMEOUT 10) + endif() + + if (websockets_shared) + target_link_libraries(${PROJECT_NAME} websockets_shared ${LIBWEBSOCKETS_DEP_LIBS}) + add_dependencies(${PROJECT_NAME} websockets_shared) + else() + target_link_libraries(${PROJECT_NAME} websockets ${LIBWEBSOCKETS_DEP_LIBS}) + endif() + + CHECK_C_SOURCE_COMPILES("#include \nint main(void) {\ni#if defined(LWS_WITH_SECURE_STREAMS_PROXY_API)\n return 0;\n #else\n fail\n #endif\n return 0;\n}\n" HAS_LWS_WITH_SECURE_STREAMS_PROXY_API) + + if (HAS_LWS_WITH_SECURE_STREAMS_PROXY_API OR LWS_WITH_SECURE_STREAMS_PROXY_API) + add_compile_options(-DLWS_SS_USE_SSPC) + + add_executable(${PROJECT_NAME}-client minimal-secure-streams-smd.c) + if (websockets_shared) + target_link_libraries(${PROJECT_NAME}-client websockets_shared ${LIBWEBSOCKETS_DEP_LIBS}) + add_dependencies(${PROJECT_NAME}-client websockets_shared) + else() + target_link_libraries(${PROJECT_NAME}-client websockets ${LIBWEBSOCKETS_DEP_LIBS}) + endif() + endif() + +endif() diff -Nru libwebsockets-3.2.1/minimal-examples/secure-streams/minimal-secure-streams-smd/minimal-secure-streams-smd.c libwebsockets-4.1.6/minimal-examples/secure-streams/minimal-secure-streams-smd/minimal-secure-streams-smd.c --- libwebsockets-3.2.1/minimal-examples/secure-streams/minimal-secure-streams-smd/minimal-secure-streams-smd.c 1970-01-01 00:00:00.000000000 +0000 +++ libwebsockets-4.1.6/minimal-examples/secure-streams/minimal-secure-streams-smd/minimal-secure-streams-smd.c 2020-12-01 17:40:26.000000000 +0000 @@ -0,0 +1,319 @@ +/* + * lws-minimal-secure-streams-smd + * + * Written in 2010-2020 by Andy Green + * + * This file is made available under the Creative Commons CC0 1.0 + * Universal Public Domain Dedication. + * + * + * This demonstrates a minimal http client using secure streams to access the + * SMD api. + */ + +#include +#include +#include + +static int interrupted, bad = 1, count_p1, count_p2, count_tx; +static lws_sorted_usec_list_t sul_timeout; + +/* + * If the -proxy app is fulfilling our connection, then we don't need to have + * the policy in the client. + * + * When we build with LWS_SS_USE_SSPC, the apis hook up to a proxy process over + * a Unix Domain Socket. To test that, you need to separately run the + * ./lws-minimal-secure-streams-proxy test app on the same machine. + */ + +#if !defined(LWS_SS_USE_SSPC) +static const char * const default_ss_policy = + "{" + "\"schema-version\":1," + "\"s\": [" + "{" + /* + * "captive_portal_detect" describes + * what to do in order to check if the path to + * the Internet is being interrupted by a + * captive portal. If there's a larger policy + * fetched from elsewhere, it should also include + * this since it needs to be done at least after + * every DHCP acquisition + */ + "\"captive_portal_detect\": {" + "\"endpoint\": \"connectivitycheck.android.com\"," + "\"http_url\": \"generate_204\"," + "\"port\": 80," + "\"protocol\": \"h1\"," + "\"http_method\": \"GET\"," + "\"opportunistic\": true," + "\"http_expect\": 204," + "\"http_fail_redirect\": true" + "}" + "}" + "]" + "}" +; + +#endif + +typedef struct myss { + struct lws_ss_handle *ss; + void *opaque_data; + /* ... application specific state ... */ + lws_sorted_usec_list_t sul; + char alternate; +} myss_t; + + +/* secure streams payload interface */ + +static int +myss_rx(void *userobj, const uint8_t *buf, size_t len, int flags) +{ +// myss_t *m = (myss_t *)userobj; + + lwsl_notice("%s: len %d, flags: %d\n", __func__, (int)len, flags); + lwsl_hexdump_notice(buf, len); + + count_p1++; + + return 0; +} + +static void +sul_tx_periodic_cb(lws_sorted_usec_list_t *sul) +{ + myss_t *m = lws_container_of(sul, myss_t, sul); + + lwsl_notice("%s: requesting TX\n", __func__); + lws_ss_request_tx(m->ss); +} + +static int +myss_tx(void *userobj, lws_ss_tx_ordinal_t ord, uint8_t *buf, size_t *len, + int *flags) +{ + myss_t *m = (myss_t *)userobj; + + lwsl_notice("%s: sending SS smd\n", __func__); + + /* + * The SS RX isn't going to see INTERACTION messages, because its class + * filter doesn't accept INTERACTION class messages. The direct + * participant we also set up for the test will see them though. + * + * Let's alternate between sending NETWORK class smd messages and + * INTERACTION so we can test both rx paths + */ + + m->alternate++; + lws_ser_wu64be(buf, (m->alternate & 1) ? LWSSMDCL_NETWORK : LWSSMDCL_INTERACTION); + lws_ser_wu64be(buf + 8, 0); /* valgrind notices uninitialized if left */ + + if (m->alternate == 4) { + /* + * after a few, let's request a CPD check + */ + *len = LWS_SMD_SS_RX_HEADER_LEN + + lws_snprintf((char *)buf + LWS_SMD_SS_RX_HEADER_LEN, *len, + "{\"trigger\": \"cpdcheck\", \"src\":\"SS-test\"}"); + } else + + *len = LWS_SMD_SS_RX_HEADER_LEN + + lws_snprintf((char *)buf + LWS_SMD_SS_RX_HEADER_LEN, *len, + (m->alternate & 1) ? "{\"class\":\"NETWORK\"}" : + "{\"class\":\"INTERACTION\"}"); + + *flags = LWSSS_FLAG_SOM | LWSSS_FLAG_EOM; + + count_tx++; + + lws_sul_schedule(lws_ss_get_context(m->ss), 0, &m->sul, + sul_tx_periodic_cb, 250 * LWS_US_PER_MS); + + return 0; +} + +static int +myss_state(void *userobj, void *h_src, lws_ss_constate_t state, + lws_ss_tx_ordinal_t ack) +{ + myss_t *m = (myss_t *)userobj; + + if (state == LWSSSCS_DESTROYING) { + lws_sul_cancel(&m->sul); + return 0; + } + + if (state == LWSSSCS_CONNECTED) { + lwsl_notice("%s: CONNECTED\n", __func__); + lws_sul_schedule(lws_ss_get_context(m->ss), 0, &m->sul, + sul_tx_periodic_cb, 1); + return 0; + } + + return 0; +} + +static const lws_ss_info_t ssi_lws_smd = { + .handle_offset = offsetof(myss_t, ss), + .opaque_user_data_offset = offsetof(myss_t, opaque_data), + .rx = myss_rx, + .tx = myss_tx, + .state = myss_state, + .user_alloc = sizeof(myss_t), + .streamtype = LWS_SMD_STREAMTYPENAME, + .manual_initial_tx_credit = LWSSMDCL_SYSTEM_STATE | + LWSSMDCL_NETWORK, +}; + +/* for comparison, this is a non-SS lws_smd participant */ + +static int +direct_smd_cb(void *opaque, lws_smd_class_t _class, lws_usec_t timestamp, + void *buf, size_t len) +{ + struct lws_context **pctx = (struct lws_context **)opaque; + + lwsl_notice("%s: class: 0x%x, ts: %llu\n", __func__, _class, + (unsigned long long)timestamp); + lwsl_hexdump_notice(buf, len); + + count_p2++; + + if (_class != LWSSMDCL_SYSTEM_STATE) + return 0; + + if (!lws_json_simple_strcmp(buf, len, "\"state\":", "OPERATIONAL")) { + +#if !defined(LWS_SS_USE_SSPC) + /* + * Let's trigger a CPD check, just as a test. SS can't see it + * anyway since it doesn't listen for NETWORK but the direct / + * local participant will see it and the result + * + * This process doesn't run the smd / captive portal action + * when it's a client of the SS proxy. SMD has to be passed + * via the SS _lws_smd proxied connection in that case. + */ + (void)lws_smd_msg_printf(*pctx, LWSSMDCL_NETWORK, + "{\"trigger\": \"cpdcheck\", \"src\":\"direct-test\"}"); +#endif + + /* + * Create the SS link to lws_smd... notice in ssi_lws_smd + * above, we tell this link to use a class filter that excludes + * NETWORK messages. + */ + + if (lws_ss_create(*pctx, 0, &ssi_lws_smd, NULL, NULL, NULL, NULL)) { + lwsl_err("%s: failed to create secure stream\n", + __func__); + + return -1; + } + } + + return 0; +} + + +static void +sul_timeout_cb(lws_sorted_usec_list_t *sul) +{ + interrupted = 1; +} + + +static void +sigint_handler(int sig) +{ + interrupted = 1; +} + +int main(int argc, const char **argv) +{ + struct lws_context_creation_info info; + struct lws_context *context; + + signal(SIGINT, sigint_handler); + + memset(&info, 0, sizeof info); + lws_cmdline_option_handle_builtin(argc, argv, &info); + + lwsl_user("LWS Secure Streams SMD test client [-d]\n"); + + info.fd_limit_per_thread = 1 + 6 + 1; + info.port = CONTEXT_PORT_NO_LISTEN; +#if !defined(LWS_SS_USE_SSPC) + info.pss_policies_json = default_ss_policy; +#else + info.protocols = lws_sspc_protocols; +#endif + info.options = LWS_SERVER_OPTION_EXPLICIT_VHOSTS | + LWS_SERVER_OPTION_DO_SSL_GLOBAL_INIT; + + info.early_smd_cb = direct_smd_cb; + info.early_smd_class_filter = 0xffffffff; + info.early_smd_opaque = &context; + + /* create the context */ + + context = lws_create_context(&info); + if (!context) { + lwsl_err("lws init failed\n"); + return 1; + } + +#if defined(LWS_SS_USE_SSPC) + if (!lws_create_vhost(context, &info)) { + lwsl_err("%s: failed to create default vhost\n", __func__); + goto bail; + } +#endif + + /* set up the test timeout */ + + lws_sul_schedule(context, 0, &sul_timeout, sul_timeout_cb, + 4 * LWS_US_PER_SEC); + + /* the event loop */ + + while (lws_service(context, 0) >= 0 && !interrupted) + ; + + /* compare what happened with what we expect */ + +#if defined(LWS_SS_USE_SSPC) + /* if SSPC + * + * - the SS _lws_smd link does not enable INTERACTION class, so doesn't + * see these messages (count_p1 is half count_tx) + * + * - the direct smd participant sees local state, but it doesn't send + * any local CPD request, since as a client it doesn't do CPD + * directly (count_p2 -= 1 compared to non-SSPC) + * + * - one CPD trigger is sent on the proxied SS link (countp1 += 1) + */ + if (count_p1 >= 6 && count_p2 >= 11 && count_tx >= 12) +#else + /* if not SSPC, then we can see direct smd activity */ + if (count_p1 >= 2 && count_p2 >= 15 && count_tx >= 5) +#endif + bad = 0; + + lwsl_notice("%d %d %d\n", count_p1, count_p2, count_tx); + +#if defined(LWS_SS_USE_SSPC) +bail: +#endif + lws_context_destroy(context); + + lwsl_user("Completed: %s\n", bad ? "failed" : "OK"); + + return bad; +} diff -Nru libwebsockets-3.2.1/minimal-examples/secure-streams/minimal-secure-streams-smd/README.md libwebsockets-4.1.6/minimal-examples/secure-streams/minimal-secure-streams-smd/README.md --- libwebsockets-3.2.1/minimal-examples/secure-streams/minimal-secure-streams-smd/README.md 1970-01-01 00:00:00.000000000 +0000 +++ libwebsockets-4.1.6/minimal-examples/secure-streams/minimal-secure-streams-smd/README.md 2020-12-01 17:40:26.000000000 +0000 @@ -0,0 +1,126 @@ +# lws minimal secure streams SMD + +This application creates a Secure Stream link to LWS SMD, System +Message Distribution. + +The SS is able to receive system messages matching a specified +class filter, and issue system messages also using SS payload +semantics. + +Both a direct api lws_smd participant and an SS based one are instantiated. +They both filter on system messages. + +When the Secure Stream is created, it asks to send using normal the SS api. +In the SS tx callback, it prepares a header and then send a NETWORK class +message. + +Numbers of messages received each way and sent is compared after 2s and the +test exits with a success or a fail. + +### Building and testing + +Build with + + -DLWS_WITH_SECURE_STREAMS=1 + -DLWS_WITH_SECURE_STREAMS_PROXY_API=1 + -DLWS_WITH_MINIMAL_EXAMPLES=1 + +The run ./bin/lws-minimal-secure-streams-smd alone (local SS and direct SMD tests) +and after run ./bin/lws-minimal-secure-streams-proxy in one console and +./bin-lws-minimal-secure-streams-smd-client in the other (SS proxy tests) + +### What's going on in the -client test + +The -client build version contains the test logic as usual, but outsources the +policy and smd_ server part to the Secure Streams Proxy. + + - start lws-minimal-secure-streams-proxy first + + - start lws-minimal-secure-streams-smd-client + +1) When the client starts, we waits to hear the client state is OPERATIONAL in +a direct smd participant callback. When it is, he creates a Secure Stream of +streamtype "_lws_smd", creating a local SS handle. + +2) The SS creation request is proxied to the SS proxy process over Unix Domain +Sockets. There it creates a Secure Stream object proxyside, and registers as +an SMD participant... this smd-related behaviour is tied to the special +streamtype name "_lws_smd". The SMD registration uses a class mask passed to +the proxy in the tx credit field of the serialization. + +3) SMD messages that pass the class mask filter are proxied back to the client +over the connection. + +4) SMD messages created at the client are passed to the proxy and added to the +proxy's SMD queue, if the same connection's class mask accepts the message then +it will be proxied back to the client same as other messages. + +The minimal example produces a variety of messages on the SS link, including +CPD detect trigger. The SS link is set up to only accept messages of classes +LWSSMDCL_SYSTEM_STATE and LWSSMDCL_NETWORK, INTERACTION type messages are +not accepted. + +## build + +``` + $ cmake . && make +``` + +## usage + +Commandline option|Meaning +---|--- +-d |Debug verbosity in decimal, eg, -d15 + +``` +$ ./bin/lws-minimal-secure-streams-smd -d 1151 +[2020/06/18 21:44:54:5148] U: LWS Secure Streams SMD test client [-d] +[2020/06/18 21:44:54:5601] I: Initial logging level 1151 +[2020/06/18 21:44:54:5605] I: Libwebsockets version: 4.0.99-v4.0.0-174-ga8a2eb954 v4.0.0-174-ga8a2eb954 +[2020/06/18 21:44:54:5607] I: IPV6 not compiled in +... +[2020/06/18 21:44:54:7906] D: _lws_state_transition: system: changed 11 'AUTH2' -> 12 'OPERATIONAL' +[2020/06/18 21:44:54:7906] D: _realloc: size 81: lws_smd_msg_alloc +[2020/06/18 21:44:54:7907] I: lws_cancel_service +[2020/06/18 21:44:54:7912] I: lws_state_transition_steps: CONTEXT_CREATED -> OPERATIONAL +[2020/06/18 21:44:54:7919] N: myss_tx: sending SS smd +[2020/06/18 21:44:54:7940] D: _realloc: size 84: lws_smd_msg_alloc +[2020/06/18 21:44:54:7944] I: lws_cancel_service +[2020/06/18 21:44:54:7966] D: direct_smd_cb: class: 0x2, ts: 3139600721554 +[2020/06/18 21:44:54:7972] D: +[2020/06/18 21:44:54:7990] D: 0000: 7B 22 73 74 61 74 65 22 3A 22 49 4E 49 54 49 41 {"state":"INITIA +[2020/06/18 21:44:54:7998] D: 0010: 4C 49 5A 45 44 22 7D LIZED"} +[2020/06/18 21:44:54:8001] D: +[2020/06/18 21:44:54:8016] I: myss_rx: len 39, flags: 3 +[2020/06/18 21:44:54:8018] I: +[2020/06/18 21:44:54:8021] I: 0000: 00 00 00 00 00 00 00 02 00 00 02 DA FE C9 26 92 ..............&. +[2020/06/18 21:44:54:8022] I: 0010: 7B 22 73 74 61 74 65 22 3A 22 49 4E 49 54 49 41 {"state":"INITIA +[2020/06/18 21:44:54:8023] I: 0020: 4C 49 5A 45 44 22 7D LIZED"} +[2020/06/18 21:44:54:8023] I: +[2020/06/18 21:44:54:8029] D: direct_smd_cb: class: 0x2, ts: 3139600724243 +[2020/06/18 21:44:54:8029] D: +[2020/06/18 21:44:54:8030] D: 0000: 7B 22 73 74 61 74 65 22 3A 22 49 46 41 43 45 5F {"state":"IFACE_ +[2020/06/18 21:44:54:8031] D: 0010: 43 4F 4C 44 50 4C 55 47 22 7D COLDPLUG"} +[2020/06/18 21:44:54:8032] D: +... +[2020/06/18 21:44:54:8112] D: direct_smd_cb: class: 0x4, ts: 3139600732952 +[2020/06/18 21:44:54:8112] D: +[2020/06/18 21:44:54:8114] D: 0000: 7B 22 73 6F 6D 74 68 69 6E 67 22 3A 22 6E 6F 74 {"somthing":"not +[2020/06/18 21:44:54:8115] D: 0010: 73 65 65 6E 62 79 73 73 72 78 22 7D seenbyssrx"} +[2020/06/18 21:44:54:8115] D: +[2020/06/18 21:44:57:5823] I: 11 12 1 +[2020/06/18 21:44:57:5838] I: lws_context_destroy: ctx 0x4f61db0 +[2020/06/18 21:44:57:5849] D: _lws_state_transition: system: changed 12 'OPERATIONAL' -> 13 'POLICY_INVALID' +[2020/06/18 21:44:57:5851] D: _realloc: size 84: lws_smd_msg_alloc +[2020/06/18 21:44:57:5853] I: lws_cancel_service +[2020/06/18 21:44:57:5871] I: lws_destroy_event_pipe +[2020/06/18 21:44:57:5906] I: lws_pt_destroy: pt destroyed +[2020/06/18 21:44:57:5913] I: lws_context_destroy2: ctx 0x4f61db0 +[2020/06/18 21:44:57:5936] D: lwsac_free: head (nil) +[2020/06/18 21:44:57:5947] D: 0x455970: post vh listl +[2020/06/18 21:44:57:5950] D: 0x455970: post pdl +[2020/06/18 21:44:57:5961] D: 0x455970: baggage +[2020/06/18 21:44:57:5968] D: 0x455970: post dc2 +[2020/06/18 21:44:57:6010] D: lws_context_destroy3: ctx 0x4f61db0 freed +[2020/06/18 21:44:57:6014] U: Completed: OK +``` \ No newline at end of file diff -Nru libwebsockets-3.2.1/minimal-examples/secure-streams/minimal-secure-streams-staticpolicy/CMakeLists.txt libwebsockets-4.1.6/minimal-examples/secure-streams/minimal-secure-streams-staticpolicy/CMakeLists.txt --- libwebsockets-3.2.1/minimal-examples/secure-streams/minimal-secure-streams-staticpolicy/CMakeLists.txt 1970-01-01 00:00:00.000000000 +0000 +++ libwebsockets-4.1.6/minimal-examples/secure-streams/minimal-secure-streams-staticpolicy/CMakeLists.txt 2020-12-01 17:40:26.000000000 +0000 @@ -0,0 +1,26 @@ +project(lws-minimal-secure-streams-staticpolicy C) +cmake_minimum_required(VERSION 2.8) +find_package(libwebsockets CONFIG REQUIRED) +list(APPEND CMAKE_MODULE_PATH ${LWS_CMAKE_DIR}) +include(CheckCSourceCompiles) +include(LwsCheckRequirements) + +set(SAMP lws-minimal-secure-streams-staticpolicy) + +set(requirements 1) +require_lws_config(LWS_ROLE_H1 1 requirements) +require_lws_config(LWS_WITHOUT_CLIENT 0 requirements) +require_lws_config(LWS_WITH_SECURE_STREAMS 1 requirements) +require_lws_config(LWS_WITH_SECURE_STREAMS_STATIC_POLICY_ONLY 1 requirements) + +if (requirements) + add_executable(${SAMP} minimal-secure-streams.c) + + if (websockets_shared) + target_link_libraries(${SAMP} websockets_shared ${LIBWEBSOCKETS_DEP_LIBS}) + add_dependencies(${SAMP} websockets_shared) + else() + target_link_libraries(${SAMP} websockets ${LIBWEBSOCKETS_DEP_LIBS}) + endif() + +endif() diff -Nru libwebsockets-3.2.1/minimal-examples/secure-streams/minimal-secure-streams-staticpolicy/minimal-secure-streams.c libwebsockets-4.1.6/minimal-examples/secure-streams/minimal-secure-streams-staticpolicy/minimal-secure-streams.c --- libwebsockets-3.2.1/minimal-examples/secure-streams/minimal-secure-streams-staticpolicy/minimal-secure-streams.c 1970-01-01 00:00:00.000000000 +0000 +++ libwebsockets-4.1.6/minimal-examples/secure-streams/minimal-secure-streams-staticpolicy/minimal-secure-streams.c 2020-12-01 17:40:26.000000000 +0000 @@ -0,0 +1,291 @@ +/* + * lws-minimal-secure-streams + * + * Written in 2010-2020 by Andy Green + * + * This file is made available under the Creative Commons CC0 1.0 + * Universal Public Domain Dedication. + * + * + * This demonstrates a minimal http client using secure streams api. + * + * It visits https://warmcat.com/ and receives the html page there. + * + * This example is built two different ways from the same source... one includes + * the policy everything needed to fulfil the stream directly. The other -client + * variant has no policy itself and some other minor init changes, and connects + * to the -proxy example to actually get the connection done. + * + * In the -client build case, the example does not even init the tls libraries + * since the proxy part will take care of all that. + */ + +#include +#include +#include + +static int interrupted, bad = 1, force_cpd_fail_portal, + force_cpd_fail_no_internet; +static lws_state_notify_link_t nl; + +/* + * This is example builds with a static policy autogenerated from a JSON + * policy... + */ +#include "static-policy.h" + + +typedef struct myss { + struct lws_ss_handle *ss; + void *opaque_data; + /* ... application specific state ... */ + lws_sorted_usec_list_t sul; +} myss_t; + +static const char *canned_root_token_payload = + "grant_type=refresh_token" + "&refresh_token=Atzr|IwEBIJedGXjDqsU_vMxykqOMg" + "SHfYe3CPcedueWEMWSDMaDnEmiW8RlR1Kns7Cb4B-TOSnqp7ifVsY4BMY2B8tpHfO39XP" + "zfu9HapGjTR458IyHX44FE71pWJkGZ79uVBpljP4sazJuk8XS3Oe_yLnm_DIO6fU1nU3Y" + "0flYmsOiOAQE_gRk_pdlmEtHnpMA-9rLw3mkY5L89Ty9kUygBsiFaYatouROhbsTn8-jW" + "k1zZLUDpT6ICtBXSnrCIg0pUbZevPFhTwdXd6eX-u4rq0W-XaDvPWFO7au-iPb4Zk5eZE" + "iX6sissYrtNmuEXc2uHu7MnQO1hHCaTdIO2CANVumf-PHSD8xseamyh04sLV5JgFzY45S" + "KvKMajiUZuLkMokOx86rjC2Hdkx5DO7G-dbG1ufBDG-N79pFMSs7Ck5pc283IdLoJkCQc" + "AGvTX8o8I29QqkcGou-9TKhOJmpX8As94T61ok0UqqEKPJ7RhfQHHYdCtsdwxgvfVr9qI" + "xL_hDCcTho8opCVX-6QhJHl6SQFlTw13" + "&client_id=" + "amzn1.application-oa2-client.4823334c434b4190a2b5a42c07938a2d"; + +/* secure streams payload interface */ + +static int +myss_rx(void *userobj, const uint8_t *buf, size_t len, int flags) +{ +// myss_t *m = (myss_t *)userobj; + + lwsl_user("%s: len %d, flags: %d\n", __func__, (int)len, flags); + lwsl_hexdump_info(buf, len); + + /* + * If we received the whole message, for our example it means + * we are done. + */ + if (flags & LWSSS_FLAG_EOM) { + bad = 0; + interrupted = 1; + } + + return 0; +} + +static int +myss_tx(void *userobj, lws_ss_tx_ordinal_t ord, uint8_t *buf, size_t *len, + int *flags) +{ + //myss_t *m = (myss_t *)userobj; + + return 0; +} + +static int +myss_state(void *userobj, void *sh, lws_ss_constate_t state, + lws_ss_tx_ordinal_t ack) +{ + myss_t *m = (myss_t *)userobj; + + lwsl_user("%s: %s, ord 0x%x\n", __func__, lws_ss_state_name(state), + (unsigned int)ack); + + switch (state) { + case LWSSSCS_CREATING: + lws_ss_set_metadata(m->ss, "uptag", "myuptag123", 10); + lws_ss_set_metadata(m->ss, "ctype", "myctype", 7); + lws_ss_client_connect(m->ss); + break; + case LWSSSCS_ALL_RETRIES_FAILED: + /* if we're out of retries, we want to close the app and FAIL */ + interrupted = 1; + break; + case LWSSSCS_QOS_ACK_REMOTE: + lwsl_notice("%s: LWSSSCS_QOS_ACK_REMOTE\n", __func__); + break; + default: + break; + } + + return 0; +} + +static int +app_system_state_nf(lws_state_manager_t *mgr, lws_state_notify_link_t *link, + int current, int target) +{ + struct lws_context *context = lws_system_context_from_system_mgr(mgr); + lws_system_blob_t *ab = lws_system_get_blob(context, + LWS_SYSBLOB_TYPE_AUTH, 1 /* AUTH_IDX_ROOT */); + size_t size; + + /* + * For the things we care about, let's notice if we are trying to get + * past them when we haven't solved them yet, and make the system + * state wait while we trigger the dependent action. + */ + switch (target) { + + case LWS_SYSTATE_REGISTERED: + size = lws_system_blob_get_size(ab); + if (size) + break; + + /* let's register our canned root token so auth can use it */ + lws_system_blob_direct_set(ab, + (const uint8_t *)canned_root_token_payload, + strlen(canned_root_token_payload)); + break; + + case LWS_SYSTATE_OPERATIONAL: + if (current == LWS_SYSTATE_OPERATIONAL) { + lws_ss_info_t ssi; + + /* We're making an outgoing secure stream ourselves */ + + memset(&ssi, 0, sizeof(ssi)); + ssi.handle_offset = offsetof(myss_t, ss); + ssi.opaque_user_data_offset = offsetof(myss_t, + opaque_data); + ssi.rx = myss_rx; + ssi.tx = myss_tx; + ssi.state = myss_state; + ssi.user_alloc = sizeof(myss_t); + ssi.streamtype = "mintest"; + + if (lws_ss_create(context, 0, &ssi, NULL, NULL, + NULL, NULL)) { + lwsl_err("%s: failed to create secure stream\n", + __func__); + return -1; + } + } + break; + } + + return 0; +} + +static lws_state_notify_link_t * const app_notifier_list[] = { + &nl, NULL +}; + +static void +sigint_handler(int sig) +{ + interrupted = 1; +} + +int main(int argc, const char **argv) +{ + struct lws_context_creation_info info; + struct lws_context *context; + int n = 0; + + signal(SIGINT, sigint_handler); + + memset(&info, 0, sizeof info); + lws_cmdline_option_handle_builtin(argc, argv, &info); + + lwsl_user("LWS secure streams static policy test client [-d]\n"); + + /* these options are mutually exclusive if given */ + + if (lws_cmdline_option(argc, argv, "--force-portal")) + force_cpd_fail_portal = 1; + + if (lws_cmdline_option(argc, argv, "--force-no-internet")) + force_cpd_fail_no_internet = 1; + + info.fd_limit_per_thread = 1 + 6 + 1; + info.port = CONTEXT_PORT_NO_LISTEN; +#if defined(LWS_SS_USE_SSPC) + info.protocols = lws_sspc_protocols; + { + const char *p; + + /* connect to ssproxy via UDS by default, else via + * tcp connection to this port */ + if ((p = lws_cmdline_option(argc, argv, "-p"))) + info.ss_proxy_port = atoi(p); + + /* UDS "proxy.ss.lws" in abstract namespace, else this socket + * path; when -p given this can specify the network interface + * to bind to */ + if ((p = lws_cmdline_option(argc, argv, "-i"))) + info.ss_proxy_bind = p; + + /* if -p given, -a specifies the proxy address to connect to */ + if ((p = lws_cmdline_option(argc, argv, "-a"))) + info.ss_proxy_address = p; + } +#else + info.pss_policies = &_ss_static_policy_entry; + info.options = LWS_SERVER_OPTION_EXPLICIT_VHOSTS | + LWS_SERVER_OPTION_DO_SSL_GLOBAL_INIT; +#endif +#if defined(LWS_WITH_DETAILED_LATENCY) + info.detailed_latency_cb = lws_det_lat_plot_cb; + info.detailed_latency_filepath = "/tmp/lws-latency-ssproxy"; +#endif + + /* integrate us with lws system state management when context created */ + + nl.name = "app"; + nl.notify_cb = app_system_state_nf; + info.register_notifier_list = app_notifier_list; + + /* create the context */ + + context = lws_create_context(&info); + if (!context) { + lwsl_err("lws init failed\n"); + return 1; + } + + /* + * Set the related lws_system blobs + * + * ...direct_set() sets a pointer, so the thing pointed to has to have + * a suitable lifetime, eg, something that already exists on the heap or + * a const string in .rodata like this + */ + + lws_system_blob_direct_set(lws_system_get_blob(context, + LWS_SYSBLOB_TYPE_DEVICE_SERIAL, 0), + (const uint8_t *)"SN12345678", 10); + lws_system_blob_direct_set(lws_system_get_blob(context, + LWS_SYSBLOB_TYPE_DEVICE_FW_VERSION, 0), + (const uint8_t *)"v0.01", 5); + + /* + * ..._heap_append() appends to a buflist kind of arrangement on heap, + * just one block is fine, otherwise it will concatenate the fragments + * in the order they were appended (and take care of freeing them at + * context destroy time). ..._heap_empty() is also available to remove + * everything that was already allocated. + * + * Here we use _heap_append() just so it's tested as well as direct set. + */ + + lws_system_blob_heap_append(lws_system_get_blob(context, + LWS_SYSBLOB_TYPE_DEVICE_TYPE, 0), + (const uint8_t *)"spacerocket", 11); + + /* the event loop */ + + while (n >= 0 && !interrupted) + n = lws_service(context, 0); + + lws_context_destroy(context); + + lwsl_user("Completed: %s\n", bad ? "failed" : "OK"); + + return bad; +} diff -Nru libwebsockets-3.2.1/minimal-examples/secure-streams/minimal-secure-streams-staticpolicy/README.md libwebsockets-4.1.6/minimal-examples/secure-streams/minimal-secure-streams-staticpolicy/README.md --- libwebsockets-3.2.1/minimal-examples/secure-streams/minimal-secure-streams-staticpolicy/README.md 1970-01-01 00:00:00.000000000 +0000 +++ libwebsockets-4.1.6/minimal-examples/secure-streams/minimal-secure-streams-staticpolicy/README.md 2020-12-01 17:40:26.000000000 +0000 @@ -0,0 +1,61 @@ +# lws minimal secure streams static policy + +The application goes to https://warmcat.com and reads index.html there. + +It does it using a static Secure Streams policy generated from JSON by +policy2c example. + +## build + +``` + $ cmake . && make +``` + +## usage + +Commandline option|Meaning +---|--- +-d |Debug verbosity in decimal, eg, -d15 + +``` +$ ./lws-minimal-secure-streams-staticpolicy +[2020/03/26 15:49:12:6640] U: LWS secure streams static policy test client [-d] +[2020/03/26 15:49:12:7067] N: lws_create_context: using ss proxy bind '(null)', port 0, ads '(null)' +[2020/03/26 15:49:12:7567] N: lws_tls_client_create_vhost_context: using mem client CA cert 914 +[2020/03/26 15:49:12:7597] N: lws_tls_client_create_vhost_context: using mem client CA cert 1011 +[2020/03/26 15:49:12:7603] N: lws_tls_client_create_vhost_context: using mem client CA cert 1425 +[2020/03/26 15:49:12:7605] N: lws_tls_client_create_vhost_context: using mem client CA cert 1011 +[2020/03/26 15:49:12:9713] N: lws_system_cpd_set: setting CPD result OK +[2020/03/26 15:49:13:9625] N: ss_api_amazon_auth_rx: acquired 588-byte api.amazon.com auth token, exp 3600s +[2020/03/26 15:49:13:9747] U: myss_state: LWSSSCS_CREATING, ord 0x0 +[2020/03/26 15:49:13:9774] U: myss_state: LWSSSCS_CONNECTING, ord 0x0 +[2020/03/26 15:49:14:1897] U: myss_state: LWSSSCS_CONNECTED, ord 0x0 +[2020/03/26 15:49:14:1926] U: myss_rx: len 1520, flags: 1 +[2020/03/26 15:49:14:1945] U: myss_rx: len 1520, flags: 0 +[2020/03/26 15:49:14:1946] U: myss_rx: len 1520, flags: 0 +[2020/03/26 15:49:14:1947] U: myss_rx: len 1520, flags: 0 +[2020/03/26 15:49:14:1948] U: myss_rx: len 1520, flags: 0 +[2020/03/26 15:49:14:1949] U: myss_rx: len 583, flags: 0 +[2020/03/26 15:49:14:2087] U: myss_rx: len 1520, flags: 0 +[2020/03/26 15:49:14:2089] U: myss_rx: len 1520, flags: 0 +[2020/03/26 15:49:14:2090] U: myss_rx: len 1520, flags: 0 +[2020/03/26 15:49:14:2091] U: myss_rx: len 1520, flags: 0 +[2020/03/26 15:49:14:2092] U: myss_rx: len 1520, flags: 0 +[2020/03/26 15:49:14:2093] U: myss_rx: len 583, flags: 0 +[2020/03/26 15:49:14:2109] U: myss_rx: len 1520, flags: 0 +[2020/03/26 15:49:14:2110] U: myss_rx: len 1520, flags: 0 +[2020/03/26 15:49:14:2111] U: myss_rx: len 1520, flags: 0 +[2020/03/26 15:49:14:2112] U: myss_rx: len 1520, flags: 0 +[2020/03/26 15:49:14:2113] U: myss_rx: len 1520, flags: 0 +[2020/03/26 15:49:14:2114] U: myss_rx: len 583, flags: 0 +[2020/03/26 15:49:14:2135] U: myss_rx: len 1520, flags: 0 +[2020/03/26 15:49:14:2136] U: myss_rx: len 1358, flags: 0 +[2020/03/26 15:49:14:2136] U: myss_rx: len 0, flags: 2 +[2020/03/26 15:49:14:2138] U: myss_state: LWSSSCS_QOS_ACK_REMOTE, ord 0x0 +[2020/03/26 15:49:14:2139] N: myss_state: LWSSSCS_QOS_ACK_REMOTE +[2020/03/26 15:49:14:2170] U: myss_state: LWSSSCS_DISCONNECTED, ord 0x0 +[2020/03/26 15:49:14:2192] U: myss_state: LWSSSCS_DESTROYING, ord 0x0 +[2020/03/26 15:49:14:2265] E: lws_context_destroy3 +[2020/03/26 15:49:14:2282] U: Completed: OK + +``` diff -Nru libwebsockets-3.2.1/minimal-examples/secure-streams/minimal-secure-streams-staticpolicy/static-policy.h libwebsockets-4.1.6/minimal-examples/secure-streams/minimal-secure-streams-staticpolicy/static-policy.h --- libwebsockets-3.2.1/minimal-examples/secure-streams/minimal-secure-streams-staticpolicy/static-policy.h 1970-01-01 00:00:00.000000000 +0000 +++ libwebsockets-4.1.6/minimal-examples/secure-streams/minimal-secure-streams-staticpolicy/static-policy.h 2020-12-01 17:40:26.000000000 +0000 @@ -0,0 +1,1513 @@ +/* + * Autogenerated from the following JSON policy + */ + +#if 0 +{ + "release": "01234567", + "product": "myproduct", + "schema-version": 1, + "retry": [{ + "default": { + "backoff": [1000, 2000, 3000, 5000, 10000], + "conceal": 5, + "jitterpc": 20, + "svalidping": 30, + "svalidhup": 35 + } + }], + "certs": [{ + "isrg_root_x1": "MIIFazCCA1OgAwIBAgIRAIIQz7DSQONZRGPgu2OCiwAwDQYJKoZIhvcNAQELBQAwTzELMAkGA1UEBhMCVVMxKTAnBgNVBAoTIEludGVybmV0IFNlY3VyaXR5IFJlc2VhcmNoIEdyb3VwMRUwEwYDVQQDEwxJU1JHIFJvb3QgWDEwHhcNMTUwNjA0MTEwNDM4WhcNMzUwNjA0MTEwNDM4WjBPMQswCQYDVQQGEwJVUzEpMCcGA1UEChMgSW50ZXJuZXQgU2VjdXJpdHkgUmVzZWFyY2ggR3JvdXAxFTATBgNVBAMTDElTUkcgUm9vdC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1UEBhMCVVMxJTAjBgNVBAoTHFN0YXJmaWVsZCBUZWNobm9sb2dpZXMsIEluYy4xMjAwBgNVBAsTKVN0YXJmaWVsZCBDbGFzcyAyIENlcnRpZmljYXRpb24gQXV0aG9yaXR5ggEAMAwGA1UdEwQFMAMBAf8wDQYJKoZIhvcNAQEFBQADggEBAAWdP4id0ckaVaGsafPzWdqbAYcaT1epoXkJKtv3L7IezMdeatiDh6GX70k1PncGQVhiv45YuApnP+yz3SFmH8lU+nLMPUxA2IGvd56Deruix/U0F47ZEUD0/CwqTRV/p2JdLiXTAAsgGh1o+Re49L2L7ShZ3U0WixeDyLJlxy16paq8U4Zt3VekyvggQQto8PT7dL5WXXp59fkdheMtlb71cZBDzI0fmgAKhynpVSJYACPq4xJDKVtHCN2MQWplBqjlIapBtJUhlbl90TSrE9atvNziPTnNvT51cKEYWQPJIrSPnNVeKtelttQKbfi3QBFGmh95DmK/D5fs4C8fF5Q=" + }], + "trust_stores": [{ + "name": "le_via_isrg", + "stack": ["isrg_root_x1", "LEX3_isrg_root_x1"] + }, { + "name": "api_amazon_com", + "stack": ["digicert_global_ca_g2", "digicert_global_root_g2"] + }, { + "name": "avs_via_starfield", + "stack": ["starfield_class_2_ca", "starfield_services_root_ca"] + }, { + "name": "mqtt_amz_iot", + "stack": ["amazon_root_ca_1", "starfield_class_2_ca", "starfield_services_root_ca"] + }], + "s": [{ + "api_amazon_com_auth": { + "endpoint": "api.amazon.com", + "port": 443, + "protocol": "h1", + "http_method": "POST", + "http_url": "auth/o2/token", + "plugins": [], + "opportunistic": true, + "tls": true, + "h2q_oflow_txcr": true, + "http_www_form_urlencoded": true, + "http_no_content_length": true, + "retry": "default", + "tls_trust_store": "api_amazon_com" + } + }, { + "avs_event": { + "endpoint": "alexa.na.gateway.devices.a2z.com", + "port": 443, + "protocol": "h2", + "http_method": "GET", + "http_url": "v20160207/directives", + "h2q_oflow_txcr": true, + "http_auth_header": "authorization:", + "http_auth_preamble": "Bearer ", + "http_no_content_length": true, + "nailed_up": true, + "long_poll": true, + "retry": "default", + "plugins": [], + "tls": true, + "tls_trust_store": "avs_via_starfield" + } + }, { + "avs_metadata": { + "endpoint": "alexa.na.gateway.devices.a2z.com", + "port": 443, + "protocol": "h2", + "http_method": "POST", + "http_url": "v20160207/events", + "opportunistic": true, + "h2q_oflow_txcr": true, + "http_auth_header": "authorization:", + "http_auth_preamble": "Bearer ", + "http_multipart_name": "metadata", + "http_mime_content_type": "application/json; charset=UTF-8", + "http_no_content_length": true, + "rideshare": "avs_audio", + "retry": "default", + "plugins": [], + "tls": true, + "tls_trust_store": "avs_via_starfield" + } + }, { + "avs_audio": { + "endpoint": "alexa.na.gateway.devices.a2z.com", + "port": 443, + "protocol": "h2", + "http_method": "POST", + "http_url": "v20160207/events", + "plugins": [], + "tls": true, + "h2q_oflow_txcr": true, + "http_auth_header": "authorization:", + "http_auth_preamble": "Bearer ", + "http_multipart_name": "audio", + "http_mime_content_type": "application/octet-stream", + "http_no_content_length": true, + "retry": "default", + "tls_trust_store": "avs_via_starfield" + } + }, { + "mintest": { + "endpoint": "warmcat.com", + "port": 443, + "protocol": "h1", + "http_method": "GET", + "http_url": "index.html?uptag=${uptag}", + "http_dsn_header": "x-dsn:", + "http_fwv_header": "x-fw-version:", + "http_devtype_header": "x-devtype:", + "metadata": [{ + "uptag": "X-Upload-Tag:" + }, { + "ctype": "Content-Type:" + }, { + "xctype": "X-Content-Type:" + }], + "plugins": [], + "tls": true, + "opportunistic": true, + "retry": "default", + "tls_trust_store": "le_via_isrg" + } + }, { + "h2longpolltest": { + "endpoint": "warmcat.com", + "port": 443, + "protocol": "h2", + "http_method": "GET", + "http_url": "index.html", + "plugins": [], + "tls": true, + "nailed_up": true, + "long_poll": true, + "retry": "default", + "tls_trust_store": "le_via_isrg" + } + }, { + "mintest-fail": { + "endpoint": "warmcat.com", + "port": 22, + "protocol": "h1", + "http_method": "GET", + "http_url": "index.html", + "plugins": [], + "tls": true, + "opportunistic": true, + "retry": "default", + "tls_trust_store": "le_via_isrg" + } + }, { + "minpost": { + "endpoint": "warmcat.com", + "port": 443, + "protocol": "h1", + "http_method": "POST", + "http_url": "testserver/formtest", + "plugins": [], + "tls": true, + "opportunistic": true, + "retry": "default", + "tls_trust_store": "le_via_isrg" + } + }, { + "mqtt_test": { + "endpoint": "a1ygonr3im5cv2-ats.iot.us-west-2.amazonaws.com", + "port": 443, + "tls": true, + "client_cert": 0, + "tls_trust_store": "mqtt_amz_iot", + "protocol": "mqtt", + "mqtt_topic": "test/topic0", + "mqtt_subscribe": "test/topic0", + "mqtt_qos": 0, + "retry": "default" + } + }, { + "mqtt_test1": { + "endpoint": "a1ygonr3im5cv2-ats.iot.us-west-2.amazonaws.com", + "port": 443, + "tls": true, + "client_cert": 0, + "tls_trust_store": "mqtt_amz_iot", + "protocol": "mqtt", + "mqtt_topic": "test/topic1", + "mqtt_subscribe": "test/topic1", + "mqtt_qos": 1, + "retry": "default" + } + }, { + "captive_portal_detect": { + "endpoint": "connectivitycheck.android.com", + "port": 80, + "protocol": "h1", + "http_method": "GET", + "http_url": "generate_204", + "opportunistic": true, + "http_expect": 204, + "http_fail_redirect": true + } + } + ] +} + + + + + Original JSON size: 15493 +#endif + +static const uint32_t _rbo_bo_0[] = { + 1000, 2000, 3000, 5000, 10000, +}; +static const lws_retry_bo_t _rbo_0 = { + .retry_ms_table = _rbo_bo_0, + .retry_ms_table_count = 5, + .conceal_count = 5, + .secs_since_valid_ping = 30, + .secs_since_valid_hangup = 35, + .jitter_percent = 20, +}; +static const uint8_t _ss_der_amazon_root_ca_1[] = { + /* 0x 0 */ 0x30, 0x82, 0x03, 0x41, 0x30, 0x82, 0x02, 0x29, + /* 0x 8 */ 0xA0, 0x03, 0x02, 0x01, 0x02, 0x02, 0x13, 0x06, + /* 0x 10 */ 0x6C, 0x9F, 0xCF, 0x99, 0xBF, 0x8C, 0x0A, 0x39, + /* 0x 18 */ 0xE2, 0xF0, 0x78, 0x8A, 0x43, 0xE6, 0x96, 0x36, + /* 0x 20 */ 0x5B, 0xCA, 0x30, 0x0D, 0x06, 0x09, 0x2A, 0x86, + /* 0x 28 */ 0x48, 0x86, 0xF7, 0x0D, 0x01, 0x01, 0x0B, 0x05, + /* 0x 30 */ 0x00, 0x30, 0x39, 0x31, 0x0B, 0x30, 0x09, 0x06, + /* 0x 38 */ 0x03, 0x55, 0x04, 0x06, 0x13, 0x02, 0x55, 0x53, + /* 0x 40 */ 0x31, 0x0F, 0x30, 0x0D, 0x06, 0x03, 0x55, 0x04, + /* 0x 48 */ 0x0A, 0x13, 0x06, 0x41, 0x6D, 0x61, 0x7A, 0x6F, + /* 0x 50 */ 0x6E, 0x31, 0x19, 0x30, 0x17, 0x06, 0x03, 0x55, + /* 0x 58 */ 0x04, 0x03, 0x13, 0x10, 0x41, 0x6D, 0x61, 0x7A, + /* 0x 60 */ 0x6F, 0x6E, 0x20, 0x52, 0x6F, 0x6F, 0x74, 0x20, + /* 0x 68 */ 0x43, 0x41, 0x20, 0x31, 0x30, 0x1E, 0x17, 0x0D, + /* 0x 70 */ 0x31, 0x35, 0x30, 0x35, 0x32, 0x36, 0x30, 0x30, + /* 0x 78 */ 0x30, 0x30, 0x30, 0x30, 0x5A, 0x17, 0x0D, 0x33, + /* 0x 80 */ 0x38, 0x30, 0x31, 0x31, 0x37, 0x30, 0x30, 0x30, + /* 0x 88 */ 0x30, 0x30, 0x30, 0x5A, 0x30, 0x39, 0x31, 0x0B, + /* 0x 90 */ 0x30, 0x09, 0x06, 0x03, 0x55, 0x04, 0x06, 0x13, + /* 0x 98 */ 0x02, 0x55, 0x53, 0x31, 0x0F, 0x30, 0x0D, 0x06, + /* 0x a0 */ 0x03, 0x55, 0x04, 0x0A, 0x13, 0x06, 0x41, 0x6D, + /* 0x a8 */ 0x61, 0x7A, 0x6F, 0x6E, 0x31, 0x19, 0x30, 0x17, + /* 0x b0 */ 0x06, 0x03, 0x55, 0x04, 0x03, 0x13, 0x10, 0x41, + /* 0x b8 */ 0x6D, 0x61, 0x7A, 0x6F, 0x6E, 0x20, 0x52, 0x6F, + /* 0x c0 */ 0x6F, 0x74, 0x20, 0x43, 0x41, 0x20, 0x31, 0x30, + /* 0x c8 */ 0x82, 0x01, 0x22, 0x30, 0x0D, 0x06, 0x09, 0x2A, + /* 0x d0 */ 0x86, 0x48, 0x86, 0xF7, 0x0D, 0x01, 0x01, 0x01, + /* 0x d8 */ 0x05, 0x00, 0x03, 0x82, 0x01, 0x0F, 0x00, 0x30, + /* 0x e0 */ 0x82, 0x01, 0x0A, 0x02, 0x82, 0x01, 0x01, 0x00, + /* 0x e8 */ 0xB2, 0x78, 0x80, 0x71, 0xCA, 0x78, 0xD5, 0xE3, + /* 0x f0 */ 0x71, 0xAF, 0x47, 0x80, 0x50, 0x74, 0x7D, 0x6E, + /* 0x f8 */ 0xD8, 0xD7, 0x88, 0x76, 0xF4, 0x99, 0x68, 0xF7, + /* 0x100 */ 0x58, 0x21, 0x60, 0xF9, 0x74, 0x84, 0x01, 0x2F, + /* 0x108 */ 0xAC, 0x02, 0x2D, 0x86, 0xD3, 0xA0, 0x43, 0x7A, + /* 0x110 */ 0x4E, 0xB2, 0xA4, 0xD0, 0x36, 0xBA, 0x01, 0xBE, + /* 0x118 */ 0x8D, 0xDB, 0x48, 0xC8, 0x07, 0x17, 0x36, 0x4C, + /* 0x120 */ 0xF4, 0xEE, 0x88, 0x23, 0xC7, 0x3E, 0xEB, 0x37, + /* 0x128 */ 0xF5, 0xB5, 0x19, 0xF8, 0x49, 0x68, 0xB0, 0xDE, + /* 0x130 */ 0xD7, 0xB9, 0x76, 0x38, 0x1D, 0x61, 0x9E, 0xA4, + /* 0x138 */ 0xFE, 0x82, 0x36, 0xA5, 0xE5, 0x4A, 0x56, 0xE4, + /* 0x140 */ 0x45, 0xE1, 0xF9, 0xFD, 0xB4, 0x16, 0xFA, 0x74, + /* 0x148 */ 0xDA, 0x9C, 0x9B, 0x35, 0x39, 0x2F, 0xFA, 0xB0, + /* 0x150 */ 0x20, 0x50, 0x06, 0x6C, 0x7A, 0xD0, 0x80, 0xB2, + /* 0x158 */ 0xA6, 0xF9, 0xAF, 0xEC, 0x47, 0x19, 0x8F, 0x50, + /* 0x160 */ 0x38, 0x07, 0xDC, 0xA2, 0x87, 0x39, 0x58, 0xF8, + /* 0x168 */ 0xBA, 0xD5, 0xA9, 0xF9, 0x48, 0x67, 0x30, 0x96, + /* 0x170 */ 0xEE, 0x94, 0x78, 0x5E, 0x6F, 0x89, 0xA3, 0x51, + /* 0x178 */ 0xC0, 0x30, 0x86, 0x66, 0xA1, 0x45, 0x66, 0xBA, + /* 0x180 */ 0x54, 0xEB, 0xA3, 0xC3, 0x91, 0xF9, 0x48, 0xDC, + /* 0x188 */ 0xFF, 0xD1, 0xE8, 0x30, 0x2D, 0x7D, 0x2D, 0x74, + /* 0x190 */ 0x70, 0x35, 0xD7, 0x88, 0x24, 0xF7, 0x9E, 0xC4, + /* 0x198 */ 0x59, 0x6E, 0xBB, 0x73, 0x87, 0x17, 0xF2, 0x32, + /* 0x1a0 */ 0x46, 0x28, 0xB8, 0x43, 0xFA, 0xB7, 0x1D, 0xAA, + /* 0x1a8 */ 0xCA, 0xB4, 0xF2, 0x9F, 0x24, 0x0E, 0x2D, 0x4B, + /* 0x1b0 */ 0xF7, 0x71, 0x5C, 0x5E, 0x69, 0xFF, 0xEA, 0x95, + /* 0x1b8 */ 0x02, 0xCB, 0x38, 0x8A, 0xAE, 0x50, 0x38, 0x6F, + /* 0x1c0 */ 0xDB, 0xFB, 0x2D, 0x62, 0x1B, 0xC5, 0xC7, 0x1E, + /* 0x1c8 */ 0x54, 0xE1, 0x77, 0xE0, 0x67, 0xC8, 0x0F, 0x9C, + /* 0x1d0 */ 0x87, 0x23, 0xD6, 0x3F, 0x40, 0x20, 0x7F, 0x20, + /* 0x1d8 */ 0x80, 0xC4, 0x80, 0x4C, 0x3E, 0x3B, 0x24, 0x26, + /* 0x1e0 */ 0x8E, 0x04, 0xAE, 0x6C, 0x9A, 0xC8, 0xAA, 0x0D, + /* 0x1e8 */ 0x02, 0x03, 0x01, 0x00, 0x01, 0xA3, 0x42, 0x30, + /* 0x1f0 */ 0x40, 0x30, 0x0F, 0x06, 0x03, 0x55, 0x1D, 0x13, + /* 0x1f8 */ 0x01, 0x01, 0xFF, 0x04, 0x05, 0x30, 0x03, 0x01, + /* 0x200 */ 0x01, 0xFF, 0x30, 0x0E, 0x06, 0x03, 0x55, 0x1D, + /* 0x208 */ 0x0F, 0x01, 0x01, 0xFF, 0x04, 0x04, 0x03, 0x02, + /* 0x210 */ 0x01, 0x86, 0x30, 0x1D, 0x06, 0x03, 0x55, 0x1D, + /* 0x218 */ 0x0E, 0x04, 0x16, 0x04, 0x14, 0x84, 0x18, 0xCC, + /* 0x220 */ 0x85, 0x34, 0xEC, 0xBC, 0x0C, 0x94, 0x94, 0x2E, + /* 0x228 */ 0x08, 0x59, 0x9C, 0xC7, 0xB2, 0x10, 0x4E, 0x0A, + /* 0x230 */ 0x08, 0x30, 0x0D, 0x06, 0x09, 0x2A, 0x86, 0x48, + /* 0x238 */ 0x86, 0xF7, 0x0D, 0x01, 0x01, 0x0B, 0x05, 0x00, + /* 0x240 */ 0x03, 0x82, 0x01, 0x01, 0x00, 0x98, 0xF2, 0x37, + /* 0x248 */ 0x5A, 0x41, 0x90, 0xA1, 0x1A, 0xC5, 0x76, 0x51, + /* 0x250 */ 0x28, 0x20, 0x36, 0x23, 0x0E, 0xAE, 0xE6, 0x28, + /* 0x258 */ 0xBB, 0xAA, 0xF8, 0x94, 0xAE, 0x48, 0xA4, 0x30, + /* 0x260 */ 0x7F, 0x1B, 0xFC, 0x24, 0x8D, 0x4B, 0xB4, 0xC8, + /* 0x268 */ 0xA1, 0x97, 0xF6, 0xB6, 0xF1, 0x7A, 0x70, 0xC8, + /* 0x270 */ 0x53, 0x93, 0xCC, 0x08, 0x28, 0xE3, 0x98, 0x25, + /* 0x278 */ 0xCF, 0x23, 0xA4, 0xF9, 0xDE, 0x21, 0xD3, 0x7C, + /* 0x280 */ 0x85, 0x09, 0xAD, 0x4E, 0x9A, 0x75, 0x3A, 0xC2, + /* 0x288 */ 0x0B, 0x6A, 0x89, 0x78, 0x76, 0x44, 0x47, 0x18, + /* 0x290 */ 0x65, 0x6C, 0x8D, 0x41, 0x8E, 0x3B, 0x7F, 0x9A, + /* 0x298 */ 0xCB, 0xF4, 0xB5, 0xA7, 0x50, 0xD7, 0x05, 0x2C, + /* 0x2a0 */ 0x37, 0xE8, 0x03, 0x4B, 0xAD, 0xE9, 0x61, 0xA0, + /* 0x2a8 */ 0x02, 0x6E, 0xF5, 0xF2, 0xF0, 0xC5, 0xB2, 0xED, + /* 0x2b0 */ 0x5B, 0xB7, 0xDC, 0xFA, 0x94, 0x5C, 0x77, 0x9E, + /* 0x2b8 */ 0x13, 0xA5, 0x7F, 0x52, 0xAD, 0x95, 0xF2, 0xF8, + /* 0x2c0 */ 0x93, 0x3B, 0xDE, 0x8B, 0x5C, 0x5B, 0xCA, 0x5A, + /* 0x2c8 */ 0x52, 0x5B, 0x60, 0xAF, 0x14, 0xF7, 0x4B, 0xEF, + /* 0x2d0 */ 0xA3, 0xFB, 0x9F, 0x40, 0x95, 0x6D, 0x31, 0x54, + /* 0x2d8 */ 0xFC, 0x42, 0xD3, 0xC7, 0x46, 0x1F, 0x23, 0xAD, + /* 0x2e0 */ 0xD9, 0x0F, 0x48, 0x70, 0x9A, 0xD9, 0x75, 0x78, + /* 0x2e8 */ 0x71, 0xD1, 0x72, 0x43, 0x34, 0x75, 0x6E, 0x57, + /* 0x2f0 */ 0x59, 0xC2, 0x02, 0x5C, 0x26, 0x60, 0x29, 0xCF, + /* 0x2f8 */ 0x23, 0x19, 0x16, 0x8E, 0x88, 0x43, 0xA5, 0xD4, + /* 0x300 */ 0xE4, 0xCB, 0x08, 0xFB, 0x23, 0x11, 0x43, 0xE8, + /* 0x308 */ 0x43, 0x29, 0x72, 0x62, 0xA1, 0xA9, 0x5D, 0x5E, + /* 0x310 */ 0x08, 0xD4, 0x90, 0xAE, 0xB8, 0xD8, 0xCE, 0x14, + /* 0x318 */ 0xC2, 0xD0, 0x55, 0xF2, 0x86, 0xF6, 0xC4, 0x93, + /* 0x320 */ 0x43, 0x77, 0x66, 0x61, 0xC0, 0xB9, 0xE8, 0x41, + /* 0x328 */ 0xD7, 0x97, 0x78, 0x60, 0x03, 0x6E, 0x4A, 0x72, + /* 0x330 */ 0xAE, 0xA5, 0xD1, 0x7D, 0xBA, 0x10, 0x9E, 0x86, + /* 0x338 */ 0x6C, 0x1B, 0x8A, 0xB9, 0x59, 0x33, 0xF8, 0xEB, + /* 0x340 */ 0xC4, 0x90, 0xBE, 0xF1, 0xB9, +}; +static const lws_ss_x509_t _ss_x509_amazon_root_ca_1 = { + .vhost_name = "amazon_root_ca_1", + .ca_der = _ss_der_amazon_root_ca_1, + .ca_der_len = 837, +}; +static const uint8_t _ss_der_starfield_class_2_ca[] = { + /* 0x 0 */ 0x30, 0x82, 0x04, 0x0F, 0x30, 0x82, 0x02, 0xF7, + /* 0x 8 */ 0xA0, 0x03, 0x02, 0x01, 0x02, 0x02, 0x01, 0x00, + /* 0x 10 */ 0x30, 0x0D, 0x06, 0x09, 0x2A, 0x86, 0x48, 0x86, + /* 0x 18 */ 0xF7, 0x0D, 0x01, 0x01, 0x05, 0x05, 0x00, 0x30, + /* 0x 20 */ 0x68, 0x31, 0x0B, 0x30, 0x09, 0x06, 0x03, 0x55, + /* 0x 28 */ 0x04, 0x06, 0x13, 0x02, 0x55, 0x53, 0x31, 0x25, + /* 0x 30 */ 0x30, 0x23, 0x06, 0x03, 0x55, 0x04, 0x0A, 0x13, + /* 0x 38 */ 0x1C, 0x53, 0x74, 0x61, 0x72, 0x66, 0x69, 0x65, + /* 0x 40 */ 0x6C, 0x64, 0x20, 0x54, 0x65, 0x63, 0x68, 0x6E, + /* 0x 48 */ 0x6F, 0x6C, 0x6F, 0x67, 0x69, 0x65, 0x73, 0x2C, + /* 0x 50 */ 0x20, 0x49, 0x6E, 0x63, 0x2E, 0x31, 0x32, 0x30, + /* 0x 58 */ 0x30, 0x06, 0x03, 0x55, 0x04, 0x0B, 0x13, 0x29, + /* 0x 60 */ 0x53, 0x74, 0x61, 0x72, 0x66, 0x69, 0x65, 0x6C, + /* 0x 68 */ 0x64, 0x20, 0x43, 0x6C, 0x61, 0x73, 0x73, 0x20, + /* 0x 70 */ 0x32, 0x20, 0x43, 0x65, 0x72, 0x74, 0x69, 0x66, + /* 0x 78 */ 0x69, 0x63, 0x61, 0x74, 0x69, 0x6F, 0x6E, 0x20, + /* 0x 80 */ 0x41, 0x75, 0x74, 0x68, 0x6F, 0x72, 0x69, 0x74, + /* 0x 88 */ 0x79, 0x30, 0x1E, 0x17, 0x0D, 0x30, 0x34, 0x30, + /* 0x 90 */ 0x36, 0x32, 0x39, 0x31, 0x37, 0x33, 0x39, 0x31, + /* 0x 98 */ 0x36, 0x5A, 0x17, 0x0D, 0x33, 0x34, 0x30, 0x36, + /* 0x a0 */ 0x32, 0x39, 0x31, 0x37, 0x33, 0x39, 0x31, 0x36, + /* 0x a8 */ 0x5A, 0x30, 0x68, 0x31, 0x0B, 0x30, 0x09, 0x06, + /* 0x b0 */ 0x03, 0x55, 0x04, 0x06, 0x13, 0x02, 0x55, 0x53, + /* 0x b8 */ 0x31, 0x25, 0x30, 0x23, 0x06, 0x03, 0x55, 0x04, + /* 0x c0 */ 0x0A, 0x13, 0x1C, 0x53, 0x74, 0x61, 0x72, 0x66, + /* 0x c8 */ 0x69, 0x65, 0x6C, 0x64, 0x20, 0x54, 0x65, 0x63, + /* 0x d0 */ 0x68, 0x6E, 0x6F, 0x6C, 0x6F, 0x67, 0x69, 0x65, + /* 0x d8 */ 0x73, 0x2C, 0x20, 0x49, 0x6E, 0x63, 0x2E, 0x31, + /* 0x e0 */ 0x32, 0x30, 0x30, 0x06, 0x03, 0x55, 0x04, 0x0B, + /* 0x e8 */ 0x13, 0x29, 0x53, 0x74, 0x61, 0x72, 0x66, 0x69, + /* 0x f0 */ 0x65, 0x6C, 0x64, 0x20, 0x43, 0x6C, 0x61, 0x73, + /* 0x f8 */ 0x73, 0x20, 0x32, 0x20, 0x43, 0x65, 0x72, 0x74, + /* 0x100 */ 0x69, 0x66, 0x69, 0x63, 0x61, 0x74, 0x69, 0x6F, + /* 0x108 */ 0x6E, 0x20, 0x41, 0x75, 0x74, 0x68, 0x6F, 0x72, + /* 0x110 */ 0x69, 0x74, 0x79, 0x30, 0x82, 0x01, 0x20, 0x30, + /* 0x118 */ 0x0D, 0x06, 0x09, 0x2A, 0x86, 0x48, 0x86, 0xF7, + /* 0x120 */ 0x0D, 0x01, 0x01, 0x01, 0x05, 0x00, 0x03, 0x82, + /* 0x128 */ 0x01, 0x0D, 0x00, 0x30, 0x82, 0x01, 0x08, 0x02, + /* 0x130 */ 0x82, 0x01, 0x01, 0x00, 0xB7, 0x32, 0xC8, 0xFE, + /* 0x138 */ 0xE9, 0x71, 0xA6, 0x04, 0x85, 0xAD, 0x0C, 0x11, + /* 0x140 */ 0x64, 0xDF, 0xCE, 0x4D, 0xEF, 0xC8, 0x03, 0x18, + /* 0x148 */ 0x87, 0x3F, 0xA1, 0xAB, 0xFB, 0x3C, 0xA6, 0x9F, + /* 0x150 */ 0xF0, 0xC3, 0xA1, 0xDA, 0xD4, 0xD8, 0x6E, 0x2B, + /* 0x158 */ 0x53, 0x90, 0xFB, 0x24, 0xA4, 0x3E, 0x84, 0xF0, + /* 0x160 */ 0x9E, 0xE8, 0x5F, 0xEC, 0xE5, 0x27, 0x44, 0xF5, + /* 0x168 */ 0x28, 0xA6, 0x3F, 0x7B, 0xDE, 0xE0, 0x2A, 0xF0, + /* 0x170 */ 0xC8, 0xAF, 0x53, 0x2F, 0x9E, 0xCA, 0x05, 0x01, + /* 0x178 */ 0x93, 0x1E, 0x8F, 0x66, 0x1C, 0x39, 0xA7, 0x4D, + /* 0x180 */ 0xFA, 0x5A, 0xB6, 0x73, 0x04, 0x25, 0x66, 0xEB, + /* 0x188 */ 0x77, 0x7F, 0xE7, 0x59, 0xC6, 0x4A, 0x99, 0x25, + /* 0x190 */ 0x14, 0x54, 0xEB, 0x26, 0xC7, 0xF3, 0x7F, 0x19, + /* 0x198 */ 0xD5, 0x30, 0x70, 0x8F, 0xAF, 0xB0, 0x46, 0x2A, + /* 0x1a0 */ 0xFF, 0xAD, 0xEB, 0x29, 0xED, 0xD7, 0x9F, 0xAA, + /* 0x1a8 */ 0x04, 0x87, 0xA3, 0xD4, 0xF9, 0x89, 0xA5, 0x34, + /* 0x1b0 */ 0x5F, 0xDB, 0x43, 0x91, 0x82, 0x36, 0xD9, 0x66, + /* 0x1b8 */ 0x3C, 0xB1, 0xB8, 0xB9, 0x82, 0xFD, 0x9C, 0x3A, + /* 0x1c0 */ 0x3E, 0x10, 0xC8, 0x3B, 0xEF, 0x06, 0x65, 0x66, + /* 0x1c8 */ 0x7A, 0x9B, 0x19, 0x18, 0x3D, 0xFF, 0x71, 0x51, + /* 0x1d0 */ 0x3C, 0x30, 0x2E, 0x5F, 0xBE, 0x3D, 0x77, 0x73, + /* 0x1d8 */ 0xB2, 0x5D, 0x06, 0x6C, 0xC3, 0x23, 0x56, 0x9A, + /* 0x1e0 */ 0x2B, 0x85, 0x26, 0x92, 0x1C, 0xA7, 0x02, 0xB3, + /* 0x1e8 */ 0xE4, 0x3F, 0x0D, 0xAF, 0x08, 0x79, 0x82, 0xB8, + /* 0x1f0 */ 0x36, 0x3D, 0xEA, 0x9C, 0xD3, 0x35, 0xB3, 0xBC, + /* 0x1f8 */ 0x69, 0xCA, 0xF5, 0xCC, 0x9D, 0xE8, 0xFD, 0x64, + /* 0x200 */ 0x8D, 0x17, 0x80, 0x33, 0x6E, 0x5E, 0x4A, 0x5D, + /* 0x208 */ 0x99, 0xC9, 0x1E, 0x87, 0xB4, 0x9D, 0x1A, 0xC0, + /* 0x210 */ 0xD5, 0x6E, 0x13, 0x35, 0x23, 0x5E, 0xDF, 0x9B, + /* 0x218 */ 0x5F, 0x3D, 0xEF, 0xD6, 0xF7, 0x76, 0xC2, 0xEA, + /* 0x220 */ 0x3E, 0xBB, 0x78, 0x0D, 0x1C, 0x42, 0x67, 0x6B, + /* 0x228 */ 0x04, 0xD8, 0xF8, 0xD6, 0xDA, 0x6F, 0x8B, 0xF2, + /* 0x230 */ 0x44, 0xA0, 0x01, 0xAB, 0x02, 0x01, 0x03, 0xA3, + /* 0x238 */ 0x81, 0xC5, 0x30, 0x81, 0xC2, 0x30, 0x1D, 0x06, + /* 0x240 */ 0x03, 0x55, 0x1D, 0x0E, 0x04, 0x16, 0x04, 0x14, + /* 0x248 */ 0xBF, 0x5F, 0xB7, 0xD1, 0xCE, 0xDD, 0x1F, 0x86, + /* 0x250 */ 0xF4, 0x5B, 0x55, 0xAC, 0xDC, 0xD7, 0x10, 0xC2, + /* 0x258 */ 0x0E, 0xA9, 0x88, 0xE7, 0x30, 0x81, 0x92, 0x06, + /* 0x260 */ 0x03, 0x55, 0x1D, 0x23, 0x04, 0x81, 0x8A, 0x30, + /* 0x268 */ 0x81, 0x87, 0x80, 0x14, 0xBF, 0x5F, 0xB7, 0xD1, + /* 0x270 */ 0xCE, 0xDD, 0x1F, 0x86, 0xF4, 0x5B, 0x55, 0xAC, + /* 0x278 */ 0xDC, 0xD7, 0x10, 0xC2, 0x0E, 0xA9, 0x88, 0xE7, + /* 0x280 */ 0xA1, 0x6C, 0xA4, 0x6A, 0x30, 0x68, 0x31, 0x0B, + /* 0x288 */ 0x30, 0x09, 0x06, 0x03, 0x55, 0x04, 0x06, 0x13, + /* 0x290 */ 0x02, 0x55, 0x53, 0x31, 0x25, 0x30, 0x23, 0x06, + /* 0x298 */ 0x03, 0x55, 0x04, 0x0A, 0x13, 0x1C, 0x53, 0x74, + /* 0x2a0 */ 0x61, 0x72, 0x66, 0x69, 0x65, 0x6C, 0x64, 0x20, + /* 0x2a8 */ 0x54, 0x65, 0x63, 0x68, 0x6E, 0x6F, 0x6C, 0x6F, + /* 0x2b0 */ 0x67, 0x69, 0x65, 0x73, 0x2C, 0x20, 0x49, 0x6E, + /* 0x2b8 */ 0x63, 0x2E, 0x31, 0x32, 0x30, 0x30, 0x06, 0x03, + /* 0x2c0 */ 0x55, 0x04, 0x0B, 0x13, 0x29, 0x53, 0x74, 0x61, + /* 0x2c8 */ 0x72, 0x66, 0x69, 0x65, 0x6C, 0x64, 0x20, 0x43, + /* 0x2d0 */ 0x6C, 0x61, 0x73, 0x73, 0x20, 0x32, 0x20, 0x43, + /* 0x2d8 */ 0x65, 0x72, 0x74, 0x69, 0x66, 0x69, 0x63, 0x61, + /* 0x2e0 */ 0x74, 0x69, 0x6F, 0x6E, 0x20, 0x41, 0x75, 0x74, + /* 0x2e8 */ 0x68, 0x6F, 0x72, 0x69, 0x74, 0x79, 0x82, 0x01, + /* 0x2f0 */ 0x00, 0x30, 0x0C, 0x06, 0x03, 0x55, 0x1D, 0x13, + /* 0x2f8 */ 0x04, 0x05, 0x30, 0x03, 0x01, 0x01, 0xFF, 0x30, + /* 0x300 */ 0x0D, 0x06, 0x09, 0x2A, 0x86, 0x48, 0x86, 0xF7, + /* 0x308 */ 0x0D, 0x01, 0x01, 0x05, 0x05, 0x00, 0x03, 0x82, + /* 0x310 */ 0x01, 0x01, 0x00, 0x05, 0x9D, 0x3F, 0x88, 0x9D, + /* 0x318 */ 0xD1, 0xC9, 0x1A, 0x55, 0xA1, 0xAC, 0x69, 0xF3, + /* 0x320 */ 0xF3, 0x59, 0xDA, 0x9B, 0x01, 0x87, 0x1A, 0x4F, + /* 0x328 */ 0x57, 0xA9, 0xA1, 0x79, 0x09, 0x2A, 0xDB, 0xF7, + /* 0x330 */ 0x2F, 0xB2, 0x1E, 0xCC, 0xC7, 0x5E, 0x6A, 0xD8, + /* 0x338 */ 0x83, 0x87, 0xA1, 0x97, 0xEF, 0x49, 0x35, 0x3E, + /* 0x340 */ 0x77, 0x06, 0x41, 0x58, 0x62, 0xBF, 0x8E, 0x58, + /* 0x348 */ 0xB8, 0x0A, 0x67, 0x3F, 0xEC, 0xB3, 0xDD, 0x21, + /* 0x350 */ 0x66, 0x1F, 0xC9, 0x54, 0xFA, 0x72, 0xCC, 0x3D, + /* 0x358 */ 0x4C, 0x40, 0xD8, 0x81, 0xAF, 0x77, 0x9E, 0x83, + /* 0x360 */ 0x7A, 0xBB, 0xA2, 0xC7, 0xF5, 0x34, 0x17, 0x8E, + /* 0x368 */ 0xD9, 0x11, 0x40, 0xF4, 0xFC, 0x2C, 0x2A, 0x4D, + /* 0x370 */ 0x15, 0x7F, 0xA7, 0x62, 0x5D, 0x2E, 0x25, 0xD3, + /* 0x378 */ 0x00, 0x0B, 0x20, 0x1A, 0x1D, 0x68, 0xF9, 0x17, + /* 0x380 */ 0xB8, 0xF4, 0xBD, 0x8B, 0xED, 0x28, 0x59, 0xDD, + /* 0x388 */ 0x4D, 0x16, 0x8B, 0x17, 0x83, 0xC8, 0xB2, 0x65, + /* 0x390 */ 0xC7, 0x2D, 0x7A, 0xA5, 0xAA, 0xBC, 0x53, 0x86, + /* 0x398 */ 0x6D, 0xDD, 0x57, 0xA4, 0xCA, 0xF8, 0x20, 0x41, + /* 0x3a0 */ 0x0B, 0x68, 0xF0, 0xF4, 0xFB, 0x74, 0xBE, 0x56, + /* 0x3a8 */ 0x5D, 0x7A, 0x79, 0xF5, 0xF9, 0x1D, 0x85, 0xE3, + /* 0x3b0 */ 0x2D, 0x95, 0xBE, 0xF5, 0x71, 0x90, 0x43, 0xCC, + /* 0x3b8 */ 0x8D, 0x1F, 0x9A, 0x00, 0x0A, 0x87, 0x29, 0xE9, + /* 0x3c0 */ 0x55, 0x22, 0x58, 0x00, 0x23, 0xEA, 0xE3, 0x12, + /* 0x3c8 */ 0x43, 0x29, 0x5B, 0x47, 0x08, 0xDD, 0x8C, 0x41, + /* 0x3d0 */ 0x6A, 0x65, 0x06, 0xA8, 0xE5, 0x21, 0xAA, 0x41, + /* 0x3d8 */ 0xB4, 0x95, 0x21, 0x95, 0xB9, 0x7D, 0xD1, 0x34, + /* 0x3e0 */ 0xAB, 0x13, 0xD6, 0xAD, 0xBC, 0xDC, 0xE2, 0x3D, + /* 0x3e8 */ 0x39, 0xCD, 0xBD, 0x3E, 0x75, 0x70, 0xA1, 0x18, + /* 0x3f0 */ 0x59, 0x03, 0xC9, 0x22, 0xB4, 0x8F, 0x9C, 0xD5, + /* 0x3f8 */ 0x5E, 0x2A, 0xD7, 0xA5, 0xB6, 0xD4, 0x0A, 0x6D, + /* 0x400 */ 0xF8, 0xB7, 0x40, 0x11, 0x46, 0x9A, 0x1F, 0x79, + /* 0x408 */ 0x0E, 0x62, 0xBF, 0x0F, 0x97, 0xEC, 0xE0, 0x2F, + /* 0x410 */ 0x1F, 0x17, 0x94, +}; +static const lws_ss_x509_t _ss_x509_starfield_class_2_ca = { + .vhost_name = "starfield_class_2_ca", + .ca_der = _ss_der_starfield_class_2_ca, + .ca_der_len = 1043, +}; +static const uint8_t _ss_der_starfield_services_root_ca[] = { + /* 0x 0 */ 0x30, 0x82, 0x03, 0xEF, 0x30, 0x82, 0x02, 0xD7, + /* 0x 8 */ 0xA0, 0x03, 0x02, 0x01, 0x02, 0x02, 0x01, 0x00, + /* 0x 10 */ 0x30, 0x0D, 0x06, 0x09, 0x2A, 0x86, 0x48, 0x86, + /* 0x 18 */ 0xF7, 0x0D, 0x01, 0x01, 0x0B, 0x05, 0x00, 0x30, + /* 0x 20 */ 0x81, 0x98, 0x31, 0x0B, 0x30, 0x09, 0x06, 0x03, + /* 0x 28 */ 0x55, 0x04, 0x06, 0x13, 0x02, 0x55, 0x53, 0x31, + /* 0x 30 */ 0x10, 0x30, 0x0E, 0x06, 0x03, 0x55, 0x04, 0x08, + /* 0x 38 */ 0x13, 0x07, 0x41, 0x72, 0x69, 0x7A, 0x6F, 0x6E, + /* 0x 40 */ 0x61, 0x31, 0x13, 0x30, 0x11, 0x06, 0x03, 0x55, + /* 0x 48 */ 0x04, 0x07, 0x13, 0x0A, 0x53, 0x63, 0x6F, 0x74, + /* 0x 50 */ 0x74, 0x73, 0x64, 0x61, 0x6C, 0x65, 0x31, 0x25, + /* 0x 58 */ 0x30, 0x23, 0x06, 0x03, 0x55, 0x04, 0x0A, 0x13, + /* 0x 60 */ 0x1C, 0x53, 0x74, 0x61, 0x72, 0x66, 0x69, 0x65, + /* 0x 68 */ 0x6C, 0x64, 0x20, 0x54, 0x65, 0x63, 0x68, 0x6E, + /* 0x 70 */ 0x6F, 0x6C, 0x6F, 0x67, 0x69, 0x65, 0x73, 0x2C, + /* 0x 78 */ 0x20, 0x49, 0x6E, 0x63, 0x2E, 0x31, 0x3B, 0x30, + /* 0x 80 */ 0x39, 0x06, 0x03, 0x55, 0x04, 0x03, 0x13, 0x32, + /* 0x 88 */ 0x53, 0x74, 0x61, 0x72, 0x66, 0x69, 0x65, 0x6C, + /* 0x 90 */ 0x64, 0x20, 0x53, 0x65, 0x72, 0x76, 0x69, 0x63, + /* 0x 98 */ 0x65, 0x73, 0x20, 0x52, 0x6F, 0x6F, 0x74, 0x20, + /* 0x a0 */ 0x43, 0x65, 0x72, 0x74, 0x69, 0x66, 0x69, 0x63, + /* 0x a8 */ 0x61, 0x74, 0x65, 0x20, 0x41, 0x75, 0x74, 0x68, + /* 0x b0 */ 0x6F, 0x72, 0x69, 0x74, 0x79, 0x20, 0x2D, 0x20, + /* 0x b8 */ 0x47, 0x32, 0x30, 0x1E, 0x17, 0x0D, 0x30, 0x39, + /* 0x c0 */ 0x30, 0x39, 0x30, 0x31, 0x30, 0x30, 0x30, 0x30, + /* 0x c8 */ 0x30, 0x30, 0x5A, 0x17, 0x0D, 0x33, 0x37, 0x31, + /* 0x d0 */ 0x32, 0x33, 0x31, 0x32, 0x33, 0x35, 0x39, 0x35, + /* 0x d8 */ 0x39, 0x5A, 0x30, 0x81, 0x98, 0x31, 0x0B, 0x30, + /* 0x e0 */ 0x09, 0x06, 0x03, 0x55, 0x04, 0x06, 0x13, 0x02, + /* 0x e8 */ 0x55, 0x53, 0x31, 0x10, 0x30, 0x0E, 0x06, 0x03, + /* 0x f0 */ 0x55, 0x04, 0x08, 0x13, 0x07, 0x41, 0x72, 0x69, + /* 0x f8 */ 0x7A, 0x6F, 0x6E, 0x61, 0x31, 0x13, 0x30, 0x11, + /* 0x100 */ 0x06, 0x03, 0x55, 0x04, 0x07, 0x13, 0x0A, 0x53, + /* 0x108 */ 0x63, 0x6F, 0x74, 0x74, 0x73, 0x64, 0x61, 0x6C, + /* 0x110 */ 0x65, 0x31, 0x25, 0x30, 0x23, 0x06, 0x03, 0x55, + /* 0x118 */ 0x04, 0x0A, 0x13, 0x1C, 0x53, 0x74, 0x61, 0x72, + /* 0x120 */ 0x66, 0x69, 0x65, 0x6C, 0x64, 0x20, 0x54, 0x65, + /* 0x128 */ 0x63, 0x68, 0x6E, 0x6F, 0x6C, 0x6F, 0x67, 0x69, + /* 0x130 */ 0x65, 0x73, 0x2C, 0x20, 0x49, 0x6E, 0x63, 0x2E, + /* 0x138 */ 0x31, 0x3B, 0x30, 0x39, 0x06, 0x03, 0x55, 0x04, + /* 0x140 */ 0x03, 0x13, 0x32, 0x53, 0x74, 0x61, 0x72, 0x66, + /* 0x148 */ 0x69, 0x65, 0x6C, 0x64, 0x20, 0x53, 0x65, 0x72, + /* 0x150 */ 0x76, 0x69, 0x63, 0x65, 0x73, 0x20, 0x52, 0x6F, + /* 0x158 */ 0x6F, 0x74, 0x20, 0x43, 0x65, 0x72, 0x74, 0x69, + /* 0x160 */ 0x66, 0x69, 0x63, 0x61, 0x74, 0x65, 0x20, 0x41, + /* 0x168 */ 0x75, 0x74, 0x68, 0x6F, 0x72, 0x69, 0x74, 0x79, + /* 0x170 */ 0x20, 0x2D, 0x20, 0x47, 0x32, 0x30, 0x82, 0x01, + /* 0x178 */ 0x22, 0x30, 0x0D, 0x06, 0x09, 0x2A, 0x86, 0x48, + /* 0x180 */ 0x86, 0xF7, 0x0D, 0x01, 0x01, 0x01, 0x05, 0x00, + /* 0x188 */ 0x03, 0x82, 0x01, 0x0F, 0x00, 0x30, 0x82, 0x01, + /* 0x190 */ 0x0A, 0x02, 0x82, 0x01, 0x01, 0x00, 0xD5, 0x0C, + /* 0x198 */ 0x3A, 0xC4, 0x2A, 0xF9, 0x4E, 0xE2, 0xF5, 0xBE, + /* 0x1a0 */ 0x19, 0x97, 0x5F, 0x8E, 0x88, 0x53, 0xB1, 0x1F, + /* 0x1a8 */ 0x3F, 0xCB, 0xCF, 0x9F, 0x20, 0x13, 0x6D, 0x29, + /* 0x1b0 */ 0x3A, 0xC8, 0x0F, 0x7D, 0x3C, 0xF7, 0x6B, 0x76, + /* 0x1b8 */ 0x38, 0x63, 0xD9, 0x36, 0x60, 0xA8, 0x9B, 0x5E, + /* 0x1c0 */ 0x5C, 0x00, 0x80, 0xB2, 0x2F, 0x59, 0x7F, 0xF6, + /* 0x1c8 */ 0x87, 0xF9, 0x25, 0x43, 0x86, 0xE7, 0x69, 0x1B, + /* 0x1d0 */ 0x52, 0x9A, 0x90, 0xE1, 0x71, 0xE3, 0xD8, 0x2D, + /* 0x1d8 */ 0x0D, 0x4E, 0x6F, 0xF6, 0xC8, 0x49, 0xD9, 0xB6, + /* 0x1e0 */ 0xF3, 0x1A, 0x56, 0xAE, 0x2B, 0xB6, 0x74, 0x14, + /* 0x1e8 */ 0xEB, 0xCF, 0xFB, 0x26, 0xE3, 0x1A, 0xBA, 0x1D, + /* 0x1f0 */ 0x96, 0x2E, 0x6A, 0x3B, 0x58, 0x94, 0x89, 0x47, + /* 0x1f8 */ 0x56, 0xFF, 0x25, 0xA0, 0x93, 0x70, 0x53, 0x83, + /* 0x200 */ 0xDA, 0x84, 0x74, 0x14, 0xC3, 0x67, 0x9E, 0x04, + /* 0x208 */ 0x68, 0x3A, 0xDF, 0x8E, 0x40, 0x5A, 0x1D, 0x4A, + /* 0x210 */ 0x4E, 0xCF, 0x43, 0x91, 0x3B, 0xE7, 0x56, 0xD6, + /* 0x218 */ 0x00, 0x70, 0xCB, 0x52, 0xEE, 0x7B, 0x7D, 0xAE, + /* 0x220 */ 0x3A, 0xE7, 0xBC, 0x31, 0xF9, 0x45, 0xF6, 0xC2, + /* 0x228 */ 0x60, 0xCF, 0x13, 0x59, 0x02, 0x2B, 0x80, 0xCC, + /* 0x230 */ 0x34, 0x47, 0xDF, 0xB9, 0xDE, 0x90, 0x65, 0x6D, + /* 0x238 */ 0x02, 0xCF, 0x2C, 0x91, 0xA6, 0xA6, 0xE7, 0xDE, + /* 0x240 */ 0x85, 0x18, 0x49, 0x7C, 0x66, 0x4E, 0xA3, 0x3A, + /* 0x248 */ 0x6D, 0xA9, 0xB5, 0xEE, 0x34, 0x2E, 0xBA, 0x0D, + /* 0x250 */ 0x03, 0xB8, 0x33, 0xDF, 0x47, 0xEB, 0xB1, 0x6B, + /* 0x258 */ 0x8D, 0x25, 0xD9, 0x9B, 0xCE, 0x81, 0xD1, 0x45, + /* 0x260 */ 0x46, 0x32, 0x96, 0x70, 0x87, 0xDE, 0x02, 0x0E, + /* 0x268 */ 0x49, 0x43, 0x85, 0xB6, 0x6C, 0x73, 0xBB, 0x64, + /* 0x270 */ 0xEA, 0x61, 0x41, 0xAC, 0xC9, 0xD4, 0x54, 0xDF, + /* 0x278 */ 0x87, 0x2F, 0xC7, 0x22, 0xB2, 0x26, 0xCC, 0x9F, + /* 0x280 */ 0x59, 0x54, 0x68, 0x9F, 0xFC, 0xBE, 0x2A, 0x2F, + /* 0x288 */ 0xC4, 0x55, 0x1C, 0x75, 0x40, 0x60, 0x17, 0x85, + /* 0x290 */ 0x02, 0x55, 0x39, 0x8B, 0x7F, 0x05, 0x02, 0x03, + /* 0x298 */ 0x01, 0x00, 0x01, 0xA3, 0x42, 0x30, 0x40, 0x30, + /* 0x2a0 */ 0x0F, 0x06, 0x03, 0x55, 0x1D, 0x13, 0x01, 0x01, + /* 0x2a8 */ 0xFF, 0x04, 0x05, 0x30, 0x03, 0x01, 0x01, 0xFF, + /* 0x2b0 */ 0x30, 0x0E, 0x06, 0x03, 0x55, 0x1D, 0x0F, 0x01, + /* 0x2b8 */ 0x01, 0xFF, 0x04, 0x04, 0x03, 0x02, 0x01, 0x06, + /* 0x2c0 */ 0x30, 0x1D, 0x06, 0x03, 0x55, 0x1D, 0x0E, 0x04, + /* 0x2c8 */ 0x16, 0x04, 0x14, 0x9C, 0x5F, 0x00, 0xDF, 0xAA, + /* 0x2d0 */ 0x01, 0xD7, 0x30, 0x2B, 0x38, 0x88, 0xA2, 0xB8, + /* 0x2d8 */ 0x6D, 0x4A, 0x9C, 0xF2, 0x11, 0x91, 0x83, 0x30, + /* 0x2e0 */ 0x0D, 0x06, 0x09, 0x2A, 0x86, 0x48, 0x86, 0xF7, + /* 0x2e8 */ 0x0D, 0x01, 0x01, 0x0B, 0x05, 0x00, 0x03, 0x82, + /* 0x2f0 */ 0x01, 0x01, 0x00, 0x4B, 0x36, 0xA6, 0x84, 0x77, + /* 0x2f8 */ 0x69, 0xDD, 0x3B, 0x19, 0x9F, 0x67, 0x23, 0x08, + /* 0x300 */ 0x6F, 0x0E, 0x61, 0xC9, 0xFD, 0x84, 0xDC, 0x5F, + /* 0x308 */ 0xD8, 0x36, 0x81, 0xCD, 0xD8, 0x1B, 0x41, 0x2D, + /* 0x310 */ 0x9F, 0x60, 0xDD, 0xC7, 0x1A, 0x68, 0xD9, 0xD1, + /* 0x318 */ 0x6E, 0x86, 0xE1, 0x88, 0x23, 0xCF, 0x13, 0xDE, + /* 0x320 */ 0x43, 0xCF, 0xE2, 0x34, 0xB3, 0x04, 0x9D, 0x1F, + /* 0x328 */ 0x29, 0xD5, 0xBF, 0xF8, 0x5E, 0xC8, 0xD5, 0xC1, + /* 0x330 */ 0xBD, 0xEE, 0x92, 0x6F, 0x32, 0x74, 0xF2, 0x91, + /* 0x338 */ 0x82, 0x2F, 0xBD, 0x82, 0x42, 0x7A, 0xAD, 0x2A, + /* 0x340 */ 0xB7, 0x20, 0x7D, 0x4D, 0xBC, 0x7A, 0x55, 0x12, + /* 0x348 */ 0xC2, 0x15, 0xEA, 0xBD, 0xF7, 0x6A, 0x95, 0x2E, + /* 0x350 */ 0x6C, 0x74, 0x9F, 0xCF, 0x1C, 0xB4, 0xF2, 0xC5, + /* 0x358 */ 0x01, 0xA3, 0x85, 0xD0, 0x72, 0x3E, 0xAD, 0x73, + /* 0x360 */ 0xAB, 0x0B, 0x9B, 0x75, 0x0C, 0x6D, 0x45, 0xB7, + /* 0x368 */ 0x8E, 0x94, 0xAC, 0x96, 0x37, 0xB5, 0xA0, 0xD0, + /* 0x370 */ 0x8F, 0x15, 0x47, 0x0E, 0xE3, 0xE8, 0x83, 0xDD, + /* 0x378 */ 0x8F, 0xFD, 0xEF, 0x41, 0x01, 0x77, 0xCC, 0x27, + /* 0x380 */ 0xA9, 0x62, 0x85, 0x33, 0xF2, 0x37, 0x08, 0xEF, + /* 0x388 */ 0x71, 0xCF, 0x77, 0x06, 0xDE, 0xC8, 0x19, 0x1D, + /* 0x390 */ 0x88, 0x40, 0xCF, 0x7D, 0x46, 0x1D, 0xFF, 0x1E, + /* 0x398 */ 0xC7, 0xE1, 0xCE, 0xFF, 0x23, 0xDB, 0xC6, 0xFA, + /* 0x3a0 */ 0x8D, 0x55, 0x4E, 0xA9, 0x02, 0xE7, 0x47, 0x11, + /* 0x3a8 */ 0x46, 0x3E, 0xF4, 0xFD, 0xBD, 0x7B, 0x29, 0x26, + /* 0x3b0 */ 0xBB, 0xA9, 0x61, 0x62, 0x37, 0x28, 0xB6, 0x2D, + /* 0x3b8 */ 0x2A, 0xF6, 0x10, 0x86, 0x64, 0xC9, 0x70, 0xA7, + /* 0x3c0 */ 0xD2, 0xAD, 0xB7, 0x29, 0x70, 0x79, 0xEA, 0x3C, + /* 0x3c8 */ 0xDA, 0x63, 0x25, 0x9F, 0xFD, 0x68, 0xB7, 0x30, + /* 0x3d0 */ 0xEC, 0x70, 0xFB, 0x75, 0x8A, 0xB7, 0x6D, 0x60, + /* 0x3d8 */ 0x67, 0xB2, 0x1E, 0xC8, 0xB9, 0xE9, 0xD8, 0xA8, + /* 0x3e0 */ 0x6F, 0x02, 0x8B, 0x67, 0x0D, 0x4D, 0x26, 0x57, + /* 0x3e8 */ 0x71, 0xDA, 0x20, 0xFC, 0xC1, 0x4A, 0x50, 0x8D, + /* 0x3f0 */ 0xB1, 0x28, 0xBA, +}; +static const lws_ss_x509_t _ss_x509_starfield_services_root_ca = { + .vhost_name = "starfield_services_root_ca", + .ca_der = _ss_der_starfield_services_root_ca, + .ca_der_len = 1011, +}; +static const lws_ss_trust_store_t _ss_ts_mqtt_amz_iot = { + .name = "mqtt_amz_iot", + .ssx509 = { + &_ss_x509_starfield_services_root_ca, + &_ss_x509_starfield_class_2_ca, + &_ss_x509_amazon_root_ca_1, + } +}; +static const uint8_t _ss_der_isrg_root_x1[] = { + /* 0x 0 */ 0x30, 0x82, 0x05, 0x6B, 0x30, 0x82, 0x03, 0x53, + /* 0x 8 */ 0xA0, 0x03, 0x02, 0x01, 0x02, 0x02, 0x11, 0x00, + /* 0x 10 */ 0x82, 0x10, 0xCF, 0xB0, 0xD2, 0x40, 0xE3, 0x59, + /* 0x 18 */ 0x44, 0x63, 0xE0, 0xBB, 0x63, 0x82, 0x8B, 0x00, + /* 0x 20 */ 0x30, 0x0D, 0x06, 0x09, 0x2A, 0x86, 0x48, 0x86, + /* 0x 28 */ 0xF7, 0x0D, 0x01, 0x01, 0x0B, 0x05, 0x00, 0x30, + /* 0x 30 */ 0x4F, 0x31, 0x0B, 0x30, 0x09, 0x06, 0x03, 0x55, + /* 0x 38 */ 0x04, 0x06, 0x13, 0x02, 0x55, 0x53, 0x31, 0x29, + /* 0x 40 */ 0x30, 0x27, 0x06, 0x03, 0x55, 0x04, 0x0A, 0x13, + /* 0x 48 */ 0x20, 0x49, 0x6E, 0x74, 0x65, 0x72, 0x6E, 0x65, + /* 0x 50 */ 0x74, 0x20, 0x53, 0x65, 0x63, 0x75, 0x72, 0x69, + /* 0x 58 */ 0x74, 0x79, 0x20, 0x52, 0x65, 0x73, 0x65, 0x61, + /* 0x 60 */ 0x72, 0x63, 0x68, 0x20, 0x47, 0x72, 0x6F, 0x75, + /* 0x 68 */ 0x70, 0x31, 0x15, 0x30, 0x13, 0x06, 0x03, 0x55, + /* 0x 70 */ 0x04, 0x03, 0x13, 0x0C, 0x49, 0x53, 0x52, 0x47, + /* 0x 78 */ 0x20, 0x52, 0x6F, 0x6F, 0x74, 0x20, 0x58, 0x31, + /* 0x 80 */ 0x30, 0x1E, 0x17, 0x0D, 0x31, 0x35, 0x30, 0x36, + /* 0x 88 */ 0x30, 0x34, 0x31, 0x31, 0x30, 0x34, 0x33, 0x38, + /* 0x 90 */ 0x5A, 0x17, 0x0D, 0x33, 0x35, 0x30, 0x36, 0x30, + /* 0x 98 */ 0x34, 0x31, 0x31, 0x30, 0x34, 0x33, 0x38, 0x5A, + /* 0x a0 */ 0x30, 0x4F, 0x31, 0x0B, 0x30, 0x09, 0x06, 0x03, + /* 0x a8 */ 0x55, 0x04, 0x06, 0x13, 0x02, 0x55, 0x53, 0x31, + /* 0x b0 */ 0x29, 0x30, 0x27, 0x06, 0x03, 0x55, 0x04, 0x0A, + /* 0x b8 */ 0x13, 0x20, 0x49, 0x6E, 0x74, 0x65, 0x72, 0x6E, + /* 0x c0 */ 0x65, 0x74, 0x20, 0x53, 0x65, 0x63, 0x75, 0x72, + /* 0x c8 */ 0x69, 0x74, 0x79, 0x20, 0x52, 0x65, 0x73, 0x65, + /* 0x d0 */ 0x61, 0x72, 0x63, 0x68, 0x20, 0x47, 0x72, 0x6F, + /* 0x d8 */ 0x75, 0x70, 0x31, 0x15, 0x30, 0x13, 0x06, 0x03, + /* 0x e0 */ 0x55, 0x04, 0x03, 0x13, 0x0C, 0x49, 0x53, 0x52, + /* 0x e8 */ 0x47, 0x20, 0x52, 0x6F, 0x6F, 0x74, 0x20, 0x58, + /* 0x f0 */ 0x31, 0x30, 0x82, 0x02, 0x22, 0x30, 0x0D, 0x06, + /* 0x f8 */ 0x09, 0x2A, 0x86, 0x48, 0x86, 0xF7, 0x0D, 0x01, + /* 0x100 */ 0x01, 0x01, 0x05, 0x00, 0x03, 0x82, 0x02, 0x0F, + /* 0x108 */ 0x00, 0x30, 0x82, 0x02, 0x0A, 0x02, 0x82, 0x02, + /* 0x110 */ 0x01, 0x00, 0xAD, 0xE8, 0x24, 0x73, 0xF4, 0x14, + /* 0x118 */ 0x37, 0xF3, 0x9B, 0x9E, 0x2B, 0x57, 0x28, 0x1C, + /* 0x120 */ 0x87, 0xBE, 0xDC, 0xB7, 0xDF, 0x38, 0x90, 0x8C, + /* 0x128 */ 0x6E, 0x3C, 0xE6, 0x57, 0xA0, 0x78, 0xF7, 0x75, + /* 0x130 */ 0xC2, 0xA2, 0xFE, 0xF5, 0x6A, 0x6E, 0xF6, 0x00, + /* 0x138 */ 0x4F, 0x28, 0xDB, 0xDE, 0x68, 0x86, 0x6C, 0x44, + /* 0x140 */ 0x93, 0xB6, 0xB1, 0x63, 0xFD, 0x14, 0x12, 0x6B, + /* 0x148 */ 0xBF, 0x1F, 0xD2, 0xEA, 0x31, 0x9B, 0x21, 0x7E, + /* 0x150 */ 0xD1, 0x33, 0x3C, 0xBA, 0x48, 0xF5, 0xDD, 0x79, + /* 0x158 */ 0xDF, 0xB3, 0xB8, 0xFF, 0x12, 0xF1, 0x21, 0x9A, + /* 0x160 */ 0x4B, 0xC1, 0x8A, 0x86, 0x71, 0x69, 0x4A, 0x66, + /* 0x168 */ 0x66, 0x6C, 0x8F, 0x7E, 0x3C, 0x70, 0xBF, 0xAD, + /* 0x170 */ 0x29, 0x22, 0x06, 0xF3, 0xE4, 0xC0, 0xE6, 0x80, + /* 0x178 */ 0xAE, 0xE2, 0x4B, 0x8F, 0xB7, 0x99, 0x7E, 0x94, + /* 0x180 */ 0x03, 0x9F, 0xD3, 0x47, 0x97, 0x7C, 0x99, 0x48, + /* 0x188 */ 0x23, 0x53, 0xE8, 0x38, 0xAE, 0x4F, 0x0A, 0x6F, + /* 0x190 */ 0x83, 0x2E, 0xD1, 0x49, 0x57, 0x8C, 0x80, 0x74, + /* 0x198 */ 0xB6, 0xDA, 0x2F, 0xD0, 0x38, 0x8D, 0x7B, 0x03, + /* 0x1a0 */ 0x70, 0x21, 0x1B, 0x75, 0xF2, 0x30, 0x3C, 0xFA, + /* 0x1a8 */ 0x8F, 0xAE, 0xDD, 0xDA, 0x63, 0xAB, 0xEB, 0x16, + /* 0x1b0 */ 0x4F, 0xC2, 0x8E, 0x11, 0x4B, 0x7E, 0xCF, 0x0B, + /* 0x1b8 */ 0xE8, 0xFF, 0xB5, 0x77, 0x2E, 0xF4, 0xB2, 0x7B, + /* 0x1c0 */ 0x4A, 0xE0, 0x4C, 0x12, 0x25, 0x0C, 0x70, 0x8D, + /* 0x1c8 */ 0x03, 0x29, 0xA0, 0xE1, 0x53, 0x24, 0xEC, 0x13, + /* 0x1d0 */ 0xD9, 0xEE, 0x19, 0xBF, 0x10, 0xB3, 0x4A, 0x8C, + /* 0x1d8 */ 0x3F, 0x89, 0xA3, 0x61, 0x51, 0xDE, 0xAC, 0x87, + /* 0x1e0 */ 0x07, 0x94, 0xF4, 0x63, 0x71, 0xEC, 0x2E, 0xE2, + /* 0x1e8 */ 0x6F, 0x5B, 0x98, 0x81, 0xE1, 0x89, 0x5C, 0x34, + /* 0x1f0 */ 0x79, 0x6C, 0x76, 0xEF, 0x3B, 0x90, 0x62, 0x79, + /* 0x1f8 */ 0xE6, 0xDB, 0xA4, 0x9A, 0x2F, 0x26, 0xC5, 0xD0, + /* 0x200 */ 0x10, 0xE1, 0x0E, 0xDE, 0xD9, 0x10, 0x8E, 0x16, + /* 0x208 */ 0xFB, 0xB7, 0xF7, 0xA8, 0xF7, 0xC7, 0xE5, 0x02, + /* 0x210 */ 0x07, 0x98, 0x8F, 0x36, 0x08, 0x95, 0xE7, 0xE2, + /* 0x218 */ 0x37, 0x96, 0x0D, 0x36, 0x75, 0x9E, 0xFB, 0x0E, + /* 0x220 */ 0x72, 0xB1, 0x1D, 0x9B, 0xBC, 0x03, 0xF9, 0x49, + /* 0x228 */ 0x05, 0xD8, 0x81, 0xDD, 0x05, 0xB4, 0x2A, 0xD6, + /* 0x230 */ 0x41, 0xE9, 0xAC, 0x01, 0x76, 0x95, 0x0A, 0x0F, + /* 0x238 */ 0xD8, 0xDF, 0xD5, 0xBD, 0x12, 0x1F, 0x35, 0x2F, + /* 0x240 */ 0x28, 0x17, 0x6C, 0xD2, 0x98, 0xC1, 0xA8, 0x09, + /* 0x248 */ 0x64, 0x77, 0x6E, 0x47, 0x37, 0xBA, 0xCE, 0xAC, + /* 0x250 */ 0x59, 0x5E, 0x68, 0x9D, 0x7F, 0x72, 0xD6, 0x89, + /* 0x258 */ 0xC5, 0x06, 0x41, 0x29, 0x3E, 0x59, 0x3E, 0xDD, + /* 0x260 */ 0x26, 0xF5, 0x24, 0xC9, 0x11, 0xA7, 0x5A, 0xA3, + /* 0x268 */ 0x4C, 0x40, 0x1F, 0x46, 0xA1, 0x99, 0xB5, 0xA7, + /* 0x270 */ 0x3A, 0x51, 0x6E, 0x86, 0x3B, 0x9E, 0x7D, 0x72, + /* 0x278 */ 0xA7, 0x12, 0x05, 0x78, 0x59, 0xED, 0x3E, 0x51, + /* 0x280 */ 0x78, 0x15, 0x0B, 0x03, 0x8F, 0x8D, 0xD0, 0x2F, + /* 0x288 */ 0x05, 0xB2, 0x3E, 0x7B, 0x4A, 0x1C, 0x4B, 0x73, + /* 0x290 */ 0x05, 0x12, 0xFC, 0xC6, 0xEA, 0xE0, 0x50, 0x13, + /* 0x298 */ 0x7C, 0x43, 0x93, 0x74, 0xB3, 0xCA, 0x74, 0xE7, + /* 0x2a0 */ 0x8E, 0x1F, 0x01, 0x08, 0xD0, 0x30, 0xD4, 0x5B, + /* 0x2a8 */ 0x71, 0x36, 0xB4, 0x07, 0xBA, 0xC1, 0x30, 0x30, + /* 0x2b0 */ 0x5C, 0x48, 0xB7, 0x82, 0x3B, 0x98, 0xA6, 0x7D, + /* 0x2b8 */ 0x60, 0x8A, 0xA2, 0xA3, 0x29, 0x82, 0xCC, 0xBA, + /* 0x2c0 */ 0xBD, 0x83, 0x04, 0x1B, 0xA2, 0x83, 0x03, 0x41, + /* 0x2c8 */ 0xA1, 0xD6, 0x05, 0xF1, 0x1B, 0xC2, 0xB6, 0xF0, + /* 0x2d0 */ 0xA8, 0x7C, 0x86, 0x3B, 0x46, 0xA8, 0x48, 0x2A, + /* 0x2d8 */ 0x88, 0xDC, 0x76, 0x9A, 0x76, 0xBF, 0x1F, 0x6A, + /* 0x2e0 */ 0xA5, 0x3D, 0x19, 0x8F, 0xEB, 0x38, 0xF3, 0x64, + /* 0x2e8 */ 0xDE, 0xC8, 0x2B, 0x0D, 0x0A, 0x28, 0xFF, 0xF7, + /* 0x2f0 */ 0xDB, 0xE2, 0x15, 0x42, 0xD4, 0x22, 0xD0, 0x27, + /* 0x2f8 */ 0x5D, 0xE1, 0x79, 0xFE, 0x18, 0xE7, 0x70, 0x88, + /* 0x300 */ 0xAD, 0x4E, 0xE6, 0xD9, 0x8B, 0x3A, 0xC6, 0xDD, + /* 0x308 */ 0x27, 0x51, 0x6E, 0xFF, 0xBC, 0x64, 0xF5, 0x33, + /* 0x310 */ 0x43, 0x4F, 0x02, 0x03, 0x01, 0x00, 0x01, 0xA3, + /* 0x318 */ 0x42, 0x30, 0x40, 0x30, 0x0E, 0x06, 0x03, 0x55, + /* 0x320 */ 0x1D, 0x0F, 0x01, 0x01, 0xFF, 0x04, 0x04, 0x03, + /* 0x328 */ 0x02, 0x01, 0x06, 0x30, 0x0F, 0x06, 0x03, 0x55, + /* 0x330 */ 0x1D, 0x13, 0x01, 0x01, 0xFF, 0x04, 0x05, 0x30, + /* 0x338 */ 0x03, 0x01, 0x01, 0xFF, 0x30, 0x1D, 0x06, 0x03, + /* 0x340 */ 0x55, 0x1D, 0x0E, 0x04, 0x16, 0x04, 0x14, 0x79, + /* 0x348 */ 0xB4, 0x59, 0xE6, 0x7B, 0xB6, 0xE5, 0xE4, 0x01, + /* 0x350 */ 0x73, 0x80, 0x08, 0x88, 0xC8, 0x1A, 0x58, 0xF6, + /* 0x358 */ 0xE9, 0x9B, 0x6E, 0x30, 0x0D, 0x06, 0x09, 0x2A, + /* 0x360 */ 0x86, 0x48, 0x86, 0xF7, 0x0D, 0x01, 0x01, 0x0B, + /* 0x368 */ 0x05, 0x00, 0x03, 0x82, 0x02, 0x01, 0x00, 0x55, + /* 0x370 */ 0x1F, 0x58, 0xA9, 0xBC, 0xB2, 0xA8, 0x50, 0xD0, + /* 0x378 */ 0x0C, 0xB1, 0xD8, 0x1A, 0x69, 0x20, 0x27, 0x29, + /* 0x380 */ 0x08, 0xAC, 0x61, 0x75, 0x5C, 0x8A, 0x6E, 0xF8, + /* 0x388 */ 0x82, 0xE5, 0x69, 0x2F, 0xD5, 0xF6, 0x56, 0x4B, + /* 0x390 */ 0xB9, 0xB8, 0x73, 0x10, 0x59, 0xD3, 0x21, 0x97, + /* 0x398 */ 0x7E, 0xE7, 0x4C, 0x71, 0xFB, 0xB2, 0xD2, 0x60, + /* 0x3a0 */ 0xAD, 0x39, 0xA8, 0x0B, 0xEA, 0x17, 0x21, 0x56, + /* 0x3a8 */ 0x85, 0xF1, 0x50, 0x0E, 0x59, 0xEB, 0xCE, 0xE0, + /* 0x3b0 */ 0x59, 0xE9, 0xBA, 0xC9, 0x15, 0xEF, 0x86, 0x9D, + /* 0x3b8 */ 0x8F, 0x84, 0x80, 0xF6, 0xE4, 0xE9, 0x91, 0x90, + /* 0x3c0 */ 0xDC, 0x17, 0x9B, 0x62, 0x1B, 0x45, 0xF0, 0x66, + /* 0x3c8 */ 0x95, 0xD2, 0x7C, 0x6F, 0xC2, 0xEA, 0x3B, 0xEF, + /* 0x3d0 */ 0x1F, 0xCF, 0xCB, 0xD6, 0xAE, 0x27, 0xF1, 0xA9, + /* 0x3d8 */ 0xB0, 0xC8, 0xAE, 0xFD, 0x7D, 0x7E, 0x9A, 0xFA, + /* 0x3e0 */ 0x22, 0x04, 0xEB, 0xFF, 0xD9, 0x7F, 0xEA, 0x91, + /* 0x3e8 */ 0x2B, 0x22, 0xB1, 0x17, 0x0E, 0x8F, 0xF2, 0x8A, + /* 0x3f0 */ 0x34, 0x5B, 0x58, 0xD8, 0xFC, 0x01, 0xC9, 0x54, + /* 0x3f8 */ 0xB9, 0xB8, 0x26, 0xCC, 0x8A, 0x88, 0x33, 0x89, + /* 0x400 */ 0x4C, 0x2D, 0x84, 0x3C, 0x82, 0xDF, 0xEE, 0x96, + /* 0x408 */ 0x57, 0x05, 0xBA, 0x2C, 0xBB, 0xF7, 0xC4, 0xB7, + /* 0x410 */ 0xC7, 0x4E, 0x3B, 0x82, 0xBE, 0x31, 0xC8, 0x22, + /* 0x418 */ 0x73, 0x73, 0x92, 0xD1, 0xC2, 0x80, 0xA4, 0x39, + /* 0x420 */ 0x39, 0x10, 0x33, 0x23, 0x82, 0x4C, 0x3C, 0x9F, + /* 0x428 */ 0x86, 0xB2, 0x55, 0x98, 0x1D, 0xBE, 0x29, 0x86, + /* 0x430 */ 0x8C, 0x22, 0x9B, 0x9E, 0xE2, 0x6B, 0x3B, 0x57, + /* 0x438 */ 0x3A, 0x82, 0x70, 0x4D, 0xDC, 0x09, 0xC7, 0x89, + /* 0x440 */ 0xCB, 0x0A, 0x07, 0x4D, 0x6C, 0xE8, 0x5D, 0x8E, + /* 0x448 */ 0xC9, 0xEF, 0xCE, 0xAB, 0xC7, 0xBB, 0xB5, 0x2B, + /* 0x450 */ 0x4E, 0x45, 0xD6, 0x4A, 0xD0, 0x26, 0xCC, 0xE5, + /* 0x458 */ 0x72, 0xCA, 0x08, 0x6A, 0xA5, 0x95, 0xE3, 0x15, + /* 0x460 */ 0xA1, 0xF7, 0xA4, 0xED, 0xC9, 0x2C, 0x5F, 0xA5, + /* 0x468 */ 0xFB, 0xFF, 0xAC, 0x28, 0x02, 0x2E, 0xBE, 0xD7, + /* 0x470 */ 0x7B, 0xBB,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0x38, 0xE1, 0x96, 0xB8, 0xAC, + /* 0x508 */ 0x5D, 0x8B, 0x37, 0xD7, 0x75, 0xD5, 0x33, 0xC0, + /* 0x510 */ 0x99, 0x11, 0xAE, 0x9D, 0x41, 0xC1, 0x72, 0x75, + /* 0x518 */ 0x84, 0xBE, 0x02, 0x41, 0x42, 0x5F, 0x67, 0x24, + /* 0x520 */ 0x48, 0x94, 0xD1, 0x9B, 0x27, 0xBE, 0x07, 0x3F, + /* 0x528 */ 0xB9, 0xB8, 0x4F, 0x81, 0x74, 0x51, 0xE1, 0x7A, + /* 0x530 */ 0xB7, 0xED, 0x9D, 0x23, 0xE2, 0xBE, 0xE0, 0xD5, + /* 0x538 */ 0x28, 0x04, 0x13, 0x3C, 0x31, 0x03, 0x9E, 0xDD, + /* 0x540 */ 0x7A, 0x6C, 0x8F, 0xC6, 0x07, 0x18, 0xC6, 0x7F, + /* 0x548 */ 0xDE, 0x47, 0x8E, 0x3F, 0x28, 0x9E, 0x04, 0x06, + /* 0x550 */ 0xCF, 0xA5, 0x54, 0x34, 0x77, 0xBD, 0xEC, 0x89, + /* 0x558 */ 0x9B, 0xE9, 0x17, 0x43, 0xDF, 0x5B, 0xDB, 0x5F, + /* 0x560 */ 0xFE, 0x8E, 0x1E, 0x57, 0xA2, 0xCD, 0x40, 0x9D, + /* 0x568 */ 0x7E, 0x62, 0x22, 0xDA, 0xDE, 0x18, 0x27, +}; +static const lws_ss_x509_t _ss_x509_isrg_root_x1 = { + .vhost_name = "isrg_root_x1", + .ca_der = _ss_der_isrg_root_x1, + .ca_der_len = 1391, +}; +static const uint8_t _ss_der_LEX3_isrg_root_x1[] = { + /* 0x 0 */ 0x30, 0x82, 0x05, 0x8D, 0x30, 0x82, 0x03, 0x75, + /* 0x 8 */ 0xA0, 0x03, 0x02, 0x01, 0x02, 0x02, 0x11, 0x00, + /* 0x 10 */ 0xD3, 0xB1, 0x72, 0x26, 0x34, 0x23, 0x32, 0xDC, + /* 0x 18 */ 0xF4, 0x05, 0x28, 0x51, 0x2A, 0xEC, 0x9C, 0x6A, + /* 0x 20 */ 0x30, 0x0D, 0x06, 0x09, 0x2A, 0x86, 0x48, 0x86, + /* 0x 28 */ 0xF7, 0x0D, 0x01, 0x01, 0x0B, 0x05, 0x00, 0x30, + /* 0x 30 */ 0x4F, 0x31, 0x0B, 0x30, 0x09, 0x06, 0x03, 0x55, + /* 0x 38 */ 0x04, 0x06, 0x13, 0x02, 0x55, 0x53, 0x31, 0x29, + /* 0x 40 */ 0x30, 0x27, 0x06, 0x03, 0x55, 0x04, 0x0A, 0x13, + /* 0x 48 */ 0x20, 0x49, 0x6E, 0x74, 0x65, 0x72, 0x6E, 0x65, + /* 0x 50 */ 0x74, 0x20, 0x53, 0x65, 0x63, 0x75, 0x72, 0x69, + /* 0x 58 */ 0x74, 0x79, 0x20, 0x52, 0x65, 0x73, 0x65, 0x61, + /* 0x 60 */ 0x72, 0x63, 0x68, 0x20, 0x47, 0x72, 0x6F, 0x75, + /* 0x 68 */ 0x70, 0x31, 0x15, 0x30, 0x13, 0x06, 0x03, 0x55, + /* 0x 70 */ 0x04, 0x03, 0x13, 0x0C, 0x49, 0x53, 0x52, 0x47, + /* 0x 78 */ 0x20, 0x52, 0x6F, 0x6F, 0x74, 0x20, 0x58, 0x31, + /* 0x 80 */ 0x30, 0x1E, 0x17, 0x0D, 0x31, 0x36, 0x31, 0x30, + /* 0x 88 */ 0x30, 0x36, 0x31, 0x35, 0x34, 0x33, 0x35, 0x35, + /* 0x 90 */ 0x5A, 0x17, 0x0D, 0x32, 0x31, 0x31, 0x30, 0x30, + /* 0x 98 */ 0x36, 0x31, 0x35, 0x34, 0x33, 0x35, 0x35, 0x5A, + /* 0x a0 */ 0x30, 0x4A, 0x31, 0x0B, 0x30, 0x09, 0x06, 0x03, + /* 0x a8 */ 0x55, 0x04, 0x06, 0x13, 0x02, 0x55, 0x53, 0x31, + /* 0x b0 */ 0x16, 0x30, 0x14, 0x06, 0x03, 0x55, 0x04, 0x0A, + /* 0x b8 */ 0x13, 0x0D, 0x4C, 0x65, 0x74, 0x27, 0x73, 0x20, + /* 0x c0 */ 0x45, 0x6E, 0x63, 0x72, 0x79, 0x70, 0x74, 0x31, + /* 0x c8 */ 0x23, 0x30, 0x21, 0x06, 0x03, 0x55, 0x04, 0x03, + /* 0x d0 */ 0x13, 0x1A, 0x4C, 0x65, 0x74, 0x27, 0x73, 0x20, + /* 0x d8 */ 0x45, 0x6E, 0x63, 0x72, 0x79, 0x70, 0x74, 0x20, + /* 0x e0 */ 0x41, 0x75, 0x74, 0x68, 0x6F, 0x72, 0x69, 0x74, + /* 0x e8 */ 0x79, 0x20, 0x58, 0x33, 0x30, 0x82, 0x01, 0x22, + /* 0x f0 */ 0x30, 0x0D, 0x06, 0x09, 0x2A, 0x86, 0x48, 0x86, + /* 0x f8 */ 0xF7, 0x0D, 0x01, 0x01, 0x01, 0x05, 0x00, 0x03, + /* 0x100 */ 0x82, 0x01, 0x0F, 0x00, 0x30, 0x82, 0x01, 0x0A, + /* 0x108 */ 0x02, 0x82, 0x01, 0x01, 0x00, 0x9C, 0xD3, 0x0C, + /* 0x110 */ 0xF0, 0x5A, 0xE5, 0x2E, 0x47, 0xB7, 0x72, 0x5D, + /* 0x118 */ 0x37, 0x83, 0xB3, 0x68, 0x63, 0x30, 0xEA, 0xD7, + /* 0x120 */ 0x35, 0x26, 0x19, 0x25, 0xE1, 0xBD, 0xBE, 0x35, + /* 0x128 */ 0xF1, 0x70, 0x92, 0x2F, 0xB7, 0xB8, 0x4B, 0x41, + /* 0x130 */ 0x05, 0xAB, 0xA9, 0x9E, 0x35, 0x08, 0x58, 0xEC, + /* 0x138 */ 0xB1, 0x2A, 0xC4, 0x68, 0x87, 0x0B, 0xA3, 0xE3, + /* 0x140 */ 0x75, 0xE4, 0xE6, 0xF3, 0xA7, 0x62, 0x71, 0xBA, + /* 0x148 */ 0x79, 0x81, 0x60, 0x1F, 0xD7, 0x91, 0x9A, 0x9F, + /* 0x150 */ 0xF3, 0xD0, 0x78, 0x67, 0x71, 0xC8, 0x69, 0x0E, + /* 0x158 */ 0x95, 0x91, 0xCF, 0xFE, 0xE6, 0x99, 0xE9, 0x60, + /* 0x160 */ 0x3C, 0x48, 0xCC, 0x7E, 0xCA, 0x4D, 0x77, 0x12, + /* 0x168 */ 0x24, 0x9D, 0x47, 0x1B, 0x5A, 0xEB, 0xB9, 0xEC, + /* 0x170 */ 0x1E, 0x37, 0x00, 0x1C, 0x9C, 0xAC, 0x7B, 0xA7, + /* 0x178 */ 0x05, 0xEA, 0xCE, 0x4A, 0xEB, 0xBD, 0x41, 0xE5, + /* 0x180 */ 0x36, 0x98, 0xB9, 0xCB, 0xFD, 0x6D, 0x3C, 0x96, + /* 0x188 */ 0x68, 0xDF, 0x23, 0x2A, 0x42, 0x90, 0x0C, 0x86, + /* 0x190 */ 0x74, 0x67, 0xC8, 0x7F, 0xA5, 0x9A, 0xB8, 0x52, + /* 0x198 */ 0x61, 0x14, 0x13, 0x3F, 0x65, 0xE9, 0x82, 0x87, + /* 0x1a0 */ 0xCB, 0xDB, 0xFA, 0x0E, 0x56, 0xF6, 0x86, 0x89, + /* 0x1a8 */ 0xF3, 0x85, 0x3F, 0x97, 0x86, 0xAF, 0xB0, 0xDC, + /* 0x1b0 */ 0x1A, 0xEF, 0x6B, 0x0D, 0x95, 0x16, 0x7D, 0xC4, + /* 0x1b8 */ 0x2B, 0xA0, 0x65, 0xB2, 0x99, 0x04, 0x36, 0x75, + /* 0x1c0 */ 0x80, 0x6B, 0xAC, 0x4A, 0xF3, 0x1B, 0x90, 0x49, + /* 0x1c8 */ 0x78, 0x2F, 0xA2, 0x96, 0x4F, 0x2A, 0x20, 0x25, + /* 0x1d0 */ 0x29, 0x04, 0xC6, 0x74, 0xC0, 0xD0, 0x31, 0xCD, + /* 0x1d8 */ 0x8F, 0x31, 0x38, 0x95, 0x16, 0xBA, 0xA8, 0x33, + /* 0x1e0 */ 0xB8, 0x43, 0xF1, 0xB1, 0x1F, 0xC3, 0x30, 0x7F, + /* 0x1e8 */ 0xA2, 0x79, 0x31, 0x13, 0x3D, 0x2D, 0x36, 0xF8, + /* 0x1f0 */ 0xE3, 0xFC, 0xF2, 0x33, 0x6A, 0xB9, 0x39, 0x31, + /* 0x1f8 */ 0xC5, 0xAF, 0xC4, 0x8D, 0x0D, 0x1D, 0x64, 0x16, + /* 0x200 */ 0x33, 0xAA, 0xFA, 0x84, 0x29, 0xB6, 0xD4, 0x0B, + /* 0x208 */ 0xC0, 0xD8, 0x7D, 0xC3, 0x93, 0x02, 0x03, 0x01, + /* 0x210 */ 0x00, 0x01, 0xA3, 0x82, 0x01, 0x67, 0x30, 0x82, + /* 0x218 */ 0x01, 0x63, 0x30, 0x0E, 0x06, 0x03, 0x55, 0x1D, + /* 0x220 */ 0x0F, 0x01, 0x01, 0xFF, 0x04, 0x04, 0x03, 0x02, + /* 0x228 */ 0x01, 0x86, 0x30, 0x12, 0x06, 0x03, 0x55, 0x1D, + /* 0x230 */ 0x13, 0x01, 0x01, 0xFF, 0x04, 0x08, 0x30, 0x06, + /* 0x238 */ 0x01, 0x01, 0xFF, 0x02, 0x01, 0x00, 0x30, 0x54, + /* 0x240 */ 0x06, 0x03, 0x55, 0x1D, 0x20, 0x04, 0x4D, 0x30, + /* 0x248 */ 0x4B, 0x30, 0x08, 0x06, 0x06, 0x67, 0x81, 0x0C, + /* 0x250 */ 0x01, 0x02, 0x01, 0x30, 0x3F, 0x06, 0x0B, 0x2B, + /* 0x258 */ 0x06, 0x01, 0x04, 0x01, 0x82, 0xDF, 0x13, 0x01, + /* 0x260 */ 0x01, 0x01, 0x30, 0x30, 0x30, 0x2E, 0x06, 0x08, + /* 0x268 */ 0x2B, 0x06, 0x01, 0x05, 0x05, 0x07, 0x02, 0x01, + /* 0x270 */ 0x16, 0x22, 0x68, 0x74, 0x74, 0x70, 0x3A, 0x2F, + /* 0x278 */ 0x2F, 0x63, 0x70, 0x73, 0x2E, 0x72, 0x6F, 0x6F, + /* 0x280 */ 0x74, 0x2D, 0x78, 0x31, 0x2E, 0x6C, 0x65, 0x74, + /* 0x288 */ 0x73, 0x65, 0x6E, 0x63, 0x72, 0x79, 0x70, 0x74, + /* 0x290 */ 0x2E, 0x6F, 0x72, 0x67, 0x30, 0x1D, 0x06, 0x03, + /* 0x298 */ 0x55, 0x1D, 0x0E, 0x04, 0x16, 0x04, 0x14, 0xA8, + /* 0x2a0 */ 0x4A, 0x6A, 0x63, 0x04, 0x7D, 0xDD, 0xBA, 0xE6, + /* 0x2a8 */ 0xD1, 0x39, 0xB7, 0xA6, 0x45, 0x65, 0xEF, 0xF3, + /* 0x2b0 */ 0xA8, 0xEC, 0xA1, 0x30, 0x33, 0x06, 0x03, 0x55, + /* 0x2b8 */ 0x1D, 0x1F, 0x04, 0x2C, 0x30, 0x2A, 0x30, 0x28, + /* 0x2c0 */ 0xA0, 0x26, 0xA0, 0x24, 0x86, 0x22, 0x68, 0x74, + /* 0x2c8 */ 0x74, 0x70, 0x3A, 0x2F, 0x2F, 0x63, 0x72, 0x6C, + /* 0x2d0 */ 0x2E, 0x72, 0x6F, 0x6F, 0x74, 0x2D, 0x78, 0x31, + /* 0x2d8 */ 0x2E, 0x6C, 0x65, 0x74, 0x73, 0x65, 0x6E, 0x63, + /* 0x2e0 */ 0x72, 0x79, 0x70, 0x74, 0x2E, 0x6F, 0x72, 0x67, + /* 0x2e8 */ 0x30, 0x72, 0x06, 0x08, 0x2B, 0x06, 0x01, 0x05, + /* 0x2f0 */ 0x05, 0x07, 0x01, 0x01, 0x04, 0x66, 0x30, 0x64, + /* 0x2f8 */ 0x30, 0x30, 0x06, 0x08, 0x2B, 0x06, 0x01, 0x05, + /* 0x300 */ 0x05, 0x07, 0x30, 0x01, 0x86, 0x24, 0x68, 0x74, + /* 0x308 */ 0x74, 0x70, 0x3A, 0x2F, 0x2F, 0x6F, 0x63, 0x73, + /* 0x310 */ 0x70, 0x2E, 0x72, 0x6F, 0x6F, 0x74, 0x2D, 0x78, + /* 0x318 */ 0x31, 0x2E, 0x6C, 0x65, 0x74, 0x73, 0x65, 0x6E, + /* 0x320 */ 0x63, 0x72, 0x79, 0x70, 0x74, 0x2E, 0x6F, 0x72, + /* 0x328 */ 0x67, 0x2F, 0x30, 0x30, 0x06, 0x08, 0x2B, 0x06, + /* 0x330 */ 0x01, 0x05, 0x05, 0x07, 0x30, 0x02, 0x86, 0x24, + /* 0x338 */ 0x68, 0x74, 0x74, 0x70, 0x3A, 0x2F, 0x2F, 0x63, + /* 0x340 */ 0x65, 0x72, 0x74, 0x2E, 0x72, 0x6F, 0x6F, 0x74, + /* 0x348 */ 0x2D, 0x78, 0x31, 0x2E, 0x6C, 0x65, 0x74, 0x73, + /* 0x350 */ 0x65, 0x6E, 0x63, 0x72, 0x79, 0x70, 0x74, 0x2E, + /* 0x358 */ 0x6F, 0x72, 0x67, 0x2F, 0x30, 0x1F, 0x06, 0x03, + /* 0x360 */ 0x55, 0x1D, 0x23, 0x04, 0x18, 0x30, 0x16, 0x80, + /* 0x368 */ 0x14, 0x79, 0xB4, 0x59, 0xE6, 0x7B, 0xB6, 0xE5, + /* 0x370 */ 0xE4, 0x01, 0x73, 0x80, 0x08, 0x88, 0xC8, 0x1A, + /* 0x378 */ 0x58, 0xF6, 0xE9, 0x9B, 0x6E, 0x30, 0x0D, 0x06, + /* 0x380 */ 0x09, 0x2A, 0x86, 0x48, 0x86, 0xF7, 0x0D, 0x01, + /* 0x388 */ 0x01, 0x0B, 0x05, 0x00, 0x03, 0x82, 0x02, 0x01, + /* 0x390 */ 0x00, 0x19, 0xCF, 0x75, 0x20, 0x34, 0x2D, 0x3A, + /* 0x398 */ 0xA6, 0x45, 0xFF, 0xD0, 0xD5, 0xE6, 0x8C, 0xDA, + /* 0x3a0 */ 0x32, 0xE8, 0x9C, 0x6E, 0x1B, 0x41, 0xD1, 0x27, + /* 0x3a8 */ 0xA8, 0xE2, 0x50, 0xF2, 0x70, 0xAA, 0xC4, 0xE7, + /* 0x3b0 */ 0x93, 0x46, 0xB4, 0xE8, 0x10, 0xAB, 0x70, 0x4F, + /* 0x3b8 */ 0xEF, 0xB7, 0xEA, 0x04, 0xD2, 0x94, 0x11, 0xB1, + /* 0x3c0 */ 0x03, 0xFE, 0x5D, 0xBA, 0xDF, 0x36, 0x8C, 0x94, + /* 0x3c8 */ 0x36, 0x8F, 0x13, 0x7C, 0x44, 0x8F, 0x0B, 0xF5, + /* 0x3d0 */ 0x01, 0x57, 0xAD, 0x68, 0xB8, 0xC5, 0x79, 0xC0, + /* 0x3d8 */ 0xD8, 0x4A, 0x80, 0xD7, 0x4C, 0xA3, 0x1E, 0x24, + /* 0x3e0 */ 0x7A, 0x1F, 0xD7, 0x23, 0xE8, 0xC1, 0x62, 0x3A, + /* 0x3e8 */ 0x76, 0xF9, 0x22, 0x7D, 0x5E, 0x5A, 0xC4, 0x4C, + /* 0x3f0 */ 0x50, 0xCD, 0xAF, 0xDD, 0xEF, 0x6D, 0x36, 0xC0, + /* 0x3f8 */ 0x80, 0x80, 0x1B, 0xA4, 0x3C, 0x70, 0x20, 0xD6, + /* 0x400 */ 0x54, 0x21, 0xD3, 0xBA, 0xEF, 0x14, 0xA9, 0xBF, + /* 0x408 */ 0x07, 0x3F, 0x41, 0x0A, 0x36, 0xB1, 0xA2, 0xB0, + /* 0x410 */ 0x0B, 0x20, 0xD5, 0x1F, 0x67, 0xD0, 0xC3, 0xEB, + /* 0x418 */ 0x88, 0xF6, 0x8A, 0x02, 0xC8, 0xC6, 0x57, 0xB6, + /* 0x420 */ 0x0C, 0xFC, 0x56, 0xF1, 0xD2, 0x3F, 0x17, 0x69, + /* 0x428 */ 0x68, 0x1C, 0xC8, 0xD7, 0x66, 0x3A, 0x86, 0xF1, + /* 0x430 */ 0x19, 0x2A, 0x65, 0x47, 0x68, 0xC6, 0xD2, 0x03, + /* 0x438 */ 0xE7, 0xEF, 0x74, 0x16, 0x0B, 0x06, 0x21, 0xF9, + /* 0x440 */ 0x0C, 0xA6, 0xA8, 0x11, 0x4B, 0x4E, 0x5F, 0xE3, + /* 0x448 */ 0x33, 0xDB, 0x08, 0x41, 0xEA, 0x09, 0x79, 0x75, + /* 0x450 */ 0x78, 0xEE, 0x47, 0xC8, 0x42, 0xD3, 0x81, 0xC5, + /* 0x458 */ 0x65, 0x2D, 0x75, 0xD0, 0x0E, 0x00, 0x16, 0x9D, + /* 0x460 */ 0x1C, 0xEE, 0xB7, 0x58, 0x45, 0x25, 0xE7, 0x33, + /* 0x468 */ 0x63, 0x5B, 0x63, 0x41, 0x09, 0xE8, 0xE9, 0xFE, + /* 0x470 */ 0xAC, 0xFA, 0x73, 0x32, 0x74, 0xB3, 0x76, 0xE9, + /* 0x478 */ 0x6B, 0x94, 0xE2, 0xCD, 0xD4, 0x62, 0xF3, 0xAE, + /* 0x480 */ 0x3A, 0xC5, 0x31, 0x46, 0x52, 0x6E, 0xED, 0x34, + /* 0x488 */ 0x91, 0x1E, 0xA0, 0xC2, 0xDE, 0x54, 0x84, 0xE5, + /* 0x490 */ 0x78, 0x20, 0x56, 0x4C, 0xDD, 0x68, 0xF9, 0x2E, + /* 0x498 */ 0x28, 0x64, 0x1B, 0x1A, 0x99, 0xF2, 0xFB, 0x4D, + /* 0x4a0 */ 0x7F, 0xE3, 0xB8, 0x5F, 0x5D, 0x73, 0x41, 0xEC, + /* 0x4a8 */ 0x79, 0xED, 0x58, 0xD6, 0x7A, 0x37, 0x65, 0x70, + /* 0x4b0 */ 0xA7, 0xB1, 0xBA, 0x39, 0xF6, 0x3E, 0x61, 0x0A, + /* 0x4b8 */ 0xD9, 0xC0, 0x86, 0x90, 0x9A, 0x1A, 0xC8, 0xA8, + /* 0x4c0 */ 0x96, 0x6E, 0x8A, 0x0B, 0x2B, 0x6D, 0xED, 0xD6, + /* 0x4c8 */ 0xFA, 0x07, 0x67, 0xE7, 0x29, 0x04, 0xF7, 0xE2, + /* 0x4d0 */ 0xB2, 0xD1, 0x58, 0x15, 0x52, 0xC7, 0xF1, 0xA3, + /* 0x4d8 */ 0x9D, 0xA6, 0xC0, 0x56, 0x2C, 0xD4, 0x92, 0x98, + /* 0x4e0 */ 0xD8, 0xF1, 0x83, 0xB9, 0x6C, 0x7C, 0x33, 0xA0, + /* 0x4e8 */ 0xE5, 0x4B, 0xAA, 0x90, 0x92, 0xF1, 0xDA, 0x45, + /* 0x4f0 */ 0x4A, 0x34, 0x14, 0xC7, 0x7C, 0x4E, 0xC4, 0xA5, + /* 0x4f8 */ 0x6C, 0x5D, 0x3F, 0xBF, 0xDE, 0xB9, 0xA8, 0x61, + /* 0x500 */ 0x4A, 0x85, 0x20, 0xDE, 0x42, 0x83, 0x29, 0x62, + /* 0x508 */ 0x7C, 0x1C, 0x99, 0x08, 0xA5, 0x46, 0x1F, 0xF4, + /* 0x510 */ 0x6B, 0x22, 0xD3, 0x86, 0x51, 0xCB, 0x37, 0xCD, + /* 0x518 */ 0x60, 0x4A, 0x42, 0x63, 0x56, 0xB3, 0xC8, 0xD1, + /* 0x520 */ 0x8F, 0x31, 0x09, 0x53, 0xC1, 0xE2, 0xDC, 0x1B, + /* 0x528 */ 0xD4, 0xF1, 0x54, 0x77, 0x67, 0xCF, 0x33, 0x7B, + /* 0x530 */ 0x00, 0xD6, 0xD2, 0x7C, 0xDE, 0xC6, 0x79, 0xBF, + /* 0x538 */ 0xCB, 0xE0, 0x16, 0xFD, 0xB2, 0xA1, 0xF2, 0x91, + /* 0x540 */ 0x3C, 0x1D, 0x2D, 0xE8, 0x9C, 0xD4, 0x03, 0xCD, + /* 0x548 */ 0x66, 0x4A, 0xA3, 0x37, 0x93, 0x19, 0x79, 0x7B, + /* 0x550 */ 0xE2, 0x19, 0xC2, 0x16, 0x00, 0xC8, 0xED, 0x0E, + /* 0x558 */ 0x4E, 0x0D, 0xFF, 0x7E, 0xCF, 0x07, 0xA8, 0x64, + /* 0x560 */ 0xCD, 0x29, 0xDF, 0x41, 0xAA, 0x85, 0x30, 0x49, + /* 0x568 */ 0x10, 0x73, 0xA7, 0x4E, 0x89, 0x32, 0x0E, 0x5B, + /* 0x570 */ 0xAD, 0x40, 0x86, 0xC1, 0xB0, 0x94, 0x0C, 0x8D, + /* 0x578 */ 0x26, 0xC5, 0xA7, 0x49, 0xDC, 0x1C, 0xF8, 0x5B, + /* 0x580 */ 0x14, 0x7A, 0x7F, 0x23, 0x69, 0x04, 0xAD, 0xB2, + /* 0x588 */ 0x02, 0x29, 0xD6, 0x12, 0xC8, 0xA4, 0xC6, 0xA1, + /* 0x590 */ 0x2D, +}; +static const lws_ss_x509_t _ss_x509_LEX3_isrg_root_x1 = { + .vhost_name = "LEX3_isrg_root_x1", + .ca_der = _ss_der_LEX3_isrg_root_x1, + .ca_der_len = 1425, +}; +static const lws_ss_trust_store_t _ss_ts_le_via_isrg = { + .name = "le_via_isrg", + .ssx509 = { + &_ss_x509_LEX3_isrg_root_x1, + &_ss_x509_isrg_root_x1, + } +}; + +static const lws_ss_metadata_t _md_mintest_xctype = { + .name = "xctype", + .value = (void *)"X-Content-Type:", + .length = 0, +}, +_md_mintest_ctype = { + .next = (void *)&_md_mintest_xctype, + .name = "ctype", + .value = (void *)"Content-Type:", + .length = 1, +}, +_md_mintest_uptag = { + .next = (void *)&_md_mintest_ctype, + .name = "uptag", + .value = (void *)"X-Upload-Tag:", + .length = 2, +}; + +static const lws_ss_trust_store_t _ss_ts_avs_via_starfield = { + .name = "avs_via_starfield", + .ssx509 = { + &_ss_x509_starfield_services_root_ca, + &_ss_x509_starfield_class_2_ca, + } +}; +static const uint8_t _ss_der_digicert_global_ca_g2[] = { + /* 0x 0 */ 0x30, 0x82, 0x04, 0x8B, 0x30, 0x82, 0x03, 0x73, + /* 0x 8 */ 0xA0, 0x03, 0x02, 0x01, 0x02, 0x02, 0x10, 0x0C, + /* 0x 10 */ 0x8E, 0xE0, 0xC9, 0x0D, 0x6A, 0x89, 0x15, 0x88, + /* 0x 18 */ 0x04, 0x06, 0x1E, 0xE2, 0x41, 0xF9, 0xAF, 0x30, + /* 0x 20 */ 0x0D, 0x06, 0x09, 0x2A, 0x86, 0x48, 0x86, 0xF7, + /* 0x 28 */ 0x0D, 0x01, 0x01, 0x0B, 0x05, 0x00, 0x30, 0x61, + /* 0x 30 */ 0x31, 0x0B, 0x30, 0x09, 0x06, 0x03, 0x55, 0x04, + /* 0x 38 */ 0x06, 0x13, 0x02, 0x55, 0x53, 0x31, 0x15, 0x30, + /* 0x 40 */ 0x13, 0x06, 0x03, 0x55, 0x04, 0x0A, 0x13, 0x0C, + /* 0x 48 */ 0x44, 0x69, 0x67, 0x69, 0x43, 0x65, 0x72, 0x74, + /* 0x 50 */ 0x20, 0x49, 0x6E, 0x63, 0x31, 0x19, 0x30, 0x17, + /* 0x 58 */ 0x06, 0x03, 0x55, 0x04, 0x0B, 0x13, 0x10, 0x77, + /* 0x 60 */ 0x77, 0x77, 0x2E, 0x64, 0x69, 0x67, 0x69, 0x63, + /* 0x 68 */ 0x65, 0x72, 0x74, 0x2E, 0x63, 0x6F, 0x6D, 0x31, + /* 0x 70 */ 0x20, 0x30, 0x1E, 0x06, 0x03, 0x55, 0x04, 0x03, + /* 0x 78 */ 0x13, 0x17, 0x44, 0x69, 0x67, 0x69, 0x43, 0x65, + /* 0x 80 */ 0x72, 0x74, 0x20, 0x47, 0x6C, 0x6F, 0x62, 0x61, + /* 0x 88 */ 0x6C, 0x20, 0x52, 0x6F, 0x6F, 0x74, 0x20, 0x47, + /* 0x 90 */ 0x32, 0x30, 0x1E, 0x17, 0x0D, 0x31, 0x33, 0x30, + /* 0x 98 */ 0x38, 0x30, 0x31, 0x31, 0x32, 0x30, 0x30, 0x30, + /* 0x a0 */ 0x30, 0x5A, 0x17, 0x0D, 0x32, 0x38, 0x30, 0x38, + /* 0x a8 */ 0x30, 0x31, 0x31, 0x32, 0x30, 0x30, 0x30, 0x30, + /* 0x b0 */ 0x5A, 0x30, 0x44, 0x31, 0x0B, 0x30, 0x09, 0x06, + /* 0x b8 */ 0x03, 0x55, 0x04, 0x06, 0x13, 0x02, 0x55, 0x53, + /* 0x c0 */ 0x31, 0x15, 0x30, 0x13, 0x06, 0x03, 0x55, 0x04, + /* 0x c8 */ 0x0A, 0x13, 0x0C, 0x44, 0x69, 0x67, 0x69, 0x43, + /* 0x d0 */ 0x65, 0x72, 0x74, 0x20, 0x49, 0x6E, 0x63, 0x31, + /* 0x d8 */ 0x1E, 0x30, 0x1C, 0x06, 0x03, 0x55, 0x04, 0x03, + /* 0x e0 */ 0x13, 0x15, 0x44, 0x69, 0x67, 0x69, 0x43, 0x65, + /* 0x e8 */ 0x72, 0x74, 0x20, 0x47, 0x6C, 0x6F, 0x62, 0x61, + /* 0x f0 */ 0x6C, 0x20, 0x43, 0x41, 0x20, 0x47, 0x32, 0x30, + /* 0x f8 */ 0x82, 0x01, 0x22, 0x30, 0x0D, 0x06, 0x09, 0x2A, + /* 0x100 */ 0x86, 0x48, 0x86, 0xF7, 0x0D, 0x01, 0x01, 0x01, + /* 0x108 */ 0x05, 0x00, 0x03, 0x82, 0x01, 0x0F, 0x00, 0x30, + /* 0x110 */ 0x82, 0x01, 0x0A, 0x02, 0x82, 0x01, 0x01, 0x00, + /* 0x118 */ 0xD3, 0x48, 0x7C, 0xBE, 0xF3, 0x05, 0x86, 0x5D, + /* 0x120 */ 0x5B, 0xD5, 0x2F, 0x85, 0x4E, 0x4B, 0xE0, 0x86, + /* 0x128 */ 0xAD, 0x15, 0xAC, 0x61, 0xCF, 0x5B, 0xAF, 0x3E, + /* 0x130 */ 0x6A, 0x0A, 0x47, 0xFB, 0x9A, 0x76, 0x91, 0x60, + /* 0x138 */ 0x0B, 0x8A, 0x6B, 0xCD, 0xCF, 0xDC, 0x57, 0x7E, + /* 0x140 */ 0x60, 0x98, 0x0B, 0xE4, 0x54, 0xD9, 0x56, 0xED, + /* 0x148 */ 0x21, 0xCC, 0x02, 0xB6, 0x5A, 0x81, 0x5F, 0x97, + /* 0x150 */ 0x6A, 0xEE, 0x02, 0x2F, 0x23, 0x27, 0xB8, 0x6D, + /* 0x158 */ 0xD4, 0xB0, 0xE7, 0x06, 0x02, 0x78, 0x0B, 0x1F, + /* 0x160 */ 0x5C, 0xA9, 0x99, 0x36, 0xFE, 0xBB, 0xAC, 0x1B, + /* 0x168 */ 0x05, 0xFA, 0x57, 0xCD, 0x81, 0x10, 0x40, 0x67, + /* 0x170 */ 0xD6, 0x30, 0x8B, 0x58, 0x35, 0xD4, 0x96, 0x61, + /* 0x178 */ 0xBE, 0xD0, 0x8C, 0x7A, 0x97, 0x9F, 0x1A, 0xF9, + /* 0x180 */ 0x22, 0xE6, 0x14, 0x2F, 0xA9, 0xC6, 0xE8, 0x01, + /* 0x188 */ 0x1F, 0xAB, 0xF8, 0x26, 0x0F, 0xAC, 0x8E, 0x4D, + /* 0x190 */ 0x2C, 0x32, 0x39, 0x1D, 0x81, 0x9B, 0x8D, 0x1C, + /* 0x198 */ 0x65, 0xB2, 0x1C, 0xDB, 0x61, 0xA8, 0x89, 0x2F, + /* 0x1a0 */ 0x60, 0xE7, 0xEB, 0xC2, 0x4A, 0x18, 0xC4, 0x6F, + /* 0x1a8 */ 0x2A, 0xE9, 0x10, 0x92, 0x09, 0xED, 0x17, 0xD1, + /* 0x1b0 */ 0x00, 0x2B, 0xE6, 0x7D, 0xEF, 0x04, 0x89, 0x14, + /* 0x1b8 */ 0x4E, 0x33, 0xA1, 0xB2, 0x0F, 0x97, 0x87, 0x9F, + /* 0x1c0 */ 0xB3, 0xA0, 0xCD, 0x2F, 0xBC, 0x2C, 0xEC, 0xB8, + /* 0x1c8 */ 0x83, 0x68, 0x31, 0x3D, 0x1F, 0xD5, 0x4A, 0x90, + /* 0x1d0 */ 0x10, 0x19, 0x0B, 0x81, 0x95, 0xD6, 0x29, 0x76, + /* 0x1d8 */ 0x51, 0xF9, 0x36, 0x76, 0xD0, 0xB7, 0x09, 0x7A, + /* 0x1e0 */ 0x38, 0x4A, 0xD7, 0x6F, 0x8C, 0xBF, 0x13, 0x7C, + /* 0x1e8 */ 0x39, 0xED, 0xBA, 0xAE, 0x90, 0xFC, 0x95, 0xF7, + /* 0x1f0 */ 0x7B, 0x78, 0x09, 0x36, 0x5E, 0x74, 0x93, 0x1E, + /* 0x1f8 */ 0x25, 0xF0, 0xFF, 0xD4, 0xAD, 0xAE, 0x68, 0x6B, + /* 0x200 */ 0xC6, 0xFF, 0x0F, 0xD5, 0x35, 0xF1, 0x55, 0x6E, + /* 0x208 */ 0x48, 0x49, 0xF8, 0xF8, 0xB8, 0xEF, 0x88, 0xF8, + /* 0x210 */ 0xF1, 0x5E, 0x11, 0x77, 0xAA, 0xDF, 0x02, 0xB3, + /* 0x218 */ 0x02, 0x03, 0x01, 0x00, 0x01, 0xA3, 0x82, 0x01, + /* 0x220 */ 0x5A, 0x30, 0x82, 0x01, 0x56, 0x30, 0x12, 0x06, + /* 0x228 */ 0x03, 0x55, 0x1D, 0x13, 0x01, 0x01, 0xFF, 0x04, + /* 0x230 */ 0x08, 0x30, 0x06, 0x01, 0x01, 0xFF, 0x02, 0x01, + /* 0x238 */ 0x00, 0x30, 0x0E, 0x06, 0x03, 0x55, 0x1D, 0x0F, + /* 0x240 */ 0x01, 0x01, 0xFF, 0x04, 0x04, 0x03, 0x02, 0x01, + /* 0x248 */ 0x86, 0x30, 0x34, 0x06, 0x08, 0x2B, 0x06, 0x01, + /* 0x250 */ 0x05, 0x05, 0x07, 0x01, 0x01, 0x04, 0x28, 0x30, + /* 0x258 */ 0x26, 0x30, 0x24, 0x06, 0x08, 0x2B, 0x06, 0x01, + /* 0x260 */ 0x05, 0x05, 0x07, 0x30, 0x01, 0x86, 0x18, 0x68, + /* 0x268 */ 0x74, 0x74, 0x70, 0x3A, 0x2F, 0x2F, 0x6F, 0x63, + /* 0x270 */ 0x73, 0x70, 0x2E, 0x64, 0x69, 0x67, 0x69, 0x63, + /* 0x278 */ 0x65, 0x72, 0x74, 0x2E, 0x63, 0x6F, 0x6D, 0x30, + /* 0x280 */ 0x7B, 0x06, 0x03, 0x55, 0x1D, 0x1F, 0x04, 0x74, + /* 0x288 */ 0x30, 0x72, 0x30, 0x37, 0xA0, 0x35, 0xA0, 0x33, + /* 0x290 */ 0x86, 0x31, 0x68, 0x74, 0x74, 0x70, 0x3A, 0x2F, + /* 0x298 */ 0x2F, 0x63, 0x72, 0x6C, 0x34, 0x2E, 0x64, 0x69, + /* 0x2a0 */ 0x67, 0x69, 0x63, 0x65, 0x72, 0x74, 0x2E, 0x63, + /* 0x2a8 */ 0x6F, 0x6D, 0x2F, 0x44, 0x69, 0x67, 0x69, 0x43, + /* 0x2b0 */ 0x65, 0x72, 0x74, 0x47, 0x6C, 0x6F, 0x62, 0x61, + /* 0x2b8 */ 0x6C, 0x52, 0x6F, 0x6F, 0x74, 0x47, 0x32, 0x2E, + /* 0x2c0 */ 0x63, 0x72, 0x6C, 0x30, 0x37, 0xA0, 0x35, 0xA0, + /* 0x2c8 */ 0x33, 0x86, 0x31, 0x68, 0x74, 0x74, 0x70, 0x3A, + /* 0x2d0 */ 0x2F, 0x2F, 0x63, 0x72, 0x6C, 0x33, 0x2E, 0x64, + /* 0x2d8 */ 0x69, 0x67, 0x69, 0x63, 0x65, 0x72, 0x74, 0x2E, + /* 0x2e0 */ 0x63, 0x6F, 0x6D, 0x2F, 0x44, 0x69, 0x67, 0x69, + /* 0x2e8 */ 0x43, 0x65, 0x72, 0x74, 0x47, 0x6C, 0x6F, 0x62, + /* 0x2f0 */ 0x61, 0x6C, 0x52, 0x6F, 0x6F, 0x74, 0x47, 0x32, + /* 0x2f8 */ 0x2E, 0x63, 0x72, 0x6C, 0x30, 0x3D, 0x06, 0x03, + /* 0x300 */ 0x55, 0x1D, 0x20, 0x04, 0x36, 0x30, 0x34, 0x30, + /* 0x308 */ 0x32, 0x06, 0x04, 0x55, 0x1D, 0x20, 0x00, 0x30, + /* 0x310 */ 0x2A, 0x30, 0x28, 0x06, 0x08, 0x2B, 0x06, 0x01, + /* 0x318 */ 0x05, 0x05, 0x07, 0x02, 0x01, 0x16, 0x1C, 0x68, + /* 0x320 */ 0x74, 0x74, 0x70, 0x73, 0x3A, 0x2F, 0x2F, 0x77, + /* 0x328 */ 0x77, 0x77, 0x2E, 0x64, 0x69, 0x67, 0x69, 0x63, + /* 0x330 */ 0x65, 0x72, 0x74, 0x2E, 0x63, 0x6F, 0x6D, 0x2F, + /* 0x338 */ 0x43, 0x50, 0x53, 0x30, 0x1D, 0x06, 0x03, 0x55, + /* 0x340 */ 0x1D, 0x0E, 0x04, 0x16, 0x04, 0x14, 0x24, 0x6E, + /* 0x348 */ 0x2B, 0x2D, 0xD0, 0x6A, 0x92, 0x51, 0x51, 0x25, + /* 0x350 */ 0x69, 0x01, 0xAA, 0x9A, 0x47, 0xA6, 0x89, 0xE7, + /* 0x358 */ 0x40, 0x20, 0x30, 0x1F, 0x06, 0x03, 0x55, 0x1D, + /* 0x360 */ 0x23, 0x04, 0x18, 0x30, 0x16, 0x80, 0x14, 0x4E, + /* 0x368 */ 0x22, 0x54, 0x20, 0x18, 0x95, 0xE6, 0xE3, 0x6E, + /* 0x370 */ 0xE6, 0x0F, 0xFA, 0xFA, 0xB9, 0x12, 0xED, 0x06, + /* 0x378 */ 0x17, 0x8F, 0x39, 0x30, 0x0D, 0x06, 0x09, 0x2A, + /* 0x380 */ 0x86, 0x48, 0x86, 0xF7, 0x0D, 0x01, 0x01, 0x0B, + /* 0x388 */ 0x05, 0x00, 0x03, 0x82, 0x01, 0x01, 0x00, 0x0B, + /* 0x390 */ 0x39, 0x84, 0x91, 0xF9, 0x97, 0xEB, 0xAA, 0x81, + /* 0x398 */ 0xAF, 0x84, 0xE9, 0x5A, 0x38, 0x92, 0xFC, 0xE2, + /* 0x3a0 */ 0x6C, 0x59, 0xBF, 0x36, 0xC8, 0x45, 0xA7, 0x31, + /* 0x3a8 */ 0x03, 0x11, 0xE1, 0x06, 0xC0, 0xAC, 0x32, 0xC7, + /* 0x3b0 */ 0x5A, 0x55, 0x29, 0xDA, 0x4F, 0x40, 0x02, 0xF5, + /* 0x3b8 */ 0xA1, 0xDE, 0xB0, 0xED, 0xDE, 0xC0, 0xF8, 0xF6, + /* 0x3c0 */ 0x75, 0x9D, 0x76, 0xB9, 0x87, 0xFE, 0x41, 0x80, + /* 0x3c8 */ 0x7A, 0xCF, 0x5D, 0xE3, 0x00, 0xC6, 0x5B, 0x02, + /* 0x3d0 */ 0xE6, 0x9B, 0x78, 0x62, 0xC9, 0xDC, 0xB8, 0x62, + /* 0x3d8 */ 0x9A, 0x77, 0xED, 0x89, 0x08, 0xD7, 0x4B, 0xC5, + /* 0x3e0 */ 0xFD, 0x43, 0xD5, 0x62, 0x23, 0x27, 0xC4, 0x04, + /* 0x3e8 */ 0x59, 0x6D, 0x71, 0x3F, 0x23, 0x5B, 0xEA, 0xD9, + /* 0x3f0 */ 0xF2, 0xE7, 0x24, 0x27, 0x6F, 0xF4, 0x95, 0x80, + /* 0x3f8 */ 0xDB, 0x96, 0x2C, 0xE4, 0x54, 0x8B, 0xCF, 0xEA, + /* 0x400 */ 0x19, 0xD9, 0x7F, 0x55, 0x99, 0x51, 0x7A, 0x0E, + /* 0x408 */ 0x2D, 0x18, 0x3D, 0x78, 0x58, 0x52, 0xBC, 0x63, + /* 0x410 */ 0x68, 0x57, 0x0B, 0xDD, 0x44, 0xB3, 0x57, 0x4A, + /* 0x418 */ 0x60, 0xE6, 0xC8, 0x70, 0x70, 0x5B, 0x87, 0x28, + /* 0x420 */ 0x6A, 0xD7, 0x3B, 0x4E, 0x52, 0x45, 0x19, 0xAF, + /* 0x428 */ 0x24, 0x06, 0x92, 0x48, 0x11, 0x1A, 0x8B, 0xAE, + /* 0x430 */ 0xAC, 0x18, 0x12, 0x57, 0xAC, 0x03, 0xCB, 0xB8, + /* 0x438 */ 0xF4, 0xBD, 0xCA, 0x26, 0x0E, 0xA7, 0xC1, 0xDD, + /* 0x440 */ 0xE3, 0x33, 0xEF, 0xC0, 0x55, 0x30, 0x0D, 0x95, + /* 0x448 */ 0x59, 0x4E, 0x9C, 0x03, 0x36, 0x06, 0xF8, 0xC0, + /* 0x450 */ 0x8F, 0x14, 0x99, 0x9C, 0x4D, 0x2A, 0x9E, 0xC1, + /* 0x458 */ 0xE1, 0x7D, 0x3B, 0xAF, 0x72, 0xA7, 0x45, 0xBA, + /* 0x460 */ 0x13, 0x96, 0x29, 0x4E, 0x19, 0xD0, 0x1A, 0x98, + /* 0x468 */ 0x06, 0xF4, 0x37, 0x94, 0x17, 0xAD, 0xA3, 0x18, + /* 0x470 */ 0xBA, 0x3E, 0xB0, 0x01, 0x0C, 0x95, 0xD6, 0x29, + /* 0x478 */ 0x35, 0x20, 0x35, 0x7D, 0xF5, 0x10, 0x60, 0xE4, + /* 0x480 */ 0xF7, 0x68, 0x62, 0x1E, 0xEC, 0x19, 0xE1, 0x24, + /* 0x488 */ 0xF2, 0x87, 0x11, 0xAC, 0xE9, 0x08, 0x80, +}; +static const lws_ss_x509_t _ss_x509_digicert_global_ca_g2 = { + .vhost_name = "digicert_global_ca_g2", + .ca_der = _ss_der_digicert_global_ca_g2, + .ca_der_len = 1167, +}; +static const uint8_t _ss_der_digicert_global_root_g2[] = { + /* 0x 0 */ 0x30, 0x82, 0x03, 0x8E, 0x30, 0x82, 0x02, 0x76, + /* 0x 8 */ 0xA0, 0x03, 0x02, 0x01, 0x02, 0x02, 0x10, 0x03, + /* 0x 10 */ 0x3A, 0xF1, 0xE6, 0xA7, 0x11, 0xA9, 0xA0, 0xBB, + /* 0x 18 */ 0x28, 0x64, 0xB1, 0x1D, 0x09, 0xFA, 0xE5, 0x30, + /* 0x 20 */ 0x0D, 0x06, 0x09, 0x2A, 0x86, 0x48, 0x86, 0xF7, + /* 0x 28 */ 0x0D, 0x01, 0x01, 0x0B, 0x05, 0x00, 0x30, 0x61, + /* 0x 30 */ 0x31, 0x0B, 0x30, 0x09, 0x06, 0x03, 0x55, 0x04, + /* 0x 38 */ 0x06, 0x13, 0x02, 0x55, 0x53, 0x31, 0x15, 0x30, + /* 0x 40 */ 0x13, 0x06, 0x03, 0x55, 0x04, 0x0A, 0x13, 0x0C, + /* 0x 48 */ 0x44, 0x69, 0x67, 0x69, 0x43, 0x65, 0x72, 0x74, + /* 0x 50 */ 0x20, 0x49, 0x6E, 0x63, 0x31, 0x19, 0x30, 0x17, + /* 0x 58 */ 0x06, 0x03, 0x55, 0x04, 0x0B, 0x13, 0x10, 0x77, + /* 0x 60 */ 0x77, 0x77, 0x2E, 0x64, 0x69, 0x67, 0x69, 0x63, + /* 0x 68 */ 0x65, 0x72, 0x74, 0x2E, 0x63, 0x6F, 0x6D, 0x31, + /* 0x 70 */ 0x20, 0x30, 0x1E, 0x06, 0x03, 0x55, 0x04, 0x03, + /* 0x 78 */ 0x13, 0x17, 0x44, 0x69, 0x67, 0x69, 0x43, 0x65, + /* 0x 80 */ 0x72, 0x74, 0x20, 0x47, 0x6C, 0x6F, 0x62, 0x61, + /* 0x 88 */ 0x6C, 0x20, 0x52, 0x6F, 0x6F, 0x74, 0x20, 0x47, + /* 0x 90 */ 0x32, 0x30, 0x1E, 0x17, 0x0D, 0x31, 0x33, 0x30, + /* 0x 98 */ 0x38, 0x30, 0x31, 0x31, 0x32, 0x30, 0x30, 0x30, + /* 0x a0 */ 0x30, 0x5A, 0x17, 0x0D, 0x33, 0x38, 0x30, 0x31, + /* 0x a8 */ 0x31, 0x35, 0x31, 0x32, 0x30, 0x30, 0x30, 0x30, + /* 0x b0 */ 0x5A, 0x30, 0x61, 0x31, 0x0B, 0x30, 0x09, 0x06, + /* 0x b8 */ 0x03, 0x55, 0x04, 0x06, 0x13, 0x02, 0x55, 0x53, + /* 0x c0 */ 0x31, 0x15, 0x30, 0x13, 0x06, 0x03, 0x55, 0x04, + /* 0x c8 */ 0x0A, 0x13, 0x0C, 0x44, 0x69, 0x67, 0x69, 0x43, + /* 0x d0 */ 0x65, 0x72, 0x74, 0x20, 0x49, 0x6E, 0x63, 0x31, + /* 0x d8 */ 0x19, 0x30, 0x17, 0x06, 0x03, 0x55, 0x04, 0x0B, + /* 0x e0 */ 0x13, 0x10, 0x77, 0x77, 0x77, 0x2E, 0x64, 0x69, + /* 0x e8 */ 0x67, 0x69, 0x63, 0x65, 0x72, 0x74, 0x2E, 0x63, + /* 0x f0 */ 0x6F, 0x6D, 0x31, 0x20, 0x30, 0x1E, 0x06, 0x03, + /* 0x f8 */ 0x55, 0x04, 0x03, 0x13, 0x17, 0x44, 0x69, 0x67, + /* 0x100 */ 0x69, 0x43, 0x65, 0x72, 0x74, 0x20, 0x47, 0x6C, + /* 0x108 */ 0x6F, 0x62, 0x61, 0x6C, 0x20, 0x52, 0x6F, 0x6F, + /* 0x110 */ 0x74, 0x20, 0x47, 0x32, 0x30, 0x82, 0x01, 0x22, + /* 0x118 */ 0x30, 0x0D, 0x06, 0x09, 0x2A, 0x86, 0x48, 0x86, + /* 0x120 */ 0xF7, 0x0D, 0x01, 0x01, 0x01, 0x05, 0x00, 0x03, + /* 0x128 */ 0x82, 0x01, 0x0F, 0x00, 0x30, 0x82, 0x01, 0x0A, + /* 0x130 */ 0x02, 0x82, 0x01, 0x01, 0x00, 0xBB, 0x37, 0xCD, + /* 0x138 */ 0x34, 0xDC, 0x7B, 0x6B, 0xC9, 0xB2, 0x68, 0x90, + /* 0x140 */ 0xAD, 0x4A, 0x75, 0xFF, 0x46, 0xBA, 0x21, 0x0A, + /* 0x148 */ 0x08, 0x8D, 0xF5, 0x19, 0x54, 0xC9, 0xFB, 0x88, + /* 0x150 */ 0xDB, 0xF3, 0xAE, 0xF2, 0x3A, 0x89, 0x91, 0x3C, + /* 0x158 */ 0x7A, 0xE6, 0xAB, 0x06, 0x1A, 0x6B, 0xCF, 0xAC, + /* 0x160 */ 0x2D, 0xE8, 0x5E, 0x09, 0x24, 0x44, 0xBA, 0x62, + /* 0x168 */ 0x9A, 0x7E, 0xD6, 0xA3, 0xA8, 0x7E, 0xE0, 0x54, + /* 0x170 */ 0x75, 0x20, 0x05, 0xAC, 0x50, 0xB7, 0x9C,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/* 0x208 */ 0xA1, 0xE6, 0x21, 0xCA, 0xFD, 0x83, 0xE5, 0x10, + /* 0x210 */ 0xBC, 0x83, 0xA5, 0x0A, 0xC4, 0x67, 0x28, 0xF6, + /* 0x218 */ 0x73, 0x14, 0x14, 0x3D, 0x46, 0x76, 0xC3, 0x87, + /* 0x220 */ 0x14, 0x89, 0x21, 0x34, 0x4D, 0xAF, 0x0F, 0x45, + /* 0x228 */ 0x0C, 0xA6, 0x49, 0xA1, 0xBA, 0xBB, 0x9C, 0xC5, + /* 0x230 */ 0xB1, 0x33, 0x83, 0x29, 0x85, 0x02, 0x03, 0x01, + /* 0x238 */ 0x00, 0x01, 0xA3, 0x42, 0x30, 0x40, 0x30, 0x0F, + /* 0x240 */ 0x06, 0x03, 0x55, 0x1D, 0x13, 0x01, 0x01, 0xFF, + /* 0x248 */ 0x04, 0x05, 0x30, 0x03, 0x01, 0x01, 0xFF, 0x30, + /* 0x250 */ 0x0E, 0x06, 0x03, 0x55, 0x1D, 0x0F, 0x01, 0x01, + /* 0x258 */ 0xFF, 0x04, 0x04, 0x03, 0x02, 0x01, 0x86, 0x30, + /* 0x260 */ 0x1D, 0x06, 0x03, 0x55, 0x1D, 0x0E, 0x04, 0x16, + /* 0x268 */ 0x04, 0x14, 0x4E, 0x22, 0x54, 0x20, 0x18, 0x95, + /* 0x270 */ 0xE6, 0xE3, 0x6E, 0xE6, 0x0F, 0xFA, 0xFA, 0xB9, + /* 0x278 */ 0x12, 0xED, 0x06, 0x17, 0x8F, 0x39, 0x30, 0x0D, + /* 0x280 */ 0x06, 0x09, 0x2A, 0x86, 0x48, 0x86, 0xF7, 0x0D, + /* 0x288 */ 0x01, 0x01, 0x0B, 0x05, 0x00, 0x03, 0x82, 0x01, + /* 0x290 */ 0x01, 0x00, 0x60, 0x67, 0x28, 0x94, 0x6F, 0x0E, + /* 0x298 */ 0x48, 0x63, 0xEB, 0x31, 0xDD, 0xEA, 0x67, 0x18, + /* 0x2a0 */ 0xD5, 0x89, 0x7D, 0x3C, 0xC5, 0x8B, 0x4A, 0x7F, + /* 0x2a8 */ 0xE9, 0xBE, 0xDB, 0x2B, 0x17, 0xDF, 0xB0, 0x5F, + /* 0x2b0 */ 0x73, 0x77, 0x2A, 0x32, 0x13, 0x39, 0x81, 0x67, + /* 0x2b8 */ 0x42, 0x84, 0x23, 0xF2, 0x45, 0x67, 0x35, 0xEC, + /* 0x2c0 */ 0x88, 0xBF, 0xF8, 0x8F, 0xB0, 0x61, 0x0C, 0x34, + /* 0x2c8 */ 0xA4, 0xAE, 0x20, 0x4C, 0x84, 0xC6, 0xDB, 0xF8, + /* 0x2d0 */ 0x35, 0xE1, 0x76, 0xD9, 0xDF, 0xA6, 0x42, 0xBB, + /* 0x2d8 */ 0xC7, 0x44, 0x08, 0x86, 0x7F, 0x36, 0x74, 0x24, + /* 0x2e0 */ 0x5A, 0xDA, 0x6C, 0x0D, 0x14, 0x59, 0x35, 0xBD, + /* 0x2e8 */ 0xF2, 0x49, 0xDD, 0xB6, 0x1F, 0xC9, 0xB3, 0x0D, + /* 0x2f0 */ 0x47, 0x2A, 0x3D, 0x99, 0x2F, 0xBB, 0x5C, 0xBB, + /* 0x2f8 */ 0xB5, 0xD4, 0x20, 0xE1, 0x99, 0x5F, 0x53, 0x46, + /* 0x300 */ 0x15, 0xDB, 0x68, 0x9B, 0xF0, 0xF3, 0x30, 0xD5, + /* 0x308 */ 0x3E, 0x31, 0xE2, 0x8D, 0x84, 0x9E, 0xE3, 0x8A, + /* 0x310 */ 0xDA, 0xDA, 0x96, 0x3E, 0x35, 0x13, 0xA5, 0x5F, + /* 0x318 */ 0xF0, 0xF9, 0x70, 0x50, 0x70, 0x47, 0x41, 0x11, + /* 0x320 */ 0x57, 0x19, 0x4E, 0xC0, 0x8F, 0xAE, 0x06, 0xC4, + /* 0x328 */ 0x95, 0x13, 0x17, 0x2F, 0x1B, 0x25, 0x9F, 0x75, + /* 0x330 */ 0xF2, 0xB1, 0x8E, 0x99, 0xA1, 0x6F, 0x13, 0xB1, + /* 0x338 */ 0x41, 0x71, 0xFE, 0x88, 0x2A, 0xC8, 0x4F, 0x10, + /* 0x340 */ 0x20, 0x55, 0xD7, 0xF3, 0x14, 0x45, 0xE5, 0xE0, + /* 0x348 */ 0x44, 0xF4, 0xEA, 0x87, 0x95, 0x32, 0x93, 0x0E, + /* 0x350 */ 0xFE, 0x53, 0x46, 0xFA, 0x2C, 0x9D, 0xFF, 0x8B, + /* 0x358 */ 0x22, 0xB9, 0x4B, 0xD9, 0x09, 0x45, 0xA4, 0xDE, + /* 0x360 */ 0xA4, 0xB8, 0x9A, 0x58, 0xDD, 0x1B, 0x7D, 0x52, + /* 0x368 */ 0x9F, 0x8E, 0x59, 0x43, 0x88, 0x81, 0xA4, 0x9E, + /* 0x370 */ 0x26, 0xD5, 0x6F, 0xAD, 0xDD, 0x0D, 0xC6, 0x37, + /* 0x378 */ 0x7D, 0xED, 0x03, 0x92, 0x1B, 0xE5, 0x77, 0x5F, + /* 0x380 */ 0x76, 0xEE, 0x3C, 0x8D, 0xC4, 0x5D, 0x56, 0x5B, + /* 0x388 */ 0xA2, 0xD9, 0x66, 0x6E, 0xB3, 0x35, 0x37, 0xE5, + /* 0x390 */ 0x32, 0xB6, +}; +static const lws_ss_x509_t _ss_x509_digicert_global_root_g2 = { + .vhost_name = "digicert_global_root_g2", + .ca_der = _ss_der_digicert_global_root_g2, + .ca_der_len = 914, +}; +static const lws_ss_trust_store_t _ss_ts_api_amazon_com = { + .name = "api_amazon_com", + .ssx509 = { + &_ss_x509_digicert_global_root_g2, + &_ss_x509_digicert_global_ca_g2, + } +}; + +static const lws_ss_policy_t _ssp_captive_portal_detect = { + .streamtype = "captive_portal_detect", + .endpoint = "connectivitycheck.android.com", + .u = { + .http = { + .method = "GET", + .url = "generate_204", + .resp_expect = 204, + .fail_redirect = 1, + } + }, + .flags = 0x1, + .port = 80, + .protocol = 0, +}, +_ssp_mqtt_test1 = { + .next = (void *)&_ssp_captive_portal_detect, + .streamtype = "mqtt_test1", + .endpoint = "a1ygonr3im5cv2-ats.iot.us-west-2.amazonaws.com", + .u = { + .mqtt = { + .topic = "test/topic1", + .subscribe = "test/topic1", + .qos = 1, + } + }, + .retry_bo = &_rbo_0, + .flags = 0x10, + .port = 443, + .protocol = 3, + .client_cert = 1, + .trust = {.store = &_ss_ts_mqtt_amz_iot}, +}, +_ssp_mqtt_test = { + .next = (void *)&_ssp_mqtt_test1, + .streamtype = "mqtt_test", + .endpoint = "a1ygonr3im5cv2-ats.iot.us-west-2.amazonaws.com", + .u = { + .mqtt = { + .topic = "test/topic0", + .subscribe = "test/topic0", + } + }, + .retry_bo = &_rbo_0, + .flags = 0x10, + .port = 443, + .protocol = 3, + .client_cert = 1, + .trust = {.store = &_ss_ts_mqtt_amz_iot}, +}, +_ssp_minpost = { + .next = (void *)&_ssp_mqtt_test, + .streamtype = "minpost", + .endpoint = "warmcat.com", + .u = { + .http = { + .method = "POST", + .url = "testserver/formtest", + } + }, + .retry_bo = &_rbo_0, + .flags = 0x11, + .port = 443, + .protocol = 0, + .trust = {.store = &_ss_ts_le_via_isrg}, +}, +_ssp_mintest_fail = { + .next = (void *)&_ssp_minpost, + .streamtype = "mintest-fail", + .endpoint = "warmcat.com", + .u = { + .http = { + .method = "GET", + .url = "index.html", + } + }, + .retry_bo = &_rbo_0, + .flags = 0x11, + .port = 22, + .protocol = 0, + .trust = {.store = &_ss_ts_le_via_isrg}, +}, +_ssp_h2longpolltest = { + .next = (void *)&_ssp_mintest_fail, + .streamtype = "h2longpolltest", + .endpoint = "warmcat.com", + .u = { + .http = { + .method = "GET", + .url = "index.html", + } + }, + .retry_bo = &_rbo_0, + .flags = 0x32, + .port = 443, + .protocol = 1, + .trust = {.store = &_ss_ts_le_via_isrg}, +}, +_ssp_mintest = { + .next = (void *)&_ssp_h2longpolltest, + .streamtype = "mintest", + .endpoint = "warmcat.com", + .metadata = (void *)&_md_mintest_uptag, + .u = { + .http = { + .method = "GET", + .url = "index.html?uptag=${uptag}", + } + }, + .retry_bo = &_rbo_0, + .flags = 0x11, + .port = 443, + .metadata_count = 3, + .protocol = 0, + .trust = {.store = &_ss_ts_le_via_isrg}, +}, +_ssp_avs_audio = { + .next = (void *)&_ssp_mintest, + .streamtype = "avs_audio", + .endpoint = "alexa.na.gateway.devices.a2z.com", + .u = { + .http = { + .method = "POST", + .url = "v20160207/events", + .multipart_name = "audio", + .multipart_content_type = "application/octet-stream", + .auth_preamble = "Bearer ", + .blob_header = { + "authorization:", + }, + } + }, + .retry_bo = &_rbo_0, + .flags = 0xa90, + .port = 443, + .protocol = 1, + .trust = {.store = &_ss_ts_avs_via_starfield}, +}, +_ssp_avs_metadata = { + .next = (void *)&_ssp_avs_audio, + .streamtype = "avs_metadata", + .endpoint = "alexa.na.gateway.devices.a2z.com", + .rideshare_streamtype = "avs_audio", + .u = { + .http = { + .method = "POST", + .url = "v20160207/events", + .multipart_name = "metadata", + .multipart_content_type = "application/json; charset=UTF-8", + .auth_preamble = "Bearer ", + .blob_header = { + "authorization:", + }, + } + }, + .retry_bo = &_rbo_0, + .flags = 0xa91, + .port = 443, + .protocol = 1, + .trust = {.store = &_ss_ts_avs_via_starfield}, +}, +_ssp_avs_event = { + .next = (void *)&_ssp_avs_metadata, + .streamtype = "avs_event", + .endpoint = "alexa.na.gateway.devices.a2z.com", + .u = { + .http = { + .method = "GET", + .url = "v20160207/directives", + .auth_preamble = "Bearer ", + .blob_header = { + "authorization:", + }, + } + }, + .retry_bo = &_rbo_0, + .flags = 0x2b2, + .port = 443, + .protocol = 1, + .trust = {.store = &_ss_ts_avs_via_starfield}, +}, +_ssp_api_amazon_com_auth = { + .next = (void *)&_ssp_avs_event, + .streamtype = "api_amazon_com_auth", + .endpoint = "api.amazon.com", + .u = { + .http = { + .method = "POST", + .url = "auth/o2/token", + } + }, + .retry_bo = &_rbo_0, + .flags = 0x1291, + .port = 443, + .protocol = 0, + .trust = {.store = &_ss_ts_api_amazon_com}, +}; +#define _ss_static_policy_entry _ssp_api_amazon_com_auth +/* estimated footprint 10720 (when sizeof void * = 8) */ diff -Nru libwebsockets-3.2.1/minimal-examples/secure-streams/minimal-secure-streams-staticpolicy/static-policy.json libwebsockets-4.1.6/minimal-examples/secure-streams/minimal-secure-streams-staticpolicy/static-policy.json --- libwebsockets-3.2.1/minimal-examples/secure-streams/minimal-secure-streams-staticpolicy/static-policy.json 1970-01-01 00:00:00.000000000 +0000 +++ libwebsockets-4.1.6/minimal-examples/secure-streams/minimal-secure-streams-staticpolicy/static-policy.json 2020-12-01 17:40:26.000000000 +0000 @@ -0,0 +1,218 @@ +{ + "release": "01234567", + "product": "myproduct", + "schema-version": 1, + "retry": [{ + "default": { + "backoff": [1000, 2000, 3000, 5000, 10000], + "conceal": 5, + "jitterpc": 20, + "svalidping": 30, + "svalidhup": 35 + } + }], + "certs": [{ + "isrg_root_x1": "MIIFazCCA1OgAwIBAgIRAIIQz7DSQONZRGPgu2OCiwAwDQYJKoZIhvcNAQELBQAwTzELMAkGA1UEBhMCVVMxKTAnBgNVBAoTIEludGVybmV0IFNlY3VyaXR5IFJlc2VhcmNoIEdyb3VwMRUwEwYDVQQDEwxJU1JHIFJvb3QgWDEwHhcNMTUwNjA0MTEwNDM4WhcNMzUwNjA0MTEwNDM4WjBPMQswCQYDVQQGEwJVUzEpMCcGA1UEChMgSW50ZXJuZXQgU2VjdXJpdHkgUmVzZWFyY2ggR3JvdXAxFTATBgNVBAMTDElTUkcgUm9vdCBYMTCCAiIwDQYJKoZIhvcNAQEBBQADggIPADCCAgoCggIBAK3oJHP0FDfzm54rVygch77ct984kIxuPOZXoHj3dcKi/vVqbvYATyjb3miGbESTtrFj/RQSa78f0uoxmyF+0TM8ukj13Xnfs7j/EvEhmkvBioZxaUpmZmyPfjxwv60pIgbz5MDmgK7iS4+3mX6UA5/TR5d8mUgjU+g4rk8Kb4Mu0UlXjIB0ttov0DiNewNwIRt18jA8+o+u3dpjq+sWT8KOEUt+zwvo/7V3LvSye0rgTB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deruix/U0F47ZEUD0/CwqTRV/p2JdLiXTAAsgGh1o+Re49L2L7ShZ3U0WixeDyLJlxy16paq8U4Zt3VekyvggQQto8PT7dL5WXXp59fkdheMtlb71cZBDzI0fmgAKhynpVSJYACPq4xJDKVtHCN2MQWplBqjlIapBtJUhlbl90TSrE9atvNziPTnNvT51cKEYWQPJIrSPnNVeKtelttQKbfi3QBFGmh95DmK/D5fs4C8fF5Q=" + }], + "trust_stores": [{ + "name": "le_via_isrg", + "stack": ["isrg_root_x1", "LEX3_isrg_root_x1"] + }, { + "name": "api_amazon_com", + "stack": ["digicert_global_ca_g2", "digicert_global_root_g2"] + }, { + "name": "avs_via_starfield", + "stack": ["starfield_class_2_ca", "starfield_services_root_ca"] + }, { + "name": "mqtt_amz_iot", + "stack": ["amazon_root_ca_1", "starfield_class_2_ca", "starfield_services_root_ca"] + }], + "s": [{ + "api_amazon_com_auth": { + "endpoint": "api.amazon.com", + "port": 443, + "protocol": "h1", + "http_method": "POST", + "http_url": "auth/o2/token", + "plugins": [], + "opportunistic": true, + "tls": true, + "h2q_oflow_txcr": true, + "http_www_form_urlencoded": true, + "http_no_content_length": true, + "retry": "default", + "tls_trust_store": "api_amazon_com" + } + }, { + "avs_event": { + "endpoint": "alexa.na.gateway.devices.a2z.com", + "port": 443, + "protocol": "h2", + "http_method": "GET", + "http_url": "v20160207/directives", + "h2q_oflow_txcr": true, + "http_auth_header": "authorization:", + "http_auth_preamble": "Bearer ", + "http_no_content_length": true, + "nailed_up": true, + "long_poll": true, + "retry": "default", + "plugins": [], + "tls": true, + "tls_trust_store": "avs_via_starfield" + } + }, { + "avs_metadata": { + "endpoint": "alexa.na.gateway.devices.a2z.com", + "port": 443, + "protocol": "h2", + "http_method": "POST", + "http_url": "v20160207/events", + "opportunistic": true, + "h2q_oflow_txcr": true, + "http_auth_header": "authorization:", + "http_auth_preamble": "Bearer ", + "http_multipart_name": "metadata", + "http_mime_content_type": "application/json; charset=UTF-8", + "http_no_content_length": true, + "rideshare": "avs_audio", + "retry": "default", + "plugins": [], + "tls": true, + "tls_trust_store": "avs_via_starfield" + } + }, { + "avs_audio": { + "endpoint": "alexa.na.gateway.devices.a2z.com", + "port": 443, + "protocol": "h2", + "http_method": "POST", + "http_url": "v20160207/events", + "plugins": [], + "tls": true, + "h2q_oflow_txcr": true, + "http_auth_header": "authorization:", + "http_auth_preamble": "Bearer ", + "http_multipart_name": "audio", + "http_mime_content_type": "application/octet-stream", + "http_no_content_length": true, + "retry": "default", + "tls_trust_store": "avs_via_starfield" + } + }, { + "mintest": { + "endpoint": "warmcat.com", + "port": 443, + "protocol": "h1", + "http_method": "GET", + "http_url": "index.html?uptag=${uptag}", + "http_dsn_header": "x-dsn:", + "http_fwv_header": "x-fw-version:", + "http_devtype_header": "x-devtype:", + "metadata": [{ + "uptag": "X-Upload-Tag:" + }, { + "ctype": "Content-Type:" + }, { + "xctype": "X-Content-Type:" + }], + "plugins": [], + "tls": true, + "opportunistic": true, + "retry": "default", + "tls_trust_store": "le_via_isrg" + } + }, { + "h2longpolltest": { + "endpoint": "warmcat.com", + "port": 443, + "protocol": "h2", + "http_method": "GET", + "http_url": "index.html", + "plugins": [], + "tls": true, + "nailed_up": true, + "long_poll": true, + "retry": "default", + "tls_trust_store": "le_via_isrg" + } + }, { + "mintest-fail": { + "endpoint": "warmcat.com", + "port": 22, + "protocol": "h1", + "http_method": "GET", + "http_url": "index.html", + "plugins": [], + "tls": true, + "opportunistic": true, + "retry": "default", + "tls_trust_store": "le_via_isrg" + } + }, { + "minpost": { + "endpoint": "warmcat.com", + "port": 443, + "protocol": "h1", + "http_method": "POST", + "http_url": "testserver/formtest", + "plugins": [], + "tls": true, + "opportunistic": true, + "retry": "default", + "tls_trust_store": "le_via_isrg" + } + }, { + "mqtt_test": { + "endpoint": "a1ygonr3im5cv2-ats.iot.us-west-2.amazonaws.com", + "port": 443, + "tls": true, + "client_cert": 0, + "tls_trust_store": "mqtt_amz_iot", + "protocol": "mqtt", + "mqtt_topic": "test/topic0", + "mqtt_subscribe": "test/topic0", + "mqtt_qos": 0, + "retry": "default" + } + }, { + "mqtt_test1": { + "endpoint": "a1ygonr3im5cv2-ats.iot.us-west-2.amazonaws.com", + "port": 443, + "tls": true, + "client_cert": 0, + "tls_trust_store": "mqtt_amz_iot", + "protocol": "mqtt", + "mqtt_topic": "test/topic1", + "mqtt_subscribe": "test/topic1", + "mqtt_qos": 1, + "retry": "default" + } + }, { + "captive_portal_detect": { + "endpoint": "connectivitycheck.android.com", + "port": 80, + "protocol": "h1", + "http_method": "GET", + "http_url": "generate_204", + "opportunistic": true, + "http_expect": 204, + "http_fail_redirect": true + } + } + ] +} + + diff -Nru libwebsockets-3.2.1/minimal-examples/secure-streams/README.md libwebsockets-4.1.6/minimal-examples/secure-streams/README.md --- libwebsockets-3.2.1/minimal-examples/secure-streams/README.md 1970-01-01 00:00:00.000000000 +0000 +++ libwebsockets-4.1.6/minimal-examples/secure-streams/README.md 2020-12-01 17:40:26.000000000 +0000 @@ -0,0 +1,14 @@ +# Secure Streams + +Secure Streams is a client API that strictly decouples the policy for connections +from the payloads. The user code only deals with the stream type name and payloads, +a policy database set at `lws_context` creation time decides all policy about the +connection, including the endpoint, tls CA, and even the wire protocol. + +|name|demonstrates| +---|--- +minimal-secure-streams|Minimal secure streams client / proxy example +minimal-secure-streams-tx|Proxy used for client-tx test below +minimal-secure-streams-client-tx|Secure streams client showing tx and rx + + diff -Nru libwebsockets-3.2.1/minimal-examples/selftests-library.sh libwebsockets-4.1.6/minimal-examples/selftests-library.sh --- libwebsockets-3.2.1/minimal-examples/selftests-library.sh 2019-12-18 14:45:31.000000000 +0000 +++ libwebsockets-4.1.6/minimal-examples/selftests-library.sh 1970-01-01 00:00:00.000000000 +0000 @@ -1,95 +0,0 @@ -#!/bin/bash - -if [ -z "$1" -o -z "$2" ] ; then - echo "required args missing" - exit 1 -fi - -IDX=$3 -TOT=$4 -MYTEST=`echo $0 | sed "s/\/[^\/]*\$//g" |sed "s/.*\///g"` -mkdir -p $2/$MYTEST -rm -f $2/$MYTEST/*.log $2/$MYTEST/*.result -FAILS=0 -WHICH=$IDX -SPID= -SCRIPT_DIR=`dirname $0` -SCRIPT_DIR=`readlink -f $SCRIPT_DIR` -LOGPATH=$2 - -feedback() { - if [ "$2" != "0" ] ; then - FAILS=$(( $FAILS + 1 )) - echo -n -e "\e[31m" - fi - T=" --- killed --- " - if [ ! -z "`cat $LOGPATH/$MYTEST/$3.time`" ] ; then - T="`cat $LOGPATH/$MYTEST/$3.time | grep real | sed "s/.*\ //g"`" - T="$T `cat $LOGPATH/$MYTEST/$3.time | grep user | sed "s/.*\ //g"`" - T="$T `cat $LOGPATH/$MYTEST/$3.time | grep sys | sed "s/.*\ //g"`" - fi - printf "%-35s [ %3s/%3s ]: %3s : %8s : %s\n" $1 $WHICH $TOT $2 "$T" $3 - if [ "$2" != "0" ] ; then - echo -n -e "\e[0m" - fi - WHICH=$(( $WHICH + 1)) -} - -spawn() { - if [ ! -z "$1" ] ; then - if [ `ps $1 | wc -l` -eq 2 ]; then -# echo "prerequisite still up" - return 0 - fi - fi - - QQ=`pwd` - cd $SCRIPT_DIR - cd $2 - $3 $4 $5 > $LOGPATH/$MYTEST/serverside.log 2> $LOGPATH/$MYTEST/serverside.log & - SPID=$! - cd $QQ - sleep 0.5s -# echo "launched prerequisite $SPID" -} - -dotest() { - T=$3 - ( - { - /usr/bin/time -p $1/lws-$MYTEST $4 $5 $6 $7 $8 $9 > $2/$MYTEST/$T.log 2> $2/$MYTEST/$T.log ; - echo $? > $2/$MYTEST/$T.result - } 2> $2/$MYTEST/$T.time >/dev/null - ) >/dev/null 2> /dev/null & - W=$! - WT=0 - while [ $WT -le 820 ] ; do - kill -0 $W 2>/dev/null - if [ $? -ne 0 ] ; then - WT=10000 - else - if [ $WT -ge 800 ] ; then - WT=10000 - kill $W 2>/dev/null - wait $W 2>/dev/null - fi - fi - sleep 0.1s - WT=$(( $WT + 1 )) - done - - R=254 - if [ -e $2/$MYTEST/$T.result ] ; then - R=`cat $2/$MYTEST/$T.result` - cat $2/$MYTEST/$T.log | tail -n 3 > $2/$MYTEST/$T.time - if [ $R -ne 0 ] ; then - pwd - echo - cat $2/$MYTEST/$T.log - echo - fi - fi - - feedback $MYTEST $R $T -} - diff -Nru libwebsockets-3.2.1/minimal-examples/selftests.sh libwebsockets-4.1.6/minimal-examples/selftests.sh --- libwebsockets-3.2.1/minimal-examples/selftests.sh 2019-12-18 14:45:31.000000000 +0000 +++ libwebsockets-4.1.6/minimal-examples/selftests.sh 1970-01-01 00:00:00.000000000 +0000 @@ -1,61 +0,0 @@ -#!/bin/bash -# -# run this from your build dir having configured -# -DLWS_WITH_MINIMAL_EXAMPLES=1 to get all the examples -# that apply built into ./bin -# -# Eg, -# -# build $ ../minimal-examples/selftests.sh - -echo -echo "----------------------------------------------" -echo "------- tests: lws minimal example selftests" -echo - -LOGGING_PATH=/tmp/logs - -# for mebedtls, we need the CA certs in ./build where we run from - -cp ../minimal-examples/http-client/minimal-http-client-multi/warmcat.com.cer . -cp ../minimal-examples/http-client/minimal-http-client-post/libwebsockets.org.cer . - -MINEX=`dirname $0` -MINEX=`realpath $MINEX` -TESTS=0 -for i in `find $MINEX -name selftest.sh` ; do - BN=`echo -n "$i" | sed "s/\/[^\/]*\$//g" | sed "s/.*\///g"` - if [ -e `pwd`/bin/lws-$BN ] ; then - C=`cat $i | grep COUNT_TESTS= | cut -d= -f2` - TESTS=$(( $TESTS + $C )) - fi -done - -FAILS=0 -WH=1 - -for i in `find $MINEX -name selftest.sh` ; do - BN=`echo -n "$i" | sed "s/\/[^\/]*\$//g" | sed "s/.*\///g"` - if [ -e `pwd`/bin/lws-$BN ] ; then - C=`cat $i | grep COUNT_TESTS= | cut -d= -f2` - sh $i `pwd`/bin $LOGGING_PATH $WH $TESTS $MINEX - FAILS=$(( $FAILS + $? )) - - L=`ps fax | grep lws- | cut -d' ' -f2` - kill $L 2>/dev/null - kill -9 $L 2>/dev/null - wait $L 2>/dev/null - - WH=$(( $WH + $C )) - fi -done - -if [ $FAILS -eq 0 ] ; then - echo "All $TESTS passed" - exit 0 -else - echo "Failed: $FAILS / $TESTS" - exit 1 -fi - - diff -Nru libwebsockets-3.2.1/minimal-examples/ws-client/minimal-ws-client/CMakeLists.txt libwebsockets-4.1.6/minimal-examples/ws-client/minimal-ws-client/CMakeLists.txt --- libwebsockets-3.2.1/minimal-examples/ws-client/minimal-ws-client/CMakeLists.txt 1970-01-01 00:00:00.000000000 +0000 +++ libwebsockets-4.1.6/minimal-examples/ws-client/minimal-ws-client/CMakeLists.txt 2020-12-01 17:40:26.000000000 +0000 @@ -0,0 +1,25 @@ +project(lws-minimal-ws-client-ping C) +cmake_minimum_required(VERSION 2.8) +find_package(libwebsockets CONFIG REQUIRED) +list(APPEND CMAKE_MODULE_PATH ${LWS_CMAKE_DIR}) +include(CheckIncludeFile) +include(CheckCSourceCompiles) +include(LwsCheckRequirements) + +set(SAMP lws-minimal-ws-client) +set(SRCS minimal-ws-client.c) + +set(requirements 1) +require_lws_config(LWS_ROLE_WS 1 requirements) +require_lws_config(LWS_WITH_CLIENT 1 requirements) + +if (requirements) + add_executable(${SAMP} ${SRCS}) + + if (websockets_shared) + target_link_libraries(${SAMP} websockets_shared ${LIBWEBSOCKETS_DEP_LIBS}) + add_dependencies(${SAMP} websockets_shared) + else() + target_link_libraries(${SAMP} websockets ${LIBWEBSOCKETS_DEP_LIBS}) + endif() +endif() diff -Nru libwebsockets-3.2.1/minimal-examples/ws-client/minimal-ws-client/libwebsockets.org.cer libwebsockets-4.1.6/minimal-examples/ws-client/minimal-ws-client/libwebsockets.org.cer --- libwebsockets-3.2.1/minimal-examples/ws-client/minimal-ws-client/libwebsockets.org.cer 1970-01-01 00:00:00.000000000 +0000 +++ libwebsockets-4.1.6/minimal-examples/ws-client/minimal-ws-client/libwebsockets.org.cer 2020-12-01 17:40:26.000000000 +0000 @@ -0,0 +1,79 @@ +-----BEGIN CERTIFICATE----- +MIIFWjCCBEKg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DQEBBQUAA4IBAQCjGiybFwBcqR7uKGY3Or+Dxz9LwwmglSBd49lZRNI+DT69 +ikugdB/OEIKcdBodfpga3csTS7MgROSR6cz8faXbauX+5v3gTt23ADq1cEmv8uXr +AvHRAosZy5Q6XkjEGB5YGV8eAlrwDPGxrancWYaLbumR9YbK+rlmM6pZW87ipxZz +R8srzJmwN0jP41ZL9c8PDHIyh8bwRLtTcm1D9SZImlJnt1ir/md2cXjbDaJWFBM5 +JDGFoqgCWjBH4d1QB7wCCZAA62RjYJsWvIjJEubSfZGL+T0yjWW06XyxV3bqxbYo +Ob8VZRzI9neWagqNdwvYkQsEjgfbKbYK7p2CNTUQ +-----END CERTIFICATE----- + diff -Nru libwebsockets-3.2.1/minimal-examples/ws-client/minimal-ws-client/minimal-ws-client.c libwebsockets-4.1.6/minimal-examples/ws-client/minimal-ws-client/minimal-ws-client.c --- libwebsockets-3.2.1/minimal-examples/ws-client/minimal-ws-client/minimal-ws-client.c 1970-01-01 00:00:00.000000000 +0000 +++ libwebsockets-4.1.6/minimal-examples/ws-client/minimal-ws-client/minimal-ws-client.c 2020-12-01 17:40:26.000000000 +0000 @@ -0,0 +1,213 @@ +/* + * lws-minimal-ws-client + * + * Written in 2010-2020 by Andy Green + * + * This file is made available under the Creative Commons CC0 1.0 + * Universal Public Domain Dedication. + * + * This demonstrates a ws client that connects by default to libwebsockets.org + * dumb increment ws server. + */ + +#include +#include +#include + +/* + * This represents your object that "contains" the client connection and has + * the client connection bound to it + */ + +static struct my_conn { + lws_sorted_usec_list_t sul; /* schedule connection retry */ + struct lws *wsi; /* related wsi if any */ + uint16_t retry_count; /* count of consequetive retries */ +} mco; + +static struct lws_context *context; +static int interrupted, port = 443, ssl_connection = LCCSCF_USE_SSL; +static const char *server_address = "libwebsockets.org", + *pro = "dumb-increment-protocol"; + +/* + * The retry and backoff policy we want to use for our client connections + */ + +static const uint32_t backoff_ms[] = { 1000, 2000, 3000, 4000, 5000 }; + +static const lws_retry_bo_t retry = { + .retry_ms_table = backoff_ms, + .retry_ms_table_count = LWS_ARRAY_SIZE(backoff_ms), + .conceal_count = LWS_ARRAY_SIZE(backoff_ms), + + .secs_since_valid_ping = 3, /* force PINGs after secs idle */ + .secs_since_valid_hangup = 10, /* hangup after secs idle */ + + .jitter_percent = 20, +}; + +/* + * Scheduled sul callback that starts the connection attempt + */ + +static void +connect_client(lws_sorted_usec_list_t *sul) +{ + struct my_conn *mco = lws_container_of(sul, struct my_conn, sul); + struct lws_client_connect_info i; + + memset(&i, 0, sizeof(i)); + + i.context = context; + i.port = port; + i.address = server_address; + i.path = "/"; + i.host = i.address; + i.origin = i.address; + i.ssl_connection = ssl_connection; + i.protocol = pro; + i.local_protocol_name = "lws-minimal-client"; + i.pwsi = &mco->wsi; + i.retry_and_idle_policy = &retry; + i.userdata = mco; + + if (!lws_client_connect_via_info(&i)) + /* + * Failed... schedule a retry... we can't use the _retry_wsi() + * convenience wrapper api here because no valid wsi at this + * point. + */ + if (lws_retry_sul_schedule(context, 0, sul, &retry, + connect_client, &mco->retry_count)) { + lwsl_err("%s: connection attempts exhausted\n", __func__); + interrupted = 1; + } +} + +static int +callback_minimal(struct lws *wsi, enum lws_callback_reasons reason, + void *user, void *in, size_t len) +{ + struct my_conn *mco = (struct my_conn *)user; + + switch (reason) { + + case LWS_CALLBACK_CLIENT_CONNECTION_ERROR: + lwsl_err("CLIENT_CONNECTION_ERROR: %s\n", + in ? (char *)in : "(null)"); + goto do_retry; + break; + + case LWS_CALLBACK_CLIENT_RECEIVE: + lwsl_hexdump_notice(in, len); + break; + + case LWS_CALLBACK_CLIENT_ESTABLISHED: + lwsl_user("%s: established\n", __func__); + break; + + case LWS_CALLBACK_CLIENT_CLOSED: + goto do_retry; + + default: + break; + } + + return lws_callback_http_dummy(wsi, reason, user, in, len); + +do_retry: + /* + * retry the connection to keep it nailed up + * + * For this example, we try to conceal any problem for one set of + * backoff retries and then exit the app. + * + * If you set retry.conceal_count to be larger than the number of + * elements in the backoff table, it will never give up and keep + * retrying at the last backoff delay plus the random jitter amount. + */ + if (lws_retry_sul_schedule_retry_wsi(wsi, &mco->sul, connect_client, + &mco->retry_count)) { + lwsl_err("%s: connection attempts exhausted\n", __func__); + interrupted = 1; + } + + return 0; +} + +static const struct lws_protocols protocols[] = { + { "lws-minimal-client", callback_minimal, 0, 0, }, + { NULL, NULL, 0, 0 } +}; + +static void +sigint_handler(int sig) +{ + interrupted = 1; +} + +int main(int argc, const char **argv) +{ + struct lws_context_creation_info info; + const char *p; + int n = 0; + + signal(SIGINT, sigint_handler); + memset(&info, 0, sizeof info); + lws_cmdline_option_handle_builtin(argc, argv, &info); + + lwsl_user("LWS minimal ws client\n"); + + info.options = LWS_SERVER_OPTION_DO_SSL_GLOBAL_INIT; + info.port = CONTEXT_PORT_NO_LISTEN; /* we do not run any server */ + info.protocols = protocols; + +#if defined(LWS_WITH_MBEDTLS) || defined(USE_WOLFSSL) + /* + * OpenSSL uses the system trust store. mbedTLS has to be told which + * CA to trust explicitly. + */ + info.client_ssl_ca_filepath = "./libwebsockets.org.cer"; +#endif + + if ((p = lws_cmdline_option(argc, argv, "--protocol"))) + pro = p; + + if ((p = lws_cmdline_option(argc, argv, "-s"))) + server_address = p; + + if ((p = lws_cmdline_option(argc, argv, "-p"))) + port = atoi(p); + + if (lws_cmdline_option(argc, argv, "-j")) + ssl_connection |= LCCSCF_ALLOW_SELFSIGNED; + + if (lws_cmdline_option(argc, argv, "-k")) + ssl_connection |= LCCSCF_ALLOW_INSECURE; + + if (lws_cmdline_option(argc, argv, "-m")) + ssl_connection |= LCCSCF_SKIP_SERVER_CERT_HOSTNAME_CHECK; + + if (lws_cmdline_option(argc, argv, "-e")) + ssl_connection |= LCCSCF_ALLOW_EXPIRED; + + info.fd_limit_per_thread = 1 + 1 + 1; + + context = lws_create_context(&info); + if (!context) { + lwsl_err("lws init failed\n"); + return 1; + } + + /* schedule the first client connection attempt to happen immediately */ + lws_sul_schedule(context, 0, &mco.sul, connect_client, 1); + + while (n >= 0 && !interrupted) + n = lws_service(context, 0); + + lws_context_destroy(context); + lwsl_user("Completed\n"); + + return 0; +} diff -Nru libwebsockets-3.2.1/minimal-examples/ws-client/minimal-ws-client/README.md libwebsockets-4.1.6/minimal-examples/ws-client/minimal-ws-client/README.md --- libwebsockets-3.2.1/minimal-examples/ws-client/minimal-ws-client/README.md 1970-01-01 00:00:00.000000000 +0000 +++ libwebsockets-4.1.6/minimal-examples/ws-client/minimal-ws-client/README.md 2020-12-01 17:40:26.000000000 +0000 @@ -0,0 +1,58 @@ +# lws minimal ws client + +This connects to libwebsockets.org using the dumb-increment-protocol. + +It demonstrates how to use the connection retry and backoff stuff in lws. + +## build + +``` + $ cmake . && make +``` + +## Commandline Options + +Option|Meaning +---|--- +-d|Set logging verbosity +-s|Use a specific server instead of libwebsockets.org, eg `--server localhost`. Implies LCCSCF_ALLOW_SELFSIGNED +-p|Use a specific port instead of 443, eg `--port 7681` +-j|Allow selfsigned tls cert +-k|Allow insecure certs +-m|Skip server hostname check +-e|Allow expired certs +--protocol|Use a specific ws subprotocol rather than dumb-increment-protocol, eg, `--protocol myprotocol` + + +## usage + +Just run it, it will connect to libwebsockets.org and spew incrementing numbers +sent by the server at 20Hz + +``` + $ ./lws-minimal-ws-client +[2020/01/22 05:38:47:3409] U: LWS minimal ws client +[2020/01/22 05:38:47:4456] N: Loading client CA for verification ./libwebsockets.org.cer +[2020/01/22 05:38:48:1649] U: callback_minimal: established +[2020/01/22 05:38:48:1739] N: +[2020/01/22 05:38:48:1763] N: 0000: 30 0 +[2020/01/22 05:38:48:1765] N: + +... +``` + +To test against the lws test server instead of libwebsockets.org, run the test +server as + +``` +$ libwebsockets-test-server -s +``` + +and run this test app with + +``` +$ ./lws-minimal-ws-client -s localhost -p 7681 -j +``` + +You can kill and restart the server to confirm the client connection is re- +established if done within the backoff period. diff -Nru libwebsockets-3.2.1/minimal-examples/ws-client/minimal-ws-client-binance/CMakeLists.txt libwebsockets-4.1.6/minimal-examples/ws-client/minimal-ws-client-binance/CMakeLists.txt --- libwebsockets-3.2.1/minimal-examples/ws-client/minimal-ws-client-binance/CMakeLists.txt 1970-01-01 00:00:00.000000000 +0000 +++ libwebsockets-4.1.6/minimal-examples/ws-client/minimal-ws-client-binance/CMakeLists.txt 2020-12-01 17:40:26.000000000 +0000 @@ -0,0 +1,26 @@ +project(lws-minimal-ws-client-binance C) +cmake_minimum_required(VERSION 2.8) +find_package(libwebsockets CONFIG REQUIRED) +list(APPEND CMAKE_MODULE_PATH ${LWS_CMAKE_DIR}) +include(CheckIncludeFile) +include(CheckCSourceCompiles) +include(LwsCheckRequirements) + +set(SAMP lws-minimal-ws-client-binance) +set(SRCS main.c) + +set(requirements 1) +require_lws_config(LWS_ROLE_WS 1 requirements) +require_lws_config(LWS_WITH_CLIENT 1 requirements) +require_lws_config(LWS_WITHOUT_EXTENSIONS 0 requirements) + +if (requirements) + add_executable(${SAMP} ${SRCS}) + + if (websockets_shared) + target_link_libraries(${SAMP} websockets_shared ${LIBWEBSOCKETS_DEP_LIBS}) + add_dependencies(${SAMP} websockets_shared) + else() + target_link_libraries(${SAMP} websockets ${LIBWEBSOCKETS_DEP_LIBS}) + endif() +endif() diff -Nru libwebsockets-3.2.1/minimal-examples/ws-client/minimal-ws-client-binance/main.c libwebsockets-4.1.6/minimal-examples/ws-client/minimal-ws-client-binance/main.c --- libwebsockets-3.2.1/minimal-examples/ws-client/minimal-ws-client-binance/main.c 1970-01-01 00:00:00.000000000 +0000 +++ libwebsockets-4.1.6/minimal-examples/ws-client/minimal-ws-client-binance/main.c 2020-12-01 17:40:26.000000000 +0000 @@ -0,0 +1,380 @@ +/* + * lws-minimal-ws-client-binance + * + * Written in 2010-2020 by Andy Green + * Kutoga + * + * This file is made available under the Creative Commons CC0 1.0 + * Universal Public Domain Dedication. + * + * This demonstrates a ws client that connects to binance ws server efficiently + */ + +#include +#include +#include +#include + +typedef struct range { + lws_usec_t sum; + lws_usec_t lowest; + lws_usec_t highest; + + int samples; +} range_t; + +/* + * This represents your object that "contains" the client connection and has + * the client connection bound to it + */ + +static struct my_conn { + lws_sorted_usec_list_t sul; /* schedule connection retry */ + lws_sorted_usec_list_t sul_hz; /* 1hz summary */ + + range_t e_lat_range; + range_t price_range; + + struct lws *wsi; /* related wsi if any */ + uint16_t retry_count; /* count of consequetive retries */ +} mco; + +static struct lws_context *context; +static int interrupted; + +#if defined(LWS_WITH_MBEDTLS) || defined(USE_WOLFSSL) +/* + * OpenSSL uses the system trust store. mbedTLS / WolfSSL have to be told which + * CA to trust explicitly. + */ +static const char * const ca_pem_digicert_global_root = + "-----BEGIN CERTIFICATE-----\n" + "MIIDrzCCApegAwIBAgIQCDvgVpBCRrGhdWrJWZHHSjANBgkqhkiG9w0BAQUFADBh\n" + "MQswCQYDVQQGEwJVUzEVMBMGA1UEChMMRGlnaUNlcnQgSW5jMRkwFwYDVQQLExB3\n" + "d3cuZGlnaWNlcnQuY29tMSAwHgYDVQQDExdEaWdpQ2VydCBHbG9iYWwgUm9vdCBD\n" + "QTAeFw0wNjExMTAwMDAwMDBaFw0zMTExMTAwMDAwMDBaMGExCzAJBgNVBAYTAlVT\n" + "MRUwEwYDVQQKEwxEaWdpQ2VydCBJbmMxGTAXBgNVBAsTEHd3dy5kaWdpY2VydC5j\n" + "b20xIDAeBgNVBAMTF0RpZ2lDZXJ0IEdsb2JhbCBSb290IENBMIIBIjANBgkqhkiG\n" + "9w0BAQEFAAOCAQ8AMIIBCgKCAQEA4jvhEXLeqKTTo1eqUKKPC3eQyaKl7hLOllsB\n" + "CSDMAZOnTjC3U/dDxGkAV53ijSLdhwZAAIEJzs4bg7/fzTtxRuLWZscFs3YnFo97\n" + "nh6Vfe63SKMI2tavegw5BmV/Sl0fvBf4q77uKNd0f3p4mVmFaG5cIzJLv07A6Fpt\n" + "43C/dxC//AH2hdmoRBBYMql1GNXRor5H4idq9Joz+EkIYIvUX7Q6hL+hqkpMfT7P\n" + "T19sdl6gSzeRntwi5m3OFBqOasv+zbMUZBfHWymeMr/y7vrTC0LUq7dBMtoM1O/4\n" + "gdW7jVg/tRvoSSiicNoxBN33shbyTApOB6jtSj1etX+jkMOvJwIDAQABo2MwYTAO\n" + "BgNVHQ8BAf8EBAMCAYYwDwYDVR0TAQH/BAUwAwEB/zAdBgNVHQ4EFgQUA95QNVbR\n" + "TLtm8KPiGxvDl7I90VUwHwYDVR0jBBgwFoAUA95QNVbRTLtm8KPiGxvDl7I90VUw\n" + "DQYJKoZIhvcNAQEFBQADggEBAMucN6pIExIK+t1EnE9SsPTfrgT1eXkIoyQY/Esr\n" + "hMAtudXH/vTBH1jLuG2cenTnmCmrEbXjcKChzUyImZOMkXDiqw8cvpOp/2PV5Adg\n" + "06O/nVsJ8dWO41P0jmP6P6fbtGbfYmbW0W5BjfIttep3Sp+dWOIrWcBAI+0tKIJF\n" + "PnlUkiaY4IBIqDfv8NZ5YBberOgOzW6sRBc4L0na4UU+Krk2U886UAb3LujEV0ls\n" + "YSEY1QSteDwsOoBrp+uvFRTp2InBuThs4pFsiv9kuXclVzDAGySj4dzp30d8tbQk\n" + "CAUw7C29C79Fv1C5qfPrmAESrciIxpg0X40KPMbp1ZWVbd4=\n" + "-----END CERTIFICATE-----\n"; +#endif + +/* + * The retry and backoff policy we want to use for our client connections + */ + +static const uint32_t backoff_ms[] = { 1000, 2000, 3000, 4000, 5000 }; + +static const lws_retry_bo_t retry = { + .retry_ms_table = backoff_ms, + .retry_ms_table_count = LWS_ARRAY_SIZE(backoff_ms), + .conceal_count = LWS_ARRAY_SIZE(backoff_ms), + + .secs_since_valid_ping = 400, /* force PINGs after secs idle */ + .secs_since_valid_hangup = 400, /* hangup after secs idle */ + + .jitter_percent = 0, +}; + +/* + * If we don't enable permessage-deflate ws extension, during times when there + * are many ws messages per second the server coalesces them inside a smaller + * number of larger ssl records, for >100 mps typically >2048 records. + * + * This is a problem, because the coalesced record cannot be send nor decrypted + * until the last part of the record is received, meaning additional latency + * for the earlier members of the coalesced record that have just been sitting + * there waiting for the last one to go out and be decrypted. + * + * permessage-deflate reduces the data size before the tls layer, for >100mps + * reducing the colesced records to ~1.2KB. + */ + +static const struct lws_extension extensions[] = { + { + "permessage-deflate", + lws_extension_callback_pm_deflate, + "permessage-deflate" + "; client_no_context_takeover" + "; client_max_window_bits" + }, + { NULL, NULL, NULL /* terminator */ } +}; +/* + * Scheduled sul callback that starts the connection attempt + */ + +static void +connect_client(lws_sorted_usec_list_t *sul) +{ + struct my_conn *mco = lws_container_of(sul, struct my_conn, sul); + struct lws_client_connect_info i; + + memset(&i, 0, sizeof(i)); + + i.context = context; + i.port = 443; + i.address = "fstream.binance.com"; + i.path = "/stream?" + "streams=btcusdt@depth@0ms/btcusdt@bookTicker/btcusdt@aggTrade"; + i.host = i.address; + i.origin = i.address; + i.ssl_connection = LCCSCF_USE_SSL | LCCSCF_PRIORITIZE_READS; + i.protocol = NULL; + i.local_protocol_name = "lws-minimal-client"; + i.pwsi = &mco->wsi; + i.retry_and_idle_policy = &retry; + i.userdata = mco; + + if (!lws_client_connect_via_info(&i)) + /* + * Failed... schedule a retry... we can't use the _retry_wsi() + * convenience wrapper api here because no valid wsi at this + * point. + */ + if (lws_retry_sul_schedule(context, 0, sul, &retry, + connect_client, &mco->retry_count)) { + lwsl_err("%s: connection attempts exhausted\n", __func__); + interrupted = 1; + } +} + +static void +range_reset(range_t *r) +{ + r->sum = r->highest = 0; + r->lowest = 999999999999ull; + r->samples = 0; +} + +static uint64_t +get_us_timeofday(void) +{ + struct timeval tv; + + gettimeofday(&tv, NULL); + + return ((lws_usec_t)tv.tv_sec * LWS_US_PER_SEC) + tv.tv_usec; +} + +static void +sul_hz_cb(lws_sorted_usec_list_t *sul) +{ + struct my_conn *mco = lws_container_of(sul, struct my_conn, sul_hz); + + /* + * We are called once a second to dump statistics on the connection + */ + + lws_sul_schedule(lws_get_context(mco->wsi), 0, &mco->sul_hz, + sul_hz_cb, LWS_US_PER_SEC); + + if (mco->price_range.samples) + lwsl_notice("%s: price: min: %llu¢, max: %llu¢, avg: %llu¢, " + "(%d prices/s)\n", + __func__, + (unsigned long long)mco->price_range.lowest, + (unsigned long long)mco->price_range.highest, + (unsigned long long)(mco->price_range.sum / mco->price_range.samples), + mco->price_range.samples); + if (mco->e_lat_range.samples) + lwsl_notice("%s: elatency: min: %llums, max: %llums, " + "avg: %llums, (%d msg/s)\n", __func__, + (unsigned long long)mco->e_lat_range.lowest / 1000, + (unsigned long long)mco->e_lat_range.highest / 1000, + (unsigned long long)(mco->e_lat_range.sum / + mco->e_lat_range.samples) / 1000, + mco->e_lat_range.samples); + + range_reset(&mco->e_lat_range); + range_reset(&mco->price_range); +} + +static uint64_t +pennies(const char *s) +{ + uint64_t price = (uint64_t)atoll(s) * 100; + + s = strchr(s, '.'); + + if (s && isdigit(s[1]) && isdigit(s[2])) + price += (10 * (s[1] - '0')) + (s[2] - '0'); + + return price; +} + +static int +callback_minimal(struct lws *wsi, enum lws_callback_reasons reason, + void *user, void *in, size_t len) +{ + struct my_conn *mco = (struct my_conn *)user; + lws_usec_t latency_us, now_us, price; + char numbuf[16]; + const char *p; + size_t alen; + + switch (reason) { + + case LWS_CALLBACK_CLIENT_CONNECTION_ERROR: + lwsl_err("CLIENT_CONNECTION_ERROR: %s\n", + in ? (char *)in : "(null)"); + goto do_retry; + break; + + case LWS_CALLBACK_CLIENT_RECEIVE: + /* + * The messages are a few 100 bytes of JSON each + */ + + // lwsl_hexdump_notice(in, len); + + now_us = get_us_timeofday(); + + p = lws_json_simple_find((const char *)in, len, + "\"depthUpdate\"", &alen); + /* + * Only the JSON with depthUpdate init has the numbers we care + * about as well + */ + if (!p) + break; + + p = lws_json_simple_find((const char *)in, len, "\"E\":", &alen); + if (!p) { + lwsl_err("%s: no E JSON\n", __func__); + break; + } + lws_strnncpy(numbuf, p, alen, sizeof(numbuf)); + latency_us = now_us - + ((lws_usec_t)atoll(numbuf) * LWS_US_PER_MS); + + if (latency_us < mco->e_lat_range.lowest) + mco->e_lat_range.lowest = latency_us; + if (latency_us > mco->e_lat_range.highest) + mco->e_lat_range.highest = latency_us; + + mco->e_lat_range.sum += latency_us; + mco->e_lat_range.samples++; + + p = lws_json_simple_find((const char *)in, len, + "\"a\":[[\"", &alen); + if (p) { + lws_strnncpy(numbuf, p, alen, sizeof(numbuf)); + price = pennies(numbuf); + + if (price < mco->price_range.lowest) + mco->price_range.lowest = price; + if (price > mco->price_range.highest) + mco->price_range.highest = price; + + mco->price_range.sum += price; + mco->price_range.samples++; + } + break; + + case LWS_CALLBACK_CLIENT_ESTABLISHED: + lwsl_user("%s: established\n", __func__); + lws_sul_schedule(lws_get_context(wsi), 0, &mco->sul_hz, + sul_hz_cb, LWS_US_PER_SEC); + mco->wsi = wsi; + range_reset(&mco->e_lat_range); + range_reset(&mco->price_range); + break; + + case LWS_CALLBACK_CLIENT_CLOSED: + goto do_retry; + + default: + break; + } + + return lws_callback_http_dummy(wsi, reason, user, in, len); + +do_retry: + /* + * retry the connection to keep it nailed up + * + * For this example, we try to conceal any problem for one set of + * backoff retries and then exit the app. + * + * If you set retry.conceal_count to be larger than the number of + * elements in the backoff table, it will never give up and keep + * retrying at the last backoff delay plus the random jitter amount. + */ + if (lws_retry_sul_schedule_retry_wsi(wsi, &mco->sul, connect_client, + &mco->retry_count)) { + lwsl_err("%s: connection attempts exhausted\n", __func__); + interrupted = 1; + } + + return 0; +} + +static const struct lws_protocols protocols[] = { + { "lws-minimal-client", callback_minimal, 0, 0, }, + { NULL, NULL, 0, 0 } +}; + +static void +sigint_handler(int sig) +{ + interrupted = 1; +} + +int main(int argc, const char **argv) +{ + struct lws_context_creation_info info; + int n = 0; + + signal(SIGINT, sigint_handler); + memset(&info, 0, sizeof info); + lws_cmdline_option_handle_builtin(argc, argv, &info); + + lwsl_user("LWS minimal binance client\n"); + + info.options = LWS_SERVER_OPTION_DO_SSL_GLOBAL_INIT; + info.port = CONTEXT_PORT_NO_LISTEN; /* we do not run any server */ + info.protocols = protocols; + info.fd_limit_per_thread = 1 + 1 + 1; + info.extensions = extensions; + +#if defined(LWS_WITH_MBEDTLS) || defined(USE_WOLFSSL) + /* + * OpenSSL uses the system trust store. mbedTLS / WolfSSL have to be + * told which CA to trust explicitly. + */ + info.client_ssl_ca_mem = ca_pem_digicert_global_root; + info.client_ssl_ca_mem_len = strlen(ca_pem_digicert_global_root); +#endif + + context = lws_create_context(&info); + if (!context) { + lwsl_err("lws init failed\n"); + return 1; + } + + /* schedule the first client connection attempt to happen immediately */ + lws_sul_schedule(context, 0, &mco.sul, connect_client, 1); + + while (n >= 0 && !interrupted) + n = lws_service(context, 0); + + lws_context_destroy(context); + lwsl_user("Completed\n"); + + return 0; +} + diff -Nru libwebsockets-3.2.1/minimal-examples/ws-client/minimal-ws-client-binance/README.md libwebsockets-4.1.6/minimal-examples/ws-client/minimal-ws-client-binance/README.md --- libwebsockets-3.2.1/minimal-examples/ws-client/minimal-ws-client-binance/README.md 1970-01-01 00:00:00.000000000 +0000 +++ libwebsockets-4.1.6/minimal-examples/ws-client/minimal-ws-client-binance/README.md 2020-12-01 17:40:26.000000000 +0000 @@ -0,0 +1,67 @@ +# lws minimal ws client binance + +This connects to the binance ws server and monitors transactions with +an eye on low latency. + +Latency seems to be associated with server-side coalescing at tls +layer, and the coalescing at server side seems somewhat correlated to number +of transactions per second, which seems to cause increased packet sizes from the +server as a reaction. The relationship is more complex probably according to what +actually happens at the server backend, but it seems to be broadly related +reliably. + +Typically when showing low latency at ~70msg/s, the messages on the wire are +eg, ~70 byte packets containing small tls records + +10:14:40.682293 IP ec2-54-249-113-172.ap-northeast-1.compute.amazonaws.com.https > constance.42952: Flags [P.], seq 50846:50927, ack 1, win 11, options [nop,nop,TS val 366445630 ecr 3893437035], length 81 + +under pressure from increased messages per second, the tls records increase above 2KB + +08:06:02.825160 IP ec2-54-249-113-172.ap-northeast-1.compute.amazonaws.com.https > constance.42688: Flags [.], seq 512319:513643, ack 1, win 11, options [nop,nop,TS val 3990208942 ecr 3885719233], length 1324 +08:06:02.825290 IP constance.42688 > ec2-54-249-113-172.ap-northeast-1.compute.amazonaws.com.https: Flags [.], ack 513643, win 14248, options [nop,nop,TS val 3885719479 ecr 3990208942], length 0 +08:06:02.891646 IP ec2-54-249-113-172.ap-northeast-1.compute.amazonaws.com.https > constance.42688: Flags [.], seq 513643:516291, ack 1, win 11, options [nop,nop,TS val 3990209006 ecr 3885719296], length 2648 + +The larger the packets, the longer the first item in the packet had to +wait before it was sent, and a tls record cannot be authenticated until +all of it has been received. + +The example circumvents this somewhat by using `permessage_deflate`, which reduces +the packet size before tls by applying compression, making even coalesced packets +smaller, and a new option for adjusting how lws manages conflicting requirements to +clear pending rx and allow interleaved tx, `LCCSCF_PRIORITIZE_READS` that causes the +stream to prioritize handling any pending rx, not just pending at ssl layer, in one +event loop trip. + +## build + +Lws must have been built with `LWS_ROLE_WS=1` and `LWS_WITHOUT_EXTENSIONS=0` + +``` + $ cmake . && make +``` + +## Commandline Options + +Option|Meaning +---|--- +-d|Set logging verbosity + +## usage + +``` +$ ./bin/lws-minimal-ws-client-binance +[2020/08/23 10:22:49:3003] U: LWS minimal binance client +[2020/08/23 10:22:49:3005] N: LWS: 4.0.99-v4.1.0-rc2-4-g3cf133aef, loglevel 1031 +[2020/08/23 10:22:49:3005] N: NET CLI SRV H1 H2 WS MQTT SS-JSON-POL SSPROX ASYNC_DNS IPv6-absent +[2020/08/23 10:22:50:8243] N: checking client ext permessage-deflate +[2020/08/23 10:22:50:8244] N: instantiating client ext permessage-deflate +[2020/08/23 10:22:50:8244] U: callback_minimal: established +[2020/08/23 10:22:51:8244] N: sul_hz_cb: price: min: 1160284¢, max: 1163794¢, avg: 1160516¢, (150 prices/s) +[2020/08/23 10:22:51:8245] N: sul_hz_cb: elatency: min: 112ms, max: 547ms, avg: 259ms, (155 msg/s) +[2020/08/23 10:22:52:8244] N: sul_hz_cb: price: min: 1160287¢, max: 1178845¢, avg: 1160897¢, (112 prices/s) +[2020/08/23 10:22:52:8245] N: sul_hz_cb: elatency: min: 111ms, max: 226ms, avg: 152ms, (134 msg/s) +[2020/08/23 10:22:53:8247] N: sul_hz_cb: price: min: 1160287¢, max: 1168005¢, avg: 1160806¢, (86 prices/s) +[2020/08/23 10:22:53:8248] N: sul_hz_cb: elatency: min: 112ms, max: 476ms, avg: 287ms, (101 msg/s) +[2020/08/23 10:22:54:8247] N: sul_hz_cb: price: min: 1160284¢, max: 1162780¢, avg: 1160698¢, (71 prices/s) +... +``` diff -Nru libwebsockets-3.2.1/minimal-examples/ws-client/minimal-ws-client-echo/CMakeLists.txt libwebsockets-4.1.6/minimal-examples/ws-client/minimal-ws-client-echo/CMakeLists.txt --- libwebsockets-3.2.1/minimal-examples/ws-client/minimal-ws-client-echo/CMakeLists.txt 2019-12-18 14:45:31.000000000 +0000 +++ libwebsockets-4.1.6/minimal-examples/ws-client/minimal-ws-client-echo/CMakeLists.txt 2020-12-01 17:40:26.000000000 +0000 @@ -1,79 +1,25 @@ +project(lws-minimal-ws-client-echo C) cmake_minimum_required(VERSION 2.8.9) +find_package(libwebsockets CONFIG REQUIRED) +list(APPEND CMAKE_MODULE_PATH ${LWS_CMAKE_DIR}) include(CheckCSourceCompiles) +include(LwsCheckRequirements) set(SAMP lws-minimal-ws-client-echo) set(SRCS minimal-ws-client-echo.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_ROLE_WS 1 requirements) -require_lws_config(LWS_WITHOUT_CLIENT 0 requirements) +require_lws_config(LWS_WITH_CLIENT 1 requirements) require_lws_config(LWS_WITHOUT_EXTENSIONS 0 requirements) if (requirements) add_executable(${SAMP} ${SRCS}) if (websockets_shared) - target_link_libraries(${SAMP} websockets_shared) + target_link_libraries(${SAMP} websockets_shared ${LIBWEBSOCKETS_DEP_LIBS}) add_dependencies(${SAMP} websockets_shared) else() - target_link_libraries(${SAMP} websockets) + target_link_libraries(${SAMP} websockets ${LIBWEBSOCKETS_DEP_LIBS}) endif() endif() diff -Nru libwebsockets-3.2.1/minimal-examples/ws-client/minimal-ws-client-echo/protocol_lws_minimal_client_echo.c libwebsockets-4.1.6/minimal-examples/ws-client/minimal-ws-client-echo/protocol_lws_minimal_client_echo.c --- libwebsockets-3.2.1/minimal-examples/ws-client/minimal-ws-client-echo/protocol_lws_minimal_client_echo.c 2019-12-18 14:45:31.000000000 +0000 +++ libwebsockets-4.1.6/minimal-examples/ws-client/minimal-ws-client-echo/protocol_lws_minimal_client_echo.c 2020-12-01 17:40:26.000000000 +0000 @@ -43,6 +43,8 @@ struct lws_vhost *vhost; struct lws *client_wsi; + lws_sorted_usec_list_t sul; + int *interrupted; int *options; const char **url; @@ -51,9 +53,11 @@ int *port; }; -static int -connect_client(struct vhd_minimal_client_echo *vhd) +static void +sul_connect_attempt(struct lws_sorted_usec_list *sul) { + struct vhd_minimal_client_echo *vhd = + lws_container_of(sul, struct vhd_minimal_client_echo, sul); struct lws_client_connect_info i; char host[128]; @@ -77,7 +81,9 @@ lwsl_user("connecting to %s:%d/%s\n", i.address, i.port, i.path); - return !lws_client_connect_via_info(&i); + if (!lws_client_connect_via_info(&i)) + lws_sul_schedule(vhd->context, 0, &vhd->sul, + sul_connect_attempt, 10 * LWS_US_PER_SEC); } static void @@ -90,13 +96,6 @@ msg->len = 0; } -static void -schedule_callback(struct lws *wsi, int reason, int secs) -{ - lws_timed_callback_vh_protocol(lws_get_vhost(wsi), - lws_get_protocol(wsi), reason, secs); -} - static int callback_minimal_client_echo(struct lws *wsi, enum lws_callback_reasons reason, void *user, void *in, size_t len) @@ -142,8 +141,11 @@ (const struct lws_protocol_vhost_options *)in, "iface")->value; - if (connect_client(vhd)) - schedule_callback(wsi, LWS_CALLBACK_USER, 1); + sul_connect_attempt(&vhd->sul); + break; + + case LWS_CALLBACK_PROTOCOL_DESTROY: + lws_sul_cancel(&vhd->sul); break; case LWS_CALLBACK_CLIENT_ESTABLISHED: @@ -250,32 +252,18 @@ lwsl_err("CLIENT_CONNECTION_ERROR: %s\n", in ? (char *)in : "(null)"); vhd->client_wsi = NULL; - //schedule_callback(wsi, LWS_CALLBACK_USER, 1); - //if (*vhd->options & 1) { - if (!*vhd->interrupted) - *vhd->interrupted = 3; - lws_cancel_service(lws_get_context(wsi)); - //} + if (!*vhd->interrupted) + *vhd->interrupted = 3; + lws_cancel_service(lws_get_context(wsi)); break; case LWS_CALLBACK_CLIENT_CLOSED: lwsl_user("LWS_CALLBACK_CLIENT_CLOSED\n"); lws_ring_destroy(pss->ring); vhd->client_wsi = NULL; - // schedule_callback(wsi, LWS_CALLBACK_USER, 1); - //if (*vhd->options & 1) { - if (!*vhd->interrupted) - *vhd->interrupted = 1 + pss->completed; - lws_cancel_service(lws_get_context(wsi)); - // } - break; - - /* rate-limited client connect retries */ - - case LWS_CALLBACK_USER: - lwsl_notice("%s: LWS_CALLBACK_USER\n", __func__); - if (connect_client(vhd)) - schedule_callback(wsi, LWS_CALLBACK_USER, 1); + if (!*vhd->interrupted) + *vhd->interrupted = 1 + pss->completed; + lws_cancel_service(lws_get_context(wsi)); break; default: @@ -293,36 +281,3 @@ 1024, \ 0, NULL, 0 \ } - -#if !defined (LWS_PLUGIN_STATIC) - -/* boilerplate needed if we are built as a dynamic plugin */ - -static const struct lws_protocols protocols[] = { - LWS_PLUGIN_PROTOCOL_MINIMAL_CLIENT_ECHO -}; - -LWS_EXTERN LWS_VISIBLE int -init_protocol_minimal_client_echo(struct lws_context *context, - struct lws_plugin_capability *c) -{ - if (c->api_magic != LWS_PLUGIN_API_MAGIC) { - lwsl_err("Plugin API %d, library API %d", LWS_PLUGIN_API_MAGIC, - c->api_magic); - return 1; - } - - c->protocols = protocols; - c->count_protocols = LWS_ARRAY_SIZE(protocols); - c->extensions = NULL; - c->count_extensions = 0; - - return 0; -} - -LWS_EXTERN LWS_VISIBLE int -destroy_protocol_minimal_client_echo(struct lws_context *context) -{ - return 0; -} -#endif diff -Nru libwebsockets-3.2.1/minimal-examples/ws-client/minimal-ws-client-ping/CMakeLists.txt libwebsockets-4.1.6/minimal-examples/ws-client/minimal-ws-client-ping/CMakeLists.txt --- libwebsockets-3.2.1/minimal-examples/ws-client/minimal-ws-client-ping/CMakeLists.txt 2019-12-18 14:45:31.000000000 +0000 +++ libwebsockets-4.1.6/minimal-examples/ws-client/minimal-ws-client-ping/CMakeLists.txt 2020-12-01 17:40:26.000000000 +0000 @@ -1,90 +1,26 @@ +project(lws-minimal-ws-client-ping C) cmake_minimum_required(VERSION 2.8) +find_package(libwebsockets CONFIG REQUIRED) +list(APPEND CMAKE_MODULE_PATH ${LWS_CMAKE_DIR}) include(CheckIncludeFile) include(CheckCSourceCompiles) +include(LwsCheckRequirements) set(SAMP lws-minimal-ws-client-ping) set(SRCS minimal-ws-client-ping.c) -MACRO(require_pthreads result) - CHECK_INCLUDE_FILE(pthread.h LWS_HAVE_PTHREAD_H) - if (NOT LWS_HAVE_PTHREAD_H) - if (LWS_WITH_MINIMAL_EXAMPLES) - set(result 0) - else() - message(FATAL_ERROR "threading support requires pthreads") - endif() - endif() -ENDMACRO() -# 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_pthreads(requirements) require_lws_config(LWS_ROLE_WS 1 requirements) -require_lws_config(LWS_WITHOUT_CLIENT 0 requirements) +require_lws_config(LWS_WITH_CLIENT 1 requirements) if (requirements) add_executable(${SAMP} ${SRCS}) if (websockets_shared) - target_link_libraries(${SAMP} websockets_shared pthread) - add_dependencies(${SAMP} websockets_shared pthread) + target_link_libraries(${SAMP} websockets_shared ${PTHREAD_LIB} ${LIBWEBSOCKETS_DEP_LIBS}) + add_dependencies(${SAMP} websockets_shared) else() - target_link_libraries(${SAMP} websockets pthread) + target_link_libraries(${SAMP} websockets ${PTHREAD_LIB} ${LIBWEBSOCKETS_DEP_LIBS}) endif() endif() diff -Nru libwebsockets-3.2.1/minimal-examples/ws-client/minimal-ws-client-ping/libwebsockets.org.cer libwebsockets-4.1.6/minimal-examples/ws-client/minimal-ws-client-ping/libwebsockets.org.cer --- libwebsockets-3.2.1/minimal-examples/ws-client/minimal-ws-client-ping/libwebsockets.org.cer 2019-12-18 14:45:31.000000000 +0000 +++ libwebsockets-4.1.6/minimal-examples/ws-client/minimal-ws-client-ping/libwebsockets.org.cer 2020-12-01 17:40:26.000000000 +0000 @@ -56,3 +56,24 @@ PfZ+G6Z6h7mjem0Y+iWlkYcV4PIWL1iwBi8saCbGS5jN2p8M+X+Q7UNKEkROb3N6 KOqkqm57TH2H3eDJAkSnh6/DNFu0Qg== -----END CERTIFICATE----- + -----BEGIN CERTIFICATE----- +MIIDSjCCAjKgAwIBAgIQRK+wgNajJ7qJMDmGLvhAazANBgkqhkiG9w0BAQUFADA/ +MSQwIgYDVQQKExtEaWdpdGFsIFNpZ25hdHVyZSBUcnVzdCBDby4xFzAVBgNVBAMT +DkRTVCBSb290IENBIFgzMB4XDTAwMDkzMDIxMTIxOVoXDTIxMDkzMDE0MDExNVow +PzEkMCIGA1UEChMbRGlnaXRhbCBTaWduYXR1cmUgVHJ1c3QgQ28uMRcwFQYDVQQD +Ew5EU1QgUm9vdCBDQSBYMzCCASIwDQYJKoZIhvcNAQEBBQADggEPADCCAQoCggEB +AN+v6ZdQCINXtMxiZfaQguzH0yxrMMpb7NnDfcdAwRgUi+DoM3ZJKuM/IUmTrE4O +rz5Iy2Xu/NMhD2XSKtkyj4zl93ewEnu1lcCJo6m67XMuegwGMoOifooUMM0RoOEq +OLl5CjH9UL2AZd+3UWODyOKIYepLYYHsUmu5ouJLGiifSKOeDNoJjj4XLh7dIN9b +xiqKqy69cK3FCxolkHRyxXtqqzTWMIn/5WgTe1QLyNau7Fqckh49ZLOMxt+/yUFw +7BZy1SbsOFU5Q9D8/RhcQPGX69Wam40dutolucbY38EVAjqr2m7xPi71XAicPNaD +aeQQmxkqtilX4+U9m5/wAl0CAwEAAaNCMEAwDwYDVR0TAQH/BAUwAwEB/zAOBgNV +HQ8BAf8EBAMCAQYwHQYDVR0OBBYEFMSnsaR7LHH62+FLkHX/xBVghYkQMA0GCSqG +SIb3DQEBBQUAA4IBAQCjGiybFwBcqR7uKGY3Or+Dxz9LwwmglSBd49lZRNI+DT69 +ikugdB/OEIKcdBodfpga3csTS7MgROSR6cz8faXbauX+5v3gTt23ADq1cEmv8uXr +AvHRAosZy5Q6XkjEGB5YGV8eAlrwDPGxrancWYaLbumR9YbK+rlmM6pZW87ipxZz +R8srzJmwN0jP41ZL9c8PDHIyh8bwRLtTcm1D9SZImlJnt1ir/md2cXjbDaJWFBM5 +JDGFoqgCWjBH4d1QB7wCCZAA62RjYJsWvIjJEubSfZGL+T0yjWW06XyxV3bqxbYo +Ob8VZRzI9neWagqNdwvYkQsEjgfbKbYK7p2CNTUQ +-----END CERTIFICATE----- + diff -Nru libwebsockets-3.2.1/minimal-examples/ws-client/minimal-ws-client-ping/minimal-ws-client-ping.c libwebsockets-4.1.6/minimal-examples/ws-client/minimal-ws-client-ping/minimal-ws-client-ping.c --- libwebsockets-3.2.1/minimal-examples/ws-client/minimal-ws-client-ping/minimal-ws-client-ping.c 2019-12-18 14:45:31.000000000 +0000 +++ libwebsockets-4.1.6/minimal-examples/ws-client/minimal-ws-client-ping/minimal-ws-client-ping.c 2020-12-01 17:40:26.000000000 +0000 @@ -1,35 +1,45 @@ /* * lws-minimal-ws-client-ping * - * Written in 2010-2019 by Andy Green + * Written in 2010-2020 by Andy Green * * This file is made available under the Creative Commons CC0 1.0 * Universal Public Domain Dedication. * - * This demonstrates a ws client that sends pings from time to time and - * shows when it receives the PONG + * This demonstrates keeping a ws connection validated by the lws validity + * timer stuff without having to do anything in the code. Use debug logging + * -d1039 to see lws doing the pings / pongs in the background. */ #include #include #include +#if defined(WIN32) +#define HAVE_STRUCT_TIMESPEC +#if defined(pid_t) +#undef pid_t +#endif +#endif #include static struct lws_context *context; static struct lws *client_wsi; -static int interrupted, zero_length_ping, port = 443, - ssl_connection = LCCSCF_USE_SSL; +static int interrupted, port = 443, ssl_connection = LCCSCF_USE_SSL; static const char *server_address = "libwebsockets.org", *pro = "lws-mirror-protocol"; +static lws_sorted_usec_list_t sul; -struct pss { - int send_a_ping; +static const lws_retry_bo_t retry = { + .secs_since_valid_ping = 3, + .secs_since_valid_hangup = 10, }; -static int -connect_client(void) +static void +connect_cb(lws_sorted_usec_list_t *_sul) { struct lws_client_connect_info i; + lwsl_notice("%s: connecting\n", __func__); + memset(&i, 0, sizeof(i)); i.context = context; @@ -40,91 +50,30 @@ i.origin = i.address; i.ssl_connection = ssl_connection; i.protocol = pro; + i.alpn = "h2;http/1.1"; i.local_protocol_name = "lws-ping-test"; i.pwsi = &client_wsi; + i.retry_and_idle_policy = &retry; - return !lws_client_connect_via_info(&i); + if (!lws_client_connect_via_info(&i)) + lws_sul_schedule(context, 0, _sul, connect_cb, 5 * LWS_USEC_PER_SEC); } static int -callback_minimal_broker(struct lws *wsi, enum lws_callback_reasons reason, - void *user, void *in, size_t len) +callback_minimal_pingtest(struct lws *wsi, enum lws_callback_reasons reason, + void *user, void *in, size_t len) { - struct pss *pss = (struct pss *)user; - int n; switch (reason) { - case LWS_CALLBACK_PROTOCOL_INIT: - goto try; - case LWS_CALLBACK_CLIENT_CONNECTION_ERROR: lwsl_err("CLIENT_CONNECTION_ERROR: %s\n", in ? (char *)in : "(null)"); - client_wsi = NULL; - lws_timed_callback_vh_protocol(lws_get_vhost(wsi), - lws_get_protocol(wsi), LWS_CALLBACK_USER, 1); + lws_sul_schedule(context, 0, &sul, connect_cb, 5 * LWS_USEC_PER_SEC); break; - /* --- client callbacks --- */ - case LWS_CALLBACK_CLIENT_ESTABLISHED: lwsl_user("%s: established\n", __func__); - lws_set_timer_usecs(wsi, 5 * LWS_USEC_PER_SEC); - break; - - case LWS_CALLBACK_CLIENT_WRITEABLE: - if (pss->send_a_ping) { - uint8_t ping[LWS_PRE + 125]; - int m; - - pss->send_a_ping = 0; - n = 0; - if (!zero_length_ping) - n = lws_snprintf((char *)ping + LWS_PRE, 125, - "ping body!"); - - lwsl_user("Sending PING %d...\n", n); - - m = lws_write(wsi, ping + LWS_PRE, n, LWS_WRITE_PING); - if (m < n) { - lwsl_err("sending ping failed: %d\n", m); - - return -1; - } - - lws_callback_on_writable(wsi); - } - break; - - case LWS_CALLBACK_WS_CLIENT_DROP_PROTOCOL: - client_wsi = NULL; - lws_timed_callback_vh_protocol(lws_get_vhost(wsi), - lws_get_protocol(wsi), - LWS_CALLBACK_USER, 1); - break; - - case LWS_CALLBACK_CLIENT_RECEIVE_PONG: - lwsl_user("LWS_CALLBACK_CLIENT_RECEIVE_PONG\n"); - lwsl_hexdump_notice(in, len); - break; - - case LWS_CALLBACK_TIMER: - /* we want to send a ws PING every few seconds */ - pss->send_a_ping = 1; - lws_callback_on_writable(wsi); - lws_set_timer_usecs(wsi, 5 * LWS_USEC_PER_SEC); - break; - - /* rate-limited client connect retries */ - - case LWS_CALLBACK_USER: - lwsl_notice("%s: LWS_CALLBACK_USER\n", __func__); -try: - if (connect_client()) - lws_timed_callback_vh_protocol(lws_get_vhost(wsi), - lws_get_protocol(wsi), - LWS_CALLBACK_USER, 1); break; default: @@ -137,8 +86,8 @@ static const struct lws_protocols protocols[] = { { "lws-ping-test", - callback_minimal_broker, - sizeof(struct pss), + callback_minimal_pingtest, + 0, 0, }, { NULL, NULL, 0, 0 } @@ -174,7 +123,7 @@ info.options = LWS_SERVER_OPTION_DO_SSL_GLOBAL_INIT; info.port = CONTEXT_PORT_NO_LISTEN; /* we do not run any server */ info.protocols = protocols; -#if defined(LWS_WITH_MBEDTLS) +#if defined(LWS_WITH_MBEDTLS) || defined(USE_WOLFSSL) /* * OpenSSL uses the system trust store. mbedTLS has to be told which * CA to trust explicitly. @@ -182,9 +131,6 @@ info.client_ssl_ca_filepath = "./libwebsockets.org.cer"; #endif - if (lws_cmdline_option(argc, argv, "-z")) - zero_length_ping = 1; - if ((p = lws_cmdline_option(argc, argv, "--protocol"))) pro = p; @@ -197,13 +143,6 @@ if ((p = lws_cmdline_option(argc, argv, "--port"))) port = atoi(p); - /* - * since we know this lws context is only ever going to be used with - * one client wsis / fds / sockets at a time, let lws know it doesn't - * have to use the default allocations for fd tables up to ulimit -n. - * It will just allocate for 1 internal and 1 (+ 1 http2 nwsi) that we - * will use. - */ info.fd_limit_per_thread = 1 + 1 + 1; context = lws_create_context(&info); @@ -212,6 +151,8 @@ return 1; } + lws_sul_schedule(context, 0, &sul, connect_cb, 100); + while (n >= 0 && !interrupted) n = lws_service(context, 0); diff -Nru libwebsockets-3.2.1/minimal-examples/ws-client/minimal-ws-client-ping/README.md libwebsockets-4.1.6/minimal-examples/ws-client/minimal-ws-client-ping/README.md --- libwebsockets-3.2.1/minimal-examples/ws-client/minimal-ws-client-ping/README.md 2019-12-18 14:45:31.000000000 +0000 +++ libwebsockets-4.1.6/minimal-examples/ws-client/minimal-ws-client-ping/README.md 2020-12-01 17:40:26.000000000 +0000 @@ -2,7 +2,8 @@ This connects to libwebsockets.org using the lws-mirror-protocol. -It then sends a ws PING every 5s and records any PONG coming back. +It sets a validity regime of testing validity with PING every 3s and failing +if it didn't get the PONG back within 10s. ## build @@ -14,29 +15,103 @@ Option|Meaning ---|--- --d|Set logging verbosity +-d|Set logging verbosity (you want 1039 to see the validity ping / pong) --server|Use a specific server instead of libwebsockets.org, eg `--server localhost`. Implies LCCSCF_ALLOW_SELFSIGNED --port|Use a specific port instead of 443, eg `--port 7681` --z|Send zero-length pings for testing --protocol|Use a specific ws subprotocol rather than lws-mirror-protocol, eg, `--protocol myprotocol` + ## usage Just run it, wait for the connect and then there will be PINGs sent at 5s intervals. ``` - $ ./lws-minimal-ws-client-ping -[2018/05/09 16:55:03:1160] USER: LWS minimal ws client PING -[2018/05/09 16:55:03:1379] NOTICE: Creating Vhost 'default' (serving disabled), 1 protocols, IPv6 off -[2018/05/09 16:55:03:1715] NOTICE: client loaded CA for verification ./libwebsockets.org.cer -[2018/05/09 16:55:03:1717] NOTICE: created client ssl context for default -[2018/05/09 16:55:04:8332] USER: callback_minimal_broker: established -[2018/05/09 16:55:09:8389] USER: Sending PING 10... -[2018/05/09 16:55:10:1491] USER: LWS_CALLBACK_CLIENT_RECEIVE_PONG -[2018/05/09 16:55:10:1494] NOTICE: -[2018/05/09 16:55:10:1514] NOTICE: 0000: 70 69 6E 67 20 62 6F 64 79 21 ping body! -[2018/05/09 16:55:10:1515] NOTICE: + $ ./lws-minimal-ws-client-ping -d1039 +[2020/03/18 13:13:47:1114] U: LWS minimal ws client PING +[2020/03/18 13:13:47:1503] I: Initial logging level 1039 +[2020/03/18 13:13:47:1507] I: Libwebsockets version: 4.0.99 v4.0.0-20-gc6165f868 +[2020/03/18 13:13:47:1508] I: IPV6 not compiled in +[2020/03/18 13:13:47:1512] I: LWS_DEF_HEADER_LEN : 4096 +[2020/03/18 13:13:47:1514] I: LWS_MAX_SMP : 1 +[2020/03/18 13:13:47:1519] I: sizeof (*info) : 720 +[2020/03/18 13:13:47:1520] I: SYSTEM_RANDOM_FILEPATH: '/dev/urandom' +[2020/03/18 13:13:47:1522] I: HTTP2 support : available +[2020/03/18 13:13:47:1552] N: lws_create_context: using ss proxy bind '(null)', port 0, ads '(null)' +[2020/03/18 13:13:47:1557] I: context created +[2020/03/18 13:13:47:1575] I: Using event loop: poll +[2020/03/18 13:13:47:1583] I: Default ALPN advertisment: h2,http/1.1 +[2020/03/18 13:13:47:1585] I: default timeout (secs): 20 +[2020/03/18 13:13:47:1614] I: Threads: 1 each 5 fds +[2020/03/18 13:13:47:1623] I: mem: context: 8152 B (4056 ctx + (1 thr x 4096)) +[2020/03/18 13:13:47:1625] I: mem: http hdr size: (4096 + 976), max count 5 +[2020/03/18 13:13:47:1629] I: mem: pollfd map: 40 B +[2020/03/18 13:13:47:1633] I: mem: platform fd map: 40 B +[2020/03/18 13:13:47:1692] I: Compiled with OpenSSL support +[2020/03/18 13:13:47:1695] I: Doing SSL library init +[2020/03/18 13:13:47:3103] I: canonical_hostname = constance +[2020/03/18 13:13:47:3140] I: Creating Vhost 'default' (serving disabled), 4 protocols, IPv6 off +[2020/03/18 13:13:47:4072] I: lws_tls_client_create_vhost_context: vh default: created new client ctx 0 +[2020/03/18 13:13:47:7468] I: created client ssl context for default +[2020/03/18 13:13:47:7482] I: Creating Vhost 'default' (serving disabled), 4 protocols, IPv6 off +[2020/03/18 13:13:47:7490] I: lws_tls_client_create_vhost_context: vh default: reusing client ctx 0: use 2 +[2020/03/18 13:13:47:7491] I: created client ssl context for default +[2020/03/18 13:13:47:7494] I: mem: per-conn: 792 bytes + protocol rx buf +[2020/03/18 13:13:47:7497] I: lws_plat_drop_app_privileges: not changing group +[2020/03/18 13:13:47:7499] I: lws_plat_drop_app_privileges: not changing user +[2020/03/18 13:13:47:7512] I: lws_cancel_service +[2020/03/18 13:13:47:7568] I: lws_state_notify_protocol_init: LWS_SYSTATE_CPD_PRE_TIME +[2020/03/18 13:13:47:7577] N: lws_ss_create: unknown stream type captive_portal_detect +[2020/03/18 13:13:47:7580] I: lws_ss_sys_cpd: Create stream failed (policy?) +[2020/03/18 13:13:47:7582] I: lws_state_notify_protocol_init: LWS_SYSTATE_CPD_PRE_TIME +[2020/03/18 13:13:47:7582] N: lws_ss_create: unknown stream type captive_portal_detect +[2020/03/18 13:13:47:7583] I: lws_ss_sys_cpd: Create stream failed (policy?) +[2020/03/18 13:13:47:7585] I: lws_state_notify_protocol_init: doing protocol init on POLICY_VALID +[2020/03/18 13:13:47:7588] I: lws_protocol_init +[2020/03/18 13:13:47:7623] I: lws_state_transition_steps: CONTEXT_CREATED -> OPERATIONAL +[2020/03/18 13:13:47:7628] N: connect_cb: connecting +[2020/03/18 13:13:47:7656] I: lws_client_connect_via_info: role binding to h1 +[2020/03/18 13:13:47:7662] I: lws_client_connect_via_info: protocol binding to lws-ping-test +[2020/03/18 13:13:47:7699] I: lws_client_connect_via_info: wsi 0x5669090: h1 lws-ping-test entry +[2020/03/18 13:13:47:7720] I: lws_header_table_attach: wsi 0x5669090: ah (nil) (tsi 0, count = 0) in +[2020/03/18 13:13:47:7729] I: _lws_create_ah: created ah 0x5669620 (size 4096): pool length 1 +[2020/03/18 13:13:47:7735] I: lws_header_table_attach: did attach wsi 0x5669090: ah 0x5669620: count 1 (on exit) +[2020/03/18 13:13:47:7780] I: lws_client_connect_2_dnsreq: 0x5669090: lookup libwebsockets.org:443 +[2020/03/18 13:13:47:8784] I: lws_getaddrinfo46: getaddrinfo 'libwebsockets.org' says 0 +[2020/03/18 13:13:47:8804] I: lws_client_connect_3_connect: libwebsockets.org ipv4 46.105.127.147 +[2020/03/18 13:13:47:9176] I: lws_client_connect_3_connect: getsockopt check: conn OK +[2020/03/18 13:13:47:9179] I: lws_client_connect_3_connect: Connection started 0x5682cc0 +[2020/03/18 13:13:47:9197] I: lws_client_connect_4_established: wsi 0x5669090: h1 lws-ping-test client created own conn (raw 0) vh defaultm st 0x202 +[2020/03/18 13:13:47:9418] I: h1 client conn using alpn list 'http/1.1' +[2020/03/18 13:13:48:4523] I: lws_role_call_alpn_negotiated: 'http/1.1' +[2020/03/18 13:13:48:4531] I: client connect OK +[2020/03/18 13:13:48:4543] I: lws_openssl_describe_cipher: wsi 0x5669090: TLS_AES_256_GCM_SHA384, TLS_AES_256_GCM_SHA384, 256 bits, TLSv1.3 +[2020/03/18 13:13:48:4717] I: lws_client_socket_service: HANDSHAKE2: 0x5669090: sending headers (wsistate 0x10000204), w sock 5 +[2020/03/18 13:13:48:4992] I: lws_buflist_aware_read: wsi 0x5669090: lws_client_socket_service: ssl_capable_read -4 +[2020/03/18 13:13:48:5005] I: lws_buflist_aware_read: wsi 0x5669090: lws_client_socket_service: ssl_capable_read 174 +[2020/03/18 13:13:48:5166] I: __lws_header_table_detach: wsi 0x5669090: ah 0x5669620 (tsi=0, count = 1) +[2020/03/18 13:13:48:5171] I: __lws_header_table_detach: nobody usable waiting +[2020/03/18 13:13:48:5175] I: _lws_destroy_ah: freed ah 0x5669620 : pool length 0 +[2020/03/18 13:13:48:5180] I: __lws_header_table_detach: wsi 0x5669090: ah 0x5669620 (tsi=0, count = 0) +[2020/03/18 13:13:48:5197] I: _lws_validity_confirmed_role: wsi 0x5669090: setting validity timer 3s (hup 0) +[2020/03/18 13:13:48:5208] U: callback_minimal_broker: established +[2020/03/18 13:13:51:5218] I: lws_validity_cb: wsi 0x5669090: scheduling validity check +[2020/03/18 13:13:51:5325] I: rops_handle_POLLOUT_ws: issuing ping on wsi 0x5669090: ws lws-ping-test h2: 0 +[2020/03/18 13:13:51:5504] I: lws_issue_raw: ssl_capable_write (6) says 6 +[2020/03/18 13:13:51:5809] I: lws_ws_client_rx_sm: client 0x5669090 received pong +[2020/03/18 13:13:51:5819] I: _lws_validity_confirmed_role: wsi 0x5669090: setting validity timer 3s (hup 0) +[2020/03/18 13:13:51:5831] I: Client doing pong callback +[2020/03/18 13:13:54:5821] I: lws_validity_cb: wsi 0x5669090: scheduling validity check +[2020/03/18 13:13:54:5825] I: rops_handle_POLLOUT_ws: issuing ping on wsi 0x5669090: ws lws-ping-test h2: 0 +[2020/03/18 13:13:54:5833] I: lws_issue_raw: ssl_capable_write (6) says 6 +[2020/03/18 13:13:54:6258] I: lws_ws_client_rx_sm: client 0x5669090 received pong +[2020/03/18 13:13:54:6261] I: _lws_validity_confirmed_role: wsi 0x5669090: setting validity timer 3s (hup 0) +[2020/03/18 13:13:54:6263] I: Client doing pong callback +[2020/03/18 13:13:57:6263] I: lws_validity_cb: wsi 0x5669090: scheduling validity check +[2020/03/18 13:13:57:6267] I: rops_handle_POLLOUT_ws: issuing ping on wsi 0x5669090: ws lws-ping-test h2: 0 +[2020/03/18 13:13:57:6275] I: lws_issue_raw: ssl_capable_write (6) says 6 +[2020/03/18 13:13:58:0034] I: lws_ws_client_rx_sm: client 0x5669090 received pong + ... ``` diff -Nru libwebsockets-3.2.1/minimal-examples/ws-client/minimal-ws-client-pmd-bulk/CMakeLists.txt libwebsockets-4.1.6/minimal-examples/ws-client/minimal-ws-client-pmd-bulk/CMakeLists.txt --- libwebsockets-3.2.1/minimal-examples/ws-client/minimal-ws-client-pmd-bulk/CMakeLists.txt 2019-12-18 14:45:31.000000000 +0000 +++ libwebsockets-4.1.6/minimal-examples/ws-client/minimal-ws-client-pmd-bulk/CMakeLists.txt 2020-12-01 17:40:26.000000000 +0000 @@ -1,79 +1,25 @@ +project(lws-minimal-ws-client-pmd-bulk C) cmake_minimum_required(VERSION 2.8.9) +find_package(libwebsockets CONFIG REQUIRED) +list(APPEND CMAKE_MODULE_PATH ${LWS_CMAKE_DIR}) include(CheckCSourceCompiles) +include(LwsCheckRequirements) set(SAMP lws-minimal-ws-client-pmd-bulk) set(SRCS minimal-ws-client-pmd-bulk.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_ROLE_WS 1 requirements) -require_lws_config(LWS_WITHOUT_CLIENT 0 requirements) +require_lws_config(LWS_WITH_CLIENT 1 requirements) #require_lws_config(LWS_WITHOUT_EXTENSIONS 0 requirements) if (requirements) add_executable(${SAMP} ${SRCS}) if (websockets_shared) - target_link_libraries(${SAMP} websockets_shared) + target_link_libraries(${SAMP} websockets_shared ${LIBWEBSOCKETS_DEP_LIBS}) add_dependencies(${SAMP} websockets_shared) else() - target_link_libraries(${SAMP} websockets) + target_link_libraries(${SAMP} websockets ${LIBWEBSOCKETS_DEP_LIBS}) endif() endif() diff -Nru libwebsockets-3.2.1/minimal-examples/ws-client/minimal-ws-client-pmd-bulk/protocol_lws_minimal_pmd_bulk.c libwebsockets-4.1.6/minimal-examples/ws-client/minimal-ws-client-pmd-bulk/protocol_lws_minimal_pmd_bulk.c --- libwebsockets-3.2.1/minimal-examples/ws-client/minimal-ws-client-pmd-bulk/protocol_lws_minimal_pmd_bulk.c 2019-12-18 14:45:31.000000000 +0000 +++ libwebsockets-4.1.6/minimal-examples/ws-client/minimal-ws-client-pmd-bulk/protocol_lws_minimal_pmd_bulk.c 2020-12-01 17:40:26.000000000 +0000 @@ -65,6 +65,8 @@ struct lws_vhost *vhost; struct lws *client_wsi; + lws_sorted_usec_list_t sul; + int *interrupted; int *options; }; @@ -78,9 +80,11 @@ return *r; } -static int -connect_client(struct vhd_minimal_pmd_bulk *vhd) +static void +sul_connect_attempt(struct lws_sorted_usec_list *sul) { + struct vhd_minimal_pmd_bulk *vhd = + lws_container_of(sul, struct vhd_minimal_pmd_bulk, sul); struct lws_client_connect_info i; memset(&i, 0, sizeof(i)); @@ -96,14 +100,9 @@ i.protocol = "lws-minimal-pmd-bulk"; i.pwsi = &vhd->client_wsi; - return !lws_client_connect_via_info(&i); -} - -static void -schedule_callback(struct lws *wsi, int reason, int secs) -{ - lws_timed_callback_vh_protocol(lws_get_vhost(wsi), - lws_get_protocol(wsi), reason, secs); + if (!lws_client_connect_via_info(&i)) + lws_sul_schedule(vhd->context, 0, &vhd->sul, + sul_connect_attempt, 10 * LWS_US_PER_SEC); } static int @@ -138,8 +137,11 @@ (const struct lws_protocol_vhost_options *)in, "options")->value; - if (connect_client(vhd)) - schedule_callback(wsi, LWS_CALLBACK_USER, 1); + sul_connect_attempt(&vhd->sul); + break; + + case LWS_CALLBACK_PROTOCOL_DESTROY: + lws_sul_cancel(&vhd->sul); break; case LWS_CALLBACK_CLIENT_ESTABLISHED: @@ -181,14 +183,14 @@ if (s > (size_t)n) s = n; memcpy(p, &redundant_string[m], s); - pss->position_tx += s; + pss->position_tx += (int)s; p += s; - n -= s; + n -= (int)s; } } else { pss->position_tx += n; while (n--) - *p++ = rng(&pss->rng_tx); + *p++ = (uint8_t)rng(&pss->rng_tx); } n = lws_ptr_diff(p, start); @@ -227,13 +229,13 @@ lwsl_user("echo'd data doesn't match\n"); return -1; } - pss->position_rx += s; + pss->position_rx += (int)s; in = ((unsigned char *)in) + s; len -= s; } } else { p = (uint8_t *)in; - pss->position_rx += len; + pss->position_rx += (int)len; while (len--) if (*p++ != (uint8_t)rng(&pss->rng_rx)) { lwsl_user("echo'd data doesn't match\n"); @@ -253,20 +255,14 @@ lwsl_err("CLIENT_CONNECTION_ERROR: %s\n", in ? (char *)in : "(null)"); vhd->client_wsi = NULL; - schedule_callback(wsi, LWS_CALLBACK_USER, 1); + lws_sul_schedule(vhd->context, 0, &vhd->sul, + sul_connect_attempt, LWS_US_PER_SEC); break; case LWS_CALLBACK_CLIENT_CLOSED: vhd->client_wsi = NULL; - schedule_callback(wsi, LWS_CALLBACK_USER, 1); - break; - - /* rate-limited client connect retries */ - - case LWS_CALLBACK_USER: - lwsl_notice("%s: LWS_CALLBACK_USER\n", __func__); - if (connect_client(vhd)) - schedule_callback(wsi, LWS_CALLBACK_USER, 1); + lws_sul_schedule(vhd->context, 0, &vhd->sul, + sul_connect_attempt, LWS_US_PER_SEC); break; default: @@ -284,36 +280,3 @@ 4096, \ 0, NULL, 0 \ } - -#if !defined (LWS_PLUGIN_STATIC) - -/* boilerplate needed if we are built as a dynamic plugin */ - -static const struct lws_protocols protocols[] = { - LWS_PLUGIN_PROTOCOL_MINIMAL_PMD_BULK -}; - -LWS_EXTERN LWS_VISIBLE int -init_protocol_minimal_pmd_bulk(struct lws_context *context, - struct lws_plugin_capability *c) -{ - if (c->api_magic != LWS_PLUGIN_API_MAGIC) { - lwsl_err("Plugin API %d, library API %d", LWS_PLUGIN_API_MAGIC, - c->api_magic); - return 1; - } - - c->protocols = protocols; - c->count_protocols = LWS_ARRAY_SIZE(protocols); - c->extensions = NULL; - c->count_extensions = 0; - - return 0; -} - -LWS_EXTERN LWS_VISIBLE int -destroy_protocol_minimal_pmd_bulk(struct lws_context *context) -{ - return 0; -} -#endif diff -Nru libwebsockets-3.2.1/minimal-examples/ws-client/minimal-ws-client-rx/CMakeLists.txt libwebsockets-4.1.6/minimal-examples/ws-client/minimal-ws-client-rx/CMakeLists.txt --- libwebsockets-3.2.1/minimal-examples/ws-client/minimal-ws-client-rx/CMakeLists.txt 2019-12-18 14:45:31.000000000 +0000 +++ libwebsockets-4.1.6/minimal-examples/ws-client/minimal-ws-client-rx/CMakeLists.txt 2020-12-01 17:40:26.000000000 +0000 @@ -1,78 +1,32 @@ +project(lws-minimal-ws-client-rx C) cmake_minimum_required(VERSION 2.8) +find_package(libwebsockets CONFIG REQUIRED) +list(APPEND CMAKE_MODULE_PATH ${LWS_CMAKE_DIR}) include(CheckCSourceCompiles) +include(LwsCheckRequirements) set(SAMP lws-minimal-ws-client-rx) set(SRCS minimal-ws-client.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_ROLE_WS 1 requirements) -require_lws_config(LWS_WITHOUT_CLIENT 0 requirements) +require_lws_config(LWS_WITH_CLIENT 1 requirements) if (requirements) add_executable(${SAMP} ${SRCS}) + if (LWS_CTEST_INTERNET_AVAILABLE) + add_test(NAME ws-client-rx-warmcat COMMAND lws-minimal-ws-client-rx -t) + set_tests_properties(ws-client-rx-warmcat + PROPERTIES + WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}/minimal-examples/ws-client/minimal-ws-client-rx + TIMEOUT 20) + + endif() if (websockets_shared) - target_link_libraries(${SAMP} websockets_shared) + target_link_libraries(${SAMP} websockets_shared ${LIBWEBSOCKETS_DEP_LIBS}) add_dependencies(${SAMP} websockets_shared) else() - target_link_libraries(${SAMP} websockets) + target_link_libraries(${SAMP} websockets ${LIBWEBSOCKETS_DEP_LIBS}) endif() -endif() \ No newline at end of file +endif() diff -Nru libwebsockets-3.2.1/minimal-examples/ws-client/minimal-ws-client-rx/libwebsockets.org.cer libwebsockets-4.1.6/minimal-examples/ws-client/minimal-ws-client-rx/libwebsockets.org.cer --- libwebsockets-3.2.1/minimal-examples/ws-client/minimal-ws-client-rx/libwebsockets.org.cer 2019-12-18 14:45:31.000000000 +0000 +++ libwebsockets-4.1.6/minimal-examples/ws-client/minimal-ws-client-rx/libwebsockets.org.cer 2020-12-01 17:40:26.000000000 +0000 @@ -56,3 +56,24 @@ PfZ+G6Z6h7mjem0Y+iWlkYcV4PIWL1iwBi8saCbGS5jN2p8M+X+Q7UNKEkROb3N6 KOqkqm57TH2H3eDJAkSnh6/DNFu0Qg== -----END CERTIFICATE----- + -----BEGIN CERTIFICATE----- +MIIDSjCCAjKgAwIBAgIQRK+wgNajJ7qJMDmGLvhAazANBgkqhkiG9w0BAQUFADA/ +MSQwIgYDVQQKExtEaWdpdGFsIFNpZ25hdHVyZSBUcnVzdCBDby4xFzAVBgNVBAMT +DkRTVCBSb290IENBIFgzMB4XDTAwMDkzMDIxMTIxOVoXDTIxMDkzMDE0MDExNVow +PzEkMCIGA1UEChMbRGlnaXRhbCBTaWduYXR1cmUgVHJ1c3QgQ28uMRcwFQYDVQQD +Ew5EU1QgUm9vdCBDQSBYMzCCASIwDQYJKoZIhvcNAQEBBQADggEPADCCAQoCggEB +AN+v6ZdQCINXtMxiZfaQguzH0yxrMMpb7NnDfcdAwRgUi+DoM3ZJKuM/IUmTrE4O +rz5Iy2Xu/NMhD2XSKtkyj4zl93ewEnu1lcCJo6m67XMuegwGMoOifooUMM0RoOEq +OLl5CjH9UL2AZd+3UWODyOKIYepLYYHsUmu5ouJLGiifSKOeDNoJjj4XLh7dIN9b +xiqKqy69cK3FCxolkHRyxXtqqzTWMIn/5WgTe1QLyNau7Fqckh49ZLOMxt+/yUFw +7BZy1SbsOFU5Q9D8/RhcQPGX69Wam40dutolucbY38EVAjqr2m7xPi71XAicPNaD +aeQQmxkqtilX4+U9m5/wAl0CAwEAAaNCMEAwDwYDVR0TAQH/BAUwAwEB/zAOBgNV +HQ8BAf8EBAMCAQYwHQYDVR0OBBYEFMSnsaR7LHH62+FLkHX/xBVghYkQMA0GCSqG +SIb3DQEBBQUAA4IBAQCjGiybFwBcqR7uKGY3Or+Dxz9LwwmglSBd49lZRNI+DT69 +ikugdB/OEIKcdBodfpga3csTS7MgROSR6cz8faXbauX+5v3gTt23ADq1cEmv8uXr +AvHRAosZy5Q6XkjEGB5YGV8eAlrwDPGxrancWYaLbumR9YbK+rlmM6pZW87ipxZz +R8srzJmwN0jP41ZL9c8PDHIyh8bwRLtTcm1D9SZImlJnt1ir/md2cXjbDaJWFBM5 +JDGFoqgCWjBH4d1QB7wCCZAA62RjYJsWvIjJEubSfZGL+T0yjWW06XyxV3bqxbYo +Ob8VZRzI9neWagqNdwvYkQsEjgfbKbYK7p2CNTUQ +-----END CERTIFICATE----- + diff -Nru libwebsockets-3.2.1/minimal-examples/ws-client/minimal-ws-client-rx/minimal-ws-client.c libwebsockets-4.1.6/minimal-examples/ws-client/minimal-ws-client-rx/minimal-ws-client.c --- libwebsockets-3.2.1/minimal-examples/ws-client/minimal-ws-client-rx/minimal-ws-client.c 2019-12-18 14:45:31.000000000 +0000 +++ libwebsockets-4.1.6/minimal-examples/ws-client/minimal-ws-client-rx/minimal-ws-client.c 2020-12-01 17:40:26.000000000 +0000 @@ -99,7 +99,9 @@ info.options = LWS_SERVER_OPTION_DO_SSL_GLOBAL_INIT; info.port = CONTEXT_PORT_NO_LISTEN; /* we do not run any server */ info.protocols = protocols; -#if defined(LWS_WITH_MBEDTLS) + info.timeout_secs = 10; + info.connect_timeout_secs = 30; +#if defined(LWS_WITH_MBEDTLS) || defined(USE_WOLFSSL) /* * OpenSSL uses the system trust store. mbedTLS has to be told which * CA to trust explicitly. diff -Nru libwebsockets-3.2.1/minimal-examples/ws-client/minimal-ws-client-rx/selftest.sh libwebsockets-4.1.6/minimal-examples/ws-client/minimal-ws-client-rx/selftest.sh --- libwebsockets-3.2.1/minimal-examples/ws-client/minimal-ws-client-rx/selftest.sh 2019-12-18 14:45:31.000000000 +0000 +++ libwebsockets-4.1.6/minimal-examples/ws-client/minimal-ws-client-rx/selftest.sh 1970-01-01 00:00:00.000000000 +0000 @@ -1,25 +0,0 @@ -#!/bin/bash -# -# $1: path to minimal example binaries... -# if lws is built with -DLWS_WITH_MINIMAL_EXAMPLES=1 -# that will be ./bin from your build dir -# -# $2: path for logs and results. The results will go -# in a subdir named after the directory this script -# is in -# -# $3: offset for test index count -# -# $4: total test count -# -# $5: path to ./minimal-examples dir in lws -# -# Test return code 0: OK, 254: timed out, other: error indication - -. $5/selftests-library.sh - -COUNT_TESTS=1 - -dotest $1 $2 warmcat -t - -exit $FAILS diff -Nru libwebsockets-3.2.1/minimal-examples/ws-client/minimal-ws-client-spam/CMakeLists.txt libwebsockets-4.1.6/minimal-examples/ws-client/minimal-ws-client-spam/CMakeLists.txt --- libwebsockets-3.2.1/minimal-examples/ws-client/minimal-ws-client-spam/CMakeLists.txt 2019-12-18 14:45:31.000000000 +0000 +++ libwebsockets-4.1.6/minimal-examples/ws-client/minimal-ws-client-spam/CMakeLists.txt 2020-12-01 17:40:26.000000000 +0000 @@ -1,90 +1,73 @@ +project(lws-minimal-ws-client-spam C) cmake_minimum_required(VERSION 2.8) +find_package(libwebsockets CONFIG REQUIRED) +list(APPEND CMAKE_MODULE_PATH ${LWS_CMAKE_DIR}) include(CheckIncludeFile) include(CheckCSourceCompiles) +include(LwsCheckRequirements) set(SAMP lws-minimal-ws-client-spam) set(SRCS minimal-ws-client-spam.c) -MACRO(require_pthreads result) - CHECK_INCLUDE_FILE(pthread.h LWS_HAVE_PTHREAD_H) - if (NOT LWS_HAVE_PTHREAD_H) - if (LWS_WITH_MINIMAL_EXAMPLES) - set(result 0) - else() - message(FATAL_ERROR "threading support requires pthreads") - endif() - endif() -ENDMACRO() -# 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_pthreads(requirements) require_lws_config(LWS_ROLE_WS 1 requirements) -require_lws_config(LWS_WITHOUT_CLIENT 0 requirements) +require_lws_config(LWS_WITH_CLIENT 1 requirements) if (requirements) add_executable(${SAMP} ${SRCS}) + # + # instantiate the server per sai builder instance, they are running in the same + # machine context in parallel so they can tread on each other otherwise + # + set(PORT_WCS_SRV "7620") + if ("$ENV{SAI_INSTANCE_IDX}" STREQUAL "0") + set(PORT_WCS_SRV 7621) + endif() + if ("$ENV{SAI_INSTANCE_IDX}" STREQUAL "1") + set(PORT_WCS_SRV 7622) + endif() + if ("$ENV{SAI_INSTANCE_IDX}" STREQUAL "2") + set(PORT_WCS_SRV 7623) + endif() + if ("$ENV{SAI_INSTANCE_IDX}" STREQUAL "3") + set(PORT_WCS_SRV 7624) + endif() + +# hack +if (WIN32) +else() + +if (LWS_WITH_SERVER) +if (WIN32) + add_test(NAME st_wcs_srv COMMAND cmd.exe /c start /b $ -s --port ${PORT_WCS_SRV}) + add_test(NAME ki_wcs_srv COMMAND taskkill /F /IM $ /T) +else() + add_test(NAME st_wcs_srv COMMAND + ${CMAKE_SOURCE_DIR}/scripts/ctest-background.sh + wcs_srv $ + -r ${CMAKE_SOURCE_DIR}/destdir/usr/local/share/libwebsockets-test-server/ + -s --port ${PORT_WCS_SRV} --ignore-sigterm) + add_test(NAME ki_wcs_srv COMMAND + ${CMAKE_SOURCE_DIR}/scripts/ctest-background-kill.sh + wcs_srv $ --port ${PORT_WCS_SRV}) +endif() + + set_tests_properties(st_wcs_srv PROPERTIES WORKING_DIRECTORY . FIXTURES_SETUP wcs_srv TIMEOUT 800) + set_tests_properties(ki_wcs_srv PROPERTIES FIXTURES_CLEANUP wcs_srv) + + add_test(NAME ws-client-spam COMMAND lws-minimal-ws-client-spam --server localhost --port ${PORT_WCS_SRV} -l 32 -c 3) + set_tests_properties(ws-client-spam PROPERTIES + WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}/minimal-examples/ws-client/minimal-ws-client-spam + FIXTURES_REQUIRED "wcs_srv" + TIMEOUT 40) +endif() +endif() if (websockets_shared) - target_link_libraries(${SAMP} websockets_shared pthread) - add_dependencies(${SAMP} websockets_shared pthread) + target_link_libraries(${SAMP} websockets_shared ${PTHREAD_LIB} ${LIBWEBSOCKETS_DEP_LIBS}) + add_dependencies(${SAMP} websockets_shared) else() - target_link_libraries(${SAMP} websockets pthread) + target_link_libraries(${SAMP} websockets ${PTHREAD_LIB} ${LIBWEBSOCKETS_DEP_LIBS}) endif() endif() diff -Nru libwebsockets-3.2.1/minimal-examples/ws-client/minimal-ws-client-spam/libwebsockets.org.cer libwebsockets-4.1.6/minimal-examples/ws-client/minimal-ws-client-spam/libwebsockets.org.cer --- libwebsockets-3.2.1/minimal-examples/ws-client/minimal-ws-client-spam/libwebsockets.org.cer 2019-12-18 14:45:31.000000000 +0000 +++ libwebsockets-4.1.6/minimal-examples/ws-client/minimal-ws-client-spam/libwebsockets.org.cer 2020-12-01 17:40:26.000000000 +0000 @@ -56,3 +56,24 @@ PfZ+G6Z6h7mjem0Y+iWlkYcV4PIWL1iwBi8saCbGS5jN2p8M+X+Q7UNKEkROb3N6 KOqkqm57TH2H3eDJAkSnh6/DNFu0Qg== -----END CERTIFICATE----- + -----BEGIN CERTIFICATE----- +MIIDSjCCAjKgAwIBAgIQRK+wgNajJ7qJMDmGLvhAazANBgkqhkiG9w0BAQUFADA/ +MSQwIgYDVQQKExtEaWdpdGFsIFNpZ25hdHVyZSBUcnVzdCBDby4xFzAVBgNVBAMT +DkRTVCBSb290IENBIFgzMB4XDTAwMDkzMDIxMTIxOVoXDTIxMDkzMDE0MDExNVow +PzEkMCIGA1UEChMbRGlnaXRhbCBTaWduYXR1cmUgVHJ1c3QgQ28uMRcwFQYDVQQD +Ew5EU1QgUm9vdCBDQSBYMzCCASIwDQYJKoZIhvcNAQEBBQADggEPADCCAQoCggEB +AN+v6ZdQCINXtMxiZfaQguzH0yxrMMpb7NnDfcdAwRgUi+DoM3ZJKuM/IUmTrE4O +rz5Iy2Xu/NMhD2XSKtkyj4zl93ewEnu1lcCJo6m67XMuegwGMoOifooUMM0RoOEq +OLl5CjH9UL2AZd+3UWODyOKIYepLYYHsUmu5ouJLGiifSKOeDNoJjj4XLh7dIN9b +xiqKqy69cK3FCxolkHRyxXtqqzTWMIn/5WgTe1QLyNau7Fqckh49ZLOMxt+/yUFw +7BZy1SbsOFU5Q9D8/RhcQPGX69Wam40dutolucbY38EVAjqr2m7xPi71XAicPNaD +aeQQmxkqtilX4+U9m5/wAl0CAwEAAaNCMEAwDwYDVR0TAQH/BAUwAwEB/zAOBgNV +HQ8BAf8EBAMCAQYwHQYDVR0OBBYEFMSnsaR7LHH62+FLkHX/xBVghYkQMA0GCSqG +SIb3DQEBBQUAA4IBAQCjGiybFwBcqR7uKGY3Or+Dxz9LwwmglSBd49lZRNI+DT69 +ikugdB/OEIKcdBodfpga3csTS7MgROSR6cz8faXbauX+5v3gTt23ADq1cEmv8uXr +AvHRAosZy5Q6XkjEGB5YGV8eAlrwDPGxrancWYaLbumR9YbK+rlmM6pZW87ipxZz +R8srzJmwN0jP41ZL9c8PDHIyh8bwRLtTcm1D9SZImlJnt1ir/md2cXjbDaJWFBM5 +JDGFoqgCWjBH4d1QB7wCCZAA62RjYJsWvIjJEubSfZGL+T0yjWW06XyxV3bqxbYo +Ob8VZRzI9neWagqNdwvYkQsEjgfbKbYK7p2CNTUQ +-----END CERTIFICATE----- + diff -Nru libwebsockets-3.2.1/minimal-examples/ws-client/minimal-ws-client-spam/minimal-ws-client-spam.c libwebsockets-4.1.6/minimal-examples/ws-client/minimal-ws-client-spam/minimal-ws-client-spam.c --- libwebsockets-3.2.1/minimal-examples/ws-client/minimal-ws-client-spam/minimal-ws-client-spam.c 2019-12-18 14:45:31.000000000 +0000 +++ libwebsockets-4.1.6/minimal-examples/ws-client/minimal-ws-client-spam/minimal-ws-client-spam.c 2020-12-01 17:40:26.000000000 +0000 @@ -13,6 +13,12 @@ #include #include #include +#if defined(WIN32) +#define HAVE_STRUCT_TIMESPEC +#if defined(pid_t) +#undef pid_t +#endif +#endif #include enum { @@ -64,6 +70,7 @@ clients[idx].state = CLIENT_CONNECTING; tries++; + lwsl_notice("%s: connection %s:%d\n", __func__, i.address, i.port); if (!lws_client_connect_via_info(&i)) { clients[idx].wsi = NULL; clients[idx].state = CLIENT_IDLE; @@ -199,7 +206,7 @@ info.options = LWS_SERVER_OPTION_DO_SSL_GLOBAL_INIT; info.port = CONTEXT_PORT_NO_LISTEN; /* we do not run any server */ info.protocols = protocols; -#if defined(LWS_WITH_MBEDTLS) +#if defined(LWS_WITH_MBEDTLS) || defined(USE_WOLFSSL) /* * OpenSSL uses the system trust store. mbedTLS has to be told which * CA to trust explicitly. @@ -252,6 +259,8 @@ while (n >= 0 && !interrupted) n = lws_service(context, 0); + lwsl_notice("%s: exiting service loop\n", __func__); + lws_context_destroy(context); if (tries == limit && closed == tries) { diff -Nru libwebsockets-3.2.1/minimal-examples/ws-client/minimal-ws-client-spam/selftest.sh libwebsockets-4.1.6/minimal-examples/ws-client/minimal-ws-client-spam/selftest.sh --- libwebsockets-3.2.1/minimal-examples/ws-client/minimal-ws-client-spam/selftest.sh 2019-12-18 14:45:31.000000000 +0000 +++ libwebsockets-4.1.6/minimal-examples/ws-client/minimal-ws-client-spam/selftest.sh 1970-01-01 00:00:00.000000000 +0000 @@ -1,26 +0,0 @@ -#!/bin/bash -# -# $1: path to minimal example binaries... -# if lws is built with -DLWS_WITH_MINIMAL_EXAMPLES=1 -# that will be ./bin from your build dir -# -# $2: path for logs and results. The results will go -# in a subdir named after the directory this script -# is in -# -# $3: offset for test index count -# -# $4: total test count -# -# $5: path to ./minimal-examples dir in lws -# -# Test return code 0: OK, 254: timed out, other: error indication - -. $5/selftests-library.sh - -COUNT_TESTS=1 - -dotest $1 $2 warmcat - -exit $FAILS - diff -Nru libwebsockets-3.2.1/minimal-examples/ws-client/minimal-ws-client-tx/CMakeLists.txt libwebsockets-4.1.6/minimal-examples/ws-client/minimal-ws-client-tx/CMakeLists.txt --- libwebsockets-3.2.1/minimal-examples/ws-client/minimal-ws-client-tx/CMakeLists.txt 2019-12-18 14:45:31.000000000 +0000 +++ libwebsockets-4.1.6/minimal-examples/ws-client/minimal-ws-client-tx/CMakeLists.txt 2020-12-01 17:40:26.000000000 +0000 @@ -1,90 +1,26 @@ +project(lws-minimal-ws-client-tx C) cmake_minimum_required(VERSION 2.8) +find_package(libwebsockets CONFIG REQUIRED) +list(APPEND CMAKE_MODULE_PATH ${LWS_CMAKE_DIR}) include(CheckIncludeFile) include(CheckCSourceCompiles) +include(LwsCheckRequirements) set(SAMP lws-minimal-ws-client-tx) set(SRCS minimal-ws-client.c) -MACRO(require_pthreads result) - CHECK_INCLUDE_FILE(pthread.h LWS_HAVE_PTHREAD_H) - if (NOT LWS_HAVE_PTHREAD_H) - if (LWS_WITH_MINIMAL_EXAMPLES) - set(result 0) - else() - message(FATAL_ERROR "threading support requires pthreads") - endif() - endif() -ENDMACRO() -# 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_pthreads(requirements) require_lws_config(LWS_ROLE_WS 1 requirements) -require_lws_config(LWS_WITHOUT_CLIENT 0 requirements) +require_lws_config(LWS_WITH_CLIENT 1 requirements) if (requirements) add_executable(${SAMP} ${SRCS}) if (websockets_shared) - target_link_libraries(${SAMP} websockets_shared pthread) - add_dependencies(${SAMP} websockets_shared pthread) + target_link_libraries(${SAMP} websockets_shared ${PTHREAD_LIB} ${LIBWEBSOCKETS_DEP_LIBS}) + add_dependencies(${SAMP} websockets_shared) else() - target_link_libraries(${SAMP} websockets pthread) + target_link_libraries(${SAMP} websockets ${PTHREAD_LIB} ${LIBWEBSOCKETS_DEP_LIBS}) endif() endif() \ No newline at end of file diff -Nru libwebsockets-3.2.1/minimal-examples/ws-client/minimal-ws-client-tx/minimal-ws-client.c libwebsockets-4.1.6/minimal-examples/ws-client/minimal-ws-client-tx/minimal-ws-client.c --- libwebsockets-3.2.1/minimal-examples/ws-client/minimal-ws-client-tx/minimal-ws-client.c 2019-12-18 14:45:31.000000000 +0000 +++ libwebsockets-4.1.6/minimal-examples/ws-client/minimal-ws-client-tx/minimal-ws-client.c 2020-12-01 17:40:26.000000000 +0000 @@ -21,6 +21,12 @@ #include #include #include +#if defined(WIN32) +#define HAVE_STRUCT_TIMESPEC +#if defined(pid_t) +#undef pid_t +#endif +#endif #include static int interrupted; @@ -38,6 +44,8 @@ const struct lws_protocols *protocol; pthread_t pthread_spam[2]; + lws_sorted_usec_list_t sul; + pthread_mutex_t lock_ring; /* serialize access to the ring buffer */ struct lws_ring *ring; /* ringbuffer holding unsent messages */ uint32_t tail; @@ -70,7 +78,11 @@ struct per_vhost_data__minimal *vhd = (struct per_vhost_data__minimal *)d; struct msg amsg; - int len = 128, index = 1, n; + int len = 128, index = 1, n, whoami = 0; + + for (n = 0; n < (int)LWS_ARRAY_SIZE(vhd->pthread_spam); n++) + if (pthread_equal(pthread_self(), vhd->pthread_spam[n])) + whoami = n + 1; do { /* don't generate output if client not connected */ @@ -92,10 +104,9 @@ goto wait_unlock; } n = lws_snprintf((char *)amsg.payload + LWS_PRE, len, - "tid: %p, msg: %d", - (void *)pthread_self(), index++); + "tid: %d, msg: %d", whoami, index++); amsg.len = n; - n = lws_ring_insert(vhd->ring, &amsg, 1); + n = (int)lws_ring_insert(vhd->ring, &amsg, 1); if (n != 1) { __minimal_destroy_message(&amsg); lwsl_user("dropping!\n"); @@ -114,16 +125,19 @@ } while (!vhd->finished); - lwsl_notice("thread_spam %p exiting\n", (void *)pthread_self()); + lwsl_notice("thread_spam %d exiting\n", whoami); pthread_exit(NULL); return NULL; } -static int -connect_client(struct per_vhost_data__minimal *vhd) +static void +sul_connect_attempt(struct lws_sorted_usec_list *sul) { + struct per_vhost_data__minimal *vhd = + lws_container_of(sul, struct per_vhost_data__minimal, sul); + vhd->i.context = vhd->context; vhd->i.port = 7681; vhd->i.address = "localhost"; @@ -135,7 +149,9 @@ vhd->i.protocol = "lws-minimal-broker"; vhd->i.pwsi = &vhd->client_wsi; - return !lws_client_connect_via_info(&vhd->i); + if (!lws_client_connect_via_info(&vhd->i)) + lws_sul_schedule(vhd->context, 0, &vhd->sul, + sul_connect_attempt, 10 * LWS_US_PER_SEC); } static int @@ -179,21 +195,19 @@ goto init_fail; } - if (connect_client(vhd)) - lws_timed_callback_vh_protocol(vhd->vhost, - vhd->protocol, LWS_CALLBACK_USER, 1); + sul_connect_attempt(&vhd->sul); break; case LWS_CALLBACK_PROTOCOL_DESTROY: init_fail: vhd->finished = 1; for (n = 0; n < (int)LWS_ARRAY_SIZE(vhd->pthread_spam); n++) - if (vhd->pthread_spam[n]) - pthread_join(vhd->pthread_spam[n], &retval); + pthread_join(vhd->pthread_spam[n], &retval); if (vhd->ring) lws_ring_destroy(vhd->ring); + lws_sul_cancel(&vhd->sul); pthread_mutex_destroy(&vhd->lock_ring); return r; @@ -202,8 +216,8 @@ lwsl_err("CLIENT_CONNECTION_ERROR: %s\n", in ? (char *)in : "(null)"); vhd->client_wsi = NULL; - lws_timed_callback_vh_protocol(vhd->vhost, - vhd->protocol, LWS_CALLBACK_USER, 1); + lws_sul_schedule(vhd->context, 0, &vhd->sul, + sul_connect_attempt, LWS_US_PER_SEC); break; /* --- client callbacks --- */ @@ -242,8 +256,8 @@ case LWS_CALLBACK_CLIENT_CLOSED: vhd->client_wsi = NULL; vhd->established = 0; - lws_timed_callback_vh_protocol(vhd->vhost, vhd->protocol, - LWS_CALLBACK_USER, 1); + lws_sul_schedule(vhd->context, 0, &vhd->sul, + sul_connect_attempt, LWS_US_PER_SEC); break; case LWS_CALLBACK_EVENT_WAIT_CANCELLED: @@ -259,16 +273,6 @@ lws_callback_on_writable(vhd->client_wsi); break; - /* rate-limited client connect retries */ - - case LWS_CALLBACK_USER: - lwsl_notice("%s: LWS_CALLBACK_USER\n", __func__); - if (connect_client(vhd)) - lws_timed_callback_vh_protocol(vhd->vhost, - vhd->protocol, - LWS_CALLBACK_USER, 1); - break; - default: break; } diff -Nru libwebsockets-3.2.1/minimal-examples/ws-client/README.md libwebsockets-4.1.6/minimal-examples/ws-client/README.md --- libwebsockets-3.2.1/minimal-examples/ws-client/README.md 2019-12-18 14:45:31.000000000 +0000 +++ libwebsockets-4.1.6/minimal-examples/ws-client/README.md 2020-12-01 17:40:26.000000000 +0000 @@ -1,5 +1,6 @@ |name|demonstrates| ---|--- +minimal-ws-client|Simple client that connects to libwebsockets.org dumb increment protocol and demonstrates retry and backoff minimal-ws-client-echo|Simple client that connects to a ws server and echos anything the server sends minimal-ws-client-ping|Ws ping test client minimal-ws-client-pmd-bulk|Client that sends bulk multifragment data to the minimal-ws-server-pmd-bulk example diff -Nru libwebsockets-3.2.1/minimal-examples/ws-server/minimal-ws-broker/CMakeLists.txt libwebsockets-4.1.6/minimal-examples/ws-server/minimal-ws-broker/CMakeLists.txt --- libwebsockets-3.2.1/minimal-examples/ws-server/minimal-ws-broker/CMakeLists.txt 2019-12-18 14:45:31.000000000 +0000 +++ libwebsockets-4.1.6/minimal-examples/ws-server/minimal-ws-broker/CMakeLists.txt 2020-12-01 17:40:26.000000000 +0000 @@ -1,77 +1,24 @@ +project(lws-minimal-ws-broker C) cmake_minimum_required(VERSION 2.8) +find_package(libwebsockets CONFIG REQUIRED) +list(APPEND CMAKE_MODULE_PATH ${LWS_CMAKE_DIR}) include(CheckCSourceCompiles) +include(LwsCheckRequirements) set(SAMP lws-minimal-ws-broker) set(SRCS minimal-ws-broker.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_ROLE_WS 1 requirements) -require_lws_config(LWS_WITHOUT_SERVER 0 requirements) +require_lws_config(LWS_WITH_SERVER 1 requirements) if (requirements) add_executable(${SAMP} ${SRCS}) if (websockets_shared) - target_link_libraries(${SAMP} websockets_shared) + target_link_libraries(${SAMP} websockets_shared ${LIBWEBSOCKETS_DEP_LIBS}) add_dependencies(${SAMP} websockets_shared) else() - target_link_libraries(${SAMP} websockets) + target_link_libraries(${SAMP} websockets ${LIBWEBSOCKETS_DEP_LIBS}) endif() endif() \ No newline at end of file diff -Nru libwebsockets-3.2.1/minimal-examples/ws-server/minimal-ws-broker/mount-origin/example.js libwebsockets-4.1.6/minimal-examples/ws-server/minimal-ws-broker/mount-origin/example.js --- libwebsockets-3.2.1/minimal-examples/ws-server/minimal-ws-broker/mount-origin/example.js 2019-12-18 14:45:31.000000000 +0000 +++ libwebsockets-4.1.6/minimal-examples/ws-server/minimal-ws-broker/mount-origin/example.js 2020-12-01 17:40:26.000000000 +0000 @@ -27,15 +27,12 @@ function new_ws(urlpath, protocol) { - if (typeof MozWebSocket != "undefined") - return new MozWebSocket(urlpath, protocol); - return new WebSocket(urlpath, protocol); } document.addEventListener("DOMContentLoaded", function() { - subscriber_ws = new_ws(get_appropriate_ws_url(""), "lws-minimal-broker"); + var subscriber_ws = new_ws(get_appropriate_ws_url(""), "lws-minimal-broker"); try { subscriber_ws.onopen = function() { document.getElementById("b").disabled = 0; @@ -55,7 +52,7 @@ alert("

Error " + exception); } - publisher_ws = new_ws(get_appropriate_ws_url("/publisher"), "lws-minimal-broker"); + var publisher_ws = new_ws(get_appropriate_ws_url("/publisher"), "lws-minimal-broker"); try { publisher_ws.onopen = function() { document.getElementById("m").disabled = 0; diff -Nru libwebsockets-3.2.1/minimal-examples/ws-server/minimal-ws-broker/mount-origin/libwebsockets.org-logo.svg libwebsockets-4.1.6/minimal-examples/ws-server/minimal-ws-broker/mount-origin/libwebsockets.org-logo.svg --- libwebsockets-3.2.1/minimal-examples/ws-server/minimal-ws-broker/mount-origin/libwebsockets.org-logo.svg 2019-12-18 14:45:31.000000000 +0000 +++ libwebsockets-4.1.6/minimal-examples/ws-server/minimal-ws-broker/mount-origin/libwebsockets.org-logo.svg 2020-12-01 17:40:26.000000000 +0000 @@ -1,120 +1,66 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + + +image/svg+xml + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff -Nru libwebsockets-3.2.1/minimal-examples/ws-server/minimal-ws-broker/protocol_lws_minimal.c libwebsockets-4.1.6/minimal-examples/ws-server/minimal-ws-broker/protocol_lws_minimal.c --- libwebsockets-3.2.1/minimal-examples/ws-server/minimal-ws-broker/protocol_lws_minimal.c 2019-12-18 14:45:31.000000000 +0000 +++ libwebsockets-4.1.6/minimal-examples/ws-server/minimal-ws-broker/protocol_lws_minimal.c 2020-12-01 17:40:26.000000000 +0000 @@ -215,36 +215,3 @@ 128, \ 0, NULL, 0 \ } - -#if !defined (LWS_PLUGIN_STATIC) - -/* boilerplate needed if we are built as a dynamic plugin */ - -static const struct lws_protocols protocols[] = { - LWS_PLUGIN_PROTOCOL_MINIMAL -}; - -LWS_EXTERN LWS_VISIBLE int -init_protocol_minimal(struct lws_context *context, - struct lws_plugin_capability *c) -{ - if (c->api_magic != LWS_PLUGIN_API_MAGIC) { - lwsl_err("Plugin API %d, library API %d", LWS_PLUGIN_API_MAGIC, - c->api_magic); - return 1; - } - - c->protocols = protocols; - c->count_protocols = LWS_ARRAY_SIZE(protocols); - c->extensions = NULL; - c->count_extensions = 0; - - return 0; -} - -LWS_EXTERN LWS_VISIBLE int -destroy_protocol_minimal(struct lws_context *context) -{ - return 0; -} -#endif diff -Nru libwebsockets-3.2.1/minimal-examples/ws-server/minimal-ws-server/CMakeLists.txt libwebsockets-4.1.6/minimal-examples/ws-server/minimal-ws-server/CMakeLists.txt --- libwebsockets-3.2.1/minimal-examples/ws-server/minimal-ws-server/CMakeLists.txt 2019-12-18 14:45:31.000000000 +0000 +++ libwebsockets-4.1.6/minimal-examples/ws-server/minimal-ws-server/CMakeLists.txt 2020-12-01 17:40:26.000000000 +0000 @@ -1,78 +1,24 @@ +project(lws-minimal-ws-server C) cmake_minimum_required(VERSION 2.8) +find_package(libwebsockets CONFIG REQUIRED) +list(APPEND CMAKE_MODULE_PATH ${LWS_CMAKE_DIR}) include(CheckCSourceCompiles) +include(LwsCheckRequirements) set(SAMP lws-minimal-ws-server) set(SRCS minimal-ws-server.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_ROLE_WS 1 requirements) -require_lws_config(LWS_WITHOUT_SERVER 0 requirements) +require_lws_config(LWS_WITH_SERVER 1 requirements) if (requirements) add_executable(${SAMP} ${SRCS}) if (websockets_shared) - target_link_libraries(${SAMP} websockets_shared) + target_link_libraries(${SAMP} websockets_shared ${LIBWEBSOCKETS_DEP_LIBS}) add_dependencies(${SAMP} websockets_shared) else() - target_link_libraries(${SAMP} websockets) + target_link_libraries(${SAMP} websockets ${LIBWEBSOCKETS_DEP_LIBS}) endif() endif() \ No newline at end of file diff -Nru libwebsockets-3.2.1/minimal-examples/ws-server/minimal-ws-server/minimal-ws-server.c libwebsockets-4.1.6/minimal-examples/ws-server/minimal-ws-server/minimal-ws-server.c --- libwebsockets-3.2.1/minimal-examples/ws-server/minimal-ws-server/minimal-ws-server.c 2019-12-18 14:45:31.000000000 +0000 +++ libwebsockets-4.1.6/minimal-examples/ws-server/minimal-ws-server/minimal-ws-server.c 2020-12-01 17:40:26.000000000 +0000 @@ -27,6 +27,11 @@ { NULL, NULL, 0, 0 } /* terminator */ }; +static const lws_retry_bo_t retry = { + .secs_since_valid_ping = 3, + .secs_since_valid_hangup = 10, +}; + static int interrupted; static const struct lws_http_mount mount = { @@ -80,20 +85,24 @@ info.mounts = &mount; info.protocols = protocols; info.vhost_name = "localhost"; - info.ws_ping_pong_interval = 10; info.options = LWS_SERVER_OPTION_HTTP_HEADERS_SECURITY_BEST_PRACTICES_ENFORCE; +#if defined(LWS_WITH_TLS) if (lws_cmdline_option(argc, argv, "-s")) { lwsl_user("Server using TLS\n"); info.options |= LWS_SERVER_OPTION_DO_SSL_GLOBAL_INIT; info.ssl_cert_filepath = "localhost-100y.cert"; info.ssl_private_key_filepath = "localhost-100y.key"; } +#endif if (lws_cmdline_option(argc, argv, "-h")) info.options |= LWS_SERVER_OPTION_VHOST_UPG_STRICT_HOST_CHECK; + if (lws_cmdline_option(argc, argv, "-v")) + info.retry_and_idle_policy = &retry; + context = lws_create_context(&info); if (!context) { lwsl_err("lws init failed\n"); diff -Nru libwebsockets-3.2.1/minimal-examples/ws-server/minimal-ws-server/mount-origin/example.js libwebsockets-4.1.6/minimal-examples/ws-server/minimal-ws-server/mount-origin/example.js --- libwebsockets-3.2.1/minimal-examples/ws-server/minimal-ws-server/mount-origin/example.js 2019-12-18 14:45:31.000000000 +0000 +++ libwebsockets-4.1.6/minimal-examples/ws-server/minimal-ws-server/mount-origin/example.js 2020-12-01 17:40:26.000000000 +0000 @@ -27,15 +27,12 @@ function new_ws(urlpath, protocol) { - if (typeof MozWebSocket != "undefined") - return new MozWebSocket(urlpath, protocol); - return new WebSocket(urlpath, protocol); } document.addEventListener("DOMContentLoaded", function() { - ws = new_ws(get_appropriate_ws_url(""), "lws-minimal"); + var ws = new_ws(get_appropriate_ws_url(""), "lws-minimal"); try { ws.onopen = function() { document.getElementById("m").disabled = 0; diff -Nru libwebsockets-3.2.1/minimal-examples/ws-server/minimal-ws-server/mount-origin/libwebsockets.org-logo.svg libwebsockets-4.1.6/minimal-examples/ws-server/minimal-ws-server/mount-origin/libwebsockets.org-logo.svg --- libwebsockets-3.2.1/minimal-examples/ws-server/minimal-ws-server/mount-origin/libwebsockets.org-logo.svg 2019-12-18 14:45:31.000000000 +0000 +++ libwebsockets-4.1.6/minimal-examples/ws-server/minimal-ws-server/mount-origin/libwebsockets.org-logo.svg 2020-12-01 17:40:26.000000000 +0000 @@ -1,120 +1,66 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + + +image/svg+xml + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff -Nru libwebsockets-3.2.1/minimal-examples/ws-server/minimal-ws-server/protocol_lws_minimal.c libwebsockets-4.1.6/minimal-examples/ws-server/minimal-ws-server/protocol_lws_minimal.c --- libwebsockets-3.2.1/minimal-examples/ws-server/minimal-ws-server/protocol_lws_minimal.c 2019-12-18 14:45:31.000000000 +0000 +++ libwebsockets-4.1.6/minimal-examples/ws-server/minimal-ws-server/protocol_lws_minimal.c 2020-12-01 17:40:26.000000000 +0000 @@ -152,36 +152,3 @@ 128, \ 0, NULL, 0 \ } - -#if !defined (LWS_PLUGIN_STATIC) - -/* boilerplate needed if we are built as a dynamic plugin */ - -static const struct lws_protocols protocols[] = { - LWS_PLUGIN_PROTOCOL_MINIMAL -}; - -LWS_EXTERN LWS_VISIBLE int -init_protocol_minimal(struct lws_context *context, - struct lws_plugin_capability *c) -{ - if (c->api_magic != LWS_PLUGIN_API_MAGIC) { - lwsl_err("Plugin API %d, library API %d", LWS_PLUGIN_API_MAGIC, - c->api_magic); - return 1; - } - - c->protocols = protocols; - c->count_protocols = LWS_ARRAY_SIZE(protocols); - c->extensions = NULL; - c->count_extensions = 0; - - return 0; -} - -LWS_EXTERN LWS_VISIBLE int -destroy_protocol_minimal(struct lws_context *context) -{ - return 0; -} -#endif diff -Nru libwebsockets-3.2.1/minimal-examples/ws-server/minimal-ws-server/README.md libwebsockets-4.1.6/minimal-examples/ws-server/minimal-ws-server/README.md --- libwebsockets-3.2.1/minimal-examples/ws-server/minimal-ws-server/README.md 2019-12-18 14:45:31.000000000 +0000 +++ libwebsockets-4.1.6/minimal-examples/ws-server/minimal-ws-server/README.md 2020-12-01 17:40:26.000000000 +0000 @@ -13,6 +13,7 @@ -d|Set logging verbosity -s|Serve using TLS selfsigned cert (ie, connect to it with https://...) -h|Strict Host: header checking against vhost name (localhost) and port +-v|Connection validity use 3s / 10s instead of default 5m / 5m10s ## usage diff -Nru libwebsockets-3.2.1/minimal-examples/ws-server/minimal-ws-server-echo/CMakeLists.txt libwebsockets-4.1.6/minimal-examples/ws-server/minimal-ws-server-echo/CMakeLists.txt --- libwebsockets-3.2.1/minimal-examples/ws-server/minimal-ws-server-echo/CMakeLists.txt 2019-12-18 14:45:31.000000000 +0000 +++ libwebsockets-4.1.6/minimal-examples/ws-server/minimal-ws-server-echo/CMakeLists.txt 2020-12-01 17:40:26.000000000 +0000 @@ -1,79 +1,25 @@ +project(lws-minimal-ws-server-echo C) cmake_minimum_required(VERSION 2.8.9) +find_package(libwebsockets CONFIG REQUIRED) +list(APPEND CMAKE_MODULE_PATH ${LWS_CMAKE_DIR}) include(CheckCSourceCompiles) +include(LwsCheckRequirements) set(SAMP lws-minimal-ws-server-echo) set(SRCS minimal-ws-server-echo.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_ROLE_WS 1 requirements) -require_lws_config(LWS_WITHOUT_SERVER 0 requirements) +require_lws_config(LWS_WITH_SERVER 1 requirements) require_lws_config(LWS_WITHOUT_EXTENSIONS 0 requirements) if (requirements) add_executable(${SAMP} ${SRCS}) if (websockets_shared) - target_link_libraries(${SAMP} websockets_shared) + target_link_libraries(${SAMP} websockets_shared ${LIBWEBSOCKETS_DEP_LIBS}) add_dependencies(${SAMP} websockets_shared) else() - target_link_libraries(${SAMP} websockets) + target_link_libraries(${SAMP} websockets ${LIBWEBSOCKETS_DEP_LIBS}) endif() endif() diff -Nru libwebsockets-3.2.1/minimal-examples/ws-server/minimal-ws-server-echo/protocol_lws_minimal_server_echo.c libwebsockets-4.1.6/minimal-examples/ws-server/minimal-ws-server-echo/protocol_lws_minimal_server_echo.c --- libwebsockets-3.2.1/minimal-examples/ws-server/minimal-ws-server-echo/protocol_lws_minimal_server_echo.c 2019-12-18 14:45:31.000000000 +0000 +++ libwebsockets-4.1.6/minimal-examples/ws-server/minimal-ws-server-echo/protocol_lws_minimal_server_echo.c 2020-12-01 17:40:26.000000000 +0000 @@ -230,36 +230,3 @@ 1024, \ 0, NULL, 0 \ } - -#if !defined (LWS_PLUGIN_STATIC) - -/* boilerplate needed if we are built as a dynamic plugin */ - -static const struct lws_protocols protocols[] = { - LWS_PLUGIN_PROTOCOL_MINIMAL_SERVER_ECHO -}; - -LWS_EXTERN LWS_VISIBLE int -init_protocol_minimal_server_echo(struct lws_context *context, - struct lws_plugin_capability *c) -{ - if (c->api_magic != LWS_PLUGIN_API_MAGIC) { - lwsl_err("Plugin API %d, library API %d", LWS_PLUGIN_API_MAGIC, - c->api_magic); - return 1; - } - - c->protocols = protocols; - c->count_protocols = LWS_ARRAY_SIZE(protocols); - c->extensions = NULL; - c->count_extensions = 0; - - return 0; -} - -LWS_EXTERN LWS_VISIBLE int -destroy_protocol_minimal_server_echo(struct lws_context *context) -{ - return 0; -} -#endif diff -Nru libwebsockets-3.2.1/minimal-examples/ws-server/minimal-ws-server-pmd/CMakeLists.txt libwebsockets-4.1.6/minimal-examples/ws-server/minimal-ws-server-pmd/CMakeLists.txt --- libwebsockets-3.2.1/minimal-examples/ws-server/minimal-ws-server-pmd/CMakeLists.txt 2019-12-18 14:45:31.000000000 +0000 +++ libwebsockets-4.1.6/minimal-examples/ws-server/minimal-ws-server-pmd/CMakeLists.txt 2020-12-01 17:40:26.000000000 +0000 @@ -1,79 +1,25 @@ +project(lws-minimal-ws-server-pmd C) cmake_minimum_required(VERSION 2.8.9) +find_package(libwebsockets CONFIG REQUIRED) +list(APPEND CMAKE_MODULE_PATH ${LWS_CMAKE_DIR}) include(CheckCSourceCompiles) +include(LwsCheckRequirements) set(SAMP lws-minimal-ws-server-pmd) set(SRCS minimal-ws-server-pmd.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_ROLE_WS 1 requirements) -require_lws_config(LWS_WITHOUT_SERVER 0 requirements) +require_lws_config(LWS_WITH_SERVER 1 requirements) require_lws_config(LWS_WITHOUT_EXTENSIONS 0 requirements) if (requirements) add_executable(${SAMP} ${SRCS}) if (websockets_shared) - target_link_libraries(${SAMP} websockets_shared) + target_link_libraries(${SAMP} websockets_shared ${LIBWEBSOCKETS_DEP_LIBS}) add_dependencies(${SAMP} websockets_shared) else() - target_link_libraries(${SAMP} websockets) + target_link_libraries(${SAMP} websockets ${LIBWEBSOCKETS_DEP_LIBS}) endif() endif() diff -Nru libwebsockets-3.2.1/minimal-examples/ws-server/minimal-ws-server-pmd/mount-origin/example.js libwebsockets-4.1.6/minimal-examples/ws-server/minimal-ws-server-pmd/mount-origin/example.js --- libwebsockets-3.2.1/minimal-examples/ws-server/minimal-ws-server-pmd/mount-origin/example.js 2019-12-18 14:45:31.000000000 +0000 +++ libwebsockets-4.1.6/minimal-examples/ws-server/minimal-ws-server-pmd/mount-origin/example.js 2020-12-01 17:40:26.000000000 +0000 @@ -27,15 +27,12 @@ function new_ws(urlpath, protocol) { - if (typeof MozWebSocket != "undefined") - return new MozWebSocket(urlpath, protocol); - return new WebSocket(urlpath, protocol); } document.addEventListener("DOMContentLoaded", function() { - ws = new_ws(get_appropriate_ws_url(""), "lws-minimal"); + var ws = new_ws(get_appropriate_ws_url(""), "lws-minimal"); try { ws.onopen = function() { document.getElementById("m").disabled = 0; diff -Nru libwebsockets-3.2.1/minimal-examples/ws-server/minimal-ws-server-pmd/mount-origin/libwebsockets.org-logo.svg libwebsockets-4.1.6/minimal-examples/ws-server/minimal-ws-server-pmd/mount-origin/libwebsockets.org-logo.svg --- libwebsockets-3.2.1/minimal-examples/ws-server/minimal-ws-server-pmd/mount-origin/libwebsockets.org-logo.svg 2019-12-18 14:45:31.000000000 +0000 +++ libwebsockets-4.1.6/minimal-examples/ws-server/minimal-ws-server-pmd/mount-origin/libwebsockets.org-logo.svg 2020-12-01 17:40:26.000000000 +0000 @@ -1,120 +1,66 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + + +image/svg+xml + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff -Nru libwebsockets-3.2.1/minimal-examples/ws-server/minimal-ws-server-pmd/protocol_lws_minimal.c libwebsockets-4.1.6/minimal-examples/ws-server/minimal-ws-server-pmd/protocol_lws_minimal.c --- libwebsockets-3.2.1/minimal-examples/ws-server/minimal-ws-server-pmd/protocol_lws_minimal.c 2019-12-18 14:45:31.000000000 +0000 +++ libwebsockets-4.1.6/minimal-examples/ws-server/minimal-ws-server-pmd/protocol_lws_minimal.c 2020-12-01 17:40:26.000000000 +0000 @@ -158,36 +158,3 @@ 128, \ 0, NULL, 0 \ } - -#if !defined (LWS_PLUGIN_STATIC) - -/* boilerplate needed if we are built as a dynamic plugin */ - -static const struct lws_protocols protocols[] = { - LWS_PLUGIN_PROTOCOL_MINIMAL -}; - -LWS_EXTERN LWS_VISIBLE int -init_protocol_minimal(struct lws_context *context, - struct lws_plugin_capability *c) -{ - if (c->api_magic != LWS_PLUGIN_API_MAGIC) { - lwsl_err("Plugin API %d, library API %d", LWS_PLUGIN_API_MAGIC, - c->api_magic); - return 1; - } - - c->protocols = protocols; - c->count_protocols = LWS_ARRAY_SIZE(protocols); - c->extensions = NULL; - c->count_extensions = 0; - - return 0; -} - -LWS_EXTERN LWS_VISIBLE int -destroy_protocol_minimal(struct lws_context *context) -{ - return 0; -} -#endif diff -Nru libwebsockets-3.2.1/minimal-examples/ws-server/minimal-ws-server-pmd-bulk/CMakeLists.txt libwebsockets-4.1.6/minimal-examples/ws-server/minimal-ws-server-pmd-bulk/CMakeLists.txt --- libwebsockets-3.2.1/minimal-examples/ws-server/minimal-ws-server-pmd-bulk/CMakeLists.txt 2019-12-18 14:45:31.000000000 +0000 +++ libwebsockets-4.1.6/minimal-examples/ws-server/minimal-ws-server-pmd-bulk/CMakeLists.txt 2020-12-01 17:40:26.000000000 +0000 @@ -1,79 +1,25 @@ +project(lws-minimal-ws-server-pmd-bulk C) cmake_minimum_required(VERSION 2.8.9) +find_package(libwebsockets CONFIG REQUIRED) +list(APPEND CMAKE_MODULE_PATH ${LWS_CMAKE_DIR}) include(CheckCSourceCompiles) +include(LwsCheckRequirements) set(SAMP lws-minimal-ws-server-pmd-bulk) set(SRCS minimal-ws-server-pmd-bulk.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_ROLE_WS 1 requirements) -require_lws_config(LWS_WITHOUT_SERVER 0 requirements) +require_lws_config(LWS_WITH_SERVER 1 requirements) #require_lws_config(LWS_WITHOUT_EXTENSIONS 0 requirements) if (requirements) add_executable(${SAMP} ${SRCS}) if (websockets_shared) - target_link_libraries(${SAMP} websockets_shared) + target_link_libraries(${SAMP} websockets_shared ${LIBWEBSOCKETS_DEP_LIBS}) add_dependencies(${SAMP} websockets_shared) else() - target_link_libraries(${SAMP} websockets) + target_link_libraries(${SAMP} websockets ${LIBWEBSOCKETS_DEP_LIBS}) endif() endif() diff -Nru libwebsockets-3.2.1/minimal-examples/ws-server/minimal-ws-server-pmd-bulk/mount-origin/example.js libwebsockets-4.1.6/minimal-examples/ws-server/minimal-ws-server-pmd-bulk/mount-origin/example.js --- libwebsockets-3.2.1/minimal-examples/ws-server/minimal-ws-server-pmd-bulk/mount-origin/example.js 2019-12-18 14:45:31.000000000 +0000 +++ libwebsockets-4.1.6/minimal-examples/ws-server/minimal-ws-server-pmd-bulk/mount-origin/example.js 2020-12-01 17:40:26.000000000 +0000 @@ -27,15 +27,12 @@ function new_ws(urlpath, protocol) { - if (typeof MozWebSocket != "undefined") - return new MozWebSocket(urlpath, protocol); - return new WebSocket(urlpath, protocol); } document.addEventListener("DOMContentLoaded", function() { - ws = new_ws(get_appropriate_ws_url(""), "lws-minimal-pmd-bulk"); + var ws = new_ws(get_appropriate_ws_url(""), "lws-minimal-pmd-bulk"); try { ws.onopen = function() { document.getElementById("r").disabled = 0; diff -Nru libwebsockets-3.2.1/minimal-examples/ws-server/minimal-ws-server-pmd-bulk/mount-origin/libwebsockets.org-logo.svg libwebsockets-4.1.6/minimal-examples/ws-server/minimal-ws-server-pmd-bulk/mount-origin/libwebsockets.org-logo.svg --- libwebsockets-3.2.1/minimal-examples/ws-server/minimal-ws-server-pmd-bulk/mount-origin/libwebsockets.org-logo.svg 2019-12-18 14:45:31.000000000 +0000 +++ libwebsockets-4.1.6/minimal-examples/ws-server/minimal-ws-server-pmd-bulk/mount-origin/libwebsockets.org-logo.svg 2020-12-01 17:40:26.000000000 +0000 @@ -1,120 +1,66 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + + +image/svg+xml + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff -Nru libwebsockets-3.2.1/minimal-examples/ws-server/minimal-ws-server-pmd-bulk/protocol_lws_minimal_pmd_bulk.c libwebsockets-4.1.6/minimal-examples/ws-server/minimal-ws-server-pmd-bulk/protocol_lws_minimal_pmd_bulk.c --- libwebsockets-3.2.1/minimal-examples/ws-server/minimal-ws-server-pmd-bulk/protocol_lws_minimal_pmd_bulk.c 2019-12-18 14:45:31.000000000 +0000 +++ libwebsockets-4.1.6/minimal-examples/ws-server/minimal-ws-server-pmd-bulk/protocol_lws_minimal_pmd_bulk.c 2020-12-01 17:40:26.000000000 +0000 @@ -147,14 +147,14 @@ if (s > (size_t)n) s = n; memcpy(p, &redundant_string[m], s); - pss->position_tx += s; + pss->position_tx += (int)s; p += s; - n -= s; + n -= (int)s; } } else { pss->position_tx += n; while (n--) - *p++ = rng(&pss->rng_tx); + *p++ = (uint8_t)rng(&pss->rng_tx); } n = lws_ptr_diff(p, start); @@ -172,7 +172,7 @@ lwsl_user("LWS_CALLBACK_RECEIVE: %4d (pss->pos=%d, rpp %5d, last %d)\n", (int)len, (int)pss->position_rx, (int)lws_remaining_packet_payload(wsi), lws_is_final_fragment(wsi)); - olen = len; + olen = (int)len; if (*vhd->options & 1) { while (len) { @@ -185,13 +185,13 @@ lwsl_user("echo'd data doesn't match\n"); return -1; } - pss->position_rx += s; + pss->position_rx += (int)s; in = ((char *)in) + s; len -= s; } } else { p = (uint8_t *)in; - pss->position_rx += len; + pss->position_rx += (int)len; while (len--) { if (*p++ != (uint8_t)rng(&pss->rng_rx)) { lwsl_user("echo'd data doesn't match: 0x%02X 0x%02X (%d)\n", @@ -221,36 +221,3 @@ 4096, \ 0, NULL, 0 \ } - -#if !defined (LWS_PLUGIN_STATIC) - -/* boilerplate needed if we are built as a dynamic plugin */ - -static const struct lws_protocols protocols[] = { - LWS_PLUGIN_PROTOCOL_MINIMAL_PMD_BULK -}; - -LWS_EXTERN LWS_VISIBLE int -init_protocol_minimal_pmd_bulk(struct lws_context *context, - struct lws_plugin_capability *c) -{ - if (c->api_magic != LWS_PLUGIN_API_MAGIC) { - lwsl_err("Plugin API %d, library API %d", LWS_PLUGIN_API_MAGIC, - c->api_magic); - return 1; - } - - c->protocols = protocols; - c->count_protocols = LWS_ARRAY_SIZE(protocols); - c->extensions = NULL; - c->count_extensions = 0; - - return 0; -} - -LWS_EXTERN LWS_VISIBLE int -destroy_protocol_minimal_pmd_bulk(struct lws_context *context) -{ - return 0; -} -#endif diff -Nru libwebsockets-3.2.1/minimal-examples/ws-server/minimal-ws-server-pmd-corner/CMakeLists.txt libwebsockets-4.1.6/minimal-examples/ws-server/minimal-ws-server-pmd-corner/CMakeLists.txt --- libwebsockets-3.2.1/minimal-examples/ws-server/minimal-ws-server-pmd-corner/CMakeLists.txt 2019-12-18 14:45:31.000000000 +0000 +++ libwebsockets-4.1.6/minimal-examples/ws-server/minimal-ws-server-pmd-corner/CMakeLists.txt 2020-12-01 17:40:26.000000000 +0000 @@ -1,79 +1,25 @@ +project(lws-minimal-ws-server-pmd-corner C) cmake_minimum_required(VERSION 2.8.9) +find_package(libwebsockets CONFIG REQUIRED) +list(APPEND CMAKE_MODULE_PATH ${LWS_CMAKE_DIR}) include(CheckCSourceCompiles) +include(LwsCheckRequirements) set(SAMP lws-minimal-ws-server-pmd-corner) set(SRCS minimal-ws-server-pmd-corner.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_ROLE_WS 1 requirements) -require_lws_config(LWS_WITHOUT_SERVER 0 requirements) +require_lws_config(LWS_WITH_SERVER 1 requirements) require_lws_config(LWS_WITHOUT_EXTENSIONS 0 requirements) if (requirements) add_executable(${SAMP} ${SRCS}) if (websockets_shared) - target_link_libraries(${SAMP} websockets_shared) + target_link_libraries(${SAMP} websockets_shared ${LIBWEBSOCKETS_DEP_LIBS}) add_dependencies(${SAMP} websockets_shared) else() - target_link_libraries(${SAMP} websockets) + target_link_libraries(${SAMP} websockets ${LIBWEBSOCKETS_DEP_LIBS}) endif() endif() diff -Nru libwebsockets-3.2.1/minimal-examples/ws-server/minimal-ws-server-pmd-corner/mount-origin/example.js libwebsockets-4.1.6/minimal-examples/ws-server/minimal-ws-server-pmd-corner/mount-origin/example.js --- libwebsockets-3.2.1/minimal-examples/ws-server/minimal-ws-server-pmd-corner/mount-origin/example.js 2019-12-18 14:45:31.000000000 +0000 +++ libwebsockets-4.1.6/minimal-examples/ws-server/minimal-ws-server-pmd-corner/mount-origin/example.js 2020-12-01 17:40:26.000000000 +0000 @@ -27,9 +27,6 @@ function new_ws(urlpath, protocol) { - if (typeof MozWebSocket != "undefined") - return new MozWebSocket(urlpath, protocol); - return new WebSocket(urlpath, protocol); } diff -Nru libwebsockets-3.2.1/minimal-examples/ws-server/minimal-ws-server-pmd-corner/mount-origin/libwebsockets.org-logo.svg libwebsockets-4.1.6/minimal-examples/ws-server/minimal-ws-server-pmd-corner/mount-origin/libwebsockets.org-logo.svg --- libwebsockets-3.2.1/minimal-examples/ws-server/minimal-ws-server-pmd-corner/mount-origin/libwebsockets.org-logo.svg 2019-12-18 14:45:31.000000000 +0000 +++ libwebsockets-4.1.6/minimal-examples/ws-server/minimal-ws-server-pmd-corner/mount-origin/libwebsockets.org-logo.svg 2020-12-01 17:40:26.000000000 +0000 @@ -1,120 +1,66 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + + +image/svg+xml + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff -Nru libwebsockets-3.2.1/minimal-examples/ws-server/minimal-ws-server-pmd-corner/protocol_lws_minimal.c libwebsockets-4.1.6/minimal-examples/ws-server/minimal-ws-server-pmd-corner/protocol_lws_minimal.c --- libwebsockets-3.2.1/minimal-examples/ws-server/minimal-ws-server-pmd-corner/protocol_lws_minimal.c 2019-12-18 14:45:31.000000000 +0000 +++ libwebsockets-4.1.6/minimal-examples/ws-server/minimal-ws-server-pmd-corner/protocol_lws_minimal.c 2020-12-01 17:40:26.000000000 +0000 @@ -269,36 +269,3 @@ 2048, \ 0, NULL, 0 \ } - -#if !defined (LWS_PLUGIN_STATIC) - -/* boilerplate needed if we are built as a dynamic plugin */ - -static const struct lws_protocols protocols[] = { - LWS_PLUGIN_PROTOCOL_MINIMAL -}; - -LWS_EXTERN LWS_VISIBLE int -init_protocol_minimal(struct lws_context *context, - struct lws_plugin_capability *c) -{ - if (c->api_magic != LWS_PLUGIN_API_MAGIC) { - lwsl_err("Plugin API %d, library API %d", LWS_PLUGIN_API_MAGIC, - c->api_magic); - return 1; - } - - c->protocols = protocols; - c->count_protocols = LWS_ARRAY_SIZE(protocols); - c->extensions = NULL; - c->count_extensions = 0; - - return 0; -} - -LWS_EXTERN LWS_VISIBLE int -destroy_protocol_minimal(struct lws_context *context) -{ - return 0; -} -#endif diff -Nru libwebsockets-3.2.1/minimal-examples/ws-server/minimal-ws-server-ring/CMakeLists.txt libwebsockets-4.1.6/minimal-examples/ws-server/minimal-ws-server-ring/CMakeLists.txt --- libwebsockets-3.2.1/minimal-examples/ws-server/minimal-ws-server-ring/CMakeLists.txt 2019-12-18 14:45:31.000000000 +0000 +++ libwebsockets-4.1.6/minimal-examples/ws-server/minimal-ws-server-ring/CMakeLists.txt 2020-12-01 17:40:26.000000000 +0000 @@ -1,78 +1,24 @@ +project(lws-minimal-ws-server-ring C) cmake_minimum_required(VERSION 2.8) +find_package(libwebsockets CONFIG REQUIRED) +list(APPEND CMAKE_MODULE_PATH ${LWS_CMAKE_DIR}) include(CheckCSourceCompiles) +include(LwsCheckRequirements) set(SAMP lws-minimal-ws-server-ring) set(SRCS minimal-ws-server-ring.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_ROLE_WS 1 requirements) -require_lws_config(LWS_WITHOUT_SERVER 0 requirements) +require_lws_config(LWS_WITH_SERVER 1 requirements) if (requirements) add_executable(${SAMP} ${SRCS}) if (websockets_shared) - target_link_libraries(${SAMP} websockets_shared) + target_link_libraries(${SAMP} websockets_shared ${LIBWEBSOCKETS_DEP_LIBS}) add_dependencies(${SAMP} websockets_shared) else() - target_link_libraries(${SAMP} websockets) + target_link_libraries(${SAMP} websockets ${LIBWEBSOCKETS_DEP_LIBS}) endif() endif() diff -Nru libwebsockets-3.2.1/minimal-examples/ws-server/minimal-ws-server-ring/mount-origin/example.js libwebsockets-4.1.6/minimal-examples/ws-server/minimal-ws-server-ring/mount-origin/example.js --- libwebsockets-3.2.1/minimal-examples/ws-server/minimal-ws-server-ring/mount-origin/example.js 2019-12-18 14:45:31.000000000 +0000 +++ libwebsockets-4.1.6/minimal-examples/ws-server/minimal-ws-server-ring/mount-origin/example.js 2020-12-01 17:40:26.000000000 +0000 @@ -26,15 +26,12 @@ function new_ws(urlpath, protocol) { - if (typeof MozWebSocket != "undefined") - return new MozWebSocket(urlpath, protocol); - return new WebSocket(urlpath, protocol); } document.addEventListener("DOMContentLoaded", function() { - ws = new_ws(get_appropriate_ws_url(""), "lws-minimal"); + var ws = new_ws(get_appropriate_ws_url(""), "lws-minimal"); try { ws.onopen = function() { document.getElementById("m").disabled = 0; diff -Nru libwebsockets-3.2.1/minimal-examples/ws-server/minimal-ws-server-ring/mount-origin/libwebsockets.org-logo.svg libwebsockets-4.1.6/minimal-examples/ws-server/minimal-ws-server-ring/mount-origin/libwebsockets.org-logo.svg --- libwebsockets-3.2.1/minimal-examples/ws-server/minimal-ws-server-ring/mount-origin/libwebsockets.org-logo.svg 2019-12-18 14:45:31.000000000 +0000 +++ libwebsockets-4.1.6/minimal-examples/ws-server/minimal-ws-server-ring/mount-origin/libwebsockets.org-logo.svg 2020-12-01 17:40:26.000000000 +0000 @@ -1,120 +1,66 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + + +image/svg+xml + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff -Nru libwebsockets-3.2.1/minimal-examples/ws-server/minimal-ws-server-ring/protocol_lws_minimal.c libwebsockets-4.1.6/minimal-examples/ws-server/minimal-ws-server-ring/protocol_lws_minimal.c --- libwebsockets-3.2.1/minimal-examples/ws-server/minimal-ws-server-ring/protocol_lws_minimal.c 2019-12-18 14:45:31.000000000 +0000 +++ libwebsockets-4.1.6/minimal-examples/ws-server/minimal-ws-server-ring/protocol_lws_minimal.c 2020-12-01 17:40:26.000000000 +0000 @@ -55,7 +55,7 @@ { uint32_t oldest_tail = lws_ring_get_oldest_tail(vhd->ring); struct per_session_data__minimal *old_pss = NULL; - int most = 0, before = lws_ring_get_count_waiting_elements(vhd->ring, + int most = 0, before = (int)lws_ring_get_count_waiting_elements(vhd->ring, &oldest_tail), m; /* @@ -111,7 +111,7 @@ * what is the largest number of pending ring elements * for any survivor. */ - m = lws_ring_get_count_waiting_elements(vhd->ring, + m = (int)lws_ring_get_count_waiting_elements(vhd->ring, &((*ppss)->tail)); if (m > most) most = m; @@ -279,36 +279,3 @@ 0, \ 0, NULL, 0 \ } - -#if !defined (LWS_PLUGIN_STATIC) - -/* boilerplate needed if we are built as a dynamic plugin */ - -static const struct lws_protocols protocols[] = { - LWS_PLUGIN_PROTOCOL_MINIMAL -}; - -LWS_EXTERN LWS_VISIBLE int -init_protocol_minimal(struct lws_context *context, - struct lws_plugin_capability *c) -{ - if (c->api_magic != LWS_PLUGIN_API_MAGIC) { - lwsl_err("Plugin API %d, library API %d", LWS_PLUGIN_API_MAGIC, - c->api_magic); - return 1; - } - - c->protocols = protocols; - c->count_protocols = LWS_ARRAY_SIZE(protocols); - c->extensions = NULL; - c->count_extensions = 0; - - return 0; -} - -LWS_EXTERN LWS_VISIBLE int -destroy_protocol_minimal(struct lws_context *context) -{ - return 0; -} -#endif diff -Nru libwebsockets-3.2.1/minimal-examples/ws-server/minimal-ws-server-threadpool/CMakeLists.txt libwebsockets-4.1.6/minimal-examples/ws-server/minimal-ws-server-threadpool/CMakeLists.txt --- libwebsockets-3.2.1/minimal-examples/ws-server/minimal-ws-server-threadpool/CMakeLists.txt 2019-12-18 14:45:31.000000000 +0000 +++ libwebsockets-4.1.6/minimal-examples/ws-server/minimal-ws-server-threadpool/CMakeLists.txt 2020-12-01 17:40:26.000000000 +0000 @@ -1,92 +1,27 @@ +project(lws-minimal-ws-server-threadpool C) cmake_minimum_required(VERSION 2.8) +find_package(libwebsockets CONFIG REQUIRED) +list(APPEND CMAKE_MODULE_PATH ${LWS_CMAKE_DIR}) include(CheckIncludeFile) include(CheckCSourceCompiles) +include(LwsCheckRequirements) set(SAMP lws-minimal-ws-server-threadpool) set(SRCS minimal-ws-server-threadpool.c) -MACRO(require_pthreads result) - CHECK_INCLUDE_FILE(pthread.h LWS_HAVE_PTHREAD_H) - if (NOT LWS_HAVE_PTHREAD_H) - if (LWS_WITH_MINIMAL_EXAMPLES) - set(result 0) - else() - message(FATAL_ERROR "threading support requires pthreads") - endif() - endif() -ENDMACRO() - -# 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_pthreads(requirements) require_lws_config(LWS_ROLE_WS 1 requirements) -require_lws_config(LWS_WITHOUT_SERVER 0 requirements) +require_lws_config(LWS_WITH_SERVER 1 requirements) require_lws_config(LWS_WITH_THREADPOOL 1 requirements) if (requirements) add_executable(${SAMP} ${SRCS}) if (websockets_shared) - target_link_libraries(${SAMP} websockets_shared pthread) + target_link_libraries(${SAMP} websockets_shared ${PTHREAD_LIB} ${LIBWEBSOCKETS_DEP_LIBS}) add_dependencies(${SAMP} websockets_shared) else() - target_link_libraries(${SAMP} websockets pthread) + target_link_libraries(${SAMP} websockets ${PTHREAD_LIB} ${LIBWEBSOCKETS_DEP_LIBS}) endif() endif() diff -Nru libwebsockets-3.2.1/minimal-examples/ws-server/minimal-ws-server-threadpool/minimal-ws-server-threadpool.c libwebsockets-4.1.6/minimal-examples/ws-server/minimal-ws-server-threadpool/minimal-ws-server-threadpool.c --- libwebsockets-3.2.1/minimal-examples/ws-server/minimal-ws-server-threadpool/minimal-ws-server-threadpool.c 2019-12-18 14:45:31.000000000 +0000 +++ libwebsockets-4.1.6/minimal-examples/ws-server/minimal-ws-server-threadpool/minimal-ws-server-threadpool.c 2020-12-01 17:40:26.000000000 +0000 @@ -21,6 +21,12 @@ #include #include #include +#if defined(WIN32) +#define HAVE_STRUCT_TIMESPEC +#if defined(pid_t) +#undef pid_t +#endif +#endif #include #define LWS_PLUGIN_STATIC @@ -125,5 +131,7 @@ lws_context_destroy(context); + lwsl_user("%s: exiting cleanly...\n", __func__); + return 0; } diff -Nru libwebsockets-3.2.1/minimal-examples/ws-server/minimal-ws-server-threadpool/mount-origin/example.js libwebsockets-4.1.6/minimal-examples/ws-server/minimal-ws-server-threadpool/mount-origin/example.js --- libwebsockets-3.2.1/minimal-examples/ws-server/minimal-ws-server-threadpool/mount-origin/example.js 2019-12-18 14:45:31.000000000 +0000 +++ libwebsockets-4.1.6/minimal-examples/ws-server/minimal-ws-server-threadpool/mount-origin/example.js 2020-12-01 17:40:26.000000000 +0000 @@ -28,9 +28,6 @@ function new_ws(urlpath, protocol) { - if (typeof MozWebSocket != "undefined") - return new MozWebSocket(urlpath, protocol); - return new WebSocket(urlpath, protocol); } @@ -40,7 +37,7 @@ for (n = 0; n < 8; n++) { - ws = new_ws(get_appropriate_ws_url(""), "lws-minimal"); + var ws = new_ws(get_appropriate_ws_url(""), "lws-minimal"); wsa.push(ws); try { ws.onopen = function() { @@ -68,7 +65,8 @@ }; ws.onclose = function(){ - if (--alive === 0) + alive--; + if (alive === 0) document.getElementById("r").disabled = 1; }; } catch(exception) { diff -Nru libwebsockets-3.2.1/minimal-examples/ws-server/minimal-ws-server-threadpool/mount-origin/libwebsockets.org-logo.svg libwebsockets-4.1.6/minimal-examples/ws-server/minimal-ws-server-threadpool/mount-origin/libwebsockets.org-logo.svg --- libwebsockets-3.2.1/minimal-examples/ws-server/minimal-ws-server-threadpool/mount-origin/libwebsockets.org-logo.svg 2019-12-18 14:45:31.000000000 +0000 +++ libwebsockets-4.1.6/minimal-examples/ws-server/minimal-ws-server-threadpool/mount-origin/libwebsockets.org-logo.svg 2020-12-01 17:40:26.000000000 +0000 @@ -1,120 +1,66 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + + +image/svg+xml + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff -Nru libwebsockets-3.2.1/minimal-examples/ws-server/minimal-ws-server-threadpool/protocol_lws_minimal_threadpool.c libwebsockets-4.1.6/minimal-examples/ws-server/minimal-ws-server-threadpool/protocol_lws_minimal_threadpool.c --- libwebsockets-3.2.1/minimal-examples/ws-server/minimal-ws-server-threadpool/protocol_lws_minimal_threadpool.c 2019-12-18 14:45:31.000000000 +0000 +++ libwebsockets-4.1.6/minimal-examples/ws-server/minimal-ws-server-threadpool/protocol_lws_minimal_threadpool.c 2020-12-01 17:40:26.000000000 +0000 @@ -34,6 +34,8 @@ struct per_vhost_data__minimal { struct lws_threadpool *tp; + struct lws_context *context; + lws_sorted_usec_list_t sul; const char *config; }; @@ -43,6 +45,10 @@ uint64_t pos, end; }; +#if defined(WIN32) +static void usleep(unsigned long l) { Sleep(l / 1000); } +#endif + /* * Create the private data for the task * @@ -129,6 +135,22 @@ return LWS_TP_RETURN_CHECKING_IN; } + +static void +sul_tp_dump(struct lws_sorted_usec_list *sul) +{ + struct per_vhost_data__minimal *vhd = + lws_container_of(sul, struct per_vhost_data__minimal, sul); + /* + * in debug mode, dump the threadpool stat to the logs once + * a second + */ + lws_threadpool_dump(vhd->tp); + lws_sul_schedule(vhd->context, 0, &vhd->sul, + sul_tp_dump, LWS_US_PER_SEC); +} + + static int callback_minimal(struct lws *wsi, enum lws_callback_reasons reason, void *user, void *in, size_t len) @@ -155,6 +177,8 @@ if (!vhd) return 1; + vhd->context = lws_get_context(wsi); + /* recover the pointer to the globals struct */ pvo = lws_pvo_search( (const struct lws_protocol_vhost_options *)in, @@ -175,27 +199,14 @@ if (!vhd->tp) return 1; - lws_timed_callback_vh_protocol(lws_get_vhost(wsi), - lws_get_protocol(wsi), - LWS_CALLBACK_USER, 1); - + lws_sul_schedule(vhd->context, 0, &vhd->sul, + sul_tp_dump, LWS_US_PER_SEC); break; case LWS_CALLBACK_PROTOCOL_DESTROY: lws_threadpool_finish(vhd->tp); lws_threadpool_destroy(vhd->tp); - break; - - case LWS_CALLBACK_USER: - - /* - * in debug mode, dump the threadpool stat to the logs once - * a second - */ - lws_threadpool_dump(vhd->tp); - lws_timed_callback_vh_protocol(lws_get_vhost(wsi), - lws_get_protocol(wsi), - LWS_CALLBACK_USER, 1); + lws_sul_cancel(&vhd->sul); break; case LWS_CALLBACK_ESTABLISHED: @@ -237,7 +248,7 @@ case LWS_CALLBACK_WS_SERVER_DROP_PROTOCOL: lwsl_debug("LWS_CALLBACK_WS_SERVER_DROP_PROTOCOL: %p\n", wsi); - lws_threadpool_dequeue(wsi); + lws_threadpool_dequeue_task(lws_threadpool_get_task_wsi(wsi)); break; case LWS_CALLBACK_SERVER_WRITEABLE: @@ -253,7 +264,10 @@ * private task data. */ - n = lws_threadpool_task_status_wsi(wsi, &task, &_user); + task = lws_threadpool_get_task_wsi(wsi); + if (!task) + break; + n = lws_threadpool_task_status(task, &_user); lwsl_debug("%s: LWS_CALLBACK_SERVER_WRITEABLE: status %d\n", __func__, n); switch(n) { @@ -276,7 +290,7 @@ lws_set_timeout(wsi, PENDING_TIMEOUT_THREADPOOL_TASK, 5); - n = strlen(priv->result + LWS_PRE); + n = (int)strlen(priv->result + LWS_PRE); m = lws_write(wsi, (unsigned char *)priv->result + LWS_PRE, n, LWS_WRITE_TEXT); if (m < n) { @@ -308,36 +322,3 @@ 128, \ 0, NULL, 0 \ } - -#if !defined (LWS_PLUGIN_STATIC) - -/* boilerplate needed if we are built as a dynamic plugin */ - -static const struct lws_protocols protocols[] = { - LWS_PLUGIN_PROTOCOL_MINIMAL -}; - -LWS_EXTERN LWS_VISIBLE int -init_protocol_minimal(struct lws_context *context, - struct lws_plugin_capability *c) -{ - if (c->api_magic != LWS_PLUGIN_API_MAGIC) { - lwsl_err("Plugin API %d, library API %d", LWS_PLUGIN_API_MAGIC, - c->api_magic); - return 1; - } - - c->protocols = protocols; - c->count_protocols = LWS_ARRAY_SIZE(protocols); - c->extensions = NULL; - c->count_extensions = 0; - - return 0; -} - -LWS_EXTERN LWS_VISIBLE int -destroy_protocol_minimal(struct lws_context *context) -{ - return 0; -} -#endif diff -Nru libwebsockets-3.2.1/minimal-examples/ws-server/minimal-ws-server-threads/CMakeLists.txt libwebsockets-4.1.6/minimal-examples/ws-server/minimal-ws-server-threads/CMakeLists.txt --- libwebsockets-3.2.1/minimal-examples/ws-server/minimal-ws-server-threads/CMakeLists.txt 2019-12-18 14:45:31.000000000 +0000 +++ libwebsockets-4.1.6/minimal-examples/ws-server/minimal-ws-server-threads/CMakeLists.txt 2020-12-01 17:40:26.000000000 +0000 @@ -1,91 +1,29 @@ +project(lws-minimal-ws-server-threads C) cmake_minimum_required(VERSION 2.8) +find_package(libwebsockets CONFIG REQUIRED) +list(APPEND CMAKE_MODULE_PATH ${LWS_CMAKE_DIR}) include(CheckIncludeFile) include(CheckCSourceCompiles) +include(LwsCheckRequirements) set(SAMP lws-minimal-ws-server-threads) set(SRCS minimal-ws-server.c) -MACRO(require_pthreads result) - CHECK_INCLUDE_FILE(pthread.h LWS_HAVE_PTHREAD_H) - if (NOT LWS_HAVE_PTHREAD_H) - if (LWS_WITH_MINIMAL_EXAMPLES) - set(result 0) - else() - message(FATAL_ERROR "threading support requires pthreads") - endif() - endif() -ENDMACRO() - -# 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) +if (WIN32) + set(requirements 0) +endif() require_pthreads(requirements) require_lws_config(LWS_ROLE_WS 1 requirements) -require_lws_config(LWS_WITHOUT_SERVER 0 requirements) +require_lws_config(LWS_WITH_SERVER 1 requirements) if (requirements) add_executable(${SAMP} ${SRCS}) if (websockets_shared) - target_link_libraries(${SAMP} websockets_shared pthread) + target_link_libraries(${SAMP} websockets_shared ${PTHREAD_LIB} ${LIBWEBSOCKETS_DEP_LIBS}) add_dependencies(${SAMP} websockets_shared) else() - target_link_libraries(${SAMP} websockets pthread) + target_link_libraries(${SAMP} websockets ${PTHREAD_LIB} ${LIBWEBSOCKETS_DEP_LIBS}) endif() endif() diff -Nru libwebsockets-3.2.1/minimal-examples/ws-server/minimal-ws-server-threads/minimal-ws-server.c libwebsockets-4.1.6/minimal-examples/ws-server/minimal-ws-server-threads/minimal-ws-server.c --- libwebsockets-3.2.1/minimal-examples/ws-server/minimal-ws-server-threads/minimal-ws-server.c 2019-12-18 14:45:31.000000000 +0000 +++ libwebsockets-4.1.6/minimal-examples/ws-server/minimal-ws-server-threads/minimal-ws-server.c 2020-12-01 17:40:26.000000000 +0000 @@ -21,6 +21,12 @@ #include #include #include +#if defined(WIN32) +#define HAVE_STRUCT_TIMESPEC +#if defined(pid_t) +#undef pid_t +#endif +#endif #include #define LWS_PLUGIN_STATIC diff -Nru libwebsockets-3.2.1/minimal-examples/ws-server/minimal-ws-server-threads/mount-origin/example.js libwebsockets-4.1.6/minimal-examples/ws-server/minimal-ws-server-threads/mount-origin/example.js --- libwebsockets-3.2.1/minimal-examples/ws-server/minimal-ws-server-threads/mount-origin/example.js 2019-12-18 14:45:31.000000000 +0000 +++ libwebsockets-4.1.6/minimal-examples/ws-server/minimal-ws-server-threads/mount-origin/example.js 2020-12-01 17:40:26.000000000 +0000 @@ -28,15 +28,12 @@ function new_ws(urlpath, protocol) { - if (typeof MozWebSocket != "undefined") - return new MozWebSocket(urlpath, protocol); - return new WebSocket(urlpath, protocol); } document.addEventListener("DOMContentLoaded", function() { - ws = new_ws(get_appropriate_ws_url(""), "lws-minimal"); + var ws = new_ws(get_appropriate_ws_url(""), "lws-minimal"); try { ws.onopen = function() { document.getElementById("r").disabled = 0; diff -Nru libwebsockets-3.2.1/minimal-examples/ws-server/minimal-ws-server-threads/mount-origin/libwebsockets.org-logo.svg libwebsockets-4.1.6/minimal-examples/ws-server/minimal-ws-server-threads/mount-origin/libwebsockets.org-logo.svg --- libwebsockets-3.2.1/minimal-examples/ws-server/minimal-ws-server-threads/mount-origin/libwebsockets.org-logo.svg 2019-12-18 14:45:31.000000000 +0000 +++ libwebsockets-4.1.6/minimal-examples/ws-server/minimal-ws-server-threads/mount-origin/libwebsockets.org-logo.svg 2020-12-01 17:40:26.000000000 +0000 @@ -1,120 +1,66 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + + +image/svg+xml + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff -Nru libwebsockets-3.2.1/minimal-examples/ws-server/minimal-ws-server-threads/protocol_lws_minimal.c libwebsockets-4.1.6/minimal-examples/ws-server/minimal-ws-server-threads/protocol_lws_minimal.c --- libwebsockets-3.2.1/minimal-examples/ws-server/minimal-ws-server-threads/protocol_lws_minimal.c 2019-12-18 14:45:31.000000000 +0000 +++ libwebsockets-4.1.6/minimal-examples/ws-server/minimal-ws-server-threads/protocol_lws_minimal.c 2020-12-01 17:40:26.000000000 +0000 @@ -83,7 +83,11 @@ struct per_vhost_data__minimal *vhd = (struct per_vhost_data__minimal *)d; struct msg amsg; - int len = 128, index = 1, n; + int len = 128, index = 1, n, whoami = 0; + + for (n = 0; n < (int)LWS_ARRAY_SIZE(vhd->pthread_spam); n++) + if (pthread_equal(pthread_self(), vhd->pthread_spam[n])) + whoami = n + 1; do { /* don't generate output if nobody connected */ @@ -105,8 +109,8 @@ goto wait_unlock; } n = lws_snprintf((char *)amsg.payload + LWS_PRE, len, - "%s: tid: %p, msg: %d", vhd->config, - (void *)pthread_self(), index++); + "%s: tid: %d, msg: %d", vhd->config, + whoami, index++); amsg.len = n; n = lws_ring_insert(vhd->ring, &amsg, 1); if (n != 1) { @@ -127,7 +131,7 @@ } while (!vhd->finished); - lwsl_notice("thread_spam %p exiting\n", (void *)pthread_self()); + lwsl_notice("thread_spam %d exiting\n", whoami); pthread_exit(NULL); @@ -291,36 +295,3 @@ 128, \ 0, NULL, 0 \ } - -#if !defined (LWS_PLUGIN_STATIC) - -/* boilerplate needed if we are built as a dynamic plugin */ - -static const struct lws_protocols protocols[] = { - LWS_PLUGIN_PROTOCOL_MINIMAL -}; - -LWS_EXTERN LWS_VISIBLE int -init_protocol_minimal(struct lws_context *context, - struct lws_plugin_capability *c) -{ - if (c->api_magic != LWS_PLUGIN_API_MAGIC) { - lwsl_err("Plugin API %d, library API %d", LWS_PLUGIN_API_MAGIC, - c->api_magic); - return 1; - } - - c->protocols = protocols; - c->count_protocols = LWS_ARRAY_SIZE(protocols); - c->extensions = NULL; - c->count_extensions = 0; - - return 0; -} - -LWS_EXTERN LWS_VISIBLE int -destroy_protocol_minimal(struct lws_context *context) -{ - return 0; -} -#endif diff -Nru libwebsockets-3.2.1/minimal-examples/ws-server/minimal-ws-server-threads-foreign-smp/CMakeLists.txt libwebsockets-4.1.6/minimal-examples/ws-server/minimal-ws-server-threads-foreign-smp/CMakeLists.txt --- libwebsockets-3.2.1/minimal-examples/ws-server/minimal-ws-server-threads-foreign-smp/CMakeLists.txt 1970-01-01 00:00:00.000000000 +0000 +++ libwebsockets-4.1.6/minimal-examples/ws-server/minimal-ws-server-threads-foreign-smp/CMakeLists.txt 2020-12-01 17:40:26.000000000 +0000 @@ -0,0 +1,44 @@ +project(lws-minimal-ws-server-threads-foreign-smp C) +cmake_minimum_required(VERSION 2.8) +find_package(libwebsockets CONFIG REQUIRED) +list(APPEND CMAKE_MODULE_PATH ${LWS_CMAKE_DIR}) +include(CheckIncludeFile) +include(CheckCSourceCompiles) +include(LwsCheckRequirements) + +set(SAMP lws-minimal-ws-server-threads-foreign-smp) +set(SRCS minimal-ws-server.c) + +set(requirements 1) +require_pthreads(requirements) +require_lws_config(LWS_ROLE_WS 1 requirements) +require_lws_config(LWS_WITH_SERVER 1 requirements) +require_lws_config(LWS_WITH_TLS 1 requirements) +require_lws_config(LWS_WITH_LIBUV 1 requirements) + +CHECK_C_SOURCE_COMPILES("#include \nint main(void) {\n#if defined(LWS_WITH_LIBUV)\n return 0;\n#else\n fail;\n#endif\n return 0;\n}\n" LWS_WITH_LIBUV) + +if (NOT LWS_WITH_LIBUV) + set(requirements 0) +endif() + + +if (requirements) + add_executable(${SAMP} ${SRCS}) + + find_path(LIBUV_INCLUDE_DIRS NAMES uv.h) + find_library(LIBUV_LIBRARIES NAMES uv) + message("libuv include dir: ${LIBUV_INCLUDE_DIRS}") + message("libuv libraries: ${LIBUV_LIBRARIES}") + include_directories("${LIBUV_INCLUDE_DIRS}") + set(extralibs ${extralibs} ${LIBUV_LIBRARIES}) + + message("Extra libs: ${extralibs}") + + if (websockets_shared) + target_link_libraries(${SAMP} websockets_shared ${extralibs} ${PTHREAD_LIB} ${LIBWEBSOCKETS_DEP_LIBS}) + add_dependencies(${SAMP} websockets_shared) + else() + target_link_libraries(${SAMP} websockets ${extralibs} ${PTHREAD_LIB} ${LIBWEBSOCKETS_DEP_LIBS}) + endif() +endif() diff -Nru libwebsockets-3.2.1/minimal-examples/ws-server/minimal-ws-server-threads-foreign-smp/minimal-ws-server.c libwebsockets-4.1.6/minimal-examples/ws-server/minimal-ws-server-threads-foreign-smp/minimal-ws-server.c --- libwebsockets-3.2.1/minimal-examples/ws-server/minimal-ws-server-threads-foreign-smp/minimal-ws-server.c 1970-01-01 00:00:00.000000000 +0000 +++ libwebsockets-4.1.6/minimal-examples/ws-server/minimal-ws-server-threads-foreign-smp/minimal-ws-server.c 2020-12-01 17:40:26.000000000 +0000 @@ -0,0 +1,182 @@ +/* + * lws-minimal-ws-server + * + * Written in 2010-2020 by Andy Green + * + * This file is made available under the Creative Commons CC0 1.0 + * Universal Public Domain Dedication. + * + * This demonstrates a minimal ws server that can cooperate with + * other threads cleanly. Two other threads are started, which fill + * a ringbuffer with strings at 10Hz. + * + * The actual work and thread spawning etc are done in the protocol + * implementation in protocol_lws_minimal.c. + * + * To keep it simple, it serves stuff in the subdirectory "./mount-origin" of + * the directory it was started in. + * You can change that by changing mount.origin. + */ + +#include +#include +#include +#if defined(WIN32) +#define HAVE_STRUCT_TIMESPEC +#if defined(pid_t) +#undef pid_t +#endif +#endif +#include +#include + +#define COUNT_THREADS 5 + +#define LWS_PLUGIN_STATIC +#include "protocol_lws_minimal.c" + +static struct lws_protocols protocols[] = { + { "http", lws_callback_http_dummy, 0, 0 }, + LWS_PLUGIN_PROTOCOL_MINIMAL, + { NULL, NULL, 0, 0 } /* terminator */ +}; + +static struct lws_context *context; +static int interrupted; +static uv_loop_t loop[COUNT_THREADS]; + +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, +}; + +/* + * This demonstrates how to pass a pointer into a specific protocol handler + * running on a specific vhost. In this case, it's our default vhost and + * we pass the pvo named "config" with the value a const char * "myconfig". + * + * This is the preferred way to pass configuration into a specific vhost + + * protocol instance. + */ + +static const struct lws_protocol_vhost_options pvo_ops = { + NULL, + NULL, + "config", /* pvo name */ + (void *)"myconfig" /* pvo value */ +}; + +static const struct lws_protocol_vhost_options pvo = { + NULL, /* "next" pvo linked-list */ + &pvo_ops, /* "child" pvo linked-list */ + "lws-minimal", /* protocol name we belong to on this vhost */ + "" /* ignored */ +}; + +void *thread_service(void *threadid) +{ + while (lws_service_tsi(context, 0, + (int)(lws_intptr_t)threadid) >= 0 && + !interrupted) + lwsl_notice("%s\n", __func__); + + pthread_exit(NULL); + + return NULL; +} + +void signal_cb(uv_signal_t *watcher, int signum) +{ + int n; + + if (interrupted) + return; + + lwsl_notice("signal_cb: signal %d caught\n", watcher->signum); + interrupted = 1; + uv_signal_stop(watcher); + lws_context_destroy(context); + for (n = 0; n < COUNT_THREADS; n++) + uv_stop(&loop[n]); +} + +int main(int argc, const char **argv) +{ + int n, logs = LLL_USER | LLL_ERR | LLL_WARN | LLL_NOTICE; + uv_signal_t *s, signal_outer[3 * COUNT_THREADS]; + pthread_t pthread_service[COUNT_THREADS]; + struct lws_context_creation_info info; + void *foreign_loops[COUNT_THREADS]; + const char *p; + void *retval; + + if ((p = lws_cmdline_option(argc, argv, "-d"))) + logs = atoi(p); + + lws_set_log_level(logs, NULL); + lwsl_user("LWS minimal ws server + threads + smp | visit http://localhost:7681\n"); + + for (n = 0; n < COUNT_THREADS; n++) { + int m; + + uv_loop_init(&loop[n]); + + for (m = 0; m < 3; m++) { + s = &signal_outer[n * 3 + m]; + uv_signal_init(&loop[n], s); + uv_signal_start(s, signal_cb, SIGINT); + } + + foreign_loops[n] = &loop[n]; + } + + memset(&info, 0, sizeof info); /* otherwise uninitialized garbage */ + info.port = 7681; + info.mounts = &mount; + info.pcontext = &context; + info.protocols = protocols; + info.pvo = &pvo; /* per-vhost options */ + info.foreign_loops = foreign_loops; + info.count_threads = COUNT_THREADS; + info.options = LWS_SERVER_OPTION_LIBUV | + LWS_SERVER_OPTION_HTTP_HEADERS_SECURITY_BEST_PRACTICES_ENFORCE; + + context = lws_create_context(&info); + if (!context) { + lwsl_err("lws init failed\n"); + return 1; + } + + lwsl_notice(" Service threads: %d\n", lws_get_count_threads(context)); + + /* start all the service threads */ + + for (n = 0; n < lws_get_count_threads(context); n++) + if (pthread_create(&pthread_service[n], NULL, thread_service, + (void *)(lws_intptr_t)n)) + lwsl_err("Failed to start service thread\n"); + + /* wait for all the service threads to exit */ + + while ((--n) >= 0) + pthread_join(pthread_service[n], &retval); + + lws_context_destroy(context); + + return 0; +} diff -Nru libwebsockets-3.2.1/minimal-examples/ws-server/minimal-ws-server-threads-foreign-smp/mount-origin/example.js libwebsockets-4.1.6/minimal-examples/ws-server/minimal-ws-server-threads-foreign-smp/mount-origin/example.js --- libwebsockets-3.2.1/minimal-examples/ws-server/minimal-ws-server-threads-foreign-smp/mount-origin/example.js 1970-01-01 00:00:00.000000000 +0000 +++ libwebsockets-4.1.6/minimal-examples/ws-server/minimal-ws-server-threads-foreign-smp/mount-origin/example.js 2020-12-01 17:40:26.000000000 +0000 @@ -0,0 +1,68 @@ +var head = 0, tail = 0, ring = new Array(); + +function get_appropriate_ws_url(extra_url) +{ + var pcol; + var u = document.URL; + + /* + * We open the websocket encrypted if this page came on an + * https:// url itself, otherwise unencrypted + */ + + if (u.substring(0, 5) === "https") { + pcol = "wss://"; + u = u.substr(8); + } else { + pcol = "ws://"; + if (u.substring(0, 4) === "http") + u = u.substr(7); + } + + u = u.split("/"); + + /* + "/xxx" bit is for IE10 workaround */ + + return pcol + u[0] + "/" + extra_url; +} + +function new_ws(urlpath, protocol) +{ + return new WebSocket(urlpath, protocol); +} + +document.addEventListener("DOMContentLoaded", function() { + + var ws = new_ws(get_appropriate_ws_url(""), "lws-minimal"); + try { + ws.onopen = function() { + document.getElementById("r").disabled = 0; + }; + + ws.onmessage =function got_packet(msg) { + var n, s = ""; + + ring[head] = msg.data + "\n"; + head = (head + 1) % 50; + if (tail === head) + tail = (tail + 1) % 50; + + n = tail; + do { + s = s + ring[n]; + n = (n + 1) % 50; + } while (n !== head); + + document.getElementById("r").value = s; + document.getElementById("r").scrollTop = + document.getElementById("r").scrollHeight; + }; + + ws.onclose = function(){ + document.getElementById("r").disabled = 1; + }; + } catch(exception) { + alert("

Error " + exception); + } + +}, false); Binary files /tmp/tmp2l8bmswe/3lv7Sxvgkv/libwebsockets-3.2.1/minimal-examples/ws-server/minimal-ws-server-threads-foreign-smp/mount-origin/favicon.ico and /tmp/tmp2l8bmswe/LwTwoWz49Q/libwebsockets-4.1.6/minimal-examples/ws-server/minimal-ws-server-threads-foreign-smp/mount-origin/favicon.ico differ diff -Nru libwebsockets-3.2.1/minimal-examples/ws-server/minimal-ws-server-threads-foreign-smp/mount-origin/index.html libwebsockets-4.1.6/minimal-examples/ws-server/minimal-ws-server-threads-foreign-smp/mount-origin/index.html --- libwebsockets-3.2.1/minimal-examples/ws-server/minimal-ws-server-threads-foreign-smp/mount-origin/index.html 1970-01-01 00:00:00.000000000 +0000 +++ libwebsockets-4.1.6/minimal-examples/ws-server/minimal-ws-server-threads-foreign-smp/mount-origin/index.html 2020-12-01 17:40:26.000000000 +0000 @@ -0,0 +1,19 @@ + + + + + + + +
+ + Minimal ws server threads SMP example.
+ Strings generated by server threads are sent to + all browsers open on this page.
+ The textarea show the last 50 lines received. +
+
+
+ + + diff -Nru libwebsockets-3.2.1/minimal-examples/ws-server/minimal-ws-server-threads-foreign-smp/mount-origin/libwebsockets.org-logo.svg libwebsockets-4.1.6/minimal-examples/ws-server/minimal-ws-server-threads-foreign-smp/mount-origin/libwebsockets.org-logo.svg --- libwebsockets-3.2.1/minimal-examples/ws-server/minimal-ws-server-threads-foreign-smp/mount-origin/libwebsockets.org-logo.svg 1970-01-01 00:00:00.000000000 +0000 +++ libwebsockets-4.1.6/minimal-examples/ws-server/minimal-ws-server-threads-foreign-smp/mount-origin/libwebsockets.org-logo.svg 2020-12-01 17:40:26.000000000 +0000 @@ -0,0 +1,66 @@ + + + + + +image/svg+xml + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff -Nru libwebsockets-3.2.1/minimal-examples/ws-server/minimal-ws-server-threads-foreign-smp/mount-origin/strict-csp.svg libwebsockets-4.1.6/minimal-examples/ws-server/minimal-ws-server-threads-foreign-smp/mount-origin/strict-csp.svg --- libwebsockets-3.2.1/minimal-examples/ws-server/minimal-ws-server-threads-foreign-smp/mount-origin/strict-csp.svg 1970-01-01 00:00:00.000000000 +0000 +++ libwebsockets-4.1.6/minimal-examples/ws-server/minimal-ws-server-threads-foreign-smp/mount-origin/strict-csp.svg 2020-12-01 17:40:26.000000000 +0000 @@ -0,0 +1,53 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff -Nru libwebsockets-3.2.1/minimal-examples/ws-server/minimal-ws-server-threads-foreign-smp/protocol_lws_minimal.c libwebsockets-4.1.6/minimal-examples/ws-server/minimal-ws-server-threads-foreign-smp/protocol_lws_minimal.c --- libwebsockets-3.2.1/minimal-examples/ws-server/minimal-ws-server-threads-foreign-smp/protocol_lws_minimal.c 1970-01-01 00:00:00.000000000 +0000 +++ libwebsockets-4.1.6/minimal-examples/ws-server/minimal-ws-server-threads-foreign-smp/protocol_lws_minimal.c 2020-12-01 17:40:26.000000000 +0000 @@ -0,0 +1,321 @@ +/* + * ws protocol handler plugin for "lws-minimal" demonstrating multithread + * + * Written in 2010-2019 by Andy Green + * + * This file is made available under the Creative Commons CC0 1.0 + * Universal Public Domain Dedication. + */ + +#if !defined (LWS_PLUGIN_STATIC) +#define LWS_DLL +#define LWS_INTERNAL +#include +#endif + +#include +#include + +/* one of these created for each message in the ringbuffer */ + +struct msg { + void *payload; /* is malloc'd */ + size_t len; +}; + +/* + * One of these is created for each client connecting to us. + * + * It is ONLY read or written from the lws service thread context. + */ + +struct per_session_data__minimal { + struct per_session_data__minimal *pss_list; + struct lws *wsi; + uint32_t tail; +}; + +/* + * One of these is created for each vhost our protocol is used with, that + * means it is a shared resource between the SMP threads and must be locked. + */ + +struct per_vhost_data__minimal { + struct lws_context *context; + struct lws_vhost *vhost; + const struct lws_protocols *protocol; + + struct per_session_data__minimal *pss_list; /* linked-list of live pss*/ + pthread_t pthread_spam[2]; + + pthread_mutex_t lock_ring; /* serialize access to the ring buffer */ + struct lws_ring *ring; /* {lock_ring} ringbuffer holding unsent content */ + + const char *config; + char finished; +}; + +#if defined(WIN32) +static void usleep(unsigned long l) { Sleep(l / 1000); } +#endif + +/* + * This runs under both lws service and "spam threads" contexts. + * Access is serialized by vhd->lock_ring. + */ + +static void +__minimal_destroy_message(void *_msg) +{ + struct msg *msg = _msg; + + free(msg->payload); + msg->payload = NULL; + msg->len = 0; +} + +/* + * This runs under the "spam thread" thread context only. + * + * We spawn two threads that generate messages with this. + * + */ + +static void * +thread_spam(void *d) +{ + struct per_vhost_data__minimal *vhd = + (struct per_vhost_data__minimal *)d; + struct msg amsg; + int len = 128, index = 1, n, whoami = 0; + + for (n = 0; n < (int)LWS_ARRAY_SIZE(vhd->pthread_spam); n++) + if (pthread_equal(pthread_self(), vhd->pthread_spam[n])) + whoami = n + 1; + + do { + pthread_mutex_lock(&vhd->lock_ring); /* --------- ring lock { */ + + /* don't generate output if nobody connected */ + if (!vhd->pss_list) + goto wait_unlock; + + /* only create if space in ringbuffer */ + n = (int)lws_ring_get_count_free_elements(vhd->ring); + if (!n) { + // lwsl_user("dropping!\n"); + goto wait_unlock; + } + + amsg.payload = malloc(LWS_PRE + len); + if (!amsg.payload) { + lwsl_user("OOM: dropping\n"); + goto wait_unlock; + } + n = lws_snprintf((char *)amsg.payload + LWS_PRE, len, + "%s: spam tid: %d, msg: %d", vhd->config, + whoami, index++); + amsg.len = n; + n = (int)lws_ring_insert(vhd->ring, &amsg, 1); + if (n != 1) { + __minimal_destroy_message(&amsg); + // lwsl_user("dropping!\n"); + } else + /* + * This will cause a LWS_CALLBACK_EVENT_WAIT_CANCELLED + * in the lws service thread context. + */ + lws_cancel_service(vhd->context); + +wait_unlock: + pthread_mutex_unlock(&vhd->lock_ring); /* } ring lock ------- */ + + usleep(100000); + + } while (!vhd->finished); + + lwsl_notice("thread_spam %d exiting\n", whoami); + + pthread_exit(NULL); + + return NULL; +} + +/* this runs under the lws service thread context only */ + +static int +callback_minimal(struct lws *wsi, enum lws_callback_reasons reason, + void *user, void *in, size_t len) +{ + struct per_session_data__minimal *pss = + (struct per_session_data__minimal *)user; + struct per_vhost_data__minimal *vhd = + (struct per_vhost_data__minimal *) + lws_protocol_vh_priv_get(lws_get_vhost(wsi), + lws_get_protocol(wsi)); + const struct lws_protocol_vhost_options *pvo; + const struct msg *pmsg; + char temp[LWS_PRE + 256]; + void *retval; + int n, m, r = 0; + + switch (reason) { + case LWS_CALLBACK_PROTOCOL_INIT: + /* create our per-vhost struct */ + vhd = lws_protocol_vh_priv_zalloc(lws_get_vhost(wsi), + lws_get_protocol(wsi), + sizeof(struct per_vhost_data__minimal)); + if (!vhd) + return 1; + + pthread_mutex_init(&vhd->lock_ring, NULL); + + /* recover the pointer to the globals struct */ + pvo = lws_pvo_search( + (const struct lws_protocol_vhost_options *)in, + "config"); + if (!pvo || !pvo->value) { + lwsl_err("%s: Can't find \"config\" pvo\n", __func__); + return 1; + } + vhd->config = pvo->value; + + vhd->context = lws_get_context(wsi); + vhd->protocol = lws_get_protocol(wsi); + vhd->vhost = lws_get_vhost(wsi); + + vhd->ring = lws_ring_create(sizeof(struct msg), 8, + __minimal_destroy_message); + if (!vhd->ring) { + lwsl_err("%s: failed to create ring\n", __func__); + return 1; + } + + /* start the content-creating threads */ + + for (n = 0; n < (int)LWS_ARRAY_SIZE(vhd->pthread_spam); n++) + if (pthread_create(&vhd->pthread_spam[n], NULL, + thread_spam, vhd)) { + lwsl_err("thread creation failed\n"); + r = 1; + goto init_fail; + } + break; + + case LWS_CALLBACK_PROTOCOL_DESTROY: +init_fail: + vhd->finished = 1; + for (n = 0; n < (int)LWS_ARRAY_SIZE(vhd->pthread_spam); n++) + pthread_join(vhd->pthread_spam[n], &retval); + + if (vhd->ring) + lws_ring_destroy(vhd->ring); + + pthread_mutex_destroy(&vhd->lock_ring); + break; + + case LWS_CALLBACK_ESTABLISHED: + /* add ourselves to the list of live pss held in the vhd */ + pthread_mutex_lock(&vhd->lock_ring); + lws_ll_fwd_insert(pss, pss_list, vhd->pss_list); + pss->tail = lws_ring_get_oldest_tail(vhd->ring); + pss->wsi = wsi; + pthread_mutex_unlock(&vhd->lock_ring); + break; + + case LWS_CALLBACK_CLOSED: + /* doesn't reference ring */ + pthread_mutex_lock(&vhd->lock_ring); + /* remove our closing pss from the list of live pss */ + lws_ll_fwd_remove(struct per_session_data__minimal, pss_list, + pss, vhd->pss_list); + pthread_mutex_unlock(&vhd->lock_ring); + break; + + case LWS_CALLBACK_SERVER_WRITEABLE: + pthread_mutex_lock(&vhd->lock_ring); /* --------- ring lock { */ + + pmsg = lws_ring_get_element(vhd->ring, &pss->tail); + if (!pmsg) { + pthread_mutex_unlock(&vhd->lock_ring); /* } ring lock ------- */ + + break; + } + + assert(pmsg->payload); + + n = lws_snprintf(temp + LWS_PRE, sizeof(temp) - LWS_PRE, + "svc, %s", + (char *)pmsg->payload + LWS_PRE); + + /* notice we allowed for LWS_PRE in the payload already */ + m = lws_write(wsi, (unsigned char *)temp + LWS_PRE, n, + LWS_WRITE_TEXT); + if (m < n) { + pthread_mutex_unlock(&vhd->lock_ring); /* } ring lock ------- */ + + lwsl_err("ERROR %d writing to ws socket\n", m); + return -1; + } + + lws_ring_consume_and_update_oldest_tail( + vhd->ring, /* lws_ring object */ + struct per_session_data__minimal, /* type of objects with tails */ + &pss->tail, /* tail of guy doing the consuming */ + 1, /* number of payload objects being consumed */ + vhd->pss_list, /* head of list of objects with tails */ + tail, /* member name of tail in objects with tails */ + pss_list /* member name of next object in objects with tails */ + ); + + /* more to do? */ + if (lws_ring_get_element(vhd->ring, &pss->tail)) + /* come back as soon as we can write more */ + lws_callback_on_writable(pss->wsi); + + pthread_mutex_unlock(&vhd->lock_ring); /* } ring lock ------- */ + + break; + + case LWS_CALLBACK_RECEIVE: + break; + + case LWS_CALLBACK_EVENT_WAIT_CANCELLED: + // lwsl_notice("EVENT_WAIT_CANCELLED tsi %d\n", lws_wsi_tsi(wsi)); + if (!vhd) + break; + /* + * When the "spam" threads add a message to the ringbuffer, + * they create this event in the lws service thread context + * using lws_cancel_service(). + * + * We respond by scheduling a writable callback for all + * connected clients. + */ + + pthread_mutex_lock(&vhd->lock_ring); /* --------- ring lock { */ + + lws_start_foreach_llp(struct per_session_data__minimal **, + ppss, vhd->pss_list) { + if (lws_wsi_tsi((*ppss)->wsi) == lws_wsi_tsi(wsi)) + lws_callback_on_writable((*ppss)->wsi); + } lws_end_foreach_llp(ppss, pss_list); + + pthread_mutex_unlock(&vhd->lock_ring); /* } ring lock ------- */ + break; + + default: + break; + } + + return r; +} + +#define LWS_PLUGIN_PROTOCOL_MINIMAL \ + { \ + "lws-minimal", \ + callback_minimal, \ + sizeof(struct per_session_data__minimal), \ + 128, \ + 0, NULL, 0 \ + } diff -Nru libwebsockets-3.2.1/minimal-examples/ws-server/minimal-ws-server-threads-foreign-smp/README.md libwebsockets-4.1.6/minimal-examples/ws-server/minimal-ws-server-threads-foreign-smp/README.md --- libwebsockets-3.2.1/minimal-examples/ws-server/minimal-ws-server-threads-foreign-smp/README.md 1970-01-01 00:00:00.000000000 +0000 +++ libwebsockets-4.1.6/minimal-examples/ws-server/minimal-ws-server-threads-foreign-smp/README.md 2020-12-01 17:40:26.000000000 +0000 @@ -0,0 +1,39 @@ +# lws minimal ws server (threads) + SMP + +This demonstrates both independent threads creating content as in the +-threads example, multiple service threads as in the http-server-smp +example (but with ws), and using the foreign libuv loop. + +## build + +You must first build libwebsockets itself with cmake `-DLWS_MAX_SMP=8` +or some other number greater than one, as well as `-DLWS_WITH_LIBUV=1` + +``` + $ cmake . && make +``` + +Pthreads is required on your system. + +## usage + +``` + $ ./lws-minimal-ws-server-threads-smp +[2019/01/28 06:59:17:4217] USER: LWS minimal ws server + threads + smp | visit http://localhost:7681 +[2019/01/28 06:59:17:4219] NOTICE: Service threads: 2 +[2019/01/28 06:59:17:4220] NOTICE: LWS_CALLBACK_EVENT_WAIT_CANCELLED in svc tid 0x7fec48af8700 +[2019/01/28 06:59:17:4220] NOTICE: LWS_CALLBACK_EVENT_WAIT_CANCELLED in svc tid 0x7fec48af8700 +... +``` + +Visit http://localhost:7681 on multiple browser windows. You may need to open +4 before the second service thread is used (check "svc tid" in the browser output). + +Two lws service threads are started. + +Two separate asynchronous threads generate strings and add them to a ringbuffer, +signalling all lws service threads to send new entries to all the browser windows. + +This demonstrates how to safely manage asynchronously generated content +and hook it up to the lws service threads. + diff -Nru libwebsockets-3.2.1/minimal-examples/ws-server/minimal-ws-server-threads-smp/CMakeLists.txt libwebsockets-4.1.6/minimal-examples/ws-server/minimal-ws-server-threads-smp/CMakeLists.txt --- libwebsockets-3.2.1/minimal-examples/ws-server/minimal-ws-server-threads-smp/CMakeLists.txt 2019-12-18 14:45:31.000000000 +0000 +++ libwebsockets-4.1.6/minimal-examples/ws-server/minimal-ws-server-threads-smp/CMakeLists.txt 2020-12-01 17:40:26.000000000 +0000 @@ -1,91 +1,26 @@ +project(lws-minimal-ws-server-threads-smp C) cmake_minimum_required(VERSION 2.8) +find_package(libwebsockets CONFIG REQUIRED) +list(APPEND CMAKE_MODULE_PATH ${LWS_CMAKE_DIR}) include(CheckIncludeFile) include(CheckCSourceCompiles) +include(LwsCheckRequirements) set(SAMP lws-minimal-ws-server-threads-smp) set(SRCS minimal-ws-server.c) -MACRO(require_pthreads result) - CHECK_INCLUDE_FILE(pthread.h LWS_HAVE_PTHREAD_H) - if (NOT LWS_HAVE_PTHREAD_H) - if (LWS_WITH_MINIMAL_EXAMPLES) - set(result 0) - else() - message(FATAL_ERROR "threading support requires pthreads") - endif() - endif() -ENDMACRO() - -# 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_pthreads(requirements) require_lws_config(LWS_ROLE_WS 1 requirements) -require_lws_config(LWS_WITHOUT_SERVER 0 requirements) +require_lws_config(LWS_WITH_SERVER 1 requirements) if (requirements) add_executable(${SAMP} ${SRCS}) if (websockets_shared) - target_link_libraries(${SAMP} websockets_shared pthread) + target_link_libraries(${SAMP} websockets_shared ${PTHREAD_LIB} ${LIBWEBSOCKETS_DEP_LIBS}) add_dependencies(${SAMP} websockets_shared) else() - target_link_libraries(${SAMP} websockets pthread) + target_link_libraries(${SAMP} websockets ${PTHREAD_LIB} ${LIBWEBSOCKETS_DEP_LIBS}) endif() endif() diff -Nru libwebsockets-3.2.1/minimal-examples/ws-server/minimal-ws-server-threads-smp/minimal-ws-server.c libwebsockets-4.1.6/minimal-examples/ws-server/minimal-ws-server-threads-smp/minimal-ws-server.c --- libwebsockets-3.2.1/minimal-examples/ws-server/minimal-ws-server-threads-smp/minimal-ws-server.c 2019-12-18 14:45:31.000000000 +0000 +++ libwebsockets-4.1.6/minimal-examples/ws-server/minimal-ws-server-threads-smp/minimal-ws-server.c 2020-12-01 17:40:26.000000000 +0000 @@ -21,6 +21,12 @@ #include #include #include +#if defined(WIN32) +#define HAVE_STRUCT_TIMESPEC +#if defined(pid_t) +#undef pid_t +#endif +#endif #include #define LWS_PLUGIN_STATIC diff -Nru libwebsockets-3.2.1/minimal-examples/ws-server/minimal-ws-server-threads-smp/mount-origin/example.js libwebsockets-4.1.6/minimal-examples/ws-server/minimal-ws-server-threads-smp/mount-origin/example.js --- libwebsockets-3.2.1/minimal-examples/ws-server/minimal-ws-server-threads-smp/mount-origin/example.js 2019-12-18 14:45:31.000000000 +0000 +++ libwebsockets-4.1.6/minimal-examples/ws-server/minimal-ws-server-threads-smp/mount-origin/example.js 2020-12-01 17:40:26.000000000 +0000 @@ -28,15 +28,12 @@ function new_ws(urlpath, protocol) { - if (typeof MozWebSocket != "undefined") - return new MozWebSocket(urlpath, protocol); - return new WebSocket(urlpath, protocol); } document.addEventListener("DOMContentLoaded", function() { - ws = new_ws(get_appropriate_ws_url(""), "lws-minimal"); + var ws = new_ws(get_appropriate_ws_url(""), "lws-minimal"); try { ws.onopen = function() { document.getElementById("r").disabled = 0; diff -Nru libwebsockets-3.2.1/minimal-examples/ws-server/minimal-ws-server-threads-smp/mount-origin/libwebsockets.org-logo.svg libwebsockets-4.1.6/minimal-examples/ws-server/minimal-ws-server-threads-smp/mount-origin/libwebsockets.org-logo.svg --- libwebsockets-3.2.1/minimal-examples/ws-server/minimal-ws-server-threads-smp/mount-origin/libwebsockets.org-logo.svg 2019-12-18 14:45:31.000000000 +0000 +++ libwebsockets-4.1.6/minimal-examples/ws-server/minimal-ws-server-threads-smp/mount-origin/libwebsockets.org-logo.svg 2020-12-01 17:40:26.000000000 +0000 @@ -1,120 +1,66 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + + +image/svg+xml + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff -Nru libwebsockets-3.2.1/minimal-examples/ws-server/minimal-ws-server-threads-smp/protocol_lws_minimal.c libwebsockets-4.1.6/minimal-examples/ws-server/minimal-ws-server-threads-smp/protocol_lws_minimal.c --- libwebsockets-3.2.1/minimal-examples/ws-server/minimal-ws-server-threads-smp/protocol_lws_minimal.c 2019-12-18 14:45:31.000000000 +0000 +++ libwebsockets-4.1.6/minimal-examples/ws-server/minimal-ws-server-threads-smp/protocol_lws_minimal.c 2020-12-01 17:40:26.000000000 +0000 @@ -83,7 +83,11 @@ struct per_vhost_data__minimal *vhd = (struct per_vhost_data__minimal *)d; struct msg amsg; - int len = 128, index = 1, n; + int len = 128, index = 1, n, whoami = 0; + + for (n = 0; n < (int)LWS_ARRAY_SIZE(vhd->pthread_spam); n++) + if (pthread_equal(pthread_self(), vhd->pthread_spam[n])) + whoami = n + 1; do { /* don't generate output if nobody connected */ @@ -105,10 +109,10 @@ goto wait_unlock; } n = lws_snprintf((char *)amsg.payload + LWS_PRE, len, - "%s: spam tid: %p, msg: %d", vhd->config, - (void *)pthread_self(), index++); + "%s: spam tid: %d, msg: %d", vhd->config, + whoami, index++); amsg.len = n; - n = lws_ring_insert(vhd->ring, &amsg, 1); + n = (int)lws_ring_insert(vhd->ring, &amsg, 1); if (n != 1) { __minimal_destroy_message(&amsg); lwsl_user("dropping!\n"); @@ -127,7 +131,7 @@ } while (!vhd->finished); - lwsl_notice("thread_spam %p exiting\n", (void *)pthread_self()); + lwsl_notice("thread_spam %d exiting\n", whoami); pthread_exit(NULL); @@ -199,8 +203,7 @@ init_fail: vhd->finished = 1; for (n = 0; n < (int)LWS_ARRAY_SIZE(vhd->pthread_spam); n++) - if (vhd->pthread_spam[n]) - pthread_join(vhd->pthread_spam[n], &retval); + pthread_join(vhd->pthread_spam[n], &retval); if (vhd->ring) lws_ring_destroy(vhd->ring); @@ -231,7 +234,7 @@ } n = lws_snprintf(temp + LWS_PRE, sizeof(temp) - LWS_PRE, - "svc tid:%p, %s", (void *)pthread_self(), + "svc, %s", (char *)pmsg->payload + LWS_PRE); /* notice we allowed for LWS_PRE in the payload already */ @@ -265,8 +268,7 @@ break; case LWS_CALLBACK_EVENT_WAIT_CANCELLED: - lwsl_notice("LWS_CALLBACK_EVENT_WAIT_CANCELLED in svc tid %p\n", - (void *)pthread_self()); + lwsl_notice("LWS_CALLBACK_EVENT_WAIT_CANCELLED in svc\n"); if (!vhd) break; /* @@ -298,36 +300,3 @@ 128, \ 0, NULL, 0 \ } - -#if !defined (LWS_PLUGIN_STATIC) - -/* boilerplate needed if we are built as a dynamic plugin */ - -static const struct lws_protocols protocols[] = { - LWS_PLUGIN_PROTOCOL_MINIMAL -}; - -LWS_EXTERN LWS_VISIBLE int -init_protocol_minimal(struct lws_context *context, - struct lws_plugin_capability *c) -{ - if (c->api_magic != LWS_PLUGIN_API_MAGIC) { - lwsl_err("Plugin API %d, library API %d", LWS_PLUGIN_API_MAGIC, - c->api_magic); - return 1; - } - - c->protocols = protocols; - c->count_protocols = LWS_ARRAY_SIZE(protocols); - c->extensions = NULL; - c->count_extensions = 0; - - return 0; -} - -LWS_EXTERN LWS_VISIBLE int -destroy_protocol_minimal(struct lws_context *context) -{ - return 0; -} -#endif diff -Nru libwebsockets-3.2.1/minimal-examples/ws-server/minimal-ws-server-timer/CMakeLists.txt libwebsockets-4.1.6/minimal-examples/ws-server/minimal-ws-server-timer/CMakeLists.txt --- libwebsockets-3.2.1/minimal-examples/ws-server/minimal-ws-server-timer/CMakeLists.txt 2019-12-18 14:45:31.000000000 +0000 +++ libwebsockets-4.1.6/minimal-examples/ws-server/minimal-ws-server-timer/CMakeLists.txt 2020-12-01 17:40:26.000000000 +0000 @@ -1,67 +1,13 @@ +project(lws-minimal-ws-server-timer C) cmake_minimum_required(VERSION 2.8) +find_package(libwebsockets CONFIG REQUIRED) +list(APPEND CMAKE_MODULE_PATH ${LWS_CMAKE_DIR}) include(CheckCSourceCompiles) +include(LwsCheckRequirements) set(SAMP lws-minimal-ws-server-timer) set(SRCS minimal-ws-server.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_ROLE_WS 1 requirements) require_lws_config(LWS_WITH_SERVER 1 requirements) @@ -70,9 +16,9 @@ add_executable(${SAMP} ${SRCS}) if (websockets_shared) - target_link_libraries(${SAMP} websockets_shared) + target_link_libraries(${SAMP} websockets_shared ${LIBWEBSOCKETS_DEP_LIBS}) add_dependencies(${SAMP} websockets_shared) else() - target_link_libraries(${SAMP} websockets) + target_link_libraries(${SAMP} websockets ${LIBWEBSOCKETS_DEP_LIBS}) endif() endif() diff -Nru libwebsockets-3.2.1/minimal-examples/ws-server/minimal-ws-server-timer/minimal-ws-server.c libwebsockets-4.1.6/minimal-examples/ws-server/minimal-ws-server-timer/minimal-ws-server.c --- libwebsockets-3.2.1/minimal-examples/ws-server/minimal-ws-server-timer/minimal-ws-server.c 2019-12-18 14:45:31.000000000 +0000 +++ libwebsockets-4.1.6/minimal-examples/ws-server/minimal-ws-server-timer/minimal-ws-server.c 2020-12-01 17:40:26.000000000 +0000 @@ -53,6 +53,11 @@ { NULL, NULL, 0, 0 } /* terminator */ }; +static const lws_retry_bo_t retry = { + .secs_since_valid_ping = 3, + .secs_since_valid_hangup = 10, +}; + static int interrupted; static const struct lws_http_mount mount = { @@ -109,16 +114,21 @@ info.options = LWS_SERVER_OPTION_HTTP_HEADERS_SECURITY_BEST_PRACTICES_ENFORCE; +#if defined(LWS_WITH_TLS) if (lws_cmdline_option(argc, argv, "-s")) { lwsl_user("Server using TLS\n"); info.options |= LWS_SERVER_OPTION_DO_SSL_GLOBAL_INIT; info.ssl_cert_filepath = "localhost-100y.cert"; info.ssl_private_key_filepath = "localhost-100y.key"; } +#endif if (lws_cmdline_option(argc, argv, "-h")) info.options |= LWS_SERVER_OPTION_VHOST_UPG_STRICT_HOST_CHECK; + if (lws_cmdline_option(argc, argv, "-v")) + info.retry_and_idle_policy = &retry; + context = lws_create_context(&info); if (!context) { lwsl_err("lws init failed\n"); diff -Nru libwebsockets-3.2.1/minimal-examples/ws-server/minimal-ws-server-timer/mount-origin/example.js libwebsockets-4.1.6/minimal-examples/ws-server/minimal-ws-server-timer/mount-origin/example.js --- libwebsockets-3.2.1/minimal-examples/ws-server/minimal-ws-server-timer/mount-origin/example.js 2019-12-18 14:45:31.000000000 +0000 +++ libwebsockets-4.1.6/minimal-examples/ws-server/minimal-ws-server-timer/mount-origin/example.js 2020-12-01 17:40:26.000000000 +0000 @@ -27,9 +27,6 @@ function new_ws(urlpath, protocol) { - if (typeof MozWebSocket != "undefined") - return new MozWebSocket(urlpath, protocol); - return new WebSocket(urlpath, protocol); } Binary files /tmp/tmp2l8bmswe/3lv7Sxvgkv/libwebsockets-3.2.1/minimal-examples/ws-server/minimal-ws-server-timer/mount-origin/favicon.ico and /tmp/tmp2l8bmswe/LwTwoWz49Q/libwebsockets-4.1.6/minimal-examples/ws-server/minimal-ws-server-timer/mount-origin/favicon.ico differ diff -Nru libwebsockets-3.2.1/minimal-examples/ws-server/minimal-ws-server-timer/mount-origin/libwebsockets.org-logo.svg libwebsockets-4.1.6/minimal-examples/ws-server/minimal-ws-server-timer/mount-origin/libwebsockets.org-logo.svg --- libwebsockets-3.2.1/minimal-examples/ws-server/minimal-ws-server-timer/mount-origin/libwebsockets.org-logo.svg 2019-12-18 14:45:31.000000000 +0000 +++ libwebsockets-4.1.6/minimal-examples/ws-server/minimal-ws-server-timer/mount-origin/libwebsockets.org-logo.svg 2020-12-01 17:40:26.000000000 +0000 @@ -1,120 +1,66 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + + +image/svg+xml + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff -Nru libwebsockets-3.2.1/plugins/acme-client/protocol_lws_acme_client.c libwebsockets-4.1.6/plugins/acme-client/protocol_lws_acme_client.c --- libwebsockets-3.2.1/plugins/acme-client/protocol_lws_acme_client.c 2019-12-18 14:45:31.000000000 +0000 +++ libwebsockets-4.1.6/plugins/acme-client/protocol_lws_acme_client.c 2020-12-01 17:40:26.000000000 +0000 @@ -1,23 +1,25 @@ /* * libwebsockets ACME client protocol plugin * - * Copyright (C) 2017 Andy Green + * Copyright (C) 2010 - 2019 Andy Green * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation: - * version 2.1 of the License. + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to + * deal in the Software without restriction, including without limitation the + * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or + * sell copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: * - * This library is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with this library; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, - * MA 02110-1301 USA + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS + * IN THE SOFTWARE. * * Acme is in a big messy transition at the moment from a homebrewed api * to an IETF one. The old repo for the homebrew api (they currently @@ -41,12 +43,15 @@ #include typedef enum { - ACME_STATE_DIRECTORY, /* get the directory JSON using GET + parse */ - ACME_STATE_NEW_REG, /* register a new RSA key + email combo */ - ACME_STATE_NEW_AUTH, /* start the process to request a cert */ - ACME_STATE_ACCEPT_CHALL, /* notify server ready for one challenge */ - ACME_STATE_POLLING, /* he should be trying our challenge */ - ACME_STATE_POLLING_CSR, /* sent CSR, checking result */ + ACME_STATE_DIRECTORY, /* get the directory JSON using GET + parse */ + ACME_STATE_NEW_NONCE, /* get the replay nonce */ + ACME_STATE_NEW_ACCOUNT, /* register a new RSA key + email combo */ + ACME_STATE_NEW_ORDER, /* start the process to request a cert */ + ACME_STATE_AUTHZ, /* */ + ACME_STATE_START_CHALL, /* notify server ready for one challenge */ + ACME_STATE_POLLING, /* he should be trying our challenge */ + ACME_STATE_POLLING_CSR, /* sent CSR, checking result */ + ACME_STATE_DOWNLOAD_CERT, ACME_STATE_FINISHED } lws_acme_state; @@ -58,9 +63,17 @@ char challenge_uri[256]; char detail[64]; char status[16]; - char san_a[100]; - char san_b[100]; + char key_auth[256]; + char http01_mountpoint[256]; + struct lws_http_mount mount; char urls[6][100]; /* directory contents */ + char active_url[100]; + char authz_url[100]; + char order_url[100]; + char finalize_url[100]; + char cert_url[100]; + char acct_id[100]; + char *kid; lws_acme_state state; struct lws_client_connect_info i; struct lejp_ctx jctx; @@ -117,52 +130,230 @@ }; static int -callback_acme_client(struct lws *wsi, enum lws_callback_reasons reason, - void *user, void *in, size_t len); +callback_chall_http01(struct lws *wsi, enum lws_callback_reasons reason, + void *user, void *in, size_t len) +{ + struct lws_vhost *vhost = lws_get_vhost(wsi); + struct acme_connection *ac = lws_vhost_user(vhost); + uint8_t buf[LWS_PRE + 2048], *start = &buf[LWS_PRE], *p = start, + *end = &buf[sizeof(buf) - LWS_PRE - 1]; + int n; -#define LWS_PLUGIN_PROTOCOL_LWS_ACME_CLIENT \ - { \ - "lws-acme-client", \ - callback_acme_client, \ - 0, \ - 512, \ - 0, NULL, 0 \ + switch (reason) { + case LWS_CALLBACK_HTTP: + lwsl_notice("%s: ca connection received, key_auth %s\n", + __func__, ac->key_auth); + + if (lws_add_http_header_status(wsi, HTTP_STATUS_OK, &p, end)) { + lwsl_notice("%s: add status failed\n", __func__); + return -1; + } + + if (lws_add_http_header_by_token(wsi, + WSI_TOKEN_HTTP_CONTENT_TYPE, + (unsigned char *)"text/plain", 10, + &p, end)) { + lwsl_notice("%s: add content_type failed\n", __func__); + return -1; + } + + n = strlen(ac->key_auth); + if (lws_add_http_header_content_length(wsi, n, &p, end)) { + lwsl_notice("%s: add content_length failed\n", + __func__); + return -1; + } + + if (lws_add_http_header_by_token(wsi, + WSI_TOKEN_HTTP_CONTENT_DISPOSITION, + (unsigned char *)"attachment", 10, + &p, end)) { + lwsl_notice("%s: add content_dispo failed\n", __func__); + return -1; + } + + if (lws_finalize_write_http_header(wsi, start, &p, end)) { + lwsl_notice("%s: finalize http header failed\n", + __func__); + return -1; + } + + lws_callback_on_writable(wsi); + return 0; + + case LWS_CALLBACK_HTTP_WRITEABLE: + p += lws_snprintf((char *)p, end - p, "%s", ac->key_auth); + lwsl_notice("%s: len %d\n", __func__, lws_ptr_diff(p, start)); + if (lws_write(wsi, (uint8_t *)start, lws_ptr_diff(p, start), + LWS_WRITE_HTTP_FINAL) != lws_ptr_diff(p, start)) { + lwsl_err("_write content failed\n"); + return 1; + } + + if (lws_http_transaction_completed(wsi)) + return -1; + + return 0; + + default: + break; } -static const struct lws_protocols acme_protocols[] = { - LWS_PLUGIN_PROTOCOL_LWS_ACME_CLIENT, + return lws_callback_http_dummy(wsi, reason, user, in, len); +} + +static const struct lws_protocols chall_http01_protocols[] = { + { "http", callback_chall_http01, 0, 0, 0, NULL, 0 }, { NULL, NULL, 0, 0, 0, NULL, 0 } }; +static int +jws_create_packet(struct lws_jwe *jwe, const char *payload, size_t len, + const char *nonce, const char *url, const char *kid, + char *out, size_t out_len, struct lws_context *context) +{ + char *buf, *start, *p, *end, *p1, *end1; + struct lws_jws jws; + int n, m; + + lws_jws_init(&jws, &jwe->jwk, context); + + /* + * This buffer is local to the function, the actual output is prepared + * into out. Only the plaintext protected header + * (which contains the public key, 512 bytes for 4096b) goes in + * here temporarily. + */ + n = LWS_PRE + 2048; + buf = malloc(n); + if (!buf) { + lwsl_notice("%s: malloc %d failed\n", __func__, n); + return -1; + } + + p = start = buf + LWS_PRE; + end = buf + n - LWS_PRE - 1; + + /* + * temporary JWS protected header plaintext + */ + if (!jwe->jose.alg || !jwe->jose.alg->alg) + goto bail; + + p += lws_snprintf(p, end - p, "{\"alg\":\"RS256\""); + if (kid) + p += lws_snprintf(p, end - p, ",\"kid\":\"%s\"", kid); + else { + p += lws_snprintf(p, end - p, ",\"jwk\":"); + m = end - p; + n = lws_jwk_export(&jwe->jwk, 0, p, &m); + if (n < 0) { + lwsl_notice("failed to export jwk\n"); + goto bail; + } + p += n; + } + p += lws_snprintf(p, end - p, ",\"url\":\"%s\"", url); + p += lws_snprintf(p, end - p, ",\"nonce\":\"%s\"}", nonce); + + /* + * prepare the signed outer JSON with all the parts in + */ + p1 = out; + end1 = out + out_len - 1; + + p1 += lws_snprintf(p1, end1 - p1, "{\"protected\":\""); + jws.map_b64.buf[LJWS_JOSE] = p1; + n = lws_jws_base64_enc(start, p - start, p1, end1 - p1); + if (n < 0) { + lwsl_notice("%s: failed to encode protected\n", __func__); + goto bail; + } + jws.map_b64.len[LJWS_JOSE] = n; + p1 += n; + + p1 += lws_snprintf(p1, end1 - p1, "\",\"payload\":\""); + jws.map_b64.buf[LJWS_PYLD] = p1; + n = lws_jws_base64_enc(payload, len, p1, end1 - p1); + if (n < 0) { + lwsl_notice("%s: failed to encode payload\n", __func__); + goto bail; + } + jws.map_b64.len[LJWS_PYLD] = n; + p1 += n; + + p1 += lws_snprintf(p1, end1 - p1, "\",\"signature\":\""); + + /* + * taking the b64 protected header and the b64 payload, sign them + * and place the signature into the packet + */ + n = lws_jws_sign_from_b64(&jwe->jose, &jws, p1, end1 - p1); + if (n < 0) { + lwsl_notice("sig gen failed\n"); + + goto bail; + } + jws.map_b64.buf[LJWS_SIG] = p1; + jws.map_b64.len[LJWS_SIG] = n; + + p1 += n; + p1 += lws_snprintf(p1, end1 - p1, "\"}"); + + free(buf); + + return p1 - out; + +bail: + lws_jws_destroy(&jws); + free(buf); + + return -1; +} + +static int +callback_acme_client(struct lws *wsi, enum lws_callback_reasons reason, + void *user, void *in, size_t len); + +#define LWS_PLUGIN_PROTOCOL_LWS_ACME_CLIENT \ +{ \ + "lws-acme-client", \ + callback_acme_client, \ + 0, \ + 512, \ + 0, NULL, 0 \ +} + /* directory JSON parsing */ static const char * const jdir_tok[] = { - "key-change", - "meta.terms-of-service", - "new-authz", - "new-cert", - "new-reg", - "revoke-cert", + "keyChange", + "meta.termsOfService", + "newAccount", + "newNonce", + "newOrder", + "revokeCert", }; -enum enum_jhdr_tok { + +enum enum_jdir_tok { JAD_KEY_CHANGE_URL, JAD_TOS_URL, - JAD_NEW_AUTHZ_URL, - JAD_NEW_CERT_URL, - JAD_NEW_REG_URL, + JAD_NEW_ACCOUNT_URL, + JAD_NEW_NONCE_URL, + JAD_NEW_ORDER_URL, JAD_REVOKE_CERT_URL, }; + static signed char cb_dir(struct lejp_ctx *ctx, char reason) { struct per_vhost_data__lws_acme_client *s = - (struct per_vhost_data__lws_acme_client *)ctx->user; + (struct per_vhost_data__lws_acme_client *)ctx->user; if (reason == LEJPCB_VAL_STR_START && ctx->path_match) { s->pos = 0; s->len = sizeof(s->ac->urls[0]) - 1; s->dest = s->ac->urls[ctx->path_match - 1]; - return 0; } @@ -171,7 +362,6 @@ if (s->pos + ctx->npos > s->len) { lwsl_notice("url too long\n"); - return -1; } @@ -182,6 +372,66 @@ return 0; } + +/* order JSON parsing */ + +static const char * const jorder_tok[] = { + "status", + "expires", + "identifiers[].type", + "identifiers[].value", + "authorizations", + "finalize", + "certificate" +}; + +enum enum_jorder_tok { + JAO_STATUS, + JAO_EXPIRES, + JAO_IDENTIFIERS_TYPE, + JAO_IDENTIFIERS_VALUE, + JAO_AUTHORIZATIONS, + JAO_FINALIZE, + JAO_CERT +}; + +static signed char +cb_order(struct lejp_ctx *ctx, char reason) +{ + struct acme_connection *s = (struct acme_connection *)ctx->user; + + if (reason == LEJPCB_CONSTRUCTED) + s->authz_url[0] = '\0'; + + if (!(reason & LEJP_FLAG_CB_IS_VALUE) || !ctx->path_match) + return 0; + + switch (ctx->path_match - 1) { + case JAO_STATUS: + lws_strncpy(s->status, ctx->buf, sizeof(s->status)); + break; + case JAO_EXPIRES: + break; + case JAO_IDENTIFIERS_TYPE: + break; + case JAO_IDENTIFIERS_VALUE: + break; + case JAO_AUTHORIZATIONS: + lws_snprintf(s->authz_url, sizeof(s->authz_url), "%s", + ctx->buf); + break; + case JAO_FINALIZE: + lws_snprintf(s->finalize_url, sizeof(s->finalize_url), "%s", + ctx->buf); + break; + case JAO_CERT: + lws_snprintf(s->cert_url, sizeof(s->cert_url), "%s", ctx->buf); + break; + } + + return 0; +} + /* authz JSON parsing */ static const char * const jauthz_tok[] = { @@ -191,10 +441,11 @@ "expires", "challenges[].type", "challenges[].status", - "challenges[].uri", + "challenges[].url", "challenges[].token", "detail" }; + enum enum_jauthz_tok { JAAZ_ID_TYPE, JAAZ_ID_VALUE, @@ -202,10 +453,11 @@ JAAZ_EXPIRES, JAAZ_CHALLENGES_TYPE, JAAZ_CHALLENGES_STATUS, - JAAZ_CHALLENGES_URI, + JAAZ_CHALLENGES_URL, JAAZ_CHALLENGES_TOKEN, JAAZ_DETAIL, }; + static signed char cb_authz(struct lejp_ctx *ctx, char reason) { @@ -215,7 +467,6 @@ s->yes = 0; s->use = 0; s->chall_token[0] = '\0'; - s->is_sni_02 = 0; } if (!(reason & LEJP_FLAG_CB_IS_VALUE) || !ctx->path_match) @@ -234,19 +485,17 @@ lws_snprintf(s->detail, sizeof(s->detail), "%s", ctx->buf); break; case JAAZ_CHALLENGES_TYPE: - if (s->is_sni_02) - break; - s->use = !strcmp(ctx->buf, "tls-sni-01") || - !strcmp(ctx->buf, "tls-sni-02"); - s->is_sni_02 = !strcmp(ctx->buf, "tls-sni-02"); + lwsl_notice("JAAZ_CHALLENGES_TYPE: %s\n", ctx->buf); + s->use = !strcmp(ctx->buf, "http-01"); break; case JAAZ_CHALLENGES_STATUS: lws_strncpy(s->status, ctx->buf, sizeof(s->status)); break; - case JAAZ_CHALLENGES_URI: + case JAAZ_CHALLENGES_URL: + lwsl_notice("JAAZ_CHALLENGES_URL: %s %d\n", ctx->buf, s->use); if (s->use) { lws_strncpy(s->challenge_uri, ctx->buf, - sizeof(s->challenge_uri)); + sizeof(s->challenge_uri)); s->yes |= 2; } break; @@ -254,7 +503,7 @@ lwsl_notice("JAAZ_CHALLENGES_TOKEN: %s %d\n", ctx->buf, s->use); if (s->use) { lws_strncpy(s->chall_token, ctx->buf, - sizeof(s->chall_token)); + sizeof(s->chall_token)); s->yes |= 1; } break; @@ -272,6 +521,7 @@ "token", "error.detail" }; + enum enum_jchac_tok { JCAC_TYPE, JCAC_STATUS, @@ -279,6 +529,7 @@ JCAC_TOKEN, JCAC_DETAIL, }; + static signed char cb_chac(struct lejp_ctx *ctx, char reason) { @@ -294,8 +545,7 @@ switch (ctx->path_match - 1) { case JCAC_TYPE: - if (strcmp(ctx->buf, "tls-sni-01") && - strcmp(ctx->buf, "tls-sni-02")) + if (strcmp(ctx->buf, "http-01")) return 1; break; case JCAC_STATUS: @@ -305,8 +555,7 @@ s->yes |= 2; break; case JCAC_TOKEN: - lws_strncpy(s->chall_token, ctx->buf, - sizeof(s->chall_token)); + lws_strncpy(s->chall_token, ctx->buf, sizeof(s->chall_token)); s->yes |= 1; break; case JCAC_DETAIL: @@ -317,29 +566,6 @@ return 0; } -/* https://github.com/letsencrypt/boulder/blob/release/docs/acme-divergences.md - * - * 7.1: - * - * Boulder does not implement the new-order resource. - * Instead of new-order Boulder implements the new-cert resource that is - * defined in draft-ietf-acme-02 Section 6.5. - * - * Boulder also doesn't implement the new-nonce endpoint. - * - * Boulder implements the new-account resource only under the new-reg key. - * - * Boulder implements Link: rel="next" headers from new-reg to new-authz, and - * new-authz to new-cert, as specified in draft-02, but these links are not - * provided in the latest draft, and clients should use URLs from the directory - * instead. - * - * Boulder does not provide the "index" link relation pointing at the - * directory URL. - * - * (ie, just use new-cert instead of new-order, use the directory for links) - */ - static int lws_acme_report_status(struct lws_vhost *v, int state, const char *json) { @@ -354,8 +580,8 @@ */ static struct lws * lws_acme_client_connect(struct lws_context *context, struct lws_vhost *vh, - struct lws **pwsi, struct lws_client_connect_info *i, - char *url, const char *method) + struct lws **pwsi, struct lws_client_connect_info *i, + char *url, const char *method) { const char *prot, *p; char path[200], _url[256]; @@ -376,7 +602,7 @@ i->path = path; i->context = context; i->vhost = vh; - i->ssl_connection = 1; + i->ssl_connection = LCCSCF_USE_SSL; i->host = i->address; i->origin = i->address; i->method = method; @@ -397,7 +623,7 @@ static void lws_acme_finished(struct per_vhost_data__lws_acme_client *vhd) { - lwsl_debug("%s\n", __func__); + lwsl_notice("%s\n", __func__); if (vhd->ac) { if (vhd->ac->vhost) @@ -422,6 +648,7 @@ "locality", "organization", "common-name", + "subject-alt-name", "email", "directory-url", "auth-path", @@ -431,32 +658,30 @@ static int lws_acme_load_create_auth_keys(struct per_vhost_data__lws_acme_client *vhd, - int bits) + int bits) { int n; if (!lws_jwk_load(&vhd->jwk, vhd->pvop[LWS_TLS_SET_AUTH_PATH], - NULL, NULL)) + NULL, NULL)) return 0; vhd->jwk.kty = LWS_GENCRYPTO_KTY_RSA; + lwsl_notice("Generating ACME %d-bit keypair... " - "will take a little while\n", bits); + "will take a little while\n", bits); n = lws_genrsa_new_keypair(vhd->context, &vhd->rsactx, LGRSAM_PKCS1_1_5, - vhd->jwk.e, bits); + vhd->jwk.e, bits); if (n) { lwsl_notice("failed to create keypair\n"); - return 1; } lwsl_notice("...keypair generated\n"); - if (lws_jwk_save(&vhd->jwk, - vhd->pvop[LWS_TLS_SET_AUTH_PATH])) { + if (lws_jwk_save(&vhd->jwk, vhd->pvop[LWS_TLS_SET_AUTH_PATH])) { lwsl_notice("unable to save %s\n", - vhd->pvop[LWS_TLS_SET_AUTH_PATH]); - + vhd->pvop[LWS_TLS_SET_AUTH_PATH]); return 1; } @@ -465,7 +690,7 @@ static int lws_acme_start_acquisition(struct per_vhost_data__lws_acme_client *vhd, - struct lws_vhost *v) + struct lws_vhost *v) { char buf[128]; @@ -478,7 +703,7 @@ * ...well... we should try to do something about it then... */ lwsl_notice("%s: ACME cert needs creating / updating: " - "vhost %s\n", __func__, lws_get_vhost_name(vhd->vhost)); + "vhost %s\n", __func__, lws_get_vhost_name(vhd->vhost)); vhd->ac = malloc(sizeof(*vhd->ac)); memset(vhd->ac, 0, sizeof(*vhd->ac)); @@ -502,11 +727,11 @@ if (!vhd->ac->urls[0][0]) { vhd->ac->state = ACME_STATE_DIRECTORY; lws_snprintf(buf, sizeof(buf) - 1, "%s", - vhd->pvop_active[LWS_TLS_SET_DIR_URL]); + vhd->pvop_active[LWS_TLS_SET_DIR_URL]); } else { - vhd->ac->state = ACME_STATE_NEW_REG; + vhd->ac->state = ACME_STATE_NEW_ACCOUNT; lws_snprintf(buf, sizeof(buf) - 1, "%s", - vhd->ac->urls[JAD_NEW_REG_URL]); + vhd->ac->urls[JAD_NEW_ACCOUNT_URL]); } vhd->ac->real_vh_port = lws_get_vhost_port(vhd->vhost); @@ -517,15 +742,15 @@ #if defined(LWS_WITH_ESP32) lws_acme_report_status(vhd->vhost, LWS_CUS_CREATE_KEYS, - "Generating keys, please wait"); + "Generating keys, please wait"); if (lws_acme_load_create_auth_keys(vhd, 2048)) goto bail; lws_acme_report_status(vhd->vhost, LWS_CUS_CREATE_KEYS, - "Auth keys created"); + "Auth keys created"); #endif if (lws_acme_client_connect(vhd->context, vhd->vhost, - &vhd->ac->cwsi, &vhd->ac->i, buf, "GET")) + &vhd->ac->cwsi, &vhd->ac->i, buf, "GET")) return 0; #if defined(LWS_WITH_ESP32) @@ -539,18 +764,17 @@ static int callback_acme_client(struct lws *wsi, enum lws_callback_reasons reason, - void *user, void *in, size_t len) + void *user, void *in, size_t len) { struct per_vhost_data__lws_acme_client *vhd = - (struct per_vhost_data__lws_acme_client *) - lws_protocol_vh_priv_get(lws_get_vhost(wsi), - lws_get_protocol(wsi)); + (struct per_vhost_data__lws_acme_client *) + lws_protocol_vh_priv_get(lws_get_vhost(wsi), + lws_get_protocol(wsi)); char buf[LWS_PRE + 2536], *start = buf + LWS_PRE, *p = start, - *end = buf + sizeof(buf) - 1, digest[32], *failreason = NULL; + *end = buf + sizeof(buf) - 1, digest[32], *failreason = NULL; const struct lws_protocol_vhost_options *pvo; struct lws_acme_cert_aging_args *caa; struct acme_connection *ac = NULL; - struct lws_genhash_ctx hctx; unsigned char **pp, *pend; const char *content_type; struct lws_jwe jwe; @@ -597,15 +821,19 @@ } n = 0; - for (m = 0; m < (int)LWS_ARRAY_SIZE(pvo_names); m++) - if (!vhd->pvop[m] && m >= LWS_TLS_REQ_ELEMENT_COMMON_NAME) { + for (m = 0; m < (int)LWS_ARRAY_SIZE(pvo_names); m++) { + if (!vhd->pvop[m] && + m >= LWS_TLS_REQ_ELEMENT_COMMON_NAME && + m != LWS_TLS_REQ_ELEMENT_SUBJECT_ALT_NAME) { lwsl_notice("%s: require pvo '%s'\n", __func__, - pvo_names[m]); + pvo_names[m]); n |= 1; - } else + } else { if (vhd->pvop[m]) lwsl_info(" %s: %s\n", pvo_names[m], - vhd->pvop[m]); + vhd->pvop[m]); + } + } if (n) { free(vhd->pvo_data); vhd->pvo_data = NULL; @@ -626,17 +854,18 @@ * still have root */ lws_snprintf(buf, sizeof(buf) - 1, "%s.upd", - vhd->pvop[LWS_TLS_SET_CERT_PATH]); - vhd->fd_updated_cert = lws_open(buf, LWS_O_WRONLY | LWS_O_CREAT | - LWS_O_TRUNC, 0600); + vhd->pvop[LWS_TLS_SET_CERT_PATH]); + vhd->fd_updated_cert = lws_open(buf, + LWS_O_WRONLY | LWS_O_CREAT | + LWS_O_TRUNC, 0600); if (vhd->fd_updated_cert < 0) { lwsl_err("unable to create update cert file %s\n", buf); return -1; } lws_snprintf(buf, sizeof(buf) - 1, "%s.upd", - vhd->pvop[LWS_TLS_SET_KEY_PATH]); + vhd->pvop[LWS_TLS_SET_KEY_PATH]); vhd->fd_updated_key = lws_open(buf, LWS_O_WRONLY | LWS_O_CREAT | - LWS_O_TRUNC, 0600); + LWS_O_TRUNC, 0600); if (vhd->fd_updated_key < 0) { lwsl_err("unable to create update key file %s\n", buf); return -1; @@ -680,7 +909,8 @@ vhd->pvop_active[n] = vhd->pvop[n]; lwsl_notice("starting acme acquisition on %s: %s\n", - lws_get_vhost_name(caa->vh), vhd->pvop_active[LWS_TLS_SET_DIR_URL]); + lws_get_vhost_name(caa->vh), + vhd->pvop_active[LWS_TLS_SET_DIR_URL]); lws_acme_start_acquisition(vhd, caa->vh); break; @@ -706,16 +936,17 @@ break; case LWS_CALLBACK_ESTABLISHED_CLIENT_HTTP: - lwsl_notice("lws_http_client_http_response %d\n", - lws_http_client_http_response(wsi)); + lwsl_notice("%s: ESTABLISHED_CLIENT_HTTP:" + "%p, state:%d, status:%d\n", __func__, wsi, + ac->state, lws_http_client_http_response(wsi)); if (!ac) break; ac->resp = lws_http_client_http_response(wsi); /* we get a new nonce each time */ if (lws_hdr_total_length(wsi, WSI_TOKEN_REPLAY_NONCE) && - lws_hdr_copy(wsi, ac->replay_nonce, - sizeof(ac->replay_nonce), - WSI_TOKEN_REPLAY_NONCE) < 0) { + lws_hdr_copy(wsi, ac->replay_nonce, + sizeof(ac->replay_nonce), + WSI_TOKEN_REPLAY_NONCE) < 0) { lwsl_notice("%s: nonce too large\n", __func__); goto failed; @@ -724,41 +955,80 @@ switch (ac->state) { case ACME_STATE_DIRECTORY: lejp_construct(&ac->jctx, cb_dir, vhd, jdir_tok, - LWS_ARRAY_SIZE(jdir_tok)); + LWS_ARRAY_SIZE(jdir_tok)); + break; + case ACME_STATE_NEW_NONCE: + /* + * we try to * register our keys next. + * It's OK if it ends up * they're already registered, + * this eliminates any * gaps where we stored the key + * but registration did not complete for some reason... + */ + ac->state = ACME_STATE_NEW_ACCOUNT; + lws_acme_report_status(vhd->vhost, LWS_CUS_REG, NULL); + + strcpy(buf, ac->urls[JAD_NEW_ACCOUNT_URL]); + cwsi = lws_acme_client_connect(vhd->context, vhd->vhost, + &ac->cwsi, &ac->i, buf, "POST"); + if (!cwsi) { + lwsl_notice("%s: failed to connect to acme\n", + __func__); + goto failed; + } + + return -1; + + case ACME_STATE_NEW_ACCOUNT: + if (!lws_hdr_total_length(wsi, + WSI_TOKEN_HTTP_LOCATION)) { + lwsl_notice("%s: no Location\n", __func__); + goto failed; + } + + if (lws_hdr_copy(wsi, ac->acct_id, sizeof(ac->acct_id), + WSI_TOKEN_HTTP_LOCATION) < 0) { + lwsl_notice("%s: Location too large\n", + __func__); + goto failed; + } + + ac->kid = ac->acct_id; + + lwsl_notice("Location: %s\n", ac->acct_id); break; - case ACME_STATE_NEW_REG: + + case ACME_STATE_NEW_ORDER: + if (lws_hdr_copy(wsi, ac->order_url, + sizeof(ac->order_url), + WSI_TOKEN_HTTP_LOCATION) < 0) { + lwsl_notice("%s: missing cert location:\n", + __func__); + + goto failed; + } + + lejp_construct(&ac->jctx, cb_order, ac, jorder_tok, + LWS_ARRAY_SIZE(jorder_tok)); break; - case ACME_STATE_NEW_AUTH: + + case ACME_STATE_AUTHZ: lejp_construct(&ac->jctx, cb_authz, ac, jauthz_tok, LWS_ARRAY_SIZE(jauthz_tok)); break; - case ACME_STATE_POLLING: - case ACME_STATE_ACCEPT_CHALL: + case ACME_STATE_START_CHALL: lejp_construct(&ac->jctx, cb_chac, ac, jchac_tok, LWS_ARRAY_SIZE(jchac_tok)); break; + case ACME_STATE_POLLING: case ACME_STATE_POLLING_CSR: - ac->cpos = 0; - if (ac->resp != 201) - break; - /* - * He acknowledges he will create the cert... - * get the URL to GET it from in the Location - * header. - */ - if (lws_hdr_copy(wsi, ac->challenge_uri, - sizeof(ac->challenge_uri), - WSI_TOKEN_HTTP_LOCATION) < 0) { - lwsl_notice("%s: missing cert location:\n", - __func__); - - goto failed; - } + lejp_construct(&ac->jctx, cb_order, ac, jorder_tok, + LWS_ARRAY_SIZE(jorder_tok)); + break; - lwsl_notice("told to fetch cert from %s\n", - ac->challenge_uri); + case ACME_STATE_DOWNLOAD_CERT: + ac->cpos = 0; break; default: @@ -769,38 +1039,40 @@ case LWS_CALLBACK_CLIENT_APPEND_HANDSHAKE_HEADER: if (!ac) break; - switch (ac->state) { + switch (ac->state) { case ACME_STATE_DIRECTORY: + case ACME_STATE_NEW_NONCE: break; - case ACME_STATE_NEW_REG: + + case ACME_STATE_NEW_ACCOUNT: p += lws_snprintf(p, end - p, "{" - "\"resource\":\"new-reg\"," - "\"contact\":[" - "\"mailto:%s\"" - "],\"agreement\":\"%s\"" - "}", - vhd->pvop_active[LWS_TLS_REQ_ELEMENT_EMAIL], - ac->urls[JAD_TOS_URL]); + "\"termsOfServiceAgreed\":true" + ",\"contact\": [\"mailto:%s\"]}", + vhd->pvop_active[LWS_TLS_REQ_ELEMENT_EMAIL]); puts(start); + strcpy(ac->active_url, ac->urls[JAD_NEW_ACCOUNT_URL]); pkt_add_hdrs: - if (lws_gencrypto_jwe_alg_to_definition("RSA1_5", &jwe.jose.alg)) { + if (lws_gencrypto_jwe_alg_to_definition("RSA1_5", + &jwe.jose.alg)) { ac->len = 0; lwsl_notice("%s: no RSA1_5\n", __func__); goto failed; } - jwe.jws.jwk = &vhd->jwk; - ac->len = lws_jwe_create_packet(&jwe, - start, p - start, - ac->replay_nonce, - &ac->buf[LWS_PRE], - sizeof(ac->buf) - - LWS_PRE, - lws_get_context(wsi)); + jwe.jwk = vhd->jwk; + + ac->len = jws_create_packet(&jwe, + start, p - start, + ac->replay_nonce, + ac->active_url, + ac->kid, + &ac->buf[LWS_PRE], + sizeof(ac->buf) - LWS_PRE, + lws_get_context(wsi)); if (ac->len < 0) { ac->len = 0; - lwsl_notice("lws_jwe_create_packet failed\n"); + lwsl_notice("jws_create_packet failed\n"); goto failed; } @@ -808,156 +1080,70 @@ pend = (*pp) + len; ac->pos = 0; - content_type = "application/jose+json"; - if (ac->state == ACME_STATE_POLLING_CSR) - content_type = "application/pkix-cert"; + content_type = "application/jose+json"; if (lws_add_http_header_by_token(wsi, - WSI_TOKEN_HTTP_CONTENT_TYPE, - (uint8_t *)content_type, 21, pp, pend)) { + WSI_TOKEN_HTTP_CONTENT_TYPE, + (uint8_t *)content_type, 21, pp, + pend)) { lwsl_notice("could not add content type\n"); goto failed; } n = sprintf(buf, "%d", ac->len); if (lws_add_http_header_by_token(wsi, - WSI_TOKEN_HTTP_CONTENT_LENGTH, - (uint8_t *)buf, n, pp, pend)) { + WSI_TOKEN_HTTP_CONTENT_LENGTH, + (uint8_t *)buf, n, pp, pend)) { lwsl_notice("could not add content length\n"); goto failed; } lws_client_http_body_pending(wsi, 1); lws_callback_on_writable(wsi); - lwsl_notice("prepare to send ACME_STATE_NEW_REG\n"); break; - case ACME_STATE_NEW_AUTH: + + case ACME_STATE_NEW_ORDER: p += lws_snprintf(p, end - p, "{" - "\"resource\":\"new-authz\"," - "\"identifier\":{" - "\"type\":\"http-01\"," - "\"value\":\"%s\"" - "}" - "}", vhd->pvop_active[LWS_TLS_REQ_ELEMENT_COMMON_NAME]); + "\"identifiers\":[{" + "\"type\":\"dns\"," + "\"value\":\"%s\"" + "}]" + "}", + vhd->pvop_active[LWS_TLS_REQ_ELEMENT_COMMON_NAME]); + + puts(start); + strcpy(ac->active_url, ac->urls[JAD_NEW_ORDER_URL]); goto pkt_add_hdrs; - case ACME_STATE_ACCEPT_CHALL: - /* - * Several of the challenges in this document makes use - * of a key authorization string. A key authorization - * expresses a domain holder's authorization for a - * specified key to satisfy a specified challenge, by - * concatenating the token for the challenge with a key - * fingerprint, separated by a "." character: - * - * key-authz = token || '.' || - * base64(JWK_Thumbprint(accountKey)) - * - * The "JWK_Thumbprint" step indicates the computation - * specified in [RFC7638], using the SHA-256 digest. As - * specified in the individual challenges below, the - * token for a challenge is a JSON string comprised - * entirely of characters in the base64 alphabet. - * The "||" operator indicates concatenation of strings. - * - * keyAuthorization (required, string): The key - * authorization for this challenge. This value MUST - * match the token from the challenge and the client's - * account key. - * - * draft acme-01 tls-sni-01: - * - * { - * "keyAuthorization": "evaGxfADs...62jcerQ", - * } (Signed as JWS) - * - * draft acme-07 tls-sni-02: - * - * POST /acme/authz/1234/1 - * Host: example.com - * Content-Type: application/jose+json - * - * { - * "protected": base64url({ - * "alg": "ES256", - * "kid": "https://example.com/acme/acct/1", - * "nonce": "JHb54aT_KTXBWQOzGYkt9A", - * "url": "https://example.com/acme/authz/1234/1" - * }), - * "payload": base64url({ - * "keyAuthorization": "evaGxfADs...62jcerQ" - * }), - * "signature": "Q1bURgJoEslbD1c5...3pYdSMLio57mQNN4" - * } - * - * On receiving a response, the server MUST verify that - * the key authorization in the response matches the - * "token" value in the challenge and the client's - * account key. If they do not match, then the server - * MUST return an HTTP error in response to the POST - * request in which the client sent the challenge. - */ + case ACME_STATE_AUTHZ: + puts(start); + strcpy(ac->active_url, ac->authz_url); + goto pkt_add_hdrs; - lws_jwk_rfc7638_fingerprint(&vhd->jwk, digest); + case ACME_STATE_START_CHALL: p = start; end = &buf[sizeof(buf) - 1]; - p += lws_snprintf(p, end - p, - "{\"resource\":\"challenge\"," - "\"type\":\"tls-sni-0%d\"," - "\"keyAuthorization\":\"%s.", - 1 + ac->is_sni_02, - ac->chall_token); - n = lws_jws_base64_enc(digest, 32, p, end - p); - if (n < 0) - goto failed; - p += n; - p += lws_snprintf(p, end - p, "\"}"); + p += lws_snprintf(p, end - p, "{}"); puts(start); + strcpy(ac->active_url, ac->challenge_uri); goto pkt_add_hdrs; case ACME_STATE_POLLING: - break; + strcpy(ac->active_url, ac->order_url); + goto pkt_add_hdrs; case ACME_STATE_POLLING_CSR: - /* - * "To obtain a certificate for the domain, the agent - * constructs a PKCS#10 Certificate Signing Request that - * asks the Let’s Encrypt CA to issue a certificate for - * example.com with a specified public key. As usual, - * the CSR includes a signature by the private key - * corresponding to the public key in the CSR. The agent - * also signs the whole CSR with the authorized - * key for example.com so that the Let’s Encrypt CA - * knows it’s authorized." - * - * IOW we must create a new RSA keypair which will be - * the cert public + private key, and put the public - * key in the CSR. The CSR, just for transport, is also - * signed with our JWK, showing that as the owner of the - * authorized JWK, the request should be allowed. - * - * The cert comes back with our public key in it showing - * that the owner of the matching private key (we - * created that keypair) is the owner of the cert. - * - * We feed the CSR the elements we want in the cert, - * like the CN etc, and it gives us the b64URL-encoded - * CSR and the PEM-encoded (public +)private key in - * memory buffers. - */ if (ac->goes_around) break; - p += lws_snprintf(p, end - p, - "{\"resource\":\"new-cert\"," - "\"csr\":\""); + p += lws_snprintf(p, end - p, "{\"csr\":\""); n = lws_tls_acme_sni_csr_create(vhd->context, - &vhd->pvop_active[0], - (uint8_t *)p, end - p, - &ac->alloc_privkey_pem, - &ac->len_privkey_pem); + &vhd->pvop_active[0], + (uint8_t *)p, end - p, + &ac->alloc_privkey_pem, + &ac->len_privkey_pem); if (n < 0) { lwsl_notice("CSR generation failed\n"); goto failed; @@ -965,7 +1151,13 @@ p += n; p += lws_snprintf(p, end - p, "\"}"); puts(start); + strcpy(ac->active_url, ac->finalize_url); + goto pkt_add_hdrs; + + case ACME_STATE_DOWNLOAD_CERT: + strcpy(ac->active_url, ac->cert_url); goto pkt_add_hdrs; + break; default: break; @@ -974,14 +1166,16 @@ case LWS_CALLBACK_CLIENT_HTTP_WRITEABLE: lwsl_notice("LWS_CALLBACK_CLIENT_HTTP_WRITEABLE\n"); + if (!ac) break; + if (ac->pos == ac->len) break; ac->buf[LWS_PRE + ac->len] = '\0'; if (lws_write(wsi, (uint8_t *)ac->buf + LWS_PRE, - ac->len, LWS_WRITE_HTTP_FINAL) < 0) + ac->len, LWS_WRITE_HTTP_FINAL) < 0) return -1; lwsl_notice("wrote %d\n", ac->len); ac->pos = ac->len; @@ -992,25 +1186,29 @@ case LWS_CALLBACK_RECEIVE_CLIENT_HTTP_READ: if (!ac) return -1; + switch (ac->state) { + case ACME_STATE_POLLING_CSR: case ACME_STATE_POLLING: - case ACME_STATE_ACCEPT_CHALL: - case ACME_STATE_NEW_AUTH: + case ACME_STATE_START_CHALL: + case ACME_STATE_AUTHZ: + case ACME_STATE_NEW_ORDER: case ACME_STATE_DIRECTORY: ((char *)in)[len] = '\0'; puts(in); - m = (int)(signed char)lejp_parse(&ac->jctx, - (uint8_t *)in, len); + m = lejp_parse(&ac->jctx, (uint8_t *)in, len); if (m < 0 && m != LEJP_CONTINUE) { lwsl_notice("lejp parse failed %d\n", m); goto failed; } break; - case ACME_STATE_NEW_REG: + case ACME_STATE_NEW_ACCOUNT: ((char *)in)[len] = '\0'; puts(in); break; - case ACME_STATE_POLLING_CSR: + case ACME_STATE_DOWNLOAD_CERT: + ((char *)in)[len] = '\0'; + puts(in); /* it should be the DER cert! */ if (ac->cpos + len > sizeof(ac->buf)) { lwsl_notice("Incoming cert is too large!\n"); @@ -1027,13 +1225,19 @@ /* unchunked content */ case LWS_CALLBACK_RECEIVE_CLIENT_HTTP: lwsl_notice("%s: LWS_CALLBACK_RECEIVE_CLIENT_HTTP\n", __func__); - { - char buffer[2048 + LWS_PRE]; - char *px = buffer + LWS_PRE; - int lenx = sizeof(buffer) - LWS_PRE; + if (!ac) + return -1; + switch (ac->state) { + default: + { + char buffer[2048 + LWS_PRE]; + char *px = buffer + LWS_PRE; + int lenx = sizeof(buffer) - LWS_PRE; - if (lws_http_client_read(wsi, &px, &lenx) < 0) - return -1; + if (lws_http_client_read(wsi, &px, &lenx) < 0) + return -1; + } + break; } break; @@ -1042,6 +1246,7 @@ if (!ac) return -1; + switch (ac->state) { case ACME_STATE_DIRECTORY: lejp_destruct(&ac->jctx); @@ -1051,212 +1256,125 @@ for (n = 0; n < 6; n++) lwsl_notice(" %d: %s\n", n, ac->urls[n]); - /* - * So... having the directory now... we try to - * register our keys next. It's OK if it ends up - * they're already registered... this eliminates any - * gaps where we stored the key but registration did - * not complete for some reason... - */ - ac->state = ACME_STATE_NEW_REG; - lws_acme_report_status(vhd->vhost, LWS_CUS_REG, NULL); + ac->state = ACME_STATE_NEW_NONCE; - strcpy(buf, ac->urls[JAD_NEW_REG_URL]); + strcpy(buf, ac->urls[JAD_NEW_NONCE_URL]); cwsi = lws_acme_client_connect(vhd->context, vhd->vhost, - &ac->cwsi, &ac->i, buf, - "POST"); + &ac->cwsi, &ac->i, buf, + "GET"); if (!cwsi) { lwsl_notice("%s: failed to connect to acme\n", - __func__); + __func__); goto failed; } return -1; /* close the completed client connection */ - case ACME_STATE_NEW_REG: + case ACME_STATE_NEW_ACCOUNT: if ((ac->resp >= 200 && ac->resp < 299) || - ac->resp == 409) { + ac->resp == 409) { /* * Our account already existed, or exists now. * - * Move on to requesting a cert auth. */ - ac->state = ACME_STATE_NEW_AUTH; - lws_acme_report_status(vhd->vhost, LWS_CUS_AUTH, - NULL); + ac->state = ACME_STATE_NEW_ORDER; - strcpy(buf, ac->urls[JAD_NEW_AUTHZ_URL]); + strcpy(buf, ac->urls[JAD_NEW_ORDER_URL]); cwsi = lws_acme_client_connect(vhd->context, - vhd->vhost, &ac->cwsi, - &ac->i, buf, "POST"); + vhd->vhost, &ac->cwsi, + &ac->i, buf, "POST"); if (!cwsi) lwsl_notice("%s: failed to connect\n", - __func__); - return -1; /* close the completed client connection */ + __func__); + + /* close the completed client connection */ + return -1; } else { - lwsl_notice("new-reg replied %d\n", ac->resp); + lwsl_notice("newAccount replied %d\n", + ac->resp); goto failed; } return -1; /* close the completed client connection */ - case ACME_STATE_NEW_AUTH: + case ACME_STATE_NEW_ORDER: + lejp_destruct(&ac->jctx); + if (!ac->authz_url[0]) { + lwsl_notice("no authz\n"); + goto failed; + } + + /* + * Move on to requesting a cert auth. + */ + ac->state = ACME_STATE_AUTHZ; + lws_acme_report_status(vhd->vhost, LWS_CUS_AUTH, + NULL); + + strcpy(buf, ac->authz_url); + cwsi = lws_acme_client_connect(vhd->context, + vhd->vhost, &ac->cwsi, + &ac->i, buf, "POST"); + if (!cwsi) + lwsl_notice("%s: failed to connect\n", + __func__); + + return -1; /* close the completed client connection */ + + case ACME_STATE_AUTHZ: lejp_destruct(&ac->jctx); if (ac->resp / 100 == 4) { lws_snprintf(buf, sizeof(buf), - "Auth failed: %s", ac->detail); + "Auth failed: %s", ac->detail); failreason = buf; lwsl_notice("auth failed\n"); goto failed; } - lwsl_notice("chall: %s (%d)\n", ac->chall_token, ac->resp); + lwsl_notice("chall: %s (%d)\n", ac->chall_token, + ac->resp); if (!ac->chall_token[0]) { lwsl_notice("no challenge\n"); goto failed; } - - ac->state = ACME_STATE_ACCEPT_CHALL; + ac->state = ACME_STATE_START_CHALL; lws_acme_report_status(vhd->vhost, LWS_CUS_CHALLENGE, - NULL); - - /* tls-sni-01 ... what a mess. - * The stuff in - * https://tools.ietf.org/html/ - * draft-ietf-acme-acme-01#section-7.3 - * "requires" n but it's missing from let's encrypt - * tls-sni-01 challenge. The go docs say that they just - * implement one hashing round regardless - * https://godoc.org/golang.org/x/crypto/acme - * - * The go way is what is actually implemented today by - * letsencrypt - * - * "A client responds to this challenge by constructing - * a key authorization from the "token" value provided - * in the challenge and the client's account key. The - * client first computes the SHA-256 digest Z0 of the - * UTF8-encoded key authorization, and encodes Z0 in - * UTF-8 lower-case hexadecimal form." - */ - - /* tls-sni-02 - * - * SAN A MUST be constructed as follows: compute the - * SHA-256 digest of the UTF-8-encoded challenge token - * and encode it in lowercase hexadecimal form. The - * dNSName is "x.y.token.acme.invalid", where x - * is the first half of the hexadecimal representation - * and y is the second half. - */ + NULL); memset(&ac->ci, 0, sizeof(ac->ci)); - /* first compute the key authorization */ + /* compute the key authorization */ - lws_jwk_rfc7638_fingerprint(&vhd->jwk, digest); - p = start; - end = &buf[sizeof(buf) - 1]; + p = ac->key_auth; + end = p + sizeof(ac->key_auth) - 1; p += lws_snprintf(p, end - p, "%s.", ac->chall_token); + lws_jwk_rfc7638_fingerprint(&vhd->jwk, digest); n = lws_jws_base64_enc(digest, 32, p, end - p); if (n < 0) goto failed; - p += n; - - if (lws_genhash_init(&hctx, LWS_GENHASH_TYPE_SHA256)) - return -1; - - if (lws_genhash_update(&hctx, (uint8_t *)start, - lws_ptr_diff(p, start))) { - lws_genhash_destroy(&hctx, NULL); - - return -1; - } - if (lws_genhash_destroy(&hctx, digest)) - return -1; - p = buf; - for (n = 0; n < 32; n++) { - p += lws_snprintf(p, end - p, "%02x", - digest[n] & 0xff); - if (n == (32 / 2) - 1) - p = buf + 64; - } - - p = ac->san_a; - if (ac->is_sni_02) { - lws_snprintf(p, sizeof(ac->san_a), - "%s.%s.token.acme.invalid", - buf, buf + 64); + lwsl_notice("key_auth: '%s'\n", ac->key_auth); - /* - * SAN B MUST be constructed as follows: compute - * the SHA-256 digest of the UTF-8 encoded key - * authorization and encode it in lowercase - * hexadecimal form. The dNSName is - * "x.y.ka.acme.invalid" where x is the first - * half of the hexadecimal representation and y - * is the second half. - */ - lws_jwk_rfc7638_fingerprint(&vhd->jwk, - (char *)digest); + lws_snprintf(ac->http01_mountpoint, + sizeof(ac->http01_mountpoint), + "/.well-known/acme-challenge/%s", + ac->chall_token); + + memset(&ac->mount, 0, sizeof (struct lws_http_mount)); + ac->mount.protocol = "http"; + ac->mount.mountpoint = ac->http01_mountpoint; + ac->mount.mountpoint_len = + strlen(ac->http01_mountpoint); + ac->mount.origin_protocol = LWSMPRO_CALLBACK; - p = buf; - for (n = 0; n < 32; n++) { - p += lws_snprintf(p, end - p, "%02x", - digest[n] & 0xff); - if (n == (32 / 2) - 1) - p = buf + 64; - } - - p = ac->san_b; - lws_snprintf(p, sizeof(ac->san_b), - "%s.%s.ka.acme.invalid", - buf, buf + 64); - } else { - lws_snprintf(p, sizeof(ac->san_a), - "%s.%s.acme.invalid", buf, buf + 64); - ac->san_b[0] = '\0'; - } - - lwsl_notice("san_a: '%s'\n", ac->san_a); - lwsl_notice("san_b: '%s'\n", ac->san_b); - - /* - * tls-sni-01: - * - * The client then configures the TLS server at the - * domain such that when a handshake is initiated with - * the Server Name Indication extension set to - * "..acme.invalid", the - * corresponding generated certificate is presented. - * - * tls-sni-02: - * - * The client MUST ensure that the certificate is - * served to TLS connections specifying a Server Name - * Indication (SNI) value of SAN A. - */ - ac->ci.vhost_name = ac->san_a; - - /* - * we bind to exact iface of real vhost, so we can - * share the listen socket by SNI - */ - ac->ci.iface = ac->real_vh_iface; + ac->ci.mounts = &ac->mount; /* listen on the same port as the vhost that triggered * us */ - ac->ci.port = ac->real_vh_port; - /* Skip filling in any x509 info into the ssl_ctx. - * It will be done at the callback - * LWS_CALLBACK_OPENSSL_LOAD_EXTRA_SERVER_VERIFY_CERTS - * in this callback handler (below) - */ - ac->ci.options = LWS_SERVER_OPTION_CREATE_VHOST_SSL_CTX | - LWS_SERVER_OPTION_SKIP_PROTOCOL_INIT | - LWS_SERVER_OPTION_DO_SSL_GLOBAL_INIT; + ac->ci.port = 80; + /* make ourselves protocols[0] for the new vhost */ - ac->ci.protocols = acme_protocols; + ac->ci.protocols = chall_http01_protocols; + /* * vhost .user points to the ac associated with the * temporary vhost @@ -1264,75 +1382,72 @@ ac->ci.user = ac; ac->vhost = lws_create_vhost(lws_get_context(wsi), - &ac->ci); + &ac->ci); if (!ac->vhost) goto failed; + lwsl_notice("challenge_uri %s\n", ac->challenge_uri); + /* * The challenge-specific vhost is up... let the ACME * server know we are ready to roll... */ - ac->goes_around = 0; cwsi = lws_acme_client_connect(vhd->context, vhd->vhost, &ac->cwsi, &ac->i, ac->challenge_uri, "POST"); if (!cwsi) { - lwsl_notice("%s: failed to connect\n", - __func__); + lwsl_notice("%s: connect failed\n", __func__); goto failed; } return -1; /* close the completed client connection */ - case ACME_STATE_ACCEPT_CHALL: - /* - * he returned something like this (which we parsed) - * - * { - * "type": "tls-sni-01", - * "status": "pending", - * "uri": "https://acme-staging.api.letsencrypt.org/ - * acme/challenge/xCt7bT3FaxoIQU3Qry87t5h - * uKDcC-L-0ERcD5DLAZts/71100507", - * "token": "j2Vs-vLI_dsza4A35SFHIU03aIe2PzFRijbqCY - * dIVeE", - * "keyAuthorization": "j2Vs-vLI_dsza4A35SFHIU03aIe2 - * PzFRijbqCYdIVeE.nmOtdFd8Jikn6K8NnYYmT5 - * vCM_PwSDT8nLdOYoFXhRU" - * } - * - */ - lwsl_notice("%s: COMPLETED accept chall: %s\n", - __func__, ac->challenge_uri); + case ACME_STATE_START_CHALL: + lwsl_notice("%s: COMPLETED start chall: %s\n", + __func__, ac->challenge_uri); poll_again: ac->state = ACME_STATE_POLLING; - lws_acme_report_status(vhd->vhost, LWS_CUS_CHALLENGE, NULL); + lws_acme_report_status(vhd->vhost, LWS_CUS_CHALLENGE, + NULL); if (ac->goes_around++ == 20) { lwsl_notice("%s: too many chall retries\n", - __func__); + __func__); goto failed; } - lws_timed_callback_vh_protocol(vhd->vhost, vhd->protocol, - LWS_CALLBACK_USER + 0xac33, ac->goes_around == 1 ? 10 : 2); + strcpy(buf, ac->order_url); + cwsi = lws_acme_client_connect(vhd->context, vhd->vhost, + &ac->cwsi, &ac->i, buf, + "POST"); + if (!cwsi) { + lwsl_notice("%s: failed to connect to acme\n", + __func__); + + goto failed; + } return -1; /* close the completed client connection */ case ACME_STATE_POLLING: - if (ac->resp == 202 && - strcmp(ac->status, "invalid") && - strcmp(ac->status, "valid")) { + if (ac->resp == 202 && strcmp(ac->status, "invalid") && + strcmp(ac->status, "valid")) { + lwsl_notice("status: %s\n", ac->status); + goto poll_again; + } + + if (!strcmp(ac->status, "pending")) { lwsl_notice("status: %s\n", ac->status); goto poll_again; } if (!strcmp(ac->status, "invalid")) { - lwsl_notice("%s: polling failed\n", __func__); + lwsl_notice("%s: Challenge failed\n", __func__); lws_snprintf(buf, sizeof(buf), - "Challenge Invalid: %s", ac->detail); + "Challenge Invalid: %s", + ac->detail); failreason = buf; goto failed; } @@ -1341,7 +1456,7 @@ /* * The challenge was validated... so delete the - * temp SNI vhost now its job is done + * temp vhost now its job is done */ if (ac->vhost) lws_vhost_destroy(ac->vhost); @@ -1357,224 +1472,141 @@ lws_acme_report_status(vhd->vhost, LWS_CUS_REQ, NULL); ac->goes_around = 0; - strcpy(buf, ac->urls[JAD_NEW_CERT_URL]); + strcpy(buf, ac->finalize_url); cwsi = lws_acme_client_connect(vhd->context, vhd->vhost, &ac->cwsi, &ac->i, buf, "POST"); if (!cwsi) { lwsl_notice("%s: failed to connect to acme\n", - __func__); + __func__); goto failed; } return -1; /* close the completed client connection */ case ACME_STATE_POLLING_CSR: - /* - * (after POSTing the CSR)... - * - * If the CA decides to issue a certificate, then the - * server creates a new certificate resource and - * returns a URI for it in the Location header field - * of a 201 (Created) response. - * - * HTTP/1.1 201 Created - * Location: https://example.com/acme/cert/asdf - * - * If the certificate is available at the time of the - * response, it is provided in the body of the response. - * If the CA has not yet issued the certificate, the - * body of this response will be empty. The client - * should then send a GET request to the certificate URI - * to poll for the certificate. As long as the - * certificate is unavailable, the server MUST provide a - * 202 (Accepted) response and include a Retry-After - * header to indicate when the server believes the - * certificate will be issued. - */ if (ac->resp < 200 || ac->resp > 202) { lwsl_notice("CSR poll failed on resp %d\n", - ac->resp); + ac->resp); goto failed; } - if (ac->resp == 200) { - char *pp; - int max; - - lwsl_notice("The cert was sent..\n"); - - lws_acme_report_status(vhd->vhost, - LWS_CUS_ISSUE, NULL); + if (ac->resp != 200) { + if (ac->goes_around++ == 30) { + lwsl_notice("%s: too many retries\n", + __func__); - /* - * That means we have the issued cert DER in - * ac->buf, length in ac->cpos; and the key in - * ac->alloc_privkey_pem, length in - * ac->len_privkey_pem. - * - * We write out a PEM copy of the cert, and a - * PEM copy of the private key, using the - * write-only fds we opened while we still - * had root. - * - * Estimate the size of the PEM version of the - * cert and allocate a temp buffer for it. - * - * This is a bit complicated because first we - * drop the b64url version into the buffer at - * +384, then we add the header at 0 and move - * lines of it back + '\n' to make PEM. - * - * This avoids the need for two fullsize - * allocations. - */ - - max = (ac->cpos * 4) / 3 + 16 + 384; - - start = p = malloc(max); - if (!p) - goto failed; - - n = lws_b64_encode_string(ac->buf, ac->cpos, - start + 384, max - 384); - if (n < 0) { - free(start); goto failed; } + strcpy(buf, ac->finalize_url); + cwsi = lws_acme_client_connect(vhd->context, + vhd->vhost, + &ac->cwsi, &ac->i, buf, + "POST"); + if (!cwsi) { + lwsl_notice("%s: " + "failed to connect to acme\n", + __func__); - pp = start + 384; - p += lws_snprintf(start, 64, "%s", - "-----BEGIN CERTIFICATE-----\n"); - - while (n) { - m = 65; - if (n < m) - m = n; - memcpy(p, pp, m); - n -= m; - p += m; - pp += m; - if (n) - *p++ = '\n'; - } - p += lws_snprintf(p, - max - lws_ptr_diff(p, start), - "%s", - "\n-----END CERTIFICATE-----\n"); - - n = lws_plat_write_cert(vhd->vhost, 0, - vhd->fd_updated_cert, start, - lws_ptr_diff(p, start)); - free(start); - if (n) { - lwsl_err("unable to write ACME cert! %d\n", n); goto failed; } - /* - * don't close it... we may update the certs - * again - */ + /* close the completed client connection */ + return -1; + } - if (lws_plat_write_cert(vhd->vhost, 1, - vhd->fd_updated_key, - ac->alloc_privkey_pem, - ac->len_privkey_pem)) { - lwsl_err("unable to write ACME key!\n"); - goto failed; - } + ac->state = ACME_STATE_DOWNLOAD_CERT; - /* - * we have written the persistent copies - */ + strcpy(buf, ac->cert_url); + cwsi = lws_acme_client_connect(vhd->context, vhd->vhost, + &ac->cwsi, &ac->i, buf, + "POST"); + if (!cwsi) { + lwsl_notice("%s: failed to connect to acme\n", + __func__); - lwsl_notice("%s: Updated certs written for %s " - "to %s.upd and %s.upd\n", __func__, - vhd->pvop_active[LWS_TLS_REQ_ELEMENT_COMMON_NAME], - vhd->pvop_active[LWS_TLS_SET_CERT_PATH], - vhd->pvop_active[LWS_TLS_SET_KEY_PATH]); + goto failed; + } + return -1; - /* notify lws there was a cert update */ + case ACME_STATE_DOWNLOAD_CERT: - if (lws_tls_cert_updated(vhd->context, - vhd->pvop_active[LWS_TLS_SET_CERT_PATH], - vhd->pvop_active[LWS_TLS_SET_KEY_PATH], - ac->buf, ac->cpos, - ac->alloc_privkey_pem, - ac->len_privkey_pem)) { - lwsl_notice("problem setting certs\n"); - } + if (ac->resp != 200) { + lwsl_notice("download cert failed on resp %d\n", + ac->resp); + goto failed; + } + lwsl_notice("The cert was sent..\n"); - lws_acme_finished(vhd); - lws_acme_report_status(vhd->vhost, - LWS_CUS_SUCCESS, NULL); + lws_acme_report_status(vhd->vhost, LWS_CUS_ISSUE, NULL); - return 0; + /* + * That means we have the issued cert in + * ac->buf, length in ac->cpos; and the key in + * ac->alloc_privkey_pem, length in + * ac->len_privkey_pem. + */ + n = lws_plat_write_cert(vhd->vhost, 0, + vhd->fd_updated_cert, + ac->buf, + ac->cpos); + if (n) { + lwsl_err("unable to write ACME cert! %d\n", n); + goto failed; } - lws_acme_report_status(vhd->vhost, LWS_CUS_CONFIRM, NULL); + /* + * don't close it... we may update the certs + * again + */ + if (lws_plat_write_cert(vhd->vhost, 1, + vhd->fd_updated_key, + ac->alloc_privkey_pem, + ac->len_privkey_pem)) { + lwsl_err("unable to write ACME key!\n"); + goto failed; + } - /* he is preparing the cert, go again with a GET */ + /* + * we have written the persistent copies + */ + lwsl_notice("%s: Updated certs written for %s " + "to %s.upd and %s.upd\n", __func__, + vhd->pvop_active[LWS_TLS_REQ_ELEMENT_COMMON_NAME], + vhd->pvop_active[LWS_TLS_SET_CERT_PATH], + vhd->pvop_active[LWS_TLS_SET_KEY_PATH]); - if (ac->goes_around++ == 30) { - lwsl_notice("%s: too many retries\n", - __func__); + /* notify lws there was a cert update */ - goto failed; + if (lws_tls_cert_updated(vhd->context, + vhd->pvop_active[LWS_TLS_SET_CERT_PATH], + vhd->pvop_active[LWS_TLS_SET_KEY_PATH], + ac->buf, ac->cpos, + ac->alloc_privkey_pem, + ac->len_privkey_pem)) { + lwsl_notice("problem setting certs\n"); } - strcpy(buf, ac->challenge_uri); - cwsi = lws_acme_client_connect(vhd->context, vhd->vhost, - &ac->cwsi, &ac->i, buf, - "GET"); - if (!cwsi) { - lwsl_notice("%s: failed to connect to acme\n", - __func__); + lws_acme_finished(vhd); + lws_acme_report_status(vhd->vhost, + LWS_CUS_SUCCESS, NULL); - goto failed; - } - return -1; /* close the completed client connection */ + return -1; default: break; } break; - case LWS_CALLBACK_USER + 0xac33: - if (!vhd) - break; - cwsi = lws_acme_client_connect(vhd->context, vhd->vhost, - &ac->cwsi, &ac->i, - ac->challenge_uri, - "GET"); - if (!cwsi) { - lwsl_notice("%s: failed to connect\n", __func__); - goto failed; - } + case LWS_CALLBACK_USER + 0xac33: + if (!vhd) break; - - case LWS_CALLBACK_OPENSSL_LOAD_EXTRA_SERVER_VERIFY_CERTS: - /* - * This goes to vhost->protocols[0], but for our temp certs - * vhost we created, we have arranged that to be our protocol, - * so the callback will come here. - * - * When we created the temp vhost, we set its pvo to point - * to the ac associated with the temp vhost. - */ - lwsl_debug("LWS_CALLBACK_OPENSSL_LOAD_EXTRA_SERVER_VERIFY_CERTS\n"); - ac = (struct acme_connection *)lws_get_vhost_user( - (struct lws_vhost *)in); - - lws_acme_report_status((struct lws_vhost *)in, - LWS_CUS_CREATE_REQ, - "creating challenge cert"); - - if (lws_tls_acme_sni_cert_create((struct lws_vhost *)in, - ac->san_a, ac->san_b)) { - lwsl_err("%s: creating the sni test cert failed\n", __func__); - - return -1; + cwsi = lws_acme_client_connect(vhd->context, vhd->vhost, + &ac->cwsi, &ac->i, + ac->challenge_uri, + "GET"); + if (!cwsi) { + lwsl_notice("%s: failed to connect\n", __func__); + goto failed; } break; @@ -1585,7 +1617,7 @@ return 0; failed: - lwsl_err("%s: failed out\n", __func__); + lwsl_notice("%s: failed out\n", __func__); lws_acme_report_status(vhd->vhost, LWS_CUS_FAILED, failreason); lws_acme_finished(vhd); @@ -1598,28 +1630,17 @@ LWS_PLUGIN_PROTOCOL_LWS_ACME_CLIENT }; -LWS_EXTERN LWS_VISIBLE int -init_protocol_lws_acme_client(struct lws_context *context, - struct lws_plugin_capability *c) -{ - if (c->api_magic != LWS_PLUGIN_API_MAGIC) { - lwsl_err("Plugin API %d, library API %d", LWS_PLUGIN_API_MAGIC, - c->api_magic); - return 1; - } - - c->protocols = protocols; - c->count_protocols = LWS_ARRAY_SIZE(protocols); - c->extensions = NULL; - c->count_extensions = 0; - - return 0; -} - -LWS_EXTERN LWS_VISIBLE int -destroy_protocol_lws_acme_client(struct lws_context *context) -{ - return 0; -} +LWS_VISIBLE const lws_plugin_protocol_t protocol_lws_acme_client = { + .hdr = { + "acme client", + "lws_protocol_plugin", + LWS_PLUGIN_API_MAGIC + }, + + .protocols = protocols, + .count_protocols = LWS_ARRAY_SIZE(protocols), + .extensions = NULL, + .count_extensions = 0, +}; #endif diff -Nru libwebsockets-3.2.1/plugins/CMakeLists.txt libwebsockets-4.1.6/plugins/CMakeLists.txt --- libwebsockets-3.2.1/plugins/CMakeLists.txt 1970-01-01 00:00:00.000000000 +0000 +++ libwebsockets-4.1.6/plugins/CMakeLists.txt 2020-12-01 17:40:26.000000000 +0000 @@ -0,0 +1,171 @@ +# +# libwebsockets - small server side websockets and web server implementation +# +# Copyright (C) 2010 - 2020 Andy Green +# +# Permission is hereby granted, free of charge, to any person obtaining a copy +# of this software and associated documentation files (the "Software"), to +# deal in the Software without restriction, including without limitation the +# rights to use, copy, modify, merge, publish, distribute, sublicense, and/or +# sell copies of the Software, and to permit persons to whom the Software is +# furnished to do so, subject to the following conditions: +# +# The above copyright notice and this permission notice shall be included in +# all copies or substantial portions of the Software. +# +# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING +# FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS +# IN THE SOFTWARE. +# + +include_directories(.) + +if (DEFINED LIB_LIST_AT_END) +link_libraries(${LIB_LIST_AT_END}) +endif() + +if (LWS_WITH_PLUGINS AND LWS_WITH_SHARED) + macro(create_plugin PLUGIN_NAME PLUGIN_INCLUDE MAIN_SRC S2 S3) + + set(PLUGIN_SRCS ${MAIN_SRC}) + + if ("${S2}" STREQUAL "") + else() + list(APPEND PLUGIN_SRCS ${S2}) + endif() + if ("${S3}" STREQUAL "") + else() + list(APPEND PLUGIN_SRCS ${S3}) + endif() + + if (WIN32) + list(APPEND PLUGIN_SRCS + ${WIN32_HELPERS_PATH}/getopt.c + ${WIN32_HELPERS_PATH}/getopt_long.c + ${WIN32_HELPERS_PATH}/gettimeofday.c + ) + + list(APPEND PLUGIN_HDR + ${WIN32_HELPERS_PATH}/getopt.h + ${WIN32_HELPERS_PATH}/gettimeofday.h + ) + endif(WIN32) + + source_group("Headers Private" FILES ${PLUGIN_HDR}) + source_group("Sources" FILES ${PLUGIN_SRCS}) + add_library(${PLUGIN_NAME} SHARED ${PLUGIN_SRCS} ${PLUGIN_HDR}) + + foreach(libpath ${LWS_DEP_LIB_PATHS}) + target_link_directories(${TEST_NAME} ${libpath}) + endforeach() + + target_link_libraries(${PLUGIN_NAME} websockets_shared) + add_dependencies(${PLUGIN_NAME} websockets_shared) + + target_include_directories(${PLUGIN_NAME} PRIVATE ${PLUGIN_INCLUDE} ${LWS_LIB_BUILD_INC_PATHS}) + + # Set test app specific defines. + set_property(TARGET ${PLUGIN_NAME} + PROPERTY COMPILE_DEFINITIONS + INSTALL_DATADIR="${CMAKE_INSTALL_PREFIX}/plugins" + ) + + set(CMAKE_POSITION_INDEPENDENT_CODE ON) + +# SET_TARGET_PROPERTIES(${PLUGIN_NAME} +# PROPERTIES COMPILE_FLAGS ${CMAKE_C_FLAGS}) + +# set_target_properties(${PLUGIN_NAME} +# PROPERTIES +# OUTPUT_NAME ${PLUGIN_NAME}) + + list(APPEND PLUGINS_LIST ${PLUGIN_NAME}) + + endmacro() + +if (LWS_ROLE_WS) + create_plugin(protocol_dumb_increment "" + "protocol_dumb_increment.c" "" "") + create_plugin(protocol_lws_mirror "" + "protocol_lws_mirror.c" "" "") + create_plugin(protocol_lws_status "" + "protocol_lws_status.c" "" "") + if (NOT WIN32) + create_plugin(protocol_lws_raw_test "" + "protocol_lws_raw_test.c" "" "") + + if (UNIX AND LWS_HAVE_PTHREAD_H) + create_plugin(protocol_deaddrop "" + "deaddrop/protocol_lws_deaddrop.c" "" "") + endif() + endif() + + if (LWS_WITH_SERVER_STATUS) + create_plugin(protocol_lws_server_status "" + "protocol_lws_server_status.c" "" "") + endif() + + if (NOT LWS_WITHOUT_CLIENT) + create_plugin(protocol_client_loopback_test "" + "protocol_client_loopback_test.c" "" "") + endif() + +endif(LWS_ROLE_WS) + + create_plugin(protocol_post_demo "" + "protocol_post_demo.c" "" "") + +if (LWS_ROLE_RAW_PROXY) + create_plugin(protocol_lws_raw_proxy "" + "raw-proxy/protocol_lws_raw_proxy.c" "" "") +endif() + +if (LWS_WITH_FTS) + create_plugin(protocol_fulltext_demo "" + "protocol_fulltext_demo.c" "" "") +endif() + + +if (LWS_WITH_SSL) + create_plugin(protocol_lws_ssh_base "ssh-base/include" + "ssh-base/sshd.c;ssh-base/telnet.c;ssh-base/kex-25519.c" "ssh-base/crypto/chacha.c;ssh-base/crypto/ed25519.c;ssh-base/crypto/fe25519.c;ssh-base/crypto/ge25519.c;ssh-base/crypto/poly1305.c;ssh-base/crypto/sc25519.c;ssh-base/crypto/smult_curve25519_ref.c" "") + create_plugin(protocol_lws_sshd_demo "ssh-base/include" "protocol_lws_sshd_demo.c" "" "") + + include_directories("${PROJECT_SOURCE_DIR}/plugins/ssh-base/include") +endif() + + + +if (LWS_WITH_ACME) + create_plugin(protocol_lws_acme_client "" + "acme-client/protocol_lws_acme_client.c" "" "") +endif() + +endif(LWS_WITH_PLUGINS AND LWS_WITH_SHARED) + + +# plugins + +if (LWS_WITH_PLUGINS) + install(TARGETS ${PLUGINS_LIST} + PERMISSIONS OWNER_WRITE OWNER_EXECUTE GROUP_EXECUTE WORLD_EXECUTE OWNER_READ GROUP_READ WORLD_READ + DESTINATION share/libwebsockets-test-server/plugins + COMPONENT plugins) + + if (NOT WIN32) + install(FILES deaddrop/assets/index.html;deaddrop/assets/deaddrop.js;deaddrop/assets/deaddrop.css;deaddrop/assets/drop.svg + DESTINATION share/libwebsockets-test-server/deaddrop + COMPONENT plugins) + endif() + + +if (LWS_WITH_SERVER_STATUS) + install(FILES server-status.html;server-status.js;server-status.css;lwsws-logo.png + DESTINATION share/libwebsockets-test-server/server-status + COMPONENT examples) +endif() +endif() diff -Nru libwebsockets-3.2.1/plugins/deaddrop/assets/deaddrop.js libwebsockets-4.1.6/plugins/deaddrop/assets/deaddrop.js --- libwebsockets-3.2.1/plugins/deaddrop/assets/deaddrop.js 2019-12-18 14:45:31.000000000 +0000 +++ libwebsockets-4.1.6/plugins/deaddrop/assets/deaddrop.js 2020-12-01 17:40:26.000000000 +0000 @@ -74,7 +74,7 @@ } function clear_errors() { - var t = document.getElementById("ongoing"); + var n, t = document.getElementById("ongoing"); for (n = 0; n < t.rows.length; n++) if (t.rows[n].cells[0].classList.contains("err")) @@ -154,8 +154,7 @@ } function upl_button(e) { - var fi = document.getElementById("file"), - da = document.getElementById("da"); + var fi = document.getElementById("file"); clear_errors(); e.preventDefault(); @@ -211,9 +210,6 @@ function new_ws(urlpath, protocol) { - if (typeof MozWebSocket != "undefined") - return new MozWebSocket(urlpath, protocol); - return new WebSocket(urlpath, protocol); } diff -Nru libwebsockets-3.2.1/plugins/deaddrop/protocol_lws_deaddrop.c libwebsockets-4.1.6/plugins/deaddrop/protocol_lws_deaddrop.c --- libwebsockets-3.2.1/plugins/deaddrop/protocol_lws_deaddrop.c 2019-12-18 14:45:31.000000000 +0000 +++ libwebsockets-4.1.6/plugins/deaddrop/protocol_lws_deaddrop.c 2020-12-01 17:40:26.000000000 +0000 @@ -1,22 +1,25 @@ /* - * lws protocol handler plugin for "Dead Drop" + * libwebsockets - small server side websockets and web server implementation * - * Copyright (C) 2010 - 2018 Andy Green + * Copyright (C) 2010 - 2019 Andy Green * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation: - * version 2.1 of the License. + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to + * deal in the Software without restriction, including without limitation the + * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or + * sell copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: * - * This library is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. * - * You should have received a copy of the GNU Lesser General Public - * License along with this library; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, - * MA 02110-1301 USA + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS + * IN THE SOFTWARE. */ #if !defined (LWS_PLUGIN_STATIC) @@ -147,10 +150,14 @@ de = readdir(dir[sp]); if (!de) { closedir(dir[sp]); +#if !defined(__COVERITY__) if (!sp) +#endif break; +#if !defined(__COVERITY__) sp--; continue; +#endif } p = filepath; @@ -165,7 +172,11 @@ /* ignore temp files */ if (de->d_name[strlen(de->d_name) - 1] == '~') continue; - +#if defined(__COVERITY__) + s.st_size = 0; + s.st_mtime = 0; +#else + /* coverity[toctou] */ if (stat(filepath, &s)) continue; @@ -189,6 +200,7 @@ } continue; } +#endif m = strlen(filepath + initial) + 1; dire = lwsac_use(&lwsac_head, sizeof(*dire) + m, 0); @@ -202,8 +214,10 @@ dire->size = s.st_size; dire->mtime = s.st_mtime; dire->user[0] = '\0'; +#if !defined(__COVERITY__) if (sp) lws_strncpy(dire->user, subdir[1], sizeof(dire->user)); +#endif found++; @@ -292,7 +306,7 @@ if (pss->file_length > pss->vhd->max_size) { pss->response_code = HTTP_STATUS_REQ_ENTITY_TOO_LARGE; - close((int)(long long)pss->fd); + close((int)(lws_intptr_t)pss->fd); pss->fd = LWS_INVALID_FILE; unlink(pss->filename); @@ -300,7 +314,7 @@ } if (pss->fd != LWS_INVALID_FILE) { - n = write((int)(long long)pss->fd, buf, len); + n = write((int)(lws_intptr_t)pss->fd, buf, len); lwsl_debug("%s: write %d says %d\n", __func__, len, n); lws_set_timeout(pss->wsi, PENDING_TIMEOUT_HTTP_CONTENT, 30); @@ -310,7 +324,7 @@ break; if (pss->fd != LWS_INVALID_FILE) - close((int)(long long)pss->fd); + close((int)(lws_intptr_t)pss->fd); /* the temp filename without the ~ */ lws_strncpy(filename2, pss->filename, sizeof(filename2)); @@ -675,28 +689,17 @@ LWS_PLUGIN_PROTOCOL_DEADDROP }; -LWS_EXTERN LWS_VISIBLE int -init_protocol_deaddrop(struct lws_context *context, - struct lws_plugin_capability *c) -{ - if (c->api_magic != LWS_PLUGIN_API_MAGIC) { - lwsl_err("Plugin API %d, library API %d", LWS_PLUGIN_API_MAGIC, - c->api_magic); - return 1; - } - - c->protocols = protocols; - c->count_protocols = LWS_ARRAY_SIZE(protocols); - c->extensions = NULL; - c->count_extensions = 0; - - return 0; -} - -LWS_EXTERN LWS_VISIBLE int -destroy_protocol_deaddrop(struct lws_context *context) -{ - return 0; -} +LWS_VISIBLE const lws_plugin_protocol_t deaddrop = { + .hdr = { + "deaddrop", + "lws_protocol_plugin", + LWS_PLUGIN_API_MAGIC + }, + + .protocols = protocols, + .count_protocols = LWS_ARRAY_SIZE(protocols), + .extensions = NULL, + .count_extensions = 0, +}; #endif diff -Nru libwebsockets-3.2.1/plugins/generic-sessions/assets/admin-login.html libwebsockets-4.1.6/plugins/generic-sessions/assets/admin-login.html --- libwebsockets-3.2.1/plugins/generic-sessions/assets/admin-login.html 2019-12-18 14:45:31.000000000 +0000 +++ libwebsockets-4.1.6/plugins/generic-sessions/assets/admin-login.html 1970-01-01 00:00:00.000000000 +0000 @@ -1,5 +0,0 @@ - -This is an example destination that will appear after successful Admin login. - -This URL cannot be served if you're not logged in as admin. - diff -Nru libwebsockets-3.2.1/plugins/generic-sessions/assets/failed-login.html libwebsockets-4.1.6/plugins/generic-sessions/assets/failed-login.html --- libwebsockets-3.2.1/plugins/generic-sessions/assets/failed-login.html 2019-12-18 14:45:31.000000000 +0000 +++ libwebsockets-4.1.6/plugins/generic-sessions/assets/failed-login.html 1970-01-01 00:00:00.000000000 +0000 @@ -1,3 +0,0 @@ - -This is an example destination that will appear after a failed login - diff -Nru libwebsockets-3.2.1/plugins/generic-sessions/assets/index.html libwebsockets-4.1.6/plugins/generic-sessions/assets/index.html --- libwebsockets-3.2.1/plugins/generic-sessions/assets/index.html 2019-12-18 14:45:31.000000000 +0000 +++ libwebsockets-4.1.6/plugins/generic-sessions/assets/index.html 1970-01-01 00:00:00.000000000 +0000 @@ -1,56 +0,0 @@ - - - - - - - - - - - - - - - - -
-
-
- -
- - This is a demo application for lws generic-sessions.

- It's a simple messageboard.

- What's interesting about it is there is no serverside scripting,
- instead client js makes a wss:// connection back to the server
- and then reacts to JSON from the ws protocol. Sessions stuff is
- handled by lws generic sessions, making the actual
- test application
very small.

- And because it's natively websocket, it's naturally connected
- for dynamic events and easy to maintain. -

- Register / Login at the top right to see and create new messages. -
- -
-
- New message
-
- -
-
-
-
- -
- -
-
- - - - diff -Nru libwebsockets-3.2.1/plugins/generic-sessions/assets/lwsgs.css libwebsockets-4.1.6/plugins/generic-sessions/assets/lwsgs.css --- libwebsockets-3.2.1/plugins/generic-sessions/assets/lwsgs.css 2019-12-18 14:45:31.000000000 +0000 +++ libwebsockets-4.1.6/plugins/generic-sessions/assets/lwsgs.css 1970-01-01 00:00:00.000000000 +0000 @@ -1,134 +0,0 @@ -.body { font-size: 12px } -.gstitle { font-size: 18px } - -.group1 { - vertical-align:middle; - text-align:center; - background:#f0f0e0; - padding:12px; - border-radius:10px; -} -.group2 { - display:none; - vertical-align:middle; - font-size: 22px; - text-align:center; - margin:auto; - align:center; - background-color: rgba(255, 255, 255, 0.8); - padding:12px; - border-radius:10px; -} - -body.seats { - background-image:url(seats.jpg) -} - -div.lwsgs { - z-index: 3; - text-align:right; - background-color: rgba(255, 255, 255, 0.8); -} - -table.lwsgs { - width:100%; - height:100%; - transition: max-height 2s; -} -table.c100 { - text-align:center; - width:100%; -} - -table.r { - vertical-align:top; - text-align:right; -} - -table.l { - vertical-align:top; - text-align:left; -} - -table.fixed { - table-layout: fixed; -} - -td.logo { - vertical-align:top; - text-align:left; - width:200px -} - -td.lwsgs { - vertical-align:top; - float:right; -} - -td.h99 { - height:99%; - vertical-align:middle; -} - -td.c { - margin:auto; - align:center -} - -td.tac { - text-align:center -} - -td.ava { - display:inline-block; - vertical-align:top; - word-wrap:break-word; -} - -iframe.hidden { - display:none; -} - -div.hidden { - display:none; -} - -div.hiddenr { - display:none; - text-align:right; -} - -input { - margin: 2px; - padding: 2px; -} - -input.em { - margin: 4px; - font-weight:bold; -} - -input.wide { - margin: 6px; - padding: 6px; -} - -input.hidden { - display: none; -} - -form.r { - text-align:right; -} - -span.bad { - color: red; -} - -span.small { - font-size:8pt; -} - -.green { - color: green; -} diff -Nru libwebsockets-3.2.1/plugins/generic-sessions/assets/lwsgs.js libwebsockets-4.1.6/plugins/generic-sessions/assets/lwsgs.js --- libwebsockets-3.2.1/plugins/generic-sessions/assets/lwsgs.js 2019-12-18 14:45:31.000000000 +0000 +++ libwebsockets-4.1.6/plugins/generic-sessions/assets/lwsgs.js 1970-01-01 00:00:00.000000000 +0000 @@ -1,631 +0,0 @@ - - -var lwsgs_user = "$lwsgs_user"; -var lwsgs_auth = "$lwsgs_auth"; -var lwsgs_email = "$lwsgs_email"; - -var lwsgs_html = '\ -

\ -\ -
\ -
\ - \ - \ - \ - \ -
\ - \ -
\ - \ -
\ -
\ -\ - \ - \ - \ - \ - \ -'; - -/*-- this came from - -- https://raw.githubusercontent.com/blueimp/JavaScript-MD5/master/js/md5.min.js - -- under MIT license */ -!function(n){"use strict";function t(n,t){var r=(65535&n)+(65535&t),e=(n>>16)+(t>>16)+(r>>16);return e<<16|65535&r}function r(n,t){return n<>>32-t}function e(n,e,o,u,c,f){return t(r(t(t(e,n),t(u,f)),c),o)}function o(n,t,r,o,u,c,f){return e(t&r|~t&o,n,t,u,c,f)}function u(n,t,r,o,u,c,f){return e(t&o|r&~o,n,t,u,c,f)}function c(n,t,r,o,u,c,f){return e(t^r^o,n,t,u,c,f)}function f(n,t,r,o,u,c,f){return e(r^(t|~o),n,t,u,c,f)}function i(n,r){n[r>>5]|=128<>>9<<4)+14]=r;var e,i,a,h,d,l=1732584193,g=-271733879,v=-1732584194,m=271733878;for(e=0;e>5]>>>t%32&255);return r}function h(n){var t,r=[];for(r[(n.length>>2)-1]=void 0,t=0;t>5]|=(255&n.charCodeAt(t/8))<16&&(o=i(o,8*n.length)),r=0;16>r;r+=1)u[r]=909522486^o[r],c[r]=1549556828^o[r];return e=i(u.concat(h(t)),512+8*t.length),a(i(c.concat(e),640))}function g(n){var t,r,e="0123456789abcdef",o="";for(r=0;r>>4&15)+e.charAt(15&t);return o}function v(n){return unescape(encodeURIComponent(n))}function m(n){return d(v(n))}function p(n){return g(m(n))}function s(n,t){return l(v(n),v(t))}function C(n,t){return g(s(n,t))}function A(n,t,r){return t?r?s(t,n):C(t,n):r?m(n):p(n)}"function"==typeof define&&define.amd?define(function(){return A}):"object"==typeof module&&module.exports?module.exports=A:n.md5=A}(this); - -if (lwsgs_user.substring(0, 1) == "$") { - alert("lwsgs.js: lws generic sessions misconfigured and not providing vars"); -} -function lwsgs_san(s) -{ - if (s.search("<") != -1) - return "invalid string"; - - return s; -} - -function lwsgs_update() -{ - var en_login = 1, en_forgot = 1; - - if (document.getElementById('password').value.length && - document.getElementById('password').value.length < 8) - en_login = 0; - - if (!document.getElementById('username').value || - !document.getElementById('password').value) - en_login = 0; - - if (!document.getElementById('username').value || - document.getElementById('password').value) - en_forgot = 0; - - document.getElementById('login').disabled = !en_login; - document.getElementById('forgot').disabled = !en_forgot; - - if (lwsgs_user) - document.getElementById("curuser").innerHTML = lwsgs_san(lwsgs_user); - - if (lwsgs_user === "") - document.getElementById("dlogin").style.display = "inline"; - else - document.getElementById("dlogout").style.display = "inline"; - } - -function lwsgs_open_registration() -{ - document.getElementById("dadmin").style.display = "none"; - document.getElementById("dlogin").style.display = "none"; - document.getElementById("dlogout").style.display = "none"; - document.getElementById("dchange").style.display = "none"; - document.getElementById("dregister").style.display = "inline"; -} - -function lwsgs_cancel_registration() -{ - document.getElementById("dadmin").style.display = "none"; - document.getElementById("dregister").style.display = "none"; - document.getElementById("dchange").style.display = "none"; - - if (lwsgs_user === "") - document.getElementById("dlogin").style.display = "inline"; - else - document.getElementById("dlogout").style.display = "inline"; -} - -function lwsgs_select_change() -{ - document.getElementById("dlogin").style.display = "none"; - document.getElementById("dlogout").style.display = "none"; - document.getElementById("dregister").style.display = "none"; - if (lwsgs_auth & 2) { - document.getElementById("dadmin").style.display = "inline"; - document.getElementById("dchange").style.display = "none"; - } else { - document.getElementById("dadmin").style.display = "none"; - document.getElementById("dchange").style.display = "inline"; - } - - event.preventDefault() -} - -var lwsgs_user_check = '0'; -var lwsgs_email_check = '0'; - -function lwsgs_rupdate() -{ - var en_register = 1, en_forgot = 0; - - if (document.getElementById('rpassword').value == - document.getElementById('password2').value) { - if (document.getElementById('rpassword').value.length) - document.getElementById('match').innerHTML = - "\u2713"; - else - document.getElementById('match').innerHTML = ""; - document.getElementById('pw2').style = ""; - } else { - if (document.getElementById('password2').value || - document.getElementById('email').value) { // ie, he is filling in "register" path and cares - document.getElementById('match').innerHTML = - "\u2718 Passwords do not match"; - } else - document.getElementById('match').innerHTML = - "\u2718 Passwords do not match"; - - en_register = 0; - } - - if (document.getElementById('rpassword').value.length && - document.getElementById('rpassword').value.length < 8) { - en_register = 0; - document.getElementById('rpw1').innerHTML = "Need 8 chars"; - } else - if (document.getElementById('rpassword').value.length) - document.getElementById('rpw1').innerHTML = "\u2713"; - else - document.getElementById('rpw1').innerHTML = ""; - - if (!document.getElementById('rpassword').value || - !document.getElementById('password2').value || - !document.getElementById('rusername').value || - !document.getElementById('email').value || - lwsgs_email_check === '1'|| - lwsgs_user_check === '1') - en_register = 0; - - document.getElementById('register').disabled = !en_register; - document.getElementById('rpassword').disabled = lwsgs_user_check === '1'; - document.getElementById('password2').disabled = lwsgs_user_check === '1'; - document.getElementById('email').disabled = lwsgs_user_check === '1'; - - if (lwsgs_user_check === '0') { - var uc = document.getElementById('uchk'); - - if (uc) { - if (document.getElementById('rusername').value) - uc.innerHTML = "\u2713"; - else - uc.innerHTML = ""; - } - } else { - if (document.getElementById('uchk')) - ocument.getElementById('uchk').innerHTML = "\u2718 Already registered"; - en_forgot = 1; - } - - if (lwsgs_email_check === '0') { - var ec = document.getElementById('echk'); - - if (ec) { - if (document.getElementById('email').value) - ec.innerHTML = "\u2713"; - else - ec.innerHTML = ""; - } - } else { - if (document.getElementById('echk')) - document.getElementById('echk').innerHTML = "\u2718 Already registered"; - en_forgot = 1; - } - - if (en_forgot) - document.getElementById('rforgot').style.display = "inline"; - else - document.getElementById('rforgot').style.display = "none"; - - if (lwsgs_user_check === '1') - op = '0.5'; - else - op = '1.0'; - document.getElementById('rpassword').style.opacity = op; - document.getElementById('password2').style.opacity = op; - document.getElementById('email').style.opacity = op; - } - -function lwsgs_cupdate() -{ - var en_change = 1, en_forgot = 1, pwok = 1; - - if (lwsgs_auth & 8) { - document.getElementById('ccurpw').style.display = "none"; - document.getElementById('ccurpw_name').style.display = "none"; - } else { - if (!document.getElementById('ccurpw').value || - document.getElementById('ccurpw').value.length < 8) { - en_change = 0; - pwok = 0; - document.getElementById('cuchk').innerHTML = "\u2718"; - } else { - en_forgot = 0; - document.getElementById('cuchk').innerHTML = ""; - } - document.getElementById('ccurpw').style.display = "inline"; - document.getElementById('ccurpw_name').style.display = "inline"; - } - - if (document.getElementById('cpassword').value == - document.getElementById('cpassword2').value) { - if (document.getElementById('cpassword').value.length) - document.getElementById('cmatch').innerHTML = "\u2713"; - else - document.getElementById('cmatch').innerHTML = ""; - document.getElementById('pw2').style = ""; - } else { - if (document.getElementById('cpassword2').value //|| - //document.getElementById('cemail').value - ) { // ie, he is filling in "register" path and cares - document.getElementById('cmatch').innerHTML = - "\u2718 Passwords do not match"; - } else - document.getElementById('cmatch').innerHTML = "\u2718 Passwords do not match"; - - en_change = 0; - } - - if (document.getElementById('cpassword').value.length && - document.getElementById('cpassword').value.length < 8) { - en_change = 0; - document.getElementById('cpw1').innerHTML = "Need 8 chars"; - } else { - var cpw = document.getElementById('cpw1'); - - if (cpw) { - if (document.getElementById('cpassword').value.length) - cpw.innerHTML = "\u2713"; - else - cpw.innerHTML = ""; - } - } - - if (!document.getElementById('cpassword').value || - !document.getElementById('cpassword2').value || - pwok === 0) - en_change = 0; - - if (document.getElementById('showdel').checked) - document.getElementById('delete').style.display = "inline"; - else - document.getElementById('delete').style.display = "none"; - - document.getElementById('change').disabled = !en_change; - document.getElementById('cpassword').disabled = pwok === 0; - document.getElementById('cpassword2').disabled = pwok === 0; - document.getElementById('showdel').disabled = pwok === 0; - document.getElementById('delete').disabled = pwok === 0; - //document.getElementById('cemail').disabled = pwok === 0; - - /* - if (lwsgs_auth & 8) { - document.getElementById('cemail').style.display = "none"; - document.getElementById('cemail_name').style.display = "none"; - } else { - document.getElementById('cemail').style.display = "inline"; - document.getElementById('cemail_name').style.display = "inline"; - if (lwsgs_email_check === '0' && - document.getElementById('cemail').value != lwsgs_email) { - if (document.getElementById('cemail').value) - document.getElementById('cechk').innerHTML = "\u2713"; - else - document.getElementById('cechk').innerHTML = ""; - } else { - document.getElementById('cechk').innerHTML = "\u2718 Already registered"; - en_forgot = 1; - } - } */ - - if (lwsgs_auth & 8) - en_forgot = 0; - - if (en_forgot) - document.getElementById('cforgot').style.display = "inline"; - else - document.getElementById('cforgot').style.display = "none"; - - if (pwok === 0) - op = '0.5'; - else - op = '1.0'; - document.getElementById('cpassword').style.opacity = op; - document.getElementById('cpassword2').style.opacity = op; - // document.getElementById('cemail').style.opacity = op; - } - -function lwsgs_check_user() -{ - var xmlHttp = new XMLHttpRequest(); - xmlHttp.onreadystatechange = function() { - if (xmlHttp.readyState === 4 && xmlHttp.status === 200) { - lwsgs_user_check = xmlHttp.responseText; - lwsgs_rupdate(); - } - } - xmlHttp.open("GET", "lwsgs-check?username="+document.getElementById('rusername').value, true); - xmlHttp.send(null); -} - -function lwsgs_check_email(id) -{ - var xmlHttp = new XMLHttpRequest(); - xmlHttp.onreadystatechange = function() { - if (xmlHttp.readyState === 4 && xmlHttp.status === 200) { - lwsgs_email_check = xmlHttp.responseText; - lwsgs_rupdate(); - } - } - xmlHttp.open("GET", "lwsgs-check?email="+document.getElementById(id).value, true); - xmlHttp.send(null); -} - -function rupdate_user() -{ - lwsgs_rupdate(); - lwsgs_check_user(); -} - -function rupdate_email() -{ - lwsgs_rupdate(); - lwsgs_check_email('email'); -} - -function cupdate_email() -{ - lwsgs_cupdate(); - lwsgs_check_email('cemail'); -} - - -function lwsgs_initial() -{ - document.getElementById('lwsgs').innerHTML = lwsgs_html; - - if (lwsgs_user) { - document.getElementById("curuser").innerHTML = - "currently logged in as " + lwsgs_san(lwsgs_user) + "
"; - - document.getElementById("ccuruser").innerHTML = - "Login settings for " + - lwsgs_san(lwsgs_user) + "
"; - } - - document.getElementById('username').oninput = lwsgs_update; - document.getElementById('username').onchange = lwsgs_update; - document.getElementById('password').oninput = lwsgs_update; - document.getElementById('password').onchange = lwsgs_update; - document.getElementById('doreg').onclick = lwsgs_open_registration; - document.getElementById('clink').onclick = lwsgs_select_change; - document.getElementById('cancel').onclick =lwsgs_cancel_registration; - document.getElementById('cancel2').onclick =lwsgs_cancel_registration; - document.getElementById('rpassword').oninput = lwsgs_rupdate; - document.getElementById('password2').oninput = lwsgs_rupdate; - document.getElementById('rusername').oninput = rupdate_user; - document.getElementById('email').oninput = rupdate_email; - document.getElementById('ccurpw').oninput = lwsgs_cupdate; - document.getElementById('cpassword').oninput = lwsgs_cupdate; - document.getElementById('cpassword2').oninput = lwsgs_cupdate; - - document.getElementById('showdel').onchange = lwsgs_cupdate; - - if (lwsgs_email) - document.getElementById('grav').innerHTML = - ""; - //if (lwsgs_email) - //document.getElementById('cemail').placeholder = lwsgs_email; - document.getElementById('cusername').value = lwsgs_user; - lwsgs_update(); - lwsgs_cupdate(); -} - -window.addEventListener("load", function() { - lwsgs_initial(); - document.getElementById("nolog").style.display = !!lwsgs_user ? "none" : "inline-block"; - document.getElementById("logged").style.display = !lwsgs_user ? "none" : "inline-block"; - - document.getElementById("msg").onkeyup = mupd; - document.getElementById("msg").onchange = mupd; - - var ws; - - function mb_format(s) - { - var r = "", n, wos = 0; - - for (n = 0; n < s.length; n++) { - if (s[n] == ' ') - wos = 0; - else { - wos++; - if (wos === 40) { - wos = 0; - r = r + ' '; - } - } - if (s[n] == '<') { - r = r + "<"; - continue; - } - if (s[n] == '\n') { - r = r + "
"; - continue; - } - - r = r + s[n]; - } - - return r; - } - - function add_div(n, m) - { - var q = document.getElementById(n); - var d = new Date(m.time * 1000); - - q.innerHTML = "
" + - "
" + - "" + lwsgs_san(m.username) + "
" + - "" + d.toDateString() + - "
" + d.toTimeString() + "

" + - "IP: " + lwsgs_san(m.ip) + - "
" + - mb_format(m.content) + - "

" + q.innerHTML; - } - - function get_appropriate_ws_url() - { - var pcol; - var u = document.URL; - - if (u.substring(0, 5) == "https") { - pcol = "wss://"; - u = u.substr(8); - } else { - pcol = "ws://"; - if (u.substring(0, 4) == "http") - u = u.substr(7); - } - u = u.split('/'); - - return pcol + u[0] + "/xxx"; - } - - if (lwsgs_user) { - if (typeof MozWebSocket != "undefined") - ws = new MozWebSocket(get_appropriate_ws_url(), - "protocol-lws-messageboard"); - else - ws = new WebSocket(get_appropriate_ws_url(), - "protocol-lws-messageboard"); - - try { - ws.onopen = function() { - document.getElementById("debug").textContent = "ws opened"; - } - ws.onmessage =function got_packet(msg) { - add_div("messages", JSON.parse(msg.data)); - } - ws.onclose = function(){ - } - } catch(exception) { - alert('

Error' + exception); - } - } - - function mupd() - { - document.getElementById("send").disabled = !document.getElementById("msg").value; - } -}, false); Binary files /tmp/tmp2l8bmswe/3lv7Sxvgkv/libwebsockets-3.2.1/plugins/generic-sessions/assets/lwsgs-logo.png and /tmp/tmp2l8bmswe/LwTwoWz49Q/libwebsockets-4.1.6/plugins/generic-sessions/assets/lwsgs-logo.png differ diff -Nru libwebsockets-3.2.1/plugins/generic-sessions/assets/md5.min.js libwebsockets-4.1.6/plugins/generic-sessions/assets/md5.min.js --- libwebsockets-3.2.1/plugins/generic-sessions/assets/md5.min.js 2019-12-18 14:45:31.000000000 +0000 +++ libwebsockets-4.1.6/plugins/generic-sessions/assets/md5.min.js 1970-01-01 00:00:00.000000000 +0000 @@ -1,2 +0,0 @@ -!function(n){"use strict";function t(n,t){var r=(65535&n)+(65535&t),e=(n>>16)+(t>>16)+(r>>16);return e<<16|65535&r}function r(n,t){return n<>>32-t}function e(n,e,o,u,c,f){return t(r(t(t(e,n),t(u,f)),c),o)}function o(n,t,r,o,u,c,f){return e(t&r|~t&o,n,t,u,c,f)}function u(n,t,r,o,u,c,f){return e(t&o|r&~o,n,t,u,c,f)}function c(n,t,r,o,u,c,f){return e(t^r^o,n,t,u,c,f)}function f(n,t,r,o,u,c,f){return e(r^(t|~o),n,t,u,c,f)}function i(n,r){n[r>>5]|=128<>>9<<4)+14]=r;var e,i,a,h,d,l=1732584193,g=-271733879,v=-1732584194,m=271733878;for(e=0;e>5]>>>t%32&255);return r}function h(n){var t,r=[];for(r[(n.length>>2)-1]=void 0,t=0;t>5]|=(255&n.charCodeAt(t/8))<16&&(o=i(o,8*n.length)),r=0;16>r;r+=1)u[r]=909522486^o[r],c[r]=1549556828^o[r];return e=i(u.concat(h(t)),512+8*t.length),a(i(c.concat(e),640))}function g(n){var t,r,e="0123456789abcdef",o="";for(r=0;r>>4&15)+e.charAt(15&t);return o}function v(n){return unescape(encodeURIComponent(n))}function m(n){return d(v(n))}function p(n){return g(m(n))}function s(n,t){return l(v(n),v(t))}function C(n,t){return g(s(n,t))}function A(n,t,r){return t?r?s(t,n):C(t,n):r?m(n):p(n)}"function"==typeof define&&define.amd?define(function(){return A}):"object"==typeof module&&module.exports?module.exports=A:n.md5=A}(this); -//# sourceMappingURL=md5.min.js.map \ No newline at end of file diff -Nru libwebsockets-3.2.1/plugins/generic-sessions/assets/post-forgot-fail.html libwebsockets-4.1.6/plugins/generic-sessions/assets/post-forgot-fail.html --- libwebsockets-3.2.1/plugins/generic-sessions/assets/post-forgot-fail.html 2019-12-18 14:45:31.000000000 +0000 +++ libwebsockets-4.1.6/plugins/generic-sessions/assets/post-forgot-fail.html 1970-01-01 00:00:00.000000000 +0000 @@ -1,5 +0,0 @@ - -Sorry, something went wrong. - -Click here to continue. - diff -Nru libwebsockets-3.2.1/plugins/generic-sessions/assets/post-forgot-ok.html libwebsockets-4.1.6/plugins/generic-sessions/assets/post-forgot-ok.html --- libwebsockets-3.2.1/plugins/generic-sessions/assets/post-forgot-ok.html 2019-12-18 14:45:31.000000000 +0000 +++ libwebsockets-4.1.6/plugins/generic-sessions/assets/post-forgot-ok.html 1970-01-01 00:00:00.000000000 +0000 @@ -1,6 +0,0 @@ - -This is a one-time password recovery login. - -Please click here and click your username at the top to reset your password. - - diff -Nru libwebsockets-3.2.1/plugins/generic-sessions/assets/post-register-fail.html libwebsockets-4.1.6/plugins/generic-sessions/assets/post-register-fail.html --- libwebsockets-3.2.1/plugins/generic-sessions/assets/post-register-fail.html 2019-12-18 14:45:31.000000000 +0000 +++ libwebsockets-4.1.6/plugins/generic-sessions/assets/post-register-fail.html 1970-01-01 00:00:00.000000000 +0000 @@ -1 +0,0 @@ -Registration failed, sorry diff -Nru libwebsockets-3.2.1/plugins/generic-sessions/assets/post-register-ok.html libwebsockets-4.1.6/plugins/generic-sessions/assets/post-register-ok.html --- libwebsockets-3.2.1/plugins/generic-sessions/assets/post-register-ok.html 2019-12-18 14:45:31.000000000 +0000 +++ libwebsockets-4.1.6/plugins/generic-sessions/assets/post-register-ok.html 1970-01-01 00:00:00.000000000 +0000 @@ -1,27 +0,0 @@ - - - - - - - - - - - - -
- -
- Your registration as is accepted,
- you will receive an email shortly with instructions
- to verify and enable the account for normal use.

- The link is only valid for an hour, after that if it has
- not been verified your account will be deleted. -
- - - - diff -Nru libwebsockets-3.2.1/plugins/generic-sessions/assets/post-verify-fail.html libwebsockets-4.1.6/plugins/generic-sessions/assets/post-verify-fail.html --- libwebsockets-3.2.1/plugins/generic-sessions/assets/post-verify-fail.html 2019-12-18 14:45:31.000000000 +0000 +++ libwebsockets-4.1.6/plugins/generic-sessions/assets/post-verify-fail.html 1970-01-01 00:00:00.000000000 +0000 @@ -1,20 +0,0 @@ - - - - - - - - - - - - -
- -
- Sorry, the link was invalid. -
- - - diff -Nru libwebsockets-3.2.1/plugins/generic-sessions/assets/post-verify-ok.html libwebsockets-4.1.6/plugins/generic-sessions/assets/post-verify-ok.html --- libwebsockets-3.2.1/plugins/generic-sessions/assets/post-verify-ok.html 2019-12-18 14:45:31.000000000 +0000 +++ libwebsockets-4.1.6/plugins/generic-sessions/assets/post-verify-ok.html 1970-01-01 00:00:00.000000000 +0000 @@ -1,25 +0,0 @@ - - - - - - - - - - - - -
- -
- Thanks for signing up, your registration as is verified.
-
- Click here to continue. -
- - - - Binary files /tmp/tmp2l8bmswe/3lv7Sxvgkv/libwebsockets-3.2.1/plugins/generic-sessions/assets/seats.jpg and /tmp/tmp2l8bmswe/LwTwoWz49Q/libwebsockets-4.1.6/plugins/generic-sessions/assets/seats.jpg differ diff -Nru libwebsockets-3.2.1/plugins/generic-sessions/assets/sent-forgot-fail.html libwebsockets-4.1.6/plugins/generic-sessions/assets/sent-forgot-fail.html --- libwebsockets-3.2.1/plugins/generic-sessions/assets/sent-forgot-fail.html 2019-12-18 14:45:31.000000000 +0000 +++ libwebsockets-4.1.6/plugins/generic-sessions/assets/sent-forgot-fail.html 1970-01-01 00:00:00.000000000 +0000 @@ -1,5 +0,0 @@ - -Sorry, something went wrong. - -Click here to continue. - diff -Nru libwebsockets-3.2.1/plugins/generic-sessions/assets/sent-forgot-ok.html libwebsockets-4.1.6/plugins/generic-sessions/assets/sent-forgot-ok.html --- libwebsockets-3.2.1/plugins/generic-sessions/assets/sent-forgot-ok.html 2019-12-18 14:45:31.000000000 +0000 +++ libwebsockets-4.1.6/plugins/generic-sessions/assets/sent-forgot-ok.html 1970-01-01 00:00:00.000000000 +0000 @@ -1,4 +0,0 @@ -An email has been sent to your registered address. - -Please follow the instructions to reset your password. - diff -Nru libwebsockets-3.2.1/plugins/generic-sessions/assets/successful-login.html libwebsockets-4.1.6/plugins/generic-sessions/assets/successful-login.html --- libwebsockets-3.2.1/plugins/generic-sessions/assets/successful-login.html 2019-12-18 14:45:31.000000000 +0000 +++ libwebsockets-4.1.6/plugins/generic-sessions/assets/successful-login.html 1970-01-01 00:00:00.000000000 +0000 @@ -1,4 +0,0 @@ - -This is an example destination that will appear after successful non-Admin login - - diff -Nru libwebsockets-3.2.1/plugins/generic-sessions/handlers.c libwebsockets-4.1.6/plugins/generic-sessions/handlers.c --- libwebsockets-3.2.1/plugins/generic-sessions/handlers.c 2019-12-18 14:45:31.000000000 +0000 +++ libwebsockets-4.1.6/plugins/generic-sessions/handlers.c 1970-01-01 00:00:00.000000000 +0000 @@ -1,648 +0,0 @@ -/* - * ws protocol handler plugin for "generic sessions" - * - * Copyright (C) 2010-2019 Andy Green - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation: - * version 2.1 of the License. - * - * This library is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * General Public License for more details. - * - * You should have received a copy of the GNU General Public - * License along with this library; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, - * MA 02110-1301 USA - */ - -#include "private-lwsgs.h" - -static int -lwsgs_smtp_client_done(struct lws_smtp_email *e, void *buf, size_t len) -{ - free(e); - - return 0; -} - -static int -lwsgs_smtp_client_done_sentvfy(struct lws_smtp_email *e, void *buf, size_t len) -{ - struct per_vhost_data__gs *vhd = (struct per_vhost_data__gs *)e->data; - const char *username = (const char *)e->extra; - char s[200], esc[96]; - - lwsl_notice("%s: registration email sent: %s\n", __func__, username); - - /* mark the user as having sent the verification email */ - lws_snprintf(s, sizeof(s) - 1, - "update users set verified=1 where username='%s' and verified==0;", - lws_sql_purify(esc, username, sizeof(esc) - 1)); - if (sqlite3_exec(vhd->pdb, s, NULL, NULL, NULL) != SQLITE_OK) { - lwsl_err("%s: Unable to update user: %s\n", __func__, - sqlite3_errmsg(vhd->pdb)); - return 1; - } - - free(e); - - return 0; -} - -/* handle account confirmation links */ - -int -lwsgs_handler_confirm(struct per_vhost_data__gs *vhd, struct lws *wsi, - struct per_session_data__gs *pss) -{ - char cookie[1024], s[256], esc[90]; - struct lws_gs_event_args a; - struct lwsgs_user u; - - if (lws_hdr_copy_fragment(wsi, cookie, sizeof(cookie), - WSI_TOKEN_HTTP_URI_ARGS, 0) < 0) { - lwsl_err("%s: missing URI_ARGS\n", __func__); - goto verf_fail; - } - - if (strncmp(cookie, "token=", 6)) { - lwsl_err("%s: missing URI_ARGS token=\n", __func__); - goto verf_fail; - } - - u.username[0] = '\0'; - u.verified = -1; - lws_snprintf(s, sizeof(s) - 1, - "select username,email,verified from users where token = '%s';", - lws_sql_purify(esc, &cookie[6], sizeof(esc) - 1)); - puts(s); - if (sqlite3_exec(vhd->pdb, s, lwsgs_lookup_callback_user, &u, NULL) != - SQLITE_OK) { - lwsl_err("Unable to lookup token: %s\n", - sqlite3_errmsg(vhd->pdb)); - goto verf_fail; - } - - if (!u.username[0] || u.verified != 1) { - lwsl_notice("verify token %s doesn't map to unverified user (user='%s', verified=%d)\n", - &cookie[6], u.username, u.verified); - goto verf_fail; - } - - lwsl_notice("Verifying %s\n", u.username); - lws_snprintf(s, sizeof(s) - 1, - "update users set verified=%d where username='%s';", - LWSGS_VERIFIED_ACCEPTED, - lws_sql_purify(esc, u.username, sizeof(esc) - 1)); - if (sqlite3_exec(vhd->pdb, s, lwsgs_lookup_callback_user, &u, NULL) != - SQLITE_OK) { - lwsl_err("Unable to lookup token: %s\n", - sqlite3_errmsg(vhd->pdb)); - - goto verf_fail; - } - - lwsl_notice("deleting account\n"); - - a.event = LWSGSE_CREATED; - a.username = u.username; - a.email = u.email; - lws_callback_vhost_protocols_vhost(lws_get_vhost(wsi), - LWS_CALLBACK_GS_EVENT, &a, 0); - - lws_snprintf(pss->onward, sizeof(pss->onward), - "%s/post-verify-ok.html", vhd->email_confirm_url); - - pss->login_expires = lws_now_secs() + vhd->timeout_absolute_secs; - - pss->delete_session.id[0] = '\0'; - lwsgs_get_sid_from_wsi(wsi, &pss->delete_session); - - /* we need to create a new, authorized session */ - - if (lwsgs_new_session_id(vhd, &pss->login_session, u.username, - pss->login_expires)) - goto verf_fail; - - lwsl_notice("Creating new session: %s, redir to %s\n", - pss->login_session.id, pss->onward); - - return 0; - -verf_fail: - pss->delete_session.id[0] = '\0'; - lwsgs_get_sid_from_wsi(wsi, &pss->delete_session); - pss->login_expires = 0; - - lws_snprintf(pss->onward, sizeof(pss->onward), "%s/post-verify-fail.html", - vhd->email_confirm_url); - - return 1; -} - -/* handle forgot password confirmation links */ - -int -lwsgs_handler_forgot(struct per_vhost_data__gs *vhd, struct lws *wsi, - struct per_session_data__gs *pss) -{ - char cookie[1024], s[256], esc[96]; - struct lwsgs_user u; - const char *a; - - a = lws_get_urlarg_by_name(wsi, "token=", cookie, sizeof(cookie)); - if (!a) - goto forgot_fail; - - u.username[0] = '\0'; - lws_snprintf(s, sizeof(s) - 1, - "select username,verified from users where verified=%d and " - "token = '%s' and token_time != 0;", - LWSGS_VERIFIED_ACCEPTED, - lws_sql_purify(esc, &cookie[6], sizeof(esc) - 1)); - if (sqlite3_exec(vhd->pdb, s, lwsgs_lookup_callback_user, &u, NULL) != - SQLITE_OK) { - lwsl_err("Unable to lookup token: %s\n", - sqlite3_errmsg(vhd->pdb)); - - goto forgot_fail; - } - - if (!u.username[0]) { - puts(s); - lwsl_notice("forgot token doesn't map to verified user\n"); - goto forgot_fail; - } - - /* mark user as having validated forgot flow just now */ - - lws_snprintf(s, sizeof(s) - 1, - "update users set token_time=0,last_forgot_validated=%lu " - "where username='%s';", - (unsigned long)lws_now_secs(), - lws_sql_purify(esc, u.username, sizeof(esc) - 1)); - - if (sqlite3_exec(vhd->pdb, s, lwsgs_lookup_callback_user, &u, NULL) != - SQLITE_OK) { - lwsl_err("Unable to lookup token: %s\n", - sqlite3_errmsg(vhd->pdb)); - goto forgot_fail; - } - - a = lws_get_urlarg_by_name(wsi, "good=", cookie, sizeof(cookie)); - if (!a) - a = "broken-forget-post-good-url"; - - lws_snprintf(pss->onward, sizeof(pss->onward), - "%s/%s", vhd->email_confirm_url, a); - - pss->login_expires = lws_now_secs() + vhd->timeout_absolute_secs; - - pss->delete_session.id[0] = '\0'; - lwsgs_get_sid_from_wsi(wsi, &pss->delete_session); - - /* we need to create a new, authorized session */ - if (lwsgs_new_session_id(vhd, &pss->login_session, - u.username, - pss->login_expires)) - goto forgot_fail; - - lwsl_notice("Creating new session: %s, redir to %s\n", - pss->login_session.id, pss->onward); - - return 0; - -forgot_fail: - pss->delete_session.id[0] = '\0'; - lwsgs_get_sid_from_wsi(wsi, &pss->delete_session); - pss->login_expires = 0; - - a = lws_get_urlarg_by_name(wsi, "bad=", cookie, sizeof(cookie)); - if (!a) - a = "broken-forget-post-bad-url"; - - lws_snprintf(pss->onward, sizeof(pss->onward), "%s/%s", - vhd->email_confirm_url, a); - - return 1; -} - -/* support dynamic username / email checking */ - -int -lwsgs_handler_check(struct per_vhost_data__gs *vhd, - struct lws *wsi, struct per_session_data__gs *pss, - const char *in) -{ - static const char * const colname[] = { "username", "email" }; - char s[256], esc[96], *pc; - unsigned char *p, *start, *end, buffer[LWS_PRE + 1024]; - struct lwsgs_user u; - int n; - - /* - * either /check/email=xxx@yyy or: /check/username=xxx - * returns '0' if not already registered, else '1' - */ - - u.username[0] = '\0'; - - n = !strncmp(in, "email=", 6); - pc = strchr(in, '='); - if (!pc) { - lwsl_notice("cookie has no =\n"); - goto reply; - } - pc++; - - /* admin user cannot be registered in user db */ - if (!strcmp(vhd->admin_user, pc)) { - u.username[0] = 'a'; - goto reply; - } - - lws_snprintf(s, sizeof(s) - 1, - "select username, email from users where %s = '%s';", - colname[n], lws_sql_purify(esc, pc, sizeof(esc) - 1)); - if (sqlite3_exec(vhd->pdb, s, lwsgs_lookup_callback_user, &u, NULL) != - SQLITE_OK) { - lwsl_err("Unable to lookup token: %s\n", - sqlite3_errmsg(vhd->pdb)); - goto reply; - } - -reply: - s[0] = '0' + !!u.username[0]; - p = buffer + LWS_PRE; - start = p; - end = p + sizeof(buffer) - LWS_PRE; - - if (lws_add_http_header_status(wsi, HTTP_STATUS_OK, &p, end)) - return -1; - if (lws_add_http_header_by_token(wsi, WSI_TOKEN_HTTP_CONTENT_TYPE, - (unsigned char *)"text/plain", 10, - &p, end)) - return -1; - - if (lws_add_http_header_content_length(wsi, 1, &p, end)) - return -1; - - if (lws_finalize_http_header(wsi, &p, end)) - return -1; - - n = lws_write(wsi, start, p - start, LWS_WRITE_HTTP_HEADERS); - if (n != (p - start)) { - lwsl_err("_write returned %d from %ld\n", n, (long)(p - start)); - return -1; - } - - pss->check_response_value = s[0]; - pss->check_response = 1; - - lws_callback_on_writable(wsi); - - return 0; -} - -/* handle forgot password confirmation links */ - -int -lwsgs_handler_change_password(struct per_vhost_data__gs *vhd, struct lws *wsi, - struct per_session_data__gs *pss) -{ - char s[256], esc[96], username[96]; - struct lwsgs_user u; - lwsgw_hash sid; - int n = 0; - - /* see if he's logged in */ - username[0] = '\0'; - if (!lwsgs_get_sid_from_wsi(wsi, &sid)) { - u.username[0] = '\0'; - if (!lwsgs_lookup_session(vhd, &sid, username, sizeof(username))) { - n = 1; /* yes, logged in */ - if (lwsgs_lookup_user(vhd, username, &u)) - return 1; - - /* did a forgot pw ? */ - if (u.last_forgot_validated > (time_t)lws_now_secs() - 300) { - n |= LWSGS_AUTH_FORGOT_FLOW; - lwsl_debug("within forgot password flow\n"); - } - } - } - - lwsl_debug("auth value %d\n", n); - - /* if he just did forgot pw flow, don't need old pw */ - if ((n & (LWSGS_AUTH_FORGOT_FLOW | 1)) != (LWSGS_AUTH_FORGOT_FLOW | 1)) { - /* otherwise user:pass must be right */ - lwsl_debug("checking pw\n"); - if (lwsgs_check_credentials(vhd, - lws_spa_get_string(pss->spa, FGS_USERNAME), - lws_spa_get_string(pss->spa, FGS_CURPW))) { - lwsl_notice("credentials bad\n"); - return 1; - } - - lwsl_debug("current pw checks out\n"); - - lws_strncpy(u.username, lws_spa_get_string(pss->spa, FGS_USERNAME), - sizeof(u.username)); - } - - /* does he want to delete his account? */ - - if (lws_spa_get_length(pss->spa, FGS_DELETE)) { - struct lws_gs_event_args a; - - lwsl_notice("deleting account\n"); - - a.event = LWSGSE_DELETED; - a.username = u.username; - a.email = ""; - lws_callback_vhost_protocols_vhost(lws_get_vhost(wsi), - LWS_CALLBACK_GS_EVENT, &a, 0); - - lws_snprintf(s, sizeof(s) - 1, - "delete from users where username='%s';" - "delete from sessions where username='%s';", - lws_sql_purify(esc, u.username, sizeof(esc) - 1), - lws_sql_purify(esc, u.username, sizeof(esc) - 1)); - goto sql; - } - - if (lwsgs_hash_password(vhd, lws_spa_get_string(pss->spa, FGS_PASSWORD), &u)) - return 1; - - lwsl_notice("updating password hash\n"); - - lws_snprintf(s, sizeof(s) - 1, - "update users set pwhash='%s', pwsalt='%s', " - "last_forgot_validated=0 where username='%s';", - u.pwhash.id, u.pwsalt.id, - lws_sql_purify(esc, u.username, sizeof(esc) - 1)); - -sql: - if (sqlite3_exec(vhd->pdb, s, NULL, NULL, NULL) != SQLITE_OK) { - lwsl_err("Unable to update pw hash: %s\n", - sqlite3_errmsg(vhd->pdb)); - return 1; - } - - return 0; -} - -int -lwsgs_handler_forgot_pw_form(struct per_vhost_data__gs *vhd, - struct lws *wsi, struct per_session_data__gs *pss) -{ - char esc[96], esc1[96], esc2[96], esc3[96], esc4[96]; - char s[LWSGS_EMAIL_CONTENT_SIZE]; - unsigned char sid_rand[32]; - lws_smtp_email_t *em; - struct lwsgs_user u; - lwsgw_hash hash; - int n; - - lwsl_notice("FORGOT %s %s\n", - lws_spa_get_string(pss->spa, FGS_USERNAME), - lws_spa_get_string(pss->spa, FGS_EMAIL)); - - if (!lws_spa_get_string(pss->spa, FGS_USERNAME) && - !lws_spa_get_string(pss->spa, FGS_EMAIL)) { - lwsl_err("Form must provide either " - "username or email\n"); - return -1; - } - - if (!lws_spa_get_string(pss->spa, FGS_FORGOT_GOOD) || - !lws_spa_get_string(pss->spa, FGS_FORGOT_BAD) || - !lws_spa_get_string(pss->spa, FGS_FORGOT_POST_GOOD) || - !lws_spa_get_string(pss->spa, FGS_FORGOT_POST_BAD)) { - lwsl_err("Form must provide reg-good " - "and reg-bad (and post-*)" - "targets\n"); - return -1; - } - - u.username[0] = '\0'; - if (lws_spa_get_string(pss->spa, FGS_USERNAME)) - lws_snprintf(s, sizeof(s) - 1, - "select username,email " - "from users where username = '%s';", - lws_sql_purify(esc, lws_spa_get_string(pss->spa, FGS_USERNAME), - sizeof(esc) - 1)); - else - lws_snprintf(s, sizeof(s) - 1, - "select username,email " - "from users where email = '%s';", - lws_sql_purify(esc, lws_spa_get_string(pss->spa, FGS_EMAIL), sizeof(esc) - 1)); - if (sqlite3_exec(vhd->pdb, s, lwsgs_lookup_callback_user, &u, NULL) != - SQLITE_OK) { - lwsl_err("Unable to lookup token: %s\n", - sqlite3_errmsg(vhd->pdb)); - return 1; - } - if (!u.username[0]) { - lwsl_err("No match found %s\n", s); - return 1; - } - - lws_get_peer_simple(wsi, pss->ip, sizeof(pss->ip)); - if (lws_get_random(vhd->context, sid_rand, - sizeof(sid_rand)) != - sizeof(sid_rand)) { - lwsl_err("Problem getting random for token\n"); - return 1; - } - sha256_to_lwsgw_hash(sid_rand, &hash); - - lws_snprintf(s, sizeof(s) - 1, - "update users set token='%s',token_time='%ld' where username='%s';", - hash.id, (long)lws_now_secs(), - lws_sql_purify(esc, u.username, sizeof(esc) - 1)); - if (sqlite3_exec(vhd->pdb, s, NULL, NULL, NULL) != - SQLITE_OK) { - lwsl_err("Unable to set token: %s\n", - sqlite3_errmsg(vhd->pdb)); - return 1; - } - - n = lws_snprintf(s, sizeof(s), - "From: Forgot Password Assistant Noreply <%s>\n" - "To: %s <%s>\n" - "Subject: Password reset request\n" - "\n" - "Hello, %s\n\n" - "We received a password reset request from IP %s for this email,\n" - "to confirm you want to do that, please click the link below.\n\n", - lws_sql_purify(esc, vhd->email_from, sizeof(esc) - 1), - lws_sql_purify(esc1, u.username, sizeof(esc1) - 1), - lws_sql_purify(esc2, u.email, sizeof(esc2) - 1), - lws_sql_purify(esc3, u.username, sizeof(esc3) - 1), - lws_sql_purify(esc4, pss->ip, sizeof(esc4) - 1)); - n += lws_snprintf(s + n, sizeof(s) - n, - "%s/lwsgs-forgot?token=%s" - "&good=%s" - "&bad=%s\n\n" - "If this request is unexpected, please ignore it and\n" - "no further action will be taken.\n\n" - "If you have any questions or concerns about this\n" - "automated email, you can contact a real person at\n" - "%s.\n" - "\n.\n", - vhd->email_confirm_url, hash.id, - lws_urlencode(esc1, - lws_spa_get_string(pss->spa, FGS_FORGOT_POST_GOOD), - sizeof(esc1) - 1), - lws_urlencode(esc3, - lws_spa_get_string(pss->spa, FGS_FORGOT_POST_BAD), - sizeof(esc3) - 1), - vhd->email_contact_person); - - puts(s); - - em = lws_smtp_client_alloc_email_helper(s, n, vhd->email_from, u.email, - u.username, strlen(u.username), - vhd, lwsgs_smtp_client_done); - if (!em) - return 1; - if (lws_smtp_client_add_email(vhd->smtp_client, em)) - return 1; - - return 0; -} - -int -lwsgs_handler_register_form(struct per_vhost_data__gs *vhd, - struct lws *wsi, - struct per_session_data__gs *pss) -{ - unsigned char buffer[LWS_PRE + LWSGS_EMAIL_CONTENT_SIZE]; - char esc[96], esc1[96], esc2[96], esc3[96], esc4[96]; - char s[LWSGS_EMAIL_CONTENT_SIZE]; - unsigned char sid_rand[32]; - lws_smtp_email_t *em; - struct lwsgs_user u; - lwsgw_hash hash; - size_t n; - - lwsl_notice("REGISTER %s %s %s\n", - lws_spa_get_string(pss->spa, FGS_USERNAME), - lws_spa_get_string(pss->spa, FGS_PASSWORD), - lws_spa_get_string(pss->spa, FGS_EMAIL)); - if (lwsgs_get_sid_from_wsi(wsi, - &pss->login_session)) - return 1; - - lws_get_peer_simple(wsi, pss->ip, sizeof(pss->ip)); - lwsl_notice("IP=%s\n", pss->ip); - - if (!lws_spa_get_string(pss->spa, FGS_REG_GOOD) || - !lws_spa_get_string(pss->spa, FGS_REG_BAD)) { - lwsl_info("Form must provide reg-good and reg-bad targets\n"); - return -1; - } - - /* admin user cannot be registered in user db */ - if (!strcmp(vhd->admin_user, - lws_spa_get_string(pss->spa, FGS_USERNAME))) - return 1; - - if (!lwsgs_lookup_user(vhd, - lws_spa_get_string(pss->spa, FGS_USERNAME), &u)) { - lwsl_notice("user %s already registered\n", - lws_spa_get_string(pss->spa, FGS_USERNAME)); - return 1; - } - - u.username[0] = '\0'; - lws_snprintf(s, sizeof(s) - 1, "select username, email from users where email = '%s';", - lws_sql_purify(esc, lws_spa_get_string(pss->spa, FGS_EMAIL), - sizeof(esc) - 1)); - - if (sqlite3_exec(vhd->pdb, s, - lwsgs_lookup_callback_user, &u, NULL) != SQLITE_OK) { - lwsl_err("Unable to lookup token: %s\n", - sqlite3_errmsg(vhd->pdb)); - return 1; - } - - if (u.username[0]) { - lwsl_notice("email %s already in use\n", - lws_spa_get_string(pss->spa, FGS_USERNAME)); - return 1; - } - - if (lwsgs_hash_password(vhd, lws_spa_get_string(pss->spa, FGS_PASSWORD), - &u)) { - lwsl_err("Password hash failed\n"); - return 1; - } - - if (lws_get_random(vhd->context, sid_rand, sizeof(sid_rand)) != - sizeof(sid_rand)) { - lwsl_err("Problem getting random for token\n"); - return 1; - } - sha256_to_lwsgw_hash(sid_rand, &hash); - - lws_snprintf((char *)buffer, sizeof(buffer) - 1, - "insert into users(username," - " creation_time, ip, email, verified," - " pwhash, pwsalt, token, last_forgot_validated)" - " values ('%s', %lu, '%s', '%s', 0," - " '%s', '%s', '%s', 0);", - lws_sql_purify(esc, lws_spa_get_string(pss->spa, FGS_USERNAME), sizeof(esc) - 1), - (unsigned long)lws_now_secs(), - lws_sql_purify(esc1, pss->ip, sizeof(esc1) - 1), - lws_sql_purify(esc2, lws_spa_get_string(pss->spa, FGS_EMAIL), sizeof(esc2) - 1), - u.pwhash.id, u.pwsalt.id, hash.id); - - if (sqlite3_exec(vhd->pdb, (char *)buffer, NULL, NULL, NULL) != SQLITE_OK) { - lwsl_err("Unable to insert user: %s\n", - sqlite3_errmsg(vhd->pdb)); - return 1; - } - - n = lws_snprintf(s, sizeof(s), - "From: Noreply <%s>\n" - "To: %s <%s>\n" - "Subject: Registration verification\n" - "\n" - "Hello, %s\n\n" - "We received a registration from IP %s using this email,\n" - "to confirm it is legitimate, please click the link below.\n\n" - "%s/lwsgs-confirm?token=%s\n\n" - "If this request is unexpected, please ignore it and\n" - "no further action will be taken.\n\n" - "If you have any questions or concerns about this\n" - "automated email, you can contact a real person at\n" - "%s.\n" - "\n.\n", - lws_sql_purify(esc, vhd->email_from, sizeof(esc) - 1), - lws_sql_purify(esc1, lws_spa_get_string(pss->spa, FGS_USERNAME), sizeof(esc1) - 1), - lws_sql_purify(esc2, lws_spa_get_string(pss->spa, FGS_EMAIL), sizeof(esc2) - 1), - lws_sql_purify(esc3, lws_spa_get_string(pss->spa, FGS_USERNAME), sizeof(esc3) - 1), - lws_sql_purify(esc4, pss->ip, sizeof(esc4) - 1), - vhd->email_confirm_url, hash.id, - vhd->email_contact_person); - - em = lws_smtp_client_alloc_email_helper(s, n, vhd->email_from, - lws_spa_get_string(pss->spa, FGS_EMAIL), - lws_spa_get_string(pss->spa, FGS_USERNAME), - strlen(lws_spa_get_string(pss->spa, FGS_USERNAME)), - vhd, lwsgs_smtp_client_done_sentvfy); - if (!em) - return 1; - - if (lws_smtp_client_add_email(vhd->smtp_client, em)) - return 1; - - return 0; -} diff -Nru libwebsockets-3.2.1/plugins/generic-sessions/private-lwsgs.h libwebsockets-4.1.6/plugins/generic-sessions/private-lwsgs.h --- libwebsockets-3.2.1/plugins/generic-sessions/private-lwsgs.h 2019-12-18 14:45:31.000000000 +0000 +++ libwebsockets-4.1.6/plugins/generic-sessions/private-lwsgs.h 1970-01-01 00:00:00.000000000 +0000 @@ -1,168 +0,0 @@ -/* - * ws protocol handler plugin for "generic sessions" - * - * Copyright (C) 2010-2016 Andy Green - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation: - * version 2.1 of the License. - * - * This library is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * General Public License for more details. - * - * You should have received a copy of the GNU General Public - * License along with this library; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, - * MA 02110-1301 USA - */ - -#define LWS_DLL -#define LWS_INTERNAL -#include - -#include -#include - -#define LWSGS_VERIFIED_ACCEPTED 100 - -enum { - FGS_USERNAME, - FGS_PASSWORD, - FGS_PASSWORD2, - FGS_EMAIL, - FGS_REGISTER, - FGS_GOOD, - FGS_BAD, - FGS_REG_GOOD, - FGS_REG_BAD, - FGS_ADMIN, - FGS_FORGOT, - FGS_FORGOT_GOOD, - FGS_FORGOT_BAD, - FGS_FORGOT_POST_GOOD, - FGS_FORGOT_POST_BAD, - FGS_CHANGE, - FGS_CURPW, - FGS_DELETE, -}; - -struct lwsgs_user { - char username[32]; - char ip[16]; - lwsgw_hash pwhash; - lwsgw_hash pwsalt; - lwsgw_hash token; - time_t created; - time_t last_forgot_validated; - char email[100]; - int verified; -}; - -struct per_vhost_data__gs { - lws_abs_t *smtp_client; - struct lwsgs_user u; - lws_token_map_t transport_tokens[3]; - lws_token_map_t protocol_tokens[2]; - char helo[64], ip[64]; - struct lws_context *context; - char session_db[256]; - char admin_user[32]; - char urlroot[48]; - char confounder[32]; - char email_contact_person[128]; - char email_title[128]; - char email_template[128]; - char email_confirm_url[128]; - char email_from[128]; - lwsgw_hash admin_password_sha256; - sqlite3 *pdb; - int timeout_idle_secs; - int timeout_absolute_secs; - int timeout_anon_absolute_secs; - int timeout_email_secs; - time_t last_session_expire; -}; - -struct per_session_data__gs { - struct lws_spa *spa; - lwsgw_hash login_session; - lwsgw_hash delete_session; - unsigned int login_expires; - char onward[256]; - char result[500 + LWS_PRE]; - char urldec[500 + LWS_PRE]; - int result_len; - char ip[46]; - struct lws_process_html_state phs; - int spos; - char check_response_value; - - unsigned int logging_out:1; - unsigned int check_response:1; -}; - -/* utils.c */ - -int -lwsgs_lookup_callback_user(void *priv, int cols, char **col_val, - char **col_name); -void -lwsgw_cookie_from_session(lwsgw_hash *sid, time_t expires, char **p, char *end); -int -lwsgs_get_sid_from_wsi(struct lws *wsi, lwsgw_hash *sid); -int -lwsgs_lookup_session(struct per_vhost_data__gs *vhd, - const lwsgw_hash *sid, char *username, int len); -int -lwsgs_get_auth_level(struct per_vhost_data__gs *vhd, - const char *username); -int -lwsgs_check_credentials(struct per_vhost_data__gs *vhd, - const char *username, const char *password); -void -sha256_to_lwsgw_hash(unsigned char *hash, lwsgw_hash *shash); -unsigned int -lwsgs_now_secs(void); -int -lwsgw_check_admin(struct per_vhost_data__gs *vhd, - const char *username, const char *password); -int -lwsgs_hash_password(struct per_vhost_data__gs *vhd, - const char *password, struct lwsgs_user *u); -int -lwsgs_new_session_id(struct per_vhost_data__gs *vhd, - lwsgw_hash *sid, const char *username, int exp); -int -lwsgs_lookup_user(struct per_vhost_data__gs *vhd, - const char *username, struct lwsgs_user *u); -int -lwsgw_update_session(struct per_vhost_data__gs *vhd, - lwsgw_hash *hash, const char *user); -int -lwsgw_expire_old_sessions(struct per_vhost_data__gs *vhd); - - -/* handlers.c */ - -int -lwsgs_handler_confirm(struct per_vhost_data__gs *vhd, struct lws *wsi, - struct per_session_data__gs *pss); -int -lwsgs_handler_forgot(struct per_vhost_data__gs *vhd, struct lws *wsi, - struct per_session_data__gs *pss); -int -lwsgs_handler_check(struct per_vhost_data__gs *vhd, struct lws *wsi, - struct per_session_data__gs *pss, const char *in); -int -lwsgs_handler_change_password(struct per_vhost_data__gs *vhd, struct lws *wsi, - struct per_session_data__gs *pss); -int -lwsgs_handler_forgot_pw_form(struct per_vhost_data__gs *vhd, struct lws *wsi, - struct per_session_data__gs *pss); -int -lwsgs_handler_register_form(struct per_vhost_data__gs *vhd, struct lws *wsi, - struct per_session_data__gs *pss); - diff -Nru libwebsockets-3.2.1/plugins/generic-sessions/protocol_generic_sessions.c libwebsockets-4.1.6/plugins/generic-sessions/protocol_generic_sessions.c --- libwebsockets-3.2.1/plugins/generic-sessions/protocol_generic_sessions.c 2019-12-18 14:45:31.000000000 +0000 +++ libwebsockets-4.1.6/plugins/generic-sessions/protocol_generic_sessions.c 1970-01-01 00:00:00.000000000 +0000 @@ -1,899 +0,0 @@ -/* - * ws protocol handler plugin for "generic sessions" - * - * Copyright (C) 2010-2019 Andy Green - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation: - * version 2.1 of the License. - * - * This library is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * General Public License for more details. - * - * You should have received a copy of the GNU General Public - * License along with this library; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, - * MA 02110-1301 USA - */ - -#include "private-lwsgs.h" -#include - -/* keep changes in sync with the enum in lwsgs.h */ -static const char * const param_names[] = { - "username", - "password", - "password2", - "email", - "register", - "good", - "bad", - "reg-good", - "reg-bad", - "admin", - "forgot", - "forgot-good", - "forgot-bad", - "forgot-post-good", - "forgot-post-bad", - "change", - "curpw", - "delete" -}; - -struct lwsgs_fill_args { - char *buf; - int len; -}; - -static const struct lws_protocols protocols[]; - -struct lwsgs_subst_args -{ - struct per_session_data__gs *pss; - struct per_vhost_data__gs *vhd; - struct lws *wsi; -}; - -static const char * -lwsgs_subst(void *data, int index) -{ - struct lwsgs_subst_args *a = (struct lwsgs_subst_args *)data; - struct lwsgs_user u; - lwsgw_hash sid; - char esc[96], s[100]; - int n; - - a->pss->result[0] = '\0'; - u.email[0] = '\0'; - if (!lwsgs_get_sid_from_wsi(a->wsi, &sid)) { - if (lwsgs_lookup_session(a->vhd, &sid, a->pss->result, 31)) { - lwsl_notice("sid lookup for %s failed\n", sid.id); - a->pss->delete_session = sid; - return NULL; - } - lws_snprintf(s, sizeof(s) - 1, "select username,email " - "from users where username = '%s';", - lws_sql_purify(esc, a->pss->result, sizeof(esc) - 1)); - if (sqlite3_exec(a->vhd->pdb, s, lwsgs_lookup_callback_user, - &u, NULL) != SQLITE_OK) { - lwsl_err("Unable to lookup token: %s\n", - sqlite3_errmsg(a->vhd->pdb)); - a->pss->delete_session = sid; - return NULL; - } - } else - lwsl_notice("no sid\n"); - - lws_strncpy(a->pss->result + 32, u.email, 100); - - switch (index) { - case 0: - return a->pss->result; - - case 1: - n = lwsgs_get_auth_level(a->vhd, a->pss->result); - sprintf(a->pss->result, "%d", n); - return a->pss->result; - case 2: - return a->pss->result + 32; - } - - return NULL; -} - -static int -lws_get_effective_host(struct lws *wsi, char *buf, size_t buflen) -{ - /* h2 */ - if (lws_hdr_copy(wsi, buf, buflen - 1, - WSI_TOKEN_HTTP_COLON_AUTHORITY) > 0) - return 0; - - /* h1 */ - if (lws_hdr_copy(wsi, buf, buflen - 1, WSI_TOKEN_HOST) > 0) - return 0; - - return 1; -} - -static int -callback_generic_sessions(struct lws *wsi, enum lws_callback_reasons reason, - void *user, void *in, size_t len) -{ - struct per_session_data__gs *pss = (struct per_session_data__gs *)user; - const struct lws_protocol_vhost_options *pvo; - struct per_vhost_data__gs *vhd = (struct per_vhost_data__gs *) - lws_protocol_vh_priv_get(lws_get_vhost(wsi), - lws_vhost_name_to_protocol(lws_get_vhost(wsi), - "protocol-generic-sessions")); - char cookie[1024], username[32], *pc = cookie; - unsigned char buffer[LWS_PRE + LWSGS_EMAIL_CONTENT_SIZE]; - struct lws_process_html_args *args = in; - struct lws_session_info *sinfo; - char s[LWSGS_EMAIL_CONTENT_SIZE]; - unsigned char *p, *start, *end; - const char *cp, *cp1; - sqlite3_stmt *sm; - lwsgw_hash sid; - lws_abs_t abs; - int n; - - switch (reason) { - case LWS_CALLBACK_PROTOCOL_INIT: /* per vhost */ - - vhd = lws_protocol_vh_priv_zalloc(lws_get_vhost(wsi), - lws_get_protocol(wsi), sizeof(struct per_vhost_data__gs)); - if (!vhd) - return 1; - vhd->context = lws_get_context(wsi); - - /* defaults */ - vhd->timeout_idle_secs = 600; - vhd->timeout_absolute_secs = 36000; - vhd->timeout_anon_absolute_secs = 1200; - vhd->timeout_email_secs = 24 * 3600; - - - strcpy(vhd->helo, "unconfigured.com"); - strcpy(vhd->ip, "127.0.0.1"); - strcpy(vhd->email_from, "noreply@unconfigured.com"); - strcpy(vhd->email_title, "Registration Email from unconfigured"); - vhd->urlroot[0] = '\0'; - - pvo = (const struct lws_protocol_vhost_options *)in; - while (pvo) { - if (!strcmp(pvo->name, "admin-user")) - lws_strncpy(vhd->admin_user, pvo->value, - sizeof(vhd->admin_user)); - if (!strcmp(pvo->name, "urlroot")) - lws_strncpy(vhd->urlroot, pvo->value, - sizeof(vhd->urlroot)); - if (!strcmp(pvo->name, "admin-password-sha256")) - lws_strncpy(vhd->admin_password_sha256.id, pvo->value, - sizeof(vhd->admin_password_sha256.id)); - if (!strcmp(pvo->name, "session-db")) - lws_strncpy(vhd->session_db, pvo->value, - sizeof(vhd->session_db)); - if (!strcmp(pvo->name, "confounder")) - lws_strncpy(vhd->confounder, pvo->value, - sizeof(vhd->confounder)); - if (!strcmp(pvo->name, "email-from")) - lws_strncpy(vhd->email_from, pvo->value, - sizeof(vhd->email_from)); - if (!strcmp(pvo->name, "email-helo")) - lws_strncpy(vhd->helo, pvo->value, sizeof(vhd->helo)); - if (!strcmp(pvo->name, "email-template")) - lws_strncpy(vhd->email_template, pvo->value, - sizeof(vhd->email_template)); - if (!strcmp(pvo->name, "email-title")) - lws_strncpy(vhd->email_title, pvo->value, - sizeof(vhd->email_title)); - if (!strcmp(pvo->name, "email-contact-person")) - lws_strncpy(vhd->email_contact_person, pvo->value, - sizeof(vhd->email_contact_person)); - if (!strcmp(pvo->name, "email-confirm-url-base")) - lws_strncpy(vhd->email_confirm_url, pvo->value, - sizeof(vhd->email_confirm_url)); - if (!strcmp(pvo->name, "email-server-ip")) - lws_strncpy(vhd->ip, pvo->value, sizeof(vhd->ip)); - - if (!strcmp(pvo->name, "timeout-idle-secs")) - vhd->timeout_idle_secs = atoi(pvo->value); - if (!strcmp(pvo->name, "timeout-absolute-secs")) - vhd->timeout_absolute_secs = atoi(pvo->value); - if (!strcmp(pvo->name, "timeout-anon-absolute-secs")) - vhd->timeout_anon_absolute_secs = atoi(pvo->value); - if (!strcmp(pvo->name, "email-expire")) - vhd->timeout_email_secs = atoi(pvo->value); - pvo = pvo->next; - } - if (!vhd->admin_user[0] || - !vhd->admin_password_sha256.id[0] || - !vhd->session_db[0]) { - lwsl_err("generic-sessions: " - "You must give \"admin-user\", " - "\"admin-password-sha256\", " - "and \"session_db\" per-vhost options\n"); - return 1; - } - - if (lws_struct_sq3_open(lws_get_context(wsi), - vhd->session_db, &vhd->pdb)) { - lwsl_err("Unable to open session db %s: %s\n", - vhd->session_db, sqlite3_errmsg(vhd->pdb)); - - return 1; - } - - if (sqlite3_prepare(vhd->pdb, - "create table if not exists sessions (" - " name char(65)," - " username varchar(32)," - " expire integer" - ");", - -1, &sm, NULL) != SQLITE_OK) { - lwsl_err("Unable to prepare session table init: %s\n", - sqlite3_errmsg(vhd->pdb)); - - return 1; - } - - if (sqlite3_step(sm) != SQLITE_DONE) { - lwsl_err("Unable to run session table init: %s\n", - sqlite3_errmsg(vhd->pdb)); - - return 1; - } - sqlite3_finalize(sm); - - if (sqlite3_exec(vhd->pdb, - "create table if not exists users (" - " username varchar(32)," - " creation_time integer," - " ip varchar(46)," - " email varchar(100)," - " pwhash varchar(65)," - " pwsalt varchar(65)," - " pwchange_time integer," - " token varchar(65)," - " verified integer," - " token_time integer," - " last_forgot_validated integer," - " primary key (username)" - ");", - NULL, NULL, NULL) != SQLITE_OK) { - lwsl_err("Unable to create user table: %s\n", - sqlite3_errmsg(vhd->pdb)); - - return 1; - } - - memset(&abs, 0, sizeof(abs)); - abs.vh = lws_get_vhost(wsi); - - /* select the protocol and bind its tokens */ - - abs.ap = lws_abs_protocol_get_by_name("smtp"); - if (!abs.ap) - return 1; - - vhd->protocol_tokens[0].name_index = LTMI_PSMTP_V_HELO; - vhd->protocol_tokens[0].u.value = vhd->helo; - - abs.ap_tokens = vhd->protocol_tokens; - - /* select the transport and bind its tokens */ - - abs.at = lws_abs_transport_get_by_name("raw_skt"); - if (!abs.at) - return 1; - - vhd->transport_tokens[0].name_index = LTMI_PEER_V_DNS_ADDRESS; - vhd->transport_tokens[0].u.value = vhd->ip; - vhd->transport_tokens[1].name_index = LTMI_PEER_LV_PORT; - vhd->transport_tokens[1].u.lvalue = 25; - - abs.at_tokens = vhd->transport_tokens; - - vhd->smtp_client = lws_abs_bind_and_create_instance(&abs); - if (!vhd->smtp_client) - return 1; - - lwsl_notice("%s: created SMTP client\n", __func__); - break; - - case LWS_CALLBACK_PROTOCOL_DESTROY: - // lwsl_notice("gs: LWS_CALLBACK_PROTOCOL_DESTROY: v=%p, ctx=%p\n", vhd, vhd->context); - if (vhd->pdb) { - sqlite3_close(vhd->pdb); - vhd->pdb = NULL; - } - if (vhd->smtp_client) - lws_abs_destroy_instance(&vhd->smtp_client); - break; - - case LWS_CALLBACK_HTTP_WRITEABLE: - if (!pss->check_response) - break; - pss->check_response = 0; - n = lws_write(wsi, (unsigned char *)&pss->check_response_value, - 1, LWS_WRITE_HTTP | LWS_WRITE_H2_STREAM_END); - if (n != 1) - return -1; - goto try_to_reuse; - - case LWS_CALLBACK_HTTP: - if (!pss) { - lwsl_err("%s: no valid pss\n", __func__); - return 1; - } - - pss->login_session.id[0] = '\0'; - pss->phs.pos = 0; - - cp = in; - if ((*(const char *)in == '/')) - cp++; - - if (lws_get_effective_host(wsi, cookie, sizeof(cookie))) { - lwsl_err("%s: HTTP: no effective host\n", __func__); - return 1; - } - - lwsl_notice("LWS_CALLBACK_HTTP: %s, HOST '%s'\n", - (const char *)in, cookie); - - n = strlen(cp); - - lws_snprintf(pss->onward, sizeof(pss->onward), - "%s%s", vhd->urlroot, (const char *)in); - - if (n >= 12 && - !strcmp(cp + n - 12, "lwsgs-forgot")) { - lwsgs_handler_forgot(vhd, wsi, pss); - goto redirect_with_cookie; - } - - if (n >= 13 && - !strcmp(cp + n - 13, "lwsgs-confirm")) { - lwsgs_handler_confirm(vhd, wsi, pss); - goto redirect_with_cookie; - } - cp = strstr(cp, "lwsgs-check/"); - if (cp) { - lwsgs_handler_check(vhd, wsi, pss, cp + 12); - /* second, async part will complete transaction */ - break; - } - - if (n >= 11 && !strcmp(cp + n - 11, "lwsgs-login")) - break; - if (n >= 12 && !strcmp(cp + n - 12, "lwsgs-logout")) - break; - if (n >= 12 && !strcmp(cp + n - 12, "lwsgs-forgot")) - break; - if (n >= 12 && !strcmp(cp + n - 12, "lwsgs-change")) - break; - - /* if no legitimate url for GET, return 404 */ - - lwsl_err("http doing 404 on %s\n", cp); - lws_return_http_status(wsi, HTTP_STATUS_NOT_FOUND, NULL); - - return -1; - //goto try_to_reuse; - - case LWS_CALLBACK_FILTER_PROTOCOL_CONNECTION: - args = (struct lws_process_html_args *)in; - if (!args->chunked) - break; - case LWS_CALLBACK_CHECK_ACCESS_RIGHTS: - n = 0; - username[0] = '\0'; - sid.id[0] = '\0'; - args = (struct lws_process_html_args *)in; - lwsl_notice("%s: LWS_CALLBACK_CHECK_ACCESS_RIGHTS: need 0x%x\n", - __func__, args->max_len); - if (!lwsgs_get_sid_from_wsi(wsi, &sid)) { - if (lwsgs_lookup_session(vhd, &sid, username, - sizeof(username))) { - - /* - * if we're authenticating for ws, we don't - * want to redirect it or gain a cookie on that, - * he'll need to get the cookie from http - * interactions outside of this. - */ - if (args->chunked) { - lwsl_notice("%s: ws auth failed\n", - __func__); - - return 1; - } - - lwsl_notice("session lookup for %s failed, " - "probably expired\n", sid.id); - pss->delete_session = sid; - args->final = 1; /* signal we dealt with it */ - lws_snprintf(pss->onward, sizeof(pss->onward) - 1, - "%s%s", vhd->urlroot, args->p); - lwsl_notice("redirecting to ourselves with " - "cookie refresh\n"); - /* we need a redirect to ourselves, - * session cookie is expired */ - goto redirect_with_cookie; - } - } else - lwsl_notice("failed to get sid from wsi\n"); - - n = lwsgs_get_auth_level(vhd, username); - - if ((args->max_len & n) != args->max_len) { - lwsl_notice("Access rights fail 0x%X vs 0x%X (cookie %s)\n", - args->max_len, n, sid.id); - return 1; - } - lwsl_debug("Access rights OK\n"); - break; - - case LWS_CALLBACK_SESSION_INFO: - { - struct lwsgs_user u; - sinfo = (struct lws_session_info *)in; - sinfo->username[0] = '\0'; - sinfo->email[0] = '\0'; - sinfo->ip[0] = '\0'; - sinfo->session[0] = '\0'; - sinfo->mask = 0; - - sid.id[0] = '\0'; - lwsl_debug("LWS_CALLBACK_SESSION_INFO\n"); - if (lwsgs_get_sid_from_wsi(wsi, &sid)) - break; - if (lwsgs_lookup_session(vhd, &sid, username, sizeof(username))) - break; - - lws_snprintf(s, sizeof(s) - 1, - "select username, email from users where username='%s';", - username); - if (sqlite3_exec(vhd->pdb, s, lwsgs_lookup_callback_user, &u, NULL) != - SQLITE_OK) { - lwsl_err("Unable to lookup token: %s\n", - sqlite3_errmsg(vhd->pdb)); - break; - } - lws_strncpy(sinfo->username, u.username, sizeof(sinfo->username)); - lws_strncpy(sinfo->email, u.email, sizeof(sinfo->email)); - lws_strncpy(sinfo->session, sid.id, sizeof(sinfo->session)); - sinfo->mask = lwsgs_get_auth_level(vhd, username); - lws_get_peer_simple(wsi, sinfo->ip, sizeof(sinfo->ip)); - } - - break; - - case LWS_CALLBACK_PROCESS_HTML: - - args = (struct lws_process_html_args *)in; - { - static const char * const vars[] = { - "$lwsgs_user", - "$lwsgs_auth", - "$lwsgs_email" - }; - struct lwsgs_subst_args a; - - a.vhd = vhd; - a.pss = pss; - a.wsi = wsi; - - pss->phs.vars = vars; - pss->phs.count_vars = LWS_ARRAY_SIZE(vars); - pss->phs.replace = lwsgs_subst; - pss->phs.data = &a; - - if (lws_chunked_html_process(args, &pss->phs)) - return -1; - } - break; - - case LWS_CALLBACK_HTTP_BODY: - if (len < 2) - break; - - if (!pss->spa) { - pss->spa = lws_spa_create(wsi, param_names, - LWS_ARRAY_SIZE(param_names), 1024, - NULL, NULL); - if (!pss->spa) - return -1; - } - - if (lws_spa_process(pss->spa, in, len)) { - lwsl_notice("spa process blew\n"); - return -1; - } - break; - - case LWS_CALLBACK_HTTP_BODY_COMPLETION: - - if (!pss->spa) - break; - - cp1 = (const char *)pss->onward; - if (*cp1 == '/') - cp1++; - - - lws_spa_finalize(pss->spa); - n = strlen(cp1); - - if (lws_get_effective_host(wsi, cookie, sizeof(cookie))) - return 1; - - if (!strcmp(cp1 + n - 12, "lwsgs-change")) { - if (!lwsgs_handler_change_password(vhd, wsi, pss)) { - cp = lws_spa_get_string(pss->spa, FGS_GOOD); - goto pass; - } - - cp = lws_spa_get_string(pss->spa, FGS_BAD); - lwsl_notice("user/password no good %s\n", - lws_spa_get_string(pss->spa, FGS_USERNAME)); - lws_snprintf(pss->onward, sizeof(pss->onward), - "%s%s", vhd->urlroot, cp); - - pss->onward[sizeof(pss->onward) - 1] = '\0'; - goto completion_flow; - } - - if (!strcmp(cp1 + n - 11, "lwsgs-login")) { - lwsl_err("%s: lwsgs-login\n", __func__); - if (lws_spa_get_string(pss->spa, FGS_FORGOT) && - lws_spa_get_string(pss->spa, FGS_FORGOT)[0]) { - if (lwsgs_handler_forgot_pw_form(vhd, wsi, pss)) { - n = FGS_FORGOT_BAD; - goto reg_done; - } - /* get the email monitor to take a look */ - lws_smtp_client_kick(vhd->smtp_client); - n = FGS_FORGOT_GOOD; - goto reg_done; - } - - if (!lws_spa_get_string(pss->spa, FGS_USERNAME) || - !lws_spa_get_string(pss->spa, FGS_PASSWORD)) { - lwsl_notice("username '%s' or pw '%s' missing\n", - lws_spa_get_string(pss->spa, FGS_USERNAME), - lws_spa_get_string(pss->spa, FGS_PASSWORD)); - return -1; - } - - if (lws_spa_get_string(pss->spa, FGS_REGISTER) && - lws_spa_get_string(pss->spa, FGS_REGISTER)[0]) { - - if (lwsgs_handler_register_form(vhd, wsi, pss)) - n = FGS_REG_BAD; - else { - n = FGS_REG_GOOD; - - /* get the email monitor to take a look */ - lws_smtp_client_kick(vhd->smtp_client); - } -reg_done: - lws_snprintf(pss->onward, sizeof(pss->onward), - "%s%s", vhd->urlroot, - lws_spa_get_string(pss->spa, n)); - - pss->login_expires = 0; - pss->logging_out = 1; - goto completion_flow; - } - - /* we have the username and password... check if admin */ - if (lwsgw_check_admin(vhd, lws_spa_get_string(pss->spa, FGS_USERNAME), - lws_spa_get_string(pss->spa, FGS_PASSWORD))) { - if (lws_spa_get_string(pss->spa, FGS_ADMIN)) - cp = lws_spa_get_string(pss->spa, FGS_ADMIN); - else - if (lws_spa_get_string(pss->spa, FGS_GOOD)) - cp = lws_spa_get_string(pss->spa, FGS_GOOD); - else { - lwsl_info("No admin or good target url in form\n"); - return -1; - } - lwsl_debug("admin\n"); - goto pass; - } - - /* check users in database */ - - if (!lwsgs_check_credentials(vhd, - lws_spa_get_string(pss->spa, FGS_USERNAME), - lws_spa_get_string(pss->spa, FGS_PASSWORD))) { - lwsl_notice("pw hash check met\n"); - cp = lws_spa_get_string(pss->spa, FGS_GOOD); - goto pass; - } else - lwsl_notice("user/password no good %s %s\n", - lws_spa_get_string(pss->spa, FGS_USERNAME), - lws_spa_get_string(pss->spa, FGS_PASSWORD)); - - if (!lws_spa_get_string(pss->spa, FGS_BAD)) { - lwsl_info("No admin or good target url in form\n"); - return -1; - } - - lws_snprintf(pss->onward, sizeof(pss->onward), - "%s%s", vhd->urlroot, - lws_spa_get_string(pss->spa, FGS_BAD)); - - lwsl_notice("failed: %s\n", pss->onward); - - goto completion_flow; - } - - if (!strcmp(cp1 + n - 12, "lwsgs-logout")) { - - lwsl_notice("/logout\n"); - - if (lwsgs_get_sid_from_wsi(wsi, &pss->login_session)) { - lwsl_notice("not logged in...\n"); - return 1; - } - - /* - * We keep the same session, but mark it as not - * being associated to any authenticated user - */ - - lwsgw_update_session(vhd, &pss->login_session, ""); - - if (!lws_spa_get_string(pss->spa, FGS_GOOD)) { - lwsl_info("No admin or good target url in form\n"); - return -1; - } - - lws_snprintf(pss->onward, sizeof(pss->onward), - "%s%s", vhd->urlroot, - lws_spa_get_string(pss->spa, FGS_GOOD)); - - pss->login_expires = 0; - pss->logging_out = 1; - - goto completion_flow; - } - - break; - -pass: - lws_snprintf(pss->onward, sizeof(pss->onward), - "%s%s", vhd->urlroot, cp); - - if (lwsgs_get_sid_from_wsi(wsi, &sid)) - sid.id[0] = '\0'; - - pss->login_expires = lws_now_secs() + - vhd->timeout_absolute_secs; - - if (!sid.id[0]) { - /* we need to create a new, authorized session */ - - if (lwsgs_new_session_id(vhd, &pss->login_session, - lws_spa_get_string(pss->spa, FGS_USERNAME), - pss->login_expires)) - goto try_to_reuse; - - lwsl_notice("Creating new session: %s\n", - pss->login_session.id); - } else { - /* - * we can just update the existing session to be - * authorized - */ - lwsl_notice("Authorizing existing session %s", sid.id); - lwsgw_update_session(vhd, &sid, - lws_spa_get_string(pss->spa, FGS_USERNAME)); - pss->login_session = sid; - } - -completion_flow: - lwsgw_expire_old_sessions(vhd); - goto redirect_with_cookie; - - case LWS_CALLBACK_HTTP_DROP_PROTOCOL: - if (pss && pss->spa) { - lws_spa_destroy(pss->spa); - pss->spa = NULL; - } - break; - - case LWS_CALLBACK_ADD_HEADERS: - lwsgw_expire_old_sessions(vhd); - - lwsl_warn("ADD_HEADERS\n"); - - args = (struct lws_process_html_args *)in; - if (!pss) - return 1; - if (pss->delete_session.id[0]) { - pc = cookie; - lwsgw_cookie_from_session(&pss->delete_session, 0, &pc, - cookie + sizeof(cookie) - 1); - - lwsl_notice("deleting cookie '%s'\n", cookie); - - if (lws_add_http_header_by_name(wsi, - (unsigned char *)"set-cookie:", - (unsigned char *)cookie, pc - cookie, - (unsigned char **)&args->p, - (unsigned char *)args->p + args->max_len)) - return 1; - } - - if (!pss->login_session.id[0]) - lwsgs_get_sid_from_wsi(wsi, &pss->login_session); - - if (!pss->login_session.id[0] && !pss->logging_out) { - - pss->login_expires = lws_now_secs() + - vhd->timeout_anon_absolute_secs; - if (lwsgs_new_session_id(vhd, &pss->login_session, "", - pss->login_expires)) - goto try_to_reuse; - pc = cookie; - lwsgw_cookie_from_session(&pss->login_session, - pss->login_expires, &pc, - cookie + sizeof(cookie) - 1); - - lwsl_info("LWS_CALLBACK_ADD_HEADERS: setting cookie '%s'\n", cookie); - if (lws_add_http_header_by_name(wsi, - (unsigned char *)"set-cookie:", - (unsigned char *)cookie, pc - cookie, - (unsigned char **)&args->p, - (unsigned char *)args->p + args->max_len)) - return 1; - } - break; - - default: - break; - } - - return 0; - -redirect_with_cookie: - p = buffer + LWS_PRE; - start = p; - end = p + sizeof(buffer) - LWS_PRE; - - lwsl_warn("%s: redirect_with_cookie\n", __func__); - - if (lws_add_http_header_status(wsi, HTTP_STATUS_SEE_OTHER, &p, end)) - return 1; - - { - char loc[1024], uria[128]; - - uria[0] = '\0'; - lws_hdr_copy_fragment(wsi, uria, sizeof(uria), - WSI_TOKEN_HTTP_URI_ARGS, 0); - n = lws_snprintf(loc, sizeof(loc), "%s?%s", - pss->onward, uria); - lwsl_notice("%s: redirect to '%s'\n", __func__, loc); - if (lws_add_http_header_by_token(wsi, WSI_TOKEN_HTTP_LOCATION, - (unsigned char *)loc, n, &p, end)) - return 1; - } - - if (lws_add_http_header_by_token(wsi, WSI_TOKEN_HTTP_CONTENT_TYPE, - (unsigned char *)"text/html", 9, &p, end)) - return 1; - if (lws_add_http_header_content_length(wsi, 0, &p, end)) - return 1; - - if (pss->delete_session.id[0]) { - lwsgw_cookie_from_session(&pss->delete_session, 0, &pc, - cookie + sizeof(cookie) - 1); - - lwsl_notice("deleting cookie '%s'\n", cookie); - - if (lws_add_http_header_by_name(wsi, - (unsigned char *)"set-cookie:", - (unsigned char *)cookie, pc - cookie, - &p, end)) { - lwsl_err("fail0\n"); - return 1; - } - } - - if (!pss->login_session.id[0]) { - pss->login_expires = lws_now_secs() + - vhd->timeout_anon_absolute_secs; - if (lwsgs_new_session_id(vhd, &pss->login_session, "", - pss->login_expires)) { - lwsl_err("fail1\n"); - return 1; - } - } else - pss->login_expires = lws_now_secs() + - vhd->timeout_absolute_secs; - - if (pss->login_session.id[0] || pss->logging_out) { - /* - * we succeeded to login, we must issue a login - * cookie with the prepared data - */ - pc = cookie; - - lwsgw_cookie_from_session(&pss->login_session, - pss->login_expires, &pc, - cookie + sizeof(cookie) - 1); - - lwsl_err("%s: setting cookie '%s'\n", __func__, cookie); - - pss->logging_out = 0; - - if (lws_add_http_header_by_name(wsi, - (unsigned char *)"set-cookie:", - (unsigned char *)cookie, pc - cookie, - &p, end)) { - lwsl_err("fail2\n"); - return 1; - } - } - - if (lws_finalize_http_header(wsi, &p, end)) - return 1; - - // lwsl_hexdump_notice(start, p - start); - - n = lws_write(wsi, start, p - start, LWS_WRITE_H2_STREAM_END | - LWS_WRITE_HTTP_HEADERS); - if (n < 0) - return 1; - - /* fallthru */ - -try_to_reuse: - if (lws_http_transaction_completed(wsi)) - return -1; - - return 0; -} - -static const struct lws_protocols protocols[] = { - { - "protocol-generic-sessions", - callback_generic_sessions, - sizeof(struct per_session_data__gs), - 1024, - }, -}; - -LWS_EXTERN LWS_VISIBLE int -init_protocol_generic_sessions(struct lws_context *context, - struct lws_plugin_capability *c) -{ - if (c->api_magic != LWS_PLUGIN_API_MAGIC) { - lwsl_err("Plugin API %d, library API %d", LWS_PLUGIN_API_MAGIC, - c->api_magic); - return 1; - } - - c->protocols = protocols; - c->count_protocols = LWS_ARRAY_SIZE(protocols); - c->extensions = NULL; - c->count_extensions = 0; - - return 0; -} - -LWS_EXTERN LWS_VISIBLE int -destroy_protocol_generic_sessions(struct lws_context *context) -{ - return 0; -} diff -Nru libwebsockets-3.2.1/plugins/generic-sessions/protocol_lws_messageboard.c libwebsockets-4.1.6/plugins/generic-sessions/protocol_lws_messageboard.c --- libwebsockets-3.2.1/plugins/generic-sessions/protocol_lws_messageboard.c 2019-12-18 14:45:31.000000000 +0000 +++ libwebsockets-4.1.6/plugins/generic-sessions/protocol_lws_messageboard.c 1970-01-01 00:00:00.000000000 +0000 @@ -1,434 +0,0 @@ -/* - * ws protocol handler plugin for messageboard "generic sessions" demo - * - * Copyright (C) 2010-2019 Andy Green - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation: - * version 2.1 of the License. - * - * This library is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * General Public License for more details. - * - * You should have received a copy of the GNU General Public - * License along with this library; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, - * MA 02110-1301 USA - */ - -#define LWS_DLL -#define LWS_INTERNAL -#include - -#include -#include -#include - -struct per_vhost_data__gs_mb { - struct lws_vhost *vh; - const struct lws_protocols *gsp; - sqlite3 *pdb; - char message_db[256]; - unsigned long last_idx; -}; - -struct per_session_data__gs_mb { - void *pss_gs; /* for use by generic-sessions */ - struct lws_session_info sinfo; - struct lws_spa *spa; - unsigned long last_idx; - unsigned int our_form:1; - char second_http_part; -}; - -static const char * const param_names[] = { - "send", - "msg", -}; -enum { - MBSPA_SUBMIT, - MBSPA_MSG, -}; - -#define MAX_MSG_LEN 512 - -struct message { - unsigned long idx; - unsigned long time; - char username[32]; - char email[100]; - char ip[72]; - char content[MAX_MSG_LEN]; -}; - -static int -lookup_cb(void *priv, int cols, char **col_val, char **col_name) -{ - struct message *m = (struct message *)priv; - int n; - - for (n = 0; n < cols; n++) { - - if (!strcmp(col_name[n], "idx") || - !strcmp(col_name[n], "MAX(idx)")) { - if (!col_val[n]) - m->idx = 0; - else - m->idx = atol(col_val[n]); - continue; - } - if (!strcmp(col_name[n], "time")) { - m->time = atol(col_val[n]); - continue; - } - if (!strcmp(col_name[n], "username")) { - lws_strncpy(m->username, col_val[n], sizeof(m->username)); - continue; - } - if (!strcmp(col_name[n], "email")) { - lws_strncpy(m->email, col_val[n], sizeof(m->email)); - continue; - } - if (!strcmp(col_name[n], "ip")) { - lws_strncpy(m->ip, col_val[n], sizeof(m->ip)); - continue; - } - if (!strcmp(col_name[n], "content")) { - lws_strncpy(m->content, col_val[n], sizeof(m->content)); - continue; - } - } - return 0; -} - -static unsigned long -get_last_idx(struct per_vhost_data__gs_mb *vhd) -{ - struct message m; - - if (sqlite3_exec(vhd->pdb, "SELECT MAX(idx) FROM msg;", - lookup_cb, &m, NULL) != SQLITE_OK) { - lwsl_err("Unable to lookup token: %s\n", - sqlite3_errmsg(vhd->pdb)); - return 0; - } - - return m.idx; -} - -static int -post_message(struct lws *wsi, struct per_vhost_data__gs_mb *vhd, - struct per_session_data__gs_mb *pss) -{ - struct lws_session_info sinfo; - char s[MAX_MSG_LEN + 512]; - char esc[MAX_MSG_LEN + 256]; - - vhd->gsp->callback(wsi, LWS_CALLBACK_SESSION_INFO, - pss->pss_gs, &sinfo, 0); - - lws_snprintf((char *)s, sizeof(s) - 1, - "insert into msg(time, username, email, ip, content)" - " values (%lu, '%s', '%s', '%s', '%s');", - (unsigned long)lws_now_secs(), sinfo.username, sinfo.email, sinfo.ip, - lws_sql_purify(esc, lws_spa_get_string(pss->spa, MBSPA_MSG), - sizeof(esc) - 1)); - if (sqlite3_exec(vhd->pdb, s, NULL, NULL, NULL) != SQLITE_OK) { - lwsl_err("Unable to insert msg: %s\n", sqlite3_errmsg(vhd->pdb)); - return 1; - } - vhd->last_idx = get_last_idx(vhd); - - /* let everybody connected by this protocol on this vhost know */ - lws_callback_on_writable_all_protocol_vhost(lws_get_vhost(wsi), - lws_get_protocol(wsi)); - - return 0; -} - -static int -callback_messageboard(struct lws *wsi, enum lws_callback_reasons reason, - void *user, void *in, size_t len) -{ - struct per_session_data__gs_mb *pss = (struct per_session_data__gs_mb *)user; - const struct lws_protocol_vhost_options *pvo; - struct per_vhost_data__gs_mb *vhd = (struct per_vhost_data__gs_mb *) - lws_protocol_vh_priv_get(lws_get_vhost(wsi), lws_get_protocol(wsi)); - unsigned char *p, *start, *end, buffer[LWS_PRE + 4096]; - char s[512]; - int n; - - switch (reason) { - case LWS_CALLBACK_PROTOCOL_INIT: /* per vhost */ - - vhd = lws_protocol_vh_priv_zalloc(lws_get_vhost(wsi), - lws_get_protocol(wsi), sizeof(struct per_vhost_data__gs_mb)); - if (!vhd) - return 1; - vhd->vh = lws_get_vhost(wsi); - vhd->gsp = lws_vhost_name_to_protocol(vhd->vh, - "protocol-generic-sessions"); - if (!vhd->gsp) { - lwsl_err("messageboard: requires generic-sessions\n"); - return 1; - } - - pvo = (const struct lws_protocol_vhost_options *)in; - while (pvo) { - if (!strcmp(pvo->name, "message-db")) - strncpy(vhd->message_db, pvo->value, - sizeof(vhd->message_db) - 1); - pvo = pvo->next; - } - if (!vhd->message_db[0]) { - lwsl_err("messageboard: \"message-db\" pvo missing\n"); - return 1; - } - - if (lws_struct_sq3_open(lws_get_context(wsi), - vhd->message_db, &vhd->pdb)) { - lwsl_err("Unable to open message db %s: %s\n", - vhd->message_db, sqlite3_errmsg(vhd->pdb)); - - return 1; - } - if (sqlite3_exec(vhd->pdb, "create table if not exists msg (" - " idx integer primary key, time integer," - " username varchar(32), email varchar(100)," - " ip varchar(80), content blob);", - NULL, NULL, NULL) != SQLITE_OK) { - lwsl_err("Unable to create msg table: %s\n", - sqlite3_errmsg(vhd->pdb)); - - return 1; - } - - vhd->last_idx = get_last_idx(vhd); - break; - - case LWS_CALLBACK_PROTOCOL_DESTROY: - if (vhd && vhd->pdb) - sqlite3_close(vhd->pdb); - goto passthru; - - case LWS_CALLBACK_ESTABLISHED: - vhd->gsp->callback(wsi, LWS_CALLBACK_SESSION_INFO, - pss->pss_gs, &pss->sinfo, 0); - if (!pss->sinfo.username[0]) { - lwsl_notice("messageboard ws attempt with no session\n"); - - return -1; - } - - lws_callback_on_writable(wsi); - break; - - case LWS_CALLBACK_CLOSED: - lwsl_debug("%s: LWS_CALLBACK_CLOSED\n", __func__); - if (pss && pss->pss_gs) { - free(pss->pss_gs); - pss->pss_gs = NULL; - } - break; - - case LWS_CALLBACK_SERVER_WRITEABLE: - { - struct message m; - char j[MAX_MSG_LEN + 512], e[MAX_MSG_LEN + 512], - *p = j + LWS_PRE, *start = p, - *end = j + sizeof(j) - LWS_PRE; - - if (pss->last_idx == vhd->last_idx) - break; - - /* restrict to last 10 */ - if (!pss->last_idx) - if (vhd->last_idx >= 10) - pss->last_idx = vhd->last_idx - 10; - - sprintf(s, "select idx, time, username, email, ip, content " - "from msg where idx > %lu order by idx limit 1;", - pss->last_idx); - if (sqlite3_exec(vhd->pdb, s, lookup_cb, &m, NULL) != SQLITE_OK) { - lwsl_err("Unable to lookup msg: %s\n", - sqlite3_errmsg(vhd->pdb)); - return 0; - } - - /* format in JSON */ - p += lws_snprintf(p, end - p, - "{\"idx\":\"%lu\",\"time\":\"%lu\",", - m.idx, m.time); - p += lws_snprintf(p, end - p, " \"username\":\"%s\",", - lws_json_purify(e, m.username, sizeof(e))); - p += lws_snprintf(p, end - p, " \"email\":\"%s\",", - lws_json_purify(e, m.email, sizeof(e))); - p += lws_snprintf(p, end - p, " \"ip\":\"%s\",", - lws_json_purify(e, m.ip, sizeof(e))); - p += lws_snprintf(p, end - p, " \"content\":\"%s\"}", - lws_json_purify(e, m.content, sizeof(e))); - - if (lws_write(wsi, (unsigned char *)start, p - start, - LWS_WRITE_TEXT) < 0) - return -1; - - pss->last_idx = m.idx; - if (pss->last_idx == vhd->last_idx) - break; - - lws_callback_on_writable(wsi); /* more to do */ - } - break; - - case LWS_CALLBACK_HTTP: - pss->our_form = 0; - - /* ie, it's our messageboard new message form */ - if (!strcmp((const char *)in, "/msg") || - !strcmp((const char *)in, "msg")) { - pss->our_form = 1; - break; - } - - goto passthru; - - case LWS_CALLBACK_HTTP_BODY: - if (!pss->our_form) - goto passthru; - - if (len < 2) - break; - if (!pss->spa) { - pss->spa = lws_spa_create(wsi, param_names, - LWS_ARRAY_SIZE(param_names), - MAX_MSG_LEN + 1024, NULL, NULL); - if (!pss->spa) - return -1; - } - - if (lws_spa_process(pss->spa, in, len)) { - lwsl_notice("spa process blew\n"); - return -1; - } - break; - - case LWS_CALLBACK_HTTP_WRITEABLE: - if (!pss->second_http_part) - goto passthru; - - s[0] = '0'; - n = lws_write(wsi, (unsigned char *)s, 1, LWS_WRITE_HTTP| - LWS_WRITE_H2_STREAM_END); - if (n != 1) - return -1; - - goto try_to_reuse; - - case LWS_CALLBACK_HTTP_BODY_COMPLETION: - if (!pss->our_form) - goto passthru; - - if (post_message(wsi, vhd, pss)) - return -1; - - p = buffer + LWS_PRE; - start = p; - end = p + sizeof(buffer) - LWS_PRE; - - if (lws_add_http_header_status(wsi, HTTP_STATUS_OK, &p, end)) - return -1; - if (lws_add_http_header_by_token(wsi, WSI_TOKEN_HTTP_CONTENT_TYPE, - (unsigned char *)"text/plain", 10, &p, end)) - return -1; - if (lws_add_http_header_content_length(wsi, 1, &p, end)) - return -1; - if (lws_finalize_http_header(wsi, &p, end)) - return -1; - - n = lws_write(wsi, start, p - start, LWS_WRITE_HTTP_HEADERS); - if (n != (p - start)) { - lwsl_err("_write returned %d from %ld\n", n, (long)(p - start)); - return -1; - } - pss->second_http_part = 1; - lws_callback_on_writable(wsi); - break; - - case LWS_CALLBACK_HTTP_BIND_PROTOCOL: - if (!pss || !vhd || pss->pss_gs) - break; - - pss->pss_gs = malloc(vhd->gsp->per_session_data_size); - if (!pss->pss_gs) - return -1; - - memset(pss->pss_gs, 0, vhd->gsp->per_session_data_size); - break; - - case LWS_CALLBACK_HTTP_DROP_PROTOCOL: - if (vhd->gsp->callback(wsi, reason, pss ? pss->pss_gs : NULL, in, len)) - return -1; - - if (pss && pss->spa) { - lws_spa_destroy(pss->spa); - pss->spa = NULL; - } - if (pss && pss->pss_gs) { - free(pss->pss_gs); - pss->pss_gs = NULL; - } - break; - - default: -passthru: - if (!pss || !vhd) - break; - - return vhd->gsp->callback(wsi, reason, pss->pss_gs, in, len); - } - - return 0; - - -try_to_reuse: - if (lws_http_transaction_completed(wsi)) - return -1; - - return 0; -} - -static const struct lws_protocols protocols[] = { - { - "protocol-lws-messageboard", - callback_messageboard, - sizeof(struct per_session_data__gs_mb), - 4096, - }, -}; - -LWS_EXTERN LWS_VISIBLE int -init_protocol_lws_messageboard(struct lws_context *context, - struct lws_plugin_capability *c) -{ - if (c->api_magic != LWS_PLUGIN_API_MAGIC) { - lwsl_err("Plugin API %d, library API %d", LWS_PLUGIN_API_MAGIC, - c->api_magic); - return 1; - } - - c->protocols = protocols; - c->count_protocols = LWS_ARRAY_SIZE(protocols); - c->extensions = NULL; - c->count_extensions = 0; - - return 0; -} - -LWS_EXTERN LWS_VISIBLE int -destroy_protocol_lws_messageboard(struct lws_context *context) -{ - return 0; -} diff -Nru libwebsockets-3.2.1/plugins/generic-sessions/utils.c libwebsockets-4.1.6/plugins/generic-sessions/utils.c --- libwebsockets-3.2.1/plugins/generic-sessions/utils.c 2019-12-18 14:45:31.000000000 +0000 +++ libwebsockets-4.1.6/plugins/generic-sessions/utils.c 1970-01-01 00:00:00.000000000 +0000 @@ -1,462 +0,0 @@ -/* - * ws protocol handler plugin for "generic sessions" - * - * Copyright (C) 2010-2016 Andy Green - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation: - * version 2.1 of the License. - * - * This library is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * General Public License for more details. - * - * You should have received a copy of the GNU General Public - * License along with this library; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, - * MA 02110-1301 USA - */ - -#include "private-lwsgs.h" -#include - -void -sha256_to_lwsgw_hash(unsigned char *hash, lwsgw_hash *shash) -{ - static const char *hex = "0123456789abcdef"; - char *p = shash->id; - int n; - - for (n = 0; n < (int)lws_genhash_size(LWS_GENHASH_TYPE_SHA256); n++) { - *p++ = hex[(hash[n] >> 4) & 0xf]; - *p++ = hex[hash[n] & 15]; - } - - *p = '\0'; -} - -int -lwsgw_check_admin(struct per_vhost_data__gs *vhd, - const char *username, const char *password) -{ - lwsgw_hash_bin hash_bin; - lwsgw_hash pw_hash; - - if (strcmp(vhd->admin_user, username)) - return 0; - - lws_SHA1((unsigned char *)password, strlen(password), hash_bin.bin); - sha256_to_lwsgw_hash(hash_bin.bin, &pw_hash); - - return !strcmp(vhd->admin_password_sha256.id, pw_hash.id); -} - -/* - * secure cookie: it can only be passed over https where it cannot be - * snooped in transit - * HttpOnly: it can only be accessed via http[s] transport, it cannot be - * gotten at by JS - */ -void -lwsgw_cookie_from_session(lwsgw_hash *sid, time_t expires, char **p, char *end) -{ - struct tm *tm = gmtime(&expires); - time_t n = lws_now_secs(); - - *p += lws_snprintf(*p, end - *p, "id=%s;Expires=", sid->id); -#ifdef WIN32 - *p += strftime(*p, end - *p, "%Y %H:%M %Z", tm); -#else - *p += strftime(*p, end - *p, "%F %H:%M %Z", tm); -#endif - *p += lws_snprintf(*p, end - *p, ";path=/"); - *p += lws_snprintf(*p, end - *p, ";Max-Age=%lu", (unsigned long)(expires - n)); -// *p += lws_snprintf(*p, end - *p, ";secure"); - *p += lws_snprintf(*p, end - *p, ";HttpOnly"); -} - -int -lwsgw_expire_old_sessions(struct per_vhost_data__gs *vhd) -{ - time_t n = lws_now_secs(); - char s[200]; - - if (n - vhd->last_session_expire < 5) - return 0; - - vhd->last_session_expire = n; - - lws_snprintf(s, sizeof(s) - 1, - "delete from sessions where " - "expire <= %lu;", (unsigned long)n); - - if (sqlite3_exec(vhd->pdb, s, NULL, NULL, NULL) != SQLITE_OK) { - lwsl_err("Unable to expire sessions: %s\n", - sqlite3_errmsg(vhd->pdb)); - return 1; - } - - return 0; -} - -int -lwsgw_update_session(struct per_vhost_data__gs *vhd, - lwsgw_hash *hash, const char *user) -{ - time_t n = lws_now_secs(); - char s[200], esc[96], esc1[96]; - - if (user[0]) - n += vhd->timeout_absolute_secs; - else - n += vhd->timeout_anon_absolute_secs; - - lws_snprintf(s, sizeof(s) - 1, - "update sessions set expire=%lu,username='%s' where name='%s';", - (unsigned long)n, - lws_sql_purify(esc, user, sizeof(esc)), - lws_sql_purify(esc1, hash->id, sizeof(esc1))); - - if (sqlite3_exec(vhd->pdb, s, NULL, NULL, NULL) != SQLITE_OK) { - lwsl_err("Unable to update session: %s\n", - sqlite3_errmsg(vhd->pdb)); - return 1; - } - - puts(s); - - return 0; -} - -static int -lwsgw_session_from_cookie(const char *cookie, lwsgw_hash *sid) -{ - const char *p = cookie; - int n; - - while (*p) { - if (p[0] == 'i' && p[1] == 'd' && p[2] == '=') { - p += 3; - break; - } - p++; - } - if (!*p) { - lwsl_info("no id= in cookie\n"); - return 1; - } - - for (n = 0; n < (int)sizeof(sid->id) - 1 && *p; n++) { - /* our SID we issue only has these chars */ - if ((*p >= '0' && *p <= '9') || - (*p >= 'a' && *p <= 'f')) - sid->id[n] = *p++; - else { - lwsl_info("bad chars in cookie id %c\n", *p); - return 1; - } - } - - if (n < (int)sizeof(sid->id) - 1) { - lwsl_info("cookie id too short\n"); - return 1; - } - - sid->id[sizeof(sid->id) - 1] = '\0'; - - return 0; -} - -int -lwsgs_get_sid_from_wsi(struct lws *wsi, lwsgw_hash *sid) -{ - char cookie[1024]; - - /* fail it on no cookie */ - if (!lws_hdr_total_length(wsi, WSI_TOKEN_HTTP_COOKIE)) { - lwsl_info("%s: no cookie\n", __func__); - return 1; - } - if (lws_hdr_copy(wsi, cookie, sizeof cookie, WSI_TOKEN_HTTP_COOKIE) < 0) { - lwsl_info("cookie copy failed\n"); - return 1; - } - /* extract the sid from the cookie */ - if (lwsgw_session_from_cookie(cookie, sid)) { - lwsl_info("%s: session from cookie failed\n", __func__); - return 1; - } - - return 0; -} - -struct lla { - char *username; - int len; - int results; -}; - -static int -lwsgs_lookup_callback(void *priv, int cols, char **col_val, char **col_name) -{ - struct lla *lla = (struct lla *)priv; - - //lwsl_err("%s: %d\n", __func__, cols); - - if (cols) - lla->results = 0; - if (col_val && col_val[0]) { - lws_strncpy(lla->username, col_val[0], lla->len + 1); - lwsl_info("%s: %s\n", __func__, lla->username); - } - - return 0; -} - -int -lwsgs_lookup_session(struct per_vhost_data__gs *vhd, - const lwsgw_hash *sid, char *username, int len) -{ - struct lla lla = { username, len, 1 }; - char s[150], esc[96]; - - lwsgw_expire_old_sessions(vhd); - - lws_snprintf(s, sizeof(s) - 1, - "select username from sessions where name = '%s';", - lws_sql_purify(esc, sid->id, sizeof(esc) - 1)); - - if (sqlite3_exec(vhd->pdb, s, lwsgs_lookup_callback, &lla, NULL) != SQLITE_OK) { - lwsl_err("Unable to create user table: %s\n", - sqlite3_errmsg(vhd->pdb)); - - return 1; - } - - /* 0 if found */ - return lla.results; -} - -int -lwsgs_lookup_callback_user(void *priv, int cols, char **col_val, char **col_name) -{ - struct lwsgs_user *u = (struct lwsgs_user *)priv; - int n; - - for (n = 0; n < cols; n++) { - if (!strcmp(col_name[n], "username")) { - lws_strncpy(u->username, col_val[n], sizeof(u->username)); - continue; - } - if (!strcmp(col_name[n], "ip")) { - lws_strncpy(u->ip, col_val[n], sizeof(u->ip)); - continue; - } - if (!strcmp(col_name[n], "creation_time")) { - u->created = atol(col_val[n]); - continue; - } - if (!strcmp(col_name[n], "last_forgot_validated")) { - if (col_val[n]) - u->last_forgot_validated = atol(col_val[n]); - else - u->last_forgot_validated = 0; - continue; - } - if (!strcmp(col_name[n], "email")) { - lws_strncpy(u->email, col_val[n], sizeof(u->email)); - continue; - } - if (!strcmp(col_name[n], "verified")) { - u->verified = atoi(col_val[n]); - continue; - } - if (!strcmp(col_name[n], "pwhash")) { - lws_strncpy(u->pwhash.id, col_val[n], sizeof(u->pwhash.id)); - continue; - } - if (!strcmp(col_name[n], "pwsalt")) { - lws_strncpy(u->pwsalt.id, col_val[n], sizeof(u->pwsalt.id)); - continue; - } - if (!strcmp(col_name[n], "token")) { - lws_strncpy(u->token.id, col_val[n], sizeof(u->token.id)); - continue; - } - } - return 0; -} - -int -lwsgs_lookup_user(struct per_vhost_data__gs *vhd, - const char *username, struct lwsgs_user *u) -{ - char s[150], esc[96]; - - u->username[0] = '\0'; - lws_snprintf(s, sizeof(s) - 1, - "select username,creation_time,ip,email,verified,pwhash,pwsalt,last_forgot_validated " - "from users where username = '%s';", - lws_sql_purify(esc, username, sizeof(esc) - 1)); - - if (sqlite3_exec(vhd->pdb, s, lwsgs_lookup_callback_user, u, NULL) != - SQLITE_OK) { - lwsl_err("Unable to lookup user: %s\n", - sqlite3_errmsg(vhd->pdb)); - - return -1; - } - - return !u->username[0]; -} - -int -lwsgs_new_session_id(struct per_vhost_data__gs *vhd, - lwsgw_hash *sid, const char *username, int exp) -{ - unsigned char sid_rand[32]; - const char *u; - char s[300], esc[96], esc1[96]; - - if (username) - u = username; - else - u = ""; - - if (!sid) { - lwsl_err("%s: NULL sid\n", __func__); - return 1; - } - - memset(sid, 0, sizeof(*sid)); - - if (lws_get_random(vhd->context, sid_rand, sizeof(sid_rand)) != - sizeof(sid_rand)) - return 1; - - sha256_to_lwsgw_hash(sid_rand, sid); - - lws_snprintf(s, sizeof(s) - 1, - "insert into sessions(name, username, expire) " - "values ('%s', '%s', %u);", - lws_sql_purify(esc, sid->id, sizeof(esc) - 1), - lws_sql_purify(esc1, u, sizeof(esc1) - 1), exp); - - if (sqlite3_exec(vhd->pdb, s, NULL, NULL, NULL) != SQLITE_OK) { - lwsl_err("Unable to insert session: %s\n", - sqlite3_errmsg(vhd->pdb)); - - return 1; - } - - lwsl_notice("%s: created session %s\n", __func__, sid->id); - - return 0; -} - -int -lwsgs_get_auth_level(struct per_vhost_data__gs *vhd, const char *username) -{ - struct lwsgs_user u; - int n = 0; - - /* we are logged in as some kind of user */ - if (username[0]) { - /* we are logged in as admin */ - if (!strcmp(username, vhd->admin_user)) - /* automatically verified */ - n |= LWSGS_AUTH_VERIFIED | LWSGS_AUTH_ADMIN; - } - - if (!lwsgs_lookup_user(vhd, username, &u)) { - if ((u.verified & 0xff) == LWSGS_VERIFIED_ACCEPTED) - n |= LWSGS_AUTH_LOGGED_IN | LWSGS_AUTH_VERIFIED; - - if (u.last_forgot_validated > (time_t)lws_now_secs() - 300) - n |= LWSGS_AUTH_FORGOT_FLOW; - } - - return n; -} - -int -lwsgs_check_credentials(struct per_vhost_data__gs *vhd, - const char *username, const char *password) -{ - struct lws_genhash_ctx hash_ctx; - lwsgw_hash_bin hash_bin; - struct lwsgs_user u; - lwsgw_hash hash; - - if (lwsgs_lookup_user(vhd, username, &u)) - return -1; - - lwsl_info("user %s found, salt '%s'\n", username, u.pwsalt.id); - - /* sha256sum of password + salt */ - - if (lws_genhash_init(&hash_ctx, LWS_GENHASH_TYPE_SHA256) || - lws_genhash_update(&hash_ctx, password, strlen(password)) || - lws_genhash_update(&hash_ctx, "-", 1) || - lws_genhash_update(&hash_ctx, vhd->confounder, strlen(vhd->confounder)) || - lws_genhash_update(&hash_ctx, "-", 1) || - lws_genhash_update(&hash_ctx, u.pwsalt.id, strlen(u.pwsalt.id)) || - lws_genhash_destroy(&hash_ctx, hash_bin.bin)) { - lws_genhash_destroy(&hash_ctx, NULL); - - return 1; - } - - sha256_to_lwsgw_hash(&hash_bin.bin[0], &hash); - - return !!strcmp(hash.id, u.pwhash.id); -} - -/* sets u->pwsalt and u->pwhash */ - -int -lwsgs_hash_password(struct per_vhost_data__gs *vhd, - const char *password, struct lwsgs_user *u) -{ - unsigned char sid_rand[32]; - struct lws_genhash_ctx hash_ctx; - lwsgw_hash_bin hash_bin; - - /* create a random salt as big as the hash */ - - if (lws_get_random(vhd->context, sid_rand, - sizeof(sid_rand)) != - sizeof(sid_rand)) { - lwsl_err("Problem getting random for salt\n"); - return 1; - } - sha256_to_lwsgw_hash(sid_rand, &u->pwsalt); -/* - if (lws_get_random(vhd->context, sid_rand, - sizeof(sid_rand)) != - sizeof(sid_rand)) { - lwsl_err("Problem getting random for token\n"); - return 1; - } - sha256_to_lwsgw_hash(sid_rand, &hash); -*/ - /* sha256sum of password + salt */ - - if (lws_genhash_init(&hash_ctx, LWS_GENHASH_TYPE_SHA256) || - lws_genhash_update(&hash_ctx, password, strlen(password)) || - lws_genhash_update(&hash_ctx, "-", 1) || - lws_genhash_update(&hash_ctx, vhd->confounder, strlen(vhd->confounder)) || - lws_genhash_update(&hash_ctx, "-", 1) || - lws_genhash_update(&hash_ctx, u->pwsalt.id, strlen(u->pwsalt.id)) || - lws_genhash_destroy(&hash_ctx, hash_bin.bin)) { - lws_genhash_destroy(&hash_ctx, NULL); - - return 1; - } - - sha256_to_lwsgw_hash(&hash_bin.bin[0], &u->pwhash); - - return 0; -} diff -Nru libwebsockets-3.2.1/plugins/generic-table/assets/index.html libwebsockets-4.1.6/plugins/generic-table/assets/index.html --- libwebsockets-3.2.1/plugins/generic-table/assets/index.html 2019-12-18 14:45:31.000000000 +0000 +++ libwebsockets-4.1.6/plugins/generic-table/assets/index.html 1970-01-01 00:00:00.000000000 +0000 @@ -1,75 +0,0 @@ - - - - - - - - - - - - - -
- LWS Generic Table demo -
- This is a demo of lws generic table, using a protocol plugin - "protocol-lws-table-dirlisting". It shows a directory listing, - but unlike an oldstyle directory listing done on the - server side with a script, this is static html that connects - back to the server with a websocket, and gets live JSON from - that. -

- Actually the static html is extremely simple, since it uses - lwsgt, LWS Generic Table, JS include on the client-side that - handles all the table generation from a template sent in JSON - over the ws link. It means there is no custom JS required - clientside either. It's just CSS, this text and a call to - initialize lwsgt with the appropriate ws protocol. -

- There's no problem having multiple independent instances per - page... -
-

- - - - diff -Nru libwebsockets-3.2.1/plugins/generic-table/assets/lwsgt.js libwebsockets-4.1.6/plugins/generic-table/assets/lwsgt.js --- libwebsockets-3.2.1/plugins/generic-table/assets/lwsgt.js 2019-12-18 14:45:31.000000000 +0000 +++ libwebsockets-4.1.6/plugins/generic-table/assets/lwsgt.js 1970-01-01 00:00:00.000000000 +0000 @@ -1,142 +0,0 @@ -function lwsgt_get_appropriate_ws_url() -{ - var pcol; - var u = document.URL; - - if (u.substring(0, 5) === "https") { - pcol = "wss://"; - u = u.substr(8); - } else { - pcol = "ws://"; - if (u.substring(0, 4) === "http") - u = u.substr(7); - } - - return pcol + u; -} - -function lwsgt_app_hdr(j, bc, ws) -{ - var s = "", n, m = 0; - - ws.bcq = 0; - - for (n = 0; n < j.cols.length; n++) - if (!j.cols[n].hide) - m++; - - s = "" + - ws.lwsgt_title + ""; - - if (!!bc) { - s += ""; - for (n = 0; n < bc.length; n++) { - s += " / "; - if (!bc[n].url && bc[n].url !== "") - s += " " + lws_san(bc[n].name) + " "; - else { - s += "" + - lws_san(bc[n].name) + " "; - ws.bcq++; - } - } - s += ""; - } - s += ""; - for (n = 0; n < j.cols.length; n++) - if (!j.cols[n].hide) - s = s + "" + lws_san(j.cols[n].name) + - ""; - - s += ""; - - return s; -} - -function lwsgt_click_callthru() -{ - window[this.getAttribute("h")](this.getAttribute("p"), this.getAttribute("aa"), this.getAttribute("m"), this.getAttribute("n")); - event.preventDefault(); -} - -function lwsgt_initial(title, pcol, divname, cb, gname) -{ - this.divname = divname; - - lws_gray_out(true,{"zindex":"499"}); - - if (typeof MozWebSocket != "undefined") - this.lwsgt_ws = new MozWebSocket(lwsgt_get_appropriate_ws_url(), pcol); - else - this.lwsgt_ws = new WebSocket(lwsgt_get_appropriate_ws_url(), pcol); - this.lwsgt_ws.divname = divname; - this.lwsgt_ws.lwsgt_cb = cb; - this.lwsgt_ws.lwsgt_parent = gname; - this.lwsgt_ws.lwsgt_title = title; - try { - this.lwsgt_ws.onopen = function() { - lws_gray_out(false); - // document.getElementById("debug").textContent = - // "ws opened " + lwsgt_get_appropriate_ws_url(); - }; - this.lwsgt_ws.onmessage = function got_packet(msg) { - var s, m, n, j = JSON.parse(msg.data); - document.getElementById("debug").textContent = msg.data; - if (j.cols) { - this.hdr = j; - } - if (j.breadcrumbs) - this.breadcrumbs = j.breadcrumbs; - - if (j.data) { - var q = 0; - s = "" + - lwsgt_app_hdr(this.hdr, this.breadcrumbs, this); - for (m = 0; m < j.data.length; m++) { - s = s + ""; - for (n = 0; n < this.hdr.cols.length; n++) { - if (!this.hdr.cols[n].hide) { - if (!this.hdr.cols[n].align) - s = s + ""; - } - } - - s = s + ""; - } - s = s + "
"; - else - s = s + ""; - - if (this.hdr.cols[n].href && - !!j.data[m][this.hdr.cols[n].href]) { - s = s + "" + - lws_san(j.data[m][this.hdr.cols[n].name]) + - ""; - q++; - } - else - s = s + lws_san(j.data[m][this.hdr.cols[n].name]); - - s = s + "
"; - document.getElementById(this.divname).innerHTML = s; - for (n = 0; n < q; n++) - document.getElementById(this.divname + n).onclick = - lwsgt_click_callthru; - - for (n = 0; n < this.bcq; n++) - document.getElementById("bc_" + this.divname + n).onclick = - lwsgt_click_callthru; - - } - }; - this.lwsgt_ws.onclose = function(){ - lws_gray_out(true,{"zindex":"499"}); - }; - } catch(exception) { - alert("

Error" + exception); - } -} - diff -Nru libwebsockets-3.2.1/plugins/generic-table/protocol_table_dirlisting.c libwebsockets-4.1.6/plugins/generic-table/protocol_table_dirlisting.c --- libwebsockets-3.2.1/plugins/generic-table/protocol_table_dirlisting.c 2019-12-18 14:45:31.000000000 +0000 +++ libwebsockets-4.1.6/plugins/generic-table/protocol_table_dirlisting.c 1970-01-01 00:00:00.000000000 +0000 @@ -1,394 +0,0 @@ -/* - * ws protocol handler plugin for dirlisting "generic table" demo - * - * Copyright (C) 2010-2016 Andy Green - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation: - * version 2.1 of the License. - * - * This library is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * General Public License for more details. - * - * You should have received a copy of the GNU General Public - * License along with this library; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, - * MA 02110-1301 USA - */ - -#define LWS_DLL -#define LWS_INTERNAL -#include - -#include -#include -#include - -struct fobj { - struct fobj *next; - const char *name, *uri, *icon, *date; - time_t m; - unsigned long size; -}; - -struct per_session_data__tbl_dir { - struct fobj base; - char strings[64 * 1024]; - char reldir[256]; - char *p; - const char *dir; - -#if UV_VERSION_MAJOR > 0 - uv_fs_event_t *event_req; -#endif - struct lws *wsi; -}; - -#if UV_VERSION_MAJOR > 0 -static void -mon_cb(uv_fs_event_t *handle, const char *filename, int events, int status) -{ - struct per_session_data__tbl_dir *pss = handle->data; - - //lwsl_notice("%s\n", __func__); - - if (pss && pss->wsi) - lws_callback_on_writable(pss->wsi); -} - -static void lws_uv_close_cb(uv_handle_t *handle) -{ - free(handle); -} - -static void -lws_protocol_dir_kill_monitor(struct per_session_data__tbl_dir *pss) -{ - if (!pss->event_req) - return; - pss->wsi = NULL; - pss->event_req->data = NULL; - uv_fs_event_stop(pss->event_req); - uv_close((uv_handle_t *)pss->event_req, lws_uv_close_cb); - pss->event_req = NULL; -} -#endif - -static int -scan_dir(struct lws *wsi, struct per_session_data__tbl_dir *pss) -{ -/* uuh travis... */ -#if UV_VERSION_MAJOR > 0 - uv_loop_t *loop = lws_uv_getloop(lws_get_context(wsi), 0); - char *end = &(pss->strings[sizeof(pss->strings) - 1]); - struct fobj *prev = &pss->base; - char path[512], da[200]; - const char *icon; - uv_dirent_t dent; - struct fobj *f; - struct stat st; - struct tm *tm; - int ret = 0, n; - uv_fs_t req; - - lws_protocol_dir_kill_monitor(pss); - - lws_snprintf(path, sizeof(path) - 1, "%s/%s", pss->dir, pss->reldir); - //lwsl_notice("path = %s\n", path); - - pss->event_req = malloc(sizeof(*pss->event_req)); - if (!pss->event_req) - return 2; - - pss->wsi = wsi; - pss->event_req->data = pss; - - uv_fs_event_init(lws_uv_getloop(lws_get_context(wsi), 0), - pss->event_req); - // The recursive flag watches subdirectories too. - n = uv_fs_event_start(pss->event_req, mon_cb, path, UV_FS_EVENT_RECURSIVE); - //lwsl_notice("monitoring %s (%d)\n", path, n); - - if (!uv_fs_scandir(loop, &req, path, 0, NULL)) { - lwsl_err("Scandir on %s failed\n", path); - return 2; - } - - pss->p = pss->strings; - - while (uv_fs_scandir_next(&req, &dent) != UV_EOF) { - lws_snprintf(path, sizeof(path) - 1, "%s/%s/%s", pss->dir, pss->reldir, dent.name); - - if (stat(path, &st)) { - lwsl_info("unable to stat %s\n", path); - continue; - } - f = malloc(sizeof(*f)); - f->next = NULL; - f->name = pss->p; - n = lws_snprintf(pss->p, end - pss->p, "%s", dent.name); - pss->p += n + 1; - f->uri = NULL; - if ((S_IFMT & st.st_mode) == S_IFDIR) { - n = lws_snprintf(pss->p, end - pss->p, "=%s/%s", pss->reldir, dent.name); - f->uri = pss->p; - } - if (lws_get_mimetype(dent.name, NULL)) { - n = lws_snprintf(pss->p, end - pss->p, "./serve/%s/%s", pss->reldir, dent.name); - f->uri = pss->p; - } - if (f->uri) - pss->p += n + 1; - - if (end - pss->p < 100) { - free(f); - break; - } - - icon = " "; - if ((S_IFMT & st.st_mode) == S_IFDIR) - icon = "📂"; - - f->icon = pss->p; - n = lws_snprintf(pss->p, end - pss->p, "%s", icon); - pss->p += n + 1; - - f->date = pss->p; - tm = gmtime(&st.st_mtime); - strftime(da, sizeof(da), "%Y-%b-%d %H:%M:%S %z", tm); - n = lws_snprintf(pss->p, end - pss->p, "%s", da); - pss->p += n + 1; - - f->size = st.st_size; - f->m = st.st_mtime; - prev->next = f; - prev = f; - } - - uv_fs_req_cleanup(&req); - - return ret; -#else - return 0; -#endif -} - -static void -free_scan_dir(struct per_session_data__tbl_dir *pss) -{ - struct fobj *f = pss->base.next, *f1; - - while (f) { - f1 = f->next; - free(f); - f = f1; - } - - pss->base.next = NULL; -} - -static int -callback_lws_table_dirlisting(struct lws *wsi, enum lws_callback_reasons reason, - void *user, void *in, size_t len) -{ - struct per_session_data__tbl_dir *pss = (struct per_session_data__tbl_dir *)user; - char j[LWS_PRE + 16384], *p = j + LWS_PRE, *start = p, *q, *q1, *w, - *end = j + sizeof(j) - LWS_PRE, e[384], s[384], s1[384]; - const struct lws_protocol_vhost_options *pmo; - struct fobj *f; - int n, first = 1; - - switch (reason) { - case LWS_CALLBACK_PROTOCOL_INIT: /* per vhost */ - break; - - case LWS_CALLBACK_ESTABLISHED: - lwsl_debug("LWS_CALLBACK_ESTABLISHED\n"); - /* - * send client the lwsgt table layout - */ - start = "{\"cols\":[" - " {\"name\": \"Date\"}," - " {\"name\": \"Size\", \"align\": \"right\"}," - " {\"name\": \"Icon\"}," - " {\"name\": \"Name\", \"href\": \"uri\"}," - " {\"name\": \"uri\", \"hide\": \"1\" }" - " ]" - "}"; - if (lws_write(wsi, (unsigned char *)start, strlen(start), - LWS_WRITE_TEXT) < 0) - return -1; - - /* send a view update next */ - lws_callback_on_writable(wsi); - break; - - case LWS_CALLBACK_RECEIVE: - if (len > sizeof(pss->reldir) - 1) - len = sizeof(pss->reldir) - 1; - if (!strstr(in, "..") && !strchr(in, '~')) - lws_strncpy(pss->reldir, in, len + 1); - else - len = 0; - pss->reldir[len] = '\0'; - if (pss->reldir[0] == '/' && !pss->reldir[1]) - pss->reldir[0] = '\0'; - lwsl_info("%s\n", pss->reldir); - lws_callback_on_writable(wsi); - break; - - case LWS_CALLBACK_SERVER_WRITEABLE: - - if (scan_dir(wsi, pss)) - return 1; - - p += lws_snprintf(p, end - p, "{\"breadcrumbs\":["); - q = pss->reldir; - - if (!q[0]) - p += lws_snprintf(p, end - p, "{\"name\":\"top\"}"); - - while (*q) { - - q1 = strchr(q, '/'); - if (!q1) { - if (first) - strcpy(s, "top1"); - else - strcpy(s, q); - s1[0] = '\0'; - q += strlen(q); - } else { - n = lws_ptr_diff(q1, q); - if (n > (int)sizeof(s) - 1) - n = sizeof(s) - 1; - if (first) { - strcpy(s1, "/"); - strcpy(s, "top"); - } else { - lws_strncpy(s, q, n + 1); - - n = lws_ptr_diff(q1, pss->reldir); - if (n > (int)sizeof(s1) - 1) - n = sizeof(s1) - 1; - lws_strncpy(s1, pss->reldir, n + 1); - } - q = q1 + 1; - } - if (!first) - p += lws_snprintf(p, end - p, ","); - else - first = 0; - - p += lws_snprintf(p, end - p, "{\"name\":\"%s\"", - lws_json_purify(e, s, sizeof(e))); - if (*q) { - w = s1; - while (w[0] == '/' && w[1] == '/') - w++; - p += lws_snprintf(p, end - p, ",\"url\":\"%s\"", - lws_json_purify(e, w, sizeof(e))); - } - p += lws_snprintf(p, end - p, "}"); - if (!q1) - break; - } - - p += lws_snprintf(p, end - p, "],\"data\":["); - - f = pss->base.next; - while (f) { - /* format in JSON */ - p += lws_snprintf(p, end - p, "{\"Icon\":\"%s\",", - lws_json_purify(e, f->icon, sizeof(e))); - p += lws_snprintf(p, end - p, " \"Date\":\"%s\",", - lws_json_purify(e, f->date, sizeof(e))); - p += lws_snprintf(p, end - p, " \"Size\":\"%ld\",", - f->size); - if (f->uri) - p += lws_snprintf(p, end - p, " \"uri\":\"%s\",", - lws_json_purify(e, f->uri, sizeof(e))); - p += lws_snprintf(p, end - p, " \"Name\":\"%s\"}", - lws_json_purify(e, f->name, sizeof(e))); - - f = f->next; - - if (f) - p += lws_snprintf(p, end - p, ","); - } - - p += lws_snprintf(p, end - p, "]}"); - - free_scan_dir(pss); - - if (lws_write(wsi, (unsigned char *)start, p - start, - LWS_WRITE_TEXT) < 0) - return -1; - - break; - - case LWS_CALLBACK_HTTP_PMO: - /* find the per-mount options we're interested in */ - lwsl_debug("LWS_CALLBACK_HTTP_PMO\n"); - pmo = (struct lws_protocol_vhost_options *)in; - while (pmo) { - if (!strcmp(pmo->name, "dir")) /* path to list files */ - pss->dir = pmo->value; - pmo = pmo->next; - } - if (!pss->dir[0]) { - lwsl_err("dirlisting: \"dir\" pmo missing\n"); - return 1; - } - break; - - case LWS_CALLBACK_HTTP_DROP_PROTOCOL: - //lwsl_notice("LWS_CALLBACK_HTTP_DROP_PROTOCOL\n"); -#if UV_VERSION_MAJOR > 0 - lws_protocol_dir_kill_monitor(pss); -#endif - break; - - default: - return 0; - } - - return 0; - -} - -static const struct lws_protocols protocols[] = { - { - "protocol-lws-table-dirlisting", - callback_lws_table_dirlisting, - sizeof(struct per_session_data__tbl_dir), - 0, - }, -}; - -LWS_EXTERN LWS_VISIBLE int -init_protocol_lws_table_dirlisting(struct lws_context *context, - struct lws_plugin_capability *c) -{ - if (c->api_magic != LWS_PLUGIN_API_MAGIC) { - lwsl_err("Plugin API %d, library API %d", LWS_PLUGIN_API_MAGIC, - c->api_magic); - return 1; - } - - c->protocols = protocols; - c->count_protocols = LWS_ARRAY_SIZE(protocols); - c->extensions = NULL; - c->count_extensions = 0; - - return 0; -} - -LWS_EXTERN LWS_VISIBLE int -destroy_protocol_lws_table_dirlisting(struct lws_context *context) -{ - return 0; -} diff -Nru libwebsockets-3.2.1/plugins/protocol_client_loopback_test.c libwebsockets-4.1.6/plugins/protocol_client_loopback_test.c --- libwebsockets-3.2.1/plugins/protocol_client_loopback_test.c 2019-12-18 14:45:31.000000000 +0000 +++ libwebsockets-4.1.6/plugins/protocol_client_loopback_test.c 2020-12-01 17:40:26.000000000 +0000 @@ -173,26 +173,15 @@ }, }; -LWS_EXTERN LWS_VISIBLE int -init_protocol_client_loopback_test(struct lws_context *context, - struct lws_plugin_capability *c) -{ - if (c->api_magic != LWS_PLUGIN_API_MAGIC) { - lwsl_err("Plugin API %d, library API %d", LWS_PLUGIN_API_MAGIC, - c->api_magic); - return 1; - } - - c->protocols = protocols; - c->count_protocols = LWS_ARRAY_SIZE(protocols); - c->extensions = NULL; - c->count_extensions = 0; - - return 0; -} +LWS_VISIBLE const lws_plugin_protocol_t client_loopback_test = { + .hdr = { + "client loopback test", + "lws_protocol_plugin", + LWS_PLUGIN_API_MAGIC + }, -LWS_EXTERN LWS_VISIBLE int -destroy_protocol_client_loopback_test(struct lws_context *context) -{ - return 0; -} + .protocols = protocols, + .count_protocols = LWS_ARRAY_SIZE(protocols), + .extensions = NULL, + .count_extensions = 0, +}; diff -Nru libwebsockets-3.2.1/plugins/protocol_dumb_increment.c libwebsockets-4.1.6/plugins/protocol_dumb_increment.c --- libwebsockets-3.2.1/plugins/protocol_dumb_increment.c 2019-12-18 14:45:31.000000000 +0000 +++ libwebsockets-4.1.6/plugins/protocol_dumb_increment.c 2020-12-01 17:40:26.000000000 +0000 @@ -121,28 +121,17 @@ LWS_PLUGIN_PROTOCOL_DUMB_INCREMENT }; -LWS_EXTERN LWS_VISIBLE int -init_protocol_dumb_increment(struct lws_context *context, - struct lws_plugin_capability *c) -{ - if (c->api_magic != LWS_PLUGIN_API_MAGIC) { - lwsl_err("Plugin API %d, library API %d", LWS_PLUGIN_API_MAGIC, - c->api_magic); - return 1; - } +LWS_VISIBLE const lws_plugin_protocol_t dumb_increment = { + .hdr = { + "dumb increment", + "lws_protocol_plugin", + LWS_PLUGIN_API_MAGIC + }, - c->protocols = protocols; - c->count_protocols = LWS_ARRAY_SIZE(protocols); - c->extensions = NULL; - c->count_extensions = 0; - - return 0; -} - -LWS_EXTERN LWS_VISIBLE int -destroy_protocol_dumb_increment(struct lws_context *context) -{ - return 0; -} + .protocols = protocols, + .count_protocols = LWS_ARRAY_SIZE(protocols), + .extensions = NULL, + .count_extensions = 0, +}; #endif diff -Nru libwebsockets-3.2.1/plugins/protocol_esp32_lws_group.c libwebsockets-4.1.6/plugins/protocol_esp32_lws_group.c --- libwebsockets-3.2.1/plugins/protocol_esp32_lws_group.c 2019-12-18 14:45:31.000000000 +0000 +++ libwebsockets-4.1.6/plugins/protocol_esp32_lws_group.c 1970-01-01 00:00:00.000000000 +0000 @@ -1,239 +0,0 @@ -/* - * ESP32 Group protocol handler - * - * Copyright (C) 2017 Andy Green - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation: - * version 2.1 of the License. - * - * This library is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with this library; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, - * MA 02110-1301 USA* - * - */ -#include -#include -#include - -typedef enum { - GROUP_STATE_NONE, - GROUP_STATE_INITIAL, - GROUP_STATE_MEMBERS, - GROUP_STATE_FINAL -} group_state; - -struct per_session_data__lws_group { - struct per_session_data__lws_group *next; - group_state group_state; - - struct lws_group_member *member; - - unsigned char subsequent:1; - unsigned char changed_partway:1; -}; - -struct per_vhost_data__lws_group { - struct per_session_data__lws_group *live_pss_list; - struct lws_context *context; - struct lws_vhost *vhost; - const struct lws_protocols *protocol; - int count_live_pss; -}; - -static void render_ip4(char *dest, int len, uint8_t *ip) -{ - snprintf(dest, len, "%u.%u.%u.%u", ip[0], ip[1], ip[2], ip[3]); -} - - - -static int -callback_lws_group(struct lws *wsi, enum lws_callback_reasons reason, - void *user, void *in, size_t len) -{ - struct per_session_data__lws_group *pss = - (struct per_session_data__lws_group *)user; - struct per_vhost_data__lws_group *vhd = - (struct per_vhost_data__lws_group *) - lws_protocol_vh_priv_get(lws_get_vhost(wsi), - lws_get_protocol(wsi)); - char buffer[1024 + LWS_PRE], ipv4[20]; - char *start = buffer + LWS_PRE - 1, *p = start, - *end = buffer + sizeof(buffer) - 1; - struct lws_group_member *mbr; - int n, m; - - switch (reason) { - - case LWS_CALLBACK_PROTOCOL_INIT: - vhd = lws_protocol_vh_priv_zalloc(lws_get_vhost(wsi), - lws_get_protocol(wsi), - sizeof(struct per_vhost_data__lws_group)); - vhd->context = lws_get_context(wsi); - vhd->protocol = lws_get_protocol(wsi); - vhd->vhost = lws_get_vhost(wsi); - break; - - case LWS_CALLBACK_PROTOCOL_DESTROY: - if (!vhd) - break; - break; - - case LWS_CALLBACK_ESTABLISHED: - lwsl_notice("%s: ESTABLISHED\n", __func__); - vhd->count_live_pss++; - pss->next = vhd->live_pss_list; - vhd->live_pss_list = pss; - pss->group_state = GROUP_STATE_INITIAL; - lws_callback_on_writable(wsi); - break; - - case LWS_CALLBACK_SERVER_WRITEABLE: - - switch (pss->group_state) { - - case GROUP_STATE_NONE: - /* fallthru */ - - case GROUP_STATE_INITIAL: - - p += snprintf((char *)p, end - p, - "{\n" - " \"group\":\"%s\"," - " \"members\":[\n", - lws_esp32.group); - - n = LWS_WRITE_TEXT | LWS_WRITE_NO_FIN; - pss->group_state = GROUP_STATE_MEMBERS; - pss->subsequent = 0; - pss->changed_partway = 0; - pss->member = lws_esp32.first; - break; - - case GROUP_STATE_MEMBERS: - - /* confirm pss->member is still in the list... */ - - mbr = lws_esp32.first; - while (mbr && mbr != pss->member) - mbr = mbr->next; - - if (!mbr) { /* no longer exists... */ - if (lws_esp32.first || pss->member) - pss->changed_partway = 1; - *p++ = ' '; - pss->member = NULL; - - /* - * finish the list where we got to, then - * immediately reissue it - */ - } - - while (end - p > 100 && pss->member) { - - if (pss->subsequent) - *p++ = ','; - - pss->subsequent = 1; - render_ip4(ipv4, sizeof(ipv4), (uint8_t *)&pss->member->addr); - - p += snprintf((char *)p, end - p, - " {\n" - " \"mac\":\"%s\",\n" - " \"model\":\"%s\",\n" - " \"role\":\"%s\",\n" - " \"width\":\"%d\",\n" - " \"height\":\"%d\",\n" - " \"ipv4\":\"%s\"\n" - " }\n", - pss->member->mac, - pss->member->model, - pss->member->role, - pss->member->width, - pss->member->height, - ipv4 - ); - pss->member = pss->member->next; - } - - lwsl_notice("%s\n", p); - - n = LWS_WRITE_CONTINUATION | LWS_WRITE_NO_FIN; - if (!pss->member) - pss->group_state = GROUP_STATE_FINAL; - break; - - case GROUP_STATE_FINAL: - n = LWS_WRITE_CONTINUATION; - p += sprintf((char *)p, "],\n \"discard\":\"%d\"}\n", - pss->changed_partway); - if (pss->changed_partway) - pss->group_state = GROUP_STATE_INITIAL; - else - pss->group_state = GROUP_STATE_NONE; - break; - default: - return 0; - } -// lwsl_notice("issue: %d (%d)\n", p - start, n); - m = lws_write(wsi, (unsigned char *)start, p - start, n); - if (m < 0) { - lwsl_err("ERROR %d writing to di socket\n", m); - return -1; - } - - if (pss->group_state != GROUP_STATE_NONE) - lws_callback_on_writable(wsi); - - break; - - case LWS_CALLBACK_RECEIVE: - { - break; - } - - case LWS_CALLBACK_CLOSED: - { - struct per_session_data__lws_group **p = &vhd->live_pss_list; - - while (*p) { - if ((*p) == pss) { - *p = pss->next; - continue; - } - - p = &((*p)->next); - } - - vhd->count_live_pss--; - } - break; - - case LWS_CALLBACK_HTTP_DROP_PROTOCOL: - /* called when our wsi user_space is going to be destroyed */ - break; - - default: - break; - } - - return 0; -} - -#define LWS_PLUGIN_PROTOCOL_LWS_GROUP \ - { \ - "lws-group", \ - callback_lws_group, \ - sizeof(struct per_session_data__lws_group), \ - 1024, 0, NULL, 900 \ - } - diff -Nru libwebsockets-3.2.1/plugins/protocol_esp32_lws_ota.c libwebsockets-4.1.6/plugins/protocol_esp32_lws_ota.c --- libwebsockets-3.2.1/plugins/protocol_esp32_lws_ota.c 2019-12-18 14:45:31.000000000 +0000 +++ libwebsockets-4.1.6/plugins/protocol_esp32_lws_ota.c 1970-01-01 00:00:00.000000000 +0000 @@ -1,288 +0,0 @@ -/* - * ESP32 OTA update protocol handler - * - * Copyright (C) 2017 Andy Green - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation: - * version 2.1 of the License. - * - * This library is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with this library; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, - * MA 02110-1301 USA - * - */ -#include -#include -#include -#include - -struct per_session_data__esplws_ota { - struct lws_spa *spa; - char filename[32]; - char result[LWS_PRE + 512]; - int result_len; - int filename_length; - esp_ota_handle_t otahandle; - const esp_partition_t *part; - long file_length; - long last_rep; - nvs_handle nvh; - TimerHandle_t reboot_timer; -}; - -struct per_vhost_data__esplws_ota { - struct lws_context *context; - struct lws_vhost *vhost; - const struct lws_protocols *protocol; -}; - -static const char * const ota_param_names[] = { - "upload", -}; - -enum enum_ota_param_names { - EPN_UPLOAD, -}; - -static void ota_reboot_timer_cb(TimerHandle_t t) -{ - esp_restart(); -} - -const esp_partition_t * -ota_choose_part(void) -{ - const esp_partition_t *bootpart, *part = NULL; - esp_partition_iterator_t i; - - bootpart = lws_esp_ota_get_boot_partition(); - i = esp_partition_find(ESP_PARTITION_TYPE_APP, ESP_PARTITION_SUBTYPE_ANY, NULL); - while (i) { - part = esp_partition_get(i); - - /* cannot update ourselves */ - if (part == bootpart) - goto next; - - /* OTA Partition numbering is from _OTA_MIN to less than _OTA_MAX */ - if (part->subtype < ESP_PARTITION_SUBTYPE_APP_OTA_MIN || - part->subtype >= ESP_PARTITION_SUBTYPE_APP_OTA_MAX) - goto next; - - break; - -next: - i = esp_partition_next(i); - } - - if (!i) { - lwsl_err("Can't find good OTA part\n"); - return NULL; - } - lwsl_notice("Directing OTA to part type %d/%d start 0x%x\n", - part->type, part->subtype, - (uint32_t)part->address); - - return part; -} - -static int -ota_file_upload_cb(void *data, const char *name, const char *filename, - char *buf, int len, enum lws_spa_fileupload_states state) -{ - struct per_session_data__esplws_ota *pss = - (struct per_session_data__esplws_ota *)data; - - switch (state) { - case LWS_UFS_OPEN: - lwsl_notice("LWS_UFS_OPEN Filename %s\n", filename); - lws_strncpy(pss->filename, filename, sizeof(pss->filename)); - if (strcmp(name, "ota")) - return 1; - - pss->part = ota_choose_part(); - if (!pss->part) - return 1; - - if (esp_ota_begin(pss->part, OTA_SIZE_UNKNOWN, &pss->otahandle) != ESP_OK) { - lwsl_err("OTA: Failed to begin\n"); - return 1; - } - - pss->file_length = 0; - pss->last_rep = -1; - break; - - case LWS_UFS_FINAL_CONTENT: - case LWS_UFS_CONTENT: - if (pss->file_length + len > pss->part->size) { - lwsl_err("OTA: incoming file too large\n"); - return 1; - } - - if ((pss->file_length & ~0xffff) != (pss->last_rep & ~0xffff)) { - lwsl_notice("writing 0x%lx...\n", - pss->part->address + pss->file_length); - pss->last_rep = pss->file_length; - } - if (esp_ota_write(pss->otahandle, buf, len) != ESP_OK) { - lwsl_err("OTA: Failed to write\n"); - return 1; - } - pss->file_length += len; - - if (state == LWS_UFS_CONTENT) - break; - - lwsl_notice("LWS_UFS_FINAL_CONTENT\n"); - if (esp_ota_end(pss->otahandle) != ESP_OK) { - lwsl_err("OTA: end failed\n"); - return 1; - } - - if (esp_ota_set_boot_partition(pss->part) != ESP_OK) { - lwsl_err("OTA: set boot part failed\n"); - return 1; - } - - pss->reboot_timer = xTimerCreate("x", pdMS_TO_TICKS(250), 0, NULL, - ota_reboot_timer_cb); - xTimerStart(pss->reboot_timer, 0); - break; - } - - return 0; -} - -static int -callback_esplws_ota(struct lws *wsi, enum lws_callback_reasons reason, - void *user, void *in, size_t len) -{ - struct per_session_data__esplws_ota *pss = - (struct per_session_data__esplws_ota *)user; - struct per_vhost_data__esplws_ota *vhd = - (struct per_vhost_data__esplws_ota *) - lws_protocol_vh_priv_get(lws_get_vhost(wsi), - lws_get_protocol(wsi)); - unsigned char buf[LWS_PRE + 384], *start = buf + LWS_PRE - 1, *p = start, - *end = buf + sizeof(buf) - 1; - int n; - - switch (reason) { - - case LWS_CALLBACK_PROTOCOL_INIT: - vhd = lws_protocol_vh_priv_zalloc(lws_get_vhost(wsi), - lws_get_protocol(wsi), - sizeof(struct per_vhost_data__esplws_ota)); - vhd->context = lws_get_context(wsi); - vhd->protocol = lws_get_protocol(wsi); - vhd->vhost = lws_get_vhost(wsi); - break; - - case LWS_CALLBACK_PROTOCOL_DESTROY: - if (!vhd) - break; - break; - - /* OTA POST handling */ - - case LWS_CALLBACK_HTTP_BODY: - /* create the POST argument parser if not already existing */ - // lwsl_notice("LWS_CALLBACK_HTTP_BODY (ota) %d %d %p\n", (int)pss->file_length, (int)len, pss->spa); - lws_set_timeout(wsi, PENDING_TIMEOUT_HTTP_CONTENT, 30); - if (!pss->spa) { - pss->spa = lws_spa_create(wsi, ota_param_names, - LWS_ARRAY_SIZE(ota_param_names), 4096, - ota_file_upload_cb, pss); - if (!pss->spa) - return -1; - - pss->filename[0] = '\0'; - pss->file_length = 0; - } - lws_esp32.upload = 1; - - /* let it parse the POST data */ - if (lws_spa_process(pss->spa, in, len)) - return -1; - break; - - case LWS_CALLBACK_HTTP_BODY_COMPLETION: - lwsl_notice("LWS_CALLBACK_HTTP_BODY_COMPLETION (ota)\n"); - /* call to inform no more payload data coming */ - lws_spa_finalize(pss->spa); - - pss->result_len = snprintf(pss->result + LWS_PRE, sizeof(pss->result) - LWS_PRE - 1, - "Rebooting after OTA update"); - - if (lws_add_http_header_status(wsi, HTTP_STATUS_OK, &p, end)) - goto bail; - - if (lws_add_http_header_by_token(wsi, WSI_TOKEN_HTTP_CONTENT_TYPE, - (unsigned char *)"text/html", 9, &p, end)) - goto bail; - if (lws_add_http_header_content_length(wsi, pss->result_len, &p, end)) - goto bail; - if (lws_finalize_http_header(wsi, &p, end)) - goto bail; - - n = lws_write(wsi, start, p - start, LWS_WRITE_HTTP_HEADERS | LWS_WRITE_H2_STREAM_END); - if (n < 0) - goto bail; - - lws_callback_on_writable(wsi); - break; - - case LWS_CALLBACK_HTTP_WRITEABLE: - if (!pss->result_len) - break; - lwsl_debug("LWS_CALLBACK_HTTP_WRITEABLE: sending %d\n", - pss->result_len); - n = lws_write(wsi, (unsigned char *)pss->result + LWS_PRE, - pss->result_len, LWS_WRITE_HTTP); - if (n < 0) - return 1; - - if (lws_http_transaction_completed(wsi)) - return 1; - - /* stop further service so we don't serve the probe GET to see if we rebooted */ - while (1); - - break; - - case LWS_CALLBACK_HTTP_DROP_PROTOCOL: - /* called when our wsi user_space is going to be destroyed */ - if (pss->spa) { - lws_spa_destroy(pss->spa); - pss->spa = NULL; - } - lws_esp32.upload = 0; - break; - - default: - break; - } - - return 0; - -bail: - return 1; -} - -#define LWS_PLUGIN_PROTOCOL_ESPLWS_OTA \ - { \ - "esplws-ota", \ - callback_esplws_ota, \ - sizeof(struct per_session_data__esplws_ota), \ - 4096, 0, NULL, 900 \ - } - diff -Nru libwebsockets-3.2.1/plugins/protocol_esp32_lws_reboot_to_factory.c libwebsockets-4.1.6/plugins/protocol_esp32_lws_reboot_to_factory.c --- libwebsockets-3.2.1/plugins/protocol_esp32_lws_reboot_to_factory.c 2019-12-18 14:45:31.000000000 +0000 +++ libwebsockets-4.1.6/plugins/protocol_esp32_lws_reboot_to_factory.c 1970-01-01 00:00:00.000000000 +0000 @@ -1,58 +0,0 @@ -/* - * Example ESP32 app code using Libwebsockets - * - * Copyright (C) 2017 Andy Green - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation: - * version 2.1 of the License. - * - * This library is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with this library; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, - * MA 02110-1301 USA - * - * This is intended to be mounted somewhere in your ESP32 user app... if the - * client touched the mount, the plugin hangs up and reboots into the - * factory mode one second later. - * - * The factory mode will reassociate with the same IP with the same MAC - * shortly afterwards and be accessible by the same IP / mDNS name. - */ -#include -#include -#include -#include - -static int -callback_esplws_rtf(struct lws *wsi, enum lws_callback_reasons reason, - void *user, void *in, size_t len) -{ - switch (reason) { - - case LWS_CALLBACK_HTTP: - - lws_esp32_restart_guided(LWS_MAGIC_REBOOT_TYPE_REQ_FACTORY); - return 1; - - default: - break; - } - - return 0; -} - -#define LWS_PLUGIN_PROTOCOL_ESPLWS_RTF \ - { \ - "esplws-rtf", \ - callback_esplws_rtf, \ - 0, \ - 10, 0, NULL, 0 \ - } - diff -Nru libwebsockets-3.2.1/plugins/protocol_esp32_lws_scan.c libwebsockets-4.1.6/plugins/protocol_esp32_lws_scan.c --- libwebsockets-3.2.1/plugins/protocol_esp32_lws_scan.c 2019-12-18 14:45:31.000000000 +0000 +++ libwebsockets-4.1.6/plugins/protocol_esp32_lws_scan.c 1970-01-01 00:00:00.000000000 +0000 @@ -1,1273 +0,0 @@ -/* - * ESP32 Scan / Factory protocol handler - * - * Copyright (C) 2017 Andy Green - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation: - * version 2.1 of the License. - * - * This library is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with this library; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, - * MA 02110-1301 USA* - * - */ -#include -#include -#include - -typedef enum { - SCAN_STATE_NONE, - SCAN_STATE_INITIAL, - SCAN_STATE_INITIAL_MANIFEST, - SCAN_STATE_KNOWN, - SCAN_STATE_LIST, - SCAN_STATE_FINAL -} scan_state; - -struct store_json { - const char *j; - const char *nvs; -}; - -struct per_session_data__esplws_scan { - struct per_session_data__esplws_scan *next; - scan_state scan_state; - struct timeval last_send; - - struct lws_spa *spa; - char filename[32]; - char result[LWS_PRE + 512]; - unsigned char buffer[4096]; - int result_len; - int filename_length; - long file_length; - nvs_handle nvh; - - char ap_record; - unsigned char subsequent:1; - unsigned char changed_partway:1; -}; - -#define max_aps 12 - -struct per_vhost_data__esplws_scan { - wifi_ap_record_t ap_records[10]; - TimerHandle_t timer, reboot_timer; - struct per_session_data__esplws_scan *live_pss_list; - struct lws_context *context; - struct lws_vhost *vhost; - const struct lws_protocols *protocol; - struct lws_wifi_scan *known_aps_list; - - const esp_partition_t *part; - esp_ota_handle_t otahandle; - long file_length; - long content_length; - - int cert_remaining_days; - - struct lws *cwsi; - char json[2048]; - int json_len; - - int acme_state; - char acme_msg[256]; - - uint16_t count_ap_records; - char count_live_pss; - unsigned char scan_ongoing:1; - unsigned char completed_any_scan:1; - unsigned char reboot:1; - unsigned char changed_settings:1; - unsigned char checked_updates:1; - unsigned char autonomous_update:1; - unsigned char autonomous_update_sampled:1; -}; - -static const struct store_json store_json[] = { - { "\"ssid0\":\"", "0ssid" }, - { ",\"pw0\":\"", "0password" }, - { "\"ssid1\":\"", "1ssid" }, - { ",\"pw1\":\"", "1password" }, - { "\"ssid2\":\"", "2ssid" }, - { ",\"pw2\":\"", "2password" }, - { "\"ssid3\":\"", "3ssid" }, - { ",\"pw3\":\"", "3password" }, - { ",\"access_pw\":\"", "access_pw" }, - { "{\"group\":\"", "group" }, - { "{\"role\":\"", "role" }, - { ",\"region\":\"", "region" }, -}; - -static wifi_scan_config_t scan_config = { - .ssid = 0, - .bssid = 0, - .channel = 0, - .show_hidden = true -}; - -const esp_partition_t * -ota_choose_part(void); - -static const char * const param_names[] = { - "text", - "pub", - "pri", - "serial", - "opts", - "group", - "role", - "updsettings", -}; - -enum enum_param_names { - EPN_TEXT, - EPN_PUB, - EPN_PRI, - EPN_SERIAL, - EPN_OPTS, - EPN_GROUP, - EPN_ROLE, - EPN_UPDSETTINGS, -}; - - -static void -scan_finished(uint16_t count, wifi_ap_record_t *recs, void *v); - -static int -esplws_simple_arg(char *dest, int len, const char *in, const char *match) -{ - const char *p = strstr(in, match); - int n = 0; - - if (!p) - return 1; - - p += strlen(match); - while (*p && *p != '\"' && n < len - 1) - dest[n++] = *p++; - dest[n] = '\0'; - - return 0; -} - -static void -scan_start(struct per_vhost_data__esplws_scan *vhd) -{ - int n; - - if (vhd->reboot) - esp_restart(); - - if (vhd->scan_ongoing) - return; - - if (lws_esp32.acme) - return; - - if (lws_esp32.upload) - return; - - vhd->scan_ongoing = 1; - lws_esp32.scan_consumer = scan_finished; - lws_esp32.scan_consumer_arg = vhd; - n = esp_wifi_scan_start(&scan_config, false); - if (n != ESP_OK) - lwsl_err("scan start failed %d\n", n); -} - -static int scan_defer; - -static void timer_cb(TimerHandle_t t) -{ - struct per_vhost_data__esplws_scan *vhd = pvTimerGetTimerID(t); - -// if (!lws_esp32.inet && ((scan_defer++) & 1)) -/* - * AP mode + scan does not work well on ESP32... if we didn't connect to an AP - * ourselves, just scan once at boot. Then leave us on the AP channel. - * - * Do the callback for everyone to keep the heartbeat alive. - */ - if (!lws_esp32.inet && scan_defer++) { - lws_callback_on_writable_all_protocol(vhd->context, vhd->protocol); - - return; - } - - scan_start(vhd); -} - -static void reboot_timer_cb(TimerHandle_t t) -{ - esp_restart(); -} - -static int -client_connection(struct per_vhost_data__esplws_scan *vhd, const char *file) -{ -#if defined(CONFIG_LWS_IS_FACTORY_APPLICATION) && defined(CONFIG_LWS_OTA_SERVER_BASE_URL) && \ - defined(CONFIG_LWS_OTA_SERVER_FQDN) - static struct lws_client_connect_info i; - char path[256]; - - memset(&i, 0, sizeof i); - - snprintf(path, sizeof(path) - 1, CONFIG_LWS_OTA_SERVER_BASE_URL "/" CONFIG_LWS_MODEL_NAME "/%s", file); - - lwsl_notice("Fetching %s\n", path); - - i.port = 443; - i.context = vhd->context; - i.address = CONFIG_LWS_OTA_SERVER_FQDN; - i.ssl_connection = 1; - i.host = i.address; - i.origin = i.host; - i.vhost = vhd->vhost; - i.method = "GET"; - i.path = path; - i.protocol = "esplws-scan"; - i.pwsi = &vhd->cwsi; - - vhd->cwsi = lws_client_connect_via_info(&i); - if (!vhd->cwsi) { - lwsl_notice("NULL return\n"); - return 1; /* fail */ - } -#endif - return 0; /* ongoing */ -} - -static int -lws_wifi_scan_rssi(struct lws_wifi_scan *p) -{ - if (!p->count) - return -127; - - return p->rssi / p->count; -} - -/* - * Insert new lws_wifi_scan into linkedlist in rssi-sorted order, trimming the - * list if needed to keep it at or below max_aps entries. - */ - -static int -lws_wifi_scan_insert_trim(struct lws_wifi_scan **list, struct lws_wifi_scan *ns) -{ - int count = 0, ins = 1, worst; - struct lws_wifi_scan *newlist, **pworst, *pp1; - - lws_start_foreach_llp(struct lws_wifi_scan **, pp, *list) { - /* try to find existing match */ - if (!strcmp((*pp)->ssid, ns->ssid) && - !memcmp((*pp)->bssid, ns->bssid, 6)) { - if ((*pp)->count > 127) { - (*pp)->count /= 2; - (*pp)->rssi /= 2; - } - (*pp)->rssi += ns->rssi; - (*pp)->count++; - ins = 0; - break; - } - } lws_end_foreach_llp(pp, next); - - if (ins) { - lws_start_foreach_llp(struct lws_wifi_scan **, pp, *list) { - /* trim any excess guys */ - if (count++ >= max_aps - 1) { - pp1 = *pp; - *pp = (*pp)->next; - free(pp1); - continue; /* stay where we are */ - } - } lws_end_foreach_llp(pp, next); - - /* we are inserting... so alloc a copy of him */ - pp1 = malloc(sizeof(*pp1)); - if (!pp1) - return -1; - - memcpy(pp1, ns, sizeof(*pp1)); - pp1->next = *list; - *list = pp1; - } - - /* sort the list ... worst first, but added at the newlist head */ - - newlist = NULL; - - /* while anybody left on the old list */ - while (*list) { - worst = 0; - pworst = NULL; - - /* who is the worst guy still left on the old list? */ - lws_start_foreach_llp(struct lws_wifi_scan **, pp, *list) { - if (lws_wifi_scan_rssi(*pp) <= worst) { - worst = lws_wifi_scan_rssi(*pp); - pworst = pp; - } - } lws_end_foreach_llp(pp, next); - - if (pworst) { - /* move the worst to the head of the new list */ - pp1 = *pworst; - *pworst = (*pworst)->next; - pp1->next = newlist; - newlist = pp1; - } - } - - *list = newlist; - - return 0; -} - -static void -scan_finished(uint16_t count, wifi_ap_record_t *recs, void *v) -{ - struct per_vhost_data__esplws_scan *vhd = v; - struct per_session_data__esplws_scan *p = vhd->live_pss_list; - struct lws_wifi_scan lws; - wifi_ap_record_t *r; - int m; - - lwsl_notice("%s: count %d\n", __func__, count); - - vhd->scan_ongoing = 0; - - if (count < LWS_ARRAY_SIZE(vhd->ap_records)) - vhd->count_ap_records = count; - else - vhd->count_ap_records = LWS_ARRAY_SIZE(vhd->ap_records); - - memcpy(vhd->ap_records, recs, vhd->count_ap_records * sizeof(*recs)); - - while (p) { - if (p->scan_state != SCAN_STATE_INITIAL && - p->scan_state != SCAN_STATE_NONE) - p->changed_partway = 1; - else - p->scan_state = SCAN_STATE_INITIAL; - p = p->next; - } - - /* convert to generic, cumulative scan results */ - - for (m = 0; m < vhd->count_ap_records; m++) { - - r = &vhd->ap_records[m]; - - lws.authmode = r->authmode; - lws.channel = r->primary; - lws.rssi = r->rssi; - lws.count = 1; - memcpy(&lws.bssid, r->bssid, 6); - lws_strncpy(lws.ssid, (const char *)r->ssid, sizeof(lws.ssid)); - - lws_wifi_scan_insert_trim(&vhd->known_aps_list, &lws); - } - - lws_callback_on_writable_all_protocol(vhd->context, vhd->protocol); - - if (lws_esp32.inet && !vhd->cwsi && !vhd->checked_updates) - client_connection(vhd, "manifest.json"); - - if (vhd->changed_settings) { - lws_esp32_wlan_nvs_get(1); - vhd->changed_settings = 0; - } else - esp_wifi_connect(); -} - -static const char *ssl_names[] = { "ap-cert.pem", "ap-key.pem" }; - -static int -file_upload_cb(void *data, const char *name, const char *filename, - char *buf, int len, enum lws_spa_fileupload_states state) -{ - struct per_session_data__esplws_scan *pss = - (struct per_session_data__esplws_scan *)data; - int n; - - switch (state) { - case LWS_UFS_OPEN: - if (lws_esp32_get_reboot_type() != LWS_MAGIC_REBOOT_TYPE_FORCED_FACTORY_BUTTON) - return -1; - - lwsl_notice("LWS_UFS_OPEN Filename %s\n", filename); - lws_strncpy(pss->filename, filename, sizeof(pss->filename)); - if (!strcmp(name, "pub") || !strcmp(name, "pri")) { - if (nvs_open("lws-station", NVS_READWRITE, &pss->nvh)) - return 1; - } else - return 1; - pss->file_length = 0; - break; - - case LWS_UFS_FINAL_CONTENT: - case LWS_UFS_CONTENT: - if (len) { - /* if the file length is too big, drop it */ - if (pss->file_length + len > sizeof(pss->buffer)) - return 1; - - memcpy(pss->buffer + pss->file_length, buf, len); - } - pss->file_length += len; - - if (state == LWS_UFS_CONTENT) - break; - - lwsl_notice("LWS_UFS_FINAL_CONTENT\n"); - n = 0; - if (!strcmp(name, "pri")) - n = 1; - lwsl_notice("writing %s\n", ssl_names[n]); - n = nvs_set_blob(pss->nvh, ssl_names[n], pss->buffer, pss->file_length); - if (n == ESP_OK) - nvs_commit(pss->nvh); - nvs_close(pss->nvh); - if (n != ESP_OK) - return 1; - break; - } - - return 0; -} - -static int -callback_esplws_scan(struct lws *wsi, enum lws_callback_reasons reason, - void *user, void *in, size_t len) -{ - struct per_session_data__esplws_scan *pss = - (struct per_session_data__esplws_scan *)user; - struct per_vhost_data__esplws_scan *vhd = - (struct per_vhost_data__esplws_scan *) - lws_protocol_vh_priv_get(lws_get_vhost(wsi), - lws_get_protocol(wsi)); - unsigned char *start = pss->buffer + LWS_PRE - 1, *p = start, - *end = pss->buffer + sizeof(pss->buffer) - 1; - union lws_tls_cert_info_results ir; - struct lws_wifi_scan *lwscan; - char subject[64]; - int n, m; - nvs_handle nvh; - size_t s; - - - switch (reason) { - - case LWS_CALLBACK_PROTOCOL_INIT: - vhd = lws_protocol_vh_priv_zalloc(lws_get_vhost(wsi), - lws_get_protocol(wsi), - sizeof(struct per_vhost_data__esplws_scan)); - vhd->context = lws_get_context(wsi); - vhd->protocol = lws_get_protocol(wsi); - vhd->vhost = lws_get_vhost(wsi); - vhd->timer = xTimerCreate("x", pdMS_TO_TICKS(10000), 1, vhd, - (TimerCallbackFunction_t)timer_cb); - vhd->scan_ongoing = 0; - strcpy(vhd->json, " { }"); - // scan_start(vhd); - break; - - case LWS_CALLBACK_PROTOCOL_DESTROY: - if (!vhd) - break; - xTimerStop(vhd->timer, 0); - xTimerDelete(vhd->timer, 0); - break; - - case LWS_CALLBACK_ESTABLISHED: - lwsl_notice("%s: ESTABLISHED\n", __func__); - if (!vhd->live_pss_list) { - // scan_start(vhd); - xTimerStart(vhd->timer, 0); - } - vhd->count_live_pss++; - pss->next = vhd->live_pss_list; - vhd->live_pss_list = pss; - /* if we have scan results, update them. Otherwise wait */ -// if (vhd->count_ap_records) { - pss->scan_state = SCAN_STATE_INITIAL; - lws_callback_on_writable(wsi); -// } - break; - - case LWS_CALLBACK_SERVER_WRITEABLE: - if (vhd->autonomous_update_sampled) { - p += snprintf((char *)p, end - p, - " {\n \"auton\":\"1\",\n \"pos\": \"%ld\",\n" - " \"len\":\"%ld\"\n}\n", - vhd->file_length, - vhd->content_length); - - n = LWS_WRITE_TEXT; - goto issue; - } - - switch (pss->scan_state) { - struct timeval t; - uint8_t mac[6]; - struct lws_esp32_image i; - char img_factory[384], img_ota[384], group[16], role[16]; - int grt; - - case SCAN_STATE_NONE: - - /* fallthru */ - - case SCAN_STATE_INITIAL: - - gettimeofday(&t, NULL); - // if (t.tv_sec - pss->last_send.tv_sec < 10) - // return 0; - - pss->last_send = t; - - if (nvs_open("lws-station", NVS_READWRITE, &nvh)) { - lwsl_err("unable to open nvs\n"); - return -1; - } - n = 0; - if (nvs_get_blob(nvh, "ap-cert.pem", NULL, &s) == ESP_OK) - n = 1; - if (nvs_get_blob(nvh, "ap-key.pem", NULL, &s) == ESP_OK) - n |= 2; - s = sizeof(group) - 1; - group[0] = '\0'; - role[0] = '\0'; - nvs_get_str(nvh, "group", group, &s); - nvs_get_str(nvh, "role", role, &s); - - nvs_close(nvh); - - ir.ns.name[0] = '\0'; - subject[0] = '\0'; - - if (t.tv_sec > 1464083026 && - !lws_tls_vhost_cert_info(vhd->vhost, - LWS_TLS_CERT_INFO_VALIDITY_TO, &ir, 0)) { - vhd->cert_remaining_days = - (ir.time - t.tv_sec) / (24 * 3600); - ir.ns.name[0] = '\0'; - lws_tls_vhost_cert_info(vhd->vhost, - LWS_TLS_CERT_INFO_COMMON_NAME, &ir, - sizeof(ir.ns.name)); - lws_strncpy(subject, ir.ns.name, sizeof(subject)); - - ir.ns.name[0] = '\0'; - lws_tls_vhost_cert_info(vhd->vhost, - LWS_TLS_CERT_INFO_ISSUER_NAME, &ir, - sizeof(ir.ns.name)); - } - - /* - * this value in the JSON is just - * used for UI indication. Each conditional feature confirms - * it itself before it allows itself to be used. - */ - - grt = lws_esp32_get_reboot_type(); - - esp_efuse_mac_get_default(mac); - strcpy(img_factory, " { \"date\": \"Empty\" }"); - strcpy(img_ota, " { \"date\": \"Empty\" }"); - - // if (grt != LWS_MAGIC_REBOOT_TYPE_FORCED_FACTORY_BUTTON) { - lws_esp32_get_image_info(esp_partition_find_first(ESP_PARTITION_TYPE_APP, - ESP_PARTITION_SUBTYPE_APP_FACTORY, NULL), &i, - img_factory, sizeof(img_factory) - 1); - img_factory[sizeof(img_factory) - 1] = '\0'; - if (img_factory[0] == 0xff || strlen(img_factory) < 8) - strcpy(img_factory, " { \"date\": \"Empty\" }"); - - lws_esp32_get_image_info(esp_partition_find_first(ESP_PARTITION_TYPE_APP, - ESP_PARTITION_SUBTYPE_APP_OTA_0, NULL), &i, - img_ota, sizeof(img_ota) - 1); - img_ota[sizeof(img_ota) - 1] = '\0'; - if (img_ota[0] == 0xff || strlen(img_ota) < 8) - strcpy(img_ota, " { \"date\": \"Empty\" }"); - // } - - p += snprintf((char *)p, end - p, - "{ \"model\":\"%s\",\n" - " \"forced_button\":\"%d\",\n" - " \"serial\":\"%s\",\n" - " \"opts\":\"%s\",\n" - " \"host\":\"%s-%s\",\n" - " \"region\":\"%d\",\n" - " \"ssl_pub\":\"%d\",\n" - " \"ssl_pri\":\"%d\",\n" - " \"mac\":\"%02X%02X%02X%02X%02X%02X\",\n" - " \"ssid\":\"%s\",\n" - " \"conn_ip\":\"%s\",\n" - " \"conn_mask\":\"%s\",\n" - " \"conn_gw\":\"%s\",\n" - " \"certdays\":\"%d\",\n" - " \"unixtime\":\"%llu\",\n" - " \"certissuer\":\"%s\",\n" - " \"certsubject\":\"%s\",\n" - " \"le_dns\":\"%s\",\n" - " \"le_email\":\"%s\",\n" - " \"acme_state\":\"%d\",\n" - " \"acme_msg\":\"%s\",\n" - " \"button\":\"%d\",\n" - " \"group\":\"%s\",\n" - " \"role\":\"%s\",\n", - lws_esp32.model, - grt == LWS_MAGIC_REBOOT_TYPE_FORCED_FACTORY_BUTTON, - lws_esp32.serial, - lws_esp32.opts, - lws_esp32.model, lws_esp32.serial, - lws_esp32.region, - n & 1, (n >> 1) & 1, - mac[0], mac[1], mac[2], mac[3], mac[4], mac[5] | 1, - lws_esp32.active_ssid, - lws_esp32.sta_ip, - lws_esp32.sta_mask, - lws_esp32.sta_gw, - vhd->cert_remaining_days, - (unsigned long long)t.tv_sec, - ir.ns.name, subject, - lws_esp32.le_dns, - lws_esp32.le_email, - vhd->acme_state, - vhd->acme_msg, - ((volatile struct lws_esp32 *)(&lws_esp32))->button_is_down, - group, role); - p += snprintf((char *)p, end - p, - " \"img_factory\": %s,\n" - " \"img_ota\": %s,\n", - img_factory, - img_ota - ); - - - n = LWS_WRITE_TEXT | LWS_WRITE_NO_FIN; - pss->scan_state = SCAN_STATE_INITIAL_MANIFEST; - pss->ap_record = 0; - pss->subsequent = 0; - break; - - case SCAN_STATE_INITIAL_MANIFEST: - p += snprintf((char *)p, end - p, - " \"latest\": %s,\n" - " \"inet\":\"%d\",\n", - vhd->json, - lws_esp32.inet - ); - - p += snprintf((char *)p, end - p, - " \"known\":[\n"); - - n = LWS_WRITE_CONTINUATION | LWS_WRITE_NO_FIN; - pss->scan_state = SCAN_STATE_KNOWN; - break; - - case SCAN_STATE_KNOWN: - if (nvs_open("lws-station", NVS_READONLY, &nvh)) { - lwsl_notice("unable to open nvh\n"); - return -1; - } - - for (m = 0; m < 4; m++) { - char name[10], ssid[65]; - unsigned int pp = 0, use = 0; - - if (m) - *p++ = ','; - - s = sizeof(ssid) - 1; - ssid[0] = '\0'; - lws_snprintf(name, sizeof(name) - 1, "%dssid", m); - nvs_get_str(nvh, name, ssid, &s); - lws_snprintf(name, sizeof(name) - 1, "%dpassword", m); - s = 10; - nvs_get_str(nvh, name, NULL, &s); - pp = !!s; - lws_snprintf(name, sizeof(name) - 1, "%duse", m); - nvs_get_u32(nvh, name, &use); - - p += snprintf((char *)p, end - p, - "{\"ssid\":\"%s\",\n" - " \"pp\":\"%u\",\n" - "\"use\":\"%u\"}\n", - ssid, pp, use); - } - nvs_close(nvh); - pss->ap_record = 0; - - p += snprintf((char *)p, end - p, - "], \"aps\":[\n"); - - n = LWS_WRITE_CONTINUATION | LWS_WRITE_NO_FIN; - pss->scan_state = SCAN_STATE_LIST; - break; - - case SCAN_STATE_LIST: - lwscan = vhd->known_aps_list; - - n = pss->ap_record; - while (lwscan && n--) - lwscan = lwscan->next; - - for (m = 0; m < 6; m++) { - n = LWS_WRITE_CONTINUATION | LWS_WRITE_NO_FIN; - if (!lwscan) - goto scan_state_final; - - if (pss->subsequent) - *p++ = ','; - pss->subsequent = 1; - pss->ap_record++; - - p += snprintf((char *)p, end - p, - "{\"ssid\":\"%s\",\n" - "\"bssid\":\"%02X:%02X:%02X:%02X:%02X:%02X\",\n" - "\"rssi\":\"%d\",\n" - "\"chan\":\"%d\",\n" - "\"auth\":\"%d\"}\n", - lwscan->ssid, - lwscan->bssid[0], lwscan->bssid[1], lwscan->bssid[2], - lwscan->bssid[3], lwscan->bssid[4], lwscan->bssid[5], - lws_wifi_scan_rssi(lwscan), - lwscan->channel, lwscan->authmode); - - lwscan = lwscan->next; - if (!lwscan) - pss->scan_state = SCAN_STATE_FINAL; - } - break; - - case SCAN_STATE_FINAL: -scan_state_final: - n = LWS_WRITE_CONTINUATION; - p += sprintf((char *)p, "]\n}\n"); - if (pss->changed_partway) { - pss->changed_partway = 0; - pss->subsequent = 0; - pss->scan_state = SCAN_STATE_INITIAL; - } else { - pss->scan_state = SCAN_STATE_NONE; - vhd->autonomous_update_sampled = vhd->autonomous_update; - } - break; - default: - return 0; - } -issue: - m = lws_write(wsi, (unsigned char *)start, p - start, n); - if (m < 0) { - lwsl_err("ERROR %d writing to di socket\n", m); - return -1; - } - - if (pss->scan_state != SCAN_STATE_NONE) - lws_callback_on_writable(wsi); - - break; - - case LWS_CALLBACK_VHOST_CERT_UPDATE: - lwsl_notice("LWS_CALLBACK_VHOST_CERT_UPDATE: %d\n", (int)len); - vhd->acme_state = (int)len; - if (in) { - lws_strncpy(vhd->acme_msg, in, sizeof(vhd->acme_msg)); - lwsl_notice("acme_msg: %s\n", (char *)in); - } - lws_callback_on_writable_all_protocol_vhost(vhd->vhost, vhd->protocol); - break; - - case LWS_CALLBACK_RECEIVE: - { - const char *sect = "\"app\": {", *b; - nvs_handle nvh; - char p[64], use[6]; - int n, si = -1; - - if (strstr((const char *)in, "identify")) { - lws_esp32_identify_physical_device(); - break; - } - - if (vhd->json_len && strstr((const char *)in, "update-factory")) { - sect = "\"factory\": {"; - goto auton; - } - if (vhd->json_len && strstr((const char *)in, "update-ota")) - goto auton; - - if (strstr((const char *)in, "\"reset\"")) - goto sched_reset; - - if (!strncmp((const char *)in, "{\"job\":\"start-le\"", 17)) - goto start_le; - - - if (nvs_open("lws-station", NVS_READWRITE, &nvh) != ESP_OK) { - lwsl_err("Unable to open nvs\n"); - break; - } - - if (!esplws_simple_arg(p, sizeof(p), in, ",\"slot\":\"")) - si = atoi(p); - - lwsl_notice("si %d\n", si); - - for (n = 0; n < LWS_ARRAY_SIZE(store_json); n++) { - if (esplws_simple_arg(p, sizeof(p), in, store_json[n].j)) - continue; - - /* only change access password if he has physical access to device */ - if (n == 8 && lws_esp32_get_reboot_type() != LWS_MAGIC_REBOOT_TYPE_FORCED_FACTORY_BUTTON) - continue; - - if (lws_nvs_set_str(nvh, store_json[n].nvs, p) != ESP_OK) { - lwsl_err("Unable to store %s in nvm\n", store_json[n].nvs); - goto bail_nvs; - } - - if (si != -1 && n < 8) { - if (!(n & 1)) { - lws_strncpy(lws_esp32.ssid[(n >> 1) & 3], p, - sizeof(lws_esp32.ssid[0])); - lws_snprintf(use, sizeof(use) - 1, "%duse", si); - lwsl_notice("resetting %s to 0\n", use); - nvs_set_u32(nvh, use, 0); - - } else - lws_strncpy(lws_esp32.password[(n >> 1) & 3], p, - sizeof(lws_esp32.password[0])); - } - - } - - nvs_commit(nvh); - nvs_close(nvh); - - if (strstr((const char *)in, "\"factory-reset\"")) { - if (lws_esp32_get_reboot_type() == - LWS_MAGIC_REBOOT_TYPE_FORCED_FACTORY_BUTTON) { - - lwsl_notice("Doing factory reset\n"); - ESP_ERROR_CHECK(nvs_open("lws-station", NVS_READWRITE, &nvh)); - n = nvs_erase_all(nvh); - if (n) - lwsl_notice("erase_all failed %d\n", n); - nvs_commit(nvh); - nvs_close(nvh); - - goto sched_reset; - } else - lwsl_notice("failed on factory button boot\n"); - } - - if (vhd->scan_ongoing) - vhd->changed_settings = 1; - else - lws_esp32_wlan_nvs_get(1); - - lwsl_notice("set Join AP info\n"); - break; - -bail_nvs: - nvs_close(nvh); - - return 1; - -sched_reset: - vhd->reboot_timer = xTimerCreate("x", pdMS_TO_TICKS(250), 0, vhd, - (TimerCallbackFunction_t)reboot_timer_cb); - xTimerStart(vhd->reboot_timer, 0); - - return 1; - -auton: - lwsl_notice("Autonomous upload\n"); - b = strstr(vhd->json, sect); - if (!b) { - lwsl_notice("Can't find %s in JSON\n", sect); - return 1; - } - b = strstr(b, "\"file\": \""); - if (!b) { - lwsl_notice("Can't find \"file\": JSON\n"); - return 1; - } - vhd->autonomous_update = 1; - if (pss->scan_state == SCAN_STATE_NONE) - vhd->autonomous_update_sampled = 1; - b += 9; - n = 0; - while ((*b != '\"') && n < sizeof(p) - 1) - p[n++] = *b++; - - p[n] = '\0'; - - vhd->part = ota_choose_part(); - if (!vhd->part) - return 1; - - if (client_connection(vhd, p)) - vhd->autonomous_update = 0; - - break; - -start_le: - lws_esp32.acme = 1; /* hold off scanning */ - puts(in); - /* - * {"job":"start-le","cn":"home.warmcat.com", - * "email":"andy@warmcat.com", "staging":"true"} - */ - - if (nvs_open("lws-station", NVS_READWRITE, &nvh) != ESP_OK) { - lwsl_err("Unable to open nvs\n"); - break; - } - - n = 0; - b = strstr(in, ",\"cn\":\""); - if (b) { - b += 7; - while (*b && *b != '\"' && n < sizeof(lws_esp32.le_dns) - 1) - lws_esp32.le_dns[n++] = *b++; - } - lws_esp32.le_dns[n] = '\0'; - - lws_nvs_set_str(nvh, "acme-cn", lws_esp32.le_dns); - n = 0; - b = strstr(in, ",\"email\":\""); - if (b) { - b += 10; - while (*b && *b != '\"' && n < sizeof(lws_esp32.le_email) - 1) - lws_esp32.le_email[n++] = *b++; - } - lws_esp32.le_email[n] = '\0'; - lws_nvs_set_str(nvh, "acme-email", lws_esp32.le_email); - nvs_commit(nvh); - - nvs_close(nvh); - - n = 1; - b = strstr(in, ",\"staging\":\""); - if (b) - lwsl_notice("staging: %s\n", b); - if (b && b[12] == 'f') - n = 0; - - lwsl_notice("cn: %s, email: %s, staging: %d\n", lws_esp32.le_dns, lws_esp32.le_email, n); - - { - struct lws_acme_cert_aging_args caa; - - memset(&caa, 0, sizeof(caa)); - caa.vh = vhd->vhost; - - caa.element_overrides[LWS_TLS_REQ_ELEMENT_COMMON_NAME] = lws_esp32.le_dns; - caa.element_overrides[LWS_TLS_REQ_ELEMENT_EMAIL] = lws_esp32.le_email; - - if (n) - caa.element_overrides[LWS_TLS_SET_DIR_URL] = - "https://acme-staging.api.letsencrypt.org/directory"; /* staging */ - else - caa.element_overrides[LWS_TLS_SET_DIR_URL] = - "https://acme-v01.api.letsencrypt.org/directory"; /* real */ - - lws_callback_vhost_protocols_vhost(vhd->vhost, - LWS_CALLBACK_VHOST_CERT_AGING, - (void *)&caa, 0); - } - - break; - - } - - case LWS_CALLBACK_CLOSED: - { - struct per_session_data__esplws_scan **p = &vhd->live_pss_list; - - while (*p) { - if ((*p) == pss) { - *p = pss->next; - continue; - } - - p = &((*p)->next); - } - - vhd->count_live_pss--; - } - if (!vhd->live_pss_list) - xTimerStop(vhd->timer, 0); - break; - - /* "factory" POST handling */ - - case LWS_CALLBACK_HTTP_BODY: - /* create the POST argument parser if not already existing */ - if (!pss->spa) { - pss->spa = lws_spa_create(wsi, param_names, - LWS_ARRAY_SIZE(param_names), 1024, - file_upload_cb, pss); - if (!pss->spa) - return -1; - - pss->filename[0] = '\0'; - pss->file_length = 0; - } - //puts((const char *)in); - /* let it parse the POST data */ - if (lws_spa_process(pss->spa, in, len)) - return -1; - break; - - case LWS_CALLBACK_HTTP_BODY_COMPLETION: - lwsl_notice("LWS_CALLBACK_HTTP_BODY_COMPLETION (scan)\n"); - /* call to inform no more payload data coming */ - lws_spa_finalize(pss->spa); - - for (n = 0; n < LWS_ARRAY_SIZE(param_names); n++) - if (lws_spa_get_string(pss->spa, n)) - lwsl_notice(" Param %s: %s\n", param_names[n], - lws_spa_get_string(pss->spa, n)); - else - lwsl_notice(" Param %s: (none)\n", - param_names[n]); - - if (nvs_open("lws-station", NVS_READWRITE, &nvh) != ESP_OK) { - lwsl_err("Unable to open nvs\n"); - break; - } - - if (lws_esp32_get_reboot_type() == LWS_MAGIC_REBOOT_TYPE_FORCED_FACTORY_BUTTON) { - - if (lws_spa_get_string(pss->spa, EPN_SERIAL)) { - if (lws_nvs_set_str(nvh, "serial", lws_spa_get_string(pss->spa, EPN_SERIAL)) != ESP_OK) { - lwsl_err("Unable to store serial in nvm\n"); - goto bail_nvs; - } - - nvs_commit(nvh); - } - - if (lws_spa_get_string(pss->spa, EPN_OPTS)) { - if (lws_nvs_set_str(nvh, "opts", lws_spa_get_string(pss->spa, EPN_OPTS)) != ESP_OK) { - lwsl_err("Unable to store options in nvm\n"); - goto bail_nvs; - } - - nvs_commit(nvh); - } - } - - if (lws_spa_get_string(pss->spa, EPN_GROUP)) { - if (lws_nvs_set_str(nvh, "group", lws_spa_get_string(pss->spa, EPN_GROUP)) != ESP_OK) { - lwsl_err("Unable to store group in nvm\n"); - goto bail_nvs; - } - - nvs_commit(nvh); - } - - if (lws_spa_get_string(pss->spa, EPN_ROLE)) { - if (lws_nvs_set_str(nvh, "role", lws_spa_get_string(pss->spa, EPN_ROLE)) != ESP_OK) { - lwsl_err("Unable to store group in nvm\n"); - goto bail_nvs; - } - - nvs_commit(nvh); - } - - nvs_close(nvh); - - pss->result_len = snprintf(pss->result + LWS_PRE, sizeof(pss->result) - LWS_PRE - 1, - "OK"); - - if (lws_add_http_header_status(wsi, HTTP_STATUS_OK, &p, end)) - goto bail; - - if (lws_add_http_header_by_token(wsi, WSI_TOKEN_HTTP_CONTENT_TYPE, - (unsigned char *)"text/html", 9, &p, end)) - goto bail; - if (lws_add_http_header_content_length(wsi, pss->result_len, &p, end)) - goto bail; - if (lws_finalize_http_header(wsi, &p, end)) - goto bail; - - n = lws_write(wsi, start, p - start, LWS_WRITE_HTTP_HEADERS); - goto bail; - - case LWS_CALLBACK_HTTP_WRITEABLE: - lwsl_debug("LWS_CALLBACK_HTTP_WRITEABLE: sending %d\n", - pss->result_len); - if (!pss->result_len) - break; - n = lws_write(wsi, (unsigned char *)pss->result + LWS_PRE, - pss->result_len, LWS_WRITE_HTTP); - if (n < 0) - return 1; - - vhd->reboot_timer = xTimerCreate("x", pdMS_TO_TICKS(3000), 0, vhd, - (TimerCallbackFunction_t)reboot_timer_cb); - xTimerStart(vhd->reboot_timer, 0); - - return 1; // hang up since we will reset - - /* ----- client handling ----- */ - - case LWS_CALLBACK_CLIENT_CONNECTION_ERROR: - lwsl_notice("Client connection error %s\n", (char *)in); - vhd->cwsi = NULL; - break; - - case LWS_CALLBACK_ESTABLISHED_CLIENT_HTTP: - if (!vhd->autonomous_update) - break; - - { - char pp[20]; - - if (lws_hdr_copy(wsi, pp, sizeof(pp) - 1, WSI_TOKEN_HTTP_CONTENT_LENGTH) < 0) - return -1; - - vhd->content_length = atoi(pp); - if (vhd->content_length <= 0 || - vhd->content_length > vhd->part->size) - return -1; - - if (esp_ota_begin(vhd->part, (long)-1, &vhd->otahandle) != ESP_OK) { - lwsl_err("OTA: Failed to begin\n"); - return 1; - } - - vhd->file_length = 0; - break; - } - break; - - case LWS_CALLBACK_RECEIVE_CLIENT_HTTP_READ: - //lwsl_notice("LWS_CALLBACK_RECEIVE_CLIENT_HTTP_READ: %ld\n", - // (long)len); - - if (!vhd->autonomous_update) { - if (sizeof(vhd->json) - vhd->json_len - 1 < len) - len = sizeof(vhd->json) - vhd->json_len - 1; - memcpy(vhd->json + vhd->json_len, in, len); - vhd->json_len += len; - vhd->json[vhd->json_len] = '\0'; - break; - } - - /* autonomous download */ - - - if (vhd->file_length + len > vhd->part->size) { - lwsl_err("OTA: incoming file too large\n"); - goto abort_ota; - } - - lwsl_debug("writing 0x%lx... 0x%lx\n", - vhd->part->address + vhd->file_length, - vhd->part->address + vhd->file_length + len); - if (esp_ota_write(vhd->otahandle, in, len) != ESP_OK) { - lwsl_err("OTA: Failed to write\n"); - goto abort_ota; - } - vhd->file_length += len; - - lws_callback_on_writable_all_protocol(vhd->context, vhd->protocol); - break; - -abort_ota: - esp_ota_end(vhd->otahandle); - vhd->otahandle = 0; - vhd->autonomous_update = 0; - - return 1; - - case LWS_CALLBACK_RECEIVE_CLIENT_HTTP: - { - char *px = (char *)pss->buffer + LWS_PRE; - int lenx = sizeof(pss->buffer) - LWS_PRE - 1; - - //lwsl_notice("LWS_CALLBACK_RECEIVE_CLIENT_HTTP: %d\n", len); - - if (lws_http_client_read(wsi, &px, &lenx) < 0) - return -1; - } - break; - - case LWS_CALLBACK_COMPLETED_CLIENT_HTTP: - lwsl_notice("LWS_CALLBACK_COMPLETED_CLIENT_HTTP\n"); - vhd->cwsi = NULL; - if (!vhd->autonomous_update) { - - vhd->checked_updates = 1; - puts(vhd->json); - return -1; - } - - /* autonomous download */ - - lwsl_notice("auton complete\n"); - - if (esp_ota_end(vhd->otahandle) != ESP_OK) { - lwsl_err("OTA: end failed\n"); - return 1; - } - - if (esp_ota_set_boot_partition(vhd->part) != ESP_OK) { - lwsl_err("OTA: set boot part failed\n"); - return 1; - } - vhd->otahandle = 0; - vhd->autonomous_update = 0; - - vhd->reboot_timer = xTimerCreate("x", pdMS_TO_TICKS(250), 0, vhd, - (TimerCallbackFunction_t)reboot_timer_cb); - xTimerStart(vhd->reboot_timer, 0); - return -1; - - case LWS_CALLBACK_CLOSED_CLIENT_HTTP: - lwsl_notice("LWS_CALLBACK_CLOSED_CLIENT_HTTP\n"); - break; - - case LWS_CALLBACK_HTTP_DROP_PROTOCOL: - /* called when our wsi user_space is going to be destroyed */ - if (pss->spa) { - lws_spa_destroy(pss->spa); - pss->spa = NULL; - } - break; - - default: - break; - } - - return 0; - -bail: - return 1; -} - -#define LWS_PLUGIN_PROTOCOL_ESPLWS_SCAN \ - { \ - "esplws-scan", \ - callback_esplws_scan, \ - sizeof(struct per_session_data__esplws_scan), \ - 1024, 0, NULL, 900 \ - } - diff -Nru libwebsockets-3.2.1/plugins/protocol_fulltext_demo.c libwebsockets-4.1.6/plugins/protocol_fulltext_demo.c --- libwebsockets-3.2.1/plugins/protocol_fulltext_demo.c 2019-12-18 14:45:31.000000000 +0000 +++ libwebsockets-4.1.6/plugins/protocol_fulltext_demo.c 2020-12-01 17:40:26.000000000 +0000 @@ -266,28 +266,17 @@ LWS_PLUGIN_PROTOCOL_FULLTEXT_DEMO }; -LWS_EXTERN LWS_VISIBLE int -init_protocol_fulltext_demo(struct lws_context *context, - struct lws_plugin_capability *c) -{ - if (c->api_magic != LWS_PLUGIN_API_MAGIC) { - lwsl_err("Plugin API %d, library API %d", LWS_PLUGIN_API_MAGIC, - c->api_magic); - return 1; - } +LWS_VISIBLE const lws_plugin_protocol_t fulltext_demo = { + .hdr = { + "fulltext demo", + "lws_protocol_plugin", + LWS_PLUGIN_API_MAGIC + }, - c->protocols = protocols; - c->count_protocols = LWS_ARRAY_SIZE(protocols); - c->extensions = NULL; - c->count_extensions = 0; - - return 0; -} - -LWS_EXTERN LWS_VISIBLE int -destroy_protocol_fulltext_demo(struct lws_context *context) -{ - return 0; -} + .protocols = protocols, + .count_protocols = LWS_ARRAY_SIZE(protocols), + .extensions = NULL, + .count_extensions = 0, +}; #endif diff -Nru libwebsockets-3.2.1/plugins/protocol_lws_mirror.c libwebsockets-4.1.6/plugins/protocol_lws_mirror.c --- libwebsockets-3.2.1/plugins/protocol_lws_mirror.c 2019-12-18 14:45:31.000000000 +0000 +++ libwebsockets-4.1.6/plugins/protocol_lws_mirror.c 2020-12-01 17:40:26.000000000 +0000 @@ -206,6 +206,15 @@ switch (reason) { case LWS_CALLBACK_ESTABLISHED: lwsl_info("%s: LWS_CALLBACK_ESTABLISHED\n", __func__); + if (!v) { + lws_protocol_vh_priv_zalloc(lws_get_vhost(wsi), + lws_get_protocol(wsi), + sizeof(struct per_vhost_data__lws_mirror)); + v = (struct per_vhost_data__lws_mirror *) + lws_protocol_vh_priv_get(lws_get_vhost(wsi), + lws_get_protocol(wsi)); + lws_pthread_mutex_init(&v->lock); + } /* * mirror instance name... defaults to "", but if URL includes @@ -332,13 +341,15 @@ return 1; /* disallow compression */ case LWS_CALLBACK_PROTOCOL_INIT: /* per vhost */ - lws_protocol_vh_priv_zalloc(lws_get_vhost(wsi), + if (!v) { + lws_protocol_vh_priv_zalloc(lws_get_vhost(wsi), lws_get_protocol(wsi), sizeof(struct per_vhost_data__lws_mirror)); - v = (struct per_vhost_data__lws_mirror *) + v = (struct per_vhost_data__lws_mirror *) lws_protocol_vh_priv_get(lws_get_vhost(wsi), lws_get_protocol(wsi)); - lws_pthread_mutex_init(&v->lock); + lws_pthread_mutex_init(&v->lock); + } break; case LWS_CALLBACK_PROTOCOL_DESTROY: @@ -471,27 +482,17 @@ LWS_PLUGIN_PROTOCOL_MIRROR }; -LWS_EXTERN LWS_VISIBLE int -init_protocol_lws_mirror(struct lws_context *context, - struct lws_plugin_capability *c) -{ - if (c->api_magic != LWS_PLUGIN_API_MAGIC) { - lwsl_err("Plugin API %d, library API %d", LWS_PLUGIN_API_MAGIC, - c->api_magic); - return 1; - } - - c->protocols = protocols; - c->count_protocols = LWS_ARRAY_SIZE(protocols); - c->extensions = NULL; - c->count_extensions = 0; - - return 0; -} +LWS_VISIBLE const lws_plugin_protocol_t lws_mirror = { + .hdr = { + "lws mirror", + "lws_protocol_plugin", + LWS_PLUGIN_API_MAGIC + }, + + .protocols = protocols, + .count_protocols = LWS_ARRAY_SIZE(protocols), + .extensions = NULL, + .count_extensions = 0, +}; -LWS_EXTERN LWS_VISIBLE int -destroy_protocol_lws_mirror(struct lws_context *context) -{ - return 0; -} #endif diff -Nru libwebsockets-3.2.1/plugins/protocol_lws_raw_test.c libwebsockets-4.1.6/plugins/protocol_lws_raw_test.c --- libwebsockets-3.2.1/plugins/protocol_lws_raw_test.c 2019-12-18 14:45:31.000000000 +0000 +++ libwebsockets-4.1.6/plugins/protocol_lws_raw_test.c 2020-12-01 17:40:26.000000000 +0000 @@ -72,6 +72,9 @@ #endif #include +#include + +#include struct per_vhost_data__raw_test { struct lws_context *context; @@ -278,28 +281,17 @@ LWS_PLUGIN_PROTOCOL_RAW_TEST }; -LWS_EXTERN LWS_VISIBLE int -init_protocol_lws_raw_test(struct lws_context *context, - struct lws_plugin_capability *c) -{ - if (c->api_magic != LWS_PLUGIN_API_MAGIC) { - lwsl_err("Plugin API %d, library API %d", LWS_PLUGIN_API_MAGIC, - c->api_magic); - return 1; - } - - c->protocols = protocols; - c->count_protocols = LWS_ARRAY_SIZE(protocols); - c->extensions = NULL; - c->count_extensions = 0; - - return 0; -} - -LWS_EXTERN LWS_VISIBLE int -destroy_protocol_lws_raw_test(struct lws_context *context) -{ - return 0; -} +LWS_VISIBLE const lws_plugin_protocol_t lws_raw_test = { + .hdr = { + "lws raw test", + "lws_protocol_plugin", + LWS_PLUGIN_API_MAGIC + }, + + .protocols = protocols, + .count_protocols = LWS_ARRAY_SIZE(protocols), + .extensions = NULL, + .count_extensions = 0, +}; #endif diff -Nru libwebsockets-3.2.1/plugins/protocol_lws_server_status.c libwebsockets-4.1.6/plugins/protocol_lws_server_status.c --- libwebsockets-3.2.1/plugins/protocol_lws_server_status.c 2019-12-18 14:45:31.000000000 +0000 +++ libwebsockets-4.1.6/plugins/protocol_lws_server_status.c 2020-12-01 17:40:26.000000000 +0000 @@ -47,6 +47,7 @@ struct lws_context *context; struct lws_vhost *vhost; const struct lws_protocols *protocol; + lws_sorted_usec_list_t sul; int hide_vhosts; int tow_flag; int period_s; @@ -58,8 +59,9 @@ static const struct lws_protocols protocols[1]; static void -update(struct vhd *v) +update(struct lws_sorted_usec_list *sul) { + struct vhd *v = lws_container_of(sul, struct vhd, sul); struct lws_ss_filepath *fp; char contents[256], pure[256], *p = v->d.buf + LWS_PRE, *end = v->d.buf + sizeof(v->d.buf) - LWS_PRE - 1; @@ -82,7 +84,7 @@ close(fd); if (n >= 0) { contents[n] = '\0'; - lws_json_purify(pure, contents, sizeof(pure)); + lws_json_purify(pure, contents, sizeof(pure), NULL); } } @@ -97,6 +99,8 @@ v->d.length = p - (v->d.buf + LWS_PRE); lws_callback_on_writable_all_protocol(v->context, &protocols[0]); + + lws_sul_schedule(v->context, 0, &v->sul, update, v->period_s * LWS_US_PER_SEC); } static int @@ -116,12 +120,9 @@ case LWS_CALLBACK_ESTABLISHED: lwsl_info("%s: LWS_CALLBACK_ESTABLISHED\n", __func__); if (!v->clients++) { - lws_timed_callback_vh_protocol(v->vhost, v->protocol, - LWS_CALLBACK_USER, v->period_s); + lws_sul_schedule(lws_get_context(wsi), 0, &v->sul, update, 1); lwsl_info("%s: starting updates\n", __func__); } - update(v); - break; case LWS_CALLBACK_CLOSED: @@ -130,13 +131,6 @@ break; - case LWS_CALLBACK_USER: - update(v); - if (v->clients) - lws_timed_callback_vh_protocol(v->vhost, v->protocol, - LWS_CALLBACK_USER, v->period_s); - break; - case LWS_CALLBACK_PROTOCOL_INIT: /* per vhost */ if (v) break; @@ -158,6 +152,8 @@ v->period_s = 5; if (!strcmp(pvo->name, "filepath")) { fp = malloc(sizeof(*fp)); + if (!fp) + return -1; fp->next = NULL; lws_snprintf(&fp->filepath[0], sizeof(fp->filepath), "%s", @@ -171,8 +167,7 @@ v->vhost = lws_get_vhost(wsi); v->protocol = lws_get_protocol(wsi); - /* get the initial data */ - update(v); + lws_sul_schedule(lws_get_context(wsi), 0, &v->sul, update, 1); break; case LWS_CALLBACK_PROTOCOL_DESTROY: /* per vhost */ @@ -209,26 +204,15 @@ }, }; -LWS_EXTERN LWS_VISIBLE int -init_protocol_lws_server_status(struct lws_context *context, - struct lws_plugin_capability *c) -{ - if (c->api_magic != LWS_PLUGIN_API_MAGIC) { - lwsl_err("Plugin API %d, library API %d", - LWS_PLUGIN_API_MAGIC, c->api_magic); - return 1; - } - - c->protocols = protocols; - c->count_protocols = LWS_ARRAY_SIZE(protocols); - c->extensions = NULL; - c->count_extensions = 0; - - return 0; -} +LWS_VISIBLE const lws_plugin_protocol_t lws_server_status = { + .hdr = { + "lws server status", + "lws_protocol_plugin", + LWS_PLUGIN_API_MAGIC + }, -LWS_EXTERN LWS_VISIBLE int -destroy_protocol_lws_server_status(struct lws_context *context) -{ - return 0; -} + .protocols = protocols, + .count_protocols = LWS_ARRAY_SIZE(protocols), + .extensions = NULL, + .count_extensions = 0, +}; diff -Nru libwebsockets-3.2.1/plugins/protocol_lws_sshd_demo.c libwebsockets-4.1.6/plugins/protocol_lws_sshd_demo.c --- libwebsockets-3.2.1/plugins/protocol_lws_sshd_demo.c 2019-12-18 14:45:31.000000000 +0000 +++ libwebsockets-4.1.6/plugins/protocol_lws_sshd_demo.c 2020-12-01 17:40:26.000000000 +0000 @@ -29,6 +29,7 @@ #include #include #include +#include #define TEST_SERVER_KEY_PATH "/etc/lws-test-sshd-server-key" @@ -455,28 +456,17 @@ LWS_PLUGIN_PROTOCOL_LWS_SSHD_DEMO }; -LWS_EXTERN LWS_VISIBLE int -init_protocol_lws_sshd_demo(struct lws_context *context, - struct lws_plugin_capability *c) -{ - if (c->api_magic != LWS_PLUGIN_API_MAGIC) { - lwsl_err("Plugin API %d, library API %d", LWS_PLUGIN_API_MAGIC, - c->api_magic); - return 1; - } - - c->protocols = protocols; - c->count_protocols = LWS_ARRAY_SIZE(protocols); - c->extensions = NULL; - c->count_extensions = 0; - - return 0; -} - -LWS_EXTERN LWS_VISIBLE int -destroy_protocol_lws_sshd_demo(struct lws_context *context) -{ - return 0; -} +LWS_VISIBLE const lws_plugin_protocol_t lws_sshd_demo = { + .hdr = { + "lws sshd demo", + "lws_protocol_plugin", + LWS_PLUGIN_API_MAGIC + }, + + .protocols = protocols, + .count_protocols = LWS_ARRAY_SIZE(protocols), + .extensions = NULL, + .count_extensions = 0, +}; #endif diff -Nru libwebsockets-3.2.1/plugins/protocol_lws_status.c libwebsockets-4.1.6/plugins/protocol_lws_status.c --- libwebsockets-3.2.1/plugins/protocol_lws_status.c 2019-12-18 14:45:31.000000000 +0000 +++ libwebsockets-4.1.6/plugins/protocol_lws_status.c 2020-12-01 17:40:26.000000000 +0000 @@ -120,8 +120,10 @@ time(&pss->time_est); pss->wsi = wsi; +#if defined(LWS_WITH_HTTP_UNCOMMON_HEADERS) if (lws_hdr_copy(wsi, pss->user_agent, sizeof(pss->user_agent), WSI_TOKEN_HTTP_USER_AGENT) < 0) /* too big */ +#endif strcpy(pss->user_agent, "unknown"); trigger_resend(vhd); break; @@ -243,29 +245,17 @@ LWS_PLUGIN_PROTOCOL_LWS_STATUS }; - -LWS_EXTERN LWS_VISIBLE int -init_protocol_lws_status(struct lws_context *context, - struct lws_plugin_capability *c) -{ - if (c->api_magic != LWS_PLUGIN_API_MAGIC) { - lwsl_err("Plugin API %d, library API %d", LWS_PLUGIN_API_MAGIC, - c->api_magic); - return 1; - } - - c->protocols = protocols; - c->count_protocols = LWS_ARRAY_SIZE(protocols); - c->extensions = NULL; - c->count_extensions = 0; - - return 0; -} - -LWS_EXTERN LWS_VISIBLE int -destroy_protocol_lws_status(struct lws_context *context) -{ - return 0; -} +LWS_VISIBLE const lws_plugin_protocol_t lws_status = { + .hdr = { + "lws status", + "lws_protocol_plugin", + LWS_PLUGIN_API_MAGIC + }, + + .protocols = protocols, + .count_protocols = LWS_ARRAY_SIZE(protocols), + .extensions = NULL, + .count_extensions = 0, +}; #endif diff -Nru libwebsockets-3.2.1/plugins/protocol_post_demo.c libwebsockets-4.1.6/plugins/protocol_post_demo.c --- libwebsockets-3.2.1/plugins/protocol_post_demo.c 2019-12-18 14:45:31.000000000 +0000 +++ libwebsockets-4.1.6/plugins/protocol_post_demo.c 2020-12-01 17:40:26.000000000 +0000 @@ -80,7 +80,7 @@ * simple demo use a fixed name so we don't have to deal with * attacks */ #if !defined(LWS_WITH_ESP32) - pss->fd = (lws_filefd_type)(long long)lws_open("/tmp/post-file", + pss->fd = (lws_filefd_type)(lws_intptr_t)lws_open("/tmp/post-file", O_CREAT | O_TRUNC | O_RDWR, 0600); #endif break; @@ -94,7 +94,7 @@ return 1; #if !defined(LWS_WITH_ESP32) - n = write((int)(long long)pss->fd, buf, len); + n = write((int)(lws_intptr_t)pss->fd, buf, len); lwsl_info("%s: write %d says %d\n", __func__, len, n); #else lwsl_notice("%s: Received chunk size %d\n", __func__, len); @@ -103,7 +103,7 @@ if (state == LWS_UFS_CONTENT) break; #if !defined(LWS_WITH_ESP32) - close((int)(long long)pss->fd); + close((int)(lws_intptr_t)pss->fd); pss->fd = LWS_INVALID_FILE; #endif break; @@ -287,28 +287,17 @@ LWS_PLUGIN_PROTOCOL_POST_DEMO }; -LWS_EXTERN LWS_VISIBLE int -init_protocol_post_demo(struct lws_context *context, - struct lws_plugin_capability *c) -{ - if (c->api_magic != LWS_PLUGIN_API_MAGIC) { - lwsl_err("Plugin API %d, library API %d", LWS_PLUGIN_API_MAGIC, - c->api_magic); - return 1; - } - - c->protocols = protocols; - c->count_protocols = LWS_ARRAY_SIZE(protocols); - c->extensions = NULL; - c->count_extensions = 0; - - return 0; -} - -LWS_EXTERN LWS_VISIBLE int -destroy_protocol_post_demo(struct lws_context *context) -{ - return 0; -} +LWS_VISIBLE const lws_plugin_protocol_t post_demo = { + .hdr = { + "post demo", + "lws_protocol_plugin", + LWS_PLUGIN_API_MAGIC + }, + + .protocols = protocols, + .count_protocols = LWS_ARRAY_SIZE(protocols), + .extensions = NULL, + .count_extensions = 0, +}; #endif diff -Nru libwebsockets-3.2.1/plugins/raw-proxy/protocol_lws_raw_proxy.c libwebsockets-4.1.6/plugins/raw-proxy/protocol_lws_raw_proxy.c --- libwebsockets-3.2.1/plugins/raw-proxy/protocol_lws_raw_proxy.c 2019-12-18 14:45:31.000000000 +0000 +++ libwebsockets-4.1.6/plugins/raw-proxy/protocol_lws_raw_proxy.c 2020-12-01 17:40:26.000000000 +0000 @@ -1,22 +1,25 @@ /* - * libwebsockets - plugin for raw proxying + * libwebsockets - small server side websockets and web server implementation * - * Copyright (C) 2010-2018 Andy Green + * Copyright (C) 2010 - 2019 Andy Green * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation: - * version 2.1 of the License. + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to + * deal in the Software without restriction, including without limitation the + * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or + * sell copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: * - * This library is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. * - * You should have received a copy of the GNU Lesser General Public - * License along with this library; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, - * MA 02110-1301 USA + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS + * IN THE SOFTWARE. */ #if !defined (LWS_PLUGIN_STATIC) @@ -249,10 +252,12 @@ break; case LWS_CALLBACK_RAW_PROXY_CLI_ADOPT: - lwsl_debug("LWS_CALLBACK_RAW_CLI_ADOPT: pss %p\n", pss); + lwsl_debug("%s: %p: LWS_CALLBACK_RAW_CLI_ADOPT: pss %p\n", __func__, wsi, pss); if (conn || !pss) break; conn = pss->conn = lws_get_opaque_user_data(wsi); + if (!conn) + break; conn->established[ONW] = 1; /* they start enabled */ conn->rx_enabled[ACC] = 1; @@ -442,6 +447,9 @@ return -1; } + if (!len) + return 0; + pkt.payload = malloc(len); if (!pkt.payload) { lwsl_notice("OOM: dropping\n"); @@ -554,29 +562,18 @@ LWS_PLUGIN_PROTOCOL_RAW_PROXY }; -LWS_EXTERN LWS_VISIBLE int -init_protocol_lws_raw_proxy(struct lws_context *context, - struct lws_plugin_capability *c) -{ - if (c->api_magic != LWS_PLUGIN_API_MAGIC) { - lwsl_err("Plugin API %d, library API %d", LWS_PLUGIN_API_MAGIC, - c->api_magic); - return 1; - } - - c->protocols = protocols; - c->count_protocols = LWS_ARRAY_SIZE(protocols); - c->extensions = NULL; - c->count_extensions = 0; - - return 0; -} - -LWS_EXTERN LWS_VISIBLE int -destroy_protocol_lws_raw_proxy(struct lws_context *context) -{ - return 0; -} +LWS_VISIBLE const lws_plugin_protocol_t lws_raw_proxy = { + .hdr = { + "raw proxy", + "lws_protocol_plugin", + LWS_PLUGIN_API_MAGIC + }, + + .protocols = protocols, + .count_protocols = LWS_ARRAY_SIZE(protocols), + .extensions = NULL, + .count_extensions = 0, +}; #endif diff -Nru libwebsockets-3.2.1/plugins/server-status.js libwebsockets-4.1.6/plugins/server-status.js --- libwebsockets-3.2.1/plugins/server-status.js 2019-12-18 14:45:31.000000000 +0000 +++ libwebsockets-4.1.6/plugins/server-status.js 2020-12-01 17:40:26.000000000 +0000 @@ -29,8 +29,6 @@ return s; } - var pos = 0; - function get_appropriate_ws_url() { var pcol; diff -Nru libwebsockets-3.2.1/plugins/ssh-base/crypto/sc25519.c libwebsockets-4.1.6/plugins/ssh-base/crypto/sc25519.c --- libwebsockets-3.2.1/plugins/ssh-base/crypto/sc25519.c 2019-12-18 14:45:31.000000000 +0000 +++ libwebsockets-4.1.6/plugins/ssh-base/crypto/sc25519.c 2020-12-01 17:40:26.000000000 +0000 @@ -68,8 +68,8 @@ if(i+j >= 31) q2[i+j] += mu[i]*x[j+31]; carry = q2[31] >> 8; q2[32] += carry; - carry = q2[32] >> 8; - q2[33] += carry; + //carry = q2[32] >> 8; + //q2[33] += carry; for(i=0;i<33;i++)r1[i] = x[i]; for(i=0;i<32;i++) diff -Nru libwebsockets-3.2.1/plugins/ssh-base/include/lws-plugin-ssh.h libwebsockets-4.1.6/plugins/ssh-base/include/lws-plugin-ssh.h --- libwebsockets-3.2.1/plugins/ssh-base/include/lws-plugin-ssh.h 2019-12-18 14:45:31.000000000 +0000 +++ libwebsockets-4.1.6/plugins/ssh-base/include/lws-plugin-ssh.h 2020-12-01 17:40:26.000000000 +0000 @@ -1,22 +1,25 @@ /* - * libwebsockets - lws-plugin-ssh-base + * libwebsockets - small server side websockets and web server implementation * - * Copyright (C) 2017 Andy Green + * Copyright (C) 2010 - 2019 Andy Green * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation: - * version 2.1 of the License. + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to + * deal in the Software without restriction, including without limitation the + * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or + * sell copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: * - * This library is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. * - * You should have received a copy of the GNU Lesser General Public - * License along with this library; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, - * MA 02110-1301 USA + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS + * IN THE SOFTWARE. */ #if !defined(__LWS_PLUGIN_SSH_H__) diff -Nru libwebsockets-3.2.1/plugins/ssh-base/include/lws-ssh.h libwebsockets-4.1.6/plugins/ssh-base/include/lws-ssh.h --- libwebsockets-3.2.1/plugins/ssh-base/include/lws-ssh.h 2019-12-18 14:45:31.000000000 +0000 +++ libwebsockets-4.1.6/plugins/ssh-base/include/lws-ssh.h 2020-12-01 17:40:26.000000000 +0000 @@ -1,22 +1,25 @@ /* - * libwebsockets - lws-plugin-ssh-base + * libwebsockets - small server side websockets and web server implementation * - * Copyright (C) 2017 Andy Green + * Copyright (C) 2010 - 2019 Andy Green * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation: - * version 2.1 of the License. + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to + * deal in the Software without restriction, including without limitation the + * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or + * sell copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: * - * This library is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. * - * You should have received a copy of the GNU Lesser General Public - * License along with this library; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, - * MA 02110-1301 USA + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS + * IN THE SOFTWARE. */ #if !defined(__LWS_SSH_H__) diff -Nru libwebsockets-3.2.1/plugins/ssh-base/kex-25519.c libwebsockets-4.1.6/plugins/ssh-base/kex-25519.c --- libwebsockets-3.2.1/plugins/ssh-base/kex-25519.c 2019-12-18 14:45:31.000000000 +0000 +++ libwebsockets-4.1.6/plugins/ssh-base/kex-25519.c 2020-12-01 17:40:26.000000000 +0000 @@ -1,23 +1,27 @@ /* - * libwebsockets - lws-plugin-ssh-base - kex-25519.c + * libwebsockets - small server side websockets and web server implementation * - * Copyright (C) 2017 Andy Green + * Copyright (C) 2010 - 2019 Andy Green * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation: - * version 2.1 of the License. + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to + * deal in the Software without restriction, including without limitation the + * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or + * sell copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: * - * This library is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. * - * You should have received a copy of the GNU Lesser General Public - * License along with this library; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, - * MA 02110-1301 USA + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS + * IN THE SOFTWARE. */ + #include "libwebsockets.h" #include "lws-ssh.h" diff -Nru libwebsockets-3.2.1/plugins/ssh-base/sshd.c libwebsockets-4.1.6/plugins/ssh-base/sshd.c --- libwebsockets-3.2.1/plugins/ssh-base/sshd.c 2019-12-18 14:45:31.000000000 +0000 +++ libwebsockets-4.1.6/plugins/ssh-base/sshd.c 2020-12-01 17:40:26.000000000 +0000 @@ -1,22 +1,25 @@ /* - * libwebsockets - lws-plugin-ssh-base - sshd.c + * libwebsockets - small server side websockets and web server implementation * - * Copyright (C) 2017 - 2018 Andy Green + * Copyright (C) 2010 - 2019 Andy Green * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation: - * version 2.1 of the License. + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to + * deal in the Software without restriction, including without limitation the + * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or + * sell copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: * - * This library is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. * - * You should have received a copy of the GNU Lesser General Public - * License along with this library; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, - * MA 02110-1301 USA + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS + * IN THE SOFTWARE. */ #include "libwebsockets.h" @@ -2555,34 +2558,24 @@ 1024, 0, NULL, 900 \ } -LWS_VISIBLE const struct lws_protocols protocols_sshd[] = { +const struct lws_protocols protocols_sshd[] = { LWS_PLUGIN_PROTOCOL_LWS_RAW_SSHD, { NULL, NULL, 0, 0, 0, NULL, 0 } /* terminator */ }; #if !defined (LWS_PLUGIN_STATIC) -LWS_VISIBLE int -init_protocol_lws_ssh_base(struct lws_context *context, - struct lws_plugin_capability *c) -{ - if (c->api_magic != LWS_PLUGIN_API_MAGIC) { - lwsl_err("Plugin API %d, library API %d", LWS_PLUGIN_API_MAGIC, - c->api_magic); - return 1; - } - - c->protocols = protocols_sshd; - c->count_protocols = LWS_ARRAY_SIZE(protocols_sshd); - c->extensions = NULL; - c->count_extensions = 0; - - return 0; -} +LWS_VISIBLE const lws_plugin_protocol_t lws_ssh_base = { + .hdr = { + "ssh base", + "lws_protocol_plugin", + LWS_PLUGIN_API_MAGIC + }, + + .protocols = protocols_sshd, + .count_protocols = LWS_ARRAY_SIZE(protocols_sshd), + .extensions = NULL, + .count_extensions = 0, +}; -LWS_VISIBLE int -destroy_protocol_lws_ssh_base(struct lws_context *context) -{ - return 0; -} #endif diff -Nru libwebsockets-3.2.1/plugins/ssh-base/telnet.c libwebsockets-4.1.6/plugins/ssh-base/telnet.c --- libwebsockets-3.2.1/plugins/ssh-base/telnet.c 2019-12-18 14:45:31.000000000 +0000 +++ libwebsockets-4.1.6/plugins/ssh-base/telnet.c 2020-12-01 17:40:26.000000000 +0000 @@ -1,22 +1,25 @@ /* - * libwebsockets - lws-plugin-ssh-base + * libwebsockets - small server side websockets and web server implementation * - * Copyright (C) 2017 Andy Green + * Copyright (C) 2010 - 2019 Andy Green * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation: - * version 2.1 of the License. + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to + * deal in the Software without restriction, including without limitation the + * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or + * sell copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: * - * This library is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. * - * You should have received a copy of the GNU Lesser General Public - * License along with this library; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, - * MA 02110-1301 USA + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS + * IN THE SOFTWARE. */ #include "libwebsockets.h" diff -Nru libwebsockets-3.2.1/plugin-standalone/CMakeLists.txt libwebsockets-4.1.6/plugin-standalone/CMakeLists.txt --- libwebsockets-3.2.1/plugin-standalone/CMakeLists.txt 2019-12-18 14:45:31.000000000 +0000 +++ libwebsockets-4.1.6/plugin-standalone/CMakeLists.txt 2020-12-01 17:40:26.000000000 +0000 @@ -1,4 +1,5 @@ cmake_minimum_required(VERSION 2.8) +find_package(libwebsockets CONFIG REQUIRED) if(NOT DEFINED CMAKE_BUILD_TYPE) set(CMAKE_BUILD_TYPE Release CACHE STRING "Build type") @@ -57,7 +58,7 @@ source_group("Sources" FILES ${PLUGIN_SRCS}) add_library(${PLUGIN_NAME} SHARED ${PLUGIN_SRCS} ${PLUGIN_HDR}) -target_link_libraries(${PLUGIN_NAME} -lwebsockets) +target_link_libraries(${PLUGIN_NAME} -lwebsockets ${LIBWEBSOCKETS_DEP_LIBS}) # Set test app specific defines. set_property(TARGET ${PLUGIN_NAME} diff -Nru libwebsockets-3.2.1/plugin-standalone/protocol_example_standalone.c libwebsockets-4.1.6/plugin-standalone/protocol_example_standalone.c --- libwebsockets-3.2.1/plugin-standalone/protocol_example_standalone.c 2019-12-18 14:45:31.000000000 +0000 +++ libwebsockets-4.1.6/plugin-standalone/protocol_example_standalone.c 2020-12-01 17:40:26.000000000 +0000 @@ -127,26 +127,15 @@ }, }; -LWS_VISIBLE int -init_protocol_example_standalone(struct lws_context *context, - struct lws_plugin_capability *c) -{ - if (c->api_magic != LWS_PLUGIN_API_MAGIC) { - lwsl_err("Plugin API %d, library API %d", LWS_PLUGIN_API_MAGIC, - c->api_magic); - return 1; - } - - c->protocols = protocols; - c->count_protocols = LWS_ARRAY_SIZE(protocols); - c->extensions = NULL; - c->count_extensions = 0; - - return 0; -} +LWS_VISIBLE const lws_plugin_protocol_t protocol_example_standalone = { + .hdr = { + "standalone", + "lws_protocol_plugin", + LWS_PLUGIN_API_MAGIC + }, -LWS_VISIBLE int -destroy_protocol_example_standalone(struct lws_context *context) -{ - return 0; -} + .protocols = protocols, + .count_protocols = LWS_ARRAY_SIZE(protocols), + .extensions = NULL, + .count_extensions = 0, +}; diff -Nru libwebsockets-3.2.1/README.md libwebsockets-4.1.6/README.md --- libwebsockets-3.2.1/README.md 2019-12-18 14:45:31.000000000 +0000 +++ libwebsockets-4.1.6/README.md 2020-12-01 17:40:26.000000000 +0000 @@ -1,14 +1,14 @@ -[![Travis Build Status](https://travis-ci.org/warmcat/libwebsockets.svg)](https://travis-ci.org/warmcat/libwebsockets) [![Appveyor Build status](https://ci.appveyor.com/api/projects/status/qfasji8mnfnd2r8t?svg=true)](https://ci.appveyor.com/project/lws-team/libwebsockets) [![Coverity Scan Build Status](https://scan.coverity.com/projects/3576/badge.svg)](https://scan.coverity.com/projects/3576) [![CII Best Practices](https://bestpractices.coreinfrastructure.org/projects/2266/badge)](https://bestpractices.coreinfrastructure.org/projects/2266) [![Codacy Badge](https://api.codacy.com/project/badge/Grade/144fb195a83046e484a75c8b4c6cfc99)](https://www.codacy.com/app/lws-team/libwebsockets?utm_source=github.com&utm_medium=referral&utm_content=warmcat/libwebsockets&utm_campaign=Badge_Grade) +[![CI status](https://libwebsockets.org/sai/status/libwebsockets)](https://libwebsockets.org/git/libwebsockets) [![Coverity Scan Build Status](https://scan.coverity.com/projects/3576/badge.svg)](https://scan.coverity.com/projects/3576) [![CII Best Practices](https://bestpractices.coreinfrastructure.org/projects/2266/badge)](https://bestpractices.coreinfrastructure.org/projects/2266) [![Codacy Badge](https://api.codacy.com/project/badge/Grade/144fb195a83046e484a75c8b4c6cfc99)](https://www.codacy.com/app/lws-team/libwebsockets?utm_source=github.com&utm_medium=referral&utm_content=warmcat/libwebsockets&utm_campaign=Badge_Grade) [![Total alerts](https://img.shields.io/lgtm/alerts/g/warmcat/libwebsockets.svg?logo=lgtm&logoWidth=18)](https://lgtm.com/projects/g/warmcat/libwebsockets/alerts/) [![Language grade: C/C++](https://img.shields.io/lgtm/grade/cpp/g/warmcat/libwebsockets.svg?logo=lgtm&logoWidth=18)](https://lgtm.com/projects/g/warmcat/libwebsockets/context:cpp) [![Language grade: JavaScript](https://img.shields.io/lgtm/grade/javascript/g/warmcat/libwebsockets.svg?logo=lgtm&logoWidth=18)](https://lgtm.com/projects/g/warmcat/libwebsockets/context:javascript) # Libwebsockets -Libwebsockets is a simple-to-use, pure C library providing client and server -for **http/1**, **http/2**, **websockets** and other protocols in a security-minded, +Libwebsockets is a simple-to-use, MIT-license, pure C library providing client and server +for **http/1**, **http/2**, **websockets**, **MQTT** and other protocols in a security-minded, lightweight, configurable, scalable and flexible way. It's easy to build and cross-build via cmake and is suitable for tasks from embedded RTOS through mass cloud serving. -[50 minimal examples](https://libwebsockets.org/git/libwebsockets/tree/minimal-examples) for +[80 independent minimal examples](https://libwebsockets.org/git/libwebsockets/tree/minimal-examples) for various scenarios, CC0-licensed (public domain) for cut-and-paste, allow you to get started quickly. ![overview](./doc-assets/lws-overview.png) @@ -16,277 +16,414 @@ News ---- -## V3.2 relase last planned LGPLv2.1+SLE release +## v4.1.0 and v4.1-stable are released -As foretold the v3.2 release is the last planned release that will have the code -under LGPLv2.1+SLE. Master has those parts changed to MIT license; the pieces -that were CC0 or another liberal license remain the same. - -## License change plan - -Lws is planning to change the pieces that are currently LGPLv2.1+SLE to MIT -https://opensource.org/licenses/MIT . Stuff that is already CC0 or another -permissive license will stay as it is. - -This license change is making an already permissive license (it was already LGPL, -and the SLE removed most restrictions already) even more permissive. -So I expect most contributors either don't much care or are happy about it. -Contributors who object should contact me via: - - - the lws mailing list https://libwebsockets.org/mailman/listinfo/libwebsockets - - github issue https://github.com/warmcat/libwebsockets , or - - email to `andy@warmcat.com` - -...before **Aug 11 2019**, and I'll rewrite the related code before the change. -There'll be a last release of the currently-licensed stuff (probably v3.2) and -then the same code will have the licese grant changed in the sources, become -master and also have an otherwise identical release, probably v4.0. The v3.2 -stuff won't be maintained (by me anyway... it's FOSS though) but the v4.0 -stuff which is the same except the license will get the usual v4.0-stable -treatment. - -Even after the change I will continue to rely on users to help me with bug -reports and patches, work together on new features. The license will no -longer require it but the practical advantages from staying aligned with -upstream lws for users remain the same. - -## New features on master - - - `LWS_WITH_NETWORK` cmake option (default on) allows one-step removal of vhost, - wsi, roles, event loop and all network-related code from the build. This - enables use-cases where you actually need unrelated features like JOSE or FTS - compactly. lws_context still exists and if tls is enabled, the tls-related code - is still built so the crypto is available, just nothing related to network. - - - New Crypto-agile APIs + JOSE / JWS / JWE / JWK support... apis work exactly - the same with OpenSSL or mbedTLS tls library backends, and allow key cycling - and crypto algorithm changes while allowing for grace periods - - [README.crypto-apis](https://libwebsockets.org/git/libwebsockets/tree/READMEs/README.crypto-apis.md) - - - CMake config simplification for crypto: `-DLWS_WITH_GENCRYPTO=1` for all - generic cipher and hash apis built (which work the same on mbedtls and - OpenSSL transparently), and `-DLWS_WITH_JOSE=1` for all JOSE, JWK, JWS - and JWE support built (which use gencrypto and so also work the same - regardless of tls library backend). - - - **`x.509`** - new generic x509 api allows PEM-based certificate and key - trust relationship verification, and conversion between x.509 keys and - JWK. Works for EC and RSA keys, and on mbedtls and OpenSSl the same. - - [x.509 api](https://libwebsockets.org/git/libwebsockets/tree/include/libwebsockets/lws-x509.h), - [x.509 minimal example](https://libwebsockets.org/git/libwebsockets/tree/minimal-examples/crypto/minimal-crypto-x509) - - - **`JWE`** - JWE (RFC7516) Algorithms with CI tests: - -|Key Encryption|Payload authentication + crypt|Enc + Dec Support| -|---|---|---| -|`RSAES-PKCS1-v1.5` 2048b & 4096b|`AES_128_CBC_HMAC_SHA_256`|Enc + Dec| -|`RSAES-PKCS1-v1.5` 2048b|`AES_192_CBC_HMAC_SHA_384`|Enc + Dec| -|`RSAES-PKCS1-v1.5` 2048b|`AES_256_CBC_HMAC_SHA_512`|Enc + Dec| -|`RSAES-OAEP`|`AES_256_GCM`|Enc + Dec| -|`AES128KW`, `AES192KW`, `AES256KW`|`AES_128_CBC_HMAC_SHA_256`|Enc + Dec| -|`AES128KW`, `AES192KW`, `AES256KW`|`AES_192_CBC_HMAC_SHA_384`|Enc + Dec| -|`AES128KW`, `AES192KW`, `AES256KW`|`AES_256_CBC_HMAC_SHA_512`|Enc + Dec| -|`ECDH-ES` (P-256/384/521 key)|`AES_128/192/256_GCM`|Enc + Dec| -|`ECDH-ES+A128/192/256KW` (P-256/384/521 key)|`AES_128/192/256_GCM`|Enc + Dec| - -All tests pass on both OpenSSL and mbedTLS backends, using keys generated on -both OpenSSL and mbedTLS in the tests. - -A minimal example tool shows how to encrypt and decrypt compact JWE objects -from the commandline for all supported algorithms. - - [jwe api](https://libwebsockets.org/git/libwebsockets/tree/include/libwebsockets/lws-jwe.h), - [jwe unit tests](https://libwebsockets.org/git/libwebsockets/tree/minimal-examples/api-tests/api-test-jose/jwe.c), - [jwe minimal example](https://libwebsockets.org/git/libwebsockets/tree/minimal-examples/crypto/minimal-crypto-jwe) - - - **`lws-genec` ECDSA** - JWS-compatible ECDSA is supported on both OpenSSL and mbedtls. - - - **`JWS`** - JWS (RFC7515) is now supported for none, HS256/384/512, RS256/384/512, and ES256/384/512, on both OpenSSL and mbedtls. There's a minimal example tool that signs and verifies compact - representation JWS from stdin. - [jws api](https://libwebsockets.org/git/libwebsockets/tree/include/libwebsockets/lws-jws.h), - [jws unit tests](https://libwebsockets.org/git/libwebsockets/tree/minimal-examples/api-tests/api-test-jose/jws.c), - [jws minimal example](https://libwebsockets.org/git/libwebsockets/tree/minimal-examples/crypto/minimal-crypto-jwe) - - - **`JWK`** - JWK (RFC7517) now supports oct, RSA and EC keys including JSON key - arrays on both OpenSSL and mbedtls. A minimal example tool shows how to create - new JSON JWK keys to specified parameters from the commandline for all supported - ciphers. - - [jwk minimal example](https://libwebsockets.org/git/libwebsockets/tree/minimal-examples/crypto/minimal-crypto-jwk) - - - **`lws-genrsa` OAEP + PSS support** - in addition to PKCS#1 1.5 padding, OAEP and PSS are - now supported on both mbedtls and openssl backends. - - - **`lws-genaes` Generic AES crypto** - thin api layer works identically with both mbedtls and openssl - backends. Supports CBC, CFB128, CFB8, CTR, ECB, OFB, XTS and GCM variants. Unit tests in CI. - [genaes api](https://libwebsockets.org/git/libwebsockets/tree/include/libwebsockets/lws-genaes.h), - [api test](https://libwebsockets.org/git/libwebsockets/tree/minimal-examples/api-tests/api-test-gencrypto), - CMake config: `-DLWS_WITH_GENCRYPTO=1` - - - **http fallback support** - you can specify a role and protocol to apply if non-http or non-tls - packets arrive at an http(s) listen port. For example, you can specify that the new `raw proxy` - role + protocol should be used, to proxy your sshd port over :443 or :80. Without affecting - normal http(s) serving on those ports but allowing, eg, `ssh -p 443 invalid@libwebsockets.org`. - [http fallback docs](https://libwebsockets.org/git/libwebsockets/tree/READMEs/README.http-fallback.md) - - - **raw tcp proxy role and protocol** - adding raw tcp proxying is now trivial using the built-in lws - implementation. You can control the onward connection using a pvo in the format "ipv4:server.com:port" - [raw proxy minimal example](https://libwebsockets.org/git/libwebsockets/tree/minimal-examples/raw/minimal-raw-proxy), - [raw proxy docs](https://libwebsockets.org/git/libwebsockets/tree/plugins/raw-proxy), - Cmake config: `-DLWS_ROLE_RAW_PROXY=1 -DLWS_WITH_PLUGINS=1` - - - **deaddrop HTML file upload protocol** - protocol and minimal example for file upload and sharing using - drag and drop and a file picker. Integrated with basic auth, uploaded files marked with upload user, - and files owned by the authenticated user may be deleted via the UI. Supports multiple simultaneous - uploads both by drag-and-drop and from the file picker. - [deaddrop minimal example](https://libwebsockets.org/git/libwebsockets/tree/minimal-examples/http-server/minimal-http-server-deaddrop) - - - **basic auth for ws(s)** - You can apply basic auth credential requirement to ws connections same - as on mounts now. Just add a pvo "basic-auth" with the value being the credentials file path when - enabling the ws protocol for the vhost. - -## v3.1 released: new features in v3.1 - - - **lws threadpool** - lightweight pool of pthreads integrated to lws wsi, with all - synchronization to event loop handled internally, queue for excess tasks - [threadpool docs](https://libwebsockets.org/git/libwebsockets/tree/lib/misc/threadpool), - [threadpool minimal example](https://libwebsockets.org/git/libwebsockets/tree/minimal-examples/ws-server/minimal-ws-server-threadpool), - Cmake config: `-DLWS_WITH_THREADPOOL=1` - - - **libdbus support** integrated on lws event loop - [lws dbus docs](https://libwebsockets.org/git/libwebsockets/tree/lib/roles/dbus), - [lws dbus client minimal examples](https://libwebsockets.org/git/libwebsockets/tree/minimal-examples/dbus-client), - [lws dbus server minimal examples](https://libwebsockets.org/git/libwebsockets/tree/minimal-examples/dbus-server), - Cmake config: `-DLWS_ROLE_DBUS=1` - - - **lws allocated chunks (lwsac)** - helpers for optimized mass allocation of small - objects inside a few larger malloc chunks... if you need to allocate a lot of - inter-related structs for a limited time, this removes per-struct allocation - library overhead completely and removes the need for any destruction handling - [lwsac docs](https://libwebsockets.org/git/libwebsockets/tree/lib/misc/lwsac), - [lwsac minimal example](https://libwebsockets.org/git/libwebsockets/tree/minimal-examples/api-tests/api-test-lwsac), - Cmake Config: `-DLWS_WITH_LWSAC=1` - - - **lws tokenizer** - helper api for robustly tokenizing your own strings without - allocating or adding complexity. Configurable by flags for common delimiter - sets and comma-separated-lists in the tokenizer. Detects and reports syntax - errors. - [lws_tokenize docs](https://libwebsockets.org/git/libwebsockets/tree/include/libwebsockets/lws-tokenize.h), - [lws_tokenize minimal example / api test](https://libwebsockets.org/git/libwebsockets/tree/minimal-examples/api-tests/api-test-lws_tokenize) - - - **lws full-text search** - optimized trie generation, serialization, - autocomplete suggestion generation and instant global search support extensible - to huge corpuses of UTF-8 text while remaining super lightweight on resources. - [full-text search docs](https://libwebsockets.org/git/libwebsockets/tree/lib/misc/fts), - [full-text search minimal example / api test](https://libwebsockets.org/git/libwebsockets/tree/minimal-examples/api-tests/api-test-fts), - [demo](https://libwebsockets.org/ftsdemo/), - [demo sources](https://libwebsockets.org/git/libwebsockets/tree/plugins/protocol_fulltext_demo.c), - Cmake config: `-DLWS_WITH_FTS=1 -DLWS_WITH_LWSAC=1` - - - **gzip + brotli http server-side compression** - h1 and h2 detection of client support - for server compression, and auto-application to files with mimetypes "text/*", - "application/javascript" and "image/svg.xml". - Cmake config: `-DLWS_WITH_HTTP_STREAM_COMPRESSION=1` for gzip, optionally also give - `-DLWS_WITH_HTTP_BROTLI=1` for preferred `br` brotli compression - - - **managed disk cache** - API for managing a directory containing cached files - with hashed names, and automatic deletion of LRU files once the cache is - above a given limit. - [lws diskcache docs](https://libwebsockets.org/git/libwebsockets/tree/include/libwebsockets/lws-diskcache.h), - Cmake config: `-DLWS_WITH_DISKCACHE=1` - - - **http reverse proxy** - lws mounts support proxying h1 or h2 requests to - a local or remote IP, or unix domain socket over h1. This allows microservice - type architectures where parts of the common URL space are actually handled - by external processes which may be remote or on the same machine. - [lws gitohashi serving](https://libwebsockets.org/git/) is handled this way. - [unix domain sockets reverse proxy docs](https://libwebsockets.org/git/libwebsockets/tree/READMEs/README.unix-domain-reverse-proxy.md), - CMake config: `-DLWS_WITH_HTTP_PROXY=1` and `-DLWS_UNIX_SOCK=1` for Unix Domain Sockets - - - **update minimal examples for strict Content Security Policy** the minimal - examples now show the best practices around Content Security Policy and - disabling inline Javascript. Updated examples that are served with the - recommended security restrictions show a new "Strict Content Security Policy" - graphic. [Read how to upgrade your applications to use a strict CSP](https://libwebsockets.org/git/libwebsockets/tree/READMEs/README.content-security-policy.md). - - - **release policy docs** - unsure what branch, version or tag to use, or how - to follow master cleanly? [Read the release policy docs](https://libwebsockets.org/git/libwebsockets/tree/READMEs/README.release-policy.md) - which explain how and why lws is developed, released and maintained. - -## v3.0.1 released - -See the git log for the list of fixes. - -## v3.0.0 released - -See the changelog for info https://libwebsockets.org/git/libwebsockets/tree/changelog?h=v3.0-stable - -## Major CI improvements for QA - -The Travis build of lws done on every commit now runs: - -Tests|Count|Explanation ----|---|--- -Build / Linux / gcc|16|-Wall -Werror cmake config variants -Build / Mac / Clang|16|-Wall -Werror cmake config variants -Build / Windows / MSVC|7|default -Selftests|openssl:43, mbedtls:43|minimal examples built and run against each other and remote server -attack.sh|225|Correctness, robustness and security tests for http parser -Autobahn Server|480|Testing lws ws client, including permessage-deflate -Autobahn Client|480|Testing lws ws server, including permaessage-deflate -h2spec|openssl:146, mbedtls:146|Http/2 server compliance suite (in strict mode) -h2load|openssl:6, mbedtls:6|Http/2 server load tool (checks 10K / 100K in h1 and h2, at 1, 10, 100 concurrency) -h2load SMP|6|Http/2 and http/1.1 server load checks on SMP server build - -The over 1,500 tests run on every commit take 1hr 15 of compute time to complete. -If any problems are found, it breaks the travis build, generating an email. - -Codacy also checks every patch and the information used to keep lws at zero issues. - -Current master is checked by Coverity at least daily and kept at zero issues. - -Current master passes all the tests and these new CI arrangements will help -keep it that way. - -## Lws has the first official ws-over-h2 server support - -![wss-over-h2](./doc-assets/wss2.png) - -There's a new [RFC](https://tools.ietf.org/html/rfc8441) 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 considerable memory -reduction serverside. - -To enable it on master you just need -DLWS_WITH_HTTP2=1 at cmake. No changes to -existing code are necessary for either http/2 (if you use the official header creation -apis if you return your own headers, as shown in the test apps for several versions) -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 (chrome -must be started with `--enable-websocket-over-http2` switch to enable it currently), -and patches exist for Firefox. Authors of both browser implementations tested -against the lws server implementation. - -## New "minimal examples" - -https://libwebsockets.org/git/libwebsockets/tree/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. Same thing with tls is just three more lines. - -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 - -32- and 64-bit Windows binary builds are available via Appveyor. Visit -[lws on Appveyor](https://ci.appveyor.com/project/lws-team/libwebsockets), -click on a build, the ARTIFACTS, and unzip the zip file at `C:\Program Files (x86)/libwebsockets`. +See the [changelog](https://libwebsockets.org/git/libwebsockets/tree/changelog), summary + + - NEW: travis / appveyor / bintray are replaced by Sai + https://libwebsockets.org/sai/ which for lws currently does 167 builds per + git push on 16 platforms, all self-hosted. The homebrew bash scripts used + to select Minimal examples are replaced by CTest. Platforms currently + include Fedora/AMD/GCC, Windows/AMD/mingw32, Windows/AMD/mingw64, Android/ + aarch64/LLVM, esp-idf (on WROVER-KIT and HELTEC physical boards), Fedora/ + RISCV (on QEMU)/GCC, CentOS8/AMD/GCC, Gentoo/AMD/GCC, Bionic/AMD/GCC, + Linkit 7697, Focal/AMD/GCC, Windows (on QEMU)/AMD/MSVC, + Focal/aarch64-RPI4/GCC, iOS/aarch64/LLVM and OSX/AMD/LLVM. + + - NEW: The single CMakeLists.txt has been refactored and modernized into smaller + CMakeLists.txt in the subdirectory along with the code that is being managed + for build by it. Build options are still listed in the top level as before + but the new way is much more maintainable. + + - NEW: Captive Portal Detection. Lws can determine if the active default + route is able to connect to the internet, or is in a captive portal type + situation, by trying to connect to a remote server that will respond in an + unusual way, like provide a 204. + + - NEW: Secure streams: Support system trust store if it exists + Build on Windows + Support lws raw socket protocol in SS + Support Unix Domain Socket transport + + - NEW: Windows: Support Unix Domain Sockets same as other platforms + + - NEW: Windows: Build using native pthreads, async dns, ipv6 on MSVC + + - NEW: lws_struct: BLOB support + + - NEW: lws_sul: Now provides two sorted timer domains, a default one as + before, and another whose scheduled events are capable to wake the system from suspend + + - NEW: System Message Distribution: lws_smd provides a very lightweight way + to pass short messages between subsystems both in RTOS type case where the + subsystems are all on the lws event loop, and in the case participants are in + different processes, using Secure Streams proxying. Participants register a bitmap + of message classes they care about; if no particpant cares about a particular message, + it is rejected at allocation time for the sender, making it cheap to provide messages + speculatively. See lib/system/smd/README.md for full details. + + - NEW: lws_drivers: wrappers for SDK driver abstractions (or actual drivers) + See lib/drivers/README.md, example implementations + minimal-examples/embedded/esp32/esp-wrover-kit + - generic gpio + - generic LED (by name) lib/drivers/led/README.md + - generic PWM, sophisticated interpolated table + sequencers with crossfade + - generic button (by name), with debounce and press classification + emitting rich SMD click, long-click, double-click, + down, repeat, up JSON messages + lib/drivers/button/README.md + - bitbang i2c on generic gpio (hw support can use same + abstract API) + - bitbang spi on generic gpio (hw support can use same + abstract API) + - generic display object, can be wired up to controller + drivers that hook up by generic i2c or spi, + generic backlight PWM sequencing and + blanking timer support + - generic settings storage: get and set blobs by name + - generic network device: netdev abstract class with + WIFI / Ethernet implementations + using underlying SDK APIs; + generic 80211 Scan managements + and credentials handling via + lws_settings + This is the new way to provide embedded platform + functionality that was in the past done like + esp32-factory. Unlike the old way, the new way has no + native apis in it and can be built on other SDK / SoCs + the same. + + - NEW: Security-aware JWS JWT (JSON Web Tokens) apis are provided on top of the existing + JOSE / JWS apis. All the common algorithms are available along with some + high level apis like lws http cookie -> JWT struct -> lws http cookie. + + - REMOVED: esp32-helper and friends used by esp32-factory now lws_drivers + exists + + - REMOVED: generic sessions and friends now JWT is provided + +## v4.0 is released + +Users wanting a stable branch should follow v4.0-stable to get the most stable version +at any given time. + +See the [changelog](https://libwebsockets.org/git/libwebsockets/tree/changelog) for +information on the huge amount of new features in this release, and additional information +below. + +``` + - NEW: Lws is now under the MIT license, see ./LICENSE for details + + - NEW: GLIB native event loop support, lws + gtk example + + - NEW: native lws MQTT client... supports client stream binding like h2 when + multiple logical connections are going to the same endpoint over MQTT, they + transparently and independently share the one connection + tls tunnel + + - NEW: "Secure Streams"... if you are making a device with client connections + to the internet or cloud, this allows separation of the communications + policy (endpoints, tls cert validation, protocols, etc) from the code, with + the goal you can combine streams, change protocols and cloud provision, and + reflect that in the device's JSON policy document without having to change + any code. + + - NEW: lws_system: New lightweight and efficient Asynchronous DNS resolver + implementation for both A and AAAA records, supports recursive (without + recursion in code) lookups, caching, and getaddrinfo() compatible results + scheme (from cache directly without per-consumer allocation). Able to + perform DNS lookups without introducing latency in the event loop. + + - NEW: lws_system: ntpclient implementation with interface for setting system + time via lws_system ops + + - NEW: lws_system: dhcpclient implementation + + - NEW: Connection validity tracking, autoproduce PING/PONG for protocols that + support it if not informed that the connection has passed data in both + directions recently enough + + - NEW: lws_retry: standardized exponential backoff and retry timing based + around backoff table and lws_sul + + - NEW: there are official public helpers for unaligned de/serialization of all + common types, see eh, lws_ser_wu16be() in include/libwebsockets/lws-misc.h + + - NEW: lws_tls_client_vhost_extra_cert_mem() api allows attaching extra certs + to a client vhost from DER in memory + + - NEW: lws_system: generic blobs support passing auth tokens, per-connection + client certs etc from platform into lws + + - NEW: public helpers to consume and produce ipv4/6 addresses in a clean way, + along with lws_sockaddr46 type now public. See eg, lws_sockaddr46-based + lws_sa46_parse_numeric_address(), lws_write_numeric_address() + in include/libwebsockets/lws-network-helper.h + + - Improved client redirect handling, h2 compatibility + + - NEW: lwsac: additional features for constant folding support (strings that + already are in the lwsac can be pointed to without copying again), backfill + (look for gaps in previous chunks that could take a new use size), and + lwsac_extend() so last use() can attempt to use more unallocated chunk space + + - NEW: lws_humanize: apis for reporting scalar quanties like 1234 as "1.234KB" + with the scaled symbol strings passed in by caller + + - NEW: freertos: support lws_cancel_service() by using UDP pair bound to lo, + since it doesn't have logical pipes + + - NEW: "esp32" plat, which implemented freertos plat compatibility on esp32, is + renamed to "freertos" plat, targeting esp32 and other freertos platforms + + - NEW: base64 has an additional api supporting stateful decode, where the input + is not all in the same place at the same time and can be processed + incrementally + + - NEW: lws ws proxy: support RFC8441 + + - NEW: lws_spawn_piped apis: generic support for vforking a process with child + wsis attached to its stdin, stdout and stderr via pipes. When processes are + reaped, a specified callback is triggered. Currently Linux + OSX. + + - NEW: lws_fsmount apis: Linux-only overlayfs mount and unmount management for + aggregating read-only layers with disposable, changeable upper layer fs + + - Improvements for RTOS / small build case bring the footprint of lws v4 below + that of v3.1 on ARM + + - lws_tokenize: flag specifying # should mark rest of line as comment + + - NEW: minimal example for integrating libasound / alsa via raw file + + - lws_struct: sqlite and json / lejp translation now usable + + +``` + +## Introducing Secure Streams client support + +Secure Streams is an optional layer above lws (`-DLWS_WITH_SECURE_STREAMS=1`) that +separates connectivity policy into a JSON document, which can be part of the +firmware or fetched at boot time. + +Code no longer deals with details like endpoint specification or tls cert stack used +to validate the remote server, it's all specified in JSON, eg, see +[this example](https://warmcat.com/policy/minimal-proxy.json). Even the protocol to use to talk to the +server, between h1, h2, ws or MQTT, is specified in the policy JSON and the code +itself just deals with payloads and optionally metadata, making it possible to +switch endpoints, update certs and even switch communication protocols by just +editing the JSON policy and leaving the code alone. + +Logical Secure Stream connections outlive any underlying lws connection, and support +"nailed-up" connection reacquisition and exponential backoff management. + +See [./lib/secure-streams/README.md](https://libwebsockets.org/git/libwebsockets/tree/lib/secure-streams/README.md) and the related minimal examples +for more details. + +## mqtt client support + +If you enable `-DLWS_ROLE_MQTT=1`, lws can now support QoS0 and QoS1 MQTT client +connections. See the examples at ./minimal-examples/mqtt-client + +## libglib native event loop support + +glib's event loop joins libuv, libevent and libev support in lws for both the +`lws_context` creating and owning the loop object for its lifetime, and for +an already-existing "foreign loop" where the `lws_context` is created, attaches, +detaches, and is destroyed without affecting the loop. + +This allows direct, lock-free integration of lws functionality with, eg, a GTK app's +existing `GMainLoop` / glib `g_main_loop`. Just select `-DLWS_WITH_GLIB=1` at cmake +time to enable. The -eventlib minimal examples also support --glib option to +select using the glib loop at runtime. + +There's also a gtk example that is built if lws cmake has `-DLWS_WITH_GTK=1`. + +## `lws_system` helper for attaching code to a single event loop from another thread + +`lws_system` ops struct now has a member that enables other threads (in the +same process) to request a callback they define from the lws event loop thread +context as soon as possible. From here, in the event loop thread context, +they can set up their lws functionality before returning and letting it +operate wholly from the lws event loop. The original thread calling the +api to request the callback returns immediately. + +## Improvements on tx credit + +H2 clients and servers can now modulate RX flow control on streams precisely, +ie, define the size of the first incoming data and hand out more tx credit +at timing of its choosing to throttle or completely quench the remote server +sending as it likes. + +The only RFC-compatible way to acheive this is set the initial tx credit to +0 and set it explicitly when sending the headers... client code can elect to +do this rather than automatically manage the credit by setting a new flag +LCCSCF_H2_MANUAL_RXFLOW and indicating the initial tx credit for that stream +in client connection info member manual_initial_tx_credit. A new public api +lws_wsi_tx_credit() allows dynamic get and add to local and estimated remote +peer credit for a connection. This api can be used without knowing if the +underlying connection is h2 or not. + +## `lws_system`: DHCP client + +DHCP client is now another network service that can be integrated into lws, with +`LWS_WITH_SYS_DHCP_CLIENT` at CMake. When enabled, the `lws_system` state +is held at `DHCP` until at least one registered network interface acquires a +usable set of DHCP information including ip, subnet mask, router / gateway +address and at least one DNS server. + +See the [api-test-dhcp](https://libwebsockets.org/git/libwebsockets/tree/minimal-examples/api-tests/api-test-dhcpc) Minimal Example for how to use. + +## UDP integration with `lws_retry` + +UDP support in lws has new helper that allow `lws_retry` to be applied for retry, +and the ability to synthesize rx and tx udp packetloss systemwide to confirm +retry strategies. Since multiple transactions may be in flight on one UDP +socket, the support relies on an `lws_sul` in the transaction object to manage +the transaction retries individually. + +See `READMEs/README.udp.md` for details. + +## `lws_system`: system state and notification handlers + +Lws now has the concept of systemwide state held in the context... this is to +manage that there may be multiple steps that need the network before it's possible +for the user code to operate normally. The steps defined are + +`CONTEXT_CREATED`, `INITIALIZED`, `IFACE_COLDPLUG`, `DHCP`, `TIME_VALID`, `POLICY_VALID`, +`REGISTERED`, `AUTH1`, `AUTH2`, `OPERATIONAL` and `POLICY_INVALID`. OPERATIONAL is the +state where user code can run normally. + +User and other parts of lws can hook notifier callbacks to receive and be able to +veto system state changes, either definitively or because they have been triggered +to perform a step asynchronously and will move the state on themselves when it +completes. + +By default just after context creation, lws attempts to move straight to OPERATIONAL. +If no notifier interecepts it, it will succeed to do that and operate in a +backwards-compatible way. Enabling various features like lws ntpclient also enable +notifiers that hold progress at the related state until their operation completes +successfully, eg, not able to enter `TIME_VALID` until ntpclient has the time. + +See `READMEs/README.lws_system.md` for details. + +## `lws_system`: HAL ops struct + +Lws allows you to define a standardized ops struct at context creation time so your +user code can get various information like device serial number without embedding +system-specific code throughout the user code. It can also perform some generic +functions like requesting a device reboot. + +See `READMEs/README.lws_system.md` for details. + +## `lws_system`: ntpclient + +Optional lws system service enabled by cmake `-DLWS_WITH_SYS_NTPCLIENT` intercepts +the `lws_system` `TIME_VALID` state and performs ntpclient to get the date and time +before entering `TIME_VALID`. This allows user code to validate tls certificates +correctly knowing the current date and time by the time it reached OPERATIONAL. + +## Connection Validity tracking + +Lws now allows you to apply a policy for how long a network connection may go +without seeing something on it that confirms it's still valid in the sense of +passing traffic cohernetly both ways. There's a global policy in the context +which defaults to 5m before it produces a PING if possible, and 5m10 before +the connection will be hung up, user code can override this in the context, +vhost (for server) and client connection info (for client). + +An api `lws_validity_confirmed(wsi)` is provided so user code can indicate +that it observed traffic that must mean the connection is passing traffic in +both directions to and from the peer. In the absence of these confirmations +lws will generate PINGs and take PONGs as the indication of validity. + +## `lws_system`: Async DNS support + +Master now provides optional Asynchronous (ie, nonblocking) recursive DNS resolving. +Enable with `-DLWS_WITH_SYS_ASYNC_DNS=1` at cmake. This provides a quite +sophisticated ipv4 + ipv6 capable resolver that autodetects the dns server on +several platforms and operates a UDP socket to its port 53 to produce and parse DNS +packets from the event loop. And of course, it's extremely compact. + +It broadly follows the getaddrinfo style api, but instead of creating the results +on the heap for each caller, it caches a single result according to the TTL and +then provides refcounted const pointers to the cached result to callers. While +there are references on the cached result it can't be reaped. + +See `READMEs/README.async-dns.md` for detailed information on how it works, along +with `api-tests/api-test-async-dns` minimal example. + +## Detailed Latency + +You can now opt to measure and store us-resolution statistics on effective +latencies for client operations, and easily spool them to a file in a +format suitable for gnuplot, or handle in your own callback. Enable +`-DLWS_WITH_DETAILED_LATENCY=1` in cmake to build it into lws. + +If you are concerned about operation latency or potential blocking from +user code, or behaviour under load, or latency variability on specific +platforms, you can get real numbers on your platform using this. + +Timings for all aspects of events on connections are recorded, including +the time needed for name resolution, setting up the connection, tls +negotiation on both client and server sides, and each read and write. + +See `READMEs/README.detailed-latency.md` for how to use it. + +## Client connection logic rewrite + +Lws master now makes much better use of the DNS results for ipv4 and ipv6... it +will iterate through them automatically making the best use it can of what's +provided and attempting new connections for each potentially usable one in turn +before giving up on the whole client connection attempt. + +If ipv6 is disabled at cmake it can only use A / ipv4 records, but if ipv6 is +enabled, it tries both; if only ipv6 is enabled it promotes ipv4 to +::ffff:1.2.3.4 IPv4-in-IPv6 addresses. + +## New network helpers for ipv4 and ipv6 + +An internal union `lws_sockaddr46` that combines `struct sockaddr_in` and +`struct sockaddr_in6` is now public, and there are helpers that can parse (using +`lws_tokenize`) any valid numeric representation for ipv4 and ipv6 either +into byte arrays and lengths, or directly to and from `lws_sockaddr46`. + +## h2 long poll support + +Lws now supports the convention that half-closing an h2 http stream may make +the stream 'immortal', in terms of not being bound by normal timeouts. For +the client side, there's an api that can be applied to the client stream to +make it transition to this "read-only" long poll mode. + +See `READMEs/README.h2-long-poll.md` for full details, including how to test +it with the minimal examples. + +## h1 client parser improvements + +H1 is not so simple to parse because the header length is not known until it +has been fully parsed. The next header, or http body may be directly coalesced +with the header as well. Lws has supported bulk h1 parsing from a buffer for a +long time, but on clientside due to interactions with http proxying it had +been stuck parsing the header bytewise out of the tls buffer. In master, +everything now bulk parses from a buffer and uses a buflist to pass leftovers +through the event loop cleanly. + +## `lws_sul` time refactor + +Just before v3.2 there was a big refactor about how lws handles time. It now +explicitly schedules anything that may happen in the future on a single, sorted +linked-list, at us resolution. When entering a poll wait (or returning to an +event lib loop) it checks the interval between now and the earliest event on the +list to figure out how long to wait if there are no network events. For the +event loop case, it sets a native event lib timer to enforce it. + +See `READMEs/README.lws_sul.md` for more details and a handy api where you can +schedule your own arbitrary callbacks using this system. + +## Master is now MIT-licensed + +Libwebsockets master is now under the MIT license. See ./LICENSE. ## Support diff -Nru libwebsockets-3.2.1/READMEs/README.async-dns.md libwebsockets-4.1.6/READMEs/README.async-dns.md --- libwebsockets-3.2.1/READMEs/README.async-dns.md 1970-01-01 00:00:00.000000000 +0000 +++ libwebsockets-4.1.6/READMEs/README.async-dns.md 2020-12-01 17:40:26.000000000 +0000 @@ -0,0 +1,100 @@ +# Asynchronous DNS + +## Introduction + +Lws now features optional asynchronous, ie, nonblocking recursive DNS +resolution done on the event loop, enable `-DLWS_WITH_SYS_ASYNC_DNS=1` +at cmake to build it in. + +## Description + +The default libc name resolution is via libc `getaddrinfo()`, which is +blocking, possibly for quite long periods (seconds). If you are +taking care about latency, but want to create outgoing connections, +you can't tolerate this exception from the rule that everything in +lws is nonblocking. + +Lws' asynchronous DNS resolver creates a caching name resolver +that directly queries the configured nameserver itself over UDP, +from the event loop. + +It supports both ipv4 / A records and ipv6 / AAAA records (see later +for a description about how). One server supported over UDP :53, +and the nameserver is autodicovered on linux, windows, and freertos. + +Other features + + - lws-style paranoid response parsing + - random unique tid generation to increase difficulty of poisoning + - it's really integrated with the lws event loop, it does not spawn + threads or use the libc resolver, and of course no blocking at all + - platform-specific server address capturing (from /etc/resolv.conf + on linux, windows apis on windows) + - LRU caching + - piggybacking (multiple requests before the first completes go on + a list on the first request, not spawn multiple requests) + - observes TTL in cache + - TTL and timeout use `lws_sul` timers on the event loop + - Uses CNAME resolution inside the same response if present, otherwise + recurses to resolve the CNAME (up to 3 deep) + - ipv6 pieces only built if cmake `LWS_IPV6` enabled + +## Api + +If enabled at cmake, the async DNS implementation is used automatically +for lws client connections. It's also possible to call it directly, see +the api-test-async-dns example for how. + +The Api follows that of `getaddrinfo()` but results are not created on +the heap. Instead a single, const cached copy of the addrinfo struct +chain is reference-counted, with `lws_async_dns_freeaddrinfo()` provided +to deduct from the reference count. Cached items with a nonzero +reference count can't be destroyed from the cache, so it's safe to keep +a pointer to the results and iterate through them. + +## Dealing with IPv4 and IPv6 + +DNS is a very old standard that has some quirks... one of them is that +multiple queries are not supported in one packet, even though the protocol +suggests it is. This creates problems on ipv6 enabled systems, where +it may prefer to have AAAA results, but the server may only have A records. + +To square the circle, for ipv4 only systems (`LWS_IPV6=0`) the resolver +requests only A records. For ipv6-capable systems, it always requests +first A and then immediately afterwards AAAA records. + +To simplify the implementation, the tid b0 is used to differentiate +between A (b0 = 0) and AAAA (b0 = 1) requests and responses using the +same query body. + +The first response to come back is parsed, and a cache entry made... +it leaves a note in the query about the address of the last `struct addrinfo` +record. When the second response comes, a second allocation is made, +but not added to the logical cache... instead it's chained on to the +first cache entry and the `struct addrinfo` linked-list from the +first cache entry is extended into the second one. At the time the +second result arrives, the query is destroyed and the cached results +provided on the result callback. + +## Recursion + +Where CNAMEs are returned, DNS servers may take two approaches... if the +CNAME is also resolved by the same server and so it knows what it should +resolve to, it may provide the CNAME resolution in the same response +packet. + +In the case the CNAME is actually resolved by a different name server, +the server with the CNAME does not have the information to hand to also +resolve the CNAME in the same response. So it just leaves it for the +client to sort out. + +The lws implementation can deal with both of these, first it "recurses" +(it does not recurse on the process stack but uses its own manual stack) +to look for results in the same packet that told it about the CNAME. If +there are no results, it resets the query to look instead for the CNAME, +and restarts it. It allows this to happen for 3 CNAME deep. + +At the end, either way, the cached result is set using the original +query name and the results from the last CNAME in the chain. + + diff -Nru libwebsockets-3.2.1/READMEs/README.build-android.md libwebsockets-4.1.6/READMEs/README.build-android.md --- libwebsockets-3.2.1/READMEs/README.build-android.md 1970-01-01 00:00:00.000000000 +0000 +++ libwebsockets-4.1.6/READMEs/README.build-android.md 2020-12-01 17:40:26.000000000 +0000 @@ -0,0 +1,77 @@ +# Building for Android NDK + +If you have the ndk and prebuilt toolchains with that, you can simply build +lws library for your android app from one cmake and one make command. + +However if you want a tls lib, you have to take care of building and pointing +to that first. But if it's a cmake project like mbedtls, that also is just a +matter of one cmake and one make. + +## Installing NDK pieces + +There's probably a more direct way but the official way is install the whole +Android Studio and then run `sdkmanager` to install a recent NDK. + +I installed the sdk and ndk pieces into /opt/android/ and that's how the +`./contrib/cross-aarch64-android.cmake` toolchain file is shipped. You can +adapt some settings at the top of that file including the path if needed. + +## Fetching lws (needed first for cross toolchain file) + +It doesn't care where you put these projects, but for simplicity they should +be in the same parent dir, like + +``` + - /home/someone + - /home/someone/libwebsockets + - /home/someone/mbedtls +``` + +The reason is that building mbedtls need the cross toolchain file from +libwebsockets, that's also why we have to get libwebsockets first now but +build it later. + +``` +$ git clone https://libwebsockets.org/repo/libwebsockets +``` + +## Building mbedtls + +``` +$ git clone https://github.com/ARMmbed/mbedtls.git +$ cd mbedtls +$ mkdir build +$ cd build +$ rm -f CMakeCache.txt && \ + cmake .. -DCMAKE_TOOLCHAIN_FILE=../libwebsockets/contrib/cross-aarch64-android.cmake \ + -DUSE_SHARED_MBEDTLS_LIBRARY=1 \ + -DENABLE_PROGRAMS=0 \ + -Wno-dev && \ + make -j && \ + cmake --install . +``` + +The lws toolchain file sets the path to install into as the cross root path, so +despite it looks like the destination dir is missing for the install, it will +go into, eg `/opt/android/ndk/21.1.6352462/platforms/android-24/arch-arm64/lib/libmbedcrypto.a` +where lws will look for it + +## Building lws + +You don't need to explain where mbedtls can be found... lws will build with the +same toolchain file that sets the cross root to the same place as mbedtls, it +will easily find them there without any further hints. + +``` +$ mkdir build +$ cd build +$ rm -f CMakeCache.txt && \ + cmake .. -DCMAKE_TOOLCHAIN_FILE=../libwebsockets/contrib/cross-aarch64-android.cmake \ + -DLWS_WITH_MBEDTLS=1 \ + -DLWS_WITHOUT_TESTAPPS=1 && \ + make && \ + cmake --install . +``` + +That's it, both mbedtls and lws library and header files are installed into the +ndk cross root. diff -Nru libwebsockets-3.2.1/READMEs/README.build.md libwebsockets-4.1.6/READMEs/README.build.md --- libwebsockets-3.2.1/READMEs/README.build.md 2019-12-18 14:45:31.000000000 +0000 +++ libwebsockets-4.1.6/READMEs/README.build.md 2020-12-01 17:40:26.000000000 +0000 @@ -1,6 +1,15 @@ Notes about building lws ======================== +You can download and install lws using the [vcpkg](https://github.com/Microsoft/vcpkg/) dependency manager: +``` +git clone https://github.com/microsoft/vcpkg.git +cd vcpkg +./bootstrap-vcpkg.sh +./vcpkg integrate install +vcpkg install libwebsockets +``` +The lws port in vcpkg is kept up to date by Microsoft team members and community contributors. If the version is out of date, please [create an issue or pull request](https://github.com/Microsoft/vcpkg/) on the vcpkg repository. @section cm Introduction to CMake diff -Nru libwebsockets-3.2.1/READMEs/README.build-windows.md libwebsockets-4.1.6/READMEs/README.build-windows.md --- libwebsockets-3.2.1/READMEs/README.build-windows.md 1970-01-01 00:00:00.000000000 +0000 +++ libwebsockets-4.1.6/READMEs/README.build-windows.md 2020-12-01 17:40:26.000000000 +0000 @@ -0,0 +1,214 @@ +# Some notes for the windows jungle + +This was how I compiled libwebsockets starting from a blank windows install +in March - April 2020. Doing this on a linux distro is way simpler and quicker +than all this! + +## Notes on vm installation + +### Disk size + +For building you'll need 40GB+ available for the guest storage. + +### Required: Windows product key + +Assuming like me the first thing you do with a new laptop is install Linux over +the windows it came with, you can recover your 'windows tax' windows product key +from your device typically using `sudo strings /sys/firmware/acpi/tables/MSDM`, +and use that for your VM install. + +### Required: Spice guest + +To have shared clipboard, and for windows video driver to match your vm window +resolution, you must install spice guest tools inside the windows VM. It also +installs some virtio pieces you will want. + +https://www.spice-space.org/download/windows/spice-guest-tools/spice-guest-tools-latest.exe + +### Blood-pressure reduction: Firefox + +https://www.mozilla.org/en-US/exp/firefox/ + +When it's up, add-ons: ublock origin, privacy badger, noscript, disable search +bar prediction + +### Blood-pressure reduction: Clink + +This is a hack on cmd.exe that lets it understand Ctrl-R and fixup unix-style +slashes automagically. + +https://github.com/mridgers/clink/releases/download/0.4.9/clink_0.4.9_setup.exe + +If you're usually using *nix, you definitely need this to keep your sanity. + +### Required: 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. + +### Required: git + +Visit the canonical git site to download their windows installer thing + +[git](https://git-scm.com/download/win) + +**Select the install option for "extra unix commands"** so you can get `ls -l`, +`cp`, `mv` and suchlike working in cmd.exe... that's awesome, thanks git! + +Afterwards you can just use `git` as normal from cmd.exe as well. + +### Required: 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... 7GB :-) + +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. + +They don't mention it during the install, but after 30 days this "free" +"community" edition demands you open a microsoft account or it stops working. +In the install they give you the option to add a microsoft account and the +alternative is, "not now, maybe later". Compare and contrast to gcc or git or +the other FOSS projects. + +### Required: OpenSSL + +Ugh... I tried using prebuilts but it's unreliable and needs an unfeasible +amount of trust. So I recommend bite the bullet and build your own... that's +trivial on Linux but of course windows makes everything nasty. + +At least hopefully all the "research" is done and listed out here. + +#### OpenSSL build Prerequisite: install perl binary + +Move the git version of perl out of the way, it won't work for OpenSSL build + +``` +mv /usr/bin/perl /usr/bin/perl-git +``` + +For windows, OpenSSL "recommends" ActiveState perl but it doesn't work for me, +complaining about stuff needed from cpan and then dying when it was installed. +"Strawberry Perl" is installed in `C:\Strawberry` and worked out the box. + +http://strawberryperl.com/download/5.30.2.1/strawberry-perl-5.30.2.1-64bit.msi + +The installer sets up `%PATH%` if you open a new cmd window. + +#### OpenSSL build Prerequisite: NASM + +Go here and click on the latest stable, download the win32 .exe + +https://nasm.us/ + +Just install via the defaults. Then add it to the PATH temporarily... + +``` +$ set PATH=%PATH%;C:\Program Files (x86)\NASM +``` + +#### OpenSSL build setup: source VC env vars + +These fix up the PATH and include dirs etc necessary for VC build in the cmd +window. + +``` +$ call "C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\VC\Auxiliary\Build\vcvarsall.bat" x86_amd64 +``` + +### OpenSSL build: + +Grab openssl from git... assuming the prerequisites above went well it will +just sit there building for 30 minutes or whatever. + +``` +$ git clone https://github.com/openssl/openssl +$ cd openssl +$ perl Configure VC-WIN64A +$ nmake +``` + +Afterwards, open an Administrator mode cmd.exe, redo the msvc path and then +install the build. + +``` +$ cd openssl +$ call "C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\VC\Auxiliary\Build\vcvarsall.bat" x86_amd64 +$ nmake install +``` + +Oh another grindingly slow windows build action. Finally it's in there in +`C:\Program Files\OpenSSL`. + +libraries are looking for a cert bundle at "C:\Program Files\Common Files\SSL\cert.pem"... +it's not documented or 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. + +## Required: pthreads + +It's amazing but after all these years windows doesn't offer pthreads compatibility +itself. Just like the many other missing POSIX bits like fork(). + +I downloaded the latest (2012) zip release of pthreads-win32 from here + +ftp://sourceware.org/pub/pthreads-win32 + +Then I created a dir "C:\Program Files (x86)\pthreads", and copied the `dll`, +`include` and `lib` subdirs from the `prebuilt` folder in the zip there. + +The cmake incantation to build against pthreads set up like that is + +``` + $ cmake .. -DLWS_HAVE_PTHREAD_H=1 -DLWS_EXT_PTHREAD_INCLUDE_DIR="C:\Program Files (x86)\pthreads\include" -DLWS_EXT_PTHREAD_LIBRARIES="C:\Program Files (x86)\pthreads\lib\x64\libpthreadGC2.a" -DLWS_WITH_MINIMAL_EXAMPLES=1 +``` + +## Building libwebsockets + +We'll clone libwebsockets then use cmake to build via vs tools + +``` +> 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 +``` + +### Hack the libs into view + +The libs we built against aren't visible in the system, I don't know what +Real Windows Programmers are supposed to do about that, but I used an Admin cmd +prompt to copy them into C:\windows\system32 + +``` +$ cp "C:\Program Files (x86)\pthreads\dll\x64\pthreadGC2.dll" "C:\Program Files\OpenSSL\bin\libcrypto-3.dll" "C:\Program Files\OpenSSL\bin\libssl-3.dll" C:\Windows\system32 +``` + +After that you can run the test apps OK, eg + +``` +$ libwebsockets-test-server.exe -s +``` + +## Note about using paths with spaces in with cmake + + diff -Nru libwebsockets-3.2.1/READMEs/README.captive-portal-detection.md libwebsockets-4.1.6/READMEs/README.captive-portal-detection.md --- libwebsockets-3.2.1/READMEs/README.captive-portal-detection.md 1970-01-01 00:00:00.000000000 +0000 +++ libwebsockets-4.1.6/READMEs/README.captive-portal-detection.md 2020-12-01 17:40:26.000000000 +0000 @@ -0,0 +1,88 @@ +# Captive Portal Detection + +## Background + +Wifi devices may face some interception of their connection to the +internet, it's very common for, eg, coffee shop wifi to present some +kind of login or other clickthrough before access to the Internet is +granted. Devices may need to understand that they are in this +situation, and there are several different techniques for trying to +gague it. + +Sequence-wise the device has been granted a DHCP lease and has been +configured with DNS, but the DNS may be wrongly resolving everything +to an address on the LAN or a portal on the net. + +Whether there is a captive portal active should be a sticky state for a given +connection if there is not going to be any attempt to login or pass the landing +page, it only needs checking for after DHCP acquisition then. If there will be +an attempt to satisfy the landing page, the test should be repeated after the +attempt. + +## Detection schemes + +The most popular detection scheme by numbers is Android's method, +which is to make an HTTP client GET to `http://connectivitycheck.android.com/generate_204` +and see if a 204 is coming back... if intercepted, typically there'll be a +3xx redirect to the portal, perhaps on https. Or, it may reply on http with +a 200 and show the portal directly... either way it won't deliver a 204 +like the real remote server does. + +Variations include expecting a 200 but with specific http body content, and +doing a DNS lookup for a static IP that the device knows; if it's resolved to +something else, it knows there's monkey business implying a captive portal. + +Other schemes involve https connections going out and detecting that the cert +of the server it's actually talking to doesn't check out, although this is +potentially ambiguous. + +Yet more methods are possible outside of tcp or http. + +## lws captive portal detect support + +lws provides a generic api to start captive portal detection... + +``` +LWS_EXTERN LWS_VISIBLE int +lws_system_cpd_start(struct lws_context *context); +``` + +and two states in `lws_system` states to trigger it from, either +`LWS_SYSTATE_CPD_PRE_TIME` which happens after DHCP acquisition but before +ntpclient and is suitable for non https-based scheme where the time doesn't +need to be known, or the alternative `LWS_SYSTATE_CPD_POST_TIME` state which +happens after ntpclient has completed and we know the time. + +The actual platform implementation is set using `lws_system_ops_t` function +pointer `captive_portal_detect_request`, ie + +``` + int (*captive_portal_detect_request)(struct lws_context *context); + /**< Check if we can go out on the internet cleanly, or if we are being + * redirected or intercepted by a captive portal. + * Start the check that proceeds asynchronously, and report the results + * by calling lws_captive_portal_detect_result() api + */ +``` + +User platform code can provide this to implement whatever scheme they want, when +it has arrived at a result, it can call the lws api `lws_system_cpd_result()` to +inform lws. If there isn't any captive portal, this will also try to advance the +system state towards OPERATIONAL. + +``` +/** + * lws_system_cpd_result() - report the result of the captive portal detection + * + * \param context: the lws_context + * \param result: one of the LWS_CPD_ constants representing captive portal state + * \param redirect_url: NULL, or the url we were redirected to if result is + * LWS_CPD_HTTP_REDIRECT + * + * Sets the context's captive portal detection state to result. User captive + * portal detection code would call this once it had a result from its test. + */ +LWS_EXTERN LWS_VISIBLE int +lws_system_cpd_result(struct lws_context *context, int result, const char *redirect_url); +``` + diff -Nru libwebsockets-3.2.1/READMEs/README.cmake.md libwebsockets-4.1.6/READMEs/README.cmake.md --- libwebsockets-3.2.1/READMEs/README.cmake.md 1970-01-01 00:00:00.000000000 +0000 +++ libwebsockets-4.1.6/READMEs/README.cmake.md 2020-12-01 17:40:26.000000000 +0000 @@ -0,0 +1,41 @@ +# Tips about CMake + +## Don't be afraid to nuke your build dir + +CMake likes to cache options and other things in the build dir... if you stop +asserting the state of something like `-DMY_OPTION=1`, then the last way it was +set it cached. On order to keep track of what you have set and not set, it's +very advisable to explicitly keep all your options and set them all on one cmake +line. + +Then, when you meet a situation you changed something but somehow cmake is +sticking with what it knew before, you can fearlessly delete your build dir +and create a new one with your explicit config. + +On Linux, it's usually enough to delete `CMakeCache.txt` to trigger it to config +from the start again, but on, eg, windows, it isn't, for whatever reason it +literally needs the build dir removing. + +## CMake presence tests that fail + +Lws makes use of various CMake features to figure out what apis your libraries +offer, eg, OpenSSL has many different apis based on version, lws knows how to +work around most of the changes, but to do it it must find out what apis are +available first on your build environment. + +CMake basically builds little throwaway test programs using each api in turn, and +if it builds, it understands that the api was available and sets a preprocessor +symbol that's available in the main build accordingly. Then we can do `#if xxx` +to figure out if we can use `xxx` or need to do a workaround at build-time. + +This works very well, but unfortunately if the program didn't build, there are +many possible ways for the build to break even if the api being tested is +really available... for example, some library in your toolchain isn't being +linked for the throwaway test program. + +When this happens, cmake indicates that apis that must be available are not available... +CMake keeps a log of what happened with the failed test programs in +`./build/CMakeFiles/CMakeError.log`. This is appeneded to, so the best way is blow +away the build dir and reconfig a new one from scratch, and go look in there to +find out what the compiler or linker was complaining about. + diff -Nru libwebsockets-3.2.1/READMEs/README.coding.md libwebsockets-4.1.6/READMEs/README.coding.md --- libwebsockets-3.2.1/READMEs/README.coding.md 2019-12-18 14:45:31.000000000 +0000 +++ libwebsockets-4.1.6/READMEs/README.coding.md 2020-12-01 17:40:26.000000000 +0000 @@ -1,7 +1,7 @@ Notes about coding with lws =========================== -@section era Old lws and lws v2.0 +@section era Old lws and lws v2.0+ Originally lws only supported the "manual" method of handling everything in the user callback found in test-server.c / test-server-http.c. @@ -1001,13 +1001,25 @@ to indicate it will use one of the event libraries at runtime. -libev has some problems, its headers conflict with libevent, they both define -critical constants like EV_READ to different values. Attempts -to discuss clearing that up with libevent and libev did not get anywhere useful. - -In addition building anything with libev using gcc spews warnings, the -maintainer is aware of this for many years, and blames gcc. We worked -around this by disabling -Werror on the parts of lws that use libev. +libev and libevent headers conflict, they both define critical constants like +EV_READ to different values. Attempts to discuss clearing that up with both +libevent and libev did not get anywhere useful. Therefore CMakeLists.txt will +error out if you enable both LWS_WITH_LIBEV and LWS_WITH_LIBEVENT. + +In addition depending on libev / compiler version, building anything with libev +apis using gcc may blow strict alias warnings (which are elevated to errors in +lws). I did some googling at found these threads related to it, the issue goes +back at least to 2010 on and off + +https://github.com/redis/hiredis/issues/434 +https://bugs.gentoo.org/show_bug.cgi?id=615532 +http://lists.schmorp.de/pipermail/libev/2010q1/000916.html +http://lists.schmorp.de/pipermail/libev/2010q1/000920.html +http://lists.schmorp.de/pipermail/libev/2010q1/000923.html + +We worked around this problem by disabling -Werror on the parts of lws that +use libev. FWIW as of Dec 2019 using Fedora 31 libev 4.27.1 and its gcc 9.2.1 +doesn't seem to trigger the problem even without the workaround. For these reasons and the response I got trying to raise these issues with them, if you have a choice about event loop, I would gently encourage you diff -Nru libwebsockets-3.2.1/READMEs/README.ctest.md libwebsockets-4.1.6/READMEs/README.ctest.md --- libwebsockets-3.2.1/READMEs/README.ctest.md 1970-01-01 00:00:00.000000000 +0000 +++ libwebsockets-4.1.6/READMEs/README.ctest.md 2020-12-01 17:40:26.000000000 +0000 @@ -0,0 +1,67 @@ +## Using CTest with lws + +### Updating ancient cmake + +You need a recent cmake to have the CTest tests work properly, if you're on an +older distro you need to update your cmake. Luckily Kitware provide a repo for +common distros. These instructions work for bionic and xenial. + +First remove the old distro cmake and install the pieces needed to get the new repo keys + +``` +# apt purge --auto-remove cmake +# apt install gnupg wget apt-transport-https ca-certificates +# wget -O - https://apt.kitware.com/keys/kitware-archive-latest.asc 2>/dev/null | sudo apt-key add - +# apt edit-sources +``` + +Add the line `deb https://apt.kitware.com/ubuntu/ bionic main` at the end +replacing `bionic` with `xenial` as needed, and save (:wq). Then + +``` +# apt update +# apt install cmake +``` + +## Generating the tests + +The main tests just need `-DLWS_WITH_MINIMAL_EXAMPLES=1`. You can optionally set +`-DLWS_CTEST_INTERNET_AVAILABLE=0` to indicate you can't run the tests that need +internet connectivity. + +## Preparing to run the tests + +The tests have to spawn by script some "test buddies", for example the client +tests have to run a test server from the built lws image. For that reason you +have to do a side-install into `./destdir` using `make install DESTDIR=../destdir` +from the build directory before all the tests will work properly. + +## Running the tests + +CMake puts the test action into a build-host type specific form, for unix type +platforms you just run `make test` or `CTEST_OUTPUT_ON_FAILURE=1 make test` to +see what happened to any broken tests. + +On windows, it looks like `ctest . -C DEBUG` or RELEASE if that was the build +type. + +## Considerations for creating tests + +### Timeout + +The default test timeout is 1500s, for that reason it's good practice to set +a more suitable `TIMEOUT` property on every test. + +### Working Directory + +Server-side test apps usually need to be run from their `./minimal-examples/...` +directory so they can access their assets like index.html etc. + +However when building with `-DLWS_WITH_MBEDTLS=1` then even client-side apps +need to be run from their directory, since they need to get the trusted CA for +warmcat.com or libwebsockets.org additionally. + +For that reason it's good practice to set the `WORKING_DIRECTORY` property to +the home dir of the example app in all cases. + + diff -Nru libwebsockets-3.2.1/READMEs/README.debugging.md libwebsockets-4.1.6/READMEs/README.debugging.md --- libwebsockets-3.2.1/READMEs/README.debugging.md 1970-01-01 00:00:00.000000000 +0000 +++ libwebsockets-4.1.6/READMEs/README.debugging.md 2020-12-01 17:40:26.000000000 +0000 @@ -0,0 +1,63 @@ +# Tips on debugging with lws + +## Problem with the library, or your code? + +Because lws is only really used when already combined with user code, +it can be a headache figuring out if the actual problem is inside lws +or in the user code. + +If it's in lws, I would really like to solve it, but if it's in your +code, that's your problem. Finding out which side it's on when it +involves your code is also something you need to try to resolve. + +The minimal examples are useful because if they demonstrate the same +problem, it's something about your platform or lws itself, I have the +minimal examples so I can test it and find out if it's your platform. +If I can reproduce it, it's my problem. + +## Debug builds + +With cmake, build with `-DCMAKE_BUILD_TYPE=DEBUG` to build in extra +logging, and use a log level bitmap of eg, 1039 or 1151 to enable +the extra logs for print. + +The minimal examples take a -d xxx commandline parameter so you can +select the logging level when you run it. + +The extra logging can be very useful to understand the sequencing of +problematic actions. + +## Valgrind + +If your problems involve heap corruption or use-after-free, Valgrind +is indespensible. It's simple to use, if you normally run `xxx`, just +run `valgrind xxx`. Your code will run slower, usually something +like 2 - 4x slower but it depends on the exact code. However you will +get a backtrace as soon as there is some kind of misbehaviour of either +lws or your code. + +lws is developed using valgrind routinely and strives to be completely +valgrind-clean. So typically any problems reported are telling you +about problems in user code (or my bugs). + +## Traffic dumping + +The best place for dumping traffic, assuming you are linking against a +tls library, is `lws_ssl_capable_read()` and `lws_ssl_capable_write()` +in either `./lib/tls/openssl/openssl-ssl.c` or +`./lib/tls/mbedtls/mbedtls-ssl.c` according to which tls library you +are using. There are default-`#if 0` sections in each function like + +``` +#if 0 + /* + * If using mbedtls type tls library, this is the earliest point for all + * paths to dump what was received as decrypted data from the tls tunnel + */ + lwsl_notice("%s: len %d\n", __func__, len); + lwsl_hexdump_notice(buf, len); +#endif +``` + +Enable these to get hexdumps for all unencrypted data in both directions. + diff -Nru libwebsockets-3.2.1/READMEs/README.detailed-latency.md libwebsockets-4.1.6/READMEs/README.detailed-latency.md --- libwebsockets-3.2.1/READMEs/README.detailed-latency.md 1970-01-01 00:00:00.000000000 +0000 +++ libwebsockets-4.1.6/READMEs/README.detailed-latency.md 2020-12-01 17:40:26.000000000 +0000 @@ -0,0 +1,117 @@ +# lws detailed latency + +![lws detailed latency example plot](../doc-assets/lws-detailed-latency-example.png) + +## Introduction + +lws has the capability to make detailed latency measurements and +report them in realtime to a specified callback. + +A default callback is provided that renders the data as text in +space-separated format suitable for gnuplot, to a specified file. + +## Configuring + +Enable `LWS_WITH_DETAILED_LATENCY` at cmake. + +Create your context with something similar to this + +``` +#if defined(LWS_WITH_DETAILED_LATENCY) + info.detailed_latency_cb = lws_det_lat_plot_cb; + info.detailed_latency_filepath = "/tmp/lws-latency-results"; +#endif +``` + +`lws_det_lat_plot_cb` is provided by lws as a convenience to convert +the stuct data provided at the callback interface to space-separated +text data that is easy to process with shell commands and gnuplot. + +## `lws_det_lat_plot_cb` format + +``` +728239173547 N 23062 0 0 23062 0 0 0 +728239192554 C 18879 0 0 18879 0 0 0 +728239217894 T 25309 0 0 25309 0 0 0 +728239234998 r 0 0 0 0 271 172 256 +728239250611 r 0 0 0 0 69 934 4096 +728239255679 w 19 122 18 159 20 80 80 +728239275718 w 20 117 15 152 18 80 80 +728239295578 w 10 73 7 90 7 80 80 +728239315567 w 9 67 5 81 7 80 80 +728239335745 w 23 133 9 165 14 80 80 +... +``` + +Each event is shown in 9 columns + + - unix time in us + - event type + - N = Name resolution + - C = TCP Connection + - T = TLS negotiation server + - t = TLS negotiation client + - r = Read + - w = Write + - us duration, for w time client spent waiting to write + - us duration, for w time data spent in transit to proxy + - us duration, for w time proxy waited to send data + - as a convenience, sum of last 3 columns above + - us duration, time spent in callback + - last 2 are actual / requested size in bytes + +## Processing captured data with ministat + +Eg, to summarize overall latencies on all captured writes + +``` + $ cat /tmp/lws-latency-results | grep " w " | cut -d' ' -f6 | ministat +... + N Min Max Median Avg Stddev +x 1000 43 273 141 132.672 32.471693 +``` + +## Processing captured data with gnuplot + +### Gnuplot plotting script + +Create a gnuplot script, eg myscript.gp + +``` +reset +set term pngcairo enhanced nocrop font "OpenSans, 12" size 800,600#output terminal and file +set output "lws-latency.png" +#set yrange [0:10000] +#to put an empty boundary around the +#data inside an autoscaled graph. +set offset graph 0.05,0.05,0.05,0.0 +set style fill transparent solid 0.5 #fillstyle +set tics out nomirror +set xlabel "event" +set ylabel "latency (us)" +set format x "" +set title "Write latency" +set key invert reverse Right inside nobox +set key autotitle columnheader +set style data histogram +set style histogram rowstacked +set style fill solid border -1 +set boxwidth 0.75 +set style fill solid 1.00 noborder +set tic scale 0 +set grid ytics lc rgb "#505050" +unset border +unset xtics + +plot '/tmp/1' \ + using ($3 + $4 + $5):xtic(1) w boxes lt rgbcolor "blue" title 'prox wr wait', \ + '' using ($3 + $4):xtic(1) w boxes lt rgbcolor "green" title 'txfr to prox', \ + '' using 3:xtic(1) w boxes lt rgbcolor "red" title 'cli wri wait' +``` + +### gnuplot invocation + +``` + $ cat /tmp/lws-latency-results | grep " w " \>/tmp/1 ; gnuplot myscript.gp && eog lws-latency.png +``` + diff -Nru libwebsockets-3.2.1/READMEs/README.event-libs.md libwebsockets-4.1.6/READMEs/README.event-libs.md --- libwebsockets-3.2.1/READMEs/README.event-libs.md 1970-01-01 00:00:00.000000000 +0000 +++ libwebsockets-4.1.6/READMEs/README.event-libs.md 2020-12-01 17:40:26.000000000 +0000 @@ -0,0 +1,80 @@ +# lws event library support + +## v4.0 and below + +Before v4.1, lws allowed selecting some event library support for inclusion +in the libwebsockets library + +Option|Feature +---|--- +`LWS_WITH_GLIB`|glib +`LWS_WITH_LIBEVENT`|libevent +`LWS_WITH_LIBUV`|libuv +`LWS_WITH_LIBEV`|libev + +The user code can select by `info->options` flags at runtime which event loop +it wants to use. + +The only restriction is that libev and libevent can't coexist, because their +header namespace conflicts. + +## v4.1 and above + +Lws continues to support the old way described above, but there's an additional +new cmake option that decides how they are built if any are selected, +`LWS_WITH_EVLIB_PLUGINS`. + +The old behaviour is set by `LWS_WITH_EVLIB_PLUGINS=0`, for UNIX platforms, this +is set to 1 by default. This causes the enabled event lib support to each be built into +its own dynamically linked plugin, and lws will bring in the requested support alone +at runtime after seeing the `info->options` flags requested by the user code. + +This has two main benefits, first the conflict around building libevent and libev +together is removed, they each build isolated in their own plugin; the libwebsockets +core library build doesn't import any of their headers (see below for exception). +And second, for distro packaging, the event lib support plugins can be separately +packaged, and apps take dependencies on the specific event lib plugin package, which +itself depends on the libwebsockets core library. This allows just the needed +dependencies for the packageset without forcing everything to bring everything in. + +Separately, lws itself has some optional dependencies on libuv, if you build lwsws +or on Windows you want plugins at all. CMake will detect these situations and +select to link the lws library itself to libuv if so as well, independent of whatever +is happening with the event lib support. + +## evlib plugin install + +The produced plugins are named + +event lib|plugin name +---|--- +glib|`libwebsockets-evlib_glib.so` +event|`libwebsockets-evlib_event.so` +uv|`libwebsockets-evlib_uv.so` +ev|`libwebsockets-evlib_ev.so` + +The evlib plugins are installed alongside libwebsockets.so/.a into the configured +library dir, it's often `/usr/local/lib/` by default on linux. + +Lws looks for them at runtime using the build-time-configured path. + +## Component packaging + +The canonical package name is `libwebsockets`, the recommended way to split the +packaging is put the expected libs and pkgconfig in `libwebsockets` or `libwebsockets-core`, +the latter is followed by the provided cmake, and produce an additional package per build +event library plugin, named, eg `libwebsockets-evlib_glib`, which has a dependency on +`libwebsockets[-core]`. + +Applications that use the default event loop can directly require `libwebsockets[-core]`, +and application packages that need specific event loop support can just require, eg, +`libwebsockets-evlib_glib`, which will bring that in and the core lws pieces in one step. +There is then no problem with multiple apps requiring different event libs, they will +bring in all the necessary pieces which will not conflict either as packages or at +runtime. + +## `LWS_WITH_DISTRO_RECOMMENDED` + +The cmake helper config `LWS_WITH_DISTRO_RECOMMENDED` is adapted to build all the +event libs with the event lib plugin support enabled. + diff -Nru libwebsockets-3.2.1/READMEs/README.generic-sessions.md libwebsockets-4.1.6/READMEs/README.generic-sessions.md --- libwebsockets-3.2.1/READMEs/README.generic-sessions.md 2019-12-18 14:45:31.000000000 +0000 +++ libwebsockets-4.1.6/READMEs/README.generic-sessions.md 1970-01-01 00:00:00.000000000 +0000 @@ -1,373 +0,0 @@ -Notes about generic-sessions Plugin -=================================== - -@section gseb Enabling lwsgs for build - -Enable at CMake with -DLWS_WITH_GENERIC_SESSIONS=1 - -This also needs sqlite3 (libsqlite3-dev or similar package) - - -@section gsi lwsgs Introduction - -The generic-sessions protocol plugin provides cookie-based login -authentication for lws web and ws connections. - -The plugin handles everything about generic account registration, -email verification, lost password, account deletion, and other generic account -management. - -Other code, in another eg, ws protocol handler, only needs very high-level -state information from generic-sessions, ie, which user the client is -authenticated as. Everything underneath is managed in generic-sessions. - - - - random 20-byte session id managed in a cookie - - - all information related to the session held at the server, nothing managed clientside - - - sqlite3 used at the server to manage active sessions and users - - - defaults to creating anonymous sessions with no user associated - - - admin account (with user-selectable username) is defined in config with a SHA-1 of the password; rest of the accounts are in sqlite3 - - - user account passwords stored as salted SHA-1 with additional confounder - only stored in the JSON config, not the database - - - login, logout, register account + email verification built-in with examples - - - in a mount, some file suffixes (ie, .js) can be associated with a protocol for the purposes of rewriting symbolnames. These are read-only copies of logged-in server state. - - - When your page fetches .js or other rewritten files from that mount, "$lwsgs_user" and so on are rewritten on the fly using chunked transfer encoding - - - Eliminates server-side scripting with a few rewritten symbols and - javascript on client side - - - 32-bit bitfield for authentication sectoring, mounts can provide a mask on the loggin-in session's associated server-side bitfield that must be set for access. - - - No code (just config) required for, eg, private URL namespace that requires login to access. - - -@section gsin Lwsgs Integration to HTML - -Only three steps are needed to integrate lwsgs in your HTML. - -1) lwsgs HTML UI is bundled with the javascript it uses in `lwsgs.js`, so -import that script file in your head section - -2) define an empty div of id "lwsgs" somewhere - -3) Call lwsgs_initial() in your page - -That's it. An example is below - -``` - - - - - - - - - - - -
- - -
-
- - - - - - -``` - -@section gsof Lwsgs Overall Flow@ - -When the protocol is initialized, it gets per-vhost information from the config, such -as where the sqlite3 databases are to be stored. The admin username and sha-1 of the -admin password are also taken from here. - -In the mounts using protocol-generic-sessions, a cookie is maintained against any requests; if no cookie was active on the initial request a new session is -created with no attached user. - -So there should always be an active session after any transactions with the server. - -In the example html going to the mount /lwsgs loads a login / register page as the default. - -The

in the login page contains 'next url' hidden inputs that let the html 'program' where the form handler will go after a successful admin login, a successful user login and a failed login. - -After a successful login, the sqlite record at the server for the current session is updated to have the logged-in username associated with it. - - - -@section gsconf Lwsgs Configuration - -"auth-mask" defines the authorization sector bits that must be enabled on the session to gain access. - -"auth-mask" 0 is the default. - - - b0 is set if you are logged in as a user at all. - - b1 is set if you are logged in with the user configured to be admin - - b2 is set if the account has been verified (the account configured for admin is always verified) - - b3 is set if your session just did the forgot password flow successfully - -``` - { - # things in here can always be served - "mountpoint": "/lwsgs", - "origin": "file:///usr/share/libwebsockets-test-server/generic-sessions", - "origin": "callback://protocol-lws-messageboard", - "default": "generic-sessions-login-example.html", - "auth-mask": "0", - "interpret": { - ".js": "protocol-lws-messageboard" - } - }, { - # things in here can only be served if logged in as a user - "mountpoint": "/lwsgs/needauth", - "origin": "file:///usr/share/libwebsockets-test-server/generic-sessions/needauth", - "origin": "callback://protocol-lws-messageboard", - "default": "generic-sessions-login-example.html", - "auth-mask": "5", # logged in as a verified user - "interpret": { - ".js": "protocol-lws-messageboard" - } - }, { - # things in here can only be served if logged in as admin - "mountpoint": "/lwsgs/needadmin", - "origin": "file:///usr/share/libwebsockets-test-server/generic-sessions/needadmin", - "origin": "callback://protocol-lws-messageboard", - "default": "generic-sessions-login-example.html", - "auth-mask": "7", # b2 = verified (by email / or admin), b1 = admin, b0 = logged in with any user name - "interpret": { - ".js": "protocol-lws-messageboard" - } - } -``` -Note that the name of the real application protocol that uses generic-sessions -is used, not generic-sessions itself. - -The vhost configures the storage dir, admin credentials and session cookie lifetimes: - -``` - "ws-protocols": [{ - "protocol-generic-sessions": { - "status": "ok", - "admin-user": "admin", - - # create the pw hash like this (for the example pw, "jipdocesExunt" ) - # $ echo -n "jipdocesExunt" | sha1sum - # 046ce9a9cca769e85798133be06ef30c9c0122c9 - - # - # Obviously ** change this password hash to a secret one before deploying ** - # - "admin-password-sha1": "046ce9a9cca769e85798133be06ef30c9c0122c9", - "session-db": "/var/www/sessions/lws.sqlite3", - "timeout-idle-secs": "600", - "timeout-anon-idle-secs": "1200", - "timeout-absolute-secs": "6000", - # the confounder is part of the salted password hashes. If this config - # file is in a 0700 root:root dir, an attacker with apache credentials - # will have to get the confounder out of the process image to even try - # to guess the password hashes. - "confounder": "Change to <=31 chars of junk", - - "email-from": "noreply@example.com", - "email-smtp-ip": "127.0.0.1", - "email-expire": "3600", - "email-helo": "myhost.com", - "email-contact-person": "Set Me ", - "email-confirm-url-base": "http://localhost:7681/lwsgs" - } -``` - -The email- related settings control generation of automatic emails for -registration and forgotten password. - - - `email-from`: The email address automatic emails are sent from - - - `email-smtp-ip`: Normally 127.0.0.1, if you have a suitable server on port - 25 on your lan you can use this instead here. - - - `email-expire`: Seconds that links sent in email will work before being - deleted - - - `email-helo`: HELO to use when communicating with your SMTP server - - - `email-contact-person`: mentioned in the automatic emails as a human who can - answer questions - - - `email-confirm-url-base`: the URL to start links with in the emails, so the - recipient can get back to the web server - -The real protocol that makes use of generic-sessions must also be listed and -any configuration it needs given - -``` - "protocol-lws-messageboard": { - "status": "ok", - "message-db": "/var/www/sessions/messageboard.sqlite3" - }, -``` - -Notice the real application uses his own sqlite db, no details about how -generic-sessions works or how it stores data are available to it. - - -@section gspwc Lwsgs Password Confounder - -You can also define a per-vhost confounder shown in the example above, used -when aggregating the password with the salt when it is hashed. Any attacker -will also need to get the confounder along with the database, which you can -make harder by making the config dir only eneterable / readable by root. - - -@section gsprep Lwsgs Preparing the db directory - -You will have to prepare the db directory so it's suitable for the lwsws user to use, -that usually means apache, eg - -``` - # mkdir -p /var/www/sessions - # chown root:apache /var/www/sessions - # chmod 770 /var/www/sessions -``` - -@section gsrmail Lwsgs Email configuration - -lwsgs will can send emails by talking to an SMTP server on localhost:25. That -will usually be sendmail or postfix, you should confirm that works first by -itself using the `mail` application to send on it. - -lwsgs has been tested on stock Fedora sendmail and postfix. - - -@section gsap Lwsgs Integration with another protocol - -lwsgs is designed to provide sessions and accounts in a standalone and generic way. - -But it's not useful by itself, there will always be the actual application who wants -to make use of generic-sessions features. - -We provide the "messageboard" plugin as an example of how to integrate with -your actual application protocol. - -The basic approach is the 'real' protocol handler (usually a plugin itself) -subclasses the generic-sessions plugin and calls through to it by default. - -The "real" protocol handler entirely deals with ws-related stuff itself, since -generic-sessions does not use ws. But for - - - LWS_CALLBACK_HTTP - - LWS_CALLBACK_HTTP_BODY - - LWS_CALLBACK_HTTP_BODY_COMPLETION - - LWS_CALLBACK_HTTP_DROP_PROTOCOL - -the "real" protocol handler checks if it recognizes the activity (eg, his own -POST form URL) and if not, passes stuff through to the generic-sessions protocol callback to handle it. To simplify matters the real protocol can just pass -through any unhandled messages to generic-sessions. - -The "real" protocol can get a pointer to generic-sessions protocol on the -same vhost using - -``` - vhd->gsp = lws_vhost_name_to_protocol(vhd->vh, "protocol-generic-sessions"); -``` - -The "real" protocol must also arrange generic-sessions per_session_data in his -own per-session allocation. To allow keeping generic-sessions opaque, the -real protocol must allocate that space at runtime, using the pss size -the generic-sessions protocol struct exposes - -``` - struct per_session_data__myapp { - void *pss_gs; - ... - - pss->pss_gs = malloc(vhd->gsp->per_session_data_size); -``` - -The allocation reserved for generic-sessions is then used as user_space when -the real protocol calls through to the generic-sessions callback - -``` - vhd->gsp->callback(wsi, reason, &pss->pss_gs, in, len); -``` - -In that way the "real" protocol can subclass generic-sessions functionality. - - -To ease management of these secondary allocations, there are callbacks that -occur when a wsi binds to a protocol and when the binding is dropped. These -should be used to malloc and free and kind of per-connection -secondary allocations. - -``` - case LWS_CALLBACK_HTTP_BIND_PROTOCOL: - if (!pss || pss->pss_gs) - break; - - pss->pss_gs = malloc(vhd->gsp->per_session_data_size); - if (!pss->pss_gs) - return -1; - - memset(pss->pss_gs, 0, vhd->gsp->per_session_data_size); - break; - - case LWS_CALLBACK_HTTP_DROP_PROTOCOL: - if (vhd->gsp->callback(wsi, reason, pss ? pss->pss_gs : NULL, in, len)) - return -1; - - if (pss->pss_gs) { - free(pss->pss_gs); - pss->pss_gs = NULL; - } - break; -``` - - -#section gsapsib Getting session-specific information from another protocol - -At least at the time when someone tries to upgrade an http(s) connection to -ws(s) with your real protocol, it is necessary to confirm the cookie the http(s) -connection has with generic-sessions and find out his username and other info. - -Generic sessions lets another protocol check it again by calling his callback, -and lws itself provides a generic session info struct to pass the related data - -``` - struct lws_session_info { - char username[32]; - char email[100]; - char ip[72]; - unsigned int mask; - char session[42]; - }; - - struct lws_session_info sinfo; - ... - vhd->gsp->callback(wsi, LWS_CALLBACK_SESSION_INFO, - &pss->pss_gs, &sinfo, 0); -``` - -After the call to generic-sessions, the results can be - - - all the strings will be zero-length and .mask zero, there is no usable cookie - - - only .ip and .session are set: the cookie is OK but no user logged in - - - all the strings contain information about the logged-in user - -the real protocol can use this to reject attempts to open ws connections from -http connections that are not authenticated; afterwards there's no need to -check the ws connection auth status again. - diff -Nru libwebsockets-3.2.1/READMEs/README.generic-table.md libwebsockets-4.1.6/READMEs/README.generic-table.md --- libwebsockets-3.2.1/READMEs/README.generic-table.md 2019-12-18 14:45:31.000000000 +0000 +++ libwebsockets-4.1.6/READMEs/README.generic-table.md 1970-01-01 00:00:00.000000000 +0000 @@ -1,219 +0,0 @@ -Notes about generic-table -========================= - -@section gtint What is generic-table? - -Generic-table is a JSON schema and client-side JS file that makes it easy to -display live, table structured HTML over a ws link. - -An example plugin and index.html using it are provided, but lwsgt itself doesn't -have its own plugin, it's just a JSON schema and client-side JS that other -plugins can use to simplify displaying live, table-based data without having -to reinvent the wheel each time. - -The ws protocol sends JSON describing the table, and then JSON updating the table -contents when it chooses, the brower table is updated automatically, live. - -\image html lwsgt-overview.png - - - Example protocol plugin (displays directory contents): https://github.com/warmcat/libwebsockets/tree/master/plugins/generic-table/protocol_table_dirlisting.c - - - Example HTML: https://github.com/warmcat/libwebsockets/tree/master/plugins/generic-table/assets/index.html - - - lwsgt.js (client-side table rendering / ws link management): https://github.com/warmcat/libwebsockets/tree/master/plugins/generic-table/assets/lwsgt.js - - -@section gteb Enabling for build - -Enable the demo plugin at CMake with -DLWS_WITH_PLUGINS=1 - - -@section gtinth Integrating with your html - - - In your HEAD section, include lwsgt.js - -``` - -``` - - - Also in your HEAD section, style the lwsgt CSS, eg - -``` - -``` - -You can skip this but the result will be less beautiful until some CSS is -provided. - - - In your body section, declare a div with an id (can be whatever you want) - -``` -
-``` - -lwsgt JS will put its content there. - - - Finally in a -``` - -In the callback, you can recover the ws object by `window[gt].lwsgt_ws`. - - -@section gtc Lwsgt constructor - -To instantiate the ws link and lwsgt instance, your HTML must call a lwsgt -constructor for each region on the page managed by lwsgt. - -`var myvar = new lwsgt_initial(title, ws_protocol, div_id, click_cb, myvar);` - -All of the arguments are strings. - -| Parameter | Description | -|-----------------|---------------------------------------------------------| -| title | Title string to go above the table | -| ws_protocol | Protocol name string to use when making ws connection | -| div_id | HTML id of div to fill with content | -| click_cb | Callback function name string to handle clickable links | -| myvar | Name of var used to hold this instantiation globally | - -Note "myvar" is needed so it can be passed to the click handling callback. - - -@section gtclick Lwsgt click handling function - -When a clickable link produced by lwsgt is clicked, the function named in the -click_cb parameter to lwsgt_initial is called. - -That function is expected to take four parameters, eg - -`function lwsgt_dir_click(gt, u, col, row)` - -| Parameter | Description | -|------- ---|-----------------------------------------------------------| -| gt | Name of global var holding this lwsgt context (ie, myvar) | -| u | Link "url" string | -| col | Table column number link is from | -| row | Table row number link is from | - - - -@section gtgj Generic-table JSON - -### Column layout - -When the ws connection is established, the protocol should send a JSON message -describing the table columns. For example - -``` - "cols": [ - { "name": "Date" }, - { "name": "Size", "align": "right" }, - { "name": "Icon" }, - { "name": "Name", "href": "uri"}, - { "name": "uri", "hide": "1" } - ] - } -``` - - - This describes 5 columns - - - Only four columns (not "uri") should be visible - - - "Name" should be presented as a clickable link using "uri" as the - destination, when a "uri" field is presented. - - - "Size" field should be presented aligned to the right - - ### Breadcrumbs - - When a view is hierarchical, it's useful to provide a "path" with links back - in the "path", known as "breadcrumbs". - - Elements before the last one should provide a "url" member as well as the - displayable name, which is used to create the link destination. - - The last element, being the current displayed page should not have a url - member and be displayed without link style. - - - ``` - "breadcrumbs":[{"name":"top", "url": "/" }, {"name":"mydir"}] - ``` - - ### Table data - - The actual file data consists of an array of rows, containing the columns - mentioned in the original "cols" section. - - ``` - "data":[ - { - "Icon":" ", - "Date":"2015-Feb-06 03:08:35 +0000", - "Size":"1406", - "uri":"./serve//favicon.ico", - "Name":"favicon.ico" - } - ] - - ``` - - @section gtdirl Setting up protocol-lws-table-dirlisting - - The example protocol needs two mounts, one to provide the index.html, js and - the protocol itself - - ``` - { - "mountpoint": "/dirtest", - "origin": "file:///usr/share/libwebsockets-test-server/generic-table", - "origin": "callback://protocol-lws-table-dirlisting", - "default": "index.html", - "pmo": [{ - "dir": "/usr/share/libwebsockets-test-server" - }] - }, -``` - -The protocol wants a per-mount option (PMO) to tell it the base directory it -is serving from, named "dir". - -The other mount is there to simply serve items that get clicked on from the -table in a secure way - -``` - { - "mountpoint": "/dirtest/serve", - "origin": "file:///usr/share/libwebsockets-test-server", - "default": "index.html" - }, -``` - -This last bit is not related to using lwsgt itself. diff -Nru libwebsockets-3.2.1/READMEs/README.h2-long-poll.md libwebsockets-4.1.6/READMEs/README.h2-long-poll.md --- libwebsockets-3.2.1/READMEs/README.h2-long-poll.md 1970-01-01 00:00:00.000000000 +0000 +++ libwebsockets-4.1.6/READMEs/README.h2-long-poll.md 2020-12-01 17:40:26.000000000 +0000 @@ -0,0 +1,55 @@ +# h2 long poll in lws + +lws server and client can support "immortal" streams that are +not subject to normal timeouts under a special condition. These +are read-only (to the client). + +Network connections that contain at least one immortal stream +are themselves not subject to timeouts until the last immortal +stream they are carrying closes. + +Because of this, it's recommended there is some other way of +confirming that the client is still active. + +## Setting up lws server for h2 long poll + +Vhosts that wish to allow clients to serve these immortal +streams need to set the info.options flag `LWS_SERVER_OPTION_VH_H2_HALF_CLOSED_LONG_POLL` +at vhost creation time. The JSON config equivalent is to set + +``` +"h2-half-closed-long-poll": "1" +``` + +on the vhost. That's all that is needed. + +Streams continue to act normally for timeout with the exception +client streams are allowed to signal they are half-closing by +sending a zero-length DATA frame with END_STREAM set. These +streams are allowed to exist outside of any timeout and data +can be sent on them at will in the server -> client direction. + +## Setting client streams for long poll + +An API is provided to allow established h2 client streams to +transition to immortal mode and send the END_STREAM to the server +to indicate it. + +``` +int +lws_h2_client_stream_long_poll_rxonly(struct lws *wsi); +``` + +## Example applications + +You can confirm the long poll flow simply using example applications. +Build and run `http-server/minimal-http-server-h2-long-poll` in one +terminal. + +In another, build the usual `http-client/minimal-http-client` example +and run it with the flags `-l --long-poll` + +The client will connect to the server and transition to the immortal mode. +The server sends a timestamp every minute to the client, and that will +stay up without timeouts. + diff -Nru libwebsockets-3.2.1/READMEs/README.jwt.md libwebsockets-4.1.6/READMEs/README.jwt.md --- libwebsockets-3.2.1/READMEs/README.jwt.md 1970-01-01 00:00:00.000000000 +0000 +++ libwebsockets-4.1.6/READMEs/README.jwt.md 2020-12-01 17:40:26.000000000 +0000 @@ -0,0 +1,176 @@ +# JWT support in lws + +lws supports the common usage scenarios of JWS (signed) JWT generation, +parsing and transferring in and out as http cookies. Care is taken to provide +helpers that implement the current security best practices for cookie handling +and JWT validation. All of the common algorithms like ES512 are supported +along with JWK generation and handling apis. + +The build options needed are `-DLWS_WITH_JOSE=1` `-DLWS_WITH_GENCRYPTO=1`. + +Underlying JOSE primitives are exposed as apis, some JWT specific primitives +and finally a JWT-via http cookie level creation apis each building on top of +what was underneath. + +The higher level APIs are provided additionally because they have the most +opportunity for implementation pitfalls like not validating alg carefully, or +not using the latest cookie security options; the provided APIs handle that +centrally for you. If your needs vary from what the higher level apis are +doing, you can cut-and-paste out those implementations and create your own +using the public lower level apis. + +## LWS JWT fields + +Lws JWT uses mainly well-known fields + +Field|Std|Meaning +---|---|--- +iss|yes|Issuer, typically the domain like "warmcat.com" +aud|yes|Audience, typically a url path like "https://warmcat.com/sai" +iat|yes|Unix-time "Issued At" +nbf|yes|Unix-time "Not Before" +exp|yes|Unix-time "Expired" +sub|yes|Subject, eg, a username or user email +csrf|no|A random 16-char hex token generated with the JWT for use in links specific to the JWT bearer +ext|no|Application-specific JSON sub-object with whatever fields you need, eg, `"authorization": 1` + +## Approach for JWT as session token + +Once JWTs are produced, they are autonomous bearer tokens, if they are not kept +secret between the browser and the site, they will be accepted as evidence for +having rights to the session from anyone. + +Requiring https, and various other cookie hardening techniques make it more +difficult for them to leak, but it is still necessary to strictly constrain the +token's validity time, usually to a few tens of minutes or how long it takes a +user to login and get stuff done on the site in one session. + +## CSRF mitigation + +Cross Site Request Forgery (CSRF) is a hacking scenario where an authorized +user with a valid token is tricked into clicking on an external link that +performs some action with side-effects on the site he has active auth on. For +example, he has a cookie that's logged into his bank, and the link posts a form +to the bank site transferring money to the attacker. + +Lws JWT mitigates this possibility by putting a random secret in the generated +JWT; when the authorized user presents his JWT to generate the page, generated +links that require auth to perform their actions include the CSRF string from +that user's current JWT. + +When the user clicks those links intentionally, the CSRF string in the link +matches the CSRF string in the currently valid JWT that was also provided to +the server along with the click, and all is well. + +An attacker does not know the random, ephemeral JWT CSRF secret to include in +forged links, so the attacker-controlled action gets rejected at the server as +having used an invalid link. + +The checking and link manipulation need to be implemented in user code / JS... +lws JWT provides the random CSRF secret in the JWT and makes it visible to the +server when the incoming JWT is processed. + +## Need for client tracking of short JWT validity times + +Many links or references on pages do not require CSRF strings, only those that +perform actions with side-effects like deletion or money transfer should need +protecting this way. + +Due to CSRF mitigation, generated pages containing the protected links +effectively have an expiry time linked to that of the JWT, since only the bearer +of the JWT used to generate the links on the page can use them; once that +expires actually nobody can use them and the page contents, which may anyway +be showing content that only authenticated users can see must be invalidated and +re-fetched. Even if the contents are visible without authentication, additional +UI elements like delete buttons that should only be shown when authenticated +will wrongly still be shown + +For that reason, the client should be informed by the server along with the +authentication status, the expiry time of it. The client should then by itself +make arrangements to refresh the page when this time is passed, +either showing an unauthenticated version of the same page if it exists, or by +redirecting to the site homepage if showing any of the contents required +authentication. The user can then log back in using his credientials typically +stored in the browser's password store and receive a new short-term JWT with a +new random csrf token along with a new page using the new csrf token in its +links. + +## Considerations for long-lived connections + +Once established as authorized, websocket links may be very long-lived and hold +their authorization state at the server. Although the browser monitoring the +JWT reloading the page on auth expiry should mitigate this, an attacker can +choose to just not do that and have an immortally useful websocket link. + +At least for actions on the long-lived connection, it should not only confirm +the JWT authorized it but that the current time is still before the "exp" time +in the JWT, this is made available as `expiry_unix_time` in the args struct +after successful validation. + +Ideally the server should close long-lived connections according to their auth +expiry time. + +## JWT lower level APIs + +The related apis are in `./include/libwebsockets/lws-jws.h` + +### Validation of JWT + +``` +int +lws_jwt_signed_validate(struct lws_context *ctx, struct lws_jwk *jwk, + const char *alg_list, const char *com, size_t len, + char *temp, int tl, char *out, size_t *out_len); +``` + +### Composing and signing JWT + +``` +int +lws_jwt_sign_compact(struct lws_context *ctx, struct lws_jwk *jwk, + const char *alg, char *out, size_t *out_len, char *temp, + int tl, const char *format, ...); +``` + +## JWT creation and cookie get / set API + +Both the validation and signing apis use the same struct to contain their +aguments. + +``` +struct lws_jwt_sign_set_cookie { + struct lws_jwk *jwk; + /**< entry: required signing key */ + const char *alg; + /**< entry: required signing alg, eg, "ES512" */ + const char *iss; + /**< entry: issuer name to use */ + const char *aud; + /**< entry: audience */ + const char *cookie_name; + /**< entry: the name of the cookie */ + char sub[33]; + /**< sign-entry, validate-exit: subject */ + const char *extra_json; + /**< sign-entry, validate-exit: + * optional "ext" JSON object contents for the JWT */ + size_t extra_json_len; + /**< validate-exit: + * length of optional "ext" JSON object contents for the JWT */ + const char *csrf_in; + /**< validate-entry: + * NULL, or an external CSRF token to check against what is in the JWT */ + unsigned long expiry_unix_time; + /**< sign-entry: seconds the JWT and cookie may live, + * validate-exit: expiry unix time */ +}; + +int +lws_jwt_sign_token_set_http_cookie(struct lws *wsi, + const struct lws_jwt_sign_set_cookie *i, + uint8_t **p, uint8_t *end); +int +lws_jwt_get_http_cookie_validate_jwt(struct lws *wsi, + struct lws_jwt_sign_set_cookie *i, + char *out, size_t *out_len); +``` diff -Nru libwebsockets-3.2.1/READMEs/README.lws_plugins.md libwebsockets-4.1.6/READMEs/README.lws_plugins.md --- libwebsockets-3.2.1/READMEs/README.lws_plugins.md 1970-01-01 00:00:00.000000000 +0000 +++ libwebsockets-4.1.6/READMEs/README.lws_plugins.md 2020-12-01 17:40:26.000000000 +0000 @@ -0,0 +1,105 @@ +# lws_plugins + +Lws now offers apis to manage your own user plugins with `LWS_WITH_PLUGINS_API`. +Lws uses these apis internally for protocol plugins and event loop plugins +if they're selected for build. But they are also exported for user code to +use them how you like. + +## Creating your plugin export + +### Specifying your plugin export type + +Lws plugins have a single exported struct with a specified header and a user +defined remainder. The public `lws_plugin_header_t` describes the common +plugin export header, it's defined via libwebsockets.h as + +``` +typedef struct lws_plugin_header { + const char *name; + const char *_class; + + unsigned int api_magic; + /* set to LWS_PLUGIN_API_MAGIC at plugin build time */ + + /* plugin-class specific superclass data follows */ +} lws_plugin_header_t; +``` + +The exported symbol name itself must match the plugin filename, for +example if the symbol name is `my_plugin`, then the filename of the +plugin might be `libmyapp-my_plugin.so` or similar... the matching +part is after the first `-` or `_`, up to the first `.`. The exact +details differ by platform but these rules cover the supported +platforms. If lws has the filename of the plugin, it can then +deduce the symbol export it should look for in the plugin. + +`name` is a freeform human-readable description for the plugin. + +`_class` is shared by your plugins and used to select them from other kinds +of plugin that may be in the same dir. So choose a unique name like +`"myapp xxx plugin"` or whatever shared by all plugins of that class. + +`api_magic` is set to `LWS_PLUGIN_API_MAGIC` to detect if the plugin is +incompatible with the lws plugin apis version. + +So for example your plugin type wrapping the header might look like + +``` +typedef struct myapp_plugin { + lws_plugin_header_t hdr; /* must be first */ + + /* optional extra data like function pointers from your plugin */ + mytype_t mymember; + /* ... */ +} myapp_plugin_t; +``` + +Typically, you will put function pointers to whatever capability your plugin +class offers as the additional members. + +## Building your own plugins + +Plugins are built standalone, cmake is recommended but you can do what you want. + +The only requirement is the single visible export of the plugin name, eg + +``` +const myapp_plugin_t my_plugin = { + .hdr = { + "my_plugin", + "myapp xxx plugin", + LWS_PLUGIN_API_MAGIC + }, + + .mymember = my_plugin_init, + /*...*/ +}; +``` + +## Bringing in plugins at runtime + +Lws provides an api to import plugins into the process space and another to +remove and destroy plugins. + +You can take two approaches depending on what you're doing, either bring in and +later destroy a whole class of plugins at once, and walk them via a linked-list, +or bring in and later destroy a single specific plugin from the class by filtering +on its specific export name. + +See `include/libwebsockets/lws-protocols-plugins.h` for documentation. + +``` +LWS_VISIBLE LWS_EXTERN int +lws_plugins_init(struct lws_plugin **pplugin, const char * const *d, + const char *_class, const char *filter, + each_plugin_cb_t each, void *each_user); + +LWS_VISIBLE LWS_EXTERN int +lws_plugins_destroy(struct lws_plugin **pplugin, each_plugin_cb_t each, + void *each_user); +``` + +`struct lws_plugin` is a public struct that contains the linked-list of loaded +plugins and a pointer to its exported header object, so you can walk this +after loading. + diff -Nru libwebsockets-3.2.1/READMEs/README.lws_retry.md libwebsockets-4.1.6/READMEs/README.lws_retry.md --- libwebsockets-3.2.1/READMEs/README.lws_retry.md 1970-01-01 00:00:00.000000000 +0000 +++ libwebsockets-4.1.6/READMEs/README.lws_retry.md 2020-12-01 17:40:26.000000000 +0000 @@ -0,0 +1,98 @@ +# `lws_retry_bo_t` client connection management + +This struct sets the policy for delays between retries, and for +how long a connection may be 'idle' before it first tries to +ping / pong on it to confirm it's up, or drops the connection +if still idle. + +## Retry rate limiting + +You can define a table of ms-resolution delays indexed by which +connection attempt number is ongoing, this is pointed to by +`.retry_ms_table` with `.retry_ms_table_count` containing the +count of table entries. + +`.conceal_count` is the number of retries that should be allowed +before informing the parent that the connection has failed. If it's +greater than the number of entries in the table, the last entry is +reused for the additional attempts. + +`.jitter_percent` controls how much additional random delay is +added to the actual interval to be used... this stops a lot of +devices all synchronizing when they try to connect after a single +trigger event and DDoS-ing the server. + +The struct and apis are provided for user implementations, lws does +not offer reconnection itself. + +## Connection validity management + +Lws has a sophisticated idea of connection validity and the need to +reconfirm that a connection is still operable if proof of validity +has not been seen for some time. It concerns itself only with network +connections rather than streams, for example, it only checks h2 +network connections rather than the individual streams inside (which +is consistent with h2 PING frames only working at the network stream +level itself). + +Connections may fail in a variety of ways, these include that no traffic +at all is passing, or, eg, incoming traffic may be received but no +outbound traffic is making it to the network, and vice versa. In the +case that tx is not failing at any point but just isn't getting sent, +endpoints can potentially kid themselves that since "they are sending" +and they are seeing RX, the combination means the connection is valid. +This can potentially continue for a long time if the peer is not +performing keepalives. + +"Connection validity" is proven when one side sends something and later +receives a response that can only have been generated by the peer +receiving what was just sent. This can happen for some kinds of user +transactions on any stream using the connection, or by sending PING / +PONG protocol packets where the PONG is only returned for a received PING. + +To ensure that the generated traffic is only sent when necessary, user +code can report for any stream that it has observed a transaction amounting +to a proof of connection validity using an api. This resets the timer for +the associated network connection before the validity is considered +expired. + +`.secs_since_valid_ping` in the retry struct sets the number of seconds since +the last validity after which lws will issue a protocol-specific PING of some +kind on the connection. `.secs_since_valid_hangup` specifies how long lws +will allow the connection to go without a confirmation of validity before +simply hanging up on it. + +## Defaults + +The context defaults to having a 5m valid ping interval and 5m10s hangup interval, +ie, it'll send a ping at 5m idle if the protocol supports it, and if no response +validating the connection arrives in another 10s, hang up the connection. + +User code can set this in the context creation info and can individually set the +retry policy per vhost for server connections. Client connections can set it +per connection in the client creation info `.retry_and_idle_policy`. + +## Checking for h2 and ws + +Check using paired minimal examples with the -v flag on one or both sides to get a +small validity check period set of 3s / 10s + +Also give, eg, -d1039 to see info level debug logging + +### h2 + +``` +$ lws-minimal-http-server-h2-long-poll -v + +$ lws-minimal-http-client -l -v +``` + +### ws + +``` +$ lws-minimal-ws-server-h2 -s -v + +$ lws-minimal-ws-client-ping -n --server 127.0.0.1 --port 7681 -v +``` + + diff -Nru libwebsockets-3.2.1/READMEs/README.lws_sequencer.md libwebsockets-4.1.6/READMEs/README.lws_sequencer.md --- libwebsockets-3.2.1/READMEs/README.lws_sequencer.md 2019-12-18 14:45:31.000000000 +0000 +++ libwebsockets-4.1.6/READMEs/README.lws_sequencer.md 2020-12-01 17:40:26.000000000 +0000 @@ -1,4 +1,4 @@ -# `lws_sequencer_t` introduction +# `struct lws_sequencer` introduction Often a single network action like a client GET is just part of a larger series of actions, perhaps involving different connections. @@ -10,7 +10,7 @@ ![lws_sequencer](/doc-assets/lws_sequencer.svg) -`lws_sequencer_t` provides a generic way to stage multi-step +`struct lws_sequencer` provides a generic way to stage multi-step operations from inside the event loop. Because it participates in the event loop similar to a wsi, it always operates from the service thread context and can access structures that share the @@ -48,7 +48,7 @@ out a retry cooloff period and then start the retry when the `LWSSEQ_TIMED_OUT` is received, according to the state of the sequencer. -## Creating an `lws_sequencer_t` +## Creating an `struct lws_sequencer` ``` typedef struct lws_seq_info { @@ -63,7 +63,7 @@ ``` ``` -lws_sequencer_t * +struct lws_sequencer * lws_sequencer_create(lws_seq_info_t *info); ``` @@ -77,7 +77,7 @@ lws_seq_events_t event, void *data); ``` -`lws_sequencer_t` objects are private to lws and opaque to the user. A small +`struct lws_sequencer` objects are private to lws and opaque to the user. A small set of apis lets you perform operations on the pointer returned by the create api. @@ -95,7 +95,7 @@ ## Destroying sequencers -`lws_sequencer_t` objects are cleaned up during context destruction if they are +`struct lws_sequencer` objects are cleaned up during context destruction if they are still around. Normally the sequencer callback receives a queued message that diff -Nru libwebsockets-3.2.1/READMEs/README.lws_sul.md libwebsockets-4.1.6/READMEs/README.lws_sul.md --- libwebsockets-3.2.1/READMEs/README.lws_sul.md 2019-12-18 14:45:31.000000000 +0000 +++ libwebsockets-4.1.6/READMEs/README.lws_sul.md 2020-12-01 17:40:26.000000000 +0000 @@ -60,3 +60,40 @@ lws_sul_schedule(context, 0, &sul_stagger, NULL, LWS_SET_TIMER_USEC_CANCEL); ``` +# lws_sul2 and system suspend + +In v4.1, alongside the existing `lws_sul` apis there is a refactor and additional +functionality aimed at negotiating system suspend, while remaining completely +backwards-compatible with v3.2+ lws_sul apis. + +Devicewide suspend is basically the withdrawal of CPU availability for an unbounded +amount of time, so what may have been scheduled by the user code may miss its time +slot because the cpu was down and nothing is getting serviced. Whether that is +actively desirable, OK, a big disaster, or a failure that will be corrected at other +layers at the cost of, eg, some additional latency, depends on the required device +behaviours and the function of the user code that was scheduled, and its meaning to +the system. + +Before v4.1, lws just offers the same scheduling service for everything both internal +and arranged by user code, and has no way to know what is critical for the device to +operate as intended, and so must force wake from suspend, or if for that scheduled +event 'failure [to get the event] is an option'. + +For example locally-initiated periodic keepalive pings not happening may allow +persistently dead (ie, no longer passing data) connections to remain unrenewed, but +eventually when suspend ends for another reason, the locally-initiated PING probes +will resume and it will be discovered and if the connectivity allows, corrected. + +If the device's function can handle the latency of there being no connectivity in +suspend under those conditions until it wakes for another reason, it's OK for these +kind of timeouts to be suppressed during suspend and basically take the power saving +instead. If for a particular device it's intolerable to ever have a silently dead +connection for more than a very short time compared to suspend durations, then these +kind of timeouts must have the priority to wake the whole device from suspend so +they continue to operate unimpeded. + +That is just one example, lws offers generic scheduler services the user code can +exploit for any purpose, including mission-critical ones. The changes give the user +code a way to tell lws if a particular scheduled event is important enough to the +system operation to wake the system from devicewide suspend. + diff -Nru libwebsockets-3.2.1/READMEs/README.lws_system.md libwebsockets-4.1.6/READMEs/README.lws_system.md --- libwebsockets-3.2.1/READMEs/README.lws_system.md 1970-01-01 00:00:00.000000000 +0000 +++ libwebsockets-4.1.6/READMEs/README.lws_system.md 2020-12-01 17:40:26.000000000 +0000 @@ -0,0 +1,219 @@ +# `lws_system` + +See `include/libwebsockets/lws-system.h` for function and object prototypes. + +## System integration api + +`lws_system` allows you to set a `system_ops` struct at context creation time, +which can write up some function callbacks for system integration. The goal +is the user code calls these by getting the ops struct pointer from the +context using `lws_system_get_ops(context)` and so does not spread system +dependencies around the user code, making it directly usable on completely +different platforms. + +``` +typedef struct lws_system_ops { + int (*reboot)(void); + int (*set_clock)(lws_usec_t us); + int (*attach)(struct lws_context *context, int tsi, lws_attach_cb_t cb, + lws_system_states_t state, void *opaque, + struct lws_attach_item **get); +} lws_system_ops_t; +``` + +|Item|Meaning| +|---|---| +|`(*reboot)()`|Reboot the system| +|`(*set_clock)()`|Set the system clock| +|`(*attach)()`|Request an event loop callback from another thread context| + +### `reboot` + +Reboots the device + +### `set_clock` + +Set the system clock to us-resolution Unix time in seconds + +### `attach` + +Request a callback from the event loop from a foreign thread. This is used, for +example, for foreign threads to set up their event loop activity in their +callback, and eg, exit once it is done, with their event loop activity able to +continue wholly from the lws event loop thread and stack context. + +## Foreign thread `attach` architecture + +When lws is started, it should define an `lws_system_ops_t` at context creation +time which defines its `.attach` handler. In the `.attach` handler +implementation, it should perform platform-specific locking around a call to +`__lws_system_attach()`, a public lws api that actually queues the callback +request and does the main work. The platform-specific wrapper is just there to +do the locking so multiple calls from different threads to the `.attach()` +operation can't conflict. + +User code can indicate it wants a callback from the lws event loop like this: + +``` +lws_system_get_ops(context)->attach(context, tsi, cb, state, opaque, NULL) +``` + +`context` is a pointer to the lws_context, `tsi` is normally 0, `cb` is the user +callback in the form + +``` +void (*lws_attach_cb_t)(struct lws_context *context, int tsi, void *opaque); +``` + +`state` is the `lws_system` state we should have reached before performing the +callback (usually, `LWS_SYSTATE_OPERATIONAL`), and `opaque` is a user pointer that +will be passed into the callback. + +`cb` will normally want to create scheduled events and set up lws network-related +activity from the event loop thread and stack context. + +Once the event loop callback has been booked by calling this api, the thread and +its stack context that booked it may be freed. It will be called back and can +continue operations from the lws event loop thread and stack context. For that +reason, if `opaque` is needed it will usually point to something on the heap, +since the stack context active at the time the callback was booked may be long +dead by the time of the callback. + +See ./lib/system/README.md for more details. + +## `lws_system` blobs + +"Blobs" are arbitrary binary objects that have a total length. Lws lets you set +them in two ways + + - "directly", by pointing to them, which has no heap implication + + - "heap", by adding one or more arbitrary chunk to a chained heap object + +In the "heap" case, it can be incrementally defined and the blob doesn't all +have to be declared at once. + +For read, the same api allows you to read all or part of the blob into a user +buffer. + +The following kinds of blob are defined + +|Item|Meaning| +|---|---| +|`LWS_SYSBLOB_TYPE_AUTH`|Auth-related blob 1, typically a registration token| +|`LWS_SYSBLOB_TYPE_AUTH + 1`|Auth-related blob 2, typically an auth token| +|`LWS_SYSBLOB_TYPE_CLIENT_CERT_DER`|Client cert public part| +|`LWS_SYSBLOB_TYPE_CLIENT_KEY_DER`|Client cert key part| +|`LWS_SYSBLOB_TYPE_DEVICE_SERIAL`|Arbitrary device serial number| +|`LWS_SYSBLOB_TYPE_DEVICE_FW_VERSION`|Arbitrary firmware version| +|`LWS_SYSBLOB_TYPE_DEVICE_TYPE`|Arbitrary Device Type identifier| +|`LWS_SYSBLOB_TYPE_NTP_SERVER`|String with the ntp server address (defaults to pool.ntp.org)| + +### Blob handle api + +Returns an object representing the blob for a particular type (listed above) + +``` +lws_system_blob_t * +lws_system_get_blob(struct lws_context *context, lws_system_blob_item_t type, + int idx); +``` + +### Blob Setting apis + +Sets the blob to point length `len` at `ptr`. No heap allocation is used. + +``` +void +lws_system_blob_direct_set(lws_system_blob_t *b, const uint8_t *ptr, size_t len); +``` + +Allocates and copied `len` bytes from `buf` into heap and chains it on the end of +any existing. + +``` +int +lws_system_blob_heap_append(lws_system_blob_t *b, const uint8_t *buf, size_t len) +``` + +Remove any content from the blob, freeing it if it was on the heap + +``` +void +lws_system_blob_heap_empty(lws_system_blob_t *b) +``` + +### Blob getting apis + +Get the total size of the blob (ie, if on the heap, the aggreate size of all the +chunks that were appeneded) + +``` +size_t +lws_system_blob_get_size(lws_system_blob_t *b) +``` + +Copy part or all of the blob starting at offset ofs into a user buffer at buf. +`*len` should be the length of the user buffer on entry, on exit it's set to +the used extent of `buf`. This works the same whether the bob is a direct pointer +or on the heap. + +``` +int +lws_system_blob_get(lws_system_blob_t *b, uint8_t *buf, size_t *len, size_t ofs) +``` + +If you know that the blob was handled as a single direct pointer, or a single +allocation, you can get a pointer to it without copying using this. + +``` +int +lws_system_blob_get_single_ptr(lws_system_blob_t *b, const uint8_t **ptr) +``` + +### Blob destroy api + +Deallocates any heap allocation for the blob + +``` +void +lws_system_blob_destroy(lws_system_blob_t *b) +``` + + +## System state and notifiers + +Lws implements a state in the context that reflects the readiness of the system +for various steps leading up to normal operation. By default it acts in a +backwards-compatible way and directly reaches the OPERATIONAL state just after +the context is created. + +However other pieces of lws, and user, code may define notification handlers +that get called back when the state changes incrementally, and may veto or delay +the changes until work necessary for the new state has completed asynchronously. + +The generic states defined are: + +|State|Meaning| +|---|---| +|`LWS_SYSTATE_CONTEXT_CREATED`|The context was just created.| +|`LWS_SYSTATE_INITIALIZED`|The vhost protocols have been initialized| +|`LWS_SYSTATE_IFACE_COLDPLUG`|Existing network interfaces have been iterated| +|`LWS_SYSTATE_DHCP`|Network identity is available| +|`LWS_SYSTATE_TIME_VALID`|The system knows the time| +|`LWS_SYSTATE_POLICY_VALID`|If the system needs information about how to act from the net, it has it| +|`LWS_SYSTATE_REGISTERED`|The device has a registered identity| +|`LWS_SYSTATE_AUTH1`|The device identity has produced a time-limited access token| +|`LWS_SYSTATE_AUTH2`|Optional second access token for different services| +|`LWS_SYSTATE_OPERATIONAL`|The system is ready for user code to work normally| +|`LWS_SYSTATE_POLICY_INVALID`|All connections are being dropped because policy information is changing. It will transition back to `LWS_SYSTATE_INITIALIZED` and onward to `OPERATIONAL` again afterwards with the new policy| + +### Inserting a notifier + +You should create an object `lws_system_notify_link_t` in non-const memory and zero it down. +Set the `notify_cb` member and the `name` member and then register it using either +`lws_system_reg_notifier()` or the `.register_notifier_list` +member of the context creation info struct to make sure it will exist early +enough to see all events. The context creation info method takes a list of +pointers to notify_link structs ending with a NULL entry. + diff -Nru libwebsockets-3.2.1/READMEs/README.plugin-sshd-base.md libwebsockets-4.1.6/READMEs/README.plugin-sshd-base.md --- libwebsockets-3.2.1/READMEs/README.plugin-sshd-base.md 2019-12-18 14:45:31.000000000 +0000 +++ libwebsockets-4.1.6/READMEs/README.plugin-sshd-base.md 2020-12-01 17:40:26.000000000 +0000 @@ -47,11 +47,10 @@ ## License -lws-ssh-base is Free Software, available under libwebsocket's LGPLv2 + -static linking exception license. +lws-ssh-base is Free Software, available under libwebsockets' MIT license. The crypto parts are available elsewhere under a BSD license. But for -simplicity the whole plugin is under LGPLv2. +simplicity the whole plugin is under MIT. ## Generating your own keys diff -Nru libwebsockets-3.2.1/READMEs/README.release-policy.md libwebsockets-4.1.6/READMEs/README.release-policy.md --- libwebsockets-3.2.1/READMEs/README.release-policy.md 2019-12-18 14:45:31.000000000 +0000 +++ libwebsockets-4.1.6/READMEs/README.release-policy.md 2020-12-01 17:40:26.000000000 +0000 @@ -1,12 +1,34 @@ # lws release policy +## How should users consume lws? + +The one definitively wrong way to consume lws (or anything else) is "import" some +version of it into your proprietary tree and think you will stick with that +forever, perhaps piling cryptic fixes or hacks on top until quite quickly, +nobody dare think about updating it. + +The stable releases go on to a branch like v4.0-stable as described below, over +time these attract dozens or even hundreds of minor or major fix patches +backported from master. So you should not consume tags like v4.0.0 but build +into your planning that you will need to follow v4.0-stable in order to stay on +top of known bugs. + +And we only backport fixes to the last stable release, although we will make +exceptions for important fixes. So after a while, trying to stick with one +old versions means nobody is providing security fixes on it any more. So you +should build into your planning that you will follow lws release upgrades. + +If you find problems and create fixes, please upstream them, simplifying your +life so you can just directly consume the upstream tree with no private changes. + ## Master branch Master branch is the default and all new work happens there. It's unstable and subject to history rewrites, patches moving about and being squashed etc. In terms of it working, it is subject to passing CI tests including a battery of runtime tests, so if it is passing CI as it usually is then it's probably in -usable shape. +usable shape. See "Why no history on master" below for why it's managed like +that. ![all work happens on master](../doc-assets/lws-relpol-1.svg) @@ -64,9 +86,10 @@ ![backports from master to stable](../doc-assets/lws-relpol-3.svg) If there is something you need in a later lws version that is not backported, -you need to either backport it yourself (remember that lws is LGPL and you must -provide your changes when you distribute the binary) or use a later lws version. -Using a more recent version of lws is almost always the correct way. +you need to either backport it yourself or use a later lws version. +Using a more recent version of lws (and contributing fixes and changes so you +yourself can get them easily as well as contributing for others) is almost +always the correct way. ## Stable point releases @@ -85,4 +108,19 @@ ![backport to multiple stable branches](../doc-assets/lws-relpol-5.svg) +## Why no history on master + +Git is a wonderful tool that can be understood to have two main modes of operation, +merge and rebase that are mutually exclusive. Most devs only use merge / pull, +but rebase / fetch is much more flexible. Running master via rebases allows me to +dispense with feature branches during development and enables tracking multiple +in-progress patches in-tree by updating them in place. If this doesn't make +sense or seems heretical to you, it's OK I don't need devsplain'ing about it, +just sit back and enjoy the clean, rapid development results. + +Since stable branches don't allow new features, they are run as traditional trees +with a history, like a one-way pile of patches on top of the original release. If +CI shows something is messed up with the latest patch, I will edit it in-place if +it has only been out for a few hours, but there is no re-ordering or other history +manipulation. diff -Nru libwebsockets-3.2.1/READMEs/README.test-apps.md libwebsockets-4.1.6/READMEs/README.test-apps.md --- libwebsockets-3.2.1/READMEs/README.test-apps.md 2019-12-18 14:45:31.000000000 +0000 +++ libwebsockets-4.1.6/READMEs/README.test-apps.md 2020-12-01 17:40:26.000000000 +0000 @@ -24,7 +24,7 @@ NOTE this method implies libuv is used by lws, to provide crossplatform implementations of timers, dynamic lib loading etc for plugins and lwsws. -2) test-server-v2.0.c +2) Using plugins in code This method lets you configure web serving in code, instead of using lwsws. @@ -34,7 +34,7 @@ $ cmake .. -DLWS_WITH_PLUGINS=1 -See [test-server-v2.0.c](../test-apps/test-server-v2.0.c) +See, eg, the [test-server](../test-apps/test-server.c) 3) protocols in the server app @@ -302,7 +302,7 @@ ``` $ libwebsockets-test-fraggle libwebsockets test fraggle - (C) Copyright 2010-2011 Andy Green licensed under LGPL2.1 + (C) Copyright 2010-2011 Andy Green licensed under MIT Compiled with SSL support, not using it Listening on port 7681 server sees client connect @@ -318,7 +318,7 @@ ``` $ libwebsockets-test-fraggle -c localhost libwebsockets test fraggle - (C) Copyright 2010-2011 Andy Green licensed under LGPL2.1 + (C) Copyright 2010-2011 Andy Green licensed under MIT Client mode Connecting to localhost:7681 denied deflate-stream extension diff -Nru libwebsockets-3.2.1/READMEs/README.udp.md libwebsockets-4.1.6/READMEs/README.udp.md --- libwebsockets-3.2.1/READMEs/README.udp.md 1970-01-01 00:00:00.000000000 +0000 +++ libwebsockets-4.1.6/READMEs/README.udp.md 2020-12-01 17:40:26.000000000 +0000 @@ -0,0 +1,50 @@ +## Using UDP in lws + +UDP is supported in lws... the quickest way is to use the api +`lws_create_adopt_udp()` which returns a wsi bound to the provided +vhost, protocol, `lws_retry` struct, dns address and port. + +The wsi can be treated normally and `lws_write()` used to write on +it. + +## Implementing UDP retries + +Retries are important in udp but there's no standardized ack method +unlike tcp. Lws allows you to bind an `lws_retry` struct describing +the policy to the udp wsi, but since one UDP socket may have many +transactions in flight, the `lws_sul` and `uint16_t` to count the +retries must live in the user's transaction object like this + +``` +... + lws_sorted_usec_list_t sul; + uint16_t retry; +... +``` + +in the `LWS_CALLBACK_RAW_WRITEABLE` callback, before doing the write, +set up the retry like this + +``` + if (lws_dll2_is_detached(&transaction->sul_write.list) && + lws_retry_sul_schedule_retry_wsi(wsi, &transaction->sul_write, + transaction_retry_write_cb, + &transaction->retry_count_write)) { + /* we have reached the end of our concealed retries */ + lwsl_warn("%s: concealed retries done, failing\n", __func__); + goto retry_conn; + } +``` + +This manages the retry counter in the transaction object, guards against it wrapping, +selects the timeout using the policy bound to the wsi, and sets the `lws_sul` in the +transaction object to call the given callback if the sul time expires. + +In the callback, it should simply call `lws_callback_on_writable()` for the udp wsi. + +## Simulating packetloss + +lws now allows you to set the amount of simulated packetloss on udp rx and tx in +the context creation info struct, using `.udp_loss_sim_tx_pc` and `.udp_loss_sim_rx_pc`, +the values are percentages between 0 and 100. 0, the default, means no packetloss. + diff -Nru libwebsockets-3.2.1/READMEs/release-checklist libwebsockets-4.1.6/READMEs/release-checklist --- libwebsockets-3.2.1/READMEs/release-checklist 2019-12-18 14:45:31.000000000 +0000 +++ libwebsockets-4.1.6/READMEs/release-checklist 2020-12-01 17:40:26.000000000 +0000 @@ -36,45 +36,25 @@ set(CPACK_PACKAGE_VERSION_MINOR "6") set(CPACK_PACKAGE_VERSION_PATCH "0") -5) specfile +5) Announce latest version on README.md - a) rpm version bump to match CMake one +6) Make sure all new READMEs and public headers are in libwebsockets.dox - scripts/libwebsockets.spec - - Version: 1.6.0 - - b) Summarize changelog - - scripts/libwebsockets.spec - -%changelog -* Sun Jan 17 2016 Andrew Cooks 1.6.4-1 -- Bump version to 1.6.4 -- MINOR fix xyz - - c) Use -DLWS_WITH_DISTRO_RECOMMENDED=1 then make package and adapt the .spec - to match the file list - -6) Announce latest version on README.md - -7) Make sure all new READMEs and public headers are in libwebsockets.dox - -8) signed tag +7) signed tag git tag -s vX.Y[.Z] -9) git +8) git a) push b) final CI check, if fail delete tag, kill pushed tags, restart flow -10) website +9) website a) update latest tag for release branch -11) post-relase version bump +10) post-relase version bump Bump the PATCH part of the version to 99 diff -Nru libwebsockets-3.2.1/.sai.json libwebsockets-4.1.6/.sai.json --- libwebsockets-3.2.1/.sai.json 1970-01-01 00:00:00.000000000 +0000 +++ libwebsockets-4.1.6/.sai.json 2020-12-01 17:40:26.000000000 +0000 @@ -0,0 +1,218 @@ +{ + "schema": "sai-1", + + # We're doing separate install into destdir so that the test server + # has somewhere to go to find its /usr/share content like certs + + "platforms": { + "linux-debian-buster/x86_64-amd/gcc": { + "build": "mkdir build destdir;cd build;export CCACHE_DISABLE=1;export SAI_CPACK=\"-G DEB\";cmake .. ${cmake} && make -j && make -j DESTDIR=../destdir install && ctest -j4 --output-on-failure ${cpack}" + }, + "linux-debian-buster/x86-amd/gcc": { + "build": "mkdir build destdir;cd build;export CCACHE_DISABLE=1;export SAI_CPACK=\"-G DEB\";cmake .. ${cmake} && make -j && make -j DESTDIR=../destdir install && ctest -j4 --output-on-failure ${cpack}" + }, + "linux-debian-sid/x86_64-amd/gcc": { + "build": "mkdir build destdir;cd build;export CCACHE_DISABLE=1;export SAI_CPACK=\"-G DEB\";cmake .. ${cmake} && make -j && make -j DESTDIR=../destdir install && ctest -j4 --output-on-failure ${cpack}" + }, + "linux-debian-sid/x86-amd/gcc": { + "build": "mkdir build destdir;cd build;export CCACHE_DISABLE=1;export SAI_CPACK=\"-G DEB\";cmake .. ${cmake} && make -j && make -j DESTDIR=../destdir install && ctest -j4 --output-on-failure ${cpack}" + }, + "linux-ubuntu-1804/x86_64-amd/gcc": { + "build": "mkdir build destdir;cd build;export CCACHE_DISABLE=1;export SAI_CPACK=\"-G DEB\";cmake .. ${cmake} && make -j && make -j DESTDIR=../destdir install && ctest -j4 --output-on-failure ${cpack}" + }, + "linux-ubuntu-2004/x86_64-amd/gcc": { + "build": "mkdir build destdir;cd build;export CCACHE_DISABLE=1;export SAI_CPACK=\"-G DEB\";cmake .. ${cmake} && make -j && make -j DESTDIR=../destdir install && ctest -j4 --output-on-failure ${cpack}" + }, + "linux-fedora-32/x86_64-amd/gcc": { + "build": "rm -rf build destdir ; mkdir build destdir;cd build;export CCACHE_DISABLE=1;export SAI_CPACK=\"-G RPM\";cmake .. ${cmake} && make -j && make -j DESTDIR=../destdir install && ctest -j4 --output-on-failure ${cpack}" + }, + "linux-gentoo/x86_64-amd/gcc": { + "build": "mkdir build destdir;cd build;export CCACHE_DISABLE=1;export SAI_CPACK=\"-G ZIP\";cmake .. ${cmake} && make -j && make -j DESTDIR=../destdir install && ctest -j4 --output-on-failure ${cpack}" + }, + "linux-centos-8/x86_64-amd/gcc": { + "build": "mkdir build destdir;cd build;export CCACHE_DISABLE=1;export SAI_CPACK=\"-G RPM\";cmake .. ${cmake} && make -j && make -j DESTDIR=../destdir install && ctest -j4 --output-on-failure ${cpack}" + }, + "linux-ubuntu-2004/aarch64-a72-bcm2711-rpi4/gcc": { + "build": "mkdir build;cd build;export CCACHE_DISABLE=1;export SAI_CPACK=\"-G DEB\";cmake .. ${cmake} && make -j3 && make -j DESTDIR=../destdir install && ctest -j3 --output-on-failure ${cpack}", + "default": false + }, + "linux-android/aarch64/llvm": { + "build": "mkdir build;cd build;cmake .. -DCMAKE_TOOLCHAIN_FILE=../libwebsockets/contrib/cross-aarch64-android.cmake ${cmake} && make -j", + "default": false + }, + "netbsd-iOS/aarch64/llvm": { + "build": "mkdir build destdir; cd build; export SAI_CPACK=\"-G ZIP\";cmake .. -DCMAKE_MAKE_PROGRAM=/usr/bin/make -DCMAKE_IOS_DEVELOPER_ROOT=/opt/Xcode-beta.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer -DCMAKE_TOOLCHAIN_FILE=contrib/iOS.cmake -DIOS_PLATFORM=OS ${cmake} && make -j", + "default": false + }, + "netbsd-OSX-catalina/x86_64-intel-i3/llvm": { + "build": "mkdir build destdir; cd build; export SAI_CPACK=\"-G ZIP\";export MACOSX_DEPLOYMENT_TARGET=10.14 ; cmake .. -DCMAKE_MAKE_PROGRAM=/usr/bin/make -DLWS_OPENSSL_INCLUDE_DIRS=/usr/local/opt/openssl@1.1/include -DLWS_OPENSSL_LIBRARIES=\"/usr/local/opt/openssl/lib/libssl.dylib;/usr/local/opt/openssl/lib/libcrypto.dylib\" ${cmake} && make -j && make -j DESTDIR=../destdir install && ctest -j4 --output-on-failure ${cpack}" + }, + + "freertos-linkit/arm32-m4-mt7697-usi/gcc": { + "build": "mkdir build;cd build;export CCACHE_DISABLE=1;cmake .. -DCMAKE_INSTALL_PREFIX:PATH=/tmp -DCMAKE_TOOLCHAIN_FILE=../contrib/cross-linkit.cmake -DLWS_PLAT_FREERTOS=1 -DLWS_WITH_ZLIB=0 -DLWS_WITHOUT_EXTENSIONS=1 -DLWS_WITH_ZIP_FOPS=0 -DLWS_WITH_HTTP_STREAM_COMPRESSION=0 -DLWS_WITH_MBEDTLS=1 -DLWS_WITH_FILE_OPS=0 ${cmake};make -j", + "default": false + }, + "windows-10/x86_64-amd/msvc": { + "build": "mkdir build && cd build && set SAI_CPACK=\"-G ZIP\" && cmake .. -DLWS_OPENSSL_LIBRARIES=\"C:\\Program Files\\OpenSSL\\lib\\libssl.lib;C:\\Program Files\\OpenSSL\\lib\\libcrypto.lib\" -DLWS_OPENSSL_INCLUDE_DIRS=\"C:\\Program Files\\OpenSSL\\include\" -DLWS_EXT_PTHREAD_INCLUDE_DIR=\"C:\\Program Files (x86)\\pthreads\\include\" -DLWS_EXT_PTHREAD_LIBRARIES=\"C:\\Program Files (x86)\\pthreads\\lib\\x64\\libpthreadGC2.a\" ${cmake} && cmake --build . --config DEBUG && set CTEST_OUTPUT_ON_FAILURE=1 && ctest . -C DEBUG -j4 --output-on-failure", + "default": false + }, + "windows-10/x86_64-amd/noptmsvc": { + "build": "mkdir build && cd build && set SAI_CPACK=\"-G ZIP\" && cmake .. -DLWS_OPENSSL_LIBRARIES=\"C:\\Program Files\\OpenSSL\\lib\\libssl.lib;C:\\Program Files\\OpenSSL\\lib\\libcrypto.lib\" -DLWS_OPENSSL_INCLUDE_DIRS=\"C:\\Program Files\\OpenSSL\\include\" ${cmake} && cmake --build . --config DEBUG && set CTEST_OUTPUT_ON_FAILURE=1 && ctest . -C DEBUG -j1 --output-on-failure", + "default": false + }, + "windows-10/x86_64-amd/mingw32": { + "build": "mkdir build && cd build && cmake .. -DCMAKE_TOOLCHAIN_FILE=../contrib/cross-w32.cmake ${cmake} && cmake --build . --config DEBUG", + "default": false + }, + "windows-10/x86_64-amd/mingw64": { + "build": "mkdir build && cd build && cmake .. -DCMAKE_TOOLCHAIN_FILE=../contrib/cross-w64.cmake ${cmake} && cmake --build . --config DEBUG", + "default": false + }, + "freertos-espidf/xl6-esp32/gcc": { + # official way to get sdkconfig.h is idf.py menuconfig, but + # no obvious way to do that in CI + "build": "rm -rf ebuild ; mkdir ebuild; cd ebuild; cp -rp ../minimal-examples/embedded/esp32/${cpack} . ; cd ${cpack} ; . /opt/esp/esp-idf/export.sh ; ln -sf ../.. libwebsockets ; idf.py set-target esp32 && cp libwebsockets/minimal-examples/embedded/esp32/${cpack}/sdkconfig . && cp sdkconfig.h build && idf.py ${cmake} build size size-components size-files && cd build && /usr/local/bin/sai-device ${cpack} ESPPORT=0 ctest --output-on-failure", + "default": false + }, + "linux-fedora-32/riscv64-virt/gcc": { + "build": "mkdir build destdir;cd build;export CCACHE_DISABLE=1;export SAI_CPACK=\"-G RPM\";cmake .. ${cmake} && make -j12 && make -j12 DESTDIR=../destdir install && ctest -j4 --output-on-failure ${cpack}", + "default": false + }, + "freebsd-12/x86_64-amd/llvm": { + "build": "mkdir build destdir;cd build;export CCACHE_DISABLE=1;cmake .. ${cmake} && make -j12 && make -j12 DESTDIR=../destdir install" + } + }, + + "configurations": { + "default": { + "cmake": "", + "platforms": "windows-10/x86_64-amd/msvc, windows-10/x86_64-amd/noptmsvc, freertos-linkit/arm32-m4-mt7697-usi/gcc, linux-ubuntu-2004/aarch64-a72-bcm2711-rpi4/gcc, windows-10/x86_64-amd/mingw32, windows-10/x86_64-amd/mingw64" + }, + "esp32-heltec": { + "cmake": "", + "cpack": "esp-heltec-wb32", + "platforms": "none, freertos-espidf/xl6-esp32/gcc" + }, + "esp32-wrover": { + "cmake": "", + "cpack": "esp-wrover-kit", + "platforms": "none, freertos-espidf/xl6-esp32/gcc" + }, + "esp32-wrover-static": { + "cmake": "-DLWS_WITH_SECURE_STREAMS_STATIC_POLICY_ONLY=1 ", + "cpack": "esp-wrover-kit", + "platforms": "none, freertos-espidf/xl6-esp32/gcc" + }, + +# "default-examples-openssl-v3": { +# "cmake": "-DLWS_OPENSSL_LIBRARIES=\"/usr/local/src/openssl/v3/usr/local/lib64/libssl.a;/usr/local/src/openssl/v3/usr/local/lib64/libcrypto.a\" -DLWS_OPENSSL_INCLUDE_DIRS=\"/usr/local/src/openssl/v3/usr/local/include/\" -DLWS_WITH_MINIMAL_EXAMPLES=1 -DLWS_WITH_GENCRYPTO=1", +# "platforms": "none,linux-fedora-32/x86_64-amd/gcc" +# }, + "default-examples-boringssl": { + "cmake": "cmake .. -DLWS_WITH_BORINGSSL=1 -DLWS_OPENSSL_INCLUDE_DIRS=\"/usr/local/src/boringssl/include\" -DLWS_OPENSSL_LIBRARIES=\"/usr/local/src/boringssl/build/ssl/libssl.so;/usr/local/src/boringssl/build/crypto/libcrypto.so\" -DLWS_WITH_MINIMAL_EXAMPLES=1", + "platforms": "none,linux-fedora-32/x86_64-amd/gcc" + }, + "default-wolfssl": { + "cmake": "-DLWS_WITH_WOLFSSL=1 -DLWS_WOLFSSL_INCLUDE_DIRS=/usr/local/include -DLWS_WOLFSSL_LIBRARIES=/usr/local/lib/libwolfssl.so", + "platforms": "none,linux-fedora-32/x86_64-amd/gcc" + }, + "default-examples": { + "cmake": "-DLWS_WITH_MINIMAL_EXAMPLES=1", + "platforms": "windows-10/x86_64-amd/msvc, windows-10/x86_64-amd/noptmsvc, linux-ubuntu-2004/aarch64-a72-bcm2711-rpi4/gcc" + }, + "unix-domain": { + "cmake": "-DUNIX_SOCK=1", + "platforms": "windows-10/x86_64-amd/msvc, windows-10/x86_64-amd/noptmsvc" + }, + "plugins": { + "cmake": "-DLWS_WITH_PLUGINS=1", + "platforms": "none,linux-fedora-32/x86_64-amd/gcc,linux-debian-sid/x86-amd/gcc,linux-debian-sid/x86_64-amd/gcc" + }, + "lws_system": { + "cmake": "-DLWS_WITH_ACME=1 -DLWS_WITH_MINIMAL_EXAMPLES=1 -DCMAKE_BUILD_TYPE=RELEASE -DLWS_WITH_GENCRYPTO=1 -DLWS_WITH_JOSE=1 -DLWS_WITH_SYS_ASYNC_DNS=1 -DLWS_WITH_SYS_NTPCLIENT=1", + "platforms": "windows-10/x86_64-amd/msvc, windows-10/x86_64-amd/noptmsvc" + }, + "secure-streams": { + "cmake": "-DLWS_WITH_SECURE_STREAMS=1", + "platforms": "windows-10/x86_64-amd/msvc, windows-10/x86_64-amd/noptmsvc" + }, + "secure-streams-proxy": { + "cmake": "-DLWS_WITH_SECURE_STREAMS=1 -DLWS_WITH_SECURE_STREAMS_PROXY_API=1", + "platforms": "not windows-10/x86_64-amd/msvc" + }, + "distro_recommended": { + "cmake": "-DLWS_WITH_DISTRO_RECOMMENDED=1", + "platforms": "not freebsd-12/x86_64-amd/llvm, not linkit-cross, not windows-10/x86_64-amd/msvc, linux-ubuntu-2004/aarch64-a72-bcm2711-rpi4/gcc, linux-fedora-32/riscv64-virt/gcc", + "cpack": "&& cpack $SAI_CPACK", + "artifacts": "build/*.rpm, build/*.deb, build/*.zip" + }, + "lwsws": { + "cmake": "-DLWS_WITH_LWSWS=ON -DLWS_WITHOUT_EXTENSIONS=0 -DLWS_WITH_HTTP2=1 -DLWS_WITH_ACME=1 -DLWS_WITH_MINIMAL_EXAMPLES=1 -DCMAKE_BUILD_TYPE=DEBUG -DLWS_WITH_GENCRYPTO=1 -DLWS_WITH_JOSE=1 -DLWS_WITH_SYS_ASYNC_DNS=1 -DLWS_WITH_SYS_NTPCLIENT=1", + # no distro -devel package for libuv + "platforms": "not linux-centos-8/x86_64-amd/gcc" + }, + "lwsws2": { + "cmake": "-DLWS_WITH_LWSWS=ON -DLWS_WITHOUT_EXTENSIONS=0 -DLWS_WITH_HTTP2=1 -DLWS_WITH_ACME=1 -DLWS_WITH_MINIMAL_EXAMPLES=1 -DCMAKE_BUILD_TYPE=DEBUG -DLWS_WITH_LWS_DSH=1", + # no distro -devel package for libuv + "platforms": "not linux-centos-8/x86_64-amd/gcc" + }, + "justmbedtls": { + "cmake": "-DLWS_WITH_MBEDTLS=1 -DLWS_WITHOUT_TESTAPPS=1", + "platforms": "none, linux-android/aarch64/llvm" + }, + "mbedtls": { + "cmake": "-DLWS_WITH_MBEDTLS=1 -DLWS_WITH_HTTP2=1 -DLWS_WITH_LWSWS=1 -DLWS_WITH_MINIMAL_EXAMPLES=1 -DLWS_WITH_JOSE=1 -DCMAKE_BUILD_TYPE=DEBUG", + # no distro -devel package for mbedtls + "platforms": "not linux-centos-8/x86_64-amd/gcc" + }, + "noserver": { + "cmake": "-DLWS_WITHOUT_SERVER=ON -DLWS_WITH_MINIMAL_EXAMPLES=1 -DLWS_WITH_SECURE_STREAMS=1" + }, + "noclient": { + "cmake": "-DLWS_WITHOUT_CLIENT=ON -DLWS_WITH_MINIMAL_EXAMPLES=1" + }, + "ext": { + "cmake": "-DLWS_WITHOUT_EXTENSIONS=0 -DLWS_WITH_MINIMAL_EXAMPLES=1" + }, + "nonetwork": { + "cmake": "-DLWS_WITH_NETWORK=0" + }, + "libev": { + "cmake": "-DLWS_WITH_LIBEV=ON" + }, + "libevent": { + "cmake": "-DLWS_WITH_LIBEVENT=ON" + }, + "libglib": { + "cmake": "-DLWS_WITH_GLIB=ON" + }, + "ipv6": { + "cmake": "-DLWS_IPV6=ON", + "platforms": "windows-10/x86_64-amd/mingw64, windows-10/x86_64-amd/msvc" + }, + "nossl": { + "cmake": "-DLWS_WITH_SSL=OFF", + "platforms": "netbsd-iOS/aarch64/llvm" + }, + "daemon": { + "cmake": "-DLWS_WITHOUT_DAEMONIZE=OFF" + }, + "cgi": { + "cmake": "-DLWS_WITH_CGI=ON" + }, + "nologs": { + "cmake": "-DLWS_WITH_NO_LOGS=ON" + }, + "smp": { + "cmake": "-DLWS_MAX_SMP=32 -DLWS_WITH_MINIMAL_EXAMPLES=1" + }, + "nows": { + "cmake": "-DLWS_ROLE_WS=0" + }, + "threadpool": { + "cmake": "-DLWS_WITH_THREADPOOL=1 -DLWS_WITH_MINIMAL_EXAMPLES=1", + "platforms": "windows-10/x86_64-amd/msvc" + } + } +} + diff -Nru libwebsockets-3.2.1/scripts/attack.sh libwebsockets-4.1.6/scripts/attack.sh --- libwebsockets-3.2.1/scripts/attack.sh 2019-12-18 14:45:31.000000000 +0000 +++ libwebsockets-4.1.6/scripts/attack.sh 2020-12-01 17:40:26.000000000 +0000 @@ -781,7 +781,11 @@ if [ "`md5sum /tmp/results | cut -d' ' -f 1`" != "`md5sum /tmp/lwsresult1 | cut -d' ' -f1`" ] ; then echo "Differences..." diff -urN /tmp/lwsresult1 /tmp/results - exit 1 + cat /tmp/lwscap1 + ls -l /tmp/results + cat /tmp/results +# this is currently broken on travis +# exit 1 else echo "OK" fi diff -Nru libwebsockets-3.2.1/scripts/autobahn-test-server.sh libwebsockets-4.1.6/scripts/autobahn-test-server.sh --- libwebsockets-3.2.1/scripts/autobahn-test-server.sh 2019-12-18 14:45:31.000000000 +0000 +++ libwebsockets-4.1.6/scripts/autobahn-test-server.sh 2020-12-01 17:40:26.000000000 +0000 @@ -40,7 +40,7 @@ "url": "ws://127.0.0.1:9001" } ], - "cases": [ "12.2.13" ], + "cases": [ "*" ], "exclude-cases": ["2.10", "2.11" ], "exclude-agent-cases": {} } diff -Nru libwebsockets-3.2.1/scripts/ctest-background-kill.sh libwebsockets-4.1.6/scripts/ctest-background-kill.sh --- libwebsockets-3.2.1/scripts/ctest-background-kill.sh 1970-01-01 00:00:00.000000000 +0000 +++ libwebsockets-4.1.6/scripts/ctest-background-kill.sh 2020-12-01 17:40:26.000000000 +0000 @@ -0,0 +1,54 @@ +#!/bin/bash +# +# $SAI_INSTANCE_IDX - which instance of sai, 0+ +# $1 - background fixture name, unique within test space, like "multipostlocalsrv" +# $2 - executable +# $3+ - args + +echo "$0 $1 $2 $3 $4" >> /tmp/ctklog + +J=`basename $2`.$1.$SAI_INSTANCE_IDX +PI=`cat /tmp/sai-ctest-$J` +echo "Stage 1 kill $J 'kill $PI'" >> /tmp/ctklog + +# +# We expect our background process to still be around +# + +set +e +set +E +kill -0 $PI 2>&1 >> /tmp/ctklog +GONESKI=$? + +if [ $GONESKI -eq 0 ] ; then + kill $PI 2>&1 >> /tmp/ctklog + kill -9 $PI 2>&1 >> /tmp/ctklog + + kill -0 $PI 2>&1 + if [ $? -eq 0 ] ; then + # + # but in case it isn't enough, use ps to find the same executable started on the same port + # and kill that + # + A1=$3 + if [ -z "$A1" ] ; then + A1=$2 + fi + A2=$4 + if [ -z "$A2" ] ; then + A2=$2 + fi + + # sed is there to match up bsd/osx ps with linux + KL=`ps -Af | grep -v ctest-background-kill | grep -v grep | grep $2 | grep $A1 | grep $A2 | tr -s ' ' | sed "s/^\ //g" | cut -d' ' -f2` + if [ ! -z "$KL" ] ; then + echo "Stage 2 kill $J 'kill $KL'" >> /tmp/ctklog + kill $KL 2>&1 >> /tmp/ctklog + fi + fi +else + echo "Process already dead" >> /tmp/ctklog +fi + +exit $GONESKI + diff -Nru libwebsockets-3.2.1/scripts/ctest-background.sh libwebsockets-4.1.6/scripts/ctest-background.sh --- libwebsockets-3.2.1/scripts/ctest-background.sh 1970-01-01 00:00:00.000000000 +0000 +++ libwebsockets-4.1.6/scripts/ctest-background.sh 2020-12-01 17:40:26.000000000 +0000 @@ -0,0 +1,16 @@ +#!/bin/bash +# +# $SAI_INSTANCE_IDX - which instance of sai, 0+ +# $1 - background fixture name, unique within test space, like "multipostlocalserver" +# $2 - executable +# $3+ - args + +J=`basename $2`.$1.$SAI_INSTANCE_IDX +$2 $3 $4 $5 $6 $7 $8 $9 2>/tmp/ctest-background-$J 1>/dev/null 0 /tmp/sai-ctest-$J +# really we want to loop until the listen port is up +# on, eg, rpi it can be blocked at sd card and slow to start +# due to parallel tests and disc cache flush +sleep 1 +exit 0 + diff -Nru libwebsockets-3.2.1/scripts/libwebsockets.spec libwebsockets-4.1.6/scripts/libwebsockets.spec --- libwebsockets-3.2.1/scripts/libwebsockets.spec 2019-12-18 14:45:31.000000000 +0000 +++ libwebsockets-4.1.6/scripts/libwebsockets.spec 1970-01-01 00:00:00.000000000 +0000 @@ -1,180 +0,0 @@ -Name: libwebsockets -Version: 3.2.0 -Release: 1%{?dist} -Summary: Websocket Server and Client Library - -Group: System Environment/Libraries -License: LGPLv2 with exceptions -URL: https://libwebsockets.org -Source0: %{name}-%{version}.tar.gz -BuildRoot: %(mktemp -ud %{_tmppath}/%{name}-%{version}-%{release}-XXXXXX) - -BuildRequires: openssl-devel libuv-devel libev-devel cmake -Requires: openssl - -%description -Webserver server and client library - -%package devel -Summary: Development files for libwebsockets -Group: Development/Libraries -Requires: %{name} = %{version}-%{release} -Requires: openssl-devel - -%description devel -Development files for libwebsockets - -%prep -%setup -q - -%build -mkdir -p build -cd build -%cmake .. -DLWS_WITH_DISTRO_RECOMMENDED=1 -make - -%install -rm -rf $RPM_BUILD_ROOT -cd build -make install DESTDIR=$RPM_BUILD_ROOT - -%post -p /sbin/ldconfig -%postun -p /sbin/ldconfig - -%clean -rm -rf $RPM_BUILD_ROOT - -%files -%defattr(-,root,root,-) -%attr(755,root,root) -"/usr/bin/libwebsockets-test-client" -"/usr/bin/libwebsockets-test-lejp" -"/usr/bin/libwebsockets-test-server" -"/usr/bin/libwebsockets-test-server-extpoll" -"/usr/bin/libwebsockets-test-sshd" -"/usr/bin/lwsws" -"/%{_libdir}/libwebsockets.so" -"/%{_libdir}/libwebsockets.so.15" -%dir "/usr/share/libwebsockets-test-server" -"/usr/share/libwebsockets-test-server/candide.zip" -"/usr/share/libwebsockets-test-server/favicon.ico" -%dir "/usr/share/libwebsockets-test-server/generic-table" -"/usr/share/libwebsockets-test-server/generic-table/index.html" -"/usr/share/libwebsockets-test-server/generic-table/lwsgt.js" -"/usr/share/libwebsockets-test-server/http2.png" -"/usr/share/libwebsockets-test-server/leaf.jpg" -"/usr/share/libwebsockets-test-server/libwebsockets-test-server.key.pem" -"/usr/share/libwebsockets-test-server/libwebsockets-test-server.pem" -"/usr/share/libwebsockets-test-server/libwebsockets.org-logo.svg" -"/usr/share/libwebsockets-test-server/lws-cgi-test.sh" -"/usr/share/libwebsockets-test-server/lws-common.js" -"/usr/share/libwebsockets-test-server/lws-ssh-test-keys" -"/usr/share/libwebsockets-test-server/lws-ssh-test-keys.pub" -%dir "/usr/share/libwebsockets-test-server/plugins" -"/usr/share/libwebsockets-test-server/plugins/libprotocol_client_loopback_test.so" -"/usr/share/libwebsockets-test-server/plugins/libprotocol_dumb_increment.so" -"/usr/share/libwebsockets-test-server/plugins/libprotocol_fulltext_demo.so" -"/usr/share/libwebsockets-test-server/plugins/libprotocol_lws_acme_client.so" -"/usr/share/libwebsockets-test-server/plugins/libprotocol_lws_mirror.so" -"/usr/share/libwebsockets-test-server/plugins/libprotocol_lws_raw_test.so" -"/usr/share/libwebsockets-test-server/plugins/libprotocol_lws_server_status.so" -"/usr/share/libwebsockets-test-server/plugins/libprotocol_lws_ssh_base.so" -"/usr/share/libwebsockets-test-server/plugins/libprotocol_lws_sshd_demo.so" -"/usr/share/libwebsockets-test-server/plugins/libprotocol_lws_status.so" -"/usr/share/libwebsockets-test-server/plugins/libprotocol_lws_table_dirlisting.so" -"/usr/share/libwebsockets-test-server/plugins/libprotocol_post_demo.so" -%dir "/usr/share/libwebsockets-test-server/private" -"/usr/share/libwebsockets-test-server/private/index.html" -%dir "/usr/share/libwebsockets-test-server/server-status" -"/usr/share/libwebsockets-test-server/server-status/lwsws-logo.png" -"/usr/share/libwebsockets-test-server/server-status/server-status.css" -"/usr/share/libwebsockets-test-server/server-status/server-status.html" -"/usr/share/libwebsockets-test-server/server-status/server-status.js" -"/usr/share/libwebsockets-test-server/test.css" -"/usr/share/libwebsockets-test-server/test.html" -"/usr/share/libwebsockets-test-server/test.js" -"/usr/share/libwebsockets-test-server/wss-over-h2.png" -%files devel -%defattr(-,root,root,-) -%dir "/usr/include/libwebsockets" -"/usr/include/libwebsockets.h" -"/usr/include/libwebsockets/lws-adopt.h" -"/usr/include/libwebsockets/lws-callbacks.h" -"/usr/include/libwebsockets/lws-cgi.h" -"/usr/include/libwebsockets/lws-client.h" -"/usr/include/libwebsockets/lws-context-vhost.h" -"/usr/include/libwebsockets/lws-dbus.h" -"/usr/include/libwebsockets/lws-diskcache.h" -"/usr/include/libwebsockets/lws-esp32.h" -"/usr/include/libwebsockets/lws-fts.h" -"/usr/include/libwebsockets/lws-genhash.h" -"/usr/include/libwebsockets/lws-genrsa.h" -"/usr/include/libwebsockets/lws-http.h" -"/usr/include/libwebsockets/lws-jose.h" -"/usr/include/libwebsockets/lws-jwk.h" -"/usr/include/libwebsockets/lws-jws.h" -"/usr/include/libwebsockets/lws-lejp.h" -"/usr/include/libwebsockets/lws-logs.h" -"/usr/include/libwebsockets/lws-lwsac.h" -"/usr/include/libwebsockets/lws-misc.h" -"/usr/include/libwebsockets/lws-network-helper.h" -"/usr/include/libwebsockets/lws-plugin-generic-sessions.h" -"/usr/include/libwebsockets/lws-protocols-plugins.h" -"/usr/include/libwebsockets/lws-purify.h" -"/usr/include/libwebsockets/lws-ring.h" -"/usr/include/libwebsockets/lws-service.h" -"/usr/include/libwebsockets/lws-sha1-base64.h" -"/usr/include/libwebsockets/lws-spa.h" -"/usr/include/libwebsockets/lws-stats.h" -"/usr/include/libwebsockets/lws-threadpool.h" -"/usr/include/libwebsockets/lws-timeout-timer.h" -"/usr/include/libwebsockets/lws-tokenize.h" -"/usr/include/libwebsockets/lws-vfs.h" -"/usr/include/libwebsockets/lws-write.h" -"/usr/include/libwebsockets/lws-writeable.h" -"/usr/include/libwebsockets/lws-ws-close.h" -"/usr/include/libwebsockets/lws-ws-ext.h" -"/usr/include/libwebsockets/lws-ws-state.h" -"/usr/include/libwebsockets/lws-x509.h" -"/usr/include/lws-plugin-ssh.h" -"/usr/include/lws_config.h" -%dir "/usr/lib/pkgconfig" -"/%{_libdir}/pkgconfig/libwebsockets.pc" -"/usr/lib/pkgconfig/libwebsockets_static.pc" -%dir "/usr/lib/cmake" -%dir "/usr/lib/cmake/libwebsockets" -"/%{_libdir}/cmake/libwebsockets/LibwebsocketsConfig.cmake" -"/%{_libdir}/cmake/libwebsockets/LibwebsocketsConfigVersion.cmake" -"/%{_libdir}/cmake/libwebsockets/LibwebsocketsTargets-debug.cmake" -"/%{_libdir}/cmake/libwebsockets/LibwebsocketsTargets.cmake" - -%changelog -* Fri Aug 14 2019 Andy Green 3.2.0-1 -- MAJOR SONAMEBUMP APICHANGES Upstream 3.2.0 release (last LGPLv2.1+SLE) - -* Fri Nov 23 2018 Andy Green 3.1.0-1 -- MAJOR SONAMEBUMP APICHANGES Upstream 3.1.0 release - -* Fri May 4 2018 Andy Green 3.0.0-1 -- MAJOR SONAMEBUMP APICHANGES Upstream 3.0.0 release - -* Mon Oct 16 2017 Andy Green 2.4.0-1 -- MAJOR SONAMEBUMP APICHANGES Upstream 2.4.0 release - -* Fri Jul 28 2017 Andy Green 2.3.0-1 -- MAJOR SONAMEBUMP APICHANGES Upstream 2.3.0 release - -* Mon Mar 06 2017 Andy Green 2.2.0-1 -- MAJOR SONAMEBUMP APICHANGES Upstream 2.2.0 release - -* Thu Oct 06 2016 Andy Green 2.1.0-1 -- MAJOR SONAMEBUMP APICHANGES Upstream 2.1.0 release - -* Thu May 05 2016 Andy Green 2.0.0-1 -- MAJOR SONAMEBUMP APICHANGES Upstream 2.0.0 release - -* Tue Feb 16 2016 Andy Green 1.7.0-1 -- MAJOR SONAMEBUMP APICHANGES Upstream 1.7.0 release - -* Sun Jan 17 2016 Andrew Cooks 1.6.0-1 -- Bump version to 1.6.0 diff -Nru libwebsockets-3.2.1/scripts/travis_control.sh libwebsockets-4.1.6/scripts/travis_control.sh --- libwebsockets-3.2.1/scripts/travis_control.sh 2019-12-18 14:45:31.000000000 +0000 +++ libwebsockets-4.1.6/scripts/travis_control.sh 2020-12-01 17:40:26.000000000 +0000 @@ -1,7 +1,7 @@ #!/bin/bash if [ "$COVERITY_SCAN_BRANCH" != 1 -a "$TRAVIS_OS_NAME" = "osx" ]; then - if [ "$LWS_METHOD" != "mbedtls" ] ; then + if [ "$LWS_METHOD" != "mbedtls" -a "$LWS_METHOD" != "ss+mbedtls" ] ; then mkdir build && cd build && cmake -DOPENSSL_ROOT_DIR="/usr/local/opt/openssl" $CMAKE_ARGS .. && cmake --build . @@ -15,10 +15,10 @@ cmake --build . && sudo make install && ../minimal-examples/selftests.sh && - ../scripts/test-dbus-proxy.sh && ../scripts/h2spec.sh && ../scripts/attack.sh && ../scripts/h2load.sh && + ../scripts/autobahn-test-server.sh && ../scripts/autobahn-test-client.sh else if [ "$LWS_METHOD" = "lwsws2" ] ; then @@ -34,7 +34,7 @@ cmake --build . && ../scripts/h2load-smp.sh else - if [ "$LWS_METHOD" = "mbedtls" ] ; then + if [ "$LWS_METHOD" = "mbedtls" -o "$LWS_METHOD" = "ss+mbedtls" ] ; then cmake $CMAKE_ARGS .. && cmake --build . && sudo make install && diff -Nru libwebsockets-3.2.1/scripts/travis_install.sh libwebsockets-4.1.6/scripts/travis_install.sh --- libwebsockets-3.2.1/scripts/travis_install.sh 2019-12-18 14:45:31.000000000 +0000 +++ libwebsockets-4.1.6/scripts/travis_install.sh 2020-12-01 17:40:26.000000000 +0000 @@ -8,7 +8,7 @@ if [ "$LWS_METHOD" == "lwsws" -o "$LWS_METHOD" == "lwsws2" ]; then - sudo apt-get install -y -qq realpath libjemalloc1 libev4 libuv-dev libdbus-1-dev + sudo apt-get install -y -qq realpath libjemalloc1 libev4 libuv-dev libdbus-1-dev valgrind mosquitto sudo apt-get remove python-six sudo pip install "six>=1.9" sudo pip install "Twisted==16.0.0" @@ -21,9 +21,9 @@ sudo update-ca-certificates fi - if [ "$LWS_METHOD" == "mbedtls" ]; + if [ "$LWS_METHOD" == "mbedtls" -o "$LWS_METHOD" == "ss+mbedtls" ]; then - sudo apt-get install -y -qq realpath libjemalloc1 libev4 libuv-dev + sudo apt-get install -y -qq realpath libjemalloc1 libev4 libuv-dev valgrind wget https://libwebsockets.org/openssl-1.1.0-trusty.tar.bz2 -O/tmp/openssl.tar.bz2 cd / sudo tar xf /tmp/openssl.tar.bz2 diff -Nru libwebsockets-3.2.1/test-apps/CMakeLists.txt libwebsockets-4.1.6/test-apps/CMakeLists.txt --- libwebsockets-3.2.1/test-apps/CMakeLists.txt 1970-01-01 00:00:00.000000000 +0000 +++ libwebsockets-4.1.6/test-apps/CMakeLists.txt 2020-12-01 17:40:26.000000000 +0000 @@ -0,0 +1,255 @@ +# +# libwebsockets - small server side websockets and web server implementation +# +# Copyright (C) 2010 - 2020 Andy Green +# +# Permission is hereby granted, free of charge, to any person obtaining a copy +# of this software and associated documentation files (the "Software"), to +# deal in the Software without restriction, including without limitation the +# rights to use, copy, modify, merge, publish, distribute, sublicense, and/or +# sell copies of the Software, and to permit persons to whom the Software is +# furnished to do so, subject to the following conditions: +# +# The above copyright notice and this permission notice shall be included in +# all copies or substantial portions of the Software. +# +# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING +# FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS +# IN THE SOFTWARE. +# + +# +# Test applications +# + +set(TEST_APP_LIST) +if ((LWS_ROLE_H1 OR LWS_ROLE_H2)) + # + # Helper function for adding a test app. + # + macro(create_test_app TEST_NAME MAIN_SRC S2 S3 S4 S5 S6) + + set(TEST_SRCS ${MAIN_SRC}) + set(TEST_HDR) + if ("${S2}" STREQUAL "") + else() + list(APPEND TEST_SRCS ${S2}) + endif() + if ("${S3}" STREQUAL "") + else() + list(APPEND TEST_SRCS ${S3}) + endif() + if ("${S4}" STREQUAL "") + else() + list(APPEND TEST_SRCS ${S4}) + endif() + if ("${S5}" STREQUAL "") + else() + list(APPEND TEST_SRCS ${S5}) + endif() + if ("${S6}" STREQUAL "") + else() + list(APPEND TEST_SRCS ${S6}) + endif() + if (WIN32) + list(APPEND TEST_SRCS + ${WIN32_HELPERS_PATH}/getopt.c + ${WIN32_HELPERS_PATH}/getopt_long.c + ${WIN32_HELPERS_PATH}/gettimeofday.c + ) + + list(APPEND TEST_HDR + ${WIN32_HELPERS_PATH}/getopt.h + ${WIN32_HELPERS_PATH}/gettimeofday.h + ) + endif(WIN32) + + source_group("Headers Private" FILES ${TEST_HDR}) + source_group("Sources" FILES ${TEST_SRCS}) + add_executable(${TEST_NAME} ${TEST_SRCS} ${TEST_HDR}) + + foreach(libpath ${LWS_DEP_LIB_PATHS}) + target_link_directories(${TEST_NAME} ${libpath}) + endforeach() + + if (LWS_LINK_TESTAPPS_DYNAMIC) + if (NOT LWS_WITH_SHARED) + message(FATAL_ERROR "Build of the shared library is disabled. LWS_LINK_TESTAPPS_DYNAMIC must be combined with LWS_WITH_SHARED.") + endif() + target_link_libraries(${TEST_NAME} websockets_shared) + add_dependencies(${TEST_NAME} websockets_shared) + else() + if (NOT LWS_WITH_STATIC) + message(FATAL_ERROR "Build of the static library is disabled. Disabled LWS_LINK_TESTAPPS_DYNAMIC must be combined with LWS_WITH_STATIC.") + endif() + target_link_libraries(${TEST_NAME} websockets) + add_dependencies(${TEST_NAME} websockets) + if (UNIX AND LWS_WITH_SSL AND NOT LWS_WITH_MBEDTLS) + target_link_libraries(${TEST_NAME} dl) + endif() + endif() + + if (LWS_LIB_INCLUDES) + target_include_directories(${TEST_NAME} PRIVATE "${LWS_LIB_INCLUDES}" ${LWS_LIB_BUILD_INC_PATHS}) + else() + target_include_directories(${TEST_NAME} PRIVATE ${LWS_LIB_BUILD_INC_PATHS}) + endif() + target_compile_options(${TEST_NAME} PRIVATE ${LWS_PTHR_FLAGS}) + + if (LWS_WITH_HTTP_STREAM_COMPRESSION) + target_link_libraries(${TEST_NAME} z) + endif() + + # Set test app specific defines. + set_property(TARGET ${TEST_NAME} + PROPERTY COMPILE_DEFINITIONS + INSTALL_DATADIR="${CMAKE_INSTALL_PREFIX}/share" + ) + + # Prefix the binary names with libwebsockets. + set_target_properties(${TEST_NAME} + PROPERTIES + OUTPUT_NAME libwebsockets-${TEST_NAME}) + + target_link_libraries(${TEST_NAME} ${LIB_LIST_AT_END}) + + # Add to the list of tests. + list(APPEND TEST_APP_LIST ${TEST_NAME}) + endmacro() + + if (NOT LWS_WITHOUT_SERVER) + # + # test-server + # + if (NOT LWS_WITHOUT_TEST_SERVER) + create_test_app(test-server "test-server.c" + "" + "" + "" + "" + "") + + if (LWS_WITH_CGI AND LWS_WITH_TLS) + create_test_app(test-sshd "test-sshd.c" + "" + "" + "" + "" + "") + target_include_directories(test-sshd PRIVATE "${PROJECT_SOURCE_DIR}/plugins/ssh-base/include") + + endif() + + endif() + + # + # test-server-extpoll + # + if (NOT LWS_WITHOUT_TEST_SERVER_EXTPOLL AND NOT WIN32) + create_test_app(test-server-extpoll + "test-server.c" + "" + "" + "" + "" + "") + # Set defines for this executable only. + set_property( + TARGET test-server-extpoll + PROPERTY COMPILE_DEFINITIONS + EXTERNAL_POLL + INSTALL_DATADIR="${CMAKE_INSTALL_PREFIX}/share" + ) + + # We need to link against winsock code. + if (WIN32) + target_link_libraries(test-server-extpoll ws2_32.lib) + endif(WIN32) + endif() + + if (LWS_WITH_LEJP) + create_test_app( + test-lejp + "test-lejp.c" + "" + "" + "" + "" + "") + endif() + + # Data files for running the test server. + list(APPEND TEST_SERVER_DATA + "${PROJECT_SOURCE_DIR}/test-apps/favicon.ico" + "${PROJECT_SOURCE_DIR}/test-apps/leaf.jpg" + "${PROJECT_SOURCE_DIR}/test-apps/candide.zip" + "${PROJECT_SOURCE_DIR}/test-apps/libwebsockets.org-logo.svg" + "${PROJECT_SOURCE_DIR}/test-apps/http2.png" + "${PROJECT_SOURCE_DIR}/test-apps/wss-over-h2.png" + "${PROJECT_SOURCE_DIR}/test-apps/lws-common.js" + "${PROJECT_SOURCE_DIR}/test-apps/test.html" + "${PROJECT_SOURCE_DIR}/test-apps/test.css" + "${PROJECT_SOURCE_DIR}/test-apps/test.js") + + add_custom_command(TARGET test-server + POST_BUILD + COMMAND "${CMAKE_COMMAND}" -E make_directory "$/../share/libwebsockets-test-server") + + # Copy the file needed to run the server so that the test apps can + # reach them from their default output location + foreach (TEST_FILE ${TEST_SERVER_DATA}) + if (EXISTS ${TEST_FILE}) + add_custom_command(TARGET test-server + POST_BUILD + COMMAND "${CMAKE_COMMAND}" -E copy "${TEST_FILE}" "$/../share/libwebsockets-test-server" VERBATIM) + endif() + endforeach() + endif(NOT LWS_WITHOUT_SERVER) + + if (NOT LWS_WITHOUT_CLIENT) + # + # test-client + # + if (NOT LWS_WITHOUT_TEST_CLIENT) + create_test_app(test-client "test-client.c" "" "" "" "" "") + endif() + + endif(NOT LWS_WITHOUT_CLIENT) +endif((LWS_ROLE_H1 OR LWS_ROLE_H2)) + +# Install test apps. + +install(TARGETS ${TEST_APP_LIST} + RUNTIME DESTINATION ${LWS_INSTALL_EXAMPLES_DIR} + COMPONENT examples) +set(CPACK_COMPONENT_EXAMPLES_DISPLAY_NAME "Example files") + +# Programs shared files used by the test-server + +if (NOT LWS_WITHOUT_SERVER) + install(FILES ${TEST_SERVER_DATA} + DESTINATION share/libwebsockets-test-server + COMPONENT examples) + + install(FILES "${PROJECT_SOURCE_DIR}/test-apps/private/index.html" + DESTINATION share/libwebsockets-test-server/private + COMPONENT examples) +if (LWS_WITH_CGI) + set(CGI_TEST_SCRIPT "${PROJECT_SOURCE_DIR}/test-apps/lws-cgi-test.sh") + install(FILES ${CGI_TEST_SCRIPT} + PERMISSIONS OWNER_EXECUTE GROUP_EXECUTE WORLD_EXECUTE OWNER_READ GROUP_READ WORLD_READ + DESTINATION share/libwebsockets-test-server + COMPONENT examples) + endif() +endif() + + +if (NOT LWS_WITHOUT_TEST_SERVER AND NOT LWS_WITHOUT_SERVER) + install(FILES lws-ssh-test-keys;lws-ssh-test-keys.pub + DESTINATION share/libwebsockets-test-server + COMPONENT examples) +endif() diff -Nru libwebsockets-3.2.1/test-apps/libwebsockets.org-logo.svg libwebsockets-4.1.6/test-apps/libwebsockets.org-logo.svg --- libwebsockets-3.2.1/test-apps/libwebsockets.org-logo.svg 2019-12-18 14:45:31.000000000 +0000 +++ libwebsockets-4.1.6/test-apps/libwebsockets.org-logo.svg 2020-12-01 17:40:26.000000000 +0000 @@ -1,120 +1,66 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + + +image/svg+xml + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff -Nru libwebsockets-3.2.1/test-apps/lws-common.js libwebsockets-4.1.6/test-apps/lws-common.js --- libwebsockets-3.2.1/test-apps/lws-common.js 2019-12-18 14:45:31.000000000 +0000 +++ libwebsockets-4.1.6/test-apps/lws-common.js 2020-12-01 17:40:26.000000000 +0000 @@ -113,9 +113,6 @@ function new_ws(urlpath, protocol) { - if (typeof MozWebSocket != "undefined") - return new MozWebSocket(urlpath, protocol); - return new WebSocket(urlpath, protocol); } diff -Nru libwebsockets-3.2.1/test-apps/test-client.c libwebsockets-4.1.6/test-apps/test-client.c --- libwebsockets-3.2.1/test-apps/test-client.c 2019-12-18 14:45:31.000000000 +0000 +++ libwebsockets-4.1.6/test-apps/test-client.c 2020-12-01 17:40:26.000000000 +0000 @@ -510,6 +510,7 @@ { NULL, NULL, 0, 0 } /* end */ }; +#if defined(LWS_ROLE_WS) && !defined(LWS_WITHOUT_EXTENSIONS) static const struct lws_extension exts[] = { { "permessage-deflate", @@ -523,7 +524,7 @@ }, { NULL, NULL, NULL /* terminator */ } }; - +#endif void sighandler(int sig) @@ -547,7 +548,6 @@ { "longlived", no_argument, NULL, 'l' }, { "post", no_argument, NULL, 'o' }, { "once", no_argument, NULL, 'O' }, - { "pingpong-secs", required_argument, NULL, 'P' }, { "ssl-cert", required_argument, NULL, 'C' }, { "ssl-key", required_argument, NULL, 'K' }, { "ssl-ca", required_argument, NULL, 'A' }, @@ -575,8 +575,7 @@ int main(int argc, char **argv) { int n = 0, m, ret = 0, port = 7681, use_ssl = 0, ietf_version = -1; - unsigned int rl_dumb = 0, rl_mirror = 0, do_ws = 1, pp_secs = 0, - do_multi = 0; + unsigned int rl_dumb = 0, rl_mirror = 0, do_ws = 1, do_multi = 0; struct lws_context_creation_info info; struct lws_client_connect_info i; struct lws_context *context; @@ -589,7 +588,7 @@ memset(&info, 0, sizeof info); - lwsl_notice("libwebsockets test client - license LGPL2.1+SLE\n"); + lwsl_notice("libwebsockets test client - license MIT\n"); lwsl_notice("(C) Copyright 2010-2018 Andy Green \n"); if (argc < 2) @@ -597,9 +596,9 @@ while (n >= 0) { #if defined(LWS_HAS_GETOPT_LONG) || defined(WIN32) - n = getopt_long(argc, argv, "Sjnuv:hsp:d:lC:K:A:P:moeO", options, NULL); + n = getopt_long(argc, argv, "Sjnuv:hsp:d:lC:K:A:moeO", options, NULL); #else - n = getopt(argc, argv, "Sjnuv:hsp:d:lC:K:A:P:moeO"); + n = getopt(argc, argv, "Sjnuv:hsp:d:lC:K:A:moeO"); #endif if (n < 0) continue; @@ -621,10 +620,6 @@ case 'e': flag_echo = 1; break; - case 'P': - pp_secs = atoi(optarg); - lwsl_notice("Setting pingpong interval to %d\n", pp_secs); - break; case 'j': justmirror = 1; break; @@ -709,8 +704,9 @@ info.protocols = protocols; info.gid = -1; info.uid = -1; - info.ws_ping_pong_interval = pp_secs; +#if defined(LWS_ROLE_WS) && !defined(LWS_WITHOUT_EXTENSIONS) info.extensions = exts; +#endif /* * since we know this lws context is only ever going to be used with @@ -725,7 +721,7 @@ #endif info.options |= LWS_SERVER_OPTION_H2_JUST_FIX_WINDOW_UPDATE_OVERFLOW; - +#if defined(LWS_WITH_TLS) if (use_ssl) { /* * If the server wants us to present a valid SSL client certificate @@ -766,7 +762,7 @@ lwsl_notice(" Skipping peer cert hostname check\n"); else lwsl_notice(" Requiring peer cert hostname matches\n"); - +#endif context = lws_create_context(&info); if (context == NULL) { fprintf(stderr, "Creating libwebsocket context failed\n"); diff -Nru libwebsockets-3.2.1/test-apps/test-lejp.c libwebsockets-4.1.6/test-apps/test-lejp.c --- libwebsockets-3.2.1/test-apps/test-lejp.c 2019-12-18 14:45:31.000000000 +0000 +++ libwebsockets-4.1.6/test-apps/test-lejp.c 2020-12-01 17:40:26.000000000 +0000 @@ -1,22 +1,14 @@ /* - * Lightweight Embedded JSON Parser + * lejp test app * - * Copyright (C) 2013-2017 Andy Green + * Written in 2010-2019 by Andy Green * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation: - * version 2.1 of the License. + * This file is made available under the Creative Commons CC0 1.0 + * Universal Public Domain Dedication. * - * This library is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with this library; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, - * MA 02110-1301 USA + * This demonstrates a minimal http server that performs a form GET with a couple + * of parameters. It dumps the parameters to the console log and redirects + * to another page. */ #include @@ -96,7 +88,7 @@ int main(int argc, char *argv[]) { - int fd, n = 1, ret = 1, m; + int fd, n = 1, ret = 1, m = 0; struct lejp_ctx ctx; char buf[128]; @@ -120,7 +112,7 @@ goto bail; } } - lwsl_notice("okay\n"); + lwsl_notice("okay (%d)\n", m); ret = 0; bail: lejp_destruct(&ctx); diff -Nru libwebsockets-3.2.1/test-apps/test-server.c libwebsockets-4.1.6/test-apps/test-server.c --- libwebsockets-3.2.1/test-apps/test-server.c 2019-12-18 14:45:31.000000000 +0000 +++ libwebsockets-4.1.6/test-apps/test-server.c 2020-12-01 17:40:26.000000000 +0000 @@ -55,26 +55,7 @@ /* * This demonstrates how to use the clean protocol service separation of - * plugins, but with static inclusion instead of runtime dynamic loading - * (which requires libuv). - * - * dumb-increment doesn't use the plugin, both to demonstrate how to - * do the protocols directly, and because it wants libuv for a timer. - * - * Please consider using test-server-v2.0.c instead of this: it has the - * same functionality but - * - * 1) uses lws built-in http handling so you don't need to deal with it in - * your callback - * - * 2) Links with libuv and uses the plugins at runtime - * - * 3) Uses advanced lws features like mounts to bind parts of the filesystem - * to the served URL space - * - * Another option is lwsws, this operates like test-server-v2,0.c but is - * configured using JSON, do you do not need to provide any code for the - * serving action at all, just implement your protocols in plugins. + * plugins, in this case by statically including them at build-time. */ #define LWS_PLUGIN_STATIC @@ -82,7 +63,21 @@ #include "../plugins/protocol_lws_mirror.c" #include "../plugins/protocol_lws_status.c" #include "../plugins/protocol_dumb_increment.c" +#endif #include "../plugins/protocol_post_demo.c" + +#if defined(LWS_WITH_EXTERNAL_POLL) +static struct lws_pollfd * +ext_find_fd(lws_sockfd_type fd) +{ + int n; + + for (n = 0; n < max_poll_elements; n++) + if (pollfds[n].fd == fd) + return &pollfds[n]; + + return NULL; +} #endif static int @@ -90,10 +85,52 @@ void *in, size_t len) { const unsigned char *c; +#if defined(LWS_WITH_EXTERNAL_POLL) + struct lws_pollargs *pa; + struct lws_pollfd *pfd; +#endif char buf[1024]; int n = 0, hlen; switch (reason) { +#if defined(LWS_WITH_EXTERNAL_POLL) + case LWS_CALLBACK_ADD_POLL_FD: + pa = (struct lws_pollargs *)in; + lwsl_debug("%s: ADD fd %d, ev %d\n", __func__, pa->fd, pa->events); + pfd = ext_find_fd(pa->fd); + if (pfd) { + lwsl_notice("%s: ADD fd %d already in ext table\n", + __func__, pa->fd); + } else { + pfd = ext_find_fd(LWS_SOCK_INVALID); + if (!pfd) + return -1; + } + pfd->fd = pa->fd; + pfd->events = pa->events; + pfd->revents = 0; + /* high water mark... */ + count_pollfds = (pfd - pollfds) + 1; + break; + case LWS_CALLBACK_DEL_POLL_FD: + pa = (struct lws_pollargs *)in; + lwsl_debug("%s: DEL fd %d\n", __func__, pa->fd); + pfd = ext_find_fd(pa->fd); + if (!pfd) + return -1; + pfd->fd = LWS_SOCK_INVALID; + break; + case LWS_CALLBACK_CHANGE_MODE_POLL_FD: + pa = (struct lws_pollargs *)in; + lwsl_debug("%s: CH fd %d\n", __func__, pa->fd); + pfd = ext_find_fd(pa->fd); + if (!pfd) { + lwsl_err("%s: unknown fd %d\n", __func__, pa->fd); + return -1; + } + pfd->events = pa->events; + break; +#endif case LWS_CALLBACK_HTTP: /* non-mount-handled accesses will turn up here */ @@ -155,8 +192,8 @@ LWS_PLUGIN_PROTOCOL_DUMB_INCREMENT, LWS_PLUGIN_PROTOCOL_MIRROR, LWS_PLUGIN_PROTOCOL_LWS_STATUS, - LWS_PLUGIN_PROTOCOL_POST_DEMO, #endif + LWS_PLUGIN_PROTOCOL_POST_DEMO, { NULL, NULL, 0, 0 } /* terminator */ }; @@ -206,6 +243,7 @@ lws_cancel_service(context); } +#if defined(LWS_ROLE_WS) && !defined(LWS_WITHOUT_EXTENSIONS) static const struct lws_extension exts[] = { { "permessage-deflate", @@ -214,15 +252,18 @@ }, { NULL, NULL, NULL /* terminator */ } }; +#endif /* - * mount handlers for sections of the URL space + * 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_ziptest = { +static const struct lws_http_mount mount_ziptest_uncomm = { NULL, /* linked-list pointer to next*/ - "/ziptest", /* mountpoint in URL namespace on this vhost */ - LOCAL_RESOURCE_PATH"/candide.zip", /* handler */ + "/uncommziptest", /* mountpoint in URL namespace on this vhost */ + LOCAL_RESOURCE_PATH"/candide-uncompressed.zip", /* handler */ NULL, /* default filename if none given */ NULL, NULL, @@ -235,16 +276,14 @@ 0, 0, LWSMPRO_FILE, /* origin points to a callback */ - 8, /* strlen("/ziptest"), ie length of the mountpoint */ + 14, /* 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 */ +}, mount_ziptest = { + (struct lws_http_mount *)&mount_ziptest_uncomm, /* 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, @@ -256,24 +295,16 @@ 0, 0, 0, - LWSMPRO_CALLBACK, /* origin points to a callback */ - 9, /* strlen("/formtest"), ie length of the mountpoint */ + LWSMPRO_FILE, /* origin points to a callback */ + 8, /* strlen("/ziptest"), 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 */ +}, 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, @@ -284,13 +315,32 @@ 0, 0, 0, - LWSMPRO_FILE, /* mount type is a directory in a filesystem */ - 1, /* strlen("/"), ie length of the mountpoint */ + LWSMPRO_CALLBACK, /* origin points to a callback */ + 9, /* strlen("/formtest"), ie length of the mountpoint */ NULL, { NULL, NULL } // sentinel +}, mount = { + /* .mount_next */ &mount_post, /* linked-list "next" */ + /* .mountpoint */ "/", /* mountpoint URL */ + /* .origin */ LOCAL_RESOURCE_PATH, /* serve from dir */ + /* .def */ "test.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, }; + static const struct lws_protocol_vhost_options pvo_options = { NULL, NULL, @@ -317,6 +367,7 @@ { "ssl-cert", required_argument, NULL, 'C' }, { "ssl-key", required_argument, NULL, 'K' }, { "ssl-ca", required_argument, NULL, 'A' }, + { "resource-path", required_argument, NULL, 'r' }, #if defined(LWS_WITH_TLS) { "ssl-verify-client", no_argument, NULL, 'v' }, #if defined(LWS_HAVE_SSL_CTX_set1_param) @@ -328,11 +379,17 @@ #ifndef LWS_NO_DAEMONIZE { "daemonize", no_argument, NULL, 'D' }, #endif - { "pingpong-secs", required_argument, NULL, 'P' }, + { "ignore-sigterm", no_argument, NULL, 'I' }, + { NULL, 0, 0, 0 } }; #endif +static void +sigterm_catch(int sig) +{ +} + int main(int argc, char **argv) { struct lws_context_creation_info info; @@ -344,7 +401,6 @@ char ca_path[1024] = ""; int uid = -1, gid = -1; int use_ssl = 0; - int pp_secs = 0; int opts = 0; int n = 0; #ifndef LWS_NO_DAEMONIZE @@ -360,9 +416,9 @@ while (n >= 0) { #if defined(LWS_HAS_GETOPT_LONG) || defined(WIN32) - n = getopt_long(argc, argv, "eci:hsap:d:DC:K:A:R:vu:g:P:kU:n", options, NULL); + n = getopt_long(argc, argv, "eci:hsap:d:DC:K:A:R:vu:g:kU:niIr:", options, NULL); #else - n = getopt(argc, argv, "eci:hsap:d:DC:K:A:R:vu:g:P:kU:n"); + n = getopt(argc, argv, "eci:hsap:d:DC:K:A:R:vu:g:kU:nIr:"); #endif if (n < 0) continue; @@ -388,6 +444,12 @@ /* no dumb increment send */ test_options |= 1; break; + case 'I': + signal(SIGTERM, sigterm_catch); + break; + case 'r': + resource_path = optarg; + break; case 's': use_ssl = 1; opts |= LWS_SERVER_OPTION_DO_SSL_GLOBAL_INIT; @@ -429,10 +491,6 @@ case 'A': lws_strncpy(ca_path, optarg, sizeof(ca_path)); break; - case 'P': - pp_secs = atoi(optarg); - lwsl_notice("Setting pingpong interval to %d\n", pp_secs); - break; #if defined(LWS_WITH_TLS) case 'v': use_ssl = 1; @@ -475,7 +533,7 @@ /* 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 - license LGPL2.1+SLE\n"); + lwsl_notice("libwebsockets test server - license MIT\n"); lwsl_notice("(C) Copyright 2010-2018 Andy Green \n"); printf("Using resource path \"%s\"\n", resource_path); @@ -491,13 +549,17 @@ lwsl_err("Out of memory pollfds=%d\n", max_poll_elements); return -1; } + for (n = 0; n < max_poll_elements; n++) + pollfds[n].fd = LWS_SOCK_INVALID; + count_pollfds = 0; #endif info.iface = iface; info.protocols = protocols; + +#if defined(LWS_WITH_TLS) info.ssl_cert_filepath = NULL; info.ssl_private_key_filepath = NULL; - info.ws_ping_pong_interval = pp_secs; if (use_ssl) { if (strlen(resource_path) > sizeof(cert_path) - 32) { @@ -514,17 +576,22 @@ if (!key_path[0]) sprintf(key_path, "%s/libwebsockets-test-server.key.pem", resource_path); - +#if defined(LWS_WITH_TLS) info.ssl_cert_filepath = cert_path; info.ssl_private_key_filepath = key_path; if (ca_path[0]) info.ssl_ca_filepath = ca_path; +#endif } +#endif info.gid = gid; info.uid = uid; info.options = opts | LWS_SERVER_OPTION_VALIDATE_UTF8 | LWS_SERVER_OPTION_EXPLICIT_VHOSTS; +#if defined(LWS_ROLE_WS) && !defined(LWS_WITHOUT_EXTENSIONS) info.extensions = exts; +#endif info.timeout_secs = 5; +#if defined(LWS_WITH_TLS) info.ssl_cipher_list = "ECDHE-ECDSA-AES256-GCM-SHA384:" "ECDHE-RSA-AES256-GCM-SHA384:" "DHE-RSA-AES256-GCM-SHA384:" @@ -538,9 +605,12 @@ "!DHE-RSA-AES256-SHA256:" "!AES256-GCM-SHA384:" "!AES256-SHA256"; +#endif info.mounts = &mount; - info.ip_limit_ah = 24; /* for testing */ - info.ip_limit_wsi = 400; /* for testing */ +#if defined(LWS_WITH_PEER_LIMITS) + info.ip_limit_ah = 128; /* for testing */ + info.ip_limit_wsi = 800; /* for testing */ +#endif if (use_ssl) /* redirect guys coming on http */ @@ -568,7 +638,7 @@ info.port++; -#if !defined(LWS_NO_CLIENT) && defined(LWS_WITH_TLS) +#if defined(LWS_WITH_CLIENT) && defined(LWS_WITH_TLS) lws_init_vhost_client_ssl(&info, vhost); #endif @@ -598,7 +668,11 @@ * this represents an existing server's single poll action * which also includes libwebsocket sockets */ - n = poll(pollfds, count_pollfds, 50); + + /* if needed, force-service wsis that may not have read all input */ + n = lws_service_adjust_timeout(context, 5000, 0); + + n = poll(pollfds, count_pollfds, n); if (n < 0) continue; @@ -611,15 +685,11 @@ * control */ if (lws_service_fd(context, - &pollfds[n]) < 0) + &pollfds[n]) < 0) goto done; - - /* if needed, force-service wsis that may not have read all input */ - while (!lws_service_adjust_timeout(context, 1, 0)) { - lwsl_notice("extpoll doing forced service!\n"); - lws_service_tsi(context, -1, 0); - } } + + lws_service_tsi(context, -1, 0); #else /* * If libwebsockets sockets are all we care about, diff -Nru libwebsockets-3.2.1/test-apps/test-sshd.c libwebsockets-4.1.6/test-apps/test-sshd.c --- libwebsockets-3.2.1/test-apps/test-sshd.c 2019-12-18 14:45:31.000000000 +0000 +++ libwebsockets-4.1.6/test-apps/test-sshd.c 2020-12-01 17:40:26.000000000 +0000 @@ -33,7 +33,7 @@ #include #include #include - +#include /* import the whole of lws-plugin-sshd-base statically */ #include diff -Nru libwebsockets-3.2.1/.travis.yml libwebsockets-4.1.6/.travis.yml --- libwebsockets-3.2.1/.travis.yml 2019-12-18 14:45:31.000000000 +0000 +++ libwebsockets-4.1.6/.travis.yml 1970-01-01 00:00:00.000000000 +0000 @@ -1,48 +0,0 @@ -env: - # The next declaration is the encrypted COVERITY_SCAN_TOKEN, created - # via the "travis encrypt" command using the project repo's public key - global: - - secure: "KhAdQ9ja+LBObWNQTYO7Df5J4DyOih6S+eerDMu8UPSO+CoWV2pWoQzbOfocjyOscGOwC+2PrrHDNZyGfqkCLDXg1BxynXPCFerHC1yc2IajvKpGXmAAygNIvp4KACDfGv/dkXrViqIzr/CdcNaU4vIMHSVb5xkeLi0W1dPnQOI=" - matrix: - - LWS_METHOD=lwsws CMAKE_ARGS="-DLWS_WITH_LWSWS=ON -DLWS_WITHOUT_EXTENSIONS=0 -DLWS_WITH_HTTP2=1 -DLWS_WITH_ACME=1 -DLWS_WITH_MINIMAL_EXAMPLES=1 -DCMAKE_BUILD_TYPE=DEBUG -DLWS_ROLE_DBUS=1 -DLWS_DBUS_INCLUDE2=/usr/lib/x86_64-linux-gnu/dbus-1.0/include/ -DLWS_WITH_GENCRYPTO=1 -DLWS_WITH_JOSE=1" - - LWS_METHOD=lwsws2 CMAKE_ARGS="-DLWS_WITH_LWSWS=ON -DLWS_WITHOUT_EXTENSIONS=0 -DLWS_WITH_HTTP2=1 -DLWS_WITH_ACME=1 -DLWS_WITH_MINIMAL_EXAMPLES=1 -DCMAKE_BUILD_TYPE=DEBUG -DLWS_ROLE_DBUS=1 -DLWS_DBUS_INCLUDE2=/usr/lib/x86_64-linux-gnu/dbus-1.0/include/ -DLWS_WITH_LWS_DSH=1" - - LWS_METHOD=default CMAKE_ARGS="-DLWS_WITH_MINIMAL_EXAMPLES=1" - - LWS_METHOD=mbedtls CMAKE_ARGS="-DLWS_WITH_MBEDTLS=1 -DLWS_WITH_HTTP2=1 -DLWS_WITH_LWSWS=1 -DLWS_WITH_MINIMAL_EXAMPLES=1 -DLWS_WITH_JOSE=1 -DCMAKE_BUILD_TYPE=DEBUG" - - LWS_METHOD=noserver CMAKE_ARGS="-DLWS_WITHOUT_SERVER=ON -DLWS_WITH_MINIMAL_EXAMPLES=1" - - LWS_METHOD=noclient CMAKE_ARGS="-DLWS_WITHOUT_CLIENT=ON -DLWS_WITH_MINIMAL_EXAMPLES=1" - - LWS_METHOD=noext CMAKE_ARGS="-DLWS_WITHOUT_EXTENSIONS=ON -DLWS_WITH_MINIMAL_EXAMPLES=1" - - LWS_METHOD=nonetwork CMAKE_ARGS="-DLWS_WITH_NETWORK=0" - - LWS_METHOD=libev CMAKE_ARGS="-DLWS_WITH_LIBEV=ON" - - LWS_METHOD=noipv6 CMAKE_ARGS="-DLWS_IPV6=OFF" - - LWS_METHOD=nossl CMAKE_ARGS="-DLWS_WITH_SSL=OFF" - - LWS_METHOD=nodaemon CMAKE_ARGS="-DLWS_WITHOUT_DAEMONIZE=ON" - - LWS_METHOD=cgi CMAKE_ARGS="-DLWS_WITH_CGI=ON" - - LWS_METHOD=nologs CMAKE_ARGS="-DLWS_WITH_NO_LOGS=ON" - - LWS_METHOD=smp CMAKE_ARGS="-DLWS_MAX_SMP=32 -DLWS_WITH_MINIMAL_EXAMPLES=1" - - LWS_METHOD=nows CMAKE_ARGS="-DLWS_ROLE_WS=0" - - LWS_METHOD=threadpool CMAKE_ARGS="-DLWS_WITH_THREADPOOL=1 -DLWS_WITH_MINIMAL_EXAMPLES=1" - -os: - - linux - - osx -language: generic -install: - - ./scripts/travis_install.sh -# - ./travis-tool.sh github_package jimhester/covr - -#after_success: -# - Rscript -e 'covr::coveralls()' - -script: - - ./scripts/travis_control.sh -sudo: required -dist: trusty -addons: - coverity_scan: - project: - name: "warmcat/libwebsockets" - notification_email: andy@warmcat.com - build_command_prepend: "mkdir build && cd build && cmake .." - build_command: "cmake --build ." - branch_pattern: coverity_scan - diff -Nru libwebsockets-3.2.1/win32port/dirent/dirent-win32.h libwebsockets-4.1.6/win32port/dirent/dirent-win32.h --- libwebsockets-3.2.1/win32port/dirent/dirent-win32.h 1970-01-01 00:00:00.000000000 +0000 +++ libwebsockets-4.1.6/win32port/dirent/dirent-win32.h 2020-12-01 17:40:26.000000000 +0000 @@ -0,0 +1,1160 @@ +/* + * Dirent interface for Microsoft Visual Studio + * + * Copyright (C) 1998-2019 Toni Ronkko + * This file is part of dirent. Dirent may be freely distributed + * under the MIT license. For all details and documentation, see + * https://github.com/tronkko/dirent + */ +#ifndef DIRENT_H +#define DIRENT_H + +/* Hide warnings about unreferenced local functions */ +#if defined(__clang__) +# pragma clang diagnostic ignored "-Wunused-function" +#elif defined(_MSC_VER) +# pragma warning(disable:4505) +#elif defined(__GNUC__) +# pragma GCC diagnostic ignored "-Wunused-function" +#endif + +/* + * Include windows.h without Windows Sockets 1.1 to prevent conflicts with + * Windows Sockets 2.0. + */ +#ifndef WIN32_LEAN_AND_MEAN +# define WIN32_LEAN_AND_MEAN +#endif +#include + +#include +#include +#include +#include +#include +#include +#include +#include +#include + +/* Indicates that d_type field is available in dirent structure */ +#define _DIRENT_HAVE_D_TYPE + +/* Indicates that d_namlen field is available in dirent structure */ +#define _DIRENT_HAVE_D_NAMLEN + +/* Entries missing from MSVC 6.0 */ +#if !defined(FILE_ATTRIBUTE_DEVICE) +# define FILE_ATTRIBUTE_DEVICE 0x40 +#endif + +/* File type and permission flags for stat(), general mask */ +#if !defined(S_IFMT) +# define S_IFMT _S_IFMT +#endif + +/* Directory bit */ +#if !defined(S_IFDIR) +# define S_IFDIR _S_IFDIR +#endif + +/* Character device bit */ +#if !defined(S_IFCHR) +# define S_IFCHR _S_IFCHR +#endif + +/* Pipe bit */ +#if !defined(S_IFFIFO) +# define S_IFFIFO _S_IFFIFO +#endif + +/* Regular file bit */ +#if !defined(S_IFREG) +# define S_IFREG _S_IFREG +#endif + +/* Read permission */ +#if !defined(S_IREAD) +# define S_IREAD _S_IREAD +#endif + +/* Write permission */ +#if !defined(S_IWRITE) +# define S_IWRITE _S_IWRITE +#endif + +/* Execute permission */ +#if !defined(S_IEXEC) +# define S_IEXEC _S_IEXEC +#endif + +/* Pipe */ +#if !defined(S_IFIFO) +# define S_IFIFO _S_IFIFO +#endif + +/* Block device */ +#if !defined(S_IFBLK) +# define S_IFBLK 0 +#endif + +/* Link */ +#if !defined(S_IFLNK) +# define S_IFLNK 0 +#endif + +/* Socket */ +#if !defined(S_IFSOCK) +# define S_IFSOCK 0 +#endif + +/* Read user permission */ +#if !defined(S_IRUSR) +# define S_IRUSR S_IREAD +#endif + +/* Write user permission */ +#if !defined(S_IWUSR) +# define S_IWUSR S_IWRITE +#endif + +/* Execute user permission */ +#if !defined(S_IXUSR) +# define S_IXUSR 0 +#endif + +/* Read group permission */ +#if !defined(S_IRGRP) +# define S_IRGRP 0 +#endif + +/* Write group permission */ +#if !defined(S_IWGRP) +# define S_IWGRP 0 +#endif + +/* Execute group permission */ +#if !defined(S_IXGRP) +# define S_IXGRP 0 +#endif + +/* Read others permission */ +#if !defined(S_IROTH) +# define S_IROTH 0 +#endif + +/* Write others permission */ +#if !defined(S_IWOTH) +# define S_IWOTH 0 +#endif + +/* Execute others permission */ +#if !defined(S_IXOTH) +# define S_IXOTH 0 +#endif + +/* Maximum length of file name */ +#if !defined(PATH_MAX) +# define PATH_MAX MAX_PATH +#endif +#if !defined(FILENAME_MAX) +# define FILENAME_MAX MAX_PATH +#endif +#if !defined(NAME_MAX) +# define NAME_MAX FILENAME_MAX +#endif + +/* File type flags for d_type */ +#define DT_UNKNOWN 0 +#define DT_REG S_IFREG +#define DT_DIR S_IFDIR +#define DT_FIFO S_IFIFO +#define DT_SOCK S_IFSOCK +#define DT_CHR S_IFCHR +#define DT_BLK S_IFBLK +#define DT_LNK S_IFLNK + +/* Macros for converting between st_mode and d_type */ +#define IFTODT(mode) ((mode) & S_IFMT) +#define DTTOIF(type) (type) + +/* + * File type macros. Note that block devices, sockets and links cannot be + * distinguished on Windows and the macros S_ISBLK, S_ISSOCK and S_ISLNK are + * only defined for compatibility. These macros should always return false + * on Windows. + */ +#if !defined(S_ISFIFO) +# define S_ISFIFO(mode) (((mode) & S_IFMT) == S_IFIFO) +#endif +#if !defined(S_ISDIR) +# define S_ISDIR(mode) (((mode) & S_IFMT) == S_IFDIR) +#endif +#if !defined(S_ISREG) +# define S_ISREG(mode) (((mode) & S_IFMT) == S_IFREG) +#endif +#if !defined(S_ISLNK) +# define S_ISLNK(mode) (((mode) & S_IFMT) == S_IFLNK) +#endif +#if !defined(S_ISSOCK) +# define S_ISSOCK(mode) (((mode) & S_IFMT) == S_IFSOCK) +#endif +#if !defined(S_ISCHR) +# define S_ISCHR(mode) (((mode) & S_IFMT) == S_IFCHR) +#endif +#if !defined(S_ISBLK) +# define S_ISBLK(mode) (((mode) & S_IFMT) == S_IFBLK) +#endif + +/* Return the exact length of the file name without zero terminator */ +#define _D_EXACT_NAMLEN(p) ((p)->d_namlen) + +/* Return the maximum size of a file name */ +#define _D_ALLOC_NAMLEN(p) ((PATH_MAX)+1) + + +#ifdef __cplusplus +extern "C" { +#endif + + +/* Wide-character version */ +struct _wdirent { + /* Always zero */ + long d_ino; + + /* File position within stream */ + long d_off; + + /* Structure size */ + unsigned short d_reclen; + + /* Length of name without \0 */ + size_t d_namlen; + + /* File type */ + int d_type; + + /* File name */ + wchar_t d_name[PATH_MAX+1]; +}; +typedef struct _wdirent _wdirent; + +struct _WDIR { + /* Current directory entry */ + struct _wdirent ent; + + /* Private file data */ + WIN32_FIND_DATAW data; + + /* True if data is valid */ + int cached; + + /* Win32 search handle */ + HANDLE handle; + + /* Initial directory name */ + wchar_t *patt; +}; +typedef struct _WDIR _WDIR; + +/* Multi-byte character version */ +struct dirent { + /* Always zero */ + long d_ino; + + /* File position within stream */ + long d_off; + + /* Structure size */ + unsigned short d_reclen; + + /* Length of name without \0 */ + size_t d_namlen; + + /* File type */ + int d_type; + + /* File name */ + char d_name[PATH_MAX+1]; +}; +typedef struct dirent dirent; + +struct DIR { + struct dirent ent; + struct _WDIR *wdirp; +}; +typedef struct DIR DIR; + + +/* Dirent functions */ +static DIR *opendir (const char *dirname); +static _WDIR *_wopendir (const wchar_t *dirname); + +static struct dirent *readdir (DIR *dirp); +static struct _wdirent *_wreaddir (_WDIR *dirp); + +static int readdir_r( + DIR *dirp, struct dirent *entry, struct dirent **result); +static int _wreaddir_r( + _WDIR *dirp, struct _wdirent *entry, struct _wdirent **result); + +static int closedir (DIR *dirp); +static int _wclosedir (_WDIR *dirp); + +static void rewinddir (DIR* dirp); +static void _wrewinddir (_WDIR* dirp); + +static int scandir (const char *dirname, struct dirent ***namelist, + int (*filter)(const struct dirent*), + int (*compare)(const struct dirent**, const struct dirent**)); + +static int alphasort (const struct dirent **a, const struct dirent **b); + +static int versionsort (const struct dirent **a, const struct dirent **b); + + +/* For compatibility with Symbian */ +#define wdirent _wdirent +#define WDIR _WDIR +#define wopendir _wopendir +#define wreaddir _wreaddir +#define wclosedir _wclosedir +#define wrewinddir _wrewinddir + + +/* Internal utility functions */ +static WIN32_FIND_DATAW *dirent_first (_WDIR *dirp); +static WIN32_FIND_DATAW *dirent_next (_WDIR *dirp); + +static int dirent_mbstowcs_s( + size_t *pReturnValue, + wchar_t *wcstr, + size_t sizeInWords, + const char *mbstr, + size_t count); + +static int dirent_wcstombs_s( + size_t *pReturnValue, + char *mbstr, + size_t sizeInBytes, + const wchar_t *wcstr, + size_t count); + +static void dirent_set_errno (int error); + + +/* + * Open directory stream DIRNAME for read and return a pointer to the + * internal working area that is used to retrieve individual directory + * entries. + */ +static _WDIR* +_wopendir( + const wchar_t *dirname) +{ + _WDIR *dirp; + DWORD n; + wchar_t *p; + + /* Must have directory name */ + if (dirname == NULL || dirname[0] == '\0') { + dirent_set_errno (ENOENT); + return NULL; + } + + /* Allocate new _WDIR structure */ + dirp = (_WDIR*) malloc (sizeof (struct _WDIR)); + if (!dirp) { + return NULL; + } + + /* Reset _WDIR structure */ + dirp->handle = INVALID_HANDLE_VALUE; + dirp->patt = NULL; + dirp->cached = 0; + + /* + * Compute the length of full path plus zero terminator + * + * Note that on WinRT there's no way to convert relative paths + * into absolute paths, so just assume it is an absolute path. + */ +#if WINAPI_FAMILY_PARTITION(WINAPI_PARTITION_DESKTOP) + /* Desktop */ + n = GetFullPathNameW (dirname, 0, NULL, NULL); +#else + /* WinRT */ + n = wcslen (dirname); +#endif + + /* Allocate room for absolute directory name and search pattern */ + dirp->patt = (wchar_t*) malloc (sizeof (wchar_t) * n + 16); + if (dirp->patt == NULL) { + goto exit_closedir; + } + + /* + * Convert relative directory name to an absolute one. This + * allows rewinddir() to function correctly even when current + * working directory is changed between opendir() and rewinddir(). + * + * Note that on WinRT there's no way to convert relative paths + * into absolute paths, so just assume it is an absolute path. + */ +#if WINAPI_FAMILY_PARTITION(WINAPI_PARTITION_DESKTOP) + /* Desktop */ + n = GetFullPathNameW (dirname, n, dirp->patt, NULL); + if (n <= 0) { + goto exit_closedir; + } +#else + /* WinRT */ + wcsncpy_s (dirp->patt, n+1, dirname, n); +#endif + + /* Append search pattern \* to the directory name */ + p = dirp->patt + n; + switch (p[-1]) { + case '\\': + case '/': + case ':': + /* Directory ends in path separator, e.g. c:\temp\ */ + /*NOP*/; + break; + + default: + /* Directory name doesn't end in path separator */ + *p++ = '\\'; + } + *p++ = '*'; + *p = '\0'; + + /* Open directory stream and retrieve the first entry */ + if (!dirent_first (dirp)) { + goto exit_closedir; + } + + /* Success */ + return dirp; + + /* Failure */ +exit_closedir: + _wclosedir (dirp); + return NULL; +} + +/* + * Read next directory entry. + * + * Returns pointer to static directory entry which may be overwritten by + * subsequent calls to _wreaddir(). + */ +static struct _wdirent* +_wreaddir( + _WDIR *dirp) +{ + struct _wdirent *entry; + + /* + * Read directory entry to buffer. We can safely ignore the return value + * as entry will be set to NULL in case of error. + */ + (void) _wreaddir_r (dirp, &dirp->ent, &entry); + + /* Return pointer to statically allocated directory entry */ + return entry; +} + +/* + * Read next directory entry. + * + * Returns zero on success. If end of directory stream is reached, then sets + * result to NULL and returns zero. + */ +static int +_wreaddir_r( + _WDIR *dirp, + struct _wdirent *entry, + struct _wdirent **result) +{ + WIN32_FIND_DATAW *datap; + + /* Read next directory entry */ + datap = dirent_next (dirp); + if (datap) { + size_t n; + DWORD attr; + + /* + * Copy file name as wide-character string. If the file name is too + * long to fit in to the destination buffer, then truncate file name + * to PATH_MAX characters and zero-terminate the buffer. + */ + n = 0; + while (n < PATH_MAX && datap->cFileName[n] != 0) { + entry->d_name[n] = datap->cFileName[n]; + n++; + } + entry->d_name[n] = 0; + + /* Length of file name excluding zero terminator */ + entry->d_namlen = n; + + /* File type */ + attr = datap->dwFileAttributes; + if ((attr & FILE_ATTRIBUTE_DEVICE) != 0) { + entry->d_type = DT_CHR; + } else if ((attr & FILE_ATTRIBUTE_DIRECTORY) != 0) { + entry->d_type = DT_DIR; + } else { + entry->d_type = DT_REG; + } + + /* Reset dummy fields */ + entry->d_ino = 0; + entry->d_off = 0; + entry->d_reclen = sizeof (struct _wdirent); + + /* Set result address */ + *result = entry; + + } else { + + /* Return NULL to indicate end of directory */ + *result = NULL; + + } + + return /*OK*/0; +} + +/* + * Close directory stream opened by opendir() function. This invalidates the + * DIR structure as well as any directory entry read previously by + * _wreaddir(). + */ +static int +_wclosedir( + _WDIR *dirp) +{ + int ok; + if (dirp) { + + /* Release search handle */ + if (dirp->handle != INVALID_HANDLE_VALUE) { + FindClose (dirp->handle); + } + + /* Release search pattern */ + free (dirp->patt); + + /* Release directory structure */ + free (dirp); + ok = /*success*/0; + + } else { + + /* Invalid directory stream */ + dirent_set_errno (EBADF); + ok = /*failure*/-1; + + } + return ok; +} + +/* + * Rewind directory stream such that _wreaddir() returns the very first + * file name again. + */ +static void +_wrewinddir( + _WDIR* dirp) +{ + if (dirp) { + /* Release existing search handle */ + if (dirp->handle != INVALID_HANDLE_VALUE) { + FindClose (dirp->handle); + } + + /* Open new search handle */ + dirent_first (dirp); + } +} + +/* Get first directory entry (internal) */ +static WIN32_FIND_DATAW* +dirent_first( + _WDIR *dirp) +{ + WIN32_FIND_DATAW *datap; + DWORD error; + + /* Open directory and retrieve the first entry */ + dirp->handle = FindFirstFileExW( + dirp->patt, FindExInfoStandard, &dirp->data, + FindExSearchNameMatch, NULL, 0); + if (dirp->handle != INVALID_HANDLE_VALUE) { + + /* a directory entry is now waiting in memory */ + datap = &dirp->data; + dirp->cached = 1; + + } else { + + /* Failed to open directory: no directory entry in memory */ + dirp->cached = 0; + datap = NULL; + + /* Set error code */ + error = GetLastError (); + switch (error) { + case ERROR_ACCESS_DENIED: + /* No read access to directory */ + dirent_set_errno (EACCES); + break; + + case ERROR_DIRECTORY: + /* Directory name is invalid */ + dirent_set_errno (ENOTDIR); + break; + + case ERROR_PATH_NOT_FOUND: + default: + /* Cannot find the file */ + dirent_set_errno (ENOENT); + } + + } + return datap; +} + +/* + * Get next directory entry (internal). + * + * Returns + */ +static WIN32_FIND_DATAW* +dirent_next( + _WDIR *dirp) +{ + WIN32_FIND_DATAW *p; + + /* Get next directory entry */ + if (dirp->cached != 0) { + + /* A valid directory entry already in memory */ + p = &dirp->data; + dirp->cached = 0; + + } else if (dirp->handle != INVALID_HANDLE_VALUE) { + + /* Get the next directory entry from stream */ + if (FindNextFileW (dirp->handle, &dirp->data) != FALSE) { + /* Got a file */ + p = &dirp->data; + } else { + /* The very last entry has been processed or an error occurred */ + FindClose (dirp->handle); + dirp->handle = INVALID_HANDLE_VALUE; + p = NULL; + } + + } else { + + /* End of directory stream reached */ + p = NULL; + + } + + return p; +} + +/* + * Open directory stream using plain old C-string. + */ +static DIR* +opendir( + const char *dirname) +{ + struct DIR *dirp; + + /* Must have directory name */ + if (dirname == NULL || dirname[0] == '\0') { + dirent_set_errno (ENOENT); + return NULL; + } + + /* Allocate memory for DIR structure */ + dirp = (DIR*) malloc (sizeof (struct DIR)); + if (!dirp) { + return NULL; + } + { + int error; + wchar_t wname[PATH_MAX + 1]; + size_t n; + + /* Convert directory name to wide-character string */ + error = dirent_mbstowcs_s( + &n, wname, PATH_MAX + 1, dirname, PATH_MAX + 1); + if (error) { + /* + * Cannot convert file name to wide-character string. This + * occurs if the string contains invalid multi-byte sequences or + * the output buffer is too small to contain the resulting + * string. + */ + goto exit_free; + } + + + /* Open directory stream using wide-character name */ + dirp->wdirp = _wopendir (wname); + if (!dirp->wdirp) { + goto exit_free; + } + + } + + /* Success */ + return dirp; + + /* Failure */ +exit_free: + free (dirp); + return NULL; +} + +/* + * Read next directory entry. + */ +static struct dirent* +readdir( + DIR *dirp) +{ + struct dirent *entry; + + /* + * Read directory entry to buffer. We can safely ignore the return value + * as entry will be set to NULL in case of error. + */ + (void) readdir_r (dirp, &dirp->ent, &entry); + + /* Return pointer to statically allocated directory entry */ + return entry; +} + +/* + * Read next directory entry into called-allocated buffer. + * + * Returns zero on success. If the end of directory stream is reached, then + * sets result to NULL and returns zero. + */ +static int +readdir_r( + DIR *dirp, + struct dirent *entry, + struct dirent **result) +{ + WIN32_FIND_DATAW *datap; + + /* Read next directory entry */ + datap = dirent_next (dirp->wdirp); + if (datap) { + size_t n; + int error; + + /* Attempt to convert file name to multi-byte string */ + error = dirent_wcstombs_s( + &n, entry->d_name, PATH_MAX + 1, datap->cFileName, PATH_MAX + 1); + + /* + * If the file name cannot be represented by a multi-byte string, + * then attempt to use old 8+3 file name. This allows traditional + * Unix-code to access some file names despite of unicode + * characters, although file names may seem unfamiliar to the user. + * + * Be ware that the code below cannot come up with a short file + * name unless the file system provides one. At least + * VirtualBox shared folders fail to do this. + */ + if (error && datap->cAlternateFileName[0] != '\0') { + error = dirent_wcstombs_s( + &n, entry->d_name, PATH_MAX + 1, + datap->cAlternateFileName, PATH_MAX + 1); + } + + if (!error) { + DWORD attr; + + /* Length of file name excluding zero terminator */ + entry->d_namlen = n - 1; + + /* File attributes */ + attr = datap->dwFileAttributes; + if ((attr & FILE_ATTRIBUTE_DEVICE) != 0) { + entry->d_type = DT_CHR; + } else if ((attr & FILE_ATTRIBUTE_DIRECTORY) != 0) { + entry->d_type = DT_DIR; + } else { + entry->d_type = DT_REG; + } + + /* Reset dummy fields */ + entry->d_ino = 0; + entry->d_off = 0; + entry->d_reclen = sizeof (struct dirent); + + } else { + + /* + * Cannot convert file name to multi-byte string so construct + * an erroneous directory entry and return that. Note that + * we cannot return NULL as that would stop the processing + * of directory entries completely. + */ + entry->d_name[0] = '?'; + entry->d_name[1] = '\0'; + entry->d_namlen = 1; + entry->d_type = DT_UNKNOWN; + entry->d_ino = 0; + entry->d_off = -1; + entry->d_reclen = 0; + + } + + /* Return pointer to directory entry */ + *result = entry; + + } else { + + /* No more directory entries */ + *result = NULL; + + } + + return /*OK*/0; +} + +/* + * Close directory stream. + */ +static int +closedir( + DIR *dirp) +{ + int ok; + if (dirp) { + + /* Close wide-character directory stream */ + ok = _wclosedir (dirp->wdirp); + dirp->wdirp = NULL; + + /* Release multi-byte character version */ + free (dirp); + + } else { + + /* Invalid directory stream */ + dirent_set_errno (EBADF); + ok = /*failure*/-1; + + } + return ok; +} + +/* + * Rewind directory stream to beginning. + */ +static void +rewinddir( + DIR* dirp) +{ + /* Rewind wide-character string directory stream */ + _wrewinddir (dirp->wdirp); +} + +/* + * Scan directory for entries. + */ +static int +scandir( + const char *dirname, + struct dirent ***namelist, + int (*filter)(const struct dirent*), + int (*compare)(const struct dirent**, const struct dirent**)) +{ + struct dirent **files = NULL; + size_t size = 0; + size_t allocated = 0; + const size_t init_size = 1; + DIR *dir = NULL; + struct dirent *entry; + struct dirent *tmp = NULL; + size_t i; + int result = 0; + + /* Open directory stream */ + dir = opendir (dirname); + if (dir) { + + /* Read directory entries to memory */ + while (1) { + + /* Enlarge pointer table to make room for another pointer */ + if (size >= allocated) { + void *p; + size_t num_entries; + + /* Compute number of entries in the enlarged pointer table */ + if (size < init_size) { + /* Allocate initial pointer table */ + num_entries = init_size; + } else { + /* Double the size */ + num_entries = size * 2; + } + + /* Allocate first pointer table or enlarge existing table */ + p = realloc (files, sizeof (void*) * num_entries); + if (p != NULL) { + /* Got the memory */ + files = (dirent**) p; + allocated = num_entries; + } else { + /* Out of memory */ + result = -1; + break; + } + + } + + /* Allocate room for temporary directory entry */ + if (tmp == NULL) { + tmp = (struct dirent*) malloc (sizeof (struct dirent)); + if (tmp == NULL) { + /* Cannot allocate temporary directory entry */ + result = -1; + break; + } + } + + /* Read directory entry to temporary area */ + if (readdir_r (dir, tmp, &entry) == /*OK*/0) { + + /* Did we get an entry? */ + if (entry != NULL) { + int pass; + + /* Determine whether to include the entry in result */ + if (filter) { + /* Let the filter function decide */ + pass = filter (tmp); + } else { + /* No filter function, include everything */ + pass = 1; + } + + if (pass) { + /* Store the temporary entry to pointer table */ + files[size++] = tmp; + tmp = NULL; + + /* Keep up with the number of files */ + result++; + } + + } else { + + /* + * End of directory stream reached => sort entries and + * exit. + */ + qsort (files, size, sizeof (void*), + (int (*) (const void*, const void*)) compare); + break; + + } + + } else { + /* Error reading directory entry */ + result = /*Error*/ -1; + break; + } + + } + + } else { + /* Cannot open directory */ + result = /*Error*/ -1; + } + + /* Release temporary directory entry */ + free (tmp); + + /* Release allocated memory on error */ + if (result < 0) { + for (i = 0; i < size; i++) { + free (files[i]); + } + free (files); + files = NULL; + } + + /* Close directory stream */ + if (dir) { + closedir (dir); + } + + /* Pass pointer table to caller */ + if (namelist) { + *namelist = files; + } + return result; +} + +/* Alphabetical sorting */ +static int +alphasort( + const struct dirent **a, const struct dirent **b) +{ + return strcoll ((*a)->d_name, (*b)->d_name); +} + +/* Sort versions */ +static int +versionsort( + const struct dirent **a, const struct dirent **b) +{ + /* FIXME: implement strverscmp and use that */ + return alphasort (a, b); +} + +/* Convert multi-byte string to wide character string */ +static int +dirent_mbstowcs_s( + size_t *pReturnValue, + wchar_t *wcstr, + size_t sizeInWords, + const char *mbstr, + size_t count) +{ + int error; + +#if defined(_MSC_VER) && _MSC_VER >= 1400 + + /* Microsoft Visual Studio 2005 or later */ + error = mbstowcs_s (pReturnValue, wcstr, sizeInWords, mbstr, count); + +#else + + /* Older Visual Studio or non-Microsoft compiler */ + size_t n; + + /* Convert to wide-character string (or count characters) */ + n = mbstowcs (wcstr, mbstr, sizeInWords); + if (!wcstr || n < count) { + + /* Zero-terminate output buffer */ + if (wcstr && sizeInWords) { + if (n >= sizeInWords) { + n = sizeInWords - 1; + } + wcstr[n] = 0; + } + + /* Length of resulting multi-byte string WITH zero terminator */ + if (pReturnValue) { + *pReturnValue = n + 1; + } + + /* Success */ + error = 0; + + } else { + + /* Could not convert string */ + error = 1; + + } + +#endif + return error; +} + +/* Convert wide-character string to multi-byte string */ +static int +dirent_wcstombs_s( + size_t *pReturnValue, + char *mbstr, + size_t sizeInBytes, /* max size of mbstr */ + const wchar_t *wcstr, + size_t count) +{ + int error; + +#if defined(_MSC_VER) && _MSC_VER >= 1400 + + /* Microsoft Visual Studio 2005 or later */ + error = wcstombs_s (pReturnValue, mbstr, sizeInBytes, wcstr, count); + +#else + + /* Older Visual Studio or non-Microsoft compiler */ + size_t n; + + /* Convert to multi-byte string (or count the number of bytes needed) */ + n = wcstombs (mbstr, wcstr, sizeInBytes); + if (!mbstr || n < count) { + + /* Zero-terminate output buffer */ + if (mbstr && sizeInBytes) { + if (n >= sizeInBytes) { + n = sizeInBytes - 1; + } + mbstr[n] = '\0'; + } + + /* Length of resulting multi-bytes string WITH zero-terminator */ + if (pReturnValue) { + *pReturnValue = n + 1; + } + + /* Success */ + error = 0; + + } else { + + /* Cannot convert string */ + error = 1; + + } + +#endif + return error; +} + +/* Set errno variable */ +static void +dirent_set_errno( + int error) +{ +#if defined(_MSC_VER) && _MSC_VER >= 1400 + + /* Microsoft Visual Studio 2005 and later */ + _set_errno (error); + +#else + + /* Non-Microsoft compiler or older Microsoft compiler */ + errno = error; + +#endif +} + + +#ifdef __cplusplus +} +#endif +#endif /*DIRENT_H*/ diff -Nru libwebsockets-3.2.1/win32port/version.rc.in libwebsockets-4.1.6/win32port/version.rc.in --- libwebsockets-3.2.1/win32port/version.rc.in 2019-12-18 14:45:31.000000000 +0000 +++ libwebsockets-4.1.6/win32port/version.rc.in 2020-12-01 17:40:26.000000000 +0000 @@ -1,12 +1,13 @@ #include +#define LWS_NUMVERSION @LWS_LIBRARY_VERSION_MAJOR@,@LWS_LIBRARY_VERSION_MINOR@,0 #define LWS_VERSION @LWS_LIBRARY_VERSION_MAJOR@,@LWS_LIBRARY_VERSION_MINOR@,@LWS_LIBRARY_VERSION_PATCH@,0 #define LWS_VERSION_STR "@LWS_LIBRARY_VERSION_MAJOR@.@LWS_LIBRARY_VERSION_MINOR@.@LWS_LIBRARY_VERSION_PATCH@\0" #define LWS_PACKAGE_NAME "@PACKAGE@\0" VS_VERSION_INFO VERSIONINFO - FILEVERSION LWS_VERSION - PRODUCTVERSION LWS_VERSION + FILEVERSION LWS_NUMVERSION + PRODUCTVERSION LWS_NUMVERSION FILEFLAGSMASK VS_FFI_FILEFLAGSMASK FILEFLAGS 0 FILEOS VOS__WINDOWS32 diff -Nru libwebsockets-3.2.1/win32port/win32helpers/gettimeofday.c libwebsockets-4.1.6/win32port/win32helpers/gettimeofday.c --- libwebsockets-3.2.1/win32port/win32helpers/gettimeofday.c 2019-12-18 14:45:31.000000000 +0000 +++ libwebsockets-4.1.6/win32port/win32helpers/gettimeofday.c 2020-12-01 17:40:26.000000000 +0000 @@ -1,11 +1,12 @@ -#include -#include //I've omitted context line - -#include "gettimeofday.h" - -int gettimeofday(struct timeval *tv, struct timezone *tz) -{ - FILETIME ft; +#include +#include + +#include "gettimeofday.h" + +#ifndef LWS_MINGW_SUPPORT +int gettimeofday(struct timeval *tv, struct timezone *tz) +{ + FILETIME ft; unsigned __int64 tmpres = 0; static int tzflag; @@ -19,11 +20,11 @@ /*converting file time to unix epoch*/ tmpres /= 10; /*convert into microseconds*/ tmpres -= DELTA_EPOCH_IN_MICROSECS; - tv->tv_sec = (long)(tmpres / 1000000UL); - tv->tv_usec = (long)(tmpres % 1000000UL); - } - - if (NULL != tz) { + tv->tv_sec = (long)(tmpres / 1000000UL); + tv->tv_usec = (long)(tmpres % 1000000UL); + } + + if (NULL != tz) { if (!tzflag) { _tzset(); tzflag++; @@ -31,6 +32,7 @@ tz->tz_minuteswest = _timezone / 60; tz->tz_dsttime = _daylight; } - - return 0; -} + + return 0; +} +#endif diff -Nru libwebsockets-3.2.1/win32port/win32helpers/gettimeofday.h libwebsockets-4.1.6/win32port/win32helpers/gettimeofday.h --- libwebsockets-3.2.1/win32port/win32helpers/gettimeofday.h 2019-12-18 14:45:31.000000000 +0000 +++ libwebsockets-4.1.6/win32port/win32helpers/gettimeofday.h 2020-12-01 17:40:26.000000000 +0000 @@ -10,11 +10,11 @@ #endif #ifdef LWS_MINGW_SUPPORT - #include + #include #endif -#ifndef _TIMEZONE_DEFINED -struct timezone +#ifndef _TIMEZONE_DEFINED +struct timezone { int tz_minuteswest; /* minutes W of Greenwich */ int tz_dsttime; /* type of dst correction */ @@ -22,6 +22,8 @@ #endif +#ifndef LWS_MINGW_SUPPORT int gettimeofday(struct timeval *tv, struct timezone *tz); +#endif #endif