Commit graph

654 commits

Author SHA1 Message Date
Gleb Popov
742cda8b46 Don't try use abstract unix sockets on !Linux platforms.
Signed-off-by: Gleb Popov <6yearold@gmail.com>
Change-Id: Iaad2159ef2c5a45c52f0c7224d58a8160bb5f260
2021-04-30 20:30:56 +01:00
Gleb Popov
f11ca121a4 Use SOL_LOCAL value instead of 0 in getsockopt() calls.
Signed-off-by: Gleb Popov <6yearold@gmail.com>
Change-Id: I5a58a73541de2a32c5a03ebef5618b1541209d8d
2021-04-30 20:30:56 +01:00
Andras Timar
887ce53417 available, off and end can be unsigned, they are byte positions
this prevents compile error with gcc (Ubuntu 5.4.0-6ubuntu1~16.04.12)
../net/HttpRequest.cpp:340:9: error: assuming signed overflow does not occur when assuming that (X + c) >= X is always true [-Werror=strict-overflow]
         if (off + VersionLen >= available)

Signed-off-by: Andras Timar <andras.timar@collabora.com>
Change-Id: I46df5d43d0997f6a1e61c05a4df7f9d71af65511
2021-04-30 14:30:16 +03:00
Miklos Vajna
656eb310bb Fix Debian 8 / gcc-4.9 warnings
net/HttpRequest.cpp:126:19: error: declaration of 'end' shadows a member of 'this' [-Werror=shadow]

kit/Kit.cpp:163:29: error: missing initializer for member 'statfs::f_bsize' [-Werror=missing-field-initializers]

kit/Kit.cpp:171:14: error: 'OVERLAYFS_SUPER_MAGIC' was not declared in this scope

Signed-off-by: Miklos Vajna <vmiklos@collabora.com>
Change-Id: Ibbd35ab5af3adad403ed22a0aeb70917b9e21970
2021-04-30 10:38:09 +02:00
Michael Meeks
6324864a46 Be more tolerant of clients sending WebSocket pings.
Change-Id: If01a268900d597993abf01d23147faa1260a2ad8
Signed-off-by: Michael Meeks <michael.meeks@collabora.com>
2021-04-28 09:14:07 +01:00
Ashod Nakashian
86aeba7bcf wsd: clarify not-enough-data case while parsing
Change-Id: I790f21a2a4ed4e48da692dcd5202046a488bec45
Signed-off-by: Ashod Nakashian <ashod.nakashian@collabora.co.uk>
(cherry picked from commit 72c24ad5cf6df3e55cdc626fe0780e5bb98d1271)
2021-04-27 17:48:23 -04:00
Ashod Nakashian
2a81c3611e wsd: properly calculate the socket buffer capacity
Change-Id: I11f97734d99291616bf787aa42138405083c3537
Signed-off-by: Ashod Nakashian <ashod.nakashian@collabora.co.uk>
(cherry picked from commit 92c6513c1fbdce3d66945ef2cd0784659d4142c9)
2021-04-27 17:48:23 -04:00
Ashod Nakashian
352840c0ea wsd: http: larger 64kb upload-file read buffer
Change-Id: Ie9a0e6f76425d796979dbc77eecf1b05993b834d
Signed-off-by: Ashod Nakashian <ashod.nakashian@collabora.co.uk>
(cherry picked from commit 34f629c6adc5bb6eb93fd8c813d72ee923d09a05)
2021-04-27 17:48:23 -04:00
Ashod Nakashian
3decba7eec wsd: specify the minimum bytes we can write to the socket
When writing to the socket, it's always more efficient
to fill the buffer up to the hardware limit for each
write. This is doubly important for efficiency with
SSL, due to the overhead of encrypting multiple
small buffers instead of one large one.

Currently we don't write more than one message
at a time, primarily due to limitations in
the Poco sockets in the unit-tests, which
have a hard time consuming multiple WS frames
with a single poll (subsequent calls to poll
doesn't enter signalled state until new data
arrives, possibly because the data is read and
buffered internally, making the whole scheme
of using poll unreliable and meaningless).

Change-Id: Ic2e2cf1babfb5ab4116efd93f392977ba234d92b
Signed-off-by: Ashod Nakashian <ashod.nakashian@collabora.co.uk>
2021-04-27 17:48:23 -04:00
Ashod Nakashian
26be3a2a2f wsd: perform socket writes more efficiently
Since it's most efficent to send full blocks at
once (especially so when SSL encryption is done),
we now perform write when the buffer has fewer
than the send-buffer-size bytes. Previously,
we were only getting more data to write to the
socket when the buffer was completely empty,
potentially wasting valuable opportunity to
write more data to the socket while we're at it.

