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

363 commits

Author SHA1 Message Date
Zevv
b09b416b1d http client: add flag to disable redir follow 2020-02-04 14:16:18 +00:00
Andy Green
270f2f48c8 lws_buflist_aware_read: restrict to incoming ebuf length if non-NULL ebuf.token incoming
(Includes fixes from Yichen Gu)

Currently the incoming ebuf is always replaced to point to either a whole
buflist segment, or up to the (pt_serv_buf - LWS_PRE) length in the pt_serv_buf.

This is called on path for handling http read... some user code reasonably wants to
restrict the read size to what it can handle.

Change the other lws_buflist_aware_read() callers to zero ebuf before calling, and for
those have it keep the current behaviour; but if non-NULL ebuf.token on incoming, as
in http read path case, restrict both reported len of buflist content and the read length
to the incoming ebuf.len so the user code can control what it will get at one time.

Additionally muxed protocol wsi have no choice but to read what was sent to them
since it's HOL-blocking for other streams and its own WINDOW_UPDATEs.  So add an
internal param to lws_buflist_aware_read() forcing read even if buflist content
is available.
2020-01-20 10:02:56 +00:00
Andy Green
6f8b606811 h2: stream binding: do not try to join existing connection until migrated 2020-01-17 18:54:44 +00:00
Andy Green
774240f73b linkit: support build using public sdk
This provides support to build lws using the linkit 7697 public SDK
from here https://docs.labs.mediatek.com/resource/mt7687-mt7697/en/downloads

This toolchain has some challenges, its int32_t / uint32_t are long,
so assumptions about format strings for those being %u / %d / %x all
break.  This fixes all the cases for the features enabled by the
default cmake settings.
2020-01-17 07:45:34 +00:00
Andy Green
09ba5c6789 freertos: lws_cancel_service udp as pipe
Freertos + lwip doesn't support pipe2() or pipe()... implement a "pipe"
based on two UDP sockets, one listening on 127.0.0.1:54321 and the other
doing a sendto() there of a single byte to interrupt the event loop wait.

Re-use the arrangements for actual pipe fds and pipe role to deliver
lws_cancel_service() functionality using this.
2020-01-15 19:52:41 +00:00
Andy Green
66b2a4a645 tls: apply restriction if any also to client connections 2020-01-15 16:32:48 +00:00
Andy Green
b0b8a684ed event-ops: rename accept member to sock_accept
Some toolchains have lwip accept() as a preprocessor define...
2020-01-15 12:20:50 +00:00
Andy Green
157acfc906 windows: clean type warnings
There are some minor public api type improvements rather than cast everywhere
inside lws and user code to work around them... these changed from int to
size_t

 - lws_buflist_use_segment() return
 - lws_tokenize_t .len and .token_len
 - lws_tokenize_cstr() length
 - lws_get_peer_simple() namelen
 - lws_get_peer_simple_fd() namelen, int fd -> lws_sockfd_type fd
 - lws_write_numeric_address() len
 - lws_sa46_write_numeric_address() len

These changes are typically a NOP for user code
2020-01-11 14:04:50 +00:00
Andy Green
86fe71fdf3 lws_get_random: change length to size_t for coverity 2020-01-11 07:58:37 +00:00
Andy Green
e9c8cee5d5 client: lws_client_reset option to keep ws
With this, ws connection to https://libwebsockets.org/redir-testserver (which redirects to
https://libwebsockets.org/testserver) can work OK.

https://github.com/warmcat/libwebsockets/issues/1820
2020-01-10 11:49:49 +00:00
Jaco Kroon
04ec3d6f73 build options: fix SOCKS5 and WITHOUT_CLIENT
Signed-off-by: Jaco Kroon <jaco@iewc.co.za>
2020-01-08 16:41:52 +00:00
Andy Green
0bfd39135e cleaning 2020-01-05 22:17:58 +00:00
Andy Green
d8ccfc2370 lws_system: helpers for attaching to existing event loop from other threads
In the case code is composed into a single process, but it isn't monolithic in the
sense it's made up of modular "applications" that are written separate projects,
provide a way for the "applications" to request a callback from the lws event loop
thread context safely.

