aboutsummaryrefslogtreecommitdiff
path: root/lib/jobs
AgeCommit message (Collapse)Author
2022-06-18Drop make_array(); use std::to_array() where neededAlexey Rusakov
make_array() has been introduced to cover for shortcomings on macOS and Windows. These shortcomings are no more there, so we can just use the standardrlibrary.
2022-06-18Drop pre-Qt 5.15 codeAlexey Rusakov
2022-05-29Cleanup and address Sonar warningsAlexey Rusakov
2022-05-29DownloadFileJob: refactor file decryptionAlexey Rusakov
2022-05-29Move encryptFile/decryptFile out of EncryptedFileMetadataAlexey Rusakov
These are not operations on EncryptedFileMetadata but rather on a combination of EncryptedFileMetadata and ciphertext. If C++ had multimethods these could be bound to such a combination.
2022-05-29Refactor EncryptedFile and EC::FileInfo::fileAlexey Rusakov
Besides having a misleading name (and it goes back to the spec), EncryptedFile under `file` key preempts the `url` (or `thumbnail_url`) string value so only one of the two should exist. This is a case for using std::variant<> - despite its clumsy syntax, it can actually simplify and streamline code when all the necessary bits are in place (such as conversion to JSON and getting the common piece - the URL - out of it). This commit replaces `FileInfo::url` and `FileInfo::file` with a common field `source` of type `FileSourceInfo` that is an alias for a variant type covering both underlying types; and `url()` is reintroduced as a function instead, to allow simplified access to whichever URL is available inside the variant. Oh, and EncryptedFile is EncryptedFileMetadata now, to clarify that it does not represent the file payload itself but rather the data necessary to obtain that payload.
2022-05-11Fix race condition in consumeRoomData()Alexey Rusakov
QCoreApplication::processEvents() is well-known to be a _wrong_ solution to the unresponsive UI problem; despite that, connection.cpp has long had that call to let UI update itself while processing bulky room updates (mainly from the initial sync). This commit finally fixes this, after an (admittedly rare) race condition has been hit, as follows: 0. Pre-requisite: quotest runs all the tests and is about to leave the room; there's an ongoing sync request. 1. Quotest calls /leave 2. Sync returns, with the batch of _several_ rooms (that's important) 3. The above code handles the first room in the batch 4. processEvents() is called, just in time for the /leave response. 5. The /leave response handler in quotest ends up calling Connection::logout() (processEvents() still hasn't returned). 6. Connection::logout() calls abandon() on the ongoing SyncJob, pulling the rug from under onSyncSuccess()/consumeRoomData(). 7. processEvents() returns and the above code proceeds to the next room - only to find that the roomDataList (that is a ref to a structure owned by SyncJob), is now pointing to garbage. Morals of the story: 1. processEvents() effectively makes code multi-threaded: one flow is suspended and another one may run _on the same data_. After the first flow is resumed, it cannot make any assumptions regarding which data the second flow touched and/or changed. 2. The library had quite a few cases of using &&-refs, avoiding even move operations but also leaving ownership of the data with the original producer (SyncJob). If the lifetime of that producer ends too soon, those refs become dangling. The fix makes two important things, respectively: 2. Ownership of room data is now transfered to the processing side, the moment it is scheduled (see below), in the form of moving into a lambda capture. 1. Instead of processEvents(), processing of room data is scheduled via QMetaObject::invokeMethod(), uncoupling the moment when the data was received in SyncJob from the moment they are processed in Room::updateData() (and all the numerous signal-slots it calls). Also: Room::baseStateLoaded now causes Connection::loadedRoomState, not the other way round - this is more natural and doesn't need Connection to keep firstTimeRooms map around.
2022-02-16More cleanup, especially in EncryptedFileAlexey Rusakov
For EncryptedFile: - JSON converter bodies moved away to .cpp; - instead of C-style casts, reinterpret_cast is used to convert from (const) char* to (const) unsigned char*; - the size for the target plain text takes into account the case where the cipher block size can be larger than 1 (after reading https://www.openssl.org/docs/man1.1.1/man3/EVP_DecryptUpdate.html). - file decryption is wrapped in #ifdef Quotient_E2EE_ENABLED, to avoid OpenSSL linking errors when compiling without E2EE.
2022-02-13Merge branch 'dev'Alexey Rusakov
The result is FTBFS as yet; next commits will fix that, along with a few other things.
2022-02-07Remove encryptionmanager and various fixesTobias Fella
2022-01-29SyncData: expect self-contained /sync responseAlexey Rusakov
SyncData can load room objects out-of-line. This is only expected when loading data from the cache (and since quite long ago, the cache always saves room objects out of line, avoiding too large JSON payloads that Qt parser chokes on). However, the code processed /sync response in the same way; in particular, this meant that SyncData filled the vector of unresolved room ids even when it came from /sync. SyncJob then looked at this vector and entered an error state if it was not empty. Well, payloads from the wire can be weird and it ultimately came to pass that a homeserver returned a non-object against a given room key, triggering the unresolved rooms branch in SyncJob - and stalling the whole sync loop as a result (https://invent.kde.org/network/neochat/-/issues/500). With this commit SyncData only fills unresolvedRoomIds when loading rooms from the cache (with the implied fallback of discarding the cache and loading from /sync anew instead). Respectively, SyncJob must never end up with SyncData that has unresolved rooms (even if those occur in the actual payload like in the mentioned issue, those rooms will be completely empty instead); the added assertion only guards for internal consistency.
2022-01-23Cleanup some #includesAlexey Rusakov
2022-01-18Revise inline keyword usageAlexey Rusakov
- Templates and constexpr imply inline - A function called from a single site better be inlined.
2022-01-05Fully-qualify types passed to slotsAlexey Rusakov
2022-01-02Add ImplPtr and makeImplAlexey Rusakov
The original (more complex and comprehensive) solution belongs to https://oliora.github.io/2015/12/29/pimpl-and-rule-of-zero.html - this commit only provides a small wrapper for non-copyable Private class implementations common throughout libQuotient. Unlike the original, default initialisation is made explicit - you have to pass ZeroImpl<Private>() instead (and I firmly believe it's a good thing: normally pointers to Private should not remain nullptr). The reason ZeroImpl<> is not a template variable is quite simple: unique_ptr is non-copyable and so cannot be initialised from; while a template function will initialise the value in-place thanks to copy elision.
2022-01-01Define destructors out-of-line when unique/scoped ptr are involvedAlexey Rusakov
Once visibility kicks in, MSVC changes its ways and tries to instantiate Private classes wrapped in smart pointers upon their occurence in the header file - which leads to build breakage because of a missing destructor. Usually making the outer class destructor out-of-line helps to fix this (see RoomEvent, for one example).
2021-12-29Add QUOTIENT_API throughout non-generated codeAlexey Rusakov
This include all (hopefully) classes/structures and functions that have non-inline definitions, as well as namespaces with Q_NAMESPACE since those have non-inline (as of Qt 5.15) QMetaObject - for that a new macro, QUO_NAMESPACE, has been devised to accommodate the lack of Q_NAMESPACE_EXPORT in Qt before 5.14.
2021-12-01Apply suggestions from code reviewTobias Fella
Co-authored-by: Alexey Rusakov <Kitsune-Ral@users.sf.net>
2021-12-01Apply suggestions from code reviewTobias Fella
Co-authored-by: Alexey Rusakov <Kitsune-Ral@users.sf.net>
2021-12-01Add mxc protocol to the networkaccessmanagerTobias Fella
2021-12-01Handle encrypted file download through existing APITobias Fella
2021-12-01Implement download and decryption of encrypted filesTobias Fella
2021-11-11DECL_DEPRECATED_ENUMERATORAlexey Rusakov
A handy macro that introduces an enumerator with a respective Q_DECL_DEPRECATED_X recommending the substitution.
2021-10-05BaseJob: refresh error handlingAlexey Rusakov
- BaseJob::prepareError() slightly updated to get the current status instead of checking the returned value outside in gotReply() - BaseJob::gotReply() no more reports on 429 Too Many Requests twice (the first time with dubious "Too Many Requests: Unknown error")
2021-10-05BaseJob::StatusCode: officially deprecate most *Error enumeratorsAlexey Rusakov
2021-10-04BaseJob: percent-encode variable path partsAlexey Rusakov
This is meant to spare clients from having to percent-encode room aliases, v3 event ids etc. that happen to hit the endpoint path. It is unfair to expect clients to do that since they are not supposed to care about the shape of CS API, which parameter should be encoded in which way. The trick (together with the slightly updated GTAD configuration) is to percent-encode parts that happen to be QStrings and not `const char[]`'s while passing all constant parts as plain C character literals. This also allows to make it more certain that the path is correctly encoded by passing and storing QByteArray's wherever the path is already encoded, and only use QStrings (next to const char arrays) before that. Since the change alters the API contract (even if that contract was crappy), some crude detection of percent-encoded stuff on input is inserted; if input is already percent-encoded, a warning is put to the logs, alerting developers about the change.
2021-09-11BaseJob: deprecate endpoint accessors; query returns an objectAlexey Rusakov
To provide more room for internal changes in BaseJob.
2021-09-01Fix building with MSVCAlexey Rusakov
Turned out it was broken, and I was looking the other way.
2021-08-22Fix building with MSVCAlexey Rusakov
2021-08-22Drop other stuff deprecated pre- or early 0.6Alexey Rusakov
BaseJob: StatusCode::JsonParseError Connection: resolved() and reconnected() signals; roomMap(); postReceipt() User: bridged() and rawName() ConnectionData: setHost() and setPort() StateEventBase: prev_content()
2021-08-22Drop QMatrixClient namespace aliasAlexey Rusakov
2021-08-22Deprecate BaseJob::DataAlexey Rusakov
The grand plan is to get rid of `BaseJob` and turn job invocations to function calls returning `QFuture`. `RequestData` will stay though, feeding data into those calls.
2021-08-07Drop an out-of-date commentAlexey Rusakov
BaseJob::loadFromJson() does just fine without QStringViews. [skip ci]
2021-07-18Introduce to_array() to fix building on macOSAlexey Rusakov
A previous incarnation, make_array, existed in basejob.cpp before. The new direction taken by C++20 is to either deduce the array (but the used Apple standard library doesn't have deduction guides yet) or to use to_array() that converts a C array to std::array. This latter option is taken here, with to_array() defined in quotient_common.h until we move over to C++20.
2021-07-16Log thumbnail requests in their own categoryAlexey Rusakov
As pointed out by one of users, thumbnail requests produce quite a bit of logging traffic, so it's better to manage them separately.
2021-07-02Actually delete BaseJob::QueryAlexey Rusakov
It was a tiny wrapper around QUrlQuery to facilitate creation from an initializer list - however, Mustache templates long changed to not actually used that additional constructor.
2021-06-13BaseJob: FollowRedirectsAttribute -> RedirectPolicyAttributeAlexey Rusakov
The latter obsoleted the former since Qt 5.9, actually.
2021-06-13Make RequestData compile againAlexey Rusakov
This fixes reliance on QIODevice being magically available for std::unique_ptr<> by indirect inclusion. Since Qt 6 this inclusion no more happens, time to #include <QIODevice> explicitly.
2021-01-16Updated copyright statements upon Git auditKitsune Ral
After going through all the files and the history of commits on them it was clear that some copyright statements are obsolete (the code has been overwritten since) and some are missing. This commit tries best to remedy that, along with adding SPDX tags where they were still not used. Also, a minimal SPDX convention is documented for further contributions. Closes #426.
2021-01-15Merge branch 'master' into dfaure/stricter-flagsKitsune Ral
2021-01-15Merge pull request #428 from ognarb/licensingKitsune Ral
Port existing copyright statement to reuse using licensedigger
2021-01-15Drop a file deleted in masterKitsune Ral
2021-01-07isJobRunning() -> isJobPending()Kitsune Ral
To be very clear what this function checks. See also #437.
2021-01-07BaseJob: setStatus(Pending) on scheduling a retryKitsune Ral
Fixes #437. (cherry picked from commit 12e00b234e5c5f4ed57b5c400d06f780e71014f4)
2021-01-07BaseJob: more loggingKitsune Ral
(cherry picked from commit 4f06d46d6d6062d6d17f69eeaddb7810edac5bbf)
2020-12-28Use generated SetReadMarkerJob instead of PostReadMarkersJobKitsune Ral
2020-12-28BaseJob::initiate: add Q_LIKELYKitsune Ral
...to show the sunny-day case.
2020-12-28Cleanup and clang-tidy/clazy fixesKitsune Ral
2020-12-27Fix use-after-free of QNetworkReply in BaseJobNicolas Fella
Usually QNetworkAccessManager expects the user to delete the replies, but when the QNetworkAccessManager itself is deleted it deletes all pending replies (https://code.woboq.org/qt5/qtbase/src/network/access/qnetworkaccessmanager.cpp.html#529). This can lead to use-after-free crashes when d->reply is accessed. By putting the reply into a QPointer the exiting if(d->reply) checks can work properly.
2020-12-26Port existing copyright statement to reuse using licensediggerCarl Schwan