Commit graph

706 commits

Author SHA1 Message Date
Noel Grandin
0969f25685 make sure modifiedTimeUs calculates with enough precision
otherwise, on some platforms, the calculation might occur with 32-bits, but we really need 64 bits for microseconds.
Also tweak the return type to make sure we use 64 bits.

Signed-off-by: Noel Grandin <noel.grandin@collabora.co.uk>
Change-Id: Ie8b8a49938c7ac2cfe7c5fc1dd6629e6ea347115
2022-01-26 10:23:36 +01:00
Aron Budea
65e3a54857 wsd: Adjust log levels
A non-writable path isn't an error in itself.

The reason why the service tried to write the systemplate,
and the perf implications is worth reporting even on default
log level.

Signed-off-by: Aron Budea <aron.budea@collabora.com>
Change-Id: Ie168875ceb4e501291676a5aa4ddc21b88c5761f
2022-01-23 13:31:17 -05:00
Yunusemre Şentürk
d15c0a6f0f use gmtime_r instead of std::gmtime for thread safe purposes
Change-Id: I3490c1353d9e2eebc3dc856fe5bd4767df4b1bec
Signed-off-by: Yunusemre Şentürk <yunusemre@collabora.com>
2022-01-21 16:51:46 +01:00
Michael Meeks
51a5b129ac fileutil: ubsan - clear state records before stat / lstat.
If these fail, we wstill want something sensible to go on.

Signed-off-by: Michael Meeks <michael.meeks@collabora.com>
Change-Id: Iabd8b60a67808a17767ac63037636e3aadd7be48
2022-01-20 15:46:50 -05:00
Ashod Nakashian
f95ff8205a wsd: test: fail when modified docs are unsaved
Change-Id: I444948ce96ff512491fe72f55a7b5abfcf1dab4e
Signed-off-by: Ashod Nakashian <ashod.nakashian@collabora.co.uk>
(cherry picked from commit 11dad9c87a979eee0fac9c85ea3387174da61760)
2022-01-11 09:28:03 +01:00
Ashod Nakashian
65d5a4f1a5 wsd: test: add slow save and upload test
Change-Id: I5c7e706a1ded7774c9da4545218ba9fa29fc9d81
Signed-off-by: Ashod Nakashian <ashod.nakashian@collabora.co.uk>
(cherry picked from commit 29c26c9afee593c20bc72a668ba0c3d5634aa35b)
2022-01-11 09:28:03 +01:00
Ashod Nakashian
cdccf4d820 wsd: test: improved test state machine
This adds a better automatic test state
enum, with support for transitions.

It is intended to be used only in tests,
to simplify the writing of tests around
a state-machine.

Signed-off-by: Ashod Nakashian <ashod.nakashian@collabora.co.uk>
(cherry picked from commit bf5e8a2d9f3b2fe99f5b46bcbd4c9e3e28853af5)

Change-Id: I8805dad57ca3c71c26cc30236d4832710e1717f9
2022-01-11 09:28:03 +01:00
Ashod Nakashian
aad22ee83c wsd: test: better logging
Signed-off-by: Ashod Nakashian <ashod.nakashian@collabora.co.uk>
(cherry picked from commit ec3613ba2df43cffe6baafafa41e5337a43070aa)

Change-Id: I5e245d0ac5c185943586d6aec651f606f8e23bb8
2022-01-11 09:28:03 +01:00
Michael Meeks
15dc307107 signal activity: add some more helpful call sites.
Based on previous crashes, it is useful to have more granularity
on what happened last.

Change-Id: If18a3a4d7817be23a6f8aadd301827a8e1bc007e
Signed-off-by: Michael Meeks <michael.meeks@collabora.com>
2022-01-10 13:03:37 +00:00
Michael Meeks
9354fc829d signal activity dumping; overdue cleanup / re-factor.
Change-Id: I7cb3047488f6daffbb5de285dfc5631c4dd89c8e
Signed-off-by: Michael Meeks <michael.meeks@collabora.com>
2022-01-10 13:03:37 +00:00
Michael Meeks
bfb7104bdd Avoid (erroneous) warnings on iOS.
Change-Id: Ibeb44383622b8471abaebfb6ce1d503e264963c4
Signed-off-by: Michael Meeks <michael.meeks@collabora.com>
2022-01-10 13:03:37 +00:00
Pranam Lashkari
75f37bb1df freemium: added option to make freemium user read only
Signed-off-by: Pranam Lashkari <lpranam@collabora.com>
Change-Id: I4dadb535e722cbeaacf177b30247899795d048f9
2021-12-20 12:03:51 +01:00
Miklos Vajna
15e08d3709 common: introduce COOLProtocol::getNonNegTokenInteger()
To simplify code that wants to extract a non-negative number from a
token value. See
<https://github.com/CollaboraOnline/online/pull/3788#pullrequestreview-826099897>.

