Commit graph

435 commits

Author SHA1 Message Date
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
Tor Lillqvist
3b4269a301 Use Util::symbolicErrno()
I think the general policy should be to always log errno using both
Util::symbolicErrno() and std::strerror(), never log a naked errno.
But only in cases where we know that it is highly likely that it is
the most recent system call that has failed, so errno makes sense.

Change-Id: I4a1fb31e375ea949e7da17687464361efe7c1761
2018-07-11 13:05:22 +03:00
Tor Lillqvist
a97c8c3455 Fis our use of inet_ntop() etc
We had:
    auto ipv4 = (struct sockaddr_in *)&clientInfo.sin_addr
even if the clientInfo variable itself was a struct sockaddr_in.

And then we also had:
    auto ipv6 = (struct sockaddr_in6 *)&clientInfo.sin_addr
which makes even less sense.

Instead, make clientInfo into a struct sockaddr_in6, which is big
enough to also to be interpreted as a sockaddr_in. Pass the address of
the correct field, either sin_addr or sin6_addr, to inet_ntop(). (Note
that sin_addr in sockaddr_in has a different offset than sin6_addr in
sockaddr_in6.)

At least on my Fedora 28, when I connect using IPv4, accept4() still
returns the client address as an IPv4 mapped IPv6 address, that is
::ffff:192.168.1.113 for 192.168.1.113. So the sample
net.post_allow.host value in loolwsd.xml.in should probably be changed
to have that ::ffff: prefix, too.

Change-Id: I0ad774616b210d94b904982e2f7dc928adc879ed
2018-07-10 23:14:51 +03:00
Michael Meeks
a521527777 Fix logging a little.
Change-Id: I858ffb40e071eae3907eeff9c2d6291fd805dc02
2018-06-15 17:38:12 +01: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
Michael Meeks
5741d76a5d Outgoing websocket - remove silly stuff.
Change-Id: I53d763158007221e9df327ec9d3b07ad2029cbfd
2018-06-15 14:54:19 +01:00
Miklos Vajna
65df3e6ceb net: use std::move() in the StreamSocket ctor
It was inconsistent that the StreamSocket ctor had a const parameter,
but the SslStreamSocket had a non-const one and used std::move(). Use
the later in the parent class as well for consistency.

Change-Id: I58597b97432a801d164d6ed9d831a0372280e687
2018-05-24 08:50:30 +02:00
Jan Holesovsky
93cc4b4548 Use std::shared_ptr consistently.
Change-Id: I6bf3ff7de47010fd78fab26a5a318bde21c1f153
2018-05-18 15:16:40 +02:00
Jan Holesovsky
6996139e5f Use correct path in the client websockets.
Change-Id: Ie0bf6646ff3f6e6cf99b505143a416c86a3a33b8
2018-05-18 15:16:40 +02:00
Jan Holesovsky
98ed24257b Move the functionality from connectToMonitor() to SocketPoll.
Change-Id: Iab2ac09638323f5e59f7a2ea0d880f52989ad64d
2018-05-18 15:16:40 +02:00
Michael Meeks
5a94614217 Enable SSL in outbound, client websockets ...
Switch SSL context creation to be generic rather than pure server.

Change-Id: I1b750b4ddc8c607381f5541a4f4412fa16e457d4
2018-05-18 15:16:39 +02:00
Michael Meeks
9e7dff79f3 re-factor socket factories to take a client parameter.
Change-Id: I0be98eb583b4f8081dd8ad23e688e93c55220367
2018-05-18 15:16:39 +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
Andras Timar
d66e8d13b7 serve files with old gith hash in their path, that comes from cached discovery.xml
moreover:
* noCache is always true in debug mode
* when noCache is true we return an explicit "Cache-Control: no-cache" line

Change-Id: I157a410df0a90f9ab151b899e44566b95cbd9929
Reviewed-on: https://gerrit.libreoffice.org/54517
Reviewed-by: Michael Meeks <michael.meeks@collabora.com>
Tested-by: Michael Meeks <michael.meeks@collabora.com>
2018-05-18 14:17:23 +02:00
Michael Meeks
adb3112820 Use inet_ntop for ipv6 address names.
Change-Id: Ic52b69eb2dc86b6532a78d770531b2fac928fb28
2018-05-14 12:03:17 +01:00
Michael Meeks
b5a1af763c Share HTTP header parsing inside the StreamSocket.
Change-Id: Id98e895a939d931ac10b7cd7403da4cbe822ee82
2018-05-01 16:29:56 +01:00
YiiChang Yen
910ae806ef wsd: to filter clientAddress before POST action.
Change-Id: I293580f041bc46b36c57f63fe4a2c0131763b3c1
Reviewed-on: https://gerrit.libreoffice.org/50977
Reviewed-by: pranavk <pranavk@collabora.co.uk>
Tested-by: pranavk <pranavk@collabora.co.uk>
2018-04-30 18:50:06 +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
Ashod Nakashian
7be98efd93 ut: log timestamp to track timeouts better
And improve the logging support in unit-tests to
help troubleshoot issues faster and more accurately.
Also makes the code more readable (hopefully).

