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

473 commits

Author SHA1 Message Date
Andy Green
04d947b6f7 windows: WSA loop fixes 2020-10-08 14:52:54 +01:00
Andy Green
3fa221f9d6 smp: lws_wsi_tsi
This lets you find out the SMP Thread Service Index (tsi) that a wsi
is bound to.  This allows you to, eg, filter a global wsi list so
you can find the ones that exist in your service thread context.
2020-10-01 10:43:12 +01:00
Andy Green
636f9c7f01 evlib: export LWS_MAX_SMP locking for evlib plugin case with SMP
Now we're also looking at SMP + event lib, SMP locking pieces are
going to be needed for import into the event lib plugins if built
as plugins.
2020-10-01 10:41:43 +01:00
Andy Green
08c9395da5 update some wording 2020-09-30 06:42:13 +01:00
Andy Green
ef8bfb2488 windows: build fixes 2020-09-30 06:42:09 +01:00
Andy Green
90a12db7ef lws_ctx_t
Let's start using a typedef for struct lws_context *, lws_ctx_t and
the convention to call it ctx.
2020-09-29 06:56:19 +01:00
Andy Green
80388bf72d sspc: extend RXPRE_CONNSTATE to handle 8 or 32-bit states
Currently only the low 8 bits of an SS state are proxied in a total packet
length of 8 octets.  Keep that format and behaviour since all the defined
states fit in 8 bits, but also allow for 32-bit states using a packet length
of 11 octets with the same command.

This lets us proxy user states (from http mapping) which start at a user
base of 1000.
2020-09-20 09:17:09 +01:00
Andy Green
49e92ba089 http: add RFC7231 date and time helpers and retry-after handling
Teach lws how to deal with date: and retry-after:

Add quick selftest into apt-test-lws_tokenize

Expand lws_retry_sul_schedule_retry_wsi() to check for retry_after and
increase the backoff if a larger one found.

Finally, change SS h1 protocol to handle 503 + retry-after: as a
failure, and apply any increased backoff from retry-after
automatically.
2020-09-19 14:11:56 +01:00
Andy Green
33da902ed4 ss: policy: response code mapping
This adds a per-streamtype JSON mapping table in the policy.

In addition to the previous flow, it lets you generate custom
SS state notifications for specific http response codes, eg:

   "http_resp_map": [ { "530": 1530 }, { "531": 1531 } ],

It's not recommended to overload the transport-layer response
code with application layer responses.  It's better to return
a 200 and then in the application protocol inside http, explain
what happened from the application perspective, usually with
JSON.  But this is designed to let you handle existing systems
that do overload the transport layer response code.

SS states for user use start at LWSSSCS_USER_BASE, which is
1000.

You can do a basic test with minimal-secure-streams and --respmap
flag, this will go to httpbin.org and get a 404, and the warmcat.com
policy has the mapping for 404 -> LWSSSCS_USER_BASE (1000).

Since the mapping emits states, these are serialized and handled
like any other state in the proxy case.

The policy2c example / tool is also updated to handle the additional
mapping tables.
2020-09-16 13:10:26 +01:00
Andy Green
101b474217 ss: rx metadata
At the moment you can define and set per-stream metadata at the client,
which will be string-substituted and if configured in the policy, set in
related outgoing protocol specific content like h1 headers.

This patch extends the metadata concept to also check incoming protocol-
specific content like h1 headers and where it matches the binding in the
streamtype's metadata entry, make it available to the client by name, via
a new lws_ss_get_metadata() api.

Currently warmcat.com has additional headers for

server: lwsws                (well-known header name)
test-custom-header: hello    (custom header name)

minimal-secure-streams test is updated to try to recover these both
in direct and -client (via proxy) versions.  The corresponding metadata
part of the "mintest" stream policy from warmcat.com is

                        {
                                "srv": "server:"
                        }, {
                                "test": "test-custom-header:"
                        },

If built direct, or at the proxy, the stream has access to the static
policy metadata definitions and can store the rx metadata in the stream
metadata allocation, with heap-allocated a value.  For client side that
talks to a proxy, only the proxy knows the policy, and it returns rx
metadata inside the serialized link to the client, which stores it on
the heap attached to the stream.

In addition an optimization for mapping static policy metadata definitions
to individual stream handle metadata is changed to match by name.
2020-09-16 13:10:26 +01:00
Andy Green
5c7b5af92a cmake: disable export visibility when building lws static
This is complicated by the fact extern on a function declaration implies
visibility... we have to make LWS_EXTERN empty when building static.

And, setting target_compile_definitions() doesn't work inside macros,
so it has to be set explicitly for the plugins.

Checking the symbol status needs nm -C -D as per

https://stackoverflow.com/questions/37934388/symbol-visibility-not-working-as-expected