From the callback the applications can set up their operations on the lws event
loop and drop their own thread.

Since it requires system-specific locking to be threadsafe, provide a non-threadsafe
helper and then indirect the actual usage through a user-defined lws_system ops
function pointer that wraps the unsafe api with the system locking to make it safe.
2020-01-05 22:17:58 +00:00
Andy Green
9cb4f25476 h2: LCCSCF_H2_MANUAL_RXFLOW and refactor txcr
This changes the approach of tx credit management to set the
initial stream tx credit window to zero.  This is the only way
with RFC7540 to gain the ability to selectively precisely rx
flow control incoming streams.

At the time the headers are sent, a WINDOW_UPDATE is sent with
the initial tx credit towards us for that specific stream.  By
default, this acts as before with a 256KB window added for both
the stream and the nwsi, and additional window management sent
as stuff is received.

It's now also possible to set a member in the client info
struct and a new option LCCSCF_H2_MANUAL_RXFLOW to precisely
manage both the initial tx credit for a specific stream and
the ongoing rate limit by meting out further tx credit
manually.

Add another minimal example http-client-h2-rxflow demonstrating how
to force a connection's peer's initial budget to transmit to us
and control it during the connection lifetime to restrict the amount
of incoming data we have to buffer.
2020-01-02 08:31:02 +00:00
Andy Green
7221bc57b5 mux children: generalize helpers out of h2 implementation
This should be a NOP for h2 support and only affects internal
apis.  But it lets us reuse the working and reliable h2 mux
arrangements directly in other protocols later, and share code
so building for h2 + new protocols can take advantage of common
mux child handling struct and code.

Break out common mux handling struct into its own type.

Convert all uses of members that used to be in wsi->h2 to wsi->mux

Audit all references to the members and break out generic helpers
for anything that is useful for other mux-capable protocols to
reuse wsi->mux related features.
2019-12-29 19:59:16 +00:00
Andy Green
1eb4d335d2 active_conns: move out dependency on ah 2019-12-23 09:25:56 +00:00
Andy Green
c327c7fdb7 vhost destruction: dont allow all wsi closures to kill vh we are already in process of destroying
Saw this on travis selftests during context destroy

==18895== Invalid read of size 8
==18895==    at 0x415909: __lws_vhost_destroy2 (vhost.c:1063)
==18895==    by 0x40E65B: lws_context_destroy2 (context.c:929)
==18895==    by 0x40EBE5: lws_context_destroy (context.c:1128)
==18895==    by 0x40CC41: main (minimal-http-client-post.c:267)
==18895==  Address 0x6168688 is 728 bytes inside a block of size 792 free'd
==18895==    at 0x4C2BDEC: free (in /usr/lib/valgrind/vgpreload_memcheck-amd64-linux.so)
==18895==    by 0x45B29E: _realloc (alloc.c:120)
==18895==    by 0x45B2D6: lws_realloc (alloc.c:130)
==18895==    by 0x415ED7: __lws_vhost_destroy2 (vhost.c:1204)
==18895==    by 0x419164: lws_vhost_unbind_wsi (wsi.c:82)
==18895==    by 0x41236B: __lws_free_wsi (close.c:154)
==18895==    by 0x4134CF: __lws_close_free_wsi_final (close.c:650)
==18895==    by 0x4133BA: __lws_close_free_wsi (close.c:610)
==18895==    by 0x413528: lws_close_free_wsi (close.c:660)
==18895==    by 0x4158C7: __lws_vhost_destroy2 (vhost.c:1053)
==18895==    by 0x40E65B: lws_context_destroy2 (context.c:929)
==18895==    by 0x40EBE5: lws_context_destroy (context.c:1128)