Signed-off-by: Miklos Vajna <vmiklos@collabora.com>
Change-Id: I389dfa1a2838e501fc308dbfd7927b142a361922
2021-12-17 02:52:37 -05:00
Luboš Luňák
a5de33496c make stringifyHexLine() simply work on std::string
Trying to construct a string using sprintf() and std::stringstream
is unnecessarily complicated for something as simple as this,
and it shows up in my profiling. This commit makes the hex values
change to uppercase because that's what hexFromByte() returns,
but I don't think it matters.

Signed-off-by: Luboš Luňák <l.lunak@collabora.com>
Change-Id: I31c7b8e7cf4c2a495eca0bf03ae4cab53b26a04b
2021-12-07 13:44:40 +01:00
Pranam Lashkari
2ac0d01461 added method to get inode number from Stat object
Signed-off-by: Pranam Lashkari <lpranam@collabora.com>
Change-Id: I110f5bd0908a1c457af65429e377425e2055290a
2021-11-25 09:59:11 +02:00
Ashod Nakashian
587d160146 wsd: Termination flag requires having ShutdownRequested
Certain parts of the code assume ShutdownRequested is set
when relying on the Termination flag. This is because
they serve as degrees not as independent flags.

The Termination flag is basically a more impatient
ShutdownRequested flag. It is used to forcefully
and immediately terminate. It is not designed to be
used independently from ShutdownRequested.

This pair is a good candidate for unifying as a single enum.

Change-Id: I8e3913a1959868197d8c5a059e89cbdbc6cef070
Signed-off-by: Ashod Nakashian <ashod.nakashian@collabora.co.uk>
2021-11-23 09:31:46 +01:00
Ashod Nakashian
4c884a003a wsd: test: safer assertions without side-effects
The default behavior of LOK_ASSERT is that of assert,
which is to evaluate the argument(s) multiple times.

This obviously has side-effects, and is therefore
problematic. It seems it's not safe to assume all
uses of assertion is aware of this side-effect.

To prevent side-effect issues, now the LOK_ASSERT
family of macros evaluate the arguments only once.

Change-Id: I5827264ca7fcd77a7d7f5ad787353c6a7beb4fab
Signed-off-by: Ashod Nakashian <ashod.nakashian@collabora.co.uk>
2021-11-23 09:31:46 +01:00
Andras Timar
f07ff8c7e0 rename: remaining lool->cool changes
Signed-off-by: Andras Timar <andras.timar@collabora.com>
Change-Id: Ib7d4e804bebe52dead8d53b0e0bbaed0f08bf3d0
2021-11-18 14:14:11 +01:00
Mert Tumer
c9a4d2f6f3 rename: loolmount -> coolmount
Signed-off-by: Mert Tumer <mert.tumer@collabora.com>
Change-Id: Ic025c5a76c6f27cdf1a6267f24cf8052733f1f24
2021-11-17 21:51:05 +01:00
Henry Castro
23afa3843c kit: rename 'lool' -> 'cool'
Change-Id: I4198570d9940a028f1b4d84666a80516174c2f7a
Signed-off-by: Henry Castro <hcastro@collabora.com>
2021-11-17 09:18:38 +01:00
Henry Castro
85ba63ddce misc: more renames 'lool' -> 'cool'
Change-Id: Ic9fbae88d92921b9081e7067347852e385f45af3
Signed-off-by: Henry Castro <hcastro@collabora.com>
2021-11-17 09:17:46 +01:00
Mert Tumer
81f61c8073 rename: loolforkit -> coolforkit
Signed-off-by: Mert Tumer <mert.tumer@collabora.com>
Change-Id: I1de688dce4b068bff35451604486b72ecc8c91d4
2021-11-16 21:02:24 +01:00
Andras Timar
49f6f5cb54 Write timestamps to log in local time and add time zone differential
Signed-off-by: Andras Timar <andras.timar@collabora.com>
Change-Id: I895bff775b36db48fa88f02c8b81841567e62271
2021-11-16 16:38:00 +01:00
Tor Lillqvist
09942e76c5 Strip shell string syntax quotes from the PRETTY_NAME line in /etc/os-release
Signed-off-by: Tor Lillqvist <tml@collabora.com>
Change-Id: I5cb6f294d6d4bf62c2e16fc88bc6195695595ba5
2021-11-16 13:33:26 +02:00
Pranam Lashkari
f84df1161c quarantine: create hard links for quarantining when file is saved
number of versions to maintain per file can be specified in loolwsd.xml
on exceeding specified quarantine size oldest file(s) is deleted

