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
|
@ -21,4 +21,5 @@ target_sources(squawk PRIVATE
|
|||
clientinfo.h
|
||||
clientinfo.cpp
|
||||
identity.h
|
||||
identity.cpp
|
||||
)
|
||||
|
|
|
@ -16,30 +16,42 @@
|
|||
|
||||
#include "clientinfo.h"
|
||||
|
||||
const std::map<QString, QCryptographicHash::Algorithm> Shared::ClientInfo::hashes = {
|
||||
//md2 is missing
|
||||
{"md5", QCryptographicHash::Md5},
|
||||
{"sha-1", QCryptographicHash::Sha1},
|
||||
{"sha-224", QCryptographicHash::Sha224},
|
||||
{"sha-256", QCryptographicHash::Sha256},
|
||||
{"sha-384", QCryptographicHash::Sha384},
|
||||
{"sha-512", QCryptographicHash::Sha512},
|
||||
//shake128 is missing
|
||||
//shake256 is missing
|
||||
|
||||
};
|
||||
|
||||
Shared::ClientInfo::ClientInfo():
|
||||
name(),
|
||||
category(),
|
||||
type(),
|
||||
capabilitiesNode(),
|
||||
capabilitiesVerification(),
|
||||
capabilitiesHash(),
|
||||
specificPresence(),
|
||||
capabilitiesExtensions() {}
|
||||
identities(),
|
||||
extensions(),
|
||||
node(),
|
||||
verification(),
|
||||
hash(),
|
||||
specificPresence() {}
|
||||
|
||||
QString Shared::ClientInfo::getId() const {
|
||||
return capabilitiesNode + "/" + capabilitiesVerification;
|
||||
return node + "/" + verification;
|
||||
}
|
||||
|
||||
|
||||
QDataStream & Shared::ClientInfo::operator >> (QDataStream& stream) const {
|
||||
stream << name;
|
||||
stream << category;
|
||||
stream << type;
|
||||
stream << capabilitiesNode;
|
||||
stream << capabilitiesVerification;
|
||||
stream << capabilitiesHash;
|
||||
stream << (quint8)capabilitiesExtensions.size();
|
||||
for (const QString& ext : capabilitiesExtensions) {
|
||||
stream << node;
|
||||
stream << verification;
|
||||
stream << hash;
|
||||
stream << (quint8)identities.size();
|
||||
for (const Shared::Identity& identity : identities) {
|
||||
stream << identity;
|
||||
}
|
||||
stream << (quint8)extensions.size();
|
||||
for (const QString& ext : extensions) {
|
||||
stream << ext;
|
||||
}
|
||||
|
||||
|
@ -47,29 +59,53 @@ QDataStream & Shared::ClientInfo::operator >> (QDataStream& stream) const {
|
|||
}
|
||||
|
||||
QDataStream & Shared::ClientInfo::operator << (QDataStream& stream) {
|
||||
stream >> name;
|
||||
stream >> category;
|
||||
stream >> type;
|
||||
stream >> capabilitiesNode;
|
||||
stream >> capabilitiesVerification;
|
||||
stream >> capabilitiesHash;
|
||||
stream >> node;
|
||||
stream >> verification;
|
||||
stream >> hash;
|
||||
|
||||
quint8 size;
|
||||
stream >> size;
|
||||
for (quint8 i = 0; i < size; ++i) {
|
||||
Shared::Identity identity;
|
||||
stream >> identity;
|
||||
identities.insert(identity);
|
||||
}
|
||||
|
||||
stream >> size;
|
||||
for (quint8 i = 0; i < size; ++i) {
|
||||
QString ext;
|
||||
stream >> ext;
|
||||
capabilitiesExtensions.insert(ext);
|
||||
extensions.insert(ext);
|
||||
}
|
||||
|
||||
return stream;
|
||||
}
|
||||
|
||||
QDataStream& operator<< (QDataStream& stream, const Shared::ClientInfo& image) {
|
||||
image >> stream;
|
||||
bool Shared::ClientInfo::valid() const {
|
||||
std::map<QString, QCryptographicHash::Algorithm>::const_iterator itr = hashes.find(hash);
|
||||
if (itr == hashes.end()) {
|
||||
return false;
|
||||
}
|
||||
|
||||
QCryptographicHash calc(itr->second);
|
||||
QString validationString = "";
|
||||
for (const Identity& identity : identities) {
|
||||
calc.addData((identity.category + "/" + identity.type + "/" + identity.language + "/" + identity.name + "<").toUtf8());
|
||||
}
|
||||
for (const QString& ext : extensions) {
|
||||
calc.addData((ext + "<").toUtf8());
|
||||
}
|
||||
|
||||
QString result = calc.result().toBase64();
|
||||
|
||||
return result == verification;
|
||||
}
|
||||
|
||||
QDataStream& operator << (QDataStream& stream, const Shared::ClientInfo& info) {
|
||||
info >> stream;
|
||||
return stream;
|
||||
}
|
||||
QDataStream& operator>> (QDataStream& stream, Shared::ClientInfo& image) {
|
||||
image << stream;
|
||||
QDataStream& operator >> (QDataStream& stream, Shared::ClientInfo& info) {
|
||||
info << stream;
|
||||
return stream;
|
||||
}
|
||||
|
|
|
@ -21,6 +21,9 @@
|
|||
|
||||
#include <QDataStream>
|
||||
#include <QString>
|
||||
#include <QCryptographicHash>
|
||||
|
||||
#include <shared/identity.h>
|
||||
|
||||
namespace Shared {
|
||||
|
||||
|
@ -30,24 +33,26 @@ public:
|
|||
ClientInfo();
|
||||
|
||||
QString getId() const;
|
||||
bool valid() const;
|
||||
|
||||
QDataStream& operator << (QDataStream& stream);
|
||||
QDataStream& operator >> (QDataStream& stream) const;
|
||||
|
||||
public:
|
||||
QString name;
|
||||
QString category;
|
||||
QString type;
|
||||
QString capabilitiesNode;
|
||||
QString capabilitiesVerification;
|
||||
QString capabilitiesHash;
|
||||
std::set<Identity> identities;
|
||||
std::set<QString> extensions;
|
||||
QString node;
|
||||
QString verification;
|
||||
QString hash;
|
||||
QString specificPresence;
|
||||
std::set<QString> capabilitiesExtensions;
|
||||
|
||||
private:
|
||||
static const std::map<QString, QCryptographicHash::Algorithm> hashes;
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
QDataStream& operator<< (QDataStream& stream, const Shared::ClientInfo& image);
|
||||
QDataStream& operator>> (QDataStream& stream, Shared::ClientInfo& image);
|
||||
QDataStream& operator << (QDataStream& stream, const Shared::ClientInfo& info);
|
||||
QDataStream& operator >> (QDataStream& stream, Shared::ClientInfo& info);
|
||||
|
||||
#endif // SHARED_CLIENTINFO_H
|
||||
|
|
142
shared/identity.cpp
Normal file
142
shared/identity.cpp
Normal file
|
@ -0,0 +1,142 @@
|
|||
/*
|
||||
* 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 "identity.h"
|
||||
|
||||
Shared::Identity::Identity():
|
||||
category(),
|
||||
type(),
|
||||
language(),
|
||||
name() {}
|
||||
|
||||
bool Shared::Identity::operator==(const Shared::Identity& other) const {
|
||||
return category == other.category && type == other.type && language == other.language && name == other.name;
|
||||
}
|
||||
|
||||
bool Shared::Identity::operator!=(const Shared::Identity& other) const {
|
||||
return category != other.category || type != other.type || language != other.language || name != other.name;
|
||||
}
|
||||
|
||||
bool Shared::Identity::operator > (const Shared::Identity& other) const {
|
||||
if (category > other.category) {
|
||||
return true;
|
||||
} else if (category < other.category) {
|
||||
return false;
|
||||
} else if (type > other.type) {
|
||||
return true;
|
||||
} else if (type < other.type) {
|
||||
return false;
|
||||
} else if (language > other.language) {
|
||||
return true;
|
||||
} else if (language < other.language) {
|
||||
return false;
|
||||
} else if (name > other.name) {
|
||||
return true;
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
bool Shared::Identity::operator < (const Shared::Identity& other) const {
|
||||
if (category < other.category) {
|
||||
return true;
|
||||
} else if (category > other.category) {
|
||||
return false;
|
||||
} else if (type < other.type) {
|
||||
return true;
|
||||
} else if (type > other.type) {
|
||||
return false;
|
||||
} else if (language < other.language) {
|
||||
return true;
|
||||
} else if (language > other.language) {
|
||||
return false;
|
||||
} else if (name < other.name) {
|
||||
return true;
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
bool Shared::Identity::operator >= (const Shared::Identity& other) const {
|
||||
if (category > other.category) {
|
||||
return true;
|
||||
} else if (category < other.category) {
|
||||
return false;
|
||||
} else if (type > other.type) {
|
||||
return true;
|
||||
} else if (type < other.type) {
|
||||
return false;
|
||||
} else if (language > other.language) {
|
||||
return true;
|
||||
} else if (language < other.language) {
|
||||
return false;
|
||||
} else if (name > other.name) {
|
||||
return true;
|
||||
} else if (name < other.name) {
|
||||
return false;
|
||||
} else {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
bool Shared::Identity::operator <= (const Shared::Identity& other) const {
|
||||
if (category < other.category) {
|
||||
return true;
|
||||
} else if (category > other.category) {
|
||||
return false;
|
||||
} else if (type < other.type) {
|
||||
return true;
|
||||
} else if (type > other.type) {
|
||||
return false;
|
||||
} else if (language < other.language) {
|
||||
return true;
|
||||
} else if (language > other.language) {
|
||||
return false;
|
||||
} else if (name < other.name) {
|
||||
return true;
|
||||
} else if (name > other.name) {
|
||||
return false;
|
||||
} else {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
QDataStream & Shared::Identity::operator >> (QDataStream& stream) const {
|
||||
stream << category;
|
||||
stream << type;
|
||||
stream << language;
|
||||
stream << name;
|
||||
}
|
||||
|
||||
QDataStream & Shared::Identity::operator << (QDataStream& stream) {
|
||||
stream >> category;
|
||||
stream >> type;
|
||||
stream >> language;
|
||||
stream >> name;
|
||||
}
|
||||
|
||||
QDataStream & operator >> (QDataStream& stream, Shared::Identity& identity) {
|
||||
identity << stream;
|
||||
return stream;
|
||||
}
|
||||
|
||||
QDataStream & operator << (QDataStream& stream, const Shared::Identity& identity) {
|
||||
identity >> stream;
|
||||
return stream;
|
||||
}
|
||||
|
|
@ -19,17 +19,34 @@
|
|||
#ifndef SHARED_IDENTITY_H
|
||||
#define SHARED_IDENTITY_H
|
||||
|
||||
#include <QDataStream>
|
||||
#include <QString>
|
||||
|
||||
namespace Shared {
|
||||
|
||||
struct Identity {
|
||||
class Identity {
|
||||
public:
|
||||
Identity();
|
||||
|
||||
QDataStream& operator << (QDataStream& stream);
|
||||
QDataStream& operator >> (QDataStream& stream) const;
|
||||
|
||||
bool operator < (const Identity& other) const;
|
||||
bool operator > (const Identity& other) const;
|
||||
bool operator >= (const Identity& other) const;
|
||||
bool operator <= (const Identity& other) const;
|
||||
bool operator == (const Identity& other) const;
|
||||
bool operator != (const Identity& other) const;
|
||||
public:
|
||||
QString category;
|
||||
QString type;
|
||||
QString language;
|
||||
QString name;
|
||||
QString type;
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
QDataStream& operator << (QDataStream& stream, const Shared::Identity& identity);
|
||||
QDataStream& operator >> (QDataStream& stream, Shared::Identity& identity);
|
||||
|
||||
#endif //SHARED_IDENTITY_H
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue