forked from blue/squawk
transition to LMDBAL
This commit is contained in:
parent
69d797fe51
commit
81cf0f8d34
18 changed files with 76 additions and 42 deletions
|
@ -35,7 +35,7 @@ Core::OmemoHandler::OmemoHandler(Account* account) :
|
|||
QVariant own = meta->getRecord("ownDevice");
|
||||
ownDevice = own.value<OwnDevice>();
|
||||
qDebug() << "Successfully found own device omemo data for account" << acc->getName();
|
||||
} catch (const DataBase::NotFound& e) {
|
||||
} catch (const LMDBAL::NotFound& e) {
|
||||
qDebug() << "No device omemo data was found for account" << acc->getName();
|
||||
}
|
||||
}
|
||||
|
@ -76,7 +76,7 @@ QXmppTask<void> Core::OmemoHandler::addDevice(const QString& jid, uint32_t devic
|
|||
bool had = true;
|
||||
try {
|
||||
devs = devices->getRecord(jid);
|
||||
} catch (const DataBase::NotFound& error) {
|
||||
} catch (const LMDBAL::NotFound& error) {
|
||||
had = false;
|
||||
}
|
||||
|
||||
|
@ -127,7 +127,7 @@ QXmppTask<void> Core::OmemoHandler::removePreKeyPair(uint32_t keyId) {
|
|||
QXmppTask<void> Core::OmemoHandler::removeSignedPreKeyPair(uint32_t keyId) {
|
||||
try {
|
||||
signedPreKeyPairs->removeRecord(keyId);
|
||||
} catch (const DataBase::NotFound& e) {}
|
||||
} catch (const LMDBAL::NotFound& e) {}
|
||||
return Core::makeReadyTask();
|
||||
}
|
||||
|
||||
|
@ -159,7 +159,7 @@ void Core::OmemoHandler::getDevices(const QString& jid, std::list<Shared::KeyInf
|
|||
QHash<uint32_t, Device> devs;
|
||||
try {
|
||||
devs = devices->getRecord(jid);
|
||||
} catch (const DataBase::NotFound& error) {}
|
||||
} catch (const LMDBAL::NotFound& error) {}
|
||||
|
||||
for (QHash<uint32_t, Device>::const_iterator itr = devs.begin(), end = devs.end(); itr != end; ++itr) {
|
||||
const Device& dev = itr.value();
|
||||
|
|
|
@ -73,11 +73,11 @@ private slots:
|
|||
private:
|
||||
Account* acc;
|
||||
std::optional<OwnDevice> ownDevice;
|
||||
DataBase db;
|
||||
DataBase::Cache<QString, QVariant>* meta;
|
||||
DataBase::Cache<QString, QHash<uint32_t, Device>>* devices;
|
||||
DataBase::Cache<uint32_t, QByteArray>* preKeyPairs;
|
||||
DataBase::Cache<uint32_t, SignedPreKeyPair>* signedPreKeyPairs;
|
||||
LMDBAL::Base db;
|
||||
LMDBAL::Cache<QString, QVariant>* meta;
|
||||
LMDBAL::Cache<QString, QHash<uint32_t, Device>>* devices;
|
||||
LMDBAL::Cache<uint32_t, QByteArray>* preKeyPairs;
|
||||
LMDBAL::Cache<uint32_t, SignedPreKeyPair>* signedPreKeyPairs;
|
||||
};
|
||||
|
||||
}
|
||||
|
|
|
@ -29,7 +29,7 @@ Core::TrustHandler::TrustHandler(Account* account):
|
|||
keysByProtocol()
|
||||
{
|
||||
if (!protocols.open(QIODevice::ReadWrite | QIODevice::Text)) { //never supposed to happen since I have just created a directory;
|
||||
throw DataBase::Directory(protocols.fileName().toStdString());
|
||||
throw LMDBAL::Directory(protocols.fileName().toStdString());
|
||||
}
|
||||
|
||||
QTextStream in(&protocols);
|
||||
|
@ -66,7 +66,7 @@ Core::TrustHandler::KeyCache * Core::TrustHandler::createNewCache(const QString&
|
|||
keysByProtocol.insert(std::make_pair(encryption, cache));
|
||||
|
||||
if(!protocols.open(QIODevice::WriteOnly | QIODevice::Append | QIODevice::Text)) {
|
||||
throw DataBase::Directory(protocols.fileName().toStdString());
|
||||
throw LMDBAL::Directory(protocols.fileName().toStdString());
|
||||
}
|
||||
QTextStream out(&protocols);
|
||||
out << encryption + "\n";
|
||||
|
@ -114,7 +114,7 @@ QXmppTask<QXmpp::TrustLevel> Core::TrustHandler::trustLevel(
|
|||
Keys::const_iterator itr = map.find(keyId);
|
||||
if (itr != map.end())
|
||||
level = itr->second;
|
||||
} catch (const DataBase::NotFound& e) {}
|
||||
} catch (const LMDBAL::NotFound& e) {}
|
||||
return Core::makeReadyTask(std::move(convert(level)));
|
||||
}
|
||||
|
||||
|
@ -176,7 +176,7 @@ QXmppTask<QHash<QString, QMultiHash<QString, QByteArray>>> Core::TrustHandler::s
|
|||
modifiedJids.insert(keyOwnerJid);
|
||||
cache->changeRecord(keyOwnerJid, map);
|
||||
}
|
||||
} catch (const DataBase::NotFound& e) {
|
||||
} catch (const LMDBAL::NotFound& e) {
|
||||
Keys map({{keyId, level}});
|
||||
modifiedKeys[encryption].insert(keyOwnerJid, keyId);
|
||||
modifiedJids.insert(keyOwnerJid);
|
||||
|
@ -204,7 +204,7 @@ QXmppTask<bool> Core::TrustHandler::hasKey(const QString& encryption,
|
|||
break;
|
||||
}
|
||||
}
|
||||
} catch (const DataBase::NotFound& e) {}
|
||||
} catch (const LMDBAL::NotFound& e) {}
|
||||
return Core::makeReadyTask(std::move(found));
|
||||
}
|
||||
|
||||
|
@ -226,7 +226,7 @@ QXmppTask<QHash<QString, QHash<QByteArray, QXmpp::TrustLevel>>> Core::TrustHandl
|
|||
pRes.insert(pair.first, level);
|
||||
}
|
||||
}
|
||||
} catch (const DataBase::NotFound& e) {}
|
||||
} catch (const LMDBAL::NotFound& e) {}
|
||||
}
|
||||
return Core::makeReadyTask(std::move(res));
|
||||
}
|
||||
|
@ -281,7 +281,7 @@ QXmppTask<void> Core::TrustHandler::removeKeys(const QString& encryption, const
|
|||
try {
|
||||
cache->removeRecord(keyOwnerJid);
|
||||
emit trustLevelsChanged(keyOwnerJid, getSummary(keyOwnerJid)); //TODO there is a probability of notification without the actial change
|
||||
} catch (const DataBase::NotFound& e) {} //if the movin entry was empty or if it consisted of Undecided keys
|
||||
} catch (const LMDBAL::NotFound& e) {} //if the movin entry was empty or if it consisted of Undecided keys
|
||||
|
||||
|
||||
return Core::makeReadyTask();
|
||||
|
@ -334,7 +334,7 @@ QXmppTask<void> Core::TrustHandler::addKeys(
|
|||
try {
|
||||
data = cache->getRecord(keyOwnerJid);
|
||||
had = true;
|
||||
} catch (const DataBase::NotFound& e) {}
|
||||
} catch (const LMDBAL::NotFound& e) {}
|
||||
for (const QByteArray& keyId : keyIds) {
|
||||
std::pair<Keys::iterator, bool> result = data.insert(std::make_pair(keyId, level));
|
||||
if (!result.second)
|
||||
|
@ -355,14 +355,14 @@ QXmppTask<QByteArray> Core::TrustHandler::ownKey(const QString& encryption) {
|
|||
QByteArray res;
|
||||
try {
|
||||
res = ownKeys->getRecord(encryption);
|
||||
} catch (const DataBase::NotFound& e) {}
|
||||
} catch (const LMDBAL::NotFound& e) {}
|
||||
return Core::makeReadyTask(std::move(res));
|
||||
}
|
||||
|
||||
QXmppTask<void> Core::TrustHandler::resetOwnKey(const QString& encryption) {
|
||||
try {
|
||||
ownKeys->removeRecord(encryption);
|
||||
} catch (const DataBase::NotFound& e) {}
|
||||
} catch (const LMDBAL::NotFound& e) {}
|
||||
|
||||
return Core::makeReadyTask();
|
||||
}
|
||||
|
@ -376,14 +376,14 @@ QXmppTask<QXmpp::TrustSecurityPolicy> Core::TrustHandler::securityPolicy(const Q
|
|||
QXmpp::TrustSecurityPolicy res;
|
||||
try {
|
||||
res = static_cast<QXmpp::TrustSecurityPolicy>(securityPolicies->getRecord(encryption));
|
||||
} catch (const DataBase::NotFound& e) {}
|
||||
} catch (const LMDBAL::NotFound& e) {}
|
||||
return Core::makeReadyTask(std::move(res));
|
||||
}
|
||||
|
||||
QXmppTask<void> Core::TrustHandler::resetSecurityPolicy(const QString& encryption) {
|
||||
try {
|
||||
securityPolicies->removeRecord(encryption);
|
||||
} catch (const DataBase::NotFound& e) {}
|
||||
} catch (const LMDBAL::NotFound& e) {}
|
||||
return Core::makeReadyTask();
|
||||
}
|
||||
|
||||
|
@ -404,7 +404,7 @@ Core::TrustHandler::Keys Core::TrustHandler::getKeys(Shared::EncryptionProtocol
|
|||
try {
|
||||
Keys map = itr->second->getRecord(jid);
|
||||
return map;
|
||||
} catch (const DataBase::NotFound& e) {
|
||||
} catch (const LMDBAL::NotFound& e) {
|
||||
return Keys();
|
||||
}
|
||||
} else {
|
||||
|
@ -421,7 +421,7 @@ Shared::TrustSummary Core::TrustHandler::getSummary(const QString& jid) const {
|
|||
for (const std::pair<const QByteArray, Shared::TrustLevel>& trust : keys) {
|
||||
result.increment(protocol, trust.second);
|
||||
}
|
||||
} catch (const DataBase::NotFound& e) {}
|
||||
} catch (const LMDBAL::NotFound& e) {}
|
||||
}
|
||||
|
||||
return result;
|
||||
|
|
|
@ -45,7 +45,7 @@ public:
|
|||
typedef QHash<QString, QHash<QByteArray, TL>> HSHBTL;
|
||||
|
||||
typedef std::map<QByteArray, Shared::TrustLevel> Keys;
|
||||
typedef DataBase::Cache<QString, Keys> KeyCache;
|
||||
typedef LMDBAL::Cache<QString, Keys> KeyCache;
|
||||
|
||||
virtual QXmppTask<void> resetAll(CSR encryption) override;
|
||||
virtual QXmppTask<TL> trustLevel(CSR encryption, CSR keyOwnerJid, const QByteArray& keyId) override;
|
||||
|
@ -77,10 +77,10 @@ private:
|
|||
|
||||
private:
|
||||
Account* acc;
|
||||
DataBase db;
|
||||
LMDBAL::Base db;
|
||||
QFile protocols;
|
||||
DataBase::Cache<QString, uint8_t>* securityPolicies;
|
||||
DataBase::Cache<QString, QByteArray>* ownKeys;
|
||||
LMDBAL::Cache<QString, uint8_t>* securityPolicies;
|
||||
LMDBAL::Cache<QString, QByteArray>* ownKeys;
|
||||
std::map<QString, KeyCache*> keysByProtocol;
|
||||
};
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue