1) This makes lwsws run a parent process with the original permissions.
But this process is only able to respond to SIGHUP, it doesn't do anything
else.
2) You can send this parent process a SIGHUP now to cause it to
- close listening sockets in existing lwsws processes
- mark those processes as to exit when the number of active connections
on the falls to zero
- spawn a fresh child process from scratch, using latest configuration
file content, latest plugins, etc. It can now reopen listening sockets
if it chooses to, or open different listen ports or whatever.
Notes:
1) lws_context_destroy() has been split into two pieces... the reason for
the split is the first part closes the per-vhost protocols, but since
they may have created libuv objects in the per-vhost protocol storage,
these cannot be freed until after the loop has been run.
That's the purpose of the second part of the context destruction,
lws_context_destroy2().
For compatibility, if you are not using libuv, the first part calls the
second part. However if you are using libuv, you must now call the
second part from your own main.c after the first part.
Thanks to Fabrice Gilot for reporting the problem that led to uncovering this.
Due to a misunderstanding of the return value of snprintf (it is not truncated according
to the max size passed in) in several places relying on snprintf to truncate the length
overflows are possible.
This patch wraps snprintf with a new lws_snprintf() which does truncate its length to allow
the buffer limiting scheme to work properly.
All users should update with these fixes.
This adds a new member to the context creation info struct "ws_ping_pong_interval".
If nonzero, it sets the number of seconds that established ws connections are
allowed to be idle before a PING is forced to be sent. If zero (the default) then
tracking of idle connection is disabled for backwards compatibility.
Timeouts cover both the period between decision to send the ping and it being
sent (because it needs the socket to become writeable), and the period between
the ping being sent and the PONG coming back.
INFO debug logs are issues when the timeout stuff is operating.
You can test the server side by running the test server hacked to set ws_ping_pong_interval
and debug log mask of 15. Both the mirror protocol and the server-status protocol are
idle if nothing is happening and will trigger the PING / PONG testing. (You can also
test using lwsws and /etc/lwsws/conf with "ws-pingpong-secs": "20" in the global section)
For client, run the test client with -n -P 20 for 20s interval. -n stops the test client
writing using the mirror protocol, so it will be idle and trigger the PING / PONGs.
The timeout interval may be up to +10s late, as lws checks for affected connections every
10s.
This clears up a couple of issues with client connect.
- if CLIENT_CONNECTION_ERROR is coming, which of the many
ways the rejection may have happened is documented in the
in argument. It's still possible if it just got hung up on
in will be NULL, but now it has MANY more canned strings
describing the issue available at the callback
"getaddrinfo (ipv6) failed"
"unknown address family"
"getaddrinfo (ipv4) failed"
"set socket opts failed"
"insert wsi failed"
"lws_ssl_client_connect1 failed"
"lws_ssl_client_connect2 failed"
"Peer hung up"
"read failed"
"HS: URI missing"
"HS: Redirect code but no Location"
"HS: URI did not parse"
"HS: Redirect failed"
"HS: Server did not return 200"
"HS: OOM"
"HS: disallowed by client filter"
"HS: disallowed at ESTABLISHED"
"HS: ACCEPT missing"
"HS: ws upgrade response not 101"
"HS: UPGRADE missing"
"HS: Upgrade to something other than websocket"
"HS: CONNECTION missing"
"HS: UPGRADE malformed"
"HS: PROTOCOL malformed"
"HS: Cannot match protocol"
"HS: EXT: list too big"
"HS: EXT: failed setting defaults"
"HS: EXT: failed parsing defaults"
"HS: EXT: failed parsing options"
"HS: EXT: Rejects server options"
"HS: EXT: unknown ext"
"HS: Accept hash wrong"
"HS: Rejected by filter cb"
"HS: OOM"
"HS: SO_SNDBUF failed"
"HS: Rejected at CLIENT_ESTABLISHED"
- until now the user code did not get the new wsi that was created
in the client connection action until it returned. However the
client connection action may provoke callbacks like
CLIENT_CONNECTION_ERROR before then, if multiple client connections
are initiated it makes it unknown to user code which one the callback
applies to. The wsi is provided in the callback but it has not yet
returned from the client connect api to give that wsi to the user code.
To solve that there is a new member added to client connect info struct,
pwsi, which lets you pass a pointer to a struct wsi * in the user code
that will get filled in with the new wsi. That happens before any
callbacks could be provoked, and it is updated to NULL if the connect
action fails before returning from the client connect api.
This gives protocols a way to talk to each other via per-vhost callbacks,
one per protocol (including the sender).
Signed-off-by: Andy Green <andy@warmcat.com>
This adds
- simple lws_urlencode()
- simple lws_urldecode()
- simple lws_sql_purify
Those expect the data to all be there and process it up until
the first '\0'.
There is also a larger opaque apis for handling POST_BODY urldecode. To
enable these, you need to give cmake -DLWS_WITH_STATEFUL_URLDECODE=1 (or
arrange any larger feature that relies on it sets that in CMakeLists.txt)
- stateful urldecode with parameter array
These have create / process / destroy semantics on a struct that maintains
decode state.
Stateful urldecode is capable of dealing with large POST data in multiple
POST_BODY callbacks cleanly, eg, file transfer by POST.
Stateful urldecode with parameter array wraps the above with a canned
callback that stores the urldecoded data and indexes them in a pointer
array matching an array of parameter names.
You may also pass it an optional callback when creating it, that will recieve
uploaded file content.
The test html is updated to support both urlencoded and multipart forms,
with some javascript to do clientside validation of an arbitrary 100KB
file size limit (there is no file size limit in the apis).
Signed-off-by: Andy Green <andy@warmcat.com>
Server ipv6 support disable is now controlled by vhost->options rather
than context->options, allowing it to be set per-vhost.
Signed-off-by: Andy Green <andy@warmcat.com>
Adds a convenient way to directly get the value of a URL
argument like ...?x=y&v=1, regardless of position in the
parameter list.
Signed-off-by: Andy Green <andy@warmcat.com>
Valgrind caught http/1.1 pipelining using dead user agent alloc
for logging... NULL it when we free it since the wsi can be
reused with keepalive
==16208== Invalid free() / delete / delete[] / realloc()
==16208== at 0x4847ACC: free (vg_replace_malloc.c:530)
==16208== by 0x4888DC3: _realloc (alloc.c:8)
==16208== by 0x4888DFF: lws_realloc (alloc.c:16)
==16208== by 0x487DBCB: lws_access_log (libwebsockets.c:2352)
==16208== by 0x48956DF: lws_http_transaction_completed (server.c:1245)
==16208== by 0x4893757: lws_http_serve (server.c:340)
==16208== by 0x48946EF: lws_http_action (server.c:748)
==16208== by 0x4894CEF: lws_handshake_server (server.c:900)
==16208== by 0x48786BF: lws_read (handshake.c:120)
==16208== by 0x4896103: lws_server_socket_service (server.c:1580)
==16208== by 0x487FB6B: lws_service_fd_tsi (service.c:779)
==16208== by 0x48803B7: lws_service_fd (service.c:1079)
==16208== Address 0x552e5f8 is 0 bytes inside a block of size 86 free'd
==16208== at 0x4847ACC: free (vg_replace_malloc.c:530)
==16208== by 0x4888DC3: _realloc (alloc.c:8)
==16208== by 0x4888DFF: lws_realloc (alloc.c:16)
==16208== by 0x487DBCB: lws_access_log (libwebsockets.c:2352)
==16208== by 0x48956DF: lws_http_transaction_completed (server.c:1245)
==16208== by 0x4893757: lws_http_serve (server.c:340)
==16208== by 0x48946EF: lws_http_action (server.c:748)
==16208== by 0x4894CEF: lws_handshake_server (server.c:900)
==16208== by 0x48786BF: lws_read (handshake.c:120)
==16208== by 0x4896103: lws_server_socket_service (server.c:1580)
==16208== by 0x487FB6B: lws_service_fd_tsi (service.c:779)
==16208== by 0x48803B7: lws_service_fd (service.c:1079)
==16208== Block was alloc'd at
==16208== at 0x4846498: malloc (vg_replace_malloc.c:298)
==16208== by 0x4848D57: realloc (vg_replace_malloc.c:785)
==16208== by 0x4888DA7: _realloc (alloc.c:6)
==16208== by 0x4888DFF: lws_realloc (alloc.c:16)
==16208== by 0x4893EAF: lws_http_action (server.c:565)
==16208== by 0x4894CEF: lws_handshake_server (server.c:900)
==16208== by 0x48786BF: lws_read (handshake.c:120)
==16208== by 0x4896103: lws_server_socket_service (server.c:1580)
==16208== by 0x487FB6B: lws_service_fd_tsi (service.c:779)
==16208== by 0x48803B7: lws_service_fd (service.c:1079)
==16208== by 0x48994B7: lws_io_cb (libuv.c:101)
==16208== by 0x4AE7B1F: ??? (in /usr/lib/libuv.so.1.0.0)
Signed-off-by: Andy Green <andy@warmcat.com>
Actually lwsws doesn't need his own protocol handler even for http
any more. The default http handler in lws should do everything.
Move the cgi routing into lws default http protocol handler, and
delete lwsws one. Remove all protocols from lwsws so the lws
default one gets used.
With this, and the earlier move of lejp into lws, lwsws itself
becomes 15.5KB of x86_64 (mainly conf parsing).
Signed-off-by: Andy Green <andy@warmcat.com>