Commit graph

51 commits

Author SHA1 Message Date
Michael Meeks
e924625cc1 re-factor: Socket / WebSocketHandler.
Essentially we want to be able to separate low-level socket code
for eg. TCP vs. UDS, from Protocol handling: eg. WebSocketHandler
and client sessions themselves which handle and send messages
which now implement the simple MessageHandlerInterface.

Some helpful renaming too:

s/SocketHandlerInterface/ProtocolHandlerInterface/

Change-Id: I58092b5e0b5792fda47498fb2c875851eada461d
Reviewed-on: https://gerrit.libreoffice.org/c/online/+/90138
Tested-by: Jenkins CollaboraOffice <jenkinscollaboraoffice@gmail.com>
Reviewed-by: Michael Meeks <michael.meeks@collabora.com>
2020-03-11 16:48:03 +01:00
Michael Meeks
019f268ffd handleDisconnect - unused.
Change-Id: Ib305f762ae33424c8a598d5c31eeda31b9c87555
Reviewed-on: https://gerrit.libreoffice.org/c/online/+/90137
Tested-by: Jenkins CollaboraOffice <jenkinscollaboraoffice@gmail.com>
Reviewed-by: Michael Meeks <michael.meeks@collabora.com>
2020-03-07 11:28:08 +01:00
Michael Meeks
f70e627795 WebSocket - simplify handleMessage for now.
WebSocketHandler handles this complexity for us now, and for the
forseeable future. Simplify to prepare for larger re-factor.

Change-Id: I73b919885adc358cb6502a13492cdac85c34459c
Reviewed-on: https://gerrit.libreoffice.org/c/online/+/90059
Tested-by: Jenkins CollaboraOffice <jenkinscollaboraoffice@gmail.com>
Reviewed-by: Michael Meeks <michael.meeks@collabora.com>
2020-03-05 20:28:48 +01:00
Miklos Vajna
547f9ea731 Rework StringVector to have a single underlying string
This is meant to reduce lots of small allocations and instead have
pointers into the single string for the various tokens instead.

This has a few requirements, though:

1) It's no longer OK to modify the tokens, changing their length would
invalidate the start/length of other tokens. Rework
DocumentBroker::load() to avoid such mutation.

2) The iterators no longer expose zero-terminated strings, so
Poco::cat() doesn't work anymore: add an own cat() instead and use that
in e.g. ChildSession. The own cat() has the benefit that it won't read
past the end of the array if the begin index is out of bounds to add
more safety.

(This nicely works towards killing Poco usage in general.)

3) If zero-terminated strings for all individual tokens is needed, a
copy has to be made, as done in spawnProcess().

(For all of these requirements, the build fails if there are problems.)

Change-Id: Iea40e4400e630b2d669f5c72aea85cb40edf9a2c
Reviewed-on: https://gerrit.libreoffice.org/c/online/+/89711
Reviewed-by: Michael Meeks <michael.meeks@collabora.com>
Tested-by: Jenkins CollaboraOffice <jenkinscollaboraoffice@gmail.com>
2020-02-28 18:31:37 +01:00
Miklos Vajna
b8bd1990aa Rework LOOLProtocol::tokenize() to return a StringVector object
The bulk of this commit just changes std::vector<std::string> to
StringVector when we deal with tokens from a websocket message.

The less boring part of it is the new StringVector class, which is a
wrapper around std::vector<std::string>, and provides the same API,
except that operator[] returns a string, not a string&, and this allows
returning an empty string in case that prevents reading past the end of
the underlying array.

This means in case client code forgets to check size() before invoking
operator[], we don't crash. (See the ~3 previous commits which fixed
such crashes.)

Later the ctor could be changed to take a single underlying string to
avoid lots of tiny allocations, that's not yet done in this commit.

