Commit graph

274 commits

Author SHA1 Message Date
Andy Green
e99d725e76 ah: reuse at end of transaction has no timeout
If we complete a transaction but end up keeping the ah, we must force
a timeout on it.  Otherwise a bad bot could keep the socket open and
exhaust the ah pool.
2017-08-15 08:06:32 +08:00
lnmx
dc4323f837 send content-type when LWS_WITH_RANGES=OFF
https://github.com/warmcat/libwebsockets/pull/987

With the RANGES feature disabled, lws_serve_http_file would
not add the content-type header to the response.
2017-08-12 20:55:14 +08:00
Leonardo Maccari Rufino
5a473e0dc3 Subject: Support to IPv6 on Windows 2017-06-01 06:57:59 +08:00
Andy Green
a36ca4dc08 logs: reduce ah err to info 2017-04-02 13:02:28 +08:00
Andy Green
42ea3bd703 ext: pmd: improve dealing with partial input usage with drain
https://github.com/warmcat/libwebsockets/issues/841
2017-03-20 19:34:49 +08:00
Andy Green
b4d2ad04bd windows: cannot use fstat 2017-03-17 11:44:47 +08:00
Andy Green
3a09c3b7d6 esp32: align fops member name defines 2017-03-08 11:11:41 +08:00
Andy Green
c53a76f0ef reduce log spew on POST processing 2017-03-08 10:52:49 +08:00
Andy Green
4219a3281d server-name: add_server_header add LWSAHH_FLAG_NO_SERVER_NAME
Also clean up usage of status code defines in lws
2017-03-08 07:51:47 +08:00
Andy Green
205ccedf6e raw: enable server and client raw sockets 2017-03-07 16:06:05 +08:00
Andy Green
19cc7acb24 fops-zip 2017-03-05 15:32:55 +08:00
Per Bothner
60f4569bb8 adopt: allow binding to parent at same time
- if protocol set, allocate own user_space

   If the child wsi wants the parent wsi user_space, it can use

       lws_wsi_user(lws_get_parent(child_wsi))

 - raw file close processing handles parent-child relationship
2017-03-03 07:36:08 +08:00
Andy Green
1ada132932 fops: allow setting from context creation and introduce lws_select_fops_by_vfs_path
1) There's now a .fops pointer that can be set in the context creation info.  If set, the array of
fops it points to (terminated by an entry with .open = NULL) is walked to find out the best vfs filesystem
path match (comparing the vfs path to fops.path_prefix) for which fops to use.

If none given (.fops is NULL in info) then behaviour is as before, fops are the platform-provided one only.

2) The built in fileserving now walks any array of fops looking for the best fops match automatically.

3) lws_plat_file_... apis are renamed to lws_vfs_file_...
2017-03-01 14:59:48 +08:00
Andy Green
be8d791b5e adoption: make union for socket and file fds
This lets lws support adopting raw file FDs and raw socket fds.

A test plugin creates a FIFO and prints data sent on it, using
the lws event loop.
2017-03-01 10:01:53 +08:00
Andy Green
1789d0a483 fops: refactor around lws_fops_fd_t 2017-02-26 08:15:42 +08:00
Andy Green
0aed7a06d5 mbed3: sayonara
The port was technically worthwhile and laid the groundwork for ESP support.

