1/****************************************************************************
2**
3** Copyright (C) 2020 The Qt Company Ltd.
4** Contact: https://www.qt.io/licensing/
5**
6** This file is part of the QtNetwork module of the Qt Toolkit.
7**
8** $QT_BEGIN_LICENSE:LGPL$
9** Commercial License Usage
10** Licensees holding valid commercial Qt licenses may use this file in
11** accordance with the commercial license agreement provided with the
12** Software or, alternatively, in accordance with the terms contained in
13** a written agreement between you and The Qt Company. For licensing terms
14** and conditions see https://www.qt.io/terms-conditions. For further
15** information use the contact form at https://www.qt.io/contact-us.
16**
17** GNU Lesser General Public License Usage
18** Alternatively, this file may be used under the terms of the GNU Lesser
19** General Public License version 3 as published by the Free Software
20** Foundation and appearing in the file LICENSE.LGPL3 included in the
21** packaging of this file. Please review the following information to
22** ensure the GNU Lesser General Public License version 3 requirements
23** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
24**
25** GNU General Public License Usage
26** Alternatively, this file may be used under the terms of the GNU
27** General Public License version 2.0 or (at your option) the GNU General
28** Public license version 3 or any later version approved by the KDE Free
29** Qt Foundation. The licenses are as published by the Free Software
30** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
31** included in the packaging of this file. Please review the following
32** information to ensure the GNU General Public License requirements will
33** be met: https://www.gnu.org/licenses/gpl-2.0.html and
34** https://www.gnu.org/licenses/gpl-3.0.html.
35**
36** $QT_END_LICENSE$
37**
38****************************************************************************/
39
40#ifndef QNETWORKACCESSBACKEND_P_H
41#define QNETWORKACCESSBACKEND_P_H
42
43//
44// W A R N I N G
45// -------------
46//
47// This file is not part of the Qt API. It exists for the convenience
48// of the Network Access API. This header file may change from
49// version to version without notice, or even be removed.
50//
51// We mean it.
52//
53
54#include <QtNetwork/qtnetworkglobal.h>
55
56#include <QtNetwork/qnetworkrequest.h>
57#include <QtNetwork/qnetworkaccessmanager.h>
58#include <QtNetwork/qnetworkreply.h>
59
60#include <QtCore/qobject.h>
61#include <QtCore/qflags.h>
62#include <QtCore/qbytearrayview.h>
63
64#if QT_CONFIG(ssl)
65#include <QtNetwork/qsslconfiguration.h>
66#endif
67
68QT_BEGIN_NAMESPACE
69
70class QNetworkReplyImplPrivate;
71class QNetworkAccessManagerPrivate;
72class QNetworkAccessBackendPrivate;
73class Q_NETWORK_EXPORT QNetworkAccessBackend : public QObject
74{
75 Q_OBJECT
76 Q_DECLARE_PRIVATE(QNetworkAccessBackend);
77
78public:
79 enum class TargetType {
80 Networked = 0x1, // We need to query for proxy in case it is needed
81 Local = 0x2, // Local file, generated data or local device
82 };
83 Q_ENUM(TargetType)
84 Q_DECLARE_FLAGS(TargetTypes, TargetType)
85
86 enum class SecurityFeature {
87 None = 0x0,
88 TLS = 0x1, // We need to set QSslConfiguration
89 };
90 Q_ENUM(SecurityFeature)
91 Q_DECLARE_FLAGS(SecurityFeatures, SecurityFeature)
92
93 enum class IOFeature {
94 None = 0x0,
95 ZeroCopy = 0x1, // readPointer and advanceReadPointer() is available!
96 NeedResetableUpload = 0x2, // Need to buffer upload data
97 SupportsSynchronousMode = 0x4, // Used for XMLHttpRequest
98 };
99 Q_ENUM(IOFeature)
100 Q_DECLARE_FLAGS(IOFeatures, IOFeature)
101
102 QNetworkAccessBackend(TargetTypes targetTypes, SecurityFeatures securityFeatures,
103 IOFeatures ioFeatures);
104 QNetworkAccessBackend(TargetTypes targetTypes);
105 QNetworkAccessBackend(TargetTypes targetTypes, SecurityFeatures securityFeatures);
106 QNetworkAccessBackend(TargetTypes targetTypes, IOFeatures ioFeatures);
107 virtual ~QNetworkAccessBackend();
108
109 SecurityFeatures securityFeatures() const noexcept;
110 TargetTypes targetTypes() const noexcept;
111 IOFeatures ioFeatures() const noexcept;
112
113 inline bool needsResetableUploadData() const noexcept
114 {
115 return ioFeatures() & IOFeature::NeedResetableUpload;
116 }
117
118 virtual bool start();
119 virtual void open() = 0;
120 virtual void close() = 0;
121#if QT_CONFIG(ssl)
122 virtual void setSslConfiguration(const QSslConfiguration &configuration);
123 virtual QSslConfiguration sslConfiguration() const;
124#endif
125 virtual void ignoreSslErrors();
126 virtual void ignoreSslErrors(const QList<QSslError> &errors);
127 virtual qint64 bytesAvailable() const = 0;
128 virtual QByteArrayView readPointer();
129 virtual void advanceReadPointer(qint64 distance);
130 virtual qint64 read(char *data, qint64 maxlen);
131 virtual bool wantToRead();
132
133#if QT_CONFIG(networkproxy)
134 QList<QNetworkProxy> proxyList() const;
135#endif
136 QUrl url() const;
137 void setUrl(const QUrl &url);
138 QVariant header(QNetworkRequest::KnownHeaders header) const;
139 void setHeader(QNetworkRequest::KnownHeaders header, const QVariant &value);
140 QByteArray rawHeader(const QByteArray &header) const;
141 void setRawHeader(const QByteArray &header, const QByteArray &value);
142 QNetworkAccessManager::Operation operation() const;
143
144 bool isCachingEnabled() const;
145 void setCachingEnabled(bool canCache);
146
147 void setAttribute(QNetworkRequest::Attribute attribute, const QVariant &value);
148
149 QIODevice *createUploadByteDevice();
150 QIODevice *uploadByteDevice();
151
152 QAbstractNetworkCache *networkCache() const;
153
154public slots:
155 void readyRead();
156protected slots:
157 void finished();
158 void error(QNetworkReply::NetworkError code, const QString &errorString);
159#ifndef QT_NO_NETWORKPROXY
160 void proxyAuthenticationRequired(const QNetworkProxy &proxy, QAuthenticator *auth);
161#endif
162 void authenticationRequired(QAuthenticator *auth);
163 void metaDataChanged();
164 void redirectionRequested(const QUrl &destination);
165
166private:
167 void setReplyPrivate(QNetworkReplyImplPrivate *reply);
168 void setManagerPrivate(QNetworkAccessManagerPrivate *manager);
169 bool isSynchronous() const;
170 void setSynchronous(bool synchronous);
171
172 friend class QNetworkAccessManager; // for setReplyPrivate
173 friend class QNetworkAccessManagerPrivate; // for setManagerPrivate
174 friend class QNetworkReplyImplPrivate; // for {set,is}Synchronous()
175};
176
177class Q_NETWORK_EXPORT QNetworkAccessBackendFactory : public QObject
178{
179 Q_OBJECT
180public:
181 QNetworkAccessBackendFactory();
182 virtual ~QNetworkAccessBackendFactory();
183 virtual QStringList supportedSchemes() const = 0;
184 virtual QNetworkAccessBackend *create(QNetworkAccessManager::Operation op,
185 const QNetworkRequest &request) const = 0;
186};
187
188#define QNetworkAccessBackendFactory_iid "org.qt-project.Qt.NetworkAccessBackendFactory"
189Q_DECLARE_INTERFACE(QNetworkAccessBackendFactory, QNetworkAccessBackendFactory_iid);
190
191QT_END_NAMESPACE
192#endif
193