2022-08-22 20:29:43 +00:00
|
|
|
// Squawk messenger.
|
|
|
|
// Copyright (C) 2019 Yury Gubich <blue@macaw.me>
|
|
|
|
//
|
|
|
|
// This program is free software: you can redistribute it and/or modify
|
|
|
|
// it under the terms of the GNU General Public License as published by
|
|
|
|
// the Free Software Foundation, either version 3 of the License, or
|
|
|
|
// (at your option) any later version.
|
|
|
|
//
|
|
|
|
// This program is distributed in the hope that it will be useful,
|
|
|
|
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
// GNU General Public License for more details.
|
|
|
|
//
|
|
|
|
// You should have received a copy of the GNU General Public License
|
|
|
|
// along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
|
|
|
|
#include "clientcache.h"
|
|
|
|
|
2022-08-24 22:41:06 +00:00
|
|
|
#include <QDebug>
|
|
|
|
|
2022-08-22 20:29:43 +00:00
|
|
|
Core::ClientCache::ClientCache():
|
2022-12-19 15:43:24 +00:00
|
|
|
db("clients"),
|
|
|
|
cache(db.addCache<QString, Shared::ClientInfo>("info")),
|
2022-08-22 20:29:43 +00:00
|
|
|
requested(),
|
2022-08-24 22:41:06 +00:00
|
|
|
specific()
|
2022-08-22 20:29:43 +00:00
|
|
|
{
|
2022-12-19 15:43:24 +00:00
|
|
|
db.open();
|
2022-08-22 20:29:43 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
Core::ClientCache::~ClientCache() {
|
2022-12-19 15:43:24 +00:00
|
|
|
db.close();
|
2022-08-22 20:29:43 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void Core::ClientCache::open() {
|
2022-12-19 15:43:24 +00:00
|
|
|
db.open();}
|
2022-08-22 20:29:43 +00:00
|
|
|
|
|
|
|
void Core::ClientCache::close() {
|
2022-12-19 15:43:24 +00:00
|
|
|
db.close();}
|
2022-08-22 20:29:43 +00:00
|
|
|
|
|
|
|
|
|
|
|
bool Core::ClientCache::checkClient(const QString& node, const QString& ver, const QString& hash) {
|
|
|
|
QString id = node + "/" + ver;
|
2022-12-19 15:43:24 +00:00
|
|
|
if (requested.count(id) == 0 && !cache->checkRecord(id)) {
|
2022-08-22 20:29:43 +00:00
|
|
|
Shared::ClientInfo& info = requested.insert(std::make_pair(id, Shared::ClientInfo())).first->second;
|
2023-03-13 19:07:10 +00:00
|
|
|
info.id.node = node;
|
|
|
|
info.id.verification = ver;
|
|
|
|
info.id.hash = hash;
|
2022-08-22 20:29:43 +00:00
|
|
|
emit requestClientInfo(id);
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2022-08-24 22:41:06 +00:00
|
|
|
bool Core::ClientCache::registerClientInfo (
|
|
|
|
const QString& sourceFullJid,
|
|
|
|
const QString& id,
|
|
|
|
const std::set<Shared::Identity>& identities,
|
|
|
|
const std::set<QString>& features)
|
|
|
|
{
|
|
|
|
std::map<QString, Shared::ClientInfo>::iterator itr = requested.find(id);
|
|
|
|
if (itr != requested.end()) {
|
|
|
|
Shared::ClientInfo& info = itr->second;
|
|
|
|
info.identities = identities;
|
|
|
|
info.extensions = features;
|
2022-08-22 20:29:43 +00:00
|
|
|
|
2022-08-24 22:41:06 +00:00
|
|
|
bool valid = info.valid();
|
|
|
|
if (valid) {
|
2022-12-19 15:43:24 +00:00
|
|
|
cache->addRecord(id, info);
|
2022-08-24 22:41:06 +00:00
|
|
|
} else {
|
|
|
|
info.specificPresence = sourceFullJid;
|
|
|
|
specific.insert(std::make_pair(sourceFullJid, info));
|
|
|
|
}
|
|
|
|
requested.erase(id);
|
|
|
|
return valid;
|
|
|
|
} else {
|
|
|
|
return false;
|
|
|
|
}
|
2022-08-22 20:29:43 +00:00
|
|
|
}
|