1
0
Fork 0
mirror of https://github.com/warmcat/libwebsockets.git synced 2025-03-09 00:00:04 +01:00
Commit graph

401 commits

Author SHA1 Message Date
Andy Green
1b4bf38d5e sspc: add request_tx length variant
Add in the missing request_tx length variant, serialization and proxy
handling for it
2020-08-10 15:04:10 +01:00
Andy Green
3899a416a9 sspc: segregate client and proxy states properly 2020-08-10 15:04:10 +01:00
Andy Green
3b6b0b7810 ss: policy: flag to allow respecting redirects 2020-08-10 15:04:10 +01:00
Andy Green
7eb36102a9 ss: server: h1, h2, ws basic support
Add initial support for defining servers using Secure Streams
policy and api semantics.

Serving h1, h2 and ws should be functional, the new minimal
example shows a combined http + SS server with an incrementing
ws message shown in the browser over tls, in around 200 lines
of user code.

NOP out anything to do with plugins, they're not currently used.

Update the docs correspondingly.
2020-07-27 12:05:24 +01:00
Andy Green
007a570962 lws_ss_change_handlers: allow dynamic handler change
You may use separate rx or tx handlers to neatly isolate different
rx or tx state handling, for example if the connection enters some
mode where you may send a variety of possibly large things, it can
be advantageous to have different code handling each of the
different things.

This allows you to change the rx, tx and / or state handlers to
different ones suitable for the user protocol state, if it's helpful.

With upcoming SS Server support, this has another use when SS
indicates that the underlying protocol upgraded, eg, http -> ws,
you may want to change the handlers for the different sort of
payloads expected after that, according to your user protocol.
2020-07-27 12:05:21 +01:00
Andy Green
9e6cefcfad lws_netdev: fix rssi averaging 2020-07-21 08:16:01 +01:00
Andy Green
1a93e73402 fakewsi: replace with smaller substructure
Currently we always reserve a fakewsi per pt so events that don't have a related actual
wsi, like vhost-protocol-init or vhost cert init via protocol callback can make callbacks
that look reasonable to user protocol handler code expecting a valid wsi every time.

This patch splits out stuff that user callbacks often unconditionally expect to be in
a wsi, like context pointer, vhost pointer etc into a substructure, which is composed
into struct lws at the top of it.  Internal references (struct lws is opaque, so there
are only internal references) are all updated to go via the substructre, the compiler
should make that a NOP.

Helpers are added when fakewsi is used and referenced.

If not PLAT_FREERTOS, we continue to provide a full fakewsi in the pt as before,
although the helpers improve consistency by zeroing down the substructure.  There is
a huge amount of user code out there over the last 10 years that did not always have
the minimal examples to follow, some of it does some unexpected things.

If it is PLAT_FREERTOS, that is a newer thing in lws and users have the benefit of
being able to follow the minimal examples' approach.  For PLAT_FREERTOS we don't
reserve the fakewsi in the pt any more, saving around 800 bytes.  The helpers then
create a struct lws_a (the substructure) on the stack, zero it down (but it is only
like 4 pointers) and prepare it with whatever we know like the context.

Then we cast it to a struct lws * and use it in the user protocol handler call.
In this case, the remainder of the struct lws is undefined.  However the amount of
old protocol handlers that might touch things outside of the substructure in
PLAT_FREERTOS is very limited compared to legacy lws user code and the saving is
significant on constrained devices.

User handlers should not be touching everything in a wsi every time anyway, there
are several cases where there is no valid wsi to do the call with.  Dereference of
things outside the substructure should only happen when the callback reason shows
there is a valid wsi bound to the activity (as in all the minimal examples).
2020-07-20 06:28:52 +01:00
Andy Green
6ae43ee06e lws_wsi_close: add helper 2020-07-20 06:28:52 +01:00
Andy Green
30761e760a sul: LWS_WITH_SUL_DEBUGGING 2020-07-15 16:18:00 +01:00
Andy Green
6762c7367f remove: old esp32 helper pieces
The old esp32 -factory stuff along with the lws support doesn't have a
future in its old form.  It has users but the ratio of effort to
contribution is really especially bad.  I haven't updated it for more
than a year since esp-idf changes broke the original stuff.

