Commit graph

844 commits

Author SHA1 Message Date
luigiiucci
78558fe9af Avoid crash when pasting image in debug mode
If COOL is running in debug mode ther is a
check that incoming messages are UTF-8.
We skip this tests if the message refers
to an image pasted.

Signed-off-by: luigiiucci <luigi.iucci@collabora.com>
Change-Id: I4f7e4a647deb22ec2a032d4d6347d910184c0701
2023-07-04 09:57:52 +02:00
Ashod Nakashian
481d3b6842 wsd: http: avoid capturing locals by reference
Fortunately, we have no need for any locals
in this case.

Change-Id: I954953bb2a8c79662152ad4cc2fb5422bc2b0baa
Signed-off-by: Ashod Nakashian <ashod.nakashian@collabora.co.uk>
2023-06-30 21:45:40 +02:00
Ashod Nakashian
5e27d0800b wsd: use STATE_ENUM in SocketDisposition
Change-Id: I914557afdbf8f03856214acf2a64d405b8e0e068
Signed-off-by: Ashod Nakashian <ashod.nakashian@collabora.co.uk>
2023-06-30 21:45:40 +02:00
Ashod Nakashian
56992f0bad wsd: logging
Change-Id: Id82e44f508397affbc828494c766dca7bb97d4dd
Signed-off-by: Ashod Nakashian <ashod.nakashian@collabora.co.uk>
2023-06-30 21:45:40 +02:00
Ashod Nakashian
826451b6cf wsd: http: protect against exceptions from onFinish
Previously, we didn't expect such exceptions,
but increasingly this can happen, as we have
more and more async processing. The main
issue with not catching exceptions is that
we do not properly discard read and
parsed data from the socket. This is a
major issue, of course.

Change-Id: I4490baed7069cd55d103301c1d3be31d9b2d9b2c
Signed-off-by: Ashod Nakashian <ashod.nakashian@collabora.co.uk>
2023-06-30 21:45:40 +02:00
Caolán McNamara
c7c2644b9b fix android ci
github_android_online_co-23.05/net/HttpRequest.hpp:1391:63: error: no matching function for call to 'min'
                      << Util::dumpHex(std::string(data.data(), std::min(data.size(), 256UL))));
                                                                ^~~~~~~~

Signed-off-by: Caolán McNamara <caolan.mcnamara@collabora.com>
Change-Id: I5b81096c696565b9e4eb4f3ca39c16bc1e5b9182
2023-06-26 17:07:35 +01:00
Michael Meeks
1cf561d0ef Restore commit 80b4e6d4ae
Remove un-necessary gating of wakeup() on stop un-related to
callbacks or new sockets.

This reverts commit 25f2581a30.

Change-Id: I9f9f30fed34c973b86206677168071abb81afa6f
Signed-off-by: Michael Meeks <michael.meeks@collabora.com>
2023-06-16 16:08:42 +01:00
Patrick Luby
e381b9194e Implement minor changes suggested during review
Signed-off-by: Patrick Luby <plubius@neooffice.org>
Change-Id: Id25c8a9deec35b9ae74ed1cc8a9dcf88dc5486cc
2023-06-15 19:01:42 +01:00
Patrick Luby
57a9db5664 Replace preprocessor directives with C++ conditional check
UnitBase::isUnitTesting() and UnitWSD::isUnitTesting() to avoid
calling methods that crash on mobile.

Signed-off-by: Patrick Luby <plubius@neooffice.org>
Change-Id: Ie6bc2d238ac9e475b02ceef5809c55acc129dd52
2023-06-15 19:01:42 +01:00
Patrick Luby
12213d7ec5 Fix iOS build breakages by adding http::Request to iOS build
Still needed to add a bunch of #if !MOBILAPP to disable all of the
Online server's unit testing classes so that the iOS app won't crash
when opening a document.