Change-Id: I69a18a042dc2e551ebc5e1af40dae091da3f3d13
Signed-off-by: Ashod Nakashian <ashod.nakashian@collabora.co.uk>
2021-04-27 17:48:23 -04:00
Ashod Nakashian
55309e128d wsd: notify outside the lock
Change-Id: I4b1c693dc561221161768ff0ddc0da5a23d512f2
Signed-off-by: Ashod Nakashian <ashod.nakashian@collabora.co.uk>
2021-04-27 08:09:49 -04:00
Ashod Nakashian
b47c81e7a8 wsd: improved WebSocketSession interface
SocketPoll is captured as weak_ptr into
WebSocketSession and a much better shutdown
support is now available. The new logic
can do async-shutdown after flushing and
will do sync-shutdown if SocketPoll is
no longer around.

Change-Id: Ia206cab58a13f20f7aeb3a6d8c57afee731c8231
Signed-off-by: Ashod Nakashian <ashod.nakashian@collabora.co.uk>
2021-04-27 08:09:49 -04:00
Ashod Nakashian
eeda9adb29 wsd: read can return 0 from the socket
Change-Id: If74a46a8649ee422ed12a2e247d316451fc9cd75
Signed-off-by: Ashod Nakashian <ashod.nakashian@collabora.co.uk>
2021-04-27 08:09:49 -04:00
Ashod Nakashian
bc38af30dc wsd: safer asyncShutdown in WebSocketSession
Change-Id: I3108a10be7691ed532301dcd42b659bdeb553473
Signed-off-by: Ashod Nakashian <ashod.nakashian@collabora.co.uk>
2021-04-27 08:09:49 -04:00
Miklos Vajna
a5566baa03 Add version of std::atoi() that needs no extra allocation
std::atoi() assumes a null-terminated string and our strings are not
always null-terminated. So add a version that takes a length parameter,
this way we don't have to copy strings around.

Also switch to this in http::StatusLine::parse().