Freertos plat is alive and well and getting a lot of new use, ESP-32 is
supported both there and by modern lws_drivers pieces, including in CI
on real hardware, any further effort will be invested in that direction
instead of more vendor api-specific code (outside of wrapper
implementation).

lws_drivers wraps any SDK apis in generic lws apis such that your code
just uses those, enabling it to become SDK / SoC / vendor independent.
Its first implementation is on esp-idf, the low and mid-level features
that were in the old -factory are already available using that and
new technologies like lws_struct and Secure Streams.
2020-07-15 16:18:00 +01:00
Andy Green
634a97ad79 lws_jwt_token_sanity 2020-07-15 16:18:00 +01:00
Andy Green
77530f8ccb jwt: sign and create jws helper 2020-07-15 16:17:59 +01:00
Andy Green
5b3ea74b77 jwt: validate jws helper
Introduce a signed JWT validation helper
2020-07-15 16:17:59 +01:00
Andy Green
0bcfe88381 lws_http_cookie_get 2020-07-15 16:17:59 +01:00
Andy Green
1ae6ce37d3 lws_dll2: add helper for typed object name from owner list
There's a good pattern that's encouraged by using lws_struct pieces, that
we have an lws_dll2 owner with an array of objects listed in it that exist
in an lwsac.  And because it came from JSON, there is tending to be a
logical name for the objects.

This adds a typed helper and wrapper to scan the owner list looking for
a specific name (of a specified length, not NUL terminated) in a specific
member of the listed objects, which must be a NUL-terminated const char *.
Again this is a good pattern that's encouraged by use of lws_tokenize
to recover the name we're looking for.

So it leads to the helper that can cleanly search for a listed object of the
right name from an owner, and return the typed object pointer or NULL, from a
length-specified string.
2020-07-09 15:30:34 +01:00
Andy Green
4939b87e66 lws_netdev: use lws_settings
Perform the AP selection using lws_settings and a generic scan state machine
2020-07-07 15:23:19 +01:00
Jed Lu
ed528b59f7 ss: client: add sspc_to_user_obj
Helper api exists in direct lws_ss_ apis but not in lws_sspc_, align it.
2020-07-07 15:23:19 +01:00
Andy Green
c410956a31 ss: event_helper handles destroy requests itself
Callbacks can ask the caller to, eg, destroy the ss handle now.  But some
callback returns are handled and produced inside other helper apis, eg
lws_ss_backoff() may have to had fulfilled the callback request to destroy
the ss... therefore it has to signal to its caller, and its callers have
to check and exit their flow accordingly.
2020-07-07 11:28:36 +01:00
Andy Green
f902873634 ss: add timeout 2020-07-07 11:28:28 +01:00
Andy Green
b72ab32c17 lws_netdev 2020-07-02 10:36:31 +01:00
Andy Green
65545d2d21 lws-settings 2020-07-02 10:20:17 +01:00
Andy Green
63c1e8ba00 esp32-wrover-kit
Add lws_display and minimal example support for esp32-wrover to match wsp32-heltec-wb32

Since no usable buttons that don't affect something else on wrover kit, assumes
a button to 0V on GPIO14.
2020-06-30 19:35:41 +01:00
Andy Green
8eca7e17f2 lws_smd: system message distribution
- Add low level system message distibution framework
 - Add support for local Secure Streams to participate using _lws_smd streamtype
 - Add apit test and minimal example
 - Add SS proxy support for _lws_smd

See minimal-secure-streams-smd README.md
2020-06-27 07:57:22 +01:00
Andy Green
30f3606b0e context: option to disable system state management 2020-06-27 07:57:22 +01:00
Andy Green
ceb4e53174 lws_button: classification
Now there's an abstract button class regardless of the underlying
connection, we can add more sophicsticated analysis on top of it
for processing its usually noisy events and classifying them into
smd-ready click, long-click or double-click events.