Change-Id: I4f8aafb5245e2f774b03231591a74544f9ec84aa
Reviewed-on: https://gerrit.libreoffice.org/48645
Reviewed-by: Ashod Nakashian <ashnakash@gmail.com>
Tested-by: Ashod Nakashian <ashnakash@gmail.com>
2018-02-11 19:21:15 +01:00
Pranav Kant
39f11ab4f7 document conflict: unit test
Change-Id: I4ea310fe5adb198bc7b5e083f6bd4b0431c0cdef
2018-02-09 00:22:57 +05:30
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
Michael Meeks
a1ee97c222 Add IPv6 support, and configuration option.
Default to listening on both IPv44 and IPv6 for public interfaces.

Change-Id: Ib04e3bf65e7dcf2a798d381297b15ee9c56e9259
2018-01-09 22:03:17 +00:00
Ashod Nakashian
57d535b15b wsd: lambda cleanup and better readability
Change-Id: Iabb850be7a7c162847514ee0fb600297accfcffb
Reviewed-on: https://gerrit.libreoffice.org/47364
Reviewed-by: Ashod Nakashian <ashnakash@gmail.com>
Tested-by: Ashod Nakashian <ashnakash@gmail.com>
2018-01-06 22:13:50 +01:00
Pranav Kant
9cbef14160 loplugin:nullptr
Change-Id: I5f0dc970e8522b63570faa0ba05ab19dd0f45d5a
2017-12-20 22:36:41 +05:30
Pranav Kant
f63858433b loplugin:includeform
Change-Id: Ib62a7aa61062f00698aa3e8a144438de5c57e53d
2017-12-20 21:21:05 +05:30
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
Michael Meeks
0778b72697 Dump hex contents of un-shared memory.
Change-Id: I47dfa8a0b48d0ba34b7462301b83e2721617814d
2017-11-29 03:33:16 +00:00
Pranav Kant
483a5d68e5 tdf#114073: Potential fix for crash with openssl1.1
Using null ssl context to set options is surely not a good idea:

unsigned long SSL_CTX_set_options(SSL_CTX *ctx, unsigned long op)
{
    return ctx->options |= op;
}

Change-Id: I2700350e0c3928e372488c81b8111c9ab0b48e06
2017-11-27 16:31:21 +05:30
Michael Meeks
ec80d623b8 Edit the right configuration XML file.
Change-Id: If72006918550ee5c440ad6b2ff26a5bd0d1efef1
2017-11-22 16:47:05 +00:00
Michael Meeks
92379ffbf2 Make the WSD SSL cipher list configurable.
Change-Id: If79b9efc9438cf0a2345b8e81385adafef63ce22
2017-11-22 15:55:03 +00: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
Christian Glombek
702bbdd5d8 Add Support for OpenSSL 1.1.0
Change-Id: I0aa58b893e8577bba94fa45c0c4c81449b12e4e2
Reviewed-on: https://gerrit.libreoffice.org/42356
Reviewed-by: Ashod Nakashian <ashnakash@gmail.com>
Reviewed-by: Thorsten Behrens <Thorsten.Behrens@CIB.de>
Tested-by: Thorsten Behrens <Thorsten.Behrens@CIB.de>
2017-09-20 03:48:08 +02:00
Miklos Vajna
f375a9d5de Socket: mark setNoDelay() as non-virtual
No derived classes override it, and if they would, that would be a
problem, as setNoDelay() is called from init(), which is called from the
Socket ctor. Calling virtual functions from the base class ctor is not a
good idea, since the object is not fully constructed yet.

Change-Id: I4993e26d09f5d3429c7e2afae7688b84c0061c9d
2017-09-18 10:15:59 +02:00
Miklos Vajna
bcb5b744b8 net, wsd: fix -Werror,-Wdelete-non-virtual-dtor warnings
Two problem types:

- non-final class has virtual functions but no virtual dtor -> mark the
  class final
- abstract class has no virtual dtor -> add a virtual dtor

Change-Id: Iae208b65c774e6da7a3dda5e725fe07d4d589e4f
2017-09-12 10:03:32 +02:00
Ashod Nakashian
4f8ebca0cb wsd: free leaking memory
With help from Valgrind to find and verify
these leaks.

Change-Id: I3afeed89dc4bcd714a222f81822144477a346fb0
Reviewed-on: https://gerrit.libreoffice.org/39464
Reviewed-by: Ashod Nakashian <ashnakash@gmail.com>
Tested-by: Ashod Nakashian <ashnakash@gmail.com>
2017-07-03 05:42:38 +02:00
Miklos Vajna
4faa3d5a70 net: remove unused using declarations in clientnb
Change-Id: Ifa7aed29160b49930c41f7cc465c8315bfca9992
2017-06-23 10:29:44 +02:00
Miklos Vajna
ffbe55adb5 SocketDisposition::setMove(): parameter is passed by value, move it
Change-Id: I2c7facfc4fc5422cef886c6ba28ac60c656a908e
2017-06-21 09:07:27 +02:00
Michael Meeks
3101fa510d Accumulate I/O stats per document.
Change-Id: Ie2f5647e65070ddd828f048820efd38b600f9133
2017-06-02 20:41:25 +01:00
Michael Meeks
c224413a9d Track bytes recv'd and sent on StreamSockets.
Dump on USR1 as part of our state.

