Commit graph

95 commits

Author SHA1 Message Date
Michael Meeks
7788bd9268 Avoid taking address over the end of a vector if reading 0 bytes.
Happens with some close frames eg.

[ docbroker_001 ] TRC  #21: Incoming WebSocket data of 6 bytes: 88 80 4a 2c 44 f9  | ..J,D.|

    fin = true
    OpCode is Close (= 0x8)
    hasMask = true
    payloadLen = 0
    headerLen = 2 -> 6 after hasMask is taken into account.

Change-Id: I0e212e4589c3cc63db16f7065dc90cd0bd539ada
2020-01-06 15:34:24 +00:00
Corentin Noël
db67c9239b WebSocketHandler: allow to build on 32bits systems
Change-Id: Id51df359d9c985e72e9186433ce5dcf98e4199a4
Reviewed-on: https://gerrit.libreoffice.org/83492
Reviewed-by: Michael Meeks <michael.meeks@collabora.com>
Tested-by: Michael Meeks <michael.meeks@collabora.com>
2019-11-22 16:23:35 +01:00
Ashod Nakashian
fca12fc1ab wsd: formatting
Change-Id: I07b91c494fe89395ebe1e91506baef46dc03aca8
Reviewed-on: https://gerrit.libreoffice.org/70035
Reviewed-by: Ashod Nakashian <ashnakash@gmail.com>
Tested-by: Ashod Nakashian <ashnakash@gmail.com>
Reviewed-on: https://gerrit.libreoffice.org/71092
2019-08-17 04:27:26 +02:00
Michael Meeks
fc6a316dd4 Improve debugging by showing un-masked websocket content.
Change-Id: I0df0b3cc7b13c36ed8afaaec4ed2fe525458a21c
2019-05-29 15:40:46 +01:00
Miklos Vajna
4e1ed7205d net: avoid UB in WebSocketHandler::readPayload()
Seen when closing a Writer document.