Change-Id: I8a6082143a8ac0b65824f574b32104d7889c184f
Reviewed-on: https://gerrit.libreoffice.org/c/online/+/89687
Tested-by: Jenkins CollaboraOffice <jenkinscollaboraoffice@gmail.com>
Reviewed-by: Miklos Vajna <vmiklos@collabora.com>
2020-02-28 16:07:56 +01:00
Miklos Vajna
57a35bb96c Add an initial libfuzzer based fuzzer
- target ClientSession::_handleInput(), since crashing there would bring
  down the whole loolwsd (not just a kit process), and it deals with
  input from untrusted users (browsers)

- add a --enable-fuzzers configure switch to build with
  -fsanitize=fuzzer (compared to normal sanitizers build, this is the only
  special flag needed)

- configuring other sanitizers is not done automatically, either use
  --with-sanitizer=... or the environment variables from LODE's sanitizer
  config

- run the actual fuzzer like this:

  ./clientsession_fuzzer -max_len=16384 fuzzer/data/

- note that at least openSUSE Leap 15.1 sadly ships with a clang with
  libfuzzer static libs removed from the package, so you need a
  self-built clang to run the fuzzer (either manual build or one from
  LODE)

- <https://chromium.googlesource.com/chromium/src/testing/libfuzzer/+/refs/heads/master/efficient_fuzzing.md#execution-speed>
  suggests that "You should aim for at least 1,000 exec/s from your fuzz
  target locally" (i.e. one run should not take more than 1 ms), so try
  this minimal approach first. The alternative would be to start from the
  existing loolwsd_fuzzer binary, then step by step cut it down to not
  fork(), not do any network traffic, etc -- till it's fast enough that
  the fuzzer can find interesting input

- the various configurations start to be really complex (the matrix is
  just very large), so try to use Util::isFuzzing() for fuzzer-specific
  changes (this is what core.git does as well), and only resort to ifdefs
  for the Util::isFuzzing() itself

Change-Id: I72dc1193b34c93eacb5d8e39cef42387d42bd72f
Reviewed-on: https://gerrit.libreoffice.org/c/online/+/89226
Tested-by: Jenkins CollaboraOffice <jenkinscollaboraoffice@gmail.com>
Reviewed-by: Michael Meeks <michael.meeks@collabora.com>
2020-02-22 12:18:22 +01:00
Michael Meeks
9cef0f385d watermarking: create SessionMap template to canonicalize views.
Use a fully reliable uniqueness check, rather than a hash, and get
simpler ids as a bonus. Fetch view data from the session itself
rather than passing it in too.

Change-Id: Ibcd625156b5a98eb280e35d6537b5c8c026d0197
Reviewed-on: https://gerrit.libreoffice.org/c/online/+/86150
Reviewed-by: Mert Tümer <mert.tumer@collabora.com>
Tested-by: Mert Tümer <mert.tumer@collabora.com>
2020-01-06 13:52:29 +01:00
Miklos Vajna
204cff5c19 Avoid UB in Session::setHash()
Ubsan says that signed integer overflow is happening here:

    #0 0xec344a in Session::setHash(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&) common/Session.cpp:267:17
    #1 0x918b54 in DocumentBroker::load(std::shared_ptr<ClientSession> const&, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&) wsd/DocumentBroker.cpp:682:18
...
SUMMARY: UndefinedBehaviorSanitizer: undefined-behavior common/Session.cpp:267:17 in

(While running unit_wopi_watermark.)

Change-Id: Idcb1692f6d5d0df8be35dc557d2d72a345acbcf4
2019-11-22 14:11:00 +01:00
Jan Holesovsky
efa293290c killpoco: Remove trivial StringTokenizer uses from some files.
Particularly those used on Android...

