2017-06-26 17:38:16 +00:00
|
|
|
/*
|
|
|
|
This file is part of Telegram Desktop,
|
2018-01-03 10:23:14 +00:00
|
|
|
the official desktop application for the Telegram messaging service.
|
2017-06-26 17:38:16 +00:00
|
|
|
|
2018-01-03 10:23:14 +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 {
|
2018-05-17 19:58:00 +00:00
|
|
|
|
2017-06-26 17:38:16 +00:00
|
|
|
class SpecialConfigRequest : public QObject {
|
|
|
|
public:
|
2018-03-20 14:21:36 +00:00
|
|
|
SpecialConfigRequest(
|
2018-06-04 15:35:11 +00:00
|
|
|
Fn<void(
|
2018-03-20 14:21:36 +00:00
|
|
|
DcId dcId,
|
|
|
|
const std::string &ip,
|
2018-05-02 19:27:03 +00:00
|
|
|
int port,
|
|
|
|
bytes::const_span secret)> callback,
|
2023-01-10 11:03:37 +00:00
|
|
|
bool isTestMode,
|
2020-06-17 09:36:25 +00:00
|
|
|
const QString &domainString,
|
2018-05-02 19:27:03 +00:00
|
|
|
const QString &phone);
|
2020-06-17 09:36:25 +00:00
|
|
|
SpecialConfigRequest(
|
|
|
|
Fn<void()> timeDoneCallback,
|
2023-01-10 11:03:37 +00:00
|
|
|
bool isTestMode,
|
2020-06-17 09:36:25 +00:00
|
|
|
const QString &domainString);
|
2017-06-26 17:38:16 +00:00
|
|
|
|
|
|
|
private:
|
2018-05-03 08:11:07 +00:00
|
|
|
enum class Type {
|
2019-10-01 17:42:18 +00:00
|
|
|
Mozilla,
|
|
|
|
Google,
|
|
|
|
RemoteConfig,
|
|
|
|
Realtime,
|
|
|
|
FireStore,
|
2018-05-03 08:11:07 +00:00
|
|
|
};
|
|
|
|
struct Attempt {
|
|
|
|
Type type;
|
2019-10-01 17:42:18 +00:00
|
|
|
QString data;
|
|
|
|
QString host;
|
2018-05-03 08:11:07 +00:00
|
|
|
};
|
|
|
|
|
2019-07-10 17:28:33 +00:00
|
|
|
SpecialConfigRequest(
|
|
|
|
Fn<void(
|
|
|
|
DcId dcId,
|
|
|
|
const std::string &ip,
|
|
|
|
int port,
|
|
|
|
bytes::const_span secret)> callback,
|
|
|
|
Fn<void()> timeDoneCallback,
|
2023-01-10 11:03:37 +00:00
|
|
|
bool isTestMode,
|
2020-06-17 09:36:25 +00:00
|
|
|
const QString &domainString,
|
2019-07-10 17:28:33 +00:00
|
|
|
const QString &phone);
|
|
|
|
|
2018-05-03 08:11:07 +00:00
|
|
|
void sendNextRequest();
|
|
|
|
void performRequest(const Attempt &attempt);
|
|
|
|
void requestFinished(Type type, not_null<QNetworkReply*> reply);
|
2019-07-10 15:03:48 +00:00
|
|
|
void handleHeaderUnixtime(not_null<QNetworkReply*> reply);
|
2018-05-03 08:11:07 +00:00
|
|
|
QByteArray finalizeRequest(not_null<QNetworkReply*> reply);
|
2017-06-26 17:38:16 +00:00
|
|
|
void handleResponse(const QByteArray &bytes);
|
|
|
|
bool decryptSimpleConfig(const QByteArray &bytes);
|
|
|
|
|
2018-06-04 15:35:11 +00:00
|
|
|
Fn<void(
|
2018-03-20 14:21:36 +00:00
|
|
|
DcId dcId,
|
|
|
|
const std::string &ip,
|
2018-05-02 19:27:03 +00:00
|
|
|
int port,
|
|
|
|
bytes::const_span secret)> _callback;
|
2019-07-10 17:28:33 +00:00
|
|
|
Fn<void()> _timeDoneCallback;
|
2020-06-17 09:36:25 +00:00
|
|
|
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;
|
2018-05-03 08:11:07 +00:00
|
|
|
std::vector<Attempt> _attempts;
|
2018-05-17 19:58:00 +00:00
|
|
|
std::vector<ServiceWebRequest> _requests;
|
|
|
|
|
|
|
|
};
|
|
|
|
|
2019-12-02 13:10:19 +00:00
|
|
|
} // namespace MTP::details
|