/home/vmiklos/lode/opt_private/gcc-7.3.0/lib/gcc/x86_64-pc-linux-gnu/7.3.0/../../../../include/c++/7.3.0/bits/stl_vector.h:798:9: runtime error: reference binding to null pointer of type 'char'
    #0 0x6ff633 in std::vector<char, std::allocator<char> >::operator[](unsigned long) /home/vmiklos/lode/opt_private/gcc-7.3.0/lib/gcc/x86_64-pc-linux-gnu/7.3.0/../../../../include/c++/7.3.0/bits/stl_vector.h:798:2
    #1 0x770d0c in WebSocketHandler::readPayload(unsigned char*, unsigned long, unsigned char*, std::vector<char, std::allocator<char> >&) /home/vmiklos/lode/dev/online/./net/WebSocketHandler.hpp:611:29
    #2 0x759324 in WebSocketHandler::handleTCPStream(std::shared_ptr<StreamSocket> const&) /home/vmiklos/lode/dev/online/./net/WebSocketHandler.hpp:251:13
    #3 0x6f820d in WebSocketHandler::handleIncomingMessage(SocketDisposition&) /home/vmiklos/lode/dev/online/./net/WebSocketHandler.hpp:419:20
    #4 0xb2da64 in ClientSession::handleIncomingMessage(SocketDisposition&) /home/vmiklos/lode/dev/online/wsd/ClientSession.cpp:74:14
    #5 0xa70a61 in StreamSocket::handlePoll(SocketDisposition&, std::chrono::time_point<std::chrono::_V2::steady_clock, std::chrono::duration<long, std::ratio<1l, 1000000000l> > >, int) /home/vmiklos/lode/dev/online/./net/Socket.hpp:1037:29
    #6 0x6ec83d in SocketPoll::poll(int) /home/vmiklos/lode/dev/online/./net/Socket.hpp:570:34
    #7 0x830019 in DocumentBroker::pollThread() /home/vmiklos/lode/dev/online/wsd/DocumentBroker.cpp:286:16
    #8 0x8fdb38 in DocumentBroker::DocumentBrokerPoll::pollingThread() /home/vmiklos/lode/dev/online/wsd/DocumentBroker.cpp:165:20
    #9 0xe00e75 in SocketPoll::pollingThreadEntry() /home/vmiklos/lode/dev/online/net/Socket.cpp:184:9
    #10 0xe49cfd in void std::__invoke_impl<void, void (SocketPoll::*)(), SocketPoll*>(std::__invoke_memfun_deref, void (SocketPoll::*&&)(), SocketPoll*&&) /home/vmiklos/lode/opt_private/gcc-7.3.0/lib/gcc/x86_64-pc-linux-gnu/7.3.0/../../../../include/c++/7.3.0/bits/invoke.h:73:14
    #11 0xe4980a in std::__invoke_result<void (SocketPoll::*)(), SocketPoll*>::type std::__invoke<void (SocketPoll::*)(), SocketPoll*>(void (SocketPoll::*&&)(), SocketPoll*&&) /home/vmiklos/lode/opt_private/gcc-7.3.0/lib/gcc/x86_64-pc-linux-gnu/7.3.0/../../../../include/c++/7.3.0/bits/invoke.h:95:14
    #12 0xe496bd in decltype(std::__invoke(_S_declval<0ul>(), _S_declval<1ul>())) std:🧵:_Invoker<std::tuple<void (SocketPoll::*)(), SocketPoll*> >::_M_invoke<0ul, 1ul>(std::_Index_tuple<0ul, 1ul>) /home/vmiklos/lode/opt_private/gcc-7.3.0/lib/gcc/x86_64-pc-linux-gnu/7.3.0/../../../../include/c++/7.3.0/thread:234:13
    #13 0xe494c7 in std:🧵:_Invoker<std::tuple<void (SocketPoll::*)(), SocketPoll*> >::operator()() /home/vmiklos/lode/opt_private/gcc-7.3.0/lib/gcc/x86_64-pc-linux-gnu/7.3.0/../../../../include/c++/7.3.0/thread:243:11
    #14 0xe4888a in std:🧵:_State_impl<std:🧵:_Invoker<std::tuple<void (SocketPoll::*)(), SocketPoll*> > >::_M_run() /home/vmiklos/lode/opt_private/gcc-7.3.0/lib/gcc/x86_64-pc-linux-gnu/7.3.0/../../../../include/c++/7.3.0/thread:186:13
    #15 0x7f2c5805fe2e in execute_native_thread_routine /home/vmiklos/lode/packages/gccbuild/x86_64-pc-linux-gnu/libstdc++-v3/src/c++11/../../../../../gcc-7.3.0/libstdc++-v3/src/c++11/thread.cc:83
    #16 0x7f2c57a3c558 in start_thread (/lib64/libpthread.so.0+0x7558)
    #17 0x7f2c5715082e in clone (/lib64/libc.so.6+0xf882e)

SUMMARY: UndefinedBehaviorSanitizer: undefined-behavior /home/vmiklos/lode/opt_private/gcc-7.3.0/lib/gcc/x86_64-pc-linux-gnu/7.3.0/../../../../include/c++/7.3.0/bits/stl_vector.h:798:9 in

Change-Id: Ifaf6b193e9bba480587c2e184df55aa0728bb370
2019-05-27 09:06:38 +02:00
Michael Meeks
9d723cb230 Initial chunked transfer encoding.
Important for convert-to on larger documents and/or with newer curls.

Change-Id: Id18be6d22741a3af7cee39a069c509e4f662977b
2019-05-22 11:07:42 +01:00
Jan Holesovsky
556b2a57e7 gtkapp: Fix clang's error: private field '...' is not used
[-Werror,-Wunused-private-field] in the WaE mode.