Change-Id: I4c6b87c19bca768402c9b0b8e26f16336e007749
2017-05-26 15:54:58 +01: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
Ashod Nakashian
7cff4fb08a wsd: fix server shutdown
Thread-affinity checks must be inhibited
not just on Socket, but on the SocketPoll as well,
before destroying DocumentBroker instances.

Also, properly initialize the inhibit statics.

Change-Id: I2ced1554d477f0c3faf09bda74034cbae99e4ce1
Reviewed-on: https://gerrit.libreoffice.org/37608
Reviewed-by: Ashod Nakashian <ashnakash@gmail.com>
Tested-by: Ashod Nakashian <ashnakash@gmail.com>
2017-05-15 05:10:31 +02:00
Michael Meeks
29b92444b1 Stream dumpHex output to an output stream.
Also output debug directly to stderr to avoid std::cerr re-direction.

Change-Id: Ib2a0eaa3514ef88d7fe8d8fbb3706925aabf3346
2017-05-12 03:06:49 +01:00
Michael Meeks
495d6da532 Reset ownership before executing the socket move.
Change-Id: I98532e59ef9c78a6cc1eb25a5a8535c4e2d9b15d
2017-05-09 13:02:23 +01:00
Michael Meeks
c04e4ffa16 loolnb - kill obsolete test app.
Change-Id: I5943cc0752f16d62d6eedf96351bb6f71a2311e6
2017-05-05 18:53:00 +01: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
Michael Meeks
faf24f7888 SocketDisposition - controls socket movement & lifecyle.
It is important that moving sockets between polls happens in a
safe and readable fashion, this enforces that.
2017-04-25 22:49:08 +01:00
Michael Meeks
ec12a0e16b DelaySocket: kill warning. 2017-04-24 11:39:31 +01:00
Ashod Nakashian
8b3a2ed9d7 wsd: reduce included headers
Change-Id: I3107b18b2edae34a76e9f56a5cbd24836b1b57c0
Reviewed-on: https://gerrit.libreoffice.org/36872
Reviewed-by: Ashod Nakashian <ashnakash@gmail.com>
Tested-by: Ashod Nakashian <ashnakash@gmail.com>
2017-04-24 06:52:02 +02:00
Ashod Nakashian
988ddaf7be wsd: cleanup sendFile to allow header-only response
HTTP HEAD verb requires sending back NO content.

Currently we don't support HEAD and that harms
the browser from using its cache where possible.

Change-Id: I3c67dc106df95312c73f6ae786b7b1657a4167fb
Reviewed-on: https://gerrit.libreoffice.org/36871
Reviewed-by: Ashod Nakashian <ashnakash@gmail.com>
Tested-by: Ashod Nakashian <ashnakash@gmail.com>
2017-04-24 06:47:42 +02:00
Michael Meeks
5d0e4fa020 DelaySocket: hide logging. 2017-04-22 18:42:16 +01:00
Michael Meeks
63aba6be1a DelaySocket: working, and much cleaner / simpler. 2017-04-22 18:42:16 +01:00
Michael Meeks
26a6d514d5 DelaySocket - simplified but working.
Assume for now that we have infinite space in-transit.
2017-04-22 18:42:16 +01:00
Michael Meeks
1c7f94045a Initial DelaySocket goodness. 2017-04-22 18:42:16 +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
9b3a22aafe wsd: save document upon server shutdown
The server correctly saves all documents
and waits to upload them before exiting.

Change-Id: I04dc9ce588bc0fa39a9deb298d0a5efa61a03f1a
Reviewed-on: https://gerrit.libreoffice.org/36654
Reviewed-by: Ashod Nakashian <ashnakash@gmail.com>
Tested-by: Ashod Nakashian <ashnakash@gmail.com>
2017-04-19 07:04:26 +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
Jan Holesovsky
e0f7c3fc67 Set the _owner even in the release builds.
We are warning about thread affinity even in the non-debug builds.

Change-Id: Ia91170765e9f4a29939dee847899345e9396d2c3
2017-04-10 14:55:04 +02:00
Ashod Nakashian
cdb80e5632 wsd: assert valid socket where it counts
Change-Id: I19faa175066cab4e0435f6a8bf29e6b051c86420
Reviewed-on: https://gerrit.libreoffice.org/36330
Reviewed-by: Ashod Nakashian <ashnakash@gmail.com>
Tested-by: Ashod Nakashian <ashnakash@gmail.com>
2017-04-10 06:09:21 +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
Ashod Nakashian
2ad3cd4de1 wsd: don't call virtuals in dtors
Change-Id: I2490e2f63dc20cf6b3fa0be45341b041e3ccb1bf
Reviewed-on: https://gerrit.libreoffice.org/36321
Reviewed-by: Ashod Nakashian <ashnakash@gmail.com>
Tested-by: Ashod Nakashian <ashnakash@gmail.com>
2017-04-10 06:06:27 +02:00
Pranav Kant
61b7112aa7 security: X-Content-Type-Options: nosniff
Don't think it is necessary/useful to have this header at other places.
This is the most important and perhaps the only where presence of this
header is required and seems sensible to prevent potential attacks.

