forked from blue/squawk
first ever received and cached client data!
This commit is contained in:
parent
037dabbe06
commit
c50cd1140e
11 changed files with 297 additions and 60 deletions
|
@ -634,16 +634,16 @@ void Core::Account::onDiscoveryInfoReceived(const QXmppDiscoveryIq& info)
|
|||
QString node = info.queryNode();
|
||||
if (!node.isEmpty()) {
|
||||
QStringList feats = info.features();
|
||||
std::list<Shared::Identity> identities;
|
||||
std::set<Shared::Identity> identities;
|
||||
std::set<QString> features(feats.begin(), feats.end());
|
||||
QList<QXmppDiscoveryIq::Identity> idents = info.identities();
|
||||
for (const QXmppDiscoveryIq::Identity& ident : idents) {
|
||||
identities.emplace_back();
|
||||
Shared::Identity& identity = identities.back();
|
||||
Shared::Identity identity;
|
||||
identity.category = ident.category();
|
||||
identity.language = ident.language();
|
||||
identity.name = ident.name();
|
||||
identity.type = ident.type();
|
||||
identities.insert(identity);
|
||||
|
||||
qDebug() << " " << identity.name << identity.category << identity.type;
|
||||
}
|
||||
|
@ -655,6 +655,16 @@ void Core::Account::onDiscoveryInfoReceived(const QXmppDiscoveryIq& info)
|
|||
}
|
||||
}
|
||||
|
||||
void Core::Account::discoverInfo(const QString& address, const QString& node) {
|
||||
if (state == Shared::ConnectionState::connected) {
|
||||
dm->requestInfo(address, node);
|
||||
} else {
|
||||
qDebug() << "An attempt to send a discover info by account" << name <<
|
||||
"sending request to" << address << "about node" << node <<
|
||||
"but the account is not in the connected state, skipping";
|
||||
}
|
||||
}
|
||||
|
||||
void Core::Account::handleDisconnection()
|
||||
{
|
||||
cm->setCarbonsEnabled(false);
|
||||
|
|
|
@ -155,7 +155,7 @@ signals:
|
|||
void uploadFile(const QFileInfo& file, const QUrl& set, const QUrl& get, QMap<QString, QString> headers);
|
||||
void uploadFileError(const QString& jid, const QString& messageId, const QString& error);
|
||||
void needPassword();
|
||||
void infoDiscovered(const QString& address, const QString& node, const std::list<Shared::Identity>& identities, const std::set<QString>& features);
|
||||
void infoDiscovered(const QString& address, const QString& node, const std::set<Shared::Identity>& identities, const std::set<QString>& features);
|
||||
|
||||
private:
|
||||
QString name;
|
||||
|
|
|
@ -14,12 +14,14 @@
|
|||
// 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"
|
||||
|
||||
#include <QDebug>
|
||||
|
||||
Core::ClientCache::ClientCache():
|
||||
requested(),
|
||||
cache("clients")
|
||||
cache("clients"),
|
||||
specific()
|
||||
{
|
||||
cache.open();
|
||||
}
|
||||
|
@ -39,9 +41,9 @@ bool Core::ClientCache::checkClient(const QString& node, const QString& ver, con
|
|||
QString id = node + "/" + ver;
|
||||
if (requested.count(id) == 0 && !cache.checkRecord(id)) {
|
||||
Shared::ClientInfo& info = requested.insert(std::make_pair(id, Shared::ClientInfo())).first->second;
|
||||
info.capabilitiesNode = node;
|
||||
info.capabilitiesVerification = ver;
|
||||
info.capabilitiesHash = hash;
|
||||
info.node = node;
|
||||
info.verification = ver;
|
||||
info.hash = hash;
|
||||
emit requestClientInfo(id);
|
||||
return false;
|
||||
}
|
||||
|
@ -49,7 +51,28 @@ bool Core::ClientCache::checkClient(const QString& node, const QString& ver, con
|
|||
return true;
|
||||
}
|
||||
|
||||
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;
|
||||
|
||||
bool Core::ClientCache::registerClientInfo(const QString& sourceFullJid, const QString& id, const Shared::Identity& identity, const std::set<QString>& features) {
|
||||
|
||||
bool valid = info.valid();
|
||||
if (valid) {
|
||||
cache.addRecord(id, info);
|
||||
} else {
|
||||
info.specificPresence = sourceFullJid;
|
||||
specific.insert(std::make_pair(sourceFullJid, info));
|
||||
}
|
||||
requested.erase(id);
|
||||
return valid;
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -43,11 +43,12 @@ signals:
|
|||
|
||||
public slots:
|
||||
bool checkClient(const QString& node, const QString& ver, const QString& hash);
|
||||
bool registerClientInfo(const QString& sourceFullJid, const QString& id, const Shared::Identity& identity, const std::set<QString>& features);
|
||||
bool registerClientInfo(const QString& sourceFullJid, const QString& id, const std::set<Shared::Identity>& identities, const std::set<QString>& features);
|
||||
|
||||
private:
|
||||
std::map<QString, Shared::ClientInfo> requested;
|
||||
Cache<Shared::ClientInfo> cache;
|
||||
std::map<QString, Shared::ClientInfo> specific;
|
||||
};
|
||||
|
||||
}
|
||||
|
|
|
@ -320,25 +320,27 @@ void Core::Squawk::onAccountAddPresence(const QString& jid, const QString& name,
|
|||
Account* acc = static_cast<Account*>(sender());
|
||||
emit addPresence(acc->getName(), jid, name, data);
|
||||
|
||||
QString node = data["capabilityNode"].toString();
|
||||
QString ver = data["capabilityVer"].toString();
|
||||
QString hash = data["capabilityHash"].toString();
|
||||
if (!clientCache.checkClient(node, ver, hash)) {
|
||||
acc->discoverInfo(jid + "/" + name, node + "/" + ver);
|
||||
//it's equal if a MUC sends its status with presence of the same jid (ex: muc@srv.im/muc@srv.im), it's not a client, so, no need to request
|
||||
if (jid != name) {
|
||||
QString node = data["capabilityNode"].toString();
|
||||
QString ver = data["capabilityVer"].toString();
|
||||
QString hash = data["capabilityHash"].toString();
|
||||
if (!clientCache.checkClient(node, ver, hash)) {
|
||||
acc->discoverInfo(jid + "/" + name, node + "/" + ver);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void Core::Squawk::onAccountInfoDiscovered(
|
||||
const QString& address,
|
||||
const QString& node,
|
||||
const std::list<Shared::Identity>& identities,
|
||||
const std::set<Shared::Identity>& identities,
|
||||
const std::set<QString>& features)
|
||||
{
|
||||
Account* acc = static_cast<Account*>(sender());
|
||||
|
||||
if (identities.size() != 1 || clientCache.registerClientInfo(address, node, identities.back(), features)) {
|
||||
if (!clientCache.registerClientInfo(address, node, identities, features)) {
|
||||
qDebug() << "Account" << acc->getName() << "received an ill-formed client discovery response from" << address << "about" << node;
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -183,7 +183,7 @@ private slots:
|
|||
void onWalletOpened(bool success);
|
||||
void onWalletRejectPassword(const QString& login);
|
||||
|
||||
void onAccountInfoDiscovered(const QString& address, const QString& node, const std::list<Shared::Identity>& identities, const std::set<QString>& features);
|
||||
void onAccountInfoDiscovered(const QString& address, const QString& node, const std::set<Shared::Identity>& identities, const std::set<QString>& features);
|
||||
|
||||
private:
|
||||
void readSettings();
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue