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

3618 commits

Author SHA1 Message Date
Andy Green
22e6d5212b spawn: in discrete env setting case do it readonly
OSX changed to blow a segfault on write to .rodata, exposing that
we're dropping a NUL in what can be .rodata to set the environment
manually.  We don't do this on Linux typically because we take the
code path where execvpe() is available to do the env for us.

Adapt the code to treat it as const, and underscore it by changing
its type to be const char ** in the info struct.
2020-10-19 16:35:03 +01:00
krismattheus
b011a915ed cmake: add windows version resources to library
Signed-off-by: krismattheus <kris.mattheus@visionbms.com>
2020-10-19 16:35:03 +01:00
Andy Green
643a001ed8 roles: netlink
This creates a role for RFC3549 Netlink monitoring.

If the OS supports it (currently, linux) then each pt creates a wsi
with the netlink role and dumps the current routing table at pt init.
It then maintains a cache of the routing table in each pt.

Upon routing table changes an SMD message is issued as an event, and
Captive Portal Detection is triggered.

All of the pt's current connections are reassessed for routability under
the changed routing table, those that no longer have a valid route or
gateway are closed.
2020-10-19 16:35:03 +01:00
Andy Green
915f888f3e sa46: network check
This adds a helper to test if an sa46 is on an sa46-based subnet.

The compare helper is adapted to say that non INET/INET6 addresses with
the same AF match.
2020-10-19 16:35:03 +01: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
4e973c3cc5 ss: metadata: rename value to add reminder about heap 2020-10-19 16:34:54 +01:00
Andy Green
657cadf7c6 http: bind PUT and friends to mounts 2020-10-10 06:52:42 +01:00
casey
eddecea3c8 fix zombie sul detection
The cmake define isn't exported, and msvc objects to void * comparision to
non void *.

Also dump the callback pointer with any errors, since after looking it up
in your mapfile this is usually enough to understand which sul and when it
was set.
2020-10-10 06:43:32 +01:00
Andy Green
db5b2c1403 close: ensure any pending sul_connect_timeout cancelled 2020-10-09 21:30:49 +01:00
Andy Green
170a5db028 cgi: support evlib_wsi in stdwsi 2020-10-09 21:30:45 +01:00
Andy Green
27964ddaf2 ws: reporting PONG with pmd enabled
Add a return code NOTHING_WE_SHOULD_DO indicating that the
extension determined by ext-specific means its operation was
disabled on this frame.

https://github.com/warmcat/libwebsockets/issues/2076
2020-10-09 08:00:44 +01:00
casey
e44c8698ca windows: null check wsi before udp check 2020-10-09 06:55:02 +01:00
casey
5d025839c6 windows: fix WSA event destruction
pt->events became an array
2020-10-09 06:53:44 +01:00
Andy Green
04d947b6f7 windows: WSA loop fixes 2020-10-08 14:52:54 +01:00
Andy Green
2ad378095d freertos: have lwip choose the cancel pipe port
Rather than a magic port, let's have lwip pick the port for
the UDP cancel "pipe", so no chance of conflict.
2020-10-08 11:21:45 +01:00
Jed Lu
ee78b90c8c ss: take care to free any metadata heap values before overwrite
Break out the core ss_set_metadata action into a subfunction that
takes the lws_ss_metadata_t, and is fixed to retire heap-based
values before they go out of scope, and adapt the exported version
to call through to that.

Simplify extract_metadata() to reuse the subfunction as well, in
both well-known and custom header cases.
2020-10-07 19:20:12 +01:00
Andy Green
8c88b857a9 h1: explicitly close when post txn completes
https://github.com/warmcat/libwebsockets/issues/2072
2020-10-06 13:56:45 +01:00
Mykola Stryebkov
89f4b739e1 minimal: smp + foreign: libuv foreign loops
AG: various fixes and adaptation of test protocol to use ring lock
to protect global wsi list against modifications from other threads
while in use
2020-10-05 08:39:05 +01:00
Andy Green
26a0d500a1 smp: additional locking for libuv
With SMP + event lib, extra locking is required when dealing with cross-thread
adoption case, and cross-vhost cases like wsi close, we need to hold the pt or
context lock.