Change-Id: I38cce5326023939391b661d077bed4616c88c12b
2019-04-19 11:10:51 +02:00
Gabriel Masei
023cbfc32d Added support for defragmentation of incoming websocket fragmented messages and handled some protocol error cases
Change-Id: I4d11a6527b6b131c65101fd53b71015529645f74
Reviewed-on: https://gerrit.libreoffice.org/68901
Reviewed-by: Michael Meeks <michael.meeks@collabora.com>
Tested-by: Michael Meeks <michael.meeks@collabora.com>
2019-03-12 15:19:42 +01:00
Jan Holesovsky
f76b36193d android: #if(n)def MOBILEAPP -> #if (!)MOBILEAPP for better reliability.
Change-Id: I5f9c9420b6c83601db1c8fdba4ae5a10b17b2107
2019-02-12 12:20:11 +01:00
Tor Lillqvist
ffe66b3efc Avoid 'Unused variable' warnings in the MOBILEAPP casse
Change-Id: I30d631559379da4baa5a73712f002435b1a36360
2018-10-30 22:03:04 +02:00
Tor Lillqvist
8bc97c0f9e Adapt after 4724aa0cf7 2018-10-25 21:33:57 +03:00
Miklos Vajna
4724aa0cf7 Socket: do what the TODO says
Drop the list of friends and just add getters for the relevant
members.
2018-10-25 16:39:02 +02:00
Miklos Vajna
22fac18fcd WebSocket: make members private
All of them were protected, but only _socket was used actually. Add a
protected setter/getter for that field.
2018-10-24 09:36:13 +02:00
Tor Lillqvist
95eb849217 Still more iOS app and related Online C++ code hacking
Re-think the plumbing between the different parts of the C++ Online
code. Do try to have it work more like in real Online on all but the
lowest socket level. Except that we don't have multiple processes, but
threads inside the same process. And instead of using actual system
sockets for WebSocket traffic between the threads, we use our own
FakeSocket things, with no WebSocket framing of messages.

Reduce the amount of #ifdef MOBILEAPP a bit also by compiling in the
UnitFoo things. Hardcode that so that no unit testing is ever
attempted, though. We don't try to dlopen any library.

Corresponding changes in the app Objective-C code. Plus fixes and
functionality improvements.

Now it gets so far that the JavaScript code thinks it has the document
tiles presented, and doesn't crash. But it hangs occasionally. And all
tiles show up blank.

Anyway, progress.

Change-Id: I769497c9a46ddb74984bc7af36d132b7b43895d4
2018-09-19 11:31:18 +03:00
Tor Lillqvist
a4f19ac229 Avoid double "0x" prefix for pointer values in log output
No need for explicit "0x" and std::hex when outputting a pointer. A
pointer will be output as a hex number anyway. We used to have things
like this in the log:

TRC  #25 Connected to WS Handler 0x0x3610b60| ./net/WebSocketHandler.hpp:80
2018-09-19 10:33:41 +03:00
Tor Lillqvist
b59d160a08 Intermediate commit of work in progress on an iOS app
The app is unimaginatively called "Mobile" for now.

Runs but crashes pretty quickly after loading the document by the LO
core. Will need some heavy changes to get a ClientSession object
created in there, too, to handle the (emulated) WebSocket messages
from the JavaScript. It would then handle some of these messages
itself, and forwards some to the ChildSession, which in this case is
in the same process. Now the messsages from the JavaScript go to a
ChildSession, which is wrong. As the assertion says, "Tile traffic
should go through the DocumentBroker-LoKit WS"
2018-09-12 18:32:05 +03:00
Tor Lillqvist
5f779e0295 Revert "Just define these static const int members in-class"
Can't say I understand why, but this turned out to not be a good idea
after all. And no, using constexpr did not work either, so I won't
waste any more time on this triviality, but just revert.

This reverts commit 195b88ac8d.