TODO: the iOS app will not accept text input at all. Is some code
unexpectedly consuming message data sent over the mobile fake socket?

Signed-off-by: Patrick Luby <plubius@neooffice.org>
Change-Id: Ie874ee8e452188a7b4cdf6d5f87708e5ed9b0235
2023-06-15 19:01:42 +01:00
Ashod Nakashian
40a915ab4d wsd: thread-safe socket shutdown flag
Change-Id: I1f0b5be698b0e4a1cb55edf65eb706f181cd8516
Signed-off-by: Ashod Nakashian <ashod.nakashian@collabora.co.uk>
2023-06-14 07:04:26 -04:00
Caolán McNamara
2f9c9396d3 cid#318856 Uninitialized scalar field
Signed-off-by: Caolán McNamara <caolan.mcnamara@collabora.com>
Change-Id: I2a6c3e9d021884b898f9efdc51c528428321d6f0
2023-06-14 10:10:46 +02:00
Caolán McNamara
88df33d467 cid#318915 Uninitialized scalar field
Signed-off-by: Caolán McNamara <caolan.mcnamara@collabora.com>
Change-Id: Ia93efc031d6072e97f90136f93dcaff03af934cc
2023-06-14 10:10:46 +02:00
Caolán McNamara
b68634db9a cid#318867 Using a moved object
probably went astray with:

commit 52f2600cf9
Date:   Wed Feb 16 17:22:18 2022 -0500

    wsd: test: embue all tests with a name and unify logs

Signed-off-by: Caolán McNamara <caolan.mcnamara@collabora.com>
Change-Id: Idf4f9bfce7ef188ac15a7cf62baadc3dd5b59dcd
2023-06-14 10:10:46 +02:00
Michael Meeks
25f2581a30 Revert this for now while we think more deeply.
This reverts commit 80b4e6d4ae.
2023-06-09 09:19:36 +01:00
Shehr Bano
80b4e6d4ae Fix: Speed-up callbacks
Signed-off-by: Shehr Bano <shehr.bano@collabora.com>
Change-Id: I796d71e48ae7110fb8d88eda781e362faba75aa2
2023-06-05 13:56:41 +02:00
Ashod Nakashian
756560642f wsd: test: better polling in tests
Shorter waits to break the polling
loop when the test finishes and we
need to terminate.

Change-Id: I79d9d89675d0a37f25a03b265b3ae636a90e57d5
Signed-off-by: Ashod Nakashian <ashod.nakashian@collabora.co.uk>
2023-05-31 07:40:11 -04:00
Ashod Nakashian
155bc06e24 wsd: de-duplicate assertCorrectThread
This merges multiple implementations of
assertCorrectThread and simplifies its
usage.

Change-Id: I7be5dea62c6046fb0412d7f885fcbcc4b66e3fd9
Signed-off-by: Ashod Nakashian <ashod.nakashian@collabora.co.uk>
2023-05-22 09:34:29 -04:00
Ashod Nakashian
685e2fb0b8 wsd: http: return const& from const response getter
Change-Id: I5dc5282938a472148148d1dd6d009261bc09c7d6
Signed-off-by: Ashod Nakashian <ashod.nakashian@collabora.co.uk>
2023-05-22 09:34:29 -04:00
Ashod Nakashian
7ce18c8a13 wsd: http: cosmetic and log
Change-Id: I984ad71601b92b8042dc7984e7339f0804c8083b
Signed-off-by: Ashod Nakashian <ashod.nakashian@collabora.co.uk>
2023-05-22 09:34:29 -04:00
Ashod Nakashian
a6551462e2 wsd: http: improved http::Session::handleIncomingMessage
The normal path is now streamlined and error handling
is at the end. We also now always set the disposition
to closed and fire onDisconnect() when disconnected
or hit an error.