Change-Id: Iad318e4b83264ac83620b86a40a49e7384e4015e
2017-04-09 23:32:06 +05:30
Michael Meeks
254de88a58 Clear ownership of socket while it is being transferred.
This addresses a gap between ServerSocket accepting new sockets,
and their being added to their new polls.
2017-04-07 20:59:34 +01:00
Miklos Vajna
b31474690a net: Socket::assertCorrectThread() can be non-virtual
None of the subclasses override it, and if they would, it would be
problematic, since e.g. the StreamSocket dtor calls it (and virtual
calls during dtors are a problem).

Change-Id: Ie0891349808a81539078fd1f2d95a55a4ce5107a
2017-04-07 09:40:00 +02:00
Michael Meeks
3d945a5c38 Revert "Don't cleanup DocumentBrokers that still have their thread running."
This reverts commit df8dc43be4.

DocumentBroker::isAlive already checks _threadFinished.
2017-04-06 16:35:55 +01:00
Michael Meeks
df8dc43be4 Don't cleanup DocumentBrokers that still have their thread running.
Plenty of time to do that next time around the cleanup.
We should still, really be doing the majority of the timeout work
inside the DocumentBroker poll itself.
2017-04-06 16:24:54 +01:00
Pranav Kant
2124ec30c6 net: Disable deflate unconditionally
First reason is that compression is very slow, and we re-compress the
files again and again.

Another reason is that IE/Edge doesn't work well with deflate turned on.
Related: https://connect.microsoft.com/IE/feedbackdetail/view/950689
The documents are not loaded at all with current code snapshot modulo
this patch.

Change-Id: I1fdd85856f448dc4ce02e1ab79e9c7474c3bb7f3
2017-04-06 20:40:51 +05:30
Ashod Nakashian
a4176cf2f5 wsd: don't invoke poll handler when invalidated
Only during shutdown do we expect a callback
to invalidate the pollSockets, but if it happens
we shouldn't invoke the poll handlers.

Change-Id: I2f56da19aec2f04cc871bd4eae1f93da110e0eb9
Reviewed-on: https://gerrit.libreoffice.org/36189
Reviewed-by: Ashod Nakashian <ashnakash@gmail.com>
Tested-by: Ashod Nakashian <ashnakash@gmail.com>
2017-04-06 07:37:51 +00:00
Ashod Nakashian
3d03a0fb5d wsd: accomodate accept_poll shutdown
When shutting down accept_poll from
main, we can't remove sockets or cleanup.
That work needs to be done fro within accept_poll's
thread. This is different from when DocBroker's
poll needs to cleanup its own sockets before
it exists.

So we split the stop and removeSockets so they
can each be called in the proper way.

For accept_poll and others that joinThread
we queue a callback to cleanup before stopping.

Change-Id: If780d6a97ac0fc6da6897f895d5b4dda443f9e73
Reviewed-on: https://gerrit.libreoffice.org/36186
Reviewed-by: Ashod Nakashian <ashnakash@gmail.com>
Tested-by: Ashod Nakashian <ashnakash@gmail.com>
2017-04-06 07:01:18 +00:00
Ashod Nakashian
4a7a0fb477 wsd: remove sockets when stopping poll thread
And assume correct thread if poll thread is
not running (i.e. no race).

Change-Id: I17958e682aba434ebb47fe0de199b9f530b54dee
Reviewed-on: https://gerrit.libreoffice.org/36183
Reviewed-by: Ashod Nakashian <ashnakash@gmail.com>
Tested-by: Ashod Nakashian <ashnakash@gmail.com>
2017-04-06 06:19:06 +00:00
Ashod Nakashian
cbe6f0c813 wsd: move prisoner socket in the poll thread
Change-Id: I4097da97d4485d98618604c039a4570efe52bc19
Reviewed-on: https://gerrit.libreoffice.org/36181
Reviewed-by: Ashod Nakashian <ashnakash@gmail.com>
Tested-by: Ashod Nakashian <ashnakash@gmail.com>
2017-04-06 06:12:39 +00:00
Michael Meeks
737f7111b0 Set thread owner to zero earlier to avoid race.
Stop-gap fix, while we come up with a nice API for transferring
sockets between SocketPolls, and/or detaching them generally.
2017-04-05 21:01:48 +01:00
Michael Meeks
185540bcde Inhibit thread checks for SIGUSR1 handling.
USR1 handling is not thread-safe; we walk the structures and hope.
2017-04-05 17:58:52 +01:00
Jan Holesovsky
b6270fae57 setThreadOwner() is now needed in the release builds too.
Change-Id: I1a60bcbac4251866739fee59994a202394339015
2017-04-05 14:54:54 +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
Jan Holesovsky
37387518f4 Suppress assert()'s in the production builds.
Change-Id: I2074ed335b7201337e6519440ff6bed1809be915
2017-04-05 12:03:33 +02:00
Jan Holesovsky
d345c29a47 The other isCorrectThread() should be active only in the debug build too.
Change-Id: Ieadb7e14f70752f5cfb2fd9ee569b56fb39d528b
2017-04-05 11:38:48 +02:00
Ashod Nakashian
463f26f417 wsd: mark detached sockets to have no owner
The DocBroker might not get a chance to
take ownership of a socket (which is done
via callbacks that are invoked in the poll loop)
if it (or WSD) is flagged for termination.

