Commit graph

598 commits

Author SHA1 Message Date
Ashod Nakashian
70690f6dab loolwsd: remove dead DocumentBrokers
Change-Id: If9b24ac1e45454e21222699a00defa70acc4ed80
Reviewed-on: https://gerrit.libreoffice.org/30212
Reviewed-by: Ashod Nakashian <ashnakash@gmail.com>
Tested-by: Ashod Nakashian <ashnakash@gmail.com>
2016-10-23 21:18:19 +00:00
Ashod Nakashian
f68ece0037 loolwsd: fix testMaxDocuments unittest
Checking for document limit must be done before allocating
a child process, otherwise the new child process will not
be cleaned up or released, thereby failing the test.

Change-Id: I99b1155bdacf2f0b7a24c7b7330d207e4c7beee8
Reviewed-on: https://gerrit.libreoffice.org/30208
Reviewed-by: Ashod Nakashian <ashnakash@gmail.com>
Tested-by: Ashod Nakashian <ashnakash@gmail.com>
2016-10-23 21:14:46 +00:00
Ashod Nakashian
30df646311 loolwsd: check for termination flag before loading new documents
Change-Id: I4b7117ba255dd81f28ed1279814048e4311c2473
Reviewed-on: https://gerrit.libreoffice.org/30211
Reviewed-by: Ashod Nakashian <ashnakash@gmail.com>
Tested-by: Ashod Nakashian <ashnakash@gmail.com>
2016-10-23 21:14:29 +00:00
Ashod Nakashian
0287d7141d loolwsd: logs around testMaxConnections
Change-Id: I0f9dc957fb95d501626e321b4e15472d077c0301
Reviewed-on: https://gerrit.libreoffice.org/30210
Reviewed-by: Ashod Nakashian <ashnakash@gmail.com>
Tested-by: Ashod Nakashian <ashnakash@gmail.com>
2016-10-23 21:14:15 +00:00
Ashod Nakashian
785fd972f4 loolwsd: cleanup dead children before balancing
Change-Id: I782080bb83973a795e2c967d91b152095678a93e
Reviewed-on: https://gerrit.libreoffice.org/30203
Reviewed-by: Ashod Nakashian <ashnakash@gmail.com>
Tested-by: Ashod Nakashian <ashnakash@gmail.com>
2016-10-23 21:08:21 +00:00
Ashod Nakashian
a69a67e81b loolwsd: don't do in catch what might have thrown in try
Change-Id: I36d039f573529545c878d30e25f3884e2b4afeb2
Reviewed-on: https://gerrit.libreoffice.org/30202
Reviewed-by: Ashod Nakashian <ashnakash@gmail.com>
Tested-by: Ashod Nakashian <ashnakash@gmail.com>
2016-10-23 21:07:21 +00:00
Ashod Nakashian
2644b39d5a loolwsd: use the container to track number of DocumentBrokers
Change-Id: Ic2d88eb6265365f8ffc99c9117a2a4383018e519
Reviewed-on: https://gerrit.libreoffice.org/30200
Reviewed-by: Ashod Nakashian <ashnakash@gmail.com>
Tested-by: Ashod Nakashian <ashnakash@gmail.com>
2016-10-23 21:06:40 +00:00
Ashod Nakashian
6c0be6d90d loolwsd: move admin updates into DocumentBroker
Change-Id: Ic35198a7e4457a775fac25954279501e37b94b42
Reviewed-on: https://gerrit.libreoffice.org/30199
Reviewed-by: Ashod Nakashian <ashnakash@gmail.com>
Tested-by: Ashod Nakashian <ashnakash@gmail.com>
2016-10-23 21:05:28 +00:00
Michael Meeks
b6291f9cb5 Unit tests new-style now search for a free port pair. 2016-10-22 16:43:42 +01:00
Michael Meeks
f8746373a7 Handle exceptions during websocket shutdown. 2016-10-22 16:43:42 +01:00
Michael Meeks
ae04deada8 Restore ability to inject prisoner requests. 2016-10-21 17:30:01 +01:00
Pranav Kant
1be2a78564 Handle WOPI's UserCanWrite to determine readonliness
permission= parameter in URL is still supported, but overridden
by UserCanWrite parameter.

Also, introduce a new protocol message, perm: which dictates
loleaflet about the permission rather than the other way around
(only in case of WOPI)

It is to be noted that by default loolwsd assumes very
restrictive permissions, so not providing UserCanWrite in WOPI
implementation by a WOPI host would lead to opening of only
readonly session.

