From 447f4b27ef6c3f7120fe9f3a42290baa317471ca Mon Sep 17 00:00:00 2001 From: Linus Jahn Date: Sun, 5 Dec 2021 16:20:44 +0100 Subject: AtmManager: Use QFutureInterface directly without shared_ptr --- src/client/QXmppAtmManager.cpp | 89 ++++++++++++++++++++++-------------------- 1 file changed, 46 insertions(+), 43 deletions(-) (limited to 'src/client/QXmppAtmManager.cpp') diff --git a/src/client/QXmppAtmManager.cpp b/src/client/QXmppAtmManager.cpp index c4fe2cad..fb20f922 100644 --- a/src/client/QXmppAtmManager.cpp +++ b/src/client/QXmppAtmManager.cpp @@ -77,10 +77,10 @@ QXmppAtmManager::QXmppAtmManager(QXmppAtmTrustStorage *trustStorage) /// QFuture QXmppAtmManager::makeTrustDecisions(const QString &encryption, const QString &keyOwnerJid, const QList &keyIdsForAuthentication, const QList &keyIdsForDistrusting) { - auto interface = std::make_shared>(QFutureInterfaceBase::Started); + QFutureInterface interface(QFutureInterfaceBase::Started); auto future = m_trustStorage->keys(encryption, QXmppTrustStorage::Authenticated | QXmppTrustStorage::ManuallyDistrusted); - await(future, this, [=](const QHash> &&keys) { + await(future, this, [=](const QHash> &&keys) mutable { const auto authenticatedKeys = keys.value(QXmppTrustStorage::Authenticated); const auto manuallyDistrustedKeys = keys.value(QXmppTrustStorage::ManuallyDistrusted); const auto ownJid = client()->configuration().jidBare(); @@ -108,7 +108,7 @@ QFuture QXmppAtmManager::makeTrustDecisions(const QString &encryption, con if (modifiedAuthenticatedKeys.isEmpty() && modifiedManuallyDistrustedKeys.isEmpty()) { // Skip further processing if there are no changes. - interface->reportFinished(); + interface.reportFinished(); } else { keyOwner.setTrustedKeys(modifiedAuthenticatedKeys); keyOwner.setDistrustedKeys(modifiedManuallyDistrustedKeys); @@ -168,7 +168,7 @@ QFuture QXmppAtmManager::makeTrustDecisions(const QString &encryption, con } auto future = makeTrustDecisions(encryption, keysBeingAuthenticated, keysBeingDistrusted); - await(future, this, [=]() { + await(future, this, [=]() mutable { // Send a trust message for all authenticated or distrusted // keys to the own endpoints whose keys have been // authenticated. @@ -210,7 +210,7 @@ QFuture QXmppAtmManager::makeTrustDecisions(const QString &encryption, con } } - interface->reportFinished(); + interface.reportFinished(); }); } else { // Send a trust message for the keys of the contact's endpoints @@ -221,7 +221,7 @@ QFuture QXmppAtmManager::makeTrustDecisions(const QString &encryption, con } auto future = makeTrustDecisions(encryption, keysBeingAuthenticated, keysBeingDistrusted); - await(future, this, [=]() { + await(future, this, [=]() mutable { // Send a trust message for own authenticated or distrusted // keys to the contact's endpoints whose keys have been // authenticated. @@ -231,13 +231,13 @@ QFuture QXmppAtmManager::makeTrustDecisions(const QString &encryption, con sendTrustMessage(encryption, { ownKeyOwner }, keyOwnerJid); } - interface->reportFinished(); + interface.reportFinished(); }); } } }); - return interface->future(); + return interface.future(); } /// \cond @@ -269,17 +269,17 @@ void QXmppAtmManager::handleMessageReceived(const QXmppMessage &message) /// QFuture QXmppAtmManager::makeTrustDecisions(const QString &encryption, const QMultiHash &keyIdsForAuthentication, const QMultiHash &keyIdsForDistrusting) { - auto interface = std::make_shared>(QFutureInterfaceBase::Started); + QFutureInterface interface(QFutureInterfaceBase::Started); auto future = authenticate(encryption, keyIdsForAuthentication); - await(future, this, [=]() { + await(future, this, [=]() mutable { auto future = distrust(encryption, keyIdsForDistrusting); - await(future, this, [=]() { - interface->reportFinished(); + await(future, this, [=]() mutable { + interface.reportFinished(); }); }); - return interface->future(); + return interface.future(); } /// @@ -290,15 +290,18 @@ QFuture QXmppAtmManager::makeTrustDecisions(const QString &encryption, con /// QFuture QXmppAtmManager::handleMessage(const QXmppMessage &message) { - auto interface = std::make_shared>(QFutureInterfaceBase::Started); + QFutureInterface interface(QFutureInterfaceBase::Started); - if (const auto trustMessageElement = message.trustMessageElement(); trustMessageElement && trustMessageElement->usage() == ns_atm && message.from() != client()->configuration().jid()) { + if (const auto trustMessageElement = message.trustMessageElement(); + trustMessageElement && + trustMessageElement->usage() == ns_atm && + message.from() != client()->configuration().jid()) { const auto senderJid = QXmppUtils::jidToBareJid(message.from()); const auto senderKey = message.senderKey(); const auto encryption = trustMessageElement->encryption(); auto future = m_trustStorage->trustLevel(encryption, senderKey); - await(future, this, [=](const auto &&senderKeyTrustLevel) { + await(future, this, [=](const auto &&senderKeyTrustLevel) mutable { const auto isSenderKeyAuthenticated = senderKeyTrustLevel == QXmppTrustStorage::Authenticated; // key owner JIDs mapped to key IDs @@ -344,10 +347,10 @@ QFuture QXmppAtmManager::handleMessage(const QXmppMessage &message) } auto future = m_trustStorage->addKeysForPostponedTrustDecisions(encryption, senderKey, keyOwnersForPostponedTrustDecisions); - await(future, this, [=]() { + await(future, this, [=]() mutable { auto future = makeTrustDecisions(encryption, keysBeingAuthenticated, keysBeingDistrusted); - await(future, this, [=]() { - interface->reportFinished(); + await(future, this, [=]() mutable { + interface.reportFinished(); }); }); }); @@ -356,10 +359,10 @@ QFuture QXmppAtmManager::handleMessage(const QXmppMessage &message) // 1. The message does not contain a trust message element. // 2. The trust message is sent by this endpoint and reflected via // Message Carbons. - interface->reportFinished(); + interface.reportFinished(); } - return interface->future(); + return interface.future(); } /// @@ -370,33 +373,33 @@ QFuture QXmppAtmManager::handleMessage(const QXmppMessage &message) /// QFuture QXmppAtmManager::authenticate(const QString &encryption, const QMultiHash &keyIds) { - auto interface = std::make_shared>(QFutureInterfaceBase::Started); + QFutureInterface interface(QFutureInterfaceBase::Started); if (keyIds.isEmpty()) { - interface->reportFinished(); + interface.reportFinished(); } else { auto future = m_trustStorage->setTrustLevel(encryption, keyIds, QXmppTrustStorage::Authenticated); - await(future, this, [=]() { - await(m_trustStorage->securityPolicy(encryption), this, [=](const auto securityPolicy) { + await(future, this, [=]() mutable { + await(m_trustStorage->securityPolicy(encryption), this, [=](const auto securityPolicy) mutable { if (securityPolicy == QXmppTrustStorage::Toakafa) { auto future = distrustAutomaticallyTrustedKeys(encryption, keyIds.uniqueKeys()); - await(future, this, [=]() { + await(future, this, [=]() mutable { auto future = makePostponedTrustDecisions(encryption, keyIds.values()); - await(future, this, [=]() { - interface->reportFinished(); + await(future, this, [=]() mutable { + interface.reportFinished(); }); }); } else { auto future = makePostponedTrustDecisions(encryption, keyIds.values()); - await(future, this, [=]() { - interface->reportFinished(); + await(future, this, [=]() mutable { + interface.reportFinished(); }); } }); }); } - return interface->future(); + return interface.future(); } /// @@ -407,21 +410,21 @@ QFuture QXmppAtmManager::authenticate(const QString &encryption, const QMu /// QFuture QXmppAtmManager::distrust(const QString &encryption, const QMultiHash &keyIds) { - auto interface = std::make_shared>(QFutureInterfaceBase::Started); + QFutureInterface interface(QFutureInterfaceBase::Started); if (keyIds.isEmpty()) { - interface->reportFinished(); + interface.reportFinished(); } else { auto future = m_trustStorage->setTrustLevel(encryption, keyIds, QXmppTrustStorage::ManuallyDistrusted); - await(future, this, [=]() { + await(future, this, [=]() mutable { auto future = m_trustStorage->removeKeysForPostponedTrustDecisions(encryption, keyIds.values()); - await(future, this, [=]() { - interface->reportFinished(); + await(future, this, [=]() mutable { + interface.reportFinished(); }); }); } - return interface->future(); + return interface.future(); } /// @@ -448,24 +451,24 @@ QFuture QXmppAtmManager::distrustAutomaticallyTrustedKeys(const QString &e /// QFuture QXmppAtmManager::makePostponedTrustDecisions(const QString &encryption, const QList &senderKeyIds) { - auto interface = std::make_shared>(QFutureInterfaceBase::Started); + QFutureInterface interface(QFutureInterfaceBase::Started); auto future = m_trustStorage->keysForPostponedTrustDecisions(encryption, senderKeyIds); - await(future, this, [=](const QHash> &&keysForPostponedTrustDecisions) { + await(future, this, [=](const QHash> &&keysForPostponedTrustDecisions) mutable { // JIDs of key owners mapped to the IDs of their keys const auto keysBeingAuthenticated = keysForPostponedTrustDecisions.value(true); const auto keysBeingDistrusted = keysForPostponedTrustDecisions.value(false); auto future = m_trustStorage->removeKeysForPostponedTrustDecisions(encryption, keysBeingAuthenticated.values(), keysBeingDistrusted.values()); - await(future, this, [=]() { + await(future, this, [=]() mutable { auto future = makeTrustDecisions(encryption, keysBeingAuthenticated, keysBeingDistrusted); - await(future, this, [=]() { - interface->reportFinished(); + await(future, this, [=]() mutable { + interface.reportFinished(); }); }); }); - return interface->future(); + return interface.future(); } /// -- cgit v1.2.3