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

439 commits

Author SHA1 Message Date
Andy Green
2329dc6968 zip-fops: example: correct zipfile serving path 2020-12-01 15:38:20 +00:00
Andy Green
4343182002 logging: reduce serving logs 2020-12-01 15:38:20 +00:00
Yucong Sun
a72e975613 mingw: libevent build fixes 2020-11-28 10:58:38 +00:00
Andy Green
acfd3491b9 http: REDIRECT_HTTP_TO_HTTPS apply the original path to redirect
Let's regenerate the path and urlargs part on the redirect, for the case we
are forcing clients to redirectto the same place but with tls


https://github.com/warmcat/libwebsockets/issues/2112
2020-11-28 10:58:38 +00:00
Andy Green
2bcae2b3b6 context: refactor destroy flow 2020-11-28 10:58:38 +00:00
Andy Green
3549a94ce6 roles: compress role ops structs
role ops are usually only sparsely filled, there are currently 20
function pointers but several roles only fill in two.  No single
role has more than 14 of the ops.  On a 32/64 bit build this part
of the ops struct takes a fixed 80 / 160 bytes then.

First reduce the type of the callback reason part from uint16_t to
uint8_t, this saves 12 bytes unconditionally.

Change to a separate function pointer array with a nybble index
array, it costs 10 bytes for the index and a pointer to the
separate array, for 32-bit the cost is

2 + (4 x ops_used)

and for 64-bit

6 + (8 x ops_used)

for 2 x ops_used it means 32-bit: 10 vs 80 / 64-bit: 22 vs 160

For a typical system with h1 (9), h2 (14), listen (2), netlink (2),
pipe (1), raw_skt (3), ws (12), == 43 ops_used out of 140, it means
the .rodata for this reduced from 32-bit: 560 -> 174 (386 byte
saving) and 64-bit: 1120 -> 350 (770 byte saving)

This doesn't account for the changed function ops calling code, two
ways were tried, a preprocessor macro and explicit functions

For an x86_64 gcc 10 build with most options, release mode,
.text + .rodata

before patch:          553282
accessor macro:        552714 (568 byte saving)
accessor functions:    553674 (392 bytes worse than without patch)

therefore we went with the macros
2020-11-28 10:58:38 +00:00
Andy Green
6bc5c0ffac reduce debug logging 2020-11-09 07:40:35 +00:00
Andy Green
21719898e8 wsi: store peer lws_sockaddr46
If we connect out to an IP address, or we adopt a connected socket,
from now on we want to hold the peer sockaddr in the wsi.

Adapt ACCESS_LOG to use this new copy rather than keep the
stringified version.
2020-10-19 16:35:03 +01:00
Andy Green
67d24d7c00 cleaning 2020-10-19 16:35:03 +01:00
Andy Green
44e860642b docs: switch to use main 2020-10-19 16:35:03 +01:00
Andy Green
657cadf7c6 http: bind PUT and friends to mounts 2020-10-10 06:52:42 +01:00
Andy Green
62e566b9de client: move staged connect pieces into core-net
They have been in lib/roles/http for historical reasons, and all
ended up in client-handshake.c that doesn't describe what they
actually do any more.  Separate out the staged client connect
related stage functions into

  lib/core-net/client/client2.c: lws_client_connect_2_dnsreq()
  lib/core-net/client/client3.c: lws_client_connect_3_connect()
  lib/core-net/client/client4.c: lws_client_connect_4_established()

