keeping up with qxmpp

This commit is contained in:
Blue 2023-01-29 20:26:54 +03:00
parent 73d83f55af
commit 3c6b611a41
Signed by: blue
GPG Key ID: 9B203B252A63EE38
10 changed files with 146 additions and 153 deletions

View File

@ -130,6 +130,7 @@ if (NOT SYSTEM_QXMPP)
target_include_directories(squawk PRIVATE ${CMAKE_SOURCE_DIR}/external/qxmpp/src/base) target_include_directories(squawk PRIVATE ${CMAKE_SOURCE_DIR}/external/qxmpp/src/base)
target_include_directories(squawk PRIVATE ${CMAKE_SOURCE_DIR}/external/qxmpp/src/client) target_include_directories(squawk PRIVATE ${CMAKE_SOURCE_DIR}/external/qxmpp/src/client)
target_include_directories(squawk PRIVATE ${CMAKE_CURRENT_BINARY_DIR}/external/qxmpp/src)
if (WITH_OMEMO) if (WITH_OMEMO)
target_include_directories(squawk PRIVATE ${CMAKE_SOURCE_DIR}/external/qxmpp/src/omemo) target_include_directories(squawk PRIVATE ${CMAKE_SOURCE_DIR}/external/qxmpp/src/omemo)

View File