In that case, DocBroker doesn't take ownership
but ultimately needs to disconnect the socket.

By detaching ownership we signal that any thread
can rightly take ownership and thus avoid spurious
warning or assertions.

Change-Id: Idb192bfaac05c5c86809cb21876f3926a080b775
Reviewed-on: https://gerrit.libreoffice.org/36117
Reviewed-by: Ashod Nakashian <ashnakash@gmail.com>
Tested-by: Ashod Nakashian <ashnakash@gmail.com>
2017-04-05 04:47:30 +00:00
Ashod Nakashian
cbd78484ad wsd: warn when waking dead poll
And insert sockets after starting the
thread so we poll the socket immediately.

Change-Id: Id336e1838f2f624ebfe59c4c2caf33eaa1a638c9
Reviewed-on: https://gerrit.libreoffice.org/36110
Reviewed-by: Ashod Nakashian <ashnakash@gmail.com>
Tested-by: Ashod Nakashian <ashnakash@gmail.com>
2017-04-05 04:41:23 +00:00
Michael Meeks
61d912cd6f Use heap buffers for file transfer and disable deflate for now. 2017-04-04 13:18:11 +01:00
Ashod Nakashian
b734284b59 wsd: cleanup deflating HTTP responses
Change-Id: Id21bdfcb5d3e04f27b681ee9581a0ed06283d163
Reviewed-on: https://gerrit.libreoffice.org/36058
Reviewed-by: Ashod Nakashian <ashnakash@gmail.com>
Tested-by: Ashod Nakashian <ashnakash@gmail.com>
2017-04-04 04:29:23 +00:00
Ashod Nakashian
7ca1f03770 wsd: don't invoke onDisconnect from wrong thread
...and warn if we are in the wrong thread.

This can happen when the socket is not properly
closed from the poll thread and is being destroyed.

Change-Id: I749c09b15d04b49038f7cee6a7a13e8f0145acff
Reviewed-on: https://gerrit.libreoffice.org/36057
Reviewed-by: Ashod Nakashian <ashnakash@gmail.com>
Tested-by: Ashod Nakashian <ashnakash@gmail.com>
2017-04-04 04:18:52 +00:00
Ashod Nakashian
762ba09370 wsd: fix SSL initialization/uninitialization error
Valgrind found a number of erroneous data access
during the construction and destruction of SslContext.

Change-Id: Ie5072798a3660ed8acc707ba32ac196fa2d0f8af
Reviewed-on: https://gerrit.libreoffice.org/36055
Reviewed-by: Ashod Nakashian <ashnakash@gmail.com>
Tested-by: Ashod Nakashian <ashnakash@gmail.com>
2017-04-04 04:16:53 +00:00
Jan Holesovsky
a9389687a4 Don't try to clean up after a runtime error.
We don't know in what state we are...

Change-Id: I8d144000ba684ca23ff67977959c95b31de34367
2017-04-03 11:39:09 +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
Ashod Nakashian
78d1cc4ac5 wsd: process callbacks before poll handlers
Callbacks are used to initialize handlers,
as is the case with addSession on DocumentBroker.

If the socket gets data before the callback is
invoked, the handler will fail since the expected
initialization hasn't happened yet.

This race indeed happens (rarely) with addSession.

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

