2016-03-24 15:57:10 +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.
|
2016-03-24 15:57:10 +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
|
2016-03-24 15:57:10 +03:00
|
|
|
*/
|
|
|
|
#pragma once
|
|
|
|
|
|
|
|
#include "mtproto/connection_abstract.h"
|
|
|
|
|
2019-09-04 10:19:15 +03:00
|
|
|
#include <QtNetwork/QNetworkAccessManager>
|
|
|
|
#include <QtNetwork/QNetworkReply>
|
|
|
|
|
2016-03-24 15:57:10 +03:00
|
|
|
namespace MTP {
|
|
|
|
namespace internal {
|
|
|
|
|
2018-05-17 13:27:27 +03:00
|
|
|
class HttpConnection : public AbstractConnection {
|
2016-03-24 15:57:10 +03:00
|
|
|
public:
|
2018-05-17 22:58:00 +03:00
|
|
|
HttpConnection(QThread *thread, const ProxyData &proxy);
|
|
|
|
|
|
|
|
ConnectionPointer clone(const ProxyData &proxy) override;
|
2016-03-24 15:57:10 +03:00
|
|
|
|
2019-02-19 10:57:53 +04:00
|
|
|
crl::time pingTime() const override;
|
|
|
|
crl::time fullConnectTimeout() const override;
|
2018-06-25 19:55:27 +01:00
|
|
|
void sendData(mtpBuffer &&buffer) override;
|
2016-03-24 15:57:10 +03:00
|
|
|
void disconnectFromServer() override;
|
2018-04-24 23:09:20 +04:00
|
|
|
void connectToServer(
|
2018-05-17 13:27:27 +03:00
|
|
|
const QString &address,
|
2018-04-24 23:09:20 +04:00
|
|
|
int port,
|
|
|
|
const bytes::vector &protocolSecret,
|
|
|
|
int16 protocolDcId) override;
|
2016-03-24 15:57:10 +03:00
|
|
|
bool isConnected() const override;
|
|
|
|
bool usingHttpWait() override;
|
|
|
|
bool needHttpWait() override;
|
|
|
|
|
|
|
|
int32 debugState() const override;
|
|
|
|
|
|
|
|
QString transport() const override;
|
2018-04-24 23:09:20 +04:00
|
|
|
QString tag() const override;
|
2016-03-24 15:57:10 +03:00
|
|
|
|
2017-02-25 19:44:02 +03:00
|
|
|
static mtpBuffer handleResponse(QNetworkReply *reply);
|
|
|
|
static qint32 handleError(QNetworkReply *reply); // returnes error code
|
|
|
|
|
2016-03-24 15:57:10 +03:00
|
|
|
private:
|
2018-04-24 23:09:20 +04:00
|
|
|
QUrl url() const;
|
|
|
|
|
2018-05-17 13:27:27 +03:00
|
|
|
void requestFinished(QNetworkReply *reply);
|
|
|
|
|
|
|
|
enum class Status {
|
|
|
|
Waiting = 0,
|
|
|
|
Ready,
|
|
|
|
Finished,
|
2016-03-24 15:57:10 +03:00
|
|
|
};
|
2018-05-17 13:27:27 +03:00
|
|
|
Status _status = Status::Waiting;
|
|
|
|
MTPint128 _checkNonce;
|
2016-03-24 15:57:10 +03:00
|
|
|
|
2018-05-17 13:27:27 +03:00
|
|
|
QNetworkAccessManager _manager;
|
2018-04-24 23:09:20 +04:00
|
|
|
QString _address;
|
2016-03-24 15:57:10 +03:00
|
|
|
|
2018-05-17 13:27:27 +03:00
|
|
|
QSet<QNetworkReply*> _requests;
|
2016-03-24 15:57:10 +03:00
|
|
|
|
2019-02-19 10:57:53 +04:00
|
|
|
crl::time _pingTime = 0;
|
2018-04-30 19:49:03 +04:00
|
|
|
|
2016-03-24 15:57:10 +03:00
|
|
|
};
|
|
|
|
|
|
|
|
} // namespace internal
|
|
|
|
} // namespace MTP
|