A "regime" defines the timing limits for different press recognition
and can be specified per-button, if not given a default regime is
applied.
2020-06-27 07:57:22 +01:00
Andy Green
33f1003305 lws_pwm 2020-06-27 07:57:22 +01:00
Andy Green
366333adba lejp: docs: clarify LEJPCB_VAL_STR_CHUNK 2020-06-22 08:14:56 +01:00
Andy Green
5a937fa830 lws_json_simple_find and lws_nstrstr
String helpers for scanning non-NUL-delimited strings safely,
and very cheap simple string match based JSON parse for cases
that make sense for it... for more complex cases, do a full
JSON parse.
2020-06-20 04:56:30 +01:00
Andy Green
d4a7c7134a lws_button and lws_led
Generic drivers for buttons and leds
2020-06-18 16:57:44 +01:00
Andy Green
6747ab830e content_info: make members conditional 2020-06-18 08:29:43 +01:00
Andy Green
ac6edaf199 lws_strexp: add ability to find output length without write
Sometimes we need to find out the substituted length before we can
allocate and actually store it.  Teach strexp that if we set the
output buffer to NULL (and the output length to something big) we
are asking for the substituted length and to not produce output.
2020-06-16 19:45:35 +01:00
Andy Green
30e6c22e14 openssl3: migrate genhmac to EVP
The low level apis for HMAC (including those only introduced at 1.1.0...)
are all deprecated in OpenSSL v3.

Let's bite the bullet and migrate to EVP, it's already existing in modern
OpenSSL and we already use it for genhash.

EVP needs a PKEY, sort that out and keep it around until the hmac is
destroyed.
2020-06-16 19:45:35 +01:00
Andy Green
15ce46d971 drivers: initial generic gpio and i2c plus bitbang
Make a start on generic peripheral and bus drivers to provide
meta-functionality regardless of platform.

On the one hand this simply provides...

 - bitbang i2c on top of esp-idf gpio apis
 - ssd1306 oled chip driver as found on Heltec WB32
 - modifications to the minimal example test for esp32 to use that

... on the other hand, those capabilities are provided by creating:

 - an abstract i2c class object
 - an abstract gpio class object
 - i2c class implementation using the abstract gpio for bitbang
 - an abstract display class object
 - an abstract display state (brightness, animated change,
    on/off/init tracking, autodim after inactive, auto-off /
    blanking after inactive)

... with the intention, eg, you only have to add a platform
implementation for the gpio to be able to use the i2c-based
display drivers and state handling, and i2c bitbang, without
any other modifications.
2020-06-10 19:17:08 +01:00
Andy Green
2a772776a9 windows: for data exports use explicit extern
LWS_EXTERN needs to be empty for windows when declaring functions in the
headers.  But for data, it needs the explicit extern otherwise on windows
or mingw based builds, it thinks we are redeclaring the data each time.
2020-06-07 07:53:36 +01:00
alex
5d514b35fc tls: add read client .pem or .der from memory #1941
and added read private key from mem
2020-06-06 13:09:31 +01:00
Andy Green
698eda63d7 ss: formalize user cb retcodes
It's not safe to destroy objects inside a callback from a parent that
still has references to the object.

Formalize what the user code can indicate by its return code from the
callback functions and provide the implementations at the parents.

 - LWSSSSRET_OK:            no action, OK
 - LWSSSSRET_DISCONNECT_ME: disconnect the underlying connection
 - LWSSSSRET_DESTROY_ME:    destroy the ss object
 - LWSSSSRET_TX_DONT_SEND:  for tx, give up the tx opportunity since nothing to send
2020-06-02 08:37:10 +01:00
Andy Green
ca3380fd56 deprecation: remove lws_dll1
lws_dll2 has been available for a couple of years and lws_dll1 marked as
deprecated since v3.2.  Remove it.

If it affects you, lws_dll2 has an almost identical api but has more
features, such as storing in the lws_dll2_t which owner it is listed by
and keeping a count of objects on the list at the owner object.
2020-06-02 08:37:10 +01:00
Andy Green
286cf4357a sul: multiple timer domains
Adapt the pt sul owner list to be an array, and define two different lists,
one that acts like before and is the default for existing users, and another
that has the ability to cooperate with systemwide suspend to restrict the
interval spent suspended so that it will wake in time for the earliest
thing on this wake-suspend sul list.

Clean the api a bit and add lws_sul_cancel() that only needs the sul as the
argument.

