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