Change-Id: I2013c1661fd491c79bb367a41e1a7036fa03f984
2016-10-19 20:47:20 +05:30
Tor Lillqvist
38ccbd0196 We can use LoolException::toString() in one more place 2016-10-18 09:45:02 +03:00
Tor Lillqvist
b02a917f0a Introduce LoolException::toString() to avoid a few std::string casts
Also consistently cast the call of std::exception::what() and not a
string literal being conatenated with that.
2016-10-18 08:40:04 +03:00
Tor Lillqvist
72133868b5 Use correct function name in some log messages
These Log::foo() calls are in ClientRequestHandler::handleClientRequest(),
not in ClientRequestHandler::handleRequest().

Actually I wonder why we show the name of the function in this handful of
places. We don't do it in general. Consistency, bah.
2016-10-18 08:39:24 +03:00
Tor Lillqvist
32b33ee685 Add logging of NumDocBrokers and the size of the DocBrokers array
I fear they get can out of sync when HTTPCrashTest::killLoKitProcesses()
kills a loolkit process, and this then causes HTTPWSError::testMaxDocuments()
to fail. This is to help debugging that.

Haven't fully understood what is going on yet. But one thing is sure:
It is a bad idea to duplicate the same state information in two
places, we shouldn't really use that separate NumDocBrokers
variable.

Probably also NumConnections tracks state that can easily be
calculated from the data structures, but maybe NumConnections does not
that easily get out of sync.
2016-10-18 08:06:16 +03:00
Tor Lillqvist
bb36ca79d4 Attempt to handle unauthorized WOPI usage better
Use the previously unused UnauthorizedRequestException for this, and
throw a such in StorageBase::create() when the WOPI host doesn't match
any of those configured.

In a developer debug build, without access to any real WOPI
functionality, you can test by setting the FAKE_UNAUTHORIZED
environment variable and attempting to edit a plain local file:
URI. That will cause such an exception to be thrown in that function.

Catch that UnauthorizedRequestException in
ClientRequestHandler::handleGetRequest(), and send an 'error:
cmd=internal kind=unauthorized' message to the client. Handle that in
loleaflet in the same place where the 'error: cmd=internal
kild=diskfull' message is handled, and in the same fashion, giving up
on the document.

Actually, using exceptions for relatively non-exceptional situations
like this is lame and makes understanding the code harder, but that is
just my personal preference...

FIXME: By the time StorageBase::create() gets called we have already
sent three 'statusindicator:' messages ('find', 'connect', and
'ready') to the client. We should ideally do the checks we do in
StorageBase::create() much earlier.

Also consider that ClientRequestHandler::handleClientRequest() has
code that catches UnauthorizedRequestException and
BadRequestException, and tries to set the HTTP response in those
cases. I am not sure if that functionality has ever been exercised,
though. Currently, we upgrade the HTTP connection to WebSocket early,
and only after that we check whether the WOPI host is authorized
etc. By that time it is too late to return an HTTP response to the
user. If that even is what we ideally should do? If not, then we
probably should drop the code that constructs HTTP responses and
attempts to send them.

Also, if I, as a test, force an HTTPResponse::HTTP_BAD_REQUEST to be
sent before the HTTP connection is upgraded to WebSocket, loleaflet
throws up the generic "Well, this is embarrassing" dialog anyway. At
least in Firefox on Linux. (Instead of the browser showing some own
dialog, which I was half-expecting to happen.)
2016-10-17 19:34:04 +03:00
Pranav Kant
38e8a38034 loolwsd: Fix admin remove doc after unloading the session
Change-Id: Ia512d5b4c5f0e230542caed6cebc242e3a345430
2016-10-17 18:34:22 +05:30
Pranav Kant
d4fbc92023 loolwsd: Fix admin console document add
Change-Id: I987f26b4aae2c4ea8ef65919f570576ef8c5d2a7
2016-10-17 18:34:22 +05:30
Pranav Kant
1c2c03fcb6 loolwsd: Query docbroker for load duration after loading the doc
addSession() now also loads the document, so querying docbroker
for load duration before it doesn't make any sense.

Change-Id: I3c60bef5e2054878ba695b8f76b6800cdedffe8d
2016-10-17 18:34:22 +05:30
Pranav Kant
cd92dc277b loolwsd: Remove this leftover duplicate comment
Change-Id: I243e2fd745b4b0c70cec79deefffcb5b8f7d2548
2016-10-17 15:25:20 +05:30
Ashod Nakashian
cb09f50d8c loolwsd: static variables must start with uppercase per the style guidelines
Change-Id: I1e8105983f98cc0cd15448e6d9cb1e6fca36ca9d
Reviewed-on: https://gerrit.libreoffice.org/29955
Reviewed-by: Ashod Nakashian <ashnakash@gmail.com>
Tested-by: Ashod Nakashian <ashnakash@gmail.com>
2016-10-16 22:14:45 +00:00
Ashod Nakashian
d857b3dbbb loolwsd: add the ClientSession to the Broker last
This avoids early connection failures causing the
session to linger in the Broker indefinetely.