Change-Id: Id9b4f63b45c5564add252e1671b7b0b08aff8150
Reviewed-on: https://gerrit.libreoffice.org/36035
Reviewed-by: Ashod Nakashian <ashnakash@gmail.com>
Tested-by: Ashod Nakashian <ashnakash@gmail.com>
2017-04-03 05:16:05 +00:00
Ashod Nakashian
6e596d11f3 wsd: catch exceptions from callbacks and wakup hook
Change-Id: Ib4579a34c91cfe43e5bd7038b175175a9ab0036a
Reviewed-on: https://gerrit.libreoffice.org/36033
Reviewed-by: Ashod Nakashian <ashnakash@gmail.com>
Tested-by: Ashod Nakashian <ashnakash@gmail.com>
2017-04-03 05:14:58 +00:00
Ashod Nakashian
d7858b08b9 wsd: fix race in setting SocketPoll owner thread id
Change-Id: Idace925ab02425ed66ac07efc22ab933d229d42e
Reviewed-on: https://gerrit.libreoffice.org/36032
Reviewed-by: Ashod Nakashian <ashnakash@gmail.com>
Tested-by: Ashod Nakashian <ashnakash@gmail.com>
2017-04-03 05:14:23 +00:00
Ashod Nakashian
d6577654bd wsd: initialization and logging
Change-Id: Icd82a966b94875a65ddb3817c88a3c4c7bedd4ff
Reviewed-on: https://gerrit.libreoffice.org/36030
Reviewed-by: Ashod Nakashian <ashnakash@gmail.com>
Tested-by: Ashod Nakashian <ashnakash@gmail.com>
2017-04-03 05:13:14 +00:00
Ashod Nakashian
e0822f8516 wsd: better thread affinity logging
Change-Id: I9e4bc3fe864aa409dc4874a9d6fc4ab22bfea592
Reviewed-on: https://gerrit.libreoffice.org/36029
Reviewed-by: Ashod Nakashian <ashnakash@gmail.com>
Tested-by: Ashod Nakashian <ashnakash@gmail.com>
2017-04-03 05:11:57 +00:00
Michael Meeks
aeb204fb14 Kill race during DocumentBroker shutdown over child process.
==20033== Invalid read of size 4
==20033==    at 0x466504: ChildProcess::close(bool) (DocumentBroker.hpp:111)
==20033==    by 0x44EA28: DocumentBroker::terminateChild(std::string const&, bool) (DocumentBroker.cpp:1313)
==20033==    by 0x45F70E: DocumentBroker::pollThread() (DocumentBroker.cpp:264)
==20033==    by 0x504B2F: SocketPoll::pollingThreadEntry() (Socket.hpp:486)
==20033==    by 0x7310E6F: execute_native_thread_routine (thread.cc:84)
==20033==    by 0x7AF60A3: start_thread (pthread_create.c:309)
==20033==    by 0x7DF002C: clone (clone.S:111)
==20033==  Address 0x0 is not stack'd, malloc'd or (recently) free'd
2017-03-31 17:28:20 +01: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
Michael Meeks
913c469aa8 Cleanup whitespace, return is not a function. 2017-03-30 17:34:52 +01:00
Michael Meeks
a4ac00d854 Add zlib cflags and libs to configuration. 2017-03-30 12:09:12 +01:00
dewana-dewan
4322045667 tdf#106579 - serving gzipped file content
Change-Id: I320b22babf1bf65a0f1d4b1809a6ffb1f5ec8344
2017-03-30 12:09:12 +01:00
Jan Holesovsky
1d335b92ce Avoid extensive warning about a normal situation.
Change-Id: Ie67a12847afddac087f74e4872744b2b8bb07b1e
2017-03-30 11:21:10 +02:00
Ashod Nakashian
492b818022 wsd: warn if isCorrectThread will fail
Change-Id: I362b23e651c00a6514bd1e44fa0961269252bcdd
2017-03-29 23:55:19 -04: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
fbf3b87626 wsd: simplify and cleanup session creation
Change-Id: I8cc05bc7a8dc89c6a521b81c6d59ff1e9968763a
Reviewed-on: https://gerrit.libreoffice.org/35789
Reviewed-by: Ashod Nakashian <ashnakash@gmail.com>
Tested-by: Ashod Nakashian <ashnakash@gmail.com>
2017-03-28 05:15:28 +00:00
Michael Meeks
e26079eecb tdf#106797 - avoid locking up / crashing on exceptions from main. 2017-03-27 20:15:30 +01:00
Ashod Nakashian
6d7f39356c wsd: flush sockets before exiting DocBroker poll thread
Change-Id: Id5384c113bd761b5b8c25286f1bd5a28051c63d3
Reviewed-on: https://gerrit.libreoffice.org/35740
Reviewed-by: Ashod Nakashian <ashnakash@gmail.com>
Tested-by: Ashod Nakashian <ashnakash@gmail.com>
2017-03-27 03:21:38 +00:00
Ashod Nakashian
f2f0040275 wsd: use isCorrectThread
Change-Id: Id63c30b19489d590b995e0ea66ef2f44e8cddfb7
Reviewed-on: https://gerrit.libreoffice.org/35738
Reviewed-by: Ashod Nakashian <ashnakash@gmail.com>
Tested-by: Ashod Nakashian <ashnakash@gmail.com>
2017-03-27 03:20:43 +00: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
Ashod Nakashian
c1ffb64904 wsd: correct shutdown status code echoed back
Change-Id: Ieb685135ab280ed76070af3392bfa69cf313f35a
Reviewed-on: https://gerrit.libreoffice.org/35708
Reviewed-by: Ashod Nakashian <ashnakash@gmail.com>
Tested-by: Ashod Nakashian <ashnakash@gmail.com>
2017-03-26 05:08:46 +00:00
Ashod Nakashian
3895897213 wsd: improved socket logging
Change-Id: Ib4751a5a73b7ec0c7ca319f552d5e0aaff06ffea
Reviewed-on: https://gerrit.libreoffice.org/35707
Reviewed-by: Ashod Nakashian <ashnakash@gmail.com>
Tested-by: Ashod Nakashian <ashnakash@gmail.com>
2017-03-26 05:07:37 +00:00
Michael Meeks
ce0dffdc12 Use callback API to implement alertAllUsers safely and simply. 2017-03-21 08:31:20 +00:00
Ashod Nakashian
dc90499514 wsd: remove the socket on move
Avoid explicit socket removal too.