Signed-off-by: Pranam Lashkari <lpranam@collabora.com>
Change-Id: I3ca55b9ab29a82988f19fe0acd43e0fae2c2a423
2021-11-01 17:21:51 +02:00
Rash419
d9795fff2e wsd: use the WOPI protocol for local files instead of the current "local storage" (in debug builds)
Signed-off-by: Rash419 <rashesh.padia@collabora.com>
Change-Id: I9e21df4c5b611ca9989915180310f0991ed28725
2021-11-01 15:45:14 +01:00
Hugo Peixoto
b2abb5e4aa Use tokens.equals() instead of tokens[] ==
This prevents additional strings from being allocated.

Signed-off-by: Hugo Peixoto <hugo.peixoto@gmail.com>
Change-Id: I84b1e5cf4d11bf8512febe068b3097770b63dc5c
2021-10-21 13:36:57 +02:00
Pranam Lashkari
f88a38a4e7 LOK: unifying the Freemium and uno command hiding APIs part 2
* replace vector with unordered_set
* avoid sending multiple blocking messages

Signed-off-by: Pranam Lashkari <lpranam@collabora.com>
Change-Id: I2f714e4f2797ade4ac9d5b4f824855bba31031c4
2021-10-21 12:28:13 +03:00
Pranam Lashkari
88601440d0 introduce way to hide/restrict uno commands
Signed-off-by: Pranam Lashkari <lpranam@collabora.com>
Change-Id: I1225190a67f726832e5b38a7c3f690b51c1385f3
2021-10-21 12:28:13 +03:00
Pranam Lashkari
f02a0a1447 freemium: renamed Freemium namespace to CommandControl
also renamed freemium files accordingly

Signed-off-by: Pranam Lashkari <lpranam@collabora.com>
Change-Id: Id33b8a1d1a2a8725bfa6e7b7c562430ea126993c
2021-10-21 12:28:13 +03:00
Hugo Peixoto
2bdb7ed56f Fix bug in StringVector::startsWith and add tests
The startsWith method that receives a StringToken was doing a bounds
check on the wrong parameter. This caused most calls to return false.

This commit adds some tests to both versions of StringVector::startsWith.

Signed-off-by: Hugo Peixoto <hugo.peixoto@gmail.com>
Change-Id: Icd4c648d681723ac66dba3c6a42ab7920850c619
2021-10-18 08:18:14 +02:00
Hugo Peixoto
7bf0ead625 Optimize startsWith calls on StringVector elements
There was a pattern of calling Util::startsWith on StringVector
elements:

- Util::startsWith(tokens[0], "boo")
- Util::startsWith(tokens.getParam(token), "boo")

These two expressions would cause a new string to be allocated and
immediately released. To optimize this, a StringVector::startsWith
method is introduced.

This method works by calling compare directly on the underlying
StringVector string, avoiding creating a temporary string.

Signed-off-by: Hugo Peixoto <hugo.peixoto@gmail.com>
Change-Id: I6f27d5bb13783f39c7d4ce0644a11e57b0071244
2021-10-15 13:58:26 +02:00
Mike Kaganski
ad2cbb4a9d JSON escaping: Have some initial extra space
Signed-off-by: Mike Kaganski <mike.kaganski@collabora.com>
Change-Id: I65421d8eaa69f42bd3557f4f221226f8fd4234ec
2021-10-14 13:41:53 +01:00
Mike Kaganski
d1bc6911b5 Escape strings in JSON
This should take care e.g. for SharePoint user IDs, which have the
form of "domain\username", and the backslash must be escaped.

