2
0
mirror of https://github.com/telegramdesktop/tdesktop synced 2025-08-23 18:57:12 +00:00
tdesktop/Telegram/SourceFiles/mtproto/special_config_request.h

78 lines
1.7 KiB
C
Raw Normal View History

2017-06-26 20:38:16 +03:00
/*
This file is part of Telegram Desktop,
the official desktop application for the Telegram messaging service.
2017-06-26 20:38:16 +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 {
2017-06-26 20:38:16 +03:00
class SpecialConfigRequest : public QObject {
public:
SpecialConfigRequest(
Fn<void(
DcId dcId,
const std::string &ip,
2018-05-02 22:27:03 +03:00
int port,
bytes::const_span secret)> callback,
const QString &phone);
explicit SpecialConfigRequest(Fn<void()> timeDoneCallback);
2017-06-26 20:38:16 +03:00
private:
enum class Type {
2019-10-01 20:42:18 +03:00
Mozilla,
Google,
RemoteConfig,
Realtime,
FireStore,
};
struct Attempt {
Type type;
2019-10-01 20:42:18 +03: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 &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 20:38:16 +03:00
void handleResponse(const QByteArray &bytes);
bool decryptSimpleConfig(const QByteArray &bytes);
Fn<void(
DcId dcId,
const std::string &ip,
2018-05-02 22:27:03 +03:00
int port,
bytes::const_span secret)> _callback;
Fn<void()> _timeDoneCallback;
2018-05-02 22:27:03 +03:00
QString _phone;
2017-06-26 20:38:16 +03:00
MTPhelp_ConfigSimple _simpleConfig;
QNetworkAccessManager _manager;
std::vector<Attempt> _attempts;
std::vector<ServiceWebRequest> _requests;
};
2019-12-02 16:10:19 +03:00
} // namespace MTP::details