|
1 /**************************************************************************** |
|
2 ** |
|
3 ** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). |
|
4 ** All rights reserved. |
|
5 ** Contact: Nokia Corporation (qt-info@nokia.com) |
|
6 ** |
|
7 ** This file is part of the QtNetwork module of the Qt Toolkit. |
|
8 ** |
|
9 ** $QT_BEGIN_LICENSE:LGPL$ |
|
10 ** No Commercial Usage |
|
11 ** This file contains pre-release code and may not be distributed. |
|
12 ** You may use this file in accordance with the terms and conditions |
|
13 ** contained in the Technology Preview License Agreement accompanying |
|
14 ** this package. |
|
15 ** |
|
16 ** GNU Lesser General Public License Usage |
|
17 ** Alternatively, this file may be used under the terms of the GNU Lesser |
|
18 ** General Public License version 2.1 as published by the Free Software |
|
19 ** Foundation and appearing in the file LICENSE.LGPL included in the |
|
20 ** packaging of this file. Please review the following information to |
|
21 ** ensure the GNU Lesser General Public License version 2.1 requirements |
|
22 ** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. |
|
23 ** |
|
24 ** In addition, as a special exception, Nokia gives you certain additional |
|
25 ** rights. These rights are described in the Nokia Qt LGPL Exception |
|
26 ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. |
|
27 ** |
|
28 ** If you have questions regarding the use of this file, please contact |
|
29 ** Nokia at qt-info@nokia.com. |
|
30 ** |
|
31 ** |
|
32 ** |
|
33 ** |
|
34 ** |
|
35 ** |
|
36 ** |
|
37 ** |
|
38 ** $QT_END_LICENSE$ |
|
39 ** |
|
40 ****************************************************************************/ |
|
41 |
|
42 #ifndef QNETWORKACCESSBACKEND_P_H |
|
43 #define QNETWORKACCESSBACKEND_P_H |
|
44 |
|
45 // |
|
46 // W A R N I N G |
|
47 // ------------- |
|
48 // |
|
49 // This file is not part of the Qt API. It exists for the convenience |
|
50 // of the Network Access API. This header file may change from |
|
51 // version to version without notice, or even be removed. |
|
52 // |
|
53 // We mean it. |
|
54 // |
|
55 |
|
56 #include "qnetworkreplyimpl_p.h" |
|
57 #include "QtCore/qobject.h" |
|
58 |
|
59 QT_BEGIN_NAMESPACE |
|
60 |
|
61 class QAuthenticator; |
|
62 class QNetworkProxy; |
|
63 class QNetworkProxyQuery; |
|
64 class QNetworkRequest; |
|
65 class QUrl; |
|
66 class QUrlInfo; |
|
67 class QSslConfiguration; |
|
68 |
|
69 class QNetworkAccessManagerPrivate; |
|
70 class QNetworkReplyImplPrivate; |
|
71 class QAbstractNetworkCache; |
|
72 class QNetworkCacheMetaData; |
|
73 class QNetworkAccessBackendUploadIODevice; |
|
74 class QNonContiguousByteDevice; |
|
75 |
|
76 // Should support direct file upload from disk or download to disk. |
|
77 // |
|
78 // - The HTTP handler will use two QIODevices for communication (pull mechanism) |
|
79 // - KIO uses a pull mechanism too (data/dataReq signals) |
|
80 class QNetworkAccessBackend : public QObject |
|
81 { |
|
82 Q_OBJECT |
|
83 public: |
|
84 QNetworkAccessBackend(); |
|
85 virtual ~QNetworkAccessBackend(); |
|
86 |
|
87 // To avoid mistaking with QIODevice names, the functions here |
|
88 // have different names. The Connection has two streams: |
|
89 // |
|
90 // - Upstream: |
|
91 // The upstream uses a QNonContiguousByteDevice provided |
|
92 // by the backend. This device emits the usual readyRead() |
|
93 // signal when the backend has data available for the connection |
|
94 // to write. The different backends can listen on this signal |
|
95 // and then pull upload data from the QNonContiguousByteDevice and |
|
96 // deal with it. |
|
97 // |
|
98 // |
|
99 // - Downstream: |
|
100 // Downstream is the data that is being read from this |
|
101 // connection and is given to the user. Downstream operates in a |
|
102 // semi-"push" mechanism: the Connection object pushes the data |
|
103 // it gets from the network, but it should avoid writing too |
|
104 // much if the data isn't being used fast enough. The value |
|
105 // returned by suggestedDownstreamBlockSize() can be used to |
|
106 // determine how much should be written at a time. The |
|
107 // downstreamBytesConsumed() function will be called when the |
|
108 // downstream buffer is consumed by the user -- the Connection |
|
109 // may choose to re-fill it with more data it has ready or get |
|
110 // more data from the network (for instance, by reading from its |
|
111 // socket). |
|
112 |
|
113 virtual void open() = 0; |
|
114 virtual void closeDownstreamChannel() = 0; |
|
115 virtual bool waitForDownstreamReadyRead(int msecs) = 0; |
|
116 |
|
117 // slot-like: |
|
118 virtual void downstreamReadyWrite(); |
|
119 virtual void copyFinished(QIODevice *); |
|
120 virtual void ignoreSslErrors(); |
|
121 virtual void ignoreSslErrors(const QList<QSslError> &errors); |
|
122 |
|
123 virtual void fetchSslConfiguration(QSslConfiguration &configuration) const; |
|
124 virtual void setSslConfiguration(const QSslConfiguration &configuration); |
|
125 |
|
126 virtual QNetworkCacheMetaData fetchCacheMetaData(const QNetworkCacheMetaData &metaData) const; |
|
127 |
|
128 // information about the request |
|
129 QNetworkAccessManager::Operation operation() const; |
|
130 QNetworkRequest request() const; |
|
131 #ifndef QT_NO_NETWORKPROXY |
|
132 QList<QNetworkProxy> proxyList() const; |
|
133 #endif |
|
134 |
|
135 QAbstractNetworkCache *networkCache() const; |
|
136 void setCachingEnabled(bool enable); |
|
137 bool isCachingEnabled() const; |
|
138 |
|
139 // information about the reply |
|
140 QUrl url() const; |
|
141 void setUrl(const QUrl &url); |
|
142 |
|
143 // "cooked" headers |
|
144 QVariant header(QNetworkRequest::KnownHeaders header) const; |
|
145 void setHeader(QNetworkRequest::KnownHeaders header, const QVariant &value); |
|
146 |
|
147 // raw headers: |
|
148 bool hasRawHeader(const QByteArray &headerName) const; |
|
149 QList<QByteArray> rawHeaderList() const; |
|
150 QByteArray rawHeader(const QByteArray &headerName) const; |
|
151 void setRawHeader(const QByteArray &headerName, const QByteArray &value); |
|
152 |
|
153 // attributes: |
|
154 QVariant attribute(QNetworkRequest::Attribute code) const; |
|
155 void setAttribute(QNetworkRequest::Attribute code, const QVariant &value); |
|
156 |
|
157 // return true if the QNonContiguousByteDevice of the upload |
|
158 // data needs to support reset(). Currently needed for HTTP. |
|
159 // This will possibly enable buffering of the upload data. |
|
160 virtual bool needsResetableUploadData() { return false; } |
|
161 |
|
162 protected: |
|
163 // Create the device used for reading the upload data |
|
164 QNonContiguousByteDevice* createUploadByteDevice(); |
|
165 |
|
166 |
|
167 // these functions control the downstream mechanism |
|
168 // that is, data that has come via the connection and is going out the backend |
|
169 qint64 nextDownstreamBlockSize() const; |
|
170 void writeDownstreamData(QByteDataBuffer &list); |
|
171 |
|
172 public slots: |
|
173 // for task 251801, needs to be a slot to be called asynchronously |
|
174 void writeDownstreamData(QIODevice *data); |
|
175 |
|
176 protected slots: |
|
177 void finished(); |
|
178 void error(QNetworkReply::NetworkError code, const QString &errorString); |
|
179 #ifndef QT_NO_NETWORKPROXY |
|
180 void proxyAuthenticationRequired(const QNetworkProxy &proxy, QAuthenticator *auth); |
|
181 #endif |
|
182 void authenticationRequired(QAuthenticator *auth); |
|
183 void metaDataChanged(); |
|
184 void redirectionRequested(const QUrl &destination); |
|
185 void sslErrors(const QList<QSslError> &errors); |
|
186 void emitReplyUploadProgress(qint64 bytesSent, qint64 bytesTotal); |
|
187 |
|
188 private: |
|
189 friend class QNetworkAccessManager; |
|
190 friend class QNetworkAccessManagerPrivate; |
|
191 friend class QNetworkAccessBackendUploadIODevice; |
|
192 QNetworkAccessManagerPrivate *manager; |
|
193 QNetworkReplyImplPrivate *reply; |
|
194 }; |
|
195 |
|
196 class QNetworkAccessBackendFactory |
|
197 { |
|
198 public: |
|
199 QNetworkAccessBackendFactory(); |
|
200 virtual ~QNetworkAccessBackendFactory(); |
|
201 virtual QNetworkAccessBackend *create(QNetworkAccessManager::Operation op, |
|
202 const QNetworkRequest &request) const = 0; |
|
203 }; |
|
204 |
|
205 QT_END_NAMESPACE |
|
206 |
|
207 #endif |
|
208 |