Commit graph

610 commits

Author SHA1 Message Date
Michael Meeks
a28b3d0d7e Disable port re-use for internal unit-tests, so we find a free socket. 2016-11-02 07:59:59 +00:00
Michael Meeks
5e9b582ed4 loolwsd: avoid ordering issues with atexit handlers.
Otherwise Admin::instance() has been destroyed by the time we're
cleaning up the DocumentBrokers resulting in FMRs etc.
2016-11-02 00:46:17 +00:00
Michael Meeks
da76cffc0d loolwsd: Better fix for 'Address already in use' vs. 86383d40db 2016-11-02 00:42:56 +00:00
Pranav Kant
86383d40db loolwsd: Tentative fix for 'Address already in use' 2016-11-01 10:25:29 +01:00
Ashod Nakashian
4ba5bedf6a loolwsd: explicitly scope DocumentBroker mutex
Change-Id: I64629774ec745f47e7376231a3ca569bcbfffaac
Reviewed-on: https://gerrit.libreoffice.org/30424
Reviewed-by: Ashod Nakashian <ashnakash@gmail.com>
Tested-by: Ashod Nakashian <ashnakash@gmail.com>
2016-10-31 06:10:57 +00:00
Ashod Nakashian
4186149f5b loolwsd: some logs converted to new form
Change-Id: I7d478ff2fc5715c3f612bf57f98aa2ce454ed4ed
Reviewed-on: https://gerrit.libreoffice.org/30423
Reviewed-by: Ashod Nakashian <ashnakash@gmail.com>
Tested-by: Ashod Nakashian <ashnakash@gmail.com>
2016-10-31 06:10:17 +00:00
Ashod Nakashian
ce785b6432 loolwsd: convert int to string before adding to literal
Change-Id: Ia3352589aa894b38892f98fedc93926f063dce72
Reviewed-on: https://gerrit.libreoffice.org/30417
Reviewed-by: Ashod Nakashian <ashnakash@gmail.com>
Tested-by: Ashod Nakashian <ashnakash@gmail.com>
2016-10-31 06:06:55 +00:00
Ashod Nakashian
773c15f710 loolwsd: consistent formatting
With the help of clang-format.
For reference, the following command was used,
but not all changes were commited:

clang-format-3.9 -style='{BasedOnStyle: WebKit,
 AlignAfterOpenBracket: Align,
 AlwaysBreakAfterReturnType: None,
 BreakBeforeBraces: Allman,
 DerivePointerAlignment: 'true',
 ExperimentalAutoDetectBinPacking: 'true',
 IndentWrappedFunctionNames: 'true',
 UseTab: Never}'

Change-Id: I0f7490c7ee38aeefeefcf9d5d4c3dab380cd63b8
Reviewed-on: https://gerrit.libreoffice.org/30416
Reviewed-by: Ashod Nakashian <ashnakash@gmail.com>
Tested-by: Ashod Nakashian <ashnakash@gmail.com>
2016-10-31 06:06:35 +00:00
Michael Meeks
87d5849176 Pass master port number to forkit.
Fixes issues with free port selection.
2016-10-26 15:51:25 +01:00
Pranav Kant
36fece8b07 loolwsd: Separate WOPI load duration and check fileinfo duration
Add both of them and send them as wopiloadduration to the client,
if storage is WOPI.

Change-Id: I5652d346d70f473624f03536469acf45470db742
2016-10-24 16:04:28 +05:30
Ashod Nakashian
cecb87dfe3 loolwsd: don't wait after autosaving to rebalance children
Change-Id: Ifb44d0395e8f416e418711b09deed3eb7f57effa
Reviewed-on: https://gerrit.libreoffice.org/30214
Reviewed-by: Ashod Nakashian <ashnakash@gmail.com>
Tested-by: Ashod Nakashian <ashnakash@gmail.com>
2016-10-23 21:19:53 +00:00
Ashod Nakashian
f4b4037f9e loolwsd: spawn new children when no forks are outstanding
This avoids always waiting until child spawning times
out by being smarter about whether or not there are
any children spawning to wait for.

Change-Id: I96a16ac35f90f70219d4153db9862cf2ee5b6a76
Reviewed-on: https://gerrit.libreoffice.org/30213
Reviewed-by: Ashod Nakashian <ashnakash@gmail.com>
Tested-by: Ashod Nakashian <ashnakash@gmail.com>
2016-10-23 21:19:03 +00:00
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