Change-Id: I984ad71601b92b8042dc7984e7339f0804c8083b
Signed-off-by: Ashod Nakashian <ashod.nakashian@collabora.co.uk>
2023-05-15 19:14:21 -04:00
Ashod Nakashian
d4b27f6643 killpoco: replace HTTP status codes
We use our own status codes, which
are type-safe and use streaming
operators to serialize and log.

Change-Id: I0eba7b16694866b5a79476a7ef4b1b78f7f9c176
Signed-off-by: Ashod Nakashian <ashod.nakashian@collabora.co.uk>
2023-05-11 07:21:42 -04:00
Ashod Nakashian
72cff36195 wsd: move streaming operator overloads
This is needed to correct overload
resolution of these operators.

Change-Id: I02c0859674efe112102a8d3833bfb0a30b1a6574
Signed-off-by: Ashod Nakashian <ashod.nakashian@collabora.co.uk>
2023-05-10 08:46:11 -04:00
Ashod Nakashian
0182af7a4a wsd: http: native support for logging http::Header
Change-Id: I8c34531e6f2616d98a4ee75fe8490d4ad25c45a9
Signed-off-by: Ashod Nakashian <ashod.nakashian@collabora.co.uk>
2023-05-10 08:46:11 -04:00
Ashod Nakashian
ff1657934a wsd: simplify log streaming
Change-Id: Id22de0bc06680f957e7475f142bcaf1131fdbdb9
Signed-off-by: Ashod Nakashian <ashod.nakashian@collabora.co.uk>
2023-05-10 08:46:11 -04:00
Ashod Nakashian
b556381406 wsd: return SSL_do_handshake error-codes unmodified
For some reason we only checked for the closed
socket case as failure and returned 0 in that case,
for error cases, we returned 1. Likely the API
had been modified in the early days, but this
return code was left lopsided.

This meant that even when the handshake failed, we
still called readIncomingData or writeOutgoindData,
depending on whether we wanted to read or write,
causing a rare race-condition.

When a client (HTTP request) connects to a server,
it needs to send the request, right after the
SSL handshake. SSL_do_handshake could need data
from the socket to complete the handshake. In such
a case it returns WANT_READ. Unfortunately,
because we always called SSL_read, the missing data
could have arrived between the SSL_do_handshake call
and the SSL_read call (a rather short duration, to
be sure, but an open window all the same).
SSL_read would of course read said data from the
socket and, since it still needs to finish the
handshake, will buffer it. It then returns the very
same error that the SSL_do_handshake returned:
WANT_READ. Of course we will oblige by polling with
POLLIN, which will time out (there is no more data
to come, and the server is waiting for *our* request
and has nothing to send us).

The only way this deadlock could break if
SSL_do_handshake was called (which will consume
the buffered data, return 1 to indicate handshake
has completed). Since we wouldn't call it unless
and until we get POLLIN, per WANT_READ, which won't
happen in this case. And since SSL_read doesn't call
SSL_do_handshake either, the request times out and
that's the end of it.

The fix is to not call SSL_read when the handshake
isn't complete and needs more data, which we do now.

Fortunately, we have very few SSL clients, outside
of unit-tests. Most notably the WOPI client. But
even then it's not a heavily used connection and
might not even be SSL-enabled (for LAN servers).

Change-Id: I04fd3dae151904194f3d7579dbf8c671b2580ffb
Signed-off-by: Ashod Nakashian <ashod.nakashian@collabora.co.uk>
2023-04-15 23:07:38 +01:00
Ashod Nakashian
49843a6af9 wsd: handle read failure on closed socket better
A rare edge-case happens when we have a socket
that is closed (and we get POLLHUP or POLLERR)
but upon reading the socket we get EAGAIN.

This was observed when simulating EAGAIN,
and it is possible that this is quite impossible
in practice (since we read only when we get
POLLIN), but at least for the unit-tests
we need to handle this case, so we don't
get random failures.

