forked from blue/squawk
some work towards encryption
This commit is contained in:
parent
297e08ba41
commit
a7d1a28f29
21 changed files with 129 additions and 81 deletions
|
@ -31,7 +31,6 @@ target_sources(squawk PRIVATE
|
|||
target_include_directories(squawk PRIVATE ${LMDB_INCLUDE_DIRS})
|
||||
|
||||
add_subdirectory(handlers)
|
||||
add_subdirectory(storage)
|
||||
add_subdirectory(passwordStorageEngines)
|
||||
add_subdirectory(components)
|
||||
add_subdirectory(delayManager)
|
||||
|
|
|
@ -669,6 +669,17 @@ void Core::Account::setRoomJoined(const QString& jid, bool joined) {
|
|||
conf->setJoined(joined);
|
||||
}
|
||||
|
||||
void Core::Account::setContactEncryption(const QString& jid, Shared::EncryptionProtocol value) {
|
||||
Contact* cnt = rh->getContact(jid);
|
||||
if (cnt == nullptr) {
|
||||
qDebug() << "An attempt to set encryption to the non-existing contact" << jid << "of the account" << getName() << ", skipping";
|
||||
return;
|
||||
}
|
||||
|
||||
cnt->setEncryption(value);
|
||||
}
|
||||
|
||||
|
||||
void Core::Account::discoverInfo(const QString& address, const QString& node) {
|
||||
if (state == Shared::ConnectionState::connected) {
|
||||
dm->requestInfo(address, node);
|
||||
|
|
|
@ -132,6 +132,7 @@ public:
|
|||
void removeContactFromGroupRequest(const QString& jid, const QString& groupName);
|
||||
void renameContactRequest(const QString& jid, const QString& newName);
|
||||
void requestChangeMessage(const QString& jid, const QString& messageId, const QMap<QString, QVariant>& data);
|
||||
void setContactEncryption(const QString& jid, Shared::EncryptionProtocol value);
|
||||
|
||||
void setRoomJoined(const QString& jid, bool joined);
|
||||
void setRoomAutoJoin(const QString& jid, bool joined);
|
||||
|
|
|
@ -2,12 +2,14 @@ set(SOURCE_FILES
|
|||
networkaccess.cpp
|
||||
clientcache.cpp
|
||||
urlstorage.cpp
|
||||
archive.cpp
|
||||
)
|
||||
|
||||
set(HEADER_FILES
|
||||
networkaccess.h
|
||||
clientcache.h
|
||||
urlstorage.h
|
||||
archive.h
|
||||
)
|
||||
|
||||
target_sources(squawk PRIVATE
|
||||
|
|
|
@ -17,12 +17,11 @@
|
|||
*/
|
||||
|
||||
#include "archive.h"
|
||||
|
||||
#include <sys/stat.h>
|
||||
#include <sys/types.h>
|
||||
#include <QStandardPaths>
|
||||
|
||||
#include <QDebug>
|
||||
#include <QDataStream>
|
||||
#include <QDir>
|
||||
|
||||
Core::Archive::Archive(const QString& account, const QString& p_jid, QObject* parent):
|
||||
QObject(parent),
|
||||
|
@ -262,23 +261,23 @@ void Core::Archive::setFromTheBeginning(bool is) {
|
|||
stats->forceRecord("fromTheBeginning", is);
|
||||
}
|
||||
|
||||
bool Core::Archive::isEncryptionEnabled() const {
|
||||
Shared::EncryptionProtocol Core::Archive::encryption() const {
|
||||
try {
|
||||
return stats->getRecord("isEncryptionEnabled").toBool();
|
||||
return stats->getRecord("encryption").value<Shared::EncryptionProtocol>();
|
||||
} catch (const LMDBAL::NotFound& e) {
|
||||
return false;
|
||||
return Shared::EncryptionProtocol::none;
|
||||
}
|
||||
}
|
||||
|
||||
bool Core::Archive::setEncryptionEnabled(bool is) {
|
||||
bool Core::Archive::setEncryption(Shared::EncryptionProtocol is) {
|
||||
LMDBAL::WriteTransaction txn = db.beginTransaction();
|
||||
bool current = false;
|
||||
Shared::EncryptionProtocol current = Shared::EncryptionProtocol::none;
|
||||
try {
|
||||
current = stats->getRecord("isEncryptionEnabled", txn).toBool();
|
||||
current = stats->getRecord("encryption", txn).value<Shared::EncryptionProtocol>();
|
||||
} catch (const LMDBAL::NotFound& e) {}
|
||||
|
||||
if (is != current) {
|
||||
stats->forceRecord("isEncryptionEnabled", is, txn);
|
||||
stats->forceRecord("encryption", static_cast<uint8_t>(is), txn);
|
||||
txn.commit();
|
||||
return true;
|
||||
}
|
|
@ -23,7 +23,9 @@
|
|||
#include <QCryptographicHash>
|
||||
#include <QMimeDatabase>
|
||||
#include <QMimeType>
|
||||
#include <QDataStream>
|
||||
|
||||
#include "shared/enums.h"
|
||||
#include "shared/message.h"
|
||||
#include "shared/exception.h"
|
||||
#include <lmdb.h>
|
||||
|
@ -60,8 +62,8 @@ public:
|
|||
std::list<Shared::Message> getBefore(unsigned int count, const QString& id);
|
||||
bool isFromTheBeginning() const;
|
||||
void setFromTheBeginning(bool is);
|
||||
bool isEncryptionEnabled() const;
|
||||
bool setEncryptionEnabled(bool is); //returns true if changed, false otherwise
|
||||
Shared::EncryptionProtocol encryption() const;
|
||||
bool setEncryption(Shared::EncryptionProtocol value); //returns true if changed, false otherwise
|
||||
bool setAvatar(const QByteArray& data, AvatarInfo& info, bool generated = false, const QString& resource = "");
|
||||
AvatarInfo getAvatarInfo(const QString& resource = "") const;
|
||||
bool readAvatarInfo(AvatarInfo& target, const QString& resource = "") const;
|
|
@ -225,7 +225,7 @@ void Core::RosterHandler::onContactGroupAdded(const QString& group) {
|
|||
#if (QXMPP_VERSION) >= QT_VERSION_CHECK(1, 5, 0)
|
||||
{"trust", QVariant::fromValue(acc->th->getSummary(contact->jid))},
|
||||
#endif
|
||||
{"encryption", contact->isEncryptionEnabled()}
|
||||
{"encryption", QVariant::fromValue(contact->encryption())}
|
||||
});
|
||||
addToGroup(contact->jid, group);
|
||||
emit acc->addContact(contact->jid, group, cData);
|
||||
|
@ -246,9 +246,9 @@ void Core::RosterHandler::onContactNameChanged(const QString& cname) {
|
|||
emit acc->changeContact(contact->jid, {{"name", cname}});
|
||||
}
|
||||
|
||||
void Core::RosterHandler::onContactEncryptionChanged(bool value) {
|
||||
void Core::RosterHandler::onContactEncryptionChanged(Shared::EncryptionProtocol value) {
|
||||
RosterItem* contact = static_cast<RosterItem*>(sender());
|
||||
emit acc->changeContact(contact->jid, {{"encryption", value}});
|
||||
emit acc->changeContact(contact->jid, {{"encryption", QVariant::fromValue(value)}});
|
||||
}
|
||||
|
||||
void Core::RosterHandler::onContactSubscriptionStateChanged(Shared::SubscriptionState cstate) {
|
||||
|
@ -328,7 +328,7 @@ Core::Contact * Core::RosterHandler::addOutOfRosterContact(const QString& jid) {
|
|||
cnt->setSubscriptionState(Shared::SubscriptionState::unknown);
|
||||
emit acc->addContact(lcJid, "", QMap<QString, QVariant>({
|
||||
{"state", QVariant::fromValue(Shared::SubscriptionState::unknown)},
|
||||
{"encryption", false}
|
||||
{"encryption", QVariant::fromValue(Shared::EncryptionProtocol::none)}
|
||||
}));
|
||||
handleNewContact(cnt);
|
||||
return cnt;
|
||||
|
@ -361,9 +361,9 @@ void Core::RosterHandler::onRosterItemRemoved(const QString& bareJid) {
|
|||
Contact* contact = itr->second;
|
||||
contacts.erase(itr);
|
||||
QSet<QString> cGroups = contact->getGroups();
|
||||
for (QSet<QString>::const_iterator itr = cGroups.begin(), end = cGroups.end(); itr != end; ++itr) {
|
||||
removeFromGroup(lcJid, *itr);
|
||||
}
|
||||
for (const QString& group : cGroups)
|
||||
removeFromGroup(lcJid, group);
|
||||
|
||||
emit acc->removeContact(lcJid);
|
||||
|
||||
contact->deleteLater();
|
||||
|
|
|
@ -95,7 +95,7 @@ private slots:
|
|||
void onContactNameChanged(const QString& name);
|
||||
void onContactSubscriptionStateChanged(Shared::SubscriptionState state);
|
||||
void onContactAvatarChanged(Shared::Avatar, const QString& path);
|
||||
void onContactEncryptionChanged(bool value);
|
||||
void onContactEncryptionChanged(Shared::EncryptionProtocol value);
|
||||
void onPepSupportedChanged(Shared::Support support);
|
||||
|
||||
private:
|
||||
|
|
|
@ -561,12 +561,12 @@ Shared::Message Core::RosterItem::getMessage(const QString& id) {
|
|||
return archive->getElement(id);
|
||||
}
|
||||
|
||||
bool Core::RosterItem::isEncryptionEnabled() const {
|
||||
return archive->isEncryptionEnabled();
|
||||
Shared::EncryptionProtocol Core::RosterItem::encryption() const {
|
||||
return archive->encryption();
|
||||
}
|
||||
|
||||
void Core::RosterItem::enableEncryption(bool value) {
|
||||
bool changed = archive->setEncryptionEnabled(value);
|
||||
void Core::RosterItem::setEncryption(Shared::EncryptionProtocol value) {
|
||||
bool changed = archive->setEncryption(value);
|
||||
if (changed)
|
||||
emit encryptionChanged(value);
|
||||
}
|
||||
|
@ -574,7 +574,7 @@ void Core::RosterItem::enableEncryption(bool value) {
|
|||
QMap<QString, QVariant> Core::RosterItem::getInfo() const {
|
||||
QMap<QString, QVariant> result({
|
||||
{"name", name},
|
||||
{"encryption", isEncryptionEnabled()},
|
||||
{"encryption", QVariant::fromValue(encryption())},
|
||||
});
|
||||
Archive::AvatarInfo info;
|
||||
bool hasAvatar = readAvatarInfo(info);
|
||||
|
|
|
@ -34,7 +34,7 @@
|
|||
#include "shared/enums.h"
|
||||
#include "shared/message.h"
|
||||
#include "shared/vcard.h"
|
||||
#include "storage/archive.h"
|
||||
#include "components/archive.h"
|
||||
#include "adapterfunctions.h"
|
||||
|
||||
namespace Core {
|
||||
|
@ -62,8 +62,8 @@ public:
|
|||
void setName(const QString& n);
|
||||
QString getServer() const;
|
||||
bool isMuc() const;
|
||||
bool isEncryptionEnabled() const;
|
||||
void enableEncryption(bool value = true);
|
||||
Shared::EncryptionProtocol encryption() const;
|
||||
void setEncryption(Shared::EncryptionProtocol value);
|
||||
|
||||
void addMessageToArchive(const Shared::Message& msg);
|
||||
void correctMessageInArchive(const QString& originalId, const Shared::Message& msg);
|
||||
|
@ -91,7 +91,7 @@ signals:
|
|||
void needHistory(const QString& before, const QString& after, const QDateTime& afterTime = QDateTime()) const;
|
||||
void avatarChanged(Shared::Avatar, const QString& path) const;
|
||||
void requestVCard(const QString& jid) const;
|
||||
void encryptionChanged(bool value) const;
|
||||
void encryptionChanged(Shared::EncryptionProtocol value) const;
|
||||
|
||||
public:
|
||||
const QString jid;
|
||||
|
|
|
@ -590,6 +590,15 @@ void Core::Squawk::setRoomAutoJoin(const QString& account, const QString& jid, b
|
|||
itr->second->setRoomAutoJoin(jid, joined);
|
||||
}
|
||||
|
||||
void Core::Squawk::setContactEncryption(const QString& account, const QString& jid, Shared::EncryptionProtocol value) {
|
||||
AccountsMap::const_iterator itr = amap.find(account);
|
||||
if (itr == amap.end()) {
|
||||
qDebug() << "An attempt to set encryption to the contact" << jid << "of non existing account" << account << ", skipping";
|
||||
return;
|
||||
}
|
||||
itr->second->setContactEncryption(jid, value);
|
||||
}
|
||||
|
||||
void Core::Squawk::onAccountAddRoomPresence(const QString& jid, const QString& nick, const QMap<QString, QVariant>& data) {
|
||||
Account* acc = static_cast<Account*>(sender());
|
||||
emit addRoomParticipant(acc->getName(), jid, nick, data);
|
||||
|
|
|
@ -116,6 +116,7 @@ public slots:
|
|||
void removeContactRequest(const QString& account, const QString& jid);
|
||||
void renameContactRequest(const QString& account, const QString& jid, const QString& newName);
|
||||
void addContactRequest(const QString& account, const QString& jid, const QString& name, const QSet<QString>& groups);
|
||||
void setContactEncryption(const QString& account, const QString& jid, Shared::EncryptionProtocol value);
|
||||
|
||||
void setRoomJoined(const QString& account, const QString& jid, bool joined);
|
||||
void setRoomAutoJoin(const QString& account, const QString& jid, bool joined);
|
||||
|
|
|
@ -1,4 +0,0 @@
|
|||
target_sources(squawk PRIVATE
|
||||
archive.cpp
|
||||
archive.h
|
||||
)
|
Loading…
Add table
Add a link
Reference in a new issue