@ -108,23 +108,19 @@ Account::Account(const QString& p_login, const QString& p_server, const QString&
client.addExtension(om); client.addExtension(om);
if (oh->hasOwnDevice()) { if (oh->hasOwnDevice()) {
QFuture<bool> future = om->load(); QXmppTask<bool> future = om->load();
loadingOmemo = true; loadingOmemo = true;
future.then(this, [this] (bool result) {
QFutureWatcher<bool> *watcher = new QFutureWatcher<bool>(this);
QObject::connect(watcher, &QFutureWatcherBase::finished, [watcher, this] () {
loadingOmemo = false; loadingOmemo = false;
if (state == Shared::ConnectionState::scheduled) { if (state == Shared::ConnectionState::scheduled) {
client.connectToServer(config, presence); client.connectToServer(config, presence);
} }
if (watcher->result()) { if (result) {
qDebug() << "successfully loaded OMEMO data for account" << getName(); qDebug() << "successfully loaded OMEMO data for account" << getName();
} else { } else {
qDebug() << "couldn't load OMEMO data for account" << getName(); qDebug() << "couldn't load OMEMO data for account" << getName();
} }
watcher->deleteLater();
}); });
watcher->setFuture(future);
} }
#endif #endif
@ -235,20 +231,17 @@ void Core::Account::onClientStateChange(QXmppClient::State st)
#ifdef WITH_OMEMO #ifdef WITH_OMEMO
if (!oh->hasOwnDevice()) { if (!oh->hasOwnDevice()) {
qDebug() << "setting up OMEMO data for account" << getName(); qDebug() << "setting up OMEMO data for account" << getName();
QFuture<bool> future = om->setUp(); QXmppTask<bool> future = om->setUp();
QFutureWatcher<bool> *watcher = new QFutureWatcher<bool>(this); future.then(this, [this] (bool result) {
QObject::connect(watcher, &QFutureWatcherBase::finished, [watcher, this] () { if (result)
if (watcher->result()) {
qDebug() << "successfully set up OMEMO data for account" << getName(); qDebug() << "successfully set up OMEMO data for account" << getName();
} else { else
qDebug() << "couldn't set up OMEMO data for account" << getName(); qDebug() << "couldn't set up OMEMO data for account" << getName();
}
watcher->deleteLater(); if (state == Shared::ConnectionState::connected)
if (state == Shared::ConnectionState::connected) {
runDiscoveryService(); runDiscoveryService();
}
}); });
watcher->setFuture(future);
} else { } else {
runDiscoveryService(); runDiscoveryService();
} }

View File

@ -19,6 +19,8 @@
#define CORE_ADAPTER_FUNCTIONS_H #define CORE_ADAPTER_FUNCTIONS_H
#include <QXmppVCardIq.h> #include <QXmppVCardIq.h>
#include <QXmppTask.h>
#include <QXmppPromise.h>
#include <shared/vcard.h> #include <shared/vcard.h>
namespace Core { namespace Core {
@ -26,6 +28,19 @@ namespace Core {
void initializeVCard(Shared::VCard& vCard, const QXmppVCardIq& card); void initializeVCard(Shared::VCard& vCard, const QXmppVCardIq& card);
void initializeQXmppVCard(QXmppVCardIq& card, const Shared::VCard& vCard); void initializeQXmppVCard(QXmppVCardIq& card, const Shared::VCard& vCard);
template<typename T>
QXmppTask<T> makeReadyTask(T &&value) {
QXmppPromise<T> promise;
promise.finish(std::move(value));
return promise.task();
}
inline QXmppTask<void> makeReadyTask() {
QXmppPromise<void> promise;
promise.finish();
return promise.task();
}
} }

View File

@ -29,6 +29,35 @@ Core::MessageHandler::MessageHandler(Core::Account* account):
void Core::MessageHandler::onMessageReceived(const QXmppMessage& msg) void Core::MessageHandler::onMessageReceived(const QXmppMessage& msg)
{ {
#if (QXMPP_VERSION) >= QT_VERSION_CHECK(1, 5, 0)
#ifdef WITH_OMEMO
switch (msg.encryptionMethod()) {
case QXmpp::NoEncryption:
break; //just do nothing
case QXmpp::UnknownEncryption:
qDebug() << "Account" << acc->getName() << "received a message with unknown encryption type";
break; //let it go the way it is, there is nothing I can do here
case QXmpp::Otr:
qDebug() << "Account" << acc->getName() << "received an OTR encrypted message, not supported yet";
break; //let it go the way it is, there is nothing I can do yet
case QXmpp::LegacyOpenPgp:
qDebug() << "Account" << acc->getName() << "received an LegacyOpenPgp encrypted message, not supported yet";
break; //let it go the way it is, there is nothing I can do yet
case QXmpp::Ox:
qDebug() << "Account" << acc->getName() << "received an Ox encrypted message, not supported yet";
break; //let it go the way it is, there is nothing I can do yet
case QXmpp::Omemo0:
qDebug() << "Account" << acc->getName() << "received an Omemo0 encrypted message, not supported yet";
break; //let it go the way it is, there is nothing I can do yet
case QXmpp::Omemo1:
qDebug() << "Account" << acc->getName() << "received an Omemo1 encrypted message, not supported yet";
break; //let it go the way it is, there is nothing I can do yet
case QXmpp::Omemo2:
qDebug() << "Account" << acc->getName() << "received an Omemo2 encrypted message, not supported yet";
break; //let it go the way it is, there is nothing I can do yet
}
#endif
#endif
bool handled = false; bool handled = false;
switch (msg.type()) { switch (msg.type()) {
case QXmppMessage::Normal: case QXmppMessage::Normal:

View File

@ -17,6 +17,7 @@
#include <QDebug> #include <QDebug>
#include "omemohandler.h" #include "omemohandler.h"
#include "core/account.h" #include "core/account.h"
#include "core/adapterfunctions.h"
Core::OmemoHandler::OmemoHandler(Account* account) : Core::OmemoHandler::OmemoHandler(Account* account) :
QXmppOmemoStorage(), QXmppOmemoStorage(),
@ -46,13 +47,7 @@ bool Core::OmemoHandler::hasOwnDevice() {
return ownDevice.has_value(); return ownDevice.has_value();
} }
QFuture<void> Core::OmemoHandler::emptyVoidFuture() { QXmppTask<QXmppOmemoStorage::OmemoData> Core::OmemoHandler::allData() {
QFutureInterface<QXmppOmemoStorage::OmemoData> result(QFutureInterfaceBase::Started);
result.reportFinished();
return result.future();
}
QFuture<QXmppOmemoStorage::OmemoData> Core::OmemoHandler::allData() {
OmemoData data; OmemoData data;
data.ownDevice = ownDevice; data.ownDevice = ownDevice;
@ -72,13 +67,10 @@ QFuture<QXmppOmemoStorage::OmemoData> Core::OmemoHandler::allData() {
data.devices.insert(pair.first, pair.second); data.devices.insert(pair.first, pair.second);
} }
QFutureInterface<QXmppOmemoStorage::OmemoData> result(QFutureInterfaceBase::Started); return Core::makeReadyTask(std::move(data));
result.reportResult(std::move(data));
result.reportFinished();
return result.future();
} }
QFuture<void> Core::OmemoHandler::addDevice(const QString& jid, uint32_t deviceId, const QXmppOmemoStorage::Device& device) { QXmppTask<void> Core::OmemoHandler::addDevice(const QString& jid, uint32_t deviceId, const QXmppOmemoStorage::Device& device) {
QHash<uint32_t, Device> devs; QHash<uint32_t, Device> devs;
bool had = true; bool had = true;
try { try {
@ -94,23 +86,23 @@ QFuture<void> Core::OmemoHandler::addDevice(const QString& jid, uint32_t deviceI
devices->addRecord(jid, devs); devices->addRecord(jid, devs);
} }
return emptyVoidFuture(); return Core::makeReadyTask();
} }
QFuture<void> Core::OmemoHandler::addPreKeyPairs(const QHash<uint32_t, QByteArray>& keyPairs) { QXmppTask<void> Core::OmemoHandler::addPreKeyPairs(const QHash<uint32_t, QByteArray>& keyPairs) {
for (QHash<uint32_t, QByteArray>::const_iterator itr = keyPairs.begin(), end = keyPairs.end(); itr != end; ++itr) { for (QHash<uint32_t, QByteArray>::const_iterator itr = keyPairs.begin(), end = keyPairs.end(); itr != end; ++itr) {
preKeyPairs->forceRecord(itr.key(), itr.value()); preKeyPairs->forceRecord(itr.key(), itr.value());
} }
return emptyVoidFuture(); return Core::makeReadyTask();
} }
QFuture<void> Core::OmemoHandler::addSignedPreKeyPair(uint32_t keyId, const QXmppOmemoStorage::SignedPreKeyPair& keyPair) { QXmppTask<void> Core::OmemoHandler::addSignedPreKeyPair(uint32_t keyId, const QXmppOmemoStorage::SignedPreKeyPair& keyPair) {
signedPreKeyPairs->forceRecord(keyId, std::make_pair(keyPair.creationDate, keyPair.data)); signedPreKeyPairs->forceRecord(keyId, std::make_pair(keyPair.creationDate, keyPair.data));
return emptyVoidFuture(); return Core::makeReadyTask();
} }
QFuture<void> Core::OmemoHandler::removeDevice(const QString& jid, uint32_t deviceId) { QXmppTask<void> Core::OmemoHandler::removeDevice(const QString& jid, uint32_t deviceId) {
QHash<uint32_t, Device> devs = devices->getRecord(jid); QHash<uint32_t, Device> devs = devices->getRecord(jid);
devs.remove(deviceId); devs.remove(deviceId);
if (devs.isEmpty()) { if (devs.isEmpty()) {
@ -118,25 +110,27 @@ QFuture<void> Core::OmemoHandler::removeDevice(const QString& jid, uint32_t devi
} else { } else {
devices->changeRecord(jid, devs); devices->changeRecord(jid, devs);
} }
return emptyVoidFuture(); return Core::makeReadyTask();
} }
QFuture<void> Core::OmemoHandler::removeDevices(const QString& jid) { QXmppTask<void> Core::OmemoHandler::removeDevices(const QString& jid) {
devices->removeRecord(jid); devices->removeRecord(jid);
return emptyVoidFuture(); return Core::makeReadyTask();
} }
QFuture<void> Core::OmemoHandler::removePreKeyPair(uint32_t keyId) { QXmppTask<void> Core::OmemoHandler::removePreKeyPair(uint32_t keyId) {
preKeyPairs->removeRecord(keyId); preKeyPairs->removeRecord(keyId);
return emptyVoidFuture(); return Core::makeReadyTask();
} }
QFuture<void> Core::OmemoHandler::removeSignedPreKeyPair(uint32_t keyId) { QXmppTask<void> Core::OmemoHandler::removeSignedPreKeyPair(uint32_t keyId) {
signedPreKeyPairs->removeRecord(keyId); try {
return emptyVoidFuture(); signedPreKeyPairs->removeRecord(keyId);
} catch (const DataBase::NotFound& e) {}
return Core::makeReadyTask();
} }
QFuture<void> Core::OmemoHandler::setOwnDevice(const std::optional<OwnDevice>& device) { QXmppTask<void> Core::OmemoHandler::setOwnDevice(const std::optional<OwnDevice>& device) {
bool had = ownDevice.has_value(); bool had = ownDevice.has_value();
ownDevice = device; ownDevice = device;
if (ownDevice.has_value()) { if (ownDevice.has_value()) {
@ -150,14 +144,14 @@ QFuture<void> Core::OmemoHandler::setOwnDevice(const std::optional<OwnDevice>& d
meta->removeRecord("ownDevice"); meta->removeRecord("ownDevice");
} }
} }
return emptyVoidFuture(); return Core::makeReadyTask();
} }
QFuture<void> Core::OmemoHandler::resetAll() { QXmppTask<void> Core::OmemoHandler::resetAll() {
ownDevice = std::nullopt; ownDevice = std::nullopt;
db.drop(); db.drop();
return emptyVoidFuture(); return Core::makeReadyTask();
} }
QDataStream & operator >> (QDataStream& in, QXmppOmemoStorage::Device& device) { QDataStream & operator >> (QDataStream& in, QXmppOmemoStorage::Device& device) {

View File

@ -34,27 +34,24 @@ public:
OmemoHandler(Account* account); OmemoHandler(Account* account);
~OmemoHandler() override; ~OmemoHandler() override;
QFuture<OmemoData> allData() override; QXmppTask<OmemoData> allData() override;
QFuture<void> setOwnDevice(const std::optional<OwnDevice> &device) override; QXmppTask<void> setOwnDevice(const std::optional<OwnDevice> &device) override;
QFuture<void> addSignedPreKeyPair(uint32_t keyId, const QXmppOmemoStorage::SignedPreKeyPair &keyPair) override; QXmppTask<void> addSignedPreKeyPair(uint32_t keyId, const QXmppOmemoStorage::SignedPreKeyPair &keyPair) override;
QFuture<void> removeSignedPreKeyPair(uint32_t keyId) override; QXmppTask<void> removeSignedPreKeyPair(uint32_t keyId) override;
QFuture<void> addPreKeyPairs(const QHash<uint32_t, QByteArray> &keyPairs) override; QXmppTask<void> addPreKeyPairs(const QHash<uint32_t, QByteArray> &keyPairs) override;
QFuture<void> removePreKeyPair(uint32_t keyId) override; QXmppTask<void> removePreKeyPair(uint32_t keyId) override;
QFuture<void> addDevice(const QString &jid, uint32_t deviceId, const Device &device) override; QXmppTask<void> addDevice(const QString &jid, uint32_t deviceId, const Device &device) override;
QFuture<void> removeDevice(const QString &jid, uint32_t deviceId) override; QXmppTask<void> removeDevice(const QString &jid, uint32_t deviceId) override;
QFuture<void> removeDevices(const QString &jid) override; QXmppTask<void> removeDevices(const QString &jid) override;
QFuture<void> resetAll() override; QXmppTask<void> resetAll() override;
bool hasOwnDevice(); bool hasOwnDevice();
private:
static QFuture<void> emptyVoidFuture();
private: private:
Account* acc; Account* acc;
std::optional<OwnDevice> ownDevice; std::optional<OwnDevice> ownDevice;

View File

@ -16,6 +16,7 @@
#include "trusthandler.h" #include "trusthandler.h"
#include "core/account.h" #include "core/account.h"
#include "core/adapterfunctions.h"
using namespace Core; using namespace Core;
@ -75,37 +76,25 @@ Core::TrustHandler::KeyCache * Core::TrustHandler::createNewCache(const QString&
return cache; return cache;
} }
QXmppTask<void> Core::TrustHandler::resetAll(const QString& encryption) {
QFuture<void> Core::TrustHandler::emptyVoidFuture() {
QFutureInterface<QXmppOmemoStorage::OmemoData> result(QFutureInterfaceBase::Started);
result.reportFinished();
return result.future();
}
QFuture<void> Core::TrustHandler::resetAll(const QString& encryption) {
securityPolicies->removeRecord(encryption); securityPolicies->removeRecord(encryption);
ownKeys->removeRecord(encryption); ownKeys->removeRecord(encryption);
getCache(encryption)->drop(); getCache(encryption)->drop();
return emptyVoidFuture(); return Core::makeReadyTask();
} }
QFuture<QXmpp::TrustLevel> Core::TrustHandler::trustLevel( QXmppTask<QXmpp::TrustLevel> Core::TrustHandler::trustLevel(
const QString& encryption, const QString& encryption,
const QString& keyOwnerJid, const QString& keyOwnerJid,
const QByteArray& keyId) const QByteArray& keyId)
{ {
Keys map = getCache(encryption)->getRecord(keyOwnerJid); Keys map = getCache(encryption)->getRecord(keyOwnerJid);
Shared::TrustLevel level = map.at(keyId); Shared::TrustLevel level = map.at(keyId);
return Core::makeReadyTask(std::move(convert(level)));
QFutureInterface<QXmpp::TrustLevel> result(QFutureInterfaceBase::Started);
result.reportResult(convert(level));
result.reportFinished();
return result.future();
} }
QFuture<QHash<QString, QMultiHash<QString, QByteArray>>> Core::TrustHandler::setTrustLevel( QXmppTask<QHash<QString, QMultiHash<QString, QByteArray>>> Core::TrustHandler::setTrustLevel(
const QString& encryption, const QString& encryption,
const QList<QString>& keyOwnerJids, const QList<QString>& keyOwnerJids,
QXmpp::TrustLevel oldTrustLevel, QXmpp::TrustLevel oldTrustLevel,
@ -130,14 +119,10 @@ QFuture<QHash<QString, QMultiHash<QString, QByteArray>>> Core::TrustHandler::set
cache->changeRecord(keyOwnerJid, map); cache->changeRecord(keyOwnerJid, map);
} }
} }
return Core::makeReadyTask(std::move(modifiedKeys));
QFutureInterface<QHash<QString, QMultiHash<QString, QByteArray>>> result(QFutureInterfaceBase::Started);
result.reportResult(modifiedKeys);
result.reportFinished();
return result.future();
} }
QFuture<QHash<QString, QMultiHash<QString, QByteArray>>> Core::TrustHandler::setTrustLevel( QXmppTask<QHash<QString, QMultiHash<QString, QByteArray>>> Core::TrustHandler::setTrustLevel(
const QString& encryption, const QString& encryption,
const QMultiHash<QString, QByteArray>& keyIds, const QMultiHash<QString, QByteArray>& keyIds,
QXmpp::TrustLevel trustLevel) QXmpp::TrustLevel trustLevel)
@ -160,14 +145,10 @@ QFuture<QHash<QString, QMultiHash<QString, QByteArray>>> Core::TrustHandler::set
cache->changeRecord(keyOwnerJid, map); cache->changeRecord(keyOwnerJid, map);
} }
} }
return Core::makeReadyTask(std::move(modifiedKeys));
QFutureInterface<QHash<QString, QMultiHash<QString, QByteArray>>> result(QFutureInterfaceBase::Started);
result.reportResult(modifiedKeys);
result.reportFinished();
return result.future();
} }
QFuture<bool> TrustHandler::hasKey(const QString& encryption, QXmppTask<bool> TrustHandler::hasKey(const QString& encryption,
const QString& keyOwnerJid, const QString& keyOwnerJid,
QXmpp::TrustLevels trustLevels) QXmpp::TrustLevels trustLevels)
{ {
@ -182,14 +163,10 @@ QFuture<bool> TrustHandler::hasKey(const QString& encryption,
} }
} }
} catch (const DataBase::NotFound& e) {} } catch (const DataBase::NotFound& e) {}
return Core::makeReadyTask(std::move(found));
QFutureInterface<bool> result(QFutureInterfaceBase::Started);
result.reportResult(found);
result.reportFinished();
return result.future();
} }
QFuture<QHash<QString, QHash<QByteArray, QXmpp::TrustLevel>>> TrustHandler::keys( QXmppTask<QHash<QString, QHash<QByteArray, QXmpp::TrustLevel>>> TrustHandler::keys(
const QString& encryption, const QString& encryption,
const QList<QString>& keyOwnerJids, const QList<QString>& keyOwnerJids,
QXmpp::TrustLevels trustLevels) QXmpp::TrustLevels trustLevels)
@ -209,14 +186,10 @@ QFuture<QHash<QString, QHash<QByteArray, QXmpp::TrustLevel>>> TrustHandler::keys
} }
} catch (const DataBase::NotFound& e) {} } catch (const DataBase::NotFound& e) {}
} }
return Core::makeReadyTask(std::move(res));
QFutureInterface<HSHBTL> result(QFutureInterfaceBase::Started);
result.reportResult(res);
result.reportFinished();
return result.future();
} }
QFuture<QHash<QXmpp::TrustLevel, QMultiHash<QString, QByteArray>>> TrustHandler::keys( QXmppTask<QHash<QXmpp::TrustLevel, QMultiHash<QString, QByteArray>>> TrustHandler::keys(
const QString& encryption, const QString& encryption,
QXmpp::TrustLevels trustLevels) QXmpp::TrustLevels trustLevels)
{ {
@ -231,24 +204,20 @@ QFuture<QHash<QXmpp::TrustLevel, QMultiHash<QString, QByteArray>>> TrustHandler:
} }
} }
} }
return Core::makeReadyTask(std::move(res));
QFutureInterface<QHash<TL, MultySB>> result(QFutureInterfaceBase::Started);
result.reportResult(res);
result.reportFinished();
return result.future();
} }
QFuture<void> TrustHandler::removeKeys(const QString& encryption) { QXmppTask<void> TrustHandler::removeKeys(const QString& encryption) {
getCache(encryption)->drop(); getCache(encryption)->drop();
return emptyVoidFuture(); return Core::makeReadyTask();
} }
QFuture<void> TrustHandler::removeKeys(const QString& encryption, const QString& keyOwnerJid) { QXmppTask<void> TrustHandler::removeKeys(const QString& encryption, const QString& keyOwnerJid) {
getCache(encryption)->removeRecord(keyOwnerJid); getCache(encryption)->removeRecord(keyOwnerJid);
return emptyVoidFuture(); return Core::makeReadyTask();
} }
QFuture<void> TrustHandler::removeKeys(const QString& encryption, const QList<QByteArray>& keyIds) { QXmppTask<void> TrustHandler::removeKeys(const QString& encryption, const QList<QByteArray>& keyIds) {
std::set<QByteArray> set; std::set<QByteArray> set;
for (const QByteArray& keyId : keyIds) { for (const QByteArray& keyId : keyIds) {
set.insert(keyId); set.insert(keyId);
@ -278,10 +247,10 @@ QFuture<void> TrustHandler::removeKeys(const QString& encryption, const QList<QB
cache->replaceAll(data); cache->replaceAll(data);
} }
return emptyVoidFuture(); return Core::makeReadyTask();
} }
QFuture<void> TrustHandler::addKeys( QXmppTask<void> TrustHandler::addKeys(
const QString& encryption, const QString& encryption,
const QString& keyOwnerJid, const QString& keyOwnerJid,
const QList<QByteArray>& keyIds, const QList<QByteArray>& keyIds,
@ -308,61 +277,53 @@ QFuture<void> TrustHandler::addKeys(
cache->addRecord(keyOwnerJid, data); cache->addRecord(keyOwnerJid, data);
} }
return emptyVoidFuture(); return Core::makeReadyTask();
} }
QFuture<QByteArray> TrustHandler::ownKey(const QString& encryption) { QXmppTask<QByteArray> TrustHandler::ownKey(const QString& encryption) {
QByteArray res; QByteArray res;
try { try {
res = ownKeys->getRecord(encryption); res = ownKeys->getRecord(encryption);
} catch (const DataBase::NotFound& e) {} } catch (const DataBase::NotFound& e) {}
return Core::makeReadyTask(std::move(res));
QFutureInterface<QByteArray> result(QFutureInterfaceBase::Started);
result.reportResult(res);
result.reportFinished();
return result.future();
} }
QFuture<void> TrustHandler::resetOwnKey(const QString& encryption) { QXmppTask<void> TrustHandler::resetOwnKey(const QString& encryption) {
try { try {
ownKeys->removeRecord(encryption); ownKeys->removeRecord(encryption);
} catch (const DataBase::NotFound& e) {} } catch (const DataBase::NotFound& e) {}
return emptyVoidFuture(); return Core::makeReadyTask();
} }
QFuture<void> TrustHandler::setOwnKey(const QString& encryption, const QByteArray& keyId) { QXmppTask<void> TrustHandler::setOwnKey(const QString& encryption, const QByteArray& keyId) {
ownKeys->forceRecord(encryption, keyId); ownKeys->forceRecord(encryption, keyId);
return emptyVoidFuture(); return Core::makeReadyTask();
} }
QFuture<QXmpp::TrustSecurityPolicy> TrustHandler::securityPolicy(const QString& encryption) { QXmppTask<QXmpp::TrustSecurityPolicy> TrustHandler::securityPolicy(const QString& encryption) {
QXmpp::TrustSecurityPolicy res; QXmpp::TrustSecurityPolicy res;
try { try {
res = static_cast<QXmpp::TrustSecurityPolicy>(securityPolicies->getRecord(encryption)); res = static_cast<QXmpp::TrustSecurityPolicy>(securityPolicies->getRecord(encryption));
} catch (const DataBase::NotFound& e) {} } catch (const DataBase::NotFound& e) {}
return Core::makeReadyTask(std::move(res));
QFutureInterface<QXmpp::TrustSecurityPolicy> result(QFutureInterfaceBase::Started);
result.reportResult(res);
result.reportFinished();
return result.future();
} }
QFuture<void> TrustHandler::resetSecurityPolicy(const QString& encryption) { QXmppTask<void> TrustHandler::resetSecurityPolicy(const QString& encryption) {
try { try {
securityPolicies->removeRecord(encryption); securityPolicies->removeRecord(encryption);
} catch (const DataBase::NotFound& e) {} } catch (const DataBase::NotFound& e) {}
return emptyVoidFuture(); return Core::makeReadyTask();
} }
QFuture<void> TrustHandler::setSecurityPolicy( QXmppTask<void> TrustHandler::setSecurityPolicy(
const QString& encryption, const QString& encryption,
QXmpp::TrustSecurityPolicy securityPolicy) QXmpp::TrustSecurityPolicy securityPolicy)
{ {
uint8_t pol = securityPolicy; uint8_t pol = securityPolicy;
securityPolicies->forceRecord(encryption, pol); securityPolicies->forceRecord(encryption, pol);
return emptyVoidFuture(); return Core::makeReadyTask();
} }
Shared::TrustLevel Core::TrustHandler::convert(Core::TrustHandler::TL level) Shared::TrustLevel Core::TrustHandler::convert(Core::TrustHandler::TL level)

