Qt 4.8
qnetworkaccessbackend_p.h
Go to the documentation of this file.
1 /****************************************************************************
2 **
3 ** Copyright (C) 2014 Digia Plc and/or its subsidiary(-ies).
4 ** Contact: http://www.qt-project.org/legal
5 **
6 ** This file is part of the QtNetwork module of the Qt Toolkit.
7 **
8 ** $QT_BEGIN_LICENSE:LGPL$
9 ** Commercial License Usage
10 ** Licensees holding valid commercial Qt licenses may use this file in
11 ** accordance with the commercial license agreement provided with the
12 ** Software or, alternatively, in accordance with the terms contained in
13 ** a written agreement between you and Digia. For licensing terms and
14 ** conditions see http://qt.digia.com/licensing. For further information
15 ** use the contact form at http://qt.digia.com/contact-us.
16 **
17 ** GNU Lesser General Public License Usage
18 ** Alternatively, this file may be used under the terms of the GNU Lesser
19 ** General Public License version 2.1 as published by the Free Software
20 ** Foundation and appearing in the file LICENSE.LGPL included in the
21 ** packaging of this file. Please review the following information to
22 ** ensure the GNU Lesser General Public License version 2.1 requirements
23 ** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
24 **
25 ** In addition, as a special exception, Digia gives you certain additional
26 ** rights. These rights are described in the Digia Qt LGPL Exception
27 ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
28 **
29 ** GNU General Public License Usage
30 ** Alternatively, this file may be used under the terms of the GNU
31 ** General Public License version 3.0 as published by the Free Software
32 ** Foundation and appearing in the file LICENSE.GPL included in the
33 ** packaging of this file. Please review the following information to
34 ** ensure the GNU General Public License version 3.0 requirements will be
35 ** met: http://www.gnu.org/copyleft/gpl.html.
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 
60 
61 class QAuthenticator;
62 class QNetworkProxy;
63 class QNetworkProxyQuery;
64 class QNetworkRequest;
65 class QUrl;
66 class QUrlInfo;
67 class QSslConfiguration;
68 
74 
75 // Should support direct file upload from disk or download to disk.
76 //
77 // - The HTTP handler will use two QIODevices for communication (pull mechanism)
78 // - KIO uses a pull mechanism too (data/dataReq signals)
80 {
81  Q_OBJECT
82 public:
84  virtual ~QNetworkAccessBackend();
85 
86  // To avoid mistaking with QIODevice names, the functions here
87  // have different names. The Connection has two streams:
88  //
89  // - Upstream:
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
95  // deal with it.
96  //
97  //
98  // - Downstream:
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
110  // socket).
111 
112  virtual void open() = 0;
113  virtual bool start();
114  virtual void closeDownstreamChannel() = 0;
115 
116  // slot-like:
117  virtual void downstreamReadyWrite();
118  virtual void setDownstreamLimited(bool b);
119  virtual void setReadBufferSize(qint64 size);
120  virtual void emitReadBufferFreed(qint64 size);
121  virtual void copyFinished(QIODevice *);
122  virtual void ignoreSslErrors();
123  virtual void ignoreSslErrors(const QList<QSslError> &errors);
124 
125  virtual void fetchSslConfiguration(QSslConfiguration &configuration) const;
126  virtual void setSslConfiguration(const QSslConfiguration &configuration);
127 
128  virtual QNetworkCacheMetaData fetchCacheMetaData(const QNetworkCacheMetaData &metaData) const;
129 
130  // information about the request
132  QNetworkRequest request() const;
133 #ifndef QT_NO_NETWORKPROXY
135 #endif
136 
138  void setCachingEnabled(bool enable);
139  bool isCachingEnabled() const;
140 
141  // information about the reply
142  QUrl url() const;
143  void setUrl(const QUrl &url);
144 
145  // "cooked" headers
147  void setHeader(QNetworkRequest::KnownHeaders header, const QVariant &value);
148 
149  // raw headers:
150  bool hasRawHeader(const QByteArray &headerName) const;
152  QByteArray rawHeader(const QByteArray &headerName) const;
153  void setRawHeader(const QByteArray &headerName, const QByteArray &value);
154 
155  // attributes:
157  void setAttribute(QNetworkRequest::Attribute code, const QVariant &value);
158 
159  bool isSynchronous() { return synchronous; }
160  void setSynchronous(bool sync) { synchronous = sync; }
161 
162  // return true if the QNonContiguousByteDevice of the upload
163  // data needs to support reset(). Currently needed for HTTP.
164  // This will possibly enable buffering of the upload data.
165  virtual bool needsResetableUploadData() { return false; }
166 
167  // Returns true if backend is able to resume downloads.
168  virtual bool canResume() const { return false; }
169  virtual void setResumeOffset(quint64 offset) { Q_UNUSED(offset); }
170 
171  virtual bool processRequestSynchronously() { return false; }
172 
173 protected:
174  // Create the device used for reading the upload data
176 
177  // these functions control the downstream mechanism
178  // that is, data that has come via the connection and is going out the backend
181 
182  // not actually appending data, it was already written to the user buffer
184  char* getDownloadBuffer(qint64);
185 
187 
188 public slots:
189  // for task 251801, needs to be a slot to be called asynchronously
191 
192 protected slots:
193  void finished();
195 #ifndef QT_NO_NETWORKPROXY
196  void proxyAuthenticationRequired(const QNetworkProxy &proxy, QAuthenticator *auth);
197 #endif
199  void metaDataChanged();
200  void redirectionRequested(const QUrl &destination);
201  void sslErrors(const QList<QSslError> &errors);
202  void emitReplyUploadProgress(qint64 bytesSent, qint64 bytesTotal);
203 
204 protected:
205  // FIXME In the long run we should get rid of our QNAM architecture
206  // and scrap this ReplyImpl/Backend distinction.
209 
210 private:
211  friend class QNetworkAccessManager;
214 
216 };
217 
219 {
220 public:
222  virtual ~QNetworkAccessBackendFactory();
224  const QNetworkRequest &request) const = 0;
225 };
226 
228 
229 #endif
230 
The QVariant class acts like a union for the most common Qt data types.
Definition: qvariant.h:92
virtual void emitReadBufferFreed(qint64 size)
virtual void setSslConfiguration(const QSslConfiguration &configuration)
#define QT_END_NAMESPACE
This macro expands to.
Definition: qglobal.h:90
void setAttribute(QNetworkRequest::Attribute code, const QVariant &value)
virtual bool needsResetableUploadData()
static QByteArray headerName(QNetworkRequest::KnownHeaders header)
virtual void setReadBufferSize(qint64 size)
QVariant header(QNetworkRequest::KnownHeaders header) const
virtual void closeDownstreamChannel()=0
The QByteArray class provides an array of bytes.
Definition: qbytearray.h:135
static Expression::Ptr create(Expression *const expr, const YYLTYPE &sourceLocator, const ParserContext *const parseInfo)
NetworkError
Indicates all possible error conditions found during the processing of the request.
Definition: qnetworkreply.h:70
Operation
Indicates the operation this reply is processing.
virtual void fetchSslConfiguration(QSslConfiguration &configuration) const
virtual bool canResume() const
virtual QNetworkCacheMetaData fetchCacheMetaData(const QNetworkCacheMetaData &metaData) const
The QUrl class provides a convenient interface for working with URLs.
Definition: qurl.h:61
The QString class provides a Unicode character string.
Definition: qstring.h:83
void writeDownstreamDataDownloadBuffer(qint64, qint64)
The QObject class is the base class of all Qt objects.
Definition: qobject.h:111
KnownHeaders
List of known header types that QNetworkRequest parses.
virtual bool processRequestSynchronously()
qint64 nextDownstreamBlockSize() const
bool hasRawHeader(const QByteArray &headerName) const
QNetworkAccessManagerPrivate * manager
Q_GUI_EXPORT QString errorString(EGLint code=eglGetError())
Definition: qegl.cpp:743
The QNetworkProxy class provides a network layer proxy.
The QUrlInfo class stores information about URLs.
Definition: qurlinfo.h:60
QNonContiguousByteDevice * createUploadByteDevice()
#define QT_BEGIN_NAMESPACE
This macro expands to.
Definition: qglobal.h:89
QNetworkReplyImplPrivate * reply
virtual void setDownstreamLimited(bool b)
void emitReplyUploadProgress(qint64 bytesSent, qint64 bytesTotal)
unsigned __int64 quint64
Definition: qglobal.h:943
void setRawHeader(const QByteArray &headerName, const QByteArray &value)
QList< QNetworkProxy > proxyList() const
static const char * data(const QByteArray &arr)
void setHeader(QNetworkRequest::KnownHeaders header, const QVariant &value)
__int64 qint64
Definition: qglobal.h:942
QNetworkAccessManager::Operation operation() const
The QNetworkAccessManager class allows the application to send network requests and receive replies...
QByteArray rawHeader(const QByteArray &headerName) const
#define Q_OBJECT
Definition: qobjectdefs.h:157
The QAuthenticator class provides an authentication object.
QAbstractNetworkCache * networkCache() const
Attribute
Attribute codes for the QNetworkRequest and QNetworkReply.
The QNetworkProxyQuery class is used to query the proxy settings for a socket.
Definition: qnetworkproxy.h:60
QSharedPointer< QNonContiguousByteDevice > uploadByteDevice
void authenticationRequired(QAuthenticator *auth)
void error(QNetworkReply::NetworkError code, const QString &errorString)
QNetworkRequest request() const
void setUrl(const QUrl &url)
void writeDownstreamData(QByteDataBuffer &list)
QVariant attribute(QNetworkRequest::Attribute code) const
The QNetworkRequest class holds a request to be sent with QNetworkAccessManager.
virtual void setResumeOffset(quint64 offset)
void setCachingEnabled(bool enable)
A QNonContiguousByteDevice is a representation of a file, array or buffer that allows access with a r...
The QSslConfiguration class holds the configuration and state of an SSL connection.
virtual void copyFinished(QIODevice *)
#define slots
Definition: qobjectdefs.h:68
virtual void open()=0
The QIODevice class is the base interface class of all I/O devices in Qt.
Definition: qiodevice.h:66
#define Q_UNUSED(x)
Indicates to the compiler that the parameter with the specified name is not used in the body of a fun...
Definition: qglobal.h:1729
QList< QByteArray > rawHeaderList() const
The QNetworkCacheMetaData class provides cache information.
virtual bool start()
Starts the backend.
void redirectionRequested(const QUrl &destination)
void sslErrors(const QList< QSslError > &errors)
void proxyAuthenticationRequired(const QNetworkProxy &proxy, QAuthenticator *auth)
The QAbstractNetworkCache class provides the interface for cache implementations. ...