Change-Id: I49f737dc6a36fa4808841cb8e0335246ad8c6d03
2018-09-11 11:39:56 +03:00
Tor Lillqvist
195b88ac8d Just define these static const int members in-class 2018-09-10 16:10:53 +03:00
Tor Lillqvist
75438baa70 More mobile app stuff, very much early state of work in progress
Re-think Linux vs mobile ifdefs a bit. Use #ifdef __linux only to
surround code that actually is Linux-specific. Use #ifdef MOBILEAPP
for code that is for a mobile version (with no separste wsd, forkit,
and kit processes, and with no WebSocket protocol used).

Bypass UnitFoo for mobile. Possibly we do want the UnitFoo stuff after
all on mobile, to run in some special testing mode? Hard to say, let's
skipt it for now.
2018-09-10 15:13:43 +03:00
Tor Lillqvist
ff31f2dba1 Avoid potential confusion by not using the term "packet" in a comment
It confused at least me for a while into pondering whether the code
thinks TCP is packet-oriented.

Change-Id: I143fc7821abd6b4023d551cdcb42a00e1613e466
2018-07-19 11:39:45 +03:00
Tor Lillqvist
6b96c73f46 Don't log binary data as such, use Util::stringifyHexLine()
Also, log the cases with still incomplete data in the buffer
separately.

Change-Id: Idfa915378c2823dd898789d6a63a0cd71a817b8a
2018-07-19 11:36:11 +03:00
Tor Lillqvist
1e7a56ddc6 Add FIXME: Do we really want to log binary data as such here?
Change-Id: I386d3c377d698f25da5094d87cd82183fc36aee4
2018-07-18 21:16:49 +03:00
Michael Meeks
7e6e81eb46 Implement client websocket masking.
Disable this for easy strace debugging and a bit of perf. to the forkit.

Change-Id: Ia330582817481410d26df50db5eb42b4692ad01c
2018-06-15 14:54:19 +01:00
Jan Holesovsky
93cc4b4548 Use std::shared_ptr consistently.
Change-Id: I6bf3ff7de47010fd78fab26a5a318bde21c1f153
2018-05-18 15:16:40 +02:00
Jan Holesovsky
ca587f4070 The WebSocketHandler::handleClientUpgrade() needs to handle a Response,
not a request.

This commit includes some fixes from Michael Meeks too.

Change-Id: I25198ded9d354a44d7718071394bcccdcabcdd94
2018-05-18 15:16:39 +02:00
Michael Meeks
4cf2ee4fab Get ping/pong handling sorted with more isClient conditionality.
Change-Id: I859ed5b5bcc302304e23ad3554247af920de2421
2018-05-18 15:16:39 +02:00
Michael Meeks
80a13a1e7b More work on client / Monitor websocket connections.
Change-Id: Ic70fe522e24f2b1863c2d9d1dd6941785510758a
2018-05-18 15:16:39 +02:00
Michael Meeks
b483f477dd Allow a 'monitor' to be connected to remotely if configured.
So far monitors have the access an permissions of an
authenticated admin.

Change-Id: I59dfa8a646a60584a5c113ee0521e9afba4f6b76
2018-05-18 15:16:39 +02:00
Miklos Vajna
e5c7c62713 'static const int' needs an explicit definition in C++11
core.git equivalent situation is e.g. SwXMLTableContext::MAX_WIDTH.

Change-Id: Id6f4201e875a7453ab2363161ea9560ae6e40384
2018-02-26 16:34:01 +01:00
Ashod Nakashian
71f4597059 wsd: WebSocket state is a property of the socket
This resolves the erroneous warnings of pinging
on a non-upgraded (i.e. HTTP) socket.

This was due to the fact that we moved the socket
from one SocketHandlerInterface to a WebSocketHandler
after upgrading and since the WSState was a property
of the handler, the WebSocketHandler didn't know
that the socket had already been upgraded.

Also other cosmetics and cleanups.