Signed-off-by: Miklos Vajna <vmiklos@collabora.com>
Change-Id: I449b356c1b9948c562434618596e8e3b38656088
2021-04-26 16:22:27 +02:00
Miklos Vajna
9afe974848 Add a fuzzer for http::Response::readData()
And remove the httpheader one, which is not useful, since it uses Poco
for the actual parsing, it did not find anything. (If we switch away
from Poco there in the future, it's easy enough to restore it.)

Also fix some problems found by the fuzzer.

Signed-off-by: Miklos Vajna <vmiklos@collabora.com>
Change-Id: I254247c46ecc78c9c3e75aac4f10c441b0e10fb3
2021-04-23 17:54:36 +02:00
Michael Meeks
e26fac4665 Use the accepted socket, not the listening one.
Change-Id: Iecaa90f4c3030b5b2e20bb0e33ef9b75717bb578
Signed-off-by: Michael Meeks <michael.meeks@collabora.com>
2021-04-23 16:36:38 +01:00
Miklos Vajna
1195e07d15 StatusLine::parse: limit size of allocated string
Signed-off-by: Miklos Vajna <vmiklos@collabora.com>
Change-Id: Idba8ad8a8905b0d03e2015de5df5c7c7f145ffc5
2021-04-23 15:32:21 +02:00
Miklos Vajna
da11acd8c5 StatusLine::parse: handle non-null-terminated buffer with std::atoi()
Signed-off-by: Miklos Vajna <vmiklos@collabora.com>
Change-Id: I51033bc4d3f97f5ae93abce1b5f19ef6a8b296d8
2021-04-23 15:32:21 +02:00
Miklos Vajna
415a834813 StatusLine::parse: only feed integers to std::atoi()
Signed-off-by: Miklos Vajna <vmiklos@collabora.com>
Change-Id: I7591fd14fbdc7c1210ac8141cb78854e3f20fffd
2021-04-23 15:32:21 +02:00
Miklos Vajna
80c6562e59 Add a fuzzer for http::StatusLine::parse()
And fix an unhandled std::length_error it found.

Signed-off-by: Miklos Vajna <vmiklos@collabora.com>
Change-Id: I571cdd71caeda84820f2c64088966936637ce2bf
2021-04-23 09:02:21 +02:00
Ashod Nakashian
be17696903 wsd: log the buffer size in WebSocketHandler::sendFrame
Change-Id: Ifb8121d9e27c9d6159af3578852e44c35b6f6e0c
Signed-off-by: Ashod Nakashian <ashod.nakashian@collabora.co.uk>
2021-04-12 09:06:38 -04:00
Ashod Nakashian
0bf5f97b15 wsd: override getPollEvents in WebSocketSession
Change-Id: I3f59e60f74830998739ae03ff1979a784b9cc8fe
Signed-off-by: Ashod Nakashian <ashod.nakashian@collabora.co.uk>
2021-04-12 09:06:38 -04:00
Ashod Nakashian
0fb4cd8bb7 wsd: trap disconnection in WebSocketSession
Change-Id: I519a24d72c3eb8e249450e9a49def077ecf0dc10
Signed-off-by: Ashod Nakashian <ashod.nakashian@collabora.co.uk>
2021-04-11 18:43:36 -04:00
Ashod Nakashian
60344a0052 wsd: support asyncronous shutdown of WebSocketSession
Change-Id: I4c50c718388ae8c790d2e2bb1e3d4db93e92aee5
Signed-off-by: Ashod Nakashian <ashod.nakashian@collabora.co.uk>
2021-04-11 18:43:36 -04:00
Ashod Nakashian
7b28fe2d41 wsd: improved WebSocketSession
Change-Id: If3c92b59ae6303079bd544e29cb995ac3e0d6742
Signed-off-by: Ashod Nakashian <ashod.nakashian@collabora.co.uk>
2021-04-11 18:43:36 -04:00
Ashod Nakashian
ce99632081 wsd: std::move better than copy-from-ref
Change-Id: I7062ed9adf71099b3c54cbbb9784a582bde23715
Signed-off-by: Ashod Nakashian <ashod.nakashian@collabora.co.uk>
2021-04-11 18:43:36 -04:00
Ashod Nakashian
2c21fce9fe wsd: use Socket::eraseFirstInputBytes for a cleaner interface
Change-Id: Ife2a740cdc79f1c908e111ba3572b4e0777054b9
Signed-off-by: Ashod Nakashian <ashod.nakashian@collabora.co.uk>
2021-04-11 18:43:36 -04:00
Ashod Nakashian
b35a269378 wsd: always include port in the Host header
Change-Id: Iab7680462eac68cf9c4fc1dde6be19e3985bd580
Signed-off-by: Ashod Nakashian <ashod.nakashian@collabora.co.uk>
2021-04-11 18:43:36 -04:00
Ashod Nakashian
bd67b25872 wsd: SocketPoll::poll overloaded for deadline time
This makes it simpler to call poll repeatedly
within a given timeout, by first calculating
the deadline and passing it to poll to handle
the math.

Change-Id: I7a9311286ec368c853de40f10523b7b98c8f8106
Signed-off-by: Ashod Nakashian <ashod.nakashian@collabora.co.uk>
2021-04-11 01:05:20 -04:00
Ashod Nakashian
374f278228 wsd: WebSocketSession isSecure() -> secure()
Change-Id: I3d15414e0527b6651f5e8bce172e15e646003144
Signed-off-by: Ashod Nakashian <ashod.nakashian@collabora.co.uk>
2021-04-11 01:05:20 -04:00
Ashod Nakashian
d6e2e641a2 wsd: make single-argument ctor explicit
Change-Id: I0adb3f73a92bbe5dedcf3d2c67b2935c13af5de0
Signed-off-by: Ashod Nakashian <ashod.nakashian@collabora.co.uk>
2021-04-11 01:05:20 -04:00
Ashod Nakashian
09f0554891 wsd: http: WebSocketSession supports flexible message polling
Change-Id: Ic8b54e08fdeae4af1713931d96bbe2cd27ee9f4d
Signed-off-by: Ashod Nakashian <ashod.nakashian@collabora.co.uk>
2021-04-11 01:05:20 -04:00
Ashod Nakashian
4ca35edd8c wsd: log the context in WebSocket Session logs
Useful for debugging, especially for unit-tests.

Change-Id: I820e584203a643a396d26c8817b9af1e750232c7
Signed-off-by: Ashod Nakashian <ashod.nakashian@collabora.co.uk>
2021-04-11 01:05:20 -04:00
Ashod Nakashian
fecf32d872 wsd: test: use WebSocketSession::create in unit test
Change-Id: Ib4aecd163237220f80ff9e169c4a463ef2c08983
Signed-off-by: Ashod Nakashian <ashod.nakashian@collabora.co.uk>
2021-04-11 01:05:20 -04:00
Ashod Nakashian
eb2424feb9 wsd: WebSocketSession create helper and shutdown member
Change-Id: I1cdf3f4f763a66972c9c84cec6a80f380ebcc2db
Signed-off-by: Ashod Nakashian <ashod.nakashian@collabora.co.uk>
2021-04-11 01:05:20 -04:00
Ashod Nakashian
ec18cefae8 wsd: http: reuse parseUri
Change-Id: Ia54c767e8f63cca9990b54f49ce6ef5a47397496
Signed-off-by: Ashod Nakashian <ashod.nakashian@collabora.co.uk>
2021-04-11 01:05:20 -04:00
Ashod Nakashian
4f05d69815 wsd: use http::Request for internal WS and simplify
Also, enable validation of WebSocket keys.

Change-Id: I226607b18a14d023bc9c55762580fd1cb47493f9
Signed-off-by: Ashod Nakashian <ashod.nakashian@collabora.co.uk>
2021-04-11 01:05:20 -04:00
Ashod Nakashian
2e4524ad57 wsd: use WebSocketHandler instead of explicit WebSocket request
Now that the WebSocket functionality is available in
WebSocketHandler, we can cleanup Socket.

Change-Id: Ia3703ab5a2f00fb835eb80493bc400a91dabefad
Signed-off-by: Ashod Nakashian <ashod.nakashian@collabora.co.uk>
2021-04-11 01:05:20 -04:00
Ashod Nakashian
7587ebd84f wsd: http: move WebSocket creation into Request
Change-Id: Idb8251fc07d35a996673f91fcb14d5fd9835a414
Signed-off-by: Ashod Nakashian <ashod.nakashian@collabora.co.uk>
2021-04-11 01:05:20 -04:00
Ashod Nakashian
1239685620 wsd: http: explicit Request constructor and Header arg
Change-Id: Ief228862d882ae96650708e30442693cc127f0c9
Signed-off-by: Ashod Nakashian <ashod.nakashian@collabora.co.uk>
2021-04-11 01:05:20 -04:00
Ashod Nakashian
1190e7f2e0 wsd: improved WebSocket support
Change-Id: Ic1b9464819f5a91df46243c376237d064beeace4
Signed-off-by: Ashod Nakashian <ashod.nakashian@collabora.co.uk>
2021-04-11 01:05:20 -04:00
Ashod Nakashian
7b2a0da05b wsd: WebSocketSession handshake and wait for message
With improved test.

Change-Id: I137a35195a81a4d2fbf530be3805e5350cb78644
Signed-off-by: Ashod Nakashian <ashod.nakashian@collabora.co.uk>
2021-04-11 01:05:20 -04:00
Ashod Nakashian
e8705abc96 wsd: new WebSocketSession to createa a WebSocket connection
A utility class to create a WebSocket connection based
on WebSocketHandler, http::Request, and SocketPoll.

Change-Id: I00dfd6fc88e210860e0e378587ef1c0a0a65bb5c
Signed-off-by: Ashod Nakashian <ashod.nakashian@collabora.co.uk>
2021-04-11 01:05:20 -04:00
Ashod Nakashian
54f80741e2 wsd: http: handle client-side WebSocket upgrade
This adds support to Web-Socket upgrade handshake
validation. We never had a proper client-side
Web-Socket, so never needed this.

Change-Id: If4b8e42daeab13a430179128750f6a4f17452f28
Signed-off-by: Ashod Nakashian <ashod.nakashian@collabora.co.uk>
2021-04-11 01:05:20 -04:00
Ashod Nakashian
0624df1da4 wsd: restrict WebSocketHandler members
This simply reduces the public surface area
of the WebSocketHandler class.

Change-Id: I93be58923f429bceab74a9e239ad0fad11390449
Signed-off-by: Ashod Nakashian <ashod.nakashian@collabora.co.uk>
2021-04-11 01:05:20 -04:00
Ashod Nakashian
b12a4105fb wsd: WebSocketHandler fully supports http::Request
Change-Id: Ia5ff17e9aa8cbaded4e304be8c673b8f1575b6ce
Signed-off-by: Ashod Nakashian <ashod.nakashian@collabora.co.uk>
2021-04-11 01:05:20 -04:00
Ashod Nakashian
813c0747f9 wsd: WebSocketHandler accepts http::Request in addition to Poco
Change-Id: I46fe2f85938284c2a3857a058ce61514354e796b
Signed-off-by: Ashod Nakashian <ashod.nakashian@collabora.co.uk>
2021-04-11 01:05:20 -04:00
Ashod Nakashian
b2a7843dc3 wsd: use http::Response in WebSocketHandler 101 responses
Change-Id: Ica3c7950360b62c0927d8a75d813846b301b7403
Signed-off-by: Ashod Nakashian <ashod.nakashian@collabora.co.uk>
2021-04-11 01:05:20 -04:00
Ashod Nakashian
bc7b36e904 wsd: log the inBuffer size not the outBuffer
Change-Id: Id8f75576bbf44d881338cd03b2ae7f30f4d092ba
Signed-off-by: Ashod Nakashian <ashod.nakashian@collabora.co.uk>
2021-04-07 11:36:10 -04:00