after this patch, libwebsockets.a shows no symbols when checked like that and
the static-linked minimal examples only show -U for their other dynamic
imports.

In a handful of cases we use LWS_EXTERN on extern data declarations,
those then need to change to explicit extern.
2020-09-06 11:46:25 +01:00
Andy Green
63e9699bda v4.1.0 2020-09-04 13:42:57 +01:00
Andy Green
008b355166 freertos: fixes for build on atmel xdk 2020-09-03 12:49:54 +01:00
Andy Green
4ae3ef51c1 ss: improve callback return consistency
Formalize the LWSSSSRET_ enums into a type "lws_ss_state_return_t"
returned by the rx, tx and state callbacks, and some private helpers
lws_ss_backoff() and lws_ss_event_helper().

Remove LWSSSSRET_SS_HANDLE_DESTROYED concept... the two helpers that could
have destroyed the ss and returned that, now return LWSSSSRET_DESTROY_ME
to the caller to perform or pass up to their caller instead.

Handle helper returns in all the ss protocols and update the rx / tx
calls to have their returns from rx / tx / event helper and ss backoff
all handled by unified code.
2020-08-31 16:51:37 +01:00
Andy Green
1e0da366be sul: export schedule helpers as functions so easier to add pt lock 2020-08-31 16:51:37 +01:00
Andy Green
c6c7ab2b44 event libs: default to building as dynamically loaded plugins
Event lib support as it has been isn't scaling well, at the low level
libevent and libev headers have a namespace conflict so they can't
both be built into the same image, and at the distro level, binding
all the event libs to libwebsockets.so makes a bloaty situation for
packaging, lws will drag in all the event libs every time.

This patch implements the plan discussed here

https://github.com/warmcat/libwebsockets/issues/1980

and refactors the event lib support so they are built into isolated
plugins and bound at runtime according to what the application says
it wants to use.  The event lib plugins can be packaged individually
so that only the needed sets of support are installed (perhaps none
of them if the user code is OK with the default poll() loop).  And
dependent user code can mark the specific event loop plugin package
as required so pieces are added as needed.

The eventlib-foreign example is also refactored to build the selected
lib support isolated.

A readme is added detailing the changes and how to use them.

https://libwebsockets.org/git/libwebsockets/tree/READMEs/README.event-libs.md
2020-08-31 16:51:37 +01:00
Andy Green
d98101d1e3 plugins: generalize and provide public api
Move the common plugin scanning dir stuff to be based on lws_dir, which
already builds for windows.  Previously this was done via dirent for unix
and libuv for windows.

Reduce the dl plat stuff to just wrap instantiation and destruction of
dynlibs, establish common code in lib/misc/dir.c for plugin scanning
itself.

Migrate the libuv windows dl stuff to windows-plugins.c, so that he's
available even if later libuv loop support becomes and event lib plugin.

Remove the existing api exports scheme for plugins, just export a const struct
now which has a fixed header type but then whatever you want afterwards depending
on the class / purpose of the plugin.  Place a "class" string in the header so
there can be different kinds of plugins implying different types exported.

Make the plugin apis public and add support for filter by class string, and
per instantation / destruction callbacks so the subclassed header type can
do its thing for the plugin class.  The user provides a linked-list base
for his class of plugins, so he can manage them completely separately and
in user code / user export types.

Rip out some last hangers-on from generic sessions / tables.

This is all aimed at making the plugins support general enough so it can
provide event lib plugins later.
2020-08-31 16:51:37 +01:00
Andy Green
fa78129f73 ws: LCCSCF_PRIORITIZE_READS 2020-08-31 16:51:37 +01:00
Andy Green
28f4aae555 listen: network filter: provide a struct with client info to the FILTER cb
For backwards compatibility, keep the cast fd on in and pass an info struct
to the callback by overloading user_data.
2020-08-31 16:51:37 +01:00
Andy Green
44608abce6 sspc: fix intree build for sspc examples and increase post example body
Correct a comment about payload layout and add detailed comments about
dsh handling at proxy.

Increase the post size so it shows up fragmentation issues at the proxy.
2020-08-13 16:48:16 +01:00
Andy Green
dd3bae8c71 ss: multipart without processing
Change the default to not process multipart mime at SS layer.

If it's desired, then set "http_multipart_ss_in" true in the policy on the streamtype.

To test, use lws-minimal-secure-streams-avs, which uses SS processing as it is.

To check it without the processing, change #if 1 to #if 0 around the policy for
"http_multipart_ss_in" in both places in avs.c, and also enable the hexdump in ss_avs_metadata_rx()
also in avs.c, and observe the multipart framing is passed through unchanged.
2020-08-11 11:07:13 +01:00
Andy Green
2edd83dac1 freebsd: sai build adaptations 2020-08-10 15:04:10 +01:00
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