1 /****************************************************************************
3 ** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies).
4 ** Contact: http://www.qt-project.org/
6 ** This file is part of the QtNetwork module of the Qt Toolkit.
8 ** $QT_BEGIN_LICENSE:LGPL$
9 ** GNU Lesser General Public License Usage
10 ** This file may be used under the terms of the GNU Lesser General Public
11 ** License version 2.1 as published by the Free Software Foundation and
12 ** appearing in the file LICENSE.LGPL included in the packaging of this
13 ** file. Please review the following information to ensure the GNU Lesser
14 ** General Public License version 2.1 requirements will be met:
15 ** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
17 ** In addition, as a special exception, Nokia gives you certain additional
18 ** rights. These rights are described in the Nokia Qt LGPL Exception
19 ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
21 ** GNU General Public License Usage
22 ** Alternatively, this file may be used under the terms of the GNU General
23 ** Public License version 3.0 as published by the Free Software Foundation
24 ** and appearing in the file LICENSE.GPL included in the packaging of this
25 ** file. Please review the following information to ensure the GNU General
26 ** Public License version 3.0 requirements will be met:
27 ** http://www.gnu.org/copyleft/gpl.html.
30 ** Alternatively, this file may be used in accordance with the terms and
31 ** conditions contained in a signed written agreement between you and Nokia.
40 ****************************************************************************/
42 #ifndef QNETWORKACCESSBACKEND_P_H
43 #define QNETWORKACCESSBACKEND_P_H
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.
56 #include "qnetworkreplyimpl_p.h"
57 #include "QtCore/qobject.h"
63 class QNetworkProxyQuery;
64 class QNetworkRequest;
67 class QSslConfiguration;
69 class QNetworkAccessManagerPrivate;
70 class QNetworkReplyImplPrivate;
71 class QAbstractNetworkCache;
72 class QNetworkCacheMetaData;
73 class QNonContiguousByteDevice;
75 // Should support direct file upload from disk or download to disk.
77 // - The HTTP handler will use two QIODevices for communication (pull mechanism)
78 // - KIO uses a pull mechanism too (data/dataReq signals)
79 class QNetworkAccessBackend : public QObject
83 QNetworkAccessBackend();
84 virtual ~QNetworkAccessBackend();
86 // To avoid mistaking with QIODevice names, the functions here
87 // have different names. The Connection has two streams:
90 // The upstream uses a QNonContiguousByteDevice provided
91 // by the backend. This device emits the usual readyRead()
92 // signal when the backend has data available for the connection
93 // to write. The different backends can listen on this signal
94 // and then pull upload data from the QNonContiguousByteDevice and
99 // Downstream is the data that is being read from this
100 // connection and is given to the user. Downstream operates in a
101 // semi-"push" mechanism: the Connection object pushes the data
102 // it gets from the network, but it should avoid writing too
103 // much if the data isn't being used fast enough. The value
104 // returned by suggestedDownstreamBlockSize() can be used to
105 // determine how much should be written at a time. The
106 // downstreamBytesConsumed() function will be called when the
107 // downstream buffer is consumed by the user -- the Connection
108 // may choose to re-fill it with more data it has ready or get
109 // more data from the network (for instance, by reading from its
112 virtual void open() = 0;
113 virtual bool start();
114 virtual void closeDownstreamChannel() = 0;
117 virtual void downstreamReadyWrite();
118 virtual void setDownstreamLimited(bool b);
119 virtual void copyFinished(QIODevice *);
120 virtual void ignoreSslErrors();
121 virtual void ignoreSslErrors(const QList<QSslError> &errors);
123 virtual void fetchSslConfiguration(QSslConfiguration &configuration) const;
124 virtual void setSslConfiguration(const QSslConfiguration &configuration);
126 virtual QNetworkCacheMetaData fetchCacheMetaData(const QNetworkCacheMetaData &metaData) const;
128 // information about the request
129 QNetworkAccessManager::Operation operation() const;
130 QNetworkRequest request() const;
131 #ifndef QT_NO_NETWORKPROXY
132 QList<QNetworkProxy> proxyList() const;
135 QAbstractNetworkCache *networkCache() const;
136 void setCachingEnabled(bool enable);
137 bool isCachingEnabled() const;
139 // information about the reply
141 void setUrl(const QUrl &url);
144 QVariant header(QNetworkRequest::KnownHeaders header) const;
145 void setHeader(QNetworkRequest::KnownHeaders header, const QVariant &value);
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);
154 QVariant attribute(QNetworkRequest::Attribute code) const;
155 void setAttribute(QNetworkRequest::Attribute code, const QVariant &value);
157 bool isSynchronous() { return synchronous; }
158 void setSynchronous(bool sync) { synchronous = sync; }
160 // return true if the QNonContiguousByteDevice of the upload
161 // data needs to support reset(). Currently needed for HTTP.
162 // This will possibly enable buffering of the upload data.
163 virtual bool needsResetableUploadData() { return false; }
165 // Returns true if backend is able to resume downloads.
166 virtual bool canResume() const { return false; }
167 virtual void setResumeOffset(quint64 offset) { Q_UNUSED(offset); }
169 virtual bool processRequestSynchronously() { return false; }
172 // Create the device used for reading the upload data
173 QNonContiguousByteDevice* createUploadByteDevice();
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);
180 // not actually appending data, it was already written to the user buffer
181 void writeDownstreamDataDownloadBuffer(qint64, qint64);
182 char* getDownloadBuffer(qint64);
184 QSharedPointer<QNonContiguousByteDevice> uploadByteDevice;
187 // for task 251801, needs to be a slot to be called asynchronously
188 void writeDownstreamData(QIODevice *data);
192 void error(QNetworkReply::NetworkError code, const QString &errorString);
193 #ifndef QT_NO_NETWORKPROXY
194 void proxyAuthenticationRequired(const QNetworkProxy &proxy, QAuthenticator *auth);
196 void authenticationRequired(QAuthenticator *auth);
197 void metaDataChanged();
198 void redirectionRequested(const QUrl &destination);
199 void sslErrors(const QList<QSslError> &errors);
200 void emitReplyUploadProgress(qint64 bytesSent, qint64 bytesTotal);
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;
209 friend class QNetworkAccessManager;
210 friend class QNetworkAccessManagerPrivate;
211 friend class QNetworkReplyImplPrivate;
216 class QNetworkAccessBackendFactory
219 QNetworkAccessBackendFactory();
220 virtual ~QNetworkAccessBackendFactory();
221 virtual QNetworkAccessBackend *create(QNetworkAccessManager::Operation op,
222 const QNetworkRequest &request) const = 0;