View File

@ -41,29 +41,28 @@ public:
typedef std::map<QByteArray, Shared::TrustLevel> Keys; typedef std::map<QByteArray, Shared::TrustLevel> Keys;
typedef DataBase::Cache<QString, Keys> KeyCache; typedef DataBase::Cache<QString, Keys> KeyCache;
virtual QFuture<void> resetAll(CSR encryption); virtual QXmppTask<void> resetAll(CSR encryption);
virtual QFuture<TL> trustLevel(CSR encryption, CSR keyOwnerJid, const QByteArray& keyId); virtual QXmppTask<TL> trustLevel(CSR encryption, CSR keyOwnerJid, const QByteArray& keyId);
virtual QFuture<HashSM> setTrustLevel(CSR encryption, CLSR keyOwnerJids, TL oldTrustLevel, TL newTrustLevel); virtual QXmppTask<HashSM> setTrustLevel(CSR encryption, CLSR keyOwnerJids, TL oldTrustLevel, TL newTrustLevel);
virtual QFuture<HashSM> setTrustLevel(CSR encryption, const MultySB& keyIds, TL trustLevel); virtual QXmppTask<HashSM> setTrustLevel(CSR encryption, const MultySB& keyIds, TL trustLevel);
virtual QFuture<bool> hasKey(CSR encryption, CSR keyOwnerJid, QXmpp::TrustLevels trustLevels); virtual QXmppTask<bool> hasKey(CSR encryption, CSR keyOwnerJid, QXmpp::TrustLevels trustLevels);
virtual QFuture<HSHBTL> keys(CSR encryption, CLSR keyOwnerJids, QXmpp::TrustLevels trustLevels); virtual QXmppTask<HSHBTL> keys(CSR encryption, CLSR keyOwnerJids, QXmpp::TrustLevels trustLevels);
virtual QFuture<QHash<TL, MultySB>> keys(CSR encryption, QXmpp::TrustLevels trustLevels); virtual QXmppTask<QHash<TL, MultySB>> keys(CSR encryption, QXmpp::TrustLevels trustLevels);
virtual QFuture<void> removeKeys(CSR encryption); virtual QXmppTask<void> removeKeys(CSR encryption);
virtual QFuture<void> removeKeys(CSR encryption, CSR keyOwnerJid); virtual QXmppTask<void> removeKeys(CSR encryption, CSR keyOwnerJid);
virtual QFuture<void> removeKeys(CSR encryption, CLBAR keyIds); virtual QXmppTask<void> removeKeys(CSR encryption, CLBAR keyIds);
virtual QFuture<void> addKeys(CSR encryption, CSR keyOwnerJid, CLBAR keyIds, TL trustLevel); virtual QXmppTask<void> addKeys(CSR encryption, CSR keyOwnerJid, CLBAR keyIds, TL trustLevel);
virtual QFuture<QByteArray> ownKey(CSR encryption); virtual QXmppTask<QByteArray> ownKey(CSR encryption);
virtual QFuture<void> resetOwnKey(CSR encryption); virtual QXmppTask<void> resetOwnKey(CSR encryption);
virtual QFuture<void> setOwnKey(CSR encryption, const QByteArray& keyId); virtual QXmppTask<void> setOwnKey(CSR encryption, const QByteArray& keyId);
virtual QFuture<QXmpp::TrustSecurityPolicy> securityPolicy(CSR encryption); virtual QXmppTask<QXmpp::TrustSecurityPolicy> securityPolicy(CSR encryption);
virtual QFuture<void> resetSecurityPolicy(CSR encryption); virtual QXmppTask<void> resetSecurityPolicy(CSR encryption);
virtual QFuture<void> setSecurityPolicy(CSR encryption, QXmpp::TrustSecurityPolicy securityPolicy); virtual QXmppTask<void> setSecurityPolicy(CSR encryption, QXmpp::TrustSecurityPolicy securityPolicy);
static TL convert(Shared::TrustLevel level); static TL convert(Shared::TrustLevel level);
static Shared::TrustLevel convert(TL level); static Shared::TrustLevel convert(TL level);
private: private:
static QFuture<void> emptyVoidFuture();
KeyCache* createNewCache(const QString& encryption); KeyCache* createNewCache(const QString& encryption);
KeyCache* getCache(const QString& encryption); KeyCache* getCache(const QString& encryption);

