2023-11-10 22:26:16 +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/>.
|
|
|
|
*/
|
|
|
|
#pragma once
|
2022-09-03 11:39:42 +00:00
|
|
|
|
2023-03-02 18:17:06 +00:00
|
|
|
#include <map>
|
|
|
|
#include <list>
|
2023-03-10 18:43:31 +00:00
|
|
|
#include <functional>
|
2023-03-02 18:17:06 +00:00
|
|
|
|
2023-11-02 22:55:11 +00:00
|
|
|
#include <Omemo/QXmppOmemoStorage.h>
|
2022-12-14 23:08:08 +00:00
|
|
|
#include <cache.h>
|
|
|
|
|
2023-03-02 18:17:06 +00:00
|
|
|
#include <shared/keyinfo.h>
|
|
|
|
#include <shared/enums.h>
|
|
|
|
|
2022-12-14 23:08:08 +00:00
|
|
|
Q_DECLARE_METATYPE(QXmppOmemoStorage::OwnDevice);
|
2022-12-19 15:43:24 +00:00
|
|
|
Q_DECLARE_METATYPE(QXmppOmemoStorage::Device);
|
2022-09-03 11:39:42 +00:00
|
|
|
|
|
|
|
namespace Core {
|
2022-12-14 23:08:08 +00:00
|
|
|
class Account;
|
2022-09-03 11:39:42 +00:00
|
|
|
|
2023-03-17 20:59:51 +00:00
|
|
|
class OmemoHandler : public QObject, public QXmppOmemoStorage {
|
2023-03-10 18:43:31 +00:00
|
|
|
Q_OBJECT
|
2022-09-03 11:39:42 +00:00
|
|
|
public:
|
2022-12-28 22:41:59 +00:00
|
|
|
typedef std::pair<QDateTime, QByteArray> SignedPreKeyPair;
|
|
|
|
|
2022-12-14 23:08:08 +00:00
|
|
|
OmemoHandler(Account* account);
|
2022-09-03 11:39:42 +00:00
|
|
|
~OmemoHandler() override;
|
|
|
|
|
2023-03-02 18:17:06 +00:00
|
|
|
virtual QXmppTask<OmemoData> allData() override;
|
2022-09-03 11:39:42 +00:00
|
|
|
|
2023-03-02 18:17:06 +00:00
|
|
|
virtual QXmppTask<void> setOwnDevice(const std::optional<OwnDevice> &device) override;
|
2022-09-03 11:39:42 +00:00
|
|
|
|
2023-03-02 18:17:06 +00:00
|
|
|
virtual QXmppTask<void> addSignedPreKeyPair(uint32_t keyId, const QXmppOmemoStorage::SignedPreKeyPair &keyPair) override;
|
|
|
|
virtual QXmppTask<void> removeSignedPreKeyPair(uint32_t keyId) override;
|
2022-09-03 11:39:42 +00:00
|
|
|
|
2023-03-02 18:17:06 +00:00
|
|
|
virtual QXmppTask<void> addPreKeyPairs(const QHash<uint32_t, QByteArray> &keyPairs) override;
|
|
|
|
virtual QXmppTask<void> removePreKeyPair(uint32_t keyId) override;
|
2022-09-03 11:39:42 +00:00
|
|
|
|
2023-03-02 18:17:06 +00:00
|
|
|
virtual QXmppTask<void> addDevice(const QString &jid, uint32_t deviceId, const Device &device) override;
|
|
|
|
virtual QXmppTask<void> removeDevice(const QString &jid, uint32_t deviceId) override;
|
|
|
|
virtual QXmppTask<void> removeDevices(const QString &jid) override;
|
2022-09-03 11:39:42 +00:00
|
|
|
|
2023-03-02 18:17:06 +00:00
|
|
|
virtual QXmppTask<void> resetAll() override;
|
2022-09-03 11:39:42 +00:00
|
|
|
|
2022-12-26 22:01:01 +00:00
|
|
|
bool hasOwnDevice();
|
|
|
|
|
2023-03-10 18:43:31 +00:00
|
|
|
void requestBundles(const QString& jid);
|
|
|
|
void requestOwnBundles();
|
2023-03-02 18:17:06 +00:00
|
|
|
void getDevices(const QString& jid, std::list<Shared::KeyInfo>& out) const;
|
|
|
|
|
2023-03-15 18:17:44 +00:00
|
|
|
public slots:
|
|
|
|
void onOmemoDeviceAdded(const QString& jid, uint32_t id);
|
|
|
|
|
2023-03-10 18:43:31 +00:00
|
|
|
private slots:
|
|
|
|
void onBundlesReceived(const QString& jid);
|
|
|
|
void onOwnBundlesReceived();
|
|
|
|
|
2022-12-14 23:08:08 +00:00
|
|
|
private:
|
|
|
|
Account* acc;
|
|
|
|
std::optional<OwnDevice> ownDevice;
|
2023-03-27 18:45:29 +00:00
|
|
|
LMDBAL::Base db;
|
|
|
|
LMDBAL::Cache<QString, QVariant>* meta;
|
|
|
|
LMDBAL::Cache<QString, QHash<uint32_t, Device>>* devices;
|
|
|
|
LMDBAL::Cache<uint32_t, QByteArray>* preKeyPairs;
|
|
|
|
LMDBAL::Cache<uint32_t, SignedPreKeyPair>* signedPreKeyPairs;
|
2022-09-03 11:39:42 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
}
|
2022-12-14 23:08:08 +00:00
|
|
|
|
|
|
|
QDataStream& operator << (QDataStream &out, const QXmppOmemoStorage::Device& device);
|
2022-12-19 15:43:24 +00:00
|
|
|
QDataStream& operator >> (QDataStream &in, QXmppOmemoStorage::Device& device);
|
|
|
|
|
|
|
|
QDataStream& operator << (QDataStream &out, const QXmppOmemoStorage::OwnDevice& device);
|
|
|
|
QDataStream& operator >> (QDataStream &in, QXmppOmemoStorage::OwnDevice& device);
|