1 | /****************************************************************************
|
---|
2 | **
|
---|
3 | ** Copyright (C) 2010 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 |
|
---|
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 setDownstreamLimited(bool b);
|
---|
120 | virtual void copyFinished(QIODevice *);
|
---|
121 | virtual void ignoreSslErrors();
|
---|
122 | virtual void ignoreSslErrors(const QList<QSslError> &errors);
|
---|
123 |
|
---|
124 | virtual void fetchSslConfiguration(QSslConfiguration &configuration) const;
|
---|
125 | virtual void setSslConfiguration(const QSslConfiguration &configuration);
|
---|
126 |
|
---|
127 | virtual QNetworkCacheMetaData fetchCacheMetaData(const QNetworkCacheMetaData &metaData) const;
|
---|
128 |
|
---|
129 | // information about the request
|
---|
130 | QNetworkAccessManager::Operation operation() const;
|
---|
131 | QNetworkRequest request() const;
|
---|
132 | #ifndef QT_NO_NETWORKPROXY
|
---|
133 | QList<QNetworkProxy> proxyList() const;
|
---|
134 | #endif
|
---|
135 |
|
---|
136 | QAbstractNetworkCache *networkCache() const;
|
---|
137 | void setCachingEnabled(bool enable);
|
---|
138 | bool isCachingEnabled() const;
|
---|
139 |
|
---|
140 | // information about the reply
|
---|
141 | QUrl url() const;
|
---|
142 | void setUrl(const QUrl &url);
|
---|
143 |
|
---|
144 | // "cooked" headers
|
---|
145 | QVariant header(QNetworkRequest::KnownHeaders header) const;
|
---|
146 | void setHeader(QNetworkRequest::KnownHeaders header, const QVariant &value);
|
---|
147 |
|
---|
148 | // raw headers:
|
---|
149 | bool hasRawHeader(const QByteArray &headerName) const;
|
---|
150 | QList<QByteArray> rawHeaderList() const;
|
---|
151 | QByteArray rawHeader(const QByteArray &headerName) const;
|
---|
152 | void setRawHeader(const QByteArray &headerName, const QByteArray &value);
|
---|
153 |
|
---|
154 | // attributes:
|
---|
155 | QVariant attribute(QNetworkRequest::Attribute code) const;
|
---|
156 | void setAttribute(QNetworkRequest::Attribute code, const QVariant &value);
|
---|
157 |
|
---|
158 | // return true if the QNonContiguousByteDevice of the upload
|
---|
159 | // data needs to support reset(). Currently needed for HTTP.
|
---|
160 | // This will possibly enable buffering of the upload data.
|
---|
161 | virtual bool needsResetableUploadData() { return false; }
|
---|
162 |
|
---|
163 | protected:
|
---|
164 | // Create the device used for reading the upload data
|
---|
165 | QNonContiguousByteDevice* createUploadByteDevice();
|
---|
166 |
|
---|
167 |
|
---|
168 | // these functions control the downstream mechanism
|
---|
169 | // that is, data that has come via the connection and is going out the backend
|
---|
170 | qint64 nextDownstreamBlockSize() const;
|
---|
171 | void writeDownstreamData(QByteDataBuffer &list);
|
---|
172 |
|
---|
173 | public slots:
|
---|
174 | // for task 251801, needs to be a slot to be called asynchronously
|
---|
175 | void writeDownstreamData(QIODevice *data);
|
---|
176 |
|
---|
177 | protected slots:
|
---|
178 | void finished();
|
---|
179 | void error(QNetworkReply::NetworkError code, const QString &errorString);
|
---|
180 | #ifndef QT_NO_NETWORKPROXY
|
---|
181 | void proxyAuthenticationRequired(const QNetworkProxy &proxy, QAuthenticator *auth);
|
---|
182 | #endif
|
---|
183 | void authenticationRequired(QAuthenticator *auth);
|
---|
184 | void metaDataChanged();
|
---|
185 | void redirectionRequested(const QUrl &destination);
|
---|
186 | void sslErrors(const QList<QSslError> &errors);
|
---|
187 | void emitReplyUploadProgress(qint64 bytesSent, qint64 bytesTotal);
|
---|
188 |
|
---|
189 | private:
|
---|
190 | friend class QNetworkAccessManager;
|
---|
191 | friend class QNetworkAccessManagerPrivate;
|
---|
192 | friend class QNetworkAccessBackendUploadIODevice;
|
---|
193 | QNetworkAccessManagerPrivate *manager;
|
---|
194 | QNetworkReplyImplPrivate *reply;
|
---|
195 | };
|
---|
196 |
|
---|
197 | class QNetworkAccessBackendFactory
|
---|
198 | {
|
---|
199 | public:
|
---|
200 | QNetworkAccessBackendFactory();
|
---|
201 | virtual ~QNetworkAccessBackendFactory();
|
---|
202 | virtual QNetworkAccessBackend *create(QNetworkAccessManager::Operation op,
|
---|
203 | const QNetworkRequest &request) const = 0;
|
---|
204 | };
|
---|
205 |
|
---|
206 | QT_END_NAMESPACE
|
---|
207 |
|
---|
208 | #endif
|
---|
209 |
|
---|