author | Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com> |
Tue, 06 Jul 2010 15:10:48 +0300 | |
changeset 30 | 5dc02b23752f |
parent 18 | 2f34d5167611 |
permissions | -rw-r--r-- |
0 | 1 |
/**************************************************************************** |
2 |
** |
|
18
2f34d5167611
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
3 |
** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies). |
0 | 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; |
|
30
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
114 |
#ifndef QT_NO_BEARERMANAGEMENT |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
115 |
virtual bool start(); |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
116 |
#endif |
0 | 117 |
virtual void closeDownstreamChannel() = 0; |
118 |
virtual bool waitForDownstreamReadyRead(int msecs) = 0; |
|
119 |
||
120 |
// slot-like: |
|
121 |
virtual void downstreamReadyWrite(); |
|
18
2f34d5167611
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
122 |
virtual void setDownstreamLimited(bool b); |
0 | 123 |
virtual void copyFinished(QIODevice *); |
124 |
virtual void ignoreSslErrors(); |
|
125 |
virtual void ignoreSslErrors(const QList<QSslError> &errors); |
|
126 |
||
127 |
virtual void fetchSslConfiguration(QSslConfiguration &configuration) const; |
|
128 |
virtual void setSslConfiguration(const QSslConfiguration &configuration); |
|
129 |
||
130 |
virtual QNetworkCacheMetaData fetchCacheMetaData(const QNetworkCacheMetaData &metaData) const; |
|
131 |
||
132 |
// information about the request |
|
133 |
QNetworkAccessManager::Operation operation() const; |
|
134 |
QNetworkRequest request() const; |
|
135 |
#ifndef QT_NO_NETWORKPROXY |
|
136 |
QList<QNetworkProxy> proxyList() const; |
|
137 |
#endif |
|
138 |
||
139 |
QAbstractNetworkCache *networkCache() const; |
|
140 |
void setCachingEnabled(bool enable); |
|
141 |
bool isCachingEnabled() const; |
|
142 |
||
143 |
// information about the reply |
|
144 |
QUrl url() const; |
|
145 |
void setUrl(const QUrl &url); |
|
146 |
||
147 |
// "cooked" headers |
|
148 |
QVariant header(QNetworkRequest::KnownHeaders header) const; |
|
149 |
void setHeader(QNetworkRequest::KnownHeaders header, const QVariant &value); |
|
150 |
||
151 |
// raw headers: |
|
152 |
bool hasRawHeader(const QByteArray &headerName) const; |
|
153 |
QList<QByteArray> rawHeaderList() const; |
|
154 |
QByteArray rawHeader(const QByteArray &headerName) const; |
|
155 |
void setRawHeader(const QByteArray &headerName, const QByteArray &value); |
|
156 |
||
157 |
// attributes: |
|
158 |
QVariant attribute(QNetworkRequest::Attribute code) const; |
|
159 |
void setAttribute(QNetworkRequest::Attribute code, const QVariant &value); |
|
160 |
||
161 |
// return true if the QNonContiguousByteDevice of the upload |
|
162 |
// data needs to support reset(). Currently needed for HTTP. |
|
163 |
// This will possibly enable buffering of the upload data. |
|
164 |
virtual bool needsResetableUploadData() { return false; } |
|
165 |
||
30
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
166 |
// Returns true if backend is able to resume downloads. |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
167 |
virtual bool canResume() const { return false; } |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
168 |
virtual void setResumeOffset(quint64 offset) { Q_UNUSED(offset); } |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
169 |
|
0 | 170 |
protected: |
171 |
// Create the device used for reading the upload data |
|
172 |
QNonContiguousByteDevice* createUploadByteDevice(); |
|
173 |
||
174 |
||
175 |
// these functions control the downstream mechanism |
|
176 |
// that is, data that has come via the connection and is going out the backend |
|
177 |
qint64 nextDownstreamBlockSize() const; |
|
178 |
void writeDownstreamData(QByteDataBuffer &list); |
|
179 |
||
180 |
public slots: |
|
181 |
// for task 251801, needs to be a slot to be called asynchronously |
|
182 |
void writeDownstreamData(QIODevice *data); |
|
183 |
||
184 |
protected slots: |
|
185 |
void finished(); |
|
186 |
void error(QNetworkReply::NetworkError code, const QString &errorString); |
|
187 |
#ifndef QT_NO_NETWORKPROXY |
|
188 |
void proxyAuthenticationRequired(const QNetworkProxy &proxy, QAuthenticator *auth); |
|
189 |
#endif |
|
190 |
void authenticationRequired(QAuthenticator *auth); |
|
30
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
191 |
void cacheCredentials(QAuthenticator *auth); |
0 | 192 |
void metaDataChanged(); |
193 |
void redirectionRequested(const QUrl &destination); |
|
194 |
void sslErrors(const QList<QSslError> &errors); |
|
195 |
void emitReplyUploadProgress(qint64 bytesSent, qint64 bytesTotal); |
|
196 |
||
197 |
private: |
|
198 |
friend class QNetworkAccessManager; |
|
199 |
friend class QNetworkAccessManagerPrivate; |
|
200 |
friend class QNetworkAccessBackendUploadIODevice; |
|
30
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
201 |
friend class QNetworkReplyImplPrivate; |
0 | 202 |
QNetworkAccessManagerPrivate *manager; |
203 |
QNetworkReplyImplPrivate *reply; |
|
204 |
}; |
|
205 |
||
206 |
class QNetworkAccessBackendFactory |
|
207 |
{ |
|
208 |
public: |
|
209 |
QNetworkAccessBackendFactory(); |
|
210 |
virtual ~QNetworkAccessBackendFactory(); |
|
211 |
virtual QNetworkAccessBackend *create(QNetworkAccessManager::Operation op, |
|
212 |
const QNetworkRequest &request) const = 0; |
|
213 |
}; |
|
214 |
||
215 |
QT_END_NAMESPACE |
|
216 |
||
217 |
#endif |
|
218 |