Signed-off-by: Mike Kaganski <mike.kaganski@collabora.com>
Change-Id: I75936070ad1661dc9b03e05a19b64159b0758018
2021-10-13 16:29:50 +01:00
Mike Kaganski
ee44f755dc Drop circular inclusion of the header itself
Signed-off-by: Mike Kaganski <mike.kaganski@collabora.com>
Change-Id: I7518a9d1729d35b85592d474ba7cdfe9065e238c
2021-10-13 14:56:33 +01:00
Michael Meeks
b043b6213d Move LOOLWebSocket into test/ - where it can be slowly removed.
Change-Id: I388690261d323377648a1502b927e73f862ad802
Signed-off-by: Michael Meeks <michael.meeks@collabora.com>
2021-10-11 13:40:20 +01:00
Ashod Nakashian
88d5491108 wsd: allow shutting down during startup
During startup we wait for extended time until
a child process is up and running. In case this
takes a long time, or indeed if forking permanently
fails, we simply don't respond to shutdown requests.

This patch makes it possible to wait for about 20
seconds at a time for a child. This way on average
we will exit the process within about 10 seconds,
assuming we are blocked waiting for a child that
will never spawn.

Change-Id: I4409cbc60aa3c7bd30970d4638c820bc581b65ba
Signed-off-by: Ashod Nakashian <ashod.nakashian@collabora.co.uk>
(cherry picked from commit 6ed8b4bb1a6532d947a6bb00f936183767b54a80)
2021-10-06 12:28:06 -04:00
Ashod Nakashian
31913d56c2 wsd: avoid misbehaving library cleanup
We cleanup all the relevant objects and instances
before exiting the wsd process, however some libraries
may still misbehave and deadlock during this final
cleanup stage. Notably, Poco has been observed to
deadlock during cleaning up the SSL context static
instance (used for the singleton) by waiting on
its internal mutex indefinitely.

Here we exit forcefully after cleaning up.

Change-Id: I76621c1de7f9a4ff918624b3019b9869c08787c2
Signed-off-by: Ashod Nakashian <ashod.nakashian@collabora.co.uk>
(cherry picked from commit f776d87cf595bab084e53202777251a38e482147)
2021-10-06 12:28:06 -04:00
Miklos Vajna
803e9fef28 common: fix leftover debug output
Assuming that the intention is to output a pair of strings on start and
a pair of string on finish.

Signed-off-by: Miklos Vajna <vmiklos@collabora.com>
Change-Id: I1ab3b03c353a8d0875e2fee451ca34965fc3038e
2021-10-05 08:23:46 +02:00
Michael Meeks
48b943e85b Notify of completing sleeping to wait for a debugger.
Change-Id: I64e7d509fa9a5e299942a0a5ec05c0b7fd7344a2
Signed-off-by: Michael Meeks <michael.meeks@collabora.com>
2021-10-02 21:24:15 +01:00
Szymon Kłos
b05c6e86a2 Handle UnitType::Tool in global instance getters and setters
Signed-off-by: Szymon Kłos <szymon.klos@collabora.com>
Change-Id: I40bf3ea69d1722e652f9d2f64d2496557dc221e1
2021-09-28 14:23:34 +02:00
Szymon Kłos
78f68fa7ef Cleanup in Unit* subclasses
- we cannot get rid of UnitBase::get() which returns the last
  set Unit class because we use it for example in WebSocketHandler
  where we don't know which kind of test we run

- free memory correctly and reset global variables for subclasses

- setup _type member variable on construction

Signed-off-by: Szymon Kłos <szymon.klos@collabora.com>
Change-Id: Ic61b88785bff7de63b11ce2046eecc993c3ddeaf
2021-09-22 20:31:35 +02:00
Szymon Kłos
029d4195ad android fix: use correct instance for Unit classes getter
On android we had issue with not working release builds
(worked when optimization flag -O0 was used for Unit.cpp).

Global which stored instance of UnitBase subtype was returned
after cast to a choosen subtype. Unfortunately in case when
android didn't work UnitWSD was returned in UnitKit::get() !

Thich patch makes us sure we don't cast to not-correct type.

Signed-off-by: Szymon Kłos <szymon.klos@collabora.com>
Change-Id: I98e91d8fa82a8e81a8f7cee2fe3109b67c4f64f7
2021-09-22 20:31:35 +02:00
Michael Meeks
b0cd66feae Enable wait for attaching a debugger in debug builds by default.
Hopefully helps to hunt segv's more effectively in development.