Change-Id: I77af1726066507af5d5ada68fe11b479a4e579e5
Signed-off-by: Ashod Nakashian <ashod.nakashian@collabora.co.uk>
2023-04-15 23:07:38 +01:00
Ashod Nakashian
2ea14b5221 wsd: reduce SocketPoll lock contention
We don't have to read the wakeup pipe
under a lock. So we no longer do.

Change-Id: I6bd724b9748add3022b4f9aa2268094b9818f3e5
Signed-off-by: Ashod Nakashian <ashod.nakashian@collabora.co.uk>
2023-04-15 23:07:38 +01:00
Ashod Nakashian
bbabcf52dc wsd: more tracing of socket and poll activity
Change-Id: Ia5cb6cfaf8108a9266b0a1daa55b0fbe1349177c
Signed-off-by: Ashod Nakashian <ashod.nakashian@collabora.co.uk>
2023-04-15 23:07:38 +01:00
Ashod Nakashian
896673c857 wsd: correct log argument order
Change-Id: I00cb3ccd740e8540341e45965cbe8460490acb8c
Signed-off-by: Ashod Nakashian <ashod.nakashian@collabora.co.uk>
2023-04-15 23:07:38 +01:00
Ashod Nakashian
587ba85aea wsd: always handle socket polls without skipping
We now always handle socket polls without skipping
when the number of sockets change. We verify the
socket FD of each socket before handlingPoll to
catch any violations of the preconditions.

This should avoid missing any events and also
handles timeouts better (which are checked
in handlePoll). It also protects against
unexpected modifications of the sockets, with
proper logging and assertion.

Change-Id: I5659eb57231a490e6c813e7a0222443b534713c6
Signed-off-by: Ashod Nakashian <ashod.nakashian@collabora.co.uk>
2023-04-14 18:02:14 +01:00
Ashod Nakashian
8facb429c2 wsd: make removeSockets private
Change-Id: I7171c67bbbe4682cf10e015e600fb25f03d4e5bb
Signed-off-by: Ashod Nakashian <ashod.nakashian@collabora.co.uk>
2023-04-14 18:02:14 +01:00
Ashod Nakashian
4968982a3d wsd: better merge new sockets into poll sockets
Change-Id: I4249ba4d35d8dfb2ff17c63af201276c77e2549b
Signed-off-by: Ashod Nakashian <ashod.nakashian@collabora.co.uk>
2023-04-14 18:02:14 +01:00
Ashod Nakashian
b82519400f wsd: update the poll round-robin index right before usage
Change-Id: I27f19c914449b689a530495681423a2906281698
Signed-off-by: Ashod Nakashian <ashod.nakashian@collabora.co.uk>
2023-04-14 18:02:14 +01:00
Ashod Nakashian
ec85f78458 wsd: drain the wakeup pipe on each read
Reading larger blocks should avoid having
the pipe back up when we accidentally
attempt more wakes than actual ones.

Change-Id: I7766230f60dbf069668ee7919f766e9093df7017
Signed-off-by: Ashod Nakashian <ashod.nakashian@collabora.co.uk>
2023-04-14 18:02:14 +01:00
Ashod Nakashian
7547e15d79 wsd: move pollingThread to private
There is no use-case for calling the
thread function of the SocketPoll
from outside.