Change-Id: I47bf9692f5e99ba30140d698558472201168a198
Reviewed-on: https://gerrit.libreoffice.org/82302
Reviewed-by: Jan Holesovsky <kendy@collabora.com>
Tested-by: Jan Holesovsky <kendy@collabora.com>
2019-11-08 22:21:31 +01:00
mert
86489d3dcd Include normalizedViewId to TileCache
Change-Id: Ib23afa023d79189f7fd7aca8b5b0e198c3011fbc
2019-10-15 18:13:03 +03:00
Ashod Nakashian
36b5109d21 wsd: cosmetic formatting
Change-Id: I552b2468432ce6ed52c50e22b6f19d8055c5dbb1
2019-09-03 01:53:12 -04:00
Michael Meeks
f384b8a414 Add watermark opacity setting.
Change-Id: I839e8aef91acfed40d4afd8c1b50176ed54c670a
2019-08-26 16:29:12 -04:00
Henry Castro
760864870f wsd: introduce "TemplateSource" WOPI property
Change-Id: I9df1d5d0d4be7fe10ee15c40c36195c86ccf857e
Reviewed-on: https://gerrit.libreoffice.org/76190
Tested-by: Jenkins CollaboraOffice <jenkinscollaboraoffice@gmail.com>
Reviewed-by: Jan Holesovsky <kendy@collabora.com>
2019-07-24 12:10:15 +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
Ashod Nakashian
4587dde56f wsd: anonymize filename by using the WOPI file ID
Reviewed-on: https://gerrit.libreoffice.org/57254
Reviewed-by: Jan Holesovsky <kendy@collabora.com>
Tested-by: Jan Holesovsky <kendy@collabora.com>
(cherry picked from commit 5e3568ff1029da948f05d1c0e0c56c6d0706690e)

Change-Id: I869cae3846c8630b192246bc68cc90e70c50d1fd
2018-10-16 20:12:23 -04:00
Ashod Nakashian
f25575181c kit: parse anonymized tokens in doc options
Also optimize the parsing in general.

Change-Id: Id1f5b5c12e867c98e523d1e32397853d7d4a6ee4
2018-10-16 20:12:23 -04: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
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
Miklos Vajna
9eacfe4fcb common: spell out non-trivial autos to improve readability
Change-Id: Id13bc0e48cec845f5b05171128be5b4efc05c6bc
2018-02-07 10:18:12 +01:00
Tor Lillqvist
e834526983 Add FIXME 2018-01-15 14:22:56 +02:00
Pranav Kant
f63858433b loplugin:includeform
Change-Id: Ib62a7aa61062f00698aa3e8a144438de5c57e53d
2017-12-20 21:21:05 +05:30
Michael Meeks
be228a160d Allow unit tests to avoid handleInput.
Change-Id: Ib4accd6bbfdc1fc55c45365df275edfa8a68bc59
2017-09-19 21:13:58 +01:00
Marco Cecchetti
dee39a562c support for rendering a watermark on each tile
Change-Id: I3edccac49a3bcd3d2493d8d7ef3a1ae29307e727
Reviewed-on: https://gerrit.libreoffice.org/41898
Reviewed-by: Jan Holesovsky <kendy@collabora.com>
Tested-by: Jan Holesovsky <kendy@collabora.com>
2017-09-07 17:28:44 +02:00
Michael Meeks
3101fa510d Accumulate I/O stats per document.
Change-Id: Ie2f5647e65070ddd828f048820efd38b600f9133
2017-06-02 20:41:25 +01:00
Ashod Nakashian
da2d3cbc92 wsd: support per-user links and commands
userextrainfo is a json array that contains
extra user-specific links.

Currently 'avatar' is assumed to hold the
image url for the user's avatar.

'mail' and other links can also be added.

Change-Id: I37c4c68bfa0b7ee659e017b4867dcb8cf5c2ca2f
Reviewed-on: https://gerrit.libreoffice.org/38120
Reviewed-by: Ashod Nakashian <ashnakash@gmail.com>
Tested-by: Ashod Nakashian <ashnakash@gmail.com>
2017-05-29 06:45:18 +02:00
Ashod Nakashian
407c538f04 Correctly send termination reason to clients
Fixes the case when the client reconnects on idle
disconnection (because it never got the 'close: idle'
message).

