1 | /**************************************************************************** |
2 | ** |
3 | ** Copyright (C) 2016 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/private/qtnetworkglobal_p.h> |
55 | #include "qnetworkreplyimpl_p.h" |
56 | #include "QtCore/qobject.h" |
57 | |
58 | QT_BEGIN_NAMESPACE |
59 | |
60 | class QAuthenticator; |
61 | class QNetworkProxy; |
62 | class QNetworkProxyQuery; |
63 | class QNetworkRequest; |
64 | class QStringList; |
65 | class QUrl; |
66 | class QSslConfiguration; |
67 | |
68 | class QNetworkAccessManagerPrivate; |
69 | class QNetworkReplyImplPrivate; |
70 | class QAbstractNetworkCache; |
71 | class QNetworkCacheMetaData; |
72 | class QNonContiguousByteDevice; |
73 | |
74 | // Should support direct file upload from disk or download to disk. |
75 | // |
76 | // - The HTTP handler will use two QIODevices for communication (pull mechanism) |
77 | // - KIO uses a pull mechanism too (data/dataReq signals) |
78 | class QNetworkAccessBackend : public QObject |
79 | { |
80 | Q_OBJECT |
81 | public: |
82 | QNetworkAccessBackend(); |
83 | virtual ~QNetworkAccessBackend(); |
84 | |
85 | // To avoid mistaking with QIODevice names, the functions here |
86 | // have different names. The Connection has two streams: |
87 | // |
88 | // - Upstream: |
89 | // The upstream uses a QNonContiguousByteDevice provided |
90 | // by the backend. This device emits the usual readyRead() |
91 | // signal when the backend has data available for the connection |
92 | // to write. The different backends can listen on this signal |
93 | // and then pull upload data from the QNonContiguousByteDevice and |
94 | // deal with it. |
95 | // |
96 | // |
97 | // - Downstream: |
98 | // Downstream is the data that is being read from this |
99 | // connection and is given to the user. Downstream operates in a |
100 | // semi-"push" mechanism: the Connection object pushes the data |
101 | // it gets from the network, but it should avoid writing too |
102 | // much if the data isn't being used fast enough. The value |
103 | // returned by suggestedDownstreamBlockSize() can be used to |
104 | // determine how much should be written at a time. The |
105 | // downstreamBytesConsumed() function will be called when the |
106 | // downstream buffer is consumed by the user -- the Connection |
107 | // may choose to re-fill it with more data it has ready or get |
108 | // more data from the network (for instance, by reading from its |
109 | // socket). |
110 | |
111 | virtual void open() = 0; |
112 | virtual bool start(); |
113 | virtual void closeDownstreamChannel() = 0; |
114 | |
115 | // slot-like: |
116 | virtual void downstreamReadyWrite(); |
117 | virtual void setDownstreamLimited(bool b); |
118 | virtual void copyFinished(QIODevice *); |
119 | virtual void ignoreSslErrors(); |
120 | virtual void ignoreSslErrors(const QList<QSslError> &errors); |
121 | |
122 | virtual void fetchSslConfiguration(QSslConfiguration &configuration) const; |
123 | virtual void setSslConfiguration(const QSslConfiguration &configuration); |
124 | |
125 | virtual QNetworkCacheMetaData fetchCacheMetaData(const QNetworkCacheMetaData &metaData) const; |
126 | |
127 | // information about the request |
128 | QNetworkAccessManager::Operation operation() const; |
129 | QNetworkRequest request() const; |
130 | #ifndef QT_NO_NETWORKPROXY |
131 | QList<QNetworkProxy> proxyList() const; |
132 | #endif |
133 | |
134 | QAbstractNetworkCache *networkCache() const; |
135 | void setCachingEnabled(bool enable); |
136 | bool isCachingEnabled() const; |
137 | |
138 | // information about the reply |
139 | QUrl url() const; |
140 | void setUrl(const QUrl &url); |
141 | |
142 | // "cooked" headers |
143 | QVariant (QNetworkRequest::KnownHeaders ) const; |
144 | void (QNetworkRequest::KnownHeaders , const QVariant &value); |
145 | |
146 | // raw headers: |
147 | bool (const QByteArray &) const; |
148 | QList<QByteArray> () const; |
149 | QByteArray (const QByteArray &) const; |
150 | void (const QByteArray &, const QByteArray &value); |
151 | |
152 | // attributes: |
153 | QVariant attribute(QNetworkRequest::Attribute code) const; |
154 | void setAttribute(QNetworkRequest::Attribute code, const QVariant &value); |
155 | |
156 | bool isSynchronous() { return synchronous; } |
157 | void setSynchronous(bool sync) { synchronous = sync; } |
158 | |
159 | // return true if the QNonContiguousByteDevice of the upload |
160 | // data needs to support reset(). Currently needed for HTTP. |
161 | // This will possibly enable buffering of the upload data. |
162 | virtual bool needsResetableUploadData() { return false; } |
163 | |
164 | // Returns \c true if backend is able to resume downloads. |
165 | virtual bool canResume() const { return false; } |
166 | virtual void setResumeOffset(quint64 offset) { Q_UNUSED(offset); } |
167 | |
168 | virtual bool processRequestSynchronously() { return false; } |
169 | |
170 | protected: |
171 | // Create the device used for reading the upload data |
172 | QNonContiguousByteDevice* createUploadByteDevice(); |
173 | |
174 | // these functions control the downstream mechanism |
175 | // that is, data that has come via the connection and is going out the backend |
176 | qint64 nextDownstreamBlockSize() const; |
177 | void writeDownstreamData(QByteDataBuffer &list); |
178 | |
179 | // not actually appending data, it was already written to the user buffer |
180 | void writeDownstreamDataDownloadBuffer(qint64, qint64); |
181 | char* getDownloadBuffer(qint64); |
182 | |
183 | QSharedPointer<QNonContiguousByteDevice> uploadByteDevice; |
184 | |
185 | public slots: |
186 | // for task 251801, needs to be a slot to be called asynchronously |
187 | void writeDownstreamData(QIODevice *data); |
188 | |
189 | protected slots: |
190 | void finished(); |
191 | void error(QNetworkReply::NetworkError code, const QString &errorString); |
192 | #ifndef QT_NO_NETWORKPROXY |
193 | void proxyAuthenticationRequired(const QNetworkProxy &proxy, QAuthenticator *auth); |
194 | #endif |
195 | void authenticationRequired(QAuthenticator *auth); |
196 | void metaDataChanged(); |
197 | void redirectionRequested(const QUrl &destination); |
198 | void encrypted(); |
199 | void sslErrors(const QList<QSslError> &errors); |
200 | void emitReplyUploadProgress(qint64 bytesSent, qint64 bytesTotal); |
201 | |
202 | protected: |
203 | // FIXME In the long run we should get rid of our QNAM architecture |
204 | // and scrap this ReplyImpl/Backend distinction. |
205 | QNetworkAccessManagerPrivate *manager; |
206 | QNetworkReplyImplPrivate *reply; |
207 | |
208 | private: |
209 | friend class QNetworkAccessManager; |
210 | friend class QNetworkAccessManagerPrivate; |
211 | friend class QNetworkReplyImplPrivate; |
212 | |
213 | bool synchronous; |
214 | }; |
215 | |
216 | class QNetworkAccessBackendFactory |
217 | { |
218 | public: |
219 | QNetworkAccessBackendFactory(); |
220 | virtual ~QNetworkAccessBackendFactory(); |
221 | virtual QStringList supportedSchemes() const = 0; |
222 | virtual QNetworkAccessBackend *create(QNetworkAccessManager::Operation op, |
223 | const QNetworkRequest &request) const = 0; |
224 | }; |
225 | |
226 | QT_END_NAMESPACE |
227 | |
228 | #endif |
229 | |
230 | |