Change-Id: I1a88edef750117ed551d23245e49380371561422
Reviewed-on: https://gerrit.libreoffice.org/49911
Reviewed-by: Ashod Nakashian <ashnakash@gmail.com>
Tested-by: Ashod Nakashian <ashnakash@gmail.com>
2018-02-23 16:42:22 +01:00
Miklos Vajna
b68bd83f6e net: spell out non-trivial autos to improve readability
Change-Id: I71f080f818e91f1d450cf858ab4aa8a3300308f2
2018-02-07 10:18:12 +01:00
Ashod Nakashian
11cdfb7688 wsd: avoid misleading socket error logs
Change-Id: Ie70d8eb1ecc0442643f4b2a4757b95688b4cf1f7
Reviewed-on: https://gerrit.libreoffice.org/48284
Reviewed-by: Ashod Nakashian <ashnakash@gmail.com>
Tested-by: Ashod Nakashian <ashnakash@gmail.com>
2018-01-22 10:14:17 +01:00
Jan Holesovsky
73d7aee2ac Fix an assert.
Change-Id: I5825a19740c0fa46c6cd14f067d0c1d3927c0c0b
Reviewed-on: https://gerrit.libreoffice.org/46236
Reviewed-by: Jan Holesovsky <kendy@collabora.com>
Tested-by: Jan Holesovsky <kendy@collabora.com>
2017-12-11 15:28:19 +01:00
Jan Holesovsky
343c5bc690 tdf#99744 SaveAs: Extend test to check that the Save As result was sent.
Change-Id: I3788b87d2599c01000af97f496ee2b840c0cae3e
2017-10-26 11:11:38 +02:00
Tor Lillqvist
6b0faf9d97 Avoid warning "this statement may fall through" when intentional
Change-Id: I8d8bcb4747a1933e4ecefe1220a80a355e60317f
2017-10-26 11:38:43 +03:00
Ashod Nakashian
bdd8b715dd wsd: include cleanup
Change-Id: I9f28ee329e318043c31c899d3a07cd3139d838f0
Reviewed-on: https://gerrit.libreoffice.org/37890
Reviewed-by: Ashod Nakashian <ashnakash@gmail.com>
Tested-by: Ashod Nakashian <ashnakash@gmail.com>
2017-05-22 07:04:24 +02:00
Michael Meeks
9e45fb30d7 SocketDisposition: push it down the stack, and cleanup around that.
Dung out overlapping return enumerations. Move more work into 'move'
callbacks at a safer time, etc.

Change-Id: I62ba5a35f12073b7b9c8de4674be9dae519a8aca
2017-05-05 18:37:26 +01:00
Jan Holesovsky
47ca32beb5 We never call setNoDelay() with false.
Change-Id: I865027300559b185222f21faa48ccd32100bd02d
2017-04-19 11:07:55 +02:00
Michael Meeks
f72b7d2ba1 Don't set the buffer size to zero.
This slows things down terribly, particularly the setting on the websocket
made tiles appearing one by one. Let's keep the possibility to zero the buffer
sizes for debugging, but hide that behind an env. variable (and in debug
builds only anyway).

Change-Id: Ie4d2cdb3c0ec3c50f1a2b4f9941a462ac4f2d196
2017-04-19 10:58:18 +02:00
Ashod Nakashian
1262378301 wsd: send document unloading error as WS message
Without an explicit WS message, the client
does not get this message and the handler
is not invoked at all.

Change-Id: I71e210a9958965cff35dd4d0f1d99985429b82f4
Reviewed-on: https://gerrit.libreoffice.org/36593
Reviewed-by: Ashod Nakashian <ashnakash@gmail.com>
Tested-by: Ashod Nakashian <ashnakash@gmail.com>
2017-04-17 06:49:23 +02:00
Ashod Nakashian
0dab4b597d wsd: return the actual number of bytes written to WS
Change-Id: Ib28c432927733ffd437d27dec749d402d25b9024
Reviewed-on: https://gerrit.libreoffice.org/36323
Reviewed-by: Ashod Nakashian <ashnakash@gmail.com>
Tested-by: Ashod Nakashian <ashnakash@gmail.com>
2017-04-10 06:07:59 +02:00
Ashod Nakashian
e00817acf6 wsd: fix pinging and add logs
Apparently pinging was enabled only when
_not_ WebSocket upgraded, which is wrong.

