Commit graph

239 commits

Author SHA1 Message Date
Michael Meeks
cca657c8f2 Apply the pre-branch rename script to re-organize the source. 2016-11-25 09:58:48 +00:00
Ashod Nakashian
8072576424 loolwsd: move signal and process code to SigUtil files
Change-Id: I91c001ef54858d942f8e3fe56d8a6b02cb2bf37e
Reviewed-on: https://gerrit.libreoffice.org/30846
Reviewed-by: Ashod Nakashian <ashnakash@gmail.com>
Tested-by: Ashod Nakashian <ashnakash@gmail.com>
2016-11-14 21:20:21 +00:00
Jan Holesovsky
0674e87831 Implement a thread-safe websocket inherited from Poco::Net::WebSocket.
sendFrame() implemented in LOOLWebSocket is thread safe, and also deals with
large messages - sends the "nextmessage: size=..." frame before the actual
large frame.

The problem this is attempting to solve was that when sending a large frame,
it was split to multiple packets.  During that, another frame was sent from a
different thread; which lead to confusion, and the resulting frame was
corrupted (because it ended up composed from unrelated packets).

Change-Id: Ie85952e431b1cad2fdc6e3c64df8a444ea0ae971
2016-11-10 10:44:48 +01:00
Pranav Kant
b0933b063e tdf#103640: Implement OwnerTermination; send application-level close frame
This implements a new feature 'OwnerTermination' for WOPI based
hosts. WOPI hosts now have to enable this feature by mentioning
'EnableOwnerTermination' as 'true' in their CheckFileInfo
response. If the OwnerId of the file matches that of the UserId
of the session, this session would be able to terminate all other
sessions currently editing the same document.

The reason for this kind of document termination is sent to all
sessions in a new application-level 'close:' message. This new message is
similar to the CLOSE frame of WebSocket protocol which doesn't
seem to work across all browsers as of now. Eg: Chrome -
https://bugs.chromium.org/p/chromium/issues/detail?id=426798
After receiving this 'close: ' message, loleaflet acts
accordingly and tells the WOPI host why the websocket was closed
via post message API.

Change-Id: I997aa2e7805157ed599a3946a877fd32477cee1b
2016-11-10 15:04:21 +05:30
Jan Holesovsky
024a6048a0 Move sendLargeFrame() from Util to IoUtil.
Change-Id: Id5db865b0bcf936651e3c89a0333a101e58ace92
2016-11-08 19:57:03 +01:00
Jan Holesovsky
5f6858f782 Factor out creation of nextmessage: and improve its logging.
Change-Id: I552bc2599835b4f6c9d4ef423889b464c5701221
2016-11-08 18:25:46 +01:00
Ashod Nakashian
f02b98b432 loolwsd: use new log macros in LOOLSession
Change-Id: Ia971d4ef3b67fe289b58c6d2b1f27d6e6454a56f
Reviewed-on: https://gerrit.libreoffice.org/30495
Reviewed-by: Ashod Nakashian <ashnakash@gmail.com>
Tested-by: Ashod Nakashian <ashnakash@gmail.com>
2016-11-02 13:23:17 +00:00
Ashod Nakashian
74ad4fb529 loolwsd: log large message transmission
Change-Id: I68d7cb7cf69c45c8050d8202f51f6160bb050587
Reviewed-on: https://gerrit.libreoffice.org/30493
Reviewed-by: Ashod Nakashian <ashnakash@gmail.com>
Tested-by: Ashod Nakashian <ashnakash@gmail.com>
2016-11-02 13:22:09 +00:00
Pranav Kant
cccf6dcb7d loolwsd: Store UserId in ChildSession
Change-Id: I46593442f7f8c61bddf00a624977c9d32bffdf44
2016-10-26 21:10:15 +05:30
Michael Meeks
f8746373a7 Handle exceptions during websocket shutdown. 2016-10-22 16:43:42 +01:00
Ashod Nakashian
b44d71f0ae loolwsd: no need to create prisoner WS anymore
Change-Id: Iaebac49f47353a6848fd2232a1838e4eaadaeefc
Reviewed-on: https://gerrit.libreoffice.org/29937
Reviewed-by: Ashod Nakashian <ashnakash@gmail.com>
Tested-by: Ashod Nakashian <ashnakash@gmail.com>
2016-10-16 22:04:31 +00:00
Miklos Vajna
31867f669d Fix remaining uninitialized members
The missing init of mutexes is probably theoretical, the TraceFile and
the Unit ones were real errors, I think.