Signed-off-by: Michael Meeks <michael.meeks@collabora.com>
Change-Id: Ife800f9902fe8d95711b3b14867ee21bb3c3f21b
2021-09-13 14:54:00 +01:00
Ashod Nakashian
28687c0bbf wsd: hexifying helpers and tests
Change-Id: I2f7fa4e6ade3361db612dbb9aa68e4d28b3905d9
Signed-off-by: Ashod Nakashian <ashod.nakashian@collabora.co.uk>
(cherry picked from commit 348ca073abe2c980f746324589bc58bf5550dc4b)
2021-09-13 09:40:09 -04:00
Tor Lillqvist
84d9a73676 Stop using .bmp files for tiles on iOS
We don't want leaking tiles to take up valuable space on the device.
Not even just while a document is open.

Signed-off-by: Tor Lillqvist <tml@collabora.com>
Change-Id: I761c2bb2ab121ee76b5535e96bd5702d0fce6856
2021-09-07 09:59:57 +03:00
Tor Lillqvist
c77b7e7dfd Actually do remove leftover tiles in the iOS app
Fix silly mistake in my previous commit. Had put code in #if 0 that
should be in #ifdef IOS.

Change-Id: I72f4dc3867bd070a01a4ba5625baba0eea3c2d73
Signed-off-by: Tor Lillqvist <tml@collabora.com>
2021-09-01 15:32:42 +03:00
Tor Lillqvist
6d2a6e110c Remove leftover tiles in the iOS app already when the document is closed
Normally (ideally), tiles (.bmp files) are removed as soon as the JS
has displayed them. But occasionally something goes wrong and they are
left behind. (For instance, it seems to happen if the user closes the
document immediately when it shows up.)

Do not leave them on disk until the app starts the next time.

Change-Id: I0c764280a69a16ad3b7b67c329832fd5331c2e1e
Signed-off-by: Tor Lillqvist <tml@collabora.com>
2021-09-01 13:32:23 +03:00
Pranam Lashkari
daef96dcb3 freemium: corrected typos
Signed-off-by: Pranam Lashkari <lpranam@collabora.com>
Change-Id: If21f4471b3ad4b20f049e2e9f2330e31989ead0b
2021-09-01 09:44:19 +02:00
Michael Meeks
09a2237372 Always lock the work queue.
The worker threads can be running and have not yet responded
to the last _cond.wait() by the time we start compressing again
- at least under valgrind:

loolforkit-nocaps: ./common/RenderTiles.hpp:304: void ThreadPool::run(): Assertion `_working == 0' failed.
==240379== Process terminating with default action of signal 6 (SIGABRT): dumping core
==240379==    at 0x5505322: raise (raise.c:50)
==240379==    by 0x54EE863: abort (abort.c:79)
==240379==    by 0x54EE748: __assert_fail_base.cold (assert.c:92)
==240379==    by 0x54FD9D5: __assert_fail (assert.c:101)
==240379==    by 0x5886BB: ThreadPool::run() (RenderTiles.hpp:304)
==240379==    by 0x56DC02: RenderTiles::doRender(std::shared_ptr<lok::Document>, TileCombined&, PngCache&, ThreadPool&, bool, std::function<void (unsigned char*, int, int, unsigned long, unsigned long, int, int, LibreOfficeKitTileMode)> const&, std::function<void (char const*, unsigned long)> const&) (RenderTiles.hpp:711)
==240379==    by 0x5A0104: Document::renderTiles(TileCombined&, bool) (Kit.cpp:762)
==240379==    by 0x59CF1A: Document::renderCombinedTiles(StringVector const&) (Kit.cpp:719)
==240379==    by 0x59AEC8: Document::drainQueue(std::chrono::time_point<std::chrono::_V2::steady_clock, std::chrono::duration<long, std::ratio<1l, 1000000000l> > > const&) (Kit.cpp:1570)

That means our queue starts processing work as we do the unlocked
queue push - causing some potential badness.

Change-Id: Ib0578dac009376c0676da73a8c1d8960304dc072
Signed-off-by: Michael Meeks <michael.meeks@collabora.com>
2021-09-01 07:14:44 +01:00