Change-Id: Ibe2b5b386ed1cd6e12e68735bff60b15957188cf
Reviewed-on: https://gerrit.libreoffice.org/29952
Reviewed-by: Ashod Nakashian <ashnakash@gmail.com>
Tested-by: Ashod Nakashian <ashnakash@gmail.com>
2016-10-16 22:12:43 +00:00
Ashod Nakashian
de7cda7891 loolwsd: improve child cleanup and forking
Change-Id: I437216d87b6fa15e567e102ed875b22ef03351b2
Reviewed-on: https://gerrit.libreoffice.org/29948
Reviewed-by: Ashod Nakashian <ashnakash@gmail.com>
Tested-by: Ashod Nakashian <ashnakash@gmail.com>
2016-10-16 22:11:18 +00:00
Ashod Nakashian
4c967ec0c8 loolwsd: correct the test document name
Change-Id: I4efe1e36a70b62154a5e0dd70d42ee0a6c98cf6f
Reviewed-on: https://gerrit.libreoffice.org/29946
Reviewed-by: Ashod Nakashian <ashnakash@gmail.com>
Tested-by: Ashod Nakashian <ashnakash@gmail.com>
2016-10-16 22:10:06 +00:00
Ashod Nakashian
67437c6076 loolwsd: all timeouts in milliseconds
Change-Id: Ic5db4e13b2caba53fcbeea0bfdb10d112f2d5a18
Reviewed-on: https://gerrit.libreoffice.org/29942
Reviewed-by: Ashod Nakashian <ashnakash@gmail.com>
Tested-by: Ashod Nakashian <ashnakash@gmail.com>
2016-10-16 22:08:00 +00:00
Ashod Nakashian
d4214c555f loolwsd: kill waitBridgeCompleted and AvailableChildSessions
Change-Id: I26eac76135d35ea17ac7e6d2697df81ad07a1d73
Reviewed-on: https://gerrit.libreoffice.org/29941
Reviewed-by: Ashod Nakashian <ashnakash@gmail.com>
Tested-by: Ashod Nakashian <ashnakash@gmail.com>
2016-10-16 22:06:21 +00:00
Ashod Nakashian
7043b95f4d loolwsd: fix convert-to after removing Prisoner WS
Change-Id: I652a9fffa267e01043262eb25d3c2e19bf9eb447
Reviewed-on: https://gerrit.libreoffice.org/29940
Reviewed-by: Ashod Nakashian <ashnakash@gmail.com>
Tested-by: Ashod Nakashian <ashnakash@gmail.com>
2016-10-16 22:06:05 +00:00
Ashod Nakashian
d98e019994 loolwsd: kill priosoner connection listener
Change-Id: Ica69c80fc9094c1139d05eaf08b9c1fa6b222347
Reviewed-on: https://gerrit.libreoffice.org/29938
Reviewed-by: Ashod Nakashian <ashnakash@gmail.com>
Tested-by: Ashod Nakashian <ashnakash@gmail.com>
2016-10-16 22:04:53 +00: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
Pranav Kant
9ebd7a15e2 loolwsd: Improved loolwsd -> storage communication
Reduces the number of WOPI calls made during a document load. Earlier
effort was made in edfd3266f8
This commit cleans up and uses better approach for the same.

Other than that, access token of each session is now correctly
used when interacting with the storage. Earlier, we used to
use the same access token for each upload to storage which means
that irrespective of who clicked the save button, changes to the
document were only made on behalf of one person (of whom the
access token is used). This is fixed now.

Also includes minor cleanup left and right.