Change-Id: If19c23a9c93d34059998346af8d45c26a34043a6
2016-09-28 10:20:48 +02:00
Ashod Nakashian
dfeae15038 loolwsd: accessing the WS should be thread-safe
Change-Id: I490e9b720024b93099ca63d66e840db2c1931720
Reviewed-on: https://gerrit.libreoffice.org/29335
Reviewed-by: Ashod Nakashian <ashnakash@gmail.com>
Tested-by: Ashod Nakashian <ashnakash@gmail.com>
2016-09-28 03:27:19 +00:00
Tor Lillqvist
fbd738c32a One more 2016-09-16 16:45:07 +03:00
Tor Lillqvist
8518620ddd Try to unify format of log messages a tiny bit
Lots more of that to do if one could be bothered. Just some details I
noticed in passing.
2016-09-16 13:09:00 +03:00
Tor Lillqvist
9d03ff2946 No need to include ChildSession.hpp here 2016-09-16 11:25:06 +03:00
Pranav Kant
db5efae2b8 loolwsd: Handle user names with spaces; encode/decode properly
Change-Id: I209bbd63686db8112529a3442a13a6162ce14d60
Reviewed-on: https://gerrit.libreoffice.org/28484
Reviewed-by: pranavk <pranavk@collabora.co.uk>
Tested-by: pranavk <pranavk@collabora.co.uk>
2016-08-30 07:46:09 +00:00
Pranav Kant
67444eeb80 loolwsd: Pass sessions' usernames to core
Change-Id: I8c81c02fafd2cb9d0048729401e082bb422e299b
Reviewed-on: https://gerrit.libreoffice.org/28481
Reviewed-by: pranavk <pranavk@collabora.co.uk>
Tested-by: pranavk <pranavk@collabora.co.uk>
2016-08-30 07:45:37 +00:00
Ashod Nakashian
76ad9b3451 loolwsd: cleanup of LOOLSession
Change-Id: Ib65e65c44b258c7ae4d4fbe68555f664900d21c9
Reviewed-on: https://gerrit.libreoffice.org/28305
Reviewed-by: Ashod Nakashian <ashnakash@gmail.com>
Tested-by: Ashod Nakashian <ashnakash@gmail.com>
2016-08-22 05:48:00 +00:00
Ashod Nakashian
ecd33e1b07 loolwsd: send json messages to the UI as text
Change-Id: Ie5712b4ebf4f01a6650f5f7c0df5197b5b9f9208
Reviewed-on: https://gerrit.libreoffice.org/27588
Reviewed-by: Ashod Nakashian <ashnakash@gmail.com>
Tested-by: Ashod Nakashian <ashnakash@gmail.com>
2016-07-27 16:00:25 +00:00
Miklos Vajna
5179d41521 LOOLSession: use std::move() 2016-07-21 10:19:39 +02:00
Pranav Kant
9417ec839c loolwsd: Introduce headless peer;fix convert-to API partially
Convert-to API got broken in
80786cc79d

In case of convert-to API, there is no actual client facing
websocket connection (and we use an invalid websocket
connection). So, when prisoner session tries to forward messages to
client it would fail as we have now started to propagate errors
from forwardToPeer.

Introduce a headless (without an actual client) peer mode, and
fail silently when someone tries to forward messages to such a peer.

Change-Id: I8a9f93f798dca9fea45c41e99bf373cd23d32e2c
2016-07-21 12:37:44 +05:30
Ashod Nakashian
fae850189d loolwsd: include cleanup and organization
A source file (.cpp) must include its own header first.
This insures that the header is self-contained and
doesn't depend on arbitrary (and accidental) includes
before it to compile.

Furthermore, system headers should go next, followed by
C then C++ headers, then libraries (Poco, etc) and, finally,
project headers come last.

This makes sure that headers and included in the same dependency
order to avoid side-effects. For example, Poco should never rely on
anything from our project in the same way that a C header should
never rely on anything in C++, Poco, or project headers.

Also, includes ought to be sorted where possible, to improve
readability and avoid accidental duplicates (of which there
were a few).

