| 1 | // Copyright (C) 2016 The Qt Company Ltd. |
| 2 | // SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only |
| 3 | // Qt-Security score:significant reason:default |
| 4 | |
| 5 | #ifndef QNETWORKREPLY_H |
| 6 | #define QNETWORKREPLY_H |
| 7 | |
| 8 | #include <QtNetwork/qtnetworkglobal.h> |
| 9 | #include <QtCore/QIODevice> |
| 10 | #include <QtCore/QString> |
| 11 | #include <QtCore/QVariant> |
| 12 | |
| 13 | #include <QtNetwork/QNetworkRequest> |
| 14 | #include <QtNetwork/QNetworkAccessManager> |
| 15 | |
| 16 | #include <utility> |
| 17 | |
| 18 | QT_BEGIN_NAMESPACE |
| 19 | |
| 20 | |
| 21 | class QUrl; |
| 22 | class QVariant; |
| 23 | class QAuthenticator; |
| 24 | class QSslConfiguration; |
| 25 | class QSslError; |
| 26 | class QSslPreSharedKeyAuthenticator; |
| 27 | |
| 28 | class QNetworkReplyPrivate; |
| 29 | class Q_NETWORK_EXPORT QNetworkReply: public QIODevice |
| 30 | { |
| 31 | Q_OBJECT |
| 32 | public: |
| 33 | enum NetworkError { |
| 34 | NoError = 0, |
| 35 | |
| 36 | // network layer errors [relating to the destination server] (1-99): |
| 37 | ConnectionRefusedError = 1, |
| 38 | RemoteHostClosedError, |
| 39 | HostNotFoundError, |
| 40 | TimeoutError, |
| 41 | OperationCanceledError, |
| 42 | SslHandshakeFailedError, |
| 43 | TemporaryNetworkFailureError, |
| 44 | NetworkSessionFailedError, |
| 45 | BackgroundRequestNotAllowedError, |
| 46 | TooManyRedirectsError, |
| 47 | InsecureRedirectError, |
| 48 | UnknownNetworkError = 99, |
| 49 | |
| 50 | // proxy errors (101-199): |
| 51 | ProxyConnectionRefusedError = 101, |
| 52 | ProxyConnectionClosedError, |
| 53 | ProxyNotFoundError, |
| 54 | ProxyTimeoutError, |
| 55 | ProxyAuthenticationRequiredError, |
| 56 | UnknownProxyError = 199, |
| 57 | |
| 58 | // content errors (201-299): |
| 59 | ContentAccessDenied = 201, |
| 60 | ContentOperationNotPermittedError, |
| 61 | ContentNotFoundError, |
| 62 | AuthenticationRequiredError, |
| 63 | ContentReSendError, |
| 64 | ContentConflictError, |
| 65 | ContentGoneError, |
| 66 | UnknownContentError = 299, |
| 67 | |
| 68 | // protocol errors |
| 69 | ProtocolUnknownError = 301, |
| 70 | ProtocolInvalidOperationError, |
| 71 | ProtocolFailure = 399, |
| 72 | |
| 73 | // Server side errors (401-499) |
| 74 | InternalServerError = 401, |
| 75 | OperationNotImplementedError, |
| 76 | ServiceUnavailableError, |
| 77 | UnknownServerError = 499 |
| 78 | }; |
| 79 | Q_ENUM(NetworkError) |
| 80 | |
| 81 | ~QNetworkReply(); |
| 82 | |
| 83 | // reimplemented from QIODevice |
| 84 | virtual void close() override; |
| 85 | virtual bool isSequential() const override; |
| 86 | |
| 87 | // like QAbstractSocket: |
| 88 | qint64 readBufferSize() const; |
| 89 | virtual void setReadBufferSize(qint64 size); |
| 90 | |
| 91 | QNetworkAccessManager *manager() const; |
| 92 | QNetworkAccessManager::Operation operation() const; |
| 93 | QNetworkRequest request() const; |
| 94 | NetworkError error() const; |
| 95 | bool isFinished() const; |
| 96 | bool isRunning() const; |
| 97 | QUrl url() const; |
| 98 | |
| 99 | // "cooked" headers |
| 100 | QVariant (QNetworkRequest::KnownHeaders ) const; |
| 101 | |
| 102 | // raw headers: |
| 103 | #if QT_NETWORK_REMOVED_SINCE(6, 7) |
| 104 | bool hasRawHeader(const QByteArray &headerName) const; |
| 105 | #endif |
| 106 | bool (QAnyStringView ) const; |
| 107 | QList<QByteArray> () const; |
| 108 | #if QT_NETWORK_REMOVED_SINCE(6, 7) |
| 109 | QByteArray rawHeader(const QByteArray &headerName) const; |
| 110 | #endif |
| 111 | QByteArray (QAnyStringView ) const; |
| 112 | |
| 113 | typedef std::pair<QByteArray, QByteArray> ; |
| 114 | const QList<RawHeaderPair>& () const; |
| 115 | QHttpHeaders () const; |
| 116 | |
| 117 | // attributes |
| 118 | QVariant attribute(QNetworkRequest::Attribute code) const; |
| 119 | |
| 120 | #if QT_CONFIG(ssl) |
| 121 | QSslConfiguration sslConfiguration() const; |
| 122 | void setSslConfiguration(const QSslConfiguration &configuration); |
| 123 | void ignoreSslErrors(const QList<QSslError> &errors); |
| 124 | #endif |
| 125 | |
| 126 | public Q_SLOTS: |
| 127 | virtual void abort() = 0; |
| 128 | virtual void ignoreSslErrors(); |
| 129 | |
| 130 | Q_SIGNALS: |
| 131 | void socketStartedConnecting(); |
| 132 | void requestSent(); |
| 133 | void metaDataChanged(); |
| 134 | void finished(); |
| 135 | void errorOccurred(QNetworkReply::NetworkError); |
| 136 | #if QT_CONFIG(ssl) |
| 137 | void encrypted(); |
| 138 | void sslErrors(const QList<QSslError> &errors); |
| 139 | void preSharedKeyAuthenticationRequired(QSslPreSharedKeyAuthenticator *authenticator); |
| 140 | #endif |
| 141 | void redirected(const QUrl &url); |
| 142 | void redirectAllowed(); |
| 143 | |
| 144 | void uploadProgress(qint64 bytesSent, qint64 bytesTotal); |
| 145 | void downloadProgress(qint64 bytesReceived, qint64 bytesTotal); |
| 146 | |
| 147 | protected: |
| 148 | explicit QNetworkReply(QObject *parent = nullptr); |
| 149 | QNetworkReply(QNetworkReplyPrivate &dd, QObject *parent); |
| 150 | virtual qint64 writeData(const char *data, qint64 len) override; |
| 151 | |
| 152 | void setOperation(QNetworkAccessManager::Operation operation); |
| 153 | void setRequest(const QNetworkRequest &request); |
| 154 | void setError(NetworkError errorCode, const QString &errorString); |
| 155 | void setFinished(bool); |
| 156 | void setUrl(const QUrl &url); |
| 157 | void (QNetworkRequest::KnownHeaders , const QVariant &value); |
| 158 | void (const QByteArray &, const QByteArray &value); |
| 159 | void (const QHttpHeaders &); |
| 160 | void (QHttpHeaders &&); |
| 161 | void (QHttpHeaders::WellKnownHeader name, QByteArrayView value); |
| 162 | void setAttribute(QNetworkRequest::Attribute code, const QVariant &value); |
| 163 | |
| 164 | #if QT_CONFIG(ssl) |
| 165 | virtual void sslConfigurationImplementation(QSslConfiguration &) const; |
| 166 | virtual void setSslConfigurationImplementation(const QSslConfiguration &); |
| 167 | virtual void ignoreSslErrorsImplementation(const QList<QSslError> &); |
| 168 | #endif |
| 169 | |
| 170 | private: |
| 171 | Q_DECLARE_PRIVATE(QNetworkReply) |
| 172 | }; |
| 173 | |
| 174 | QT_END_NAMESPACE |
| 175 | |
| 176 | QT_DECL_METATYPE_EXTERN_TAGGED(QNetworkReply::NetworkError, |
| 177 | QNetworkReply__NetworkError, Q_NETWORK_EXPORT) |
| 178 | |
| 179 | #endif |
| 180 | |