Change-Id: Id32702ff02aea4f63b7cc6afa9f62664807bb57d
Reviewed-on: https://gerrit.libreoffice.org/29931
Reviewed-by: Ashod Nakashian <ashnakash@gmail.com>
Tested-by: Ashod Nakashian <ashnakash@gmail.com>
2016-10-16 22:02:25 +00:00
Pranav Kant
07f10570cc loolwsd: Add wopiloadduration - time taken to interact with WOPI host
Change-Id: Ia2d763ef721128450bf402a61d0e0f3e75701441
2016-10-16 23:01:50 +05:30
Pranav Kant
7cacaa070d loolwsd: Make this const
Change-Id: Ieb1be92323061110798da23f066a5be0e8314472
2016-10-16 23:01:46 +05:30
Tor Lillqvist
650ab54d00 Log fatal errors as such 2016-10-14 13:02:58 +03:00
Henry Castro
a0a87276f9 loolwsd: fix media type 2016-10-13 16:54:27 -04:00
Tor Lillqvist
213c7c6d09 Catch by const ref
That's what we do everywhere else, not reason to do differently in
these two places.
2016-10-13 12:00:54 +03:00
Henry Castro
bd5e138aa9 loolwsd: fix error message localization 2016-10-12 12:44:44 -04:00
Tor Lillqvist
dc7f561481 Don't use 'FIFO' in function names as we don't use FIFOs any more
No functional changes.
2016-10-12 19:07:54 +03:00
Tor Lillqvist
58f78f8734 Don't use named pipes (FIFOs)
Use a plain pipe, as created by Poco::Process::launch() when you pass
a non-nullptr inPipe pointer to it. Leads to simpler code. No need to
explicitly create a FIFO and open it. In loolforkit, the read fd of
the pipe is now always 0 (stdin).

Creating the pipe ourselves in loolwsd using pipe() and passing the fd
of the read end of the pipe on the loolforkit command-line would not
be much more complex, and was what I first tried. But it did not work,
as Poco::ProcessImpl::launchByForkExecImpl() closes all file
descriptors >= 3. Which is a bit rude, and not documented, but there
you go.
2016-10-12 18:51:40 +03:00
Tor Lillqvist
e07069eda2 Drop parameter when we always pass the same value for it
For the 'message' parameter of LOOLSession::shutdown(),
ClientSession::shutdownPeer(), and PrisonerSession::shutdownPeer() we
always passed "". It was passed on as the 'statusMessage' parameter to
WebSocet::shutdown() which has "" as default anyway.
2016-10-12 13:05:57 +03:00
Tor Lillqvist
4b5561c9b4 "" is the default value for the WebSocket::shutdown() statusMessage parameter
So no need to pass it.
2016-10-12 12:51:06 +03:00
Tor Lillqvist
9fee650f43 Use std::getenv() consistently 2016-10-12 11:47:26 +03:00
Henry Castro
c62344db81 loolwsd: websocket shutdown cleanup 2016-10-10 22:28:56 -04:00
Ashod Nakashian
1edd37ea2d loolwsd: fix convert-to handling
Change-Id: I24b8c0b7129bee2692696809613ee49a38024c98
Reviewed-on: https://gerrit.libreoffice.org/29649
Reviewed-by: Ashod Nakashian <ashnakash@gmail.com>
Tested-by: Ashod Nakashian <ashnakash@gmail.com>
2016-10-10 06:30:48 +00:00
Ashod Nakashian
366e0e21d5 loolwsd: support timeout on MessageQueue get
Change-Id: Iaad39aaa06c59cdacdd4a864599ef6a4a12976f8
Reviewed-on: https://gerrit.libreoffice.org/29648
Reviewed-by: Ashod Nakashian <ashnakash@gmail.com>
Tested-by: Ashod Nakashian <ashnakash@gmail.com>
2016-10-10 06:29:50 +00:00
Ashod Nakashian
22fb71c672 loolwsd: cleanup lastEditableSession flag in DocumentBroker
Change-Id: Iab3a226e3ff089c6bdab264d6f1b1d639bcf3b37
Reviewed-on: https://gerrit.libreoffice.org/29630
Reviewed-by: Ashod Nakashian <ashnakash@gmail.com>
Tested-by: Ashod Nakashian <ashnakash@gmail.com>
2016-10-10 06:15:44 +00:00
Michael Meeks
f5a7a19b95 Restore LD_BIND_NOW=1 to share linking.
Finally seen linking on a 'perf top' output, and restored this.
UnitPrefork shows that it saves memory, and it should save CPU time
and more memory as the suite is actually used.
2016-10-07 17:52:52 +01:00
Tor Lillqvist
a4b0c22161 There is nothing called 'PocoException' 2016-10-07 13:51:55 +03:00
Tor Lillqvist
3576b17ac9 Refuse to start a second loolwsd listening on the same socket
Poco's ServerSocket by default uses SO_REUSEPORT when one creates it
using the constructor that takes a port number. If one uses the
default constructor and calls bind() and listen() separately, one can
tell it not to reuse the port.
2016-10-07 13:49:28 +03:00
Tor Lillqvist
3800c988b6 Don't claim log is available in a file if it isn't
Also, when it is, show the actual pathname from loolwsd.xml, not the
default.
2016-10-06 13:37:57 +03:00