Also, show informative message to users in this case
instead of grey screen.

Change-Id: Ia2e1f2ffefe6d35dd1552e7cc44e490aab86c600
Reviewed-on: https://gerrit.libreoffice.org/37891
Reviewed-by: Ashod Nakashian <ashnakash@gmail.com>
Tested-by: Ashod Nakashian <ashnakash@gmail.com>
2017-05-22 07:05:28 +02:00
Ashod Nakashian
47c01440ba wsd: logs
Change-Id: I286c4c7415b114f51f3258bd6d50f8e103ea6c75
Reviewed-on: https://gerrit.libreoffice.org/37611
Reviewed-by: Ashod Nakashian <ashnakash@gmail.com>
Tested-by: Ashod Nakashian <ashnakash@gmail.com>
2017-05-15 05:14:55 +02:00
Michael Meeks
2d1764d30e Dump ClientSession and MessageQueue state too. 2017-04-05 17:59:29 +01:00
Pranav Kant
ce1084b74f wsd: Send readonly info to clients
With this every other client would be able to know about other client's
permission i.e whether they have opened the document as readonly. This
could be important eg: to hide the cursor overlay of readonly users in
the UI or to mark these users as readonly in the userlist.

Change-Id: I5dcb1b4e5a22c9b546d16b69b9216cc7653cff04
2017-03-31 12:20:09 +05:30
Michael Meeks
913c469aa8 Cleanup whitespace, return is not a function. 2017-03-30 17:34:52 +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
Jan Holesovsky
9f17050a7d Pass the locale settings from loleaflet to wsd/kit.
Change-Id: Ie530db73cfbdb62787f16eae0f4b07fbf8b8acb4
2017-03-24 12:34:32 +01:00
Michael Meeks
0eaef6c896 config.h - get includes right: must always be the first include. 2017-03-10 10:47:43 +01:00
Ashod Nakashian
4abf706af6 nb: websocket shutdown support
Change-Id: I2fcab98e9725eca86d097f34236889fdf9289c47
2017-03-10 10:47:41 +01:00
Ashod Nakashian
57235943c0 nb: ignore empty payloads
When the socket is closed the last WS frame
will not have any payload, just a frame.
In this case the socket should still fire
handleMessage so this frame could trigger
application logic, however in this case
ClientSession has nothing to do, so we skip it.

Change-Id: Ia2b13026e31460ffceb8f9d9cfa39d36fbc57146
2017-03-10 10:47:41 +01:00
Ashod Nakashian
784dd41eae nb: simplify WS sendMessage interface
No need to construct vector<char> where
a simple char*/size_t suffice.

Change-Id: Ic70ad65a2078a1f653695504a79532f7831d88be
2017-03-10 10:47:40 +01:00
Ashod Nakashian
9efb14def7 nb: pass the WS frame type explicitly
Change-Id: Iaf4d832af4313b629701c7f07832dcaaf3e53c20
2017-03-10 10:47:40 +01:00
Jan Holesovsky
a1a46c240e nb: Use the non-blocking socket in the loolwsd.
This so far only builds, but I did not even try to run it yet.

Change-Id: Iceacb5fc5c8994726508e8ea00bd495d758391a8
2017-03-10 10:47:39 +01:00
Miklos Vajna
98b02fb9c4 common: unused using declaration in Session
Change-Id: I0122b6ad6f5d0e47a2b3c153cdd5e65a7adc6040
2017-02-07 09:08:38 +01:00
Ashod Nakashian
0476d1d9f2 wsd: don't complain to the user on idle termination
We no longer tell the clinet "This is embarrassing..."
when we disconnect and unload an idle document. Instead,
the client UI remains greyed out so the user can resume
as if it was inactive (and reload the document in this case).

