Qt 4.8
qnetworkreplyimpl_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 QNETWORKREPLYIMPL_P_H
43 #define QNETWORKREPLYIMPL_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 "qnetworkreply.h"
57 #include "qnetworkreply_p.h"
58 #include "qnetworkaccessmanager.h"
59 #include "qnetworkproxy.h"
60 #include "QtCore/qmap.h"
61 #include "QtCore/qqueue.h"
62 #include "QtCore/qbuffer.h"
63 #include "private/qringbuffer_p.h"
64 #include "private/qbytedata_p.h"
65 #include <QSharedPointer>
66 
68 
71 
74 {
75  Q_OBJECT
76 public:
79  virtual void abort();
80 
81  // reimplemented from QNetworkReply / QIODevice
82  virtual void close();
83  virtual qint64 bytesAvailable() const;
84  virtual void setReadBufferSize(qint64 size);
85  virtual bool canReadLine () const;
86 
87  virtual qint64 readData(char *data, qint64 maxlen);
88  virtual bool event(QEvent *);
89 
90 #ifndef QT_NO_OPENSSL
93  virtual void ignoreSslErrors();
95 #endif
96 
98  Q_PRIVATE_SLOT(d_func(), void _q_startOperation())
99  Q_PRIVATE_SLOT(d_func(), void _q_copyReadyRead())
100  Q_PRIVATE_SLOT(d_func(), void _q_copyReadChannelFinished())
101  Q_PRIVATE_SLOT(d_func(), void _q_bufferOutgoingData())
102  Q_PRIVATE_SLOT(d_func(), void _q_bufferOutgoingDataFinished())
103 #ifndef QT_NO_BEARERMANAGEMENT
104  Q_PRIVATE_SLOT(d_func(), void _q_networkSessionConnected())
105  Q_PRIVATE_SLOT(d_func(), void _q_networkSessionFailed())
106 #endif
107  Q_PRIVATE_SLOT(d_func(), void _q_cacheDestroyed())
108 };
109 
111 {
112 public:
116  NotifyCopyFinished
117  };
118 
119  enum State {
120  Idle, // The reply is idle.
121  Buffering, // The reply is buffering outgoing data.
122  Working, // The reply is uploading/downloading data.
123  Finished, // The reply has finished.
124  Aborted, // The reply has been aborted.
125  WaitingForSession, // The reply is waiting for the session to open before connecting.
126  Reconnecting // The reply will reconnect to once roaming has completed.
127  };
128 
130 
132 
133  void _q_startOperation();
134  void _q_sourceReadyRead();
135  void _q_sourceReadChannelFinished();
136  void _q_copyReadyRead();
137  void _q_copyReadChannelFinished();
138  void _q_bufferOutgoingData();
139  void _q_bufferOutgoingDataFinished();
140 #ifndef QT_NO_BEARERMANAGEMENT
141  void _q_networkSessionConnected();
142  void _q_networkSessionFailed();
143 #endif
144  void _q_cacheDestroyed();
145 
147  QIODevice *outgoingData);
148 
149  void pauseNotificationHandling();
150  void resumeNotificationHandling();
151  void backendNotify(InternalNotifications notification);
152  void handleNotifications();
153  void createCache();
154  void completeCacheSave();
155 
156  // callbacks from the backend (through the manager):
157  void setCachingEnabled(bool enable);
158  bool isCachingEnabled() const;
159  void consume(qint64 count);
160  void emitUploadProgress(qint64 bytesSent, qint64 bytesTotal);
161  qint64 nextDownstreamBlockSize() const;
162 
163  void initCacheSaveDevice();
164  void appendDownstreamDataSignalEmissions();
165  void appendDownstreamData(QByteDataBuffer &data);
166  void appendDownstreamData(QIODevice *data);
167  void appendDownstreamData(const QByteArray &data);
168 
169  void setDownloadBuffer(QSharedPointer<char> sp, qint64 size);
170  char* getDownloadBuffer(qint64 size);
171  void appendDownstreamDataDownloadBuffer(qint64, qint64);
172 
173  void finished();
175  void metaDataChanged();
176  void redirectionRequested(const QUrl &target);
177  void sslErrors(const QList<QSslError> &errors);
178 
183  QAbstractNetworkCache *networkCache() const;
184 
185  bool migrateBackend();
186 
189 
190  NotificationQueue pendingNotifications;
192 
194 #ifndef QT_NO_NETWORKPROXY
197 #endif
198 
199  // Used for normal downloading. For "zero copy" the downloadBuffer is used
205 
208 
210 
211  // only used when the "zero copy" style is used. Else readBuffer is used.
212  // Please note that the whole "zero copy" download buffer API is private right now. Do not use it.
218 
220 };
221 
222 #ifndef QT_NO_BEARERMANAGEMENT
224 {
225  Q_OBJECT
226 
227 public:
231 
232  void abort() { }
233 protected:
234  qint64 readData(char *, qint64) { return -1; }
235 };
236 #endif
237 
239 
240 #endif
void sslErrors(const QList< QSslError > &errors)
This signal is emitted if the SSL/TLS session encountered errors during the set up, including certificate verification errors.
virtual qint64 size() const
For open random-access devices, this function returns the size of the device.
Definition: qiodevice.cpp:642
NetworkError error() const
Returns the error that was found during the processing of this request.
QQueue< InternalNotifications > NotificationQueue
#define QT_END_NAMESPACE
This macro expands to.
Definition: qglobal.h:90
virtual qint64 readData(char *data, qint64 maxlen)
virtual void ignoreSslErrors()
If this function is called, SSL errors related to network connection will be ignored, including certificate validation errors.
The QNetworkReply class contains the data and headers for a request sent with QNetworkAccessManager.
Definition: qnetworkreply.h:65
The QByteArray class provides an array of bytes.
Definition: qbytearray.h:135
QString errorString() const
Returns a human-readable description of the last device error that occurred.
Definition: qiodevice.cpp:1671
#define Q_INVOKABLE
Definition: qobjectdefs.h:90
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 setReadBufferSize(qint64 size)
Sets the size of the read buffer to be size bytes.
QList< QNetworkProxy > proxyList
#define Q_PRIVATE_SLOT(d, signature)
Definition: qobjectdefs.h:73
QNetworkAccessBackend * backend
NotificationQueue pendingNotifications
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
QSharedPointer< char > downloadBufferPointer
The QObject class is the base class of all Qt objects.
Definition: qobject.h:111
virtual Q_INVOKABLE void ignoreSslErrorsImplementation(const QList< QSslError > &errors)
QNetworkRequest request() const
Returns the request that was posted for this reply.
qint64 readData(char *, qint64)
Reads up to maxSize bytes from the device into data, and returns the number of bytes read or -1 if an...
The QNetworkProxy class provides a network layer proxy.
#define QT_BEGIN_NAMESPACE
This macro expands to.
Definition: qglobal.h:89
static const char * data(const QByteArray &arr)
__int64 qint64
Definition: qglobal.h:942
The State element defines configurations of objects and properties.
#define Q_OBJECT
Definition: qobjectdefs.h:157
QSharedPointer< QRingBuffer > outgoingDataBuffer
void finished()
This signal is emitted when the reply has finished processing.
#define Q_DECLARE_PUBLIC(Class)
Definition: qglobal.h:2477
virtual void close()
Closes this device for reading.
Q_INVOKABLE QSslConfiguration sslConfigurationImplementation() const
QObject * parent() const
Returns a pointer to the parent object.
Definition: qobject.h:273
void metaDataChanged()
This signal is emitted whenever the metadata in this reply changes.
QNetworkReplyImpl(QObject *parent=0)
The QNetworkRequest class holds a request to be sent with QNetworkAccessManager.
Q_INVOKABLE void setSslConfigurationImplementation(const QSslConfiguration &configuration)
virtual void abort()
Aborts the operation immediately and close down any network connections still open.
The QSslConfiguration class holds the configuration and state of an SSL connection.
#define Q_DECLARE_PRIVATE(Class)
Definition: qglobal.h:2467
The QIODevice class is the base interface class of all I/O devices in Qt.
Definition: qiodevice.h:66
The QEvent class is the base class of all event classes.
Definition: qcoreevent.h:56
virtual qint64 bytesAvailable() const
Returns the number of bytes available for reading with QIODevice::read().
virtual bool canReadLine() const
Returns true if a complete line of data can be read from the device; otherwise returns false...
void abort()
Aborts the operation immediately and close down any network connections still open.
virtual bool event(QEvent *)
static void setup()
Definition: qtextcodec.cpp:718
The QAbstractNetworkCache class provides the interface for cache implementations. ...