Move a couple of other functions from there that don't belong out to
tls-client.c and client-http.c, which is related to http and remains
in the http role dir.
2020-09-21 12:47:11 +01:00
Andy Green
21546e511d h2: mark :protocol as an h2 psuedoheader 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
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
e3e177a7d6 smp: add pt lock on client connect path 2020-08-31 16:51:37 +01:00
Andy Green
095b76853e smp: lws_mutex_refcount: add assert held helper
also additional pt locks shown as needed by that
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
72b245ea38 h2: fix breakage with LWS_WITH_HTTP2=0 2020-08-31 16:51:37 +01:00
Andy Green
258ee1886f coverity: 37468: confirm gethostname worked 2020-08-19 07:19:48 +01:00
Andy Green
7ff64b3c42 coverity: 10117: help coverity understand simple_ptr cannot be NULL 2020-08-19 06:40:13 +01:00
Andy Green
5ef6c548d8 coverity: 62488 62253: comment NOP left in for extensibility 2020-08-18 14:00:54 +01:00
Andy Green
1892af1ce3 coverity: 40529: add needless check on NULL simple_ptr after confirmed it has nonzero length 2020-08-18 14:00:54 +01:00
Andy Green
630391e0fb coverity: 50320: show coverity protocol can always be found by name 2020-08-18 14:00:54 +01:00
Andy Green
b1281f1f3a coverity: 50773: no need to set m any more when transitioning and exiting 2020-08-18 14:00:54 +01:00
Andy Green
cdbf86fe4a coverity: 51248: convince coverity we have an ah attached before dereference during parse 2020-08-18 14:00:54 +01:00
Andy Green
b63c7f1e8e coverity: 62131: check when logging role name for NULL 2020-08-18 14:00:54 +01:00
Andy Green
06005d14b4 coverity: 62154: calculation needed if WITH_FILE_OPS 2020-08-18 09:34:50 +01:00
Andy Green
048604751c coverity: 62584: init m only inside preprocessor conditional that needs it 2020-08-18 09:28:40 +01:00
Andy Green
60e2c65208 coverity: 62333; no need to init cce as set on all paths that use it 2020-08-18 09:19:34 +01:00
Andy Green
400355fdc3 coverity: 62458: coverity doesnt understand nonzero header length means simple_ptr cannot be NULL 2020-08-18 09:19:33 +01:00
Andy Green
9745c5cca8 coverity: 62477: explicitly check wsi->protocol even though client creation sets it 2020-08-18 09:11:45 +01:00
Andy Green
192b76c89b coverity: 62540: explicitly check for NULL even though cannot be 2020-08-18 09:08:03 +01:00
Andy Green
0f173e0bbe coverity: 62622: remove unused line 2020-08-18 09:00:39 +01:00
Andy Green
491f0f6068 coverity: 324943: confirm get_random worked
In normal systems this doesn't have a way to fail.  But check it for
consistency.
2020-08-14 09:07:27 +01:00
Andy Green
908d259a47 coverity: 305064: clear false positive by needless NULL check
Add needless check so we don't keep getting the same coverity hit from different people
2020-08-14 07:02:07 +01:00
Andy Green
9a7ce85001 h2: defend against no NUL possible in log 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
08bc9bf410 ss: http: handle rx DESTROY_ME 2020-07-21 07:57:15 +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
da7ef0468b cgi: add spawn reap callback 2020-07-20 06:28:52 +01:00
Andy Green
634a97ad79 lws_jwt_token_sanity 2020-07-15 16:18:00 +01:00
Andy Green
0bcfe88381 lws_http_cookie_get 2020-07-15 16:17:59 +01:00
Andy Green
6b639e6a81 coverity: force amount to 0 before read call 2020-07-08 18:27:47 +01:00
Andy Green
b72ab32c17 lws_netdev 2020-07-02 10:36:31 +01:00
Andy Green
04c20d7460 ah: workaround for broken routers with no http header delimiter
There's a type of router in the wild issuing malformed http when
in captive portal mode... there's no \x0a\x0d but just \x0a
2020-06-30 17:52:10 +01:00
Jed Lu
84f8137fa6 ah-un_pos-cleanup-fix-other-path 2020-06-30 17:49:14 +01:00
Andy Green
a75a476026 ah: use unk_pos to clean up unknown header starts even without CUSTOM_HEADERS 2020-06-27 07:57:22 +01:00
Andy Green
6747ab830e content_info: make members conditional 2020-06-18 08:29:43 +01:00
Andy Green
4948291b8b multipart: quote boundary
https://github.com/warmcat/libwebsockets/issues/1948
2020-06-16 19:45:35 +01:00