tdesktop/Telegram/SourceFiles/mtproto/special_config_request.h

83 lines
1.9 KiB
C
Raw Normal View History

2017-06-26 17:38:16 +00:00
/*
This file is part of Telegram Desktop,
the official desktop application for the Telegram messaging service.
2017-06-26 17:38:16 +00:00
For license and copyright information please follow this link:
https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
2017-06-26 17:38:16 +00:00
*/
#pragma once
2019-12-02 13:10:19 +00:00
#include "mtproto/details/mtproto_domain_resolver.h"
2018-05-02 19:27:03 +00:00
#include "base/bytes.h"
2019-12-02 13:10:19 +00:00
#include "base/weak_ptr.h"
2018-05-02 19:27:03 +00:00
2019-12-02 13:10:19 +00:00
#include <QtCore/QPointer>
2019-09-04 07:19:15 +00:00
#include <QtNetwork/QNetworkReply>
#include <QtNetwork/QNetworkAccessManager>
2019-12-02 13:10:19 +00:00
namespace MTP::details {
2017-06-26 17:38:16 +00:00
class SpecialConfigRequest : public QObject {
public:
SpecialConfigRequest(
Fn<void(
DcId dcId,
const std::string &ip,
2018-05-02 19:27:03 +00:00
int port,
bytes::const_span secret)> callback,
const QString &domainString,
2018-05-02 19:27:03 +00:00
const QString &phone);
SpecialConfigRequest(
Fn<void()> timeDoneCallback,
const QString &domainString);
2017-06-26 17:38:16 +00:00
private:
enum class Type {
2019-10-01 17:42:18 +00:00
Mozilla,
Google,
RemoteConfig,
Realtime,
FireStore,
};
struct Attempt {
Type type;
2019-10-01 17:42:18 +00:00
QString data;
QString host;
};
SpecialConfigRequest(
Fn<void(
DcId dcId,
const std::string &ip,
int port,
bytes::const_span secret)> callback,
Fn<void()> timeDoneCallback,
const QString &domainString,
const QString &phone);
void sendNextRequest();
void performRequest(const Attempt &attempt);
void requestFinished(Type type, not_null<QNetworkReply*> reply);
void handleHeaderUnixtime(not_null<QNetworkReply*> reply);
QByteArray finalizeRequest(not_null<QNetworkReply*> reply);
2017-06-26 17:38:16 +00:00
void handleResponse(const QByteArray &bytes);
bool decryptSimpleConfig(const QByteArray &bytes);
Fn<void(
DcId dcId,
const std::string &ip,
2018-05-02 19:27:03 +00:00
int port,
bytes::const_span secret)> _callback;
Fn<void()> _timeDoneCallback;
QString _domainString;
2018-05-02 19:27:03 +00:00
QString _phone;
2017-06-26 17:38:16 +00:00
MTPhelp_ConfigSimple _simpleConfig;
QNetworkAccessManager _manager;
std::vector<Attempt> _attempts;
std::vector<ServiceWebRequest> _requests;
};
2019-12-02 13:10:19 +00:00
} // namespace MTP::details