Also, we now always send the "close: " message prior
to shutting down a client websocket. This is more
reasonable and consistent when we intentionally disconnect,
so clients can rely on it to signal intent and give reason.

Otherwise, a disconnection without this application-level
message should be unexpected and is therefore reasonable
to show the "This is embarrassing..." message.

Change-Id: Ic7439bcc9267be155586ccd5d122e9fe60225516
2017-02-05 21:59:23 -05:00
Ashod Nakashian
25be7f0ab6 wsd: use own tokenizer
Change-Id: Ia6e58767e3a138d086d4e0ae287782d3ed558076
Reviewed-on: https://gerrit.libreoffice.org/33418
Reviewed-by: Ashod Nakashian <ashnakash@gmail.com>
Tested-by: Ashod Nakashian <ashnakash@gmail.com>
2017-01-23 04:37:21 +00:00
Miklos Vajna
4b980530e5 common: remove unused using declaration
Change-Id: I51d4d1f555ed5508370e4b9a7b8f04f266a2ca4a
2017-01-17 09:58:50 +01:00
Ashod Nakashian
b1ff72e13f wsd: move shutdown web socket helper into LOOLWebSocket
Change-Id: Ide377fe3a8c950490bb6c04382464f0fdfd66088
Reviewed-on: https://gerrit.libreoffice.org/33129
Reviewed-by: Ashod Nakashian <ashnakash@gmail.com>
Tested-by: Ashod Nakashian <ashnakash@gmail.com>
2017-01-16 02:08:28 +00:00
Ashod Nakashian
3a5be2926b wsd: log WS incoming messages only once
Change-Id: Iee31bc649ae2d194b6418367f0e9ab8561099b17
Reviewed-on: https://gerrit.libreoffice.org/32551
Reviewed-by: Ashod Nakashian <ashnakash@gmail.com>
Tested-by: Ashod Nakashian <ashnakash@gmail.com>
2017-01-01 03:55:19 +00:00
Ashod Nakashian
9e677e268f wsd: new LOG_CHECK_RET to log failure and return
This is to replace assertion for non-fatal cases.

Change-Id: I6f8aedea52fb861309d0bc8f8f9cd43395da0805
Reviewed-on: https://gerrit.libreoffice.org/32550
Reviewed-by: Ashod Nakashian <ashnakash@gmail.com>
Tested-by: Ashod Nakashian <ashnakash@gmail.com>
2017-01-01 03:54:51 +00:00
Ashod Nakashian
477ca6f414 loolwsd: cleanup the Sessions
Change-Id: I3cd065ab84e17f943fa7de7e094db574ff6fde07
Reviewed-on: https://gerrit.libreoffice.org/31931
Reviewed-by: Ashod Nakashian <ashnakash@gmail.com>
Tested-by: Ashod Nakashian <ashnakash@gmail.com>
2016-12-13 04:35:00 +00:00
Ashod Nakashian
e60bc28a00 loolwsd: LOOLSession -> Session
Change-Id: I94369480fb0a6789375dfe5610ada300e94b80eb
Reviewed-on: https://gerrit.libreoffice.org/31930
Reviewed-by: Ashod Nakashian <ashnakash@gmail.com>
Tested-by: Ashod Nakashian <ashnakash@gmail.com>
2016-12-13 04:34:19 +00:00
Michael Meeks
7cf77c26f7 Improved fuzzer - to fuzz input.
Pass --unitlib=test/.libs/unit-fuzz.so to loolwsd to enable.
2016-12-08 14:53:01 +00:00
Miklos Vajna
dd1dbaa737 common: clean up redundant initializers for members
Change-Id: I7ee177acdc2521bc5b2d9fd0b0d3fa4947d6f2e2
2016-12-02 08:16:40 +01:00
Michael Meeks
c1a398977f Adapt makefiles, includes etc. to new locations. 2016-11-25 09:58:57 +00:00