source: trunk/src/network/access/qnetworkaccessbackend_p.h@ 1004

Last change on this file since 1004 was 846, checked in by Dmitry A. Kuminov, 15 years ago

trunk: Merged in qt 4.7.2 sources from branches/vendor/nokia/qt.

File size: 8.1 KB
Line 
1/****************************************************************************
2**
3** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
4** All rights reserved.
5** Contact: Nokia Corporation ([email protected])
6**
7** This file is part of the QtNetwork module of the Qt Toolkit.
8**
9** $QT_BEGIN_LICENSE:LGPL$
10** Commercial Usage
11** Licensees holding valid Qt Commercial licenses may use this file in
12** accordance with the Qt Commercial License Agreement provided with the
13** Software or, alternatively, in accordance with the terms contained in
14** a written agreement between you and Nokia.
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** GNU General Public License Usage
29** Alternatively, this file may be used under the terms of the GNU
30** General Public License version 3.0 as published by the Free Software
31** Foundation and appearing in the file LICENSE.GPL included in the
32** packaging of this file. Please review the following information to
33** ensure the GNU General Public License version 3.0 requirements will be
34** met: http://www.gnu.org/copyleft/gpl.html.
35**
36** If you have questions regarding the use of this file, please contact
37** Nokia at [email protected].
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
59QT_BEGIN_NAMESPACE
60
61class QAuthenticator;
62class QNetworkProxy;
63class QNetworkProxyQuery;
64class QNetworkRequest;
65class QUrl;
66class QUrlInfo;
67class QSslConfiguration;
68
69class QNetworkAccessManagerPrivate;
70class QNetworkReplyImplPrivate;
71class QAbstractNetworkCache;
72class QNetworkCacheMetaData;
73class QNetworkAccessBackendUploadIODevice;
74class 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)
80class QNetworkAccessBackend : public QObject
81{
82 Q_OBJECT
83public:
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#ifndef QT_NO_BEARERMANAGEMENT
115 virtual bool start();
116#endif
117 virtual void closeDownstreamChannel() = 0;
118
119 // slot-like:
120 virtual void downstreamReadyWrite();
121 virtual void setDownstreamLimited(bool b);
122 virtual void copyFinished(QIODevice *);
123 virtual void ignoreSslErrors();
124 virtual void ignoreSslErrors(const QList<QSslError> &errors);
125
126 virtual void fetchSslConfiguration(QSslConfiguration &configuration) const;
127 virtual void setSslConfiguration(const QSslConfiguration &configuration);
128
129 virtual QNetworkCacheMetaData fetchCacheMetaData(const QNetworkCacheMetaData &metaData) const;
130
131 // information about the request
132 QNetworkAccessManager::Operation operation() const;
133 QNetworkRequest request() const;
134#ifndef QT_NO_NETWORKPROXY
135 QList<QNetworkProxy> proxyList() const;
136#endif
137
138 QAbstractNetworkCache *networkCache() const;
139 void setCachingEnabled(bool enable);
140 bool isCachingEnabled() const;
141
142 // information about the reply
143 QUrl url() const;
144 void setUrl(const QUrl &url);
145
146 // "cooked" headers
147 QVariant header(QNetworkRequest::KnownHeaders header) const;
148 void setHeader(QNetworkRequest::KnownHeaders header, const QVariant &value);
149
150 // raw headers:
151 bool hasRawHeader(const QByteArray &headerName) const;
152 QList<QByteArray> rawHeaderList() const;
153 QByteArray rawHeader(const QByteArray &headerName) const;
154 void setRawHeader(const QByteArray &headerName, const QByteArray &value);
155
156 // attributes:
157 QVariant attribute(QNetworkRequest::Attribute code) const;
158 void setAttribute(QNetworkRequest::Attribute code, const QVariant &value);
159
160 bool isSynchronous() { return synchronous; }
161 void setSynchronous(bool sync) { synchronous = sync; }
162
163 // return true if the QNonContiguousByteDevice of the upload
164 // data needs to support reset(). Currently needed for HTTP.
165 // This will possibly enable buffering of the upload data.
166 virtual bool needsResetableUploadData() { return false; }
167
168 // Returns true if backend is able to resume downloads.
169 virtual bool canResume() const { return false; }
170 virtual void setResumeOffset(quint64 offset) { Q_UNUSED(offset); }
171
172 virtual bool processRequestSynchronously() { return false; }
173
174protected:
175 // Create the device used for reading the upload data
176 QNonContiguousByteDevice* createUploadByteDevice();
177
178
179 // these functions control the downstream mechanism
180 // that is, data that has come via the connection and is going out the backend
181 qint64 nextDownstreamBlockSize() const;
182 void writeDownstreamData(QByteDataBuffer &list);
183
184public slots:
185 // for task 251801, needs to be a slot to be called asynchronously
186 void writeDownstreamData(QIODevice *data);
187
188protected slots:
189 void finished();
190 void error(QNetworkReply::NetworkError code, const QString &errorString);
191#ifndef QT_NO_NETWORKPROXY
192 void proxyAuthenticationRequired(const QNetworkProxy &proxy, QAuthenticator *auth);
193#endif
194 void authenticationRequired(QAuthenticator *auth);
195 void cacheCredentials(QAuthenticator *auth);
196 void metaDataChanged();
197 void redirectionRequested(const QUrl &destination);
198 void sslErrors(const QList<QSslError> &errors);
199 void emitReplyUploadProgress(qint64 bytesSent, qint64 bytesTotal);
200
201private:
202 friend class QNetworkAccessManager;
203 friend class QNetworkAccessManagerPrivate;
204 friend class QNetworkAccessBackendUploadIODevice;
205 friend class QNetworkReplyImplPrivate;
206 QNetworkAccessManagerPrivate *manager;
207 QNetworkReplyImplPrivate *reply;
208 bool synchronous;
209};
210
211class QNetworkAccessBackendFactory
212{
213public:
214 QNetworkAccessBackendFactory();
215 virtual ~QNetworkAccessBackendFactory();
216 virtual QNetworkAccessBackend *create(QNetworkAccessManager::Operation op,
217 const QNetworkRequest &request) const = 0;
218};
219
220QT_END_NAMESPACE
221
222#endif
223
Note: See TracBrowser for help on using the repository browser.