author | Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com> |
Mon, 04 Oct 2010 01:19:32 +0300 | |
changeset 37 | 758a864f9613 |
parent 30 | 5dc02b23752f |
permissions | -rw-r--r-- |
0 | 1 |
/**************************************************************************** |
2 |
** |
|
18
2f34d5167611
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
3 |
** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies). |
0 | 4 |
** All rights reserved. |
5 |
** Contact: Nokia Corporation (qt-info@nokia.com) |
|
6 |
** |
|
7 |
** This file is part of the QtNetwork module of the Qt Toolkit. |
|
8 |
** |
|
9 |
** $QT_BEGIN_LICENSE:LGPL$ |
|
10 |
** No Commercial Usage |
|
11 |
** This file contains pre-release code and may not be distributed. |
|
12 |
** You may use this file in accordance with the terms and conditions |
|
13 |
** contained in the Technology Preview License Agreement accompanying |
|
14 |
** this package. |
|
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 |
** If you have questions regarding the use of this file, please contact |
|
29 |
** Nokia at qt-info@nokia.com. |
|
30 |
** |
|
31 |
** |
|
32 |
** |
|
33 |
** |
|
34 |
** |
|
35 |
** |
|
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 |
||
66 |
QT_BEGIN_NAMESPACE |
|
67 |
||
68 |
class QAbstractNetworkCache; |
|
69 |
class QNetworkAccessBackend; |
|
70 |
||
71 |
class QNetworkReplyImplPrivate; |
|
72 |
class QNetworkReplyImpl: public QNetworkReply |
|
73 |
{ |
|
74 |
Q_OBJECT |
|
75 |
public: |
|
76 |
QNetworkReplyImpl(QObject *parent = 0); |
|
77 |
~QNetworkReplyImpl(); |
|
78 |
virtual void abort(); |
|
79 |
||
30
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
23
diff
changeset
|
80 |
// reimplemented from QNetworkReply / QIODevice |
0 | 81 |
virtual void close(); |
82 |
virtual qint64 bytesAvailable() const; |
|
83 |
virtual void setReadBufferSize(qint64 size); |
|
30
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
23
diff
changeset
|
84 |
virtual bool canReadLine () const; |
0 | 85 |
|
86 |
virtual qint64 readData(char *data, qint64 maxlen); |
|
87 |
virtual bool event(QEvent *); |
|
88 |
||
89 |
#ifndef QT_NO_OPENSSL |
|
90 |
Q_INVOKABLE QSslConfiguration sslConfigurationImplementation() const; |
|
91 |
Q_INVOKABLE void setSslConfigurationImplementation(const QSslConfiguration &configuration); |
|
92 |
virtual void ignoreSslErrors(); |
|
93 |
Q_INVOKABLE virtual void ignoreSslErrorsImplementation(const QList<QSslError> &errors); |
|
94 |
#endif |
|
95 |
||
96 |
Q_DECLARE_PRIVATE(QNetworkReplyImpl) |
|
97 |
Q_PRIVATE_SLOT(d_func(), void _q_startOperation()) |
|
98 |
Q_PRIVATE_SLOT(d_func(), void _q_copyReadyRead()) |
|
99 |
Q_PRIVATE_SLOT(d_func(), void _q_copyReadChannelFinished()) |
|
100 |
Q_PRIVATE_SLOT(d_func(), void _q_bufferOutgoingData()) |
|
101 |
Q_PRIVATE_SLOT(d_func(), void _q_bufferOutgoingDataFinished()) |
|
30
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
23
diff
changeset
|
102 |
#ifndef QT_NO_BEARERMANAGEMENT |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
23
diff
changeset
|
103 |
Q_PRIVATE_SLOT(d_func(), void _q_networkSessionConnected()) |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
23
diff
changeset
|
104 |
Q_PRIVATE_SLOT(d_func(), void _q_networkSessionFailed()) |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
23
diff
changeset
|
105 |
#endif |
0 | 106 |
}; |
107 |
||
108 |
class QNetworkReplyImplPrivate: public QNetworkReplyPrivate |
|
109 |
{ |
|
110 |
public: |
|
111 |
enum InternalNotifications { |
|
112 |
NotifyDownstreamReadyWrite, |
|
113 |
NotifyCloseDownstreamChannel, |
|
114 |
NotifyCopyFinished |
|
115 |
}; |
|
116 |
||
117 |
enum State { |
|
30
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
23
diff
changeset
|
118 |
Idle, // The reply is idle. |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
23
diff
changeset
|
119 |
Buffering, // The reply is buffering outgoing data. |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
23
diff
changeset
|
120 |
Working, // The reply is uploading/downloading data. |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
23
diff
changeset
|
121 |
Finished, // The reply has finished. |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
23
diff
changeset
|
122 |
Aborted, // The reply has been aborted. |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
23
diff
changeset
|
123 |
WaitingForSession, // The reply is waiting for the session to open before connecting. |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
23
diff
changeset
|
124 |
Reconnecting // The reply will reconnect to once roaming has completed. |
0 | 125 |
}; |
126 |
||
127 |
typedef QQueue<InternalNotifications> NotificationQueue; |
|
128 |
||
129 |
QNetworkReplyImplPrivate(); |
|
130 |
||
131 |
void _q_startOperation(); |
|
132 |
void _q_sourceReadyRead(); |
|
133 |
void _q_sourceReadChannelFinished(); |
|
134 |
void _q_copyReadyRead(); |
|
135 |
void _q_copyReadChannelFinished(); |
|
136 |
void _q_bufferOutgoingData(); |
|
137 |
void _q_bufferOutgoingDataFinished(); |
|
30
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
23
diff
changeset
|
138 |
#ifndef QT_NO_BEARERMANAGEMENT |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
23
diff
changeset
|
139 |
void _q_networkSessionConnected(); |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
23
diff
changeset
|
140 |
void _q_networkSessionFailed(); |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
23
diff
changeset
|
141 |
#endif |
0 | 142 |
|
143 |
void setup(QNetworkAccessManager::Operation op, const QNetworkRequest &request, |
|
144 |
QIODevice *outgoingData); |
|
145 |
||
146 |
void pauseNotificationHandling(); |
|
147 |
void resumeNotificationHandling(); |
|
148 |
void backendNotify(InternalNotifications notification); |
|
149 |
void handleNotifications(); |
|
150 |
void createCache(); |
|
151 |
void completeCacheSave(); |
|
152 |
||
153 |
// callbacks from the backend (through the manager): |
|
154 |
void setCachingEnabled(bool enable); |
|
155 |
bool isCachingEnabled() const; |
|
156 |
void consume(qint64 count); |
|
157 |
void emitUploadProgress(qint64 bytesSent, qint64 bytesTotal); |
|
158 |
qint64 nextDownstreamBlockSize() const; |
|
23
89e065397ea6
Revision: 201019
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
159 |
|
89e065397ea6
Revision: 201019
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
160 |
void initCacheSaveDevice(); |
89e065397ea6
Revision: 201019
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
161 |
void appendDownstreamDataSignalEmissions(); |
0 | 162 |
void appendDownstreamData(QByteDataBuffer &data); |
163 |
void appendDownstreamData(QIODevice *data); |
|
23
89e065397ea6
Revision: 201019
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
164 |
void appendDownstreamData(const QByteArray &data); |
89e065397ea6
Revision: 201019
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
165 |
|
0 | 166 |
void finished(); |
167 |
void error(QNetworkReply::NetworkError code, const QString &errorString); |
|
168 |
void metaDataChanged(); |
|
169 |
void redirectionRequested(const QUrl &target); |
|
170 |
void sslErrors(const QList<QSslError> &errors); |
|
171 |
||
172 |
bool isFinished() const; |
|
173 |
||
174 |
QNetworkAccessBackend *backend; |
|
175 |
QIODevice *outgoingData; |
|
176 |
QRingBuffer *outgoingDataBuffer; |
|
177 |
QIODevice *copyDevice; |
|
178 |
QAbstractNetworkCache *networkCache() const; |
|
179 |
||
30
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
23
diff
changeset
|
180 |
bool migrateBackend(); |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
23
diff
changeset
|
181 |
|
0 | 182 |
bool cacheEnabled; |
183 |
QIODevice *cacheSaveDevice; |
|
184 |
||
185 |
NotificationQueue pendingNotifications; |
|
186 |
bool notificationHandlingPaused; |
|
187 |
||
188 |
QUrl urlForLastAuthentication; |
|
189 |
#ifndef QT_NO_NETWORKPROXY |
|
190 |
QNetworkProxy lastProxyAuthentication; |
|
191 |
QList<QNetworkProxy> proxyList; |
|
192 |
#endif |
|
193 |
||
194 |
QByteDataBuffer readBuffer; |
|
195 |
qint64 bytesDownloaded; |
|
196 |
qint64 lastBytesDownloaded; |
|
197 |
qint64 bytesUploaded; |
|
30
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
23
diff
changeset
|
198 |
qint64 preMigrationDownloaded; |
0 | 199 |
|
200 |
QString httpReasonPhrase; |
|
201 |
int httpStatusCode; |
|
202 |
||
203 |
State state; |
|
204 |
||
205 |
Q_DECLARE_PUBLIC(QNetworkReplyImpl) |
|
206 |
}; |
|
207 |
||
30
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
23
diff
changeset
|
208 |
#ifndef QT_NO_BEARERMANAGEMENT |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
23
diff
changeset
|
209 |
class QDisabledNetworkReply : public QNetworkReply |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
23
diff
changeset
|
210 |
{ |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
23
diff
changeset
|
211 |
Q_OBJECT |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
23
diff
changeset
|
212 |
|
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
23
diff
changeset
|
213 |
public: |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
23
diff
changeset
|
214 |
QDisabledNetworkReply(QObject *parent, const QNetworkRequest &req, |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
23
diff
changeset
|
215 |
QNetworkAccessManager::Operation op); |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
23
diff
changeset
|
216 |
~QDisabledNetworkReply(); |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
23
diff
changeset
|
217 |
|
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
23
diff
changeset
|
218 |
void abort() { } |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
23
diff
changeset
|
219 |
protected: |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
23
diff
changeset
|
220 |
qint64 readData(char *, qint64) { return -1; } |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
23
diff
changeset
|
221 |
}; |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
23
diff
changeset
|
222 |
#endif |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
23
diff
changeset
|
223 |
|
0 | 224 |
QT_END_NAMESPACE |
225 |
||
226 |
#endif |