These lock apis are NOPs when LWS_MAX_SMP == 1 which is the default.
2020-10-01 10:46:51 +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
6490dc3e89 smp: set tsi in fakewsi used with WAIT_CANCELLED
Together with the new lws_wsi_tsi(wsi) this lets the WAIT_CANCELLED
callback understand its tsi context, the broadcasts are done for each
pt / loop.
2020-10-01 10:41:46 +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
cb2e04f602 ss: compiler may complain in release mode due to info 2020-09-29 16:52:51 +01:00
Jed Lu
9bff4d84ed sspc: http map proxying fixes 2020-09-22 07:39:24 +01:00
Sakthi Kannan
4e9f433b7e mqtt: fix extra byte on SUBSCRIBE 2020-09-21 17:04:42 +01:00
小明
c8fc7a6f37 ios: adapt to MSG_NOSIGNAL available in iOS SDK 12+ 2020-09-21 12:47:11 +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
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
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
40f4ce9ffc testapp: extpoll: add back missing EXTERNAL_POLL pieces
EXTERNAL_POLL is not recommended for use for a while, it's a hack to allow
integration of lws with random application poll() loops.

While lws is very happy to do that secondary job for any event lib using the
foreign loop support (for uv, event, glib, and ev), for random roll-your-
own poll() waits there's no api because there's no event lib.  The solution
with a future is upgrade your application to use an event loop.

The test app that supports EXTERNAL_POLL was broken in Apr 2018, so it's
apparently good news nobody has been using it in new implementations
since then.  This patch adds in the missing pieces so we can test it until
it is formally deprecated.
2020-09-18 11:37:21 +01:00
Orgad Shaneh
471dbf5280 cmake: mingw: fix openssl linkage
ws32 and friends must come after the openssl libs,
and pthread is required for openssl.
2020-09-18 11:37:17 +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
d41bb16074 docs: force markdown to render correct path 2020-09-16 13:10:23 +01:00
Andy Green
aa539e607b client: awaiting header is only a CCE for ws
In the case http client doesn't get a response and closes, currently
it is confused, it reports it as a CLIENT_CONNECTION_ERROR but then
also a CLOSED_CLIENT_HTTP.

Adapt the logic so we only go that way for ws connection... not getting
the server headers means not reaching ESTABLISHED, which makes it a
CCE not a CLOSE.

Also make sure we never issue a CLOSE type callback if we issued a CCE.
2020-09-16 12:30:46 +01:00
Orgad Shaneh
1ce85e005c smd: fix strict-aliasing warning on gcc 4.4 2020-09-16 08:04:39 +01:00
Orgad Shaneh
0ca76698c1 lws_dir: do not compare enums using the preprocessor
It is invalid on some platforms.

Fixes #2003
2020-09-16 08:04:33 +01:00
Orgad Shaneh
7676313946 core-net: initialize some variables
Amends 286cf4357a.
2020-09-16 07:07:04 +01:00
Sakthi Kannan
1a8979b68c mbedtls: use lws helper for PEM DER import 2020-09-16 07:07:04 +01:00
Orgad Shaneh
2badaef4fc unix plat: avoid strict aliasing complaint from a toolchain
The type of the fields in rtentry is sockaddr, and it is
casted to sockaddr_in. Size-wise it is ok, they should both
be the same size. But casting a pointer breaks build with
optimizations with the following error:

unix-sockets.c:434: error: dereferencing pointer 'addr' does break strict-aliasing rules

Amends commit 3c95483518.
2020-09-16 07:07:04 +01:00
Andy Green
92ed19164c event-libs: update README.md in the main dir for plugin capable flow 2020-09-14 06:58:08 +01:00
Andy Green
b1a084e7be ss: server: make sure failures after adopt invalidate ss copy of wsi
For server, if the adoption of the incoming connection proceeds but then
fails early on, eg, tls alert due to hostname mismatch with cert, the
wsi close happens but it doesn't clean up the invalidated reference to
itself in the server ss object... if it became established, that's handled
by the ss protocol callback.

This patch helps the close path to understand there is a related ss object
and to clean up after itself.
2020-09-13 14:37:15 +01:00
Andy Green
a7c9af5ac5 ss: server: dont allow client request_tx path even if disconnected 2020-09-13 14:37:15 +01:00
Andy Green
6a32db56bc libuv: fix pt derivation from ptpr in callbacks
The per-pt priv for event libs ended up overallocated at the context,
and pointed-to by a single pointer composed into each pt.  That means
we can't do pointer arithmetic on it any more.

Update a couple of stragglers in libuv event lib to use a pointer in
the pt-priv for the event lib back to the pt instead.

Also in foreign case if we start idle, there may not be anything
happening to trigger the initial idle.  So let each pt start with
its idle active.
2020-09-13 14:37:15 +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