Change-Id: Id8e87369494817aaab749d03d1cd4cd3724c2da1
Signed-off-by: Ashod Nakashian <ashod.nakashian@collabora.co.uk>
2023-04-14 11:30:14 +01:00
Ashod Nakashian
75dbe7af53 wsd: better scope locality
Change-Id: I49156505dfb855ce00815c6afabc762951fcc4c8
Signed-off-by: Ashod Nakashian <ashod.nakashian@collabora.co.uk>
2023-04-14 11:30:14 +01:00
Ashod Nakashian
4089302362 wsd: better socket logging
Change-Id: I31b64ce1f174896a3bcfa5cd620e0babd7f425d1
Signed-off-by: Ashod Nakashian <ashod.nakashian@collabora.co.uk>
2023-04-14 11:30:14 +01:00
Ashod Nakashian
3dbfce54d3 wsd: helper to dump the state of an object as a string
Change-Id: Ib49a47be2dc37663ef06ac80be981c9f3c029814
Signed-off-by: Ashod Nakashian <ashod.nakashian@collabora.co.uk>
2023-04-11 08:03:01 -04:00
Ashod Nakashian
f41ba11bad wsd: test: socket context logging
Change-Id: Ib3675985cf0e2d8864ed544d5e7c615d5fde2331
Signed-off-by: Ashod Nakashian <ashod.nakashian@collabora.co.uk>
2023-04-11 08:03:01 -04:00
Ashod Nakashian
bca82f50ee wsd: better logging of the current socket being handled
Change-Id: Ieca96a685f5cfea24fde7251806746408e0bfbf8
Signed-off-by: Ashod Nakashian <ashod.nakashian@collabora.co.uk>
2023-04-11 08:03:01 -04:00
Ashod Nakashian
9596d5a0ab wsd: http: set http::Request log context
Change-Id: Ic8b9c1e7526ebf2f7c69f47f1bd98fdb9fc471ce
Signed-off-by: Ashod Nakashian <ashod.nakashian@collabora.co.uk>
2023-03-14 15:46:48 +01:00
FedericoHeichou
985f284c89 Fix isLocal failing check with IPv4
Signed-off-by: FedericoHeichou <34757141+FedericoHeichou@users.noreply.github.com>
Change-Id: If6fa382102252908dac1fb80199bb332ce400aeb
2023-03-14 10:48:20 +01:00
Ashod Nakashian
9c39ebad1f wsd: string::empty() is clearer than size() == 0
Change-Id: If2e25d344b5718c35cb9ae7b7519010ee88f0f60
Signed-off-by: Ashod Nakashian <ashod.nakashian@collabora.co.uk>
2023-03-10 07:45:12 -05:00
Ashod Nakashian
29193de7cd wsd: improved socket creation/destruction logging
Change-Id: I3f2919b646aad4c7c8b2b464155066008fbe25ae
Signed-off-by: Ashod Nakashian <ashod.nakashian@collabora.co.uk>
2023-03-06 08:43:37 -05:00
Ashod Nakashian
903bb76c36 wsd: fix DEBUG_HTTP in HttpRequest
Change-Id: Iebc61b6632d33528ad362c943cb44cea56418b16
Signed-off-by: Ashod Nakashian <ashod.nakashian@collabora.co.uk>
2023-03-06 08:43:37 -05:00
Ashod Nakashian
e3deb96152 wsd: log the socket FD of http::Response
Change-Id: Ibd02ee6656f4db2e7b09e0b7702a6db55ec8269e
Signed-off-by: Ashod Nakashian <ashod.nakashian@collabora.co.uk>
2023-03-06 08:43:37 -05:00
Ashod Nakashian
8fac85b5c2 wsd: log the socket FD of http::Session
Change-Id: I9c0eb3fde6577185bce63277147a6a453311f1ec
Signed-off-by: Ashod Nakashian <ashod.nakashian@collabora.co.uk>
2023-03-06 08:43:37 -05:00
Ashod Nakashian
359017ef10 wsd: log the socket FD of PrisonerRequestDispatcher
Change-Id: I6a000e53d8baca231a2fb8f6df2251a4f57d9876
Signed-off-by: Ashod Nakashian <ashod.nakashian@collabora.co.uk>
2023-03-06 08:43:37 -05:00
Ashod Nakashian
547c97988a wsd: log the socket FD of WebSocketHandler
Change-Id: I5c06ae44437cac32fb726861a5bc49b149ecd0c4
Signed-off-by: Ashod Nakashian <ashod.nakashian@collabora.co.uk>
2023-03-06 08:43:37 -05:00