But now it is just useless cruft like mbed3 itself...
2017-02-22 09:50:11 +08:00
Andy Green
297c0313fa raw: adoption and processing 2017-02-21 07:47:35 +08:00
Andy Green
c7c4ae0aa4 ESP32 platform
This is enough for all the test app features to work on ESP32 without
SSL.
2017-02-18 17:27:22 +08:00
Andy Green
186ba832b3 client: allow http[s] to select targeted protocol name in vhost 2017-02-18 17:27:22 +08:00
Per Bothner
baa0f74bf2 gzip fixes 2017-02-18 17:27:22 +08:00
Andy Green
2e11efa84b file_ops: add compression flags and convert open flags to pointer
ihttps://libwebsockets.org/pipermail/libwebsockets/2017-February/003127.html
2017-02-12 18:15:15 +08:00
Andy Green
ce37ee9624 gcc- format strings: debug and extra plugins 2017-02-05 22:30:27 +08:00
Martin Milata
be1f0a3a92 Subject: gcc format strings: Make GCC check format strings, fix found problems 2017-02-05 21:32:30 +08:00
Sven Hoffmann
b5ebd599b2 post processing: fix problem where hex cant straddle block correctly 2017-02-05 21:25:39 +08:00
Tobias
3f55e5e964 ignore leading spaces when checking for a suitable subprotocol
My Browsers send as Subprotocols e.g. chat, superchat, mySubprotocol (with spaces after the ,). Libwebsockets now checked if ' mySubprotocol' was equal to 'mySubprotocol' which failed. With this fix the leading space is ignored and uses 'mySubprotocol' for comparision.
2017-01-17 06:22:58 +08:00
Denis Osvald
9b129c137a server: check listen(2) return value
The `listen` call can fail with EADDRINUSE after bind() succeeds, for
example because another process called listen on that port in the
meantime, or under some circumstances with IPv6-mapped-IPv4. This was
causing EINVAL on accept, with an infinite loop in case of libuv.

A reproducible example was to run nc -l -p 5555 ( OpenBSD netcat (Debian
patchlevel 1)) before starting test-server

Signed-off-by: Denis Osvald <denis.osvald@sartura.hr>
2017-01-03 01:56:20 +08:00
Andy Green
dd0dfaecb7 ESP8266: LWS_POSIX fixes for basic auth and deprecated context 2016-12-22 11:32:34 +08:00
Alan Conway
f3ad9540fa ssl-server: Add CONTEXT_PORT_NO_LISTEN_SERVER
Special port setting to disable listening for a server using socket adoption.
This contrasts with CONTEXT_PORT_NO_LISTEN which does the same for a client.

In particular, server-side SSL is not disabled by CONTEXT_PORT_NO_LISTEN_SERVER
as it is by CONTEXT_PORT_NO_LISTEN.
2016-12-21 09:32:44 +08:00
Alan Conway
acdf0c7066 server: expose lws_adopt_socket_vhost() as public API
Allows a socket to be adopted and associated with an existing vhost.
Also added corresponding  lws_adopt_socket_vhost_readbuf()
2016-12-21 09:32:16 +08:00
Andy Green
be9fb919d1 context deprecation
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.
2016-12-20 14:37:07 +08:00
Andy Green
ed4acef481 RFC7233 HTTP Ranges support for server
This adds a serverside implementation of RFC7233 HTTP ranges.

 - LWS_WITH_RANGES is on by default at cmake

 - Accept-Ranges: bytes is added if LWS_WITH_RANGES is enabled

 - Both single ranges and multipart (2+) ranges are supported

Test with curl like this

Single

$ $ curl -s -r 64-95  http://localhost:7681/libwebsockets.org-logo.png  | hexdump -C
00000000  2e 01 fd 9d 12 27 00 00  00 19 74 45 58 74 53 6f  |.....'....tEXtSo|
00000010  66 74 77 61 72 65 00 77  77 77 2e 69 6e 6b 73 63  |ftware.www.inksc|

Multipart

$ curl -s -r 64-95,128-143  http://localhost:7681/libwebsockets.org-logo.png  | hexdump -C

