2023-11-14 23:23:39 +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/>.
|
|
|
|
*/
|
2022-08-22 20:29:43 +00:00
|
|
|
|
|
|
|
#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
|
|
|
|
2023-03-14 19:49:58 +00:00
|
|
|
bool Core::ClientCache::checkClient(const Shared::ClientId& p_id) {
|
|
|
|
QString id = p_id.getId();
|
2022-12-19 15:43:24 +00:00
|
|
|
if (requested.count(id) == 0 && !cache->checkRecord(id)) {
|
2023-03-14 19:49:58 +00:00
|
|
|
requested.emplace(id, p_id);
|
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
|
|
|
}
|