Add a flag for client creation info to indicate that this client connection
is important enough that, eg, validity checking it to detect silently dead
connections should go on the wake-suspend sul list.  That flag is exposed in
secure streams policy so it can be added to a streamtype with
"swake_validity": true

Deprecate out the old vhost timer stuff that predates sul.  Add a flag
LWS_WITH_DEPRECATED_THINGS in cmake so users can get it back temporarily
before it will be removed in a v4.2.

Adapt all remaining in-tree users of it to use explicit suls.
2020-06-02 08:37:10 +01:00
Andy Green
90c7e789eb PEER_LIMITS: modernize to sa46 and add notification cb
There are a bunch of sa46-aware lws apis for formatting, etc sa46
in ./include/libwebsockets/lws-network-helper.h
2020-06-02 08:37:10 +01:00
Andy Green
b3131fdfdd cmakelist: Augean Stables refactor
Establish a new distributed CMake architecture with CMake code related to
a source directory moving to be in the subdir in its own CMakeLists.txt.
In particular, there's now one in ./lib which calls through to ones
further down the directory tree like ./lib/plat/xxx, ./lib/roles/xxx etc.

This cuts the main CMakelists.txt from 98KB -> 33KB, about a 66% reduction,
and it's much easier to maintain sub-CMakeLists.txt that are in the same
directory as the sources they manage, and conceal all the details that that
level.

Child CMakelists.txt become responsible for:

 - include_directories() definition (this is not supported by CMake
   directly, it passes it back up via PARENT_SCOPE vars in helper
   macros)

 - Addition child CMakeLists.txt inclusion, for example toplevel ->
   role -> role subdir

 - Source file addition to the build

 - Dependent library path resolution... this is now a private thing
   in the child CMakeLists.txt, it just passes back any adaptations
   to include_directories() and the LIB_LIST without filling the
   parent namespace with the details
2020-05-27 08:40:12 +01:00
Andy Green
cabe021955 esp32: shift to support latest esp-idf
Esp-idf has an improved but still kind of abused cmake-
based build system now.

If we see ESP_PLATFORM coming as a cmake var, we can know we
are being built from inside the esp-idf config system.

Leave the existing esp32 arrangements alone but triggered off
ESP_PLATFORM, adapt to use the cross toolchain file and
various quirks automatically.

In this way you can build lws a part of your project in a
much cleaner way.

Prepare a minimal esp32 test app for use in Sai

Adapt .sai.json to build for esp32
2020-05-27 08:40:12 +01:00
Andy Green
b6641af88d api-test: lws_struct-json: add worked example
Add support for implicit schema polymorphism
2020-05-27 08:40:12 +01:00
Andy Green
280c81278d ws: remove now unused ws_ping_pong_interval
https://github.com/warmcat/libwebsockets/issues/1915
2020-05-27 08:40:12 +01:00
Andy Green
36ec353dac client: allow setting overall connect timeout from vh init
Add a member to the vh init struct allowing control of the overall
connection wait introduced in an earlier patch.  Set it to 20s
by default.


The timeout_secs member controls the individual DNS result
connect timeout and is reduced to 5s by default.
2020-05-26 17:05:39 +01:00
Andy Green
e4a9307b11 lejp: support outer element is array 2020-05-11 21:20:29 +01:00
Kyle Greenwell
bebd3f71a6 h2: add prior knowledge support 2020-05-08 18:56:17 +01:00
Andy Green
43b83c333b client: allow setting keep warm time
Until now if the generic transaction completes and the connection is idle,
there's a fixed 5s grace period to keep the connection up in case something
else wants it.

This allows setting it in the client creation info struct .keep_warm_secs.
If left at 0, then it maintains the backward-compatible 5s wait.
2020-05-06 09:06:24 +01:00
Andy Green
641831b3c5 context: if linux and fd_limit_per_thread set try to configure by setrlimit 2020-05-06 09:06:24 +01:00
Andy Green
3d995cf7c5 fds: add sanity checks 2020-05-05 06:34:58 +01:00
Andy Green
cced12822b lws_dir: add rm -rf and glob filter callbacks
Bring over two general-purpose callbacks for lws_dir from Sai
2020-05-03 14:16:48 +01:00