Change-Id: I44d773761a5a463aad828c19c6b394bb6bac63d8
2017-03-20 23:26:06 -04:00
Ashod Nakashian
b01e555b47 wsd: correct copying of socket shutdown message
Avoid segfaulting.

Change-Id: I320606937a0d3a3e53270a70ef0a00fcb01b855a
2017-03-20 23:25:54 -04:00
Ashod Nakashian
53da72a1dc wsd: fix hot looping the poll
When not sending ping the ping time is not set
which results in the setting the poll timeout to
a negative value, forcing it to return immediately.

This happens when sending ping before upgrading
to WebSocket, which isn't common. One way to
reproduce it, however, is to connect to the
admin console with an unauthenticated socket.

Change-Id: I9f3db1a02b8f8e2781d23d843e848068ad434958
2017-03-20 00:41:54 -04:00
Ashod Nakashian
e9675ed6e1 wsd: close socket when WS close handshake is complete
We shouldn't send any more data after the client
shuts down, or after we initiate shutdown.

Change-Id: Ibf0cf61dcabe9d02ddcb7eb40b2df23712c5a136
2017-03-20 00:41:53 -04:00
Ashod Nakashian
6283dbd9cc wsd: copy and un-mask web-socket data at the same time
Change-Id: I2a4831065ae0a81f20d0513b0772d7d427ffc4ea
2017-03-20 00:41:53 -04:00
Ashod Nakashian
0d3ea2bbfd wsd: flag thread start before creating thread
This prevents a race where the thread is started
a second time before the first gets a chance to
set the flag.

Change-Id: Ib106aa0626cdfa403b321822180b0545d3aa9139
2017-03-20 00:41:53 -04:00
Ashod Nakashian
14779f5cd4 wsd: return moved socket state to stop any IO processing
Once a socket has changed ownership to a new
poll it will assert thread affinity with said
new poll. So we cannot do any IO on the old
poll's thread at that point and on.

Change-Id: I662f188dea7c377a18f3e546839ec43f2875dc7b
2017-03-20 00:41:53 -04:00
Ashod Nakashian
7096133f07 wsd: log thread affinity violations
Change-Id: Ib1317bc71f9162f005e0ce9b8c715bbce656db73
2017-03-20 00:41:53 -04:00
Michael Meeks
50661924b7 Dump much more ClientSession state, and also websocket latency. 2017-03-18 15:03:04 +00:00
Michael Meeks
0d8809f0ca Get warning logic right on wakeup socket. 2017-03-18 15:03:04 +00:00
Michael Meeks
b8b5cc2069 Shorten time to send first ping - to assess socket latency.
Also ensure we never send a ping on a non-upgraded websocket.
2017-03-18 15:03:04 +00:00
Michael Meeks
a6a4094e52 Send ping message, handle pong & store ping-time on the Websocket. 2017-03-17 22:59:03 +00:00
Michael Meeks
9381d4134f Unify and simplify timeout and poll events setup.
Both happen at the same time, and need support from the
SocketHandlerInterface.

Rename hasQueuedWrites to getPollEvents and merge updateTimeout.
2017-03-17 22:00:28 +00:00
Michael Meeks
3a5ca4b03f Switch to std::chrono from Poco::Time and simplify lots. 2017-03-17 21:13:11 +00:00
Michael Meeks
e9dbab6900 Always call handlePoll so we can handle timeouts. 2017-03-17 21:13:11 +00:00
Michael Meeks
e7ebe0fdaa remove obsolete Poco headers, and Poco SSL pieces. 2017-03-16 18:03:23 +00:00
Michael Meeks
69feb165dd Remove websocket assert on performWrites.
Since commit 862d7a0734
      wsd: write as many messages to socket as possible:

