From ea9fa4e0df8d45e06b1d7ead5e29813ea5025493 Mon Sep 17 00:00:00 2001 From: Linus Jahn Date: Mon, 27 Feb 2023 17:27:53 +0100 Subject: MamManager: Fix task is not finished when no message is encrypted --- src/client/QXmppMamManager.cpp | 9 +++++++++ 1 file changed, 9 insertions(+) (limited to 'src') diff --git a/src/client/QXmppMamManager.cpp b/src/client/QXmppMamManager.cpp index f173aa01..c39a3411 100644 --- a/src/client/QXmppMamManager.cpp +++ b/src/client/QXmppMamManager.cpp @@ -264,11 +264,14 @@ QXmppTask QXmppMamManager::retrieveMessages(con if (auto *e2eeExt = client()->encryptionExtension()) { auto &messages = itr->second.messages; auto running = std::make_shared(0); + // handle case when no message is encrypted + auto hasEncryptedMessages = false; for (auto i = 0; i < messages.size(); i++) { if (!e2eeExt->isEncrypted(messages.at(i))) { continue; } + hasEncryptedMessages = true; auto message = messages.at(i); (*running)++; @@ -290,6 +293,12 @@ QXmppTask QXmppMamManager::retrieveMessages(con } }); } + + if (!hasEncryptedMessages) { + // finish here, no decryptMessage callback will do it + itr->second.finish(); + d->ongoingRequests.erase(itr); + } } else { itr->second.finish(); d->ongoingRequests.erase(itr); -- cgit v1.2.3 From 2a39ea6743ea4b7075184cd37c16fec5c4226009 Mon Sep 17 00:00:00 2001 From: Linus Jahn Date: Wed, 8 Mar 2023 22:16:17 +0100 Subject: Fix library files install directory on windows For details see: https://stackoverflow.com/a/22280842/4483773 --- src/CMakeLists.txt | 4 +++- src/omemo/CMakeLists.txt | 4 +++- 2 files changed, 6 insertions(+), 2 deletions(-) (limited to 'src') diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 1b44e011..4a260a7b 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -360,8 +360,10 @@ generate_export_header(qxmpp install( TARGETS qxmpp - DESTINATION "${CMAKE_INSTALL_LIBDIR}" EXPORT QXmppTarget + RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR} + LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR} + ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR} ) install( diff --git a/src/omemo/CMakeLists.txt b/src/omemo/CMakeLists.txt index 0ec3c0f0..89e1f06c 100644 --- a/src/omemo/CMakeLists.txt +++ b/src/omemo/CMakeLists.txt @@ -54,8 +54,10 @@ set_target_properties(QXmppOmemo PROPERTIES install( TARGETS QXmppOmemo - DESTINATION ${CMAKE_INSTALL_LIBDIR} EXPORT QXmppOmemoTargets + RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR} + LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR} + ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR} ) install( -- cgit v1.2.3 From c5642526513363608d538417d0e50e00f9cd5e46 Mon Sep 17 00:00:00 2001 From: Jonah Brüchert Date: Thu, 9 Mar 2023 13:30:58 +0100 Subject: Fix compilation on MSVC 2019 --- src/base/QXmppPromise.h | 4 ++-- src/client/QXmppDiscoveryManager.h | 2 +- src/client/QXmppEntityTimeManager.h | 2 +- src/client/QXmppFileEncryption.cpp | 2 ++ src/client/QXmppFileEncryption.h | 8 ++++---- 5 files changed, 10 insertions(+), 8 deletions(-) (limited to 'src') diff --git a/src/base/QXmppPromise.h b/src/base/QXmppPromise.h index 4900dae1..6408ad0c 100644 --- a/src/base/QXmppPromise.h +++ b/src/base/QXmppPromise.h @@ -45,7 +45,7 @@ public: #ifdef QXMPP_DOC void reportFinished(T &&value) #else - template && std::is_same_v> * = nullptr> + template && std::is_same_v> * = nullptr> void finish(U &&value) #endif { @@ -61,7 +61,7 @@ public: } /// \cond - template && std::is_constructible_v && !std::is_same_v> * = nullptr> + template && std::is_constructible_v && !std::is_same_v> * = nullptr> void finish(U &&value) { Q_ASSERT(!d.isFinished()); diff --git a/src/client/QXmppDiscoveryManager.h b/src/client/QXmppDiscoveryManager.h index 10744a0d..d45e63a4 100644 --- a/src/client/QXmppDiscoveryManager.h +++ b/src/client/QXmppDiscoveryManager.h @@ -15,7 +15,7 @@ class QXmppTask; class QXmppDataForm; class QXmppDiscoveryIq; class QXmppDiscoveryManagerPrivate; -class QXmppError; +struct QXmppError; /// \brief The QXmppDiscoveryManager class makes it possible to discover information /// about other entities as defined by \xep{0030}: Service Discovery. diff --git a/src/client/QXmppEntityTimeManager.h b/src/client/QXmppEntityTimeManager.h index 3b090feb..87219122 100644 --- a/src/client/QXmppEntityTimeManager.h +++ b/src/client/QXmppEntityTimeManager.h @@ -13,7 +13,7 @@ template class QXmppTask; class QXmppEntityTimeIq; -class QXmppError; +struct QXmppError; /// /// \brief The QXmppEntityTimeManager class provided the functionality to get diff --git a/src/client/QXmppFileEncryption.cpp b/src/client/QXmppFileEncryption.cpp index ba78821e..e767769a 100644 --- a/src/client/QXmppFileEncryption.cpp +++ b/src/client/QXmppFileEncryption.cpp @@ -7,6 +7,8 @@ #include #include +#undef min + using namespace QCA; constexpr std::size_t AES128_BLOCK_SIZE = 128 / 8; diff --git a/src/client/QXmppFileEncryption.h b/src/client/QXmppFileEncryption.h index 5bd52c7e..e50bf83c 100644 --- a/src/client/QXmppFileEncryption.h +++ b/src/client/QXmppFileEncryption.h @@ -23,9 +23,9 @@ enum Direction { Decode, }; -QByteArray process(const QByteArray &data, Cipher cipherConfig, Direction direction, const QByteArray &key, const QByteArray &iv); -QByteArray generateKey(Cipher cipher); -QByteArray generateInitializationVector(Cipher); +QXMPP_EXPORT QByteArray process(const QByteArray &data, Cipher cipherConfig, Direction direction, const QByteArray &key, const QByteArray &iv); +QXMPP_EXPORT QByteArray generateKey(Cipher cipher); +QXMPP_EXPORT QByteArray generateInitializationVector(Cipher); // export for tests class QXMPP_EXPORT EncryptionDevice : public QIODevice @@ -50,7 +50,7 @@ private: std::unique_ptr m_cipher; }; -class DecryptionDevice : public QIODevice +class QXMPP_EXPORT DecryptionDevice : public QIODevice { public: DecryptionDevice(std::unique_ptr output, Cipher config, const QByteArray &key, const QByteArray &iv); -- cgit v1.2.3 From 5fffebeb5f636e4c050e61df5cd6d60032b55fc2 Mon Sep 17 00:00:00 2001 From: Melvin Keskin Date: Wed, 8 Mar 2023 00:39:56 +0100 Subject: CarbonManagerV2: Fix enabling carbons --- src/client/QXmppCarbonManagerV2.cpp | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) (limited to 'src') diff --git a/src/client/QXmppCarbonManagerV2.cpp b/src/client/QXmppCarbonManagerV2.cpp index 0f48370e..7959cab3 100644 --- a/src/client/QXmppCarbonManagerV2.cpp +++ b/src/client/QXmppCarbonManagerV2.cpp @@ -18,9 +18,10 @@ using namespace QXmpp::Private; class CarbonEnableIq : public QXmppIq { public: - CarbonEnableIq() + CarbonEnableIq(const QString &jid) : QXmppIq() { + setTo(jid); setType(QXmppIq::Set); } @@ -30,7 +31,8 @@ public: } void toXmlElementFromChild(QXmlStreamWriter *writer) const override { - writer->writeStartElement(ns_carbons, "enable"); + writer->writeStartElement(QStringLiteral("enable")); + writer->writeDefaultNamespace(ns_carbons); writer->writeEndElement(); } }; @@ -163,7 +165,7 @@ void QXmppCarbonManagerV2::enableCarbons() return; } - client()->sendIq(CarbonEnableIq()).then(this, [this](QXmppClient::IqResult domResult) { + client()->sendIq(CarbonEnableIq(client()->configuration().jidBare())).then(this, [this](QXmppClient::IqResult domResult) { if (auto err = parseIq(std::move(domResult))) { warning("Could not enable message carbons: " % err->description); } else { -- cgit v1.2.3 From 0752de902404ed59fdc71975a72a42c487edb5f6 Mon Sep 17 00:00:00 2001 From: Melvin Keskin Date: Sat, 4 Mar 2023 00:32:44 +0100 Subject: Update OMEMO to new libomemo-c 0.5 APIs --- src/omemo/QXmppOmemoManager.cpp | 2 +- src/omemo/QXmppOmemoManager_p.cpp | 74 +++++------------------ src/omemo/QXmppOmemoManager_p.h | 2 - tests/qxmppomemomanager/tst_qxmppomemomanager.cpp | 2 +- 4 files changed, 18 insertions(+), 62 deletions(-) (limited to 'src') diff --git a/src/omemo/QXmppOmemoManager.cpp b/src/omemo/QXmppOmemoManager.cpp index 55a21190..7b38c73e 100644 --- a/src/omemo/QXmppOmemoManager.cpp +++ b/src/omemo/QXmppOmemoManager.cpp @@ -669,7 +669,7 @@ QXmppOmemoOwnDevice Manager::ownDevice() QXmppOmemoOwnDevice device; device.setLabel(ownDevice.label); - device.setKeyId(createKeyId(ownDevice.publicIdentityKey)); + device.setKeyId(ownDevice.publicIdentityKey); return device; } diff --git a/src/omemo/QXmppOmemoManager_p.cpp b/src/omemo/QXmppOmemoManager_p.cpp index c6668e19..4e474984 100644 --- a/src/omemo/QXmppOmemoManager_p.cpp +++ b/src/omemo/QXmppOmemoManager_p.cpp @@ -40,23 +40,6 @@ namespace QXmpp::Omemo::Private { const QString PAYLOAD_MESSAGE_AUTHENTICATION_CODE_TYPE = QStringLiteral("hmac(sha256)"); -// -// Creates a key ID. -// -// The first byte representing a version string used by the OMEMO library but -// not needed for trust management is removed. -// It corresponds to the fingerprint shown to users which also does not contain -// the first byte. -// -// \param key key for whom its ID is created -// -// \return the key ID -// -QByteArray createKeyId(const QByteArray &key) -{ - return QByteArray(key).remove(0, 1); -} - } // namespace QXmpp::Omemo::Private // @@ -713,13 +696,7 @@ bool ManagerPrivate::setUpIdentityKeyPair(ratchet_identity_key_pair **identityKe const auto privateIdentityKey = privateIdentityKeyBuffer.toByteArray(); ownDevice.privateIdentityKey = privateIdentityKey; - BufferPtr publicIdentityKeyBuffer; - - if (ec_public_key_serialize(publicIdentityKeyBuffer.ptrRef(), ratchet_identity_key_pair_get_public(*identityKeyPair)) < 0) { - warning("Public identity key could not be serialized"); - return false; - } - + BufferPtr publicIdentityKeyBuffer(ec_public_key_get_ed(ratchet_identity_key_pair_get_public(*identityKeyPair))); const auto publicIdentityKey = publicIdentityKeyBuffer.toByteArray(); deviceBundle.setPublicIdentityKey(publicIdentityKey); ownDevice.publicIdentityKey = publicIdentityKey; @@ -835,18 +812,12 @@ bool ManagerPrivate::updateSignedPreKeyPair(ratchet_identity_key_pair *identityK signedPreKeyPairs.insert(latestSignedPreKeyId, signedPreKeyPairForStorage); omemoStorage->addSignedPreKeyPair(latestSignedPreKeyId, signedPreKeyPairForStorage); - BufferPtr signedPublicPreKeyBuffer; - - if (ec_public_key_serialize(signedPublicPreKeyBuffer.ptrRef(), ec_key_pair_get_public(session_signed_pre_key_get_key_pair(signedPreKeyPair.get()))) < 0) { - warning("Signed public pre key could not be serialized"); - return false; - } - + BufferPtr signedPublicPreKeyBuffer(ec_public_key_get_mont(ec_key_pair_get_public(session_signed_pre_key_get_key_pair(signedPreKeyPair.get())))); const auto signedPublicPreKeyByteArray = signedPublicPreKeyBuffer.toByteArray(); deviceBundle.setSignedPublicPreKeyId(latestSignedPreKeyId); deviceBundle.setSignedPublicPreKey(signedPublicPreKeyByteArray); - deviceBundle.setSignedPublicPreKeySignature(QByteArray(reinterpret_cast(session_signed_pre_key_get_signature(signedPreKeyPair.get())), session_signed_pre_key_get_signature_len(signedPreKeyPair.get()))); + deviceBundle.setSignedPublicPreKeySignature(QByteArray(reinterpret_cast(session_signed_pre_key_get_signature_omemo(signedPreKeyPair.get())), session_signed_pre_key_get_signature_omemo_len(signedPreKeyPair.get()))); ownDevice.latestSignedPreKeyId = latestSignedPreKeyId; @@ -924,7 +895,6 @@ bool ManagerPrivate::updatePreKeyPairs(uint32_t count) node != nullptr; node = signal_protocol_key_helper_key_list_next(node)) { BufferSecurePtr preKeyPairBuffer; - BufferPtr publicPreKeyBuffer; auto preKeyPair = signal_protocol_key_helper_key_list_element(node); @@ -937,11 +907,7 @@ bool ManagerPrivate::updatePreKeyPairs(uint32_t count) serializedPreKeyPairs.insert(preKeyId, preKeyPairBuffer.toByteArray()); - if (ec_public_key_serialize(publicPreKeyBuffer.ptrRef(), ec_key_pair_get_public(session_pre_key_get_key_pair(preKeyPair))) < 0) { - warning("Public pre key could not be serialized"); - return false; - } - + BufferPtr publicPreKeyBuffer(ec_public_key_get_mont(ec_key_pair_get_public(session_pre_key_get_key_pair(preKeyPair)))); const auto serializedPublicPreKey = publicPreKeyBuffer.toByteArray(); deviceBundle.addPublicPreKey(preKeyId, serializedPublicPreKey); } @@ -1020,7 +986,7 @@ bool ManagerPrivate::generateIdentityKeyPair(ratchet_identity_key_pair **identit RefCountedPtr publicIdentityKey; - if (curve_decode_point(publicIdentityKey.ptrRef(), signal_buffer_data(publicIdentityKeyBuffer.get()), signal_buffer_len(publicIdentityKeyBuffer.get()), globalContext.get()) < 0) { + if (curve_decode_point_ed(publicIdentityKey.ptrRef(), signal_buffer_data(publicIdentityKeyBuffer.get()), signal_buffer_len(publicIdentityKeyBuffer.get()), globalContext.get()) < 0) { warning("Public identity key could not be deserialized"); return false; } @@ -1237,15 +1203,14 @@ QXmppTask> ManagerPrivate::encryptStanza(const if (optionalDeviceBundle && devices.value(jid).contains(deviceId)) { auto &deviceBeingModified = devices[jid][deviceId]; const auto &deviceBundle = *optionalDeviceBundle; - const auto key = deviceBundle.publicIdentityKey(); - deviceBeingModified.keyId = createKeyId(key); + deviceBeingModified.keyId = deviceBundle.publicIdentityKey(); auto future = q->trustLevel(jid, deviceBeingModified.keyId); future.then(q, [=](TrustLevel trustLevel) mutable { // Store the retrieved key's trust level if it is not stored // yet. if (trustLevel == TrustLevel::Undecided) { - auto future = storeKeyDependingOnSecurityPolicy(jid, key); + auto future = storeKeyDependingOnSecurityPolicy(jid, deviceBeingModified.keyId); future.then(q, [=](TrustLevel trustLevel) mutable { omemoStorage->addDevice(jid, deviceId, deviceBeingModified); Q_EMIT q->deviceChanged(jid, deviceId); @@ -1731,11 +1696,10 @@ QXmppTask> ManagerPrivate::extractPayloadDecrypt const auto key = publicIdentityKeyBuffer.toByteArray(); auto &device = devices[senderJid][senderDeviceId]; auto &storedKeyId = device.keyId; - const auto createdKeyId = createKeyId(key); // Store the key if its ID has changed. - if (storedKeyId != createdKeyId) { - storedKeyId = createdKeyId; + if (storedKeyId != key) { + storedKeyId = key; omemoStorage->addDevice(senderJid, senderDeviceId, device); Q_EMIT q->deviceChanged(senderJid, senderDeviceId); } @@ -3341,8 +3305,7 @@ QXmppTask ManagerPrivate::buildSessionWithDeviceBundle(const QString &jid, future.then(q, [=, &device](std::optional optionalDeviceBundle) mutable { if (optionalDeviceBundle) { const auto &deviceBundle = *optionalDeviceBundle; - const auto key = deviceBundle.publicIdentityKey(); - device.keyId = createKeyId(key); + device.keyId = deviceBundle.publicIdentityKey(); auto future = q->trustLevel(jid, device.keyId); future.then(q, [=](TrustLevel trustLevel) mutable { @@ -3375,7 +3338,7 @@ QXmppTask ManagerPrivate::buildSessionWithDeviceBundle(const QString &jid, if (trustLevel == TrustLevel::Undecided) { // Store the key's trust level if it is not stored yet. - auto future = storeKeyDependingOnSecurityPolicy(jid, key); + auto future = storeKeyDependingOnSecurityPolicy(jid, device.keyId); future.then(q, [=](TrustLevel trustLevel) mutable { buildSessionDependingOnTrustLevel(trustLevel); }); @@ -3524,7 +3487,7 @@ bool ManagerPrivate::deserializePublicIdentityKey(ec_public_key **publicIdentity return false; } - if (curve_decode_point(publicIdentityKey, signal_buffer_data(publicIdentityKeyBuffer.get()), signal_buffer_len(publicIdentityKeyBuffer.get()), globalContext.get()) < 0) { + if (curve_decode_point_ed(publicIdentityKey, signal_buffer_data(publicIdentityKeyBuffer.get()), signal_buffer_len(publicIdentityKeyBuffer.get()), globalContext.get()) < 0) { warning("Public identity key could not be deserialized"); return false; } @@ -3549,7 +3512,7 @@ bool ManagerPrivate::deserializeSignedPublicPreKey(ec_public_key **signedPublicP return false; } - if (curve_decode_point(signedPublicPreKey, signal_buffer_data(signedPublicPreKeyBuffer.get()), signal_buffer_len(signedPublicPreKeyBuffer.get()), globalContext.get()) < 0) { + if (curve_decode_point_mont(signedPublicPreKey, signal_buffer_data(signedPublicPreKeyBuffer.get()), signal_buffer_len(signedPublicPreKeyBuffer.get()), globalContext.get()) < 0) { warning("Signed public pre key could not be deserialized"); return false; } @@ -3574,7 +3537,7 @@ bool ManagerPrivate::deserializePublicPreKey(ec_public_key **publicPreKey, const return false; } - if (curve_decode_point(publicPreKey, signal_buffer_data(publicPreKeyBuffer.get()), signal_buffer_len(publicPreKeyBuffer.get()), globalContext.get()) < 0) { + if (curve_decode_point_mont(publicPreKey, signal_buffer_data(publicPreKeyBuffer.get()), signal_buffer_len(publicPreKeyBuffer.get()), globalContext.get()) < 0) { warning("Public pre key could not be deserialized"); return false; } @@ -3640,16 +3603,11 @@ QXmppTask ManagerPrivate::sendEmptyMessage(const QString &rec // // Sets the key of this client instance's device. // -// The first byte representing a version string used by the OMEMO library but -// not needed for trust management is removed before storing it. -// It corresponds to the fingerprint shown to users which also does not contain -// the first byte. -// QXmppTask ManagerPrivate::storeOwnKey() const { QXmppPromise interface; - auto future = trustManager->setOwnKey(ns_omemo_2, createKeyId(ownDevice.publicIdentityKey)); + auto future = trustManager->setOwnKey(ns_omemo_2, ownDevice.publicIdentityKey); future.then(q, [=]() mutable { interface.finish(); }); @@ -3722,7 +3680,7 @@ QXmppTask ManagerPrivate::storeKey(const QString &keyOwnerJid, const { QXmppPromise interface; - auto future = trustManager->addKeys(ns_omemo_2, keyOwnerJid, { createKeyId(key) }, trustLevel); + auto future = trustManager->addKeys(ns_omemo_2, keyOwnerJid, { key }, trustLevel); future.then(q, [=]() mutable { Q_EMIT q->trustLevelsChanged({ { keyOwnerJid, key } }); interface.finish(std::move(trustLevel)); diff --git a/src/omemo/QXmppOmemoManager_p.h b/src/omemo/QXmppOmemoManager_p.h index 6875a571..838e68ad 100644 --- a/src/omemo/QXmppOmemoManager_p.h +++ b/src/omemo/QXmppOmemoManager_p.h @@ -115,8 +115,6 @@ struct IqDecryptionResult QXmppE2eeMetadata e2eeMetadata; }; -QByteArray createKeyId(const QByteArray &key); - } // namespace QXmpp::Omemo::Private using namespace QXmpp::Private; diff --git a/tests/qxmppomemomanager/tst_qxmppomemomanager.cpp b/tests/qxmppomemomanager/tst_qxmppomemomanager.cpp index d276a626..95c70237 100644 --- a/tests/qxmppomemomanager/tst_qxmppomemomanager.cpp +++ b/tests/qxmppomemomanager/tst_qxmppomemomanager.cpp @@ -231,7 +231,7 @@ void tst_QXmppOmemoManager::testLoad() QVERIFY(result); const auto storedOwnDevice = m_alice1.manager->ownDevice(); - // QCOMPARE(storedOwnDevice.keyId(), m_alice1.manager->d->createKeyId(ownDevice.publicIdentityKey)); + // QCOMPARE(storedOwnDevice.keyId(), ownDevice.publicIdentityKey); QCOMPARE(storedOwnDevice.label(), ownDevice.label); m_alice1.omemoStorage->resetAll(); -- cgit v1.2.3 From df2ddfe37aead0fc2819cdf3b649d76075897187 Mon Sep 17 00:00:00 2001 From: Melvin Keskin Date: Sat, 4 Mar 2023 00:34:56 +0100 Subject: OmemoManagerPrivate: Adapt return value handling to adjusted method --- src/omemo/QXmppOmemoManager_p.cpp | 15 ++------------- 1 file changed, 2 insertions(+), 13 deletions(-) (limited to 'src') diff --git a/src/omemo/QXmppOmemoManager_p.cpp b/src/omemo/QXmppOmemoManager_p.cpp index 4e474984..9d2d41a2 100644 --- a/src/omemo/QXmppOmemoManager_p.cpp +++ b/src/omemo/QXmppOmemoManager_p.cpp @@ -1441,8 +1441,6 @@ QXmppTask> ManagerPrivate::decryptMessage(QXmppMessa future.then(q, [=](std::optional payloadDecryptionData) mutable { if (!payloadDecryptionData) { warning("Empty OMEMO message could not be successfully processed"); - } else if (payloadDecryptionData->isEmpty()) { - warning("Empty OMEMO message could not be successfully processed"); } else { q->debug("Successfully processed empty OMEMO message"); } @@ -1616,9 +1614,6 @@ QXmppTask ManagerPrivate::extractSceEnvelope(const QString &senderJi if (!payloadDecryptionData) { warning("Data for decrypting OMEMO payload could not be extracted"); interface.finish(QByteArray()); - } else if (payloadDecryptionData->isEmpty()) { - warning("Data for decrypting OMEMO payload could not be extracted"); - interface.finish(QByteArray()); } else { interface.finish(decryptPayload(*payloadDecryptionData, omemoPayload)); } @@ -1637,8 +1632,7 @@ QXmppTask ManagerPrivate::extractSceEnvelope(const QString &senderJi // \param omemoEnvelope OMEMO envelope containing the payload decryption data // \param isMessageStanza whether the received stanza is a message stanza // -// \return the serialized payload decryption data if it could be extracted, otherwise a -// default-constructed secure array +// \return the serialized payload decryption data if it could be extracted, otherwise std::nullopt // QXmppTask> ManagerPrivate::extractPayloadDecryptionData(const QString &senderJid, uint32_t senderDeviceId, const QXmppOmemoEnvelope &omemoEnvelope, bool isMessageStanza) { @@ -1748,12 +1742,7 @@ QXmppTask> ManagerPrivate::extractPayloadDecrypt auto future = q->trustLevel(senderJid, storedKeyId); future.then(q, [=](TrustLevel trustLevel) mutable { if (trustLevel == TrustLevel::Undecided) { - auto future = storeKeyDependingOnSecurityPolicy(senderJid, key); - future.then(q, [=](auto) mutable { - interface.finish(std::nullopt); - }); - } else { - interface.finish(std::nullopt); + storeKeyDependingOnSecurityPolicy(senderJid, key); } }); } -- cgit v1.2.3 From 72571909c4b0e95f1b5ab3865de2b25fe859b367 Mon Sep 17 00:00:00 2001 From: Melvin Keskin Date: Sat, 4 Mar 2023 01:09:23 +0100 Subject: Organize OMEMO includes --- src/base/QXmppOmemoElement_p.h | 2 +- src/omemo/QXmppOmemoData.cpp | 2 -- src/omemo/QXmppOmemoDeviceList_p.h | 2 +- src/omemo/QXmppOmemoManager.cpp | 3 --- tests/qxmppomemomanager/tst_qxmppomemomanager.cpp | 2 -- 5 files changed, 2 insertions(+), 9 deletions(-) (limited to 'src') diff --git a/src/base/QXmppOmemoElement_p.h b/src/base/QXmppOmemoElement_p.h index 1e160479..cd95ea00 100644 --- a/src/base/QXmppOmemoElement_p.h +++ b/src/base/QXmppOmemoElement_p.h @@ -7,13 +7,13 @@ #define QXMPPOMEMOELEMENT_H #include "QXmppGlobal.h" +#include "QXmppOmemoEnvelope_p.h" #include #include class QDomElement; -class QXmppOmemoEnvelope; class QXmlStreamWriter; class QXMPP_EXPORT QXmppOmemoElement diff --git a/src/omemo/QXmppOmemoData.cpp b/src/omemo/QXmppOmemoData.cpp index d1dd2a88..d457326a 100644 --- a/src/omemo/QXmppOmemoData.cpp +++ b/src/omemo/QXmppOmemoData.cpp @@ -8,10 +8,8 @@ #include "QXmppOmemoDeviceElement_p.h" #include "QXmppOmemoDeviceList_p.h" #include "QXmppOmemoElement_p.h" -#include "QXmppOmemoEnvelope_p.h" #include "QXmppOmemoIq_p.h" #include "QXmppOmemoItems_p.h" -#include "QXmppUtils.h" #include #include diff --git a/src/omemo/QXmppOmemoDeviceList_p.h b/src/omemo/QXmppOmemoDeviceList_p.h index 76bff435..46ac724d 100644 --- a/src/omemo/QXmppOmemoDeviceList_p.h +++ b/src/omemo/QXmppOmemoDeviceList_p.h @@ -7,12 +7,12 @@ #define QXMPPOMEMODEVICELIST_H #include "QXmppGlobal.h" +#include "QXmppOmemoDeviceElement_p.h" #include "QList" class QDomElement; class QXmlStreamWriter; -class QXmppOmemoDeviceElement; class QXMPP_AUTOTEST_EXPORT QXmppOmemoDeviceList : public QList { diff --git a/src/omemo/QXmppOmemoManager.cpp b/src/omemo/QXmppOmemoManager.cpp index 7b38c73e..f3137889 100644 --- a/src/omemo/QXmppOmemoManager.cpp +++ b/src/omemo/QXmppOmemoManager.cpp @@ -5,10 +5,7 @@ #include "QXmppClient.h" #include "QXmppConstants_p.h" -#include "QXmppOmemoDeviceElement_p.h" -#include "QXmppOmemoDeviceList_p.h" #include "QXmppOmemoElement_p.h" -#include "QXmppOmemoEnvelope_p.h" #include "QXmppOmemoIq_p.h" #include "QXmppOmemoItems_p.h" #include "QXmppOmemoManager_p.h" diff --git a/tests/qxmppomemomanager/tst_qxmppomemomanager.cpp b/tests/qxmppomemomanager/tst_qxmppomemomanager.cpp index 95c70237..e6d2c7ed 100644 --- a/tests/qxmppomemomanager/tst_qxmppomemomanager.cpp +++ b/tests/qxmppomemomanager/tst_qxmppomemomanager.cpp @@ -12,11 +12,9 @@ #include "QXmppE2eeMetadata.h" #include "QXmppMessage.h" #include "QXmppOmemoElement_p.h" -#include "QXmppOmemoEnvelope_p.h" #include "QXmppOmemoManager.h" #include "QXmppOmemoManager_p.h" #include "QXmppOmemoMemoryStorage.h" -#include "QXmppPubSubItem.h" #include "QXmppPubSubManager.h" #include "IntegrationTesting.h" -- cgit v1.2.3 From 761929aebc57bb4de20f62c3f6a73d6b2706c47f Mon Sep 17 00:00:00 2001 From: Linus Jahn Date: Wed, 8 Mar 2023 12:50:18 +0100 Subject: SceEnvelope: Don't use reference to avoid misusage --- src/client/QXmppSceEnvelope_p.h | 6 +++--- tests/qxmppsceenvelope/tst_qxmppsceenvelope.cpp | 3 +-- 2 files changed, 4 insertions(+), 5 deletions(-) (limited to 'src') diff --git a/src/client/QXmppSceEnvelope_p.h b/src/client/QXmppSceEnvelope_p.h index 4a92378d..b40da9fd 100644 --- a/src/client/QXmppSceEnvelope_p.h +++ b/src/client/QXmppSceEnvelope_p.h @@ -25,8 +25,8 @@ class QXmppSceEnvelopeReader { public: - QXmppSceEnvelopeReader(const QDomElement &element) - : element(element) + QXmppSceEnvelopeReader(QDomElement &&element) + : element(std::move(element)) { } @@ -51,7 +51,7 @@ public: // rpad is usually not needed (but can be parsed manually if really needed) private: - const QDomElement &element; + QDomElement element; }; class QXmppSceEnvelopeWriter diff --git a/tests/qxmppsceenvelope/tst_qxmppsceenvelope.cpp b/tests/qxmppsceenvelope/tst_qxmppsceenvelope.cpp index a490a5c0..30c6d493 100644 --- a/tests/qxmppsceenvelope/tst_qxmppsceenvelope.cpp +++ b/tests/qxmppsceenvelope/tst_qxmppsceenvelope.cpp @@ -26,9 +26,8 @@ void tst_QXmppSceEnvelope::testReader() "" "C1DHN9HK-9A25tSmwK4hU!Jji9%GKYK^syIlHJT9TnI4" ""); - const auto dom = xmlToDom(xml); - QXmppSceEnvelopeReader reader(dom); + QXmppSceEnvelopeReader reader(xmlToDom(xml)); QCOMPARE(reader.from(), QStringLiteral("opportunity@mars.planet")); QCOMPARE(reader.to(), QStringLiteral("missioncontrol@houston.nasa.gov")); QCOMPARE(reader.timestamp(), QDateTime({ 2004, 01, 25 }, { 05, 05, 00 }, Qt::UTC)); -- cgit v1.2.3 From a19e16a54149be09fb5913ac211577ce254f6b28 Mon Sep 17 00:00:00 2001 From: Linus Jahn Date: Thu, 9 Mar 2023 16:01:17 +0100 Subject: omemo: Fix usage of unexported symbols from Constants_p.h This adds the constants to files from the omemo module. It fixes the build of the omemo module on windows with MSVC (and potentially release builds on linux too). --- src/omemo/QXmppOmemoManager.cpp | 1 - src/omemo/QXmppOmemoManager_p.cpp | 10 +++++++++- src/omemo/QXmppOmemoManager_p.h | 5 +++++ 3 files changed, 14 insertions(+), 2 deletions(-) (limited to 'src') diff --git a/src/omemo/QXmppOmemoManager.cpp b/src/omemo/QXmppOmemoManager.cpp index f3137889..8af588d1 100644 --- a/src/omemo/QXmppOmemoManager.cpp +++ b/src/omemo/QXmppOmemoManager.cpp @@ -4,7 +4,6 @@ // SPDX-License-Identifier: LGPL-2.1-or-later #include "QXmppClient.h" -#include "QXmppConstants_p.h" #include "QXmppOmemoElement_p.h" #include "QXmppOmemoIq_p.h" #include "QXmppOmemoItems_p.h" diff --git a/src/omemo/QXmppOmemoManager_p.cpp b/src/omemo/QXmppOmemoManager_p.cpp index 9d2d41a2..f3b71545 100644 --- a/src/omemo/QXmppOmemoManager_p.cpp +++ b/src/omemo/QXmppOmemoManager_p.cpp @@ -7,7 +7,6 @@ #include "QXmppOmemoManager_p.h" -#include "QXmppConstants_p.h" #include "QXmppOmemoDeviceElement_p.h" #include "QXmppOmemoElement_p.h" #include "QXmppOmemoEnvelope_p.h" @@ -36,6 +35,15 @@ using Error = QXmppStanza::Error; using Manager = QXmppOmemoManager; using ManagerPrivate = QXmppOmemoManagerPrivate; +const char *ns_client = "jabber:client"; +const char *ns_pubsub_auto_create = "http://jabber.org/protocol/pubsub#auto-create"; +const char *ns_pubsub_config_node = "http://jabber.org/protocol/pubsub#config-node"; +const char *ns_pubsub_config_node_max = "http://jabber.org/protocol/pubsub#config-node-max"; +const char *ns_pubsub_create_and_configure = "http://jabber.org/protocol/pubsub#create-and-configure"; +const char *ns_pubsub_create_nodes = "http://jabber.org/protocol/pubsub#create-nodes"; +const char *ns_pubsub_publish = "http://jabber.org/protocol/pubsub#publish"; +const char *ns_pubsub_publish_options = "http://jabber.org/protocol/pubsub#publish-options"; + namespace QXmpp::Omemo::Private { const QString PAYLOAD_MESSAGE_AUTHENTICATION_CODE_TYPE = QStringLiteral("hmac(sha256)"); diff --git a/src/omemo/QXmppOmemoManager_p.h b/src/omemo/QXmppOmemoManager_p.h index 838e68ad..db488023 100644 --- a/src/omemo/QXmppOmemoManager_p.h +++ b/src/omemo/QXmppOmemoManager_p.h @@ -34,6 +34,11 @@ using namespace std::chrono_literals; namespace QXmpp::Omemo::Private { +// XMPP namespaces +constexpr auto ns_omemo_2 = "urn:xmpp:omemo:2"; +constexpr auto ns_omemo_2_bundles = "urn:xmpp:omemo:2:bundles"; +constexpr auto ns_omemo_2_devices = "urn:xmpp:omemo:2:devices"; + // default possible trust levels a key must have to be used for encryption // The class documentation must be adapted if the trust levels are modified. constexpr auto ACCEPTED_TRUST_LEVELS = TrustLevel::AutomaticallyTrusted | TrustLevel::ManuallyTrusted | TrustLevel::Authenticated; -- cgit v1.2.3 From fe5986783ad816111994a752216d58ee043ef6d8 Mon Sep 17 00:00:00 2001 From: Jonah Brüchert Date: Thu, 9 Mar 2023 16:48:09 +0100 Subject: omemo: Fix build on MSVC 2019 (#550) --- src/omemo/QXmppOmemoData.cpp | 3 ++- src/omemo/QXmppOmemoManager.cpp | 3 +++ src/omemo/QXmppOmemoManager_p.cpp | 3 +++ src/omemo/QXmppOmemoManager_p.h | 9 ++++++--- 4 files changed, 14 insertions(+), 4 deletions(-) (limited to 'src') diff --git a/src/omemo/QXmppOmemoData.cpp b/src/omemo/QXmppOmemoData.cpp index d457326a..6bc1815b 100644 --- a/src/omemo/QXmppOmemoData.cpp +++ b/src/omemo/QXmppOmemoData.cpp @@ -3,7 +3,6 @@ // // SPDX-License-Identifier: LGPL-2.1-or-later -#include "QXmppConstants_p.h" #include "QXmppOmemoDeviceBundle_p.h" #include "QXmppOmemoDeviceElement_p.h" #include "QXmppOmemoDeviceList_p.h" @@ -14,6 +13,8 @@ #include #include +const char *ns_omemo_2 = "urn:xmpp:omemo:2"; + /// \cond /// /// \class QXmppOmemoDeviceElement diff --git a/src/omemo/QXmppOmemoManager.cpp b/src/omemo/QXmppOmemoManager.cpp index 8af588d1..7ad511e0 100644 --- a/src/omemo/QXmppOmemoManager.cpp +++ b/src/omemo/QXmppOmemoManager.cpp @@ -14,6 +14,9 @@ #include +#undef max +#undef interface + using namespace QXmpp; using namespace QXmpp::Private; using namespace QXmpp::Omemo::Private; diff --git a/src/omemo/QXmppOmemoManager_p.cpp b/src/omemo/QXmppOmemoManager_p.cpp index f3b71545..8da77f5f 100644 --- a/src/omemo/QXmppOmemoManager_p.cpp +++ b/src/omemo/QXmppOmemoManager_p.cpp @@ -27,6 +27,9 @@ #endif #include +#undef max +#undef interface + using namespace QXmpp; using namespace QXmpp::Private; using namespace QXmpp::Omemo::Private; diff --git a/src/omemo/QXmppOmemoManager_p.h b/src/omemo/QXmppOmemoManager_p.h index db488023..01a372a7 100644 --- a/src/omemo/QXmppOmemoManager_p.h +++ b/src/omemo/QXmppOmemoManager_p.h @@ -18,6 +18,8 @@ #include #include +#undef max + class QXmppTrustManager; class QXmppOmemoManager; class QXmppPubSubManager; @@ -171,9 +173,10 @@ public: QXmppOmemoManagerPrivate(QXmppOmemoManager *parent, QXmppOmemoStorage *omemoStorage); void init(); - bool initGlobalContext(); - bool initLocking(); - bool initCryptoProvider(); + // exports for unit tests + QXMPP_EXPORT bool initGlobalContext(); + QXMPP_EXPORT bool initLocking(); + QXMPP_EXPORT bool initCryptoProvider(); void initStores(); signal_protocol_identity_key_store createIdentityKeyStore() const; -- cgit v1.2.3 From 18353901a2215376e2f0274a408ce2213c180f16 Mon Sep 17 00:00:00 2001 From: Linus Jahn Date: Thu, 9 Mar 2023 17:36:17 +0100 Subject: SaslDigestMd5: Fix UB when at the end of input byte array [Qt6 only] Also adds a unit test. Fixes #541. --- src/base/QXmppSasl.cpp | 8 ++++++-- tests/qxmppsasl/tst_qxmppsasl.cpp | 10 ++++++++++ 2 files changed, 16 insertions(+), 2 deletions(-) (limited to 'src') diff --git a/src/base/QXmppSasl.cpp b/src/base/QXmppSasl.cpp index d8a86bb0..86e67b01 100644 --- a/src/base/QXmppSasl.cpp +++ b/src/base/QXmppSasl.cpp @@ -896,8 +896,12 @@ QMap QXmppSaslDigestMd5::parseMessage(const QByteArray & const QByteArray key = ba.mid(startIndex, pos - startIndex).trimmed(); pos++; - // check whether string is quoted - if (ba.at(pos) == '"') { + if (pos == ba.size()) { + // end of the input + map.insert(key, QByteArray()); + startIndex = pos; + } else if (ba.at(pos) == '"') { + // check whether string is quoted // skip opening quote pos++; int endPos = ba.indexOf('"', pos); diff --git a/tests/qxmppsasl/tst_qxmppsasl.cpp b/tests/qxmppsasl/tst_qxmppsasl.cpp index 951af0b4..88dd5673 100644 --- a/tests/qxmppsasl/tst_qxmppsasl.cpp +++ b/tests/qxmppsasl/tst_qxmppsasl.cpp @@ -28,6 +28,7 @@ private: Q_SLOT void testClientAnonymous(); Q_SLOT void testClientDigestMd5(); Q_SLOT void testClientDigestMd5_data(); + Q_SLOT void testDigestMd5ParseMessage(); Q_SLOT void testClientFacebook(); Q_SLOT void testClientGoogle(); Q_SLOT void testClientPlain(); @@ -220,6 +221,15 @@ void tst_QXmppSasl::testClientDigestMd5_data() QTest::newRow("qop-multi") << QByteArray(",qop=\"auth,auth-int\""); } +void tst_QXmppSasl::testDigestMd5ParseMessage() +{ + auto result = QXmppSaslDigestMd5::parseMessage("charset=utf-8,digest-uri=\"xmpp/0.0.0.0\",nc=00000001,qop=auth,realm=0.0.0.0,response=9c3ee0a919d714c9d72853ff51c0a4f3,username="); + QCOMPARE(result["username"], QByteArray()); + + result = QXmppSaslDigestMd5::parseMessage("nc=00000001,username=,qop=auth,realm=0.0.0.0,response=9c3ee0a919d714c9d72853ff51c0a4f3"); + QCOMPARE(result["username"], QByteArray()); +} + void tst_QXmppSasl::testClientDigestMd5() { QFETCH(QByteArray, qop); -- cgit v1.2.3 From fcd8224256e38d50d4ec67b71c504dcb6e480e95 Mon Sep 17 00:00:00 2001 From: Linus Jahn Date: Thu, 9 Mar 2023 18:48:21 +0100 Subject: Rename PubSubItem -> PubSubBaseItem to be able to include old PubSubItem --- src/CMakeLists.txt | 4 +- src/base/QXmppGeolocItem.cpp | 2 +- src/base/QXmppGeolocItem.h | 4 +- src/base/QXmppMixInfoItem.h | 4 +- src/base/QXmppMixItems.cpp | 4 +- src/base/QXmppMixParticipantItem.h | 4 +- src/base/QXmppPubSubBaseItem.cpp | 152 +++++++++++++++++++++ src/base/QXmppPubSubBaseItem.h | 87 ++++++++++++ src/base/QXmppPubSubEvent.h | 4 +- src/base/QXmppPubSubIq_p.h | 4 +- src/base/QXmppPubSubItem.cpp | 152 --------------------- src/base/QXmppPubSubItem.h | 90 ------------ src/base/QXmppUserTuneItem.cpp | 2 +- src/base/QXmppUserTuneItem.h | 4 +- src/client/QXmppPubSubManager.cpp | 10 +- src/client/QXmppPubSubManager.h | 14 +- src/omemo/QXmppOmemoData.cpp | 4 +- src/omemo/QXmppOmemoItems_p.h | 6 +- src/omemo/QXmppOmemoManager_p.cpp | 2 +- tests/pubsubutil.h | 8 +- tests/qxmpppubsub/tst_qxmpppubsub.cpp | 8 +- tests/qxmpppubsubevent/tst_qxmpppubsubevent.cpp | 22 +-- tests/qxmpppubsubiq/tst_qxmpppubsubiq.cpp | 6 +- .../qxmpppubsubmanager/tst_qxmpppubsubmanager.cpp | 20 +-- 24 files changed, 307 insertions(+), 310 deletions(-) create mode 100644 src/base/QXmppPubSubBaseItem.cpp create mode 100644 src/base/QXmppPubSubBaseItem.h delete mode 100644 src/base/QXmppPubSubItem.cpp delete mode 100644 src/base/QXmppPubSubItem.h (limited to 'src') diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 4a260a7b..0f533a01 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -52,7 +52,7 @@ set(INSTALL_HEADER_FILES base/QXmppPubSubAffiliation.h base/QXmppPubSubEvent.h base/QXmppPubSubIq_p.h - base/QXmppPubSubItem.h + base/QXmppPubSubBaseItem.h base/QXmppPubSubMetadata.h base/QXmppPubSubNodeConfig.h base/QXmppPubSubPublishOptions.h @@ -184,7 +184,7 @@ set(SOURCE_FILES base/QXmppPubSubAffiliation.cpp base/QXmppPubSubEvent.cpp base/QXmppPubSubIq.cpp - base/QXmppPubSubItem.cpp + base/QXmppPubSubBaseItem.cpp base/QXmppPubSubMetadata.cpp base/QXmppPubSubNodeConfig.cpp base/QXmppPubSubSubscribeOptions.cpp diff --git a/src/base/QXmppGeolocItem.cpp b/src/base/QXmppGeolocItem.cpp index b6bf0b85..32e08189 100644 --- a/src/base/QXmppGeolocItem.cpp +++ b/src/base/QXmppGeolocItem.cpp @@ -146,7 +146,7 @@ bool QXmppGeolocItem::isItem(const QDomElement &itemElement) payload.namespaceURI() == ns_geoloc; }; - return QXmppPubSubItem::isItem(itemElement, isPayloadValid); + return QXmppPubSubBaseItem::isItem(itemElement, isPayloadValid); } /// \cond diff --git a/src/base/QXmppGeolocItem.h b/src/base/QXmppGeolocItem.h index 05d42dba..58914b1b 100644 --- a/src/base/QXmppGeolocItem.h +++ b/src/base/QXmppGeolocItem.h @@ -5,7 +5,7 @@ #ifndef QXMPPGEOLOCITEM_H #define QXMPPGEOLOCITEM_H -#include "QXmppPubSubItem.h" +#include "QXmppPubSubBaseItem.h" #include @@ -13,7 +13,7 @@ class QXmppGeolocItemPrivate; -class QXMPP_EXPORT QXmppGeolocItem : public QXmppPubSubItem +class QXMPP_EXPORT QXmppGeolocItem : public QXmppPubSubBaseItem { public: QXmppGeolocItem(); diff --git a/src/base/QXmppMixInfoItem.h b/src/base/QXmppMixInfoItem.h index 9a28decb..313c3e14 100644 --- a/src/base/QXmppMixInfoItem.h +++ b/src/base/QXmppMixInfoItem.h @@ -5,11 +5,11 @@ #ifndef QXMPPMIXINFOITEM_H #define QXMPPMIXINFOITEM_H -#include "QXmppPubSubItem.h" +#include "QXmppPubSubBaseItem.h" class QXmppMixInfoItemPrivate; -class QXMPP_EXPORT QXmppMixInfoItem : public QXmppPubSubItem +class QXMPP_EXPORT QXmppMixInfoItem : public QXmppPubSubBaseItem { public: QXmppMixInfoItem(); diff --git a/src/base/QXmppMixItems.cpp b/src/base/QXmppMixItems.cpp index e08dd3f2..a19edbb0 100644 --- a/src/base/QXmppMixItems.cpp +++ b/src/base/QXmppMixItems.cpp @@ -138,7 +138,7 @@ void QXmppMixInfoItem::setContactJids(QStringList contactJids) /// bool QXmppMixInfoItem::isItem(const QDomElement &element) { - return QXmppPubSubItem::isItem(element, [](const QDomElement &payload) { + return QXmppPubSubBaseItem::isItem(element, [](const QDomElement &payload) { // check FORM_TYPE without parsing a full QXmppDataForm if (payload.tagName() != u'x' || payload.namespaceURI() != ns_data) { return false; @@ -264,7 +264,7 @@ void QXmppMixParticipantItem::serializePayload(QXmlStreamWriter *writer) const /// bool QXmppMixParticipantItem::isItem(const QDomElement &element) { - return QXmppPubSubItem::isItem(element, [](const QDomElement &payload) { + return QXmppPubSubBaseItem::isItem(element, [](const QDomElement &payload) { return payload.tagName() == QStringLiteral("participant") && payload.namespaceURI() == ns_mix; }); diff --git a/src/base/QXmppMixParticipantItem.h b/src/base/QXmppMixParticipantItem.h index f0f2abaa..ce179fbe 100644 --- a/src/base/QXmppMixParticipantItem.h +++ b/src/base/QXmppMixParticipantItem.h @@ -5,11 +5,11 @@ #ifndef QXMPPMIXPARTICIPANTITEM_H #define QXMPPMIXPARTICIPANTITEM_H -#include "QXmppPubSubItem.h" +#include "QXmppPubSubBaseItem.h" class QXmppMixParticipantItemPrivate; -class QXMPP_EXPORT QXmppMixParticipantItem : public QXmppPubSubItem +class QXMPP_EXPORT QXmppMixParticipantItem : public QXmppPubSubBaseItem { public: QXmppMixParticipantItem(); diff --git a/src/base/QXmppPubSubBaseItem.cpp b/src/base/QXmppPubSubBaseItem.cpp new file mode 100644 index 00000000..43b1aa88 --- /dev/null +++ b/src/base/QXmppPubSubBaseItem.cpp @@ -0,0 +1,152 @@ +// SPDX-FileCopyrightText: 2019 Jeremy Lainé +// SPDX-FileCopyrightText: 2019 Linus Jahn +// +// SPDX-License-Identifier: LGPL-2.1-or-later + +#include "QXmppPubSubBaseItem.h" + +#include "QXmppElement.h" +#include "QXmppUtils.h" + +#include + +class QXmppPubSubBaseItemPrivate : public QSharedData +{ +public: + QXmppPubSubBaseItemPrivate(const QString &id, const QString &publisher); + + QString id; + QString publisher; +}; + +QXmppPubSubBaseItemPrivate::QXmppPubSubBaseItemPrivate(const QString &id, const QString &publisher) + : id(id), publisher(publisher) +{ +} + +/// +/// \class QXmppPubSubBaseItem +/// +/// The QXmppPubSubBaseItem class represents a publish-subscribe item as defined by +/// \xep{0060, Publish-Subscribe}. +/// +/// To access the payload of an item, you need to create a derived class of this +/// and override QXmppPubSubBaseItem::parsePayload() and +/// QXmppPubSubBaseItem::serializePayload(). +/// +/// It is also required that you override QXmppPubSubBaseItem::isItem() and also +/// check for the correct payload of the PubSub item. This can be easily done by +/// using the protected overload of isItem() with an function that checks the +/// tag name and namespace of the payload. The function is only called if a +/// payload exists. +/// +/// In short, you need to reimplement these methods: +/// * QXmppPubSubBaseItem::parsePayload() +/// * QXmppPubSubBaseItem::serializePayload() +/// * QXmppPubSubBaseItem::isItem() +/// +/// \since QXmpp 1.5 +/// + +/// +/// Constructs an item with \a id and \a publisher. +/// +/// \param id +/// \param publisher +/// +QXmppPubSubBaseItem::QXmppPubSubBaseItem(const QString &id, const QString &publisher) + : d(new QXmppPubSubBaseItemPrivate(id, publisher)) +{ +} + +/// Default copy-constructor +QXmppPubSubBaseItem::QXmppPubSubBaseItem(const QXmppPubSubBaseItem &iq) = default; +/// Default move-constructor +QXmppPubSubBaseItem::QXmppPubSubBaseItem(QXmppPubSubBaseItem &&) = default; +QXmppPubSubBaseItem::~QXmppPubSubBaseItem() = default; +/// Default assignment operator +QXmppPubSubBaseItem &QXmppPubSubBaseItem::operator=(const QXmppPubSubBaseItem &iq) = default; +/// Default move-assignment operator +QXmppPubSubBaseItem &QXmppPubSubBaseItem::operator=(QXmppPubSubBaseItem &&iq) = default; + +/// +/// Returns the ID of the PubSub item. +/// +QString QXmppPubSubBaseItem::id() const +{ + return d->id; +} + +/// +/// Sets the ID of the PubSub item. +/// +/// \param id +/// +void QXmppPubSubBaseItem::setId(const QString &id) +{ + d->id = id; +} + +/// +/// Returns the JID of the publisher of the item. +/// +QString QXmppPubSubBaseItem::publisher() const +{ + return d->publisher; +} + +/// +/// Sets the JID of the publisher of the item. +/// +void QXmppPubSubBaseItem::setPublisher(const QString &publisher) +{ + d->publisher = publisher; +} + +/// \cond +void QXmppPubSubBaseItem::parse(const QDomElement &element) +{ + d->id = element.attribute(QStringLiteral("id")); + d->publisher = element.attribute(QStringLiteral("publisher")); + + parsePayload(element.firstChildElement()); +} + +void QXmppPubSubBaseItem::toXml(QXmlStreamWriter *writer) const +{ + writer->writeStartElement(QStringLiteral("item")); + helperToXmlAddAttribute(writer, QStringLiteral("id"), d->id); + helperToXmlAddAttribute(writer, QStringLiteral("publisher"), d->publisher); + + serializePayload(writer); + + writer->writeEndElement(); +} +/// \endcond + +/// +/// Returns true, if the element is possibly a PubSub item. +/// +bool QXmppPubSubBaseItem::isItem(const QDomElement &element) +{ + return element.tagName() == QStringLiteral("item"); +} + +/// +/// Parses the payload of the item (the child element of the <item/>). +/// +/// This method needs to be overriden to perform the payload-specific parsing. +/// +void QXmppPubSubBaseItem::parsePayload(const QDomElement &) +{ +} + +/// +/// Serializes the payload of the item (the child element of the <item/>). +/// +/// This method needs to be overriden to perform the payload-specific +/// serialization. +/// +void QXmppPubSubBaseItem::serializePayload(QXmlStreamWriter *) const +{ +} diff --git a/src/base/QXmppPubSubBaseItem.h b/src/base/QXmppPubSubBaseItem.h new file mode 100644 index 00000000..20702662 --- /dev/null +++ b/src/base/QXmppPubSubBaseItem.h @@ -0,0 +1,87 @@ +// SPDX-FileCopyrightText: 2019 Jeremy Lainé +// SPDX-FileCopyrightText: 2019 Linus Jahn +// +// SPDX-License-Identifier: LGPL-2.1-or-later + +#pragma once + +#include "QXmppGlobal.h" + +#include +#include +#include + +class QXmlStreamWriter; +class QXmppPubSubBaseItemPrivate; + +class QXMPP_EXPORT QXmppPubSubBaseItem +{ +public: + QXmppPubSubBaseItem(const QString &id = {}, const QString &publisher = {}); + QXmppPubSubBaseItem(const QXmppPubSubBaseItem &); + QXmppPubSubBaseItem(QXmppPubSubBaseItem &&); + virtual ~QXmppPubSubBaseItem(); + + QXmppPubSubBaseItem &operator=(const QXmppPubSubBaseItem &); + QXmppPubSubBaseItem &operator=(QXmppPubSubBaseItem &&); + + QString id() const; + void setId(const QString &id); + + QString publisher() const; + void setPublisher(const QString &publisher); + + /// \cond + void parse(const QDomElement &element); + void toXml(QXmlStreamWriter *writer) const; + /// \endcond + + static bool isItem(const QDomElement &element); + +protected: + virtual void parsePayload(const QDomElement &payloadElement); + virtual void serializePayload(QXmlStreamWriter *writer) const; + + template + static bool isItem(const QDomElement &element, PayloadChecker isPayloadValid); + +private: + QSharedDataPointer d; +}; + +/// +/// Returns true, if the element is a valid PubSub item and (if existant) the +/// payload is correct. +/// +/// \param element The element to be checked to be an <item/> element. +/// \param isPayloadValid A function that validates the payload element (first +/// child element). The functions needs to return true, if the payload is valid. +/// In case there is no payload, the function is not called. +/// +/// Here is an example covering how this could be used to check for the +/// \xep{0118, User Tune} payload: +/// \code +/// auto isPayloadValid = [](const QDomElement &payload) -> bool { +/// return payload.tagName() == "tune" && payload.namespaceURI() == ns_tune; +/// }; +/// +/// bool valid = QXmppPubSubItem::isItem(itemElement, isPayloadValid); +/// \endcode +/// +template +bool QXmppPubSubBaseItem::isItem(const QDomElement &element, PayloadChecker isPayloadValid) +{ + if (!isItem(element)) { + return false; + } + + const QDomElement payload = element.firstChildElement(); + + // we can only check the payload if it's existant + if (!payload.isNull()) { + return isPayloadValid(payload); + } + return true; +} + +Q_DECLARE_METATYPE(QXmppPubSubBaseItem) diff --git a/src/base/QXmppPubSubEvent.h b/src/base/QXmppPubSubEvent.h index 0faf62b6..3625c8aa 100644 --- a/src/base/QXmppPubSubEvent.h +++ b/src/base/QXmppPubSubEvent.h @@ -15,7 +15,7 @@ class QXmppDataForm; class QXmppPubSubEventPrivate; -class QXmppPubSubItem; +class QXmppPubSubBaseItem; class QXMPP_EXPORT QXmppPubSubEventBase : public QXmppMessage { @@ -73,7 +73,7 @@ private: QSharedDataPointer d; }; -template +template class QXmppPubSubEvent : public QXmppPubSubEventBase { public: diff --git a/src/base/QXmppPubSubIq_p.h b/src/base/QXmppPubSubIq_p.h index eb5ed43f..6868eb84 100644 --- a/src/base/QXmppPubSubIq_p.h +++ b/src/base/QXmppPubSubIq_p.h @@ -15,7 +15,7 @@ class QXmppDataForm; class QXmppPubSubIqPrivate; -class QXmppPubSubItem; +class QXmppPubSubBaseItem; class QXmppPubSubSubscription; class QXmppPubSubAffiliation; class QXmppResultSetReply; @@ -103,7 +103,7 @@ private: QSharedDataPointer d; }; -template +template class PubSubIq : public PubSubIqBase { public: diff --git a/src/base/QXmppPubSubItem.cpp b/src/base/QXmppPubSubItem.cpp deleted file mode 100644 index f87c5d6e..00000000 --- a/src/base/QXmppPubSubItem.cpp +++ /dev/null @@ -1,152 +0,0 @@ -// SPDX-FileCopyrightText: 2019 Jeremy Lainé -// SPDX-FileCopyrightText: 2019 Linus Jahn -// -// SPDX-License-Identifier: LGPL-2.1-or-later - -#include "QXmppPubSubItem.h" - -#include "QXmppElement.h" -#include "QXmppUtils.h" - -#include - -class QXmppPubSubItemPrivate : public QSharedData -{ -public: - QXmppPubSubItemPrivate(const QString &id, const QString &publisher); - - QString id; - QString publisher; -}; - -QXmppPubSubItemPrivate::QXmppPubSubItemPrivate(const QString &id, const QString &publisher) - : id(id), publisher(publisher) -{ -} - -/// -/// \class QXmppPubSubItem -/// -/// The QXmppPubSubItem class represents a publish-subscribe item as defined by -/// \xep{0060, Publish-Subscribe}. -/// -/// To access the payload of an item, you need to create a derived class of this -/// and override QXmppPubSubItem::parsePayload() and -/// QXmppPubSubItem::serializePayload(). -/// -/// It is also required that you override QXmppPubSubItem::isItem() and also -/// check for the correct payload of the PubSub item. This can be easily done by -/// using the protected overload of isItem() with an function that checks the -/// tag name and namespace of the payload. The function is only called if a -/// payload exists. -/// -/// In short, you need to reimplement these methods: -/// * QXmppPubSubItem::parsePayload() -/// * QXmppPubSubItem::serializePayload() -/// * QXmppPubSubItem::isItem() -/// -/// \since QXmpp 1.5 -/// - -/// -/// Constructs an item with \a id and \a publisher. -/// -/// \param id -/// \param publisher -/// -QXmppPubSubItem::QXmppPubSubItem(const QString &id, const QString &publisher) - : d(new QXmppPubSubItemPrivate(id, publisher)) -{ -} - -/// Default copy-constructor -QXmppPubSubItem::QXmppPubSubItem(const QXmppPubSubItem &iq) = default; -/// Default move-constructor -QXmppPubSubItem::QXmppPubSubItem(QXmppPubSubItem &&) = default; -QXmppPubSubItem::~QXmppPubSubItem() = default; -/// Default assignment operator -QXmppPubSubItem &QXmppPubSubItem::operator=(const QXmppPubSubItem &iq) = default; -/// Default move-assignment operator -QXmppPubSubItem &QXmppPubSubItem::operator=(QXmppPubSubItem &&iq) = default; - -/// -/// Returns the ID of the PubSub item. -/// -QString QXmppPubSubItem::id() const -{ - return d->id; -} - -/// -/// Sets the ID of the PubSub item. -/// -/// \param id -/// -void QXmppPubSubItem::setId(const QString &id) -{ - d->id = id; -} - -/// -/// Returns the JID of the publisher of the item. -/// -QString QXmppPubSubItem::publisher() const -{ - return d->publisher; -} - -/// -/// Sets the JID of the publisher of the item. -/// -void QXmppPubSubItem::setPublisher(const QString &publisher) -{ - d->publisher = publisher; -} - -/// \cond -void QXmppPubSubItem::parse(const QDomElement &element) -{ - d->id = element.attribute(QStringLiteral("id")); - d->publisher = element.attribute(QStringLiteral("publisher")); - - parsePayload(element.firstChildElement()); -} - -void QXmppPubSubItem::toXml(QXmlStreamWriter *writer) const -{ - writer->writeStartElement(QStringLiteral("item")); - helperToXmlAddAttribute(writer, QStringLiteral("id"), d->id); - helperToXmlAddAttribute(writer, QStringLiteral("publisher"), d->publisher); - - serializePayload(writer); - - writer->writeEndElement(); -} -/// \endcond - -/// -/// Returns true, if the element is possibly a PubSub item. -/// -bool QXmppPubSubItem::isItem(const QDomElement &element) -{ - return element.tagName() == QStringLiteral("item"); -} - -/// -/// Parses the payload of the item (the child element of the <item/>). -/// -/// This method needs to be overriden to perform the payload-specific parsing. -/// -void QXmppPubSubItem::parsePayload(const QDomElement &) -{ -} - -/// -/// Serializes the payload of the item (the child element of the <item/>). -/// -/// This method needs to be overriden to perform the payload-specific -/// serialization. -/// -void QXmppPubSubItem::serializePayload(QXmlStreamWriter *) const -{ -} diff --git a/src/base/QXmppPubSubItem.h b/src/base/QXmppPubSubItem.h deleted file mode 100644 index e585de9d..00000000 --- a/src/base/QXmppPubSubItem.h +++ /dev/null @@ -1,90 +0,0 @@ -// SPDX-FileCopyrightText: 2019 Jeremy Lainé -// SPDX-FileCopyrightText: 2019 Linus Jahn -// -// SPDX-License-Identifier: LGPL-2.1-or-later - -#ifndef QXMPPPUBSUBITEM_H -#define QXMPPPUBSUBITEM_H - -#include "QXmppGlobal.h" - -#include -#include -#include - -class QXmlStreamWriter; -class QXmppPubSubItemPrivate; - -class QXMPP_EXPORT QXmppPubSubItem -{ -public: - QXmppPubSubItem(const QString &id = {}, const QString &publisher = {}); - QXmppPubSubItem(const QXmppPubSubItem &); - QXmppPubSubItem(QXmppPubSubItem &&); - virtual ~QXmppPubSubItem(); - - QXmppPubSubItem &operator=(const QXmppPubSubItem &); - QXmppPubSubItem &operator=(QXmppPubSubItem &&); - - QString id() const; - void setId(const QString &id); - - QString publisher() const; - void setPublisher(const QString &publisher); - - /// \cond - void parse(const QDomElement &element); - void toXml(QXmlStreamWriter *writer) const; - /// \endcond - - static bool isItem(const QDomElement &element); - -protected: - virtual void parsePayload(const QDomElement &payloadElement); - virtual void serializePayload(QXmlStreamWriter *writer) const; - - template - static bool isItem(const QDomElement &element, PayloadChecker isPayloadValid); - -private: - QSharedDataPointer d; -}; - -/// -/// Returns true, if the element is a valid PubSub item and (if existant) the -/// payload is correct. -/// -/// \param element The element to be checked to be an <item/> element. -/// \param isPayloadValid A function that validates the payload element (first -/// child element). The functions needs to return true, if the payload is valid. -/// In case there is no payload, the function is not called. -/// -/// Here is an example covering how this could be used to check for the -/// \xep{0118, User Tune} payload: -/// \code -/// auto isPayloadValid = [](const QDomElement &payload) -> bool { -/// return payload.tagName() == "tune" && payload.namespaceURI() == ns_tune; -/// }; -/// -/// bool valid = QXmppPubSubItem::isItem(itemElement, isPayloadValid); -/// \endcode -/// -template -bool QXmppPubSubItem::isItem(const QDomElement &element, PayloadChecker isPayloadValid) -{ - if (!isItem(element)) { - return false; - } - - const QDomElement payload = element.firstChildElement(); - - // we can only check the payload if it's existant - if (!payload.isNull()) { - return isPayloadValid(payload); - } - return true; -} - -Q_DECLARE_METATYPE(QXmppPubSubItem) - -#endif // QXMPPPUBSUBITEM_H diff --git a/src/base/QXmppUserTuneItem.cpp b/src/base/QXmppUserTuneItem.cpp index 6d8fb8bf..55d30333 100644 --- a/src/base/QXmppUserTuneItem.cpp +++ b/src/base/QXmppUserTuneItem.cpp @@ -224,7 +224,7 @@ bool QXmppTuneItem::isItem(const QDomElement &itemElement) payload.namespaceURI() == ns_tune; }; - return QXmppPubSubItem::isItem(itemElement, isPayloadValid); + return QXmppPubSubBaseItem::isItem(itemElement, isPayloadValid); } /// \cond diff --git a/src/base/QXmppUserTuneItem.h b/src/base/QXmppUserTuneItem.h index 03bafb1e..c4b1f0a8 100644 --- a/src/base/QXmppUserTuneItem.h +++ b/src/base/QXmppUserTuneItem.h @@ -5,7 +5,7 @@ #ifndef QXMPPUSERTUNEITEM_H #define QXMPPUSERTUNEITEM_H -#include "QXmppPubSubItem.h" +#include "QXmppPubSubBaseItem.h" #include #include @@ -16,7 +16,7 @@ class QXmppTuneItemPrivate; class QUrl; -class QXMPP_EXPORT QXmppTuneItem : public QXmppPubSubItem +class QXMPP_EXPORT QXmppTuneItem : public QXmppPubSubBaseItem { public: QXmppTuneItem(); diff --git a/src/client/QXmppPubSubManager.cpp b/src/client/QXmppPubSubManager.cpp index 18ad9d7a..de7a9db0 100644 --- a/src/client/QXmppPubSubManager.cpp +++ b/src/client/QXmppPubSubManager.cpp @@ -10,7 +10,7 @@ #include "QXmppConstants_p.h" #include "QXmppPubSubAffiliation.h" #include "QXmppPubSubEventHandler.h" -#include "QXmppPubSubItem.h" +#include "QXmppPubSubBaseItem.h" #include "QXmppPubSubSubscribeOptions.h" #include "QXmppPubSubSubscription.h" #include "QXmppStanza.h" @@ -435,7 +435,7 @@ auto QXmppPubSubManager::retractItem(const QString &jid, const QString &nodeName request.setType(QXmppIq::Set); request.setQueryType(PubSubIq<>::Retract); request.setQueryNode(nodeName); - request.setItems({ QXmppPubSubItem(itemId) }); + request.setItems({ QXmppPubSubBaseItem(itemId) }); request.setTo(jid); return client()->sendGenericIq(std::move(request)); @@ -1006,10 +1006,10 @@ PubSubIq<> QXmppPubSubManager::requestItemsIq(const QString &jid, const QString request.setQueryNode(nodeName); if (!itemIds.isEmpty()) { - QVector items; + QVector items; items.reserve(itemIds.size()); for (const auto &id : itemIds) { - items << QXmppPubSubItem(id); + items << QXmppPubSubBaseItem(id); } request.setItems(items); } @@ -1038,7 +1038,7 @@ auto QXmppPubSubManager::publishItems(PubSubIqBase &&request) -> QXmppTasksendIq(std::move(request)), this, [](const PubSubIq<> &iq) -> PublishItemsResult { - const auto itemToId = [](const QXmppPubSubItem &item) { + const auto itemToId = [](const QXmppPubSubBaseItem &item) { return item.id(); }; diff --git a/src/client/QXmppPubSubManager.h b/src/client/QXmppPubSubManager.h index 73a5b4d4..154f585d 100644 --- a/src/client/QXmppPubSubManager.h +++ b/src/client/QXmppPubSubManager.h @@ -79,13 +79,13 @@ public: QXmppTask createInstantNode(const QString &jid, const QXmppPubSubNodeConfig &config); QXmppTask deleteNode(const QString &jid, const QString &nodeName); QXmppTask requestItemIds(const QString &serviceJid, const QString &nodeName); - template + template QXmppTask> requestItem(const QString &jid, const QString &nodeName, const QString &itemId); - template + template QXmppTask> requestItem(const QString &jid, const QString &nodeName, StandardItemId itemId); - template + template QXmppTask> requestItems(const QString &jid, const QString &nodeName); - template + template QXmppTask> requestItems(const QString &jid, const QString &nodeName, const QStringList &itemIds); template QXmppTask publishItem(const QString &jid, const QString &nodeName, const T &item); @@ -118,11 +118,11 @@ public: QXmppTask createOwnPepNode(const QString &nodeName) { return createNode(client()->configuration().jidBare(), nodeName); } QXmppTask createOwnPepNode(const QString &nodeName, const QXmppPubSubNodeConfig &config) { return createNode(client()->configuration().jidBare(), nodeName, config); } QXmppTask deleteOwnPepNode(const QString &nodeName) { return deleteNode(client()->configuration().jidBare(), nodeName); } - template + template QXmppTask> requestOwnPepItem(const QString &nodeName, const QString &itemId) { return requestItem(client()->configuration().jidBare(), nodeName, itemId); } - template + template QXmppTask> requestOwnPepItem(const QString &nodeName, StandardItemId itemId) { return requestItem(client()->configuration().jidBare(), nodeName, itemId); } - template + template QXmppTask> requestOwnPepItems(const QString &nodeName) { return requestItems(client()->configuration().jidBare(), nodeName); } QXmppTask requestOwnPepItemIds(const QString &nodeName) { return requestItemIds(client()->configuration().jidBare(), nodeName); } template diff --git a/src/omemo/QXmppOmemoData.cpp b/src/omemo/QXmppOmemoData.cpp index 6bc1815b..43e00c35 100644 --- a/src/omemo/QXmppOmemoData.cpp +++ b/src/omemo/QXmppOmemoData.cpp @@ -424,7 +424,7 @@ void QXmppOmemoDeviceBundleItem::setDeviceBundle(const QXmppOmemoDeviceBundle &d bool QXmppOmemoDeviceBundleItem::isItem(const QDomElement &itemElement) { - return QXmppPubSubItem::isItem(itemElement, QXmppOmemoDeviceBundle::isOmemoDeviceBundle); + return QXmppPubSubBaseItem::isItem(itemElement, QXmppOmemoDeviceBundle::isOmemoDeviceBundle); } void QXmppOmemoDeviceBundleItem::parsePayload(const QDomElement &payloadElement) @@ -449,7 +449,7 @@ void QXmppOmemoDeviceListItem::setDeviceList(const QXmppOmemoDeviceList &deviceL bool QXmppOmemoDeviceListItem::isItem(const QDomElement &itemElement) { - return QXmppPubSubItem::isItem(itemElement, QXmppOmemoDeviceList::isOmemoDeviceList); + return QXmppPubSubBaseItem::isItem(itemElement, QXmppOmemoDeviceList::isOmemoDeviceList); } void QXmppOmemoDeviceListItem::parsePayload(const QDomElement &payloadElement) diff --git a/src/omemo/QXmppOmemoItems_p.h b/src/omemo/QXmppOmemoItems_p.h index 9b816ed8..abc6a65f 100644 --- a/src/omemo/QXmppOmemoItems_p.h +++ b/src/omemo/QXmppOmemoItems_p.h @@ -7,9 +7,9 @@ #include "QXmppOmemoDeviceBundle_p.h" #include "QXmppOmemoDeviceList_p.h" -#include "QXmppPubSubItem.h" +#include "QXmppPubSubBaseItem.h" -class QXmppOmemoDeviceBundleItem : public QXmppPubSubItem +class QXmppOmemoDeviceBundleItem : public QXmppPubSubBaseItem { public: QXmppOmemoDeviceBundle deviceBundle() const; @@ -25,7 +25,7 @@ private: QXmppOmemoDeviceBundle m_deviceBundle; }; -class QXmppOmemoDeviceListItem : public QXmppPubSubItem +class QXmppOmemoDeviceListItem : public QXmppPubSubBaseItem { public: QXmppOmemoDeviceList deviceList() const; diff --git a/src/omemo/QXmppOmemoManager_p.cpp b/src/omemo/QXmppOmemoManager_p.cpp index 8da77f5f..d8830d0d 100644 --- a/src/omemo/QXmppOmemoManager_p.cpp +++ b/src/omemo/QXmppOmemoManager_p.cpp @@ -12,7 +12,7 @@ #include "QXmppOmemoEnvelope_p.h" #include "QXmppOmemoIq_p.h" #include "QXmppOmemoItems_p.h" -#include "QXmppPubSubItem.h" +#include "QXmppPubSubBaseItem.h" #include "QXmppSceEnvelope_p.h" #include "QXmppTrustManager.h" #include "QXmppUtils.h" diff --git a/tests/pubsubutil.h b/tests/pubsubutil.h index 20b02785..f8059a6c 100644 --- a/tests/pubsubutil.h +++ b/tests/pubsubutil.h @@ -5,17 +5,17 @@ #ifndef PUBSUBUTIL_H #define PUBSUBUTIL_H -#include "QXmppPubSubItem.h" +#include "QXmppPubSubBaseItem.h" #include #include #include -class TestItem : public QXmppPubSubItem +class TestItem : public QXmppPubSubBaseItem { public: TestItem(const QString &id = {}) - : QXmppPubSubItem(id) + : QXmppPubSubBaseItem(id) { } @@ -34,7 +34,7 @@ public: static bool isItem(const QDomElement &element) { isItemCalled = true; - return QXmppPubSubItem::isItem(element, [](const QDomElement &payload) { + return QXmppPubSubBaseItem::isItem(element, [](const QDomElement &payload) { return payload.tagName() == "test-payload"; }); } diff --git a/tests/qxmpppubsub/tst_qxmpppubsub.cpp b/tests/qxmpppubsub/tst_qxmpppubsub.cpp index b34f34cf..ca1d6640 100644 --- a/tests/qxmpppubsub/tst_qxmpppubsub.cpp +++ b/tests/qxmpppubsub/tst_qxmpppubsub.cpp @@ -211,7 +211,7 @@ void tst_QXmppPubSub::testItem() { const auto xml = QByteArrayLiteral(""); - QXmppPubSubItem item; + QXmppPubSubBaseItem item; parsePacket(item, xml); QCOMPARE(item.id(), QStringLiteral("abc1337")); @@ -221,11 +221,11 @@ void tst_QXmppPubSub::testItem() serializePacket(item, xml); // test serialization with constructor values - item = QXmppPubSubItem("abc1337", "lnj@qxmpp.org"); + item = QXmppPubSubBaseItem("abc1337", "lnj@qxmpp.org"); serializePacket(item, xml); // test serialization with setters - item = QXmppPubSubItem(); + item = QXmppPubSubBaseItem(); item.setId("abc1337"); item.setPublisher("lnj@qxmpp.org"); serializePacket(item, xml); @@ -261,7 +261,7 @@ void tst_QXmppPubSub::testIsItem() QFETCH(QByteArray, xml); QFETCH(bool, valid); - QCOMPARE(QXmppPubSubItem::isItem(xmlToDom(xml)), valid); + QCOMPARE(QXmppPubSubBaseItem::isItem(xmlToDom(xml)), valid); } void tst_QXmppPubSub::testTestItem() diff --git a/tests/qxmpppubsubevent/tst_qxmpppubsubevent.cpp b/tests/qxmpppubsubevent/tst_qxmpppubsubevent.cpp index a3b457e9..8f37d943 100644 --- a/tests/qxmpppubsubevent/tst_qxmpppubsubevent.cpp +++ b/tests/qxmpppubsubevent/tst_qxmpppubsubevent.cpp @@ -4,7 +4,7 @@ #include "QXmppDataForm.h" #include "QXmppPubSubEvent.h" -#include "QXmppPubSubItem.h" +#include "QXmppPubSubBaseItem.h" #include "pubsubutil.h" #include "util.h" @@ -31,7 +31,7 @@ void tst_QXmppPubSubEvent::testBasic_data() QTest::addColumn("retractIds"); QTest::addColumn("redirectUri"); QTest::addColumn>("subscription"); - QTest::addColumn>("items"); + QTest::addColumn>("items"); QTest::addColumn>("configurationForm"); #define ROW(name, xml, type, node, retractIds, redirectUri, subscription, items, configForm) \ @@ -57,7 +57,7 @@ void tst_QXmppPubSubEvent::testBasic_data() QStringList(), QString(), std::nullopt, - QVector() << QXmppPubSubItem("ae890ac52d0df67ed7cfdf51b644e901"), + QVector() << QXmppPubSubBaseItem("ae890ac52d0df67ed7cfdf51b644e901"), std::nullopt); ROW("retract", @@ -75,7 +75,7 @@ void tst_QXmppPubSubEvent::testBasic_data() << "34324897shdfjk948577342343243243", QString(), std::nullopt, - QVector(), + QVector(), std::nullopt); ROW("configuration-notify", @@ -89,7 +89,7 @@ void tst_QXmppPubSubEvent::testBasic_data() QStringList(), QString(), std::nullopt, - QVector(), + QVector(), std::nullopt); ROW("configuration", @@ -112,7 +112,7 @@ void tst_QXmppPubSubEvent::testBasic_data() QStringList(), QString(), std::nullopt, - QVector(), + QVector(), QXmppDataForm(QXmppDataForm::Result, QList() << QXmppDataForm::Field(QXmppDataForm::Field::HiddenField, @@ -133,7 +133,7 @@ void tst_QXmppPubSubEvent::testBasic_data() QStringList(), QString(), std::nullopt, - QVector(), + QVector(), std::nullopt); ROW("subscription-subscribed", @@ -147,7 +147,7 @@ void tst_QXmppPubSubEvent::testBasic_data() QStringList(), QString(), QXmppPubSubSubscription("horatio@denmark.lit", "princely_musings", {}, QXmppPubSubSubscription::Subscribed), - QVector(), + QVector(), std::nullopt); ROW("subscription-none", @@ -161,7 +161,7 @@ void tst_QXmppPubSubEvent::testBasic_data() QStringList(), QString(), QXmppPubSubSubscription("polonius@denmark.lit", "princely_musings", {}, QXmppPubSubSubscription::None), - QVector(), + QVector(), std::nullopt); ROW("subscription-expiry", @@ -180,7 +180,7 @@ void tst_QXmppPubSubEvent::testBasic_data() QXmppPubSubSubscription::Subscribed, QXmppPubSubSubscription::Unavailable, QDateTime({ 2006, 02, 28 }, { 23, 59, 59 }, Qt::UTC)), - QVector(), + QVector(), std::nullopt); #undef ROW @@ -194,7 +194,7 @@ void tst_QXmppPubSubEvent::testBasic() QFETCH(QStringList, retractIds); QFETCH(QString, redirectUri); QFETCH(std::optional, subscription); - QFETCH(QVector, items); + QFETCH(QVector, items); QFETCH(std::optional, configurationForm); // parse diff --git a/tests/qxmpppubsubiq/tst_qxmpppubsubiq.cpp b/tests/qxmpppubsubiq/tst_qxmpppubsubiq.cpp index 2d59124f..bb6c0768 100644 --- a/tests/qxmpppubsubiq/tst_qxmpppubsubiq.cpp +++ b/tests/qxmpppubsubiq/tst_qxmpppubsubiq.cpp @@ -4,7 +4,7 @@ // SPDX-License-Identifier: LGPL-2.1-or-later #include "QXmppPubSubIq_p.h" -#include "QXmppPubSubItem.h" +#include "QXmppPubSubBaseItem.h" #include "QXmppPubSubSubscription.h" #include "QXmppResultSet.h" @@ -193,7 +193,7 @@ void tst_QXmppPubSubIq::testPublish() serializePacket(iq, xml); // serialize using setters - QXmppPubSubItem item(QStringLiteral("current")); + QXmppPubSubBaseItem item(QStringLiteral("current")); iq = PubSubIq(); iq.setId(QLatin1String("items1")); @@ -245,7 +245,7 @@ void tst_QXmppPubSubIq::testRetractItem() iq.setQueryJid({}); iq.setQueryNode(QLatin1String("princely_musings")); - QXmppPubSubItem item; + QXmppPubSubBaseItem item; item.setId(QStringLiteral("ae890ac52d0df67ed7cfdf51b644e901")); iq.setItems({ item }); diff --git a/tests/qxmpppubsubmanager/tst_qxmpppubsubmanager.cpp b/tests/qxmpppubsubmanager/tst_qxmpppubsubmanager.cpp index eef1912e..6589b92e 100644 --- a/tests/qxmpppubsubmanager/tst_qxmpppubsubmanager.cpp +++ b/tests/qxmpppubsubmanager/tst_qxmpppubsubmanager.cpp @@ -8,7 +8,7 @@ #include "QXmppMessage.h" #include "QXmppPubSubAffiliation.h" #include "QXmppPubSubEventHandler.h" -#include "QXmppPubSubItem.h" +#include "QXmppPubSubBaseItem.h" #include "QXmppPubSubManager.h" #include "QXmppPubSubPublishOptions.h" #include "QXmppPubSubSubscribeOptions.h" @@ -421,7 +421,7 @@ void tst_QXmppPubSubManager::testPublishItems_data() QTest::addColumn("isPep"); QTest::addColumn("jid"); QTest::addColumn("node"); - QTest::addColumn>("items"); + QTest::addColumn>("items"); QTest::addColumn("publishOptions"); QTest::addColumn("returnIds"); @@ -434,14 +434,14 @@ void tst_QXmppPubSubManager::testPublishItems_data() item2.setArtist("Rick Astley"); item2.setTitle("Never gonna give you up"); - QVector items1 { item1 }; - QVector items2 { item1, item2 }; + QVector items1 { item1 }; + QVector items2 { item1, item2 }; QXmppPubSubPublishOptions publishOptions; publishOptions.setAccessModel(QXmppPubSubPublishOptions::Presence); auto addRow = [&](const char *name, bool isPep, QString &&jid, - QString &&node, const QVector &items) { + QString &&node, const QVector &items) { QTest::addRow("%s", name) << isPep << jid << node << items << OptionsOpt() << false; QTest::addRow("%s%s", name, "ReturnIds") << isPep << jid << node << items << OptionsOpt() << true; QTest::addRow("%s%s", name, "WithOptions") << isPep << jid << node << items << std::make_optional(publishOptions) << false; @@ -459,7 +459,7 @@ void tst_QXmppPubSubManager::testPublishItems() QFETCH(bool, isPep); QFETCH(QString, jid); QFETCH(QString, node); - QFETCH(QVector, items); + QFETCH(QVector, items); QFETCH(std::optional, publishOptions); QFETCH(bool, returnIds); @@ -736,7 +736,7 @@ void tst_QXmppPubSubManager::testRequestCurrentItem() "" "")); - const auto item = expectFutureVariant(future); + const auto item = expectFutureVariant(future); QCOMPARE(item.id(), QStringLiteral("current")); } @@ -892,7 +892,7 @@ void tst_QXmppPubSubManager::testRequestCurrentPepItem() "" "")); - const auto item = expectFutureVariant(future); + const auto item = expectFutureVariant(future); QCOMPARE(item.id(), QStringLiteral("current")); } @@ -915,7 +915,7 @@ void tst_QXmppPubSubManager::testRequestPepItem() "" "")); - const auto item = expectFutureVariant(future); + const auto item = expectFutureVariant(future); QCOMPARE(item.id(), QStringLiteral("ae890ac52d0df67ed7cfdf51b644e901")); } @@ -937,7 +937,7 @@ void tst_QXmppPubSubManager::testRequestPepItems() "" "")); - const auto items = expectFutureVariant>(future); + const auto items = expectFutureVariant>(future); QCOMPARE(items.items.first().id(), QStringLiteral("368866411b877c30064a5f62b917cffe")); QCOMPARE(items.items.last().id(), QStringLiteral("3300659945416e274474e469a1f0154c")); } -- cgit v1.2.3 From 7c7ce1ac0b06455cf08186543452c65410fe79a9 Mon Sep 17 00:00:00 2001 From: Linus Jahn Date: Thu, 9 Mar 2023 20:36:08 +0100 Subject: Readd old PubSubIq and PubSubItem for compatibility There is at least one package that actually uses this API and this way QXmpp 1.5 can be easily adopted. --- src/CMakeLists.txt | 4 + src/base/compat/QXmppPubSubIq.cpp | 210 ++++++++++++++++++++++++++++++++++++ src/base/compat/QXmppPubSubIq.h | 66 ++++++++++++ src/base/compat/QXmppPubSubItem.cpp | 76 +++++++++++++ src/base/compat/QXmppPubSubItem.h | 42 ++++++++ 5 files changed, 398 insertions(+) create mode 100644 src/base/compat/QXmppPubSubIq.cpp create mode 100644 src/base/compat/QXmppPubSubIq.h create mode 100644 src/base/compat/QXmppPubSubItem.cpp create mode 100644 src/base/compat/QXmppPubSubItem.h (limited to 'src') diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 0f533a01..54120b8a 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -81,6 +81,8 @@ set(INSTALL_HEADER_FILES base/QXmppUtils.h base/QXmppVCardIq.h base/QXmppVersionIq.h + base/compat/QXmppPubSubIq.h + base/compat/QXmppPubSubItem.h # Client client/QXmppArchiveManager.h @@ -212,6 +214,8 @@ set(SOURCE_FILES base/QXmppUtils.cpp base/QXmppVCardIq.cpp base/QXmppVersionIq.cpp + base/compat/QXmppPubSubIq.cpp + base/compat/QXmppPubSubItem.cpp # Client client/QXmppArchiveManager.cpp diff --git a/src/base/compat/QXmppPubSubIq.cpp b/src/base/compat/QXmppPubSubIq.cpp new file mode 100644 index 00000000..9df2fdf1 --- /dev/null +++ b/src/base/compat/QXmppPubSubIq.cpp @@ -0,0 +1,210 @@ +// SPDX-FileCopyrightText: 2010 Jeremy Lainé +// +// SPDX-License-Identifier: LGPL-2.1-or-later + +#include "QXmppPubSubIq.h" + +#include "QXmppConstants_p.h" +#include "QXmppUtils.h" + +#include +#include + +/// \cond +QT_WARNING_PUSH +QT_WARNING_DISABLE_DEPRECATED + +static const QStringList PUBSUB_QUERIES = { + QStringLiteral("affiliations"), + QStringLiteral("default"), + QStringLiteral("items"), + QStringLiteral("publish"), + QStringLiteral("retract"), + QStringLiteral("subscribe"), + QStringLiteral("subscription"), + QStringLiteral("subscriptions"), + QStringLiteral("unsubscribe"), +}; + +class QXmppPubSubIqPrivate : public QSharedData +{ +public: + QXmppPubSubIqPrivate(); + + QXmppPubSubIq::QueryType queryType; + QString queryJid; + QString queryNode; + QList items; + QString subscriptionId; + QString subscriptionType; +}; + +QXmppPubSubIqPrivate::QXmppPubSubIqPrivate() + : queryType(QXmppPubSubIq::ItemsQuery) +{ +} + +QXmppPubSubIq::QXmppPubSubIq() + : d(new QXmppPubSubIqPrivate) +{ +} + +QXmppPubSubIq::QXmppPubSubIq(const QXmppPubSubIq &iq) = default; + +QXmppPubSubIq::~QXmppPubSubIq() = default; + +QXmppPubSubIq &QXmppPubSubIq::operator=(const QXmppPubSubIq &iq) = default; + +/// Returns the PubSub queryType for this IQ. + +QXmppPubSubIq::QueryType QXmppPubSubIq::queryType() const +{ + return d->queryType; +} + +/// Sets the PubSub queryType for this IQ. +/// +/// \param queryType + +void QXmppPubSubIq::setQueryType(QXmppPubSubIq::QueryType queryType) +{ + d->queryType = queryType; +} + +/// Returns the JID being queried. + +QString QXmppPubSubIq::queryJid() const +{ + return d->queryJid; +} + +/// Sets the JID being queried. +/// +/// \param queryJid + +void QXmppPubSubIq::setQueryJid(const QString &queryJid) +{ + d->queryJid = queryJid; +} + +/// Returns the node being queried. + +QString QXmppPubSubIq::queryNode() const +{ + return d->queryNode; +} + +/// Sets the node being queried. +/// +/// \param queryNode + +void QXmppPubSubIq::setQueryNode(const QString &queryNode) +{ + d->queryNode = queryNode; +} + +/// Returns the subscription ID. + +QString QXmppPubSubIq::subscriptionId() const +{ + return d->subscriptionId; +} + +/// Sets the subscription ID. +/// +/// \param subscriptionId + +void QXmppPubSubIq::setSubscriptionId(const QString &subscriptionId) +{ + d->subscriptionId = subscriptionId; +} + +/// Returns the IQ's items. + +QList QXmppPubSubIq::items() const +{ + return d->items; +} + +/// Sets the IQ's items. +/// +/// \param items + +void QXmppPubSubIq::setItems(const QList &items) +{ + d->items = items; +} + +bool QXmppPubSubIq::isPubSubIq(const QDomElement &element) +{ + return element.firstChildElement(QStringLiteral("pubsub")).namespaceURI() == ns_pubsub; +} + +void QXmppPubSubIq::parseElementFromChild(const QDomElement &element) +{ + const QDomElement pubSubElement = element.firstChildElement(QStringLiteral("pubsub")); + + const QDomElement queryElement = pubSubElement.firstChildElement(); + + // determine query type + const QString tagName = queryElement.tagName(); + int queryType = PUBSUB_QUERIES.indexOf(queryElement.tagName()); + if (queryType > -1) + d->queryType = QueryType(queryType); + + d->queryJid = queryElement.attribute(QStringLiteral("jid")); + d->queryNode = queryElement.attribute(QStringLiteral("node")); + + // parse contents + QDomElement childElement; + switch (d->queryType) { + case QXmppPubSubIq::ItemsQuery: + case QXmppPubSubIq::PublishQuery: + case QXmppPubSubIq::RetractQuery: + childElement = queryElement.firstChildElement(QStringLiteral("item")); + while (!childElement.isNull()) { + QXmppPubSubItem item; + item.parse(childElement); + d->items << item; + childElement = childElement.nextSiblingElement(QStringLiteral("item")); + } + break; + case QXmppPubSubIq::SubscriptionQuery: + d->subscriptionId = queryElement.attribute(QStringLiteral("subid")); + d->subscriptionType = queryElement.attribute(QStringLiteral("subscription")); + break; + default: + break; + } +} + +void QXmppPubSubIq::toXmlElementFromChild(QXmlStreamWriter *writer) const +{ + writer->writeStartElement(QStringLiteral("pubsub")); + writer->writeDefaultNamespace(ns_pubsub); + + // write query type + writer->writeStartElement(PUBSUB_QUERIES.at(d->queryType)); + helperToXmlAddAttribute(writer, QStringLiteral("jid"), d->queryJid); + helperToXmlAddAttribute(writer, QStringLiteral("node"), d->queryNode); + + // write contents + switch (d->queryType) { + case QXmppPubSubIq::ItemsQuery: + case QXmppPubSubIq::PublishQuery: + case QXmppPubSubIq::RetractQuery: + for (const auto &item : d->items) + item.toXml(writer); + break; + case QXmppPubSubIq::SubscriptionQuery: + helperToXmlAddAttribute(writer, QStringLiteral("subid"), d->subscriptionId); + helperToXmlAddAttribute(writer, QStringLiteral("subscription"), d->subscriptionType); + break; + default: + break; + } + writer->writeEndElement(); + writer->writeEndElement(); +} +QT_WARNING_POP +/// \endcond diff --git a/src/base/compat/QXmppPubSubIq.h b/src/base/compat/QXmppPubSubIq.h new file mode 100644 index 00000000..057efa98 --- /dev/null +++ b/src/base/compat/QXmppPubSubIq.h @@ -0,0 +1,66 @@ +// SPDX-FileCopyrightText: 2010 Jeremy Lainé +// +// SPDX-License-Identifier: LGPL-2.1-or-later + +#ifndef QXMPPPUBSUBIQ_H +#define QXMPPPUBSUBIQ_H + +#include "QXmppIq.h" + +#include + +#if QXMPP_DEPRECATED_SINCE(1, 2) +#include "QXmppPubSubItem.h" +#endif + +class QXmppPubSubIqPrivate; + +#if QXMPP_DEPRECATED_SINCE(1, 5) +class QXMPP_EXPORT QXmppPubSubIq : public QXmppIq +{ +public: + enum [[deprecated]] QueryType { + AffiliationsQuery, + DefaultQuery, + ItemsQuery, + PublishQuery, + RetractQuery, + SubscribeQuery, + SubscriptionQuery, + SubscriptionsQuery, + UnsubscribeQuery + }; + + [[deprecated]] QXmppPubSubIq(); + QXmppPubSubIq(const QXmppPubSubIq &iq); + ~QXmppPubSubIq(); + + QXmppPubSubIq &operator=(const QXmppPubSubIq &iq); + + [[deprecated]] QXmppPubSubIq::QueryType queryType() const; + [[deprecated]] void setQueryType(QXmppPubSubIq::QueryType queryType); + + [[deprecated]] QString queryJid() const; + [[deprecated]] void setQueryJid(const QString &jid); + + [[deprecated]] QString queryNode() const; + [[deprecated]] void setQueryNode(const QString &node); + + [[deprecated]] QList items() const; + [[deprecated]] void setItems(const QList &items); + + [[deprecated]] QString subscriptionId() const; + [[deprecated]] void setSubscriptionId(const QString &id); + + [[deprecated]] static bool isPubSubIq(const QDomElement &element); + +protected: + void parseElementFromChild(const QDomElement &) override; + void toXmlElementFromChild(QXmlStreamWriter *writer) const override; + +private: + QSharedDataPointer d; +}; +#endif + +#endif // QXMPPPUBSUBIQ_H diff --git a/src/base/compat/QXmppPubSubItem.cpp b/src/base/compat/QXmppPubSubItem.cpp new file mode 100644 index 00000000..cfd2724e --- /dev/null +++ b/src/base/compat/QXmppPubSubItem.cpp @@ -0,0 +1,76 @@ +// SPDX-FileCopyrightText: 2010 Jeremy Lainé +// +// SPDX-License-Identifier: LGPL-2.1-or-later + +#include "QXmppPubSubItem.h" + +#include "QXmppElement.h" +#include "QXmppUtils.h" + +#include + +/// \cond +class QXmppPubSubItemPrivate : public QSharedData +{ +public: + QString id; + QXmppElement contents; +}; + +QXmppPubSubItem::QXmppPubSubItem() + : d(new QXmppPubSubItemPrivate) +{ +} + +QXmppPubSubItem::QXmppPubSubItem(const QXmppPubSubItem &iq) = default; + +QXmppPubSubItem::~QXmppPubSubItem() = default; + +QXmppPubSubItem &QXmppPubSubItem::operator=(const QXmppPubSubItem &iq) = default; + +/// Returns the ID of the PubSub item. + +QString QXmppPubSubItem::id() const +{ + return d->id; +} + +/// Sets the ID of the PubSub item. +/// +/// \param id + +void QXmppPubSubItem::setId(const QString &id) +{ + d->id = id; +} + +/// Returns the contents of the PubSub item. + +QXmppElement QXmppPubSubItem::contents() const +{ + return d->contents; +} + +/// Sets the contents of the PubSub item. +/// +/// \param contents + +void QXmppPubSubItem::setContents(const QXmppElement &contents) +{ + d->contents = contents; +} + +void QXmppPubSubItem::parse(const QDomElement &element) +{ + d->id = element.attribute(QStringLiteral("id")); + d->contents = QXmppElement(element.firstChildElement()); +} + +void QXmppPubSubItem::toXml(QXmlStreamWriter *writer) const +{ + writer->writeStartElement(QStringLiteral("item")); + helperToXmlAddAttribute(writer, QStringLiteral("id"), d->id); + d->contents.toXml(writer); + writer->writeEndElement(); +} +/// \endcond diff --git a/src/base/compat/QXmppPubSubItem.h b/src/base/compat/QXmppPubSubItem.h new file mode 100644 index 00000000..1d8dc4d3 --- /dev/null +++ b/src/base/compat/QXmppPubSubItem.h @@ -0,0 +1,42 @@ +// SPDX-FileCopyrightText: 2010 Jeremy Lainé +// +// SPDX-License-Identifier: LGPL-2.1-or-later + +#ifndef QXMPPPUBSUBITEM_H +#define QXMPPPUBSUBITEM_H + +#include "QXmppGlobal.h" + +#include + +class QDomElement; +class QXmlStreamWriter; + +class QXmppElement; +class QXmppPubSubItemPrivate; + +#if QXMPP_DEPRECATED_SINCE(1, 5) +class QXMPP_EXPORT QXmppPubSubItem +{ +public: + [[deprecated]] QXmppPubSubItem(); + QXmppPubSubItem(const QXmppPubSubItem &iq); + ~QXmppPubSubItem(); + + QXmppPubSubItem &operator=(const QXmppPubSubItem &iq); + + [[deprecated]] QString id() const; + [[deprecated]] void setId(const QString &id); + + [[deprecated]] QXmppElement contents() const; + [[deprecated]] void setContents(const QXmppElement &contents); + + [[deprecated]] void parse(const QDomElement &element); + [[deprecated]] void toXml(QXmlStreamWriter *writer) const; + +private: + QSharedDataPointer d; +}; +#endif + +#endif // QXMPPPUBSUBITEM_H -- cgit v1.2.3 From 70a8585a38797d24537b8109354bb83cd9262176 Mon Sep 17 00:00:00 2001 From: Linus Jahn Date: Thu, 9 Mar 2023 21:07:05 +0100 Subject: PubSubIq_p: Rename Private class to avoid conflicts --- src/base/QXmppPubSubIq.cpp | 8 ++++++-- src/base/QXmppPubSubIq_p.h | 5 +++-- 2 files changed, 9 insertions(+), 4 deletions(-) (limited to 'src') diff --git a/src/base/QXmppPubSubIq.cpp b/src/base/QXmppPubSubIq.cpp index d45df2d3..27da0e4b 100644 --- a/src/base/QXmppPubSubIq.cpp +++ b/src/base/QXmppPubSubIq.cpp @@ -81,7 +81,9 @@ static const QStringList PUBSUB_QUERIES = { QStringLiteral("unsubscribe"), }; -class QXmppPubSubIqPrivate : public QSharedData +namespace QXmpp::Private { + +class PubSubIqPrivate : public QSharedData { public: PubSubIqBase::QueryType queryType = PubSubIqBase::Items; @@ -95,11 +97,13 @@ public: std::optional itemsContinuation; }; +} + /// /// Constructs a PubSub IQ. /// PubSubIqBase::PubSubIqBase() - : d(new QXmppPubSubIqPrivate) + : d(new PubSubIqPrivate) { } diff --git a/src/base/QXmppPubSubIq_p.h b/src/base/QXmppPubSubIq_p.h index 6868eb84..c8828579 100644 --- a/src/base/QXmppPubSubIq_p.h +++ b/src/base/QXmppPubSubIq_p.h @@ -14,7 +14,6 @@ #include class QXmppDataForm; -class QXmppPubSubIqPrivate; class QXmppPubSubBaseItem; class QXmppPubSubSubscription; class QXmppPubSubAffiliation; @@ -22,6 +21,8 @@ class QXmppResultSetReply; namespace QXmpp::Private { +class PubSubIqPrivate; + class QXMPP_EXPORT PubSubIqBase : public QXmppIq { public: @@ -100,7 +101,7 @@ private: static std::optional queryTypeFromDomElement(const QDomElement &element); static bool queryTypeIsOwnerIq(QueryType type); - QSharedDataPointer d; + QSharedDataPointer d; }; template -- cgit v1.2.3 From 13ecdcc063ad4b4c9cae12e6bc8d3d3ee2b5cf42 Mon Sep 17 00:00:00 2001 From: Blue Date: Fri, 10 Mar 2023 15:26:21 +0300 Subject: OmemoManager: Fix buildMissingSessions never finishes (#552) --- src/omemo/QXmppOmemoManager.cpp | 3 +++ 1 file changed, 3 insertions(+) (limited to 'src') diff --git a/src/omemo/QXmppOmemoManager.cpp b/src/omemo/QXmppOmemoManager.cpp index 7ad511e0..0aab152d 100644 --- a/src/omemo/QXmppOmemoManager.cpp +++ b/src/omemo/QXmppOmemoManager.cpp @@ -884,13 +884,16 @@ QXmppTask Manager::buildMissingSessions(const QList &jids) auto future = d->buildSessionWithDeviceBundle(jid, deviceId, device); future.then(this, [=](auto) mutable { if (++(*processedDevicesCount) == devicesCount) { + interface.finish(); } }); } else if (++(*processedDevicesCount) == devicesCount) { + interface.finish(); } } } } else { + interface.finish(); } return interface.task(); -- cgit v1.2.3 From 501686a49d9797b25c998060d97e1fb3f82079f0 Mon Sep 17 00:00:00 2001 From: Melvin Keskin Date: Fri, 10 Mar 2023 17:38:38 +0100 Subject: OmemoManagerPrivate: Fix SCE affix element processing as specified --- src/omemo/QXmppOmemoManager_p.cpp | 62 ++++++++++++++++----------------------- 1 file changed, 26 insertions(+), 36 deletions(-) (limited to 'src') diff --git a/src/omemo/QXmppOmemoManager_p.cpp b/src/omemo/QXmppOmemoManager_p.cpp index d8830d0d..303c19dc 100644 --- a/src/omemo/QXmppOmemoManager_p.cpp +++ b/src/omemo/QXmppOmemoManager_p.cpp @@ -1553,48 +1553,38 @@ QXmppTask> ManagerPrivate::decryptStanza(T stanz QXmppSceEnvelopeReader sceEnvelopeReader(document.documentElement()); if (sceEnvelopeReader.from() != senderJid) { - warning("Sender '" % senderJid % "' of stanza does not match SCE 'from' affix element '" % sceEnvelopeReader.from() % "'"); - interface.finish(std::nullopt); - } else { - const auto recipientJid = QXmppUtils::jidToBareJid(stanza.to()); - auto isSceAffixElementValid = true; + q->info("Sender '" % senderJid % "' of stanza does not match SCE 'from' affix element '" % sceEnvelopeReader.from() % "'"); + } - if (isMessageStanza) { - if (const auto &message = dynamic_cast(stanza); message.type() == QXmppMessage::GroupChat && (sceEnvelopeReader.to() != recipientJid)) { - warning("Recipient of group chat message does not match SCE affix element ''"); - isSceAffixElementValid = false; - } - } else { - if (sceEnvelopeReader.to() != recipientJid) { - warning("Recipient of IQ does not match SCE affix element ''"); - isSceAffixElementValid = false; - } + if (const auto recipientJid = QXmppUtils::jidToBareJid(stanza.to()); isMessageStanza) { + if (const auto &message = dynamic_cast(stanza); message.type() == QXmppMessage::GroupChat && (sceEnvelopeReader.to() != recipientJid)) { + warning("Recipient of group chat message does not match SCE affix element ''"); + interface.finish(std::nullopt); + return; } + } else if (sceEnvelopeReader.to() != recipientJid) { + q->info("Recipient of IQ does not match SCE affix element ''"); + } - if (!isSceAffixElementValid) { - interface.finish(std::nullopt); - } else { - auto &device = devices[senderJid][senderDeviceId]; - device.unrespondedSentStanzasCount = 0; + auto &device = devices[senderJid][senderDeviceId]; + device.unrespondedSentStanzasCount = 0; - // Send a heartbeat message to the sender if too many stanzas were - // received responding to none. - if (device.unrespondedReceivedStanzasCount == UNRESPONDED_STANZAS_UNTIL_HEARTBEAT_MESSAGE_IS_SENT) { - sendEmptyMessage(senderJid, senderDeviceId); - device.unrespondedReceivedStanzasCount = 0; - } else { - ++device.unrespondedReceivedStanzasCount; - } + // Send a heartbeat message to the sender if too many stanzas were + // received responding to none. + if (device.unrespondedReceivedStanzasCount == UNRESPONDED_STANZAS_UNTIL_HEARTBEAT_MESSAGE_IS_SENT) { + sendEmptyMessage(senderJid, senderDeviceId); + device.unrespondedReceivedStanzasCount = 0; + } else { + ++device.unrespondedReceivedStanzasCount; + } - QXmppE2eeMetadata e2eeMetadata; - e2eeMetadata.setSceTimestamp(sceEnvelopeReader.timestamp()); - e2eeMetadata.setEncryption(QXmpp::Omemo2); - const auto &senderDevice = devices.value(senderJid).value(senderDeviceId); - e2eeMetadata.setSenderKey(senderDevice.keyId); + QXmppE2eeMetadata e2eeMetadata; + e2eeMetadata.setSceTimestamp(sceEnvelopeReader.timestamp()); + e2eeMetadata.setEncryption(QXmpp::Omemo2); + const auto &senderDevice = devices.value(senderJid).value(senderDeviceId); + e2eeMetadata.setSenderKey(senderDevice.keyId); - interface.finish(DecryptionResult { sceEnvelopeReader.contentElement(), e2eeMetadata }); - } - } + interface.finish(DecryptionResult { sceEnvelopeReader.contentElement(), e2eeMetadata }); } }); -- cgit v1.2.3 From 7513cb6ccfe6b0fdd5e8c4b59cef77f774976c29 Mon Sep 17 00:00:00 2001 From: Melvin Keskin Date: Fri, 10 Mar 2023 17:40:35 +0100 Subject: OmemoManagerPrivate: Fix sizes of HKDF output and HMAC --- src/omemo/QXmppOmemoManager_p.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'src') diff --git a/src/omemo/QXmppOmemoManager_p.h b/src/omemo/QXmppOmemoManager_p.h index 01a372a7..96f10f94 100644 --- a/src/omemo/QXmppOmemoManager_p.h +++ b/src/omemo/QXmppOmemoManager_p.h @@ -91,14 +91,14 @@ constexpr QCA::Cipher::Padding PAYLOAD_CIPHER_PADDING = QCA::Cipher::PKCS7; constexpr auto HKDF_INFO = "OMEMO Payload"; constexpr int HKDF_KEY_SIZE = 32; constexpr int HKDF_SALT_SIZE = 32; -constexpr int HKDF_OUTPUT_SIZE = 60; +constexpr int HKDF_OUTPUT_SIZE = 80; extern const QString PAYLOAD_MESSAGE_AUTHENTICATION_CODE_TYPE; constexpr uint32_t PAYLOAD_MESSAGE_AUTHENTICATION_CODE_SIZE = 16; constexpr int PAYLOAD_KEY_SIZE = 32; constexpr uint32_t PAYLOAD_INITIALIZATION_VECTOR_SIZE = 16; -constexpr uint32_t PAYLOAD_AUTHENTICATION_KEY_SIZE = 16; +constexpr uint32_t PAYLOAD_AUTHENTICATION_KEY_SIZE = 32; // boundaries for the count of characters in SCE's element constexpr uint32_t SCE_RPAD_SIZE_MIN = 0; -- cgit v1.2.3