2
external/qxmpp vendored

@ -1 +1 @@
Subproject commit befab2fe2e71330170bba48f173258be724c65b9 Subproject commit d2c2acd4848f815d0dc3d108f8bc306f9015fc89

View File

@ -19,10 +19,14 @@
#include <QXmppGlobal.h> #include <QXmppGlobal.h>
#include <QDebug> #include <QDebug>
#if (QXMPP_VERSION) < QT_VERSION_CHECK(1, 3, 0)
static const std::string QXMPP_VERSION_PATCH(std::to_string(QXMPP_VERSION & 0xff)); static const std::string QXMPP_VERSION_PATCH(std::to_string(QXMPP_VERSION & 0xff));
static const std::string QXMPP_VERSION_MINOR(std::to_string((QXMPP_VERSION & 0xff00) >> 8)); static const std::string QXMPP_VERSION_MINOR(std::to_string((QXMPP_VERSION & 0xff00) >> 8));
static const std::string QXMPP_VERSION_MAJOR(std::to_string(QXMPP_VERSION >> 16)); static const std::string QXMPP_VERSION_MAJOR(std::to_string(QXMPP_VERSION >> 16));
static const QString QXMPP_VERSION_STRING = QString::fromStdString(QXMPP_VERSION_MAJOR + "." + QXMPP_VERSION_MINOR + "." + QXMPP_VERSION_PATCH); static const QString QXMPP_VERSION_STRING = QString::fromStdString(QXMPP_VERSION_MAJOR + "." + QXMPP_VERSION_MINOR + "." + QXMPP_VERSION_PATCH);
#else
static const QString QXMPP_VERSION_STRING = QXmppVersion();
#endif
About::About(QWidget* parent): About::About(QWidget* parent):
QWidget(parent), QWidget(parent),