Removed sending ping immediately after
upgrading to WS as it's superfluous.

Change-Id: Ic8103bab063d87f58d371f0eab49f7b7530e2374
Reviewed-on: https://gerrit.libreoffice.org/36322
Reviewed-by: Ashod Nakashian <ashnakash@gmail.com>
Tested-by: Ashod Nakashian <ashnakash@gmail.com>
2017-04-10 06:07:25 +02:00
Jan Holesovsky
cb2b788cc7 assert(isCorrectThread()) -> assertCorrectThread().
assert()'s are no-op in the release builds, but we still want to see threading
problems in the log at least.

Change-Id: Idb02bb018e8f2d628a57ab570249613ad00bcff2
2017-04-05 14:49:30 +02:00
Ashod Nakashian
8932a1e92e wsd: remove LOOL_CHECK_THREADS
isCorrectThread now always checks
with ENABLE_DEBUG.

Change-Id: I2b5747f3ab18c8ebdbc92e7ffc86a2469b8c7d13
Reviewed-on: https://gerrit.libreoffice.org/36038
Reviewed-by: Ashod Nakashian <ashnakash@gmail.com>
Tested-by: Ashod Nakashian <ashnakash@gmail.com>
2017-04-03 05:18:53 +00:00
Ashod Nakashian
95d51493aa wsd: remove nextmessage
This was a workaround to Poco's limitation
of requiring socket receiveFrame be given
preallocated buffer, which couldn't be
exceeded by a larger payload. This meant
the receiver had to know the maximum
payload in advance.

Since only the Kit uses Poco sockets,
and the Kit never receives large payloads,
this preamble is now obsolete.

100% (94/94) of old-style tests PASS.

Change-Id: I76776f89497409e5755e335a3e25553e91cf0876
Reviewed-on: https://gerrit.libreoffice.org/36037
Reviewed-by: Ashod Nakashian <ashnakash@gmail.com>
Tested-by: Ashod Nakashian <ashnakash@gmail.com>
2017-04-03 05:18:09 +00:00
Ashod Nakashian
b52a8ac6e2 wsd: const correctness and avoid unnecessary shared_ptr promotion
Change-Id: I4352d82e7b5c6873837e73ec04d894dce9a716b7
Reviewed-on: https://gerrit.libreoffice.org/36036
Reviewed-by: Ashod Nakashian <ashnakash@gmail.com>
Tested-by: Ashod Nakashian <ashnakash@gmail.com>
2017-04-03 05:16:49 +00:00
Michael Meeks
194c169f68 Remove obsolete write-lock.
The lock was used incompletely & inconsistently, and we should
always and only ever write in the associated SocketPoll's thread.
2017-03-31 14:58:37 +01:00
Ashod Nakashian
30d58f96a4 wsd: avoid unnecessary temp string construction
...when sending text messages over socket and
make return value indicative of success/failure.

Change-Id: Ie4d99103b0d49d238152f7da3155ebcb6ccd4e22
2017-03-29 23:55:19 -04:00
Ashod Nakashian
d77ede8954 wsd: consistent naming sendFrame -> sendMessage
Change-Id: I06c6bb42392a8982a8bb232eee33ece4c8dfc451
2017-03-29 20:03:01 -04:00
Ashod Nakashian
5ae94cc7ec wsd: onConnect takes shared_ptr and better logging
Change-Id: I175dfa1f28444b9bb1f612242ee44b6d0507272c
Reviewed-on: https://gerrit.libreoffice.org/35737
Reviewed-by: Ashod Nakashian <ashnakash@gmail.com>
Tested-by: Ashod Nakashian <ashnakash@gmail.com>
2017-03-27 03:20:22 +00:00