transition to LMDBAL

This commit is contained in:
Blue 2023-03-27 21:45:29 +03:00
parent 69d797fe51
commit 81cf0f8d34
Signed by untrusted user: blue
GPG key ID: 9B203B252A63EE38
18 changed files with 76 additions and 42 deletions

View file

@ -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;