Change-Id: I62cc1343e4a091d69195e37ed659dba20cfcb1ef
Reviewed-on: https://gerrit.libreoffice.org/25262
Reviewed-by: Ashod Nakashian <ashnakash@gmail.com>
Tested-by: Ashod Nakashian <ashnakash@gmail.com>
2016-05-21 15:52:54 +00:00
Ashod Nakashian
32ee3d0650 loolwsd: socket sending returns success or failure
Change-Id: I3f486b236e5b6a83292a9d7f3e4931e5235f3a33
Reviewed-on: https://gerrit.libreoffice.org/25239
Reviewed-by: Ashod Nakashian <ashnakash@gmail.com>
Tested-by: Ashod Nakashian <ashnakash@gmail.com>
2016-05-21 03:28:16 +00:00
Ashod Nakashian
e797ae9861 loolwsd: logging improvements
Change-Id: Ic28e8f523f67e3339cae20adcf6cab966b610f24
Reviewed-on: https://gerrit.libreoffice.org/25233
Reviewed-by: Ashod Nakashian <ashnakash@gmail.com>
Tested-by: Ashod Nakashian <ashnakash@gmail.com>
2016-05-21 03:19:04 +00:00
Miklos Vajna
c2fc95ac23 Drop unused using declarations
Change-Id: Iee778833781c6f00c1fb0b8fc1975acfe4fb0cd9
2016-05-10 09:14:22 +02:00
Ashod Nakashian
1dd88e68ea loolwsd: shortened some long identifiers
Change-Id: I87809f5ad2a6d8f546cf3abaf646672d2d8168dc
Reviewed-on: https://gerrit.libreoffice.org/24471
Reviewed-by: Ashod Nakashian <ashnakash@gmail.com>
Tested-by: Ashod Nakashian <ashnakash@gmail.com>
2016-04-29 01:05:45 +00:00
Ashod Nakashian
5fbaa8f3d2 loolwsd: useractive and userinactive command support
loleaflet can now send userinactive when the user
has switched tabs or the browser window loses
focus. Similarly, it can send useractive when
focus is regained.

Change-Id: Id3186949b10a8263e29ada1a790d3123a79e8f08
Reviewed-on: https://gerrit.libreoffice.org/24272
Reviewed-by: Ashod Nakashian <ashnakash@gmail.com>
Tested-by: Ashod Nakashian <ashnakash@gmail.com>
2016-04-21 05:31:18 +00:00
Henry Castro
c29944a386 loolwsd: fix close after close
The closing handshake.
Either peer can send a control frame with data containing
a specified control sequence to begin the closing handshake.

Upon receiving such a frame, the other peer sends a
Close frame in response, if it hasn't already sent one.
2016-04-18 20:27:27 -04:00
Tor Lillqvist
4087ac8089 With "disconnect" messages gone, no need for a 'reason' to disconnect()
YAGNI.
2016-04-13 15:56:23 +03:00
Tor Lillqvist
e5de11113b Don't check for or send "disconnect" frames anywhere and don't document them
Follow-up to 68b3a2c81e.
2016-04-13 15:49:10 +03:00
Pranav Kant
9ea4624839 loolwsd: Handle socket exceptions while trying to send frame
In case of abnormal termination of session from client-side,
we might still have data being processed in the kit process, for
example, during auto-save. Trying to send such data over an
expired socket towards the client would throw exceptions which
need to be handled, otherwise the auto-save process would not be
successful. Further, the unhandled exception can bring the document
broker in an unstable state with dockey still present in the
object.

Also do not send 'editlock: 0' to a websocket session which is
going to be removed because the session might have been
forcefully terminated from the client-side, in which case sending
data would go nowhere.

Change-Id: I10eb9c818bc81d4db26d5a19dc8bd44f6fbdf32c
2016-04-13 09:56:32 +05:30
Tor Lillqvist
df2048c895 No need for <condition_variable> here 2016-04-10 09:36:36 +03:00
Ashod Nakashian
b6d2edb0e3 loolwsd: moved activity tracking into LOOLSession
Change-Id: I87d5afc43bea29ede2ad6e2871c594c4746bc3d5
Reviewed-on: https://gerrit.libreoffice.org/23948
Reviewed-by: Ashod Nakashian <ashnakash@gmail.com>
Tested-by: Ashod Nakashian <ashnakash@gmail.com>
2016-04-10 03:32:58 +00:00
Tor Lillqvist
acc59a2ea5 Make error messages more consistent and use Log::syserror() in more places
A call to Log::error() should be enough to indicate that it is an
error. We don't need to prefix the message with the string "Error: "
in some cases but not others. (If we do want such a prefix for all
errors, surely then we should add it in the actual Log::error()
function.)