00000000  5f 6c 77 73 0d 0a 43 6f  6e 74 65 6e 74 2d 54 79  |_lws..Content-Ty|
00000010  70 65 3a 20 69 6d 61 67  65 2f 70 6e 67 0d 0a 43  |pe: image/png..C|
00000020  6f 6e 74 65 6e 74 2d 52  61 6e 67 65 3a 20 62 79  |ontent-Range: by|
00000030  74 65 73 20 36 34 2d 39  35 2f 37 30 32 39 0d 0a  |tes 64-95/7029..|
00000040  0d 0a 2e 01 fd 9d 12 27  00 00 00 19 74 45 58 74  |.......'....tEXt|
00000050  53 6f 66 74 77 61 72 65  00 77 77 77 2e 69 6e 6b  |Software.www.ink|
00000060  73 63 5f 6c 77 73 0d 0a  43 6f 6e 74 65 6e 74 2d  |sc_lws..Content-|
00000070  54 79 70 65 3a 20 69 6d  61 67 65 2f 70 6e 67 0d  |Type: image/png.|
00000080  0a 43 6f 6e 74 65 6e 74  2d 52 61 6e 67 65 3a 20  |.Content-Range: |
00000090  62 79 74 65 73 20 31 32  38 2d 31 34 33 2f 37 30  |bytes 128-143/70|
000000a0  32 39 0d 0a 0d 0a 05 14  50 40 05 15 a5 c4 60 43  |29......P@....`C|
000000b0  91 c4 4a d4 c4 fc 5f 6c  77 73 0d 00              |..J..._lws..|

The corresponding header part is like this

	0x0030:            4854 5450 2f31 2e31 2032 3036      HTTP/1.1.206
	0x0040:  200d 0a73 6572 7665 723a 206c 7773 7773  ...server:.lwsws
	0x0050:  0d0a 636f 6e74 656e 742d 7479 7065 3a20  ..content-type:.
	0x0060:  6d75 6c74 6970 6172 742f 6279 7465 7261  multipart/bytera
	0x0070:  6e67 6573 0d0a 6163 6365 7074 2d72 616e  nges..accept-ran
	0x0080:  6765 733a 2062 7974 6573 0d0a 636f 6e74  ges:.bytes..cont
	0x0090:  656e 742d 6c65 6e67 7468 3a20 3138 380d  ent-length:.188.
	0x00a0:  0a63 6163 6865 2d63 6f6e 7472 6f6c 3a20  .cache-control:.
	0x00b0:  7072 6976 6174 6520 6d61 782d 6167 653a  private.max-age:
	0x00c0:  2036 300d 0a63 6f6e 6e65 6374 696f 6e3a  .60..connection:
	0x00d0:  206b 6565 702d 616c 6976 650d 0a65 7461  .keep-alive..eta
	0x00e0:  673a 2030 3030 3031 4237 3535 3444 3433  g:.00001B7554D43
	0x00f0:  3033 330d 0a0d 0a                        033....
2016-12-20 14:37:07 +08:00
Andy Green
ee94621b40 basic-auth 2016-12-16 22:08:13 +08:00
Bablooos
6e436dca39 vhost: allow adding vhosts after server init
This should allow adding vhosts "late", ie, after the server is up and
running with its initial vhost(s).  The necessary housekeeping is folded
into lws_create_vhost() itself so it should be transparent.

Notice though that at the point the server starts to do service after it
starts initially, if it was requested that the UID / GID change, that
is performed at that point and is not reversible.

So vhosts added "late" find themselves running under the unprivileged
UID / GID from the very start, whereas vhosts added "early" initially
run under the UID / GID the process started with.  If protocols the
vhost uses want to, eg, open privileged files at init and then use
them unprivileged, that will fail if the vhost is added late because
the initial privs are already gone.

AG: also deal with lws_protocol_init() on late vhost init (does the
callbacks for per vh protocol creation), add comments
2016-12-16 22:08:13 +08:00
Andy Green
f2a130f9bf generic-sessions: move auth level check to after mount protocol selection 2016-12-16 22:08:13 +08:00
Iblis Lin
62a86ac9c9 server: portable option for setsockopt
From linux ipv6(7) manual (section `Note`):

        SOL_IP, SOL_IPV6, SOL_ICMPV6 and other SOL_* socket options are
        nonportable variants of IPPROTO_*.  See also ip(7).

Ref: http://man7.org/linux/man-pages/man7/ipv6.7.html
2016-12-16 22:08:13 +08:00
Andy Green
c541e2d7e3 post file upload: dont lose sight of end of upload just because we hit end of incoming post data 2016-12-16 22:08:13 +08:00
Andy Green
3b93e344f6 Add reject service keywords list 2016-10-13 06:32:57 +08:00
Andy Green
6e8f360e58 closing drops any pending ah rx immediately 2016-10-04 18:05:10 +08:00
Andy Green
8187c76943 post form parsing fix retry as new boundary start needed after mismatching boundary
https://github.com/warmcat/libwebsockets/issues/641
2016-10-04 08:26:17 +08:00
Peter Pentchev
fb71b790cd Subject: Fix some typographical and grammatical errors. 2016-10-03 21:31:27 +08:00
Andy Green
f94bef42c4 lws_header_table_reset: make caller responsibility to clear down ah rx buffer
There are two kinds of reaason to call lws_header_table_reset(), one is we are reallocating
a destroyed ah to another wsi, and the other is we are moving to the next pipelined header set
still on the same wsi, and we need a "weaker" reset that only clears down the state related
to the header parsing, not everything about the ah context including the ah rx buffer.

This patch moves the ah rxbuffer rxpos and rxlen resetting out of lws_header_table_reset() and to
be the responsibility of the caller.  Callers who are moving the ah to another wsi are
patched to deal with resetting rxpos and rxlen and lws_http_transaction_completed() who only
resets the ah when moving to the next pipelined headers, no longer wrongly clears the ah rxbuf.

https://github.com/warmcat/libwebsockets/issues/638
2016-09-29 10:31:06 +08:00
Patrick Gansterer
e468e15a2b Add SVG to lws_get_mimetype() 2016-09-23 06:31:24 +08:00
Andy Green
a496700b3a lws_snprintf
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.
2016-09-15 02:22:57 +08:00
Andy Green
c15714f35a handle rx flow control active when consuming payload
https://github.com/warmcat/libwebsockets/issues/622
2016-09-10 04:54:20 +08:00
Andy Green
9c7e84d346 adopt_socket_vhost: error path doesn't remove us from timeout list
As found by "github user 7"

https://github.com/warmcat/libwebsockets/issues/621
2016-09-10 04:54:20 +08:00
Andy Green
01020b60f6 coverity 169273 - off-by-one on cgi chunking swallow limit 2016-08-28 09:44:15 +08:00
Andy Green
e35d91a860 per-vhost headers and lwsws conf support
This l;ets you add per-vhost arbitrary headers on served files, eg

     "headers": [{
        "X-Content-Type-Options": "nosniff",
        "X-XSS-Protection": "1; mode=block",
        "x-frame-options": "SAMEORIGIN"
        }],
2016-08-27 17:07:06 +08:00
Patrick Gansterer
387e50bd8f Allow serving files without known mimetype
RFC2616 only says that any HTTP/1.1 message containing an entity-body
SHOULD include a Content-Type header field defining the media type of
that body.
RFC2119 defines SHOULD as: This word mean that there may exist valid
reasons in particular circumstances to ignore a particular item, but
the full implications must be understood and carefully weighed before
choosing a different course.

AG: this isn't an oversight, it's paranoia about sending out /etc/passwd
or /etc/shadow accidentally.

I agree it should be allowed if people really want to override it.  But
the default should remain like it is I think.

I adapted the patch to allow the extra mimetype "*": "" to be declared on
a mount, as a wildcard match that serves the file without a Content-Type.
2016-08-14 19:28:29 +08:00
Andy Green
3ffd0eb84a server max protocol element 64
https://github.com/warmcat/libwebsockets/issues/601
2016-08-11 05:36:08 +08:00
Andy Green
7acf76cd3d esp8266 initial support 2016-08-10 21:20:23 +08:00