Removing the last wsi from the vhost we started to destroy finalized the
vhost destruction, which is aimed at libuv async close cleanup.  But if
we already entered __lws_vhost_destroy2, we will definitely destroy the vhost
ourselves at the end of that function already.  So defeat the wsi close
triggering it.
2019-12-22 18:17:45 +00:00
Jerry Jacobs
6879574d8d close.c: close reason length wrong
The string length is actually 25... solve it by measuring the same
string.
2019-12-14 23:55:28 +00:00
Andy Green
392dfe186b LWS_ERRNO: audit uses for case logging may destroy errno
On some platforms, it's possible that logging flow may reset errno.  In the case where
we try to log errno on those platforms and afterwards try to query it, we will get a
nasty surprise that the logged errno is destroyed by the time we come to test it.

In the two cases of this in the tree at the moment, sample errno into a temp and
log and test the temp.

Thanks to Sakthi Ramabadran for finding this.
2019-12-14 23:55:28 +00:00
Andy Green
fb54b590c7 adopt: pass wsi opaque so its set from the start 2019-12-09 14:48:54 +00:00
Andy Green
8c2114a430 minimal-raw-serial
Add a minimal example showing how to set up, send and receive on a
serial tty in the event loop.
2019-12-09 14:48:54 +00:00
Andy Green
2eeec91d3d tls: lws_system per-connection client certs
Now the generic lws_system blobs can cover client certs + key, let's
add support for applying one of the blob sets to a specific client
connection (rather than doing it via the vhost).
2019-12-09 14:48:54 +00:00
Andy Green
cb2b0e88b2 fail paths: deregister notifier and be sure adopt returns NULL
Notifiers may also have scoped lifecycles, support deregister
2019-12-06 17:14:28 +00:00
Andy Green
68de449093 raw: client: make sure we get CONNECT and opaque_user_data before RX 2019-12-02 11:19:32 +00:00
Andy Green
b4449e9f12 semmle: char comparison is actually constrained
It looks to semmle like the int size can be bigger than the char loop var.
But the size is the size of the IPv4 or IPv6 address, so it cannot make
a problem.
2019-12-01 18:04:19 +00:00
Andy Green
092ebf9879 cgi: minimal example 2019-11-20 05:20:59 +00:00
Andy Green
0f7f27801e http redirect: 303: force method to GET
This teaches http client stuff how to handle 303 redirects... these
can happen after POST where the server side wants you to come back with
a GET to the Location: mentioned.

lws client will follow the redirect and force GET, this works for both
h1 and h2.  Client protocol handler has to act differently if it finds
it is connecting for the initial POST or the subsequent GET, it can
find out which by checking a new api lws_http_is_redirected_to_get(wsi)
which returns nonzero if in GET mode.

Minimal example for server form-post has a new --303 switch to enable
this behaviour there and the client post example has additions to
check lws_http_is_redirected_to_get().
2019-11-17 10:47:01 +00:00
Andy Green
285fb9c8ba server vfs: close: cleanup also at just_kill_connection
Also make sure to close the vfs handle on transaction completed as
well as close.
2019-11-16 09:00:15 +00:00
Andy Green
1968edcf44 cgi: reenable h1 with chunking 2019-11-16 09:00:15 +00:00
Andy Green
44585d0fc0 http_proxy: fixes
Eg,

http_proxy=http://127.0.0.1:3128 ./bin/lws-minimal-http-client

works OK on h1 + h2
2019-11-15 08:28:50 +00:00
Andy Green
f01e2e1321 immortal: allow ASYNC_KILL timeout even if immortal 2019-11-05 20:34:29 +00:00
Andy Green
38e43bb51e ws-over-h2: disable validity checking on encapsulated wsi
The h2 nwsi is subject to its own validity checking PINGs,
we don't need to also do them to encapsulated ws-over-h2
2019-11-05 04:53:09 +00:00
Zhiwen Zheng
3299c54130 illumos: fix build errors 2019-11-04 13:49:13 +00:00
Andy Green
08fac7a1f7 unix: sul schedule rename internal api and call regardless of existing timeout
Pre-sul, checking for interval to next pending scheduled event was expensive and
iterative, so the service avoided it if the wait was already 0.