Also, change some more Log::error() calls to Log::syserror() where
appropriate.
2016-04-07 11:53:44 +03:00
Ashod Nakashian
ce2fabb733 loolwsd: moved IO utilities into IoUtil file
Change-Id: I1e8d5562787134cbb490c38b19d83b7514ec9baa
Reviewed-on: https://gerrit.libreoffice.org/23586
Reviewed-by: Ashod Nakashian <ashnakash@gmail.com>
Tested-by: Ashod Nakashian <ashnakash@gmail.com>
2016-03-29 14:09:04 +00:00
Ashod Nakashian
7d2d2aab1c loolwsd: message handling cleanups
Change-Id: I346511819907757bd84895c3751f0cbce4f37084
Reviewed-on: https://gerrit.libreoffice.org/23585
Reviewed-by: Ashod Nakashian <ashnakash@gmail.com>
Tested-by: Ashod Nakashian <ashnakash@gmail.com>
2016-03-29 02:48:28 +00:00
Ashod Nakashian
74580df0d6 loolwsd: warn if still communicating while terminating
Change-Id: Id42bb29e7c5f17772c4251d686e82d4380d2a073
Reviewed-on: https://gerrit.libreoffice.org/23539
Reviewed-by: Ashod Nakashian <ashnakash@gmail.com>
Tested-by: Ashod Nakashian <ashnakash@gmail.com>
2016-03-26 17:08:37 +00:00
Tor Lillqvist
e8a5ba1b29 _bShutdown is always false 2016-03-08 09:45:23 +02:00
Tor Lillqvist
e7e1ef58ae Cosmetics: Sort and prune #include and 'using' lines 2016-03-08 09:44:04 +02:00
Tor Lillqvist
7d89cfa6f0 Clean up #includes and usings.
Include and use 'using' only for what is actually used. Sort the
include and 'using' lines.
2016-03-07 20:00:35 +02:00
Tor Lillqvist
9947633550 Catch IOException from sendTextFrame() in LOOLSession::disconnect()
Otherwise the uncaught exception will terminate the loolkit process
unexpectedly, which surely messes things up.
2016-03-07 20:00:35 +02:00
Tor Lillqvist
9f67eecadd Improve exception logging
Always try to identify *where* we caught the exception. It is not that
useful to have half a dozen places that all just log "Exception:".
2016-03-07 18:36:01 +02:00
Tor Lillqvist
72ff491fb2 Cosmetics: avoid trailing space in 'disconnect' message 2016-02-22 16:27:12 +02:00
Tor Lillqvist
ef30af121a Log a bit more information 2016-02-22 13:50:14 +02:00
Tor Lillqvist
b4387a535a Bin some superfluous using declarations and includes, and actually use others
Sorry, could not resist. Obviously not very important.

In retrospect, maybe it would have been better to have as policy to
*not* use any 'using Poco::Foo'. Now there is an inconsistent mix of
writing out the complete type and using a 'using'. Plus copy-pasted
long lists of 'usings'. And of course, one should never have 'using'
in an include file. Oh well.
2016-02-22 11:37:47 +02:00
Pranav Kant
3667bef9a6 loolwsd: Handle password protected documents
Change-Id: Iceb5bb598ef1517bf640994c27bad4ca36bd72c1
Reviewed-on: https://gerrit.libreoffice.org/21894
Reviewed-by: Ashod Nakashian <ashnakash@gmail.com>
Tested-by: Ashod Nakashian <ashnakash@gmail.com>
2016-02-19 21:49:45 +00:00
Pranav Kant
7ffd4b45db bccu#1468: handle 'nextmessage:' in prisoner -> master text frames
There are cases when prisoner would send huge text data but
without preceeding 'nextmessage' frames making the master throw
WebSocketException.

Also move the 'nextmessage' frame interpretation logic up in the
'else if' ladder to be able to detect and handle such huge text frames.

Change-Id: Ibe44b69f4ab75c1b8096648c6006316c88366e7c
Reviewed-on: https://gerrit.libreoffice.org/21835
Reviewed-by: Ashod Nakashian <ashnakash@gmail.com>
Tested-by: Ashod Nakashian <ashnakash@gmail.com>
2016-02-01 05:09:35 +00:00
Ashod Nakashian
55f2105f00 loolwsd: logging improvements
Change-Id: I77844a2b549c1f497c2d44f054169bf11d9227d8
Reviewed-on: https://gerrit.libreoffice.org/21752
Reviewed-by: Ashod Nakashian <ashnakash@gmail.com>
Tested-by: Ashod Nakashian <ashnakash@gmail.com>
2016-01-24 21:00:34 +00:00
Ashod Nakashian
d3fc5ac37b loolwsd: sockets are shutdown on disconnect
Change-Id: I1c00be4648cff94013ceab87fcb607b9bb921535
Reviewed-on: https://gerrit.libreoffice.org/21684
Reviewed-by: Ashod Nakashian <ashnakash@gmail.com>
Tested-by: Ashod Nakashian <ashnakash@gmail.com>
2016-01-21 16:06:37 +00:00