This can be called even if hasQueuedWrites returns false.
2017-03-16 17:23:42 +00:00
Michael Meeks
f392d9e6f0 Move http serving into socket impl.
Avoid caching headers with parameter, and add Date: parameter.
2017-03-15 18:21:59 +00:00
Michael Meeks
909b5f8ac3 Admin: should be its own socket-poll goodness. 2017-03-15 16:13:13 +00:00
Ashod Nakashian
fa1dc4e051 wsd: wrap polling thread and manage state correctly
Change-Id: Iaa4eff1fac1cd7147603ba0c9d51fd8b6b0e96d2
2017-03-15 00:04:55 -04:00
Ashod Nakashian
c8bece208d wsd: socket logs include socket FD for better traceability
Change-Id: I994c7c5ab73b97be312a9d6abf3258dc5f4c08c1
2017-03-15 00:04:55 -04:00
Ashod Nakashian
aa19964b03 wsd: SSL logging improvement
Change-Id: I99d08a764fd43ab0c7eb50a1f017202e6bbc3477
2017-03-15 00:04:55 -04:00
Ashod Nakashian
45e1c7763c wsd: Socket stores SocketHandler shared_ptr
Change-Id: I5b460069eb4d91cee2d58833791f961fd6f42b39
2017-03-15 00:04:55 -04:00
Ashod Nakashian
b258355039 wsd: StreamSocket supports changing its SocketHandler
Change-Id: I2ffc33daad4da5b98183af39e3c2a64e7e10b3e8
Reviewed-on: https://gerrit.libreoffice.org/35158
Reviewed-by: Ashod Nakashian <ashnakash@gmail.com>
Tested-by: Ashod Nakashian <ashnakash@gmail.com>
2017-03-14 04:31:22 +00:00
Ashod Nakashian
8b9623010a wsd: sendHttpResponse -> send
Change-Id: I7c94f6d4cd1054ea86585bfcd4079140471f3518
Reviewed-on: https://gerrit.libreoffice.org/35157
Reviewed-by: Ashod Nakashian <ashnakash@gmail.com>
Tested-by: Ashod Nakashian <ashnakash@gmail.com>
2017-03-14 04:30:55 +00:00
Michael Meeks
bf8068de18 Clarify comment a little. 2017-03-13 13:42:05 +00:00
Andras Timar
07c0452ec1 fix error: unused parameter 'hard' [-Werror=unused-parameter]
Change-Id: Ie2f2a12cc2f5d6c2fd3319d3c870cc7f0a226fae
2017-03-13 13:22:56 +01:00
Michael Meeks
97e9463f17 Revert "wsd: TerminatingPoll always starts its own thread"
This reverts commit 388d7b1dbf.

It is vital to have clean control of thread start. By starting
a thread during init. of a member (or base-clase) we loose lots of
control, some examples:

	Any members initialized after a member that auto-starts a
	thread, is effectively un-defined, and cannot be accessed
	reliably.

	This is particularly problematic for sub-classes.

	I've seen threads started before the base-class has
	finished constructing in the original creating thread -
	such that the vtable was not yet updated to the sub-class
	causing the transient parent vtable used during construction
	to be used in-error.
2017-03-13 12:13:22 +00:00
Ashod Nakashian
94051f21b5 wsd: SocketPoll::startThread can be protected
Change-Id: Idd17f7314ac181e9a412e05a1287e15edf5047d2
Reviewed-on: https://gerrit.libreoffice.org/35125
Reviewed-by: Ashod Nakashian <ashnakash@gmail.com>
Tested-by: Ashod Nakashian <ashnakash@gmail.com>
2017-03-13 04:25:20 +00:00
Ashod Nakashian
c4d27fd060 wsd: prevent and warn when joining own thread
Change-Id: I8405a1aacb1281e52bbd07d32cdcf35bdc484d8b
Reviewed-on: https://gerrit.libreoffice.org/35124
Reviewed-by: Ashod Nakashian <ashnakash@gmail.com>
Tested-by: Ashod Nakashian <ashnakash@gmail.com>
2017-03-13 04:25:04 +00:00
Ashod Nakashian
862d7a0734 wsd: write as many messages to socket as possible
Change-Id: Ie2702ea68dd1ae6200fcc304224dea34fc94544f
Reviewed-on: https://gerrit.libreoffice.org/35123
Reviewed-by: Ashod Nakashian <ashnakash@gmail.com>
Tested-by: Ashod Nakashian <ashnakash@gmail.com>
2017-03-13 04:24:37 +00:00
Ashod Nakashian
9248107702 wsd: SocketPoll reports thread isAlive and use in DocBroker
Now that DocumentBroker has SocketPoll thread,
it's isAlive() must be defined by the lifetime of
both the SocketPoll thread and the ChildProcess,
which it previously did.

Change-Id: I093f8774cf4374d01729a383f6c535de4143fec6
Reviewed-on: https://gerrit.libreoffice.org/35122
Reviewed-by: Ashod Nakashian <ashnakash@gmail.com>
Tested-by: Ashod Nakashian <ashnakash@gmail.com>
2017-03-13 04:23:18 +00:00
Ashod Nakashian
c9a07a3087 wsd: assert socket is in correct thread
Change-Id: I22c3f62bdf45188641326774dd86b7cacfce9198
Reviewed-on: https://gerrit.libreoffice.org/35120
Reviewed-by: Ashod Nakashian <ashnakash@gmail.com>
Tested-by: Ashod Nakashian <ashnakash@gmail.com>
2017-03-13 04:20:41 +00:00
Ashod Nakashian
04bbb75200 wsd: dump state to generic ostream for flexiblity and to log
Change-Id: I4670ee2e90b7809ebc66a2b324a44334b3dbba2b
Reviewed-on: https://gerrit.libreoffice.org/35119
Reviewed-by: Ashod Nakashian <ashnakash@gmail.com>
Tested-by: Ashod Nakashian <ashnakash@gmail.com>
2017-03-13 04:19:58 +00:00