With sul though, the internal "check" function also services ripe events and
removes them, and finding the interval to the next one is really cheap.

Rename the "check" function to __lws_sul_service_ripe() to make it clear it's
not just about returning the interval to the next pending one.  And call it
regardless of if we already decided we are not going to wait in the poll.

After https://github.com/warmcat/libwebsockets/pull/1745
2019-11-01 07:07:33 +00:00
Sun Dro
10bb008dd4 lws_get_tsi
Get thread service index wsi belong to
2019-10-29 09:14:42 +00:00
Zhiwen Zheng
1d618e8793 wsproxy: decrement client rx buflist size at server side tx
https://github.com/warmcat/libwebsockets/issues/1738
2019-10-28 13:20:45 +00:00
Zhiwen Zheng
6cb9f4eb60 wsproxy: send buffered data from head not tail
https://github.com/warmcat/libwebsockets/issues/1737
2019-10-28 13:20:44 +00:00
Andy Green
2f4316527b sul: more paranoid casting vs libc header types
As it is, if time_t is 32-bit on the platform it might lead to
arithmetic overflow, so force it to lws_usec_t (uint64_t) even
though it works OK here on x86_64.

Add a minimal example aimed at testing the wsi hrtimer stability
consistently across platforms.

Add and disable by default hrtimer dump code (this is too expensive
and specific to internal testing to leave in for debug mode even if
it's not printed).  If you hack it enabled, it will dump the sul
list for the pt and assert if the list is disordered.
2019-10-27 06:22:13 +00:00
Kristján Valur Jónsson
f5ccdd1825 windows: clean warnings around int usage
Change all plat instances of lws_plat_setnonblocking() to use lws_sockfd_type
2019-10-23 06:39:35 +01:00
Andy Green
0ff633eb35 lws_sul: always iterate from head of list
The sul callback is allowed to do anything to the sul list, it's
not possible to safely iterate it inbetween calls.

Luckily because it's sorted, we only ever care about the current
head, so switch to iterating it like that.
2019-10-14 10:53:28 +01:00
Andy Green
938f692c48 adopt: improve logging of server adopt fail
This is usually something that either couldn't negotate tls at all
or compatible tls parameters.

Log the vhost it came in on and the IP.
2019-10-14 07:08:57 +01:00
Andy Green
da8995bb61 h2: tolerate unexpected server behaviour
Make sure we only do one SETTINGS ack handling

Fix corner case of ignored header with 0 data being the last in the HEADERS
2019-10-12 12:41:14 +01:00
Andy Green
37ac955fc4 wsi flags: extra encodings 2019-10-12 12:41:14 +01:00
Andy Green
ba8402b43f coverity: use function comments to clear false positives 2019-10-12 12:41:14 +01:00
Andy Green
db760fa164 wsproxy: clear down proxy struct at alloc 2019-10-12 12:41:14 +01:00
Andy Green
3c95483518 adopt: udp iface and AF_PACKET 2019-10-12 12:41:14 +01:00
Andy Green
761207442d cgi: check for stdout failed or gone away 2019-10-12 12:41:14 +01:00
Andy Green
6feb51fd42 h2: ack SETTINGS just the once 2019-10-12 12:41:14 +01:00
Andy Green
b40e19edca h2: end stream with end headers
This shouldn't be necessary; just END_HEADERS flag should be enough.
But nghttp2 will not talk to us unless we end the stream from our side.

Unfortunately ending the stream at the time we sent the headers means
we cannot support the long poll half-close scheme.  So add a quirk
flag to optionally support this behaviour of nghttp2 when the client
is creating the connection.
2019-10-12 12:41:14 +01:00
Andy Green
f4b38f104c LWS_WITH_UDP 2019-10-12 12:41:14 +01:00