Commit graph

1643 commits

Author SHA1 Message Date
Andy Green
023ac896e9 client: avoid possible NULL deref on error path
https://github.com/warmcat/libwebsockets/issues/672
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
fdddf5af51 clean: usused accidental global wsi
https://github.com/warmcat/libwebsockets/issues/708
2016-12-20 14:37:07 +08:00
Andy Green
ba8fb14e85 token:x-forwarded-for
https://github.com/warmcat/libwebsockets/issues/702
2016-12-20 14:37:07 +08:00
Andy Green
69c88d9f0c context: external_baggage_free_on_destroy
This adds a context creation-time member that points to something
that should be freed when the context is destroyed.

It's in preparation for context deprecation, when a context might
be destroyed asynchronously... a related external with the
lifetime of thee context should also be freed at that time.

Adapt lwsws to use it with the context "strings" (also used for
aligned structs created by the config) allocation.
2016-12-20 14:37:07 +08:00
Andy Green
ee94621b40 basic-auth 2016-12-16 22:08:13 +08:00
Andy Green
7a77c0b572 just finalize startup once 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
Andy Green
39ec84202d ws-server: restrict returned Sec-Websocket-Protocol to the chosen name only
https://libwebsockets.org/pipermail/libwebsockets/2016-November/002948.html

Updated to fix a problem with no protocol

https://github.com/warmcat/libwebsockets/issues/705
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
sjames1958gm
0fdca9f782 client stash: update path variable to larger size 2016-12-16 22:08:13 +08:00
Andy Green
53bed78950 lws_socket_bind: use lws_sockfd_type 2016-12-16 22:08:13 +08:00
Andy Green
2926553c41 client: protect againt losing ah by lws_client_connect_2 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
Joachim Bauch
b3160f9fd0 Added flag to allow expired certificates. 2016-12-16 22:08:13 +08:00
Rainer Poisel
d2cef1515e Better support for MINW32 2016-12-16 22:08:13 +08:00
Yannick Kiekens
e7cc1ffc1e From 7f84bc3e864b52eb13c670362a4b53bc3505393e Mon Sep 17 00:00:00 2001
Subject: [PATCH] Fix typo in lws_create_context documentation
2016-12-16 22:08:13 +08:00
Andy Green
86ab060cd9 client: add lws_http_client_http_response api 2016-12-16 22:08:13 +08:00
Andy Green
fbe66065ff client: treat 304 like 200 2016-12-16 22:08:12 +08:00
Andy Green
b46c401245 alias lws_plat_service_tsi to lws_service_tsi in public api
Via Dosvald

lws_service_tsi() which has been around a while actually just
calls through to lws_plat_service_tsi(), meaning there is no
need to expose both apis.

Rename the internal lws_plat_service_tsi() to _lws_plat_service_tsi()
and replace the api export with a #define to lws_service_tsi for
compatibility's sake.
2016-12-16 22:08:12 +08:00
Andy Green
3b93e344f6 Add reject service keywords list 2016-10-13 06:32:57 +08:00
Andy Green
202e8a7428 adjust_timeout: with default lws_plat_service_tsi allow beings passed 0 timeout
Some people are calling service with zero timeout, taking care of
not busywaiting by some other external arrangements.

Adapt the forced service signalling to survive this.
2016-10-10 20:34:34 +08:00
Joerg Pommnitz
0733610c0e some compilers need void param explicitly 2016-10-10 20:10:39 +08:00
Andy Green
abe0c5e57e docs: explain lws_write handling of truncated sends better 2016-10-08 18:08:03 +08:00
Denis Osvald
4be9a5234d publicly document lws_service_fd timeout servicing
Signed-off-by: Denis Osvald <denis.osvald@sartura.hr>
2016-10-07 17:34:25 +08:00
Andy Green
443b31d012 extpoll: expose forced service apis 2016-10-07 03:19:45 +08:00
Andy Green
4cfe81dfba ubuntu: fix uv detection for lwsws 2016-10-05 14:00:55 +08:00
Andy Green
6e8f360e58 closing drops any pending ah rx immediately 2016-10-04 18:05:10 +08:00
Andy Green
65135f2bc4 port forced service checking from libuv
Related to second part of

https://github.com/warmcat/libwebsockets/issues/638
2016-10-04 08:39:14 +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
939bb7f6e9 Remove the cleanup functions with OpenSSL 1.1.
The thread support in OpenSSL has been rewritten almost completely
and the cleanup functions are now executed automatically.
2016-10-04 08:26:13 +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
Benjamin Ness
668a6fbf29 fix build problem on systems without X509_VERIFY_PARAM type 2016-09-27 05:28:11 +08:00
Patrick Gansterer
e468e15a2b Add SVG to lws_get_mimetype() 2016-09-23 06:31:24 +08:00
Andy Green
0c984014f0 lwsws license to cc0
https://github.com/warmcat/libwebsockets/issues/629
2016-09-19 19:16:47 +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
Fredrik Skogman
316960b87d Added build support for Solaris. 2016-09-09 06:52:42 +08:00
Andy Green
723b3f16fa client http: extra read notification after close
https://github.com/warmcat/libwebsockets/issues/620
2016-09-06 15:36:51 +08:00
Andy Green
64dd359192 windows: WCHAR in lws_plat_inet_ntop needs double the final allocation
https://github.com/warmcat/libwebsockets/issues/619
2016-09-05 15:03:37 +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
d6761e87b5 coverity 169272 - off-by-one possible on CGI buffer limit 2016-08-28 09:44:15 +08:00
Andy Green
d8e051dd97 coverity 169271 - take care about sockfd of -1 on close 2016-08-28 09:44:15 +08:00
Andy Green
2f863cf59a coverity 169269 - dont issue NULL cce 2016-08-28 09:44:15 +08:00
Andy Green
cd02a15669 coverity 169268 + 169270- dead code plus repeat NULL check on error path 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
396b58ce70 Remove unneeded #include <stdint.h>
This fixes the build for Visual Studio 2008.
2016-08-26 18:31:09 +08:00