diff options
-rw-r--r-- | .clang-format | 4 | ||||
-rw-r--r-- | README.md | 7 | ||||
-rw-r--r-- | lib/logging.cpp | 12 | ||||
-rw-r--r-- | lib/logging.h | 5 | ||||
-rw-r--r-- | lib/room.cpp | 58 |
5 files changed, 43 insertions, 43 deletions
diff --git a/.clang-format b/.clang-format index 40262bc3..e114580e 100644 --- a/.clang-format +++ b/.clang-format @@ -96,8 +96,8 @@ IndentPPDirectives: AfterHash #MacroBlockEnd: '' #MaxEmptyLinesToKeep: 1 #NamespaceIndentation: Inner -PenaltyBreakAssignment: 30 -PenaltyBreakBeforeFirstCallParameter: 50 +PenaltyBreakAssignment: 10 +PenaltyBreakBeforeFirstCallParameter: 70 PenaltyBreakComment: 45 #PenaltyBreakFirstLessLess: 120 PenaltyBreakString: 200 @@ -155,8 +155,11 @@ libQuotient uses Qt's logging categories to make switching certain types of logg quotient.<category>.<level>=<flag> ``` where -- `<category>` is one of: `main`, `jobs`, `jobs.sync`, `events`, `events.ephemeral`, and `profiler` (you can always find the full list in the file `lib/logging.cpp`) -- `<level>` is one of `debug` and `warning` +- `<category>` is one of: `main`, `jobs`, `jobs.sync`, `events`, `events.state` + (covering both the "usual" room state and account data), `events.messages`, + `events.ephemeral`, `e2ee` and `profiler` (you can always find the full list + in `lib/logging.cpp`) +- `<level>` is one of `debug`, `info`, and `warning` - `<flag>` is either `true` or `false`. `*` can be used as a wildcard for any part between two dots, and semicolon is used for a separator. Latter statements override former ones, so if you want to switch on all debug logs except `jobs` you can set diff --git a/lib/logging.cpp b/lib/logging.cpp index a7676c97..c346fbf1 100644 --- a/lib/logging.cpp +++ b/lib/logging.cpp @@ -18,17 +18,15 @@ #include "logging.h" -#if QT_VERSION >= QT_VERSION_CHECK(5, 5, 0) -# define LOGGING_CATEGORY(Name, Id) \ - Q_LOGGING_CATEGORY((Name), (Id), QtInfoMsg) -#else -# define LOGGING_CATEGORY(Name, Id) Q_LOGGING_CATEGORY((Name), (Id)) -#endif +#define LOGGING_CATEGORY(Name, Id) Q_LOGGING_CATEGORY((Name), (Id), QtInfoMsg) // Use LOGGING_CATEGORY instead of Q_LOGGING_CATEGORY in the rest of the code LOGGING_CATEGORY(MAIN, "quotient.main") -LOGGING_CATEGORY(PROFILER, "quotient.profiler") LOGGING_CATEGORY(EVENTS, "quotient.events") +LOGGING_CATEGORY(STATE, "quotient.events.state") +LOGGING_CATEGORY(MESSAGES, "quotient.events.messages") LOGGING_CATEGORY(EPHEMERAL, "quotient.events.ephemeral") +LOGGING_CATEGORY(E2EE, "quotient.e2ee") LOGGING_CATEGORY(JOBS, "quotient.jobs") LOGGING_CATEGORY(SYNCJOB, "quotient.jobs.sync") +LOGGING_CATEGORY(PROFILER, "quotient.profiler") diff --git a/lib/logging.h b/lib/logging.h index 3d13569a..ce4131bb 100644 --- a/lib/logging.h +++ b/lib/logging.h @@ -22,11 +22,14 @@ #include <QtCore/QLoggingCategory> Q_DECLARE_LOGGING_CATEGORY(MAIN) -Q_DECLARE_LOGGING_CATEGORY(PROFILER) +Q_DECLARE_LOGGING_CATEGORY(STATE) +Q_DECLARE_LOGGING_CATEGORY(MESSAGES) Q_DECLARE_LOGGING_CATEGORY(EVENTS) Q_DECLARE_LOGGING_CATEGORY(EPHEMERAL) +Q_DECLARE_LOGGING_CATEGORY(E2EE) Q_DECLARE_LOGGING_CATEGORY(JOBS) Q_DECLARE_LOGGING_CATEGORY(SYNCJOB) +Q_DECLARE_LOGGING_CATEGORY(PROFILER) namespace Quotient { // QDebug manipulators diff --git a/lib/room.cpp b/lib/room.cpp index 031f9467..f7d3a797 100644 --- a/lib/room.cpp +++ b/lib/room.cpp @@ -1107,34 +1107,30 @@ bool Room::usesEncryption() const return !d->getCurrentState<EncryptionEvent>()->algorithm().isEmpty(); } -const RoomEvent* Room::decryptMessage(EncryptedEvent* encryptedEvent) const +RoomEventPtr Room::decryptMessage(EncryptedEvent* encryptedEvent) { if (encryptedEvent->algorithm() == OlmV1Curve25519AesSha2AlgoKey) { - QString identityKey = connection()->olmAccount()->curve25519IdentityKey(); + QString identityKey = + connection()->olmAccount()->curve25519IdentityKey(); QJsonObject personalCipherObject = encryptedEvent->ciphertext(identityKey); if (personalCipherObject.isEmpty()) { - qCDebug(EVENTS) << "Encrypted event is not for the current device"; - return nullptr; + qCDebug(E2EE) << "Encrypted event is not for the current device"; + return {}; } - return makeEvent<RoomMessageEvent>( - decryptMessage(personalCipherObject, - encryptedEvent->senderKey().toLatin1())) - .get(); + return makeEvent<RoomMessageEvent>(decryptMessage( + personalCipherObject, encryptedEvent->senderKey().toLatin1())); } if (encryptedEvent->algorithm() == MegolmV1AesSha2AlgoKey) { - return makeEvent<RoomMessageEvent>( - decryptMessage(encryptedEvent->ciphertext(), - encryptedEvent->senderKey(), - encryptedEvent->deviceId(), - encryptedEvent->sessionId())) - .get(); + return makeEvent<RoomMessageEvent>(decryptMessage( + encryptedEvent->ciphertext(), encryptedEvent->senderKey(), + encryptedEvent->deviceId(), encryptedEvent->sessionId())); } - return nullptr; + return {}; } -const QString Room::decryptMessage(QJsonObject personalCipherObject, - QByteArray senderKey) const +QString Room::decryptMessage(QJsonObject personalCipherObject, + QByteArray senderKey) { QString decrypted; @@ -1145,25 +1141,26 @@ const QString Room::decryptMessage(QJsonObject personalCipherObject, int type = personalCipherObject.value(TypeKeyL).toInt(-1); QByteArray body = personalCipherObject.value(BodyKeyL).toString().toLatin1(); - PreKeyMessage* preKeyMessage = new PreKeyMessage(body); - session = new InboundSession(connection()->olmAccount(), preKeyMessage, - senderKey); + PreKeyMessage preKeyMessage { body }; + session = + new InboundSession(connection()->olmAccount(), &preKeyMessage, senderKey, this); if (type == 0) { - if (!session->matches(preKeyMessage, senderKey)) { + if (!session->matches(&preKeyMessage, senderKey)) { connection()->olmAccount()->removeOneTimeKeys(session); } try { - decrypted = session->decrypt(preKeyMessage); + decrypted = session->decrypt(&preKeyMessage); } catch (std::runtime_error& e) { qWarning(EVENTS) << "Decrypt failed:" << e.what(); } - } else if (type == 1) { - Message* message = new Message(body); - if (!session->matches(preKeyMessage, senderKey)) { + } + else if (type == 1) { + Message message { body }; + if (!session->matches(&preKeyMessage, senderKey)) { qWarning(EVENTS) << "Invalid encrypted message"; } try { - decrypted = session->decrypt(message); + decrypted = session->decrypt(&message); } catch (std::runtime_error& e) { qWarning(EVENTS) << "Decrypt failed:" << e.what(); } @@ -1172,16 +1169,15 @@ const QString Room::decryptMessage(QJsonObject personalCipherObject, return decrypted; } -const QString Room::sessionKey(const QString& senderKey, const QString& deviceId, - const QString& sessionId) const +QString Room::sessionKey(const QString& senderKey, const QString& deviceId, + const QString& sessionId) const { // TODO: handling an m.room_key event return ""; } -const QString Room::decryptMessage(QByteArray cipher, const QString& senderKey, - const QString& deviceId, - const QString& sessionId) const +QString Room::decryptMessage(QByteArray cipher, const QString& senderKey, + const QString& deviceId, const QString& sessionId) { QString decrypted; using namespace QtOlm; |