From 76a9c5da0cf734e854e2dc49af47ad2e8a4394d4 Mon Sep 17 00:00:00 2001 From: blue Date: Mon, 13 Mar 2023 22:07:10 +0300 Subject: [PATCH] extracted clientId from clientInfo to use it in the presence information later --- core/components/clientcache.cpp | 6 ++-- shared/CMakeLists.txt | 46 +++++++++++++++++------------ shared/clientid.cpp | 52 +++++++++++++++++++++++++++++++++ shared/clientid.h | 45 ++++++++++++++++++++++++++++ shared/clientinfo.cpp | 18 ++++-------- shared/clientinfo.h | 8 ++--- 6 files changed, 137 insertions(+), 38 deletions(-) create mode 100644 shared/clientid.cpp create mode 100644 shared/clientid.h diff --git a/core/components/clientcache.cpp b/core/components/clientcache.cpp index a312b24..dfd9680 100644 --- a/core/components/clientcache.cpp +++ b/core/components/clientcache.cpp @@ -42,9 +42,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.node = node; - info.verification = ver; - info.hash = hash; + info.id.node = node; + info.id.verification = ver; + info.id.hash = hash; emit requestClientInfo(id); return false; } diff --git a/shared/CMakeLists.txt b/shared/CMakeLists.txt index 9080fb6..5db96f0 100644 --- a/shared/CMakeLists.txt +++ b/shared/CMakeLists.txt @@ -1,33 +1,43 @@ -target_sources(squawk PRIVATE - enums.h +set(SOURCE_FILES global.cpp - global.h exception.cpp - exception.h icons.cpp - icons.h message.cpp - message.h messageinfo.cpp - messageinfo.h - order.h - shared.h utils.cpp - utils.h vcard.cpp - vcard.h pathcheck.cpp - pathcheck.h - clientinfo.h clientinfo.cpp - identity.h identity.cpp - form.h form.cpp - field.h field.cpp keyinfo.cpp - keyinfo.h info.cpp + clientid.cpp +) + +set(HEADER_FILES + order.h + shared.h + enums.h + global.h + exception.h + icons.h + message.h + messageinfo.h + utils.h + vcard.h + pathcheck.h + clientinfo.h + identity.h + form.h + field.h + keyinfo.h info.h - ) + clientid.h +) + +target_sources(squawk PRIVATE + ${SOURCE_FILES} + ${HEADER_FILES} +) diff --git a/shared/clientid.cpp b/shared/clientid.cpp new file mode 100644 index 0000000..f16736c --- /dev/null +++ b/shared/clientid.cpp @@ -0,0 +1,52 @@ +// Squawk messenger. +// Copyright (C) 2019 Yury Gubich +// +// 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 . + +#include "clientid.h" + +Shared::ClientId::ClientId(): + node(), + verification(), + hash() +{} + +QString Shared::ClientId::getId() const { + return node + "/" + verification; +} + +QDataStream & Shared::ClientId::operator<<(QDataStream& stream) { + stream >> node; + stream >> verification; + stream >> hash; + return stream; +} + +QDataStream & Shared::ClientId::operator>>(QDataStream& stream) const { + stream << node; + stream << verification; + stream << hash; + return stream; +} + +QDataStream & operator<<(QDataStream& stream, const Shared::ClientId& info) { + info >> stream; + return stream; +} + +QDataStream & operator>>(QDataStream& stream, Shared::ClientId& info) { + info << stream; + return stream; +} + diff --git a/shared/clientid.h b/shared/clientid.h new file mode 100644 index 0000000..defe909 --- /dev/null +++ b/shared/clientid.h @@ -0,0 +1,45 @@ +// Squawk messenger. +// Copyright (C) 2019 Yury Gubich +// +// 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 . + +#ifndef SHARED_CLIENTID_H +#define SHARED_CLIENTID_H + +#include +#include + +namespace Shared { + +class ClientId { +public: + ClientId(); + + QString getId() const; + + QDataStream& operator << (QDataStream& stream); + QDataStream& operator >> (QDataStream& stream) const; + +public: + QString node; + QString verification; + QString hash; +}; + +} + +QDataStream& operator << (QDataStream& stream, const Shared::ClientId& info); +QDataStream& operator >> (QDataStream& stream, Shared::ClientId& info); + +#endif // SHARED_CLIENTID_H diff --git a/shared/clientinfo.cpp b/shared/clientinfo.cpp index 86af1c8..9a3fdac 100644 --- a/shared/clientinfo.cpp +++ b/shared/clientinfo.cpp @@ -32,20 +32,16 @@ const std::map Shared::ClientInfo::hashe Shared::ClientInfo::ClientInfo(): identities(), extensions(), - node(), - verification(), - hash(), + id(), specificPresence() {} QString Shared::ClientInfo::getId() const { - return node + "/" + verification; + return id.getId(); } QDataStream & Shared::ClientInfo::operator >> (QDataStream& stream) const { - stream << node; - stream << verification; - stream << hash; + stream << id; stream << (quint8)identities.size(); for (const Shared::Identity& identity : identities) { stream << identity; @@ -59,9 +55,7 @@ QDataStream & Shared::ClientInfo::operator >> (QDataStream& stream) const { } QDataStream & Shared::ClientInfo::operator << (QDataStream& stream) { - stream >> node; - stream >> verification; - stream >> hash; + stream >> id; quint8 size; stream >> size; @@ -82,7 +76,7 @@ QDataStream & Shared::ClientInfo::operator << (QDataStream& stream) { } bool Shared::ClientInfo::valid() const { - std::map::const_iterator itr = hashes.find(hash); + std::map::const_iterator itr = hashes.find(id.hash); if (itr == hashes.end()) { return false; } @@ -98,7 +92,7 @@ bool Shared::ClientInfo::valid() const { QString result = calc.result().toBase64(); - return result == verification; + return result == id.verification; } QDataStream& operator << (QDataStream& stream, const Shared::ClientInfo& info) { diff --git a/shared/clientinfo.h b/shared/clientinfo.h index 53c7dd0..8e95180 100644 --- a/shared/clientinfo.h +++ b/shared/clientinfo.h @@ -24,11 +24,11 @@ #include #include +#include namespace Shared { -class ClientInfo -{ +class ClientInfo { public: ClientInfo(); @@ -41,9 +41,7 @@ public: public: std::set identities; std::set extensions; - QString node; - QString verification; - QString hash; + ClientId id; QString specificPresence; private: